@eldrajs/vite-plugin-theme 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/{scan-ClxSvaDL.js → scan-DBOHDmAQ.js} +162 -20
- package/dist/scan.d.ts +1 -1
- package/dist/scan.js +1 -1
- package/dist/{types-Zt7J0J6v.d.ts → types-Dej7h4ZU.d.ts} +73 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,28 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- **A theme can declare its menu as an object: `metadata.tree` takes depth, sections and cards
|
|
9
|
+
(WS-1312).** `tree` on a `link` field is now `boolean | EldraLinkTree` (new types `EldraLinkTree`,
|
|
10
|
+
`EldraLinkTreeSections`, `EldraLinkTreeCards`, Core's own JSON keys). The scanner refuses exactly
|
|
11
|
+
what Core's manifest ingest refuses: a depth other than 1 or 2, `sections` or `cards` at depth 1,
|
|
12
|
+
a `max` below 1, a malformed `aspect`, `cards.kinds` outside the field's `kinds`, a cards
|
|
13
|
+
declaration that allows page, entry, url or category without `customImage`, and `cards` anywhere
|
|
14
|
+
but a top-level link or a top-level list's link item. It also stops refusing `tree` on a top-level
|
|
15
|
+
link or a composite child, which Core accepts (`groupsToSections` supports a top-level link or a
|
|
16
|
+
list of links, never a composite child). See
|
|
17
|
+
`docs/themes.md`, "Declaring a menu".
|
|
18
|
+
|
|
19
|
+
- **`migrations[].groupsToSections`: grouped menu children become sections (WS-1318).** A step may
|
|
20
|
+
declare `groupsToSections: [{ "field": "links" }]` (at most 16, `field` the only key) to turn a link
|
|
21
|
+
field's rows' children, grouped by their `group` text, into `sections` on deploy. The scanner
|
|
22
|
+
refuses a field that is missing, is not a `link` or a `list` of links, does not declare
|
|
23
|
+
`tree.sections`, or is converted twice, and a step now has to declare `renames`, `convertToLink`
|
|
24
|
+
or `groupsToSections`. New type `BlockMigrationGroupsToSections`. Needs a Core that accepts the
|
|
25
|
+
step; `convertToLink` in the same deploy runs first. See `docs/theme-field-migrations.md`.
|
|
26
|
+
- **`capabilities` (WS-1303).** `EldraThemeOptions.capabilities` (set by a framework wrapper) puts
|
|
27
|
+
`capabilities: { draftPreview: 1 }` in the manifest; an unknown capability or version is an error.
|
|
28
|
+
Absent when none is declared, so today's manifests are unchanged.
|
|
29
|
+
|
|
8
30
|
- **`formSeeds[].actions.subscribe.consentText` (WS-386).** A subscribe action may carry its consent
|
|
9
31
|
sentence per locale (`{ 'en-US': '… {shop} …' }`), validated like Core: locale tags, at most 500
|
|
10
32
|
characters each, plain text (no `<`, `>` or control characters), at least one locale when the key is
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as PageSeedTarget, B as ThemeMessages, C as ManifestPageSeedBlock, D as ManifestTemplateRoles, E as ManifestRoute, F as TemplateSeedLayoutNode, I as TemplateSeedReusableNode, L as TemplateSeedSchemaApiId, M as ScanResult, N as TemplateSeedBlockNode, O as ManifestTemplateSeed, P as TemplateSeedLayout, R as ThemeManifest, S as ManifestPageSeed, T as ManifestPageSeedRegion, _ as EldraThemeOptions, a as DeclaredFormSeed, b as ManifestFormSeedField, c as DeclaredPageSeedEntry, d as DeclaredTemplateSeed, f as DeclaredTemplateSeedBlock, g as EldraLinkTreeSections, h as EldraLinkTreeCards, i as BlockMigrationGroupsToSections, j as ScanOptions, k as ManifestTemplateSeedBlock, l as DeclaredPageSeedRegion, m as EldraLinkTree, n as BlockField, o as DeclaredPageSeed, p as DeclaredThemeCodePage, r as BlockMigration, s as DeclaredPageSeedBlock, t as BlockDefinition, u as DeclaredSeed, v as LegacyThemeTokens, w as ManifestPageSeedEntry, x as ManifestFormSeedFieldType, y as ManifestFormSeed, z as ThemeManifestCapabilities } from "./types-Dej7h4ZU.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
export default function eldraTheme(options?: EldraThemeOptions): Plugin;
|
|
4
4
|
export declare function generateBlockTypes(blocks: BlockDefinition[], messages?: ThemeMessages): string;
|
|
@@ -76,4 +76,4 @@ export declare function validatePageSeeds(seeds: ReadonlyArray<DeclaredSeed>, bl
|
|
|
76
76
|
* it, so Core is never handed a template it cannot seed a site with.
|
|
77
77
|
*/
|
|
78
78
|
export declare function validateTemplateRoles(roles: ManifestTemplateRoles | undefined, blocks: ReadonlyArray<Record<string, unknown>>, templates: ReadonlyArray<ManifestTemplateSeed>, errors: string[]): ManifestTemplateRoles | undefined;
|
|
79
|
-
export type { BlockDefinition, BlockField, BlockMigration, DeclaredFormSeed, DeclaredPageSeed, DeclaredPageSeedBlock, DeclaredPageSeedEntry, DeclaredPageSeedRegion, DeclaredSeed, DeclaredTemplateSeed, DeclaredTemplateSeedBlock, DeclaredThemeCodePage, EldraThemeOptions, LegacyThemeTokens, ManifestFormSeed, ManifestFormSeedField, ManifestFormSeedFieldType, ManifestPageSeed, ManifestPageSeedBlock, ManifestPageSeedEntry, ManifestPageSeedRegion, ManifestRoute, ManifestTemplateRoles, ManifestTemplateSeed, ManifestTemplateSeedBlock, PageSeedTarget, ScanOptions, ScanResult, TemplateSeedBlockNode, TemplateSeedLayout, TemplateSeedLayoutNode, TemplateSeedReusableNode, TemplateSeedSchemaApiId, ThemeManifest, ThemeMessages };
|
|
79
|
+
export type { BlockDefinition, BlockField, BlockMigration, BlockMigrationGroupsToSections, DeclaredFormSeed, DeclaredPageSeed, DeclaredPageSeedBlock, DeclaredPageSeedEntry, DeclaredPageSeedRegion, DeclaredSeed, DeclaredTemplateSeed, DeclaredTemplateSeedBlock, DeclaredThemeCodePage, EldraLinkTree, EldraLinkTreeCards, EldraLinkTreeSections, EldraThemeOptions, LegacyThemeTokens, ManifestFormSeed, ManifestFormSeedField, ManifestFormSeedFieldType, ManifestPageSeed, ManifestPageSeedBlock, ManifestPageSeedEntry, ManifestPageSeedRegion, ManifestRoute, ManifestTemplateRoles, ManifestTemplateSeed, ManifestTemplateSeedBlock, PageSeedTarget, ScanOptions, ScanResult, TemplateSeedBlockNode, TemplateSeedLayout, TemplateSeedLayoutNode, TemplateSeedReusableNode, TemplateSeedSchemaApiId, ThemeManifest, ThemeManifestCapabilities, ThemeMessages };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, s as validateFormSeeds, t as readPreviousManifest } from "./scan-
|
|
1
|
+
import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, s as validateFormSeeds, t as readPreviousManifest } from "./scan-DBOHDmAQ.js";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { generateDesignTokenCss, generateTailwindThemeCss, normalizeThemeDesignTokens } from "@eldrajs/theme-core/design-tokens";
|
|
@@ -249,7 +249,8 @@ function eldraTheme(options = {}) {
|
|
|
249
249
|
templates: options.templates,
|
|
250
250
|
templateRoles: options.templateRoles,
|
|
251
251
|
formSeeds: options.formSeeds,
|
|
252
|
-
breakpoints: options.breakpoints
|
|
252
|
+
breakpoints: options.breakpoints,
|
|
253
|
+
capabilities: options.capabilities
|
|
253
254
|
});
|
|
254
255
|
scan.errors.unshift(...historyErrors);
|
|
255
256
|
if (scan.errors.length > 0 || scan.manifest === null) {
|
|
@@ -110,6 +110,19 @@ const blockJsonSchema = {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
+
groupsToSections: {
|
|
114
|
+
type: "array",
|
|
115
|
+
maxItems: 16,
|
|
116
|
+
items: {
|
|
117
|
+
type: "object",
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
required: ["field"],
|
|
120
|
+
properties: { field: {
|
|
121
|
+
type: "string",
|
|
122
|
+
pattern: FIELD_ID_PATTERN$1
|
|
123
|
+
} }
|
|
124
|
+
}
|
|
125
|
+
},
|
|
113
126
|
convertToLink: {
|
|
114
127
|
type: "array",
|
|
115
128
|
maxItems: 16,
|
|
@@ -329,6 +342,7 @@ const STORED_RELATION_KEYS = [
|
|
|
329
342
|
function migrationChecks(file, block, previous, errors) {
|
|
330
343
|
const next = new Map(block.fields.map((field) => [field.fieldId, field]));
|
|
331
344
|
const versions = /* @__PURE__ */ new Set();
|
|
345
|
+
const groupedFields = /* @__PURE__ */ new Set();
|
|
332
346
|
for (const [index, step] of (block.migrations ?? []).entries()) {
|
|
333
347
|
const at = `${file}: migrations[${index}]`;
|
|
334
348
|
if (step.version > block.version) errors.push(`${at}.version — must be a block version bump`);
|
|
@@ -336,7 +350,8 @@ function migrationChecks(file, block, previous, errors) {
|
|
|
336
350
|
versions.add(step.version);
|
|
337
351
|
const renames = step.renames ?? [];
|
|
338
352
|
const conversions = step.convertToLink ?? [];
|
|
339
|
-
if (step.renames === void 0 && step.convertToLink === void 0) errors.push(`${at} — a migration step must declare renames or
|
|
353
|
+
if (step.renames === void 0 && step.convertToLink === void 0 && step.groupsToSections === void 0) errors.push(`${at} — a migration step must declare renames, convertToLink or groupsToSections`);
|
|
354
|
+
checkGroupsToSections(at, step.groupsToSections ?? [], next, groupedFields, errors);
|
|
340
355
|
const conversionTargets = /* @__PURE__ */ new Set();
|
|
341
356
|
for (const conversion of conversions) {
|
|
342
357
|
checkConversionTarget(at, conversion, next, errors);
|
|
@@ -383,6 +398,30 @@ function migrationChecks(file, block, previous, errors) {
|
|
|
383
398
|
requireVersionBumpForRetirement(file, block, previous, old, next, errors);
|
|
384
399
|
}
|
|
385
400
|
/**
|
|
401
|
+
* What a `groupsToSections` step must be true of in the *incoming* fields: it
|
|
402
|
+
* names a link field, or a list of links, and that link declares
|
|
403
|
+
* `tree.sections`, so the sections the step writes are ones the field then
|
|
404
|
+
* accepts on every save. Core re-checks the same rules at ingest.
|
|
405
|
+
*/
|
|
406
|
+
function checkGroupsToSections(at, steps, next, seen, errors) {
|
|
407
|
+
for (const { field: fieldId } of steps) {
|
|
408
|
+
const target = next.get(fieldId);
|
|
409
|
+
if (target === void 0) {
|
|
410
|
+
errors.push(`${at} — groupsToSections field "${fieldId}" does not exist in incoming fields`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const link = target.type === "list" ? listItem(target) : target;
|
|
414
|
+
if (link === null || link.type !== "link") {
|
|
415
|
+
errors.push(`${at} — groupsToSections field "${fieldId}" must be a link field or a list of links`);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
const tree = link.metadata?.tree;
|
|
419
|
+
if (!isRecord$1(tree) || !isRecord$1(tree.sections)) errors.push(`${at} — groupsToSections field "${fieldId}" must declare tree.sections`);
|
|
420
|
+
if (seen.has(fieldId)) errors.push(`${at} — groupsToSections fields must be unique; one field cannot be converted twice`);
|
|
421
|
+
seen.add(fieldId);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
386
425
|
* What a conversion must be true of in the *incoming* fields: it writes a link,
|
|
387
426
|
* so `to` has to be one — or, for `shape: "list"`, a list whose item is one.
|
|
388
427
|
* Checked without any history, because it is a statement about the block being
|
|
@@ -641,7 +680,7 @@ const REFERENCE_RELATION_MESSAGE = "a {_type: \"collection\", slug} seed referen
|
|
|
641
680
|
* `reference` field's own seed grammar stays collection-only. */
|
|
642
681
|
const LINK_SLUG_KEYS = /* @__PURE__ */ new Set(["_type", "slug"]);
|
|
643
682
|
const LINK_SLUG_TYPES = /* @__PURE__ */ new Set(["product", "collection"]);
|
|
644
|
-
const LINK_KINDS = /* @__PURE__ */ new Set([
|
|
683
|
+
const LINK_KINDS$1 = /* @__PURE__ */ new Set([
|
|
645
684
|
"product",
|
|
646
685
|
"collection",
|
|
647
686
|
"category",
|
|
@@ -792,7 +831,7 @@ function checkLinkValue(format, path, value, errors, isChild = false) {
|
|
|
792
831
|
return;
|
|
793
832
|
}
|
|
794
833
|
const kind = typeof value.kind === "string" ? value.kind.trim() : "";
|
|
795
|
-
if (!LINK_KINDS.has(kind)) {
|
|
834
|
+
if (!LINK_KINDS$1.has(kind)) {
|
|
796
835
|
errors.push(format(path, LINK_MESSAGE));
|
|
797
836
|
return;
|
|
798
837
|
}
|
|
@@ -1748,7 +1787,10 @@ const SEMVER_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-
|
|
|
1748
1787
|
const SLOT_ID_PATTERN = /^[a-z][a-z0-9-]{0,47}$/;
|
|
1749
1788
|
const SLOT_CONTROL_CHARS = /[\p{Cc}\p{Cf}]/gu;
|
|
1750
1789
|
const RICH_TEXT_TOOLBAR_CONTROL_SET = new Set(RICH_TEXT_TOOLBAR_CONTROLS);
|
|
1751
|
-
|
|
1790
|
+
/** What a `link` value may be — six destinations plus `none`, the heading that
|
|
1791
|
+
* groups the links under it and goes nowhere itself. Core validates a stored
|
|
1792
|
+
* value against the same set. */
|
|
1793
|
+
const LINK_KINDS = [
|
|
1752
1794
|
"product",
|
|
1753
1795
|
"collection",
|
|
1754
1796
|
"category",
|
|
@@ -1756,7 +1798,8 @@ const LINK_KIND_SET = /* @__PURE__ */ new Set([
|
|
|
1756
1798
|
"page",
|
|
1757
1799
|
"url",
|
|
1758
1800
|
"none"
|
|
1759
|
-
]
|
|
1801
|
+
];
|
|
1802
|
+
const LINK_KIND_SET = new Set(LINK_KINDS);
|
|
1760
1803
|
/** The three metadata keys Core's `link` field type declares, and therefore
|
|
1761
1804
|
* the whole surface a block.json may carry on one. */
|
|
1762
1805
|
const LINK_METADATA_KEYS = [
|
|
@@ -1779,6 +1822,24 @@ const validateBlockJson = new Ajv({
|
|
|
1779
1822
|
allErrors: true,
|
|
1780
1823
|
allowUnionTypes: true
|
|
1781
1824
|
}).compile(blockJsonSchema);
|
|
1825
|
+
/** Every capability this version knows, at the version it knows. */
|
|
1826
|
+
const THEME_MANIFEST_CAPABILITIES = { draftPreview: 1 };
|
|
1827
|
+
/**
|
|
1828
|
+
* The runtime's declared capabilities, as the manifest carries them: absent when there are none,
|
|
1829
|
+
* and only the ones this version knows, at the version it knows. Anything else is an error rather
|
|
1830
|
+
* than something Studio would be told the theme can do.
|
|
1831
|
+
*/
|
|
1832
|
+
function validateCapabilities(capabilities, errors) {
|
|
1833
|
+
if (capabilities === void 0) return {};
|
|
1834
|
+
const declared = {};
|
|
1835
|
+
for (const [name, version] of Object.entries(capabilities)) {
|
|
1836
|
+
if (version === void 0) continue;
|
|
1837
|
+
if (!Object.hasOwn(THEME_MANIFEST_CAPABILITIES, name)) errors.push(`capabilities: unknown capability "${name}"`);
|
|
1838
|
+
else if (version !== THEME_MANIFEST_CAPABILITIES[name]) errors.push(`capabilities.${name}: unsupported version ${JSON.stringify(version)}`);
|
|
1839
|
+
else declared[name] = 1;
|
|
1840
|
+
}
|
|
1841
|
+
return Object.keys(declared).length === 0 ? {} : { capabilities: declared };
|
|
1842
|
+
}
|
|
1782
1843
|
function scanTheme(opts) {
|
|
1783
1844
|
const themeDir = opts.themeDir;
|
|
1784
1845
|
const blocksDir = join(themeDir, "blocks");
|
|
@@ -1871,7 +1932,8 @@ function scanTheme(opts) {
|
|
|
1871
1932
|
...pageSeeds.length === 0 ? {} : { pageSeeds },
|
|
1872
1933
|
...formSeeds.length === 0 ? {} : { formSeeds },
|
|
1873
1934
|
tokens: readTokens(themeDir, errors),
|
|
1874
|
-
...messages === void 0 ? {} : { messages }
|
|
1935
|
+
...messages === void 0 ? {} : { messages },
|
|
1936
|
+
...validateCapabilities(opts.capabilities, errors)
|
|
1875
1937
|
};
|
|
1876
1938
|
const breakpoints = resolveLayoutBreakpoints(opts.breakpoints);
|
|
1877
1939
|
if (!/^[a-z][a-z0-9-]{1,48}$/.test(manifest.theme.name)) errors.push("package.json: name — cannot be sanitized to a valid theme name");
|
|
@@ -2097,7 +2159,7 @@ function semanticChecks(file, block, errors) {
|
|
|
2097
2159
|
});
|
|
2098
2160
|
if (titleCount > 1) errors.push(`${file}: fields — at most one field may set isTitle (found ${titleCount})`);
|
|
2099
2161
|
checkFieldSetVisibility(file, fields, "fields", errors);
|
|
2100
|
-
checkLinkFieldSet(file, fields, "fields",
|
|
2162
|
+
checkLinkFieldSet(file, fields, "fields", "top", errors);
|
|
2101
2163
|
const slots = Array.isArray(block.slots) ? block.slots : [];
|
|
2102
2164
|
const slotIds = /* @__PURE__ */ new Set();
|
|
2103
2165
|
for (const [index, slot] of slots.entries()) {
|
|
@@ -2116,24 +2178,23 @@ function semanticChecks(file, block, errors) {
|
|
|
2116
2178
|
*
|
|
2117
2179
|
* Three metadata keys belong to `link` and to nothing else, so a block that
|
|
2118
2180
|
* puts `kinds` on a string field learns that here rather than from Core's
|
|
2119
|
-
* ingest. `tree`
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
2122
|
-
* `allowedSchemas` and `item` and refuses every other metadata key.
|
|
2181
|
+
* ingest. `tree` is declared on the link itself (a `list` can carry only
|
|
2182
|
+
* `allowedSchemas` and `item`), as `true` or as a declaration object; see
|
|
2183
|
+
* `checkLinkTree`.
|
|
2123
2184
|
*/
|
|
2124
|
-
function checkLinkFieldSet(file, fields, path,
|
|
2185
|
+
function checkLinkFieldSet(file, fields, path, placement, errors, depth = 1, isListItem = false) {
|
|
2125
2186
|
if (depth > 6) return;
|
|
2126
2187
|
fields.forEach((field, index) => {
|
|
2127
2188
|
if (!isRecord(field)) return;
|
|
2128
|
-
const at =
|
|
2129
|
-
checkLinkField(file, field, at,
|
|
2189
|
+
const at = isListItem ? path : `${path}[${index}]`;
|
|
2190
|
+
checkLinkField(file, field, at, placement, errors);
|
|
2130
2191
|
const metadata = isRecord(field.metadata) ? field.metadata : null;
|
|
2131
2192
|
if (metadata === null) return;
|
|
2132
|
-
if (Array.isArray(metadata.fields)) checkLinkFieldSet(file, metadata.fields.filter(isRecord), `${at}.metadata.fields`,
|
|
2133
|
-
if (isRecord(metadata.item)) checkLinkFieldSet(file, [metadata.item], `${at}.metadata.item`,
|
|
2193
|
+
if (Array.isArray(metadata.fields)) checkLinkFieldSet(file, metadata.fields.filter(isRecord), `${at}.metadata.fields`, "nested", errors, depth + 1);
|
|
2194
|
+
if (isRecord(metadata.item)) checkLinkFieldSet(file, [metadata.item], `${at}.metadata.item`, placement === "top" ? "topListItem" : "nested", errors, depth + 1, true);
|
|
2134
2195
|
});
|
|
2135
2196
|
}
|
|
2136
|
-
function checkLinkField(file, field, at,
|
|
2197
|
+
function checkLinkField(file, field, at, placement, errors) {
|
|
2137
2198
|
const metadata = isRecord(field.metadata) ? field.metadata : {};
|
|
2138
2199
|
const declared = LINK_METADATA_KEYS.filter((key) => key in metadata);
|
|
2139
2200
|
if (declared.length === 0) return;
|
|
@@ -2149,11 +2210,92 @@ function checkLinkField(file, field, at, isListItem, errors) {
|
|
|
2149
2210
|
else for (const id of ids) if (typeof id !== "string" || !SCHEMA_API_ID_PATTERN.test(id)) errors.push(`${file}: ${at}.metadata.allowedEntrySchemaApiIds — invalid schema apiId "${String(id)}"`);
|
|
2150
2211
|
if (kinds !== null && !kinds.includes("entry")) errors.push(`${file}: ${at}.metadata.allowedEntrySchemaApiIds — requires metadata.kinds to include "entry"`);
|
|
2151
2212
|
}
|
|
2152
|
-
if ("tree" in metadata)
|
|
2153
|
-
|
|
2154
|
-
|
|
2213
|
+
if ("tree" in metadata) checkLinkTree(file, metadata.tree, kinds, at, placement, errors);
|
|
2214
|
+
}
|
|
2215
|
+
const LINK_ASPECT_PATTERN = /^\d+:\d+$/;
|
|
2216
|
+
const LINK_TREE_DEFAULT_DEPTH = 2;
|
|
2217
|
+
/** Card kinds that carry no picture of their own: a card of one needs an image
|
|
2218
|
+
* the author uploads, so the declaration must allow `customImage`. */
|
|
2219
|
+
const LINK_CARD_KINDS_NEEDING_IMAGE = /* @__PURE__ */ new Set([
|
|
2220
|
+
"page",
|
|
2221
|
+
"entry",
|
|
2222
|
+
"url",
|
|
2223
|
+
"category"
|
|
2224
|
+
]);
|
|
2225
|
+
/**
|
|
2226
|
+
* `metadata.tree`, held to what Core's `ValidateLinkMetadata` accepts. `true`
|
|
2227
|
+
* means depth 2 with legacy groups, `{}` means the same, `false` and `null`
|
|
2228
|
+
* mean off; an object may declare `depth`, `sections` and `cards`. Keys the
|
|
2229
|
+
* grammar does not know are ignored, as Core ignores them.
|
|
2230
|
+
*/
|
|
2231
|
+
function checkLinkTree(file, tree, kinds, at, placement, errors) {
|
|
2232
|
+
const where = `${file}: ${at}.metadata.tree`;
|
|
2233
|
+
if (tree === null || typeof tree === "boolean") return;
|
|
2234
|
+
if (!isRecord(tree)) {
|
|
2235
|
+
errors.push(`${where} — must be a boolean or an object`);
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
if (isPresent(tree.enabled) && typeof tree.enabled !== "boolean") errors.push(`${where}.enabled — must be a boolean`);
|
|
2239
|
+
let depth = LINK_TREE_DEFAULT_DEPTH;
|
|
2240
|
+
if (tree.depth !== void 0 && tree.depth !== null) {
|
|
2241
|
+
if (typeof tree.depth !== "number" || !Number.isInteger(tree.depth)) {
|
|
2242
|
+
errors.push(`${where}.depth — must be 1 or 2`);
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
if (tree.depth !== 0) depth = tree.depth;
|
|
2246
|
+
}
|
|
2247
|
+
if (depth !== 1 && depth !== LINK_TREE_DEFAULT_DEPTH) {
|
|
2248
|
+
errors.push(`${where}.depth — must be 1 or 2 (got ${depth})`);
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
const sections = tree.sections ?? null;
|
|
2252
|
+
const cards = tree.cards ?? null;
|
|
2253
|
+
if ((sections !== null || cards !== null) && depth !== LINK_TREE_DEFAULT_DEPTH) errors.push(`${where} — sections and cards require depth 2`);
|
|
2254
|
+
if (sections !== null) checkLinkTreeSections(where, sections, errors);
|
|
2255
|
+
if (cards !== null) {
|
|
2256
|
+
if (placement === "nested") errors.push(`${where}.cards — only allowed on a top-level link field or the link item of a top-level list`);
|
|
2257
|
+
checkLinkTreeCards(where, cards, kinds, errors);
|
|
2155
2258
|
}
|
|
2156
2259
|
}
|
|
2260
|
+
function checkLinkTreeSections(where, sections, errors) {
|
|
2261
|
+
if (!isRecord(sections)) {
|
|
2262
|
+
errors.push(`${where}.sections — must be an object`);
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
checkTreeMax(`${where}.sections.max`, sections.max, errors);
|
|
2266
|
+
for (const key of ["headingLink", "seeAll"]) if (isPresent(sections[key]) && typeof sections[key] !== "boolean") errors.push(`${where}.sections.${key} — must be a boolean`);
|
|
2267
|
+
}
|
|
2268
|
+
function checkLinkTreeCards(where, cards, kinds, errors) {
|
|
2269
|
+
if (!isRecord(cards)) {
|
|
2270
|
+
errors.push(`${where}.cards — must be an object`);
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
checkTreeMax(`${where}.cards.max`, cards.max, errors);
|
|
2274
|
+
const allowed = kinds ?? LINK_KINDS;
|
|
2275
|
+
let cardKinds = allowed;
|
|
2276
|
+
if (cards.kinds !== void 0 && cards.kinds !== null) {
|
|
2277
|
+
if (!Array.isArray(cards.kinds) || cards.kinds.some((kind) => typeof kind !== "string")) errors.push(`${where}.cards.kinds — must be an array of link kinds`);
|
|
2278
|
+
else {
|
|
2279
|
+
const declared = cards.kinds;
|
|
2280
|
+
for (const kind of declared) if (!allowed.includes(kind)) errors.push(`${where}.cards.kinds — "${kind}" is not one of the field's metadata.kinds (cards.kinds must be a subset of it)`);
|
|
2281
|
+
if (declared.length > 0) cardKinds = declared;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
if (cards.aspect !== void 0 && cards.aspect !== null) {
|
|
2285
|
+
if (typeof cards.aspect !== "string") errors.push(`${where}.cards.aspect — must be a string like "4:5"`);
|
|
2286
|
+
else if (cards.aspect !== "" && !LINK_ASPECT_PATTERN.test(cards.aspect)) errors.push(`${where}.cards.aspect — must look like 4:5 (got "${cards.aspect}")`);
|
|
2287
|
+
}
|
|
2288
|
+
if (isPresent(cards.customImage) && typeof cards.customImage !== "boolean") errors.push(`${where}.cards.customImage — must be a boolean`);
|
|
2289
|
+
else if (cards.customImage !== true && cardKinds.some((kind) => LINK_CARD_KINDS_NEEDING_IMAGE.has(kind))) errors.push(`${where}.cards.customImage — required when cards may be a page, entry, url or category (declare cards.kinds, or customImage: true)`);
|
|
2290
|
+
}
|
|
2291
|
+
/** Core decodes an explicit `null` into a Go bool as a no-op, so it means the
|
|
2292
|
+
* same as an absent key. */
|
|
2293
|
+
function isPresent(value) {
|
|
2294
|
+
return value !== void 0 && value !== null;
|
|
2295
|
+
}
|
|
2296
|
+
function checkTreeMax(at, value, errors) {
|
|
2297
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) errors.push(`${at} — must be an integer of at least 1`);
|
|
2298
|
+
}
|
|
2157
2299
|
/** The declared kinds, or null when the field declares none (which means all
|
|
2158
2300
|
* six) or declared something unusable. */
|
|
2159
2301
|
function checkLinkKinds(file, metadata, at, errors) {
|
package/dist/scan.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as ManifestRoute, M as ScanResult, O as ManifestTemplateSeed, R as ThemeManifest, d as DeclaredTemplateSeed, j as ScanOptions } from "./types-Dej7h4ZU.js";
|
|
2
2
|
export declare function scanTheme(opts: ScanOptions): ScanResult;
|
|
3
3
|
export declare function readPreviousManifest(themeDir: string, errors: string[]): ThemeManifest | undefined;
|
|
4
4
|
export type { DeclaredTemplateSeed, ManifestRoute, ManifestTemplateSeed, ScanOptions, ScanResult, ThemeManifest };
|
package/dist/scan.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as readPreviousManifest, n as scanTheme } from "./scan-
|
|
1
|
+
export { t as readPreviousManifest, n as scanTheme } from "./scan-DBOHDmAQ.js";
|
|
@@ -194,6 +194,43 @@ interface BlockFieldShowWhen {
|
|
|
194
194
|
in?: string[];
|
|
195
195
|
equals?: string;
|
|
196
196
|
}
|
|
197
|
+
/** What a `link` field's value points at. Six are destinations; `none` is a
|
|
198
|
+
* heading — a row that groups the links under it and goes nowhere itself, which
|
|
199
|
+
* is the only shape a mega-menu column heading has. Core validates a stored
|
|
200
|
+
* value against the same seven. */
|
|
201
|
+
type LinkKind = 'product' | 'collection' | 'category' | 'entry' | 'page' | 'url' | 'none';
|
|
202
|
+
/** The menu a theme declares for a `link` field, spelled with Core's own JSON
|
|
203
|
+
* keys (`LinkTreeDecl`). `{}` means the same as `true`. */
|
|
204
|
+
interface EldraLinkTree {
|
|
205
|
+
/** How many levels the editor offers: 1 (links only) or 2 (a link and one
|
|
206
|
+
* level under it). Defaults to 2; `sections` and `cards` need 2. */
|
|
207
|
+
depth?: 1 | 2;
|
|
208
|
+
/** Grouped columns under a top-level link. */
|
|
209
|
+
sections?: EldraLinkTreeSections;
|
|
210
|
+
/** Promotional cards a top-level link may carry. Allowed only on a top-level
|
|
211
|
+
* link field or the link item of a top-level list. */
|
|
212
|
+
cards?: EldraLinkTreeCards;
|
|
213
|
+
}
|
|
214
|
+
interface EldraLinkTreeSections {
|
|
215
|
+
/** Most sections one link may have; at least 1. */
|
|
216
|
+
max: number;
|
|
217
|
+
/** A section may have a heading that is itself a link. */
|
|
218
|
+
headingLink?: boolean;
|
|
219
|
+
/** A section may end with a "see all" link. */
|
|
220
|
+
seeAll?: boolean;
|
|
221
|
+
}
|
|
222
|
+
interface EldraLinkTreeCards {
|
|
223
|
+
/** The link kinds a card may be; every kind the field offers when absent.
|
|
224
|
+
* Must be within the field's `kinds`. */
|
|
225
|
+
kinds?: LinkKind[];
|
|
226
|
+
/** Most cards per section, or per link without sections; at least 1. */
|
|
227
|
+
max: number;
|
|
228
|
+
/** The image's `width:height`, such as `4:5` or `16:9`. */
|
|
229
|
+
aspect?: string;
|
|
230
|
+
/** An author may upload a card's own image. Required when cards may be a
|
|
231
|
+
* page, entry, url or category, which have no picture of their own. */
|
|
232
|
+
customImage?: boolean;
|
|
233
|
+
}
|
|
197
234
|
interface BlockField {
|
|
198
235
|
fieldId: string;
|
|
199
236
|
name: string;
|
|
@@ -258,15 +295,26 @@ interface BlockMigrationLinkConversion {
|
|
|
258
295
|
group?: string;
|
|
259
296
|
};
|
|
260
297
|
}
|
|
298
|
+
/** One link field whose rows' children are grouped into sections on deploy:
|
|
299
|
+
* each row's children are partitioned on their `group` text, in first-seen
|
|
300
|
+
* order, into `sections` (children with no group form one section with no
|
|
301
|
+
* heading), and the row keeps `sections` instead of `children`. `field` names
|
|
302
|
+
* a top-level `link` field, or a `list` of links, and the block must declare
|
|
303
|
+
* `tree.sections` on that link. It runs after the same deploy's `convertToLink`
|
|
304
|
+
* conversions, which are what write the `group` it reads. */
|
|
305
|
+
interface BlockMigrationGroupsToSections {
|
|
306
|
+
field: string;
|
|
307
|
+
}
|
|
261
308
|
interface BlockMigration {
|
|
262
309
|
version: number;
|
|
263
310
|
/** Optional: a step may carry only conversions. A step must declare at least
|
|
264
|
-
* one of `renames` and `
|
|
311
|
+
* one of `renames`, `convertToLink` and `groupsToSections`. */
|
|
265
312
|
renames?: Array<{
|
|
266
313
|
from: string;
|
|
267
314
|
to: string;
|
|
268
315
|
}>;
|
|
269
316
|
convertToLink?: BlockMigrationLinkConversion[];
|
|
317
|
+
groupsToSections?: BlockMigrationGroupsToSections[];
|
|
270
318
|
}
|
|
271
319
|
interface BlockDefinition {
|
|
272
320
|
apiId: string;
|
|
@@ -328,6 +376,25 @@ interface ThemeManifest {
|
|
|
328
376
|
* no `i18n/` directory, so a theme that declares no texts keeps emitting
|
|
329
377
|
* the manifest shape an older Core already accepts. */
|
|
330
378
|
messages?: ThemeMessages;
|
|
379
|
+
/** What the theme's runtime can do that Studio has to know before it offers it — see
|
|
380
|
+
* `ThemeManifestCapabilities`. Absent rather than empty when the runtime declares none, so the
|
|
381
|
+
* manifest stays the shape an older Core accepts. */
|
|
382
|
+
capabilities?: ThemeManifestCapabilities;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Features of the theme's **runtime** (the framework wrapper the theme is built with, not the
|
|
386
|
+
* theme's own code) that Studio offers only to a deployment that has them. Each is a version
|
|
387
|
+
* number, so a later, incompatible form can be told apart.
|
|
388
|
+
*
|
|
389
|
+
* * `draftPreview: 1` — the theme renders a draft preview session (WS-1293): on the preview
|
|
390
|
+
* router's session host it reads drafts through the router's same-origin proxy, covers the
|
|
391
|
+
* published prerender until the draft is on screen, and shows a notice, never the published
|
|
392
|
+
* page, when the session is refused. Studio disables Preview for a deployment without it.
|
|
393
|
+
*
|
|
394
|
+
* Declared by the framework wrapper through `EldraThemeOptions.capabilities`, never by a theme.
|
|
395
|
+
*/
|
|
396
|
+
interface ThemeManifestCapabilities {
|
|
397
|
+
draftPreview?: 1;
|
|
331
398
|
}
|
|
332
399
|
interface LegacyThemeTokens {
|
|
333
400
|
colors: Record<string, string>;
|
|
@@ -426,6 +493,8 @@ interface ScanOptions {
|
|
|
426
493
|
templateRoles?: ManifestTemplateRoles;
|
|
427
494
|
/** The forms a site is created with; see `ManifestFormSeed`. */
|
|
428
495
|
formSeeds?: DeclaredFormSeed[];
|
|
496
|
+
/** The runtime's capabilities; see `ThemeManifestCapabilities`. */
|
|
497
|
+
capabilities?: ThemeManifestCapabilities;
|
|
429
498
|
/** The theme's raw, as-configured breakpoints — validated and defaulted
|
|
430
499
|
* into the manifest's `breakpoints` by resolveLayoutBreakpoints (Core),
|
|
431
500
|
* not here. */
|
|
@@ -433,6 +502,8 @@ interface ScanOptions {
|
|
|
433
502
|
}
|
|
434
503
|
interface EldraThemeOptions {
|
|
435
504
|
framework?: string;
|
|
505
|
+
/** The runtime's capabilities, set by a framework wrapper; see `ThemeManifestCapabilities`. */
|
|
506
|
+
capabilities?: ThemeManifestCapabilities;
|
|
436
507
|
routes?: ManifestRoute[];
|
|
437
508
|
customPages?: DeclaredThemeCodePage[];
|
|
438
509
|
/** The seeds a site is created with on its first deploy: the route templates
|
|
@@ -494,4 +565,4 @@ interface EldraThemeOptions {
|
|
|
494
565
|
*/
|
|
495
566
|
resolveTokens?: (manifestTokens: ThemeDesignTokens | LegacyThemeTokens) => ThemeDesignTokens;
|
|
496
567
|
}
|
|
497
|
-
export {
|
|
568
|
+
export { PageSeedTarget as A, ThemeMessages as B, ManifestPageSeedBlock as C, ManifestTemplateRoles as D, ManifestRoute as E, TemplateSeedLayoutNode as F, TemplateSeedReusableNode as I, TemplateSeedSchemaApiId as L, ScanResult as M, TemplateSeedBlockNode as N, ManifestTemplateSeed as O, TemplateSeedLayout as P, ThemeManifest as R, ManifestPageSeed as S, ManifestPageSeedRegion as T, EldraThemeOptions as _, DeclaredFormSeed as a, ManifestFormSeedField as b, DeclaredPageSeedEntry as c, DeclaredTemplateSeed as d, DeclaredTemplateSeedBlock as f, EldraLinkTreeSections as g, EldraLinkTreeCards as h, BlockMigrationGroupsToSections as i, ScanOptions as j, ManifestTemplateSeedBlock as k, DeclaredPageSeedRegion as l, EldraLinkTree as m, BlockField as n, DeclaredPageSeed as o, DeclaredThemeCodePage as p, BlockMigration as r, DeclaredPageSeedBlock as s, BlockDefinition as t, DeclaredSeed as u, LegacyThemeTokens as v, ManifestPageSeedEntry as w, ManifestFormSeedFieldType as x, ManifestFormSeed as y, ThemeManifestCapabilities as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/vite-plugin-theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Vite plugin for Eldra themes: scans blocks/*/block.json, validates them, emits the theme manifest and the virtual modules the runtime reads (blocks, manifest, block fields, breakpoints, tokens CSS).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"ajv": "^8.17.1",
|
|
44
|
-
"@eldrajs/theme-core": "^0.
|
|
44
|
+
"@eldrajs/theme-core": "^0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@tailwindcss/vite": "^4.1.14",
|