@nerd-bible/wordgard 0.5.3-beta6 → 0.6.2-beta1

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/dist/editor.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as wordgard_doc from 'wordgard/doc';
2
- import { Elt, Node as Node$1, ChangeSet, Plot, Pos } from 'wordgard/doc';
2
+ import { Elt, Node as Node$1, Mark, Shape, ChangeSet, Plot, Pos } from 'wordgard/doc';
3
3
  import { GardState, TextblockMap, Transaction, GardSelection } from 'wordgard/state';
4
4
  import { PhraseSet } from 'wordgard/phrases';
5
5
  import { StyleModule, StyleSpec } from 'style-mod';
@@ -125,7 +125,7 @@ declare namespace Decoration {
125
125
  This function allows you to define a {@link Decoration.Tag.shape
126
126
  custom node shape} that depends on the editor state. It will
127
127
  automatically track which state slots (see {@link
128
- GardState.Facet.compute}) you use, and make sure the nodes
128
+ GardState.Facet.derive}) you use, and make sure the nodes
129
129
  are redrawn when those change.
130
130
 
131
131
  If your shape function returns a function from a tag, you
@@ -141,8 +141,7 @@ declare namespace Decoration {
141
141
  When providing a shape for a plot that changes whether it is
142
142
  rendered as an atom, provide the `atom` option.
143
143
  */
144
- function dynamic<T extends Node$1.Type<any>>(// FIXME find better name?
145
- type: T, shape: (state: GardState) => Shape | ((tag: Node$1.Tag.For<T>) => Shape), config?: {
144
+ function derived<T extends Node$1.Type<any>>(type: T, shape: (state: GardState) => Shape | ((tag: Node$1.Tag.For<T>) => Shape), config?: {
146
145
  atom?: boolean;
147
146
  }): GardState.Extension;
148
147
  }
@@ -172,9 +171,9 @@ declare namespace Decoration {
172
171
  /**
173
172
  Define a node widget decoration that depends on some aspect
174
173
  of the editor state. See the notes for {@link
175
- Decoration.Tag.shape.dynamic}.
174
+ Decoration.Tag.shape.derived}.
176
175
  */
177
- function dynamic<T extends Node$1.Type.Ref<any>>(type: T, place: "before" | "after" | "start" | "end", widget: (state: GardState) => Widget | ((tag: Node$1.Tag.For<T>) => Widget)): GardState.Extension;
176
+ function derived<T extends Node$1.Type.Ref<any>>(type: T, place: "before" | "after" | "start" | "end", widget: (state: GardState) => Widget | ((tag: Node$1.Tag.For<T>) => Widget)): GardState.Extension;
178
177
  }
179
178
  /**
180
179
  Add an attribute to the representation of a given node type.
@@ -190,6 +189,13 @@ declare namespace Decoration {
190
189
  target?: string;
191
190
  }): GardState.Extension;
192
191
  }
192
+ namespace Mark {
193
+ /**
194
+ Override the shape used for a given mark inside the editor.
195
+ */
196
+ function shape<V>(type: Mark.Type<V>, shape: Shape.Element<V> | Shape.Attribute<V> | Shape.Attributes<V>): GardState.Extension;
197
+ function shape(mark: Mark<null>, shape: Shape.Element<null> | Shape.Attribute<null> | Shape.Attributes<null>): GardState.Extension;
198
+ }
193
199
  /**
194
200
  A point decoration is a decoration that targets a given position
195
201
  in the document, or the node after a given position. Sets of
@@ -691,7 +697,7 @@ declare class Wordgard {
691
697
  Serializers are tried in order of precedence until one returns
692
698
  a string.
693
699
  */
694
- static clipboardTextSerializer: GardState.Facet<(slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[], state: GardState) => string | null, readonly ((slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[], state: GardState) => string | null)[]>;
700
+ static clipboardTextSerializer: GardState.Facet<(slice: wordgard_doc.Slice, state: GardState) => string | null, readonly ((slice: wordgard_doc.Slice, state: GardState) => string | null)[]>;
695
701
  /**
696
702
  Filter to run on the plain text representation of content put
697
703
  onto the clipboard.
@@ -721,7 +727,7 @@ declare class Wordgard {
721
727
  Facet that allows you to register handlers to override paste
722
728
  behavior.
723
729
  */
724
- static pasteHandler: GardState.Facet<(wg: Wordgard, event: ClipboardEvent, slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[]) => boolean, readonly ((wg: Wordgard, event: ClipboardEvent, slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[]) => boolean)[]>;
730
+ static pasteHandler: GardState.Facet<(wg: Wordgard, event: InputEvent, slice: wordgard_doc.Slice) => boolean, readonly ((wg: Wordgard, event: InputEvent, slice: wordgard_doc.Slice) => boolean)[]>;
725
731
  /**
726
732
  Facet for custom drop handlers. When the drop is done inside the
727
733
  editor and should move an existing range, the `move` parameter
@@ -730,10 +736,10 @@ declare class Wordgard {
730
736
  static dropHandler: GardState.Facet<(wg: Wordgard, event: DragEvent, pos: number, move: {
731
737
  from: number;
732
738
  to: number;
733
- } | null, slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[]) => boolean, readonly ((wg: Wordgard, event: DragEvent, pos: number, move: {
739
+ } | null, slice: wordgard_doc.Slice) => boolean, readonly ((wg: Wordgard, event: DragEvent, pos: number, move: {
734
740
  from: number;
735
741
  to: number;
736
- } | null, slice: wordgard_doc.Slice, context: readonly wordgard_doc.Plot.Tag[]) => boolean)[]>;
742
+ } | null, slice: wordgard_doc.Slice) => boolean)[]>;
737
743
  /**
738
744
  This annotation is added to transactions created because the
739
745
  editor's focused status changed. It holds `true` when the editor
@@ -1160,9 +1166,8 @@ appear in
1160
1166
  Use lowercase letters to refer to letter keys. You can use
1161
1167
  `"Space"` as an alias for the `" "` name.
1162
1168
 
1163
- Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
1164
- `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
1165
- `Meta-`) are recognized.
1169
+ Modifiers can be given in any order. `Shift-`, `Alt-`, `Ctrl-` and
1170
+ `Cmd-` (or `Meta-`) are recognized.
1166
1171
 
1167
1172
  You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
1168
1173
  other platforms. So `Mod-b` is `Ctrl-b` on Linux but `Cmd-b` on
@@ -1238,28 +1243,28 @@ declare namespace KeyBinding {
1238
1243
  */
1239
1244
  any?: (wg: Wordgard, event: KeyboardEvent) => boolean;
1240
1245
  /**
1241
- By default, key bindings apply when focus is on the editor
1242
- content (the `"editor"` scope). Some extensions, mostly those
1243
- that define their own panels, might want to allow registering
1244
- bindings local to that panel. Such bindings should use a custom
1245
- scope name. You may also assign multiple scope names to a
1246
- binding, separating them by spaces.
1247
- */
1248
- scope?: string;
1249
- /**
1250
1246
  By default, all keys events for which a handler exists have
1251
1247
  their `preventDefault` called, even if no handler returns
1252
1248
  true. You can set this to true to disable that behavior.
1253
1249
  */
1254
1250
  allowDefault?: boolean;
1251
+ /**
1252
+ A textual description of what this key does. Will be used by
1253
+ {@link keyBindingHelp} to create a list of active bindings.
1254
+ */
1255
+ description?: PhraseSet.Ref | string;
1256
+ /**
1257
+ A textual description of what the shifted variant of this key
1258
+ does.
1259
+ */
1260
+ shiftDescription?: PhraseSet.Ref | string;
1261
+ /**
1262
+ The group under which the description of this key should be
1263
+ organized in the list of bindings.
1264
+ */
1265
+ group?: Group;
1255
1266
  }
1256
1267
  /**
1257
- Run the key handlers registered for a given scope. The event
1258
- object should be a `"keydown"` event. Returns true if any of the
1259
- handlers handled it.
1260
- */
1261
- function runScopeHandlers(wg: Wordgard, event: KeyboardEvent, scope: string): boolean;
1262
- /**
1263
1268
  Facet used for registering key bindings. Extension precedence
1264
1269
  determines the order in which bindings that match the same key
1265
1270
  are called. When a handler has returned `true` for a given key,
@@ -1273,6 +1278,38 @@ declare namespace KeyBinding {
1273
1278
  */
1274
1279
  const useDefaultKeymap: GardState.Facet<boolean, boolean>;
1275
1280
  /**
1281
+ Key binding groups are used to {@link KeyBinding.Spec.group
1282
+ organize} key bindings in the user-presented {@link
1283
+ keyBindingHelp list} of bindings.
1284
+ */
1285
+ class Group {
1286
+ /**
1287
+ The description given for this group.
1288
+ */
1289
+ readonly description: PhraseSet.Ref | string;
1290
+ /**
1291
+ A sorting rank.
1292
+ */
1293
+ readonly rank: number;
1294
+ private constructor();
1295
+ /**
1296
+ Define a key binding group.
1297
+ */
1298
+ static define(spec: {
1299
+ description: PhraseSet.Ref | string;
1300
+ rank?: number;
1301
+ }): Group;
1302
+ static Inline: Group;
1303
+ static Block: Group;
1304
+ static History: Group;
1305
+ }
1306
+ /**
1307
+ Look for a key associated with the given description in the
1308
+ state's key bindings, and if found, return its key name as a
1309
+ string.
1310
+ */
1311
+ function lookupByDescription(state: GardState, desc: string | PhraseSet.Ref): string | null;
1312
+ /**
1276
1313
  The editor's set of default key bindings. Binds the following
1277
1314
  keys. Most cursor motion bindings include a `Shift-` variant
1278
1315
  that passes the `extend` flag to the command. Enabled by default
@@ -1326,6 +1363,27 @@ declare namespace KeyBinding {
1326
1363
  const defaultKeymap: readonly KeyBinding[];
1327
1364
  }
1328
1365
 
1366
+ /**
1367
+ Returns an extension that binds `Mod-?` to {@link
1368
+ keyBindingHelp.showKeyBindings}.
1369
+ */
1370
+ declare function keyBindingHelp(): GardState.Extension;
1371
+ declare namespace keyBindingHelp {
1372
+ /**
1373
+ This command opens a dialog displaying the key bindings that
1374
+ have a description associated with them.
1375
+ */
1376
+ const showKeyBindings: Command;
1377
+ /**
1378
+ A menu button that, when clicked, displays the available key bindings.
1379
+ */
1380
+ const button: Menu.Button;
1381
+ /**
1382
+ Bind `Mod-?` to {@link keyBindingHelp.showKeyBindings `showKeyBindings`}.
1383
+ */
1384
+ const keyBindings: KeyBinding[];
1385
+ }
1386
+
1329
1387
  type Config = {
1330
1388
  /**
1331
1389
  The type of plot to decorate.
@@ -1433,81 +1491,6 @@ declare function menuBar(config?: {
1433
1491
  template?: Menu.Template | readonly Menu.Template[];
1434
1492
  }): GardState.Extension;
1435
1493
 
1436
- /**
1437
- Dialogs are {@link Panel panels} opened as a side-effect, and
1438
- closed by user action. This interface is used to describe them.
1439
- */
1440
- interface Dialog {
1441
- /**
1442
- A function to render the content of the dialog. The result
1443
- should contain at least one `<form>` element. Submit handlers
1444
- and a handler for the Escape key will be added to the form.
1445
-
1446
- If this is not given, the `label`, `input`, and `submitLabel`
1447
- fields will be used to create a simple form for you.
1448
- */
1449
- content?: (wg: Wordgard, close: () => void) => Element;
1450
- /**
1451
- When `content` isn't given, this provides the text shown in the
1452
- dialog.
1453
- */
1454
- label?: string;
1455
- /**
1456
- The attributes for an input element shown next to the label. If
1457
- not given, no input element is added.
1458
- */
1459
- input?: {
1460
- [attr: string]: string;
1461
- };
1462
- /**
1463
- The label for the button that submits the form. Defaults to
1464
- `"OK"`.
1465
- */
1466
- submitLabel?: string;
1467
- /**
1468
- Extra classes to add to the panel.
1469
- */
1470
- class?: string;
1471
- /**
1472
- A query selector to find the field that should be focused when
1473
- the dialog is opened. When set to true, this picks the first
1474
- `<input>` or `<button>` element in the form. When set to
1475
- `false`, focus is not moved into the dialog.
1476
- */
1477
- focus?: string | boolean;
1478
- /**
1479
- By default, dialogs are shown above the editor. Set this to
1480
- `false` to have it show up at the bottom.
1481
- */
1482
- top?: boolean;
1483
- }
1484
- declare namespace Dialog {
1485
- /**
1486
- Show a dialog to display a message or prompt the user for input.
1487
- Returns an effect that can be dispatched to close the dialog,
1488
- and a promise that resolves when the dialog is closed or a form
1489
- inside of it is submitted.
1490
-
1491
- You are encouraged, if your handling of the result of the promise
1492
- dispatches a transaction, to include the `close` effect in it. If
1493
- you don't, this function will automatically dispatch a separate
1494
- transaction right after.
1495
- */
1496
- function show(wg: Wordgard, config: Dialog): {
1497
- close: Transaction.Effect<unknown>;
1498
- result: Promise<HTMLFormElement | null>;
1499
- };
1500
- /**
1501
- Find the {@link Panel} for an open dialog, using a class name as
1502
- identifier.
1503
- */
1504
- function get(wg: Wordgard, className: string): Panel | null;
1505
- /**
1506
- Close the {@link Panel} for an open dialog, by class name.
1507
- */
1508
- function close(wg: Wordgard, className: string): boolean;
1509
- }
1510
-
1511
1494
  /**
1512
1495
  Describes a tooltip. Values of this type, when provided through
1513
1496
  the {@link Tooltip.show} facet, provide the active tooltips on an
@@ -1732,6 +1715,109 @@ hover tooltip source}.
1732
1715
  */
1733
1716
  type HoverTooltipSource = (wg: Wordgard, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>;
1734
1717
 
1718
+ /**
1719
+ Dialogs are UI elements opened as a side-effect and closed by user
1720
+ action. They may be either placed near some document position (as
1721
+ a {@link Tooltip tooltip}), or free-floating.
1722
+ */
1723
+ interface Dialog {
1724
+ /**
1725
+ An arbitrary value used to identify this dialog. Used to query
1726
+ for it via {@link Dialog.get}.
1727
+ */
1728
+ key?: any;
1729
+ /**
1730
+ A function to render the content of the dialog. The result
1731
+ should contain at least one `<form>` element. Submit handlers
1732
+ and a handler for the Escape key will be added to the form.
1733
+
1734
+ If this is not given, the `label`, `input`, and `submitLabel`
1735
+ fields will be used to create a simple form for you.
1736
+ */
1737
+ content?: (wg: Wordgard, close: () => void) => Element | DocumentFragment;
1738
+ /**
1739
+ When `content` isn't given, this provides the text shown in the
1740
+ dialog.
1741
+ */
1742
+ label?: string;
1743
+ /**
1744
+ The attributes for an input element shown next to the label. If
1745
+ not given, no input element is added.
1746
+ */
1747
+ input?: {
1748
+ [attr: string]: string;
1749
+ };
1750
+ /**
1751
+ The label for the button that submits the form. Defaults to
1752
+ `"OK"`.
1753
+ */
1754
+ submitLabel?: string;
1755
+ /**
1756
+ Extra classes to add to the element.
1757
+ */
1758
+ class?: string;
1759
+ /**
1760
+ A query selector to find the field that should be focused when
1761
+ the dialog is opened. When set to true, this picks the first
1762
+ `<input>` or `<button>` element in the form. When set to
1763
+ `false`, focus is not moved into the dialog.
1764
+ */
1765
+ focus?: string | boolean;
1766
+ /**
1767
+ If given, a transaction for which the predicate returns true
1768
+ will automatically close the dialog.
1769
+ */
1770
+ closedBy?: (tr: Transaction) => boolean;
1771
+ /**
1772
+ Provide this option to position this dialog like a tooltip,
1773
+ relative to some document position.
1774
+ */
1775
+ tooltip?: Omit<Tooltip, "create">;
1776
+ /**
1777
+ If given try to align the left top (or right top, in a
1778
+ right-to-left layout) with the corner of this rectangle. If set
1779
+ to `true`, call {@link PositioningHint.get} to try and get a
1780
+ rectangle. When available, this will override the `tooltip`
1781
+ option.
1782
+ */
1783
+ positioningHint?: DOMRect | true;
1784
+ }
1785
+ declare namespace Dialog {
1786
+ /**
1787
+ Show a dialog to display a message or prompt the user for input.
1788
+ Returns a function that closes the dialog and a promise that
1789
+ resolves when the dialog is closed or a form inside of it is
1790
+ submitted.
1791
+ */
1792
+ function show(wg: Wordgard, config: Dialog): {
1793
+ close: () => void;
1794
+ result: Promise<HTMLFormElement | null>;
1795
+ };
1796
+ /**
1797
+ See whether a dialog with the given key is present in the
1798
+ editor, and if so return its DOM representation and a functionto
1799
+ close it. Note that `dom` may be `null` if the dialog is present
1800
+ but not yet rendered.
1801
+ */
1802
+ function get(wg: Wordgard, key: any): {
1803
+ dom: HTMLElement | null;
1804
+ close: () => void;
1805
+ } | null;
1806
+ }
1807
+ declare namespace PositioningHint {
1808
+ /**
1809
+ Run function `run` with the positioning hint provided by `hint`
1810
+ available. Until that function returns, {@link
1811
+ PositioningHint.get} will return this rectangle, unless a nested
1812
+ call to `runWith` shadows it.
1813
+ */
1814
+ function runWith<T>(hint: () => DOMRect, run: () => T): T;
1815
+ /**
1816
+ Get the current positioning hint, if available.
1817
+ */
1818
+ function get(): DOMRect | null;
1819
+ }
1820
+
1735
1821
  /**
1736
1822
  Objects of this type represent input rules.
1737
1823
  */
@@ -1861,4 +1947,4 @@ being dragged over the editor.
1861
1947
  */
1862
1948
  declare function dropCursor(): GardState.Extension;
1863
1949
 
1864
- export { Decoration, Dialog, InputRule, KeyBinding, Panel, Tooltip, Widget, Wordgard, decoratePlots, dropCursor, menuBar, placeholder };
1950
+ export { Decoration, Dialog, InputRule, KeyBinding, Panel, PositioningHint, Tooltip, Widget, Wordgard, decoratePlots, dropCursor, keyBindingHelp, menuBar, placeholder };