UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

261 lines (257 loc) 10.2 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod)), __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var hooks_exports = {}; __export(hooks_exports, { Frozen: () => Frozen, useActiveParams: () => useActiveParams, useGlobalSearchParams: () => useGlobalSearchParams, useLocalSearchParams: () => useLocalSearchParams, useNavigationContainerRef: () => useNavigationContainerRef, useParams: () => useParams, usePathname: () => usePathname, useRootNavigationState: () => useRootNavigationState, useRouteInfo: () => useRouteInfo, useRouter: () => useRouter, useSearchParams: () => useSearchParams, useSegments: () => useSegments, useUnstableGlobalHref: () => useUnstableGlobalHref }); module.exports = __toCommonJS(hooks_exports); var import_jsx_runtime = require("react/jsx-runtime"), import_react = __toESM(require("react"), 1), import_imperative_api = require("./router/imperative-api.native.js"), import_Route = require("./router/Route.native.js"), import_RouteInfoContext = require("./router/RouteInfoContext.native.js"), import_router = require("./router/router.native.js"); function _assert_this_initialized(self) { if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; } function _call_super(_this, derived, args) { return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _construct(Parent, args, Class) { return _is_native_reflect_construct() ? _construct = Reflect.construct : _construct = function (Parent2, args2, Class2) { var a = [null]; a.push.apply(a, args2); var Constructor = Function.bind.apply(Parent2, a), instance = new Constructor(); return Class2 && _set_prototype_of(instance, Class2.prototype), instance; }, _construct.apply(null, arguments); } 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 _get_prototype_of(o) { return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }, _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass != "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: !0, configurable: !0 } }), superClass && _set_prototype_of(subClass, superClass); } function _is_native_function(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } function _possible_constructor_return(self, call) { return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self); } function _set_prototype_of(o, p) { return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) { return o2.__proto__ = p2, o2; }, _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _wrap_native_super(Class) { var _cache = typeof Map == "function" ? /* @__PURE__ */new Map() : void 0; return _wrap_native_super = function (Class2) { if (Class2 === null || !_is_native_function(Class2)) return Class2; if (typeof Class2 != "function") throw new TypeError("Super expression must either be null or a function"); if (typeof _cache < "u") { if (_cache.has(Class2)) return _cache.get(Class2); _cache.set(Class2, Wrapper); } function Wrapper() { return _construct(Class2, arguments, _get_prototype_of(this).constructor); } return Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _set_prototype_of(Wrapper, Class2); }, _wrap_native_super(Class); } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch {} return (_is_native_reflect_construct = function () { return !!result; })(); } function useRootNavigationState() { return (0, import_router.useStoreRootState)(); } function useRouteInfo() { var routeInfoFromContext = (0, import_react.useContext)(import_RouteInfoContext.RouteInfoContext), routeInfoFromRootState = (0, import_router.useStoreRouteInfo)(), routeNode = (0, import_Route.useRouteNode)(); return routeNode?.type === "layout" ? routeInfoFromRootState : routeInfoFromContext || routeInfoFromRootState; } function useNavigationContainerRef() { return import_router.navigationRef; } var FrozeContext = /* @__PURE__ */(0, import_react.createContext)(!1); function Frozen(param) { var { on = !1, children } = param; return typeof window > "u" ? children : /* @__PURE__ */(0, import_jsx_runtime.jsx)(FrozeContext.Provider, { value: on, children: (/* <Freeze freeze={on}> */ /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", { ...(on && { inert: !0 }), style: { display: "contents" }, children })) }); } function useRouter() { return import_imperative_api.router; } function useUnstableGlobalHref() { return useRouteInfo().unstable_globalHref; } function useSegments() { return useRouteInfo().segments; } function usePathname() { return useRouteInfo().pathname; } function useActiveParams() { return useRouteInfo().params; } var useLocalSearchParams = useParams, useGlobalSearchParams = useActiveParams; function useParams() { var _React_useContext, params = (_React_useContext = import_react.default.useContext(import_Route.RouteParamsContext)) !== null && _React_useContext !== void 0 ? _React_useContext : {}; return import_react.default.useMemo(function () { return Object.fromEntries(Object.entries(params).filter(function (param) { var [_, value] = param; return value !== void 0; }).map(function (param) { var [key, value] = param; if (Array.isArray(value)) return [key, value.map(function (v) { try { return decodeURIComponent(v); } catch { return v; } })]; try { return [key, decodeURIComponent(value)]; } catch { return [key, value]; } })); }, [params]); } var ReadOnlyURLSearchParams = /* @__PURE__ */function (URLSearchParams1) { "use strict"; _inherits(ReadOnlyURLSearchParams2, URLSearchParams1); function ReadOnlyURLSearchParams2() { return _class_call_check(this, ReadOnlyURLSearchParams2), _call_super(this, ReadOnlyURLSearchParams2, arguments); } return _create_class(ReadOnlyURLSearchParams2, [{ key: "set", value: function (_name, _value) { throw new Error("useSearchParams returns a read-only URLSearchParams object"); } }, { key: "append", value: function (_name, _value) { throw new Error("useSearchParams returns a read-only URLSearchParams object"); } }, { key: "delete", value: function (_name, _value) { throw new Error("useSearchParams returns a read-only URLSearchParams object"); } }]), ReadOnlyURLSearchParams2; }(_wrap_native_super(URLSearchParams)); function useSearchParams() { var { global = !1 } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, globalRef = import_react.default.useRef(global); process.env.NODE_ENV !== "production" && global !== globalRef.current && console.warn("useSearchParams: the 'global' option cannot change between renders"); var params = global ? useActiveParams() : useParams(); return import_react.default.useMemo(function () { var entries = Object.entries(params).flatMap(function (param) { var [key, value] = param; return value === void 0 ? [] : Array.isArray(value) ? value.map(function (v) { return [key, String(v)]; }) : [[key, String(value)]]; }); return new ReadOnlyURLSearchParams(entries); }, [params]); } //# sourceMappingURL=hooks.native.js.map