UNPKG

one

Version:

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

473 lines (470 loc) • 25.6 kB
"use strict"; 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 menuItems_exports = {}; __export(menuItems_exports, { flattenMenuItems: () => flattenMenuItems }); module.exports = __toCommonJS(menuItems_exports); var import_swiftui = require("./generated/swiftui.native.js"); function flattenMenuItems(items) { var iosVersion = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 17; var result = []; var ids = /* @__PURE__ */ new Set(); var append = function append1(items2, parentId, disabled, hidden) { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { var _loop = function() { var item = _step.value; var input = item; switch (item.type) { case "action": { var _input_id, _input_title, _input_systemImage, _input_role, _input_disabled, _input_hidden, _input_help, _input_menuActionDismissBehavior; var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0; try { for (var _iterator2 = Object.keys(input)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion2 = (_step1 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var name = _step1.value; if (name !== "type" && name !== "id" && name !== "title" && name !== "systemImage" && name !== "role" && name !== "disabled" && name !== "hidden" && name !== "help" && name !== "menuActionDismissBehavior") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name); } } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; } finally { try { if (!_iteratorNormalCompletion2 && _iterator2.return != null) { _iterator2.return(); } } finally { if (_didIteratorError2) { throw _iteratorError2; } } } var id = (_input_id = input.id) !== null && _input_id !== void 0 ? _input_id : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id !== "string") throw new Error("Invalid Swift.Menu id"); var title = (_input_title = input.title) !== null && _input_title !== void 0 ? _input_title : ""; if (input.title == null) throw new Error("Swift.Menu " + item.type + " requires title"); if (typeof title !== "string") throw new Error("Invalid Swift.Menu title"); var systemImage = (_input_systemImage = input.systemImage) !== null && _input_systemImage !== void 0 ? _input_systemImage : ""; if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage"); var role = (_input_role = input.role) !== null && _input_role !== void 0 ? _input_role : ""; if (typeof role !== "string") throw new Error("Invalid Swift.Menu role"); if (role !== "") (0, import_swiftui.assertSwiftUIValue)("ButtonRole", role, iosVersion); var disabledValue = (_input_disabled = input.disabled) !== null && _input_disabled !== void 0 ? _input_disabled : false; if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled"); var hiddenValue = (_input_hidden = input.hidden) !== null && _input_hidden !== void 0 ? _input_hidden : false; if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden"); var help = (_input_help = input.help) !== null && _input_help !== void 0 ? _input_help : ""; if (typeof help !== "string") throw new Error("Invalid Swift.Menu help"); var menuActionDismissBehavior = (_input_menuActionDismissBehavior = input.menuActionDismissBehavior) !== null && _input_menuActionDismissBehavior !== void 0 ? _input_menuActionDismissBehavior : ""; if (typeof menuActionDismissBehavior !== "string") throw new Error("Invalid Swift.Menu menuActionDismissBehavior"); if (menuActionDismissBehavior !== "") (0, import_swiftui.assertSwiftUIValue)("MenuActionDismissBehavior", menuActionDismissBehavior, iosVersion); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id, title, systemImage, role, disabled: disabled || disabledValue, hidden: hidden || hiddenValue, help, controlGroupStyle: "automatic", values: [], selection: "", menuOrder: "", menuActionDismissBehavior, parentId, type: item.type }); break; } case "toggle": { var _input_id1, _input_title1, _input_systemImage1, _input_values, _input_disabled1, _input_hidden1, _input_help1, _input_menuActionDismissBehavior1; var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0; try { for (var _iterator1 = Object.keys(input)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion1 = (_step2 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) { var name1 = _step2.value; if (name1 !== "type" && name1 !== "id" && name1 !== "title" && name1 !== "systemImage" && name1 !== "values" && name1 !== "disabled" && name1 !== "hidden" && name1 !== "help" && name1 !== "menuActionDismissBehavior") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name1); } } catch (err) { _didIteratorError1 = true; _iteratorError1 = err; } finally { try { if (!_iteratorNormalCompletion1 && _iterator1.return != null) { _iterator1.return(); } } finally { if (_didIteratorError1) { throw _iteratorError1; } } } var id1 = (_input_id1 = input.id) !== null && _input_id1 !== void 0 ? _input_id1 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id1 !== "string") throw new Error("Invalid Swift.Menu id"); var title1 = (_input_title1 = input.title) !== null && _input_title1 !== void 0 ? _input_title1 : ""; if (input.title == null) throw new Error("Swift.Menu " + item.type + " requires title"); if (typeof title1 !== "string") throw new Error("Invalid Swift.Menu title"); var systemImage1 = (_input_systemImage1 = input.systemImage) !== null && _input_systemImage1 !== void 0 ? _input_systemImage1 : ""; if (typeof systemImage1 !== "string") throw new Error("Invalid Swift.Menu systemImage"); var values = (_input_values = input.values) !== null && _input_values !== void 0 ? _input_values : []; if (input.values == null) throw new Error("Swift.Menu " + item.type + " requires values"); if (!Array.isArray(values) || !values.length || values.some(function(v) { return typeof v !== "boolean"; })) throw new Error("Swift.Menu toggle values must be a nonempty boolean array"); var disabledValue1 = (_input_disabled1 = input.disabled) !== null && _input_disabled1 !== void 0 ? _input_disabled1 : false; if (typeof disabledValue1 !== "boolean") throw new Error("Invalid Swift.Menu disabled"); var hiddenValue1 = (_input_hidden1 = input.hidden) !== null && _input_hidden1 !== void 0 ? _input_hidden1 : false; if (typeof hiddenValue1 !== "boolean") throw new Error("Invalid Swift.Menu hidden"); var help1 = (_input_help1 = input.help) !== null && _input_help1 !== void 0 ? _input_help1 : ""; if (typeof help1 !== "string") throw new Error("Invalid Swift.Menu help"); var menuActionDismissBehavior1 = (_input_menuActionDismissBehavior1 = input.menuActionDismissBehavior) !== null && _input_menuActionDismissBehavior1 !== void 0 ? _input_menuActionDismissBehavior1 : ""; if (typeof menuActionDismissBehavior1 !== "string") throw new Error("Invalid Swift.Menu menuActionDismissBehavior"); if (menuActionDismissBehavior1 !== "") (0, import_swiftui.assertSwiftUIValue)("MenuActionDismissBehavior", menuActionDismissBehavior1, iosVersion); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id1, title: title1, systemImage: systemImage1, role: "", disabled: disabled || disabledValue1, hidden: hidden || hiddenValue1, help: help1, controlGroupStyle: "automatic", values, selection: "", menuOrder: "", menuActionDismissBehavior: menuActionDismissBehavior1, parentId, type: item.type }); break; } case "submenu": { var _input_id2, _input_title2, _input_systemImage2, _input_disabled2, _input_hidden2, _input_help2, _input_menuOrder, _input_menuActionDismissBehavior2; var _iteratorNormalCompletion22 = true, _didIteratorError22 = false, _iteratorError22 = void 0; try { for (var _iterator22 = Object.keys(input)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion22 = (_step3 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) { var name2 = _step3.value; if (name2 !== "type" && name2 !== "id" && name2 !== "title" && name2 !== "systemImage" && name2 !== "disabled" && name2 !== "hidden" && name2 !== "help" && name2 !== "menuOrder" && name2 !== "menuActionDismissBehavior" && name2 !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name2); } } catch (err) { _didIteratorError22 = true; _iteratorError22 = err; } finally { try { if (!_iteratorNormalCompletion22 && _iterator22.return != null) { _iterator22.return(); } } finally { if (_didIteratorError22) { throw _iteratorError22; } } } var id2 = (_input_id2 = input.id) !== null && _input_id2 !== void 0 ? _input_id2 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id2 !== "string") throw new Error("Invalid Swift.Menu id"); var title2 = (_input_title2 = input.title) !== null && _input_title2 !== void 0 ? _input_title2 : ""; if (input.title == null) throw new Error("Swift.Menu " + item.type + " requires title"); if (typeof title2 !== "string") throw new Error("Invalid Swift.Menu title"); var systemImage2 = (_input_systemImage2 = input.systemImage) !== null && _input_systemImage2 !== void 0 ? _input_systemImage2 : ""; if (typeof systemImage2 !== "string") throw new Error("Invalid Swift.Menu systemImage"); var disabledValue2 = (_input_disabled2 = input.disabled) !== null && _input_disabled2 !== void 0 ? _input_disabled2 : false; if (typeof disabledValue2 !== "boolean") throw new Error("Invalid Swift.Menu disabled"); var hiddenValue2 = (_input_hidden2 = input.hidden) !== null && _input_hidden2 !== void 0 ? _input_hidden2 : false; if (typeof hiddenValue2 !== "boolean") throw new Error("Invalid Swift.Menu hidden"); var help2 = (_input_help2 = input.help) !== null && _input_help2 !== void 0 ? _input_help2 : ""; if (typeof help2 !== "string") throw new Error("Invalid Swift.Menu help"); var menuOrder = (_input_menuOrder = input.menuOrder) !== null && _input_menuOrder !== void 0 ? _input_menuOrder : ""; if (typeof menuOrder !== "string") throw new Error("Invalid Swift.Menu menuOrder"); if (menuOrder !== "") (0, import_swiftui.assertSwiftUIValue)("MenuOrder", menuOrder, iosVersion); var menuActionDismissBehavior2 = (_input_menuActionDismissBehavior2 = input.menuActionDismissBehavior) !== null && _input_menuActionDismissBehavior2 !== void 0 ? _input_menuActionDismissBehavior2 : ""; if (typeof menuActionDismissBehavior2 !== "string") throw new Error("Invalid Swift.Menu menuActionDismissBehavior"); if (menuActionDismissBehavior2 !== "") (0, import_swiftui.assertSwiftUIValue)("MenuActionDismissBehavior", menuActionDismissBehavior2, iosVersion); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id2, title: title2, systemImage: systemImage2, role: "", disabled: disabled || disabledValue2, hidden: hidden || hiddenValue2, help: help2, controlGroupStyle: "automatic", values: [], selection: "", menuOrder, menuActionDismissBehavior: menuActionDismissBehavior2, parentId, type: item.type }); if (!Array.isArray(input.children)) throw new Error("Swift.Menu " + item.type + " requires children"); append(input.children, item.id, Boolean(disabled || disabledValue2), Boolean(hidden || hiddenValue2)); break; } case "section": { var _input_id3, _input_title3, _input_hidden3; var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0; try { for (var _iterator3 = Object.keys(input)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion3 = (_step4 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { var name3 = _step4.value; if (name3 !== "type" && name3 !== "id" && name3 !== "title" && name3 !== "hidden" && name3 !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name3); } } catch (err) { _didIteratorError3 = true; _iteratorError3 = err; } finally { try { if (!_iteratorNormalCompletion3 && _iterator3.return != null) { _iterator3.return(); } } finally { if (_didIteratorError3) { throw _iteratorError3; } } } var id3 = (_input_id3 = input.id) !== null && _input_id3 !== void 0 ? _input_id3 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id3 !== "string") throw new Error("Invalid Swift.Menu id"); var title3 = (_input_title3 = input.title) !== null && _input_title3 !== void 0 ? _input_title3 : ""; if (typeof title3 !== "string") throw new Error("Invalid Swift.Menu title"); var hiddenValue3 = (_input_hidden3 = input.hidden) !== null && _input_hidden3 !== void 0 ? _input_hidden3 : false; if (typeof hiddenValue3 !== "boolean") throw new Error("Invalid Swift.Menu hidden"); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id3, title: title3, systemImage: "", role: "", disabled: disabled || false, hidden: hidden || hiddenValue3, help: "", controlGroupStyle: "automatic", values: [], selection: "", menuOrder: "", menuActionDismissBehavior: "", parentId, type: item.type }); if (!Array.isArray(input.children)) throw new Error("Swift.Menu " + item.type + " requires children"); append(input.children, item.id, Boolean(disabled || false), Boolean(hidden || hiddenValue3)); break; } case "controlGroup": { var _input_id4, _input_title4, _input_systemImage3, _input_disabled3, _input_hidden4, _input_controlGroupStyle; var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = void 0; try { for (var _iterator4 = Object.keys(input)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion4 = (_step5 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { var name4 = _step5.value; if (name4 !== "type" && name4 !== "id" && name4 !== "title" && name4 !== "systemImage" && name4 !== "disabled" && name4 !== "hidden" && name4 !== "controlGroupStyle" && name4 !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name4); } } catch (err) { _didIteratorError4 = true; _iteratorError4 = err; } finally { try { if (!_iteratorNormalCompletion4 && _iterator4.return != null) { _iterator4.return(); } } finally { if (_didIteratorError4) { throw _iteratorError4; } } } var id4 = (_input_id4 = input.id) !== null && _input_id4 !== void 0 ? _input_id4 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id4 !== "string") throw new Error("Invalid Swift.Menu id"); var title4 = (_input_title4 = input.title) !== null && _input_title4 !== void 0 ? _input_title4 : ""; if (typeof title4 !== "string") throw new Error("Invalid Swift.Menu title"); var systemImage3 = (_input_systemImage3 = input.systemImage) !== null && _input_systemImage3 !== void 0 ? _input_systemImage3 : ""; if (typeof systemImage3 !== "string") throw new Error("Invalid Swift.Menu systemImage"); var disabledValue3 = (_input_disabled3 = input.disabled) !== null && _input_disabled3 !== void 0 ? _input_disabled3 : false; if (typeof disabledValue3 !== "boolean") throw new Error("Invalid Swift.Menu disabled"); var hiddenValue4 = (_input_hidden4 = input.hidden) !== null && _input_hidden4 !== void 0 ? _input_hidden4 : false; if (typeof hiddenValue4 !== "boolean") throw new Error("Invalid Swift.Menu hidden"); var controlGroupStyle = (_input_controlGroupStyle = input.controlGroupStyle) !== null && _input_controlGroupStyle !== void 0 ? _input_controlGroupStyle : "automatic"; if (typeof controlGroupStyle !== "string") throw new Error("Invalid Swift.Menu controlGroupStyle"); (0, import_swiftui.assertSwiftUIValue)("ControlGroupStyle", controlGroupStyle, iosVersion); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id4, title: title4, systemImage: systemImage3, role: "", disabled: disabled || disabledValue3, hidden: hidden || hiddenValue4, help: "", controlGroupStyle, values: [], selection: "", menuOrder: "", menuActionDismissBehavior: "", parentId, type: item.type }); if (!Array.isArray(input.children)) throw new Error("Swift.Menu " + item.type + " requires children"); append(input.children, item.id, Boolean(disabled || disabledValue3), Boolean(hidden || hiddenValue4)); break; } case "picker": { var _input_id5, _input_title5, _input_systemImage4, _input_selection, _input_disabled4, _input_hidden5, _input_help3; var _iteratorNormalCompletion5 = true, _didIteratorError5 = false, _iteratorError5 = void 0; try { for (var _iterator5 = Object.keys(input)[Symbol.iterator](), _step6; !(_iteratorNormalCompletion5 = (_step6 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { var name5 = _step6.value; if (name5 !== "type" && name5 !== "id" && name5 !== "title" && name5 !== "systemImage" && name5 !== "selection" && name5 !== "disabled" && name5 !== "hidden" && name5 !== "help" && name5 !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name5); } } catch (err) { _didIteratorError5 = true; _iteratorError5 = err; } finally { try { if (!_iteratorNormalCompletion5 && _iterator5.return != null) { _iterator5.return(); } } finally { if (_didIteratorError5) { throw _iteratorError5; } } } var id5 = (_input_id5 = input.id) !== null && _input_id5 !== void 0 ? _input_id5 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id5 !== "string") throw new Error("Invalid Swift.Menu id"); var title5 = (_input_title5 = input.title) !== null && _input_title5 !== void 0 ? _input_title5 : ""; if (input.title == null) throw new Error("Swift.Menu " + item.type + " requires title"); if (typeof title5 !== "string") throw new Error("Invalid Swift.Menu title"); var systemImage4 = (_input_systemImage4 = input.systemImage) !== null && _input_systemImage4 !== void 0 ? _input_systemImage4 : ""; if (typeof systemImage4 !== "string") throw new Error("Invalid Swift.Menu systemImage"); var selection = (_input_selection = input.selection) !== null && _input_selection !== void 0 ? _input_selection : ""; if (input.selection == null) throw new Error("Swift.Menu " + item.type + " requires selection"); if (typeof selection !== "string") throw new Error("Invalid Swift.Menu selection"); var disabledValue4 = (_input_disabled4 = input.disabled) !== null && _input_disabled4 !== void 0 ? _input_disabled4 : false; if (typeof disabledValue4 !== "boolean") throw new Error("Invalid Swift.Menu disabled"); var hiddenValue5 = (_input_hidden5 = input.hidden) !== null && _input_hidden5 !== void 0 ? _input_hidden5 : false; if (typeof hiddenValue5 !== "boolean") throw new Error("Invalid Swift.Menu hidden"); var help3 = (_input_help3 = input.help) !== null && _input_help3 !== void 0 ? _input_help3 : ""; if (typeof help3 !== "string") throw new Error("Invalid Swift.Menu help"); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id5, title: title5, systemImage: systemImage4, role: "", disabled: disabled || disabledValue4, hidden: hidden || hiddenValue5, help: help3, controlGroupStyle: "automatic", values: [], selection, menuOrder: "", menuActionDismissBehavior: "", parentId, type: item.type }); if (!Array.isArray(input.children)) throw new Error("Swift.Menu " + item.type + " requires children"); if (!input.children.length || input.children.some(function(child) { return (child === null || child === void 0 ? void 0 : child.type) !== "action"; })) throw new Error("Swift.Menu picker children must be actions"); if (!input.children.some(function(child) { return child.id === input.selection; })) throw new Error("Swift.Menu picker selection must match a child id"); append(input.children, item.id, Boolean(disabled || disabledValue4), Boolean(hidden || hiddenValue5)); break; } case "divider": { var _input_id6; var _iteratorNormalCompletion6 = true, _didIteratorError6 = false, _iteratorError6 = void 0; try { for (var _iterator6 = Object.keys(input)[Symbol.iterator](), _step7; !(_iteratorNormalCompletion6 = (_step7 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { var name6 = _step7.value; if (name6 !== "type" && name6 !== "id") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name6); } } catch (err) { _didIteratorError6 = true; _iteratorError6 = err; } finally { try { if (!_iteratorNormalCompletion6 && _iterator6.return != null) { _iterator6.return(); } } finally { if (_didIteratorError6) { throw _iteratorError6; } } } var id6 = (_input_id6 = input.id) !== null && _input_id6 !== void 0 ? _input_id6 : ""; if (input.id == null) throw new Error("Swift.Menu " + item.type + " requires id"); if (typeof id6 !== "string") throw new Error("Invalid Swift.Menu id"); if (!item.id || ids.has(item.id)) throw new Error("Swift.Menu requires unique, nonempty item ids: \"" + item.id + "\""); ids.add(item.id); result.push({ id: id6, title: "", systemImage: "", role: "", disabled: disabled || false, hidden: hidden || false, help: "", controlGroupStyle: "automatic", values: [], selection: "", menuOrder: "", menuActionDismissBehavior: "", parentId, type: item.type }); break; } default: throw new Error("Unknown Swift.Menu item type: " + input.type); } }; for (var _iterator = items2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } }; append(items, "", false, false); return result; } //# sourceMappingURL=menuItems.native.js.map