@perkyzz/emvb 0.8.0 → 1.0.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 +3 -3
- package/package.json +4 -4
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +325 -239
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +36 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/host.ts +6 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +53 -15
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +55 -2
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/index.tsx +5 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +11 -28
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/ui.ts +39 -2
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/content-port.ts +14 -1
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/resolve-theme.ts +58 -3
- package/src/astro/resolve.ts +128 -5
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +19 -4
- package/src/core/elements/index.ts +73 -9
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +949 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +84 -0
- package/src/core/json-schema.ts +107 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +5 -5
- package/src/core/portable-text.ts +127 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +2 -1
- package/src/core/schema/layout.ts +87 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/pagination.ts +9 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +35 -1
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +21 -2
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +53 -5
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { Button, Checkbox, Input } from "@cloudflare/kumo";
|
|
2
|
+
import { LinkSimpleIcon, TextBIcon, TextItalicIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
hasFormat,
|
|
6
|
+
type LayoutNode,
|
|
7
|
+
MAX_TEXT_MARKS,
|
|
8
|
+
type MarkFormat,
|
|
9
|
+
sanitizeHref,
|
|
10
|
+
setFormat,
|
|
11
|
+
type TextMark,
|
|
12
|
+
unsetFormat,
|
|
13
|
+
} from "../../../../core/index.ts";
|
|
14
|
+
import { BUTTON, FIELD } from "../../../ui.ts";
|
|
15
|
+
import { propsOf, withProp } from "./node-props.ts";
|
|
16
|
+
|
|
17
|
+
type Range = { start: number; end: number };
|
|
18
|
+
|
|
19
|
+
/** The element's Text field, next to this control in the panel. */
|
|
20
|
+
function textField(from: HTMLElement | null): HTMLInputElement | HTMLTextAreaElement | null {
|
|
21
|
+
const scope =
|
|
22
|
+
from?.closest("[data-emvb-fields]") ?? from?.parentElement?.parentElement ?? document;
|
|
23
|
+
const holder = scope.querySelector('[data-emvb-field="text"]');
|
|
24
|
+
if (holder instanceof HTMLInputElement || holder instanceof HTMLTextAreaElement) return holder;
|
|
25
|
+
return holder?.querySelector("textarea, input") ?? null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Buttons keep the Text field's selection: pressing one doesn't move focus there first. */
|
|
29
|
+
const keep = (event: React.MouseEvent) => event.preventDefault();
|
|
30
|
+
|
|
31
|
+
const describe = (mark: TextMark): string =>
|
|
32
|
+
[
|
|
33
|
+
mark.bold ? "Bold" : null,
|
|
34
|
+
mark.italic ? "Italic" : null,
|
|
35
|
+
typeof mark.color === "string" ? `Color ${mark.color}` : mark.color ? "Color" : null,
|
|
36
|
+
mark.href ? `Link ${mark.href}${mark.newTab ? " (new tab)" : ""}` : null,
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join(", ");
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Formatting (W-950): bold, italic, colour and links on the words selected in the Text field.
|
|
43
|
+
* The text stays plain; each format is a range over it, listed below with a Remove button.
|
|
44
|
+
*/
|
|
45
|
+
export function TextMarksControl({
|
|
46
|
+
node,
|
|
47
|
+
onChange,
|
|
48
|
+
}: {
|
|
49
|
+
node: LayoutNode;
|
|
50
|
+
onChange: (node: LayoutNode) => void;
|
|
51
|
+
}) {
|
|
52
|
+
const props = propsOf(node);
|
|
53
|
+
const text = typeof props["text"] === "string" ? props["text"] : "";
|
|
54
|
+
const marks = Array.isArray(props["marks"]) ? (props["marks"] as TextMark[]) : [];
|
|
55
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
56
|
+
const colorRef = React.useRef<HTMLInputElement>(null);
|
|
57
|
+
const [message, setMessage] = React.useState<string>();
|
|
58
|
+
const [linkFor, setLinkFor] = React.useState<Range>();
|
|
59
|
+
const [href, setHref] = React.useState("");
|
|
60
|
+
const [newTab, setNewTab] = React.useState(false);
|
|
61
|
+
const linkedHeading = node.type === "heading" && typeof props["href"] === "string";
|
|
62
|
+
|
|
63
|
+
/** The selected words, or a message saying why there are none. */
|
|
64
|
+
const selection = (): Range | undefined => {
|
|
65
|
+
const field = textField(ref.current);
|
|
66
|
+
if (!field) return undefined;
|
|
67
|
+
if (field.value !== text) {
|
|
68
|
+
setMessage("Finish editing the text first (press Enter or leave the field).");
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const start = field.selectionStart ?? 0;
|
|
72
|
+
const end = field.selectionEnd ?? 0;
|
|
73
|
+
if (end <= start) {
|
|
74
|
+
setMessage("Select some words in the Text field first.");
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
setMessage(undefined);
|
|
78
|
+
return { start, end };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const save = (next: TextMark[]) => {
|
|
82
|
+
if (next.length > MAX_TEXT_MARKS) {
|
|
83
|
+
setMessage(`A text can have up to ${MAX_TEXT_MARKS} formatted parts.`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
onChange(withProp(node, "marks", next.length > 0 ? next : undefined));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const toggle = (format: Extract<MarkFormat, "bold" | "italic">) => {
|
|
90
|
+
const range = selection();
|
|
91
|
+
if (!range) return;
|
|
92
|
+
save(
|
|
93
|
+
hasFormat(marks, range.start, range.end, format)
|
|
94
|
+
? unsetFormat(marks, range.start, range.end, format)
|
|
95
|
+
: setFormat(marks, range.start, range.end, { [format]: true }),
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// A colour is applied when the picker closes, not on every step of a drag.
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
const input = colorRef.current;
|
|
102
|
+
if (!input) return;
|
|
103
|
+
const apply = () => {
|
|
104
|
+
const range = selection();
|
|
105
|
+
if (range) save(setFormat(marks, range.start, range.end, { color: input.value }));
|
|
106
|
+
};
|
|
107
|
+
input.addEventListener("change", apply);
|
|
108
|
+
return () => input.removeEventListener("change", apply);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const applyLink = () => {
|
|
112
|
+
if (!linkFor) return;
|
|
113
|
+
const safe = sanitizeHref(href.trim());
|
|
114
|
+
if (!safe) {
|
|
115
|
+
setMessage("Enter a link such as /contact or https://example.com.");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
save(
|
|
119
|
+
setFormat(marks, linkFor.start, linkFor.end, {
|
|
120
|
+
href: safe,
|
|
121
|
+
...(newTab ? { newTab: true } : {}),
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
setLinkFor(undefined);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const clear = () => {
|
|
128
|
+
const range = selection();
|
|
129
|
+
if (!range) return;
|
|
130
|
+
let next = marks;
|
|
131
|
+
for (const format of ["bold", "italic", "color", "href"] as const)
|
|
132
|
+
next = unsetFormat(next, range.start, range.end, format);
|
|
133
|
+
save(next);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div ref={ref} className="emvb-marks" data-emvb-field="marks">
|
|
138
|
+
<span className="emvb-import-label">Formatting</span>
|
|
139
|
+
<div className="emvb-marks-bar" role="toolbar" aria-label="Formatting">
|
|
140
|
+
<Button
|
|
141
|
+
type="button"
|
|
142
|
+
variant="secondary"
|
|
143
|
+
className={BUTTON}
|
|
144
|
+
aria-label="Bold"
|
|
145
|
+
icon={<TextBIcon aria-hidden="true" />}
|
|
146
|
+
onMouseDown={keep}
|
|
147
|
+
onClick={() => toggle("bold")}
|
|
148
|
+
/>
|
|
149
|
+
<Button
|
|
150
|
+
type="button"
|
|
151
|
+
variant="secondary"
|
|
152
|
+
className={BUTTON}
|
|
153
|
+
aria-label="Italic"
|
|
154
|
+
icon={<TextItalicIcon aria-hidden="true" />}
|
|
155
|
+
onMouseDown={keep}
|
|
156
|
+
onClick={() => toggle("italic")}
|
|
157
|
+
/>
|
|
158
|
+
<label className="emvb-marks-color">
|
|
159
|
+
<span className="emvb-helper">Color</span>
|
|
160
|
+
<input
|
|
161
|
+
ref={colorRef}
|
|
162
|
+
type="color"
|
|
163
|
+
aria-label="Color of selected words"
|
|
164
|
+
defaultValue="#000000"
|
|
165
|
+
/>
|
|
166
|
+
</label>
|
|
167
|
+
{!linkedHeading && (
|
|
168
|
+
<Button
|
|
169
|
+
type="button"
|
|
170
|
+
variant="secondary"
|
|
171
|
+
className={BUTTON}
|
|
172
|
+
aria-label="Link selected words"
|
|
173
|
+
icon={<LinkSimpleIcon aria-hidden="true" />}
|
|
174
|
+
onMouseDown={keep}
|
|
175
|
+
onClick={() => {
|
|
176
|
+
const range = selection();
|
|
177
|
+
if (!range) return;
|
|
178
|
+
setLinkFor(range);
|
|
179
|
+
setHref("");
|
|
180
|
+
setNewTab(false);
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
<Button
|
|
185
|
+
type="button"
|
|
186
|
+
variant="secondary"
|
|
187
|
+
className={BUTTON}
|
|
188
|
+
onMouseDown={keep}
|
|
189
|
+
onClick={clear}
|
|
190
|
+
>
|
|
191
|
+
Clear
|
|
192
|
+
</Button>
|
|
193
|
+
</div>
|
|
194
|
+
{linkFor && (
|
|
195
|
+
<div className="emvb-marks-link" data-emvb-marks-link="">
|
|
196
|
+
<Input
|
|
197
|
+
label={`Link for "${text.slice(linkFor.start, linkFor.end)}"`}
|
|
198
|
+
className={FIELD}
|
|
199
|
+
value={href}
|
|
200
|
+
placeholder="/contact"
|
|
201
|
+
onChange={(event) => setHref(event.target.value)}
|
|
202
|
+
/>
|
|
203
|
+
<Checkbox
|
|
204
|
+
label="Open in a new tab"
|
|
205
|
+
checked={newTab}
|
|
206
|
+
onCheckedChange={(checked: boolean) => setNewTab(checked)}
|
|
207
|
+
/>
|
|
208
|
+
<div className="emvb-marks-bar">
|
|
209
|
+
<Button type="button" variant="primary" className={BUTTON} onClick={applyLink}>
|
|
210
|
+
Apply link
|
|
211
|
+
</Button>
|
|
212
|
+
<Button
|
|
213
|
+
type="button"
|
|
214
|
+
variant="secondary"
|
|
215
|
+
className={BUTTON}
|
|
216
|
+
onClick={() => setLinkFor(undefined)}
|
|
217
|
+
>
|
|
218
|
+
Cancel
|
|
219
|
+
</Button>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
)}
|
|
223
|
+
<p className="emvb-helper" role="status">
|
|
224
|
+
{message ?? "Select words in the Text field, then choose a format."}
|
|
225
|
+
</p>
|
|
226
|
+
{marks.length > 0 && (
|
|
227
|
+
<ul className="emvb-marks-list" aria-label="Formatted words">
|
|
228
|
+
{marks.map((mark, index) => (
|
|
229
|
+
<li key={`${mark.start}-${mark.end}-${index}`}>
|
|
230
|
+
<span>
|
|
231
|
+
<strong>“{text.slice(mark.start, mark.end) || "…"}”</strong> {describe(mark)}
|
|
232
|
+
</span>
|
|
233
|
+
<Button
|
|
234
|
+
type="button"
|
|
235
|
+
variant="ghost"
|
|
236
|
+
className={BUTTON}
|
|
237
|
+
aria-label={`Remove formatting from "${text.slice(mark.start, mark.end)}"`}
|
|
238
|
+
icon={<XIcon aria-hidden="true" />}
|
|
239
|
+
onClick={() => save(marks.filter((_, i) => i !== index))}
|
|
240
|
+
/>
|
|
241
|
+
</li>
|
|
242
|
+
))}
|
|
243
|
+
</ul>
|
|
244
|
+
)}
|
|
245
|
+
</div>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DropdownMenu } from "@cloudflare/kumo";
|
|
2
2
|
import { BracketsCurlyIcon, RulerIcon, TextAaIcon, TextTIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
-
import type { DesignSystem,
|
|
3
|
+
import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
|
|
4
4
|
import type { StyleKey } from "./style-sections.ts";
|
|
5
5
|
|
|
6
6
|
/** Variable kinds a length or font property can bind to. Colours bind through ColorControl. */
|
|
@@ -77,7 +77,7 @@ export function VariableButton({
|
|
|
77
77
|
kind: BindKind;
|
|
78
78
|
design: DesignSystem;
|
|
79
79
|
current: string | null;
|
|
80
|
-
onBind: (ref: NonNullable<
|
|
80
|
+
onBind: (ref: NonNullable<FlatStyleProps["gap"]>) => void;
|
|
81
81
|
}) {
|
|
82
82
|
const list = variablesOf(design, kind);
|
|
83
83
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FlatStyleProps } from "../../../../core/index.ts";
|
|
2
2
|
import { STYLE_UI } from "./style-sections.ts";
|
|
3
3
|
import { NEW_GRADIENT } from "./BackgroundControls.tsx";
|
|
4
4
|
|
|
@@ -11,14 +11,14 @@ const BOXES = new Set([
|
|
|
11
11
|
"div-block",
|
|
12
12
|
"layout-section",
|
|
13
13
|
"form",
|
|
14
|
-
"
|
|
14
|
+
"part-ref",
|
|
15
15
|
"tab-panel",
|
|
16
16
|
"accordion",
|
|
17
17
|
"accordion-item",
|
|
18
18
|
]);
|
|
19
19
|
|
|
20
20
|
/** Color and gradient everywhere. Image and video on boxes, or when already set. */
|
|
21
|
-
export function fillModes(type: string, style?:
|
|
21
|
+
export function fillModes(type: string, style?: FlatStyleProps): FillMode[] {
|
|
22
22
|
const modes: FillMode[] = ["color", "gradient"];
|
|
23
23
|
const box = BOXES.has(type) || !(type in STYLE_UI);
|
|
24
24
|
if (box || type === "button" || type === "submit" || style?.backgroundImage !== undefined)
|
|
@@ -28,7 +28,7 @@ export function fillModes(type: string, style?: StyleProps): FillMode[] {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** The fill the page is showing. Video wins, then image, then gradient, then a solid color. */
|
|
31
|
-
export function activeFill(style:
|
|
31
|
+
export function activeFill(style: FlatStyleProps | undefined): FillMode {
|
|
32
32
|
if (style?.backgroundVideo) return "video";
|
|
33
33
|
if (style?.backgroundImage) return "image";
|
|
34
34
|
if (style?.gradient) return "gradient";
|
|
@@ -36,7 +36,7 @@ export function activeFill(style: StyleProps | undefined): FillMode {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** More than one fill is stored, so the page paints a stack the type switcher will collapse. */
|
|
39
|
-
export function fillIsMixed(style:
|
|
39
|
+
export function fillIsMixed(style: FlatStyleProps | undefined): boolean {
|
|
40
40
|
return (
|
|
41
41
|
[
|
|
42
42
|
style?.backgroundColor !== undefined,
|
|
@@ -59,7 +59,7 @@ const CLEARED = {
|
|
|
59
59
|
} as const;
|
|
60
60
|
|
|
61
61
|
/** Choosing a type removes the other fills. Overlay stays with an image or a video. */
|
|
62
|
-
function switchFill(style:
|
|
62
|
+
function switchFill(style: FlatStyleProps | undefined, mode: FillMode): Partial<FlatStyleProps> {
|
|
63
63
|
if (mode === "gradient") return { ...CLEARED, gradient: style?.gradient ?? NEW_GRADIENT };
|
|
64
64
|
if (mode === "image") {
|
|
65
65
|
return {
|
|
@@ -78,7 +78,10 @@ function switchFill(style: StyleProps | undefined, mode: FillMode): Partial<Styl
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** The fields a fill type owns as stored now, or undefined when that type has nothing set. */
|
|
81
|
-
function heldFill(
|
|
81
|
+
function heldFill(
|
|
82
|
+
style: FlatStyleProps | undefined,
|
|
83
|
+
mode: FillMode,
|
|
84
|
+
): Partial<FlatStyleProps> | undefined {
|
|
82
85
|
const main = {
|
|
83
86
|
color: style?.backgroundColor,
|
|
84
87
|
gradient: style?.gradient,
|
|
@@ -88,22 +91,22 @@ function heldFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleP
|
|
|
88
91
|
if (main === undefined) return undefined;
|
|
89
92
|
return Object.fromEntries(
|
|
90
93
|
Object.entries(switchFill(style, mode)).filter(([, value]) => value !== undefined),
|
|
91
|
-
) as Partial<
|
|
94
|
+
) as Partial<FlatStyleProps>;
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
/** What each fill type last held while this element was being edited (W-184). */
|
|
95
|
-
export type FillMemory = Partial<Record<FillMode, Partial<
|
|
98
|
+
export type FillMemory = Partial<Record<FillMode, Partial<FlatStyleProps>>>;
|
|
96
99
|
|
|
97
100
|
/**
|
|
98
101
|
* Like `switchFill`, but the type being left is remembered in `memory`, and an empty type being
|
|
99
102
|
* chosen gets back what it last held, so Gradient → Color → Gradient keeps the gradient (W-184).
|
|
100
103
|
*/
|
|
101
104
|
export function switchFillRemembered(
|
|
102
|
-
style:
|
|
105
|
+
style: FlatStyleProps | undefined,
|
|
103
106
|
from: FillMode,
|
|
104
107
|
to: FillMode,
|
|
105
108
|
memory: FillMemory,
|
|
106
|
-
): Partial<
|
|
109
|
+
): Partial<FlatStyleProps> {
|
|
107
110
|
const held = heldFill(style, from);
|
|
108
111
|
if (held) memory[from] = held;
|
|
109
112
|
const remembered = memory[to];
|
|
@@ -5,7 +5,7 @@ import { nodeChildren } from "../../../../core/tree-ops.ts";
|
|
|
5
5
|
const TEXT_PROPS = ["text", "label", "summary", "title", "alt"] as const;
|
|
6
6
|
|
|
7
7
|
/** Elements whose text comes from the post or another layout; assume they name the link. */
|
|
8
|
-
const DYNAMIC = new Set(["
|
|
8
|
+
const DYNAMIC = new Set(["part-ref", "loop"]);
|
|
9
9
|
|
|
10
10
|
const hasName = (node: LayoutNode): boolean => {
|
|
11
11
|
if (DYNAMIC.has(node.type) || node.type.startsWith("post-")) return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
1
|
+
import type { FlatStyleProps } from "../../../../core/index.ts";
|
|
2
|
+
import { fluidDraft, isFluid, type LengthUnit } from "./length-units.ts";
|
|
3
3
|
import type { StyleKey } from "./style-sections.ts";
|
|
4
4
|
|
|
5
5
|
type Four<T> = readonly [T, T, T, T];
|
|
@@ -73,7 +73,7 @@ const groupKeys = (group: BoxGroup): StyleKey[] => [
|
|
|
73
73
|
];
|
|
74
74
|
|
|
75
75
|
/** What each box shows: its own value, else the all-sides value. */
|
|
76
|
-
export function sideValues(group: BoxGroup, style:
|
|
76
|
+
export function sideValues(group: BoxGroup, style: FlatStyleProps | undefined): unknown[] {
|
|
77
77
|
const all = group.all ? style?.[group.all] : undefined;
|
|
78
78
|
return group.sides.map((key) => style?.[key] ?? all);
|
|
79
79
|
}
|
|
@@ -84,11 +84,11 @@ const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
|
|
|
84
84
|
export const allSame = (values: readonly unknown[]) => values.every((v) => same(v, values[0]));
|
|
85
85
|
|
|
86
86
|
/** True when the edited target sets any of the control's keys. */
|
|
87
|
-
export const groupSet = (group: BoxGroup, style:
|
|
87
|
+
export const groupSet = (group: BoxGroup, style: FlatStyleProps | undefined) =>
|
|
88
88
|
groupKeys(group).some((key) => style?.[key] !== undefined);
|
|
89
89
|
|
|
90
90
|
/** One value on every box. Border width and radius use their all-sides key and drop the sides. */
|
|
91
|
-
export function linkedPatch(group: BoxGroup, value: unknown): Partial<
|
|
91
|
+
export function linkedPatch(group: BoxGroup, value: unknown): Partial<FlatStyleProps> {
|
|
92
92
|
const patch: Record<string, unknown> = {};
|
|
93
93
|
if (group.all) {
|
|
94
94
|
patch[group.all] = value;
|
|
@@ -96,15 +96,22 @@ export function linkedPatch(group: BoxGroup, value: unknown): Partial<StyleProps
|
|
|
96
96
|
} else {
|
|
97
97
|
for (const key of group.sides) patch[key] = value;
|
|
98
98
|
}
|
|
99
|
-
return patch as Partial<
|
|
99
|
+
return patch as Partial<FlatStyleProps>;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/** One box's value. */
|
|
103
|
-
export const sidePatch = (
|
|
104
|
-
|
|
103
|
+
export const sidePatch = (
|
|
104
|
+
group: BoxGroup,
|
|
105
|
+
index: number,
|
|
106
|
+
value: unknown,
|
|
107
|
+
): Partial<FlatStyleProps> =>
|
|
108
|
+
({ [group.sides[index] as StyleKey]: value }) as Partial<FlatStyleProps>;
|
|
105
109
|
|
|
106
110
|
/** Linking copies the first box that has a value to all four. */
|
|
107
|
-
export function linkPatch(
|
|
111
|
+
export function linkPatch(
|
|
112
|
+
group: BoxGroup,
|
|
113
|
+
style: FlatStyleProps | undefined,
|
|
114
|
+
): Partial<FlatStyleProps> {
|
|
108
115
|
return linkedPatch(
|
|
109
116
|
group,
|
|
110
117
|
sideValues(group, style).find((value) => value !== undefined),
|
|
@@ -112,10 +119,10 @@ export function linkPatch(group: BoxGroup, style: StyleProps | undefined): Parti
|
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
/** Clears every key of the control. */
|
|
115
|
-
export function resetPatch(group: BoxGroup): Partial<
|
|
122
|
+
export function resetPatch(group: BoxGroup): Partial<FlatStyleProps> {
|
|
116
123
|
const patch: Record<string, unknown> = {};
|
|
117
124
|
for (const key of groupKeys(group)) patch[key] = undefined;
|
|
118
|
-
return patch as Partial<
|
|
125
|
+
return patch as Partial<FlatStyleProps>;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
const isLiteral = (value: unknown): value is { value: number; unit: LengthUnit } =>
|
|
@@ -127,15 +134,15 @@ const isLiteral = (value: unknown): value is { value: number; unit: LengthUnit }
|
|
|
127
134
|
/** The shared unit menu: every number the control sets keeps its value in the new unit. */
|
|
128
135
|
export function unitPatch(
|
|
129
136
|
group: BoxGroup,
|
|
130
|
-
style:
|
|
137
|
+
style: FlatStyleProps | undefined,
|
|
131
138
|
unit: LengthUnit,
|
|
132
|
-
): Partial<
|
|
139
|
+
): Partial<FlatStyleProps> {
|
|
133
140
|
const patch: Record<string, unknown> = {};
|
|
134
141
|
for (const key of groupKeys(group)) {
|
|
135
142
|
const value = style?.[key];
|
|
136
143
|
if (isLiteral(value) && value.unit !== unit) patch[key] = { value: value.value, unit };
|
|
137
144
|
}
|
|
138
|
-
return patch as Partial<
|
|
145
|
+
return patch as Partial<FlatStyleProps>;
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
/** The unit the shared menu shows: the first box with a number, else `fallback`. */
|
|
@@ -148,6 +155,7 @@ export function sideDraft(value: unknown, unit: LengthUnit, varName?: string): s
|
|
|
148
155
|
if (isLiteral(value))
|
|
149
156
|
return value.unit === unit ? String(value.value) : `${value.value}${value.unit}`;
|
|
150
157
|
if (value === "auto") return "auto";
|
|
158
|
+
if (isFluid(value)) return fluidDraft(value);
|
|
151
159
|
if (typeof value === "object" && value !== null && "var" in value) return varName ?? "";
|
|
152
160
|
return "";
|
|
153
161
|
}
|
|
@@ -11,13 +11,17 @@ const SHARED_PARTS: ReadonlySet<ThemePartType> = new Set([
|
|
|
11
11
|
"loop_item",
|
|
12
12
|
]);
|
|
13
13
|
|
|
14
|
+
/** True for a part that lands on pages with their own H1, so a new Heading stays H2 (W-946). */
|
|
15
|
+
export const isSharedPart = (partType: ThemePartType | undefined): boolean =>
|
|
16
|
+
partType !== undefined && SHARED_PARTS.has(partType);
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* W-208: true for an H1 (a Heading, or a Post title, at level 1) in a header, footer, popup, float,
|
|
16
20
|
* synced section or loop item. The page it lands on then has two H1s (or one per post), which
|
|
17
21
|
* confuses screen readers and search engines.
|
|
18
22
|
*/
|
|
19
23
|
export function sharedPartH1(node: LayoutNode, partType: ThemePartType | undefined): boolean {
|
|
20
|
-
if (!
|
|
24
|
+
if (!isSharedPart(partType)) return false;
|
|
21
25
|
const level = (node.props as { level?: number } | undefined)?.level;
|
|
22
26
|
if (node.type === "heading") return level === 1;
|
|
23
27
|
if (node.type === "post-title") return (level ?? 1) === 1;
|
|
@@ -12,6 +12,7 @@ const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
|
|
|
12
12
|
const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
13
13
|
width: BOX_AUTO,
|
|
14
14
|
height: BOX_AUTO,
|
|
15
|
+
flexBasis: BOX_AUTO,
|
|
15
16
|
marginTop: BOX_AUTO,
|
|
16
17
|
marginRight: BOX_AUTO,
|
|
17
18
|
marginBottom: BOX_AUTO,
|
|
@@ -20,10 +21,12 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
|
20
21
|
right: BOX_AUTO,
|
|
21
22
|
bottom: BOX_AUTO,
|
|
22
23
|
left: BOX_AUTO,
|
|
23
|
-
|
|
24
|
+
// vh since W-910, for hero headings sized to the screen height.
|
|
25
|
+
fontSize: ["px", "rem", "em", "%", "vw", "vh"],
|
|
24
26
|
// em first, so a typed 1.5 means 1.5 times the font size, not 1.5 px (W-125).
|
|
25
27
|
lineHeight: ["em", "px", "rem", "%", "x"],
|
|
26
28
|
letterSpacing: ["px", "rem", "em"],
|
|
29
|
+
markerSize: ["em", "px", "rem", "%"],
|
|
27
30
|
borderWidth: ["px", "rem", "em"],
|
|
28
31
|
borderTopWidth: ["px", "rem", "em"],
|
|
29
32
|
borderRightWidth: ["px", "rem", "em"],
|
|
@@ -51,8 +54,46 @@ const NEGATIVE = new Set<StyleKey>([
|
|
|
51
54
|
"marginLeft",
|
|
52
55
|
]);
|
|
53
56
|
|
|
57
|
+
/** W-955: a fluid size, px on small screens to px on large ones. */
|
|
58
|
+
export type FluidLiteral = { fluid: { min: number; max: number } };
|
|
59
|
+
|
|
60
|
+
/** Keys that take a fluid size ("32–56"): type, gap, sizes, padding and margins (W-955). */
|
|
61
|
+
const FLUID = new Set<StyleKey>([
|
|
62
|
+
"fontSize",
|
|
63
|
+
"gap",
|
|
64
|
+
"width",
|
|
65
|
+
"minWidth",
|
|
66
|
+
"maxWidth",
|
|
67
|
+
"height",
|
|
68
|
+
"minHeight",
|
|
69
|
+
"maxHeight",
|
|
70
|
+
"paddingTop",
|
|
71
|
+
"paddingRight",
|
|
72
|
+
"paddingBottom",
|
|
73
|
+
"paddingLeft",
|
|
74
|
+
"marginTop",
|
|
75
|
+
"marginRight",
|
|
76
|
+
"marginBottom",
|
|
77
|
+
"marginLeft",
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
export const takesFluid = (key: StyleKey) => FLUID.has(key);
|
|
81
|
+
|
|
82
|
+
export const isFluid = (value: unknown): value is FluidLiteral =>
|
|
83
|
+
typeof value === "object" &&
|
|
84
|
+
value !== null &&
|
|
85
|
+
"fluid" in value &&
|
|
86
|
+
typeof (value as FluidLiteral).fluid?.min === "number" &&
|
|
87
|
+
typeof (value as FluidLiteral).fluid?.max === "number";
|
|
88
|
+
|
|
89
|
+
/** How a fluid size reads in a length field: "32–56" (px). */
|
|
90
|
+
export const fluidDraft = (value: FluidLiteral) => `${value.fluid.min}–${value.fluid.max}`;
|
|
91
|
+
|
|
92
|
+
/** "32–56", "32-56px", "32 to 56": small-screen and large-screen px. */
|
|
93
|
+
const FLUID_DRAFT = /^(\d+(?:\.\d+)?)\s*(?:px)?\s*(?:–|—|-|to|→)\s*(\d+(?:\.\d+)?)\s*(?:px)?$/i;
|
|
94
|
+
|
|
54
95
|
export type ParsedLength =
|
|
55
|
-
| { ok: true; value: LengthLiteral | "auto" | number | undefined }
|
|
96
|
+
| { ok: true; value: LengthLiteral | FluidLiteral | "auto" | number | undefined }
|
|
56
97
|
| { ok: false; message: string };
|
|
57
98
|
|
|
58
99
|
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh|ch)?$/i;
|
|
@@ -81,6 +122,18 @@ export function parseLengthDraft(
|
|
|
81
122
|
? { ok: true, value: "auto" }
|
|
82
123
|
: { ok: false, message: `${label} can't be auto. Enter a number.` };
|
|
83
124
|
}
|
|
125
|
+
const range = FLUID_DRAFT.exec(text);
|
|
126
|
+
if (range) {
|
|
127
|
+
if (!FLUID.has(key)) {
|
|
128
|
+
return { ok: false, message: `${label} takes one number, not a range.` };
|
|
129
|
+
}
|
|
130
|
+
const min = Number(range[1]);
|
|
131
|
+
const max = Number(range[2]);
|
|
132
|
+
if (min > 10_000 || max > 10_000) {
|
|
133
|
+
return { ok: false, message: `${label} can be up to 10000. Enter a smaller number.` };
|
|
134
|
+
}
|
|
135
|
+
return { ok: true, value: { fluid: { min, max } } };
|
|
136
|
+
}
|
|
84
137
|
const match = DRAFT.exec(text);
|
|
85
138
|
const n = match ? Number(match[1]) : Number.NaN;
|
|
86
139
|
if (!match || !Number.isFinite(n)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatStyleProps } from "../../../../core/index.ts";
|
|
2
2
|
|
|
3
3
|
/** Style keys a container-query style may set (W-398). */
|
|
4
|
-
export const QUERY_STYLE_KEYS: readonly string[] = Object.keys(
|
|
4
|
+
export const QUERY_STYLE_KEYS: readonly string[] = Object.keys(FlatStyleProps.shape).toSorted();
|
|
5
5
|
|
|
6
6
|
/** A stored style value as one line of text: `16px`, `auto`, `#112233`, `var(--name)` (W-398). */
|
|
7
7
|
export function formatStyleValue(value: unknown): string {
|
|
@@ -77,7 +77,7 @@ function candidates(text: string, key: string): unknown[] {
|
|
|
77
77
|
/** The value `key` would store for `text`, or why it can't (W-398). */
|
|
78
78
|
export function parseStyleValue(key: string, text: string): { value: unknown } | { error: string } {
|
|
79
79
|
// W-542: an inherited name ("constructor") is not a style property; it used to throw.
|
|
80
|
-
const shape =
|
|
80
|
+
const shape = FlatStyleProps.shape as Record<
|
|
81
81
|
string,
|
|
82
82
|
{ safeParse: (v: unknown) => { success: boolean } }
|
|
83
83
|
>;
|