@wzyjs/uis 0.3.28 → 0.3.30
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/advanced/Com2Canvas/index.d.ts +8 -0
- package/dist/advanced/Com2Canvas/index.js +39 -0
- package/dist/advanced/Crud/components/CardList/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CardList/index.js +90 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.js +78 -0
- package/dist/advanced/Crud/components/ListTabs/index.d.ts +8 -0
- package/dist/advanced/Crud/components/ListTabs/index.js +7 -0
- package/dist/advanced/Crud/components/Provider/index.d.ts +7 -0
- package/dist/advanced/Crud/components/Provider/index.js +42 -0
- package/dist/advanced/Crud/components/QuickFilters/index.d.ts +8 -0
- package/dist/advanced/Crud/components/QuickFilters/index.js +20 -0
- package/dist/advanced/Crud/components/Remove/index.d.ts +2 -0
- package/dist/advanced/Crud/components/Remove/index.js +18 -0
- package/dist/advanced/Crud/components/index.d.ts +6 -0
- package/dist/advanced/Crud/components/index.js +6 -0
- package/dist/advanced/Crud/hooks/index.d.ts +5 -0
- package/dist/advanced/Crud/hooks/index.js +5 -0
- package/dist/advanced/Crud/hooks/useColumns.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useColumns.js +111 -0
- package/dist/advanced/Crud/hooks/useList.d.ts +12 -0
- package/dist/advanced/Crud/hooks/useList.js +53 -0
- package/dist/advanced/Crud/hooks/useListFilters.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useListFilters.js +159 -0
- package/dist/advanced/Crud/hooks/useOrderable.d.ts +15 -0
- package/dist/advanced/Crud/hooks/useOrderable.js +75 -0
- package/dist/advanced/Crud/hooks/useRequest.d.ts +13 -0
- package/dist/advanced/Crud/hooks/useRequest.js +27 -0
- package/dist/advanced/Crud/index.d.ts +3 -0
- package/dist/advanced/Crud/index.js +46 -0
- package/dist/advanced/Crud/types/index.d.ts +176 -0
- package/dist/advanced/Crud/types/index.js +1 -0
- package/dist/advanced/Crud/utils/index.d.ts +7 -0
- package/dist/advanced/Crud/utils/index.js +80 -0
- package/dist/advanced/Crud/utils/query.d.ts +3 -0
- package/dist/advanced/Crud/utils/query.js +34 -0
- package/dist/advanced/MindMap/context.d.ts +12 -0
- package/dist/advanced/MindMap/context.js +12 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.d.ts +15 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.js +164 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.d.ts +11 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.js +209 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.d.ts +21 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.js +216 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.d.ts +18 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.js +108 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.d.ts +12 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.js +98 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.d.ts +14 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.js +181 -0
- package/dist/advanced/MindMap/index.d.ts +29 -0
- package/dist/advanced/MindMap/index.js +52 -0
- package/dist/advanced/index.d.ts +5 -0
- package/dist/advanced/index.js +5 -0
- package/dist/antd/index.d.ts +6 -0
- package/dist/antd/index.js +5 -0
- package/dist/buttons/ButtonGroup/index.d.ts +8 -0
- package/dist/buttons/ButtonGroup/index.js +13 -0
- package/dist/buttons/ConfirmButton/index.d.ts +5 -0
- package/dist/buttons/ConfirmButton/index.js +9 -0
- package/dist/buttons/CopyButton/index.d.ts +6 -0
- package/dist/buttons/CopyButton/index.js +26 -0
- package/dist/buttons/DrawerButton/index.d.ts +6 -0
- package/dist/buttons/DrawerButton/index.js +13 -0
- package/dist/buttons/ProgressButton/index.css +63 -0
- package/dist/buttons/ProgressButton/index.d.ts +17 -0
- package/dist/buttons/ProgressButton/index.js +31 -0
- package/dist/buttons/SectorButton/index.d.ts +20 -0
- package/dist/buttons/SectorButton/index.js +130 -0
- package/dist/buttons/index.d.ts +6 -0
- package/dist/buttons/index.js +6 -0
- package/dist/display/CodeView/index.d.ts +26 -0
- package/dist/display/CodeView/index.js +60 -0
- package/dist/display/EnumTag/index.d.ts +12 -0
- package/dist/display/EnumTag/index.js +10 -0
- package/dist/display/HtmlDataRenderer/index.d.ts +6 -0
- package/dist/display/HtmlDataRenderer/index.js +15 -0
- package/dist/display/HtmlView/index.d.ts +6 -0
- package/dist/display/HtmlView/index.js +6 -0
- package/dist/display/IframePro/index.d.ts +8 -0
- package/dist/display/IframePro/index.js +24 -0
- package/dist/display/JsonSchemaRenderer/index.d.ts +11 -0
- package/dist/display/JsonSchemaRenderer/index.js +62 -0
- package/dist/display/JsonView/index.d.ts +3 -0
- package/dist/display/JsonView/index.js +7 -0
- package/dist/display/MarkdownView/index.d.ts +7 -0
- package/dist/display/MarkdownView/index.js +80 -0
- package/dist/display/MarkdownView/style.d.ts +1 -0
- package/{src/components/Markdown/style.ts → dist/display/MarkdownView/style.js} +1 -1
- package/dist/display/VideoPro/index.d.ts +9 -0
- package/dist/display/VideoPro/index.js +15 -0
- package/dist/display/index.d.ts +9 -0
- package/dist/display/index.js +9 -0
- package/dist/inputs/CheckboxButton/index.css +22 -0
- package/dist/inputs/CheckboxButton/index.d.ts +12 -0
- package/dist/inputs/CheckboxButton/index.js +9 -0
- package/dist/inputs/DateSwitcher/index.css +10 -0
- package/dist/inputs/DateSwitcher/index.d.ts +8 -0
- package/dist/inputs/DateSwitcher/index.js +29 -0
- package/dist/inputs/FetchSelect/index.d.ts +3 -0
- package/dist/inputs/FetchSelect/index.js +121 -0
- package/dist/inputs/FetchSelect/types.d.ts +33 -0
- package/dist/inputs/FetchSelect/types.js +1 -0
- package/dist/inputs/FetchSelect/utils.d.ts +21 -0
- package/dist/inputs/FetchSelect/utils.js +67 -0
- package/dist/inputs/FileUploader/index.d.ts +22 -0
- package/dist/inputs/FileUploader/index.js +79 -0
- package/dist/inputs/IconSelect/index.d.ts +89 -0
- package/dist/inputs/IconSelect/index.js +54 -0
- package/dist/inputs/ImageUploader/index.d.ts +12 -0
- package/dist/inputs/ImageUploader/index.js +192 -0
- package/dist/inputs/RadioButton/index.d.ts +15 -0
- package/dist/inputs/RadioButton/index.js +11 -0
- package/dist/inputs/RangeInput/index.d.ts +8 -0
- package/dist/inputs/RangeInput/index.js +17 -0
- package/dist/inputs/TextInput/index.d.ts +6 -0
- package/dist/inputs/TextInput/index.js +30 -0
- package/dist/inputs/index.d.ts +9 -0
- package/dist/inputs/index.js +9 -0
- package/dist/layout/DragSort/index.d.ts +16 -0
- package/dist/layout/DragSort/index.js +12 -0
- package/dist/layout/FoldCard/index.d.ts +9 -0
- package/dist/layout/FoldCard/index.js +69 -0
- package/dist/layout/PageBase/index.d.ts +6 -0
- package/dist/layout/PageBase/index.js +6 -0
- package/dist/layout/ResizableGridLayout/index.d.ts +11 -0
- package/dist/layout/ResizableGridLayout/index.js +13 -0
- package/dist/layout/SideMenu/index.d.ts +27 -0
- package/dist/layout/SideMenu/index.js +40 -0
- package/dist/layout/TabsPro/index.d.ts +9 -0
- package/dist/layout/TabsPro/index.js +87 -0
- package/dist/layout/index.d.ts +6 -0
- package/dist/layout/index.js +6 -0
- package/dist/web.d.ts +6 -0
- package/dist/web.js +6 -0
- package/package.json +28 -12
- package/src/antd/form/CheckboxButton/index.module.scss +0 -24
- package/src/antd/form/CheckboxButton/index.tsx +0 -31
- package/src/antd/form/FileUploader/index.tsx +0 -163
- package/src/antd/form/RadioButton/index.tsx +0 -32
- package/src/antd/form/Upload/index.tsx +0 -65
- package/src/antd/form/UploadImage/index.tsx +0 -338
- package/src/antd/form/index.ts +0 -6
- package/src/antd/index.ts +0 -46
- package/src/antd/pro/Alert/index.tsx +0 -24
- package/src/antd/pro/Button/components/Confirm.tsx +0 -24
- package/src/antd/pro/Button/components/Copy.tsx +0 -47
- package/src/antd/pro/Button/components/Drawer.tsx +0 -37
- package/src/antd/pro/Button/components/Group.tsx +0 -26
- package/src/antd/pro/Button/index.tsx +0 -11
- package/src/antd/pro/Card/index.tsx +0 -92
- package/src/antd/pro/Collapse/components/Item.tsx +0 -30
- package/src/antd/pro/Collapse/index.tsx +0 -27
- package/src/antd/pro/Image/index.tsx +0 -17
- package/src/antd/pro/Input/components/Range.tsx +0 -46
- package/src/antd/pro/Input/index.tsx +0 -61
- package/src/antd/pro/Popconfirm/index.tsx +0 -16
- package/src/antd/pro/Radio/components/Cancel.tsx +0 -30
- package/src/antd/pro/Radio/index.tsx +0 -7
- package/src/antd/pro/Space/index.tsx +0 -15
- package/src/antd/pro/Tabs/index.tsx +0 -135
- package/src/antd/pro/Typography/components/String.tsx +0 -72
- package/src/antd/pro/Typography/index.tsx +0 -9
- package/src/antd/pro/index.ts +0 -11
- package/src/components/BottomBar/index.tsx +0 -28
- package/src/components/CodeView/index.tsx +0 -85
- package/src/components/Collapse/index.tsx +0 -26
- package/src/components/Com2Canvas/index.tsx +0 -60
- package/src/components/CompileHtml/index.tsx +0 -26
- package/src/components/Crud/components/CardList/index.tsx +0 -174
- package/src/components/Crud/components/CreateUpdate/index.tsx +0 -179
- package/src/components/Crud/components/Provider/index.tsx +0 -83
- package/src/components/Crud/components/Remove/index.tsx +0 -56
- package/src/components/Crud/components/index.ts +0 -4
- package/src/components/Crud/hooks/index.ts +0 -4
- package/src/components/Crud/hooks/useColumns.tsx +0 -169
- package/src/components/Crud/hooks/useList.ts +0 -65
- package/src/components/Crud/hooks/useOrderable.tsx +0 -107
- package/src/components/Crud/hooks/useRequest.ts +0 -41
- package/src/components/Crud/index.tsx +0 -91
- package/src/components/Crud/types/index.ts +0 -188
- package/src/components/Crud/utils/index.ts +0 -87
- package/src/components/DateSwitcher/index.module.scss +0 -10
- package/src/components/DateSwitcher/index.tsx +0 -75
- package/src/components/DownloadLink/index.tsx +0 -36
- package/src/components/DragSort/index.tsx +0 -77
- package/src/components/DynamicSelect/index.tsx +0 -74
- package/src/components/DynamicSelect/utils.ts +0 -45
- package/src/components/EnumTag/index.tsx +0 -24
- package/src/components/FetchSelect/index.tsx +0 -57
- package/src/components/Fold/index.tsx +0 -52
- package/src/components/FormPro/index.tsx +0 -28
- package/src/components/GroupLayout/index.tsx +0 -45
- package/src/components/HtmlPro/index.tsx +0 -18
- package/src/components/IframePro/index.tsx +0 -52
- package/src/components/JsonRenderer/index.tsx +0 -114
- package/src/components/JsonView/index.tsx +0 -21
- package/src/components/Markdown/index.tsx +0 -152
- package/src/components/MindMap/context.tsx +0 -29
- package/src/components/MindMap/hooks/useAlignmentSnap.ts +0 -220
- package/src/components/MindMap/hooks/useCopyPaste.ts +0 -272
- package/src/components/MindMap/hooks/useDropToReparent.ts +0 -288
- package/src/components/MindMap/hooks/useExpandCollapse.ts +0 -146
- package/src/components/MindMap/hooks/useMoveDescendants.ts +0 -136
- package/src/components/MindMap/hooks/useUndoRedo.ts +0 -232
- package/src/components/MindMap/index.tsx +0 -117
- package/src/components/MultiImageDisplay/index.tsx +0 -63
- package/src/components/ProgressButton/index.module.scss +0 -65
- package/src/components/ProgressButton/index.tsx +0 -96
- package/src/components/SectorButton/index.tsx +0 -247
- package/src/components/TextInput/index.tsx +0 -61
- package/src/components/TimelineBar/components/CurrentWeekHighlight/index.tsx +0 -64
- package/src/components/TimelineBar/components/Guides/index.tsx +0 -61
- package/src/components/TimelineBar/components/Ticks/index.tsx +0 -56
- package/src/components/TimelineBar/components/TodayIndicator/index.tsx +0 -54
- package/src/components/TimelineBar/components/index.ts +0 -4
- package/src/components/TimelineBar/const.ts +0 -3
- package/src/components/TimelineBar/hooks/index.ts +0 -5
- package/src/components/TimelineBar/hooks/useHighlightRange.ts +0 -21
- package/src/components/TimelineBar/hooks/useMonthGuides.ts +0 -40
- package/src/components/TimelineBar/hooks/useTickValues.ts +0 -18
- package/src/components/TimelineBar/hooks/useVisibleRange.ts +0 -43
- package/src/components/TimelineBar/hooks/useWeekGuides.ts +0 -39
- package/src/components/TimelineBar/index.tsx +0 -63
- package/src/components/TimelineBar/utils.ts +0 -27
- package/src/components/Video/index.tsx +0 -37
- package/src/components/index.ts +0 -27
- package/src/rn.ts +0 -1
- package/src/rns/index.ts +0 -0
- package/src/web.ts +0 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Space } from 'antd';
|
|
4
|
+
import { QuickFilters } from '../components/QuickFilters';
|
|
5
|
+
import { mergeQuery, stringifyQuery } from '../utils/query';
|
|
6
|
+
const hasOwnValue = (value, key) => {
|
|
7
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
8
|
+
};
|
|
9
|
+
const loadCachedValues = (cacheKey) => {
|
|
10
|
+
if (!cacheKey || typeof window === 'undefined') {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const raw = window.localStorage.getItem(cacheKey);
|
|
15
|
+
return raw ? JSON.parse(raw) : {};
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const saveCachedValues = (cacheKey, values) => {
|
|
22
|
+
if (!cacheKey || typeof window === 'undefined') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
window.localStorage.setItem(cacheKey, JSON.stringify(values));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// localStorage can be unavailable in private browsing or restricted embeds.
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const useListFilters = ({ list }) => {
|
|
33
|
+
const listTabs = list?.tabs;
|
|
34
|
+
const quickFiltersConfig = list?.quickFilters;
|
|
35
|
+
const quickFilters = React.useMemo(() => quickFiltersConfig?.items || [], [quickFiltersConfig?.items]);
|
|
36
|
+
const cacheKey = quickFiltersConfig?.cacheKey;
|
|
37
|
+
const onChangeQueryRef = React.useRef(list?.onChangeQuery);
|
|
38
|
+
const tableQueryRef = React.useRef({});
|
|
39
|
+
const extraQueryRef = React.useRef({});
|
|
40
|
+
const lastExtraQueryKeyRef = React.useRef('');
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
onChangeQueryRef.current = list?.onChangeQuery;
|
|
43
|
+
}, [list?.onChangeQuery]);
|
|
44
|
+
const [activeTabKey, setActiveTabKey] = React.useState(() => {
|
|
45
|
+
return listTabs?.activeKey ?? listTabs?.defaultActiveKey ?? listTabs?.items?.[0]?.key;
|
|
46
|
+
});
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (listTabs?.activeKey !== undefined && listTabs.activeKey !== activeTabKey) {
|
|
49
|
+
setActiveTabKey(listTabs.activeKey);
|
|
50
|
+
}
|
|
51
|
+
}, [activeTabKey, listTabs?.activeKey]);
|
|
52
|
+
const [quickFilterValues, setQuickFilterValues] = React.useState(() => {
|
|
53
|
+
const cachedValues = loadCachedValues(cacheKey);
|
|
54
|
+
return quickFilters.reduce((prev, filter) => {
|
|
55
|
+
if (!hasOwnValue(prev, filter.key)) {
|
|
56
|
+
prev[filter.key] = filter.defaultValue;
|
|
57
|
+
}
|
|
58
|
+
if (hasOwnValue(filter, 'value')) {
|
|
59
|
+
prev[filter.key] = filter.value;
|
|
60
|
+
}
|
|
61
|
+
return prev;
|
|
62
|
+
}, { ...cachedValues });
|
|
63
|
+
});
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
setQuickFilterValues(prev => {
|
|
66
|
+
let changed = false;
|
|
67
|
+
const next = { ...prev };
|
|
68
|
+
quickFilters.forEach((filter) => {
|
|
69
|
+
if (hasOwnValue(filter, 'value') && next[filter.key] !== filter.value) {
|
|
70
|
+
next[filter.key] = filter.value;
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return changed ? next : prev;
|
|
75
|
+
});
|
|
76
|
+
}, [quickFilters]);
|
|
77
|
+
const buildExtraQuery = React.useCallback((tabKey, values = quickFilterValues) => {
|
|
78
|
+
const tabItem = listTabs?.items?.find(item => item.key === tabKey);
|
|
79
|
+
const tabQuery = typeof tabItem?.query === 'function'
|
|
80
|
+
? tabItem.query(tabItem.key, tabItem)
|
|
81
|
+
: tabItem?.query;
|
|
82
|
+
const filterQueries = quickFilters.map((filter) => {
|
|
83
|
+
const value = values[filter.key];
|
|
84
|
+
if (filter.getQuery) {
|
|
85
|
+
return filter.getQuery(value, filter);
|
|
86
|
+
}
|
|
87
|
+
if (!filter.field || value === undefined || value === null || value === '') {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
where: {
|
|
92
|
+
[filter.field]: { equals: value },
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
return mergeQuery(tabQuery, ...filterQueries);
|
|
97
|
+
}, [listTabs?.items, quickFilterValues, quickFilters]);
|
|
98
|
+
const emitQuery = React.useCallback((nextTableQuery, nextExtraQuery) => {
|
|
99
|
+
tableQueryRef.current = nextTableQuery;
|
|
100
|
+
extraQueryRef.current = nextExtraQuery;
|
|
101
|
+
onChangeQueryRef.current?.(mergeQuery(nextTableQuery, nextExtraQuery));
|
|
102
|
+
}, []);
|
|
103
|
+
const handleListQueryChange = React.useCallback((nextQuery) => {
|
|
104
|
+
emitQuery(nextQuery, extraQueryRef.current);
|
|
105
|
+
}, [emitQuery]);
|
|
106
|
+
const emitFilterQuery = React.useCallback((nextExtraQuery) => {
|
|
107
|
+
const nextTableQuery = {
|
|
108
|
+
...tableQueryRef.current,
|
|
109
|
+
skip: 0,
|
|
110
|
+
};
|
|
111
|
+
lastExtraQueryKeyRef.current = stringifyQuery(nextExtraQuery);
|
|
112
|
+
emitQuery(nextTableQuery, nextExtraQuery);
|
|
113
|
+
}, [emitQuery]);
|
|
114
|
+
const extraQuery = React.useMemo(() => {
|
|
115
|
+
return buildExtraQuery(activeTabKey);
|
|
116
|
+
}, [activeTabKey, buildExtraQuery]);
|
|
117
|
+
React.useEffect(() => {
|
|
118
|
+
const extraQueryKey = stringifyQuery(extraQuery);
|
|
119
|
+
if (lastExtraQueryKeyRef.current === extraQueryKey) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
emitFilterQuery(extraQuery);
|
|
123
|
+
}, [emitFilterQuery, extraQuery]);
|
|
124
|
+
const handleTabChange = React.useCallback((key) => {
|
|
125
|
+
setActiveTabKey(key);
|
|
126
|
+
listTabs?.onChange?.(key);
|
|
127
|
+
emitFilterQuery(buildExtraQuery(key));
|
|
128
|
+
}, [buildExtraQuery, emitFilterQuery, listTabs]);
|
|
129
|
+
const handleQuickFilterChange = React.useCallback((key, value) => {
|
|
130
|
+
const nextValues = {
|
|
131
|
+
...quickFilterValues,
|
|
132
|
+
[key]: value,
|
|
133
|
+
};
|
|
134
|
+
const filter = quickFilters.find(filter => filter.key === key);
|
|
135
|
+
setQuickFilterValues(nextValues);
|
|
136
|
+
filter?.onChange?.(value);
|
|
137
|
+
saveCachedValues(cacheKey, nextValues);
|
|
138
|
+
emitFilterQuery(buildExtraQuery(activeTabKey, nextValues));
|
|
139
|
+
}, [activeTabKey, buildExtraQuery, cacheKey, emitFilterQuery, quickFilterValues, quickFilters]);
|
|
140
|
+
const preparedList = React.useMemo(() => {
|
|
141
|
+
const { tabs: _tabs, quickFilters: _quickFilters, onChangeQuery: _onChangeQuery, toolbar, ...restList } = list || {};
|
|
142
|
+
const quickFilterNode = (_jsx(QuickFilters, { filters: quickFilters, values: quickFilterValues, onChange: handleQuickFilterChange }));
|
|
143
|
+
const toolbarFilter = toolbar?.filter;
|
|
144
|
+
const filterNode = quickFilters.length > 0 || toolbarFilter ? (_jsxs(Space, { wrap: true, children: [quickFilters.length > 0 ? quickFilterNode : null, toolbarFilter] })) : undefined;
|
|
145
|
+
return {
|
|
146
|
+
...restList,
|
|
147
|
+
onChangeQuery: handleListQueryChange,
|
|
148
|
+
toolbar: {
|
|
149
|
+
...toolbar,
|
|
150
|
+
...(filterNode ? { filter: filterNode } : {}),
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}, [handleListQueryChange, handleQuickFilterChange, list, quickFilterValues, quickFilters]);
|
|
154
|
+
return {
|
|
155
|
+
activeTabKey,
|
|
156
|
+
handleTabChange,
|
|
157
|
+
preparedList,
|
|
158
|
+
};
|
|
159
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CrudProps, ProColumnsPro } from '../types';
|
|
2
|
+
export declare const useOrderable: <T extends Record<string, unknown>>(params: {
|
|
3
|
+
orderable: CrudProps["orderable"];
|
|
4
|
+
columns: ProColumnsPro<T>[];
|
|
5
|
+
crud: CrudProps["crud"];
|
|
6
|
+
update: CrudProps["update"];
|
|
7
|
+
readonly?: boolean;
|
|
8
|
+
cardMode?: boolean;
|
|
9
|
+
}) => {
|
|
10
|
+
enabledFeature: boolean;
|
|
11
|
+
tableColumns: ProColumnsPro<T>[];
|
|
12
|
+
dragSortKey: string;
|
|
13
|
+
dataSource: T[];
|
|
14
|
+
onDragSortEnd: (_beforeIndex: number, _afterIndex: number, newDataSource: T[]) => Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
const dragSortKey = '__drag_sort__';
|
|
3
|
+
const getOrderableConfig = (orderable) => {
|
|
4
|
+
if (orderable && typeof orderable === 'object') {
|
|
5
|
+
return orderable;
|
|
6
|
+
}
|
|
7
|
+
return {};
|
|
8
|
+
};
|
|
9
|
+
const sortByOrderField = (list, orderField) => {
|
|
10
|
+
const indexed = list.map((item, index) => ({ item, index }));
|
|
11
|
+
indexed.sort((a, b) => {
|
|
12
|
+
const av = a.item[orderField];
|
|
13
|
+
const bv = b.item[orderField];
|
|
14
|
+
const an = typeof av === 'number' && Number.isFinite(av) ? av : Number.POSITIVE_INFINITY;
|
|
15
|
+
const bn = typeof bv === 'number' && Number.isFinite(bv) ? bv : Number.POSITIVE_INFINITY;
|
|
16
|
+
return an - bn;
|
|
17
|
+
});
|
|
18
|
+
return indexed.map(i => i.item);
|
|
19
|
+
};
|
|
20
|
+
export const useOrderable = (params) => {
|
|
21
|
+
const { orderable, columns, crud, update, readonly, cardMode } = params;
|
|
22
|
+
const enabledFeature = !!orderable && !cardMode;
|
|
23
|
+
const config = useMemo(() => getOrderableConfig(orderable), [orderable]);
|
|
24
|
+
const orderField = config.orderField ?? 'sort';
|
|
25
|
+
const start = config.start ?? 0;
|
|
26
|
+
const canUpdate = enabledFeature && !readonly && update !== false && !!crud.updateState?.mutateAsync;
|
|
27
|
+
const [dataSource, setDataSource] = useState([]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!enabledFeature)
|
|
30
|
+
return;
|
|
31
|
+
const list = crud.listState.data || [];
|
|
32
|
+
setDataSource(sortByOrderField(list, orderField));
|
|
33
|
+
}, [enabledFeature, crud.listState.data, orderField]);
|
|
34
|
+
const tableColumns = useMemo(() => {
|
|
35
|
+
if (!enabledFeature)
|
|
36
|
+
return columns;
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
title: '',
|
|
40
|
+
key: dragSortKey,
|
|
41
|
+
dataIndex: dragSortKey,
|
|
42
|
+
width: 48,
|
|
43
|
+
fixed: 'left',
|
|
44
|
+
hideInSearch: true,
|
|
45
|
+
hideInForm: true,
|
|
46
|
+
render: () => null,
|
|
47
|
+
},
|
|
48
|
+
...columns,
|
|
49
|
+
];
|
|
50
|
+
}, [columns, enabledFeature]);
|
|
51
|
+
const onDragSortEnd = async (_beforeIndex, _afterIndex, newDataSource) => {
|
|
52
|
+
const next = newDataSource.map((row, index) => ({
|
|
53
|
+
...row,
|
|
54
|
+
[orderField]: start + index,
|
|
55
|
+
}));
|
|
56
|
+
setDataSource(next);
|
|
57
|
+
if (!canUpdate)
|
|
58
|
+
return;
|
|
59
|
+
await Promise.allSettled(next.map((row) => {
|
|
60
|
+
const id = row.id;
|
|
61
|
+
if (typeof id !== 'string' || !id) {
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
}
|
|
64
|
+
return crud.updateState.mutateAsync(id, { [orderField]: row[orderField] });
|
|
65
|
+
}));
|
|
66
|
+
await crud.listState.refetch();
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
enabledFeature,
|
|
70
|
+
tableColumns,
|
|
71
|
+
dragSortKey: enabledFeature ? dragSortKey : undefined,
|
|
72
|
+
dataSource: enabledFeature ? dataSource : crud.listState.data,
|
|
73
|
+
onDragSortEnd: enabledFeature ? onDragSortEnd : undefined,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CrudProps, PaginationState } from '../types';
|
|
2
|
+
interface UseRequest {
|
|
3
|
+
columns: CrudProps['columns'];
|
|
4
|
+
list: CrudProps['list'];
|
|
5
|
+
}
|
|
6
|
+
export declare const useRequest: ({ columns, list }: UseRequest) => {
|
|
7
|
+
request: (params: PaginationState, sort: any, filter: any) => Promise<{
|
|
8
|
+
data: any[];
|
|
9
|
+
total: number;
|
|
10
|
+
success: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { transformOrder, transformPagination, transformWhere } from '../utils';
|
|
2
|
+
export const useRequest = ({ columns, list }) => {
|
|
3
|
+
const request = async (params, sort, filter) => {
|
|
4
|
+
const { current, pageSize, ...search } = params;
|
|
5
|
+
// 转换分页参数
|
|
6
|
+
const pagination = transformPagination({ current, pageSize });
|
|
7
|
+
// 转换排序参数
|
|
8
|
+
const orderBy = transformOrder(sort);
|
|
9
|
+
// 转换过滤参数
|
|
10
|
+
const where = transformWhere(search, columns);
|
|
11
|
+
const query = {
|
|
12
|
+
...pagination,
|
|
13
|
+
...(orderBy && { orderBy }),
|
|
14
|
+
...(where && { where }),
|
|
15
|
+
};
|
|
16
|
+
console.log(666, 35, params, sort, search, filter, where, query);
|
|
17
|
+
list?.onChangeQuery?.(query);
|
|
18
|
+
return {
|
|
19
|
+
data: [],
|
|
20
|
+
total: 0,
|
|
21
|
+
success: true,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
request,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Space } from 'antd';
|
|
4
|
+
import { DragSortTable, ProTable } from '@ant-design/pro-components';
|
|
5
|
+
import { CardList, CreateUpdate, ListTabs, Provider } from './components';
|
|
6
|
+
import { useColumns, useList, useListFilters, useOrderable, useRequest } from './hooks';
|
|
7
|
+
export const Crud = (props_) => {
|
|
8
|
+
const props = { ...props_ };
|
|
9
|
+
if (props.readonly) {
|
|
10
|
+
props.create = props.create ?? false;
|
|
11
|
+
props.update = props.update ?? false;
|
|
12
|
+
props.remove = props.remove ?? false;
|
|
13
|
+
}
|
|
14
|
+
const { crud, columns, list, create, update, remove, orderable } = props;
|
|
15
|
+
const { activeTabKey, handleTabChange, preparedList } = useListFilters({ list });
|
|
16
|
+
const { tableColumns, dataSource, dragSortKey, onDragSortEnd } = useOrderable({
|
|
17
|
+
orderable,
|
|
18
|
+
columns,
|
|
19
|
+
crud,
|
|
20
|
+
update,
|
|
21
|
+
readonly: props.readonly,
|
|
22
|
+
cardMode: !!list?.cardConfig,
|
|
23
|
+
});
|
|
24
|
+
const { finalColumns } = useColumns({ columns: tableColumns, crud, update, remove });
|
|
25
|
+
const { finalList } = useList({ list: preparedList });
|
|
26
|
+
const { request } = useRequest({ list: finalList, columns });
|
|
27
|
+
const TableComponent = dragSortKey ? DragSortTable : ProTable;
|
|
28
|
+
return (_jsxs(Provider, { crud: crud, children: [list?.tabs && (_jsx(ListTabs, { tabs: list?.tabs, activeKey: activeTabKey, onChange: handleTabChange })), _jsx(TableComponent, { rowKey: 'id', loading: crud.listState.isLoading, columns: finalColumns, scroll: { x: 'max-content' }, search: {
|
|
29
|
+
labelWidth: 'auto',
|
|
30
|
+
}, dataSource: dataSource, request: request, dragSortKey: dragSortKey, onDragSortEnd: onDragSortEnd, pagination: {
|
|
31
|
+
total: crud.countState.data,
|
|
32
|
+
showSizeChanger: true,
|
|
33
|
+
showQuickJumper: true,
|
|
34
|
+
defaultPageSize: 10,
|
|
35
|
+
pageSizeOptions: ['10', '15', '20', '30', '50'],
|
|
36
|
+
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/总共 ${total} 条`,
|
|
37
|
+
}, toolBarRender: () => [
|
|
38
|
+
create !== false ? (_jsx(CreateUpdate, { crud: crud, columns: tableColumns, config: create || {} }, 'create')) : null,
|
|
39
|
+
].filter(Boolean), tableRender: list?.cardConfig ? (props, dom, domList) => (_jsxs(Space, { style: { width: '100%' }, children: [domList.toolbar, _jsx(CardList, { crud: crud, columns: columns, list: list, create: create, update: update, remove: remove })] })) : undefined, ...finalList, options: {
|
|
40
|
+
...finalList?.options,
|
|
41
|
+
reload: () => {
|
|
42
|
+
crud.countState.refetch();
|
|
43
|
+
crud.listState.refetch();
|
|
44
|
+
},
|
|
45
|
+
} })] }));
|
|
46
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ButtonProps } from 'antd';
|
|
3
|
+
import type { ProTableProps, ProFormProps, ProColumns } from '@ant-design/pro-components';
|
|
4
|
+
export type ProColumnsPro<T = any> = Omit<ProColumns<T>, 'valueType'> & {
|
|
5
|
+
valueType?: ProColumns<T>['valueType'] | 'tags' | 'enabled';
|
|
6
|
+
};
|
|
7
|
+
export interface PaginationState {
|
|
8
|
+
current: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Crud {
|
|
12
|
+
listState: {
|
|
13
|
+
data?: any[];
|
|
14
|
+
isLoading?: boolean;
|
|
15
|
+
error?: any;
|
|
16
|
+
refetch: () => any;
|
|
17
|
+
};
|
|
18
|
+
countState: {
|
|
19
|
+
data?: any;
|
|
20
|
+
isLoading?: boolean;
|
|
21
|
+
error?: any;
|
|
22
|
+
refetch: () => any;
|
|
23
|
+
};
|
|
24
|
+
createState: {
|
|
25
|
+
mutate: (data: any) => void;
|
|
26
|
+
mutateAsync: (data: any) => Promise<any>;
|
|
27
|
+
isLoading?: boolean;
|
|
28
|
+
error?: any;
|
|
29
|
+
};
|
|
30
|
+
updateState: {
|
|
31
|
+
mutate: (id: string, data: any) => void;
|
|
32
|
+
mutateAsync: (id: string, data: any) => Promise<any>;
|
|
33
|
+
isLoading?: boolean;
|
|
34
|
+
error?: any;
|
|
35
|
+
};
|
|
36
|
+
removeState: {
|
|
37
|
+
mutate: (id: string) => void;
|
|
38
|
+
mutateAsync: (id: string) => Promise<any>;
|
|
39
|
+
isLoading?: boolean;
|
|
40
|
+
error?: any;
|
|
41
|
+
};
|
|
42
|
+
deleteState: {
|
|
43
|
+
mutate: (id: string) => void;
|
|
44
|
+
mutateAsync: (id: string) => Promise<any>;
|
|
45
|
+
isLoading?: boolean;
|
|
46
|
+
error?: any;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export type CardFieldValue = string | ReactNode;
|
|
50
|
+
export interface CardItem {
|
|
51
|
+
title?: CardFieldValue;
|
|
52
|
+
extra?: CardFieldValue;
|
|
53
|
+
content?: CardFieldValue;
|
|
54
|
+
cover?: CardFieldValue;
|
|
55
|
+
actions?: CardFieldValue[];
|
|
56
|
+
meta?: {
|
|
57
|
+
title?: CardFieldValue;
|
|
58
|
+
description?: CardFieldValue;
|
|
59
|
+
avatar?: CardFieldValue;
|
|
60
|
+
};
|
|
61
|
+
props?: any;
|
|
62
|
+
}
|
|
63
|
+
export interface CardConfig {
|
|
64
|
+
gutter?: [number, number];
|
|
65
|
+
col?: {
|
|
66
|
+
xs?: number;
|
|
67
|
+
sm?: number;
|
|
68
|
+
md?: number;
|
|
69
|
+
lg?: number;
|
|
70
|
+
xl?: number;
|
|
71
|
+
xxl?: number;
|
|
72
|
+
};
|
|
73
|
+
height?: string;
|
|
74
|
+
render?: (record: any, index: number, defaultActions: ReactNode[]) => ReactNode;
|
|
75
|
+
card: CardItem | ((record: any, index: number) => CardItem);
|
|
76
|
+
}
|
|
77
|
+
type CrudQuery = Record<string, any>;
|
|
78
|
+
export interface CrudListTabItem {
|
|
79
|
+
key: string;
|
|
80
|
+
label: ReactNode;
|
|
81
|
+
disabled?: boolean;
|
|
82
|
+
query?: CrudQuery | ((key: string, item: CrudListTabItem) => CrudQuery | undefined);
|
|
83
|
+
}
|
|
84
|
+
export interface CrudListTabs {
|
|
85
|
+
activeKey?: string;
|
|
86
|
+
defaultActiveKey?: string;
|
|
87
|
+
type?: 'line' | 'card' | 'editable-card';
|
|
88
|
+
items: CrudListTabItem[];
|
|
89
|
+
onChange?: (key: string) => void;
|
|
90
|
+
}
|
|
91
|
+
export interface CrudQuickFilterOption<V = any> {
|
|
92
|
+
label: string;
|
|
93
|
+
value: V;
|
|
94
|
+
}
|
|
95
|
+
export interface CrudQuickFilterRadio<V = any> {
|
|
96
|
+
type: 'radio';
|
|
97
|
+
key: string;
|
|
98
|
+
label?: ReactNode;
|
|
99
|
+
value?: V;
|
|
100
|
+
defaultValue?: V;
|
|
101
|
+
options: CrudQuickFilterOption<V>[] | string[];
|
|
102
|
+
buttonStyle?: 'outline' | 'solid';
|
|
103
|
+
field?: string;
|
|
104
|
+
onChange?: (value: V) => void;
|
|
105
|
+
getQuery?: (value: V, filter: CrudQuickFilterRadio<V>) => CrudQuery | undefined;
|
|
106
|
+
}
|
|
107
|
+
export type CrudQuickFilter = CrudQuickFilterRadio;
|
|
108
|
+
export interface CrudQuickFilters {
|
|
109
|
+
cacheKey?: string;
|
|
110
|
+
items: CrudQuickFilter[];
|
|
111
|
+
}
|
|
112
|
+
export interface List extends Omit<ProTableProps<any, any>, 'columns' | 'dataSource' | 'loading'> {
|
|
113
|
+
onChangeQuery?: (query: any) => void;
|
|
114
|
+
cardConfig?: CardConfig;
|
|
115
|
+
tabs?: CrudListTabs;
|
|
116
|
+
quickFilters?: CrudQuickFilters;
|
|
117
|
+
}
|
|
118
|
+
export interface Create {
|
|
119
|
+
mode?: 'modal' | 'drawer';
|
|
120
|
+
buttonProps?: ButtonProps;
|
|
121
|
+
formProps?: ProFormProps;
|
|
122
|
+
transformData?: (values: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
123
|
+
coverData?: (record: any) => Record<string, unknown>;
|
|
124
|
+
title?: string;
|
|
125
|
+
width?: number | string;
|
|
126
|
+
}
|
|
127
|
+
export interface Update {
|
|
128
|
+
mode?: 'modal' | 'drawer';
|
|
129
|
+
buttonProps?: ButtonProps;
|
|
130
|
+
formProps?: ProFormProps;
|
|
131
|
+
transformData?: (values: Record<string, unknown>, record: any) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
132
|
+
coverData?: (record: any) => Record<string, unknown>;
|
|
133
|
+
title?: string;
|
|
134
|
+
width?: number | string;
|
|
135
|
+
}
|
|
136
|
+
export interface Remove {
|
|
137
|
+
confirm?: boolean;
|
|
138
|
+
buttonProps?: ButtonProps;
|
|
139
|
+
title?: string;
|
|
140
|
+
content?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface Orderable {
|
|
143
|
+
orderField?: string;
|
|
144
|
+
start?: number;
|
|
145
|
+
label?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface CrudProps {
|
|
148
|
+
crud: Crud;
|
|
149
|
+
columns: ProColumnsPro[];
|
|
150
|
+
list?: List;
|
|
151
|
+
create?: false | Create;
|
|
152
|
+
update?: false | Update;
|
|
153
|
+
remove?: false | Remove;
|
|
154
|
+
orderable?: boolean | Orderable;
|
|
155
|
+
readonly?: boolean;
|
|
156
|
+
}
|
|
157
|
+
export interface ListProps {
|
|
158
|
+
crud: Crud;
|
|
159
|
+
columns: ProColumnsPro[];
|
|
160
|
+
list: List;
|
|
161
|
+
create?: false | Create;
|
|
162
|
+
update?: false | Update;
|
|
163
|
+
remove?: false | Remove;
|
|
164
|
+
}
|
|
165
|
+
export interface RemoveProps {
|
|
166
|
+
crud: Crud;
|
|
167
|
+
config: Remove;
|
|
168
|
+
record: any;
|
|
169
|
+
}
|
|
170
|
+
export interface CreateUpdateProps {
|
|
171
|
+
crud: Crud;
|
|
172
|
+
columns: ProColumnsPro[];
|
|
173
|
+
config: Create | Update;
|
|
174
|
+
record?: any;
|
|
175
|
+
}
|
|
176
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PaginationState, ProColumnsPro } from '../types';
|
|
2
|
+
export declare const transformPagination: (pagination: PaginationState) => {
|
|
3
|
+
skip: number;
|
|
4
|
+
take: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const transformOrder: (sort: Record<string, "ascend" | "descend">) => Record<string, "desc" | "asc">[];
|
|
7
|
+
export declare const transformWhere: (filter: Record<string, (string | number)[] | null>, columns: ProColumnsPro[]) => Record<string, any>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const transformPagination = (pagination) => {
|
|
2
|
+
return {
|
|
3
|
+
skip: (pagination.current - 1) * pagination.pageSize,
|
|
4
|
+
take: pagination.pageSize,
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export const transformOrder = (sort) => {
|
|
8
|
+
const orderByFields = [];
|
|
9
|
+
Object.keys(sort).forEach((key) => {
|
|
10
|
+
if (sort[key]) {
|
|
11
|
+
orderByFields.push({
|
|
12
|
+
[key]: sort[key] === 'ascend' ? 'asc' : 'desc',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
// 始终返回数组格式以支持多重排序
|
|
17
|
+
return orderByFields.length > 0 ? orderByFields : undefined;
|
|
18
|
+
};
|
|
19
|
+
export const transformWhere = (filter, columns) => {
|
|
20
|
+
const where = {};
|
|
21
|
+
Object.keys(filter).forEach((key) => {
|
|
22
|
+
const value = filter[key];
|
|
23
|
+
if (value !== null && value !== undefined) {
|
|
24
|
+
const column = columns.find(col => col.dataIndex === key);
|
|
25
|
+
// 根据字段类型转换过滤条件
|
|
26
|
+
if (column) {
|
|
27
|
+
switch (column.valueType) {
|
|
28
|
+
case 'text':
|
|
29
|
+
case 'textarea':
|
|
30
|
+
// 文本类型使用 contains 搜索
|
|
31
|
+
if (typeof value === 'string') {
|
|
32
|
+
where[key] = { contains: value };
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
case 'select':
|
|
36
|
+
case 'option':
|
|
37
|
+
if (column?.fieldProps?.multiple) {
|
|
38
|
+
where[key] = { in: value };
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
where[key] = { equals: value };
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case 'dateRange':
|
|
45
|
+
case 'dateTimeRange':
|
|
46
|
+
// 日期范围搜索
|
|
47
|
+
if (value.length >= 2) {
|
|
48
|
+
where[key] = {
|
|
49
|
+
gte: value[0],
|
|
50
|
+
lte: value[1],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case 'digit':
|
|
55
|
+
case 'money':
|
|
56
|
+
// 数字类型
|
|
57
|
+
if (typeof value === 'number') {
|
|
58
|
+
where[key] = { equals: value };
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'switch':
|
|
62
|
+
// 布尔类型
|
|
63
|
+
if (typeof value === 'boolean') {
|
|
64
|
+
where[key] = { equals: value };
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case 'tags':
|
|
68
|
+
where[key] = { equals: value };
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
where[key] = { equals: value };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
where[key] = { equals: value };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return Object.keys(where).length > 0 ? where : undefined;
|
|
80
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isPlainObject = (value) => {
|
|
2
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
3
|
+
};
|
|
4
|
+
export const mergeQuery = (...queries) => {
|
|
5
|
+
const result = {};
|
|
6
|
+
queries.forEach((query) => {
|
|
7
|
+
if (!query) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
Object.keys(query).forEach((key) => {
|
|
11
|
+
const value = query[key];
|
|
12
|
+
if (value === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (key === 'where' && isPlainObject(value) && isPlainObject(result.where)) {
|
|
16
|
+
result.where = {
|
|
17
|
+
...result.where,
|
|
18
|
+
...value,
|
|
19
|
+
};
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
result[key] = value;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
export const stringifyQuery = (query) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.stringify(query);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return String(Date.now());
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface MindMapDndState {
|
|
3
|
+
draggingNodeId: string | null;
|
|
4
|
+
dropTargetNodeId: string | null;
|
|
5
|
+
}
|
|
6
|
+
interface MindMapDndProviderProps {
|
|
7
|
+
value: MindMapDndState;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const MindMapDndProvider: (props: MindMapDndProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const useMindMapDndState: () => MindMapDndState;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
const MindMapDndContext = createContext(null);
|
|
5
|
+
export const MindMapDndProvider = (props) => {
|
|
6
|
+
const { value, children } = props;
|
|
7
|
+
return (_jsx(MindMapDndContext.Provider, { value: value, children: children }));
|
|
8
|
+
};
|
|
9
|
+
export const useMindMapDndState = () => {
|
|
10
|
+
const value = useContext(MindMapDndContext);
|
|
11
|
+
return value ?? { draggingNodeId: null, dropTargetNodeId: null };
|
|
12
|
+
};
|