UNPKG

one

Version:

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

110 lines (107 loc) 5.05 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 withLayoutContext_exports = {}; __export(withLayoutContext_exports, { useFilterScreenChildren: () => useFilterScreenChildren, withLayoutContext: () => withLayoutContext }); module.exports = __toCommonJS(withLayoutContext_exports); var import_jsx_runtime = require("react/jsx-runtime"), import_react = __toESM(require("react"), 1), import_Route = require("../router/Route.native.js"), import_useScreens = require("../router/useScreens.native.js"), import_withStaticProperties = require("../utils/withStaticProperties.native.js"), import_Screen = require("../views/Screen.native.js"); function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function useFilterScreenChildren(children) { var { isCustomNavigator, contextKey } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : (/** Used for sending developer hints */ {}); return import_react.default.useMemo(function () { var _React_Children_map, customChildren = [], screens = (_React_Children_map = import_react.default.Children.map(children, function (child) { if (/* @__PURE__ */import_react.default.isValidElement(child) && child && child.type === import_Screen.Screen) { if (_type_of(child.props) === "object" && child.props && "name" in child.props && !child.props.name) throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must have a \`name\` prop when used as a child of a Layout Route.`); if (process.env.NODE_ENV !== "production" && ["children", "component", "getComponent"].some(function (key) { return child.props && _type_of(child.props) === "object" && key in child.props; })) throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must not have a \`children\`, \`component\`, or \`getComponent\` prop when used as a child of a Layout Route`); return child.props; } return isCustomNavigator ? customChildren.push(child) : console.warn(`Layout children must be of type Screen, all other children are ignored. To use custom children, create a custom <Layout />. Update Layout Route at: "app${contextKey}/_layout"`), null; })) === null || _React_Children_map === void 0 ? void 0 : _React_Children_map.filter(Boolean); if (process.env.NODE_ENV !== "production") { var names = screens?.map(function (screen) { return screen.name; }); if (names && new Set(names).size !== names.length) throw new Error("Screen names must be unique: " + names); } return { screens, children: customChildren }; }, [children, contextKey, isCustomNavigator]); } function withLayoutContext(Nav, processor, options) { return (0, import_withStaticProperties.withStaticProperties)(/* @__PURE__ */import_react.default.forwardRef(function (propsIn, ref) { var { children, ...props } = propsIn, contextKey = (0, import_Route.useContextKey)(), { screens } = useFilterScreenChildren(children, { contextKey }), processed = processor ? processor(screens ?? []) : screens, sorted = (0, import_useScreens.useSortedScreens)(processed ?? [], { onlyMatching: !0 }); return sorted.length ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(Nav, { ...options?.props, ...props, id: contextKey, ref, children: sorted }) : null; }), { Screen: import_Screen.Screen }); } //# sourceMappingURL=withLayoutContext.native.js.map