ochre-sdk 1.0.50 → 1.0.52

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.
@@ -233,6 +233,60 @@ function parseStylesheets(styles) {
233
233
  return parsedStyles;
234
234
  }
235
235
  /**
236
+ * Default values for a collection's display properties, shared between the
237
+ * "collection" component and the "query" component's collection overrides.
238
+ */
239
+ const COLLECTION_PROPERTY_DEFAULTS = {
240
+ variant: "slide",
241
+ paginationVariant: "default",
242
+ loadingVariant: "skeleton",
243
+ imageLayout: "start",
244
+ isImagePlaceholderDisplayed: true,
245
+ minimumColumnCount: null,
246
+ maximumColumnCount: null,
247
+ expectedItemCount: null,
248
+ isSortDisplayed: false,
249
+ isUsingQueryParams: false,
250
+ isInteractive: true
251
+ };
252
+ /**
253
+ * Reads the collection display properties explicitly set on a reader, omitting
254
+ * any that are unset. The "collection" component merges these over
255
+ * {@link COLLECTION_PROPERTY_DEFAULTS}, while the "query" component uses them as
256
+ * partial overrides for its embedded collection.
257
+ */
258
+ function parseCollectionPropertyOverrides(reader) {
259
+ const overrides = {};
260
+ function read(key, label) {
261
+ const value = reader.value(label);
262
+ if (value != null) overrides[key] = value;
263
+ }
264
+ read("variant", "variant");
265
+ read("paginationVariant", "pagination-variant");
266
+ read("loadingVariant", "loading-variant");
267
+ read("imageLayout", "image-layout");
268
+ read("isImagePlaceholderDisplayed", "image-placeholder-displayed");
269
+ read("minimumColumnCount", "minimum-column-count");
270
+ read("maximumColumnCount", "maximum-column-count");
271
+ read("expectedItemCount", "item-count");
272
+ read("isSortDisplayed", "sort-displayed");
273
+ read("isUsingQueryParams", "is-using-query-params");
274
+ read("isInteractive", "is-interactive");
275
+ return overrides;
276
+ }
277
+ /**
278
+ * Parses the "use-property" values defining which item properties a collection
279
+ * displays, returning `null` when none are set.
280
+ */
281
+ function parseCollectionDisplayedProperties(reader) {
282
+ const property = reader.property("use-property");
283
+ if (property == null) return null;
284
+ return property.values.filter((value) => value.uuid !== null).map((value) => ({
285
+ uuid: value.uuid,
286
+ label: value.label
287
+ }));
288
+ }
289
+ /**
236
290
  * Parses raw web element properties into a standardized WebElementComponent structure
237
291
  *
238
292
  * @param componentProperty - Raw component property data in OCHRE format
@@ -314,14 +368,13 @@ function parseWebElementProperties(componentProperty, elementResource, options,
314
368
  break;
315
369
  }
316
370
  case "bibliography": {
317
- const itemLinks = websiteLinks.filter((link) => link.category === "bibliography");
318
371
  const bibliographies = parseBibliographyList(elementResource.bibliographies, options);
319
- if (itemLinks.length === 0 && bibliographies.length === 0) throw new Error(formatComponentError("No links found", componentName, elementResource), { cause: componentProperty });
372
+ if (websiteLinks.length === 0 && bibliographies.length === 0) throw new Error(formatComponentError("No links found", componentName, elementResource), { cause: componentProperty });
320
373
  const layout = componentReader.valueOr("layout", "long");
321
374
  const isSourceDocumentDisplayed = componentReader.valueOr("source-document-displayed", true);
322
375
  properties = {
323
376
  component: "bibliography",
324
- linkUuids: itemLinks.map((link) => link.uuid),
377
+ linkUuids: websiteLinks.map((link) => link.uuid),
325
378
  bibliographies,
326
379
  layout,
327
380
  isSourceDocumentDisplayed
@@ -369,39 +422,19 @@ function parseWebElementProperties(componentProperty, elementResource, options,
369
422
  case "collection": {
370
423
  const setLinks = getWebsiteLinks(websiteLinks, "set");
371
424
  if (setLinks.length === 0) throw new Error(formatComponentError("Set links not found", componentName, elementResource), { cause: componentProperty });
372
- const displayedProperties = componentReader.property("use-property");
373
- const variant = componentReader.valueOr("variant", "slide");
374
- const paginationVariant = componentReader.valueOr("pagination-variant", "default");
375
- const loadingVariant = componentReader.valueOr("loading-variant", "skeleton");
376
- const expectedItemCount = componentReader.valueOr("item-count", null);
377
- const isUsingQueryParams = componentReader.valueOr("is-using-query-params", false);
378
425
  const isFilterResultsBarDisplayed = componentReader.valueOr("filter-results-bar-displayed", false);
379
426
  const isFilterInputDisplayed = componentReader.valueOr("filter-input-displayed", false);
380
427
  const isFilterLimitedToInputFilter = componentReader.valueOr("filter-limit-to-input-filter", false);
381
428
  const isFilterLimitedToLeafPropertyValues = componentReader.valueOr("filter-limit-to-leaf-property-values", false);
382
- const isSortDisplayed = componentReader.valueOr("sort-displayed", false);
383
429
  const isFilterSidebarDisplayed = componentReader.valueOr("filter-sidebar-displayed", false);
384
430
  const filterSidebarSort = componentReader.valueOr("filter-sidebar-sort", "default");
385
- const imageLayout = componentReader.valueOr("image-layout", "start");
386
- const isImagePlaceholderDisplayed = componentReader.valueOr("image-placeholder-displayed", true);
387
- const isInteractive = componentReader.valueOr("is-interactive", true);
388
431
  const componentOptions = parseWebsiteOptions(elementResource.options, options);
389
432
  properties = {
390
433
  component: "collection",
391
434
  linkUuids: setLinks.map((link) => link.uuid),
392
- displayedProperties: displayedProperties?.values.filter(({ uuid }) => uuid !== null).map((value) => ({
393
- uuid: value.uuid,
394
- label: value.label
395
- })) ?? null,
396
- variant,
397
- paginationVariant,
398
- loadingVariant,
399
- imageLayout,
400
- isImagePlaceholderDisplayed,
401
- expectedItemCount,
402
- isSortDisplayed,
403
- isUsingQueryParams,
404
- isInteractive,
435
+ displayedProperties: parseCollectionDisplayedProperties(componentReader),
436
+ ...COLLECTION_PROPERTY_DEFAULTS,
437
+ ...parseCollectionPropertyOverrides(componentReader),
405
438
  filter: {
406
439
  isSidebarDisplayed: isFilterSidebarDisplayed,
407
440
  isResultsBarDisplayed: isFilterResultsBarDisplayed,
@@ -602,31 +635,9 @@ function parseWebElementProperties(componentProperty, elementResource, options,
602
635
  }
603
636
  if (items.length === 0) throw new Error(formatComponentError("No queries found", componentName, elementResource), { cause: componentProperty });
604
637
  const componentOptions = parseWebsiteOptions(elementResource.options, options);
605
- const collectionProperties = {};
606
- const displayedProperties = componentReader.property("use-property");
607
- if (displayedProperties != null) collectionProperties.displayedProperties = displayedProperties.values.filter((value) => value.uuid !== null).map((value) => ({
608
- uuid: value.uuid,
609
- label: value.label
610
- }));
611
- const overrideReader = componentReader.nestedByValue("sub-component-override", "collection");
612
- const variant = overrideReader.value("variant");
613
- if (variant != null) collectionProperties.variant = variant;
614
- const paginationVariant = overrideReader.value("pagination-variant");
615
- if (paginationVariant != null) collectionProperties.paginationVariant = paginationVariant;
616
- const loadingVariant = overrideReader.value("loading-variant");
617
- if (loadingVariant != null) collectionProperties.loadingVariant = loadingVariant;
618
- const imageLayout = overrideReader.value("image-layout");
619
- if (imageLayout != null) collectionProperties.imageLayout = imageLayout;
620
- const isImagePlaceholderDisplayed = overrideReader.value("image-placeholder-displayed");
621
- if (isImagePlaceholderDisplayed != null) collectionProperties.isImagePlaceholderDisplayed = isImagePlaceholderDisplayed;
622
- const expectedItemCount = overrideReader.value("item-count");
623
- if (expectedItemCount != null) collectionProperties.expectedItemCount = expectedItemCount;
624
- const isSortDisplayed = overrideReader.value("sort-displayed");
625
- if (isSortDisplayed != null) collectionProperties.isSortDisplayed = isSortDisplayed;
626
- const isUsingQueryParams = overrideReader.value("is-using-query-params");
627
- if (isUsingQueryParams != null) collectionProperties.isUsingQueryParams = isUsingQueryParams;
628
- const isInteractive = overrideReader.value("is-interactive");
629
- if (isInteractive != null) collectionProperties.isInteractive = isInteractive;
638
+ const collectionProperties = parseCollectionPropertyOverrides(componentReader.nestedByValue("sub-component-override", "collection"));
639
+ const displayedProperties = parseCollectionDisplayedProperties(componentReader);
640
+ if (displayedProperties != null) collectionProperties.displayedProperties = displayedProperties;
630
641
  properties = {
631
642
  component: "query",
632
643
  linkUuids: setLinks.map((link) => link.uuid),
@@ -302,6 +302,8 @@ type WebElementComponent<T extends LanguageCodes = LanguageCodes> = {
302
302
  loadingVariant: "spinner" | "skeleton" | "animation" | "none";
303
303
  imageLayout: "top" | "bottom" | "start" | "end" | null;
304
304
  isImagePlaceholderDisplayed: boolean;
305
+ minimumColumnCount: number | null;
306
+ maximumColumnCount: number | null;
305
307
  expectedItemCount: number | null;
306
308
  isSortDisplayed: boolean;
307
309
  isUsingQueryParams: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
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",
@@ -47,19 +47,19 @@
47
47
  "dependencies": {
48
48
  "date-fns": "^4.4.0",
49
49
  "fast-equals": "^6.0.0",
50
- "fast-xml-parser": "^5.8.0",
50
+ "fast-xml-parser": "^5.9.0",
51
51
  "valibot": "^1.4.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@antfu/eslint-config": "^9.0.0",
55
55
  "@types/node": "^24.13.2",
56
56
  "bumpp": "^11.1.0",
57
- "eslint": "^10.4.1",
58
- "knip": "^6.16.1",
59
- "oxfmt": "^0.54.0",
57
+ "eslint": "^10.5.0",
58
+ "knip": "^6.17.1",
59
+ "oxfmt": "^0.55.0",
60
60
  "tsdown": "^0.22.2",
61
61
  "typescript": "^6.0.3",
62
- "vitest": "^4.1.8"
62
+ "vitest": "^4.1.9"
63
63
  },
64
64
  "scripts": {
65
65
  "dev": "tsdown src/index.ts --watch",