foldkit-cms 0.2.0 → 0.4.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 +361 -128
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +240 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -16
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,79 @@ 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>;
|
|
517
|
+
readonly child: <Parent, ParentMessage, Child, ChildMessage, Services>(link: Link<Parent, ParentMessage, Child, ChildMessage, string>, update: (model: Child, message: ChildMessage) => Update.Return<Child, ChildMessage, Services>, view: (model: Child, h: HtmlBuilder<ChildMessage>) => Html, slotId: string) => {
|
|
518
|
+
readonly update: (parent: Parent, message: ChildMessage) => Update.Return<Parent, ParentMessage, Services>;
|
|
519
|
+
readonly view: PlacedView<Parent, ParentMessage, void>;
|
|
520
|
+
};
|
|
356
521
|
};
|
|
357
522
|
//#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
523
|
//#region ../bundle/src/collection.d.ts
|
|
423
524
|
declare const PlacedCollectionTypeId: unique symbol;
|
|
424
|
-
interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> {
|
|
425
|
-
/**
|
|
426
|
-
|
|
525
|
+
interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string, ParentSeed = Parent> {
|
|
526
|
+
/**
|
|
527
|
+
* The args every item's `init` and `update` receive: a static value, or a
|
|
528
|
+
* factory from the parent seed, computed once per initialization and
|
|
529
|
+
* retained. Adding items requires `initial`/`config` to have run; `update`
|
|
530
|
+
* on a Model no initialization produced derives per use instead.
|
|
531
|
+
*/
|
|
532
|
+
readonly args?: ArgsSource<ParentSeed, Args>;
|
|
427
533
|
/** Handles an item's OutMessage in parent terms, with the item already written back. */
|
|
428
534
|
readonly onOut?: (outMessage: OutMessage, key: Key, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
535
|
+
/** Observes each item's Messages in parent terms, after the item has handled it and its `onOut` has run. */
|
|
536
|
+
readonly onMessage?: (message: Message, key: Key) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
429
537
|
/** Prefix for the collection's Subscription keys. Defaults to `Name@path[]`. */
|
|
430
538
|
readonly key?: string;
|
|
431
539
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
432
540
|
}
|
|
433
541
|
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
542
|
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> {
|
|
543
|
+
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
544
|
readonly [PlacedCollectionTypeId]: typeof PlacedCollectionTypeId;
|
|
437
545
|
/** Types only: the record field this collection owns, or `string` when unknown. */
|
|
438
546
|
readonly field?: Field;
|
|
547
|
+
/** Types only: the parent Message tag this collection routes, or `string` when unknown. */
|
|
548
|
+
readonly claims?: Claimed;
|
|
439
549
|
readonly name: Name;
|
|
440
550
|
/** `Name@path[]`, or the configured `key`: the prefix of every Subscription key. */
|
|
441
551
|
readonly key: string;
|
|
442
552
|
/** The encoded args as text, when the bundle has an args Schema. */
|
|
443
553
|
readonly argsSummary: string | undefined;
|
|
554
|
+
/** Whether `args` was given as a seed factory; resolved once per initialization. */
|
|
555
|
+
readonly hasDynamicArgs: boolean;
|
|
556
|
+
/**
|
|
557
|
+
* Derives the factory's args from `seed` and retains them for `add`,
|
|
558
|
+
* `update`, and Subscriptions. A no-op for static args.
|
|
559
|
+
*/
|
|
560
|
+
readonly resolveArgs: (seed: unknown) => void;
|
|
444
561
|
readonly link: CollectionLink<Parent, ParentMessage, Model, Message, Key>;
|
|
445
562
|
/** Folds the Message into its item; `None` when it is not this collection's. A missing key leaves the parent unchanged. */
|
|
446
563
|
readonly update: (parent: Parent, message: AnyMessage) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
@@ -461,6 +578,11 @@ interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Me
|
|
|
461
578
|
}
|
|
462
579
|
//#endregion
|
|
463
580
|
//#region ../bundle/src/bundle.d.ts
|
|
581
|
+
/**
|
|
582
|
+
* The parent seed a factory observes: the parent without the placement's own
|
|
583
|
+
* field, or the whole parent where the field is unknown (`string`).
|
|
584
|
+
*/
|
|
585
|
+
type SeedFor<Parent, Field extends string> = string extends Field ? Parent : Omit<Parent, Field>;
|
|
464
586
|
declare const BundleTypeId: unique symbol;
|
|
465
587
|
/** A child Managed Resource entry: its requirements are an `Option`, so the entry can release. */
|
|
466
588
|
type ResourceEntry<Model, Message> = ManagedResource.Entry<Model, Message, Option.Option<any>, any, any>;
|
|
@@ -494,44 +616,96 @@ interface Bundle$1<Name extends string, Args, Model, Message extends AnyMessage,
|
|
|
494
616
|
*/
|
|
495
617
|
readonly with: (args: Args) => Bundle$1<Name, void, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>;
|
|
496
618
|
/** 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
|
|
619
|
+
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
620
|
/** 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
|
|
621
|
+
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
622
|
}
|
|
501
623
|
/**
|
|
502
624
|
* What placing needs: `args` when `init` takes them, and `onOut` when the
|
|
503
625
|
* bundle has an OutMessage, so an OutMessage is never dropped by omission.
|
|
626
|
+
* `args` is a static value or a factory from the parent seed (the parent
|
|
627
|
+
* without this placement's own field); the seed type defaults to the whole
|
|
628
|
+
* parent where the field is unknown.
|
|
504
629
|
*/
|
|
505
|
-
type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = {
|
|
630
|
+
type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed = Parent> = {
|
|
506
631
|
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
507
632
|
readonly key?: string;
|
|
508
633
|
/** A gate beside the Link's own: the child's Subscriptions and resources run only while both hold. */
|
|
509
634
|
readonly when?: (parent: Parent) => boolean;
|
|
635
|
+
/** Observes each of the child's Messages in parent terms, after the child handled it. */
|
|
636
|
+
readonly onMessage?: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>>['onMessage'];
|
|
510
637
|
} & ([Args] extends [void] ? {
|
|
511
638
|
readonly args?: never;
|
|
512
639
|
} : {
|
|
513
|
-
readonly args: Args
|
|
640
|
+
readonly args: ArgsSource<ParentSeed, Args>;
|
|
514
641
|
}) & ([OutMessage] extends [never] ? {
|
|
515
642
|
readonly onOut?: never;
|
|
516
643
|
} : {
|
|
517
|
-
readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>>['onOut'];
|
|
644
|
+
readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, ParentSeed>>['onOut'];
|
|
518
645
|
});
|
|
519
646
|
/** 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> = {
|
|
647
|
+
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>];
|
|
648
|
+
type EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string, ParentSeed = Parent> = {
|
|
522
649
|
readonly key?: string;
|
|
523
650
|
/** A gate per item beside the Link's own: an item's Subscriptions run only while both hold. */
|
|
524
651
|
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
652
|
+
/** Observes each item's Messages in parent terms, after the item handled it. */
|
|
653
|
+
readonly onMessage?: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>>['onMessage'];
|
|
525
654
|
} & ([Args] extends [void] ? {
|
|
526
655
|
readonly args?: never;
|
|
527
656
|
} : {
|
|
528
|
-
readonly args: Args
|
|
657
|
+
readonly args: ArgsSource<ParentSeed, Args>;
|
|
529
658
|
}) & ([OutMessage] extends [never] ? {
|
|
530
659
|
readonly onOut?: never;
|
|
531
660
|
} : {
|
|
532
|
-
readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>>['onOut'];
|
|
661
|
+
readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key, ParentSeed>>['onOut'];
|
|
533
662
|
});
|
|
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>];
|
|
663
|
+
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>];
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/views.d.ts
|
|
666
|
+
/** A published revision, as an editor's History lists it. */
|
|
667
|
+
interface RevisionRow {
|
|
668
|
+
readonly n: number;
|
|
669
|
+
readonly publishedAt: string;
|
|
670
|
+
readonly publishedBy: string | null;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* The open entry's published revisions, as they have been read. A posts'
|
|
674
|
+
* history and a pages' revisions read through the same shape, so one helper
|
|
675
|
+
* serves both: which read is the section's to name. A read that failed, or
|
|
676
|
+
* that has no answer yet, is its own state rather than an empty list, so the
|
|
677
|
+
* card cannot mistake either for nothing published.
|
|
678
|
+
*/
|
|
679
|
+
type RevisionHistory = {
|
|
680
|
+
readonly _tag: 'Ready';
|
|
681
|
+
readonly revisions: ReadonlyArray<RevisionRow>;
|
|
682
|
+
} | {
|
|
683
|
+
readonly _tag: 'Loading';
|
|
684
|
+
} | {
|
|
685
|
+
readonly _tag: 'Failed';
|
|
686
|
+
};
|
|
687
|
+
/** The builders `historyCard` reads. */
|
|
688
|
+
interface HistoryCardSlots<M> {
|
|
689
|
+
readonly card: SlotView.SlotBuilder<M>;
|
|
690
|
+
readonly cardTitle: SlotView.SlotBuilder<M>;
|
|
691
|
+
readonly muted: SlotView.SlotBuilder<M>;
|
|
692
|
+
readonly timeline: SlotView.SlotBuilder<M>;
|
|
693
|
+
readonly revision: SlotView.SlotBuilder<M>;
|
|
694
|
+
readonly revisionMark: SlotView.SlotBuilder<M>;
|
|
695
|
+
readonly revisionBody: SlotView.SlotBuilder<M>;
|
|
696
|
+
readonly revisionTitle: SlotView.SlotBuilder<M>;
|
|
697
|
+
readonly revisionLive: SlotView.SlotBuilder<M>;
|
|
698
|
+
readonly revisionMeta: SlotView.SlotBuilder<M>;
|
|
699
|
+
readonly revisionRestore: SlotView.SlotBuilder<M>;
|
|
700
|
+
}
|
|
701
|
+
/** The builders `moreCard` reads. */
|
|
702
|
+
interface MoreCardSlots<M> {
|
|
703
|
+
readonly card: SlotView.SlotBuilder<M>;
|
|
704
|
+
readonly cardTitle: SlotView.SlotBuilder<M>;
|
|
705
|
+
readonly toolbar: SlotView.SlotBuilder<M>;
|
|
706
|
+
readonly button: SlotView.SlotBuilder<M>;
|
|
707
|
+
readonly danger: SlotView.SlotBuilder<M>;
|
|
708
|
+
}
|
|
535
709
|
//#endregion
|
|
536
710
|
//#region src/kinds.d.ts
|
|
537
711
|
interface StateWords {
|
|
@@ -542,6 +716,8 @@ interface StateWords {
|
|
|
542
716
|
readonly Archived?: string;
|
|
543
717
|
readonly scheduled?: string;
|
|
544
718
|
readonly overdue?: string;
|
|
719
|
+
/** A state with what its schedule adds: `{state}` and `{schedule}`. */
|
|
720
|
+
readonly withSchedule?: string;
|
|
545
721
|
}
|
|
546
722
|
/** What `foldkit-mixins-form` gives a control's renderer, as far as these read it. */
|
|
547
723
|
interface ControlContext<Message> {
|
|
@@ -554,6 +730,12 @@ interface ControlContext<Message> {
|
|
|
554
730
|
readonly text: {
|
|
555
731
|
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
556
732
|
};
|
|
733
|
+
readonly group: {
|
|
734
|
+
readonly attrs: () => any;
|
|
735
|
+
};
|
|
736
|
+
readonly affix: {
|
|
737
|
+
readonly attrs: () => any;
|
|
738
|
+
};
|
|
557
739
|
};
|
|
558
740
|
readonly h: HtmlBuilder<Message>;
|
|
559
741
|
}
|
|
@@ -561,11 +743,14 @@ interface ControlContext<Message> {
|
|
|
561
743
|
interface DisplayContext<Message> {
|
|
562
744
|
readonly display: {
|
|
563
745
|
readonly kind: string;
|
|
564
|
-
readonly text: (value: unknown, words:
|
|
746
|
+
readonly text: (value: unknown, words: DisplayWords) => string;
|
|
565
747
|
};
|
|
566
748
|
readonly value: unknown;
|
|
567
|
-
readonly words:
|
|
749
|
+
readonly words: DisplayWords;
|
|
568
750
|
readonly h: HtmlBuilder<Message>;
|
|
751
|
+
readonly badge: {
|
|
752
|
+
readonly attrs: (attrs: ReadonlyArray<any>) => any;
|
|
753
|
+
};
|
|
569
754
|
}
|
|
570
755
|
//#endregion
|
|
571
756
|
//#region src/index.d.ts
|
|
@@ -641,9 +826,13 @@ export declare const Cms: {
|
|
|
641
826
|
*/
|
|
642
827
|
editor: <const Name extends string, FormModel, FormMessage extends {
|
|
643
828
|
readonly _tag: string;
|
|
644
|
-
}, Value>(name: Name, config: {
|
|
645
|
-
readonly content: EditorContent<FormModel, FormMessage, Value>;
|
|
646
|
-
readonly rest
|
|
829
|
+
}, Value, Resources = {}, Services = never>(name: Name, config: {
|
|
830
|
+
readonly content: EditorContent<FormModel, FormMessage, Value, Resources, Services>;
|
|
831
|
+
readonly rest? /**
|
|
832
|
+
* A pipe step naming the members of an Entity that play a CMS part. It is
|
|
833
|
+
* metadata: the Entity is the same Entity, and anything may read it with
|
|
834
|
+
* `Cms.rolesOf`. A member that cannot play the part is refused here.
|
|
835
|
+
*/ : import("effect/Duration").Input;
|
|
647
836
|
readonly version?: string;
|
|
648
837
|
readonly untitled?: string;
|
|
649
838
|
}) => {
|
|
@@ -676,7 +865,7 @@ export declare const Cms: {
|
|
|
676
865
|
readonly _tag: "ReloadAsked";
|
|
677
866
|
} | {
|
|
678
867
|
readonly _tag: "OverwriteAsked";
|
|
679
|
-
}, EditorOut,
|
|
868
|
+
}, EditorOut, Services, Services, void, [keyof Resources] extends [never] ? {} : Readonly<Record<string, never>>, {
|
|
680
869
|
open: (_: EditorModel<FormModel>, entry: string) => {
|
|
681
870
|
model: {
|
|
682
871
|
mode: "edit";
|
|
@@ -690,6 +879,7 @@ export declare const Cms: {
|
|
|
690
879
|
saveWanted: boolean;
|
|
691
880
|
publishId: string | null;
|
|
692
881
|
publishWanted: boolean;
|
|
882
|
+
submit: "idle" | "waiting" | "stopped";
|
|
693
883
|
scheduleAt: string | null;
|
|
694
884
|
otherId: string | null;
|
|
695
885
|
previewing: boolean;
|
|
@@ -710,6 +900,7 @@ export declare const Cms: {
|
|
|
710
900
|
saveWanted: boolean;
|
|
711
901
|
publishId: string | null;
|
|
712
902
|
publishWanted: boolean;
|
|
903
|
+
submit: "idle" | "waiting" | "stopped";
|
|
713
904
|
scheduleAt: string | null;
|
|
714
905
|
otherId: string | null;
|
|
715
906
|
previewing: boolean;
|
|
@@ -761,18 +952,56 @@ export declare const Cms: {
|
|
|
761
952
|
}>(update: (model: Root, message: Message) => Result) => (model: Root, message: Message) => Result;
|
|
762
953
|
canPreview: boolean;
|
|
763
954
|
previewing: (root: Root) => boolean;
|
|
764
|
-
pageId: (root: Root) => string
|
|
765
|
-
entry: (root: Root) => string
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
955
|
+
pageId: (root: Root) => import("effect/Option").Option<string>;
|
|
956
|
+
entry: (root: Root) => import("effect/Option").Option<string>;
|
|
957
|
+
storedEntry: (root: Root) => import("effect/Option").Option<string>;
|
|
958
|
+
resumed: (root: Root) => import("effect/Option").Option<Resumed>;
|
|
959
|
+
state: (root: Root) => import("effect/Option").Option<State>;
|
|
960
|
+
may: (root: Root, transition: Transition) => boolean;
|
|
961
|
+
error: (root: Root) => import("effect/Option").Option<import("foldkit-remote").RemoteError>;
|
|
769
962
|
status: (root: Root) => EditorStatus;
|
|
770
963
|
};
|
|
771
964
|
};
|
|
772
965
|
/** A form's Submodel view as its editor's, for `Bundle.withView`. */
|
|
773
966
|
editorView: <FormModel, FormMessage, ViewInputs>(view: import("foldkit/submodel").View<FormModel, FormMessage, ViewInputs>) => import("foldkit/submodel").View<EditorModel<FormModel>, FormMessage | EditorMessage, ViewInputs>;
|
|
967
|
+
/**
|
|
968
|
+
* The entry-level views every studio draws, on its own slot builders: its
|
|
969
|
+
* state badge, its published revisions, what was published, and the rest of
|
|
970
|
+
* what can happen to it. Words for states come from `Cms.Display`, so a
|
|
971
|
+
* studio and its lists say them one way.
|
|
972
|
+
*/
|
|
973
|
+
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;
|
|
974
|
+
/** Whether the entry's state is one of the given tags; no state yet is none of them. */
|
|
975
|
+
stateIs: (state: import("effect/Option").Option<State>, ...tags: ReadonlyArray<State["_tag"]>) => boolean;
|
|
976
|
+
revisionsOf: <M, Value extends {
|
|
977
|
+
readonly revisions: ReadonlyArray<RevisionRow>;
|
|
978
|
+
}>(model: M, history: (model: M) => import("effect/Option").Option<{
|
|
979
|
+
readonly read: (model: M) => import("foldkit-remote").RemoteData<Value>;
|
|
980
|
+
}>) => RevisionHistory;
|
|
981
|
+
historyCard: <M>(slots: HistoryCardSlots<M>, h: import("foldkit/html").HtmlBuilder<M>, history: RevisionHistory, entry: {
|
|
982
|
+
readonly state: import("effect/Option").Option<State>;
|
|
983
|
+
readonly restore: (revision: number) => M;
|
|
984
|
+
readonly authorName: (name: string) => string;
|
|
985
|
+
readonly onRetry?: M | undefined;
|
|
986
|
+
readonly words?: {
|
|
987
|
+
readonly retry?: string | undefined;
|
|
988
|
+
} | undefined;
|
|
989
|
+
}) => import("foldkit/html").Html;
|
|
990
|
+
moreCard: <M>(slots: MoreCardSlots<M>, h: import("foldkit/html").HtmlBuilder<M>, entry: {
|
|
991
|
+
readonly state: import("effect/Option").Option<State>;
|
|
992
|
+
readonly may: (transition: Transition) => boolean;
|
|
993
|
+
readonly asks: {
|
|
994
|
+
readonly discard: M;
|
|
995
|
+
readonly unpublish: M;
|
|
996
|
+
readonly archive: M;
|
|
997
|
+
readonly unarchive: M;
|
|
998
|
+
};
|
|
999
|
+
readonly archiveIcon: import("foldkit/html").Html;
|
|
1000
|
+
}) => ReadonlyArray<import("foldkit/html").Html>;
|
|
774
1001
|
/** The state of an entry, from what is known of it and a clock. */
|
|
775
1002
|
state: (facts: Facts, now: Date) => State;
|
|
1003
|
+
/** Every transition an author may ask, in order: what `allow` is asked about. */
|
|
1004
|
+
transitions: readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"];
|
|
776
1005
|
/** The transitions an entry offers now, before anyone asks who is asking. */
|
|
777
1006
|
offers: (facts: Facts, now: Date, content: {
|
|
778
1007
|
readonly roles: Roles;
|
|
@@ -859,6 +1088,7 @@ export declare const Cms: {
|
|
|
859
1088
|
readonly error: Schema.NullOr<Schema.String>;
|
|
860
1089
|
}>>;
|
|
861
1090
|
}>>;
|
|
1091
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
862
1092
|
}>;
|
|
863
1093
|
readonly Draft: Entity<"CmsDraft", {
|
|
864
1094
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -918,6 +1148,7 @@ export declare const Cms: {
|
|
|
918
1148
|
readonly error: Schema.NullOr<Schema.String>;
|
|
919
1149
|
}>>;
|
|
920
1150
|
}>>;
|
|
1151
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
921
1152
|
}>;
|
|
922
1153
|
readonly Draft: Entity<"CmsDraft", {
|
|
923
1154
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -955,6 +1186,7 @@ export declare const Cms: {
|
|
|
955
1186
|
readonly error: Schema.NullOr<Schema.String>;
|
|
956
1187
|
}>>;
|
|
957
1188
|
}>>;
|
|
1189
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
958
1190
|
}>;
|
|
959
1191
|
readonly Draft: Entity<"CmsDraft", {
|
|
960
1192
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -1033,6 +1265,7 @@ export declare const Cms: {
|
|
|
1033
1265
|
readonly error: Schema.NullOr<Schema.String>;
|
|
1034
1266
|
}>>;
|
|
1035
1267
|
}>>;
|
|
1268
|
+
readonly may: import("foldkit-entity").DerivedSpec<Schema.$Array<Schema.Literals<readonly ["save", "discard", "publish", "schedule", "unschedule", "unpublish", "archive", "unarchive", "restore"]>>>;
|
|
1036
1269
|
}>;
|
|
1037
1270
|
readonly Draft: Entity<"CmsDraft", {
|
|
1038
1271
|
/** The entry's id: an entry has at most one draft. */
|
|
@@ -1216,5 +1449,5 @@ export declare const Cms: {
|
|
|
1216
1449
|
}) => import("effect/Effect").Effect<string | undefined, never, import("foldkit-remote").RemoteClient>);
|
|
1217
1450
|
};
|
|
1218
1451
|
//#endregion
|
|
1219
|
-
export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, Resumed, Schedule, State, StateTag, StateWords, Transition };
|
|
1452
|
+
export type { ControlContext, DisplayContext, EditorContent, EditorDomain, EditorForm, EditorMessage, EditorModel, EditorOut, EditorStatus, Facts, HistoryCardSlots, MoreCardSlots, Resumed, RevisionHistory, RevisionRow, Schedule, State, StateTag, StateWords, Transition };
|
|
1220
1453
|
//# sourceMappingURL=index.d.mts.map
|