one
Version:
One is a React framework for web, iOS, and Android apps.
318 lines (317 loc) • 15.9 kB
JavaScript
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.cjs");
function flattenMenuItems(items, iosVersion = 17) {
const result = [];
const ids = /* @__PURE__ */ new Set();
const append = (items2, parentId, disabled, hidden) => {
for (const item of items2) {
const input = item;
switch (item.type) {
case "action": {
for (const name of Object.keys(input)) {
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);
}
const id = 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");
const title = 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");
const systemImage = input.systemImage ?? "";
if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage");
const role = input.role ?? "";
if (typeof role !== "string") throw new Error("Invalid Swift.Menu role");
if (role !== "") (0, import_swiftui.assertSwiftUIValue)("ButtonRole", role, iosVersion);
const disabledValue = input.disabled ?? false;
if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden");
const help = input.help ?? "";
if (typeof help !== "string") throw new Error("Invalid Swift.Menu help");
const menuActionDismissBehavior = 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": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id" && name !== "title" && name !== "systemImage" && name !== "values" && name !== "disabled" && name !== "hidden" && name !== "help" && name !== "menuActionDismissBehavior") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
const title = 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");
const systemImage = input.systemImage ?? "";
if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage");
const values = input.values ?? [];
if (input.values == null) throw new Error("Swift.Menu " + item.type + " requires values");
if (!Array.isArray(values) || !values.length || values.some((v) => typeof v !== "boolean")) throw new Error("Swift.Menu toggle values must be a nonempty boolean array");
const disabledValue = input.disabled ?? false;
if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden");
const help = input.help ?? "";
if (typeof help !== "string") throw new Error("Invalid Swift.Menu help");
const menuActionDismissBehavior = 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 "submenu": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id" && name !== "title" && name !== "systemImage" && name !== "disabled" && name !== "hidden" && name !== "help" && name !== "menuOrder" && name !== "menuActionDismissBehavior" && name !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
const title = 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");
const systemImage = input.systemImage ?? "";
if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage");
const disabledValue = input.disabled ?? false;
if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden");
const help = input.help ?? "";
if (typeof help !== "string") throw new Error("Invalid Swift.Menu help");
const menuOrder = input.menuOrder ?? "";
if (typeof menuOrder !== "string") throw new Error("Invalid Swift.Menu menuOrder");
if (menuOrder !== "") (0, import_swiftui.assertSwiftUIValue)("MenuOrder", menuOrder, iosVersion);
const menuActionDismissBehavior = 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
});
if (!Array.isArray(input.children)) throw new Error("Swift.Menu " + item.type + " requires children");
append(input.children, item.id, Boolean(disabled || disabledValue), Boolean(hidden || hiddenValue));
break;
}
case "section": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id" && name !== "title" && name !== "hidden" && name !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
const title = input.title ?? "";
if (typeof title !== "string") throw new Error("Invalid Swift.Menu title");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "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,
title,
systemImage: "",
role: "",
disabled: disabled || false,
hidden: hidden || hiddenValue,
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 || hiddenValue));
break;
}
case "controlGroup": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id" && name !== "title" && name !== "systemImage" && name !== "disabled" && name !== "hidden" && name !== "controlGroupStyle" && name !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
const title = input.title ?? "";
if (typeof title !== "string") throw new Error("Invalid Swift.Menu title");
const systemImage = input.systemImage ?? "";
if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage");
const disabledValue = input.disabled ?? false;
if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden");
const controlGroupStyle = 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,
title,
systemImage,
role: "",
disabled: disabled || disabledValue,
hidden: hidden || hiddenValue,
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 || disabledValue), Boolean(hidden || hiddenValue));
break;
}
case "picker": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id" && name !== "title" && name !== "systemImage" && name !== "selection" && name !== "disabled" && name !== "hidden" && name !== "help" && name !== "children") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
const title = 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");
const systemImage = input.systemImage ?? "";
if (typeof systemImage !== "string") throw new Error("Invalid Swift.Menu systemImage");
const selection = 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");
const disabledValue = input.disabled ?? false;
if (typeof disabledValue !== "boolean") throw new Error("Invalid Swift.Menu disabled");
const hiddenValue = input.hidden ?? false;
if (typeof hiddenValue !== "boolean") throw new Error("Invalid Swift.Menu hidden");
const help = input.help ?? "";
if (typeof help !== "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,
title,
systemImage,
role: "",
disabled: disabled || disabledValue,
hidden: hidden || hiddenValue,
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");
if (!input.children.length || input.children.some((child) => child?.type !== "action")) throw new Error("Swift.Menu picker children must be actions");
if (!input.children.some((child) => child.id === input.selection)) throw new Error("Swift.Menu picker selection must match a child id");
append(input.children, item.id, Boolean(disabled || disabledValue), Boolean(hidden || hiddenValue));
break;
}
case "divider": {
for (const name of Object.keys(input)) {
if (name !== "type" && name !== "id") throw new Error("Unsupported Swift.Menu " + item.type + " property: " + name);
}
const id = 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");
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 || 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);
}
}
};
append(items, "", false, false);
return result;
}