@crombolo/core 0.21.0 → 0.23.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/core",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "Domain model, entity keys and shared contracts for crombolo. No I/O.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -113,8 +113,15 @@ export const SYSTEM_MEDIA_TYPE_KEYS: Readonly<Record<'Folder' | 'Image' | 'File'
113
113
  File: '4c52d8ab-54e6-40cd-999c-7a5f24903e4d',
114
114
  }
115
115
 
116
+ /** "Caching" for media (story 057): a composition this CMS ships, never created as an item. */
117
+ export const MEDIA_CACHE_FIELDS_TYPE_KEY = '2d7c5e91-4a38-4f06-b1e2-8c9a0f3d6b57'
118
+ export const MEDIA_CACHE_KEEP_FOR_PROPERTY_KEY = '6e1d9b47-3a2c-4f85-8b06-d4c7a2e5f193'
119
+
116
120
  export function isSystemMediaType(key: string): boolean {
117
- return Object.values(SYSTEM_MEDIA_TYPE_KEYS).includes(key.toLowerCase())
121
+ const lower = key.toLowerCase()
122
+ return (
123
+ Object.values(SYSTEM_MEDIA_TYPE_KEYS).includes(lower) || lower === MEDIA_CACHE_FIELDS_TYPE_KEY
124
+ )
118
125
  }
119
126
 
120
127
  /**
@@ -131,8 +138,13 @@ export function isSystemMemberType(key: string): boolean {
131
138
  * Content types this CMS ships: always present, not deletable, alias fixed. A
132
139
  * site may add fields to one, but not remove or change the ones it ships with.
133
140
  */
134
- export const SYSTEM_CONTENT_TYPE_KEYS: Readonly<Record<'SeoFields', string>> = {
141
+ export const SYSTEM_CONTENT_TYPE_KEYS: Readonly<
142
+ Record<'SeoFields' | 'CacheFields' | 'Menu' | 'MenuItem', string>
143
+ > = {
135
144
  SeoFields: '5e0f1c2a-7b3d-4c8e-9a61-0d2b4f6e8a13',
145
+ CacheFields: '7a1e4c93-2b6d-4f58-a0c7-5d3e9b1f8a24',
146
+ Menu: '3c9e2f71-5a4d-4b86-9e13-7f0a2d6c8b45',
147
+ MenuItem: '8b4d1a26-6e3f-4c90-a7d5-2e9c0f4b7a18',
136
148
  }
137
149
 
138
150
  export function isSystemContentType(kind: 'document' | 'media' | 'member', key: string): boolean {
@@ -201,9 +213,41 @@ export const SEO_FIELDS_PROPERTIES: readonly SystemPropertyModel[] = [
201
213
  },
202
214
  ]
203
215
 
216
+ /** Where an editor chooses how long copies of a page or media item may be kept (story 057). */
217
+ export const CACHE_KEEP_FOR_ALIAS = 'cacheKeepFor'
218
+
219
+ /** The "Keep copies for" data type: a dropdown of `KEEP_COPIES_FOR` labels. */
220
+ export const KEEP_COPIES_FOR_DATA_TYPE_KEY = '4f2b8d61-9c0e-4a73-b5d8-1e6a3c7f9b02'
221
+
222
+ /** Each choice, as it is stored and shown, and its lifetime in seconds; none chosen is the site's. */
223
+ export const KEEP_COPIES_FOR: ReadonlyArray<{ label: string; seconds: number }> = [
224
+ { label: "Don't keep copies", seconds: 0 },
225
+ { label: '1 minute', seconds: 60 },
226
+ { label: '5 minutes', seconds: 300 },
227
+ { label: '1 hour', seconds: 3600 },
228
+ { label: '1 day', seconds: 86400 },
229
+ ]
230
+
231
+ /** The "Caching" composition's one field, the same for pages and media. */
232
+ export const CACHE_FIELDS_PROPERTIES: readonly SystemPropertyModel[] = [
233
+ {
234
+ key: '9b3e6f12-5d8a-4c07-8e41-2f7a0c9d6b13',
235
+ alias: CACHE_KEEP_FOR_ALIAS,
236
+ name: 'Keep copies for',
237
+ description:
238
+ "How long browsers and any service in front of the site may reuse a copy before asking again. Leave empty for the site's usual setting.",
239
+ dataTypeKey: KEEP_COPIES_FOR_DATA_TYPE_KEY,
240
+ },
241
+ ]
242
+
204
243
  /** The fields a system content type ships with, by the type's key. */
205
244
  export function systemContentTypeProperties(key: string): readonly SystemPropertyModel[] {
206
- return key.toLowerCase() === SYSTEM_CONTENT_TYPE_KEYS.SeoFields ? SEO_FIELDS_PROPERTIES : []
245
+ const lower = key.toLowerCase()
246
+ if (lower === SYSTEM_CONTENT_TYPE_KEYS.SeoFields) return SEO_FIELDS_PROPERTIES
247
+ if (lower === SYSTEM_CONTENT_TYPE_KEYS.CacheFields) return CACHE_FIELDS_PROPERTIES
248
+ if (lower === SYSTEM_CONTENT_TYPE_KEYS.Menu) return MENU_PROPERTIES
249
+ if (lower === SYSTEM_CONTENT_TYPE_KEYS.MenuItem) return MENU_ITEM_PROPERTIES
250
+ return []
207
251
  }
208
252
 
209
253
  /**
@@ -272,3 +316,78 @@ export interface Page<T> {
272
316
  total: number
273
317
  items: T[]
274
318
  }
319
+
320
+ /** A menu's "Alias", which templates name it by: `menu('header')` (story 141). */
321
+ export const MENU_ALIAS_PROPERTY = 'alias'
322
+
323
+ /** The "Menu items" data type: a block list of menu items, nested in each item too. */
324
+ export const MENU_ITEMS_DATA_TYPE_KEY = '5d2a8f47-1c6b-4e93-b0f4-8a3e7c2d9f61'
325
+
326
+ /** The "Menu link" data type: one page, media item or address. */
327
+ export const MENU_LINK_DATA_TYPE_KEY = '1f7c3b95-8d2e-4a64-9c0b-6e5d4a2f8c37'
328
+
329
+ /** The Menu element type's own fields. */
330
+ export const MENU_PROPERTIES: readonly SystemPropertyModel[] = [
331
+ {
332
+ key: '0a6f4d38-2c9b-4e71-8f5a-3d1b7e9c4a62',
333
+ alias: MENU_ALIAS_PROPERTY,
334
+ name: 'Alias',
335
+ description:
336
+ "What templates call this menu, such as header. Left empty, it is made from the menu's name when saved; renaming the menu later does not change it.",
337
+ dataTypeKey: '0cc0eba1-9960-42c9-bf9b-60e150b429ae',
338
+ },
339
+ {
340
+ key: '6e2b9c41-7f3a-4d58-b1c6-9a0e5d8f2b73',
341
+ alias: 'items',
342
+ name: 'Items',
343
+ description: 'Drag to reorder. Each item can hold items of its own.',
344
+ dataTypeKey: MENU_ITEMS_DATA_TYPE_KEY,
345
+ },
346
+ ]
347
+
348
+ /** The Menu item element type's fields. */
349
+ export const MENU_ITEM_PROPERTIES: readonly SystemPropertyModel[] = [
350
+ {
351
+ key: '4c8a1e57-3b6d-4f92-a0e8-7d2c5b9f1a84',
352
+ alias: 'link',
353
+ name: 'Link',
354
+ description:
355
+ 'A page, a media item or an address. Leave it empty for a heading that only holds the items below it.',
356
+ dataTypeKey: MENU_LINK_DATA_TYPE_KEY,
357
+ },
358
+ {
359
+ key: '9d3f6b28-1a7e-4c05-b8d2-5e4a0c7f3b95',
360
+ alias: 'label',
361
+ name: 'Label',
362
+ description: "Shown instead of the page's name. Needed when there is no link.",
363
+ dataTypeKey: '0cc0eba1-9960-42c9-bf9b-60e150b429ae',
364
+ },
365
+ {
366
+ key: '2b7e0c64-8f1d-4a39-9c5e-6a3d8b1f4e06',
367
+ alias: 'children',
368
+ name: 'Items below',
369
+ description: 'Shown under this item, as a submenu.',
370
+ dataTypeKey: MENU_ITEMS_DATA_TYPE_KEY,
371
+ },
372
+ ]
373
+
374
+ /**
375
+ * An alias made from a name as Umbraco's `ToSafeAlias` makes one: letters and
376
+ * digits only, words joined in camelCase, starting with a lowercase letter.
377
+ * "Main navigation" becomes `mainNavigation`. Pure.
378
+ */
379
+ export function safeAlias(name: string): string {
380
+ const words = name
381
+ .normalize('NFKD')
382
+ .replace(/[\u0300-\u036f]/g, '')
383
+ .split(/[^A-Za-z0-9]+/)
384
+ .filter(Boolean)
385
+ const joined = words
386
+ .map((word, i) =>
387
+ i === 0
388
+ ? word.charAt(0).toLowerCase() + word.slice(1)
389
+ : word.charAt(0).toUpperCase() + word.slice(1),
390
+ )
391
+ .join('')
392
+ return joined.replace(/^[0-9]+/, '')
393
+ }