UNPKG

@ima/react-page-renderer

Version:

IMA.js React page renderer.

150 lines (149 loc) 5.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "AbstractComponent", { enumerable: true, get: function() { return AbstractComponent; } }); const _react = require("react"); const _componentHelpers = /*#__PURE__*/ _interop_require_wildcard(require("../componentHelpers")); const _PageContext = require("../PageContext"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interop_require_wildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = { __proto__: null }; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for(var key in obj){ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } class AbstractComponent extends _react.Component { static contextType = _PageContext.PageContext; _utils; /** * Returns the utilities for the view components. The returned value is the * value bound to the `$Utils` object container constant. * * @return The utilities for the view components. */ get utils() { if (!this._utils) { this._utils = _componentHelpers.getUtils(this.props, this.context); } return this._utils; } /** * Returns the localized phrase identified by the specified key. The * placeholders in the localization phrase will be replaced by the provided * values. * * @param key Localization key. * @param params Values for replacing * the placeholders in the localization phrase. * @return Localized phrase. */ localize(key, params = {}) { return _componentHelpers.localize(this, key, params); } /** * Generates an absolute URL using the provided route name (see the * <code>app/config/routes.js</code> file). The provided parameters will * replace the placeholders in the route pattern, while the extraneous * parameters will be appended to the generated URL's query string. * * @param name The route name. * @param params Router parameters and * extraneous parameters to add to the URL as a query string. * @return The generated URL. */ link(name, params = {}) { return _componentHelpers.link(this, name, params); } /** * Generate a string of CSS classes from the properties of the passed-in * object that resolve to true. * * @example * this.cssClasses('my-class my-class-modifier', true); * @example * this.cssClasses({ * 'my-class': true, * 'my-class-modifier': this.props.modifier * }, true); * * @param classRules CSS classes in a * string separated by whitespace, or a map of CSS class names to * boolean values. The CSS class name will be included in the result * only if the value is `true`. * @param includeComponentClassName * @return String of CSS classes that had their property resolved * to `true`. */ cssClasses(classRules, includeComponentClassName = false) { return _componentHelpers.cssClasses(this, classRules, includeComponentClassName); } /** * Creates and sends a new IMA.js DOM custom event from this component. * * @param eventName The name of the event. * @param eventTarget EventTarget compatible node. * @param data Data to send within the event. */ fire(eventTarget, eventName, data) { _componentHelpers.fire(this, eventTarget, eventName, data); } /** * Registers the provided event listener for execution whenever an IMA.js * DOM custom event of the specified name occurs at the specified event * target. * * @param eventTarget The react component or * event target at which the listener should listen for the event. * @param eventName The name of the event for which to listen. * @param listener The listener for event to register. */ listen(eventTarget, eventName, listener) { _componentHelpers.listen(this, eventTarget, eventName, listener); } /** * Deregisters the provided event listener for an IMA.js DOM custom event * of the specified name at the specified event target. * * @param eventTarget The react component or * event target at which the listener should listen for the event. * @param eventName The name of the event for which to listen. * @param listener The listener for event to register. */ unlisten(eventTarget, eventName, listener) { _componentHelpers.unlisten(this, eventTarget, eventName, listener); } } //# sourceMappingURL=AbstractComponent.js.map