ochre-sdk 1.3.28 → 1.3.29
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.
|
@@ -18,13 +18,16 @@ export type WebElementContext<T extends ReadonlyArray<string>> = {
|
|
|
18
18
|
/**
|
|
19
19
|
Reads the "customize-special" "element" properties of a website, each
|
|
20
20
|
holding "component" properties whose settings every element of that
|
|
21
|
-
component starts from
|
|
21
|
+
component starts from
|
|
22
22
|
|
|
23
23
|
@param websiteReader - Reader over the website's "presentation" properties
|
|
24
24
|
@param parent - The defaults of the enclosing website, which these extend
|
|
25
|
+
@param websiteUuid - The website's UUID, for error messages
|
|
25
26
|
@returns The component defaults in effect for the website's elements
|
|
27
|
+
@throws When a default sets one of {@link ELEMENT_TARGET_LABELS}, which
|
|
28
|
+
every element has to set itself
|
|
26
29
|
*/
|
|
27
|
-
export declare function parseComponentDefaults<T extends ReadonlyArray<string>>(websiteReader: WebsitePresentationReader<T>, parent: WebComponentDefaults<T
|
|
30
|
+
export declare function parseComponentDefaults<T extends ReadonlyArray<string>>(websiteReader: WebsitePresentationReader<T>, parent: WebComponentDefaults<T>, websiteUuid: string): WebComponentDefaults<T>;
|
|
28
31
|
/**
|
|
29
32
|
What every component parser is handed
|
|
30
33
|
*/
|
|
@@ -125,18 +125,23 @@ const ELEMENT_TARGET_LABELS = [
|
|
|
125
125
|
/**
|
|
126
126
|
Reads the "customize-special" "element" properties of a website, each
|
|
127
127
|
holding "component" properties whose settings every element of that
|
|
128
|
-
component starts from
|
|
128
|
+
component starts from
|
|
129
129
|
|
|
130
130
|
@param websiteReader - Reader over the website's "presentation" properties
|
|
131
131
|
@param parent - The defaults of the enclosing website, which these extend
|
|
132
|
+
@param websiteUuid - The website's UUID, for error messages
|
|
132
133
|
@returns The component defaults in effect for the website's elements
|
|
134
|
+
@throws When a default sets one of {@link ELEMENT_TARGET_LABELS}, which
|
|
135
|
+
every element has to set itself
|
|
133
136
|
*/
|
|
134
|
-
function parseComponentDefaults(websiteReader, parent) {
|
|
137
|
+
function parseComponentDefaults(websiteReader, parent, websiteUuid) {
|
|
135
138
|
const elementReaders = websiteReader.nestedAllByValue("customize-special", "element");
|
|
136
139
|
if (elementReaders.length === 0) return parent;
|
|
137
140
|
const defaults = { ...parent };
|
|
138
141
|
for (const component of componentSchema.options) for (const elementReader of elementReaders) {
|
|
139
|
-
const componentProperties = elementReader.propertyByValue("component", component)?.properties
|
|
142
|
+
const componentProperties = elementReader.propertyByValue("component", component)?.properties;
|
|
143
|
+
const targetLabel = ELEMENT_TARGET_LABELS.find((label) => getProperty(componentProperties ?? [], { label }) != null);
|
|
144
|
+
if (targetLabel != null) throw new Error(`Component defaults cannot set \u{201C}${targetLabel}\u{201D}, which each element sets itself (component \u{201C}${component}\u{201D}, website uuid \u{201C}${websiteUuid}\u{201D})`, { cause: componentProperties });
|
|
140
145
|
if (componentProperties != null && componentProperties.length > 0) {
|
|
141
146
|
defaults[component] = [componentProperties, ...parent[component] ?? []];
|
|
142
147
|
break;
|
|
@@ -302,7 +302,7 @@ function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
|
|
|
302
302
|
const treeContext = {
|
|
303
303
|
...context,
|
|
304
304
|
pageSlugs: context.pageSlugs ?? collectWebsitePageSlugs(pages, options),
|
|
305
|
-
componentDefaults: parseComponentDefaults(websiteReader, context.componentDefaults)
|
|
305
|
+
componentDefaults: parseComponentDefaults(websiteReader, context.componentDefaults, websiteTree.uuid)
|
|
306
306
|
};
|
|
307
307
|
const sidebar = parseSidebar(resources, options, treeContext);
|
|
308
308
|
const properties = parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, context.parentProperties ?? null, treeContext.componentDefaults);
|
package/dist/types/website.d.mts
CHANGED
|
@@ -203,7 +203,7 @@ export type Website<T extends LanguageCodes = LanguageCodes> = {
|
|
|
203
203
|
component name: the "component" properties of this website, then of each
|
|
204
204
|
enclosing one, which an element overrides by setting the property itself.
|
|
205
205
|
The settings naming what an element points at ("link-to", "navigate-to",
|
|
206
|
-
and "bound-element")
|
|
206
|
+
and "bound-element") cannot be defaults, since every element sets its own.
|
|
207
207
|
*/
|
|
208
208
|
componentDefaults: Partial<Record<WebElementComponentName, Array<Array<SimplifiedProperty<T>>>>>;
|
|
209
209
|
itemPage: {
|