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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { 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 | * Initializes the component.
|
34 | *
|
35 | * @param {Object<string, *>} props The component properties.
|
36 | * @param {Object<string, *>} context The component context.
|
37 | */
|
38 |
|
39 |
|
40 | constructor(props, context) {
|
41 | super(props, context);
|
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 |
|
49 | this._utils = null;
|
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 |
|
58 |
|
59 | get utils() {
|
60 | if (!this._utils) {
|
61 | this._utils = helpers.getUtils(this.props, this.context);
|
62 | }
|
63 |
|
64 | return this._utils;
|
65 | }
|
66 | /**
|
67 | * Returns the localized phrase identified by the specified key. The
|
68 | * placeholders in the localization phrase will be replaced by the provided
|
69 | * values.
|
70 | *
|
71 | * @param {string} key Localization key.
|
72 | * @param {Object<string, (number|string)>=} params Values for replacing
|
73 | * the placeholders in the localization phrase.
|
74 | * @return {string} Localized phrase.
|
75 | */
|
76 |
|
77 |
|
78 | localize(key, params = {}) {
|
79 | return helpers.localize(this, key, params);
|
80 | }
|
81 | /**
|
82 | * Generates an absolute URL using the provided route name (see the
|
83 | * <code>app/config/routes.js</code> file). The provided parameters will
|
84 | * replace the placeholders in the route pattern, while the extraneous
|
85 | * parameters will be appended to the generated URL's query string.
|
86 | *
|
87 | * @param {string} name The route name.
|
88 | * @param {Object<string, (number|string)>=} params Router parameters and
|
89 | * extraneous parameters to add to the URL as a query string.
|
90 | * @return {string} The generated URL.
|
91 | */
|
92 |
|
93 |
|
94 | link(name, params = {}) {
|
95 | return helpers.link(this, name, params);
|
96 | }
|
97 | /**
|
98 | * Generate a string of CSS classes from the properties of the passed-in
|
99 | * object that resolve to true.
|
100 | *
|
101 | * @example
|
102 | * this.cssClasses('my-class my-class-modificator', true);
|
103 | * @example
|
104 | * this.cssClasses({
|
105 | * 'my-class': true,
|
106 | * 'my-class-modificator': this.props.modificator
|
107 | * }, true);
|
108 | *
|
109 | * @param {(string|Object<string, boolean>)} classRules CSS classes in a
|
110 | * string separated by whitespace, or a map of CSS class names to
|
111 | * boolean values. The CSS class name will be included in the result
|
112 | * only if the value is {@code true}.
|
113 | * @param {boolean} includeComponentClassName
|
114 | * @return {string} String of CSS classes that had their property resolved
|
115 | * to {@code true}.
|
116 | */
|
117 |
|
118 |
|
119 | cssClasses(classRules, includeComponentClassName = false) {
|
120 | return helpers.cssClasses(this, classRules, includeComponentClassName);
|
121 | }
|
122 | /**
|
123 | * Creates and sends a new IMA.js DOM custom event from this component.
|
124 | *
|
125 | * @param {string} eventName The name of the event.
|
126 | * @param {*=} data Data to send within the event.
|
127 | */
|
128 |
|
129 |
|
130 | fire(eventName, data = null) {
|
131 | helpers.fire(this, eventName, data);
|
132 | }
|
133 | /**
|
134 | * Registers the provided event listener for execution whenever an IMA.js
|
135 | * DOM custom event of the specified name occurs at the specified event
|
136 | * target.
|
137 | *
|
138 | * @param {(React.Element|EventTarget)} eventTarget The react component or
|
139 | * event target at which the listener should listen for the event.
|
140 | * @param {string} eventName The name of the event for which to listen.
|
141 | * @param {function(Event)} listener The listener for event to register.
|
142 | */
|
143 |
|
144 |
|
145 | listen(eventTarget, eventName, listener) {
|
146 | helpers.listen(this, eventTarget, eventName, listener);
|
147 | }
|
148 | /**
|
149 | * Deregisters the provided event listener for an IMA.js DOM custom event
|
150 | * of the specified name at the specified event target.
|
151 | *
|
152 | * @param {(React.Element|EventTarget)} eventTarget The react component or
|
153 | * event target at which the listener should listen for the event.
|
154 | * @param {string} eventName The name of the event for which to listen.
|
155 | * @param {function(Event)} listener The listener for event to register.
|
156 | */
|
157 |
|
158 |
|
159 | unlisten(eventTarget, eventName, listener) {
|
160 | helpers.unlisten(this, eventTarget, eventName, listener);
|
161 | }
|
162 |
|
163 | }
|
164 |
|
165 | exports.default = AbstractComponent;
|
166 |
|
167 | typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/page/AbstractComponent', [], function (_export, _context) {
|
168 | ;
|
169 | return {
|
170 | setters: [],
|
171 | execute: function () {
|
172 | _export('default', exports.default);
|
173 | }
|
174 | };
|
175 | });
|