@canlooks/can-ui 0.0.200 → 0.0.202
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/dataGrid/dataGrid.d.ts +2 -1
- package/dist/cjs/components/dataGrid/dataGrid.js +2 -2
- package/dist/cjs/components/pickerDialog/pickerDialog.d.ts +5 -7
- package/dist/cjs/components/pickerDialog/pickerDialog.js +11 -16
- 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/dataGrid/dataGrid.d.ts +2 -1
- package/dist/esm/components/dataGrid/dataGrid.js +2 -2
- package/dist/esm/components/pickerDialog/pickerDialog.d.ts +5 -7
- package/dist/esm/components/pickerDialog/pickerDialog.js +12 -17
- 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),
|
|
@@ -72,7 +72,7 @@ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps
|
|
|
72
72
|
renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
|
|
73
73
|
}
|
|
74
74
|
export type OrderType = 'ascend' | 'descend';
|
|
75
|
-
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
|
|
75
|
+
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onToggle' | 'onChange'> {
|
|
76
76
|
columns?: (ColumnType<R> | symbol)[];
|
|
77
77
|
rows?: R[];
|
|
78
78
|
filterProps?: FormProps;
|
|
@@ -99,6 +99,7 @@ export interface DataGridBaseProps<R extends RowType = RowType> extends DataGrid
|
|
|
99
99
|
/** 是否允许全选,默认为true */
|
|
100
100
|
allowSelectAll?: boolean;
|
|
101
101
|
selectorProps?(row: R, index: number, rows: R[]): CheckboxProps | RadioProps;
|
|
102
|
+
onToggle?(checked: boolean, value: Id, option?: R): void;
|
|
102
103
|
defaultExpanded?: Id[];
|
|
103
104
|
expanded?: Id[];
|
|
104
105
|
onExpandedChange?(expanded: Id[], key: Id, isExpand: boolean): void;
|
|
@@ -19,7 +19,7 @@ const DataGridContext = (0, react_1.createContext)({});
|
|
|
19
19
|
function useDataGridContext() {
|
|
20
20
|
return (0, react_1.useContext)(DataGridContext);
|
|
21
21
|
}
|
|
22
|
-
exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
22
|
+
exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, onToggle, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
23
23
|
/**
|
|
24
24
|
* ---------------------------------------------------------------
|
|
25
25
|
* 选择行
|
|
@@ -135,7 +135,7 @@ exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProp
|
|
|
135
135
|
const renderedContent = ((0, jsx_runtime_1.jsx)(columnResize_1.ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => (0, jsx_runtime_1.jsxs)(Container, { ...(0, utils_1.mergeComponentProps)(containerProps, {
|
|
136
136
|
ref: scrollerRef,
|
|
137
137
|
className: dataGrid_style_1.classes.container
|
|
138
|
-
}), children: [(0, jsx_runtime_1.jsx)(table_1.Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: (0, utils_1.cloneRef)(tableProps?.ref, tableRef), children: (0, jsx_runtime_1.jsxs)(selectionContext_1.SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [(0, jsx_runtime_1.jsx)(dataGridHead_1.DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsx)(DataGridContext, { value: (0, react_1.useMemo)(() => ({
|
|
138
|
+
}), children: [(0, jsx_runtime_1.jsx)(table_1.Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: (0, utils_1.cloneRef)(tableProps?.ref, tableRef), children: (0, jsx_runtime_1.jsxs)(selectionContext_1.SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, onToggle: onToggle, children: [(0, jsx_runtime_1.jsx)(dataGridHead_1.DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsx)(DataGridContext, { value: (0, react_1.useMemo)(() => ({
|
|
139
139
|
slots, slotProps,
|
|
140
140
|
rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
|
|
141
141
|
expandedSet, flattedColumns, toggleExpanded
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { ReactElement,
|
|
1
|
+
import { ReactElement, Ref } from 'react';
|
|
2
2
|
import { DialogProps } from '../dialog';
|
|
3
3
|
import { OptionType, SelectionContextBaseProps } from '../selectionContext';
|
|
4
4
|
import { SelectedListProps } from '../selectedList';
|
|
5
|
-
import { Id } from '../../types';
|
|
5
|
+
import { Id, SelectableProps } from '../../types';
|
|
6
6
|
export type PickerDialogRef<V extends Id = Id> = {
|
|
7
7
|
open(value?: V | V[]): Promise<V | V[]>;
|
|
8
8
|
};
|
|
9
|
-
export interface
|
|
9
|
+
export interface PickerDialogBaseProps<O extends OptionType<V>, V extends Id = Id> extends Omit<DialogProps, 'ref' | 'onConfirm' | 'onToggle' | 'onChange'>, SelectionContextBaseProps<O, V> {
|
|
10
10
|
ref?: Ref<PickerDialogRef<V>>;
|
|
11
11
|
/** 默认的ref已被PickerDialogRef取代,需要dialogRef指向dialog元素 */
|
|
12
12
|
dialogRef?: Ref<HTMLDivElement>;
|
|
13
|
-
multiple?: boolean;
|
|
14
|
-
children?: ReactNode | ((selectionProps: Omit<SelectionContextBaseProps<O, V>, 'children'> & {
|
|
15
|
-
multiple?: boolean;
|
|
16
|
-
}) => ReactNode);
|
|
17
13
|
showSelectedList?: boolean;
|
|
18
14
|
/** 已选列表的位置,默认为`right` */
|
|
19
15
|
selectedListPlacement?: 'left' | 'right';
|
|
20
16
|
selectedListProps?: SelectedListProps<V>;
|
|
21
17
|
selectedItemProps?: SelectedListProps<V>['itemProps'];
|
|
22
18
|
onConfirm?(value: V | V[]): void;
|
|
19
|
+
onClear?(): void;
|
|
23
20
|
/** @alias {@link options} */
|
|
24
21
|
rows?: O[];
|
|
25
22
|
/** @alias {@link options} */
|
|
26
23
|
nodes?: O[];
|
|
27
24
|
}
|
|
25
|
+
export type PickerDialogProps<O extends OptionType<V>, V extends Id = Id> = PickerDialogBaseProps<O, V> & SelectableProps<V>;
|
|
28
26
|
export declare const PickerDialog: <O extends OptionType<V>, V extends Id = Id>(props: PickerDialogProps<O, V>) => ReactElement;
|
|
@@ -12,9 +12,9 @@ const selectedList_1 = require("../selectedList");
|
|
|
12
12
|
const button_1 = require("../button");
|
|
13
13
|
const icon_1 = require("../icon");
|
|
14
14
|
const faTrashCan_1 = require("@fortawesome/free-regular-svg-icons/faTrashCan");
|
|
15
|
-
exports.PickerDialog = (({ ref, dialogRef, multiple,
|
|
16
|
-
// 以下属性从
|
|
17
|
-
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, ...props }) => {
|
|
15
|
+
exports.PickerDialog = (({ ref, dialogRef, multiple, showSelectedList = !!multiple, selectedListPlacement = 'right', selectedListProps, selectedItemProps, onConfirm, onClear, rows, nodes,
|
|
16
|
+
// 以下属性从SelectionContextProps继承
|
|
17
|
+
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, defaultValue, value, onChange, ...props }) => {
|
|
18
18
|
const resolvers = (0, react_1.useRef)(void 0);
|
|
19
19
|
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
20
20
|
open(value) {
|
|
@@ -30,6 +30,12 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
30
30
|
// 单选模式,值每次改变都触发确认
|
|
31
31
|
!multiple && confirmHandler(value);
|
|
32
32
|
};
|
|
33
|
+
const clearHandler = () => {
|
|
34
|
+
onClear?.();
|
|
35
|
+
const newValue = multiple ? [] : null;
|
|
36
|
+
onChange?.(newValue);
|
|
37
|
+
setInnerValue(newValue);
|
|
38
|
+
};
|
|
33
39
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(props.defaultOpen, props.open);
|
|
34
40
|
const closeHandler = (reason) => {
|
|
35
41
|
if (reason === 'confirmed') {
|
|
@@ -52,17 +58,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
52
58
|
const onExited = () => {
|
|
53
59
|
_setInnerValue(null);
|
|
54
60
|
};
|
|
55
|
-
const renderChildren = () => {
|
|
56
|
-
const selectionProps = { rows, nodes, options, primaryKey, relation, integration, disabled, multiple };
|
|
57
|
-
return typeof children === 'function'
|
|
58
|
-
? children(selectionProps)
|
|
59
|
-
: (0, react_1.isValidElement)(children)
|
|
60
|
-
? (0, react_1.cloneElement)(children, {
|
|
61
|
-
...selectionProps,
|
|
62
|
-
...children.props
|
|
63
|
-
})
|
|
64
|
-
: children;
|
|
65
|
-
};
|
|
66
61
|
const selectedCount = (0, utils_1.toArray)(innerValue)?.length || 0;
|
|
67
62
|
return ((0, jsx_runtime_1.jsx)(selectionContext_1.SelectionContext, { options,
|
|
68
63
|
primaryKey,
|
|
@@ -83,6 +78,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
83
78
|
modalProps: (0, utils_1.mergeComponentProps)(props.modalProps, { onExited })
|
|
84
79
|
}), onClose: closeHandler, ...showSelectedList && {
|
|
85
80
|
[selectedListPlacement === 'left' ? 'prefix' : 'suffix']: ((0, jsx_runtime_1.jsxs)("div", { className: pickerDialog_style_1.classes.selectedArea, children: [(0, jsx_runtime_1.jsxs)(divider_1.Divider, { className: pickerDialog_style_1.classes.count, textAlign: "start", children: [(0, jsx_runtime_1.jsxs)("div", { children: ["\u5DF2\u9009\u62E9", (0, jsx_runtime_1.jsx)("b", { children: selectedCount }), "\u9879"] }), clearable &&
|
|
86
|
-
(0, jsx_runtime_1.jsx)(button_1.Button, { prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faTrashCan_1.faTrashCan }), variant: "plain", color: "text.secondary", onClick:
|
|
87
|
-
}, children:
|
|
81
|
+
(0, jsx_runtime_1.jsx)(button_1.Button, { prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faTrashCan_1.faTrashCan }), variant: "plain", color: "text.secondary", onClick: clearHandler, children: "\u6E05\u7A7A" })] }), (0, jsx_runtime_1.jsx)(selectedList_1.SelectedList, { itemProps: selectedItemProps, ...selectedListProps, className: (0, utils_1.clsx)(pickerDialog_style_1.classes.list, selectedListProps?.className) }), (0, jsx_runtime_1.jsx)(button_1.Button, { className: pickerDialog_style_1.classes.confirm, disabled: selectedCount === 0, onClick: () => confirmHandler(), children: "\u786E\u5B9A" })] }))
|
|
82
|
+
}, children: props.children }) }));
|
|
88
83
|
});
|
|
@@ -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),
|
|
@@ -72,7 +72,7 @@ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps
|
|
|
72
72
|
renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
|
|
73
73
|
}
|
|
74
74
|
export type OrderType = 'ascend' | 'descend';
|
|
75
|
-
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
|
|
75
|
+
export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onToggle' | 'onChange'> {
|
|
76
76
|
columns?: (ColumnType<R> | symbol)[];
|
|
77
77
|
rows?: R[];
|
|
78
78
|
filterProps?: FormProps;
|
|
@@ -99,6 +99,7 @@ export interface DataGridBaseProps<R extends RowType = RowType> extends DataGrid
|
|
|
99
99
|
/** 是否允许全选,默认为true */
|
|
100
100
|
allowSelectAll?: boolean;
|
|
101
101
|
selectorProps?(row: R, index: number, rows: R[]): CheckboxProps | RadioProps;
|
|
102
|
+
onToggle?(checked: boolean, value: Id, option?: R): void;
|
|
102
103
|
defaultExpanded?: Id[];
|
|
103
104
|
expanded?: Id[];
|
|
104
105
|
onExpandedChange?(expanded: Id[], key: Id, isExpand: boolean): void;
|
|
@@ -15,7 +15,7 @@ const DataGridContext = createContext({});
|
|
|
15
15
|
export function useDataGridContext() {
|
|
16
16
|
return useContext(DataGridContext);
|
|
17
17
|
}
|
|
18
|
-
export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
18
|
+
export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, filterBubbleProps, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, onToggle, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, _noRenderFormTag = false, multiple, defaultValue, value, onChange, ...props }) => {
|
|
19
19
|
/**
|
|
20
20
|
* ---------------------------------------------------------------
|
|
21
21
|
* 选择行
|
|
@@ -131,7 +131,7 @@ export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, prima
|
|
|
131
131
|
const renderedContent = (_jsx(ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => _jsxs(Container, { ...mergeComponentProps(containerProps, {
|
|
132
132
|
ref: scrollerRef,
|
|
133
133
|
className: classes.container
|
|
134
|
-
}), children: [_jsx(Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: cloneRef(tableProps?.ref, tableRef), children: _jsxs(SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [_jsx(DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), _jsx("tbody", { children: _jsx(DataGridContext, { value: useMemo(() => ({
|
|
134
|
+
}), children: [_jsx(Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: cloneRef(tableProps?.ref, tableRef), children: _jsxs(SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, onToggle: onToggle, children: [_jsx(DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, filterBubbleProps: filterBubbleProps, onFilterClick: onFilterClick }), _jsx("tbody", { children: _jsx(DataGridContext, { value: useMemo(() => ({
|
|
135
135
|
slots, slotProps,
|
|
136
136
|
rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
|
|
137
137
|
expandedSet, flattedColumns, toggleExpanded
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { ReactElement,
|
|
1
|
+
import { ReactElement, Ref } from 'react';
|
|
2
2
|
import { DialogProps } from '../dialog/index.js';
|
|
3
3
|
import { OptionType, SelectionContextBaseProps } from '../selectionContext/index.js';
|
|
4
4
|
import { SelectedListProps } from '../selectedList/index.js';
|
|
5
|
-
import { Id } from '../../types.js';
|
|
5
|
+
import { Id, SelectableProps } from '../../types.js';
|
|
6
6
|
export type PickerDialogRef<V extends Id = Id> = {
|
|
7
7
|
open(value?: V | V[]): Promise<V | V[]>;
|
|
8
8
|
};
|
|
9
|
-
export interface
|
|
9
|
+
export interface PickerDialogBaseProps<O extends OptionType<V>, V extends Id = Id> extends Omit<DialogProps, 'ref' | 'onConfirm' | 'onToggle' | 'onChange'>, SelectionContextBaseProps<O, V> {
|
|
10
10
|
ref?: Ref<PickerDialogRef<V>>;
|
|
11
11
|
/** 默认的ref已被PickerDialogRef取代,需要dialogRef指向dialog元素 */
|
|
12
12
|
dialogRef?: Ref<HTMLDivElement>;
|
|
13
|
-
multiple?: boolean;
|
|
14
|
-
children?: ReactNode | ((selectionProps: Omit<SelectionContextBaseProps<O, V>, 'children'> & {
|
|
15
|
-
multiple?: boolean;
|
|
16
|
-
}) => ReactNode);
|
|
17
13
|
showSelectedList?: boolean;
|
|
18
14
|
/** 已选列表的位置,默认为`right` */
|
|
19
15
|
selectedListPlacement?: 'left' | 'right';
|
|
20
16
|
selectedListProps?: SelectedListProps<V>;
|
|
21
17
|
selectedItemProps?: SelectedListProps<V>['itemProps'];
|
|
22
18
|
onConfirm?(value: V | V[]): void;
|
|
19
|
+
onClear?(): void;
|
|
23
20
|
/** @alias {@link options} */
|
|
24
21
|
rows?: O[];
|
|
25
22
|
/** @alias {@link options} */
|
|
26
23
|
nodes?: O[];
|
|
27
24
|
}
|
|
25
|
+
export type PickerDialogProps<O extends OptionType<V>, V extends Id = Id> = PickerDialogBaseProps<O, V> & SelectableProps<V>;
|
|
28
26
|
export declare const PickerDialog: <O extends OptionType<V>, V extends Id = Id>(props: PickerDialogProps<O, V>) => ReactElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useImperativeHandle, useRef, useState } from 'react';
|
|
3
3
|
import { Dialog } from '../dialog/index.js';
|
|
4
4
|
import { clsx, mergeComponentProps, toArray, useControlled } from '../../utils/index.js';
|
|
5
5
|
import { classes, style } from './pickerDialog.style.js';
|
|
@@ -9,9 +9,9 @@ import { SelectedList } from '../selectedList/index.js';
|
|
|
9
9
|
import { Button } from '../button/index.js';
|
|
10
10
|
import { Icon } from '../icon/index.js';
|
|
11
11
|
import { faTrashCan } from '@fortawesome/free-regular-svg-icons/faTrashCan';
|
|
12
|
-
export const PickerDialog = (({ ref, dialogRef, multiple,
|
|
13
|
-
// 以下属性从
|
|
14
|
-
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, ...props }) => {
|
|
12
|
+
export const PickerDialog = (({ ref, dialogRef, multiple, showSelectedList = !!multiple, selectedListPlacement = 'right', selectedListProps, selectedItemProps, onConfirm, onClear, rows, nodes,
|
|
13
|
+
// 以下属性从SelectionContextProps继承
|
|
14
|
+
options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', disabled, clearable = !!multiple, onToggle, defaultValue, value, onChange, ...props }) => {
|
|
15
15
|
const resolvers = useRef(void 0);
|
|
16
16
|
useImperativeHandle(ref, () => ({
|
|
17
17
|
open(value) {
|
|
@@ -27,6 +27,12 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
27
27
|
// 单选模式,值每次改变都触发确认
|
|
28
28
|
!multiple && confirmHandler(value);
|
|
29
29
|
};
|
|
30
|
+
const clearHandler = () => {
|
|
31
|
+
onClear?.();
|
|
32
|
+
const newValue = multiple ? [] : null;
|
|
33
|
+
onChange?.(newValue);
|
|
34
|
+
setInnerValue(newValue);
|
|
35
|
+
};
|
|
30
36
|
const [innerOpen, setInnerOpen] = useControlled(props.defaultOpen, props.open);
|
|
31
37
|
const closeHandler = (reason) => {
|
|
32
38
|
if (reason === 'confirmed') {
|
|
@@ -49,17 +55,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
49
55
|
const onExited = () => {
|
|
50
56
|
_setInnerValue(null);
|
|
51
57
|
};
|
|
52
|
-
const renderChildren = () => {
|
|
53
|
-
const selectionProps = { rows, nodes, options, primaryKey, relation, integration, disabled, multiple };
|
|
54
|
-
return typeof children === 'function'
|
|
55
|
-
? children(selectionProps)
|
|
56
|
-
: isValidElement(children)
|
|
57
|
-
? cloneElement(children, {
|
|
58
|
-
...selectionProps,
|
|
59
|
-
...children.props
|
|
60
|
-
})
|
|
61
|
-
: children;
|
|
62
|
-
};
|
|
63
58
|
const selectedCount = toArray(innerValue)?.length || 0;
|
|
64
59
|
return (_jsx(SelectionContext, { options,
|
|
65
60
|
primaryKey,
|
|
@@ -80,6 +75,6 @@ options = rows ?? nodes, primaryKey = 'id', childrenKey = 'children', relation =
|
|
|
80
75
|
modalProps: mergeComponentProps(props.modalProps, { onExited })
|
|
81
76
|
}), onClose: closeHandler, ...showSelectedList && {
|
|
82
77
|
[selectedListPlacement === 'left' ? 'prefix' : 'suffix']: (_jsxs("div", { className: classes.selectedArea, children: [_jsxs(Divider, { className: classes.count, textAlign: "start", children: [_jsxs("div", { children: ["\u5DF2\u9009\u62E9", _jsx("b", { children: selectedCount }), "\u9879"] }), clearable &&
|
|
83
|
-
_jsx(Button, { prefix: _jsx(Icon, { icon: faTrashCan }), variant: "plain", color: "text.secondary", onClick:
|
|
84
|
-
}, children:
|
|
78
|
+
_jsx(Button, { prefix: _jsx(Icon, { icon: faTrashCan }), variant: "plain", color: "text.secondary", onClick: clearHandler, children: "\u6E05\u7A7A" })] }), _jsx(SelectedList, { itemProps: selectedItemProps, ...selectedListProps, className: clsx(classes.list, selectedListProps?.className) }), _jsx(Button, { className: classes.confirm, disabled: selectedCount === 0, onClick: () => confirmHandler(), children: "\u786E\u5B9A" })] }))
|
|
79
|
+
}, children: props.children }) }));
|
|
85
80
|
});
|
|
@@ -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,
|