@auth0/quantum-product 2.10.2 → 2.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/command-palette/command-palette-classes.d.ts +5 -0
  2. package/command-palette/command-palette-classes.js +34 -0
  3. package/command-palette/command-palette-context.d.ts +8 -0
  4. package/command-palette/command-palette-context.js +61 -0
  5. package/command-palette/command-palette-dialog.d.ts +3 -0
  6. package/command-palette/command-palette-dialog.js +112 -0
  7. package/command-palette/command-palette-empty.d.ts +3 -0
  8. package/command-palette/command-palette-empty.js +90 -0
  9. package/command-palette/command-palette-footer.d.ts +4 -0
  10. package/command-palette/command-palette-footer.js +111 -0
  11. package/command-palette/command-palette-group.d.ts +3 -0
  12. package/command-palette/command-palette-group.js +118 -0
  13. package/command-palette/command-palette-input.d.ts +3 -0
  14. package/command-palette/command-palette-input.js +144 -0
  15. package/command-palette/command-palette-item.d.ts +3 -0
  16. package/command-palette/command-palette-item.js +235 -0
  17. package/command-palette/command-palette-list.d.ts +3 -0
  18. package/command-palette/command-palette-list.js +101 -0
  19. package/command-palette/command-palette-loading.d.ts +3 -0
  20. package/command-palette/command-palette-loading.js +89 -0
  21. package/command-palette/command-palette-score.d.ts +1 -0
  22. package/command-palette/command-palette-score.js +47 -0
  23. package/command-palette/command-palette-separator.d.ts +3 -0
  24. package/command-palette/command-palette-separator.js +86 -0
  25. package/command-palette/command-palette-tabs.d.ts +4 -0
  26. package/command-palette/command-palette-tabs.js +146 -0
  27. package/command-palette/command-palette-types.d.ts +121 -0
  28. package/command-palette/command-palette-types.js +2 -0
  29. package/command-palette/command-palette.d.ts +5 -0
  30. package/command-palette/command-palette.js +474 -0
  31. package/command-palette/index.d.ts +27 -0
  32. package/command-palette/index.js +36 -0
  33. package/command-palette/use-command-palette-shortcut.d.ts +6 -0
  34. package/command-palette/use-command-palette-shortcut.js +65 -0
  35. package/esm/command-palette/command-palette-classes.js +30 -0
  36. package/esm/command-palette/command-palette-context.js +22 -0
  37. package/esm/command-palette/command-palette-dialog.js +73 -0
  38. package/esm/command-palette/command-palette-empty.js +51 -0
  39. package/esm/command-palette/command-palette-footer.js +72 -0
  40. package/esm/command-palette/command-palette-group.js +79 -0
  41. package/esm/command-palette/command-palette-input.js +105 -0
  42. package/esm/command-palette/command-palette-item.js +196 -0
  43. package/esm/command-palette/command-palette-list.js +62 -0
  44. package/esm/command-palette/command-palette-loading.js +50 -0
  45. package/esm/command-palette/command-palette-score.js +44 -0
  46. package/esm/command-palette/command-palette-separator.js +47 -0
  47. package/esm/command-palette/command-palette-tabs.js +107 -0
  48. package/esm/command-palette/command-palette-types.js +1 -0
  49. package/esm/command-palette/command-palette.js +435 -0
  50. package/esm/command-palette/index.js +14 -0
  51. package/esm/command-palette/use-command-palette-shortcut.js +29 -0
  52. package/esm/index.js +1 -0
  53. package/index.d.ts +1 -0
  54. package/index.js +1 -0
  55. package/package.json +1 -1
@@ -0,0 +1,474 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __rest = (this && this.__rest) || function (s, e) {
47
+ var t = {};
48
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
49
+ t[p] = s[p];
50
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
51
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
52
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
53
+ t[p[i]] = s[p[i]];
54
+ }
55
+ return t;
56
+ };
57
+ var __read = (this && this.__read) || function (o, n) {
58
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
59
+ if (!m) return o;
60
+ var i = m.call(o), r, ar = [], e;
61
+ try {
62
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
63
+ }
64
+ catch (error) { e = { error: error }; }
65
+ finally {
66
+ try {
67
+ if (r && !r.done && (m = i["return"])) m.call(i);
68
+ }
69
+ finally { if (e) throw e.error; }
70
+ }
71
+ return ar;
72
+ };
73
+ var __importDefault = (this && this.__importDefault) || function (mod) {
74
+ return (mod && mod.__esModule) ? mod : { "default": mod };
75
+ };
76
+ Object.defineProperty(exports, "__esModule", { value: true });
77
+ exports.VALUE_ATTR = exports.CommandPalette = void 0;
78
+ var React = __importStar(require("react"));
79
+ var styled_1 = require("../styled");
80
+ var classes_1 = require("../styles/classes");
81
+ var clsx_1 = __importDefault(require("../utils/clsx"));
82
+ var command_palette_classes_1 = require("./command-palette-classes");
83
+ var command_palette_context_1 = require("./command-palette-context");
84
+ var command_palette_score_1 = require("./command-palette-score");
85
+ var VALUE_ATTR = 'data-value';
86
+ exports.VALUE_ATTR = VALUE_ATTR;
87
+ var ITEM_SELECTOR = ".".concat(command_palette_classes_1.commandPaletteClasses.item);
88
+ var GROUP_ITEMS_SELECTOR = ".".concat(command_palette_classes_1.commandPaletteClasses.groupItems);
89
+ var VALID_ITEM_SELECTOR = "".concat(ITEM_SELECTOR, ":not([aria-disabled=\"true\"])");
90
+ var Root = (0, styled_1.styled)('div', {
91
+ name: command_palette_classes_1.commandPaletteComponentName,
92
+ slot: 'Root',
93
+ })(function (_a) {
94
+ var theme = _a.theme;
95
+ return ({
96
+ display: 'flex',
97
+ flexDirection: 'column',
98
+ width: '100%',
99
+ fontFamily: theme.typography.fontFamily,
100
+ overflow: 'hidden',
101
+ borderRadius: theme.typography.pxToRem(12),
102
+ backgroundColor: theme.tokens.color_bg_layer_elevated,
103
+ '&:focus-visible': {
104
+ outline: "none",
105
+ },
106
+ });
107
+ });
108
+ function defaultFilter(value, search, keywords) {
109
+ var allText = (keywords === null || keywords === void 0 ? void 0 : keywords.length) ? "".concat(value, " ").concat(keywords.join(' ')) : value;
110
+ return (0, command_palette_score_1.commandScore)(allText, search);
111
+ }
112
+ function useAsRef(value) {
113
+ var ref = React.useRef(value);
114
+ ref.current = value;
115
+ return ref;
116
+ }
117
+ function useLazyRef(fn) {
118
+ var ref = React.useRef(undefined);
119
+ if (ref.current === undefined) {
120
+ ref.current = fn();
121
+ }
122
+ return ref;
123
+ }
124
+ function findNextItem(el, loop) {
125
+ var _a, _b, _c;
126
+ var next = el.nextElementSibling;
127
+ while (next) {
128
+ if (next.matches(VALID_ITEM_SELECTOR))
129
+ return next;
130
+ next = next.nextElementSibling;
131
+ }
132
+ var group = el.closest(GROUP_ITEMS_SELECTOR);
133
+ while (group) {
134
+ var nextGroup = (_a = group.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling;
135
+ if (nextGroup) {
136
+ var items = nextGroup.querySelector(GROUP_ITEMS_SELECTOR);
137
+ if (items) {
138
+ var firstItem = items.querySelector(VALID_ITEM_SELECTOR);
139
+ if (firstItem)
140
+ return firstItem;
141
+ }
142
+ group = nextGroup.querySelector(GROUP_ITEMS_SELECTOR);
143
+ }
144
+ else {
145
+ group = null;
146
+ }
147
+ }
148
+ if (!el.closest(GROUP_ITEMS_SELECTOR)) {
149
+ var sibling = (_b = el.parentElement) === null || _b === void 0 ? void 0 : _b.nextElementSibling;
150
+ while (sibling) {
151
+ var item = ((_c = sibling.matches) === null || _c === void 0 ? void 0 : _c.call(sibling, VALID_ITEM_SELECTOR)) ? sibling : sibling.querySelector(VALID_ITEM_SELECTOR);
152
+ if (item)
153
+ return item;
154
+ sibling = sibling.nextElementSibling;
155
+ }
156
+ }
157
+ if (loop) {
158
+ var list = el.closest(".".concat(command_palette_classes_1.commandPaletteClasses.list));
159
+ if (list) {
160
+ return list.querySelector(VALID_ITEM_SELECTOR) || undefined;
161
+ }
162
+ }
163
+ return undefined;
164
+ }
165
+ function findPrevItem(el, loop) {
166
+ var _a;
167
+ var prev = el.previousElementSibling;
168
+ while (prev) {
169
+ if (prev.matches(VALID_ITEM_SELECTOR))
170
+ return prev;
171
+ prev = prev.previousElementSibling;
172
+ }
173
+ var group = el.closest(GROUP_ITEMS_SELECTOR);
174
+ while (group) {
175
+ var prevGroup = (_a = group.parentElement) === null || _a === void 0 ? void 0 : _a.previousElementSibling;
176
+ if (prevGroup) {
177
+ var items = prevGroup.querySelector(GROUP_ITEMS_SELECTOR);
178
+ if (items) {
179
+ var allItems = items.querySelectorAll(VALID_ITEM_SELECTOR);
180
+ if (allItems.length)
181
+ return allItems[allItems.length - 1];
182
+ }
183
+ group = prevGroup.querySelector(GROUP_ITEMS_SELECTOR);
184
+ }
185
+ else {
186
+ group = null;
187
+ }
188
+ }
189
+ if (loop) {
190
+ var list = el.closest(".".concat(command_palette_classes_1.commandPaletteClasses.list));
191
+ if (list) {
192
+ var allItems = list.querySelectorAll(VALID_ITEM_SELECTOR);
193
+ return allItems.length ? allItems[allItems.length - 1] : undefined;
194
+ }
195
+ }
196
+ return undefined;
197
+ }
198
+ function getSelectedItem(listInnerRef, value) {
199
+ var _a;
200
+ return ((_a = listInnerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("".concat(ITEM_SELECTOR, "[").concat(VALUE_ATTR, "=\"").concat(encodeURIComponent(value), "\"]"))) || null;
201
+ }
202
+ function getValidItems(listInnerRef) {
203
+ var _a;
204
+ return Array.from(((_a = listInnerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(VALID_ITEM_SELECTOR)) || []);
205
+ }
206
+ function useScheduleLayoutEffect() {
207
+ var _a = __read(React.useState(0), 2), count = _a[0], setCount = _a[1];
208
+ var callbackRef = React.useRef(null);
209
+ React.useLayoutEffect(function () {
210
+ if (callbackRef.current) {
211
+ callbackRef.current();
212
+ callbackRef.current = null;
213
+ }
214
+ }, [count]);
215
+ return React.useCallback(function (callback) {
216
+ callbackRef.current = callback;
217
+ setCount(function (c) { return c + 1; });
218
+ }, []);
219
+ }
220
+ exports.CommandPalette = React.forwardRef(function (props, ref) {
221
+ var _a = props.label, label = _a === void 0 ? 'Command palette' : _a, searchProp = props.search, _onSearchChange = props.onSearchChange, valueProp = props.value, _onValueChange = props.onValueChange, filterProp = props.filter, _b = props.shouldFilter, shouldFilter = _b === void 0 ? true : _b, _c = props.loop, loop = _c === void 0 ? false : _c, _onSelect = props.onSelect, children = props.children, className = props.className, rootProps = __rest(props, ["label", "search", "onSearchChange", "value", "onValueChange", "filter", "shouldFilter", "loop", "onSelect", "children", "className"]);
222
+ var id = React.useId();
223
+ var listId = "".concat(id, "-list");
224
+ var inputId = "".concat(id, "-input");
225
+ var listInnerRef = React.useRef(null);
226
+ var allItems = React.useRef(new Map());
227
+ var allGroups = React.useRef(new Map());
228
+ var filter = shouldFilter ? filterProp !== null && filterProp !== void 0 ? filterProp : defaultFilter : false;
229
+ var propsRef = useAsRef(props);
230
+ var schedule = useScheduleLayoutEffect();
231
+ var store = useLazyRef(function () {
232
+ var listeners = new Set();
233
+ var state = {
234
+ search: searchProp || '',
235
+ selectedValue: valueProp || '',
236
+ filtered: { count: 0, items: new Map(), groups: new Map() },
237
+ };
238
+ return {
239
+ subscribe: function (callback) {
240
+ listeners.add(callback);
241
+ return function () { return listeners.delete(callback); };
242
+ },
243
+ snapshot: function () {
244
+ return state;
245
+ },
246
+ setState: function (key, value, shouldEmit) {
247
+ var _a;
248
+ var _b, _c;
249
+ if (Object.is(state[key], value))
250
+ return;
251
+ state = __assign(__assign({}, state), (_a = {}, _a[key] = value, _a));
252
+ if (key === 'search') {
253
+ filterItems();
254
+ schedule(function () { return selectFirstItem(); });
255
+ (_c = (_b = propsRef.current).onSearchChange) === null || _c === void 0 ? void 0 : _c.call(_b, value);
256
+ }
257
+ if (shouldEmit !== false) {
258
+ this.emit();
259
+ }
260
+ },
261
+ emit: function () {
262
+ listeners.forEach(function (l) { return l(); });
263
+ },
264
+ };
265
+ });
266
+ var filterItems = React.useCallback(function () {
267
+ if (!filter) {
268
+ store.current.setState('filtered', {
269
+ count: allItems.current.size,
270
+ items: new Map(),
271
+ groups: new Map(),
272
+ });
273
+ return;
274
+ }
275
+ var search = store.current.snapshot().search;
276
+ var items = new Map();
277
+ var groups = new Map();
278
+ var count = 0;
279
+ allItems.current.forEach(function (itemMeta, id) {
280
+ var score = filter(itemMeta.value, search, itemMeta.keywords);
281
+ items.set(id, score);
282
+ if (score > 0)
283
+ count++;
284
+ });
285
+ allGroups.current.forEach(function (groupItems, groupId) {
286
+ var groupCount = 0;
287
+ groupItems.forEach(function (itemId) {
288
+ var score = items.get(itemId) || 0;
289
+ if (score > 0)
290
+ groupCount++;
291
+ });
292
+ groups.set(groupId, groupCount);
293
+ });
294
+ store.current.setState('filtered', { count: count, items: items, groups: groups }, false);
295
+ // eslint-disable-next-line react-hooks/exhaustive-deps
296
+ }, []);
297
+ var selectFirstItem = React.useCallback(function () {
298
+ var _a, _b;
299
+ var items = getValidItems(listInnerRef);
300
+ var item = items.find(function (el) { return el.getAttribute('aria-disabled') !== 'true'; });
301
+ if (item) {
302
+ var value = item.getAttribute(VALUE_ATTR);
303
+ if (value) {
304
+ var decoded = decodeURIComponent(value);
305
+ store.current.setState('selectedValue', decoded);
306
+ (_b = (_a = propsRef.current).onValueChange) === null || _b === void 0 ? void 0 : _b.call(_a, decoded);
307
+ }
308
+ }
309
+ // eslint-disable-next-line react-hooks/exhaustive-deps
310
+ }, []);
311
+ React.useEffect(function () {
312
+ if (searchProp !== undefined) {
313
+ store.current.setState('search', searchProp);
314
+ }
315
+ }, [searchProp, store]);
316
+ React.useEffect(function () {
317
+ if (valueProp !== undefined) {
318
+ store.current.setState('selectedValue', valueProp);
319
+ }
320
+ }, [valueProp, store]);
321
+ var context = React.useMemo(function () { return ({
322
+ value: function (id, value, keywords) {
323
+ var existing = allItems.current.get(id);
324
+ if (existing && existing.value === value && existing.keywords === keywords)
325
+ return;
326
+ allItems.current.set(id, { value: value, keywords: keywords });
327
+ filterItems();
328
+ schedule(function () {
329
+ var state = store.current.snapshot();
330
+ var validItems = getValidItems(listInnerRef);
331
+ var selectedEl = getSelectedItem(listInnerRef, state.selectedValue);
332
+ if (!selectedEl && validItems.length > 0) {
333
+ selectFirstItem();
334
+ }
335
+ store.current.emit();
336
+ });
337
+ },
338
+ item: function (id, groupId) {
339
+ if (groupId) {
340
+ if (!allGroups.current.has(groupId)) {
341
+ allGroups.current.set(groupId, new Set());
342
+ }
343
+ allGroups.current.get(groupId).add(id);
344
+ }
345
+ filterItems();
346
+ store.current.emit();
347
+ return function () {
348
+ var _a;
349
+ allItems.current.delete(id);
350
+ if (groupId) {
351
+ (_a = allGroups.current.get(groupId)) === null || _a === void 0 ? void 0 : _a.delete(id);
352
+ }
353
+ filterItems();
354
+ schedule(function () {
355
+ selectFirstItem();
356
+ store.current.emit();
357
+ });
358
+ };
359
+ },
360
+ group: function (id) {
361
+ if (!allGroups.current.has(id)) {
362
+ allGroups.current.set(id, new Set());
363
+ }
364
+ return function () {
365
+ allGroups.current.delete(id);
366
+ store.current.emit();
367
+ };
368
+ },
369
+ filter: filter,
370
+ label: label,
371
+ listId: listId,
372
+ inputId: inputId,
373
+ listInnerRef: listInnerRef,
374
+ }); },
375
+ // eslint-disable-next-line react-hooks/exhaustive-deps
376
+ [label, listId, inputId]);
377
+ var handleKeyDown = React.useCallback(function (e) {
378
+ var _a, _b, _c, _d, _e, _f;
379
+ var state = store.current.snapshot();
380
+ var updateSelectedByChange = function (change) {
381
+ var _a, _b;
382
+ var selected = getSelectedItem(listInnerRef, state.selectedValue);
383
+ var nextItem;
384
+ if (selected) {
385
+ nextItem = change === 1 ? findNextItem(selected, loop) : findPrevItem(selected, loop);
386
+ }
387
+ else {
388
+ var items = getValidItems(listInnerRef);
389
+ nextItem = change === 1 ? items[0] : items[items.length - 1];
390
+ }
391
+ if (nextItem) {
392
+ var value = nextItem.getAttribute(VALUE_ATTR);
393
+ if (value) {
394
+ var decoded = decodeURIComponent(value);
395
+ store.current.setState('selectedValue', decoded);
396
+ (_b = (_a = propsRef.current).onValueChange) === null || _b === void 0 ? void 0 : _b.call(_a, decoded);
397
+ nextItem.scrollIntoView({ block: 'nearest' });
398
+ }
399
+ }
400
+ };
401
+ switch (e.key) {
402
+ case 'ArrowDown': {
403
+ e.preventDefault();
404
+ updateSelectedByChange(1);
405
+ break;
406
+ }
407
+ case 'ArrowUp': {
408
+ e.preventDefault();
409
+ updateSelectedByChange(-1);
410
+ break;
411
+ }
412
+ case 'Home': {
413
+ e.preventDefault();
414
+ var items = getValidItems(listInnerRef);
415
+ var first = items[0];
416
+ if (first) {
417
+ var value = first.getAttribute(VALUE_ATTR);
418
+ if (value) {
419
+ var decoded = decodeURIComponent(value);
420
+ store.current.setState('selectedValue', decoded);
421
+ (_b = (_a = propsRef.current).onValueChange) === null || _b === void 0 ? void 0 : _b.call(_a, decoded);
422
+ first.scrollIntoView({ block: 'nearest' });
423
+ }
424
+ }
425
+ break;
426
+ }
427
+ case 'End': {
428
+ e.preventDefault();
429
+ var items = getValidItems(listInnerRef);
430
+ var last = items[items.length - 1];
431
+ if (last) {
432
+ var value = last.getAttribute(VALUE_ATTR);
433
+ if (value) {
434
+ var decoded = decodeURIComponent(value);
435
+ store.current.setState('selectedValue', decoded);
436
+ (_d = (_c = propsRef.current).onValueChange) === null || _d === void 0 ? void 0 : _d.call(_c, decoded);
437
+ last.scrollIntoView({ block: 'nearest' });
438
+ }
439
+ }
440
+ break;
441
+ }
442
+ case 'Enter': {
443
+ e.preventDefault();
444
+ var selected = getSelectedItem(listInnerRef, state.selectedValue);
445
+ if (selected) {
446
+ selected.click();
447
+ (_f = (_e = propsRef.current).onSelect) === null || _f === void 0 ? void 0 : _f.call(_e, state.selectedValue);
448
+ }
449
+ break;
450
+ }
451
+ case 'n':
452
+ case 'j': {
453
+ if (e.ctrlKey) {
454
+ e.preventDefault();
455
+ updateSelectedByChange(1);
456
+ }
457
+ break;
458
+ }
459
+ case 'p':
460
+ case 'k': {
461
+ if (e.ctrlKey) {
462
+ e.preventDefault();
463
+ updateSelectedByChange(-1);
464
+ }
465
+ break;
466
+ }
467
+ }
468
+ }, [loop, store, propsRef]);
469
+ var classes = (0, classes_1.useMergedClasses)(command_palette_classes_1.commandPaletteClasses, command_palette_classes_1.getCommandPaletteUtilityClass, undefined);
470
+ return (React.createElement(command_palette_context_1.CommandPaletteStoreContext.Provider, { value: store.current },
471
+ React.createElement(command_palette_context_1.CommandPaletteContext.Provider, { value: context },
472
+ React.createElement(Root, __assign({ ref: ref, className: (0, clsx_1.default)(classes.root, className), tabIndex: -1, onKeyDown: handleKeyDown, "aria-label": label }, rootProps), children))));
473
+ });
474
+ exports.CommandPalette.displayName = 'CommandPalette';
@@ -0,0 +1,27 @@
1
+ export { CommandPalette } from './command-palette';
2
+ export type { ICommandPaletteProps } from './command-palette-types';
3
+ export { CommandPaletteInput } from './command-palette-input';
4
+ export type { ICommandPaletteInputProps } from './command-palette-types';
5
+ export { CommandPaletteList } from './command-palette-list';
6
+ export type { ICommandPaletteListProps } from './command-palette-types';
7
+ export { CommandPaletteGroup } from './command-palette-group';
8
+ export type { ICommandPaletteGroupProps } from './command-palette-types';
9
+ export { CommandPaletteItem } from './command-palette-item';
10
+ export type { ICommandPaletteItemProps } from './command-palette-types';
11
+ export { CommandPaletteTab, CommandPaletteTabs } from './command-palette-tabs';
12
+ export type { ICommandPaletteTabProps, ICommandPaletteTabsProps } from './command-palette-types';
13
+ export { CommandPaletteSeparator } from './command-palette-separator';
14
+ export type { ICommandPaletteSeparatorProps } from './command-palette-types';
15
+ export { CommandPaletteEmpty } from './command-palette-empty';
16
+ export type { ICommandPaletteEmptyProps } from './command-palette-types';
17
+ export { CommandPaletteLoading } from './command-palette-loading';
18
+ export type { ICommandPaletteLoadingProps } from './command-palette-types';
19
+ export { CommandPaletteDialog } from './command-palette-dialog';
20
+ export type { ICommandPaletteDialogProps } from './command-palette-types';
21
+ export { CommandPaletteFooter, CommandPaletteShortcutKey } from './command-palette-footer';
22
+ export type { ICommandPaletteFooterProps, ICommandPaletteShortcutKeyProps } from './command-palette-types';
23
+ export { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
24
+ export type { CommandPaletteClassKey, CommandPaletteClasses } from './command-palette-classes';
25
+ export { useCommandPaletteShortcut } from './use-command-palette-shortcut';
26
+ export { CommandPaletteContext, useCommandPaletteContext, useCommandPaletteState } from './command-palette-context';
27
+ export type { CommandPaletteFilterFn, ICommandPaletteContextValue, ICommandPaletteState, } from './command-palette-types';
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCommandPaletteState = exports.useCommandPaletteContext = exports.CommandPaletteContext = exports.useCommandPaletteShortcut = exports.commandPaletteComponentName = exports.commandPaletteClasses = exports.CommandPaletteShortcutKey = exports.CommandPaletteFooter = exports.CommandPaletteDialog = exports.CommandPaletteLoading = exports.CommandPaletteEmpty = exports.CommandPaletteSeparator = exports.CommandPaletteTabs = exports.CommandPaletteTab = exports.CommandPaletteItem = exports.CommandPaletteGroup = exports.CommandPaletteList = exports.CommandPaletteInput = exports.CommandPalette = void 0;
4
+ var command_palette_1 = require("./command-palette");
5
+ Object.defineProperty(exports, "CommandPalette", { enumerable: true, get: function () { return command_palette_1.CommandPalette; } });
6
+ var command_palette_input_1 = require("./command-palette-input");
7
+ Object.defineProperty(exports, "CommandPaletteInput", { enumerable: true, get: function () { return command_palette_input_1.CommandPaletteInput; } });
8
+ var command_palette_list_1 = require("./command-palette-list");
9
+ Object.defineProperty(exports, "CommandPaletteList", { enumerable: true, get: function () { return command_palette_list_1.CommandPaletteList; } });
10
+ var command_palette_group_1 = require("./command-palette-group");
11
+ Object.defineProperty(exports, "CommandPaletteGroup", { enumerable: true, get: function () { return command_palette_group_1.CommandPaletteGroup; } });
12
+ var command_palette_item_1 = require("./command-palette-item");
13
+ Object.defineProperty(exports, "CommandPaletteItem", { enumerable: true, get: function () { return command_palette_item_1.CommandPaletteItem; } });
14
+ var command_palette_tabs_1 = require("./command-palette-tabs");
15
+ Object.defineProperty(exports, "CommandPaletteTab", { enumerable: true, get: function () { return command_palette_tabs_1.CommandPaletteTab; } });
16
+ Object.defineProperty(exports, "CommandPaletteTabs", { enumerable: true, get: function () { return command_palette_tabs_1.CommandPaletteTabs; } });
17
+ var command_palette_separator_1 = require("./command-palette-separator");
18
+ Object.defineProperty(exports, "CommandPaletteSeparator", { enumerable: true, get: function () { return command_palette_separator_1.CommandPaletteSeparator; } });
19
+ var command_palette_empty_1 = require("./command-palette-empty");
20
+ Object.defineProperty(exports, "CommandPaletteEmpty", { enumerable: true, get: function () { return command_palette_empty_1.CommandPaletteEmpty; } });
21
+ var command_palette_loading_1 = require("./command-palette-loading");
22
+ Object.defineProperty(exports, "CommandPaletteLoading", { enumerable: true, get: function () { return command_palette_loading_1.CommandPaletteLoading; } });
23
+ var command_palette_dialog_1 = require("./command-palette-dialog");
24
+ Object.defineProperty(exports, "CommandPaletteDialog", { enumerable: true, get: function () { return command_palette_dialog_1.CommandPaletteDialog; } });
25
+ var command_palette_footer_1 = require("./command-palette-footer");
26
+ Object.defineProperty(exports, "CommandPaletteFooter", { enumerable: true, get: function () { return command_palette_footer_1.CommandPaletteFooter; } });
27
+ Object.defineProperty(exports, "CommandPaletteShortcutKey", { enumerable: true, get: function () { return command_palette_footer_1.CommandPaletteShortcutKey; } });
28
+ var command_palette_classes_1 = require("./command-palette-classes");
29
+ Object.defineProperty(exports, "commandPaletteClasses", { enumerable: true, get: function () { return command_palette_classes_1.commandPaletteClasses; } });
30
+ Object.defineProperty(exports, "commandPaletteComponentName", { enumerable: true, get: function () { return command_palette_classes_1.commandPaletteComponentName; } });
31
+ var use_command_palette_shortcut_1 = require("./use-command-palette-shortcut");
32
+ Object.defineProperty(exports, "useCommandPaletteShortcut", { enumerable: true, get: function () { return use_command_palette_shortcut_1.useCommandPaletteShortcut; } });
33
+ var command_palette_context_1 = require("./command-palette-context");
34
+ Object.defineProperty(exports, "CommandPaletteContext", { enumerable: true, get: function () { return command_palette_context_1.CommandPaletteContext; } });
35
+ Object.defineProperty(exports, "useCommandPaletteContext", { enumerable: true, get: function () { return command_palette_context_1.useCommandPaletteContext; } });
36
+ Object.defineProperty(exports, "useCommandPaletteState", { enumerable: true, get: function () { return command_palette_context_1.useCommandPaletteState; } });
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ export declare function useCommandPaletteShortcut(setOpen: React.Dispatch<React.SetStateAction<boolean>>, shortcut?: {
3
+ key: string;
4
+ metaKey?: boolean;
5
+ ctrlKey?: boolean;
6
+ }): void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useCommandPaletteShortcut = useCommandPaletteShortcut;
37
+ var React = __importStar(require("react"));
38
+ function useCommandPaletteShortcut(setOpen, shortcut) {
39
+ if (shortcut === void 0) { shortcut = { key: 'k', metaKey: true }; }
40
+ var setOpenRef = React.useRef(setOpen);
41
+ setOpenRef.current = setOpen;
42
+ var shortcutRef = React.useRef(shortcut);
43
+ shortcutRef.current = shortcut;
44
+ React.useEffect(function () {
45
+ var handleKeyDown = function (e) {
46
+ var target = e.target;
47
+ if (target.tagName === 'INPUT' ||
48
+ target.tagName === 'TEXTAREA' ||
49
+ target.tagName === 'SELECT' ||
50
+ target.isContentEditable) {
51
+ return;
52
+ }
53
+ var s = shortcutRef.current;
54
+ var matchesMeta = e.metaKey === !!s.metaKey;
55
+ var matchesCtrl = e.ctrlKey === !!s.ctrlKey;
56
+ var matchesKey = e.key.toLowerCase() === s.key.toLowerCase();
57
+ if (matchesMeta && matchesCtrl && matchesKey) {
58
+ e.preventDefault();
59
+ setOpenRef.current(function (prev) { return !prev; });
60
+ }
61
+ };
62
+ document.addEventListener('keydown', handleKeyDown);
63
+ return function () { return document.removeEventListener('keydown', handleKeyDown); };
64
+ }, []);
65
+ }
@@ -0,0 +1,30 @@
1
+ import { generateUtilityClass, generateUtilityClasses } from '../styles/classes';
2
+ export var commandPaletteComponentName = 'QuantumCommandPalette';
3
+ export function getCommandPaletteUtilityClass(slot) {
4
+ return generateUtilityClass(commandPaletteComponentName, slot);
5
+ }
6
+ export var commandPaletteClasses = generateUtilityClasses(commandPaletteComponentName, [
7
+ 'root',
8
+ 'input',
9
+ 'inputWrapper',
10
+ 'inputIcon',
11
+ 'list',
12
+ 'group',
13
+ 'groupHeading',
14
+ 'groupItems',
15
+ 'item',
16
+ 'itemSelected',
17
+ 'itemIcon',
18
+ 'itemLabel',
19
+ 'itemShortcut',
20
+ 'tabs',
21
+ 'tab',
22
+ 'tabSelected',
23
+ 'separator',
24
+ 'empty',
25
+ 'loading',
26
+ 'dialog',
27
+ 'dialogPaper',
28
+ 'footer',
29
+ 'kbd',
30
+ ]);
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ export var CommandPaletteContext = React.createContext(undefined);
3
+ export var CommandPaletteStoreContext = React.createContext(undefined);
4
+ export var CommandPaletteGroupContext = React.createContext(undefined);
5
+ export function useCommandPaletteContext() {
6
+ var context = React.useContext(CommandPaletteContext);
7
+ if (!context) {
8
+ throw new Error('useCommandPaletteContext must be used within a CommandPalette');
9
+ }
10
+ return context;
11
+ }
12
+ export function useCommandPaletteStore() {
13
+ var store = React.useContext(CommandPaletteStoreContext);
14
+ if (!store) {
15
+ throw new Error('useCommandPaletteStore must be used within a CommandPalette');
16
+ }
17
+ return store;
18
+ }
19
+ export function useCommandPaletteState(selector) {
20
+ var store = useCommandPaletteStore();
21
+ return React.useSyncExternalStore(store.subscribe, function () { return selector(store.snapshot()); }, function () { return selector(store.snapshot()); });
22
+ }