@ngrok/mantle 0.92.1 → 0.93.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.json +48 -1
- package/dist/alert-dialog.js +1 -1
- package/dist/app-layout.js +1 -1
- package/dist/code-DUJzSl4K.js +1 -0
- package/dist/{code-block-Bqw9VyK_.d.ts → code-block-BGdV4Yty.d.ts} +1 -1
- package/dist/{code-block-CNR8NuNT.js → code-block-W3kWPxCJ.js} +1 -1
- package/dist/code-block.d.ts +1 -1
- package/dist/code-block.js +2 -2
- package/dist/code-block_highlight-utils.d.ts +1 -1
- package/dist/code-block_highlight-utils.js +1 -1
- package/dist/code.js +1 -1
- package/dist/command.js +1 -1
- package/dist/{dialog-qordIos1.js → dialog-7TUgiSzX.js} +1 -1
- package/dist/dialog.js +1 -1
- package/dist/dropdown-menu-BHBzCDSZ.js +1 -0
- package/dist/dropdown-menu.js +1 -1
- package/dist/field.d.ts +1 -0
- package/dist/field.js +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hover-card.js +1 -1
- package/dist/{icons-DGL0d2Il.js → icons-DP3lQw5O.js} +1 -1
- package/dist/icons.js +1 -1
- package/dist/layer-container-kEQiE4zV.js +1 -0
- package/dist/layer-container.d.ts +8 -1
- package/dist/layer-container.js +1 -1
- package/dist/llms.txt +5 -1
- package/dist/multi-select.js +1 -1
- package/dist/pagination.js +1 -1
- package/dist/popover-C96V8SXi.d.ts +1 -0
- package/dist/{popover-BCGCpwkK.js → popover-DxOqLKxy.js} +1 -1
- package/dist/popover.d.ts +1 -0
- package/dist/popover.js +1 -1
- package/dist/primitive-Dz9Al-us.js +1 -0
- package/dist/query-filter.d.ts +399 -0
- package/dist/query-filter.js +1 -0
- package/dist/query.d.ts +688 -0
- package/dist/query.js +1 -0
- package/dist/sandbar.d.ts +6 -0
- package/dist/sandbar.js +1 -1
- package/dist/select-CAAYk4Yj.js +1 -0
- package/dist/select.js +1 -1
- package/dist/{sheet-C0QytOsE.js → sheet-CSJc_sB4.js} +1 -1
- package/dist/sheet.js +1 -1
- package/dist/sidebar.js +1 -1
- package/dist/slider.js +1 -1
- package/dist/split-button.js +1 -1
- package/dist/suggestions-Ciz2vaJO.js +1 -0
- package/dist/suggestions-NkqYTT49.d.ts +261 -0
- package/dist/tabs.d.ts +6 -1
- package/dist/tabs.js +1 -1
- package/dist/theme-C-glc5Q-.js +1 -0
- package/dist/theme-switcher.js +1 -1
- package/dist/theme.d.ts +2 -2
- package/dist/theme.js +1 -1
- package/dist/toast.js +1 -1
- package/dist/{tooltip-BwMlCD6k.js → tooltip-b6oiTaWq.js} +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/truncated-text.js +1 -1
- package/package.json +4 -2
- package/dist/dropdown-menu-CLHkKzhe.js +0 -1
- package/dist/layer-container-DLf-6eBz.js +0 -1
- package/dist/primitive-AGoxSJBI.js +0 -1
- package/dist/select-MjJMGqwP.js +0 -1
- package/dist/theme-CwtpudOH.js +0 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { _ as getFilterKeyDefinition, a as ValueCandidate, b as resolveFilterValue, c as FilterGrammar, d as FilterSyntax, f as FilterValueDefinition, g as defineRemoteFilterGrammar, h as acceptsValueList, i as FilterSuggestionsOptions, l as FilterKeyDefinition, m as RemoteFilterKeyDefinition, n as FilterSuggestionSection, o as getFilterSuggestions, p as RemoteFilterGrammarOptions, r as FilterSuggestions, s as getValueCandidates, t as FilterSuggestion, u as FilterMatchContext, v as getFilterSyntax, y as resolveFilterKey } from "./suggestions-NkqYTT49.js";
|
|
2
|
+
/**
|
|
3
|
+
* Splits a filter query into coloured runs for the overlay that sits behind the
|
|
4
|
+
* caret in `QueryFilterInput`.
|
|
5
|
+
*
|
|
6
|
+
* The segments always concatenate back to the exact input, whitespace and quote
|
|
7
|
+
* characters included. The overlay is a second copy of the same string painted
|
|
8
|
+
* under a transparent input, so a dropped character would slide every glyph
|
|
9
|
+
* after it out of line with the caret.
|
|
10
|
+
*/
|
|
11
|
+
/** How one run of the query reads in the grammar. */
|
|
12
|
+
type HighlightSegmentKind =
|
|
13
|
+
/** A qualifier key, up to but not including the `:`. */
|
|
14
|
+
"key" |
|
|
15
|
+
/** A qualifier value the grammar recognizes. */
|
|
16
|
+
"value" |
|
|
17
|
+
/**
|
|
18
|
+
* A qualifier value that matches no alias, so the filter matches nothing.
|
|
19
|
+
* Under the `"conjunction"` syntax, also a run the executor cannot run: a
|
|
20
|
+
* bare term, or a `-` on a key that is not negatable.
|
|
21
|
+
*/
|
|
22
|
+
"invalid" |
|
|
23
|
+
/** A bare search term. */
|
|
24
|
+
"text" |
|
|
25
|
+
/** The `OR` between two filter groups. */
|
|
26
|
+
"operator" |
|
|
27
|
+
/** The `-` and `:` that give a token its shape. */
|
|
28
|
+
"syntax" |
|
|
29
|
+
/** Whitespace between tokens. */
|
|
30
|
+
"plain";
|
|
31
|
+
/** One coloured run of the query. */
|
|
32
|
+
type HighlightSegment = {
|
|
33
|
+
/** Offset of the run's first character in the source query. */
|
|
34
|
+
start: number;
|
|
35
|
+
/** The exact source text of this run. */
|
|
36
|
+
text: string;
|
|
37
|
+
/** How the run reads in the grammar. */
|
|
38
|
+
kind: HighlightSegmentKind;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Splits a filter query into segments for the syntax-highlighting overlay.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* getHighlightSegments(grammar, "is:bogus");
|
|
46
|
+
* // => [{ start: 0, text: "is", kind: "key" },
|
|
47
|
+
* // { start: 2, text: ":", kind: "syntax" },
|
|
48
|
+
* // { start: 3, text: "bogus", kind: "invalid" }]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function getHighlightSegments<Item>(grammar: FilterGrammar<Item>, query: string): HighlightSegment[];
|
|
52
|
+
/**
|
|
53
|
+
* The query-filter language, tokenized.
|
|
54
|
+
*
|
|
55
|
+
* The parser is **total**: it returns tokens for every prefix of every input and
|
|
56
|
+
* never throws. The query is a hand-editable URL param and the suggestion list
|
|
57
|
+
* re-parses on each keystroke, so a thrown `SyntaxError` would take the page
|
|
58
|
+
* down mid-word. Anything the grammar does not recognize degrades to free text.
|
|
59
|
+
*
|
|
60
|
+
* A `"qualifiers"` grammar reads only `key:value` tokens as structure: quotes,
|
|
61
|
+
* the negation dash, the `OR`/`AND` operators, and comma lists all stay text.
|
|
62
|
+
* A `"conjunction"` grammar reads every token the full syntax does; what the
|
|
63
|
+
* executor cannot run is the highlighter's and the consumer's concern. Under
|
|
64
|
+
* either richer syntax, `\"` and `\\` write a literal quote and backslash.
|
|
65
|
+
*/
|
|
66
|
+
/** Fields every token carries, whatever its kind. */
|
|
67
|
+
type FilterTokenBase = {
|
|
68
|
+
/** Offset of the token's first character in the source query. */
|
|
69
|
+
start: number;
|
|
70
|
+
/** Offset one past the token's last character in the source query. */
|
|
71
|
+
end: number;
|
|
72
|
+
/** True when the token was written with a leading `-`. */
|
|
73
|
+
negated: boolean;
|
|
74
|
+
};
|
|
75
|
+
/** A bare search term, matched against the item search corpus. */
|
|
76
|
+
type FreeTextToken = FilterTokenBase & {
|
|
77
|
+
kind: "text";
|
|
78
|
+
/** The term with its negation prefix and quotes removed. */
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
/** One comma-separated member of a qualifier's value list. */
|
|
82
|
+
type FacetValueMember = {
|
|
83
|
+
/**
|
|
84
|
+
* The canonical value for enumerated keys, the written value for free-text
|
|
85
|
+
* keys, and the written value again when no alias matched.
|
|
86
|
+
*/
|
|
87
|
+
value: string;
|
|
88
|
+
/** The member exactly as written, with quotes removed. */
|
|
89
|
+
rawValue: string;
|
|
90
|
+
/** False only when the key is enumerated and the member matched no alias. */
|
|
91
|
+
isKnownValue: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Offset of the member's first character in the source query. A quoted
|
|
94
|
+
* member's span covers its quote characters too.
|
|
95
|
+
*/
|
|
96
|
+
start: number;
|
|
97
|
+
/** Offset one past the member's last character in the source query. */
|
|
98
|
+
end: number;
|
|
99
|
+
};
|
|
100
|
+
/** A `key:value` qualifier whose key resolved to a known facet. */
|
|
101
|
+
type FacetToken = FilterTokenBase & {
|
|
102
|
+
kind: "facet";
|
|
103
|
+
/** The canonical key the written spelling resolved to. */
|
|
104
|
+
key: string;
|
|
105
|
+
/** The whole value exactly as written, with quotes removed. */
|
|
106
|
+
rawValue: string;
|
|
107
|
+
/**
|
|
108
|
+
* The value's members, which OR together: every unquoted comma splits one
|
|
109
|
+
* off for a list key (`is:active,pending`), a quoted comma stays inside its
|
|
110
|
+
* member (`name:"a,b",c`), and a prose key keeps one member. Empty while the
|
|
111
|
+
* value is empty — the user is still typing.
|
|
112
|
+
*/
|
|
113
|
+
members: FacetValueMember[];
|
|
114
|
+
/**
|
|
115
|
+
* False only when some member is unknown on an enumerated key. An empty
|
|
116
|
+
* value is never invalid — the user is still typing.
|
|
117
|
+
*/
|
|
118
|
+
isKnownValue: boolean;
|
|
119
|
+
/** Offset of the separating `:` in the source query. */
|
|
120
|
+
colonIndex: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* The OR operator between two filter groups. Only the bare, unquoted spellings
|
|
124
|
+
* `OR` and `||` count: a quoted `"OR"` and a lowercase `or` stay search terms.
|
|
125
|
+
*/
|
|
126
|
+
type OrToken = FilterTokenBase & {
|
|
127
|
+
kind: "or";
|
|
128
|
+
/** The operator exactly as written. */
|
|
129
|
+
text: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The AND operator, written `AND` or `&&`, unquoted. Conjunction is already
|
|
133
|
+
* implicit between tokens, so this token only spells it out.
|
|
134
|
+
*/
|
|
135
|
+
type AndToken = FilterTokenBase & {
|
|
136
|
+
kind: "and";
|
|
137
|
+
/** The operator exactly as written. */
|
|
138
|
+
text: string;
|
|
139
|
+
};
|
|
140
|
+
/** One token of a parsed filter query. */
|
|
141
|
+
type FilterToken = FreeTextToken | FacetToken | OrToken | AndToken;
|
|
142
|
+
/**
|
|
143
|
+
* Parses a filter query into tokens. Never throws, on any input.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* parseFilterQuery(grammar, 'name:api -is:active,pending acme');
|
|
148
|
+
* // => [{ kind: "facet", key: "name", members: [{ value: "api", … }], … },
|
|
149
|
+
* // { kind: "facet", key: "is", members: [{ value: "active", … }, { value: "pending", … }], negated: true, … },
|
|
150
|
+
* // { kind: "text", text: "acme", … }]
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
declare function parseFilterQuery<Item>(grammar: FilterGrammar<Item>, query: string): FilterToken[];
|
|
154
|
+
/**
|
|
155
|
+
* Reports whether a query holds at least one `key:value` qualifier.
|
|
156
|
+
*
|
|
157
|
+
* The filtered-empty states pick their advice from this. A structured query
|
|
158
|
+
* that matched nothing needs advice about relaxing a filter, and a free-text
|
|
159
|
+
* one needs advice about spelling.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* queryUsesQualifiers(grammar, "is:active acme"); // => true
|
|
164
|
+
* queryUsesQualifiers(grammar, "acme"); // => false
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function queryUsesQualifiers<Item>(grammar: FilterGrammar<Item>, query: string): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Writes a value so it parses back to itself: quoted when it would otherwise
|
|
170
|
+
* split into several tokens, with each quote and backslash escaped.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* quoteFilterValue("staging api"); // => "\"staging api\""
|
|
175
|
+
* quoteFilterValue("acme"); // => "acme"
|
|
176
|
+
* quoteFilterValue('/a"b'); // => "\"/a\\\"b\""
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function quoteFilterValue(value: string): string;
|
|
180
|
+
/**
|
|
181
|
+
* Writes a qualifier in its canonical form. Accepting a suggestion always
|
|
182
|
+
* replaces what was typed with this, so `-DESC:api` becomes `-description:api`.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* formatFacet({ key: "description", value: "staging api", negated: true });
|
|
187
|
+
* // => '-description:"staging api"'
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
declare function formatFacet({ key, value, negated }: {
|
|
191
|
+
key: string;
|
|
192
|
+
value: string;
|
|
193
|
+
negated: boolean;
|
|
194
|
+
}): string;
|
|
195
|
+
/**
|
|
196
|
+
* Adds a qualifier to a query, or takes it out when the query already has it.
|
|
197
|
+
* Use it for a value that filters when the person clicks it, such as a status
|
|
198
|
+
* badge in a table row.
|
|
199
|
+
*
|
|
200
|
+
* The key and the value resolve through the grammar's aliases, so `is:personal`
|
|
201
|
+
* counts as `is:private`. The opposite qualifier gives way: `-is:shared`
|
|
202
|
+
* becomes `is:shared`. A list such as `is:shared,private` stays as written. An
|
|
203
|
+
* `OR` or `AND` beside a removed qualifier goes with it, so no operator dangles.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* toggleFacet({ grammar, query: "api", facet: { key: "is", value: "shared", negated: false } });
|
|
208
|
+
* // => "api is:shared"
|
|
209
|
+
* toggleFacet({ grammar, query: "api is:shared", facet: { key: "is", value: "shared", negated: false } });
|
|
210
|
+
* // => "api"
|
|
211
|
+
* toggleFacet({ grammar, query: "-is:shared", facet: { key: "is", value: "shared", negated: false } });
|
|
212
|
+
* // => "is:shared"
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function toggleFacet<Item>({ grammar, query, facet }: {
|
|
216
|
+
grammar: FilterGrammar<Item>;
|
|
217
|
+
query: string;
|
|
218
|
+
facet: {
|
|
219
|
+
key: string;
|
|
220
|
+
value: string;
|
|
221
|
+
negated: boolean;
|
|
222
|
+
};
|
|
223
|
+
}): string;
|
|
224
|
+
/**
|
|
225
|
+
* Finds the token the caret sits in or against.
|
|
226
|
+
*
|
|
227
|
+
* A caret touching either edge belongs to that token, which is what makes
|
|
228
|
+
* suggestions keep refining the word being typed. A caret in whitespace belongs
|
|
229
|
+
* to no token, and the suggestions fall back to offering every key.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* const tokens = parseFilterQuery(grammar, "is:active acme");
|
|
234
|
+
* findTokenAtCaret(tokens, 3)?.key; // => "is"
|
|
235
|
+
* findTokenAtCaret(tokens, 6); // => undefined — the caret is in the space
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function findTokenAtCaret(tokens: readonly FilterToken[], caretIndex: number): FilterToken | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Reports whether the caret sits in a qualifier's value, past its `:`.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const [token] = parseFilterQuery(grammar, "is:active");
|
|
245
|
+
* isCaretInFacetValue(token, 4); // => true
|
|
246
|
+
* isCaretInFacetValue(token, 2); // => false — still in the key
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function isCaretInFacetValue(token: FilterToken, caretIndex: number): token is FacetToken;
|
|
250
|
+
/**
|
|
251
|
+
* Filters items with an already-parsed query, preserving the input order.
|
|
252
|
+
*
|
|
253
|
+
* Take this overload when you already hold the tokens. The `context` defaults
|
|
254
|
+
* to the clock at the call.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* filterItemsByTokens({ grammar, items, tokens: parseFilterQuery(grammar, "is:active") });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare function filterItemsByTokens<Item extends object>({ grammar, items, tokens, context }: {
|
|
262
|
+
grammar: FilterGrammar<Item>;
|
|
263
|
+
items: Item[];
|
|
264
|
+
tokens: readonly FilterToken[];
|
|
265
|
+
context?: FilterMatchContext;
|
|
266
|
+
}): Item[];
|
|
267
|
+
/**
|
|
268
|
+
* Filters items with a raw `?q=` string, preserving the input order.
|
|
269
|
+
*
|
|
270
|
+
* An empty or whitespace-only query returns every item: nothing was asked.
|
|
271
|
+
* The `context` defaults to the clock at the call. Pass `{ now }` from a
|
|
272
|
+
* ticking state hook when a matcher reads the clock and the pass is memoized.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* filterItemsByQuery({ grammar, items, query: "is:active -staging acme" });
|
|
277
|
+
* filterItemsByQuery({ grammar, items, query: "is:expired", context: { now: clockTick } });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function filterItemsByQuery<Item extends object>({ grammar, items, query, context }: {
|
|
281
|
+
grammar: FilterGrammar<Item>;
|
|
282
|
+
items: Item[];
|
|
283
|
+
query: string;
|
|
284
|
+
context?: FilterMatchContext;
|
|
285
|
+
}): Item[];
|
|
286
|
+
/**
|
|
287
|
+
* Counts the items a raw `?q=` string matches, without building the filtered
|
|
288
|
+
* array. Counts are memoized (see {@link matchCountCaches}), so a count whose
|
|
289
|
+
* matcher reads the clock — `is:expired` — can lag until a refetch replaces
|
|
290
|
+
* the items.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* countItemsByQuery(grammar, items, "is:active -staging"); // => 42
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function countItemsByQuery<Item extends object>(grammar: FilterGrammar<Item>, items: Item[], query: string): number;
|
|
298
|
+
/**
|
|
299
|
+
* The helpers a natural-language search needs: a description of the filter
|
|
300
|
+
* language to send to a model, and a check of the query the model sends back.
|
|
301
|
+
* Neither one calls a model. The host owns the request, so this module stays
|
|
302
|
+
* free of React and of any network code.
|
|
303
|
+
*/
|
|
304
|
+
/** One qualifier key, as a model reads it. */
|
|
305
|
+
type FilterKeyDescription = {
|
|
306
|
+
/** The canonical key, as it is written before the `:`. */
|
|
307
|
+
key: string;
|
|
308
|
+
/** What the key filters by. */
|
|
309
|
+
description: string;
|
|
310
|
+
/**
|
|
311
|
+
* The only values the key accepts, with what each one means. Absent for a
|
|
312
|
+
* free-text key, which takes any text.
|
|
313
|
+
*/
|
|
314
|
+
values?: {
|
|
315
|
+
value: string;
|
|
316
|
+
description?: string;
|
|
317
|
+
}[];
|
|
318
|
+
/** Whether `-key:value` excludes on this key. */
|
|
319
|
+
negatable: boolean;
|
|
320
|
+
/** Whether `key:a,b` matches either value. */
|
|
321
|
+
acceptsList: boolean;
|
|
322
|
+
};
|
|
323
|
+
/** The whole filter language, as plain data that serializes to JSON. */
|
|
324
|
+
type FilterGrammarDescription = {
|
|
325
|
+
/** The syntax the grammar honors. */
|
|
326
|
+
syntax: FilterSyntax;
|
|
327
|
+
/** The qualifier keys, in the order the grammar lists them. */
|
|
328
|
+
keys: FilterKeyDescription[];
|
|
329
|
+
/** The syntax rules, one sentence each, for a system prompt. */
|
|
330
|
+
rules: string[];
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Describes a grammar as plain data for a language model: each key, its
|
|
334
|
+
* values, and the syntax rules the grammar honors. Send it with the person's
|
|
335
|
+
* words, and ask the model for one query in this language.
|
|
336
|
+
*
|
|
337
|
+
* The description holds no matchers and no aliases: a model that writes the
|
|
338
|
+
* canonical spelling writes a query every surface reads the same way.
|
|
339
|
+
*
|
|
340
|
+
* @preview The API is not stable and may change. There may also be bugs.
|
|
341
|
+
* Please file an issue at https://github.com/ngrok/mantle/issues if you find any.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* const description = describeFilterGrammar(projectFilterGrammar);
|
|
346
|
+
* const system = `Translate a request into one filter query.\n${JSON.stringify(description)}`;
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare function describeFilterGrammar<Item>(grammar: FilterGrammar<Item>): FilterGrammarDescription;
|
|
350
|
+
/** One problem in a query that a model or a person wrote. */
|
|
351
|
+
type FilterQueryProblem = {
|
|
352
|
+
/** A `key:` that the grammar does not define. The parser reads it as free text. */
|
|
353
|
+
kind: "unknown-key";
|
|
354
|
+
key: string;
|
|
355
|
+
start: number;
|
|
356
|
+
end: number;
|
|
357
|
+
} | {
|
|
358
|
+
/** A value that a key with listed values does not accept. It matches no item. */
|
|
359
|
+
kind: "unknown-value";
|
|
360
|
+
key: string;
|
|
361
|
+
value: string;
|
|
362
|
+
start: number;
|
|
363
|
+
end: number;
|
|
364
|
+
} | {
|
|
365
|
+
/** A `-key:` on a key that cannot exclude. It matches no item. */
|
|
366
|
+
kind: "not-negatable";
|
|
367
|
+
key: string;
|
|
368
|
+
start: number;
|
|
369
|
+
end: number;
|
|
370
|
+
} | {
|
|
371
|
+
/** A bare term in a `"conjunction"` query. The executor cannot run it. */
|
|
372
|
+
kind: "unsupported-term";
|
|
373
|
+
text: string;
|
|
374
|
+
start: number;
|
|
375
|
+
end: number;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Finds the parts of a query that do not mean what they look like: an
|
|
379
|
+
* unknown key, an unknown value, an exclusion on a key that cannot exclude,
|
|
380
|
+
* or a bare term that a `"conjunction"` grammar cannot run. Check a query
|
|
381
|
+
* that a model wrote before you show it, so an invented filter never empties
|
|
382
|
+
* the list without a reason.
|
|
383
|
+
*
|
|
384
|
+
* A quoted `"key:value"` and a URL are free text on purpose, so neither one
|
|
385
|
+
* is a problem.
|
|
386
|
+
*
|
|
387
|
+
* @preview The API is not stable and may change. There may also be bugs.
|
|
388
|
+
* Please file an issue at https://github.com/ngrok/mantle/issues if you find any.
|
|
389
|
+
*
|
|
390
|
+
* @returns the problems in query order, or an empty array for a clean query.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```ts
|
|
394
|
+
* checkFilterQuery(grammar, "is:shared owner:me");
|
|
395
|
+
* // => [{ kind: "unknown-key", key: "owner", start: 10, end: 18 }]
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
declare function checkFilterQuery<Item>(grammar: FilterGrammar<Item>, query: string): FilterQueryProblem[];
|
|
399
|
+
export { type AndToken, type FacetToken, type FacetValueMember, type FilterGrammar, type FilterGrammarDescription, type FilterKeyDefinition, type FilterKeyDescription, type FilterMatchContext, type FilterQueryProblem, type FilterSuggestion, type FilterSuggestionSection, type FilterSuggestions, type FilterSuggestionsOptions, type FilterSyntax, type FilterToken, type FilterValueDefinition, type FreeTextToken, type HighlightSegment, type HighlightSegmentKind, type OrToken, type RemoteFilterGrammarOptions, type RemoteFilterKeyDefinition, type ValueCandidate, acceptsValueList, checkFilterQuery, countItemsByQuery, defineRemoteFilterGrammar, describeFilterGrammar, filterItemsByQuery, filterItemsByTokens, findTokenAtCaret, formatFacet, getFilterKeyDefinition, getFilterSuggestions, getFilterSyntax, getHighlightSegments, getValueCandidates, isCaretInFacetValue, parseFilterQuery, queryUsesQualifiers, quoteFilterValue, resolveFilterKey, resolveFilterValue, toggleFacet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _,y as v}from"./suggestions-Ciz2vaJO.js";function y(t){let n=e(t),r=t.keys.map(e=>({key:e.key,description:e.description,...e.values==null?{}:{values:e.values.map(({value:e,description:t})=>({value:e,description:t}))},negatable:n!==`qualifiers`&&e.negatable!==!1,acceptsList:l(t,e)}));return{syntax:n,keys:r,rules:["`key:value` keeps the items whose key has that value.",`A key with listed values accepts only those values.`,r.some(e=>e.negatable)&&"`-key:value` excludes the items that match.",r.some(e=>e.acceptsList)&&"`key:a,b` keeps the items that match either value.",n!==`qualifiers`&&'Wrap a value that has spaces in double quotes: `key:"a b"`.',n===`full`&&"`OR` between two groups keeps the items that match either group.",`Qualifiers separated by spaces must all match.`,n===`conjunction`?`Write only qualifiers. The search cannot read other words.`:`Other words search the item text.`].filter(e=>e!==!1)}}const b=/^[\p{L}\p{N}_-]+$/u;function x({query:e,start:t,end:n,quotes:r}){let i=!1,a=``;for(let o=t;o<n;o+=1){let t=e.charAt(o);if(r&&t===`\\`&&/["\\]/.test(e.charAt(o+1)))a+=e.charAt(o+1),o+=1;else if(r&&t===`"`)i=!i;else if(t===`:`&&!i)return!e.startsWith(`//`,o+1)&&b.test(a)?a:null;else a+=t}return null}function S(t,n){let r=[],i=e(t);for(let e of g(t,n))if(e.kind===`text`){let{start:t,end:a}=e,o=x({query:n,start:t+ +!!e.negated,end:a,quotes:i!==`qualifiers`});o==null?i===`conjunction`&&r.push({kind:`unsupported-term`,text:e.text,start:t,end:a}):r.push({kind:`unknown-key`,key:o,start:t,end:a})}else if(e.kind===`facet`){e.negated&&a(t,e.key)?.negatable===!1&&r.push({kind:`not-negatable`,key:e.key,start:e.start,end:e.end});for(let t of e.members)t.isKnownValue||r.push({kind:`unknown-value`,key:e.key,value:t.value,start:t.start,end:t.end})}return r}export{l as acceptsValueList,S as checkFilterQuery,p as countItemsByQuery,o as defineRemoteFilterGrammar,y as describeFilterGrammar,s as filterItemsByQuery,t as filterItemsByTokens,m as findTokenAtCaret,n as formatFacet,a as getFilterKeyDefinition,h as getFilterSuggestions,e as getFilterSyntax,d as getHighlightSegments,u as getValueCandidates,c as isCaretInFacetValue,g as parseFilterQuery,r as queryUsesQualifiers,i as quoteFilterValue,_ as resolveFilterKey,v as resolveFilterValue,f as toggleFacet};
|