@vuu-ui/vuu-filters 0.7.6 → 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/cjs/index.js CHANGED
@@ -1,34 +1,4882 @@
1
- "use strict";var Qo=Object.create;var oe=Object.defineProperty;var Ao=Object.getOwnPropertyDescriptor;var ko=Object.getOwnPropertyNames;var Mo=Object.getPrototypeOf,Lo=Object.prototype.hasOwnProperty;var Uo=(e,o)=>()=>(o||e((o={exports:{}}).exports,o),o.exports),Wo=(e,o)=>{for(var r in o)oe(e,r,{get:o[r],enumerable:!0})},De=(e,o,r,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ko(o))!Lo.call(e,n)&&n!==r&&oe(e,n,{get:()=>o[n],enumerable:!(t=Ao(o,n))||t.enumerable});return e};var Ve=(e,o,r)=>(r=e!=null?Qo(Mo(e)):{},De(o||!e||!e.__esModule?oe(r,"default",{value:e,enumerable:!0}):r,e)),Ho=e=>De(oe({},"__esModule",{value:!0}),e);var Qe=(e,o,r)=>{if(!o.has(e))throw TypeError("Cannot "+r)};var R=(e,o,r)=>(Qe(e,o,"read from private field"),r?r.call(e):o.get(e)),Ae=(e,o,r)=>{if(o.has(e))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(e):o.set(e,r)},Ie=(e,o,r,t)=>(Qe(e,o,"write to private field"),t?t.call(e,r):o.set(e,r),r);var Te=Uo((yt,le)=>{(function(){"use strict";var e={}.hasOwnProperty,o="[native code]";function r(){for(var t=[],n=0;n<arguments.length;n++){var i=arguments[n];if(i){var s=typeof i;if(s==="string"||s==="number")t.push(i);else if(Array.isArray(i)){if(i.length){var p=r.apply(null,i);p&&t.push(p)}}else if(s==="object"){if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]")){t.push(i.toString());continue}for(var f in i)e.call(i,f)&&i[f]&&t.push(f)}}}return t.join(" ")}typeof le<"u"&&le.exports?(r.default=r,le.exports=r):typeof define=="function"&&typeof define.amd=="object"&&define.amd?define("classnames",[],function(){return r}):window.classNames=r})()});var $r={};Wo($r,{AND:()=>h,ColumnFilter:()=>ar,ENDS_WITH:()=>Yo,EQUALS:()=>te,FilterInput:()=>Ir,FilterToolbar:()=>Nr,GREATER_THAN:()=>jo,IN:()=>$e,LESS_THAN:()=>Zo,OR:()=>Be,STARTS_WITH:()=>Oe,addFilter:()=>G,filterAsQuery:()=>H,filterClauses:()=>ze,filterEquals:()=>ne,filterIncludesColumn:()=>_e,filterPredicate:()=>ge,getFilterPredicate:()=>Vr,isAndFilter:()=>re,isFilterClause:()=>Go,isInFilter:()=>W,isMultiClauseFilter:()=>V,isMultiValueFilter:()=>D,isNamedFilter:()=>he,isOrFilter:()=>Ce,isSingleValueFilter:()=>k,overrideColName:()=>Xe,parseFilter:()=>Y,removeColumnFromFilter:()=>tr,removeFilter:()=>nr,splitFilterOnColumn:()=>ir,updateFilter:()=>je,useCodeMirrorEditor:()=>Ee,useFilterSuggestionProvider:()=>Rr});module.exports=Ho($r);var P=require("@heswell/salt-lab"),no=require("@salt-ds/core");var Se=require("react/jsx-runtime"),Ue=require("react");function ke(e){var o,r,t="";if(typeof e=="string"||typeof e=="number")t+=e;else if(typeof e=="object")if(Array.isArray(e))for(o=0;o<e.length;o++)e[o]&&(r=ke(e[o]))&&(t&&(t+=" "),t+=r);else for(o in e)e[o]&&(t&&(t+=" "),t+=o);return t}function Me(){for(var e,o,r=0,t="";r<arguments.length;)(e=arguments[r++])&&(o=ke(e))&&(t&&(t+=" "),t+=o);return t}function Le(e,o){o===void 0&&(o={});var r=o.insertAt;if(!(!e||typeof document>"u")){var t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css",r==="top"&&t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}var Bo=`/* Style applied to the root element */
2
- .saltIcon {
3
- --icon-color: var(--saltIcon-color, var(--salt-text-secondary-foreground));
4
- --icon-size-multiplier: var(--saltIcon-size-multiplier, 1);
5
- --icon-base-size: var(--salt-size-icon-base, 12px);
6
- /**
7
- * Icon size will be the multiplier (an integer from the size prop) * the base size (set by the theme per density)
8
- * Icons should never be smaller than 12px for readability so we've added a max() to enforce this
9
- */
10
- --icon-size: max(calc(var(--icon-base-size) * var(--icon-size-multiplier)), 12px);
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var __accessCheck = (obj, member, msg) => {
33
+ if (!member.has(obj))
34
+ throw TypeError("Cannot " + msg);
35
+ };
36
+ var __privateGet = (obj, member, getter) => {
37
+ __accessCheck(obj, member, "read from private field");
38
+ return getter ? getter.call(obj) : member.get(obj);
39
+ };
40
+ var __privateAdd = (obj, member, value) => {
41
+ if (member.has(obj))
42
+ throw TypeError("Cannot add the same private member more than once");
43
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
44
+ };
45
+ var __privateSet = (obj, member, value, setter) => {
46
+ __accessCheck(obj, member, "write to private field");
47
+ setter ? setter.call(obj, value) : member.set(obj, value);
48
+ return value;
49
+ };
50
+
51
+ // ../../node_modules/classnames/index.js
52
+ var require_classnames = __commonJS({
53
+ "../../node_modules/classnames/index.js"(exports, module2) {
54
+ (function() {
55
+ "use strict";
56
+ var hasOwn = {}.hasOwnProperty;
57
+ var nativeCodeString = "[native code]";
58
+ function classNames() {
59
+ var classes = [];
60
+ for (var i = 0; i < arguments.length; i++) {
61
+ var arg = arguments[i];
62
+ if (!arg)
63
+ continue;
64
+ var argType = typeof arg;
65
+ if (argType === "string" || argType === "number") {
66
+ classes.push(arg);
67
+ } else if (Array.isArray(arg)) {
68
+ if (arg.length) {
69
+ var inner = classNames.apply(null, arg);
70
+ if (inner) {
71
+ classes.push(inner);
72
+ }
73
+ }
74
+ } else if (argType === "object") {
75
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
76
+ classes.push(arg.toString());
77
+ continue;
78
+ }
79
+ for (var key in arg) {
80
+ if (hasOwn.call(arg, key) && arg[key]) {
81
+ classes.push(key);
82
+ }
83
+ }
84
+ }
85
+ }
86
+ return classes.join(" ");
87
+ }
88
+ if (typeof module2 !== "undefined" && module2.exports) {
89
+ classNames.default = classNames;
90
+ module2.exports = classNames;
91
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
92
+ define("classnames", [], function() {
93
+ return classNames;
94
+ });
95
+ } else {
96
+ window.classNames = classNames;
97
+ }
98
+ })();
99
+ }
100
+ });
101
+
102
+ // src/index.ts
103
+ var src_exports = {};
104
+ __export(src_exports, {
105
+ AND: () => AND,
106
+ ColumnFilter: () => ColumnFilter,
107
+ ENDS_WITH: () => ENDS_WITH,
108
+ EQUALS: () => EQUALS,
109
+ FilterInput: () => FilterInput,
110
+ FilterToolbar: () => FilterToolbar,
111
+ GREATER_THAN: () => GREATER_THAN,
112
+ IN: () => IN,
113
+ LESS_THAN: () => LESS_THAN,
114
+ OR: () => OR,
115
+ STARTS_WITH: () => STARTS_WITH,
116
+ addFilter: () => addFilter,
117
+ filterClauses: () => filterClauses,
118
+ filterEquals: () => filterEquals,
119
+ filterIncludesColumn: () => filterIncludesColumn,
120
+ overrideColName: () => overrideColName,
121
+ removeFilter: () => removeFilter,
122
+ splitFilterOnColumn: () => splitFilterOnColumn,
123
+ updateFilter: () => updateFilter,
124
+ useCodeMirrorEditor: () => useCodeMirrorEditor,
125
+ useFilterSuggestionProvider: () => useFilterSuggestionProvider
126
+ });
127
+ module.exports = __toCommonJS(src_exports);
128
+
129
+ // src/column-filter/ColumnFilter.tsx
130
+ var import_salt_lab4 = require("@heswell/salt-lab");
131
+ var import_core = require("@salt-ds/core");
132
+
133
+ // ../../node_modules/@salt-ds/icons/dist-es/packages/icons/src/icon/Icon.js
134
+ var import_jsx_runtime = require("react/jsx-runtime");
135
+ var import_react = require("react");
136
+
137
+ // ../../node_modules/clsx/dist/clsx.m.js
138
+ function r(e) {
139
+ var t, f, n = "";
140
+ if ("string" == typeof e || "number" == typeof e)
141
+ n += e;
142
+ else if ("object" == typeof e)
143
+ if (Array.isArray(e))
144
+ for (t = 0; t < e.length; t++)
145
+ e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
146
+ else
147
+ for (t in e)
148
+ e[t] && (n && (n += " "), n += t);
149
+ return n;
150
+ }
151
+ function clsx() {
152
+ for (var e, t, f = 0, n = ""; f < arguments.length; )
153
+ (e = arguments[f++]) && (t = r(e)) && (n && (n += " "), n += t);
154
+ return n;
11
155
  }
12
156
 
13
- .saltIcon {
14
- fill: var(--saltIcon-color, var(--icon-color));
15
- display: inline-block;
16
- margin: var(--saltIcon-margin, 0);
17
- position: relative;
18
- width: var(--icon-size);
19
- height: var(--icon-size);
20
- min-width: var(--icon-size);
21
- min-height: var(--icon-size);
157
+ // ../../node_modules/@salt-ds/icons/dist-es/node_modules/style-inject/dist/style-inject.es.js
158
+ function styleInject(css, ref) {
159
+ if (ref === void 0)
160
+ ref = {};
161
+ var insertAt = ref.insertAt;
162
+ if (!css || typeof document === "undefined") {
163
+ return;
164
+ }
165
+ var head = document.head || document.getElementsByTagName("head")[0];
166
+ var style = document.createElement("style");
167
+ style.type = "text/css";
168
+ if (insertAt === "top") {
169
+ if (head.firstChild) {
170
+ head.insertBefore(style, head.firstChild);
171
+ } else {
172
+ head.appendChild(style);
173
+ }
174
+ } else {
175
+ head.appendChild(style);
176
+ }
177
+ if (style.styleSheet) {
178
+ style.styleSheet.cssText = css;
179
+ } else {
180
+ style.appendChild(document.createTextNode(css));
181
+ }
22
182
  }
23
183
 
24
- .saltIcon:hover {
25
- --icon-color: var(--saltIcon-color-hover, var(--salt-text-secondary-foreground));
184
+ // ../../node_modules/@salt-ds/icons/dist-es/packages/icons/src/icon/Icon.css.js
185
+ var css_248z = "/* Style applied to the root element */\n.saltIcon {\n --icon-color: var(--saltIcon-color, var(--salt-text-secondary-foreground));\n --icon-size-multiplier: var(--saltIcon-size-multiplier, 1);\n --icon-base-size: var(--salt-size-icon-base, 12px);\n /**\n * Icon size will be the multiplier (an integer from the size prop) * the base size (set by the theme per density)\n * Icons should never be smaller than 12px for readability so we've added a max() to enforce this\n */\n --icon-size: max(calc(var(--icon-base-size) * var(--icon-size-multiplier)), 12px);\n}\n\n.saltIcon {\n fill: var(--saltIcon-color, var(--icon-color));\n display: inline-block;\n margin: var(--saltIcon-margin, 0);\n position: relative;\n width: var(--icon-size);\n height: var(--icon-size);\n min-width: var(--icon-size);\n min-height: var(--icon-size);\n}\n\n.saltIcon:hover {\n --icon-color: var(--saltIcon-color-hover, var(--salt-text-secondary-foreground));\n}\n\n.saltIcon:active {\n --icon-color: var(--saltIcon-color-active, var(--salt-text-secondary-foreground));\n}\n";
186
+ styleInject(css_248z);
187
+
188
+ // ../../node_modules/@salt-ds/icons/dist-es/packages/icons/src/icon/Icon.js
189
+ var makePrefixer = (prefix) => (...names) => [prefix, ...names].join("-");
190
+ var withBaseName = makePrefixer("saltIcon");
191
+ var DEFAULT_ICON_SIZE = 1;
192
+ var Icon = (0, import_react.forwardRef)(function Icon2({ children, className, size = DEFAULT_ICON_SIZE, style: styleProp, ...rest }, ref) {
193
+ const style = {
194
+ ...styleProp,
195
+ "--saltIcon-size-multiplier": `${size}`
196
+ };
197
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
198
+ className: clsx(withBaseName(), className),
199
+ style,
200
+ role: "img",
201
+ ...rest,
202
+ ref,
203
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", {
204
+ "aria-hidden": true,
205
+ children
206
+ })
207
+ });
208
+ });
209
+
210
+ // ../../node_modules/@salt-ds/icons/dist-es/packages/icons/src/components/Delete.js
211
+ var import_jsx_runtime2 = require("react/jsx-runtime");
212
+ var import_react2 = require("react");
213
+ var DeleteIcon = (0, import_react2.forwardRef)(
214
+ function DeleteIcon2(props, ref) {
215
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Icon, {
216
+ "data-testid": "DeleteIcon",
217
+ "aria-label": "delete",
218
+ viewBox: "0 0 12 12",
219
+ ref,
220
+ ...props,
221
+ children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", {
223
+ d: "M5 4v6H4V4h1Zm2 0v6H6V4h1Z"
224
+ }),
225
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", {
226
+ fillRule: "evenodd",
227
+ d: "M4 0a1 1 0 0 0-1 1v1H0v1h1v7a2 2 0 0 0 2 2h5.25A1.75 1.75 0 0 0 10 10.25V3h1V2H8V1a1 1 0 0 0-1-1H4Zm5 3H2v7a1 1 0 0 0 1 1h5.25a.75.75 0 0 0 .75-.75V3ZM7 2H4v-.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V2Z",
228
+ clipRule: "evenodd"
229
+ })
230
+ ]
231
+ });
232
+ }
233
+ );
234
+
235
+ // src/column-filter/RangeFilter.tsx
236
+ var import_salt_lab = require("@heswell/salt-lab");
237
+
238
+ // src/filter-utils.ts
239
+ var import_vuu_utils = require("@vuu-ui/vuu-utils");
240
+ var AND = "and";
241
+ var EQUALS = "=";
242
+ var GREATER_THAN = ">";
243
+ var LESS_THAN = "<";
244
+ var OR = "or";
245
+ var STARTS_WITH = "starts";
246
+ var ENDS_WITH = "ends";
247
+ var IN = "in";
248
+ var filterClauses = (filter, clauses = []) => {
249
+ if (filter) {
250
+ if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
251
+ filter.filters.forEach((f) => clauses.push(...filterClauses(f)));
252
+ } else {
253
+ clauses.push(filter);
254
+ }
255
+ }
256
+ return clauses;
257
+ };
258
+ var DEFAULT_ADD_FILTER_OPTS = {
259
+ combineWith: "and"
260
+ };
261
+ var addFilter = (existingFilter, filter, { combineWith = AND } = DEFAULT_ADD_FILTER_OPTS) => {
262
+ var _a;
263
+ if (includesNoValues(filter)) {
264
+ if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
265
+ } else {
266
+ existingFilter = removeFilterForColumn(existingFilter, {
267
+ name: filter.column
268
+ });
269
+ }
270
+ } else if (includesAllValues(filter)) {
271
+ if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
272
+ }
273
+ return removeFilterForColumn(existingFilter, { name: (_a = filter.column) != null ? _a : "" });
274
+ }
275
+ if (!existingFilter) {
276
+ return filter;
277
+ }
278
+ if (!filter) {
279
+ return existingFilter;
280
+ }
281
+ if (existingFilter.op === AND && filter.op === AND) {
282
+ return {
283
+ op: AND,
284
+ filters: combine(existingFilter.filters, filter.filters)
285
+ };
286
+ }
287
+ if (existingFilter.op === AND) {
288
+ const filters = replaceOrInsert(existingFilter.filters, filter);
289
+ return filters.length > 1 ? { op: AND, filters } : filters[0];
290
+ }
291
+ if (filter.op === AND) {
292
+ return { op: AND, filters: filter.filters.concat(existingFilter) };
293
+ }
294
+ if (filterEquals(existingFilter, filter, true)) {
295
+ return filter;
296
+ }
297
+ if (canMerge(existingFilter, filter)) {
298
+ return merge(existingFilter, filter);
299
+ }
300
+ return { op: combineWith, filters: [existingFilter, filter] };
301
+ };
302
+ var includesNoValues = (filter) => {
303
+ if (!filter) {
304
+ return false;
305
+ }
306
+ if ((0, import_vuu_utils.isInFilter)(filter) && filter.values.length === 0) {
307
+ return true;
308
+ }
309
+ return (0, import_vuu_utils.isAndFilter)(filter) && filter.filters.some((f) => includesNoValues(f));
310
+ };
311
+ var includesAllValues = (filter) => {
312
+ if (!filter) {
313
+ return false;
314
+ }
315
+ if (filter.op === STARTS_WITH && filter.value === "") {
316
+ return true;
317
+ }
318
+ return filter.op === STARTS_WITH && filter.value === "";
319
+ };
320
+ var replaceOrInsert = (filters, filter) => {
321
+ return filters.concat(filter);
322
+ };
323
+ var merge = (f1, f2) => {
324
+ if (includesNoValues(f2)) {
325
+ return f2;
326
+ }
327
+ if ((0, import_vuu_utils.isInFilter)(f1) && (0, import_vuu_utils.isInFilter)(f2)) {
328
+ return {
329
+ ...f1,
330
+ values: [
331
+ ...f1.values,
332
+ ...f2.values.filter(
333
+ (v) => !f1.values.includes(v)
334
+ )
335
+ ]
336
+ };
337
+ } else if ((0, import_vuu_utils.isInFilter)(f1) && f2.op === EQUALS) {
338
+ return {
339
+ ...f1,
340
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
341
+ // @ts-ignore
342
+ values: f1.values.concat([f2.value])
343
+ };
344
+ } else if (f1.op === EQUALS && f2.op === EQUALS) {
345
+ return {
346
+ column: f1.column,
347
+ op: IN,
348
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
349
+ // @ts-ignore
350
+ values: [f1.value, f2.value]
351
+ };
352
+ }
353
+ return f2;
354
+ };
355
+ var combine = (existingFilters, replacementFilters) => {
356
+ const equivalentType = ({ op: t1 }, { op: t2 }) => {
357
+ return t1 === t2 || t1[0] === t2[0];
358
+ };
359
+ const replaces = (existingFilter, replacementFilter) => {
360
+ return existingFilter.column === replacementFilter.column && equivalentType(existingFilter, replacementFilter);
361
+ };
362
+ const stillApplicable = (existingFilter) => replacementFilters.some(
363
+ (replacementFilter) => replaces(existingFilter, replacementFilter)
364
+ ) === false;
365
+ return existingFilters.filter(stillApplicable).concat(replacementFilters);
366
+ };
367
+ var removeFilter = (sourceFilter, filterToRemove) => {
368
+ if (filterEquals(sourceFilter, filterToRemove, true)) {
369
+ return null;
370
+ }
371
+ if (sourceFilter.op !== AND) {
372
+ throw Error(
373
+ `removeFilter cannot remove ${JSON.stringify(
374
+ filterToRemove
375
+ )} from ${JSON.stringify(sourceFilter)}`
376
+ );
377
+ }
378
+ const filters = sourceFilter.filters.filter(
379
+ (f) => !filterEquals(f, filterToRemove)
380
+ );
381
+ return filters.length > 0 ? { type: AND, filters } : null;
382
+ };
383
+ var splitFilterOnColumn = (columnName, filter) => {
384
+ if (!filter) {
385
+ return [void 0, void 0];
386
+ }
387
+ if (filter.column === columnName) {
388
+ return [filter, void 0];
389
+ }
390
+ if (filter.op !== AND) {
391
+ return [void 0, filter];
392
+ }
393
+ const [[columnFilter = void 0], filters] = (0, import_vuu_utils.partition)(
394
+ filter.filters,
395
+ (f) => f.column === columnName
396
+ );
397
+ return filters.length === 1 ? [columnFilter, filters[0]] : [columnFilter, { op: AND, filters }];
398
+ };
399
+ var overrideColName = (filter, column) => {
400
+ if ((0, import_vuu_utils.isMultiClauseFilter)(filter)) {
401
+ return {
402
+ op: filter.op,
403
+ filters: filter.filters.map((f) => overrideColName(f, column))
404
+ };
405
+ }
406
+ return { ...filter, column };
407
+ };
408
+ var filterIncludesColumn = (filter, column) => {
409
+ if (!filter) {
410
+ return false;
411
+ }
412
+ const { op, column: filterColName } = filter;
413
+ switch (op) {
414
+ case AND:
415
+ case OR:
416
+ return filter.filters != null && filter.filters.some((f) => filterIncludesColumn(f, column));
417
+ default:
418
+ return filterColName === column.name;
419
+ }
420
+ };
421
+ var removeFilterForColumn = (sourceFilter, column) => {
422
+ const colName = column.name;
423
+ if (!sourceFilter) {
424
+ return void 0;
425
+ }
426
+ if (sourceFilter.column === colName) {
427
+ return void 0;
428
+ }
429
+ if ((0, import_vuu_utils.isAndFilter)(sourceFilter) || (0, import_vuu_utils.isOrFilter)(sourceFilter)) {
430
+ const { op } = sourceFilter;
431
+ const filters = sourceFilter.filters;
432
+ const otherColFilters = filters.filter((f) => f.column !== colName);
433
+ switch (otherColFilters.length) {
434
+ case 0:
435
+ return void 0;
436
+ case 1:
437
+ return otherColFilters[0];
438
+ default:
439
+ return { op, filters: otherColFilters };
440
+ }
441
+ }
442
+ return sourceFilter;
443
+ };
444
+ var canMerge = (f1, f2) => f1.column === f2.column && (f1.op === "=" || f1.op === "in") && (f2.op === "=" || f2.op === "in");
445
+ var sameValues = (arr1, arr2) => {
446
+ if (arr1 === arr2) {
447
+ return true;
448
+ }
449
+ if (arr1.length === arr2.length) {
450
+ const a = arr1.slice().sort();
451
+ const b = arr2.slice().sort();
452
+ return a.join("|") === b.join("|");
453
+ }
454
+ return false;
455
+ };
456
+ var filterEquals = (f1, f2, strict = false) => {
457
+ if (!strict) {
458
+ return true;
459
+ }
460
+ if (f1 && f2 && canMerge(f1, f2)) {
461
+ return f1.op === f2.op && ((0, import_vuu_utils.isSingleValueFilter)(f1) && (0, import_vuu_utils.isSingleValueFilter)(f2) && f1.value === f2.value || (0, import_vuu_utils.isMultiValueFilter)(f1) && (0, import_vuu_utils.isMultiValueFilter)(f2) && sameValues(f1.values, f2.values));
462
+ }
463
+ return false;
464
+ };
465
+ var updateFilter = (filter, newFilter, mode) => {
466
+ if (filter && newFilter) {
467
+ if (mode === "replace") {
468
+ return newFilter;
469
+ }
470
+ if (filter.op === "and") {
471
+ return {
472
+ ...filter,
473
+ filters: filter.filters.concat(newFilter)
474
+ };
475
+ }
476
+ const { column: columnName } = newFilter;
477
+ if (columnName) {
478
+ const existingClause = newFilter.column ? (0, import_vuu_utils.extractFilterForColumn)(filter, columnName) : void 0;
479
+ if (existingClause && columnName) {
480
+ const result = removeFilterForColumn(filter, { name: columnName });
481
+ return updateFilter(result, newFilter, "add");
482
+ }
483
+ }
484
+ return {
485
+ op: "and",
486
+ filters: [filter, newFilter]
487
+ };
488
+ }
489
+ if (newFilter) {
490
+ return newFilter;
491
+ }
492
+ return filter;
493
+ };
494
+
495
+ // src/column-filter/utils.ts
496
+ var isStartsWithValue = (value) => /\.\.\.$/.test(value);
497
+ var getTypeaheadFilter = (column, filterValues, isStartsWithFilter) => {
498
+ if (filterValues.length === 0) {
499
+ return void 0;
500
+ }
501
+ if (isStartsWithFilter) {
502
+ const startsWith = filterValues[0].substring(0, filterValues[0].length - 3);
503
+ return {
504
+ column,
505
+ op: "starts",
506
+ value: `"${startsWith}"`
507
+ };
508
+ }
509
+ return {
510
+ column,
511
+ op: "in",
512
+ values: filterValues.map((value) => `"${value}"`)
513
+ };
514
+ };
515
+ var getRangeFilter = (column, startValue, endValue) => {
516
+ const startFilter = startValue === void 0 ? void 0 : { column, op: ">", value: startValue - 1 };
517
+ const endFilter = endValue === void 0 ? void 0 : { column, op: "<", value: endValue + 1 };
518
+ if (endFilter === void 0)
519
+ return startFilter;
520
+ return addFilter(startFilter, endFilter, { combineWith: "and" });
521
+ };
522
+
523
+ // src/column-filter/RangeFilter.tsx
524
+ var import_jsx_runtime3 = require("react/jsx-runtime");
525
+ var RangeFilter = ({
526
+ defaultTypeaheadParams,
527
+ filterValues,
528
+ onChange
529
+ }) => {
530
+ var _a, _b;
531
+ const columnName = defaultTypeaheadParams[1];
532
+ const startChangeHandler = (e) => {
533
+ const value = parseFloat(e.target.value);
534
+ const newRange = {
535
+ start: isNaN(value) ? void 0 : value,
536
+ end: filterValues == null ? void 0 : filterValues.end
537
+ };
538
+ const filter = getRangeFilter(columnName, newRange.start, newRange.end);
539
+ onChange(newRange, filter);
540
+ };
541
+ const endChangeHandler = (e) => {
542
+ const value = parseFloat(e.target.value);
543
+ const newRange = {
544
+ start: filterValues == null ? void 0 : filterValues.start,
545
+ end: isNaN(value) ? void 0 : value
546
+ };
547
+ const filter = getRangeFilter(columnName, newRange.start, newRange.end);
548
+ onChange(newRange, filter);
549
+ };
550
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "row" }, children: [
551
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "From", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
552
+ import_salt_lab.Input,
553
+ {
554
+ onChange: startChangeHandler,
555
+ value: ((_a = filterValues == null ? void 0 : filterValues.start) == null ? void 0 : _a.toString()) || "",
556
+ type: "number"
557
+ }
558
+ ) }),
559
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_salt_lab.ToolbarField, { label: "To", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
560
+ import_salt_lab.Input,
561
+ {
562
+ onChange: endChangeHandler,
563
+ value: ((_b = filterValues == null ? void 0 : filterValues.end) == null ? void 0 : _b.toString()) || "",
564
+ type: "number"
565
+ }
566
+ ) })
567
+ ] });
568
+ };
569
+
570
+ // ../vuu-data-react/src/hooks/useDataSource.ts
571
+ var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
572
+ var import_react3 = require("react");
573
+ var { SELECTED } = import_vuu_utils2.metadataKeys;
574
+
575
+ // ../vuu-data-react/src/hooks/useServerConnectionStatus.ts
576
+ var import_react4 = require("react");
577
+ var import_vuu_data = require("@vuu-ui/vuu-data");
578
+
579
+ // ../vuu-data-react/src/hooks/useServerConnectionQuality.ts
580
+ var import_react5 = require("react");
581
+ var import_vuu_data2 = require("@vuu-ui/vuu-data");
582
+
583
+ // ../vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
584
+ var import_react6 = require("react");
585
+ var import_vuu_data3 = require("@vuu-ui/vuu-data");
586
+ var TYPEAHEAD_MESSAGE_CONSTANTS = {
587
+ type: "RPC_CALL",
588
+ service: "TypeAheadRpcHandler"
589
+ };
590
+ var getTypeaheadParams = (table, column, text = "", selectedValues = []) => {
591
+ if (text !== "" && !selectedValues.includes(text.toLowerCase())) {
592
+ return [table, column, text];
593
+ }
594
+ return [table, column];
595
+ };
596
+ var useTypeaheadSuggestions = () => {
597
+ const getTypeaheadSuggestions = (0, import_react6.useCallback)(
598
+ async (params) => {
599
+ const rpcMessage = params.length === 2 ? {
600
+ method: "getUniqueFieldValues",
601
+ params,
602
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
603
+ } : {
604
+ method: "getUniqueFieldValuesStartingWith",
605
+ params,
606
+ ...TYPEAHEAD_MESSAGE_CONSTANTS
607
+ };
608
+ const suggestions = await (0, import_vuu_data3.makeRpcCall)(rpcMessage);
609
+ return suggestions;
610
+ },
611
+ []
612
+ );
613
+ return getTypeaheadSuggestions;
614
+ };
615
+
616
+ // ../../node_modules/@lezer/common/dist/index.js
617
+ var DefaultBufferLength = 1024;
618
+ var nextPropID = 0;
619
+ var Range = class {
620
+ constructor(from, to) {
621
+ this.from = from;
622
+ this.to = to;
623
+ }
624
+ };
625
+ var NodeProp = class {
626
+ /// Create a new node prop type.
627
+ constructor(config = {}) {
628
+ this.id = nextPropID++;
629
+ this.perNode = !!config.perNode;
630
+ this.deserialize = config.deserialize || (() => {
631
+ throw new Error("This node type doesn't define a deserialize function");
632
+ });
633
+ }
634
+ /// This is meant to be used with
635
+ /// [`NodeSet.extend`](#common.NodeSet.extend) or
636
+ /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
637
+ /// prop values for each node type in the set. Takes a [match
638
+ /// object](#common.NodeType^match) or function that returns undefined
639
+ /// if the node type doesn't get this prop, and the prop's value if
640
+ /// it does.
641
+ add(match) {
642
+ if (this.perNode)
643
+ throw new RangeError("Can't add per-node props to node types");
644
+ if (typeof match != "function")
645
+ match = NodeType.match(match);
646
+ return (type) => {
647
+ let result = match(type);
648
+ return result === void 0 ? null : [this, result];
649
+ };
650
+ }
651
+ };
652
+ NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
653
+ NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
654
+ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
655
+ NodeProp.contextHash = new NodeProp({ perNode: true });
656
+ NodeProp.lookAhead = new NodeProp({ perNode: true });
657
+ NodeProp.mounted = new NodeProp({ perNode: true });
658
+ var noProps = /* @__PURE__ */ Object.create(null);
659
+ var NodeType = class {
660
+ /// @internal
661
+ constructor(name, props, id, flags = 0) {
662
+ this.name = name;
663
+ this.props = props;
664
+ this.id = id;
665
+ this.flags = flags;
666
+ }
667
+ /// Define a node type.
668
+ static define(spec) {
669
+ let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
670
+ let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
671
+ let type = new NodeType(spec.name || "", props, spec.id, flags);
672
+ if (spec.props)
673
+ for (let src of spec.props) {
674
+ if (!Array.isArray(src))
675
+ src = src(type);
676
+ if (src) {
677
+ if (src[0].perNode)
678
+ throw new RangeError("Can't store a per-node prop on a node type");
679
+ props[src[0].id] = src[1];
680
+ }
681
+ }
682
+ return type;
683
+ }
684
+ /// Retrieves a node prop for this type. Will return `undefined` if
685
+ /// the prop isn't present on this node.
686
+ prop(prop) {
687
+ return this.props[prop.id];
688
+ }
689
+ /// True when this is the top node of a grammar.
690
+ get isTop() {
691
+ return (this.flags & 1) > 0;
692
+ }
693
+ /// True when this node is produced by a skip rule.
694
+ get isSkipped() {
695
+ return (this.flags & 2) > 0;
696
+ }
697
+ /// Indicates whether this is an error node.
698
+ get isError() {
699
+ return (this.flags & 4) > 0;
700
+ }
701
+ /// When true, this node type doesn't correspond to a user-declared
702
+ /// named node, for example because it is used to cache repetition.
703
+ get isAnonymous() {
704
+ return (this.flags & 8) > 0;
705
+ }
706
+ /// Returns true when this node's name or one of its
707
+ /// [groups](#common.NodeProp^group) matches the given string.
708
+ is(name) {
709
+ if (typeof name == "string") {
710
+ if (this.name == name)
711
+ return true;
712
+ let group = this.prop(NodeProp.group);
713
+ return group ? group.indexOf(name) > -1 : false;
714
+ }
715
+ return this.id == name;
716
+ }
717
+ /// Create a function from node types to arbitrary values by
718
+ /// specifying an object whose property names are node or
719
+ /// [group](#common.NodeProp^group) names. Often useful with
720
+ /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
721
+ /// names, separated by spaces, in a single property name to map
722
+ /// multiple node names to a single value.
723
+ static match(map) {
724
+ let direct = /* @__PURE__ */ Object.create(null);
725
+ for (let prop in map)
726
+ for (let name of prop.split(" "))
727
+ direct[name] = map[prop];
728
+ return (node) => {
729
+ for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
730
+ let found = direct[i < 0 ? node.name : groups[i]];
731
+ if (found)
732
+ return found;
733
+ }
734
+ };
735
+ }
736
+ };
737
+ NodeType.none = new NodeType(
738
+ "",
739
+ /* @__PURE__ */ Object.create(null),
740
+ 0,
741
+ 8
742
+ /* NodeFlag.Anonymous */
743
+ );
744
+ var NodeSet = class {
745
+ /// Create a set with the given types. The `id` property of each
746
+ /// type should correspond to its position within the array.
747
+ constructor(types) {
748
+ this.types = types;
749
+ for (let i = 0; i < types.length; i++)
750
+ if (types[i].id != i)
751
+ throw new RangeError("Node type ids should correspond to array positions when creating a node set");
752
+ }
753
+ /// Create a copy of this set with some node properties added. The
754
+ /// arguments to this method can be created with
755
+ /// [`NodeProp.add`](#common.NodeProp.add).
756
+ extend(...props) {
757
+ let newTypes = [];
758
+ for (let type of this.types) {
759
+ let newProps = null;
760
+ for (let source of props) {
761
+ let add = source(type);
762
+ if (add) {
763
+ if (!newProps)
764
+ newProps = Object.assign({}, type.props);
765
+ newProps[add[0].id] = add[1];
766
+ }
767
+ }
768
+ newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
769
+ }
770
+ return new NodeSet(newTypes);
771
+ }
772
+ };
773
+ var CachedNode = /* @__PURE__ */ new WeakMap();
774
+ var CachedInnerNode = /* @__PURE__ */ new WeakMap();
775
+ var IterMode;
776
+ (function(IterMode2) {
777
+ IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
778
+ IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
779
+ IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
780
+ IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
781
+ })(IterMode || (IterMode = {}));
782
+ var Tree = class {
783
+ /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
784
+ constructor(type, children, positions, length, props) {
785
+ this.type = type;
786
+ this.children = children;
787
+ this.positions = positions;
788
+ this.length = length;
789
+ this.props = null;
790
+ if (props && props.length) {
791
+ this.props = /* @__PURE__ */ Object.create(null);
792
+ for (let [prop, value] of props)
793
+ this.props[typeof prop == "number" ? prop : prop.id] = value;
794
+ }
795
+ }
796
+ /// @internal
797
+ toString() {
798
+ let mounted = this.prop(NodeProp.mounted);
799
+ if (mounted && !mounted.overlay)
800
+ return mounted.tree.toString();
801
+ let children = "";
802
+ for (let ch of this.children) {
803
+ let str = ch.toString();
804
+ if (str) {
805
+ if (children)
806
+ children += ",";
807
+ children += str;
808
+ }
809
+ }
810
+ return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
811
+ }
812
+ /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
813
+ /// the tree. Mode can be used to [control](#common.IterMode) which
814
+ /// nodes the cursor visits.
815
+ cursor(mode = 0) {
816
+ return new TreeCursor(this.topNode, mode);
817
+ }
818
+ /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
819
+ /// at the given position and side (see
820
+ /// [`moveTo`](#common.TreeCursor.moveTo).
821
+ cursorAt(pos, side = 0, mode = 0) {
822
+ let scope = CachedNode.get(this) || this.topNode;
823
+ let cursor = new TreeCursor(scope);
824
+ cursor.moveTo(pos, side);
825
+ CachedNode.set(this, cursor._tree);
826
+ return cursor;
827
+ }
828
+ /// Get a [syntax node](#common.SyntaxNode) object for the top of the
829
+ /// tree.
830
+ get topNode() {
831
+ return new TreeNode(this, 0, 0, null);
832
+ }
833
+ /// Get the [syntax node](#common.SyntaxNode) at the given position.
834
+ /// If `side` is -1, this will move into nodes that end at the
835
+ /// position. If 1, it'll move into nodes that start at the
836
+ /// position. With 0, it'll only enter nodes that cover the position
837
+ /// from both sides.
838
+ ///
839
+ /// Note that this will not enter
840
+ /// [overlays](#common.MountedTree.overlay), and you often want
841
+ /// [`resolveInner`](#common.Tree.resolveInner) instead.
842
+ resolve(pos, side = 0) {
843
+ let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
844
+ CachedNode.set(this, node);
845
+ return node;
846
+ }
847
+ /// Like [`resolve`](#common.Tree.resolve), but will enter
848
+ /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
849
+ /// pointing into the innermost overlaid tree at the given position
850
+ /// (with parent links going through all parent structure, including
851
+ /// the host trees).
852
+ resolveInner(pos, side = 0) {
853
+ let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
854
+ CachedInnerNode.set(this, node);
855
+ return node;
856
+ }
857
+ /// Iterate over the tree and its children, calling `enter` for any
858
+ /// node that touches the `from`/`to` region (if given) before
859
+ /// running over such a node's children, and `leave` (if given) when
860
+ /// leaving the node. When `enter` returns `false`, that node will
861
+ /// not have its children iterated over (or `leave` called).
862
+ iterate(spec) {
863
+ let { enter, leave, from = 0, to = this.length } = spec;
864
+ let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
865
+ for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
866
+ let entered = false;
867
+ if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
868
+ if (c.firstChild())
869
+ continue;
870
+ entered = true;
871
+ }
872
+ for (; ; ) {
873
+ if (entered && leave && (anon || !c.type.isAnonymous))
874
+ leave(c);
875
+ if (c.nextSibling())
876
+ break;
877
+ if (!c.parent())
878
+ return;
879
+ entered = true;
880
+ }
881
+ }
882
+ }
883
+ /// Get the value of the given [node prop](#common.NodeProp) for this
884
+ /// node. Works with both per-node and per-type props.
885
+ prop(prop) {
886
+ return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
887
+ }
888
+ /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
889
+ /// format that can be passed to the [`Tree`](#common.Tree)
890
+ /// constructor.
891
+ get propValues() {
892
+ let result = [];
893
+ if (this.props)
894
+ for (let id in this.props)
895
+ result.push([+id, this.props[id]]);
896
+ return result;
897
+ }
898
+ /// Balance the direct children of this tree, producing a copy of
899
+ /// which may have children grouped into subtrees with type
900
+ /// [`NodeType.none`](#common.NodeType^none).
901
+ balance(config = {}) {
902
+ 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)));
903
+ }
904
+ /// Build a tree from a postfix-ordered buffer of node information,
905
+ /// or a cursor over such a buffer.
906
+ static build(data) {
907
+ return buildTree(data);
908
+ }
909
+ };
910
+ Tree.empty = new Tree(NodeType.none, [], [], 0);
911
+ var FlatBufferCursor = class {
912
+ constructor(buffer, index) {
913
+ this.buffer = buffer;
914
+ this.index = index;
915
+ }
916
+ get id() {
917
+ return this.buffer[this.index - 4];
918
+ }
919
+ get start() {
920
+ return this.buffer[this.index - 3];
921
+ }
922
+ get end() {
923
+ return this.buffer[this.index - 2];
924
+ }
925
+ get size() {
926
+ return this.buffer[this.index - 1];
927
+ }
928
+ get pos() {
929
+ return this.index;
930
+ }
931
+ next() {
932
+ this.index -= 4;
933
+ }
934
+ fork() {
935
+ return new FlatBufferCursor(this.buffer, this.index);
936
+ }
937
+ };
938
+ var TreeBuffer = class {
939
+ /// Create a tree buffer.
940
+ constructor(buffer, length, set) {
941
+ this.buffer = buffer;
942
+ this.length = length;
943
+ this.set = set;
944
+ }
945
+ /// @internal
946
+ get type() {
947
+ return NodeType.none;
948
+ }
949
+ /// @internal
950
+ toString() {
951
+ let result = [];
952
+ for (let index = 0; index < this.buffer.length; ) {
953
+ result.push(this.childString(index));
954
+ index = this.buffer[index + 3];
955
+ }
956
+ return result.join(",");
957
+ }
958
+ /// @internal
959
+ childString(index) {
960
+ let id = this.buffer[index], endIndex = this.buffer[index + 3];
961
+ let type = this.set.types[id], result = type.name;
962
+ if (/\W/.test(result) && !type.isError)
963
+ result = JSON.stringify(result);
964
+ index += 4;
965
+ if (endIndex == index)
966
+ return result;
967
+ let children = [];
968
+ while (index < endIndex) {
969
+ children.push(this.childString(index));
970
+ index = this.buffer[index + 3];
971
+ }
972
+ return result + "(" + children.join(",") + ")";
973
+ }
974
+ /// @internal
975
+ findChild(startIndex, endIndex, dir, pos, side) {
976
+ let { buffer } = this, pick = -1;
977
+ for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
978
+ if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
979
+ pick = i;
980
+ if (dir > 0)
981
+ break;
982
+ }
983
+ }
984
+ return pick;
985
+ }
986
+ /// @internal
987
+ slice(startI, endI, from) {
988
+ let b = this.buffer;
989
+ let copy = new Uint16Array(endI - startI), len = 0;
990
+ for (let i = startI, j = 0; i < endI; ) {
991
+ copy[j++] = b[i++];
992
+ copy[j++] = b[i++] - from;
993
+ let to = copy[j++] = b[i++] - from;
994
+ copy[j++] = b[i++] - startI;
995
+ len = Math.max(len, to);
996
+ }
997
+ return new TreeBuffer(copy, len, this.set);
998
+ }
999
+ };
1000
+ function checkSide(side, pos, from, to) {
1001
+ switch (side) {
1002
+ case -2:
1003
+ return from < pos;
1004
+ case -1:
1005
+ return to >= pos && from < pos;
1006
+ case 0:
1007
+ return from < pos && to > pos;
1008
+ case 1:
1009
+ return from <= pos && to > pos;
1010
+ case 2:
1011
+ return to > pos;
1012
+ case 4:
1013
+ return true;
1014
+ }
1015
+ }
1016
+ function enterUnfinishedNodesBefore(node, pos) {
1017
+ let scan = node.childBefore(pos);
1018
+ while (scan) {
1019
+ let last = scan.lastChild;
1020
+ if (!last || last.to != scan.to)
1021
+ break;
1022
+ if (last.type.isError && last.from == last.to) {
1023
+ node = scan;
1024
+ scan = last.prevSibling;
1025
+ } else {
1026
+ scan = last;
1027
+ }
1028
+ }
1029
+ return node;
1030
+ }
1031
+ function resolveNode(node, pos, side, overlays) {
1032
+ var _a;
1033
+ while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
1034
+ let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
1035
+ if (!parent)
1036
+ return node;
1037
+ node = parent;
1038
+ }
1039
+ let mode = overlays ? 0 : IterMode.IgnoreOverlays;
1040
+ if (overlays)
1041
+ for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
1042
+ if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
1043
+ node = parent;
1044
+ }
1045
+ for (; ; ) {
1046
+ let inner = node.enter(pos, side, mode);
1047
+ if (!inner)
1048
+ return node;
1049
+ node = inner;
1050
+ }
1051
+ }
1052
+ var TreeNode = class {
1053
+ constructor(_tree, from, index, _parent) {
1054
+ this._tree = _tree;
1055
+ this.from = from;
1056
+ this.index = index;
1057
+ this._parent = _parent;
1058
+ }
1059
+ get type() {
1060
+ return this._tree.type;
1061
+ }
1062
+ get name() {
1063
+ return this._tree.type.name;
1064
+ }
1065
+ get to() {
1066
+ return this.from + this._tree.length;
1067
+ }
1068
+ nextChild(i, dir, pos, side, mode = 0) {
1069
+ for (let parent = this; ; ) {
1070
+ for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
1071
+ let next = children[i], start = positions[i] + parent.from;
1072
+ if (!checkSide(side, pos, start, start + next.length))
1073
+ continue;
1074
+ if (next instanceof TreeBuffer) {
1075
+ if (mode & IterMode.ExcludeBuffers)
1076
+ continue;
1077
+ let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
1078
+ if (index > -1)
1079
+ return new BufferNode(new BufferContext(parent, next, i, start), null, index);
1080
+ } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
1081
+ let mounted;
1082
+ if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
1083
+ return new TreeNode(mounted.tree, start, i, parent);
1084
+ let inner = new TreeNode(next, start, i, parent);
1085
+ return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
1086
+ }
1087
+ }
1088
+ if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
1089
+ return null;
1090
+ if (parent.index >= 0)
1091
+ i = parent.index + dir;
1092
+ else
1093
+ i = dir < 0 ? -1 : parent._parent._tree.children.length;
1094
+ parent = parent._parent;
1095
+ if (!parent)
1096
+ return null;
1097
+ }
1098
+ }
1099
+ get firstChild() {
1100
+ return this.nextChild(
1101
+ 0,
1102
+ 1,
1103
+ 0,
1104
+ 4
1105
+ /* Side.DontCare */
1106
+ );
1107
+ }
1108
+ get lastChild() {
1109
+ return this.nextChild(
1110
+ this._tree.children.length - 1,
1111
+ -1,
1112
+ 0,
1113
+ 4
1114
+ /* Side.DontCare */
1115
+ );
1116
+ }
1117
+ childAfter(pos) {
1118
+ return this.nextChild(
1119
+ 0,
1120
+ 1,
1121
+ pos,
1122
+ 2
1123
+ /* Side.After */
1124
+ );
1125
+ }
1126
+ childBefore(pos) {
1127
+ return this.nextChild(
1128
+ this._tree.children.length - 1,
1129
+ -1,
1130
+ pos,
1131
+ -2
1132
+ /* Side.Before */
1133
+ );
1134
+ }
1135
+ enter(pos, side, mode = 0) {
1136
+ let mounted;
1137
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
1138
+ let rPos = pos - this.from;
1139
+ for (let { from, to } of mounted.overlay) {
1140
+ if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
1141
+ return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
1142
+ }
1143
+ }
1144
+ return this.nextChild(0, 1, pos, side, mode);
1145
+ }
1146
+ nextSignificantParent() {
1147
+ let val = this;
1148
+ while (val.type.isAnonymous && val._parent)
1149
+ val = val._parent;
1150
+ return val;
1151
+ }
1152
+ get parent() {
1153
+ return this._parent ? this._parent.nextSignificantParent() : null;
1154
+ }
1155
+ get nextSibling() {
1156
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1157
+ this.index + 1,
1158
+ 1,
1159
+ 0,
1160
+ 4
1161
+ /* Side.DontCare */
1162
+ ) : null;
1163
+ }
1164
+ get prevSibling() {
1165
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1166
+ this.index - 1,
1167
+ -1,
1168
+ 0,
1169
+ 4
1170
+ /* Side.DontCare */
1171
+ ) : null;
1172
+ }
1173
+ cursor(mode = 0) {
1174
+ return new TreeCursor(this, mode);
1175
+ }
1176
+ get tree() {
1177
+ return this._tree;
1178
+ }
1179
+ toTree() {
1180
+ return this._tree;
1181
+ }
1182
+ resolve(pos, side = 0) {
1183
+ return resolveNode(this, pos, side, false);
1184
+ }
1185
+ resolveInner(pos, side = 0) {
1186
+ return resolveNode(this, pos, side, true);
1187
+ }
1188
+ enterUnfinishedNodesBefore(pos) {
1189
+ return enterUnfinishedNodesBefore(this, pos);
1190
+ }
1191
+ getChild(type, before = null, after = null) {
1192
+ let r2 = getChildren(this, type, before, after);
1193
+ return r2.length ? r2[0] : null;
1194
+ }
1195
+ getChildren(type, before = null, after = null) {
1196
+ return getChildren(this, type, before, after);
1197
+ }
1198
+ /// @internal
1199
+ toString() {
1200
+ return this._tree.toString();
1201
+ }
1202
+ get node() {
1203
+ return this;
1204
+ }
1205
+ matchContext(context) {
1206
+ return matchNodeContext(this, context);
1207
+ }
1208
+ };
1209
+ function getChildren(node, type, before, after) {
1210
+ let cur = node.cursor(), result = [];
1211
+ if (!cur.firstChild())
1212
+ return result;
1213
+ if (before != null) {
1214
+ while (!cur.type.is(before))
1215
+ if (!cur.nextSibling())
1216
+ return result;
1217
+ }
1218
+ for (; ; ) {
1219
+ if (after != null && cur.type.is(after))
1220
+ return result;
1221
+ if (cur.type.is(type))
1222
+ result.push(cur.node);
1223
+ if (!cur.nextSibling())
1224
+ return after == null ? result : [];
1225
+ }
1226
+ }
1227
+ function matchNodeContext(node, context, i = context.length - 1) {
1228
+ for (let p = node.parent; i >= 0; p = p.parent) {
1229
+ if (!p)
1230
+ return false;
1231
+ if (!p.type.isAnonymous) {
1232
+ if (context[i] && context[i] != p.name)
1233
+ return false;
1234
+ i--;
1235
+ }
1236
+ }
1237
+ return true;
1238
+ }
1239
+ var BufferContext = class {
1240
+ constructor(parent, buffer, index, start) {
1241
+ this.parent = parent;
1242
+ this.buffer = buffer;
1243
+ this.index = index;
1244
+ this.start = start;
1245
+ }
1246
+ };
1247
+ var BufferNode = class {
1248
+ get name() {
1249
+ return this.type.name;
1250
+ }
1251
+ get from() {
1252
+ return this.context.start + this.context.buffer.buffer[this.index + 1];
1253
+ }
1254
+ get to() {
1255
+ return this.context.start + this.context.buffer.buffer[this.index + 2];
1256
+ }
1257
+ constructor(context, _parent, index) {
1258
+ this.context = context;
1259
+ this._parent = _parent;
1260
+ this.index = index;
1261
+ this.type = context.buffer.set.types[context.buffer.buffer[index]];
1262
+ }
1263
+ child(dir, pos, side) {
1264
+ let { buffer } = this.context;
1265
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
1266
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1267
+ }
1268
+ get firstChild() {
1269
+ return this.child(
1270
+ 1,
1271
+ 0,
1272
+ 4
1273
+ /* Side.DontCare */
1274
+ );
1275
+ }
1276
+ get lastChild() {
1277
+ return this.child(
1278
+ -1,
1279
+ 0,
1280
+ 4
1281
+ /* Side.DontCare */
1282
+ );
1283
+ }
1284
+ childAfter(pos) {
1285
+ return this.child(
1286
+ 1,
1287
+ pos,
1288
+ 2
1289
+ /* Side.After */
1290
+ );
1291
+ }
1292
+ childBefore(pos) {
1293
+ return this.child(
1294
+ -1,
1295
+ pos,
1296
+ -2
1297
+ /* Side.Before */
1298
+ );
1299
+ }
1300
+ enter(pos, side, mode = 0) {
1301
+ if (mode & IterMode.ExcludeBuffers)
1302
+ return null;
1303
+ let { buffer } = this.context;
1304
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
1305
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1306
+ }
1307
+ get parent() {
1308
+ return this._parent || this.context.parent.nextSignificantParent();
1309
+ }
1310
+ externalSibling(dir) {
1311
+ return this._parent ? null : this.context.parent.nextChild(
1312
+ this.context.index + dir,
1313
+ dir,
1314
+ 0,
1315
+ 4
1316
+ /* Side.DontCare */
1317
+ );
1318
+ }
1319
+ get nextSibling() {
1320
+ let { buffer } = this.context;
1321
+ let after = buffer.buffer[this.index + 3];
1322
+ if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
1323
+ return new BufferNode(this.context, this._parent, after);
1324
+ return this.externalSibling(1);
1325
+ }
1326
+ get prevSibling() {
1327
+ let { buffer } = this.context;
1328
+ let parentStart = this._parent ? this._parent.index + 4 : 0;
1329
+ if (this.index == parentStart)
1330
+ return this.externalSibling(-1);
1331
+ return new BufferNode(this.context, this._parent, buffer.findChild(
1332
+ parentStart,
1333
+ this.index,
1334
+ -1,
1335
+ 0,
1336
+ 4
1337
+ /* Side.DontCare */
1338
+ ));
1339
+ }
1340
+ cursor(mode = 0) {
1341
+ return new TreeCursor(this, mode);
1342
+ }
1343
+ get tree() {
1344
+ return null;
1345
+ }
1346
+ toTree() {
1347
+ let children = [], positions = [];
1348
+ let { buffer } = this.context;
1349
+ let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
1350
+ if (endI > startI) {
1351
+ let from = buffer.buffer[this.index + 1];
1352
+ children.push(buffer.slice(startI, endI, from));
1353
+ positions.push(0);
1354
+ }
1355
+ return new Tree(this.type, children, positions, this.to - this.from);
1356
+ }
1357
+ resolve(pos, side = 0) {
1358
+ return resolveNode(this, pos, side, false);
1359
+ }
1360
+ resolveInner(pos, side = 0) {
1361
+ return resolveNode(this, pos, side, true);
1362
+ }
1363
+ enterUnfinishedNodesBefore(pos) {
1364
+ return enterUnfinishedNodesBefore(this, pos);
1365
+ }
1366
+ /// @internal
1367
+ toString() {
1368
+ return this.context.buffer.childString(this.index);
1369
+ }
1370
+ getChild(type, before = null, after = null) {
1371
+ let r2 = getChildren(this, type, before, after);
1372
+ return r2.length ? r2[0] : null;
1373
+ }
1374
+ getChildren(type, before = null, after = null) {
1375
+ return getChildren(this, type, before, after);
1376
+ }
1377
+ get node() {
1378
+ return this;
1379
+ }
1380
+ matchContext(context) {
1381
+ return matchNodeContext(this, context);
1382
+ }
1383
+ };
1384
+ var TreeCursor = class {
1385
+ /// Shorthand for `.type.name`.
1386
+ get name() {
1387
+ return this.type.name;
1388
+ }
1389
+ /// @internal
1390
+ constructor(node, mode = 0) {
1391
+ this.mode = mode;
1392
+ this.buffer = null;
1393
+ this.stack = [];
1394
+ this.index = 0;
1395
+ this.bufferNode = null;
1396
+ if (node instanceof TreeNode) {
1397
+ this.yieldNode(node);
1398
+ } else {
1399
+ this._tree = node.context.parent;
1400
+ this.buffer = node.context;
1401
+ for (let n = node._parent; n; n = n._parent)
1402
+ this.stack.unshift(n.index);
1403
+ this.bufferNode = node;
1404
+ this.yieldBuf(node.index);
1405
+ }
1406
+ }
1407
+ yieldNode(node) {
1408
+ if (!node)
1409
+ return false;
1410
+ this._tree = node;
1411
+ this.type = node.type;
1412
+ this.from = node.from;
1413
+ this.to = node.to;
1414
+ return true;
1415
+ }
1416
+ yieldBuf(index, type) {
1417
+ this.index = index;
1418
+ let { start, buffer } = this.buffer;
1419
+ this.type = type || buffer.set.types[buffer.buffer[index]];
1420
+ this.from = start + buffer.buffer[index + 1];
1421
+ this.to = start + buffer.buffer[index + 2];
1422
+ return true;
1423
+ }
1424
+ yield(node) {
1425
+ if (!node)
1426
+ return false;
1427
+ if (node instanceof TreeNode) {
1428
+ this.buffer = null;
1429
+ return this.yieldNode(node);
1430
+ }
1431
+ this.buffer = node.context;
1432
+ return this.yieldBuf(node.index, node.type);
1433
+ }
1434
+ /// @internal
1435
+ toString() {
1436
+ return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
1437
+ }
1438
+ /// @internal
1439
+ enterChild(dir, pos, side) {
1440
+ if (!this.buffer)
1441
+ return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
1442
+ let { buffer } = this.buffer;
1443
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
1444
+ if (index < 0)
1445
+ return false;
1446
+ this.stack.push(this.index);
1447
+ return this.yieldBuf(index);
1448
+ }
1449
+ /// Move the cursor to this node's first child. When this returns
1450
+ /// false, the node has no child, and the cursor has not been moved.
1451
+ firstChild() {
1452
+ return this.enterChild(
1453
+ 1,
1454
+ 0,
1455
+ 4
1456
+ /* Side.DontCare */
1457
+ );
1458
+ }
1459
+ /// Move the cursor to this node's last child.
1460
+ lastChild() {
1461
+ return this.enterChild(
1462
+ -1,
1463
+ 0,
1464
+ 4
1465
+ /* Side.DontCare */
1466
+ );
1467
+ }
1468
+ /// Move the cursor to the first child that ends after `pos`.
1469
+ childAfter(pos) {
1470
+ return this.enterChild(
1471
+ 1,
1472
+ pos,
1473
+ 2
1474
+ /* Side.After */
1475
+ );
1476
+ }
1477
+ /// Move to the last child that starts before `pos`.
1478
+ childBefore(pos) {
1479
+ return this.enterChild(
1480
+ -1,
1481
+ pos,
1482
+ -2
1483
+ /* Side.Before */
1484
+ );
1485
+ }
1486
+ /// Move the cursor to the child around `pos`. If side is -1 the
1487
+ /// child may end at that position, when 1 it may start there. This
1488
+ /// will also enter [overlaid](#common.MountedTree.overlay)
1489
+ /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
1490
+ /// set to false.
1491
+ enter(pos, side, mode = this.mode) {
1492
+ if (!this.buffer)
1493
+ return this.yield(this._tree.enter(pos, side, mode));
1494
+ return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
1495
+ }
1496
+ /// Move to the node's parent node, if this isn't the top node.
1497
+ parent() {
1498
+ if (!this.buffer)
1499
+ return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
1500
+ if (this.stack.length)
1501
+ return this.yieldBuf(this.stack.pop());
1502
+ let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
1503
+ this.buffer = null;
1504
+ return this.yieldNode(parent);
1505
+ }
1506
+ /// @internal
1507
+ sibling(dir) {
1508
+ if (!this.buffer)
1509
+ 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));
1510
+ let { buffer } = this.buffer, d = this.stack.length - 1;
1511
+ if (dir < 0) {
1512
+ let parentStart = d < 0 ? 0 : this.stack[d] + 4;
1513
+ if (this.index != parentStart)
1514
+ return this.yieldBuf(buffer.findChild(
1515
+ parentStart,
1516
+ this.index,
1517
+ -1,
1518
+ 0,
1519
+ 4
1520
+ /* Side.DontCare */
1521
+ ));
1522
+ } else {
1523
+ let after = buffer.buffer[this.index + 3];
1524
+ if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
1525
+ return this.yieldBuf(after);
1526
+ }
1527
+ return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
1528
+ }
1529
+ /// Move to this node's next sibling, if any.
1530
+ nextSibling() {
1531
+ return this.sibling(1);
1532
+ }
1533
+ /// Move to this node's previous sibling, if any.
1534
+ prevSibling() {
1535
+ return this.sibling(-1);
1536
+ }
1537
+ atLastNode(dir) {
1538
+ let index, parent, { buffer } = this;
1539
+ if (buffer) {
1540
+ if (dir > 0) {
1541
+ if (this.index < buffer.buffer.buffer.length)
1542
+ return false;
1543
+ } else {
1544
+ for (let i = 0; i < this.index; i++)
1545
+ if (buffer.buffer.buffer[i + 3] < this.index)
1546
+ return false;
1547
+ }
1548
+ ({ index, parent } = buffer);
1549
+ } else {
1550
+ ({ index, _parent: parent } = this._tree);
1551
+ }
1552
+ for (; parent; { index, _parent: parent } = parent) {
1553
+ if (index > -1)
1554
+ for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
1555
+ let child = parent._tree.children[i];
1556
+ if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
1557
+ return false;
1558
+ }
1559
+ }
1560
+ return true;
1561
+ }
1562
+ move(dir, enter) {
1563
+ if (enter && this.enterChild(
1564
+ dir,
1565
+ 0,
1566
+ 4
1567
+ /* Side.DontCare */
1568
+ ))
1569
+ return true;
1570
+ for (; ; ) {
1571
+ if (this.sibling(dir))
1572
+ return true;
1573
+ if (this.atLastNode(dir) || !this.parent())
1574
+ return false;
1575
+ }
1576
+ }
1577
+ /// Move to the next node in a
1578
+ /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1579
+ /// traversal, going from a node to its first child or, if the
1580
+ /// current node is empty or `enter` is false, its next sibling or
1581
+ /// the next sibling of the first parent node that has one.
1582
+ next(enter = true) {
1583
+ return this.move(1, enter);
1584
+ }
1585
+ /// Move to the next node in a last-to-first pre-order traveral. A
1586
+ /// node is followed by its last child or, if it has none, its
1587
+ /// previous sibling or the previous sibling of the first parent
1588
+ /// node that has one.
1589
+ prev(enter = true) {
1590
+ return this.move(-1, enter);
1591
+ }
1592
+ /// Move the cursor to the innermost node that covers `pos`. If
1593
+ /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1594
+ /// it will enter nodes that start at `pos`.
1595
+ moveTo(pos, side = 0) {
1596
+ while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
1597
+ if (!this.parent())
1598
+ break;
1599
+ while (this.enterChild(1, pos, side)) {
1600
+ }
1601
+ return this;
1602
+ }
1603
+ /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
1604
+ /// position.
1605
+ get node() {
1606
+ if (!this.buffer)
1607
+ return this._tree;
1608
+ let cache = this.bufferNode, result = null, depth = 0;
1609
+ if (cache && cache.context == this.buffer) {
1610
+ scan:
1611
+ for (let index = this.index, d = this.stack.length; d >= 0; ) {
1612
+ for (let c = cache; c; c = c._parent)
1613
+ if (c.index == index) {
1614
+ if (index == this.index)
1615
+ return c;
1616
+ result = c;
1617
+ depth = d + 1;
1618
+ break scan;
1619
+ }
1620
+ index = this.stack[--d];
1621
+ }
1622
+ }
1623
+ for (let i = depth; i < this.stack.length; i++)
1624
+ result = new BufferNode(this.buffer, result, this.stack[i]);
1625
+ return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1626
+ }
1627
+ /// Get the [tree](#common.Tree) that represents the current node, if
1628
+ /// any. Will return null when the node is in a [tree
1629
+ /// buffer](#common.TreeBuffer).
1630
+ get tree() {
1631
+ return this.buffer ? null : this._tree._tree;
1632
+ }
1633
+ /// Iterate over the current node and all its descendants, calling
1634
+ /// `enter` when entering a node and `leave`, if given, when leaving
1635
+ /// one. When `enter` returns `false`, any children of that node are
1636
+ /// skipped, and `leave` isn't called for it.
1637
+ iterate(enter, leave) {
1638
+ for (let depth = 0; ; ) {
1639
+ let mustLeave = false;
1640
+ if (this.type.isAnonymous || enter(this) !== false) {
1641
+ if (this.firstChild()) {
1642
+ depth++;
1643
+ continue;
1644
+ }
1645
+ if (!this.type.isAnonymous)
1646
+ mustLeave = true;
1647
+ }
1648
+ for (; ; ) {
1649
+ if (mustLeave && leave)
1650
+ leave(this);
1651
+ mustLeave = this.type.isAnonymous;
1652
+ if (this.nextSibling())
1653
+ break;
1654
+ if (!depth)
1655
+ return;
1656
+ this.parent();
1657
+ depth--;
1658
+ mustLeave = true;
1659
+ }
1660
+ }
1661
+ }
1662
+ /// Test whether the current node matches a given context—a sequence
1663
+ /// of direct parent node names. Empty strings in the context array
1664
+ /// are treated as wildcards.
1665
+ matchContext(context) {
1666
+ if (!this.buffer)
1667
+ return matchNodeContext(this.node, context);
1668
+ let { buffer } = this.buffer, { types } = buffer.set;
1669
+ for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
1670
+ if (d < 0)
1671
+ return matchNodeContext(this.node, context, i);
1672
+ let type = types[buffer.buffer[this.stack[d]]];
1673
+ if (!type.isAnonymous) {
1674
+ if (context[i] && context[i] != type.name)
1675
+ return false;
1676
+ i--;
1677
+ }
1678
+ }
1679
+ return true;
1680
+ }
1681
+ };
1682
+ function hasChild(tree) {
1683
+ return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
1684
+ }
1685
+ function buildTree(data) {
1686
+ var _a;
1687
+ let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
1688
+ let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
1689
+ let types = nodeSet.types;
1690
+ let contextHash = 0, lookAhead = 0;
1691
+ function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
1692
+ let { id, start, end, size } = cursor;
1693
+ let lookAheadAtStart = lookAhead;
1694
+ while (size < 0) {
1695
+ cursor.next();
1696
+ if (size == -1) {
1697
+ let node2 = reused[id];
1698
+ children2.push(node2);
1699
+ positions2.push(start - parentStart);
1700
+ return;
1701
+ } else if (size == -3) {
1702
+ contextHash = id;
1703
+ return;
1704
+ } else if (size == -4) {
1705
+ lookAhead = id;
1706
+ return;
1707
+ } else {
1708
+ throw new RangeError(`Unrecognized record size: ${size}`);
1709
+ }
1710
+ }
1711
+ let type = types[id], node, buffer2;
1712
+ let startPos = start - parentStart;
1713
+ if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
1714
+ let data2 = new Uint16Array(buffer2.size - buffer2.skip);
1715
+ let endPos = cursor.pos - buffer2.size, index = data2.length;
1716
+ while (cursor.pos > endPos)
1717
+ index = copyToBuffer(buffer2.start, data2, index);
1718
+ node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
1719
+ startPos = buffer2.start - parentStart;
1720
+ } else {
1721
+ let endPos = cursor.pos - size;
1722
+ cursor.next();
1723
+ let localChildren = [], localPositions = [];
1724
+ let localInRepeat = id >= minRepeatType ? id : -1;
1725
+ let lastGroup = 0, lastEnd = end;
1726
+ while (cursor.pos > endPos) {
1727
+ if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
1728
+ if (cursor.end <= lastEnd - maxBufferLength) {
1729
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
1730
+ lastGroup = localChildren.length;
1731
+ lastEnd = cursor.end;
1732
+ }
1733
+ cursor.next();
1734
+ } else {
1735
+ takeNode(start, endPos, localChildren, localPositions, localInRepeat);
1736
+ }
1737
+ }
1738
+ if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
1739
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
1740
+ localChildren.reverse();
1741
+ localPositions.reverse();
1742
+ if (localInRepeat > -1 && lastGroup > 0) {
1743
+ let make = makeBalanced(type);
1744
+ node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
1745
+ } else {
1746
+ node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
1747
+ }
1748
+ }
1749
+ children2.push(node);
1750
+ positions2.push(startPos);
1751
+ }
1752
+ function makeBalanced(type) {
1753
+ return (children2, positions2, length2) => {
1754
+ let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
1755
+ if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
1756
+ if (!lastI && last.type == type && last.length == length2)
1757
+ return last;
1758
+ if (lookAheadProp = last.prop(NodeProp.lookAhead))
1759
+ lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
1760
+ }
1761
+ return makeTree(type, children2, positions2, length2, lookAhead2);
1762
+ };
1763
+ }
1764
+ function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
1765
+ let localChildren = [], localPositions = [];
1766
+ while (children2.length > i) {
1767
+ localChildren.push(children2.pop());
1768
+ localPositions.push(positions2.pop() + base - from);
1769
+ }
1770
+ children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
1771
+ positions2.push(from - base);
1772
+ }
1773
+ function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
1774
+ if (contextHash) {
1775
+ let pair2 = [NodeProp.contextHash, contextHash];
1776
+ props = props ? [pair2].concat(props) : [pair2];
1777
+ }
1778
+ if (lookAhead2 > 25) {
1779
+ let pair2 = [NodeProp.lookAhead, lookAhead2];
1780
+ props = props ? [pair2].concat(props) : [pair2];
1781
+ }
1782
+ return new Tree(type, children2, positions2, length2, props);
1783
+ }
1784
+ function findBufferSize(maxSize, inRepeat) {
1785
+ let fork = cursor.fork();
1786
+ let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
1787
+ let result = { size: 0, start: 0, skip: 0 };
1788
+ scan:
1789
+ for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
1790
+ let nodeSize2 = fork.size;
1791
+ if (fork.id == inRepeat && nodeSize2 >= 0) {
1792
+ result.size = size;
1793
+ result.start = start;
1794
+ result.skip = skip;
1795
+ skip += 4;
1796
+ size += 4;
1797
+ fork.next();
1798
+ continue;
1799
+ }
1800
+ let startPos = fork.pos - nodeSize2;
1801
+ if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
1802
+ break;
1803
+ let localSkipped = fork.id >= minRepeatType ? 4 : 0;
1804
+ let nodeStart = fork.start;
1805
+ fork.next();
1806
+ while (fork.pos > startPos) {
1807
+ if (fork.size < 0) {
1808
+ if (fork.size == -3)
1809
+ localSkipped += 4;
1810
+ else
1811
+ break scan;
1812
+ } else if (fork.id >= minRepeatType) {
1813
+ localSkipped += 4;
1814
+ }
1815
+ fork.next();
1816
+ }
1817
+ start = nodeStart;
1818
+ size += nodeSize2;
1819
+ skip += localSkipped;
1820
+ }
1821
+ if (inRepeat < 0 || size == maxSize) {
1822
+ result.size = size;
1823
+ result.start = start;
1824
+ result.skip = skip;
1825
+ }
1826
+ return result.size > 4 ? result : void 0;
1827
+ }
1828
+ function copyToBuffer(bufferStart, buffer2, index) {
1829
+ let { id, start, end, size } = cursor;
1830
+ cursor.next();
1831
+ if (size >= 0 && id < minRepeatType) {
1832
+ let startIndex = index;
1833
+ if (size > 4) {
1834
+ let endPos = cursor.pos - (size - 4);
1835
+ while (cursor.pos > endPos)
1836
+ index = copyToBuffer(bufferStart, buffer2, index);
1837
+ }
1838
+ buffer2[--index] = startIndex;
1839
+ buffer2[--index] = end - bufferStart;
1840
+ buffer2[--index] = start - bufferStart;
1841
+ buffer2[--index] = id;
1842
+ } else if (size == -3) {
1843
+ contextHash = id;
1844
+ } else if (size == -4) {
1845
+ lookAhead = id;
1846
+ }
1847
+ return index;
1848
+ }
1849
+ let children = [], positions = [];
1850
+ while (cursor.pos > 0)
1851
+ takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
1852
+ let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
1853
+ return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
26
1854
  }
1855
+ var nodeSizeCache = /* @__PURE__ */ new WeakMap();
1856
+ function nodeSize(balanceType, node) {
1857
+ if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
1858
+ return 1;
1859
+ let size = nodeSizeCache.get(node);
1860
+ if (size == null) {
1861
+ size = 1;
1862
+ for (let child of node.children) {
1863
+ if (child.type != balanceType || !(child instanceof Tree)) {
1864
+ size = 1;
1865
+ break;
1866
+ }
1867
+ size += nodeSize(balanceType, child);
1868
+ }
1869
+ nodeSizeCache.set(node, size);
1870
+ }
1871
+ return size;
1872
+ }
1873
+ function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
1874
+ let total = 0;
1875
+ for (let i = from; i < to; i++)
1876
+ total += nodeSize(balanceType, children[i]);
1877
+ let maxChild = Math.ceil(
1878
+ total * 1.5 / 8
1879
+ /* Balance.BranchFactor */
1880
+ );
1881
+ let localChildren = [], localPositions = [];
1882
+ function divide(children2, positions2, from2, to2, offset) {
1883
+ for (let i = from2; i < to2; ) {
1884
+ let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
1885
+ i++;
1886
+ for (; i < to2; i++) {
1887
+ let nextSize = nodeSize(balanceType, children2[i]);
1888
+ if (groupSize + nextSize >= maxChild)
1889
+ break;
1890
+ groupSize += nextSize;
1891
+ }
1892
+ if (i == groupFrom + 1) {
1893
+ if (groupSize > maxChild) {
1894
+ let only = children2[groupFrom];
1895
+ divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
1896
+ continue;
1897
+ }
1898
+ localChildren.push(children2[groupFrom]);
1899
+ } else {
1900
+ let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
1901
+ localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
1902
+ }
1903
+ localPositions.push(groupStart + offset - start);
1904
+ }
1905
+ }
1906
+ divide(children, positions, from, to, 0);
1907
+ return (mkTop || mkTree)(localChildren, localPositions, length);
1908
+ }
1909
+ var Parser = class {
1910
+ /// Start a parse, returning a [partial parse](#common.PartialParse)
1911
+ /// object. [`fragments`](#common.TreeFragment) can be passed in to
1912
+ /// make the parse incremental.
1913
+ ///
1914
+ /// By default, the entire input is parsed. You can pass `ranges`,
1915
+ /// which should be a sorted array of non-empty, non-overlapping
1916
+ /// ranges, to parse only those ranges. The tree returned in that
1917
+ /// case will start at `ranges[0].from`.
1918
+ startParse(input, fragments, ranges) {
1919
+ if (typeof input == "string")
1920
+ input = new StringInput(input);
1921
+ ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r2) => new Range(r2.from, r2.to)) : [new Range(0, 0)];
1922
+ return this.createParse(input, fragments || [], ranges);
1923
+ }
1924
+ /// Run a full parse, returning the resulting tree.
1925
+ parse(input, fragments, ranges) {
1926
+ let parse = this.startParse(input, fragments, ranges);
1927
+ for (; ; ) {
1928
+ let done = parse.advance();
1929
+ if (done)
1930
+ return done;
1931
+ }
1932
+ }
1933
+ };
1934
+ var StringInput = class {
1935
+ constructor(string) {
1936
+ this.string = string;
1937
+ }
1938
+ get length() {
1939
+ return this.string.length;
1940
+ }
1941
+ chunk(from) {
1942
+ return this.string.slice(from);
1943
+ }
1944
+ get lineChunks() {
1945
+ return false;
1946
+ }
1947
+ read(from, to) {
1948
+ return this.string.slice(from, to);
1949
+ }
1950
+ };
1951
+ var stoppedInner = new NodeProp({ perNode: true });
27
1952
 
28
- .saltIcon:active {
29
- --icon-color: var(--saltIcon-color-active, var(--salt-text-secondary-foreground));
1953
+ // ../../node_modules/@lezer/lr/dist/index.js
1954
+ var Stack = class {
1955
+ /// @internal
1956
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
1957
+ this.p = p;
1958
+ this.stack = stack;
1959
+ this.state = state;
1960
+ this.reducePos = reducePos;
1961
+ this.pos = pos;
1962
+ this.score = score;
1963
+ this.buffer = buffer;
1964
+ this.bufferBase = bufferBase;
1965
+ this.curContext = curContext;
1966
+ this.lookAhead = lookAhead;
1967
+ this.parent = parent;
1968
+ }
1969
+ /// @internal
1970
+ toString() {
1971
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
1972
+ }
1973
+ // Start an empty stack
1974
+ /// @internal
1975
+ static start(p, state, pos = 0) {
1976
+ let cx3 = p.parser.context;
1977
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx3 ? new StackContext(cx3, cx3.start) : null, 0, null);
1978
+ }
1979
+ /// The stack's current [context](#lr.ContextTracker) value, if
1980
+ /// any. Its type will depend on the context tracker's type
1981
+ /// parameter, or it will be `null` if there is no context
1982
+ /// tracker.
1983
+ get context() {
1984
+ return this.curContext ? this.curContext.context : null;
1985
+ }
1986
+ // Push a state onto the stack, tracking its start position as well
1987
+ // as the buffer base at that point.
1988
+ /// @internal
1989
+ pushState(state, start) {
1990
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
1991
+ this.state = state;
1992
+ }
1993
+ // Apply a reduce action
1994
+ /// @internal
1995
+ reduce(action) {
1996
+ var _a;
1997
+ let depth = action >> 19, type = action & 65535;
1998
+ let { parser: parser2 } = this.p;
1999
+ let dPrec = parser2.dynamicPrecedence(type);
2000
+ if (dPrec)
2001
+ this.score += dPrec;
2002
+ if (depth == 0) {
2003
+ this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
2004
+ if (type < parser2.minRepeatTerm)
2005
+ this.storeNode(type, this.reducePos, this.reducePos, 4, true);
2006
+ this.reduceContext(type, this.reducePos);
2007
+ return;
2008
+ }
2009
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
2010
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
2011
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
2012
+ if (start == this.p.lastBigReductionStart) {
2013
+ this.p.bigReductionCount++;
2014
+ this.p.lastBigReductionSize = size;
2015
+ } else if (this.p.lastBigReductionSize < size) {
2016
+ this.p.bigReductionCount = 1;
2017
+ this.p.lastBigReductionStart = start;
2018
+ this.p.lastBigReductionSize = size;
2019
+ }
2020
+ }
2021
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
2022
+ if (type < parser2.minRepeatTerm || action & 131072) {
2023
+ let pos = parser2.stateFlag(
2024
+ this.state,
2025
+ 1
2026
+ /* StateFlag.Skipped */
2027
+ ) ? this.pos : this.reducePos;
2028
+ this.storeNode(type, start, pos, count + 4, true);
2029
+ }
2030
+ if (action & 262144) {
2031
+ this.state = this.stack[base];
2032
+ } else {
2033
+ let baseStateID = this.stack[base - 3];
2034
+ this.state = parser2.getGoto(baseStateID, type, true);
2035
+ }
2036
+ while (this.stack.length > base)
2037
+ this.stack.pop();
2038
+ this.reduceContext(type, start);
2039
+ }
2040
+ // Shift a value into the buffer
2041
+ /// @internal
2042
+ storeNode(term, start, end, size = 4, isReduce = false) {
2043
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
2044
+ let cur = this, top = this.buffer.length;
2045
+ if (top == 0 && cur.parent) {
2046
+ top = cur.bufferBase - cur.parent.bufferBase;
2047
+ cur = cur.parent;
2048
+ }
2049
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
2050
+ if (start == end)
2051
+ return;
2052
+ if (cur.buffer[top - 2] >= start) {
2053
+ cur.buffer[top - 2] = end;
2054
+ return;
2055
+ }
2056
+ }
2057
+ }
2058
+ if (!isReduce || this.pos == end) {
2059
+ this.buffer.push(term, start, end, size);
2060
+ } else {
2061
+ let index = this.buffer.length;
2062
+ if (index > 0 && this.buffer[index - 4] != 0)
2063
+ while (index > 0 && this.buffer[index - 2] > end) {
2064
+ this.buffer[index] = this.buffer[index - 4];
2065
+ this.buffer[index + 1] = this.buffer[index - 3];
2066
+ this.buffer[index + 2] = this.buffer[index - 2];
2067
+ this.buffer[index + 3] = this.buffer[index - 1];
2068
+ index -= 4;
2069
+ if (size > 4)
2070
+ size -= 4;
2071
+ }
2072
+ this.buffer[index] = term;
2073
+ this.buffer[index + 1] = start;
2074
+ this.buffer[index + 2] = end;
2075
+ this.buffer[index + 3] = size;
2076
+ }
2077
+ }
2078
+ // Apply a shift action
2079
+ /// @internal
2080
+ shift(action, next, nextEnd) {
2081
+ let start = this.pos;
2082
+ if (action & 131072) {
2083
+ this.pushState(action & 65535, this.pos);
2084
+ } else if ((action & 262144) == 0) {
2085
+ let nextState = action, { parser: parser2 } = this.p;
2086
+ if (nextEnd > this.pos || next <= parser2.maxNode) {
2087
+ this.pos = nextEnd;
2088
+ if (!parser2.stateFlag(
2089
+ nextState,
2090
+ 1
2091
+ /* StateFlag.Skipped */
2092
+ ))
2093
+ this.reducePos = nextEnd;
2094
+ }
2095
+ this.pushState(nextState, start);
2096
+ this.shiftContext(next, start);
2097
+ if (next <= parser2.maxNode)
2098
+ this.buffer.push(next, start, nextEnd, 4);
2099
+ } else {
2100
+ this.pos = nextEnd;
2101
+ this.shiftContext(next, start);
2102
+ if (next <= this.p.parser.maxNode)
2103
+ this.buffer.push(next, start, nextEnd, 4);
2104
+ }
2105
+ }
2106
+ // Apply an action
2107
+ /// @internal
2108
+ apply(action, next, nextEnd) {
2109
+ if (action & 65536)
2110
+ this.reduce(action);
2111
+ else
2112
+ this.shift(action, next, nextEnd);
2113
+ }
2114
+ // Add a prebuilt (reused) node into the buffer.
2115
+ /// @internal
2116
+ useNode(value, next) {
2117
+ let index = this.p.reused.length - 1;
2118
+ if (index < 0 || this.p.reused[index] != value) {
2119
+ this.p.reused.push(value);
2120
+ index++;
2121
+ }
2122
+ let start = this.pos;
2123
+ this.reducePos = this.pos = start + value.length;
2124
+ this.pushState(next, start);
2125
+ this.buffer.push(
2126
+ index,
2127
+ start,
2128
+ this.reducePos,
2129
+ -1
2130
+ /* size == -1 means this is a reused value */
2131
+ );
2132
+ if (this.curContext)
2133
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
2134
+ }
2135
+ // Split the stack. Due to the buffer sharing and the fact
2136
+ // that `this.stack` tends to stay quite shallow, this isn't very
2137
+ // expensive.
2138
+ /// @internal
2139
+ split() {
2140
+ let parent = this;
2141
+ let off = parent.buffer.length;
2142
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
2143
+ off -= 4;
2144
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
2145
+ while (parent && base == parent.bufferBase)
2146
+ parent = parent.parent;
2147
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
2148
+ }
2149
+ // Try to recover from an error by 'deleting' (ignoring) one token.
2150
+ /// @internal
2151
+ recoverByDelete(next, nextEnd) {
2152
+ let isNode = next <= this.p.parser.maxNode;
2153
+ if (isNode)
2154
+ this.storeNode(next, this.pos, nextEnd, 4);
2155
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
2156
+ this.pos = this.reducePos = nextEnd;
2157
+ this.score -= 190;
2158
+ }
2159
+ /// Check if the given term would be able to be shifted (optionally
2160
+ /// after some reductions) on this stack. This can be useful for
2161
+ /// external tokenizers that want to make sure they only provide a
2162
+ /// given token when it applies.
2163
+ canShift(term) {
2164
+ for (let sim = new SimulatedStack(this); ; ) {
2165
+ let action = this.p.parser.stateSlot(
2166
+ sim.state,
2167
+ 4
2168
+ /* ParseState.DefaultReduce */
2169
+ ) || this.p.parser.hasAction(sim.state, term);
2170
+ if (action == 0)
2171
+ return false;
2172
+ if ((action & 65536) == 0)
2173
+ return true;
2174
+ sim.reduce(action);
2175
+ }
2176
+ }
2177
+ // Apply up to Recover.MaxNext recovery actions that conceptually
2178
+ // inserts some missing token or rule.
2179
+ /// @internal
2180
+ recoverByInsert(next) {
2181
+ if (this.stack.length >= 300)
2182
+ return [];
2183
+ let nextStates = this.p.parser.nextStates(this.state);
2184
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
2185
+ let best = [];
2186
+ for (let i = 0, s; i < nextStates.length; i += 2) {
2187
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
2188
+ best.push(nextStates[i], s);
2189
+ }
2190
+ if (this.stack.length < 120)
2191
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
2192
+ let s = nextStates[i + 1];
2193
+ if (!best.some((v, i2) => i2 & 1 && v == s))
2194
+ best.push(nextStates[i], s);
2195
+ }
2196
+ nextStates = best;
2197
+ }
2198
+ let result = [];
2199
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
2200
+ let s = nextStates[i + 1];
2201
+ if (s == this.state)
2202
+ continue;
2203
+ let stack = this.split();
2204
+ stack.pushState(s, this.pos);
2205
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
2206
+ stack.shiftContext(nextStates[i], this.pos);
2207
+ stack.score -= 200;
2208
+ result.push(stack);
2209
+ }
2210
+ return result;
2211
+ }
2212
+ // Force a reduce, if possible. Return false if that can't
2213
+ // be done.
2214
+ /// @internal
2215
+ forceReduce() {
2216
+ let reduce = this.p.parser.stateSlot(
2217
+ this.state,
2218
+ 5
2219
+ /* ParseState.ForcedReduce */
2220
+ );
2221
+ if ((reduce & 65536) == 0)
2222
+ return false;
2223
+ let { parser: parser2 } = this.p;
2224
+ if (!parser2.validAction(this.state, reduce)) {
2225
+ let depth = reduce >> 19, term = reduce & 65535;
2226
+ let target = this.stack.length - depth * 3;
2227
+ if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0)
2228
+ return false;
2229
+ this.storeNode(0, this.reducePos, this.reducePos, 4, true);
2230
+ this.score -= 100;
2231
+ }
2232
+ this.reducePos = this.pos;
2233
+ this.reduce(reduce);
2234
+ return true;
2235
+ }
2236
+ /// @internal
2237
+ forceAll() {
2238
+ while (!this.p.parser.stateFlag(
2239
+ this.state,
2240
+ 2
2241
+ /* StateFlag.Accepting */
2242
+ )) {
2243
+ if (!this.forceReduce()) {
2244
+ this.storeNode(0, this.pos, this.pos, 4, true);
2245
+ break;
2246
+ }
2247
+ }
2248
+ return this;
2249
+ }
2250
+ /// Check whether this state has no further actions (assumed to be a direct descendant of the
2251
+ /// top state, since any other states must be able to continue
2252
+ /// somehow). @internal
2253
+ get deadEnd() {
2254
+ if (this.stack.length != 3)
2255
+ return false;
2256
+ let { parser: parser2 } = this.p;
2257
+ return parser2.data[parser2.stateSlot(
2258
+ this.state,
2259
+ 1
2260
+ /* ParseState.Actions */
2261
+ )] == 65535 && !parser2.stateSlot(
2262
+ this.state,
2263
+ 4
2264
+ /* ParseState.DefaultReduce */
2265
+ );
2266
+ }
2267
+ /// Restart the stack (put it back in its start state). Only safe
2268
+ /// when this.stack.length == 3 (state is directly below the top
2269
+ /// state). @internal
2270
+ restart() {
2271
+ this.state = this.stack[0];
2272
+ this.stack.length = 0;
2273
+ }
2274
+ /// @internal
2275
+ sameState(other) {
2276
+ if (this.state != other.state || this.stack.length != other.stack.length)
2277
+ return false;
2278
+ for (let i = 0; i < this.stack.length; i += 3)
2279
+ if (this.stack[i] != other.stack[i])
2280
+ return false;
2281
+ return true;
2282
+ }
2283
+ /// Get the parser used by this stack.
2284
+ get parser() {
2285
+ return this.p.parser;
2286
+ }
2287
+ /// Test whether a given dialect (by numeric ID, as exported from
2288
+ /// the terms file) is enabled.
2289
+ dialectEnabled(dialectID) {
2290
+ return this.p.parser.dialect.flags[dialectID];
2291
+ }
2292
+ shiftContext(term, start) {
2293
+ if (this.curContext)
2294
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
2295
+ }
2296
+ reduceContext(term, start) {
2297
+ if (this.curContext)
2298
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
2299
+ }
2300
+ /// @internal
2301
+ emitContext() {
2302
+ let last = this.buffer.length - 1;
2303
+ if (last < 0 || this.buffer[last] != -3)
2304
+ this.buffer.push(this.curContext.hash, this.reducePos, this.reducePos, -3);
2305
+ }
2306
+ /// @internal
2307
+ emitLookAhead() {
2308
+ let last = this.buffer.length - 1;
2309
+ if (last < 0 || this.buffer[last] != -4)
2310
+ this.buffer.push(this.lookAhead, this.reducePos, this.reducePos, -4);
2311
+ }
2312
+ updateContext(context) {
2313
+ if (context != this.curContext.context) {
2314
+ let newCx = new StackContext(this.curContext.tracker, context);
2315
+ if (newCx.hash != this.curContext.hash)
2316
+ this.emitContext();
2317
+ this.curContext = newCx;
2318
+ }
2319
+ }
2320
+ /// @internal
2321
+ setLookAhead(lookAhead) {
2322
+ if (lookAhead > this.lookAhead) {
2323
+ this.emitLookAhead();
2324
+ this.lookAhead = lookAhead;
2325
+ }
2326
+ }
2327
+ /// @internal
2328
+ close() {
2329
+ if (this.curContext && this.curContext.tracker.strict)
2330
+ this.emitContext();
2331
+ if (this.lookAhead > 0)
2332
+ this.emitLookAhead();
2333
+ }
2334
+ };
2335
+ var StackContext = class {
2336
+ constructor(tracker, context) {
2337
+ this.tracker = tracker;
2338
+ this.context = context;
2339
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
2340
+ }
2341
+ };
2342
+ var Recover;
2343
+ (function(Recover2) {
2344
+ Recover2[Recover2["Insert"] = 200] = "Insert";
2345
+ Recover2[Recover2["Delete"] = 190] = "Delete";
2346
+ Recover2[Recover2["Reduce"] = 100] = "Reduce";
2347
+ Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
2348
+ Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
2349
+ Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
2350
+ Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
2351
+ })(Recover || (Recover = {}));
2352
+ var SimulatedStack = class {
2353
+ constructor(start) {
2354
+ this.start = start;
2355
+ this.state = start.state;
2356
+ this.stack = start.stack;
2357
+ this.base = this.stack.length;
2358
+ }
2359
+ reduce(action) {
2360
+ let term = action & 65535, depth = action >> 19;
2361
+ if (depth == 0) {
2362
+ if (this.stack == this.start.stack)
2363
+ this.stack = this.stack.slice();
2364
+ this.stack.push(this.state, 0, 0);
2365
+ this.base += 3;
2366
+ } else {
2367
+ this.base -= (depth - 1) * 3;
2368
+ }
2369
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
2370
+ this.state = goto;
2371
+ }
2372
+ };
2373
+ var StackBufferCursor = class {
2374
+ constructor(stack, pos, index) {
2375
+ this.stack = stack;
2376
+ this.pos = pos;
2377
+ this.index = index;
2378
+ this.buffer = stack.buffer;
2379
+ if (this.index == 0)
2380
+ this.maybeNext();
2381
+ }
2382
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
2383
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
2384
+ }
2385
+ maybeNext() {
2386
+ let next = this.stack.parent;
2387
+ if (next != null) {
2388
+ this.index = this.stack.bufferBase - next.bufferBase;
2389
+ this.stack = next;
2390
+ this.buffer = next.buffer;
2391
+ }
2392
+ }
2393
+ get id() {
2394
+ return this.buffer[this.index - 4];
2395
+ }
2396
+ get start() {
2397
+ return this.buffer[this.index - 3];
2398
+ }
2399
+ get end() {
2400
+ return this.buffer[this.index - 2];
2401
+ }
2402
+ get size() {
2403
+ return this.buffer[this.index - 1];
2404
+ }
2405
+ next() {
2406
+ this.index -= 4;
2407
+ this.pos -= 4;
2408
+ if (this.index == 0)
2409
+ this.maybeNext();
2410
+ }
2411
+ fork() {
2412
+ return new StackBufferCursor(this.stack, this.pos, this.index);
2413
+ }
2414
+ };
2415
+ function decodeArray(input, Type = Uint16Array) {
2416
+ if (typeof input != "string")
2417
+ return input;
2418
+ let array = null;
2419
+ for (let pos = 0, out = 0; pos < input.length; ) {
2420
+ let value = 0;
2421
+ for (; ; ) {
2422
+ let next = input.charCodeAt(pos++), stop = false;
2423
+ if (next == 126) {
2424
+ value = 65535;
2425
+ break;
2426
+ }
2427
+ if (next >= 92)
2428
+ next--;
2429
+ if (next >= 34)
2430
+ next--;
2431
+ let digit = next - 32;
2432
+ if (digit >= 46) {
2433
+ digit -= 46;
2434
+ stop = true;
2435
+ }
2436
+ value += digit;
2437
+ if (stop)
2438
+ break;
2439
+ value *= 46;
2440
+ }
2441
+ if (array)
2442
+ array[out++] = value;
2443
+ else
2444
+ array = new Type(value);
2445
+ }
2446
+ return array;
2447
+ }
2448
+ var CachedToken = class {
2449
+ constructor() {
2450
+ this.start = -1;
2451
+ this.value = -1;
2452
+ this.end = -1;
2453
+ this.extended = -1;
2454
+ this.lookAhead = 0;
2455
+ this.mask = 0;
2456
+ this.context = 0;
2457
+ }
2458
+ };
2459
+ var nullToken = new CachedToken();
2460
+ var InputStream = class {
2461
+ /// @internal
2462
+ constructor(input, ranges) {
2463
+ this.input = input;
2464
+ this.ranges = ranges;
2465
+ this.chunk = "";
2466
+ this.chunkOff = 0;
2467
+ this.chunk2 = "";
2468
+ this.chunk2Pos = 0;
2469
+ this.next = -1;
2470
+ this.token = nullToken;
2471
+ this.rangeIndex = 0;
2472
+ this.pos = this.chunkPos = ranges[0].from;
2473
+ this.range = ranges[0];
2474
+ this.end = ranges[ranges.length - 1].to;
2475
+ this.readNext();
2476
+ }
2477
+ /// @internal
2478
+ resolveOffset(offset, assoc) {
2479
+ let range = this.range, index = this.rangeIndex;
2480
+ let pos = this.pos + offset;
2481
+ while (pos < range.from) {
2482
+ if (!index)
2483
+ return null;
2484
+ let next = this.ranges[--index];
2485
+ pos -= range.from - next.to;
2486
+ range = next;
2487
+ }
2488
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
2489
+ if (index == this.ranges.length - 1)
2490
+ return null;
2491
+ let next = this.ranges[++index];
2492
+ pos += next.from - range.to;
2493
+ range = next;
2494
+ }
2495
+ return pos;
2496
+ }
2497
+ /// @internal
2498
+ clipPos(pos) {
2499
+ if (pos >= this.range.from && pos < this.range.to)
2500
+ return pos;
2501
+ for (let range of this.ranges)
2502
+ if (range.to > pos)
2503
+ return Math.max(pos, range.from);
2504
+ return this.end;
2505
+ }
2506
+ /// Look at a code unit near the stream position. `.peek(0)` equals
2507
+ /// `.next`, `.peek(-1)` gives you the previous character, and so
2508
+ /// on.
2509
+ ///
2510
+ /// Note that looking around during tokenizing creates dependencies
2511
+ /// on potentially far-away content, which may reduce the
2512
+ /// effectiveness incremental parsing—when looking forward—or even
2513
+ /// cause invalid reparses when looking backward more than 25 code
2514
+ /// units, since the library does not track lookbehind.
2515
+ peek(offset) {
2516
+ let idx = this.chunkOff + offset, pos, result;
2517
+ if (idx >= 0 && idx < this.chunk.length) {
2518
+ pos = this.pos + offset;
2519
+ result = this.chunk.charCodeAt(idx);
2520
+ } else {
2521
+ let resolved = this.resolveOffset(offset, 1);
2522
+ if (resolved == null)
2523
+ return -1;
2524
+ pos = resolved;
2525
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
2526
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
2527
+ } else {
2528
+ let i = this.rangeIndex, range = this.range;
2529
+ while (range.to <= pos)
2530
+ range = this.ranges[++i];
2531
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
2532
+ if (pos + this.chunk2.length > range.to)
2533
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
2534
+ result = this.chunk2.charCodeAt(0);
2535
+ }
2536
+ }
2537
+ if (pos >= this.token.lookAhead)
2538
+ this.token.lookAhead = pos + 1;
2539
+ return result;
2540
+ }
2541
+ /// Accept a token. By default, the end of the token is set to the
2542
+ /// current stream position, but you can pass an offset (relative to
2543
+ /// the stream position) to change that.
2544
+ acceptToken(token, endOffset = 0) {
2545
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2546
+ if (end == null || end < this.token.start)
2547
+ throw new RangeError("Token end out of bounds");
2548
+ this.token.value = token;
2549
+ this.token.end = end;
2550
+ }
2551
+ getChunk() {
2552
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2553
+ let { chunk, chunkPos } = this;
2554
+ this.chunk = this.chunk2;
2555
+ this.chunkPos = this.chunk2Pos;
2556
+ this.chunk2 = chunk;
2557
+ this.chunk2Pos = chunkPos;
2558
+ this.chunkOff = this.pos - this.chunkPos;
2559
+ } else {
2560
+ this.chunk2 = this.chunk;
2561
+ this.chunk2Pos = this.chunkPos;
2562
+ let nextChunk = this.input.chunk(this.pos);
2563
+ let end = this.pos + nextChunk.length;
2564
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2565
+ this.chunkPos = this.pos;
2566
+ this.chunkOff = 0;
2567
+ }
2568
+ }
2569
+ readNext() {
2570
+ if (this.chunkOff >= this.chunk.length) {
2571
+ this.getChunk();
2572
+ if (this.chunkOff == this.chunk.length)
2573
+ return this.next = -1;
2574
+ }
2575
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
2576
+ }
2577
+ /// Move the stream forward N (defaults to 1) code units. Returns
2578
+ /// the new value of [`next`](#lr.InputStream.next).
2579
+ advance(n = 1) {
2580
+ this.chunkOff += n;
2581
+ while (this.pos + n >= this.range.to) {
2582
+ if (this.rangeIndex == this.ranges.length - 1)
2583
+ return this.setDone();
2584
+ n -= this.range.to - this.pos;
2585
+ this.range = this.ranges[++this.rangeIndex];
2586
+ this.pos = this.range.from;
2587
+ }
2588
+ this.pos += n;
2589
+ if (this.pos >= this.token.lookAhead)
2590
+ this.token.lookAhead = this.pos + 1;
2591
+ return this.readNext();
2592
+ }
2593
+ setDone() {
2594
+ this.pos = this.chunkPos = this.end;
2595
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2596
+ this.chunk = "";
2597
+ return this.next = -1;
2598
+ }
2599
+ /// @internal
2600
+ reset(pos, token) {
2601
+ if (token) {
2602
+ this.token = token;
2603
+ token.start = pos;
2604
+ token.lookAhead = pos + 1;
2605
+ token.value = token.extended = -1;
2606
+ } else {
2607
+ this.token = nullToken;
2608
+ }
2609
+ if (this.pos != pos) {
2610
+ this.pos = pos;
2611
+ if (pos == this.end) {
2612
+ this.setDone();
2613
+ return this;
2614
+ }
2615
+ while (pos < this.range.from)
2616
+ this.range = this.ranges[--this.rangeIndex];
2617
+ while (pos >= this.range.to)
2618
+ this.range = this.ranges[++this.rangeIndex];
2619
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
2620
+ this.chunkOff = pos - this.chunkPos;
2621
+ } else {
2622
+ this.chunk = "";
2623
+ this.chunkOff = 0;
2624
+ }
2625
+ this.readNext();
2626
+ }
2627
+ return this;
2628
+ }
2629
+ /// @internal
2630
+ read(from, to) {
2631
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
2632
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
2633
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
2634
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
2635
+ if (from >= this.range.from && to <= this.range.to)
2636
+ return this.input.read(from, to);
2637
+ let result = "";
2638
+ for (let r2 of this.ranges) {
2639
+ if (r2.from >= to)
2640
+ break;
2641
+ if (r2.to > from)
2642
+ result += this.input.read(Math.max(r2.from, from), Math.min(r2.to, to));
2643
+ }
2644
+ return result;
2645
+ }
2646
+ };
2647
+ var TokenGroup = class {
2648
+ constructor(data, id) {
2649
+ this.data = data;
2650
+ this.id = id;
2651
+ }
2652
+ token(input, stack) {
2653
+ let { parser: parser2 } = stack.p;
2654
+ readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
2655
+ }
2656
+ };
2657
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2658
+ var LocalTokenGroup = class {
2659
+ constructor(data, precTable, elseToken) {
2660
+ this.precTable = precTable;
2661
+ this.elseToken = elseToken;
2662
+ this.data = typeof data == "string" ? decodeArray(data) : data;
2663
+ }
2664
+ token(input, stack) {
2665
+ let start = input.pos, skipped = 0;
2666
+ for (; ; ) {
2667
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
2668
+ if (input.token.value > -1)
2669
+ break;
2670
+ if (this.elseToken == null)
2671
+ return;
2672
+ if (input.next < 0)
2673
+ break;
2674
+ input.advance();
2675
+ input.reset(input.pos, input.token);
2676
+ skipped++;
2677
+ }
2678
+ if (skipped) {
2679
+ input.reset(start, input.token);
2680
+ input.acceptToken(this.elseToken, skipped);
2681
+ }
2682
+ }
2683
+ };
2684
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2685
+ function readToken(data, input, stack, group, precTable, precOffset) {
2686
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
2687
+ scan:
2688
+ for (; ; ) {
2689
+ if ((groupMask & data[state]) == 0)
2690
+ break;
2691
+ let accEnd = data[state + 1];
2692
+ for (let i = state + 3; i < accEnd; i += 2)
2693
+ if ((data[i + 1] & groupMask) > 0) {
2694
+ let term = data[i];
2695
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
2696
+ input.acceptToken(term);
2697
+ break;
2698
+ }
2699
+ }
2700
+ let next = input.next, low = 0, high = data[state + 2];
2701
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
2702
+ state = data[accEnd + high * 3 - 1];
2703
+ continue scan;
2704
+ }
2705
+ for (; low < high; ) {
2706
+ let mid = low + high >> 1;
2707
+ let index = accEnd + mid + (mid << 1);
2708
+ let from = data[index], to = data[index + 1] || 65536;
2709
+ if (next < from)
2710
+ high = mid;
2711
+ else if (next >= to)
2712
+ low = mid + 1;
2713
+ else {
2714
+ state = data[index + 2];
2715
+ input.advance();
2716
+ continue scan;
2717
+ }
2718
+ }
2719
+ break;
2720
+ }
2721
+ }
2722
+ function findOffset(data, start, term) {
2723
+ for (let i = start, next; (next = data[i]) != 65535; i++)
2724
+ if (next == term)
2725
+ return i - start;
2726
+ return -1;
2727
+ }
2728
+ function overrides(token, prev, tableData, tableOffset) {
2729
+ let iPrev = findOffset(tableData, tableOffset, prev);
2730
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
2731
+ }
2732
+ var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
2733
+ var stackIDs = null;
2734
+ var Safety;
2735
+ (function(Safety2) {
2736
+ Safety2[Safety2["Margin"] = 25] = "Margin";
2737
+ })(Safety || (Safety = {}));
2738
+ function cutAt(tree, pos, side) {
2739
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
2740
+ cursor.moveTo(pos);
2741
+ for (; ; ) {
2742
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
2743
+ for (; ; ) {
2744
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
2745
+ return side < 0 ? Math.max(0, Math.min(
2746
+ cursor.to - 1,
2747
+ pos - 25
2748
+ /* Safety.Margin */
2749
+ )) : Math.min(tree.length, Math.max(
2750
+ cursor.from + 1,
2751
+ pos + 25
2752
+ /* Safety.Margin */
2753
+ ));
2754
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
2755
+ break;
2756
+ if (!cursor.parent())
2757
+ return side < 0 ? 0 : tree.length;
2758
+ }
2759
+ }
2760
+ }
2761
+ var FragmentCursor = class {
2762
+ constructor(fragments, nodeSet) {
2763
+ this.fragments = fragments;
2764
+ this.nodeSet = nodeSet;
2765
+ this.i = 0;
2766
+ this.fragment = null;
2767
+ this.safeFrom = -1;
2768
+ this.safeTo = -1;
2769
+ this.trees = [];
2770
+ this.start = [];
2771
+ this.index = [];
2772
+ this.nextFragment();
2773
+ }
2774
+ nextFragment() {
2775
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
2776
+ if (fr) {
2777
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
2778
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
2779
+ while (this.trees.length) {
2780
+ this.trees.pop();
2781
+ this.start.pop();
2782
+ this.index.pop();
2783
+ }
2784
+ this.trees.push(fr.tree);
2785
+ this.start.push(-fr.offset);
2786
+ this.index.push(0);
2787
+ this.nextStart = this.safeFrom;
2788
+ } else {
2789
+ this.nextStart = 1e9;
2790
+ }
2791
+ }
2792
+ // `pos` must be >= any previously given `pos` for this cursor
2793
+ nodeAt(pos) {
2794
+ if (pos < this.nextStart)
2795
+ return null;
2796
+ while (this.fragment && this.safeTo <= pos)
2797
+ this.nextFragment();
2798
+ if (!this.fragment)
2799
+ return null;
2800
+ for (; ; ) {
2801
+ let last = this.trees.length - 1;
2802
+ if (last < 0) {
2803
+ this.nextFragment();
2804
+ return null;
2805
+ }
2806
+ let top = this.trees[last], index = this.index[last];
2807
+ if (index == top.children.length) {
2808
+ this.trees.pop();
2809
+ this.start.pop();
2810
+ this.index.pop();
2811
+ continue;
2812
+ }
2813
+ let next = top.children[index];
2814
+ let start = this.start[last] + top.positions[index];
2815
+ if (start > pos) {
2816
+ this.nextStart = start;
2817
+ return null;
2818
+ }
2819
+ if (next instanceof Tree) {
2820
+ if (start == pos) {
2821
+ if (start < this.safeFrom)
2822
+ return null;
2823
+ let end = start + next.length;
2824
+ if (end <= this.safeTo) {
2825
+ let lookAhead = next.prop(NodeProp.lookAhead);
2826
+ if (!lookAhead || end + lookAhead < this.fragment.to)
2827
+ return next;
2828
+ }
2829
+ }
2830
+ this.index[last]++;
2831
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
2832
+ this.trees.push(next);
2833
+ this.start.push(start);
2834
+ this.index.push(0);
2835
+ }
2836
+ } else {
2837
+ this.index[last]++;
2838
+ this.nextStart = start + next.length;
2839
+ }
2840
+ }
2841
+ }
2842
+ };
2843
+ var TokenCache = class {
2844
+ constructor(parser2, stream) {
2845
+ this.stream = stream;
2846
+ this.tokens = [];
2847
+ this.mainToken = null;
2848
+ this.actions = [];
2849
+ this.tokens = parser2.tokenizers.map((_) => new CachedToken());
2850
+ }
2851
+ getActions(stack) {
2852
+ let actionIndex = 0;
2853
+ let main = null;
2854
+ let { parser: parser2 } = stack.p, { tokenizers } = parser2;
2855
+ let mask = parser2.stateSlot(
2856
+ stack.state,
2857
+ 3
2858
+ /* ParseState.TokenizerMask */
2859
+ );
2860
+ let context = stack.curContext ? stack.curContext.hash : 0;
2861
+ let lookAhead = 0;
2862
+ for (let i = 0; i < tokenizers.length; i++) {
2863
+ if ((1 << i & mask) == 0)
2864
+ continue;
2865
+ let tokenizer = tokenizers[i], token = this.tokens[i];
2866
+ if (main && !tokenizer.fallback)
2867
+ continue;
2868
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
2869
+ this.updateCachedToken(token, tokenizer, stack);
2870
+ token.mask = mask;
2871
+ token.context = context;
2872
+ }
2873
+ if (token.lookAhead > token.end + 25)
2874
+ lookAhead = Math.max(token.lookAhead, lookAhead);
2875
+ if (token.value != 0) {
2876
+ let startIndex = actionIndex;
2877
+ if (token.extended > -1)
2878
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
2879
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
2880
+ if (!tokenizer.extend) {
2881
+ main = token;
2882
+ if (actionIndex > startIndex)
2883
+ break;
2884
+ }
2885
+ }
2886
+ }
2887
+ while (this.actions.length > actionIndex)
2888
+ this.actions.pop();
2889
+ if (lookAhead)
2890
+ stack.setLookAhead(lookAhead);
2891
+ if (!main && stack.pos == this.stream.end) {
2892
+ main = new CachedToken();
2893
+ main.value = stack.p.parser.eofTerm;
2894
+ main.start = main.end = stack.pos;
2895
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
2896
+ }
2897
+ this.mainToken = main;
2898
+ return this.actions;
2899
+ }
2900
+ getMainToken(stack) {
2901
+ if (this.mainToken)
2902
+ return this.mainToken;
2903
+ let main = new CachedToken(), { pos, p } = stack;
2904
+ main.start = pos;
2905
+ main.end = Math.min(pos + 1, p.stream.end);
2906
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
2907
+ return main;
2908
+ }
2909
+ updateCachedToken(token, tokenizer, stack) {
2910
+ let start = this.stream.clipPos(stack.pos);
2911
+ tokenizer.token(this.stream.reset(start, token), stack);
2912
+ if (token.value > -1) {
2913
+ let { parser: parser2 } = stack.p;
2914
+ for (let i = 0; i < parser2.specialized.length; i++)
2915
+ if (parser2.specialized[i] == token.value) {
2916
+ let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
2917
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
2918
+ if ((result & 1) == 0)
2919
+ token.value = result >> 1;
2920
+ else
2921
+ token.extended = result >> 1;
2922
+ break;
2923
+ }
2924
+ }
2925
+ } else {
2926
+ token.value = 0;
2927
+ token.end = this.stream.clipPos(start + 1);
2928
+ }
2929
+ }
2930
+ putAction(action, token, end, index) {
2931
+ for (let i = 0; i < index; i += 3)
2932
+ if (this.actions[i] == action)
2933
+ return index;
2934
+ this.actions[index++] = action;
2935
+ this.actions[index++] = token;
2936
+ this.actions[index++] = end;
2937
+ return index;
2938
+ }
2939
+ addActions(stack, token, end, index) {
2940
+ let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
2941
+ for (let set = 0; set < 2; set++) {
2942
+ for (let i = parser2.stateSlot(
2943
+ state,
2944
+ set ? 2 : 1
2945
+ /* ParseState.Actions */
2946
+ ); ; i += 3) {
2947
+ if (data[i] == 65535) {
2948
+ if (data[i + 1] == 1) {
2949
+ i = pair(data, i + 2);
2950
+ } else {
2951
+ if (index == 0 && data[i + 1] == 2)
2952
+ index = this.putAction(pair(data, i + 2), token, end, index);
2953
+ break;
2954
+ }
2955
+ }
2956
+ if (data[i] == token)
2957
+ index = this.putAction(pair(data, i + 1), token, end, index);
2958
+ }
2959
+ }
2960
+ return index;
2961
+ }
2962
+ };
2963
+ var Rec;
2964
+ (function(Rec2) {
2965
+ Rec2[Rec2["Distance"] = 5] = "Distance";
2966
+ Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
2967
+ Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
2968
+ Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
2969
+ Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
2970
+ Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
2971
+ Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
2972
+ Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
2973
+ })(Rec || (Rec = {}));
2974
+ var Parse = class {
2975
+ constructor(parser2, input, fragments, ranges) {
2976
+ this.parser = parser2;
2977
+ this.input = input;
2978
+ this.ranges = ranges;
2979
+ this.recovering = 0;
2980
+ this.nextStackID = 9812;
2981
+ this.minStackPos = 0;
2982
+ this.reused = [];
2983
+ this.stoppedAt = null;
2984
+ this.lastBigReductionStart = -1;
2985
+ this.lastBigReductionSize = 0;
2986
+ this.bigReductionCount = 0;
2987
+ this.stream = new InputStream(input, ranges);
2988
+ this.tokens = new TokenCache(parser2, this.stream);
2989
+ this.topTerm = parser2.top[1];
2990
+ let { from } = ranges[0];
2991
+ this.stacks = [Stack.start(this, parser2.top[0], from)];
2992
+ this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
2993
+ }
2994
+ get parsedPos() {
2995
+ return this.minStackPos;
2996
+ }
2997
+ // Move the parser forward. This will process all parse stacks at
2998
+ // `this.pos` and try to advance them to a further position. If no
2999
+ // stack for such a position is found, it'll start error-recovery.
3000
+ //
3001
+ // When the parse is finished, this will return a syntax tree. When
3002
+ // not, it returns `null`.
3003
+ advance() {
3004
+ let stacks = this.stacks, pos = this.minStackPos;
3005
+ let newStacks = this.stacks = [];
3006
+ let stopped, stoppedTokens;
3007
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
3008
+ let [s] = stacks;
3009
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
3010
+ }
3011
+ this.bigReductionCount = this.lastBigReductionSize = 0;
3012
+ }
3013
+ for (let i = 0; i < stacks.length; i++) {
3014
+ let stack = stacks[i];
3015
+ for (; ; ) {
3016
+ this.tokens.mainToken = null;
3017
+ if (stack.pos > pos) {
3018
+ newStacks.push(stack);
3019
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
3020
+ continue;
3021
+ } else {
3022
+ if (!stopped) {
3023
+ stopped = [];
3024
+ stoppedTokens = [];
3025
+ }
3026
+ stopped.push(stack);
3027
+ let tok = this.tokens.getMainToken(stack);
3028
+ stoppedTokens.push(tok.value, tok.end);
3029
+ }
3030
+ break;
3031
+ }
3032
+ }
3033
+ if (!newStacks.length) {
3034
+ let finished = stopped && findFinished(stopped);
3035
+ if (finished)
3036
+ return this.stackToTree(finished);
3037
+ if (this.parser.strict) {
3038
+ if (verbose && stopped)
3039
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
3040
+ throw new SyntaxError("No parse at " + pos);
3041
+ }
3042
+ if (!this.recovering)
3043
+ this.recovering = 5;
3044
+ }
3045
+ if (this.recovering && stopped) {
3046
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
3047
+ if (finished)
3048
+ return this.stackToTree(finished.forceAll());
3049
+ }
3050
+ if (this.recovering) {
3051
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
3052
+ if (newStacks.length > maxRemaining) {
3053
+ newStacks.sort((a, b) => b.score - a.score);
3054
+ while (newStacks.length > maxRemaining)
3055
+ newStacks.pop();
3056
+ }
3057
+ if (newStacks.some((s) => s.reducePos > pos))
3058
+ this.recovering--;
3059
+ } else if (newStacks.length > 1) {
3060
+ outer:
3061
+ for (let i = 0; i < newStacks.length - 1; i++) {
3062
+ let stack = newStacks[i];
3063
+ for (let j = i + 1; j < newStacks.length; j++) {
3064
+ let other = newStacks[j];
3065
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
3066
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
3067
+ newStacks.splice(j--, 1);
3068
+ } else {
3069
+ newStacks.splice(i--, 1);
3070
+ continue outer;
3071
+ }
3072
+ }
3073
+ }
3074
+ }
3075
+ if (newStacks.length > 12)
3076
+ newStacks.splice(
3077
+ 12,
3078
+ newStacks.length - 12
3079
+ /* Rec.MaxStackCount */
3080
+ );
3081
+ }
3082
+ this.minStackPos = newStacks[0].pos;
3083
+ for (let i = 1; i < newStacks.length; i++)
3084
+ if (newStacks[i].pos < this.minStackPos)
3085
+ this.minStackPos = newStacks[i].pos;
3086
+ return null;
3087
+ }
3088
+ stopAt(pos) {
3089
+ if (this.stoppedAt != null && this.stoppedAt < pos)
3090
+ throw new RangeError("Can't move stoppedAt forward");
3091
+ this.stoppedAt = pos;
3092
+ }
3093
+ // Returns an updated version of the given stack, or null if the
3094
+ // stack can't advance normally. When `split` and `stacks` are
3095
+ // given, stacks split off by ambiguous operations will be pushed to
3096
+ // `split`, or added to `stacks` if they move `pos` forward.
3097
+ advanceStack(stack, stacks, split) {
3098
+ let start = stack.pos, { parser: parser2 } = this;
3099
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3100
+ if (this.stoppedAt != null && start > this.stoppedAt)
3101
+ return stack.forceReduce() ? stack : null;
3102
+ if (this.fragments) {
3103
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
3104
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
3105
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
3106
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
3107
+ stack.useNode(cached, match);
3108
+ if (verbose)
3109
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
3110
+ return true;
3111
+ }
3112
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
3113
+ break;
3114
+ let inner = cached.children[0];
3115
+ if (inner instanceof Tree && cached.positions[0] == 0)
3116
+ cached = inner;
3117
+ else
3118
+ break;
3119
+ }
3120
+ }
3121
+ let defaultReduce = parser2.stateSlot(
3122
+ stack.state,
3123
+ 4
3124
+ /* ParseState.DefaultReduce */
3125
+ );
3126
+ if (defaultReduce > 0) {
3127
+ stack.reduce(defaultReduce);
3128
+ if (verbose)
3129
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
3130
+ defaultReduce & 65535
3131
+ /* Action.ValueMask */
3132
+ )})`);
3133
+ return true;
3134
+ }
3135
+ if (stack.stack.length >= 15e3) {
3136
+ while (stack.stack.length > 9e3 && stack.forceReduce()) {
3137
+ }
3138
+ }
3139
+ let actions = this.tokens.getActions(stack);
3140
+ for (let i = 0; i < actions.length; ) {
3141
+ let action = actions[i++], term = actions[i++], end = actions[i++];
3142
+ let last = i == actions.length || !split;
3143
+ let localStack = last ? stack : stack.split();
3144
+ localStack.apply(action, term, end);
3145
+ if (verbose)
3146
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
3147
+ action & 65535
3148
+ /* Action.ValueMask */
3149
+ )}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
3150
+ if (last)
3151
+ return true;
3152
+ else if (localStack.pos > start)
3153
+ stacks.push(localStack);
3154
+ else
3155
+ split.push(localStack);
3156
+ }
3157
+ return false;
3158
+ }
3159
+ // Advance a given stack forward as far as it will go. Returns the
3160
+ // (possibly updated) stack if it got stuck, or null if it moved
3161
+ // forward and was given to `pushStackDedup`.
3162
+ advanceFully(stack, newStacks) {
3163
+ let pos = stack.pos;
3164
+ for (; ; ) {
3165
+ if (!this.advanceStack(stack, null, null))
3166
+ return false;
3167
+ if (stack.pos > pos) {
3168
+ pushStackDedup(stack, newStacks);
3169
+ return true;
3170
+ }
3171
+ }
3172
+ }
3173
+ runRecovery(stacks, tokens, newStacks) {
3174
+ let finished = null, restarted = false;
3175
+ for (let i = 0; i < stacks.length; i++) {
3176
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
3177
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3178
+ if (stack.deadEnd) {
3179
+ if (restarted)
3180
+ continue;
3181
+ restarted = true;
3182
+ stack.restart();
3183
+ if (verbose)
3184
+ console.log(base + this.stackID(stack) + " (restarted)");
3185
+ let done = this.advanceFully(stack, newStacks);
3186
+ if (done)
3187
+ continue;
3188
+ }
3189
+ let force = stack.split(), forceBase = base;
3190
+ for (let j = 0; force.forceReduce() && j < 10; j++) {
3191
+ if (verbose)
3192
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
3193
+ let done = this.advanceFully(force, newStacks);
3194
+ if (done)
3195
+ break;
3196
+ if (verbose)
3197
+ forceBase = this.stackID(force) + " -> ";
3198
+ }
3199
+ for (let insert of stack.recoverByInsert(token)) {
3200
+ if (verbose)
3201
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
3202
+ this.advanceFully(insert, newStacks);
3203
+ }
3204
+ if (this.stream.end > stack.pos) {
3205
+ if (tokenEnd == stack.pos) {
3206
+ tokenEnd++;
3207
+ token = 0;
3208
+ }
3209
+ stack.recoverByDelete(token, tokenEnd);
3210
+ if (verbose)
3211
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
3212
+ pushStackDedup(stack, newStacks);
3213
+ } else if (!finished || finished.score < stack.score) {
3214
+ finished = stack;
3215
+ }
3216
+ }
3217
+ return finished;
3218
+ }
3219
+ // Convert the stack's buffer to a syntax tree.
3220
+ stackToTree(stack) {
3221
+ stack.close();
3222
+ return Tree.build({
3223
+ buffer: StackBufferCursor.create(stack),
3224
+ nodeSet: this.parser.nodeSet,
3225
+ topID: this.topTerm,
3226
+ maxBufferLength: this.parser.bufferLength,
3227
+ reused: this.reused,
3228
+ start: this.ranges[0].from,
3229
+ length: stack.pos - this.ranges[0].from,
3230
+ minRepeatType: this.parser.minRepeatTerm
3231
+ });
3232
+ }
3233
+ stackID(stack) {
3234
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
3235
+ if (!id)
3236
+ stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
3237
+ return id + stack;
3238
+ }
3239
+ };
3240
+ function pushStackDedup(stack, newStacks) {
3241
+ for (let i = 0; i < newStacks.length; i++) {
3242
+ let other = newStacks[i];
3243
+ if (other.pos == stack.pos && other.sameState(stack)) {
3244
+ if (newStacks[i].score < stack.score)
3245
+ newStacks[i] = stack;
3246
+ return;
3247
+ }
3248
+ }
3249
+ newStacks.push(stack);
30
3250
  }
31
- `;Le(Bo);var $o=e=>(...o)=>[e,...o].join("-"),zo=$o("saltIcon"),Xo=1,We=(0,Ue.forwardRef)(function({children:o,className:r,size:t=Xo,style:n,...i},s){let p={...n,"--saltIcon-size-multiplier":`${t}`};return(0,Se.jsx)("svg",{className:Me(zo(),r),style:p,role:"img",...i,ref:s,children:(0,Se.jsx)("g",{"aria-hidden":!0,children:o})})});var _=require("react/jsx-runtime"),He=require("react");var Fe=(0,He.forwardRef)(function(o,r){return(0,_.jsxs)(We,{"data-testid":"DeleteIcon","aria-label":"delete",viewBox:"0 0 12 12",ref:r,...o,children:[(0,_.jsx)("path",{d:"M5 4v6H4V4h1Zm2 0v6H6V4h1Z"}),(0,_.jsx)("path",{fillRule:"evenodd",d:"M4 0a1 1 0 0 0-1 1v1H0v1h1v7a2 2 0 0 0 2 2h5.25A1.75 1.75 0 0 0 10 10.25V3h1V2H8V1a1 1 0 0 0-1-1H4Zm5 3H2v7a1 1 0 0 0 1 1h5.25a.75.75 0 0 0 .75-.75V3ZM7 2H4v-.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V2Z",clipRule:"evenodd"})]})});var B=require("@heswell/salt-lab");var ie=require("@vuu-ui/vuu-utils");var _o=new Set(["=","!=",">",">=","<","<=","starts","ends"]),he=e=>e!==void 0&&e.name!==void 0,k=e=>e!==void 0&&_o.has(e.op),Go=e=>e!==void 0&&(k(e)||D(e)),D=e=>e!==void 0&&e.op==="in",W=e=>e.op==="in",re=e=>e.op==="and",Ce=e=>e.op==="or";function V(e){return e!==void 0&&(e.op==="and"||e.op==="or")}var h="and",te="=",jo=">",Zo="<",Be="or",Oe="starts",Yo="ends",$e="in",ze=(e,o=[])=>(e&&(V(e)?e.filters.forEach(r=>o.push(...ze(r))):o.push(e)),o),qo={combineWith:"and"},G=(e,o,{combineWith:r=h}=qo)=>{var t;if(be(o))V(o)||(e=ve(e,{name:o.column}));else if(Jo(o))return V(o),ve(e,{name:(t=o.column)!=null?t:""});if(!e)return o;if(!o)return e;if(e.op===h&&o.op===h)return{op:h,filters:rr(e.filters,o.filters)};if(e.op===h){let n=er(e.filters,o);return n.length>1?{op:h,filters:n}:n[0]}return o.op===h?{op:h,filters:o.filters.concat(e)}:ne(e,o,!0)?o:Ge(e,o)?or(e,o):{op:r,filters:[e,o]}},be=e=>e?W(e)&&e.values.length===0?!0:re(e)&&e.filters.some(o=>be(o)):!1,Ko=e=>typeof e=="string"?`"${e}"`:e,H=e=>V(e)?e.filters.map(o=>H(o)).join(` ${e.op} `):D(e)?`${e.column} ${e.op} [${e.values.join(",")}]`:`${e.column} ${e.op} ${Ko(e.value)}`,Jo=e=>e?e.op===Oe&&e.value===""?!0:e.op===Oe&&e.value==="":!1,er=(e,o)=>e.concat(o),or=(e,o)=>be(o)?o:W(e)&&W(o)?{...e,values:[...e.values,...o.values.filter(r=>!e.values.includes(r))]}:W(e)&&o.op===te?{...e,values:e.values.concat([o.value])}:e.op===te&&o.op===te?{column:e.column,op:$e,values:[e.value,o.value]}:o,rr=(e,o)=>{let r=({op:i},{op:s})=>i===s||i[0]===s[0],t=(i,s)=>i.column===s.column&&r(i,s),n=i=>o.some(s=>t(i,s))===!1;return e.filter(n).concat(o)},tr=(e,o)=>{if(V(o)){let[r,t]=o.filters;if(r.column===e.name)return[t,H(t)];if(t.column===e.name)return[r,H(r)]}return[void 0,""]},nr=(e,o)=>{if(ne(e,o,!0))return null;if(e.op!==h)throw Error(`removeFilter cannot remove ${JSON.stringify(o)} from ${JSON.stringify(e)}`);let r=e.filters.filter(t=>!ne(t,o));return r.length>0?{type:h,filters:r}:null},ir=(e,o)=>{if(!e)return[null,null];if(e.column===o)return[e,null];if(e.op!==h)return[null,e];let[[r=null],t]=(0,ie.partition)(e.filters,n=>n.column===o);return t.length===1?[r,t[0]]:[r,{op:h,filters:t}]},Xe=(e,o)=>V(e)?{op:e.op,filters:e.filters.map(r=>Xe(r,o))}:{...e,column:o},_e=(e,o)=>{if(!e)return!1;let{op:r,column:t}=e;switch(r){case h:case Be:return e.filters!=null&&e.filters.some(n=>_e(n,o));default:return t===o.name}},ve=(e,o)=>{let r=o.name;if(e&&e.column!==r){if(re(e)||Ce(e)){let{op:t}=e,i=e.filters.filter(s=>s.column!==r);switch(i.length){case 0:return;case 1:return i[0];default:return{op:t,filters:i}}}return e}},Ge=(e,o)=>e.column===o.column&&(e.op==="="||e.op==="in")&&(o.op==="="||o.op==="in"),sr=(e,o)=>{if(e===o)return!0;if(e.length===o.length){let r=e.slice().sort(),t=o.slice().sort();return r.join("|")===t.join("|")}return!1},ne=(e,o,r=!1)=>r?e&&o&&Ge(e,o)?e.op===o.op&&(k(e)&&k(o)&&e.value===o.value||D(e)&&D(o)&&sr(e.values,o.values)):!1:!0,je=(e,o,r)=>{if(e&&o){if(r==="replace")return o;if(e.op==="and")return{...e,filters:e.filters.concat(o)};let{column:t}=o;if(t&&(o.column?(0,ie.extractFilterForColumn)(e,t):void 0)&&t){let i=ve(e,{name:t});return je(i,o,"add")}return{op:"and",filters:[e,o]}}return o||e};var j=e=>/\.\.\.$/.test(e),Ze=(e,o,r)=>{if(o.length!==0){if(r){let t=o[0].substring(0,o[0].length-3);return{column:e,op:"starts",value:`"${t}"`}}return{column:e,op:"in",values:o.map(t=>`"${t}"`)}}},ye=(e,o,r)=>{let t=o===void 0?void 0:{column:e,op:">",value:o-1},n=r===void 0?void 0:{column:e,op:"<",value:r+1};return n===void 0?t:G(t,n,{combineWith:"and"})};var M=require("react/jsx-runtime"),Ye=({defaultTypeaheadParams:e,filterValues:o,onChange:r})=>{var s,p;let t=e[1],n=f=>{let l=parseFloat(f.target.value),u={start:isNaN(l)?void 0:l,end:o==null?void 0:o.end},m=ye(t,u.start,u.end);r(u,m)},i=f=>{let l=parseFloat(f.target.value),u={start:o==null?void 0:o.start,end:isNaN(l)?void 0:l},m=ye(t,u.start,u.end);r(u,m)};return(0,M.jsxs)("div",{style:{display:"flex",flexDirection:"row"},children:[(0,M.jsx)(B.ToolbarField,{label:"From",children:(0,M.jsx)(B.Input,{onChange:n,value:((s=o==null?void 0:o.start)==null?void 0:s.toString())||"",type:"number"})}),(0,M.jsx)(B.ToolbarField,{label:"To",children:(0,M.jsx)(B.Input,{onChange:i,value:((p=o==null?void 0:o.end)==null?void 0:p.toString())||"",type:"number"})})]})};var Q=require("react"),qe=require("@vuu-ui/vuu-data"),Ke=require("@heswell/salt-lab");var eo=require("react/jsx-runtime"),Je=({defaultTypeaheadParams:e,filterValues:o=[],onChange:r})=>{let[t,n]=e,[i,s]=(0,Q.useState)(""),[p,f]=(0,Q.useState)([]),l=(0,qe.useTypeaheadSuggestions)();(0,Q.useEffect)(()=>{let a=i?[t,n,i]:e,c=!0;return l(a).then(x=>{c&&(j(o[0])&&x.unshift(o[0]),i&&x.unshift(`${i}...`),x.concat(o),f(x))}),()=>{c=!1}},[o,i,n,t,l,e]);let u=(0,Q.useCallback)(a=>{let c=a.target.value;s(c)},[]),m=(0,Q.useCallback)((a,c)=>{if(s(""),c===null)return;c.some(j)&&(c=c.filter(j).slice(-1));let x=Ze(n,c,j(c[0]));r(c,x)},[n,r]);return(0,eo.jsx)(Ke.ComboBoxDeprecated,{multiSelect:!0,onInputChange:u,onChange:m,source:p,style:{minWidth:200},inputValue:i,selectedItem:o},n)};var oo=require("react"),se=require("@heswell/salt-lab"),Z=require("react/jsx-runtime"),ro=e=>(0,Z.jsx)(lr,{...e}),lr=(0,oo.memo)(function({item:o,itemTextHighlightPattern:r,...t}){return(0,Z.jsx)(se.ListItem,{...t,children:(0,Z.jsx)("span",{style:{marginLeft:10},children:(0,Z.jsx)(se.Highlighter,{matchPattern:r,text:o==null?void 0:o.name})})})});var w=require("react");var Pe=(e,o,r)=>e.filter(t=>t[r]!==o[r]).concat(o),to=e=>{var C,y;let[o,r]=(0,w.useState)(""),[t,n]=(0,w.useState)([]),[i,s]=(0,w.useState)([]),[p,f]=(0,w.useState)([]),l=()=>{r(""),s([]),f([]),n([]),e("")},u=(0,w.useCallback)(g=>{let F=Pe(t,{column:o,filter:g},"column");n(F);let N=F.map(U=>U.filter).reduce((U,X)=>X===void 0?U:G(U,X,{combineWith:h}),void 0),xe=N===void 0?"":H(N);e(xe,N)},[o,e,t]),m=(0,w.useCallback)((g,F)=>{f(Pe(p,{column:o,value:g},"column")),u(F)},[o,p,u]),a=(0,w.useCallback)((g,F)=>{s(Pe(i,{column:o,value:g},"column")),u(F)},[o,i,u]),c=(0,w.useCallback)(g=>r((g==null?void 0:g.name)||""),[]),x=(C=i.filter(g=>g.column===o)[0])==null?void 0:C.value,d=(y=p.filter(g=>g.column===o)[0])==null?void 0:y.value;return{clear:l,selectedColumnName:o,rangeValue:x,typeaheadValue:d,onSelectedColumnChange:c,onRangeChange:a,onTypeaheadChange:m}};var v=require("react/jsx-runtime"),ar=({className:e,table:o,columns:r,onFilterSubmit:t,...n})=>{let{clear:i,onTypeaheadChange:s,onRangeChange:p,onSelectedColumnChange:f,selectedColumnName:l,rangeValue:u,typeaheadValue:m}=to(t);return(0,v.jsxs)(P.Toolbar,{...n,style:{alignItems:"center",height:"36px"},children:[(0,v.jsx)(P.ToolbarField,{label:"Select a column to filter",labelPlacement:"top",style:{width:180},children:(0,v.jsx)(P.Dropdown,{source:r,ListItem:ro,itemToString:c=>c.name,onSelectionChange:(c,x)=>f(x)})}),l&&(()=>{var d;let c=[o,l];switch((d=r.find(C=>C.name===l))==null?void 0:d.serverDataType){case"string":case"char":return(0,v.jsx)(P.ToolbarField,{label:"Start typing to select a filter",labelPlacement:"top",children:(0,v.jsx)(Je,{defaultTypeaheadParams:c,filterValues:m,onChange:s})});case"int":case"long":case"double":return(0,v.jsx)(P.ToolbarField,{label:"Select a range",labelPlacement:"top",children:(0,v.jsx)(Ye,{defaultTypeaheadParams:c,filterValues:u,onChange:p})});default:return(0,v.jsx)(P.ToolbarField,{children:(0,v.jsx)(no.Text,{children:"Data type unsupported"})})}})(),(0,v.jsx)(P.ToolbarButton,{onClick:i,children:(0,v.jsx)(Fe,{})})]})};var Ne=require("@salt-ds/core");var I=require("@vuu-ui/vuu-codemirror"),xo=Ve(Te(),1),A=require("react");var T=require("@vuu-ui/vuu-codemirror");var io=require("@vuu-ui/vuu-codemirror"),ae=io.LRParser.deserialize({version:14,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",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",goto:"#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",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",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,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",tokenizers:[0,1],topRules:{Filter:[0,1]},tokenPrec:0});var cr=T.LRLanguage.define({name:"VuuFilterQuery",parser:ae.configure({props:[(0,T.styleTags)({Identifier:T.tags.variableName,String:T.tags.string,Or:T.tags.emphasis,Operator:T.tags.operator})]})}),so=()=>new T.LanguageSupport(cr);var E=require("@vuu-ui/vuu-utils");var O,Re=class{constructor(){Ae(this,O,void 0)}setFilterCombinatorOp(o,r=R(this,O)){(0,E.isMultiClauseFilter)(r)&&r.op===o||Ie(this,O,{op:o,filters:[R(this,O)]})}add(o){if(R(this,O)===void 0)Ie(this,O,o);else if((0,E.isMultiClauseFilter)(R(this,O)))R(this,O).filters.push(o);else throw Error("Invalid filter passed to FilterExpression")}setColumn(o,r=R(this,O)){if((0,E.isMultiClauseFilter)(r)){let t=r.filters.at(-1);t&&this.setColumn(o,t)}else r&&(r.column=o)}setOp(o,r=R(this,O)){if((0,E.isMultiClauseFilter)(r)){let t=r.filters.at(-1);t&&this.setOp(o,t)}else r&&(r.op=o)}setValue(o,r=R(this,O)){var t;if((0,E.isMultiClauseFilter)(r)){let n=r.filters.at(-1);n&&this.setValue(o,n)}else(0,E.isMultiValueFilter)(r)?((t=r.values)!=null||(r.values=[]),r.values.push(o)):(0,E.isSingleValueFilter)(r)&&(r.value=o)}toJSON(o=R(this,O)){return this.name?{...o,name:this.name}:o}};O=new WeakMap;var ce=(e,o)=>{let r=new Re,t=e.cursor();do{let{name:n,from:i,to:s}=t;switch(n){case"ColumnValueExpression":r.add({});break;case"ColumnSetExpression":r.add({op:"in"});break;case"Or":case"And":r.setFilterCombinatorOp(o.substring(i,s));break;case"Column":r.setColumn(o.substring(i,s));break;case"Operator":r.setOp(o.substring(i,s));break;case"String":r.setValue(o.substring(i+1,s-1));break;case"Number":r.setValue(parseFloat(o.substring(i,s)));break;case"True":r.setValue(!0);break;case"False":r.setValue(!1);break;case"FilterName":r.name=o.substring(i,s);break;default:}}while(t.next());return r.toJSON()};var pr=ae.configure({strict:!0}),Y=e=>{let o=pr.parse(e);return ce(o,e)};var L=require("@vuu-ui/vuu-codemirror"),ur=L.HighlightStyle.define([{tag:L.tags.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:L.tags.comment,color:"green",fontStyle:"italic"}]),lo=(0,L.syntaxHighlighting)(ur);var ao=require("@vuu-ui/vuu-codemirror"),co=ao.EditorView.theme({"&":{color:"var(--vuuFilterEditor-color)",backgroundColor:"var(--vuuFilterEditor-background)",fontSize:"var(--vuuFilterEditor-fontSize)"},".cm-content":{caretColor:"var(--vuuFilterEditor-cursorColor)",padding:0},".cm-line":{lineHeight:"var(--vuuFilterEditor-lineHeight)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-scroller":{fontFamily:"var(--vuuFilterEditor-fontFamily)"},".cm-tooltip":{background:"var(--vuuFilterEditor-tooltipBackground)",border:"var(--vuuFilterEditor-tooltipBorder)",boxShadow:"var(--vuuFilterEditor-tooltipElevation)","&.cm-tooltip-autocomplete > ul":{fontFamily:"var(--vuuFilterEditor-fontFamily)",fontSize:"var(--vuuFilterEditor-fontSize)",maxHeight:"240px"},"&.cm-tooltip-autocomplete > ul > li":{alignItems:"center",display:"flex",height:"var(--vuuFilterEditor-suggestion-height)",padding:"0 3px",lineHeight:"var(--vuuFilterEditor-suggestion-height)"},"&.cm-tooltip-autocomplete li[aria-selected]":{background:"var(--vuuFilterEditor-suggestion-selectedBackground)",color:"var(--vuuFilterEditor-suggestion-selectedColor)"}},".cm-completionIcon":{height:"18px",flex:"0 0 16px"},".cm-completionLabel":{flex:"1 1 auto"},".cm-completionIcon-filter":{position:"relative","&:after":{background:"var(--salt-text-secondary-foreground)",content:"''","-webkit-mask":"var(--svg-filter) center center/13px 13px","-webkit-mask-repeat":"no-repeat",position:"absolute",height:"18px",left:"0px",top:"0px",width:"16px"}}},{dark:!1});var S=require("@vuu-ui/vuu-codemirror"),we=require("react"),po=(e,o)=>{let r=e.prevSibling||e.parent;for(;r&&!["Column","Operator","In"].includes(r.name);)r=r.prevSibling||r.parent;if((r==null?void 0:r.name)==="In"||(r==null?void 0:r.name)==="Operator")return(0,S.getValue)(r,o)},mr=(e,o,r)=>{let t=(0,S.getValue)(e,o);if(!(r===void 0||t===r)&&["contains","ends","starts"].some(n=>n.startsWith(t.toLowerCase())))return t},uo=(e,o)=>{let r=e.prevSibling||e.parent||e.lastChild;for(;r&&r.name==="\u26A0";)r=r.prevSibling;if(r&&["As","Or","And"].includes(r.name))return(0,S.getValue)(r,o)},mo=(e,o)=>{if(e.name==="FilterName")return(0,S.getValue)(e,o);{let r=e.prevSibling||e.parent||e.lastChild;for(;r&&r.name!=="FilterName";)r=r.prevSibling;if(r&&r.name==="FilterName")return(0,S.getValue)(e,o)}},fo=(e,o)=>{let r=e.prevSibling;if((r==null?void 0:r.name)==="Column")return(0,S.getValue)(r,o);if((r==null?void 0:r.name)==="Operator")return fo(r,o)},dr=(e,o)=>{let r=e.lastChild,t=[];for(;r&&r.name!=="In";){let n=(0,S.getValue)(r,o);if(n)t.push(n);else break;r=r.prevSibling}return t};var go=(e,o,r)=>{let t=(0,we.useCallback)(async(n,i,s={})=>{let{startsWith:p=""}=s,f=await e.getSuggestions(i,s);return{from:n.pos-p.length,options:f}},[e]);return(0,we.useCallback)(async n=>{var u,m;let{state:i,pos:s}=n,p=(u=n.matchBefore(/\w*/))!=null?u:{from:0,to:0,text:void 0},l=(0,S.syntaxTree)(i).resolveInner(s,-1);switch(console.log({nodeBeforeName:l.name}),l.name){case"Filter":if(n.pos===0)return t(n,"column");if(uo(l,i)==="as")return t(n,"name");{let c=mo(l,i);return t(n,"save",{onSubmit:o.current,existingFilter:r,filterName:c})}case"String":{let a=po(l,i),c=fo(l,i),{from:x,to:d}=l;if(d-x===2&&n.pos===x+1){if(c&&a)return t(n,"columnValue",{columnName:c,operator:a,quoted:!0,startsWith:p.text})}else console.log(`we have a string, column is ${c} ${x} ${d}`)}break;case"As":return t(n,"name");case"FilterName":return t(n,"save",{onSubmit:o.current,existingFilter:r,filterName:mo(l,i)});case"Column":{let a=(0,S.getValue)(l,i);return await e.isPartialMatch("column",void 0,a)?t(n,"column",{startsWith:a}):t(n,"operator",{columnName:a})}case"\u26A0":{let a=(0,S.getNodeByName)(l,i),c=po(l,i),x=c?void 0:mr(l,i,a);return x?t(n,"operator",{columnName:a,startsWith:x}):t(n,"columnValue",{columnName:a,operator:c,startsWith:p.text})}case"Identifier":if(uo(l,i)==="as")return{from:n.pos,options:[{label:"press ENTER to apply filter and save",apply:()=>o.current(),boost:5}]};break;case"ColumnSetExpression":case"Values":{let a=(0,S.getNodeByName)(l,i),c=dr(l,i);return t(n,"columnValue",{columnName:a,selection:c})}case"Comma":case"LBrack":{let a=(0,S.getNodeByName)(l,i);return t(n,"columnValue",{columnName:a})}case"ColumnValueExpression":{let a=(m=l.lastChild)==null?void 0:m.prevSibling;if((a==null?void 0:a.name)==="Column")return t(n,"operator",{columnName:(0,S.getNodeByName)(l,i)});if((a==null?void 0:a.name)==="Operator")return t(n,"columnValue",{columnName:(0,S.getNodeByName)(a,i),operator:(0,S.getValue)(a,i)})}break;case"In":return{from:n.pos,options:[{label:"[",apply:" [",type:"text"}]};case"Eq":return t(n,"columnValue",{columnName:(0,S.getNodeByName)(l,i)});case"AndExpression":case"OrExpression":return t(n,"column");default:}},[r,t,o,e])};var q=e=>{if(e.current==null)throw Error("EditorView not defined");return e.current},fr=e=>(0,xo.default)("vuuSuggestion",{vuuIllustration:e.isIllustration}),gr=e=>{let o=e.lastIndexOf(" as ");return o!==-1?e.slice(0,o):e},xr=()=>console.log("noooop"),Ee=({existingFilter:e,onSubmitFilter:o,suggestionProvider:r})=>{let t=(0,A.useRef)(null),n=(0,A.useRef)(xr),i=(0,A.useRef)(),s=go(r,n,e),[p,f]=(0,A.useMemo)(()=>{let l=()=>{let d=q(i),C=d.state.doc.toString(),y=(0,I.ensureSyntaxTree)(d.state,d.state.doc.length,5e3);if(y){let g=ce(y,C);return[g,gr(C),g.name]}else return[void 0,"",void 0]},u=()=>{q(i).setState(x())},m=d=>{let[C,y,g]=l();o==null||o(C,y,d,g),u()},a=d=>I.keymap.of([{key:d,run(){return m(),!0}}]),c=d=>I.keymap.of([{key:d,run(){return(0,I.startCompletion)(q(i)),!0}}]),x=()=>I.EditorState.create({doc:"",extensions:[I.minimalSetup,(0,I.autocompletion)({override:[s],optionClass:fr}),so(),I.keymap.of(I.defaultKeymap),a("Ctrl-Enter"),c("ArrowDown"),I.EditorView.updateListener.of(d=>{let C=q(i);d.docChanged&&(0,I.startCompletion)(C)}),I.EditorState.transactionFilter.of(d=>d.newDoc.lines>1?[]:d),co,lo]});return n.current=d=>{m(d),setTimeout(()=>{q(i).focus()},100)},[x,u]},[s,o]);return(0,A.useEffect)(()=>{if(!t.current)throw Error("editor not in dom");return i.current=new I.EditorView({state:p(),parent:t.current}),()=>{var l;(l=i.current)==null||l.destroy()}},[s,p]),{editorRef:t,clearInput:f}};var $=require("react/jsx-runtime"),pe="vuuFilterInput",Ir=({existingFilter:e,iconName:o="filter",namedFilters:r,onSubmitFilter:t,suggestionProvider:n,...i})=>{let{editorRef:s,clearInput:p}=Ee({existingFilter:e,onSubmitFilter:t,suggestionProvider:n});return(0,$.jsxs)("div",{...i,className:pe,children:[(0,$.jsx)(Ne.Button,{className:`${pe}-FilterButton`,"data-icon":o,tabIndex:-1}),(0,$.jsx)("div",{className:`${pe}-Editor`,ref:s}),(0,$.jsx)(Ne.Button,{className:`${pe}-ClearButton`,"data-icon":"close-circle",onClick:p})]})};var b=require("@vuu-ui/vuu-codemirror"),me=require("@vuu-ui/vuu-data"),J=require("react");var K=require("@vuu-ui/vuu-utils"),Io=(e,o)=>{let r=(0,K.createEl)("div","vuuFunctionDoc"),t=(0,K.createEl)("div","function-heading"),n=(0,K.createEl)("span","function-name",e);t.appendChild(n);let i=(0,K.createEl)("p",void 0,o);return r.appendChild(t),r.appendChild(i),r};var Sr=[],Fr={},hr=e=>[{label:"Press ENTER to create TAB",apply:()=>e("tab"),boost:6}],So=(e,o,r=!0)=>{let t=o?[{label:"REPLACE existing filter",apply:()=>e("replace"),boost:8},{label:"AND existing filter",apply:()=>e("and"),boost:7},{label:"OR existing filter",apply:()=>e("or"),boost:7}]:[{label:"Press ENTER to submit",apply:()=>e(),boost:6}];return r?t.concat(b.booleanJoinSuggestions).concat(b.asNameSuggestion):t},Cr=(e,o)=>So(e,o,!0),Or=e=>So(e,void 0),vr=({existingFilter:e,filterName:o,onSubmit:r,saveOptions:t})=>{let n=o&&t.allowSaveAsTab,i=e?Cr(r,e):Or(r);return n?i.concat(hr(r)):i},br=e=>e.map(o=>({boost:5,label:o.name})),yr=e=>e?Array.from(e.entries()).map(([o,r])=>({info:()=>Io(o,r),label:o,type:"filter"})):Sr,Pr={label:"Done",apply:"] ",type:"keyword",boost:10},ue=(e,o="")=>e.filter(r=>o===""||r.label.startsWith(o)).map(r=>({...r,apply:r.label+" "})),Tr={allowReplace:!0},Rr=({columns:e,namedFilters:o,saveOptions:r=Tr,table:t,typeaheadHook:n=me.useTypeaheadSuggestions})=>{let i=(0,J.useRef)(),s=n(),p=(0,J.useCallback)(async(l,u=Fr)=>{let{columnName:m,existingFilter:a,filterName:c,operator:x,quoted:d,onSubmit:C,startsWith:y,selection:g}=u;switch(l){case"operator":{let F=e.find(N=>N.name===m);if(F)switch(F.serverDataType){case"string":case"char":return ue(b.stringOperators,y);case"int":case"long":case"double":return ue(b.numericOperators)}else console.warn(`'${m}' does not match any column name`)}break;case"column":{let F=await br(e),N=await yr(o);return(i.current=ue(F)).concat(ue(N))}case"columnValue":if(m){let F=e.find(Vo=>Vo.name===m);if(!F)throw Error(`useFilterSUggestionProvider no column ${m}`);let N=Array.isArray(g)?g.length===0?"[":",":"",xe=(0,me.getTypeaheadParams)(t,m,y),U=await s(xe),X=x==="starts";return i.current=(0,b.toSuggestions)(U,{moveCursorToEnd:d,quoted:(F==null?void 0:F.serverDataType)==="string"&&!d,suffix:d?"":" ",prefix:X?y:N,isIllustration:X}),Array.isArray(g)&&(g==null?void 0:g.length)>1?[Pr,...i.current]:i.current}break;case"save":{if(typeof C!="function")throw Error("useFilterSuggestionProvider, onSubmit must be supplied for 'save' suggestions");return await vr({existingFilter:a,filterName:c,onSubmit:C,saveOptions:r})}case"name":return await(0,b.getNamePrompt)("filter");default:}return[]},[e,s,o,r,t]),f=(0,J.useCallback)(async(l,u,m)=>{let a=await p(l,{columnName:u});if(m&&a)for(let c of a){if(c.label===m)return!1;if(c.label.startsWith(m))return!0}return!1},[p]);return{getSuggestions:p,isPartialMatch:f}};var wo=require("@heswell/salt-lab"),Eo=Ve(Te(),1);var ee=require("@heswell/salt-lab");var Fo=require("@heswell/salt-lab"),de=require("react"),Oo=require("react/jsx-runtime"),wr=e=>typeof e=="string",ho=e=>wr(e)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:e.map(ho),Co=({column:e,selected:o,suggestionProvider:r,...t})=>{let n=o!=null?ho(o):void 0,i=Array.isArray(n)?n:n!=null?[n]:[],[s,p]=(0,de.useState)(i);console.log({initialValues:i});let f=(0,de.useCallback)(async l=>{if(l){let u=await r.getSuggestions("columnValue",{columnName:e});console.log({values:u}),p(u.map(m=>m.label))}},[e,r]);return(0,Oo.jsx)(Fo.Dropdown,{...t,onOpenChange:f,selected:n,source:s})};var vo=require("@heswell/salt-lab"),fe=require("react"),Po=require("react/jsx-runtime"),Er=e=>typeof e=="string",bo=e=>{if(e!==void 0)return Er(e)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:e.map(bo)},yo=({column:e,selected:o,suggestionProvider:r,...t})=>{let n=bo(o),i=Array.isArray(n)?n:n!=null?[n]:[],[s,p]=(0,fe.useState)(i),f=(0,fe.useCallback)(async l=>{if(l){let u=await r.getSuggestions("columnValue",{columnName:e});console.log({values:u}),p(u.map(m=>m.label))}},[e,r]);return(0,Po.jsx)(vo.Dropdown,{...t,onOpenChange:f,selected:n,selectionStrategy:"multiple",source:s})};var z=require("react/jsx-runtime"),To=(e,o)=>{if(he(e))return(0,z.jsx)(ee.ToggleButton,{className:"vuuToggleButton",toggled:!0,variant:"secondary",children:e.name});if(k(e)){let{column:r,value:t}=e;return(0,z.jsx)(ee.ToolbarField,{className:"vuuFilterDropdown",label:r,labelPlacement:"top",children:(0,z.jsx)(Co,{column:r,selected:t.toString(),selectionStrategy:"default",source:[t.toString()],suggestionProvider:o,style:{width:100}})},r)}if(D(e)){let r=e.values.map(t=>t.toString());return(0,z.jsx)(ee.ToolbarField,{className:"vuuFilterDropdown",label:e.column,labelPlacement:"top",children:(0,z.jsx)(yo,{column:e.column,selected:r,source:r,suggestionProvider:o,style:{width:100}})},e.column)}return e.filters.map(r=>To(r,o))},Ro=({filter:e,suggestionProvider:o})=>e?To(e,o):[];var No=require("react/jsx-runtime"),Nr=({className:e,filter:o,suggestionProvider:r,...t})=>{console.log(`FilterToolbar ${JSON.stringify(o,null,2)}`);let n=Ro({filter:o,suggestionProvider:r});return(0,No.jsx)(wo.Toolbar,{className:(0,Eo.default)("vuuFilterToolbar",e),...t,children:n})};var Do=new Map,Dr=()=>!1,Vr=(e,o)=>{let r=Do.get(o);if(r)return r;try{let t=Y(o);return r=ge(e,t),Do.set(o,r),r}catch{return console.warn(`filter-evaluation-utils, failed to parse filter "${o}"`),Dr}};function ge(e,o){switch(o.op){case"in":return Qr(e,o);case"=":return Ar(e,o);case">":return kr(e,o);case">=":return Mr(e,o);case"<":return Lr(e,o);case"<=":return Ur(e,o);case"starts":return Wr(e,o);case"and":return Hr(e,o);case"or":return Br(e,o);default:return console.log(`unrecognized filter type ${o.op}`),()=>!0}}var Qr=(e,o)=>r=>o.values.indexOf(r[e[o.column]])!==-1,Ar=(e,o)=>r=>r[e[o.column]]===o.value,kr=(e,o)=>r=>r[e[o.column]]>o.value,Mr=(e,o)=>r=>r[e[o.column]]>=o.value,Lr=(e,o)=>r=>r[e[o.column]]<o.value,Ur=(e,o)=>r=>r[e[o.column]]<=o.value,Wr=(e,o)=>{let r=o.value;if(typeof r!="string")throw Error("string filter applied to value of wrong type");return t=>{let n=t[e[o.column]];if(typeof n!="string")throw Error("string filter applied to value of wrong type");return n.toLowerCase().startsWith(r.toLowerCase())}},Hr=(e,o)=>{let r=o.filters.map(t=>ge(e,t));return t=>r.every(n=>n(t))};function Br(e,o){let r=o.filters.map(t=>ge(e,t));return t=>r.some(n=>n(t))}
3251
+ var Dialect = class {
3252
+ constructor(source, flags, disabled) {
3253
+ this.source = source;
3254
+ this.flags = flags;
3255
+ this.disabled = disabled;
3256
+ }
3257
+ allows(term) {
3258
+ return !this.disabled || this.disabled[term] == 0;
3259
+ }
3260
+ };
3261
+ var LRParser = class extends Parser {
3262
+ /// @internal
3263
+ constructor(spec) {
3264
+ super();
3265
+ this.wrappers = [];
3266
+ if (spec.version != 14)
3267
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
3268
+ let nodeNames = spec.nodeNames.split(" ");
3269
+ this.minRepeatTerm = nodeNames.length;
3270
+ for (let i = 0; i < spec.repeatNodeCount; i++)
3271
+ nodeNames.push("");
3272
+ let topTerms = Object.keys(spec.topRules).map((r2) => spec.topRules[r2][1]);
3273
+ let nodeProps = [];
3274
+ for (let i = 0; i < nodeNames.length; i++)
3275
+ nodeProps.push([]);
3276
+ function setProp(nodeID, prop, value) {
3277
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
3278
+ }
3279
+ if (spec.nodeProps)
3280
+ for (let propSpec of spec.nodeProps) {
3281
+ let prop = propSpec[0];
3282
+ if (typeof prop == "string")
3283
+ prop = NodeProp[prop];
3284
+ for (let i = 1; i < propSpec.length; ) {
3285
+ let next = propSpec[i++];
3286
+ if (next >= 0) {
3287
+ setProp(next, prop, propSpec[i++]);
3288
+ } else {
3289
+ let value = propSpec[i + -next];
3290
+ for (let j = -next; j > 0; j--)
3291
+ setProp(propSpec[i++], prop, value);
3292
+ i++;
3293
+ }
3294
+ }
3295
+ }
3296
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
3297
+ name: i >= this.minRepeatTerm ? void 0 : name,
3298
+ id: i,
3299
+ props: nodeProps[i],
3300
+ top: topTerms.indexOf(i) > -1,
3301
+ error: i == 0,
3302
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
3303
+ })));
3304
+ if (spec.propSources)
3305
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
3306
+ this.strict = false;
3307
+ this.bufferLength = DefaultBufferLength;
3308
+ let tokenArray = decodeArray(spec.tokenData);
3309
+ this.context = spec.context;
3310
+ this.specializerSpecs = spec.specialized || [];
3311
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
3312
+ for (let i = 0; i < this.specializerSpecs.length; i++)
3313
+ this.specialized[i] = this.specializerSpecs[i].term;
3314
+ this.specializers = this.specializerSpecs.map(getSpecializer);
3315
+ this.states = decodeArray(spec.states, Uint32Array);
3316
+ this.data = decodeArray(spec.stateData);
3317
+ this.goto = decodeArray(spec.goto);
3318
+ this.maxTerm = spec.maxTerm;
3319
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
3320
+ this.topRules = spec.topRules;
3321
+ this.dialects = spec.dialects || {};
3322
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
3323
+ this.tokenPrecTable = spec.tokenPrec;
3324
+ this.termNames = spec.termNames || null;
3325
+ this.maxNode = this.nodeSet.types.length - 1;
3326
+ this.dialect = this.parseDialect();
3327
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
3328
+ }
3329
+ createParse(input, fragments, ranges) {
3330
+ let parse = new Parse(this, input, fragments, ranges);
3331
+ for (let w of this.wrappers)
3332
+ parse = w(parse, input, fragments, ranges);
3333
+ return parse;
3334
+ }
3335
+ /// Get a goto table entry @internal
3336
+ getGoto(state, term, loose = false) {
3337
+ let table = this.goto;
3338
+ if (term >= table[0])
3339
+ return -1;
3340
+ for (let pos = table[term + 1]; ; ) {
3341
+ let groupTag = table[pos++], last = groupTag & 1;
3342
+ let target = table[pos++];
3343
+ if (last && loose)
3344
+ return target;
3345
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
3346
+ if (table[pos] == state)
3347
+ return target;
3348
+ if (last)
3349
+ return -1;
3350
+ }
3351
+ }
3352
+ /// Check if this state has an action for a given terminal @internal
3353
+ hasAction(state, terminal) {
3354
+ let data = this.data;
3355
+ for (let set = 0; set < 2; set++) {
3356
+ for (let i = this.stateSlot(
3357
+ state,
3358
+ set ? 2 : 1
3359
+ /* ParseState.Actions */
3360
+ ), next; ; i += 3) {
3361
+ if ((next = data[i]) == 65535) {
3362
+ if (data[i + 1] == 1)
3363
+ next = data[i = pair(data, i + 2)];
3364
+ else if (data[i + 1] == 2)
3365
+ return pair(data, i + 2);
3366
+ else
3367
+ break;
3368
+ }
3369
+ if (next == terminal || next == 0)
3370
+ return pair(data, i + 1);
3371
+ }
3372
+ }
3373
+ return 0;
3374
+ }
3375
+ /// @internal
3376
+ stateSlot(state, slot) {
3377
+ return this.states[state * 6 + slot];
3378
+ }
3379
+ /// @internal
3380
+ stateFlag(state, flag) {
3381
+ return (this.stateSlot(
3382
+ state,
3383
+ 0
3384
+ /* ParseState.Flags */
3385
+ ) & flag) > 0;
3386
+ }
3387
+ /// @internal
3388
+ validAction(state, action) {
3389
+ if (action == this.stateSlot(
3390
+ state,
3391
+ 4
3392
+ /* ParseState.DefaultReduce */
3393
+ ))
3394
+ return true;
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
+ return false;
3405
+ }
3406
+ if (action == pair(this.data, i + 1))
3407
+ return true;
3408
+ }
3409
+ }
3410
+ /// Get the states that can follow this one through shift actions or
3411
+ /// goto jumps. @internal
3412
+ nextStates(state) {
3413
+ let result = [];
3414
+ for (let i = this.stateSlot(
3415
+ state,
3416
+ 1
3417
+ /* ParseState.Actions */
3418
+ ); ; i += 3) {
3419
+ if (this.data[i] == 65535) {
3420
+ if (this.data[i + 1] == 1)
3421
+ i = pair(this.data, i + 2);
3422
+ else
3423
+ break;
3424
+ }
3425
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
3426
+ let value = this.data[i + 1];
3427
+ if (!result.some((v, i2) => i2 & 1 && v == value))
3428
+ result.push(this.data[i], value);
3429
+ }
3430
+ }
3431
+ return result;
3432
+ }
3433
+ /// Configure the parser. Returns a new parser instance that has the
3434
+ /// given settings modified. Settings not provided in `config` are
3435
+ /// kept from the original parser.
3436
+ configure(config) {
3437
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
3438
+ if (config.props)
3439
+ copy.nodeSet = this.nodeSet.extend(...config.props);
3440
+ if (config.top) {
3441
+ let info = this.topRules[config.top];
3442
+ if (!info)
3443
+ throw new RangeError(`Invalid top rule name ${config.top}`);
3444
+ copy.top = info;
3445
+ }
3446
+ if (config.tokenizers)
3447
+ copy.tokenizers = this.tokenizers.map((t) => {
3448
+ let found = config.tokenizers.find((r2) => r2.from == t);
3449
+ return found ? found.to : t;
3450
+ });
3451
+ if (config.specializers) {
3452
+ copy.specializers = this.specializers.slice();
3453
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
3454
+ let found = config.specializers.find((r2) => r2.from == s.external);
3455
+ if (!found)
3456
+ return s;
3457
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
3458
+ copy.specializers[i] = getSpecializer(spec);
3459
+ return spec;
3460
+ });
3461
+ }
3462
+ if (config.contextTracker)
3463
+ copy.context = config.contextTracker;
3464
+ if (config.dialect)
3465
+ copy.dialect = this.parseDialect(config.dialect);
3466
+ if (config.strict != null)
3467
+ copy.strict = config.strict;
3468
+ if (config.wrap)
3469
+ copy.wrappers = copy.wrappers.concat(config.wrap);
3470
+ if (config.bufferLength != null)
3471
+ copy.bufferLength = config.bufferLength;
3472
+ return copy;
3473
+ }
3474
+ /// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
3475
+ /// are registered for this parser.
3476
+ hasWrappers() {
3477
+ return this.wrappers.length > 0;
3478
+ }
3479
+ /// Returns the name associated with a given term. This will only
3480
+ /// work for all terms when the parser was generated with the
3481
+ /// `--names` option. By default, only the names of tagged terms are
3482
+ /// stored.
3483
+ getName(term) {
3484
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
3485
+ }
3486
+ /// The eof term id is always allocated directly after the node
3487
+ /// types. @internal
3488
+ get eofTerm() {
3489
+ return this.maxNode + 1;
3490
+ }
3491
+ /// The type of top node produced by the parser.
3492
+ get topNode() {
3493
+ return this.nodeSet.types[this.top[1]];
3494
+ }
3495
+ /// @internal
3496
+ dynamicPrecedence(term) {
3497
+ let prec = this.dynamicPrecedences;
3498
+ return prec == null ? 0 : prec[term] || 0;
3499
+ }
3500
+ /// @internal
3501
+ parseDialect(dialect) {
3502
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
3503
+ if (dialect)
3504
+ for (let part of dialect.split(" ")) {
3505
+ let id = values.indexOf(part);
3506
+ if (id >= 0)
3507
+ flags[id] = true;
3508
+ }
3509
+ let disabled = null;
3510
+ for (let i = 0; i < values.length; i++)
3511
+ if (!flags[i]) {
3512
+ for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
3513
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
3514
+ }
3515
+ return new Dialect(dialect, flags, disabled);
3516
+ }
3517
+ /// Used by the output of the parser generator. Not available to
3518
+ /// user code. @hide
3519
+ static deserialize(spec) {
3520
+ return new LRParser(spec);
3521
+ }
3522
+ };
3523
+ function pair(data, off) {
3524
+ return data[off] | data[off + 1] << 16;
3525
+ }
3526
+ function findFinished(stacks) {
3527
+ let best = null;
3528
+ for (let stack of stacks) {
3529
+ let stopped = stack.p.stoppedAt;
3530
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
3531
+ stack.state,
3532
+ 2
3533
+ /* StateFlag.Accepting */
3534
+ ) && (!best || best.score < stack.score))
3535
+ best = stack;
3536
+ }
3537
+ return best;
3538
+ }
3539
+ function getSpecializer(spec) {
3540
+ if (spec.external) {
3541
+ let mask = spec.extend ? 1 : 0;
3542
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
3543
+ }
3544
+ return spec.get;
3545
+ }
3546
+
3547
+ // ../vuu-filter-parser/src/generated/filter-parser.js
3548
+ var parser = LRParser.deserialize({
3549
+ version: 14,
3550
+ 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",
3551
+ 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",
3552
+ goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
3553
+ 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",
3554
+ maxTerm: 39,
3555
+ skippedNodes: [0],
3556
+ repeatNodeCount: 1,
3557
+ 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",
3558
+ tokenizers: [0, 1],
3559
+ topRules: { "Filter": [0, 1] },
3560
+ tokenPrec: 0
3561
+ });
3562
+
3563
+ // ../vuu-filter-parser/src/FilterTreeWalker.ts
3564
+ var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
3565
+ var _filter;
3566
+ var FilterExpression = class {
3567
+ constructor() {
3568
+ __privateAdd(this, _filter, void 0);
3569
+ }
3570
+ setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
3571
+ if ((0, import_vuu_utils3.isMultiClauseFilter)(filter) && filter.op === op) {
3572
+ return;
3573
+ } else {
3574
+ __privateSet(this, _filter, {
3575
+ op,
3576
+ filters: [__privateGet(this, _filter)]
3577
+ });
3578
+ }
3579
+ }
3580
+ add(filter) {
3581
+ if (__privateGet(this, _filter) === void 0) {
3582
+ __privateSet(this, _filter, filter);
3583
+ } else if ((0, import_vuu_utils3.isMultiClauseFilter)(__privateGet(this, _filter))) {
3584
+ __privateGet(this, _filter).filters.push(filter);
3585
+ } else {
3586
+ throw Error(`Invalid filter passed to FilterExpression`);
3587
+ }
3588
+ }
3589
+ setColumn(column, filter = __privateGet(this, _filter)) {
3590
+ if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
3591
+ const target = filter.filters.at(-1);
3592
+ if (target) {
3593
+ this.setColumn(column, target);
3594
+ }
3595
+ } else if (filter) {
3596
+ filter.column = column;
3597
+ }
3598
+ }
3599
+ setOp(value, filter = __privateGet(this, _filter)) {
3600
+ if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
3601
+ const target = filter.filters.at(-1);
3602
+ if (target) {
3603
+ this.setOp(value, target);
3604
+ }
3605
+ } else if (filter) {
3606
+ filter.op = value;
3607
+ }
3608
+ }
3609
+ setValue(value, filter = __privateGet(this, _filter)) {
3610
+ var _a;
3611
+ if ((0, import_vuu_utils3.isMultiClauseFilter)(filter)) {
3612
+ const target = filter.filters.at(-1);
3613
+ if (target) {
3614
+ this.setValue(value, target);
3615
+ }
3616
+ } else if ((0, import_vuu_utils3.isMultiValueFilter)(filter)) {
3617
+ (_a = filter.values) != null ? _a : filter.values = [];
3618
+ filter.values.push(value);
3619
+ } else if ((0, import_vuu_utils3.isSingleValueFilter)(filter)) {
3620
+ filter.value = value;
3621
+ }
3622
+ }
3623
+ toJSON(filter = __privateGet(this, _filter)) {
3624
+ if (this.name) {
3625
+ return {
3626
+ ...filter,
3627
+ name: this.name
3628
+ };
3629
+ } else {
3630
+ return filter;
3631
+ }
3632
+ }
3633
+ };
3634
+ _filter = new WeakMap();
3635
+ var walkTree = (tree, source) => {
3636
+ const filterExpression = new FilterExpression();
3637
+ const cursor = tree.cursor();
3638
+ do {
3639
+ const { name, from, to } = cursor;
3640
+ switch (name) {
3641
+ case "ColumnValueExpression":
3642
+ filterExpression.add({});
3643
+ break;
3644
+ case "ColumnSetExpression":
3645
+ filterExpression.add({ op: "in" });
3646
+ break;
3647
+ case "Or":
3648
+ case "And":
3649
+ filterExpression.setFilterCombinatorOp(source.substring(from, to));
3650
+ break;
3651
+ case "Column":
3652
+ filterExpression.setColumn(source.substring(from, to));
3653
+ break;
3654
+ case "Operator":
3655
+ filterExpression.setOp(source.substring(from, to));
3656
+ break;
3657
+ case "String":
3658
+ filterExpression.setValue(source.substring(from + 1, to - 1));
3659
+ break;
3660
+ case "Number":
3661
+ filterExpression.setValue(parseFloat(source.substring(from, to)));
3662
+ break;
3663
+ case "True":
3664
+ filterExpression.setValue(true);
3665
+ break;
3666
+ case "False":
3667
+ filterExpression.setValue(false);
3668
+ break;
3669
+ case "FilterName":
3670
+ filterExpression.name = source.substring(from, to);
3671
+ break;
3672
+ default:
3673
+ }
3674
+ } while (cursor.next());
3675
+ return filterExpression.toJSON();
3676
+ };
3677
+
3678
+ // ../vuu-filter-parser/src/FilterParser.ts
3679
+ var strictParser = parser.configure({ strict: true });
3680
+
3681
+ // ../vuu-data-react/src/hooks/useVuuMenuActions.ts
3682
+ var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
3683
+ var import_react7 = require("react");
3684
+ var { KEY } = import_vuu_utils4.metadataKeys;
3685
+
3686
+ // ../vuu-data-react/src/hooks/useVuuTables.ts
3687
+ var import_react8 = require("react");
3688
+ var import_vuu_data4 = require("@vuu-ui/vuu-data");
3689
+
3690
+ // src/column-filter/TypeaheadFilter.tsx
3691
+ var import_salt_lab2 = require("@heswell/salt-lab");
3692
+ var import_react9 = require("react");
3693
+ var import_jsx_runtime4 = require("react/jsx-runtime");
3694
+ var TypeaheadFilter = ({
3695
+ defaultTypeaheadParams,
3696
+ filterValues = [],
3697
+ onChange: onFilterChange
3698
+ }) => {
3699
+ const [tableName, columnName] = defaultTypeaheadParams;
3700
+ const [searchValue, setSearchValue] = (0, import_react9.useState)("");
3701
+ const [typeaheadValues, setTypeaheadValues] = (0, import_react9.useState)([]);
3702
+ const getSuggestions = useTypeaheadSuggestions();
3703
+ (0, import_react9.useEffect)(() => {
3704
+ const params = searchValue ? [tableName, columnName, searchValue] : defaultTypeaheadParams;
3705
+ let isSubscribed = true;
3706
+ getSuggestions(params).then((options) => {
3707
+ if (!isSubscribed) {
3708
+ return;
3709
+ }
3710
+ if (isStartsWithValue(filterValues[0])) {
3711
+ options.unshift(filterValues[0]);
3712
+ }
3713
+ if (searchValue) {
3714
+ options.unshift(`${searchValue}...`);
3715
+ }
3716
+ options.concat(filterValues);
3717
+ setTypeaheadValues(options);
3718
+ });
3719
+ return () => {
3720
+ isSubscribed = false;
3721
+ };
3722
+ }, [
3723
+ filterValues,
3724
+ searchValue,
3725
+ columnName,
3726
+ tableName,
3727
+ getSuggestions,
3728
+ defaultTypeaheadParams
3729
+ ]);
3730
+ const onInputChange = (0, import_react9.useCallback)(
3731
+ (evt) => {
3732
+ const value = evt.target.value;
3733
+ setSearchValue(value);
3734
+ },
3735
+ []
3736
+ );
3737
+ const onSelectionChange = (0, import_react9.useCallback)(
3738
+ (_evt, selected) => {
3739
+ setSearchValue("");
3740
+ if (selected === null)
3741
+ return;
3742
+ if (selected.some(isStartsWithValue)) {
3743
+ selected = selected.filter(isStartsWithValue).slice(-1);
3744
+ }
3745
+ const filter = getTypeaheadFilter(
3746
+ columnName,
3747
+ selected,
3748
+ isStartsWithValue(selected[0])
3749
+ );
3750
+ onFilterChange(selected, filter);
3751
+ },
3752
+ [columnName, onFilterChange]
3753
+ );
3754
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3755
+ import_salt_lab2.ComboBoxDeprecated,
3756
+ {
3757
+ multiSelect: true,
3758
+ onInputChange,
3759
+ onChange: onSelectionChange,
3760
+ source: typeaheadValues,
3761
+ style: { minWidth: 200 },
3762
+ inputValue: searchValue,
3763
+ selectedItem: filterValues
3764
+ },
3765
+ columnName
3766
+ );
3767
+ };
3768
+
3769
+ // src/column-filter/ColumnListItem.tsx
3770
+ var import_react10 = require("react");
3771
+ var import_salt_lab3 = require("@heswell/salt-lab");
3772
+ var import_jsx_runtime5 = require("react/jsx-runtime");
3773
+ var ColumnListItem = (props) => {
3774
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MemoColumnItem, { ...props });
3775
+ };
3776
+ var MemoColumnItem = (0, import_react10.memo)(function MemoizedItem({
3777
+ item,
3778
+ itemTextHighlightPattern,
3779
+ ...restProps
3780
+ }) {
3781
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_salt_lab3.ListItem, { ...restProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { marginLeft: 10 }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3782
+ import_salt_lab3.Highlighter,
3783
+ {
3784
+ matchPattern: itemTextHighlightPattern,
3785
+ text: item == null ? void 0 : item.name
3786
+ }
3787
+ ) }) });
3788
+ });
3789
+
3790
+ // src/column-filter/useColumnFilterStore.ts
3791
+ var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
3792
+ var import_react11 = require("react");
3793
+ var addOrReplace = (array, newValue, key) => array.filter((oldValue) => oldValue[key] !== newValue[key]).concat(newValue);
3794
+ var useColumnFilterStore = (onFilterSubmit) => {
3795
+ var _a, _b;
3796
+ const [selectedColumnName, setSelectedColumnName] = (0, import_react11.useState)("");
3797
+ const [savedFilters, setSavedFilters] = (0, import_react11.useState)([]);
3798
+ const [rangeValues, setRangeValues] = (0, import_react11.useState)([]);
3799
+ const [typeaheadValues, setTypeaheadValues] = (0, import_react11.useState)([]);
3800
+ const clear = () => {
3801
+ setSelectedColumnName("");
3802
+ setRangeValues([]);
3803
+ setTypeaheadValues([]);
3804
+ setSavedFilters([]);
3805
+ onFilterSubmit({ filter: "" });
3806
+ };
3807
+ const updateFilters = (0, import_react11.useCallback)(
3808
+ (newFilter) => {
3809
+ const newSavedFilters = addOrReplace(
3810
+ savedFilters,
3811
+ { column: selectedColumnName, filter: newFilter },
3812
+ "column"
3813
+ );
3814
+ setSavedFilters(newSavedFilters);
3815
+ const combinedFilter = newSavedFilters.map((x) => x.filter).reduce((prev, filter) => {
3816
+ if (filter === void 0)
3817
+ return prev;
3818
+ return addFilter(prev, filter, { combineWith: AND });
3819
+ }, void 0);
3820
+ const query = combinedFilter === void 0 ? "" : (0, import_vuu_utils5.filterAsQuery)(combinedFilter);
3821
+ onFilterSubmit({ filter: query, filterStruct: combinedFilter });
3822
+ },
3823
+ [selectedColumnName, onFilterSubmit, savedFilters]
3824
+ );
3825
+ const onTypeaheadChange = (0, import_react11.useCallback)(
3826
+ (newValues, newFilter) => {
3827
+ setTypeaheadValues(
3828
+ addOrReplace(
3829
+ typeaheadValues,
3830
+ { column: selectedColumnName, value: newValues },
3831
+ "column"
3832
+ )
3833
+ );
3834
+ updateFilters(newFilter);
3835
+ },
3836
+ [selectedColumnName, typeaheadValues, updateFilters]
3837
+ );
3838
+ const onRangeChange = (0, import_react11.useCallback)(
3839
+ (newValues, newFilter) => {
3840
+ setRangeValues(
3841
+ addOrReplace(
3842
+ rangeValues,
3843
+ { column: selectedColumnName, value: newValues },
3844
+ "column"
3845
+ )
3846
+ );
3847
+ updateFilters(newFilter);
3848
+ },
3849
+ [selectedColumnName, rangeValues, updateFilters]
3850
+ );
3851
+ const onSelectedColumnChange = (0, import_react11.useCallback)(
3852
+ (column) => setSelectedColumnName((column == null ? void 0 : column.name) || ""),
3853
+ []
3854
+ );
3855
+ const rangeValue = (_a = rangeValues.filter(
3856
+ (v) => v.column === selectedColumnName
3857
+ )[0]) == null ? void 0 : _a.value;
3858
+ const typeaheadValue = (_b = typeaheadValues.filter(
3859
+ (v) => v.column === selectedColumnName
3860
+ )[0]) == null ? void 0 : _b.value;
3861
+ return {
3862
+ clear,
3863
+ selectedColumnName,
3864
+ rangeValue,
3865
+ typeaheadValue,
3866
+ onSelectedColumnChange,
3867
+ onRangeChange,
3868
+ onTypeaheadChange
3869
+ };
3870
+ };
3871
+
3872
+ // src/column-filter/ColumnFilter.tsx
3873
+ var import_jsx_runtime6 = require("react/jsx-runtime");
3874
+ var ColumnFilter = ({
3875
+ className,
3876
+ table,
3877
+ columns,
3878
+ onFilterSubmit,
3879
+ ...htmlAttributes
3880
+ }) => {
3881
+ const {
3882
+ clear,
3883
+ onTypeaheadChange,
3884
+ onRangeChange,
3885
+ onSelectedColumnChange,
3886
+ selectedColumnName,
3887
+ rangeValue,
3888
+ typeaheadValue
3889
+ } = useColumnFilterStore(onFilterSubmit);
3890
+ const getFilterComponent = () => {
3891
+ var _a;
3892
+ const defaultTypeaheadParams = [table, selectedColumnName];
3893
+ const selectedColumnType = (_a = columns.find(
3894
+ (column) => column.name === selectedColumnName
3895
+ )) == null ? void 0 : _a.serverDataType;
3896
+ switch (selectedColumnType) {
3897
+ case "string":
3898
+ case "char":
3899
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3900
+ import_salt_lab4.ToolbarField,
3901
+ {
3902
+ label: "Start typing to select a filter",
3903
+ labelPlacement: "top",
3904
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3905
+ TypeaheadFilter,
3906
+ {
3907
+ defaultTypeaheadParams,
3908
+ filterValues: typeaheadValue,
3909
+ onChange: onTypeaheadChange
3910
+ }
3911
+ )
3912
+ }
3913
+ );
3914
+ case "int":
3915
+ case "long":
3916
+ case "double":
3917
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_salt_lab4.ToolbarField, { label: "Select a range", labelPlacement: "top", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3918
+ RangeFilter,
3919
+ {
3920
+ defaultTypeaheadParams,
3921
+ filterValues: rangeValue,
3922
+ onChange: onRangeChange
3923
+ }
3924
+ ) });
3925
+ default:
3926
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_salt_lab4.ToolbarField, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_core.Text, { children: "Data type unsupported" }) });
3927
+ }
3928
+ };
3929
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
3930
+ import_salt_lab4.Toolbar,
3931
+ {
3932
+ ...htmlAttributes,
3933
+ style: { alignItems: "center", height: "36px" },
3934
+ children: [
3935
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3936
+ import_salt_lab4.ToolbarField,
3937
+ {
3938
+ label: "Select a column to filter",
3939
+ labelPlacement: "top",
3940
+ style: { width: 180 },
3941
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3942
+ import_salt_lab4.Dropdown,
3943
+ {
3944
+ source: columns,
3945
+ ListItem: ColumnListItem,
3946
+ itemToString: (column) => column.name,
3947
+ onSelectionChange: (_evt, column) => onSelectedColumnChange(column)
3948
+ }
3949
+ )
3950
+ }
3951
+ ),
3952
+ selectedColumnName && getFilterComponent(),
3953
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_salt_lab4.ToolbarButton, { onClick: clear, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DeleteIcon, {}) })
3954
+ ]
3955
+ }
3956
+ );
3957
+ };
3958
+
3959
+ // src/filter-input/FilterInput.tsx
3960
+ var import_core2 = require("@salt-ds/core");
3961
+
3962
+ // src/filter-input/useCodeMirrorEditor.ts
3963
+ var import_vuu_codemirror5 = require("@vuu-ui/vuu-codemirror");
3964
+ var import_classnames = __toESM(require_classnames(), 1);
3965
+ var import_react13 = require("react");
3966
+
3967
+ // src/filter-input/FilterLanguage.ts
3968
+ var import_vuu_codemirror = require("@vuu-ui/vuu-codemirror");
3969
+ var filterLanguage = import_vuu_codemirror.LRLanguage.define({
3970
+ name: "VuuFilterQuery",
3971
+ parser: parser.configure({
3972
+ props: [
3973
+ (0, import_vuu_codemirror.styleTags)({
3974
+ Identifier: import_vuu_codemirror.tags.variableName,
3975
+ String: import_vuu_codemirror.tags.string,
3976
+ Or: import_vuu_codemirror.tags.emphasis,
3977
+ Operator: import_vuu_codemirror.tags.operator
3978
+ })
3979
+ ]
3980
+ })
3981
+ });
3982
+ var filterLanguageSupport = () => {
3983
+ return new import_vuu_codemirror.LanguageSupport(filterLanguage);
3984
+ };
3985
+
3986
+ // src/filter-input/highlighting.ts
3987
+ var import_vuu_codemirror2 = require("@vuu-ui/vuu-codemirror");
3988
+ var myHighlightStyle = import_vuu_codemirror2.HighlightStyle.define([
3989
+ { tag: import_vuu_codemirror2.tags.variableName, color: "var(--vuuFilterEditor-variableColor)" },
3990
+ { tag: import_vuu_codemirror2.tags.comment, color: "green", fontStyle: "italic" }
3991
+ ]);
3992
+ var vuuHighlighting = (0, import_vuu_codemirror2.syntaxHighlighting)(myHighlightStyle);
3993
+
3994
+ // src/filter-input/theme.ts
3995
+ var import_vuu_codemirror3 = require("@vuu-ui/vuu-codemirror");
3996
+ var vuuTheme = import_vuu_codemirror3.EditorView.theme(
3997
+ {
3998
+ "&": {
3999
+ color: "var(--vuuFilterEditor-color)",
4000
+ backgroundColor: "var(--vuuFilterEditor-background)",
4001
+ fontSize: "var(--vuuFilterEditor-fontSize)"
4002
+ },
4003
+ ".cm-content": {
4004
+ caretColor: "var(--vuuFilterEditor-cursorColor)",
4005
+ padding: 0
4006
+ },
4007
+ ".cm-line": {
4008
+ lineHeight: "var(--vuuFilterEditor-lineHeight)"
4009
+ },
4010
+ "&.cm-focused .cm-cursor": {
4011
+ borderLeftColor: "var(--vuuFilterEditor-cursorColor)"
4012
+ },
4013
+ "&.cm-focused .cm-selectionBackground, ::selection": {
4014
+ backgroundColor: "var(--vuuFilterEditor-selectionBackground)"
4015
+ },
4016
+ ".cm-selectionBackground, ::selection": {
4017
+ backgroundColor: "var(--vuuFilterEditor-selectionBackground)"
4018
+ },
4019
+ ".cm-scroller": {
4020
+ fontFamily: "var(--vuuFilterEditor-fontFamily)"
4021
+ },
4022
+ ".cm-tooltip": {
4023
+ background: "var(--vuuFilterEditor-tooltipBackground)",
4024
+ border: "var(--vuuFilterEditor-tooltipBorder)",
4025
+ boxShadow: "var(--vuuFilterEditor-tooltipElevation)",
4026
+ "&.cm-tooltip-autocomplete > ul": {
4027
+ fontFamily: "var(--vuuFilterEditor-fontFamily)",
4028
+ fontSize: "var(--vuuFilterEditor-fontSize)",
4029
+ maxHeight: "240px"
4030
+ },
4031
+ "&.cm-tooltip-autocomplete > ul > li": {
4032
+ alignItems: "center",
4033
+ display: "flex",
4034
+ height: "var(--vuuFilterEditor-suggestion-height)",
4035
+ padding: "0 3px",
4036
+ lineHeight: "var(--vuuFilterEditor-suggestion-height)"
4037
+ },
4038
+ "&.cm-tooltip-autocomplete li[aria-selected]": {
4039
+ background: "var(--vuuFilterEditor-suggestion-selectedBackground)",
4040
+ color: "var(--vuuFilterEditor-suggestion-selectedColor)"
4041
+ }
4042
+ },
4043
+ ".cm-completionIcon": {
4044
+ height: "18px",
4045
+ flex: "0 0 16px"
4046
+ },
4047
+ ".cm-completionLabel": {
4048
+ flex: "1 1 auto"
4049
+ },
4050
+ ".cm-completionIcon-filter": {
4051
+ position: "relative",
4052
+ "&:after": {
4053
+ background: "var(--salt-text-secondary-foreground)",
4054
+ content: "''",
4055
+ "-webkit-mask": "var(--svg-filter) center center/13px 13px",
4056
+ "-webkit-mask-repeat": "no-repeat",
4057
+ position: "absolute",
4058
+ height: "18px",
4059
+ left: "0px",
4060
+ top: "0px",
4061
+ width: "16px"
4062
+ }
4063
+ }
4064
+ },
4065
+ { dark: false }
4066
+ );
4067
+
4068
+ // src/filter-input/useFilterAutoComplete.ts
4069
+ var import_vuu_codemirror4 = require("@vuu-ui/vuu-codemirror");
4070
+ var import_react12 = require("react");
4071
+ var getOperator = (node, state) => {
4072
+ let maybeColumnNode = node.prevSibling || node.parent;
4073
+ while (maybeColumnNode && !["Column", "Operator", "In"].includes(maybeColumnNode.name)) {
4074
+ maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
4075
+ }
4076
+ if ((maybeColumnNode == null ? void 0 : maybeColumnNode.name) === "In" || (maybeColumnNode == null ? void 0 : maybeColumnNode.name) === "Operator") {
4077
+ return (0, import_vuu_codemirror4.getValue)(maybeColumnNode, state);
4078
+ } else {
4079
+ return void 0;
4080
+ }
4081
+ };
4082
+ var getPartialOperator = (maybeOperatorNode, state, columnName) => {
4083
+ const value = (0, import_vuu_codemirror4.getValue)(maybeOperatorNode, state);
4084
+ if (columnName === void 0 || value === columnName) {
4085
+ return;
4086
+ }
4087
+ if (["contains", "ends", "starts"].some(
4088
+ (val) => val.startsWith(value.toLowerCase())
4089
+ )) {
4090
+ return value;
4091
+ } else {
4092
+ return void 0;
4093
+ }
4094
+ };
4095
+ var getClauseOperator = (node, state) => {
4096
+ let maybeTargetNode = node.prevSibling || node.parent || node.lastChild;
4097
+ while (maybeTargetNode && maybeTargetNode.name === "\u26A0")
4098
+ maybeTargetNode = maybeTargetNode.prevSibling;
4099
+ if (maybeTargetNode && ["As", "Or", "And"].includes(maybeTargetNode.name)) {
4100
+ return (0, import_vuu_codemirror4.getValue)(maybeTargetNode, state);
4101
+ } else {
4102
+ return void 0;
4103
+ }
4104
+ };
4105
+ var getFilterName = (node, state) => {
4106
+ if (node.name === "FilterName") {
4107
+ return (0, import_vuu_codemirror4.getValue)(node, state);
4108
+ } else {
4109
+ let maybeTargetNode = node.prevSibling || node.parent || node.lastChild;
4110
+ while (maybeTargetNode && maybeTargetNode.name !== "FilterName")
4111
+ maybeTargetNode = maybeTargetNode.prevSibling;
4112
+ if (maybeTargetNode && maybeTargetNode.name === "FilterName") {
4113
+ return (0, import_vuu_codemirror4.getValue)(node, state);
4114
+ }
4115
+ }
4116
+ };
4117
+ var getColumnName = (node, state) => {
4118
+ const prevNode = node.prevSibling;
4119
+ if ((prevNode == null ? void 0 : prevNode.name) === "Column") {
4120
+ return (0, import_vuu_codemirror4.getValue)(prevNode, state);
4121
+ } else if ((prevNode == null ? void 0 : prevNode.name) === "Operator") {
4122
+ return getColumnName(prevNode, state);
4123
+ }
4124
+ };
4125
+ var getSetValues = (node, state) => {
4126
+ let maybeTargetNode = node.lastChild;
4127
+ const values = [];
4128
+ while (maybeTargetNode && maybeTargetNode.name !== "In") {
4129
+ const value = (0, import_vuu_codemirror4.getValue)(maybeTargetNode, state);
4130
+ if (value) {
4131
+ values.push(value);
4132
+ } else {
4133
+ break;
4134
+ }
4135
+ maybeTargetNode = maybeTargetNode.prevSibling;
4136
+ }
4137
+ return values;
4138
+ };
4139
+ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
4140
+ const makeSuggestions = (0, import_react12.useCallback)(
4141
+ async (context, suggestionType, optionalArgs = {}) => {
4142
+ const { startsWith = "" } = optionalArgs;
4143
+ const options = await suggestionProvider.getSuggestions(
4144
+ suggestionType,
4145
+ optionalArgs
4146
+ );
4147
+ return { from: context.pos - startsWith.length, options };
4148
+ },
4149
+ [suggestionProvider]
4150
+ );
4151
+ return (0, import_react12.useCallback)(
4152
+ async (context) => {
4153
+ var _a, _b;
4154
+ const { state, pos } = context;
4155
+ const word = (_a = context.matchBefore(/\w*/)) != null ? _a : {
4156
+ from: 0,
4157
+ to: 0,
4158
+ text: void 0
4159
+ };
4160
+ const tree = (0, import_vuu_codemirror4.syntaxTree)(state);
4161
+ const nodeBefore = tree.resolveInner(pos, -1);
4162
+ console.log({ nodeBeforeName: nodeBefore.name });
4163
+ switch (nodeBefore.name) {
4164
+ case "Filter":
4165
+ if (context.pos === 0) {
4166
+ return makeSuggestions(context, "column");
4167
+ } else {
4168
+ const clauseOperator = getClauseOperator(nodeBefore, state);
4169
+ if (clauseOperator === "as") {
4170
+ return makeSuggestions(context, "name");
4171
+ } else {
4172
+ const filterName = getFilterName(nodeBefore, state);
4173
+ return makeSuggestions(context, "save", {
4174
+ onSubmit: onSubmit.current,
4175
+ existingFilter,
4176
+ filterName
4177
+ });
4178
+ }
4179
+ }
4180
+ case "String":
4181
+ {
4182
+ const operator = getOperator(nodeBefore, state);
4183
+ const columnName = getColumnName(nodeBefore, state);
4184
+ const { from, to } = nodeBefore;
4185
+ if (to - from === 2 && context.pos === from + 1) {
4186
+ if (columnName && operator) {
4187
+ return makeSuggestions(context, "columnValue", {
4188
+ columnName,
4189
+ operator,
4190
+ quoted: true,
4191
+ startsWith: word.text
4192
+ });
4193
+ }
4194
+ } else {
4195
+ console.log(
4196
+ `we have a string, column is ${columnName} ${from} ${to}`
4197
+ );
4198
+ }
4199
+ }
4200
+ break;
4201
+ case "As":
4202
+ return makeSuggestions(context, "name");
4203
+ case "FilterName":
4204
+ return makeSuggestions(context, "save", {
4205
+ onSubmit: onSubmit.current,
4206
+ existingFilter,
4207
+ filterName: getFilterName(nodeBefore, state)
4208
+ });
4209
+ case "Column": {
4210
+ const columnName = (0, import_vuu_codemirror4.getValue)(nodeBefore, state);
4211
+ const isPartialMatch = await suggestionProvider.isPartialMatch(
4212
+ "column",
4213
+ void 0,
4214
+ columnName
4215
+ );
4216
+ if (isPartialMatch) {
4217
+ return makeSuggestions(context, "column", {
4218
+ startsWith: columnName
4219
+ });
4220
+ } else {
4221
+ return makeSuggestions(context, "operator", { columnName });
4222
+ }
4223
+ }
4224
+ case "\u26A0": {
4225
+ const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
4226
+ const operator = getOperator(nodeBefore, state);
4227
+ const partialOperator = operator ? void 0 : getPartialOperator(nodeBefore, state, columnName);
4228
+ if (partialOperator) {
4229
+ return makeSuggestions(context, "operator", {
4230
+ columnName,
4231
+ startsWith: partialOperator
4232
+ });
4233
+ } else {
4234
+ return makeSuggestions(context, "columnValue", {
4235
+ columnName,
4236
+ operator,
4237
+ startsWith: word.text
4238
+ });
4239
+ }
4240
+ }
4241
+ case "Identifier":
4242
+ {
4243
+ const clauseOperator = getClauseOperator(nodeBefore, state);
4244
+ if (clauseOperator === "as") {
4245
+ return {
4246
+ from: context.pos,
4247
+ options: [
4248
+ {
4249
+ label: "press ENTER to apply filter and save",
4250
+ apply: () => onSubmit.current(),
4251
+ boost: 5
4252
+ }
4253
+ ]
4254
+ };
4255
+ }
4256
+ }
4257
+ break;
4258
+ case "ColumnSetExpression":
4259
+ case "Values": {
4260
+ const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
4261
+ const selection = getSetValues(nodeBefore, state);
4262
+ return makeSuggestions(context, "columnValue", {
4263
+ columnName,
4264
+ selection
4265
+ });
4266
+ }
4267
+ case "Comma":
4268
+ case "LBrack": {
4269
+ const columnName = (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state);
4270
+ return makeSuggestions(context, "columnValue", { columnName });
4271
+ }
4272
+ case "ColumnValueExpression":
4273
+ {
4274
+ const lastToken = (_b = nodeBefore.lastChild) == null ? void 0 : _b.prevSibling;
4275
+ if ((lastToken == null ? void 0 : lastToken.name) === "Column") {
4276
+ return makeSuggestions(context, "operator", {
4277
+ columnName: (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state)
4278
+ });
4279
+ } else if ((lastToken == null ? void 0 : lastToken.name) === "Operator") {
4280
+ return makeSuggestions(context, "columnValue", {
4281
+ columnName: (0, import_vuu_codemirror4.getNodeByName)(lastToken, state),
4282
+ operator: (0, import_vuu_codemirror4.getValue)(lastToken, state)
4283
+ });
4284
+ }
4285
+ }
4286
+ break;
4287
+ case "In": {
4288
+ return {
4289
+ from: context.pos,
4290
+ options: [{ label: "[", apply: " [", type: "text" }]
4291
+ };
4292
+ }
4293
+ case "Eq": {
4294
+ return makeSuggestions(context, "columnValue", {
4295
+ columnName: (0, import_vuu_codemirror4.getNodeByName)(nodeBefore, state)
4296
+ });
4297
+ }
4298
+ case "AndExpression":
4299
+ case "OrExpression": {
4300
+ return makeSuggestions(context, "column");
4301
+ }
4302
+ default:
4303
+ }
4304
+ },
4305
+ [existingFilter, makeSuggestions, onSubmit, suggestionProvider]
4306
+ );
4307
+ };
4308
+
4309
+ // src/filter-input/useCodeMirrorEditor.ts
4310
+ var getView = (ref) => {
4311
+ if (ref.current == void 0) {
4312
+ throw Error("EditorView not defined");
4313
+ }
4314
+ return ref.current;
4315
+ };
4316
+ var getOptionClass = (completion) => {
4317
+ return (0, import_classnames.default)("vuuSuggestion", {
4318
+ vuuIllustration: completion.isIllustration
4319
+ });
4320
+ };
4321
+ var stripName = (filterQuery) => {
4322
+ const pos = filterQuery.lastIndexOf(" as ");
4323
+ if (pos !== -1) {
4324
+ return filterQuery.slice(0, pos);
4325
+ } else {
4326
+ return filterQuery;
4327
+ }
4328
+ };
4329
+ var noop = () => console.log("noooop");
4330
+ var useCodeMirrorEditor = ({
4331
+ existingFilter,
4332
+ onSubmitFilter,
4333
+ suggestionProvider
4334
+ }) => {
4335
+ const editorRef = (0, import_react13.useRef)(null);
4336
+ const onSubmit = (0, import_react13.useRef)(noop);
4337
+ const viewRef = (0, import_react13.useRef)();
4338
+ const completionFn = useAutoComplete(
4339
+ suggestionProvider,
4340
+ onSubmit,
4341
+ existingFilter
4342
+ );
4343
+ const [createState, clearInput] = (0, import_react13.useMemo)(() => {
4344
+ const parseFilter2 = () => {
4345
+ const view = getView(viewRef);
4346
+ const source = view.state.doc.toString();
4347
+ const tree = (0, import_vuu_codemirror5.ensureSyntaxTree)(view.state, view.state.doc.length, 5e3);
4348
+ if (tree) {
4349
+ const filter = walkTree(tree, source);
4350
+ return [filter, stripName(source), filter.name];
4351
+ } else {
4352
+ return [void 0, "", void 0];
4353
+ }
4354
+ };
4355
+ const clearInput2 = () => {
4356
+ getView(viewRef).setState(createState2());
4357
+ };
4358
+ const submitFilterAndClearInput = (mode) => {
4359
+ const [filter, filterQuery, filterName] = parseFilter2();
4360
+ onSubmitFilter == null ? void 0 : onSubmitFilter(filter, filterQuery, mode, filterName);
4361
+ clearInput2();
4362
+ };
4363
+ const submitFilter = (key) => {
4364
+ return import_vuu_codemirror5.keymap.of([
4365
+ {
4366
+ key,
4367
+ run() {
4368
+ submitFilterAndClearInput();
4369
+ return true;
4370
+ }
4371
+ }
4372
+ ]);
4373
+ };
4374
+ const showSuggestions = (key) => {
4375
+ return import_vuu_codemirror5.keymap.of([
4376
+ {
4377
+ key,
4378
+ run() {
4379
+ (0, import_vuu_codemirror5.startCompletion)(getView(viewRef));
4380
+ return true;
4381
+ }
4382
+ }
4383
+ ]);
4384
+ };
4385
+ const createState2 = () => import_vuu_codemirror5.EditorState.create({
4386
+ doc: "",
4387
+ extensions: [
4388
+ import_vuu_codemirror5.minimalSetup,
4389
+ (0, import_vuu_codemirror5.autocompletion)({
4390
+ override: [completionFn],
4391
+ optionClass: getOptionClass
4392
+ }),
4393
+ filterLanguageSupport(),
4394
+ import_vuu_codemirror5.keymap.of(import_vuu_codemirror5.defaultKeymap),
4395
+ submitFilter("Ctrl-Enter"),
4396
+ showSuggestions("ArrowDown"),
4397
+ import_vuu_codemirror5.EditorView.updateListener.of((v) => {
4398
+ const view = getView(viewRef);
4399
+ if (v.docChanged) {
4400
+ (0, import_vuu_codemirror5.startCompletion)(view);
4401
+ }
4402
+ }),
4403
+ import_vuu_codemirror5.EditorState.transactionFilter.of(
4404
+ (tr) => tr.newDoc.lines > 1 ? [] : tr
4405
+ ),
4406
+ vuuTheme,
4407
+ vuuHighlighting
4408
+ ]
4409
+ });
4410
+ onSubmit.current = (mode) => {
4411
+ submitFilterAndClearInput(mode);
4412
+ setTimeout(() => {
4413
+ getView(viewRef).focus();
4414
+ }, 100);
4415
+ };
4416
+ return [createState2, clearInput2];
4417
+ }, [completionFn, onSubmitFilter]);
4418
+ (0, import_react13.useEffect)(() => {
4419
+ if (!editorRef.current) {
4420
+ throw Error("editor not in dom");
4421
+ }
4422
+ viewRef.current = new import_vuu_codemirror5.EditorView({
4423
+ state: createState(),
4424
+ parent: editorRef.current
4425
+ });
4426
+ return () => {
4427
+ var _a;
4428
+ (_a = viewRef.current) == null ? void 0 : _a.destroy();
4429
+ };
4430
+ }, [completionFn, createState]);
4431
+ return { editorRef, clearInput };
4432
+ };
4433
+
4434
+ // src/filter-input/FilterInput.tsx
4435
+ var import_jsx_runtime7 = require("react/jsx-runtime");
4436
+ var classBase = "vuuFilterInput";
4437
+ var FilterInput = ({
4438
+ existingFilter,
4439
+ iconName = "filter",
4440
+ namedFilters,
4441
+ onSubmitFilter,
4442
+ suggestionProvider,
4443
+ ...props
4444
+ }) => {
4445
+ const { editorRef, clearInput } = useCodeMirrorEditor({
4446
+ existingFilter,
4447
+ onSubmitFilter,
4448
+ suggestionProvider
4449
+ });
4450
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { ...props, className: classBase, children: [
4451
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4452
+ import_core2.Button,
4453
+ {
4454
+ className: `${classBase}-FilterButton`,
4455
+ "data-icon": iconName,
4456
+ tabIndex: -1
4457
+ }
4458
+ ),
4459
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase}-Editor`, ref: editorRef }),
4460
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4461
+ import_core2.Button,
4462
+ {
4463
+ className: `${classBase}-ClearButton`,
4464
+ "data-icon": "close-circle",
4465
+ onClick: clearInput
4466
+ }
4467
+ )
4468
+ ] });
4469
+ };
4470
+
4471
+ // src/filter-input/useFilterSuggestionProvider.ts
4472
+ var import_vuu_codemirror6 = require("@vuu-ui/vuu-codemirror");
4473
+ var import_react14 = require("react");
4474
+
4475
+ // src/filter-input/filterInfo.ts
4476
+ var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
4477
+ var filterInfo = (filterName, filterQuery) => {
4478
+ const rootElement = (0, import_vuu_utils6.createEl)("div", "vuuFunctionDoc");
4479
+ const headingElement = (0, import_vuu_utils6.createEl)("div", "function-heading");
4480
+ const nameElement = (0, import_vuu_utils6.createEl)("span", "function-name", filterName);
4481
+ headingElement.appendChild(nameElement);
4482
+ const child2 = (0, import_vuu_utils6.createEl)("p", void 0, filterQuery);
4483
+ rootElement.appendChild(headingElement);
4484
+ rootElement.appendChild(child2);
4485
+ return rootElement;
4486
+ };
4487
+
4488
+ // src/filter-input/useFilterSuggestionProvider.ts
4489
+ var NO_NAMED_FILTERS = [];
4490
+ var NONE = {};
4491
+ var saveAsTab = (onSubmit) => [
4492
+ {
4493
+ label: "Press ENTER to create TAB",
4494
+ apply: () => onSubmit("tab"),
4495
+ boost: 6
4496
+ }
4497
+ ];
4498
+ var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions = true) => {
4499
+ const result = existingFilter ? [
4500
+ {
4501
+ label: "REPLACE existing filter",
4502
+ apply: () => onSubmit("replace"),
4503
+ boost: 8
4504
+ },
4505
+ {
4506
+ label: "AND existing filter",
4507
+ apply: () => onSubmit("and"),
4508
+ boost: 7
4509
+ },
4510
+ {
4511
+ label: "OR existing filter",
4512
+ apply: () => onSubmit("or"),
4513
+ boost: 7
4514
+ }
4515
+ ] : [
4516
+ {
4517
+ label: "Press ENTER to submit",
4518
+ apply: () => onSubmit(),
4519
+ boost: 6
4520
+ }
4521
+ ];
4522
+ return withJoinSuggestions ? result.concat(import_vuu_codemirror6.booleanJoinSuggestions).concat(import_vuu_codemirror6.asNameSuggestion) : result;
4523
+ };
4524
+ var promptToSaveOrExtend = (onSubmit, existingFilter) => makeSaveOrExtendSuggestions(onSubmit, existingFilter, true);
4525
+ var promptToSave = (onSubmit) => makeSaveOrExtendSuggestions(onSubmit, void 0);
4526
+ var getSaveSuggestions = ({
4527
+ existingFilter,
4528
+ filterName,
4529
+ onSubmit,
4530
+ saveOptions
4531
+ }) => {
4532
+ const includeTabSuggestion = filterName && saveOptions.allowSaveAsTab;
4533
+ const result = existingFilter ? promptToSaveOrExtend(onSubmit, existingFilter) : promptToSave(onSubmit);
4534
+ if (includeTabSuggestion) {
4535
+ return result.concat(saveAsTab(onSubmit));
4536
+ } else {
4537
+ return result;
4538
+ }
4539
+ };
4540
+ var suggestColumns = (columns) => columns.map((column) => ({
4541
+ boost: 5,
4542
+ label: column.name
4543
+ }));
4544
+ var suggestNamedFilters = (namedFilters) => namedFilters ? Array.from(namedFilters.entries()).map(([filterName, filterQuery]) => ({
4545
+ info: () => filterInfo(filterName, filterQuery),
4546
+ label: filterName,
4547
+ type: "filter"
4548
+ })) : NO_NAMED_FILTERS;
4549
+ var doneCommand = {
4550
+ label: "Done",
4551
+ apply: "] ",
4552
+ type: "keyword",
4553
+ boost: 10
4554
+ };
4555
+ var withApplySpace = (suggestions, startsWith = "") => suggestions.filter((sugg) => startsWith === "" || sugg.label.startsWith(startsWith)).map((suggestion) => ({
4556
+ ...suggestion,
4557
+ apply: suggestion.label + " "
4558
+ }));
4559
+ var defaultSaveOptions = {
4560
+ allowReplace: true
4561
+ };
4562
+ var useFilterSuggestionProvider = ({
4563
+ columns,
4564
+ namedFilters,
4565
+ saveOptions = defaultSaveOptions,
4566
+ table,
4567
+ typeaheadHook: useTypeahead = useTypeaheadSuggestions
4568
+ }) => {
4569
+ const latestSuggestionsRef = (0, import_react14.useRef)();
4570
+ const getTypeaheadSuggestions = useTypeahead();
4571
+ const getSuggestions = (0, import_react14.useCallback)(
4572
+ async (suggestionType, options = NONE) => {
4573
+ const {
4574
+ columnName,
4575
+ existingFilter,
4576
+ filterName,
4577
+ operator,
4578
+ quoted: autoQuoted,
4579
+ onSubmit,
4580
+ startsWith,
4581
+ selection
4582
+ } = options;
4583
+ switch (suggestionType) {
4584
+ case "operator":
4585
+ {
4586
+ const column = columns.find((col) => col.name === columnName);
4587
+ if (column) {
4588
+ switch (column.serverDataType) {
4589
+ case "string":
4590
+ case "char":
4591
+ return withApplySpace(import_vuu_codemirror6.stringOperators, startsWith);
4592
+ case "int":
4593
+ case "long":
4594
+ case "double":
4595
+ return withApplySpace(import_vuu_codemirror6.numericOperators);
4596
+ }
4597
+ } else {
4598
+ console.warn(`'${columnName}' does not match any column name`);
4599
+ }
4600
+ }
4601
+ break;
4602
+ case "column": {
4603
+ const columnSuggestions = await suggestColumns(columns);
4604
+ const filterSuggestions = await suggestNamedFilters(namedFilters);
4605
+ return (latestSuggestionsRef.current = withApplySpace(columnSuggestions)).concat(
4606
+ withApplySpace(filterSuggestions)
4607
+ );
4608
+ }
4609
+ case "columnValue":
4610
+ {
4611
+ if (columnName) {
4612
+ const column = columns.find((col) => col.name === columnName);
4613
+ if (!column) {
4614
+ throw Error(
4615
+ `useFilterSUggestionProvider no column ${columnName}`
4616
+ );
4617
+ }
4618
+ const prefix = Array.isArray(selection) ? selection.length === 0 ? "[" : "," : "";
4619
+ const params = getTypeaheadParams(
4620
+ table,
4621
+ columnName,
4622
+ startsWith
4623
+ );
4624
+ const suggestions = await getTypeaheadSuggestions(params);
4625
+ const isIllustration = operator === "starts";
4626
+ latestSuggestionsRef.current = (0, import_vuu_codemirror6.toSuggestions)(suggestions, {
4627
+ moveCursorToEnd: autoQuoted,
4628
+ quoted: (column == null ? void 0 : column.serverDataType) === "string" && !autoQuoted,
4629
+ suffix: autoQuoted ? "" : " ",
4630
+ prefix: isIllustration ? startsWith : prefix,
4631
+ isIllustration
4632
+ });
4633
+ if (Array.isArray(selection) && (selection == null ? void 0 : selection.length) > 1) {
4634
+ return [doneCommand, ...latestSuggestionsRef.current];
4635
+ }
4636
+ return latestSuggestionsRef.current;
4637
+ }
4638
+ }
4639
+ break;
4640
+ case "save": {
4641
+ if (typeof onSubmit !== "function") {
4642
+ throw Error(
4643
+ "useFilterSuggestionProvider, onSubmit must be supplied for 'save' suggestions"
4644
+ );
4645
+ }
4646
+ return await getSaveSuggestions({
4647
+ existingFilter,
4648
+ filterName,
4649
+ onSubmit,
4650
+ saveOptions
4651
+ });
4652
+ }
4653
+ case "name":
4654
+ return await (0, import_vuu_codemirror6.getNamePrompt)("filter");
4655
+ default:
4656
+ }
4657
+ return [];
4658
+ },
4659
+ [columns, getTypeaheadSuggestions, namedFilters, saveOptions, table]
4660
+ );
4661
+ const isPartialMatch = (0, import_react14.useCallback)(
4662
+ async (valueType, columnName, pattern) => {
4663
+ const suggestions = (
4664
+ // latestSuggestions && latestSuggestions.length > 0
4665
+ // ? latestSuggestions
4666
+ await getSuggestions(valueType, { columnName })
4667
+ );
4668
+ if (pattern && suggestions) {
4669
+ for (const option of suggestions) {
4670
+ if (option.label === pattern) {
4671
+ return false;
4672
+ } else if (option.label.startsWith(pattern)) {
4673
+ return true;
4674
+ }
4675
+ }
4676
+ }
4677
+ return false;
4678
+ },
4679
+ [getSuggestions]
4680
+ );
4681
+ return {
4682
+ getSuggestions,
4683
+ isPartialMatch
4684
+ };
4685
+ };
4686
+
4687
+ // src/filter-toolbar/FilterToolbar.tsx
4688
+ var import_salt_lab8 = require("@heswell/salt-lab");
4689
+ var import_classnames2 = __toESM(require_classnames(), 1);
4690
+
4691
+ // src/filter-toolbar/useFilterToolbar.tsx
4692
+ var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
4693
+ var import_salt_lab7 = require("@heswell/salt-lab");
4694
+
4695
+ // src/filter-toolbar/FilterDropdown.tsx
4696
+ var import_salt_lab5 = require("@heswell/salt-lab");
4697
+ var import_react15 = require("react");
4698
+ var import_jsx_runtime8 = require("react/jsx-runtime");
4699
+ var isString = (s) => typeof s === "string";
4700
+ var stripQuotes = (selected) => {
4701
+ if (isString(selected)) {
4702
+ if (selected.startsWith('"') && selected.endsWith('"')) {
4703
+ return selected.slice(1, -1);
4704
+ } else {
4705
+ return selected;
4706
+ }
4707
+ } else {
4708
+ return selected.map(stripQuotes);
4709
+ }
4710
+ };
4711
+ var FilterDropdown = ({
4712
+ column,
4713
+ selected: selectedProp,
4714
+ suggestionProvider,
4715
+ ...props
4716
+ }) => {
4717
+ const selected = selectedProp != null ? stripQuotes(selectedProp) : void 0;
4718
+ const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
4719
+ const [values, setValues] = (0, import_react15.useState)(initialValues);
4720
+ console.log({ initialValues });
4721
+ const handleOpenChange = (0, import_react15.useCallback)(
4722
+ async (isOpen) => {
4723
+ if (isOpen) {
4724
+ const values2 = await suggestionProvider.getSuggestions("columnValue", {
4725
+ columnName: column
4726
+ });
4727
+ console.log({ values: values2 });
4728
+ setValues(values2.map((suggestion) => suggestion.label));
4729
+ }
4730
+ },
4731
+ [column, suggestionProvider]
4732
+ );
4733
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4734
+ import_salt_lab5.Dropdown,
4735
+ {
4736
+ ...props,
4737
+ onOpenChange: handleOpenChange,
4738
+ selected,
4739
+ source: values
4740
+ }
4741
+ );
4742
+ };
4743
+
4744
+ // src/filter-toolbar/FilterDropdownMultiSelect.tsx
4745
+ var import_salt_lab6 = require("@heswell/salt-lab");
4746
+ var import_react16 = require("react");
4747
+ var import_jsx_runtime9 = require("react/jsx-runtime");
4748
+ var isString2 = (s) => typeof s === "string";
4749
+ var stripQuotes2 = (selected) => {
4750
+ if (selected === void 0) {
4751
+ return void 0;
4752
+ } else if (isString2(selected)) {
4753
+ if (selected.startsWith('"') && selected.endsWith('"')) {
4754
+ return selected.slice(1, -1);
4755
+ } else {
4756
+ return selected;
4757
+ }
4758
+ } else {
4759
+ return selected.map(stripQuotes2);
4760
+ }
4761
+ };
4762
+ var FilterDropdownMultiSelect = ({
4763
+ column,
4764
+ selected: selectedProp,
4765
+ suggestionProvider,
4766
+ ...props
4767
+ }) => {
4768
+ const selected = stripQuotes2(selectedProp);
4769
+ const initialValues = Array.isArray(selected) ? selected : selected != null ? [selected] : [];
4770
+ const [values, setValues] = (0, import_react16.useState)(initialValues);
4771
+ const handleOpenChange = (0, import_react16.useCallback)(
4772
+ async (isOpen) => {
4773
+ if (isOpen) {
4774
+ const values2 = await suggestionProvider.getSuggestions("columnValue", {
4775
+ columnName: column
4776
+ });
4777
+ console.log({ values: values2 });
4778
+ setValues(values2.map((suggestion) => suggestion.label));
4779
+ }
4780
+ },
4781
+ [column, suggestionProvider]
4782
+ );
4783
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4784
+ import_salt_lab6.Dropdown,
4785
+ {
4786
+ ...props,
4787
+ onOpenChange: handleOpenChange,
4788
+ selected,
4789
+ selectionStrategy: "multiple",
4790
+ source: values
4791
+ }
4792
+ );
4793
+ };
4794
+
4795
+ // src/filter-toolbar/useFilterToolbar.tsx
4796
+ var import_jsx_runtime10 = require("react/jsx-runtime");
4797
+ var filterToControl = (filter, suggestionProvider) => {
4798
+ if ((0, import_vuu_utils7.isNamedFilter)(filter)) {
4799
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4800
+ import_salt_lab7.ToggleButton,
4801
+ {
4802
+ className: "vuuToggleButton",
4803
+ toggled: true,
4804
+ variant: "secondary",
4805
+ children: filter.name
4806
+ }
4807
+ );
4808
+ }
4809
+ if ((0, import_vuu_utils7.isSingleValueFilter)(filter)) {
4810
+ const { column, value } = filter;
4811
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4812
+ import_salt_lab7.ToolbarField,
4813
+ {
4814
+ className: "vuuFilterDropdown",
4815
+ label: column,
4816
+ labelPlacement: "top",
4817
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4818
+ FilterDropdown,
4819
+ {
4820
+ column,
4821
+ selected: value.toString(),
4822
+ selectionStrategy: "default",
4823
+ source: [value.toString()],
4824
+ suggestionProvider,
4825
+ style: { width: 100 }
4826
+ }
4827
+ )
4828
+ },
4829
+ column
4830
+ );
4831
+ }
4832
+ if ((0, import_vuu_utils7.isMultiValueFilter)(filter)) {
4833
+ const values = filter.values.map((v) => v.toString());
4834
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4835
+ import_salt_lab7.ToolbarField,
4836
+ {
4837
+ className: "vuuFilterDropdown",
4838
+ label: filter.column,
4839
+ labelPlacement: "top",
4840
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
4841
+ FilterDropdownMultiSelect,
4842
+ {
4843
+ column: filter.column,
4844
+ selected: values,
4845
+ source: values,
4846
+ suggestionProvider,
4847
+ style: { width: 100 }
4848
+ }
4849
+ )
4850
+ },
4851
+ filter.column
4852
+ );
4853
+ }
4854
+ return filter.filters.map(
4855
+ (filter2) => filterToControl(filter2, suggestionProvider)
4856
+ );
4857
+ };
4858
+ var useFilterToolbar = ({
4859
+ filter,
4860
+ suggestionProvider
4861
+ }) => {
4862
+ if (filter) {
4863
+ return filterToControl(filter, suggestionProvider);
4864
+ }
4865
+ return [];
4866
+ };
4867
+
4868
+ // src/filter-toolbar/FilterToolbar.tsx
4869
+ var import_jsx_runtime11 = require("react/jsx-runtime");
4870
+ var FilterToolbar = ({
4871
+ className,
4872
+ filter,
4873
+ suggestionProvider,
4874
+ ...props
4875
+ }) => {
4876
+ console.log(`FilterToolbar ${JSON.stringify(filter, null, 2)}`);
4877
+ const toolbarItems = useFilterToolbar({ filter, suggestionProvider });
4878
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_salt_lab8.Toolbar, { className: (0, import_classnames2.default)("vuuFilterToolbar", className), ...props, children: toolbarItems });
4879
+ };
32
4880
  /*! Bundled license information:
33
4881
 
34
4882
  classnames/index.js: