ochre-sdk 1.3.27 → 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.
@@ -22,9 +22,12 @@ 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>): 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
  */
@@ -1,4 +1,5 @@
1
1
  import { normalizeItemCategory } from "../../categories.mjs";
2
+ import { getProperty } from "../../getters.mjs";
2
3
  import { parseStringContent } from "../helpers.mjs";
3
4
  import { parseBibliographyList, parseIdentification, parseLinks, parseSimplifiedProperties } from "../index.mjs";
4
5
  import { parseXMLContent, transformPermanentIdentificationUrlToItemLink } from "../string.mjs";
@@ -116,6 +117,11 @@ function parseCollectionRelations(reader) {
116
117
  }
117
118
  return relations;
118
119
  }
120
+ const ELEMENT_TARGET_LABELS = [
121
+ "link-to",
122
+ "navigate-to",
123
+ "bound-element"
124
+ ];
119
125
  /**
120
126
  Reads the "customize-special" "element" properties of a website, each
121
127
  holding "component" properties whose settings every element of that
@@ -123,14 +129,19 @@ component starts from
123
129
 
124
130
  @param websiteReader - Reader over the website's "presentation" properties
125
131
  @param parent - The defaults of the enclosing website, which these extend
132
+ @param websiteUuid - The website's UUID, for error messages
126
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
127
136
  */
128
- function parseComponentDefaults(websiteReader, parent) {
137
+ function parseComponentDefaults(websiteReader, parent, websiteUuid) {
129
138
  const elementReaders = websiteReader.nestedAllByValue("customize-special", "element");
130
139
  if (elementReaders.length === 0) return parent;
131
140
  const defaults = { ...parent };
132
141
  for (const component of componentSchema.options) for (const elementReader of elementReaders) {
133
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 });
134
145
  if (componentProperties != null && componentProperties.length > 0) {
135
146
  defaults[component] = [componentProperties, ...parent[component] ?? []];
136
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);
@@ -201,7 +201,9 @@ export type Website<T extends LanguageCodes = LanguageCodes> = {
201
201
  /**
202
202
  The settings every element of a component starts from, keyed by
203
203
  component name: the "component" properties of this website, then of each
204
- enclosing one, which an element overrides by setting the property itself
204
+ enclosing one, which an element overrides by setting the property itself.
205
+ The settings naming what an element points at ("link-to", "navigate-to",
206
+ and "bound-element") cannot be defaults, since every element sets its own.
205
207
  */
206
208
  componentDefaults: Partial<Record<WebElementComponentName, Array<Array<SimplifiedProperty<T>>>>>;
207
209
  itemPage: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.3.27",
3
+ "version": "1.3.29",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",