one
Version:
One is a new React Framework that makes Vite serve both native and web.
76 lines (75 loc) • 3.2 kB
JavaScript
"use client";
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 StackScreen_exports = {};
__export(StackScreen_exports, {
StackScreen: () => StackScreen,
appendScreenStackPropsToOptions: () => appendScreenStackPropsToOptions,
validateStackPresentation: () => validateStackPresentation
});
module.exports = __toCommonJS(StackScreen_exports);
var import_react = require("react");
var import_children = require("../../headless/children.cjs");
var import_StackHeaderComponent = require("./StackHeaderComponent.cjs");
var import_StackToolbar = require("./StackToolbar.cjs");
var import_StackToolbarImplementation = require("./StackToolbarImplementation.cjs");
var import_Screen = require("../../views/Screen.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function StackScreen({
children,
options,
...rest
}) {
const toolbarImplementation = (0, import_StackToolbarImplementation.getStackToolbarImplementation)();
const updatedOptions = (0, import_react.useMemo)(() => appendScreenStackPropsToOptions(options ?? {}, {
children
}, toolbarImplementation), [options, children, toolbarImplementation]);
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
...rest,
options: updatedOptions
});
}
Object.assign(StackScreen, {
[import_children.NAVIGATOR_CONFIG]: true
});
function validateStackPresentation(options) {
if (typeof options === "function") return (...args) => {
return validateStackPresentation(options(...args));
};
return options;
}
function appendScreenStackPropsToOptions(options, props, toolbarImplementation) {
let updatedOptions = {
...options,
...props.options
};
updatedOptions = validateStackPresentation(updatedOptions);
function appendChildOptions(child, options2) {
if (child.type === import_StackHeaderComponent.StackHeaderComponent) return (0, import_StackHeaderComponent.appendStackHeaderPropsToOptions)(options2, child.props);else if (child.type === import_StackToolbar.StackToolbar) return (0, import_StackToolbar.appendStackToolbarPropsToOptions)(options2, child.props, toolbarImplementation);else console.warn(`Warning: Unknown child element passed to Stack.Screen: ${child.type.name ?? child.type}`);
return options2;
}
import_react.Children.forEach(props.children, child => {
if ((0, import_react.isValidElement)(child)) updatedOptions = appendChildOptions(child, updatedOptions);
});
return updatedOptions;
}