@perkyzz/emvb 0.1.0 → 0.2.1
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 +6 -4
- 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 +9 -5
- package/src/admin/api.ts +27 -0
- package/src/admin/content-api.ts +72 -9
- package/src/admin/editor/Editor.tsx +89 -14
- package/src/admin/editor/EditorOverlay.tsx +12 -0
- package/src/admin/editor/SmallScreenNotice.tsx +4 -3
- package/src/admin/editor/TopBar.tsx +76 -12
- package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
- package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
- package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
- package/src/admin/editor/canvas/canvas-events.ts +20 -7
- package/src/admin/editor/canvas/tab-reveal.ts +66 -0
- package/src/admin/editor/canvas/vnode-react.tsx +21 -1
- package/src/admin/editor/dialogs.tsx +39 -0
- package/src/admin/editor/dnd/drop-target.ts +63 -16
- package/src/admin/editor/dnd/new-element.ts +76 -1
- package/src/admin/editor/editor-css.ts +101 -15
- 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 +7 -3
- package/src/admin/editor/panels/ClassesSection.tsx +44 -6
- package/src/admin/editor/panels/ColorControl.tsx +268 -21
- package/src/admin/editor/panels/ElementPanel.tsx +237 -93
- package/src/admin/editor/panels/LayersPanel.tsx +303 -66
- package/src/admin/editor/panels/LeftPanel.tsx +4 -0
- package/src/admin/editor/panels/PageSettings.tsx +134 -5
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
- package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
- package/src/admin/editor/panels/VariableSection.tsx +47 -9
- 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 +153 -55
- 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/ClassChipInput.tsx +104 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +25 -16
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
- package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
- package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
- package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
- package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
- 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 +5 -3
- 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 +40 -7
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/style-sections.ts +114 -11
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +3 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/shortcuts.ts +1 -1
- package/src/admin/editor/store.ts +35 -7
- package/src/admin/editor/useEditorCommands.ts +66 -5
- package/src/admin/editor/useEditorData.ts +29 -3
- package/src/admin/editor/useEditorShortcuts.ts +34 -2
- package/src/admin/editor/useNodeActions.ts +68 -6
- package/src/admin/editor/useSave.ts +60 -3
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/pages/PageList.tsx +22 -2
- package/src/admin/pages/ThemePartList.tsx +23 -4
- package/src/admin/pages/list-kit.tsx +52 -2
- package/src/admin/setup/spec.ts +7 -0
- package/src/admin/theme-api.ts +61 -14
- package/src/admin/ui.ts +17 -4
- package/src/astro/EmVBPage.astro +28 -2
- 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-definitions.ts +22 -0
- package/src/astro/index.ts +1 -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/runtime.ts +54 -4
- package/src/astro/render.ts +47 -13
- package/src/astro/resolve-theme.ts +168 -24
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +25 -5
- package/src/astro/theme-posts.ts +19 -1
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +98 -10
- package/src/core/clipboard.ts +91 -9
- package/src/core/css/generate.ts +21 -4
- package/src/core/design/classes.ts +95 -9
- package/src/core/design/transfer.ts +101 -2
- package/src/core/design/variables.ts +51 -11
- package/src/core/elements/dynamic-elements.ts +57 -5
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +23 -8
- package/src/core/elements/index.ts +267 -49
- package/src/core/elements/menu.ts +190 -0
- package/src/core/forms/definition.ts +11 -0
- package/src/core/index.ts +67 -3
- package/src/core/limits.ts +2 -0
- package/src/core/migrate/index.ts +51 -1
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +7 -0
- package/src/core/render/dynamic-post.ts +39 -11
- package/src/core/render/extras.ts +22 -3
- package/src/core/render/form.ts +134 -36
- package/src/core/render/index.ts +123 -25
- package/src/core/render/loop.ts +10 -3
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +5 -1
- package/src/core/render/tabs.ts +8 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +197 -17
- package/src/core/sanitize/embed-url.ts +64 -7
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +102 -21
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +7 -2
- package/src/core/schema/layout.ts +210 -19
- package/src/core/schema/style.ts +87 -8
- package/src/core/tabs/presence.ts +9 -0
- package/src/core/theme/conditions.ts +4 -1
- package/src/core/theme/dynamic.ts +10 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/part-types.ts +2 -0
- package/src/core/theme/popup-markup.ts +3 -1
- package/src/core/theme/popup-rules.ts +4 -3
- package/src/server/hooks.ts +20 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +5 -1
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { getEmDashCollection, getEmDashEntry } from "emdash";
|
|
1
|
+
import { getEmDashCollection, getEmDashEntry, getTerm } from "emdash";
|
|
2
2
|
import { getPublicPluginApiRouteHandler } from "emdash/plugin-utils";
|
|
3
3
|
import {
|
|
4
4
|
collectLoopItemPartIds,
|
|
5
5
|
collectSectionPartIds,
|
|
6
6
|
contentPartTypeForContext,
|
|
7
7
|
defaultConditions,
|
|
8
|
+
defaultFloatSettings,
|
|
8
9
|
defaultTriggers,
|
|
10
|
+
FLOAT_CHROME_CSS,
|
|
11
|
+
floatHasOwnSurface,
|
|
9
12
|
listMatchingThemeParts,
|
|
10
13
|
parseThemePartType,
|
|
11
14
|
pickThemePartWinner,
|
|
12
15
|
POPUP_CHROME_CSS,
|
|
13
16
|
validateConditions,
|
|
17
|
+
validateFloatSettings,
|
|
14
18
|
validateTriggers,
|
|
19
|
+
wrapFloatMarkup,
|
|
15
20
|
wrapPopupMarkup,
|
|
21
|
+
type FloatSettings,
|
|
16
22
|
type Layout,
|
|
17
23
|
type ThemeDynamicData,
|
|
18
24
|
type ThemePartCandidate,
|
|
@@ -20,11 +26,20 @@ import {
|
|
|
20
26
|
type ThemePostFields,
|
|
21
27
|
type ThemeRequestContext,
|
|
22
28
|
type TriggersDoc,
|
|
29
|
+
archivePagePath,
|
|
30
|
+
loopPerPage,
|
|
31
|
+
type ArchivePagination,
|
|
23
32
|
} from "../core/index.ts";
|
|
24
33
|
import { THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
25
34
|
import { loadDesign, readLayout, renderStored, type RenderedPage } from "./render.ts";
|
|
26
|
-
import { themeContextFrom } from "./theme-context.ts";
|
|
27
|
-
import { themePostFromEntry } from "./theme-posts.ts";
|
|
35
|
+
import { decodePathSegment, themeContextFrom } from "./theme-context.ts";
|
|
36
|
+
import { entryTimestamp, themePostFromEntry } from "./theme-posts.ts";
|
|
37
|
+
|
|
38
|
+
/** The landmark element for a part's wrapper (W-216); other parts get a plain div. */
|
|
39
|
+
const WRAPPER_TAGS: Partial<Record<string, "header" | "footer">> = {
|
|
40
|
+
header: "header",
|
|
41
|
+
footer: "footer",
|
|
42
|
+
};
|
|
28
43
|
|
|
29
44
|
export type RenderedThemePart = {
|
|
30
45
|
id: string;
|
|
@@ -42,6 +57,14 @@ export type RenderedPopup = {
|
|
|
42
57
|
triggers: TriggersDoc;
|
|
43
58
|
};
|
|
44
59
|
|
|
60
|
+
export type RenderedFloat = {
|
|
61
|
+
id: string;
|
|
62
|
+
title: string;
|
|
63
|
+
html: string;
|
|
64
|
+
css: string;
|
|
65
|
+
settings: FloatSettings;
|
|
66
|
+
};
|
|
67
|
+
|
|
45
68
|
export type ResolvedThemeParts = {
|
|
46
69
|
header: RenderedThemePart | null;
|
|
47
70
|
footer: RenderedThemePart | null;
|
|
@@ -52,12 +75,37 @@ export type ResolvedThemeParts = {
|
|
|
52
75
|
content: RenderedThemePart | null;
|
|
53
76
|
/** Matching published popups for this request (S7b). May be more than one. */
|
|
54
77
|
popups: RenderedPopup[];
|
|
78
|
+
/** Matching published floats. May be more than one. Not dialogs. */
|
|
79
|
+
floats: RenderedFloat[];
|
|
55
80
|
/** Concatenated CSS for all winners (empty when none match). */
|
|
56
81
|
css: string;
|
|
57
82
|
/** Hosts load `EmVBPopupsRuntime` only when this is true (R-031). */
|
|
58
83
|
needsPopupsRuntime: boolean;
|
|
84
|
+
/** Hosts load `EmVBFloatsRuntime` only when a float matches (R-031). */
|
|
85
|
+
needsFloatsRuntime: boolean;
|
|
59
86
|
/** Hosts load `EmVBTabsRuntime` only when Tabs appear in a winning part (R-031 / W-078). */
|
|
60
87
|
needsTabsRuntime: boolean;
|
|
88
|
+
/** Hosts load `EmVBMenuRuntime` only when a winning part has a Menu dropdown (W-197). */
|
|
89
|
+
needsMenuRuntime: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* True for an archive page past the last one (`/posts/page/9` with no posts there). Hosts
|
|
92
|
+
* answer 404 (W-221). Page 1 with no posts is not a 404.
|
|
93
|
+
*/
|
|
94
|
+
notFound: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The canonical path of an archive page: the bare archive path for page 1 (also for
|
|
97
|
+
* `/page/1`, which hosts should redirect there), else `<archive>/page/N` (W-221).
|
|
98
|
+
*/
|
|
99
|
+
canonicalPath?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The archive's title when an Archive part renders: "Posts", or the category/tag slug
|
|
102
|
+
* (W-229). Hosts build "Posts – page 2" with `archivePageTitle`.
|
|
103
|
+
*/
|
|
104
|
+
archiveTitle?: string;
|
|
105
|
+
/** The archive page number when an Archive part renders (1 for the bare URL). */
|
|
106
|
+
archivePage?: number;
|
|
107
|
+
/** The site's text direction from Site styles when a part renders, for `<html dir>` (W-230). */
|
|
108
|
+
dir?: "ltr" | "rtl" | "auto";
|
|
61
109
|
};
|
|
62
110
|
|
|
63
111
|
type AstroLike = {
|
|
@@ -73,6 +121,7 @@ type StoredPart = {
|
|
|
73
121
|
layout: unknown;
|
|
74
122
|
conditions: ReturnType<typeof defaultConditions>;
|
|
75
123
|
triggers: TriggersDoc;
|
|
124
|
+
float: FloatSettings;
|
|
76
125
|
updatedAt: string;
|
|
77
126
|
};
|
|
78
127
|
|
|
@@ -90,6 +139,9 @@ function storedPartFrom(entry: { id: string; data: unknown }): StoredPart | unde
|
|
|
90
139
|
const triggers = validateTriggers(storedOr(data["triggers"], defaultTriggers));
|
|
91
140
|
// Invalid triggers fail closed for popups; other part types ignore triggers.
|
|
92
141
|
if (partType === "popup" && !triggers.ok) return undefined;
|
|
142
|
+
const float = validateFloatSettings(storedOr(data["float"], defaultFloatSettings));
|
|
143
|
+
// Invalid float settings fail closed for floats; other part types ignore them.
|
|
144
|
+
if (partType === "float" && !float.ok) return undefined;
|
|
93
145
|
return {
|
|
94
146
|
id: String(data["id"] ?? entry.id),
|
|
95
147
|
title: typeof data["title"] === "string" ? data["title"] : "",
|
|
@@ -97,7 +149,8 @@ function storedPartFrom(entry: { id: string; data: unknown }): StoredPart | unde
|
|
|
97
149
|
layout: data["layout"],
|
|
98
150
|
conditions: conditions.conditions,
|
|
99
151
|
triggers: triggers.ok ? triggers.triggers : defaultTriggers(),
|
|
100
|
-
|
|
152
|
+
float: float.ok ? float.settings : defaultFloatSettings(),
|
|
153
|
+
updatedAt: entryTimestamp(data["updatedAt"] ?? data["updated_at"]) ?? "",
|
|
101
154
|
};
|
|
102
155
|
}
|
|
103
156
|
|
|
@@ -179,7 +232,7 @@ async function loadSingularPost(ctx: ThemeRequestContext): Promise<ThemePostFiel
|
|
|
179
232
|
const key = ctx.entryId || undefined;
|
|
180
233
|
// Prefer slug from path `/posts/{slug}` when entry id is missing.
|
|
181
234
|
const pathSlug = /^\/posts\/([^/]+)$/.exec(ctx.path)?.[1];
|
|
182
|
-
const lookup = key || (pathSlug ?
|
|
235
|
+
const lookup = key || (pathSlug ? decodePathSegment(pathSlug) : undefined);
|
|
183
236
|
if (!lookup) return undefined;
|
|
184
237
|
try {
|
|
185
238
|
const { entry } = await getEmDashEntry("posts", lookup);
|
|
@@ -190,19 +243,37 @@ async function loadSingularPost(ctx: ThemeRequestContext): Promise<ThemePostFiel
|
|
|
190
243
|
}
|
|
191
244
|
}
|
|
192
245
|
|
|
193
|
-
|
|
246
|
+
/** A taxonomy term's label for archive titles; the slug when the term can't be read (W-263). */
|
|
247
|
+
async function termLabel(taxonomy: string, slug: string): Promise<string> {
|
|
248
|
+
try {
|
|
249
|
+
const term = await getTerm(taxonomy, slug);
|
|
250
|
+
return term?.label?.trim() || slug;
|
|
251
|
+
} catch {
|
|
252
|
+
return slug;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function loadArchivePosts(
|
|
257
|
+
ctx: ThemeRequestContext,
|
|
258
|
+
perPage: number,
|
|
259
|
+
): Promise<{
|
|
194
260
|
posts: ThemePostFields[];
|
|
195
261
|
archiveTitle?: string;
|
|
262
|
+
pagination?: ArchivePagination;
|
|
196
263
|
}> {
|
|
197
264
|
if (ctx.kind !== "archive" || ctx.isSearch) return { posts: [] };
|
|
265
|
+
const page = ctx.page ?? 1;
|
|
198
266
|
try {
|
|
267
|
+
// Offset paging for numbered `/page/N` routes (W-221); EmDash reports `hasMore`.
|
|
199
268
|
const filter: {
|
|
200
269
|
orderBy: { published_at: "desc" };
|
|
201
270
|
limit: number;
|
|
271
|
+
offset?: number;
|
|
202
272
|
where?: Record<string, string>;
|
|
203
273
|
} = {
|
|
204
274
|
orderBy: { published_at: "desc" },
|
|
205
|
-
limit:
|
|
275
|
+
limit: perPage,
|
|
276
|
+
...(page > 1 ? { offset: (page - 1) * perPage } : {}),
|
|
206
277
|
};
|
|
207
278
|
if (ctx.taxonomy?.type === "category") {
|
|
208
279
|
filter.where = { category: ctx.taxonomy.slug };
|
|
@@ -211,15 +282,17 @@ async function loadArchivePosts(ctx: ThemeRequestContext): Promise<{
|
|
|
211
282
|
}
|
|
212
283
|
const result = await getEmDashCollection("posts", filter);
|
|
213
284
|
if (result.error || !result.entries) return { posts: [] };
|
|
285
|
+
const hasMore = (result as { hasMore?: boolean }).hasMore === true;
|
|
214
286
|
const posts = result.entries
|
|
215
287
|
.map((entry) => themePostFromEntry(entry))
|
|
216
288
|
.filter((p): p is ThemePostFields => p !== null);
|
|
289
|
+
// W-263: a category or tag archive is titled by its term's label ("News"), not its slug.
|
|
217
290
|
const archiveTitle = ctx.taxonomy?.slug
|
|
218
|
-
? ctx.taxonomy.slug
|
|
291
|
+
? await termLabel(ctx.taxonomy.type, ctx.taxonomy.slug)
|
|
219
292
|
: ctx.collection === "posts"
|
|
220
293
|
? "Posts"
|
|
221
294
|
: undefined;
|
|
222
|
-
return { posts, archiveTitle };
|
|
295
|
+
return { posts, archiveTitle, pagination: { page, hasMore, basePath: ctx.path } };
|
|
223
296
|
} catch {
|
|
224
297
|
return { posts: [] };
|
|
225
298
|
}
|
|
@@ -243,8 +316,8 @@ async function buildDynamicForContent(
|
|
|
243
316
|
return { ...referenced, post };
|
|
244
317
|
}
|
|
245
318
|
if (partType === "archive") {
|
|
246
|
-
const { posts, archiveTitle } = await loadArchivePosts(ctx);
|
|
247
|
-
return { ...referenced, posts, archiveTitle };
|
|
319
|
+
const { posts, archiveTitle, pagination } = await loadArchivePosts(ctx, loopPerPage(layout));
|
|
320
|
+
return { ...referenced, posts, archiveTitle, ...(pagination ? { pagination } : {}) };
|
|
248
321
|
}
|
|
249
322
|
if (Object.keys(referenced).length > 0) return referenced;
|
|
250
323
|
return undefined;
|
|
@@ -273,9 +346,16 @@ export async function resolveThemeParts(
|
|
|
273
346
|
footer: null,
|
|
274
347
|
content: null,
|
|
275
348
|
popups: [],
|
|
349
|
+
floats: [],
|
|
276
350
|
css: "",
|
|
277
351
|
needsPopupsRuntime: false,
|
|
352
|
+
needsFloatsRuntime: false,
|
|
278
353
|
needsTabsRuntime: false,
|
|
354
|
+
needsMenuRuntime: false,
|
|
355
|
+
notFound: false,
|
|
356
|
+
...(context.kind === "archive" && !context.isSearch
|
|
357
|
+
? { canonicalPath: archivePagePath(context.path, context.page ?? 1) }
|
|
358
|
+
: {}),
|
|
279
359
|
};
|
|
280
360
|
|
|
281
361
|
const parts = await loadPublishedThemeParts();
|
|
@@ -293,8 +373,15 @@ export async function resolveThemeParts(
|
|
|
293
373
|
const contentType = contentPartTypeForContext(context);
|
|
294
374
|
const contentWinner = contentType ? pickThemePartWinner(candidates, contentType, context) : null;
|
|
295
375
|
const popupMatches = listMatchingThemeParts(candidates, "popup", context);
|
|
376
|
+
const floatMatches = listMatchingThemeParts(candidates, "float", context);
|
|
296
377
|
|
|
297
|
-
if (
|
|
378
|
+
if (
|
|
379
|
+
!headerWinner &&
|
|
380
|
+
!footerWinner &&
|
|
381
|
+
!contentWinner &&
|
|
382
|
+
popupMatches.length === 0 &&
|
|
383
|
+
floatMatches.length === 0
|
|
384
|
+
) {
|
|
298
385
|
return empty;
|
|
299
386
|
}
|
|
300
387
|
|
|
@@ -306,27 +393,37 @@ export async function resolveThemeParts(
|
|
|
306
393
|
const renderOne = (stored: StoredPart, dynamic?: ThemeDynamicData) => {
|
|
307
394
|
const page = renderStored(stored.layout, design, stored.id, undefined, dynamic);
|
|
308
395
|
rendered.push(page);
|
|
396
|
+
// W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
|
|
397
|
+
// straight in <body> instead of their own <header>/<footer>).
|
|
398
|
+
const tag = WRAPPER_TAGS[stored.partType] ?? "div";
|
|
309
399
|
const html = page.html
|
|
310
|
-
?
|
|
400
|
+
? `<${tag} class="emvb-theme-${stored.partType}" data-emvb-theme-part="${stored.id}">${page.html}</${tag}>`
|
|
311
401
|
: "";
|
|
312
402
|
return { html, css: page.css };
|
|
313
403
|
};
|
|
314
404
|
|
|
405
|
+
/** Synced sections and loop items a part uses, for every part type (W-200). */
|
|
406
|
+
const templatesFor = async (stored: StoredPart): Promise<ThemeDynamicData | undefined> => {
|
|
407
|
+
const layout = readLayout(stored.layout);
|
|
408
|
+
const sectionTemplates = layout ? loadSectionTemplates(layout, parts) : {};
|
|
409
|
+
const loopTemplates = layout ? await loadLoopTemplates(layout, parts) : {};
|
|
410
|
+
return Object.keys(sectionTemplates).length > 0 || Object.keys(loopTemplates).length > 0
|
|
411
|
+
? {
|
|
412
|
+
...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
|
|
413
|
+
...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
|
|
414
|
+
}
|
|
415
|
+
: undefined;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
let pastLastPage = false;
|
|
419
|
+
let archiveInfo: { title?: string; page: number } | undefined;
|
|
315
420
|
const renderPart = async (
|
|
316
421
|
winner: ThemePartCandidate | null,
|
|
317
422
|
): Promise<RenderedThemePart | null> => {
|
|
318
423
|
const stored = winner ? byId.get(winner.id) : undefined;
|
|
319
424
|
if (!stored) return null;
|
|
320
425
|
const layout = readLayout(stored.layout);
|
|
321
|
-
const
|
|
322
|
-
const loopTemplates = layout ? await loadLoopTemplates(layout, parts) : {};
|
|
323
|
-
const referenced: ThemeDynamicData | undefined =
|
|
324
|
-
Object.keys(sectionTemplates).length > 0 || Object.keys(loopTemplates).length > 0
|
|
325
|
-
? {
|
|
326
|
-
...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
|
|
327
|
-
...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
|
|
328
|
-
}
|
|
329
|
-
: undefined;
|
|
426
|
+
const referenced = await templatesFor(stored);
|
|
330
427
|
const dynamic =
|
|
331
428
|
layout && winner === contentWinner
|
|
332
429
|
? {
|
|
@@ -334,6 +431,13 @@ export async function resolveThemeParts(
|
|
|
334
431
|
...(await buildDynamicForContent(stored.partType, context, layout, parts)),
|
|
335
432
|
}
|
|
336
433
|
: referenced;
|
|
434
|
+
// A page past the last one has no posts; the host answers 404 (W-221).
|
|
435
|
+
if (winner === contentWinner && dynamic?.pagination) {
|
|
436
|
+
archiveInfo = { title: dynamic.archiveTitle, page: dynamic.pagination.page };
|
|
437
|
+
}
|
|
438
|
+
if (winner === contentWinner && (dynamic?.pagination?.page ?? 1) > 1) {
|
|
439
|
+
pastLastPage = (dynamic?.posts ?? []).length === 0;
|
|
440
|
+
}
|
|
337
441
|
const { html, css } = renderOne(stored, dynamic);
|
|
338
442
|
return { id: stored.id, title: stored.title, partType: stored.partType, html, css };
|
|
339
443
|
};
|
|
@@ -342,11 +446,20 @@ export async function resolveThemeParts(
|
|
|
342
446
|
const footer = await renderPart(footerWinner);
|
|
343
447
|
const content = await renderPart(contentWinner);
|
|
344
448
|
|
|
449
|
+
const extraParts = [...popupMatches, ...floatMatches]
|
|
450
|
+
.map((match) => byId.get(match.id))
|
|
451
|
+
.filter((stored): stored is StoredPart => stored !== undefined);
|
|
452
|
+
const extraTemplates = new Map(
|
|
453
|
+
await Promise.all(
|
|
454
|
+
extraParts.map(async (stored) => [stored.id, await templatesFor(stored)] as const),
|
|
455
|
+
),
|
|
456
|
+
);
|
|
457
|
+
|
|
345
458
|
const popups: RenderedPopup[] = [];
|
|
346
459
|
for (const match of popupMatches) {
|
|
347
460
|
const stored = byId.get(match.id);
|
|
348
461
|
if (!stored) continue;
|
|
349
|
-
const { html, css } = renderOne(stored);
|
|
462
|
+
const { html, css } = renderOne(stored, extraTemplates.get(stored.id));
|
|
350
463
|
popups.push({
|
|
351
464
|
id: stored.id,
|
|
352
465
|
title: stored.title,
|
|
@@ -356,16 +469,47 @@ export async function resolveThemeParts(
|
|
|
356
469
|
});
|
|
357
470
|
}
|
|
358
471
|
|
|
359
|
-
const
|
|
472
|
+
const floats: RenderedFloat[] = [];
|
|
473
|
+
for (const match of floatMatches) {
|
|
474
|
+
const stored = byId.get(match.id);
|
|
475
|
+
if (!stored) continue;
|
|
476
|
+
const { html, css } = renderOne(stored, extraTemplates.get(stored.id));
|
|
477
|
+
const layout = readLayout(stored.layout);
|
|
478
|
+
const surface = !layout || !floatHasOwnSurface(layout, design);
|
|
479
|
+
floats.push({
|
|
480
|
+
id: stored.id,
|
|
481
|
+
title: stored.title,
|
|
482
|
+
html: wrapFloatMarkup(stored.id, stored.title, html, stored.float, surface),
|
|
483
|
+
css,
|
|
484
|
+
settings: stored.float,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const cssParts = [
|
|
489
|
+
header?.css,
|
|
490
|
+
content?.css,
|
|
491
|
+
footer?.css,
|
|
492
|
+
...popups.map((p) => p.css),
|
|
493
|
+
...floats.map((item) => item.css),
|
|
494
|
+
];
|
|
360
495
|
if (popups.length > 0) cssParts.push(POPUP_CHROME_CSS);
|
|
496
|
+
if (floats.length > 0) cssParts.push(FLOAT_CHROME_CSS);
|
|
361
497
|
const css = cssParts.filter(Boolean).join("\n");
|
|
362
498
|
return {
|
|
363
499
|
header,
|
|
364
500
|
footer,
|
|
365
501
|
content,
|
|
366
502
|
popups,
|
|
503
|
+
floats,
|
|
367
504
|
css,
|
|
368
505
|
needsPopupsRuntime: popups.length > 0,
|
|
506
|
+
needsFloatsRuntime: floats.length > 0,
|
|
369
507
|
needsTabsRuntime: rendered.some((page) => page.needsTabsRuntime),
|
|
508
|
+
needsMenuRuntime: rendered.some((page) => page.needsMenuRuntime),
|
|
509
|
+
notFound: pastLastPage,
|
|
510
|
+
...(design.direction ? { dir: design.direction } : {}),
|
|
511
|
+
...(archiveInfo?.title ? { archiveTitle: archiveInfo.title } : {}),
|
|
512
|
+
...(archiveInfo ? { archivePage: archiveInfo.page } : {}),
|
|
513
|
+
...(empty.canonicalPath ? { canonicalPath: empty.canonicalPath } : {}),
|
|
370
514
|
};
|
|
371
515
|
}
|
|
@@ -80,7 +80,12 @@ function enhance(root: HTMLElement): void {
|
|
|
80
80
|
const list = root.querySelector<HTMLElement>(":scope > .emvb-tab-list");
|
|
81
81
|
if (!list) return;
|
|
82
82
|
list.setAttribute("aria-orientation", "horizontal");
|
|
83
|
-
const { labels, panels } = parts(root);
|
|
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
|
+
}
|
|
84
89
|
linkTabs(root, labels, panels);
|
|
85
90
|
activate(root, selectedIndex(root));
|
|
86
91
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { splitArchivePage, type ThemeRequestContext } from "../core/index.ts";
|
|
2
2
|
|
|
3
3
|
type ContentRef = { collection: string; id: string; slug?: string | null };
|
|
4
4
|
type Kind = Pick<ThemeRequestContext, "kind">;
|
|
@@ -12,15 +12,27 @@ const context = (path: string, rest: Kind & Partial<ThemeRequestContext>): Theme
|
|
|
12
12
|
...rest,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A percent-decoded path segment, or the raw segment when its escapes are malformed (W-305), the
|
|
17
|
+
* way EmDash 1.2's `decodeSlug` stopped throwing: `/category/%E0` is a lookup that finds nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function decodePathSegment(segment: string): string {
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(segment);
|
|
22
|
+
} catch {
|
|
23
|
+
return segment;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
/** Archive URLs by pattern, and what each adds to the context. */
|
|
16
28
|
const ARCHIVES: [RegExp, (match: RegExpExecArray) => Partial<ThemeRequestContext>][] = [
|
|
17
29
|
[
|
|
18
30
|
/^\/category\/([^/]+)$/,
|
|
19
|
-
([, slug]) => ({ taxonomy: { type: "category", slug:
|
|
31
|
+
([, slug]) => ({ taxonomy: { type: "category", slug: decodePathSegment(slug ?? "") } }),
|
|
20
32
|
],
|
|
21
33
|
[
|
|
22
34
|
/^\/tag\/([^/]+)$/,
|
|
23
|
-
([, slug]) => ({ taxonomy: { type: "tag", slug:
|
|
35
|
+
([, slug]) => ({ taxonomy: { type: "tag", slug: decodePathSegment(slug ?? "") } }),
|
|
24
36
|
],
|
|
25
37
|
[/^\/posts$/, () => ({ collection: "posts" })],
|
|
26
38
|
];
|
|
@@ -50,9 +62,17 @@ export function themeContextFrom(
|
|
|
50
62
|
});
|
|
51
63
|
}
|
|
52
64
|
if (options.isSearch === true || path === "/search") return themeContextSearch(path);
|
|
65
|
+
// `/posts/page/2` is page 2 of the `/posts` archive; conditions see `/posts` (W-221).
|
|
66
|
+
const paged = splitArchivePage(path);
|
|
53
67
|
for (const [pattern, extra] of ARCHIVES) {
|
|
54
|
-
const match = pattern.exec(
|
|
55
|
-
if (match
|
|
68
|
+
const match = paged ? pattern.exec(paged.basePath) : null;
|
|
69
|
+
if (match && paged) {
|
|
70
|
+
return context(paged.basePath, {
|
|
71
|
+
kind: "archive",
|
|
72
|
+
...extra(match),
|
|
73
|
+
...(paged.page > 1 || paged.basePath !== path ? { page: paged.page } : {}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
56
76
|
}
|
|
57
77
|
if (content) {
|
|
58
78
|
return context(path, { kind: "singular", collection: content.collection, entryId: content.id });
|
package/src/astro/theme-posts.ts
CHANGED
|
@@ -27,6 +27,15 @@ export function mediaFieldsFrom(value: unknown): {
|
|
|
27
27
|
return { featuredImageUrl, featuredImageAlt };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* An entry timestamp as an ISO string (W-302). EmDash hands system dates (`updatedAt`,
|
|
32
|
+
* `publishedAt`) to templates as `Date` objects, so `String()` gave "Sun Sep 06 2026 …".
|
|
33
|
+
*/
|
|
34
|
+
export function entryTimestamp(value: unknown): string | undefined {
|
|
35
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? undefined : value.toISOString();
|
|
36
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
/**
|
|
31
40
|
* Normalize an EmDash posts collection entry (or plain data bag) into ThemePostFields.
|
|
32
41
|
* Permalink defaults to `/posts/{slug}` to match the demo routes.
|
|
@@ -48,7 +57,10 @@ export function themePostFromEntry(
|
|
|
48
57
|
const prefix = options.permalinkPrefix ?? "/posts";
|
|
49
58
|
const permalink = `${prefix.replace(/\/$/, "")}/${slug || id}`;
|
|
50
59
|
const media = mediaFieldsFrom(data["featured_image"]);
|
|
51
|
-
|
|
60
|
+
// W-303: EmDash's own publish date is `data.publishedAt`, a `Date`; a custom field may be text.
|
|
61
|
+
const publishedAt = ["published_at", "publishedAt", "date"]
|
|
62
|
+
.map((key) => entryTimestamp(data[key]))
|
|
63
|
+
.find(Boolean);
|
|
52
64
|
const authorName = authorFrom(data);
|
|
53
65
|
return {
|
|
54
66
|
id: id || slug,
|
|
@@ -80,5 +92,11 @@ function authorFrom(data: Record<string, unknown>): string | undefined {
|
|
|
80
92
|
const name = (author as { name?: unknown }).name;
|
|
81
93
|
if (typeof name === "string" && name.trim()) return name.trim();
|
|
82
94
|
}
|
|
95
|
+
// W-304: EmDash hydrates the primary byline onto `data.byline` (a BylineSummary).
|
|
96
|
+
const byline = data["byline"];
|
|
97
|
+
if (byline && typeof byline === "object" && "displayName" in byline) {
|
|
98
|
+
const name = (byline as { displayName?: unknown }).displayName;
|
|
99
|
+
if (typeof name === "string" && name.trim()) return name.trim();
|
|
100
|
+
}
|
|
83
101
|
return undefined;
|
|
84
102
|
}
|
package/src/constants.ts
CHANGED
package/src/core/arrange.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_DEPTH, MAX_NODES } from "./limits.ts";
|
|
1
|
+
import { MAX_DEPTH, MAX_NODES, MAX_TABS } from "./limits.ts";
|
|
2
2
|
import {
|
|
3
3
|
isContainerNode,
|
|
4
4
|
isFormFieldType,
|
|
@@ -23,7 +23,8 @@ import {
|
|
|
23
23
|
|
|
24
24
|
/** A refused operation, with the reason shown or announced to the user (R-003). */
|
|
25
25
|
export type Refusal = { ok: false; reason: string };
|
|
26
|
-
|
|
26
|
+
/** `note`, when set, is announced after the change (W-133: a CSS id left on the original). */
|
|
27
|
+
export type Arranged = { ok: true; layout: Layout; selected: string; note?: string } | Refusal;
|
|
27
28
|
export type Allowed = { ok: true } | Refusal;
|
|
28
29
|
|
|
29
30
|
/** What is being dropped: an element already on the page, or a new one from the Add panel. */
|
|
@@ -48,6 +49,7 @@ export const REASONS = {
|
|
|
48
49
|
missing: "That element is no longer on the page.",
|
|
49
50
|
tooDeep: `Elements can be nested at most ${MAX_DEPTH} levels deep.`,
|
|
50
51
|
tooMany: `A page can have at most ${MAX_NODES} elements.`,
|
|
52
|
+
tooManyTabs: `Tabs can show up to ${MAX_TABS} tabs.`,
|
|
51
53
|
first: "It's already first in its container.",
|
|
52
54
|
last: "It's already last in its container.",
|
|
53
55
|
top: "It's already at the top level.",
|
|
@@ -59,12 +61,12 @@ export const REASONS = {
|
|
|
59
61
|
onlyTabPanels: "Tabs can only hold tab panels.",
|
|
60
62
|
itemOutsideAccordion: "Accordion items can only go inside an Accordion.",
|
|
61
63
|
onlyAccordionItems: "An accordion can only hold accordion items.",
|
|
64
|
+
itemOutsideMenu: "Menu items can only go inside a Menu.",
|
|
65
|
+
onlyMenuItems: "A menu can only hold menu items.",
|
|
62
66
|
} as const;
|
|
63
67
|
|
|
64
68
|
const refuse = (reason: string): Refusal => ({ ok: false, reason });
|
|
65
69
|
|
|
66
|
-
const isContainer = (node: LayoutNode): node is ContainerNode => node.type === "container";
|
|
67
|
-
|
|
68
70
|
function locate(layout: Layout, id: string): Located | undefined {
|
|
69
71
|
const walk = (
|
|
70
72
|
node: LayoutNode,
|
|
@@ -134,6 +136,15 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
|
|
|
134
136
|
({ node, into }) => into.node.type === "accordion" && node.type !== "accordion-item",
|
|
135
137
|
REASONS.onlyAccordionItems,
|
|
136
138
|
],
|
|
139
|
+
[
|
|
140
|
+
({ node, into }) =>
|
|
141
|
+
node.type === "menu-item" && into.node.type !== "menu" && into.node.type !== "menu-item",
|
|
142
|
+
REASONS.itemOutsideMenu,
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
({ node, into }) => into.node.type === "menu" && node.type !== "menu-item",
|
|
146
|
+
REASONS.onlyMenuItems,
|
|
147
|
+
],
|
|
137
148
|
[
|
|
138
149
|
({ node, into, layout }) => isFormNode(node) && underForm(layout, into.node.id),
|
|
139
150
|
REASONS.nestedForm,
|
|
@@ -143,6 +154,14 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
|
|
|
143
154
|
({ node, into, layout }) => isFormFieldType(node.type) && !underForm(layout, into.node.id),
|
|
144
155
|
REASONS.fieldOutsideForm,
|
|
145
156
|
],
|
|
157
|
+
// A 13th panel would be stored but never shown (W-188); moving within the same Tabs is fine.
|
|
158
|
+
[
|
|
159
|
+
({ node, into }) =>
|
|
160
|
+
into.node.type === "tabs" &&
|
|
161
|
+
!nodeChildren(into.node).some((child) => child.id === node.id) &&
|
|
162
|
+
nodeChildren(into.node).length >= MAX_TABS,
|
|
163
|
+
REASONS.tooManyTabs,
|
|
164
|
+
],
|
|
146
165
|
[({ node, into }) => into.depth + height(node) > MAX_DEPTH, REASONS.tooDeep],
|
|
147
166
|
[
|
|
148
167
|
({ node, layout, isNew }) => isNew && size(layout.root) + size(node) > MAX_NODES,
|
|
@@ -240,7 +259,28 @@ export function layoutFromPageTemplate(source: Layout, random: () => number = Ma
|
|
|
240
259
|
return { schemaVersion: LAYOUT_SCHEMA_VERSION, root };
|
|
241
260
|
}
|
|
242
261
|
|
|
243
|
-
/**
|
|
262
|
+
/** Announced when a duplicate leaves its CSS ids on the original (W-133). */
|
|
263
|
+
export const CSS_ID_KEPT = "The CSS id stays on the original: CSS ids must be unique on the page.";
|
|
264
|
+
|
|
265
|
+
/** `node` without the CSS id on it or any descendant; returns how many it dropped. */
|
|
266
|
+
function withoutHtmlIds(node: LayoutNode): { node: LayoutNode; dropped: number } {
|
|
267
|
+
let dropped = node.htmlId ? 1 : 0;
|
|
268
|
+
const { htmlId: _htmlId, ...rest } = node;
|
|
269
|
+
const kids = nodeChildren(node);
|
|
270
|
+
if (kids.length === 0) return { node: rest as LayoutNode, dropped };
|
|
271
|
+
const children = kids.map((child) => {
|
|
272
|
+
const cleaned = withoutHtmlIds(child);
|
|
273
|
+
dropped += cleaned.dropped;
|
|
274
|
+
return cleaned.node;
|
|
275
|
+
});
|
|
276
|
+
return { node: { ...rest, children } as LayoutNode, dropped };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* A deep copy with new unique ids, inserted right after the original and selected. CSS ids stay
|
|
281
|
+
* on the original: a copied one made the page fail to save, so edits to the copy never reached
|
|
282
|
+
* the site (W-133).
|
|
283
|
+
*/
|
|
244
284
|
export function duplicateNode(
|
|
245
285
|
layout: Layout,
|
|
246
286
|
id: string,
|
|
@@ -250,11 +290,17 @@ export function duplicateNode(
|
|
|
250
290
|
if (!found) return refuse(REASONS.missing);
|
|
251
291
|
if (!found.parent) return refuse(REASONS.rootCopy);
|
|
252
292
|
if (size(layout.root) + size(found.node) > MAX_NODES) return refuse(REASONS.tooMany);
|
|
253
|
-
|
|
293
|
+
if (found.parent.type === "tabs" && nodeChildren(found.parent).length >= MAX_TABS) {
|
|
294
|
+
return refuse(REASONS.tooManyTabs);
|
|
295
|
+
}
|
|
296
|
+
const { node: copy, dropped } = withoutHtmlIds(
|
|
297
|
+
withNewIds(found.node, allIds(layout.root), random),
|
|
298
|
+
);
|
|
254
299
|
return {
|
|
255
300
|
ok: true,
|
|
256
301
|
layout: insertNode(layout, found.parent.id, found.index + 1, copy),
|
|
257
302
|
selected: copy.id,
|
|
303
|
+
...(dropped > 0 ? { note: CSS_ID_KEPT } : {}),
|
|
258
304
|
};
|
|
259
305
|
}
|
|
260
306
|
|
|
@@ -267,6 +313,42 @@ export function insertionPoint(layout: Layout, selectedId: string | null): Place
|
|
|
267
313
|
return { parentId: layout.root.id, index: layout.root.children.length };
|
|
268
314
|
}
|
|
269
315
|
|
|
316
|
+
/** Where an Add-panel element went. `after` and `refused` are set when it fell back (W-175). */
|
|
317
|
+
export type Added = {
|
|
318
|
+
ok: true;
|
|
319
|
+
layout: Layout;
|
|
320
|
+
selected: string;
|
|
321
|
+
parentId: string;
|
|
322
|
+
fallback?: { after: string; refused: string };
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Adds a new element where `insertionPoint` says. When that place refuses it, the element goes
|
|
327
|
+
* right after the nearest ancestor of that place whose own parent takes it, and `fallback` keeps
|
|
328
|
+
* the first reason so the editor can say where it went and why (W-175). Refused only when no
|
|
329
|
+
* ancestor can take it (a form field with no form on the way up, say).
|
|
330
|
+
*/
|
|
331
|
+
export function addNodeNear(
|
|
332
|
+
layout: Layout,
|
|
333
|
+
node: LayoutNode,
|
|
334
|
+
selectedId: string | null,
|
|
335
|
+
): Added | Refusal {
|
|
336
|
+
const first = insertionPoint(layout, selectedId);
|
|
337
|
+
const tried = addNode(layout, node, first);
|
|
338
|
+
if (tried.ok) return { ...tried, parentId: first.parentId };
|
|
339
|
+
let refusing = locate(layout, first.parentId);
|
|
340
|
+
while (refusing?.parent) {
|
|
341
|
+
const place = { parentId: refusing.parent.id, index: refusing.index + 1 };
|
|
342
|
+
const next = addNode(layout, node, place);
|
|
343
|
+
if (next.ok) {
|
|
344
|
+
const fallback = { after: refusing.node.id, refused: tried.reason };
|
|
345
|
+
return { ...next, parentId: place.parentId, fallback };
|
|
346
|
+
}
|
|
347
|
+
refusing = locate(layout, refusing.parent.id);
|
|
348
|
+
}
|
|
349
|
+
return tried;
|
|
350
|
+
}
|
|
351
|
+
|
|
270
352
|
type Child = Located & { parent: NonNullable<Located["parent"]> };
|
|
271
353
|
|
|
272
354
|
/** Moves a non-root element to where `place` says, or returns the first refusal. */
|
|
@@ -305,8 +387,12 @@ export const moveOut = (layout: Layout, id: string): Arranged =>
|
|
|
305
387
|
export const moveIn = (layout: Layout, id: string): Arranged =>
|
|
306
388
|
moveChild(layout, id, ({ parent, index }) => {
|
|
307
389
|
const above = parent.children[index - 1];
|
|
308
|
-
|
|
309
|
-
|
|
390
|
+
// W-211: any element that holds children (Flexbox, Grid, Form, Accordion item…), not only a
|
|
391
|
+
// Container; moveNode refuses what can't go there, with the reason.
|
|
392
|
+
const kids =
|
|
393
|
+
above && "children" in above && Array.isArray(above.children) ? above.children : null;
|
|
394
|
+
return above && kids
|
|
395
|
+
? { parentId: above.id, index: kids.length }
|
|
310
396
|
: refuse(REASONS.noContainerAbove);
|
|
311
397
|
});
|
|
312
398
|
|
|
@@ -334,10 +420,12 @@ export function previousInOrder(layout: Layout, id: string): string {
|
|
|
334
420
|
return at === -1 ? layout.root.id : (ids[at - 1] ?? id);
|
|
335
421
|
}
|
|
336
422
|
|
|
337
|
-
/** Enter: the first child of
|
|
423
|
+
/** Enter: the first child of any element that holds children, if it has one (W-211). */
|
|
338
424
|
export function firstChild(layout: Layout, id: string): string | undefined {
|
|
339
425
|
const node = findNode(layout, id);
|
|
340
|
-
return node &&
|
|
426
|
+
return node && "children" in node && Array.isArray(node.children)
|
|
427
|
+
? node.children[0]?.id
|
|
428
|
+
: undefined;
|
|
341
429
|
}
|
|
342
430
|
|
|
343
431
|
/** Shift+Enter: the parent container, if any. */
|