@crombolo/render 0.39.1 → 0.41.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/render",
3
- "version": "0.39.1",
3
+ "version": "0.41.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.39.1",
38
- "@crombolo/core": "0.39.1",
37
+ "@crombolo/common": "0.41.1",
38
+ "@crombolo/core": "0.41.1",
39
39
  "@types/react": "^19.3.0"
40
40
  }
41
41
  }
package/src/context.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  * rendering at once each see their own.
11
11
  */
12
12
  import { AsyncLocalStorage } from 'node:async_hooks'
13
+ import type { ActionState } from '@crombolo/common'
13
14
  import type { Child } from './jsx-runtime.ts'
14
15
  import type { PageProps } from './model.ts'
15
16
  import type { SiteSearchPort } from './search.ts'
@@ -40,6 +41,14 @@ interface RenderScope {
40
41
  metadata?: { value?: Metadata }
41
42
  /** Set once anything on the page renders an island, so the loader is linked (story 209). */
42
43
  islands?: { used: boolean }
44
+ /** The site's server actions, and what one answered the visitor just now (story 219). */
45
+ actions?: PageActions
46
+ }
47
+
48
+ /** A page's server actions: each one's id, and the result the visitor returned with. */
49
+ export interface PageActions {
50
+ idOf(action: unknown): string | undefined
51
+ flash?: { id: string; state: ActionState }
43
52
  }
44
53
 
45
54
  /** What `cookies()` and `headers()` read: the request's, or nothing for a static page. */
@@ -63,6 +72,7 @@ export interface RenderScopeOptions {
63
72
  personal?: { value: boolean }
64
73
  metadata?: { value?: Metadata }
65
74
  islands?: { used: boolean }
75
+ actions?: PageActions
66
76
  }
67
77
 
68
78
  /**
@@ -130,6 +140,51 @@ export function currentSiteSearch(): { page: PageProps; search: SiteSearchPort |
130
140
  return { page: scope.page, search: scope.search }
131
141
  }
132
142
 
143
+ /** The id a server action answers at, or undefined for any other function. */
144
+ export function actionIdOf(action: unknown): string | undefined {
145
+ return store.getStore()?.actions?.idOf(action)
146
+ }
147
+
148
+ /**
149
+ * The id a server action answers at, for `<form action={…}>` and an island's
150
+ * props (story 219); an action the config does not list fails the render.
151
+ */
152
+ export function actionIdFor(action: unknown, where: string): string {
153
+ const id = store.getStore()?.actions?.idOf(action)
154
+ if (id) return id
155
+ throw new Error(
156
+ `${where} is given a function that is not one of the site's server actions. List its module in \`actions\` in crombolo.config.ts (\`actions: { profile }\` after \`import * as profile from '#actions/profile.ts'\`), and import it from there.`,
157
+ )
158
+ }
159
+
160
+ /**
161
+ * Where an action's form returns, and the member's token: the hidden fields
162
+ * every action form carries.
163
+ */
164
+ export function actionFormFields(): { returnTo: string; antiforgery: string | undefined } {
165
+ const scope = store.getStore()
166
+ const url = scope?.page?.request.url
167
+ let returnTo = '/'
168
+ if (url) {
169
+ const parsed = new URL(url, 'http://localhost')
170
+ returnTo = `${parsed.pathname}${parsed.search}`
171
+ }
172
+ return { returnTo, antiforgery: scope?.page?.member ? scope.antiforgery : undefined }
173
+ }
174
+
175
+ /**
176
+ * What a server action answered, when the visitor has just been returned here
177
+ * from it (story 219): `undefined` on an ordinary visit. Reading it makes the
178
+ * page private, as reading cookies does.
179
+ */
180
+ export function actionState<T = unknown>(action: unknown): ActionState<T> | undefined {
181
+ const scope = within('actionState()')
182
+ const id = actionIdFor(action, 'actionState()')
183
+ if (scope.personal) scope.personal.value = true
184
+ const flash = scope.actions?.flash
185
+ return flash?.id === id ? (flash.state as ActionState<T>) : undefined
186
+ }
187
+
133
188
  /** The signed-in member's anti-forgery token for this render, or undefined for a visitor. */
134
189
  export function currentAntiforgery(): string | undefined {
135
190
  const scope = within('<AntiforgeryMeta />')
package/src/islands.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * generation, and `/crombolo/islands.js` mounts each island when it is needed.
7
7
  * docs/rendering.md, "Islands".
8
8
  */
9
- import { markIslands } from './context.ts'
9
+ import { actionIdOf, markIslands } from './context.ts'
10
10
  import { escapeHtml, RawHtml } from './html.ts'
11
11
  import { type Child, renderToString } from './jsx-runtime.ts'
12
12
 
@@ -56,10 +56,12 @@ export function serializeProps(props: Record<string, unknown>, island: string):
56
56
  throw new IslandPropsError(`${island}: ${path} is ${value}, which JSON cannot carry.`)
57
57
  return
58
58
  }
59
+ // A server action travels as its id, and the browser calls it (story 219).
60
+ if (typeof value === 'function' && actionIdOf(value)) return
59
61
  if (typeof value !== 'object') {
60
62
  const what = value === undefined ? 'undefined' : `a ${typeof value}`
61
63
  throw new IslandPropsError(
62
- `${island}: ${path} is ${what}; an island's props travel to the browser as JSON, so only data can be passed.`,
64
+ `${island}: ${path} is ${what}; an island's props travel to the browser as JSON, so only data, or one of the site's server actions, can be passed.`,
63
65
  )
64
66
  }
65
67
  if (seen.has(value))
@@ -80,7 +82,9 @@ export function serializeProps(props: Record<string, unknown>, island: string):
80
82
  seen.delete(value)
81
83
  }
82
84
  check(props, 'props')
83
- return JSON.stringify(props)
85
+ return JSON.stringify(props, (_key, value) =>
86
+ typeof value === 'function' ? { $action: actionIdOf(value) } : value,
87
+ )
84
88
  .replaceAll('<', '\\u003c')
85
89
  .replaceAll('>', '\\u003e')
86
90
  .replaceAll('&', '\\u0026')
@@ -43,12 +43,24 @@ export interface RuntimeAttributes {
43
43
  for?: string
44
44
  /** Dropped when rendered. */
45
45
  ref?: unknown
46
+ /**
47
+ * A form's address, or one of the site's server actions, which the form then
48
+ * posts to (story 219; docs/rendering.md, "Server actions").
49
+ */
50
+ action?: string | ActionLike | null
51
+ /** A button's or submit input's own address, or a server action, for that button alone. */
52
+ formAction?: string | ActionLike | null
46
53
  /** A page is static HTML, so a handler could never run. */
47
54
  [handler: `on${Capitalize<string>}`]: never
48
55
  }
49
56
 
57
+ /** Any server action: the form's data, and the context the server gives it. */
58
+ type ActionLike = (formData: FormData, context: never) => unknown
59
+
50
60
  /** Props React declares that mean nothing to a string renderer, or that are typed again above. */
51
61
  type Replaced =
62
+ | 'action'
63
+ | 'formAction'
52
64
  | 'children'
53
65
  | 'style'
54
66
  | 'ref'
@@ -9,6 +9,8 @@
9
9
  * promise, and from there hands back a promise of the markup instead, so a tree
10
10
  * without one renders exactly as it always has.
11
11
  */
12
+ import { ACTIONS_PATH } from '@crombolo/common'
13
+ import { actionFormFields, actionIdFor } from './context.ts'
12
14
  import { escapeHtml, RawHtml, serializeAttributes, VOID_ELEMENTS } from './html.ts'
13
15
  import type { CustomElementAttributes, KnownElements } from './jsx-attributes.ts'
14
16
 
@@ -260,6 +262,43 @@ function select(props: ElementProps): Html {
260
262
  return isPromise(html) ? html.then(check) : check(html)
261
263
  }
262
264
 
265
+ /**
266
+ * A form whose `action` is a server action posts to it, carrying where to
267
+ * return and the member's token; a button's or submit input's `formAction` posts
268
+ * its form to another (story 219). An unlisted function fails the render.
269
+ */
270
+ function withAction(type: string, props: ElementProps): ElementProps {
271
+ if (type === 'form' && typeof props.action === 'function') {
272
+ const id = actionIdFor(props.action, '<form action>')
273
+ const { returnTo, antiforgery } = actionFormFields()
274
+ const hidden = [
275
+ jsx('input', { type: 'hidden', name: '__return', value: returnTo }),
276
+ ...(antiforgery
277
+ ? [jsx('input', { type: 'hidden', name: '__antiforgery', value: antiforgery })]
278
+ : []),
279
+ ]
280
+ const { encType, enctype, ...rest } = props
281
+ return {
282
+ ...rest,
283
+ action: `${ACTIONS_PATH}/${id}`,
284
+ method: 'post',
285
+ enctype: enctype ?? encType ?? 'multipart/form-data',
286
+ children: [...hidden, props.children as Child],
287
+ }
288
+ }
289
+ if ((type === 'button' || type === 'input') && typeof props.formAction === 'function') {
290
+ const id = actionIdFor(props.formAction, `<${type} formAction>`)
291
+ const { formAction: _, formEncType, formenctype, ...rest } = props
292
+ return {
293
+ ...rest,
294
+ formaction: `${ACTIONS_PATH}/${id}`,
295
+ formmethod: 'post',
296
+ formenctype: formenctype ?? formEncType ?? 'multipart/form-data',
297
+ }
298
+ }
299
+ return props
300
+ }
301
+
263
302
  export function jsx(type: string | Component | typeof Fragment, props: ElementProps | null): Html {
264
303
  const actual = props ?? {}
265
304
 
@@ -276,7 +315,7 @@ export function jsx(type: string | Component | typeof Fragment, props: ElementPr
276
315
  `The "${name}" attribute of <${type}> is a promise. Await it before rendering the element.`,
277
316
  )
278
317
  }
279
- const attributes = formControl(type, actual)
318
+ const attributes = formControl(type, withAction(type, actual))
280
319
  if (type === 'optgroup') return optgroup(attributes)
281
320
  const open = `<${type}${serializeAttributes(attributes, type)}`
282
321
  if (VOID_ELEMENTS.has(type)) return new RawHtml(`${open} />`)
package/src/model.ts CHANGED
@@ -311,6 +311,12 @@ export interface PageProps<Properties = any> {
311
311
  * Empty when there is no such menu (story 141; docs/rendering.md, "Menus").
312
312
  */
313
313
  menu: (alias: string) => MenuItem[]
314
+ /**
315
+ * The site's settings page: its root's child of a settings type, or `null`
316
+ * when the site has none (story 058; docs/rendering.md, "Site settings").
317
+ */
318
+ // biome-ignore lint/suspicious/noExplicitAny: typed by the site's own settings type.
319
+ settings: PublishedContent<any> | null
314
320
  /** The signed-in member, or undefined for an anonymous visitor. */
315
321
  member: RequestMember | undefined
316
322
  /**
@@ -365,4 +371,6 @@ export interface Navigation {
365
371
  * query builder writes `nav.byKey('…')` for exactly that.
366
372
  */
367
373
  byKey(key: string): PublishedContent | undefined
374
+ /** Whether the page is a site's settings, which has no address (story 058). */
375
+ isSettings?(content: PublishedContent): boolean
368
376
  }
@@ -85,6 +85,8 @@ export interface PublishedContentSource {
85
85
  loadElements?(): Promise<PublishedElementNode[]>
86
86
  /** Content type aliases by key, so a block knows its element type; none when omitted. */
87
87
  loadContentTypeAliases?(): Promise<Map<string, string>>
88
+ /** The aliases of the content types that are a site's settings (story 058). */
89
+ loadSiteSettingsTypes?(): Promise<string[]>
88
90
  /** How URLs are built; Umbraco's defaults when omitted. */
89
91
  loadUrlOptions?(): Promise<PublishedUrlOptions>
90
92
  /**
@@ -157,6 +159,19 @@ export interface CultureView {
157
159
  childrenOf: Map<number, PublishedContent[]>
158
160
  roots: PublishedContent[]
159
161
  parentIdOf: Map<number, number>
162
+ /** Each root's settings page, by the root's id (story 058). */
163
+ settings: Map<number, PublishedContent>
164
+ /** Every page of a settings type in this view, by lowercase key. */
165
+ settingsKeys: Set<string>
166
+ }
167
+
168
+ /** A page of a settings type that is not, or not alone, its site's settings. */
169
+ export interface SiteSettingsFinding {
170
+ kind: 'second' | 'deep'
171
+ key: string
172
+ name: string
173
+ /** The settings page that counts, for a second one. */
174
+ counted?: string
160
175
  }
161
176
 
162
177
  export interface DictionaryOutlineItem {
@@ -189,6 +204,8 @@ export interface CacheSnapshot {
189
204
  dictionaryOutline: DictionaryOutlineItem[]
190
205
  /** Content type key (lowercase) → alias. */
191
206
  contentTypeAliases: Map<string, string>
207
+ /** Pages of a settings type that are not, or not alone, a site's settings. */
208
+ settingsFindings: SiteSettingsFinding[]
192
209
  /**
193
210
  * The content checkpoint whose changes this snapshot holds (story 174): every
194
211
  * change numbered at or below it, and none above. Absent from a source that
@@ -241,6 +258,7 @@ const EMPTY: CacheSnapshot = {
241
258
  dictionary: new Map(),
242
259
  dictionaryOutline: [],
243
260
  contentTypeAliases: new Map(),
261
+ settingsFindings: [],
244
262
  }
245
263
 
246
264
  const normaliseRoute = (route: string) =>
@@ -285,6 +303,11 @@ export interface PublishedCacheOptions {
285
303
  * menus look items up here. Without one, nothing resolves to media.
286
304
  */
287
305
  media?: MediaCache
306
+ /**
307
+ * How long a reader waits for a rebuild when there is a previous snapshot to
308
+ * answer from instead (story 230). 50 ms by default.
309
+ */
310
+ readerGraceMs?: number
288
311
  }
289
312
 
290
313
  const NO_MEDIA = () => Promise.resolve(undefined)
@@ -310,6 +333,10 @@ const menuAliasOf = (element: PublishedElement) => {
310
333
  return typeof own === 'string' ? own.trim().toLowerCase() : undefined
311
334
  }
312
335
 
336
+ /** A page a menu names, unless it is a site's settings, which has no address (story 058). */
337
+ const menuPage = (view: CultureView, key: string): PublishedContent | undefined =>
338
+ view.settingsKeys.has(key.toLowerCase()) ? undefined : view.byKey.get(key.toLowerCase())
339
+
313
340
  /** The menu published under `alias` in a view, its media looked up in one query. */
314
341
  export async function menuIn(
315
342
  view: CultureView,
@@ -321,7 +348,7 @@ export async function menuIn(
321
348
  if (!element) return undefined
322
349
  const items = media ? await media.byKeys(menuMediaKeys(element)) : new Map()
323
350
  return buildMenu(element, {
324
- content: (key) => view.byKey.get(key.toLowerCase()),
351
+ content: (key) => menuPage(view, key),
325
352
  media: (key) => items.get(key.toLowerCase()),
326
353
  })
327
354
  }
@@ -342,7 +369,7 @@ export async function menusIn(
342
369
  out.set(
343
370
  alias,
344
371
  buildMenu(element, {
345
- content: (key) => view.byKey.get(key.toLowerCase()),
372
+ content: (key) => menuPage(view, key),
346
373
  media: (key) => items.get(key.toLowerCase()),
347
374
  }),
348
375
  )
@@ -388,18 +415,29 @@ export class PublishedCache {
388
415
  }
389
416
 
390
417
  /**
391
- * The current snapshot, building it if it was dropped. The reader that starts
392
- * a build, or queues the one after it, waits for it; readers arriving while
393
- * one builds are answered from the previous snapshot rather than waiting
394
- * (story 175). Before the first build there is none, so they share the build.
418
+ * The current snapshot, building it if it was dropped. Readers arriving while
419
+ * one builds are answered from the previous snapshot (story 175); the reader
420
+ * that starts a build, or queues the one after it, waits for it only for the
421
+ * grace, then is answered from the previous snapshot too (story 230). Before
422
+ * the first build there is none, so they share the build.
395
423
  */
396
424
  async snapshot(): Promise<CacheSnapshot> {
397
425
  if (this.#loaded) return this.#snapshot
398
426
  const generation = this.#generation
399
427
  const previous = this.#snapshotGeneration >= 0 ? this.#snapshot : undefined
400
428
  if (this.#building?.generation === generation) return previous ?? this.#building.done
401
- if (this.#building) return this.#next && previous ? previous : this.#followUp()
402
- return this.#start(generation)
429
+ if (this.#building && this.#next && previous) return previous
430
+ const build = this.#building ? this.#followUp() : this.#start(generation)
431
+ return previous ? this.#within(build, previous) : build
432
+ }
433
+
434
+ /** The build if it finishes within the grace, otherwise the previous snapshot. */
435
+ #within(build: Promise<CacheSnapshot>, previous: CacheSnapshot): Promise<CacheSnapshot> {
436
+ let timer: ReturnType<typeof setTimeout> | undefined
437
+ const grace = new Promise<CacheSnapshot>((resolve) => {
438
+ timer = setTimeout(() => resolve(previous), this.#options.readerGraceMs ?? 50)
439
+ })
440
+ return Promise.race([build, grace]).finally(() => clearTimeout(timer))
403
441
  }
404
442
 
405
443
  /** Whether readers are being answered from a snapshot older than the latest change. */
@@ -698,6 +736,52 @@ export class PublishedCache {
698
736
  return urlsIn(await this.snapshot(), key).map(({ culture, url }) => ({ culture, url }))
699
737
  }
700
738
 
739
+ /**
740
+ * A site's settings page (story 058): the first child of a settings type under
741
+ * the root with `rootKey`, else under the first root.
742
+ */
743
+ async settings(
744
+ rootKey: string | null,
745
+ culture?: string | null,
746
+ ): Promise<PublishedContent | undefined> {
747
+ const view = this.#view(await this.snapshot(), culture)
748
+ if (!view) return undefined
749
+ const root = rootKey ? view.byKey.get(rootKey.toLowerCase()) : view.roots[0]
750
+ return root ? view.settings.get(root.id) : undefined
751
+ }
752
+
753
+ /** The key of the root a hostname serves, when one does. */
754
+ async rootForHost(host: string): Promise<string | undefined> {
755
+ const snapshot = await this.snapshot()
756
+ const best = this.#domainFor(snapshot, host, '/')
757
+ if (!best) return undefined
758
+ const view = this.#view(snapshot, best.domain.isoCode)
759
+ let id: number | undefined = best.domain.nodeId
760
+ let top: PublishedContent | undefined
761
+ while (id !== undefined && view?.byId.has(id)) {
762
+ top = view.byId.get(id)
763
+ id = view.parentIdOf.get(id)
764
+ }
765
+ return top?.key
766
+ }
767
+
768
+ /** Pages of a settings type that are not, or not alone, their site's settings. */
769
+ async settingsFindings(): Promise<SiteSettingsFinding[]> {
770
+ return (await this.snapshot()).settingsFindings
771
+ }
772
+
773
+ /** Every dictionary item in `culture`, each falling back as `dictionary` does. */
774
+ async dictionaryEntries(
775
+ culture: string | null,
776
+ keys?: readonly string[],
777
+ ): Promise<Record<string, string>> {
778
+ const snapshot = await this.snapshot()
779
+ const out: Record<string, string> = {}
780
+ const wanted = keys ?? snapshot.dictionaryOutline.map((item) => item.name)
781
+ for (const key of wanted) out[key] = translate(snapshot, key, culture)
782
+ return out
783
+ }
784
+
701
785
  /** A dictionary item's translation in `culture`, then its fallback languages; '' when none. */
702
786
  async dictionary(key: string, culture: string | null): Promise<string> {
703
787
  const snapshot = await this.snapshot()
@@ -711,6 +795,7 @@ export class PublishedCache {
711
795
  const byKey = view?.byKey ?? new Map<string, PublishedContent>()
712
796
  const parentIdOf = view?.parentIdOf ?? new Map<number, number>()
713
797
  return {
798
+ isSettings: (content) => view?.settingsKeys.has(content.key.toLowerCase()) ?? false,
714
799
  parent: (content) => {
715
800
  const parentId = parentIdOf.get(content.id)
716
801
  return parentId === undefined ? undefined : byId.get(parentId)
@@ -791,12 +876,37 @@ export class PublishedCache {
791
876
  alias,
792
877
  ]),
793
878
  )
879
+ // Story 058: a settings type's pages have no address; a root's first child of
880
+ // one is that site's settings.
881
+ const settingsTypes = new Set(
882
+ ((await source.loadSiteSettingsTypes?.()) ?? []).map((alias) => alias.toLowerCase()),
883
+ )
884
+ const isSettings = (node: PublishedNode) =>
885
+ settingsTypes.has(node.contentTypeAlias.toLowerCase())
794
886
  const defaultCulture =
795
887
  languages.find((l) => l.isDefault)?.isoCode ?? languages[0]?.isoCode ?? null
796
888
  const cultures: Array<string | null> =
797
889
  languages.length > 0 ? languages.map((l) => l.isoCode) : [null]
798
890
 
799
891
  const nodeById = new Map(nodes.map((node) => [node.id, node]))
892
+ const settingsFindings: SiteSettingsFinding[] = []
893
+ const countedFor = new Map<number, PublishedNode>()
894
+ for (const node of [...nodes].filter(isSettings).sort((a, b) => a.sortOrder - b.sortOrder)) {
895
+ const parent = nodeById.get(node.parentId)
896
+ if (!parent || parent.parentId > 0) {
897
+ settingsFindings.push({ kind: 'deep', key: node.key, name: node.name })
898
+ continue
899
+ }
900
+ const counted = countedFor.get(parent.id)
901
+ if (counted)
902
+ settingsFindings.push({
903
+ kind: 'second',
904
+ key: node.key,
905
+ name: node.name,
906
+ counted: counted.name,
907
+ })
908
+ else countedFor.set(parent.id, node)
909
+ }
800
910
  const domainsOf = new Map<number, PublishedDomain[]>()
801
911
  for (const domain of domains)
802
912
  if (!domain.isWildcard)
@@ -845,7 +955,7 @@ export class PublishedCache {
845
955
  const segmentOf = new Map<number, string>()
846
956
  for (const node of nodes) {
847
957
  await pace()
848
- if (!inCulture(node)) continue
958
+ if (!inCulture(node) || isSettings(node)) continue
849
959
  const override =
850
960
  node.properties.find(
851
961
  (p) =>
@@ -914,29 +1024,21 @@ export class PublishedCache {
914
1024
  childrenOf: new Map(),
915
1025
  roots: [],
916
1026
  parentIdOf: new Map(),
1027
+ settings: new Map(),
1028
+ settingsKeys: new Set(),
917
1029
  }
918
1030
  const isDefault = viewKey(culture) === viewKey(defaultCulture)
919
1031
  // Shallow and first-sorted nodes claim a route before any that collide with it.
920
1032
  const ordered = [...nodes]
921
1033
  .filter(inCulture)
922
1034
  .sort((a, b) => a.level - b.level || a.sortOrder - b.sortOrder)
923
- for (const node of ordered) {
924
- await pace()
925
- const route = routeOf(node)
926
- if (route === undefined) continue
927
- const domainRoute = domainRouteOf(node)
928
- const variant = node.cultures.length > 0
929
- const url = domainRoute
930
- ? `//${domainRoute.domain.domainName}${domainRoute.route === '/' ? '/' : domainRoute.route}`
931
- : isDefault || !variant
932
- ? route
933
- : '#'
934
- const content = new PublishedContent({
1035
+ const contentOf = (node: PublishedNode, url: string, urlSegment: string) =>
1036
+ new PublishedContent({
935
1037
  key: node.key,
936
1038
  id: node.id,
937
1039
  name: nameIn(node),
938
1040
  contentTypeAlias: node.contentTypeAlias,
939
- urlSegment: segmentOf.get(node.id) as string,
1041
+ urlSegment,
940
1042
  url,
941
1043
  level: node.level,
942
1044
  path: node.path,
@@ -946,9 +1048,32 @@ export class PublishedCache {
946
1048
  componentAlias: node.componentAlias,
947
1049
  cultures: node.cultures,
948
1050
  properties: node.properties,
949
- variationCulture: variant ? culture : null,
1051
+ variationCulture: node.cultures.length > 0 ? culture : null,
950
1052
  languageFallback: fallbackChain(languages, culture),
951
1053
  })
1054
+ for (const node of ordered) {
1055
+ await pace()
1056
+ if (isSettings(node)) {
1057
+ // Found by key and as its root's settings, and nowhere a visitor goes.
1058
+ const content = contentOf(node, '#', urlSegmentFor(nameIn(node), null))
1059
+ view.byId.set(node.id, content)
1060
+ view.byKey.set(node.key.toLowerCase(), content)
1061
+ view.settingsKeys.add(node.key.toLowerCase())
1062
+ if (nodeById.has(node.parentId)) view.parentIdOf.set(node.id, node.parentId)
1063
+ if (countedFor.get(node.parentId)?.id === node.id)
1064
+ view.settings.set(node.parentId, content)
1065
+ continue
1066
+ }
1067
+ const route = routeOf(node)
1068
+ if (route === undefined) continue
1069
+ const domainRoute = domainRouteOf(node)
1070
+ const variant = node.cultures.length > 0
1071
+ const url = domainRoute
1072
+ ? `//${domainRoute.domain.domainName}${domainRoute.route === '/' ? '/' : domainRoute.route}`
1073
+ : isDefault || !variant
1074
+ ? route
1075
+ : '#'
1076
+ const content = contentOf(node, url, segmentOf.get(node.id) as string)
952
1077
  view.byId.set(node.id, content)
953
1078
  view.byKey.set(node.key.toLowerCase(), content)
954
1079
  for (const alias of urlAliasesOf(node, culture)) {
@@ -1071,6 +1196,7 @@ export class PublishedCache {
1071
1196
  dictionary,
1072
1197
  dictionaryOutline,
1073
1198
  contentTypeAliases,
1199
+ settingsFindings,
1074
1200
  ...(checkpoint === undefined ? {} : { checkpoint }),
1075
1201
  builtAt,
1076
1202
  }
package/src/renderer.ts CHANGED
@@ -11,7 +11,7 @@ import { basename, join, resolve, sep } from 'node:path'
11
11
  import { pathToFileURL } from 'node:url'
12
12
  import { type FormSubmissionState, isOutcome, type Outcome } from '@crombolo/core'
13
13
  import { componentStackOf, trackComponent } from './component-stack.ts'
14
- import { emailScope, markPersonal, renderScope } from './context.ts'
14
+ import { emailScope, markPersonal, type PageActions, renderScope } from './context.ts'
15
15
  import type { EmailProps, EmailRenderResult } from './email.ts'
16
16
  import { RawHtml } from './html.ts'
17
17
  import { ISLANDS_PATH, withIslandTags } from './islands.ts'
@@ -138,6 +138,8 @@ export interface RenderRequest {
138
138
  preview?: boolean
139
139
  /** The signed-in member's anti-forgery token, written by `<AntiforgeryMeta />` (story 186). */
140
140
  antiforgery?: string
141
+ /** The site's server actions, and what one answered the visitor with (story 219). */
142
+ actions?: PageActions
141
143
  /** The request's headers, cookies among them, for `cookies()` and `headers()` (story 206). */
142
144
  headers?: Headers
143
145
  /** The site's services as whoever is asking, for `site()`. */
@@ -472,6 +474,8 @@ export class Renderer {
472
474
  // and `menu()` stays synchronous for the views.
473
475
  const menus = await this.#cache.menus(culture)
474
476
  const menu = (alias: string) => menus.get(alias.trim().toLowerCase())?.items ?? []
477
+ const root = nav.ancestors(content).at(-1) ?? content
478
+ const settings = (await this.#cache.settings(root.key, culture)) ?? null
475
479
  const origin = (request.origin ?? 'http://localhost').replace(/\/$/, '')
476
480
  const props: PageProps = {
477
481
  model: content,
@@ -479,6 +483,7 @@ export class Renderer {
479
483
  culture,
480
484
  dictionary,
481
485
  menu,
486
+ settings,
482
487
  member,
483
488
  submission: request.submission,
484
489
  request: { origin, url: request.url ?? `${origin}/` },
@@ -514,6 +519,7 @@ export class Renderer {
514
519
  personal: shared ? { value: false } : personal,
515
520
  metadata,
516
521
  islands,
522
+ actions: request.actions,
517
523
  },
518
524
  )
519
525
  if (html === undefined || !islands.used) return html