@perkyzz/emvb 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +76 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +75 -0
- package/src/admin/content-api.ts +210 -0
- package/src/admin/editor/Editor.tsx +532 -0
- package/src/admin/editor/EditorOverlay.tsx +66 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +21 -0
- package/src/admin/editor/TopBar.tsx +243 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
- package/src/admin/editor/canvas/canvas-events.ts +245 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +101 -0
- package/src/admin/editor/canvas/vnode-react.tsx +69 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +164 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +148 -0
- package/src/admin/editor/dnd/new-element.ts +107 -0
- package/src/admin/editor/editor-css.ts +625 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +146 -0
- package/src/admin/editor/panels/ClassesSection.tsx +372 -0
- package/src/admin/editor/panels/ColorControl.tsx +477 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +773 -0
- package/src/admin/editor/panels/LayersPanel.tsx +573 -0
- package/src/admin/editor/panels/LeftPanel.tsx +81 -0
- package/src/admin/editor/panels/PageSettings.tsx +255 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
- package/src/admin/editor/panels/VariableSection.tsx +530 -0
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +116 -0
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +394 -0
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +209 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +240 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +203 -0
- package/src/admin/editor/useEditorData.ts +193 -0
- package/src/admin/editor/useEditorShortcuts.ts +180 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +184 -0
- package/src/admin/editor/useSave.ts +242 -0
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +91 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +221 -0
- package/src/admin/pages/list-kit.tsx +125 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +107 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +233 -0
- package/src/admin/ui.ts +244 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +63 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +126 -0
- package/src/astro/index.ts +16 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +296 -0
- package/src/astro/render.ts +108 -0
- package/src/astro/resolve-theme.ts +515 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +116 -0
- package/src/astro/theme-context.ts +89 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +448 -0
- package/src/core/clipboard.ts +504 -0
- package/src/core/css/generate.ts +236 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +224 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +132 -0
- package/src/core/design/variables.ts +359 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +225 -0
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +219 -0
- package/src/core/elements/index.ts +960 -0
- package/src/core/elements/menu.ts +190 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +45 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +380 -0
- package/src/core/limits.ts +9 -0
- package/src/core/migrate/index.ts +126 -0
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +21 -0
- package/src/core/render/dynamic-post.ts +175 -0
- package/src/core/render/extras.ts +98 -0
- package/src/core/render/form.ts +235 -0
- package/src/core/render/index.ts +372 -0
- package/src/core/render/loop.ts +43 -0
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +37 -0
- package/src/core/render/tabs.ts +76 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +771 -0
- package/src/core/sanitize/embed-url.ts +160 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +374 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +37 -0
- package/src/core/schema/design.ts +93 -0
- package/src/core/schema/layout.ts +1008 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +336 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +25 -0
- package/src/core/theme/conditions.ts +324 -0
- package/src/core/theme/dynamic.ts +143 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +81 -0
- package/src/core/theme/popup-markup.ts +41 -0
- package/src/core/theme/popup-rules.ts +62 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +118 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +43 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional public Tabs keyboard / ARIA runtime (W-078).
|
|
3
|
+
* Hosts load this only when `needsTabsRuntime` is true (R-031).
|
|
4
|
+
* CSS radio + :has() remains the no-JS fallback.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The group's own radios, tab labels and panels; nested groups are left out. */
|
|
8
|
+
function parts(root: HTMLElement) {
|
|
9
|
+
const all = <T extends HTMLElement>(selector: string) => [
|
|
10
|
+
...root.querySelectorAll<T>(`:scope > ${selector}`),
|
|
11
|
+
];
|
|
12
|
+
return {
|
|
13
|
+
inputs: all<HTMLInputElement>(".emvb-tab-input"),
|
|
14
|
+
labels: all(".emvb-tab-list > .emvb-tab-label"),
|
|
15
|
+
panels: all(".emvb-tab-panels > .emvb-tab-panel"),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Where each navigation key moves from tab `current` of `count`. */
|
|
20
|
+
const KEY_TARGETS: Record<string, (current: number, count: number) => number> = {
|
|
21
|
+
ArrowRight: (current) => current + 1,
|
|
22
|
+
ArrowLeft: (current) => current - 1,
|
|
23
|
+
Home: () => 0,
|
|
24
|
+
End: (_current, count) => count - 1,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Selects tab `index`; only keyboard navigation moves focus, never load or a radio change. */
|
|
28
|
+
function activate(root: HTMLElement, index: number, focus = false): void {
|
|
29
|
+
if (root.dataset["emvbTabsActivating"] === "1") return;
|
|
30
|
+
root.dataset["emvbTabsActivating"] = "1";
|
|
31
|
+
try {
|
|
32
|
+
const { inputs, labels, panels } = parts(root);
|
|
33
|
+
if (inputs.length === 0 || labels.length === 0) return;
|
|
34
|
+
const next = ((index % inputs.length) + inputs.length) % inputs.length;
|
|
35
|
+
const input = inputs[next];
|
|
36
|
+
if (!input) return;
|
|
37
|
+
if (!input.checked) input.checked = true;
|
|
38
|
+
for (const [i, label] of labels.entries()) {
|
|
39
|
+
const selected = i === next;
|
|
40
|
+
label.setAttribute("aria-selected", String(selected));
|
|
41
|
+
label.tabIndex = selected ? 0 : -1;
|
|
42
|
+
panels[i]?.setAttribute("aria-hidden", String(!selected));
|
|
43
|
+
}
|
|
44
|
+
const focusTarget = focus ? labels[next] : undefined;
|
|
45
|
+
if (focusTarget && document.activeElement !== focusTarget) {
|
|
46
|
+
try {
|
|
47
|
+
focusTarget.focus({ preventScroll: true });
|
|
48
|
+
} catch {
|
|
49
|
+
// focus may fail in non-interactive test hosts
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} finally {
|
|
53
|
+
delete root.dataset["emvbTabsActivating"];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function selectedIndex(root: HTMLElement): number {
|
|
58
|
+
const checked = parts(root).inputs.findIndex((el) => el.checked);
|
|
59
|
+
return checked >= 0 ? checked : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Points each tab at its panel and back, giving either an id when it has none. */
|
|
63
|
+
function linkTabs(root: HTMLElement, labels: HTMLElement[], panels: HTMLElement[]): void {
|
|
64
|
+
const prefix = root.id || "emvb-tabs";
|
|
65
|
+
for (const [i, label] of labels.entries()) {
|
|
66
|
+
const panel = panels[i];
|
|
67
|
+
const panelId = panel?.id || `${prefix}-panel-${i}`;
|
|
68
|
+
if (panel && !panel.id) panel.id = panelId;
|
|
69
|
+
label.setAttribute("aria-controls", panelId);
|
|
70
|
+
if (panel) {
|
|
71
|
+
if (!label.id) label.id = `${prefix}-tab-${i}`;
|
|
72
|
+
panel.setAttribute("aria-labelledby", label.id);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function enhance(root: HTMLElement): void {
|
|
78
|
+
if (root.dataset["emvbTabsReady"] === "1") return;
|
|
79
|
+
root.dataset["emvbTabsReady"] = "1";
|
|
80
|
+
const list = root.querySelector<HTMLElement>(":scope > .emvb-tab-list");
|
|
81
|
+
if (!list) return;
|
|
82
|
+
list.setAttribute("aria-orientation", "horizontal");
|
|
83
|
+
const { inputs, labels, panels } = parts(root);
|
|
84
|
+
// W-195: the tabs now take keyboard focus, so the invisible radios leave the Tab order.
|
|
85
|
+
for (const input of inputs) {
|
|
86
|
+
input.tabIndex = -1;
|
|
87
|
+
input.setAttribute("aria-hidden", "true");
|
|
88
|
+
}
|
|
89
|
+
linkTabs(root, labels, panels);
|
|
90
|
+
activate(root, selectedIndex(root));
|
|
91
|
+
|
|
92
|
+
list.addEventListener("keydown", (event) => {
|
|
93
|
+
const target = KEY_TARGETS[event.key];
|
|
94
|
+
if (!target) return;
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
if (labels.length === 0) return;
|
|
97
|
+
activate(root, target(selectedIndex(root), labels.length), true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Keep ARIA in sync when the CSS-only radio path is used (click / label).
|
|
101
|
+
root.addEventListener("change", (event) => {
|
|
102
|
+
const target = event.target as HTMLInputElement | null;
|
|
103
|
+
if (!target || !target.classList.contains("emvb-tab-input")) return;
|
|
104
|
+
activate(root, selectedIndex(root));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function initTabs(root: ParentNode = document): void {
|
|
109
|
+
const nodes = root.querySelectorAll<HTMLElement>(".emvb-tabs");
|
|
110
|
+
for (const node of nodes) enhance(node);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Test helper: select tab by index after enhance. */
|
|
114
|
+
export function selectTabForTest(root: HTMLElement, index: number): void {
|
|
115
|
+
activate(root, index);
|
|
116
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { splitArchivePage, type ThemeRequestContext } from "../core/index.ts";
|
|
2
|
+
|
|
3
|
+
type ContentRef = { collection: string; id: string; slug?: string | null };
|
|
4
|
+
type Kind = Pick<ThemeRequestContext, "kind">;
|
|
5
|
+
|
|
6
|
+
/** A context for `path` that is not the front page, a 404 or a search, plus `rest`. */
|
|
7
|
+
const context = (path: string, rest: Kind & Partial<ThemeRequestContext>): ThemeRequestContext => ({
|
|
8
|
+
path,
|
|
9
|
+
isFront: false,
|
|
10
|
+
is404: false,
|
|
11
|
+
isSearch: false,
|
|
12
|
+
...rest,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** Archive URLs by pattern, and what each adds to the context. */
|
|
16
|
+
const ARCHIVES: [RegExp, (match: RegExpExecArray) => Partial<ThemeRequestContext>][] = [
|
|
17
|
+
[
|
|
18
|
+
/^\/category\/([^/]+)$/,
|
|
19
|
+
([, slug]) => ({ taxonomy: { type: "category", slug: decodeURIComponent(slug ?? "") } }),
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
/^\/tag\/([^/]+)$/,
|
|
23
|
+
([, slug]) => ({ taxonomy: { type: "tag", slug: decodeURIComponent(slug ?? "") } }),
|
|
24
|
+
],
|
|
25
|
+
[/^\/posts$/, () => ({ collection: "posts" })],
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Build a ThemeRequestContext from the request URL and optional host content hint.
|
|
30
|
+
* Hosts can override by passing a fully built context to `resolveThemeParts`.
|
|
31
|
+
*/
|
|
32
|
+
export function themeContextFrom(
|
|
33
|
+
url: URL,
|
|
34
|
+
options: {
|
|
35
|
+
content?: ContentRef | null;
|
|
36
|
+
is404?: boolean;
|
|
37
|
+
isFront?: boolean;
|
|
38
|
+
isSearch?: boolean;
|
|
39
|
+
} = {},
|
|
40
|
+
): ThemeRequestContext {
|
|
41
|
+
const path = url.pathname.replace(/\/+$/, "") || "/";
|
|
42
|
+
const { content } = options;
|
|
43
|
+
if (options.is404 === true) return themeContext404(path);
|
|
44
|
+
if (options.isFront === true || (!content && path === "/")) {
|
|
45
|
+
return context("/", {
|
|
46
|
+
isFront: true,
|
|
47
|
+
kind: "singular",
|
|
48
|
+
collection: content?.collection,
|
|
49
|
+
entryId: content?.id,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (options.isSearch === true || path === "/search") return themeContextSearch(path);
|
|
53
|
+
// `/posts/page/2` is page 2 of the `/posts` archive; conditions see `/posts` (W-221).
|
|
54
|
+
const paged = splitArchivePage(path);
|
|
55
|
+
for (const [pattern, extra] of ARCHIVES) {
|
|
56
|
+
const match = paged ? pattern.exec(paged.basePath) : null;
|
|
57
|
+
if (match && paged) {
|
|
58
|
+
return context(paged.basePath, {
|
|
59
|
+
kind: "archive",
|
|
60
|
+
...extra(match),
|
|
61
|
+
...(paged.page > 1 || paged.basePath !== path ? { page: paged.page } : {}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (content) {
|
|
66
|
+
return context(path, { kind: "singular", collection: content.collection, entryId: content.id });
|
|
67
|
+
}
|
|
68
|
+
// EmVB / pages singular under /{slug} without an explicit content hint
|
|
69
|
+
if (path !== "/" && !path.includes("/", 1)) {
|
|
70
|
+
return context(path, { kind: "singular", collection: "pages" });
|
|
71
|
+
}
|
|
72
|
+
return context(path, { kind: "other" });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function themeContextFront(): ThemeRequestContext {
|
|
76
|
+
return context("/", { isFront: true, kind: "singular" });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function themeContext404(path = "/404"): ThemeRequestContext {
|
|
80
|
+
return context(path, { is404: true, kind: "other" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function themeContextFromContent(content: ContentRef, path: string): ThemeRequestContext {
|
|
84
|
+
return themeContextFrom(new URL(path, "http://local.invalid"), { content });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function themeContextSearch(path = "/search"): ThemeRequestContext {
|
|
88
|
+
return context(path, { isSearch: true, kind: "archive" });
|
|
89
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ThemePostFields } from "../core/index.ts";
|
|
2
|
+
|
|
3
|
+
type MediaLike = {
|
|
4
|
+
src?: unknown;
|
|
5
|
+
url?: unknown;
|
|
6
|
+
previewUrl?: unknown;
|
|
7
|
+
alt?: unknown;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** Pull a sanitized-ready image URL + alt from an EmDash media / image field value. */
|
|
11
|
+
export function mediaFieldsFrom(value: unknown): {
|
|
12
|
+
featuredImageUrl?: string;
|
|
13
|
+
featuredImageAlt?: string;
|
|
14
|
+
} {
|
|
15
|
+
if (!value || typeof value !== "object") return {};
|
|
16
|
+
const media = value as MediaLike;
|
|
17
|
+
const candidates = [media.src, media.url, media.previewUrl];
|
|
18
|
+
let featuredImageUrl: string | undefined;
|
|
19
|
+
for (const candidate of candidates) {
|
|
20
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
21
|
+
featuredImageUrl = candidate.trim();
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const featuredImageAlt =
|
|
26
|
+
typeof media.alt === "string" && media.alt.trim() ? media.alt.trim() : undefined;
|
|
27
|
+
return { featuredImageUrl, featuredImageAlt };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalize an EmDash posts collection entry (or plain data bag) into ThemePostFields.
|
|
32
|
+
* Permalink defaults to `/posts/{slug}` to match the demo routes.
|
|
33
|
+
*/
|
|
34
|
+
export function themePostFromEntry(
|
|
35
|
+
entry: { id?: string; data?: Record<string, unknown> } | Record<string, unknown>,
|
|
36
|
+
options: { permalinkPrefix?: string } = {},
|
|
37
|
+
): ThemePostFields | null {
|
|
38
|
+
const data =
|
|
39
|
+
"data" in entry && entry.data && typeof entry.data === "object"
|
|
40
|
+
? (entry.data as Record<string, unknown>)
|
|
41
|
+
: (entry as Record<string, unknown>);
|
|
42
|
+
const id = String(data["id"] ?? ("id" in entry ? entry.id : "") ?? "");
|
|
43
|
+
const slug = typeof data["slug"] === "string" ? data["slug"] : id;
|
|
44
|
+
if (!slug && !id) return null;
|
|
45
|
+
const title = typeof data["title"] === "string" ? data["title"] : "";
|
|
46
|
+
const excerpt = typeof data["excerpt"] === "string" ? data["excerpt"] : "";
|
|
47
|
+
const content = data["content"] ?? "";
|
|
48
|
+
const prefix = options.permalinkPrefix ?? "/posts";
|
|
49
|
+
const permalink = `${prefix.replace(/\/$/, "")}/${slug || id}`;
|
|
50
|
+
const media = mediaFieldsFrom(data["featured_image"]);
|
|
51
|
+
const publishedAt = firstString(data, ["published_at", "publishedAt", "date"]);
|
|
52
|
+
const authorName = authorFrom(data);
|
|
53
|
+
return {
|
|
54
|
+
id: id || slug,
|
|
55
|
+
slug: slug || id,
|
|
56
|
+
title,
|
|
57
|
+
excerpt,
|
|
58
|
+
content,
|
|
59
|
+
permalink,
|
|
60
|
+
...(publishedAt ? { publishedAt } : {}),
|
|
61
|
+
...(authorName ? { authorName } : {}),
|
|
62
|
+
...media,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function firstString(data: Record<string, unknown>, keys: string[]): string | undefined {
|
|
67
|
+
for (const key of keys) {
|
|
68
|
+
const value = data[key];
|
|
69
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function authorFrom(data: Record<string, unknown>): string | undefined {
|
|
75
|
+
const direct = firstString(data, ["author_name", "authorName"]);
|
|
76
|
+
if (direct) return direct;
|
|
77
|
+
const author = data["author"];
|
|
78
|
+
if (typeof author === "string" && author.trim()) return author.trim();
|
|
79
|
+
if (author && typeof author === "object" && "name" in author) {
|
|
80
|
+
const name = (author as { name?: unknown }).name;
|
|
81
|
+
if (typeof name === "string" && name.trim()) return name.trim();
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const PLUGIN_ID = "emvb";
|
|
2
|
+
export const PLUGIN_VERSION = "0.2.0";
|
|
3
|
+
export const PACKAGE_NAME = "@perkyzz/emvb";
|
|
4
|
+
export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
|
|
5
|
+
export const PAGES_COLLECTION = "emvb_pages";
|
|
6
|
+
/** Hidden collection for Header/Footer theme parts (D-TB-03). Not public URLs. */
|
|
7
|
+
export const THEME_PARTS_COLLECTION = "emvb_theme_parts";
|
|
8
|
+
/** EDITOR in EmDash's RBAC (`packages/auth/src/rbac.ts`); EmVB is for editors and above (D-020). */
|
|
9
|
+
export const EDITOR_ROLE = 40;
|
|
10
|
+
export const DESIGN_KEY = "system";
|
|
11
|
+
/** Editor working copy. The public route keeps reading `DESIGN_KEY` (W-100). */
|
|
12
|
+
export const DESIGN_DRAFT_KEY = "draft";
|