foldkit-cms 0.7.12 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -11
- package/dist/index.d.mts +16 -51
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +43 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -225,26 +225,33 @@ PostEditor.storedEntry(model) // Option: the entry the server knows, none until
|
|
|
225
225
|
|
|
226
226
|
## Kinds, and how they are drawn
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
An entry's address and its publish time are
|
|
229
|
+
[`foldkit-form-recipes`](../form-recipes/README.md)' `slug` and `dateTime`; the CMS
|
|
230
|
+
adds two displays, made with `Display.kind` exactly as you make your own. There is
|
|
231
|
+
no CMS view package: a kind and its renderer are all a view needs.
|
|
231
232
|
|
|
232
233
|
```ts
|
|
234
|
+
import { FieldRecipes } from 'foldkit-form-recipes'
|
|
235
|
+
import { renderers } from 'foldkit-form-recipes/html'
|
|
236
|
+
|
|
233
237
|
const PostForm = Form.make('PostForm', Entity.input(Post, PostInput), {
|
|
234
238
|
inputs: {
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
// follows the title until the author writes it
|
|
240
|
+
slug: FieldRecipes.slug('title', { prefix: '/blog/' }).control,
|
|
241
|
+
// a datetime-local input, read in London, submitted as an ISO instant
|
|
242
|
+
goesLiveAt: FieldRecipes.dateTime({ stored: 'instant', zone: 'Europe/London' }).control,
|
|
237
243
|
},
|
|
238
244
|
})
|
|
239
245
|
|
|
240
|
-
FormView.define(PostForm, { renderers:
|
|
246
|
+
FormView.define(PostForm, { renderers: renderers() })
|
|
241
247
|
EntryTable({ page, renderers: Cms.displayRenderers() }, h)
|
|
242
248
|
```
|
|
243
249
|
|
|
250
|
+
A slug follows its title until the author writes it, and a form filled with a
|
|
251
|
+
published slug does not follow: an address must not move because its title did.
|
|
252
|
+
|
|
244
253
|
| Kind | What it is |
|
|
245
254
|
| --- | --- |
|
|
246
|
-
| `Cms.Input.Slug` | Text shown after the address it completes. `Cms.slug(from, { prefix?, through? })` makes one that follows `from` through `Cms.slugify`. A form filled with a published slug does not follow: an address must not move because its title did. Drawn as the prefix in `FieldSlots.affix` and the input in `text`, together in `group`. |
|
|
247
|
-
| `Cms.Input.DateTime` | A moment. Text that is none is `Invalid`, not submitted. |
|
|
248
255
|
| `Cms.Display.State` | An entry's state as words: `Changed, scheduled`, `New, overdue`. `of({ words })` takes yours, text with blanks as every words object is: each state, `scheduled`, `overdue`, and `withSchedule` (`'{state}, {schedule}'`). Its renderer is a `span` with `data-cms-state` and `data-cms-schedule` to style. |
|
|
249
256
|
| `Cms.Display.Moment` | A time. `of({ now })` reads relative to that clock (`3 days ago`), and you decide how often it moves; without one it is the date and time. Its renderer is a `time`. |
|
|
250
257
|
|
|
@@ -292,13 +299,13 @@ nobody has makes the entry, so an editor need not wait to learn what it edits.
|
|
|
292
299
|
| --- | --- |
|
|
293
300
|
| `Cms.roles({ label?, slug?, published? })` | Pipe step: the members of an Entity that play a CMS part. |
|
|
294
301
|
| `Cms.rolesOf(entity)` | Those roles, as Fields; `undefined` for a part nobody named. |
|
|
302
|
+
| `Cms.published(entity)` | Whether a row is published, as a predicate: the operator `cms.published` over the `published` role's field, for a public query and a visitor's Read rule alike. Throws with no `published` role. |
|
|
295
303
|
| `Cms.content(name, { entity, form, publish, words, preview? })` | A type of content: its Entity, form, publish operations, and name. |
|
|
296
304
|
| `Cms.editor(name, { content, rest?, version?, untitled? })` | The authoring editor: `bundle`, `Message`, and `at({ data, model })`. |
|
|
297
305
|
| `Cms.newEntryId()` | An id for something new. |
|
|
298
306
|
| `Cms.editorView(view)` | A form's Submodel view as its editor's, for `Bundle.withView`. |
|
|
299
|
-
| `Cms.
|
|
300
|
-
| `Cms.
|
|
301
|
-
| `Cms.controlRenderers()`, `Cms.displayRenderers()` | Their renderers, to spread beside the mixins' own. |
|
|
307
|
+
| `Cms.Display.{State, Moment}` | The display kinds: `.of(data)`, `.is(x)`. |
|
|
308
|
+
| `Cms.displayRenderers()` | Their renderers, to spread beside the mixins' own. |
|
|
302
309
|
| `Cms.state(facts, now)` | The state of an entry, with its schedule. |
|
|
303
310
|
| `Cms.offers(facts, now, content)` | The transitions it offers now. |
|
|
304
311
|
| `Cms.Entities`, `Cms.Operations`, `Cms.operations` | The CMS's own Entities and mutations. |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { Effect, Option, Schema } from "effect";
|
|
2
|
-
import { AnyEntity, Entity, EntityField, EntityInput } from "foldkit-entity";
|
|
2
|
+
import { AnyEntity, Entity, EntityField, EntityInput, Reads, TestPredicate } from "foldkit-entity";
|
|
3
3
|
import { MutationDescriptor, MutationStatus, OptimisticOperation, RemoteClient, RemoteData, RemoteMessage } from "foldkit-remote";
|
|
4
4
|
import { Bundle } from "foldkit-bundle";
|
|
5
5
|
import * as Subscription from "foldkit/subscription";
|
|
6
6
|
import * as Submodel from "foldkit/submodel";
|
|
7
7
|
import { DisplayWords } from "foldkit-crud";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Submitted } from "foldkit-form";
|
|
9
|
+
import { Html, HtmlBuilder } from "foldkit/html";
|
|
10
10
|
import { ActiveSurface, Projection } from "foldkit-surface";
|
|
11
11
|
import { Command } from "foldkit/command";
|
|
12
12
|
import * as FieldValidation from "foldkit/fieldValidation";
|
|
13
13
|
import * as Update from "foldkit/update";
|
|
14
14
|
import { SlotView } from "foldkit-mixins";
|
|
15
|
-
//#region src/kinds.d.ts
|
|
16
|
-
/** Text as an address: lower case, unaccented, words joined by `-`. */
|
|
17
|
-
declare const slugify: (text: string) => string;
|
|
18
15
|
interface StateWords {
|
|
19
16
|
readonly New?: string;
|
|
20
17
|
readonly Published?: string;
|
|
@@ -26,26 +23,6 @@ interface StateWords {
|
|
|
26
23
|
/** A state with what its schedule adds: `{state}` and `{schedule}`. */
|
|
27
24
|
readonly withSchedule?: string;
|
|
28
25
|
}
|
|
29
|
-
/** What `foldkit-mixins-form` gives a control's renderer, as far as these read it. */
|
|
30
|
-
interface ControlContext<Message> {
|
|
31
|
-
readonly control: Control;
|
|
32
|
-
readonly draft: Draft;
|
|
33
|
-
readonly change: (value: Draft) => Message;
|
|
34
|
-
readonly blurred: Message;
|
|
35
|
-
readonly state: ReadonlyArray<Attribute<Message>>;
|
|
36
|
-
readonly slots: {
|
|
37
|
-
readonly text: {
|
|
38
|
-
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
39
|
-
};
|
|
40
|
-
readonly group: {
|
|
41
|
-
readonly attrs: () => any;
|
|
42
|
-
};
|
|
43
|
-
readonly affix: {
|
|
44
|
-
readonly attrs: () => any;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
readonly h: HtmlBuilder<Message>;
|
|
48
|
-
}
|
|
49
26
|
/** What `foldkit-mixins-crud` gives a display's renderer, as far as these read it. */
|
|
50
27
|
interface DisplayContext<Message> {
|
|
51
28
|
readonly display: {
|
|
@@ -59,8 +36,6 @@ interface DisplayContext<Message> {
|
|
|
59
36
|
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
60
37
|
};
|
|
61
38
|
}
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/lifecycle.d.ts
|
|
64
39
|
/** What is known of one entry. The server gathers it; nothing here reads a database. */
|
|
65
40
|
interface Facts {
|
|
66
41
|
/** When the entry was archived, if it was. */
|
|
@@ -98,8 +73,6 @@ interface State {
|
|
|
98
73
|
/** What an author may ask of an entry. Each is an operation the server runs after asking `allow`. */
|
|
99
74
|
declare const Transitions: Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>;
|
|
100
75
|
type Transition = typeof Transitions.Type;
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/editor.d.ts
|
|
103
76
|
/** How the form came to hold what it holds. */
|
|
104
77
|
type Resumed =
|
|
105
78
|
/** The draft's saved Model: the form exactly as it was left, errors and all. */
|
|
@@ -296,8 +269,6 @@ type EditorMessage = typeof EditorMessage.Type;
|
|
|
296
269
|
* ```
|
|
297
270
|
*/
|
|
298
271
|
declare const editorView: <FormModel, FormMessage, ViewInputs>(view: Submodel.View<FormModel, FormMessage, ViewInputs>) => Submodel.View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>;
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/views.d.ts
|
|
301
272
|
/** Whether the entry's state is one of `tags`; an entry with no state yet is none of them. */
|
|
302
273
|
declare const stateIs: (state: Option.Option<State>, ...tags: ReadonlyArray<State['_tag']>) => boolean;
|
|
303
274
|
/**
|
|
@@ -397,8 +368,6 @@ declare const moreCard: <M>(slots: MoreCardSlots<M>, h: HtmlBuilder<M>, entry: {
|
|
|
397
368
|
};
|
|
398
369
|
readonly archiveIcon: Html;
|
|
399
370
|
}) => ReadonlyArray<Html>;
|
|
400
|
-
//#endregion
|
|
401
|
-
//#region src/slug.d.ts
|
|
402
371
|
/**
|
|
403
372
|
* A form check that says, while the author types, what a publish would refuse:
|
|
404
373
|
* this address belongs to something else. It asks the content type's `bySlug`
|
|
@@ -420,8 +389,6 @@ declare const moreCard: <M>(slots: MoreCardSlots<M>, h: HtmlBuilder<M>, entry: {
|
|
|
420
389
|
declare const addressFree: (content: string) => ((slug: string, context: {
|
|
421
390
|
readonly subject: Readonly<Record<string, string>>;
|
|
422
391
|
}) => Effect.Effect<string | undefined, never, RemoteClient>);
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/index.d.ts
|
|
425
392
|
/** The members of an Entity that play a part a CMS knows: by key. */
|
|
426
393
|
export interface RoleKeys<E extends AnyEntity> {
|
|
427
394
|
/** What an entry is called in a list. A text field. */
|
|
@@ -487,12 +454,6 @@ export interface Content<Name extends string, E extends AnyEntity, Value, Target
|
|
|
487
454
|
readonly preview?: ((value: Partial<Value>, id: string) => ReadonlyArray<OptimisticOperation>) | undefined;
|
|
488
455
|
}
|
|
489
456
|
export declare const Cms: {
|
|
490
|
-
Input: {
|
|
491
|
-
Slug: import("foldkit-form").ControlKind<{
|
|
492
|
-
readonly prefix: string;
|
|
493
|
-
}>;
|
|
494
|
-
DateTime: import("foldkit-form").ControlKind<Record<string, never>>;
|
|
495
|
-
};
|
|
496
457
|
Display: {
|
|
497
458
|
State: import("foldkit-crud").DisplayKind<{
|
|
498
459
|
readonly words?: StateWords | undefined;
|
|
@@ -502,13 +463,6 @@ export declare const Cms: {
|
|
|
502
463
|
readonly locale?: string | undefined;
|
|
503
464
|
}>;
|
|
504
465
|
};
|
|
505
|
-
slugify: typeof slugify;
|
|
506
|
-
slug: (from: string, options?: {
|
|
507
|
-
readonly prefix?: string;
|
|
508
|
-
readonly through?: (text: string) => string;
|
|
509
|
-
}) => import("foldkit-form").ControlChange;
|
|
510
|
-
dateTime: () => import("foldkit-form").Control;
|
|
511
|
-
controlRenderers: <Message>() => Readonly<Record<string, (context: ControlContext<Message>) => import("foldkit/html").Html>>;
|
|
512
466
|
displayRenderers: <Message>() => Readonly<Record<string, (context: DisplayContext<Message>) => import("foldkit/html").Html>>;
|
|
513
467
|
/**
|
|
514
468
|
* A pipe step naming the members of an Entity that play a CMS part. It is
|
|
@@ -518,6 +472,18 @@ export declare const Cms: {
|
|
|
518
472
|
roles: <E extends AnyEntity>(roles: RoleKeys<NoInfer<E>>) => (entity: E) => E;
|
|
519
473
|
/** The roles an Entity was given, as its Fields. A part nobody named is `undefined`. */
|
|
520
474
|
rolesOf: (entity: AnyEntity) => Roles;
|
|
475
|
+
/**
|
|
476
|
+
* Whether a row of `entity` is published: `cms.published` over the field its
|
|
477
|
+
* `published` role names. Present means a visitor may see the row, so this is
|
|
478
|
+
* the predicate a public query and a visitor's Read rule both ask. An Entity
|
|
479
|
+
* with no published role is refused: every row of it is visible already.
|
|
480
|
+
*
|
|
481
|
+
* ```ts
|
|
482
|
+
* Query.from(Post).pipe(Query.where(Cms.published(Post)))
|
|
483
|
+
* guard.row(Post, () => Cms.published(Post))
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
published: <E extends AnyEntity>(entity: E) => TestPredicate & Reads<E['name']>;
|
|
521
487
|
/**
|
|
522
488
|
* A type of content: the Entity it is, the form that edits it, the operations
|
|
523
489
|
* that publish it, and what it is called. The form is an ordinary form; the
|
|
@@ -1124,6 +1090,5 @@ export declare const Cms: {
|
|
|
1124
1090
|
readonly roles: Roles;
|
|
1125
1091
|
}) => ReadonlyArray<Transition>;
|
|
1126
1092
|
};
|
|
1127
|
-
|
|
1128
|
-
export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, HistoryCardSlots, MoreCardSlots, Resumed, RevisionHistory, RevisionRow, Schedule, State, StateTag, StateWords, Transition };
|
|
1093
|
+
export type { DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, HistoryCardSlots, MoreCardSlots, Resumed, RevisionHistory, RevisionRow, Schedule, State, StateTag, StateWords, Transition };
|
|
1129
1094
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["_$__kinds_js0.StateWords","_$__kinds_js0.
|
|
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;;;UAmEM,eAAe;WACrB;aACE;aACA,OAAO,gBA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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
|
@@ -8,8 +8,8 @@ import { defineMessageUnion } from "foldkit/message";
|
|
|
8
8
|
import * as Subscription from "foldkit/subscription";
|
|
9
9
|
import * as Submodel from "foldkit/submodel";
|
|
10
10
|
import { Display } from "foldkit-crud";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import { fillWords } from "foldkit-form";
|
|
12
|
+
// src/lifecycle.ts
|
|
13
13
|
/**
|
|
14
14
|
* The lifecycle of a piece of content, derived. Nothing stores a status: a state
|
|
15
15
|
* is a pure function of facts (is there a row, can a visitor see it, is there a
|
|
@@ -76,8 +76,7 @@ const offers = (facts, now, capabilities) => {
|
|
|
76
76
|
"archive"
|
|
77
77
|
];
|
|
78
78
|
};
|
|
79
|
-
|
|
80
|
-
//#region src/editor.ts
|
|
79
|
+
// src/editor.ts
|
|
81
80
|
/**
|
|
82
81
|
* The authoring editor: a form, the entry it belongs to, and the draft that
|
|
83
82
|
* keeps what the author has entered.
|
|
@@ -749,12 +748,11 @@ const makeEditor = (cms) => (name, config) => {
|
|
|
749
748
|
}
|
|
750
749
|
};
|
|
751
750
|
};
|
|
752
|
-
|
|
753
|
-
//#region src/kinds.ts
|
|
751
|
+
// src/kinds.ts
|
|
754
752
|
/**
|
|
755
|
-
* The
|
|
756
|
-
*
|
|
757
|
-
*
|
|
753
|
+
* The displays a CMS adds, made with `Display.kind` exactly as an application
|
|
754
|
+
* makes its own, and a renderer for each to spread beside `foldkit-mixins-crud`'s.
|
|
755
|
+
* Its controls, a slug and a moment, are `foldkit-form-recipes`'.
|
|
758
756
|
* Entry-level views (its state badge, published history, remaining
|
|
759
757
|
* transitions) live in `./views.js`: they draw on the application's own slot
|
|
760
758
|
* builders, so the application keeps its slots and styles.
|
|
@@ -764,19 +762,6 @@ const makeEditor = (cms) => (name, config) => {
|
|
|
764
762
|
* list's state cell, `stateBadge`): one name, so one tone rule styles both.
|
|
765
763
|
*/
|
|
766
764
|
const stateAttribute = "data-cms-state";
|
|
767
|
-
/** Text as an address: lower case, unaccented, words joined by `-`. */
|
|
768
|
-
const slugify = (text) => text.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
769
|
-
/** A slug: text, shown after the address it completes. */
|
|
770
|
-
const Slug = Input.kind("CmsSlug", { draft: "text" });
|
|
771
|
-
/** A moment: the text of a `datetime-local` input, submitted as an ISO string. */
|
|
772
|
-
const DateTime = Input.kind("CmsDateTime", {
|
|
773
|
-
draft: "text",
|
|
774
|
-
parse: (draft) => {
|
|
775
|
-
const at = new Date(draft);
|
|
776
|
-
return Number.isNaN(at.getTime()) ? void 0 : at.toISOString();
|
|
777
|
-
},
|
|
778
|
-
unparsed: "Enter a date and a time"
|
|
779
|
-
});
|
|
780
765
|
const stateWords = {
|
|
781
766
|
New: "New",
|
|
782
767
|
Published: "Published",
|
|
@@ -827,63 +812,19 @@ const Moment = Display.kind("CmsMoment", { text: (data, value) => {
|
|
|
827
812
|
const unit = units.find(([, size]) => Math.abs(delta) >= size);
|
|
828
813
|
return unit === void 0 ? relative.format(0, "minute") : relative.format(Math.trunc(delta / unit[1]), unit[0]);
|
|
829
814
|
} });
|
|
830
|
-
/** An ISO moment as a `datetime-local` input writes one, in the viewer's zone; other text as it is. */
|
|
831
|
-
const localText = (draft) => {
|
|
832
|
-
const at = new Date(draft);
|
|
833
|
-
if (!/Z$|[+-]\d\d:\d\d$/.test(draft) || Number.isNaN(at.getTime())) return draft;
|
|
834
|
-
return (/* @__PURE__ */ new Date(at.getTime() - at.getTimezoneOffset() * 6e4)).toISOString().slice(0, 16);
|
|
835
|
-
};
|
|
836
815
|
const Kinds = {
|
|
837
|
-
/** The control kinds: `Cms.Input.Slug.is(control)` narrows one, as `Input.Text.is` does. */
|
|
838
|
-
Input: {
|
|
839
|
-
Slug,
|
|
840
|
-
DateTime
|
|
841
|
-
},
|
|
842
816
|
/** The display kinds. */
|
|
843
817
|
Display: {
|
|
844
818
|
State: StateDisplay,
|
|
845
819
|
Moment
|
|
846
820
|
},
|
|
847
|
-
slugify,
|
|
848
|
-
/**
|
|
849
|
-
* Under a form's `inputs`: the key is a slug that follows `from` until the
|
|
850
|
-
* author writes it, and is shown after `prefix`. A form filled with a published
|
|
851
|
-
* slug does not follow: an address must not move because its title did.
|
|
852
|
-
*/
|
|
853
|
-
slug: (from, options = {}) => ({ change: (resolved, inputKey) => {
|
|
854
|
-
const following = Input.following(from, options.through ?? slugify).change(resolved, inputKey);
|
|
855
|
-
return Object.freeze({
|
|
856
|
-
...Slug.of({ prefix: options.prefix ?? "/" }),
|
|
857
|
-
follows: following.follows
|
|
858
|
-
});
|
|
859
|
-
} }),
|
|
860
|
-
/** Under a form's `inputs`, or as Entity metadata with `Input.of`: a moment. */
|
|
861
|
-
dateTime: () => DateTime.of({}),
|
|
862
|
-
/** For `FormView`'s `renderers`, beside its own. */
|
|
863
|
-
controlRenderers: () => ({
|
|
864
|
-
[Slug.kind]: ({ control, state, draft, change, blurred, slots, h }) => h.div(slots.group.attrs(), [h.span(slots.affix.attrs(), [Slug.is(control) ? control.data.prefix : ""]), h.input(slots.text.attrs([
|
|
865
|
-
...state,
|
|
866
|
-
h.Type("text"),
|
|
867
|
-
h.Value(String(draft)),
|
|
868
|
-
h.OnInput(change),
|
|
869
|
-
h.OnBlur(blurred)
|
|
870
|
-
]))]),
|
|
871
|
-
[DateTime.kind]: ({ state, draft, change, blurred, slots, h }) => h.input(slots.text.attrs([
|
|
872
|
-
...state,
|
|
873
|
-
h.Type("datetime-local"),
|
|
874
|
-
h.Value(localText(String(draft))),
|
|
875
|
-
h.OnInput(change),
|
|
876
|
-
h.OnBlur(blurred)
|
|
877
|
-
]))
|
|
878
|
-
}),
|
|
879
821
|
/** For `ListView`'s and `DetailView`'s `renderers`: a state as a badge, a moment as a `time`. */
|
|
880
822
|
displayRenderers: () => ({
|
|
881
823
|
[StateDisplay.kind]: ({ display, value, words, h, badge }) => h.span(badge.attrs(isState(value) ? [h.Attribute(stateAttribute, value._tag), ...scheduleOf(value) === void 0 ? [] : [h.DataAttribute("cms-schedule", scheduleOf(value))]] : []), [display.text(value, words)]),
|
|
882
824
|
[Moment.kind]: ({ display, value, words, h }) => h.time([h.Attribute("datetime", String(value))], [display.text(value, words)])
|
|
883
825
|
})
|
|
884
826
|
};
|
|
885
|
-
|
|
886
|
-
//#region src/views.ts
|
|
827
|
+
// src/views.ts
|
|
887
828
|
/**
|
|
888
829
|
* The entry-level views every CMS studio draws: its state badge, its
|
|
889
830
|
* published revisions, and what can still happen to it. An application passes
|
|
@@ -987,8 +928,7 @@ const moreCard = (slots, h, entry) => {
|
|
|
987
928
|
stateIs(state, "Archived") ? action("unarchive", "Unarchive", asks.unarchive) : h.button(slots.danger.attrs([h.Id("archive"), h.OnClick(asks.archive)]), [entry.archiveIcon, "Archive"])
|
|
988
929
|
])])];
|
|
989
930
|
};
|
|
990
|
-
|
|
991
|
-
//#region src/slug.ts
|
|
931
|
+
// src/slug.ts
|
|
992
932
|
/**
|
|
993
933
|
* A form check that says, while the author types, what a publish would refuse:
|
|
994
934
|
* this address belongs to something else. It asks the content type's `bySlug`
|
|
@@ -1014,8 +954,7 @@ const addressFree = (content) => {
|
|
|
1014
954
|
});
|
|
1015
955
|
return (slug, context) => Remote.query(descriptor.ref({ slug })).pipe(Effect.map((result) => result.edges.some((edge) => edge.id !== context.subject.id) ? `"${slug}" is already used` : void 0), Effect.orElseSucceed(() => void 0));
|
|
1016
956
|
};
|
|
1017
|
-
|
|
1018
|
-
//#region src/index.ts
|
|
957
|
+
// src/index.ts
|
|
1019
958
|
/**
|
|
1020
959
|
* `foldkit-cms` — what a CMS adds to a domain that is already declared: audience
|
|
1021
960
|
* (who may see it), time (drafts, revisions, a schedule), and address (a slug).
|
|
@@ -1069,7 +1008,7 @@ const Entry = Entity.define("CmsEntry", Schema.Struct({
|
|
|
1069
1008
|
createdAt: Metadata.combine([Display.of(Kinds.Display.Moment.of({})), Collation.of(Collation.binary)]),
|
|
1070
1009
|
archivedAt: Display.of(Kinds.Display.Moment.of({}))
|
|
1071
1010
|
}));
|
|
1072
|
-
const Draft
|
|
1011
|
+
const Draft = Entity.define("CmsDraft", Schema.Struct({
|
|
1073
1012
|
/** The entry's id: an entry has at most one draft. */
|
|
1074
1013
|
id: EntryId,
|
|
1075
1014
|
/** The keys of the form's value that decode, as the operation's input encodes them. */
|
|
@@ -1094,10 +1033,10 @@ const Revision = Entity.define("CmsRevision", Schema.Struct({
|
|
|
1094
1033
|
})).pipe(Entity.annotateMembers({ publishedAt: Display.of(Kinds.Display.Moment.of({})) }));
|
|
1095
1034
|
const Entities = Entity.relate({
|
|
1096
1035
|
Entry,
|
|
1097
|
-
Draft
|
|
1036
|
+
Draft,
|
|
1098
1037
|
Revision
|
|
1099
1038
|
}, { Entry: {
|
|
1100
|
-
draft: Relation.one(Draft
|
|
1039
|
+
draft: Relation.one(Draft, { optional: true }),
|
|
1101
1040
|
revisions: Relation.many(Revision)
|
|
1102
1041
|
} });
|
|
1103
1042
|
const entryInput = { entry: EntryId };
|
|
@@ -1226,6 +1165,16 @@ const editor = makeEditor({
|
|
|
1226
1165
|
Entities,
|
|
1227
1166
|
Operations
|
|
1228
1167
|
});
|
|
1168
|
+
/**
|
|
1169
|
+
* Whether a row is published: its published role holds a value. One operator,
|
|
1170
|
+
* so a query, a guard and an invariant that ask it name the same question.
|
|
1171
|
+
*/
|
|
1172
|
+
const publishedOperator = Expr.operator("cms.published", {
|
|
1173
|
+
input: [Schema.Unknown],
|
|
1174
|
+
output: Schema.Boolean,
|
|
1175
|
+
description: "Whether a row is published: its published role holds a value.",
|
|
1176
|
+
definedAs: (publishedAt) => Expr.isNotNull(publishedAt)
|
|
1177
|
+
});
|
|
1229
1178
|
const Cms = {
|
|
1230
1179
|
/**
|
|
1231
1180
|
* A pipe step naming the members of an Entity that play a CMS part. It is
|
|
@@ -1258,6 +1207,22 @@ const Cms = {
|
|
|
1258
1207
|
};
|
|
1259
1208
|
},
|
|
1260
1209
|
/**
|
|
1210
|
+
* Whether a row of `entity` is published: `cms.published` over the field its
|
|
1211
|
+
* `published` role names. Present means a visitor may see the row, so this is
|
|
1212
|
+
* the predicate a public query and a visitor's Read rule both ask. An Entity
|
|
1213
|
+
* with no published role is refused: every row of it is visible already.
|
|
1214
|
+
*
|
|
1215
|
+
* ```ts
|
|
1216
|
+
* Query.from(Post).pipe(Query.where(Cms.published(Post)))
|
|
1217
|
+
* guard.row(Post, () => Cms.published(Post))
|
|
1218
|
+
* ```
|
|
1219
|
+
*/
|
|
1220
|
+
published: (entity) => {
|
|
1221
|
+
const field = Cms.rolesOf(entity).published;
|
|
1222
|
+
if (field === void 0) throw new Error(`[foldkit-cms] Cms.published: ${entity.name} names no published role, so every row is visible`);
|
|
1223
|
+
return publishedOperator(field);
|
|
1224
|
+
},
|
|
1225
|
+
/**
|
|
1261
1226
|
* A type of content: the Entity it is, the form that edits it, the operations
|
|
1262
1227
|
* that publish it, and what it is called. The form is an ordinary form; the
|
|
1263
1228
|
* operations are the application's own. It adds no fields and generates nothing.
|
|
@@ -1305,10 +1270,10 @@ const Cms = {
|
|
|
1305
1270
|
*/
|
|
1306
1271
|
addressFree,
|
|
1307
1272
|
/**
|
|
1308
|
-
* The
|
|
1309
|
-
* `Cms.
|
|
1310
|
-
*
|
|
1311
|
-
*
|
|
1273
|
+
* The displays a CMS adds, and a renderer for each: `Cms.Display.State` and
|
|
1274
|
+
* `Cms.Display.Moment` for a list's columns, `Cms.displayRenderers()` to spread
|
|
1275
|
+
* beside the mixins' own. A slug and a moment are `foldkit-form-recipes`'
|
|
1276
|
+
* `FieldRecipes.slug` and `FieldRecipes.dateTime`.
|
|
1312
1277
|
*/
|
|
1313
1278
|
...Kinds,
|
|
1314
1279
|
/**
|
|
@@ -1343,7 +1308,6 @@ const Cms = {
|
|
|
1343
1308
|
/** The transitions an entry offers now, before anyone asks who is asking. */
|
|
1344
1309
|
offers: (facts, now, content) => offers(facts, now, { unpublishes: content.roles.published !== void 0 })
|
|
1345
1310
|
};
|
|
1346
|
-
//#endregion
|
|
1347
1311
|
export { Cms, EntryId };
|
|
1348
1312
|
|
|
1349
1313
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["scheduleOf","Draft"],"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 type { ActiveSurface, ModelRef, 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: { readonly key: never; readonly error: string }) => 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> {\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 overlay(model: Root, id: string, optimistic: ReadonlyArray<OptimisticOperation>): Root\n lift(model: Root, id: string): Root\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, model: slice } = where\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 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 data.lift(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 = data.overlay(\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 if (content.roles.slug?.key !== key) 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({ key: key as never, error: reason }),\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' && fresh(read(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 kinds a CMS adds: two controls and two displays, made with `Input.kind`\n * and `Display.kind` exactly as an application makes its own, and a renderer for\n * each to spread beside `foldkit-mixins-form`'s and `foldkit-mixins-crud`'s.\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 { Input, fillWords, type Control, type ControlChange, type Draft } from 'foldkit-form'\nimport type { Attribute, 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\n/** Text as an address: lower case, unaccented, words joined by `-`. */\nexport const slugify = (text: string): string =>\n text\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n\n/** A slug: text, shown after the address it completes. */\nconst Slug = Input.kind<{ readonly prefix: string }>('CmsSlug', { draft: 'text' })\n\n/** A moment: the text of a `datetime-local` input, submitted as an ISO string. */\nconst DateTime = Input.kind('CmsDateTime', {\n draft: 'text',\n parse: draft => {\n const at = new Date(draft)\n return Number.isNaN(at.getTime()) ? undefined : at.toISOString()\n },\n unparsed: 'Enter a date and a time',\n})\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/**\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)\n return new Intl.DateTimeFormat(data.locale ?? 'en', {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: 'UTC',\n }).format(at)\n const delta = at.getTime() - data.now().getTime()\n const relative = new Intl.RelativeTimeFormat(data.locale ?? 'en', { numeric: 'auto' })\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-form` gives a control's renderer, as far as these read it. */\nexport interface ControlContext<Message> {\n readonly control: Control\n readonly draft: Draft\n readonly change: (value: Draft) => Message\n readonly blurred: Message\n readonly state: ReadonlyArray<Attribute<Message>>\n readonly slots: {\n readonly text: { readonly attrs: (attrs: ReadonlyArray<any>) => any }\n readonly group: { readonly attrs: () => any }\n readonly affix: { readonly attrs: () => any }\n }\n readonly h: HtmlBuilder<Message>\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\n/** An ISO moment as a `datetime-local` input writes one, in the viewer's zone; other text as it is. */\nconst localText = (draft: string): string => {\n const at = new Date(draft)\n if (!/Z$|[+-]\\d\\d:\\d\\d$/.test(draft) || Number.isNaN(at.getTime())) return draft\n const local = new Date(at.getTime() - at.getTimezoneOffset() * 60_000)\n return local.toISOString().slice(0, 16)\n}\n\nexport const Kinds = {\n /** The control kinds: `Cms.Input.Slug.is(control)` narrows one, as `Input.Text.is` does. */\n Input: { Slug, DateTime },\n /** The display kinds. */\n Display: { State: StateDisplay, Moment },\n\n slugify,\n\n /**\n * Under a form's `inputs`: the key is a slug that follows `from` until the\n * author writes it, and is shown after `prefix`. A form filled with a published\n * slug does not follow: an address must not move because its title did.\n */\n slug: (\n from: string,\n options: { readonly prefix?: string; readonly through?: (text: string) => string } = {},\n ): ControlChange => ({\n change: (resolved, inputKey) => {\n const following = Input.following(from, options.through ?? slugify).change(resolved, inputKey)\n return Object.freeze({\n ...Slug.of({ prefix: options.prefix ?? '/' }),\n follows: following.follows,\n })\n },\n }),\n /** Under a form's `inputs`, or as Entity metadata with `Input.of`: a moment. */\n dateTime: (): Control => DateTime.of({}),\n\n /** For `FormView`'s `renderers`, beside its own. */\n controlRenderers: <Message>(): Readonly<\n Record<string, (context: ControlContext<Message>) => Html>\n > => ({\n [Slug.kind]: ({ control, state, draft, change, blurred, slots, h }) =>\n h.div(slots.group.attrs(), [\n h.span(slots.affix.attrs(), [Slug.is(control) ? control.data.prefix : '']),\n h.input(\n slots.text.attrs([\n ...state,\n h.Type('text'),\n h.Value(String(draft)),\n h.OnInput(change),\n h.OnBlur(blurred),\n ]),\n ),\n ]),\n [DateTime.kind]: ({ state, draft, change, blurred, slots, h }) =>\n h.input(\n slots.text.attrs([\n ...state,\n h.Type('datetime-local'),\n h.Value(localText(String(draft))),\n h.OnInput(change),\n h.OnBlur(blurred),\n ]),\n ),\n }),\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 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\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 * 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 kinds a CMS adds, and a renderer for each: `Cms.slug('title')` and\n * `Cms.dateTime()` for a form's `inputs`; `Cms.Display.State` and\n * `Cms.Display.Moment` for a list's columns; `Cms.controlRenderers()` and `Cms.displayRenderers()` to spread\n * beside the mixins' own.\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 { ControlContext, 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,i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,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, 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 type { ActiveSurface, ModelRef, 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: { readonly key: never; readonly error: string }) => 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> {\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 overlay(model: Root, id: string, optimistic: ReadonlyArray<OptimisticOperation>): Root\n lift(model: Root, id: string): Root\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, model: slice } = where\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 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 data.lift(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 = data.overlay(\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 if (content.roles.slug?.key !== key) 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({ key: key as never, error: reason }),\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' && fresh(read(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/**\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)\n return new Intl.DateTimeFormat(data.locale ?? 'en', {\n dateStyle: 'medium',\n timeStyle: 'short',\n timeZone: 'UTC',\n }).format(at)\n const delta = at.getTime() - data.now().getTime()\n const relative = new Intl.RelativeTimeFormat(data.locale ?? 'en', { numeric: 'auto' })\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,OAAO,CAAC,WAAW;CACpD,MAAM,UAAU,MAAM,UAAU;CAChC,OAAO;EACL;EACA,GAAI,UAAW,CAAC,WAAW,SAAS,IAAc,CAAC;EACnD,GAAI,WAAW,QAA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,MAAM,cAAc,KAAA,EAAU,CAAC;AAC7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"foldkit-bundle": "0.8.1",
|
|
43
|
-
"foldkit-
|
|
44
|
-
"foldkit-
|
|
45
|
-
"foldkit-
|
|
43
|
+
"foldkit-crud": "0.11.0",
|
|
44
|
+
"foldkit-entity": "0.13.0",
|
|
45
|
+
"foldkit-remote": "0.21.0",
|
|
46
46
|
"foldkit-metadata": "0.1.0",
|
|
47
|
-
"foldkit-mixins": "0.
|
|
48
|
-
"foldkit-
|
|
49
|
-
"foldkit-
|
|
47
|
+
"foldkit-mixins": "0.20.0",
|
|
48
|
+
"foldkit-surface": "0.10.2",
|
|
49
|
+
"foldkit-form": "0.8.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"effect": "^4.0.0",
|
|
@@ -58,8 +58,9 @@
|
|
|
58
58
|
"foldkit": "0.169.0",
|
|
59
59
|
"tsdown": "^0.23.1",
|
|
60
60
|
"typescript": "7.0.2",
|
|
61
|
-
"foldkit-
|
|
62
|
-
"foldkit-mixins-
|
|
61
|
+
"foldkit-form-recipes": "0.1.1",
|
|
62
|
+
"foldkit-mixins-crud": "0.9.0",
|
|
63
|
+
"foldkit-mixins-form": "0.10.0"
|
|
63
64
|
},
|
|
64
65
|
"scripts": {
|
|
65
66
|
"build": "tsdown",
|