extra-react-hooks 0.1.15 → 0.2.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.
- package/README.md +3 -3
- package/dist/es2015/index.min.mjs +1 -1
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +6 -6
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +6 -6
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +1 -1
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +1 -1
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +6 -6
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +6 -6
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +1 -1
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/use-multiple-selection.d.ts +1 -1
- package/lib/es2015/use-multiple-selection.js +3 -3
- package/lib/es2015/use-multiple-selection.js.map +1 -1
- package/lib/es2015/use-single-selection.d.ts +2 -2
- package/lib/es2015/use-single-selection.js +3 -3
- package/lib/es2015/use-single-selection.js.map +1 -1
- package/lib/es2018/use-multiple-selection.d.ts +1 -1
- package/lib/es2018/use-multiple-selection.js +3 -3
- package/lib/es2018/use-multiple-selection.js.map +1 -1
- package/lib/es2018/use-single-selection.d.ts +2 -2
- package/lib/es2018/use-single-selection.js +3 -3
- package/lib/es2018/use-single-selection.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ interface IMultipleSelectionOption<T> {
|
|
|
7
7
|
toggle(): void;
|
|
8
8
|
}
|
|
9
9
|
export declare function useMultipleSelection<T>(values: T[], defaultSelectedIndexes?: number[]): {
|
|
10
|
-
|
|
10
|
+
selectedValues: T[];
|
|
11
11
|
options: Array<IMultipleSelectionOption<T>>;
|
|
12
12
|
};
|
|
13
13
|
export {};
|
|
@@ -10,8 +10,8 @@ function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
|
10
10
|
(0, errors_1.assert)(index >= 0 && index < values.length, 'The index of parameter defaultSelectedIndexes must be in the range of 0 to values.length');
|
|
11
11
|
}
|
|
12
12
|
const [selectedIndexes, setSelectedIndexes] = (0, react_1.useState)(new Set(defaultSelectedIndexes));
|
|
13
|
-
return {
|
|
14
|
-
|
|
13
|
+
return (0, react_1.useMemo)(() => ({
|
|
14
|
+
selectedValues: (0, iterable_operator_1.toArray)((0, iterable_operator_1.map)(selectedIndexes, i => values[i])),
|
|
15
15
|
options: values.map((value, index) => {
|
|
16
16
|
const selected = selectedIndexes.has(index);
|
|
17
17
|
const select = () => {
|
|
@@ -33,7 +33,7 @@ function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
|
33
33
|
toggle: selected ? unselect : select
|
|
34
34
|
};
|
|
35
35
|
})
|
|
36
|
-
};
|
|
36
|
+
}), [selectedIndexes]);
|
|
37
37
|
}
|
|
38
38
|
exports.useMultipleSelection = useMultipleSelection;
|
|
39
39
|
//# sourceMappingURL=use-multiple-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AACzC,+CAA2C;AAC3C,yDAAgD;AAYhD,SAAgB,oBAAoB,CAClC,MAAW,EACX,yBAAmC,EAAE;IAKrC,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,gDAAgD,CAAC,CAAA;IAC3E,KAAK,MAAM,KAAK,IAAI,sBAAsB,EAAE;QAC1C,IAAA,eAAM,EACJ,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,EACnC,0FAA0F,CAC3F,CAA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], defaultSelectedIndex: number): {
|
|
8
|
-
|
|
8
|
+
selectedValue: T;
|
|
9
9
|
options: Array<ISingleSelectionOption<T>>;
|
|
10
10
|
};
|
|
11
11
|
export declare function useSingleSelection<T>(values: T[]): {
|
|
12
|
-
|
|
12
|
+
selectedValue: T | undefined;
|
|
13
13
|
options: Array<ISingleSelectionOption<T>>;
|
|
14
14
|
};
|
|
@@ -10,15 +10,15 @@ function useSingleSelection(values, defaultSelectedIndex) {
|
|
|
10
10
|
(0, errors_1.assert)(defaultSelectedIndex >= 0 && defaultSelectedIndex < values.length, 'The parameter defaultSelectedIndex must be in the range of 0 to values.length');
|
|
11
11
|
}
|
|
12
12
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(defaultSelectedIndex);
|
|
13
|
-
return {
|
|
14
|
-
|
|
13
|
+
return (0, react_1.useMemo)(() => ({
|
|
14
|
+
selectedValue: (0, types_1.isUndefined)(selectedIndex) ? undefined : values[selectedIndex],
|
|
15
15
|
options: values.map((value, index) => ({
|
|
16
16
|
value,
|
|
17
17
|
index,
|
|
18
18
|
selected: index === selectedIndex,
|
|
19
19
|
select: () => setSelectedIndex(index)
|
|
20
20
|
}))
|
|
21
|
-
};
|
|
21
|
+
}), [selectedIndex]);
|
|
22
22
|
}
|
|
23
23
|
exports.useSingleSelection = useSingleSelection;
|
|
24
24
|
//# sourceMappingURL=use-single-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AACzC,6CAA8D;AAC9D,+CAA2C;AAqB3C,SAAgB,kBAAkB,CAChC,MAAW,EACX,oBAA6B;IAE7B,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,gDAAgD,CAAC,CAAA;IAC3E,IAAI,IAAA,qBAAa,EAAC,oBAAoB,CAAC,EAAE;QACvC,IAAA,eAAM,EACJ,oBAAoB,IAAI,CAAC,IAAI,oBAAoB,GAAG,MAAM,CAAC,MAAM,EACjE,+EAA+E,CAChF,CAAA;KACF;IAED,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAqB,oBAAoB,CAAC,CAAA;IAE5F,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QACpB,aAAa,EAAE,IAAA,mBAAW,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC7E,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACrC,KAAK;YACL,KAAK;YACL,QAAQ,EAAE,KAAK,KAAK,aAAa;YACjC,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC;SACtC,CAAC,CAAC;KACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAA;AACtB,CAAC;AAvBD,gDAuBC"}
|
|
@@ -7,7 +7,7 @@ interface IMultipleSelectionOption<T> {
|
|
|
7
7
|
toggle(): void;
|
|
8
8
|
}
|
|
9
9
|
export declare function useMultipleSelection<T>(values: T[], defaultSelectedIndexes?: number[]): {
|
|
10
|
-
|
|
10
|
+
selectedValues: T[];
|
|
11
11
|
options: Array<IMultipleSelectionOption<T>>;
|
|
12
12
|
};
|
|
13
13
|
export {};
|
|
@@ -10,8 +10,8 @@ function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
|
10
10
|
(0, errors_1.assert)(index >= 0 && index < values.length, 'The index of parameter defaultSelectedIndexes must be in the range of 0 to values.length');
|
|
11
11
|
}
|
|
12
12
|
const [selectedIndexes, setSelectedIndexes] = (0, react_1.useState)(new Set(defaultSelectedIndexes));
|
|
13
|
-
return {
|
|
14
|
-
|
|
13
|
+
return (0, react_1.useMemo)(() => ({
|
|
14
|
+
selectedValues: (0, iterable_operator_1.toArray)((0, iterable_operator_1.map)(selectedIndexes, i => values[i])),
|
|
15
15
|
options: values.map((value, index) => {
|
|
16
16
|
const selected = selectedIndexes.has(index);
|
|
17
17
|
const select = () => {
|
|
@@ -33,7 +33,7 @@ function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
|
33
33
|
toggle: selected ? unselect : select
|
|
34
34
|
};
|
|
35
35
|
})
|
|
36
|
-
};
|
|
36
|
+
}), [selectedIndexes]);
|
|
37
37
|
}
|
|
38
38
|
exports.useMultipleSelection = useMultipleSelection;
|
|
39
39
|
//# sourceMappingURL=use-multiple-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AACzC,+CAA2C;AAC3C,yDAAgD;AAYhD,SAAgB,oBAAoB,CAClC,MAAW,EACX,yBAAmC,EAAE;IAKrC,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,gDAAgD,CAAC,CAAA;IAC3E,KAAK,MAAM,KAAK,IAAI,sBAAsB,EAAE;QAC1C,IAAA,eAAM,EACJ,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,EACnC,0FAA0F,CAC3F,CAAA;KACF;IAED,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAA;IAEvF,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QACpB,cAAc,EAAE,IAAA,2BAAO,EAAC,IAAA,uBAAG,EAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACnC,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YAC3C,MAAM,MAAM,GAAG,GAAG,EAAE;gBAClB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;gBACpC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBACd,kBAAkB,CAAC,GAAG,CAAC,CAAA;YACzB,CAAC,CAAA;YACD,MAAM,QAAQ,GAAG,GAAG,EAAE;gBACpB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;gBACpC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;gBACjB,kBAAkB,CAAC,GAAG,CAAC,CAAA;YACzB,CAAC,CAAA;YAED,OAAO;gBACL,KAAK;gBACL,KAAK;gBACL,QAAQ;gBACR,MAAM;gBACN,QAAQ;gBACR,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;aACrC,CAAA;QACH,CAAC,CAAC;KACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAA;AACxB,CAAC;AA1CD,oDA0CC"}
|
|
@@ -5,10 +5,10 @@ export interface ISingleSelectionOption<T> {
|
|
|
5
5
|
select(): void;
|
|
6
6
|
}
|
|
7
7
|
export declare function useSingleSelection<T>(values: T[], defaultSelectedIndex: number): {
|
|
8
|
-
|
|
8
|
+
selectedValue: T;
|
|
9
9
|
options: Array<ISingleSelectionOption<T>>;
|
|
10
10
|
};
|
|
11
11
|
export declare function useSingleSelection<T>(values: T[]): {
|
|
12
|
-
|
|
12
|
+
selectedValue: T | undefined;
|
|
13
13
|
options: Array<ISingleSelectionOption<T>>;
|
|
14
14
|
};
|
|
@@ -10,15 +10,15 @@ function useSingleSelection(values, defaultSelectedIndex) {
|
|
|
10
10
|
(0, errors_1.assert)(defaultSelectedIndex >= 0 && defaultSelectedIndex < values.length, 'The parameter defaultSelectedIndex must be in the range of 0 to values.length');
|
|
11
11
|
}
|
|
12
12
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(defaultSelectedIndex);
|
|
13
|
-
return {
|
|
14
|
-
|
|
13
|
+
return (0, react_1.useMemo)(() => ({
|
|
14
|
+
selectedValue: (0, types_1.isUndefined)(selectedIndex) ? undefined : values[selectedIndex],
|
|
15
15
|
options: values.map((value, index) => ({
|
|
16
16
|
value,
|
|
17
17
|
index,
|
|
18
18
|
selected: index === selectedIndex,
|
|
19
19
|
select: () => setSelectedIndex(index)
|
|
20
20
|
}))
|
|
21
|
-
};
|
|
21
|
+
}), [selectedIndex]);
|
|
22
22
|
}
|
|
23
23
|
exports.useSingleSelection = useSingleSelection;
|
|
24
24
|
//# sourceMappingURL=use-single-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAyC;AACzC,6CAA8D;AAC9D,+CAA2C;AAqB3C,SAAgB,kBAAkB,CAChC,MAAW,EACX,oBAA6B;IAE7B,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,gDAAgD,CAAC,CAAA;IAC3E,IAAI,IAAA,qBAAa,EAAC,oBAAoB,CAAC,EAAE;QACvC,IAAA,eAAM,EACJ,oBAAoB,IAAI,CAAC,IAAI,oBAAoB,GAAG,MAAM,CAAC,MAAM,EACjE,+EAA+E,CAChF,CAAA;KACF;IAED,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAqB,oBAAoB,CAAC,CAAA;IAE5F,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC;QACpB,aAAa,EAAE,IAAA,mBAAW,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC7E,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACrC,KAAK;YACL,KAAK;YACL,QAAQ,EAAE,KAAK,KAAK,aAAa;YACjC,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC;SACtC,CAAC,CAAC;KACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAA;AACtB,CAAC;AAvBD,gDAuBC"}
|