@canlooks/can-ui 0.0.200 → 0.0.201
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/dist/cjs/components/cascade/cascade.js +1 -1
- package/dist/cjs/components/selectionContext/selectionContext.d.ts +2 -0
- package/dist/cjs/components/selectionContext/selectionHook.js +10 -17
- package/dist/cjs/components/treeSelect/treeSelect.js +1 -0
- package/dist/esm/components/cascade/cascade.js +1 -1
- package/dist/esm/components/selectionContext/selectionContext.d.ts +2 -0
- package/dist/esm/components/selectionContext/selectionHook.js +10 -17
- package/dist/esm/components/treeSelect/treeSelect.js +1 -0
- package/package.json +1 -1
|
@@ -76,7 +76,6 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
|
|
|
76
76
|
if ((0, utils_1.isNoValue)(value)) {
|
|
77
77
|
return [];
|
|
78
78
|
}
|
|
79
|
-
console.log(142, value.slice(0, -1));
|
|
80
79
|
return value.slice(0, -1);
|
|
81
80
|
});
|
|
82
81
|
const toggleOpenedPanels = (value, index) => {
|
|
@@ -132,6 +131,7 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
|
|
|
132
131
|
};
|
|
133
132
|
const actualOptions = innerOptions || options;
|
|
134
133
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, selectionStatus, optionsMap } = (0, selectionContext_1.useSelection)({
|
|
134
|
+
standalone: true,
|
|
135
135
|
options: actualOptions,
|
|
136
136
|
multiple,
|
|
137
137
|
value: toStandardValue(pathifiedValue.current),
|
|
@@ -32,6 +32,8 @@ export type SelectionContextBaseProps<O extends OptionType<V>, V extends Id = Id
|
|
|
32
32
|
disabled?: boolean;
|
|
33
33
|
onToggle?(checked: boolean, value: V, option?: O): void;
|
|
34
34
|
children?: ReactNode;
|
|
35
|
+
/** 若设为true,则该Context不受父级Context影响,默认为`false` */
|
|
36
|
+
standalone?: boolean;
|
|
35
37
|
};
|
|
36
38
|
export type ISelectionContext<O extends OptionType<V>, V extends Id = Id> = {
|
|
37
39
|
inSelection: true;
|
|
@@ -19,15 +19,12 @@ function useSelection({ ...props }) {
|
|
|
19
19
|
* 若嵌套在另个一SelectionContext内,取最外层数据
|
|
20
20
|
*/
|
|
21
21
|
const context = (0, selectionContext_1.useSelectionContext)();
|
|
22
|
-
if (context.inSelection) {
|
|
22
|
+
if (!props.standalone && context.inSelection) {
|
|
23
23
|
innerValue.current = context.value;
|
|
24
24
|
setInnerValue = context.setValue;
|
|
25
25
|
innerOptions.current = context.options;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
if (context.inSelection) {
|
|
29
|
-
return context.optionsMap;
|
|
30
|
-
}
|
|
27
|
+
const _optionsMap = (0, react_1.useMemo)(() => {
|
|
31
28
|
const map = new Map();
|
|
32
29
|
const fn = (arr, parentId) => {
|
|
33
30
|
// 有时arr可能不为数组,需要判断,如DataGrid组件的row.children
|
|
@@ -41,7 +38,8 @@ function useSelection({ ...props }) {
|
|
|
41
38
|
};
|
|
42
39
|
fn(innerOptions.current);
|
|
43
40
|
return map;
|
|
44
|
-
}, [innerOptions.current, props.primaryKey, props.childrenKey
|
|
41
|
+
}, [innerOptions.current, props.primaryKey, props.childrenKey]);
|
|
42
|
+
const optionsMap = !props.standalone && context.inSelection ? context.optionsMap : _optionsMap;
|
|
45
43
|
const syncOptionsMap = (0, utils_1.useSync)(optionsMap);
|
|
46
44
|
const syncProps = (0, utils_1.useSync)(props);
|
|
47
45
|
const calSelectionStatus = (selectedSet = new Set((0, utils_1.toArray)(innerValue.current))) => {
|
|
@@ -84,21 +82,15 @@ function useSelection({ ...props }) {
|
|
|
84
82
|
return map;
|
|
85
83
|
};
|
|
86
84
|
const preCalSelectionStatus = (0, react_1.useRef)(void 0);
|
|
87
|
-
const
|
|
88
|
-
if (context.inSelection) {
|
|
89
|
-
return context.selectionStatus;
|
|
90
|
-
}
|
|
85
|
+
const _selectionStatus = (0, react_1.useMemo)(() => {
|
|
91
86
|
// 调用toggleSelected()方法后可能会预先计算selectionStatus
|
|
92
87
|
const ret = preCalSelectionStatus.current || calSelectionStatus();
|
|
93
88
|
preCalSelectionStatus.current = void 0;
|
|
94
89
|
return ret;
|
|
95
|
-
}, [innerValue.current, optionsMap, props.multiple, props.relation
|
|
90
|
+
}, [innerValue.current, optionsMap, props.multiple, props.relation]);
|
|
91
|
+
const selectionStatus = !props.standalone && context.inSelection ? context.selectionStatus : _selectionStatus;
|
|
96
92
|
const syncSelectionStatus = (0, utils_1.useSync)(selectionStatus);
|
|
97
|
-
const
|
|
98
|
-
if (context.inSelection) {
|
|
99
|
-
context.toggleSelected(value);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
93
|
+
const _toggleSelected = (0, react_1.useCallback)((value) => {
|
|
102
94
|
if (syncProps.current.disabled) {
|
|
103
95
|
return;
|
|
104
96
|
}
|
|
@@ -190,7 +182,8 @@ function useSelection({ ...props }) {
|
|
|
190
182
|
children && loopOptions(callback, children, ret);
|
|
191
183
|
});
|
|
192
184
|
}
|
|
193
|
-
}, [
|
|
185
|
+
}, []);
|
|
186
|
+
const toggleSelected = !props.standalone && context.inSelection ? context.toggleSelected : _toggleSelected;
|
|
194
187
|
return {
|
|
195
188
|
inSelection: true,
|
|
196
189
|
multiple: props.multiple,
|
|
@@ -39,6 +39,7 @@ value, onChange, renderBackfill, ...props }) => {
|
|
|
39
39
|
return fn(react_1.Children.toArray(children));
|
|
40
40
|
}, [options, nodes, children]);
|
|
41
41
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, optionsMap } = (0, selectionContext_1.useSelection)({
|
|
42
|
+
standalone: true,
|
|
42
43
|
options: actualOptions,
|
|
43
44
|
primaryKey,
|
|
44
45
|
childrenKey,
|
|
@@ -72,7 +72,6 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
|
|
|
72
72
|
if (isNoValue(value)) {
|
|
73
73
|
return [];
|
|
74
74
|
}
|
|
75
|
-
console.log(142, value.slice(0, -1));
|
|
76
75
|
return value.slice(0, -1);
|
|
77
76
|
});
|
|
78
77
|
const toggleOpenedPanels = (value, index) => {
|
|
@@ -128,6 +127,7 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
|
|
|
128
127
|
};
|
|
129
128
|
const actualOptions = innerOptions || options;
|
|
130
129
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, selectionStatus, optionsMap } = useSelection({
|
|
130
|
+
standalone: true,
|
|
131
131
|
options: actualOptions,
|
|
132
132
|
multiple,
|
|
133
133
|
value: toStandardValue(pathifiedValue.current),
|
|
@@ -32,6 +32,8 @@ export type SelectionContextBaseProps<O extends OptionType<V>, V extends Id = Id
|
|
|
32
32
|
disabled?: boolean;
|
|
33
33
|
onToggle?(checked: boolean, value: V, option?: O): void;
|
|
34
34
|
children?: ReactNode;
|
|
35
|
+
/** 若设为true,则该Context不受父级Context影响,默认为`false` */
|
|
36
|
+
standalone?: boolean;
|
|
35
37
|
};
|
|
36
38
|
export type ISelectionContext<O extends OptionType<V>, V extends Id = Id> = {
|
|
37
39
|
inSelection: true;
|
|
@@ -15,15 +15,12 @@ export function useSelection({ ...props }) {
|
|
|
15
15
|
* 若嵌套在另个一SelectionContext内,取最外层数据
|
|
16
16
|
*/
|
|
17
17
|
const context = useSelectionContext();
|
|
18
|
-
if (context.inSelection) {
|
|
18
|
+
if (!props.standalone && context.inSelection) {
|
|
19
19
|
innerValue.current = context.value;
|
|
20
20
|
setInnerValue = context.setValue;
|
|
21
21
|
innerOptions.current = context.options;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
if (context.inSelection) {
|
|
25
|
-
return context.optionsMap;
|
|
26
|
-
}
|
|
23
|
+
const _optionsMap = useMemo(() => {
|
|
27
24
|
const map = new Map();
|
|
28
25
|
const fn = (arr, parentId) => {
|
|
29
26
|
// 有时arr可能不为数组,需要判断,如DataGrid组件的row.children
|
|
@@ -37,7 +34,8 @@ export function useSelection({ ...props }) {
|
|
|
37
34
|
};
|
|
38
35
|
fn(innerOptions.current);
|
|
39
36
|
return map;
|
|
40
|
-
}, [innerOptions.current, props.primaryKey, props.childrenKey
|
|
37
|
+
}, [innerOptions.current, props.primaryKey, props.childrenKey]);
|
|
38
|
+
const optionsMap = !props.standalone && context.inSelection ? context.optionsMap : _optionsMap;
|
|
41
39
|
const syncOptionsMap = useSync(optionsMap);
|
|
42
40
|
const syncProps = useSync(props);
|
|
43
41
|
const calSelectionStatus = (selectedSet = new Set(toArray(innerValue.current))) => {
|
|
@@ -80,21 +78,15 @@ export function useSelection({ ...props }) {
|
|
|
80
78
|
return map;
|
|
81
79
|
};
|
|
82
80
|
const preCalSelectionStatus = useRef(void 0);
|
|
83
|
-
const
|
|
84
|
-
if (context.inSelection) {
|
|
85
|
-
return context.selectionStatus;
|
|
86
|
-
}
|
|
81
|
+
const _selectionStatus = useMemo(() => {
|
|
87
82
|
// 调用toggleSelected()方法后可能会预先计算selectionStatus
|
|
88
83
|
const ret = preCalSelectionStatus.current || calSelectionStatus();
|
|
89
84
|
preCalSelectionStatus.current = void 0;
|
|
90
85
|
return ret;
|
|
91
|
-
}, [innerValue.current, optionsMap, props.multiple, props.relation
|
|
86
|
+
}, [innerValue.current, optionsMap, props.multiple, props.relation]);
|
|
87
|
+
const selectionStatus = !props.standalone && context.inSelection ? context.selectionStatus : _selectionStatus;
|
|
92
88
|
const syncSelectionStatus = useSync(selectionStatus);
|
|
93
|
-
const
|
|
94
|
-
if (context.inSelection) {
|
|
95
|
-
context.toggleSelected(value);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
89
|
+
const _toggleSelected = useCallback((value) => {
|
|
98
90
|
if (syncProps.current.disabled) {
|
|
99
91
|
return;
|
|
100
92
|
}
|
|
@@ -186,7 +178,8 @@ export function useSelection({ ...props }) {
|
|
|
186
178
|
children && loopOptions(callback, children, ret);
|
|
187
179
|
});
|
|
188
180
|
}
|
|
189
|
-
}, [
|
|
181
|
+
}, []);
|
|
182
|
+
const toggleSelected = !props.standalone && context.inSelection ? context.toggleSelected : _toggleSelected;
|
|
190
183
|
return {
|
|
191
184
|
inSelection: true,
|
|
192
185
|
multiple: props.multiple,
|
|
@@ -36,6 +36,7 @@ value, onChange, renderBackfill, ...props }) => {
|
|
|
36
36
|
return fn(Children.toArray(children));
|
|
37
37
|
}, [options, nodes, children]);
|
|
38
38
|
const { value: innerValue, setValue: setInnerValue, toggleSelected, optionsMap } = useSelection({
|
|
39
|
+
standalone: true,
|
|
39
40
|
options: actualOptions,
|
|
40
41
|
primaryKey,
|
|
41
42
|
childrenKey,
|