@mantine/spotlight 9.0.0-alpha.5 → 9.0.0-alpha.7
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/Spotlight.cjs +85 -75
- package/cjs/Spotlight.cjs.map +1 -1
- package/cjs/Spotlight.context.cjs +6 -10
- package/cjs/Spotlight.context.cjs.map +1 -1
- package/cjs/Spotlight.module.cjs +21 -0
- package/cjs/Spotlight.module.cjs.map +1 -0
- package/cjs/SpotlightAction.cjs +75 -92
- package/cjs/SpotlightAction.cjs.map +1 -1
- package/cjs/SpotlightActionsGroup.cjs +23 -29
- package/cjs/SpotlightActionsGroup.cjs.map +1 -1
- package/cjs/SpotlightActionsList.cjs +35 -38
- package/cjs/SpotlightActionsList.cjs.map +1 -1
- package/cjs/SpotlightEmpty.cjs +21 -19
- package/cjs/SpotlightEmpty.cjs.map +1 -1
- package/cjs/SpotlightFooter.cjs +21 -19
- package/cjs/SpotlightFooter.cjs.map +1 -1
- package/cjs/SpotlightRoot.cjs +92 -120
- package/cjs/SpotlightRoot.cjs.map +1 -1
- package/cjs/SpotlightSearch.cjs +48 -60
- package/cjs/SpotlightSearch.cjs.map +1 -1
- package/cjs/default-spotlight-filter.cjs +41 -46
- package/cjs/default-spotlight-filter.cjs.map +1 -1
- package/cjs/get-hotkeys.cjs +10 -15
- package/cjs/get-hotkeys.cjs.map +1 -1
- package/cjs/index.cjs +27 -32
- package/cjs/is-actions-group.cjs +7 -7
- package/cjs/is-actions-group.cjs.map +1 -1
- package/cjs/limit-actions.cjs +23 -28
- package/cjs/limit-actions.cjs.map +1 -1
- package/cjs/spotlight.store.cjs +98 -117
- package/cjs/spotlight.store.cjs.map +1 -1
- package/esm/Spotlight.context.mjs +7 -8
- package/esm/Spotlight.context.mjs.map +1 -1
- package/esm/Spotlight.mjs +74 -62
- package/esm/Spotlight.mjs.map +1 -1
- package/esm/Spotlight.module.mjs +21 -0
- package/esm/Spotlight.module.mjs.map +1 -0
- package/esm/SpotlightAction.mjs +74 -89
- package/esm/SpotlightAction.mjs.map +1 -1
- package/esm/SpotlightActionsGroup.mjs +22 -26
- package/esm/SpotlightActionsGroup.mjs.map +1 -1
- package/esm/SpotlightActionsList.mjs +34 -35
- package/esm/SpotlightActionsList.mjs.map +1 -1
- package/esm/SpotlightEmpty.mjs +20 -16
- package/esm/SpotlightEmpty.mjs.map +1 -1
- package/esm/SpotlightFooter.mjs +20 -16
- package/esm/SpotlightFooter.mjs.map +1 -1
- package/esm/SpotlightRoot.mjs +91 -117
- package/esm/SpotlightRoot.mjs.map +1 -1
- package/esm/SpotlightSearch.mjs +47 -57
- package/esm/SpotlightSearch.mjs.map +1 -1
- package/esm/default-spotlight-filter.mjs +41 -44
- package/esm/default-spotlight-filter.mjs.map +1 -1
- package/esm/get-hotkeys.mjs +10 -13
- package/esm/get-hotkeys.mjs.map +1 -1
- package/esm/index.mjs +11 -11
- package/esm/is-actions-group.mjs +7 -5
- package/esm/is-actions-group.mjs.map +1 -1
- package/esm/limit-actions.mjs +23 -26
- package/esm/limit-actions.mjs.map +1 -1
- package/esm/spotlight.store.mjs +96 -100
- package/esm/spotlight.store.mjs.map +1 -1
- package/package.json +4 -4
- package/cjs/Spotlight.module.css.cjs +0 -7
- package/cjs/Spotlight.module.css.cjs.map +0 -1
- package/cjs/index.cjs.map +0 -1
- package/esm/Spotlight.module.css.mjs +0 -5
- package/esm/Spotlight.module.css.mjs.map +0 -1
- package/esm/index.mjs.map +0 -1
package/cjs/SpotlightSearch.cjs
CHANGED
|
@@ -1,63 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
classNames: [{ input: inputStyles.className }, classNames],
|
|
46
|
-
styles: [{ input: inputStyles.style }, styles],
|
|
47
|
-
...others,
|
|
48
|
-
value: value ?? ctx.query,
|
|
49
|
-
onChange: (event) => {
|
|
50
|
-
ctx.setQuery(event.currentTarget.value);
|
|
51
|
-
onChange?.(event);
|
|
52
|
-
},
|
|
53
|
-
onKeyDown: handleKeyDown,
|
|
54
|
-
onCompositionStart: () => setIsComposing(true),
|
|
55
|
-
onCompositionEnd: () => setIsComposing(false)
|
|
56
|
-
}
|
|
57
|
-
);
|
|
1
|
+
"use client";
|
|
2
|
+
const require_spotlight_store = require("./spotlight.store.cjs");
|
|
3
|
+
const require_Spotlight_context = require("./Spotlight.context.cjs");
|
|
4
|
+
const require_Spotlight_module = require("./Spotlight.module.cjs");
|
|
5
|
+
let _mantine_core = require("@mantine/core");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
//#region packages/@mantine/spotlight/src/SpotlightSearch.tsx
|
|
9
|
+
const defaultProps = { size: "lg" };
|
|
10
|
+
const SpotlightSearch = (0, _mantine_core.factory)((props) => {
|
|
11
|
+
const { classNames, styles, onKeyDown, onChange, vars, value, attributes, ...others } = (0, _mantine_core.useProps)("SpotlightSearch", defaultProps, props);
|
|
12
|
+
const ctx = require_Spotlight_context.useSpotlightContext();
|
|
13
|
+
const inputStyles = ctx.getStyles("search");
|
|
14
|
+
const [isComposing, setIsComposing] = (0, react.useState)(false);
|
|
15
|
+
const handleKeyDown = (event) => {
|
|
16
|
+
onKeyDown?.(event);
|
|
17
|
+
if (isComposing) return;
|
|
18
|
+
if (event.nativeEvent.code === "ArrowDown") {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
require_spotlight_store.spotlightActions.selectNextAction(ctx.store);
|
|
21
|
+
}
|
|
22
|
+
if (event.nativeEvent.code === "ArrowUp") {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
require_spotlight_store.spotlightActions.selectPreviousAction(ctx.store);
|
|
25
|
+
}
|
|
26
|
+
if (event.nativeEvent.code === "Enter" || event.nativeEvent.code === "NumpadEnter") {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
require_spotlight_store.spotlightActions.triggerSelectedAction(ctx.store);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Input, {
|
|
32
|
+
...inputStyles,
|
|
33
|
+
classNames: [{ input: inputStyles.className }, classNames],
|
|
34
|
+
styles: [{ input: inputStyles.style }, styles],
|
|
35
|
+
...others,
|
|
36
|
+
value: value ?? ctx.query,
|
|
37
|
+
onChange: (event) => {
|
|
38
|
+
ctx.setQuery(event.currentTarget.value);
|
|
39
|
+
onChange?.(event);
|
|
40
|
+
},
|
|
41
|
+
onKeyDown: handleKeyDown,
|
|
42
|
+
onCompositionStart: () => setIsComposing(true),
|
|
43
|
+
onCompositionEnd: () => setIsComposing(false)
|
|
44
|
+
});
|
|
58
45
|
});
|
|
59
|
-
SpotlightSearch.classes =
|
|
46
|
+
SpotlightSearch.classes = require_Spotlight_module.default;
|
|
60
47
|
SpotlightSearch.displayName = "@mantine/spotlight/SpotlightSearch";
|
|
61
|
-
|
|
48
|
+
//#endregion
|
|
62
49
|
exports.SpotlightSearch = SpotlightSearch;
|
|
63
|
-
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=SpotlightSearch.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpotlightSearch.cjs","sources":["../src/SpotlightSearch.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n BoxProps,\n CompoundStylesApiProps,\n ElementProps,\n factory,\n Factory,\n Input,\n InputProps,\n InputStylesNames,\n useProps,\n} from '@mantine/core';\nimport { useSpotlightContext } from './Spotlight.context';\nimport { spotlightActions } from './spotlight.store';\nimport classes from './Spotlight.module.css';\n\nexport type SpotlightSearchStylesNames = InputStylesNames;\n\nexport interface SpotlightSearchProps\n extends\n BoxProps,\n Omit<InputProps, 'classNames' | 'styles' | 'vars' | 'variant'>,\n CompoundStylesApiProps<SpotlightSearchFactory>,\n ElementProps<'input', 'size'> {}\n\nexport type SpotlightSearchFactory = Factory<{\n props: SpotlightSearchProps;\n ref: HTMLInputElement;\n stylesNames: SpotlightSearchStylesNames;\n compound: true;\n}>;\n\nconst defaultProps = {\n size: 'lg',\n} satisfies Partial<SpotlightSearchProps>;\n\nexport const SpotlightSearch = factory<SpotlightSearchFactory>((props) => {\n const { classNames, styles, onKeyDown, onChange, vars, value, attributes, ...others } = useProps(\n 'SpotlightSearch',\n defaultProps,\n props\n );\n const ctx = useSpotlightContext();\n const inputStyles = ctx.getStyles('search');\n const [isComposing, setIsComposing] = useState(false); // IME\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (isComposing) {\n return;\n }\n\n if (event.nativeEvent.code === 'ArrowDown') {\n event.preventDefault();\n spotlightActions.selectNextAction(ctx.store);\n }\n\n if (event.nativeEvent.code === 'ArrowUp') {\n event.preventDefault();\n spotlightActions.selectPreviousAction(ctx.store);\n }\n\n if (event.nativeEvent.code === 'Enter' || event.nativeEvent.code === 'NumpadEnter') {\n event.preventDefault();\n spotlightActions.triggerSelectedAction(ctx.store);\n }\n };\n\n return (\n <Input\n {...inputStyles}\n classNames={[{ input: inputStyles.className }, classNames] as any}\n styles={[{ input: inputStyles.style }, styles] as any}\n {...others}\n value={value ?? ctx.query}\n onChange={(event) => {\n ctx.setQuery(event.currentTarget.value);\n onChange?.(event);\n }}\n onKeyDown={handleKeyDown}\n onCompositionStart={() => setIsComposing(true)}\n onCompositionEnd={() => setIsComposing(false)}\n />\n );\n});\n\nSpotlightSearch.classes = classes;\nSpotlightSearch.displayName = '@mantine/spotlight/SpotlightSearch';\n"],"
|
|
1
|
+
{"version":3,"file":"SpotlightSearch.cjs","names":["useSpotlightContext","Input","classes"],"sources":["../src/SpotlightSearch.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n BoxProps,\n CompoundStylesApiProps,\n ElementProps,\n factory,\n Factory,\n Input,\n InputProps,\n InputStylesNames,\n useProps,\n} from '@mantine/core';\nimport { useSpotlightContext } from './Spotlight.context';\nimport { spotlightActions } from './spotlight.store';\nimport classes from './Spotlight.module.css';\n\nexport type SpotlightSearchStylesNames = InputStylesNames;\n\nexport interface SpotlightSearchProps\n extends\n BoxProps,\n Omit<InputProps, 'classNames' | 'styles' | 'vars' | 'variant'>,\n CompoundStylesApiProps<SpotlightSearchFactory>,\n ElementProps<'input', 'size'> {}\n\nexport type SpotlightSearchFactory = Factory<{\n props: SpotlightSearchProps;\n ref: HTMLInputElement;\n stylesNames: SpotlightSearchStylesNames;\n compound: true;\n}>;\n\nconst defaultProps = {\n size: 'lg',\n} satisfies Partial<SpotlightSearchProps>;\n\nexport const SpotlightSearch = factory<SpotlightSearchFactory>((props) => {\n const { classNames, styles, onKeyDown, onChange, vars, value, attributes, ...others } = useProps(\n 'SpotlightSearch',\n defaultProps,\n props\n );\n const ctx = useSpotlightContext();\n const inputStyles = ctx.getStyles('search');\n const [isComposing, setIsComposing] = useState(false); // IME\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (isComposing) {\n return;\n }\n\n if (event.nativeEvent.code === 'ArrowDown') {\n event.preventDefault();\n spotlightActions.selectNextAction(ctx.store);\n }\n\n if (event.nativeEvent.code === 'ArrowUp') {\n event.preventDefault();\n spotlightActions.selectPreviousAction(ctx.store);\n }\n\n if (event.nativeEvent.code === 'Enter' || event.nativeEvent.code === 'NumpadEnter') {\n event.preventDefault();\n spotlightActions.triggerSelectedAction(ctx.store);\n }\n };\n\n return (\n <Input\n {...inputStyles}\n classNames={[{ input: inputStyles.className }, classNames] as any}\n styles={[{ input: inputStyles.style }, styles] as any}\n {...others}\n value={value ?? ctx.query}\n onChange={(event) => {\n ctx.setQuery(event.currentTarget.value);\n onChange?.(event);\n }}\n onKeyDown={handleKeyDown}\n onCompositionStart={() => setIsComposing(true)}\n onCompositionEnd={() => setIsComposing(false)}\n />\n );\n});\n\nSpotlightSearch.classes = classes;\nSpotlightSearch.displayName = '@mantine/spotlight/SpotlightSearch';\n"],"mappings":";;;;;;;;AAgCA,MAAM,eAAe,EACnB,MAAM,MACP;AAED,MAAa,mBAAA,GAAA,cAAA,UAAmD,UAAU;CACxE,MAAM,EAAE,YAAY,QAAQ,WAAW,UAAU,MAAM,OAAO,YAAY,GAAG,YAAA,GAAA,cAAA,UAC3E,mBACA,cACA,MACD;CACD,MAAM,MAAMA,0BAAAA,qBAAqB;CACjC,MAAM,cAAc,IAAI,UAAU,SAAS;CAC3C,MAAM,CAAC,aAAa,mBAAA,GAAA,MAAA,UAA2B,MAAM;CAErD,MAAM,iBAAiB,UAAiD;AACtE,cAAY,MAAM;AAClB,MAAI,YACF;AAGF,MAAI,MAAM,YAAY,SAAS,aAAa;AAC1C,SAAM,gBAAgB;AACtB,2BAAA,iBAAiB,iBAAiB,IAAI,MAAM;;AAG9C,MAAI,MAAM,YAAY,SAAS,WAAW;AACxC,SAAM,gBAAgB;AACtB,2BAAA,iBAAiB,qBAAqB,IAAI,MAAM;;AAGlD,MAAI,MAAM,YAAY,SAAS,WAAW,MAAM,YAAY,SAAS,eAAe;AAClF,SAAM,gBAAgB;AACtB,2BAAA,iBAAiB,sBAAsB,IAAI,MAAM;;;AAIrD,QACE,iBAAA,GAAA,kBAAA,KAACC,cAAAA,OAAD;EACE,GAAI;EACJ,YAAY,CAAC,EAAE,OAAO,YAAY,WAAW,EAAE,WAAW;EAC1D,QAAQ,CAAC,EAAE,OAAO,YAAY,OAAO,EAAE,OAAO;EAC9C,GAAI;EACJ,OAAO,SAAS,IAAI;EACpB,WAAW,UAAU;AACnB,OAAI,SAAS,MAAM,cAAc,MAAM;AACvC,cAAW,MAAM;;EAEnB,WAAW;EACX,0BAA0B,eAAe,KAAK;EAC9C,wBAAwB,eAAe,MAAM;EAC7C,CAAA;EAEJ;AAEF,gBAAgB,UAAUC,yBAAAA;AAC1B,gBAAgB,cAAc"}
|
|
@@ -1,55 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
//#region packages/@mantine/spotlight/src/default-spotlight-filter.ts
|
|
4
3
|
function getKeywords(keywords) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (typeof keywords === "string") {
|
|
9
|
-
return keywords.toLowerCase().trim();
|
|
10
|
-
}
|
|
11
|
-
return "";
|
|
4
|
+
if (Array.isArray(keywords)) return keywords.map((keyword) => keyword.trim()).join(",").toLowerCase().trim();
|
|
5
|
+
if (typeof keywords === "string") return keywords.toLowerCase().trim();
|
|
6
|
+
return "";
|
|
12
7
|
}
|
|
13
8
|
function getFlatActions(data) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
return data.reduce((acc, item) => {
|
|
10
|
+
if ("actions" in item) return [...acc, ...item.actions.map((action) => ({
|
|
11
|
+
...action,
|
|
12
|
+
group: item.group
|
|
13
|
+
}))];
|
|
14
|
+
return [...acc, item];
|
|
15
|
+
}, []);
|
|
20
16
|
}
|
|
21
17
|
function flatActionsToGroups(data) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
const groups = {};
|
|
19
|
+
const result = [];
|
|
20
|
+
data.forEach((action) => {
|
|
21
|
+
if (action.group) {
|
|
22
|
+
if (!groups[action.group]) groups[action.group] = {
|
|
23
|
+
pushed: false,
|
|
24
|
+
data: {
|
|
25
|
+
group: action.group,
|
|
26
|
+
actions: []
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
groups[action.group].data.actions.push(action);
|
|
30
|
+
if (!groups[action.group].pushed) {
|
|
31
|
+
groups[action.group].pushed = true;
|
|
32
|
+
result.push(groups[action.group].data);
|
|
33
|
+
}
|
|
34
|
+
} else result.push(action);
|
|
35
|
+
});
|
|
36
|
+
return result;
|
|
39
37
|
}
|
|
40
38
|
const defaultSpotlightFilter = (_query, data) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
priorityMatrix[1].push(item);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return flatActionsToGroups(priorityMatrix.flat());
|
|
39
|
+
const query = _query.trim().toLowerCase();
|
|
40
|
+
const priorityMatrix = [[], []];
|
|
41
|
+
getFlatActions(data).forEach((item) => {
|
|
42
|
+
if (item.label?.toLowerCase().includes(query)) priorityMatrix[0].push(item);
|
|
43
|
+
else if (item.description?.toLowerCase().includes(query) || getKeywords(item.keywords).includes(query)) priorityMatrix[1].push(item);
|
|
44
|
+
});
|
|
45
|
+
return flatActionsToGroups(priorityMatrix.flat());
|
|
52
46
|
};
|
|
53
|
-
|
|
47
|
+
//#endregion
|
|
54
48
|
exports.defaultSpotlightFilter = defaultSpotlightFilter;
|
|
55
|
-
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=default-spotlight-filter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-spotlight-filter.cjs","sources":["../src/default-spotlight-filter.ts"],"sourcesContent":["import type {\n SpotlightActionData,\n SpotlightActionGroupData,\n SpotlightActions,\n SpotlightFilterFunction,\n} from './Spotlight';\n\nfunction getKeywords(keywords: string | string[] | undefined) {\n if (Array.isArray(keywords)) {\n return keywords\n .map((keyword) => keyword.trim())\n .join(',')\n .toLowerCase()\n .trim();\n }\n\n if (typeof keywords === 'string') {\n return keywords.toLowerCase().trim();\n }\n\n return '';\n}\n\nfunction getFlatActions(data: SpotlightActions[]) {\n return data.reduce<SpotlightActionData[]>((acc, item) => {\n if ('actions' in item) {\n return [...acc, ...item.actions.map((action) => ({ ...action, group: item.group }))];\n }\n\n return [...acc, item];\n }, []);\n}\n\nfunction flatActionsToGroups(data: SpotlightActionData[]) {\n const groups: Record<string, { pushed: boolean; data: SpotlightActionGroupData }> = {};\n const result: SpotlightActions[] = [];\n\n data.forEach((action) => {\n if (action.group) {\n if (!groups[action.group]) {\n groups[action.group] = { pushed: false, data: { group: action.group, actions: [] } };\n }\n\n groups[action.group].data.actions.push(action);\n\n if (!groups[action.group].pushed) {\n groups[action.group].pushed = true;\n result.push(groups[action.group].data);\n }\n } else {\n result.push(action);\n }\n });\n\n return result;\n}\n\nexport const defaultSpotlightFilter: SpotlightFilterFunction = (_query, data) => {\n const query = _query.trim().toLowerCase();\n const priorityMatrix: SpotlightActionData[][] = [[], []];\n const flatActions = getFlatActions(data);\n flatActions.forEach((item) => {\n if (item.label?.toLowerCase().includes(query)) {\n priorityMatrix[0].push(item);\n } else if (\n item.description?.toLowerCase().includes(query) ||\n getKeywords(item.keywords).includes(query)\n ) {\n priorityMatrix[1].push(item);\n }\n });\n\n return flatActionsToGroups(priorityMatrix.flat());\n};\n"],"
|
|
1
|
+
{"version":3,"file":"default-spotlight-filter.cjs","names":[],"sources":["../src/default-spotlight-filter.ts"],"sourcesContent":["import type {\n SpotlightActionData,\n SpotlightActionGroupData,\n SpotlightActions,\n SpotlightFilterFunction,\n} from './Spotlight';\n\nfunction getKeywords(keywords: string | string[] | undefined) {\n if (Array.isArray(keywords)) {\n return keywords\n .map((keyword) => keyword.trim())\n .join(',')\n .toLowerCase()\n .trim();\n }\n\n if (typeof keywords === 'string') {\n return keywords.toLowerCase().trim();\n }\n\n return '';\n}\n\nfunction getFlatActions(data: SpotlightActions[]) {\n return data.reduce<SpotlightActionData[]>((acc, item) => {\n if ('actions' in item) {\n return [...acc, ...item.actions.map((action) => ({ ...action, group: item.group }))];\n }\n\n return [...acc, item];\n }, []);\n}\n\nfunction flatActionsToGroups(data: SpotlightActionData[]) {\n const groups: Record<string, { pushed: boolean; data: SpotlightActionGroupData }> = {};\n const result: SpotlightActions[] = [];\n\n data.forEach((action) => {\n if (action.group) {\n if (!groups[action.group]) {\n groups[action.group] = { pushed: false, data: { group: action.group, actions: [] } };\n }\n\n groups[action.group].data.actions.push(action);\n\n if (!groups[action.group].pushed) {\n groups[action.group].pushed = true;\n result.push(groups[action.group].data);\n }\n } else {\n result.push(action);\n }\n });\n\n return result;\n}\n\nexport const defaultSpotlightFilter: SpotlightFilterFunction = (_query, data) => {\n const query = _query.trim().toLowerCase();\n const priorityMatrix: SpotlightActionData[][] = [[], []];\n const flatActions = getFlatActions(data);\n flatActions.forEach((item) => {\n if (item.label?.toLowerCase().includes(query)) {\n priorityMatrix[0].push(item);\n } else if (\n item.description?.toLowerCase().includes(query) ||\n getKeywords(item.keywords).includes(query)\n ) {\n priorityMatrix[1].push(item);\n }\n });\n\n return flatActionsToGroups(priorityMatrix.flat());\n};\n"],"mappings":";;AAOA,SAAS,YAAY,UAAyC;AAC5D,KAAI,MAAM,QAAQ,SAAS,CACzB,QAAO,SACJ,KAAK,YAAY,QAAQ,MAAM,CAAC,CAChC,KAAK,IAAI,CACT,aAAa,CACb,MAAM;AAGX,KAAI,OAAO,aAAa,SACtB,QAAO,SAAS,aAAa,CAAC,MAAM;AAGtC,QAAO;;AAGT,SAAS,eAAe,MAA0B;AAChD,QAAO,KAAK,QAA+B,KAAK,SAAS;AACvD,MAAI,aAAa,KACf,QAAO,CAAC,GAAG,KAAK,GAAG,KAAK,QAAQ,KAAK,YAAY;GAAE,GAAG;GAAQ,OAAO,KAAK;GAAO,EAAE,CAAC;AAGtF,SAAO,CAAC,GAAG,KAAK,KAAK;IACpB,EAAE,CAAC;;AAGR,SAAS,oBAAoB,MAA6B;CACxD,MAAM,SAA8E,EAAE;CACtF,MAAM,SAA6B,EAAE;AAErC,MAAK,SAAS,WAAW;AACvB,MAAI,OAAO,OAAO;AAChB,OAAI,CAAC,OAAO,OAAO,OACjB,QAAO,OAAO,SAAS;IAAE,QAAQ;IAAO,MAAM;KAAE,OAAO,OAAO;KAAO,SAAS,EAAE;KAAE;IAAE;AAGtF,UAAO,OAAO,OAAO,KAAK,QAAQ,KAAK,OAAO;AAE9C,OAAI,CAAC,OAAO,OAAO,OAAO,QAAQ;AAChC,WAAO,OAAO,OAAO,SAAS;AAC9B,WAAO,KAAK,OAAO,OAAO,OAAO,KAAK;;QAGxC,QAAO,KAAK,OAAO;GAErB;AAEF,QAAO;;AAGT,MAAa,0BAAmD,QAAQ,SAAS;CAC/E,MAAM,QAAQ,OAAO,MAAM,CAAC,aAAa;CACzC,MAAM,iBAA0C,CAAC,EAAE,EAAE,EAAE,CAAC;AACpC,gBAAe,KAAK,CAC5B,SAAS,SAAS;AAC5B,MAAI,KAAK,OAAO,aAAa,CAAC,SAAS,MAAM,CAC3C,gBAAe,GAAG,KAAK,KAAK;WAE5B,KAAK,aAAa,aAAa,CAAC,SAAS,MAAM,IAC/C,YAAY,KAAK,SAAS,CAAC,SAAS,MAAM,CAE1C,gBAAe,GAAG,KAAK,KAAK;GAE9B;AAEF,QAAO,oBAAoB,eAAe,MAAM,CAAC"}
|
package/cjs/get-hotkeys.cjs
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var spotlight_store = require('./spotlight.store.cjs');
|
|
5
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
const require_spotlight_store = require("./spotlight.store.cjs");
|
|
3
|
+
//#region packages/@mantine/spotlight/src/get-hotkeys.ts
|
|
6
4
|
function getHotkeys(hotkeys, store) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (Array.isArray(hotkeys)) {
|
|
12
|
-
return hotkeys.map((hotkey) => [hotkey, open]);
|
|
13
|
-
}
|
|
14
|
-
return [[hotkeys, open]];
|
|
5
|
+
if (!hotkeys) return [];
|
|
6
|
+
const open = () => require_spotlight_store.spotlightActions.open(store);
|
|
7
|
+
if (Array.isArray(hotkeys)) return hotkeys.map((hotkey) => [hotkey, open]);
|
|
8
|
+
return [[hotkeys, open]];
|
|
15
9
|
}
|
|
16
|
-
|
|
10
|
+
//#endregion
|
|
17
11
|
exports.getHotkeys = getHotkeys;
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=get-hotkeys.cjs.map
|
package/cjs/get-hotkeys.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-hotkeys.cjs","sources":["../src/get-hotkeys.ts"],"sourcesContent":["import { HotkeyItem } from '@mantine/hooks';\nimport { spotlightActions, SpotlightStore } from './spotlight.store';\n\nexport function getHotkeys(\n hotkeys: string | string[] | null | undefined,\n store: SpotlightStore\n): HotkeyItem[] {\n if (!hotkeys) {\n return [];\n }\n\n const open = () => spotlightActions.open(store);\n\n if (Array.isArray(hotkeys)) {\n return hotkeys.map((hotkey) => [hotkey, open]);\n }\n\n return [[hotkeys, open]];\n}\n"],"
|
|
1
|
+
{"version":3,"file":"get-hotkeys.cjs","names":["spotlightActions"],"sources":["../src/get-hotkeys.ts"],"sourcesContent":["import { HotkeyItem } from '@mantine/hooks';\nimport { spotlightActions, SpotlightStore } from './spotlight.store';\n\nexport function getHotkeys(\n hotkeys: string | string[] | null | undefined,\n store: SpotlightStore\n): HotkeyItem[] {\n if (!hotkeys) {\n return [];\n }\n\n const open = () => spotlightActions.open(store);\n\n if (Array.isArray(hotkeys)) {\n return hotkeys.map((hotkey) => [hotkey, open]);\n }\n\n return [[hotkeys, open]];\n}\n"],"mappings":";;;AAGA,SAAgB,WACd,SACA,OACc;AACd,KAAI,CAAC,QACH,QAAO,EAAE;CAGX,MAAM,aAAaA,wBAAAA,iBAAiB,KAAK,MAAM;AAE/C,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,KAAK,WAAW,CAAC,QAAQ,KAAK,CAAC;AAGhD,QAAO,CAAC,CAAC,SAAS,KAAK,CAAC"}
|
package/cjs/index.cjs
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.isActionsGroup =
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.SpotlightActionsList = SpotlightActionsList.SpotlightActionsList;
|
|
29
|
-
exports.SpotlightEmpty = SpotlightEmpty.SpotlightEmpty;
|
|
30
|
-
exports.SpotlightFooter = SpotlightFooter.SpotlightFooter;
|
|
31
|
-
exports.SpotlightSearch = SpotlightSearch.SpotlightSearch;
|
|
32
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_spotlight_store = require("./spotlight.store.cjs");
|
|
3
|
+
const require_is_actions_group = require("./is-actions-group.cjs");
|
|
4
|
+
const require_SpotlightAction = require("./SpotlightAction.cjs");
|
|
5
|
+
const require_SpotlightActionsGroup = require("./SpotlightActionsGroup.cjs");
|
|
6
|
+
const require_SpotlightActionsList = require("./SpotlightActionsList.cjs");
|
|
7
|
+
const require_SpotlightEmpty = require("./SpotlightEmpty.cjs");
|
|
8
|
+
const require_SpotlightFooter = require("./SpotlightFooter.cjs");
|
|
9
|
+
const require_SpotlightRoot = require("./SpotlightRoot.cjs");
|
|
10
|
+
const require_SpotlightSearch = require("./SpotlightSearch.cjs");
|
|
11
|
+
const require_Spotlight = require("./Spotlight.cjs");
|
|
12
|
+
exports.Spotlight = require_Spotlight.Spotlight;
|
|
13
|
+
exports.SpotlightAction = require_SpotlightAction.SpotlightAction;
|
|
14
|
+
exports.SpotlightActionsGroup = require_SpotlightActionsGroup.SpotlightActionsGroup;
|
|
15
|
+
exports.SpotlightActionsList = require_SpotlightActionsList.SpotlightActionsList;
|
|
16
|
+
exports.SpotlightEmpty = require_SpotlightEmpty.SpotlightEmpty;
|
|
17
|
+
exports.SpotlightFooter = require_SpotlightFooter.SpotlightFooter;
|
|
18
|
+
exports.SpotlightRoot = require_SpotlightRoot.SpotlightRoot;
|
|
19
|
+
exports.SpotlightSearch = require_SpotlightSearch.SpotlightSearch;
|
|
20
|
+
exports.closeSpotlight = require_spotlight_store.closeSpotlight;
|
|
21
|
+
exports.createSpotlight = require_spotlight_store.createSpotlight;
|
|
22
|
+
exports.createSpotlightStore = require_spotlight_store.createSpotlightStore;
|
|
23
|
+
exports.isActionsGroup = require_is_actions_group.isActionsGroup;
|
|
24
|
+
exports.openSpotlight = require_spotlight_store.openSpotlight;
|
|
25
|
+
exports.spotlight = require_spotlight_store.spotlight;
|
|
26
|
+
exports.toggleSpotlight = require_spotlight_store.toggleSpotlight;
|
|
27
|
+
exports.useSpotlight = require_spotlight_store.useSpotlight;
|
package/cjs/is-actions-group.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
//#region packages/@mantine/spotlight/src/is-actions-group.ts
|
|
4
3
|
function isActionsGroup(item) {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const _item = item;
|
|
5
|
+
return _item.group !== void 0 && Array.isArray(_item.actions);
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
//#endregion
|
|
9
8
|
exports.isActionsGroup = isActionsGroup;
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=is-actions-group.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-actions-group.cjs","sources":["../src/is-actions-group.ts"],"sourcesContent":["import type { SpotlightActionData, SpotlightActionGroupData } from './Spotlight';\n\nexport function isActionsGroup(\n item: SpotlightActionData | SpotlightActionGroupData\n): item is SpotlightActionGroupData {\n const _item = item as SpotlightActionGroupData;\n return _item.group !== undefined && Array.isArray(_item.actions);\n}\n"],"
|
|
1
|
+
{"version":3,"file":"is-actions-group.cjs","names":[],"sources":["../src/is-actions-group.ts"],"sourcesContent":["import type { SpotlightActionData, SpotlightActionGroupData } from './Spotlight';\n\nexport function isActionsGroup(\n item: SpotlightActionData | SpotlightActionGroupData\n): item is SpotlightActionGroupData {\n const _item = item as SpotlightActionGroupData;\n return _item.group !== undefined && Array.isArray(_item.actions);\n}\n"],"mappings":";;AAEA,SAAgB,eACd,MACkC;CAClC,MAAM,QAAQ;AACd,QAAO,MAAM,UAAU,KAAA,KAAa,MAAM,QAAQ,MAAM,QAAQ"}
|
package/cjs/limit-actions.cjs
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var isActionsGroup = require('./is-actions-group.cjs');
|
|
5
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
const require_is_actions_group = require("./is-actions-group.cjs");
|
|
3
|
+
//#region packages/@mantine/spotlight/src/limit-actions.ts
|
|
6
4
|
function limitActions(actions, limit) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
count += 1;
|
|
25
|
-
}
|
|
26
|
-
return acc;
|
|
27
|
-
}, []);
|
|
5
|
+
if (!Array.isArray(actions)) return [];
|
|
6
|
+
let count = 0;
|
|
7
|
+
return actions.reduce((acc, item) => {
|
|
8
|
+
if (count >= limit) return acc;
|
|
9
|
+
if (require_is_actions_group.isActionsGroup(item)) {
|
|
10
|
+
const groupActions = limitActions(item.actions, limit - count);
|
|
11
|
+
acc.push({
|
|
12
|
+
group: item.group,
|
|
13
|
+
actions: groupActions
|
|
14
|
+
});
|
|
15
|
+
count += groupActions.length;
|
|
16
|
+
} else {
|
|
17
|
+
acc.push(item);
|
|
18
|
+
count += 1;
|
|
19
|
+
}
|
|
20
|
+
return acc;
|
|
21
|
+
}, []);
|
|
28
22
|
}
|
|
29
|
-
|
|
23
|
+
//#endregion
|
|
30
24
|
exports.limitActions = limitActions;
|
|
31
|
-
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=limit-actions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limit-actions.cjs","sources":["../src/limit-actions.ts"],"sourcesContent":["import { isActionsGroup } from './is-actions-group';\nimport type { SpotlightActionData, SpotlightActions } from './Spotlight';\n\nexport function limitActions(actions: SpotlightActions[], limit: number) {\n if (!Array.isArray(actions)) {\n return [];\n }\n\n let count = 0;\n return actions.reduce<SpotlightActions[]>((acc, item) => {\n if (count >= limit) {\n return acc;\n }\n\n if (isActionsGroup(item)) {\n const groupActions = limitActions(item.actions, limit - count);\n acc.push({\n group: item.group,\n actions: groupActions as SpotlightActionData[],\n });\n count += groupActions.length;\n } else {\n acc.push(item);\n count += 1;\n }\n\n return acc;\n }, []);\n}\n"],"
|
|
1
|
+
{"version":3,"file":"limit-actions.cjs","names":["isActionsGroup"],"sources":["../src/limit-actions.ts"],"sourcesContent":["import { isActionsGroup } from './is-actions-group';\nimport type { SpotlightActionData, SpotlightActions } from './Spotlight';\n\nexport function limitActions(actions: SpotlightActions[], limit: number) {\n if (!Array.isArray(actions)) {\n return [];\n }\n\n let count = 0;\n return actions.reduce<SpotlightActions[]>((acc, item) => {\n if (count >= limit) {\n return acc;\n }\n\n if (isActionsGroup(item)) {\n const groupActions = limitActions(item.actions, limit - count);\n acc.push({\n group: item.group,\n actions: groupActions as SpotlightActionData[],\n });\n count += groupActions.length;\n } else {\n acc.push(item);\n count += 1;\n }\n\n return acc;\n }, []);\n}\n"],"mappings":";;;AAGA,SAAgB,aAAa,SAA6B,OAAe;AACvE,KAAI,CAAC,MAAM,QAAQ,QAAQ,CACzB,QAAO,EAAE;CAGX,IAAI,QAAQ;AACZ,QAAO,QAAQ,QAA4B,KAAK,SAAS;AACvD,MAAI,SAAS,MACX,QAAO;AAGT,MAAIA,yBAAAA,eAAe,KAAK,EAAE;GACxB,MAAM,eAAe,aAAa,KAAK,SAAS,QAAQ,MAAM;AAC9D,OAAI,KAAK;IACP,OAAO,KAAK;IACZ,SAAS;IACV,CAAC;AACF,YAAS,aAAa;SACjB;AACL,OAAI,KAAK,KAAK;AACd,YAAS;;AAGX,SAAO;IACN,EAAE,CAAC"}
|