@mantine/hooks 4.2.4 → 4.2.5
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/use-list-state/use-list-state.js +22 -51
- package/cjs/use-list-state/use-list-state.js.map +1 -1
- package/esm/use-list-state/use-list-state.js +22 -51
- package/esm/use-list-state/use-list-state.js.map +1 -1
- package/lib/use-list-state/use-list-state.d.ts +11 -11
- package/lib/use-list-state/use-list-state.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -25,68 +25,39 @@ var __spreadValues = (a, b) => {
|
|
|
25
25
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
26
|
function useListState(initialValue = []) {
|
|
27
27
|
const [state, setState] = react.useState(initialValue);
|
|
28
|
-
const append = (...items) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
setState(newState);
|
|
36
|
-
return newState;
|
|
37
|
-
};
|
|
38
|
-
const insert = (index, ...items) => {
|
|
39
|
-
const newState = [...state.slice(0, index), ...items, ...state.slice(index)];
|
|
40
|
-
setState(newState);
|
|
41
|
-
return newState;
|
|
42
|
-
};
|
|
43
|
-
const apply = (fn) => {
|
|
44
|
-
const newState = state.map((item, index) => fn(item, index));
|
|
45
|
-
setState(newState);
|
|
46
|
-
return newState;
|
|
47
|
-
};
|
|
48
|
-
const remove = (...indices) => {
|
|
49
|
-
const newState = state.filter((_, index) => !indices.includes(index));
|
|
50
|
-
setState(newState);
|
|
51
|
-
return newState;
|
|
52
|
-
};
|
|
53
|
-
const pop = () => {
|
|
54
|
-
const cloned = [...state];
|
|
28
|
+
const append = (...items) => setState((current) => [...current, ...items]);
|
|
29
|
+
const prepend = (...items) => setState((current) => [...items, ...current]);
|
|
30
|
+
const insert = (index, ...items) => setState((current) => [...current.slice(0, index), ...items, ...current.slice(index)]);
|
|
31
|
+
const apply = (fn) => setState((current) => current.map((item, index) => fn(item, index)));
|
|
32
|
+
const remove = (...indices) => setState((current) => current.filter((_, index) => !indices.includes(index)));
|
|
33
|
+
const pop = () => setState((current) => {
|
|
34
|
+
const cloned = [...current];
|
|
55
35
|
cloned.pop();
|
|
56
|
-
setState(cloned);
|
|
57
36
|
return cloned;
|
|
58
|
-
};
|
|
59
|
-
const shift = () => {
|
|
60
|
-
const cloned = [...
|
|
37
|
+
});
|
|
38
|
+
const shift = () => setState((current) => {
|
|
39
|
+
const cloned = [...current];
|
|
61
40
|
cloned.shift();
|
|
62
|
-
setState(cloned);
|
|
63
41
|
return cloned;
|
|
64
|
-
};
|
|
65
|
-
const reorder = ({ from, to }) => {
|
|
66
|
-
const cloned = [...
|
|
67
|
-
const item =
|
|
42
|
+
});
|
|
43
|
+
const reorder = ({ from, to }) => setState((current) => {
|
|
44
|
+
const cloned = [...current];
|
|
45
|
+
const item = current[from];
|
|
68
46
|
cloned.splice(from, 1);
|
|
69
47
|
cloned.splice(to, 0, item);
|
|
70
|
-
setState(cloned);
|
|
71
48
|
return cloned;
|
|
72
|
-
};
|
|
73
|
-
const setItem = (index, item) => {
|
|
74
|
-
const cloned = [...
|
|
49
|
+
});
|
|
50
|
+
const setItem = (index, item) => setState((current) => {
|
|
51
|
+
const cloned = [...current];
|
|
75
52
|
cloned[index] = item;
|
|
76
|
-
setState(cloned);
|
|
77
53
|
return cloned;
|
|
78
|
-
};
|
|
79
|
-
const setItemProp = (index, prop, value) => {
|
|
80
|
-
const cloned = [...
|
|
54
|
+
});
|
|
55
|
+
const setItemProp = (index, prop, value) => setState((current) => {
|
|
56
|
+
const cloned = [...current];
|
|
81
57
|
cloned[index] = __spreadProps(__spreadValues({}, cloned[index]), { [prop]: value });
|
|
82
|
-
setState(cloned);
|
|
83
58
|
return cloned;
|
|
84
|
-
};
|
|
85
|
-
const applyWhere = (condition, fn) =>
|
|
86
|
-
const newState = state.map((item, index) => condition(item, index) ? fn(item, index) : item);
|
|
87
|
-
setState(newState);
|
|
88
|
-
return newState;
|
|
89
|
-
};
|
|
59
|
+
});
|
|
60
|
+
const applyWhere = (condition, fn) => setState((current) => current.map((item, index) => condition(item, index) ? fn(item, index) : item));
|
|
90
61
|
return [
|
|
91
62
|
state,
|
|
92
63
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-list-state.js","sources":["../../src/use-list-state/use-list-state.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nexport interface UseListStateHandler<T> {\n setState: React.Dispatch<React.SetStateAction<T[]>>;\n append: (...items: T[]) =>
|
|
1
|
+
{"version":3,"file":"use-list-state.js","sources":["../../src/use-list-state/use-list-state.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nexport interface UseListStateHandler<T> {\n setState: React.Dispatch<React.SetStateAction<T[]>>;\n append: (...items: T[]) => void;\n prepend: (...items: T[]) => void;\n insert: (index: number, ...items: T[]) => void;\n pop: () => void;\n shift: () => void;\n apply: (fn: (item: T, index?: number) => T) => void;\n applyWhere: (\n condition: (item: T, index: number) => boolean,\n fn: (item: T, index?: number) => T\n ) => void;\n remove: (...indices: number[]) => void;\n reorder: ({ from, to }: { from: number; to: number }) => void;\n setItem: (index: number, item: T) => void;\n setItemProp: <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) => void;\n}\n\nexport type UseListState<T> = [T[], UseListStateHandler<T>];\n\nexport function useListState<T>(initialValue: T[] = []): UseListState<T> {\n const [state, setState] = useState(initialValue);\n\n const append = (...items: T[]) => setState((current) => [...current, ...items]);\n const prepend = (...items: T[]) => setState((current) => [...items, ...current]);\n\n const insert = (index: number, ...items: T[]) =>\n setState((current) => [...current.slice(0, index), ...items, ...current.slice(index)]);\n\n const apply = (fn: (item: T, index?: number) => T) =>\n setState((current) => current.map((item, index) => fn(item, index)));\n\n const remove = (...indices: number[]) =>\n setState((current) => current.filter((_, index) => !indices.includes(index)));\n\n const pop = () =>\n setState((current) => {\n const cloned = [...current];\n cloned.pop();\n return cloned;\n });\n\n const shift = () =>\n setState((current) => {\n const cloned = [...current];\n cloned.shift();\n return cloned;\n });\n\n const reorder = ({ from, to }: { from: number; to: number }) =>\n setState((current) => {\n const cloned = [...current];\n const item = current[from];\n\n cloned.splice(from, 1);\n cloned.splice(to, 0, item);\n\n return cloned;\n });\n\n const setItem = (index: number, item: T) =>\n setState((current) => {\n const cloned = [...current];\n cloned[index] = item;\n return cloned;\n });\n\n const setItemProp = <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) =>\n setState((current) => {\n const cloned = [...current];\n cloned[index] = { ...cloned[index], [prop]: value };\n return cloned;\n });\n\n const applyWhere = (\n condition: (item: T, index: number) => boolean,\n fn: (item: T, index?: number) => T\n ) =>\n setState((current) =>\n current.map((item, index) => (condition(item, index) ? fn(item, index) : item))\n );\n\n return [\n state,\n {\n setState,\n append,\n prepend,\n insert,\n pop,\n shift,\n apply,\n applyWhere,\n remove,\n reorder,\n setItem,\n setItemProp,\n },\n ];\n}\n"],"names":["useState"],"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,c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,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,WAAW;AACjB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -21,68 +21,39 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
22
|
function useListState(initialValue = []) {
|
|
23
23
|
const [state, setState] = useState(initialValue);
|
|
24
|
-
const append = (...items) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
setState(newState);
|
|
32
|
-
return newState;
|
|
33
|
-
};
|
|
34
|
-
const insert = (index, ...items) => {
|
|
35
|
-
const newState = [...state.slice(0, index), ...items, ...state.slice(index)];
|
|
36
|
-
setState(newState);
|
|
37
|
-
return newState;
|
|
38
|
-
};
|
|
39
|
-
const apply = (fn) => {
|
|
40
|
-
const newState = state.map((item, index) => fn(item, index));
|
|
41
|
-
setState(newState);
|
|
42
|
-
return newState;
|
|
43
|
-
};
|
|
44
|
-
const remove = (...indices) => {
|
|
45
|
-
const newState = state.filter((_, index) => !indices.includes(index));
|
|
46
|
-
setState(newState);
|
|
47
|
-
return newState;
|
|
48
|
-
};
|
|
49
|
-
const pop = () => {
|
|
50
|
-
const cloned = [...state];
|
|
24
|
+
const append = (...items) => setState((current) => [...current, ...items]);
|
|
25
|
+
const prepend = (...items) => setState((current) => [...items, ...current]);
|
|
26
|
+
const insert = (index, ...items) => setState((current) => [...current.slice(0, index), ...items, ...current.slice(index)]);
|
|
27
|
+
const apply = (fn) => setState((current) => current.map((item, index) => fn(item, index)));
|
|
28
|
+
const remove = (...indices) => setState((current) => current.filter((_, index) => !indices.includes(index)));
|
|
29
|
+
const pop = () => setState((current) => {
|
|
30
|
+
const cloned = [...current];
|
|
51
31
|
cloned.pop();
|
|
52
|
-
setState(cloned);
|
|
53
32
|
return cloned;
|
|
54
|
-
};
|
|
55
|
-
const shift = () => {
|
|
56
|
-
const cloned = [...
|
|
33
|
+
});
|
|
34
|
+
const shift = () => setState((current) => {
|
|
35
|
+
const cloned = [...current];
|
|
57
36
|
cloned.shift();
|
|
58
|
-
setState(cloned);
|
|
59
37
|
return cloned;
|
|
60
|
-
};
|
|
61
|
-
const reorder = ({ from, to }) => {
|
|
62
|
-
const cloned = [...
|
|
63
|
-
const item =
|
|
38
|
+
});
|
|
39
|
+
const reorder = ({ from, to }) => setState((current) => {
|
|
40
|
+
const cloned = [...current];
|
|
41
|
+
const item = current[from];
|
|
64
42
|
cloned.splice(from, 1);
|
|
65
43
|
cloned.splice(to, 0, item);
|
|
66
|
-
setState(cloned);
|
|
67
44
|
return cloned;
|
|
68
|
-
};
|
|
69
|
-
const setItem = (index, item) => {
|
|
70
|
-
const cloned = [...
|
|
45
|
+
});
|
|
46
|
+
const setItem = (index, item) => setState((current) => {
|
|
47
|
+
const cloned = [...current];
|
|
71
48
|
cloned[index] = item;
|
|
72
|
-
setState(cloned);
|
|
73
49
|
return cloned;
|
|
74
|
-
};
|
|
75
|
-
const setItemProp = (index, prop, value) => {
|
|
76
|
-
const cloned = [...
|
|
50
|
+
});
|
|
51
|
+
const setItemProp = (index, prop, value) => setState((current) => {
|
|
52
|
+
const cloned = [...current];
|
|
77
53
|
cloned[index] = __spreadProps(__spreadValues({}, cloned[index]), { [prop]: value });
|
|
78
|
-
setState(cloned);
|
|
79
54
|
return cloned;
|
|
80
|
-
};
|
|
81
|
-
const applyWhere = (condition, fn) =>
|
|
82
|
-
const newState = state.map((item, index) => condition(item, index) ? fn(item, index) : item);
|
|
83
|
-
setState(newState);
|
|
84
|
-
return newState;
|
|
85
|
-
};
|
|
55
|
+
});
|
|
56
|
+
const applyWhere = (condition, fn) => setState((current) => current.map((item, index) => condition(item, index) ? fn(item, index) : item));
|
|
86
57
|
return [
|
|
87
58
|
state,
|
|
88
59
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-list-state.js","sources":["../../src/use-list-state/use-list-state.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nexport interface UseListStateHandler<T> {\n setState: React.Dispatch<React.SetStateAction<T[]>>;\n append: (...items: T[]) =>
|
|
1
|
+
{"version":3,"file":"use-list-state.js","sources":["../../src/use-list-state/use-list-state.ts"],"sourcesContent":["import React, { useState } from 'react';\n\nexport interface UseListStateHandler<T> {\n setState: React.Dispatch<React.SetStateAction<T[]>>;\n append: (...items: T[]) => void;\n prepend: (...items: T[]) => void;\n insert: (index: number, ...items: T[]) => void;\n pop: () => void;\n shift: () => void;\n apply: (fn: (item: T, index?: number) => T) => void;\n applyWhere: (\n condition: (item: T, index: number) => boolean,\n fn: (item: T, index?: number) => T\n ) => void;\n remove: (...indices: number[]) => void;\n reorder: ({ from, to }: { from: number; to: number }) => void;\n setItem: (index: number, item: T) => void;\n setItemProp: <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) => void;\n}\n\nexport type UseListState<T> = [T[], UseListStateHandler<T>];\n\nexport function useListState<T>(initialValue: T[] = []): UseListState<T> {\n const [state, setState] = useState(initialValue);\n\n const append = (...items: T[]) => setState((current) => [...current, ...items]);\n const prepend = (...items: T[]) => setState((current) => [...items, ...current]);\n\n const insert = (index: number, ...items: T[]) =>\n setState((current) => [...current.slice(0, index), ...items, ...current.slice(index)]);\n\n const apply = (fn: (item: T, index?: number) => T) =>\n setState((current) => current.map((item, index) => fn(item, index)));\n\n const remove = (...indices: number[]) =>\n setState((current) => current.filter((_, index) => !indices.includes(index)));\n\n const pop = () =>\n setState((current) => {\n const cloned = [...current];\n cloned.pop();\n return cloned;\n });\n\n const shift = () =>\n setState((current) => {\n const cloned = [...current];\n cloned.shift();\n return cloned;\n });\n\n const reorder = ({ from, to }: { from: number; to: number }) =>\n setState((current) => {\n const cloned = [...current];\n const item = current[from];\n\n cloned.splice(from, 1);\n cloned.splice(to, 0, item);\n\n return cloned;\n });\n\n const setItem = (index: number, item: T) =>\n setState((current) => {\n const cloned = [...current];\n cloned[index] = item;\n return cloned;\n });\n\n const setItemProp = <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) =>\n setState((current) => {\n const cloned = [...current];\n cloned[index] = { ...cloned[index], [prop]: value };\n return cloned;\n });\n\n const applyWhere = (\n condition: (item: T, index: number) => boolean,\n fn: (item: T, index?: number) => T\n ) =>\n setState((current) =>\n current.map((item, index) => (condition(item, index) ? fn(item, index) : item))\n );\n\n return [\n state,\n {\n setState,\n append,\n prepend,\n insert,\n pop,\n shift,\n apply,\n applyWhere,\n remove,\n reorder,\n setItem,\n setItemProp,\n },\n ];\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,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,E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]>>;
|
|
4
|
-
append: (...items: T[]) =>
|
|
5
|
-
prepend: (...items: T[]) =>
|
|
6
|
-
insert: (index: number, ...items: T[]) =>
|
|
7
|
-
pop: () =>
|
|
8
|
-
shift: () =>
|
|
9
|
-
apply: (fn: (item: T, index?: number) => T) =>
|
|
10
|
-
applyWhere: (condition: (item: T, index: number) => boolean, fn: (item: T, index?: number) => T) =>
|
|
11
|
-
remove: (...indices: number[]) =>
|
|
4
|
+
append: (...items: T[]) => void;
|
|
5
|
+
prepend: (...items: T[]) => void;
|
|
6
|
+
insert: (index: number, ...items: T[]) => void;
|
|
7
|
+
pop: () => void;
|
|
8
|
+
shift: () => void;
|
|
9
|
+
apply: (fn: (item: T, index?: number) => T) => void;
|
|
10
|
+
applyWhere: (condition: (item: T, index: number) => boolean, fn: (item: T, index?: number) => T) => void;
|
|
11
|
+
remove: (...indices: number[]) => void;
|
|
12
12
|
reorder: ({ from, to }: {
|
|
13
13
|
from: number;
|
|
14
14
|
to: number;
|
|
15
|
-
}) =>
|
|
16
|
-
setItem: (index: number, item: T) =>
|
|
17
|
-
setItemProp: <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) =>
|
|
15
|
+
}) => void;
|
|
16
|
+
setItem: (index: number, item: T) => void;
|
|
17
|
+
setItemProp: <K extends keyof T, U extends T[K]>(index: number, prop: K, value: U) => void;
|
|
18
18
|
}
|
|
19
19
|
export declare type UseListState<T> = [T[], UseListStateHandler<T>];
|
|
20
20
|
export declare function useListState<T>(initialValue?: T[]): UseListState<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-list-state.d.ts","sourceRoot":"","sources":["../../src/use-list-state/use-list-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC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