@perkyzz/emvb 0.3.0 → 0.5.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 +22 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +5 -2
- package/src/admin/access/role.ts +9 -3
- package/src/admin/agents-api.ts +39 -0
- 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/CommandPalette.tsx +43 -2
- package/src/admin/editor/Editor.tsx +133 -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 +124 -9
- 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/editor-css.ts +4 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +37 -18
- 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 +9 -4
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +21 -18
- 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/TokenScales.tsx +4 -2
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/color-space.ts +12 -1
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
- package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- 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/link-rules.ts +19 -0
- package/src/admin/editor/panels/settings/number-input.ts +11 -0
- package/src/admin/editor/panels/settings/query-style.ts +65 -0
- 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/panels/variable-values.ts +4 -2
- package/src/admin/editor/remote-change.ts +67 -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/index.tsx +3 -1
- package/src/admin/media-api.ts +20 -0
- package/src/admin/pages/AgentsPage.tsx +274 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/admin/ui.ts +28 -0
- package/src/astro/content-port.ts +24 -0
- package/src/astro/floats/runtime.ts +10 -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/popups/runtime.ts +15 -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/tabs/runtime.ts +60 -1
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +202 -26
- package/src/core/arrange.ts +71 -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 +18 -1
- 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 +20 -3
- package/src/core/elements/index.ts +211 -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 +22 -7
- package/src/core/render/form.ts +145 -15
- package/src/core/render/index.ts +195 -14
- package/src/core/render/pagination.ts +21 -2
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/embed-url.ts +7 -1
- package/src/core/sanitize/href.ts +13 -1
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/descriptors.ts +4 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +160 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +72 -29
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +205 -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/mcp/errors.ts +44 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/ports.ts +78 -0
- package/src/mcp/prompts.ts +76 -0
- package/src/mcp/publish.ts +60 -0
- package/src/mcp/queue.ts +19 -0
- package/src/mcp/rate-limit.ts +80 -0
- package/src/mcp/read.ts +419 -0
- package/src/mcp/refs.ts +84 -0
- package/src/mcp/settings.ts +18 -0
- package/src/mcp/tools.ts +265 -0
- package/src/mcp/write.ts +582 -0
- package/src/server/agent-settings.ts +134 -0
- package/src/server/design-routes.ts +75 -18
- package/src/server/icon-routes.ts +72 -16
- package/src/server/mcp-routes.ts +265 -0
- package/src/server/plugin.ts +40 -4
- 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
|
@@ -47,6 +47,21 @@ export const hasItemList = (type: string) => type in KINDS;
|
|
|
47
47
|
const childrenOf = (node: LayoutNode): LayoutNode[] =>
|
|
48
48
|
"children" in node && Array.isArray(node.children) ? (node.children as LayoutNode[]) : [];
|
|
49
49
|
|
|
50
|
+
/** One reorder of `kids`, moving `fromId` to `toIndex`. Same place or an unknown id changes nothing. */
|
|
51
|
+
export function reorderItems(
|
|
52
|
+
kids: LayoutNode[],
|
|
53
|
+
fromId: string,
|
|
54
|
+
toIndex: number,
|
|
55
|
+
): LayoutNode[] | undefined {
|
|
56
|
+
const from = kids.findIndex((item) => item.id === fromId);
|
|
57
|
+
if (from < 0 || from === toIndex) return undefined;
|
|
58
|
+
const next = kids.slice();
|
|
59
|
+
const [moved] = next.splice(from, 1);
|
|
60
|
+
if (!moved) return undefined;
|
|
61
|
+
next.splice(toIndex, 0, moved);
|
|
62
|
+
return next;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
/** Fallback when no editor actions are wired (isolated panels): plain edits of the parent. */
|
|
51
66
|
function localActions(node: LayoutNode, onChange: (node: LayoutNode) => void): ItemActions {
|
|
52
67
|
const kids = childrenOf(node);
|
|
@@ -115,7 +130,25 @@ export function ItemList({
|
|
|
115
130
|
{kids.map((child, index) => {
|
|
116
131
|
const n = index + 1;
|
|
117
132
|
return (
|
|
118
|
-
<li
|
|
133
|
+
<li
|
|
134
|
+
key={child.id}
|
|
135
|
+
className="emvb-item-row"
|
|
136
|
+
data-emvb-item={child.id}
|
|
137
|
+
draggable
|
|
138
|
+
onDragStart={(event) => {
|
|
139
|
+
event.dataTransfer.setData("text/plain", child.id);
|
|
140
|
+
event.dataTransfer.effectAllowed = "move";
|
|
141
|
+
}}
|
|
142
|
+
onDragOver={(event) => {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
event.dataTransfer.dropEffect = "move";
|
|
145
|
+
}}
|
|
146
|
+
onDrop={(event) => {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
const next = reorderItems(kids, event.dataTransfer.getData("text/plain"), index);
|
|
149
|
+
if (next) onChange({ ...node, children: next } as LayoutNode);
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
119
152
|
<DraftTextField
|
|
120
153
|
field={kind.field(n)}
|
|
121
154
|
node={child}
|
|
@@ -5,6 +5,7 @@ import type { Fetcher } from "../../../api.ts";
|
|
|
5
5
|
import {
|
|
6
6
|
listImages,
|
|
7
7
|
propsFromMedia,
|
|
8
|
+
propsFromUrl,
|
|
8
9
|
uploadImage,
|
|
9
10
|
type MediaLibraryItem,
|
|
10
11
|
} from "../../../media-api.ts";
|
|
@@ -103,9 +104,7 @@ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props)
|
|
|
103
104
|
}
|
|
104
105
|
setError(null);
|
|
105
106
|
if (safe === src) return;
|
|
106
|
-
|
|
107
|
-
delete next.mediaId;
|
|
108
|
-
onChange(withProps(node, next));
|
|
107
|
+
onChange(withProps(node, propsFromUrl(propsOf(node), safe)));
|
|
109
108
|
};
|
|
110
109
|
|
|
111
110
|
return (
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { LayoutNode } from "../../../../core/index.ts";
|
|
3
|
+
import { FIELD } from "../../../ui.ts";
|
|
4
|
+
import { savableNode } from "./DraftTextField.tsx";
|
|
5
|
+
import { formatStyleValue, parseStyleValue, QUERY_STYLE_KEYS } from "./query-style.ts";
|
|
6
|
+
|
|
7
|
+
type QueryStyle = NonNullable<LayoutNode["query"]>["style"];
|
|
8
|
+
|
|
9
|
+
/** Store `style` as the node's query style, or say why it can't be saved. */
|
|
10
|
+
function withQueryStyle(node: LayoutNode, style: Record<string, unknown>): LayoutNode | string {
|
|
11
|
+
const query = node.query;
|
|
12
|
+
if (!query) return "Set a container width first.";
|
|
13
|
+
const next = { ...node, query: { ...query, style: style as QueryStyle } } as LayoutNode;
|
|
14
|
+
return savableNode(next) || !savableNode(node) ? next : "That value can't be saved here.";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** One stored property: its value commits on blur or Enter; Remove deletes it. */
|
|
18
|
+
function QueryStyleRow({
|
|
19
|
+
node,
|
|
20
|
+
styleKey,
|
|
21
|
+
onChange,
|
|
22
|
+
}: {
|
|
23
|
+
node: LayoutNode;
|
|
24
|
+
styleKey: string;
|
|
25
|
+
onChange: (node: LayoutNode) => void;
|
|
26
|
+
}) {
|
|
27
|
+
const style = (node.query?.style ?? {}) as Record<string, unknown>;
|
|
28
|
+
const stored = formatStyleValue(style[styleKey]);
|
|
29
|
+
const [draft, setDraft] = React.useState(stored);
|
|
30
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
setDraft(stored);
|
|
33
|
+
setError(null);
|
|
34
|
+
}, [stored]);
|
|
35
|
+
const id = React.useId();
|
|
36
|
+
const commit = () => {
|
|
37
|
+
if (draft === stored) {
|
|
38
|
+
setError(null);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const parsed = parseStyleValue(styleKey, draft);
|
|
42
|
+
if ("error" in parsed) {
|
|
43
|
+
setError(parsed.error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const next = withQueryStyle(node, { ...style, [styleKey]: parsed.value });
|
|
47
|
+
if (typeof next === "string") {
|
|
48
|
+
setError(next);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
setError(null);
|
|
52
|
+
onChange(next);
|
|
53
|
+
};
|
|
54
|
+
return (
|
|
55
|
+
<div className="emvb-query-row" data-emvb-query-key={styleKey}>
|
|
56
|
+
<label className="emvb-field-label" htmlFor={id}>
|
|
57
|
+
{styleKey}
|
|
58
|
+
</label>
|
|
59
|
+
<input
|
|
60
|
+
id={id}
|
|
61
|
+
className={FIELD}
|
|
62
|
+
value={draft}
|
|
63
|
+
aria-invalid={error ? true : undefined}
|
|
64
|
+
aria-describedby={error ? `${id}-error` : undefined}
|
|
65
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
66
|
+
onBlur={commit}
|
|
67
|
+
onKeyDown={(event) => {
|
|
68
|
+
if (event.key === "Enter") commit();
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
className="emvb-link-button"
|
|
74
|
+
aria-label={`Remove ${styleKey}`}
|
|
75
|
+
onClick={() => {
|
|
76
|
+
const { [styleKey]: _gone, ...rest } = style;
|
|
77
|
+
const next = withQueryStyle(node, rest);
|
|
78
|
+
if (typeof next !== "string") onChange(next);
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
Remove
|
|
82
|
+
</button>
|
|
83
|
+
{error && (
|
|
84
|
+
<span className="emvb-helper" id={`${id}-error`} data-emvb-query-error="">
|
|
85
|
+
{error}
|
|
86
|
+
</span>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The container-query style, one property per row, plus a row to add one (W-398). */
|
|
93
|
+
export function QueryStyleRows({
|
|
94
|
+
node,
|
|
95
|
+
onChange,
|
|
96
|
+
}: {
|
|
97
|
+
node: LayoutNode;
|
|
98
|
+
onChange: (node: LayoutNode) => void;
|
|
99
|
+
}) {
|
|
100
|
+
const style = (node.query?.style ?? {}) as Record<string, unknown>;
|
|
101
|
+
const keys = Object.keys(style).filter((key) => style[key] !== undefined);
|
|
102
|
+
const free = QUERY_STYLE_KEYS.filter((key) => !keys.includes(key));
|
|
103
|
+
const [newKey, setNewKey] = React.useState("");
|
|
104
|
+
const [newValue, setNewValue] = React.useState("");
|
|
105
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
106
|
+
const keyId = React.useId();
|
|
107
|
+
const valueId = React.useId();
|
|
108
|
+
if (!node.query) return null;
|
|
109
|
+
const add = () => {
|
|
110
|
+
if (!newKey) {
|
|
111
|
+
setError("Choose a property.");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const parsed = parseStyleValue(newKey, newValue);
|
|
115
|
+
if ("error" in parsed) {
|
|
116
|
+
setError(parsed.error);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const next = withQueryStyle(node, { ...style, [newKey]: parsed.value });
|
|
120
|
+
if (typeof next === "string") {
|
|
121
|
+
setError(next);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
setError(null);
|
|
125
|
+
setNewKey("");
|
|
126
|
+
setNewValue("");
|
|
127
|
+
onChange(next);
|
|
128
|
+
};
|
|
129
|
+
return (
|
|
130
|
+
<div className="emvb-query-style" data-emvb-query-style="">
|
|
131
|
+
{keys.length === 0 && <p className="emvb-helper">No styles at this width yet.</p>}
|
|
132
|
+
{keys.map((key) => (
|
|
133
|
+
<QueryStyleRow key={key} node={node} styleKey={key} onChange={onChange} />
|
|
134
|
+
))}
|
|
135
|
+
<div className="emvb-query-add" data-emvb-query-add="">
|
|
136
|
+
<label className="emvb-field-label" htmlFor={keyId}>
|
|
137
|
+
Property
|
|
138
|
+
</label>
|
|
139
|
+
<select
|
|
140
|
+
id={keyId}
|
|
141
|
+
className={FIELD}
|
|
142
|
+
value={newKey}
|
|
143
|
+
onChange={(event) => setNewKey(event.target.value)}
|
|
144
|
+
>
|
|
145
|
+
<option value="">Choose…</option>
|
|
146
|
+
{free.map((key) => (
|
|
147
|
+
<option key={key} value={key}>
|
|
148
|
+
{key}
|
|
149
|
+
</option>
|
|
150
|
+
))}
|
|
151
|
+
</select>
|
|
152
|
+
<label className="emvb-field-label" htmlFor={valueId}>
|
|
153
|
+
Value
|
|
154
|
+
</label>
|
|
155
|
+
<input
|
|
156
|
+
id={valueId}
|
|
157
|
+
className={FIELD}
|
|
158
|
+
placeholder="16px, auto, #112233, var(--space-4)"
|
|
159
|
+
value={newValue}
|
|
160
|
+
aria-invalid={error ? true : undefined}
|
|
161
|
+
aria-describedby={error ? `${valueId}-error` : undefined}
|
|
162
|
+
onChange={(event) => setNewValue(event.target.value)}
|
|
163
|
+
onKeyDown={(event) => {
|
|
164
|
+
if (event.key === "Enter") add();
|
|
165
|
+
}}
|
|
166
|
+
/>
|
|
167
|
+
<button type="button" className="emvb-link-button" onClick={add}>
|
|
168
|
+
Add style
|
|
169
|
+
</button>
|
|
170
|
+
{error && (
|
|
171
|
+
<span className="emvb-helper" id={`${valueId}-error`} data-emvb-query-error="">
|
|
172
|
+
{error}
|
|
173
|
+
</span>
|
|
174
|
+
)}
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
@@ -62,6 +62,7 @@ const LENGTH_KEYS = new Set<StyleKey>([
|
|
|
62
62
|
|
|
63
63
|
const Z_INDEX: NumberSpec = { min: -9999, max: 9999, integer: true, example: "10" };
|
|
64
64
|
const GRID_SPAN: NumberSpec = { min: 1, max: 12, integer: true, example: "2" };
|
|
65
|
+
const GRID_LINE: NumberSpec = { min: 1, max: 13, integer: true, example: "1" };
|
|
65
66
|
const OPACITY: NumberSpec = { min: 0, max: 100, scale: 100, example: "50", suffix: "%" };
|
|
66
67
|
|
|
67
68
|
const COLOR_KEYS = new Set<StyleKey>(["color", "backgroundColor", "borderColor"]);
|
|
@@ -410,9 +411,18 @@ export function StyleRow({
|
|
|
410
411
|
styleKey === "zIndex" ||
|
|
411
412
|
styleKey === "opacity" ||
|
|
412
413
|
styleKey === "gridColumnSpan" ||
|
|
413
|
-
styleKey === "gridRowSpan"
|
|
414
|
+
styleKey === "gridRowSpan" ||
|
|
415
|
+
styleKey === "gridColumnStart" ||
|
|
416
|
+
styleKey === "gridRowStart"
|
|
414
417
|
) {
|
|
415
|
-
const spec =
|
|
418
|
+
const spec =
|
|
419
|
+
styleKey === "zIndex"
|
|
420
|
+
? Z_INDEX
|
|
421
|
+
: styleKey === "opacity"
|
|
422
|
+
? OPACITY
|
|
423
|
+
: styleKey === "gridColumnStart" || styleKey === "gridRowStart"
|
|
424
|
+
? GRID_LINE
|
|
425
|
+
: GRID_SPAN;
|
|
416
426
|
return (
|
|
417
427
|
<NumberRow
|
|
418
428
|
rowKey={styleKey}
|
|
@@ -553,7 +563,9 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
553
563
|
"fontFamily",
|
|
554
564
|
"zIndex",
|
|
555
565
|
"gridColumnSpan",
|
|
566
|
+
"gridColumnStart",
|
|
556
567
|
"gridRowSpan",
|
|
568
|
+
"gridRowStart",
|
|
557
569
|
"opacity",
|
|
558
570
|
"boxShadow",
|
|
559
571
|
"filter",
|
|
@@ -26,6 +26,9 @@ export function htmlIdError(value: string, layout: Layout | null, nodeId: string
|
|
|
26
26
|
if (!HTML_ID.test(value)) {
|
|
27
27
|
return "Start with a letter; use letters, digits, - and _ only (up to 64).";
|
|
28
28
|
}
|
|
29
|
+
// W-418: EmVB names headings (emvb-h-…), form fields and tabs with emvb- ids; reusing one
|
|
30
|
+
// made two elements share an id, so a contents link or a label could point at the wrong one.
|
|
31
|
+
if (/^emvb-/i.test(value)) return "Ids starting with emvb- are reserved; choose another.";
|
|
29
32
|
if (otherHtmlIds(layout, nodeId).has(value)) return "Another element already uses this CSS id.";
|
|
30
33
|
return null;
|
|
31
34
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
isFormNode,
|
|
4
|
-
parentOf,
|
|
5
|
-
type Layout,
|
|
6
|
-
type LayoutNode,
|
|
7
|
-
} from "../../../../core/index.ts";
|
|
1
|
+
import { isFormNode, type Layout, type LayoutNode } from "../../../../core/index.ts";
|
|
2
|
+
import { indexLayout } from "../../../../core/tree-ops.ts";
|
|
8
3
|
|
|
9
4
|
const fieldOf = (node: LayoutNode): string => {
|
|
10
5
|
const value = (node.props as Record<string, unknown> | undefined)?.field;
|
|
@@ -16,12 +11,13 @@ const fieldOf = (node: LayoutNode): string => {
|
|
|
16
11
|
* one value would overwrite the other. Controls outside any form are not checked.
|
|
17
12
|
*/
|
|
18
13
|
export function duplicateFieldName(layout: Layout, nodeId: string): boolean {
|
|
19
|
-
const
|
|
14
|
+
const index = indexLayout(layout);
|
|
15
|
+
const self = index.byId.get(nodeId);
|
|
20
16
|
const name = self ? fieldOf(self) : "";
|
|
21
17
|
if (!name) return false;
|
|
22
|
-
let current = parentOf(
|
|
18
|
+
let current = index.parentOf.get(nodeId);
|
|
23
19
|
while (current) {
|
|
24
|
-
const form =
|
|
20
|
+
const form = index.byId.get(current);
|
|
25
21
|
if (form && isFormNode(form)) {
|
|
26
22
|
let count = 0;
|
|
27
23
|
const walk = (node: LayoutNode) => {
|
|
@@ -32,7 +28,7 @@ export function duplicateFieldName(layout: Layout, nodeId: string): boolean {
|
|
|
32
28
|
walk(form);
|
|
33
29
|
return count > 1;
|
|
34
30
|
}
|
|
35
|
-
current = parentOf(
|
|
31
|
+
current = index.parentOf.get(current);
|
|
36
32
|
}
|
|
37
33
|
return false;
|
|
38
34
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
|
|
2
2
|
|
|
3
|
-
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh";
|
|
3
|
+
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh" | "ch";
|
|
4
4
|
/** `x` is a unitless number, for Line height only (W-213). */
|
|
5
5
|
export type UnitChoice = LengthUnit | "auto" | "x";
|
|
6
6
|
export type LengthLiteral = { value: number; unit: LengthUnit };
|
|
7
7
|
|
|
8
|
-
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh"];
|
|
8
|
+
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh", "ch"];
|
|
9
9
|
const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
|
|
10
10
|
|
|
11
11
|
/** Units each length property offers in its unit menu (DESIGN.md § Inputs). */
|
|
@@ -38,13 +38,24 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
|
38
38
|
|
|
39
39
|
export const unitsFor = (key: StyleKey): readonly UnitChoice[] => UNITS[key] ?? BOX;
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/** Keys that take a negative number; margins since W-331. */
|
|
42
|
+
const NEGATIVE = new Set<StyleKey>([
|
|
43
|
+
"top",
|
|
44
|
+
"right",
|
|
45
|
+
"bottom",
|
|
46
|
+
"left",
|
|
47
|
+
"letterSpacing",
|
|
48
|
+
"marginTop",
|
|
49
|
+
"marginRight",
|
|
50
|
+
"marginBottom",
|
|
51
|
+
"marginLeft",
|
|
52
|
+
]);
|
|
42
53
|
|
|
43
54
|
export type ParsedLength =
|
|
44
55
|
| { ok: true; value: LengthLiteral | "auto" | number | undefined }
|
|
45
56
|
| { ok: false; message: string };
|
|
46
57
|
|
|
47
|
-
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh)?$/i;
|
|
58
|
+
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh|ch)?$/i;
|
|
48
59
|
/** A number with a unit EmVB doesn't take ("100dvh", "12pt"), or a comma decimal ("1,5") (W-262). */
|
|
49
60
|
const OTHER_UNIT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[a-z%]+$/i;
|
|
50
61
|
const COMMA_DECIMAL = /^[+-]?\d*,\d+\s*[a-z%]*$/i;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { sanitizeHref } from "../../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
const GENERIC = "Use a full URL such as https://example.com or a path such as /pricing.";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Why a typed link can't be used, or null when it can (W-429). The generic hint told people who
|
|
7
|
+
* had typed a full URL to type a full URL; the common causes get their own message.
|
|
8
|
+
*/
|
|
9
|
+
export function hrefError(value: string, message = GENERIC): string | null {
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
if (sanitizeHref(trimmed)) return null;
|
|
12
|
+
if (/^https?:\/\/\S*\s/i.test(trimmed)) {
|
|
13
|
+
return "Links can't contain spaces. Replace each space with %20.";
|
|
14
|
+
}
|
|
15
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed) && !/^(https?|mailto|tel):/i.test(trimmed)) {
|
|
16
|
+
return "Only web (https://), email (mailto:) and phone (tel:) links are allowed.";
|
|
17
|
+
}
|
|
18
|
+
return message;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-436: a typed number for a settings field, or NaN. "16px" in a "(px)" field is read as 16, as
|
|
3
|
+
* the label invites; "0x10", "1e3" and "Infinity", which Number() read, are not numbers here.
|
|
4
|
+
*/
|
|
5
|
+
export function fieldNumber(text: string, unit?: string): number {
|
|
6
|
+
let trimmed = text.trim();
|
|
7
|
+
if (unit && trimmed.toLowerCase().endsWith(unit.toLowerCase())) {
|
|
8
|
+
trimmed = trimmed.slice(0, -unit.length).trimEnd();
|
|
9
|
+
}
|
|
10
|
+
return /^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { StyleProps } from "../../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
/** Style keys a container-query style may set (W-398). */
|
|
4
|
+
export const QUERY_STYLE_KEYS: readonly string[] = Object.keys(StyleProps.shape).toSorted();
|
|
5
|
+
|
|
6
|
+
/** A stored style value as one line of text: `16px`, `auto`, `#112233`, `var(--name)` (W-398). */
|
|
7
|
+
export function formatStyleValue(value: unknown): string {
|
|
8
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
9
|
+
return String(value);
|
|
10
|
+
}
|
|
11
|
+
if (value && typeof value === "object") {
|
|
12
|
+
const record = value as Record<string, unknown>;
|
|
13
|
+
if (
|
|
14
|
+
Object.keys(record).length === 2 &&
|
|
15
|
+
typeof record["value"] === "number" &&
|
|
16
|
+
typeof record["unit"] === "string"
|
|
17
|
+
) {
|
|
18
|
+
return `${record["value"]}${record["unit"]}`;
|
|
19
|
+
}
|
|
20
|
+
if (typeof record["var"] === "string" && Object.keys(record).length === 1) {
|
|
21
|
+
return `var(--${record["var"]})`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Readings of `text` to try, most specific first. */
|
|
28
|
+
function candidates(text: string): unknown[] {
|
|
29
|
+
const out: unknown[] = [];
|
|
30
|
+
const length = /^(-?\d+(?:\.\d+)?)([a-z%]+)$/i.exec(text);
|
|
31
|
+
if (length) out.push({ value: Number(length[1]), unit: (length[2] as string).toLowerCase() });
|
|
32
|
+
const variable = /^var\(--([a-z0-9-]{1,40})\)$/.exec(text);
|
|
33
|
+
if (variable) out.push({ var: variable[1] });
|
|
34
|
+
if (/^-?\d+(?:\.\d+)?$/.test(text)) {
|
|
35
|
+
out.push(Number(text));
|
|
36
|
+
// W-404: a bare number on a length property means px, as in the Style tab.
|
|
37
|
+
out.push({ value: Number(text), unit: "px" });
|
|
38
|
+
}
|
|
39
|
+
// W-404: keywords are lowercase in the schema; AUTO or Row should still work.
|
|
40
|
+
if (/^[A-Za-z-]+$/.test(text) && text !== text.toLowerCase()) out.push(text.toLowerCase());
|
|
41
|
+
if (text === "true" || text === "false") out.push(text === "true");
|
|
42
|
+
if (text.startsWith("{") || text.startsWith("[")) {
|
|
43
|
+
try {
|
|
44
|
+
out.push(JSON.parse(text));
|
|
45
|
+
} catch {
|
|
46
|
+
// not JSON; the plain string reading below reports the error
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
out.push(text);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The value `key` would store for `text`, or why it can't (W-398). */
|
|
54
|
+
export function parseStyleValue(key: string, text: string): { value: unknown } | { error: string } {
|
|
55
|
+
const schema = (
|
|
56
|
+
StyleProps.shape as Record<string, { safeParse: (v: unknown) => { success: boolean } }>
|
|
57
|
+
)[key];
|
|
58
|
+
if (!schema) return { error: `${key} isn't a style property.` };
|
|
59
|
+
const trimmed = text.trim();
|
|
60
|
+
if (trimmed === "") return { error: "Enter a value." };
|
|
61
|
+
for (const candidate of candidates(trimmed)) {
|
|
62
|
+
if (candidate !== undefined && schema.safeParse(candidate).success) return { value: candidate };
|
|
63
|
+
}
|
|
64
|
+
return { error: `"${trimmed.slice(0, 40)}" isn't a value ${key} accepts.` };
|
|
65
|
+
}
|
|
@@ -148,7 +148,9 @@ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
|
|
|
148
148
|
"alignItems",
|
|
149
149
|
"gap",
|
|
150
150
|
"gridColumnSpan",
|
|
151
|
+
"gridColumnStart",
|
|
151
152
|
"gridRowSpan",
|
|
153
|
+
"gridRowStart",
|
|
152
154
|
],
|
|
153
155
|
spacing: [
|
|
154
156
|
"paddingTop",
|
|
@@ -228,7 +230,7 @@ const ONLY_FOR: Partial<Record<StyleKey, string[]>> = {
|
|
|
228
230
|
),
|
|
229
231
|
};
|
|
230
232
|
|
|
231
|
-
const SPANS: StyleKey[] = ["gridColumnSpan", "gridRowSpan"];
|
|
233
|
+
const SPANS: StyleKey[] = ["gridColumnSpan", "gridColumnStart", "gridRowSpan", "gridRowStart"];
|
|
232
234
|
|
|
233
235
|
/**
|
|
234
236
|
* Direction, wrap, justify, align and gap only where the element's own box is a flex or grid
|
|
@@ -323,7 +325,9 @@ export const STYLE_LABELS: Record<StyleKey, string> = {
|
|
|
323
325
|
alignItems: "Align",
|
|
324
326
|
gap: "Gap",
|
|
325
327
|
gridColumnSpan: "Column span",
|
|
328
|
+
gridColumnStart: "Column start",
|
|
326
329
|
gridRowSpan: "Row span",
|
|
330
|
+
gridRowStart: "Row start",
|
|
327
331
|
width: "Width",
|
|
328
332
|
minWidth: "Min width",
|
|
329
333
|
maxWidth: "Max width",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
patchClassDevices,
|
|
3
|
+
patchClassState,
|
|
4
|
+
patchClassStyle,
|
|
5
|
+
patchDeviceStyle,
|
|
6
|
+
patchStates,
|
|
7
|
+
type DesignSystem,
|
|
8
|
+
type DeviceStyles,
|
|
9
|
+
type LayoutNode,
|
|
10
|
+
type PopupDevice,
|
|
11
|
+
type StyleProps,
|
|
12
|
+
type StyleStateName,
|
|
13
|
+
type StyleStates,
|
|
14
|
+
} from "../../../core/index.ts";
|
|
15
|
+
import type { StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
16
|
+
|
|
17
|
+
export type StyleSlot =
|
|
18
|
+
| { owner: "element" | "class"; slot: "style" }
|
|
19
|
+
| { owner: "element" | "class"; slot: "state"; state: StyleStateName }
|
|
20
|
+
| { owner: "element" | "class"; slot: "device"; device: "tablet" | "mobile" };
|
|
21
|
+
|
|
22
|
+
/** Which style object a patch writes: the element's own, a class, a state, or a device. */
|
|
23
|
+
export function styleTarget({
|
|
24
|
+
classId,
|
|
25
|
+
device,
|
|
26
|
+
state,
|
|
27
|
+
}: {
|
|
28
|
+
classId: string | null;
|
|
29
|
+
device: PopupDevice;
|
|
30
|
+
state: StyleStateChoice;
|
|
31
|
+
}): StyleSlot {
|
|
32
|
+
const owner = classId ? "class" : "element";
|
|
33
|
+
if (device !== "desktop") return { owner, slot: "device", device };
|
|
34
|
+
if (state === "normal") return { owner, slot: "style" };
|
|
35
|
+
return { owner, slot: "state", state };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const withStyle = (node: LayoutNode, patch: Partial<StyleProps>): LayoutNode => {
|
|
39
|
+
const style: Record<string, unknown> = { ...node.style, ...patch };
|
|
40
|
+
for (const key of Object.keys(style)) if (style[key] === undefined) delete style[key];
|
|
41
|
+
return {
|
|
42
|
+
...node,
|
|
43
|
+
style: Object.keys(style).length > 0 ? (style as StyleProps) : undefined,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const withDevices = (node: LayoutNode, devices: DeviceStyles | undefined): LayoutNode => {
|
|
48
|
+
const { devices: _old, ...rest } = node;
|
|
49
|
+
return (devices ? { ...rest, devices } : rest) as LayoutNode;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNode => {
|
|
53
|
+
const { states: _old, ...rest } = node;
|
|
54
|
+
return (states ? { ...rest, states } : rest) as LayoutNode;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type StyleWrite =
|
|
58
|
+
| { kind: "node"; node: LayoutNode }
|
|
59
|
+
| { kind: "design"; design: DesignSystem };
|
|
60
|
+
|
|
61
|
+
/** Apply a style patch to the slot `styleTarget` names. */
|
|
62
|
+
export function applyStylePatch({
|
|
63
|
+
node,
|
|
64
|
+
design,
|
|
65
|
+
classId,
|
|
66
|
+
device,
|
|
67
|
+
state,
|
|
68
|
+
patch,
|
|
69
|
+
}: {
|
|
70
|
+
node: LayoutNode;
|
|
71
|
+
design: DesignSystem;
|
|
72
|
+
classId: string | null;
|
|
73
|
+
device: PopupDevice;
|
|
74
|
+
state: StyleStateChoice;
|
|
75
|
+
patch: Partial<StyleProps>;
|
|
76
|
+
}): StyleWrite {
|
|
77
|
+
const target = styleTarget({ classId, device, state });
|
|
78
|
+
if (target.slot === "device") {
|
|
79
|
+
if (!classId) {
|
|
80
|
+
return {
|
|
81
|
+
kind: "node",
|
|
82
|
+
node: withDevices(node, patchDeviceStyle(node.devices, target.device, patch)),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
kind: "design",
|
|
87
|
+
design: patchClassDevices(design, classId, target.device, patch),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (!classId) {
|
|
91
|
+
return {
|
|
92
|
+
kind: "node",
|
|
93
|
+
node:
|
|
94
|
+
state === "normal"
|
|
95
|
+
? withStyle(node, patch)
|
|
96
|
+
: withStates(node, patchStates(node.states, state, patch)),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const cls = { id: classId };
|
|
100
|
+
const next =
|
|
101
|
+
state === "normal"
|
|
102
|
+
? patchClassStyle(design, cls.id, patch)
|
|
103
|
+
: patchClassState(design, cls.id, state, patch);
|
|
104
|
+
return { kind: "design", design: next };
|
|
105
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { VariableKind } from "../../../core/index.ts";
|
|
2
|
+
import { hexInput } from "./color-space.ts";
|
|
2
3
|
|
|
3
4
|
export type Length = { value: number; unit: "px" | "rem" | "em" | "%" };
|
|
4
5
|
|
|
5
|
-
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
6
6
|
const LENGTH = /^(\d+(?:\.\d+)?|\.\d+)\s*(px|rem|em|%)?$/i;
|
|
7
7
|
const MAX_LENGTH = 10_000;
|
|
8
8
|
|
|
@@ -54,7 +54,9 @@ export function parseValue(
|
|
|
54
54
|
return length ? { ok: true, value: length } : { ok: false, error: ERRORS[kind] };
|
|
55
55
|
}
|
|
56
56
|
if (kind === "color") {
|
|
57
|
-
|
|
57
|
+
// W-434: "1a2b3c" without "#", as design tools copy it, is accepted.
|
|
58
|
+
const hex = hexInput(trimmed);
|
|
59
|
+
return hex ? { ok: true, value: hex } : { ok: false, error: ERRORS.color };
|
|
58
60
|
}
|
|
59
61
|
return trimmed && trimmed.length <= 200
|
|
60
62
|
? { ok: true, value: trimmed }
|