@nerd-bible/wordgard 0.6.2-beta7 → 0.6.2-beta9

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/collab.js CHANGED
@@ -37,6 +37,7 @@ class CollabState {
37
37
  }
38
38
  }
39
39
  const collabConfig = /*@__PURE__*/GardState.Facet.define({
40
+ name: "collabConfig",
40
41
  combine(configs) {
41
42
  let combined = GardState.Facet.combineConfig(configs, {
42
43
  startVersion: 0,
@@ -52,12 +53,14 @@ const collabConfig = /*@__PURE__*/GardState.Facet.define({
52
53
  }
53
54
  });
54
55
  const collabReceive = /*@__PURE__*/Transaction.Effect.define({
56
+ name: "collabReceive",
55
57
  map(state, changes) {
56
58
  return changes.empty ? state
57
59
  : new CollabState(state.version, state.syncedDoc, state.nextUpdate, addUpdate(state.openUpdate, changes));
58
60
  }
59
61
  });
60
62
  const collabField = /*@__PURE__*/GardState.Field.define({
63
+ name: "collab",
61
64
  create(state) {
62
65
  return new CollabState(state.facet(collabConfig).startVersion, state.doc, null, null);
63
66
  },
package/dist/command.js CHANGED
@@ -5,6 +5,7 @@ import { findClusterBreak } from '@marijn/find-cluster-break';
5
5
  import { Alignment, Direction, Emphasis, Strong, Underline } from 'wordgard/types';
6
6
 
7
7
  const commandHandler = /*@__PURE__*/GardState.Facet.define({
8
+ name: "commandHandler",
8
9
  combine(handlers) {
9
10
  let map = new Map();
10
11
  for (let [cmd, handler] of handlers) {
@@ -834,8 +835,9 @@ const deleteToLineEnd = (wg, dir) => {
834
835
  userEvent: "delete." + dir
835
836
  };
836
837
  };
837
- const addToKillBuffer = /*@__PURE__*/Transaction.Effect.define();
838
+ const addToKillBuffer = /*@__PURE__*/Transaction.Effect.define({ name: "addToKillBuffer" });
838
839
  const killBuffer = /*@__PURE__*/GardState.Field.define({
840
+ name: "killBuffer",
839
841
  create() { return { content: [], active: false }; },
840
842
  update(value, tr) {
841
843
  let add = tr.effects.find(e => e.is(addToKillBuffer));
@@ -1318,9 +1320,10 @@ const Menu = /*@__PURE__*/(function (Menu) {
1318
1320
  let src = Menu.Item.source.of(this);
1319
1321
  this.extension = this.parent ? [src, this.parent] : src;
1320
1322
  }
1323
+ toString() { return "Menu.Item"; }
1321
1324
  }
1322
1325
  Item.Base = Base;
1323
- Item.source = GardState.Facet.define();
1326
+ Item.source = GardState.Facet.define({ name: "menuItem" });
1324
1327
  })(Item = Menu.Item || (Menu.Item = {}));
1325
1328
  class Button extends Item.Base {
1326
1329
  spec;
@@ -1395,6 +1398,7 @@ const Menu = /*@__PURE__*/(function (Menu) {
1395
1398
  template(...content) {
1396
1399
  return Template.new(this, content.length ? content : ["..."]);
1397
1400
  }
1401
+ toString() { return "Menu.Group"; }
1398
1402
  }
1399
1403
  Menu.Group = Group;
1400
1404
  (function (Group) {
package/dist/doc.d.ts CHANGED
@@ -1310,12 +1310,19 @@ declare namespace Node {
1310
1310
  implies membership of its parent groups.
1311
1311
  */
1312
1312
  readonly parent: Group | undefined;
1313
+ /**
1314
+ This group's debug name.
1315
+ */
1316
+ readonly name: string | null;
1313
1317
  private tag;
1314
1318
  private constructor();
1315
1319
  /**
1316
1320
  Define a custom node group.
1317
1321
  */
1318
- static define(parent?: Group): Group;
1322
+ static define(spec?: {
1323
+ parent?: Group;
1324
+ name?: string;
1325
+ }): Group;
1319
1326
  /**
1320
1327
  A group that contains every node type.
1321
1328
  */
@@ -1374,11 +1381,15 @@ declare namespace Node {
1374
1381
  whether a given node has the role attached.
1375
1382
  */
1376
1383
  class Role {
1384
+ /**
1385
+ This role's name.
1386
+ */
1387
+ readonly name: string | null;
1377
1388
  private constructor();
1378
1389
  /**
1379
1390
  Define a new role.
1380
1391
  */
1381
- static define(): Role;
1392
+ static define(name?: string): Role;
1382
1393
  /**
1383
1394
  This role indicates that a plot contains code, and makes some
1384
1395
  commands behave differently inside such a plot.
package/dist/doc.js CHANGED
@@ -867,8 +867,8 @@ class Pos {
867
867
  let d = this.depth;
868
868
  if (depth > d)
869
869
  throw new RangeError("Asking for parent deeper than position depth");
870
- for (let d = this.depth, p = this.parent;; p = p.parent)
871
- if (d == depth)
870
+ for (let p = this.parent;; p = p.parent)
871
+ if (d-- == depth)
872
872
  return p;
873
873
  }
874
874
  isAtStart(parent) {
@@ -1093,6 +1093,7 @@ class BaseType {
1093
1093
  get isBlock() { return (this.flags & 1) == 0; }
1094
1094
  get isAtom() { return (this.flags & 4) > 0; }
1095
1095
  get isSelectable() { return (this.flags & 32) > 0; }
1096
+ toString() { return this.name; }
1096
1097
  }
1097
1098
  class BaseTag {
1098
1099
  param;
@@ -1131,29 +1132,48 @@ const Node = /*@__PURE__*/(function (Node) {
1131
1132
  })(Node.Type || (Node.Type = {}));
1132
1133
  class Group {
1133
1134
  parent;
1135
+ name;
1134
1136
  constructor(
1135
- parent) {
1137
+ parent,
1138
+ name) {
1136
1139
  this.parent = parent;
1140
+ this.name = name;
1137
1141
  }
1138
- static define(parent) { return new Group(parent); }
1139
- static All = Group.define();
1140
- static Inline = Group.define();
1141
- static Block = Group.define();
1142
- static Leaf = Group.define();
1143
- static Plot = Group.define();
1144
- static Textblock = Group.define();
1145
- static Content = Group.define();
1146
- static TableCell = Group.define();
1147
- static ListItem = Group.define();
1142
+ static define(spec = {}) {
1143
+ return new Group(spec.parent, spec.name || null);
1144
+ }
1145
+ static All = Group.define({ name: "All" });
1146
+ static Inline = Group.define({ name: "Inline" });
1147
+ static Block = Group.define({ name: "Block" });
1148
+ static Leaf = Group.define({ name: "Leaf" });
1149
+ static Plot = Group.define({ name: "Plot" });
1150
+ static Textblock = Group.define({ name: "Textblock" });
1151
+ static Content = Group.define({ name: "Content" });
1152
+ static TableCell = Group.define({ name: "TableCell" });
1153
+ static ListItem = Group.define({ name: "ListItem" });
1148
1154
  static builtin = [Group.All, Group.Inline, Group.Block, Group.Leaf, Group.Plot, Group.Textblock];
1155
+ toString() { return "Node.Group" + (this.name ? ":" + this.name : ""); }
1149
1156
  }
1150
1157
  Node.Group = Group;
1158
+ function queryToString(q) {
1159
+ if ("and" in q)
1160
+ return `and(${q.and.map(queryToString)})`;
1161
+ if (Array.isArray(q))
1162
+ return `or(q.map(queryToString))`;
1163
+ return String(q);
1164
+ }
1165
+ Node.queryToString = queryToString;
1151
1166
  class Role {
1152
- constructor() { }
1153
- static define() { return new Role; }
1154
- static Code = Role.define();
1155
- static List = Role.define();
1156
- static LineBreak = Role.define();
1167
+ name;
1168
+ constructor(
1169
+ name) {
1170
+ this.name = name;
1171
+ }
1172
+ static define(name) { return new Role(name || null); }
1173
+ static Code = Role.define("Code");
1174
+ static List = Role.define("List");
1175
+ static LineBreak = Role.define("LineBreak");
1176
+ toString() { return "Node.Role" + (this.name ? ":" + this.name : ""); }
1157
1177
  }
1158
1178
  Node.Role = Role;
1159
1179
  ;return Node})({});
@@ -1392,6 +1412,8 @@ class Plot {
1392
1412
  constructor(type, param, marks) {
1393
1413
  super(param, marks);
1394
1414
  this.type = type;
1415
+ if (this.type.isDoc && marks.length)
1416
+ throw new Error("Document nodes cannot have marks");
1395
1417
  }
1396
1418
  static new(type, param, marks) {
1397
1419
  return new Tag(type, param, marks);
package/dist/editor.d.ts CHANGED
@@ -8,6 +8,7 @@ import { PointSet, Set, RangeSet } from 'wordgard/set';
8
8
 
9
9
  type MakeSelectionStyle = (wg: Wordgard, event: MouseEvent) => Wordgard.MouseSelectionStyle | null;
10
10
 
11
+ import Mark_ = Mark;
11
12
  /**
12
13
  A widget describes a piece of DOM content that can be used to
13
14
  render a node, a part of a node, or an extra element added via a
@@ -193,8 +194,8 @@ declare namespace Decoration {
193
194
  /**
194
195
  Override the shape used for a given mark inside the editor.
195
196
  */
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;
197
+ function shape<V>(type: Mark_.Type<V>, shape: Shape.Element<V> | Shape.Attribute<V> | Shape.Attributes<V>): GardState.Extension;
198
+ function shape(mark: Mark_<null>, shape: Shape.Element<null> | Shape.Attribute<null> | Shape.Attributes<null>): GardState.Extension;
198
199
  }
199
200
  /**
200
201
  A point decoration is a decoration that targets a given position
@@ -730,7 +731,13 @@ declare class Wordgard {
730
731
  Facet that allows you to register handlers to override paste
731
732
  behavior.
732
733
  */
733
- static pasteHandler: GardState.Facet<(wg: Wordgard, event: InputEvent, slice: wordgard_doc.Slice) => boolean, readonly ((wg: Wordgard, event: InputEvent, slice: wordgard_doc.Slice) => boolean)[]>;
734
+ static pasteHandler: GardState.Facet<(wg: Wordgard, event: InputEvent | null, slice: wordgard_doc.Slice, html: string, text: string) => boolean, readonly ((wg: Wordgard, event: InputEvent | null, slice: wordgard_doc.Slice, html: string, text: string) => boolean)[]>;
735
+ /**
736
+ Perform a paste with the given content. This will run {@link
737
+ Wordgard.pasteHandler paste handlers} and, if none handles the
738
+ paste, fall back to the default handling.
739
+ */
740
+ paste(html: string, text?: string): void;
734
741
  /**
735
742
  Facet for custom drop handlers. When the drop is done inside the
736
743
  editor and should move an existing range, the `move` parameter
@@ -856,7 +863,7 @@ declare class Wordgard {
856
863
  the editor's {@link Wordgard.dom wrapper element} (to which the
857
864
  scope class will be added) need to be explicitly differentiated
858
865
  by adding an `&` to the selector for that element—for example
859
- `&:has(wg-content:focus)`.
866
+ `&.wg-focused`.
860
867
  */
861
868
  static theme(spec: Record<string, StyleSpec>): GardState.Extension;
862
869
  /**
@@ -925,6 +932,11 @@ declare class Wordgard {
925
932
  part of the editor (for example a gutter).
926
933
  */
927
934
  static coveredMargins: GardState.Facet<(wg: Wordgard) => Partial<DOMRect> | null, readonly ((wg: Wordgard) => Partial<DOMRect> | null)[]>;
935
+ /**
936
+ Given a DOM element that may be a Wordgard editor, retrieve its
937
+ editor instance.
938
+ */
939
+ static findFromDOM(elt: Element): Wordgard | null;
928
940
  }
929
941
  declare namespace Wordgard {
930
942
  /**