@perkyzz/emvb 0.4.0 → 0.6.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.
Files changed (127) hide show
  1. package/README.md +23 -3
  2. package/THIRD_PARTY_NOTICES.md +23 -1
  3. package/licenses/exif-js.LICENSE +21 -0
  4. package/licenses/fflate.LICENSE +21 -0
  5. package/licenses/glfx.js.LICENSE +19 -0
  6. package/licenses/mini-photo-editor.LICENSE +21 -0
  7. package/licenses/photocn.LICENSE +21 -0
  8. package/package.json +5 -3
  9. package/src/admin/agents-api.ts +39 -0
  10. package/src/admin/editor/CommandPalette.tsx +43 -2
  11. package/src/admin/editor/Editor.tsx +33 -0
  12. package/src/admin/editor/Timeline.tsx +108 -6
  13. package/src/admin/editor/collection-previews.ts +6 -1
  14. package/src/admin/editor/editor-chrome.tsx +49 -0
  15. package/src/admin/editor/editor-commands.ts +13 -0
  16. package/src/admin/editor/editor-css.ts +7 -0
  17. package/src/admin/editor/feature-css.ts +22 -3
  18. package/src/admin/editor/palette.ts +6 -2
  19. package/src/admin/editor/panels/ColorControl.tsx +24 -12
  20. package/src/admin/editor/panels/ElementPanel.tsx +1 -1
  21. package/src/admin/editor/panels/LayersPanel.tsx +13 -3
  22. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  23. package/src/admin/editor/panels/VariableSection.tsx +5 -3
  24. package/src/admin/editor/panels/color-space.ts +12 -1
  25. package/src/admin/editor/panels/settings/AdvancedFields.tsx +84 -28
  26. package/src/admin/editor/panels/settings/AudienceEditor.tsx +42 -4
  27. package/src/admin/editor/panels/settings/DraftTextField.tsx +38 -9
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +24 -7
  29. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  30. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  31. package/src/admin/editor/panels/settings/MediaPicker.tsx +156 -7
  32. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  33. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
  34. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  35. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  36. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  37. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  38. package/src/admin/editor/panels/variable-values.ts +18 -2
  39. package/src/admin/editor/remote-change.ts +67 -0
  40. package/src/admin/editor/store.ts +7 -3
  41. package/src/admin/image-editor/BlurFocus.tsx +112 -0
  42. package/src/admin/image-editor/Canvas.tsx +261 -0
  43. package/src/admin/image-editor/CropOverlay.tsx +390 -0
  44. package/src/admin/image-editor/CurvesPanel.tsx +394 -0
  45. package/src/admin/image-editor/ExportDialog.tsx +354 -0
  46. package/src/admin/image-editor/ImageEditButton.tsx +83 -0
  47. package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
  48. package/src/admin/image-editor/MetadataPanel.tsx +183 -0
  49. package/src/admin/image-editor/announce.tsx +65 -0
  50. package/src/admin/image-editor/crop-geometry.ts +161 -0
  51. package/src/admin/image-editor/curve-math.ts +177 -0
  52. package/src/admin/image-editor/data-url-fetch.ts +59 -0
  53. package/src/admin/image-editor/engine.ts +55 -0
  54. package/src/admin/image-editor/exif.ts +82 -0
  55. package/src/admin/image-editor/flatten.ts +54 -0
  56. package/src/admin/image-editor/gpu-fit.ts +81 -0
  57. package/src/admin/image-editor/image-editor-css.ts +398 -0
  58. package/src/admin/image-editor/load.ts +109 -0
  59. package/src/admin/image-editor/panels.tsx +287 -0
  60. package/src/admin/image-editor/parts.tsx +565 -0
  61. package/src/admin/image-editor/save.ts +125 -0
  62. package/src/admin/image-editor/tone-panels.tsx +338 -0
  63. package/src/admin/image-editor/tools.ts +59 -0
  64. package/src/admin/image-editor/worker.ts +111 -0
  65. package/src/admin/index.tsx +3 -1
  66. package/src/admin/media-api.ts +132 -2
  67. package/src/admin/pages/AgentsPage.tsx +274 -0
  68. package/src/admin/ui.ts +33 -0
  69. package/src/astro/EmVBPage.astro +11 -2
  70. package/src/astro/floats/runtime.ts +10 -0
  71. package/src/astro/popups/runtime.ts +15 -0
  72. package/src/astro/render.ts +3 -0
  73. package/src/astro/resolve-theme.ts +15 -4
  74. package/src/astro/tabs/runtime.ts +60 -1
  75. package/src/astro/visitor.ts +4 -3
  76. package/src/constants.ts +1 -1
  77. package/src/core/a11y/audit.ts +202 -26
  78. package/src/core/arrange.ts +13 -3
  79. package/src/core/css/generate.ts +9 -1
  80. package/src/core/data/bindings.ts +12 -6
  81. package/src/core/design/classes.ts +5 -3
  82. package/src/core/design/diff.ts +3 -1
  83. package/src/core/design/merge.ts +3 -1
  84. package/src/core/design/transfer.ts +13 -2
  85. package/src/core/design/variables.ts +2 -1
  86. package/src/core/elements/dynamic-elements.ts +9 -1
  87. package/src/core/elements/form-elements.ts +18 -3
  88. package/src/core/elements/index.ts +39 -11
  89. package/src/core/elements/plain-text.ts +2 -2
  90. package/src/core/forms/binding.ts +148 -1
  91. package/src/core/history/diff.ts +32 -4
  92. package/src/core/image-edit/schema.ts +145 -0
  93. package/src/core/image-edit/summary.ts +58 -0
  94. package/src/core/index.ts +14 -0
  95. package/src/core/limits.ts +10 -0
  96. package/src/core/migrate/index.ts +3 -1
  97. package/src/core/perf/meter.ts +9 -1
  98. package/src/core/render/dynamic-post.ts +23 -6
  99. package/src/core/render/form.ts +36 -11
  100. package/src/core/render/index.ts +75 -15
  101. package/src/core/render/pagination.ts +21 -2
  102. package/src/core/sanitize/embed-url.ts +7 -1
  103. package/src/core/sanitize/href.ts +13 -1
  104. package/src/core/schema/descriptors.ts +4 -1
  105. package/src/core/schema/layout.ts +21 -4
  106. package/src/core/share/link.ts +9 -3
  107. package/src/core/stable-json.ts +15 -0
  108. package/src/core/theme/dynamic.ts +32 -24
  109. package/src/core/theme/pagination.ts +30 -3
  110. package/src/core/theme/popup-rules.ts +10 -5
  111. package/src/mcp/errors.ts +44 -0
  112. package/src/mcp/index.ts +4 -0
  113. package/src/mcp/ports.ts +85 -0
  114. package/src/mcp/prompts.ts +76 -0
  115. package/src/mcp/publish.ts +60 -0
  116. package/src/mcp/queue.ts +19 -0
  117. package/src/mcp/rate-limit.ts +80 -0
  118. package/src/mcp/read.ts +486 -0
  119. package/src/mcp/refs.ts +84 -0
  120. package/src/mcp/settings.ts +18 -0
  121. package/src/mcp/tools.ts +265 -0
  122. package/src/mcp/write.ts +664 -0
  123. package/src/server/agent-settings.ts +159 -0
  124. package/src/server/design-routes.ts +71 -17
  125. package/src/server/icon-routes.ts +13 -6
  126. package/src/server/mcp-routes.ts +323 -0
  127. package/src/server/plugin.ts +32 -2
@@ -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
+ }
@@ -0,0 +1,76 @@
1
+ import { Banner } from "@cloudflare/kumo";
2
+ import { WarningIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import type { Fetcher } from "../../../api.ts";
5
+ import { loadFormFields, type DefinitionField } from "../../../forms-api.ts";
6
+ import {
7
+ requiredFieldIssues,
8
+ requiredFieldIssueText,
9
+ type LayoutNode,
10
+ type RequiredFieldIssue,
11
+ } from "../../../../core/index.ts";
12
+
13
+ /** The panel's short line for one issue; the full sentence is its tooltip and the MCP text. */
14
+ function shortReason(issue: RequiredFieldIssue): string {
15
+ if (issue.kind === "missing") return `has no field on this form (${issue.field}).`;
16
+ if (issue.kind === "hidden") {
17
+ return issue.devices.length === 3
18
+ ? "is hidden on every device."
19
+ : `is hidden on ${issue.devices.join(" and ")}.`;
20
+ }
21
+ return `is shown only to some visitors: ${issue.who}.`;
22
+ }
23
+
24
+ /**
25
+ * W-511: on a Form, the required fields visitors can't fill: missing from the form, or hidden on
26
+ * a device. Either way the form can't be sent there, and the visitor sees no reason why.
27
+ */
28
+ export function RequiredFieldsNotice({ node, fetcher }: { node: LayoutNode; fetcher: Fetcher }) {
29
+ const formId = String((node.props as { formId?: unknown }).formId ?? "").trim();
30
+ const [fields, setFields] = React.useState<DefinitionField[] | null>(null);
31
+ React.useEffect(() => {
32
+ let cancelled = false;
33
+ setFields(null);
34
+ if (!formId) return undefined;
35
+ void loadFormFields(fetcher, formId).then((next) => {
36
+ if (!cancelled) setFields(next);
37
+ });
38
+ return () => {
39
+ cancelled = true;
40
+ };
41
+ }, [fetcher, formId]);
42
+ const issues = fields ? requiredFieldIssues(node, fields) : [];
43
+ if (issues.length === 0) return null;
44
+ const title =
45
+ issues.length === 1
46
+ ? "A required field can't be filled in"
47
+ : `${issues.length} required fields can't be filled in`;
48
+ return (
49
+ <div className="emvb-required-notice" data-emvb-required-fields="">
50
+ <Banner
51
+ variant="alert"
52
+ icon={<WarningIcon aria-hidden="true" />}
53
+ title={title}
54
+ description={
55
+ <>
56
+ <ul className="emvb-required-notice__list">
57
+ {issues.map((issue) => (
58
+ <li
59
+ key={`${issue.kind}:${issue.field}`}
60
+ data-emvb-required-issue={issue.kind}
61
+ title={requiredFieldIssueText(issue)}
62
+ >
63
+ <strong>{issue.label}</strong> {shortReason(issue)}
64
+ </li>
65
+ ))}
66
+ </ul>
67
+ <span className="emvb-required-notice__hint">
68
+ Visitors who can't fill a required field can't send the form. Show the field to
69
+ everyone, or make it optional in Forms.
70
+ </span>
71
+ </>
72
+ }
73
+ />
74
+ </div>
75
+ );
76
+ }
@@ -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
  }
@@ -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
+ }
@@ -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
- return HEX.test(trimmed) ? { ok: true, value: trimmed } : { ok: false, error: ERRORS.color };
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 }
@@ -71,3 +73,17 @@ export function pickerHex(hex: string): string {
71
73
  }
72
74
  return "#000000";
73
75
  }
76
+
77
+ /**
78
+ * The picker's 6-digit colour with the alpha `previous` had: `<input type="color">` has no alpha,
79
+ * so picking a colour made a see-through one solid (W-526).
80
+ */
81
+ export function withPreviousAlpha(picked: string, previous: string): string {
82
+ const p = previous.trim().toLowerCase();
83
+ const alpha = /^#[0-9a-f]{8}$/.test(p)
84
+ ? p.slice(7)
85
+ : /^#[0-9a-f]{4}$/.test(p)
86
+ ? (p[4] ?? "") + (p[4] ?? "")
87
+ : "";
88
+ return alpha && alpha !== "ff" && /^#[0-9a-f]{6}$/i.test(picked) ? picked + alpha : picked;
89
+ }
@@ -0,0 +1,67 @@
1
+ import * as React from "react";
2
+ import { PLUGIN_ID } from "../../constants.ts";
3
+ import { requestJson, type Fetcher } from "../api.ts";
4
+
5
+ /** How often an idle editor checks whether the page changed elsewhere (W-466). */
6
+ const REMOTE_CHECK_MS = 20_000;
7
+
8
+ export type RemoteChange = null | "agent" | "other";
9
+
10
+ /**
11
+ * What changed the stored draft since `rev`: null when nothing did, "agent" when the newest
12
+ * version is one an AI agent saved, "other" for anyone else.
13
+ */
14
+ export async function checkRemoteChange(
15
+ fetcher: Fetcher,
16
+ collection: string,
17
+ id: string,
18
+ rev: string,
19
+ ): Promise<RemoteChange> {
20
+ const body = await requestJson<{ item?: { draftRevisionId?: string | null }; _rev?: string }>(
21
+ fetcher,
22
+ `/_emdash/api/content/${collection}/${encodeURIComponent(id)}`,
23
+ );
24
+ const stored = body["_rev"];
25
+ if (!stored || stored === rev) return null;
26
+ const draft = body.item?.draftRevisionId;
27
+ if (!draft) return "other";
28
+ const agents = await requestJson<{ versions?: { revisionId: string }[] }>(
29
+ fetcher,
30
+ `/_emdash/api/plugins/${PLUGIN_ID}/agents/page`,
31
+ { method: "POST", body: { pageId: id } },
32
+ ).catch(() => ({ versions: [] }));
33
+ return (agents.versions ?? []).some((v) => v.revisionId === draft) ? "agent" : "other";
34
+ }
35
+
36
+ /**
37
+ * Polls while the editor is idle (no unsaved edits, nothing in flight, tab visible) and reports
38
+ * when the page changed elsewhere, so the person can reload before their next save conflicts.
39
+ */
40
+ export function useRemoteChange(
41
+ fetcher: Fetcher,
42
+ collection: string,
43
+ id: string,
44
+ rev: string | null,
45
+ idle: boolean,
46
+ ): RemoteChange {
47
+ const [change, setChange] = React.useState<RemoteChange>(null);
48
+ React.useEffect(() => setChange(null), [rev]);
49
+ React.useEffect(() => {
50
+ if (!idle || !rev || change) return;
51
+ let cancelled = false;
52
+ const timer = setInterval(() => {
53
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
54
+ checkRemoteChange(fetcher, collection, id, rev).then(
55
+ (next) => {
56
+ if (!cancelled && next) setChange(next);
57
+ },
58
+ () => undefined,
59
+ );
60
+ }, REMOTE_CHECK_MS);
61
+ return () => {
62
+ cancelled = true;
63
+ clearInterval(timer);
64
+ };
65
+ }, [fetcher, collection, id, rev, idle, change]);
66
+ return change;
67
+ }
@@ -87,8 +87,12 @@ const withLayout = (
87
87
  ): EditorState => ({ ...edited(state, { ...state.page, layout }), selectedId, lastDeleted });
88
88
 
89
89
  /** Applies an arrange result; a refused one leaves the state unchanged. */
90
- const arranged = (state: EditorState, result: Arranged): EditorState =>
91
- result.ok ? withLayout(state, result.layout, result.selected) : state;
90
+ const arranged = (state: EditorState, result: Arranged): EditorState => {
91
+ if (!result.ok) return state;
92
+ // W-521: an unchanged layout (a drop on its own spot) only selects: no undo step, not unsaved.
93
+ if (result.layout === state.page.layout) return { ...state, selectedId: result.selected };
94
+ return withLayout(state, result.layout, result.selected);
95
+ };
92
96
 
93
97
  /** Page edits kept for undo. Save, publish and design stay on the live state (D-035, proposed). */
94
98
  const PAGE_HISTORY_LIMIT = 100;
@@ -209,7 +213,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
209
213
  if (!state.page.layout) return state;
210
214
  return arranged(state, moveNode(state.page.layout, action.id, action.parentId, action.index));
211
215
  case "apply-arranged":
212
- return withLayout(state, action.layout, action.selected);
216
+ return arranged(state, { ok: true, layout: action.layout, selected: action.selected });
213
217
  case "saved":
214
218
  // A saved draft on a published entry is not live until Publish (W-190).
215
219
  return {
@@ -0,0 +1,112 @@
1
+ /**
2
+ * The blur tool's sharp spot on the image (W-484): drag it, or focus it and use the arrow keys.
3
+ *
4
+ * Follows photocn's `blur-center-overlay.tsx` (https://github.com/rbbydotdev/photocn,
5
+ * apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev. The keyboard
6
+ * control is EmVB's.
7
+ */
8
+ import * as React from "react";
9
+
10
+ type Center = { centerX: number; centerY: number };
11
+ const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
12
+ const pct = (v: number) => Math.round(v * 100);
13
+
14
+ export function BlurFocus({
15
+ centerX,
16
+ centerY,
17
+ disabled = false,
18
+ onChange,
19
+ onCommit,
20
+ }: Center & {
21
+ disabled?: boolean;
22
+ onChange: (next: Center) => void;
23
+ onCommit: (next: Center) => void;
24
+ }) {
25
+ const ref = React.useRef<HTMLDivElement | null>(null);
26
+ const [dragging, setDragging] = React.useState(false);
27
+ const at = (event: { clientX: number; clientY: number }): Center | null => {
28
+ const rect = ref.current?.getBoundingClientRect();
29
+ if (!rect || rect.width <= 0 || rect.height <= 0) return null;
30
+ return {
31
+ centerX: clamp01((event.clientX - rect.left) / rect.width),
32
+ centerY: clamp01((event.clientY - rect.top) / rect.height),
33
+ };
34
+ };
35
+ const end = (event: React.PointerEvent<HTMLDivElement>) => {
36
+ if (!dragging) return;
37
+ if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
38
+ event.currentTarget.releasePointerCapture(event.pointerId);
39
+ }
40
+ setDragging(false);
41
+ onCommit(at(event) ?? { centerX, centerY });
42
+ };
43
+ return (
44
+ <div
45
+ ref={ref}
46
+ className="emvb-ie-blur-focus"
47
+ data-disabled={disabled || undefined}
48
+ data-emvb-image-blur-area=""
49
+ onPointerDown={(event) => {
50
+ if (disabled || (event.pointerType === "mouse" && event.button !== 0)) return;
51
+ const pos = at(event);
52
+ if (!pos) return;
53
+ // Dragging the spot must not flash the original (the stage's press-and-hold compare).
54
+ event.stopPropagation();
55
+ event.currentTarget.setPointerCapture?.(event.pointerId);
56
+ setDragging(true);
57
+ onChange(pos);
58
+ }}
59
+ onPointerMove={(event) => {
60
+ if (disabled || !dragging) return;
61
+ const pos = at(event);
62
+ if (pos) onChange(pos);
63
+ }}
64
+ onPointerUp={end}
65
+ onPointerCancel={end}
66
+ >
67
+ <div
68
+ className="emvb-ie-blur-handle"
69
+ data-dragging={dragging || undefined}
70
+ data-emvb-image-blur-focus=""
71
+ role="slider"
72
+ tabIndex={disabled ? -1 : 0}
73
+ aria-label="Sharp spot (blur center)"
74
+ aria-valuemin={0}
75
+ aria-valuemax={100}
76
+ aria-valuenow={pct(centerX)}
77
+ aria-valuetext={`${pct(centerX)}% across, ${pct(centerY)}% down`}
78
+ aria-disabled={disabled || undefined}
79
+ style={{ left: `${centerX * 100}%`, top: `${centerY * 100}%` }}
80
+ onPointerDown={(event) => event.currentTarget.focus({ preventScroll: true })}
81
+ onKeyDown={(event) => {
82
+ if (disabled) return;
83
+ const step = event.shiftKey ? 0.1 : 0.01;
84
+ const moves: Record<string, [number, number]> = {
85
+ ArrowLeft: [-step, 0],
86
+ ArrowRight: [step, 0],
87
+ ArrowUp: [0, -step],
88
+ ArrowDown: [0, step],
89
+ };
90
+ const move = moves[event.key];
91
+ if (event.key === "Home") {
92
+ event.preventDefault();
93
+ onCommit({ centerX: 0.5, centerY: 0.5 });
94
+ return;
95
+ }
96
+ if (!move) return;
97
+ event.preventDefault();
98
+ event.stopPropagation();
99
+ onChange({
100
+ centerX: Number(clamp01(centerX + move[0]).toFixed(2)),
101
+ centerY: Number(clamp01(centerY + move[1]).toFixed(2)),
102
+ });
103
+ }}
104
+ onKeyUp={(event) => {
105
+ if (event.key.startsWith("Arrow")) onCommit({ centerX, centerY });
106
+ }}
107
+ >
108
+ <span aria-hidden="true" />
109
+ </div>
110
+ </div>
111
+ );
112
+ }