@perkyzz/emvb 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +188 -152
- package/src/admin/editor/EditorOverlay.tsx +9 -1
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +287 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
- 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 +114 -0
- 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 +5 -3
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +35 -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/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +136 -0
- package/src/admin/editor/palette.ts +68 -0
- package/src/admin/editor/panels/AddPanel.tsx +48 -68
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +74 -102
- package/src/admin/editor/panels/LayersPanel.tsx +72 -63
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +10 -14
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +16 -5
- package/src/admin/editor/panels/settings/style-sections.ts +7 -2
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +6 -1
- 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 +30 -14
- package/src/admin/editor/useNodeActions.ts +44 -16
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/admin/ui.ts +4 -4
- package/src/astro/content-port.ts +24 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +109 -0
- package/src/astro/resolve-theme.ts +184 -64
- package/src/astro/resolve.ts +63 -16
- package/src/astro/theme-posts.ts +48 -5
- package/src/astro/visitor.ts +204 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +150 -34
- package/src/core/audience/rules.ts +124 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +29 -2
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css/trace.ts +169 -0
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +255 -0
- 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/tokens.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +117 -2
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +185 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +121 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +12 -4
- package/src/core/nesting.ts +4 -22
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +61 -0
- package/src/core/recipes/index.ts +433 -0
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +206 -17
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +129 -80
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +29 -8
- package/src/core/schema/layout.ts +291 -169
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +101 -66
- package/src/core/share/link.ts +187 -0
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +242 -32
- package/src/core/theme/float.ts +1 -1
- package/src/core/theme/pagination.ts +56 -0
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ export default defineConfig({
|
|
|
38
38
|
import { getEmDashEntry, decodeSlug } from "emdash";
|
|
39
39
|
import { EmVBPage, resolveEmVBPage } from "@perkyzz/emvb/astro";
|
|
40
40
|
// With @emdash-cms/plugin-forms installed and registered:
|
|
41
|
-
import { EmVBFormsRuntime } from "@perkyzz/emvb/astro/forms";
|
|
41
|
+
import { EmVBFormsRuntime } from "@perkyzz/emvb/astro/forms/client";
|
|
42
42
|
|
|
43
43
|
const emvb = await resolveEmVBPage(Astro);
|
|
44
44
|
if (!emvb && !(await getEmDashEntry("pages", decodeSlug(Astro.params.slug)))) {
|
|
@@ -49,7 +49,9 @@ if (!emvb && !(await getEmDashEntry("pages", decodeSlug(Astro.params.slug)))) {
|
|
|
49
49
|
{emvb && <EmVBPage page={emvb}>{emvb.needsFormsRuntime && <EmVBFormsRuntime />}</EmVBPage>}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Without the forms plugin,
|
|
52
|
+
Without the forms plugin, import `EmVBFormsRuntime` from `@perkyzz/emvb/astro/forms` (it renders nothing and does not import the plugin) or leave the element out. The `/client` subpath is the one that calls `initForms`.
|
|
53
|
+
|
|
54
|
+
A fixed route has no slug parameter. Pass the page's slug: `await resolveEmVBPage(Astro, { slug: "home" })`. Visitor rules can use the same call's `visitor` option (`{ segments: ["member"] }`, and country, device or returning when the site knows better); `resolveThemeParts` takes it too. The [install guide](https://github.com/PerkyZZ999/EmVB/blob/main/docs/guides/install-in-a-host-site.md) shows both.
|
|
53
55
|
|
|
54
56
|
Then sign in as an admin, open **Pages VisualBuilder** and click **Set up EmVB** once.
|
|
55
57
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
EmVB (<https://emvb.dev>) is MIT licensed. The editor's **Icon library** (
|
|
3
|
+
EmVB (<https://emvb.dev>) is MIT licensed. The editor's **Icon library** (`@perkyzz/emvb-icons`, the JSON sets) contains icons from the projects below. They keep their own licenses, copied in full in [`licenses/`](licenses/). `scripts/build-icon-sets.ts` in the EmVB repository builds the set files from the pinned npm packages. It refuses to build when a package's license file changes.
|
|
4
4
|
|
|
5
5
|
Changes made to every set: the SVG markup is reformatted into compact JSON, and only elements and attributes in EmVB's SVG allowlist are kept. Class attributes and comments are removed. Shared presentation attributes (stroke or fill, viewBox) move to the root `<svg>`. Set-specific changes are listed with each set.
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perkyzz/emvb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Visual page builder plugin for EmDash CMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"./admin": "./src/admin/index.tsx",
|
|
36
36
|
"./astro": "./src/astro/index.ts",
|
|
37
37
|
"./astro/forms": "./src/astro/forms/index.ts",
|
|
38
|
+
"./astro/forms/client": "./src/astro/forms/client.ts",
|
|
38
39
|
"./astro/popups": "./src/astro/popups/index.ts",
|
|
39
40
|
"./astro/floats": "./src/astro/floats/index.ts",
|
|
40
41
|
"./astro/tabs": "./src/astro/tabs/index.ts",
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
"test:astro": "bun --bun vitest run"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
51
|
+
"@perkyzz/emvb-icons": "0.1.0",
|
|
50
52
|
"zod": "~4.5.4"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
package/src/admin/access/role.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { EDITOR_ROLE } from "../../constants.ts";
|
|
3
|
-
import { requestJson, type Fetcher } from "../api.ts";
|
|
3
|
+
import { ApiError, requestJson, type Fetcher } from "../api.ts";
|
|
4
4
|
|
|
5
5
|
export async function readRole(fetcher: Fetcher): Promise<number> {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
try {
|
|
7
|
+
const me = await requestJson<{ role?: unknown }>(fetcher, "/_emdash/api/auth/me");
|
|
8
|
+
return typeof me.role === "number" ? me.role : 0;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
// A 200 with no body is "no role", the same as a role that is not a number.
|
|
11
|
+
if (error instanceof ApiError && error.code === "MISSING_DATA") return 0;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
/** D-020: EmVB is for editors and administrators. The server enforces the same line. */
|
package/src/admin/api.ts
CHANGED
|
@@ -44,7 +44,10 @@ export async function requestJson<T>(
|
|
|
44
44
|
});
|
|
45
45
|
const payload = await readEnvelope<T>(response);
|
|
46
46
|
if (!response.ok) throw envelopeError(response, payload);
|
|
47
|
-
|
|
47
|
+
if (payload.data === undefined) {
|
|
48
|
+
throw new ApiError(response.status, "MISSING_DATA", "The response had no data.");
|
|
49
|
+
}
|
|
50
|
+
return payload.data;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const LIST_PAGE = 50;
|
|
@@ -62,12 +65,19 @@ export async function listAllItems<T>(fetcher: Fetcher, collectionPath: string):
|
|
|
62
65
|
const query = `?limit=${LIST_PAGE}&orderBy=updatedAt&order=desc${
|
|
63
66
|
cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""
|
|
64
67
|
}`;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
let body: { items?: T[]; nextCursor?: string };
|
|
69
|
+
try {
|
|
70
|
+
// oxlint-disable-next-line no-await-in-loop -- each page needs the previous page's cursor
|
|
71
|
+
body = await requestJson<{ items?: T[]; nextCursor?: string }>(
|
|
72
|
+
fetcher,
|
|
73
|
+
`${collectionPath}${query}`,
|
|
74
|
+
);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
// A 200 with no body ends the list. It is not a failed load.
|
|
77
|
+
if (error instanceof ApiError && error.code === "MISSING_DATA") break;
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
items.push(...(body.items ?? []));
|
|
71
81
|
cursor = body?.nextCursor || undefined;
|
|
72
82
|
if (!cursor) break;
|
|
73
83
|
}
|
package/src/admin/content-api.ts
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ConditionsDoc,
|
|
3
|
-
DesignSystem,
|
|
4
3
|
FloatSettings,
|
|
5
4
|
Layout,
|
|
6
5
|
ThemePartType,
|
|
7
6
|
TriggersDoc,
|
|
8
7
|
} from "../core/index.ts";
|
|
9
|
-
import { PAGES_COLLECTION
|
|
8
|
+
import { PAGES_COLLECTION } from "../constants.ts";
|
|
10
9
|
import { listAllItems, requestJson, type Fetcher } from "./api.ts";
|
|
10
|
+
import { titleOf, type ContentItem } from "./content-item.ts";
|
|
11
11
|
import { entryStatus } from "./entry-status.ts";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export { publishDesign, saveDesign } from "./design-api.ts";
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
id: string;
|
|
17
|
-
slug?: string | null;
|
|
18
|
-
status?: string;
|
|
19
|
-
draftRevisionId?: string | null;
|
|
20
|
-
updatedAt?: string;
|
|
21
|
-
data?: Record<string, unknown>;
|
|
22
|
-
seo?: {
|
|
23
|
-
title?: string | null;
|
|
24
|
-
description?: string | null;
|
|
25
|
-
canonical?: string | null;
|
|
26
|
-
noIndex?: boolean | null;
|
|
27
|
-
image?: string | null;
|
|
28
|
-
} | null;
|
|
29
|
-
};
|
|
15
|
+
const CONTENT = `/_emdash/api/content/${PAGES_COLLECTION}`;
|
|
30
16
|
|
|
31
17
|
export type PageSummary = {
|
|
32
18
|
id: string;
|
|
@@ -36,16 +22,11 @@ export type PageSummary = {
|
|
|
36
22
|
updatedAt: string;
|
|
37
23
|
};
|
|
38
24
|
|
|
39
|
-
const titleOf = (item: RawItem) =>
|
|
40
|
-
typeof item.data?.["title"] === "string" && item.data["title"]
|
|
41
|
-
? item.data["title"]
|
|
42
|
-
: "Untitled page";
|
|
43
|
-
|
|
44
25
|
export async function listPages(fetcher: Fetcher): Promise<PageSummary[]> {
|
|
45
|
-
const items = await listAllItems<
|
|
26
|
+
const items = await listAllItems<ContentItem>(fetcher, CONTENT);
|
|
46
27
|
return items.map((item) => ({
|
|
47
28
|
id: item.id,
|
|
48
|
-
title: titleOf(item),
|
|
29
|
+
title: titleOf(item, "Untitled page"),
|
|
49
30
|
slug: item.slug ?? "",
|
|
50
31
|
status: entryStatus(item),
|
|
51
32
|
updatedAt: item.updatedAt ?? "",
|
|
@@ -56,7 +37,7 @@ export async function createPage(
|
|
|
56
37
|
fetcher: Fetcher,
|
|
57
38
|
input: { title: string; slug: string; layout: Layout },
|
|
58
39
|
): Promise<string> {
|
|
59
|
-
const body = await requestJson<{ item:
|
|
40
|
+
const body = await requestJson<{ item: ContentItem }>(fetcher, CONTENT, {
|
|
60
41
|
method: "POST",
|
|
61
42
|
body: { data: { title: input.title, layout: input.layout }, slug: input.slug },
|
|
62
43
|
});
|
|
@@ -183,28 +164,3 @@ export async function previewUrl(fetcher: Fetcher, id: string): Promise<string>
|
|
|
183
164
|
);
|
|
184
165
|
return body.url;
|
|
185
166
|
}
|
|
186
|
-
|
|
187
|
-
export async function saveDesign(
|
|
188
|
-
fetcher: Fetcher,
|
|
189
|
-
design: DesignSystem,
|
|
190
|
-
revision: string | null,
|
|
191
|
-
): Promise<string> {
|
|
192
|
-
const body = await requestJson<{ revision: string }>(
|
|
193
|
-
fetcher,
|
|
194
|
-
`/_emdash/api/plugins/${PLUGIN_ID}/design/save`,
|
|
195
|
-
{ method: "POST", body: { design, revision } },
|
|
196
|
-
);
|
|
197
|
-
return body.revision;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export async function publishDesign(
|
|
201
|
-
fetcher: Fetcher,
|
|
202
|
-
publishedRevision: string | null,
|
|
203
|
-
): Promise<string> {
|
|
204
|
-
const body = await requestJson<{ revision: string }>(
|
|
205
|
-
fetcher,
|
|
206
|
-
`/_emdash/api/plugins/${PLUGIN_ID}/design/publish`,
|
|
207
|
-
{ method: "POST", body: { publishedRevision } },
|
|
208
|
-
);
|
|
209
|
-
return body.revision;
|
|
210
|
-
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** One EmDash content row, as list and get return it. Pages add `seo`; theme parts omit it. */
|
|
2
|
+
export type ContentItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
slug?: string | null;
|
|
5
|
+
status?: string;
|
|
6
|
+
draftRevisionId?: string | null;
|
|
7
|
+
updatedAt?: string;
|
|
8
|
+
data?: Record<string, unknown>;
|
|
9
|
+
seo?: {
|
|
10
|
+
title?: string | null;
|
|
11
|
+
description?: string | null;
|
|
12
|
+
canonical?: string | null;
|
|
13
|
+
noIndex?: boolean | null;
|
|
14
|
+
image?: string | null;
|
|
15
|
+
} | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** The stored title, or `fallback` when it is missing or blank. */
|
|
19
|
+
export function titleOf(item: ContentItem, fallback: string): string {
|
|
20
|
+
const title = item.data?.["title"];
|
|
21
|
+
return typeof title === "string" && title ? title : fallback;
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DesignSystem } from "../core/index.ts";
|
|
2
|
+
import { PLUGIN_ID } from "../constants.ts";
|
|
3
|
+
import { requestJson, type Fetcher } from "./api.ts";
|
|
4
|
+
|
|
5
|
+
/** Saves the design draft. The returned revision is the one the next save must send. */
|
|
6
|
+
export async function saveDesign(
|
|
7
|
+
fetcher: Fetcher,
|
|
8
|
+
design: DesignSystem,
|
|
9
|
+
revision: string | null,
|
|
10
|
+
): Promise<string> {
|
|
11
|
+
const body = await requestJson<{ revision: string }>(
|
|
12
|
+
fetcher,
|
|
13
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/design/save`,
|
|
14
|
+
{ method: "POST", body: { design, revision } },
|
|
15
|
+
);
|
|
16
|
+
return body.revision;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Publishes the design draft. `publishedRevision` is the revision the editor last saw published. */
|
|
20
|
+
export async function publishDesign(
|
|
21
|
+
fetcher: Fetcher,
|
|
22
|
+
publishedRevision: string | null,
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
const body = await requestJson<{ revision: string }>(
|
|
25
|
+
fetcher,
|
|
26
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/design/publish`,
|
|
27
|
+
{ method: "POST", body: { publishedRevision } },
|
|
28
|
+
);
|
|
29
|
+
return body.revision;
|
|
30
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Button, Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
applyA11yFix,
|
|
4
|
+
applyAllA11yFixes,
|
|
5
|
+
findNode,
|
|
6
|
+
type A11yReport,
|
|
7
|
+
type Layout,
|
|
8
|
+
} from "../../core/index.ts";
|
|
9
|
+
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
10
|
+
|
|
11
|
+
/** Score bands for the badge colour (W-317). */
|
|
12
|
+
const scoreBand = (score: number) => (score >= 90 ? "good" : score >= 70 ? "fair" : "poor");
|
|
13
|
+
|
|
14
|
+
/** The live score in the top bar (W-317); opens the co-pilot. */
|
|
15
|
+
export function A11yScoreButton({ report, onOpen }: { report: A11yReport; onOpen: () => void }) {
|
|
16
|
+
const count = report.issues.length;
|
|
17
|
+
return (
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
className="emvb-a11y-score"
|
|
21
|
+
data-band={scoreBand(report.score)}
|
|
22
|
+
data-emvb-a11y-open=""
|
|
23
|
+
title={
|
|
24
|
+
count === 0
|
|
25
|
+
? "Accessibility: no issues found"
|
|
26
|
+
: `Accessibility: ${count} issue${count === 1 ? "" : "s"}`
|
|
27
|
+
}
|
|
28
|
+
aria-label={`Accessibility score ${report.score} of 100, ${count} issue${count === 1 ? "" : "s"}`}
|
|
29
|
+
onClick={onOpen}
|
|
30
|
+
>
|
|
31
|
+
A11y <b>{report.score}</b>
|
|
32
|
+
</button>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Accessibility co-pilot (W-317): the page's issues with what's wrong, a jump to the element,
|
|
38
|
+
* and a one-click fix where there is a safe one (or all at once). Fixes are ordinary edits.
|
|
39
|
+
*/
|
|
40
|
+
export function A11yDialog({
|
|
41
|
+
open,
|
|
42
|
+
onOpenChange,
|
|
43
|
+
report,
|
|
44
|
+
layout,
|
|
45
|
+
onSelect,
|
|
46
|
+
onApply,
|
|
47
|
+
}: {
|
|
48
|
+
open: boolean;
|
|
49
|
+
onOpenChange: (open: boolean) => void;
|
|
50
|
+
report: A11yReport;
|
|
51
|
+
layout: Layout | null;
|
|
52
|
+
onSelect: (id: string) => void;
|
|
53
|
+
onApply: (layout: Layout, note: string) => void;
|
|
54
|
+
}) {
|
|
55
|
+
const fixable = report.issues.filter((issue) => issue.fix);
|
|
56
|
+
const name = (id: string) => {
|
|
57
|
+
const node = layout ? findNode(layout, id) : undefined;
|
|
58
|
+
if (!node) return "Element";
|
|
59
|
+
if (layout && node.id === layout.root.id) return "Page";
|
|
60
|
+
return node.label || ELEMENT_NAMES[node.type] || node.type;
|
|
61
|
+
};
|
|
62
|
+
return (
|
|
63
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
64
|
+
<Dialog size="base" className="p-6 emvb-a11y" data-emvb-a11y="">
|
|
65
|
+
<Dialog.Title>
|
|
66
|
+
Accessibility · <span data-band={scoreBand(report.score)}>{report.score}</span>/100
|
|
67
|
+
</Dialog.Title>
|
|
68
|
+
{report.issues.length === 0 ? (
|
|
69
|
+
<p className="emvb-helper" data-emvb-a11y-clean="">
|
|
70
|
+
No issues found. Automated checks catch some problems, not all: try the page with a
|
|
71
|
+
keyboard and a screen reader too.
|
|
72
|
+
</p>
|
|
73
|
+
) : (
|
|
74
|
+
<ul className="emvb-a11y-issues">
|
|
75
|
+
{report.issues.map((issue) => (
|
|
76
|
+
<li key={issue.id} data-emvb-a11y-issue={issue.id} data-severity={issue.severity}>
|
|
77
|
+
<span className="emvb-a11y-what">
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
className="emvb-link-button"
|
|
81
|
+
onClick={() => {
|
|
82
|
+
onSelect(issue.nodeId);
|
|
83
|
+
onOpenChange(false);
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
{name(issue.nodeId)}
|
|
87
|
+
</button>
|
|
88
|
+
: {issue.message}
|
|
89
|
+
</span>
|
|
90
|
+
{issue.fix && layout && (
|
|
91
|
+
<Button
|
|
92
|
+
variant="secondary"
|
|
93
|
+
size="sm"
|
|
94
|
+
data-emvb-a11y-fix={issue.id}
|
|
95
|
+
onClick={() =>
|
|
96
|
+
onApply(applyA11yFix(layout, issue), `Fixed: ${issue.fixLabel ?? "issue"}`)
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
{issue.fixLabel ?? "Fix"}
|
|
100
|
+
</Button>
|
|
101
|
+
)}
|
|
102
|
+
</li>
|
|
103
|
+
))}
|
|
104
|
+
</ul>
|
|
105
|
+
)}
|
|
106
|
+
<div className="emvb-a11y-actions">
|
|
107
|
+
{fixable.length > 1 && layout && (
|
|
108
|
+
<Button
|
|
109
|
+
variant="primary"
|
|
110
|
+
data-emvb-a11y-fix-all=""
|
|
111
|
+
onClick={() =>
|
|
112
|
+
onApply(
|
|
113
|
+
applyAllA11yFixes(layout, fixable),
|
|
114
|
+
`Fixed ${fixable.length} accessibility issues`,
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
>
|
|
118
|
+
Fix all {fixable.length}
|
|
119
|
+
</Button>
|
|
120
|
+
)}
|
|
121
|
+
<Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
|
|
122
|
+
</div>
|
|
123
|
+
</Dialog>
|
|
124
|
+
</Dialog.Root>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Dialog } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { filterPalette, type PaletteItem } from "./palette.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ctrl/Cmd+K (W-314): one box to insert an element, jump to a layer, apply a class, or run an
|
|
7
|
+
* action. ↑/↓ choose, Enter runs, Esc closes. `>`, `+`, `@` and `.` narrow to one group.
|
|
8
|
+
*/
|
|
9
|
+
export function CommandPalette({
|
|
10
|
+
open,
|
|
11
|
+
onOpenChange,
|
|
12
|
+
items,
|
|
13
|
+
}: {
|
|
14
|
+
open: boolean;
|
|
15
|
+
onOpenChange: (open: boolean) => void;
|
|
16
|
+
items: PaletteItem[];
|
|
17
|
+
}) {
|
|
18
|
+
const [query, setQuery] = React.useState("");
|
|
19
|
+
const [active, setActive] = React.useState(0);
|
|
20
|
+
const listRef = React.useRef<HTMLUListElement>(null);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
if (open) {
|
|
23
|
+
setQuery("");
|
|
24
|
+
setActive(0);
|
|
25
|
+
}
|
|
26
|
+
}, [open]);
|
|
27
|
+
const shown = React.useMemo(() => filterPalette(items, query), [items, query]);
|
|
28
|
+
const current = Math.min(active, Math.max(0, shown.length - 1));
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
listRef.current
|
|
31
|
+
?.querySelector<HTMLElement>(`[data-index="${current}"]`)
|
|
32
|
+
?.scrollIntoView?.({ block: "nearest" });
|
|
33
|
+
}, [current]);
|
|
34
|
+
const run = (item: PaletteItem | undefined) => {
|
|
35
|
+
if (!item) return;
|
|
36
|
+
onOpenChange(false);
|
|
37
|
+
// After the dialog closes, so focus moves where the command wants it.
|
|
38
|
+
setTimeout(item.run, 0);
|
|
39
|
+
};
|
|
40
|
+
const onKeyDown = (event: React.KeyboardEvent) => {
|
|
41
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
44
|
+
setActive((current + step + shown.length) % Math.max(1, shown.length));
|
|
45
|
+
} else if (event.key === "Enter") {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
run(shown[current]);
|
|
48
|
+
} else if (event.key === "Home" && event.ctrlKey) {
|
|
49
|
+
setActive(0);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
let lastGroup = "";
|
|
53
|
+
return (
|
|
54
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
55
|
+
<Dialog size="base" className="emvb-palette" data-emvb-palette="">
|
|
56
|
+
<Dialog.Title className="sr-only">Command palette</Dialog.Title>
|
|
57
|
+
<input
|
|
58
|
+
className="emvb-palette-input"
|
|
59
|
+
role="combobox"
|
|
60
|
+
aria-expanded="true"
|
|
61
|
+
aria-controls="emvb-palette-list"
|
|
62
|
+
aria-activedescendant={shown[current] ? `emvb-palette-${current}` : undefined}
|
|
63
|
+
aria-label="Type a command, an element, a layer or a class"
|
|
64
|
+
placeholder="Insert, jump to a layer, apply a class, or run an action…"
|
|
65
|
+
autoFocus
|
|
66
|
+
value={query}
|
|
67
|
+
data-emvb-palette-input=""
|
|
68
|
+
onChange={(event) => {
|
|
69
|
+
setQuery(event.currentTarget.value);
|
|
70
|
+
setActive(0);
|
|
71
|
+
}}
|
|
72
|
+
onKeyDown={onKeyDown}
|
|
73
|
+
/>
|
|
74
|
+
<ul className="emvb-palette-list" id="emvb-palette-list" role="listbox" ref={listRef}>
|
|
75
|
+
{shown.length === 0 && (
|
|
76
|
+
<li className="emvb-palette-empty" role="presentation">
|
|
77
|
+
Nothing matches “{query}”.
|
|
78
|
+
</li>
|
|
79
|
+
)}
|
|
80
|
+
{shown.map((item, index) => {
|
|
81
|
+
const heading = !query.trim() && item.group !== lastGroup ? item.group : null;
|
|
82
|
+
lastGroup = item.group;
|
|
83
|
+
return (
|
|
84
|
+
<React.Fragment key={item.id}>
|
|
85
|
+
{heading && (
|
|
86
|
+
<li className="emvb-palette-group" role="presentation">
|
|
87
|
+
{heading}
|
|
88
|
+
</li>
|
|
89
|
+
)}
|
|
90
|
+
<li
|
|
91
|
+
id={`emvb-palette-${index}`}
|
|
92
|
+
role="option"
|
|
93
|
+
aria-selected={index === current}
|
|
94
|
+
data-index={index}
|
|
95
|
+
data-emvb-palette-item={item.id}
|
|
96
|
+
className="emvb-palette-item"
|
|
97
|
+
onMouseMove={() => setActive(index)}
|
|
98
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
99
|
+
onClick={() => run(item)}
|
|
100
|
+
>
|
|
101
|
+
<span className="emvb-palette-label">{item.label}</span>
|
|
102
|
+
<span className="emvb-palette-hint">
|
|
103
|
+
{query.trim() ? item.group : ""}
|
|
104
|
+
{item.hint ? ` ${item.hint}` : ""}
|
|
105
|
+
</span>
|
|
106
|
+
</li>
|
|
107
|
+
</React.Fragment>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</ul>
|
|
111
|
+
<p className="emvb-palette-tips">
|
|
112
|
+
↑↓ choose · Enter run · Esc close · <kbd>></kbd> actions · <kbd>+</kbd> insert ·{" "}
|
|
113
|
+
<kbd>@</kbd> layers · <kbd>.</kbd> classes
|
|
114
|
+
</p>
|
|
115
|
+
</Dialog>
|
|
116
|
+
</Dialog.Root>
|
|
117
|
+
);
|
|
118
|
+
}
|