@scalar/use-codemirror 0.5.4 → 0.6.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AA4DlD,KAAK,QAAQ,GACT,OAAO,GACP,GAAG,GACH,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,MAAM,GACN,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,GAAG,GACH,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0LT,wBAAkD"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AA6DlD,KAAK,QAAQ,GACT,OAAO,GACP,GAAG,GACH,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,MAAM,GACN,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,GAAG,GACH,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LT,wBAAkD"}
package/dist/index.js CHANGED
@@ -6311,7 +6311,9 @@ const swift = {
6311
6311
  const DefaultBufferLength = 1024;
6312
6312
  let nextPropID = 0;
6313
6313
  class NodeProp {
6314
- /// Create a new node prop type.
6314
+ /**
6315
+ Create a new node prop type.
6316
+ */
6315
6317
  constructor(config = {}) {
6316
6318
  this.id = nextPropID++;
6317
6319
  this.perNode = !!config.perNode;
@@ -6319,13 +6321,15 @@ class NodeProp {
6319
6321
  throw new Error("This node type doesn't define a deserialize function");
6320
6322
  });
6321
6323
  }
6322
- /// This is meant to be used with
6323
- /// [`NodeSet.extend`](#common.NodeSet.extend) or
6324
- /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
6325
- /// prop values for each node type in the set. Takes a [match
6326
- /// object](#common.NodeType^match) or function that returns undefined
6327
- /// if the node type doesn't get this prop, and the prop's value if
6328
- /// it does.
6324
+ /**
6325
+ This is meant to be used with
6326
+ [`NodeSet.extend`](#common.NodeSet.extend) or
6327
+ [`LRParser.configure`](#lr.ParserConfig.props) to compute
6328
+ prop values for each node type in the set. Takes a [match
6329
+ object](#common.NodeType^match) or function that returns undefined
6330
+ if the node type doesn't get this prop, and the prop's value if
6331
+ it does.
6332
+ */
6329
6333
  add(match) {
6330
6334
  if (this.perNode)
6331
6335
  throw new RangeError("Can't add per-node props to node types");
@@ -6343,16 +6347,33 @@ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
6343
6347
  NodeProp.contextHash = new NodeProp({ perNode: true });
6344
6348
  NodeProp.lookAhead = new NodeProp({ perNode: true });
6345
6349
  NodeProp.mounted = new NodeProp({ perNode: true });
6350
+ class MountedTree {
6351
+ constructor(tree, overlay, parser) {
6352
+ this.tree = tree;
6353
+ this.overlay = overlay;
6354
+ this.parser = parser;
6355
+ }
6356
+ /**
6357
+ @internal
6358
+ */
6359
+ static get(tree) {
6360
+ return tree && tree.props && tree.props[NodeProp.mounted.id];
6361
+ }
6362
+ }
6346
6363
  const noProps = /* @__PURE__ */ Object.create(null);
6347
6364
  class NodeType {
6348
- /// @internal
6365
+ /**
6366
+ @internal
6367
+ */
6349
6368
  constructor(name2, props, id, flags = 0) {
6350
6369
  this.name = name2;
6351
6370
  this.props = props;
6352
6371
  this.id = id;
6353
6372
  this.flags = flags;
6354
6373
  }
6355
- /// Define a node type.
6374
+ /**
6375
+ Define a node type.
6376
+ */
6356
6377
  static define(spec) {
6357
6378
  let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
6358
6379
  let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
@@ -6369,30 +6390,42 @@ class NodeType {
6369
6390
  }
6370
6391
  return type;
6371
6392
  }
6372
- /// Retrieves a node prop for this type. Will return `undefined` if
6373
- /// the prop isn't present on this node.
6393
+ /**
6394
+ Retrieves a node prop for this type. Will return `undefined` if
6395
+ the prop isn't present on this node.
6396
+ */
6374
6397
  prop(prop) {
6375
6398
  return this.props[prop.id];
6376
6399
  }
6377
- /// True when this is the top node of a grammar.
6400
+ /**
6401
+ True when this is the top node of a grammar.
6402
+ */
6378
6403
  get isTop() {
6379
6404
  return (this.flags & 1) > 0;
6380
6405
  }
6381
- /// True when this node is produced by a skip rule.
6406
+ /**
6407
+ True when this node is produced by a skip rule.
6408
+ */
6382
6409
  get isSkipped() {
6383
6410
  return (this.flags & 2) > 0;
6384
6411
  }
6385
- /// Indicates whether this is an error node.
6412
+ /**
6413
+ Indicates whether this is an error node.
6414
+ */
6386
6415
  get isError() {
6387
6416
  return (this.flags & 4) > 0;
6388
6417
  }
6389
- /// When true, this node type doesn't correspond to a user-declared
6390
- /// named node, for example because it is used to cache repetition.
6418
+ /**
6419
+ When true, this node type doesn't correspond to a user-declared
6420
+ named node, for example because it is used to cache repetition.
6421
+ */
6391
6422
  get isAnonymous() {
6392
6423
  return (this.flags & 8) > 0;
6393
6424
  }
6394
- /// Returns true when this node's name or one of its
6395
- /// [groups](#common.NodeProp^group) matches the given string.
6425
+ /**
6426
+ Returns true when this node's name or one of its
6427
+ [groups](#common.NodeProp^group) matches the given string.
6428
+ */
6396
6429
  is(name2) {
6397
6430
  if (typeof name2 == "string") {
6398
6431
  if (this.name == name2)
@@ -6402,12 +6435,14 @@ class NodeType {
6402
6435
  }
6403
6436
  return this.id == name2;
6404
6437
  }
6405
- /// Create a function from node types to arbitrary values by
6406
- /// specifying an object whose property names are node or
6407
- /// [group](#common.NodeProp^group) names. Often useful with
6408
- /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
6409
- /// names, separated by spaces, in a single property name to map
6410
- /// multiple node names to a single value.
6438
+ /**
6439
+ Create a function from node types to arbitrary values by
6440
+ specifying an object whose property names are node or
6441
+ [group](#common.NodeProp^group) names. Often useful with
6442
+ [`NodeProp.add`](#common.NodeProp.add). You can put multiple
6443
+ names, separated by spaces, in a single property name to map
6444
+ multiple node names to a single value.
6445
+ */
6411
6446
  static match(map2) {
6412
6447
  let direct = /* @__PURE__ */ Object.create(null);
6413
6448
  for (let prop in map2)
@@ -6438,7 +6473,9 @@ var IterMode;
6438
6473
  IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
6439
6474
  })(IterMode || (IterMode = {}));
6440
6475
  class Tree {
6441
- /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
6476
+ /**
6477
+ Construct a new tree. See also [`Tree.build`](#common.Tree^build).
6478
+ */
6442
6479
  constructor(type, children, positions, length, props) {
6443
6480
  this.type = type;
6444
6481
  this.children = children;
@@ -6451,9 +6488,11 @@ class Tree {
6451
6488
  this.props[typeof prop == "number" ? prop : prop.id] = value;
6452
6489
  }
6453
6490
  }
6454
- /// @internal
6491
+ /**
6492
+ @internal
6493
+ */
6455
6494
  toString() {
6456
- let mounted = this.prop(NodeProp.mounted);
6495
+ let mounted = MountedTree.get(this);
6457
6496
  if (mounted && !mounted.overlay)
6458
6497
  return mounted.tree.toString();
6459
6498
  let children = "";
@@ -6467,15 +6506,19 @@ class Tree {
6467
6506
  }
6468
6507
  return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
6469
6508
  }
6470
- /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
6471
- /// the tree. Mode can be used to [control](#common.IterMode) which
6472
- /// nodes the cursor visits.
6509
+ /**
6510
+ Get a [tree cursor](#common.TreeCursor) positioned at the top of
6511
+ the tree. Mode can be used to [control](#common.IterMode) which
6512
+ nodes the cursor visits.
6513
+ */
6473
6514
  cursor(mode = 0) {
6474
6515
  return new TreeCursor(this.topNode, mode);
6475
6516
  }
6476
- /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
6477
- /// at the given position and side (see
6478
- /// [`moveTo`](#common.TreeCursor.moveTo).
6517
+ /**
6518
+ Get a [tree cursor](#common.TreeCursor) pointing into this tree
6519
+ at the given position and side (see
6520
+ [`moveTo`](#common.TreeCursor.moveTo).
6521
+ */
6479
6522
  cursorAt(pos, side = 0, mode = 0) {
6480
6523
  let scope = CachedNode.get(this) || this.topNode;
6481
6524
  let cursor = new TreeCursor(scope);
@@ -6483,40 +6526,58 @@ class Tree {
6483
6526
  CachedNode.set(this, cursor._tree);
6484
6527
  return cursor;
6485
6528
  }
6486
- /// Get a [syntax node](#common.SyntaxNode) object for the top of the
6487
- /// tree.
6529
+ /**
6530
+ Get a [syntax node](#common.SyntaxNode) object for the top of the
6531
+ tree.
6532
+ */
6488
6533
  get topNode() {
6489
6534
  return new TreeNode(this, 0, 0, null);
6490
6535
  }
6491
- /// Get the [syntax node](#common.SyntaxNode) at the given position.
6492
- /// If `side` is -1, this will move into nodes that end at the
6493
- /// position. If 1, it'll move into nodes that start at the
6494
- /// position. With 0, it'll only enter nodes that cover the position
6495
- /// from both sides.
6496
- ///
6497
- /// Note that this will not enter
6498
- /// [overlays](#common.MountedTree.overlay), and you often want
6499
- /// [`resolveInner`](#common.Tree.resolveInner) instead.
6536
+ /**
6537
+ Get the [syntax node](#common.SyntaxNode) at the given position.
6538
+ If `side` is -1, this will move into nodes that end at the
6539
+ position. If 1, it'll move into nodes that start at the
6540
+ position. With 0, it'll only enter nodes that cover the position
6541
+ from both sides.
6542
+
6543
+ Note that this will not enter
6544
+ [overlays](#common.MountedTree.overlay), and you often want
6545
+ [`resolveInner`](#common.Tree.resolveInner) instead.
6546
+ */
6500
6547
  resolve(pos, side = 0) {
6501
6548
  let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
6502
6549
  CachedNode.set(this, node);
6503
6550
  return node;
6504
6551
  }
6505
- /// Like [`resolve`](#common.Tree.resolve), but will enter
6506
- /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
6507
- /// pointing into the innermost overlaid tree at the given position
6508
- /// (with parent links going through all parent structure, including
6509
- /// the host trees).
6552
+ /**
6553
+ Like [`resolve`](#common.Tree.resolve), but will enter
6554
+ [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
6555
+ pointing into the innermost overlaid tree at the given position
6556
+ (with parent links going through all parent structure, including
6557
+ the host trees).
6558
+ */
6510
6559
  resolveInner(pos, side = 0) {
6511
6560
  let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
6512
6561
  CachedInnerNode.set(this, node);
6513
6562
  return node;
6514
6563
  }
6515
- /// Iterate over the tree and its children, calling `enter` for any
6516
- /// node that touches the `from`/`to` region (if given) before
6517
- /// running over such a node's children, and `leave` (if given) when
6518
- /// leaving the node. When `enter` returns `false`, that node will
6519
- /// not have its children iterated over (or `leave` called).
6564
+ /**
6565
+ In some situations, it can be useful to iterate through all
6566
+ nodes around a position, including those in overlays that don't
6567
+ directly cover the position. This method gives you an iterator
6568
+ that will produce all nodes, from small to big, around the given
6569
+ position.
6570
+ */
6571
+ resolveStack(pos, side = 0) {
6572
+ return stackIterator(this, pos, side);
6573
+ }
6574
+ /**
6575
+ Iterate over the tree and its children, calling `enter` for any
6576
+ node that touches the `from`/`to` region (if given) before
6577
+ running over such a node's children, and `leave` (if given) when
6578
+ leaving the node. When `enter` returns `false`, that node will
6579
+ not have its children iterated over (or `leave` called).
6580
+ */
6520
6581
  iterate(spec) {
6521
6582
  let { enter, leave, from = 0, to = this.length } = spec;
6522
6583
  let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
@@ -6538,14 +6599,18 @@ class Tree {
6538
6599
  }
6539
6600
  }
6540
6601
  }
6541
- /// Get the value of the given [node prop](#common.NodeProp) for this
6542
- /// node. Works with both per-node and per-type props.
6602
+ /**
6603
+ Get the value of the given [node prop](#common.NodeProp) for this
6604
+ node. Works with both per-node and per-type props.
6605
+ */
6543
6606
  prop(prop) {
6544
6607
  return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
6545
6608
  }
6546
- /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
6547
- /// format that can be passed to the [`Tree`](#common.Tree)
6548
- /// constructor.
6609
+ /**
6610
+ Returns the node's [per-node props](#common.NodeProp.perNode) in a
6611
+ format that can be passed to the [`Tree`](#common.Tree)
6612
+ constructor.
6613
+ */
6549
6614
  get propValues() {
6550
6615
  let result = [];
6551
6616
  if (this.props)
@@ -6553,14 +6618,18 @@ class Tree {
6553
6618
  result.push([+id, this.props[id]]);
6554
6619
  return result;
6555
6620
  }
6556
- /// Balance the direct children of this tree, producing a copy of
6557
- /// which may have children grouped into subtrees with type
6558
- /// [`NodeType.none`](#common.NodeType^none).
6621
+ /**
6622
+ Balance the direct children of this tree, producing a copy of
6623
+ which may have children grouped into subtrees with type
6624
+ [`NodeType.none`](#common.NodeType^none).
6625
+ */
6559
6626
  balance(config = {}) {
6560
6627
  return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
6561
6628
  }
6562
- /// Build a tree from a postfix-ordered buffer of node information,
6563
- /// or a cursor over such a buffer.
6629
+ /**
6630
+ Build a tree from a postfix-ordered buffer of node information,
6631
+ or a cursor over such a buffer.
6632
+ */
6564
6633
  static build(data) {
6565
6634
  return buildTree(data);
6566
6635
  }
@@ -6594,17 +6663,23 @@ class FlatBufferCursor {
6594
6663
  }
6595
6664
  }
6596
6665
  class TreeBuffer {
6597
- /// Create a tree buffer.
6666
+ /**
6667
+ Create a tree buffer.
6668
+ */
6598
6669
  constructor(buffer, length, set2) {
6599
6670
  this.buffer = buffer;
6600
6671
  this.length = length;
6601
6672
  this.set = set2;
6602
6673
  }
6603
- /// @internal
6674
+ /**
6675
+ @internal
6676
+ */
6604
6677
  get type() {
6605
6678
  return NodeType.none;
6606
6679
  }
6607
- /// @internal
6680
+ /**
6681
+ @internal
6682
+ */
6608
6683
  toString() {
6609
6684
  let result = [];
6610
6685
  for (let index = 0; index < this.buffer.length; ) {
@@ -6613,7 +6688,9 @@ class TreeBuffer {
6613
6688
  }
6614
6689
  return result.join(",");
6615
6690
  }
6616
- /// @internal
6691
+ /**
6692
+ @internal
6693
+ */
6617
6694
  childString(index) {
6618
6695
  let id = this.buffer[index], endIndex = this.buffer[index + 3];
6619
6696
  let type = this.set.types[id], result = type.name;
@@ -6629,7 +6706,9 @@ class TreeBuffer {
6629
6706
  }
6630
6707
  return result + "(" + children.join(",") + ")";
6631
6708
  }
6632
- /// @internal
6709
+ /**
6710
+ @internal
6711
+ */
6633
6712
  findChild(startIndex, endIndex, dir, pos, side) {
6634
6713
  let { buffer } = this, pick = -1;
6635
6714
  for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
@@ -6641,7 +6720,9 @@ class TreeBuffer {
6641
6720
  }
6642
6721
  return pick;
6643
6722
  }
6644
- /// @internal
6723
+ /**
6724
+ @internal
6725
+ */
6645
6726
  slice(startI, endI, from) {
6646
6727
  let b = this.buffer;
6647
6728
  let copy = new Uint16Array(endI - startI), len = 0;
@@ -6671,21 +6752,6 @@ function checkSide(side, pos, from, to) {
6671
6752
  return true;
6672
6753
  }
6673
6754
  }
6674
- function enterUnfinishedNodesBefore(node, pos) {
6675
- let scan = node.childBefore(pos);
6676
- while (scan) {
6677
- let last = scan.lastChild;
6678
- if (!last || last.to != scan.to)
6679
- break;
6680
- if (last.type.isError && last.from == last.to) {
6681
- node = scan;
6682
- scan = last.prevSibling;
6683
- } else {
6684
- scan = last;
6685
- }
6686
- }
6687
- return node;
6688
- }
6689
6755
  function resolveNode(node, pos, side, overlays) {
6690
6756
  var _a;
6691
6757
  while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
@@ -6707,8 +6773,51 @@ function resolveNode(node, pos, side, overlays) {
6707
6773
  node = inner;
6708
6774
  }
6709
6775
  }
6710
- class TreeNode {
6776
+ class BaseNode {
6777
+ cursor(mode = 0) {
6778
+ return new TreeCursor(this, mode);
6779
+ }
6780
+ getChild(type, before = null, after = null) {
6781
+ let r2 = getChildren(this, type, before, after);
6782
+ return r2.length ? r2[0] : null;
6783
+ }
6784
+ getChildren(type, before = null, after = null) {
6785
+ return getChildren(this, type, before, after);
6786
+ }
6787
+ resolve(pos, side = 0) {
6788
+ return resolveNode(this, pos, side, false);
6789
+ }
6790
+ resolveInner(pos, side = 0) {
6791
+ return resolveNode(this, pos, side, true);
6792
+ }
6793
+ matchContext(context) {
6794
+ return matchNodeContext(this, context);
6795
+ }
6796
+ enterUnfinishedNodesBefore(pos) {
6797
+ let scan = this.childBefore(pos), node = this;
6798
+ while (scan) {
6799
+ let last = scan.lastChild;
6800
+ if (!last || last.to != scan.to)
6801
+ break;
6802
+ if (last.type.isError && last.from == last.to) {
6803
+ node = scan;
6804
+ scan = last.prevSibling;
6805
+ } else {
6806
+ scan = last;
6807
+ }
6808
+ }
6809
+ return node;
6810
+ }
6811
+ get node() {
6812
+ return this;
6813
+ }
6814
+ get next() {
6815
+ return this.parent;
6816
+ }
6817
+ }
6818
+ class TreeNode extends BaseNode {
6711
6819
  constructor(_tree, from, index, _parent) {
6820
+ super();
6712
6821
  this._tree = _tree;
6713
6822
  this.from = from;
6714
6823
  this.index = index;
@@ -6737,7 +6846,7 @@ class TreeNode {
6737
6846
  return new BufferNode(new BufferContext(parent, next, i, start2), null, index);
6738
6847
  } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
6739
6848
  let mounted;
6740
- if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
6849
+ if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay)
6741
6850
  return new TreeNode(mounted.tree, start2, i, parent);
6742
6851
  let inner = new TreeNode(next, start2, i, parent);
6743
6852
  return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
@@ -6792,7 +6901,7 @@ class TreeNode {
6792
6901
  }
6793
6902
  enter(pos, side, mode = 0) {
6794
6903
  let mounted;
6795
- if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
6904
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) {
6796
6905
  let rPos = pos - this.from;
6797
6906
  for (let { from, to } of mounted.overlay) {
6798
6907
  if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
@@ -6828,41 +6937,18 @@ class TreeNode {
6828
6937
  /* Side.DontCare */
6829
6938
  ) : null;
6830
6939
  }
6831
- cursor(mode = 0) {
6832
- return new TreeCursor(this, mode);
6833
- }
6834
6940
  get tree() {
6835
6941
  return this._tree;
6836
6942
  }
6837
6943
  toTree() {
6838
6944
  return this._tree;
6839
6945
  }
6840
- resolve(pos, side = 0) {
6841
- return resolveNode(this, pos, side, false);
6842
- }
6843
- resolveInner(pos, side = 0) {
6844
- return resolveNode(this, pos, side, true);
6845
- }
6846
- enterUnfinishedNodesBefore(pos) {
6847
- return enterUnfinishedNodesBefore(this, pos);
6848
- }
6849
- getChild(type, before = null, after = null) {
6850
- let r2 = getChildren(this, type, before, after);
6851
- return r2.length ? r2[0] : null;
6852
- }
6853
- getChildren(type, before = null, after = null) {
6854
- return getChildren(this, type, before, after);
6855
- }
6856
- /// @internal
6946
+ /**
6947
+ @internal
6948
+ */
6857
6949
  toString() {
6858
6950
  return this._tree.toString();
6859
6951
  }
6860
- get node() {
6861
- return this;
6862
- }
6863
- matchContext(context) {
6864
- return matchNodeContext(this, context);
6865
- }
6866
6952
  }
6867
6953
  function getChildren(node, type, before, after) {
6868
6954
  let cur = node.cursor(), result = [];
@@ -6902,7 +6988,7 @@ class BufferContext {
6902
6988
  this.start = start2;
6903
6989
  }
6904
6990
  }
6905
- class BufferNode {
6991
+ class BufferNode extends BaseNode {
6906
6992
  get name() {
6907
6993
  return this.type.name;
6908
6994
  }
@@ -6913,6 +6999,7 @@ class BufferNode {
6913
6999
  return this.context.start + this.context.buffer.buffer[this.index + 2];
6914
7000
  }
6915
7001
  constructor(context, _parent, index) {
7002
+ super();
6916
7003
  this.context = context;
6917
7004
  this._parent = _parent;
6918
7005
  this.index = index;
@@ -6995,9 +7082,6 @@ class BufferNode {
6995
7082
  /* Side.DontCare */
6996
7083
  ));
6997
7084
  }
6998
- cursor(mode = 0) {
6999
- return new TreeCursor(this, mode);
7000
- }
7001
7085
  get tree() {
7002
7086
  return null;
7003
7087
  }
@@ -7012,39 +7096,70 @@ class BufferNode {
7012
7096
  }
7013
7097
  return new Tree(this.type, children, positions, this.to - this.from);
7014
7098
  }
7015
- resolve(pos, side = 0) {
7016
- return resolveNode(this, pos, side, false);
7017
- }
7018
- resolveInner(pos, side = 0) {
7019
- return resolveNode(this, pos, side, true);
7020
- }
7021
- enterUnfinishedNodesBefore(pos) {
7022
- return enterUnfinishedNodesBefore(this, pos);
7023
- }
7024
- /// @internal
7099
+ /**
7100
+ @internal
7101
+ */
7025
7102
  toString() {
7026
7103
  return this.context.buffer.childString(this.index);
7027
7104
  }
7028
- getChild(type, before = null, after = null) {
7029
- let r2 = getChildren(this, type, before, after);
7030
- return r2.length ? r2[0] : null;
7031
- }
7032
- getChildren(type, before = null, after = null) {
7033
- return getChildren(this, type, before, after);
7105
+ }
7106
+ function iterStack(heads) {
7107
+ if (!heads.length)
7108
+ return null;
7109
+ if (heads.length == 1)
7110
+ return heads[0];
7111
+ let pick = 0, picked = heads[0];
7112
+ for (let i = 1; i < heads.length; i++) {
7113
+ let node = heads[i];
7114
+ if (node.from > picked.from || node.to < picked.to) {
7115
+ picked = node;
7116
+ pick = i;
7117
+ }
7118
+ }
7119
+ let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
7120
+ let newHeads = heads.slice();
7121
+ if (next)
7122
+ newHeads[pick] = next;
7123
+ else
7124
+ newHeads.splice(pick, 1);
7125
+ return new StackIterator(newHeads, picked);
7126
+ }
7127
+ class StackIterator {
7128
+ constructor(heads, node) {
7129
+ this.heads = heads;
7130
+ this.node = node;
7034
7131
  }
7035
- get node() {
7036
- return this;
7132
+ get next() {
7133
+ return iterStack(this.heads);
7037
7134
  }
7038
- matchContext(context) {
7039
- return matchNodeContext(this, context);
7135
+ }
7136
+ function stackIterator(tree, pos, side) {
7137
+ let inner = tree.resolveInner(pos, side), layers = null;
7138
+ for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) {
7139
+ if (scan.index < 0) {
7140
+ let parent = scan.parent;
7141
+ (layers || (layers = [inner])).push(parent.resolve(pos, side));
7142
+ scan = parent;
7143
+ } else {
7144
+ let mount = MountedTree.get(scan.tree);
7145
+ if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
7146
+ let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, 0, null);
7147
+ (layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
7148
+ }
7149
+ }
7040
7150
  }
7151
+ return layers ? iterStack(layers) : inner;
7041
7152
  }
7042
7153
  class TreeCursor {
7043
- /// Shorthand for `.type.name`.
7154
+ /**
7155
+ Shorthand for `.type.name`.
7156
+ */
7044
7157
  get name() {
7045
7158
  return this.type.name;
7046
7159
  }
7047
- /// @internal
7160
+ /**
7161
+ @internal
7162
+ */
7048
7163
  constructor(node, mode = 0) {
7049
7164
  this.mode = mode;
7050
7165
  this.buffer = null;
@@ -7089,11 +7204,15 @@ class TreeCursor {
7089
7204
  this.buffer = node.context;
7090
7205
  return this.yieldBuf(node.index, node.type);
7091
7206
  }
7092
- /// @internal
7207
+ /**
7208
+ @internal
7209
+ */
7093
7210
  toString() {
7094
7211
  return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
7095
7212
  }
7096
- /// @internal
7213
+ /**
7214
+ @internal
7215
+ */
7097
7216
  enterChild(dir, pos, side) {
7098
7217
  if (!this.buffer)
7099
7218
  return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
@@ -7104,8 +7223,10 @@ class TreeCursor {
7104
7223
  this.stack.push(this.index);
7105
7224
  return this.yieldBuf(index);
7106
7225
  }
7107
- /// Move the cursor to this node's first child. When this returns
7108
- /// false, the node has no child, and the cursor has not been moved.
7226
+ /**
7227
+ Move the cursor to this node's first child. When this returns
7228
+ false, the node has no child, and the cursor has not been moved.
7229
+ */
7109
7230
  firstChild() {
7110
7231
  return this.enterChild(
7111
7232
  1,
@@ -7114,7 +7235,9 @@ class TreeCursor {
7114
7235
  /* Side.DontCare */
7115
7236
  );
7116
7237
  }
7117
- /// Move the cursor to this node's last child.
7238
+ /**
7239
+ Move the cursor to this node's last child.
7240
+ */
7118
7241
  lastChild() {
7119
7242
  return this.enterChild(
7120
7243
  -1,
@@ -7123,7 +7246,9 @@ class TreeCursor {
7123
7246
  /* Side.DontCare */
7124
7247
  );
7125
7248
  }
7126
- /// Move the cursor to the first child that ends after `pos`.
7249
+ /**
7250
+ Move the cursor to the first child that ends after `pos`.
7251
+ */
7127
7252
  childAfter(pos) {
7128
7253
  return this.enterChild(
7129
7254
  1,
@@ -7132,7 +7257,9 @@ class TreeCursor {
7132
7257
  /* Side.After */
7133
7258
  );
7134
7259
  }
7135
- /// Move to the last child that starts before `pos`.
7260
+ /**
7261
+ Move to the last child that starts before `pos`.
7262
+ */
7136
7263
  childBefore(pos) {
7137
7264
  return this.enterChild(
7138
7265
  -1,
@@ -7141,17 +7268,21 @@ class TreeCursor {
7141
7268
  /* Side.Before */
7142
7269
  );
7143
7270
  }
7144
- /// Move the cursor to the child around `pos`. If side is -1 the
7145
- /// child may end at that position, when 1 it may start there. This
7146
- /// will also enter [overlaid](#common.MountedTree.overlay)
7147
- /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
7148
- /// set to false.
7271
+ /**
7272
+ Move the cursor to the child around `pos`. If side is -1 the
7273
+ child may end at that position, when 1 it may start there. This
7274
+ will also enter [overlaid](#common.MountedTree.overlay)
7275
+ [mounted](#common.NodeProp^mounted) trees unless `overlays` is
7276
+ set to false.
7277
+ */
7149
7278
  enter(pos, side, mode = this.mode) {
7150
7279
  if (!this.buffer)
7151
7280
  return this.yield(this._tree.enter(pos, side, mode));
7152
7281
  return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
7153
7282
  }
7154
- /// Move to the node's parent node, if this isn't the top node.
7283
+ /**
7284
+ Move to the node's parent node, if this isn't the top node.
7285
+ */
7155
7286
  parent() {
7156
7287
  if (!this.buffer)
7157
7288
  return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
@@ -7161,7 +7292,9 @@ class TreeCursor {
7161
7292
  this.buffer = null;
7162
7293
  return this.yieldNode(parent);
7163
7294
  }
7164
- /// @internal
7295
+ /**
7296
+ @internal
7297
+ */
7165
7298
  sibling(dir) {
7166
7299
  if (!this.buffer)
7167
7300
  return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
@@ -7184,11 +7317,15 @@ class TreeCursor {
7184
7317
  }
7185
7318
  return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
7186
7319
  }
7187
- /// Move to this node's next sibling, if any.
7320
+ /**
7321
+ Move to this node's next sibling, if any.
7322
+ */
7188
7323
  nextSibling() {
7189
7324
  return this.sibling(1);
7190
7325
  }
7191
- /// Move to this node's previous sibling, if any.
7326
+ /**
7327
+ Move to this node's previous sibling, if any.
7328
+ */
7192
7329
  prevSibling() {
7193
7330
  return this.sibling(-1);
7194
7331
  }
@@ -7232,24 +7369,30 @@ class TreeCursor {
7232
7369
  return false;
7233
7370
  }
7234
7371
  }
7235
- /// Move to the next node in a
7236
- /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
7237
- /// traversal, going from a node to its first child or, if the
7238
- /// current node is empty or `enter` is false, its next sibling or
7239
- /// the next sibling of the first parent node that has one.
7372
+ /**
7373
+ Move to the next node in a
7374
+ [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
7375
+ traversal, going from a node to its first child or, if the
7376
+ current node is empty or `enter` is false, its next sibling or
7377
+ the next sibling of the first parent node that has one.
7378
+ */
7240
7379
  next(enter = true) {
7241
7380
  return this.move(1, enter);
7242
7381
  }
7243
- /// Move to the next node in a last-to-first pre-order traveral. A
7244
- /// node is followed by its last child or, if it has none, its
7245
- /// previous sibling or the previous sibling of the first parent
7246
- /// node that has one.
7382
+ /**
7383
+ Move to the next node in a last-to-first pre-order traveral. A
7384
+ node is followed by its last child or, if it has none, its
7385
+ previous sibling or the previous sibling of the first parent
7386
+ node that has one.
7387
+ */
7247
7388
  prev(enter = true) {
7248
7389
  return this.move(-1, enter);
7249
7390
  }
7250
- /// Move the cursor to the innermost node that covers `pos`. If
7251
- /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
7252
- /// it will enter nodes that start at `pos`.
7391
+ /**
7392
+ Move the cursor to the innermost node that covers `pos`. If
7393
+ `side` is -1, it will enter nodes that end at `pos`. If it is 1,
7394
+ it will enter nodes that start at `pos`.
7395
+ */
7253
7396
  moveTo(pos, side = 0) {
7254
7397
  while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
7255
7398
  if (!this.parent())
@@ -7258,8 +7401,10 @@ class TreeCursor {
7258
7401
  }
7259
7402
  return this;
7260
7403
  }
7261
- /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
7262
- /// position.
7404
+ /**
7405
+ Get a [syntax node](#common.SyntaxNode) at the cursor's current
7406
+ position.
7407
+ */
7263
7408
  get node() {
7264
7409
  if (!this.buffer)
7265
7410
  return this._tree;
@@ -7282,16 +7427,20 @@ class TreeCursor {
7282
7427
  result = new BufferNode(this.buffer, result, this.stack[i]);
7283
7428
  return this.bufferNode = new BufferNode(this.buffer, result, this.index);
7284
7429
  }
7285
- /// Get the [tree](#common.Tree) that represents the current node, if
7286
- /// any. Will return null when the node is in a [tree
7287
- /// buffer](#common.TreeBuffer).
7430
+ /**
7431
+ Get the [tree](#common.Tree) that represents the current node, if
7432
+ any. Will return null when the node is in a [tree
7433
+ buffer](#common.TreeBuffer).
7434
+ */
7288
7435
  get tree() {
7289
7436
  return this.buffer ? null : this._tree._tree;
7290
7437
  }
7291
- /// Iterate over the current node and all its descendants, calling
7292
- /// `enter` when entering a node and `leave`, if given, when leaving
7293
- /// one. When `enter` returns `false`, any children of that node are
7294
- /// skipped, and `leave` isn't called for it.
7438
+ /**
7439
+ Iterate over the current node and all its descendants, calling
7440
+ `enter` when entering a node and `leave`, if given, when leaving
7441
+ one. When `enter` returns `false`, any children of that node are
7442
+ skipped, and `leave` isn't called for it.
7443
+ */
7295
7444
  iterate(enter, leave) {
7296
7445
  for (let depth = 0; ; ) {
7297
7446
  let mustLeave = false;
@@ -7317,9 +7466,11 @@ class TreeCursor {
7317
7466
  }
7318
7467
  }
7319
7468
  }
7320
- /// Test whether the current node matches a given context—a sequence
7321
- /// of direct parent node names. Empty strings in the context array
7322
- /// are treated as wildcards.
7469
+ /**
7470
+ Test whether the current node matches a given context—a sequence
7471
+ of direct parent node names. Empty strings in the context array
7472
+ are treated as wildcards.
7473
+ */
7323
7474
  matchContext(context) {
7324
7475
  if (!this.buffer)
7325
7476
  return matchNodeContext(this.node, context);
package/package.json CHANGED
@@ -1,71 +1,69 @@
1
1
  {
2
2
  "name": "@scalar/use-codemirror",
3
3
  "description": "CodeMirror for Vue",
4
- "keywords": [
5
- "vue",
6
- "vue3",
7
- "composable",
8
- "codemirror"
9
- ],
10
- "version": "0.5.4",
4
+ "version": "0.6.0",
11
5
  "author": "Scalar (https://github.com/scalar)",
12
- "homepage": "https://github.com/scalar/scalar",
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/scalar/scalar.git",
16
- "directory": "packages/use-codemirror"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/scalar/scalar/issues/new"
20
- },
21
- "license": "MIT",
22
- "engines": {
23
- "node": ">=18"
24
- },
25
- "type": "module",
26
- "main": "dist/index.js",
27
- "module": "dist/index.js",
28
- "files": [
29
- "dist"
30
- ],
31
- "exports": {
32
- "import": "./dist/index.js"
33
- },
6
+ "bugs": "https://github.com/scalar/scalar/issues/new",
34
7
  "dependencies": {
35
- "@codemirror/lang-java": "^6.0.1",
8
+ "@codemirror/lang-java": "6.0.1",
36
9
  "@codemirror/lang-javascript": "6.2.1",
37
10
  "@codemirror/lang-json": "6.0.1",
38
11
  "@codemirror/lang-python": "6.1.3",
39
- "@codemirror/language": "6.9.0",
12
+ "@codemirror/language": "6.9.1",
40
13
  "@codemirror/legacy-modes": "6.3.3",
41
14
  "@codemirror/state": "6.2.1",
42
- "@codemirror/view": "6.18.0",
43
- "@headlessui/vue": "1.7.14",
44
- "@lezer/common": "1.0.3",
45
- "@lezer/lr": "1.3.10",
15
+ "@codemirror/view": "6.20.0",
16
+ "@headlessui/vue": "1.7.16",
17
+ "@lezer/common": "1.1.0",
46
18
  "@lezer/highlight": "1.1.6",
47
- "@uiw/codemirror-theme-duotone": "4.21.13",
48
- "@uiw/codemirror-themes": "4.21.13",
49
- "@vueuse/core": "10.1.2",
50
- "axios": "1.4.0",
19
+ "@lezer/lr": "1.3.11",
20
+ "@uiw/codemirror-theme-duotone": "4.21.16",
21
+ "@uiw/codemirror-themes": "4.21.16",
22
+ "@vueuse/core": "10.4.1",
23
+ "axios": "1.5.0",
51
24
  "codemirror": "6.0.1",
52
25
  "javascript-time-ago": "2.5.9",
53
- "nanoid": "4.0.2",
54
- "pretty-bytes": "6.1.0",
26
+ "nanoid": "5.0.1",
27
+ "pretty-bytes": "6.1.1",
55
28
  "pretty-ms": "8.0.0",
56
29
  "tippy.js": "6.3.7"
57
30
  },
58
31
  "devDependencies": {
59
- "@vitejs/plugin-vue": "4.2.3",
60
- "tsc-alias": "1.8.6",
61
- "vite": "4.4.8",
62
- "vitest": "0.34.1",
63
- "@vitest/coverage-v8": "^0.34.4",
64
- "vue-tsc": "1.8.8"
32
+ "@vitejs/plugin-vue": "4.3.4",
33
+ "@vitest/coverage-v8": "0.34.4",
34
+ "tsc-alias": "1.8.8",
35
+ "vite": "4.4.9",
36
+ "vitest": "0.34.4",
37
+ "vue-tsc": "1.8.13"
65
38
  },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "exports": {
43
+ "import": "./dist/index.js"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "homepage": "https://github.com/scalar/scalar",
49
+ "keywords": [
50
+ "codemirror",
51
+ "composable",
52
+ "vue",
53
+ "vue3"
54
+ ],
55
+ "license": "MIT",
56
+ "main": "dist/index.js",
57
+ "module": "dist/index.js",
66
58
  "peerDependencies": {
67
59
  "vue": "3.3.4"
68
60
  },
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "https://github.com/scalar/scalar.git",
64
+ "directory": "packages/use-codemirror"
65
+ },
66
+ "type": "module",
69
67
  "scripts": {
70
68
  "build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
71
69
  "dev": "vite",