@perkyzz/emvb 0.0.0-stage → 0.1.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 +57 -2
- package/package.json +72 -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 +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -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 +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -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 +71 -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 +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -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 +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -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.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -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 +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import type { DesignSystem } from "../schema/design.ts";
|
|
2
|
+
import type { Layout, LayoutNode } from "../schema/layout.ts";
|
|
3
|
+
import { STYLE_STATES } from "../schema/state-names.ts";
|
|
4
|
+
import type { DeviceStyles, StyleProps, StyleStates } from "../schema/style.ts";
|
|
5
|
+
import { nodeChildren, slugify, updateNode } from "../tree-ops.ts";
|
|
6
|
+
|
|
7
|
+
export type VariableKind = "color" | "font" | "fontSize" | "spacing";
|
|
8
|
+
|
|
9
|
+
/** Where a design variable is referenced from a layout (or, later, a class style). */
|
|
10
|
+
export type VariableUsage = {
|
|
11
|
+
nodeId: string;
|
|
12
|
+
prop: string;
|
|
13
|
+
/** Present when the ref lives on a design class style (W-030). */
|
|
14
|
+
classId?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type VariableRefLike = { var: string; from?: VariableKind };
|
|
18
|
+
|
|
19
|
+
const isVariableRef = (value: unknown): value is VariableRefLike =>
|
|
20
|
+
typeof value === "object" &&
|
|
21
|
+
value !== null &&
|
|
22
|
+
"var" in value &&
|
|
23
|
+
typeof (value as { var: unknown }).var === "string";
|
|
24
|
+
|
|
25
|
+
/** Colour refs omit `from` (legacy); length/font refs set it (W-028). */
|
|
26
|
+
export function refMatchesKind(ref: VariableRefLike, kind: VariableKind): boolean {
|
|
27
|
+
if (kind === "color") return ref.from === undefined || ref.from === "color";
|
|
28
|
+
return ref.from === kind;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const matches = (value: unknown, id: string, kind: VariableKind | undefined) =>
|
|
32
|
+
isVariableRef(value) && value.var === id && (kind === undefined || refMatchesKind(value, kind));
|
|
33
|
+
|
|
34
|
+
/** Nested colour refs: the box shadow (W-088), and gradient stops and the overlay (W-094). */
|
|
35
|
+
const shadowColorMatches = (style: StyleProps, id: string, kind: VariableKind | undefined) =>
|
|
36
|
+
matches(style.boxShadow?.color, id, kind);
|
|
37
|
+
|
|
38
|
+
function collectStyleUsages(
|
|
39
|
+
style: StyleProps | undefined,
|
|
40
|
+
id: string,
|
|
41
|
+
kind: VariableKind | undefined,
|
|
42
|
+
hit: (prop: string) => void,
|
|
43
|
+
): void {
|
|
44
|
+
if (!style) return;
|
|
45
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
46
|
+
if (matches(value, id, kind)) hit(prop);
|
|
47
|
+
}
|
|
48
|
+
if (shadowColorMatches(style, id, kind)) hit("boxShadow.color");
|
|
49
|
+
if (matches(style.gradient?.from, id, kind)) hit("gradient.from");
|
|
50
|
+
if (matches(style.gradient?.to, id, kind)) hit("gradient.to");
|
|
51
|
+
if (matches(style.overlay?.color, id, kind)) hit("overlay.color");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const RESPONSIVE = ["tablet", "mobile"] as const;
|
|
55
|
+
|
|
56
|
+
/** Style, state styles and device overrides. A nested usage is `<state|device>.<prop>`. */
|
|
57
|
+
function collectAllUsages(
|
|
58
|
+
owner: { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles },
|
|
59
|
+
id: string,
|
|
60
|
+
kind: VariableKind | undefined,
|
|
61
|
+
hit: (prop: string) => void,
|
|
62
|
+
): void {
|
|
63
|
+
collectStyleUsages(owner.style, id, kind, hit);
|
|
64
|
+
for (const state of STYLE_STATES) {
|
|
65
|
+
collectStyleUsages(owner.states?.[state], id, kind, (prop) => hit(`${state}.${prop}`));
|
|
66
|
+
}
|
|
67
|
+
for (const device of RESPONSIVE) {
|
|
68
|
+
collectStyleUsages(owner.devices?.[device], id, kind, (prop) => hit(`${device}.${prop}`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function walkNodes(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
73
|
+
visit(node);
|
|
74
|
+
for (const child of nodeChildren(node)) walkNodes(child, visit);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Find every style property on `layout` that references variable `id` (optionally of `kind`). */
|
|
78
|
+
export function findVariableUsages(
|
|
79
|
+
layout: Layout,
|
|
80
|
+
id: string,
|
|
81
|
+
kind?: VariableKind,
|
|
82
|
+
): VariableUsage[] {
|
|
83
|
+
const usages: VariableUsage[] = [];
|
|
84
|
+
walkNodes(layout.root, (node) => {
|
|
85
|
+
collectAllUsages(node, id, kind, (prop) => {
|
|
86
|
+
usages.push({ nodeId: node.id, prop });
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return usages;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Usages on design class styles (W-030). Safe no-op until `classes` exist on the design.
|
|
94
|
+
* Keeps the W-029 API ready for the Site styles delete dialog.
|
|
95
|
+
*/
|
|
96
|
+
export function findVariableUsagesInDesign(
|
|
97
|
+
design: DesignSystem,
|
|
98
|
+
id: string,
|
|
99
|
+
kind?: VariableKind,
|
|
100
|
+
): VariableUsage[] {
|
|
101
|
+
const usages: VariableUsage[] = [];
|
|
102
|
+
for (const cls of design.classes ?? []) {
|
|
103
|
+
collectAllUsages(cls, id, kind, (prop) => {
|
|
104
|
+
usages.push({ nodeId: "", prop, classId: cls.id });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return usages;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function stripRefsFromStyle(
|
|
111
|
+
style: StyleProps | undefined,
|
|
112
|
+
id: string,
|
|
113
|
+
kind: VariableKind | undefined,
|
|
114
|
+
): StyleProps | undefined {
|
|
115
|
+
if (!style) return undefined;
|
|
116
|
+
let changed = false;
|
|
117
|
+
const next: Record<string, unknown> = { ...style };
|
|
118
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
119
|
+
if (!matches(value, id, kind)) continue;
|
|
120
|
+
delete next[prop];
|
|
121
|
+
changed = true;
|
|
122
|
+
}
|
|
123
|
+
if (style.boxShadow && shadowColorMatches(style, id, kind)) {
|
|
124
|
+
const { color: _drop, ...shadow } = style.boxShadow;
|
|
125
|
+
next["boxShadow"] = shadow;
|
|
126
|
+
changed = true;
|
|
127
|
+
}
|
|
128
|
+
if (
|
|
129
|
+
style.gradient &&
|
|
130
|
+
(matches(style.gradient.from, id, kind) || matches(style.gradient.to, id, kind))
|
|
131
|
+
) {
|
|
132
|
+
delete next["gradient"];
|
|
133
|
+
changed = true;
|
|
134
|
+
}
|
|
135
|
+
if (style.overlay && matches(style.overlay.color, id, kind)) {
|
|
136
|
+
delete next["overlay"];
|
|
137
|
+
changed = true;
|
|
138
|
+
}
|
|
139
|
+
if (!changed) return style;
|
|
140
|
+
return Object.keys(next).length === 0 ? undefined : (next as StyleProps);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The same for every state; a state left empty is dropped, and so is `states` itself. */
|
|
144
|
+
function stripRefsFromStates(
|
|
145
|
+
states: StyleStates | undefined,
|
|
146
|
+
id: string,
|
|
147
|
+
kind: VariableKind | undefined,
|
|
148
|
+
): StyleStates | undefined {
|
|
149
|
+
if (!states) return undefined;
|
|
150
|
+
let changed = false;
|
|
151
|
+
const next: StyleStates = {};
|
|
152
|
+
for (const state of STYLE_STATES) {
|
|
153
|
+
const style = states[state];
|
|
154
|
+
if (!style) continue;
|
|
155
|
+
const stripped = stripRefsFromStyle(style, id, kind);
|
|
156
|
+
if (stripped !== style) changed = true;
|
|
157
|
+
if (stripped) next[state] = stripped;
|
|
158
|
+
}
|
|
159
|
+
if (!changed) return states;
|
|
160
|
+
return Object.keys(next).length === 0 ? undefined : next;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function stripRefsFromDevices(
|
|
164
|
+
devices: DeviceStyles | undefined,
|
|
165
|
+
id: string,
|
|
166
|
+
kind: VariableKind | undefined,
|
|
167
|
+
): DeviceStyles | undefined {
|
|
168
|
+
if (!devices) return undefined;
|
|
169
|
+
let changed = false;
|
|
170
|
+
const next: DeviceStyles = { ...devices };
|
|
171
|
+
for (const device of RESPONSIVE) {
|
|
172
|
+
const style = stripRefsFromStyle(devices[device], id, kind);
|
|
173
|
+
if (style === devices[device]) continue;
|
|
174
|
+
changed = true;
|
|
175
|
+
if (style) next[device] = style;
|
|
176
|
+
else delete next[device];
|
|
177
|
+
}
|
|
178
|
+
if (!changed) return devices;
|
|
179
|
+
return next.tablet || next.mobile ? next : undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Style, states and device overrides with the refs removed. Same object when nothing changed. */
|
|
183
|
+
function stripOwner<T extends { style?: StyleProps; states?: StyleStates; devices?: DeviceStyles }>(
|
|
184
|
+
owner: T,
|
|
185
|
+
id: string,
|
|
186
|
+
kind: VariableKind | undefined,
|
|
187
|
+
): T {
|
|
188
|
+
const style = stripRefsFromStyle(owner.style, id, kind);
|
|
189
|
+
const states = stripRefsFromStates(owner.states, id, kind);
|
|
190
|
+
const devices = stripRefsFromDevices(owner.devices, id, kind);
|
|
191
|
+
if (style === owner.style && states === owner.states && devices === owner.devices) return owner;
|
|
192
|
+
const next: T = { ...owner, style, states, devices };
|
|
193
|
+
if (style === undefined) delete next.style;
|
|
194
|
+
if (states === undefined) delete next.states;
|
|
195
|
+
if (devices === undefined) delete next.devices;
|
|
196
|
+
return next;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Drop every `{ var: id }` style binding on the layout (fallback to defaults). Pure. */
|
|
200
|
+
export function clearVariableRefs(layout: Layout, id: string, kind?: VariableKind): Layout {
|
|
201
|
+
let next = layout;
|
|
202
|
+
const usages = findVariableUsages(layout, id, kind);
|
|
203
|
+
// Deduplicate node ids — a node may reference the same var on several props.
|
|
204
|
+
const nodeIds = [...new Set(usages.map((u) => u.nodeId))];
|
|
205
|
+
for (const nodeId of nodeIds) {
|
|
206
|
+
next = updateNode(next, nodeId, (node) => stripOwner(node, id, kind));
|
|
207
|
+
}
|
|
208
|
+
return next;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const KIND_TO_LIST = {
|
|
212
|
+
color: "colors",
|
|
213
|
+
font: "fonts",
|
|
214
|
+
fontSize: "fontSizes",
|
|
215
|
+
spacing: "spacings",
|
|
216
|
+
} as const;
|
|
217
|
+
|
|
218
|
+
/** Drop every binding to the variable on class styles; a class left with none keeps `{}`. */
|
|
219
|
+
function clearClassStyleRefs(
|
|
220
|
+
classes: DesignSystem["classes"],
|
|
221
|
+
id: string,
|
|
222
|
+
kind: VariableKind,
|
|
223
|
+
): DesignSystem["classes"] {
|
|
224
|
+
if (!classes) return classes;
|
|
225
|
+
let changed = false;
|
|
226
|
+
const next = classes.map((cls) => {
|
|
227
|
+
const stripped = stripOwner(cls, id, kind);
|
|
228
|
+
if (stripped === cls) return cls;
|
|
229
|
+
changed = true;
|
|
230
|
+
return { ...stripped, style: stripped.style ?? {} };
|
|
231
|
+
});
|
|
232
|
+
return changed ? next : classes;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Remove a variable from the design document and its bindings on class styles. Pure; does not touch layouts. */
|
|
236
|
+
export function removeVariable(design: DesignSystem, id: string, kind: VariableKind): DesignSystem {
|
|
237
|
+
const key = KIND_TO_LIST[kind];
|
|
238
|
+
const list = design.variables[key] ?? [];
|
|
239
|
+
const filtered = list.filter((v) => v.id !== id);
|
|
240
|
+
const classes = clearClassStyleRefs(design.classes, id, kind);
|
|
241
|
+
if (filtered.length === list.length && classes === design.classes) return design;
|
|
242
|
+
return {
|
|
243
|
+
...design,
|
|
244
|
+
variables: {
|
|
245
|
+
...design.variables,
|
|
246
|
+
[key]: filtered,
|
|
247
|
+
},
|
|
248
|
+
...(classes ? { classes } : {}),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** A copy of a variable, with a new id and the name "… copy". The source is unchanged. Pure. */
|
|
253
|
+
export function duplicateVariable(
|
|
254
|
+
design: DesignSystem,
|
|
255
|
+
id: string,
|
|
256
|
+
kind: VariableKind,
|
|
257
|
+
): DesignSystem {
|
|
258
|
+
const key = KIND_TO_LIST[kind];
|
|
259
|
+
const list = design.variables[key] ?? [];
|
|
260
|
+
const source = list.find((entry) => entry.id === id);
|
|
261
|
+
if (!source) return design;
|
|
262
|
+
const name = `${source.name} copy`;
|
|
263
|
+
const base = slugify(name).slice(0, 34) || kind;
|
|
264
|
+
const taken = new Set(list.map((entry) => entry.id));
|
|
265
|
+
let nextId = base;
|
|
266
|
+
for (let n = 2; taken.has(nextId); n++) nextId = `${base}-${n}`.slice(0, 40);
|
|
267
|
+
const copy = Object.assign({}, source, {
|
|
268
|
+
id: nextId,
|
|
269
|
+
name,
|
|
270
|
+
value: typeof source.value === "object" ? structuredClone(source.value) : source.value,
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
...design,
|
|
274
|
+
variables: { ...design.variables, [key]: [...list, copy] },
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Rename is name-only; variable ids stay stable (slug at create time). */
|
|
279
|
+
export function renameVariable(
|
|
280
|
+
design: DesignSystem,
|
|
281
|
+
id: string,
|
|
282
|
+
kind: VariableKind,
|
|
283
|
+
name: string,
|
|
284
|
+
): DesignSystem {
|
|
285
|
+
const trimmed = name.trim();
|
|
286
|
+
if (!trimmed) return design;
|
|
287
|
+
const key = KIND_TO_LIST[kind];
|
|
288
|
+
const list = design.variables[key] ?? [];
|
|
289
|
+
let changed = false;
|
|
290
|
+
const next = list.map((v) => {
|
|
291
|
+
if (v.id !== id || v.name === trimmed) return v;
|
|
292
|
+
changed = true;
|
|
293
|
+
return Object.assign({}, v, { name: trimmed });
|
|
294
|
+
});
|
|
295
|
+
if (!changed) return design;
|
|
296
|
+
return {
|
|
297
|
+
...design,
|
|
298
|
+
variables: {
|
|
299
|
+
...design.variables,
|
|
300
|
+
[key]: next,
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Delete a variable: remove it from the design, clear refs on class styles and on `layout`.
|
|
307
|
+
* Callers that need a confirmation dialog should run `findVariableUsages` first.
|
|
308
|
+
*/
|
|
309
|
+
export function deleteVariable(
|
|
310
|
+
design: DesignSystem,
|
|
311
|
+
layout: Layout,
|
|
312
|
+
id: string,
|
|
313
|
+
kind: VariableKind,
|
|
314
|
+
): { design: DesignSystem; layout: Layout } {
|
|
315
|
+
return {
|
|
316
|
+
design: removeVariable(design, id, kind),
|
|
317
|
+
layout: clearVariableRefs(layout, id, kind),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElementDescriptor } from "../schema/descriptors.ts";
|
|
2
|
+
import type { VNode } from "../render/vnode.ts";
|
|
3
|
+
|
|
4
|
+
/** Shared shape of an element definition: defaults, descriptor, CSS, and its VNode build. */
|
|
5
|
+
export type Build<N> = (node: N, attrs: Record<string, string>, children: VNode[]) => VNode;
|
|
6
|
+
|
|
7
|
+
export type ElementDefinition<N> = {
|
|
8
|
+
baseCss: string;
|
|
9
|
+
build: Build<N>;
|
|
10
|
+
descriptor: ElementDescriptor;
|
|
11
|
+
defaults: () => Omit<N, "id">;
|
|
12
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LoopNode,
|
|
3
|
+
SectionNode,
|
|
4
|
+
PostAuthorNode,
|
|
5
|
+
PostContentNode,
|
|
6
|
+
PostDateNode,
|
|
7
|
+
PostExcerptNode,
|
|
8
|
+
PostImageNode,
|
|
9
|
+
PostLinkNode,
|
|
10
|
+
PostTitleNode,
|
|
11
|
+
} from "../schema/layout.ts";
|
|
12
|
+
import type { ElementDefinition } from "./definition.ts";
|
|
13
|
+
|
|
14
|
+
export const postTitle: ElementDefinition<PostTitleNode> = {
|
|
15
|
+
baseCss: ".emvb-post-title{margin:0}",
|
|
16
|
+
defaults: () => ({ type: "post-title", props: { level: 1 } }),
|
|
17
|
+
descriptor: {
|
|
18
|
+
type: "post-title",
|
|
19
|
+
name: "Post Title",
|
|
20
|
+
group: "dynamic",
|
|
21
|
+
defaultTab: "content",
|
|
22
|
+
fields: [
|
|
23
|
+
{
|
|
24
|
+
key: "level",
|
|
25
|
+
kind: "select",
|
|
26
|
+
label: "Level",
|
|
27
|
+
optional: true,
|
|
28
|
+
options: [1, 2, 3, 4, 5, 6].map((n) => ({ value: n, label: `H${n}` })),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
// Rendered with ThemeDynamicData in renderPage (placeholder build for typing).
|
|
33
|
+
build: (_node, attrs) => ({ tag: "h1", attrs, children: ["Post Title"] }),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const postExcerpt: ElementDefinition<PostExcerptNode> = {
|
|
37
|
+
baseCss: ".emvb-post-excerpt{margin:0}",
|
|
38
|
+
defaults: () => ({ type: "post-excerpt", props: {} }),
|
|
39
|
+
descriptor: {
|
|
40
|
+
type: "post-excerpt",
|
|
41
|
+
name: "Post Excerpt",
|
|
42
|
+
group: "dynamic",
|
|
43
|
+
defaultTab: "style",
|
|
44
|
+
fields: [],
|
|
45
|
+
},
|
|
46
|
+
build: (_node, attrs) => ({ tag: "p", attrs, children: ["Post excerpt…"] }),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const postContent: ElementDefinition<PostContentNode> = {
|
|
50
|
+
baseCss: ".emvb-post-content{min-width:0}",
|
|
51
|
+
defaults: () => ({ type: "post-content", props: {} }),
|
|
52
|
+
descriptor: {
|
|
53
|
+
type: "post-content",
|
|
54
|
+
name: "Post Content",
|
|
55
|
+
group: "dynamic",
|
|
56
|
+
defaultTab: "style",
|
|
57
|
+
fields: [],
|
|
58
|
+
},
|
|
59
|
+
build: (_node, attrs) => ({
|
|
60
|
+
tag: "div",
|
|
61
|
+
attrs,
|
|
62
|
+
children: [{ tag: "p", attrs: {}, children: ["Post content…"] }],
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const postImage: ElementDefinition<PostImageNode> = {
|
|
67
|
+
baseCss: ".emvb-post-image{display:block;max-width:100%;height:auto}",
|
|
68
|
+
defaults: () => ({ type: "post-image", props: { decorative: false } }),
|
|
69
|
+
descriptor: {
|
|
70
|
+
type: "post-image",
|
|
71
|
+
name: "Post Image",
|
|
72
|
+
group: "dynamic",
|
|
73
|
+
defaultTab: "content",
|
|
74
|
+
fields: [{ key: "decorative", kind: "boolean", label: "Decorative", optional: true }],
|
|
75
|
+
},
|
|
76
|
+
build: (_node, attrs) => ({
|
|
77
|
+
tag: "div",
|
|
78
|
+
attrs: { ...attrs, class: `${attrs.class ?? ""} emvb-post-image-missing`.trim() },
|
|
79
|
+
children: ["Featured image"],
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const postDate: ElementDefinition<PostDateNode> = {
|
|
84
|
+
baseCss: ".emvb-post-date{margin:0}",
|
|
85
|
+
defaults: () => ({ type: "post-date", props: {} }),
|
|
86
|
+
descriptor: {
|
|
87
|
+
type: "post-date",
|
|
88
|
+
name: "Post Date",
|
|
89
|
+
group: "dynamic",
|
|
90
|
+
defaultTab: "style",
|
|
91
|
+
fields: [],
|
|
92
|
+
},
|
|
93
|
+
build: (_node, attrs) => ({ tag: "time", attrs, children: ["Post date"] }),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const postAuthor: ElementDefinition<PostAuthorNode> = {
|
|
97
|
+
baseCss: ".emvb-post-author{margin:0}",
|
|
98
|
+
defaults: () => ({ type: "post-author", props: {} }),
|
|
99
|
+
descriptor: {
|
|
100
|
+
type: "post-author",
|
|
101
|
+
name: "Post Author",
|
|
102
|
+
group: "dynamic",
|
|
103
|
+
defaultTab: "style",
|
|
104
|
+
fields: [],
|
|
105
|
+
},
|
|
106
|
+
build: (_node, attrs) => ({ tag: "span", attrs, children: ["Author"] }),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const postLink: ElementDefinition<PostLinkNode> = {
|
|
110
|
+
baseCss: ".emvb-post-link{color:inherit}",
|
|
111
|
+
defaults: () => ({ type: "post-link", props: {} }),
|
|
112
|
+
descriptor: {
|
|
113
|
+
type: "post-link",
|
|
114
|
+
name: "Post Link",
|
|
115
|
+
group: "dynamic",
|
|
116
|
+
defaultTab: "content",
|
|
117
|
+
fields: [
|
|
118
|
+
{
|
|
119
|
+
key: "text",
|
|
120
|
+
kind: "text",
|
|
121
|
+
label: "Text",
|
|
122
|
+
optional: true,
|
|
123
|
+
message: "Leave blank to use the post title.",
|
|
124
|
+
},
|
|
125
|
+
{ key: "newTab", kind: "boolean", label: "Open in new tab", optional: true },
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
build: (_node, attrs) => ({ tag: "a", attrs: { ...attrs, href: "#" }, children: ["Post link"] }),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const loop: ElementDefinition<LoopNode> = {
|
|
132
|
+
baseCss: ".emvb-loop{display:flex;flex-direction:column;min-width:0;gap:1rem}",
|
|
133
|
+
defaults: () => ({ type: "loop", props: {}, children: [] }),
|
|
134
|
+
descriptor: {
|
|
135
|
+
type: "loop",
|
|
136
|
+
name: "Loop",
|
|
137
|
+
group: "dynamic",
|
|
138
|
+
defaultTab: "content",
|
|
139
|
+
fields: [
|
|
140
|
+
{
|
|
141
|
+
key: "itemPartId",
|
|
142
|
+
kind: "text",
|
|
143
|
+
label: "Loop Item",
|
|
144
|
+
optional: true,
|
|
145
|
+
message:
|
|
146
|
+
"Optional published Loop Item theme part. Leave blank to use nested elements as the item template.",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const section: ElementDefinition<SectionNode> = {
|
|
154
|
+
baseCss: ".emvb-section{display:flex;flex-direction:column;min-width:0}",
|
|
155
|
+
defaults: () => ({ type: "section", props: {}, children: [] }),
|
|
156
|
+
descriptor: {
|
|
157
|
+
type: "section",
|
|
158
|
+
name: "Section",
|
|
159
|
+
group: "layout",
|
|
160
|
+
defaultTab: "content",
|
|
161
|
+
fields: [
|
|
162
|
+
{
|
|
163
|
+
key: "partId",
|
|
164
|
+
kind: "text",
|
|
165
|
+
label: "Section",
|
|
166
|
+
optional: true,
|
|
167
|
+
message:
|
|
168
|
+
"Optional published Section theme part. When set, the part's contents replace the nested elements on every page that uses it.",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
|
|
173
|
+
};
|