foldkit-cms 0.11.0 → 0.12.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/README.md CHANGED
@@ -64,6 +64,33 @@ your domain module; [the example domain](../../examples/cms/src/content/domain.t
64
64
  those definitions together. Start with [Form](../form/README.md) if you have not
65
65
  yet defined the operation's input.
66
66
 
67
+ <!-- docs-check standalone
68
+ import { Schema } from 'effect'
69
+ import { Entity } from 'foldkit-entity'
70
+ import { Form } from 'foldkit-form'
71
+ import { Mutation } from 'foldkit-remote'
72
+
73
+ const PostId = Schema.String.pipe(Schema.brand('PostId'))
74
+ const Blog = {
75
+ Post: Entity.define(
76
+ 'Post',
77
+ Schema.Struct({
78
+ id: PostId,
79
+ title: Schema.String,
80
+ slug: Schema.String,
81
+ publishedAt: Schema.NullOr(Schema.String),
82
+ }),
83
+ ),
84
+ }
85
+ const PostInput = Schema.Struct({ title: Schema.String, slug: Schema.String })
86
+ const PostForm = Form.make('PostForm', Entity.input(Blog.Post, PostInput))
87
+ const CreatePostMutation = Mutation.make('CreatePost', { Input: PostInput, Output: { id: PostId } })
88
+ const UpdatePostMutation = Mutation.make('UpdatePost', {
89
+ Input: { ...PostInput.fields, id: PostId },
90
+ Output: {},
91
+ })
92
+ -->
93
+
67
94
  ```ts
68
95
  import { Cms } from 'foldkit-cms'
69
96
 
@@ -102,6 +129,11 @@ audience policy, a `bySlug` query, a sitemap this package knows nothing of.
102
129
  State is derived from facts and a clock. Nothing stores a status, so it cannot
103
130
  disagree with what is true.
104
131
 
132
+ <!-- docs-check
133
+ declare const scheduledFor: string
134
+ declare const now: Date
135
+ -->
136
+
105
137
  ```ts
106
138
  Cms.state({ archivedAt: null, row: 'visible', draft: { scheduledFor, scheduleError: null } }, now)
107
139
  // { _tag: 'Changed', schedule: { at, overdue: false, error: null } }
@@ -132,12 +164,21 @@ and the draft that keeps what the author has entered. It is a Bundle, placed
132
164
  like any other; the view is the form's own.
133
165
 
134
166
  ```ts
167
+ import { Bundle } from 'foldkit-bundle'
168
+ import { Remote, type RemoteClient } from 'foldkit-remote'
169
+ import { Surface } from 'foldkit-surface'
170
+
135
171
  const Editor = Cms.editor('PostEditor', { content: Posts })
136
172
  const Base = Bundle.compose({ remote: Remote.Model }).pipe(
137
173
  Bundle.withMessages(Remote.messages),
138
174
  Bundle.withChild('editor', Editor.bundle), // its Model and its Messages, in yours
139
175
  )
140
- // App = Surface.application(Base), and Data = Remote.make({ model: App.model.remote, ... })
176
+ const App = Surface.application(Base)
177
+ const Data = Remote.make({
178
+ model: App.model.remote,
179
+ entities: [Post, ...Object.values(Cms.Entities)],
180
+ mutations: [...Cms.operations],
181
+ })
141
182
 
142
183
  const PostEditor = Editor.at({ data: Data, model: App.model.editor })
143
184
  const Page = Base.pipe(
@@ -145,10 +186,21 @@ const Page = Base.pipe(
145
186
  Bundle.configure('editor', { onOut: PostEditor.onOut }), // made from Data, so given now
146
187
  )
147
188
  const Placed = Page.children.editor
148
- const update = PostEditor.after(Page.placements.update(yourUpdate))
189
+ const update = PostEditor.after(
190
+ Page.placements.update((model, message) =>
191
+ Remote.reduces(message) ? { model: Data.reduce(model, message) } : { model },
192
+ ),
193
+ )
194
+
195
+ Data.subscriptions({ ...PostEditor.actives }) // beside your own Surfaces' actives
196
+ ```
149
197
 
150
- Data.subscriptions({ ...yourSurfaces, ...PostEditor.actives })
198
+ <!-- docs-check
199
+ declare const model: typeof Base.Model.Type
200
+ declare const entryId: string
201
+ -->
151
202
 
203
+ ```ts
152
204
  Placed.helpers.open(entryId) // resume the draft, else show what is published
153
205
  Placed.helpers.create(Cms.newEntryId()) // something new; its first save makes the entry
154
206
  Editor.Message.PublishAsked() // also: ScheduleAsked({ at }), UnscheduleAsked, DiscardAsked,
@@ -230,9 +282,31 @@ An entry's address and its publish time are
230
282
  adds two displays, made with `Display.kind` exactly as you make your own. There is
231
283
  no CMS view package: a kind and its renderer are all a view needs.
232
284
 
285
+ <!-- docs-check standalone
286
+ import { Schema } from 'effect'
287
+ import { Entity } from 'foldkit-entity'
288
+
289
+ const Post = Entity.define(
290
+ 'Post',
291
+ Schema.Struct({
292
+ id: Schema.String,
293
+ title: Schema.String,
294
+ slug: Schema.String,
295
+ goesLiveAt: Schema.String,
296
+ }),
297
+ )
298
+ const PostInput = Schema.Struct({
299
+ title: Schema.String,
300
+ slug: Schema.String,
301
+ goesLiveAt: Schema.String,
302
+ })
303
+ -->
304
+
233
305
  ```ts
306
+ import { Form } from 'foldkit-form'
234
307
  import { FieldRecipes } from 'foldkit-form-recipes'
235
308
  import { renderers } from 'foldkit-form-recipes/html'
309
+ import { FormView } from 'foldkit-mixins-form'
236
310
 
237
311
  const PostForm = Form.make('PostForm', Entity.input(Post, PostInput), {
238
312
  inputs: {
@@ -244,6 +318,11 @@ const PostForm = Form.make('PostForm', Entity.input(Post, PostInput), {
244
318
  })
245
319
 
246
320
  FormView.define(PostForm, { renderers: renderers() })
321
+ ```
322
+
323
+ Beside a list's own renderers (`EntryTable` is a `Crud.list` over `Cms.Entries`):
324
+
325
+ ```ts sketch
247
326
  EntryTable({ page, renderers: Cms.displayRenderers() }, h)
248
327
  ```
249
328
 
@@ -265,13 +344,59 @@ is, so one tone rule styles both),
265
344
  `Cms.revisionsOf` for the open entry's published revisions, `Cms.historyCard`
266
345
  for the timeline, `Cms.moreCard` for the rest of what can happen to it. They
267
346
  draw on your own slot builders, so you keep your slots and styles; who
268
- published and the archive button's icon are yours to name:
347
+ published, the archive button's icon, and the locale and time zone the
348
+ History writes its dates in are yours to name. Both are required: the
349
+ runtime's own differ between a server and a browser, which would then write
350
+ different text for one revision:
351
+
352
+ <!-- docs-check standalone
353
+ import { Option, Schema } from 'effect'
354
+ import { Capability, Slot, Slots, type SlotView } from 'foldkit-mixins'
355
+ import { Cms, type RevisionRow, type State } from 'foldkit-cms'
356
+ import type { HtmlBuilder } from 'foldkit/html'
357
+ import { defineMessageUnion } from 'foldkit/message'
358
+ import type { RemoteData } from 'foldkit-remote'
359
+
360
+ const Message = defineMessageUnion({ RestoreAsked: { revision: Schema.Number } })
361
+ type Message = typeof Message.Type
362
+ type Model = { readonly entryId: string }
363
+
364
+ const EntrySlots = Slots.define({
365
+ card: Slot.make({ capability: Capability.Container }),
366
+ cardTitle: Slot.make({ capability: Capability.Container }),
367
+ badge: Slot.make({ capability: Capability.Container }),
368
+ muted: Slot.make({ capability: Capability.Container }),
369
+ timeline: Slot.make({ capability: Capability.Container }),
370
+ revision: Slot.make({ capability: Capability.Container }),
371
+ revisionMark: Slot.make({ capability: Capability.Container }),
372
+ revisionBody: Slot.make({ capability: Capability.Container }),
373
+ revisionTitle: Slot.make({ capability: Capability.Container }),
374
+ revisionLive: Slot.make({ capability: Capability.Container }),
375
+ revisionMeta: Slot.make({ capability: Capability.Container }),
376
+ revisionRestore: Slot.make({ capability: Capability.Interactive }),
377
+ toolbar: Slot.make({ capability: Capability.Container }),
378
+ button: Slot.make({ capability: Capability.Interactive }),
379
+ danger: Slot.make({ capability: Capability.Interactive }),
380
+ })
381
+ declare const slots: SlotView.SlotBuilders<typeof EntrySlots, Message>
382
+ declare const h: HtmlBuilder<Message>
383
+ declare const model: Model
384
+ declare const state: Option.Option<State>
385
+ declare const history: (model: Model) => Option.Option<{
386
+ readonly read: (
387
+ model: Model,
388
+ ) => RemoteData<{ readonly revisions: ReadonlyArray<RevisionRow> }>
389
+ }>
390
+ declare const directoryName: (name: string) => string
391
+ -->
269
392
 
270
393
  ```ts
271
394
  Cms.historyCard(slots, h, Cms.revisionsOf(model, history), {
272
395
  state,
273
396
  restore: revision => Message.RestoreAsked({ revision }),
274
397
  authorName: name => directoryName(name),
398
+ locale: 'en',
399
+ timeZone: 'UTC',
275
400
  })
276
401
  ```
277
402
 
package/dist/index.d.mts CHANGED
@@ -323,15 +323,24 @@ interface HistoryCardSlots<M> {
323
323
  * the entry is on the site; restoring it is offered only while a draft sits
324
324
  * over it, since otherwise it changes nothing. A history still being read
325
325
  * says so as a busy status, and one that failed as an alert, so neither is
326
- * mistaken for nothing published nor read as plain text. A failed read is not
326
+ * mistaken for nothing published nor read as plain text; give `muted`
327
+ * `Utilities.busyReveal` (`foldkit-mixins/utilities`) and the wait is said
328
+ * only once it is noticeable. A failed read is not
327
329
  * retried on its own: given `onRetry`, a button sends it, drawn on the
328
330
  * restore slot so no new builder is required of every studio. Who published
329
331
  * is the application's to name (`authorName`), as only it knows its chairs.
332
+ * Its dates are written in the `locale` and `timeZone` given: both are
333
+ * required, since the runtime's own would differ between a server and a
334
+ * browser.
330
335
  */
331
336
  declare const historyCard: <M>(slots: HistoryCardSlots<M>, h: HtmlBuilder<M>, history: RevisionHistory, entry: {
332
337
  readonly state: Option.Option<State>;
333
338
  readonly restore: (revision: number) => M;
334
339
  readonly authorName: (name: string) => string;
340
+ /** The BCP 47 locale each revision's date and time are written in, such as `en`. */
341
+ readonly locale: string;
342
+ /** The IANA time zone each revision's date and time are written in, such as `UTC`. */
343
+ readonly timeZone: string;
335
344
  /**
336
345
  * Asks again after a failed read. Given, a failed history shows a button
337
346
  * that sends it; a failed read is not retried on its own.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["_$__kinds_js0.StateWords","_$__kinds_js0.DisplayContext","_$__editor_js0.EditorContent","_$__editor_js0.EditorModel","_$__editor_js0.EditorOut","_$__editor_js0.Resumed","_$__editor_js0.EditorDomain","_$__editor_js0.EditorStatus"],"sources":["../src/kinds.ts","../src/lifecycle.ts","../src/editor.ts","../src/views.ts","../src/slug.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;UAmBiB;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;;UAqFM,eAAe;WACrB;aACE;aACA,OAAO,gBAAgB,OAAO;;WAEhC;WACA,OAAO;WACP,GAAG,YAAY;WACf;aAAkB,QAAQ,OAAO;;;;UC/G3B;;WAEN;;WAEA;;WAEA;aACE;aACA;;;;UAKI;WACN;;WAEA;;WAEA;;KAGC;;;;;;;;;;UAWK;WACN,MAAM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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgE5E,QAAA,OAAA,OAAK,KAAO,SAAO;;;;EAKzB,SAAA,OAAA,OAAK,KACP,MAAI;aACW,OAAO;QAC1B,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":["_$__kinds_js0.StateWords","_$__kinds_js0.DisplayContext","_$__editor_js0.EditorContent","_$__editor_js0.EditorModel","_$__editor_js0.EditorOut","_$__editor_js0.Resumed","_$__editor_js0.EditorDomain","_$__editor_js0.EditorStatus"],"sources":["../src/kinds.ts","../src/lifecycle.ts","../src/editor.ts","../src/views.ts","../src/slug.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;UAmBiB;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;WAEA;;;UAqFM,eAAe;WACrB;aACE;aACA,OAAO,gBAAgB,OAAO;;WAEhC;WACA,OAAO;WACP,GAAG,YAAY;WACf;aAAkB,QAAQ,OAAO;;;;UC/G3B;;WAEN;;WAEA;;WAEA;aACE;aACA;;;;UAKI;WACN;;WAEA;;WAEA;;KAGC;;;;;;;;;;UAWK;WACN,MAAM;WACN,UAAU;;;cAIR,aAAW,OAAA;KAWZ,oBAAoB,YAAY;;KCpBhC;;;;;;;;;;;KAYA;;;;;;;;;;;;;;;;;;;UAgCK,YAAY;WAClB,MAAM;WACN;WACA;WACA;WACA,SAAS;WACT;WACA;WACA;WACA;WACA;WACA;;;;;WAKA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;KAIC;WACG;;WACA;;WACA;;WACA;WAA0B;;WAC1B;;WACA;;WACA;;WACA;;WACA;;WACA;;;;UAIE,WAAW,WAAW,aAAa,OAAO,gBAAgB;WAChE;WACA;aAAkB,QAAQ,OAAO;;WACjC;aACE,OAAO,OAAO,MAAM;aACpB,SAAS,OAAO,MAAM;aACtB,SACP,OAAO,W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AG,QAAQ,QAAQ;QAErD,QAAQ,MAAM,GAAG,OAAO,UAAU;;EASrB,kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAvPZ,gCAAK,aAAA;;;;;;;;;;;;;;;;QACL,oCAAS,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuBA,QAAA,aAAM;;;;;;;;;;;;;;;;;;;;EAkPV,SAAA,qBAAqB,UAAU,WAAS,SAAW,QAAQ,MAAM,+CAAiB,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgE5E,QAAA,OAAA,OAAK,KAAO,SAAO;;;;EAKzB,SAAA,OAAA,OAAK,KACP,MAAI;aACW,OAAO;QAC1B,cAAc"}
package/dist/index.mjs CHANGED
@@ -92,7 +92,6 @@ const offers = (facts, now, capabilities) => {
92
92
  * saves have got. What the server holds is read from Remote, never copied: the
93
93
  * draft's `updatedAt` a save is based on, and the entry's `revision` a publish is.
94
94
  */
95
- const held = (read) => read?._tag === "Ready" || read?._tag === "Refreshing" ? read.value : void 0;
96
95
  /** Read, and not being read again: what the server said last, not what it said before. */
97
96
  const fresh = (read) => read?._tag === "Ready" || read?._tag === "NotFound";
98
97
  const Own = defineMessageUnion({
@@ -355,9 +354,13 @@ const makeEditor = (cms) => (name, config) => {
355
354
  entry: (root) => Option.map(Option.fromUndefinedOr(entryOf(root)), (entry) => data.get(EntryRead, entry)),
356
355
  state: (root) => Option.map(Option.fromUndefinedOr(entryOf(root)), (entry) => data.get(EntryState, entry)),
357
356
  draft: (root) => Option.map(Option.fromUndefinedOr(entryOf(root)), (entry) => data.get(DraftRead, entry)),
358
- row: (root) => Option.map(Option.fromNullishOr(held(read(root, "entry"))?.targetId), (target) => data.get(RowRead, target))
357
+ row: (root) => Option.map(targetOf(root), (target) => data.get(RowRead, target))
359
358
  };
360
359
  const read = (root, part) => Option.getOrUndefined(Option.map(projections[part](root), (projection) => projection.read(root)));
360
+ /** What `part`'s read holds, by `RemoteData.held`; none while there is none to read. */
361
+ const heldIn = (root, part) => Option.flatMap(Option.fromUndefinedOr(read(root, part)), (r) => RemoteData.held(r));
362
+ /** The published row the open entry points at, once the entry is read. */
363
+ const targetOf = (root) => Option.flatMap(heldIn(root, "entry"), (entry) => Option.fromNullOr(entry.targetId));
361
364
  /**
362
365
  * Read and asked for nothing more. A draft known absent still reads
363
366
  * `NotFound` while a refresh asks about it again, so `fresh` alone
@@ -377,10 +380,10 @@ const makeEditor = (cms) => (name, config) => {
377
380
  if (statusOf(root, editor.otherId)._tag === "Pending") return root;
378
381
  const entry = read(root, "entry");
379
382
  const draft = read(root, "draft");
380
- const arrived = editor.settling === "reload" ? fresh : (r) => held(r) !== void 0 || r?._tag === "NotFound";
383
+ const arrived = editor.settling === "reload" ? fresh : (r) => r !== void 0 && (Option.isSome(RemoteData.held(r)) || r._tag === "NotFound");
381
384
  if (!arrived(entry) || !arrived(draft)) return root;
382
- const entryValue = held(entry);
383
- if (entryValue === void 0) return root;
385
+ const entryValue = heldIn(root, "entry");
386
+ if (Option.isNone(entryValue)) return root;
384
387
  const shown = (resumed, next) => slice.set(root, {
385
388
  ...closed,
386
389
  mode: "edit",
@@ -390,19 +393,20 @@ const makeEditor = (cms) => (name, config) => {
390
393
  resumed,
391
394
  otherId: editor.otherId
392
395
  });
393
- const saved = held(draft);
394
- if (saved !== void 0) {
395
- const model = saved.form === formTag ? decodeModel(saved.model) : Option.none();
396
+ const saved = heldIn(root, "draft");
397
+ if (Option.isSome(saved)) {
398
+ const model = saved.value.form === formTag ? decodeModel(saved.value.model) : Option.none();
396
399
  if (Option.isSome(model)) return shown("Model", form.settled(model.value));
397
- const values = fitting(saved.values);
400
+ const values = fitting(saved.value.values);
398
401
  if (Object.keys(values).length > 0) return shown("Values", form.fill(form.initial, values).model);
399
402
  }
400
- const lost = saved === void 0 ? "Published" : "Lost";
401
- if (entryValue.targetId === null) return shown(saved === void 0 ? "Blank" : "Lost", form.initial);
402
- const row = read(root, "row");
403
- if (!arrived(row)) return root;
404
- const rowValue = held(row);
405
- return rowValue === void 0 ? shown(lost, form.initial) : shown(lost, form.fill(form.initial, Entity.valuesFor(form.input, rowValue)).model);
403
+ const lost = Option.isNone(saved) ? "Published" : "Lost";
404
+ if (entryValue.value.targetId === null) return shown(Option.isNone(saved) ? "Blank" : "Lost", form.initial);
405
+ if (!arrived(read(root, "row"))) return root;
406
+ return Option.match(heldIn(root, "row"), {
407
+ onNone: () => shown(lost, form.initial),
408
+ onSome: (rowValue) => shown(lost, form.fill(form.initial, Entity.valuesFor(form.input, rowValue)).model)
409
+ });
406
410
  };
407
411
  const startSave = (root) => {
408
412
  const editor = slice.get(root);
@@ -410,7 +414,10 @@ const makeEditor = (cms) => (name, config) => {
410
414
  const labelKey = content.roles.label?.key;
411
415
  const typed = labelKey === void 0 ? "" : form.field(editor.form, labelKey).value;
412
416
  const label = typeof typed === "string" ? typed.trim() : "";
413
- const basedOn = held(read(root, "draft"))?.updatedAt ?? null;
417
+ const basedOn = Option.match(heldIn(root, "draft"), {
418
+ onNone: () => null,
419
+ onSome: (draft) => draft.updatedAt
420
+ });
414
421
  const started = data.mutate(root, cms.Operations.SaveDraft, {
415
422
  entry: editor.entry,
416
423
  type: content.name,
@@ -455,7 +462,7 @@ const makeEditor = (cms) => (name, config) => {
455
462
  const editor = slice.get(root);
456
463
  if (editor.entry === null) return { model: root };
457
464
  if (editor.mode === "new" && editor.saveId === null) return { model: slice.set(root, closed) };
458
- const unpublished = held(read(root, "entry"))?.targetId == null;
465
+ const unpublished = Option.isNone(targetOf(root));
459
466
  const started = data.mutate(root, cms.Operations.DiscardDraft, { entry: editor.entry });
460
467
  return {
461
468
  model: slice.set(started.model, unpublished ? closed : {
@@ -500,7 +507,8 @@ const makeEditor = (cms) => (name, config) => {
500
507
  const previewed = (root) => {
501
508
  const editor = slice.get(root);
502
509
  if (!editor.previewing || content.preview === void 0 || editor.entry === null) return lift(data, root, overlayId);
503
- const id = held(read(root, "entry"))?.targetId ?? editor.entry;
510
+ const entry = editor.entry;
511
+ const id = Option.getOrElse(targetOf(root), () => entry);
504
512
  const as = `${editor.edits}:${id}`;
505
513
  if (editor.previewedAs === as) return root;
506
514
  const shown = overlay(data, root, overlayId, content.preview(form.partial(editor.form), id));
@@ -540,8 +548,8 @@ const makeEditor = (cms) => (name, config) => {
540
548
  */
541
549
  const about = (root) => {
542
550
  const editor = slice.get(root);
543
- const target = held(read(root, "entry"))?.targetId;
544
- const subject = target === null || target === void 0 ? {} : { id: target };
551
+ const target = Option.getOrUndefined(targetOf(root));
552
+ const subject = target === void 0 ? {} : { id: target };
545
553
  if (form.subject(editor.form).id === subject.id) return root;
546
554
  return slice.set(root, {
547
555
  ...editor,
@@ -568,14 +576,35 @@ const makeEditor = (cms) => (name, config) => {
568
576
  if (editor().publishWanted && !saving() && editor().settling === null) {
569
577
  const save = statusOf(root, editor().saveId);
570
578
  const resumedDraft = editor().resumed === "Model" || editor().resumed === "Values";
571
- const saved = editor().edits === editor().savedEdit && (editor().saveId === null ? resumedDraft : save._tag === "Applied");
572
- if (save._tag === "Failed" && editor().edits === editor().savedEdit) root = slice.set(root, {
579
+ const { applied, failed } = Match.valueTags(save, {
580
+ Applied: () => ({
581
+ applied: true,
582
+ failed: false
583
+ }),
584
+ Failed: () => ({
585
+ applied: false,
586
+ failed: true
587
+ }),
588
+ Pending: () => ({
589
+ applied: false,
590
+ failed: false
591
+ }),
592
+ Unknown: () => ({
593
+ applied: false,
594
+ failed: false
595
+ })
596
+ });
597
+ const saved = editor().edits === editor().savedEdit && (editor().saveId === null ? resumedDraft : applied);
598
+ if (failed && editor().edits === editor().savedEdit) root = slice.set(root, {
573
599
  ...editor(),
574
600
  publishWanted: false
575
601
  });
576
602
  else if (!saved) run(startSave);
577
603
  else {
578
- const basedOn = held(read(root, "entry"))?.revision ?? null;
604
+ const basedOn = Option.match(heldIn(root, "entry"), {
605
+ onNone: () => null,
606
+ onSome: (entry) => entry.revision
607
+ });
579
608
  const at = editor().scheduleAt;
580
609
  const started = at === null ? data.mutate(root, cms.Operations.Publish, {
581
610
  entry: editor().entry,
@@ -701,7 +730,7 @@ const makeEditor = (cms) => (name, config) => {
701
730
  * The id the application's own pages know this content by: the row's, or
702
731
  * the entry's while there is no row. It is what a preview is shown under.
703
732
  */
704
- pageId: (root) => Option.fromNullishOr(held(read(root, "entry"))?.targetId ?? slice.get(root).entry),
733
+ pageId: (root) => Option.orElse(targetOf(root), () => Option.fromNullOr(slice.get(root).entry)),
705
734
  /** The entry being edited; none while closed. */
706
735
  entry: (root) => Option.fromNullOr(slice.get(root).entry),
707
736
  /**
@@ -712,30 +741,29 @@ const makeEditor = (cms) => (name, config) => {
712
741
  /** How the form came to hold what it holds; `Lost` is worth telling the author. */
713
742
  resumed: (root) => Option.fromNullOr(slice.get(root).resumed),
714
743
  /** The entry's lifecycle state, as the server last derived it; none until it is read. */
715
- state: (root) => Option.fromUndefinedOr(held(read(root, "state"))?.state),
744
+ state: (root) => Option.map(heldIn(root, "state"), (entryState) => entryState.state),
716
745
  /**
717
746
  * Whether the signed-in principal may ask this transition of the open
718
747
  * entry, by the server's `allow`, as the server said with the entry: false
719
748
  * until it is read. Whether the entry offers it now is its `state`'s to
720
749
  * say. For hiding what would be refused; the server still decides.
721
750
  */
722
- may: (root, transition) => held(read(root, "state"))?.may.includes(transition) === true,
751
+ may: (root, transition) => Option.exists(heldIn(root, "state"), (entryState) => entryState.may.includes(transition)),
723
752
  /** Why the last publish, save, discard or unpublish failed. */
724
753
  error: failure,
725
754
  status: (root) => {
726
755
  const editor = slice.get(root);
727
756
  if (editor.mode === "closed") return "Closed";
728
- const stateUnread = editor.mode === "edit" && !Option.match(Option.fromUndefinedOr(read(root, "state")), {
729
- onNone: () => false,
730
- onSome: RemoteData.answered
731
- });
757
+ const stateRead = read(root, "state");
758
+ const stateUnread = editor.mode === "edit" && (stateRead === void 0 || stateRead._tag !== "NotFound" && Option.isNone(RemoteData.held(stateRead)));
732
759
  if (!editor.filled || stateUnread) {
733
760
  const entry = read(root, "entry");
734
761
  if (entry?._tag === "NotFound") return "NotFound";
735
762
  return [
736
763
  entry,
737
764
  read(root, "draft"),
738
- read(root, "row")
765
+ read(root, "row"),
766
+ stateRead
739
767
  ].some((part) => part?._tag === "Failed") ? "LoadFailed" : "Loading";
740
768
  }
741
769
  const publish = statusOf(root, editor.publishId);
@@ -895,17 +923,19 @@ const revisionsOf = (model, history) => Option.match(history(model), {
895
923
  }
896
924
  });
897
925
  /** A moment as the History says it: "Sep 27, 2026" and "9:12 PM", apart. */
898
- const momentOf = (iso) => {
926
+ const momentOf = (iso, locale, timeZone) => {
899
927
  const at = new Date(iso);
900
928
  return {
901
- day: at.toLocaleDateString(void 0, {
929
+ day: at.toLocaleDateString(locale, {
902
930
  month: "short",
903
931
  day: "numeric",
904
- year: "numeric"
932
+ year: "numeric",
933
+ timeZone
905
934
  }),
906
- time: at.toLocaleTimeString(void 0, {
935
+ time: at.toLocaleTimeString(locale, {
907
936
  hour: "numeric",
908
- minute: "2-digit"
937
+ minute: "2-digit",
938
+ timeZone
909
939
  })
910
940
  };
911
941
  };
@@ -915,10 +945,15 @@ const momentOf = (iso) => {
915
945
  * the entry is on the site; restoring it is offered only while a draft sits
916
946
  * over it, since otherwise it changes nothing. A history still being read
917
947
  * says so as a busy status, and one that failed as an alert, so neither is
918
- * mistaken for nothing published nor read as plain text. A failed read is not
948
+ * mistaken for nothing published nor read as plain text; give `muted`
949
+ * `Utilities.busyReveal` (`foldkit-mixins/utilities`) and the wait is said
950
+ * only once it is noticeable. A failed read is not
919
951
  * retried on its own: given `onRetry`, a button sends it, drawn on the
920
952
  * restore slot so no new builder is required of every studio. Who published
921
953
  * is the application's to name (`authorName`), as only it knows its chairs.
954
+ * Its dates are written in the `locale` and `timeZone` given: both are
955
+ * required, since the runtime's own would differ between a server and a
956
+ * browser.
922
957
  */
923
958
  const historyCard = (slots, h, history, entry) => {
924
959
  const live = stateIs(entry.state, "Published", "Changed");
@@ -928,7 +963,7 @@ const historyCard = (slots, h, history, entry) => {
928
963
  Loading: () => [h.p(slots.muted.attrs([h.Role("status"), h.AriaBusy(true)]), ["Loading…"])],
929
964
  Ready: ({ revisions }) => [revisions.length === 0 ? h.p(slots.muted.attrs(), ["Nothing has been published yet."]) : h.ol(slots.timeline.attrs([h.AriaLabel("Published revisions, newest first")]), revisions.map((revision, index) => {
930
965
  const newest = index === 0;
931
- const { day, time } = momentOf(revision.publishedAt);
966
+ const { day, time } = momentOf(revision.publishedAt, entry.locale, entry.timeZone);
932
967
  const isLive = newest && live;
933
968
  return h.li(slots.revision.attrs(isLive ? [h.DataAttribute("live", "")] : []), [
934
969
  h.span(slots.revisionMark.attrs([h.AriaHidden(true)]), []),
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["scheduleOf"],"sources":["../src/lifecycle.ts","../src/editor.ts","../src/kinds.ts","../src/views.ts","../src/slug.ts","../src/index.ts"],"sourcesContent":["/**\n * The lifecycle of a piece of content, derived. Nothing stores a status: a state\n * is a pure function of facts (is there a row, can a visitor see it, is there a\n * draft, has the entry been archived) and a clock, so it cannot disagree with\n * them. A scheduled publish that failed reads scheduled and overdue, which is\n * true, and not published, which would not be.\n */\nimport { Schema } from 'effect'\n\n/** What is known of one entry. The server gathers it; nothing here reads a database. */\nexport interface Facts {\n /** When the entry was archived, if it was. */\n readonly archivedAt: string | null\n /** The content row: none yet, one a visitor can see, or one hidden by its `published` role. */\n readonly row: 'none' | 'visible' | 'hidden'\n /** The entry's working copy, if it has one. */\n readonly draft: {\n readonly scheduledFor: string | null\n readonly scheduleError: string | null\n } | null\n}\n\n/** A draft that is to be published at a time, and how that stands. */\nexport interface Schedule {\n readonly at: string\n /** The time has come and the draft is still a draft: the publish has not run, or failed. */\n readonly overdue: boolean\n /** Why the last attempt failed, for the author to fix. */\n readonly error: string | null\n}\n\nexport type StateTag = 'New' | 'Published' | 'Changed' | 'Unpublished' | 'Archived'\n\n/**\n * - `New`: nothing published yet.\n * - `Published`: what a visitor sees is all there is.\n * - `Changed`: published, with unpublished work beside it.\n * - `Unpublished`: a row a visitor cannot see.\n * - `Archived`: put away; nothing else applies until it is restored.\n *\n * `schedule` rides beside `New` and `Changed`, the states that have a draft to publish.\n */\nexport interface State {\n readonly _tag: StateTag\n readonly schedule: Schedule | null\n}\n\n/** What an author may ask of an entry. Each is an operation the server runs after asking `allow`. */\nexport const Transitions = Schema.Literals([\n 'save',\n 'discard',\n 'publish',\n 'schedule',\n 'unschedule',\n 'unpublish',\n 'archive',\n 'unarchive',\n 'restore',\n])\nexport type Transition = typeof Transitions.Type\n\nconst scheduleOf = (draft: Facts['draft'], now: Date): Schedule | null =>\n draft === null || draft.scheduledFor === null\n ? null\n : {\n at: draft.scheduledFor,\n overdue: new Date(draft.scheduledFor).getTime() <= now.getTime(),\n error: draft.scheduleError,\n }\n\nexport const state = (facts: Facts, now: Date): State => {\n if (facts.archivedAt !== null) return { _tag: 'Archived', schedule: null }\n const schedule = scheduleOf(facts.draft, now)\n if (facts.row === 'hidden') return { _tag: 'Unpublished', schedule }\n if (facts.row === 'none') return { _tag: 'New', schedule }\n return facts.draft === null\n ? { _tag: 'Published', schedule: null }\n : { _tag: 'Changed', schedule }\n}\n\n/**\n * The transitions a state offers, before anyone asks who is asking. `facts` says\n * whether there is a draft, which a state alone does not: an unpublished entry\n * may or may not have one. `unpublishes` is whether the content type declared a\n * `published` role: without one a row cannot be hidden, so it is not offered.\n */\nexport const offers = (\n facts: Facts,\n now: Date,\n capabilities: { readonly unpublishes: boolean },\n): ReadonlyArray<Transition> => {\n const current = state(facts, now)\n if (current._tag === 'Archived') return ['unarchive']\n const drafted = facts.draft !== null\n return [\n 'save',\n ...(drafted ? (['discard', 'publish'] as const) : []),\n ...(drafted && current.schedule === null ? (['schedule'] as const) : []),\n ...(current.schedule !== null ? (['unschedule'] as const) : []),\n ...(facts.row === 'visible' && capabilities.unpublishes ? (['unpublish'] as const) : []),\n ...(facts.row !== 'none' ? (['restore'] as const) : []),\n 'archive',\n ]\n}\n","/**\n * The authoring editor: a form, the entry it belongs to, and the draft that\n * keeps what the author has entered.\n *\n * Saving is automatic and is not publishing. Each edit starts a rest, and the\n * edit that is still the last one when its rest ends saves the form as it\n * stands, valid or not. Publishing submits the form, so its rules and checks\n * decide; what is published is the saved draft, so a publish saves first.\n *\n * The Bundle holds what is the editor's own: the form's Model and how far the\n * saves have got. What the server holds is read from Remote, never copied: the\n * draft's `updatedAt` a save is based on, and the entry's `revision` a publish is.\n */\nimport { Duration, Effect, Option, Predicate, Schema } from 'effect'\nimport { Bundle } from 'foldkit-bundle'\nimport { Entity, type AnyEntity } from 'foldkit-entity'\nimport type { Submitted } from 'foldkit-form'\nimport {\n Refusal,\n RemoteData,\n type MutationStatus,\n type OptimisticOperation,\n type RemoteClient,\n type RemoteError,\n type RemoteMessage,\n} from 'foldkit-remote'\nimport { lift, overlay, type OverlaidDomain } from 'foldkit-remote/overlay'\nimport { ModelRef, type ActiveSurface, type Projection } from 'foldkit-surface'\nimport type { Command } from 'foldkit/command'\nimport type * as FieldValidation from 'foldkit/fieldValidation'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport { defineMessageUnion } from 'foldkit/message'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport * as Subscription from 'foldkit/subscription'\nimport * as Submodel from 'foldkit/submodel'\nimport type * as Update from 'foldkit/update'\nimport type { State, Transition } from './lifecycle.js'\n\n/** How the form came to hold what it holds. */\nexport type Resumed =\n /** The draft's saved Model: the form exactly as it was left, errors and all. */\n | 'Model'\n /** The draft's values, key by key, keeping what the form still accepts. */\n | 'Values'\n /** What is published: there was no draft. */\n | 'Published'\n /** There was a draft and nothing of it fits the form any more; what is published is shown. */\n | 'Lost'\n /** Something new. */\n | 'Blank'\n\nexport type EditorStatus =\n | 'Closed'\n | 'Loading'\n | 'NotFound'\n | 'LoadFailed'\n /** Open, with nothing entered since it was opened and nothing pending. */\n | 'Opened'\n /** Edited since the last save. */\n | 'Editing'\n | 'Saving'\n | 'Saved'\n /** Someone else saved or published in between. The author's text is still in the form. */\n | 'Conflict'\n | 'SaveFailed'\n | 'Publishing'\n | 'Published'\n | 'PublishFailed'\n /**\n * A publish or a schedule the form's own checks stopped before anything was\n * sent: the fields that fail say why. Until the next edit.\n */\n | 'Incomplete'\n | 'Scheduling'\n /** Promised for later. The entry's `state` says for when, and whether it happened. */\n | 'Scheduled'\n | 'ScheduleFailed'\n\n/**\n * An editor's slice of the parent Model. `edits` counts the edits made, and\n * `savedEdit` is the count the last save was started at: the form is saved when\n * they agree.\n */\nexport interface EditorModel<FormModel> {\n readonly form: FormModel\n readonly mode: 'closed' | 'new' | 'edit'\n readonly entry: string | null\n readonly filled: boolean\n readonly resumed: Resumed | null\n readonly edits: number\n readonly savedEdit: number\n readonly saveId: string | null\n readonly saveWanted: boolean\n readonly publishId: string | null\n readonly publishWanted: boolean\n /**\n * The last publish or schedule asked, as the form took it: waiting for a\n * check still running, or stopped by one and not edited since; else idle.\n */\n readonly submit: 'idle' | 'waiting' | 'stopped'\n /** When the publish that is wanted, under way or last settled is a promise for later: for when. */\n readonly scheduleAt: string | null\n /** The discard or unpublish in progress or last settled. */\n readonly otherId: string | null\n /** Whether what is in the form is laid over the store, for the application's own views to draw. */\n readonly previewing: boolean\n /** What the overlay was last made of: the edit, and the row it is shown on. */\n readonly previewedAs: string | null\n /** After a conflict: waiting for the server's copy, to show it or to save over it. */\n readonly settling: 'reload' | 'overwrite' | null\n}\n\n/** What the editor asks of where it is placed; `onOut` answers each. */\nexport type EditorOut =\n | { readonly _tag: 'Save' }\n | { readonly _tag: 'Publish' }\n | { readonly _tag: 'Discard' }\n | { readonly _tag: 'Restore'; readonly revision: number }\n | { readonly _tag: 'Unpublish' }\n | { readonly _tag: 'Unschedule' }\n | { readonly _tag: 'Archive' }\n | { readonly _tag: 'Unarchive' }\n | { readonly _tag: 'Reload' }\n | { readonly _tag: 'Overwrite' }\n\n/** The parts of a `Form.make` result the editor drives. */\n/** `Services` is what the form's Commands and Subscriptions require, which the editor's then do. */\nexport interface EditorForm<FormModel, FormMessage, Value, Resources = {}, Services = never> {\n readonly name: string\n readonly input: { readonly schema: Schema.Struct<any> }\n readonly bundle: {\n readonly Model: Schema.Codec<FormModel, unknown>\n readonly Message: Schema.Codec<FormMessage, unknown>\n readonly update: (\n model: FormModel,\n message: FormMessage,\n args: void,\n ) => Update.ReturnWithOutMessage<FormModel, FormMessage, Submitted<Value>, Services>\n /** The Subscriptions of the form's controls backed by a Bundle, which the editor runs while open. */\n readonly subscriptions?: (\n args: void,\n ) => Subscription.Subscriptions<FormModel, FormMessage, Services>\n /** Their Resources, which the editor holds while open. */\n readonly resources?: (args: void) => Resources\n }\n readonly Message: {\n readonly Submitted: () => FormMessage\n readonly Refused: (payload: {\n readonly key: never\n readonly error: string\n readonly value: unknown\n }) => FormMessage\n readonly About: (payload: { readonly subject: Readonly<Record<string, string>> }) => FormMessage\n }\n readonly initial: FormModel\n readonly fill: (model: FormModel, values: Partial<Value>) => { readonly model: FormModel }\n readonly partial: (model: FormModel) => Partial<Value>\n readonly settled: (model: FormModel) => FormModel\n /** What the form is editing; `{}` while it creates. See `Form.FormModel.subject`. */\n readonly subject: (model: FormModel) => Readonly<Record<string, string>>\n /**\n * Whether a completed transition changed authored content (§45). The editor\n * asks this instead of recognizing the form's Message tags, so a control it\n * does not know about — a Bundle-backed one, a stateful one — autosaves the\n * same way a text field does, and a blur or a refused edit does not.\n */\n authoredChanged(before: FormModel, after: FormModel): boolean\n /** Whether a check is still running, which a submit waits for. */\n readonly engine: { readonly isValidating: (model: FormModel) => boolean }\n readonly field: (model: FormModel, key: never) => FieldValidation.Field<unknown>\n}\n\n/** The parts of a bound Remote domain the editor uses. */\nexport interface EditorDomain<Root> extends OverlaidDomain<Root> {\n // Method syntax: the descriptors are checked where the domain is made, not here.\n mutate(\n model: Root,\n mutation: any,\n input: any,\n ): {\n readonly model: Root\n readonly requestId: string\n readonly command: Command<RemoteMessage, never, RemoteClient>\n }\n get(selection: any, id: string): Projection<Root, RemoteData<any>>\n mutation(model: Root, requestId: string): MutationStatus\n refusal(model: Root, requestId: string, mutation: any): Option.Option<unknown>\n refresh(model: Root, target: any): Root\n plan(model: Root, projection: Projection<Root, any>): ReadonlyArray<unknown>\n /** `Data.active`: a read of the domain as an active Surface of its application. */\n active(\n name: string,\n projectionOf: (model: Root) => Option.Option<Projection<Root, any>>,\n ): ActiveSurface<Root>\n}\n\nexport interface EditorContent<FormModel, FormMessage, Value, Resources = {}, Services = never> {\n readonly name: string\n readonly entity: AnyEntity\n readonly form: EditorForm<FormModel, FormMessage, Value, Resources, Services>\n readonly roles: {\n readonly label: { readonly key: string } | undefined\n readonly slug: { readonly key: string } | undefined\n }\n readonly preview?:\n | ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>)\n | undefined\n}\n\nconst held = <A>(read: RemoteData<A> | undefined): A | undefined =>\n read?._tag === 'Ready' || read?._tag === 'Refreshing' ? read.value : undefined\n\n/** Read, and not being read again: what the server said last, not what it said before. */\nconst fresh = (read: RemoteData<unknown> | undefined): boolean =>\n read?._tag === 'Ready' || read?._tag === 'NotFound'\n\n// The editor's own Messages, beside the form's. `Rested` is the end of the\n// rest an edit started; the rest are what an author asks.\nexport const EditorMessage = defineMessageUnion({\n Rested: { edit: Schema.Number },\n PublishAsked: {},\n /** Lays what is in the form over the store, until `PreviewHidden`. Nothing is sent. */\n PreviewShown: {},\n PreviewHidden: {},\n /** Publishes later: the form is submitted and saved now, and the server keeps the promise. */\n ScheduleAsked: { at: Schema.String },\n UnscheduleAsked: {},\n ArchiveAsked: {},\n UnarchiveAsked: {},\n DiscardAsked: {},\n /** Makes a revision's value the working copy. It replaces what is here, and publishes nothing. */\n RestoreAsked: { revision: Schema.Number },\n UnpublishAsked: {},\n /** After a conflict: drop what is here and show the server's copy. */\n ReloadAsked: {},\n /** After a conflict: save what is here over the server's copy. */\n OverwriteAsked: {},\n})\nexport type EditorMessage = typeof EditorMessage.Type\nconst Own = EditorMessage\ntype Own = EditorMessage\n\n/**\n * A form's Submodel view as the view of the editor that wraps it, for\n * `Bundle.withView`: the editor's Model holds the form's under `form`, and what\n * the form's view sends is among the editor's Messages.\n *\n * ```ts\n * Editor.bundle.pipe(Bundle.withView(Cms.editorView(FormView.submodel(form, view))))\n * ```\n */\nexport const editorView = <FormModel, FormMessage, ViewInputs>(\n view: Submodel.View<FormModel, FormMessage, ViewInputs>,\n): Submodel.View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs> =>\n Submodel.defineView<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>(((\n model: EditorModel<FormModel>,\n inputs: ViewInputs,\n h: HtmlBuilder<FormMessage>,\n ): Html =>\n (view as (model: FormModel, inputs: ViewInputs, h: HtmlBuilder<FormMessage>) => Html)(\n model.form,\n inputs,\n h,\n )) as never)\n\nexport const makeEditor =\n (cms: {\n readonly Entities: { readonly Entry: AnyEntity; readonly Draft: AnyEntity }\n readonly Operations: Readonly<\n Record<\n | 'SaveDraft'\n | 'DiscardDraft'\n | 'Publish'\n | 'Unpublish'\n | 'Schedule'\n | 'Unschedule'\n | 'Archive'\n | 'Unarchive'\n | 'Restore',\n any\n >\n >\n }) =>\n <\n const Name extends string,\n FormModel,\n FormMessage extends { readonly _tag: string },\n Value,\n Resources = {},\n Services = never,\n >(\n name: Name,\n config: {\n readonly content: EditorContent<FormModel, FormMessage, Value, Resources, Services>\n /** How long after the last edit the draft is saved. Default: one second. */\n readonly rest?: Duration.Input\n /** Bumped when the form changes so that a saved Model no longer fits it. */\n readonly version?: string\n /** What an entry with no label yet is called in the worklist. */\n readonly untitled?: string\n },\n ) => {\n type Model = EditorModel<FormModel>\n const { content } = config\n const { form } = content\n const rest = config.rest ?? '1 second'\n const formTag = `${form.name}@${config.version ?? '1'}`\n\n const closed: Model = {\n form: form.initial,\n mode: 'closed',\n entry: null,\n filled: false,\n resumed: null,\n edits: 0,\n savedEdit: 0,\n saveId: null,\n saveWanted: false,\n publishId: null,\n publishWanted: false,\n submit: 'idle',\n scheduleAt: null,\n otherId: null,\n previewing: false,\n previewedAs: null,\n settling: null,\n }\n const Model = Schema.Struct({\n form: form.bundle.Model,\n mode: Schema.Literals(['closed', 'new', 'edit']),\n entry: Schema.NullOr(Schema.String),\n filled: Schema.Boolean,\n resumed: Schema.NullOr(Schema.Literals(['Model', 'Values', 'Published', 'Lost', 'Blank'])),\n edits: Schema.Number,\n savedEdit: Schema.Number,\n saveId: Schema.NullOr(Schema.String),\n saveWanted: Schema.Boolean,\n publishId: Schema.NullOr(Schema.String),\n publishWanted: Schema.Boolean,\n submit: Schema.Literals(['idle', 'waiting', 'stopped']),\n scheduleAt: Schema.NullOr(Schema.String),\n otherId: Schema.NullOr(Schema.String),\n previewing: Schema.Boolean,\n previewedAs: Schema.NullOr(Schema.String),\n settling: Schema.NullOr(Schema.Literals(['reload', 'overwrite'])),\n }) as unknown as Schema.Codec<Model, unknown>\n\n type Message = FormMessage | Own\n const Message = Schema.Union([form.bundle.Message, Own]) as unknown as Schema.Codec<\n Message,\n unknown\n >\n const own = new Set([\n 'Rested',\n 'PublishAsked',\n 'PreviewShown',\n 'PreviewHidden',\n 'ScheduleAsked',\n 'UnscheduleAsked',\n 'ArchiveAsked',\n 'UnarchiveAsked',\n 'DiscardAsked',\n 'RestoreAsked',\n 'UnpublishAsked',\n 'ReloadAsked',\n 'OverwriteAsked',\n ])\n const isOwn = (message: Message): message is Own => own.has(message._tag)\n\n const asks: Readonly<\n Record<\n Exclude<\n Own['_tag'],\n | 'Rested'\n | 'PublishAsked'\n | 'ScheduleAsked'\n | 'RestoreAsked'\n | 'PreviewShown'\n | 'PreviewHidden'\n >,\n EditorOut\n >\n > = {\n DiscardAsked: { _tag: 'Discard' },\n UnpublishAsked: { _tag: 'Unpublish' },\n UnscheduleAsked: { _tag: 'Unschedule' },\n ArchiveAsked: { _tag: 'Archive' },\n UnarchiveAsked: { _tag: 'Unarchive' },\n ReloadAsked: { _tag: 'Reload' },\n OverwriteAsked: { _tag: 'Overwrite' },\n }\n\n type Returned = Update.ReturnWithOutMessage<Model, Message, EditorOut, Services>\n\n const viaForm = (model: Model, message: FormMessage): Returned => {\n const next = form.bundle.update(model.form, message, undefined)\n // Authored content, not Message tags: a blur, a refusal, or a no-op does\n // not start a save, and a control the editor does not know about does.\n const edited = form.authoredChanged(model.form, next.model)\n const edits = edited ? model.edits + 1 : model.edits\n const commands: ReadonlyArray<Command<Message, never, Services>> = [\n // A form Message is one of the editor's, so the form's Commands are the editor's.\n ...((next.commands ?? []) as ReadonlyArray<Command<Message, never, Services>>),\n ...(edited\n ? [\n {\n name: `${name}.rest`,\n args: { edit: edits },\n effect: Effect.sleep(rest).pipe(Effect.as(Own.Rested({ edit: edits }))),\n } satisfies Command<Message, never, never>,\n ]\n : []),\n ]\n // A submit the form stopped is said until the next edit: stopped at once, or once\n // the check it waited for answered without letting it go.\n const validating = form.engine.isValidating(next.model)\n const submit: Model['submit'] =\n next.outMessage !== undefined || edited\n ? 'idle'\n : Predicate.isTagged(message, 'Submitted')\n ? validating\n ? 'waiting'\n : 'stopped'\n : model.submit === 'waiting' && !validating\n ? 'stopped'\n : model.submit\n // A form Message that changed nothing keeps this Model: Foldkit renders on its identity.\n const result = {\n model:\n next.model === model.form && submit === model.submit\n ? model\n : { ...model, form: next.model, edits, submit },\n commands,\n }\n return next.outMessage === undefined ? result : { ...result, outMessage: { _tag: 'Publish' } }\n }\n\n const bundle = Bundle.make(name, {\n Model,\n Message,\n init: () => ({ model: closed }),\n update: (model: Model, message: Message): Returned => {\n if (model.mode === 'closed') return { model }\n // A submit from the form's own button is a publish now, whatever was asked before.\n if (!isOwn(message))\n return viaForm(\n Predicate.isTagged(message, 'Submitted') ? { ...model, scheduleAt: null } : model,\n message,\n )\n switch (message._tag) {\n case 'Rested':\n // An edit since then started its own rest; this one has nothing to say.\n return message.edit === model.edits && model.edits > model.savedEdit\n ? { model, outMessage: { _tag: 'Save' } }\n : { model }\n case 'PublishAsked':\n return viaForm({ ...model, scheduleAt: null }, form.Message.Submitted())\n case 'PreviewShown':\n // A capability is declared, never implied.\n return content.preview === undefined\n ? { model }\n : { model: { ...model, previewing: true, previewedAs: null } }\n case 'PreviewHidden':\n return model.previewing ? { model: { ...model, previewing: false } } : { model }\n case 'RestoreAsked':\n return { model, outMessage: { _tag: 'Restore', revision: message.revision } }\n case 'ScheduleAsked':\n return viaForm({ ...model, scheduleAt: message.at }, form.Message.Submitted())\n case 'UnscheduleAsked':\n case 'ArchiveAsked':\n case 'UnarchiveAsked':\n case 'DiscardAsked':\n case 'UnpublishAsked':\n case 'ReloadAsked':\n case 'OverwriteAsked':\n return { model, outMessage: asks[message._tag] }\n }\n },\n helpers: {\n /** Opens an entry: its draft is resumed, or what is published is shown. */\n open: (_: Model, entry: string) => ({\n model: { ...closed, mode: 'edit' as const, entry },\n }),\n /**\n * Something new, under an id made where this is called (`Cms.newEntryId()`,\n * in a Command or an event handler): the first save makes the entry.\n */\n create: (_: Model, entry: string) => ({\n model: {\n ...closed,\n mode: 'new' as const,\n entry,\n filled: true,\n resumed: 'Blank' as const,\n },\n }),\n close: () => ({ model: closed }),\n },\n // A form control backed by a Bundle may listen and hold resources: they\n // run while an entry is open, and stop when the editor closes.\n subscriptions: () =>\n form.bundle.subscriptions === undefined\n ? {}\n : Subscription.lift(form.bundle.subscriptions(undefined))({\n read: (model: Model) =>\n model.mode === 'closed' ? Option.none() : Option.some(model.form),\n toParentMessage: (message: FormMessage): Message => message,\n }),\n resources: () =>\n (form.bundle.resources === undefined\n ? {}\n : ManagedResource.lift(\n form.bundle.resources(undefined) as Readonly<Record<string, never>>,\n )({\n read: (model: Model) =>\n model.mode === 'closed' ? Option.none() : Option.some(model.form),\n toParentMessage: message => message as Message,\n })) as [keyof Resources] extends [never] ? {} : Readonly<Record<string, never>>,\n })\n\n const EntryRead = Entity.select(\n cms.Entities.Entry as never,\n {\n type: true,\n targetId: true,\n revision: true,\n archivedAt: true,\n } as never,\n )\n const EntryState = Entity.select(\n cms.Entities.Entry as never,\n { state: true, may: true } as never,\n )\n const DraftRead = Entity.select(\n cms.Entities.Draft as never,\n {\n values: true,\n model: true,\n form: true,\n updatedAt: true,\n } as never,\n )\n const RowRead = Entity.selectFor(form.input as never)\n\n const decodeModel = Schema.decodeUnknownOption(form.bundle.Model)\n const encodeModel = Schema.encodeUnknownSync(form.bundle.Model as never)\n\n /** The keys of some saved values the form still accepts. */\n const fitting = (values: unknown): Partial<Value> => {\n if (typeof values !== 'object' || values === null) return {}\n const fields = form.input.schema.fields as Readonly<Record<string, Schema.Schema<unknown>>>\n return Object.fromEntries(\n Object.entries(values).filter(\n ([key, value]) => fields[key] !== undefined && Schema.is(fields[key])(value),\n ),\n ) as Partial<Value>\n }\n\n return {\n bundle,\n Message: Own,\n /** What is saved as a draft's `form`: the form's name and the version given. */\n formTag,\n\n at: <Root>(where: {\n readonly data: EditorDomain<Root>\n readonly model: ModelRef<Root, Model>\n }) => {\n type Step = Update.Step<Root, RemoteMessage, RemoteClient>\n const { data } = where\n const slice = ModelRef.focus(where.model)\n\n const entryOf = (root: Root) => {\n const { mode, entry, saveId } = slice.get(root)\n // Something new is not on the server until its first save.\n return entry === null || mode === 'closed' || (mode === 'new' && saveId === null)\n ? undefined\n : entry\n }\n /** What the editor reads of the open entry: each none while there is none to read. */\n const projections = {\n entry: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(EntryRead, entry)),\n state: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(EntryState, entry)),\n draft: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(DraftRead, entry)),\n row: (root: Root) =>\n Option.map(\n Option.fromNullishOr(\n held<{ readonly targetId: string | null }>(read(root, 'entry'))?.targetId,\n ),\n target => data.get(RowRead, target),\n ),\n }\n // The editor's own reasoning reads these as plain values, with `held`.\n const read = (root: Root, part: keyof typeof projections): RemoteData<any> | undefined =>\n Option.getOrUndefined(\n Option.map(projections[part](root), projection => projection.read(root)),\n )\n /**\n * Read and asked for nothing more. A draft known absent still reads\n * `NotFound` while a refresh asks about it again, so `fresh` alone\n * would take the old absence for the answer; the plan holds it until then.\n */\n const answered = (root: Root, part: keyof typeof projections): boolean =>\n fresh(read(root, part)) &&\n Option.match(projections[part](root), {\n onNone: () => true,\n onSome: projection => data.plan(root, projection).length === 0,\n })\n\n const statusOf = (root: Root, requestId: string | null): MutationStatus =>\n requestId === null ? { _tag: 'Unknown' } : data.mutation(root, requestId)\n /** Why the server refused a request, as the data its mutation declares. */\n const refusalOf = (\n root: Root,\n requestId: string | null,\n mutation: unknown,\n ): Option.Option<unknown> =>\n requestId === null ? Option.none() : data.refusal(root, requestId, mutation)\n\n /** Shows what was loaded, once: the draft by the ladder, else what is published. */\n const fill = (root: Root): Root => {\n const editor = slice.get(root)\n if (editor.filled || editor.mode !== 'edit') return root\n // A discard under way decides what there is to show.\n if (statusOf(root, editor.otherId)._tag === 'Pending') return root\n const entry = read(root, 'entry')\n const draft = read(root, 'draft')\n // After a conflict, what was held before is not what the server holds now.\n const arrived =\n editor.settling === 'reload'\n ? fresh\n : (r: RemoteData<unknown> | undefined) =>\n held(r) !== undefined || r?._tag === 'NotFound'\n if (!arrived(entry) || !arrived(draft)) return root\n const entryValue = held<{ readonly targetId: string | null }>(entry)\n if (entryValue === undefined) return root\n const shown = (resumed: Resumed, next: FormModel): Root =>\n slice.set(root, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n form: next,\n filled: true,\n resumed,\n // A discard that led here is still the last thing that was asked.\n otherId: editor.otherId,\n })\n\n const saved = held<{\n readonly values: unknown\n readonly model: unknown\n readonly form: string\n }>(draft)\n if (saved !== undefined) {\n const model = saved.form === formTag ? decodeModel(saved.model) : Option.none()\n // A check that was running when it was saved will never answer.\n if (Option.isSome(model)) return shown('Model', form.settled(model.value))\n const values = fitting(saved.values)\n if (Object.keys(values).length > 0)\n return shown('Values', form.fill(form.initial, values).model)\n }\n const lost: Resumed = saved === undefined ? 'Published' : 'Lost'\n if (entryValue.targetId === null)\n return shown(saved === undefined ? 'Blank' : 'Lost', form.initial)\n const row = read(root, 'row')\n if (!arrived(row)) return root\n const rowValue = held<Readonly<Record<string, unknown>>>(row)\n return rowValue === undefined\n ? shown(lost, form.initial)\n : shown(\n lost,\n form.fill(\n form.initial,\n Entity.valuesFor(form.input as never, rowValue as never) as Partial<Value>,\n ).model,\n )\n }\n\n const startSave: Step = root => {\n const editor = slice.get(root)\n const values = form.partial(editor.form) as Readonly<Record<string, unknown>>\n const labelKey = content.roles.label?.key\n const typed =\n labelKey === undefined ? '' : form.field(editor.form, labelKey as never).value\n const label = typeof typed === 'string' ? typed.trim() : ''\n const basedOn =\n held<{ readonly updatedAt: string }>(read(root, 'draft'))?.updatedAt ?? null\n const started = data.mutate(root, cms.Operations.SaveDraft, {\n entry: editor.entry,\n type: content.name,\n label: label === '' ? (config.untitled ?? 'Untitled') : label,\n values,\n // Settled, as it is shown again: nothing in flight is stored, such as a Builder's\n // undo history, which made a big page's draft too large to save.\n model: encodeModel(form.settled(editor.form)),\n form: formTag,\n basedOn,\n })\n return {\n model: slice.set(started.model, {\n ...slice.get(started.model),\n saveId: started.requestId,\n // A save starts a new round: the last publish no longer describes the form.\n publishId: null,\n otherId: null,\n savedEdit: editor.edits,\n saveWanted: false,\n settling: null,\n }),\n commands: [started.command],\n }\n }\n\n /** An operation that names the entry and nothing else. The server's patches say what it did. */\n const simple =\n (operation: 'Unpublish' | 'Unschedule' | 'Archive' | 'Unarchive'): Step =>\n root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n const started = data.mutate(root, cms.Operations[operation], { entry: editor.entry })\n return {\n model: slice.set(started.model, {\n ...slice.get(started.model),\n otherId: started.requestId,\n }),\n commands: [started.command],\n }\n }\n\n /**\n * A discarded draft takes what is on screen with it, the edits still resting\n * included. What is published is shown again once the discard has settled;\n * something never published has nothing left, and the editor closes.\n */\n const discard: Step = root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n // Something new that was never saved is only here.\n if (editor.mode === 'new' && editor.saveId === null)\n return { model: slice.set(root, closed) }\n const unpublished =\n held<{ readonly targetId: string | null }>(read(root, 'entry'))?.targetId == null\n const started = data.mutate(root, cms.Operations.DiscardDraft, { entry: editor.entry })\n return {\n model: slice.set(\n started.model,\n unpublished\n ? closed\n : {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n otherId: started.requestId,\n settling: 'reload',\n },\n ),\n commands: [started.command],\n }\n }\n\n /** The form is emptied, and filled from the restored draft once the restore has settled. */\n const restore =\n (revision: number): Step =>\n root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n const started = data.mutate(root, cms.Operations.Restore, {\n entry: editor.entry,\n revision,\n })\n return {\n model: slice.set(started.model, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n otherId: started.requestId,\n settling: 'reload',\n }),\n commands: [started.command],\n }\n }\n\n /**\n * What follows from what has arrived: the loaded value is shown, a save\n * that waited its turn starts, and a publish goes once its draft is saved.\n */\n const overlayId = `${name}.preview`\n /**\n * What is in the form, over the store, while preview is on: made again when\n * the form has moved on, and lifted the moment it is off, however that came\n * about (a close, a discard, a reload).\n */\n const previewed = (root: Root): Root => {\n const editor = slice.get(root)\n if (!editor.previewing || content.preview === undefined || editor.entry === null)\n return lift(data, root, overlayId)\n // Something new is shown under its entry's id until publishing gives it a row.\n const id =\n held<{ readonly targetId: string | null }>(read(root, 'entry'))?.targetId ??\n editor.entry\n const as = `${editor.edits}:${id}`\n if (editor.previewedAs === as) return root\n const shown = overlay(\n data,\n root,\n overlayId,\n content.preview(form.partial(editor.form), id),\n )\n return slice.set(shown, { ...slice.get(shown), previewedAs: as })\n }\n\n /**\n * A server's word about one key, on that key. A publish refused for a taken\n * address is about the address, and belongs beside it rather than in a\n * status line. Saying it again while it already stands would be noise.\n */\n const refused = (root: Root): Root => {\n const editor = slice.get(root)\n const refusal = Option.filter(\n refusalOf(root, editor.publishId, cms.Operations.Publish),\n Refusal.isField,\n )\n if (Option.isNone(refusal)) return root\n const { key } = refusal.value\n // A publish sends the saved draft, which the form still holds until the next edit.\n if (content.roles.slug?.key !== key || editor.edits !== editor.savedEdit) return root\n const reason = String(refusal.value.reason)\n const field = form.field(editor.form, key as never)\n if (field._tag === 'Invalid' && field.errors.includes(reason)) return root\n return slice.set(root, {\n ...editor,\n form: form.bundle.update(\n editor.form,\n form.Message.Refused({\n key: key as never,\n error: reason,\n value: (form.partial(editor.form) as Readonly<Record<string, unknown>>)[key],\n }),\n undefined,\n ).model,\n })\n }\n\n /**\n * Tells the form which row it is editing, so a check that asks the server\n * about a key can pass over what this row already holds: an address is not\n * taken by the post that owns it. A form that creates something is about\n * nothing, which is the subject it starts with.\n */\n const about = (root: Root): Root => {\n const editor = slice.get(root)\n const target = held<{ readonly targetId: string | null }>(read(root, 'entry'))?.targetId\n const subject = target === null || target === undefined ? {} : { id: target }\n if (form.subject(editor.form).id === subject.id) return root\n return slice.set(root, {\n ...editor,\n form: form.bundle.update(editor.form, form.Message.About({ subject }), undefined).model,\n })\n }\n\n const sync: Step = given => {\n let root = refused(previewed(about(fill(given))))\n const commands: Array<Command<RemoteMessage, never, RemoteClient>> = []\n const run = (step: Step) => {\n const next = step(root)\n root = next.model\n commands.push(...(next.commands ?? []))\n }\n const editor = () => slice.get(root)\n if (editor().mode === 'closed' || !editor().filled) return { model: root }\n\n const saving = () => statusOf(root, editor().saveId)._tag === 'Pending'\n // Saving over someone else's copy is based on that copy, once it is here.\n if (editor().settling === 'overwrite' && answered(root, 'draft')) run(startSave)\n if (editor().saveWanted && !saving() && editor().settling === null) run(startSave)\n\n // A second ask while the first is on its way is the same ask.\n if (editor().publishWanted && statusOf(root, editor().publishId)._tag === 'Pending')\n root = slice.set(root, { ...editor(), publishWanted: false })\n if (editor().publishWanted && !saving() && editor().settling === null) {\n const save = statusOf(root, editor().saveId)\n const resumedDraft = editor().resumed === 'Model' || editor().resumed === 'Values'\n const saved =\n editor().edits === editor().savedEdit &&\n (editor().saveId === null ? resumedDraft : save._tag === 'Applied')\n if (save._tag === 'Failed' && editor().edits === editor().savedEdit) {\n // The draft could not be saved, so there is nothing to publish; the save says why.\n root = slice.set(root, { ...editor(), publishWanted: false })\n } else if (!saved) {\n run(startSave)\n } else {\n const basedOn =\n held<{ readonly revision: number | null }>(read(root, 'entry'))?.revision ?? null\n const at = editor().scheduleAt\n const started =\n at === null\n ? data.mutate(root, cms.Operations.Publish, { entry: editor().entry, basedOn })\n : data.mutate(root, cms.Operations.Schedule, { entry: editor().entry, at })\n root = slice.set(started.model, {\n ...slice.get(started.model),\n publishId: started.requestId,\n publishWanted: false,\n })\n commands.push(started.command)\n }\n }\n return { model: root, commands }\n }\n\n const failure = (root: Root): Option.Option<RemoteError> => {\n const editor = slice.get(root)\n for (const id of [editor.publishId, editor.saveId, editor.otherId]) {\n const status = statusOf(root, id)\n if (status._tag === 'Failed') return Option.some(status.error)\n }\n return Option.none()\n }\n\n const active = (part: keyof typeof projections): ActiveSurface<Root> =>\n data.active(`${name}.${part}`, projections[part])\n\n return {\n /** For the placement: what the editor asked becomes the mutation, or waits its turn. */\n onOut:\n (out: EditorOut): Step =>\n root => {\n const editor = slice.get(root)\n switch (out._tag) {\n case 'Save':\n return sync(slice.set(root, { ...editor, saveWanted: true }))\n case 'Publish':\n return sync(slice.set(root, { ...editor, publishWanted: true }))\n case 'Restore':\n return restore(out.revision)(root)\n case 'Discard':\n return discard(root)\n case 'Unpublish':\n return simple('Unpublish')(root)\n case 'Unschedule':\n return simple('Unschedule')(root)\n case 'Archive':\n return simple('Archive')(root)\n case 'Unarchive':\n return simple('Unarchive')(root)\n case 'Reload': {\n const refreshed = (['entry', 'draft', 'row'] as const).reduce(\n (next, part) =>\n Option.match(projections[part](next), {\n onNone: () => next,\n onSome: projection => data.refresh(next, projection),\n }),\n root,\n )\n return {\n model: slice.set(refreshed, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n settling: 'reload',\n }),\n }\n }\n case 'Overwrite': {\n const refreshed = Option.match(projections.draft(root), {\n onNone: () => root,\n onSome: projection => data.refresh(root, projection),\n })\n return {\n model: slice.set(refreshed, { ...slice.get(refreshed), settling: 'overwrite' }),\n }\n }\n }\n },\n\n /**\n * For `Data.subscriptions`, spread beside the application's own: the entry,\n * its state, its draft, and the row what is published is shown from. Each\n * is a requirement while an entry is open, so Remote fetches and retains it.\n */\n actives: {\n [`${name}.entry`]: active('entry'),\n [`${name}.state`]: active('state'),\n [`${name}.draft`]: active('draft'),\n [`${name}.row`]: active('row'),\n } as Readonly<\n Record<`${Name}.${'entry' | 'state' | 'draft' | 'row'}`, ActiveSurface<Root>>\n >,\n\n sync,\n\n /**\n * Saves what has not been saved, now, without waiting for the rest to end.\n * Run it before `close` or `open`, which drop what is in the form: an\n * author who types and leaves within the rest would otherwise lose it.\n */\n flush: (root => {\n const editor = slice.get(root)\n return editor.mode === 'closed' || !editor.filled || editor.edits === editor.savedEdit\n ? { model: root }\n : sync(slice.set(root, { ...editor, saveWanted: true }))\n }) satisfies Step,\n\n /**\n * Wraps the application's `update` so `sync` runs after every Message: a\n * value may arrive, or a save settle, with any of them.\n */\n after:\n <\n Message,\n Result extends { readonly model: Root; readonly commands?: ReadonlyArray<any> },\n >(\n update: (model: Root, message: Message) => Result,\n ) =>\n (model: Root, message: Message): Result => {\n const next = update(model, message)\n const synced = sync(next.model)\n return {\n ...next,\n model: synced.model,\n commands: [...(next.commands ?? []), ...(synced.commands ?? [])],\n }\n },\n\n /** Whether this content type can be previewed, and whether it is being. */\n canPreview: content.preview !== undefined,\n previewing: (root: Root): boolean => slice.get(root).previewing,\n /**\n * The id the application's own pages know this content by: the row's, or\n * the entry's while there is no row. It is what a preview is shown under.\n */\n pageId: (root: Root): Option.Option<string> =>\n Option.fromNullishOr(\n held<{ readonly targetId: string | null }>(read(root, 'entry'))?.targetId ??\n slice.get(root).entry,\n ),\n /** The entry being edited; none while closed. */\n entry: (root: Root): Option.Option<string> => Option.fromNullOr(slice.get(root).entry),\n /**\n * The entry as the server knows it: none while closed, and while\n * something new is not saved yet, so a link naming it would find nothing.\n */\n storedEntry: (root: Root): Option.Option<string> => Option.fromUndefinedOr(entryOf(root)),\n /** How the form came to hold what it holds; `Lost` is worth telling the author. */\n resumed: (root: Root): Option.Option<Resumed> =>\n Option.fromNullOr(slice.get(root).resumed),\n /** The entry's lifecycle state, as the server last derived it; none until it is read. */\n state: (root: Root): Option.Option<State> =>\n Option.fromUndefinedOr(held<{ readonly state: State }>(read(root, 'state'))?.state),\n /**\n * Whether the signed-in principal may ask this transition of the open\n * entry, by the server's `allow`, as the server said with the entry: false\n * until it is read. Whether the entry offers it now is its `state`'s to\n * say. For hiding what would be refused; the server still decides.\n */\n may: (root: Root, transition: Transition): boolean =>\n held<{ readonly may: ReadonlyArray<Transition> }>(read(root, 'state'))?.may.includes(\n transition,\n ) === true,\n /** Why the last publish, save, discard or unpublish failed. */\n error: failure,\n\n status: (root: Root): EditorStatus => {\n const editor = slice.get(root)\n if (editor.mode === 'closed') return 'Closed'\n // An entry opened from the server is loading until its state is read\n // too, so what the state draws (the badge, the history, Publish)\n // arrives with the form instead of a moment after it.\n const stateUnread =\n editor.mode === 'edit' &&\n !Option.match(Option.fromUndefinedOr(read(root, 'state')), {\n onNone: () => false,\n onSome: RemoteData.answered,\n })\n if (!editor.filled || stateUnread) {\n const entry = read(root, 'entry')\n if (entry?._tag === 'NotFound') return 'NotFound'\n return [entry, read(root, 'draft'), read(root, 'row')].some(\n part => part?._tag === 'Failed',\n )\n ? 'LoadFailed'\n : 'Loading'\n }\n const publish = statusOf(root, editor.publishId)\n const save = statusOf(root, editor.saveId)\n const later = editor.scheduleAt !== null\n // A submit waiting for a check is on its way, as one sent is.\n if (publish._tag === 'Pending' || editor.submit === 'waiting')\n return later ? 'Scheduling' : 'Publishing'\n if (save._tag === 'Pending' || editor.settling === 'overwrite') return 'Saving'\n if (editor.submit === 'stopped') return 'Incomplete'\n const conflicted =\n Option.exists(\n refusalOf(root, editor.saveId, cms.Operations.SaveDraft),\n Refusal.isConflict,\n ) ||\n Option.exists(\n refusalOf(root, editor.publishId, cms.Operations.Publish),\n Refusal.isConflict,\n )\n if (editor.edits > editor.savedEdit) return 'Editing'\n if (conflicted) return 'Conflict'\n // A failed save outranks what the publish says; neither is pending here.\n switch (save._tag) {\n case 'Failed':\n return 'SaveFailed'\n case 'Unknown':\n case 'Applied':\n switch (publish._tag) {\n case 'Failed':\n return later ? 'ScheduleFailed' : 'PublishFailed'\n case 'Applied':\n return later ? 'Scheduled' : 'Published'\n case 'Unknown':\n // Nothing pending and nothing entered: the form is as it was found. A\n // draft it was filled from is on the server already; anything else is not.\n return save._tag === 'Applied' ||\n editor.resumed === 'Model' ||\n editor.resumed === 'Values'\n ? 'Saved'\n : 'Opened'\n }\n }\n },\n }\n },\n }\n }\n","/**\n * The displays a CMS adds, made with `Display.kind` exactly as an application\n * makes its own, and a renderer for each to spread beside `foldkit-mixins-crud`'s.\n * Its controls, a slug and a moment, are `foldkit-form-recipes`'.\n * Entry-level views (its state badge, published history, remaining\n * transitions) live in `./views.js`: they draw on the application's own slot\n * builders, so the application keeps its slots and styles.\n */\nimport { Display, type DisplayWords } from 'foldkit-crud'\nimport { fillWords } from 'foldkit-form'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { State } from './lifecycle.js'\n\n/**\n * The attribute an entry's state is written in, wherever the CMS draws one (a\n * list's state cell, `stateBadge`): one name, so one tone rule styles both.\n */\nexport const stateAttribute = 'data-cms-state'\n\nexport interface StateWords {\n readonly New?: string\n readonly Published?: string\n readonly Changed?: string\n readonly Unpublished?: string\n readonly Archived?: string\n readonly scheduled?: string\n readonly overdue?: string\n /** A state with what its schedule adds: `{state}` and `{schedule}`. */\n readonly withSchedule?: string\n}\nconst stateWords: Required<StateWords> = {\n New: 'New',\n Published: 'Published',\n Changed: 'Changed',\n Unpublished: 'Unpublished',\n Archived: 'Archived',\n scheduled: 'scheduled',\n overdue: 'overdue',\n withSchedule: '{state}, {schedule}',\n}\n\nconst isState = (value: unknown): value is State =>\n typeof value === 'object' && value !== null && '_tag' in value && 'schedule' in value\n\n/** What a state's schedule adds to it: nothing, `scheduled`, or `overdue`. */\nconst scheduleOf = (state: State): 'scheduled' | 'overdue' | undefined =>\n state.schedule === null ? undefined : state.schedule.overdue ? 'overdue' : 'scheduled'\n\n/** An entry's lifecycle state, as words. A publish that did not happen says so. */\nconst StateDisplay = Display.kind<{ readonly words?: StateWords | undefined }>('CmsState', {\n text: (data, value) => {\n if (!isState(value)) return String(value)\n const words = { ...stateWords, ...data.words }\n const schedule = scheduleOf(value)\n return schedule === undefined\n ? words[value._tag]\n : fillWords(words.withSchedule, { state: words[value._tag], schedule: words[schedule] })\n },\n})\n\nconst units: ReadonlyArray<readonly [Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 31_536_000_000],\n ['month', 2_592_000_000],\n ['day', 86_400_000],\n ['hour', 3_600_000],\n ['minute', 60_000],\n]\n\n// One formatter per locale, kept: a list draws a Moment in every row, and\n// making an Intl formatter costs far more than formatting with one.\nconst absolutes = new Map<string, Intl.DateTimeFormat>()\nconst relatives = new Map<string, Intl.RelativeTimeFormat>()\nconst absoluteIn = (locale: string): Intl.DateTimeFormat => {\n const known = absolutes.get(locale)\n if (known !== undefined) return known\n const made = new Intl.DateTimeFormat(locale, {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: 'UTC',\n })\n absolutes.set(locale, made)\n return made\n}\nconst relativeIn = (locale: string): Intl.RelativeTimeFormat => {\n const known = relatives.get(locale)\n if (known !== undefined) return known\n const made = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n relatives.set(locale, made)\n return made\n}\n\n/**\n * A time. Given a clock it reads relative to it (\"3 days ago\"), and the view\n * decides how often that clock moves; given none it is the date and the time.\n */\nconst Moment = Display.kind<{\n readonly now?: (() => Date) | undefined\n readonly locale?: string | undefined\n}>('CmsMoment', {\n text: (data, value) => {\n const at = new Date(String(value))\n if (Number.isNaN(at.getTime())) return String(value)\n if (data.now === undefined) return absoluteIn(data.locale ?? 'en').format(at)\n const delta = at.getTime() - data.now().getTime()\n const relative = relativeIn(data.locale ?? 'en')\n const unit = units.find(([, size]) => Math.abs(delta) >= size)\n return unit === undefined\n ? relative.format(0, 'minute')\n : relative.format(Math.trunc(delta / unit[1]), unit[0])\n },\n})\n\n/** What `foldkit-mixins-crud` gives a display's renderer, as far as these read it. */\nexport interface DisplayContext<Message> {\n readonly display: {\n readonly kind: string\n readonly text: (value: unknown, words: DisplayWords) => string\n }\n readonly value: unknown\n readonly words: DisplayWords\n readonly h: HtmlBuilder<Message>\n readonly badge: { readonly attrs: (attrs: ReadonlyArray<any>) => any }\n}\n\nexport const Kinds = {\n /** The display kinds. */\n Display: { State: StateDisplay, Moment },\n\n /** For `ListView`'s and `DetailView`'s `renderers`: a state as a badge, a moment as a `time`. */\n displayRenderers: <Message>(): Readonly<\n Record<string, (context: DisplayContext<Message>) => Html>\n > => ({\n [StateDisplay.kind]: ({ display, value, words, h, badge }) =>\n h.span(\n badge.attrs(\n isState(value)\n ? [\n h.Attribute(stateAttribute, value._tag),\n ...(scheduleOf(value) === undefined\n ? []\n : [h.DataAttribute('cms-schedule', scheduleOf(value)!)]),\n ]\n : [],\n ),\n [display.text(value, words)],\n ),\n [Moment.kind]: ({ display, value, words, h }) =>\n h.time([h.Attribute('datetime', String(value))], [display.text(value, words)]),\n }),\n}\n","/**\n * The entry-level views every CMS studio draws: its state badge, its\n * published revisions, and what can still happen to it. An application passes\n * its own slot builders and keeps its slots and styles; the interfaces below\n * are the builders each view reads. Words for states come from\n * `Cms.Display`, so a studio and its lists say them one way.\n */\nimport { Match, Option } from 'effect'\nimport { Display } from 'foldkit-crud'\nimport type { SlotView } from 'foldkit-mixins'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { RemoteData } from 'foldkit-remote'\nimport { Kinds, stateAttribute } from './kinds.js'\nimport type { State, Transition } from './lifecycle.js'\n\n/** Whether the entry's state is one of `tags`; an entry with no state yet is none of them. */\nexport const stateIs = (state: Option.Option<State>, ...tags: ReadonlyArray<State['_tag']>) =>\n Option.exists(state, known => tags.includes(known._tag))\n\n/**\n * An entry's state as a badge: its tag is its color, its words the CMS's. The\n * tag is in `stateAttribute`, as a list's state cell writes it.\n */\nexport const stateBadge = <M>(\n badge: SlotView.SlotBuilder<M>,\n h: HtmlBuilder<M>,\n state: Option.Option<State>,\n): Html =>\n Option.match(state, {\n // Something new has no entry yet, so no state: it is new all the same.\n onNone: () => h.span(badge.attrs([h.Attribute(stateAttribute, 'New')]), ['New']),\n onSome: known =>\n h.span(badge.attrs([h.Attribute(stateAttribute, known._tag)]), [\n Display.show(Kinds.Display.State.of({}), known),\n ]),\n })\n\n/** A published revision, as an editor's History lists it. */\nexport interface RevisionRow {\n readonly n: number\n readonly publishedAt: string\n readonly publishedBy: string | null\n}\n\n/**\n * The open entry's published revisions, as they have been read. A posts'\n * history and a pages' revisions read through the same shape, so one helper\n * serves both: which read is the section's to name. A read that failed, or\n * that has no answer yet, is its own state rather than an empty list, so the\n * card cannot mistake either for nothing published.\n */\nexport type RevisionHistory =\n | { readonly _tag: 'Ready'; readonly revisions: ReadonlyArray<RevisionRow> }\n | { readonly _tag: 'Loading' }\n | { readonly _tag: 'Failed' }\n\nexport const revisionsOf = <M, Value extends { readonly revisions: ReadonlyArray<RevisionRow> }>(\n model: M,\n history: (model: M) => Option.Option<{ readonly read: (model: M) => RemoteData<Value> }>,\n): RevisionHistory =>\n Option.match(history(model), {\n // No history to read: there is nothing to wait for and nothing to fail.\n onNone: () => ({ _tag: 'Ready', revisions: [] }),\n onSome: projection => {\n const read = projection.read(model)\n switch (read._tag) {\n case 'Ready':\n case 'Refreshing':\n return { _tag: 'Ready', revisions: read.value.revisions } as const\n case 'Failed':\n return { _tag: 'Failed' } as const\n case 'NotFound':\n return { _tag: 'Ready', revisions: [] } as const\n case 'Initial':\n case 'Loading':\n return { _tag: 'Loading' } as const\n }\n },\n })\n\n/** A moment as the History says it: \"Sep 27, 2026\" and \"9:12 PM\", apart. */\nconst momentOf = (iso: string) => {\n const at = new Date(iso)\n return {\n day: at.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }),\n time: at.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' }),\n }\n}\n\n/** The builders `historyCard` reads. */\nexport interface HistoryCardSlots<M> {\n readonly card: SlotView.SlotBuilder<M>\n readonly cardTitle: SlotView.SlotBuilder<M>\n readonly muted: SlotView.SlotBuilder<M>\n readonly timeline: SlotView.SlotBuilder<M>\n readonly revision: SlotView.SlotBuilder<M>\n readonly revisionMark: SlotView.SlotBuilder<M>\n readonly revisionBody: SlotView.SlotBuilder<M>\n readonly revisionTitle: SlotView.SlotBuilder<M>\n readonly revisionLive: SlotView.SlotBuilder<M>\n readonly revisionMeta: SlotView.SlotBuilder<M>\n readonly revisionRestore: SlotView.SlotBuilder<M>\n}\n\n/**\n * What was published, newest first, as a timeline: each revision on a line\n * down to the first, with when and by whom. The newest is marked Live while\n * the entry is on the site; restoring it is offered only while a draft sits\n * over it, since otherwise it changes nothing. A history still being read\n * says so as a busy status, and one that failed as an alert, so neither is\n * mistaken for nothing published nor read as plain text. A failed read is not\n * retried on its own: given `onRetry`, a button sends it, drawn on the\n * restore slot so no new builder is required of every studio. Who published\n * is the application's to name (`authorName`), as only it knows its chairs.\n */\nexport const historyCard = <M>(\n slots: HistoryCardSlots<M>,\n h: HtmlBuilder<M>,\n history: RevisionHistory,\n entry: {\n readonly state: Option.Option<State>\n readonly restore: (revision: number) => M\n readonly authorName: (name: string) => string\n /**\n * Asks again after a failed read. Given, a failed history shows a button\n * that sends it; a failed read is not retried on its own.\n */\n readonly onRetry?: M | undefined\n /** What the retry button says. Default `Try again`. */\n readonly words?: { readonly retry?: string | undefined } | undefined\n },\n): Html => {\n const live = stateIs(entry.state, 'Published', 'Changed')\n const drafted = stateIs(entry.state, 'Changed')\n const body: ReadonlyArray<Html> = Match.value(history).pipe(\n Match.tagsExhaustive({\n Failed: () => [\n h.p(slots.muted.attrs([h.Role('alert')]), ['The history could not be read.']),\n ...(entry.onRetry === undefined\n ? []\n : [\n h.button(slots.revisionRestore.attrs([h.Type('button'), h.OnClick(entry.onRetry)]), [\n entry.words?.retry ?? 'Try again',\n ]),\n ]),\n ],\n Loading: () => [h.p(slots.muted.attrs([h.Role('status'), h.AriaBusy(true)]), ['Loading…'])],\n Ready: ({ revisions }) => [\n revisions.length === 0\n ? h.p(slots.muted.attrs(), ['Nothing has been published yet.'])\n : h.ol(\n slots.timeline.attrs([h.AriaLabel('Published revisions, newest first')]),\n revisions.map((revision, index) => {\n const newest = index === 0\n const { day, time } = momentOf(revision.publishedAt)\n const isLive = newest && live\n return h.li(slots.revision.attrs(isLive ? [h.DataAttribute('live', '')] : []), [\n h.span(slots.revisionMark.attrs([h.AriaHidden(true)]), []),\n h.div(slots.revisionBody.attrs(), [\n h.p(slots.revisionTitle.attrs(), [\n `Revision ${revision.n}`,\n ...(isLive ? [h.span(slots.revisionLive.attrs(), ['Live'])] : []),\n ]),\n h.p(slots.revisionMeta.attrs(), [\n h.time([h.Attribute('datetime', revision.publishedAt)], [`${day} · ${time}`]),\n ...(revision.publishedBy === null\n ? []\n : [` · ${entry.authorName(revision.publishedBy)}`]),\n ]),\n ]),\n ...(isLive && !drafted\n ? []\n : [\n h.button(\n slots.revisionRestore.attrs([\n h.OnClick(entry.restore(revision.n)),\n h.AriaLabel(`Restore revision ${revision.n}`),\n ]),\n ['Restore'],\n ),\n ]),\n ])\n }),\n ),\n ],\n }),\n )\n return h.section(slots.card.attrs([h.Id('history')]), [\n h.h2(slots.cardTitle.attrs(), ['History']),\n ...body,\n ])\n}\n\n/** The builders `moreCard` reads. */\nexport interface MoreCardSlots<M> {\n readonly card: SlotView.SlotBuilder<M>\n readonly cardTitle: SlotView.SlotBuilder<M>\n readonly toolbar: SlotView.SlotBuilder<M>\n readonly button: SlotView.SlotBuilder<M>\n readonly danger: SlotView.SlotBuilder<M>\n}\n\n/**\n * The rest of what can happen to an entry: its draft discarded, taken off the\n * site, put away or brought back. Discard and unpublish are each offered only\n * where the server would allow them; archive is always offered, with unarchive\n * taking its place once put away. None for something never saved, which has\n * nothing to discard or put away. The archive button's icon is the\n * application's, drawn its way.\n */\nexport const moreCard = <M>(\n slots: MoreCardSlots<M>,\n h: HtmlBuilder<M>,\n entry: {\n readonly state: Option.Option<State>\n readonly may: (transition: Transition) => boolean\n readonly asks: {\n readonly discard: M\n readonly unpublish: M\n readonly archive: M\n readonly unarchive: M\n }\n readonly archiveIcon: Html\n },\n): ReadonlyArray<Html> => {\n const { state, may, asks } = entry\n if (Option.isNone(state)) return []\n const action = (id: string, label: string, message: M): Html =>\n h.button(slots.button.attrs([h.Id(id), h.OnClick(message)]), [label])\n return [\n h.section(slots.card.attrs(), [\n h.h2(slots.cardTitle.attrs(), ['More']),\n h.div(slots.toolbar.attrs(), [\n ...(may('discard') && stateIs(state, 'Changed', 'New')\n ? [action('discard', 'Discard draft', asks.discard)]\n : []),\n ...(may('unpublish') && stateIs(state, 'Published', 'Changed')\n ? [action('unpublish', 'Unpublish', asks.unpublish)]\n : []),\n stateIs(state, 'Archived')\n ? action('unarchive', 'Unarchive', asks.unarchive)\n : h.button(slots.danger.attrs([h.Id('archive'), h.OnClick(asks.archive)]), [\n entry.archiveIcon,\n 'Archive',\n ]),\n ]),\n ]),\n ]\n}\n","import { Effect, Schema } from 'effect'\nimport { Query, Remote } from 'foldkit-remote'\nimport type { RemoteClient } from 'foldkit-remote'\n\n/**\n * A form check that says, while the author types, what a publish would refuse:\n * this address belongs to something else. It asks the content type's `bySlug`\n * query, which an author reads through the same binding as everyone else — so it\n * sees unpublished rows too, and an address taken by work not yet shown is taken.\n *\n * It is named by the content type, not given it, so a form can be made with it\n * before the content type that nests the form exists.\n *\n * Put it in the form's `checks` under the slug key:\n * `checks: { slug: Cms.addressFree('posts') }`. The form must know which row it\n * is editing for the row to keep its own address; `Cms.editor` tells it.\n *\n * This is advice, and deliberately not the rule. Two authors can both be told an\n * address is free and both publish; the server refuses the second on the same\n * key, through `Form.Message.Refused`. Asking earlier makes that rarer, never\n * impossible.\n */\nexport const addressFree = (\n content: string,\n): ((\n slug: string,\n context: { readonly subject: Readonly<Record<string, string>> },\n) => Effect.Effect<string | undefined, never, RemoteClient>) => {\n // The same query the server registered for this content type: a descriptor is\n // its name and its input, so one made here asks what one made there answers.\n const descriptor = Query.make(`${content}BySlug`, {\n Input: { slug: Schema.String },\n Result: Schema.Unknown,\n })\n return (\n slug: string,\n context: { readonly subject: Readonly<Record<string, string>> },\n ): Effect.Effect<string | undefined, never, RemoteClient> =>\n Remote.query(descriptor.ref({ slug })).pipe(\n // An edge is an id, which is all this asks about.\n Effect.map(result =>\n result.edges.some(edge => edge.id !== context.subject.id)\n ? `\"${slug}\" is already used`\n : undefined,\n ),\n // A check that could not ask says nothing: the publish is still the rule,\n // and an address is not refused because the network was down.\n Effect.orElseSucceed(() => undefined),\n )\n}\n","/**\n * `foldkit-cms` — what a CMS adds to a domain that is already declared: audience\n * (who may see it), time (drafts, revisions, a schedule), and address (a slug).\n *\n * A draft is an unsent form, kept beside the content row and never in it. The\n * row holds what is published; publishing is the application's own mutation,\n * run with the draft's value. This package is the declarations and the pure\n * rules. It reads no database and owns no state; `foldkit-cms-drizzle` is the\n * server, and lists and forms draw through `foldkit-crud`'s views.\n */\nimport { Schema } from 'effect'\nimport {\n Collation,\n Entity,\n Relation,\n Derived,\n type AnyEntity,\n type EntityField,\n type EntityInput,\n type Reads,\n type TestPredicate,\n Expr,\n Order,\n SchemaShape,\n} from 'foldkit-entity'\nimport { Metadata } from 'foldkit-metadata'\nimport {\n Mutation,\n Query,\n Refusal,\n type MutationDescriptor,\n type OptimisticOperation,\n} from 'foldkit-remote'\nimport { Transitions, offers, state, type Facts, type State, type Transition } from './lifecycle.js'\nimport { editorView, makeEditor } from './editor.js'\nimport { historyCard, moreCard, revisionsOf, stateBadge, stateIs } from './views.js'\nimport { addressFree } from './slug.js'\nimport { Display } from 'foldkit-crud'\nimport { Kinds, stateAttribute } from './kinds.js'\n\nexport type { Facts, Schedule, State, StateTag, Transition } from './lifecycle.js'\n\n/** The members of an Entity that play a part a CMS knows: by key. */\nexport interface RoleKeys<E extends AnyEntity> {\n /** What an entry is called in a list. A text field. */\n readonly label?: TextKey<E>\n /** The address a visitor reaches it by. A text field, unique in its table. */\n readonly slug?: TextKey<E>\n /**\n * Present means a visitor may see the row. A field that admits `null`. Without\n * it a content type cannot be unpublished, and every row is visible.\n */\n readonly published?: NullableKey<E>\n}\n\ntype TextKey<E extends AnyEntity> = {\n [K in keyof E['fields']]: [E['fields'][K]['schema']['Type']] extends [string] ? K : never\n}[keyof E['fields']] &\n string\n\ntype NullableKey<E extends AnyEntity> = {\n [K in keyof E['fields']]: null extends E['fields'][K]['schema']['Type'] ? K : never\n}[keyof E['fields']] &\n string\n\n/** The roles of an Entity, as its Fields. */\nexport interface Roles {\n readonly label: EntityField<string, string, Schema.Constraint> | undefined\n readonly slug: EntityField<string, string, Schema.Constraint> | undefined\n readonly published: EntityField<string, string, Schema.Constraint> | undefined\n}\n\nconst rolesKey = Metadata.key<Readonly<Record<string, string>>>('foldkit-cms/roles', {\n // Later roles add to earlier ones, and win where they name the same part.\n merge: roles => [Object.assign({}, ...roles) as Readonly<Record<string, string>>],\n summarize: roles => Object.keys(roles).join(','),\n})\n\nconst fail = (message: string): never => {\n throw new Error(`foldkit-cms: ${message}`)\n}\n\n/** An entry's id. Branded, so an entry is not opened with a post's id. */\nexport const EntryId = Schema.String.pipe(Schema.brand('CmsEntryId'))\nexport type EntryId = typeof EntryId.Type\n\nconst StateSchema = Schema.Struct({\n _tag: Schema.Literals(['New', 'Published', 'Changed', 'Unpublished', 'Archived']),\n schedule: Schema.NullOr(\n Schema.Struct({\n at: Schema.String,\n overdue: Schema.Boolean,\n error: Schema.NullOr(Schema.String),\n }),\n ),\n}).annotate({ title: 'State' })\n\n// A piece of content from its first keystroke to its archive: the thing an author\n// works on. It exists before the content row does, and after the row is hidden.\nconst Entry = Entity.define(\n 'CmsEntry',\n Schema.Struct({\n id: EntryId,\n /** The content type's name: `Cms.content('posts', ...)`. */\n type: Schema.String,\n /** The content row's id, once there is one. */\n targetId: Schema.NullOr(Schema.String),\n label: Schema.String.annotate({ title: 'Title' }),\n createdAt: Schema.String,\n archivedAt: Schema.NullOr(Schema.String),\n /** The number of the latest published revision: what the next publish is based on. */\n revision: Schema.NullOr(Schema.Number),\n }),\n).pipe(\n // Derived by the server, with its clock, so a list can show and filter by it;\n // `may` is what the principal reading it may do now, by the server's `allow`.\n Entity.derived({\n state: Derived.make(StateSchema),\n may: Derived.make(Schema.Array(Transitions)),\n }),\n // How a list or a detail shows them, with nothing said where it is declared.\n Entity.annotateMembers({\n // An entry's id is how it is opened, not something to read in a list.\n id: Display.of(Display.hidden()),\n state: Display.of(Kinds.Display.State.of({})),\n // An ISO-8601 instant, so code-point order is time order: said, so a\n // client places a created or renamed entry in a list as the server does.\n createdAt: Metadata.combine([\n Display.of(Kinds.Display.Moment.of({})),\n Collation.of(Collation.binary),\n ]),\n archivedAt: Display.of(Kinds.Display.Moment.of({})),\n }),\n)\n\n// The entry's one working copy: what an author has entered and not published.\nconst Draft = Entity.define(\n 'CmsDraft',\n Schema.Struct({\n /** The entry's id: an entry has at most one draft. */\n id: EntryId,\n /** The keys of the form's value that decode, as the operation's input encodes them. */\n values: Schema.Unknown,\n /** The form's whole Model, encoded: what resumes unfinished work. */\n model: Schema.Unknown,\n /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */\n form: Schema.String,\n updatedAt: Schema.String,\n updatedBy: Schema.NullOr(Schema.String),\n /** The revision this draft was started from; publishing over a newer one is a conflict. */\n baseRevision: Schema.NullOr(Schema.Number),\n scheduledFor: Schema.NullOr(Schema.String),\n scheduleError: Schema.NullOr(Schema.String),\n }),\n)\n\n// A published value, kept. Append-only.\nconst Revision = Entity.define(\n 'CmsRevision',\n Schema.Struct({\n id: Schema.String,\n n: Schema.Number.annotate({ title: 'Revision' }),\n values: Schema.Unknown,\n publishedAt: Schema.String.annotate({ title: 'Published' }),\n publishedBy: Schema.NullOr(Schema.String),\n }),\n).pipe(Entity.annotateMembers({ publishedAt: Display.of(Kinds.Display.Moment.of({})) }))\n\nconst Entities = Entity.relate(\n { Entry, Draft, Revision },\n {\n Entry: {\n draft: Relation.one(Draft, { optional: true }),\n revisions: Relation.many(Revision),\n },\n },\n)\n\nconst entryInput = { entry: EntryId }\n\n/**\n * What an author may ask, as Remote mutations. They are the same for every\n * content type; the entry says which type it is. The server runs each after\n * asking the application's `allow`.\n */\n/**\n * Why a save or a publish is refused, as data: one key of the content's form\n * (a taken address, named by the content type's slug key, so the key is any\n * string here), or a conflict with work saved or published since.\n */\nconst RefusedField = Schema.TaggedStruct('Field', { key: Schema.String, reason: Schema.String })\nconst Refused = Schema.Union([RefusedField, Refusal.conflict])\n\n/** The values a server refuses a save or a publish with, for `RemoteServer.refuse`. */\nconst refusal = {\n /** One key of the content's form, and why, as text a form shows beside it. */\n field: (key: string, reason: string) => RefusedField.make({ key, reason }),\n conflict: Refusal.conflict.make({}),\n}\n\nconst Operations = {\n /**\n * Saves the working copy, valid or not. The first save of an id nobody has\n * makes the entry, so a client names something new itself (`Cms.newEntryId`) and\n * need not wait to be told what it is called. `basedOn` is the `updatedAt` this\n * save was made from: a newer one on the server is a conflict, not an overwrite.\n */\n SaveDraft: Mutation.make('CmsSaveDraft', {\n Input: {\n entry: EntryId,\n type: Schema.String,\n label: Schema.String,\n values: Schema.Unknown,\n model: Schema.Unknown,\n form: Schema.String,\n basedOn: Schema.NullOr(Schema.String),\n },\n Output: { entry: EntryId, updatedAt: Schema.String },\n Refusal: Refused,\n }),\n DiscardDraft: Mutation.make('CmsDiscardDraft', { Input: entryInput, Output: {} }),\n /**\n * Publishes the saved draft through the content type's own mutation. `basedOn`\n * is the revision the draft was started from.\n */\n Publish: Mutation.make('CmsPublish', {\n Input: { entry: EntryId, basedOn: Schema.NullOr(Schema.Number) },\n Output: { entry: EntryId, targetId: Schema.String, revision: Schema.Number },\n Refusal: Refused,\n }),\n Unpublish: Mutation.make('CmsUnpublish', { Input: entryInput, Output: {} }),\n Schedule: Mutation.make('CmsSchedule', {\n Input: { entry: EntryId, at: Schema.String },\n Output: {},\n }),\n Unschedule: Mutation.make('CmsUnschedule', { Input: entryInput, Output: {} }),\n Archive: Mutation.make('CmsArchive', { Input: entryInput, Output: {} }),\n Unarchive: Mutation.make('CmsUnarchive', { Input: entryInput, Output: {} }),\n /** Makes a revision's value the working copy. It publishes nothing. */\n Restore: Mutation.make('CmsRestore', {\n Input: { entry: EntryId, revision: Schema.Number },\n Output: { updatedAt: Schema.String },\n }),\n}\n\n/**\n * What an author works on: the entries of one content type, searched by what\n * they are called. `archived` chooses the put-away ones or the rest. It lists\n * entries, not content rows, so something never published is here too.\n */\n/**\n * The worklist: a content type's entries, archived or not, narrowed by a\n * search. Declared by what it means, so the server compiles it rather than\n * being told the same three questions again in SQL.\n *\n * Both of the conditions an author changes are asked without a branch, because\n * a body is built once and its inputs are placeholders. \"Archived or not\" is\n * *is-archived equals what you asked for*; \"search or everything\" is *the label\n * contains what you asked for*, and containing the empty string is everything.\n * `label` is not nullable, which is what makes the second of those exactly no\n * filter when the box is empty.\n */\nconst Entries = Query.define(\n 'CmsEntries',\n { type: Schema.String, search: Schema.String, archived: Schema.Boolean },\n ({ input }) =>\n Query.from(Entities.Entry).pipe(\n Query.where(\n Expr.eq(Entities.Entry.fields.type, input.type),\n Expr.eq(Expr.isNotNull(Entities.Entry.fields.archivedAt), input.archived),\n Expr.contains(Entities.Entry.fields.label, input.search),\n ),\n Query.orderBy(Order.desc(Entities.Entry.fields.createdAt)),\n ),\n)\n\n/** A form as a content type needs it: what it was made from, and what it edits. */\ninterface ContentForm<E extends AnyEntity, Value> {\n readonly name: string\n readonly input: EntityInput<E, any, any>\n readonly bundle: { readonly Model: Schema.Codec<any, unknown> }\n readonly initial: unknown\n readonly engine: { readonly value: (model: any) => Value | undefined }\n}\n\n/** How a type of content is authored: the application's facts, beside the Entity's roles. */\nexport interface Content<\n Name extends string,\n E extends AnyEntity,\n Value,\n TargetId extends string,\n F extends ContentForm<E, Value> = ContentForm<E, Value>,\n> {\n readonly name: Name\n readonly entity: E\n /** The form as it was given, so an editor of this content is typed by it. */\n readonly form: F\n readonly publish: {\n /** Makes the row, the first time. Its input is the form's value; its output names the row. */\n readonly create: MutationDescriptor<string, Value, { readonly id: TargetId }>\n /** Changes the row, every time after. Its input is the form's value and the row's id. */\n readonly update: MutationDescriptor<string, Value & { readonly id: TargetId }, any>\n }\n readonly roles: Roles\n readonly words: { readonly one: string; readonly many: string }\n /**\n * How a value of the form would look in the store: the operations an optimistic\n * publish of it would show. Declared, an author can preview what they have\n * entered in the application's own views; not declared, there is no preview.\n * `id` is the row's, or the entry's while there is no row yet.\n */\n readonly preview?:\n | ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>)\n | undefined\n}\n\nconst editor = makeEditor({ Entities, Operations })\n\n/**\n * Whether a row is published: its published role holds a value. One operator,\n * so a query, a guard and an invariant that ask it name the same question.\n */\nconst publishedOperator = Expr.operator('cms.published', {\n input: [Schema.Unknown],\n output: Schema.Boolean,\n description: 'Whether a row is published: its published role holds a value.',\n definedAs: publishedAt => Expr.isNotNull(publishedAt),\n})\n\nexport const Cms = {\n /**\n * A pipe step naming the members of an Entity that play a CMS part. It is\n * metadata: the Entity is the same Entity, and anything may read it with\n * `Cms.rolesOf`. A member that cannot play the part is refused here.\n */\n roles:\n <E extends AnyEntity>(roles: RoleKeys<NoInfer<E>>) =>\n (entity: E): E => {\n const given = roles as Readonly<Record<string, string | undefined>>\n const fields: Readonly<Record<string, EntityField<string, string, Schema.Constraint>>> =\n entity.fields\n for (const [role, key] of Object.entries(given)) {\n if (key === undefined) continue\n const field =\n fields[key] ??\n fail(`\"${key}\" is not a field of ${entity.name}, so it cannot be its ${role}`)\n const type = Schema.toType(field.schema as Schema.Top)\n if (role === 'published') {\n if (!Schema.is(type as Schema.Codec<unknown>)(null))\n fail(`\"${key}\" of ${entity.name} admits no null, so it cannot say a row is unpublished`)\n } else if (!SchemaShape.isText(type.ast)) {\n fail(`\"${key}\" of ${entity.name} is not text, so it cannot be its ${role}`)\n }\n }\n const named = Object.fromEntries(\n Object.entries(given).filter((entry): entry is [string, string] => entry[1] !== undefined),\n )\n return entity.pipe(Entity.annotate(rolesKey.of(named))) as E\n },\n\n /** The roles an Entity was given, as its Fields. A part nobody named is `undefined`. */\n rolesOf: (entity: AnyEntity): Roles => {\n const [named = {}] = rolesKey.get(entity.metadata)\n const fields: Readonly<Record<string, EntityField<string, string, Schema.Constraint>>> =\n entity.fields\n const field = (role: string) => (named[role] === undefined ? undefined : fields[named[role]])\n return { label: field('label'), slug: field('slug'), published: field('published') }\n },\n\n /**\n * Whether a row of `entity` is published: `cms.published` over the field its\n * `published` role names. Present means a visitor may see the row, so this is\n * the predicate a public query and a visitor's Read rule both ask. An Entity\n * with no published role is refused: every row of it is visible already.\n *\n * ```ts\n * Query.from(Post).pipe(Query.where(Cms.published(Post)))\n * guard.row(Post, () => Cms.published(Post))\n * ```\n */\n published: <E extends AnyEntity>(entity: E): TestPredicate & Reads<E['name']> => {\n const field = Cms.rolesOf(entity).published\n if (field === undefined) {\n throw new Error(\n `[foldkit-cms] Cms.published: ${entity.name} names no published role, so every row is visible`,\n )\n }\n return publishedOperator(field) as TestPredicate & Reads<E['name']>\n },\n\n /**\n * A type of content: the Entity it is, the form that edits it, the operations\n * that publish it, and what it is called. The form is an ordinary form; the\n * operations are the application's own. It adds no fields and generates nothing.\n */\n content: <\n const Name extends string,\n E extends AnyEntity,\n Value,\n TargetId extends string = string,\n F extends ContentForm<NoInfer<E>, Value> = ContentForm<NoInfer<E>, Value>,\n >(\n name: Name,\n config: {\n readonly entity: E\n readonly form: F & ContentForm<NoInfer<E>, Value>\n readonly publish: Content<Name, E, NoInfer<Value>, TargetId>['publish']\n readonly words: { readonly one: string; readonly many: string }\n readonly preview?: Content<Name, E, NoInfer<Value>, TargetId>['preview']\n },\n ): Content<Name, E, Value, TargetId, F> => {\n if (!Entity.same(config.form.input.entity, config.entity))\n fail(\n `content \"${name}\" is of ${config.entity.name}, but its form edits ${config.form.input.entity.name}`,\n )\n return Object.freeze({ name, ...config, roles: Cms.rolesOf(config.entity) })\n },\n\n /** An id for something new, made where it is written: the first save of it makes the entry. */\n newEntryId: (): EntryId => globalThis.crypto.randomUUID() as EntryId,\n /** `Entry`, `Draft` and `Revision`: register them with Remote beside the application's own. */\n Entities,\n /** The operations, to register with Remote's `mutations`. */\n Operations,\n operations: Object.values(Operations),\n /**\n * What a server refuses `SaveDraft` and `Publish` with: `refusal.field(key,\n * reason)` for one key of the content's form, `refusal.conflict` for work\n * saved or published since. An editor reads them with `Data.refusal`.\n */\n refusal,\n /** The worklist query, to register with Remote's `queries` and list with `Crud.list`. */\n Entries,\n /**\n * The query that finds a piece of content by its address: `<name>BySlug`, a\n * connection of one or none. It throws for a content type with no `slug` role:\n * a capability is declared, never implied.\n */\n bySlug: <Name extends string, E extends AnyEntity>(content: Content<Name, E, any, any, any>) => {\n const address = content.roles.slug\n if (address === undefined) {\n return fail(`content \"${content.name}\" has no slug role, so nothing is found by slug`)\n }\n const entity = content.entity as AnyEntity\n // Declared by what it means, so a server compiles the body instead of being\n // told the same `where` again in its own dialect. Ordered by id: one row is\n // expected, and a connection still pages on something stable.\n return Query.define(\n `${content.name}BySlug` as `${Name}BySlug`,\n { slug: Schema.String },\n ({ input }) =>\n Query.from(entity).pipe(\n Query.where(Expr.eq(address, input.slug)),\n Query.orderBy(Order.asc(entity.fields.id!)),\n ),\n ) as ReturnType<typeof Query.make<`${Name}BySlug`, { slug: typeof Schema.String }, E>>\n },\n /**\n * A form check that asks, while the author types, whether an address is already\n * used: `checks: { slug: Cms.addressFree('posts') }`. Named by the content type,\n * so a form can be made with it before the content type exists. It needs that\n * type's `bySlug` query registered, which `CmsServer` does for a content type\n * with a slug role.\n */\n addressFree,\n\n /**\n * The displays a CMS adds, and a renderer for each: `Cms.Display.State` and\n * `Cms.Display.Moment` for a list's columns, `Cms.displayRenderers()` to spread\n * beside the mixins' own. A slug and a moment are `foldkit-form-recipes`'\n * `FieldRecipes.slug` and `FieldRecipes.dateTime`.\n */\n ...Kinds,\n\n /**\n * The authoring editor of a content type: its form, the entry, and the draft\n * that keeps what the author has entered. Saving is automatic and is not\n * publishing; publishing submits the form.\n */\n editor,\n /** A form's Submodel view as its editor's, for `Bundle.withView`. */\n editorView,\n\n /**\n * The entry-level views every studio draws, on its own slot builders: its\n * state badge, its published revisions, what was published, and the rest of\n * what can happen to it. Words for states come from `Cms.Display`, so a\n * studio and its lists say them one way.\n */\n stateBadge,\n /**\n * The attribute every state the CMS draws is written in, `data-cms-state`:\n * a badge's tone rules select on it, `[${Cms.stateAttribute}=\"Published\"]`.\n */\n stateAttribute,\n /** Whether the entry's state is one of the given tags; no state yet is none of them. */\n stateIs,\n revisionsOf,\n historyCard,\n moreCard,\n\n /** The state of an entry, from what is known of it and a clock. */\n state: (facts: Facts, now: Date): State => state(facts, now),\n /** Every transition an author may ask, in order: what `allow` is asked about. */\n transitions: Transitions.literals,\n /** The transitions an entry offers now, before anyone asks who is asking. */\n offers: (\n facts: Facts,\n now: Date,\n content: { readonly roles: Roles },\n ): ReadonlyArray<Transition> =>\n offers(facts, now, { unpublishes: content.roles.published !== undefined }),\n}\n\nexport type {\n EditorContent,\n EditorMessage,\n EditorDomain,\n EditorForm,\n EditorModel,\n EditorOut,\n EditorStatus,\n Resumed,\n} from './editor.js'\nexport type { DisplayContext, StateWords } from './kinds.js'\nexport type { HistoryCardSlots, MoreCardSlots, RevisionHistory, RevisionRow } from './views.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,cAAc,OAAO,SAAS;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAMA,gBAAc,OAAuB,QACzC,UAAU,QAAQ,MAAM,iBAAiB,OACrC,OACA;CACE,IAAI,MAAM;CACV,SAAS,IAAI,KAAK,MAAM,YAAY,CAAC,CAAC,QAAQ,KAAK,IAAI,QAAQ;CAC/D,OAAO,MAAM;AACf;AAEN,MAAa,SAAS,OAAc,QAAqB;CACvD,IAAI,MAAM,eAAe,MAAM,OAAO;EAAE,MAAM;EAAY,UAAU;CAAK;CACzE,MAAM,WAAWA,aAAW,MAAM,OAAO,GAAG;CAC5C,IAAI,MAAM,QAAQ,UAAU,OAAO;EAAE,MAAM;EAAe;CAAS;CACnE,IAAI,MAAM,QAAQ,QAAQ,OAAO;EAAE,MAAM;EAAO;CAAS;CACzD,OAAO,MAAM,UAAU,OACnB;EAAE,MAAM;EAAa,UAAU;CAAK,IACpC;EAAE,MAAM;EAAW;CAAS;AAClC;;;;;;;AAQA,MAAa,UACX,OACA,KACA,iBAC8B;CAC9B,MAAM,UAAU,MAAM,OAAO,GAAG;CAChC,IAAI,QAAQ,SAAS,YAAY,O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AO,KAAK,MAAM,OAAO,MAChG;EACF,OAAO,OAAO,OAAO;GAAE;GAAM,GAAG;GAAQ,OAAO,IAAI,QAAQ,OAAO,MAAM;EAAE,CAAC;CAC7E;;CAGA,kBAA2B,WAAW,OAAO,WAAW;;CAExD;;CAEA;CACA,YAAY,OAAO,OAAO,UAAU;;;;;;CAMpC;;CAEA;;;;;;CAMA,SAAmD,YAA6C;EAC9F,MAAM,UAAU,QAAQ,MAAM;EAC9B,IAAI,YAAY,KAAA,GACd,OAAO,KAAK,YAAY,QAAQ,KAAK,gDAAgD;EAEvF,MAAM,SAAS,QAAQ;EAIvB,OAAO,MAAM,OACX,GAAG,QAAQ,KAAK,SAChB,EAAE,MAAM,OAAO,OAAO,IACrB,EAAE,YACD,MAAM,KAAK,MAAM,CAAC,CAAC,KACjB,MAAM,MAAM,KAAK,GAAG,SAAS,MAAM,IAAI,CAAC,GACxC,MAAM,QAAQ,MAAM,IAAI,OAAO,OAAO,EAAG,CAAC,CAC5C,CACJ;CACF;;;;;;;;CAQA;;;;;;;CAQA,GAAG;;;;;;CAOH;;CAEA;;;;;;;CAQA;;;;;CAKA;;CAEA;CACA;CACA;CACA;;CAGA,QAAQ,OAAc,QAAqB,MAAM,OAAO,GAAG;;CAE3D,aAAa,YAAY;;CAEzB,SACE,OACA,KACA,YAEA,OAAO,OAAO,KAAK,EAAE,aAAa,QAAQ,MAAM,cAAc,KAAA,EAAU,CAAC;AAC7E"}
1
+ {"version":3,"file":"index.mjs","names":["scheduleOf"],"sources":["../src/lifecycle.ts","../src/editor.ts","../src/kinds.ts","../src/views.ts","../src/slug.ts","../src/index.ts"],"sourcesContent":["/**\n * The lifecycle of a piece of content, derived. Nothing stores a status: a state\n * is a pure function of facts (is there a row, can a visitor see it, is there a\n * draft, has the entry been archived) and a clock, so it cannot disagree with\n * them. A scheduled publish that failed reads scheduled and overdue, which is\n * true, and not published, which would not be.\n */\nimport { Schema } from 'effect'\n\n/** What is known of one entry. The server gathers it; nothing here reads a database. */\nexport interface Facts {\n /** When the entry was archived, if it was. */\n readonly archivedAt: string | null\n /** The content row: none yet, one a visitor can see, or one hidden by its `published` role. */\n readonly row: 'none' | 'visible' | 'hidden'\n /** The entry's working copy, if it has one. */\n readonly draft: {\n readonly scheduledFor: string | null\n readonly scheduleError: string | null\n } | null\n}\n\n/** A draft that is to be published at a time, and how that stands. */\nexport interface Schedule {\n readonly at: string\n /** The time has come and the draft is still a draft: the publish has not run, or failed. */\n readonly overdue: boolean\n /** Why the last attempt failed, for the author to fix. */\n readonly error: string | null\n}\n\nexport type StateTag = 'New' | 'Published' | 'Changed' | 'Unpublished' | 'Archived'\n\n/**\n * - `New`: nothing published yet.\n * - `Published`: what a visitor sees is all there is.\n * - `Changed`: published, with unpublished work beside it.\n * - `Unpublished`: a row a visitor cannot see.\n * - `Archived`: put away; nothing else applies until it is restored.\n *\n * `schedule` rides beside `New` and `Changed`, the states that have a draft to publish.\n */\nexport interface State {\n readonly _tag: StateTag\n readonly schedule: Schedule | null\n}\n\n/** What an author may ask of an entry. Each is an operation the server runs after asking `allow`. */\nexport const Transitions = Schema.Literals([\n 'save',\n 'discard',\n 'publish',\n 'schedule',\n 'unschedule',\n 'unpublish',\n 'archive',\n 'unarchive',\n 'restore',\n])\nexport type Transition = typeof Transitions.Type\n\nconst scheduleOf = (draft: Facts['draft'], now: Date): Schedule | null =>\n draft === null || draft.scheduledFor === null\n ? null\n : {\n at: draft.scheduledFor,\n overdue: new Date(draft.scheduledFor).getTime() <= now.getTime(),\n error: draft.scheduleError,\n }\n\nexport const state = (facts: Facts, now: Date): State => {\n if (facts.archivedAt !== null) return { _tag: 'Archived', schedule: null }\n const schedule = scheduleOf(facts.draft, now)\n if (facts.row === 'hidden') return { _tag: 'Unpublished', schedule }\n if (facts.row === 'none') return { _tag: 'New', schedule }\n return facts.draft === null\n ? { _tag: 'Published', schedule: null }\n : { _tag: 'Changed', schedule }\n}\n\n/**\n * The transitions a state offers, before anyone asks who is asking. `facts` says\n * whether there is a draft, which a state alone does not: an unpublished entry\n * may or may not have one. `unpublishes` is whether the content type declared a\n * `published` role: without one a row cannot be hidden, so it is not offered.\n */\nexport const offers = (\n facts: Facts,\n now: Date,\n capabilities: { readonly unpublishes: boolean },\n): ReadonlyArray<Transition> => {\n const current = state(facts, now)\n if (current._tag === 'Archived') return ['unarchive']\n const drafted = facts.draft !== null\n return [\n 'save',\n ...(drafted ? (['discard', 'publish'] as const) : []),\n ...(drafted && current.schedule === null ? (['schedule'] as const) : []),\n ...(current.schedule !== null ? (['unschedule'] as const) : []),\n ...(facts.row === 'visible' && capabilities.unpublishes ? (['unpublish'] as const) : []),\n ...(facts.row !== 'none' ? (['restore'] as const) : []),\n 'archive',\n ]\n}\n","/**\n * The authoring editor: a form, the entry it belongs to, and the draft that\n * keeps what the author has entered.\n *\n * Saving is automatic and is not publishing. Each edit starts a rest, and the\n * edit that is still the last one when its rest ends saves the form as it\n * stands, valid or not. Publishing submits the form, so its rules and checks\n * decide; what is published is the saved draft, so a publish saves first.\n *\n * The Bundle holds what is the editor's own: the form's Model and how far the\n * saves have got. What the server holds is read from Remote, never copied: the\n * draft's `updatedAt` a save is based on, and the entry's `revision` a publish is.\n */\nimport { Duration, Effect, Match, Option, Predicate, Schema } from 'effect'\nimport { Bundle } from 'foldkit-bundle'\nimport { Entity, type AnyEntity } from 'foldkit-entity'\nimport type { Submitted } from 'foldkit-form'\nimport {\n Refusal,\n RemoteData,\n type MutationStatus,\n type OptimisticOperation,\n type RemoteClient,\n type RemoteError,\n type RemoteMessage,\n} from 'foldkit-remote'\nimport { lift, overlay, type OverlaidDomain } from 'foldkit-remote/overlay'\nimport { ModelRef, type ActiveSurface, type Projection } from 'foldkit-surface'\nimport type { Command } from 'foldkit/command'\nimport type * as FieldValidation from 'foldkit/fieldValidation'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport { defineMessageUnion } from 'foldkit/message'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport * as Subscription from 'foldkit/subscription'\nimport * as Submodel from 'foldkit/submodel'\nimport type * as Update from 'foldkit/update'\nimport type { State, Transition } from './lifecycle.js'\n\n/** How the form came to hold what it holds. */\nexport type Resumed =\n /** The draft's saved Model: the form exactly as it was left, errors and all. */\n | 'Model'\n /** The draft's values, key by key, keeping what the form still accepts. */\n | 'Values'\n /** What is published: there was no draft. */\n | 'Published'\n /** There was a draft and nothing of it fits the form any more; what is published is shown. */\n | 'Lost'\n /** Something new. */\n | 'Blank'\n\nexport type EditorStatus =\n | 'Closed'\n | 'Loading'\n | 'NotFound'\n | 'LoadFailed'\n /** Open, with nothing entered since it was opened and nothing pending. */\n | 'Opened'\n /** Edited since the last save. */\n | 'Editing'\n | 'Saving'\n | 'Saved'\n /** Someone else saved or published in between. The author's text is still in the form. */\n | 'Conflict'\n | 'SaveFailed'\n | 'Publishing'\n | 'Published'\n | 'PublishFailed'\n /**\n * A publish or a schedule the form's own checks stopped before anything was\n * sent: the fields that fail say why. Until the next edit.\n */\n | 'Incomplete'\n | 'Scheduling'\n /** Promised for later. The entry's `state` says for when, and whether it happened. */\n | 'Scheduled'\n | 'ScheduleFailed'\n\n/**\n * An editor's slice of the parent Model. `edits` counts the edits made, and\n * `savedEdit` is the count the last save was started at: the form is saved when\n * they agree.\n */\nexport interface EditorModel<FormModel> {\n readonly form: FormModel\n readonly mode: 'closed' | 'new' | 'edit'\n readonly entry: string | null\n readonly filled: boolean\n readonly resumed: Resumed | null\n readonly edits: number\n readonly savedEdit: number\n readonly saveId: string | null\n readonly saveWanted: boolean\n readonly publishId: string | null\n readonly publishWanted: boolean\n /**\n * The last publish or schedule asked, as the form took it: waiting for a\n * check still running, or stopped by one and not edited since; else idle.\n */\n readonly submit: 'idle' | 'waiting' | 'stopped'\n /** When the publish that is wanted, under way or last settled is a promise for later: for when. */\n readonly scheduleAt: string | null\n /** The discard or unpublish in progress or last settled. */\n readonly otherId: string | null\n /** Whether what is in the form is laid over the store, for the application's own views to draw. */\n readonly previewing: boolean\n /** What the overlay was last made of: the edit, and the row it is shown on. */\n readonly previewedAs: string | null\n /** After a conflict: waiting for the server's copy, to show it or to save over it. */\n readonly settling: 'reload' | 'overwrite' | null\n}\n\n/** What the editor asks of where it is placed; `onOut` answers each. */\nexport type EditorOut =\n | { readonly _tag: 'Save' }\n | { readonly _tag: 'Publish' }\n | { readonly _tag: 'Discard' }\n | { readonly _tag: 'Restore'; readonly revision: number }\n | { readonly _tag: 'Unpublish' }\n | { readonly _tag: 'Unschedule' }\n | { readonly _tag: 'Archive' }\n | { readonly _tag: 'Unarchive' }\n | { readonly _tag: 'Reload' }\n | { readonly _tag: 'Overwrite' }\n\n/** The parts of a `Form.make` result the editor drives. */\n/** `Services` is what the form's Commands and Subscriptions require, which the editor's then do. */\nexport interface EditorForm<FormModel, FormMessage, Value, Resources = {}, Services = never> {\n readonly name: string\n readonly input: { readonly schema: Schema.Struct<any> }\n readonly bundle: {\n readonly Model: Schema.Codec<FormModel, unknown>\n readonly Message: Schema.Codec<FormMessage, unknown>\n readonly update: (\n model: FormModel,\n message: FormMessage,\n args: void,\n ) => Update.ReturnWithOutMessage<FormModel, FormMessage, Submitted<Value>, Services>\n /** The Subscriptions of the form's controls backed by a Bundle, which the editor runs while open. */\n readonly subscriptions?: (\n args: void,\n ) => Subscription.Subscriptions<FormModel, FormMessage, Services>\n /** Their Resources, which the editor holds while open. */\n readonly resources?: (args: void) => Resources\n }\n readonly Message: {\n readonly Submitted: () => FormMessage\n readonly Refused: (payload: {\n readonly key: never\n readonly error: string\n readonly value: unknown\n }) => FormMessage\n readonly About: (payload: { readonly subject: Readonly<Record<string, string>> }) => FormMessage\n }\n readonly initial: FormModel\n readonly fill: (model: FormModel, values: Partial<Value>) => { readonly model: FormModel }\n readonly partial: (model: FormModel) => Partial<Value>\n readonly settled: (model: FormModel) => FormModel\n /** What the form is editing; `{}` while it creates. See `Form.FormModel.subject`. */\n readonly subject: (model: FormModel) => Readonly<Record<string, string>>\n /**\n * Whether a completed transition changed authored content (§45). The editor\n * asks this instead of recognizing the form's Message tags, so a control it\n * does not know about — a Bundle-backed one, a stateful one — autosaves the\n * same way a text field does, and a blur or a refused edit does not.\n */\n authoredChanged(before: FormModel, after: FormModel): boolean\n /** Whether a check is still running, which a submit waits for. */\n readonly engine: { readonly isValidating: (model: FormModel) => boolean }\n readonly field: (model: FormModel, key: never) => FieldValidation.Field<unknown>\n}\n\n/** The parts of a bound Remote domain the editor uses. */\nexport interface EditorDomain<Root> extends OverlaidDomain<Root> {\n // Method syntax: the descriptors are checked where the domain is made, not here.\n mutate(\n model: Root,\n mutation: any,\n input: any,\n ): {\n readonly model: Root\n readonly requestId: string\n readonly command: Command<RemoteMessage, never, RemoteClient>\n }\n get(selection: any, id: string): Projection<Root, RemoteData<any>>\n mutation(model: Root, requestId: string): MutationStatus\n refusal(model: Root, requestId: string, mutation: any): Option.Option<unknown>\n refresh(model: Root, target: any): Root\n plan(model: Root, projection: Projection<Root, any>): ReadonlyArray<unknown>\n /** `Data.active`: a read of the domain as an active Surface of its application. */\n active(\n name: string,\n projectionOf: (model: Root) => Option.Option<Projection<Root, any>>,\n ): ActiveSurface<Root>\n}\n\nexport interface EditorContent<FormModel, FormMessage, Value, Resources = {}, Services = never> {\n readonly name: string\n readonly entity: AnyEntity\n readonly form: EditorForm<FormModel, FormMessage, Value, Resources, Services>\n readonly roles: {\n readonly label: { readonly key: string } | undefined\n readonly slug: { readonly key: string } | undefined\n }\n readonly preview?:\n | ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>)\n | undefined\n}\n\n/** Read, and not being read again: what the server said last, not what it said before. */\nconst fresh = (read: RemoteData<unknown> | undefined): boolean =>\n read?._tag === 'Ready' || read?._tag === 'NotFound'\n\n// The editor's own Messages, beside the form's. `Rested` is the end of the\n// rest an edit started; the rest are what an author asks.\nexport const EditorMessage = defineMessageUnion({\n Rested: { edit: Schema.Number },\n PublishAsked: {},\n /** Lays what is in the form over the store, until `PreviewHidden`. Nothing is sent. */\n PreviewShown: {},\n PreviewHidden: {},\n /** Publishes later: the form is submitted and saved now, and the server keeps the promise. */\n ScheduleAsked: { at: Schema.String },\n UnscheduleAsked: {},\n ArchiveAsked: {},\n UnarchiveAsked: {},\n DiscardAsked: {},\n /** Makes a revision's value the working copy. It replaces what is here, and publishes nothing. */\n RestoreAsked: { revision: Schema.Number },\n UnpublishAsked: {},\n /** After a conflict: drop what is here and show the server's copy. */\n ReloadAsked: {},\n /** After a conflict: save what is here over the server's copy. */\n OverwriteAsked: {},\n})\nexport type EditorMessage = typeof EditorMessage.Type\nconst Own = EditorMessage\ntype Own = EditorMessage\n\n/**\n * A form's Submodel view as the view of the editor that wraps it, for\n * `Bundle.withView`: the editor's Model holds the form's under `form`, and what\n * the form's view sends is among the editor's Messages.\n *\n * ```ts\n * Editor.bundle.pipe(Bundle.withView(Cms.editorView(FormView.submodel(form, view))))\n * ```\n */\nexport const editorView = <FormModel, FormMessage, ViewInputs>(\n view: Submodel.View<FormModel, FormMessage, ViewInputs>,\n): Submodel.View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs> =>\n Submodel.defineView<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>(((\n model: EditorModel<FormModel>,\n inputs: ViewInputs,\n h: HtmlBuilder<FormMessage>,\n ): Html =>\n (view as (model: FormModel, inputs: ViewInputs, h: HtmlBuilder<FormMessage>) => Html)(\n model.form,\n inputs,\n h,\n )) as never)\n\nexport const makeEditor =\n (cms: {\n readonly Entities: { readonly Entry: AnyEntity; readonly Draft: AnyEntity }\n readonly Operations: Readonly<\n Record<\n | 'SaveDraft'\n | 'DiscardDraft'\n | 'Publish'\n | 'Unpublish'\n | 'Schedule'\n | 'Unschedule'\n | 'Archive'\n | 'Unarchive'\n | 'Restore',\n any\n >\n >\n }) =>\n <\n const Name extends string,\n FormModel,\n FormMessage extends { readonly _tag: string },\n Value,\n Resources = {},\n Services = never,\n >(\n name: Name,\n config: {\n readonly content: EditorContent<FormModel, FormMessage, Value, Resources, Services>\n /** How long after the last edit the draft is saved. Default: one second. */\n readonly rest?: Duration.Input\n /** Bumped when the form changes so that a saved Model no longer fits it. */\n readonly version?: string\n /** What an entry with no label yet is called in the worklist. */\n readonly untitled?: string\n },\n ) => {\n type Model = EditorModel<FormModel>\n const { content } = config\n const { form } = content\n const rest = config.rest ?? '1 second'\n const formTag = `${form.name}@${config.version ?? '1'}`\n\n const closed: Model = {\n form: form.initial,\n mode: 'closed',\n entry: null,\n filled: false,\n resumed: null,\n edits: 0,\n savedEdit: 0,\n saveId: null,\n saveWanted: false,\n publishId: null,\n publishWanted: false,\n submit: 'idle',\n scheduleAt: null,\n otherId: null,\n previewing: false,\n previewedAs: null,\n settling: null,\n }\n const Model = Schema.Struct({\n form: form.bundle.Model,\n mode: Schema.Literals(['closed', 'new', 'edit']),\n entry: Schema.NullOr(Schema.String),\n filled: Schema.Boolean,\n resumed: Schema.NullOr(Schema.Literals(['Model', 'Values', 'Published', 'Lost', 'Blank'])),\n edits: Schema.Number,\n savedEdit: Schema.Number,\n saveId: Schema.NullOr(Schema.String),\n saveWanted: Schema.Boolean,\n publishId: Schema.NullOr(Schema.String),\n publishWanted: Schema.Boolean,\n submit: Schema.Literals(['idle', 'waiting', 'stopped']),\n scheduleAt: Schema.NullOr(Schema.String),\n otherId: Schema.NullOr(Schema.String),\n previewing: Schema.Boolean,\n previewedAs: Schema.NullOr(Schema.String),\n settling: Schema.NullOr(Schema.Literals(['reload', 'overwrite'])),\n }) as unknown as Schema.Codec<Model, unknown>\n\n type Message = FormMessage | Own\n const Message = Schema.Union([form.bundle.Message, Own]) as unknown as Schema.Codec<\n Message,\n unknown\n >\n const own = new Set([\n 'Rested',\n 'PublishAsked',\n 'PreviewShown',\n 'PreviewHidden',\n 'ScheduleAsked',\n 'UnscheduleAsked',\n 'ArchiveAsked',\n 'UnarchiveAsked',\n 'DiscardAsked',\n 'RestoreAsked',\n 'UnpublishAsked',\n 'ReloadAsked',\n 'OverwriteAsked',\n ])\n const isOwn = (message: Message): message is Own => own.has(message._tag)\n\n const asks: Readonly<\n Record<\n Exclude<\n Own['_tag'],\n | 'Rested'\n | 'PublishAsked'\n | 'ScheduleAsked'\n | 'RestoreAsked'\n | 'PreviewShown'\n | 'PreviewHidden'\n >,\n EditorOut\n >\n > = {\n DiscardAsked: { _tag: 'Discard' },\n UnpublishAsked: { _tag: 'Unpublish' },\n UnscheduleAsked: { _tag: 'Unschedule' },\n ArchiveAsked: { _tag: 'Archive' },\n UnarchiveAsked: { _tag: 'Unarchive' },\n ReloadAsked: { _tag: 'Reload' },\n OverwriteAsked: { _tag: 'Overwrite' },\n }\n\n type Returned = Update.ReturnWithOutMessage<Model, Message, EditorOut, Services>\n\n const viaForm = (model: Model, message: FormMessage): Returned => {\n const next = form.bundle.update(model.form, message, undefined)\n // Authored content, not Message tags: a blur, a refusal, or a no-op does\n // not start a save, and a control the editor does not know about does.\n const edited = form.authoredChanged(model.form, next.model)\n const edits = edited ? model.edits + 1 : model.edits\n const commands: ReadonlyArray<Command<Message, never, Services>> = [\n // A form Message is one of the editor's, so the form's Commands are the editor's.\n ...((next.commands ?? []) as ReadonlyArray<Command<Message, never, Services>>),\n ...(edited\n ? [\n {\n name: `${name}.rest`,\n args: { edit: edits },\n effect: Effect.sleep(rest).pipe(Effect.as(Own.Rested({ edit: edits }))),\n } satisfies Command<Message, never, never>,\n ]\n : []),\n ]\n // A submit the form stopped is said until the next edit: stopped at once, or once\n // the check it waited for answered without letting it go.\n const validating = form.engine.isValidating(next.model)\n const submit: Model['submit'] =\n next.outMessage !== undefined || edited\n ? 'idle'\n : Predicate.isTagged(message, 'Submitted')\n ? validating\n ? 'waiting'\n : 'stopped'\n : model.submit === 'waiting' && !validating\n ? 'stopped'\n : model.submit\n // A form Message that changed nothing keeps this Model: Foldkit renders on its identity.\n const result = {\n model:\n next.model === model.form && submit === model.submit\n ? model\n : { ...model, form: next.model, edits, submit },\n commands,\n }\n return next.outMessage === undefined ? result : { ...result, outMessage: { _tag: 'Publish' } }\n }\n\n const bundle = Bundle.make(name, {\n Model,\n Message,\n init: () => ({ model: closed }),\n update: (model: Model, message: Message): Returned => {\n if (model.mode === 'closed') return { model }\n // A submit from the form's own button is a publish now, whatever was asked before.\n if (!isOwn(message))\n return viaForm(\n Predicate.isTagged(message, 'Submitted') ? { ...model, scheduleAt: null } : model,\n message,\n )\n switch (message._tag) {\n case 'Rested':\n // An edit since then started its own rest; this one has nothing to say.\n return message.edit === model.edits && model.edits > model.savedEdit\n ? { model, outMessage: { _tag: 'Save' } }\n : { model }\n case 'PublishAsked':\n return viaForm({ ...model, scheduleAt: null }, form.Message.Submitted())\n case 'PreviewShown':\n // A capability is declared, never implied.\n return content.preview === undefined\n ? { model }\n : { model: { ...model, previewing: true, previewedAs: null } }\n case 'PreviewHidden':\n return model.previewing ? { model: { ...model, previewing: false } } : { model }\n case 'RestoreAsked':\n return { model, outMessage: { _tag: 'Restore', revision: message.revision } }\n case 'ScheduleAsked':\n return viaForm({ ...model, scheduleAt: message.at }, form.Message.Submitted())\n case 'UnscheduleAsked':\n case 'ArchiveAsked':\n case 'UnarchiveAsked':\n case 'DiscardAsked':\n case 'UnpublishAsked':\n case 'ReloadAsked':\n case 'OverwriteAsked':\n return { model, outMessage: asks[message._tag] }\n }\n },\n helpers: {\n /** Opens an entry: its draft is resumed, or what is published is shown. */\n open: (_: Model, entry: string) => ({\n model: { ...closed, mode: 'edit' as const, entry },\n }),\n /**\n * Something new, under an id made where this is called (`Cms.newEntryId()`,\n * in a Command or an event handler): the first save makes the entry.\n */\n create: (_: Model, entry: string) => ({\n model: {\n ...closed,\n mode: 'new' as const,\n entry,\n filled: true,\n resumed: 'Blank' as const,\n },\n }),\n close: () => ({ model: closed }),\n },\n // A form control backed by a Bundle may listen and hold resources: they\n // run while an entry is open, and stop when the editor closes.\n subscriptions: () =>\n form.bundle.subscriptions === undefined\n ? {}\n : Subscription.lift(form.bundle.subscriptions(undefined))({\n read: (model: Model) =>\n model.mode === 'closed' ? Option.none() : Option.some(model.form),\n toParentMessage: (message: FormMessage): Message => message,\n }),\n resources: () =>\n (form.bundle.resources === undefined\n ? {}\n : ManagedResource.lift(\n form.bundle.resources(undefined) as Readonly<Record<string, never>>,\n )({\n read: (model: Model) =>\n model.mode === 'closed' ? Option.none() : Option.some(model.form),\n toParentMessage: message => message as Message,\n })) as [keyof Resources] extends [never] ? {} : Readonly<Record<string, never>>,\n })\n\n const EntryRead = Entity.select(\n cms.Entities.Entry as never,\n {\n type: true,\n targetId: true,\n revision: true,\n archivedAt: true,\n } as never,\n )\n const EntryState = Entity.select(\n cms.Entities.Entry as never,\n { state: true, may: true } as never,\n )\n const DraftRead = Entity.select(\n cms.Entities.Draft as never,\n {\n values: true,\n model: true,\n form: true,\n updatedAt: true,\n } as never,\n )\n const RowRead = Entity.selectFor(form.input as never)\n\n const decodeModel = Schema.decodeUnknownOption(form.bundle.Model)\n const encodeModel = Schema.encodeUnknownSync(form.bundle.Model as never)\n\n /** The keys of some saved values the form still accepts. */\n const fitting = (values: unknown): Partial<Value> => {\n if (typeof values !== 'object' || values === null) return {}\n const fields = form.input.schema.fields as Readonly<Record<string, Schema.Schema<unknown>>>\n return Object.fromEntries(\n Object.entries(values).filter(\n ([key, value]) => fields[key] !== undefined && Schema.is(fields[key])(value),\n ),\n ) as Partial<Value>\n }\n\n return {\n bundle,\n Message: Own,\n /** What is saved as a draft's `form`: the form's name and the version given. */\n formTag,\n\n at: <Root>(where: {\n readonly data: EditorDomain<Root>\n readonly model: ModelRef<Root, Model>\n }) => {\n type Step = Update.Step<Root, RemoteMessage, RemoteClient>\n const { data } = where\n const slice = ModelRef.focus(where.model)\n\n const entryOf = (root: Root) => {\n const { mode, entry, saveId } = slice.get(root)\n // Something new is not on the server until its first save.\n return entry === null || mode === 'closed' || (mode === 'new' && saveId === null)\n ? undefined\n : entry\n }\n /** What the editor reads of the open entry: each none while there is none to read. */\n const projections = {\n entry: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(EntryRead, entry)),\n state: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(EntryState, entry)),\n draft: (root: Root) =>\n Option.map(Option.fromUndefinedOr(entryOf(root)), entry => data.get(DraftRead, entry)),\n row: (root: Root) => Option.map(targetOf(root), target => data.get(RowRead, target)),\n }\n const read = (root: Root, part: keyof typeof projections): RemoteData<any> | undefined =>\n Option.getOrUndefined(\n Option.map(projections[part](root), projection => projection.read(root)),\n )\n /** What `part`'s read holds, by `RemoteData.held`; none while there is none to read. */\n const heldIn = <A>(root: Root, part: keyof typeof projections): Option.Option<A> =>\n Option.flatMap(Option.fromUndefinedOr(read(root, part)), r => RemoteData.held<A>(r))\n /** The published row the open entry points at, once the entry is read. */\n const targetOf = (root: Root): Option.Option<string> =>\n Option.flatMap(heldIn<{ readonly targetId: string | null }>(root, 'entry'), entry =>\n Option.fromNullOr(entry.targetId),\n )\n /**\n * Read and asked for nothing more. A draft known absent still reads\n * `NotFound` while a refresh asks about it again, so `fresh` alone\n * would take the old absence for the answer; the plan holds it until then.\n */\n const answered = (root: Root, part: keyof typeof projections): boolean =>\n fresh(read(root, part)) &&\n Option.match(projections[part](root), {\n onNone: () => true,\n onSome: projection => data.plan(root, projection).length === 0,\n })\n\n const statusOf = (root: Root, requestId: string | null): MutationStatus =>\n requestId === null ? { _tag: 'Unknown' } : data.mutation(root, requestId)\n /** Why the server refused a request, as the data its mutation declares. */\n const refusalOf = (\n root: Root,\n requestId: string | null,\n mutation: unknown,\n ): Option.Option<unknown> =>\n requestId === null ? Option.none() : data.refusal(root, requestId, mutation)\n\n /** Shows what was loaded, once: the draft by the ladder, else what is published. */\n const fill = (root: Root): Root => {\n const editor = slice.get(root)\n if (editor.filled || editor.mode !== 'edit') return root\n // A discard under way decides what there is to show.\n if (statusOf(root, editor.otherId)._tag === 'Pending') return root\n const entry = read(root, 'entry')\n const draft = read(root, 'draft')\n // After a conflict, what was held before is not what the server holds now.\n const arrived =\n editor.settling === 'reload'\n ? fresh\n : (r: RemoteData<unknown> | undefined) =>\n r !== undefined && (Option.isSome(RemoteData.held(r)) || r._tag === 'NotFound')\n if (!arrived(entry) || !arrived(draft)) return root\n const entryValue = heldIn<{ readonly targetId: string | null }>(root, 'entry')\n if (Option.isNone(entryValue)) return root\n const shown = (resumed: Resumed, next: FormModel): Root =>\n slice.set(root, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n form: next,\n filled: true,\n resumed,\n // A discard that led here is still the last thing that was asked.\n otherId: editor.otherId,\n })\n\n const saved = heldIn<{\n readonly values: unknown\n readonly model: unknown\n readonly form: string\n }>(root, 'draft')\n if (Option.isSome(saved)) {\n const model =\n saved.value.form === formTag ? decodeModel(saved.value.model) : Option.none()\n // A check that was running when it was saved will never answer.\n if (Option.isSome(model)) return shown('Model', form.settled(model.value))\n const values = fitting(saved.value.values)\n if (Object.keys(values).length > 0)\n return shown('Values', form.fill(form.initial, values).model)\n }\n const lost: Resumed = Option.isNone(saved) ? 'Published' : 'Lost'\n if (entryValue.value.targetId === null)\n return shown(Option.isNone(saved) ? 'Blank' : 'Lost', form.initial)\n if (!arrived(read(root, 'row'))) return root\n return Option.match(heldIn<Readonly<Record<string, unknown>>>(root, 'row'), {\n onNone: () => shown(lost, form.initial),\n onSome: rowValue =>\n shown(\n lost,\n form.fill(\n form.initial,\n Entity.valuesFor(form.input as never, rowValue as never) as Partial<Value>,\n ).model,\n ),\n })\n }\n\n const startSave: Step = root => {\n const editor = slice.get(root)\n const values = form.partial(editor.form) as Readonly<Record<string, unknown>>\n const labelKey = content.roles.label?.key\n const typed =\n labelKey === undefined ? '' : form.field(editor.form, labelKey as never).value\n const label = typeof typed === 'string' ? typed.trim() : ''\n const basedOn = Option.match(heldIn<{ readonly updatedAt: string }>(root, 'draft'), {\n onNone: () => null,\n onSome: draft => draft.updatedAt,\n })\n const started = data.mutate(root, cms.Operations.SaveDraft, {\n entry: editor.entry,\n type: content.name,\n label: label === '' ? (config.untitled ?? 'Untitled') : label,\n values,\n // Settled, as it is shown again: nothing in flight is stored, such as a Builder's\n // undo history, which made a big page's draft too large to save.\n model: encodeModel(form.settled(editor.form)),\n form: formTag,\n basedOn,\n })\n return {\n model: slice.set(started.model, {\n ...slice.get(started.model),\n saveId: started.requestId,\n // A save starts a new round: the last publish no longer describes the form.\n publishId: null,\n otherId: null,\n savedEdit: editor.edits,\n saveWanted: false,\n settling: null,\n }),\n commands: [started.command],\n }\n }\n\n /** An operation that names the entry and nothing else. The server's patches say what it did. */\n const simple =\n (operation: 'Unpublish' | 'Unschedule' | 'Archive' | 'Unarchive'): Step =>\n root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n const started = data.mutate(root, cms.Operations[operation], { entry: editor.entry })\n return {\n model: slice.set(started.model, {\n ...slice.get(started.model),\n otherId: started.requestId,\n }),\n commands: [started.command],\n }\n }\n\n /**\n * A discarded draft takes what is on screen with it, the edits still resting\n * included. What is published is shown again once the discard has settled;\n * something never published has nothing left, and the editor closes.\n */\n const discard: Step = root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n // Something new that was never saved is only here.\n if (editor.mode === 'new' && editor.saveId === null)\n return { model: slice.set(root, closed) }\n const unpublished = Option.isNone(targetOf(root))\n const started = data.mutate(root, cms.Operations.DiscardDraft, { entry: editor.entry })\n return {\n model: slice.set(\n started.model,\n unpublished\n ? closed\n : {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n otherId: started.requestId,\n settling: 'reload',\n },\n ),\n commands: [started.command],\n }\n }\n\n /** The form is emptied, and filled from the restored draft once the restore has settled. */\n const restore =\n (revision: number): Step =>\n root => {\n const editor = slice.get(root)\n if (editor.entry === null) return { model: root }\n const started = data.mutate(root, cms.Operations.Restore, {\n entry: editor.entry,\n revision,\n })\n return {\n model: slice.set(started.model, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n otherId: started.requestId,\n settling: 'reload',\n }),\n commands: [started.command],\n }\n }\n\n /**\n * What follows from what has arrived: the loaded value is shown, a save\n * that waited its turn starts, and a publish goes once its draft is saved.\n */\n const overlayId = `${name}.preview`\n /**\n * What is in the form, over the store, while preview is on: made again when\n * the form has moved on, and lifted the moment it is off, however that came\n * about (a close, a discard, a reload).\n */\n const previewed = (root: Root): Root => {\n const editor = slice.get(root)\n if (!editor.previewing || content.preview === undefined || editor.entry === null)\n return lift(data, root, overlayId)\n // Something new is shown under its entry's id until publishing gives it a row.\n const entry = editor.entry\n const id = Option.getOrElse(targetOf(root), () => entry)\n const as = `${editor.edits}:${id}`\n if (editor.previewedAs === as) return root\n const shown = overlay(\n data,\n root,\n overlayId,\n content.preview(form.partial(editor.form), id),\n )\n return slice.set(shown, { ...slice.get(shown), previewedAs: as })\n }\n\n /**\n * A server's word about one key, on that key. A publish refused for a taken\n * address is about the address, and belongs beside it rather than in a\n * status line. Saying it again while it already stands would be noise.\n */\n const refused = (root: Root): Root => {\n const editor = slice.get(root)\n const refusal = Option.filter(\n refusalOf(root, editor.publishId, cms.Operations.Publish),\n Refusal.isField,\n )\n if (Option.isNone(refusal)) return root\n const { key } = refusal.value\n // A publish sends the saved draft, which the form still holds until the next edit.\n if (content.roles.slug?.key !== key || editor.edits !== editor.savedEdit) return root\n const reason = String(refusal.value.reason)\n const field = form.field(editor.form, key as never)\n if (field._tag === 'Invalid' && field.errors.includes(reason)) return root\n return slice.set(root, {\n ...editor,\n form: form.bundle.update(\n editor.form,\n form.Message.Refused({\n key: key as never,\n error: reason,\n value: (form.partial(editor.form) as Readonly<Record<string, unknown>>)[key],\n }),\n undefined,\n ).model,\n })\n }\n\n /**\n * Tells the form which row it is editing, so a check that asks the server\n * about a key can pass over what this row already holds: an address is not\n * taken by the post that owns it. A form that creates something is about\n * nothing, which is the subject it starts with.\n */\n const about = (root: Root): Root => {\n const editor = slice.get(root)\n const target = Option.getOrUndefined(targetOf(root))\n const subject = target === undefined ? {} : { id: target }\n if (form.subject(editor.form).id === subject.id) return root\n return slice.set(root, {\n ...editor,\n form: form.bundle.update(editor.form, form.Message.About({ subject }), undefined).model,\n })\n }\n\n const sync: Step = given => {\n let root = refused(previewed(about(fill(given))))\n const commands: Array<Command<RemoteMessage, never, RemoteClient>> = []\n const run = (step: Step) => {\n const next = step(root)\n root = next.model\n commands.push(...(next.commands ?? []))\n }\n const editor = () => slice.get(root)\n if (editor().mode === 'closed' || !editor().filled) return { model: root }\n\n const saving = () => statusOf(root, editor().saveId)._tag === 'Pending'\n // Saving over someone else's copy is based on that copy, once it is here.\n if (editor().settling === 'overwrite' && answered(root, 'draft')) run(startSave)\n if (editor().saveWanted && !saving() && editor().settling === null) run(startSave)\n\n // A second ask while the first is on its way is the same ask.\n if (editor().publishWanted && statusOf(root, editor().publishId)._tag === 'Pending')\n root = slice.set(root, { ...editor(), publishWanted: false })\n if (editor().publishWanted && !saving() && editor().settling === null) {\n const save = statusOf(root, editor().saveId)\n const resumedDraft = editor().resumed === 'Model' || editor().resumed === 'Values'\n const { applied, failed } = Match.valueTags(save, {\n Applied: () => ({ applied: true, failed: false }),\n Failed: () => ({ applied: false, failed: true }),\n Pending: () => ({ applied: false, failed: false }),\n Unknown: () => ({ applied: false, failed: false }),\n })\n const saved =\n editor().edits === editor().savedEdit &&\n (editor().saveId === null ? resumedDraft : applied)\n if (failed && editor().edits === editor().savedEdit) {\n // The draft could not be saved, so there is nothing to publish; the save says why.\n root = slice.set(root, { ...editor(), publishWanted: false })\n } else if (!saved) {\n run(startSave)\n } else {\n const basedOn = Option.match(\n heldIn<{ readonly revision: number | null }>(root, 'entry'),\n { onNone: () => null, onSome: entry => entry.revision },\n )\n const at = editor().scheduleAt\n const started =\n at === null\n ? data.mutate(root, cms.Operations.Publish, { entry: editor().entry, basedOn })\n : data.mutate(root, cms.Operations.Schedule, { entry: editor().entry, at })\n root = slice.set(started.model, {\n ...slice.get(started.model),\n publishId: started.requestId,\n publishWanted: false,\n })\n commands.push(started.command)\n }\n }\n return { model: root, commands }\n }\n\n const failure = (root: Root): Option.Option<RemoteError> => {\n const editor = slice.get(root)\n for (const id of [editor.publishId, editor.saveId, editor.otherId]) {\n const status = statusOf(root, id)\n if (status._tag === 'Failed') return Option.some(status.error)\n }\n return Option.none()\n }\n\n const active = (part: keyof typeof projections): ActiveSurface<Root> =>\n data.active(`${name}.${part}`, projections[part])\n\n return {\n /** For the placement: what the editor asked becomes the mutation, or waits its turn. */\n onOut:\n (out: EditorOut): Step =>\n root => {\n const editor = slice.get(root)\n switch (out._tag) {\n case 'Save':\n return sync(slice.set(root, { ...editor, saveWanted: true }))\n case 'Publish':\n return sync(slice.set(root, { ...editor, publishWanted: true }))\n case 'Restore':\n return restore(out.revision)(root)\n case 'Discard':\n return discard(root)\n case 'Unpublish':\n return simple('Unpublish')(root)\n case 'Unschedule':\n return simple('Unschedule')(root)\n case 'Archive':\n return simple('Archive')(root)\n case 'Unarchive':\n return simple('Unarchive')(root)\n case 'Reload': {\n const refreshed = (['entry', 'draft', 'row'] as const).reduce(\n (next, part) =>\n Option.match(projections[part](next), {\n onNone: () => next,\n onSome: projection => data.refresh(next, projection),\n }),\n root,\n )\n return {\n model: slice.set(refreshed, {\n ...closed,\n mode: 'edit',\n entry: editor.entry,\n settling: 'reload',\n }),\n }\n }\n case 'Overwrite': {\n const refreshed = Option.match(projections.draft(root), {\n onNone: () => root,\n onSome: projection => data.refresh(root, projection),\n })\n return {\n model: slice.set(refreshed, { ...slice.get(refreshed), settling: 'overwrite' }),\n }\n }\n }\n },\n\n /**\n * For `Data.subscriptions`, spread beside the application's own: the entry,\n * its state, its draft, and the row what is published is shown from. Each\n * is a requirement while an entry is open, so Remote fetches and retains it.\n */\n actives: {\n [`${name}.entry`]: active('entry'),\n [`${name}.state`]: active('state'),\n [`${name}.draft`]: active('draft'),\n [`${name}.row`]: active('row'),\n } as Readonly<\n Record<`${Name}.${'entry' | 'state' | 'draft' | 'row'}`, ActiveSurface<Root>>\n >,\n\n sync,\n\n /**\n * Saves what has not been saved, now, without waiting for the rest to end.\n * Run it before `close` or `open`, which drop what is in the form: an\n * author who types and leaves within the rest would otherwise lose it.\n */\n flush: (root => {\n const editor = slice.get(root)\n return editor.mode === 'closed' || !editor.filled || editor.edits === editor.savedEdit\n ? { model: root }\n : sync(slice.set(root, { ...editor, saveWanted: true }))\n }) satisfies Step,\n\n /**\n * Wraps the application's `update` so `sync` runs after every Message: a\n * value may arrive, or a save settle, with any of them.\n */\n after:\n <\n Message,\n Result extends { readonly model: Root; readonly commands?: ReadonlyArray<any> },\n >(\n update: (model: Root, message: Message) => Result,\n ) =>\n (model: Root, message: Message): Result => {\n const next = update(model, message)\n const synced = sync(next.model)\n return {\n ...next,\n model: synced.model,\n commands: [...(next.commands ?? []), ...(synced.commands ?? [])],\n }\n },\n\n /** Whether this content type can be previewed, and whether it is being. */\n canPreview: content.preview !== undefined,\n previewing: (root: Root): boolean => slice.get(root).previewing,\n /**\n * The id the application's own pages know this content by: the row's, or\n * the entry's while there is no row. It is what a preview is shown under.\n */\n pageId: (root: Root): Option.Option<string> =>\n Option.orElse(targetOf(root), () => Option.fromNullOr(slice.get(root).entry)),\n /** The entry being edited; none while closed. */\n entry: (root: Root): Option.Option<string> => Option.fromNullOr(slice.get(root).entry),\n /**\n * The entry as the server knows it: none while closed, and while\n * something new is not saved yet, so a link naming it would find nothing.\n */\n storedEntry: (root: Root): Option.Option<string> => Option.fromUndefinedOr(entryOf(root)),\n /** How the form came to hold what it holds; `Lost` is worth telling the author. */\n resumed: (root: Root): Option.Option<Resumed> =>\n Option.fromNullOr(slice.get(root).resumed),\n /** The entry's lifecycle state, as the server last derived it; none until it is read. */\n state: (root: Root): Option.Option<State> =>\n Option.map(\n heldIn<{ readonly state: State }>(root, 'state'),\n entryState => entryState.state,\n ),\n /**\n * Whether the signed-in principal may ask this transition of the open\n * entry, by the server's `allow`, as the server said with the entry: false\n * until it is read. Whether the entry offers it now is its `state`'s to\n * say. For hiding what would be refused; the server still decides.\n */\n may: (root: Root, transition: Transition): boolean =>\n Option.exists(\n heldIn<{ readonly may: ReadonlyArray<Transition> }>(root, 'state'),\n entryState => entryState.may.includes(transition),\n ),\n /** Why the last publish, save, discard or unpublish failed. */\n error: failure,\n\n status: (root: Root): EditorStatus => {\n const editor = slice.get(root)\n if (editor.mode === 'closed') return 'Closed'\n // An entry opened from the server is loading until its state is read\n // too, so what the state draws (the badge, the history, Publish)\n // arrives with the form instead of a moment after it. A state whose\n // read failed holds nothing either: the badge would say New.\n const stateRead = read(root, 'state')\n const stateUnread =\n editor.mode === 'edit' &&\n (stateRead === undefined ||\n (stateRead._tag !== 'NotFound' && Option.isNone(RemoteData.held(stateRead))))\n if (!editor.filled || stateUnread) {\n const entry = read(root, 'entry')\n if (entry?._tag === 'NotFound') return 'NotFound'\n const parts = [entry, read(root, 'draft'), read(root, 'row'), stateRead]\n return parts.some(part => part?._tag === 'Failed') ? 'LoadFailed' : 'Loading'\n }\n const publish = statusOf(root, editor.publishId)\n const save = statusOf(root, editor.saveId)\n const later = editor.scheduleAt !== null\n // A submit waiting for a check is on its way, as one sent is.\n if (publish._tag === 'Pending' || editor.submit === 'waiting')\n return later ? 'Scheduling' : 'Publishing'\n if (save._tag === 'Pending' || editor.settling === 'overwrite') return 'Saving'\n if (editor.submit === 'stopped') return 'Incomplete'\n const conflicted =\n Option.exists(\n refusalOf(root, editor.saveId, cms.Operations.SaveDraft),\n Refusal.isConflict,\n ) ||\n Option.exists(\n refusalOf(root, editor.publishId, cms.Operations.Publish),\n Refusal.isConflict,\n )\n if (editor.edits > editor.savedEdit) return 'Editing'\n if (conflicted) return 'Conflict'\n // A failed save outranks what the publish says; neither is pending here.\n switch (save._tag) {\n case 'Failed':\n return 'SaveFailed'\n case 'Unknown':\n case 'Applied':\n switch (publish._tag) {\n case 'Failed':\n return later ? 'ScheduleFailed' : 'PublishFailed'\n case 'Applied':\n return later ? 'Scheduled' : 'Published'\n case 'Unknown': {\n // Nothing pending and nothing entered: the form is as it was found. A\n // draft it was filled from is on the server already; anything else is not.\n const onServer =\n save._tag === 'Applied' ||\n editor.resumed === 'Model' ||\n editor.resumed === 'Values'\n return onServer ? 'Saved' : 'Opened'\n }\n }\n }\n },\n }\n },\n }\n }\n","/**\n * The displays a CMS adds, made with `Display.kind` exactly as an application\n * makes its own, and a renderer for each to spread beside `foldkit-mixins-crud`'s.\n * Its controls, a slug and a moment, are `foldkit-form-recipes`'.\n * Entry-level views (its state badge, published history, remaining\n * transitions) live in `./views.js`: they draw on the application's own slot\n * builders, so the application keeps its slots and styles.\n */\nimport { Display, type DisplayWords } from 'foldkit-crud'\nimport { fillWords } from 'foldkit-form'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { State } from './lifecycle.js'\n\n/**\n * The attribute an entry's state is written in, wherever the CMS draws one (a\n * list's state cell, `stateBadge`): one name, so one tone rule styles both.\n */\nexport const stateAttribute = 'data-cms-state'\n\nexport interface StateWords {\n readonly New?: string\n readonly Published?: string\n readonly Changed?: string\n readonly Unpublished?: string\n readonly Archived?: string\n readonly scheduled?: string\n readonly overdue?: string\n /** A state with what its schedule adds: `{state}` and `{schedule}`. */\n readonly withSchedule?: string\n}\nconst stateWords: Required<StateWords> = {\n New: 'New',\n Published: 'Published',\n Changed: 'Changed',\n Unpublished: 'Unpublished',\n Archived: 'Archived',\n scheduled: 'scheduled',\n overdue: 'overdue',\n withSchedule: '{state}, {schedule}',\n}\n\nconst isState = (value: unknown): value is State =>\n typeof value === 'object' && value !== null && '_tag' in value && 'schedule' in value\n\n/** What a state's schedule adds to it: nothing, `scheduled`, or `overdue`. */\nconst scheduleOf = (state: State): 'scheduled' | 'overdue' | undefined =>\n state.schedule === null ? undefined : state.schedule.overdue ? 'overdue' : 'scheduled'\n\n/** An entry's lifecycle state, as words. A publish that did not happen says so. */\nconst StateDisplay = Display.kind<{ readonly words?: StateWords | undefined }>('CmsState', {\n text: (data, value) => {\n if (!isState(value)) return String(value)\n const words = { ...stateWords, ...data.words }\n const schedule = scheduleOf(value)\n return schedule === undefined\n ? words[value._tag]\n : fillWords(words.withSchedule, { state: words[value._tag], schedule: words[schedule] })\n },\n})\n\nconst units: ReadonlyArray<readonly [Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 31_536_000_000],\n ['month', 2_592_000_000],\n ['day', 86_400_000],\n ['hour', 3_600_000],\n ['minute', 60_000],\n]\n\n// One formatter per locale, kept: a list draws a Moment in every row, and\n// making an Intl formatter costs far more than formatting with one.\nconst absolutes = new Map<string, Intl.DateTimeFormat>()\nconst relatives = new Map<string, Intl.RelativeTimeFormat>()\nconst absoluteIn = (locale: string): Intl.DateTimeFormat => {\n const known = absolutes.get(locale)\n if (known !== undefined) return known\n const made = new Intl.DateTimeFormat(locale, {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: 'UTC',\n })\n absolutes.set(locale, made)\n return made\n}\nconst relativeIn = (locale: string): Intl.RelativeTimeFormat => {\n const known = relatives.get(locale)\n if (known !== undefined) return known\n const made = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n relatives.set(locale, made)\n return made\n}\n\n/**\n * A time. Given a clock it reads relative to it (\"3 days ago\"), and the view\n * decides how often that clock moves; given none it is the date and the time.\n */\nconst Moment = Display.kind<{\n readonly now?: (() => Date) | undefined\n readonly locale?: string | undefined\n}>('CmsMoment', {\n text: (data, value) => {\n const at = new Date(String(value))\n if (Number.isNaN(at.getTime())) return String(value)\n if (data.now === undefined) return absoluteIn(data.locale ?? 'en').format(at)\n const delta = at.getTime() - data.now().getTime()\n const relative = relativeIn(data.locale ?? 'en')\n const unit = units.find(([, size]) => Math.abs(delta) >= size)\n return unit === undefined\n ? relative.format(0, 'minute')\n : relative.format(Math.trunc(delta / unit[1]), unit[0])\n },\n})\n\n/** What `foldkit-mixins-crud` gives a display's renderer, as far as these read it. */\nexport interface DisplayContext<Message> {\n readonly display: {\n readonly kind: string\n readonly text: (value: unknown, words: DisplayWords) => string\n }\n readonly value: unknown\n readonly words: DisplayWords\n readonly h: HtmlBuilder<Message>\n readonly badge: { readonly attrs: (attrs: ReadonlyArray<any>) => any }\n}\n\nexport const Kinds = {\n /** The display kinds. */\n Display: { State: StateDisplay, Moment },\n\n /** For `ListView`'s and `DetailView`'s `renderers`: a state as a badge, a moment as a `time`. */\n displayRenderers: <Message>(): Readonly<\n Record<string, (context: DisplayContext<Message>) => Html>\n > => ({\n [StateDisplay.kind]: ({ display, value, words, h, badge }) =>\n h.span(\n badge.attrs(\n isState(value)\n ? [\n h.Attribute(stateAttribute, value._tag),\n ...(scheduleOf(value) === undefined\n ? []\n : [h.DataAttribute('cms-schedule', scheduleOf(value)!)]),\n ]\n : [],\n ),\n [display.text(value, words)],\n ),\n [Moment.kind]: ({ display, value, words, h }) =>\n h.time([h.Attribute('datetime', String(value))], [display.text(value, words)]),\n }),\n}\n","/**\n * The entry-level views every CMS studio draws: its state badge, its\n * published revisions, and what can still happen to it. An application passes\n * its own slot builders and keeps its slots and styles; the interfaces below\n * are the builders each view reads. Words for states come from\n * `Cms.Display`, so a studio and its lists say them one way.\n */\nimport { Match, Option } from 'effect'\nimport { Display } from 'foldkit-crud'\nimport type { SlotView } from 'foldkit-mixins'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { RemoteData } from 'foldkit-remote'\nimport { Kinds, stateAttribute } from './kinds.js'\nimport type { State, Transition } from './lifecycle.js'\n\n/** Whether the entry's state is one of `tags`; an entry with no state yet is none of them. */\nexport const stateIs = (state: Option.Option<State>, ...tags: ReadonlyArray<State['_tag']>) =>\n Option.exists(state, known => tags.includes(known._tag))\n\n/**\n * An entry's state as a badge: its tag is its color, its words the CMS's. The\n * tag is in `stateAttribute`, as a list's state cell writes it.\n */\nexport const stateBadge = <M>(\n badge: SlotView.SlotBuilder<M>,\n h: HtmlBuilder<M>,\n state: Option.Option<State>,\n): Html =>\n Option.match(state, {\n // Something new has no entry yet, so no state: it is new all the same.\n onNone: () => h.span(badge.attrs([h.Attribute(stateAttribute, 'New')]), ['New']),\n onSome: known =>\n h.span(badge.attrs([h.Attribute(stateAttribute, known._tag)]), [\n Display.show(Kinds.Display.State.of({}), known),\n ]),\n })\n\n/** A published revision, as an editor's History lists it. */\nexport interface RevisionRow {\n readonly n: number\n readonly publishedAt: string\n readonly publishedBy: string | null\n}\n\n/**\n * The open entry's published revisions, as they have been read. A posts'\n * history and a pages' revisions read through the same shape, so one helper\n * serves both: which read is the section's to name. A read that failed, or\n * that has no answer yet, is its own state rather than an empty list, so the\n * card cannot mistake either for nothing published.\n */\nexport type RevisionHistory =\n | { readonly _tag: 'Ready'; readonly revisions: ReadonlyArray<RevisionRow> }\n | { readonly _tag: 'Loading' }\n | { readonly _tag: 'Failed' }\n\nexport const revisionsOf = <M, Value extends { readonly revisions: ReadonlyArray<RevisionRow> }>(\n model: M,\n history: (model: M) => Option.Option<{ readonly read: (model: M) => RemoteData<Value> }>,\n): RevisionHistory =>\n Option.match(history(model), {\n // No history to read: there is nothing to wait for and nothing to fail.\n onNone: () => ({ _tag: 'Ready', revisions: [] }),\n onSome: projection => {\n const read = projection.read(model)\n switch (read._tag) {\n case 'Ready':\n case 'Refreshing':\n return { _tag: 'Ready', revisions: read.value.revisions } as const\n case 'Failed':\n return { _tag: 'Failed' } as const\n case 'NotFound':\n return { _tag: 'Ready', revisions: [] } as const\n case 'Initial':\n case 'Loading':\n return { _tag: 'Loading' } as const\n }\n },\n })\n\n/** A moment as the History says it: \"Sep 27, 2026\" and \"9:12 PM\", apart. */\nconst momentOf = (iso: string, locale: string, timeZone: string) => {\n const at = new Date(iso)\n return {\n day: at.toLocaleDateString(locale, {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n timeZone,\n }),\n time: at.toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit', timeZone }),\n }\n}\n\n/** The builders `historyCard` reads. */\nexport interface HistoryCardSlots<M> {\n readonly card: SlotView.SlotBuilder<M>\n readonly cardTitle: SlotView.SlotBuilder<M>\n readonly muted: SlotView.SlotBuilder<M>\n readonly timeline: SlotView.SlotBuilder<M>\n readonly revision: SlotView.SlotBuilder<M>\n readonly revisionMark: SlotView.SlotBuilder<M>\n readonly revisionBody: SlotView.SlotBuilder<M>\n readonly revisionTitle: SlotView.SlotBuilder<M>\n readonly revisionLive: SlotView.SlotBuilder<M>\n readonly revisionMeta: SlotView.SlotBuilder<M>\n readonly revisionRestore: SlotView.SlotBuilder<M>\n}\n\n/**\n * What was published, newest first, as a timeline: each revision on a line\n * down to the first, with when and by whom. The newest is marked Live while\n * the entry is on the site; restoring it is offered only while a draft sits\n * over it, since otherwise it changes nothing. A history still being read\n * says so as a busy status, and one that failed as an alert, so neither is\n * mistaken for nothing published nor read as plain text; give `muted`\n * `Utilities.busyReveal` (`foldkit-mixins/utilities`) and the wait is said\n * only once it is noticeable. A failed read is not\n * retried on its own: given `onRetry`, a button sends it, drawn on the\n * restore slot so no new builder is required of every studio. Who published\n * is the application's to name (`authorName`), as only it knows its chairs.\n * Its dates are written in the `locale` and `timeZone` given: both are\n * required, since the runtime's own would differ between a server and a\n * browser.\n */\nexport const historyCard = <M>(\n slots: HistoryCardSlots<M>,\n h: HtmlBuilder<M>,\n history: RevisionHistory,\n entry: {\n readonly state: Option.Option<State>\n readonly restore: (revision: number) => M\n readonly authorName: (name: string) => string\n /** The BCP 47 locale each revision's date and time are written in, such as `en`. */\n readonly locale: string\n /** The IANA time zone each revision's date and time are written in, such as `UTC`. */\n readonly timeZone: string\n /**\n * Asks again after a failed read. Given, a failed history shows a button\n * that sends it; a failed read is not retried on its own.\n */\n readonly onRetry?: M | undefined\n /** What the retry button says. Default `Try again`. */\n readonly words?: { readonly retry?: string | undefined } | undefined\n },\n): Html => {\n const live = stateIs(entry.state, 'Published', 'Changed')\n const drafted = stateIs(entry.state, 'Changed')\n const body: ReadonlyArray<Html> = Match.value(history).pipe(\n Match.tagsExhaustive({\n Failed: () => [\n h.p(slots.muted.attrs([h.Role('alert')]), ['The history could not be read.']),\n ...(entry.onRetry === undefined\n ? []\n : [\n h.button(slots.revisionRestore.attrs([h.Type('button'), h.OnClick(entry.onRetry)]), [\n entry.words?.retry ?? 'Try again',\n ]),\n ]),\n ],\n Loading: () => [h.p(slots.muted.attrs([h.Role('status'), h.AriaBusy(true)]), ['Loading…'])],\n Ready: ({ revisions }) => [\n revisions.length === 0\n ? h.p(slots.muted.attrs(), ['Nothing has been published yet.'])\n : h.ol(\n slots.timeline.attrs([h.AriaLabel('Published revisions, newest first')]),\n revisions.map((revision, index) => {\n const newest = index === 0\n const { day, time } = momentOf(revision.publishedAt, entry.locale, entry.timeZone)\n const isLive = newest && live\n return h.li(slots.revision.attrs(isLive ? [h.DataAttribute('live', '')] : []), [\n h.span(slots.revisionMark.attrs([h.AriaHidden(true)]), []),\n h.div(slots.revisionBody.attrs(), [\n h.p(slots.revisionTitle.attrs(), [\n `Revision ${revision.n}`,\n ...(isLive ? [h.span(slots.revisionLive.attrs(), ['Live'])] : []),\n ]),\n h.p(slots.revisionMeta.attrs(), [\n h.time([h.Attribute('datetime', revision.publishedAt)], [`${day} · ${time}`]),\n ...(revision.publishedBy === null\n ? []\n : [` · ${entry.authorName(revision.publishedBy)}`]),\n ]),\n ]),\n ...(isLive && !drafted\n ? []\n : [\n h.button(\n slots.revisionRestore.attrs([\n h.OnClick(entry.restore(revision.n)),\n h.AriaLabel(`Restore revision ${revision.n}`),\n ]),\n ['Restore'],\n ),\n ]),\n ])\n }),\n ),\n ],\n }),\n )\n return h.section(slots.card.attrs([h.Id('history')]), [\n h.h2(slots.cardTitle.attrs(), ['History']),\n ...body,\n ])\n}\n\n/** The builders `moreCard` reads. */\nexport interface MoreCardSlots<M> {\n readonly card: SlotView.SlotBuilder<M>\n readonly cardTitle: SlotView.SlotBuilder<M>\n readonly toolbar: SlotView.SlotBuilder<M>\n readonly button: SlotView.SlotBuilder<M>\n readonly danger: SlotView.SlotBuilder<M>\n}\n\n/**\n * The rest of what can happen to an entry: its draft discarded, taken off the\n * site, put away or brought back. Discard and unpublish are each offered only\n * where the server would allow them; archive is always offered, with unarchive\n * taking its place once put away. None for something never saved, which has\n * nothing to discard or put away. The archive button's icon is the\n * application's, drawn its way.\n */\nexport const moreCard = <M>(\n slots: MoreCardSlots<M>,\n h: HtmlBuilder<M>,\n entry: {\n readonly state: Option.Option<State>\n readonly may: (transition: Transition) => boolean\n readonly asks: {\n readonly discard: M\n readonly unpublish: M\n readonly archive: M\n readonly unarchive: M\n }\n readonly archiveIcon: Html\n },\n): ReadonlyArray<Html> => {\n const { state, may, asks } = entry\n if (Option.isNone(state)) return []\n const action = (id: string, label: string, message: M): Html =>\n h.button(slots.button.attrs([h.Id(id), h.OnClick(message)]), [label])\n return [\n h.section(slots.card.attrs(), [\n h.h2(slots.cardTitle.attrs(), ['More']),\n h.div(slots.toolbar.attrs(), [\n ...(may('discard') && stateIs(state, 'Changed', 'New')\n ? [action('discard', 'Discard draft', asks.discard)]\n : []),\n ...(may('unpublish') && stateIs(state, 'Published', 'Changed')\n ? [action('unpublish', 'Unpublish', asks.unpublish)]\n : []),\n stateIs(state, 'Archived')\n ? action('unarchive', 'Unarchive', asks.unarchive)\n : h.button(slots.danger.attrs([h.Id('archive'), h.OnClick(asks.archive)]), [\n entry.archiveIcon,\n 'Archive',\n ]),\n ]),\n ]),\n ]\n}\n","import { Effect, Schema } from 'effect'\nimport { Query, Remote } from 'foldkit-remote'\nimport type { RemoteClient } from 'foldkit-remote'\n\n/**\n * A form check that says, while the author types, what a publish would refuse:\n * this address belongs to something else. It asks the content type's `bySlug`\n * query, which an author reads through the same binding as everyone else — so it\n * sees unpublished rows too, and an address taken by work not yet shown is taken.\n *\n * It is named by the content type, not given it, so a form can be made with it\n * before the content type that nests the form exists.\n *\n * Put it in the form's `checks` under the slug key:\n * `checks: { slug: Cms.addressFree('posts') }`. The form must know which row it\n * is editing for the row to keep its own address; `Cms.editor` tells it.\n *\n * This is advice, and deliberately not the rule. Two authors can both be told an\n * address is free and both publish; the server refuses the second on the same\n * key, through `Form.Message.Refused`. Asking earlier makes that rarer, never\n * impossible.\n */\nexport const addressFree = (\n content: string,\n): ((\n slug: string,\n context: { readonly subject: Readonly<Record<string, string>> },\n) => Effect.Effect<string | undefined, never, RemoteClient>) => {\n // The same query the server registered for this content type: a descriptor is\n // its name and its input, so one made here asks what one made there answers.\n const descriptor = Query.make(`${content}BySlug`, {\n Input: { slug: Schema.String },\n Result: Schema.Unknown,\n })\n return (\n slug: string,\n context: { readonly subject: Readonly<Record<string, string>> },\n ): Effect.Effect<string | undefined, never, RemoteClient> =>\n Remote.query(descriptor.ref({ slug })).pipe(\n // An edge is an id, which is all this asks about.\n Effect.map(result =>\n result.edges.some(edge => edge.id !== context.subject.id)\n ? `\"${slug}\" is already used`\n : undefined,\n ),\n // A check that could not ask says nothing: the publish is still the rule,\n // and an address is not refused because the network was down.\n Effect.orElseSucceed(() => undefined),\n )\n}\n","/**\n * `foldkit-cms` — what a CMS adds to a domain that is already declared: audience\n * (who may see it), time (drafts, revisions, a schedule), and address (a slug).\n *\n * A draft is an unsent form, kept beside the content row and never in it. The\n * row holds what is published; publishing is the application's own mutation,\n * run with the draft's value. This package is the declarations and the pure\n * rules. It reads no database and owns no state; `foldkit-cms-drizzle` is the\n * server, and lists and forms draw through `foldkit-crud`'s views.\n */\nimport { Schema } from 'effect'\nimport {\n Collation,\n Entity,\n Relation,\n Derived,\n type AnyEntity,\n type EntityField,\n type EntityInput,\n type Reads,\n type TestPredicate,\n Expr,\n Order,\n SchemaShape,\n} from 'foldkit-entity'\nimport { Metadata } from 'foldkit-metadata'\nimport {\n Mutation,\n Query,\n Refusal,\n type MutationDescriptor,\n type OptimisticOperation,\n} from 'foldkit-remote'\nimport { Transitions, offers, state, type Facts, type State, type Transition } from './lifecycle.js'\nimport { editorView, makeEditor } from './editor.js'\nimport { historyCard, moreCard, revisionsOf, stateBadge, stateIs } from './views.js'\nimport { addressFree } from './slug.js'\nimport { Display } from 'foldkit-crud'\nimport { Kinds, stateAttribute } from './kinds.js'\n\nexport type { Facts, Schedule, State, StateTag, Transition } from './lifecycle.js'\n\n/** The members of an Entity that play a part a CMS knows: by key. */\nexport interface RoleKeys<E extends AnyEntity> {\n /** What an entry is called in a list. A text field. */\n readonly label?: TextKey<E>\n /** The address a visitor reaches it by. A text field, unique in its table. */\n readonly slug?: TextKey<E>\n /**\n * Present means a visitor may see the row. A field that admits `null`. Without\n * it a content type cannot be unpublished, and every row is visible.\n */\n readonly published?: NullableKey<E>\n}\n\ntype TextKey<E extends AnyEntity> = {\n [K in keyof E['fields']]: [E['fields'][K]['schema']['Type']] extends [string] ? K : never\n}[keyof E['fields']] &\n string\n\ntype NullableKey<E extends AnyEntity> = {\n [K in keyof E['fields']]: null extends E['fields'][K]['schema']['Type'] ? K : never\n}[keyof E['fields']] &\n string\n\n/** The roles of an Entity, as its Fields. */\nexport interface Roles {\n readonly label: EntityField<string, string, Schema.Constraint> | undefined\n readonly slug: EntityField<string, string, Schema.Constraint> | undefined\n readonly published: EntityField<string, string, Schema.Constraint> | undefined\n}\n\nconst rolesKey = Metadata.key<Readonly<Record<string, string>>>('foldkit-cms/roles', {\n // Later roles add to earlier ones, and win where they name the same part.\n merge: roles => [Object.assign({}, ...roles) as Readonly<Record<string, string>>],\n summarize: roles => Object.keys(roles).join(','),\n})\n\nconst fail = (message: string): never => {\n throw new Error(`foldkit-cms: ${message}`)\n}\n\n/** An entry's id. Branded, so an entry is not opened with a post's id. */\nexport const EntryId = Schema.String.pipe(Schema.brand('CmsEntryId'))\nexport type EntryId = typeof EntryId.Type\n\nconst StateSchema = Schema.Struct({\n _tag: Schema.Literals(['New', 'Published', 'Changed', 'Unpublished', 'Archived']),\n schedule: Schema.NullOr(\n Schema.Struct({\n at: Schema.String,\n overdue: Schema.Boolean,\n error: Schema.NullOr(Schema.String),\n }),\n ),\n}).annotate({ title: 'State' })\n\n// A piece of content from its first keystroke to its archive: the thing an author\n// works on. It exists before the content row does, and after the row is hidden.\nconst Entry = Entity.define(\n 'CmsEntry',\n Schema.Struct({\n id: EntryId,\n /** The content type's name: `Cms.content('posts', ...)`. */\n type: Schema.String,\n /** The content row's id, once there is one. */\n targetId: Schema.NullOr(Schema.String),\n label: Schema.String.annotate({ title: 'Title' }),\n createdAt: Schema.String,\n archivedAt: Schema.NullOr(Schema.String),\n /** The number of the latest published revision: what the next publish is based on. */\n revision: Schema.NullOr(Schema.Number),\n }),\n).pipe(\n // Derived by the server, with its clock, so a list can show and filter by it;\n // `may` is what the principal reading it may do now, by the server's `allow`.\n Entity.derived({\n state: Derived.make(StateSchema),\n may: Derived.make(Schema.Array(Transitions)),\n }),\n // How a list or a detail shows them, with nothing said where it is declared.\n Entity.annotateMembers({\n // An entry's id is how it is opened, not something to read in a list.\n id: Display.of(Display.hidden()),\n state: Display.of(Kinds.Display.State.of({})),\n // An ISO-8601 instant, so code-point order is time order: said, so a\n // client places a created or renamed entry in a list as the server does.\n createdAt: Metadata.combine([\n Display.of(Kinds.Display.Moment.of({})),\n Collation.of(Collation.binary),\n ]),\n archivedAt: Display.of(Kinds.Display.Moment.of({})),\n }),\n)\n\n// The entry's one working copy: what an author has entered and not published.\nconst Draft = Entity.define(\n 'CmsDraft',\n Schema.Struct({\n /** The entry's id: an entry has at most one draft. */\n id: EntryId,\n /** The keys of the form's value that decode, as the operation's input encodes them. */\n values: Schema.Unknown,\n /** The form's whole Model, encoded: what resumes unfinished work. */\n model: Schema.Unknown,\n /** Which form made it, and at which version, so a Model is only resumed by the form that wrote it. */\n form: Schema.String,\n updatedAt: Schema.String,\n updatedBy: Schema.NullOr(Schema.String),\n /** The revision this draft was started from; publishing over a newer one is a conflict. */\n baseRevision: Schema.NullOr(Schema.Number),\n scheduledFor: Schema.NullOr(Schema.String),\n scheduleError: Schema.NullOr(Schema.String),\n }),\n)\n\n// A published value, kept. Append-only.\nconst Revision = Entity.define(\n 'CmsRevision',\n Schema.Struct({\n id: Schema.String,\n n: Schema.Number.annotate({ title: 'Revision' }),\n values: Schema.Unknown,\n publishedAt: Schema.String.annotate({ title: 'Published' }),\n publishedBy: Schema.NullOr(Schema.String),\n }),\n).pipe(Entity.annotateMembers({ publishedAt: Display.of(Kinds.Display.Moment.of({})) }))\n\nconst Entities = Entity.relate(\n { Entry, Draft, Revision },\n {\n Entry: {\n draft: Relation.one(Draft, { optional: true }),\n revisions: Relation.many(Revision),\n },\n },\n)\n\nconst entryInput = { entry: EntryId }\n\n/**\n * What an author may ask, as Remote mutations. They are the same for every\n * content type; the entry says which type it is. The server runs each after\n * asking the application's `allow`.\n */\n/**\n * Why a save or a publish is refused, as data: one key of the content's form\n * (a taken address, named by the content type's slug key, so the key is any\n * string here), or a conflict with work saved or published since.\n */\nconst RefusedField = Schema.TaggedStruct('Field', { key: Schema.String, reason: Schema.String })\nconst Refused = Schema.Union([RefusedField, Refusal.conflict])\n\n/** The values a server refuses a save or a publish with, for `RemoteServer.refuse`. */\nconst refusal = {\n /** One key of the content's form, and why, as text a form shows beside it. */\n field: (key: string, reason: string) => RefusedField.make({ key, reason }),\n conflict: Refusal.conflict.make({}),\n}\n\nconst Operations = {\n /**\n * Saves the working copy, valid or not. The first save of an id nobody has\n * makes the entry, so a client names something new itself (`Cms.newEntryId`) and\n * need not wait to be told what it is called. `basedOn` is the `updatedAt` this\n * save was made from: a newer one on the server is a conflict, not an overwrite.\n */\n SaveDraft: Mutation.make('CmsSaveDraft', {\n Input: {\n entry: EntryId,\n type: Schema.String,\n label: Schema.String,\n values: Schema.Unknown,\n model: Schema.Unknown,\n form: Schema.String,\n basedOn: Schema.NullOr(Schema.String),\n },\n Output: { entry: EntryId, updatedAt: Schema.String },\n Refusal: Refused,\n }),\n DiscardDraft: Mutation.make('CmsDiscardDraft', { Input: entryInput, Output: {} }),\n /**\n * Publishes the saved draft through the content type's own mutation. `basedOn`\n * is the revision the draft was started from.\n */\n Publish: Mutation.make('CmsPublish', {\n Input: { entry: EntryId, basedOn: Schema.NullOr(Schema.Number) },\n Output: { entry: EntryId, targetId: Schema.String, revision: Schema.Number },\n Refusal: Refused,\n }),\n Unpublish: Mutation.make('CmsUnpublish', { Input: entryInput, Output: {} }),\n Schedule: Mutation.make('CmsSchedule', {\n Input: { entry: EntryId, at: Schema.String },\n Output: {},\n }),\n Unschedule: Mutation.make('CmsUnschedule', { Input: entryInput, Output: {} }),\n Archive: Mutation.make('CmsArchive', { Input: entryInput, Output: {} }),\n Unarchive: Mutation.make('CmsUnarchive', { Input: entryInput, Output: {} }),\n /** Makes a revision's value the working copy. It publishes nothing. */\n Restore: Mutation.make('CmsRestore', {\n Input: { entry: EntryId, revision: Schema.Number },\n Output: { updatedAt: Schema.String },\n }),\n}\n\n/**\n * What an author works on: the entries of one content type, searched by what\n * they are called. `archived` chooses the put-away ones or the rest. It lists\n * entries, not content rows, so something never published is here too.\n */\n/**\n * The worklist: a content type's entries, archived or not, narrowed by a\n * search. Declared by what it means, so the server compiles it rather than\n * being told the same three questions again in SQL.\n *\n * Both of the conditions an author changes are asked without a branch, because\n * a body is built once and its inputs are placeholders. \"Archived or not\" is\n * *is-archived equals what you asked for*; \"search or everything\" is *the label\n * contains what you asked for*, and containing the empty string is everything.\n * `label` is not nullable, which is what makes the second of those exactly no\n * filter when the box is empty.\n */\nconst Entries = Query.define(\n 'CmsEntries',\n { type: Schema.String, search: Schema.String, archived: Schema.Boolean },\n ({ input }) =>\n Query.from(Entities.Entry).pipe(\n Query.where(\n Expr.eq(Entities.Entry.fields.type, input.type),\n Expr.eq(Expr.isNotNull(Entities.Entry.fields.archivedAt), input.archived),\n Expr.contains(Entities.Entry.fields.label, input.search),\n ),\n Query.orderBy(Order.desc(Entities.Entry.fields.createdAt)),\n ),\n)\n\n/** A form as a content type needs it: what it was made from, and what it edits. */\ninterface ContentForm<E extends AnyEntity, Value> {\n readonly name: string\n readonly input: EntityInput<E, any, any>\n readonly bundle: { readonly Model: Schema.Codec<any, unknown> }\n readonly initial: unknown\n readonly engine: { readonly value: (model: any) => Value | undefined }\n}\n\n/** How a type of content is authored: the application's facts, beside the Entity's roles. */\nexport interface Content<\n Name extends string,\n E extends AnyEntity,\n Value,\n TargetId extends string,\n F extends ContentForm<E, Value> = ContentForm<E, Value>,\n> {\n readonly name: Name\n readonly entity: E\n /** The form as it was given, so an editor of this content is typed by it. */\n readonly form: F\n readonly publish: {\n /** Makes the row, the first time. Its input is the form's value; its output names the row. */\n readonly create: MutationDescriptor<string, Value, { readonly id: TargetId }>\n /** Changes the row, every time after. Its input is the form's value and the row's id. */\n readonly update: MutationDescriptor<string, Value & { readonly id: TargetId }, any>\n }\n readonly roles: Roles\n readonly words: { readonly one: string; readonly many: string }\n /**\n * How a value of the form would look in the store: the operations an optimistic\n * publish of it would show. Declared, an author can preview what they have\n * entered in the application's own views; not declared, there is no preview.\n * `id` is the row's, or the entry's while there is no row yet.\n */\n readonly preview?:\n | ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>)\n | undefined\n}\n\nconst editor = makeEditor({ Entities, Operations })\n\n/**\n * Whether a row is published: its published role holds a value. One operator,\n * so a query, a guard and an invariant that ask it name the same question.\n */\nconst publishedOperator = Expr.operator('cms.published', {\n input: [Schema.Unknown],\n output: Schema.Boolean,\n description: 'Whether a row is published: its published role holds a value.',\n definedAs: publishedAt => Expr.isNotNull(publishedAt),\n})\n\nexport const Cms = {\n /**\n * A pipe step naming the members of an Entity that play a CMS part. It is\n * metadata: the Entity is the same Entity, and anything may read it with\n * `Cms.rolesOf`. A member that cannot play the part is refused here.\n */\n roles:\n <E extends AnyEntity>(roles: RoleKeys<NoInfer<E>>) =>\n (entity: E): E => {\n const given = roles as Readonly<Record<string, string | undefined>>\n const fields: Readonly<Record<string, EntityField<string, string, Schema.Constraint>>> =\n entity.fields\n for (const [role, key] of Object.entries(given)) {\n if (key === undefined) continue\n const field =\n fields[key] ??\n fail(`\"${key}\" is not a field of ${entity.name}, so it cannot be its ${role}`)\n const type = Schema.toType(field.schema as Schema.Top)\n if (role === 'published') {\n if (!Schema.is(type as Schema.Codec<unknown>)(null))\n fail(`\"${key}\" of ${entity.name} admits no null, so it cannot say a row is unpublished`)\n } else if (!SchemaShape.isText(type.ast)) {\n fail(`\"${key}\" of ${entity.name} is not text, so it cannot be its ${role}`)\n }\n }\n const named = Object.fromEntries(\n Object.entries(given).filter((entry): entry is [string, string] => entry[1] !== undefined),\n )\n return entity.pipe(Entity.annotate(rolesKey.of(named))) as E\n },\n\n /** The roles an Entity was given, as its Fields. A part nobody named is `undefined`. */\n rolesOf: (entity: AnyEntity): Roles => {\n const [named = {}] = rolesKey.get(entity.metadata)\n const fields: Readonly<Record<string, EntityField<string, string, Schema.Constraint>>> =\n entity.fields\n const field = (role: string) => (named[role] === undefined ? undefined : fields[named[role]])\n return { label: field('label'), slug: field('slug'), published: field('published') }\n },\n\n /**\n * Whether a row of `entity` is published: `cms.published` over the field its\n * `published` role names. Present means a visitor may see the row, so this is\n * the predicate a public query and a visitor's Read rule both ask. An Entity\n * with no published role is refused: every row of it is visible already.\n *\n * ```ts\n * Query.from(Post).pipe(Query.where(Cms.published(Post)))\n * guard.row(Post, () => Cms.published(Post))\n * ```\n */\n published: <E extends AnyEntity>(entity: E): TestPredicate & Reads<E['name']> => {\n const field = Cms.rolesOf(entity).published\n if (field === undefined) {\n throw new Error(\n `[foldkit-cms] Cms.published: ${entity.name} names no published role, so every row is visible`,\n )\n }\n return publishedOperator(field) as TestPredicate & Reads<E['name']>\n },\n\n /**\n * A type of content: the Entity it is, the form that edits it, the operations\n * that publish it, and what it is called. The form is an ordinary form; the\n * operations are the application's own. It adds no fields and generates nothing.\n */\n content: <\n const Name extends string,\n E extends AnyEntity,\n Value,\n TargetId extends string = string,\n F extends ContentForm<NoInfer<E>, Value> = ContentForm<NoInfer<E>, Value>,\n >(\n name: Name,\n config: {\n readonly entity: E\n readonly form: F & ContentForm<NoInfer<E>, Value>\n readonly publish: Content<Name, E, NoInfer<Value>, TargetId>['publish']\n readonly words: { readonly one: string; readonly many: string }\n readonly preview?: Content<Name, E, NoInfer<Value>, TargetId>['preview']\n },\n ): Content<Name, E, Value, TargetId, F> => {\n if (!Entity.same(config.form.input.entity, config.entity))\n fail(\n `content \"${name}\" is of ${config.entity.name}, but its form edits ${config.form.input.entity.name}`,\n )\n return Object.freeze({ name, ...config, roles: Cms.rolesOf(config.entity) })\n },\n\n /** An id for something new, made where it is written: the first save of it makes the entry. */\n newEntryId: (): EntryId => globalThis.crypto.randomUUID() as EntryId,\n /** `Entry`, `Draft` and `Revision`: register them with Remote beside the application's own. */\n Entities,\n /** The operations, to register with Remote's `mutations`. */\n Operations,\n operations: Object.values(Operations),\n /**\n * What a server refuses `SaveDraft` and `Publish` with: `refusal.field(key,\n * reason)` for one key of the content's form, `refusal.conflict` for work\n * saved or published since. An editor reads them with `Data.refusal`.\n */\n refusal,\n /** The worklist query, to register with Remote's `queries` and list with `Crud.list`. */\n Entries,\n /**\n * The query that finds a piece of content by its address: `<name>BySlug`, a\n * connection of one or none. It throws for a content type with no `slug` role:\n * a capability is declared, never implied.\n */\n bySlug: <Name extends string, E extends AnyEntity>(content: Content<Name, E, any, any, any>) => {\n const address = content.roles.slug\n if (address === undefined) {\n return fail(`content \"${content.name}\" has no slug role, so nothing is found by slug`)\n }\n const entity = content.entity as AnyEntity\n // Declared by what it means, so a server compiles the body instead of being\n // told the same `where` again in its own dialect. Ordered by id: one row is\n // expected, and a connection still pages on something stable.\n return Query.define(\n `${content.name}BySlug` as `${Name}BySlug`,\n { slug: Schema.String },\n ({ input }) =>\n Query.from(entity).pipe(\n Query.where(Expr.eq(address, input.slug)),\n Query.orderBy(Order.asc(entity.fields.id!)),\n ),\n ) as ReturnType<typeof Query.make<`${Name}BySlug`, { slug: typeof Schema.String }, E>>\n },\n /**\n * A form check that asks, while the author types, whether an address is already\n * used: `checks: { slug: Cms.addressFree('posts') }`. Named by the content type,\n * so a form can be made with it before the content type exists. It needs that\n * type's `bySlug` query registered, which `CmsServer` does for a content type\n * with a slug role.\n */\n addressFree,\n\n /**\n * The displays a CMS adds, and a renderer for each: `Cms.Display.State` and\n * `Cms.Display.Moment` for a list's columns, `Cms.displayRenderers()` to spread\n * beside the mixins' own. A slug and a moment are `foldkit-form-recipes`'\n * `FieldRecipes.slug` and `FieldRecipes.dateTime`.\n */\n ...Kinds,\n\n /**\n * The authoring editor of a content type: its form, the entry, and the draft\n * that keeps what the author has entered. Saving is automatic and is not\n * publishing; publishing submits the form.\n */\n editor,\n /** A form's Submodel view as its editor's, for `Bundle.withView`. */\n editorView,\n\n /**\n * The entry-level views every studio draws, on its own slot builders: its\n * state badge, its published revisions, what was published, and the rest of\n * what can happen to it. Words for states come from `Cms.Display`, so a\n * studio and its lists say them one way.\n */\n stateBadge,\n /**\n * The attribute every state the CMS draws is written in, `data-cms-state`:\n * a badge's tone rules select on it, `[${Cms.stateAttribute}=\"Published\"]`.\n */\n stateAttribute,\n /** Whether the entry's state is one of the given tags; no state yet is none of them. */\n stateIs,\n revisionsOf,\n historyCard,\n moreCard,\n\n /** The state of an entry, from what is known of it and a clock. */\n state: (facts: Facts, now: Date): State => state(facts, now),\n /** Every transition an author may ask, in order: what `allow` is asked about. */\n transitions: Transitions.literals,\n /** The transitions an entry offers now, before anyone asks who is asking. */\n offers: (\n facts: Facts,\n now: Date,\n content: { readonly roles: Roles },\n ): ReadonlyArray<Transition> =>\n offers(facts, now, { unpublishes: content.roles.published !== undefined }),\n}\n\nexport type {\n EditorContent,\n EditorMessage,\n EditorDomain,\n EditorForm,\n EditorModel,\n EditorOut,\n EditorStatus,\n Resumed,\n} from './editor.js'\nexport type { DisplayContext, StateWords } from './kinds.js'\nexport type { HistoryCardSlots, MoreCardSlots, RevisionHistory, RevisionRow } from './views.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,cAAc,OAAO,SAAS;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAMA,gBAAc,OAAuB,QACzC,UAAU,QAAQ,MAAM,iBAAiB,OACrC,OACA;CACE,IAAI,MAAM;CACV,SAAS,IAAI,KAAK,MAAM,YAAY,CAAC,CAAC,QAAQ,KAAK,IAAI,QAAQ;CAC/D,OA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AM,UAAU,QAAQ,MAAM;EAC9B,IAAI,YAAY,KAAA,GACd,OAAO,KAAK,YAAY,QAAQ,KAAK,gDAAgD;EAEvF,MAAM,SAAS,QAAQ;EAIvB,OAAO,MAAM,OACX,GAAG,QAAQ,KAAK,SAChB,EAAE,MAAM,OAAO,OAAO,IACrB,EAAE,YACD,MAAM,KAAK,MAAM,CAAC,CAAC,KACjB,MAAM,MAAM,KAAK,GAAG,SAAS,MAAM,IAAI,CAAC,GACxC,MAAM,QAAQ,MAAM,IAAI,OAAO,OAAO,EAAG,CAAC,CAC5C,CACJ;CACF;;;;;;;;CAQA;;;;;;;CAQA,GAAG;;;;;;CAOH;;CAEA;;;;;;;CAQA;;;;;CAKA;;CAEA;CACA;CACA;CACA;;CAGA,QAAQ,OAAc,QAAqB,MAAM,OAAO,GAAG;;CAE3D,aAAa,YAAY;;CAEzB,SACE,OACA,KACA,YAEA,OAAO,OAAO,KAAK,EAAE,aAAa,QAAQ,MAAM,cAAc,KAAA,EAAU,CAAC;AAC7E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit-cms",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "What a CMS adds to a Foldkit Plus domain: audience, time, and address. A draft is an unsent form kept beside the content row; state is derived, never stored. Entry history and transitions ship as view helpers.",
5
5
  "keywords": [
6
6
  "foldkit",
@@ -39,14 +39,14 @@
39
39
  "LICENSE"
40
40
  ],
41
41
  "dependencies": {
42
- "foldkit-bundle": "0.11.0",
43
- "foldkit-crud": "0.14.0",
44
- "foldkit-form": "0.11.0",
45
- "foldkit-remote": "0.24.0",
42
+ "foldkit-bundle": "0.12.0",
43
+ "foldkit-crud": "0.15.0",
44
+ "foldkit-form": "0.12.0",
46
45
  "foldkit-metadata": "0.1.0",
47
- "foldkit-entity": "0.16.0",
48
- "foldkit-surface": "0.13.0",
49
- "foldkit-mixins": "0.23.0"
46
+ "foldkit-mixins": "0.24.0",
47
+ "foldkit-entity": "0.17.0",
48
+ "foldkit-remote": "0.25.0",
49
+ "foldkit-surface": "0.14.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "effect": "^4.1.0",
@@ -58,9 +58,9 @@
58
58
  "foldkit": "0.170.0",
59
59
  "tsdown": "^0.23.1",
60
60
  "typescript": "7.0.2",
61
- "foldkit-form-recipes": "0.4.0",
62
- "foldkit-mixins-crud": "0.12.0",
63
- "foldkit-mixins-form": "0.13.0"
61
+ "foldkit-mixins-crud": "0.13.0",
62
+ "foldkit-mixins-form": "0.14.0",
63
+ "foldkit-form-recipes": "0.5.0"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",