@perkyzz/emvb 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +106 -332
- package/src/admin/editor/EditorOverlay.tsx +3 -1
- package/src/admin/editor/PerfMeter.tsx +1 -1
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +16 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
- package/src/admin/editor/canvas/canvas-scale.ts +20 -0
- package/src/admin/editor/canvas/drop-line.ts +24 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
- package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
- package/src/admin/editor/collection-previews.ts +28 -5
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +15 -15
- package/src/admin/editor/host.ts +33 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
- package/src/admin/editor/icons/library.ts +29 -19
- package/src/admin/editor/icons/use-icon-library.ts +315 -0
- package/src/admin/editor/palette-items.ts +36 -5
- package/src/admin/editor/palette.ts +3 -2
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +40 -99
- package/src/admin/editor/panels/LayersPanel.tsx +34 -62
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +15 -4
- package/src/admin/editor/panels/settings/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +4 -0
- package/src/admin/editor/store.ts +10 -1
- package/src/admin/editor/useClipboardActions.ts +1 -1
- package/src/admin/editor/useEditorCommands.ts +61 -13
- package/src/admin/editor/useEditorData.ts +7 -1
- package/src/admin/editor/useEditorShortcuts.ts +23 -15
- package/src/admin/editor/useNodeActions.ts +6 -1
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/astro/content-port.ts +24 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +20 -8
- package/src/astro/resolve-theme.ts +166 -76
- package/src/astro/resolve.ts +57 -16
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +63 -38
- package/src/core/audience/rules.ts +22 -2
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +9 -0
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +4 -6
- package/src/core/design/classes.ts +13 -15
- package/src/core/design/diff.ts +55 -0
- package/src/core/design/merge.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +30 -0
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +183 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/index.ts +10 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +9 -4
- package/src/core/nesting.ts +4 -23
- package/src/core/perf/scripts.ts +9 -6
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +155 -13
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +153 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +68 -28
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +200 -39
- package/src/core/theme/float.ts +1 -1
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
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
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type A11yReport,
|
|
7
7
|
type Layout,
|
|
8
8
|
} from "../../core/index.ts";
|
|
9
|
-
import { ELEMENT_NAMES } from "./
|
|
9
|
+
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
10
10
|
|
|
11
11
|
/** Score bands for the badge colour (W-317). */
|
|
12
12
|
const scoreBand = (score: number) => (score >= 90 ? "good" : score >= 70 ? "fair" : "poor");
|