UNPKG

one

Version:

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

251 lines (249 loc) • 11.6 kB
"use strict"; 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 NavigationSplitView_native_exports = {}; __export(NavigationSplitView_native_exports, { Content: () => Content, Detail: () => Detail, NavigationSplitView: () => NavigationSplitView, Sidebar: () => Sidebar }); module.exports = __toCommonJS(NavigationSplitView_native_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_react = require("react"); var import_react_native = require("react-native"); var import_swiftStyleNative = require("./generated/swiftStyleNative.native.js"); var import_OneNativeNavigationStackContentNativeComponent = __toESM(require("./specs/OneNativeNavigationStackContentNativeComponent.native.js"), 1); var import_OneNativeNavigationSplitViewNativeComponent = __toESM(require("./specs/OneNativeNavigationSplitViewNativeComponent.native.js"), 1); var import_OneNativeNavigationSplitViewColumnNativeComponent = __toESM(require("./specs/OneNativeNavigationSplitViewColumnNativeComponent.native.js"), 1); var import_containerChildren = require("./containerChildren.native.js"); var import_NavigationStack = require("./NavigationStack.native.js"); var import_viewportStyle = require("./viewportStyle.native.js"); var COLUMN_CONTENT_STYLE = { position: "absolute", left: 0, top: 0 }; var COLUMN_MARKER_STYLE = { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" }; var columns = [ "sidebar", "content", "detail" ]; var visibilities = [ "automatic", "all", "doubleColumn", "detailOnly" ]; var Sidebar = function Sidebar2() { throw new Error("Swift.NavigationSplitView.Sidebar must be a direct child of Swift.NavigationSplitView"); }; var Content = function Content2() { throw new Error("Swift.NavigationSplitView.Content must be a direct child of Swift.NavigationSplitView"); }; var Detail = function Detail2() { throw new Error("Swift.NavigationSplitView.Detail must be a direct child of Swift.NavigationSplitView"); }; var columnForMarker = /* @__PURE__ */ new Map([ [Sidebar, "sidebar"], [Content, "content"], [Detail, "detail"] ]); function toolbarItem(child) { if (!/* @__PURE__ */ (0, import_react.isValidElement)(child)) return false; return child.type === import_NavigationStack.ToolbarItem || child.type === import_NavigationStack.ToolbarItemGroup || child.type === import_NavigationStack.ToolbarSpacer; } function columnChildren(entry) { var content = []; var toolbarItems = []; var toolbarCount = 0; var contentMarkerCount = 0; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = import_react.Children.toArray(entry.children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var child = _step.value; if (/* @__PURE__ */ (0, import_react.isValidElement)(child) && child.type === import_NavigationStack.Toolbar) { toolbarCount += 1; if (toolbarCount > 1) throw new Error(`Swift.NavigationSplitView.${entry.name} accepts one Swift.Toolbar`); var toolbarChildren = import_react.Children.toArray(child.props.children); var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0; try { for (var _iterator1 = toolbarChildren[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) { var toolbarChild = _step1.value; if (/* @__PURE__ */ (0, import_react.isValidElement)(toolbarChild) && toolbarChild.type === import_NavigationStack.ToolbarContent) { contentMarkerCount += 1; if (contentMarkerCount > 1) throw new Error(`Swift.NavigationSplitView.${entry.name} accepts one Swift.Toolbar.Content`); toolbarItems.push(toolbarChild); } else if (toolbarItem(toolbarChild)) { throw new Error(`Swift.NavigationSplitView.${entry.name} toolbar items must be inside Swift.Toolbar.Content`); } else if (/* @__PURE__ */ (0, import_react.isValidElement)(toolbarChild) && (toolbarChild.type === import_NavigationStack.Toolbar || toolbarChild.type === import_NavigationStack.ToolbarContent)) { throw new Error(`Swift.NavigationSplitView.${entry.name} toolbar markers must be direct children`); } else { content.push(toolbarChild); } } } catch (err) { _didIteratorError1 = true; _iteratorError1 = err; } finally { try { if (!_iteratorNormalCompletion1 && _iterator1.return != null) { _iterator1.return(); } } finally { if (_didIteratorError1) { throw _iteratorError1; } } } continue; } if (/* @__PURE__ */ (0, import_react.isValidElement)(child) && child.type === import_NavigationStack.ToolbarContent) throw new Error(`Swift.Toolbar.Content must be inside Swift.Toolbar in Swift.NavigationSplitView.${entry.name}`); if (toolbarItem(child)) throw new Error(`Swift.NavigationSplitView.${entry.name} toolbar items must be inside Swift.Toolbar`); content.push(child); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } if (content.length === 0) throw new Error(`Swift.NavigationSplitView.${entry.name} needs column content`); return { content, toolbarItems }; } function NavigationSplitViewView(param) { var { children, columnVisibility, onColumnVisibilityChange, preferredCompactColumn, onPreferredCompactColumnChange, swiftStyle, style, ...props } = param; var entries = (0, import_react.useMemo)(function() { var found = /* @__PURE__ */ new Map(); var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = import_react.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var child = _step.value; if (!/* @__PURE__ */ (0, import_react.isValidElement)(child)) throw new Error("Swift.NavigationSplitView children must be direct Sidebar, Content, or Detail elements"); var element = child; var name = columnForMarker.get(element.type); if (!name) throw new Error("Swift.NavigationSplitView accepts direct Sidebar, Content, and Detail elements"); if (found.has(name)) throw new Error(`Swift.NavigationSplitView accepts one ${name} column`); if (import_react.Children.count(element.props.children) === 0) throw new Error(`Swift.NavigationSplitView.${name} needs children`); found.set(name, { name, children: element.props.children, swiftStyle: element.props.swiftStyle }); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } if (!found.has("sidebar")) throw new Error("Swift.NavigationSplitView needs a Sidebar column"); if (!found.has("detail")) throw new Error("Swift.NavigationSplitView needs a Detail column"); return columns.flatMap(function(name2) { return found.has(name2) ? [found.get(name2)] : []; }); }, [children]); if (columnVisibility !== void 0 && !visibilities.includes(columnVisibility)) throw new Error(`Swift.NavigationSplitView columnVisibility must be one of ${visibilities.join(", ")}`); if (preferredCompactColumn !== void 0 && !columns.includes(preferredCompactColumn)) throw new Error(`Swift.NavigationSplitView preferredCompactColumn must be one of ${columns.join(", ")}`); var iosVersion = Number.parseFloat(String(import_react_native.Platform.Version)); var renderedColumns = entries.map(function(entry) { var { content, toolbarItems } = columnChildren(entry); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_OneNativeNavigationSplitViewColumnNativeComponent.default, { column: entry.name, style: COLUMN_MARKER_STYLE, swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(entry.swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return (0, import_swiftStyleNative.dispatchSDKEvent)(entry.swiftStyle, nativeEvent.name, nativeEvent.value); }, children: [toolbarItems.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_NavigationStack.ToolbarNode, { iosVersion, children: toolbarItems }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeNavigationStackContentNativeComponent.default, { collapsable: false, style: COLUMN_CONTENT_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_containerChildren.InsideContainer, { value: false, children: content }) })] }, entry.name); }); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeNavigationSplitViewNativeComponent.default, { ...props, style: (0, import_viewportStyle.viewportStyle)(style), columnVisibility: columnVisibility !== null && columnVisibility !== void 0 ? columnVisibility : "automatic", columnVisibilityIsControlled: columnVisibility !== void 0, preferredCompactColumn: preferredCompactColumn !== null && preferredCompactColumn !== void 0 ? preferredCompactColumn : "sidebar", preferredCompactColumnIsControlled: preferredCompactColumn !== void 0, swiftStyle: (0, import_swiftStyleNative.swiftStyleNative)(swiftStyle), onNativeNavigationSplitViewColumnVisibilityChange: function onNativeNavigationSplitViewColumnVisibilityChange(param2) { var { nativeEvent } = param2; return onColumnVisibilityChange === null || onColumnVisibilityChange === void 0 ? void 0 : onColumnVisibilityChange(nativeEvent.visibility); }, onNativeNavigationSplitViewPreferredCompactColumnChange: function onNativeNavigationSplitViewPreferredCompactColumnChange(param2) { var { nativeEvent } = param2; return onPreferredCompactColumnChange === null || onPreferredCompactColumnChange === void 0 ? void 0 : onPreferredCompactColumnChange(nativeEvent.column); }, onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return (0, import_swiftStyleNative.dispatchSDKEvent)(swiftStyle, nativeEvent.name, nativeEvent.value); }, children: renderedColumns }); } var NavigationSplitView = Object.assign(NavigationSplitViewView, { Sidebar, Content, Detail });