@perkyzz/emvb 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** The group's own radios and panels; nested groups are left out. */
|
|
2
|
+
const own = (tabs: Element) => ({
|
|
3
|
+
inputs: [...tabs.querySelectorAll<HTMLInputElement>(":scope > .emvb-tab-input")],
|
|
4
|
+
labels: [...tabs.querySelectorAll(":scope > .emvb-tab-list > .emvb-tab-label")],
|
|
5
|
+
panels: [...tabs.querySelectorAll(":scope > .emvb-tab-panels > .emvb-tab-panel")],
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Checks the tab radios that show element `id` on the canvas, so an element selected inside a
|
|
10
|
+
* hidden tab panel (from Layers, or a tab label) appears. The canvas has no tabs script (D-011).
|
|
11
|
+
*/
|
|
12
|
+
export function revealInTabs(doc: Document, id: string | null): void {
|
|
13
|
+
if (!id) return;
|
|
14
|
+
const element = doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`);
|
|
15
|
+
for (
|
|
16
|
+
let panel = element?.closest(".emvb-tab-panel");
|
|
17
|
+
panel;
|
|
18
|
+
panel = panel.parentElement?.closest(".emvb-tab-panel")
|
|
19
|
+
) {
|
|
20
|
+
const tabs = panel.closest(".emvb-tabs");
|
|
21
|
+
if (!tabs) continue;
|
|
22
|
+
const { inputs, panels } = own(tabs);
|
|
23
|
+
const input = inputs[panels.indexOf(panel)];
|
|
24
|
+
if (input && !input.checked) input.checked = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The tab panel a click on its tab label stands for, since labels carry no element id. */
|
|
29
|
+
export function tabPanelIdForLabel(target: EventTarget | null): string | null {
|
|
30
|
+
const label = (target as Element | null)?.closest?.(".emvb-tab-label");
|
|
31
|
+
const tabs = label?.closest(".emvb-tabs");
|
|
32
|
+
if (!label || !tabs) return null;
|
|
33
|
+
const { labels, panels } = own(tabs);
|
|
34
|
+
return panels[labels.indexOf(label)]?.getAttribute("data-emvb-id") ?? null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const AUTO_OPEN = "data-emvb-auto-open";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Opens the closed accordion items that hold element `id` on the canvas, so it can be seen and
|
|
41
|
+
* edited, and closes the ones it opened before once the selection leaves them. Canvas only: the
|
|
42
|
+
* saved Open setting is untouched (W-130).
|
|
43
|
+
*/
|
|
44
|
+
export function revealInAccordions(
|
|
45
|
+
doc: Document,
|
|
46
|
+
id: string | null,
|
|
47
|
+
savedOpen: (itemId: string) => boolean = () => false,
|
|
48
|
+
): void {
|
|
49
|
+
const element = id ? doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`) : null;
|
|
50
|
+
const holders = new Set<HTMLDetailsElement>();
|
|
51
|
+
for (
|
|
52
|
+
let item = element?.closest<HTMLDetailsElement>("details.emvb-accordion-item");
|
|
53
|
+
item;
|
|
54
|
+
item = item.parentElement?.closest<HTMLDetailsElement>("details.emvb-accordion-item")
|
|
55
|
+
) {
|
|
56
|
+
holders.add(item);
|
|
57
|
+
}
|
|
58
|
+
for (const item of doc.querySelectorAll<HTMLDetailsElement>(`details[${AUTO_OPEN}]`)) {
|
|
59
|
+
if (holders.has(item)) continue;
|
|
60
|
+
item.removeAttribute(AUTO_OPEN);
|
|
61
|
+
// Open was switched on while we held it open: leave it open.
|
|
62
|
+
if (!savedOpen(item.getAttribute("data-emvb-id") ?? "")) item.open = false;
|
|
63
|
+
}
|
|
64
|
+
for (const item of holders) {
|
|
65
|
+
if (item.open) continue;
|
|
66
|
+
item.setAttribute(AUTO_OPEN, "");
|
|
67
|
+
item.open = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Opens the menu disclosures that hold element `id` on the canvas, and closes the ones it
|
|
73
|
+
* opened before once the selection leaves them. The public page stays closed until the visitor
|
|
74
|
+
* opens it.
|
|
75
|
+
*/
|
|
76
|
+
export function revealInMenus(doc: Document, id: string | null): void {
|
|
77
|
+
const element = id ? doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`) : null;
|
|
78
|
+
const holders = new Set<HTMLDetailsElement>();
|
|
79
|
+
for (
|
|
80
|
+
let item = element?.closest("li.emvb-menu-item");
|
|
81
|
+
item;
|
|
82
|
+
item = item.parentElement?.closest("li.emvb-menu-item")
|
|
83
|
+
) {
|
|
84
|
+
const details = item.querySelector<HTMLDetailsElement>(
|
|
85
|
+
":scope > .emvb-menu-item__bar > details",
|
|
86
|
+
);
|
|
87
|
+
if (details) holders.add(details);
|
|
88
|
+
}
|
|
89
|
+
for (const details of doc.querySelectorAll<HTMLDetailsElement>(
|
|
90
|
+
`details.emvb-menu-item__disclosure[${AUTO_OPEN}]`,
|
|
91
|
+
)) {
|
|
92
|
+
if (holders.has(details)) continue;
|
|
93
|
+
details.removeAttribute(AUTO_OPEN);
|
|
94
|
+
details.open = false;
|
|
95
|
+
}
|
|
96
|
+
for (const details of holders) {
|
|
97
|
+
if (details.open) continue;
|
|
98
|
+
details.setAttribute(AUTO_OPEN, "");
|
|
99
|
+
details.open = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isAllowedAttr, isAllowedTag, type VNode } from "../../../core/index.ts";
|
|
3
|
+
|
|
4
|
+
/** Lowercase HTML attr names React spells in camelCase. */
|
|
5
|
+
const REACT_ATTR: Record<string, string> = {
|
|
6
|
+
class: "className",
|
|
7
|
+
for: "htmlFor",
|
|
8
|
+
tabindex: "tabIndex",
|
|
9
|
+
autocomplete: "autoComplete",
|
|
10
|
+
allowfullscreen: "allowFullScreen",
|
|
11
|
+
referrerpolicy: "referrerPolicy",
|
|
12
|
+
// W-297: form field limits from the bound form definition.
|
|
13
|
+
minlength: "minLength",
|
|
14
|
+
maxlength: "maxLength",
|
|
15
|
+
novalidate: "noValidate",
|
|
16
|
+
// The canvas never updates a radio from props, so a tab chosen there stays chosen (QA-5).
|
|
17
|
+
checked: "defaultChecked",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Presence attributes the core writes as `""`. React reads `""` as false for these, so a saved-open
|
|
22
|
+
* accordion item rendered closed on the canvas (W-130); presence means on.
|
|
23
|
+
*/
|
|
24
|
+
const BOOLEAN_ATTRS = new Set([
|
|
25
|
+
"open",
|
|
26
|
+
"controls",
|
|
27
|
+
"allowfullscreen",
|
|
28
|
+
"muted",
|
|
29
|
+
"loop",
|
|
30
|
+
"playsinline",
|
|
31
|
+
"autoplay",
|
|
32
|
+
"required",
|
|
33
|
+
"novalidate",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/** SVG tags the core keeps lowercase; the SVG namespace only knows their camelCase names. */
|
|
37
|
+
const REACT_TAG: Record<string, string> = {
|
|
38
|
+
lineargradient: "linearGradient",
|
|
39
|
+
radialgradient: "radialGradient",
|
|
40
|
+
clippath: "clipPath",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** React's name for an attribute: SVG's `stop-color` and `xlink:href` become `stopColor`, `xlinkHref`. */
|
|
44
|
+
function reactAttr(name: string): string {
|
|
45
|
+
const mapped = REACT_ATTR[name];
|
|
46
|
+
if (mapped) return mapped;
|
|
47
|
+
if (name.startsWith("data-") || name.startsWith("aria-")) return name;
|
|
48
|
+
return name.replace(/[-:]([a-z])/g, (_match, letter: string) => letter.toUpperCase());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Turns the core's VNode tree into React elements for the canvas (A-08). It applies the same tag
|
|
53
|
+
* and attribute allowlists as `serialize`, so the canvas and the public page get the same markup
|
|
54
|
+
* (R-005). Text stays text: React escapes it.
|
|
55
|
+
*/
|
|
56
|
+
export function vnodeToReact(node: VNode | string, key?: React.Key): React.ReactNode {
|
|
57
|
+
if (typeof node === "string") return node;
|
|
58
|
+
if (!isAllowedTag(node.tag)) return null;
|
|
59
|
+
const props: Record<string, unknown> = { key };
|
|
60
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
61
|
+
if (!isAllowedAttr(name)) continue;
|
|
62
|
+
props[reactAttr(name)] = name === "checked" || BOOLEAN_ATTRS.has(name) ? true : value;
|
|
63
|
+
}
|
|
64
|
+
return React.createElement(
|
|
65
|
+
REACT_TAG[node.tag] ?? node.tag,
|
|
66
|
+
props,
|
|
67
|
+
...node.children.map((child, index) => vnodeToReact(child, index)),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where copied elements and styles live (W-093, D-033): localStorage on the admin's origin, so a
|
|
5
|
+
* copy reaches every page and theme part open in this browser, in this tab or another, without a
|
|
6
|
+
* clipboard permission prompt. The system clipboard is left alone.
|
|
7
|
+
*/
|
|
8
|
+
export const CLIPBOARD_KEY = "emvb-clipboard";
|
|
9
|
+
const CHANGE_EVENT = "emvb-clipboard-change";
|
|
10
|
+
|
|
11
|
+
export function readClipboardText(): string | null {
|
|
12
|
+
try {
|
|
13
|
+
return localStorage.getItem(CLIPBOARD_KEY);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Stores the clip; false when storage is unavailable or full. */
|
|
20
|
+
export function writeClipboardText(text: string): boolean {
|
|
21
|
+
try {
|
|
22
|
+
localStorage.setItem(CLIPBOARD_KEY, text);
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
window.dispatchEvent(new Event(CHANGE_EVENT));
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function subscribe(onChange: () => void): () => void {
|
|
31
|
+
const onStorage = (event: StorageEvent) => {
|
|
32
|
+
if (event.key === null || event.key === CLIPBOARD_KEY) onChange();
|
|
33
|
+
};
|
|
34
|
+
window.addEventListener(CHANGE_EVENT, onChange);
|
|
35
|
+
window.addEventListener("storage", onStorage);
|
|
36
|
+
return () => {
|
|
37
|
+
window.removeEventListener(CHANGE_EVENT, onChange);
|
|
38
|
+
window.removeEventListener("storage", onStorage);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The clipboard text, updated when this tab or another one copies. */
|
|
43
|
+
export const useClipboardText = (): string | null =>
|
|
44
|
+
React.useSyncExternalStore(subscribe, readClipboardText, () => null);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import { BUTTON, SOLID_DESTRUCTIVE, SOLID_PRIMARY, UI_CSS } from "../ui.ts";
|
|
3
|
+
|
|
4
|
+
type OpenProps = { open: boolean; onOpenChange: (open: boolean) => void };
|
|
5
|
+
|
|
6
|
+
/** 409 on save (R-006): the stored page changed; the user chooses, nothing is overwritten silently. */
|
|
7
|
+
export function ConflictDialog({
|
|
8
|
+
open,
|
|
9
|
+
onOpenChange,
|
|
10
|
+
onReload,
|
|
11
|
+
onOverwrite,
|
|
12
|
+
}: OpenProps & { onReload: () => void; onOverwrite: () => void }) {
|
|
13
|
+
return (
|
|
14
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
15
|
+
<Dialog size="base" className="p-6">
|
|
16
|
+
<style>{UI_CSS}</style>
|
|
17
|
+
<div data-emvb-dialog="conflict" className="emvb-dialog">
|
|
18
|
+
<Dialog.Title>This page was changed somewhere else</Dialog.Title>
|
|
19
|
+
<Dialog.Description>
|
|
20
|
+
Someone saved this page after you opened it. Reload to get their version and lose your
|
|
21
|
+
unsaved changes, or overwrite their version with yours.
|
|
22
|
+
</Dialog.Description>
|
|
23
|
+
<div className="emvb-dialog-actions">
|
|
24
|
+
<Button variant="secondary" className={BUTTON} onClick={onReload}>
|
|
25
|
+
Reload page
|
|
26
|
+
</Button>
|
|
27
|
+
<Button
|
|
28
|
+
variant="destructive"
|
|
29
|
+
className={BUTTON}
|
|
30
|
+
style={SOLID_DESTRUCTIVE}
|
|
31
|
+
onClick={onOverwrite}
|
|
32
|
+
>
|
|
33
|
+
Overwrite
|
|
34
|
+
</Button>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</Dialog>
|
|
38
|
+
</Dialog.Root>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Revert to published (W-193): drops the saved draft and any unsaved edits, after a confirm. */
|
|
43
|
+
export function RevertDialog({
|
|
44
|
+
open,
|
|
45
|
+
onOpenChange,
|
|
46
|
+
onRevert,
|
|
47
|
+
}: OpenProps & { onRevert: () => void }) {
|
|
48
|
+
return (
|
|
49
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
50
|
+
<Dialog size="base" className="p-6">
|
|
51
|
+
<style>{UI_CSS}</style>
|
|
52
|
+
<div data-emvb-dialog="revert" className="emvb-dialog">
|
|
53
|
+
<Dialog.Title>Revert to the published version?</Dialog.Title>
|
|
54
|
+
<Dialog.Description>
|
|
55
|
+
Your saved draft and any unsaved changes are discarded, and the editor shows what is
|
|
56
|
+
live now. This can't be undone.
|
|
57
|
+
</Dialog.Description>
|
|
58
|
+
<div className="emvb-dialog-actions">
|
|
59
|
+
<Dialog.Close
|
|
60
|
+
render={(props) => (
|
|
61
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
62
|
+
Cancel
|
|
63
|
+
</Button>
|
|
64
|
+
)}
|
|
65
|
+
/>
|
|
66
|
+
<Button
|
|
67
|
+
variant="destructive"
|
|
68
|
+
className={BUTTON}
|
|
69
|
+
style={SOLID_DESTRUCTIVE}
|
|
70
|
+
onClick={onRevert}
|
|
71
|
+
>
|
|
72
|
+
Revert
|
|
73
|
+
</Button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</Dialog>
|
|
77
|
+
</Dialog.Root>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Exit with unsaved changes (IA "Leaving the editor"). */
|
|
82
|
+
export function LeaveDialog({
|
|
83
|
+
open,
|
|
84
|
+
onOpenChange,
|
|
85
|
+
onDiscard,
|
|
86
|
+
onSaveAndLeave,
|
|
87
|
+
}: OpenProps & { onDiscard: () => void; onSaveAndLeave: () => void }) {
|
|
88
|
+
return (
|
|
89
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
90
|
+
<Dialog size="base" className="p-6">
|
|
91
|
+
<style>{UI_CSS}</style>
|
|
92
|
+
<div data-emvb-dialog="leave" className="emvb-dialog">
|
|
93
|
+
<Dialog.Title>Leave without saving?</Dialog.Title>
|
|
94
|
+
<Dialog.Description>You have unsaved changes on this page.</Dialog.Description>
|
|
95
|
+
<div className="emvb-dialog-actions">
|
|
96
|
+
<Dialog.Close
|
|
97
|
+
render={(props) => (
|
|
98
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
99
|
+
Keep editing
|
|
100
|
+
</Button>
|
|
101
|
+
)}
|
|
102
|
+
/>
|
|
103
|
+
<Button
|
|
104
|
+
variant="secondary"
|
|
105
|
+
className={`${BUTTON} emvb-danger-text`}
|
|
106
|
+
onClick={onDiscard}
|
|
107
|
+
>
|
|
108
|
+
Discard changes
|
|
109
|
+
</Button>
|
|
110
|
+
<Button
|
|
111
|
+
variant="primary"
|
|
112
|
+
className={BUTTON}
|
|
113
|
+
style={SOLID_PRIMARY}
|
|
114
|
+
onClick={onSaveAndLeave}
|
|
115
|
+
>
|
|
116
|
+
Save and leave
|
|
117
|
+
</Button>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
</Dialog>
|
|
121
|
+
</Dialog.Root>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Confirm deleting an element that has children (W-020). */
|
|
126
|
+
export function DeleteSubtreeDialog({
|
|
127
|
+
open,
|
|
128
|
+
onOpenChange,
|
|
129
|
+
label,
|
|
130
|
+
count,
|
|
131
|
+
onConfirm,
|
|
132
|
+
}: OpenProps & { label: string; count: number; onConfirm: () => void }) {
|
|
133
|
+
const inside = count - 1;
|
|
134
|
+
return (
|
|
135
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
136
|
+
<Dialog size="base" className="p-6">
|
|
137
|
+
<style>{UI_CSS}</style>
|
|
138
|
+
<div data-emvb-dialog="delete-subtree" className="emvb-dialog">
|
|
139
|
+
<Dialog.Title>
|
|
140
|
+
Delete {label} and the {inside} element{inside === 1 ? "" : "s"} inside it?
|
|
141
|
+
</Dialog.Title>
|
|
142
|
+
<Dialog.Description>This can be undone with Restore after delete.</Dialog.Description>
|
|
143
|
+
<div className="emvb-dialog-actions">
|
|
144
|
+
<Dialog.Close
|
|
145
|
+
render={(props) => (
|
|
146
|
+
<Button {...props} variant="secondary" className={BUTTON}>
|
|
147
|
+
Cancel
|
|
148
|
+
</Button>
|
|
149
|
+
)}
|
|
150
|
+
/>
|
|
151
|
+
<Button
|
|
152
|
+
variant="destructive"
|
|
153
|
+
className={BUTTON}
|
|
154
|
+
style={SOLID_DESTRUCTIVE}
|
|
155
|
+
onClick={onConfirm}
|
|
156
|
+
>
|
|
157
|
+
Delete
|
|
158
|
+
</Button>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
</Dialog>
|
|
162
|
+
</Dialog.Root>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const ID = "emvb-drag-id";
|
|
2
|
+
const TYPE = "emvb-drag-type";
|
|
3
|
+
|
|
4
|
+
const store = (key: string, value: string, other: string) => {
|
|
5
|
+
try {
|
|
6
|
+
sessionStorage.setItem(key, value);
|
|
7
|
+
sessionStorage.removeItem(other);
|
|
8
|
+
} catch {
|
|
9
|
+
/* private mode */
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The element being dragged, kept in session storage because Chromium hides `getData` during
|
|
15
|
+
* dragover and parent-document Esc/dragend must know a drag is running (K16).
|
|
16
|
+
*/
|
|
17
|
+
export const dragStash = {
|
|
18
|
+
existing: (id: string) => store(ID, id, TYPE),
|
|
19
|
+
new: (type: string) => store(TYPE, type, ID),
|
|
20
|
+
id: () => sessionStorage.getItem(ID),
|
|
21
|
+
type: () => sessionStorage.getItem(TYPE),
|
|
22
|
+
active: () => Boolean(sessionStorage.getItem(ID) || sessionStorage.getItem(TYPE)),
|
|
23
|
+
clear: () => {
|
|
24
|
+
sessionStorage.removeItem(ID);
|
|
25
|
+
sessionStorage.removeItem(TYPE);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Layout, LayoutNode, StyleProps } from "../../../core/index.ts";
|
|
2
|
+
import { findNode, isParentNode, parentOf } from "../../../core/index.ts";
|
|
3
|
+
|
|
4
|
+
export type Rect = { top: number; left: number; width: number; height: number };
|
|
5
|
+
export type Point = { x: number; y: number };
|
|
6
|
+
export type Direction = NonNullable<StyleProps["flexDirection"]>;
|
|
7
|
+
|
|
8
|
+
/** The MIME type an Add tile puts on `dataTransfer`, carrying the element type. */
|
|
9
|
+
export const NEW_ELEMENT_MIME = "application/x-emvb-new-element";
|
|
10
|
+
|
|
11
|
+
/** MIME for dragging an existing canvas/Layers element (carries its id). */
|
|
12
|
+
export const EXISTING_ELEMENT_MIME = "application/x-emvb-element-id";
|
|
13
|
+
|
|
14
|
+
/** Which EmVB drag payloads a `DataTransfer` carries. */
|
|
15
|
+
export const transferKinds = (transfer: DataTransfer | null) => {
|
|
16
|
+
if (!transfer) return { neu: false, existing: false };
|
|
17
|
+
const types = new Set(transfer.types);
|
|
18
|
+
return {
|
|
19
|
+
neu: types.has(NEW_ELEMENT_MIME),
|
|
20
|
+
existing: types.has(EXISTING_ELEMENT_MIME),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The `data-emvb-id` an event target belongs to, if any. */
|
|
25
|
+
export const idAt = (target: EventTarget | null): string | null => {
|
|
26
|
+
const element = target as Element | null;
|
|
27
|
+
const hit = element?.closest?.("[data-emvb-id]");
|
|
28
|
+
return hit?.getAttribute("data-emvb-id") ?? null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type Span = { start: number; end: number };
|
|
32
|
+
|
|
33
|
+
const along = (rect: Rect, row: boolean): Span =>
|
|
34
|
+
row
|
|
35
|
+
? { start: rect.left, end: rect.left + rect.width }
|
|
36
|
+
: { start: rect.top, end: rect.top + rect.height };
|
|
37
|
+
|
|
38
|
+
const middle = (span: Span) => (span.start + span.end) / 2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Splits children (in document order) into flex lines: a new line starts when a child no longer
|
|
42
|
+
* overlaps the current line on the cross axis. Without wrapping there is exactly one line.
|
|
43
|
+
*/
|
|
44
|
+
function lines(rects: Rect[], row: boolean): number[][] {
|
|
45
|
+
const result: number[][] = [];
|
|
46
|
+
let cross: Span | null = null;
|
|
47
|
+
for (const [i, rect] of rects.entries()) {
|
|
48
|
+
const span = along(rect, !row);
|
|
49
|
+
const current = result.at(-1);
|
|
50
|
+
if (current && cross && span.start < cross.end && span.end > cross.start) {
|
|
51
|
+
current.push(i);
|
|
52
|
+
cross = { start: Math.min(cross.start, span.start), end: Math.max(cross.end, span.end) };
|
|
53
|
+
} else {
|
|
54
|
+
result.push([i]);
|
|
55
|
+
cross = span;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The insertion index for a pointer over a flex container, given its children's rects in document
|
|
63
|
+
* order: before the first child whose middle (along the main axis) is past the pointer.
|
|
64
|
+
*/
|
|
65
|
+
export function dropIndex(direction: Direction, children: Rect[], point: Point): number {
|
|
66
|
+
if (children.length === 0) return 0;
|
|
67
|
+
const row = direction.startsWith("row");
|
|
68
|
+
const reverse = direction.endsWith("reverse");
|
|
69
|
+
const pointer = row ? point.x : point.y;
|
|
70
|
+
const crossPointer = row ? point.y : point.x;
|
|
71
|
+
const groups = lines(children, row);
|
|
72
|
+
const distance = (group: number[]) => {
|
|
73
|
+
const spans = group.map((i) => along(children[i] as Rect, !row));
|
|
74
|
+
const start = Math.min(...spans.map((s) => s.start));
|
|
75
|
+
const end = Math.max(...spans.map((s) => s.end));
|
|
76
|
+
return crossPointer < start ? start - crossPointer : Math.max(0, crossPointer - end);
|
|
77
|
+
};
|
|
78
|
+
const group = groups.reduce((best, next) => (distance(next) < distance(best) ? next : best));
|
|
79
|
+
const before = group.find((i) => {
|
|
80
|
+
const mid = middle(along(children[i] as Rect, row));
|
|
81
|
+
return reverse ? pointer > mid : pointer < mid;
|
|
82
|
+
});
|
|
83
|
+
return before ?? (group.at(-1) as number) + 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Whether `parent` takes the element being dragged (usually `canDrop` for the known source). */
|
|
87
|
+
export type Accepts = (parent: LayoutNode) => boolean;
|
|
88
|
+
|
|
89
|
+
const anyParent: Accepts = (parent) => isParentNode(parent);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The element a drop over `hoveredId` goes into (W-128): the nearest element at or above it that
|
|
93
|
+
* takes the dragged element. A non-panel dropped on Tabs goes into its active panel
|
|
94
|
+
* (`activePanel`, else the first panel). Falls back to the page's root.
|
|
95
|
+
*/
|
|
96
|
+
export function dropContainer(
|
|
97
|
+
layout: Layout,
|
|
98
|
+
hoveredId: string | null,
|
|
99
|
+
accepts: Accepts = anyParent,
|
|
100
|
+
activePanel?: (tabsId: string) => string | undefined,
|
|
101
|
+
): LayoutNode {
|
|
102
|
+
let current: LayoutNode | undefined = hoveredId ? findNode(layout, hoveredId) : undefined;
|
|
103
|
+
while (current) {
|
|
104
|
+
if (isParentNode(current)) {
|
|
105
|
+
if (accepts(current)) return current;
|
|
106
|
+
if (current.type === "tabs") {
|
|
107
|
+
const wanted = activePanel?.(current.id);
|
|
108
|
+
const panel = current.children.find((child) => child.id === wanted) ?? current.children[0];
|
|
109
|
+
if (panel && accepts(panel)) return panel;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const parentId = parentOf(layout, current.id);
|
|
113
|
+
current = parentId ? findNode(layout, parentId) : undefined;
|
|
114
|
+
}
|
|
115
|
+
return layout.root;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** How close to a container's edge, along its parent's main axis, a drop goes beside it. */
|
|
119
|
+
const EDGE_ZONE = 10;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Before/after edge zones (W-128): a pointer within `EDGE_ZONE` px (at most a quarter of its size)
|
|
123
|
+
* of `container`'s start or end edge, along its parent's main axis, drops beside it in the
|
|
124
|
+
* parent instead of inside it. Null when the pointer is in the middle, for the root, or when the
|
|
125
|
+
* parent doesn't take the element.
|
|
126
|
+
*/
|
|
127
|
+
export function edgeDrop(
|
|
128
|
+
layout: Layout,
|
|
129
|
+
container: LayoutNode,
|
|
130
|
+
rect: Rect,
|
|
131
|
+
point: Point,
|
|
132
|
+
accepts: Accepts = anyParent,
|
|
133
|
+
): { parentId: string; index: number } | null {
|
|
134
|
+
const parentId = parentOf(layout, container.id);
|
|
135
|
+
const parent = parentId ? findNode(layout, parentId) : undefined;
|
|
136
|
+
if (!parent || !isParentNode(parent) || !accepts(parent)) return null;
|
|
137
|
+
const direction = parent.style?.flexDirection ?? "column";
|
|
138
|
+
const row = direction.startsWith("row");
|
|
139
|
+
const span = along(rect, row);
|
|
140
|
+
const zone = Math.min(EDGE_ZONE, (span.end - span.start) / 4);
|
|
141
|
+
const pointer = row ? point.x : point.y;
|
|
142
|
+
const index = parent.children.findIndex((child) => child.id === container.id);
|
|
143
|
+
const reverse = direction.endsWith("reverse");
|
|
144
|
+
if (pointer < span.start + zone)
|
|
145
|
+
return { parentId: parent.id, index: reverse ? index + 1 : index };
|
|
146
|
+
if (pointer > span.end - zone) return { parentId: parent.id, index: reverse ? index : index + 1 };
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultElement,
|
|
3
|
+
ELEMENTS,
|
|
4
|
+
newNodeId,
|
|
5
|
+
type ElementType,
|
|
6
|
+
type Layout,
|
|
7
|
+
type LayoutNode,
|
|
8
|
+
} from "../../../core/index.ts";
|
|
9
|
+
|
|
10
|
+
const hasH1 = (node: LayoutNode): boolean =>
|
|
11
|
+
((node.type === "heading" || node.type === "post-title") &&
|
|
12
|
+
(node.props as { level?: number }).level === 1) ||
|
|
13
|
+
("children" in node && Array.isArray(node.children) && node.children.some(hasH1));
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A new Heading is the page's H1 when the page has none yet, otherwise the default H2 (W-147).
|
|
17
|
+
* Other nodes, and headings whose level was already chosen, are returned as they are.
|
|
18
|
+
*/
|
|
19
|
+
export function withPageHeadingLevel(node: LayoutNode, layout: Layout): LayoutNode {
|
|
20
|
+
if (node.type !== "heading" || node.props.level !== 2 || hasH1(layout.root)) return node;
|
|
21
|
+
return { ...node, props: { ...node.props, level: 1 } };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const textNode = (text: string, random?: () => number): LayoutNode => ({
|
|
25
|
+
...defaultElement("text", newNodeId(random)),
|
|
26
|
+
props: { text },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An accordion item titled "Question n" holding a Text, for a new Accordion or its Add item
|
|
31
|
+
* (W-130, W-154).
|
|
32
|
+
*/
|
|
33
|
+
export function newAccordionItem(n: number, random?: () => number, open = false): LayoutNode {
|
|
34
|
+
return {
|
|
35
|
+
id: newNodeId(random),
|
|
36
|
+
type: "accordion-item",
|
|
37
|
+
props: open ? { summary: `Question ${n}`, open: true } : { summary: `Question ${n}` },
|
|
38
|
+
children: [
|
|
39
|
+
textNode(`Answer to question ${n}. Replace this text or add elements here.`, random),
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A tab panel labelled "Tab n" holding a Text, for Tabs' Add tab (W-130). */
|
|
45
|
+
export function newTabPanel(n: number, random?: () => number): LayoutNode {
|
|
46
|
+
return {
|
|
47
|
+
id: newNodeId(random),
|
|
48
|
+
type: "tab-panel",
|
|
49
|
+
props: { label: `Tab ${n}` },
|
|
50
|
+
children: [textNode(`Content for tab ${n}.`, random)],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Default node for a new element from the Add panel. Only new inserts get starter children;
|
|
56
|
+
* saved Accordions and Tabs with no items keep working as they are (W-130).
|
|
57
|
+
*/
|
|
58
|
+
export function newElement(type: string, random?: () => number): LayoutNode | null {
|
|
59
|
+
if (!(type in ELEMENTS)) return null;
|
|
60
|
+
if (type === "tabs") {
|
|
61
|
+
const tabs = defaultElement("tabs", newNodeId(random));
|
|
62
|
+
const panel = (label: string, heading: string): LayoutNode => ({
|
|
63
|
+
id: newNodeId(random),
|
|
64
|
+
type: "tab-panel",
|
|
65
|
+
props: { label },
|
|
66
|
+
children: [
|
|
67
|
+
{
|
|
68
|
+
id: newNodeId(random),
|
|
69
|
+
type: "heading",
|
|
70
|
+
props: { text: heading, level: 3 },
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
...tabs,
|
|
76
|
+
children: [panel("Tab 1", "First tab"), panel("Tab 2", "Second tab")],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (type === "menu") {
|
|
80
|
+
const menuNode = defaultElement("menu", newNodeId(random));
|
|
81
|
+
const item = (text: string, href: string, children: LayoutNode[] = []): LayoutNode => ({
|
|
82
|
+
id: newNodeId(random),
|
|
83
|
+
type: "menu-item",
|
|
84
|
+
props: { text, href },
|
|
85
|
+
children,
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
...menuNode,
|
|
89
|
+
children: [
|
|
90
|
+
item("Home", "/"),
|
|
91
|
+
item("Work", "/work", [
|
|
92
|
+
item("Projects", "/work/projects"),
|
|
93
|
+
item("Archive", "/work/archive"),
|
|
94
|
+
]),
|
|
95
|
+
item("About", "/about"),
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (type === "accordion") {
|
|
100
|
+
const accordion = defaultElement("accordion", newNodeId(random));
|
|
101
|
+
return {
|
|
102
|
+
...accordion,
|
|
103
|
+
children: [1, 2, 3].map((n) => newAccordionItem(n, random, n === 1)),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return defaultElement(type as ElementType, newNodeId(random));
|
|
107
|
+
}
|