@mantine-vue/spotlight 1.1.2

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/cjs/index.cjs ADDED
@@ -0,0 +1,1007 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _mantine_vue_store = require("@mantine-vue/store");
3
+ let vue = require("vue");
4
+ let _mantine_vue_core = require("@mantine-vue/core");
5
+ let _mantine_vue_hooks = require("@mantine-vue/hooks");
6
+ //#region src/spotlight.store.ts
7
+ function clamp(value, min, max) {
8
+ return Math.min(max, Math.max(min, value));
9
+ }
10
+ var createSpotlightStore = () => (0, _mantine_vue_store.createStore)({
11
+ opened: false,
12
+ empty: false,
13
+ selected: -1,
14
+ listId: "",
15
+ query: "",
16
+ registeredActions: /* @__PURE__ */ new Set()
17
+ });
18
+ var useSpotlight = (store) => store.value;
19
+ function updateSpotlightStateAction(update, store) {
20
+ const state = store.getState();
21
+ store.setState({
22
+ ...state,
23
+ ...update(store.getState())
24
+ });
25
+ }
26
+ function openSpotlightAction(store) {
27
+ updateSpotlightStateAction(() => ({
28
+ opened: true,
29
+ selected: -1
30
+ }), store);
31
+ }
32
+ function closeSpotlightAction(store) {
33
+ updateSpotlightStateAction(() => ({ opened: false }), store);
34
+ }
35
+ function toggleSpotlightAction(store) {
36
+ updateSpotlightStateAction((state) => ({
37
+ opened: !state.opened,
38
+ selected: state.opened ? state.selected : -1
39
+ }), store);
40
+ }
41
+ function setSelectedAction(index, store) {
42
+ store.setState((state) => ({
43
+ ...state,
44
+ selected: index
45
+ }));
46
+ }
47
+ function setListId(id, store) {
48
+ store.setState((state) => ({
49
+ ...state,
50
+ listId: id
51
+ }));
52
+ }
53
+ function findElementByQuerySelector(selector, root = document) {
54
+ const element = root.querySelector(selector);
55
+ if (element) return element;
56
+ const children = root instanceof ShadowRoot ? root.host.children : root.children;
57
+ for (let i = 0; i < children.length; i += 1) {
58
+ const child = children[i];
59
+ if (child.shadowRoot) {
60
+ const shadowElement = findElementByQuerySelector(selector, child.shadowRoot);
61
+ if (shadowElement) return shadowElement;
62
+ }
63
+ const nestedElement = findElementByQuerySelector(selector, child);
64
+ if (nestedElement) return nestedElement;
65
+ }
66
+ return null;
67
+ }
68
+ function selectAction(index, store) {
69
+ const state = store.getState();
70
+ const actionsList = state.listId ? findElementByQuerySelector(`#${state.listId}`) : null;
71
+ const selected = actionsList?.querySelector("[data-selected]");
72
+ const actions = actionsList?.querySelectorAll("[data-action]") ?? [];
73
+ const selectedIndex = clamp(index === -1 ? actions.length - 1 : index === actions.length ? 0 : index, 0, actions.length - 1);
74
+ selected?.removeAttribute("data-selected");
75
+ actions[selectedIndex]?.scrollIntoView?.({ block: "nearest" });
76
+ actions[selectedIndex]?.setAttribute("data-selected", "true");
77
+ setSelectedAction(selectedIndex, store);
78
+ return selectedIndex;
79
+ }
80
+ function selectNextAction(store) {
81
+ return selectAction(store.getState().selected + 1, store);
82
+ }
83
+ function selectPreviousAction(store) {
84
+ return selectAction(store.getState().selected - 1, store);
85
+ }
86
+ function triggerSelectedAction(store) {
87
+ const state = store.getState();
88
+ (state.listId ? findElementByQuerySelector(`#${state.listId} [data-selected]`) : null)?.click();
89
+ }
90
+ function registerAction(id, store) {
91
+ const state = store.getState();
92
+ state.registeredActions.add(id);
93
+ return () => {
94
+ state.registeredActions.delete(id);
95
+ };
96
+ }
97
+ function setQuery(query, store) {
98
+ updateSpotlightStateAction(() => ({ query }), store);
99
+ Promise.resolve().then(() => {
100
+ selectAction(0, store);
101
+ updateSpotlightStateAction((state) => ({ empty: state.query.trim().length > 0 && state.registeredActions.size === 0 || false }), store);
102
+ });
103
+ }
104
+ function clearSpotlightState({ clearQuery }, store) {
105
+ store.setState((state) => ({
106
+ ...state,
107
+ selected: -1,
108
+ query: clearQuery ? "" : state.query,
109
+ empty: clearQuery ? false : state.empty
110
+ }));
111
+ }
112
+ var spotlightActions = {
113
+ open: openSpotlightAction,
114
+ close: closeSpotlightAction,
115
+ toggle: toggleSpotlightAction,
116
+ updateState: updateSpotlightStateAction,
117
+ setSelectedAction,
118
+ setListId,
119
+ selectAction,
120
+ selectNextAction,
121
+ selectPreviousAction,
122
+ triggerSelectedAction,
123
+ registerAction,
124
+ setQuery,
125
+ clearSpotlightState
126
+ };
127
+ function createSpotlight() {
128
+ const store = createSpotlightStore();
129
+ return [store, {
130
+ open: () => openSpotlightAction(store),
131
+ close: () => closeSpotlightAction(store),
132
+ toggle: () => toggleSpotlightAction(store)
133
+ }];
134
+ }
135
+ var [spotlightStore, spotlight] = createSpotlight();
136
+ var { open: openSpotlight, close: closeSpotlight, toggle: toggleSpotlight } = spotlight;
137
+ //#endregion
138
+ //#region src/is-actions-group.ts
139
+ function isActionsGroup(item) {
140
+ const group = item;
141
+ return group.group !== void 0 && Array.isArray(group.actions);
142
+ }
143
+ //#endregion
144
+ //#region src/default-spotlight-filter.ts
145
+ function getKeywords(keywords) {
146
+ if (Array.isArray(keywords)) return keywords.map((keyword) => keyword.trim()).join(",").toLowerCase().trim();
147
+ if (typeof keywords === "string") return keywords.toLowerCase().trim();
148
+ return "";
149
+ }
150
+ function getFlatActions(data) {
151
+ return data.reduce((acc, item) => {
152
+ if ("actions" in item) return [...acc, ...item.actions.map((action) => ({
153
+ ...action,
154
+ group: item.group
155
+ }))];
156
+ return [...acc, item];
157
+ }, []);
158
+ }
159
+ function flatActionsToGroups(data) {
160
+ const groups = {};
161
+ const result = [];
162
+ data.forEach((action) => {
163
+ if (action.group) {
164
+ if (!groups[action.group]) groups[action.group] = {
165
+ pushed: false,
166
+ data: {
167
+ group: action.group,
168
+ actions: []
169
+ }
170
+ };
171
+ groups[action.group].data.actions.push(action);
172
+ if (!groups[action.group].pushed) {
173
+ groups[action.group].pushed = true;
174
+ result.push(groups[action.group].data);
175
+ }
176
+ } else result.push(action);
177
+ });
178
+ return result;
179
+ }
180
+ var defaultSpotlightFilter = (_query, data) => {
181
+ const query = _query.trim().toLowerCase();
182
+ const priorityMatrix = [[], []];
183
+ getFlatActions(data).forEach((item) => {
184
+ if (item.label?.toLowerCase().includes(query)) priorityMatrix[0].push(item);
185
+ else if (item.description?.toLowerCase().includes(query) || getKeywords(item.keywords).includes(query)) priorityMatrix[1].push(item);
186
+ });
187
+ return flatActionsToGroups(priorityMatrix.flat());
188
+ };
189
+ //#endregion
190
+ //#region src/limit-actions.ts
191
+ function limitActions(actions, limit) {
192
+ if (!Array.isArray(actions)) return [];
193
+ let count = 0;
194
+ return actions.reduce((acc, item) => {
195
+ if (count >= limit) return acc;
196
+ if (isActionsGroup(item)) {
197
+ const groupActions = limitActions(item.actions, limit - count);
198
+ acc.push({
199
+ group: item.group,
200
+ actions: groupActions
201
+ });
202
+ count += groupActions.length;
203
+ } else {
204
+ acc.push(item);
205
+ count += 1;
206
+ }
207
+ return acc;
208
+ }, []);
209
+ }
210
+ //#endregion
211
+ //#region src/Spotlight.context.ts
212
+ var SpotlightContextKey = Symbol("SpotlightContext");
213
+ function provideSpotlightContext(value) {
214
+ (0, vue.provide)(SpotlightContextKey, value);
215
+ }
216
+ function useSpotlightContext() {
217
+ const ctx = (0, vue.inject)(SpotlightContextKey, null);
218
+ if (ctx === null) throw new Error("Spotlight component was not found in tree");
219
+ return ctx;
220
+ }
221
+ //#endregion
222
+ //#region src/style-api.ts
223
+ function mergeClassNames(...items) {
224
+ return items.reduce((acc, item) => {
225
+ if (!item || typeof item !== "object" || Array.isArray(item)) return acc;
226
+ Object.entries(item).forEach(([key, value]) => {
227
+ acc[key] = acc[key] ? [acc[key], value] : value;
228
+ });
229
+ return acc;
230
+ }, {});
231
+ }
232
+ function mergeStyles(...items) {
233
+ return items.reduce((acc, item) => {
234
+ if (!item || typeof item !== "object" || Array.isArray(item)) return acc;
235
+ Object.entries(item).forEach(([key, value]) => {
236
+ acc[key] = acc[key] ? [acc[key], value] : value;
237
+ });
238
+ return acc;
239
+ }, {});
240
+ }
241
+ function renderContent$1(value) {
242
+ return typeof value === "function" ? value() : value;
243
+ }
244
+ var Spotlight_module_default = {
245
+ root: "_root_87n7g_1",
246
+ content: "_content_87n7g_7",
247
+ body: "_body_87n7g_13",
248
+ search: "_search_87n7g_19",
249
+ actionsList: "_actionsList_87n7g_24",
250
+ action: "_action_87n7g_24",
251
+ actionBody: "_actionBody_87n7g_73",
252
+ actionSection: "_actionSection_87n7g_77",
253
+ actionLabel: "_actionLabel_87n7g_99",
254
+ actionDescription: "_actionDescription_87n7g_103",
255
+ empty: "_empty_87n7g_110",
256
+ footer: "_footer_87n7g_116",
257
+ actionsGroup: "_actionsGroup_87n7g_129"
258
+ };
259
+ //#endregion
260
+ //#region src/SpotlightAction.ts
261
+ var defaultProps$3 = {
262
+ dimmedSections: true,
263
+ highlightQuery: false
264
+ };
265
+ var SpotlightAction = (0, vue.defineComponent)({
266
+ name: "SpotlightAction",
267
+ inheritAttrs: false,
268
+ props: {
269
+ label: {
270
+ type: String,
271
+ default: void 0
272
+ },
273
+ description: {
274
+ type: String,
275
+ default: void 0
276
+ },
277
+ leftSection: {
278
+ type: [
279
+ String,
280
+ Number,
281
+ Object,
282
+ Function
283
+ ],
284
+ default: void 0
285
+ },
286
+ rightSection: {
287
+ type: [
288
+ String,
289
+ Number,
290
+ Object,
291
+ Function
292
+ ],
293
+ default: void 0
294
+ },
295
+ dimmedSections: {
296
+ type: Boolean,
297
+ default: void 0
298
+ },
299
+ highlightQuery: {
300
+ type: Boolean,
301
+ default: void 0
302
+ },
303
+ highlightColor: {
304
+ type: String,
305
+ default: void 0
306
+ },
307
+ closeSpotlightOnTrigger: {
308
+ type: Boolean,
309
+ default: void 0
310
+ },
311
+ keywords: {
312
+ type: [String, Array],
313
+ default: void 0
314
+ },
315
+ classNames: {
316
+ type: [Object, Function],
317
+ default: void 0
318
+ },
319
+ styles: {
320
+ type: [Object, Function],
321
+ default: void 0
322
+ },
323
+ vars: {
324
+ type: [Object, Function],
325
+ default: void 0
326
+ }
327
+ },
328
+ setup(rawProps, { attrs, slots }) {
329
+ const props = (0, _mantine_vue_core.useProps)("SpotlightAction", defaultProps$3, rawProps);
330
+ const ctx = useSpotlightContext();
331
+ return () => {
332
+ const stylesApi = {
333
+ classNames: props.classNames,
334
+ styles: props.styles
335
+ };
336
+ const labelNode = props.highlightQuery && typeof props.label === "string" ? (0, vue.h)(_mantine_vue_core.Highlight, {
337
+ component: "span",
338
+ highlight: ctx.query,
339
+ color: props.highlightColor,
340
+ ...ctx.getStyles("actionLabel", stylesApi)
341
+ }, () => props.label) : (0, vue.h)("span", ctx.getStyles("actionLabel", stylesApi), props.label);
342
+ return (0, vue.h)(_mantine_vue_core.UnstyledButton, {
343
+ ...attrs,
344
+ "data-action": true,
345
+ ...ctx.getStyles("action", {
346
+ className: attrs.class,
347
+ style: attrs.style,
348
+ ...stylesApi
349
+ }),
350
+ onMousedown: (event) => {
351
+ event.preventDefault();
352
+ attrs.onMousedown?.(event);
353
+ },
354
+ onClick: (event) => {
355
+ attrs.onClick?.(event);
356
+ if (props.closeSpotlightOnTrigger ?? ctx.closeOnActionTrigger) spotlightActions.close(ctx.store);
357
+ },
358
+ tabindex: -1
359
+ }, () => slots.default?.() ?? [
360
+ props.leftSection ? (0, vue.h)(_mantine_vue_core.Box, {
361
+ component: "span",
362
+ mod: {
363
+ position: "left",
364
+ dimmed: props.dimmedSections
365
+ },
366
+ ...ctx.getStyles("actionSection", stylesApi)
367
+ }, () => renderContent$1(props.leftSection)) : null,
368
+ (0, vue.h)("span", ctx.getStyles("actionBody", stylesApi), [labelNode, (0, vue.h)("span", ctx.getStyles("actionDescription", stylesApi), props.description)]),
369
+ props.rightSection ? (0, vue.h)(_mantine_vue_core.Box, {
370
+ component: "span",
371
+ mod: {
372
+ position: "right",
373
+ dimmed: props.dimmedSections
374
+ },
375
+ ...ctx.getStyles("actionSection", stylesApi)
376
+ }, () => renderContent$1(props.rightSection)) : null
377
+ ]);
378
+ };
379
+ }
380
+ });
381
+ Object.assign(SpotlightAction, { classes: Spotlight_module_default });
382
+ //#endregion
383
+ //#region src/SpotlightActionsGroup.ts
384
+ var SpotlightActionsGroup = (0, vue.defineComponent)({
385
+ name: "SpotlightActionsGroup",
386
+ inheritAttrs: false,
387
+ props: {
388
+ label: {
389
+ type: String,
390
+ default: void 0
391
+ },
392
+ classNames: {
393
+ type: [Object, Function],
394
+ default: void 0
395
+ },
396
+ styles: {
397
+ type: [Object, Function],
398
+ default: void 0
399
+ },
400
+ vars: {
401
+ type: [Object, Function],
402
+ default: void 0
403
+ }
404
+ },
405
+ setup(rawProps, { attrs, slots }) {
406
+ const props = (0, _mantine_vue_core.useProps)("SpotlightActionsGroup", null, rawProps);
407
+ const ctx = useSpotlightContext();
408
+ return () => (0, vue.h)(_mantine_vue_core.Box, {
409
+ ...attrs,
410
+ ...ctx.getStyles("actionsGroup", {
411
+ className: attrs.class,
412
+ style: attrs.style,
413
+ classNames: props.classNames,
414
+ styles: props.styles
415
+ }),
416
+ style: [
417
+ ctx.getStyles("actionsGroup", { styles: props.styles }).style,
418
+ attrs.style,
419
+ { "--spotlight-label": `'${props.label?.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'` }
420
+ ]
421
+ }, () => slots.default?.());
422
+ }
423
+ });
424
+ Object.assign(SpotlightActionsGroup, { classes: Spotlight_module_default });
425
+ //#endregion
426
+ //#region src/SpotlightActionsList.ts
427
+ var SpotlightActionsList = (0, vue.defineComponent)({
428
+ name: "SpotlightActionsList",
429
+ inheritAttrs: false,
430
+ props: {
431
+ id: {
432
+ type: String,
433
+ default: void 0
434
+ },
435
+ classNames: {
436
+ type: [Object, Function],
437
+ default: void 0
438
+ },
439
+ styles: {
440
+ type: [Object, Function],
441
+ default: void 0
442
+ },
443
+ vars: {
444
+ type: [Object, Function],
445
+ default: void 0
446
+ }
447
+ },
448
+ setup(rawProps, { attrs, slots }) {
449
+ const props = (0, _mantine_vue_core.useProps)("SpotlightActionsList", null, rawProps);
450
+ const ctx = useSpotlightContext();
451
+ const generatedId = (0, _mantine_vue_hooks.useId)();
452
+ const listId = props.id || `mantine-${generatedId.value.replace(/:/g, "")}`;
453
+ (0, vue.onMounted)(() => spotlightActions.setListId(listId, ctx.store));
454
+ (0, vue.onBeforeUnmount)(() => spotlightActions.setListId("", ctx.store));
455
+ return () => (0, vue.h)(_mantine_vue_core.ScrollAreaAutosize, {
456
+ ...attrs,
457
+ ...ctx.getStyles("actionsList", {
458
+ className: attrs.class,
459
+ style: attrs.style,
460
+ classNames: props.classNames,
461
+ styles: props.styles
462
+ }),
463
+ type: "scroll",
464
+ scrollbarSize: "var(--spotlight-actions-list-padding)",
465
+ offsetScrollbars: "y",
466
+ id: listId
467
+ }, () => slots.default?.());
468
+ }
469
+ });
470
+ Object.assign(SpotlightActionsList, { classes: Spotlight_module_default });
471
+ //#endregion
472
+ //#region src/SpotlightEmpty.ts
473
+ var SpotlightEmpty = (0, vue.defineComponent)({
474
+ name: "SpotlightEmpty",
475
+ inheritAttrs: false,
476
+ props: {
477
+ classNames: {
478
+ type: [Object, Function],
479
+ default: void 0
480
+ },
481
+ styles: {
482
+ type: [Object, Function],
483
+ default: void 0
484
+ },
485
+ vars: {
486
+ type: [Object, Function],
487
+ default: void 0
488
+ }
489
+ },
490
+ setup(rawProps, { attrs, slots }) {
491
+ const props = (0, _mantine_vue_core.useProps)("SpotlightEmpty", null, rawProps);
492
+ const ctx = useSpotlightContext();
493
+ return () => (0, vue.h)(_mantine_vue_core.Box, {
494
+ ...attrs,
495
+ ...ctx.getStyles("empty", {
496
+ className: attrs.class,
497
+ style: attrs.style,
498
+ classNames: props.classNames,
499
+ styles: props.styles
500
+ })
501
+ }, () => slots.default?.());
502
+ }
503
+ });
504
+ Object.assign(SpotlightEmpty, { classes: Spotlight_module_default });
505
+ //#endregion
506
+ //#region src/SpotlightFooter.ts
507
+ var SpotlightFooter = (0, vue.defineComponent)({
508
+ name: "SpotlightFooter",
509
+ inheritAttrs: false,
510
+ props: {
511
+ classNames: {
512
+ type: [Object, Function],
513
+ default: void 0
514
+ },
515
+ styles: {
516
+ type: [Object, Function],
517
+ default: void 0
518
+ },
519
+ vars: {
520
+ type: [Object, Function],
521
+ default: void 0
522
+ }
523
+ },
524
+ setup(rawProps, { attrs, slots }) {
525
+ const props = (0, _mantine_vue_core.useProps)("SpotlightFooter", null, rawProps);
526
+ const ctx = useSpotlightContext();
527
+ return () => (0, vue.h)(_mantine_vue_core.Box, {
528
+ ...attrs,
529
+ ...ctx.getStyles("footer", {
530
+ className: attrs.class,
531
+ style: attrs.style,
532
+ classNames: props.classNames,
533
+ styles: props.styles
534
+ })
535
+ }, () => slots.default?.());
536
+ }
537
+ });
538
+ Object.assign(SpotlightFooter, { classes: Spotlight_module_default });
539
+ //#endregion
540
+ //#region src/get-hotkeys.ts
541
+ function getHotkeys(hotkeys, store) {
542
+ if (!hotkeys) return [];
543
+ const open = () => spotlightActions.open(store);
544
+ if (Array.isArray(hotkeys)) return hotkeys.map((hotkey) => [hotkey, open]);
545
+ return [[hotkeys, open]];
546
+ }
547
+ //#endregion
548
+ //#region src/SpotlightRoot.ts
549
+ var defaultProps$2 = {
550
+ size: 600,
551
+ yOffset: 80,
552
+ zIndex: (0, _mantine_vue_core.getDefaultZIndex)("max"),
553
+ overlayProps: {
554
+ backgroundOpacity: .35,
555
+ blur: 7
556
+ },
557
+ transitionProps: {
558
+ duration: 200,
559
+ transition: "pop"
560
+ },
561
+ store: spotlightStore,
562
+ clearQueryOnClose: true,
563
+ closeOnActionTrigger: true,
564
+ shortcut: "mod + K",
565
+ maxHeight: 400
566
+ };
567
+ var SpotlightRoot = (0, vue.defineComponent)({
568
+ name: "SpotlightRoot",
569
+ inheritAttrs: false,
570
+ props: {
571
+ store: {
572
+ type: Object,
573
+ default: void 0
574
+ },
575
+ query: {
576
+ type: String,
577
+ default: void 0
578
+ },
579
+ onQueryChange: {
580
+ type: Function,
581
+ default: void 0
582
+ },
583
+ clearQueryOnClose: {
584
+ type: Boolean,
585
+ default: void 0
586
+ },
587
+ shortcut: {
588
+ type: [
589
+ String,
590
+ Array,
591
+ null
592
+ ],
593
+ default: void 0
594
+ },
595
+ tagsToIgnore: {
596
+ type: Array,
597
+ default: void 0
598
+ },
599
+ triggerOnContentEditable: {
600
+ type: Boolean,
601
+ default: void 0
602
+ },
603
+ disabled: {
604
+ type: Boolean,
605
+ default: false
606
+ },
607
+ onSpotlightOpen: {
608
+ type: Function,
609
+ default: void 0
610
+ },
611
+ onSpotlightClose: {
612
+ type: Function,
613
+ default: void 0
614
+ },
615
+ forceOpened: {
616
+ type: Boolean,
617
+ default: false
618
+ },
619
+ closeOnActionTrigger: {
620
+ type: Boolean,
621
+ default: void 0
622
+ },
623
+ maxHeight: {
624
+ type: [String, Number],
625
+ default: void 0
626
+ },
627
+ scrollable: {
628
+ type: Boolean,
629
+ default: false
630
+ },
631
+ classNames: {
632
+ type: [Object, Function],
633
+ default: void 0
634
+ },
635
+ styles: {
636
+ type: [Object, Function],
637
+ default: void 0
638
+ },
639
+ vars: {
640
+ type: [Object, Function],
641
+ default: void 0
642
+ },
643
+ unstyled: {
644
+ type: Boolean,
645
+ default: false
646
+ }
647
+ },
648
+ setup(rawProps, { attrs, slots }) {
649
+ const props = (0, _mantine_vue_core.useProps)("SpotlightRoot", defaultProps$2, rawProps);
650
+ const state = useSpotlight(props.store);
651
+ const previousOpened = (0, vue.ref)(state.value.opened);
652
+ const currentQuery = (0, vue.computed)(() => typeof props.query === "string" ? props.query : state.value.query);
653
+ const setQuery = (query) => {
654
+ props.onQueryChange?.(query);
655
+ spotlightActions.setQuery(query, props.store);
656
+ };
657
+ const getStyles = (0, _mantine_vue_core.useStyles)({
658
+ name: "Spotlight",
659
+ classes: Spotlight_module_default,
660
+ props,
661
+ className: attrs.class,
662
+ style: attrs.style,
663
+ classNames: props.classNames,
664
+ styles: props.styles,
665
+ unstyled: props.unstyled,
666
+ vars: props.vars
667
+ });
668
+ provideSpotlightContext({
669
+ get query() {
670
+ return currentQuery.value;
671
+ },
672
+ setQuery,
673
+ getStyles,
674
+ store: props.store,
675
+ get closeOnActionTrigger() {
676
+ return props.closeOnActionTrigger;
677
+ }
678
+ });
679
+ (0, _mantine_vue_hooks.useHotkeys)(() => getHotkeys(props.shortcut, props.store), () => props.tagsToIgnore, () => props.triggerOnContentEditable);
680
+ (0, vue.watch)(() => state.value.opened, (opened) => {
681
+ if (opened === previousOpened.value) return;
682
+ if (opened) props.onSpotlightOpen?.();
683
+ else props.onSpotlightClose?.();
684
+ previousOpened.value = opened;
685
+ });
686
+ return () => {
687
+ if (props.disabled) return null;
688
+ const rootStyles = getStyles("root", {
689
+ className: attrs.class,
690
+ style: attrs.style
691
+ });
692
+ const { classNames: _classNames, styles: _styles, vars: _vars, unstyled: _unstyled, store: _store, query: _query, onQueryChange: _onQueryChange, clearQueryOnClose: _clearQueryOnClose, shortcut: _shortcut, tagsToIgnore: _tagsToIgnore, triggerOnContentEditable: _triggerOnContentEditable, disabled: _disabled, onSpotlightOpen: _onSpotlightOpen, onSpotlightClose: _onSpotlightClose, forceOpened: _forceOpened, closeOnActionTrigger: _closeOnActionTrigger, maxHeight: _maxHeight, scrollable: _scrollable, ...modalAttrs } = {
693
+ ...attrs,
694
+ ...props
695
+ };
696
+ return (0, vue.h)(_mantine_vue_core.Modal, {
697
+ ...modalAttrs,
698
+ withCloseButton: false,
699
+ opened: state.value.opened || !!props.forceOpened,
700
+ padding: 0,
701
+ onClose: () => spotlightActions.close(props.store),
702
+ class: rootStyles.class,
703
+ style: rootStyles.style,
704
+ classNames: mergeClassNames({
705
+ body: Spotlight_module_default.body,
706
+ content: Spotlight_module_default.content
707
+ }, props.classNames),
708
+ styles: mergeStyles(props.styles),
709
+ vars: mergeStyles({ root: { "--spotlight-max-height": props.scrollable ? (0, _mantine_vue_core.rem)(props.maxHeight) : void 0 } }, props.vars),
710
+ onExitTransitionEnd: () => {
711
+ if (props.clearQueryOnClose) setQuery("");
712
+ spotlightActions.clearSpotlightState({ clearQuery: props.clearQueryOnClose }, props.store);
713
+ props.transitionProps?.onExited?.();
714
+ props.onExitTransitionEnd?.();
715
+ },
716
+ "data-scrollable": props.scrollable || void 0
717
+ }, slots);
718
+ };
719
+ }
720
+ });
721
+ Object.assign(SpotlightRoot, { classes: Spotlight_module_default });
722
+ //#endregion
723
+ //#region src/SpotlightSearch.ts
724
+ var defaultProps$1 = { size: "lg" };
725
+ var SpotlightSearch = (0, vue.defineComponent)({
726
+ name: "SpotlightSearch",
727
+ inheritAttrs: false,
728
+ props: {
729
+ size: {
730
+ type: [String, Number],
731
+ default: void 0
732
+ },
733
+ value: {
734
+ type: String,
735
+ default: void 0
736
+ },
737
+ onChange: {
738
+ type: Function,
739
+ default: void 0
740
+ },
741
+ onKeydown: {
742
+ type: Function,
743
+ default: void 0
744
+ },
745
+ classNames: {
746
+ type: [Object, Function],
747
+ default: void 0
748
+ },
749
+ styles: {
750
+ type: [Object, Function],
751
+ default: void 0
752
+ },
753
+ vars: {
754
+ type: [Object, Function],
755
+ default: void 0
756
+ }
757
+ },
758
+ setup(rawProps, { attrs }) {
759
+ const props = (0, _mantine_vue_core.useProps)("SpotlightSearch", defaultProps$1, rawProps);
760
+ const ctx = useSpotlightContext();
761
+ const isComposing = (0, vue.ref)(false);
762
+ const handleKeydown = (event) => {
763
+ props.onKeydown?.(event);
764
+ if (isComposing.value) return;
765
+ if (event.code === "ArrowDown") {
766
+ event.preventDefault();
767
+ spotlightActions.selectNextAction(ctx.store);
768
+ }
769
+ if (event.code === "ArrowUp") {
770
+ event.preventDefault();
771
+ spotlightActions.selectPreviousAction(ctx.store);
772
+ }
773
+ if (event.code === "Enter" || event.code === "NumpadEnter") {
774
+ event.preventDefault();
775
+ spotlightActions.triggerSelectedAction(ctx.store);
776
+ }
777
+ };
778
+ return () => {
779
+ const inputStyles = ctx.getStyles("search");
780
+ return (0, vue.h)(_mantine_vue_core.Input, {
781
+ ...attrs,
782
+ size: props.size,
783
+ value: props.value ?? ctx.query,
784
+ classNames: mergeClassNames({ input: inputStyles.class }, props.classNames),
785
+ styles: mergeStyles({ input: inputStyles.style }, props.styles),
786
+ vars: props.vars,
787
+ onInput: (event) => {
788
+ ctx.setQuery(event.currentTarget.value);
789
+ props.onChange?.(event);
790
+ },
791
+ onKeydown: handleKeydown,
792
+ onCompositionstart: () => {
793
+ isComposing.value = true;
794
+ },
795
+ onCompositionend: () => {
796
+ isComposing.value = false;
797
+ }
798
+ });
799
+ };
800
+ }
801
+ });
802
+ Object.assign(SpotlightSearch, { classes: Spotlight_module_default });
803
+ //#endregion
804
+ //#region src/Spotlight.ts
805
+ var defaultProps = {
806
+ size: 600,
807
+ yOffset: 80,
808
+ limit: Infinity,
809
+ zIndex: (0, _mantine_vue_core.getDefaultZIndex)("max"),
810
+ overlayProps: {
811
+ backgroundOpacity: .35,
812
+ blur: 7
813
+ },
814
+ transitionProps: {
815
+ duration: 200,
816
+ transition: "pop"
817
+ },
818
+ store: spotlightStore,
819
+ filter: defaultSpotlightFilter,
820
+ clearQueryOnClose: true,
821
+ closeOnActionTrigger: true,
822
+ shortcut: "mod + K"
823
+ };
824
+ function renderContent(value) {
825
+ return typeof value === "function" ? value() : value;
826
+ }
827
+ var SpotlightBase = (0, vue.defineComponent)({
828
+ name: "Spotlight",
829
+ inheritAttrs: false,
830
+ props: {
831
+ searchProps: {
832
+ type: Object,
833
+ default: void 0
834
+ },
835
+ actions: {
836
+ type: Array,
837
+ required: true
838
+ },
839
+ filter: {
840
+ type: Function,
841
+ default: void 0
842
+ },
843
+ nothingFound: {
844
+ type: [
845
+ String,
846
+ Number,
847
+ Object,
848
+ Function
849
+ ],
850
+ default: void 0
851
+ },
852
+ highlightQuery: {
853
+ type: Boolean,
854
+ default: false
855
+ },
856
+ limit: {
857
+ type: Number,
858
+ default: void 0
859
+ },
860
+ scrollAreaProps: {
861
+ type: Object,
862
+ default: void 0
863
+ },
864
+ query: {
865
+ type: String,
866
+ default: void 0
867
+ },
868
+ onQueryChange: {
869
+ type: Function,
870
+ default: void 0
871
+ },
872
+ store: {
873
+ type: Object,
874
+ default: void 0
875
+ },
876
+ clearQueryOnClose: {
877
+ type: Boolean,
878
+ default: void 0
879
+ },
880
+ shortcut: {
881
+ type: [String, Array],
882
+ default: void 0
883
+ },
884
+ tagsToIgnore: {
885
+ type: Array,
886
+ default: void 0
887
+ },
888
+ triggerOnContentEditable: {
889
+ type: Boolean,
890
+ default: void 0
891
+ },
892
+ disabled: {
893
+ type: Boolean,
894
+ default: false
895
+ },
896
+ onSpotlightOpen: {
897
+ type: Function,
898
+ default: void 0
899
+ },
900
+ onSpotlightClose: {
901
+ type: Function,
902
+ default: void 0
903
+ },
904
+ forceOpened: {
905
+ type: Boolean,
906
+ default: false
907
+ },
908
+ closeOnActionTrigger: {
909
+ type: Boolean,
910
+ default: void 0
911
+ },
912
+ maxHeight: {
913
+ type: [String, Number],
914
+ default: void 0
915
+ },
916
+ scrollable: {
917
+ type: Boolean,
918
+ default: false
919
+ },
920
+ classNames: {
921
+ type: [Object, Function],
922
+ default: void 0
923
+ },
924
+ styles: {
925
+ type: [Object, Function],
926
+ default: void 0
927
+ },
928
+ vars: {
929
+ type: [Object, Function],
930
+ default: void 0
931
+ },
932
+ unstyled: {
933
+ type: Boolean,
934
+ default: false
935
+ }
936
+ },
937
+ setup(rawProps, { attrs }) {
938
+ const props = (0, _mantine_vue_core.useProps)("Spotlight", defaultProps, rawProps);
939
+ const uncontrolledQuery = (0, vue.ref)("");
940
+ const currentQuery = (0, vue.computed)(() => typeof props.query === "string" ? props.query : uncontrolledQuery.value);
941
+ const setQuery = (query) => {
942
+ if (typeof props.query !== "string") uncontrolledQuery.value = query;
943
+ props.onQueryChange?.(query);
944
+ };
945
+ return () => {
946
+ const renderedActions = limitActions(props.filter(currentQuery.value, props.actions), props.limit).map((item) => {
947
+ if (isActionsGroup(item)) return (0, vue.h)(SpotlightActionsGroup, {
948
+ key: item.group,
949
+ label: item.group
950
+ }, () => item.actions.map(({ id, ...actionData }) => (0, vue.h)(SpotlightAction, {
951
+ key: id,
952
+ highlightQuery: props.highlightQuery,
953
+ ...actionData
954
+ })));
955
+ const { id, ...actionData } = item;
956
+ return (0, vue.h)(SpotlightAction, {
957
+ key: id,
958
+ highlightQuery: props.highlightQuery,
959
+ ...actionData
960
+ });
961
+ });
962
+ const { searchProps: _searchProps, actions: _actions, filter: _filter, nothingFound: _nothingFound, highlightQuery: _highlightQuery, limit: _limit, scrollAreaProps: _scrollAreaProps, query: _query, onQueryChange: _onQueryChange, ...rootProps } = props;
963
+ return (0, vue.h)(SpotlightRoot, {
964
+ ...attrs,
965
+ ...rootProps,
966
+ query: currentQuery.value,
967
+ onQueryChange: setQuery
968
+ }, () => [
969
+ (0, vue.h)(SpotlightSearch, props.searchProps),
970
+ renderedActions.length > 0 ? (0, vue.h)(SpotlightActionsList, props.scrollAreaProps, () => renderedActions) : null,
971
+ renderedActions.length === 0 && props.nothingFound ? (0, vue.h)(SpotlightEmpty, null, () => renderContent(props.nothingFound)) : null
972
+ ]);
973
+ };
974
+ }
975
+ });
976
+ var Spotlight = Object.assign(SpotlightBase, {
977
+ classes: Spotlight_module_default,
978
+ Search: SpotlightSearch,
979
+ ActionsList: SpotlightActionsList,
980
+ Action: SpotlightAction,
981
+ Empty: SpotlightEmpty,
982
+ Footer: SpotlightFooter,
983
+ ActionsGroup: SpotlightActionsGroup,
984
+ Root: SpotlightRoot,
985
+ open: spotlight.open,
986
+ close: spotlight.close,
987
+ toggle: spotlight.toggle
988
+ });
989
+ //#endregion
990
+ exports.Spotlight = Spotlight;
991
+ exports.SpotlightAction = SpotlightAction;
992
+ exports.SpotlightActionsGroup = SpotlightActionsGroup;
993
+ exports.SpotlightActionsList = SpotlightActionsList;
994
+ exports.SpotlightEmpty = SpotlightEmpty;
995
+ exports.SpotlightFooter = SpotlightFooter;
996
+ exports.SpotlightRoot = SpotlightRoot;
997
+ exports.SpotlightSearch = SpotlightSearch;
998
+ exports.closeSpotlight = closeSpotlight;
999
+ exports.createSpotlight = createSpotlight;
1000
+ exports.createSpotlightStore = createSpotlightStore;
1001
+ exports.isActionsGroup = isActionsGroup;
1002
+ exports.openSpotlight = openSpotlight;
1003
+ exports.spotlight = spotlight;
1004
+ exports.toggleSpotlight = toggleSpotlight;
1005
+ exports.useSpotlight = useSpotlight;
1006
+
1007
+ //# sourceMappingURL=index.cjs.map