UNPKG

one

Version:

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

219 lines (216 loc) • 9.43 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { Children, isValidElement, useMemo } from "react"; import { Platform } from "react-native"; import { dispatchSDKEvent, swiftStyleNative } from "./generated/swiftStyleNative.native.js"; import NativeContent from "./specs/OneNativeNavigationStackContentNativeComponent.native.js"; import NativeNavigationSplitView from "./specs/OneNativeNavigationSplitViewNativeComponent.native.js"; import NativeColumn from "./specs/OneNativeNavigationSplitViewColumnNativeComponent.native.js"; import { InsideContainer } from "./containerChildren.native.js"; import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemGroup, ToolbarNode, ToolbarSpacer } from "./NavigationStack.native.js"; import { viewportStyle } from "./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__ */ isValidElement(child)) return false; return child.type === ToolbarItem || child.type === ToolbarItemGroup || child.type === 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 = Children.toArray(entry.children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var child = _step.value; if (/* @__PURE__ */ isValidElement(child) && child.type === Toolbar) { toolbarCount += 1; if (toolbarCount > 1) throw new Error(`Swift.NavigationSplitView.${entry.name} accepts one Swift.Toolbar`); var toolbarChildren = 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__ */ isValidElement(toolbarChild) && toolbarChild.type === 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__ */ isValidElement(toolbarChild) && (toolbarChild.type === Toolbar || toolbarChild.type === 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__ */ isValidElement(child) && child.type === 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 = useMemo(function() { var found = /* @__PURE__ */ new Map(); var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var child = _step.value; if (!/* @__PURE__ */ 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 (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(Platform.Version)); var renderedColumns = entries.map(function(entry) { var { content, toolbarItems } = columnChildren(entry); return /* @__PURE__ */ jsxs(NativeColumn, { column: entry.name, style: COLUMN_MARKER_STYLE, swiftStyle: swiftStyleNative(entry.swiftStyle), onNativeSDKEvent: function onNativeSDKEvent(param2) { var { nativeEvent } = param2; return dispatchSDKEvent(entry.swiftStyle, nativeEvent.name, nativeEvent.value); }, children: [toolbarItems.length > 0 ? /* @__PURE__ */ jsx(ToolbarNode, { iosVersion, children: toolbarItems }) : null, /* @__PURE__ */ jsx(NativeContent, { collapsable: false, style: COLUMN_CONTENT_STYLE, children: /* @__PURE__ */ jsx(InsideContainer, { value: false, children: content }) })] }, entry.name); }); return /* @__PURE__ */ jsx(NativeNavigationSplitView, { ...props, style: 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: 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 dispatchSDKEvent(swiftStyle, nativeEvent.name, nativeEvent.value); }, children: renderedColumns }); } var NavigationSplitView = Object.assign(NavigationSplitViewView, { Sidebar, Content, Detail }); export { Content, Detail, NavigationSplitView, Sidebar }; //# sourceMappingURL=NavigationSplitView.native.js.map