@eldrajs/vite-plugin-theme 0.3.6 → 0.4.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/CHANGELOG.md +23 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/{scan-ClxSvaDL.js → scan-DB3i4ttC.js} +189 -21
- package/dist/scan.d.ts +1 -1
- package/dist/scan.js +1 -1
- package/dist/{types-Zt7J0J6v.d.ts → types-CVzauCgt.d.ts} +79 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,29 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- A block field may say `"allowPrices": false` (WS-1474): Core allows price tokens in every `string`, `text` and `rich-text` field of a theme block, and this opts one out — a URL, an email, a code. The scan refuses it unless it is a boolean on one of those types, at any depth, and it reaches the manifest. Changing it never needs a version bump.
|
|
9
|
+
- **A theme can declare its menu as an object: `metadata.tree` takes depth, sections and cards
|
|
10
|
+
(WS-1312).** `tree` on a `link` field is now `boolean | EldraLinkTree` (new types `EldraLinkTree`,
|
|
11
|
+
`EldraLinkTreeSections`, `EldraLinkTreeCards`, Core's own JSON keys). The scanner refuses exactly
|
|
12
|
+
what Core's manifest ingest refuses: a depth other than 1 or 2, `sections` or `cards` at depth 1,
|
|
13
|
+
a `max` below 1, a malformed `aspect`, `cards.kinds` outside the field's `kinds`, a cards
|
|
14
|
+
declaration that allows page, entry, url or category without `customImage`, and `cards` anywhere
|
|
15
|
+
but a top-level link or a top-level list's link item. It also stops refusing `tree` on a top-level
|
|
16
|
+
link or a composite child, which Core accepts (`groupsToSections` supports a top-level link or a
|
|
17
|
+
list of links, never a composite child). See
|
|
18
|
+
`docs/themes.md`, "Declaring a menu".
|
|
19
|
+
|
|
20
|
+
- **`migrations[].groupsToSections`: grouped menu children become sections (WS-1318).** A step may
|
|
21
|
+
declare `groupsToSections: [{ "field": "links" }]` (at most 16, `field` the only key) to turn a link
|
|
22
|
+
field's rows' children, grouped by their `group` text, into `sections` on deploy. The scanner
|
|
23
|
+
refuses a field that is missing, is not a `link` or a `list` of links, does not declare
|
|
24
|
+
`tree.sections`, or is converted twice, and a step now has to declare `renames`, `convertToLink`
|
|
25
|
+
or `groupsToSections`. New type `BlockMigrationGroupsToSections`. Needs a Core that accepts the
|
|
26
|
+
step; `convertToLink` in the same deploy runs first. See `docs/theme-field-migrations.md`.
|
|
27
|
+
- **`capabilities` (WS-1303).** `EldraThemeOptions.capabilities` (set by a framework wrapper) puts
|
|
28
|
+
`capabilities: { draftPreview: 1 }` in the manifest; an unknown capability or version is an error.
|
|
29
|
+
Absent when none is declared, so today's manifests are unchanged.
|
|
30
|
+
|
|
8
31
|
- **`formSeeds[].actions.subscribe.consentText` (WS-386).** A subscribe action may carry its consent
|
|
9
32
|
sentence per locale (`{ 'en-US': '… {shop} …' }`), validated like Core: locale tags, at most 500
|
|
10
33
|
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-CVzauCgt.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-DB3i4ttC.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,
|
|
@@ -198,6 +211,7 @@ const blockJsonSchema = {
|
|
|
198
211
|
groupId: { type: "string" },
|
|
199
212
|
isTitle: { type: "boolean" },
|
|
200
213
|
localized: { type: "boolean" },
|
|
214
|
+
allowPrices: { type: "boolean" },
|
|
201
215
|
default: {},
|
|
202
216
|
description: { type: "string" },
|
|
203
217
|
helpText: { type: "string" },
|
|
@@ -313,6 +327,7 @@ const STORED_FIELD_KEYS = [
|
|
|
313
327
|
"description",
|
|
314
328
|
"default",
|
|
315
329
|
"localized",
|
|
330
|
+
"allowPrices",
|
|
316
331
|
"helpText",
|
|
317
332
|
"validators",
|
|
318
333
|
"metadata",
|
|
@@ -329,6 +344,7 @@ const STORED_RELATION_KEYS = [
|
|
|
329
344
|
function migrationChecks(file, block, previous, errors) {
|
|
330
345
|
const next = new Map(block.fields.map((field) => [field.fieldId, field]));
|
|
331
346
|
const versions = /* @__PURE__ */ new Set();
|
|
347
|
+
const groupedFields = /* @__PURE__ */ new Set();
|
|
332
348
|
for (const [index, step] of (block.migrations ?? []).entries()) {
|
|
333
349
|
const at = `${file}: migrations[${index}]`;
|
|
334
350
|
if (step.version > block.version) errors.push(`${at}.version — must be a block version bump`);
|
|
@@ -336,7 +352,8 @@ function migrationChecks(file, block, previous, errors) {
|
|
|
336
352
|
versions.add(step.version);
|
|
337
353
|
const renames = step.renames ?? [];
|
|
338
354
|
const conversions = step.convertToLink ?? [];
|
|
339
|
-
if (step.renames === void 0 && step.convertToLink === void 0) errors.push(`${at} — a migration step must declare renames or
|
|
355
|
+
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`);
|
|
356
|
+
checkGroupsToSections(at, step.groupsToSections ?? [], next, groupedFields, errors);
|
|
340
357
|
const conversionTargets = /* @__PURE__ */ new Set();
|
|
341
358
|
for (const conversion of conversions) {
|
|
342
359
|
checkConversionTarget(at, conversion, next, errors);
|
|
@@ -383,6 +400,30 @@ function migrationChecks(file, block, previous, errors) {
|
|
|
383
400
|
requireVersionBumpForRetirement(file, block, previous, old, next, errors);
|
|
384
401
|
}
|
|
385
402
|
/**
|
|
403
|
+
* What a `groupsToSections` step must be true of in the *incoming* fields: it
|
|
404
|
+
* names a link field, or a list of links, and that link declares
|
|
405
|
+
* `tree.sections`, so the sections the step writes are ones the field then
|
|
406
|
+
* accepts on every save. Core re-checks the same rules at ingest.
|
|
407
|
+
*/
|
|
408
|
+
function checkGroupsToSections(at, steps, next, seen, errors) {
|
|
409
|
+
for (const { field: fieldId } of steps) {
|
|
410
|
+
const target = next.get(fieldId);
|
|
411
|
+
if (target === void 0) {
|
|
412
|
+
errors.push(`${at} — groupsToSections field "${fieldId}" does not exist in incoming fields`);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const link = target.type === "list" ? listItem(target) : target;
|
|
416
|
+
if (link === null || link.type !== "link") {
|
|
417
|
+
errors.push(`${at} — groupsToSections field "${fieldId}" must be a link field or a list of links`);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const tree = link.metadata?.tree;
|
|
421
|
+
if (!isRecord$1(tree) || !isRecord$1(tree.sections)) errors.push(`${at} — groupsToSections field "${fieldId}" must declare tree.sections`);
|
|
422
|
+
if (seen.has(fieldId)) errors.push(`${at} — groupsToSections fields must be unique; one field cannot be converted twice`);
|
|
423
|
+
seen.add(fieldId);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
386
427
|
* What a conversion must be true of in the *incoming* fields: it writes a link,
|
|
387
428
|
* so `to` has to be one — or, for `shape: "list"`, a list whose item is one.
|
|
388
429
|
* Checked without any history, because it is a statement about the block being
|
|
@@ -536,7 +577,7 @@ function validMigrationFieldShape(value, depth = 1) {
|
|
|
536
577
|
function storedMigrationField(raw, depth = 1) {
|
|
537
578
|
const value = storedObject(raw, STORED_FIELD_KEYS);
|
|
538
579
|
if (value !== null) for (const key of IGNORED_FIELD_KEYS) delete value[key];
|
|
539
|
-
if (value === null || typeof value.fieldId !== "string" || !/^[a-zA-Z0-9_]+$/.test(value.fieldId) || typeof value.name !== "string" || value.name === "" || typeof value.type !== "string" || !STORED_FIELD_TYPES.has(value.type) || value.localized != null && typeof value.localized !== "boolean" || depth > 5) return null;
|
|
580
|
+
if (value === null || typeof value.fieldId !== "string" || !/^[a-zA-Z0-9_]+$/.test(value.fieldId) || typeof value.name !== "string" || value.name === "" || typeof value.type !== "string" || !STORED_FIELD_TYPES.has(value.type) || value.localized != null && typeof value.localized !== "boolean" || value.allowPrices != null && typeof value.allowPrices !== "boolean" || depth > 5) return null;
|
|
540
581
|
if ([
|
|
541
582
|
"groupId",
|
|
542
583
|
"presetId",
|
|
@@ -641,7 +682,7 @@ const REFERENCE_RELATION_MESSAGE = "a {_type: \"collection\", slug} seed referen
|
|
|
641
682
|
* `reference` field's own seed grammar stays collection-only. */
|
|
642
683
|
const LINK_SLUG_KEYS = /* @__PURE__ */ new Set(["_type", "slug"]);
|
|
643
684
|
const LINK_SLUG_TYPES = /* @__PURE__ */ new Set(["product", "collection"]);
|
|
644
|
-
const LINK_KINDS = /* @__PURE__ */ new Set([
|
|
685
|
+
const LINK_KINDS$1 = /* @__PURE__ */ new Set([
|
|
645
686
|
"product",
|
|
646
687
|
"collection",
|
|
647
688
|
"category",
|
|
@@ -792,7 +833,7 @@ function checkLinkValue(format, path, value, errors, isChild = false) {
|
|
|
792
833
|
return;
|
|
793
834
|
}
|
|
794
835
|
const kind = typeof value.kind === "string" ? value.kind.trim() : "";
|
|
795
|
-
if (!LINK_KINDS.has(kind)) {
|
|
836
|
+
if (!LINK_KINDS$1.has(kind)) {
|
|
796
837
|
errors.push(format(path, LINK_MESSAGE));
|
|
797
838
|
return;
|
|
798
839
|
}
|
|
@@ -1748,7 +1789,10 @@ const SEMVER_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-
|
|
|
1748
1789
|
const SLOT_ID_PATTERN = /^[a-z][a-z0-9-]{0,47}$/;
|
|
1749
1790
|
const SLOT_CONTROL_CHARS = /[\p{Cc}\p{Cf}]/gu;
|
|
1750
1791
|
const RICH_TEXT_TOOLBAR_CONTROL_SET = new Set(RICH_TEXT_TOOLBAR_CONTROLS);
|
|
1751
|
-
|
|
1792
|
+
/** What a `link` value may be — six destinations plus `none`, the heading that
|
|
1793
|
+
* groups the links under it and goes nowhere itself. Core validates a stored
|
|
1794
|
+
* value against the same set. */
|
|
1795
|
+
const LINK_KINDS = [
|
|
1752
1796
|
"product",
|
|
1753
1797
|
"collection",
|
|
1754
1798
|
"category",
|
|
@@ -1756,7 +1800,8 @@ const LINK_KIND_SET = /* @__PURE__ */ new Set([
|
|
|
1756
1800
|
"page",
|
|
1757
1801
|
"url",
|
|
1758
1802
|
"none"
|
|
1759
|
-
]
|
|
1803
|
+
];
|
|
1804
|
+
const LINK_KIND_SET = new Set(LINK_KINDS);
|
|
1760
1805
|
/** The three metadata keys Core's `link` field type declares, and therefore
|
|
1761
1806
|
* the whole surface a block.json may carry on one. */
|
|
1762
1807
|
const LINK_METADATA_KEYS = [
|
|
@@ -1779,6 +1824,24 @@ const validateBlockJson = new Ajv({
|
|
|
1779
1824
|
allErrors: true,
|
|
1780
1825
|
allowUnionTypes: true
|
|
1781
1826
|
}).compile(blockJsonSchema);
|
|
1827
|
+
/** Every capability this version knows, at the version it knows. */
|
|
1828
|
+
const THEME_MANIFEST_CAPABILITIES = { draftPreview: 1 };
|
|
1829
|
+
/**
|
|
1830
|
+
* The runtime's declared capabilities, as the manifest carries them: absent when there are none,
|
|
1831
|
+
* and only the ones this version knows, at the version it knows. Anything else is an error rather
|
|
1832
|
+
* than something Studio would be told the theme can do.
|
|
1833
|
+
*/
|
|
1834
|
+
function validateCapabilities(capabilities, errors) {
|
|
1835
|
+
if (capabilities === void 0) return {};
|
|
1836
|
+
const declared = {};
|
|
1837
|
+
for (const [name, version] of Object.entries(capabilities)) {
|
|
1838
|
+
if (version === void 0) continue;
|
|
1839
|
+
if (!Object.hasOwn(THEME_MANIFEST_CAPABILITIES, name)) errors.push(`capabilities: unknown capability "${name}"`);
|
|
1840
|
+
else if (version !== THEME_MANIFEST_CAPABILITIES[name]) errors.push(`capabilities.${name}: unsupported version ${JSON.stringify(version)}`);
|
|
1841
|
+
else declared[name] = 1;
|
|
1842
|
+
}
|
|
1843
|
+
return Object.keys(declared).length === 0 ? {} : { capabilities: declared };
|
|
1844
|
+
}
|
|
1782
1845
|
function scanTheme(opts) {
|
|
1783
1846
|
const themeDir = opts.themeDir;
|
|
1784
1847
|
const blocksDir = join(themeDir, "blocks");
|
|
@@ -1871,7 +1934,8 @@ function scanTheme(opts) {
|
|
|
1871
1934
|
...pageSeeds.length === 0 ? {} : { pageSeeds },
|
|
1872
1935
|
...formSeeds.length === 0 ? {} : { formSeeds },
|
|
1873
1936
|
tokens: readTokens(themeDir, errors),
|
|
1874
|
-
...messages === void 0 ? {} : { messages }
|
|
1937
|
+
...messages === void 0 ? {} : { messages },
|
|
1938
|
+
...validateCapabilities(opts.capabilities, errors)
|
|
1875
1939
|
};
|
|
1876
1940
|
const breakpoints = resolveLayoutBreakpoints(opts.breakpoints);
|
|
1877
1941
|
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");
|
|
@@ -2048,6 +2112,7 @@ function formatAjvError(file, error) {
|
|
|
2048
2112
|
}
|
|
2049
2113
|
function semanticChecks(file, block, errors) {
|
|
2050
2114
|
const fields = Array.isArray(block.fields) ? block.fields : [];
|
|
2115
|
+
priceFieldChecks(file, fields, "fields", errors);
|
|
2051
2116
|
const seen = /* @__PURE__ */ new Set();
|
|
2052
2117
|
let titleCount = 0;
|
|
2053
2118
|
const groups = Array.isArray(block.groups) ? block.groups : [];
|
|
@@ -2097,7 +2162,7 @@ function semanticChecks(file, block, errors) {
|
|
|
2097
2162
|
});
|
|
2098
2163
|
if (titleCount > 1) errors.push(`${file}: fields — at most one field may set isTitle (found ${titleCount})`);
|
|
2099
2164
|
checkFieldSetVisibility(file, fields, "fields", errors);
|
|
2100
|
-
checkLinkFieldSet(file, fields, "fields",
|
|
2165
|
+
checkLinkFieldSet(file, fields, "fields", "top", errors);
|
|
2101
2166
|
const slots = Array.isArray(block.slots) ? block.slots : [];
|
|
2102
2167
|
const slotIds = /* @__PURE__ */ new Set();
|
|
2103
2168
|
for (const [index, slot] of slots.entries()) {
|
|
@@ -2116,24 +2181,23 @@ function semanticChecks(file, block, errors) {
|
|
|
2116
2181
|
*
|
|
2117
2182
|
* Three metadata keys belong to `link` and to nothing else, so a block that
|
|
2118
2183
|
* 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.
|
|
2184
|
+
* ingest. `tree` is declared on the link itself (a `list` can carry only
|
|
2185
|
+
* `allowedSchemas` and `item`), as `true` or as a declaration object; see
|
|
2186
|
+
* `checkLinkTree`.
|
|
2123
2187
|
*/
|
|
2124
|
-
function checkLinkFieldSet(file, fields, path,
|
|
2188
|
+
function checkLinkFieldSet(file, fields, path, placement, errors, depth = 1, isListItem = false) {
|
|
2125
2189
|
if (depth > 6) return;
|
|
2126
2190
|
fields.forEach((field, index) => {
|
|
2127
2191
|
if (!isRecord(field)) return;
|
|
2128
|
-
const at =
|
|
2129
|
-
checkLinkField(file, field, at,
|
|
2192
|
+
const at = isListItem ? path : `${path}[${index}]`;
|
|
2193
|
+
checkLinkField(file, field, at, placement, errors);
|
|
2130
2194
|
const metadata = isRecord(field.metadata) ? field.metadata : null;
|
|
2131
2195
|
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`,
|
|
2196
|
+
if (Array.isArray(metadata.fields)) checkLinkFieldSet(file, metadata.fields.filter(isRecord), `${at}.metadata.fields`, "nested", errors, depth + 1);
|
|
2197
|
+
if (isRecord(metadata.item)) checkLinkFieldSet(file, [metadata.item], `${at}.metadata.item`, placement === "top" ? "topListItem" : "nested", errors, depth + 1, true);
|
|
2134
2198
|
});
|
|
2135
2199
|
}
|
|
2136
|
-
function checkLinkField(file, field, at,
|
|
2200
|
+
function checkLinkField(file, field, at, placement, errors) {
|
|
2137
2201
|
const metadata = isRecord(field.metadata) ? field.metadata : {};
|
|
2138
2202
|
const declared = LINK_METADATA_KEYS.filter((key) => key in metadata);
|
|
2139
2203
|
if (declared.length === 0) return;
|
|
@@ -2149,10 +2213,91 @@ function checkLinkField(file, field, at, isListItem, errors) {
|
|
|
2149
2213
|
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
2214
|
if (kinds !== null && !kinds.includes("entry")) errors.push(`${file}: ${at}.metadata.allowedEntrySchemaApiIds — requires metadata.kinds to include "entry"`);
|
|
2151
2215
|
}
|
|
2152
|
-
if ("tree" in metadata)
|
|
2153
|
-
|
|
2154
|
-
|
|
2216
|
+
if ("tree" in metadata) checkLinkTree(file, metadata.tree, kinds, at, placement, errors);
|
|
2217
|
+
}
|
|
2218
|
+
const LINK_ASPECT_PATTERN = /^\d+:\d+$/;
|
|
2219
|
+
const LINK_TREE_DEFAULT_DEPTH = 2;
|
|
2220
|
+
/** Card kinds that carry no picture of their own: a card of one needs an image
|
|
2221
|
+
* the author uploads, so the declaration must allow `customImage`. */
|
|
2222
|
+
const LINK_CARD_KINDS_NEEDING_IMAGE = /* @__PURE__ */ new Set([
|
|
2223
|
+
"page",
|
|
2224
|
+
"entry",
|
|
2225
|
+
"url",
|
|
2226
|
+
"category"
|
|
2227
|
+
]);
|
|
2228
|
+
/**
|
|
2229
|
+
* `metadata.tree`, held to what Core's `ValidateLinkMetadata` accepts. `true`
|
|
2230
|
+
* means depth 2 with legacy groups, `{}` means the same, `false` and `null`
|
|
2231
|
+
* mean off; an object may declare `depth`, `sections` and `cards`. Keys the
|
|
2232
|
+
* grammar does not know are ignored, as Core ignores them.
|
|
2233
|
+
*/
|
|
2234
|
+
function checkLinkTree(file, tree, kinds, at, placement, errors) {
|
|
2235
|
+
const where = `${file}: ${at}.metadata.tree`;
|
|
2236
|
+
if (tree === null || typeof tree === "boolean") return;
|
|
2237
|
+
if (!isRecord(tree)) {
|
|
2238
|
+
errors.push(`${where} — must be a boolean or an object`);
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
if (isPresent(tree.enabled) && typeof tree.enabled !== "boolean") errors.push(`${where}.enabled — must be a boolean`);
|
|
2242
|
+
let depth = LINK_TREE_DEFAULT_DEPTH;
|
|
2243
|
+
if (tree.depth !== void 0 && tree.depth !== null) {
|
|
2244
|
+
if (typeof tree.depth !== "number" || !Number.isInteger(tree.depth)) {
|
|
2245
|
+
errors.push(`${where}.depth — must be 1 or 2`);
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2248
|
+
if (tree.depth !== 0) depth = tree.depth;
|
|
2249
|
+
}
|
|
2250
|
+
if (depth !== 1 && depth !== LINK_TREE_DEFAULT_DEPTH) {
|
|
2251
|
+
errors.push(`${where}.depth — must be 1 or 2 (got ${depth})`);
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
const sections = tree.sections ?? null;
|
|
2255
|
+
const cards = tree.cards ?? null;
|
|
2256
|
+
if ((sections !== null || cards !== null) && depth !== LINK_TREE_DEFAULT_DEPTH) errors.push(`${where} — sections and cards require depth 2`);
|
|
2257
|
+
if (sections !== null) checkLinkTreeSections(where, sections, errors);
|
|
2258
|
+
if (cards !== null) {
|
|
2259
|
+
if (placement === "nested") errors.push(`${where}.cards — only allowed on a top-level link field or the link item of a top-level list`);
|
|
2260
|
+
checkLinkTreeCards(where, cards, kinds, errors);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
function checkLinkTreeSections(where, sections, errors) {
|
|
2264
|
+
if (!isRecord(sections)) {
|
|
2265
|
+
errors.push(`${where}.sections — must be an object`);
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
checkTreeMax(`${where}.sections.max`, sections.max, errors);
|
|
2269
|
+
for (const key of ["headingLink", "seeAll"]) if (isPresent(sections[key]) && typeof sections[key] !== "boolean") errors.push(`${where}.sections.${key} — must be a boolean`);
|
|
2270
|
+
}
|
|
2271
|
+
function checkLinkTreeCards(where, cards, kinds, errors) {
|
|
2272
|
+
if (!isRecord(cards)) {
|
|
2273
|
+
errors.push(`${where}.cards — must be an object`);
|
|
2274
|
+
return;
|
|
2155
2275
|
}
|
|
2276
|
+
checkTreeMax(`${where}.cards.max`, cards.max, errors);
|
|
2277
|
+
const allowed = kinds ?? LINK_KINDS;
|
|
2278
|
+
let cardKinds = allowed;
|
|
2279
|
+
if (cards.kinds !== void 0 && cards.kinds !== null) {
|
|
2280
|
+
if (!Array.isArray(cards.kinds) || cards.kinds.some((kind) => typeof kind !== "string")) errors.push(`${where}.cards.kinds — must be an array of link kinds`);
|
|
2281
|
+
else {
|
|
2282
|
+
const declared = cards.kinds;
|
|
2283
|
+
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)`);
|
|
2284
|
+
if (declared.length > 0) cardKinds = declared;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
if (cards.aspect !== void 0 && cards.aspect !== null) {
|
|
2288
|
+
if (typeof cards.aspect !== "string") errors.push(`${where}.cards.aspect — must be a string like "4:5"`);
|
|
2289
|
+
else if (cards.aspect !== "" && !LINK_ASPECT_PATTERN.test(cards.aspect)) errors.push(`${where}.cards.aspect — must look like 4:5 (got "${cards.aspect}")`);
|
|
2290
|
+
}
|
|
2291
|
+
if (isPresent(cards.customImage) && typeof cards.customImage !== "boolean") errors.push(`${where}.cards.customImage — must be a boolean`);
|
|
2292
|
+
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)`);
|
|
2293
|
+
}
|
|
2294
|
+
/** Core decodes an explicit `null` into a Go bool as a no-op, so it means the
|
|
2295
|
+
* same as an absent key. */
|
|
2296
|
+
function isPresent(value) {
|
|
2297
|
+
return value !== void 0 && value !== null;
|
|
2298
|
+
}
|
|
2299
|
+
function checkTreeMax(at, value, errors) {
|
|
2300
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) errors.push(`${at} — must be an integer of at least 1`);
|
|
2156
2301
|
}
|
|
2157
2302
|
/** The declared kinds, or null when the field declares none (which means all
|
|
2158
2303
|
* six) or declared something unusable. */
|
|
@@ -2257,6 +2402,29 @@ function checkFieldVisibility(file, field, siblings, at, errors) {
|
|
|
2257
2402
|
in: values
|
|
2258
2403
|
};
|
|
2259
2404
|
}
|
|
2405
|
+
/** The field types that hold price tokens (WS-1474), and so the only ones `allowPrices` may name. */
|
|
2406
|
+
const PRICE_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
2407
|
+
"string",
|
|
2408
|
+
"text",
|
|
2409
|
+
"rich-text"
|
|
2410
|
+
]);
|
|
2411
|
+
/**
|
|
2412
|
+
* `allowPrices` is a text field's own setting: Core allows price tokens in every text field of a
|
|
2413
|
+
* theme block, and `false` opts one out. At any depth (a list item's or composite's fields too) it
|
|
2414
|
+
* must be a boolean on `string`, `text` or `rich-text`.
|
|
2415
|
+
*/
|
|
2416
|
+
function priceFieldChecks(file, fields, at, errors) {
|
|
2417
|
+
fields.forEach((field, index) => {
|
|
2418
|
+
const where = `${at}[${index}]`;
|
|
2419
|
+
if ("allowPrices" in field) {
|
|
2420
|
+
if (typeof field.allowPrices !== "boolean") errors.push(`${file}: ${where}.allowPrices — must be a boolean`);
|
|
2421
|
+
else if (!PRICE_FIELD_TYPES.has(String(field.type))) errors.push(`${file}: ${where}.allowPrices — only allowed on type "string", "text" or "rich-text" (got "${String(field.type)}")`);
|
|
2422
|
+
}
|
|
2423
|
+
const metadata = isRecord(field.metadata) ? field.metadata : {};
|
|
2424
|
+
if (Array.isArray(metadata.fields)) priceFieldChecks(file, metadata.fields.filter(isRecord), `${where}.metadata.fields`, errors);
|
|
2425
|
+
if (isRecord(metadata.item)) priceFieldChecks(file, [metadata.item], `${where}.metadata.item`, errors);
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2260
2428
|
function compositeDepth(field, depth = 1) {
|
|
2261
2429
|
const metadata = field.metadata;
|
|
2262
2430
|
if (typeof metadata !== "object" || metadata === null || Array.isArray(metadata)) return depth;
|
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-CVzauCgt.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-DB3i4ttC.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;
|
|
@@ -201,6 +238,12 @@ interface BlockField {
|
|
|
201
238
|
groupId?: string;
|
|
202
239
|
isTitle?: boolean;
|
|
203
240
|
localized?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Whether a merchant may insert price tokens here (WS-1474). Core allows them in every
|
|
243
|
+
* `string`/`text`/`rich-text` field of a theme block; `false` opts one out — a URL, a code, an
|
|
244
|
+
* id, anything a written price would break. Only on those three types.
|
|
245
|
+
*/
|
|
246
|
+
allowPrices?: boolean;
|
|
204
247
|
default?: unknown;
|
|
205
248
|
description?: string;
|
|
206
249
|
helpText?: string;
|
|
@@ -258,15 +301,26 @@ interface BlockMigrationLinkConversion {
|
|
|
258
301
|
group?: string;
|
|
259
302
|
};
|
|
260
303
|
}
|
|
304
|
+
/** One link field whose rows' children are grouped into sections on deploy:
|
|
305
|
+
* each row's children are partitioned on their `group` text, in first-seen
|
|
306
|
+
* order, into `sections` (children with no group form one section with no
|
|
307
|
+
* heading), and the row keeps `sections` instead of `children`. `field` names
|
|
308
|
+
* a top-level `link` field, or a `list` of links, and the block must declare
|
|
309
|
+
* `tree.sections` on that link. It runs after the same deploy's `convertToLink`
|
|
310
|
+
* conversions, which are what write the `group` it reads. */
|
|
311
|
+
interface BlockMigrationGroupsToSections {
|
|
312
|
+
field: string;
|
|
313
|
+
}
|
|
261
314
|
interface BlockMigration {
|
|
262
315
|
version: number;
|
|
263
316
|
/** Optional: a step may carry only conversions. A step must declare at least
|
|
264
|
-
* one of `renames` and `
|
|
317
|
+
* one of `renames`, `convertToLink` and `groupsToSections`. */
|
|
265
318
|
renames?: Array<{
|
|
266
319
|
from: string;
|
|
267
320
|
to: string;
|
|
268
321
|
}>;
|
|
269
322
|
convertToLink?: BlockMigrationLinkConversion[];
|
|
323
|
+
groupsToSections?: BlockMigrationGroupsToSections[];
|
|
270
324
|
}
|
|
271
325
|
interface BlockDefinition {
|
|
272
326
|
apiId: string;
|
|
@@ -328,6 +382,25 @@ interface ThemeManifest {
|
|
|
328
382
|
* no `i18n/` directory, so a theme that declares no texts keeps emitting
|
|
329
383
|
* the manifest shape an older Core already accepts. */
|
|
330
384
|
messages?: ThemeMessages;
|
|
385
|
+
/** What the theme's runtime can do that Studio has to know before it offers it — see
|
|
386
|
+
* `ThemeManifestCapabilities`. Absent rather than empty when the runtime declares none, so the
|
|
387
|
+
* manifest stays the shape an older Core accepts. */
|
|
388
|
+
capabilities?: ThemeManifestCapabilities;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Features of the theme's **runtime** (the framework wrapper the theme is built with, not the
|
|
392
|
+
* theme's own code) that Studio offers only to a deployment that has them. Each is a version
|
|
393
|
+
* number, so a later, incompatible form can be told apart.
|
|
394
|
+
*
|
|
395
|
+
* * `draftPreview: 1` — the theme renders a draft preview session (WS-1293): on the preview
|
|
396
|
+
* router's session host it reads drafts through the router's same-origin proxy, covers the
|
|
397
|
+
* published prerender until the draft is on screen, and shows a notice, never the published
|
|
398
|
+
* page, when the session is refused. Studio disables Preview for a deployment without it.
|
|
399
|
+
*
|
|
400
|
+
* Declared by the framework wrapper through `EldraThemeOptions.capabilities`, never by a theme.
|
|
401
|
+
*/
|
|
402
|
+
interface ThemeManifestCapabilities {
|
|
403
|
+
draftPreview?: 1;
|
|
331
404
|
}
|
|
332
405
|
interface LegacyThemeTokens {
|
|
333
406
|
colors: Record<string, string>;
|
|
@@ -426,6 +499,8 @@ interface ScanOptions {
|
|
|
426
499
|
templateRoles?: ManifestTemplateRoles;
|
|
427
500
|
/** The forms a site is created with; see `ManifestFormSeed`. */
|
|
428
501
|
formSeeds?: DeclaredFormSeed[];
|
|
502
|
+
/** The runtime's capabilities; see `ThemeManifestCapabilities`. */
|
|
503
|
+
capabilities?: ThemeManifestCapabilities;
|
|
429
504
|
/** The theme's raw, as-configured breakpoints — validated and defaulted
|
|
430
505
|
* into the manifest's `breakpoints` by resolveLayoutBreakpoints (Core),
|
|
431
506
|
* not here. */
|
|
@@ -433,6 +508,8 @@ interface ScanOptions {
|
|
|
433
508
|
}
|
|
434
509
|
interface EldraThemeOptions {
|
|
435
510
|
framework?: string;
|
|
511
|
+
/** The runtime's capabilities, set by a framework wrapper; see `ThemeManifestCapabilities`. */
|
|
512
|
+
capabilities?: ThemeManifestCapabilities;
|
|
436
513
|
routes?: ManifestRoute[];
|
|
437
514
|
customPages?: DeclaredThemeCodePage[];
|
|
438
515
|
/** The seeds a site is created with on its first deploy: the route templates
|
|
@@ -494,4 +571,4 @@ interface EldraThemeOptions {
|
|
|
494
571
|
*/
|
|
495
572
|
resolveTokens?: (manifestTokens: ThemeDesignTokens | LegacyThemeTokens) => ThemeDesignTokens;
|
|
496
573
|
}
|
|
497
|
-
export {
|
|
574
|
+
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.1",
|
|
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.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@tailwindcss/vite": "^4.1.14",
|