@vuu-ui/vuu-filters 0.7.6-debug → 0.8.0-debug

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/esm/index.js CHANGED
@@ -208,31 +208,16 @@ var DeleteIcon = forwardRef2(
208
208
  import { Input, ToolbarField } from "@heswell/salt-lab";
209
209
 
210
210
  // src/filter-utils.ts
211
- import { extractFilterForColumn, partition } from "@vuu-ui/vuu-utils";
212
-
213
- // src/filterTypes.ts
214
- var singleValueFilterOps = /* @__PURE__ */ new Set([
215
- "=",
216
- "!=",
217
- ">",
218
- ">=",
219
- "<",
220
- "<=",
221
- "starts",
222
- "ends"
223
- ]);
224
- var isNamedFilter = (f) => f !== void 0 && f.name !== void 0;
225
- var isSingleValueFilter = (f) => f !== void 0 && singleValueFilterOps.has(f.op);
226
- var isFilterClause = (f) => f !== void 0 && (isSingleValueFilter(f) || isMultiValueFilter(f));
227
- var isMultiValueFilter = (f) => f !== void 0 && f.op === "in";
228
- var isInFilter = (f) => f.op === "in";
229
- var isAndFilter = (f) => f.op === "and";
230
- var isOrFilter = (f) => f.op === "or";
231
- function isMultiClauseFilter(f) {
232
- return f !== void 0 && (f.op === "and" || f.op === "or");
233
- }
234
-
235
- // src/filter-utils.ts
211
+ import {
212
+ extractFilterForColumn,
213
+ isAndFilter,
214
+ isInFilter,
215
+ isMultiClauseFilter,
216
+ isMultiValueFilter,
217
+ isOrFilter,
218
+ isSingleValueFilter,
219
+ partition
220
+ } from "@vuu-ui/vuu-utils";
236
221
  var AND = "and";
237
222
  var EQUALS = "=";
238
223
  var GREATER_THAN = ">";
@@ -304,16 +289,6 @@ var includesNoValues = (filter) => {
304
289
  }
305
290
  return isAndFilter(filter) && filter.filters.some((f) => includesNoValues(f));
306
291
  };
307
- var filterValue = (value) => typeof value === "string" ? `"${value}"` : value;
308
- var filterAsQuery = (f) => {
309
- if (isMultiClauseFilter(f)) {
310
- return f.filters.map((filter) => filterAsQuery(filter)).join(` ${f.op} `);
311
- } else if (isMultiValueFilter(f)) {
312
- return `${f.column} ${f.op} [${f.values.join(",")}]`;
313
- } else {
314
- return `${f.column} ${f.op} ${filterValue(f.value)}`;
315
- }
316
- };
317
292
  var includesAllValues = (filter) => {
318
293
  if (!filter) {
319
294
  return false;
@@ -370,18 +345,6 @@ var combine = (existingFilters, replacementFilters) => {
370
345
  ) === false;
371
346
  return existingFilters.filter(stillApplicable).concat(replacementFilters);
372
347
  };
373
- var removeColumnFromFilter = (column, filter) => {
374
- if (isMultiClauseFilter(filter)) {
375
- const [clause1, clause2] = filter.filters;
376
- if (clause1.column === column.name) {
377
- return [clause2, filterAsQuery(clause2)];
378
- }
379
- if (clause2.column === column.name) {
380
- return [clause1, filterAsQuery(clause1)];
381
- }
382
- }
383
- return [void 0, ""];
384
- };
385
348
  var removeFilter = (sourceFilter, filterToRemove) => {
386
349
  if (filterEquals(sourceFilter, filterToRemove, true)) {
387
350
  return null;
@@ -398,17 +361,17 @@ var removeFilter = (sourceFilter, filterToRemove) => {
398
361
  );
399
362
  return filters.length > 0 ? { type: AND, filters } : null;
400
363
  };
401
- var splitFilterOnColumn = (filter, columnName) => {
364
+ var splitFilterOnColumn = (columnName, filter) => {
402
365
  if (!filter) {
403
- return [null, null];
366
+ return [void 0, void 0];
404
367
  }
405
368
  if (filter.column === columnName) {
406
- return [filter, null];
369
+ return [filter, void 0];
407
370
  }
408
371
  if (filter.op !== AND) {
409
- return [null, filter];
372
+ return [void 0, filter];
410
373
  }
411
- const [[columnFilter = null], filters] = partition(
374
+ const [[columnFilter = void 0], filters] = partition(
412
375
  filter.filters,
413
376
  (f) => f.column === columnName
414
377
  );
@@ -499,96 +462,3223 @@ var updateFilter = (filter, newFilter, mode) => {
499
462
  return updateFilter(result, newFilter, "add");
500
463
  }
501
464
  }
502
- return {
503
- op: "and",
504
- filters: [filter, newFilter]
505
- };
506
- }
507
- if (newFilter) {
508
- return newFilter;
509
- }
510
- return filter;
465
+ return {
466
+ op: "and",
467
+ filters: [filter, newFilter]
468
+ };
469
+ }
470
+ if (newFilter) {
471
+ return newFilter;
472
+ }
473
+ return filter;
474
+ };
475
+
476
+ // src/column-filter/utils.ts
477
+ var isStartsWithValue = (value) => /\.\.\.$/.test(value);
478
+ var getTypeaheadFilter = (column, filterValues, isStartsWithFilter) => {
479
+ if (filterValues.length === 0) {
480
+ return void 0;
481
+ }
482
+ if (isStartsWithFilter) {
483
+ const startsWith = filterValues[0].substring(0, filterValues[0].length - 3);
484
+ return {
485
+ column,
486
+ op: "starts",
487
+ value: `"${startsWith}"`
488
+ };
489
+ }
490
+ return {
491
+ column,
492
+ op: "in",
493
+ values: filterValues.map((value) => `"${value}"`)
494
+ };
495
+ };
496
+ var getRangeFilter = (column, startValue, endValue) => {
497
+ const startFilter = startValue === void 0 ? void 0 : { column, op: ">", value: startValue - 1 };
498
+ const endFilter = endValue === void 0 ? void 0 : { column, op: "<", value: endValue + 1 };
499
+ if (endFilter === void 0)
500
+ return startFilter;
501
+ return addFilter(startFilter, endFilter, { combineWith: "and" });
502
+ };
503
+
504
+ // src/column-filter/RangeFilter.tsx
505
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
506
+ var RangeFilter = ({
507
+ defaultTypeaheadParams,
508
+ filterValues,
509
+ onChange
510
+ }) => {
511
+ var _a, _b;
512
+ const columnName = defaultTypeaheadParams[1];
513
+ const startChangeHandler = (e) => {
514
+ const value = parseFloat(e.target.value);
515
+ const newRange = {
516
+ start: isNaN(value) ? void 0 : value,
517
+ end: filterValues == null ? void 0 : filterValues.end
518
+ };
519
+ const filter = getRangeFilter(columnName, newRange.start, newRange.end);
520
+ onChange(newRange, filter);
521
+ };
522
+ const endChangeHandler = (e) => {
523
+ const value = parseFloat(e.target.value);
524
+ const newRange = {
525
+ start: filterValues == null ? void 0 : filterValues.start,
526
+ end: isNaN(value) ? void 0 : value
527
+ };
528
+ const filter = getRangeFilter(columnName, newRange.start, newRange.end);
529
+ onChange(newRange, filter);
530
+ };
531
+ return /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: "row" }, children: [
532
+ /* @__PURE__ */ jsx3(ToolbarField, { label: "From", children: /* @__PURE__ */ jsx3(
533
+ Input,
534
+ {
535
+ onChange: startChangeHandler,
536
+ value: ((_a = filterValues == null ? void 0 : filterValues.start) == null ? void 0 : _a.toString()) || "",
537
+ type: "number"
538
+ }
539
+ ) }),
540
+ /* @__PURE__ */ jsx3(ToolbarField, { label: "To", children: /* @__PURE__ */ jsx3(
541
+ Input,
542
+ {
543
+ onChange: endChangeHandler,
544
+ value: ((_b = filterValues == null ? void 0 : filterValues.end) == null ? void 0 : _b.toString()) || "",
545
+ type: "number"
546
+ }
547
+ ) })
548
+ ] });
549
+ };
550
+
551
+ // ../vuu-data-react/src/hooks/useDataSource.ts
552
+ import { getFullRange, metadataKeys, WindowRange } from "@vuu-ui/vuu-utils";
553
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
554
+ var { SELECTED } = metadataKeys;
555
+
556
+ // ../vuu-data-react/src/hooks/useServerConnectionStatus.ts
557
+ import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
558
+ import { ConnectionManager } from "@vuu-ui/vuu-data";
559
+
560
+ // ../vuu-data-react/src/hooks/useServerConnectionQuality.ts
561
+ import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
562
+ import { ConnectionManager as ConnectionManager2 } from "@vuu-ui/vuu-data";
563
+
564
+ // ../vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
565
+ import { useCallback as useCallback4 } from "react";
566
+ import { makeRpcCall } from "@vuu-ui/vuu-data";
567
+ var TYPEAHEAD_MESSAGE_CONSTANTS = {
568
+ type: "RPC_CALL",
569
+ service: "TypeAheadRpcHandler"
570
+ };
571
+ var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
572
+ if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
573
+ return [table, column, text];
574
+ }
575
+ return [table, column];
576
+ };
577
+ var useTypeaheadSuggestions = () => {
578
+ const getTypeaheadSuggestions = useCallback4(
579
+ async (params) => {
580
+ const rpcMessage = params.length === 2 ? {
581
+ method: "getUniqueFieldValues",
582
+ params,
583
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
584
+ } : {
585
+ method: "getUniqueFieldValuesStartingWith",
586
+ params,
587
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
588
+ };
589
+ const suggestions = await makeRpcCall(rpcMessage);
590
+ return suggestions;
591
+ },
592
+ []
593
+ );
594
+ return getTypeaheadSuggestions;
595
+ };
596
+
597
+ // ../../node_modules/@lezer/common/dist/index.js
598
+ var DefaultBufferLength = 1024;
599
+ var nextPropID = 0;
600
+ var Range = class {
601
+ constructor(from, to) {
602
+ this.from = from;
603
+ this.to = to;
604
+ }
605
+ };
606
+ var NodeProp = class {
607
+ /// Create a new node prop type.
608
+ constructor(config = {}) {
609
+ this.id = nextPropID++;
610
+ this.perNode = !!config.perNode;
611
+ this.deserialize = config.deserialize || (() => {
612
+ throw new Error("This node type doesn't define a deserialize function");
613
+ });
614
+ }
615
+ /// This is meant to be used with
616
+ /// [`NodeSet.extend`](#common.NodeSet.extend) or
617
+ /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
618
+ /// prop values for each node type in the set. Takes a [match
619
+ /// object](#common.NodeType^match) or function that returns undefined
620
+ /// if the node type doesn't get this prop, and the prop's value if
621
+ /// it does.
622
+ add(match) {
623
+ if (this.perNode)
624
+ throw new RangeError("Can't add per-node props to node types");
625
+ if (typeof match != "function")
626
+ match = NodeType.match(match);
627
+ return (type) => {
628
+ let result = match(type);
629
+ return result === void 0 ? null : [this, result];
630
+ };
631
+ }
632
+ };
633
+ NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
634
+ NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
635
+ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
636
+ NodeProp.contextHash = new NodeProp({ perNode: true });
637
+ NodeProp.lookAhead = new NodeProp({ perNode: true });
638
+ NodeProp.mounted = new NodeProp({ perNode: true });
639
+ var noProps = /* @__PURE__ */ Object.create(null);
640
+ var NodeType = class {
641
+ /// @internal
642
+ constructor(name, props, id, flags = 0) {
643
+ this.name = name;
644
+ this.props = props;
645
+ this.id = id;
646
+ this.flags = flags;
647
+ }
648
+ /// Define a node type.
649
+ static define(spec) {
650
+ let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
651
+ let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
652
+ let type = new NodeType(spec.name || "", props, spec.id, flags);
653
+ if (spec.props)
654
+ for (let src of spec.props) {
655
+ if (!Array.isArray(src))
656
+ src = src(type);
657
+ if (src) {
658
+ if (src[0].perNode)
659
+ throw new RangeError("Can't store a per-node prop on a node type");
660
+ props[src[0].id] = src[1];
661
+ }
662
+ }
663
+ return type;
664
+ }
665
+ /// Retrieves a node prop for this type. Will return `undefined` if
666
+ /// the prop isn't present on this node.
667
+ prop(prop) {
668
+ return this.props[prop.id];
669
+ }
670
+ /// True when this is the top node of a grammar.
671
+ get isTop() {
672
+ return (this.flags & 1) > 0;
673
+ }
674
+ /// True when this node is produced by a skip rule.
675
+ get isSkipped() {
676
+ return (this.flags & 2) > 0;
677
+ }
678
+ /// Indicates whether this is an error node.
679
+ get isError() {
680
+ return (this.flags & 4) > 0;
681
+ }
682
+ /// When true, this node type doesn't correspond to a user-declared
683
+ /// named node, for example because it is used to cache repetition.
684
+ get isAnonymous() {
685
+ return (this.flags & 8) > 0;
686
+ }
687
+ /// Returns true when this node's name or one of its
688
+ /// [groups](#common.NodeProp^group) matches the given string.
689
+ is(name) {
690
+ if (typeof name == "string") {
691
+ if (this.name == name)
692
+ return true;
693
+ let group = this.prop(NodeProp.group);
694
+ return group ? group.indexOf(name) > -1 : false;
695
+ }
696
+ return this.id == name;
697
+ }
698
+ /// Create a function from node types to arbitrary values by
699
+ /// specifying an object whose property names are node or
700
+ /// [group](#common.NodeProp^group) names. Often useful with
701
+ /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
702
+ /// names, separated by spaces, in a single property name to map
703
+ /// multiple node names to a single value.
704
+ static match(map) {
705
+ let direct = /* @__PURE__ */ Object.create(null);
706
+ for (let prop in map)
707
+ for (let name of prop.split(" "))
708
+ direct[name] = map[prop];
709
+ return (node) => {
710
+ for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
711
+ let found = direct[i < 0 ? node.name : groups[i]];
712
+ if (found)
713
+ return found;
714
+ }
715
+ };
716
+ }
717
+ };
718
+ NodeType.none = new NodeType(
719
+ "",
720
+ /* @__PURE__ */ Object.create(null),
721
+ 0,
722
+ 8
723
+ /* NodeFlag.Anonymous */
724
+ );
725
+ var NodeSet = class {
726
+ /// Create a set with the given types. The `id` property of each
727
+ /// type should correspond to its position within the array.
728
+ constructor(types) {
729
+ this.types = types;
730
+ for (let i = 0; i < types.length; i++)
731
+ if (types[i].id != i)
732
+ throw new RangeError("Node type ids should correspond to array positions when creating a node set");
733
+ }
734
+ /// Create a copy of this set with some node properties added. The
735
+ /// arguments to this method can be created with
736
+ /// [`NodeProp.add`](#common.NodeProp.add).
737
+ extend(...props) {
738
+ let newTypes = [];
739
+ for (let type of this.types) {
740
+ let newProps = null;
741
+ for (let source of props) {
742
+ let add = source(type);
743
+ if (add) {
744
+ if (!newProps)
745
+ newProps = Object.assign({}, type.props);
746
+ newProps[add[0].id] = add[1];
747
+ }
748
+ }
749
+ newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
750
+ }
751
+ return new NodeSet(newTypes);
752
+ }
753
+ };
754
+ var CachedNode = /* @__PURE__ */ new WeakMap();
755
+ var CachedInnerNode = /* @__PURE__ */ new WeakMap();
756
+ var IterMode;
757
+ (function(IterMode2) {
758
+ IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
759
+ IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
760
+ IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
761
+ IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
762
+ })(IterMode || (IterMode = {}));
763
+ var Tree = class {
764
+ /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
765
+ constructor(type, children, positions, length, props) {
766
+ this.type = type;
767
+ this.children = children;
768
+ this.positions = positions;
769
+ this.length = length;
770
+ this.props = null;
771
+ if (props && props.length) {
772
+ this.props = /* @__PURE__ */ Object.create(null);
773
+ for (let [prop, value] of props)
774
+ this.props[typeof prop == "number" ? prop : prop.id] = value;
775
+ }
776
+ }
777
+ /// @internal
778
+ toString() {
779
+ let mounted = this.prop(NodeProp.mounted);
780
+ if (mounted && !mounted.overlay)
781
+ return mounted.tree.toString();
782
+ let children = "";
783
+ for (let ch of this.children) {
784
+ let str = ch.toString();
785
+ if (str) {
786
+ if (children)
787
+ children += ",";
788
+ children += str;
789
+ }
790
+ }
791
+ return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
792
+ }
793
+ /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
794
+ /// the tree. Mode can be used to [control](#common.IterMode) which
795
+ /// nodes the cursor visits.
796
+ cursor(mode = 0) {
797
+ return new TreeCursor(this.topNode, mode);
798
+ }
799
+ /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
800
+ /// at the given position and side (see
801
+ /// [`moveTo`](#common.TreeCursor.moveTo).
802
+ cursorAt(pos, side = 0, mode = 0) {
803
+ let scope = CachedNode.get(this) || this.topNode;
804
+ let cursor = new TreeCursor(scope);
805
+ cursor.moveTo(pos, side);
806
+ CachedNode.set(this, cursor._tree);
807
+ return cursor;
808
+ }
809
+ /// Get a [syntax node](#common.SyntaxNode) object for the top of the
810
+ /// tree.
811
+ get topNode() {
812
+ return new TreeNode(this, 0, 0, null);
813
+ }
814
+ /// Get the [syntax node](#common.SyntaxNode) at the given position.
815
+ /// If `side` is -1, this will move into nodes that end at the
816
+ /// position. If 1, it'll move into nodes that start at the
817
+ /// position. With 0, it'll only enter nodes that cover the position
818
+ /// from both sides.
819
+ ///
820
+ /// Note that this will not enter
821
+ /// [overlays](#common.MountedTree.overlay), and you often want
822
+ /// [`resolveInner`](#common.Tree.resolveInner) instead.
823
+ resolve(pos, side = 0) {
824
+ let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
825
+ CachedNode.set(this, node);
826
+ return node;
827
+ }
828
+ /// Like [`resolve`](#common.Tree.resolve), but will enter
829
+ /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
830
+ /// pointing into the innermost overlaid tree at the given position
831
+ /// (with parent links going through all parent structure, including
832
+ /// the host trees).
833
+ resolveInner(pos, side = 0) {
834
+ let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
835
+ CachedInnerNode.set(this, node);
836
+ return node;
837
+ }
838
+ /// Iterate over the tree and its children, calling `enter` for any
839
+ /// node that touches the `from`/`to` region (if given) before
840
+ /// running over such a node's children, and `leave` (if given) when
841
+ /// leaving the node. When `enter` returns `false`, that node will
842
+ /// not have its children iterated over (or `leave` called).
843
+ iterate(spec) {
844
+ let { enter, leave, from = 0, to = this.length } = spec;
845
+ let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
846
+ for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
847
+ let entered = false;
848
+ if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
849
+ if (c.firstChild())
850
+ continue;
851
+ entered = true;
852
+ }
853
+ for (; ; ) {
854
+ if (entered && leave && (anon || !c.type.isAnonymous))
855
+ leave(c);
856
+ if (c.nextSibling())
857
+ break;
858
+ if (!c.parent())
859
+ return;
860
+ entered = true;
861
+ }
862
+ }
863
+ }
864
+ /// Get the value of the given [node prop](#common.NodeProp) for this
865
+ /// node. Works with both per-node and per-type props.
866
+ prop(prop) {
867
+ return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
868
+ }
869
+ /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
870
+ /// format that can be passed to the [`Tree`](#common.Tree)
871
+ /// constructor.
872
+ get propValues() {
873
+ let result = [];
874
+ if (this.props)
875
+ for (let id in this.props)
876
+ result.push([+id, this.props[id]]);
877
+ return result;
878
+ }
879
+ /// Balance the direct children of this tree, producing a copy of
880
+ /// which may have children grouped into subtrees with type
881
+ /// [`NodeType.none`](#common.NodeType^none).
882
+ balance(config = {}) {
883
+ 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)));
884
+ }
885
+ /// Build a tree from a postfix-ordered buffer of node information,
886
+ /// or a cursor over such a buffer.
887
+ static build(data) {
888
+ return buildTree(data);
889
+ }
890
+ };
891
+ Tree.empty = new Tree(NodeType.none, [], [], 0);
892
+ var FlatBufferCursor = class {
893
+ constructor(buffer, index) {
894
+ this.buffer = buffer;
895
+ this.index = index;
896
+ }
897
+ get id() {
898
+ return this.buffer[this.index - 4];
899
+ }
900
+ get start() {
901
+ return this.buffer[this.index - 3];
902
+ }
903
+ get end() {
904
+ return this.buffer[this.index - 2];
905
+ }
906
+ get size() {
907
+ return this.buffer[this.index - 1];
908
+ }
909
+ get pos() {
910
+ return this.index;
911
+ }
912
+ next() {
913
+ this.index -= 4;
914
+ }
915
+ fork() {
916
+ return new FlatBufferCursor(this.buffer, this.index);
917
+ }
918
+ };
919
+ var TreeBuffer = class {
920
+ /// Create a tree buffer.
921
+ constructor(buffer, length, set) {
922
+ this.buffer = buffer;
923
+ this.length = length;
924
+ this.set = set;
925
+ }
926
+ /// @internal
927
+ get type() {
928
+ return NodeType.none;
929
+ }
930
+ /// @internal
931
+ toString() {
932
+ let result = [];
933
+ for (let index = 0; index < this.buffer.length; ) {
934
+ result.push(this.childString(index));
935
+ index = this.buffer[index + 3];
936
+ }
937
+ return result.join(",");
938
+ }
939
+ /// @internal
940
+ childString(index) {
941
+ let id = this.buffer[index], endIndex = this.buffer[index + 3];
942
+ let type = this.set.types[id], result = type.name;
943
+ if (/\W/.test(result) && !type.isError)
944
+ result = JSON.stringify(result);
945
+ index += 4;
946
+ if (endIndex == index)
947
+ return result;
948
+ let children = [];
949
+ while (index < endIndex) {
950
+ children.push(this.childString(index));
951
+ index = this.buffer[index + 3];
952
+ }
953
+ return result + "(" + children.join(",") + ")";
954
+ }
955
+ /// @internal
956
+ findChild(startIndex, endIndex, dir, pos, side) {
957
+ let { buffer } = this, pick = -1;
958
+ for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
959
+ if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
960
+ pick = i;
961
+ if (dir > 0)
962
+ break;
963
+ }
964
+ }
965
+ return pick;
966
+ }
967
+ /// @internal
968
+ slice(startI, endI, from) {
969
+ let b = this.buffer;
970
+ let copy = new Uint16Array(endI - startI), len = 0;
971
+ for (let i = startI, j = 0; i < endI; ) {
972
+ copy[j++] = b[i++];
973
+ copy[j++] = b[i++] - from;
974
+ let to = copy[j++] = b[i++] - from;
975
+ copy[j++] = b[i++] - startI;
976
+ len = Math.max(len, to);
977
+ }
978
+ return new TreeBuffer(copy, len, this.set);
979
+ }
980
+ };
981
+ function checkSide(side, pos, from, to) {
982
+ switch (side) {
983
+ case -2:
984
+ return from < pos;
985
+ case -1:
986
+ return to >= pos && from < pos;
987
+ case 0:
988
+ return from < pos && to > pos;
989
+ case 1:
990
+ return from <= pos && to > pos;
991
+ case 2:
992
+ return to > pos;
993
+ case 4:
994
+ return true;
995
+ }
996
+ }
997
+ function enterUnfinishedNodesBefore(node, pos) {
998
+ let scan = node.childBefore(pos);
999
+ while (scan) {
1000
+ let last = scan.lastChild;
1001
+ if (!last || last.to != scan.to)
1002
+ break;
1003
+ if (last.type.isError && last.from == last.to) {
1004
+ node = scan;
1005
+ scan = last.prevSibling;
1006
+ } else {
1007
+ scan = last;
1008
+ }
1009
+ }
1010
+ return node;
1011
+ }
1012
+ function resolveNode(node, pos, side, overlays) {
1013
+ var _a;
1014
+ while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
1015
+ let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
1016
+ if (!parent)
1017
+ return node;
1018
+ node = parent;
1019
+ }
1020
+ let mode = overlays ? 0 : IterMode.IgnoreOverlays;
1021
+ if (overlays)
1022
+ for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
1023
+ if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
1024
+ node = parent;
1025
+ }
1026
+ for (; ; ) {
1027
+ let inner = node.enter(pos, side, mode);
1028
+ if (!inner)
1029
+ return node;
1030
+ node = inner;
1031
+ }
1032
+ }
1033
+ var TreeNode = class {
1034
+ constructor(_tree, from, index, _parent) {
1035
+ this._tree = _tree;
1036
+ this.from = from;
1037
+ this.index = index;
1038
+ this._parent = _parent;
1039
+ }
1040
+ get type() {
1041
+ return this._tree.type;
1042
+ }
1043
+ get name() {
1044
+ return this._tree.type.name;
1045
+ }
1046
+ get to() {
1047
+ return this.from + this._tree.length;
1048
+ }
1049
+ nextChild(i, dir, pos, side, mode = 0) {
1050
+ for (let parent = this; ; ) {
1051
+ for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
1052
+ let next = children[i], start = positions[i] + parent.from;
1053
+ if (!checkSide(side, pos, start, start + next.length))
1054
+ continue;
1055
+ if (next instanceof TreeBuffer) {
1056
+ if (mode & IterMode.ExcludeBuffers)
1057
+ continue;
1058
+ let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
1059
+ if (index > -1)
1060
+ return new BufferNode(new BufferContext(parent, next, i, start), null, index);
1061
+ } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
1062
+ let mounted;
1063
+ if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
1064
+ return new TreeNode(mounted.tree, start, i, parent);
1065
+ let inner = new TreeNode(next, start, i, parent);
1066
+ return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
1067
+ }
1068
+ }
1069
+ if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
1070
+ return null;
1071
+ if (parent.index >= 0)
1072
+ i = parent.index + dir;
1073
+ else
1074
+ i = dir < 0 ? -1 : parent._parent._tree.children.length;
1075
+ parent = parent._parent;
1076
+ if (!parent)
1077
+ return null;
1078
+ }
1079
+ }
1080
+ get firstChild() {
1081
+ return this.nextChild(
1082
+ 0,
1083
+ 1,
1084
+ 0,
1085
+ 4
1086
+ /* Side.DontCare */
1087
+ );
1088
+ }
1089
+ get lastChild() {
1090
+ return this.nextChild(
1091
+ this._tree.children.length - 1,
1092
+ -1,
1093
+ 0,
1094
+ 4
1095
+ /* Side.DontCare */
1096
+ );
1097
+ }
1098
+ childAfter(pos) {
1099
+ return this.nextChild(
1100
+ 0,
1101
+ 1,
1102
+ pos,
1103
+ 2
1104
+ /* Side.After */
1105
+ );
1106
+ }
1107
+ childBefore(pos) {
1108
+ return this.nextChild(
1109
+ this._tree.children.length - 1,
1110
+ -1,
1111
+ pos,
1112
+ -2
1113
+ /* Side.Before */
1114
+ );
1115
+ }
1116
+ enter(pos, side, mode = 0) {
1117
+ let mounted;
1118
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
1119
+ let rPos = pos - this.from;
1120
+ for (let { from, to } of mounted.overlay) {
1121
+ if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
1122
+ return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
1123
+ }
1124
+ }
1125
+ return this.nextChild(0, 1, pos, side, mode);
1126
+ }
1127
+ nextSignificantParent() {
1128
+ let val = this;
1129
+ while (val.type.isAnonymous && val._parent)
1130
+ val = val._parent;
1131
+ return val;
1132
+ }
1133
+ get parent() {
1134
+ return this._parent ? this._parent.nextSignificantParent() : null;
1135
+ }
1136
+ get nextSibling() {
1137
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1138
+ this.index + 1,
1139
+ 1,
1140
+ 0,
1141
+ 4
1142
+ /* Side.DontCare */
1143
+ ) : null;
1144
+ }
1145
+ get prevSibling() {
1146
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1147
+ this.index - 1,
1148
+ -1,
1149
+ 0,
1150
+ 4
1151
+ /* Side.DontCare */
1152
+ ) : null;
1153
+ }
1154
+ cursor(mode = 0) {
1155
+ return new TreeCursor(this, mode);
1156
+ }
1157
+ get tree() {
1158
+ return this._tree;
1159
+ }
1160
+ toTree() {
1161
+ return this._tree;
1162
+ }
1163
+ resolve(pos, side = 0) {
1164
+ return resolveNode(this, pos, side, false);
1165
+ }
1166
+ resolveInner(pos, side = 0) {
1167
+ return resolveNode(this, pos, side, true);
1168
+ }
1169
+ enterUnfinishedNodesBefore(pos) {
1170
+ return enterUnfinishedNodesBefore(this, pos);
1171
+ }
1172
+ getChild(type, before = null, after = null) {
1173
+ let r2 = getChildren(this, type, before, after);
1174
+ return r2.length ? r2[0] : null;
1175
+ }
1176
+ getChildren(type, before = null, after = null) {
1177
+ return getChildren(this, type, before, after);
1178
+ }
1179
+ /// @internal
1180
+ toString() {
1181
+ return this._tree.toString();
1182
+ }
1183
+ get node() {
1184
+ return this;
1185
+ }
1186
+ matchContext(context) {
1187
+ return matchNodeContext(this, context);
1188
+ }
1189
+ };
1190
+ function getChildren(node, type, before, after) {
1191
+ let cur = node.cursor(), result = [];
1192
+ if (!cur.firstChild())
1193
+ return result;
1194
+ if (before != null) {
1195
+ while (!cur.type.is(before))
1196
+ if (!cur.nextSibling())
1197
+ return result;
1198
+ }
1199
+ for (; ; ) {
1200
+ if (after != null && cur.type.is(after))
1201
+ return result;
1202
+ if (cur.type.is(type))
1203
+ result.push(cur.node);
1204
+ if (!cur.nextSibling())
1205
+ return after == null ? result : [];
1206
+ }
1207
+ }
1208
+ function matchNodeContext(node, context, i = context.length - 1) {
1209
+ for (let p = node.parent; i >= 0; p = p.parent) {
1210
+ if (!p)
1211
+ return false;
1212
+ if (!p.type.isAnonymous) {
1213
+ if (context[i] && context[i] != p.name)
1214
+ return false;
1215
+ i--;
1216
+ }
1217
+ }
1218
+ return true;
1219
+ }
1220
+ var BufferContext = class {
1221
+ constructor(parent, buffer, index, start) {
1222
+ this.parent = parent;
1223
+ this.buffer = buffer;
1224
+ this.index = index;
1225
+ this.start = start;
1226
+ }
1227
+ };
1228
+ var BufferNode = class {
1229
+ get name() {
1230
+ return this.type.name;
1231
+ }
1232
+ get from() {
1233
+ return this.context.start + this.context.buffer.buffer[this.index + 1];
1234
+ }
1235
+ get to() {
1236
+ return this.context.start + this.context.buffer.buffer[this.index + 2];
1237
+ }
1238
+ constructor(context, _parent, index) {
1239
+ this.context = context;
1240
+ this._parent = _parent;
1241
+ this.index = index;
1242
+ this.type = context.buffer.set.types[context.buffer.buffer[index]];
1243
+ }
1244
+ child(dir, pos, side) {
1245
+ let { buffer } = this.context;
1246
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
1247
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1248
+ }
1249
+ get firstChild() {
1250
+ return this.child(
1251
+ 1,
1252
+ 0,
1253
+ 4
1254
+ /* Side.DontCare */
1255
+ );
1256
+ }
1257
+ get lastChild() {
1258
+ return this.child(
1259
+ -1,
1260
+ 0,
1261
+ 4
1262
+ /* Side.DontCare */
1263
+ );
1264
+ }
1265
+ childAfter(pos) {
1266
+ return this.child(
1267
+ 1,
1268
+ pos,
1269
+ 2
1270
+ /* Side.After */
1271
+ );
1272
+ }
1273
+ childBefore(pos) {
1274
+ return this.child(
1275
+ -1,
1276
+ pos,
1277
+ -2
1278
+ /* Side.Before */
1279
+ );
1280
+ }
1281
+ enter(pos, side, mode = 0) {
1282
+ if (mode & IterMode.ExcludeBuffers)
1283
+ return null;
1284
+ let { buffer } = this.context;
1285
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
1286
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1287
+ }
1288
+ get parent() {
1289
+ return this._parent || this.context.parent.nextSignificantParent();
1290
+ }
1291
+ externalSibling(dir) {
1292
+ return this._parent ? null : this.context.parent.nextChild(
1293
+ this.context.index + dir,
1294
+ dir,
1295
+ 0,
1296
+ 4
1297
+ /* Side.DontCare */
1298
+ );
1299
+ }
1300
+ get nextSibling() {
1301
+ let { buffer } = this.context;
1302
+ let after = buffer.buffer[this.index + 3];
1303
+ if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
1304
+ return new BufferNode(this.context, this._parent, after);
1305
+ return this.externalSibling(1);
1306
+ }
1307
+ get prevSibling() {
1308
+ let { buffer } = this.context;
1309
+ let parentStart = this._parent ? this._parent.index + 4 : 0;
1310
+ if (this.index == parentStart)
1311
+ return this.externalSibling(-1);
1312
+ return new BufferNode(this.context, this._parent, buffer.findChild(
1313
+ parentStart,
1314
+ this.index,
1315
+ -1,
1316
+ 0,
1317
+ 4
1318
+ /* Side.DontCare */
1319
+ ));
1320
+ }
1321
+ cursor(mode = 0) {
1322
+ return new TreeCursor(this, mode);
1323
+ }
1324
+ get tree() {
1325
+ return null;
1326
+ }
1327
+ toTree() {
1328
+ let children = [], positions = [];
1329
+ let { buffer } = this.context;
1330
+ let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
1331
+ if (endI > startI) {
1332
+ let from = buffer.buffer[this.index + 1];
1333
+ children.push(buffer.slice(startI, endI, from));
1334
+ positions.push(0);
1335
+ }
1336
+ return new Tree(this.type, children, positions, this.to - this.from);
1337
+ }
1338
+ resolve(pos, side = 0) {
1339
+ return resolveNode(this, pos, side, false);
1340
+ }
1341
+ resolveInner(pos, side = 0) {
1342
+ return resolveNode(this, pos, side, true);
1343
+ }
1344
+ enterUnfinishedNodesBefore(pos) {
1345
+ return enterUnfinishedNodesBefore(this, pos);
1346
+ }
1347
+ /// @internal
1348
+ toString() {
1349
+ return this.context.buffer.childString(this.index);
1350
+ }
1351
+ getChild(type, before = null, after = null) {
1352
+ let r2 = getChildren(this, type, before, after);
1353
+ return r2.length ? r2[0] : null;
1354
+ }
1355
+ getChildren(type, before = null, after = null) {
1356
+ return getChildren(this, type, before, after);
1357
+ }
1358
+ get node() {
1359
+ return this;
1360
+ }
1361
+ matchContext(context) {
1362
+ return matchNodeContext(this, context);
1363
+ }
1364
+ };
1365
+ var TreeCursor = class {
1366
+ /// Shorthand for `.type.name`.
1367
+ get name() {
1368
+ return this.type.name;
1369
+ }
1370
+ /// @internal
1371
+ constructor(node, mode = 0) {
1372
+ this.mode = mode;
1373
+ this.buffer = null;
1374
+ this.stack = [];
1375
+ this.index = 0;
1376
+ this.bufferNode = null;
1377
+ if (node instanceof TreeNode) {
1378
+ this.yieldNode(node);
1379
+ } else {
1380
+ this._tree = node.context.parent;
1381
+ this.buffer = node.context;
1382
+ for (let n = node._parent; n; n = n._parent)
1383
+ this.stack.unshift(n.index);
1384
+ this.bufferNode = node;
1385
+ this.yieldBuf(node.index);
1386
+ }
1387
+ }
1388
+ yieldNode(node) {
1389
+ if (!node)
1390
+ return false;
1391
+ this._tree = node;
1392
+ this.type = node.type;
1393
+ this.from = node.from;
1394
+ this.to = node.to;
1395
+ return true;
1396
+ }
1397
+ yieldBuf(index, type) {
1398
+ this.index = index;
1399
+ let { start, buffer } = this.buffer;
1400
+ this.type = type || buffer.set.types[buffer.buffer[index]];
1401
+ this.from = start + buffer.buffer[index + 1];
1402
+ this.to = start + buffer.buffer[index + 2];
1403
+ return true;
1404
+ }
1405
+ yield(node) {
1406
+ if (!node)
1407
+ return false;
1408
+ if (node instanceof TreeNode) {
1409
+ this.buffer = null;
1410
+ return this.yieldNode(node);
1411
+ }
1412
+ this.buffer = node.context;
1413
+ return this.yieldBuf(node.index, node.type);
1414
+ }
1415
+ /// @internal
1416
+ toString() {
1417
+ return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
1418
+ }
1419
+ /// @internal
1420
+ enterChild(dir, pos, side) {
1421
+ if (!this.buffer)
1422
+ return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
1423
+ let { buffer } = this.buffer;
1424
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
1425
+ if (index < 0)
1426
+ return false;
1427
+ this.stack.push(this.index);
1428
+ return this.yieldBuf(index);
1429
+ }
1430
+ /// Move the cursor to this node's first child. When this returns
1431
+ /// false, the node has no child, and the cursor has not been moved.
1432
+ firstChild() {
1433
+ return this.enterChild(
1434
+ 1,
1435
+ 0,
1436
+ 4
1437
+ /* Side.DontCare */
1438
+ );
1439
+ }
1440
+ /// Move the cursor to this node's last child.
1441
+ lastChild() {
1442
+ return this.enterChild(
1443
+ -1,
1444
+ 0,
1445
+ 4
1446
+ /* Side.DontCare */
1447
+ );
1448
+ }
1449
+ /// Move the cursor to the first child that ends after `pos`.
1450
+ childAfter(pos) {
1451
+ return this.enterChild(
1452
+ 1,
1453
+ pos,
1454
+ 2
1455
+ /* Side.After */
1456
+ );
1457
+ }
1458
+ /// Move to the last child that starts before `pos`.
1459
+ childBefore(pos) {
1460
+ return this.enterChild(
1461
+ -1,
1462
+ pos,
1463
+ -2
1464
+ /* Side.Before */
1465
+ );
1466
+ }
1467
+ /// Move the cursor to the child around `pos`. If side is -1 the
1468
+ /// child may end at that position, when 1 it may start there. This
1469
+ /// will also enter [overlaid](#common.MountedTree.overlay)
1470
+ /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
1471
+ /// set to false.
1472
+ enter(pos, side, mode = this.mode) {
1473
+ if (!this.buffer)
1474
+ return this.yield(this._tree.enter(pos, side, mode));
1475
+ return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
1476
+ }
1477
+ /// Move to the node's parent node, if this isn't the top node.
1478
+ parent() {
1479
+ if (!this.buffer)
1480
+ return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
1481
+ if (this.stack.length)
1482
+ return this.yieldBuf(this.stack.pop());
1483
+ let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
1484
+ this.buffer = null;
1485
+ return this.yieldNode(parent);
1486
+ }
1487
+ /// @internal
1488
+ sibling(dir) {
1489
+ if (!this.buffer)
1490
+ 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));
1491
+ let { buffer } = this.buffer, d = this.stack.length - 1;
1492
+ if (dir < 0) {
1493
+ let parentStart = d < 0 ? 0 : this.stack[d] + 4;
1494
+ if (this.index != parentStart)
1495
+ return this.yieldBuf(buffer.findChild(
1496
+ parentStart,
1497
+ this.index,
1498
+ -1,
1499
+ 0,
1500
+ 4
1501
+ /* Side.DontCare */
1502
+ ));
1503
+ } else {
1504
+ let after = buffer.buffer[this.index + 3];
1505
+ if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
1506
+ return this.yieldBuf(after);
1507
+ }
1508
+ return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
1509
+ }
1510
+ /// Move to this node's next sibling, if any.
1511
+ nextSibling() {
1512
+ return this.sibling(1);
1513
+ }
1514
+ /// Move to this node's previous sibling, if any.
1515
+ prevSibling() {
1516
+ return this.sibling(-1);
1517
+ }
1518
+ atLastNode(dir) {
1519
+ let index, parent, { buffer } = this;
1520
+ if (buffer) {
1521
+ if (dir > 0) {
1522
+ if (this.index < buffer.buffer.buffer.length)
1523
+ return false;
1524
+ } else {
1525
+ for (let i = 0; i < this.index; i++)
1526
+ if (buffer.buffer.buffer[i + 3] < this.index)
1527
+ return false;
1528
+ }
1529
+ ({ index, parent } = buffer);
1530
+ } else {
1531
+ ({ index, _parent: parent } = this._tree);
1532
+ }
1533
+ for (; parent; { index, _parent: parent } = parent) {
1534
+ if (index > -1)
1535
+ for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
1536
+ let child = parent._tree.children[i];
1537
+ if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
1538
+ return false;
1539
+ }
1540
+ }
1541
+ return true;
1542
+ }
1543
+ move(dir, enter) {
1544
+ if (enter && this.enterChild(
1545
+ dir,
1546
+ 0,
1547
+ 4
1548
+ /* Side.DontCare */
1549
+ ))
1550
+ return true;
1551
+ for (; ; ) {
1552
+ if (this.sibling(dir))
1553
+ return true;
1554
+ if (this.atLastNode(dir) || !this.parent())
1555
+ return false;
1556
+ }
1557
+ }
1558
+ /// Move to the next node in a
1559
+ /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1560
+ /// traversal, going from a node to its first child or, if the
1561
+ /// current node is empty or `enter` is false, its next sibling or
1562
+ /// the next sibling of the first parent node that has one.
1563
+ next(enter = true) {
1564
+ return this.move(1, enter);
1565
+ }
1566
+ /// Move to the next node in a last-to-first pre-order traveral. A
1567
+ /// node is followed by its last child or, if it has none, its
1568
+ /// previous sibling or the previous sibling of the first parent
1569
+ /// node that has one.
1570
+ prev(enter = true) {
1571
+ return this.move(-1, enter);
1572
+ }
1573
+ /// Move the cursor to the innermost node that covers `pos`. If
1574
+ /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1575
+ /// it will enter nodes that start at `pos`.
1576
+ moveTo(pos, side = 0) {
1577
+ while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
1578
+ if (!this.parent())
1579
+ break;
1580
+ while (this.enterChild(1, pos, side)) {
1581
+ }
1582
+ return this;
1583
+ }
1584
+ /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
1585
+ /// position.
1586
+ get node() {
1587
+ if (!this.buffer)
1588
+ return this._tree;
1589
+ let cache = this.bufferNode, result = null, depth = 0;
1590
+ if (cache && cache.context == this.buffer) {
1591
+ scan:
1592
+ for (let index = this.index, d = this.stack.length; d >= 0; ) {
1593
+ for (let c = cache; c; c = c._parent)
1594
+ if (c.index == index) {
1595
+ if (index == this.index)
1596
+ return c;
1597
+ result = c;
1598
+ depth = d + 1;
1599
+ break scan;
1600
+ }
1601
+ index = this.stack[--d];
1602
+ }
1603
+ }
1604
+ for (let i = depth; i < this.stack.length; i++)
1605
+ result = new BufferNode(this.buffer, result, this.stack[i]);
1606
+ return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1607
+ }
1608
+ /// Get the [tree](#common.Tree) that represents the current node, if
1609
+ /// any. Will return null when the node is in a [tree
1610
+ /// buffer](#common.TreeBuffer).
1611
+ get tree() {
1612
+ return this.buffer ? null : this._tree._tree;
1613
+ }
1614
+ /// Iterate over the current node and all its descendants, calling
1615
+ /// `enter` when entering a node and `leave`, if given, when leaving
1616
+ /// one. When `enter` returns `false`, any children of that node are
1617
+ /// skipped, and `leave` isn't called for it.
1618
+ iterate(enter, leave) {
1619
+ for (let depth = 0; ; ) {
1620
+ let mustLeave = false;
1621
+ if (this.type.isAnonymous || enter(this) !== false) {
1622
+ if (this.firstChild()) {
1623
+ depth++;
1624
+ continue;
1625
+ }
1626
+ if (!this.type.isAnonymous)
1627
+ mustLeave = true;
1628
+ }
1629
+ for (; ; ) {
1630
+ if (mustLeave && leave)
1631
+ leave(this);
1632
+ mustLeave = this.type.isAnonymous;
1633
+ if (this.nextSibling())
1634
+ break;
1635
+ if (!depth)
1636
+ return;
1637
+ this.parent();
1638
+ depth--;
1639
+ mustLeave = true;
1640
+ }
1641
+ }
1642
+ }
1643
+ /// Test whether the current node matches a given context—a sequence
1644
+ /// of direct parent node names. Empty strings in the context array
1645
+ /// are treated as wildcards.
1646
+ matchContext(context) {
1647
+ if (!this.buffer)
1648
+ return matchNodeContext(this.node, context);
1649
+ let { buffer } = this.buffer, { types } = buffer.set;
1650
+ for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
1651
+ if (d < 0)
1652
+ return matchNodeContext(this.node, context, i);
1653
+ let type = types[buffer.buffer[this.stack[d]]];
1654
+ if (!type.isAnonymous) {
1655
+ if (context[i] && context[i] != type.name)
1656
+ return false;
1657
+ i--;
1658
+ }
1659
+ }
1660
+ return true;
1661
+ }
1662
+ };
1663
+ function hasChild(tree) {
1664
+ return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
1665
+ }
1666
+ function buildTree(data) {
1667
+ var _a;
1668
+ let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
1669
+ let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
1670
+ let types = nodeSet.types;
1671
+ let contextHash = 0, lookAhead = 0;
1672
+ function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
1673
+ let { id, start, end, size } = cursor;
1674
+ let lookAheadAtStart = lookAhead;
1675
+ while (size < 0) {
1676
+ cursor.next();
1677
+ if (size == -1) {
1678
+ let node2 = reused[id];
1679
+ children2.push(node2);
1680
+ positions2.push(start - parentStart);
1681
+ return;
1682
+ } else if (size == -3) {
1683
+ contextHash = id;
1684
+ return;
1685
+ } else if (size == -4) {
1686
+ lookAhead = id;
1687
+ return;
1688
+ } else {
1689
+ throw new RangeError(`Unrecognized record size: ${size}`);
1690
+ }
1691
+ }
1692
+ let type = types[id], node, buffer2;
1693
+ let startPos = start - parentStart;
1694
+ if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
1695
+ let data2 = new Uint16Array(buffer2.size - buffer2.skip);
1696
+ let endPos = cursor.pos - buffer2.size, index = data2.length;
1697
+ while (cursor.pos > endPos)
1698
+ index = copyToBuffer(buffer2.start, data2, index);
1699
+ node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
1700
+ startPos = buffer2.start - parentStart;
1701
+ } else {
1702
+ let endPos = cursor.pos - size;
1703
+ cursor.next();
1704
+ let localChildren = [], localPositions = [];
1705
+ let localInRepeat = id >= minRepeatType ? id : -1;
1706
+ let lastGroup = 0, lastEnd = end;
1707
+ while (cursor.pos > endPos) {
1708
+ if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
1709
+ if (cursor.end <= lastEnd - maxBufferLength) {
1710
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
1711
+ lastGroup = localChildren.length;
1712
+ lastEnd = cursor.end;
1713
+ }
1714
+ cursor.next();
1715
+ } else {
1716
+ takeNode(start, endPos, localChildren, localPositions, localInRepeat);
1717
+ }
1718
+ }
1719
+ if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
1720
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
1721
+ localChildren.reverse();
1722
+ localPositions.reverse();
1723
+ if (localInRepeat > -1 && lastGroup > 0) {
1724
+ let make = makeBalanced(type);
1725
+ node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
1726
+ } else {
1727
+ node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
1728
+ }
1729
+ }
1730
+ children2.push(node);
1731
+ positions2.push(startPos);
1732
+ }
1733
+ function makeBalanced(type) {
1734
+ return (children2, positions2, length2) => {
1735
+ let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
1736
+ if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
1737
+ if (!lastI && last.type == type && last.length == length2)
1738
+ return last;
1739
+ if (lookAheadProp = last.prop(NodeProp.lookAhead))
1740
+ lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
1741
+ }
1742
+ return makeTree(type, children2, positions2, length2, lookAhead2);
1743
+ };
1744
+ }
1745
+ function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
1746
+ let localChildren = [], localPositions = [];
1747
+ while (children2.length > i) {
1748
+ localChildren.push(children2.pop());
1749
+ localPositions.push(positions2.pop() + base - from);
1750
+ }
1751
+ children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
1752
+ positions2.push(from - base);
1753
+ }
1754
+ function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
1755
+ if (contextHash) {
1756
+ let pair2 = [NodeProp.contextHash, contextHash];
1757
+ props = props ? [pair2].concat(props) : [pair2];
1758
+ }
1759
+ if (lookAhead2 > 25) {
1760
+ let pair2 = [NodeProp.lookAhead, lookAhead2];
1761
+ props = props ? [pair2].concat(props) : [pair2];
1762
+ }
1763
+ return new Tree(type, children2, positions2, length2, props);
1764
+ }
1765
+ function findBufferSize(maxSize, inRepeat) {
1766
+ let fork = cursor.fork();
1767
+ let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
1768
+ let result = { size: 0, start: 0, skip: 0 };
1769
+ scan:
1770
+ for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
1771
+ let nodeSize2 = fork.size;
1772
+ if (fork.id == inRepeat && nodeSize2 >= 0) {
1773
+ result.size = size;
1774
+ result.start = start;
1775
+ result.skip = skip;
1776
+ skip += 4;
1777
+ size += 4;
1778
+ fork.next();
1779
+ continue;
1780
+ }
1781
+ let startPos = fork.pos - nodeSize2;
1782
+ if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
1783
+ break;
1784
+ let localSkipped = fork.id >= minRepeatType ? 4 : 0;
1785
+ let nodeStart = fork.start;
1786
+ fork.next();
1787
+ while (fork.pos > startPos) {
1788
+ if (fork.size < 0) {
1789
+ if (fork.size == -3)
1790
+ localSkipped += 4;
1791
+ else
1792
+ break scan;
1793
+ } else if (fork.id >= minRepeatType) {
1794
+ localSkipped += 4;
1795
+ }
1796
+ fork.next();
1797
+ }
1798
+ start = nodeStart;
1799
+ size += nodeSize2;
1800
+ skip += localSkipped;
1801
+ }
1802
+ if (inRepeat < 0 || size == maxSize) {
1803
+ result.size = size;
1804
+ result.start = start;
1805
+ result.skip = skip;
1806
+ }
1807
+ return result.size > 4 ? result : void 0;
1808
+ }
1809
+ function copyToBuffer(bufferStart, buffer2, index) {
1810
+ let { id, start, end, size } = cursor;
1811
+ cursor.next();
1812
+ if (size >= 0 && id < minRepeatType) {
1813
+ let startIndex = index;
1814
+ if (size > 4) {
1815
+ let endPos = cursor.pos - (size - 4);
1816
+ while (cursor.pos > endPos)
1817
+ index = copyToBuffer(bufferStart, buffer2, index);
1818
+ }
1819
+ buffer2[--index] = startIndex;
1820
+ buffer2[--index] = end - bufferStart;
1821
+ buffer2[--index] = start - bufferStart;
1822
+ buffer2[--index] = id;
1823
+ } else if (size == -3) {
1824
+ contextHash = id;
1825
+ } else if (size == -4) {
1826
+ lookAhead = id;
1827
+ }
1828
+ return index;
1829
+ }
1830
+ let children = [], positions = [];
1831
+ while (cursor.pos > 0)
1832
+ takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
1833
+ let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
1834
+ return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
1835
+ }
1836
+ var nodeSizeCache = /* @__PURE__ */ new WeakMap();
1837
+ function nodeSize(balanceType, node) {
1838
+ if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
1839
+ return 1;
1840
+ let size = nodeSizeCache.get(node);
1841
+ if (size == null) {
1842
+ size = 1;
1843
+ for (let child of node.children) {
1844
+ if (child.type != balanceType || !(child instanceof Tree)) {
1845
+ size = 1;
1846
+ break;
1847
+ }
1848
+ size += nodeSize(balanceType, child);
1849
+ }
1850
+ nodeSizeCache.set(node, size);
1851
+ }
1852
+ return size;
1853
+ }
1854
+ function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
1855
+ let total = 0;
1856
+ for (let i = from; i < to; i++)
1857
+ total += nodeSize(balanceType, children[i]);
1858
+ let maxChild = Math.ceil(
1859
+ total * 1.5 / 8
1860
+ /* Balance.BranchFactor */
1861
+ );
1862
+ let localChildren = [], localPositions = [];
1863
+ function divide(children2, positions2, from2, to2, offset) {
1864
+ for (let i = from2; i < to2; ) {
1865
+ let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
1866
+ i++;
1867
+ for (; i < to2; i++) {
1868
+ let nextSize = nodeSize(balanceType, children2[i]);
1869
+ if (groupSize + nextSize >= maxChild)
1870
+ break;
1871
+ groupSize += nextSize;
1872
+ }
1873
+ if (i == groupFrom + 1) {
1874
+ if (groupSize > maxChild) {
1875
+ let only = children2[groupFrom];
1876
+ divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
1877
+ continue;
1878
+ }
1879
+ localChildren.push(children2[groupFrom]);
1880
+ } else {
1881
+ let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
1882
+ localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
1883
+ }
1884
+ localPositions.push(groupStart + offset - start);
1885
+ }
1886
+ }
1887
+ divide(children, positions, from, to, 0);
1888
+ return (mkTop || mkTree)(localChildren, localPositions, length);
1889
+ }
1890
+ var Parser = class {
1891
+ /// Start a parse, returning a [partial parse](#common.PartialParse)
1892
+ /// object. [`fragments`](#common.TreeFragment) can be passed in to
1893
+ /// make the parse incremental.
1894
+ ///
1895
+ /// By default, the entire input is parsed. You can pass `ranges`,
1896
+ /// which should be a sorted array of non-empty, non-overlapping
1897
+ /// ranges, to parse only those ranges. The tree returned in that
1898
+ /// case will start at `ranges[0].from`.
1899
+ startParse(input, fragments, ranges) {
1900
+ if (typeof input == "string")
1901
+ input = new StringInput(input);
1902
+ ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r2) => new Range(r2.from, r2.to)) : [new Range(0, 0)];
1903
+ return this.createParse(input, fragments || [], ranges);
1904
+ }
1905
+ /// Run a full parse, returning the resulting tree.
1906
+ parse(input, fragments, ranges) {
1907
+ let parse = this.startParse(input, fragments, ranges);
1908
+ for (; ; ) {
1909
+ let done = parse.advance();
1910
+ if (done)
1911
+ return done;
1912
+ }
1913
+ }
1914
+ };
1915
+ var StringInput = class {
1916
+ constructor(string) {
1917
+ this.string = string;
1918
+ }
1919
+ get length() {
1920
+ return this.string.length;
1921
+ }
1922
+ chunk(from) {
1923
+ return this.string.slice(from);
1924
+ }
1925
+ get lineChunks() {
1926
+ return false;
1927
+ }
1928
+ read(from, to) {
1929
+ return this.string.slice(from, to);
1930
+ }
1931
+ };
1932
+ var stoppedInner = new NodeProp({ perNode: true });
1933
+
1934
+ // ../../node_modules/@lezer/lr/dist/index.js
1935
+ var Stack = class {
1936
+ /// @internal
1937
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
1938
+ this.p = p;
1939
+ this.stack = stack;
1940
+ this.state = state;
1941
+ this.reducePos = reducePos;
1942
+ this.pos = pos;
1943
+ this.score = score;
1944
+ this.buffer = buffer;
1945
+ this.bufferBase = bufferBase;
1946
+ this.curContext = curContext;
1947
+ this.lookAhead = lookAhead;
1948
+ this.parent = parent;
1949
+ }
1950
+ /// @internal
1951
+ toString() {
1952
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
1953
+ }
1954
+ // Start an empty stack
1955
+ /// @internal
1956
+ static start(p, state, pos = 0) {
1957
+ let cx3 = p.parser.context;
1958
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx3 ? new StackContext(cx3, cx3.start) : null, 0, null);
1959
+ }
1960
+ /// The stack's current [context](#lr.ContextTracker) value, if
1961
+ /// any. Its type will depend on the context tracker's type
1962
+ /// parameter, or it will be `null` if there is no context
1963
+ /// tracker.
1964
+ get context() {
1965
+ return this.curContext ? this.curContext.context : null;
1966
+ }
1967
+ // Push a state onto the stack, tracking its start position as well
1968
+ // as the buffer base at that point.
1969
+ /// @internal
1970
+ pushState(state, start) {
1971
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
1972
+ this.state = state;
1973
+ }
1974
+ // Apply a reduce action
1975
+ /// @internal
1976
+ reduce(action) {
1977
+ var _a;
1978
+ let depth = action >> 19, type = action & 65535;
1979
+ let { parser: parser2 } = this.p;
1980
+ let dPrec = parser2.dynamicPrecedence(type);
1981
+ if (dPrec)
1982
+ this.score += dPrec;
1983
+ if (depth == 0) {
1984
+ this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
1985
+ if (type < parser2.minRepeatTerm)
1986
+ this.storeNode(type, this.reducePos, this.reducePos, 4, true);
1987
+ this.reduceContext(type, this.reducePos);
1988
+ return;
1989
+ }
1990
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
1991
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
1992
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
1993
+ if (start == this.p.lastBigReductionStart) {
1994
+ this.p.bigReductionCount++;
1995
+ this.p.lastBigReductionSize = size;
1996
+ } else if (this.p.lastBigReductionSize < size) {
1997
+ this.p.bigReductionCount = 1;
1998
+ this.p.lastBigReductionStart = start;
1999
+ this.p.lastBigReductionSize = size;
2000
+ }
2001
+ }
2002
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
2003
+ if (type < parser2.minRepeatTerm || action & 131072) {
2004
+ let pos = parser2.stateFlag(
2005
+ this.state,
2006
+ 1
2007
+ /* StateFlag.Skipped */
2008
+ ) ? this.pos : this.reducePos;
2009
+ this.storeNode(type, start, pos, count + 4, true);
2010
+ }
2011
+ if (action & 262144) {
2012
+ this.state = this.stack[base];
2013
+ } else {
2014
+ let baseStateID = this.stack[base - 3];
2015
+ this.state = parser2.getGoto(baseStateID, type, true);
2016
+ }
2017
+ while (this.stack.length > base)
2018
+ this.stack.pop();
2019
+ this.reduceContext(type, start);
2020
+ }
2021
+ // Shift a value into the buffer
2022
+ /// @internal
2023
+ storeNode(term, start, end, size = 4, isReduce = false) {
2024
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
2025
+ let cur = this, top = this.buffer.length;
2026
+ if (top == 0 && cur.parent) {
2027
+ top = cur.bufferBase - cur.parent.bufferBase;
2028
+ cur = cur.parent;
2029
+ }
2030
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
2031
+ if (start == end)
2032
+ return;
2033
+ if (cur.buffer[top - 2] >= start) {
2034
+ cur.buffer[top - 2] = end;
2035
+ return;
2036
+ }
2037
+ }
2038
+ }
2039
+ if (!isReduce || this.pos == end) {
2040
+ this.buffer.push(term, start, end, size);
2041
+ } else {
2042
+ let index = this.buffer.length;
2043
+ if (index > 0 && this.buffer[index - 4] != 0)
2044
+ while (index > 0 && this.buffer[index - 2] > end) {
2045
+ this.buffer[index] = this.buffer[index - 4];
2046
+ this.buffer[index + 1] = this.buffer[index - 3];
2047
+ this.buffer[index + 2] = this.buffer[index - 2];
2048
+ this.buffer[index + 3] = this.buffer[index - 1];
2049
+ index -= 4;
2050
+ if (size > 4)
2051
+ size -= 4;
2052
+ }
2053
+ this.buffer[index] = term;
2054
+ this.buffer[index + 1] = start;
2055
+ this.buffer[index + 2] = end;
2056
+ this.buffer[index + 3] = size;
2057
+ }
2058
+ }
2059
+ // Apply a shift action
2060
+ /// @internal
2061
+ shift(action, next, nextEnd) {
2062
+ let start = this.pos;
2063
+ if (action & 131072) {
2064
+ this.pushState(action & 65535, this.pos);
2065
+ } else if ((action & 262144) == 0) {
2066
+ let nextState = action, { parser: parser2 } = this.p;
2067
+ if (nextEnd > this.pos || next <= parser2.maxNode) {
2068
+ this.pos = nextEnd;
2069
+ if (!parser2.stateFlag(
2070
+ nextState,
2071
+ 1
2072
+ /* StateFlag.Skipped */
2073
+ ))
2074
+ this.reducePos = nextEnd;
2075
+ }
2076
+ this.pushState(nextState, start);
2077
+ this.shiftContext(next, start);
2078
+ if (next <= parser2.maxNode)
2079
+ this.buffer.push(next, start, nextEnd, 4);
2080
+ } else {
2081
+ this.pos = nextEnd;
2082
+ this.shiftContext(next, start);
2083
+ if (next <= this.p.parser.maxNode)
2084
+ this.buffer.push(next, start, nextEnd, 4);
2085
+ }
2086
+ }
2087
+ // Apply an action
2088
+ /// @internal
2089
+ apply(action, next, nextEnd) {
2090
+ if (action & 65536)
2091
+ this.reduce(action);
2092
+ else
2093
+ this.shift(action, next, nextEnd);
2094
+ }
2095
+ // Add a prebuilt (reused) node into the buffer.
2096
+ /// @internal
2097
+ useNode(value, next) {
2098
+ let index = this.p.reused.length - 1;
2099
+ if (index < 0 || this.p.reused[index] != value) {
2100
+ this.p.reused.push(value);
2101
+ index++;
2102
+ }
2103
+ let start = this.pos;
2104
+ this.reducePos = this.pos = start + value.length;
2105
+ this.pushState(next, start);
2106
+ this.buffer.push(
2107
+ index,
2108
+ start,
2109
+ this.reducePos,
2110
+ -1
2111
+ /* size == -1 means this is a reused value */
2112
+ );
2113
+ if (this.curContext)
2114
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
2115
+ }
2116
+ // Split the stack. Due to the buffer sharing and the fact
2117
+ // that `this.stack` tends to stay quite shallow, this isn't very
2118
+ // expensive.
2119
+ /// @internal
2120
+ split() {
2121
+ let parent = this;
2122
+ let off = parent.buffer.length;
2123
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
2124
+ off -= 4;
2125
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
2126
+ while (parent && base == parent.bufferBase)
2127
+ parent = parent.parent;
2128
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
2129
+ }
2130
+ // Try to recover from an error by 'deleting' (ignoring) one token.
2131
+ /// @internal
2132
+ recoverByDelete(next, nextEnd) {
2133
+ let isNode = next <= this.p.parser.maxNode;
2134
+ if (isNode)
2135
+ this.storeNode(next, this.pos, nextEnd, 4);
2136
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
2137
+ this.pos = this.reducePos = nextEnd;
2138
+ this.score -= 190;
2139
+ }
2140
+ /// Check if the given term would be able to be shifted (optionally
2141
+ /// after some reductions) on this stack. This can be useful for
2142
+ /// external tokenizers that want to make sure they only provide a
2143
+ /// given token when it applies.
2144
+ canShift(term) {
2145
+ for (let sim = new SimulatedStack(this); ; ) {
2146
+ let action = this.p.parser.stateSlot(
2147
+ sim.state,
2148
+ 4
2149
+ /* ParseState.DefaultReduce */
2150
+ ) || this.p.parser.hasAction(sim.state, term);
2151
+ if (action == 0)
2152
+ return false;
2153
+ if ((action & 65536) == 0)
2154
+ return true;
2155
+ sim.reduce(action);
2156
+ }
2157
+ }
2158
+ // Apply up to Recover.MaxNext recovery actions that conceptually
2159
+ // inserts some missing token or rule.
2160
+ /// @internal
2161
+ recoverByInsert(next) {
2162
+ if (this.stack.length >= 300)
2163
+ return [];
2164
+ let nextStates = this.p.parser.nextStates(this.state);
2165
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
2166
+ let best = [];
2167
+ for (let i = 0, s; i < nextStates.length; i += 2) {
2168
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
2169
+ best.push(nextStates[i], s);
2170
+ }
2171
+ if (this.stack.length < 120)
2172
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
2173
+ let s = nextStates[i + 1];
2174
+ if (!best.some((v, i2) => i2 & 1 && v == s))
2175
+ best.push(nextStates[i], s);
2176
+ }
2177
+ nextStates = best;
2178
+ }
2179
+ let result = [];
2180
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
2181
+ let s = nextStates[i + 1];
2182
+ if (s == this.state)
2183
+ continue;
2184
+ let stack = this.split();
2185
+ stack.pushState(s, this.pos);
2186
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
2187
+ stack.shiftContext(nextStates[i], this.pos);
2188
+ stack.score -= 200;
2189
+ result.push(stack);
2190
+ }
2191
+ return result;
2192
+ }
2193
+ // Force a reduce, if possible. Return false if that can't
2194
+ // be done.
2195
+ /// @internal
2196
+ forceReduce() {
2197
+ let reduce = this.p.parser.stateSlot(
2198
+ this.state,
2199
+ 5
2200
+ /* ParseState.ForcedReduce */
2201
+ );
2202
+ if ((reduce & 65536) == 0)
2203
+ return false;
2204
+ let { parser: parser2 } = this.p;
2205
+ if (!parser2.validAction(this.state, reduce)) {
2206
+ let depth = reduce >> 19, term = reduce & 65535;
2207
+ let target = this.stack.length - depth * 3;
2208
+ if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0)
2209
+ return false;
2210
+ this.storeNode(0, this.reducePos, this.reducePos, 4, true);
2211
+ this.score -= 100;
2212
+ }
2213
+ this.reducePos = this.pos;
2214
+ this.reduce(reduce);
2215
+ return true;
2216
+ }
2217
+ /// @internal
2218
+ forceAll() {
2219
+ while (!this.p.parser.stateFlag(
2220
+ this.state,
2221
+ 2
2222
+ /* StateFlag.Accepting */
2223
+ )) {
2224
+ if (!this.forceReduce()) {
2225
+ this.storeNode(0, this.pos, this.pos, 4, true);
2226
+ break;
2227
+ }
2228
+ }
2229
+ return this;
2230
+ }
2231
+ /// Check whether this state has no further actions (assumed to be a direct descendant of the
2232
+ /// top state, since any other states must be able to continue
2233
+ /// somehow). @internal
2234
+ get deadEnd() {
2235
+ if (this.stack.length != 3)
2236
+ return false;
2237
+ let { parser: parser2 } = this.p;
2238
+ return parser2.data[parser2.stateSlot(
2239
+ this.state,
2240
+ 1
2241
+ /* ParseState.Actions */
2242
+ )] == 65535 && !parser2.stateSlot(
2243
+ this.state,
2244
+ 4
2245
+ /* ParseState.DefaultReduce */
2246
+ );
2247
+ }
2248
+ /// Restart the stack (put it back in its start state). Only safe
2249
+ /// when this.stack.length == 3 (state is directly below the top
2250
+ /// state). @internal
2251
+ restart() {
2252
+ this.state = this.stack[0];
2253
+ this.stack.length = 0;
2254
+ }
2255
+ /// @internal
2256
+ sameState(other) {
2257
+ if (this.state != other.state || this.stack.length != other.stack.length)
2258
+ return false;
2259
+ for (let i = 0; i < this.stack.length; i += 3)
2260
+ if (this.stack[i] != other.stack[i])
2261
+ return false;
2262
+ return true;
2263
+ }
2264
+ /// Get the parser used by this stack.
2265
+ get parser() {
2266
+ return this.p.parser;
2267
+ }
2268
+ /// Test whether a given dialect (by numeric ID, as exported from
2269
+ /// the terms file) is enabled.
2270
+ dialectEnabled(dialectID) {
2271
+ return this.p.parser.dialect.flags[dialectID];
2272
+ }
2273
+ shiftContext(term, start) {
2274
+ if (this.curContext)
2275
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
2276
+ }
2277
+ reduceContext(term, start) {
2278
+ if (this.curContext)
2279
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
2280
+ }
2281
+ /// @internal
2282
+ emitContext() {
2283
+ let last = this.buffer.length - 1;
2284
+ if (last < 0 || this.buffer[last] != -3)
2285
+ this.buffer.push(this.curContext.hash, this.reducePos, this.reducePos, -3);
2286
+ }
2287
+ /// @internal
2288
+ emitLookAhead() {
2289
+ let last = this.buffer.length - 1;
2290
+ if (last < 0 || this.buffer[last] != -4)
2291
+ this.buffer.push(this.lookAhead, this.reducePos, this.reducePos, -4);
2292
+ }
2293
+ updateContext(context) {
2294
+ if (context != this.curContext.context) {
2295
+ let newCx = new StackContext(this.curContext.tracker, context);
2296
+ if (newCx.hash != this.curContext.hash)
2297
+ this.emitContext();
2298
+ this.curContext = newCx;
2299
+ }
2300
+ }
2301
+ /// @internal
2302
+ setLookAhead(lookAhead) {
2303
+ if (lookAhead > this.lookAhead) {
2304
+ this.emitLookAhead();
2305
+ this.lookAhead = lookAhead;
2306
+ }
2307
+ }
2308
+ /// @internal
2309
+ close() {
2310
+ if (this.curContext && this.curContext.tracker.strict)
2311
+ this.emitContext();
2312
+ if (this.lookAhead > 0)
2313
+ this.emitLookAhead();
2314
+ }
2315
+ };
2316
+ var StackContext = class {
2317
+ constructor(tracker, context) {
2318
+ this.tracker = tracker;
2319
+ this.context = context;
2320
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
2321
+ }
2322
+ };
2323
+ var Recover;
2324
+ (function(Recover2) {
2325
+ Recover2[Recover2["Insert"] = 200] = "Insert";
2326
+ Recover2[Recover2["Delete"] = 190] = "Delete";
2327
+ Recover2[Recover2["Reduce"] = 100] = "Reduce";
2328
+ Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
2329
+ Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
2330
+ Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
2331
+ Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
2332
+ })(Recover || (Recover = {}));
2333
+ var SimulatedStack = class {
2334
+ constructor(start) {
2335
+ this.start = start;
2336
+ this.state = start.state;
2337
+ this.stack = start.stack;
2338
+ this.base = this.stack.length;
2339
+ }
2340
+ reduce(action) {
2341
+ let term = action & 65535, depth = action >> 19;
2342
+ if (depth == 0) {
2343
+ if (this.stack == this.start.stack)
2344
+ this.stack = this.stack.slice();
2345
+ this.stack.push(this.state, 0, 0);
2346
+ this.base += 3;
2347
+ } else {
2348
+ this.base -= (depth - 1) * 3;
2349
+ }
2350
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
2351
+ this.state = goto;
2352
+ }
2353
+ };
2354
+ var StackBufferCursor = class {
2355
+ constructor(stack, pos, index) {
2356
+ this.stack = stack;
2357
+ this.pos = pos;
2358
+ this.index = index;
2359
+ this.buffer = stack.buffer;
2360
+ if (this.index == 0)
2361
+ this.maybeNext();
2362
+ }
2363
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
2364
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
2365
+ }
2366
+ maybeNext() {
2367
+ let next = this.stack.parent;
2368
+ if (next != null) {
2369
+ this.index = this.stack.bufferBase - next.bufferBase;
2370
+ this.stack = next;
2371
+ this.buffer = next.buffer;
2372
+ }
2373
+ }
2374
+ get id() {
2375
+ return this.buffer[this.index - 4];
2376
+ }
2377
+ get start() {
2378
+ return this.buffer[this.index - 3];
2379
+ }
2380
+ get end() {
2381
+ return this.buffer[this.index - 2];
2382
+ }
2383
+ get size() {
2384
+ return this.buffer[this.index - 1];
2385
+ }
2386
+ next() {
2387
+ this.index -= 4;
2388
+ this.pos -= 4;
2389
+ if (this.index == 0)
2390
+ this.maybeNext();
2391
+ }
2392
+ fork() {
2393
+ return new StackBufferCursor(this.stack, this.pos, this.index);
2394
+ }
2395
+ };
2396
+ function decodeArray(input, Type = Uint16Array) {
2397
+ if (typeof input != "string")
2398
+ return input;
2399
+ let array = null;
2400
+ for (let pos = 0, out = 0; pos < input.length; ) {
2401
+ let value = 0;
2402
+ for (; ; ) {
2403
+ let next = input.charCodeAt(pos++), stop = false;
2404
+ if (next == 126) {
2405
+ value = 65535;
2406
+ break;
2407
+ }
2408
+ if (next >= 92)
2409
+ next--;
2410
+ if (next >= 34)
2411
+ next--;
2412
+ let digit = next - 32;
2413
+ if (digit >= 46) {
2414
+ digit -= 46;
2415
+ stop = true;
2416
+ }
2417
+ value += digit;
2418
+ if (stop)
2419
+ break;
2420
+ value *= 46;
2421
+ }
2422
+ if (array)
2423
+ array[out++] = value;
2424
+ else
2425
+ array = new Type(value);
2426
+ }
2427
+ return array;
2428
+ }
2429
+ var CachedToken = class {
2430
+ constructor() {
2431
+ this.start = -1;
2432
+ this.value = -1;
2433
+ this.end = -1;
2434
+ this.extended = -1;
2435
+ this.lookAhead = 0;
2436
+ this.mask = 0;
2437
+ this.context = 0;
2438
+ }
2439
+ };
2440
+ var nullToken = new CachedToken();
2441
+ var InputStream = class {
2442
+ /// @internal
2443
+ constructor(input, ranges) {
2444
+ this.input = input;
2445
+ this.ranges = ranges;
2446
+ this.chunk = "";
2447
+ this.chunkOff = 0;
2448
+ this.chunk2 = "";
2449
+ this.chunk2Pos = 0;
2450
+ this.next = -1;
2451
+ this.token = nullToken;
2452
+ this.rangeIndex = 0;
2453
+ this.pos = this.chunkPos = ranges[0].from;
2454
+ this.range = ranges[0];
2455
+ this.end = ranges[ranges.length - 1].to;
2456
+ this.readNext();
2457
+ }
2458
+ /// @internal
2459
+ resolveOffset(offset, assoc) {
2460
+ let range = this.range, index = this.rangeIndex;
2461
+ let pos = this.pos + offset;
2462
+ while (pos < range.from) {
2463
+ if (!index)
2464
+ return null;
2465
+ let next = this.ranges[--index];
2466
+ pos -= range.from - next.to;
2467
+ range = next;
2468
+ }
2469
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
2470
+ if (index == this.ranges.length - 1)
2471
+ return null;
2472
+ let next = this.ranges[++index];
2473
+ pos += next.from - range.to;
2474
+ range = next;
2475
+ }
2476
+ return pos;
2477
+ }
2478
+ /// @internal
2479
+ clipPos(pos) {
2480
+ if (pos >= this.range.from && pos < this.range.to)
2481
+ return pos;
2482
+ for (let range of this.ranges)
2483
+ if (range.to > pos)
2484
+ return Math.max(pos, range.from);
2485
+ return this.end;
2486
+ }
2487
+ /// Look at a code unit near the stream position. `.peek(0)` equals
2488
+ /// `.next`, `.peek(-1)` gives you the previous character, and so
2489
+ /// on.
2490
+ ///
2491
+ /// Note that looking around during tokenizing creates dependencies
2492
+ /// on potentially far-away content, which may reduce the
2493
+ /// effectiveness incremental parsing—when looking forward—or even
2494
+ /// cause invalid reparses when looking backward more than 25 code
2495
+ /// units, since the library does not track lookbehind.
2496
+ peek(offset) {
2497
+ let idx = this.chunkOff + offset, pos, result;
2498
+ if (idx >= 0 && idx < this.chunk.length) {
2499
+ pos = this.pos + offset;
2500
+ result = this.chunk.charCodeAt(idx);
2501
+ } else {
2502
+ let resolved = this.resolveOffset(offset, 1);
2503
+ if (resolved == null)
2504
+ return -1;
2505
+ pos = resolved;
2506
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
2507
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
2508
+ } else {
2509
+ let i = this.rangeIndex, range = this.range;
2510
+ while (range.to <= pos)
2511
+ range = this.ranges[++i];
2512
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
2513
+ if (pos + this.chunk2.length > range.to)
2514
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
2515
+ result = this.chunk2.charCodeAt(0);
2516
+ }
2517
+ }
2518
+ if (pos >= this.token.lookAhead)
2519
+ this.token.lookAhead = pos + 1;
2520
+ return result;
2521
+ }
2522
+ /// Accept a token. By default, the end of the token is set to the
2523
+ /// current stream position, but you can pass an offset (relative to
2524
+ /// the stream position) to change that.
2525
+ acceptToken(token, endOffset = 0) {
2526
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2527
+ if (end == null || end < this.token.start)
2528
+ throw new RangeError("Token end out of bounds");
2529
+ this.token.value = token;
2530
+ this.token.end = end;
2531
+ }
2532
+ getChunk() {
2533
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2534
+ let { chunk, chunkPos } = this;
2535
+ this.chunk = this.chunk2;
2536
+ this.chunkPos = this.chunk2Pos;
2537
+ this.chunk2 = chunk;
2538
+ this.chunk2Pos = chunkPos;
2539
+ this.chunkOff = this.pos - this.chunkPos;
2540
+ } else {
2541
+ this.chunk2 = this.chunk;
2542
+ this.chunk2Pos = this.chunkPos;
2543
+ let nextChunk = this.input.chunk(this.pos);
2544
+ let end = this.pos + nextChunk.length;
2545
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2546
+ this.chunkPos = this.pos;
2547
+ this.chunkOff = 0;
2548
+ }
2549
+ }
2550
+ readNext() {
2551
+ if (this.chunkOff >= this.chunk.length) {
2552
+ this.getChunk();
2553
+ if (this.chunkOff == this.chunk.length)
2554
+ return this.next = -1;
2555
+ }
2556
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
2557
+ }
2558
+ /// Move the stream forward N (defaults to 1) code units. Returns
2559
+ /// the new value of [`next`](#lr.InputStream.next).
2560
+ advance(n = 1) {
2561
+ this.chunkOff += n;
2562
+ while (this.pos + n >= this.range.to) {
2563
+ if (this.rangeIndex == this.ranges.length - 1)
2564
+ return this.setDone();
2565
+ n -= this.range.to - this.pos;
2566
+ this.range = this.ranges[++this.rangeIndex];
2567
+ this.pos = this.range.from;
2568
+ }
2569
+ this.pos += n;
2570
+ if (this.pos >= this.token.lookAhead)
2571
+ this.token.lookAhead = this.pos + 1;
2572
+ return this.readNext();
2573
+ }
2574
+ setDone() {
2575
+ this.pos = this.chunkPos = this.end;
2576
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2577
+ this.chunk = "";
2578
+ return this.next = -1;
2579
+ }
2580
+ /// @internal
2581
+ reset(pos, token) {
2582
+ if (token) {
2583
+ this.token = token;
2584
+ token.start = pos;
2585
+ token.lookAhead = pos + 1;
2586
+ token.value = token.extended = -1;
2587
+ } else {
2588
+ this.token = nullToken;
2589
+ }
2590
+ if (this.pos != pos) {
2591
+ this.pos = pos;
2592
+ if (pos == this.end) {
2593
+ this.setDone();
2594
+ return this;
2595
+ }
2596
+ while (pos < this.range.from)
2597
+ this.range = this.ranges[--this.rangeIndex];
2598
+ while (pos >= this.range.to)
2599
+ this.range = this.ranges[++this.rangeIndex];
2600
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
2601
+ this.chunkOff = pos - this.chunkPos;
2602
+ } else {
2603
+ this.chunk = "";
2604
+ this.chunkOff = 0;
2605
+ }
2606
+ this.readNext();
2607
+ }
2608
+ return this;
2609
+ }
2610
+ /// @internal
2611
+ read(from, to) {
2612
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
2613
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
2614
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
2615
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
2616
+ if (from >= this.range.from && to <= this.range.to)
2617
+ return this.input.read(from, to);
2618
+ let result = "";
2619
+ for (let r2 of this.ranges) {
2620
+ if (r2.from >= to)
2621
+ break;
2622
+ if (r2.to > from)
2623
+ result += this.input.read(Math.max(r2.from, from), Math.min(r2.to, to));
2624
+ }
2625
+ return result;
2626
+ }
2627
+ };
2628
+ var TokenGroup = class {
2629
+ constructor(data, id) {
2630
+ this.data = data;
2631
+ this.id = id;
2632
+ }
2633
+ token(input, stack) {
2634
+ let { parser: parser2 } = stack.p;
2635
+ readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
2636
+ }
2637
+ };
2638
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2639
+ var LocalTokenGroup = class {
2640
+ constructor(data, precTable, elseToken) {
2641
+ this.precTable = precTable;
2642
+ this.elseToken = elseToken;
2643
+ this.data = typeof data == "string" ? decodeArray(data) : data;
2644
+ }
2645
+ token(input, stack) {
2646
+ let start = input.pos, skipped = 0;
2647
+ for (; ; ) {
2648
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
2649
+ if (input.token.value > -1)
2650
+ break;
2651
+ if (this.elseToken == null)
2652
+ return;
2653
+ if (input.next < 0)
2654
+ break;
2655
+ input.advance();
2656
+ input.reset(input.pos, input.token);
2657
+ skipped++;
2658
+ }
2659
+ if (skipped) {
2660
+ input.reset(start, input.token);
2661
+ input.acceptToken(this.elseToken, skipped);
2662
+ }
2663
+ }
2664
+ };
2665
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2666
+ function readToken(data, input, stack, group, precTable, precOffset) {
2667
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
2668
+ scan:
2669
+ for (; ; ) {
2670
+ if ((groupMask & data[state]) == 0)
2671
+ break;
2672
+ let accEnd = data[state + 1];
2673
+ for (let i = state + 3; i < accEnd; i += 2)
2674
+ if ((data[i + 1] & groupMask) > 0) {
2675
+ let term = data[i];
2676
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
2677
+ input.acceptToken(term);
2678
+ break;
2679
+ }
2680
+ }
2681
+ let next = input.next, low = 0, high = data[state + 2];
2682
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
2683
+ state = data[accEnd + high * 3 - 1];
2684
+ continue scan;
2685
+ }
2686
+ for (; low < high; ) {
2687
+ let mid = low + high >> 1;
2688
+ let index = accEnd + mid + (mid << 1);
2689
+ let from = data[index], to = data[index + 1] || 65536;
2690
+ if (next < from)
2691
+ high = mid;
2692
+ else if (next >= to)
2693
+ low = mid + 1;
2694
+ else {
2695
+ state = data[index + 2];
2696
+ input.advance();
2697
+ continue scan;
2698
+ }
2699
+ }
2700
+ break;
2701
+ }
2702
+ }
2703
+ function findOffset(data, start, term) {
2704
+ for (let i = start, next; (next = data[i]) != 65535; i++)
2705
+ if (next == term)
2706
+ return i - start;
2707
+ return -1;
2708
+ }
2709
+ function overrides(token, prev, tableData, tableOffset) {
2710
+ let iPrev = findOffset(tableData, tableOffset, prev);
2711
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
2712
+ }
2713
+ var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
2714
+ var stackIDs = null;
2715
+ var Safety;
2716
+ (function(Safety2) {
2717
+ Safety2[Safety2["Margin"] = 25] = "Margin";
2718
+ })(Safety || (Safety = {}));
2719
+ function cutAt(tree, pos, side) {
2720
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
2721
+ cursor.moveTo(pos);
2722
+ for (; ; ) {
2723
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
2724
+ for (; ; ) {
2725
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
2726
+ return side < 0 ? Math.max(0, Math.min(
2727
+ cursor.to - 1,
2728
+ pos - 25
2729
+ /* Safety.Margin */
2730
+ )) : Math.min(tree.length, Math.max(
2731
+ cursor.from + 1,
2732
+ pos + 25
2733
+ /* Safety.Margin */
2734
+ ));
2735
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
2736
+ break;
2737
+ if (!cursor.parent())
2738
+ return side < 0 ? 0 : tree.length;
2739
+ }
2740
+ }
2741
+ }
2742
+ var FragmentCursor = class {
2743
+ constructor(fragments, nodeSet) {
2744
+ this.fragments = fragments;
2745
+ this.nodeSet = nodeSet;
2746
+ this.i = 0;
2747
+ this.fragment = null;
2748
+ this.safeFrom = -1;
2749
+ this.safeTo = -1;
2750
+ this.trees = [];
2751
+ this.start = [];
2752
+ this.index = [];
2753
+ this.nextFragment();
2754
+ }
2755
+ nextFragment() {
2756
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
2757
+ if (fr) {
2758
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
2759
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
2760
+ while (this.trees.length) {
2761
+ this.trees.pop();
2762
+ this.start.pop();
2763
+ this.index.pop();
2764
+ }
2765
+ this.trees.push(fr.tree);
2766
+ this.start.push(-fr.offset);
2767
+ this.index.push(0);
2768
+ this.nextStart = this.safeFrom;
2769
+ } else {
2770
+ this.nextStart = 1e9;
2771
+ }
2772
+ }
2773
+ // `pos` must be >= any previously given `pos` for this cursor
2774
+ nodeAt(pos) {
2775
+ if (pos < this.nextStart)
2776
+ return null;
2777
+ while (this.fragment && this.safeTo <= pos)
2778
+ this.nextFragment();
2779
+ if (!this.fragment)
2780
+ return null;
2781
+ for (; ; ) {
2782
+ let last = this.trees.length - 1;
2783
+ if (last < 0) {
2784
+ this.nextFragment();
2785
+ return null;
2786
+ }
2787
+ let top = this.trees[last], index = this.index[last];
2788
+ if (index == top.children.length) {
2789
+ this.trees.pop();
2790
+ this.start.pop();
2791
+ this.index.pop();
2792
+ continue;
2793
+ }
2794
+ let next = top.children[index];
2795
+ let start = this.start[last] + top.positions[index];
2796
+ if (start > pos) {
2797
+ this.nextStart = start;
2798
+ return null;
2799
+ }
2800
+ if (next instanceof Tree) {
2801
+ if (start == pos) {
2802
+ if (start < this.safeFrom)
2803
+ return null;
2804
+ let end = start + next.length;
2805
+ if (end <= this.safeTo) {
2806
+ let lookAhead = next.prop(NodeProp.lookAhead);
2807
+ if (!lookAhead || end + lookAhead < this.fragment.to)
2808
+ return next;
2809
+ }
2810
+ }
2811
+ this.index[last]++;
2812
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
2813
+ this.trees.push(next);
2814
+ this.start.push(start);
2815
+ this.index.push(0);
2816
+ }
2817
+ } else {
2818
+ this.index[last]++;
2819
+ this.nextStart = start + next.length;
2820
+ }
2821
+ }
2822
+ }
2823
+ };
2824
+ var TokenCache = class {
2825
+ constructor(parser2, stream) {
2826
+ this.stream = stream;
2827
+ this.tokens = [];
2828
+ this.mainToken = null;
2829
+ this.actions = [];
2830
+ this.tokens = parser2.tokenizers.map((_) => new CachedToken());
2831
+ }
2832
+ getActions(stack) {
2833
+ let actionIndex = 0;
2834
+ let main = null;
2835
+ let { parser: parser2 } = stack.p, { tokenizers } = parser2;
2836
+ let mask = parser2.stateSlot(
2837
+ stack.state,
2838
+ 3
2839
+ /* ParseState.TokenizerMask */
2840
+ );
2841
+ let context = stack.curContext ? stack.curContext.hash : 0;
2842
+ let lookAhead = 0;
2843
+ for (let i = 0; i < tokenizers.length; i++) {
2844
+ if ((1 << i & mask) == 0)
2845
+ continue;
2846
+ let tokenizer = tokenizers[i], token = this.tokens[i];
2847
+ if (main && !tokenizer.fallback)
2848
+ continue;
2849
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
2850
+ this.updateCachedToken(token, tokenizer, stack);
2851
+ token.mask = mask;
2852
+ token.context = context;
2853
+ }
2854
+ if (token.lookAhead > token.end + 25)
2855
+ lookAhead = Math.max(token.lookAhead, lookAhead);
2856
+ if (token.value != 0) {
2857
+ let startIndex = actionIndex;
2858
+ if (token.extended > -1)
2859
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
2860
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
2861
+ if (!tokenizer.extend) {
2862
+ main = token;
2863
+ if (actionIndex > startIndex)
2864
+ break;
2865
+ }
2866
+ }
2867
+ }
2868
+ while (this.actions.length > actionIndex)
2869
+ this.actions.pop();
2870
+ if (lookAhead)
2871
+ stack.setLookAhead(lookAhead);
2872
+ if (!main && stack.pos == this.stream.end) {
2873
+ main = new CachedToken();
2874
+ main.value = stack.p.parser.eofTerm;
2875
+ main.start = main.end = stack.pos;
2876
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
2877
+ }
2878
+ this.mainToken = main;
2879
+ return this.actions;
2880
+ }
2881
+ getMainToken(stack) {
2882
+ if (this.mainToken)
2883
+ return this.mainToken;
2884
+ let main = new CachedToken(), { pos, p } = stack;
2885
+ main.start = pos;
2886
+ main.end = Math.min(pos + 1, p.stream.end);
2887
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
2888
+ return main;
2889
+ }
2890
+ updateCachedToken(token, tokenizer, stack) {
2891
+ let start = this.stream.clipPos(stack.pos);
2892
+ tokenizer.token(this.stream.reset(start, token), stack);
2893
+ if (token.value > -1) {
2894
+ let { parser: parser2 } = stack.p;
2895
+ for (let i = 0; i < parser2.specialized.length; i++)
2896
+ if (parser2.specialized[i] == token.value) {
2897
+ let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
2898
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
2899
+ if ((result & 1) == 0)
2900
+ token.value = result >> 1;
2901
+ else
2902
+ token.extended = result >> 1;
2903
+ break;
2904
+ }
2905
+ }
2906
+ } else {
2907
+ token.value = 0;
2908
+ token.end = this.stream.clipPos(start + 1);
2909
+ }
2910
+ }
2911
+ putAction(action, token, end, index) {
2912
+ for (let i = 0; i < index; i += 3)
2913
+ if (this.actions[i] == action)
2914
+ return index;
2915
+ this.actions[index++] = action;
2916
+ this.actions[index++] = token;
2917
+ this.actions[index++] = end;
2918
+ return index;
2919
+ }
2920
+ addActions(stack, token, end, index) {
2921
+ let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
2922
+ for (let set = 0; set < 2; set++) {
2923
+ for (let i = parser2.stateSlot(
2924
+ state,
2925
+ set ? 2 : 1
2926
+ /* ParseState.Actions */
2927
+ ); ; i += 3) {
2928
+ if (data[i] == 65535) {
2929
+ if (data[i + 1] == 1) {
2930
+ i = pair(data, i + 2);
2931
+ } else {
2932
+ if (index == 0 && data[i + 1] == 2)
2933
+ index = this.putAction(pair(data, i + 2), token, end, index);
2934
+ break;
2935
+ }
2936
+ }
2937
+ if (data[i] == token)
2938
+ index = this.putAction(pair(data, i + 1), token, end, index);
2939
+ }
2940
+ }
2941
+ return index;
2942
+ }
2943
+ };
2944
+ var Rec;
2945
+ (function(Rec2) {
2946
+ Rec2[Rec2["Distance"] = 5] = "Distance";
2947
+ Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
2948
+ Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
2949
+ Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
2950
+ Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
2951
+ Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
2952
+ Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
2953
+ Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
2954
+ })(Rec || (Rec = {}));
2955
+ var Parse = class {
2956
+ constructor(parser2, input, fragments, ranges) {
2957
+ this.parser = parser2;
2958
+ this.input = input;
2959
+ this.ranges = ranges;
2960
+ this.recovering = 0;
2961
+ this.nextStackID = 9812;
2962
+ this.minStackPos = 0;
2963
+ this.reused = [];
2964
+ this.stoppedAt = null;
2965
+ this.lastBigReductionStart = -1;
2966
+ this.lastBigReductionSize = 0;
2967
+ this.bigReductionCount = 0;
2968
+ this.stream = new InputStream(input, ranges);
2969
+ this.tokens = new TokenCache(parser2, this.stream);
2970
+ this.topTerm = parser2.top[1];
2971
+ let { from } = ranges[0];
2972
+ this.stacks = [Stack.start(this, parser2.top[0], from)];
2973
+ this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
2974
+ }
2975
+ get parsedPos() {
2976
+ return this.minStackPos;
2977
+ }
2978
+ // Move the parser forward. This will process all parse stacks at
2979
+ // `this.pos` and try to advance them to a further position. If no
2980
+ // stack for such a position is found, it'll start error-recovery.
2981
+ //
2982
+ // When the parse is finished, this will return a syntax tree. When
2983
+ // not, it returns `null`.
2984
+ advance() {
2985
+ let stacks = this.stacks, pos = this.minStackPos;
2986
+ let newStacks = this.stacks = [];
2987
+ let stopped, stoppedTokens;
2988
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
2989
+ let [s] = stacks;
2990
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
2991
+ }
2992
+ this.bigReductionCount = this.lastBigReductionSize = 0;
2993
+ }
2994
+ for (let i = 0; i < stacks.length; i++) {
2995
+ let stack = stacks[i];
2996
+ for (; ; ) {
2997
+ this.tokens.mainToken = null;
2998
+ if (stack.pos > pos) {
2999
+ newStacks.push(stack);
3000
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
3001
+ continue;
3002
+ } else {
3003
+ if (!stopped) {
3004
+ stopped = [];
3005
+ stoppedTokens = [];
3006
+ }
3007
+ stopped.push(stack);
3008
+ let tok = this.tokens.getMainToken(stack);
3009
+ stoppedTokens.push(tok.value, tok.end);
3010
+ }
3011
+ break;
3012
+ }
3013
+ }
3014
+ if (!newStacks.length) {
3015
+ let finished = stopped && findFinished(stopped);
3016
+ if (finished)
3017
+ return this.stackToTree(finished);
3018
+ if (this.parser.strict) {
3019
+ if (verbose && stopped)
3020
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
3021
+ throw new SyntaxError("No parse at " + pos);
3022
+ }
3023
+ if (!this.recovering)
3024
+ this.recovering = 5;
3025
+ }
3026
+ if (this.recovering && stopped) {
3027
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
3028
+ if (finished)
3029
+ return this.stackToTree(finished.forceAll());
3030
+ }
3031
+ if (this.recovering) {
3032
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
3033
+ if (newStacks.length > maxRemaining) {
3034
+ newStacks.sort((a, b) => b.score - a.score);
3035
+ while (newStacks.length > maxRemaining)
3036
+ newStacks.pop();
3037
+ }
3038
+ if (newStacks.some((s) => s.reducePos > pos))
3039
+ this.recovering--;
3040
+ } else if (newStacks.length > 1) {
3041
+ outer:
3042
+ for (let i = 0; i < newStacks.length - 1; i++) {
3043
+ let stack = newStacks[i];
3044
+ for (let j = i + 1; j < newStacks.length; j++) {
3045
+ let other = newStacks[j];
3046
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
3047
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
3048
+ newStacks.splice(j--, 1);
3049
+ } else {
3050
+ newStacks.splice(i--, 1);
3051
+ continue outer;
3052
+ }
3053
+ }
3054
+ }
3055
+ }
3056
+ if (newStacks.length > 12)
3057
+ newStacks.splice(
3058
+ 12,
3059
+ newStacks.length - 12
3060
+ /* Rec.MaxStackCount */
3061
+ );
3062
+ }
3063
+ this.minStackPos = newStacks[0].pos;
3064
+ for (let i = 1; i < newStacks.length; i++)
3065
+ if (newStacks[i].pos < this.minStackPos)
3066
+ this.minStackPos = newStacks[i].pos;
3067
+ return null;
3068
+ }
3069
+ stopAt(pos) {
3070
+ if (this.stoppedAt != null && this.stoppedAt < pos)
3071
+ throw new RangeError("Can't move stoppedAt forward");
3072
+ this.stoppedAt = pos;
3073
+ }
3074
+ // Returns an updated version of the given stack, or null if the
3075
+ // stack can't advance normally. When `split` and `stacks` are
3076
+ // given, stacks split off by ambiguous operations will be pushed to
3077
+ // `split`, or added to `stacks` if they move `pos` forward.
3078
+ advanceStack(stack, stacks, split) {
3079
+ let start = stack.pos, { parser: parser2 } = this;
3080
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3081
+ if (this.stoppedAt != null && start > this.stoppedAt)
3082
+ return stack.forceReduce() ? stack : null;
3083
+ if (this.fragments) {
3084
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
3085
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
3086
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
3087
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
3088
+ stack.useNode(cached, match);
3089
+ if (verbose)
3090
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
3091
+ return true;
3092
+ }
3093
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
3094
+ break;
3095
+ let inner = cached.children[0];
3096
+ if (inner instanceof Tree && cached.positions[0] == 0)
3097
+ cached = inner;
3098
+ else
3099
+ break;
3100
+ }
3101
+ }
3102
+ let defaultReduce = parser2.stateSlot(
3103
+ stack.state,
3104
+ 4
3105
+ /* ParseState.DefaultReduce */
3106
+ );
3107
+ if (defaultReduce > 0) {
3108
+ stack.reduce(defaultReduce);
3109
+ if (verbose)
3110
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
3111
+ defaultReduce & 65535
3112
+ /* Action.ValueMask */
3113
+ )})`);
3114
+ return true;
3115
+ }
3116
+ if (stack.stack.length >= 15e3) {
3117
+ while (stack.stack.length > 9e3 && stack.forceReduce()) {
3118
+ }
3119
+ }
3120
+ let actions = this.tokens.getActions(stack);
3121
+ for (let i = 0; i < actions.length; ) {
3122
+ let action = actions[i++], term = actions[i++], end = actions[i++];
3123
+ let last = i == actions.length || !split;
3124
+ let localStack = last ? stack : stack.split();
3125
+ localStack.apply(action, term, end);
3126
+ if (verbose)
3127
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
3128
+ action & 65535
3129
+ /* Action.ValueMask */
3130
+ )}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
3131
+ if (last)
3132
+ return true;
3133
+ else if (localStack.pos > start)
3134
+ stacks.push(localStack);
3135
+ else
3136
+ split.push(localStack);
3137
+ }
3138
+ return false;
3139
+ }
3140
+ // Advance a given stack forward as far as it will go. Returns the
3141
+ // (possibly updated) stack if it got stuck, or null if it moved
3142
+ // forward and was given to `pushStackDedup`.
3143
+ advanceFully(stack, newStacks) {
3144
+ let pos = stack.pos;
3145
+ for (; ; ) {
3146
+ if (!this.advanceStack(stack, null, null))
3147
+ return false;
3148
+ if (stack.pos > pos) {
3149
+ pushStackDedup(stack, newStacks);
3150
+ return true;
3151
+ }
3152
+ }
3153
+ }
3154
+ runRecovery(stacks, tokens, newStacks) {
3155
+ let finished = null, restarted = false;
3156
+ for (let i = 0; i < stacks.length; i++) {
3157
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
3158
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3159
+ if (stack.deadEnd) {
3160
+ if (restarted)
3161
+ continue;
3162
+ restarted = true;
3163
+ stack.restart();
3164
+ if (verbose)
3165
+ console.log(base + this.stackID(stack) + " (restarted)");
3166
+ let done = this.advanceFully(stack, newStacks);
3167
+ if (done)
3168
+ continue;
3169
+ }
3170
+ let force = stack.split(), forceBase = base;
3171
+ for (let j = 0; force.forceReduce() && j < 10; j++) {
3172
+ if (verbose)
3173
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
3174
+ let done = this.advanceFully(force, newStacks);
3175
+ if (done)
3176
+ break;
3177
+ if (verbose)
3178
+ forceBase = this.stackID(force) + " -> ";
3179
+ }
3180
+ for (let insert of stack.recoverByInsert(token)) {
3181
+ if (verbose)
3182
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
3183
+ this.advanceFully(insert, newStacks);
3184
+ }
3185
+ if (this.stream.end > stack.pos) {
3186
+ if (tokenEnd == stack.pos) {
3187
+ tokenEnd++;
3188
+ token = 0;
3189
+ }
3190
+ stack.recoverByDelete(token, tokenEnd);
3191
+ if (verbose)
3192
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
3193
+ pushStackDedup(stack, newStacks);
3194
+ } else if (!finished || finished.score < stack.score) {
3195
+ finished = stack;
3196
+ }
3197
+ }
3198
+ return finished;
3199
+ }
3200
+ // Convert the stack's buffer to a syntax tree.
3201
+ stackToTree(stack) {
3202
+ stack.close();
3203
+ return Tree.build({
3204
+ buffer: StackBufferCursor.create(stack),
3205
+ nodeSet: this.parser.nodeSet,
3206
+ topID: this.topTerm,
3207
+ maxBufferLength: this.parser.bufferLength,
3208
+ reused: this.reused,
3209
+ start: this.ranges[0].from,
3210
+ length: stack.pos - this.ranges[0].from,
3211
+ minRepeatType: this.parser.minRepeatTerm
3212
+ });
3213
+ }
3214
+ stackID(stack) {
3215
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
3216
+ if (!id)
3217
+ stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
3218
+ return id + stack;
3219
+ }
3220
+ };
3221
+ function pushStackDedup(stack, newStacks) {
3222
+ for (let i = 0; i < newStacks.length; i++) {
3223
+ let other = newStacks[i];
3224
+ if (other.pos == stack.pos && other.sameState(stack)) {
3225
+ if (newStacks[i].score < stack.score)
3226
+ newStacks[i] = stack;
3227
+ return;
3228
+ }
3229
+ }
3230
+ newStacks.push(stack);
3231
+ }
3232
+ var Dialect = class {
3233
+ constructor(source, flags, disabled) {
3234
+ this.source = source;
3235
+ this.flags = flags;
3236
+ this.disabled = disabled;
3237
+ }
3238
+ allows(term) {
3239
+ return !this.disabled || this.disabled[term] == 0;
3240
+ }
3241
+ };
3242
+ var LRParser = class extends Parser {
3243
+ /// @internal
3244
+ constructor(spec) {
3245
+ super();
3246
+ this.wrappers = [];
3247
+ if (spec.version != 14)
3248
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
3249
+ let nodeNames = spec.nodeNames.split(" ");
3250
+ this.minRepeatTerm = nodeNames.length;
3251
+ for (let i = 0; i < spec.repeatNodeCount; i++)
3252
+ nodeNames.push("");
3253
+ let topTerms = Object.keys(spec.topRules).map((r2) => spec.topRules[r2][1]);
3254
+ let nodeProps = [];
3255
+ for (let i = 0; i < nodeNames.length; i++)
3256
+ nodeProps.push([]);
3257
+ function setProp(nodeID, prop, value) {
3258
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
3259
+ }
3260
+ if (spec.nodeProps)
3261
+ for (let propSpec of spec.nodeProps) {
3262
+ let prop = propSpec[0];
3263
+ if (typeof prop == "string")
3264
+ prop = NodeProp[prop];
3265
+ for (let i = 1; i < propSpec.length; ) {
3266
+ let next = propSpec[i++];
3267
+ if (next >= 0) {
3268
+ setProp(next, prop, propSpec[i++]);
3269
+ } else {
3270
+ let value = propSpec[i + -next];
3271
+ for (let j = -next; j > 0; j--)
3272
+ setProp(propSpec[i++], prop, value);
3273
+ i++;
3274
+ }
3275
+ }
3276
+ }
3277
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
3278
+ name: i >= this.minRepeatTerm ? void 0 : name,
3279
+ id: i,
3280
+ props: nodeProps[i],
3281
+ top: topTerms.indexOf(i) > -1,
3282
+ error: i == 0,
3283
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
3284
+ })));
3285
+ if (spec.propSources)
3286
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
3287
+ this.strict = false;
3288
+ this.bufferLength = DefaultBufferLength;
3289
+ let tokenArray = decodeArray(spec.tokenData);
3290
+ this.context = spec.context;
3291
+ this.specializerSpecs = spec.specialized || [];
3292
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
3293
+ for (let i = 0; i < this.specializerSpecs.length; i++)
3294
+ this.specialized[i] = this.specializerSpecs[i].term;
3295
+ this.specializers = this.specializerSpecs.map(getSpecializer);
3296
+ this.states = decodeArray(spec.states, Uint32Array);
3297
+ this.data = decodeArray(spec.stateData);
3298
+ this.goto = decodeArray(spec.goto);
3299
+ this.maxTerm = spec.maxTerm;
3300
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
3301
+ this.topRules = spec.topRules;
3302
+ this.dialects = spec.dialects || {};
3303
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
3304
+ this.tokenPrecTable = spec.tokenPrec;
3305
+ this.termNames = spec.termNames || null;
3306
+ this.maxNode = this.nodeSet.types.length - 1;
3307
+ this.dialect = this.parseDialect();
3308
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
3309
+ }
3310
+ createParse(input, fragments, ranges) {
3311
+ let parse = new Parse(this, input, fragments, ranges);
3312
+ for (let w of this.wrappers)
3313
+ parse = w(parse, input, fragments, ranges);
3314
+ return parse;
3315
+ }
3316
+ /// Get a goto table entry @internal
3317
+ getGoto(state, term, loose = false) {
3318
+ let table = this.goto;
3319
+ if (term >= table[0])
3320
+ return -1;
3321
+ for (let pos = table[term + 1]; ; ) {
3322
+ let groupTag = table[pos++], last = groupTag & 1;
3323
+ let target = table[pos++];
3324
+ if (last && loose)
3325
+ return target;
3326
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
3327
+ if (table[pos] == state)
3328
+ return target;
3329
+ if (last)
3330
+ return -1;
3331
+ }
3332
+ }
3333
+ /// Check if this state has an action for a given terminal @internal
3334
+ hasAction(state, terminal) {
3335
+ let data = this.data;
3336
+ for (let set = 0; set < 2; set++) {
3337
+ for (let i = this.stateSlot(
3338
+ state,
3339
+ set ? 2 : 1
3340
+ /* ParseState.Actions */
3341
+ ), next; ; i += 3) {
3342
+ if ((next = data[i]) == 65535) {
3343
+ if (data[i + 1] == 1)
3344
+ next = data[i = pair(data, i + 2)];
3345
+ else if (data[i + 1] == 2)
3346
+ return pair(data, i + 2);
3347
+ else
3348
+ break;
3349
+ }
3350
+ if (next == terminal || next == 0)
3351
+ return pair(data, i + 1);
3352
+ }
3353
+ }
3354
+ return 0;
3355
+ }
3356
+ /// @internal
3357
+ stateSlot(state, slot) {
3358
+ return this.states[state * 6 + slot];
3359
+ }
3360
+ /// @internal
3361
+ stateFlag(state, flag) {
3362
+ return (this.stateSlot(
3363
+ state,
3364
+ 0
3365
+ /* ParseState.Flags */
3366
+ ) & flag) > 0;
3367
+ }
3368
+ /// @internal
3369
+ validAction(state, action) {
3370
+ if (action == this.stateSlot(
3371
+ state,
3372
+ 4
3373
+ /* ParseState.DefaultReduce */
3374
+ ))
3375
+ return true;
3376
+ for (let i = this.stateSlot(
3377
+ state,
3378
+ 1
3379
+ /* ParseState.Actions */
3380
+ ); ; i += 3) {
3381
+ if (this.data[i] == 65535) {
3382
+ if (this.data[i + 1] == 1)
3383
+ i = pair(this.data, i + 2);
3384
+ else
3385
+ return false;
3386
+ }
3387
+ if (action == pair(this.data, i + 1))
3388
+ return true;
3389
+ }
3390
+ }
3391
+ /// Get the states that can follow this one through shift actions or
3392
+ /// goto jumps. @internal
3393
+ nextStates(state) {
3394
+ let result = [];
3395
+ for (let i = this.stateSlot(
3396
+ state,
3397
+ 1
3398
+ /* ParseState.Actions */
3399
+ ); ; i += 3) {
3400
+ if (this.data[i] == 65535) {
3401
+ if (this.data[i + 1] == 1)
3402
+ i = pair(this.data, i + 2);
3403
+ else
3404
+ break;
3405
+ }
3406
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
3407
+ let value = this.data[i + 1];
3408
+ if (!result.some((v, i2) => i2 & 1 && v == value))
3409
+ result.push(this.data[i], value);
3410
+ }
3411
+ }
3412
+ return result;
3413
+ }
3414
+ /// Configure the parser. Returns a new parser instance that has the
3415
+ /// given settings modified. Settings not provided in `config` are
3416
+ /// kept from the original parser.
3417
+ configure(config) {
3418
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
3419
+ if (config.props)
3420
+ copy.nodeSet = this.nodeSet.extend(...config.props);
3421
+ if (config.top) {
3422
+ let info = this.topRules[config.top];
3423
+ if (!info)
3424
+ throw new RangeError(`Invalid top rule name ${config.top}`);
3425
+ copy.top = info;
3426
+ }
3427
+ if (config.tokenizers)
3428
+ copy.tokenizers = this.tokenizers.map((t) => {
3429
+ let found = config.tokenizers.find((r2) => r2.from == t);
3430
+ return found ? found.to : t;
3431
+ });
3432
+ if (config.specializers) {
3433
+ copy.specializers = this.specializers.slice();
3434
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
3435
+ let found = config.specializers.find((r2) => r2.from == s.external);
3436
+ if (!found)
3437
+ return s;
3438
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
3439
+ copy.specializers[i] = getSpecializer(spec);
3440
+ return spec;
3441
+ });
3442
+ }
3443
+ if (config.contextTracker)
3444
+ copy.context = config.contextTracker;
3445
+ if (config.dialect)
3446
+ copy.dialect = this.parseDialect(config.dialect);
3447
+ if (config.strict != null)
3448
+ copy.strict = config.strict;
3449
+ if (config.wrap)
3450
+ copy.wrappers = copy.wrappers.concat(config.wrap);
3451
+ if (config.bufferLength != null)
3452
+ copy.bufferLength = config.bufferLength;
3453
+ return copy;
3454
+ }
3455
+ /// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
3456
+ /// are registered for this parser.
3457
+ hasWrappers() {
3458
+ return this.wrappers.length > 0;
3459
+ }
3460
+ /// Returns the name associated with a given term. This will only
3461
+ /// work for all terms when the parser was generated with the
3462
+ /// `--names` option. By default, only the names of tagged terms are
3463
+ /// stored.
3464
+ getName(term) {
3465
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
3466
+ }
3467
+ /// The eof term id is always allocated directly after the node
3468
+ /// types. @internal
3469
+ get eofTerm() {
3470
+ return this.maxNode + 1;
3471
+ }
3472
+ /// The type of top node produced by the parser.
3473
+ get topNode() {
3474
+ return this.nodeSet.types[this.top[1]];
3475
+ }
3476
+ /// @internal
3477
+ dynamicPrecedence(term) {
3478
+ let prec = this.dynamicPrecedences;
3479
+ return prec == null ? 0 : prec[term] || 0;
3480
+ }
3481
+ /// @internal
3482
+ parseDialect(dialect) {
3483
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
3484
+ if (dialect)
3485
+ for (let part of dialect.split(" ")) {
3486
+ let id = values.indexOf(part);
3487
+ if (id >= 0)
3488
+ flags[id] = true;
3489
+ }
3490
+ let disabled = null;
3491
+ for (let i = 0; i < values.length; i++)
3492
+ if (!flags[i]) {
3493
+ for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
3494
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
3495
+ }
3496
+ return new Dialect(dialect, flags, disabled);
3497
+ }
3498
+ /// Used by the output of the parser generator. Not available to
3499
+ /// user code. @hide
3500
+ static deserialize(spec) {
3501
+ return new LRParser(spec);
3502
+ }
3503
+ };
3504
+ function pair(data, off) {
3505
+ return data[off] | data[off + 1] << 16;
3506
+ }
3507
+ function findFinished(stacks) {
3508
+ let best = null;
3509
+ for (let stack of stacks) {
3510
+ let stopped = stack.p.stoppedAt;
3511
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
3512
+ stack.state,
3513
+ 2
3514
+ /* StateFlag.Accepting */
3515
+ ) && (!best || best.score < stack.score))
3516
+ best = stack;
3517
+ }
3518
+ return best;
3519
+ }
3520
+ function getSpecializer(spec) {
3521
+ if (spec.external) {
3522
+ let mask = spec.extend ? 1 : 0;
3523
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
3524
+ }
3525
+ return spec.get;
3526
+ }
3527
+
3528
+ // ../vuu-filter-parser/src/generated/filter-parser.js
3529
+ var parser = LRParser.deserialize({
3530
+ version: 14,
3531
+ states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
3532
+ stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
3533
+ goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
3534
+ nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
3535
+ maxTerm: 39,
3536
+ skippedNodes: [0],
3537
+ repeatNodeCount: 1,
3538
+ tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
3539
+ tokenizers: [0, 1],
3540
+ topRules: { "Filter": [0, 1] },
3541
+ tokenPrec: 0
3542
+ });
3543
+
3544
+ // ../vuu-filter-parser/src/FilterTreeWalker.ts
3545
+ import {
3546
+ isMultiClauseFilter as isMultiClauseFilter2,
3547
+ isMultiValueFilter as isMultiValueFilter2,
3548
+ isSingleValueFilter as isSingleValueFilter2
3549
+ } from "@vuu-ui/vuu-utils";
3550
+ var _filter;
3551
+ var FilterExpression = class {
3552
+ constructor() {
3553
+ __privateAdd(this, _filter, void 0);
3554
+ }
3555
+ setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
3556
+ if (isMultiClauseFilter2(filter) && filter.op === op) {
3557
+ return;
3558
+ } else {
3559
+ __privateSet(this, _filter, {
3560
+ op,
3561
+ filters: [__privateGet(this, _filter)]
3562
+ });
3563
+ }
3564
+ }
3565
+ add(filter) {
3566
+ if (__privateGet(this, _filter) === void 0) {
3567
+ __privateSet(this, _filter, filter);
3568
+ } else if (isMultiClauseFilter2(__privateGet(this, _filter))) {
3569
+ __privateGet(this, _filter).filters.push(filter);
3570
+ } else {
3571
+ throw Error(`Invalid filter passed to FilterExpression`);
3572
+ }
3573
+ }
3574
+ setColumn(column, filter = __privateGet(this, _filter)) {
3575
+ if (isMultiClauseFilter2(filter)) {
3576
+ const target = filter.filters.at(-1);
3577
+ if (target) {
3578
+ this.setColumn(column, target);
3579
+ }
3580
+ } else if (filter) {
3581
+ filter.column = column;
3582
+ }
3583
+ }
3584
+ setOp(value, filter = __privateGet(this, _filter)) {
3585
+ if (isMultiClauseFilter2(filter)) {
3586
+ const target = filter.filters.at(-1);
3587
+ if (target) {
3588
+ this.setOp(value, target);
3589
+ }
3590
+ } else if (filter) {
3591
+ filter.op = value;
3592
+ }
3593
+ }
3594
+ setValue(value, filter = __privateGet(this, _filter)) {
3595
+ var _a;
3596
+ if (isMultiClauseFilter2(filter)) {
3597
+ const target = filter.filters.at(-1);
3598
+ if (target) {
3599
+ this.setValue(value, target);
3600
+ }
3601
+ } else if (isMultiValueFilter2(filter)) {
3602
+ (_a = filter.values) != null ? _a : filter.values = [];
3603
+ filter.values.push(value);
3604
+ } else if (isSingleValueFilter2(filter)) {
3605
+ filter.value = value;
3606
+ }
3607
+ }
3608
+ toJSON(filter = __privateGet(this, _filter)) {
3609
+ if (this.name) {
3610
+ return {
3611
+ ...filter,
3612
+ name: this.name
3613
+ };
3614
+ } else {
3615
+ return filter;
3616
+ }
3617
+ }
3618
+ };
3619
+ _filter = new WeakMap();
3620
+ var walkTree = (tree, source) => {
3621
+ const filterExpression = new FilterExpression();
3622
+ const cursor = tree.cursor();
3623
+ do {
3624
+ const { name, from, to } = cursor;
3625
+ switch (name) {
3626
+ case "ColumnValueExpression":
3627
+ filterExpression.add({});
3628
+ break;
3629
+ case "ColumnSetExpression":
3630
+ filterExpression.add({ op: "in" });
3631
+ break;
3632
+ case "Or":
3633
+ case "And":
3634
+ filterExpression.setFilterCombinatorOp(source.substring(from, to));
3635
+ break;
3636
+ case "Column":
3637
+ filterExpression.setColumn(source.substring(from, to));
3638
+ break;
3639
+ case "Operator":
3640
+ filterExpression.setOp(source.substring(from, to));
3641
+ break;
3642
+ case "String":
3643
+ filterExpression.setValue(source.substring(from + 1, to - 1));
3644
+ break;
3645
+ case "Number":
3646
+ filterExpression.setValue(parseFloat(source.substring(from, to)));
3647
+ break;
3648
+ case "True":
3649
+ filterExpression.setValue(true);
3650
+ break;
3651
+ case "False":
3652
+ filterExpression.setValue(false);
3653
+ break;
3654
+ case "FilterName":
3655
+ filterExpression.name = source.substring(from, to);
3656
+ break;
3657
+ default:
3658
+ }
3659
+ } while (cursor.next());
3660
+ return filterExpression.toJSON();
511
3661
  };
512
3662
 
513
- // src/column-filter/utils.ts
514
- var isStartsWithValue = (value) => /\.\.\.$/.test(value);
515
- var getTypeaheadFilter = (column, filterValues, isStartsWithFilter) => {
516
- if (filterValues.length === 0) {
517
- return void 0;
518
- }
519
- if (isStartsWithFilter) {
520
- const startsWith = filterValues[0].substring(0, filterValues[0].length - 3);
521
- return {
522
- column,
523
- op: "starts",
524
- value: `"${startsWith}"`
525
- };
526
- }
527
- return {
528
- column,
529
- op: "in",
530
- values: filterValues.map((value) => `"${value}"`)
531
- };
532
- };
533
- var getRangeFilter = (column, startValue, endValue) => {
534
- const startFilter = startValue === void 0 ? void 0 : { column, op: ">", value: startValue - 1 };
535
- const endFilter = endValue === void 0 ? void 0 : { column, op: "<", value: endValue + 1 };
536
- if (endFilter === void 0)
537
- return startFilter;
538
- return addFilter(startFilter, endFilter, { combineWith: "and" });
539
- };
3663
+ // ../vuu-filter-parser/src/FilterParser.ts
3664
+ var strictParser = parser.configure({ strict: true });
540
3665
 
541
- // src/column-filter/RangeFilter.tsx
542
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
543
- var RangeFilter = ({
544
- defaultTypeaheadParams,
545
- filterValues,
546
- onChange
547
- }) => {
548
- var _a, _b;
549
- const columnName = defaultTypeaheadParams[1];
550
- const startChangeHandler = (e) => {
551
- const value = parseFloat(e.target.value);
552
- const newRange = {
553
- start: isNaN(value) ? void 0 : value,
554
- end: filterValues == null ? void 0 : filterValues.end
555
- };
556
- const filter = getRangeFilter(columnName, newRange.start, newRange.end);
557
- onChange(newRange, filter);
558
- };
559
- const endChangeHandler = (e) => {
560
- const value = parseFloat(e.target.value);
561
- const newRange = {
562
- start: filterValues == null ? void 0 : filterValues.start,
563
- end: isNaN(value) ? void 0 : value
564
- };
565
- const filter = getRangeFilter(columnName, newRange.start, newRange.end);
566
- onChange(newRange, filter);
567
- };
568
- return /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: "row" }, children: [
569
- /* @__PURE__ */ jsx3(ToolbarField, { label: "From", children: /* @__PURE__ */ jsx3(
570
- Input,
571
- {
572
- onChange: startChangeHandler,
573
- value: ((_a = filterValues == null ? void 0 : filterValues.start) == null ? void 0 : _a.toString()) || "",
574
- type: "number"
575
- }
576
- ) }),
577
- /* @__PURE__ */ jsx3(ToolbarField, { label: "To", children: /* @__PURE__ */ jsx3(
578
- Input,
579
- {
580
- onChange: endChangeHandler,
581
- value: ((_b = filterValues == null ? void 0 : filterValues.end) == null ? void 0 : _b.toString()) || "",
582
- type: "number"
583
- }
584
- ) })
585
- ] });
586
- };
3666
+ // ../vuu-data-react/src/hooks/useVuuMenuActions.ts
3667
+ import {
3668
+ getRowRecord,
3669
+ isGroupMenuItemDescriptor,
3670
+ metadataKeys as metadataKeys2
3671
+ } from "@vuu-ui/vuu-utils";
3672
+ import { useCallback as useCallback5 } from "react";
3673
+ var { KEY } = metadataKeys2;
3674
+
3675
+ // ../vuu-data-react/src/hooks/useVuuTables.ts
3676
+ import { useCallback as useCallback6, useEffect as useEffect4, useState as useState4 } from "react";
3677
+ import { getServerAPI } from "@vuu-ui/vuu-data";
587
3678
 
588
3679
  // src/column-filter/TypeaheadFilter.tsx
589
- import { useCallback, useEffect, useState } from "react";
590
- import { useTypeaheadSuggestions } from "@vuu-ui/vuu-data";
591
3680
  import { ComboBoxDeprecated } from "@heswell/salt-lab";
3681
+ import { useCallback as useCallback7, useEffect as useEffect5, useState as useState5 } from "react";
592
3682
  import { jsx as jsx4 } from "react/jsx-runtime";
593
3683
  var TypeaheadFilter = ({
594
3684
  defaultTypeaheadParams,
@@ -596,10 +3686,10 @@ var TypeaheadFilter = ({
596
3686
  onChange: onFilterChange
597
3687
  }) => {
598
3688
  const [tableName, columnName] = defaultTypeaheadParams;
599
- const [searchValue, setSearchValue] = useState("");
600
- const [typeaheadValues, setTypeaheadValues] = useState([]);
3689
+ const [searchValue, setSearchValue] = useState5("");
3690
+ const [typeaheadValues, setTypeaheadValues] = useState5([]);
601
3691
  const getSuggestions = useTypeaheadSuggestions();
602
- useEffect(() => {
3692
+ useEffect5(() => {
603
3693
  const params = searchValue ? [tableName, columnName, searchValue] : defaultTypeaheadParams;
604
3694
  let isSubscribed = true;
605
3695
  getSuggestions(params).then((options) => {
@@ -626,14 +3716,14 @@ var TypeaheadFilter = ({
626
3716
  getSuggestions,
627
3717
  defaultTypeaheadParams
628
3718
  ]);
629
- const onInputChange = useCallback(
3719
+ const onInputChange = useCallback7(
630
3720
  (evt) => {
631
3721
  const value = evt.target.value;
632
3722
  setSearchValue(value);
633
3723
  },
634
3724
  []
635
3725
  );
636
- const onSelectionChange = useCallback(
3726
+ const onSelectionChange = useCallback7(
637
3727
  (_evt, selected) => {
638
3728
  setSearchValue("");
639
3729
  if (selected === null)
@@ -690,22 +3780,23 @@ var MemoColumnItem = memo(function MemoizedItem({
690
3780
  });
691
3781
 
692
3782
  // src/column-filter/useColumnFilterStore.ts
693
- import { useCallback as useCallback2, useState as useState2 } from "react";
3783
+ import { filterAsQuery as filterAsQuery2 } from "@vuu-ui/vuu-utils";
3784
+ import { useCallback as useCallback8, useState as useState6 } from "react";
694
3785
  var addOrReplace = (array, newValue, key) => array.filter((oldValue) => oldValue[key] !== newValue[key]).concat(newValue);
695
3786
  var useColumnFilterStore = (onFilterSubmit) => {
696
3787
  var _a, _b;
697
- const [selectedColumnName, setSelectedColumnName] = useState2("");
698
- const [savedFilters, setSavedFilters] = useState2([]);
699
- const [rangeValues, setRangeValues] = useState2([]);
700
- const [typeaheadValues, setTypeaheadValues] = useState2([]);
3788
+ const [selectedColumnName, setSelectedColumnName] = useState6("");
3789
+ const [savedFilters, setSavedFilters] = useState6([]);
3790
+ const [rangeValues, setRangeValues] = useState6([]);
3791
+ const [typeaheadValues, setTypeaheadValues] = useState6([]);
701
3792
  const clear = () => {
702
3793
  setSelectedColumnName("");
703
3794
  setRangeValues([]);
704
3795
  setTypeaheadValues([]);
705
3796
  setSavedFilters([]);
706
- onFilterSubmit("");
3797
+ onFilterSubmit({ filter: "" });
707
3798
  };
708
- const updateFilters = useCallback2(
3799
+ const updateFilters = useCallback8(
709
3800
  (newFilter) => {
710
3801
  const newSavedFilters = addOrReplace(
711
3802
  savedFilters,
@@ -718,12 +3809,12 @@ var useColumnFilterStore = (onFilterSubmit) => {
718
3809
  return prev;
719
3810
  return addFilter(prev, filter, { combineWith: AND });
720
3811
  }, void 0);
721
- const query = combinedFilter === void 0 ? "" : filterAsQuery(combinedFilter);
722
- onFilterSubmit(query, combinedFilter);
3812
+ const query = combinedFilter === void 0 ? "" : filterAsQuery2(combinedFilter);
3813
+ onFilterSubmit({ filter: query, filterStruct: combinedFilter });
723
3814
  },
724
3815
  [selectedColumnName, onFilterSubmit, savedFilters]
725
3816
  );
726
- const onTypeaheadChange = useCallback2(
3817
+ const onTypeaheadChange = useCallback8(
727
3818
  (newValues, newFilter) => {
728
3819
  setTypeaheadValues(
729
3820
  addOrReplace(
@@ -736,7 +3827,7 @@ var useColumnFilterStore = (onFilterSubmit) => {
736
3827
  },
737
3828
  [selectedColumnName, typeaheadValues, updateFilters]
738
3829
  );
739
- const onRangeChange = useCallback2(
3830
+ const onRangeChange = useCallback8(
740
3831
  (newValues, newFilter) => {
741
3832
  setRangeValues(
742
3833
  addOrReplace(
@@ -749,7 +3840,7 @@ var useColumnFilterStore = (onFilterSubmit) => {
749
3840
  },
750
3841
  [selectedColumnName, rangeValues, updateFilters]
751
3842
  );
752
- const onSelectedColumnChange = useCallback2(
3843
+ const onSelectedColumnChange = useCallback8(
753
3844
  (column) => setSelectedColumnName((column == null ? void 0 : column.name) || ""),
754
3845
  []
755
3846
  );
@@ -861,7 +3952,6 @@ var ColumnFilter = ({
861
3952
  import { Button } from "@salt-ds/core";
862
3953
 
863
3954
  // src/filter-input/useCodeMirrorEditor.ts
864
- var import_classnames = __toESM(require_classnames(), 1);
865
3955
  import {
866
3956
  autocompletion,
867
3957
  defaultKeymap,
@@ -872,34 +3962,16 @@ import {
872
3962
  minimalSetup,
873
3963
  startCompletion
874
3964
  } from "@vuu-ui/vuu-codemirror";
875
- import { useEffect as useEffect2, useMemo, useRef } from "react";
3965
+ var import_classnames = __toESM(require_classnames(), 1);
3966
+ import { useEffect as useEffect6, useMemo as useMemo2, useRef as useRef2 } from "react";
876
3967
 
877
- // src/filter-input/filter-language-parser/FilterLanguage.ts
3968
+ // src/filter-input/FilterLanguage.ts
878
3969
  import {
879
3970
  LanguageSupport,
880
3971
  LRLanguage,
881
3972
  styleTags,
882
3973
  tags as tag
883
3974
  } from "@vuu-ui/vuu-codemirror";
884
-
885
- // src/filter-input/filter-language-parser/generated/filter-parser.js
886
- import { LRParser } from "@vuu-ui/vuu-codemirror";
887
- var parser = LRParser.deserialize({
888
- version: 14,
889
- states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
890
- stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
891
- goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
892
- nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
893
- maxTerm: 39,
894
- skippedNodes: [0],
895
- repeatNodeCount: 1,
896
- tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
897
- tokenizers: [0, 1],
898
- topRules: { "Filter": [0, 1] },
899
- tokenPrec: 0
900
- });
901
-
902
- // src/filter-input/filter-language-parser/FilterLanguage.ts
903
3975
  var filterLanguage = LRLanguage.define({
904
3976
  name: "VuuFilterQuery",
905
3977
  parser: parser.configure({
@@ -917,133 +3989,6 @@ var filterLanguageSupport = () => {
917
3989
  return new LanguageSupport(filterLanguage);
918
3990
  };
919
3991
 
920
- // src/filter-input/filter-language-parser/FilterTreeWalker.ts
921
- import {
922
- isMultiClauseFilter as isMultiClauseFilter2,
923
- isMultiValueFilter as isMultiValueFilter2,
924
- isSingleValueFilter as isSingleValueFilter2
925
- } from "@vuu-ui/vuu-utils";
926
- var _filter;
927
- var FilterExpression = class {
928
- constructor() {
929
- __privateAdd(this, _filter, void 0);
930
- }
931
- setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
932
- if (isMultiClauseFilter2(filter) && filter.op === op) {
933
- return;
934
- } else {
935
- __privateSet(this, _filter, {
936
- op,
937
- filters: [__privateGet(this, _filter)]
938
- });
939
- }
940
- }
941
- add(filter) {
942
- if (__privateGet(this, _filter) === void 0) {
943
- __privateSet(this, _filter, filter);
944
- } else if (isMultiClauseFilter2(__privateGet(this, _filter))) {
945
- __privateGet(this, _filter).filters.push(filter);
946
- } else {
947
- throw Error(`Invalid filter passed to FilterExpression`);
948
- }
949
- }
950
- setColumn(column, filter = __privateGet(this, _filter)) {
951
- if (isMultiClauseFilter2(filter)) {
952
- const target = filter.filters.at(-1);
953
- if (target) {
954
- this.setColumn(column, target);
955
- }
956
- } else if (filter) {
957
- filter.column = column;
958
- }
959
- }
960
- setOp(value, filter = __privateGet(this, _filter)) {
961
- if (isMultiClauseFilter2(filter)) {
962
- const target = filter.filters.at(-1);
963
- if (target) {
964
- this.setOp(value, target);
965
- }
966
- } else if (filter) {
967
- filter.op = value;
968
- }
969
- }
970
- setValue(value, filter = __privateGet(this, _filter)) {
971
- var _a;
972
- if (isMultiClauseFilter2(filter)) {
973
- const target = filter.filters.at(-1);
974
- if (target) {
975
- this.setValue(value, target);
976
- }
977
- } else if (isMultiValueFilter2(filter)) {
978
- (_a = filter.values) != null ? _a : filter.values = [];
979
- filter.values.push(value);
980
- } else if (isSingleValueFilter2(filter)) {
981
- filter.value = value;
982
- }
983
- }
984
- toJSON(filter = __privateGet(this, _filter)) {
985
- if (this.name) {
986
- return {
987
- ...filter,
988
- name: this.name
989
- };
990
- } else {
991
- return filter;
992
- }
993
- }
994
- };
995
- _filter = new WeakMap();
996
- var walkTree = (tree, source) => {
997
- const filterExpression = new FilterExpression();
998
- const cursor = tree.cursor();
999
- do {
1000
- const { name, from, to } = cursor;
1001
- switch (name) {
1002
- case "ColumnValueExpression":
1003
- filterExpression.add({});
1004
- break;
1005
- case "ColumnSetExpression":
1006
- filterExpression.add({ op: "in" });
1007
- break;
1008
- case "Or":
1009
- case "And":
1010
- filterExpression.setFilterCombinatorOp(source.substring(from, to));
1011
- break;
1012
- case "Column":
1013
- filterExpression.setColumn(source.substring(from, to));
1014
- break;
1015
- case "Operator":
1016
- filterExpression.setOp(source.substring(from, to));
1017
- break;
1018
- case "String":
1019
- filterExpression.setValue(source.substring(from + 1, to - 1));
1020
- break;
1021
- case "Number":
1022
- filterExpression.setValue(parseFloat(source.substring(from, to)));
1023
- break;
1024
- case "True":
1025
- filterExpression.setValue(true);
1026
- break;
1027
- case "False":
1028
- filterExpression.setValue(false);
1029
- break;
1030
- case "FilterName":
1031
- filterExpression.name = source.substring(from, to);
1032
- break;
1033
- default:
1034
- }
1035
- } while (cursor.next());
1036
- return filterExpression.toJSON();
1037
- };
1038
-
1039
- // src/filter-input/filter-language-parser/FilterParser.ts
1040
- var strictParser = parser.configure({ strict: true });
1041
- var parseFilter = (filterQuery) => {
1042
- const parseTree = strictParser.parse(filterQuery);
1043
- const filter = walkTree(parseTree, filterQuery);
1044
- return filter;
1045
- };
1046
-
1047
3992
  // src/filter-input/highlighting.ts
1048
3993
  import {
1049
3994
  HighlightStyle,
@@ -1136,7 +4081,7 @@ import {
1136
4081
  getValue,
1137
4082
  syntaxTree
1138
4083
  } from "@vuu-ui/vuu-codemirror";
1139
- import { useCallback as useCallback3 } from "react";
4084
+ import { useCallback as useCallback9 } from "react";
1140
4085
  var getOperator = (node, state) => {
1141
4086
  let maybeColumnNode = node.prevSibling || node.parent;
1142
4087
  while (maybeColumnNode && !["Column", "Operator", "In"].includes(maybeColumnNode.name)) {
@@ -1206,7 +4151,7 @@ var getSetValues = (node, state) => {
1206
4151
  return values;
1207
4152
  };
1208
4153
  var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
1209
- const makeSuggestions = useCallback3(
4154
+ const makeSuggestions = useCallback9(
1210
4155
  async (context, suggestionType, optionalArgs = {}) => {
1211
4156
  const { startsWith = "" } = optionalArgs;
1212
4157
  const options = await suggestionProvider.getSuggestions(
@@ -1217,7 +4162,7 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
1217
4162
  },
1218
4163
  [suggestionProvider]
1219
4164
  );
1220
- return useCallback3(
4165
+ return useCallback9(
1221
4166
  async (context) => {
1222
4167
  var _a, _b;
1223
4168
  const { state, pos } = context;
@@ -1401,15 +4346,15 @@ var useCodeMirrorEditor = ({
1401
4346
  onSubmitFilter,
1402
4347
  suggestionProvider
1403
4348
  }) => {
1404
- const editorRef = useRef(null);
1405
- const onSubmit = useRef(noop);
1406
- const viewRef = useRef();
4349
+ const editorRef = useRef2(null);
4350
+ const onSubmit = useRef2(noop);
4351
+ const viewRef = useRef2();
1407
4352
  const completionFn = useAutoComplete(
1408
4353
  suggestionProvider,
1409
4354
  onSubmit,
1410
4355
  existingFilter
1411
4356
  );
1412
- const [createState, clearInput] = useMemo(() => {
4357
+ const [createState, clearInput] = useMemo2(() => {
1413
4358
  const parseFilter2 = () => {
1414
4359
  const view = getView(viewRef);
1415
4360
  const source = view.state.doc.toString();
@@ -1484,7 +4429,7 @@ var useCodeMirrorEditor = ({
1484
4429
  };
1485
4430
  return [createState2, clearInput2];
1486
4431
  }, [completionFn, onSubmitFilter]);
1487
- useEffect2(() => {
4432
+ useEffect6(() => {
1488
4433
  if (!editorRef.current) {
1489
4434
  throw Error("editor not in dom");
1490
4435
  }
@@ -1546,11 +4491,7 @@ import {
1546
4491
  stringOperators,
1547
4492
  toSuggestions
1548
4493
  } from "@vuu-ui/vuu-codemirror";
1549
- import {
1550
- getTypeaheadParams,
1551
- useTypeaheadSuggestions as useTypeaheadSuggestions2
1552
- } from "@vuu-ui/vuu-data";
1553
- import { useCallback as useCallback4, useRef as useRef2 } from "react";
4494
+ import { useCallback as useCallback10, useRef as useRef3 } from "react";
1554
4495
 
1555
4496
  // src/filter-input/filterInfo.ts
1556
4497
  import { createEl } from "@vuu-ui/vuu-utils";
@@ -1644,11 +4585,11 @@ var useFilterSuggestionProvider = ({
1644
4585
  namedFilters,
1645
4586
  saveOptions = defaultSaveOptions,
1646
4587
  table,
1647
- typeaheadHook: useTypeahead = useTypeaheadSuggestions2
4588
+ typeaheadHook: useTypeahead = useTypeaheadSuggestions
1648
4589
  }) => {
1649
- const latestSuggestionsRef = useRef2();
4590
+ const latestSuggestionsRef = useRef3();
1650
4591
  const getTypeaheadSuggestions = useTypeahead();
1651
- const getSuggestions = useCallback4(
4592
+ const getSuggestions = useCallback10(
1652
4593
  async (suggestionType, options = NONE) => {
1653
4594
  const {
1654
4595
  columnName,
@@ -1738,7 +4679,7 @@ var useFilterSuggestionProvider = ({
1738
4679
  },
1739
4680
  [columns, getTypeaheadSuggestions, namedFilters, saveOptions, table]
1740
4681
  );
1741
- const isPartialMatch = useCallback4(
4682
+ const isPartialMatch = useCallback10(
1742
4683
  async (valueType, columnName, pattern) => {
1743
4684
  const suggestions = (
1744
4685
  // latestSuggestions && latestSuggestions.length > 0
@@ -1769,11 +4710,16 @@ var import_classnames2 = __toESM(require_classnames(), 1);
1769
4710
  import { Toolbar as Toolbar2 } from "@heswell/salt-lab";
1770
4711
 
1771
4712
  // src/filter-toolbar/useFilterToolbar.tsx
4713
+ import {
4714
+ isMultiValueFilter as isMultiValueFilter3,
4715
+ isNamedFilter,
4716
+ isSingleValueFilter as isSingleValueFilter3
4717
+ } from "@vuu-ui/vuu-utils";
1772
4718
  import { ToggleButton, ToolbarField as ToolbarField3 } from "@heswell/salt-lab";
1773
4719
 
1774
4720
  // src/filter-toolbar/FilterDropdown.tsx
1775
4721
  import { Dropdown as Dropdown2 } from "@heswell/salt-lab";
1776
- import { useCallback as useCallback5, useState as useState3 } from "react";
4722
+ import { useCallback as useCallback11, useState as useState7 } from "react";
1777
4723
  import { jsx as jsx8 } from "react/jsx-runtime";
1778
4724
  var isString = (s) => typeof s === "string";
1779
4725
  var stripQuotes = (selected) => {
@@ -1795,9 +4741,9 @@ var FilterDropdown = ({
1795
4741
  }) => {
1796
4742
  const selected = selectedProp != null ? stripQuotes(selectedProp) : void 0;
1797
4743
  const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
1798
- const [values, setValues] = useState3(initialValues);
4744
+ const [values, setValues] = useState7(initialValues);
1799
4745
  console.log({ initialValues });
1800
- const handleOpenChange = useCallback5(
4746
+ const handleOpenChange = useCallback11(
1801
4747
  async (isOpen) => {
1802
4748
  if (isOpen) {
1803
4749
  const values2 = await suggestionProvider.getSuggestions("columnValue", {
@@ -1822,7 +4768,7 @@ var FilterDropdown = ({
1822
4768
 
1823
4769
  // src/filter-toolbar/FilterDropdownMultiSelect.tsx
1824
4770
  import { Dropdown as Dropdown3 } from "@heswell/salt-lab";
1825
- import { useCallback as useCallback6, useState as useState4 } from "react";
4771
+ import { useCallback as useCallback12, useState as useState8 } from "react";
1826
4772
  import { jsx as jsx9 } from "react/jsx-runtime";
1827
4773
  var isString2 = (s) => typeof s === "string";
1828
4774
  var stripQuotes2 = (selected) => {
@@ -1846,8 +4792,8 @@ var FilterDropdownMultiSelect = ({
1846
4792
  }) => {
1847
4793
  const selected = stripQuotes2(selectedProp);
1848
4794
  const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
1849
- const [values, setValues] = useState4(initialValues);
1850
- const handleOpenChange = useCallback6(
4795
+ const [values, setValues] = useState8(initialValues);
4796
+ const handleOpenChange = useCallback12(
1851
4797
  async (isOpen) => {
1852
4798
  if (isOpen) {
1853
4799
  const values2 = await suggestionProvider.getSuggestions("columnValue", {
@@ -1885,7 +4831,7 @@ var filterToControl = (filter, suggestionProvider) => {
1885
4831
  }
1886
4832
  );
1887
4833
  }
1888
- if (isSingleValueFilter(filter)) {
4834
+ if (isSingleValueFilter3(filter)) {
1889
4835
  const { column, value } = filter;
1890
4836
  return /* @__PURE__ */ jsx10(
1891
4837
  ToolbarField3,
@@ -1908,7 +4854,7 @@ var filterToControl = (filter, suggestionProvider) => {
1908
4854
  column
1909
4855
  );
1910
4856
  }
1911
- if (isMultiValueFilter(filter)) {
4857
+ if (isMultiValueFilter3(filter)) {
1912
4858
  const values = filter.values.map((v) => v.toString());
1913
4859
  return /* @__PURE__ */ jsx10(
1914
4860
  ToolbarField3,
@@ -1956,91 +4902,6 @@ var FilterToolbar = ({
1956
4902
  const toolbarItems = useFilterToolbar({ filter, suggestionProvider });
1957
4903
  return /* @__PURE__ */ jsx11(Toolbar2, { className: (0, import_classnames2.default)("vuuFilterToolbar", className), ...props, children: toolbarItems });
1958
4904
  };
1959
-
1960
- // src/filter-evaluation-utils.ts
1961
- var filterPredicateMap = /* @__PURE__ */ new Map();
1962
- var filterReject = () => false;
1963
- var getFilterPredicate = (columnMap, filterQuery) => {
1964
- let predicate = filterPredicateMap.get(filterQuery);
1965
- if (predicate) {
1966
- return predicate;
1967
- }
1968
- try {
1969
- const filter = parseFilter(filterQuery);
1970
- predicate = filterPredicate(columnMap, filter);
1971
- filterPredicateMap.set(filterQuery, predicate);
1972
- return predicate;
1973
- } catch (err) {
1974
- console.warn(
1975
- `filter-evaluation-utils, failed to parse filter "${filterQuery}"`
1976
- );
1977
- return filterReject;
1978
- }
1979
- };
1980
- function filterPredicate(columnMap, filter) {
1981
- switch (filter.op) {
1982
- case "in":
1983
- return testInclude(columnMap, filter);
1984
- case "=":
1985
- return testEQ(columnMap, filter);
1986
- case ">":
1987
- return testGT(columnMap, filter);
1988
- case ">=":
1989
- return testGE(columnMap, filter);
1990
- case "<":
1991
- return testLT(columnMap, filter);
1992
- case "<=":
1993
- return testLE(columnMap, filter);
1994
- case "starts":
1995
- return testSW(columnMap, filter);
1996
- case "and":
1997
- return testAND(columnMap, filter);
1998
- case "or":
1999
- return testOR(columnMap, filter);
2000
- default:
2001
- console.log(`unrecognized filter type ${filter.op}`);
2002
- return () => true;
2003
- }
2004
- }
2005
- var testInclude = (columnMap, filter) => {
2006
- return (row) => filter.values.indexOf(row[columnMap[filter.column]]) !== -1;
2007
- };
2008
- var testEQ = (columnMap, filter) => {
2009
- return (row) => row[columnMap[filter.column]] === filter.value;
2010
- };
2011
- var testGT = (columnMap, filter) => {
2012
- return (row) => row[columnMap[filter.column]] > filter.value;
2013
- };
2014
- var testGE = (columnMap, filter) => {
2015
- return (row) => row[columnMap[filter.column]] >= filter.value;
2016
- };
2017
- var testLT = (columnMap, filter) => {
2018
- return (row) => row[columnMap[filter.column]] < filter.value;
2019
- };
2020
- var testLE = (columnMap, filter) => {
2021
- return (row) => row[columnMap[filter.column]] <= filter.value;
2022
- };
2023
- var testSW = (columnMap, filter) => {
2024
- const filterValue2 = filter.value;
2025
- if (typeof filterValue2 !== "string") {
2026
- throw Error("string filter applied to value of wrong type");
2027
- }
2028
- return (row) => {
2029
- const rowValue = row[columnMap[filter.column]];
2030
- if (typeof rowValue !== "string") {
2031
- throw Error("string filter applied to value of wrong type");
2032
- }
2033
- return rowValue.toLowerCase().startsWith(filterValue2.toLowerCase());
2034
- };
2035
- };
2036
- var testAND = (columnMap, filter) => {
2037
- const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
2038
- return (row) => filters.every((fn) => fn(row));
2039
- };
2040
- function testOR(columnMap, filter) {
2041
- const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
2042
- return (row) => filters.some((fn) => fn(row));
2043
- }
2044
4905
  export {
2045
4906
  AND,
2046
4907
  ColumnFilter,
@@ -2054,23 +4915,10 @@ export {
2054
4915
  OR,
2055
4916
  STARTS_WITH,
2056
4917
  addFilter,
2057
- filterAsQuery,
2058
4918
  filterClauses,
2059
4919
  filterEquals,
2060
4920
  filterIncludesColumn,
2061
- filterPredicate,
2062
- getFilterPredicate,
2063
- isAndFilter,
2064
- isFilterClause,
2065
- isInFilter,
2066
- isMultiClauseFilter,
2067
- isMultiValueFilter,
2068
- isNamedFilter,
2069
- isOrFilter,
2070
- isSingleValueFilter,
2071
4921
  overrideColName,
2072
- parseFilter,
2073
- removeColumnFromFilter,
2074
4922
  removeFilter,
2075
4923
  splitFilterOnColumn,
2076
4924
  updateFilter,