UNPKG

@tamagui/react-native-web-lite

Version:
117 lines (116 loc) 4.76 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: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__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: !0 }), mod); var Linking_exports = {}; __export(Linking_exports, { default: () => Linking_default }); module.exports = __toCommonJS(Linking_exports); var import_react_native_web_internals = require("@tamagui/react-native-web-internals"); function _class_call_check(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 || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } function _define_property(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value, enumerable: !0, configurable: !0, writable: !0 }) : obj[key] = value, obj; } var initialURL = import_react_native_web_internals.canUseDOM ? window.location.href : "", Linking = /* @__PURE__ */ function() { "use strict"; function Linking2() { var _this = this; _class_call_check(this, Linking2), _define_property(this, "_eventCallbacks", {}), _define_property(this, "addEventListener", function(event, callback) { if (!_this._eventCallbacks[event]) { _this._eventCallbacks[event] = [ callback ]; return; } _this._eventCallbacks[event].push(callback); }), _define_property(this, "removeEventListener", function(event, callback) { var callbacks = _this._eventCallbacks[event], filteredCallbacks = callbacks.filter(function(c) { return c.toString() !== callback.toString(); }); _this._eventCallbacks[event] = filteredCallbacks; }); } return _create_class(Linking2, [ { key: "_dispatchEvent", value: function(event) { for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) data[_key - 1] = arguments[_key]; var listeners = this._eventCallbacks[event]; listeners != null && Array.isArray(listeners) && listeners.map(function(listener) { listener(...data); }); } }, { key: "canOpenURL", value: function() { return Promise.resolve(!0); } }, { key: "getInitialURL", value: function() { return Promise.resolve(initialURL); } }, { /** * Try to open the given url in a secure fashion. The method returns a Promise object. * If a target is passed (including undefined) that target will be used, otherwise '_blank'. * If the url opens, the promise is resolved. If not, the promise is rejected. * Dispatches the `onOpen` event if `url` is opened successfully. */ key: "openURL", value: function(url, target) { arguments.length === 1 && (target = "_blank"); try { return open(url, target), this._dispatchEvent("onOpen", url), Promise.resolve(); } catch (e) { return Promise.reject(e); } } }, { key: "_validateURL", value: function(url) { (0, import_react_native_web_internals.invariant)(typeof url == "string", "Invalid URL: should be a string. Was: " + url), (0, import_react_native_web_internals.invariant)(url, "Invalid URL: cannot be empty"); } } ]), Linking2; }(), open = function(url, target) { if (import_react_native_web_internals.canUseDOM) { var urlToOpen = new URL(url, window.location).toString(); urlToOpen.indexOf("tel:") === 0 ? window.location = urlToOpen : window.open(urlToOpen, target, "noopener"); } }, Linking_default = new Linking(); //# sourceMappingURL=index.js.map