@cloudvoyant/helical-ui 0.21.1 → 0.22.0
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/index.cjs +1038 -57
- package/dist/index.d.cts +314 -10
- package/dist/index.d.ts +314 -10
- package/dist/index.js +992 -57
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1212,7 +1212,15 @@ var listboxItemGroupLabelBase = "px-2 py-1 text-[11px] font-semibold tracking-wi
|
|
|
1212
1212
|
|
|
1213
1213
|
// src/kbd.ts
|
|
1214
1214
|
import { cva as cva19 } from "class-variance-authority";
|
|
1215
|
-
import {
|
|
1215
|
+
import {
|
|
1216
|
+
ALL_KEYS,
|
|
1217
|
+
detectPlatform,
|
|
1218
|
+
formatForDisplay,
|
|
1219
|
+
hasNonModifierKey,
|
|
1220
|
+
isModifierKey,
|
|
1221
|
+
normalizeKeyName,
|
|
1222
|
+
validateHotkey
|
|
1223
|
+
} from "@tanstack/hotkeys";
|
|
1216
1224
|
var kbdVariants = cva19(
|
|
1217
1225
|
"inline-flex shrink-0 items-center justify-center gap-0.5 rounded border font-mono font-medium leading-none tracking-tight select-none",
|
|
1218
1226
|
{
|
|
@@ -1226,30 +1234,115 @@ var kbdVariants = cva19(
|
|
|
1226
1234
|
sm: "min-h-4 min-w-4 px-1 py-0.5 text-[10px]",
|
|
1227
1235
|
md: "min-h-5 min-w-5 px-1.5 py-0.5 text-xs",
|
|
1228
1236
|
lg: "min-h-6 min-w-6 px-2 py-1 text-sm"
|
|
1237
|
+
},
|
|
1238
|
+
invalid: {
|
|
1239
|
+
true: "border-destructive/70 bg-destructive/10 text-destructive line-through decoration-destructive/70",
|
|
1240
|
+
false: ""
|
|
1229
1241
|
}
|
|
1230
1242
|
},
|
|
1231
1243
|
defaultVariants: {
|
|
1232
1244
|
variant: "outline",
|
|
1233
|
-
size: "md"
|
|
1245
|
+
size: "md",
|
|
1246
|
+
invalid: false
|
|
1234
1247
|
}
|
|
1235
1248
|
}
|
|
1236
1249
|
);
|
|
1237
1250
|
var kbdGroupBase = "inline-flex items-center gap-1";
|
|
1238
1251
|
var KEY_LABEL_OVERRIDES = {
|
|
1239
1252
|
Space: "Space",
|
|
1253
|
+
Spacebar: "Space",
|
|
1240
1254
|
" ": "Space",
|
|
1241
1255
|
Escape: "Esc",
|
|
1256
|
+
Esc: "Esc",
|
|
1242
1257
|
Backspace: "\u232B",
|
|
1258
|
+
Delete: "\u2326",
|
|
1259
|
+
Del: "\u2326",
|
|
1243
1260
|
Enter: "\u21B5",
|
|
1261
|
+
Return: "\u21B5",
|
|
1262
|
+
Tab: "Tab",
|
|
1244
1263
|
ArrowUp: "\u2191",
|
|
1245
1264
|
ArrowDown: "\u2193",
|
|
1246
1265
|
ArrowLeft: "\u2190",
|
|
1247
1266
|
ArrowRight: "\u2192"
|
|
1248
1267
|
};
|
|
1268
|
+
var ALL_KEYS_SET = ALL_KEYS;
|
|
1269
|
+
function isKnownSingleKey(keyPart) {
|
|
1270
|
+
if (!keyPart) return false;
|
|
1271
|
+
if (Object.hasOwn(KEY_LABEL_OVERRIDES, keyPart)) return true;
|
|
1272
|
+
if (ALL_KEYS_SET.has(keyPart)) return true;
|
|
1273
|
+
if (keyPart.length === 1 && ALL_KEYS_SET.has(normalizeKeyName(keyPart))) return true;
|
|
1274
|
+
if (/^\[[A-Za-z][A-Za-z0-9]*\]$/.test(keyPart)) {
|
|
1275
|
+
return validateHotkey(keyPart).valid;
|
|
1276
|
+
}
|
|
1277
|
+
return false;
|
|
1278
|
+
}
|
|
1279
|
+
function inferPlatform() {
|
|
1280
|
+
const hint = typeof navigator !== "undefined" ? `${navigator.platform ?? ""} ${navigator.userAgent ?? ""}`.trim() : void 0;
|
|
1281
|
+
return detectPlatform(hint || void 0);
|
|
1282
|
+
}
|
|
1283
|
+
function validateKbdChord(chord) {
|
|
1284
|
+
const trimmed = chord.trim();
|
|
1285
|
+
if (!trimmed) {
|
|
1286
|
+
return { valid: false, warnings: [], errors: ["Hotkey cannot be empty"] };
|
|
1287
|
+
}
|
|
1288
|
+
if (trimmed.length > 1 && (trimmed.startsWith("+") || /[^+]\+$/.test(trimmed) || trimmed.includes("++") && !trimmed.endsWith("++"))) {
|
|
1289
|
+
return {
|
|
1290
|
+
valid: false,
|
|
1291
|
+
warnings: [],
|
|
1292
|
+
errors: [`Invalid hotkey format in '${trimmed}': empty modifier or key part`]
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
const baseResult = validateHotkey(trimmed);
|
|
1296
|
+
if (!baseResult.valid) {
|
|
1297
|
+
return baseResult;
|
|
1298
|
+
}
|
|
1299
|
+
if (trimmed.includes("+") && trimmed.length > 1) {
|
|
1300
|
+
if (!hasNonModifierKey(trimmed)) {
|
|
1301
|
+
return {
|
|
1302
|
+
valid: false,
|
|
1303
|
+
warnings: baseResult.warnings,
|
|
1304
|
+
errors: [...baseResult.errors, `Modifier-only chord '${trimmed}' is missing an action key`]
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
const rawParts = trimmed.endsWith("++") ? [...trimmed.slice(0, -2).split("+"), "+"] : trimmed.split("+");
|
|
1308
|
+
const keyPart = rawParts[rawParts.length - 1]?.trim() ?? "";
|
|
1309
|
+
if (!isKnownSingleKey(keyPart)) {
|
|
1310
|
+
return {
|
|
1311
|
+
valid: false,
|
|
1312
|
+
warnings: baseResult.warnings,
|
|
1313
|
+
errors: [...baseResult.errors, `Unknown key: '${keyPart}'`]
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
return baseResult;
|
|
1317
|
+
}
|
|
1318
|
+
if (trimmed.length === 1 || isKnownSingleKey(trimmed) || isModifierKey(trimmed)) {
|
|
1319
|
+
return baseResult;
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
valid: false,
|
|
1323
|
+
warnings: baseResult.warnings,
|
|
1324
|
+
errors: [...baseResult.errors, `Unknown key: '${trimmed}'`]
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
function validateKbdHotkey(hotkey) {
|
|
1328
|
+
const rawSteps = Array.isArray(hotkey) ? hotkey : typeof hotkey === "string" ? hotkey.trim().split(/\s+/).filter(Boolean) : [];
|
|
1329
|
+
if (rawSteps.length === 0) {
|
|
1330
|
+
return { valid: false, warnings: [], errors: ["Hotkey cannot be empty"] };
|
|
1331
|
+
}
|
|
1332
|
+
if (rawSteps.length === 1) {
|
|
1333
|
+
return validateKbdChord(rawSteps[0]);
|
|
1334
|
+
}
|
|
1335
|
+
const results = rawSteps.map((step) => validateKbdChord(step));
|
|
1336
|
+
return {
|
|
1337
|
+
valid: results.every((r) => r.valid),
|
|
1338
|
+
warnings: results.flatMap((r, idx) => r.warnings.map((w) => `Step ${idx + 1}: ${w}`)),
|
|
1339
|
+
errors: results.flatMap((r, idx) => r.errors.map((e) => `Step ${idx + 1}: ${e}`))
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1249
1342
|
function formatKeyChord(chord, options) {
|
|
1250
1343
|
const trimmed = chord.trim();
|
|
1251
1344
|
if (!trimmed) return "";
|
|
1252
|
-
if (KEY_LABEL_OVERRIDES
|
|
1345
|
+
if (Object.hasOwn(KEY_LABEL_OVERRIDES, trimmed)) {
|
|
1253
1346
|
return KEY_LABEL_OVERRIDES[trimmed];
|
|
1254
1347
|
}
|
|
1255
1348
|
if (trimmed.length === 1) {
|
|
@@ -1258,9 +1351,13 @@ function formatKeyChord(chord, options) {
|
|
|
1258
1351
|
if (/^Shift\+([a-zA-Z])$/.test(trimmed)) {
|
|
1259
1352
|
return trimmed.slice(-1).toUpperCase();
|
|
1260
1353
|
}
|
|
1354
|
+
const validation = validateKbdChord(trimmed);
|
|
1355
|
+
if (!validation.valid) {
|
|
1356
|
+
return trimmed;
|
|
1357
|
+
}
|
|
1261
1358
|
try {
|
|
1262
1359
|
const formatted = formatForDisplay(trimmed, {
|
|
1263
|
-
platform:
|
|
1360
|
+
platform: inferPlatform(),
|
|
1264
1361
|
useSymbols: options?.useSymbols ?? true
|
|
1265
1362
|
});
|
|
1266
1363
|
return formatted || trimmed;
|
|
@@ -1269,9 +1366,721 @@ function formatKeyChord(chord, options) {
|
|
|
1269
1366
|
}
|
|
1270
1367
|
}
|
|
1271
1368
|
function formatKeySequence(hotkey, options) {
|
|
1272
|
-
const steps =
|
|
1369
|
+
const steps = typeof hotkey === "string" ? hotkey.trim().split(/\s+/).filter(Boolean) : hotkey;
|
|
1273
1370
|
return steps.map((step) => formatKeyChord(step, options));
|
|
1274
1371
|
}
|
|
1372
|
+
function resolveKbdSteps(hotkey, options) {
|
|
1373
|
+
const rawSteps = Array.isArray(hotkey) ? [...hotkey] : typeof hotkey === "string" ? hotkey.trim().split(/\s+/).filter(Boolean) : [];
|
|
1374
|
+
if (rawSteps.length === 0) {
|
|
1375
|
+
const msg = "Hotkey cannot be empty";
|
|
1376
|
+
if (options?.warn !== false) {
|
|
1377
|
+
console.warn(`[helical-ui/Kbd] Invalid hotkey "${String(hotkey)}": ${msg}`);
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
steps: [{ raw: "", label: "?", valid: false, errors: [msg], warnings: [] }],
|
|
1381
|
+
valid: false,
|
|
1382
|
+
message: msg
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
const steps = rawSteps.map((raw) => {
|
|
1386
|
+
const validation = validateKbdChord(raw);
|
|
1387
|
+
const label = validation.valid ? formatKeyChord(raw, options) : raw.trim() || "?";
|
|
1388
|
+
return {
|
|
1389
|
+
raw,
|
|
1390
|
+
label,
|
|
1391
|
+
valid: validation.valid,
|
|
1392
|
+
errors: validation.errors,
|
|
1393
|
+
warnings: validation.warnings
|
|
1394
|
+
};
|
|
1395
|
+
});
|
|
1396
|
+
const valid = steps.every((s) => s.valid);
|
|
1397
|
+
const allMessages = steps.flatMap((s, idx) => {
|
|
1398
|
+
const prefix = steps.length > 1 ? `Step ${idx + 1} (${s.raw}): ` : "";
|
|
1399
|
+
return [...s.errors, ...s.warnings].map((m) => `${prefix}${m}`);
|
|
1400
|
+
});
|
|
1401
|
+
const message = allMessages.length > 0 ? allMessages.join("; ") : void 0;
|
|
1402
|
+
if (!valid && options?.warn !== false) {
|
|
1403
|
+
const rawDisplay = Array.isArray(hotkey) ? hotkey.join(" ") : hotkey;
|
|
1404
|
+
console.warn(`[helical-ui/Kbd] Invalid hotkey "${rawDisplay}": ${message}`);
|
|
1405
|
+
}
|
|
1406
|
+
return { steps, valid, message };
|
|
1407
|
+
}
|
|
1408
|
+
function isChordCommandString(value) {
|
|
1409
|
+
const trimmed = value.trim();
|
|
1410
|
+
if (!trimmed || trimmed.length <= 1) return false;
|
|
1411
|
+
if (trimmed.includes("+")) return true;
|
|
1412
|
+
if (/\s+/.test(trimmed)) {
|
|
1413
|
+
const tokens = trimmed.split(/\s+/).filter(Boolean);
|
|
1414
|
+
return tokens.length > 1 && tokens.every((t) => validateKbdChord(t).valid);
|
|
1415
|
+
}
|
|
1416
|
+
return false;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// src/toast.ts
|
|
1420
|
+
import { cva as cva20 } from "class-variance-authority";
|
|
1421
|
+
var toasterBase = [
|
|
1422
|
+
"w-[calc(100%-var(--viewport-offset-left))] sm:w-(--width) [--width:22.25rem]",
|
|
1423
|
+
"data-[align=center]:left-[calc(var(--viewport-offset-right)/2)]!",
|
|
1424
|
+
"sm:data-[align=center]:w-full"
|
|
1425
|
+
].join(" ");
|
|
1426
|
+
var toastVariants = cva20(
|
|
1427
|
+
[
|
|
1428
|
+
"z-(--z-index) translate-x-(--x) translate-y-(--y) opacity-(--opacity)",
|
|
1429
|
+
"data-[overlap]:scale-[calc(1-var(--index,0)*0.04)]",
|
|
1430
|
+
"relative w-[calc(100%-var(--viewport-offset-left))] sm:w-(--width)",
|
|
1431
|
+
"flex items-start justify-between gap-2.5 rounded-lg border border-border bg-popover px-3.5 py-3 text-sm text-popover-foreground shadow-lg select-none outline-none",
|
|
1432
|
+
"transition-[translate,scale,opacity,height] duration-250 ease-[cubic-bezier(0.21,1.02,0.73,1)] will-change-[translate,opacity,scale]",
|
|
1433
|
+
"data-[state=closed]:duration-200 data-[state=closed]:ease-[cubic-bezier(0.06,0.71,0.55,1)]",
|
|
1434
|
+
"motion-reduce:transition-none!",
|
|
1435
|
+
"data-[type=info]:border-info/30",
|
|
1436
|
+
"data-[type=success]:border-success/30",
|
|
1437
|
+
"data-[type=warning]:border-warn/30",
|
|
1438
|
+
"data-[type=error]:border-danger/30"
|
|
1439
|
+
].join(" ")
|
|
1440
|
+
);
|
|
1441
|
+
var toastIconBase = [
|
|
1442
|
+
"mt-0.5 shrink-0",
|
|
1443
|
+
"in-data-[type=warning]:text-warn",
|
|
1444
|
+
"in-data-[type=success]:text-success",
|
|
1445
|
+
"in-data-[type=error]:text-danger",
|
|
1446
|
+
"in-data-[type=info]:text-info",
|
|
1447
|
+
"in-data-[type=loading]:text-primary",
|
|
1448
|
+
"[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"
|
|
1449
|
+
].join(" ");
|
|
1450
|
+
var toastTitleBase = "text-sm font-medium leading-tight text-popover-foreground";
|
|
1451
|
+
var toastDescriptionBase = "text-xs leading-relaxed text-muted-foreground";
|
|
1452
|
+
var toastActionTriggerBase = "inline-flex h-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-border bg-secondary px-2.5 text-xs font-medium text-secondary-foreground transition-colors hover:bg-secondary/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50";
|
|
1453
|
+
var toastCloseTriggerBase = "inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted-foreground opacity-70 transition-opacity hover:bg-accent hover:text-accent-foreground hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 [&_svg]:pointer-events-none [&_svg]:size-3.5";
|
|
1454
|
+
|
|
1455
|
+
// src/command/core.ts
|
|
1456
|
+
import { matchesKeyboardEvent } from "@tanstack/hotkeys";
|
|
1457
|
+
import { TreeCollection } from "@zag-js/collection";
|
|
1458
|
+
import { createFilter } from "@zag-js/i18n-utils";
|
|
1459
|
+
import { createLiveRegion } from "@zag-js/live-region";
|
|
1460
|
+
import { Fzf, byLengthAsc } from "fzf";
|
|
1461
|
+
var ROOT_NODE_VALUE = "__root__";
|
|
1462
|
+
var DEFAULT_GROUP_LABEL = "Commands";
|
|
1463
|
+
var i18nFilter = createFilter({ sensitivity: "base" });
|
|
1464
|
+
var sharedLiveRegion = null;
|
|
1465
|
+
function getNodeCommandToken(node) {
|
|
1466
|
+
return (node.command ?? node.value).trim();
|
|
1467
|
+
}
|
|
1468
|
+
function isEditableTarget(target) {
|
|
1469
|
+
if (!target || typeof target !== "object") return false;
|
|
1470
|
+
const el = target;
|
|
1471
|
+
if (el.isContentEditable) return true;
|
|
1472
|
+
const tag = el.tagName?.toLowerCase();
|
|
1473
|
+
if (tag === "input" || tag === "textarea" || tag === "select") return true;
|
|
1474
|
+
if (typeof el.closest === "function" && el.closest('[contenteditable="true"], .ProseMirror')) {
|
|
1475
|
+
return true;
|
|
1476
|
+
}
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
function toFlatItem(node, ancestorPath, ancestorLabels, ancestorCommands, tree, fallbackGroup) {
|
|
1480
|
+
const cmd = getNodeCommandToken(node);
|
|
1481
|
+
const valuePath = [...ancestorPath, node.value];
|
|
1482
|
+
const commandTokens = [...ancestorCommands, cmd];
|
|
1483
|
+
const isBranch = tree.isBranchNode(node);
|
|
1484
|
+
const group = node.group ?? fallbackGroup ?? (ancestorLabels.length > 0 ? ancestorLabels[ancestorLabels.length - 1] : DEFAULT_GROUP_LABEL);
|
|
1485
|
+
return {
|
|
1486
|
+
value: valuePath.join("/"),
|
|
1487
|
+
label: node.label,
|
|
1488
|
+
description: node.description,
|
|
1489
|
+
group,
|
|
1490
|
+
command: cmd,
|
|
1491
|
+
fullCommand: `:${commandTokens.join(" ")}`,
|
|
1492
|
+
aliases: node.aliases ?? [],
|
|
1493
|
+
shortcut: node.shortcut,
|
|
1494
|
+
badge: node.badge,
|
|
1495
|
+
active: Boolean(node.active),
|
|
1496
|
+
disabled: Boolean(node.disabled),
|
|
1497
|
+
isBranch,
|
|
1498
|
+
valuePath,
|
|
1499
|
+
breadcrumbLabels: ancestorLabels,
|
|
1500
|
+
node
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function groupCommandItems(items) {
|
|
1504
|
+
const map = /* @__PURE__ */ new Map();
|
|
1505
|
+
for (const item of items) {
|
|
1506
|
+
const groupLabel = item.group || DEFAULT_GROUP_LABEL;
|
|
1507
|
+
const list = map.get(groupLabel);
|
|
1508
|
+
if (list) {
|
|
1509
|
+
list.push(item);
|
|
1510
|
+
} else {
|
|
1511
|
+
map.set(groupLabel, [item]);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return Array.from(map.entries()).map(([label, groupItems]) => ({
|
|
1515
|
+
label,
|
|
1516
|
+
items: groupItems
|
|
1517
|
+
}));
|
|
1518
|
+
}
|
|
1519
|
+
function collectDeepFlatItems(parentNode, ancestorPath, ancestorLabels, ancestorCommands, tree, out) {
|
|
1520
|
+
const children = tree.getNodeChildren(parentNode);
|
|
1521
|
+
for (const child of children) {
|
|
1522
|
+
const flat = toFlatItem(child, ancestorPath, ancestorLabels, ancestorCommands, tree);
|
|
1523
|
+
out.push(flat);
|
|
1524
|
+
if (tree.isBranchNode(child)) {
|
|
1525
|
+
collectDeepFlatItems(
|
|
1526
|
+
child,
|
|
1527
|
+
[...ancestorPath, child.value],
|
|
1528
|
+
[...ancestorLabels, child.label],
|
|
1529
|
+
[...ancestorCommands, getNodeCommandToken(child)],
|
|
1530
|
+
tree,
|
|
1531
|
+
out
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
function matchesCommandToken(node, token) {
|
|
1537
|
+
const lower = token.toLowerCase();
|
|
1538
|
+
const cmd = getNodeCommandToken(node).toLowerCase();
|
|
1539
|
+
if (cmd === lower || node.value.toLowerCase() === lower) {
|
|
1540
|
+
return true;
|
|
1541
|
+
}
|
|
1542
|
+
return (node.aliases ?? []).some((alias) => alias.toLowerCase() === lower);
|
|
1543
|
+
}
|
|
1544
|
+
function createCommandTree(items) {
|
|
1545
|
+
if (items instanceof TreeCollection) {
|
|
1546
|
+
return items;
|
|
1547
|
+
}
|
|
1548
|
+
const rootNode = {
|
|
1549
|
+
value: ROOT_NODE_VALUE,
|
|
1550
|
+
label: "Root",
|
|
1551
|
+
children: items ?? []
|
|
1552
|
+
};
|
|
1553
|
+
return new TreeCollection({
|
|
1554
|
+
rootNode,
|
|
1555
|
+
nodeToValue: (node) => node.value,
|
|
1556
|
+
nodeToString: (node) => node.label,
|
|
1557
|
+
isNodeDisabled: (node) => Boolean(node.disabled),
|
|
1558
|
+
nodeToChildren: (node) => node.children ?? []
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
function resolveCommandLevel(tree, activePath = [], query = "", options) {
|
|
1562
|
+
const rootChildren = tree.getNodeChildren(tree.rootNode);
|
|
1563
|
+
const hasCommands = rootChildren.length > 0;
|
|
1564
|
+
if (!hasCommands) {
|
|
1565
|
+
return {
|
|
1566
|
+
hasCommands: false,
|
|
1567
|
+
breadcrumbs: [],
|
|
1568
|
+
items: [],
|
|
1569
|
+
groups: []
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
const breadcrumbs = [];
|
|
1573
|
+
const resolvedValuePath = [];
|
|
1574
|
+
const resolvedLabels = [];
|
|
1575
|
+
const resolvedCommands = [];
|
|
1576
|
+
let currentNode = tree.rootNode;
|
|
1577
|
+
for (const segment of activePath) {
|
|
1578
|
+
const children = tree.getNodeChildren(currentNode);
|
|
1579
|
+
const match = children.find((child) => child.value === segment);
|
|
1580
|
+
if (!match || !tree.isBranchNode(match)) {
|
|
1581
|
+
break;
|
|
1582
|
+
}
|
|
1583
|
+
const cmd = getNodeCommandToken(match);
|
|
1584
|
+
breadcrumbs.push({
|
|
1585
|
+
value: match.value,
|
|
1586
|
+
label: match.label,
|
|
1587
|
+
command: cmd
|
|
1588
|
+
});
|
|
1589
|
+
resolvedValuePath.push(match.value);
|
|
1590
|
+
resolvedLabels.push(match.label);
|
|
1591
|
+
resolvedCommands.push(cmd);
|
|
1592
|
+
currentNode = match;
|
|
1593
|
+
}
|
|
1594
|
+
const trimmedQuery = query.trim();
|
|
1595
|
+
const directChildren = tree.getNodeChildren(currentNode);
|
|
1596
|
+
const directItems = directChildren.map(
|
|
1597
|
+
(child) => toFlatItem(child, resolvedValuePath, resolvedLabels, resolvedCommands, tree)
|
|
1598
|
+
);
|
|
1599
|
+
if (!trimmedQuery) {
|
|
1600
|
+
return {
|
|
1601
|
+
hasCommands: true,
|
|
1602
|
+
breadcrumbs,
|
|
1603
|
+
items: directItems,
|
|
1604
|
+
groups: groupCommandItems(directItems)
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
const normalizedQuery = trimmedQuery.startsWith(":") ? trimmedQuery.slice(1).trim() : trimmedQuery;
|
|
1608
|
+
if (!normalizedQuery) {
|
|
1609
|
+
return {
|
|
1610
|
+
hasCommands: true,
|
|
1611
|
+
breadcrumbs,
|
|
1612
|
+
items: directItems,
|
|
1613
|
+
groups: groupCommandItems(directItems)
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
const allowDeepSearch = options?.deepSearch !== false && breadcrumbs.length === 0;
|
|
1617
|
+
const candidatePool = [];
|
|
1618
|
+
if (allowDeepSearch) {
|
|
1619
|
+
collectDeepFlatItems(currentNode, resolvedValuePath, resolvedLabels, resolvedCommands, tree, candidatePool);
|
|
1620
|
+
} else {
|
|
1621
|
+
candidatePool.push(...directItems);
|
|
1622
|
+
}
|
|
1623
|
+
const labelFzf = new Fzf(candidatePool, {
|
|
1624
|
+
selector: (item) => item.label,
|
|
1625
|
+
tiebreakers: [byLengthAsc],
|
|
1626
|
+
casing: "case-insensitive"
|
|
1627
|
+
});
|
|
1628
|
+
const labelResults = labelFzf.find(normalizedQuery);
|
|
1629
|
+
const labelMatchMap = /* @__PURE__ */ new Map();
|
|
1630
|
+
for (const res of labelResults) {
|
|
1631
|
+
labelMatchMap.set(res.item.value, {
|
|
1632
|
+
score: res.score,
|
|
1633
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
const compositeFzf = new Fzf(candidatePool, {
|
|
1637
|
+
selector: (item) => [
|
|
1638
|
+
item.label,
|
|
1639
|
+
item.command,
|
|
1640
|
+
item.fullCommand,
|
|
1641
|
+
...item.aliases,
|
|
1642
|
+
...item.breadcrumbLabels,
|
|
1643
|
+
item.description ?? "",
|
|
1644
|
+
...item.node.keywords ?? []
|
|
1645
|
+
].join(" "),
|
|
1646
|
+
tiebreakers: [byLengthAsc],
|
|
1647
|
+
casing: "case-insensitive"
|
|
1648
|
+
});
|
|
1649
|
+
const compositeResults = compositeFzf.find(normalizedQuery);
|
|
1650
|
+
const matchedByValue = /* @__PURE__ */ new Map();
|
|
1651
|
+
for (const res of compositeResults) {
|
|
1652
|
+
const labelHit = labelMatchMap.get(res.item.value);
|
|
1653
|
+
const depthPenalty = (res.item.valuePath.length - 1) * 2;
|
|
1654
|
+
const effectiveScore = (labelHit ? labelHit.score + 20 : res.score) - depthPenalty;
|
|
1655
|
+
matchedByValue.set(res.item.value, {
|
|
1656
|
+
...res.item,
|
|
1657
|
+
matchPositions: labelHit?.positions ?? [],
|
|
1658
|
+
score: effectiveScore
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
for (const candidate of candidatePool) {
|
|
1662
|
+
if (matchedByValue.has(candidate.value)) continue;
|
|
1663
|
+
if (i18nFilter.contains(candidate.label, normalizedQuery) || i18nFilter.contains(candidate.command, normalizedQuery)) {
|
|
1664
|
+
matchedByValue.set(candidate.value, {
|
|
1665
|
+
...candidate,
|
|
1666
|
+
matchPositions: [],
|
|
1667
|
+
score: 1
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
const rankedItems = Array.from(matchedByValue.values()).sort((a, b) => {
|
|
1672
|
+
const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
|
|
1673
|
+
if (scoreDiff !== 0) return scoreDiff;
|
|
1674
|
+
if (a.valuePath.length !== b.valuePath.length) {
|
|
1675
|
+
return a.valuePath.length - b.valuePath.length;
|
|
1676
|
+
}
|
|
1677
|
+
return a.label.length - b.label.length;
|
|
1678
|
+
});
|
|
1679
|
+
return {
|
|
1680
|
+
hasCommands: true,
|
|
1681
|
+
breadcrumbs,
|
|
1682
|
+
items: rankedItems,
|
|
1683
|
+
groups: groupCommandItems(rankedItems)
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
function resolveCommandMenuState(tree, rawInput = "") {
|
|
1687
|
+
const rootChildren = tree.getNodeChildren(tree.rootNode);
|
|
1688
|
+
const hasCommands = rootChildren.length > 0;
|
|
1689
|
+
const withoutColon = rawInput.startsWith(":") ? rawInput.slice(1) : rawInput;
|
|
1690
|
+
const normalizedInput = `:${withoutColon}`;
|
|
1691
|
+
if (!hasCommands) {
|
|
1692
|
+
return {
|
|
1693
|
+
hasCommands: false,
|
|
1694
|
+
normalizedInput,
|
|
1695
|
+
completedTokens: [],
|
|
1696
|
+
partialToken: withoutColon.trim(),
|
|
1697
|
+
breadcrumbs: [],
|
|
1698
|
+
suggestions: [],
|
|
1699
|
+
exactNode: null,
|
|
1700
|
+
error: null
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
const hasTrailingSpace = /\s+$/.test(withoutColon);
|
|
1704
|
+
const trimmed = withoutColon.trim();
|
|
1705
|
+
const rawTokens = trimmed.length > 0 ? trimmed.split(/\s+/) : [];
|
|
1706
|
+
const tokensToWalk = hasTrailingSpace ? rawTokens : rawTokens.slice(0, -1);
|
|
1707
|
+
const partialToken = hasTrailingSpace ? "" : rawTokens[rawTokens.length - 1] ?? "";
|
|
1708
|
+
const completedTokens = [];
|
|
1709
|
+
const breadcrumbs = [];
|
|
1710
|
+
const ancestorPath = [];
|
|
1711
|
+
const ancestorLabels = [];
|
|
1712
|
+
let currentNode = tree.rootNode;
|
|
1713
|
+
for (let i = 0; i < tokensToWalk.length; i++) {
|
|
1714
|
+
const token = tokensToWalk[i];
|
|
1715
|
+
const children = tree.getNodeChildren(currentNode);
|
|
1716
|
+
const matchedChild = children.find((child) => matchesCommandToken(child, token));
|
|
1717
|
+
if (!matchedChild) {
|
|
1718
|
+
return {
|
|
1719
|
+
hasCommands: true,
|
|
1720
|
+
normalizedInput,
|
|
1721
|
+
completedTokens,
|
|
1722
|
+
partialToken: rawTokens.slice(i).join(" "),
|
|
1723
|
+
breadcrumbs,
|
|
1724
|
+
suggestions: [],
|
|
1725
|
+
exactNode: null,
|
|
1726
|
+
error: `Unknown command: ${token}`
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
const canonicalCmd = getNodeCommandToken(matchedChild);
|
|
1730
|
+
if (!tree.isBranchNode(matchedChild)) {
|
|
1731
|
+
const extraTokens = rawTokens.slice(i + 1);
|
|
1732
|
+
const hasExtra = extraTokens.length > 0 || partialToken.length > 0;
|
|
1733
|
+
if (hasExtra) {
|
|
1734
|
+
return {
|
|
1735
|
+
hasCommands: true,
|
|
1736
|
+
normalizedInput,
|
|
1737
|
+
completedTokens: [...completedTokens, canonicalCmd],
|
|
1738
|
+
partialToken,
|
|
1739
|
+
breadcrumbs,
|
|
1740
|
+
suggestions: [],
|
|
1741
|
+
exactNode: null,
|
|
1742
|
+
error: `Command ':${[...completedTokens, canonicalCmd].join(" ")}' does not take arguments`
|
|
1743
|
+
};
|
|
1744
|
+
}
|
|
1745
|
+
const exactFlat = toFlatItem(matchedChild, ancestorPath, ancestorLabels, completedTokens, tree);
|
|
1746
|
+
return {
|
|
1747
|
+
hasCommands: true,
|
|
1748
|
+
normalizedInput,
|
|
1749
|
+
completedTokens: [...completedTokens, canonicalCmd],
|
|
1750
|
+
partialToken: "",
|
|
1751
|
+
breadcrumbs,
|
|
1752
|
+
suggestions: [exactFlat],
|
|
1753
|
+
exactNode: exactFlat,
|
|
1754
|
+
error: null
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
completedTokens.push(canonicalCmd);
|
|
1758
|
+
breadcrumbs.push({
|
|
1759
|
+
value: matchedChild.value,
|
|
1760
|
+
label: matchedChild.label,
|
|
1761
|
+
command: canonicalCmd
|
|
1762
|
+
});
|
|
1763
|
+
ancestorPath.push(matchedChild.value);
|
|
1764
|
+
ancestorLabels.push(matchedChild.label);
|
|
1765
|
+
currentNode = matchedChild;
|
|
1766
|
+
}
|
|
1767
|
+
const branchChildren = tree.getNodeChildren(currentNode);
|
|
1768
|
+
const branchItems = branchChildren.map(
|
|
1769
|
+
(child) => toFlatItem(child, ancestorPath, ancestorLabels, completedTokens, tree)
|
|
1770
|
+
);
|
|
1771
|
+
if (!partialToken) {
|
|
1772
|
+
return {
|
|
1773
|
+
hasCommands: true,
|
|
1774
|
+
normalizedInput,
|
|
1775
|
+
completedTokens,
|
|
1776
|
+
partialToken: "",
|
|
1777
|
+
breadcrumbs,
|
|
1778
|
+
suggestions: branchItems,
|
|
1779
|
+
exactNode: null,
|
|
1780
|
+
error: null
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
const exactChild = branchItems.find((item) => matchesCommandToken(item.node, partialToken)) ?? null;
|
|
1784
|
+
const cmdFzf = new Fzf(branchItems, {
|
|
1785
|
+
selector: (item) => item.command,
|
|
1786
|
+
tiebreakers: [byLengthAsc],
|
|
1787
|
+
casing: "case-insensitive"
|
|
1788
|
+
});
|
|
1789
|
+
const cmdHits = /* @__PURE__ */ new Map();
|
|
1790
|
+
for (const res of cmdFzf.find(partialToken)) {
|
|
1791
|
+
cmdHits.set(res.item.value, {
|
|
1792
|
+
score: res.score,
|
|
1793
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
const labelFzf = new Fzf(branchItems, {
|
|
1797
|
+
selector: (item) => item.label,
|
|
1798
|
+
tiebreakers: [byLengthAsc],
|
|
1799
|
+
casing: "case-insensitive"
|
|
1800
|
+
});
|
|
1801
|
+
const labelHits = /* @__PURE__ */ new Map();
|
|
1802
|
+
for (const res of labelFzf.find(partialToken)) {
|
|
1803
|
+
labelHits.set(res.item.value, {
|
|
1804
|
+
score: res.score,
|
|
1805
|
+
positions: Array.from(res.positions).sort((a, b) => a - b)
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
const combinedFzf = new Fzf(branchItems, {
|
|
1809
|
+
selector: (item) => [item.command, ...item.aliases, item.label, item.description ?? "", ...item.node.keywords ?? []].join(" "),
|
|
1810
|
+
tiebreakers: [byLengthAsc],
|
|
1811
|
+
casing: "case-insensitive"
|
|
1812
|
+
});
|
|
1813
|
+
const suggestionMap = /* @__PURE__ */ new Map();
|
|
1814
|
+
for (const res of combinedFzf.find(partialToken)) {
|
|
1815
|
+
const cmdHit = cmdHits.get(res.item.value);
|
|
1816
|
+
const labelHit = labelHits.get(res.item.value);
|
|
1817
|
+
const isExact = exactChild?.value === res.item.value;
|
|
1818
|
+
const isPrefix = res.item.command.toLowerCase().startsWith(partialToken.toLowerCase());
|
|
1819
|
+
const score = (cmdHit ? cmdHit.score + 50 : res.score) + (isExact ? 500 : 0) + (isPrefix ? 100 : 0);
|
|
1820
|
+
suggestionMap.set(res.item.value, {
|
|
1821
|
+
...res.item,
|
|
1822
|
+
commandMatchPositions: cmdHit?.positions ?? [],
|
|
1823
|
+
matchPositions: labelHit?.positions ?? [],
|
|
1824
|
+
score
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
const suggestions = Array.from(suggestionMap.values()).sort((a, b) => {
|
|
1828
|
+
const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
|
|
1829
|
+
if (scoreDiff !== 0) return scoreDiff;
|
|
1830
|
+
return a.command.length - b.command.length;
|
|
1831
|
+
});
|
|
1832
|
+
const error = suggestions.length === 0 ? `Unknown command: ${[...completedTokens, partialToken].join(" ")}` : null;
|
|
1833
|
+
return {
|
|
1834
|
+
hasCommands: true,
|
|
1835
|
+
normalizedInput,
|
|
1836
|
+
completedTokens,
|
|
1837
|
+
partialToken,
|
|
1838
|
+
breadcrumbs,
|
|
1839
|
+
suggestions,
|
|
1840
|
+
exactNode: exactChild ? suggestionMap.get(exactChild.value) ?? exactChild : null,
|
|
1841
|
+
error
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
var resolveColonCommandState = resolveCommandMenuState;
|
|
1845
|
+
function formatCommandMenuCompletionInput(completedTokens, item, appendBranchSpace = true) {
|
|
1846
|
+
const nextTokens = [...completedTokens, item.command].join(" ");
|
|
1847
|
+
return item.isBranch && appendBranchSpace ? `:${nextTokens} ` : `:${nextTokens}`;
|
|
1848
|
+
}
|
|
1849
|
+
var formatColonCompletionInput = formatCommandMenuCompletionInput;
|
|
1850
|
+
function splitHighlightSegments(text, matchPositions) {
|
|
1851
|
+
if (!text) return [];
|
|
1852
|
+
if (!matchPositions || matchPositions.length === 0) {
|
|
1853
|
+
return [{ text, highlight: false }];
|
|
1854
|
+
}
|
|
1855
|
+
const posSet = new Set(matchPositions);
|
|
1856
|
+
const segments = [];
|
|
1857
|
+
let currentText = "";
|
|
1858
|
+
let currentHighlight = posSet.has(0);
|
|
1859
|
+
for (let i = 0; i < text.length; i++) {
|
|
1860
|
+
const isHighlighted = posSet.has(i);
|
|
1861
|
+
if (i > 0 && isHighlighted !== currentHighlight) {
|
|
1862
|
+
segments.push({ text: currentText, highlight: currentHighlight });
|
|
1863
|
+
currentText = text[i];
|
|
1864
|
+
currentHighlight = isHighlighted;
|
|
1865
|
+
} else {
|
|
1866
|
+
currentText += text[i];
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
if (currentText.length > 0) {
|
|
1870
|
+
segments.push({ text: currentText, highlight: currentHighlight });
|
|
1871
|
+
}
|
|
1872
|
+
return segments;
|
|
1873
|
+
}
|
|
1874
|
+
function announceCommandMessage(message) {
|
|
1875
|
+
if (typeof document === "undefined" || !message) return;
|
|
1876
|
+
try {
|
|
1877
|
+
if (!sharedLiveRegion) {
|
|
1878
|
+
sharedLiveRegion = createLiveRegion({ level: "polite", document });
|
|
1879
|
+
}
|
|
1880
|
+
sharedLiveRegion.announce(message, 150);
|
|
1881
|
+
} catch {
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
function matchesCommandHotkey(event, hotkey) {
|
|
1885
|
+
if (!hotkey) return false;
|
|
1886
|
+
const trimmed = hotkey.trim();
|
|
1887
|
+
if (trimmed === ":") {
|
|
1888
|
+
if (isEditableTarget(event.target)) return false;
|
|
1889
|
+
return !event.metaKey && !event.ctrlKey && !event.altKey && event.key === ":";
|
|
1890
|
+
}
|
|
1891
|
+
try {
|
|
1892
|
+
if (matchesKeyboardEvent(event, hotkey)) {
|
|
1893
|
+
return true;
|
|
1894
|
+
}
|
|
1895
|
+
} catch {
|
|
1896
|
+
}
|
|
1897
|
+
const normalized = trimmed.toLowerCase();
|
|
1898
|
+
if (normalized === "mod+k" || normalized === "cmd+k" || normalized === "ctrl+k") {
|
|
1899
|
+
return (event.metaKey || event.ctrlKey) && !event.altKey && event.key.toLowerCase() === "k";
|
|
1900
|
+
}
|
|
1901
|
+
return false;
|
|
1902
|
+
}
|
|
1903
|
+
function isHotkeyAnchorVisible(el) {
|
|
1904
|
+
if (el.closest("[hidden]")) return false;
|
|
1905
|
+
const fwWrapper = el.closest("[data-fw]");
|
|
1906
|
+
const activeFw = el.ownerDocument?.documentElement?.getAttribute("data-framework");
|
|
1907
|
+
if (fwWrapper && activeFw && fwWrapper.getAttribute("data-fw") !== activeFw) {
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
return true;
|
|
1911
|
+
}
|
|
1912
|
+
function shouldHandleCommandHotkey(anchorEl, selector) {
|
|
1913
|
+
if (!anchorEl || typeof document === "undefined") return true;
|
|
1914
|
+
if (!isHotkeyAnchorVisible(anchorEl)) return false;
|
|
1915
|
+
const myPreview = anchorEl.closest("[data-example-preview]");
|
|
1916
|
+
const activePreview = document.activeElement?.closest?.("[data-example-preview]") ?? null;
|
|
1917
|
+
if (activePreview) {
|
|
1918
|
+
return myPreview === activePreview;
|
|
1919
|
+
}
|
|
1920
|
+
if (myPreview) {
|
|
1921
|
+
const previewAnchors = Array.from(
|
|
1922
|
+
document.querySelectorAll(`[data-example-preview] ${selector}`)
|
|
1923
|
+
).filter(isHotkeyAnchorVisible);
|
|
1924
|
+
return previewAnchors[0] === anchorEl;
|
|
1925
|
+
}
|
|
1926
|
+
return true;
|
|
1927
|
+
}
|
|
1928
|
+
function resolveCommandMenuGridStyle(columns = "auto", itemCount) {
|
|
1929
|
+
if (columns === 1 || itemCount <= 0) {
|
|
1930
|
+
return void 0;
|
|
1931
|
+
}
|
|
1932
|
+
const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
|
|
1933
|
+
const colCount = Math.max(1, Math.min(maxCols, itemCount));
|
|
1934
|
+
const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
|
|
1935
|
+
return {
|
|
1936
|
+
display: "grid",
|
|
1937
|
+
gridAutoFlow: "column",
|
|
1938
|
+
gridTemplateRows: `repeat(${rowCount}, minmax(0, auto))`,
|
|
1939
|
+
gridTemplateColumns: `repeat(${colCount}, minmax(0, 1fr))`
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
var resolveColonCommandGridStyle = resolveCommandMenuGridStyle;
|
|
1943
|
+
function resolveCommandMenuGridNavigation(columns = "auto", itemCount, currentIdx, key) {
|
|
1944
|
+
if (itemCount <= 0) return -1;
|
|
1945
|
+
const safeIdx = currentIdx >= 0 && currentIdx < itemCount ? currentIdx : 0;
|
|
1946
|
+
if (key === "ArrowDown") {
|
|
1947
|
+
return (safeIdx + 1) % itemCount;
|
|
1948
|
+
}
|
|
1949
|
+
if (key === "ArrowUp") {
|
|
1950
|
+
return (safeIdx - 1 + itemCount) % itemCount;
|
|
1951
|
+
}
|
|
1952
|
+
if (columns === 1) {
|
|
1953
|
+
return safeIdx;
|
|
1954
|
+
}
|
|
1955
|
+
const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
|
|
1956
|
+
const colCount = Math.max(1, Math.min(maxCols, itemCount));
|
|
1957
|
+
const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
|
|
1958
|
+
const totalCols = Math.max(1, Math.ceil(itemCount / rowCount));
|
|
1959
|
+
const row = safeIdx % rowCount;
|
|
1960
|
+
const col = Math.floor(safeIdx / rowCount);
|
|
1961
|
+
const nextCol = key === "ArrowRight" ? (col + 1) % totalCols : (col - 1 + totalCols) % totalCols;
|
|
1962
|
+
return Math.min(nextCol * rowCount + row, itemCount - 1);
|
|
1963
|
+
}
|
|
1964
|
+
var resolveColonCommandGridNavigation = resolveCommandMenuGridNavigation;
|
|
1965
|
+
|
|
1966
|
+
// src/command/styles.ts
|
|
1967
|
+
import { cva as cva21 } from "class-variance-authority";
|
|
1968
|
+
var commandPaletteVariants = cva21(
|
|
1969
|
+
"flex w-full flex-col overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-2xl outline-none",
|
|
1970
|
+
{
|
|
1971
|
+
variants: {
|
|
1972
|
+
size: {
|
|
1973
|
+
sm: "max-w-md",
|
|
1974
|
+
md: "max-w-xl",
|
|
1975
|
+
lg: "max-w-2xl"
|
|
1976
|
+
}
|
|
1977
|
+
},
|
|
1978
|
+
defaultVariants: {
|
|
1979
|
+
size: "md"
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
);
|
|
1983
|
+
var commandPalettePositionerBase = "items-center justify-center p-4";
|
|
1984
|
+
var commandPaletteDialogContentBase = "my-auto gap-0 overflow-hidden p-0 sm:max-w-xl";
|
|
1985
|
+
var commandPaletteHeaderBase = "flex items-center gap-2 border-b border-border px-3 py-2.5";
|
|
1986
|
+
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";
|
|
1987
|
+
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";
|
|
1988
|
+
var commandPaletteListBase = "max-h-80 overflow-y-auto p-1.5 outline-none";
|
|
1989
|
+
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";
|
|
1990
|
+
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";
|
|
1991
|
+
var commandMenuVariants = cva21(
|
|
1992
|
+
"flex w-full flex-col overflow-hidden border border-border bg-popover font-mono text-popover-foreground shadow-2xl outline-none",
|
|
1993
|
+
{
|
|
1994
|
+
variants: {
|
|
1995
|
+
size: {
|
|
1996
|
+
sm: "text-xs",
|
|
1997
|
+
md: "text-sm",
|
|
1998
|
+
lg: "text-base"
|
|
1999
|
+
}
|
|
2000
|
+
},
|
|
2001
|
+
defaultVariants: {
|
|
2002
|
+
size: "md"
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
);
|
|
2006
|
+
var commandMenuPositionerBase = "items-end justify-stretch p-0!";
|
|
2007
|
+
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";
|
|
2008
|
+
var commandMenuListVariants = cva21("overflow-y-auto border-b border-border bg-popover/95 outline-none", {
|
|
2009
|
+
variants: {
|
|
2010
|
+
columns: {
|
|
2011
|
+
auto: "grid! grid-flow-col!",
|
|
2012
|
+
1: "flex flex-col",
|
|
2013
|
+
2: "grid! grid-flow-col!",
|
|
2014
|
+
3: "grid! grid-flow-col!",
|
|
2015
|
+
4: "grid! grid-flow-col!"
|
|
2016
|
+
},
|
|
2017
|
+
size: {
|
|
2018
|
+
sm: "max-h-44 gap-x-2 gap-y-0.5 px-2 py-1",
|
|
2019
|
+
md: "max-h-60 gap-x-3 gap-y-1 p-2",
|
|
2020
|
+
lg: "max-h-72 gap-x-4 gap-y-1.5 p-3"
|
|
2021
|
+
}
|
|
2022
|
+
},
|
|
2023
|
+
defaultVariants: {
|
|
2024
|
+
columns: "auto",
|
|
2025
|
+
size: "md"
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
var commandMenuItemVariants = cva21(
|
|
2029
|
+
"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",
|
|
2030
|
+
{
|
|
2031
|
+
variants: {
|
|
2032
|
+
size: {
|
|
2033
|
+
sm: "px-1.5 py-0.5 text-[11px] leading-tight",
|
|
2034
|
+
md: "px-2.5 py-1.5 text-xs",
|
|
2035
|
+
lg: "px-3 py-2 text-sm"
|
|
2036
|
+
}
|
|
2037
|
+
},
|
|
2038
|
+
defaultVariants: {
|
|
2039
|
+
size: "md"
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
var commandMenuPromptBarVariants = cva21(
|
|
2044
|
+
"flex w-full items-center border-t border-border/60 bg-muted/50 font-mono",
|
|
2045
|
+
{
|
|
2046
|
+
variants: {
|
|
2047
|
+
size: {
|
|
2048
|
+
sm: "gap-1 px-2 py-1 text-xs",
|
|
2049
|
+
md: "gap-1.5 px-3 py-2 text-sm",
|
|
2050
|
+
lg: "gap-2 px-4 py-2.5 text-base"
|
|
2051
|
+
}
|
|
2052
|
+
},
|
|
2053
|
+
defaultVariants: {
|
|
2054
|
+
size: "md"
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
);
|
|
2058
|
+
var commandMenuPrefixBase = "select-none font-mono font-bold text-primary";
|
|
2059
|
+
var commandMenuInputVariants = cva21(
|
|
2060
|
+
"flex-1 border-0 bg-transparent font-mono text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-0",
|
|
2061
|
+
{
|
|
2062
|
+
variants: {
|
|
2063
|
+
size: {
|
|
2064
|
+
sm: "px-0.5 py-0 text-xs",
|
|
2065
|
+
md: "px-1 py-0.5 text-sm",
|
|
2066
|
+
lg: "px-1.5 py-1 text-base"
|
|
2067
|
+
}
|
|
2068
|
+
},
|
|
2069
|
+
defaultVariants: {
|
|
2070
|
+
size: "md"
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
);
|
|
2074
|
+
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";
|
|
2075
|
+
var colonCommandVariants = commandMenuVariants;
|
|
2076
|
+
var colonCommandPositionerBase = commandMenuPositionerBase;
|
|
2077
|
+
var colonCommandDialogContentBase = commandMenuDialogContentBase;
|
|
2078
|
+
var colonCommandListVariants = commandMenuListVariants;
|
|
2079
|
+
var colonCommandItemVariants = commandMenuItemVariants;
|
|
2080
|
+
var colonCommandPromptBarVariants = commandMenuPromptBarVariants;
|
|
2081
|
+
var colonCommandPrefixBase = commandMenuPrefixBase;
|
|
2082
|
+
var colonCommandInputVariants = commandMenuInputVariants;
|
|
2083
|
+
var colonCommandErrorBase = commandMenuErrorBase;
|
|
1275
2084
|
|
|
1276
2085
|
// src/which-key/core.ts
|
|
1277
2086
|
var DEFAULT_JUMP_ALPHABET = "asdfghjklqwertyuiopzxcvbnm";
|
|
@@ -1330,6 +2139,14 @@ function isGroupNode(node, rootTrie) {
|
|
|
1330
2139
|
const children = getNodeChildren(node, rootTrie);
|
|
1331
2140
|
return Object.keys(children).length > 0;
|
|
1332
2141
|
}
|
|
2142
|
+
function formatWhichKeyLabel(label) {
|
|
2143
|
+
const trimmed = label.trim();
|
|
2144
|
+
if (!trimmed.startsWith("+")) return trimmed;
|
|
2145
|
+
const withoutPlus = trimmed.slice(1).trim();
|
|
2146
|
+
if (!withoutPlus) return trimmed;
|
|
2147
|
+
if (withoutPlus.toLowerCase() === "goto") return "Go to";
|
|
2148
|
+
return withoutPlus.charAt(0).toUpperCase() + withoutPlus.slice(1);
|
|
2149
|
+
}
|
|
1333
2150
|
function buildWhichKeyTree(rootTrie, activePath, mode) {
|
|
1334
2151
|
if (activePath.length === 0) {
|
|
1335
2152
|
const items2 = Object.values(rootTrie).filter((item) => !item.hidden && nodeMatchesMode(item, mode));
|
|
@@ -1585,7 +2402,7 @@ function createTextObjectChildren() {
|
|
|
1585
2402
|
return {
|
|
1586
2403
|
i: {
|
|
1587
2404
|
key: "i",
|
|
1588
|
-
label: "
|
|
2405
|
+
label: "Inner",
|
|
1589
2406
|
group: "Inner Text Object",
|
|
1590
2407
|
category: "Match / Text Objects",
|
|
1591
2408
|
mode: ["normal", "select"],
|
|
@@ -1629,7 +2446,7 @@ function createTextObjectChildren() {
|
|
|
1629
2446
|
},
|
|
1630
2447
|
a: {
|
|
1631
2448
|
key: "a",
|
|
1632
|
-
label: "
|
|
2449
|
+
label: "Around",
|
|
1633
2450
|
group: "Around Text Object",
|
|
1634
2451
|
category: "Match / Text Objects",
|
|
1635
2452
|
mode: ["normal", "select"],
|
|
@@ -1676,7 +2493,7 @@ function createTextObjectChildren() {
|
|
|
1676
2493
|
function createWindowMenu() {
|
|
1677
2494
|
return {
|
|
1678
2495
|
key: "Control+w",
|
|
1679
|
-
label: "
|
|
2496
|
+
label: "Window",
|
|
1680
2497
|
group: "Window / Pane",
|
|
1681
2498
|
category: "Window / Pane",
|
|
1682
2499
|
mode: ["normal", "select"],
|
|
@@ -1753,7 +2570,7 @@ function createWindowMenu() {
|
|
|
1753
2570
|
},
|
|
1754
2571
|
s: {
|
|
1755
2572
|
key: "s",
|
|
1756
|
-
label: "
|
|
2573
|
+
label: "Sticky Window",
|
|
1757
2574
|
group: "Sticky Window Mode",
|
|
1758
2575
|
description: "Keep Window menu open until Escape",
|
|
1759
2576
|
category: "Window / Pane",
|
|
@@ -1778,7 +2595,7 @@ function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
|
1778
2595
|
}
|
|
1779
2596
|
return {
|
|
1780
2597
|
key: leaderKey,
|
|
1781
|
-
label: "
|
|
2598
|
+
label: "Leader",
|
|
1782
2599
|
group: "Leader",
|
|
1783
2600
|
category: "Leader",
|
|
1784
2601
|
mode: ["normal", "select"],
|
|
@@ -1792,7 +2609,7 @@ function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
|
1792
2609
|
},
|
|
1793
2610
|
w: {
|
|
1794
2611
|
key: "w",
|
|
1795
|
-
label: "
|
|
2612
|
+
label: "Window",
|
|
1796
2613
|
group: "Window / Pane",
|
|
1797
2614
|
description: "Spatial and indexed pane navigation",
|
|
1798
2615
|
category: "Window / Pane",
|
|
@@ -1807,15 +2624,15 @@ function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
|
1807
2624
|
},
|
|
1808
2625
|
g: {
|
|
1809
2626
|
key: "g",
|
|
1810
|
-
label: "
|
|
1811
|
-
group: "
|
|
2627
|
+
label: "Go to",
|
|
2628
|
+
group: "Go to",
|
|
1812
2629
|
description: "Go to locations and boundaries",
|
|
1813
2630
|
category: "Goto",
|
|
1814
2631
|
proxy: ["g"]
|
|
1815
2632
|
},
|
|
1816
2633
|
v: {
|
|
1817
2634
|
key: "v",
|
|
1818
|
-
label: "
|
|
2635
|
+
label: "View",
|
|
1819
2636
|
group: "View / Scroll",
|
|
1820
2637
|
description: "Scroll and align viewport",
|
|
1821
2638
|
category: "View",
|
|
@@ -1823,7 +2640,7 @@ function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
|
1823
2640
|
},
|
|
1824
2641
|
k: {
|
|
1825
2642
|
key: "k",
|
|
1826
|
-
label: "
|
|
2643
|
+
label: "Preset",
|
|
1827
2644
|
group: "Keybinding Preset",
|
|
1828
2645
|
description: "Switch modal grammar (Helix / Vim / Kakoune)",
|
|
1829
2646
|
category: "Space",
|
|
@@ -1858,7 +2675,7 @@ function createSpaceMenu(leaderKey = "Space", viewKey = "z") {
|
|
|
1858
2675
|
function createViewMenu(key, centerKey) {
|
|
1859
2676
|
return {
|
|
1860
2677
|
key,
|
|
1861
|
-
label: "
|
|
2678
|
+
label: "View",
|
|
1862
2679
|
group: "View",
|
|
1863
2680
|
category: "View",
|
|
1864
2681
|
mode: ["normal", "select"],
|
|
@@ -1912,7 +2729,7 @@ function createUnimpairedMenus() {
|
|
|
1912
2729
|
return {
|
|
1913
2730
|
"[": {
|
|
1914
2731
|
key: "[",
|
|
1915
|
-
label: "
|
|
2732
|
+
label: "Previous",
|
|
1916
2733
|
group: "Previous (Unimpaired)",
|
|
1917
2734
|
category: "Unimpaired",
|
|
1918
2735
|
mode: ["normal", "select"],
|
|
@@ -1956,7 +2773,7 @@ function createUnimpairedMenus() {
|
|
|
1956
2773
|
},
|
|
1957
2774
|
"]": {
|
|
1958
2775
|
key: "]",
|
|
1959
|
-
label: "
|
|
2776
|
+
label: "Next",
|
|
1960
2777
|
group: "Next (Unimpaired)",
|
|
1961
2778
|
category: "Unimpaired",
|
|
1962
2779
|
mode: ["normal", "select"],
|
|
@@ -2209,8 +3026,8 @@ function createHelixPreset(leaderKey = "Space") {
|
|
|
2209
3026
|
"Control+w": createWindowMenu(),
|
|
2210
3027
|
g: {
|
|
2211
3028
|
key: "g",
|
|
2212
|
-
label: "
|
|
2213
|
-
group: "
|
|
3029
|
+
label: "Go to",
|
|
3030
|
+
group: "Go to",
|
|
2214
3031
|
category: "Goto",
|
|
2215
3032
|
mode: ["normal", "select"],
|
|
2216
3033
|
children: {
|
|
@@ -2296,7 +3113,7 @@ function createHelixPreset(leaderKey = "Space") {
|
|
|
2296
3113
|
z: createViewMenu("z", "z"),
|
|
2297
3114
|
Z: {
|
|
2298
3115
|
key: "Z",
|
|
2299
|
-
label: "
|
|
3116
|
+
label: "Sticky View",
|
|
2300
3117
|
group: "View (Sticky)",
|
|
2301
3118
|
description: "Lock View menu open until Escape",
|
|
2302
3119
|
category: "View",
|
|
@@ -2307,7 +3124,7 @@ function createHelixPreset(leaderKey = "Space") {
|
|
|
2307
3124
|
},
|
|
2308
3125
|
m: {
|
|
2309
3126
|
key: "m",
|
|
2310
|
-
label: "
|
|
3127
|
+
label: "Match",
|
|
2311
3128
|
group: "Match / Text Objects",
|
|
2312
3129
|
category: "Match / Text Objects",
|
|
2313
3130
|
mode: ["normal", "select"],
|
|
@@ -2390,8 +3207,8 @@ function createVimPreset(leaderKey = "Space") {
|
|
|
2390
3207
|
"Control+w": createWindowMenu(),
|
|
2391
3208
|
g: {
|
|
2392
3209
|
key: "g",
|
|
2393
|
-
label: "
|
|
2394
|
-
group: "
|
|
3210
|
+
label: "Go to",
|
|
3211
|
+
group: "Go to",
|
|
2395
3212
|
category: "Goto",
|
|
2396
3213
|
mode: ["normal", "select"],
|
|
2397
3214
|
children: {
|
|
@@ -2502,7 +3319,7 @@ function createVimPreset(leaderKey = "Space") {
|
|
|
2502
3319
|
z: createViewMenu("z", "z"),
|
|
2503
3320
|
m: {
|
|
2504
3321
|
key: "m",
|
|
2505
|
-
label: "
|
|
3322
|
+
label: "Text Objects",
|
|
2506
3323
|
group: "Text Objects",
|
|
2507
3324
|
category: "Match / Text Objects",
|
|
2508
3325
|
mode: ["normal", "select"],
|
|
@@ -2528,8 +3345,8 @@ function createKakounePreset(leaderKey = "Space") {
|
|
|
2528
3345
|
"Control+w": createWindowMenu(),
|
|
2529
3346
|
g: {
|
|
2530
3347
|
key: "g",
|
|
2531
|
-
label: "
|
|
2532
|
-
group: "
|
|
3348
|
+
label: "Go to",
|
|
3349
|
+
group: "Go to",
|
|
2533
3350
|
category: "Goto",
|
|
2534
3351
|
mode: ["normal", "select"],
|
|
2535
3352
|
children: {
|
|
@@ -2636,7 +3453,7 @@ function createKakounePreset(leaderKey = "Space") {
|
|
|
2636
3453
|
v: createViewMenu("v", "v"),
|
|
2637
3454
|
V: {
|
|
2638
3455
|
key: "V",
|
|
2639
|
-
label: "
|
|
3456
|
+
label: "Lock View",
|
|
2640
3457
|
group: "View (Lock)",
|
|
2641
3458
|
description: "Lock Kakoune View mode open until Escape (V)",
|
|
2642
3459
|
category: "View",
|
|
@@ -2647,7 +3464,7 @@ function createKakounePreset(leaderKey = "Space") {
|
|
|
2647
3464
|
},
|
|
2648
3465
|
m: {
|
|
2649
3466
|
key: "m",
|
|
2650
|
-
label: "
|
|
3467
|
+
label: "Object",
|
|
2651
3468
|
group: "Object / Match",
|
|
2652
3469
|
category: "Match / Text Objects",
|
|
2653
3470
|
mode: ["normal", "select"],
|
|
@@ -2717,11 +3534,11 @@ function getPresetKeymap(preset, leaderKey = "Space") {
|
|
|
2717
3534
|
}
|
|
2718
3535
|
|
|
2719
3536
|
// src/which-key/controller.ts
|
|
2720
|
-
import { isModifierKey, normalizeKeyName, parseKeyboardEvent } from "@tanstack/hotkeys";
|
|
3537
|
+
import { isModifierKey as isModifierKey2, normalizeKeyName as normalizeKeyName2, parseKeyboardEvent } from "@tanstack/hotkeys";
|
|
2721
3538
|
import { trackDismissableBranch } from "@zag-js/dismissable";
|
|
2722
3539
|
import { getFirstFocusable, getFocusables, isEditableElement, isInView } from "@zag-js/dom-query";
|
|
2723
3540
|
import { setInteractionModality, trackInteractionModality } from "@zag-js/focus-visible";
|
|
2724
|
-
import { createLiveRegion } from "@zag-js/live-region";
|
|
3541
|
+
import { createLiveRegion as createLiveRegion2 } from "@zag-js/live-region";
|
|
2725
3542
|
function mergeKeymapTrees(base, overlay) {
|
|
2726
3543
|
const result = { ...base };
|
|
2727
3544
|
for (const [key, node] of Object.entries(overlay)) {
|
|
@@ -2786,8 +3603,8 @@ function isTextEntryElement(el) {
|
|
|
2786
3603
|
function eventToChordKeys(event) {
|
|
2787
3604
|
const rawKey = event.key;
|
|
2788
3605
|
if (!rawKey) return [];
|
|
2789
|
-
const normalizedName =
|
|
2790
|
-
if (
|
|
3606
|
+
const normalizedName = normalizeKeyName2(rawKey);
|
|
3607
|
+
if (isModifierKey2(normalizedName) || rawKey === "Shift" || rawKey === "Control" || rawKey === "Alt" || rawKey === "Meta") {
|
|
2791
3608
|
return [];
|
|
2792
3609
|
}
|
|
2793
3610
|
const hasCtrl = event.ctrlKey;
|
|
@@ -2848,15 +3665,18 @@ function getTopMostModalDialog(doc) {
|
|
|
2848
3665
|
}
|
|
2849
3666
|
return dialogs[dialogs.length - 1] ?? null;
|
|
2850
3667
|
}
|
|
2851
|
-
function getPaneFocusableItems(container, ownScope) {
|
|
3668
|
+
function getPaneFocusableItems(container, ownScope, ignoreEnteredExample = false) {
|
|
2852
3669
|
const doc = container.ownerDocument;
|
|
2853
3670
|
const activeEl = doc?.activeElement instanceof HTMLElement ? doc.activeElement : null;
|
|
2854
|
-
const enteredExample = !ownScope && activeEl && !activeEl.hasAttribute("data-example") ? activeEl.closest("[data-example]") : null;
|
|
3671
|
+
const enteredExample = !ignoreEnteredExample && !ownScope && activeEl && !activeEl.hasAttribute("data-example") ? activeEl.closest("[data-example]") : null;
|
|
2855
3672
|
const searchRoot = enteredExample && container.contains(enteredExample) ? enteredExample.querySelector("[data-example-preview]") ?? enteredExample : container;
|
|
2856
3673
|
const raw = getFocusables(searchRoot, { includeContainer: false });
|
|
2857
3674
|
return raw.filter((el) => {
|
|
2858
3675
|
if (!(el instanceof HTMLElement)) return false;
|
|
2859
|
-
if (el.
|
|
3676
|
+
if (el.tabIndex < 0 && el.getAttribute("role") !== "tab") return false;
|
|
3677
|
+
if (el.closest(
|
|
3678
|
+
'[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay], [data-scope="toast"]'
|
|
3679
|
+
)) {
|
|
2860
3680
|
return false;
|
|
2861
3681
|
}
|
|
2862
3682
|
const fwEl = el.closest("[data-fw]");
|
|
@@ -2891,7 +3711,10 @@ function getJumpableItems(container, ownScope) {
|
|
|
2891
3711
|
for (const el of [...rawFocusables, ...rawTabs]) {
|
|
2892
3712
|
if (!(el instanceof HTMLElement) || seen.has(el)) continue;
|
|
2893
3713
|
seen.add(el);
|
|
2894
|
-
if (el.
|
|
3714
|
+
if (el.tabIndex < 0 && el.getAttribute("role") !== "tab") continue;
|
|
3715
|
+
if (el.closest(
|
|
3716
|
+
'[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay], [data-scope="toast"]'
|
|
3717
|
+
)) {
|
|
2895
3718
|
continue;
|
|
2896
3719
|
}
|
|
2897
3720
|
const fwEl = el.closest("[data-fw]");
|
|
@@ -3042,9 +3865,31 @@ function createWhichKeyController(options = {}) {
|
|
|
3042
3865
|
} catch {
|
|
3043
3866
|
}
|
|
3044
3867
|
}
|
|
3868
|
+
function readStoredLeaderOnly() {
|
|
3869
|
+
if (!storageKey || typeof window === "undefined") return null;
|
|
3870
|
+
try {
|
|
3871
|
+
const raw = window.localStorage.getItem(`${storageKey}:leader-only`);
|
|
3872
|
+
if (raw === "true") return true;
|
|
3873
|
+
if (raw === "false") return false;
|
|
3874
|
+
} catch {
|
|
3875
|
+
}
|
|
3876
|
+
return null;
|
|
3877
|
+
}
|
|
3878
|
+
function writeStoredLeaderOnly(next) {
|
|
3879
|
+
const doc = resolveDoc();
|
|
3880
|
+
if (doc?.documentElement && !options.getScopeElement?.()) {
|
|
3881
|
+
doc.documentElement.dataset.whichKeyLeaderOnly = String(next);
|
|
3882
|
+
}
|
|
3883
|
+
if (!storageKey || typeof window === "undefined") return;
|
|
3884
|
+
try {
|
|
3885
|
+
window.localStorage.setItem(`${storageKey}:leader-only`, String(next));
|
|
3886
|
+
} catch {
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3045
3889
|
let preset = options.preset ?? readStoredPreset() ?? "helix";
|
|
3046
3890
|
let mode = options.defaultMode ?? "normal";
|
|
3047
3891
|
const leaderKey = options.leaderKey ?? "Space";
|
|
3892
|
+
let leaderOnly = options.leaderOnly ?? readStoredLeaderOnly() ?? false;
|
|
3048
3893
|
let jumpAction = options.jumpAction ?? readStoredJumpAction() ?? "activate";
|
|
3049
3894
|
const jumpAlphabet = options.jumpAlphabet ?? DEFAULT_JUMP_ALPHABET;
|
|
3050
3895
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -3134,7 +3979,7 @@ function createWhichKeyController(options = {}) {
|
|
|
3134
3979
|
order,
|
|
3135
3980
|
lastFocusedElement: existing?.lastFocusedElement ?? null
|
|
3136
3981
|
});
|
|
3137
|
-
if (!activePaneId &&
|
|
3982
|
+
if (!disabled && (!activePaneId || id === "docs-main" && activePaneId === "docs-sidebar")) {
|
|
3138
3983
|
activePaneId = id;
|
|
3139
3984
|
}
|
|
3140
3985
|
}
|
|
@@ -3164,11 +4009,12 @@ function createWhichKeyController(options = {}) {
|
|
|
3164
4009
|
preset,
|
|
3165
4010
|
mode,
|
|
3166
4011
|
leaderKey,
|
|
4012
|
+
leaderOnly,
|
|
3167
4013
|
activePath: [...activePath],
|
|
3168
4014
|
breadcrumb: tree.breadcrumb,
|
|
3169
4015
|
title: tree.title,
|
|
3170
4016
|
items: tree.items,
|
|
3171
|
-
isOpen: activePath.length > 0 && tree.items.length > 0,
|
|
4017
|
+
isOpen: activePath.length > 0 && tree.items.length > 0 && (!leaderOnly || activePath[0] === leaderKey),
|
|
3172
4018
|
sticky: sticky || tree.sticky,
|
|
3173
4019
|
countBuffer,
|
|
3174
4020
|
explorerOpen,
|
|
@@ -3257,6 +4103,13 @@ function createWhichKeyController(options = {}) {
|
|
|
3257
4103
|
announce(`Switched to ${nextPreset} preset`);
|
|
3258
4104
|
emit();
|
|
3259
4105
|
}
|
|
4106
|
+
function setLeaderOnly(nextLeaderOnly) {
|
|
4107
|
+
if (leaderOnly === nextLeaderOnly) return;
|
|
4108
|
+
leaderOnly = nextLeaderOnly;
|
|
4109
|
+
writeStoredLeaderOnly(nextLeaderOnly);
|
|
4110
|
+
options.onLeaderOnlyChange?.(nextLeaderOnly);
|
|
4111
|
+
emit();
|
|
4112
|
+
}
|
|
3260
4113
|
function setJumpAction(action) {
|
|
3261
4114
|
if (jumpAction === action) return;
|
|
3262
4115
|
jumpAction = action;
|
|
@@ -3404,17 +4257,23 @@ function createWhichKeyController(options = {}) {
|
|
|
3404
4257
|
function jumpToBoundary(boundary) {
|
|
3405
4258
|
const container = getActiveContainer();
|
|
3406
4259
|
if (!container) return false;
|
|
3407
|
-
const
|
|
3408
|
-
|
|
4260
|
+
const ownScope = options.getScopeElement?.() ?? null;
|
|
4261
|
+
const ignoreEnteredExample = boundary === "start" || boundary === "end";
|
|
4262
|
+
const items = getPaneFocusableItems(container, ownScope, ignoreEnteredExample);
|
|
3409
4263
|
const doc = resolveDoc();
|
|
3410
4264
|
const win = doc?.defaultView ?? null;
|
|
4265
|
+
if (items.length === 0 && boundary !== "start" && boundary !== "end") {
|
|
4266
|
+
return false;
|
|
4267
|
+
}
|
|
3411
4268
|
recordCurrentLocation();
|
|
3412
4269
|
if (boundary === "start" || boundary === "first-in-group") {
|
|
3413
4270
|
const target2 = items[0];
|
|
3414
|
-
|
|
4271
|
+
if (target2) {
|
|
4272
|
+
focusElementInActivePane(target2);
|
|
4273
|
+
}
|
|
3415
4274
|
if (boundary === "start") {
|
|
3416
4275
|
container.scrollTop = 0;
|
|
3417
|
-
if (win && !isScrollableContainer(container, doc)) {
|
|
4276
|
+
if (win && !ownScope && !isScrollableContainer(container, doc)) {
|
|
3418
4277
|
try {
|
|
3419
4278
|
win.scrollTo({ top: 0, behavior: "instant" });
|
|
3420
4279
|
} catch {
|
|
@@ -3427,10 +4286,12 @@ function createWhichKeyController(options = {}) {
|
|
|
3427
4286
|
return true;
|
|
3428
4287
|
}
|
|
3429
4288
|
const target = items[items.length - 1];
|
|
3430
|
-
|
|
4289
|
+
if (target) {
|
|
4290
|
+
focusElementInActivePane(target);
|
|
4291
|
+
}
|
|
3431
4292
|
if (boundary === "end") {
|
|
3432
4293
|
container.scrollTop = container.scrollHeight;
|
|
3433
|
-
if (win && !isScrollableContainer(container, doc)) {
|
|
4294
|
+
if (win && !ownScope && !isScrollableContainer(container, doc)) {
|
|
3434
4295
|
const scrollMax = Math.max(
|
|
3435
4296
|
doc?.documentElement?.scrollHeight ?? 0,
|
|
3436
4297
|
doc?.body?.scrollHeight ?? 0,
|
|
@@ -4352,6 +5213,11 @@ function createWhichKeyController(options = {}) {
|
|
|
4352
5213
|
}
|
|
4353
5214
|
const doc = resolveDoc();
|
|
4354
5215
|
const targetEl = (isElementLike(event.target) ? event.target : null) ?? doc?.activeElement ?? null;
|
|
5216
|
+
if (targetEl && isHTMLElementLike(targetEl) && typeof targetEl.closest === "function" && (targetEl.closest(
|
|
5217
|
+
'[data-command-palette][data-modal="true"], [data-command-menu][data-modal="true"], [data-colon-command][data-modal="true"]'
|
|
5218
|
+
) || isTextEntryElement(targetEl) && targetEl.closest("[data-command-palette], [data-command-menu], [data-colon-command]"))) {
|
|
5219
|
+
return false;
|
|
5220
|
+
}
|
|
4355
5221
|
const editorTarget = getModalEditor(targetEl);
|
|
4356
5222
|
const inEditable = isTextEntryElement(targetEl);
|
|
4357
5223
|
if (mode === "insert") {
|
|
@@ -4529,7 +5395,7 @@ function createWhichKeyController(options = {}) {
|
|
|
4529
5395
|
} catch {
|
|
4530
5396
|
}
|
|
4531
5397
|
try {
|
|
4532
|
-
liveRegion =
|
|
5398
|
+
liveRegion = createLiveRegion2({
|
|
4533
5399
|
level: "polite",
|
|
4534
5400
|
document: doc
|
|
4535
5401
|
});
|
|
@@ -4562,9 +5428,14 @@ function createWhichKeyController(options = {}) {
|
|
|
4562
5428
|
if (storedJump && !options.jumpAction) {
|
|
4563
5429
|
jumpAction = storedJump;
|
|
4564
5430
|
}
|
|
5431
|
+
const storedLeaderOnly = readStoredLeaderOnly();
|
|
5432
|
+
if (storedLeaderOnly !== null && options.leaderOnly === void 0) {
|
|
5433
|
+
leaderOnly = storedLeaderOnly;
|
|
5434
|
+
}
|
|
4565
5435
|
if (doc.documentElement) {
|
|
4566
5436
|
doc.documentElement.dataset.keymapPreset = preset;
|
|
4567
5437
|
doc.documentElement.dataset.jumpAction = jumpAction;
|
|
5438
|
+
doc.documentElement.dataset.whichKeyLeaderOnly = String(leaderOnly);
|
|
4568
5439
|
}
|
|
4569
5440
|
rootControllerByDoc.set(doc, controllerApi);
|
|
4570
5441
|
notifyRootControllerListeners(doc);
|
|
@@ -4599,7 +5470,9 @@ function createWhichKeyController(options = {}) {
|
|
|
4599
5470
|
break;
|
|
4600
5471
|
}
|
|
4601
5472
|
}
|
|
4602
|
-
if (isTextEntryElement(targetNode) && (
|
|
5473
|
+
if (isTextEntryElement(targetNode) && !targetNode.closest(
|
|
5474
|
+
"[data-which-key-explorer], [data-command-palette], [data-command-menu], [data-colon-command]"
|
|
5475
|
+
) && (mode === "normal" || mode === "select")) {
|
|
4603
5476
|
setMode("insert");
|
|
4604
5477
|
}
|
|
4605
5478
|
};
|
|
@@ -4611,8 +5484,13 @@ function createWhichKeyController(options = {}) {
|
|
|
4611
5484
|
'[data-which-key-root], [data-which-key-explorer], [data-which-key-jump-overlay], [data-scope="dialog"]'
|
|
4612
5485
|
)) {
|
|
4613
5486
|
const focusedScope = targetNode.closest("[data-which-key-scope]") ?? null;
|
|
4614
|
-
if (
|
|
5487
|
+
if (focusedScope && isScopeElementActive(focusedScope, doc)) {
|
|
4615
5488
|
lastInteractedScopeByDoc.set(doc, focusedScope);
|
|
5489
|
+
} else if (!focusedScope) {
|
|
5490
|
+
const currentRemembered = lastInteractedScopeByDoc.get(doc) ?? null;
|
|
5491
|
+
if (!currentRemembered || !targetNode.contains(currentRemembered)) {
|
|
5492
|
+
lastInteractedScopeByDoc.set(doc, null);
|
|
5493
|
+
}
|
|
4616
5494
|
}
|
|
4617
5495
|
}
|
|
4618
5496
|
if (!shouldEntryHandleEvent(entry, doc)) return;
|
|
@@ -4630,7 +5508,9 @@ function createWhichKeyController(options = {}) {
|
|
|
4630
5508
|
if (programmaticFocusDepth > 0) {
|
|
4631
5509
|
return;
|
|
4632
5510
|
}
|
|
4633
|
-
if (isTextEntryElement(targetNode) && !getModalEditor(targetNode)
|
|
5511
|
+
if (isTextEntryElement(targetNode) && !getModalEditor(targetNode) && !targetNode.closest(
|
|
5512
|
+
"[data-which-key-explorer], [data-command-palette], [data-command-menu], [data-colon-command]"
|
|
5513
|
+
)) {
|
|
4634
5514
|
if (mode === "normal" || mode === "select") {
|
|
4635
5515
|
setMode("insert");
|
|
4636
5516
|
}
|
|
@@ -4728,6 +5608,7 @@ function createWhichKeyController(options = {}) {
|
|
|
4728
5608
|
handleKeyDown,
|
|
4729
5609
|
setPreset,
|
|
4730
5610
|
setMode,
|
|
5611
|
+
setLeaderOnly,
|
|
4731
5612
|
setJumpAction,
|
|
4732
5613
|
openPrefix,
|
|
4733
5614
|
closePrefix,
|
|
@@ -4757,8 +5638,8 @@ function createWhichKeyController(options = {}) {
|
|
|
4757
5638
|
}
|
|
4758
5639
|
|
|
4759
5640
|
// src/which-key/styles.ts
|
|
4760
|
-
import { cva as
|
|
4761
|
-
var whichKeyVariants =
|
|
5641
|
+
import { cva as cva22 } from "class-variance-authority";
|
|
5642
|
+
var whichKeyVariants = cva22(
|
|
4762
5643
|
"fixed z-50 flex flex-col overflow-hidden border bg-popover/95 text-popover-foreground shadow-xl backdrop-blur-md transition-all duration-150 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
4763
5644
|
{
|
|
4764
5645
|
variants: {
|
|
@@ -4776,7 +5657,7 @@ var whichKeyVariants = cva20(
|
|
|
4776
5657
|
var whichKeyHeaderBase = "flex items-center justify-between gap-2 px-3 pt-2.5 pb-1 text-xs font-medium";
|
|
4777
5658
|
var whichKeyTitleBase = "flex items-center gap-1.5 font-semibold text-foreground";
|
|
4778
5659
|
var whichKeyBreadcrumbBase = "flex items-center gap-1 text-[11px] text-muted-foreground";
|
|
4779
|
-
var whichKeyBodyVariants =
|
|
5660
|
+
var whichKeyBodyVariants = cva22("p-1.5", {
|
|
4780
5661
|
variants: {
|
|
4781
5662
|
variant: {
|
|
4782
5663
|
helix: "flex flex-col gap-0.5",
|
|
@@ -4789,9 +5670,9 @@ var whichKeyBodyVariants = cva20("p-1.5", {
|
|
|
4789
5670
|
}
|
|
4790
5671
|
});
|
|
4791
5672
|
var whichKeyItemBase = "group flex w-full cursor-pointer items-center justify-between gap-3 rounded-md px-2 py-1 text-left text-xs transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none";
|
|
4792
|
-
var whichKeyItemLabelBase = "truncate text-foreground group-hover:text-accent-foreground data-[group=true]:font-medium data-[group=true]:text-primary";
|
|
4793
|
-
var whichKeyFooterBase = "
|
|
4794
|
-
var whichKeyModeBadgeVariants =
|
|
5673
|
+
var whichKeyItemLabelBase = "inline-flex min-w-0 items-center gap-1 truncate text-foreground group-hover:text-accent-foreground data-[group=true]:font-medium data-[group=true]:text-primary";
|
|
5674
|
+
var whichKeyFooterBase = "pointer-events-none h-2 shrink-0";
|
|
5675
|
+
var whichKeyModeBadgeVariants = cva22(
|
|
4795
5676
|
"inline-flex items-center gap-1 rounded font-mono font-semibold tracking-wider uppercase select-none",
|
|
4796
5677
|
{
|
|
4797
5678
|
variants: {
|
|
@@ -4820,7 +5701,7 @@ var whichKeyExplorerInputBase = "mx-4 mb-2 w-[calc(100%-2rem)] rounded-md border
|
|
|
4820
5701
|
var whichKeyExplorerListContentBase = "max-h-none flex-1 overflow-visible px-2.5 pt-1 pb-3 outline-none";
|
|
4821
5702
|
var whichKeyExplorerItemBase = "flex w-full cursor-pointer items-center justify-between gap-3 rounded-md px-2.5 py-1.5 text-sm outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground";
|
|
4822
5703
|
var whichKeyExplorerHighlightMarkBase = "rounded-xs bg-primary/20 px-0.5 font-semibold text-foreground";
|
|
4823
|
-
var paneVariants =
|
|
5704
|
+
var paneVariants = cva22(
|
|
4824
5705
|
"relative transition-shadow duration-150 data-[pane-active=true]:ring-1 data-[pane-active=true]:ring-primary/40",
|
|
4825
5706
|
{
|
|
4826
5707
|
variants: {
|
|
@@ -4835,7 +5716,7 @@ var paneVariants = cva20(
|
|
|
4835
5716
|
}
|
|
4836
5717
|
);
|
|
4837
5718
|
var jumpOverlayRootBase = "pointer-events-none fixed inset-0 z-[60] overflow-hidden";
|
|
4838
|
-
var jumpBadgeVariants =
|
|
5719
|
+
var jumpBadgeVariants = cva22(
|
|
4839
5720
|
"pointer-events-auto fixed z-[61] inline-flex items-center justify-center rounded border px-1 py-0.5 font-mono text-[11px] leading-none font-bold shadow-md transition-transform select-none",
|
|
4840
5721
|
{
|
|
4841
5722
|
variants: {
|
|
@@ -6793,6 +7674,7 @@ export {
|
|
|
6793
7674
|
THEMES,
|
|
6794
7675
|
THEME_NAMES,
|
|
6795
7676
|
TitleHeading,
|
|
7677
|
+
announceCommandMessage,
|
|
6796
7678
|
badgeVariants,
|
|
6797
7679
|
buildChartDefinition,
|
|
6798
7680
|
buildExtensions,
|
|
@@ -6828,6 +7710,15 @@ export {
|
|
|
6828
7710
|
codeBlockSpinnerBase,
|
|
6829
7711
|
codeBlockTitleBase,
|
|
6830
7712
|
colBase,
|
|
7713
|
+
colonCommandDialogContentBase,
|
|
7714
|
+
colonCommandErrorBase,
|
|
7715
|
+
colonCommandInputVariants,
|
|
7716
|
+
colonCommandItemVariants,
|
|
7717
|
+
colonCommandListVariants,
|
|
7718
|
+
colonCommandPositionerBase,
|
|
7719
|
+
colonCommandPrefixBase,
|
|
7720
|
+
colonCommandPromptBarVariants,
|
|
7721
|
+
colonCommandVariants,
|
|
6831
7722
|
comboboxClearTriggerBase,
|
|
6832
7723
|
comboboxContentBase,
|
|
6833
7724
|
comboboxControlBase,
|
|
@@ -6839,8 +7730,27 @@ export {
|
|
|
6839
7730
|
comboboxListBase,
|
|
6840
7731
|
comboboxPositionerBase,
|
|
6841
7732
|
comboboxTriggerBase,
|
|
7733
|
+
commandMenuDialogContentBase,
|
|
7734
|
+
commandMenuErrorBase,
|
|
7735
|
+
commandMenuInputVariants,
|
|
7736
|
+
commandMenuItemVariants,
|
|
7737
|
+
commandMenuListVariants,
|
|
7738
|
+
commandMenuPositionerBase,
|
|
7739
|
+
commandMenuPrefixBase,
|
|
7740
|
+
commandMenuPromptBarVariants,
|
|
7741
|
+
commandMenuVariants,
|
|
7742
|
+
commandPaletteBreadcrumbBase,
|
|
7743
|
+
commandPaletteDialogContentBase,
|
|
7744
|
+
commandPaletteFooterBase,
|
|
7745
|
+
commandPaletteHeaderBase,
|
|
7746
|
+
commandPaletteInputBase,
|
|
7747
|
+
commandPaletteItemBase,
|
|
7748
|
+
commandPaletteListBase,
|
|
7749
|
+
commandPalettePositionerBase,
|
|
7750
|
+
commandPaletteVariants,
|
|
6842
7751
|
containerBase,
|
|
6843
7752
|
createCodeBlockCustom,
|
|
7753
|
+
createCommandTree,
|
|
6844
7754
|
createHelixPreset,
|
|
6845
7755
|
createImageNode,
|
|
6846
7756
|
createInternalMention,
|
|
@@ -6885,9 +7795,12 @@ export {
|
|
|
6885
7795
|
findDirectionalPane,
|
|
6886
7796
|
findEditorScrollContainer,
|
|
6887
7797
|
flattenKeymapEntries,
|
|
7798
|
+
formatColonCompletionInput,
|
|
7799
|
+
formatCommandMenuCompletionInput,
|
|
6888
7800
|
formatKeyChord,
|
|
6889
7801
|
formatKeySequence,
|
|
6890
7802
|
formatTime,
|
|
7803
|
+
formatWhichKeyLabel,
|
|
6891
7804
|
generateJumpLabels,
|
|
6892
7805
|
getDocumentWhichKeyController,
|
|
6893
7806
|
getEditorModalTarget,
|
|
@@ -6895,9 +7808,11 @@ export {
|
|
|
6895
7808
|
getNodeChildren,
|
|
6896
7809
|
getPresetKeymap,
|
|
6897
7810
|
hstackBase,
|
|
7811
|
+
inferPlatform,
|
|
6898
7812
|
injectCodeBlockStyles,
|
|
6899
7813
|
inputVariants,
|
|
6900
7814
|
insertPastedUrlAsLink,
|
|
7815
|
+
isChordCommandString,
|
|
6901
7816
|
isEditorInInsertMode,
|
|
6902
7817
|
isGroupNode,
|
|
6903
7818
|
itemVariants,
|
|
@@ -6927,6 +7842,7 @@ export {
|
|
|
6927
7842
|
manimPlaceholderBase,
|
|
6928
7843
|
manimPlaceholderLabelBase,
|
|
6929
7844
|
manimRootBase,
|
|
7845
|
+
matchesCommandHotkey,
|
|
6930
7846
|
mermaidLoadingBase,
|
|
6931
7847
|
mermaidRootBase,
|
|
6932
7848
|
mermaidSourceBase,
|
|
@@ -7028,6 +7944,14 @@ export {
|
|
|
7028
7944
|
renderChartSvgString,
|
|
7029
7945
|
renderCodeToHtml,
|
|
7030
7946
|
renderMermaidSource,
|
|
7947
|
+
resolveColonCommandGridNavigation,
|
|
7948
|
+
resolveColonCommandGridStyle,
|
|
7949
|
+
resolveColonCommandState,
|
|
7950
|
+
resolveCommandLevel,
|
|
7951
|
+
resolveCommandMenuGridNavigation,
|
|
7952
|
+
resolveCommandMenuGridStyle,
|
|
7953
|
+
resolveCommandMenuState,
|
|
7954
|
+
resolveKbdSteps,
|
|
7031
7955
|
resolveMermaidThemeVariables,
|
|
7032
7956
|
resolveNode,
|
|
7033
7957
|
revealChevronBase,
|
|
@@ -7051,9 +7975,11 @@ export {
|
|
|
7051
7975
|
selectPositionerBase,
|
|
7052
7976
|
selectTriggerBase,
|
|
7053
7977
|
selectValueBase,
|
|
7978
|
+
shouldHandleCommandHotkey,
|
|
7054
7979
|
sidebarMenuButtonVariants,
|
|
7055
7980
|
sidebarStyles,
|
|
7056
7981
|
slashCommands,
|
|
7982
|
+
splitHighlightSegments,
|
|
7057
7983
|
splitterPanelBase,
|
|
7058
7984
|
splitterResizeTriggerBase,
|
|
7059
7985
|
splitterResizeTriggerIndicatorBase,
|
|
@@ -7082,6 +8008,13 @@ export {
|
|
|
7082
8008
|
tagsInputRootBase,
|
|
7083
8009
|
textareaBase,
|
|
7084
8010
|
toLaTeX,
|
|
8011
|
+
toastActionTriggerBase,
|
|
8012
|
+
toastCloseTriggerBase,
|
|
8013
|
+
toastDescriptionBase,
|
|
8014
|
+
toastIconBase,
|
|
8015
|
+
toastTitleBase,
|
|
8016
|
+
toastVariants,
|
|
8017
|
+
toasterBase,
|
|
7085
8018
|
toggleButtonVariants,
|
|
7086
8019
|
toggleGroupRootVariants,
|
|
7087
8020
|
tooltipArrowBase,
|
|
@@ -7089,6 +8022,8 @@ export {
|
|
|
7089
8022
|
tooltipPositionerBase,
|
|
7090
8023
|
unregisterImageInsertCallback,
|
|
7091
8024
|
unregisterYouTubeInsertCallback,
|
|
8025
|
+
validateKbdChord,
|
|
8026
|
+
validateKbdHotkey,
|
|
7092
8027
|
vstackBase,
|
|
7093
8028
|
whichKeyBodyVariants,
|
|
7094
8029
|
whichKeyBreadcrumbBase,
|