UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

98 lines (95 loc) • 3.77 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var index_native_exports = {}; __export(index_native_exports, { AppIntents: () => AppIntents }); module.exports = __toCommonJS(index_native_exports); var import_react_native = require("react-native"); var import_react_native_nitro_modules = require("react-native-nitro-modules"); var import_nativeError = require("../nativeError.native.js"); var import_validate = require("./validate.native.js"); var import_unavailable = require("./unavailable.native.js"); var hybrid; var handlers = /* @__PURE__ */ new Map(); function native() { if (import_react_native.Platform.OS !== "ios") throw new Error("AppIntents requires an iOS native build"); hybrid !== null && hybrid !== void 0 ? hybrid : hybrid = import_react_native_nitro_modules.NitroModules.createHybridObject("OneAppIntents"); return hybrid; } function errorMessage(error) { return error instanceof Error ? error.message : String(error); } function defineAction(identifier, handler) { (0, import_validate.assertActionHandler)(identifier, handler); if (handlers.has(identifier)) { throw new Error(`AppIntents.defineAction: ${identifier} is already defined`); } handlers.set(identifier, handler); var dispatch = function dispatch2(invocation2) { Promise.resolve().then(function() { var _invocation_text; return handler((_invocation_text = invocation2.text) !== null && _invocation_text !== void 0 ? _invocation_text : null); }).then(function(result) { if (typeof result !== "string") { throw new TypeError("AppIntents action handler must return a string"); } native().complete(invocation2.executionId, true, result); }).catch(function(error) { native().complete(invocation2.executionId, false, errorMessage(error)); }); }; var remove; try { remove = native().addInvocationListener(identifier, dispatch); var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = native().claimPending(identifier)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var invocation = _step.value; dispatch(invocation); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } } catch (error) { remove === null || remove === void 0 ? void 0 : remove(); handlers.delete(identifier); (0, import_nativeError.rethrowNativeError)(error); } return function() { if (handlers.get(identifier) !== handler) return; handlers.delete(identifier); remove === null || remove === void 0 ? void 0 : remove(); }; } var nativeAppIntents = Object.freeze({ defineAction }); var AppIntents = import_react_native.Platform.OS === "android" ? import_unavailable.AppIntents : nativeAppIntents; //# sourceMappingURL=index.native.js.map