@mantine/spotlight 4.0.7 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Spotlight.context.js","sources":["../src/Spotlight.context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { SpotlightAction } from './types';\n\nexport interface SpotlightContextProps {\n /** Opens spotlight */\n openSpotlight(): void;\n\n /** Closes spotlight */\n closeSpotlight(): void;\n\n /** Toggles spotlight opened state */\n toggleSpotlight(): void;\n\n /** Triggers action with given id */\n triggerAction(actionId: string): void;\n\n /** Registers additional actions */\n registerActions(action: SpotlightAction[]): void;\n\n /** Removes actions with given ids */\n removeActions(actionIds: string[]): void;\n\n /** Current opened state */\n opened: boolean;\n\n /** List of registered actions */\n actions: SpotlightAction[];\n\n /** Search query */\n query: string;\n}\n\nexport const SpotlightContext = createContext<SpotlightContextProps>(null);\n\nexport function useSpotlight() {\n const ctx = useContext(SpotlightContext);\n\n if (!ctx) {\n throw new Error('[@mantine/spotlight] SpotlightProvider was not found in tree');\n }\n\n return ctx;\n}\n"],"names":["createContext","useContext"],"mappings":";;;;;;AACY,MAAC,gBAAgB,GAAGA,mBAAa,CAAC,IAAI,EAAE;AAC7C,SAAS,YAAY,GAAG;AAC/B,EAAE,MAAM,GAAG,GAAGC,gBAAU,CAAC,gBAAgB,CAAC,CAAC;AAC3C,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AACpF,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;;"}
1
+ {"version":3,"file":"Spotlight.context.js","sources":["../src/Spotlight.context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { SpotlightAction } from './types';\n\nexport interface SpotlightContextValue {\n /** Opens spotlight */\n openSpotlight(): void;\n\n /** Closes spotlight */\n closeSpotlight(): void;\n\n /** Toggles spotlight opened state */\n toggleSpotlight(): void;\n\n /** Triggers action with given id */\n triggerAction(actionId: string): void;\n\n /** Registers additional actions */\n registerActions(actions: SpotlightAction[]): void;\n\n /** Removes actions with given ids */\n removeActions(actionIds: string[]): void;\n\n /** Current opened state */\n opened: boolean;\n\n /** List of registered actions */\n actions: SpotlightAction[];\n\n /** Search query */\n query: string;\n}\n\nexport const SpotlightContext = createContext<SpotlightContextValue>(null);\n\nexport function useSpotlight() {\n const ctx = useContext(SpotlightContext);\n\n if (!ctx) {\n throw new Error('[@mantine/spotlight] SpotlightProvider was not found in tree');\n }\n\n return ctx;\n}\n"],"names":["createContext","useContext"],"mappings":";;;;;;AACY,MAAC,gBAAgB,GAAGA,mBAAa,CAAC,IAAI,EAAE;AAC7C,SAAS,YAAY,GAAG;AAC/B,EAAE,MAAM,GAAG,GAAGC,gBAAU,CAAC,gBAAgB,CAAC,CAAC;AAC3C,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AACpF,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;;"}
@@ -7,6 +7,7 @@ var hooks = require('@mantine/hooks');
7
7
  var useActionsState = require('./use-actions-state/use-actions-state.js');
8
8
  var useSpotlightShortcuts = require('./use-spotlight-shortcuts/use-spotlight-shortcuts.js');
9
9
  var Spotlight = require('./Spotlight/Spotlight.js');
10
+ var events = require('./events.js');
10
11
  var Spotlight_context = require('./Spotlight.context.js');
11
12
 
12
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
@@ -63,7 +64,10 @@ function SpotlightProvider(_a) {
63
64
  ]);
64
65
  const timeoutRef = React.useRef(-1);
65
66
  const [query, setQuery] = React.useState("");
66
- const [actions, { registerActions, removeActions, triggerAction }] = useActionsState.useActionsState(initialActions, query);
67
+ const [actions, { registerActions, updateActions, removeActions, triggerAction }] = useActionsState.useActionsState(initialActions, query);
68
+ hooks.useDidUpdate(() => {
69
+ updateActions(initialActions);
70
+ }, [initialActions]);
67
71
  const handleQueryChange = (value) => {
68
72
  setQuery(value);
69
73
  onQueryChange == null ? void 0 : onQueryChange(value);
@@ -82,19 +86,21 @@ function SpotlightProvider(_a) {
82
86
  window.clearTimeout(timeoutRef.current);
83
87
  }
84
88
  });
89
+ const ctx = {
90
+ openSpotlight: open,
91
+ closeSpotlight: close,
92
+ toggleSpotlight: toggle,
93
+ registerActions,
94
+ removeActions,
95
+ triggerAction,
96
+ opened,
97
+ actions,
98
+ query
99
+ };
85
100
  useSpotlightShortcuts.useSpotlightShortcuts(shortcut, open);
101
+ events.useSpotlightEvents(ctx);
86
102
  return /* @__PURE__ */ React__default.createElement(Spotlight_context.SpotlightContext.Provider, {
87
- value: {
88
- openSpotlight: open,
89
- closeSpotlight: close,
90
- toggleSpotlight: toggle,
91
- registerActions,
92
- removeActions,
93
- triggerAction,
94
- opened,
95
- actions,
96
- query
97
- }
103
+ value: ctx
98
104
  }, /* @__PURE__ */ React__default.createElement(Spotlight.Spotlight, __spreadValues({
99
105
  actions,
100
106
  onClose: close,
@@ -1 +1 @@
1
- {"version":3,"file":"SpotlightProvider.js","sources":["../src/SpotlightProvider.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { useDisclosure } from '@mantine/hooks';\nimport { useActionsState } from './use-actions-state/use-actions-state';\nimport { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts';\nimport { Spotlight, InnerSpotlightProps } from './Spotlight/Spotlight';\nimport type { SpotlightAction } from './types';\nimport { SpotlightContext } from './Spotlight.context';\n\nexport interface SpotlightProviderProps extends InnerSpotlightProps {\n /** Actions list */\n actions: SpotlightAction[] | ((query: string) => SpotlightAction[]);\n\n /** Your application */\n children?: React.ReactNode;\n\n /** Called when spotlight opens */\n onSpotlightOpen?(): void;\n\n /** Called when spotlight closes */\n onSpotlightClose?(): void;\n\n /** Called when user enters text in search input */\n onQueryChange?(query: string): void;\n\n /** Keyboard shortcut or list of shortcuts to trigger spotlight */\n shortcut?: string | string[] | null;\n\n /** Should search be cleared when spotlight closes */\n cleanQueryOnClose?: boolean;\n}\n\nexport function SpotlightProvider({\n actions: initialActions,\n children,\n shortcut = 'mod + K',\n onSpotlightClose,\n onSpotlightOpen,\n onQueryChange,\n cleanQueryOnClose = true,\n transitionDuration = 150,\n ...others\n}: SpotlightProviderProps) {\n const timeoutRef = useRef<number>(-1);\n const [query, setQuery] = useState('');\n const [actions, { registerActions, removeActions, triggerAction }] = useActionsState(\n initialActions,\n query\n );\n\n const handleQueryChange = (value: string) => {\n setQuery(value);\n onQueryChange?.(value);\n };\n\n const [opened, { open, close, toggle }] = useDisclosure(false, {\n onClose: () => {\n onSpotlightClose?.();\n if (cleanQueryOnClose) {\n timeoutRef.current = window.setTimeout(() => {\n handleQueryChange('');\n }, transitionDuration);\n }\n },\n onOpen: () => {\n onSpotlightOpen?.();\n window.clearTimeout(timeoutRef.current);\n },\n });\n\n useSpotlightShortcuts(shortcut, open);\n\n return (\n <SpotlightContext.Provider\n value={{\n openSpotlight: open,\n closeSpotlight: close,\n toggleSpotlight: toggle,\n registerActions,\n removeActions,\n triggerAction,\n opened,\n actions,\n query,\n }}\n >\n <Spotlight\n actions={actions}\n onClose={close}\n opened={opened}\n query={query}\n onQueryChange={handleQueryChange}\n transitionDuration={transitionDuration}\n {...others}\n />\n {children}\n </SpotlightContext.Provider>\n );\n}\n\nSpotlightProvider.displayName = '@mantine/spotlight/SpotlightProvider';\n"],"names":["useRef","useState","useActionsState","useDisclosure","useSpotlightShortcuts","React","SpotlightContext","Spotlight"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,o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E,KAAK;AAClB,IAAI,MAAM;AACV,IAAI,KAAK;AACT,IAAI,aAAa,EAAE,iBAAiB;AACpC,IAAI,kBAAkB;AACtB,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzB,CAAC;AACD,iBAAiB,CAAC,WAAW,GAAG,sCAAsC;;;;"}
1
+ {"version":3,"file":"SpotlightProvider.js","sources":["../src/SpotlightProvider.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { useDidUpdate, useDisclosure } from '@mantine/hooks';\nimport { useActionsState } from './use-actions-state/use-actions-state';\nimport { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts';\nimport { Spotlight, InnerSpotlightProps } from './Spotlight/Spotlight';\nimport { useSpotlightEvents } from './events';\nimport type { SpotlightAction } from './types';\nimport { SpotlightContext } from './Spotlight.context';\n\nexport interface SpotlightProviderProps extends InnerSpotlightProps {\n /** Actions list */\n actions: SpotlightAction[] | ((query: string) => SpotlightAction[]);\n\n /** Your application */\n children?: React.ReactNode;\n\n /** Called when spotlight opens */\n onSpotlightOpen?(): void;\n\n /** Called when spotlight closes */\n onSpotlightClose?(): void;\n\n /** Called when user enters text in search input */\n onQueryChange?(query: string): void;\n\n /** Keyboard shortcut or list of shortcuts to trigger spotlight */\n shortcut?: string | string[] | null;\n\n /** Should search be cleared when spotlight closes */\n cleanQueryOnClose?: boolean;\n}\n\nexport function SpotlightProvider({\n actions: initialActions,\n children,\n shortcut = 'mod + K',\n onSpotlightClose,\n onSpotlightOpen,\n onQueryChange,\n cleanQueryOnClose = true,\n transitionDuration = 150,\n ...others\n}: SpotlightProviderProps) {\n const timeoutRef = useRef<number>(-1);\n const [query, setQuery] = useState('');\n const [actions, { registerActions, updateActions, removeActions, triggerAction }] =\n useActionsState(initialActions, query);\n\n useDidUpdate(() => {\n updateActions(initialActions);\n }, [initialActions]);\n\n const handleQueryChange = (value: string) => {\n setQuery(value);\n onQueryChange?.(value);\n };\n\n const [opened, { open, close, toggle }] = useDisclosure(false, {\n onClose: () => {\n onSpotlightClose?.();\n if (cleanQueryOnClose) {\n timeoutRef.current = window.setTimeout(() => {\n handleQueryChange('');\n }, transitionDuration);\n }\n },\n onOpen: () => {\n onSpotlightOpen?.();\n window.clearTimeout(timeoutRef.current);\n },\n });\n\n const ctx = {\n openSpotlight: open,\n closeSpotlight: close,\n toggleSpotlight: toggle,\n registerActions,\n removeActions,\n triggerAction,\n opened,\n actions,\n query,\n };\n\n useSpotlightShortcuts(shortcut, open);\n useSpotlightEvents(ctx);\n\n return (\n <SpotlightContext.Provider value={ctx}>\n <Spotlight\n actions={actions}\n onClose={close}\n opened={opened}\n query={query}\n onQueryChange={handleQueryChange}\n transitionDuration={transitionDuration}\n {...others}\n />\n {children}\n </SpotlightContext.Provider>\n );\n}\n\nSpotlightProvider.displayName = '@mantine/spotlight/SpotlightProvider';\n"],"names":["useRef","useState","useActionsState","useDidUpdate","useDisclosure","useSpotlightShortcuts","useSpotlightEvents","React","SpotlightContext","Spotlight"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,K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AAE,QAAQ,CAAC,CAAC;AACzB,CAAC;AACD,iBAAiB,CAAC,WAAW,GAAG,sCAAsC;;;;"}
package/cjs/events.js ADDED
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ const SPOTLIGHT_EVENTS = {
8
+ open: "mantine:open-spotlight",
9
+ close: "mantine:close-spotlight",
10
+ toggle: "mantine:toggle-spotlight",
11
+ triggerAction: "mantine:trigger-spotlight-action",
12
+ registerActions: "mantine:register-spotlight-actions",
13
+ removeActions: "mantine:remove-spotlight-actions"
14
+ };
15
+ function createEvent(type, detail) {
16
+ return new CustomEvent(type, { detail });
17
+ }
18
+ function openSpotlight() {
19
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.open));
20
+ }
21
+ function closeSpotlight() {
22
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.close));
23
+ }
24
+ function toggleSpotlight() {
25
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.toggle));
26
+ }
27
+ function triggerSpotlightAction(actionId) {
28
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionId));
29
+ }
30
+ function registerSpotlightActions(actions) {
31
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actions));
32
+ }
33
+ function removeSpotlightActions(actionsIds) {
34
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionsIds));
35
+ }
36
+ function useSpotlightEvents(ctx) {
37
+ const events = {
38
+ registerActions: (event) => ctx.registerActions(event.detail),
39
+ removeActions: (event) => ctx.registerActions(event.detail),
40
+ triggerAction: (event) => ctx.triggerAction(event.detail),
41
+ open: ctx.openSpotlight,
42
+ close: ctx.closeSpotlight,
43
+ toggle: ctx.toggleSpotlight
44
+ };
45
+ React.useEffect(() => {
46
+ Object.keys(events).forEach((event) => {
47
+ window.addEventListener(SPOTLIGHT_EVENTS[event], events[event]);
48
+ });
49
+ return () => {
50
+ Object.keys(events).forEach((event) => {
51
+ window.removeEventListener(SPOTLIGHT_EVENTS[event], events[event]);
52
+ });
53
+ };
54
+ }, []);
55
+ }
56
+
57
+ exports.SPOTLIGHT_EVENTS = SPOTLIGHT_EVENTS;
58
+ exports.closeSpotlight = closeSpotlight;
59
+ exports.openSpotlight = openSpotlight;
60
+ exports.registerSpotlightActions = registerSpotlightActions;
61
+ exports.removeSpotlightActions = removeSpotlightActions;
62
+ exports.toggleSpotlight = toggleSpotlight;
63
+ exports.triggerSpotlightAction = triggerSpotlightAction;
64
+ exports.useSpotlightEvents = useSpotlightEvents;
65
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sources":["../src/events.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport type { SpotlightContextValue } from './Spotlight.context';\nimport type { SpotlightAction } from './types';\n\ntype ValueOf<T> = T[keyof T];\n\nexport const SPOTLIGHT_EVENTS = {\n open: 'mantine:open-spotlight',\n close: 'mantine:close-spotlight',\n toggle: 'mantine:toggle-spotlight',\n triggerAction: 'mantine:trigger-spotlight-action',\n registerActions: 'mantine:register-spotlight-actions',\n removeActions: 'mantine:remove-spotlight-actions',\n} as const;\n\nfunction createEvent(type: ValueOf<typeof SPOTLIGHT_EVENTS>, detail?: any) {\n return new CustomEvent(type, { detail });\n}\n\nexport function openSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.open));\n}\n\nexport function closeSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.close));\n}\n\nexport function toggleSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.toggle));\n}\n\nexport function triggerSpotlightAction(actionId: string) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionId));\n}\n\nexport function registerSpotlightActions(actions: SpotlightAction[]) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actions));\n}\n\nexport function removeSpotlightActions(actionsIds: string[]) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionsIds));\n}\n\nexport function useSpotlightEvents(ctx: SpotlightContextValue) {\n const events = {\n registerActions: (event: any) => ctx.registerActions(event.detail),\n removeActions: (event: any) => ctx.registerActions(event.detail),\n triggerAction: (event: any) => ctx.triggerAction(event.detail),\n open: ctx.openSpotlight,\n close: ctx.closeSpotlight,\n toggle: ctx.toggleSpotlight,\n };\n\n useEffect(() => {\n Object.keys(events).forEach((event) => {\n window.addEventListener(SPOTLIGHT_EVENTS[event], events[event]);\n });\n\n return () => {\n Object.keys(events).forEach((event) => {\n window.removeEventListener(SPOTLIGHT_EVENTS[event], events[event]);\n });\n };\n }, []);\n}\n"],"names":["useEffect"],"mappings":";;;;;;AACY,MAAC,gBAAgB,GAAG;AAChC,EAAE,IAAI,EAAE,wBAAwB;AAChC,EAAE,KAAK,EAAE,yBAAyB;AAClC,EAAE,MAAM,EAAE,0BAA0B;AACpC,EAAE,aAAa,EAAE,kCAAkC;AACnD,EAAE,eAAe,EAAE,oCAAoC;AACvD,EAAE,aAAa,EAAE,kCAAkC;AACnD,EAAE;AACF,SAAS,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE;AACnC,EAAE,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3C,CAAC;AACM,SAAS,aAAa,GAAG;AAChC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AACM,SAAS,cAAc,GAAG;AACjC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,eAAe,GAAG;AAClC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D,CAA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C,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK;AAC7C,QAAQ,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3E,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;;;;;;;;"}
package/cjs/index.js CHANGED
@@ -4,9 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Spotlight_context = require('./Spotlight.context.js');
6
6
  var SpotlightProvider = require('./SpotlightProvider.js');
7
+ var events = require('./events.js');
7
8
 
8
9
 
9
10
 
10
11
  exports.useSpotlight = Spotlight_context.useSpotlight;
11
12
  exports.SpotlightProvider = SpotlightProvider.SpotlightProvider;
13
+ exports.closeSpotlight = events.closeSpotlight;
14
+ exports.openSpotlight = events.openSpotlight;
15
+ exports.registerSpotlightActions = events.registerSpotlightActions;
16
+ exports.removeSpotlightActions = events.removeSpotlightActions;
17
+ exports.toggleSpotlight = events.toggleSpotlight;
18
+ exports.triggerSpotlightAction = events.triggerSpotlightAction;
12
19
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -47,6 +47,7 @@ function useActionsState(initialActions, query) {
47
47
  setActions(prepareActions(initialActions(query)));
48
48
  }
49
49
  }, [query]);
50
+ const updateActions = (payload) => setActions(prepareActions(typeof payload === "function" ? payload(query) : payload));
50
51
  const registerActions = (payload) => setActions((current) => prepareActions([...current, ...payload]));
51
52
  const removeActions = (ids) => setActions((current) => current.filter((action) => !ids.includes(action.id)));
52
53
  const triggerAction = (id) => {
@@ -58,6 +59,7 @@ function useActionsState(initialActions, query) {
58
59
  actions,
59
60
  {
60
61
  registerActions,
62
+ updateActions,
61
63
  removeActions,
62
64
  triggerAction
63
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-actions-state.js","sources":["../../src/use-actions-state/use-actions-state.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { randomId } from '@mantine/hooks';\nimport type { SpotlightAction } from '../types';\n\nfunction prepareAction(action: SpotlightAction) {\n return { ...action, id: action.id || randomId() };\n}\n\nfunction filterDuplicateActions(actions: SpotlightAction[]) {\n const ids = [];\n\n return actions\n .reduceRight<SpotlightAction[]>((acc, action) => {\n if (!ids.includes(action.id)) {\n ids.push(action.id);\n acc.push(action);\n }\n\n return acc;\n }, [])\n .reverse();\n}\n\nfunction prepareActions(initialActions: SpotlightAction[]) {\n return filterDuplicateActions(initialActions.map((action) => prepareAction(action)));\n}\n\nexport function useActionsState(\n initialActions: SpotlightAction[] | ((query: string) => SpotlightAction[]),\n query: string\n) {\n const [actions, setActions] = useState(\n prepareActions(typeof initialActions === 'function' ? initialActions(query) : initialActions)\n );\n\n useEffect(() => {\n if (typeof initialActions === 'function') {\n setActions(prepareActions(initialActions(query)));\n }\n }, [query]);\n\n const registerActions = (payload: SpotlightAction[]) =>\n setActions((current) => prepareActions([...current, ...payload]));\n\n const removeActions = (ids: string[]) =>\n setActions((current) => current.filter((action) => !ids.includes(action.id)));\n\n const triggerAction = (id: string) => {\n const action = actions.find((item) => item.id === id);\n action?.onTrigger?.(action);\n };\n\n return [\n actions,\n {\n registerActions,\n removeActions,\n triggerAction,\n },\n ] as const;\n}\n"],"names":["randomId","useState","useEffect"],"mappings":";;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;A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AAO,CAAC,CAAC,CAAC,CAAC;AACzG,EAAE,MAAM,aAAa,GAAG,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/G,EAAE,MAAM,aAAa,GAAG,CAAC,EAAE,KAAK;AAChC,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,IAAI,CAAC,EAAE,GAAG,MAAM,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,SAAS,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjG,GAAG,CAAC;AACJ,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI;AACJ,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"use-actions-state.js","sources":["../../src/use-actions-state/use-actions-state.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { randomId } from '@mantine/hooks';\nimport type { SpotlightAction } from '../types';\n\nfunction prepareAction(action: SpotlightAction) {\n return { ...action, id: action.id || randomId() };\n}\n\nfunction filterDuplicateActions(actions: SpotlightAction[]) {\n const ids = [];\n\n return actions\n .reduceRight<SpotlightAction[]>((acc, action) => {\n if (!ids.includes(action.id)) {\n ids.push(action.id);\n acc.push(action);\n }\n\n return acc;\n }, [])\n .reverse();\n}\n\nfunction prepareActions(initialActions: SpotlightAction[]) {\n return filterDuplicateActions(initialActions.map((action) => prepareAction(action)));\n}\n\nexport function useActionsState(\n initialActions: SpotlightAction[] | ((query: string) => SpotlightAction[]),\n query: string\n) {\n const [actions, setActions] = useState(\n prepareActions(typeof initialActions === 'function' ? initialActions(query) : initialActions)\n );\n\n useEffect(() => {\n if (typeof initialActions === 'function') {\n setActions(prepareActions(initialActions(query)));\n }\n }, [query]);\n\n const updateActions = (payload: SpotlightAction[] | ((query: string) => SpotlightAction[])) =>\n setActions(prepareActions(typeof payload === 'function' ? payload(query) : payload));\n\n const registerActions = (payload: SpotlightAction[]) =>\n setActions((current) => prepareActions([...current, ...payload]));\n\n const removeActions = (ids: string[]) =>\n setActions((current) => current.filter((action) => !ids.includes(action.id)));\n\n const triggerAction = (id: string) => {\n const action = actions.find((item) => item.id === id);\n action?.onTrigger?.(action);\n };\n\n return [\n actions,\n {\n registerActions,\n updateActions,\n removeActions,\n triggerAction,\n },\n ] as const;\n}\n"],"names":["randomId","useState","useEffect"],"mappings":";;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAA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GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,IAAI,CAAC,EAAE,GAAG,MAAM,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,SAAS,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjG,GAAG,CAAC;AACJ,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI;AACJ,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Spotlight.context.js","sources":["../src/Spotlight.context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { SpotlightAction } from './types';\n\nexport interface SpotlightContextProps {\n /** Opens spotlight */\n openSpotlight(): void;\n\n /** Closes spotlight */\n closeSpotlight(): void;\n\n /** Toggles spotlight opened state */\n toggleSpotlight(): void;\n\n /** Triggers action with given id */\n triggerAction(actionId: string): void;\n\n /** Registers additional actions */\n registerActions(action: SpotlightAction[]): void;\n\n /** Removes actions with given ids */\n removeActions(actionIds: string[]): void;\n\n /** Current opened state */\n opened: boolean;\n\n /** List of registered actions */\n actions: SpotlightAction[];\n\n /** Search query */\n query: string;\n}\n\nexport const SpotlightContext = createContext<SpotlightContextProps>(null);\n\nexport function useSpotlight() {\n const ctx = useContext(SpotlightContext);\n\n if (!ctx) {\n throw new Error('[@mantine/spotlight] SpotlightProvider was not found in tree');\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;AACY,MAAC,gBAAgB,GAAG,aAAa,CAAC,IAAI,EAAE;AAC7C,SAAS,YAAY,GAAG;AAC/B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAC3C,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AACpF,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
1
+ {"version":3,"file":"Spotlight.context.js","sources":["../src/Spotlight.context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { SpotlightAction } from './types';\n\nexport interface SpotlightContextValue {\n /** Opens spotlight */\n openSpotlight(): void;\n\n /** Closes spotlight */\n closeSpotlight(): void;\n\n /** Toggles spotlight opened state */\n toggleSpotlight(): void;\n\n /** Triggers action with given id */\n triggerAction(actionId: string): void;\n\n /** Registers additional actions */\n registerActions(actions: SpotlightAction[]): void;\n\n /** Removes actions with given ids */\n removeActions(actionIds: string[]): void;\n\n /** Current opened state */\n opened: boolean;\n\n /** List of registered actions */\n actions: SpotlightAction[];\n\n /** Search query */\n query: string;\n}\n\nexport const SpotlightContext = createContext<SpotlightContextValue>(null);\n\nexport function useSpotlight() {\n const ctx = useContext(SpotlightContext);\n\n if (!ctx) {\n throw new Error('[@mantine/spotlight] SpotlightProvider was not found in tree');\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;AACY,MAAC,gBAAgB,GAAG,aAAa,CAAC,IAAI,EAAE;AAC7C,SAAS,YAAY,GAAG;AAC/B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAC3C,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;AACpF,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -1,8 +1,9 @@
1
1
  import React, { useRef, useState } from 'react';
2
- import { useDisclosure } from '@mantine/hooks';
2
+ import { useDidUpdate, useDisclosure } from '@mantine/hooks';
3
3
  import { useActionsState } from './use-actions-state/use-actions-state.js';
4
4
  import { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts.js';
5
5
  import { Spotlight } from './Spotlight/Spotlight.js';
6
+ import { useSpotlightEvents } from './events.js';
6
7
  import { SpotlightContext } from './Spotlight.context.js';
7
8
 
8
9
  var __defProp = Object.defineProperty;
@@ -55,7 +56,10 @@ function SpotlightProvider(_a) {
55
56
  ]);
56
57
  const timeoutRef = useRef(-1);
57
58
  const [query, setQuery] = useState("");
58
- const [actions, { registerActions, removeActions, triggerAction }] = useActionsState(initialActions, query);
59
+ const [actions, { registerActions, updateActions, removeActions, triggerAction }] = useActionsState(initialActions, query);
60
+ useDidUpdate(() => {
61
+ updateActions(initialActions);
62
+ }, [initialActions]);
59
63
  const handleQueryChange = (value) => {
60
64
  setQuery(value);
61
65
  onQueryChange == null ? void 0 : onQueryChange(value);
@@ -74,19 +78,21 @@ function SpotlightProvider(_a) {
74
78
  window.clearTimeout(timeoutRef.current);
75
79
  }
76
80
  });
81
+ const ctx = {
82
+ openSpotlight: open,
83
+ closeSpotlight: close,
84
+ toggleSpotlight: toggle,
85
+ registerActions,
86
+ removeActions,
87
+ triggerAction,
88
+ opened,
89
+ actions,
90
+ query
91
+ };
77
92
  useSpotlightShortcuts(shortcut, open);
93
+ useSpotlightEvents(ctx);
78
94
  return /* @__PURE__ */ React.createElement(SpotlightContext.Provider, {
79
- value: {
80
- openSpotlight: open,
81
- closeSpotlight: close,
82
- toggleSpotlight: toggle,
83
- registerActions,
84
- removeActions,
85
- triggerAction,
86
- opened,
87
- actions,
88
- query
89
- }
95
+ value: ctx
90
96
  }, /* @__PURE__ */ React.createElement(Spotlight, __spreadValues({
91
97
  actions,
92
98
  onClose: close,
@@ -1 +1 @@
1
- {"version":3,"file":"SpotlightProvider.js","sources":["../src/SpotlightProvider.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { useDisclosure } from '@mantine/hooks';\nimport { useActionsState } from './use-actions-state/use-actions-state';\nimport { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts';\nimport { Spotlight, InnerSpotlightProps } from './Spotlight/Spotlight';\nimport type { SpotlightAction } from './types';\nimport { SpotlightContext } from './Spotlight.context';\n\nexport interface SpotlightProviderProps extends InnerSpotlightProps {\n /** Actions list */\n actions: SpotlightAction[] | ((query: string) => SpotlightAction[]);\n\n /** Your application */\n children?: React.ReactNode;\n\n /** Called when spotlight opens */\n onSpotlightOpen?(): void;\n\n /** Called when spotlight closes */\n onSpotlightClose?(): void;\n\n /** Called when user enters text in search input */\n onQueryChange?(query: string): void;\n\n /** Keyboard shortcut or list of shortcuts to trigger spotlight */\n shortcut?: string | string[] | null;\n\n /** Should search be cleared when spotlight closes */\n cleanQueryOnClose?: boolean;\n}\n\nexport function SpotlightProvider({\n actions: initialActions,\n children,\n shortcut = 'mod + K',\n onSpotlightClose,\n onSpotlightOpen,\n onQueryChange,\n cleanQueryOnClose = true,\n transitionDuration = 150,\n ...others\n}: SpotlightProviderProps) {\n const timeoutRef = useRef<number>(-1);\n const [query, setQuery] = useState('');\n const [actions, { registerActions, removeActions, triggerAction }] = useActionsState(\n initialActions,\n query\n );\n\n const handleQueryChange = (value: string) => {\n setQuery(value);\n onQueryChange?.(value);\n };\n\n const [opened, { open, close, toggle }] = useDisclosure(false, {\n onClose: () => {\n onSpotlightClose?.();\n if (cleanQueryOnClose) {\n timeoutRef.current = window.setTimeout(() => {\n handleQueryChange('');\n }, transitionDuration);\n }\n },\n onOpen: () => {\n onSpotlightOpen?.();\n window.clearTimeout(timeoutRef.current);\n },\n });\n\n useSpotlightShortcuts(shortcut, open);\n\n return (\n <SpotlightContext.Provider\n value={{\n openSpotlight: open,\n closeSpotlight: close,\n toggleSpotlight: toggle,\n registerActions,\n removeActions,\n triggerAction,\n opened,\n actions,\n query,\n }}\n >\n <Spotlight\n actions={actions}\n onClose={close}\n opened={opened}\n query={query}\n onQueryChange={handleQueryChange}\n transitionDuration={transitionDuration}\n {...others}\n />\n {children}\n </SpotlightContext.Provider>\n );\n}\n\nSpotlightProvider.displayName = '@mantine/spotlight/SpotlightProvider';\n"],"names":[],"mappings":";;;;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B,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,KAAK;AACX,KAAK;AACL,GAAG,kBAAkB,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,cAAc,CAAC;AACnE,IAAI,OAAO;AACX,IAAI,OAAO,EAAE,KAAK;AAClB,IAAI,MAAM;AACV,IAAI,KAAK;AACT,IAAI,aAAa,EAAE,iBAAiB;AACpC,IAAI,kBAAkB;AACtB,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzB,CAAC;AACD,iBAAiB,CAAC,WAAW,GAAG,sCAAsC;;;;"}
1
+ {"version":3,"file":"SpotlightProvider.js","sources":["../src/SpotlightProvider.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { useDidUpdate, useDisclosure } from '@mantine/hooks';\nimport { useActionsState } from './use-actions-state/use-actions-state';\nimport { useSpotlightShortcuts } from './use-spotlight-shortcuts/use-spotlight-shortcuts';\nimport { Spotlight, InnerSpotlightProps } from './Spotlight/Spotlight';\nimport { useSpotlightEvents } from './events';\nimport type { SpotlightAction } from './types';\nimport { SpotlightContext } from './Spotlight.context';\n\nexport interface SpotlightProviderProps extends InnerSpotlightProps {\n /** Actions list */\n actions: SpotlightAction[] | ((query: string) => SpotlightAction[]);\n\n /** Your application */\n children?: React.ReactNode;\n\n /** Called when spotlight opens */\n onSpotlightOpen?(): void;\n\n /** Called when spotlight closes */\n onSpotlightClose?(): void;\n\n /** Called when user enters text in search input */\n onQueryChange?(query: string): void;\n\n /** Keyboard shortcut or list of shortcuts to trigger spotlight */\n shortcut?: string | string[] | null;\n\n /** Should search be cleared when spotlight closes */\n cleanQueryOnClose?: boolean;\n}\n\nexport function SpotlightProvider({\n actions: initialActions,\n children,\n shortcut = 'mod + K',\n onSpotlightClose,\n onSpotlightOpen,\n onQueryChange,\n cleanQueryOnClose = true,\n transitionDuration = 150,\n ...others\n}: SpotlightProviderProps) {\n const timeoutRef = useRef<number>(-1);\n const [query, setQuery] = useState('');\n const [actions, { registerActions, updateActions, removeActions, triggerAction }] =\n useActionsState(initialActions, query);\n\n useDidUpdate(() => {\n updateActions(initialActions);\n }, [initialActions]);\n\n const handleQueryChange = (value: string) => {\n setQuery(value);\n onQueryChange?.(value);\n };\n\n const [opened, { open, close, toggle }] = useDisclosure(false, {\n onClose: () => {\n onSpotlightClose?.();\n if (cleanQueryOnClose) {\n timeoutRef.current = window.setTimeout(() => {\n handleQueryChange('');\n }, transitionDuration);\n }\n },\n onOpen: () => {\n onSpotlightOpen?.();\n window.clearTimeout(timeoutRef.current);\n },\n });\n\n const ctx = {\n openSpotlight: open,\n closeSpotlight: close,\n toggleSpotlight: toggle,\n registerActions,\n removeActions,\n triggerAction,\n opened,\n actions,\n query,\n };\n\n useSpotlightShortcuts(shortcut, open);\n useSpotlightEvents(ctx);\n\n return (\n <SpotlightContext.Provider value={ctx}>\n <Spotlight\n actions={actions}\n onClose={close}\n opened={opened}\n query={query}\n onQueryChange={handleQueryChange}\n transitionDuration={transitionDuration}\n {...others}\n />\n {children}\n </SpotlightContext.Provider>\n );\n}\n\nSpotlightProvider.displayName = '@mantine/spotlight/SpotlightProvider';\n"],"names":[],"mappings":";;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAA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I,KAAK;AACT,IAAI,aAAa,EAAE,iBAAiB;AACpC,IAAI,kBAAkB;AACtB,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzB,CAAC;AACD,iBAAiB,CAAC,WAAW,GAAG,sCAAsC;;;;"}
package/esm/events.js ADDED
@@ -0,0 +1,54 @@
1
+ import { useEffect } from 'react';
2
+
3
+ const SPOTLIGHT_EVENTS = {
4
+ open: "mantine:open-spotlight",
5
+ close: "mantine:close-spotlight",
6
+ toggle: "mantine:toggle-spotlight",
7
+ triggerAction: "mantine:trigger-spotlight-action",
8
+ registerActions: "mantine:register-spotlight-actions",
9
+ removeActions: "mantine:remove-spotlight-actions"
10
+ };
11
+ function createEvent(type, detail) {
12
+ return new CustomEvent(type, { detail });
13
+ }
14
+ function openSpotlight() {
15
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.open));
16
+ }
17
+ function closeSpotlight() {
18
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.close));
19
+ }
20
+ function toggleSpotlight() {
21
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.toggle));
22
+ }
23
+ function triggerSpotlightAction(actionId) {
24
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionId));
25
+ }
26
+ function registerSpotlightActions(actions) {
27
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actions));
28
+ }
29
+ function removeSpotlightActions(actionsIds) {
30
+ window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionsIds));
31
+ }
32
+ function useSpotlightEvents(ctx) {
33
+ const events = {
34
+ registerActions: (event) => ctx.registerActions(event.detail),
35
+ removeActions: (event) => ctx.registerActions(event.detail),
36
+ triggerAction: (event) => ctx.triggerAction(event.detail),
37
+ open: ctx.openSpotlight,
38
+ close: ctx.closeSpotlight,
39
+ toggle: ctx.toggleSpotlight
40
+ };
41
+ useEffect(() => {
42
+ Object.keys(events).forEach((event) => {
43
+ window.addEventListener(SPOTLIGHT_EVENTS[event], events[event]);
44
+ });
45
+ return () => {
46
+ Object.keys(events).forEach((event) => {
47
+ window.removeEventListener(SPOTLIGHT_EVENTS[event], events[event]);
48
+ });
49
+ };
50
+ }, []);
51
+ }
52
+
53
+ export { SPOTLIGHT_EVENTS, closeSpotlight, openSpotlight, registerSpotlightActions, removeSpotlightActions, toggleSpotlight, triggerSpotlightAction, useSpotlightEvents };
54
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sources":["../src/events.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport type { SpotlightContextValue } from './Spotlight.context';\nimport type { SpotlightAction } from './types';\n\ntype ValueOf<T> = T[keyof T];\n\nexport const SPOTLIGHT_EVENTS = {\n open: 'mantine:open-spotlight',\n close: 'mantine:close-spotlight',\n toggle: 'mantine:toggle-spotlight',\n triggerAction: 'mantine:trigger-spotlight-action',\n registerActions: 'mantine:register-spotlight-actions',\n removeActions: 'mantine:remove-spotlight-actions',\n} as const;\n\nfunction createEvent(type: ValueOf<typeof SPOTLIGHT_EVENTS>, detail?: any) {\n return new CustomEvent(type, { detail });\n}\n\nexport function openSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.open));\n}\n\nexport function closeSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.close));\n}\n\nexport function toggleSpotlight() {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.toggle));\n}\n\nexport function triggerSpotlightAction(actionId: string) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionId));\n}\n\nexport function registerSpotlightActions(actions: SpotlightAction[]) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actions));\n}\n\nexport function removeSpotlightActions(actionsIds: string[]) {\n window.dispatchEvent(createEvent(SPOTLIGHT_EVENTS.triggerAction, actionsIds));\n}\n\nexport function useSpotlightEvents(ctx: SpotlightContextValue) {\n const events = {\n registerActions: (event: any) => ctx.registerActions(event.detail),\n removeActions: (event: any) => ctx.registerActions(event.detail),\n triggerAction: (event: any) => ctx.triggerAction(event.detail),\n open: ctx.openSpotlight,\n close: ctx.closeSpotlight,\n toggle: ctx.toggleSpotlight,\n };\n\n useEffect(() => {\n Object.keys(events).forEach((event) => {\n window.addEventListener(SPOTLIGHT_EVENTS[event], events[event]);\n });\n\n return () => {\n Object.keys(events).forEach((event) => {\n window.removeEventListener(SPOTLIGHT_EVENTS[event], events[event]);\n });\n };\n }, []);\n}\n"],"names":[],"mappings":";;AACY,MAAC,gBAAgB,GAAG;AAChC,EAAE,IAAI,EAAE,wBAAwB;AAChC,EAAE,KAAK,EAAE,yBAAyB;AAClC,EAAE,MAAM,EAAE,0BAA0B;AACpC,EAAE,aAAa,EAAE,kCAAkC;AACnD,EAAE,eAAe,EAAE,oCAAoC;AACvD,EAAE,aAAa,EAAE,kCAAkC;AACnD,EAAE;AACF,SAAS,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE;AACnC,EAAE,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3C,CAAC;AACM,SAAS,aAAa,GAAG;AAChC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AACM,SAAS,cAAc,GAAG;AACjC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AACM,SAAS,eAAe,GAAG;AAClC,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7D,CAAC;AACM,SAAS,sBAAsB,CAAC,QAAQ,EAAE;AACjD,EAAE,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC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,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3E,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { useSpotlight } from './Spotlight.context.js';
2
2
  export { SpotlightProvider } from './SpotlightProvider.js';
3
+ export { closeSpotlight, openSpotlight, registerSpotlightActions, removeSpotlightActions, toggleSpotlight, triggerSpotlightAction } from './events.js';
3
4
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -43,6 +43,7 @@ function useActionsState(initialActions, query) {
43
43
  setActions(prepareActions(initialActions(query)));
44
44
  }
45
45
  }, [query]);
46
+ const updateActions = (payload) => setActions(prepareActions(typeof payload === "function" ? payload(query) : payload));
46
47
  const registerActions = (payload) => setActions((current) => prepareActions([...current, ...payload]));
47
48
  const removeActions = (ids) => setActions((current) => current.filter((action) => !ids.includes(action.id)));
48
49
  const triggerAction = (id) => {
@@ -54,6 +55,7 @@ function useActionsState(initialActions, query) {
54
55
  actions,
55
56
  {
56
57
  registerActions,
58
+ updateActions,
57
59
  removeActions,
58
60
  triggerAction
59
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-actions-state.js","sources":["../../src/use-actions-state/use-actions-state.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { randomId } from '@mantine/hooks';\nimport type { SpotlightAction } from '../types';\n\nfunction prepareAction(action: SpotlightAction) {\n return { ...action, id: action.id || randomId() };\n}\n\nfunction filterDuplicateActions(actions: SpotlightAction[]) {\n const ids = [];\n\n return actions\n .reduceRight<SpotlightAction[]>((acc, action) => {\n if (!ids.includes(action.id)) {\n ids.push(action.id);\n acc.push(action);\n }\n\n return acc;\n }, [])\n .reverse();\n}\n\nfunction prepareActions(initialActions: SpotlightAction[]) {\n return filterDuplicateActions(initialActions.map((action) => prepareAction(action)));\n}\n\nexport function useActionsState(\n initialActions: SpotlightAction[] | ((query: string) => SpotlightAction[]),\n query: string\n) {\n const [actions, setActions] = useState(\n prepareActions(typeof initialActions === 'function' ? initialActions(query) : initialActions)\n );\n\n useEffect(() => {\n if (typeof initialActions === 'function') {\n setActions(prepareActions(initialActions(query)));\n }\n }, [query]);\n\n const registerActions = (payload: SpotlightAction[]) =>\n setActions((current) => prepareActions([...current, ...payload]));\n\n const removeActions = (ids: string[]) =>\n setActions((current) => current.filter((action) => !ids.includes(action.id)));\n\n const triggerAction = (id: string) => {\n const action = actions.find((item) => item.id === id);\n action?.onTrigger?.(action);\n };\n\n return [\n actions,\n {\n registerActions,\n removeActions,\n triggerAction,\n },\n ] as const;\n}\n"],"names":[],"mappings":";;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,I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AAC,GAAG,MAAM,CAAC,SAAS,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjG,GAAG,CAAC;AACJ,EAAE,OAAO;AACT,IAAI,OAAO;AACX,IAAI;AACJ,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"use-actions-state.js","sources":["../../src/use-actions-state/use-actions-state.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { randomId } from '@mantine/hooks';\nimport type { SpotlightAction } from '../types';\n\nfunction prepareAction(action: SpotlightAction) {\n return { ...action, id: action.id || randomId() };\n}\n\nfunction filterDuplicateActions(actions: SpotlightAction[]) {\n const ids = [];\n\n return actions\n .reduceRight<SpotlightAction[]>((acc, action) => {\n if (!ids.includes(action.id)) {\n ids.push(action.id);\n acc.push(action);\n }\n\n return acc;\n }, [])\n .reverse();\n}\n\nfunction prepareActions(initialActions: SpotlightAction[]) {\n return filterDuplicateActions(initialActions.map((action) => prepareAction(action)));\n}\n\nexport function useActionsState(\n initialActions: SpotlightAction[] | ((query: string) => SpotlightAction[]),\n query: string\n) {\n const [actions, setActions] = useState(\n prepareActions(typeof initialActions === 'function' ? initialActions(query) : initialActions)\n );\n\n useEffect(() => {\n if (typeof initialActions === 'function') {\n setActions(prepareActions(initialActions(query)));\n }\n }, [query]);\n\n const updateActions = (payload: SpotlightAction[] | ((query: string) => SpotlightAction[])) =>\n setActions(prepareActions(typeof payload === 'function' ? payload(query) : payload));\n\n const registerActions = (payload: SpotlightAction[]) =>\n setActions((current) => prepareActions([...current, ...payload]));\n\n const removeActions = (ids: string[]) =>\n setActions((current) => current.filter((action) => !ids.includes(action.id)));\n\n const triggerAction = (id: string) => {\n const action = actions.find((item) => item.id === id);\n action?.onTrigger?.(action);\n };\n\n return [\n actions,\n {\n registerActions,\n updateActions,\n removeActions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otlightAction } from './types';
3
- export interface SpotlightContextProps {
3
+ export interface SpotlightContextValue {
4
4
  /** Opens spotlight */
5
5
  openSpotlight(): void;
6
6
  /** Closes spotlight */
@@ -10,7 +10,7 @@ export interface SpotlightContextProps {
10
10
  /** Triggers action with given id */
11
11
  triggerAction(actionId: string): void;
12
12
  /** Registers additional actions */
13
- registerActions(action: SpotlightAction[]): void;
13
+ registerActions(actions: SpotlightAction[]): void;
14
14
  /** Removes actions with given ids */
15
15
  removeActions(actionIds: string[]): void;
16
16
  /** Current opened state */
@@ -20,6 +20,6 @@ export interface SpotlightContextProps {
20
20
  /** Search query */
21
21
  query: string;
22
22
  }
23
- export declare const SpotlightContext: import("react").Context<SpotlightContextProps>;
24
- export declare function useSpotlight(): SpotlightContextProps;
23
+ export declare const SpotlightContext: import("react").Context<SpotlightContextValue>;
24
+ export declare function useSpotlight(): SpotlightContextValue;
25
25
  //# sourceMappingURL=Spotlight.context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Spotlight.context.d.ts","sourceRoot":"","sources":["../src/Spotlight.context.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,sBAAsB;IACtB,aAAa,IAAI,IAAI,CAAC;IAEtB,uBAAuB;IACvB,cAAc,IAAI,IAAI,CAAC;IAEvB,qCAAqC;IACrC,eAAe,IAAI,IAAI,CAAC;IAExB,oCAAoC;IACpC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,mCAAmC;IACnC,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IAEjD,qCAAqC;IACrC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEzC,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAC;IAEhB,iCAAiC;IACjC,OAAO,EAAE,eAAe,EAAE,CAAC;IAE3B,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,gBAAgB,gDAA6C,CAAC;AAE3E,wBAAgB,YAAY,0BAQ3B"}
1
+ {"version":3,"file":"Spotlight.context.d.ts","sourceRoot":"","sources":["../src/Spotlight.context.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,sBAAsB;IACtB,aAAa,IAAI,IAAI,CAAC;IAEtB,uBAAuB;IACvB,cAAc,IAAI,IAAI,CAAC;IAEvB,qCAAqC;IACrC,eAAe,IAAI,IAAI,CAAC;IAExB,oCAAoC;IACpC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC,mCAAmC;IACnC,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IAElD,qCAAqC;IACrC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEzC,2BAA2B;IAC3B,MAAM,EAAE,OAAO,CAAC;IAEhB,iCAAiC;IACjC,OAAO,EAAE,eAAe,EAAE,CAAC;IAE3B,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,gBAAgB,gDAA6C,CAAC;AAE3E,wBAAgB,YAAY,0BAQ3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"SpotlightProvider.d.ts","sourceRoot":"","sources":["../src/SpotlightProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAIhD,OAAO,EAAa,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,mBAAmB;IACnB,OAAO,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,eAAe,EAA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AAI,CAAC;IAEpC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IAEpC,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EAAE,cAAc,EACvB,QAAQ,EACR,QAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,iBAAwB,EACxB,kBAAwB,EACxB,GAAG,MAAM,EACV,EAAE,sBAAsB,eA2DxB;yBArEe,iBAAiB"}
@@ -0,0 +1,18 @@
1
+ import type { SpotlightContextValue } from './Spotlight.context';
2
+ import type { SpotlightAction } from './types';
3
+ export declare const SPOTLIGHT_EVENTS: {
4
+ readonly open: "mantine:open-spotlight";
5
+ readonly close: "mantine:close-spotlight";
6
+ readonly toggle: "mantine:toggle-spotlight";
7
+ readonly triggerAction: "mantine:trigger-spotlight-action";
8
+ readonly registerActions: "mantine:register-spotlight-actions";
9
+ readonly removeActions: "mantine:remove-spotlight-actions";
10
+ };
11
+ export declare function openSpotlight(): void;
12
+ export declare function closeSpotlight(): void;
13
+ export declare function toggleSpotlight(): void;
14
+ export declare function triggerSpotlightAction(actionId: string): void;
15
+ export declare function registerSpotlightActions(actions: SpotlightAction[]): void;
16
+ export declare function removeSpotlightActions(actionsIds: string[]): void;
17
+ export declare function useSpotlightEvents(ctx: SpotlightContextValue): void;
18
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI/C,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAMX,wBAAgB,aAAa,SAE5B;AAED,wBAAgB,cAAc,SAE7B;AAED,wBAAgB,eAAe,SAE9B;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,QAEtD;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe,EAAE,QAElE;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAE1D;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,qBAAqB,QAqB5D"}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { useSpotlight } from './Spotlight.context';
2
2
  export { SpotlightProvider } from './SpotlightProvider';
3
+ export { openSpotlight, closeSpotlight, toggleSpotlight, triggerSpotlightAction, registerSpotlightActions, removeSpotlightActions, } from './events';
3
4
  export type { SpotlightAction } from './types';
4
5
  export type { SpotlightProviderProps } from './SpotlightProvider';
5
6
  export type { DefaultActionProps as SpotlightActionProps } from './DefaultAction/DefaultAction';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EAAE,kBAAkB,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAChG,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,aAAa,EACb,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EAAE,kBAAkB,IAAI,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAChG,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { SpotlightAction } from '../types';
2
2
  export declare function useActionsState(initialActions: SpotlightAction[] | ((query: string) => SpotlightAction[]), query: string): readonly [SpotlightAction[], {
3
3
  readonly registerActions: (payload: SpotlightAction[]) => void;
4
+ readonly updateActions: (payload: SpotlightAction[] | ((query: string) => SpotlightAction[])) => void;
4
5
  readonly removeActions: (ids: string[]) => void;
5
6
  readonly triggerAction: (id: string) => void;
6
7
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"use-actions-state.d.ts","sourceRoot":"","sources":["../../src/use-actions-state/use-actions-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAyBhD,wBAAgB,eAAe,CAC7B,cAAc,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC,EAC1E,KAAK,EAAE,MAAM;wCAYqB,eAAe,EAAE;kCAGvB,MAAM,EAAE;iCAGT,MAAM;GAalC"}
1
+ {"version":3,"file":"use-actions-state.d.ts","sourceRoot":"","sources":["../../src/use-actions-state/use-actions-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAyBhD,wBAAgB,eAAe,CAC7B,cAAc,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC,EAC1E,KAAK,EAAE,MAAM;wCAeqB,eAAe,EAAE;mEAHU,MAAM,KAAK,eAAe,EAAE;kCAM7D,MAAM,EAAE;iCAGT,MAAM;GAclC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mantine/spotlight",
3
3
  "description": "Command center for your application",
4
- "version": "4.0.7",
4
+ "version": "4.1.0",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "directory": "src/mantine-spotlight"
16
16
  },
17
17
  "peerDependencies": {
18
- "@mantine/core": "4.0.7",
19
- "@mantine/hooks": "4.0.7",
18
+ "@mantine/core": "4.1.0",
19
+ "@mantine/hooks": "4.1.0",
20
20
  "react": ">=16.8.0",
21
21
  "react-dom": ">=16.8.0"
22
22
  },