@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- 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 +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- 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/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 +68 -20
- 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 +72 -15
- 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 +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- 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 +120 -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 +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -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 +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- 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 +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -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 +967 -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 +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -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 +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -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 +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- 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 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- 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,41 @@
|
|
|
1
|
+
export {
|
|
2
|
+
EXTENSION_API_VERSION,
|
|
3
|
+
type EmVBExtension,
|
|
4
|
+
type ExtensionManifest,
|
|
5
|
+
type ExtensionElement,
|
|
6
|
+
type ExtensionPanel,
|
|
7
|
+
type ExtensionSource,
|
|
8
|
+
type ExtensionPropSchema,
|
|
9
|
+
type ExtensionField,
|
|
10
|
+
type ExtensionElementManifest,
|
|
11
|
+
type ExtensionPanelManifest,
|
|
12
|
+
type ExtensionSourceManifest,
|
|
13
|
+
type ExtensionRenderContext,
|
|
14
|
+
} from "./types.ts";
|
|
15
|
+
export {
|
|
16
|
+
isExtensionType,
|
|
17
|
+
parseExtensionType,
|
|
18
|
+
extensionType,
|
|
19
|
+
extensionNamespaceIssue,
|
|
20
|
+
extensionIdIssue,
|
|
21
|
+
extensionNameIssue,
|
|
22
|
+
} from "./namespace.ts";
|
|
23
|
+
export { validateExtensionProps, schemaDefaults } from "./schema.ts";
|
|
24
|
+
export {
|
|
25
|
+
EXTENSION_PLACEHOLDER_TEXT,
|
|
26
|
+
EXTENSION_PLACEHOLDER_CSS,
|
|
27
|
+
extensionPlaceholderLabel,
|
|
28
|
+
extensionPlaceholderVNode,
|
|
29
|
+
} from "./placeholder.ts";
|
|
30
|
+
export { normalizeExtension } from "./normalize.ts";
|
|
31
|
+
export {
|
|
32
|
+
rememberExtensions,
|
|
33
|
+
listedExtensionManifests,
|
|
34
|
+
liveExtension,
|
|
35
|
+
liveElement,
|
|
36
|
+
clearExtensions,
|
|
37
|
+
manifestsFromOptions,
|
|
38
|
+
} from "./registry.ts";
|
|
39
|
+
export { safeExtensionOutput } from "./safe-nodes.ts";
|
|
40
|
+
export { syncSourceValues, renderExtensionNode } from "./render-ext.ts";
|
|
41
|
+
export { defineExtension } from "./define.ts";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension type namespacing (W-927, D-066). Stored types are `ext:<pkg>/<name>`.
|
|
3
|
+
* Built-in element types, path escape, HTML and extra colons are refused.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { KNOWN_ELEMENT_TYPES } from "../schema/layout.ts";
|
|
7
|
+
|
|
8
|
+
/** Unscoped package id: lowercase start, letters/digits/dashes, up to 64. */
|
|
9
|
+
const EXTENSION_ID_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
10
|
+
|
|
11
|
+
/** Element or source or panel name inside a package. */
|
|
12
|
+
const EXTENSION_NAME_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Full stored type. Looser than UnknownNode's generic 64-char cap so a long package
|
|
16
|
+
* id still fits (limits may only loosen, D-065).
|
|
17
|
+
*/
|
|
18
|
+
const EXTENSION_TYPE_PATTERN = /^ext:[a-z][a-z0-9-]{0,63}\/[a-z][a-z0-9-]{0,31}$/;
|
|
19
|
+
|
|
20
|
+
const KNOWN = new Set<string>(KNOWN_ELEMENT_TYPES);
|
|
21
|
+
|
|
22
|
+
export function isExtensionType(type: string): boolean {
|
|
23
|
+
return type.startsWith("ext:");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Parse `ext:pkg/name` into parts, or undefined when the string is not a valid extension type. */
|
|
27
|
+
export function parseExtensionType(type: string): { pkg: string; name: string } | undefined {
|
|
28
|
+
if (!EXTENSION_TYPE_PATTERN.test(type)) return undefined;
|
|
29
|
+
const body = type.slice("ext:".length);
|
|
30
|
+
const slash = body.indexOf("/");
|
|
31
|
+
if (slash <= 0) return undefined;
|
|
32
|
+
const pkg = body.slice(0, slash);
|
|
33
|
+
const name = body.slice(slash + 1);
|
|
34
|
+
if (!EXTENSION_ID_PATTERN.test(pkg) || !EXTENSION_NAME_PATTERN.test(name)) return undefined;
|
|
35
|
+
if (KNOWN.has(type) || KNOWN.has(pkg) || KNOWN.has(name)) return undefined;
|
|
36
|
+
return { pkg, name };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function extensionType(pkg: string, name: string): string | undefined {
|
|
40
|
+
if (!EXTENSION_ID_PATTERN.test(pkg) || !EXTENSION_NAME_PATTERN.test(name)) return undefined;
|
|
41
|
+
// A package id must not collide with a built-in element type.
|
|
42
|
+
if (KNOWN.has(pkg) || KNOWN.has(name)) return undefined;
|
|
43
|
+
const type = `ext:${pkg}/${name}`;
|
|
44
|
+
if (KNOWN.has(type)) return undefined;
|
|
45
|
+
return type;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Why a candidate type or id is refused. Used by registration and by seeds that
|
|
50
|
+
* try to escape the namespace.
|
|
51
|
+
*/
|
|
52
|
+
export function extensionNamespaceIssue(type: string): string | undefined {
|
|
53
|
+
if (!type.startsWith("ext:")) return "Extension types must start with ext:";
|
|
54
|
+
if (type.includes("..")) return "Extension types must not contain ..";
|
|
55
|
+
if (type.includes(":")) {
|
|
56
|
+
const rest = type.slice(4);
|
|
57
|
+
if (rest.includes(":")) return "Extension types must not contain extra colons";
|
|
58
|
+
}
|
|
59
|
+
if (/[<>"'`]/.test(type) || [...type].some((ch) => (ch.codePointAt(0) ?? 0) < 32)) {
|
|
60
|
+
return "Extension types must not contain HTML or control characters";
|
|
61
|
+
}
|
|
62
|
+
if (!EXTENSION_TYPE_PATTERN.test(type)) {
|
|
63
|
+
return "Extension types must be ext:<package>/<name> with lowercase letters, digits and dashes";
|
|
64
|
+
}
|
|
65
|
+
if (KNOWN.has(type)) return "Extension types must not collide with built-in elements";
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function extensionIdIssue(id: string): string | undefined {
|
|
70
|
+
if (!EXTENSION_ID_PATTERN.test(id)) {
|
|
71
|
+
return "Extension ids are lowercase, start with a letter, and use letters, digits and dashes only";
|
|
72
|
+
}
|
|
73
|
+
if (KNOWN.has(id)) return "Extension id collides with a built-in element type";
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function extensionNameIssue(name: string): string | undefined {
|
|
78
|
+
if (!EXTENSION_NAME_PATTERN.test(name)) {
|
|
79
|
+
return "Extension names are lowercase, start with a letter, and use letters, digits and dashes only";
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate and turn a live EmVBExtension into a manifest + kept live object (W-927).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { extensionIdIssue, extensionNameIssue, extensionType } from "./namespace.ts";
|
|
6
|
+
import { isAllowedExtensionFieldKind, schemaDefaults } from "./schema.ts";
|
|
7
|
+
import type {
|
|
8
|
+
EmVBExtension,
|
|
9
|
+
ExtensionElement,
|
|
10
|
+
ExtensionManifest,
|
|
11
|
+
ExtensionPanel,
|
|
12
|
+
ExtensionSource,
|
|
13
|
+
} from "./types.ts";
|
|
14
|
+
import { EXTENSION_API_VERSION } from "./types.ts";
|
|
15
|
+
|
|
16
|
+
export type NormalizedExtension = {
|
|
17
|
+
live: EmVBExtension;
|
|
18
|
+
manifest: ExtensionManifest;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const MAX_ELEMENTS = 32;
|
|
22
|
+
const MAX_PANELS = 8;
|
|
23
|
+
const MAX_SOURCES = 8;
|
|
24
|
+
|
|
25
|
+
function normalizeElement(
|
|
26
|
+
pkg: string,
|
|
27
|
+
element: ExtensionElement,
|
|
28
|
+
): ExtensionManifest["elements"][number] | undefined {
|
|
29
|
+
if (extensionNameIssue(element.name)) return undefined;
|
|
30
|
+
const type = extensionType(pkg, element.name);
|
|
31
|
+
if (!type) return undefined;
|
|
32
|
+
if (typeof element.render !== "function") return undefined;
|
|
33
|
+
if (element.schema.type !== "object") return undefined;
|
|
34
|
+
const fields = (element.fields ?? [])
|
|
35
|
+
.filter(
|
|
36
|
+
(f) =>
|
|
37
|
+
typeof f.key === "string" &&
|
|
38
|
+
/^[a-zA-Z][a-zA-Z0-9_]{0,31}$/.test(f.key) &&
|
|
39
|
+
isAllowedExtensionFieldKind(f.kind) &&
|
|
40
|
+
typeof f.label === "string" &&
|
|
41
|
+
f.label.length > 0 &&
|
|
42
|
+
f.label.length <= 80,
|
|
43
|
+
)
|
|
44
|
+
.slice(0, 32);
|
|
45
|
+
const defaults = {
|
|
46
|
+
...schemaDefaults(element.schema),
|
|
47
|
+
...(typeof element.defaults === "function" ? element.defaults() : {}),
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
type,
|
|
51
|
+
name: element.name,
|
|
52
|
+
label: element.label.trim().slice(0, 80) || element.name,
|
|
53
|
+
group: element.group ?? "content",
|
|
54
|
+
schema: element.schema,
|
|
55
|
+
fields,
|
|
56
|
+
defaults,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function normalizePanel(
|
|
61
|
+
pkg: string,
|
|
62
|
+
panel: ExtensionPanel,
|
|
63
|
+
): ExtensionManifest["panels"][number] | undefined {
|
|
64
|
+
if (extensionNameIssue(panel.name)) return undefined;
|
|
65
|
+
return {
|
|
66
|
+
id: `ext:${pkg}/${panel.name}`,
|
|
67
|
+
name: panel.name,
|
|
68
|
+
label: panel.label.trim().slice(0, 80) || panel.name,
|
|
69
|
+
...(panel.description ? { description: panel.description.slice(0, 500) } : {}),
|
|
70
|
+
...(panel.source && !extensionNameIssue(panel.source) ? { source: panel.source } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function normalizeSource(
|
|
75
|
+
pkg: string,
|
|
76
|
+
source: ExtensionSource,
|
|
77
|
+
): ExtensionManifest["sources"][number] | undefined {
|
|
78
|
+
if (extensionNameIssue(source.name)) return undefined;
|
|
79
|
+
if (typeof source.resolve !== "function") return undefined;
|
|
80
|
+
const capabilities = (source.capabilities ?? []).filter(
|
|
81
|
+
(c): c is "text" | "url" | "image" => c === "text" || c === "url" || c === "image",
|
|
82
|
+
);
|
|
83
|
+
if (capabilities.length === 0) return undefined;
|
|
84
|
+
return {
|
|
85
|
+
id: `ext:${pkg}/${source.name}`,
|
|
86
|
+
name: source.name,
|
|
87
|
+
label: source.label.trim().slice(0, 80) || source.name,
|
|
88
|
+
capabilities,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accept a live extension or refuse it (returns undefined). Refused extensions
|
|
94
|
+
* are skipped so a bad neighbour cannot take down the site's EmVB plugin.
|
|
95
|
+
*/
|
|
96
|
+
export function normalizeExtension(input: unknown): NormalizedExtension | undefined {
|
|
97
|
+
if (!input || typeof input !== "object") return undefined;
|
|
98
|
+
const ext = input as EmVBExtension;
|
|
99
|
+
if (ext.extensionApi !== EXTENSION_API_VERSION) return undefined;
|
|
100
|
+
if (extensionIdIssue(ext.id)) return undefined;
|
|
101
|
+
|
|
102
|
+
const elementsIn = Array.isArray(ext.elements) ? ext.elements.slice(0, MAX_ELEMENTS) : [];
|
|
103
|
+
const panelsIn = Array.isArray(ext.panels) ? ext.panels.slice(0, MAX_PANELS) : [];
|
|
104
|
+
const sourcesIn = Array.isArray(ext.sources) ? ext.sources.slice(0, MAX_SOURCES) : [];
|
|
105
|
+
|
|
106
|
+
const elements = elementsIn
|
|
107
|
+
.map((el) => normalizeElement(ext.id, el))
|
|
108
|
+
.filter((el): el is NonNullable<typeof el> => el !== undefined);
|
|
109
|
+
const panels = panelsIn
|
|
110
|
+
.map((p) => normalizePanel(ext.id, p))
|
|
111
|
+
.filter((p): p is NonNullable<typeof p> => p !== undefined);
|
|
112
|
+
const sources = sourcesIn
|
|
113
|
+
.map((s) => normalizeSource(ext.id, s))
|
|
114
|
+
.filter((s): s is NonNullable<typeof s> => s !== undefined);
|
|
115
|
+
|
|
116
|
+
// Keep only live pieces that survived normalization (drop bad entries).
|
|
117
|
+
const liveElements = elementsIn.filter((el) => elements.some((m) => m.name === el.name));
|
|
118
|
+
const livePanels = panelsIn.filter((p) => panels.some((m) => m.name === p.name));
|
|
119
|
+
const liveSources = sourcesIn.filter((s) => sources.some((m) => m.name === s.name));
|
|
120
|
+
|
|
121
|
+
const live: EmVBExtension = {
|
|
122
|
+
extensionApi: EXTENSION_API_VERSION,
|
|
123
|
+
id: ext.id,
|
|
124
|
+
...(ext.label ? { label: ext.label.trim().slice(0, 80) } : {}),
|
|
125
|
+
elements: liveElements,
|
|
126
|
+
panels: livePanels,
|
|
127
|
+
sources: liveSources,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
live,
|
|
132
|
+
manifest: {
|
|
133
|
+
extensionApi: EXTENSION_API_VERSION,
|
|
134
|
+
id: ext.id,
|
|
135
|
+
label: (ext.label ?? ext.id).trim().slice(0, 80),
|
|
136
|
+
elements,
|
|
137
|
+
panels,
|
|
138
|
+
sources,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder for a missing, throwing or illegal extension element (W-927, D-066).
|
|
3
|
+
* Visible in the editor and on the published page; never runs extension code;
|
|
4
|
+
* never breaks siblings.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { VNode } from "../render/vnode.ts";
|
|
8
|
+
import { parseExtensionType } from "./namespace.ts";
|
|
9
|
+
|
|
10
|
+
/** Public copy shown when an extension element cannot render. */
|
|
11
|
+
export const EXTENSION_PLACEHOLDER_TEXT = "This block needs an extension that is not installed.";
|
|
12
|
+
|
|
13
|
+
/** Editor copy names the missing type so authors can tell which package to add back. */
|
|
14
|
+
export function extensionPlaceholderLabel(type: string): string {
|
|
15
|
+
const safe = parseExtensionType(type) ? type : "extension";
|
|
16
|
+
return `Missing extension “${safe}”`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function extensionPlaceholderVNode(
|
|
20
|
+
type: string,
|
|
21
|
+
id: string | undefined,
|
|
22
|
+
mode: "public" | "editor",
|
|
23
|
+
): VNode {
|
|
24
|
+
const label = mode === "editor" ? extensionPlaceholderLabel(type) : EXTENSION_PLACEHOLDER_TEXT;
|
|
25
|
+
const safeType = parseExtensionType(type) ? type : undefined;
|
|
26
|
+
return {
|
|
27
|
+
tag: "div",
|
|
28
|
+
attrs: {
|
|
29
|
+
class: "emvb-ext-missing",
|
|
30
|
+
...(safeType ? { "data-emvb-ext": safeType } : {}),
|
|
31
|
+
...(id ? { "data-emvb-id": id } : {}),
|
|
32
|
+
...(mode === "public" ? { role: "note" } : {}),
|
|
33
|
+
},
|
|
34
|
+
children: [label],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Minimal CSS so the placeholder is readable without any extension stylesheet. */
|
|
39
|
+
export const EXTENSION_PLACEHOLDER_CSS =
|
|
40
|
+
".emvb-ext-missing{margin:0;padding:12px 16px;border:1px dashed currentColor;opacity:0.7;font:inherit}" +
|
|
41
|
+
".emvb-ext{min-width:0}";
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide live extension registry (W-927).
|
|
3
|
+
*
|
|
4
|
+
* EmDash JSON.stringifies `emvb()` options before calling `createPlugin`, so render
|
|
5
|
+
* and resolve functions cannot travel in `options`. `emvb()` stores the live objects
|
|
6
|
+
* here (on `globalThis`, so Vite SSR module duplication still sees them); createPlugin
|
|
7
|
+
* and the renderer look them up by id.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { normalizeExtension } from "./normalize.ts";
|
|
11
|
+
import type { EmVBExtension, ExtensionManifest } from "./types.ts";
|
|
12
|
+
|
|
13
|
+
const KEY = Symbol.for("emvb.extensions.v1");
|
|
14
|
+
|
|
15
|
+
type Store = {
|
|
16
|
+
byId: Map<string, EmVBExtension>;
|
|
17
|
+
manifests: ExtensionManifest[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function store(): Store {
|
|
21
|
+
const g = globalThis as typeof globalThis & { [KEY]?: Store };
|
|
22
|
+
if (!g[KEY]) g[KEY] = { byId: new Map(), manifests: [] };
|
|
23
|
+
return g[KEY];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Register live extensions from `emvb({ extensions })`. Returns serializable manifests. */
|
|
27
|
+
export function rememberExtensions(input: unknown): ExtensionManifest[] {
|
|
28
|
+
const list = Array.isArray(input) ? input : [];
|
|
29
|
+
const manifests: ExtensionManifest[] = [];
|
|
30
|
+
const s = store();
|
|
31
|
+
for (const item of list) {
|
|
32
|
+
const normalized = normalizeExtension(item);
|
|
33
|
+
if (!normalized) continue;
|
|
34
|
+
s.byId.set(normalized.live.id, normalized.live);
|
|
35
|
+
// Replace an existing manifest for the same id (re-import / HMR).
|
|
36
|
+
s.manifests = s.manifests.filter((m) => m.id !== normalized.manifest.id);
|
|
37
|
+
s.manifests.push(normalized.manifest);
|
|
38
|
+
manifests.push(normalized.manifest);
|
|
39
|
+
}
|
|
40
|
+
return manifests;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Manifests currently remembered (for editor/config). */
|
|
44
|
+
export function listedExtensionManifests(): ExtensionManifest[] {
|
|
45
|
+
return store().manifests.slice();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Live extension by package id. */
|
|
49
|
+
export function liveExtension(id: string): EmVBExtension | undefined {
|
|
50
|
+
return store().byId.get(id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Live element by stored type `ext:pkg/name`. */
|
|
54
|
+
export function liveElement(type: string):
|
|
55
|
+
| {
|
|
56
|
+
extension: EmVBExtension;
|
|
57
|
+
element: NonNullable<EmVBExtension["elements"]>[number];
|
|
58
|
+
manifest: ExtensionManifest["elements"][number];
|
|
59
|
+
}
|
|
60
|
+
| undefined {
|
|
61
|
+
const manifests = store().manifests;
|
|
62
|
+
for (const manifest of manifests) {
|
|
63
|
+
const elManifest = manifest.elements.find((e) => e.type === type);
|
|
64
|
+
if (!elManifest) continue;
|
|
65
|
+
const extension = store().byId.get(manifest.id);
|
|
66
|
+
const element = extension?.elements?.find((e) => e.name === elManifest.name);
|
|
67
|
+
if (!extension || !element) continue;
|
|
68
|
+
return { extension, element, manifest: elManifest };
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Test helper: drop every registered extension. */
|
|
74
|
+
export function clearExtensions(): void {
|
|
75
|
+
const s = store();
|
|
76
|
+
s.byId.clear();
|
|
77
|
+
s.manifests = [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Rebuild manifests from options.extensions after createPlugin (ids only or full manifests). */
|
|
81
|
+
export function manifestsFromOptions(input: unknown): ExtensionManifest[] {
|
|
82
|
+
if (!Array.isArray(input)) return listedExtensionManifests();
|
|
83
|
+
// Prefer live registry order; fall back to whatever was serialized.
|
|
84
|
+
const live = listedExtensionManifests();
|
|
85
|
+
if (live.length > 0) return live;
|
|
86
|
+
const out: ExtensionManifest[] = [];
|
|
87
|
+
for (const item of input) {
|
|
88
|
+
if (!item || typeof item !== "object") continue;
|
|
89
|
+
const m = item as ExtensionManifest;
|
|
90
|
+
if (m.extensionApi !== 1 || typeof m.id !== "string") continue;
|
|
91
|
+
out.push(m);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render one extension element node to a VNode (W-927, D-066).
|
|
3
|
+
* Missing extension, throwing render, or illegal output → placeholder.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { LayoutNode } from "../schema/layout.ts";
|
|
7
|
+
import type { VNode } from "../render/vnode.ts";
|
|
8
|
+
import { liveElement, liveExtension } from "./registry.ts";
|
|
9
|
+
import { validateExtensionProps } from "./schema.ts";
|
|
10
|
+
import { safeExtensionOutput } from "./safe-nodes.ts";
|
|
11
|
+
import { extensionPlaceholderVNode } from "./placeholder.ts";
|
|
12
|
+
import type { ExtensionRenderContext } from "./types.ts";
|
|
13
|
+
import { parseExtensionType } from "./namespace.ts";
|
|
14
|
+
|
|
15
|
+
export type ExtensionRenderMode = "public" | "editor";
|
|
16
|
+
|
|
17
|
+
function isThenable(value: unknown): value is Promise<unknown> {
|
|
18
|
+
return !!value && typeof (value as { then?: unknown }).then === "function";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function cleanSourceRecord(raw: Readonly<Record<string, string>>): Record<string, string> {
|
|
22
|
+
const out: Record<string, string> = {};
|
|
23
|
+
let n = 0;
|
|
24
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
25
|
+
if (n >= 32) break;
|
|
26
|
+
if (typeof key !== "string" || !/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/.test(key)) continue;
|
|
27
|
+
if (typeof value !== "string") continue;
|
|
28
|
+
let cleaned = "";
|
|
29
|
+
for (const char of value) {
|
|
30
|
+
const code = char.codePointAt(0) ?? 0;
|
|
31
|
+
if (code === 9) cleaned += " ";
|
|
32
|
+
else if (code === 10 || (code >= 32 && code !== 127 && !(code >= 0x80 && code <= 0x9f))) {
|
|
33
|
+
cleaned += char;
|
|
34
|
+
}
|
|
35
|
+
if (cleaned.length >= 2000) break;
|
|
36
|
+
}
|
|
37
|
+
out[key] = cleaned.trim();
|
|
38
|
+
n += 1;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve source values for one package (sync resolvers only).
|
|
45
|
+
* Async sources are left empty here; hosts that need them can pre-resolve later.
|
|
46
|
+
*/
|
|
47
|
+
export function syncSourceValues(pkg: string): Record<string, Record<string, string>> {
|
|
48
|
+
const ext = liveExtension(pkg);
|
|
49
|
+
if (!ext?.sources) return {};
|
|
50
|
+
const out: Record<string, Record<string, string>> = {};
|
|
51
|
+
for (const source of ext.sources) {
|
|
52
|
+
try {
|
|
53
|
+
const result = source.resolve();
|
|
54
|
+
if (result && typeof result === "object" && !Array.isArray(result) && !isThenable(result)) {
|
|
55
|
+
out[source.name] = cleanSourceRecord(result as Readonly<Record<string, string>>);
|
|
56
|
+
} else {
|
|
57
|
+
out[source.name] = {};
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
out[source.name] = {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type VisitChildren = (nodes: LayoutNode[]) => VNode[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Build the VNode for a stored extension element. Always returns a node (placeholder
|
|
70
|
+
* on failure) so siblings keep rendering.
|
|
71
|
+
*/
|
|
72
|
+
export function renderExtensionNode(
|
|
73
|
+
node: LayoutNode,
|
|
74
|
+
mode: ExtensionRenderMode,
|
|
75
|
+
visitChildren: VisitChildren,
|
|
76
|
+
): VNode {
|
|
77
|
+
const id = typeof node.id === "string" ? node.id : undefined;
|
|
78
|
+
const type = node.type;
|
|
79
|
+
const parsed = parseExtensionType(type);
|
|
80
|
+
if (!parsed) {
|
|
81
|
+
return extensionPlaceholderVNode(type, id, mode);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const found = liveElement(type);
|
|
85
|
+
if (!found) {
|
|
86
|
+
return extensionPlaceholderVNode(type, id, mode);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const storedProps =
|
|
90
|
+
node.props && typeof node.props === "object" && !Array.isArray(node.props)
|
|
91
|
+
? (node.props as Record<string, unknown>)
|
|
92
|
+
: {};
|
|
93
|
+
const checked = validateExtensionProps(found.manifest.schema, storedProps);
|
|
94
|
+
const ctx: ExtensionRenderContext = { sources: syncSourceValues(parsed.pkg) };
|
|
95
|
+
|
|
96
|
+
let raw: unknown;
|
|
97
|
+
try {
|
|
98
|
+
raw = found.element.render(checked.props, ctx);
|
|
99
|
+
} catch {
|
|
100
|
+
return extensionPlaceholderVNode(type, id, mode);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const safe = safeExtensionOutput(raw);
|
|
104
|
+
if (safe.length === 0) {
|
|
105
|
+
return extensionPlaceholderVNode(type, id, mode);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const children = visitChildren(safe);
|
|
109
|
+
return {
|
|
110
|
+
tag: "div",
|
|
111
|
+
attrs: {
|
|
112
|
+
class: "emvb-ext",
|
|
113
|
+
"data-emvb-ext": type,
|
|
114
|
+
...(id && mode === "editor" ? { "data-emvb-id": id } : {}),
|
|
115
|
+
},
|
|
116
|
+
children,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn an extension render() result into built-in LayoutNodes EmVB will render (W-927).
|
|
3
|
+
* Rejects raw HTML strings, unknown types, nested extension types, and oversized trees.
|
|
4
|
+
* Surviving nodes are re-validated through EmVB's layout schema so props and styles
|
|
5
|
+
* pass the same sanitizer as editor-saved content.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { LAYOUT_SCHEMA_VERSION, type LayoutNode } from "../schema/layout.ts";
|
|
9
|
+
import { KNOWN_ELEMENT_TYPES } from "../schema/layout.ts";
|
|
10
|
+
import { validateLayout } from "../validate.ts";
|
|
11
|
+
import { newNodeId } from "../tree-ops.ts";
|
|
12
|
+
import { isExtensionType } from "./namespace.ts";
|
|
13
|
+
|
|
14
|
+
const KNOWN = new Set<string>(KNOWN_ELEMENT_TYPES);
|
|
15
|
+
const MAX_NODES = 32;
|
|
16
|
+
const MAX_DEPTH = 8;
|
|
17
|
+
|
|
18
|
+
function coerce(
|
|
19
|
+
value: unknown,
|
|
20
|
+
depth: number,
|
|
21
|
+
budget: { left: number },
|
|
22
|
+
random: () => number,
|
|
23
|
+
): Record<string, unknown> | undefined {
|
|
24
|
+
if (budget.left <= 0 || depth > MAX_DEPTH) return undefined;
|
|
25
|
+
if (typeof value === "string") return undefined; // raw HTML / text — refused
|
|
26
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
27
|
+
const node = value as Record<string, unknown>;
|
|
28
|
+
if (typeof node.type !== "string" || !KNOWN.has(node.type) || isExtensionType(node.type)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (
|
|
32
|
+
node.props !== undefined &&
|
|
33
|
+
(typeof node.props !== "object" || node.props === null || Array.isArray(node.props))
|
|
34
|
+
) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
budget.left -= 1;
|
|
38
|
+
const id =
|
|
39
|
+
typeof node.id === "string" && /^[A-Za-z0-9_-]{4,24}$/.test(node.id)
|
|
40
|
+
? node.id
|
|
41
|
+
: newNodeId(random);
|
|
42
|
+
let children: Record<string, unknown>[] | undefined;
|
|
43
|
+
if (Array.isArray(node.children)) {
|
|
44
|
+
children = [];
|
|
45
|
+
for (const child of node.children) {
|
|
46
|
+
const ok = coerce(child, depth + 1, budget, random);
|
|
47
|
+
if (ok) children.push(ok);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Drop style/attributes from extension output: only props + children of built-ins.
|
|
51
|
+
// (Extensions style through the host element's own style on the wrapper.)
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
type: node.type,
|
|
55
|
+
props: { ...(node.props as Record<string, unknown>) },
|
|
56
|
+
...(children ? { children } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Normalize a render() return value to validated built-in nodes.
|
|
62
|
+
* Illegal shapes, schema failures and empty output yield `[]` (caller shows the placeholder).
|
|
63
|
+
*/
|
|
64
|
+
export function safeExtensionOutput(
|
|
65
|
+
raw: unknown,
|
|
66
|
+
random: () => number = Math.random,
|
|
67
|
+
): LayoutNode[] {
|
|
68
|
+
const budget = { left: MAX_NODES };
|
|
69
|
+
const coerced: Record<string, unknown>[] = [];
|
|
70
|
+
if (Array.isArray(raw)) {
|
|
71
|
+
for (const item of raw) {
|
|
72
|
+
const node = coerce(item, 0, budget, random);
|
|
73
|
+
if (node) coerced.push(node);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
const one = coerce(raw, 0, budget, random);
|
|
77
|
+
if (one) coerced.push(one);
|
|
78
|
+
}
|
|
79
|
+
if (coerced.length === 0) return [];
|
|
80
|
+
|
|
81
|
+
const page = {
|
|
82
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
83
|
+
root: {
|
|
84
|
+
id: "root0001",
|
|
85
|
+
type: "container",
|
|
86
|
+
props: {},
|
|
87
|
+
children: coerced,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const result = validateLayout(page);
|
|
91
|
+
if (!result.ok) return [];
|
|
92
|
+
return result.layout.root.children.slice();
|
|
93
|
+
}
|