foldkit-builder 0.6.0 → 0.7.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 +56 -2
- package/dist/index.d.ts +135 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -69
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +9 -9
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -39,7 +39,37 @@ Form: Control Message carries it; a change of Document is an edit; the rest is n
|
|
|
39
39
|
|
|
40
40
|
## Sixty seconds
|
|
41
41
|
|
|
42
|
+
<!-- docs-check
|
|
43
|
+
import { Schema } from 'effect'
|
|
44
|
+
import { Block, Catalog, Content, Region, Composition } from 'foldkit-composition'
|
|
45
|
+
import { Renderer } from 'foldkit-composition/foldkit'
|
|
46
|
+
import { Entity } from 'foldkit-entity'
|
|
47
|
+
const Heading = Block.define('Heading', {
|
|
48
|
+
Props: Schema.Struct({ text: Schema.String }),
|
|
49
|
+
provides: [Content.Flow],
|
|
50
|
+
})
|
|
51
|
+
const Section = Block.define('Section', {
|
|
52
|
+
Props: Schema.Struct({}),
|
|
53
|
+
regions: { body: Region.many({ accepts: [Content.Flow] }) },
|
|
54
|
+
provides: [Content.Section],
|
|
55
|
+
})
|
|
56
|
+
const Site = Catalog.make({ blocks: [Heading, Section], roots: [Content.Section] })
|
|
57
|
+
const SiteRenderer = Renderer.make(Site, {
|
|
58
|
+
Heading: ({ field, h }) => h.h2([], [field('text')]),
|
|
59
|
+
Section: ({ regions, h }) => h.section([], [...regions.body]),
|
|
60
|
+
})
|
|
61
|
+
const Page = Entity.define(
|
|
62
|
+
'Page',
|
|
63
|
+
Schema.Struct({ id: Schema.String, document: Composition.Document }),
|
|
64
|
+
)
|
|
65
|
+
const PageInput = Entity.input(
|
|
66
|
+
Page,
|
|
67
|
+
Schema.Struct({ document: Composition.Document.check(Composition.valid(Site)) }),
|
|
68
|
+
)
|
|
69
|
+
-->
|
|
70
|
+
|
|
42
71
|
```ts
|
|
72
|
+
import { Form } from 'foldkit-form'
|
|
43
73
|
import { Builder } from 'foldkit-builder'
|
|
44
74
|
|
|
45
75
|
const PageBuilder = Builder.make('PageBuilder', {
|
|
@@ -74,10 +104,11 @@ const PageForm = Form.make('PageForm', PageInput, {
|
|
|
74
104
|
| `InsertAsked({ block, at })` | a new node with the Block's starting props, once an id is minted |
|
|
75
105
|
| `DuplicateAsked({ id, at })` | a copy of a node and what it holds, once ids are minted |
|
|
76
106
|
| `PatternAsked({ pattern, at })` | one of the Catalog's patterns, once ids are minted for its nodes |
|
|
77
|
-
| `CopyAsked({ id })`, `CutAsked({ id })`, `PasteAsked()`, `ClipboardRead({ text })` | the clipboard: see below |
|
|
107
|
+
| `CopyAsked({ id })`, `CutAsked({ id })`, `Copied({ said })`, `PasteAsked()`, `ClipboardRead({ text })` | the clipboard: see below |
|
|
78
108
|
| `EditingAsked({ field })`, `FieldTyped({ field, text })`, `EditingCommitted({ field, text })`, `EditingCancelled({ field })` | text edited in place: see below |
|
|
79
109
|
| `Minted({ ids, request })` | the ids a request waited for, answered by a Command |
|
|
80
110
|
| `Selected({ id })`, `Deselected()`, `Hovered({ id })`, `Unhovered()` | what the inspector and the node actions work on |
|
|
111
|
+
| `RowPressed({ id })`, `RowToggled({ id })` | a layers row pressed (made current, so selected, keeping the panel) and its expander (opened or shut by the tree's state) |
|
|
81
112
|
| `Undid()`, `Redid()` | a step of the page's undo history |
|
|
82
113
|
| `PanelChosen({ panel })`, `ViewportChosen({ viewport })` | the editor's own choices |
|
|
83
114
|
| `DragStarted({ source })`, `DraggedOver({ id, zone })`, `DraggedOverRegion({ id, region })`, `DraggedOff()`, `DraggedOverPage()`, `DragDropped()`, `DragCancelled()` | a pointer drag: see below |
|
|
@@ -299,6 +330,24 @@ selection is read back out into the URL.
|
|
|
299
330
|
In, from the parent's own `update`, for a form key named `document` placed as
|
|
300
331
|
`page`:
|
|
301
332
|
|
|
333
|
+
<!-- docs-check
|
|
334
|
+
import { Effect, Option, Schema, Stream } from 'effect'
|
|
335
|
+
import { Bundle } from 'foldkit-bundle'
|
|
336
|
+
import { NodeId } from 'foldkit-composition'
|
|
337
|
+
import { defineMessageUnion } from 'foldkit/message'
|
|
338
|
+
import * as Navigation from 'foldkit/navigation'
|
|
339
|
+
import * as Subscription from 'foldkit/subscription'
|
|
340
|
+
import { Url } from 'foldkit/url'
|
|
341
|
+
import { Message as BuilderMessage } from 'foldkit-builder'
|
|
342
|
+
const Slot = Bundle.declare(PageForm.bundle, 'page')
|
|
343
|
+
const Model = Schema.Struct({ ...Slot.fields })
|
|
344
|
+
type Model = typeof Model.Type
|
|
345
|
+
const Message = defineMessageUnion({ ...Slot.cases, UrlChanged: { url: Url } })
|
|
346
|
+
type Message = typeof Message.Type
|
|
347
|
+
const Parent = Bundle.parent({ Model, Message })
|
|
348
|
+
const placements = Parent.assemble(Parent.at(Slot, { onOut: () => model => ({ model }) }))
|
|
349
|
+
-->
|
|
350
|
+
|
|
302
351
|
```ts
|
|
303
352
|
const blockIn = (url: Url): Option.Option<NodeId> =>
|
|
304
353
|
Option.map(
|
|
@@ -366,7 +415,12 @@ keeps what the author previews the page as in `preview`, by context key,
|
|
|
366
415
|
starting from the `preview` it was made with:
|
|
367
416
|
|
|
368
417
|
```ts
|
|
369
|
-
Builder.make('PageBuilder', {
|
|
418
|
+
Builder.make('PageBuilder', {
|
|
419
|
+
catalog: Site,
|
|
420
|
+
renderer: SiteRenderer,
|
|
421
|
+
starters: { Section: {}, Heading: { text: 'New heading' } },
|
|
422
|
+
preview: { audience: 'guest' },
|
|
423
|
+
})
|
|
370
424
|
```
|
|
371
425
|
|
|
372
426
|
The page is drawn in edit mode with `preview` as its context, so a node hidden
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AnyBlock, Catalog, Document, NodeId, Operation, PropsOf } from "foldkit
|
|
|
4
4
|
import { Renderer } from "foldkit-composition/foldkit";
|
|
5
5
|
import { Settings, Settings as Settings$1, controlOf, controls, inputOf, settingsOf } from "./settings.js";
|
|
6
6
|
import { EditWords, EditWords as EditWords$1, editWords } from "./words.js";
|
|
7
|
-
import { TreeNavigation } from "foldkit-primitives/interaction";
|
|
7
|
+
import { LiveAnnounce, TreeNavigation } from "foldkit-primitives/interaction";
|
|
8
8
|
import { KeyboardModifiers } from "foldkit/html";
|
|
9
9
|
import * as Submodel from "foldkit/submodel";
|
|
10
10
|
export declare const Panel: Schema.Literals<readonly ["insert", "layers", "properties"]>;
|
|
@@ -24,7 +24,76 @@ export declare const Layers: Bundle.Declared<Bundle.Bundle<"TreeNavigation", {
|
|
|
24
24
|
} | {
|
|
25
25
|
readonly _tag: "Opened";
|
|
26
26
|
readonly id: string;
|
|
27
|
-
}, never, never, never, import("foldkit-bundle").NoView, {}, {
|
|
27
|
+
}, never, never, never, import("foldkit-bundle").NoView, {}, {
|
|
28
|
+
focus: (model: TreeNavigation.Model, id: string) => Readonly<{
|
|
29
|
+
model: {
|
|
30
|
+
readonly current: string | null;
|
|
31
|
+
readonly toggled: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
commands?: import("foldkit/update").Commands<{
|
|
34
|
+
readonly _tag: "Closed";
|
|
35
|
+
readonly id: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly _tag: "Focused";
|
|
38
|
+
readonly id: string;
|
|
39
|
+
} | {
|
|
40
|
+
readonly _tag: "Opened";
|
|
41
|
+
readonly id: string;
|
|
42
|
+
}, never>;
|
|
43
|
+
outMessage?: never;
|
|
44
|
+
}>;
|
|
45
|
+
open: (model: TreeNavigation.Model, id: string) => Readonly<{
|
|
46
|
+
model: {
|
|
47
|
+
readonly current: string | null;
|
|
48
|
+
readonly toggled: readonly string[];
|
|
49
|
+
};
|
|
50
|
+
commands?: import("foldkit/update").Commands<{
|
|
51
|
+
readonly _tag: "Closed";
|
|
52
|
+
readonly id: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly _tag: "Focused";
|
|
55
|
+
readonly id: string;
|
|
56
|
+
} | {
|
|
57
|
+
readonly _tag: "Opened";
|
|
58
|
+
readonly id: string;
|
|
59
|
+
}, never>;
|
|
60
|
+
outMessage?: never;
|
|
61
|
+
}>;
|
|
62
|
+
close: (model: TreeNavigation.Model, id: string) => Readonly<{
|
|
63
|
+
model: {
|
|
64
|
+
readonly current: string | null;
|
|
65
|
+
readonly toggled: readonly string[];
|
|
66
|
+
};
|
|
67
|
+
commands?: import("foldkit/update").Commands<{
|
|
68
|
+
readonly _tag: "Closed";
|
|
69
|
+
readonly id: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly _tag: "Focused";
|
|
72
|
+
readonly id: string;
|
|
73
|
+
} | {
|
|
74
|
+
readonly _tag: "Opened";
|
|
75
|
+
readonly id: string;
|
|
76
|
+
}, never>;
|
|
77
|
+
outMessage?: never;
|
|
78
|
+
}>;
|
|
79
|
+
toggle: (model: TreeNavigation.Model, id: string) => Readonly<{
|
|
80
|
+
model: {
|
|
81
|
+
readonly current: string | null;
|
|
82
|
+
readonly toggled: readonly string[];
|
|
83
|
+
};
|
|
84
|
+
commands?: import("foldkit/update").Commands<{
|
|
85
|
+
readonly _tag: "Closed";
|
|
86
|
+
readonly id: string;
|
|
87
|
+
} | {
|
|
88
|
+
readonly _tag: "Focused";
|
|
89
|
+
readonly id: string;
|
|
90
|
+
} | {
|
|
91
|
+
readonly _tag: "Opened";
|
|
92
|
+
readonly id: string;
|
|
93
|
+
}, never>;
|
|
94
|
+
outMessage?: never;
|
|
95
|
+
}>;
|
|
96
|
+
}>, "layers">;
|
|
28
97
|
export declare const layersArgs: TreeNavigation.Args;
|
|
29
98
|
/** What the editor says to assistive technology: a move, an insert, a refusal. */
|
|
30
99
|
export declare const Announcer: Bundle.Declared<Bundle.Bundle<"LiveAnnounce", {
|
|
@@ -48,7 +117,31 @@ export declare const Announcer: Bundle.Declared<Bundle.Bundle<"LiveAnnounce", {
|
|
|
48
117
|
} | {
|
|
49
118
|
readonly _tag: "Read";
|
|
50
119
|
readonly generation: number;
|
|
51
|
-
}, never, never, never, import("foldkit-bundle").NoView, {}, {
|
|
120
|
+
}, never, never, never, import("foldkit-bundle").NoView, {}, {
|
|
121
|
+
announce: (model: LiveAnnounce.Model, text: string, politeness?: LiveAnnounce.Politeness) => Readonly<{
|
|
122
|
+
model: {
|
|
123
|
+
readonly polite: string;
|
|
124
|
+
readonly assertive: string;
|
|
125
|
+
readonly pending: {
|
|
126
|
+
readonly message: string;
|
|
127
|
+
readonly politeness: "assertive" | "polite";
|
|
128
|
+
} | null;
|
|
129
|
+
readonly generation: number;
|
|
130
|
+
};
|
|
131
|
+
commands?: import("foldkit/update").Commands<{
|
|
132
|
+
readonly _tag: "Announced";
|
|
133
|
+
readonly message: string;
|
|
134
|
+
readonly politeness: "assertive" | "polite";
|
|
135
|
+
} | {
|
|
136
|
+
readonly _tag: "Cleared";
|
|
137
|
+
readonly generation: number;
|
|
138
|
+
} | {
|
|
139
|
+
readonly _tag: "Read";
|
|
140
|
+
readonly generation: number;
|
|
141
|
+
}, never>;
|
|
142
|
+
outMessage?: never;
|
|
143
|
+
}>;
|
|
144
|
+
}>, "announcer">;
|
|
52
145
|
/** Where over a node a drop lands: before it, inside it, or after it. */
|
|
53
146
|
export declare const DropZone: Schema.Literals<readonly ["before", "inside", "after"]>;
|
|
54
147
|
export type DropZone = typeof DropZone.Type;
|
|
@@ -282,6 +375,14 @@ export declare const Message: import("foldkit/message").MessageUnion<{
|
|
|
282
375
|
};
|
|
283
376
|
/** Nothing is selected. */
|
|
284
377
|
readonly Deselected: {};
|
|
378
|
+
/** A layers row pressed: it becomes current, as the keys make one, and so selected. */
|
|
379
|
+
readonly RowPressed: {
|
|
380
|
+
id: Schema.brand<Schema.NonEmptyString, "@foldkit-composition/NodeId">;
|
|
381
|
+
};
|
|
382
|
+
/** A layers row's expander pressed: the row opens if shut and shuts if open. */
|
|
383
|
+
readonly RowToggled: {
|
|
384
|
+
id: Schema.brand<Schema.NonEmptyString, "@foldkit-composition/NodeId">;
|
|
385
|
+
};
|
|
285
386
|
readonly Hovered: {
|
|
286
387
|
id: Schema.brand<Schema.NonEmptyString, "@foldkit-composition/NodeId">;
|
|
287
388
|
};
|
|
@@ -334,6 +435,10 @@ export declare const Message: import("foldkit/message").MessageUnion<{
|
|
|
334
435
|
};
|
|
335
436
|
/** A paste: the system clipboard is read, and what it holds goes in by the selection. */
|
|
336
437
|
readonly PasteAsked: {};
|
|
438
|
+
/** A copy or cut reached the system clipboard: `said` tells assistive technology. */
|
|
439
|
+
readonly Copied: {
|
|
440
|
+
said: Schema.String;
|
|
441
|
+
};
|
|
337
442
|
/** What the system clipboard held for a paste; none when it could not be read. */
|
|
338
443
|
readonly ClipboardRead: {
|
|
339
444
|
text: Schema.OptionFromNullOr<Schema.String>;
|
|
@@ -720,6 +825,9 @@ export declare const Builder: {
|
|
|
720
825
|
} | {
|
|
721
826
|
readonly _tag: "ClipboardRead";
|
|
722
827
|
readonly text: Option.Option<string>;
|
|
828
|
+
} | {
|
|
829
|
+
readonly _tag: "Copied";
|
|
830
|
+
readonly said: string;
|
|
723
831
|
} | {
|
|
724
832
|
readonly _tag: "CopyAsked";
|
|
725
833
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
@@ -929,6 +1037,12 @@ export declare const Builder: {
|
|
|
929
1037
|
readonly key: string;
|
|
930
1038
|
} | {
|
|
931
1039
|
readonly _tag: "Redid";
|
|
1040
|
+
} | {
|
|
1041
|
+
readonly _tag: "RowPressed";
|
|
1042
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
1043
|
+
} | {
|
|
1044
|
+
readonly _tag: "RowToggled";
|
|
1045
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
932
1046
|
} | {
|
|
933
1047
|
readonly _tag: "Selected";
|
|
934
1048
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
@@ -1232,6 +1346,9 @@ export declare const Builder: {
|
|
|
1232
1346
|
} | {
|
|
1233
1347
|
readonly _tag: "ClipboardRead";
|
|
1234
1348
|
readonly text: Option.Option<string>;
|
|
1349
|
+
} | {
|
|
1350
|
+
readonly _tag: "Copied";
|
|
1351
|
+
readonly said: string;
|
|
1235
1352
|
} | {
|
|
1236
1353
|
readonly _tag: "CopyAsked";
|
|
1237
1354
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
@@ -1441,6 +1558,12 @@ export declare const Builder: {
|
|
|
1441
1558
|
readonly key: string;
|
|
1442
1559
|
} | {
|
|
1443
1560
|
readonly _tag: "Redid";
|
|
1561
|
+
} | {
|
|
1562
|
+
readonly _tag: "RowPressed";
|
|
1563
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
1564
|
+
} | {
|
|
1565
|
+
readonly _tag: "RowToggled";
|
|
1566
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
1444
1567
|
} | {
|
|
1445
1568
|
readonly _tag: "Selected";
|
|
1446
1569
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
@@ -1623,6 +1746,9 @@ export declare const Builder: {
|
|
|
1623
1746
|
} | {
|
|
1624
1747
|
readonly _tag: "ClipboardRead";
|
|
1625
1748
|
readonly text: Option.Option<string>;
|
|
1749
|
+
} | {
|
|
1750
|
+
readonly _tag: "Copied";
|
|
1751
|
+
readonly said: string;
|
|
1626
1752
|
} | {
|
|
1627
1753
|
readonly _tag: "CopyAsked";
|
|
1628
1754
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
@@ -1832,6 +1958,12 @@ export declare const Builder: {
|
|
|
1832
1958
|
readonly key: string;
|
|
1833
1959
|
} | {
|
|
1834
1960
|
readonly _tag: "Redid";
|
|
1961
|
+
} | {
|
|
1962
|
+
readonly _tag: "RowPressed";
|
|
1963
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
1964
|
+
} | {
|
|
1965
|
+
readonly _tag: "RowToggled";
|
|
1966
|
+
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
|
1835
1967
|
} | {
|
|
1836
1968
|
readonly _tag: "Selected";
|
|
1837
1969
|
readonly id: string & import("effect/Brand").Brand<"@foldkit-composition/NodeId">;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Settings","EditWords"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;qBA4Ca,OAAK,OAAA;qBACL,UAAQ,OAAA;;qBAGR,QAAM,OAAA,SAAA,OAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Settings","EditWords"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;qBA4Ca,OAAK,OAAA;qBACL,UAAQ,OAAA;;qBAGR,QAAM,OAAA,SAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBACN,YAAY,eAAe;;qBAG3B,WAAS,OAAA,SAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAIT,UAAQ,OAAA;YACT,kBAAkB,SAAS;;qBAG1B,YAAU,OAAA,gBAAA,OAAA;;;;;YAIX,oBAAoB,WAAW;;qBAG9B,MAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoBL,cAAc,KAAK;;qBAGlB,cAAY,OAAA,gBAAA,OAAA,QAAA,OAAA,QAAA,OAAA,SAAA,OAAA;YAMb,sBAAsB,aAAa;qBAElC,OAAK,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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xD,WAAA,UAAA,UAAQ,UAAY,OAAO,OAAO,SAAO,OAAS,mBAAc,OAAA;;;;;;;;;;IAG/D,YAAA,UAAA,UAAQ,UAAY,OAAO,OAAO,SAAO,oBAAiB,OAAA;;;;;;;;;;;IAS7D,SAAA,UAAA,UAAQ,SAAW,YAAU,QAAU,QAAM,MAAQ,aAAQ,OAAA;;;;;;;;;;;;;IAhEzE,aAAA,OAAA,KAAK,yCAAuC,aACxC,WACA,sBACV,OAAO,OAAO;IAiBR,aAAA,OAAA,KAAK,mBAAiB,aAClB,WACA,sBACV,OAAO,OAAO;;;;;IAv7BR,aAAA,OAAA,KAAK,8CACX,OAAO,OAAO"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Option, Result, Schema } from "effect";
|
|
1
|
+
import { Effect, Match, Option, Result, Schema } from "effect";
|
|
2
2
|
import { Bundle } from "foldkit-bundle";
|
|
3
3
|
import { Block, Catalog, Composition, NodeId } from "foldkit-composition";
|
|
4
4
|
import { Renderer, fieldName, fieldOf } from "foldkit-composition/foldkit";
|
|
@@ -174,6 +174,10 @@ const Message = defineMessageUnion({
|
|
|
174
174
|
Selected: { id: NodeId },
|
|
175
175
|
/** Nothing is selected. */
|
|
176
176
|
Deselected: {},
|
|
177
|
+
/** A layers row pressed: it becomes current, as the keys make one, and so selected. */
|
|
178
|
+
RowPressed: { id: NodeId },
|
|
179
|
+
/** A layers row's expander pressed: the row opens if shut and shuts if open. */
|
|
180
|
+
RowToggled: { id: NodeId },
|
|
177
181
|
Hovered: { id: NodeId },
|
|
178
182
|
/** The pointer left every node. */
|
|
179
183
|
Unhovered: {},
|
|
@@ -200,6 +204,8 @@ const Message = defineMessageUnion({
|
|
|
200
204
|
CutAsked: { id: NodeId },
|
|
201
205
|
/** A paste: the system clipboard is read, and what it holds goes in by the selection. */
|
|
202
206
|
PasteAsked: {},
|
|
207
|
+
/** A copy or cut reached the system clipboard: `said` tells assistive technology. */
|
|
208
|
+
Copied: { said: Schema.String },
|
|
203
209
|
/** What the system clipboard held for a paste; none when it could not be read. */
|
|
204
210
|
ClipboardRead: { text: Schema.OptionFromNullOr(Schema.String) },
|
|
205
211
|
/**
|
|
@@ -287,7 +293,11 @@ const Parent = Bundle.parent({
|
|
|
287
293
|
Message
|
|
288
294
|
});
|
|
289
295
|
/** The layers' tree and the announcer, placed in the Builder's own Model. */
|
|
290
|
-
const
|
|
296
|
+
const LayersPlaced = Parent.at(Layers, { args: layersArgs });
|
|
297
|
+
const AnnouncerPlaced = Parent.at(Announcer, { args: announcerArgs });
|
|
298
|
+
const placements = Parent.assemble(LayersPlaced, AnnouncerPlaced);
|
|
299
|
+
/** The row a Message makes current in the layers: one the keys moved to, or one pressed. */
|
|
300
|
+
const focusedBy = (message) => Match.value(message).pipe(Match.tag("RowPressed", ({ id }) => Option.some(id)), Match.orElse(() => Option.flatMap(Layers.wrapper.fromParentMessage(message), (child) => Match.value(child).pipe(Match.tag("Focused", ({ id }) => Option.some(id)), Match.orElse(() => Option.none())))));
|
|
291
301
|
/** Props as a Document stores them, read from what a Block's Schema encoded. */
|
|
292
302
|
const storedProps = Schema.decodeUnknownResult(Composition.Node.fields.props);
|
|
293
303
|
/**
|
|
@@ -379,7 +389,10 @@ const landingBy = (catalog, document, dragged, target, zone, region) => {
|
|
|
379
389
|
return Option.map(named, (regionName) => Composition.region(target, regionName, without(holder.regions[regionName] ?? []).length));
|
|
380
390
|
};
|
|
381
391
|
const current = Option.flatMap(dragged.id, (id) => Option.fromUndefinedOr(Composition.index(document).get(id))).pipe(Option.getOrUndefined);
|
|
382
|
-
const stays = (at) => current !== void 0 && at.index === current.index && (at
|
|
392
|
+
const stays = (at) => current !== void 0 && at.index === current.index && Match.valueTags(at, {
|
|
393
|
+
Root: () => current.parent === void 0,
|
|
394
|
+
Region: ({ parent, region }) => parent === current.parent && region === current.region
|
|
395
|
+
});
|
|
383
396
|
const candidates = zone === "before" ? [{
|
|
384
397
|
at: beside(0),
|
|
385
398
|
zone
|
|
@@ -411,7 +424,7 @@ const documentOf = (model) => model.page.present;
|
|
|
411
424
|
* are one step, so typing a heading undoes as a whole. Everything else stands
|
|
412
425
|
* alone, which `History.push` takes as a `null` group.
|
|
413
426
|
*/
|
|
414
|
-
const groupOf = (op) => op.
|
|
427
|
+
const groupOf = (op) => Match.value(op).pipe(Match.tag("SetProp", ({ id, prop }) => `SetProp:${id}:${prop}`), Match.orElse(() => null));
|
|
415
428
|
/** The position right after a node, among its siblings. */
|
|
416
429
|
const after = (document, id) => {
|
|
417
430
|
const place = Composition.index(document).get(id);
|
|
@@ -526,7 +539,7 @@ const landing = (catalog, document, dragged, target, zone, region = Option.none(
|
|
|
526
539
|
return Option.none();
|
|
527
540
|
};
|
|
528
541
|
/** The node an Operation that creates nodes creates first, to select it. */
|
|
529
|
-
const created = (catalog, op) => op.
|
|
542
|
+
const created = (catalog, op) => Match.value(op).pipe(Match.tag("Insert", ({ id }) => Option.some(id)), Match.tag("InsertTree", ({ tree }) => Option.some(tree.root)), Match.tag("Duplicate", ({ id, ids }) => Option.fromUndefinedOr(ids[id])), Match.tag("UsePattern", (pattern) => patternRoot(catalog, pattern)), Match.orElse(() => Option.none()));
|
|
530
543
|
/** Whether a key press is `spec`. A letter is matched as either case. */
|
|
531
544
|
const pressed = (spec, key, modifiers) => spec.key.toLowerCase() === key.toLowerCase() && (spec.mod ?? false) === (modifiers.ctrlKey || modifiers.metaKey) && (spec.alt ?? false) === modifiers.altKey && (spec.shift === void 0 || spec.shift === modifiers.shiftKey);
|
|
532
545
|
const Builder = {
|
|
@@ -564,18 +577,12 @@ const Builder = {
|
|
|
564
577
|
clipboard: Option.none(),
|
|
565
578
|
editing: Option.none()
|
|
566
579
|
}).model;
|
|
567
|
-
/**
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
model: {
|
|
574
|
-
...model,
|
|
575
|
-
refused: Option.some(refusal)
|
|
576
|
-
},
|
|
577
|
-
commands: announce(refusal.message, "assertive")
|
|
578
|
-
});
|
|
580
|
+
/** `model`, with `text` said to assistive technology through the announcer. */
|
|
581
|
+
const announced = (model, text, politeness = "polite") => AnnouncerPlaced.helpers.announce(text, politeness)(model);
|
|
582
|
+
const refuse = (model, refusal) => announced({
|
|
583
|
+
...model,
|
|
584
|
+
refused: Option.some(refusal)
|
|
585
|
+
}, refusal.message, "assertive");
|
|
579
586
|
const applyOp = (model, op, group = groupOf(op)) => {
|
|
580
587
|
const result = Composition.apply(catalog, documentOf(model), op);
|
|
581
588
|
if (Result.isFailure(result)) return refuse(model, {
|
|
@@ -587,21 +594,19 @@ const Builder = {
|
|
|
587
594
|
});
|
|
588
595
|
const { document, removed } = result.success;
|
|
589
596
|
const kept = Option.filter(model.selected, (id) => !removed.includes(id));
|
|
590
|
-
|
|
591
|
-
model
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
refused: Option.none()
|
|
599
|
-
},
|
|
600
|
-
...Option.match(describeEdit(catalog, words, documentOf(model), document, op), {
|
|
601
|
-
onNone: () => ({}),
|
|
602
|
-
onSome: (said) => ({ commands: announce(said) })
|
|
603
|
-
})
|
|
597
|
+
const applied = {
|
|
598
|
+
...model,
|
|
599
|
+
page: History.push(model.page, document, {
|
|
600
|
+
capacity,
|
|
601
|
+
group
|
|
602
|
+
}),
|
|
603
|
+
selected: Option.orElse(created(catalog, op), () => kept),
|
|
604
|
+
refused: Option.none()
|
|
604
605
|
};
|
|
606
|
+
return Option.match(describeEdit(catalog, words, documentOf(model), document, op), {
|
|
607
|
+
onNone: () => ({ model: applied }),
|
|
608
|
+
onSome: (said) => announced(applied, said)
|
|
609
|
+
});
|
|
605
610
|
};
|
|
606
611
|
/** A Block's starting props, encoded as the Document stores them; none for a Block with none. */
|
|
607
612
|
const startingProps = (name) => {
|
|
@@ -614,7 +619,10 @@ const Builder = {
|
|
|
614
619
|
* page takes its Block, as a press with nothing selected puts it. None for
|
|
615
620
|
* a node on the page, which is moved only onto another.
|
|
616
621
|
*/
|
|
617
|
-
const onPage = (document, source) =>
|
|
622
|
+
const onPage = (document, source) => Match.valueTags(source, {
|
|
623
|
+
New: ({ block }) => placeFor(catalog, document, Option.none(), block),
|
|
624
|
+
Existing: () => Option.none()
|
|
625
|
+
});
|
|
618
626
|
/** What a drag carries, as `landing` weighs it; none for a node gone or a Block not offered. */
|
|
619
627
|
const draggedOf = (document, source) => {
|
|
620
628
|
if (source._tag === "Existing") {
|
|
@@ -671,12 +679,15 @@ const Builder = {
|
|
|
671
679
|
/** Puts a node's tree on the system clipboard, then says `said`, whether it could or not. */
|
|
672
680
|
const copy = (tree, said) => [{
|
|
673
681
|
name: `${name}.copy`,
|
|
674
|
-
effect: Effect.as(copyText(clipText(tree)).effect,
|
|
682
|
+
effect: Effect.as(copyText(clipText(tree)).effect, Message.Copied({ said }))
|
|
675
683
|
}];
|
|
676
684
|
/** The edit under way of the field a canvas Message names; none for any other. */
|
|
677
685
|
const editingOf = (model, field) => Option.flatMap(fieldOf(field), (named) => Option.filter(model.editing, (editing) => editing.id === named.id && editing.key === named.key));
|
|
678
686
|
/** What is said when a drag ends with nothing done. */
|
|
679
|
-
const unmoved = (source) => source
|
|
687
|
+
const unmoved = (source) => Match.valueTags(source, {
|
|
688
|
+
Existing: () => words.notMoved,
|
|
689
|
+
New: () => words.notAdded
|
|
690
|
+
});
|
|
680
691
|
/** Asks for `count` new ids; the request goes through once they arrive. */
|
|
681
692
|
const mint = (count, request) => [{
|
|
682
693
|
name: `${name}.mint`,
|
|
@@ -889,6 +900,8 @@ const Builder = {
|
|
|
889
900
|
...model,
|
|
890
901
|
selected: Option.none()
|
|
891
902
|
} };
|
|
903
|
+
case "RowPressed": return LayersPlaced.helpers.focus(message.id)(model);
|
|
904
|
+
case "RowToggled": return LayersPlaced.helpers.toggle(message.id)(model);
|
|
892
905
|
case "Hovered": return { model: {
|
|
893
906
|
...model,
|
|
894
907
|
hovered: Option.some(message.id)
|
|
@@ -956,9 +969,10 @@ const Builder = {
|
|
|
956
969
|
model,
|
|
957
970
|
commands: [{
|
|
958
971
|
name: `${name}.paste`,
|
|
959
|
-
effect: Effect.map(readText().effect, (read) => Message.ClipboardRead({ text: read.
|
|
972
|
+
effect: Effect.map(readText().effect, (read) => Message.ClipboardRead({ text: Match.value(read).pipe(Match.tag("Read", ({ text }) => Option.some(text)), Match.orElse(() => Option.none())) }))
|
|
960
973
|
}]
|
|
961
974
|
};
|
|
975
|
+
case "Copied": return announced(model, message.said);
|
|
962
976
|
case "ClipboardRead": {
|
|
963
977
|
const tree = Option.match(message.text, {
|
|
964
978
|
onNone: () => model.clipboard,
|
|
@@ -1040,7 +1054,10 @@ const Builder = {
|
|
|
1040
1054
|
case "EditingCancelled": return Option.match(editingOf(model, message.field), {
|
|
1041
1055
|
onNone: () => ({ model }),
|
|
1042
1056
|
onSome: (editing) => {
|
|
1043
|
-
const kept =
|
|
1057
|
+
const kept = Match.valueTags(message, {
|
|
1058
|
+
EditingCommitted: ({ text }) => text,
|
|
1059
|
+
EditingCancelled: () => editing.initial
|
|
1060
|
+
});
|
|
1044
1061
|
if (!editing.typed && kept === editing.initial) return { model: {
|
|
1045
1062
|
...model,
|
|
1046
1063
|
editing: Option.none()
|
|
@@ -1109,18 +1126,21 @@ const Builder = {
|
|
|
1109
1126
|
}
|
|
1110
1127
|
case "Undid":
|
|
1111
1128
|
case "Redid": {
|
|
1112
|
-
const page = (message
|
|
1129
|
+
const page = Match.valueTags(message, {
|
|
1130
|
+
Undid: () => History.undo,
|
|
1131
|
+
Redid: () => History.redo
|
|
1132
|
+
})(model.page);
|
|
1113
1133
|
if (page === model.page) return { model };
|
|
1114
|
-
return {
|
|
1115
|
-
model
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
};
|
|
1134
|
+
return announced({
|
|
1135
|
+
...model,
|
|
1136
|
+
page,
|
|
1137
|
+
selected: keptIn(page.present, model.selected),
|
|
1138
|
+
refused: Option.none(),
|
|
1139
|
+
editing: Option.none()
|
|
1140
|
+
}, Match.valueTags(message, {
|
|
1141
|
+
Undid: () => words.undone,
|
|
1142
|
+
Redid: () => words.redone
|
|
1143
|
+
}));
|
|
1124
1144
|
}
|
|
1125
1145
|
case "DragStarted": return Option.isNone(draggedOf(documentOf(model), message.source)) ? { model } : { model: {
|
|
1126
1146
|
...model,
|
|
@@ -1129,7 +1149,10 @@ const Builder = {
|
|
|
1129
1149
|
over: Option.none(),
|
|
1130
1150
|
at: Option.none()
|
|
1131
1151
|
}),
|
|
1132
|
-
selected:
|
|
1152
|
+
selected: Match.valueTags(message.source, {
|
|
1153
|
+
Existing: ({ id }) => Option.some(id),
|
|
1154
|
+
New: () => model.selected
|
|
1155
|
+
})
|
|
1133
1156
|
} };
|
|
1134
1157
|
case "DraggedOver": return draggedOver(model, message.id, message.zone, Option.none());
|
|
1135
1158
|
case "DraggedOverRegion": return draggedOver(model, message.id, "inside", Option.some(message.region));
|
|
@@ -1165,27 +1188,24 @@ const Builder = {
|
|
|
1165
1188
|
onSome: (target) => Option.flatMap(draggedOf(documentOf(model), source), (dragged) => landing(catalog, documentOf(model), dragged, target.id, target.zone, target.region))
|
|
1166
1189
|
});
|
|
1167
1190
|
return Option.match(landed, {
|
|
1168
|
-
onNone: () => (
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1191
|
+
onNone: () => announced(ended, unmoved(source)),
|
|
1192
|
+
onSome: ({ at }) => Match.valueTags(source, {
|
|
1193
|
+
Existing: ({ id }) => applyOp(ended, Composition.Op.move(id, at)),
|
|
1194
|
+
New: ({ block }) => ({
|
|
1195
|
+
model: ended,
|
|
1196
|
+
commands: mint(1, {
|
|
1197
|
+
_tag: "Insert",
|
|
1198
|
+
block,
|
|
1199
|
+
at
|
|
1200
|
+
})
|
|
1178
1201
|
})
|
|
1179
|
-
}
|
|
1202
|
+
})
|
|
1180
1203
|
});
|
|
1181
1204
|
}
|
|
1182
|
-
case "DragCancelled": return Option.isNone(model.drag) ? { model } : {
|
|
1183
|
-
model
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
},
|
|
1187
|
-
commands: announce(unmoved(model.drag.value.source))
|
|
1188
|
-
};
|
|
1205
|
+
case "DragCancelled": return Option.isNone(model.drag) ? { model } : announced({
|
|
1206
|
+
...model,
|
|
1207
|
+
drag: Option.none()
|
|
1208
|
+
}, unmoved(model.drag.value.source));
|
|
1189
1209
|
case "PreviewChosen": return { model: {
|
|
1190
1210
|
...model,
|
|
1191
1211
|
preview: {
|
|
@@ -1255,10 +1275,11 @@ const Builder = {
|
|
|
1255
1275
|
const moved = assembled(model, message);
|
|
1256
1276
|
const next = {
|
|
1257
1277
|
...moved,
|
|
1258
|
-
model: stillEditing(message.
|
|
1278
|
+
model: stillEditing(Match.value(message).pipe(Match.tag("Inspected", () => moved.model), Match.orElse(() => reconciled(model, moved.model))))
|
|
1259
1279
|
};
|
|
1260
|
-
|
|
1261
|
-
|
|
1280
|
+
const focused = focusedBy(message);
|
|
1281
|
+
if (Option.isSome(focused)) {
|
|
1282
|
+
const id = NodeId.make(focused.value);
|
|
1262
1283
|
return Composition.nodeAt(documentOf(next.model), id) === void 0 ? next : {
|
|
1263
1284
|
...next,
|
|
1264
1285
|
model: {
|