UNPKG

one

Version:

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

124 lines (123 loc) • 5.49 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var Stack_exports = {}; __export(Stack_exports, { Stack: () => Stack, default: () => Stack_default }); module.exports = __toCommonJS(Stack_exports); var import_react = __toESM(require("react"), 1); var import_children = require("../utils/children.cjs"); var import_Protected = require("../views/Protected.cjs"); var import_Screen = require("../views/Screen.cjs"); var import_stack_navigator = require("./stack-navigator.cjs"); var import_stack_utils = require("./stack-utils/index.cjs"); var import_withLayoutContext = require("./withLayoutContext.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); const NativeStackNavigator = (0, import_stack_navigator.createStackNavigator)().Navigator; const RNStack = (0, import_withLayoutContext.withLayoutContext)(NativeStackNavigator, void 0, { undeclaredRoutes: true }); function mapChildren(children) { return import_react.Children.toArray(children).map((child, index) => { if ((0, import_children.isChildOfType)(child, import_stack_utils.StackScreen)) { const options = (0, import_stack_utils.appendScreenStackPropsToOptions)({}, child.props); const { children: _, ...rest } = child.props; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Screen.Screen, { ...rest, options }, child.props.name ?? index); } if ((0, import_children.isChildOfType)(child, import_Protected.Protected)) { return import_react.default.cloneElement(child, { key: `protected-${index}` }, mapChildren(child.props.children)); } if ((0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent)) { return null; } if ((0, import_children.isChildOfType)(child, import_stack_utils.StackToolbarComponent)) { return null; } if ((0, import_children.isChildOfType)(child, import_Screen.Screen)) { return child; } return null; }).filter(Boolean); } const StackWithComposition = import_react.default.forwardRef((props, ref) => { const { children, screenOptions, ...rest } = props; const screenOptionsWithHeader = (0, import_react.useMemo)(() => { const stackHeader = import_react.Children.toArray(children).find((child) => (0, import_children.isChildOfType)(child, import_stack_utils.StackHeaderComponent)); const stackToolbars = import_react.Children.toArray(children).filter((child) => (0, import_children.isChildOfType)(child, import_stack_utils.StackToolbarComponent)); if (!stackHeader && !stackToolbars.length) return screenOptions; const applyComposition = (opts) => { let result = opts; for (const stackToolbar of stackToolbars) { result = (0, import_stack_utils.appendStackToolbarPropsToOptions)(result, stackToolbar.props); } if (stackHeader && (0, import_children.isChildOfType)(stackHeader, import_stack_utils.StackHeaderComponent)) { const headerProps = { children: stackHeader }; result = (0, import_stack_utils.appendScreenStackPropsToOptions)(result, headerProps); } return result; }; if (screenOptions) { if (typeof screenOptions === "function") { return (...args) => { const opts = screenOptions(...args); return applyComposition(opts); }; } return applyComposition(screenOptions); } return applyComposition({}); }, [children, screenOptions]); const processedChildren = (0, import_react.useMemo)(() => mapChildren(children), [children]); const navigatorProps = (0, import_react.useMemo)(() => (0, import_stack_navigator.getStackNavigatorProps)(children), [children]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNStack, { ...rest, ...navigatorProps, ref, screenOptions: screenOptionsWithHeader, children: processedChildren }); }); const StackToolbar = Object.assign(import_stack_utils.StackToolbarComponent, { Button: import_stack_utils.StackToolbarButton, Menu: import_stack_utils.StackToolbarMenu, MenuAction: import_stack_utils.StackToolbarMenuAction, Spacer: import_stack_utils.StackToolbarSpacer, SearchBarSlot: import_stack_utils.StackToolbarSearchBarSlot, Label: import_stack_utils.StackToolbarLabel, Icon: import_stack_utils.StackToolbarIcon, Badge: import_stack_utils.StackToolbarBadge }); const Stack = Object.assign(StackWithComposition, { Screen: import_stack_utils.StackScreen, Header: import_stack_utils.StackHeader, Toolbar: StackToolbar, Protected: import_Protected.Protected, SearchBar: import_stack_utils.StackHeaderSearchBar }); var Stack_default = Stack;