@perkyzz/emvb 0.3.0 → 0.4.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/README.md +4 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +106 -332
- package/src/admin/editor/EditorOverlay.tsx +3 -1
- package/src/admin/editor/PerfMeter.tsx +1 -1
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +16 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
- package/src/admin/editor/canvas/canvas-scale.ts +20 -0
- package/src/admin/editor/canvas/drop-line.ts +24 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
- package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
- package/src/admin/editor/collection-previews.ts +28 -5
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +15 -15
- package/src/admin/editor/host.ts +33 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
- package/src/admin/editor/icons/library.ts +29 -19
- package/src/admin/editor/icons/use-icon-library.ts +315 -0
- package/src/admin/editor/palette-items.ts +36 -5
- package/src/admin/editor/palette.ts +3 -2
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +40 -99
- package/src/admin/editor/panels/LayersPanel.tsx +34 -62
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +15 -4
- package/src/admin/editor/panels/settings/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +4 -0
- package/src/admin/editor/store.ts +10 -1
- package/src/admin/editor/useClipboardActions.ts +1 -1
- package/src/admin/editor/useEditorCommands.ts +61 -13
- package/src/admin/editor/useEditorData.ts +7 -1
- package/src/admin/editor/useEditorShortcuts.ts +23 -15
- package/src/admin/editor/useNodeActions.ts +6 -1
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/astro/content-port.ts +24 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +20 -8
- package/src/astro/resolve-theme.ts +166 -76
- package/src/astro/resolve.ts +57 -16
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +63 -38
- package/src/core/audience/rules.ts +22 -2
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +9 -0
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +4 -6
- package/src/core/design/classes.ts +13 -15
- package/src/core/design/diff.ts +55 -0
- package/src/core/design/merge.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +30 -0
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +183 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/index.ts +10 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +9 -4
- package/src/core/nesting.ts +4 -23
- package/src/core/perf/scripts.ts +9 -6
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +155 -13
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +153 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +68 -28
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +200 -39
- package/src/core/theme/float.ts +1 -1
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyword allowlists the schema and the CSS sanitizer both read (W-357).
|
|
3
|
+
* Emission stays in the sanitizer.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
7
|
+
|
|
8
|
+
export const LENGTH_UNITS = ["px", "rem", "em", "%", "vw", "vh", "ch"] as const;
|
|
9
|
+
|
|
10
|
+
export const FLEX_DIRECTIONS = ["row", "column", "row-reverse", "column-reverse"] as const;
|
|
11
|
+
|
|
12
|
+
export const FLEX_WRAPS = ["nowrap", "wrap", "wrap-reverse"] as const;
|
|
13
|
+
|
|
14
|
+
export const JUSTIFY_CONTENT = [
|
|
15
|
+
"flex-start",
|
|
16
|
+
"flex-end",
|
|
17
|
+
"center",
|
|
18
|
+
"space-between",
|
|
19
|
+
"space-around",
|
|
20
|
+
"space-evenly",
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
export const ALIGN_ITEMS = ["stretch", "flex-start", "flex-end", "center", "baseline"] as const;
|
|
24
|
+
|
|
25
|
+
export const TEXT_ALIGNS = ["left", "center", "right", "justify"] as const;
|
|
26
|
+
|
|
27
|
+
export const TEXT_TRANSFORMS = ["none", "uppercase", "lowercase", "capitalize"] as const;
|
|
28
|
+
|
|
29
|
+
export const TEXT_DECORATIONS = ["none", "underline", "overline", "line-through"] as const;
|
|
30
|
+
|
|
31
|
+
export const BORDER_STYLES = ["none", "solid", "dashed", "dotted"] as const;
|
|
32
|
+
|
|
33
|
+
export const OVERFLOWS = ["visible", "hidden", "clip", "scroll", "auto"] as const;
|
|
34
|
+
|
|
35
|
+
export const OBJECT_FITS = ["fill", "contain", "cover", "none", "scale-down"] as const;
|
|
36
|
+
|
|
37
|
+
export const POSITIONS = ["static", "relative", "absolute", "fixed", "sticky"] as const;
|
|
38
|
+
|
|
39
|
+
export const CURSORS = [
|
|
40
|
+
"default",
|
|
41
|
+
"pointer",
|
|
42
|
+
"text",
|
|
43
|
+
"move",
|
|
44
|
+
"grab",
|
|
45
|
+
"not-allowed",
|
|
46
|
+
"help",
|
|
47
|
+
"crosshair",
|
|
48
|
+
"zoom-in",
|
|
49
|
+
] as const;
|
|
50
|
+
|
|
51
|
+
export const FONT_WEIGHTS = [
|
|
52
|
+
"normal",
|
|
53
|
+
"bold",
|
|
54
|
+
"100",
|
|
55
|
+
"200",
|
|
56
|
+
"300",
|
|
57
|
+
"400",
|
|
58
|
+
"500",
|
|
59
|
+
"600",
|
|
60
|
+
"700",
|
|
61
|
+
"800",
|
|
62
|
+
"900",
|
|
63
|
+
] as const;
|
|
64
|
+
|
|
65
|
+
export const TRANSITION_EASINGS = ["ease", "ease-in", "ease-out", "ease-in-out", "linear"] as const;
|
|
66
|
+
|
|
67
|
+
export const TRANSITION_PROPERTIES = ["all", "colors", "opacity", "shadow", "filter"] as const;
|
|
68
|
+
|
|
69
|
+
export const BACKGROUND_SIZES = ["auto", "cover", "contain"] as const;
|
|
70
|
+
|
|
71
|
+
export const BACKGROUND_POSITIONS = [
|
|
72
|
+
"center",
|
|
73
|
+
"top",
|
|
74
|
+
"bottom",
|
|
75
|
+
"left",
|
|
76
|
+
"right",
|
|
77
|
+
"top left",
|
|
78
|
+
"top right",
|
|
79
|
+
"bottom left",
|
|
80
|
+
"bottom right",
|
|
81
|
+
] as const;
|
|
82
|
+
|
|
83
|
+
export const BACKGROUND_REPEATS = ["no-repeat", "repeat", "repeat-x", "repeat-y"] as const;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Binding, BindSource, LayoutNode } from "../schema/layout.ts";
|
|
2
|
+
import { someNode } from "../tree-ops.ts";
|
|
2
3
|
import { sanitizeHref } from "../sanitize/href.ts";
|
|
3
4
|
import { sanitizeMediaUrl } from "../sanitize/media-url.ts";
|
|
4
5
|
import type { ThemePostFields } from "../theme/dynamic.ts";
|
|
@@ -248,10 +249,7 @@ export function siteBindingValues(settings: unknown): Record<string, string> {
|
|
|
248
249
|
|
|
249
250
|
/** Whether any node in the tree reads a source (hosts fetch site settings only when needed). */
|
|
250
251
|
export function layoutUsesSource(root: LayoutNode, source: BindSource): boolean {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return Array.isArray(children) && (children as LayoutNode[]).some(walk);
|
|
255
|
-
};
|
|
256
|
-
return walk(root);
|
|
252
|
+
return someNode(root, (node) =>
|
|
253
|
+
Boolean(node.bind && Object.values(node.bind).some((b) => b.source === source)),
|
|
254
|
+
);
|
|
257
255
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DesignSystem } from "../schema/design.ts";
|
|
2
2
|
import type { Layout, LayoutNode } from "../schema/layout.ts";
|
|
3
3
|
import type { StyleProps } from "../schema/style.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { localStyleOf, withLocalStyle } from "../local-style.ts";
|
|
5
|
+
import { forEachNode, slugify, updateNode } from "../tree-ops.ts";
|
|
5
6
|
|
|
6
7
|
/** Reorder an applied class-id list. Out-of-range moves are no-ops. Pure (W-031). */
|
|
7
8
|
export function moveClassId(ids: readonly string[], index: number, delta: -1 | 1): string[] {
|
|
@@ -27,15 +28,10 @@ export function removeClassId(ids: readonly string[], id: string): string[] {
|
|
|
27
28
|
return ids.filter((entry) => entry !== id);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
function walk(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
31
|
-
visit(node);
|
|
32
|
-
for (const child of nodeChildren(node)) walk(child, visit);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
31
|
/** Nodes that list `classId` in `node.classes` (W-032 delete dialog). */
|
|
36
32
|
export function findClassUsages(layout: Layout, classId: string): { nodeId: string }[] {
|
|
37
33
|
const usages: { nodeId: string }[] = [];
|
|
38
|
-
|
|
34
|
+
forEachNode(layout.root, (node) => {
|
|
39
35
|
if (node.classes?.includes(classId)) usages.push({ nodeId: node.id });
|
|
40
36
|
});
|
|
41
37
|
return usages;
|
|
@@ -85,10 +81,11 @@ const filled = (style: object | undefined) =>
|
|
|
85
81
|
|
|
86
82
|
/** Whether an element has local styles: base, hover/focus/active or tablet/mobile (W-134). */
|
|
87
83
|
export function hasLocalStyles(node: LayoutNode): boolean {
|
|
84
|
+
const local = localStyleOf(node);
|
|
88
85
|
return (
|
|
89
|
-
filled(
|
|
90
|
-
Object.values(
|
|
91
|
-
Object.values(
|
|
86
|
+
filled(local.style) ||
|
|
87
|
+
Object.values(local.states ?? {}).some(filled) ||
|
|
88
|
+
Object.values(local.devices ?? {}).some(filled)
|
|
92
89
|
);
|
|
93
90
|
}
|
|
94
91
|
|
|
@@ -130,17 +127,18 @@ export function localStylesToClass(
|
|
|
130
127
|
const taken = new Set(classes.map((c) => c.id));
|
|
131
128
|
let id = base;
|
|
132
129
|
for (let n = 2; taken.has(id); n++) id = `${base}-${n}`;
|
|
130
|
+
const local = localStyleOf(node);
|
|
133
131
|
const cls = {
|
|
134
132
|
id,
|
|
135
133
|
name: trimmed,
|
|
136
|
-
style:
|
|
137
|
-
...(
|
|
138
|
-
...(
|
|
134
|
+
style: (local.style ?? {}) as StyleProps,
|
|
135
|
+
...(local.states ? { states: local.states } : {}),
|
|
136
|
+
...(local.devices ? { devices: local.devices } : {}),
|
|
139
137
|
};
|
|
140
|
-
const
|
|
138
|
+
const cleared = withLocalStyle(node, local.hiddenOn ? { hiddenOn: local.hiddenOn } : {});
|
|
141
139
|
return {
|
|
142
140
|
design: { ...design, classes: [...classes, cls] },
|
|
143
|
-
node: { ...
|
|
141
|
+
node: { ...cleared, classes: addClassId(node.classes ?? [], id) },
|
|
144
142
|
classId: id,
|
|
145
143
|
};
|
|
146
144
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DesignSystem } from "../schema/design.ts";
|
|
2
|
+
|
|
3
|
+
export type DesignChange = {
|
|
4
|
+
kind: "added" | "removed" | "changed";
|
|
5
|
+
what: "variable" | "class" | "setting";
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
|
|
10
|
+
|
|
11
|
+
/** What Publish styles will write: draft compared with the published design (W-340). */
|
|
12
|
+
export function designChanges(published: DesignSystem, draft: DesignSystem): DesignChange[] {
|
|
13
|
+
const changes: DesignChange[] = [];
|
|
14
|
+
listChanges(published.variables.colors, draft.variables.colors, "variable", changes);
|
|
15
|
+
listChanges(published.variables.fonts, draft.variables.fonts, "variable", changes);
|
|
16
|
+
listChanges(published.variables.fontSizes, draft.variables.fontSizes, "variable", changes);
|
|
17
|
+
listChanges(published.variables.spacings, draft.variables.spacings, "variable", changes);
|
|
18
|
+
listChanges(published.classes, draft.classes, "class", changes);
|
|
19
|
+
if (!same(published.direction, draft.direction)) {
|
|
20
|
+
changes.push({ kind: "changed", what: "setting", name: "Direction" });
|
|
21
|
+
}
|
|
22
|
+
if (!same(published.fluidRange, draft.fluidRange)) {
|
|
23
|
+
changes.push({ kind: "changed", what: "setting", name: "Fluid range" });
|
|
24
|
+
}
|
|
25
|
+
if (!same(published.defaults, draft.defaults)) {
|
|
26
|
+
changes.push({ kind: "changed", what: "setting", name: "Tag defaults" });
|
|
27
|
+
}
|
|
28
|
+
return changes;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function designChangeLabel(change: DesignChange): string {
|
|
32
|
+
const noun =
|
|
33
|
+
change.what === "class" ? "Class" : change.what === "setting" ? "Setting" : "Variable";
|
|
34
|
+
if (change.kind === "added") return `Add ${noun.toLowerCase()} ${change.name}`;
|
|
35
|
+
if (change.kind === "removed") return `Remove ${noun.toLowerCase()} ${change.name}`;
|
|
36
|
+
return `Change ${noun.toLowerCase()} ${change.name}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function listChanges<T extends { id: string; name: string }>(
|
|
40
|
+
published: T[] | undefined,
|
|
41
|
+
draft: T[] | undefined,
|
|
42
|
+
what: "variable" | "class",
|
|
43
|
+
into: DesignChange[],
|
|
44
|
+
) {
|
|
45
|
+
const from = new Map((published ?? []).map((item) => [item.id, item]));
|
|
46
|
+
const to = new Map((draft ?? []).map((item) => [item.id, item]));
|
|
47
|
+
for (const item of draft ?? []) {
|
|
48
|
+
const before = from.get(item.id);
|
|
49
|
+
if (!before) into.push({ kind: "added", what, name: item.name });
|
|
50
|
+
else if (!same(before, item)) into.push({ kind: "changed", what, name: item.name });
|
|
51
|
+
}
|
|
52
|
+
for (const item of published ?? []) {
|
|
53
|
+
if (!to.has(item.id)) into.push({ kind: "removed", what, name: item.name });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { emptyDesign, type DesignSystem } from "../schema/design.ts";
|
|
2
|
+
|
|
3
|
+
export type DesignConflict = { kind: "variable" | "class" | "setting"; name: string };
|
|
4
|
+
|
|
5
|
+
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
|
|
6
|
+
|
|
7
|
+
type Named = { id: string; name: string };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Replays `ours` (what this tab tried to save) onto `theirs` (what the server has now),
|
|
11
|
+
* starting from `base` (what this tab last loaded). A list item this tab changed is kept
|
|
12
|
+
* when the server still has the base copy. When both sides changed the same item, the
|
|
13
|
+
* server copy stays and the name is reported. Nothing is overwritten silently.
|
|
14
|
+
*/
|
|
15
|
+
export function mergeDesign(
|
|
16
|
+
base: DesignSystem | undefined,
|
|
17
|
+
ours: DesignSystem,
|
|
18
|
+
theirs: DesignSystem,
|
|
19
|
+
): { design: DesignSystem; conflicts: DesignConflict[] } {
|
|
20
|
+
const from = base ?? emptyDesign();
|
|
21
|
+
const conflicts: DesignConflict[] = [];
|
|
22
|
+
const design: DesignSystem = {
|
|
23
|
+
...theirs,
|
|
24
|
+
variables: {
|
|
25
|
+
colors: mergeList(
|
|
26
|
+
from.variables.colors,
|
|
27
|
+
ours.variables.colors,
|
|
28
|
+
theirs.variables.colors,
|
|
29
|
+
conflicts,
|
|
30
|
+
"variable",
|
|
31
|
+
),
|
|
32
|
+
fonts: mergeList(
|
|
33
|
+
from.variables.fonts,
|
|
34
|
+
ours.variables.fonts,
|
|
35
|
+
theirs.variables.fonts,
|
|
36
|
+
conflicts,
|
|
37
|
+
"variable",
|
|
38
|
+
),
|
|
39
|
+
fontSizes: mergeList(
|
|
40
|
+
from.variables.fontSizes,
|
|
41
|
+
ours.variables.fontSizes,
|
|
42
|
+
theirs.variables.fontSizes,
|
|
43
|
+
conflicts,
|
|
44
|
+
"variable",
|
|
45
|
+
),
|
|
46
|
+
spacings: mergeList(
|
|
47
|
+
from.variables.spacings,
|
|
48
|
+
ours.variables.spacings,
|
|
49
|
+
theirs.variables.spacings,
|
|
50
|
+
conflicts,
|
|
51
|
+
"variable",
|
|
52
|
+
),
|
|
53
|
+
},
|
|
54
|
+
classes: mergeList(from.classes, ours.classes, theirs.classes, conflicts, "class"),
|
|
55
|
+
fluidRange: pickSetting(
|
|
56
|
+
from.fluidRange,
|
|
57
|
+
ours.fluidRange,
|
|
58
|
+
theirs.fluidRange,
|
|
59
|
+
conflicts,
|
|
60
|
+
"Fluid range",
|
|
61
|
+
),
|
|
62
|
+
direction: pickSetting(
|
|
63
|
+
from.direction,
|
|
64
|
+
ours.direction,
|
|
65
|
+
theirs.direction,
|
|
66
|
+
conflicts,
|
|
67
|
+
"Direction",
|
|
68
|
+
),
|
|
69
|
+
defaults: pickSetting(from.defaults, ours.defaults, theirs.defaults, conflicts, "Tag defaults"),
|
|
70
|
+
};
|
|
71
|
+
return { design, conflicts };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function mergeList<T extends Named>(
|
|
75
|
+
base: T[] | undefined,
|
|
76
|
+
ours: T[] | undefined,
|
|
77
|
+
theirs: T[] | undefined,
|
|
78
|
+
conflicts: DesignConflict[],
|
|
79
|
+
kind: "variable" | "class",
|
|
80
|
+
): T[] {
|
|
81
|
+
const baseItems = base ?? [];
|
|
82
|
+
const ourItems = ours ?? [];
|
|
83
|
+
const theirItems = theirs ?? [];
|
|
84
|
+
const by = (list: T[]) => new Map(list.map((item) => [item.id, item]));
|
|
85
|
+
const baseBy = by(baseItems);
|
|
86
|
+
const oursBy = by(ourItems);
|
|
87
|
+
const theirsBy = by(theirItems);
|
|
88
|
+
const result: T[] = [];
|
|
89
|
+
const seen = new Set<string>();
|
|
90
|
+
const take = (id: string) => {
|
|
91
|
+
if (seen.has(id)) return;
|
|
92
|
+
seen.add(id);
|
|
93
|
+
const baseItem = baseBy.get(id);
|
|
94
|
+
const ourItem = oursBy.get(id);
|
|
95
|
+
const theirItem = theirsBy.get(id);
|
|
96
|
+
const weChanged = !same(baseItem, ourItem);
|
|
97
|
+
const theyChanged = !same(baseItem, theirItem);
|
|
98
|
+
if (!weChanged) {
|
|
99
|
+
if (theirItem) result.push(theirItem);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!theyChanged || same(ourItem, theirItem)) {
|
|
103
|
+
if (ourItem) result.push(ourItem);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
conflicts.push({ kind, name: ourItem?.name ?? theirItem?.name ?? id });
|
|
107
|
+
if (theirItem) result.push(theirItem);
|
|
108
|
+
};
|
|
109
|
+
for (const item of theirItems) take(item.id);
|
|
110
|
+
for (const item of ourItems) take(item.id);
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function pickSetting<T>(
|
|
115
|
+
base: T | undefined,
|
|
116
|
+
ours: T | undefined,
|
|
117
|
+
theirs: T | undefined,
|
|
118
|
+
conflicts: DesignConflict[],
|
|
119
|
+
name: string,
|
|
120
|
+
): T | undefined {
|
|
121
|
+
const weChanged = !same(base, ours);
|
|
122
|
+
const theyChanged = !same(base, theirs);
|
|
123
|
+
if (!weChanged) return theirs;
|
|
124
|
+
if (!theyChanged || same(ours, theirs)) return ours;
|
|
125
|
+
conflicts.push({ kind: "setting", name });
|
|
126
|
+
return theirs;
|
|
127
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DesignSystem } from "../schema/design.ts";
|
|
2
|
-
import type { Layout
|
|
2
|
+
import type { Layout } from "../schema/layout.ts";
|
|
3
3
|
import { cleanClassName } from "./classes.ts";
|
|
4
4
|
import { STYLE_STATES } from "../schema/state-names.ts";
|
|
5
5
|
import type { DeviceStyles, StyleProps, StyleStates } from "../schema/style.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { forEachNode, slugify, updateNode } from "../tree-ops.ts";
|
|
7
7
|
|
|
8
8
|
export type VariableKind = "color" | "font" | "fontSize" | "spacing";
|
|
9
9
|
|
|
@@ -32,26 +32,35 @@ export function refMatchesKind(ref: VariableRefLike, kind: VariableKind): boolea
|
|
|
32
32
|
const matches = (value: unknown, id: string, kind: VariableKind | undefined) =>
|
|
33
33
|
isVariableRef(value) && value.var === id && (kind === undefined || refMatchesKind(value, kind));
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
const shadowColorMatches = (style: StyleProps, id: string, kind: VariableKind | undefined) =>
|
|
37
|
-
matches(style.boxShadow?.color, id, kind);
|
|
35
|
+
const NESTED_COLOR_KEYS = new Set(["boxShadow", "iconShadow", "gradient", "overlay"]);
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
/** Every value that can be a variable, including nested colours (W-356). */
|
|
38
|
+
export function forEachStyleRef(
|
|
40
39
|
style: StyleProps | undefined,
|
|
41
|
-
|
|
42
|
-
kind: VariableKind | undefined,
|
|
43
|
-
hit: (prop: string) => void,
|
|
40
|
+
visit: (value: unknown, path: string) => void,
|
|
44
41
|
): void {
|
|
45
42
|
if (!style) return;
|
|
46
43
|
for (const [prop, value] of Object.entries(style)) {
|
|
47
|
-
if (
|
|
44
|
+
if (NESTED_COLOR_KEYS.has(prop)) continue;
|
|
45
|
+
visit(value, prop);
|
|
48
46
|
}
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
47
|
+
if (style.boxShadow) visit(style.boxShadow.color, "boxShadow.color");
|
|
48
|
+
if (style.iconShadow) visit(style.iconShadow.color, "iconShadow.color");
|
|
51
49
|
style.gradient?.stops.forEach((stop, index) => {
|
|
52
|
-
|
|
50
|
+
visit(stop.color, `gradient.stops.${index}`);
|
|
51
|
+
});
|
|
52
|
+
if (style.overlay) visit(style.overlay.color, "overlay.color");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function collectStyleUsages(
|
|
56
|
+
style: StyleProps | undefined,
|
|
57
|
+
id: string,
|
|
58
|
+
kind: VariableKind | undefined,
|
|
59
|
+
hit: (prop: string) => void,
|
|
60
|
+
): void {
|
|
61
|
+
forEachStyleRef(style, (value, path) => {
|
|
62
|
+
if (matches(value, id, kind)) hit(path);
|
|
53
63
|
});
|
|
54
|
-
if (matches(style.overlay?.color, id, kind)) hit("overlay.color");
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
const RESPONSIVE = ["tablet", "mobile"] as const;
|
|
@@ -72,11 +81,6 @@ function collectAllUsages(
|
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
|
|
75
|
-
function walkNodes(node: LayoutNode, visit: (node: LayoutNode) => void): void {
|
|
76
|
-
visit(node);
|
|
77
|
-
for (const child of nodeChildren(node)) walkNodes(child, visit);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
84
|
/** Find every style property on `layout` that references variable `id` (optionally of `kind`). */
|
|
81
85
|
export function findVariableUsages(
|
|
82
86
|
layout: Layout,
|
|
@@ -84,7 +88,7 @@ export function findVariableUsages(
|
|
|
84
88
|
kind?: VariableKind,
|
|
85
89
|
): VariableUsage[] {
|
|
86
90
|
const usages: VariableUsage[] = [];
|
|
87
|
-
|
|
91
|
+
forEachNode(layout.root, (node) => {
|
|
88
92
|
collectAllUsages(node, id, kind, (prop) => {
|
|
89
93
|
usages.push({ nodeId: node.id, prop });
|
|
90
94
|
});
|
|
@@ -123,7 +127,7 @@ function stripRefsFromStyle(
|
|
|
123
127
|
delete next[prop];
|
|
124
128
|
changed = true;
|
|
125
129
|
}
|
|
126
|
-
if (style.boxShadow &&
|
|
130
|
+
if (style.boxShadow && matches(style.boxShadow.color, id, kind)) {
|
|
127
131
|
const { color: _drop, ...shadow } = style.boxShadow;
|
|
128
132
|
next["boxShadow"] = shadow;
|
|
129
133
|
changed = true;
|
|
@@ -216,6 +216,36 @@ export const loop: ElementDefinition<LoopNode> = {
|
|
|
216
216
|
{ value: "title", label: "By title" },
|
|
217
217
|
],
|
|
218
218
|
},
|
|
219
|
+
{
|
|
220
|
+
key: "permalink",
|
|
221
|
+
kind: "text",
|
|
222
|
+
label: "Link pattern",
|
|
223
|
+
optional: true,
|
|
224
|
+
message:
|
|
225
|
+
"Where each entry links, e.g. /team/{slug}; {slug} and {id} are filled in. Leave it empty for /collection/{slug}.",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
key: "imageField",
|
|
229
|
+
kind: "text",
|
|
230
|
+
label: "Image field",
|
|
231
|
+
optional: true,
|
|
232
|
+
message: "The field Post Image shows, e.g. photo. Leave it empty for the featured image.",
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
key: "excerptField",
|
|
236
|
+
kind: "text",
|
|
237
|
+
label: "Excerpt field",
|
|
238
|
+
optional: true,
|
|
239
|
+
message: "The field Post Excerpt shows, e.g. role. Leave it empty for the excerpt.",
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "filter",
|
|
243
|
+
kind: "text",
|
|
244
|
+
label: "Only entries where",
|
|
245
|
+
optional: true,
|
|
246
|
+
message:
|
|
247
|
+
"field=value pairs separated by ;, e.g. category=news; team=design. A taxonomy works too. The same field twice matches either value.",
|
|
248
|
+
},
|
|
219
249
|
{
|
|
220
250
|
key: "itemPartId",
|
|
221
251
|
kind: "text",
|
|
@@ -50,6 +50,7 @@ const FORM_FIELD_CSS =
|
|
|
50
50
|
export const form: ElementDefinition<FormNode> = {
|
|
51
51
|
baseCss:
|
|
52
52
|
".emvb-form{display:flex;flex-direction:column;gap:12px;min-width:0}.emvb-form-unbound{min-height:48px;padding:12px;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}.ec-form-hp{position:absolute;left:-9999px}" +
|
|
53
|
+
":where(.emvb-form-paused){padding:12px 16px;border:1px solid rgba(128,128,128,.5);border:1px solid color-mix(in srgb,currentColor 25%,transparent);border-radius:6px}:where(.emvb-form-paused p){margin:0}" +
|
|
53
54
|
FORM_FIELD_CSS,
|
|
54
55
|
defaults: () => ({ type: "form", props: { formId: "" }, children: [] }),
|
|
55
56
|
descriptor: fieldDescriptor("form", "Form", [
|