@cloudvoyant/helical-ui 0.23.0 → 0.23.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/chunk-AFE6BORT.js +691 -0
- package/dist/command/index.cjs +726 -0
- package/dist/command/index.d.cts +5 -0
- package/dist/command/index.d.ts +5 -0
- package/dist/command/index.js +64 -0
- package/dist/index-FoNHRG3R.d.cts +352 -0
- package/dist/index-FoNHRG3R.d.ts +352 -0
- package/dist/index.cjs +376 -576
- package/dist/index.d.cts +144 -309
- package/dist/index.d.ts +144 -309
- package/dist/index.js +357 -754
- package/package.json +6 -1
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/command/core.ts
|
|
20
|
+
import { matchesKeyboardEvent } from "@tanstack/hotkeys";
|
|
21
|
+
import { TreeCollection } from "@zag-js/collection";
|
|
22
|
+
import { createFilter } from "@zag-js/i18n-utils";
|
|
23
|
+
import { createLiveRegion } from "@zag-js/live-region";
|
|
24
|
+
import { Fzf, byLengthAsc } from "fzf";
|
|
25
|
+
var ROOT_NODE_VALUE = "__root__";
|
|
26
|
+
var DEFAULT_GROUP_LABEL = "Commands";
|
|
27
|
+
var i18nFilter = createFilter({ sensitivity: "base" });
|
|
28
|
+
var sharedLiveRegion = null;
|
|
29
|
+
function getNodeCommandToken(node) {
|
|
30
|
+
return (node.command ?? node.value).trim();
|
|
31
|
+
}
|
|
32
|
+
function isEditableTarget(target) {
|
|
33
|
+
if (!target || typeof target !== "object") return false;
|
|
34
|
+
const el = target;
|
|
35
|
+
if (el.isContentEditable) return true;
|
|
36
|
+
const tag = el.tagName?.toLowerCase();
|
|
37
|
+
if (tag === "input" || tag === "textarea" || tag === "select") return true;
|
|
38
|
+
if (typeof el.closest === "function" && el.closest('[contenteditable="true"], .ProseMirror')) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function toFlatItem(node, ancestorPath, ancestorLabels, ancestorCommands, tree, fallbackGroup) {
|
|
44
|
+
const cmd = getNodeCommandToken(node);
|
|
45
|
+
const valuePath = [...ancestorPath, node.value];
|
|
46
|
+
const commandTokens = [...ancestorCommands, cmd];
|
|
47
|
+
const isBranch = tree.isBranchNode(node);
|
|
48
|
+
const group = node.group ?? fallbackGroup ?? (ancestorLabels.length > 0 ? ancestorLabels[ancestorLabels.length - 1] : DEFAULT_GROUP_LABEL);
|
|
49
|
+
return {
|
|
50
|
+
value: valuePath.join("/"),
|
|
51
|
+
label: node.label,
|
|
52
|
+
description: node.description,
|
|
53
|
+
group,
|
|
54
|
+
command: cmd,
|
|
55
|
+
fullCommand: `:${commandTokens.join(" ")}`,
|
|
56
|
+
aliases: node.aliases ?? [],
|
|
57
|
+
shortcut: node.shortcut,
|
|
58
|
+
badge: node.badge,
|
|
59
|
+
active: Boolean(node.active),
|
|
60
|
+
disabled: Boolean(node.disabled),
|
|
61
|
+
isBranch,
|
|
62
|
+
valuePath,
|
|
63
|
+
breadcrumbLabels: ancestorLabels,
|
|
64
|
+
node
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function groupCommandItems(items) {
|
|
68
|
+
const map = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const item of items) {
|
|
70
|
+
const groupLabel = item.group || DEFAULT_GROUP_LABEL;
|
|
71
|
+
const list = map.get(groupLabel);
|
|
72
|
+
if (list) {
|
|
73
|
+
list.push(item);
|
|
74
|
+
} else {
|
|
75
|
+
map.set(groupLabel, [item]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return Array.from(map.entries()).map(([label, groupItems]) => ({
|
|
79
|
+
label,
|
|
80
|
+
items: groupItems
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
function collectDeepFlatItems(parentNode, ancestorPath, ancestorLabels, ancestorCommands, tree, out) {
|
|
84
|
+
const children = tree.getNodeChildren(parentNode);
|
|
85
|
+
for (const child of children) {
|
|
86
|
+
const flat = toFlatItem(child, ancestorPath, ancestorLabels, ancestorCommands, tree);
|
|
87
|
+
out.push(flat);
|
|
88
|
+
if (tree.isBranchNode(child)) {
|
|
89
|
+
collectDeepFlatItems(
|
|
90
|
+
child,
|
|
91
|
+
[...ancestorPath, child.value],
|
|
92
|
+
[...ancestorLabels, child.label],
|
|
93
|
+
[...ancestorCommands, getNodeCommandToken(child)],
|
|
94
|
+
tree,
|
|
95
|
+
out
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function matchesCommandToken(node, token) {
|
|
101
|
+
const lower = token.toLowerCase();
|
|
102
|
+
const cmd = getNodeCommandToken(node).toLowerCase();
|
|
103
|
+
if (cmd === lower || node.value.toLowerCase() === lower) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return (node.aliases ?? []).some((alias) => alias.toLowerCase() === lower);
|
|
107
|
+
}
|
|
108
|
+
function isHotkeyAnchorVisible(el) {
|
|
109
|
+
if (el.closest("[hidden]")) return false;
|
|
110
|
+
const fwWrapper = el.closest("[data-fw]");
|
|
111
|
+
const activeFw = el.ownerDocument?.documentElement?.getAttribute("data-framework");
|
|
112
|
+
if (fwWrapper && activeFw && fwWrapper.getAttribute("data-fw") !== activeFw) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
function createCommandTree(items) {
|
|
118
|
+
if (items instanceof TreeCollection) {
|
|
119
|
+
return items;
|
|
120
|
+
}
|
|
121
|
+
const rootNode = {
|
|
122
|
+
value: ROOT_NODE_VALUE,
|
|
123
|
+
label: "Root",
|
|
124
|
+
children: items ?? []
|
|
125
|
+
};
|
|
126
|
+
return new TreeCollection({
|
|
127
|
+
rootNode,
|
|
128
|
+
nodeToValue: (node) => node.value,
|
|
129
|
+
nodeToString: (node) => node.label,
|
|
130
|
+
isNodeDisabled: (node) => Boolean(node.disabled),
|
|
131
|
+
nodeToChildren: (node) => node.children ?? []
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function resolveCommandLevel(tree, activePath = [], query = "", options) {
|
|
135
|
+
const rootChildren = tree.getNodeChildren(tree.rootNode);
|
|
136
|
+
const hasCommands = rootChildren.length > 0;
|
|
137
|
+
if (!hasCommands) {
|
|
138
|
+
return {
|
|
139
|
+
hasCommands: false,
|
|
140
|
+
breadcrumbs: [],
|
|
141
|
+
items: [],
|
|
142
|
+
groups: []
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const breadcrumbs = [];
|
|
146
|
+
const resolvedValuePath = [];
|
|
147
|
+
const resolvedLabels = [];
|
|
148
|
+
const resolvedCommands = [];
|
|
149
|
+
let currentNode = tree.rootNode;
|
|
150
|
+
for (const segment of activePath) {
|
|
151
|
+
const children = tree.getNodeChildren(currentNode);
|
|
152
|
+
const match = children.find((child) => child.value === segment);
|
|
153
|
+
if (!match || !tree.isBranchNode(match)) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
const cmd = getNodeCommandToken(match);
|
|
157
|
+
breadcrumbs.push({
|
|
158
|
+
value: match.value,
|
|
159
|
+
label: match.label,
|
|
160
|
+
command: cmd
|
|
161
|
+
});
|
|
162
|
+
resolvedValuePath.push(match.value);
|
|
163
|
+
resolvedLabels.push(match.label);
|
|
164
|
+
resolvedCommands.push(cmd);
|
|
165
|
+
currentNode = match;
|
|
166
|
+
}
|
|
167
|
+
const trimmedQuery = query.trim();
|
|
168
|
+
const directChildren = tree.getNodeChildren(currentNode);
|
|
169
|
+
const directItems = directChildren.map(
|
|
170
|
+
(child) => toFlatItem(child, resolvedValuePath, resolvedLabels, resolvedCommands, tree)
|
|
171
|
+
);
|
|
172
|
+
if (!trimmedQuery) {
|
|
173
|
+
return {
|
|
174
|
+
hasCommands: true,
|
|
175
|
+
breadcrumbs,
|
|
176
|
+
items: directItems,
|
|
177
|
+
groups: groupCommandItems(directItems)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const normalizedQuery = trimmedQuery.startsWith(":") ? trimmedQuery.slice(1).trim() : trimmedQuery;
|
|
181
|
+
if (!normalizedQuery) {
|
|
182
|
+
return {
|
|
183
|
+
hasCommands: true,
|
|
184
|
+
breadcrumbs,
|
|
185
|
+
items: directItems,
|
|
186
|
+
groups: groupCommandItems(directItems)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const allowDeepSearch = options?.deepSearch !== false && breadcrumbs.length === 0;
|
|
190
|
+
const candidatePool = [];
|
|
191
|
+
if (allowDeepSearch) {
|
|
192
|
+
collectDeepFlatItems(currentNode, resolvedValuePath, resolvedLabels, resolvedCommands, tree, candidatePool);
|
|
193
|
+
} else {
|
|
194
|
+
candidatePool.push(...directItems);
|
|
195
|
+
}
|
|
196
|
+
const labelFzf = new Fzf(candidatePool, {
|
|
197
|
+
selector: (item) => item.label,
|
|
198
|
+
tiebreakers: [byLengthAsc],
|
|
199
|
+
casing: "case-insensitive"
|
|
200
|
+
});
|
|
201
|
+
const labelResults = labelFzf.find(normalizedQuery);
|
|
202
|
+
const labelMatchMap = /* @__PURE__ */ new Map();
|
|
203
|
+
for (const res of labelResults) {
|
|
204
|
+
labelMatchMap.set(res.item.value, {
|
|
205
|
+
score: res.score,
|
|
206
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const compositeFzf = new Fzf(candidatePool, {
|
|
210
|
+
selector: (item) => [
|
|
211
|
+
item.label,
|
|
212
|
+
item.command,
|
|
213
|
+
item.fullCommand,
|
|
214
|
+
...item.aliases,
|
|
215
|
+
...item.breadcrumbLabels,
|
|
216
|
+
item.description ?? "",
|
|
217
|
+
...item.node.keywords ?? []
|
|
218
|
+
].join(" "),
|
|
219
|
+
tiebreakers: [byLengthAsc],
|
|
220
|
+
casing: "case-insensitive"
|
|
221
|
+
});
|
|
222
|
+
const compositeResults = compositeFzf.find(normalizedQuery);
|
|
223
|
+
const matchedByValue = /* @__PURE__ */ new Map();
|
|
224
|
+
for (const res of compositeResults) {
|
|
225
|
+
const labelHit = labelMatchMap.get(res.item.value);
|
|
226
|
+
const depthPenalty = (res.item.valuePath.length - 1) * 2;
|
|
227
|
+
const effectiveScore = (labelHit ? labelHit.score + 20 : res.score) - depthPenalty;
|
|
228
|
+
matchedByValue.set(res.item.value, {
|
|
229
|
+
...res.item,
|
|
230
|
+
matchPositions: labelHit?.positions ?? [],
|
|
231
|
+
score: effectiveScore
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
for (const candidate of candidatePool) {
|
|
235
|
+
if (matchedByValue.has(candidate.value)) continue;
|
|
236
|
+
if (i18nFilter.contains(candidate.label, normalizedQuery) || i18nFilter.contains(candidate.command, normalizedQuery)) {
|
|
237
|
+
matchedByValue.set(candidate.value, {
|
|
238
|
+
...candidate,
|
|
239
|
+
matchPositions: [],
|
|
240
|
+
score: 1
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const rankedItems = Array.from(matchedByValue.values()).sort((a, b) => {
|
|
245
|
+
const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
|
|
246
|
+
if (scoreDiff !== 0) return scoreDiff;
|
|
247
|
+
if (a.valuePath.length !== b.valuePath.length) {
|
|
248
|
+
return a.valuePath.length - b.valuePath.length;
|
|
249
|
+
}
|
|
250
|
+
return a.label.length - b.label.length;
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
hasCommands: true,
|
|
254
|
+
breadcrumbs,
|
|
255
|
+
items: rankedItems,
|
|
256
|
+
groups: groupCommandItems(rankedItems)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function resolveCommandMenuState(tree, rawInput = "") {
|
|
260
|
+
const rootChildren = tree.getNodeChildren(tree.rootNode);
|
|
261
|
+
const hasCommands = rootChildren.length > 0;
|
|
262
|
+
const withoutColon = rawInput.startsWith(":") ? rawInput.slice(1) : rawInput;
|
|
263
|
+
const normalizedInput = `:${withoutColon}`;
|
|
264
|
+
if (!hasCommands) {
|
|
265
|
+
return {
|
|
266
|
+
hasCommands: false,
|
|
267
|
+
normalizedInput,
|
|
268
|
+
completedTokens: [],
|
|
269
|
+
partialToken: withoutColon.trim(),
|
|
270
|
+
breadcrumbs: [],
|
|
271
|
+
suggestions: [],
|
|
272
|
+
exactNode: null,
|
|
273
|
+
error: null
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const hasTrailingSpace = /\s+$/.test(withoutColon);
|
|
277
|
+
const trimmed = withoutColon.trim();
|
|
278
|
+
const rawTokens = trimmed.length > 0 ? trimmed.split(/\s+/) : [];
|
|
279
|
+
const tokensToWalk = hasTrailingSpace ? rawTokens : rawTokens.slice(0, -1);
|
|
280
|
+
const partialToken = hasTrailingSpace ? "" : rawTokens[rawTokens.length - 1] ?? "";
|
|
281
|
+
const completedTokens = [];
|
|
282
|
+
const breadcrumbs = [];
|
|
283
|
+
const ancestorPath = [];
|
|
284
|
+
const ancestorLabels = [];
|
|
285
|
+
let currentNode = tree.rootNode;
|
|
286
|
+
for (let i = 0; i < tokensToWalk.length; i++) {
|
|
287
|
+
const token = tokensToWalk[i];
|
|
288
|
+
const children = tree.getNodeChildren(currentNode);
|
|
289
|
+
const matchedChild = children.find((child) => matchesCommandToken(child, token));
|
|
290
|
+
if (!matchedChild) {
|
|
291
|
+
return {
|
|
292
|
+
hasCommands: true,
|
|
293
|
+
normalizedInput,
|
|
294
|
+
completedTokens,
|
|
295
|
+
partialToken: rawTokens.slice(i).join(" "),
|
|
296
|
+
breadcrumbs,
|
|
297
|
+
suggestions: [],
|
|
298
|
+
exactNode: null,
|
|
299
|
+
error: `Unknown command: ${token}`
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const canonicalCmd = getNodeCommandToken(matchedChild);
|
|
303
|
+
if (!tree.isBranchNode(matchedChild)) {
|
|
304
|
+
const extraTokens = rawTokens.slice(i + 1);
|
|
305
|
+
const hasExtra = extraTokens.length > 0 || partialToken.length > 0;
|
|
306
|
+
if (hasExtra) {
|
|
307
|
+
return {
|
|
308
|
+
hasCommands: true,
|
|
309
|
+
normalizedInput,
|
|
310
|
+
completedTokens: [...completedTokens, canonicalCmd],
|
|
311
|
+
partialToken,
|
|
312
|
+
breadcrumbs,
|
|
313
|
+
suggestions: [],
|
|
314
|
+
exactNode: null,
|
|
315
|
+
error: `Command ':${[...completedTokens, canonicalCmd].join(" ")}' does not take arguments`
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const exactFlat = toFlatItem(matchedChild, ancestorPath, ancestorLabels, completedTokens, tree);
|
|
319
|
+
return {
|
|
320
|
+
hasCommands: true,
|
|
321
|
+
normalizedInput,
|
|
322
|
+
completedTokens: [...completedTokens, canonicalCmd],
|
|
323
|
+
partialToken: "",
|
|
324
|
+
breadcrumbs,
|
|
325
|
+
suggestions: [exactFlat],
|
|
326
|
+
exactNode: exactFlat,
|
|
327
|
+
error: null
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
completedTokens.push(canonicalCmd);
|
|
331
|
+
breadcrumbs.push({
|
|
332
|
+
value: matchedChild.value,
|
|
333
|
+
label: matchedChild.label,
|
|
334
|
+
command: canonicalCmd
|
|
335
|
+
});
|
|
336
|
+
ancestorPath.push(matchedChild.value);
|
|
337
|
+
ancestorLabels.push(matchedChild.label);
|
|
338
|
+
currentNode = matchedChild;
|
|
339
|
+
}
|
|
340
|
+
const branchChildren = tree.getNodeChildren(currentNode);
|
|
341
|
+
const branchItems = branchChildren.map(
|
|
342
|
+
(child) => toFlatItem(child, ancestorPath, ancestorLabels, completedTokens, tree)
|
|
343
|
+
);
|
|
344
|
+
if (!partialToken) {
|
|
345
|
+
return {
|
|
346
|
+
hasCommands: true,
|
|
347
|
+
normalizedInput,
|
|
348
|
+
completedTokens,
|
|
349
|
+
partialToken: "",
|
|
350
|
+
breadcrumbs,
|
|
351
|
+
suggestions: branchItems,
|
|
352
|
+
exactNode: null,
|
|
353
|
+
error: null
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const exactChild = branchItems.find((item) => matchesCommandToken(item.node, partialToken)) ?? null;
|
|
357
|
+
const cmdFzf = new Fzf(branchItems, {
|
|
358
|
+
selector: (item) => item.command,
|
|
359
|
+
tiebreakers: [byLengthAsc],
|
|
360
|
+
casing: "case-insensitive"
|
|
361
|
+
});
|
|
362
|
+
const cmdHits = /* @__PURE__ */ new Map();
|
|
363
|
+
for (const res of cmdFzf.find(partialToken)) {
|
|
364
|
+
cmdHits.set(res.item.value, {
|
|
365
|
+
score: res.score,
|
|
366
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const labelFzf = new Fzf(branchItems, {
|
|
370
|
+
selector: (item) => item.label,
|
|
371
|
+
tiebreakers: [byLengthAsc],
|
|
372
|
+
casing: "case-insensitive"
|
|
373
|
+
});
|
|
374
|
+
const labelHits = /* @__PURE__ */ new Map();
|
|
375
|
+
for (const res of labelFzf.find(partialToken)) {
|
|
376
|
+
labelHits.set(res.item.value, {
|
|
377
|
+
score: res.score,
|
|
378
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
const combinedFzf = new Fzf(branchItems, {
|
|
382
|
+
selector: (item) => [item.command, ...item.aliases, item.label, item.description ?? "", ...item.node.keywords ?? []].join(" "),
|
|
383
|
+
tiebreakers: [byLengthAsc],
|
|
384
|
+
casing: "case-insensitive"
|
|
385
|
+
});
|
|
386
|
+
const suggestionMap = /* @__PURE__ */ new Map();
|
|
387
|
+
for (const res of combinedFzf.find(partialToken)) {
|
|
388
|
+
const cmdHit = cmdHits.get(res.item.value);
|
|
389
|
+
const labelHit = labelHits.get(res.item.value);
|
|
390
|
+
const isExact = exactChild?.value === res.item.value;
|
|
391
|
+
const isPrefix = res.item.command.toLowerCase().startsWith(partialToken.toLowerCase());
|
|
392
|
+
const score = (cmdHit ? cmdHit.score + 50 : res.score) + (isExact ? 500 : 0) + (isPrefix ? 100 : 0);
|
|
393
|
+
suggestionMap.set(res.item.value, {
|
|
394
|
+
...res.item,
|
|
395
|
+
commandMatchPositions: cmdHit?.positions ?? [],
|
|
396
|
+
matchPositions: labelHit?.positions ?? [],
|
|
397
|
+
score
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const suggestions = Array.from(suggestionMap.values()).sort((a, b) => {
|
|
401
|
+
const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
|
|
402
|
+
if (scoreDiff !== 0) return scoreDiff;
|
|
403
|
+
return a.command.length - b.command.length;
|
|
404
|
+
});
|
|
405
|
+
const error = suggestions.length === 0 ? `Unknown command: ${[...completedTokens, partialToken].join(" ")}` : null;
|
|
406
|
+
return {
|
|
407
|
+
hasCommands: true,
|
|
408
|
+
normalizedInput,
|
|
409
|
+
completedTokens,
|
|
410
|
+
partialToken,
|
|
411
|
+
breadcrumbs,
|
|
412
|
+
suggestions,
|
|
413
|
+
exactNode: exactChild ? suggestionMap.get(exactChild.value) ?? exactChild : null,
|
|
414
|
+
error
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function formatCommandMenuCompletionInput(completedTokens, item, appendBranchSpace = true) {
|
|
418
|
+
const nextTokens = [...completedTokens, item.command].join(" ");
|
|
419
|
+
return item.isBranch && appendBranchSpace ? `:${nextTokens} ` : `:${nextTokens}`;
|
|
420
|
+
}
|
|
421
|
+
function splitHighlightSegments(text, matchPositions) {
|
|
422
|
+
if (!text) return [];
|
|
423
|
+
if (!matchPositions || matchPositions.length === 0) {
|
|
424
|
+
return [{ text, highlight: false }];
|
|
425
|
+
}
|
|
426
|
+
const posSet = new Set(matchPositions);
|
|
427
|
+
const segments = [];
|
|
428
|
+
let currentText = "";
|
|
429
|
+
let currentHighlight = posSet.has(0);
|
|
430
|
+
for (let i = 0; i < text.length; i++) {
|
|
431
|
+
const isHighlighted = posSet.has(i);
|
|
432
|
+
if (i > 0 && isHighlighted !== currentHighlight) {
|
|
433
|
+
segments.push({ text: currentText, highlight: currentHighlight });
|
|
434
|
+
currentText = text[i];
|
|
435
|
+
currentHighlight = isHighlighted;
|
|
436
|
+
} else {
|
|
437
|
+
currentText += text[i];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (currentText.length > 0) {
|
|
441
|
+
segments.push({ text: currentText, highlight: currentHighlight });
|
|
442
|
+
}
|
|
443
|
+
return segments;
|
|
444
|
+
}
|
|
445
|
+
function announceCommandMessage(message) {
|
|
446
|
+
if (typeof document === "undefined" || !message) return;
|
|
447
|
+
try {
|
|
448
|
+
if (!sharedLiveRegion) {
|
|
449
|
+
sharedLiveRegion = createLiveRegion({ level: "polite", document });
|
|
450
|
+
}
|
|
451
|
+
sharedLiveRegion.announce(message, 150);
|
|
452
|
+
} catch {
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function matchesCommandHotkey(event, hotkey) {
|
|
456
|
+
if (!hotkey) return false;
|
|
457
|
+
const trimmed = hotkey.trim();
|
|
458
|
+
if (trimmed === ":") {
|
|
459
|
+
if (isEditableTarget(event.target)) return false;
|
|
460
|
+
return !event.metaKey && !event.ctrlKey && !event.altKey && event.key === ":";
|
|
461
|
+
}
|
|
462
|
+
try {
|
|
463
|
+
if (matchesKeyboardEvent(event, hotkey)) {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
} catch {
|
|
467
|
+
}
|
|
468
|
+
const normalized = trimmed.toLowerCase();
|
|
469
|
+
if (normalized === "mod+k" || normalized === "cmd+k" || normalized === "ctrl+k") {
|
|
470
|
+
return (event.metaKey || event.ctrlKey) && !event.altKey && event.key.toLowerCase() === "k";
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
function shouldHandleCommandHotkey(anchorEl, selector) {
|
|
475
|
+
if (!anchorEl || typeof document === "undefined") return true;
|
|
476
|
+
if (!isHotkeyAnchorVisible(anchorEl)) return false;
|
|
477
|
+
const myPreview = anchorEl.closest("[data-example-preview]");
|
|
478
|
+
const activePreview = document.activeElement?.closest?.("[data-example-preview]") ?? null;
|
|
479
|
+
if (activePreview) {
|
|
480
|
+
return myPreview === activePreview;
|
|
481
|
+
}
|
|
482
|
+
if (myPreview) {
|
|
483
|
+
const previewAnchors = Array.from(
|
|
484
|
+
document.querySelectorAll(`[data-example-preview] ${selector}`)
|
|
485
|
+
).filter(isHotkeyAnchorVisible);
|
|
486
|
+
return previewAnchors[0] === anchorEl;
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
function resolveCommandMenuGridStyle(columns = "auto", itemCount) {
|
|
491
|
+
if (columns === 1 || itemCount <= 0) {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
|
|
495
|
+
const colCount = Math.max(1, Math.min(maxCols, itemCount));
|
|
496
|
+
const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
|
|
497
|
+
return {
|
|
498
|
+
display: "grid",
|
|
499
|
+
gridAutoFlow: "column",
|
|
500
|
+
gridTemplateRows: `repeat(${rowCount}, minmax(0, auto))`,
|
|
501
|
+
gridTemplateColumns: `repeat(${colCount}, minmax(0, 1fr))`
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function resolveCommandMenuGridNavigation(columns = "auto", itemCount, currentIdx, key) {
|
|
505
|
+
if (itemCount <= 0) return -1;
|
|
506
|
+
const safeIdx = currentIdx >= 0 && currentIdx < itemCount ? currentIdx : 0;
|
|
507
|
+
if (key === "ArrowDown") {
|
|
508
|
+
return (safeIdx + 1) % itemCount;
|
|
509
|
+
}
|
|
510
|
+
if (key === "ArrowUp") {
|
|
511
|
+
return (safeIdx - 1 + itemCount) % itemCount;
|
|
512
|
+
}
|
|
513
|
+
if (columns === 1) {
|
|
514
|
+
return safeIdx;
|
|
515
|
+
}
|
|
516
|
+
const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
|
|
517
|
+
const colCount = Math.max(1, Math.min(maxCols, itemCount));
|
|
518
|
+
const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
|
|
519
|
+
const totalCols = Math.max(1, Math.ceil(itemCount / rowCount));
|
|
520
|
+
const row = safeIdx % rowCount;
|
|
521
|
+
const col = Math.floor(safeIdx / rowCount);
|
|
522
|
+
const nextCol = key === "ArrowRight" ? (col + 1) % totalCols : (col - 1 + totalCols) % totalCols;
|
|
523
|
+
return Math.min(nextCol * rowCount + row, itemCount - 1);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/command/styles.ts
|
|
527
|
+
import { cva } from "class-variance-authority";
|
|
528
|
+
var commandPaletteVariants = cva(
|
|
529
|
+
"flex w-full flex-col overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-2xl outline-none",
|
|
530
|
+
{
|
|
531
|
+
variants: {
|
|
532
|
+
size: {
|
|
533
|
+
sm: "max-w-md",
|
|
534
|
+
md: "max-w-xl",
|
|
535
|
+
lg: "max-w-2xl"
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
defaultVariants: {
|
|
539
|
+
size: "md"
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
);
|
|
543
|
+
var commandPalettePositionerBase = "items-center justify-center p-4";
|
|
544
|
+
var commandPaletteDialogContentBase = "my-auto gap-0 overflow-hidden p-0 sm:max-w-xl";
|
|
545
|
+
var commandPaletteHeaderBase = "flex items-center gap-2 border-b border-border px-3 py-2.5";
|
|
546
|
+
var commandPaletteBreadcrumbBase = "inline-flex shrink-0 items-center gap-1 rounded-md bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground";
|
|
547
|
+
var commandPaletteInputBase = "flex-1 border-0 bg-transparent px-1 py-0.5 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-0";
|
|
548
|
+
var commandPaletteListBase = "max-h-80 overflow-y-auto p-1.5 outline-none";
|
|
549
|
+
var commandPaletteItemBase = "group relative flex w-full cursor-pointer select-none items-center justify-between gap-3 rounded-lg px-2.5 py-2 text-sm outline-none transition-colors data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
|
|
550
|
+
var commandPaletteFooterBase = "flex flex-wrap items-center justify-between gap-2 border-t border-border bg-muted/30 px-3 py-2 text-[11px] text-muted-foreground";
|
|
551
|
+
var commandPaletteStyles = {
|
|
552
|
+
root: commandPaletteVariants,
|
|
553
|
+
positioner: commandPalettePositionerBase,
|
|
554
|
+
dialogContent: commandPaletteDialogContentBase,
|
|
555
|
+
header: commandPaletteHeaderBase,
|
|
556
|
+
breadcrumb: commandPaletteBreadcrumbBase,
|
|
557
|
+
input: commandPaletteInputBase,
|
|
558
|
+
list: commandPaletteListBase,
|
|
559
|
+
item: commandPaletteItemBase,
|
|
560
|
+
footer: commandPaletteFooterBase
|
|
561
|
+
};
|
|
562
|
+
var commandMenuVariants = cva(
|
|
563
|
+
"flex w-full flex-col overflow-hidden border border-border bg-popover font-mono text-popover-foreground shadow-2xl outline-none",
|
|
564
|
+
{
|
|
565
|
+
variants: {
|
|
566
|
+
size: {
|
|
567
|
+
sm: "text-xs",
|
|
568
|
+
md: "text-sm",
|
|
569
|
+
lg: "text-base"
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
defaultVariants: {
|
|
573
|
+
size: "md"
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
);
|
|
577
|
+
var commandMenuPositionerBase = "items-end justify-stretch p-0!";
|
|
578
|
+
var commandMenuDialogContentBase = "fixed inset-x-0 bottom-0 top-auto my-0 w-full max-w-none translate-x-0 translate-y-0 gap-0 overflow-hidden rounded-none border-x-0 border-b-0 border-t border-border p-0 shadow-2xl sm:max-w-none sm:rounded-none";
|
|
579
|
+
var commandMenuListVariants = cva("overflow-y-auto border-b border-border bg-popover/95 outline-none", {
|
|
580
|
+
variants: {
|
|
581
|
+
columns: {
|
|
582
|
+
auto: "grid! grid-flow-col!",
|
|
583
|
+
1: "flex flex-col",
|
|
584
|
+
2: "grid! grid-flow-col!",
|
|
585
|
+
3: "grid! grid-flow-col!",
|
|
586
|
+
4: "grid! grid-flow-col!"
|
|
587
|
+
},
|
|
588
|
+
size: {
|
|
589
|
+
sm: "max-h-44 gap-x-2 gap-y-0.5 px-2 py-1",
|
|
590
|
+
md: "max-h-60 gap-x-3 gap-y-1 p-2",
|
|
591
|
+
lg: "max-h-72 gap-x-4 gap-y-1.5 p-3"
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
defaultVariants: {
|
|
595
|
+
columns: "auto",
|
|
596
|
+
size: "md"
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
var commandMenuItemVariants = cva(
|
|
600
|
+
"group relative flex min-w-0 w-full cursor-pointer select-none items-center justify-between gap-2 rounded-md font-mono outline-none transition-colors data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
601
|
+
{
|
|
602
|
+
variants: {
|
|
603
|
+
size: {
|
|
604
|
+
sm: "px-1.5 py-0.5 text-[11px] leading-tight",
|
|
605
|
+
md: "px-2.5 py-1.5 text-xs",
|
|
606
|
+
lg: "px-3 py-2 text-sm"
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
defaultVariants: {
|
|
610
|
+
size: "md"
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
);
|
|
614
|
+
var commandMenuPromptBarVariants = cva(
|
|
615
|
+
"flex w-full items-center border-t border-border/60 bg-muted/50 font-mono",
|
|
616
|
+
{
|
|
617
|
+
variants: {
|
|
618
|
+
size: {
|
|
619
|
+
sm: "gap-1 px-2 py-1 text-xs",
|
|
620
|
+
md: "gap-1.5 px-3 py-2 text-sm",
|
|
621
|
+
lg: "gap-2 px-4 py-2.5 text-base"
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
defaultVariants: {
|
|
625
|
+
size: "md"
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
var commandMenuPrefixBase = "select-none font-mono font-bold text-primary";
|
|
630
|
+
var commandMenuInputVariants = cva(
|
|
631
|
+
"flex-1 border-0 bg-transparent font-mono text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-0",
|
|
632
|
+
{
|
|
633
|
+
variants: {
|
|
634
|
+
size: {
|
|
635
|
+
sm: "px-0.5 py-0 text-xs",
|
|
636
|
+
md: "px-1 py-0.5 text-sm",
|
|
637
|
+
lg: "px-1.5 py-1 text-base"
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
defaultVariants: {
|
|
641
|
+
size: "md"
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
);
|
|
645
|
+
var commandMenuErrorBase = "flex items-center justify-between gap-2 border-t border-destructive/30 bg-destructive/10 px-3 py-1.5 font-mono text-xs text-destructive";
|
|
646
|
+
var commandMenuStyles = {
|
|
647
|
+
root: commandMenuVariants,
|
|
648
|
+
positioner: commandMenuPositionerBase,
|
|
649
|
+
dialogContent: commandMenuDialogContentBase,
|
|
650
|
+
list: commandMenuListVariants,
|
|
651
|
+
item: commandMenuItemVariants,
|
|
652
|
+
promptBar: commandMenuPromptBarVariants,
|
|
653
|
+
prefix: commandMenuPrefixBase,
|
|
654
|
+
input: commandMenuInputVariants,
|
|
655
|
+
error: commandMenuErrorBase
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
export {
|
|
659
|
+
__export,
|
|
660
|
+
__reExport,
|
|
661
|
+
createCommandTree,
|
|
662
|
+
resolveCommandLevel,
|
|
663
|
+
resolveCommandMenuState,
|
|
664
|
+
formatCommandMenuCompletionInput,
|
|
665
|
+
splitHighlightSegments,
|
|
666
|
+
announceCommandMessage,
|
|
667
|
+
matchesCommandHotkey,
|
|
668
|
+
shouldHandleCommandHotkey,
|
|
669
|
+
resolveCommandMenuGridStyle,
|
|
670
|
+
resolveCommandMenuGridNavigation,
|
|
671
|
+
commandPaletteVariants,
|
|
672
|
+
commandPalettePositionerBase,
|
|
673
|
+
commandPaletteDialogContentBase,
|
|
674
|
+
commandPaletteHeaderBase,
|
|
675
|
+
commandPaletteBreadcrumbBase,
|
|
676
|
+
commandPaletteInputBase,
|
|
677
|
+
commandPaletteListBase,
|
|
678
|
+
commandPaletteItemBase,
|
|
679
|
+
commandPaletteFooterBase,
|
|
680
|
+
commandPaletteStyles,
|
|
681
|
+
commandMenuVariants,
|
|
682
|
+
commandMenuPositionerBase,
|
|
683
|
+
commandMenuDialogContentBase,
|
|
684
|
+
commandMenuListVariants,
|
|
685
|
+
commandMenuItemVariants,
|
|
686
|
+
commandMenuPromptBarVariants,
|
|
687
|
+
commandMenuPrefixBase,
|
|
688
|
+
commandMenuInputVariants,
|
|
689
|
+
commandMenuErrorBase,
|
|
690
|
+
commandMenuStyles
|
|
691
|
+
};
|