@nerd-bible/wordgard 0.6.2-beta1 → 0.6.2-beta10

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/history.js CHANGED
@@ -4,6 +4,7 @@ import { Command, undo as undo$1, redo as redo$1, Menu } from 'wordgard/command'
4
4
  import { phrases } from 'wordgard/phrases';
5
5
 
6
6
  const fromHistory = /*@__PURE__*/Transaction.Effect.define({
7
+ name: "fromHistory",
7
8
  map(value, change) {
8
9
  return {
9
10
  side: value.side,
@@ -13,6 +14,7 @@ const fromHistory = /*@__PURE__*/Transaction.Effect.define({
13
14
  }
14
15
  });
15
16
  const historyConfig = /*@__PURE__*/GardState.Facet.define({
17
+ name: "historyConfig",
16
18
  combine(configs) {
17
19
  return GardState.Facet.combineConfig(configs, {
18
20
  minDepth: 100,
@@ -26,6 +28,7 @@ const historyConfig = /*@__PURE__*/GardState.Facet.define({
26
28
  }
27
29
  });
28
30
  const historyField_ = /*@__PURE__*/GardState.Field.define({
31
+ name: "history",
29
32
  create() {
30
33
  return new HistoryState(null, null);
31
34
  },
@@ -88,8 +91,10 @@ function history(config = {}) {
88
91
  }
89
92
  ;history = /*@__PURE__*/(function (history) {
90
93
  history.field = historyField_;
91
- history.isolate = Transaction.Annotation.define();
92
- history.invertedEffects = GardState.Facet.define();
94
+ history.isolate = Transaction.Annotation.define("historyIsolate");
95
+ history.invertedEffects = GardState.Facet.define({
96
+ name: "invertedEffects"
97
+ });
93
98
  ;return history})(history);
94
99
  const undo = ({ state }) => {
95
100
  let historyState = state.field(historyField_, false);
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * as collab from "wordgard/collab"
2
2
  export * as command from "wordgard/command"
3
3
  export * as doc from "wordgard/doc"
4
4
  export * as editor from "wordgard/editor"
5
- export * as highlight-code from "wordgard/highlight-code"
5
+ export * as highlightCode from "wordgard/highlight-code"
6
6
  export * as history from "wordgard/history"
7
7
  export * as phrases from "wordgard/phrases"
8
8
  export * as schema from "wordgard/schema"
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export * as collab from "wordgard/collab"
2
2
  export * as command from "wordgard/command"
3
3
  export * as doc from "wordgard/doc"
4
4
  export * as editor from "wordgard/editor"
5
- export * as highlight-code from "wordgard/highlight-code"
5
+ export * as highlightCode from "wordgard/highlight-code"
6
6
  export * as history from "wordgard/history"
7
7
  export * as phrases from "wordgard/phrases"
8
8
  export * as schema from "wordgard/schema"
package/dist/phrases.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { GardState } from 'wordgard/state';
2
2
 
3
3
  const phraseOverride = /*@__PURE__*/GardState.Facet.define({
4
+ name: "phraseOverride",
4
5
  combine(records) {
5
6
  let map = new Map();
6
7
  for (let i = records.length - 1; i >= 0; i--) {
package/dist/schema.js CHANGED
@@ -365,6 +365,7 @@ const languageStyles = /*@__PURE__*/Wordgard.styles({
365
365
  }
366
366
  });
367
367
  const languageOptions = /*@__PURE__*/GardState.Facet.define({
368
+ name: "languageOptions",
368
369
  combine: input => {
369
370
  let options = [];
370
371
  for (let arr of input)
@@ -582,7 +583,7 @@ function subscript() {
582
583
  });
583
584
  ;return subscript})(subscript);
584
585
 
585
- const imageUploader = /*@__PURE__*/GardState.Facet.define();
586
+ const imageUploader = /*@__PURE__*/GardState.Facet.define({ name: "imageUploader" });
586
587
  const imageTypes = [Image, Figure, CaptionedFigure];
587
588
  function activeImage(sel) {
588
589
  if (sel.selection instanceof GardSelection.Node && imageTypes.includes(sel.selection.node.type))
@@ -825,6 +826,7 @@ const resizeTheme = /*@__PURE__*/Wordgard.theme({
825
826
  }
826
827
  });
827
828
  const setResizing = /*@__PURE__*/Transaction.Effect.define({
829
+ name: "setImageResize",
828
830
  map: (value, mapping) => {
829
831
  let newPos = mapping.mapPos(value.target, 1, "after");
830
832
  return newPos == null ? undefined : { target: newPos, resizing: value.resizing };
@@ -836,6 +838,7 @@ const handleElt = /*@__PURE__*/(() => Elt.mk("svg:svg", { class: "wg-resize-hand
836
838
  ]))();
837
839
  const resizeWrapper = /*@__PURE__*/(() => Decoration.Point.wrapper(Elt.mk("span", { class: "wg-resize-hover" }, [handleElt, 0]), { target: "img" }))();
838
840
  const resizeState = /*@__PURE__*/GardState.Field.define({
841
+ name: "imageResize",
839
842
  create: () => ({ target: -1, resizing: -1, deco: Decoration.Point.none }),
840
843
  update: (value, tr) => {
841
844
  for (let e of tr.effects) {
@@ -1188,9 +1191,11 @@ class ColorPicker {
1188
1191
  ];
1189
1192
  }
1190
1193
  ColorPicker.width = GardState.Facet.define({
1194
+ name: "colorPickerWidth",
1191
1195
  combine: values => values.length ? values[0] : 10
1192
1196
  });
1193
1197
  ColorPicker.options = GardState.Facet.define({
1198
+ name: "colorPickerOptions",
1194
1199
  combine: values => values.length ? values[0] : defaultColors()
1195
1200
  });
1196
1201
  ColorPicker.theme = Wordgard.styles({
@@ -1329,8 +1334,9 @@ function computeLinkTooltip(state) {
1329
1334
  create: () => renderLinkTooltip(link.value)
1330
1335
  };
1331
1336
  }
1332
- const closeLinkTooltip = /*@__PURE__*/Transaction.Effect.define();
1337
+ const closeLinkTooltip = /*@__PURE__*/Transaction.Effect.define({ name: "closeLinkTooltip" });
1333
1338
  const linkTooltipField = /*@__PURE__*/GardState.Field.define({
1339
+ name: "linkTooltip",
1334
1340
  create: computeLinkTooltip,
1335
1341
  update(value, tr) {
1336
1342
  if (tr.effects.some(e => e.is(closeLinkTooltip)))
@@ -1412,12 +1418,9 @@ function link() {
1412
1418
  })),
1413
1419
  linkTooltipTheme
1414
1420
  ];
1415
- link_1.pasteOver = Wordgard.pasteHandler.of((wg, event) => {
1416
- let { selection } = wg.state, data = event.dataTransfer;
1417
- if (!data || selection.empty)
1418
- return false;
1419
- let text = data.getData("text/plain") || data.getData("Text") || data.getData("text/uri-list");
1420
- if (!text || !/^(https?|mailto|xmpp|data):[^ ]+$/.test(text))
1421
+ link_1.pasteOver = Wordgard.pasteHandler.of((wg, event, slice, html, text) => {
1422
+ let { selection } = wg.state;
1423
+ if (selection.empty || !/^(https?|mailto|xmpp|data):[^ ]+$/.test(text))
1421
1424
  return false;
1422
1425
  let link = Link.of(text);
1423
1426
  let changes = ChangeSet.create(wg.state.doc, { from: selection.from, to: selection.to, add: link });
package/dist/set.d.ts CHANGED
@@ -195,9 +195,10 @@ declare class PointSet<T extends PointSet.Value> implements Set<T> {
195
195
  /**
196
196
  Get the value at the given position, if any. If there's multiple
197
197
  values at that position, the one with the lowest side is
198
- returned.
198
+ returned. If a predicate is given, only points that satisfy it
199
+ are returned.
199
200
  */
200
- at(pos: number): T | undefined;
201
+ at(pos: number, pred?: (value: T) => boolean): T | undefined;
201
202
  /**
202
203
  Adjust the points for a set of document changes. Returns a new
203
204
  set with the adjusted points. May delete points when the content
package/dist/set.js CHANGED
@@ -164,7 +164,11 @@ let SetBuilder$1 = class SetBuilder {
164
164
  addRange(value, from, to) {
165
165
  if (from >= to)
166
166
  throw new Error("Ranges cannot be empty");
167
- (this.lastTo <= from ? this : this.next).addInner(value, from, to);
167
+ for (let target = this;; target = target.next)
168
+ if (target.lastTo <= from) {
169
+ target.addInner(value, from, to);
170
+ break;
171
+ }
168
172
  }
169
173
  addInner(value, from, to) {
170
174
  let chunk;
@@ -246,13 +250,13 @@ class RangeSet extends Set {
246
250
  let replI = 0, posA = 0, posB = 0;
247
251
  let build = new SetBuilder$1();
248
252
  for (let i = 0; i < sections.length;) {
249
- let len = sections[i++], ins = sections[i++];
253
+ let len = sections[i++], ins = sections[i++], endA = posA + len;
250
254
  if (ins < 0) {
251
255
  while (i < sections.length && sections[i + 1] < 0) {
252
256
  len += sections[i];
253
257
  i += 2;
254
258
  }
255
- let upto = i == sections.length ? 1e9 : posA + len, off = posB - posA;
259
+ let upto = i == sections.length ? 1e9 : endA, off = posB - posA;
256
260
  while (cursor.cur) {
257
261
  let chunk = cursor.cur;
258
262
  if (cursor.i == 0 && chunk.end < upto) {
@@ -277,12 +281,12 @@ class RangeSet extends Set {
277
281
  if (repl.add)
278
282
  build.add(repl.add);
279
283
  }
280
- if (len)
281
- cursor.goto(posA + len - 1);
282
- copyMappedUpto$1(cursor, posA + len, map, build, replace, replStartI);
284
+ if (len && cursor.to < endA)
285
+ cursor.goto(endA - 1);
286
+ copyMappedUpto$1(cursor, endA, map, build, replace, replStartI);
283
287
  posB = endB;
284
288
  }
285
- posA += len;
289
+ posA = endA;
286
290
  }
287
291
  return build.finish(this.next && this.next.mapInner(sections, map, replace));
288
292
  }
@@ -556,15 +560,16 @@ class PointSet {
556
560
  cursors.push(set.cursor(from, side));
557
561
  return cursors.length == 0 ? PointSet.empty.cursor() : cursors.length == 1 ? cursors[0] : new HeapCursor(cmpCursor, cursors);
558
562
  }
559
- at(pos) {
563
+ at(pos, pred) {
560
564
  for (let chunk of this.chunks) {
561
565
  if (chunk.start > pos)
562
566
  break;
563
567
  if (chunk.end < pos)
564
568
  continue;
565
- let index = findAbove(chunk.pos, 0, pos - chunk.start - 1);
566
- if (index < chunk.pos.length && chunk.pos[index] + chunk.start == pos)
567
- return chunk.value[index];
569
+ for (let index = findAbove(chunk.pos, 0, pos - chunk.start - 1); index < chunk.pos.length && chunk.pos[index] + chunk.start == pos; index++) {
570
+ if (!pred || pred(chunk.value[index]))
571
+ return chunk.value[index];
572
+ }
568
573
  }
569
574
  return undefined;
570
575
  }
package/dist/state.d.ts CHANGED
@@ -398,6 +398,10 @@ declare class Transaction {
398
398
  */
399
399
  readonly effects: readonly Transaction.Effect<any>[];
400
400
  /**
401
+ The annotations on this transaction.
402
+ */
403
+ readonly annotations: readonly Transaction.Annotation<any>[];
404
+ /**
401
405
  Whether the selection should be scrolled into view after this
402
406
  transaction is dispatched.
403
407
  */
@@ -492,7 +496,7 @@ declare namespace Transaction {
492
496
  scrollIntoView?: boolean;
493
497
  /**
494
498
  Only meaningful for specs that are combined with another
495
- transaction spec (via {@link Transaction.merge or by being
499
+ transaction spec (via {@link Transaction.merge} or by being
496
500
  returned from an {@link Transaction.extender extender}.
497
501
  Normally, when specs are combined, the positions in `changes`
498
502
  are taken to refer to the document positions in the initial
@@ -569,7 +573,7 @@ declare namespace Transaction {
569
573
  /**
570
574
  Define a new type of annotation.
571
575
  */
572
- static define<T>(): Annotation.Type<T>;
576
+ static define<T>(name?: string): Annotation.Type<T>;
573
577
  private _isAnnotation;
574
578
  }
575
579
  namespace Annotation {
@@ -578,13 +582,17 @@ declare namespace Transaction {
578
582
  annotation}.
579
583
  */
580
584
  class Type<T> {
585
+ /**
586
+ This type's debug name.
587
+ */
588
+ readonly name: string | null;
589
+ private constructor();
581
590
  /**
582
591
  Create an instance of this annotation.
583
592
  */
584
593
  of(value: T): Transaction.Annotation<T>;
585
594
  }
586
595
  }
587
- const foo: number;
588
596
  /**
589
597
  Annotation used to store transaction timestamps. Automatically
590
598
  added to every transaction, holding `Date.now()`.
@@ -688,6 +696,11 @@ declare namespace Transaction {
688
696
  */
689
697
  readonly map: (value: any, mapping: ChangeSet) => any | undefined;
690
698
  /**
699
+ The debug name of this effect.
700
+ */
701
+ readonly name: string | null;
702
+ private constructor();
703
+ /**
691
704
  Create an {@link Transaction.Effect effect} instance of this
692
705
  type.
693
706
  */
@@ -697,6 +710,10 @@ declare namespace Transaction {
697
710
  Options passed when defining an effect.
698
711
  */
699
712
  interface Spec<Value> {
713
+ /**
714
+ An optional debug name to assign to this effect.
715
+ */
716
+ name?: string;
700
717
  /**
701
718
  Provides a way to map an effect like this through a position
702
719
  mapping. When not given, the effects will simply not be mapped.
@@ -913,9 +930,9 @@ declare class GardState {
913
930
  isAtom(type: Node.Type): boolean;
914
931
  /**
915
932
  Return the extent of the word around the given position, as a
916
- text selection.
933
+ text selection, or null if there is no word there.
917
934
  */
918
- wordAt(pos: number, bias?: -1 | 1): GardSelection.Text;
935
+ wordAt(pos: number, bias?: -1 | 1): GardSelection.Text | null;
919
936
  /**
920
937
  This effect can be used to reconfigure the root extensions of
921
938
  the editor. Doing this will discard any extensions {@link
@@ -976,6 +993,10 @@ declare namespace GardState {
976
993
  Define a state field.
977
994
  */
978
995
  static define<Value>(config: GardState.Field.Spec<Value>): GardState.Field<Value>;
996
+ /**
997
+ The field's debugging name, if given.
998
+ */
999
+ name: string | null;
979
1000
  private create;
980
1001
  /**
981
1002
  State field instances can be used as {@link
@@ -995,6 +1016,11 @@ declare namespace GardState {
995
1016
  The options passed when defining a state field.
996
1017
  */
997
1018
  type Spec<Value> = {
1019
+ /**
1020
+ An optional name to associate with this field for debugging
1021
+ purposes.
1022
+ */
1023
+ name?: string;
998
1024
  /**
999
1025
  Creates the initial value for the field when a state is created.
1000
1026
  */
@@ -1043,11 +1069,19 @@ declare namespace GardState {
1043
1069
  */
1044
1070
  class Derived<Value> {
1045
1071
  private compareF;
1072
+ /**
1073
+ This field's debugging name, if given.
1074
+ */
1075
+ readonly name: string | null;
1046
1076
  private constructor();
1047
1077
  /**
1048
1078
  Define a derived field.
1049
1079
  */
1050
1080
  static define<Value>(compute: (state: GardState) => Value, spec?: {
1081
+ /**
1082
+ An optional debugging name for this field.
1083
+ */
1084
+ name?: string;
1051
1085
  /**
1052
1086
  Optional function used to compare the value of the field,
1053
1087
  to prevent propagating a change when a recomputed result
@@ -1088,6 +1122,10 @@ declare namespace GardState {
1088
1122
  */
1089
1123
  readonly isStatic: boolean;
1090
1124
  /**
1125
+ The facet's debug name.
1126
+ */
1127
+ readonly name: string | null;
1128
+ /**
1091
1129
  The output of the facet when it has no inputs.
1092
1130
  */
1093
1131
  readonly default: Output;
@@ -1132,7 +1170,6 @@ declare namespace GardState {
1132
1170
  */
1133
1171
  from<T extends Input>(field: GardState.Field<T> | GardState.Field.Derived<T>): GardState.Extension;
1134
1172
  from<T>(field: GardState.Field<T> | GardState.Field.Derived<T>, get: (value: T) => Input): GardState.Extension;
1135
- tag: Output;
1136
1173
  }
1137
1174
  namespace Facet {
1138
1175
  /**
@@ -1140,6 +1177,10 @@ declare namespace GardState {
1140
1177
  facet.
1141
1178
  */
1142
1179
  type Spec<Input, Output> = {
1180
+ /**
1181
+ And optional name, to recognize the facet when debugging.
1182
+ */
1183
+ name?: string;
1143
1184
  /**
1144
1185
  How to combine the input values into a single output value. When
1145
1186
  not given, the array of input values becomes the output. This
@@ -1286,11 +1327,15 @@ declare namespace GardState {
1286
1327
  transaction.
1287
1328
  */
1288
1329
  class Compartment {
1330
+ /**
1331
+ The compartment's debugging name, if given.
1332
+ */
1333
+ readonly name: string | null;
1289
1334
  private constructor();
1290
1335
  /**
1291
1336
  Define a new compartment.
1292
1337
  */
1293
- static define(): Compartment;
1338
+ static define(name?: string): Compartment;
1294
1339
  /**
1295
1340
  Create an instance of this compartment to add to your {@link
1296
1341
  GardState.Spec.config state configuration}.