@aglyn/tenant-runtime 1.0.0-beta.143

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 (120) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +26 -0
  3. package/package.json +39 -0
  4. package/src/index.d.ts +21 -0
  5. package/src/index.js +22 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/apply-publish-schedule.d.ts +34 -0
  8. package/src/lib/apply-publish-schedule.js +285 -0
  9. package/src/lib/apply-publish-schedule.js.map +1 -0
  10. package/src/lib/assign-contact-owner.d.ts +162 -0
  11. package/src/lib/assign-contact-owner.js +322 -0
  12. package/src/lib/assign-contact-owner.js.map +1 -0
  13. package/src/lib/associate-company-by-domain.d.ts +70 -0
  14. package/src/lib/associate-company-by-domain.js +150 -0
  15. package/src/lib/associate-company-by-domain.js.map +1 -0
  16. package/src/lib/author-page-nodes.d.ts +36 -0
  17. package/src/lib/author-page-nodes.js +296 -0
  18. package/src/lib/author-page-nodes.js.map +1 -0
  19. package/src/lib/built-in-page-layout.d.ts +48 -0
  20. package/src/lib/built-in-page-layout.js +107 -0
  21. package/src/lib/built-in-page-layout.js.map +1 -0
  22. package/src/lib/capture-host-contact.d.ts +95 -0
  23. package/src/lib/capture-host-contact.js +137 -0
  24. package/src/lib/capture-host-contact.js.map +1 -0
  25. package/src/lib/collection-fallback-nodes.d.ts +90 -0
  26. package/src/lib/collection-fallback-nodes.js +602 -0
  27. package/src/lib/collection-fallback-nodes.js.map +1 -0
  28. package/src/lib/compose-author-page.d.ts +109 -0
  29. package/src/lib/compose-author-page.js +225 -0
  30. package/src/lib/compose-author-page.js.map +1 -0
  31. package/src/lib/compose-collection-page.d.ts +94 -0
  32. package/src/lib/compose-collection-page.js +256 -0
  33. package/src/lib/compose-collection-page.js.map +1 -0
  34. package/src/lib/compose-screen-nodes.d.ts +156 -0
  35. package/src/lib/compose-screen-nodes.js +547 -0
  36. package/src/lib/compose-screen-nodes.js.map +1 -0
  37. package/src/lib/compose-search-page.d.ts +39 -0
  38. package/src/lib/compose-search-page.js +57 -0
  39. package/src/lib/compose-search-page.js.map +1 -0
  40. package/src/lib/convert-host-lead.d.ts +189 -0
  41. package/src/lib/convert-host-lead.js +443 -0
  42. package/src/lib/convert-host-lead.js.map +1 -0
  43. package/src/lib/defer-lazy-panels.d.ts +58 -0
  44. package/src/lib/defer-lazy-panels.js +171 -0
  45. package/src/lib/defer-lazy-panels.js.map +1 -0
  46. package/src/lib/element-animation-assets.d.ts +62 -0
  47. package/src/lib/element-animation-assets.js +290 -0
  48. package/src/lib/element-animation-assets.js.map +1 -0
  49. package/src/lib/emit-host-event.d.ts +29 -0
  50. package/src/lib/emit-host-event.js +30 -0
  51. package/src/lib/emit-host-event.js.map +1 -0
  52. package/src/lib/enrich-gated-page.d.ts +67 -0
  53. package/src/lib/enrich-gated-page.js +134 -0
  54. package/src/lib/enrich-gated-page.js.map +1 -0
  55. package/src/lib/entry-link-routes.d.ts +61 -0
  56. package/src/lib/entry-link-routes.js +169 -0
  57. package/src/lib/entry-link-routes.js.map +1 -0
  58. package/src/lib/get-author-content.d.ts +119 -0
  59. package/src/lib/get-author-content.js +288 -0
  60. package/src/lib/get-author-content.js.map +1 -0
  61. package/src/lib/get-collection-content.d.ts +290 -0
  62. package/src/lib/get-collection-content.js +565 -0
  63. package/src/lib/get-collection-content.js.map +1 -0
  64. package/src/lib/get-components.d.ts +24 -0
  65. package/src/lib/get-components.js +102 -0
  66. package/src/lib/get-components.js.map +1 -0
  67. package/src/lib/get-datasets.d.ts +45 -0
  68. package/src/lib/get-datasets.js +169 -0
  69. package/src/lib/get-datasets.js.map +1 -0
  70. package/src/lib/get-forms.d.ts +24 -0
  71. package/src/lib/get-forms.js +116 -0
  72. package/src/lib/get-forms.js.map +1 -0
  73. package/src/lib/get-layout-version.d.ts +26 -0
  74. package/src/lib/get-layout-version.js +99 -0
  75. package/src/lib/get-layout-version.js.map +1 -0
  76. package/src/lib/get-media-asset-facts.d.ts +74 -0
  77. package/src/lib/get-media-asset-facts.js +116 -0
  78. package/src/lib/get-media-asset-facts.js.map +1 -0
  79. package/src/lib/get-plugin-installs.d.ts +29 -0
  80. package/src/lib/get-plugin-installs.js +94 -0
  81. package/src/lib/get-plugin-installs.js.map +1 -0
  82. package/src/lib/get-screen-version.d.ts +27 -0
  83. package/src/lib/get-screen-version.js +66 -0
  84. package/src/lib/get-screen-version.js.map +1 -0
  85. package/src/lib/get-screen.d.ts +39 -0
  86. package/src/lib/get-screen.js +126 -0
  87. package/src/lib/get-screen.js.map +1 -0
  88. package/src/lib/get-variables.d.ts +41 -0
  89. package/src/lib/get-variables.js +128 -0
  90. package/src/lib/get-variables.js.map +1 -0
  91. package/src/lib/get-video-asset-facts.d.ts +22 -0
  92. package/src/lib/get-video-asset-facts.js +22 -0
  93. package/src/lib/get-video-asset-facts.js.map +1 -0
  94. package/src/lib/host-event-listeners.d.ts +83 -0
  95. package/src/lib/host-event-listeners.js +91 -0
  96. package/src/lib/host-event-listeners.js.map +1 -0
  97. package/src/lib/org-permissions.d.ts +63 -0
  98. package/src/lib/org-permissions.js +187 -0
  99. package/src/lib/org-permissions.js.map +1 -0
  100. package/src/lib/repeat-record-pages.d.ts +48 -0
  101. package/src/lib/repeat-record-pages.js +64 -0
  102. package/src/lib/repeat-record-pages.js.map +1 -0
  103. package/src/lib/required-site-plugins.d.ts +114 -0
  104. package/src/lib/required-site-plugins.js +121 -0
  105. package/src/lib/required-site-plugins.js.map +1 -0
  106. package/src/lib/resolve-dataset.d.ts +40 -0
  107. package/src/lib/resolve-dataset.js +64 -0
  108. package/src/lib/resolve-dataset.js.map +1 -0
  109. package/src/lib/search-results-nodes.d.ts +48 -0
  110. package/src/lib/search-results-nodes.js +302 -0
  111. package/src/lib/search-results-nodes.js.map +1 -0
  112. package/src/lib/social-image-facts.d.ts +107 -0
  113. package/src/lib/social-image-facts.js +133 -0
  114. package/src/lib/social-image-facts.js.map +1 -0
  115. package/src/lib/stamp-form-dataset-bindings.d.ts +32 -0
  116. package/src/lib/stamp-form-dataset-bindings.js +59 -0
  117. package/src/lib/stamp-form-dataset-bindings.js.map +1 -0
  118. package/src/lib/template-screens.d.ts +227 -0
  119. package/src/lib/template-screens.js +364 -0
  120. package/src/lib/template-screens.js.map +1 -0
@@ -0,0 +1,602 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { wistiaMediaId } from "@aglyn/aglyn/app-utils/wistia-embed";
18
+ import * as Aglyn from "@aglyn/aglyn/server";
19
+ /** Namespaces the synthetic fallback node ids (never persisted). */ const FALLBACK_ID_PREFIX = 'cfb__';
20
+ const id = (suffix)=>`${FALLBACK_ID_PREFIX}${suffix}`;
21
+ // The one shared formatter (AGL-1926). This composes server-side, so the
22
+ // inline `toLocaleDateString()` it replaces was not itself a hydration
23
+ // mismatch — but it was a THIRD spelling of "the entry's published date",
24
+ // free to drift from the byline and the related-post card that quote the
25
+ // same instant. Pinned locale and zone, so all three agree by construction.
26
+ const formatDate = (value)=>Aglyn.formatCollectionEntryDate(value);
27
+ /**
28
+ * What may be interpolated into the cover block's CSS `url("…")` (AGL-1407).
29
+ *
30
+ * The gate this replaces was `/^https?:\/\//i`, which answered the safety
31
+ * question correctly and the coverage question wrongly: it admitted only the
32
+ * OLDEST of the stored generations. A `media:` reference failed it and the
33
+ * cover block was never emitted — a SILENT drop, no error, no placeholder,
34
+ * just a page missing its picture — and so did the AGL-175 relative CDN path
35
+ * that the first pass at media references wrote. Resolving before testing is
36
+ * what closes that, and the test then has to accept a site-relative path,
37
+ * which is what {@link Aglyn.resolveMediaSrc} returns for a reference.
38
+ *
39
+ * Still a scheme allowlist rather than "anything non-empty": this value lands
40
+ * inside a stylesheet rather than in an `<img src>`, so `data:` and friends
41
+ * have no business here even though {@link cssUrlValue} already makes
42
+ * quote-breaking impossible. A bare relative `cover.png` stays rejected
43
+ * exactly as before — there is no page for it to resolve against at compose
44
+ * time.
45
+ *
46
+ * `http:` was dropped for AGL-1725. AGL-1701 found two paths accepting it;
47
+ * markdown-lite is AGL-1713 and this was the second, separate one. It is the
48
+ * only scheme change here, and it is not a host restriction: an author
49
+ * hotlinking their own https cover keeps working, because on a published
50
+ * site the author IS the site owner and the audience is their own visitors.
51
+ * `http:` alone has no defensible use — the request is mixed passive content
52
+ * that current browsers already block or auto-upgrade, so the author gains
53
+ * nothing from it, while the plaintext fetch discloses which article a
54
+ * visitor is reading to every observer on the network path.
55
+ *
56
+ * The consequence of the drop is the SILENT DROP this whole comment is about,
57
+ * for `http:` covers only: no cover node is emitted. That is the correct
58
+ * trade here and the browser was very likely refusing the image anyway, but
59
+ * it is the reason the change is one scheme and not a host list.
60
+ */ const RENDERABLE_COVER_URL = /^(?:https:\/\/|\/)/i;
61
+ /**
62
+ * A URL made safe to sit inside `url("…")`, WITHOUT re-encoding it.
63
+ *
64
+ * This replaces `encodeURI`, which was the wrong tool and quietly broke the
65
+ * commonest stored form: `encodeURI` escapes `%`, so every raw firebasestorage
66
+ * download URL — whose object path is `orgs%2F…%2Fmedia%2F…` — came out
67
+ * double-encoded as `%252F` and 404'd. The block rendered, the image did not,
68
+ * which is why it survived: the page looks composed and the picture is just
69
+ * missing.
70
+ *
71
+ * Only the characters that could END the CSS string are escaped, and they are
72
+ * escaped percent-wise rather than with a backslash so the result is still a
73
+ * valid URL if anything downstream reads it as one. `encodeURI` was never
74
+ * needed for anything else here — a stored URL is already URL-encoded.
75
+ */ const cssUrlValue = (url)=>url.replace(/["\\\n\r]/g, (char)=>encodeURIComponent(char));
76
+ /**
77
+ * Container width for the built-in entry article: the PROSE case of the
78
+ * Container standard (AGL-1298), not an arbitrary narrow default. A
79
+ * collection entry is an article body, and `xl` — the section default — runs
80
+ * a paragraph past 180 characters a line. Stock breakpoint, no bespoke
81
+ * number.
82
+ */ const ENTRY_MAX_WIDTH = 'md';
83
+ /**
84
+ * Container width for the built-in listing: the section default. A listing is
85
+ * a card grid rather than a reading column, so the entry's prose width is the
86
+ * wrong measure for it, and the authored list screens render at this same
87
+ * `xl` (AGL-2567). Still a stock breakpoint, so the AGL-1298 rule holds.
88
+ */ const LIST_MAX_WIDTH = 'xl';
89
+ /**
90
+ * Vertical rhythm between the built-in listing's sections, in MUI theme
91
+ * spacing units: `theme.spacing(6)` resolves to 48px, the same rhythm the
92
+ * authored list screens carry, so a generated listing and an authored one
93
+ * read as one product (AGL-2567).
94
+ *
95
+ * A theme token rather than a pixel string: a hand-written length here
96
+ * answers to no theme, and a length missing its unit is a valid-looking
97
+ * value the browser drops.
98
+ *
99
+ * @see https://mui.com/material-ui/customization/spacing/
100
+ */ const LIST_SECTION_GAP = 6;
101
+ /** The entry article's shell: reading column, sections close together. */ const entryShell = ()=>({
102
+ maxWidth: ENTRY_MAX_WIDTH,
103
+ stackProps: {
104
+ spacing: 2
105
+ }
106
+ });
107
+ /**
108
+ * The listing's shell: full section width, sections on the 48px rhythm.
109
+ *
110
+ * The gap is declared on the stack's `sx` rather than left to the Stack's own
111
+ * `spacing`, which is the shape the authored list screens carry: one
112
+ * `row-gap` on the flex container, so every section is spaced by the same
113
+ * declaration instead of by margins that a section's own styling can collapse
114
+ * or override.
115
+ */ const listShell = ()=>({
116
+ maxWidth: LIST_MAX_WIDTH,
117
+ stackProps: {
118
+ sx: {
119
+ display: 'flex',
120
+ flexDirection: 'column',
121
+ gap: LIST_SECTION_GAP
122
+ }
123
+ }
124
+ });
125
+ /** Root → centered container → content stack; children slot underneath. */ function shell(childIds, layout) {
126
+ return {
127
+ [Aglyn.NODE_ROOT_ID]: {
128
+ $id: Aglyn.NODE_ROOT_ID,
129
+ componentId: 'div',
130
+ nodes: [
131
+ id('container')
132
+ ]
133
+ },
134
+ [id('container')]: {
135
+ $id: id('container'),
136
+ componentId: 'muiContainer',
137
+ pluginId: 'mui',
138
+ parentId: Aglyn.NODE_ROOT_ID,
139
+ props: {
140
+ maxWidth: layout.maxWidth,
141
+ sx: {
142
+ paddingTop: 6,
143
+ paddingBottom: 6
144
+ }
145
+ },
146
+ nodes: [
147
+ id('stack')
148
+ ]
149
+ },
150
+ [id('stack')]: {
151
+ $id: id('stack'),
152
+ componentId: 'muiStack',
153
+ pluginId: 'mui',
154
+ parentId: id('container'),
155
+ props: layout.stackProps,
156
+ nodes: childIds
157
+ }
158
+ };
159
+ }
160
+ const typography = (suffix, props)=>[
161
+ id(suffix),
162
+ {
163
+ $id: id(suffix),
164
+ componentId: 'muiTypography',
165
+ pluginId: 'mui',
166
+ parentId: id('stack'),
167
+ props
168
+ }
169
+ ];
170
+ /**
171
+ * The Video node's props for an entry's featured video, or `undefined` when
172
+ * the entry has none this page can play (AGL-2956).
173
+ *
174
+ * An entry of a video collection is an article whose film sits where a post's
175
+ * cover would, and on the built-in page nobody is there to bind one. So the
176
+ * props carry what a designer would bind by hand: the source, the cover as
177
+ * the poster, and the three facts the page's `VideoObject` is built from —
178
+ * the title, the SEO description falling back to the excerpt as
179
+ * `{{entry.seoDescription}}` does, and the ISO publish instant
180
+ * `{{entry.publishedAt}}` resolves to. An instant rather than a calendar day:
181
+ * the builder publishes `uploadDate` as a date-time with a zone, and it keeps
182
+ * an instant as given where it would publish a bare day at noon UTC.
183
+ *
184
+ * `undefined` rather than a Video node in two cases, because the element's
185
+ * answer to each is a labeled placeholder, which a published article must
186
+ * never show:
187
+ *
188
+ * - a source nothing resolves, such as an empty field or a malformed `media:`
189
+ * reference;
190
+ * - a Wistia link with no poster. Its player loads only when a visitor
191
+ * presses the poster, so without one there is nothing to press.
192
+ *
193
+ * The page then renders as a cover article, exactly as it does for an entry
194
+ * with no video.
195
+ *
196
+ * The poster is the stored reference, not a resolved URL, so the element and
197
+ * the structured data each resolve it against the site rendering the page. It
198
+ * is passed only when the cover's own scheme rule would render it, so this
199
+ * page never shows a still as a poster that it refuses as a cover.
200
+ *
201
+ * The film takes the cover's whole slot in the reading column, whose stock
202
+ * `md` container bounds it; the column is the width limit rather than a pixel
203
+ * cap (AGL-1298).
204
+ */ function featuredVideoProps(entry, options) {
205
+ var _entry_coverVideo, _entry_title;
206
+ const src = ((_entry_coverVideo = entry.coverVideo) != null ? _entry_coverVideo : '').trim();
207
+ if (!src || !Aglyn.resolveMediaSrc(src, {
208
+ hostId: options.hostId
209
+ })) {
210
+ return undefined;
211
+ }
212
+ const poster = options.posterRenders ? entry.coverImage : undefined;
213
+ if (wistiaMediaId(src) && !poster) return undefined;
214
+ const description = entry.seoDescription || entry.excerpt || '';
215
+ const uploadDate = Aglyn.collectionEntryPublishedAtIso(entry.publishedAt);
216
+ return _extends({
217
+ src
218
+ }, poster ? {
219
+ poster
220
+ } : {}, {
221
+ title: (_entry_title = entry.title) != null ? _entry_title : ''
222
+ }, description ? {
223
+ description
224
+ } : {}, uploadDate ? {
225
+ uploadDate
226
+ } : {}, {
227
+ width: '100%'
228
+ });
229
+ }
230
+ /**
231
+ * Built-in entry article as canvas nodes (AGL-551): when a collection has
232
+ * no entry-template screen, `/{collection}/{entry}` renders these through
233
+ * the normal compose pipeline — site theme, shared layout chrome, and the
234
+ * markdown-rendering Entry body block — instead of the old unthemed HTML.
235
+ */ export function buildCollectionEntryFallbackNodes(collection, entry, /**
236
+ * The site being composed, so an org-scoped reference is host-qualified the
237
+ * way every other render surface qualifies one (AGL-1043/AGL-1407). Optional
238
+ * because a bare org reference still resolves without it; passing it is what
239
+ * lets an asset restricted to this site resolve at all.
240
+ */ hostId) {
241
+ var _entry_title, _entry_tags, _Aglyn_resolveEntryCategoryName, _entry_body;
242
+ const entries = [
243
+ typography('title', {
244
+ variant: 'h3',
245
+ component: 'h1',
246
+ children: (_entry_title = entry.title) != null ? _entry_title : ''
247
+ })
248
+ ];
249
+ const date = formatDate(entry.publishedAt);
250
+ const tags = ((_entry_tags = entry.tags) != null ? _entry_tags : []).filter(Boolean);
251
+ // Category name resolves against the collection's taxonomy (AGL-582):
252
+ // `categoryId` lookup first, legacy free-typed string fallback.
253
+ const categoryName = (_Aglyn_resolveEntryCategoryName = Aglyn.resolveEntryCategoryName(entry, collection.categories)) != null ? _Aglyn_resolveEntryCategoryName : '';
254
+ if (date || categoryName || tags.length) {
255
+ // Entry meta block (AGL-582): "date · category" line + tag chips.
256
+ entries.push([
257
+ id('meta'),
258
+ {
259
+ $id: id('meta'),
260
+ componentId: Aglyn.COLLECTION_ENTRY_META_COMPONENT_ID,
261
+ pluginId: 'mui',
262
+ parentId: id('stack'),
263
+ props: {
264
+ date,
265
+ category: categoryName,
266
+ tags: tags.join(', ')
267
+ }
268
+ }
269
+ ]);
270
+ }
271
+ // The cover, through the ONE shared resolver (AGL-1407). A `media:`
272
+ // reference becomes the site-relative CDN path; a raw storage URL, an
273
+ // AGL-175 CDN path and an author's own hotlinked URL all pass through
274
+ // untouched, which is the documented precedence in `media-ref.ts`.
275
+ const coverImage = Aglyn.resolveMediaSrc(entry.coverImage, {
276
+ hostId
277
+ });
278
+ const coverRenders = Boolean(coverImage && RENDERABLE_COVER_URL.test(coverImage));
279
+ // A featured video takes the cover's slot, with the cover as its poster
280
+ // (AGL-2956); see `featuredVideoProps` for when an entry has one to play.
281
+ const video = featuredVideoProps(entry, {
282
+ hostId,
283
+ posterRenders: coverRenders
284
+ });
285
+ if (video) {
286
+ entries.push([
287
+ id('video'),
288
+ {
289
+ $id: id('video'),
290
+ componentId: Aglyn.VIDEO_COMPONENT_ID,
291
+ pluginId: 'mui',
292
+ parentId: id('stack'),
293
+ props: video
294
+ }
295
+ ]);
296
+ } else if (coverRenders) {
297
+ var _entry_title1;
298
+ // Rendered as a background image on a plain stack, NOT through the
299
+ // first-party `image` component — that component crashes tenant SSR
300
+ // (AGL-579); the background-image approach is proven safe.
301
+ entries.push([
302
+ id('cover'),
303
+ {
304
+ $id: id('cover'),
305
+ componentId: 'muiStack',
306
+ pluginId: 'mui',
307
+ parentId: id('stack'),
308
+ props: {
309
+ role: 'img',
310
+ 'aria-label': (_entry_title1 = entry.title) != null ? _entry_title1 : '',
311
+ sx: {
312
+ backgroundImage: `url("${cssUrlValue(coverImage)}")`,
313
+ backgroundSize: 'cover',
314
+ backgroundPosition: 'center',
315
+ borderRadius: 1,
316
+ minHeight: 320
317
+ }
318
+ }
319
+ }
320
+ ]);
321
+ }
322
+ entries.push([
323
+ id('body'),
324
+ {
325
+ $id: id('body'),
326
+ componentId: Aglyn.COLLECTION_ENTRY_BODY_COMPONENT_ID,
327
+ pluginId: 'mui',
328
+ parentId: id('stack'),
329
+ props: {
330
+ markdown: (_entry_body = entry.body) != null ? _entry_body : ''
331
+ }
332
+ }
333
+ ]);
334
+ // Related posts after the body, share bar at the end (AGL-582); the
335
+ // compose pipeline stamps the related entries server-side.
336
+ entries.push([
337
+ id('related'),
338
+ {
339
+ $id: id('related'),
340
+ componentId: Aglyn.COLLECTION_RELATED_COMPONENT_ID,
341
+ pluginId: 'mui',
342
+ parentId: id('stack'),
343
+ props: {
344
+ heading: 'Related articles',
345
+ limit: 3,
346
+ sx: {
347
+ paddingTop: 2
348
+ }
349
+ }
350
+ }
351
+ ]);
352
+ entries.push([
353
+ id('share'),
354
+ {
355
+ $id: id('share'),
356
+ componentId: Aglyn.COLLECTION_SHARE_COMPONENT_ID,
357
+ pluginId: 'mui',
358
+ parentId: id('stack'),
359
+ props: {}
360
+ }
361
+ ]);
362
+ entries.push([
363
+ id('back'),
364
+ {
365
+ $id: id('back'),
366
+ componentId: 'muiScreenLink',
367
+ pluginId: 'mui',
368
+ parentId: id('stack'),
369
+ props: {
370
+ href: `/${collection.slug}`,
371
+ children: `← ${collection.displayName}`,
372
+ sx: {
373
+ alignSelf: 'flex-start'
374
+ }
375
+ }
376
+ }
377
+ ]);
378
+ return _extends({}, shell(entries.map(([entryId])=>entryId), entryShell()), Object.fromEntries(entries));
379
+ }
380
+ /** Prev/next + "Page X of Y" nav linking to /{slug}/page/{n} (AGL-620). */ function paginationNodes(collection, pagination, category) {
381
+ // Page 1 lives at the bare listing; deeper pages at .../page/{n}. Built
382
+ // through the shared pager computation so this fallback and the
383
+ // `{{pagination.*}}` tokens an authored template binds (AGL-1386) can never
384
+ // disagree — and so the pager stays inside the category it is paging
385
+ // (AGL-1321): a "next" that dropped the filter would silently return the
386
+ // reader to the unfiltered list. An edge is the empty string, which is
387
+ // exactly the "no link here" this fallback already meant.
388
+ const { page, totalPages, prevUrl, nextUrl } = Aglyn.collectionPaginationLinks(_extends({
389
+ collectionSlug: collection.slug
390
+ }, category ? {
391
+ categorySlug: category.slug
392
+ } : {}, {
393
+ page: pagination.page,
394
+ totalPages: pagination.totalPages
395
+ }));
396
+ const children = [];
397
+ const nodes = {};
398
+ if (prevUrl) {
399
+ nodes[id('prev')] = {
400
+ $id: id('prev'),
401
+ componentId: 'muiScreenLink',
402
+ pluginId: 'mui',
403
+ parentId: id('pager'),
404
+ props: {
405
+ href: prevUrl,
406
+ children: '← Newer'
407
+ }
408
+ };
409
+ children.push(id('prev'));
410
+ }
411
+ nodes[id('pageinfo')] = {
412
+ $id: id('pageinfo'),
413
+ componentId: 'muiTypography',
414
+ pluginId: 'mui',
415
+ parentId: id('pager'),
416
+ props: {
417
+ variant: 'body2',
418
+ children: `Page ${page} of ${totalPages}`,
419
+ sx: {
420
+ color: 'text.secondary'
421
+ }
422
+ }
423
+ };
424
+ children.push(id('pageinfo'));
425
+ if (nextUrl) {
426
+ nodes[id('next')] = {
427
+ $id: id('next'),
428
+ componentId: 'muiScreenLink',
429
+ pluginId: 'mui',
430
+ parentId: id('pager'),
431
+ props: {
432
+ href: nextUrl,
433
+ children: 'Older →'
434
+ }
435
+ };
436
+ children.push(id('next'));
437
+ }
438
+ nodes[id('pager')] = {
439
+ $id: id('pager'),
440
+ componentId: 'muiStack',
441
+ pluginId: 'mui',
442
+ parentId: id('stack'),
443
+ props: {
444
+ direction: 'row',
445
+ spacing: 3,
446
+ sx: {
447
+ alignItems: 'center',
448
+ justifyContent: 'center'
449
+ }
450
+ },
451
+ nodes: children
452
+ };
453
+ return {
454
+ childId: id('pager'),
455
+ nodes
456
+ };
457
+ }
458
+ /**
459
+ * Built-in entry list as canvas nodes (AGL-551): a heading plus a
460
+ * Collection entries block whose template (title, date, excerpt, Read
461
+ * more) the compose pipeline expands over the published entries — the same
462
+ * block designers drop onto their own list-template screens. With
463
+ * `pagination` (AGL-620) the block renders one page and prev/next nav links
464
+ * to `/{slug}/page/{n}`.
465
+ */ export function buildCollectionListFallbackNodes(collection, hasEntries, pagination, category) {
466
+ var _collection_categories;
467
+ const [titleId, title] = typography('title', {
468
+ variant: 'h3',
469
+ component: 'h1',
470
+ // A filtered listing says which slice it is (AGL-1321) — a page of
471
+ // Guides whose only heading reads "Blog" tells the reader nothing about
472
+ // why the other posts vanished.
473
+ children: category ? `${collection.displayName} · ${category.name}` : collection.displayName
474
+ });
475
+ // Category pills (AGL-1321): stamped by `expandCollectionCategories` during
476
+ // compose, from the same taxonomy this node's collection carries. Present
477
+ // in the EMPTY case too — a filtered listing with no entries whose pills
478
+ // vanished would be a dead end with no way back to "All".
479
+ const pills = ((_collection_categories = collection.categories) == null ? void 0 : _collection_categories.length) ? {
480
+ $id: id('pills'),
481
+ componentId: Aglyn.COLLECTION_CATEGORIES_COMPONENT_ID,
482
+ pluginId: 'mui',
483
+ parentId: id('stack'),
484
+ props: {
485
+ allLabel: 'All'
486
+ }
487
+ } : null;
488
+ const lead = pills ? [
489
+ titleId,
490
+ id('pills')
491
+ ] : [
492
+ titleId
493
+ ];
494
+ if (!hasEntries) {
495
+ const [emptyId, empty] = typography('empty', {
496
+ variant: 'body1',
497
+ children: category ? `Nothing published in ${category.name} yet.` : 'Nothing published yet.',
498
+ sx: {
499
+ color: 'text.secondary'
500
+ }
501
+ });
502
+ return _extends({}, shell([
503
+ ...lead,
504
+ emptyId
505
+ ], listShell()), {
506
+ [titleId]: title
507
+ }, pills ? {
508
+ [id('pills')]: pills
509
+ } : {}, {
510
+ [emptyId]: empty
511
+ });
512
+ }
513
+ const item = (suffix, props)=>({
514
+ $id: id(suffix),
515
+ componentId: 'muiTypography',
516
+ pluginId: 'mui',
517
+ parentId: id('item'),
518
+ props
519
+ });
520
+ const pager = pagination && pagination.totalPages > 1 ? paginationNodes(collection, pagination, category) : null;
521
+ return _extends({}, shell(pager ? [
522
+ ...lead,
523
+ id('entries'),
524
+ pager.childId
525
+ ] : [
526
+ ...lead,
527
+ id('entries')
528
+ ], listShell()), {
529
+ [titleId]: title
530
+ }, pills ? {
531
+ [id('pills')]: pills
532
+ } : {}, {
533
+ [id('entries')]: {
534
+ $id: id('entries'),
535
+ componentId: Aglyn.COLLECTION_ENTRIES_COMPONENT_ID,
536
+ pluginId: 'mui',
537
+ parentId: id('stack'),
538
+ props: _extends({
539
+ spacing: 4
540
+ }, pagination ? {
541
+ perPage: pagination.perPage,
542
+ page: pagination.page
543
+ } : {}),
544
+ nodes: [
545
+ id('item')
546
+ ]
547
+ }
548
+ }, pager ? pager.nodes : {}, {
549
+ [id('item')]: {
550
+ $id: id('item'),
551
+ componentId: 'muiStack',
552
+ pluginId: 'mui',
553
+ parentId: id('entries'),
554
+ props: {
555
+ spacing: 0.5
556
+ },
557
+ nodes: [
558
+ id('item-title'),
559
+ id('item-date'),
560
+ id('item-excerpt'),
561
+ id('item-link')
562
+ ]
563
+ },
564
+ [id('item-title')]: item('item-title', {
565
+ variant: 'h5',
566
+ component: 'h2',
567
+ children: '{{entry.title}}'
568
+ }),
569
+ [id('item-date')]: item('item-date', {
570
+ variant: 'caption',
571
+ children: '{{entry.date}}',
572
+ sx: {
573
+ color: 'text.secondary'
574
+ }
575
+ }),
576
+ [id('item-excerpt')]: item('item-excerpt', {
577
+ variant: 'body1',
578
+ children: '{{entry.excerpt}}'
579
+ }),
580
+ [id('item-link')]: {
581
+ $id: id('item-link'),
582
+ componentId: 'muiScreenLink',
583
+ pluginId: 'mui',
584
+ parentId: id('item'),
585
+ props: {
586
+ href: '{{entry.url}}',
587
+ children: 'Read more',
588
+ size: 'small',
589
+ sx: {
590
+ alignSelf: 'flex-start'
591
+ }
592
+ }
593
+ }
594
+ });
595
+ }
596
+ /** Entry vs list fallback selection for the routed content (AGL-551). */ export function buildCollectionFallbackNodes(content) {
597
+ var _content_pagination, _content_category;
598
+ return content.entry ? buildCollectionEntryFallbackNodes(content.collection, content.entry, content.hostId) : buildCollectionListFallbackNodes(content.collection, content.entries.length > 0, (_content_pagination = content.pagination) != null ? _content_pagination : undefined, (_content_category = content.category) != null ? _content_category : undefined);
599
+ }
600
+ export default buildCollectionFallbackNodes;
601
+
602
+ //# sourceMappingURL=collection-fallback-nodes.js.map