UNPKG

one

Version:

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

114 lines (112 loc) • 4.88 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 Menu_native_exports = {}; __export(Menu_native_exports, { ContextMenu: () => ContextMenu, Menu: () => Menu }); module.exports = __toCommonJS(Menu_native_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_controlled = require("./controlled.native.js"); var import_react = require("react"); var import_react_native = require("react-native"); var import_OneNativeMenuNativeComponent = __toESM(require("./specs/OneNativeMenuNativeComponent.native.js"), 1); var import_menuItems = require("./menuItems.native.js"); var import_swiftui = require("./generated/swiftui.native.js"); function Menu(props) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, { ...props, presentation: "menu" }); } function ContextMenu(props) { var _props_accessibilityLabel; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, { ...props, accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : "", presentation: "contextMenu" }); } function MenuPresentation(param) { var { items, onAction, primaryAction, children, onValueChange, onPickerChange, revision = 0, menuOrder = "automatic", menuActionDismissBehavior = "automatic", disabled = false, accessibilityLabel, presentation, ...props } = param; var iosVersion = Number.parseFloat(String(import_react_native.Platform.Version)); (0, import_swiftui.assertSwiftUIValue)("MenuOrder", menuOrder, iosVersion); (0, import_swiftui.assertSwiftUIValue)("MenuActionDismissBehavior", menuActionDismissBehavior, iosVersion); var nativeItems = (0, import_react.useMemo)(function() { return (0, import_menuItems.flattenMenuItems)(items, iosVersion); }, [items, iosVersion]); if (!onValueChange && nativeItems.some(function(item) { return item.type === "toggle"; })) { var name = presentation === "contextMenu" ? "ContextMenu" : "Menu"; throw new Error(`Swift.${name} with toggles requires onValueChange`); } if (!onPickerChange && nativeItems.some(function(item) { return item.type === "picker"; })) { throw new Error("Swift.Menu with a Picker requires onPickerChange"); } var controlled = (0, import_controlled.useControlled)(function(event) { return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(event.id, event.value, event.sourceIndex); }, revision); var pickerControlled = (0, import_controlled.useControlled)(function(event) { return onPickerChange === null || onPickerChange === void 0 ? void 0 : onPickerChange(event.id, event.value); }, revision); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneNativeMenuNativeComponent.default, { ...props, items: nativeItems, revision, acknowledgedEvent: controlled.acknowledgedEvent, pickerAcknowledgedEvent: pickerControlled.acknowledgedEvent, menuOrder, menuActionDismissBehavior, triggerLabel: accessibilityLabel, disabled, hasPrimaryAction: presentation === "menu" && !!primaryAction, presentation, onNativeMenuAction: function onNativeMenuAction(param2) { var { nativeEvent } = param2; return onAction(nativeEvent.id); }, onNativeMenuPrimaryAction: function onNativeMenuPrimaryAction() { return primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction(); }, onNativeMenuValueChange: function onNativeMenuValueChange(param2) { var { nativeEvent } = param2; return controlled.onNativeChange(nativeEvent); }, onNativeMenuPickerChange: function onNativeMenuPickerChange(param2) { var { nativeEvent } = param2; return pickerControlled.onNativeChange(nativeEvent); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { collapsable: false, children }) }); }