@kortix/ui 0.15.7 → 0.15.8
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/README.md +7 -7
- package/dist/_vendor/kortix-shared.js +36 -1
- package/dist/_vendor/shared/my-kortix-agent.d.ts +7 -0
- package/dist/_vendor/shared/pixel-mark.d.ts +18 -0
- package/dist/customize/connectors/catalog/connector-categories.d.ts +2 -2
- package/dist/customize/connectors/catalog/connector-categories.js +2 -2
- package/dist/customize/connectors/detail/connector-modal.js +1 -1
- package/dist/customize/sections/gateway-view.d.ts +1 -1
- package/dist/customize/sections/gateway-view.js +1 -1
- package/dist/customize/sections/view/account-secret-resources-panel.js +4 -2
- package/dist/customize/sections/view/agent-editor-basics-fields.js +1 -1
- package/dist/customize/sections/view/gateway/gateway-logs.d.ts +1 -1
- package/dist/customize/sections/view/git-view.js +1 -1
- package/dist/customize/sections/view/permission-editor.js +1 -1
- package/dist/customize/sections/view/subscription-usage.d.ts +3 -32
- package/dist/customize/sections/view/subscription-usage.js +2 -86
- package/dist/customize/shared/entity/entity-modal.js +8 -10
- package/dist/files/project/components/drive-toolbar.d.ts +1 -1
- package/dist/files/project/components/drive-toolbar.js +1 -1
- package/dist/files/project/store/version-store.d.ts +1 -1
- package/dist/files/renderers/shared/scroll-area-compat.d.ts +6 -6
- package/dist/files/renderers/shared/scroll-area-compat.js +7 -9
- package/dist/files/renderers/shared/select-compat.js +3 -7
- package/dist/files/viewer/file-preview-modal.d.ts +10 -11
- package/dist/files/viewer/file-preview-modal.js +17 -18
- package/dist/i18n/en.d.ts +3 -0
- package/dist/i18n/en.js +7 -4
- package/dist/index.js +1 -1
- package/dist/internal/account-hub/account-hub-location.js +2 -2
- package/dist/internal/account-hub/use-account-members.d.ts +28 -1
- package/dist/internal/account-hub/use-account-members.js +27 -10
- package/dist/internal/components/agent-mark.d.ts +1 -8
- package/dist/internal/components/agent-mark.js +2 -19
- package/dist/internal/lib/navigation/modified-click.js +2 -2
- package/dist/internal/lib/pixel-mark.d.ts +3 -20
- package/dist/internal/lib/pixel-mark.js +3 -34
- package/dist/internal/stores/active-space-store.d.ts +1 -1
- package/dist/internal/stores/browser-recents-store.d.ts +1 -1
- package/dist/internal/stores/current-account-store.d.ts +1 -1
- package/dist/internal/stores/first-chat-store.d.ts +1 -1
- package/dist/internal/stores/mobile-app-promo-store.d.ts +1 -1
- package/dist/internal/stores/session-browser-store.d.ts +1 -1
- package/dist/internal/stores/session-expanded-store.d.ts +1 -1
- package/dist/internal/stores/session-filter-store.d.ts +1 -1
- package/dist/internal/stores/session-history-view-store.d.ts +1 -1
- package/dist/internal/stores/session-hover-store.d.ts +1 -1
- package/dist/internal/stores/session-hover-store.js +1 -1
- package/dist/internal/stores/session-panel-memory-store.d.ts +1 -1
- package/dist/internal/stores/sound-store.d.ts +1 -1
- package/dist/internal/stores/tab-store.d.ts +1 -1
- package/dist/internal/stores/user-preferences-store.d.ts +1 -1
- package/dist/internal/stores/web-notification-store.d.ts +1 -1
- package/dist/lib/base-ui-compat.d.ts +149 -0
- package/dist/lib/base-ui-compat.js +339 -0
- package/dist/lib/portal-container.d.ts +3 -7
- package/dist/lib/portal-container.js +5 -3
- package/dist/lib/z-stack.d.ts +4 -4
- package/dist/lib/z-stack.js +5 -5
- package/dist/primitives/accordion.d.ts +36 -5
- package/dist/primitives/accordion.js +41 -8
- package/dist/primitives/alert-dialog.d.ts +33 -11
- package/dist/primitives/alert-dialog.js +41 -19
- package/dist/primitives/avatar.d.ts +5 -2
- package/dist/primitives/avatar.js +3 -3
- package/dist/primitives/badge.js +1 -1
- package/dist/primitives/breadcrumb.js +1 -1
- package/dist/primitives/button-group.js +3 -3
- package/dist/primitives/button.js +1 -1
- package/dist/primitives/checkbox.d.ts +14 -5
- package/dist/primitives/checkbox.js +24 -9
- package/dist/primitives/collapsible.d.ts +16 -4
- package/dist/primitives/collapsible.js +18 -7
- package/dist/primitives/command-core.d.ts +121 -0
- package/dist/primitives/command-core.js +642 -0
- package/dist/primitives/command.d.ts +38 -4
- package/dist/primitives/command.js +22 -13
- package/dist/primitives/context-menu.d.ts +61 -31
- package/dist/primitives/context-menu.js +40 -53
- package/dist/primitives/dialog.d.ts +48 -10
- package/dist/primitives/dialog.js +48 -19
- package/dist/primitives/disclosure.d.ts +1 -1
- package/dist/primitives/disclosure.js +2 -2
- package/dist/primitives/drawer.d.ts +28 -9
- package/dist/primitives/drawer.js +42 -18
- package/dist/primitives/dropdown-menu.d.ts +55 -33
- package/dist/primitives/dropdown-menu.js +46 -82
- package/dist/primitives/faded-scroll-area.js +2 -1
- package/dist/primitives/hint.js +3 -3
- package/dist/primitives/hover-card.d.ts +17 -5
- package/dist/primitives/hover-card.js +45 -8
- package/dist/primitives/item.js +2 -2
- package/dist/primitives/label.d.ts +5 -2
- package/dist/primitives/label.js +10 -3
- package/dist/primitives/menu-base.d.ts +150 -0
- package/dist/primitives/menu-base.js +171 -0
- package/dist/primitives/menu-recipe.d.ts +1 -1
- package/dist/primitives/menu-recipe.js +2 -7
- package/dist/primitives/modal.d.ts +19 -52
- package/dist/primitives/modal.js +24 -28
- package/dist/primitives/navigation-menu.d.ts +36 -11
- package/dist/primitives/navigation-menu.js +31 -12
- package/dist/primitives/popover.d.ts +31 -6
- package/dist/primitives/popover.js +79 -12
- package/dist/primitives/preview-image.d.ts +18 -7
- package/dist/primitives/preview-image.js +14 -11
- package/dist/primitives/progress.d.ts +4 -2
- package/dist/primitives/progress.js +4 -3
- package/dist/primitives/project-icon-picker.js +2 -2
- package/dist/primitives/radio-group.d.ts +28 -5
- package/dist/primitives/radio-group.js +18 -10
- package/dist/primitives/scroll-area.d.ts +2 -2
- package/dist/primitives/scroll-area.js +8 -3
- package/dist/primitives/select.d.ts +55 -12
- package/dist/primitives/select.js +93 -36
- package/dist/primitives/separator.d.ts +6 -2
- package/dist/primitives/separator.js +10 -2
- package/dist/primitives/sheet.d.ts +17 -10
- package/dist/primitives/sheet.js +19 -22
- package/dist/primitives/sidebar-menu-primitives.js +8 -8
- package/dist/primitives/slider-native.d.ts +2 -2
- package/dist/primitives/slider-native.js +11 -9
- package/dist/primitives/slider.d.ts +24 -6
- package/dist/primitives/slider.js +26 -24
- package/dist/primitives/slot.d.ts +6 -0
- package/dist/primitives/slot.js +7 -0
- package/dist/primitives/split-sheet.js +1 -1
- package/dist/primitives/stepper.js +1 -1
- package/dist/primitives/switch.d.ts +16 -3
- package/dist/primitives/switch.js +7 -6
- package/dist/primitives/tabs.d.ts +36 -20
- package/dist/primitives/tabs.js +131 -102
- package/dist/primitives/toggle.d.ts +16 -3
- package/dist/primitives/toggle.js +8 -3
- package/dist/primitives/tooltip.d.ts +24 -5
- package/dist/primitives/tooltip.js +32 -10
- package/dist/primitives/type-to-confirm-dialog.d.ts +1 -1
- package/dist/primitives/type-to-confirm-dialog.js +1 -1
- package/dist/session/composer/animated-placeholder.js +1 -1
- package/dist/session/composer/chat-input/chat-input-control.js +3 -3
- package/dist/session/composer/editor/composer-editor.js +1 -1
- package/dist/session/composer/menus/menu-shell.d.ts +1 -1
- package/dist/session/composer/menus/menu-shell.js +1 -1
- package/dist/session/composer/menus/mount.js +1 -1
- package/dist/session/composer/reasoning-effort-selector.js +1 -1
- package/dist/session/header/session-site-header.js +2 -2
- package/dist/session/header/subagent-hover-card.js +2 -2
- package/dist/session/media/image-preview.js +1 -1
- package/dist/session/models/model-selector.d.ts +1 -1
- package/dist/session/models/model-selector.js +18 -12
- package/dist/session/models/subscription-switcher.d.ts +37 -0
- package/dist/session/models/subscription-switcher.js +97 -0
- package/dist/session/models/subscription-windows.d.ts +40 -0
- package/dist/session/models/subscription-windows.js +86 -0
- package/dist/session/overrides/session-overrides-control.js +3 -3
- package/dist/session/panel/diff-dialog.js +1 -1
- package/dist/session/panel/easy/detail-view.js +3 -3
- package/dist/session/panel/mobile-tool-drawer.js +2 -2
- package/dist/session/panel/panel-fallback.js +1 -1
- package/dist/session/panel/session-files-explorer.d.ts +1 -1
- package/dist/session/panel/session-files-explorer.js +1 -1
- package/dist/session/thread/session-chat.js +2 -2
- package/dist/session/thread/session-context-message-explorer.js +1 -1
- package/dist/session/thread/turn-share.js +3 -4
- package/dist/session/tool/shared/show-helpers.js +1 -1
- package/dist/session/turn/message-time-label.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/test-utils/intl.d.ts +3 -0
- package/dist/workspace/projects/modal/project-icon-field.js +9 -23
- package/dist/workspace/review/review-center.js +1 -1
- package/dist/workspace/sessions/session-row.js +1 -1
- package/dist/workspace/sidebar/project-session-list.js +2 -2
- package/dist/workspace/sidebar/session-brief-hover-card.d.ts +1 -1
- package/dist/workspace/sidebar/session-brief-hover-card.js +3 -3
- package/dist/workspace/sidebar/session-title.d.ts +2 -2
- package/dist/workspace/sidebar/session-title.js +2 -2
- package/dist/workspace/sidebar/workspace-menu-section.js +1 -1
- package/dist/workspace/spaces/space-links.js +1 -1
- package/dist/workspace/spaces/space-threads-tab.js +1 -1
- package/package.json +16 -35
- package/skills/kortix-ui/SKILL.md +1 -1
- package/skills/kortix-ui/references/custom-dashboard.md +1 -1
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The headless command list behind `./command`: a port of cmdk 0.2.1 without
|
|
5
|
+
* its Radix dialog.
|
|
6
|
+
*
|
|
7
|
+
* cmdk 0.2.1 depends on `@radix-ui/react-dialog` only for `Command.Dialog`,
|
|
8
|
+
* which `@kortix/ui` never used (`CommandDialog` wraps our own `Dialog`). The
|
|
9
|
+
* ⌘K palette depends on cmdk's exact behavior — lowercased `value` identity,
|
|
10
|
+
* `forceMount` groups, Enter dispatching `cmdk-item-select`, `aria-selected`
|
|
11
|
+
* on the highlighted row, and the `[cmdk-*]` attributes its classes select —
|
|
12
|
+
* so this port keeps all of it, including the DOM re-sort after a search.
|
|
13
|
+
* That re-sort reads scores by `data-value` from a map keyed by item id, so
|
|
14
|
+
* every score is 0: it keeps row order, and its one visible effect is moving
|
|
15
|
+
* ungrouped rows after the groups in the list. Kept for parity.
|
|
16
|
+
*
|
|
17
|
+
* cmdk: Copyright (c) 2022 Paco Coursey. MIT License. Permission is hereby
|
|
18
|
+
* granted, free of charge, to any person obtaining a copy of this software and
|
|
19
|
+
* associated documentation files (the "Software"), to deal in the Software
|
|
20
|
+
* without restriction, including without limitation the rights to use, copy,
|
|
21
|
+
* modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
22
|
+
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
23
|
+
* subject to the following conditions: The above copyright notice and this
|
|
24
|
+
* permission notice shall be included in all copies or substantial portions
|
|
25
|
+
* of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
26
|
+
* KIND, EXPRESS OR IMPLIED.
|
|
27
|
+
*/
|
|
28
|
+
import * as React from 'react';
|
|
29
|
+
/* ---------- command-score (cmdk 0.2.1) ---------- */
|
|
30
|
+
const SCORE_CONTINUE_MATCH = 1;
|
|
31
|
+
const SCORE_SPACE_WORD_JUMP = 0.9;
|
|
32
|
+
const SCORE_NON_SPACE_WORD_JUMP = 0.8;
|
|
33
|
+
const SCORE_CHARACTER_JUMP = 0.17;
|
|
34
|
+
const SCORE_TRANSPOSITION = 0.1;
|
|
35
|
+
const PENALTY_SKIPPED = 0.999;
|
|
36
|
+
const PENALTY_CASE_MISMATCH = 0.9999;
|
|
37
|
+
const PENALTY_NOT_COMPLETE = 0.99;
|
|
38
|
+
const IS_GAP_REGEXP = /[\\/_+.#"@[({&]/;
|
|
39
|
+
const COUNT_GAPS_REGEXP = /[\\/_+.#"@[({&]/g;
|
|
40
|
+
const IS_SPACE_REGEXP = /[\s-]/;
|
|
41
|
+
const COUNT_SPACE_REGEXP = /[\s-]/g;
|
|
42
|
+
function scoreFrom(string, abbreviation, lowerString, lowerAbbreviation, stringIndex, abbreviationIndex, memo) {
|
|
43
|
+
if (abbreviationIndex === abbreviation.length) {
|
|
44
|
+
return stringIndex === string.length ? SCORE_CONTINUE_MATCH : PENALTY_NOT_COMPLETE;
|
|
45
|
+
}
|
|
46
|
+
const memoKey = `${stringIndex},${abbreviationIndex}`;
|
|
47
|
+
if (memo[memoKey] !== undefined)
|
|
48
|
+
return memo[memoKey];
|
|
49
|
+
const abbreviationChar = lowerAbbreviation.charAt(abbreviationIndex);
|
|
50
|
+
let index = lowerString.indexOf(abbreviationChar, stringIndex);
|
|
51
|
+
let highScore = 0;
|
|
52
|
+
while (index >= 0) {
|
|
53
|
+
let score = scoreFrom(string, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 1, memo);
|
|
54
|
+
if (score > highScore) {
|
|
55
|
+
if (index === stringIndex) {
|
|
56
|
+
score *= SCORE_CONTINUE_MATCH;
|
|
57
|
+
}
|
|
58
|
+
else if (IS_GAP_REGEXP.test(string.charAt(index - 1))) {
|
|
59
|
+
score *= SCORE_NON_SPACE_WORD_JUMP;
|
|
60
|
+
const gaps = string.slice(stringIndex, index - 1).match(COUNT_GAPS_REGEXP);
|
|
61
|
+
if (gaps && stringIndex > 0)
|
|
62
|
+
score *= Math.pow(PENALTY_SKIPPED, gaps.length);
|
|
63
|
+
}
|
|
64
|
+
else if (IS_SPACE_REGEXP.test(string.charAt(index - 1))) {
|
|
65
|
+
score *= SCORE_SPACE_WORD_JUMP;
|
|
66
|
+
const spaces = string.slice(stringIndex, index - 1).match(COUNT_SPACE_REGEXP);
|
|
67
|
+
if (spaces && stringIndex > 0)
|
|
68
|
+
score *= Math.pow(PENALTY_SKIPPED, spaces.length);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
score *= SCORE_CHARACTER_JUMP;
|
|
72
|
+
if (stringIndex > 0)
|
|
73
|
+
score *= Math.pow(PENALTY_SKIPPED, index - stringIndex);
|
|
74
|
+
}
|
|
75
|
+
if (string.charAt(index) !== abbreviation.charAt(abbreviationIndex)) {
|
|
76
|
+
score *= PENALTY_CASE_MISMATCH;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if ((score < SCORE_TRANSPOSITION &&
|
|
80
|
+
lowerString.charAt(index - 1) === lowerAbbreviation.charAt(abbreviationIndex + 1)) ||
|
|
81
|
+
(lowerAbbreviation.charAt(abbreviationIndex + 1) ===
|
|
82
|
+
lowerAbbreviation.charAt(abbreviationIndex) &&
|
|
83
|
+
lowerString.charAt(index - 1) !== lowerAbbreviation.charAt(abbreviationIndex))) {
|
|
84
|
+
const transposedScore = scoreFrom(string, abbreviation, lowerString, lowerAbbreviation, index + 1, abbreviationIndex + 2, memo);
|
|
85
|
+
if (transposedScore * SCORE_TRANSPOSITION > score) {
|
|
86
|
+
score = transposedScore * SCORE_TRANSPOSITION;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (score > highScore)
|
|
90
|
+
highScore = score;
|
|
91
|
+
index = lowerString.indexOf(abbreviationChar, index + 1);
|
|
92
|
+
}
|
|
93
|
+
memo[memoKey] = highScore;
|
|
94
|
+
return highScore;
|
|
95
|
+
}
|
|
96
|
+
function formatInput(value) {
|
|
97
|
+
return value.toLowerCase().replace(COUNT_SPACE_REGEXP, ' ');
|
|
98
|
+
}
|
|
99
|
+
/** cmdk's default filter: 0 hides the row, 1 is a perfect match. */
|
|
100
|
+
export function commandScore(string, abbreviation) {
|
|
101
|
+
return scoreFrom(string, abbreviation, formatInput(string), formatInput(abbreviation), 0, 0, {});
|
|
102
|
+
}
|
|
103
|
+
/* ---------- store and contexts ---------- */
|
|
104
|
+
const LIST_SIZER_SELECTOR = '[cmdk-list-sizer=""]';
|
|
105
|
+
const GROUP_SELECTOR = '[cmdk-group=""]';
|
|
106
|
+
const GROUP_ITEMS_SELECTOR = '[cmdk-group-items=""]';
|
|
107
|
+
const GROUP_HEADING_SELECTOR = '[cmdk-group-heading=""]';
|
|
108
|
+
const ITEM_SELECTOR = '[cmdk-item=""]';
|
|
109
|
+
const VALID_ITEM_SELECTOR = `${ITEM_SELECTOR}:not([aria-disabled="true"])`;
|
|
110
|
+
const SELECT_EVENT = 'cmdk-item-select';
|
|
111
|
+
const VALUE_ATTR = 'data-value';
|
|
112
|
+
const CommandContext = React.createContext(undefined);
|
|
113
|
+
const StoreContext = React.createContext(undefined);
|
|
114
|
+
const GroupContext = React.createContext(undefined);
|
|
115
|
+
const useCommand = () => React.useContext(CommandContext);
|
|
116
|
+
const useStore = () => React.useContext(StoreContext);
|
|
117
|
+
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
|
|
118
|
+
function useLazyRef(init) {
|
|
119
|
+
const ref = React.useRef(undefined);
|
|
120
|
+
if (ref.current === undefined)
|
|
121
|
+
ref.current = init();
|
|
122
|
+
return ref;
|
|
123
|
+
}
|
|
124
|
+
function useLatest(value) {
|
|
125
|
+
const ref = React.useRef(value);
|
|
126
|
+
useIsomorphicLayoutEffect(() => {
|
|
127
|
+
ref.current = value;
|
|
128
|
+
});
|
|
129
|
+
return ref;
|
|
130
|
+
}
|
|
131
|
+
function mergeRefs(refs) {
|
|
132
|
+
return (node) => {
|
|
133
|
+
for (const ref of refs) {
|
|
134
|
+
if (typeof ref === 'function')
|
|
135
|
+
ref(node);
|
|
136
|
+
else if (ref)
|
|
137
|
+
ref.current = node;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Reads a slice of the command state; re-renders when it changes. */
|
|
142
|
+
export function useCommandState(selector) {
|
|
143
|
+
const store = useStore();
|
|
144
|
+
const get = () => selector(store.snapshot());
|
|
145
|
+
return React.useSyncExternalStore(store.subscribe, get, get);
|
|
146
|
+
}
|
|
147
|
+
/** Batches store work into one layout effect after the next render. */
|
|
148
|
+
function useScheduleLayoutEffect() {
|
|
149
|
+
const [tick, setTick] = React.useState();
|
|
150
|
+
const fns = useLazyRef(() => new Map());
|
|
151
|
+
useIsomorphicLayoutEffect(() => {
|
|
152
|
+
fns.current.forEach((fn) => fn());
|
|
153
|
+
fns.current = new Map();
|
|
154
|
+
}, [tick]);
|
|
155
|
+
return (id, cb) => {
|
|
156
|
+
fns.current.set(id, cb);
|
|
157
|
+
setTick({});
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A row's or group's identity: the first string in `deps`, else the text of
|
|
162
|
+
* the first ref's element, trimmed and lowercased — as cmdk computes it.
|
|
163
|
+
*/
|
|
164
|
+
function useValue(id, ref, deps) {
|
|
165
|
+
const valueRef = React.useRef(undefined);
|
|
166
|
+
const context = useCommand();
|
|
167
|
+
useIsomorphicLayoutEffect(() => {
|
|
168
|
+
const value = (() => {
|
|
169
|
+
for (const part of deps) {
|
|
170
|
+
if (typeof part === 'string')
|
|
171
|
+
return part.trim().toLowerCase();
|
|
172
|
+
if (typeof part === 'object' && part && 'current' in part) {
|
|
173
|
+
const node = part.current;
|
|
174
|
+
return node ? node.textContent?.trim().toLowerCase() : valueRef.current;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
})();
|
|
179
|
+
context.value(id, value);
|
|
180
|
+
ref.current?.setAttribute(VALUE_ATTR, value);
|
|
181
|
+
valueRef.current = value;
|
|
182
|
+
});
|
|
183
|
+
return valueRef;
|
|
184
|
+
}
|
|
185
|
+
const SR_ONLY = {
|
|
186
|
+
position: 'absolute',
|
|
187
|
+
width: '1px',
|
|
188
|
+
height: '1px',
|
|
189
|
+
padding: '0',
|
|
190
|
+
margin: '-1px',
|
|
191
|
+
overflow: 'hidden',
|
|
192
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
193
|
+
whiteSpace: 'nowrap',
|
|
194
|
+
borderWidth: '0',
|
|
195
|
+
};
|
|
196
|
+
export const CommandRoot = React.forwardRef((props, forwardedRef) => {
|
|
197
|
+
const ref = React.useRef(null);
|
|
198
|
+
const state = useLazyRef(() => ({
|
|
199
|
+
search: '',
|
|
200
|
+
value: props.value ?? props.defaultValue?.toLowerCase() ?? '',
|
|
201
|
+
filtered: { count: 0, items: new Map(), groups: new Set() },
|
|
202
|
+
}));
|
|
203
|
+
const allItems = useLazyRef(() => new Set());
|
|
204
|
+
const allGroups = useLazyRef(() => new Map());
|
|
205
|
+
const ids = useLazyRef(() => new Map());
|
|
206
|
+
const listeners = useLazyRef(() => new Set());
|
|
207
|
+
const propsRef = useLatest(props);
|
|
208
|
+
const { label, children, value, onValueChange: _onValueChange, filter: _filter, shouldFilter: _shouldFilter, vimBindings = true, loop: _loop, defaultValue: _defaultValue, ...etc } = props;
|
|
209
|
+
const listId = React.useId();
|
|
210
|
+
const labelId = React.useId();
|
|
211
|
+
const inputId = React.useId();
|
|
212
|
+
const schedule = useScheduleLayoutEffect();
|
|
213
|
+
// True while the selection is the core's own pick (the first row), false
|
|
214
|
+
// once the user moves it with the keyboard or the pointer.
|
|
215
|
+
const autoSelected = React.useRef(true);
|
|
216
|
+
const pickingFirst = React.useRef(false);
|
|
217
|
+
useIsomorphicLayoutEffect(() => {
|
|
218
|
+
if (value !== undefined) {
|
|
219
|
+
state.current.value = value.trim().toLowerCase();
|
|
220
|
+
schedule(6, scrollSelectedIntoView);
|
|
221
|
+
store.emit();
|
|
222
|
+
}
|
|
223
|
+
}, [value]);
|
|
224
|
+
const store = React.useMemo(() => ({
|
|
225
|
+
subscribe: (cb) => {
|
|
226
|
+
listeners.current.add(cb);
|
|
227
|
+
return () => listeners.current.delete(cb);
|
|
228
|
+
},
|
|
229
|
+
snapshot: () => state.current,
|
|
230
|
+
setState: (key, next, opts) => {
|
|
231
|
+
if (Object.is(state.current[key], next))
|
|
232
|
+
return;
|
|
233
|
+
state.current[key] = next;
|
|
234
|
+
if (key === 'search') {
|
|
235
|
+
filterItems();
|
|
236
|
+
sort();
|
|
237
|
+
schedule(1, selectFirstItem);
|
|
238
|
+
}
|
|
239
|
+
else if (key === 'value') {
|
|
240
|
+
autoSelected.current = pickingFirst.current;
|
|
241
|
+
if (propsRef.current.value !== undefined) {
|
|
242
|
+
propsRef.current.onValueChange?.(next ?? '');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
else if (!opts) {
|
|
246
|
+
schedule(5, scrollSelectedIntoView);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
store.emit();
|
|
250
|
+
},
|
|
251
|
+
emit: () => listeners.current.forEach((l) => l()),
|
|
252
|
+
}),
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
+
[]);
|
|
255
|
+
const context = React.useMemo(() => ({
|
|
256
|
+
value: (id, next) => {
|
|
257
|
+
if (next !== ids.current.get(id)) {
|
|
258
|
+
ids.current.set(id, next);
|
|
259
|
+
state.current.filtered.items.set(id, score(next));
|
|
260
|
+
schedule(2, () => {
|
|
261
|
+
sort();
|
|
262
|
+
ensureSelection();
|
|
263
|
+
store.emit();
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
item: (id, groupId) => {
|
|
268
|
+
allItems.current.add(id);
|
|
269
|
+
if (groupId) {
|
|
270
|
+
const group = allGroups.current.get(groupId);
|
|
271
|
+
if (group)
|
|
272
|
+
group.add(id);
|
|
273
|
+
else
|
|
274
|
+
allGroups.current.set(groupId, new Set([id]));
|
|
275
|
+
}
|
|
276
|
+
schedule(3, () => {
|
|
277
|
+
filterItems();
|
|
278
|
+
sort();
|
|
279
|
+
ensureSelection();
|
|
280
|
+
store.emit();
|
|
281
|
+
});
|
|
282
|
+
return () => {
|
|
283
|
+
ids.current.delete(id);
|
|
284
|
+
allItems.current.delete(id);
|
|
285
|
+
state.current.filtered.items.delete(id);
|
|
286
|
+
const selected = getSelectedItem();
|
|
287
|
+
schedule(4, () => {
|
|
288
|
+
filterItems();
|
|
289
|
+
if (selected?.getAttribute('id') === id)
|
|
290
|
+
selectFirstItem();
|
|
291
|
+
else
|
|
292
|
+
ensureSelection();
|
|
293
|
+
store.emit();
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
group: (id) => {
|
|
298
|
+
if (!allGroups.current.has(id))
|
|
299
|
+
allGroups.current.set(id, new Set());
|
|
300
|
+
return () => {
|
|
301
|
+
ids.current.delete(id);
|
|
302
|
+
allGroups.current.delete(id);
|
|
303
|
+
};
|
|
304
|
+
},
|
|
305
|
+
filter: () => propsRef.current.shouldFilter,
|
|
306
|
+
label: label || props['aria-label'],
|
|
307
|
+
commandRef: ref,
|
|
308
|
+
listId,
|
|
309
|
+
inputId,
|
|
310
|
+
labelId,
|
|
311
|
+
}),
|
|
312
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
313
|
+
[]);
|
|
314
|
+
function score(next) {
|
|
315
|
+
const filter = propsRef.current.filter ?? commandScore;
|
|
316
|
+
return next ? filter(next, state.current.search) : 0;
|
|
317
|
+
}
|
|
318
|
+
/** cmdk 0.2.1's re-sort, as shipped (see the file comment). */
|
|
319
|
+
function sort() {
|
|
320
|
+
if (!ref.current || !state.current.search || propsRef.current.shouldFilter === false)
|
|
321
|
+
return;
|
|
322
|
+
const scores = state.current.filtered.items;
|
|
323
|
+
const groups = [];
|
|
324
|
+
state.current.filtered.groups.forEach((groupId) => {
|
|
325
|
+
let max = 0;
|
|
326
|
+
allGroups.current.get(groupId)?.forEach((itemId) => {
|
|
327
|
+
max = Math.max(scores.get(itemId) ?? 0, max);
|
|
328
|
+
});
|
|
329
|
+
groups.push([groupId, max]);
|
|
330
|
+
});
|
|
331
|
+
const sizer = ref.current.querySelector(LIST_SIZER_SELECTOR);
|
|
332
|
+
getValidItems()
|
|
333
|
+
.sort((a, b) => (scores.get(b.getAttribute(VALUE_ATTR)) ?? 0) -
|
|
334
|
+
(scores.get(a.getAttribute(VALUE_ATTR)) ?? 0))
|
|
335
|
+
.forEach((item) => {
|
|
336
|
+
const group = item.closest(GROUP_ITEMS_SELECTOR);
|
|
337
|
+
const parent = group ?? sizer;
|
|
338
|
+
const node = item.parentElement === parent ? item : item.closest(`${GROUP_ITEMS_SELECTOR} > *`);
|
|
339
|
+
if (parent && node)
|
|
340
|
+
parent.appendChild(node);
|
|
341
|
+
});
|
|
342
|
+
groups
|
|
343
|
+
.sort((a, b) => b[1] - a[1])
|
|
344
|
+
.forEach(([groupId]) => {
|
|
345
|
+
const element = ref.current?.querySelector(`${GROUP_SELECTOR}[${VALUE_ATTR}="${groupId}"]`);
|
|
346
|
+
element?.parentElement?.appendChild(element);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Keeps the selection on a row that is rendered, and keeps the core's own
|
|
351
|
+
* pick on the first row as rows arrive. A row that stops matching
|
|
352
|
+
* renders nothing but stays mounted, so its unmount never reselects. A host
|
|
353
|
+
* that renders its rows from a deferred copy of the search (the command
|
|
354
|
+
* palette) mounts the matching rows a render later; without this check the
|
|
355
|
+
* selection stays on a hidden row and Enter does nothing.
|
|
356
|
+
*/
|
|
357
|
+
function ensureSelection() {
|
|
358
|
+
if (autoSelected.current)
|
|
359
|
+
return selectFirstItem();
|
|
360
|
+
const current = state.current.value;
|
|
361
|
+
if (current && getValidItems().some((el) => el.getAttribute(VALUE_ATTR) === current))
|
|
362
|
+
return;
|
|
363
|
+
selectFirstItem();
|
|
364
|
+
}
|
|
365
|
+
function selectFirstItem() {
|
|
366
|
+
const item = getValidItems().find((el) => el.getAttribute('aria-disabled') !== 'true');
|
|
367
|
+
const next = item?.getAttribute(VALUE_ATTR);
|
|
368
|
+
pickingFirst.current = true;
|
|
369
|
+
store.setState('value', (next || undefined));
|
|
370
|
+
pickingFirst.current = false;
|
|
371
|
+
autoSelected.current = true;
|
|
372
|
+
}
|
|
373
|
+
function filterItems() {
|
|
374
|
+
if (!state.current.search || propsRef.current.shouldFilter === false) {
|
|
375
|
+
state.current.filtered.count = allItems.current.size;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
state.current.filtered.groups = new Set();
|
|
379
|
+
let count = 0;
|
|
380
|
+
for (const id of allItems.current) {
|
|
381
|
+
const rank = score(ids.current.get(id));
|
|
382
|
+
state.current.filtered.items.set(id, rank);
|
|
383
|
+
if (rank > 0)
|
|
384
|
+
count++;
|
|
385
|
+
}
|
|
386
|
+
for (const [groupId, group] of allGroups.current) {
|
|
387
|
+
for (const itemId of group) {
|
|
388
|
+
if ((state.current.filtered.items.get(itemId) ?? 0) > 0) {
|
|
389
|
+
state.current.filtered.groups.add(groupId);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
state.current.filtered.count = count;
|
|
395
|
+
}
|
|
396
|
+
function scrollSelectedIntoView() {
|
|
397
|
+
const item = getSelectedItem();
|
|
398
|
+
if (!item)
|
|
399
|
+
return;
|
|
400
|
+
if (item.parentElement?.firstChild === item) {
|
|
401
|
+
item
|
|
402
|
+
.closest(GROUP_SELECTOR)
|
|
403
|
+
?.querySelector(GROUP_HEADING_SELECTOR)
|
|
404
|
+
?.scrollIntoView({ block: 'nearest' });
|
|
405
|
+
}
|
|
406
|
+
item.scrollIntoView({ block: 'nearest' });
|
|
407
|
+
}
|
|
408
|
+
function getSelectedItem() {
|
|
409
|
+
return (ref.current?.querySelector(`${ITEM_SELECTOR}[aria-selected="true"]`) ?? null);
|
|
410
|
+
}
|
|
411
|
+
function getValidItems() {
|
|
412
|
+
return Array.from(ref.current?.querySelectorAll(VALID_ITEM_SELECTOR) ?? []);
|
|
413
|
+
}
|
|
414
|
+
function updateSelectedToIndex(index) {
|
|
415
|
+
const item = getValidItems()[index];
|
|
416
|
+
if (item)
|
|
417
|
+
store.setState('value', item.getAttribute(VALUE_ATTR));
|
|
418
|
+
}
|
|
419
|
+
function updateSelectedByChange(change) {
|
|
420
|
+
const selected = getSelectedItem();
|
|
421
|
+
const items = getValidItems();
|
|
422
|
+
const index = items.findIndex((item) => item === selected);
|
|
423
|
+
let next = items[index + change];
|
|
424
|
+
if (propsRef.current.loop) {
|
|
425
|
+
next =
|
|
426
|
+
index + change < 0
|
|
427
|
+
? items[items.length - 1]
|
|
428
|
+
: index + change === items.length
|
|
429
|
+
? items[0]
|
|
430
|
+
: items[index + change];
|
|
431
|
+
}
|
|
432
|
+
if (next)
|
|
433
|
+
store.setState('value', next.getAttribute(VALUE_ATTR));
|
|
434
|
+
}
|
|
435
|
+
function updateSelectedToGroup(change) {
|
|
436
|
+
let group = getSelectedItem()?.closest(GROUP_SELECTOR) ?? null;
|
|
437
|
+
let item = null;
|
|
438
|
+
while (group && !item) {
|
|
439
|
+
group =
|
|
440
|
+
change > 0
|
|
441
|
+
? findNextSibling(group, GROUP_SELECTOR)
|
|
442
|
+
: findPreviousSibling(group, GROUP_SELECTOR);
|
|
443
|
+
item = group?.querySelector(VALID_ITEM_SELECTOR);
|
|
444
|
+
}
|
|
445
|
+
if (item)
|
|
446
|
+
store.setState('value', item.getAttribute(VALUE_ATTR));
|
|
447
|
+
else
|
|
448
|
+
updateSelectedByChange(change);
|
|
449
|
+
}
|
|
450
|
+
const last = () => updateSelectedToIndex(getValidItems().length - 1);
|
|
451
|
+
const next = (e) => {
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
if (e.metaKey)
|
|
454
|
+
last();
|
|
455
|
+
else if (e.altKey)
|
|
456
|
+
updateSelectedToGroup(1);
|
|
457
|
+
else
|
|
458
|
+
updateSelectedByChange(1);
|
|
459
|
+
};
|
|
460
|
+
const prev = (e) => {
|
|
461
|
+
e.preventDefault();
|
|
462
|
+
if (e.metaKey)
|
|
463
|
+
updateSelectedToIndex(0);
|
|
464
|
+
else if (e.altKey)
|
|
465
|
+
updateSelectedToGroup(-1);
|
|
466
|
+
else
|
|
467
|
+
updateSelectedByChange(-1);
|
|
468
|
+
};
|
|
469
|
+
return (_jsxs("div", { ref: mergeRefs([ref, forwardedRef]), ...etc, "cmdk-root": "", onKeyDown: (e) => {
|
|
470
|
+
etc.onKeyDown?.(e);
|
|
471
|
+
if (e.defaultPrevented)
|
|
472
|
+
return;
|
|
473
|
+
switch (e.key) {
|
|
474
|
+
case 'n':
|
|
475
|
+
case 'j':
|
|
476
|
+
if (vimBindings && e.ctrlKey)
|
|
477
|
+
next(e);
|
|
478
|
+
break;
|
|
479
|
+
case 'ArrowDown':
|
|
480
|
+
next(e);
|
|
481
|
+
break;
|
|
482
|
+
case 'p':
|
|
483
|
+
case 'k':
|
|
484
|
+
if (vimBindings && e.ctrlKey)
|
|
485
|
+
prev(e);
|
|
486
|
+
break;
|
|
487
|
+
case 'ArrowUp':
|
|
488
|
+
prev(e);
|
|
489
|
+
break;
|
|
490
|
+
case 'Home':
|
|
491
|
+
e.preventDefault();
|
|
492
|
+
updateSelectedToIndex(0);
|
|
493
|
+
break;
|
|
494
|
+
case 'End':
|
|
495
|
+
e.preventDefault();
|
|
496
|
+
last();
|
|
497
|
+
break;
|
|
498
|
+
case 'Enter':
|
|
499
|
+
if (!e.nativeEvent.isComposing) {
|
|
500
|
+
e.preventDefault();
|
|
501
|
+
getSelectedItem()?.dispatchEvent(new Event(SELECT_EVENT));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}, children: [_jsx("label", { "cmdk-label": "", htmlFor: context.inputId, id: context.labelId, style: SR_ONLY, children: label }), _jsx(StoreContext.Provider, { value: store, children: _jsx(CommandContext.Provider, { value: context, children: children }) })] }));
|
|
505
|
+
});
|
|
506
|
+
CommandRoot.displayName = 'CommandRoot';
|
|
507
|
+
function findNextSibling(el, selector) {
|
|
508
|
+
let sibling = el.nextElementSibling;
|
|
509
|
+
while (sibling) {
|
|
510
|
+
if (sibling.matches(selector))
|
|
511
|
+
return sibling;
|
|
512
|
+
sibling = sibling.nextElementSibling;
|
|
513
|
+
}
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
function findPreviousSibling(el, selector) {
|
|
517
|
+
let sibling = el.previousElementSibling;
|
|
518
|
+
while (sibling) {
|
|
519
|
+
if (sibling.matches(selector))
|
|
520
|
+
return sibling;
|
|
521
|
+
sibling = sibling.previousElementSibling;
|
|
522
|
+
}
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
export const CommandItemCore = React.forwardRef((props, forwardedRef) => {
|
|
526
|
+
const id = React.useId();
|
|
527
|
+
const ref = React.useRef(null);
|
|
528
|
+
const groupContext = React.useContext(GroupContext);
|
|
529
|
+
const context = useCommand();
|
|
530
|
+
const propsRef = useLatest(props);
|
|
531
|
+
const forceMount = propsRef.current?.forceMount ?? groupContext?.forceMount;
|
|
532
|
+
useIsomorphicLayoutEffect(() => context.item(id, groupContext?.id), []);
|
|
533
|
+
const value = useValue(id, ref, [props.value, props.children, ref]);
|
|
534
|
+
const store = useStore();
|
|
535
|
+
const selected = useCommandState((s) => Boolean(s.value) && s.value === value.current);
|
|
536
|
+
const render = useCommandState((s) => forceMount || context.filter() === false
|
|
537
|
+
? true
|
|
538
|
+
: s.search
|
|
539
|
+
? (s.filtered.items.get(id) ?? 0) > 0
|
|
540
|
+
: true);
|
|
541
|
+
React.useEffect(() => {
|
|
542
|
+
const element = ref.current;
|
|
543
|
+
if (!element || props.disabled)
|
|
544
|
+
return;
|
|
545
|
+
element.addEventListener(SELECT_EVENT, onSelect);
|
|
546
|
+
return () => element.removeEventListener(SELECT_EVENT, onSelect);
|
|
547
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
548
|
+
}, [render, props.onSelect, props.disabled]);
|
|
549
|
+
function onSelect() {
|
|
550
|
+
select();
|
|
551
|
+
propsRef.current.onSelect?.(value.current);
|
|
552
|
+
}
|
|
553
|
+
function select() {
|
|
554
|
+
store.setState('value', value.current, true);
|
|
555
|
+
}
|
|
556
|
+
if (!render)
|
|
557
|
+
return null;
|
|
558
|
+
const { disabled, value: _value, onSelect: _onSelect, forceMount: _forceMount, ...etc } = props;
|
|
559
|
+
return (_jsx("div", { ref: mergeRefs([ref, forwardedRef]), ...etc, id: id, "cmdk-item": "", role: "option", "aria-disabled": disabled || undefined, "aria-selected": selected || undefined, "data-disabled": disabled || undefined, "data-selected": selected || undefined, onPointerMove: disabled ? undefined : select, onClick: disabled ? undefined : onSelect, children: props.children }));
|
|
560
|
+
});
|
|
561
|
+
CommandItemCore.displayName = 'CommandItemCore';
|
|
562
|
+
export const CommandGroupCore = React.forwardRef((props, forwardedRef) => {
|
|
563
|
+
const { heading, children, forceMount, ...etc } = props;
|
|
564
|
+
const id = React.useId();
|
|
565
|
+
const ref = React.useRef(null);
|
|
566
|
+
const headingRef = React.useRef(null);
|
|
567
|
+
const headingId = React.useId();
|
|
568
|
+
const context = useCommand();
|
|
569
|
+
const render = useCommandState((s) => forceMount || context.filter() === false ? true : s.search ? s.filtered.groups.has(id) : true);
|
|
570
|
+
useIsomorphicLayoutEffect(() => context.group(id), []);
|
|
571
|
+
useValue(id, ref, [props.value, props.heading, headingRef]);
|
|
572
|
+
const contextValue = React.useMemo(() => ({ id, forceMount }), [id, forceMount]);
|
|
573
|
+
return (_jsxs("div", { ref: mergeRefs([ref, forwardedRef]), ...etc, "cmdk-group": "", role: "presentation", hidden: render ? undefined : true, children: [heading && (_jsx("div", { ref: headingRef, "cmdk-group-heading": "", "aria-hidden": true, id: headingId, children: heading })), _jsx("div", { "cmdk-group-items": "", role: "group", "aria-labelledby": heading ? headingId : undefined, children: _jsx(GroupContext.Provider, { value: contextValue, children: children }) })] }));
|
|
574
|
+
});
|
|
575
|
+
CommandGroupCore.displayName = 'CommandGroupCore';
|
|
576
|
+
/* ---------- separator, input, list, empty ---------- */
|
|
577
|
+
export const CommandSeparatorCore = React.forwardRef(({ alwaysRender, ...etc }, forwardedRef) => {
|
|
578
|
+
const render = useCommandState((s) => !s.search);
|
|
579
|
+
if (!alwaysRender && !render)
|
|
580
|
+
return null;
|
|
581
|
+
return _jsx("div", { ref: forwardedRef, ...etc, "cmdk-separator": "", role: "separator" });
|
|
582
|
+
});
|
|
583
|
+
CommandSeparatorCore.displayName = 'CommandSeparatorCore';
|
|
584
|
+
export const CommandInputCore = React.forwardRef(({ onValueChange, ...etc }, forwardedRef) => {
|
|
585
|
+
const isControlled = etc.value != null;
|
|
586
|
+
const store = useStore();
|
|
587
|
+
const search = useCommandState((s) => s.search);
|
|
588
|
+
const value = useCommandState((s) => s.value);
|
|
589
|
+
const context = useCommand();
|
|
590
|
+
const selectedItemId = React.useMemo(() => {
|
|
591
|
+
const item = context.commandRef.current?.querySelector(`${ITEM_SELECTOR}[${VALUE_ATTR}="${value}"]`);
|
|
592
|
+
return item?.getAttribute('id') ?? undefined;
|
|
593
|
+
}, [value, context.commandRef]);
|
|
594
|
+
React.useEffect(() => {
|
|
595
|
+
if (etc.value != null)
|
|
596
|
+
store.setState('search', etc.value);
|
|
597
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
598
|
+
}, [etc.value]);
|
|
599
|
+
return (_jsx("input", { ref: forwardedRef, ...etc, "cmdk-input": "", autoComplete: "off", autoCorrect: "off", spellCheck: false, "aria-autocomplete": "list", role: "combobox", "aria-expanded": true, "aria-controls": context.listId, "aria-labelledby": context.labelId, "aria-activedescendant": selectedItemId, id: context.inputId, type: "text", value: isControlled ? etc.value : search, onChange: (e) => {
|
|
600
|
+
if (!isControlled)
|
|
601
|
+
store.setState('search', e.target.value);
|
|
602
|
+
onValueChange?.(e.target.value);
|
|
603
|
+
} }));
|
|
604
|
+
});
|
|
605
|
+
CommandInputCore.displayName = 'CommandInputCore';
|
|
606
|
+
export const CommandListCore = React.forwardRef(({ children, ...etc }, forwardedRef) => {
|
|
607
|
+
const ref = React.useRef(null);
|
|
608
|
+
const height = React.useRef(null);
|
|
609
|
+
const context = useCommand();
|
|
610
|
+
React.useEffect(() => {
|
|
611
|
+
if (!height.current || !ref.current || typeof ResizeObserver === 'undefined')
|
|
612
|
+
return;
|
|
613
|
+
const sizer = height.current;
|
|
614
|
+
const list = ref.current;
|
|
615
|
+
let frame;
|
|
616
|
+
const observer = new ResizeObserver(() => {
|
|
617
|
+
frame = requestAnimationFrame(() => {
|
|
618
|
+
list.style.setProperty('--cmdk-list-height', `${sizer.offsetHeight.toFixed(1)}px`);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
observer.observe(sizer);
|
|
622
|
+
return () => {
|
|
623
|
+
cancelAnimationFrame(frame);
|
|
624
|
+
observer.unobserve(sizer);
|
|
625
|
+
};
|
|
626
|
+
}, []);
|
|
627
|
+
return (_jsx("div", { ref: mergeRefs([ref, forwardedRef]), ...etc, "cmdk-list": "", role: "listbox", "aria-label": "Suggestions", id: context.listId, "aria-labelledby": context.inputId, children: _jsx("div", { ref: height, "cmdk-list-sizer": "", children: children }) }));
|
|
628
|
+
});
|
|
629
|
+
CommandListCore.displayName = 'CommandListCore';
|
|
630
|
+
/** Shows when no row matches the search. Hidden on the first render, as in cmdk. */
|
|
631
|
+
export const CommandEmptyCore = React.forwardRef((props, forwardedRef) => {
|
|
632
|
+
const isFirstRender = React.useRef(true);
|
|
633
|
+
const render = useCommandState((s) => s.filtered.count === 0);
|
|
634
|
+
React.useEffect(() => {
|
|
635
|
+
isFirstRender.current = false;
|
|
636
|
+
}, []);
|
|
637
|
+
// eslint-disable-next-line react-hooks/refs
|
|
638
|
+
if (isFirstRender.current || !render)
|
|
639
|
+
return null;
|
|
640
|
+
return _jsx("div", { ref: forwardedRef, ...props, "cmdk-empty": "", role: "presentation" });
|
|
641
|
+
});
|
|
642
|
+
CommandEmptyCore.displayName = 'CommandEmptyCore';
|