@crombolo/render 0.39.1 → 0.40.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/render",
3
- "version": "0.39.1",
3
+ "version": "0.40.0",
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.40.0",
38
+ "@crombolo/core": "0.40.0",
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) =>
@@ -310,6 +328,10 @@ const menuAliasOf = (element: PublishedElement) => {
310
328
  return typeof own === 'string' ? own.trim().toLowerCase() : undefined
311
329
  }
312
330
 
331
+ /** A page a menu names, unless it is a site's settings, which has no address (story 058). */
332
+ const menuPage = (view: CultureView, key: string): PublishedContent | undefined =>
333
+ view.settingsKeys.has(key.toLowerCase()) ? undefined : view.byKey.get(key.toLowerCase())
334
+
313
335
  /** The menu published under `alias` in a view, its media looked up in one query. */
314
336
  export async function menuIn(
315
337
  view: CultureView,
@@ -321,7 +343,7 @@ export async function menuIn(
321
343
  if (!element) return undefined
322
344
  const items = media ? await media.byKeys(menuMediaKeys(element)) : new Map()
323
345
  return buildMenu(element, {
324
- content: (key) => view.byKey.get(key.toLowerCase()),
346
+ content: (key) => menuPage(view, key),
325
347
  media: (key) => items.get(key.toLowerCase()),
326
348
  })
327
349
  }
@@ -342,7 +364,7 @@ export async function menusIn(
342
364
  out.set(
343
365
  alias,
344
366
  buildMenu(element, {
345
- content: (key) => view.byKey.get(key.toLowerCase()),
367
+ content: (key) => menuPage(view, key),
346
368
  media: (key) => items.get(key.toLowerCase()),
347
369
  }),
348
370
  )
@@ -698,6 +720,52 @@ export class PublishedCache {
698
720
  return urlsIn(await this.snapshot(), key).map(({ culture, url }) => ({ culture, url }))
699
721
  }
700
722
 
723
+ /**
724
+ * A site's settings page (story 058): the first child of a settings type under
725
+ * the root with `rootKey`, else under the first root.
726
+ */
727
+ async settings(
728
+ rootKey: string | null,
729
+ culture?: string | null,
730
+ ): Promise<PublishedContent | undefined> {
731
+ const view = this.#view(await this.snapshot(), culture)
732
+ if (!view) return undefined
733
+ const root = rootKey ? view.byKey.get(rootKey.toLowerCase()) : view.roots[0]
734
+ return root ? view.settings.get(root.id) : undefined
735
+ }
736
+
737
+ /** The key of the root a hostname serves, when one does. */
738
+ async rootForHost(host: string): Promise<string | undefined> {
739
+ const snapshot = await this.snapshot()
740
+ const best = this.#domainFor(snapshot, host, '/')
741
+ if (!best) return undefined
742
+ const view = this.#view(snapshot, best.domain.isoCode)
743
+ let id: number | undefined = best.domain.nodeId
744
+ let top: PublishedContent | undefined
745
+ while (id !== undefined && view?.byId.has(id)) {
746
+ top = view.byId.get(id)
747
+ id = view.parentIdOf.get(id)
748
+ }
749
+ return top?.key
750
+ }
751
+
752
+ /** Pages of a settings type that are not, or not alone, their site's settings. */
753
+ async settingsFindings(): Promise<SiteSettingsFinding[]> {
754
+ return (await this.snapshot()).settingsFindings
755
+ }
756
+
757
+ /** Every dictionary item in `culture`, each falling back as `dictionary` does. */
758
+ async dictionaryEntries(
759
+ culture: string | null,
760
+ keys?: readonly string[],
761
+ ): Promise<Record<string, string>> {
762
+ const snapshot = await this.snapshot()
763
+ const out: Record<string, string> = {}
764
+ const wanted = keys ?? snapshot.dictionaryOutline.map((item) => item.name)
765
+ for (const key of wanted) out[key] = translate(snapshot, key, culture)
766
+ return out
767
+ }
768
+
701
769
  /** A dictionary item's translation in `culture`, then its fallback languages; '' when none. */
702
770
  async dictionary(key: string, culture: string | null): Promise<string> {
703
771
  const snapshot = await this.snapshot()
@@ -711,6 +779,7 @@ export class PublishedCache {
711
779
  const byKey = view?.byKey ?? new Map<string, PublishedContent>()
712
780
  const parentIdOf = view?.parentIdOf ?? new Map<number, number>()
713
781
  return {
782
+ isSettings: (content) => view?.settingsKeys.has(content.key.toLowerCase()) ?? false,
714
783
  parent: (content) => {
715
784
  const parentId = parentIdOf.get(content.id)
716
785
  return parentId === undefined ? undefined : byId.get(parentId)
@@ -791,12 +860,37 @@ export class PublishedCache {
791
860
  alias,
792
861
  ]),
793
862
  )
863
+ // Story 058: a settings type's pages have no address; a root's first child of
864
+ // one is that site's settings.
865
+ const settingsTypes = new Set(
866
+ ((await source.loadSiteSettingsTypes?.()) ?? []).map((alias) => alias.toLowerCase()),
867
+ )
868
+ const isSettings = (node: PublishedNode) =>
869
+ settingsTypes.has(node.contentTypeAlias.toLowerCase())
794
870
  const defaultCulture =
795
871
  languages.find((l) => l.isDefault)?.isoCode ?? languages[0]?.isoCode ?? null
796
872
  const cultures: Array<string | null> =
797
873
  languages.length > 0 ? languages.map((l) => l.isoCode) : [null]
798
874
 
799
875
  const nodeById = new Map(nodes.map((node) => [node.id, node]))
876
+ const settingsFindings: SiteSettingsFinding[] = []
877
+ const countedFor = new Map<number, PublishedNode>()
878
+ for (const node of [...nodes].filter(isSettings).sort((a, b) => a.sortOrder - b.sortOrder)) {
879
+ const parent = nodeById.get(node.parentId)
880
+ if (!parent || parent.parentId > 0) {
881
+ settingsFindings.push({ kind: 'deep', key: node.key, name: node.name })
882
+ continue
883
+ }
884
+ const counted = countedFor.get(parent.id)
885
+ if (counted)
886
+ settingsFindings.push({
887
+ kind: 'second',
888
+ key: node.key,
889
+ name: node.name,
890
+ counted: counted.name,
891
+ })
892
+ else countedFor.set(parent.id, node)
893
+ }
800
894
  const domainsOf = new Map<number, PublishedDomain[]>()
801
895
  for (const domain of domains)
802
896
  if (!domain.isWildcard)
@@ -845,7 +939,7 @@ export class PublishedCache {
845
939
  const segmentOf = new Map<number, string>()
846
940
  for (const node of nodes) {
847
941
  await pace()
848
- if (!inCulture(node)) continue
942
+ if (!inCulture(node) || isSettings(node)) continue
849
943
  const override =
850
944
  node.properties.find(
851
945
  (p) =>
@@ -914,29 +1008,21 @@ export class PublishedCache {
914
1008
  childrenOf: new Map(),
915
1009
  roots: [],
916
1010
  parentIdOf: new Map(),
1011
+ settings: new Map(),
1012
+ settingsKeys: new Set(),
917
1013
  }
918
1014
  const isDefault = viewKey(culture) === viewKey(defaultCulture)
919
1015
  // Shallow and first-sorted nodes claim a route before any that collide with it.
920
1016
  const ordered = [...nodes]
921
1017
  .filter(inCulture)
922
1018
  .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({
1019
+ const contentOf = (node: PublishedNode, url: string, urlSegment: string) =>
1020
+ new PublishedContent({
935
1021
  key: node.key,
936
1022
  id: node.id,
937
1023
  name: nameIn(node),
938
1024
  contentTypeAlias: node.contentTypeAlias,
939
- urlSegment: segmentOf.get(node.id) as string,
1025
+ urlSegment,
940
1026
  url,
941
1027
  level: node.level,
942
1028
  path: node.path,
@@ -946,9 +1032,32 @@ export class PublishedCache {
946
1032
  componentAlias: node.componentAlias,
947
1033
  cultures: node.cultures,
948
1034
  properties: node.properties,
949
- variationCulture: variant ? culture : null,
1035
+ variationCulture: node.cultures.length > 0 ? culture : null,
950
1036
  languageFallback: fallbackChain(languages, culture),
951
1037
  })
1038
+ for (const node of ordered) {
1039
+ await pace()
1040
+ if (isSettings(node)) {
1041
+ // Found by key and as its root's settings, and nowhere a visitor goes.
1042
+ const content = contentOf(node, '#', urlSegmentFor(nameIn(node), null))
1043
+ view.byId.set(node.id, content)
1044
+ view.byKey.set(node.key.toLowerCase(), content)
1045
+ view.settingsKeys.add(node.key.toLowerCase())
1046
+ if (nodeById.has(node.parentId)) view.parentIdOf.set(node.id, node.parentId)
1047
+ if (countedFor.get(node.parentId)?.id === node.id)
1048
+ view.settings.set(node.parentId, content)
1049
+ continue
1050
+ }
1051
+ const route = routeOf(node)
1052
+ if (route === undefined) continue
1053
+ const domainRoute = domainRouteOf(node)
1054
+ const variant = node.cultures.length > 0
1055
+ const url = domainRoute
1056
+ ? `//${domainRoute.domain.domainName}${domainRoute.route === '/' ? '/' : domainRoute.route}`
1057
+ : isDefault || !variant
1058
+ ? route
1059
+ : '#'
1060
+ const content = contentOf(node, url, segmentOf.get(node.id) as string)
952
1061
  view.byId.set(node.id, content)
953
1062
  view.byKey.set(node.key.toLowerCase(), content)
954
1063
  for (const alias of urlAliasesOf(node, culture)) {
@@ -1071,6 +1180,7 @@ export class PublishedCache {
1071
1180
  dictionary,
1072
1181
  dictionaryOutline,
1073
1182
  contentTypeAliases,
1183
+ settingsFindings,
1074
1184
  ...(checkpoint === undefined ? {} : { checkpoint }),
1075
1185
  builtAt,
1076
1186
  }
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