@nerd-bible/wordgard 0.3.6 → 0.5.2-beta2

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
@@ -3,7 +3,15 @@ import { ChangeSet } from 'wordgard/doc';
3
3
  import { Command, undo as undo$1, redo as redo$1, Menu } from 'wordgard/command';
4
4
  import { phrases } from 'wordgard/phrases';
5
5
 
6
- const fromHistory = /*@__PURE__*/Transaction.Annotation.define();
6
+ const fromHistory = /*@__PURE__*/Transaction.Effect.define({
7
+ map(value, change) {
8
+ return {
9
+ side: value.side,
10
+ startDoc: change.apply(value.startDoc),
11
+ rest: !value.rest ? null : value.rest.addMapping(change, value.startDoc)
12
+ };
13
+ }
14
+ });
7
15
  const historyConfig = /*@__PURE__*/GardState.Facet.define({
8
16
  combine(configs) {
9
17
  return GardState.Facet.combineConfig(configs, {
@@ -23,13 +31,13 @@ const historyField_ = /*@__PURE__*/GardState.Field.define({
23
31
  },
24
32
  update(state, tr) {
25
33
  let config = tr.state.facet(historyConfig);
26
- let fromHist = tr.annotation(fromHistory);
34
+ let fromHist = tr.effects.find(e => e.is(fromHistory));
27
35
  if (fromHist) {
28
- let from = fromHist.side, event = eventFromTransaction(tr);
29
- let other = from == 0 ? state.undone : state.done;
36
+ let { side, rest } = fromHist.value, event = eventFromTransaction(tr);
37
+ let other = side == 0 ? state.undone : state.done;
30
38
  if (event)
31
39
  other = new Branch(event.changes, event.effects, null, tr.startState.selection, other);
32
- return new HistoryState(from == 0 ? fromHist.rest : other, from == 0 ? other : fromHist.rest);
40
+ return new HistoryState(side == 0 ? rest : other, side == 0 ? other : rest);
33
41
  }
34
42
  let isolate = tr.annotation(history.isolate);
35
43
  if (isolate == true || isolate == "before")
@@ -239,8 +247,7 @@ class HistoryState {
239
247
  return {
240
248
  changes: branch.changes,
241
249
  selection: branch.startSelection,
242
- effects: branch.effects,
243
- annotations: fromHistory.of({ side, rest: branch.next }),
250
+ effects: branch.effects.concat(fromHistory.of({ side, startDoc: branch.changes.apply(state.doc), rest: branch.next })),
244
251
  userEvent: side == 0 ? "undo" : "redo",
245
252
  scrollIntoView: true
246
253
  };
package/dist/schema.js CHANGED
@@ -1290,7 +1290,7 @@ function computeLinkTooltip(state) {
1290
1290
  if (!state.selection.isCursor)
1291
1291
  return null;
1292
1292
  let { head } = state.sel, before = head.nodeBefore, link = before && Link.isInSet(before.marks);
1293
- if (!link)
1293
+ if (!link || head.matchingParent(plot => state.isAtom(plot.type)))
1294
1294
  return null;
1295
1295
  let start = head.pos - before.length, end = head.pos, siblings = head.parent.node.content;
1296
1296
  for (let index = head.index - 1; index > 0 && link.isInSet(siblings[index - 1].marks);)
package/dist/state.d.ts CHANGED
@@ -151,9 +151,7 @@ declare abstract class GardSelection {
151
151
  Find the next normal cursor position after or before this selection's
152
152
  head. Normal cursor positions are:
153
153
 
154
- - Any inline position, except one directly inside of an inline
155
- plot that doesn't have {@link Plot.Spec.cursorInsideBounds
156
- `cursorInsideBounds`} set.
154
+ - Any inline position.
157
155
 
158
156
  - Positions between two cursor barriers, if not already an
159
157
  inline position. Cursor barriers are the sides of the
package/dist/state.js CHANGED
@@ -384,19 +384,11 @@ class TextblockMap {
384
384
  sectionPos = pos + ch.length;
385
385
  }
386
386
  }
387
- else if (ch.type.cursorInsideBounds) {
387
+ else {
388
388
  text += " ";
389
389
  scan(ch, pos + 1);
390
390
  text += " ";
391
391
  }
392
- else {
393
- flush(pos);
394
- sections.push((1 << 2) | 3);
395
- scan(ch, sectionPos = pos + 1);
396
- flush(pos + ch.length - 1);
397
- sections.push((1 << 2) | 2);
398
- sectionPos = pos + ch.length;
399
- }
400
392
  pos += ch.length;
401
393
  }
402
394
  };
@@ -759,11 +751,11 @@ function cursorAtStart(cx, block) {
759
751
  }
760
752
  function isBarrier(cx, node) {
761
753
  if (node.isLeaf)
762
- return node.type.isBlock;
754
+ return node.isBlock;
763
755
  let override = node.type.spec.cursorBarrier;
764
756
  if (override != null)
765
757
  return override;
766
- return node.type.isBlock && (node.type.isolating || node.type.preserveWhitespace || cx.config.isAtom(node.type));
758
+ return node.isBlock && (node.type.isolating || node.type.preserveWhitespace || cx.config.isAtom(node.type));
767
759
  }
768
760
  function scanNormalFrom(cx, from, side, forward) {
769
761
  let pos = cx.doc.resolve(from), pastBarrier = false;
@@ -852,26 +844,24 @@ function findNormalAt(cx, pos, bias) {
852
844
  for (let pass = 0; pass < 2; pass++) {
853
845
  let dir = !pass ? bias : -bias, { parent, index } = res, curPos = pos;
854
846
  for (;;) {
855
- if (parent.node.inlineContent &&
856
- (parent.node.type.isBlock || curPos > parent.start && curPos < parent.end || parent.node.type.cursorInsideBounds))
847
+ if (parent.node.inlineContent)
857
848
  return { pos: curPos, side: bias };
858
849
  if (index == (dir > 0 ? parent.node.content.length : 0)) {
859
- if ((parent.node.type.isInline ? parent.node.type.cursorInsideBounds : isBarrier(cx, parent.node)) ||
860
- !parent.parent)
850
+ if (isBarrier(cx, parent.node) || !parent.parent)
861
851
  break;
862
852
  lowest = curPos = curPos + dir;
863
853
  index = parent.index + (dir > 0 ? 1 : 0);
864
854
  parent = parent.parent;
865
855
  }
866
856
  else {
867
- let next = parent.node.content[index + (dir > 0 ? 0 : -1)];
857
+ let nextIndex = index + (dir > 0 ? 0 : -1), next = parent.node.content[nextIndex];
868
858
  if (next.isLeaf || isBarrier(cx, next))
869
859
  break;
870
860
  if (!parent.node.inlineContent && next.inlineContent && cx.config.visualCursorMotion) {
871
861
  let startPos = curPos - (dir > 0 ? 0 : next.length) + 1;
872
862
  return TextblockMap.get(cx, startPos, next).visualSide(dir > 0);
873
863
  }
874
- parent = Pos.Plot.create(parent, next, curPos, index);
864
+ parent = Pos.Plot.create(parent, next, curPos, nextIndex);
875
865
  index = dir > 0 ? 0 : next.content.length;
876
866
  curPos += dir;
877
867
  }
package/dist/table.js CHANGED
@@ -205,10 +205,11 @@ function computeMap(table) {
205
205
  }
206
206
  pos++;
207
207
  }
208
- for (let row = 0, i = width; row < height; row++, i += width) {
208
+ for (let row = 0, i = 0; row < height; row++) {
209
209
  let missing = 0;
210
- while (missing < width && map[i - missing - 1] == 0)
211
- missing++;
210
+ for (let col = 0; col < width; col++)
211
+ if (map[i++] == 0)
212
+ missing++;
212
213
  if (missing)
213
214
  (problems || (problems = [])).push({ type: "missing", row, n: missing });
214
215
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { Mark, Plot, Leaf } from 'wordgard/doc';
2
2
 
3
+ /**
4
+ A hard line break. Renders as `<br>` and has the {@link
5
+ Node.Role.LineBreak | `LineBreak`} role.
6
+ */
7
+ declare const LineBreak: Leaf<null>;
3
8
  /**
4
9
  A paragraph. Part of the {@link Node.Group.Content | `Content`}
5
10
  group, allowing inline content, rendered as `<p>`.
@@ -58,11 +63,6 @@ A horizontal separator. Part of the {@link Node.Group.Content |
58
63
  */
59
64
  declare const HorizontalRule: Leaf<null>;
60
65
  /**
61
- A hard line break. Renders as `<br>` and has the {@link
62
- Node.Role.LineBreak | `LineBreak`} role.
63
- */
64
- declare const LineBreak: Leaf<null>;
65
- /**
66
66
  Table cell plot. Allows inline content, and is in the {@link
67
67
  Node.Group.TableCell | `TableCell`} group. Rendered as `<td>`
68
68
  */
package/dist/types.js CHANGED
@@ -1,6 +1,12 @@
1
- import { Node, Plot, Elt, ValidationError, Mark, Leaf, parse } from 'wordgard/doc';
1
+ import { Node, Leaf, Plot, Elt, ValidationError, Mark, parse } from 'wordgard/doc';
2
2
 
3
3
  const G = /*@__PURE__*/(() => Node.Group)();
4
+ const LineBreak = /*@__PURE__*/(() => Leaf.define("LineBreak", {
5
+ inline: true,
6
+ role: Node.Role.LineBreak,
7
+ toText: () => "\n",
8
+ shape: { element: "br" }
9
+ }))();
4
10
  const Paragraph = /*@__PURE__*/(() => Plot.define("Paragraph", {
5
11
  inlineContent: true,
6
12
  group: G.Content,
@@ -27,7 +33,7 @@ const Heading = /*@__PURE__*/(() => Plot.Type.define("Heading", {
27
33
  ]
28
34
  }))();
29
35
  const CodeBlock = /*@__PURE__*/(() => Plot.define("CodeBlock", {
30
- inlineContent: true,
36
+ inlineContent: [Leaf.Text, LineBreak],
31
37
  group: G.Content,
32
38
  role: Node.Role.Code,
33
39
  shape: { element: "pre" },
@@ -81,12 +87,6 @@ const HorizontalRule = /*@__PURE__*/(() => Leaf.define("HorizontalRule", {
81
87
  toText: () => "---",
82
88
  selectable: true
83
89
  }))();
84
- const LineBreak = /*@__PURE__*/(() => Leaf.define("LineBreak", {
85
- inline: true,
86
- role: Node.Role.LineBreak,
87
- toText: () => "\n",
88
- shape: { element: "br" }
89
- }))();
90
90
  const Cell = /*@__PURE__*/(() => Plot.define("Cell", {
91
91
  inlineContent: true,
92
92
  group: G.TableCell,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nerd-bible/wordgard",
3
- "version": "0.3.6",
3
+ "version": "0.5.2-beta2",
4
4
  "description": "Semantic rich text editor system",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",