@flozy/editor 5.0.5 → 5.0.6
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/Editor/CommonEditor.js +6 -4
- package/dist/Editor/Editor.css +19 -1
- package/dist/Editor/Elements/Button/EditorButton.js +71 -53
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +4 -2
- package/dist/Editor/Elements/DataView/DataView.js +101 -0
- package/dist/Editor/Elements/DataView/DataViewButton.js +23 -0
- package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +59 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +128 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +25 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/DateType.js +26 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +38 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/PersonType.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/SelectType.js +35 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +36 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/index.js +17 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseField.js +28 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseSort.js +37 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/index.js +74 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +59 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +66 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterView.js +174 -0
- package/dist/Editor/Elements/DataView/Layouts/Formula.js +29 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +113 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AddProperty.js +37 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +111 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +62 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +36 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +101 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +158 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +190 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +42 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/index.js +110 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +176 -0
- package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +94 -0
- package/dist/Editor/Elements/DataView/Layouts/TableView.js +214 -0
- package/dist/Editor/Elements/DataView/Layouts/ViewData.js +83 -0
- package/dist/Editor/Elements/DataView/Layouts/index.js +25 -0
- package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +288 -0
- package/dist/Editor/Elements/DataView/Utils/globalSearch.js +15 -0
- package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +72 -0
- package/dist/Editor/Elements/DataView/styles.js +133 -0
- package/dist/Editor/Elements/FreeGrid/styles.js +2 -1
- package/dist/Editor/Elements/Signature/Signature.css +1 -1
- package/dist/Editor/Elements/Table/AddRowCol.js +1 -1
- package/dist/Editor/Elements/Table/DragButton.js +71 -68
- package/dist/Editor/Elements/Table/Styles.js +2 -2
- package/dist/Editor/Elements/Table/Table.js +10 -7
- package/dist/Editor/Elements/Table/TableCell.js +21 -21
- package/dist/Editor/Elements/Table/tableHelper.js +4 -16
- package/dist/Editor/Toolbar/PopupTool/index.js +1 -1
- package/dist/Editor/Toolbar/Toolbar.js +6 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +4 -0
- package/dist/Editor/assets/svg/OpenLinkIcon.js +3 -3
- package/dist/Editor/common/Icon.js +7 -1
- package/dist/Editor/common/MentionsPopup/index.js +1 -1
- package/dist/Editor/common/Shorthands/elements.js +13 -1
- package/dist/Editor/common/StyleBuilder/tableStyle.js +1 -1
- package/dist/Editor/common/iconslist.js +6 -3
- package/dist/Editor/hooks/useTable.js +4 -5
- package/dist/Editor/plugins/withHTML.js +18 -2
- package/dist/Editor/utils/SlateUtilityFunctions.js +16 -0
- package/dist/Editor/utils/dataView.js +43 -0
- package/dist/Editor/utils/embed.js +2 -1
- package/dist/Editor/utils/helper.js +19 -1
- package/dist/Editor/utils/insertNewLine.js +19 -1
- package/package.json +1 -1
@@ -0,0 +1,214 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { Box, Button, useTheme } from "@mui/material";
|
3
|
+
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
|
4
|
+
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
5
|
+
import { useDataView } from "../Providers/DataViewProvider";
|
6
|
+
import PropertySettings from "./Options";
|
7
|
+
import { PROPERTY_TYPES } from "./Options/Constants";
|
8
|
+
import useTableStyles from "./TableStyles";
|
9
|
+
import { GridSettingsIcon, GridAddSectionIcon } from "../../../common/iconslist";
|
10
|
+
import { useEditorContext } from "../../../hooks/useMouseMove";
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
12
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
14
|
+
const SortIcon = props => {
|
15
|
+
const {
|
16
|
+
sortBy
|
17
|
+
} = props;
|
18
|
+
return sortBy ? sortBy === "asc" ? /*#__PURE__*/_jsx(KeyboardArrowUpIcon, {
|
19
|
+
sx: {
|
20
|
+
color: "rgba(37, 99, 235, 1)"
|
21
|
+
}
|
22
|
+
}) : /*#__PURE__*/_jsx(KeyboardArrowDownIcon, {
|
23
|
+
sx: {
|
24
|
+
color: "rgba(37, 99, 235, 1)"
|
25
|
+
}
|
26
|
+
}) : null;
|
27
|
+
};
|
28
|
+
const TableView = props => {
|
29
|
+
const {
|
30
|
+
theme: appTheme
|
31
|
+
} = useEditorContext();
|
32
|
+
const {
|
33
|
+
children,
|
34
|
+
readOnly
|
35
|
+
} = props;
|
36
|
+
const theme = useTheme();
|
37
|
+
const classes = useTableStyles(theme, appTheme);
|
38
|
+
const {
|
39
|
+
properties,
|
40
|
+
onAddProperty,
|
41
|
+
onUpdateProperty,
|
42
|
+
onUpdateSort,
|
43
|
+
sort
|
44
|
+
} = useDataView();
|
45
|
+
const [sortBy] = sort || [];
|
46
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
47
|
+
const [mode, setMode] = useState({
|
48
|
+
mode: null,
|
49
|
+
edit: null
|
50
|
+
});
|
51
|
+
const open = Boolean(anchorEl);
|
52
|
+
const shownProperties = properties?.filter(f => f.visible);
|
53
|
+
const onAddClick = e => {
|
54
|
+
setMode({
|
55
|
+
type: "addProperty"
|
56
|
+
});
|
57
|
+
setAnchorEl(e.currentTarget);
|
58
|
+
};
|
59
|
+
const onEvent = (type, data, navToEdit = true) => {
|
60
|
+
switch (type) {
|
61
|
+
case "addProperty":
|
62
|
+
const np = onAddProperty({
|
63
|
+
type: data?.type
|
64
|
+
}, data?.overrides || {});
|
65
|
+
if (navToEdit) {
|
66
|
+
setMode({
|
67
|
+
type: "editProperty",
|
68
|
+
edit: {
|
69
|
+
...np
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
break;
|
74
|
+
case "editProperty":
|
75
|
+
setMode({
|
76
|
+
type: "editProperty",
|
77
|
+
edit: {
|
78
|
+
...data?.edit
|
79
|
+
}
|
80
|
+
});
|
81
|
+
break;
|
82
|
+
case "changeProperty":
|
83
|
+
setMode({
|
84
|
+
type: "changeProperty",
|
85
|
+
edit: {
|
86
|
+
...(data?.edit || {})
|
87
|
+
}
|
88
|
+
});
|
89
|
+
break;
|
90
|
+
case "updateProperty":
|
91
|
+
const up = onUpdateProperty(data);
|
92
|
+
if (navToEdit) {
|
93
|
+
setMode({
|
94
|
+
type: "editProperty",
|
95
|
+
edit: {
|
96
|
+
...(up || {})
|
97
|
+
}
|
98
|
+
});
|
99
|
+
}
|
100
|
+
break;
|
101
|
+
case "deleteProperty":
|
102
|
+
onUpdateProperty(data, true);
|
103
|
+
break;
|
104
|
+
case "allProperties":
|
105
|
+
setMode({
|
106
|
+
type: "allProperties",
|
107
|
+
edit: null
|
108
|
+
});
|
109
|
+
break;
|
110
|
+
case "editOption":
|
111
|
+
setMode({
|
112
|
+
type: "editOption",
|
113
|
+
edit: {
|
114
|
+
...(data?.edit || {})
|
115
|
+
}
|
116
|
+
});
|
117
|
+
break;
|
118
|
+
case "addSort":
|
119
|
+
onUpdateSort(data);
|
120
|
+
break;
|
121
|
+
case "close":
|
122
|
+
onClose();
|
123
|
+
break;
|
124
|
+
default:
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
};
|
128
|
+
const onEditProperty = data => e => {
|
129
|
+
if (!readOnly) {
|
130
|
+
setAnchorEl(e?.currentTarget);
|
131
|
+
onEvent("editProperty", {
|
132
|
+
edit: {
|
133
|
+
...data
|
134
|
+
}
|
135
|
+
});
|
136
|
+
} else {
|
137
|
+
const currentSort = sortBy?.key === data?.key ? sortBy : null;
|
138
|
+
onUpdateSort({
|
139
|
+
...(sortBy || data),
|
140
|
+
newKey: data.key,
|
141
|
+
operator: currentSort?.operator === "asc" ? "desc" : "asc"
|
142
|
+
}, false, false);
|
143
|
+
}
|
144
|
+
};
|
145
|
+
const onSettings = e => {
|
146
|
+
setAnchorEl(e?.currentTarget);
|
147
|
+
onEvent("allProperties", {});
|
148
|
+
};
|
149
|
+
const onClose = () => {
|
150
|
+
setMode({});
|
151
|
+
setAnchorEl(null);
|
152
|
+
};
|
153
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
154
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
155
|
+
component: "div",
|
156
|
+
className: `tv-d-wrapper ${readOnly ? "readOnly" : ""}`,
|
157
|
+
sx: classes.root,
|
158
|
+
contentEditable: false,
|
159
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
160
|
+
component: "table",
|
161
|
+
sx: classes.table,
|
162
|
+
children: [/*#__PURE__*/_jsx("thead", {
|
163
|
+
children: /*#__PURE__*/_jsxs("tr", {
|
164
|
+
children: [shownProperties?.map((m, i) => {
|
165
|
+
const {
|
166
|
+
Icon
|
167
|
+
} = PROPERTY_TYPES?.find(f => f.type === m.type) || {};
|
168
|
+
const isSort = sortBy?.key === m.key ? sortBy?.operator : null;
|
169
|
+
return /*#__PURE__*/_jsx("th", {
|
170
|
+
style: {
|
171
|
+
minWidth: "200px"
|
172
|
+
},
|
173
|
+
children: /*#__PURE__*/_jsx(Button, {
|
174
|
+
className: "tv-act-btn la",
|
175
|
+
startIcon: /*#__PURE__*/_jsx(Icon, {}),
|
176
|
+
endIcon: /*#__PURE__*/_jsx(SortIcon, {
|
177
|
+
sortBy: isSort
|
178
|
+
}),
|
179
|
+
fullWidth: true,
|
180
|
+
onClick: onEditProperty(m),
|
181
|
+
children: m.label
|
182
|
+
})
|
183
|
+
}, i);
|
184
|
+
}), !readOnly ? /*#__PURE__*/_jsxs(_Fragment, {
|
185
|
+
children: [/*#__PURE__*/_jsx("th", {
|
186
|
+
className: "tv-act-btn ico",
|
187
|
+
children: /*#__PURE__*/_jsx(Button, {
|
188
|
+
onClick: onAddClick,
|
189
|
+
fullWidth: true,
|
190
|
+
children: /*#__PURE__*/_jsx(GridAddSectionIcon, {})
|
191
|
+
})
|
192
|
+
}), /*#__PURE__*/_jsx("th", {
|
193
|
+
className: "tv-act-btn ico",
|
194
|
+
children: /*#__PURE__*/_jsx(Button, {
|
195
|
+
onClick: onSettings,
|
196
|
+
fullWidth: true,
|
197
|
+
children: /*#__PURE__*/_jsx(GridSettingsIcon, {})
|
198
|
+
})
|
199
|
+
})]
|
200
|
+
}) : null]
|
201
|
+
})
|
202
|
+
}), children]
|
203
|
+
})
|
204
|
+
}), open && !readOnly ? /*#__PURE__*/_jsx(PropertySettings, {
|
205
|
+
open: open,
|
206
|
+
anchorEl: anchorEl,
|
207
|
+
mode: mode,
|
208
|
+
properties: properties,
|
209
|
+
onClose: onClose,
|
210
|
+
onEvent: onEvent
|
211
|
+
}) : null]
|
212
|
+
});
|
213
|
+
};
|
214
|
+
export default TableView;
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { Box, Button } from "@mui/material";
|
3
|
+
import AddCircleOutlineIcon from "@mui/icons-material/AddCircleOutline";
|
4
|
+
import { useDataView } from "../Providers/DataViewProvider";
|
5
|
+
import ColumnView from "./ColumnView";
|
6
|
+
// import Formula from "./Formula";
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
|
+
const RenderRow = props => {
|
10
|
+
const {
|
11
|
+
rowIndex,
|
12
|
+
row,
|
13
|
+
properties,
|
14
|
+
onSelect,
|
15
|
+
selected,
|
16
|
+
readOnly
|
17
|
+
} = props;
|
18
|
+
const showProperties = properties?.filter(f => f.visible);
|
19
|
+
return showProperties?.map((property, i) => {
|
20
|
+
return /*#__PURE__*/_jsx(ColumnView, {
|
21
|
+
needAnchor: i === 0,
|
22
|
+
row: row,
|
23
|
+
rowIndex: rowIndex,
|
24
|
+
property: property,
|
25
|
+
onSelect: onSelect,
|
26
|
+
selected: selected,
|
27
|
+
readOnly: readOnly
|
28
|
+
}, `${property.key}_${i}`);
|
29
|
+
});
|
30
|
+
};
|
31
|
+
const ViewData = props => {
|
32
|
+
const {
|
33
|
+
attributes,
|
34
|
+
customProps
|
35
|
+
} = props;
|
36
|
+
const {
|
37
|
+
readOnly
|
38
|
+
} = customProps || {};
|
39
|
+
const {
|
40
|
+
properties,
|
41
|
+
rows,
|
42
|
+
onAddRow,
|
43
|
+
selectedRows,
|
44
|
+
setSelectedRows
|
45
|
+
} = useDataView();
|
46
|
+
const onSelect = (id, checked) => {
|
47
|
+
if (checked) {
|
48
|
+
setSelectedRows([...selectedRows, id]);
|
49
|
+
} else {
|
50
|
+
setSelectedRows([...selectedRows?.filter(f => f !== id)]);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
return /*#__PURE__*/_jsxs(Box, {
|
54
|
+
component: "tbody",
|
55
|
+
...attributes,
|
56
|
+
children: [rows?.map((row, i) => {
|
57
|
+
return /*#__PURE__*/_jsx(Box, {
|
58
|
+
component: "tr",
|
59
|
+
className: "tv-act-row",
|
60
|
+
children: /*#__PURE__*/_jsx(RenderRow, {
|
61
|
+
rowIndex: row?.id,
|
62
|
+
row: row,
|
63
|
+
properties: properties,
|
64
|
+
onSelect: onSelect,
|
65
|
+
selected: selectedRows?.includes(row?.id),
|
66
|
+
readOnly: readOnly
|
67
|
+
})
|
68
|
+
}, i);
|
69
|
+
}), !readOnly ? /*#__PURE__*/_jsx("tr", {
|
70
|
+
children: /*#__PURE__*/_jsx("td", {
|
71
|
+
colSpan: properties?.length + 2,
|
72
|
+
children: /*#__PURE__*/_jsx(Button, {
|
73
|
+
className: "tv-act-btn la",
|
74
|
+
fullWidth: true,
|
75
|
+
onClick: onAddRow,
|
76
|
+
startIcon: /*#__PURE__*/_jsx(AddCircleOutlineIcon, {}),
|
77
|
+
children: "Add new row"
|
78
|
+
})
|
79
|
+
})
|
80
|
+
}) : null]
|
81
|
+
});
|
82
|
+
};
|
83
|
+
export default ViewData;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import TableView from "./TableView";
|
3
|
+
import { useDataView } from "../Providers/DataViewProvider";
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
6
|
+
const LAYOUT_COMPONENT = {
|
7
|
+
table: TableView
|
8
|
+
};
|
9
|
+
const LayoutView = props => {
|
10
|
+
const {
|
11
|
+
readOnly,
|
12
|
+
children
|
13
|
+
} = props;
|
14
|
+
const {
|
15
|
+
layoutType
|
16
|
+
} = useDataView();
|
17
|
+
const Layout = LAYOUT_COMPONENT[layoutType] || LAYOUT_COMPONENT["table"];
|
18
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
19
|
+
children: /*#__PURE__*/_jsx(Layout, {
|
20
|
+
readOnly: readOnly,
|
21
|
+
children: children
|
22
|
+
})
|
23
|
+
});
|
24
|
+
};
|
25
|
+
export default LayoutView;
|
@@ -0,0 +1,288 @@
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from "react";
|
2
|
+
import { Transforms } from "slate";
|
3
|
+
import { PROPERTY_DEFAULTS } from "../Layouts/Options/Constants";
|
4
|
+
import multiSortRows from "../Utils/multiSortRows";
|
5
|
+
import globalSearch from "../Utils/globalSearch";
|
6
|
+
|
7
|
+
// Data View context
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
9
|
+
const DataViewContext = /*#__PURE__*/createContext();
|
10
|
+
export const useDataView = () => useContext(DataViewContext);
|
11
|
+
const DEFAULT_PROPERTIES = [{
|
12
|
+
key: "column1",
|
13
|
+
label: "Name",
|
14
|
+
dataType: "text"
|
15
|
+
}, {
|
16
|
+
key: "column2",
|
17
|
+
label: "Status",
|
18
|
+
dataType: "select",
|
19
|
+
options: ["Active", "Inactive"]
|
20
|
+
}, {
|
21
|
+
key: "column3",
|
22
|
+
label: "Agree?",
|
23
|
+
dataType: "checkbox"
|
24
|
+
}];
|
25
|
+
|
26
|
+
// Combined provider
|
27
|
+
export const DataViewProvider = ({
|
28
|
+
children,
|
29
|
+
...props
|
30
|
+
}) => {
|
31
|
+
const {
|
32
|
+
initialData,
|
33
|
+
path,
|
34
|
+
editor
|
35
|
+
} = props;
|
36
|
+
const [layouts, setLayouts] = useState(initialData?.layouts || []);
|
37
|
+
const [seletectedLayout, setSelectedLayout] = useState({
|
38
|
+
...(layouts[0] || {})
|
39
|
+
});
|
40
|
+
const [layoutType, setLayoutType] = useState(seletectedLayout?.type || "table");
|
41
|
+
const [properties, setProperties] = useState(initialData?.properties || [...DEFAULT_PROPERTIES]);
|
42
|
+
const [sort, setSort] = useState(seletectedLayout?.sort || []);
|
43
|
+
const [filter, setFilter] = useState(seletectedLayout?.filter || []);
|
44
|
+
const [rows, setRows] = useState(initialData?.rows || []);
|
45
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
46
|
+
const [search, setSearch] = useState("");
|
47
|
+
const [title, setTitle] = useState(initialData?.tableTitle || "");
|
48
|
+
let {
|
49
|
+
users
|
50
|
+
} = initialData || {};
|
51
|
+
users = users?.map(m => {
|
52
|
+
return {
|
53
|
+
value: m?.name
|
54
|
+
};
|
55
|
+
});
|
56
|
+
|
57
|
+
// re-order when sort val changes
|
58
|
+
useEffect(() => {
|
59
|
+
if ((sort?.length > 0 || search) && rows?.length > 0) {
|
60
|
+
const reOrderRows = sort?.length > 0 ? multiSortRows(rows, sort, properties) : [...rows];
|
61
|
+
setRows(globalSearch(reOrderRows, search));
|
62
|
+
} else {
|
63
|
+
// reset to default order
|
64
|
+
setRows(globalSearch(initialData?.rows || [], search));
|
65
|
+
}
|
66
|
+
}, [sort, search]);
|
67
|
+
const onAddProperty = (data, overrides = {}) => {
|
68
|
+
try {
|
69
|
+
const {
|
70
|
+
type
|
71
|
+
} = data;
|
72
|
+
const key = `col_${new Date().getTime()}`;
|
73
|
+
const newProperty = {
|
74
|
+
...(PROPERTY_DEFAULTS[type] || {}),
|
75
|
+
...overrides,
|
76
|
+
key: key,
|
77
|
+
type
|
78
|
+
};
|
79
|
+
const updatedProperties = [...properties, {
|
80
|
+
...newProperty
|
81
|
+
}];
|
82
|
+
Transforms.setNodes(editor, {
|
83
|
+
properties: [...updatedProperties]
|
84
|
+
}, {
|
85
|
+
at: path
|
86
|
+
});
|
87
|
+
setProperties([...updatedProperties]);
|
88
|
+
return newProperty;
|
89
|
+
} catch (err) {
|
90
|
+
console.log(err);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
const onUpdateProperty = (data, isDelete = false) => {
|
94
|
+
try {
|
95
|
+
const {
|
96
|
+
key
|
97
|
+
} = data;
|
98
|
+
let up = {
|
99
|
+
...data
|
100
|
+
};
|
101
|
+
const updatedProperties = properties?.map(m => {
|
102
|
+
if (m.key === key) {
|
103
|
+
up = {
|
104
|
+
...m,
|
105
|
+
...data
|
106
|
+
};
|
107
|
+
return up;
|
108
|
+
}
|
109
|
+
return m;
|
110
|
+
});
|
111
|
+
if (isDelete) {
|
112
|
+
const deleteIndex = updatedProperties.findIndex(f => f.key === key);
|
113
|
+
updatedProperties.splice(deleteIndex, 1);
|
114
|
+
}
|
115
|
+
Transforms.setNodes(editor, {
|
116
|
+
properties: [...updatedProperties]
|
117
|
+
}, {
|
118
|
+
at: path
|
119
|
+
});
|
120
|
+
setProperties([...updatedProperties]);
|
121
|
+
return up;
|
122
|
+
} catch (err) {
|
123
|
+
console.log(err);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
const onChange = (rowIndex, rowData) => {
|
127
|
+
try {
|
128
|
+
const updatedRows = rows?.map(m => {
|
129
|
+
if (m?.id === rowIndex) {
|
130
|
+
m = {
|
131
|
+
...m,
|
132
|
+
...rowData
|
133
|
+
};
|
134
|
+
}
|
135
|
+
return m;
|
136
|
+
});
|
137
|
+
Transforms.setNodes(editor, {
|
138
|
+
rows: [...updatedRows]
|
139
|
+
}, {
|
140
|
+
at: path
|
141
|
+
});
|
142
|
+
setRows(updatedRows);
|
143
|
+
} catch (err) {
|
144
|
+
console.log(err);
|
145
|
+
}
|
146
|
+
};
|
147
|
+
const onAddRow = () => {
|
148
|
+
try {
|
149
|
+
const newRow = properties?.reduce((a, b) => {
|
150
|
+
a[b.key] = "";
|
151
|
+
return a;
|
152
|
+
}, {
|
153
|
+
id: `row_${new Date().getTime()}`
|
154
|
+
});
|
155
|
+
const updatedRows = [...rows, newRow];
|
156
|
+
Transforms.setNodes(editor, {
|
157
|
+
rows: [...updatedRows]
|
158
|
+
}, {
|
159
|
+
at: path
|
160
|
+
});
|
161
|
+
setRows(updatedRows);
|
162
|
+
} catch (err) {
|
163
|
+
console.log(err);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
const formatSort = (sorts = [], sortData, isDelete = false) => {
|
167
|
+
let upSort = [];
|
168
|
+
const isUpdate = sorts?.find(f => f.key === sortData?.key);
|
169
|
+
if (isUpdate) {
|
170
|
+
// update if any
|
171
|
+
upSort = sorts?.map(m => {
|
172
|
+
if (m.key === sortData.key) {
|
173
|
+
// if update col
|
174
|
+
if (sortData["newKey"]) {
|
175
|
+
sortData["key"] = sortData["newKey"];
|
176
|
+
delete sortData["newKey"];
|
177
|
+
}
|
178
|
+
return {
|
179
|
+
...sortData
|
180
|
+
};
|
181
|
+
}
|
182
|
+
return m;
|
183
|
+
});
|
184
|
+
} else {
|
185
|
+
upSort = [...sorts, {
|
186
|
+
...sortData
|
187
|
+
}];
|
188
|
+
}
|
189
|
+
|
190
|
+
// if no sort
|
191
|
+
if (sorts?.length === 0 && !isDelete) {
|
192
|
+
upSort = [{
|
193
|
+
...sortData
|
194
|
+
}];
|
195
|
+
}
|
196
|
+
|
197
|
+
// if delete
|
198
|
+
if (isDelete) {
|
199
|
+
const deleteIndex = upSort.findIndex(f => f.key === sortData.key);
|
200
|
+
upSort.splice(deleteIndex, 1);
|
201
|
+
}
|
202
|
+
return upSort;
|
203
|
+
};
|
204
|
+
const onUpdateSort = (sortData = {}, isDelete = false, deleteAll = false) => {
|
205
|
+
try {
|
206
|
+
let upSort = {};
|
207
|
+
const updatedLayouts = layouts?.map((m, i) => {
|
208
|
+
if (seletectedLayout?.key === m.key) {
|
209
|
+
upSort = !deleteAll ? formatSort(m?.sort || [], sortData, isDelete) : [];
|
210
|
+
return {
|
211
|
+
...m,
|
212
|
+
sort: [...upSort]
|
213
|
+
};
|
214
|
+
}
|
215
|
+
return m;
|
216
|
+
});
|
217
|
+
Transforms.setNodes(editor, {
|
218
|
+
layouts: [...updatedLayouts]
|
219
|
+
}, {
|
220
|
+
at: path
|
221
|
+
});
|
222
|
+
setLayouts(updatedLayouts);
|
223
|
+
setSort(upSort);
|
224
|
+
} catch (err) {
|
225
|
+
console.log(err);
|
226
|
+
}
|
227
|
+
};
|
228
|
+
const onDeleteRows = () => {
|
229
|
+
try {
|
230
|
+
const updatedRows = [...rows].filter(f => selectedRows.includes(f.id) === false);
|
231
|
+
Transforms.setNodes(editor, {
|
232
|
+
rows: [...updatedRows]
|
233
|
+
}, {
|
234
|
+
at: path
|
235
|
+
});
|
236
|
+
setRows(updatedRows);
|
237
|
+
setSelectedRows([]);
|
238
|
+
} catch (err) {
|
239
|
+
console.log(err);
|
240
|
+
}
|
241
|
+
};
|
242
|
+
const onSearch = e => {
|
243
|
+
setSearch(e?.target?.value);
|
244
|
+
};
|
245
|
+
const onTitleChange = value => {
|
246
|
+
try {
|
247
|
+
Transforms.setNodes(editor, {
|
248
|
+
title: value
|
249
|
+
}, {
|
250
|
+
at: path
|
251
|
+
});
|
252
|
+
setTitle(value);
|
253
|
+
} catch (err) {
|
254
|
+
console.log(err);
|
255
|
+
}
|
256
|
+
};
|
257
|
+
const value = {
|
258
|
+
layoutType,
|
259
|
+
setLayoutType,
|
260
|
+
properties,
|
261
|
+
setProperties,
|
262
|
+
rows,
|
263
|
+
setRows,
|
264
|
+
onAddProperty,
|
265
|
+
layouts,
|
266
|
+
setLayouts,
|
267
|
+
onUpdateProperty,
|
268
|
+
onChange,
|
269
|
+
onAddRow,
|
270
|
+
users: users,
|
271
|
+
onUpdateSort,
|
272
|
+
sort,
|
273
|
+
filter,
|
274
|
+
setSelectedLayout,
|
275
|
+
setFilter,
|
276
|
+
selectedRows,
|
277
|
+
setSelectedRows,
|
278
|
+
onDeleteRows,
|
279
|
+
search,
|
280
|
+
onSearch,
|
281
|
+
title,
|
282
|
+
setTitle: onTitleChange
|
283
|
+
};
|
284
|
+
return /*#__PURE__*/_jsx(DataViewContext.Provider, {
|
285
|
+
value: value,
|
286
|
+
children: children
|
287
|
+
});
|
288
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const globalSearch = (array, searchTerm) => {
|
2
|
+
if (!searchTerm) {
|
3
|
+
return array;
|
4
|
+
}
|
5
|
+
const lowerCaseSearchTerm = searchTerm.toLowerCase();
|
6
|
+
return array.filter(item => Object.values(item).some(value => {
|
7
|
+
if (typeof value === "string" && value) {
|
8
|
+
return value?.toLowerCase().includes(lowerCaseSearchTerm);
|
9
|
+
} else if (Array.isArray(value)) {
|
10
|
+
return value?.map(m => m?.value).some(d => d.toLowerCase().includes(lowerCaseSearchTerm));
|
11
|
+
}
|
12
|
+
return false;
|
13
|
+
}));
|
14
|
+
};
|
15
|
+
export default globalSearch;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
function sortByDate(a, b) {
|
2
|
+
const dateA = new Date(a);
|
3
|
+
const dateB = new Date(b);
|
4
|
+
|
5
|
+
// Check if both dates are valid
|
6
|
+
const isValidA = !isNaN(dateA.getTime());
|
7
|
+
const isValidB = !isNaN(dateB.getTime());
|
8
|
+
if (isValidA && isValidB) {
|
9
|
+
// Compare valid dates
|
10
|
+
return dateA - dateB;
|
11
|
+
} else if (isValidA) {
|
12
|
+
// Invalid date in `b` pushes `a` before `b`
|
13
|
+
return -1;
|
14
|
+
} else if (isValidB) {
|
15
|
+
// Invalid date in `a` pushes `b` before `a`
|
16
|
+
return 1;
|
17
|
+
} else {
|
18
|
+
// Both are invalid, maintain their relative order
|
19
|
+
return 0;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Multi-sort rows based on multiple criteria.
|
25
|
+
* @param {Array} rows - Array of row objects.
|
26
|
+
* @param {Array} criteria - Array of sort criteria [{key, sortBy}].
|
27
|
+
* @param {Object} columnConfig - Column configurations with data types.
|
28
|
+
*/
|
29
|
+
const multiSortRows = (rows, criteria, columnConfig) => {
|
30
|
+
return rows.slice().sort((a, b) => {
|
31
|
+
for (let {
|
32
|
+
key,
|
33
|
+
operator
|
34
|
+
} of criteria) {
|
35
|
+
const column = columnConfig.find(col => col.key === key);
|
36
|
+
if (!column) continue;
|
37
|
+
const dataType = column.type;
|
38
|
+
const valueA = a[key];
|
39
|
+
const valueB = b[key];
|
40
|
+
let comparison = 0;
|
41
|
+
switch (dataType) {
|
42
|
+
case "text":
|
43
|
+
comparison = valueA.localeCompare(valueB, undefined, {
|
44
|
+
sensitivity: "base"
|
45
|
+
});
|
46
|
+
break;
|
47
|
+
case "number":
|
48
|
+
comparison = parseInt(valueA || 0) - parseInt(valueB || 0);
|
49
|
+
break;
|
50
|
+
case "select":
|
51
|
+
case "multi-select":
|
52
|
+
comparison = valueA?.map(m => m?.value).join(", ").localeCompare(valueB?.map(m => m?.value).join(", "), undefined, {
|
53
|
+
sensitivity: "base"
|
54
|
+
});
|
55
|
+
break;
|
56
|
+
case "date":
|
57
|
+
comparison = sortByDate(valueA, valueB);
|
58
|
+
break;
|
59
|
+
case "check":
|
60
|
+
return valueA && operator === "desc" ? 1 : -1;
|
61
|
+
default:
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
if (comparison !== 0) {
|
65
|
+
return operator === "asc" ? comparison : -comparison;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return 0; // Rows are equal based on all criteria
|
69
|
+
});
|
70
|
+
};
|
71
|
+
|
72
|
+
export default multiSortRows;
|