UNPKG

@formidable-webview/webshell

Version:

🔥 Craft Robust React Native WebView-based components with ease.

116 lines (91 loc) • 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /** * A feature constructor function, aka class. * * @typeparam O - A type describing the shape of the JSON-serializable object that will be passed to the Web script. * @typeparam P - A type specifying the new properties added to the shell (capabilities to send message to the shell). * @typeparam W - A type specifying the Web handlers added to the shell (capabilities to send message to the Web script). * * @public */ /** * A feature encapsulates injectable behaviors in a WebView. * * @remarks * You should never instantiate that class directly. Use {@link FeatureBuilder} instead. * * @typeparam O - A type describing the shape of the JSON-serializable object that will be passed to the Web script. * @typeparam P - A type specifying the new properties added to the shell (capabilities to send message to the shell). * @typeparam W - A type specifying the Web handlers added to the shell (capabilities to send message to the Web script). * * @public */ var Feature = /*#__PURE__*/function () { /** * The string containing valid ECMAScript 5 to be run in the WebView. * * @remarks * The script must define a single function which only argument is of the * type {@link WebjsContext}. * * It is recommended that you use eslint to validate this script syntax, and * event better, unit-test the script. See our repository home page for more * information. */ /** * A unique identifier of the feature. The convention is to use a reverse * namespace domain ending with the feature name. * * @example * org.formidable-webview/webshell.link-press */ /** * An object specifying which props this feature will add to the shell. */ /** * An object specifying which handlers this feature Web script will support. */ /** * These options will be shallow-merged with the options provided to the {@link FeatureClass}. */ /** * The options that will be passed to the Web script. */ function Feature(params, options) { _classCallCheck(this, Feature); _defineProperty(this, "script", void 0); _defineProperty(this, "identifier", void 0); _defineProperty(this, "propSpecs", void 0); _defineProperty(this, "webSpecs", void 0); _defineProperty(this, "defaultOptions", void 0); _defineProperty(this, "options", void 0); this.script = params.script; this.identifier = params.identifier; this.propSpecs = params.propSpecs; this.defaultOptions = params.defaultOptions; this.options = _objectSpread(_objectSpread({}, params.defaultOptions), options); this.webSpecs = params.webSpecs; } /** * @internal */ _createClass(Feature, [{ key: "hasWebHandler", value: function hasWebHandler(eventId) { return !!this.webSpecs[eventId]; } }]); return Feature; }(); exports["default"] = Feature; //# sourceMappingURL=Feature.js.map