foldkit-richtext 0.5.2 → 0.6.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.
Files changed (100) hide show
  1. package/dist/clipboard.d.ts +224 -0
  2. package/dist/clipboard.d.ts.map +1 -0
  3. package/dist/clipboard.js +208 -0
  4. package/dist/clipboard.js.map +1 -0
  5. package/dist/code.d.ts +27 -0
  6. package/dist/code.d.ts.map +1 -0
  7. package/dist/code.js +45 -0
  8. package/dist/code.js.map +1 -0
  9. package/dist/command.d.ts +300 -0
  10. package/dist/command.d.ts.map +1 -0
  11. package/dist/command.js +1438 -0
  12. package/dist/command.js.map +1 -0
  13. package/dist/decoration.d.ts +44 -0
  14. package/dist/decoration.d.ts.map +1 -0
  15. package/dist/decoration.js +96 -0
  16. package/dist/decoration.js.map +1 -0
  17. package/dist/document.d.ts +1045 -0
  18. package/dist/document.d.ts.map +1 -0
  19. package/dist/document.js +544 -0
  20. package/dist/document.js.map +1 -0
  21. package/dist/footnote.d.ts +35 -0
  22. package/dist/footnote.d.ts.map +1 -0
  23. package/dist/footnote.js +100 -0
  24. package/dist/footnote.js.map +1 -0
  25. package/dist/history.d.ts +470 -0
  26. package/dist/history.d.ts.map +1 -0
  27. package/dist/history.js +81 -0
  28. package/dist/history.js.map +1 -0
  29. package/dist/html.d.ts +27 -0
  30. package/dist/html.d.ts.map +1 -0
  31. package/dist/html.js +99 -0
  32. package/dist/html.js.map +1 -0
  33. package/dist/indent.d.ts +16 -0
  34. package/dist/indent.d.ts.map +1 -0
  35. package/dist/indent.js +101 -0
  36. package/dist/indent.js.map +1 -0
  37. package/dist/index.d.ts +24 -0
  38. package/dist/index.js +24 -0
  39. package/dist/input.d.ts +54 -0
  40. package/dist/input.d.ts.map +1 -0
  41. package/dist/input.js +37 -0
  42. package/dist/input.js.map +1 -0
  43. package/dist/kit.d.ts +179 -0
  44. package/dist/kit.d.ts.map +1 -0
  45. package/dist/kit.js +202 -0
  46. package/dist/kit.js.map +1 -0
  47. package/dist/marks.d.ts +79 -0
  48. package/dist/marks.d.ts.map +1 -0
  49. package/dist/marks.js +127 -0
  50. package/dist/marks.js.map +1 -0
  51. package/dist/media.d.ts +30 -0
  52. package/dist/media.d.ts.map +1 -0
  53. package/dist/media.js +148 -0
  54. package/dist/media.js.map +1 -0
  55. package/dist/migration.d.ts +55 -0
  56. package/dist/migration.d.ts.map +1 -0
  57. package/dist/migration.js +124 -0
  58. package/dist/migration.js.map +1 -0
  59. package/dist/outline.d.ts +15 -0
  60. package/dist/outline.d.ts.map +1 -0
  61. package/dist/outline.js +39 -0
  62. package/dist/outline.js.map +1 -0
  63. package/dist/rendering.d.ts +96 -0
  64. package/dist/rendering.d.ts.map +1 -0
  65. package/dist/rendering.js +106 -0
  66. package/dist/rendering.js.map +1 -0
  67. package/dist/replicated.d.ts +340 -0
  68. package/dist/replicated.d.ts.map +1 -0
  69. package/dist/replicated.js +1727 -0
  70. package/dist/replicated.js.map +1 -0
  71. package/dist/search.d.ts +28 -0
  72. package/dist/search.d.ts.map +1 -0
  73. package/dist/search.js +61 -0
  74. package/dist/search.js.map +1 -0
  75. package/dist/standard.d.ts +61 -0
  76. package/dist/standard.d.ts.map +1 -0
  77. package/dist/standard.js +231 -0
  78. package/dist/standard.js.map +1 -0
  79. package/dist/table.d.ts +38 -0
  80. package/dist/table.d.ts.map +1 -0
  81. package/dist/table.js +160 -0
  82. package/dist/table.js.map +1 -0
  83. package/dist/transaction.d.ts +712 -0
  84. package/dist/transaction.d.ts.map +1 -0
  85. package/dist/transaction.js +993 -0
  86. package/dist/transaction.js.map +1 -0
  87. package/dist/transform.d.ts +48 -0
  88. package/dist/transform.d.ts.map +1 -0
  89. package/dist/transform.js +94 -0
  90. package/dist/transform.js.map +1 -0
  91. package/dist/url.d.ts +16 -0
  92. package/dist/url.d.ts.map +1 -0
  93. package/dist/url.js +32 -0
  94. package/dist/url.js.map +1 -0
  95. package/package.json +6 -6
  96. package/dist/index.d.mts +0 -3787
  97. package/dist/index.d.mts.map +0 -1
  98. package/dist/index.mjs +0 -6688
  99. package/dist/index.mjs.map +0 -1
  100. package/dist/rolldown-runtime-D8jQpDG7.mjs +0 -12
@@ -0,0 +1,300 @@
1
+ import { Schema } from "effect";
2
+ import { Block, Document, EditorState, MarkValue, NodeId, Position, RunMark, Selection } from "./document.js";
3
+ import { Slice } from "./clipboard.js";
4
+ import { MarkRegistry } from "./marks.js";
5
+ import { NodeRegistry } from "./kit.js";
6
+ import { ChangeSet, TextBlock, TransactionResult } from "./transaction.js";
7
+ /**
8
+ * Editor intent: what the user is trying to do. Commands resolve against the
9
+ * current document and selection into a Transaction of low-level operations, so
10
+ * durable history keeps its meaning (§19). Identities a command needs come from
11
+ * the caller's `mint`; nothing here reads a clock or a hidden counter.
12
+ */
13
+ export type Command = {
14
+ readonly type: 'InsertText';
15
+ readonly text: string;
16
+ /** Stored marks: a bare name, or a value when the mark carries props. */
17
+ readonly marks?: ReadonlyArray<string | MarkValue>;
18
+ } | {
19
+ readonly type: 'DeleteBackward';
20
+ } | {
21
+ readonly type: 'DeleteForward';
22
+ } | {
23
+ readonly type: 'SplitBlock';
24
+ } | {
25
+ readonly type: 'ToggleMark';
26
+ readonly mark: string | MarkValue;
27
+ } |
28
+ /**
29
+ * Puts exactly this mark on every run the selection covers, replacing a same-named mark
30
+ * whose props differ: how a link gets a new `href`. A caret acts on the extent of the
31
+ * mark around it (`markExtent`), and does nothing outside one.
32
+ */
33
+ {
34
+ readonly type: 'SetMark';
35
+ readonly mark: string | MarkValue;
36
+ } |
37
+ /**
38
+ * Takes the named mark off every run the selection covers; a caret, off its extent. Given a
39
+ * mark value, only off the runs carrying exactly that value: one discussion's highlight,
40
+ * leaving another's inside it.
41
+ */
42
+ {
43
+ readonly type: 'ClearMark';
44
+ readonly mark: string | MarkValue;
45
+ } | {
46
+ readonly type: 'SetSelection';
47
+ readonly selection: Selection | null;
48
+ } | {
49
+ readonly type: 'Paste';
50
+ readonly slice: Slice;
51
+ } |
52
+ /** Retypes the block the selection starts in: a paragraph, or a heading. */
53
+ {
54
+ readonly type: 'RetypeBlock';
55
+ readonly to: TextBlock;
56
+ } |
57
+ /**
58
+ * Wraps the block the selection starts in, in new containers listed outermost first: a
59
+ * `Quote`, or a `List` holding a `ListItem`. The block keeps its identity and its runs,
60
+ * so the caret stays where it was. Given a vocabulary, a list wrap right after a list of the
61
+ * same kind and props adds the block to it as a new item.
62
+ */
63
+ {
64
+ readonly type: 'WrapBlock';
65
+ readonly containers: ReadonlyArray<Container>;
66
+ } |
67
+ /**
68
+ * Retypes the text block the selection starts in to a node kind that holds text, such as a
69
+ * `CodeBlock`. The block and its runs keep their identities, text, and marks.
70
+ */
71
+ {
72
+ readonly type: 'ConvertBlock';
73
+ readonly to: Container;
74
+ } |
75
+ /**
76
+ * Retypes the container the selection starts in (the node block holding its block, such as
77
+ * a list item) to another node kind, where it stands: its identity and every block it holds
78
+ * are kept, so edits made inside it meanwhile survive. Only from the container's first block,
79
+ * which is where a marker for the container is typed. Given a vocabulary, the new kind must
80
+ * hold blocks, hold each block the container holds, and stand where the container does.
81
+ */
82
+ {
83
+ readonly type: 'RetypeContainer';
84
+ readonly to: Container;
85
+ } |
86
+ /**
87
+ * Lifts the block the selection starts in out of its container, the inverse of a wrap:
88
+ * repeated while the new parent's declaration refuses it, so a list item's paragraph leaves
89
+ * both the item and the list. The block keeps its identity, and the caret with it.
90
+ */
91
+ {
92
+ readonly type: 'LiftBlock';
93
+ } |
94
+ /**
95
+ * Moves a block, and everything it holds, before or after another block, in its own container
96
+ * or another one the vocabulary lets it stand in (§149). It addresses blocks rather than the
97
+ * selection, so a handle or a key can move the block it stands for; identities are kept, and
98
+ * the selection with them. A container the move leaves empty is deleted.
99
+ */
100
+ {
101
+ readonly type: 'MoveBlock';
102
+ readonly node: NodeId;
103
+ readonly to: Beside;
104
+ } |
105
+ /**
106
+ * Sets the named props of a node block, such as a task item's `checked`, keeping the rest.
107
+ * It addresses the block by identity, as `MoveBlock` does, so a checkbox sends it for its
108
+ * own item. Given a vocabulary, props that decode as the kind's must still decode after.
109
+ */
110
+ {
111
+ readonly type: 'SetProps';
112
+ readonly node: NodeId;
113
+ readonly props: Schema.JsonObject;
114
+ } |
115
+ /**
116
+ * Inserts a block, and everything it holds, before or after another block, under fresh
117
+ * identities from `mint`: an image chosen from a file, a table from a menu, a copy of a block
118
+ * for its handle's Duplicate. The caret goes to the start of its first text, when it has any.
119
+ * Without `to` it goes beside the caret's block: before it when that block is empty, so a
120
+ * slash command typed on a blank line puts its block there and the line stays to type on,
121
+ * and after it otherwise.
122
+ */
123
+ {
124
+ readonly type: 'InsertBlock';
125
+ readonly block: Block;
126
+ readonly to?: Beside | undefined;
127
+ } |
128
+ /**
129
+ * Deletes a block and everything it holds, with any container that would be left empty by it,
130
+ * as a block handle's Delete does. A caret inside it moves to the nearest text that stays; a
131
+ * document left with no block gets an empty paragraph, so there is somewhere to type.
132
+ */
133
+ {
134
+ readonly type: 'DeleteBlock';
135
+ readonly node: NodeId;
136
+ } |
137
+ /**
138
+ * A row above or below the caret's table cell, as wide as the table's widest row, with the caret
139
+ * moved into it. The table is the standard vocabulary's (`Table`, `TableRow`, `TableCell`).
140
+ */
141
+ {
142
+ readonly type: 'InsertRow';
143
+ readonly where: 'before' | 'after';
144
+ } |
145
+ /** A cell beside the caret's in every row, before or after it: a column. */
146
+ {
147
+ readonly type: 'InsertColumn';
148
+ readonly where: 'before' | 'after';
149
+ } |
150
+ /** The caret's row, deleted; the last one deletes the table. */
151
+ {
152
+ readonly type: 'DeleteRow';
153
+ } |
154
+ /** The caret's column, deleted from every row that has it; the last one deletes the table. */
155
+ {
156
+ readonly type: 'DeleteColumn';
157
+ } |
158
+ /**
159
+ * Tab. In a kind declared `indents` (code), a level of indentation at the caret, or at the
160
+ * start of every line a range covers; in a table cell, the caret to the next cell, adding a row
161
+ * after the last. Refused anywhere else (`InvalidSelection`), so Tab can move focus there.
162
+ */
163
+ {
164
+ readonly type: 'Indent';
165
+ } |
166
+ /** Shift+Tab: a level of indentation off each line in code; the previous cell in a table. */
167
+ {
168
+ readonly type: 'Outdent';
169
+ } |
170
+ /**
171
+ * Find and replace: the match at index `at` of `query` (in document order, as `findMatches`
172
+ * lists them), or every match when `at` is absent, becomes `replacement`, as one transaction.
173
+ * Case does not count unless `caseSensitive`. The caret ends after the earliest replacement.
174
+ */
175
+ {
176
+ readonly type: 'Replace';
177
+ readonly query: string;
178
+ readonly replacement: string;
179
+ readonly caseSensitive?: boolean | undefined;
180
+ readonly at?: number | undefined;
181
+ } |
182
+ /**
183
+ * A footnote at the caret, or at the end of a range: a reference showing the next free label
184
+ * (`nextFootnoteLabel`), and its definition after the last top-level block holding `text`, with
185
+ * the caret at the definition's start, ready to write the note.
186
+ */
187
+ {
188
+ readonly type: 'InsertFootnote';
189
+ readonly text?: string | undefined;
190
+ } |
191
+ /**
192
+ * A footnote's label, `from`, becomes `to`: on its definition, and on every reference, whose
193
+ * text becomes `to` where it showed `from`. Refused (`InvalidInput`) when `to` is blank or
194
+ * another footnote's, or when no footnote is labelled `from`.
195
+ */
196
+ {
197
+ readonly type: 'RenameFootnote';
198
+ readonly from: string;
199
+ readonly to: string;
200
+ };
201
+ /** Where `MoveBlock` puts a block: before or after a sibling, named by identity. */
202
+ export declare const Beside: Schema.Union<readonly [Schema.Struct<{
203
+ readonly before: Schema.brand<Schema.NonEmptyString, "foldkit-richtext/NodeId">;
204
+ readonly after: Schema.optionalKey<Schema.Never>;
205
+ }>, Schema.Struct<{
206
+ readonly after: Schema.brand<Schema.NonEmptyString, "foldkit-richtext/NodeId">;
207
+ readonly before: Schema.optionalKey<Schema.Never>;
208
+ }>]>;
209
+ export type Beside = typeof Beside.Type;
210
+ /** A container a block is wrapped in: a node kind, and the props it starts with. */
211
+ export declare const Container: Schema.Struct<{
212
+ readonly kind: Schema.NonEmptyString;
213
+ readonly props: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
214
+ }>;
215
+ export type Container = typeof Container.Type;
216
+ /** Caller-owned identity source. Live edits mint; replay applies transactions. */
217
+ export interface CommandIds {
218
+ readonly mint: () => string;
219
+ }
220
+ /** What a command needs beyond state and identity, such as a Kit's mark policy. */
221
+ export interface RunOptions {
222
+ readonly marks?: MarkRegistry | undefined;
223
+ /** The node vocabulary, so an edit a constraint forbids is refused here (§125). */
224
+ readonly nodes?: NodeRegistry | undefined;
225
+ }
226
+ /**
227
+ * Whether a block is an atom, holding neither text nor blocks, as an image is. Without a
228
+ * vocabulary, a node with nothing in it is one.
229
+ */
230
+ export declare const isAtom: (nodes: NodeRegistry | undefined, block: Block) => boolean;
231
+ /** Whether a selection covers text: a range that is not a caret. What a mark or a link applies to. */
232
+ export declare const coversText: (selection: Selection | null) => boolean;
233
+ /**
234
+ * The marks every run the selection covers carries: the ones a toggle would
235
+ * remove, which is what an "active" toolbar button means. A caret reports its
236
+ * run's marks — an empty run can carry them, which is how a caret holds a format
237
+ * — and a range is not bold when it straddles a bold run and a plain one. A node
238
+ * selection reports what its whole subtree agrees on. A read, not a command:
239
+ * nothing here changes anything.
240
+ */
241
+ export declare const marksInRange: (document: Document, selection: Selection | null) => ReadonlySet<string>;
242
+ /** A mark around a caret, and the range of runs it spans. */
243
+ export interface MarkExtent {
244
+ readonly mark: RunMark;
245
+ readonly selection: Extract<Selection, {
246
+ readonly type: 'Range';
247
+ }>;
248
+ }
249
+ /**
250
+ * The named mark on the run a position is in, and the adjacent runs of its block carrying
251
+ * the same mark with the same props: the whole link a caret sits in, which is what a link
252
+ * editor shows and what `SetMark` and `ClearMark` act on at a caret. Undefined when that
253
+ * run does not carry the mark. A read, like `marksInRange`.
254
+ */
255
+ export declare const markExtent: (document: Document, position: Position, name: string) => MarkExtent | undefined;
256
+ /**
257
+ * The text style of the block a selection starts in, in the shape `RetypeBlock` takes, so a
258
+ * style picker compares what it would send with what is there. Undefined for a node
259
+ * selection, one that resolves to nothing, or a block a retype does not reach, such as a code
260
+ * block.
261
+ */
262
+ export declare const textBlockAt: (document: Document, selection: Selection | null) => TextBlock | undefined;
263
+ /**
264
+ * The blocks `node` may move beside, in document order (§149): the blocks of every container it
265
+ * may move into, which is what a drag offers. Empty when the document does not hold it.
266
+ */
267
+ export declare const moveTargets: (document: Document, node: NodeId, nodes?: NodeRegistry) => ReadonlyArray<NodeId>;
268
+ /**
269
+ * The blocks a selection starts in, outermost first: a caret in a list item's paragraph gives
270
+ * the list, the item, and the paragraph. What a block handle picks from, and a breadcrumb draws.
271
+ * Empty when the selection is null or resolves to nothing.
272
+ */
273
+ export declare const blocksAt: (document: Document, selection: Selection | null) => ReadonlyArray<Block>;
274
+ /**
275
+ * Resolves one intent into a transaction and applies it atomically. Commands
276
+ * describe intent; the returned `positionMap` and `ChangeSet` describe the
277
+ * document effect, and rejection returns no partially edited state.
278
+ */
279
+ export declare const run: (state: EditorState, command: Command, ids: CommandIds, options?: RunOptions) => TransactionResult;
280
+ /**
281
+ * Whether Tab means something where the selection is: in code, or in a table cell. An editor
282
+ * takes Tab only there, so anywhere else it still moves focus out of the editor.
283
+ */
284
+ export declare const takesTab: (document: Document, selection: Selection | null, nodes?: NodeRegistry) => boolean;
285
+ /** An ordered list of commands that commit as one action (§124 §5). */
286
+ export type Action = ReadonlyArray<Command>;
287
+ /**
288
+ * A composed action's invalidation summary is the union of its commands': an identity
289
+ * one command retired and a later one restored appears in both sets, and a patch reads
290
+ * that as "remove it, then render it", so it never under-invalidates.
291
+ */
292
+ export declare const unionChangeSet: (left: ChangeSet, right: ChangeSet) => ChangeSet;
293
+ /**
294
+ * Resolves commands in order and commits them as one action: one resulting state, one
295
+ * composed ChangeSet, and one identity stream, so a caller can treat "remove the query,
296
+ * then apply the choice" as a single transition. It stops at the first refusal and
297
+ * returns that command's error; state is a value, so nothing partial escapes.
298
+ */
299
+ export declare const runAction: (state: EditorState, commands: Action, ids: CommandIds, options?: RunOptions) => TransactionResult;
300
+ //# sourceMappingURL=command.d.ts.map
@@ -0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