foldkit-cms 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -4
- package/dist/index.d.mts +353 -128
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +234 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -12
package/dist/index.d.mts
CHANGED
|
@@ -2,25 +2,21 @@ import { Option, Pipeable, Schema } from "effect";
|
|
|
2
2
|
import { AnyEntity, Entity, EntityField, EntityInput } from "foldkit-entity";
|
|
3
3
|
import { MutationDescriptor, MutationStatus, OptimisticOperation, RemoteClient, RemoteData, RemoteMessage } from "foldkit-remote";
|
|
4
4
|
import { Bundle } from "foldkit-bundle";
|
|
5
|
+
import * as ManagedResource from "foldkit/managedResource";
|
|
5
6
|
import "foldkit/message";
|
|
7
|
+
import * as Subscription from "foldkit/subscription";
|
|
6
8
|
import * as Submodel from "foldkit/submodel";
|
|
9
|
+
import { DisplayWords } from "foldkit-crud";
|
|
7
10
|
import { Control, Draft, Submitted } from "foldkit-form";
|
|
8
|
-
import { Projection } from "foldkit-surface";
|
|
11
|
+
import { ActiveSurface, Projection } from "foldkit-surface";
|
|
9
12
|
import { Command } from "foldkit/command";
|
|
13
|
+
import * as FieldValidation from "foldkit/fieldValidation";
|
|
10
14
|
import * as Update from "foldkit/update";
|
|
11
|
-
import * as ManagedResource from "foldkit/managedResource";
|
|
12
|
-
import * as Subscription from "foldkit/subscription";
|
|
13
15
|
import { CallableTaggedStruct } from "foldkit/schema";
|
|
14
16
|
import { Attribute, Html, HtmlBuilder } from "foldkit/html";
|
|
15
17
|
import "foldkit/url";
|
|
18
|
+
import { SlotView } from "foldkit-mixins";
|
|
16
19
|
//#region src/lifecycle.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* The lifecycle of a piece of content, derived. Nothing stores a status: a state
|
|
19
|
-
* is a pure function of facts (is there a row, can a visitor see it, is there a
|
|
20
|
-
* draft, has the entry been archived) and a clock, so it cannot disagree with
|
|
21
|
-
* them. A scheduled publish that failed reads scheduled and overdue, which is
|
|
22
|
-
* true, and not published, which would not be.
|
|
23
|
-
*/
|
|
24
20
|
/** What is known of one entry. The server gathers it; nothing here reads a database. */
|
|
25
21
|
interface Facts {
|
|
26
22
|
/** When the entry was archived, if it was. */
|
|
@@ -56,7 +52,8 @@ interface State {
|
|
|
56
52
|
readonly schedule: Schedule | null;
|
|
57
53
|
}
|
|
58
54
|
/** What an author may ask of an entry. Each is an operation the server runs after asking `allow`. */
|
|
59
|
-
|
|
55
|
+
declare const Transitions: Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>;
|
|
56
|
+
type Transition = typeof Transitions.Type;
|
|
60
57
|
//#endregion
|
|
61
58
|
//#region src/editor.d.ts
|
|
62
59
|
/** How the form came to hold what it holds. */
|
|
@@ -77,7 +74,12 @@ type EditorStatus = 'Closed' | 'Loading' | 'NotFound' | 'LoadFailed' |
|
|
|
77
74
|
/** Edited since the last save. */
|
|
78
75
|
'Editing' | 'Saving' | 'Saved' |
|
|
79
76
|
/** Someone else saved or published in between. The author's text is still in the form. */
|
|
80
|
-
'Conflict' | 'SaveFailed' | 'Publishing' | 'Published' | 'PublishFailed' |
|
|
77
|
+
'Conflict' | 'SaveFailed' | 'Publishing' | 'Published' | 'PublishFailed' |
|
|
78
|
+
/**
|
|
79
|
+
* A publish or a schedule the form's own checks stopped before anything was
|
|
80
|
+
* sent: the fields that fail say why. Until the next edit.
|
|
81
|
+
*/
|
|
82
|
+
'Incomplete' | 'Scheduling' |
|
|
81
83
|
/** Promised for later. The entry's `state` says for when, and whether it happened. */
|
|
82
84
|
'Scheduled' | 'ScheduleFailed';
|
|
83
85
|
/**
|
|
@@ -97,6 +99,11 @@ interface EditorModel<FormModel> {
|
|
|
97
99
|
readonly saveWanted: boolean;
|
|
98
100
|
readonly publishId: string | null;
|
|
99
101
|
readonly publishWanted: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* The last publish or schedule asked, as the form took it: waiting for a
|
|
104
|
+
* check still running, or stopped by one and not edited since; else idle.
|
|
105
|
+
*/
|
|
106
|
+
readonly submit: 'idle' | 'waiting' | 'stopped';
|
|
100
107
|
/** When the publish that is wanted, under way or last settled is a promise for later: for when. */
|
|
101
108
|
readonly scheduleAt: string | null;
|
|
102
109
|
/** The discard or unpublish in progress or last settled. */
|
|
@@ -132,7 +139,8 @@ type EditorOut = {
|
|
|
132
139
|
readonly _tag: 'Overwrite';
|
|
133
140
|
};
|
|
134
141
|
/** The parts of a `Form.make` result the editor drives. */
|
|
135
|
-
|
|
142
|
+
/** `Services` is what the form's Commands and Subscriptions require, which the editor's then do. */
|
|
143
|
+
interface EditorForm<FormModel, FormMessage, Value, Resources = {}, Services = never> {
|
|
136
144
|
readonly name: string;
|
|
137
145
|
readonly input: {
|
|
138
146
|
readonly schema: Schema.Struct<any>;
|
|
@@ -140,7 +148,11 @@ interface EditorForm<FormModel, FormMessage, Value> {
|
|
|
140
148
|
readonly bundle: {
|
|
141
149
|
readonly Model: Schema.Codec<FormModel, unknown>;
|
|
142
150
|
readonly Message: Schema.Codec<FormMessage, unknown>;
|
|
143
|
-
readonly update: (model: FormModel, message: FormMessage, args: void) => Update.ReturnWithOutMessage<FormModel, FormMessage, Submitted<Value>,
|
|
151
|
+
readonly update: (model: FormModel, message: FormMessage, args: void) => Update.ReturnWithOutMessage<FormModel, FormMessage, Submitted<Value>, Services>;
|
|
152
|
+
/** The Subscriptions of the form's controls backed by a Bundle, which the editor runs while open. */
|
|
153
|
+
readonly subscriptions?: (args: void) => Subscription.Subscriptions<FormModel, FormMessage, Services>;
|
|
154
|
+
/** Their Resources, which the editor holds while open. */
|
|
155
|
+
readonly resources?: (args: void) => Resources;
|
|
144
156
|
};
|
|
145
157
|
readonly Message: {
|
|
146
158
|
readonly Submitted: () => FormMessage;
|
|
@@ -167,11 +179,11 @@ interface EditorForm<FormModel, FormMessage, Value> {
|
|
|
167
179
|
* same way a text field does, and a blur or a refused edit does not.
|
|
168
180
|
*/
|
|
169
181
|
authoredChanged(before: FormModel, after: FormModel): boolean;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
readonly
|
|
173
|
-
readonly errors?: ReadonlyArray<string>;
|
|
182
|
+
/** Whether a check is still running, which a submit waits for. */
|
|
183
|
+
readonly engine: {
|
|
184
|
+
readonly isValidating: (model: FormModel) => boolean;
|
|
174
185
|
};
|
|
186
|
+
readonly field: (model: FormModel, key: never) => FieldValidation.Field<unknown>;
|
|
175
187
|
}
|
|
176
188
|
/** The parts of a bound Remote domain the editor uses. */
|
|
177
189
|
interface EditorDomain<Root> {
|
|
@@ -185,14 +197,13 @@ interface EditorDomain<Root> {
|
|
|
185
197
|
refresh(model: Root, target: any): Root;
|
|
186
198
|
overlay(model: Root, id: string, optimistic: ReadonlyArray<OptimisticOperation>): Root;
|
|
187
199
|
lift(model: Root, id: string): Root;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
};
|
|
200
|
+
/** `Data.active`: a read of the domain as an active Surface of its application. */
|
|
201
|
+
active(name: string, projectionOf: (model: Root) => Option.Option<Projection<Root, any>>): ActiveSurface<Root>;
|
|
191
202
|
}
|
|
192
|
-
interface EditorContent<FormModel, FormMessage, Value> {
|
|
203
|
+
interface EditorContent<FormModel, FormMessage, Value, Resources = {}, Services = never> {
|
|
193
204
|
readonly name: string;
|
|
194
205
|
readonly entity: AnyEntity;
|
|
195
|
-
readonly form: EditorForm<FormModel, FormMessage, Value>;
|
|
206
|
+
readonly form: EditorForm<FormModel, FormMessage, Value, Resources, Services>;
|
|
196
207
|
readonly roles: {
|
|
197
208
|
readonly label: {
|
|
198
209
|
readonly key: string;
|
|
@@ -231,6 +242,123 @@ declare const EditorMessage: import("foldkit/message").MessageUnion<{
|
|
|
231
242
|
}>;
|
|
232
243
|
type EditorMessage = typeof EditorMessage.Type;
|
|
233
244
|
//#endregion
|
|
245
|
+
//#region ../bundle/src/placed.d.ts
|
|
246
|
+
declare const PlacedTypeId: unique symbol;
|
|
247
|
+
/**
|
|
248
|
+
* Args for a placement: a static value, or a factory deriving them from the
|
|
249
|
+
* parent seed — the fields `assembly.initial(rest)` was given, before any
|
|
250
|
+
* placement initialised. A factory runs once per initialization and its result
|
|
251
|
+
* is retained for the placement's `init`, `update`, helpers, Subscriptions,
|
|
252
|
+
* and resources; it never re-runs against changing parent state, so keep it
|
|
253
|
+
* pure of its seed.
|
|
254
|
+
*
|
|
255
|
+
* When no initialization ran — a hand-built Model in a test, which never went
|
|
256
|
+
* through `initial` — `update` derives from the given parent per use, without
|
|
257
|
+
* retaining, so each Model is folded with its own seed.
|
|
258
|
+
*
|
|
259
|
+
* Read only seed fields (route, auth, workspace, ...), never sibling
|
|
260
|
+
* placement fields: every factory sees the same base seed, so a sibling read
|
|
261
|
+
* is consistently absent rather than order-dependent.
|
|
262
|
+
*/
|
|
263
|
+
type ArgsSource<Seed, Args> = Args | ((seed: Seed) => Args);
|
|
264
|
+
interface PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed = Parent> {
|
|
265
|
+
/**
|
|
266
|
+
* The bundle's args: a static value, or a factory from the parent seed (the
|
|
267
|
+
* fields `assembly.initial(rest)` was given, minus this placement's own
|
|
268
|
+
* field). A factory is computed once per initialization and retained for
|
|
269
|
+
* `init`, `update`, and helpers. Subscriptions and resources built from it
|
|
270
|
+
* require `initial`/`config` to have run first; a bundle with neither
|
|
271
|
+
* contributes empty records either way.
|
|
272
|
+
*/
|
|
273
|
+
readonly args?: ArgsSource<ParentSeed, Args>;
|
|
274
|
+
/** Handles the child's OutMessage in parent terms, with the child already written back. */
|
|
275
|
+
readonly onOut?: (outMessage: OutMessage, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
276
|
+
/**
|
|
277
|
+
* Observes each of the child's Messages in parent terms, after the child has
|
|
278
|
+
* handled it and its `onOut` has run, so the parent's own update needs no arm
|
|
279
|
+
* for the wrapper. Helpers are not Messages and do not reach it.
|
|
280
|
+
*/
|
|
281
|
+
readonly onMessage?: (message: Message) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
282
|
+
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
283
|
+
readonly key?: string;
|
|
284
|
+
/** A gate beside the Link's own: Subscriptions and resources run only while both hold. */
|
|
285
|
+
readonly when?: (parent: Parent) => boolean;
|
|
286
|
+
}
|
|
287
|
+
/** A lifted resource record: each child entry in parent terms, keyed by the placement. */
|
|
288
|
+
type PlacedResources<Parent, ParentMessage, Resources> = Readonly<Record<string, { readonly [K in keyof Resources]: Resources[K] extends ManagedResource.Entry<any, any, infer Requirements, infer Value, infer Service, infer OnAcquired extends (...args: ReadonlyArray<any>) => any> ? ManagedResource.Entry<Parent, ParentMessage, Requirements, Value, Service, (...args: Parameters<OnAcquired>) => ParentMessage> : never; }[keyof Resources]>>;
|
|
289
|
+
type PlacedHelpers<Parent, ParentMessage, R, Helpers> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
|
|
290
|
+
interface Placed<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Resources, Helpers, Field extends string = string, Claimed extends string = string> {
|
|
291
|
+
readonly [PlacedTypeId]: typeof PlacedTypeId;
|
|
292
|
+
/** Types only: the top-level Model field this placement owns, or `string` when unknown. */
|
|
293
|
+
readonly field?: Field;
|
|
294
|
+
/** Types only: the parent Message tag this placement routes, or `string` when unknown. */
|
|
295
|
+
readonly claims?: Claimed;
|
|
296
|
+
readonly name: Name;
|
|
297
|
+
/** `Name@path`, or the configured `key`: the prefix of every Subscription and resource key. */
|
|
298
|
+
readonly key: string;
|
|
299
|
+
/** The encoded args as text, when the bundle has an args Schema. */
|
|
300
|
+
readonly argsSummary: string | undefined;
|
|
301
|
+
/** Whether `args` was given as a seed factory; resolved once per initialization. */
|
|
302
|
+
readonly hasDynamicArgs: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Derives the factory's args from `seed`, validates them against the
|
|
305
|
+
* bundle's args Schema, and retains them for `init`, `update`, helpers,
|
|
306
|
+
* Subscriptions, and resources. A no-op for static args. The assembly calls
|
|
307
|
+
* this with the base seed before running inits, so every factory sees the
|
|
308
|
+
* same parent state whatever the placement order.
|
|
309
|
+
*/
|
|
310
|
+
readonly resolveArgs: (seed: unknown) => void;
|
|
311
|
+
/**
|
|
312
|
+
* Assembly use: marks the placement skipped because `rest` provides its
|
|
313
|
+
* top-level field, so its factory never runs and its records contribute
|
|
314
|
+
* nothing while the child is absent. Cleared by the next `resolveArgs`.
|
|
315
|
+
*/
|
|
316
|
+
readonly skipArgs: () => void;
|
|
317
|
+
readonly link: Link<Parent, ParentMessage, Model, Message>;
|
|
318
|
+
/** Writes the child's initial Model and starts its `init` Commands. */
|
|
319
|
+
readonly init: Update.Step<Parent, ParentMessage, R>;
|
|
320
|
+
/** Folds the Message when it belongs to this placement; `None` otherwise. */
|
|
321
|
+
readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
322
|
+
readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
|
|
323
|
+
readonly resources: PlacedResources<Parent, ParentMessage, Resources>;
|
|
324
|
+
/**
|
|
325
|
+
* Renders the child through `h.submodel`; nothing while the child is absent.
|
|
326
|
+
* Generic over the parent's whole Message, which must include this placement's.
|
|
327
|
+
*/
|
|
328
|
+
readonly view: PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
329
|
+
/**
|
|
330
|
+
* The same view in another slot, for rendering one placement in two DOM
|
|
331
|
+
* positions (desktop and mobile). `h.submodel` throws on a repeated slot.
|
|
332
|
+
*/
|
|
333
|
+
readonly viewIn: (slot: string) => PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
334
|
+
readonly helpers: PlacedHelpers<Parent, ParentMessage, R, Helpers>;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* What a placement's view needs of a builder: `submodel`, and `OnClick` to
|
|
338
|
+
* read its Message from. A wrapper of Foldkit's builder that keeps both, such
|
|
339
|
+
* as `foldkit-ssr`'s resumable builder, is one.
|
|
340
|
+
*/
|
|
341
|
+
type BuilderLike = Pick<HtmlBuilder<any>, 'submodel' | 'OnClick'>;
|
|
342
|
+
type PlacedView<Parent, ParentMessage, ViewInputs> = [ViewInputs] extends [void] ? <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>) => Html : <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>, viewInputs: ViewInputs) => Html;
|
|
343
|
+
/** A readable type error: intersected onto a parameter, its message names the fix. */
|
|
344
|
+
interface Invalid<Message extends string> {
|
|
345
|
+
readonly invalid: Message;
|
|
346
|
+
}
|
|
347
|
+
type BuilderMessage<H> = H extends {
|
|
348
|
+
readonly OnClick: (message: infer M, ...rest: any) => any;
|
|
349
|
+
} ? M : never;
|
|
350
|
+
/**
|
|
351
|
+
* The parent's `h`, checked to accept this placement's Messages. Generic over the
|
|
352
|
+
* whole builder rather than its Message: inferring a Message through
|
|
353
|
+
* `HtmlBuilder` costs thousands of type instantiations per call, while the
|
|
354
|
+
* builder infers as itself and its Message is extracted once per builder type.
|
|
355
|
+
*/
|
|
356
|
+
type ViewBuilder<H, ParentMessage> = H & ([ParentMessage] extends [BuilderMessage<H>] ? unknown : Invalid<"The parent Message does not include this placement's wrapper variant; spread its Link.wrapper(...).cases into defineMessageUnion">);
|
|
357
|
+
/** The tag of a Link's parent variant, or `string` when it cannot be read. */
|
|
358
|
+
type TagOf<LinkMessage> = LinkMessage extends {
|
|
359
|
+
readonly _tag: infer Tag extends string;
|
|
360
|
+
} ? Tag : string;
|
|
361
|
+
//#endregion
|
|
234
362
|
//#region ../bundle/src/link.d.ts
|
|
235
363
|
declare const LinkTypeId: unique symbol;
|
|
236
364
|
/** The parent Message variant `Tag({ message })` that carries a child's Messages. */
|
|
@@ -259,8 +387,14 @@ interface Wrapper<Tag extends string, ChildMessage> {
|
|
|
259
387
|
type AnyMessage = {
|
|
260
388
|
readonly _tag: string;
|
|
261
389
|
};
|
|
262
|
-
|
|
390
|
+
/**
|
|
391
|
+
* `Field` is the parent's top-level field the child is written into, when the
|
|
392
|
+
* Link is one: `never` for a child nested deeper, and `string` when unknown.
|
|
393
|
+
*/
|
|
394
|
+
interface Link<Parent, ParentMessage, Child, ChildMessage, Field extends string = string> extends Pipeable.Pipeable {
|
|
263
395
|
readonly [LinkTypeId]: typeof LinkTypeId;
|
|
396
|
+
/** Types only: the top-level field, so `placements.initial` knows who writes it. */
|
|
397
|
+
readonly field?: Field;
|
|
264
398
|
readonly read: (parent: Parent) => Option.Option<Child>;
|
|
265
399
|
readonly write: (parent: Parent, child: Child) => Parent;
|
|
266
400
|
readonly toParentMessage: (message: ChildMessage) => ParentMessage;
|
|
@@ -275,14 +409,35 @@ interface Link<Parent, ParentMessage, Child, ChildMessage> extends Pipeable.Pipe
|
|
|
275
409
|
/** The application a Link built from a Surface field ref belongs to, for its Module contract. */
|
|
276
410
|
readonly owner?: object | undefined;
|
|
277
411
|
}
|
|
278
|
-
|
|
412
|
+
/** A Message union's variant `Tag({ message })`, as `defineMessageUnion` declares it. */
|
|
413
|
+
type Variant = {
|
|
414
|
+
readonly fields: {
|
|
415
|
+
readonly _tag: Schema.tag<string>;
|
|
416
|
+
readonly message: Schema.Top;
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
type VariantTag<V extends Variant> = V['fields']['_tag'] extends Schema.tag<infer Tag extends string> ? Tag : never;
|
|
420
|
+
type OnlyMessage<V extends Variant> = [Exclude<keyof V['fields'], '_tag' | 'message'>] extends [never] ? unknown : Invalid<'A wrapper variant carries only `message`; this variant has other fields'>;
|
|
421
|
+
/**
|
|
422
|
+
* The parent variant `Tag({ message })` for a child's Messages: from a tag and
|
|
423
|
+
* the child's Message Schema, whose `cases` then go into the parent's union, or
|
|
424
|
+
* from a variant the parent's union already declares.
|
|
425
|
+
*/
|
|
426
|
+
declare function wrapper<const Tag extends string, ChildMessage>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>): Wrapper<Tag, ChildMessage>;
|
|
427
|
+
declare function wrapper<V extends Variant>(variant: V & OnlyMessage<V>): Wrapper<VariantTag<V>, V['fields']['message']['Type']>;
|
|
428
|
+
interface MakeConfig<Parent, Tag extends string, Child, ChildMessage, Path> {
|
|
279
429
|
readonly read: (parent: Parent) => Option.Option<Child>;
|
|
280
430
|
readonly write: (parent: Parent, child: Child) => Parent;
|
|
281
431
|
readonly wrapper: Wrapper<Tag, ChildMessage>;
|
|
282
432
|
readonly when?: (parent: Parent) => boolean;
|
|
283
|
-
readonly path:
|
|
433
|
+
readonly path: Path;
|
|
284
434
|
readonly owner?: object | undefined;
|
|
285
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* The top-level field a path names. `initial` treats a one-segment path as the
|
|
438
|
+
* field the placement writes, so a longer one names none.
|
|
439
|
+
*/
|
|
440
|
+
type FieldOfPath<Path> = Path extends readonly [infer Field extends string] ? Field : Path extends readonly [string, ...ReadonlyArray<string>] ? never : string;
|
|
286
441
|
type OptionKeys<Parent> = { [K in keyof Parent]: Parent[K] extends Option.Option<unknown> ? K : never; }[keyof Parent] & string;
|
|
287
442
|
type OptionValue<A> = A extends Option.Option<infer Value> ? Value : never;
|
|
288
443
|
/** The parent Message variant `Tag({ key, message })` that carries one collection item's Messages. */
|
|
@@ -308,7 +463,9 @@ interface KeyedWrapper<Tag extends string, ChildMessage, Key extends string = st
|
|
|
308
463
|
* business: a record by key, an array identified by id, or anything with these
|
|
309
464
|
* operations. `entries` is the order views and Subscriptions follow.
|
|
310
465
|
*/
|
|
311
|
-
interface CollectionLink<Parent, ParentMessage, Child, ChildMessage, Key extends string = string> {
|
|
466
|
+
interface CollectionLink<Parent, ParentMessage, Child, ChildMessage, Key extends string = string, Field extends string = string> {
|
|
467
|
+
/** Types only: the top-level field holding the items, or `string` when unknown. */
|
|
468
|
+
readonly field?: Field;
|
|
312
469
|
/** The storage with no items, for a parent's initial Model. */
|
|
313
470
|
readonly empty: unknown;
|
|
314
471
|
readonly entries: (parent: Parent) => ReadonlyArray<readonly [key: Key, child: Child]>;
|
|
@@ -328,119 +485,75 @@ type RecordValue<A> = A extends Readonly<Record<string, infer Value>> ? Value :
|
|
|
328
485
|
type ArrayKeys<Parent> = { [K in keyof Parent]: Parent[K] extends ReadonlyArray<unknown> ? K : never; }[keyof Parent] & string;
|
|
329
486
|
type ArrayItem<A> = A extends ReadonlyArray<infer Item> ? Item : never;
|
|
330
487
|
declare const Link: {
|
|
331
|
-
readonly wrapper:
|
|
332
|
-
readonly make: <Parent, const Tag extends string, Child, ChildMessage>(config: MakeConfig<Parent, Tag, Child, ChildMessage>) => Link<Parent, Wrapped<Tag, ChildMessage>, Child, ChildMessage
|
|
488
|
+
readonly wrapper: typeof wrapper;
|
|
489
|
+
readonly make: <Parent, const Tag extends string, Child, ChildMessage, const Path extends ReadonlyArray<string> = readonly string[]>(config: MakeConfig<Parent, Tag, Child, ChildMessage, Path>) => Link<Parent, Wrapped<Tag, ChildMessage>, Child, ChildMessage, FieldOfPath<Path>>;
|
|
333
490
|
readonly field: <Parent>() => <const Key extends keyof Parent & string, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper<Tag, ChildMessage>, options?: {
|
|
334
491
|
readonly when?: (parent: Parent) => boolean;
|
|
335
|
-
}) => Link<Parent, Wrapped<Tag, ChildMessage>, Parent[Key], ChildMessage>;
|
|
492
|
+
}) => Link<Parent, Wrapped<Tag, ChildMessage>, Parent[Key], ChildMessage, Key>;
|
|
336
493
|
readonly optional: <Parent>() => <const Key extends OptionKeys<Parent>, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper<Tag, ChildMessage>, options?: {
|
|
337
494
|
readonly when?: (parent: Parent) => boolean;
|
|
338
|
-
}) => Link<Parent, Wrapped<Tag, ChildMessage>, OptionValue<Parent[Key]>, ChildMessage>;
|
|
339
|
-
readonly compose: <A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage>, inner: Link<B, BMessage, C, CMessage>) => Link<A, AMessage, C, CMessage>;
|
|
495
|
+
}) => Link<Parent, Wrapped<Tag, ChildMessage>, OptionValue<Parent[Key]>, ChildMessage, Key>;
|
|
496
|
+
readonly compose: <A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage, string>, inner: Link<B, BMessage, C, CMessage, string>) => Link<A, AMessage, C, CMessage, never>;
|
|
340
497
|
readonly andThen: {
|
|
341
|
-
<B, BMessage extends AnyMessage, C, CMessage>(inner: Link<B, BMessage, C, CMessage>): <A, AMessage>(outer: Link<A, AMessage, B, BMessage>) => Link<A, AMessage, C, CMessage>;
|
|
342
|
-
<A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage>, inner: Link<B, BMessage, C, CMessage>): Link<A, AMessage, C, CMessage>;
|
|
498
|
+
<B, BMessage extends AnyMessage, C, CMessage>(inner: Link<B, BMessage, C, CMessage, string>): <A, AMessage>(outer: Link<A, AMessage, B, BMessage, string>) => Link<A, AMessage, C, CMessage, never>;
|
|
499
|
+
<A, AMessage, B, BMessage extends AnyMessage, C, CMessage>(outer: Link<A, AMessage, B, BMessage, string>, inner: Link<B, BMessage, C, CMessage, string>): Link<A, AMessage, C, CMessage, never>;
|
|
343
500
|
};
|
|
344
501
|
readonly when: {
|
|
345
|
-
<Parent>(predicate: (parent: Parent) => boolean): <ParentMessage, Child, ChildMessage>(self: Link<Parent, ParentMessage, Child, ChildMessage>) => Link<Parent, ParentMessage, Child, ChildMessage>;
|
|
346
|
-
<Parent, ParentMessage, Child, ChildMessage>(self: Link<Parent, ParentMessage, Child, ChildMessage>, predicate: (parent: Parent) => boolean): Link<Parent, ParentMessage, Child, ChildMessage>;
|
|
502
|
+
<Parent>(predicate: (parent: Parent) => boolean): <ParentMessage, Child, ChildMessage, Field extends string>(self: Link<Parent, ParentMessage, Child, ChildMessage, Field>) => Link<Parent, ParentMessage, Child, ChildMessage, Field>;
|
|
503
|
+
<Parent, ParentMessage, Child, ChildMessage, Field extends string>(self: Link<Parent, ParentMessage, Child, ChildMessage, Field>, predicate: (parent: Parent) => boolean): Link<Parent, ParentMessage, Child, ChildMessage, Field>;
|
|
504
|
+
};
|
|
505
|
+
readonly foldInit: <Parent, ParentMessage, Child, ChildMessage, Field extends string>(link: Link<Parent, ParentMessage, Child, ChildMessage, Field>, rest: Omit<Parent, Field>) => {
|
|
506
|
+
readonly toParentModel: (child: Child) => Parent;
|
|
507
|
+
readonly toParentMessage: (message: ChildMessage) => ParentMessage;
|
|
347
508
|
};
|
|
348
509
|
readonly keyedWrapper: <const Tag extends string, ChildMessage, Key extends string = string>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>, key?: Schema.Codec<Key, string>) => KeyedWrapper<Tag, ChildMessage, Key>;
|
|
349
510
|
readonly collection: <Parent>() => <const Field extends RecordKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options?: {
|
|
350
511
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
351
|
-
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, RecordValue<Parent[Field]>, ChildMessage, Key>;
|
|
512
|
+
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, RecordValue<Parent[Field]>, ChildMessage, Key, Field>;
|
|
352
513
|
readonly collectionById: <Parent>() => <const Field extends ArrayKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options: {
|
|
353
514
|
readonly id: (item: ArrayItem<Parent[Field]>) => Key;
|
|
354
515
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
355
|
-
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, ArrayItem<Parent[Field]>, ChildMessage, Key>;
|
|
516
|
+
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, ArrayItem<Parent[Field]>, ChildMessage, Key, Field>;
|
|
356
517
|
};
|
|
357
518
|
//#endregion
|
|
358
|
-
//#region ../bundle/src/placed.d.ts
|
|
359
|
-
declare const PlacedTypeId: unique symbol;
|
|
360
|
-
interface PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> {
|
|
361
|
-
readonly args?: Args;
|
|
362
|
-
/** Handles the child's OutMessage in parent terms, with the child already written back. */
|
|
363
|
-
readonly onOut?: (outMessage: OutMessage, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
364
|
-
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
365
|
-
readonly key?: string;
|
|
366
|
-
/** A gate beside the Link's own: Subscriptions and resources run only while both hold. */
|
|
367
|
-
readonly when?: (parent: Parent) => boolean;
|
|
368
|
-
}
|
|
369
|
-
/** A lifted resource record: each child entry in parent terms, keyed by the placement. */
|
|
370
|
-
type PlacedResources<Parent, ParentMessage, Resources> = Readonly<Record<string, { readonly [K in keyof Resources]: Resources[K] extends ManagedResource.Entry<any, any, infer Requirements, infer Value, infer Service, any> ? ManagedResource.Entry<Parent, ParentMessage, Requirements, Value, Service> : never; }[keyof Resources]>>;
|
|
371
|
-
type PlacedHelpers<Parent, ParentMessage, R, Helpers> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
|
|
372
|
-
interface Placed<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Resources, Helpers, Field extends string = string> {
|
|
373
|
-
readonly [PlacedTypeId]: typeof PlacedTypeId;
|
|
374
|
-
/** Types only: the top-level Model field this placement owns, or `string` when unknown. */
|
|
375
|
-
readonly field?: Field;
|
|
376
|
-
readonly name: Name;
|
|
377
|
-
/** `Name@path`, or the configured `key`: the prefix of every Subscription and resource key. */
|
|
378
|
-
readonly key: string;
|
|
379
|
-
/** The encoded args as text, when the bundle has an args Schema. */
|
|
380
|
-
readonly argsSummary: string | undefined;
|
|
381
|
-
readonly link: Link<Parent, ParentMessage, Model, Message>;
|
|
382
|
-
/** Writes the child's initial Model and starts its `init` Commands. */
|
|
383
|
-
readonly init: Update.Step<Parent, ParentMessage, R>;
|
|
384
|
-
/** Folds the Message when it belongs to this placement; `None` otherwise. */
|
|
385
|
-
readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
386
|
-
readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
|
|
387
|
-
readonly resources: PlacedResources<Parent, ParentMessage, Resources>;
|
|
388
|
-
/**
|
|
389
|
-
* Renders the child through `h.submodel`; nothing while the child is absent.
|
|
390
|
-
* Generic over the parent's whole Message, which must include this placement's.
|
|
391
|
-
*/
|
|
392
|
-
readonly view: PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
393
|
-
/**
|
|
394
|
-
* The same view in another slot, for rendering one placement in two DOM
|
|
395
|
-
* positions (desktop and mobile). `h.submodel` throws on a repeated slot.
|
|
396
|
-
*/
|
|
397
|
-
readonly viewIn: (slot: string) => PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
398
|
-
readonly helpers: PlacedHelpers<Parent, ParentMessage, R, Helpers>;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* What a placement's view needs of a builder: `submodel`, and `OnClick` to
|
|
402
|
-
* read its Message from. A wrapper of Foldkit's builder that keeps both, such
|
|
403
|
-
* as `foldkit-ssr`'s resumable builder, is one.
|
|
404
|
-
*/
|
|
405
|
-
type BuilderLike = Pick<HtmlBuilder<any>, 'submodel' | 'OnClick'>;
|
|
406
|
-
type PlacedView<Parent, ParentMessage, ViewInputs> = [ViewInputs] extends [void] ? <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>) => Html : <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>, viewInputs: ViewInputs) => Html;
|
|
407
|
-
/** A readable type error: intersected onto a parameter, its message names the fix. */
|
|
408
|
-
interface Invalid<Message extends string> {
|
|
409
|
-
readonly invalid: Message;
|
|
410
|
-
}
|
|
411
|
-
type BuilderMessage<H> = H extends {
|
|
412
|
-
readonly OnClick: (message: infer M, ...rest: any) => any;
|
|
413
|
-
} ? M : never;
|
|
414
|
-
/**
|
|
415
|
-
* The parent's `h`, checked to accept this placement's Messages. Generic over the
|
|
416
|
-
* whole builder rather than its Message: inferring a Message through
|
|
417
|
-
* `HtmlBuilder` costs thousands of type instantiations per call, while the
|
|
418
|
-
* builder infers as itself and its Message is extracted once per builder type.
|
|
419
|
-
*/
|
|
420
|
-
type ViewBuilder<H, ParentMessage> = H & ([ParentMessage] extends [BuilderMessage<H>] ? unknown : Invalid<"The parent Message does not include this placement's wrapper variant; spread its Link.wrapper(...).cases into defineMessageUnion">);
|
|
421
|
-
//#endregion
|
|
422
519
|
//#region ../bundle/src/collection.d.ts
|
|
423
520
|
declare const PlacedCollectionTypeId: unique symbol;
|
|
424
|
-
interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> {
|
|
425
|
-
/**
|
|
426
|
-
|
|
521
|
+
interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string, ParentSeed = Parent> {
|
|
522
|
+
/**
|
|
523
|
+
* The args every item's `init` and `update` receive: a static value, or a
|
|
524
|
+
* factory from the parent seed, computed once per initialization and
|
|
525
|
+
* retained. Adding items requires `initial`/`config` to have run; `update`
|
|
526
|
+
* on a Model no initialization produced derives per use instead.
|
|
527
|
+
*/
|
|
528
|
+
readonly args?: ArgsSource<ParentSeed, Args>;
|
|
427
529
|
/** Handles an item's OutMessage in parent terms, with the item already written back. */
|
|
428
530
|
readonly onOut?: (outMessage: OutMessage, key: Key, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
531
|
+
/** Observes each item's Messages in parent terms, after the item has handled it and its `onOut` has run. */
|
|
532
|
+
readonly onMessage?: (message: Message, key: Key) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
429
533
|
/** Prefix for the collection's Subscription keys. Defaults to `Name@path[]`. */
|
|
430
534
|
readonly key?: string;
|
|
431
535
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
432
536
|
}
|
|
433
537
|
type CollectionView<Parent, ParentMessage, ViewInputs, Key extends string = string> = [ViewInputs] extends [void] ? <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key) => Html : <H extends BuilderLike>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key, viewInputs: ViewInputs) => Html;
|
|
434
538
|
type CollectionHelpers<Parent, ParentMessage, R, Helpers, Key extends string = string> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (key: Key, ...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
|
|
435
|
-
interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Helpers, Field extends string = string, Key extends string = string> {
|
|
539
|
+
interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Helpers, Field extends string = string, Key extends string = string, Claimed extends string = string> {
|
|
436
540
|
readonly [PlacedCollectionTypeId]: typeof PlacedCollectionTypeId;
|
|
437
541
|
/** Types only: the record field this collection owns, or `string` when unknown. */
|
|
438
542
|
readonly field?: Field;
|
|
543
|
+
/** Types only: the parent Message tag this collection routes, or `string` when unknown. */
|
|
544
|
+
readonly claims?: Claimed;
|
|
439
545
|
readonly name: Name;
|
|
440
546
|
/** `Name@path[]`, or the configured `key`: the prefix of every Subscription key. */
|
|
441
547
|
readonly key: string;
|
|
442
548
|
/** The encoded args as text, when the bundle has an args Schema. */
|
|
443
549
|
readonly argsSummary: string | undefined;
|
|
550
|
+
/** Whether `args` was given as a seed factory; resolved once per initialization. */
|
|
551
|
+
readonly hasDynamicArgs: boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Derives the factory's args from `seed` and retains them for `add`,
|
|
554
|
+
* `update`, and Subscriptions. A no-op for static args.
|
|
555
|
+
*/
|
|
556
|
+
readonly resolveArgs: (seed: unknown) => void;
|
|
444
557
|
readonly link: CollectionLink<Parent, ParentMessage, Model, Message, Key>;
|
|
445
558
|
/** Folds the Message into its item; `None` when it is not this collection's. A missing key leaves the parent unchanged. */
|
|
446
559
|
readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
@@ -461,6 +574,11 @@ interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Me
|
|
|
461
574
|
}
|
|
462
575
|
//#endregion
|
|
463
576
|
//#region ../bundle/src/bundle.d.ts
|
|
577
|
+
/**
|
|
578
|
+
* The parent seed a factory observes: the parent without the placement's own
|
|
579
|
+
* field, or the whole parent where the field is unknown (`string`).
|
|
580
|
+
*/
|
|
581
|
+
type SeedFor<Parent, Field extends string> = string extends Field ? Parent : Omit<Parent, Field>;
|
|
464
582
|
declare const BundleTypeId: unique symbol;
|
|
465
583
|
/** A child Managed Resource entry: its requirements are an `Option`, so the entry can release. */
|
|
466
584
|
type ResourceEntry<Model, Message> = ManagedResource.Entry<Model, Message, Option.Option<any>, any, any>;
|
|
@@ -494,44 +612,96 @@ interface Bundle$1<Name extends string, Args, Model, Message extends AnyMessage,
|
|
|
494
612
|
*/
|
|
495
613
|
readonly with: (args: Args) => Bundle$1<Name, void, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>;
|
|
496
614
|
/** Places the bundle where `link` points. */
|
|
497
|
-
readonly at: <Parent, LinkMessage, OutStepMessage = never, R2 = never>(link: Link<Parent, LinkMessage, Model, Message>, ...config: PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2
|
|
615
|
+
readonly at: <Parent, LinkMessage, Field extends string, OutStepMessage = never, R2 = never>(link: Link<Parent, LinkMessage, Model, Message, Field>, ...config: PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, SeedFor<Parent, Field>>) => Placed<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Resources, Helpers, Field, TagOf<LinkMessage>>;
|
|
498
616
|
/** Places the bundle once per key of the collection `link` points at. */
|
|
499
|
-
readonly each: [keyof Resources] extends [never] ? <Parent, LinkMessage, Key extends string, OutStepMessage = never, R2 = never>(link: CollectionLink<Parent, LinkMessage, Model, Message, Key>, ...config: EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key
|
|
617
|
+
readonly each: [keyof Resources] extends [never] ? <Parent, LinkMessage, Key extends string, Field extends string, OutStepMessage = never, R2 = never>(link: CollectionLink<Parent, LinkMessage, Model, Message, Key, Field>, ...config: EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, SeedFor<Parent, Field>>) => PlacedCollection<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Helpers, Field, Key, TagOf<LinkMessage>> : Invalid<'Bundle.each does not support Managed Resources yet: the runtime provides a resource by one tag, so items would share it'>;
|
|
500
618
|
}
|
|
501
619
|
/**
|
|
502
620
|
* What placing needs: `args` when `init` takes them, and `onOut` when the
|
|
503
621
|
* bundle has an OutMessage, so an OutMessage is never dropped by omission.
|
|
622
|
+
* `args` is a static value or a factory from the parent seed (the parent
|
|
623
|
+
* without this placement's own field); the seed type defaults to the whole
|
|
624
|
+
* parent where the field is unknown.
|
|
504
625
|
*/
|
|
505
|
-
type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = {
|
|
626
|
+
type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed = Parent> = {
|
|
506
627
|
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
507
628
|
readonly key?: string;
|
|
508
629
|
/** A gate beside the Link's own: the child's Subscriptions and resources run only while both hold. */
|
|
509
630
|
readonly when?: (parent: Parent) => boolean;
|
|
631
|
+
/** Observes each of the child's Messages in parent terms, after the child handled it. */
|
|
632
|
+
readonly onMessage?: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>>['onMessage'];
|
|
510
633
|
} & ([Args] extends [void] ? {
|
|
511
634
|
readonly args?: never;
|
|
512
635
|
} : {
|
|
513
|
-
readonly args: Args
|
|
636
|
+
readonly args: ArgsSource<ParentSeed, Args>;
|
|
514
637
|
}) & ([OutMessage] extends [never] ? {
|
|
515
638
|
readonly onOut?: never;
|
|
516
639
|
} : {
|
|
517
|
-
readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>>['onOut'];
|
|
640
|
+
readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>>['onOut'];
|
|
518
641
|
});
|
|
519
642
|
/** The config argument is optional only when it would be empty. */
|
|
520
|
-
type PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>];
|
|
521
|
-
type EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = {
|
|
643
|
+
type PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed = Parent> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>];
|
|
644
|
+
type EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string, ParentSeed = Parent> = {
|
|
522
645
|
readonly key?: string;
|
|
523
646
|
/** A gate per item beside the Link's own: an item's Subscriptions run only while both hold. */
|
|
524
647
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
648
|
+
/** Observes each item's Messages in parent terms, after the item handled it. */
|
|
649
|
+
readonly onMessage?: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>>['onMessage'];
|
|
525
650
|
} & ([Args] extends [void] ? {
|
|
526
651
|
readonly args?: never;
|
|
527
652
|
} : {
|
|
528
|
-
readonly args: Args
|
|
653
|
+
readonly args: ArgsSource<ParentSeed, Args>;
|
|
529
654
|
}) & ([OutMessage] extends [never] ? {
|
|
530
655
|
readonly onOut?: never;
|
|
531
656
|
} : {
|
|
532
|
-
readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>>['onOut'];
|
|
657
|
+
readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>>['onOut'];
|
|
533
658
|
});
|
|
534
|
-
type EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>];
|
|
659
|
+
type EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string, ParentSeed = Parent> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>];
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/views.d.ts
|
|
662
|
+
/** A published revision, as an editor's History lists it. */
|
|
663
|
+
interface RevisionRow {
|
|
664
|
+
readonly n: number;
|
|
665
|
+
readonly publishedAt: string;
|
|
666
|
+
readonly publishedBy: string | null;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* The open entry's published revisions, as they have been read. A posts'
|
|
670
|
+
* history and a pages' revisions read through the same shape, so one helper
|
|
671
|
+
* serves both: which read is the section's to name. A read that failed, or
|
|
672
|
+
* that has no answer yet, is its own state rather than an empty list, so the
|
|
673
|
+
* card cannot mistake either for nothing published.
|
|
674
|
+
*/
|
|
675
|
+
type RevisionHistory = {
|
|
676
|
+
readonly _tag: 'Ready';
|
|
677
|
+
readonly revisions: ReadonlyArray<RevisionRow>;
|
|
678
|
+
} | {
|
|
679
|
+
readonly _tag: 'Loading';
|
|
680
|
+
} | {
|
|
681
|
+
readonly _tag: 'Failed';
|
|
682
|
+
};
|
|
683
|
+
/** The builders `historyCard` reads. */
|
|
684
|
+
interface HistoryCardSlots<M> {
|
|
685
|
+
readonly card: SlotView.SlotBuilder<M>;
|
|
686
|
+
readonly cardTitle: SlotView.SlotBuilder<M>;
|
|
687
|
+
readonly muted: SlotView.SlotBuilder<M>;
|
|
688
|
+
readonly timeline: SlotView.SlotBuilder<M>;
|
|
689
|
+
readonly revision: SlotView.SlotBuilder<M>;
|
|
690
|
+
readonly revisionMark: SlotView.SlotBuilder<M>;
|
|
691
|
+
readonly revisionBody: SlotView.SlotBuilder<M>;
|
|
692
|
+
readonly revisionTitle: SlotView.SlotBuilder<M>;
|
|
693
|
+
readonly revisionLive: SlotView.SlotBuilder<M>;
|
|
694
|
+
readonly revisionMeta: SlotView.SlotBuilder<M>;
|
|
695
|
+
readonly revisionRestore: SlotView.SlotBuilder<M>;
|
|
696
|
+
}
|
|
697
|
+
/** The builders `moreCard` reads. */
|
|
698
|
+
interface MoreCardSlots<M> {
|
|
699
|
+
readonly card: SlotView.SlotBuilder<M>;
|
|
700
|
+
readonly cardTitle: SlotView.SlotBuilder<M>;
|
|
701
|
+
readonly toolbar: SlotView.SlotBuilder<M>;
|
|
702
|
+
readonly button: SlotView.SlotBuilder<M>;
|
|
703
|
+
readonly danger: SlotView.SlotBuilder<M>;
|
|
704
|
+
}
|
|
535
705
|
//#endregion
|
|
536
706
|
//#region src/kinds.d.ts
|
|
537
707
|
interface StateWords {
|
|
@@ -542,6 +712,8 @@ interface StateWords {
|
|
|
542
712
|
readonly Archived?: string;
|
|
543
713
|
readonly scheduled?: string;
|
|
544
714
|
readonly overdue?: string;
|
|
715
|
+
/** A state with what its schedule adds: `{state}` and `{schedule}`. */
|
|
716
|
+
readonly withSchedule?: string;
|
|
545
717
|
}
|
|
546
718
|
/** What `foldkit-mixins-form` gives a control's renderer, as far as these read it. */
|
|
547
719
|
interface ControlContext<Message> {
|
|
@@ -554,6 +726,12 @@ interface ControlContext<Message> {
|
|
|
554
726
|
readonly text: {
|
|
555
727
|
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
556
728
|
};
|
|
729
|
+
readonly group: {
|
|
730
|
+
readonly attrs: () => any;
|
|
731
|
+
};
|
|
732
|
+
readonly affix: {
|
|
733
|
+
readonly attrs: () => any;
|
|
734
|
+
};
|
|
557
735
|
};
|
|
558
736
|
readonly h: HtmlBuilder<Message>;
|
|
559
737
|
}
|
|
@@ -561,11 +739,14 @@ interface ControlContext<Message> {
|
|
|
561
739
|
interface DisplayContext<Message> {
|
|
562
740
|
readonly display: {
|
|
563
741
|
readonly kind: string;
|
|
564
|
-
readonly text: (value: unknown, words:
|
|
742
|
+
readonly text: (value: unknown, words: DisplayWords) => string;
|
|
565
743
|
};
|
|
566
744
|
readonly value: unknown;
|
|
567
|
-
readonly words:
|
|
745
|
+
readonly words: DisplayWords;
|
|
568
746
|
readonly h: HtmlBuilder<Message>;
|
|
747
|
+
readonly badge: {
|
|
748
|
+
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
749
|
+
};
|
|
569
750
|
}
|
|
570
751
|
//#endregion
|
|
571
752
|
//#region src/index.d.ts
|
|
@@ -641,9 +822,13 @@ export declare const Cms: {
|
|
|
641
822
|
*/
|
|
642
823
|
editor: <const Name extends string, FormModel, FormMessage extends {
|
|
643
824
|
readonly _tag: string;
|
|
644
|
-
}, Value>(name: Name, config: {
|
|
645
|
-
readonly content: EditorContent<FormModel, FormMessage, Value>;
|
|
646
|
-
readonly rest
|
|
825
|
+
}, Value, Resources = {}, Services = never>(name: Name, config: {
|
|
826
|
+
readonly content: EditorContent<FormModel, FormMessage, Value, Resources, Services>;
|
|
827
|
+
readonly rest? /**
|
|
828
|
+
* A pipe step naming the members of an Entity that play a CMS part. It is
|
|
829
|
+
* metadata: the Entity is the same Entity, and anything may read it with
|
|
830
|
+
* `Cms.rolesOf`. A member that cannot play the part is refused here.
|
|
831
|
+
*/ : import("effect/Duration").Input;
|
|
647
832
|
readonly version?: string;
|
|
648
833
|
readonly untitled?: string;
|
|
649
834
|
}) => {
|
|
@@ -676,7 +861,7 @@ export declare const Cms: {
|
|
|
676
861
|
readonly _tag: "ReloadAsked";
|
|
677
862
|
} | {
|
|
678
863
|
readonly _tag: "OverwriteAsked";
|
|
679
|
-
}, EditorOut,
|
|
864
|
+
}, EditorOut, Services, Services, void, [keyof Resources] extends [never] ? {} : Readonly<Record<string, never>>, {
|
|
680
865
|
open: (_: EditorModel<FormModel>, entry: string) => {
|
|
681
866
|
model: {
|
|
682
867
|
mode: "edit";
|
|
@@ -690,6 +875,7 @@ export declare const Cms: {
|
|
|
690
875
|
saveWanted: boolean;
|
|
691
876
|
publishId: string | null;
|
|
692
877
|
publishWanted: boolean;
|
|
878
|
+
submit: "idle" | "waiting" | "stopped";
|
|
693
879
|
scheduleAt: string | null;
|
|
694
880
|
otherId: string | null;
|
|
695
881
|
previewing: boolean;
|
|
@@ -710,6 +896,7 @@ export declare const Cms: {
|
|
|
710
896
|
saveWanted: boolean;
|
|
711
897
|
publishId: string | null;
|
|
712
898
|
publishWanted: boolean;
|
|
899
|
+
submit: "idle" | "waiting" | "stopped";
|
|
713
900
|
scheduleAt: string | null;
|
|
714
901
|
otherId: string | null;
|
|
715
902
|
previewing: boolean;
|
|
@@ -761,18 +948,52 @@ export declare const Cms: {
|
|
|
761
948
|
}>(update: (model: Root, message: Message) => Result) => (model: Root, message: Message) => Result;
|
|
762
949
|
canPreview: boolean;
|
|
763
950
|
previewing: (root: Root) => boolean;
|
|
764
|
-
pageId: (root: Root) => string
|
|
765
|
-
entry: (root: Root) => string
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
951
|
+
pageId: (root: Root) => import("effect/Option").Option<string>;
|
|
952
|
+
entry: (root: Root) => import("effect/Option").Option<string>;
|
|
953
|
+
storedEntry: (root: Root) => import("effect/Option").Option<string>;
|
|
954
|
+
resumed: (root: Root) => import("effect/Option").Option<Resumed>;
|
|
955
|
+
state: (root: Root) => import("effect/Option").Option<State>;
|
|
956
|
+
may: (root: Root, transition: Transition) => boolean;
|
|
957
|
+
error: (root: Root) => import("effect/Option").Option<import("foldkit-remote").RemoteError>;
|
|
769
958
|
status: (root: Root) => EditorStatus;
|
|
770
959
|
};
|
|
771
960
|
};
|
|
772
961
|
/** A form's Submodel view as its editor's, for `Bundle.withView`. */
|
|
773
962
|
editorView: <FormModel, FormMessage, ViewInputs>(view: import("foldkit/submodel").View<FormModel, FormMessage, ViewInputs>) => import("foldkit/submodel").View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>;
|
|
963
|
+
/**
|
|
964
|
+
* The entry-level views every studio draws, on its own slot builders: its
|
|
965
|
+
* state badge, its published revisions, what was published, and the rest of
|
|
966
|
+
* what can happen to it. Words for states come from `Cms.Display`, so a
|
|
967
|
+
* studio and its lists say them one way.
|
|
968
|
+
*/
|
|
969
|
+
stateBadge: <M>(badge: import("foldkit-mixins").SlotBuilder<M>, h: import("foldkit/html").HtmlBuilder<M>, state: import("effect/Option").Option<State>, attribute?: string) => import("foldkit/html").Html;
|
|
970
|
+
/** Whether the entry's state is one of the given tags; no state yet is none of them. */
|
|
971
|
+
stateIs: (state: import("effect/Option").Option<State>, ...tags: ReadonlyArray<State["_tag"]>) => boolean;
|
|
972
|
+
revisionsOf: <M, Value extends {
|
|
973
|
+
readonly revisions: ReadonlyArray<RevisionRow>;
|
|
974
|
+
}>(model: M, history: (model: M) => import("effect/Option").Option<{
|
|
975
|
+
readonly read: (model: M) => import("foldkit-remote").RemoteData<Value>;
|
|
976
|
+
}>) => RevisionHistory;
|
|
977
|
+
historyCard: <M>(slots: HistoryCardSlots<M>, h: import("foldkit/html").HtmlBuilder<M>, history: RevisionHistory, entry: {
|
|
978
|
+
readonly state: import("effect/Option").Option<State>;
|
|
979
|
+
readonly restore: (revision: number) => M;
|
|
980
|
+
readonly authorName: (name: string) => string;
|
|
981
|
+
}) => import("foldkit/html").Html;
|
|
982
|
+
moreCard: <M>(slots: MoreCardSlots<M>, h: import("foldkit/html").HtmlBuilder<M>, entry: {
|
|
983
|
+
readonly state: import("effect/Option").Option<State>;
|
|
984
|
+
readonly may: (transition: Transition) => boolean;
|
|
985
|
+
readonly asks: {
|
|
986
|
+
readonly discard: M;
|
|
987
|
+
readonly unpublish: M;
|
|
988
|
+
readonly archive: M;
|
|
989
|
+
readonly unarchive: M;
|
|
990
|
+
};
|
|
991
|
+
readonly archiveIcon: import("foldkit/html").Html;
|
|
992
|
+
}) => ReadonlyArray<import("foldkit/html").Html>;
|
|
774
993
|
/** The state of an entry, from what is known of it and a clock. */
|
|
775
994
|
state: (facts: Facts, now: Date) => State;
|
|
995
|
+
/** Every transition an author may ask, in order: what `allow` is asked about. */
|
|
996
|
+
transitions: readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"];
|
|
776
997
|
/** The transitions an entry offers now, before anyone asks who is asking. */
|
|
777
998
|
offers: (facts: Facts, now: Date, content: {
|
|
778
999
|
readonly roles: Roles;
|
|
@@ -859,6 +1080,7 @@ export declare const Cms: {
|
|
|
859
1080
|
readonly error: Schema.NullOr<Schema.String>;
|
|
860
1081
|
}>>;
|
|
861
1082
|
}>>;
|
|
1083
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
862
1084
|
}>;
|
|
863
1085
|
readonly Draft: Entity<"CmsDraft", {
|
|
864
1086
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -918,6 +1140,7 @@ export declare const Cms: {
|
|
|
918
1140
|
readonly error: Schema.NullOr<Schema.String>;
|
|
919
1141
|
}>>;
|
|
920
1142
|
}>>;
|
|
1143
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
921
1144
|
}>;
|
|
922
1145
|
readonly Draft: Entity<"CmsDraft", {
|
|
923
1146
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -955,6 +1178,7 @@ export declare const Cms: {
|
|
|
955
1178
|
readonly error: Schema.NullOr<Schema.String>;
|
|
956
1179
|
}>>;
|
|
957
1180
|
}>>;
|
|
1181
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
958
1182
|
}>;
|
|
959
1183
|
readonly Draft: Entity<"CmsDraft", {
|
|
960
1184
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -1033,6 +1257,7 @@ export declare const Cms: {
|
|
|
1033
1257
|
readonly error: Schema.NullOr<Schema.String>;
|
|
1034
1258
|
}>>;
|
|
1035
1259
|
}>>;
|
|
1260
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
1036
1261
|
}>;
|
|
1037
1262
|
readonly Draft: Entity<"CmsDraft", {
|
|
1038
1263
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -1216,5 +1441,5 @@ export declare const Cms: {
|
|
|
1216
1441
|
}) => import("effect/Effect").Effect<string | undefined, never, import("foldkit-remote").RemoteClient>);
|
|
1217
1442
|
};
|
|
1218
1443
|
//#endregion
|
|
1219
|
-
export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, Resumed, Schedule, State, StateTag, StateWords, Transition };
|
|
1444
|
+
export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, HistoryCardSlots, MoreCardSlots, Resumed, RevisionHistory, RevisionRow, Schedule, State, StateTag, StateWords, Transition };
|
|
1220
1445
|
//# sourceMappingURL=index.d.mts.map
|