extra-react-hooks 0.1.12 → 0.1.13
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 +30 -5
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +41 -7
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +41 -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 +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +41 -7
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +41 -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/index.d.ts +1 -0
- package/lib/es2015/index.js +1 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2015/use-multiple-selection.d.ts +13 -0
- package/lib/es2015/use-multiple-selection.js +39 -0
- package/lib/es2015/use-multiple-selection.js.map +1 -0
- package/lib/es2015/use-single-selection.d.ts +5 -6
- package/lib/es2015/use-single-selection.js +4 -4
- package/lib/es2015/use-single-selection.js.map +1 -1
- package/lib/es2018/index.d.ts +1 -0
- package/lib/es2018/index.js +1 -0
- package/lib/es2018/index.js.map +1 -1
- package/lib/es2018/use-multiple-selection.d.ts +13 -0
- package/lib/es2018/use-multiple-selection.js +39 -0
- package/lib/es2018/use-multiple-selection.js.map +1 -0
- package/lib/es2018/use-single-selection.d.ts +5 -6
- package/lib/es2018/use-single-selection.js +4 -4
- package/lib/es2018/use-single-selection.js.map +1 -1
- package/package.json +12 -11
package/lib/es2015/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './use-increment';
|
|
|
2
2
|
export * from './use-is-mounted';
|
|
3
3
|
export * from './use-mount';
|
|
4
4
|
export * from './use-single-selection';
|
|
5
|
+
export * from './use-multiple-selection';
|
|
5
6
|
export * from './use-state-cycle';
|
|
6
7
|
export * from './use-toggle';
|
|
7
8
|
export * from './use-resize-observer';
|
package/lib/es2015/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./use-increment"), exports);
|
|
|
18
18
|
__exportStar(require("./use-is-mounted"), exports);
|
|
19
19
|
__exportStar(require("./use-mount"), exports);
|
|
20
20
|
__exportStar(require("./use-single-selection"), exports);
|
|
21
|
+
__exportStar(require("./use-multiple-selection"), exports);
|
|
21
22
|
__exportStar(require("./use-state-cycle"), exports);
|
|
22
23
|
__exportStar(require("./use-toggle"), exports);
|
|
23
24
|
__exportStar(require("./use-resize-observer"), exports);
|
package/lib/es2015/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,mDAAgC;AAChC,8CAA2B;AAC3B,yDAAsC;AACtC,oDAAiC;AACjC,+CAA4B;AAC5B,wDAAqC;AACrC,6CAA0B;AAC1B,qDAAkC;AAClC,6DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,mDAAgC;AAChC,8CAA2B;AAC3B,yDAAsC;AACtC,2DAAwC;AACxC,oDAAiC;AACjC,+CAA4B;AAC5B,wDAAqC;AACrC,6CAA0B;AAC1B,qDAAkC;AAClC,6DAA0C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface IMultipleSelectionOption<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
index: number;
|
|
4
|
+
selected: boolean;
|
|
5
|
+
select(): void;
|
|
6
|
+
unselect(): void;
|
|
7
|
+
toggle(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useMultipleSelection<T>(values: T[], defaultSelectedIndexes?: number[]): {
|
|
10
|
+
values: T[];
|
|
11
|
+
options: Array<IMultipleSelectionOption<T>>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultipleSelection = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const errors_1 = require("@blackglory/errors");
|
|
6
|
+
const iterable_operator_1 = require("iterable-operator");
|
|
7
|
+
function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
8
|
+
(0, errors_1.assert)(values.length > 0, 'The parameter values must be a non-empty array');
|
|
9
|
+
for (const index of defaultSelectedIndexes) {
|
|
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
|
+
}
|
|
12
|
+
const [selectedIndexes, setSelectedIndexes] = (0, react_1.useState)(new Set(defaultSelectedIndexes));
|
|
13
|
+
return {
|
|
14
|
+
values: (0, iterable_operator_1.toArray)((0, iterable_operator_1.map)(selectedIndexes, i => values[i])),
|
|
15
|
+
options: values.map((value, index) => {
|
|
16
|
+
const selected = selectedIndexes.has(index);
|
|
17
|
+
const select = () => {
|
|
18
|
+
const set = new Set(selectedIndexes);
|
|
19
|
+
set.add(index);
|
|
20
|
+
setSelectedIndexes(set);
|
|
21
|
+
};
|
|
22
|
+
const unselect = () => {
|
|
23
|
+
const set = new Set(selectedIndexes);
|
|
24
|
+
set.delete(index);
|
|
25
|
+
setSelectedIndexes(set);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
value,
|
|
29
|
+
index,
|
|
30
|
+
selected,
|
|
31
|
+
select,
|
|
32
|
+
unselect,
|
|
33
|
+
toggle: selected ? unselect : select
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.useMultipleSelection = useMultipleSelection;
|
|
39
|
+
//# sourceMappingURL=use-multiple-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,+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;QACL,MAAM,EAAE,IAAA,2BAAO,EAAC,IAAA,uBAAG,EAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,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,CAAA;AACH,CAAC;AA1CD,oDA0CC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface ISingleSelectionOption<T> {
|
|
2
2
|
value: T;
|
|
3
3
|
index: number;
|
|
4
4
|
selected: boolean;
|
|
5
|
-
select
|
|
5
|
+
select(): void;
|
|
6
6
|
}
|
|
7
|
-
export declare function useSingleSelection<T>(values: T[],
|
|
7
|
+
export declare function useSingleSelection<T>(values: T[], defaultSelectedIndex: number): {
|
|
8
8
|
value: T;
|
|
9
|
-
options: Array<
|
|
9
|
+
options: Array<ISingleSelectionOption<T>>;
|
|
10
10
|
};
|
|
11
11
|
export declare function useSingleSelection<T>(values: T[]): {
|
|
12
12
|
value: T | undefined;
|
|
13
|
-
options: Array<
|
|
13
|
+
options: Array<ISingleSelectionOption<T>>;
|
|
14
14
|
};
|
|
15
|
-
export {};
|
|
@@ -4,12 +4,12 @@ exports.useSingleSelection = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const types_1 = require("@blackglory/types");
|
|
6
6
|
const errors_1 = require("@blackglory/errors");
|
|
7
|
-
function useSingleSelection(values,
|
|
7
|
+
function useSingleSelection(values, defaultSelectedIndex) {
|
|
8
8
|
(0, errors_1.assert)(values.length > 0, 'The parameter values must be a non-empty array');
|
|
9
|
-
if ((0, types_1.isntUndefined)(
|
|
10
|
-
(0, errors_1.assert)(
|
|
9
|
+
if ((0, types_1.isntUndefined)(defaultSelectedIndex)) {
|
|
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
|
-
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(
|
|
12
|
+
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(defaultSelectedIndex);
|
|
13
13
|
return {
|
|
14
14
|
value: (0, types_1.isUndefined)(selectedIndex) ? undefined : values[selectedIndex],
|
|
15
15
|
options: values.map((value, index) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,6CAA8D;AAC9D,+CAA2C;
|
|
1
|
+
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,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;QACL,KAAK,EAAE,IAAA,mBAAW,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QACrE,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,CAAA;AACH,CAAC;AAvBD,gDAuBC"}
|
package/lib/es2018/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './use-increment';
|
|
|
2
2
|
export * from './use-is-mounted';
|
|
3
3
|
export * from './use-mount';
|
|
4
4
|
export * from './use-single-selection';
|
|
5
|
+
export * from './use-multiple-selection';
|
|
5
6
|
export * from './use-state-cycle';
|
|
6
7
|
export * from './use-toggle';
|
|
7
8
|
export * from './use-resize-observer';
|
package/lib/es2018/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./use-increment"), exports);
|
|
|
18
18
|
__exportStar(require("./use-is-mounted"), exports);
|
|
19
19
|
__exportStar(require("./use-mount"), exports);
|
|
20
20
|
__exportStar(require("./use-single-selection"), exports);
|
|
21
|
+
__exportStar(require("./use-multiple-selection"), exports);
|
|
21
22
|
__exportStar(require("./use-state-cycle"), exports);
|
|
22
23
|
__exportStar(require("./use-toggle"), exports);
|
|
23
24
|
__exportStar(require("./use-resize-observer"), exports);
|
package/lib/es2018/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,mDAAgC;AAChC,8CAA2B;AAC3B,yDAAsC;AACtC,oDAAiC;AACjC,+CAA4B;AAC5B,wDAAqC;AACrC,6CAA0B;AAC1B,qDAAkC;AAClC,6DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,mDAAgC;AAChC,8CAA2B;AAC3B,yDAAsC;AACtC,2DAAwC;AACxC,oDAAiC;AACjC,+CAA4B;AAC5B,wDAAqC;AACrC,6CAA0B;AAC1B,qDAAkC;AAClC,6DAA0C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface IMultipleSelectionOption<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
index: number;
|
|
4
|
+
selected: boolean;
|
|
5
|
+
select(): void;
|
|
6
|
+
unselect(): void;
|
|
7
|
+
toggle(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useMultipleSelection<T>(values: T[], defaultSelectedIndexes?: number[]): {
|
|
10
|
+
values: T[];
|
|
11
|
+
options: Array<IMultipleSelectionOption<T>>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultipleSelection = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const errors_1 = require("@blackglory/errors");
|
|
6
|
+
const iterable_operator_1 = require("iterable-operator");
|
|
7
|
+
function useMultipleSelection(values, defaultSelectedIndexes = []) {
|
|
8
|
+
(0, errors_1.assert)(values.length > 0, 'The parameter values must be a non-empty array');
|
|
9
|
+
for (const index of defaultSelectedIndexes) {
|
|
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
|
+
}
|
|
12
|
+
const [selectedIndexes, setSelectedIndexes] = (0, react_1.useState)(new Set(defaultSelectedIndexes));
|
|
13
|
+
return {
|
|
14
|
+
values: (0, iterable_operator_1.toArray)((0, iterable_operator_1.map)(selectedIndexes, i => values[i])),
|
|
15
|
+
options: values.map((value, index) => {
|
|
16
|
+
const selected = selectedIndexes.has(index);
|
|
17
|
+
const select = () => {
|
|
18
|
+
const set = new Set(selectedIndexes);
|
|
19
|
+
set.add(index);
|
|
20
|
+
setSelectedIndexes(set);
|
|
21
|
+
};
|
|
22
|
+
const unselect = () => {
|
|
23
|
+
const set = new Set(selectedIndexes);
|
|
24
|
+
set.delete(index);
|
|
25
|
+
setSelectedIndexes(set);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
value,
|
|
29
|
+
index,
|
|
30
|
+
selected,
|
|
31
|
+
select,
|
|
32
|
+
unselect,
|
|
33
|
+
toggle: selected ? unselect : select
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.useMultipleSelection = useMultipleSelection;
|
|
39
|
+
//# sourceMappingURL=use-multiple-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multiple-selection.js","sourceRoot":"","sources":["../../src/use-multiple-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,+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;QACL,MAAM,EAAE,IAAA,2BAAO,EAAC,IAAA,uBAAG,EAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,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,CAAA;AACH,CAAC;AA1CD,oDA0CC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface ISingleSelectionOption<T> {
|
|
2
2
|
value: T;
|
|
3
3
|
index: number;
|
|
4
4
|
selected: boolean;
|
|
5
|
-
select
|
|
5
|
+
select(): void;
|
|
6
6
|
}
|
|
7
|
-
export declare function useSingleSelection<T>(values: T[],
|
|
7
|
+
export declare function useSingleSelection<T>(values: T[], defaultSelectedIndex: number): {
|
|
8
8
|
value: T;
|
|
9
|
-
options: Array<
|
|
9
|
+
options: Array<ISingleSelectionOption<T>>;
|
|
10
10
|
};
|
|
11
11
|
export declare function useSingleSelection<T>(values: T[]): {
|
|
12
12
|
value: T | undefined;
|
|
13
|
-
options: Array<
|
|
13
|
+
options: Array<ISingleSelectionOption<T>>;
|
|
14
14
|
};
|
|
15
|
-
export {};
|
|
@@ -4,12 +4,12 @@ exports.useSingleSelection = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const types_1 = require("@blackglory/types");
|
|
6
6
|
const errors_1 = require("@blackglory/errors");
|
|
7
|
-
function useSingleSelection(values,
|
|
7
|
+
function useSingleSelection(values, defaultSelectedIndex) {
|
|
8
8
|
(0, errors_1.assert)(values.length > 0, 'The parameter values must be a non-empty array');
|
|
9
|
-
if ((0, types_1.isntUndefined)(
|
|
10
|
-
(0, errors_1.assert)(
|
|
9
|
+
if ((0, types_1.isntUndefined)(defaultSelectedIndex)) {
|
|
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
|
-
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(
|
|
12
|
+
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(defaultSelectedIndex);
|
|
13
13
|
return {
|
|
14
14
|
value: (0, types_1.isUndefined)(selectedIndex) ? undefined : values[selectedIndex],
|
|
15
15
|
options: values.map((value, index) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,6CAA8D;AAC9D,+CAA2C;
|
|
1
|
+
{"version":3,"file":"use-single-selection.js","sourceRoot":"","sources":["../../src/use-single-selection.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,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;QACL,KAAK,EAAE,IAAA,mBAAW,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QACrE,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,CAAA;AACH,CAAC;AAvBD,gDAuBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-react-hooks",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@blackglory/wait-for": "^0.5.1",
|
|
42
|
-
"@commitlint/cli": "^17.0.
|
|
43
|
-
"@commitlint/config-conventional": "^17.0.
|
|
44
|
-
"@rollup/plugin-commonjs": "^22.0.
|
|
42
|
+
"@commitlint/cli": "^17.0.3",
|
|
43
|
+
"@commitlint/config-conventional": "^17.0.3",
|
|
44
|
+
"@rollup/plugin-commonjs": "^22.0.1",
|
|
45
45
|
"@rollup/plugin-json": "^4.1.0",
|
|
46
46
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
47
47
|
"@rollup/plugin-replace": "^4.0.0",
|
|
@@ -50,24 +50,24 @@
|
|
|
50
50
|
"@testing-library/react-hooks": "^7.0.2",
|
|
51
51
|
"@types/jasmine": "^4.0.0",
|
|
52
52
|
"@types/react": "^17.0.40",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
54
|
-
"@typescript-eslint/parser": "^5.
|
|
55
|
-
"eslint": "^8.
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
|
54
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
55
|
+
"eslint": "^8.20.0",
|
|
56
56
|
"husky": "4",
|
|
57
57
|
"karma": "^6.3.17",
|
|
58
58
|
"karma-chrome-launcher": "^3.1.1",
|
|
59
|
-
"karma-jasmine": "^
|
|
59
|
+
"karma-jasmine": "^5.1.0",
|
|
60
60
|
"karma-webpack": "^5.0.0",
|
|
61
61
|
"npm-run-all": "^4.1.5",
|
|
62
62
|
"react": "^17.0.2",
|
|
63
63
|
"react-dom": "^17.0.2",
|
|
64
64
|
"react-test-renderer": "^17.0.2",
|
|
65
65
|
"rimraf": "^3.0.2",
|
|
66
|
-
"rollup": "^2.
|
|
66
|
+
"rollup": "^2.77.0",
|
|
67
67
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
68
68
|
"rollup-plugin-terser": "^7.0.2",
|
|
69
69
|
"standard-version": "^9.3.2",
|
|
70
|
-
"ts-loader": "^9.
|
|
70
|
+
"ts-loader": "^9.3.1",
|
|
71
71
|
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
72
72
|
"tscpaths": "^0.0.9",
|
|
73
73
|
"tslib": "^2.3.1",
|
|
@@ -78,7 +78,8 @@
|
|
|
78
78
|
"@blackglory/errors": "^2.2.1",
|
|
79
79
|
"@blackglory/structures": "^0.6.0",
|
|
80
80
|
"@blackglory/types": "^1.0.0",
|
|
81
|
-
"
|
|
81
|
+
"iterable-operator": "^1.1.0",
|
|
82
|
+
"rxjs": "^7.5.6"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
85
|
"react": ">= 16.8"
|