@crombolo/render 0.44.0 → 0.46.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/values.ts +22 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/render",
3
- "version": "0.44.0",
3
+ "version": "0.46.1",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. TSX server rendering and the published-content model for crombolo.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -34,8 +34,8 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@crombolo/common": "0.44.0",
38
- "@crombolo/core": "0.44.0",
37
+ "@crombolo/common": "0.46.1",
38
+ "@crombolo/core": "0.46.1",
39
39
  "@types/react": "^19.3.0"
40
40
  }
41
41
  }
package/src/values.ts CHANGED
@@ -44,6 +44,8 @@ export interface Link {
44
44
 
45
45
  export interface BlockItem {
46
46
  contentKey: string
47
+ /** The name it was given on the page, unique within its property (story 253). */
48
+ alias: string | null
47
49
  content: PublishedElement
48
50
  settingsKey: string | null
49
51
  settings: PublishedElement | null
@@ -66,8 +68,21 @@ export interface BlockGridItem extends BlockItem {
66
68
  areas: BlockGridArea[]
67
69
  }
68
70
 
71
+ /** A block list's items, with the one given an alias picked out by it. */
72
+ export type BlockListValue<T extends BlockItem = BlockItem> = T[] & {
73
+ byAlias(alias: string): T | undefined
74
+ }
75
+
69
76
  /** A Block Grid's items, carrying the grid's column count for its markup. */
70
- export type BlockGridValue = BlockGridItem[] & { gridColumns: number }
77
+ export type BlockGridValue = BlockListValue<BlockGridItem> & { gridColumns: number }
78
+
79
+ /** Items with `byAlias`, which finds an alias in any case. */
80
+ function withAliases<T extends BlockItem>(items: T[]): BlockListValue<T> {
81
+ return Object.assign(items, {
82
+ byAlias: (alias: string) =>
83
+ items.find((item) => item.alias?.toLowerCase() === alias.toLowerCase()),
84
+ })
85
+ }
71
86
 
72
87
  const references = (value: unknown): string[] => {
73
88
  if (Array.isArray(value)) return value.flatMap((v) => (typeof v === 'string' ? [v] : []))
@@ -194,6 +209,7 @@ interface BlockData {
194
209
 
195
210
  interface BlockLayout {
196
211
  contentKey?: string
212
+ alias?: unknown
197
213
  settingsKey?: string | null
198
214
  columnSpan?: number
199
215
  rowSpan?: number
@@ -247,6 +263,7 @@ function blockItems<T extends BlockItem>(
247
263
  if (!content) return []
248
264
  const item: BlockItem = {
249
265
  contentKey: content.key,
266
+ alias: typeof layout.alias === 'string' && layout.alias ? layout.alias : null,
250
267
  content,
251
268
  settingsKey: layout.settingsKey ?? null,
252
269
  settings: elementFrom(settings.get(layout.settingsKey ?? ''), context),
@@ -449,7 +466,9 @@ export function convertValue(
449
466
  }),
450
467
  ).then((links) => links.filter((link): link is Link => link !== undefined))
451
468
  case 'Umbraco.BlockList':
452
- return blockItems<BlockItem>(value, 'Umbraco.BlockList', context, (_, item) => item)
469
+ return withAliases(
470
+ blockItems<BlockItem>(value, 'Umbraco.BlockList', context, (_, item) => item),
471
+ )
453
472
  case 'Umbraco.BlockGrid': {
454
473
  // What the data type says of each block type's areas: their aliases and spans.
455
474
  const blockTypes = Array.isArray(config.blocks) ? (config.blocks as GridBlockConfig[]) : []
@@ -484,7 +503,7 @@ export function convertValue(
484
503
  }
485
504
  },
486
505
  )
487
- return Object.assign(items, { gridColumns: Number(config.gridColumns) || 12 })
506
+ return Object.assign(withAliases(items), { gridColumns: Number(config.gridColumns) || 12 })
488
507
  }
489
508
  default:
490
509
  return value