@nerd-bible/wordgard 0.3.3
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/LICENSE +22 -0
- package/README.md +24 -0
- package/dist/collab.d.ts +105 -0
- package/dist/collab.js +218 -0
- package/dist/command.d.ts +796 -0
- package/dist/command.js +1451 -0
- package/dist/doc.d.ts +2210 -0
- package/dist/doc.js +3814 -0
- package/dist/editor.d.ts +1920 -0
- package/dist/editor.js +7154 -0
- package/dist/history.d.ts +90 -0
- package/dist/history.js +278 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/phrases.d.ts +90 -0
- package/dist/phrases.js +141 -0
- package/dist/schema.d.ts +579 -0
- package/dist/schema.js +1341 -0
- package/dist/state.d.ts +1388 -0
- package/dist/state.js +2024 -0
- package/dist/table.d.ts +215 -0
- package/dist/table.js +1302 -0
- package/dist/types.d.ts +196 -0
- package/dist/types.js +288 -0
- package/package.json +52 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import { Wordgard } from 'wordgard/editor';
|
|
2
|
+
import { Transaction, GardState } from 'wordgard/state';
|
|
3
|
+
import { PhraseSet } from 'wordgard/phrases';
|
|
4
|
+
import { Mark, Plot, Node, Schema, Pos, ChangeSet } from 'wordgard/doc';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
A command is a function that takes an editor and an additional
|
|
8
|
+
parameter, and either...
|
|
9
|
+
|
|
10
|
+
- returns `false` to indicate that it does not apply to the
|
|
11
|
+
current editor state
|
|
12
|
+
|
|
13
|
+
- performs its action as a side effect and returns `true`
|
|
14
|
+
|
|
15
|
+
- returns a {@link state.Transaction.Spec transaction spec} that
|
|
16
|
+
should be dispatched as its effect
|
|
17
|
+
|
|
18
|
+
This formulation is chosen to cover both side-effecting commands
|
|
19
|
+
(whose effect may not even directly affect the editor—a command
|
|
20
|
+
may just open a dialog or change some editor-external state) _and_
|
|
21
|
+
{@link Command.Pure commands} implemented as pure functions from
|
|
22
|
+
state to transaction.
|
|
23
|
+
|
|
24
|
+
Extensions can register additional handlers for a command, which
|
|
25
|
+
will be called in order of precedence (until one returns true)
|
|
26
|
+
when the command is {@link Command.dispatch dispatched}.
|
|
27
|
+
Commands are recognized by function identity. So, for example, the
|
|
28
|
+
`enter` command is both the tag used to indicate invocation of an
|
|
29
|
+
enter press and the function that implements the default behavior
|
|
30
|
+
for this action.
|
|
31
|
+
*/
|
|
32
|
+
type Command<Param = null> = (target: Wordgard, param: Param) => boolean | Transaction.Spec;
|
|
33
|
+
declare namespace Command {
|
|
34
|
+
/**
|
|
35
|
+
`Command.Pure` is a subtype of `Command` that relies only on the
|
|
36
|
+
editor state, and performs no imperative effects. When
|
|
37
|
+
implementing such a command function, it can be useful to tag it
|
|
38
|
+
with this type, so that it can be invoked without a full editor
|
|
39
|
+
component for testing or for use in a context where there is no
|
|
40
|
+
editor.
|
|
41
|
+
|
|
42
|
+
Note that invoking a command function directly will not activate
|
|
43
|
+
custom {@link Command.handler handlers}.
|
|
44
|
+
*/
|
|
45
|
+
type Pure<Param = null> = (target: {
|
|
46
|
+
state: GardState;
|
|
47
|
+
}, param: Param) => false | Transaction.Spec;
|
|
48
|
+
/**
|
|
49
|
+
Create an extension that adds a handler for the given {@link
|
|
50
|
+
Command command}.
|
|
51
|
+
*/
|
|
52
|
+
function handler<Param>(command: Command<Param>, handler: Command<Param>): GardState.Extension;
|
|
53
|
+
/**
|
|
54
|
+
Bind a command with a parameter. The only thing you can do with
|
|
55
|
+
a bound command is to {@link Command.dispatch dispatch} it.
|
|
56
|
+
*/
|
|
57
|
+
function bind<Param>(command: Command<Param>, param: Param): Command.Bound;
|
|
58
|
+
/**
|
|
59
|
+
Opaque type used for {@link Command.bind bound} commands.
|
|
60
|
+
*/
|
|
61
|
+
type Bound = {
|
|
62
|
+
readonly tag: unique symbol;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
Apply a command to the given editor view. When passing a
|
|
66
|
+
non-{@link Command.bind bound} command with a parameter, the
|
|
67
|
+
parameter has to be passed as second argument.
|
|
68
|
+
*/
|
|
69
|
+
function dispatch(wg: Wordgard, command: Command<null> | Command.Bound): boolean;
|
|
70
|
+
function dispatch<Param>(wg: Wordgard, command: Command<Param>, param: Param): boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare namespace Menu {
|
|
74
|
+
/**
|
|
75
|
+
Editor menus are structured as trees, with item groups and
|
|
76
|
+
submenus as internal nodes, and buttons and custom controls as
|
|
77
|
+
leaf nodes.
|
|
78
|
+
*/
|
|
79
|
+
type Item = Group | Submenu | Button | CustomControl;
|
|
80
|
+
namespace Item {
|
|
81
|
+
/**
|
|
82
|
+
Generic configuration fields supported by all menu items.
|
|
83
|
+
*/
|
|
84
|
+
interface Spec {
|
|
85
|
+
/**
|
|
86
|
+
When given and returning false, this item should be hidden
|
|
87
|
+
from the menu. Should be used sparingly, to avoid the menu
|
|
88
|
+
constantly flickering and changing size as the user is
|
|
89
|
+
editing.
|
|
90
|
+
*/
|
|
91
|
+
select?: (state: GardState) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
When given and returning false, this item is disabled, which
|
|
94
|
+
means it looks faded and cannot be interacted with.
|
|
95
|
+
*/
|
|
96
|
+
enable?: (state: GardState) => boolean;
|
|
97
|
+
/**
|
|
98
|
+
By default, state predicates (`select`, `enable`, and `active`)
|
|
99
|
+
are re-checked whenever the document or selection changes. If an
|
|
100
|
+
item is sensitive to other aspects of the state, provide a test
|
|
101
|
+
here that returns `true` for transactions that might affect the
|
|
102
|
+
item state.
|
|
103
|
+
*/
|
|
104
|
+
updateFor?: (tr: Transaction) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
The item's parent. See {@link Menu.resolve} for information
|
|
107
|
+
on how menus are linked up.
|
|
108
|
+
*/
|
|
109
|
+
parent?: Group | Submenu;
|
|
110
|
+
/**
|
|
111
|
+
Determines the order of elements in the parent. Should be a
|
|
112
|
+
number between 0 and 100. Defaults to 100.
|
|
113
|
+
*/
|
|
114
|
+
rank?: number;
|
|
115
|
+
/**
|
|
116
|
+
A description to associate with the item, used for hover
|
|
117
|
+
tooltips and screen-reader text. If the item has a textual
|
|
118
|
+
label, this will default to that label when not given.
|
|
119
|
+
*/
|
|
120
|
+
description?: PhraseSet.Ref | string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
Base class for menu items, storing the fields specified in
|
|
124
|
+
{@link Menu.Item.Spec}.
|
|
125
|
+
*/
|
|
126
|
+
class Base {
|
|
127
|
+
select: ((state: GardState) => boolean) | undefined;
|
|
128
|
+
enable: ((state: GardState) => boolean) | undefined;
|
|
129
|
+
updateFor: ((tr: Transaction) => boolean) | undefined;
|
|
130
|
+
parent: Group | Submenu | undefined;
|
|
131
|
+
rank: number;
|
|
132
|
+
description: PhraseSet.Ref | string | undefined;
|
|
133
|
+
/**
|
|
134
|
+
Menu items can be used as editor extensions to include them
|
|
135
|
+
in a configuration.
|
|
136
|
+
*/
|
|
137
|
+
extension: GardState.Extension;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
The facet used to add menu items to a configuration. Used by
|
|
141
|
+
the items' extensions to register them, and by menu
|
|
142
|
+
implementations to find available items.
|
|
143
|
+
*/
|
|
144
|
+
const source: GardState.Facet<Item, readonly Item[]>;
|
|
145
|
+
/**
|
|
146
|
+
A resolved menu consists of buttons, custom controls,
|
|
147
|
+
submenus, and spacers, which are represented by the string
|
|
148
|
+
literal `"|"`.
|
|
149
|
+
*/
|
|
150
|
+
type Resolved = Button | CustomControl | "|" | Submenu.Resolved;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
Labels are used by buttons and submenus to determine what they
|
|
154
|
+
look like. They may either be textual (a string or reference to
|
|
155
|
+
a phrase), or an icon, which is expressed an SVG path string
|
|
156
|
+
that draws the icon inside a 100-by-100 space. The `directional`
|
|
157
|
+
flag indicates that the icon should be mirrored vertically in a
|
|
158
|
+
right-to-left editor.
|
|
159
|
+
*/
|
|
160
|
+
type Label = string | PhraseSet.Ref | {
|
|
161
|
+
icon: string;
|
|
162
|
+
directional?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
A menu button runs a command when activated. See the {@link
|
|
166
|
+
Menu.Button.Spec spec type} for the meaning of the fields.
|
|
167
|
+
*/
|
|
168
|
+
class Button extends Item.Base {
|
|
169
|
+
/**
|
|
170
|
+
The configuration object used to create this button.
|
|
171
|
+
*/
|
|
172
|
+
readonly spec: Button.Spec;
|
|
173
|
+
label: Label;
|
|
174
|
+
run: Command.Bound | Command;
|
|
175
|
+
active: ((state: GardState) => boolean) | undefined;
|
|
176
|
+
private constructor();
|
|
177
|
+
/**
|
|
178
|
+
Define a menu button.
|
|
179
|
+
*/
|
|
180
|
+
static define(spec: Button.Spec): Button;
|
|
181
|
+
}
|
|
182
|
+
namespace Button {
|
|
183
|
+
interface Spec extends Item.Spec {
|
|
184
|
+
/**
|
|
185
|
+
The command to run when the user activates the button.
|
|
186
|
+
*/
|
|
187
|
+
run: Command.Bound | Command;
|
|
188
|
+
/**
|
|
189
|
+
When this returns true, the button is highlighted as active.
|
|
190
|
+
This can be used to show, for example, that a mark is active
|
|
191
|
+
at the cursor, or that a block type matches the block around
|
|
192
|
+
the current selection. Also used to automatically select a
|
|
193
|
+
label for a {@link Menu.Submenu submenu}.
|
|
194
|
+
*/
|
|
195
|
+
active?: (state: GardState) => boolean;
|
|
196
|
+
/**
|
|
197
|
+
The label to show on this button.
|
|
198
|
+
*/
|
|
199
|
+
label: Label;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
Creates a menu button that toggles an inline mark via {@link
|
|
203
|
+
Menu.Button.toggleMark}, and is shown as active when either
|
|
204
|
+
that mark is part of the marks associated with the current
|
|
205
|
+
cursor, or the selection covers only content with that mark.
|
|
206
|
+
*/
|
|
207
|
+
function toggleMark(config: {
|
|
208
|
+
mark: Mark;
|
|
209
|
+
parent?: Menu.Group | Menu.Submenu;
|
|
210
|
+
rank?: number;
|
|
211
|
+
description?: PhraseSet.Ref;
|
|
212
|
+
label: Menu.Label;
|
|
213
|
+
}): Button;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
Custom controls are similar to buttons, in that they can be part
|
|
217
|
+
of the menu and receive focus through menu navigation, but they
|
|
218
|
+
manage their own DOM. This can be used for elements like color
|
|
219
|
+
pickers that should be displayed inside of the menu but support
|
|
220
|
+
user interaction more complex than a button.
|
|
221
|
+
*/
|
|
222
|
+
class CustomControl extends Item.Base {
|
|
223
|
+
/**
|
|
224
|
+
The configuration object used to create this control.
|
|
225
|
+
*/
|
|
226
|
+
readonly spec: CustomControl.Spec;
|
|
227
|
+
/**
|
|
228
|
+
See {@link Menu.CustomControl.Spec.render}.
|
|
229
|
+
*/
|
|
230
|
+
render: (wg: Wordgard, done: () => void) => {
|
|
231
|
+
dom: HTMLElement;
|
|
232
|
+
focus?: HTMLElement;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
See {@link Menu.CustomControl.Spec.setEnabled}.
|
|
236
|
+
*/
|
|
237
|
+
setEnabled: ((dom: Element, enabled: boolean) => void) | undefined;
|
|
238
|
+
private constructor();
|
|
239
|
+
/**
|
|
240
|
+
Define a custom menu item.
|
|
241
|
+
*/
|
|
242
|
+
static define(spec: CustomControl.Spec): CustomControl;
|
|
243
|
+
}
|
|
244
|
+
namespace CustomControl {
|
|
245
|
+
interface Spec extends Item.Spec {
|
|
246
|
+
/**
|
|
247
|
+
The function that renders the actual control. The `dom`
|
|
248
|
+
property on the returned object will be displayed in the
|
|
249
|
+
menu. If `focus` is provided, that is used as the element to
|
|
250
|
+
put focus on. If not, `dom` is used.
|
|
251
|
+
|
|
252
|
+
The control should call the `done` function when it decides
|
|
253
|
+
it is closed or activated, so that any submenu above it
|
|
254
|
+
knows to close, and focus can be moved back to the editor if
|
|
255
|
+
appropriate.
|
|
256
|
+
*/
|
|
257
|
+
render: (wg: Wordgard, done: () => void) => {
|
|
258
|
+
dom: HTMLElement;
|
|
259
|
+
focus?: HTMLElement;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
If the control supports {@link Menu.Item.Spec.enable
|
|
263
|
+
disabling}, this function will be called when the enabled
|
|
264
|
+
state changes, and should update the control to show this.
|
|
265
|
+
*/
|
|
266
|
+
setEnabled?: (focus: Element, enabled: boolean) => void;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
Groups are used to organize sets of menu items together. The
|
|
271
|
+
{@link Menu.Group.top top-level menu} is a group, but groups
|
|
272
|
+
may appear at any level, so that items with similar roles can
|
|
273
|
+
attach themselves to them in order to appear next to each other.
|
|
274
|
+
|
|
275
|
+
See the {@link Menu.Group.Spec spec type} for the meaning of the
|
|
276
|
+
class's fields.
|
|
277
|
+
*/
|
|
278
|
+
class Group {
|
|
279
|
+
/**
|
|
280
|
+
The configuration object used to create this group.
|
|
281
|
+
*/
|
|
282
|
+
readonly spec: Group.Spec;
|
|
283
|
+
margin: boolean;
|
|
284
|
+
parent: Group | Submenu | undefined;
|
|
285
|
+
rank: number;
|
|
286
|
+
content: readonly (Item | "...")[] | undefined;
|
|
287
|
+
overflow: {
|
|
288
|
+
at: number;
|
|
289
|
+
wrap?: Submenu;
|
|
290
|
+
} | undefined;
|
|
291
|
+
/**
|
|
292
|
+
Menu groups count as extensions.
|
|
293
|
+
*/
|
|
294
|
+
extension: GardState.Extension;
|
|
295
|
+
private constructor();
|
|
296
|
+
/**
|
|
297
|
+
Define a menu group.
|
|
298
|
+
*/
|
|
299
|
+
static define(spec?: Group.Spec): Group;
|
|
300
|
+
/**
|
|
301
|
+
Create a template for this group.
|
|
302
|
+
*/
|
|
303
|
+
template(...content: (Template | Item | "...")[]): Template;
|
|
304
|
+
}
|
|
305
|
+
namespace Group {
|
|
306
|
+
/**
|
|
307
|
+
Options used to configure a menu group.
|
|
308
|
+
*/
|
|
309
|
+
interface Spec {
|
|
310
|
+
/**
|
|
311
|
+
When set to true, leave a bit of space between this group
|
|
312
|
+
and adjacent items.
|
|
313
|
+
*/
|
|
314
|
+
margin?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
The group's parent item, if any.
|
|
317
|
+
*/
|
|
318
|
+
parent?: Group | Submenu;
|
|
319
|
+
/**
|
|
320
|
+
The group's rank within its parent.
|
|
321
|
+
*/
|
|
322
|
+
rank?: number;
|
|
323
|
+
/**
|
|
324
|
+
Default content for this group. Usually you don't need this,
|
|
325
|
+
as you let parent links from the content items determine
|
|
326
|
+
what goes in the group. See the {@link Menu.resolve menu
|
|
327
|
+
resolution} system.
|
|
328
|
+
*/
|
|
329
|
+
content?: readonly (Item | "...")[];
|
|
330
|
+
/**
|
|
331
|
+
If given when, during resolution, the group contains more
|
|
332
|
+
than `at` items, wrap items `at - 1` and up in a submenu.
|
|
333
|
+
You may optionally provide submenu object to specify the
|
|
334
|
+
look of the submenu, or let it default to showing three
|
|
335
|
+
vertical dots.
|
|
336
|
+
*/
|
|
337
|
+
overflow?: {
|
|
338
|
+
at: number;
|
|
339
|
+
wrap?: Submenu;
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
The top-level menu. When you don't provide a custom menu
|
|
344
|
+
template, this is the starting point from which the menu will
|
|
345
|
+
be resolved. Parent of most other groups.
|
|
346
|
+
*/
|
|
347
|
+
const top: Group;
|
|
348
|
+
/**
|
|
349
|
+
Editing commands. Holds items like the history undo/redo
|
|
350
|
+
buttons.
|
|
351
|
+
*/
|
|
352
|
+
const commands: Group;
|
|
353
|
+
/**
|
|
354
|
+
Inline style items. Will, by default, contain buttons to
|
|
355
|
+
create emphasized text, links, and so on.
|
|
356
|
+
*/
|
|
357
|
+
const inline: Group;
|
|
358
|
+
/**
|
|
359
|
+
Group for block-related items. Holds things like list toggles
|
|
360
|
+
and text alignment.
|
|
361
|
+
*/
|
|
362
|
+
const block: Group;
|
|
363
|
+
/**
|
|
364
|
+
Group for inserting elements into the document, such as images
|
|
365
|
+
or tables.
|
|
366
|
+
*/
|
|
367
|
+
const insert: Group;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
A submenu is a menu item that, when activated, shows the menu
|
|
371
|
+
items that are nested under it. See the {@link Menu.Submenu.spec
|
|
372
|
+
spec type} for the meaning of the class fields.
|
|
373
|
+
*/
|
|
374
|
+
class Submenu extends Item.Base {
|
|
375
|
+
/**
|
|
376
|
+
The configuration object used to define this submenu.
|
|
377
|
+
*/
|
|
378
|
+
readonly spec: Submenu.Spec;
|
|
379
|
+
label: Label | undefined;
|
|
380
|
+
defaultLabel: Label | undefined;
|
|
381
|
+
arrow: boolean;
|
|
382
|
+
width: number | undefined;
|
|
383
|
+
content: readonly (Item | "...")[] | undefined;
|
|
384
|
+
private constructor();
|
|
385
|
+
/**
|
|
386
|
+
Define a submenu.
|
|
387
|
+
*/
|
|
388
|
+
static define(spec: Submenu.Spec): Submenu;
|
|
389
|
+
/**
|
|
390
|
+
Create a template item for this submenu.
|
|
391
|
+
*/
|
|
392
|
+
template(...content: (Template | Item | "...")[]): Template;
|
|
393
|
+
}
|
|
394
|
+
namespace Submenu {
|
|
395
|
+
/**
|
|
396
|
+
The options that can be passed to a submenu.
|
|
397
|
+
*/
|
|
398
|
+
interface Spec extends Item.Spec {
|
|
399
|
+
/**
|
|
400
|
+
The label to show for the submenu. When not given, the
|
|
401
|
+
submenu will look for the first {@link
|
|
402
|
+
Menu.Button.Spec.active active} item in its children, and
|
|
403
|
+
use that child's label, or fall back to `defaultLabel`.
|
|
404
|
+
*/
|
|
405
|
+
label?: Label;
|
|
406
|
+
/**
|
|
407
|
+
Fallback label when no regular label is given and there are
|
|
408
|
+
no active children.
|
|
409
|
+
*/
|
|
410
|
+
defaultLabel?: Label;
|
|
411
|
+
/**
|
|
412
|
+
Whether to show an arrow on the submenu button to indicate
|
|
413
|
+
that it can be expanded. Defaults to true.
|
|
414
|
+
*/
|
|
415
|
+
arrow?: boolean;
|
|
416
|
+
/**
|
|
417
|
+
A base with for the submenu button, in CSS `ch` units. Can
|
|
418
|
+
be useful when the menu uses a dynamic textual label, and
|
|
419
|
+
you want to prevent it from changing size as its label
|
|
420
|
+
changes.
|
|
421
|
+
*/
|
|
422
|
+
width?: number;
|
|
423
|
+
/**
|
|
424
|
+
An optional default content. See the {@link Menu.resolve
|
|
425
|
+
resolution system}.
|
|
426
|
+
*/
|
|
427
|
+
content?: readonly (Item | "...")[];
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
A resolved submenu, part of the output of {@link
|
|
431
|
+
Menu.resolve}.
|
|
432
|
+
*/
|
|
433
|
+
class Resolved {
|
|
434
|
+
/**
|
|
435
|
+
The submenu item.
|
|
436
|
+
*/
|
|
437
|
+
readonly item: Submenu;
|
|
438
|
+
/**
|
|
439
|
+
The items inside the submenu.
|
|
440
|
+
*/
|
|
441
|
+
readonly content: readonly Item.Resolved[];
|
|
442
|
+
private constructor();
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
The submenu to select textblock type. Used to switch between,
|
|
446
|
+
for example, regular paragraphs and headings
|
|
447
|
+
*/
|
|
448
|
+
const textblockStyle: Submenu;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
Templates are used to explicitly choose (part of) your menu
|
|
452
|
+
structure, rather than letting the resolution algorithm build
|
|
453
|
+
one from your configuration. See {@link Menu.resolve}, {@link
|
|
454
|
+
Menu.Group.template `Group.template`}, and {@link
|
|
455
|
+
Menu.Submenu.template `Submenu.template`}.
|
|
456
|
+
*/
|
|
457
|
+
class Template {
|
|
458
|
+
private tag;
|
|
459
|
+
private constructor();
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
Given a set of menu items and optionally a template, this
|
|
463
|
+
function will resolve a concrete menu tree. To do this, it goes
|
|
464
|
+
through the template (which defaults to just the {@link
|
|
465
|
+
Menu.Group.top top group}), filling in open spaces (represented
|
|
466
|
+
as the string literal `"..."`) with any items provided that have
|
|
467
|
+
the group or submenu as parent.
|
|
468
|
+
|
|
469
|
+
The idea is to combine a top-down (the template) and bottom-up
|
|
470
|
+
(the items, which typically come from an editor {@link
|
|
471
|
+
Menu.Item.source configuration}) in a way that allows the user
|
|
472
|
+
to figure out a balance between manually specifying their menu
|
|
473
|
+
and just using whatever is in the configuration.
|
|
474
|
+
|
|
475
|
+
Items that are used explicitly in a template will not be used
|
|
476
|
+
again implicitly. Items included in the `suppress` parameter
|
|
477
|
+
will be ignored.
|
|
478
|
+
|
|
479
|
+
When a submenu or group specifies default content, this will
|
|
480
|
+
only be used when the template does not specify its own content
|
|
481
|
+
for the item.
|
|
482
|
+
*/
|
|
483
|
+
function resolve(items: readonly Item[], template?: Template | readonly Template[], suppress?: readonly Item[]): readonly Item.Resolved[];
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
This command handles text input. To selectively override the
|
|
488
|
+
behavior of text input, provide a handler that, when the
|
|
489
|
+
conditions that it requires apply, handles the input and returns
|
|
490
|
+
true. `userEvent` will generally be one of `"input.type"`,
|
|
491
|
+
`"input.type.compose"` (text inserted as part as a composition),
|
|
492
|
+
or `"input.type.compose.start"` (initial text created by a started
|
|
493
|
+
composition).
|
|
494
|
+
*/
|
|
495
|
+
declare const insertText: Command.Pure<{
|
|
496
|
+
from: number;
|
|
497
|
+
to: number;
|
|
498
|
+
insert: string;
|
|
499
|
+
userEvent: string;
|
|
500
|
+
}>;
|
|
501
|
+
/**
|
|
502
|
+
Command to insert a line break. The default handler will, if the
|
|
503
|
+
schema defines a {@link Node.Role.LineBreak line break} node and
|
|
504
|
+
the selection's parent node allows that, insert such a node.
|
|
505
|
+
Otherwise, in nodes marked as
|
|
506
|
+
{@link Plot.Spec.preserveWhitespace whitespace-preserving}, this
|
|
507
|
+
will insert a line break.
|
|
508
|
+
*/
|
|
509
|
+
declare const insertLineBreak: Command.Pure;
|
|
510
|
+
/**
|
|
511
|
+
The command that handles enter presses. The default handler will,
|
|
512
|
+
if the selection is not in an inline context, insert an empty
|
|
513
|
+
default textblock in its position. Otherwise it first tries
|
|
514
|
+
`liftEmptyTextblock`, then `splitTextblock`.
|
|
515
|
+
*/
|
|
516
|
+
declare const enter: Command.Pure;
|
|
517
|
+
/**
|
|
518
|
+
Delete the selection, or the unit after or before the selection.
|
|
519
|
+
If that unit is the start or end of a textblock, this will try to
|
|
520
|
+
join that textblock to the next one. Otherwise, if it is a
|
|
521
|
+
character or leaf node, that is deleted. If none of that is
|
|
522
|
+
possible and the cursor is in an empty textblock, this will delete
|
|
523
|
+
the textblock.
|
|
524
|
+
|
|
525
|
+
When deleting backward at the start of a list item that has a
|
|
526
|
+
sibling before it, this command will try to join those list items.
|
|
527
|
+
*/
|
|
528
|
+
declare const deleteUnit: Command.Pure<"forward" | "backward">;
|
|
529
|
+
/**
|
|
530
|
+
Delete the selection, or the word next to it. Will behave like
|
|
531
|
+
{@link deleteUnit}, except that, when deleting text, it will
|
|
532
|
+
delete an entire word.
|
|
533
|
+
*/
|
|
534
|
+
declare const deleteWord: Command.Pure<"forward" | "backward">;
|
|
535
|
+
/**
|
|
536
|
+
Delete to the end or start of the line. Stops at line wrapping
|
|
537
|
+
points.
|
|
538
|
+
*/
|
|
539
|
+
declare const deleteToLineEnd: Command<"forward" | "backward">;
|
|
540
|
+
/**
|
|
541
|
+
Delete the selection, or if that is empty, the line around the
|
|
542
|
+
cursor.
|
|
543
|
+
*/
|
|
544
|
+
declare const deleteLine: Command;
|
|
545
|
+
/**
|
|
546
|
+
Swap the characters before and after the cursor.
|
|
547
|
+
*/
|
|
548
|
+
declare const transposeChars: Command.Pure;
|
|
549
|
+
/**
|
|
550
|
+
Set the type of the textblock(s) around the selection to the given
|
|
551
|
+
tag.
|
|
552
|
+
*/
|
|
553
|
+
declare const setTextblockType: Command.Pure<Plot.Tag>;
|
|
554
|
+
/**
|
|
555
|
+
Try to unwrap blocks around the selection. The second argument, if
|
|
556
|
+
given, indicates what kind of wrapping plots may be removed.
|
|
557
|
+
Returns null when no unwrapping is possible.
|
|
558
|
+
*/
|
|
559
|
+
declare const unwrapBlock: Command.Pure<Node.Query | null>;
|
|
560
|
+
/**
|
|
561
|
+
Try to wrap selected textblocks in the given wrapper. Will return
|
|
562
|
+
null if no wrapping is possible.
|
|
563
|
+
*/
|
|
564
|
+
declare const wrapBlock: Command.Pure<Plot.Tag>;
|
|
565
|
+
/**
|
|
566
|
+
If the selection is in a block of the given type, unwap it.
|
|
567
|
+
Otherwise, try to wrap the selected blocks in such a tag.
|
|
568
|
+
*/
|
|
569
|
+
declare const toggleBlock: Command.Pure<Plot.Tag>;
|
|
570
|
+
/**
|
|
571
|
+
Toggle the given mark. If there is no selection, it is added to
|
|
572
|
+
the cursor's active marks, or removed if it is already in there.
|
|
573
|
+
Otherwise, if any selected content allows for the mark to be
|
|
574
|
+
added, it is added. If not, remove the mark from the selection.
|
|
575
|
+
*/
|
|
576
|
+
declare const toggleMark: Command.Pure<Mark>;
|
|
577
|
+
/**
|
|
578
|
+
Toggle emphasis. The default implementation uses the {@link
|
|
579
|
+
Emphasis} mark.
|
|
580
|
+
*/
|
|
581
|
+
declare const toggleEmphasis: Command.Pure;
|
|
582
|
+
/**
|
|
583
|
+
Toggle strong emphasis. The default implementation uses the {@link
|
|
584
|
+
Strong} mark.
|
|
585
|
+
*/
|
|
586
|
+
declare const toggleStrong: Command.Pure;
|
|
587
|
+
/**
|
|
588
|
+
Toggle underlining. The default implementation uses the {@link
|
|
589
|
+
Underline} mark.
|
|
590
|
+
*/
|
|
591
|
+
declare const toggleUnderline: Command.Pure;
|
|
592
|
+
/**
|
|
593
|
+
Set the selected textblocks to the given alignment. `"left"` and
|
|
594
|
+
`"right"` will be normalized to `"start"` or `"end"` depending on
|
|
595
|
+
the editor's text direction. The default implementation uses the
|
|
596
|
+
{@link Alignment} mark.
|
|
597
|
+
*/
|
|
598
|
+
declare const setAlignment: Command.Pure<null | "start" | "end" | "center" | "left" | "right">;
|
|
599
|
+
/**
|
|
600
|
+
Set the text direction for the selected textblocks. `null` will
|
|
601
|
+
remove an explicit direction mark, defaulting the blocks back to
|
|
602
|
+
the editor's base direction. The default implementation uses the
|
|
603
|
+
{@link Direction} mark.
|
|
604
|
+
*/
|
|
605
|
+
declare const setDirection: Command.Pure<null | "ltr" | "rtl" | "auto">;
|
|
606
|
+
/**
|
|
607
|
+
Toggle list wrapping with the given list tag for the selected
|
|
608
|
+
blocks.
|
|
609
|
+
*/
|
|
610
|
+
declare const toggleList: Command.Pure<Plot.Tag>;
|
|
611
|
+
/**
|
|
612
|
+
Returns true when all selected textblocks are wrapped in a list of
|
|
613
|
+
the given type.
|
|
614
|
+
*/
|
|
615
|
+
declare const listIsActive: (listTag: Plot.Tag) => (state: GardState) => boolean;
|
|
616
|
+
/**
|
|
617
|
+
Move the selection head one unit (text cluster, atomic node, or
|
|
618
|
+
node boundary) in the indicated direction. When `extend` is true,
|
|
619
|
+
keep the selection anchor in place. The default handler moves
|
|
620
|
+
visually through bidirectional text, so when going left, the
|
|
621
|
+
motion will go back in left-to-right text, and
|
|
622
|
+
forward in right-to-left text.
|
|
623
|
+
*/
|
|
624
|
+
declare const moveByUnit: Command.Pure<{
|
|
625
|
+
dir: "left" | "right" | "forward" | "backward";
|
|
626
|
+
extend?: boolean;
|
|
627
|
+
}>;
|
|
628
|
+
/**
|
|
629
|
+
Move the selection head one word in the indicated direction. Keep
|
|
630
|
+
the anchor in place if `extend` is true. The default handler moves
|
|
631
|
+
visually.
|
|
632
|
+
*/
|
|
633
|
+
declare const moveByWord: Command.Pure<{
|
|
634
|
+
dir: "left" | "right";
|
|
635
|
+
extend?: boolean;
|
|
636
|
+
}>;
|
|
637
|
+
/**
|
|
638
|
+
Move the selection head one line up or down. When `extend` is
|
|
639
|
+
true, keep the anchor in place.
|
|
640
|
+
*/
|
|
641
|
+
declare const moveByLine: Command<{
|
|
642
|
+
dir: "up" | "down";
|
|
643
|
+
extend?: boolean;
|
|
644
|
+
}>;
|
|
645
|
+
/**
|
|
646
|
+
Move the selection head one page up or down. Extend the selection
|
|
647
|
+
when the `extend` flag is true.
|
|
648
|
+
*/
|
|
649
|
+
declare const moveByPage: Command<{
|
|
650
|
+
dir: "up" | "down";
|
|
651
|
+
extend?: boolean;
|
|
652
|
+
}>;
|
|
653
|
+
/**
|
|
654
|
+
Move to the indicated side of the current line. Will stop at line
|
|
655
|
+
wrap points. `"left"` and `"right"` will be interpreted based on
|
|
656
|
+
the editor's text direction.
|
|
657
|
+
*/
|
|
658
|
+
declare const moveToLineSide: Command<{
|
|
659
|
+
dir: "left" | "right" | "forward" | "backward";
|
|
660
|
+
extend?: boolean;
|
|
661
|
+
}>;
|
|
662
|
+
/**
|
|
663
|
+
Move to the start or end of the textblock that has the selection
|
|
664
|
+
head.
|
|
665
|
+
*/
|
|
666
|
+
declare const moveToTextblockSide: Command<{
|
|
667
|
+
dir: "left" | "right" | "forward" | "backward";
|
|
668
|
+
extend?: boolean;
|
|
669
|
+
}>;
|
|
670
|
+
/**
|
|
671
|
+
Move to the start or end of the document.
|
|
672
|
+
*/
|
|
673
|
+
declare const moveToDocSide: Command.Pure<{
|
|
674
|
+
side: "start" | "end";
|
|
675
|
+
extend?: boolean;
|
|
676
|
+
}>;
|
|
677
|
+
/**
|
|
678
|
+
Select the entire document.
|
|
679
|
+
*/
|
|
680
|
+
declare const selectAll: Command.Pure;
|
|
681
|
+
/**
|
|
682
|
+
Undo an edit. Does not have a default handler, but a handler is
|
|
683
|
+
added by the history extension.
|
|
684
|
+
*/
|
|
685
|
+
declare const undo: Command;
|
|
686
|
+
/**
|
|
687
|
+
Redo an edit. Does not have a default handler.
|
|
688
|
+
*/
|
|
689
|
+
declare const redo: Command;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
If the cursor is in an empty textblock that can be lifted out of a
|
|
693
|
+
parent, return a transaction that does this.
|
|
694
|
+
*/
|
|
695
|
+
declare function liftEmptyBlock(state: GardState): Transaction.Spec | false;
|
|
696
|
+
/**
|
|
697
|
+
Split the textblock at the cursor position, if any. If the
|
|
698
|
+
textblock is the first child of a list item, also split that item,
|
|
699
|
+
unless `splitListItem` is false.
|
|
700
|
+
*/
|
|
701
|
+
declare function splitTextblock(state: GardState, splitListItem?: boolean): Transaction.Spec | false;
|
|
702
|
+
/**
|
|
703
|
+
Returns a transaction that deletes the selection, or false if the
|
|
704
|
+
selection is empty.
|
|
705
|
+
*/
|
|
706
|
+
declare function deleteSelection(state: GardState): Transaction.Spec | false;
|
|
707
|
+
/**
|
|
708
|
+
If the cursor is inside an empty textblock, return a transaction
|
|
709
|
+
that deletes the entire block. `dir` determines which way the
|
|
710
|
+
cursor moves after the deletion.
|
|
711
|
+
*/
|
|
712
|
+
declare function deleteEmptyTextblock(state: GardState, dir?: -1 | 1): Transaction.Spec | false;
|
|
713
|
+
/**
|
|
714
|
+
If the cursor is at the start of a textblock that can be joined to
|
|
715
|
+
a textblock before it, return a transaction to performs this join.
|
|
716
|
+
*/
|
|
717
|
+
declare function joinBackward(state: GardState): Transaction.Spec | false;
|
|
718
|
+
/**
|
|
719
|
+
If the cursor is at the start of a list item that has another item
|
|
720
|
+
before it, return a transaction that joins those two items.
|
|
721
|
+
*/
|
|
722
|
+
declare function joinListItems(state: GardState): Transaction.Spec | false;
|
|
723
|
+
/**
|
|
724
|
+
If the cursor is at the end of a textblock that can be joined to
|
|
725
|
+
the textblock after it, return a transaction that performs this
|
|
726
|
+
join.
|
|
727
|
+
*/
|
|
728
|
+
declare function joinForward(state: GardState): Transaction.Spec | false;
|
|
729
|
+
/**
|
|
730
|
+
Create a transaction that deletes the atomic node or text
|
|
731
|
+
cluster/word in front of the cursor, if possible.
|
|
732
|
+
*/
|
|
733
|
+
declare function deleteBackward(state: GardState, word?: boolean): Transaction.Spec | false;
|
|
734
|
+
/**
|
|
735
|
+
Return a transaction that deletes the element (text cluster or
|
|
736
|
+
leaf node) after the cursor, if any.
|
|
737
|
+
*/
|
|
738
|
+
declare function deleteForward(state: GardState, word?: boolean): Transaction.Spec | false;
|
|
739
|
+
/**
|
|
740
|
+
Get an array of all textblocks that contain part of the selection.
|
|
741
|
+
*/
|
|
742
|
+
declare function selectedTextblocks(state: GardState): Pos.Plot[];
|
|
743
|
+
/**
|
|
744
|
+
Remove all content in `node` that is not allowed to appear in
|
|
745
|
+
`type`.
|
|
746
|
+
*/
|
|
747
|
+
declare function clearNonFitting(schema: Schema, node: Pos.Plot, type: Plot.Type): ChangeSet.Spec;
|
|
748
|
+
/**
|
|
749
|
+
Find a way to wrap the blocks betwen `from` and `to` in a node
|
|
750
|
+
with the given tag. Returns precise start and end positions where
|
|
751
|
+
a wrap is possible, or null if none is possible.
|
|
752
|
+
*/
|
|
753
|
+
declare function findWrappable(from: Pos, to: Pos, wrapper: Plot.Tag): {
|
|
754
|
+
from: Pos;
|
|
755
|
+
to: Pos;
|
|
756
|
+
} | null;
|
|
757
|
+
/**
|
|
758
|
+
Wrap the given range in the given wrapper tag. The caller is
|
|
759
|
+
responsible for verifying that this is actually a valid wrapping.
|
|
760
|
+
It is recommended to use {@link findWrappable} for finding wrap
|
|
761
|
+
positions in non-trivial situations.
|
|
762
|
+
*/
|
|
763
|
+
declare function wrapBlockRange(range: {
|
|
764
|
+
from: Pos;
|
|
765
|
+
to: Pos;
|
|
766
|
+
}, wrapper: Plot.Tag): ChangeSet.Spec[];
|
|
767
|
+
/**
|
|
768
|
+
Find the set of block nodes around the given range that match the
|
|
769
|
+
predicate (if any) and can be unwrapped, meaning their content
|
|
770
|
+
gets moved out to a parent node.
|
|
771
|
+
*/
|
|
772
|
+
declare function findUnwrappable(schema: Schema, from: Pos, to: Pos, query?: Node.Query): Pos.Plot[] | null;
|
|
773
|
+
/**
|
|
774
|
+
Unwrap the given block node, or the node's children between `from`
|
|
775
|
+
and `to`.
|
|
776
|
+
*/
|
|
777
|
+
declare function doUnwrapBlock(block: Pos.Plot, from?: number, to?: number): ChangeSet.Spec;
|
|
778
|
+
/**
|
|
779
|
+
Join two adjacent (only separated by first a sequence of block end
|
|
780
|
+
tokens and then a sequence of block open tokens) block plots.
|
|
781
|
+
*/
|
|
782
|
+
declare function joinBlocks(before: Pos.Plot, after: Pos.Plot): ChangeSet.Spec;
|
|
783
|
+
/**
|
|
784
|
+
Query whether the given range has any content to which the given
|
|
785
|
+
mark or mark type could be added.
|
|
786
|
+
*/
|
|
787
|
+
declare function canAddMarkInRange(doc: Plot.Doc, from: number, to: number, mark: Mark | Mark.Type): boolean;
|
|
788
|
+
/**
|
|
789
|
+
Post-process the given transaction spec to check for any block
|
|
790
|
+
boundaries touched by the changes in it that can be {@link
|
|
791
|
+
Plot.Spec.autoJoin auto-joined}. If any are found, the spec is
|
|
792
|
+
updated to perform those joins.
|
|
793
|
+
*/
|
|
794
|
+
declare function autoJoinBlocks(state: GardState, tr: Transaction.Spec): Transaction.Spec;
|
|
795
|
+
|
|
796
|
+
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyTextblock, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange };
|