1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _react = require('react');
|
8 |
|
9 | var _react2 = _interopRequireDefault(_react);
|
10 |
|
11 | var _componentHelpers = require('./componentHelpers');
|
12 |
|
13 | var helpers = _interopRequireWildcard(_componentHelpers);
|
14 |
|
15 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
16 |
|
17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18 |
|
19 | /**
|
20 | * The base class for all view components.
|
21 | *
|
22 | * @abstract
|
23 | */
|
24 | class AbstractComponent extends _react2.default.Component {
|
25 | static get contextTypes() {
|
26 | return helpers.getContextTypes(this);
|
27 | }
|
28 |
|
29 | static set contextTypes(contextTypes) {
|
30 | helpers.setContextTypes(this, contextTypes);
|
31 | }
|
32 |
|
33 | /**
|
34 | * Initializes the component.
|
35 | *
|
36 | * @param {Object<string, *>} props The component properties.
|
37 | * @param {Object<string, *>} context The component context.
|
38 | */
|
39 | constructor(props, context) {
|
40 | super(props, context);
|
41 |
|
42 | /**
|
43 | * The view utilities, initialized lazily upon first use from either
|
44 | * the context, or the component's props.
|
45 | *
|
46 | * @type {?Object<string, *>}
|
47 | */
|
48 | this._utils = null;
|
49 | }
|
50 |
|
51 | /**
|
52 | * Returns the utilities for the view components. The returned value is the
|
53 | * value bound to the {@code $Utils} object container constant.
|
54 | *
|
55 | * @return {Object<string, *>} The utilities for the view components.
|
56 | */
|
57 | get utils() {
|
58 | if (!this._utils) {
|
59 | this._utils = helpers.getUtils(this.props, this.context);
|
60 | }
|
61 |
|
62 | return this._utils;
|
63 | }
|
64 |
|
65 | /**
|
66 | * Returns the localized phrase identified by the specified key. The
|
67 | * placeholders in the localization phrase will be replaced by the provided
|
68 | * values.
|
69 | *
|
70 | * @param {string} key Localization key.
|
71 | * @param {Object<string, (number|string)>=} params Values for replacing
|
72 | * the placeholders in the localization phrase.
|
73 | * @return {string} Localized phrase.
|
74 | */
|
75 | localize(key, params = {}) {
|
76 | return helpers.localize(this, key, params);
|
77 | }
|
78 |
|
79 | /**
|
80 | * Generates an absolute URL using the provided route name (see the
|
81 | * <code>app/config/routes.js</code> file). The provided parameters will
|
82 | * replace the placeholders in the route pattern, while the extraneous
|
83 | * parameters will be appended to the generated URL's query string.
|
84 | *
|
85 | * @param {string} name The route name.
|
86 | * @param {Object<string, (number|string)>=} params Router parameters and
|
87 | * extraneous parameters to add to the URL as a query string.
|
88 | * @return {string} The generated URL.
|
89 | */
|
90 | link(name, params = {}) {
|
91 | return helpers.link(this, name, params);
|
92 | }
|
93 |
|
94 | /**
|
95 | * Generate a string of CSS classes from the properties of the passed-in
|
96 | * object that resolve to true.
|
97 | *
|
98 | * @example
|
99 | * this.cssClasses('my-class my-class-modificator', true);
|
100 | * @example
|
101 | * this.cssClasses({
|
102 | * 'my-class': true,
|
103 | * 'my-class-modificator': this.props.modificator
|
104 | * }, true);
|
105 | *
|
106 | * @param {(string|Object<string, boolean>)} classRules CSS classes in a
|
107 | * string separated by whitespace, or a map of CSS class names to
|
108 | * boolean values. The CSS class name will be included in the result
|
109 | * only if the value is {@code true}.
|
110 | * @param {boolean} includeComponentClassName
|
111 | * @return {string} String of CSS classes that had their property resolved
|
112 | * to {@code true}.
|
113 | */
|
114 | cssClasses(classRules, includeComponentClassName = false) {
|
115 | return helpers.cssClasses(this, classRules, includeComponentClassName);
|
116 | }
|
117 |
|
118 | /**
|
119 | * Creates and sends a new IMA.js DOM custom event from this component.
|
120 | *
|
121 | * @param {string} eventName The name of the event.
|
122 | * @param {*=} data Data to send within the event.
|
123 | */
|
124 | fire(eventName, data = null) {
|
125 | helpers.fire(this, eventName, data);
|
126 | }
|
127 |
|
128 | /**
|
129 | * Registers the provided event listener for execution whenever an IMA.js
|
130 | * DOM custom event of the specified name occurs at the specified event
|
131 | * target.
|
132 | *
|
133 | * @param {(React.Element|EventTarget)} eventTarget The react component or
|
134 | * event target at which the listener should listen for the event.
|
135 | * @param {string} eventName The name of the event for which to listen.
|
136 | * @param {function(Event)} listener The listener for event to register.
|
137 | */
|
138 | listen(eventTarget, eventName, listener) {
|
139 | helpers.listen(this, eventTarget, eventName, listener);
|
140 | }
|
141 |
|
142 | /**
|
143 | * Deregisters the provided event listener for an IMA.js DOM custom event
|
144 | * of the specified name at the specified event target.
|
145 | *
|
146 | * @param {(React.Element|EventTarget)} eventTarget The react component or
|
147 | * event target at which the listener should listen for the event.
|
148 | * @param {string} eventName The name of the event for which to listen.
|
149 | * @param {function(Event)} listener The listener for event to register.
|
150 | */
|
151 | unlisten(eventTarget, eventName, listener) {
|
152 | helpers.unlisten(this, eventTarget, eventName, listener);
|
153 | }
|
154 | }
|
155 | exports.default = AbstractComponent;
|
156 |
|
157 | typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/page/AbstractComponent', [], function (_export, _context) {
|
158 | ;
|
159 | return {
|
160 | setters: [],
|
161 | execute: function () {
|
162 | _export('default', exports.default);
|
163 | }
|
164 | };
|
165 | });
|