@wallarm-org/design-system 4.7.0 → 4.8.0-rc-feat-parser.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.
Files changed (120) hide show
  1. package/dist/components/DropdownMenu/DropdownMenu.d.ts +2 -0
  2. package/dist/components/DropdownMenu/DropdownMenu.js +84 -71
  3. package/dist/components/DropdownMenu/DropdownMenuItemDescription.js +1 -1
  4. package/dist/components/FilterInput/hooks/useFilterInputAutocomplete/useFilterInputAutocomplete.js +1 -1
  5. package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.d.ts +14 -0
  6. package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.js +209 -0
  7. package/dist/components/Rules/PointSelector/MatchStep.d.ts +15 -0
  8. package/dist/components/Rules/PointSelector/MatchStep.js +186 -0
  9. package/dist/components/Rules/PointSelector/MenuFooterHints.d.ts +16 -0
  10. package/dist/components/Rules/PointSelector/MenuFooterHints.js +177 -0
  11. package/dist/components/Rules/PointSelector/PointPreview.d.ts +10 -0
  12. package/dist/components/Rules/PointSelector/PointPreview.js +88 -0
  13. package/dist/components/Rules/PointSelector/PointSelector.d.ts +17 -0
  14. package/dist/components/Rules/PointSelector/PointSelector.js +937 -0
  15. package/dist/components/Rules/PointSelector/PointSelectorEmptyState.d.ts +12 -0
  16. package/dist/components/Rules/PointSelector/PointSelectorEmptyState.js +173 -0
  17. package/dist/components/Rules/PointSelector/PointSelectorError.d.ts +31 -0
  18. package/dist/components/Rules/PointSelector/PointSelectorError.js +275 -0
  19. package/dist/components/Rules/PointSelector/PointSelectorInput.d.ts +20 -0
  20. package/dist/components/Rules/PointSelector/PointSelectorInput.js +130 -0
  21. package/dist/components/Rules/PointSelector/PointSelectorMenu.d.ts +31 -0
  22. package/dist/components/Rules/PointSelector/PointSelectorMenu.js +317 -0
  23. package/dist/components/Rules/PointSelector/PointSelectorSkeleton.d.ts +8 -0
  24. package/dist/components/Rules/PointSelector/PointSelectorSkeleton.js +73 -0
  25. package/dist/components/Rules/PointSelector/SampleRequest.d.ts +14 -0
  26. package/dist/components/Rules/PointSelector/SampleRequest.js +116 -0
  27. package/dist/components/Rules/PointSelector/StepMenu.d.ts +40 -0
  28. package/dist/components/Rules/PointSelector/StepMenu.js +210 -0
  29. package/dist/components/Rules/PointSelector/VersionWarning.d.ts +26 -0
  30. package/dist/components/Rules/PointSelector/VersionWarning.js +231 -0
  31. package/dist/components/Rules/PointSelector/WhereBar.d.ts +48 -0
  32. package/dist/components/Rules/PointSelector/WhereBar.js +263 -0
  33. package/dist/components/Rules/PointSelector/classes.d.ts +28 -0
  34. package/dist/components/Rules/PointSelector/classes.js +22 -0
  35. package/dist/components/Rules/PointSelector/index.d.ts +20 -0
  36. package/dist/components/Rules/PointSelector/index.js +18 -0
  37. package/dist/components/Rules/PointSelector/liftLayer.d.ts +8 -0
  38. package/dist/components/Rules/PointSelector/liftLayer.js +4 -0
  39. package/dist/components/Rules/PointSelector/sampleValue.d.ts +6 -0
  40. package/dist/components/Rules/PointSelector/sampleValue.js +51 -0
  41. package/dist/components/Rules/PointSelector/sdkBridge.d.ts +508 -0
  42. package/dist/components/Rules/PointSelector/sdkBridge.js +339 -0
  43. package/dist/components/Rules/PointSelector/types.d.ts +304 -0
  44. package/dist/components/Rules/PointSelector/types.js +0 -0
  45. package/dist/components/Rules/PointSelector/usePointSelector.d.ts +161 -0
  46. package/dist/components/Rules/PointSelector/usePointSelector.js +1088 -0
  47. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.d.ts +28 -0
  48. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.js +208 -0
  49. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.d.ts +23 -0
  50. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.js +950 -0
  51. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.d.ts +21 -0
  52. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.js +110 -0
  53. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.d.ts +20 -0
  54. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.js +31 -0
  55. package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.d.ts +23 -0
  56. package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.js +131 -0
  57. package/dist/components/Rules/RuleBuilder/ActionEditor/classes.d.ts +17 -0
  58. package/dist/components/Rules/RuleBuilder/ActionEditor/classes.js +14 -0
  59. package/dist/components/Rules/RuleBuilder/ActionEditor/index.d.ts +6 -0
  60. package/dist/components/Rules/RuleBuilder/ActionEditor/index.js +6 -0
  61. package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.d.ts +24 -0
  62. package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.js +245 -0
  63. package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.d.ts +15 -0
  64. package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.js +691 -0
  65. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.d.ts +19 -0
  66. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.js +72 -0
  67. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.d.ts +27 -0
  68. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.js +407 -0
  69. package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.d.ts +14 -0
  70. package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.js +269 -0
  71. package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.d.ts +25 -0
  72. package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.js +99 -0
  73. package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.d.ts +14 -0
  74. package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.js +118 -0
  75. package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.d.ts +14 -0
  76. package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.js +446 -0
  77. package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.d.ts +14 -0
  78. package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.js +266 -0
  79. package/dist/components/Rules/RuleBuilder/ConditionTree/classes.d.ts +35 -0
  80. package/dist/components/Rules/RuleBuilder/ConditionTree/classes.js +57 -0
  81. package/dist/components/Rules/RuleBuilder/ConditionTree/index.d.ts +15 -0
  82. package/dist/components/Rules/RuleBuilder/ConditionTree/index.js +10 -0
  83. package/dist/components/Rules/RuleBuilder/RuleBuilder.d.ts +67 -0
  84. package/dist/components/Rules/RuleBuilder/RuleBuilder.js +366 -0
  85. package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.d.ts +32 -0
  86. package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.js +420 -0
  87. package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.d.ts +27 -0
  88. package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.js +446 -0
  89. package/dist/components/Rules/RuleBuilder/Summary/index.d.ts +7 -0
  90. package/dist/components/Rules/RuleBuilder/Summary/index.js +2 -0
  91. package/dist/components/Rules/RuleBuilder/classes.d.ts +19 -0
  92. package/dist/components/Rules/RuleBuilder/classes.js +18 -0
  93. package/dist/components/Rules/RuleBuilder/index.d.ts +55 -0
  94. package/dist/components/Rules/RuleBuilder/index.js +11 -0
  95. package/dist/components/Rules/RuleBuilder/models/actionModel.d.ts +31 -0
  96. package/dist/components/Rules/RuleBuilder/models/actionModel.js +276 -0
  97. package/dist/components/Rules/RuleBuilder/models/conditionModel.d.ts +95 -0
  98. package/dist/components/Rules/RuleBuilder/models/conditionModel.js +418 -0
  99. package/dist/components/Rules/RuleBuilder/models/index.d.ts +3 -0
  100. package/dist/components/Rules/RuleBuilder/models/index.js +3 -0
  101. package/dist/components/Rules/RuleBuilder/models/validation.d.ts +176 -0
  102. package/dist/components/Rules/RuleBuilder/models/validation.js +242 -0
  103. package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.d.ts +27 -0
  104. package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.js +92 -0
  105. package/dist/components/Rules/RuleBuilder/shared/index.d.ts +1 -0
  106. package/dist/components/Rules/RuleBuilder/shared/index.js +1 -0
  107. package/dist/components/Rules/RuleBuilder/types.d.ts +384 -0
  108. package/dist/components/Rules/RuleBuilder/types.js +0 -0
  109. package/dist/components/Rules/RuleBuilder/utils/constants.d.ts +65 -0
  110. package/dist/components/Rules/RuleBuilder/utils/constants.js +356 -0
  111. package/dist/components/Rules/RuleBuilder/utils/extractBindings.d.ts +48 -0
  112. package/dist/components/Rules/RuleBuilder/utils/extractBindings.js +42 -0
  113. package/dist/components/Rules/RuleBuilder/utils/helpers.d.ts +92 -0
  114. package/dist/components/Rules/RuleBuilder/utils/helpers.js +54 -0
  115. package/dist/components/Rules/RuleBuilder/utils/index.d.ts +2 -0
  116. package/dist/components/Rules/RuleBuilder/utils/index.js +2 -0
  117. package/dist/index.d.ts +2 -0
  118. package/dist/index.js +2 -0
  119. package/dist/metadata/components.json +100 -2
  120. package/package.json +4 -1
@@ -0,0 +1,1088 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { CONDITIONS, PICK_LABELS, checkOf, describe, fuzzyScore, isCaseFixed, isKeyStep, isPositionStep, listTitle, nameRows, nounOf, pickByNumber, takesValue } from "@wallarm-org/rules-lib/ui";
3
+ import { checkSegmentsDirectly, completePoint, completionToMenuRow, getNextSegmentOptions, normalizeSegment, renderSegments, sdkCombine, sdkSeg } from "./sdkBridge.js";
4
+ const ALL = '*all';
5
+ const ANY = 'any';
6
+ const listed = (p)=>p.choices.filter((c)=>c !== ANY);
7
+ const isDigit = (key)=>/^[0-9]$/.test(key);
8
+ const usePointSelector = ({ context, value, onChange, initialStage, pointOnly, proton, profile, keys, keysDebounceMs = 300, onShowKeyboardHelp })=>{
9
+ const segments = value.segments;
10
+ const keysCache = useRef(new Map());
11
+ const inFlightFetches = useRef(new Map());
12
+ const [loadingKeys, setLoadingKeys] = useState(false);
13
+ const [recomputeTick, setRecomputeTick] = useState(0);
14
+ const triggerRecomplete = useCallback(()=>{
15
+ setLoadingKeys(false);
16
+ setRecomputeTick((t)=>t + 1);
17
+ }, []);
18
+ const nextCache = useRef(new Map());
19
+ const nextItemsRef = useRef(null);
20
+ const syncKeysProvider = useMemo(()=>{
21
+ if (Array.isArray(keys)) return keys;
22
+ if (!keys) return;
23
+ const timeoutRefs = new Map();
24
+ return (parent)=>{
25
+ const cached = keysCache.current.get(parent);
26
+ if (void 0 !== cached) return cached;
27
+ const result = keys(parent);
28
+ if (Array.isArray(result)) {
29
+ keysCache.current.set(parent, result);
30
+ return result;
31
+ }
32
+ const inFlight = inFlightFetches.current.get(parent);
33
+ if (inFlight) return [];
34
+ const existingTimeout = timeoutRefs.get(parent);
35
+ if (existingTimeout) clearTimeout(existingTimeout);
36
+ const timeout = setTimeout(()=>{
37
+ timeoutRefs.delete(parent);
38
+ setLoadingKeys(true);
39
+ const controller = new AbortController();
40
+ inFlightFetches.current.set(parent, {
41
+ promise: result,
42
+ abort: ()=>controller.abort()
43
+ });
44
+ result.then((fetchedKeys)=>{
45
+ if (controller.signal.aborted) return;
46
+ keysCache.current.set(parent, fetchedKeys);
47
+ inFlightFetches.current.delete(parent);
48
+ triggerRecomplete();
49
+ }, (_error)=>{
50
+ if (controller.signal.aborted) return;
51
+ keysCache.current.set(parent, []);
52
+ inFlightFetches.current.delete(parent);
53
+ setLoadingKeys(false);
54
+ });
55
+ }, keysDebounceMs);
56
+ timeoutRefs.set(parent, timeout);
57
+ return [];
58
+ };
59
+ }, [
60
+ keys,
61
+ keysDebounceMs,
62
+ triggerRecomplete
63
+ ]);
64
+ const [ui, setUi] = useState(()=>({
65
+ stage: pointOnly ? 'point' : initialStage ?? (value.condition ? 'value' : 'point'),
66
+ query: '',
67
+ highlight: 0,
68
+ menuOpen: false,
69
+ nameStep: null,
70
+ nameIgnoreCase: false,
71
+ pickStep: null,
72
+ picked: [],
73
+ conditionQuery: '',
74
+ conditionHighlight: 0,
75
+ focusTick: 0,
76
+ focusTarget: value.condition ? 'value' : 'bar',
77
+ sdkError: null,
78
+ incomplete: false,
79
+ canonicalInfo: null
80
+ }));
81
+ useEffect(()=>()=>{
82
+ for (const fetch of inFlightFetches.current.values())fetch.abort();
83
+ inFlightFetches.current.clear();
84
+ }, []);
85
+ const patch = (p)=>setUi((s)=>({
86
+ ...s,
87
+ ...p
88
+ }));
89
+ const focus = (target, p = {})=>setUi((s)=>({
90
+ ...s,
91
+ ...p,
92
+ focusTarget: target,
93
+ focusTick: s.focusTick + 1
94
+ }));
95
+ const setSegments = (next, p = {}, target = 'bar')=>{
96
+ const result = checkSegmentsDirectly(proton, next, {
97
+ profile: profile ?? 'tree',
98
+ context
99
+ });
100
+ let sdkError = null;
101
+ let canonical;
102
+ let incomplete = false;
103
+ let canonicalInfo = null;
104
+ if (result.ok) {
105
+ canonical = result.canonical;
106
+ if (canonical && proton) {
107
+ const built = renderSegments(proton, next);
108
+ if (built !== canonical) canonicalInfo = {
109
+ built,
110
+ canonical
111
+ };
112
+ }
113
+ } else {
114
+ incomplete = result.error.incomplete;
115
+ const isTransportError = 'TRANSPORT_ERROR' === result.error.code;
116
+ sdkError = {
117
+ code: result.error.code,
118
+ message: result.error.message,
119
+ layer: result.error.layer,
120
+ span: void 0,
121
+ incomplete,
122
+ fixes: result.error.fixes?.map((f)=>({
123
+ label: f.label,
124
+ replace: f.replace,
125
+ insert: f.insert
126
+ })),
127
+ transport: isTransportError
128
+ };
129
+ }
130
+ const errorState = {
131
+ sdkError,
132
+ incomplete,
133
+ canonicalInfo
134
+ };
135
+ const canonicalVersion = proton ? proton.version().canonical : null;
136
+ onChange({
137
+ ...value,
138
+ segments: next,
139
+ canonical: canonical ?? null,
140
+ canonicalVersion
141
+ });
142
+ let only = null;
143
+ if ('bar' === target && proton) {
144
+ const nextItems = getNextSegmentOptions(proton, next, context, syncKeysProvider, profile ?? 'tree');
145
+ nextItemsRef.current = {
146
+ segments: next,
147
+ items: nextItems
148
+ };
149
+ const lastSeg = next[next.length - 1];
150
+ const justAddedKey = lastSeg && ('key' === lastSeg.kind || 'attr' === lastSeg.kind) && 'value' in lastSeg && !('role' in lastSeg);
151
+ if (!justAddedKey && 1 === nextItems.length && nextItems[0]?.open) {
152
+ const item = nextItems[0];
153
+ let placeholder = `Enter ${item.label.toLowerCase()}`;
154
+ let allowsCase = false;
155
+ let showsStarHint = false;
156
+ const category = item.category;
157
+ switch(category){
158
+ case 'key':
159
+ allowsCase = true;
160
+ showsStarHint = true;
161
+ break;
162
+ case 'attr':
163
+ placeholder = item.label.includes('@') ? 'Enter attribute name (@id, @class, ...)' : 'Enter attribute';
164
+ allowsCase = false;
165
+ showsStarHint = false;
166
+ break;
167
+ default:
168
+ allowsCase = false;
169
+ showsStarHint = false;
170
+ }
171
+ only = {
172
+ label: item.label,
173
+ placeholder,
174
+ segs: [],
175
+ allowsCase,
176
+ showsStarHint,
177
+ sdkItem: item
178
+ };
179
+ }
180
+ }
181
+ focus(only ? 'name' : target, {
182
+ query: '',
183
+ highlight: 0,
184
+ nameStep: only,
185
+ nameIgnoreCase: false,
186
+ pickStep: null,
187
+ picked: [],
188
+ ...errorState,
189
+ ...p
190
+ });
191
+ };
192
+ const sdkCompletionItems = useMemo(()=>{
193
+ if (!proton) return [];
194
+ if (nextItemsRef.current?.segments === segments) {
195
+ const items = nextItemsRef.current.items;
196
+ return Array.isArray(items) ? items : [];
197
+ }
198
+ const parentPoint = renderSegments(proton, segments);
199
+ const cached = nextCache.current.get(parentPoint);
200
+ if (void 0 !== cached) {
201
+ const items = Array.isArray(cached) ? cached : [];
202
+ nextItemsRef.current = {
203
+ segments,
204
+ items
205
+ };
206
+ return items;
207
+ }
208
+ const items = getNextSegmentOptions(proton, segments, context, syncKeysProvider, profile ?? 'tree');
209
+ nextCache.current.set(parentPoint, items);
210
+ nextItemsRef.current = {
211
+ segments,
212
+ items
213
+ };
214
+ return items;
215
+ }, [
216
+ segments,
217
+ context,
218
+ proton,
219
+ syncKeysProvider,
220
+ profile,
221
+ recomputeTick
222
+ ]);
223
+ const { query, nameStep, pickStep, picked } = ui;
224
+ const numericQuery = !nameStep && /^\d+$/.test(query);
225
+ const pointStage = 'point' === ui.stage;
226
+ let items = [];
227
+ let status = loadingKeys ? 'Loading keys...' : '';
228
+ if (pointStage && pickStep) {
229
+ const all = {
230
+ kind: 'pick',
231
+ choice: ALL,
232
+ row: {
233
+ id: ALL,
234
+ number: 1,
235
+ label: 'All',
236
+ desc: listed(pickStep).map((c)=>PICK_LABELS[c]?.[0] ?? c).join(', '),
237
+ checked: listed(pickStep).every((c)=>picked.includes(c))
238
+ }
239
+ };
240
+ const choices = pickStep.choices.map((c, i)=>({
241
+ kind: 'pick',
242
+ choice: c,
243
+ row: {
244
+ id: c,
245
+ number: i + 2,
246
+ label: PICK_LABELS[c]?.[0] ?? c,
247
+ desc: PICK_LABELS[c]?.[1] ?? '',
248
+ checked: picked.includes(c)
249
+ }
250
+ }));
251
+ items = [
252
+ all,
253
+ ...choices
254
+ ];
255
+ if (query && !numericQuery) items = items.filter((it)=>fuzzyScore(query, `${it.row.label} ${it.row.id}`) > 0);
256
+ if (!items.length) status = `Nothing here matches "${query.trim()}".`;
257
+ } else if (pointStage && nameStep) if (nameStep.sdkItem && proton) {
258
+ const sdkItem = nameStep.sdkItem;
259
+ const currentPoint = renderSegments(proton, segments);
260
+ let partialInsert = sdkItem.insert || '';
261
+ partialInsert = partialInsert.includes('<cursor>') ? partialInsert.replace('<cursor>', query) : partialInsert.endsWith("['") ? `['${query}` : query;
262
+ const partialPoint = currentPoint + partialInsert;
263
+ try {
264
+ const completion = completePoint(proton, partialPoint, partialPoint.length, {
265
+ context,
266
+ profile: profile ?? 'tree',
267
+ keys: syncKeysProvider
268
+ });
269
+ if (completion && !completion.error) {
270
+ items = completion.items.map((item, i)=>{
271
+ const nameRow = {
272
+ id: item.key || `sdk-name-${i}`,
273
+ label: item.label,
274
+ desc: item.detail,
275
+ segs: [],
276
+ custom: 'dictionary' === item.source
277
+ };
278
+ return {
279
+ kind: 'name',
280
+ name: nameRow,
281
+ row: {
282
+ id: nameRow.id,
283
+ label: nameRow.label,
284
+ desc: nameRow.desc,
285
+ custom: nameRow.custom
286
+ }
287
+ };
288
+ });
289
+ status = 0 === items.length ? `No matches for "${query.trim()}".` : '';
290
+ } else {
291
+ const rows = nameRows(query, nameStep, true);
292
+ status = 0 === rows.length ? `No matches for "${query.trim()}".` : '';
293
+ items = rows.map((n)=>({
294
+ kind: 'name',
295
+ name: n,
296
+ row: {
297
+ id: n.id,
298
+ label: n.label,
299
+ desc: n.desc,
300
+ custom: n.custom
301
+ }
302
+ }));
303
+ }
304
+ } catch {
305
+ const rows = nameRows(query, nameStep, true);
306
+ status = 0 === rows.length ? `No matches for "${query.trim()}".` : '';
307
+ items = rows.map((n)=>({
308
+ kind: 'name',
309
+ name: n,
310
+ row: {
311
+ id: n.id,
312
+ label: n.label,
313
+ desc: n.desc,
314
+ custom: n.custom
315
+ }
316
+ }));
317
+ }
318
+ } else {
319
+ const rows = nameRows(query, nameStep, true);
320
+ status = 0 === rows.length ? `No matches for "${query.trim()}".` : '';
321
+ items = rows.map((n)=>({
322
+ kind: 'name',
323
+ name: n,
324
+ row: {
325
+ id: n.id,
326
+ label: n.label,
327
+ desc: n.desc,
328
+ custom: n.custom
329
+ }
330
+ }));
331
+ }
332
+ else if (pointStage) {
333
+ if (!sdkCompletionItems) {
334
+ const errorPoint = proton && segments.length > 0 ? renderSegments(proton, segments) : '';
335
+ const errorCheck = value.condition ? checkOf(value.condition, value.value, value.ignoreCase, errorPoint, context) : null;
336
+ return {
337
+ ui,
338
+ point: errorPoint,
339
+ check: errorCheck,
340
+ sentence: '',
341
+ reserved: false,
342
+ sdkError: null,
343
+ incomplete: false,
344
+ canonicalInfo: null,
345
+ loadingKeys,
346
+ pointStage: true,
347
+ menuOpen: false,
348
+ menuTitle: 'Error',
349
+ menuFooter: 'list',
350
+ rows: [],
351
+ highlightedId: null,
352
+ status: 'An error occurred',
353
+ pendingLabel: '',
354
+ nameStep: null,
355
+ nameInputPlaceholder: '',
356
+ nameAllowsCase: false,
357
+ nameShowsStarHint: false,
358
+ applyLabel: null,
359
+ conditionStage: false,
360
+ conditionRows: [],
361
+ conditionHighlight: 0,
362
+ conditionQuery: '',
363
+ valueStage: false,
364
+ allowsCase: false,
365
+ showsIgnoreCase: false,
366
+ showsStarHint: false,
367
+ showsProfilePicker: false
368
+ };
369
+ }
370
+ let baseItems = sdkCompletionItems.map((item, i)=>({
371
+ kind: 'option',
372
+ option: {
373
+ label: item.label,
374
+ desc: item.detail,
375
+ name: void 0,
376
+ pick: void 0,
377
+ segs: [],
378
+ done: false,
379
+ sdkItem: item
380
+ },
381
+ row: completionToMenuRow(item, i)
382
+ }));
383
+ const lastSeg = segments[segments.length - 1];
384
+ const canHaveDup = lastSeg && ('key' === lastSeg.kind || 'attr' === lastSeg.kind || 'index' === lastSeg.kind) && !('ord' in lastSeg) && !('separator' in lastSeg);
385
+ const canHaveRole = lastSeg && ('key' === lastSeg.kind || 'attr' === lastSeg.kind) && !('role' in lastSeg);
386
+ const dupRoleItems = [];
387
+ let offset = 0;
388
+ if (canHaveRole && proton) dupRoleItems.push({
389
+ kind: 'option',
390
+ option: {
391
+ label: 'Select key name',
392
+ desc: "Address the key's own text (e.g., 'Authorization' → the word itself)",
393
+ name: void 0,
394
+ pick: void 0,
395
+ segs: [],
396
+ done: false,
397
+ roleModifier: 'name'
398
+ },
399
+ row: {
400
+ id: 'role:name',
401
+ number: ++offset,
402
+ label: 'Key name [role:name]',
403
+ desc: "The key's own text as data"
404
+ }
405
+ });
406
+ if (canHaveDup && proton) dupRoleItems.push({
407
+ kind: 'option',
408
+ option: {
409
+ label: 'First duplicate',
410
+ desc: 'The first occurrence of this key (0-indexed)',
411
+ name: void 0,
412
+ pick: void 0,
413
+ segs: [],
414
+ done: false,
415
+ dupModifier: 0
416
+ },
417
+ row: {
418
+ id: 'dup:0',
419
+ number: ++offset,
420
+ label: 'First duplicate [dup:0]',
421
+ desc: 'Select the first occurrence'
422
+ }
423
+ }, {
424
+ kind: 'option',
425
+ option: {
426
+ label: 'Second duplicate',
427
+ desc: 'The second occurrence of this key (1-indexed)',
428
+ name: void 0,
429
+ pick: void 0,
430
+ segs: [],
431
+ done: false,
432
+ dupModifier: 1
433
+ },
434
+ row: {
435
+ id: 'dup:1',
436
+ number: ++offset,
437
+ label: 'Second duplicate [dup:1]',
438
+ desc: 'Select the second occurrence'
439
+ }
440
+ }, {
441
+ kind: 'option',
442
+ option: {
443
+ label: 'Last duplicate',
444
+ desc: 'The last occurrence of this key (negative index)',
445
+ name: void 0,
446
+ pick: void 0,
447
+ segs: [],
448
+ done: false,
449
+ dupModifier: -1
450
+ },
451
+ row: {
452
+ id: 'dup:-1',
453
+ number: ++offset,
454
+ label: 'Last duplicate [dup:-1]',
455
+ desc: 'Select the last occurrence'
456
+ }
457
+ }, {
458
+ kind: 'option',
459
+ option: {
460
+ label: 'All duplicates',
461
+ desc: 'Every occurrence of this key (universal quantifier)',
462
+ name: void 0,
463
+ pick: void 0,
464
+ segs: [],
465
+ done: false,
466
+ dupModifier: 'all'
467
+ },
468
+ row: {
469
+ id: 'dup:all',
470
+ number: ++offset,
471
+ label: 'All duplicates [dup:all]',
472
+ desc: 'All occurrences must satisfy'
473
+ }
474
+ }, {
475
+ kind: 'option',
476
+ option: {
477
+ label: 'Any duplicate',
478
+ desc: 'Any occurrence of this key (default behavior)',
479
+ name: void 0,
480
+ pick: void 0,
481
+ segs: [],
482
+ done: false,
483
+ dupModifier: 'any'
484
+ },
485
+ row: {
486
+ id: 'dup:any',
487
+ number: ++offset,
488
+ label: 'Any duplicate [dup:any]',
489
+ desc: 'Default: match any occurrence'
490
+ }
491
+ });
492
+ baseItems = baseItems.map((it, i)=>({
493
+ ...it,
494
+ row: {
495
+ ...it.row,
496
+ number: i + offset < 9 ? i + offset + 1 : void 0
497
+ }
498
+ }));
499
+ items = [
500
+ ...dupRoleItems,
501
+ ...baseItems
502
+ ];
503
+ if (query && !numericQuery) {
504
+ items = items.map((it)=>({
505
+ it,
506
+ score: fuzzyScore(query, `${it.row.label} ${it.row.desc}`)
507
+ })).filter((x)=>x.score > 0).sort((a, b)=>b.score - a.score).map((x)=>x.it);
508
+ if (!items.length && proton) {
509
+ const templateItem = sdkCompletionItems.find((item)=>item.open);
510
+ if (templateItem) {
511
+ const currentPoint = renderSegments(proton, segments);
512
+ let partialInsert = templateItem.insert || '';
513
+ partialInsert = partialInsert.includes('<cursor>') ? partialInsert.replace('<cursor>', query) : partialInsert.endsWith("['") ? `['${query}` : query;
514
+ const partialPoint = currentPoint + partialInsert;
515
+ try {
516
+ const completion = completePoint(proton, partialPoint, partialPoint.length, {
517
+ context,
518
+ profile: profile ?? 'tree',
519
+ keys: syncKeysProvider
520
+ });
521
+ if (completion && !completion.error && completion.items.length > 0) items = completion.items.slice(0, 1).filter((item)=>'dictionary' === item.source).map((item, i)=>{
522
+ const nameRow = {
523
+ id: item.key || `sdk-typed-${i}`,
524
+ label: item.label,
525
+ desc: `${templateItem.label}: ${item.detail}`,
526
+ segs: [],
527
+ custom: true
528
+ };
529
+ return {
530
+ kind: 'name',
531
+ name: nameRow,
532
+ row: {
533
+ id: nameRow.id,
534
+ label: nameRow.label,
535
+ desc: nameRow.desc,
536
+ custom: nameRow.custom
537
+ }
538
+ };
539
+ });
540
+ } catch {}
541
+ }
542
+ }
543
+ if (!items.length) status = `Nothing here matches "${query.trim()}". Backspace to clear.`;
544
+ }
545
+ const hasItems = sdkCompletionItems.length > 0;
546
+ if (!hasItems && segments.length) status = 'Nothing more to choose here. Press Next to set the condition.';
547
+ else if (segments.length > 0 && !query) status = 'Or press Next to set the condition.';
548
+ }
549
+ const highlight = numericQuery ? Math.min(Number.parseInt(query, 10) - 1, items.length - 1) : Math.min(ui.highlight, Math.max(0, items.length - 1));
550
+ const allOn = !!pickStep && listed(pickStep).every((c)=>picked.includes(c));
551
+ const toggle = (choice)=>{
552
+ if (!pickStep) return;
553
+ const next = choice === ALL ? allOn ? [] : listed(pickStep) : picked.includes(choice) ? picked.filter((c)=>c !== choice) : choice === ANY ? [
554
+ ANY
555
+ ] : [
556
+ ...picked.filter((c)=>c !== ANY),
557
+ choice
558
+ ];
559
+ focus('bar', {
560
+ picked: next,
561
+ query: ''
562
+ });
563
+ };
564
+ const applyPick = (fallback)=>{
565
+ if (!pickStep) return;
566
+ const chosen = pickStep.choices.filter((c)=>picked.includes(c));
567
+ const use = chosen.length ? chosen : fallback === ALL ? listed(pickStep) : fallback ? [
568
+ fallback
569
+ ] : [];
570
+ if (!use.length) return;
571
+ setSegments([
572
+ ...segments,
573
+ sdkCombine(pickStep.kind, use)
574
+ ], {
575
+ menuOpen: true
576
+ });
577
+ };
578
+ const goMatch = ()=>{
579
+ if (!segments.length) return;
580
+ if (pointOnly) return void patch({
581
+ menuOpen: false,
582
+ nameStep: null,
583
+ pickStep: null
584
+ });
585
+ value.condition ? focus('value', {
586
+ stage: 'value',
587
+ menuOpen: false,
588
+ nameStep: null,
589
+ pickStep: null
590
+ }) : focus('condition', {
591
+ stage: 'condition',
592
+ menuOpen: false,
593
+ conditionQuery: '',
594
+ conditionHighlight: 0
595
+ });
596
+ };
597
+ const choose = (item)=>{
598
+ if (!item) return;
599
+ if ('pick' === item.kind) return toggle(item.choice);
600
+ if ('name' === item.kind) {
601
+ const sdkItem = nameStep ? nameStep.sdkItem : null;
602
+ const isTypedAhead = item.name.id.startsWith('typed:') || item.name.id.startsWith('sdk-typed-');
603
+ if ((sdkItem || isTypedAhead) && proton) try {
604
+ const currentPoint = renderSegments(proton, segments);
605
+ const nameText = item.name.label;
606
+ let insertTemplate = sdkItem?.insert || '';
607
+ if (!insertTemplate && isTypedAhead) {
608
+ const templateItem = sdkCompletionItems.find((i)=>i.open);
609
+ insertTemplate = templateItem?.insert || '';
610
+ }
611
+ const category = sdkItem?.category || (isTypedAhead ? 'key' : 'key');
612
+ let insertText = insertTemplate;
613
+ let prefix = "['";
614
+ if ('attr' === category) prefix = "[attr:'";
615
+ else if ('method' === category) prefix = "[method:'";
616
+ else if ('key' === category) prefix = ui.nameIgnoreCase ? "[i:'" : "['";
617
+ insertText = insertText.endsWith("['") || insertText.endsWith("[attr:'") || insertText.endsWith("[method:'") ? `${prefix}${nameText}']` : insertText.includes('<cursor>') ? insertText.replace('<cursor>', nameText) : `${prefix}${nameText}']`;
618
+ const pointAfterInsert = currentPoint + insertText;
619
+ const newSegments = proton.point.parse(pointAfterInsert);
620
+ return setSegments(newSegments, {
621
+ menuOpen: true
622
+ });
623
+ } catch {}
624
+ return setSegments([
625
+ ...segments,
626
+ ...item.name.segs
627
+ ], {
628
+ menuOpen: true
629
+ });
630
+ }
631
+ const o = item.option;
632
+ if (void 0 !== o.dupModifier && proton) {
633
+ let dupSeg;
634
+ dupSeg = 'all' === o.dupModifier ? sdkSeg.dupAll() : 'any' === o.dupModifier ? sdkSeg.dupAny() : sdkSeg.dup(o.dupModifier);
635
+ dupSeg = normalizeSegment(dupSeg);
636
+ const newSegments = [
637
+ ...segments,
638
+ dupSeg
639
+ ];
640
+ return setSegments(newSegments, {
641
+ menuOpen: true
642
+ });
643
+ }
644
+ if (void 0 !== o.roleModifier && proton) {
645
+ const lastSeg = segments[segments.length - 1];
646
+ if (lastSeg && ('key' === lastSeg.kind || 'attr' === lastSeg.kind)) {
647
+ const modifiedSeg = {
648
+ ...lastSeg,
649
+ role: o.roleModifier
650
+ };
651
+ const newSegments = [
652
+ ...segments.slice(0, -1),
653
+ modifiedSeg
654
+ ];
655
+ return setSegments(newSegments, {
656
+ menuOpen: true
657
+ });
658
+ }
659
+ return;
660
+ }
661
+ if (o.sdkItem && proton) {
662
+ const sdkItem = o.sdkItem;
663
+ if (sdkItem.open) {
664
+ let placeholder = `Enter ${sdkItem.label.toLowerCase()}`;
665
+ if ('attr' === sdkItem.category) placeholder = 'Enter attribute name (@id, @class, ...)';
666
+ else if ('method' === sdkItem.category) placeholder = 'Enter method name (e.g., tools/call)';
667
+ const nameStep = {
668
+ label: sdkItem.label,
669
+ placeholder,
670
+ segs: [],
671
+ allowsCase: 'key' === sdkItem.category,
672
+ showsStarHint: 'key' === sdkItem.category,
673
+ sdkItem
674
+ };
675
+ return focus('name', {
676
+ nameStep,
677
+ nameIgnoreCase: false,
678
+ query: '',
679
+ menuOpen: true
680
+ });
681
+ }
682
+ if (sdkItem.insert) try {
683
+ const pointAfterInsert = renderSegments(proton, segments) + sdkItem.insert;
684
+ const newSegments = proton.point.parse(pointAfterInsert);
685
+ return setSegments(newSegments, {
686
+ menuOpen: true
687
+ });
688
+ } catch {
689
+ return;
690
+ }
691
+ try {
692
+ const currentPoint = renderSegments(proton, segments);
693
+ const pointWithLabel = currentPoint + sdkItem.label;
694
+ const newSegments = proton.point.parse(pointWithLabel);
695
+ return setSegments(newSegments, {
696
+ menuOpen: true
697
+ });
698
+ } catch {
699
+ return;
700
+ }
701
+ }
702
+ if (o.pick) return focus('bar', {
703
+ pickStep: o.pick,
704
+ picked: [],
705
+ query: '',
706
+ menuOpen: true
707
+ });
708
+ if (o.name) return focus('name', {
709
+ nameStep: o.name,
710
+ nameIgnoreCase: false,
711
+ query: '',
712
+ menuOpen: true
713
+ });
714
+ if (o.done) {
715
+ const newSegments = [
716
+ ...segments,
717
+ ...o.segs ?? []
718
+ ];
719
+ const result = checkSegmentsDirectly(proton, newSegments, {
720
+ profile: profile ?? 'tree',
721
+ context
722
+ });
723
+ const canonical = result.ok ? result.canonical : null;
724
+ const canonicalVersion = proton ? proton.version().canonical : null;
725
+ onChange({
726
+ ...value,
727
+ segments: newSegments,
728
+ canonical,
729
+ canonicalVersion
730
+ });
731
+ return focus(value.condition ? 'value' : 'condition', {
732
+ stage: value.condition ? 'value' : 'condition',
733
+ menuOpen: false,
734
+ query: '',
735
+ nameStep: null,
736
+ pickStep: null,
737
+ conditionQuery: '',
738
+ conditionHighlight: 0
739
+ });
740
+ }
741
+ return setSegments([
742
+ ...segments,
743
+ ...o.segs ?? []
744
+ ], {
745
+ menuOpen: true
746
+ });
747
+ };
748
+ const back = ()=>{
749
+ if (pickStep || nameStep) return focus('bar', {
750
+ pickStep: null,
751
+ nameStep: null,
752
+ picked: [],
753
+ query: ''
754
+ });
755
+ if (segments.length) setSegments(segments.slice(0, -1), {
756
+ menuOpen: true
757
+ });
758
+ };
759
+ const truncateTo = (index)=>setSegments(segments.slice(0, index + 1), {
760
+ stage: 'point',
761
+ menuOpen: true
762
+ });
763
+ const onNumber = (e, typed, count, onWait, onPick)=>{
764
+ if (!isDigit(e.key) || !('' === typed || /^\d+$/.test(typed))) return false;
765
+ e.preventDefault();
766
+ return pickByNumber(e.key, typed, count, onWait, onPick);
767
+ };
768
+ const handleBarKey = (e)=>{
769
+ if ('?' === e.key && onShowKeyboardHelp) {
770
+ e.preventDefault();
771
+ onShowKeyboardHelp();
772
+ return;
773
+ }
774
+ if ('Enter' === e.key && (e.ctrlKey || e.metaKey)) {
775
+ e.preventDefault();
776
+ if (segments.length > 0) goMatch();
777
+ return;
778
+ }
779
+ if ('Tab' === e.key && !e.shiftKey && !pickStep && segments.length > 0) {
780
+ e.preventDefault();
781
+ focus('next', {
782
+ menuOpen: false
783
+ });
784
+ return;
785
+ }
786
+ if (pickStep) {
787
+ if (onNumber(e, query, items.length, (q)=>patch({
788
+ query: q
789
+ }), (i)=>items[i] && choose(items[i]))) return;
790
+ if (' ' === e.key) {
791
+ e.preventDefault();
792
+ const it = items[highlight];
793
+ if (it?.kind === 'pick') toggle(it.choice);
794
+ return;
795
+ }
796
+ if ('Enter' === e.key) {
797
+ e.preventDefault();
798
+ const it = items[highlight];
799
+ applyPick(it?.kind === 'pick' ? it.choice : void 0);
800
+ return;
801
+ }
802
+ } else if (onNumber(e, query, items.length, (q)=>patch({
803
+ query: q,
804
+ menuOpen: true
805
+ }), (i)=>choose(items[i]))) return;
806
+ if ('ArrowDown' === e.key) {
807
+ e.preventDefault();
808
+ if (ui.menuOpen) {
809
+ if (items.length) patch({
810
+ highlight: Math.min(highlight + 1, items.length - 1),
811
+ query: numericQuery ? '' : query
812
+ });
813
+ } else patch({
814
+ menuOpen: true
815
+ });
816
+ } else if ('ArrowUp' === e.key) {
817
+ e.preventDefault();
818
+ patch({
819
+ highlight: Math.max(highlight - 1, 0),
820
+ query: numericQuery ? '' : query
821
+ });
822
+ } else if ('Enter' === e.key) {
823
+ e.preventDefault();
824
+ if (sdkCompletionItems.length || !segments.length || pickStep) {
825
+ if (!pickStep) choose(items[highlight]);
826
+ } else goMatch();
827
+ } else if ('Backspace' === e.key && '' === query || 'Escape' === e.key && pickStep) {
828
+ e.preventDefault();
829
+ back();
830
+ } else if ('Escape' === e.key) {
831
+ e.preventDefault();
832
+ if (ui.menuOpen) patch({
833
+ menuOpen: false,
834
+ query: '',
835
+ highlight: 0
836
+ });
837
+ else e.target.blur();
838
+ }
839
+ };
840
+ const handleNameKey = (e)=>{
841
+ e.stopPropagation();
842
+ if ('?' === e.key && onShowKeyboardHelp) {
843
+ e.preventDefault();
844
+ onShowKeyboardHelp();
845
+ return;
846
+ }
847
+ if ('ArrowDown' === e.key) {
848
+ e.preventDefault();
849
+ patch({
850
+ highlight: Math.min(highlight + 1, Math.max(0, items.length - 1))
851
+ });
852
+ } else if ('ArrowUp' === e.key) {
853
+ e.preventDefault();
854
+ patch({
855
+ highlight: Math.max(highlight - 1, 0)
856
+ });
857
+ } else if ('Enter' === e.key) {
858
+ e.preventDefault();
859
+ choose(items[highlight]);
860
+ } else if ('Backspace' === e.key && '' === query || 'Escape' === e.key) {
861
+ e.preventDefault();
862
+ back();
863
+ } else if (e.altKey && 'KeyC' === e.code && nameStep && isKeyStep(nameStep) && !isCaseFixed(nameStep)) {
864
+ e.preventDefault();
865
+ patch({
866
+ nameIgnoreCase: !ui.nameIgnoreCase
867
+ });
868
+ }
869
+ };
870
+ const cq = ui.conditionQuery;
871
+ const numericCondition = /^\d+$/.test(cq);
872
+ const conditionItems = CONDITIONS.map(([type, label], i)=>({
873
+ type,
874
+ row: {
875
+ id: type,
876
+ number: i + 1,
877
+ label,
878
+ desc: ''
879
+ }
880
+ })).map((c)=>({
881
+ ...c,
882
+ score: fuzzyScore(cq, c.row.label)
883
+ })).filter((c)=>!cq || numericCondition || c.score > 0).sort((a, b)=>cq && !numericCondition ? b.score - a.score : 0);
884
+ const conditionHighlight = numericCondition ? Number.parseInt(cq, 10) - 1 : Math.min(ui.conditionHighlight, Math.max(0, conditionItems.length - 1));
885
+ const chooseCondition = (type)=>{
886
+ if (!type) return;
887
+ onChange({
888
+ ...value,
889
+ condition: type
890
+ });
891
+ focus(takesValue(type) ? 'value' : 'conditionChip', {
892
+ stage: 'value',
893
+ conditionQuery: '',
894
+ conditionHighlight: 0
895
+ });
896
+ };
897
+ const handleConditionKey = (e)=>{
898
+ e.stopPropagation();
899
+ if ('?' === e.key && onShowKeyboardHelp) {
900
+ e.preventDefault();
901
+ onShowKeyboardHelp();
902
+ return;
903
+ }
904
+ if (onNumber(e, cq, CONDITIONS.length, (q)=>patch({
905
+ conditionQuery: q
906
+ }), (i)=>chooseCondition(CONDITIONS[i]?.[0]))) return;
907
+ if ('ArrowDown' === e.key) {
908
+ e.preventDefault();
909
+ patch({
910
+ conditionHighlight: Math.min(conditionHighlight + 1, conditionItems.length - 1),
911
+ conditionQuery: numericCondition ? '' : cq
912
+ });
913
+ } else if ('ArrowUp' === e.key) {
914
+ e.preventDefault();
915
+ patch({
916
+ conditionHighlight: Math.max(conditionHighlight - 1, 0),
917
+ conditionQuery: numericCondition ? '' : cq
918
+ });
919
+ } else if ('Enter' === e.key) {
920
+ e.preventDefault();
921
+ chooseCondition(conditionItems[conditionHighlight]?.type);
922
+ } else if ('Backspace' === e.key && '' === cq || 'Escape' === e.key) {
923
+ e.preventDefault();
924
+ focus('bar', {
925
+ stage: 'point',
926
+ menuOpen: true
927
+ });
928
+ }
929
+ };
930
+ const handleValueKey = (e)=>{
931
+ if ('?' === e.key && onShowKeyboardHelp) {
932
+ e.preventDefault();
933
+ onShowKeyboardHelp();
934
+ return;
935
+ }
936
+ if ('Backspace' === e.key && '' === value.value || 'Escape' === e.key) {
937
+ e.preventDefault();
938
+ focus('condition', {
939
+ stage: 'condition',
940
+ conditionQuery: ''
941
+ });
942
+ } else if (e.altKey && 'KeyC' === e.code) {
943
+ e.preventDefault();
944
+ onChange({
945
+ ...value,
946
+ ignoreCase: !value.ignoreCase
947
+ });
948
+ }
949
+ };
950
+ const point = proton && segments.length > 0 ? renderSegments(proton, segments) : '';
951
+ const check = value.condition ? checkOf(value.condition, value.value, value.ignoreCase, point, context) : null;
952
+ const last = segments[segments.length - 1];
953
+ const nameAllowsCase = !!nameStep && isKeyStep(nameStep) && !isCaseFixed(nameStep);
954
+ const computeSentence = ()=>{
955
+ if (0 === segments.length) return '';
956
+ const described = describe(segments);
957
+ if (described) return described;
958
+ return value.canonical || '';
959
+ };
960
+ return {
961
+ ui,
962
+ point,
963
+ check,
964
+ sentence: computeSentence(),
965
+ reserved: segments.some((s)=>s.reserved),
966
+ sdkError: ui.sdkError,
967
+ incomplete: ui.incomplete,
968
+ canonicalInfo: ui.canonicalInfo,
969
+ loadingKeys,
970
+ pointStage,
971
+ menuOpen: pointStage && (!!nameStep || !!pickStep || ui.menuOpen),
972
+ menuTitle: pickStep ? pickStep.title : nameStep ? nameStep.wordsOnly ? nameStep.placeholder : isPositionStep(nameStep) ? `Which ${nounOf(nameStep)}? (0 is the first)` : `Which ${nounOf(nameStep)}?` : listTitle(segments, context),
973
+ menuFooter: pickStep ? 'pick' : nameStep ? 'name' : 'list',
974
+ rows: items.map((it)=>it.row),
975
+ highlightedId: items[highlight]?.row.id ?? null,
976
+ status,
977
+ pendingLabel: pickStep ? 'format' === pickStep.kind ? 'parse as …' : 'decode as …' : nameStep ? `${nounOf(nameStep)} …` : '',
978
+ nameStep,
979
+ nameInputPlaceholder: nameStep ? nameStep.wordsOnly ? 'type to filter' : isPositionStep(nameStep) ? `type a number: 0 is the first ${nounOf(nameStep)}` : `type ${nameStep.placeholder}` : '',
980
+ nameAllowsCase,
981
+ nameShowsStarHint: !!nameStep && isKeyStep(nameStep),
982
+ applyLabel: allOn ? 'Apply: all' : picked.length && pickStep ? `Apply: ${pickStep.choices.filter((c)=>picked.includes(c)).map((c)=>PICK_LABELS[c]?.[0] ?? c).join(' + ')}` : 'Tick one or more',
983
+ barPlaceholder: segments.length ? pickStep ? 'type a number or press Space to tick, Enter to apply' : sdkCompletionItems.length ? 'what next? type to filter, or a number' : 'press Next (Tab, or Ctrl+Enter) to set the condition' : 'Header, Body, Query, Path… type to filter, or a number (Press ? for help)',
984
+ canContinue: segments.length > 0,
985
+ conditionTitle: last ? ('dup_index' === last.kind || 'dup_all' === last.kind || 'dup_any' === last.kind) && last.dup ? `How should the ${last.label} match?` : 'wild' === last.kind || 'dup_index' === last.kind || 'dup_all' === last.kind || 'dup_any' === last.kind || 'joined' === last.kind ? `How should ${last.label} match?` : `How should the value of ${last.label} match?` : 'How should the value match?',
986
+ conditionRows: conditionItems.map((c)=>c.row),
987
+ conditionHighlightedId: conditionItems[conditionHighlight]?.row.id ?? null,
988
+ conditionTakesValue: !!value.condition && takesValue(value.condition),
989
+ readAs: 'Use * for any text: *admin* means contains admin.',
990
+ actions: {
991
+ setQuery: (q)=>patch({
992
+ query: q,
993
+ highlight: 0,
994
+ menuOpen: true
995
+ }),
996
+ openMenu: ()=>!ui.menuOpen && patch({
997
+ menuOpen: true
998
+ }),
999
+ closeMenu: ()=>patch({
1000
+ menuOpen: false,
1001
+ nameStep: null,
1002
+ pickStep: null,
1003
+ picked: [],
1004
+ query: ''
1005
+ }),
1006
+ highlight: (id)=>{
1007
+ const i = items.findIndex((it)=>it.row.id === id);
1008
+ if (i >= 0) patch({
1009
+ highlight: i,
1010
+ query: numericQuery ? '' : query
1011
+ });
1012
+ },
1013
+ chooseRow: (id)=>choose(items.find((it)=>it.row.id === id)),
1014
+ applyPick: ()=>applyPick(),
1015
+ toggleNameCase: ()=>focus('name', {
1016
+ nameIgnoreCase: !ui.nameIgnoreCase
1017
+ }),
1018
+ truncateTo,
1019
+ goMatch,
1020
+ editPoint: ()=>focus('bar', {
1021
+ stage: 'point',
1022
+ menuOpen: true
1023
+ }),
1024
+ setConditionQuery: (q)=>patch({
1025
+ conditionQuery: q,
1026
+ conditionHighlight: 0
1027
+ }),
1028
+ highlightCondition: (id)=>{
1029
+ const i = conditionItems.findIndex((c)=>c.row.id === id);
1030
+ if (i >= 0) patch({
1031
+ conditionHighlight: i,
1032
+ conditionQuery: numericCondition ? '' : cq
1033
+ });
1034
+ },
1035
+ chooseCondition: (id)=>chooseCondition(conditionItems.find((c)=>c.row.id === id)?.type),
1036
+ editCondition: ()=>focus('condition', {
1037
+ stage: 'condition',
1038
+ conditionQuery: ''
1039
+ }),
1040
+ closeConditionList: ()=>patch({
1041
+ stage: 'value',
1042
+ conditionQuery: ''
1043
+ }),
1044
+ setValue: (v)=>onChange({
1045
+ ...value,
1046
+ value: v
1047
+ }),
1048
+ setIgnoreCase: (on)=>onChange({
1049
+ ...value,
1050
+ ignoreCase: on
1051
+ }),
1052
+ clearSdkError: ()=>patch({
1053
+ sdkError: null,
1054
+ incomplete: false
1055
+ }),
1056
+ clearCanonicalInfo: ()=>patch({
1057
+ canonicalInfo: null
1058
+ }),
1059
+ applyFix: (fix)=>{
1060
+ if (!proton) return void patch({
1061
+ sdkError: null,
1062
+ incomplete: false
1063
+ });
1064
+ try {
1065
+ const currentPoint = renderSegments(proton, segments);
1066
+ const fixedPoint = currentPoint.slice(0, fix.replace[0]) + fix.insert + currentPoint.slice(fix.replace[1]);
1067
+ const newSegments = proton.point.parse(fixedPoint);
1068
+ setSegments(newSegments, {
1069
+ sdkError: null,
1070
+ incomplete: false
1071
+ });
1072
+ } catch {
1073
+ patch({
1074
+ sdkError: null,
1075
+ incomplete: false
1076
+ });
1077
+ }
1078
+ }
1079
+ },
1080
+ keys: {
1081
+ handleBarKey,
1082
+ handleNameKey,
1083
+ handleConditionKey,
1084
+ handleValueKey
1085
+ }
1086
+ };
1087
+ };
1088
+ export { usePointSelector };