@flozy/editor 5.3.5 → 5.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. package/dist/Editor/CommonEditor.js +8 -14
  2. package/dist/Editor/Editor.css +22 -58
  3. package/dist/Editor/Elements/Accordion/Accordion.js +1 -8
  4. package/dist/Editor/Elements/AppHeader/AppHeader.js +6 -6
  5. package/dist/Editor/Elements/Button/EditorButton.js +2 -9
  6. package/dist/Editor/Elements/Color Picker/ColorButtons.js +2 -4
  7. package/dist/Editor/Elements/Divider/Divider.js +9 -24
  8. package/dist/Editor/Elements/Embed/Image.js +12 -31
  9. package/dist/Editor/Elements/Embed/Video.js +2 -13
  10. package/dist/Editor/Elements/Form/Form.js +0 -1
  11. package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +4 -4
  12. package/dist/Editor/Elements/FreeGrid/styles.js +1 -2
  13. package/dist/Editor/Elements/Grid/GridItem.js +0 -2
  14. package/dist/Editor/Elements/Grid/Styles.js +0 -44
  15. package/dist/Editor/Elements/List/CheckList.js +1 -2
  16. package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +0 -1
  17. package/dist/Editor/Elements/Search/SearchAttachment.js +0 -1
  18. package/dist/Editor/Elements/Signature/SignaturePopup.js +4 -4
  19. package/dist/Editor/Elements/SimpleText/index.js +1 -8
  20. package/dist/Editor/Elements/SimpleText/style.js +1 -10
  21. package/dist/Editor/Elements/TopBanner/TopBanner.js +1 -2
  22. package/dist/Editor/MiniEditor.js +1 -15
  23. package/dist/Editor/Styles/EditorStyles.js +3 -5
  24. package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +1 -17
  25. package/dist/Editor/Toolbar/FormatTools/TextSize.js +3 -5
  26. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +72 -210
  27. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +8 -55
  28. package/dist/Editor/Toolbar/Toolbar.js +0 -6
  29. package/dist/Editor/Toolbar/toolbarGroups.js +0 -4
  30. package/dist/Editor/assets/svg/SettingsIcon.js +4 -4
  31. package/dist/Editor/common/ColorPickerButton.js +3 -5
  32. package/dist/Editor/common/DnD/Draggable.js +1 -2
  33. package/dist/Editor/common/FontLoader/FontLoader.js +4 -4
  34. package/dist/Editor/common/Icon.js +0 -6
  35. package/dist/Editor/common/ImageSelector/Options/Upload.js +1 -2
  36. package/dist/Editor/common/ImageSelector/Styles.js +6 -47
  37. package/dist/Editor/common/ImageSelector/UploadStyles.js +6 -18
  38. package/dist/Editor/common/MentionsPopup/Styles.js +122 -109
  39. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +0 -1
  40. package/dist/Editor/common/RnD/GuideLines/styles.js +3 -3
  41. package/dist/Editor/common/RnD/ShadowElement.js +1 -1
  42. package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +2 -14
  43. package/dist/Editor/common/RnD/Utils/gridDropItem.js +6 -9
  44. package/dist/Editor/common/RnD/index.js +1 -2
  45. package/dist/Editor/common/Section/index.js +3 -3
  46. package/dist/Editor/common/Section/styles.js +1 -5
  47. package/dist/Editor/common/Shorthands/elements.js +1 -13
  48. package/dist/Editor/common/StyleBuilder/fieldStyle.js +1 -2
  49. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +3 -9
  50. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +3 -27
  51. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +2 -15
  52. package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +2 -10
  53. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +1 -2
  54. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +1 -1
  55. package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +0 -2
  56. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +1 -3
  57. package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +4 -4
  58. package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +6 -22
  59. package/dist/Editor/common/StyleBuilder/fieldTypes/selectBox.js +2 -21
  60. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +4 -15
  61. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +0 -7
  62. package/dist/Editor/common/StyleBuilder/index.js +9 -17
  63. package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +0 -4
  64. package/dist/Editor/common/ToolbarIcon.js +1 -2
  65. package/dist/Editor/common/Uploader.js +36 -46
  66. package/dist/Editor/common/iconListV2.js +130 -348
  67. package/dist/Editor/common/iconslist.js +3 -6
  68. package/dist/Editor/commonStyle.js +4 -290
  69. package/dist/Editor/helper/index.js +3 -16
  70. package/dist/Editor/helper/theme.js +1 -24
  71. package/dist/Editor/hooks/useMouseMove.js +2 -5
  72. package/dist/Editor/plugins/withCustomDeleteBackward.js +2 -33
  73. package/dist/Editor/plugins/withEmbeds.js +26 -30
  74. package/dist/Editor/utils/SlateUtilityFunctions.js +4 -27
  75. package/dist/Editor/utils/button.js +4 -4
  76. package/dist/Editor/utils/helper.js +13 -40
  77. package/dist/Editor/utils/pageSettings.js +2 -14
  78. package/package.json +2 -2
  79. package/dist/Editor/Elements/DataView/DataView.js +0 -124
  80. package/dist/Editor/Elements/DataView/DataViewButton.js +0 -23
  81. package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +0 -67
  82. package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +0 -33
  83. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +0 -162
  84. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +0 -40
  85. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/styles.js +0 -67
  86. package/dist/Editor/Elements/DataView/Layouts/DataTypes/DateType.js +0 -35
  87. package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +0 -39
  88. package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +0 -30
  89. package/dist/Editor/Elements/DataView/Layouts/DataTypes/PersonType.js +0 -30
  90. package/dist/Editor/Elements/DataView/Layouts/DataTypes/SelectType.js +0 -35
  91. package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +0 -36
  92. package/dist/Editor/Elements/DataView/Layouts/DataTypes/index.js +0 -17
  93. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseField.js +0 -29
  94. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseSort.js +0 -38
  95. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/index.js +0 -74
  96. package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +0 -64
  97. package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +0 -106
  98. package/dist/Editor/Elements/DataView/Layouts/FilterView.js +0 -174
  99. package/dist/Editor/Elements/DataView/Layouts/Formula.js +0 -29
  100. package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +0 -113
  101. package/dist/Editor/Elements/DataView/Layouts/Options/AddProperty.js +0 -37
  102. package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +0 -111
  103. package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +0 -60
  104. package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +0 -36
  105. package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +0 -101
  106. package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +0 -160
  107. package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +0 -190
  108. package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +0 -42
  109. package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +0 -30
  110. package/dist/Editor/Elements/DataView/Layouts/Options/index.js +0 -110
  111. package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +0 -179
  112. package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +0 -112
  113. package/dist/Editor/Elements/DataView/Layouts/TableView.js +0 -227
  114. package/dist/Editor/Elements/DataView/Layouts/ViewData.js +0 -80
  115. package/dist/Editor/Elements/DataView/Layouts/colStyles.js +0 -10
  116. package/dist/Editor/Elements/DataView/Layouts/index.js +0 -25
  117. package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +0 -281
  118. package/dist/Editor/Elements/DataView/Utils/globalSearch.js +0 -15
  119. package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +0 -74
  120. package/dist/Editor/Elements/DataView/styles.js +0 -154
  121. package/dist/Editor/common/StyleBuilder/fieldTypes/lineSpacing.js +0 -79
  122. package/dist/Editor/helper/enforceDateFormat.js +0 -41
  123. package/dist/Editor/utils/dataView.js +0 -43
@@ -1,227 +0,0 @@
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 AddCircleOutlineIcon from "@mui/icons-material/AddCircleOutline";
6
- import { useDataView } from "../Providers/DataViewProvider";
7
- import PropertySettings from "./Options";
8
- import { PROPERTY_TYPES } from "./Options/Constants";
9
- import useTableStyles from "./TableStyles";
10
- import { GridSettingsIcon, GridAddSectionIcon } from "../../../common/iconslist";
11
- import { useEditorContext } from "../../../hooks/useMouseMove";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { Fragment as _Fragment } from "react/jsx-runtime";
14
- import { jsxs as _jsxs } from "react/jsx-runtime";
15
- const SortIcon = props => {
16
- const {
17
- sortBy
18
- } = props;
19
- return sortBy ? sortBy === "asc" ? /*#__PURE__*/_jsx(KeyboardArrowUpIcon, {
20
- sx: {
21
- color: "rgba(37, 99, 235, 1)"
22
- }
23
- }) : /*#__PURE__*/_jsx(KeyboardArrowDownIcon, {
24
- sx: {
25
- color: "rgba(37, 99, 235, 1)"
26
- }
27
- }) : null;
28
- };
29
- const TableView = props => {
30
- const {
31
- theme: appTheme
32
- } = useEditorContext();
33
- const {
34
- children,
35
- readOnly
36
- } = props;
37
- const theme = useTheme();
38
- const classes = useTableStyles(theme, appTheme);
39
- const {
40
- properties,
41
- onAddProperty,
42
- onUpdateProperty,
43
- onUpdateSort,
44
- sort,
45
- onAddRow
46
- } = useDataView();
47
- const [sortBy] = sort || [];
48
- const [anchorEl, setAnchorEl] = useState(null);
49
- const [mode, setMode] = useState({
50
- mode: null,
51
- edit: null
52
- });
53
- const open = Boolean(anchorEl);
54
- const shownProperties = properties?.filter(f => f.visible);
55
- const onAddClick = e => {
56
- setMode({
57
- type: "addProperty"
58
- });
59
- setAnchorEl(e.currentTarget);
60
- };
61
- const onEvent = (type, data, navToEdit = true) => {
62
- switch (type) {
63
- case "addProperty":
64
- const np = onAddProperty({
65
- type: data?.type
66
- }, data?.overrides || {});
67
- if (navToEdit) {
68
- setMode({
69
- type: "editProperty",
70
- edit: {
71
- ...np
72
- }
73
- });
74
- }
75
- break;
76
- case "editProperty":
77
- setMode({
78
- type: "editProperty",
79
- edit: {
80
- ...data?.edit
81
- }
82
- });
83
- break;
84
- case "changeProperty":
85
- setMode({
86
- type: "changeProperty",
87
- edit: {
88
- ...(data?.edit || {})
89
- }
90
- });
91
- break;
92
- case "updateProperty":
93
- const up = onUpdateProperty(data);
94
- if (navToEdit) {
95
- setMode({
96
- type: "editProperty",
97
- edit: {
98
- ...(up || {})
99
- }
100
- });
101
- }
102
- break;
103
- case "deleteProperty":
104
- onUpdateProperty(data, true);
105
- break;
106
- case "allProperties":
107
- setMode({
108
- type: "allProperties",
109
- edit: null
110
- });
111
- break;
112
- case "editOption":
113
- setMode({
114
- type: "editOption",
115
- edit: {
116
- ...(data?.edit || {})
117
- }
118
- });
119
- break;
120
- case "addSort":
121
- onUpdateSort(data);
122
- break;
123
- case "close":
124
- onClose();
125
- break;
126
- default:
127
- return;
128
- }
129
- };
130
- const onEditProperty = data => e => {
131
- if (!readOnly) {
132
- setAnchorEl(e?.currentTarget);
133
- onEvent("editProperty", {
134
- edit: {
135
- ...data
136
- }
137
- });
138
- } else {
139
- const currentSort = sortBy?.key === data?.key ? sortBy : null;
140
- onUpdateSort({
141
- ...(sortBy || data),
142
- newKey: data.key,
143
- operator: currentSort?.operator === "asc" ? "desc" : "asc"
144
- }, false, false);
145
- }
146
- };
147
- const onSettings = e => {
148
- setAnchorEl(e?.currentTarget);
149
- onEvent("allProperties", {});
150
- };
151
- const onClose = () => {
152
- setMode({});
153
- setAnchorEl(null);
154
- };
155
- return /*#__PURE__*/_jsxs(_Fragment, {
156
- children: [/*#__PURE__*/_jsx(Box, {
157
- component: "div",
158
- className: `tv-d-wrapper ${readOnly ? "readOnly" : ""}`,
159
- sx: classes.root,
160
- contentEditable: false,
161
- children: /*#__PURE__*/_jsxs(Box, {
162
- component: "table",
163
- sx: classes.table,
164
- children: [/*#__PURE__*/_jsx("thead", {
165
- children: /*#__PURE__*/_jsxs("tr", {
166
- children: [shownProperties?.map((m, i) => {
167
- const {
168
- Icon
169
- } = PROPERTY_TYPES?.find(f => f.type === m.type) || {};
170
- const isSort = sortBy?.key === m.key ? sortBy?.operator : null;
171
- return /*#__PURE__*/_jsx("th", {
172
- style: {
173
- minWidth: "200px"
174
- },
175
- children: /*#__PURE__*/_jsx(Button, {
176
- className: "tv-act-btn la",
177
- startIcon: /*#__PURE__*/_jsx(Icon, {}),
178
- endIcon: /*#__PURE__*/_jsx(SortIcon, {
179
- sortBy: isSort
180
- }),
181
- fullWidth: true,
182
- onClick: onEditProperty(m),
183
- children: m.label
184
- })
185
- }, i);
186
- }), !readOnly ? /*#__PURE__*/_jsxs(_Fragment, {
187
- children: [/*#__PURE__*/_jsx("th", {
188
- className: "tv-act-btn ico",
189
- children: /*#__PURE__*/_jsx(Button, {
190
- onClick: onAddClick,
191
- fullWidth: true,
192
- children: /*#__PURE__*/_jsx(GridAddSectionIcon, {})
193
- })
194
- }), /*#__PURE__*/_jsx("th", {
195
- className: "tv-act-btn ico",
196
- children: /*#__PURE__*/_jsx(Button, {
197
- onClick: onSettings,
198
- fullWidth: true,
199
- children: /*#__PURE__*/_jsx(GridSettingsIcon, {})
200
- })
201
- })]
202
- }) : null]
203
- })
204
- }), children]
205
- })
206
- }), !readOnly ? /*#__PURE__*/_jsx(Button, {
207
- contentEditable: false,
208
- className: "tv-act-btn la",
209
- fullWidth: true,
210
- onClick: onAddRow,
211
- sx: {
212
- textTransform: "none",
213
- justifyContent: "start"
214
- },
215
- startIcon: /*#__PURE__*/_jsx(AddCircleOutlineIcon, {}),
216
- children: "Add new row"
217
- }) : null, open && !readOnly ? /*#__PURE__*/_jsx(PropertySettings, {
218
- open: open,
219
- anchorEl: anchorEl,
220
- mode: mode,
221
- properties: properties,
222
- onClose: onClose,
223
- onEvent: onEvent
224
- }) : null]
225
- });
226
- };
227
- export default TableView;
@@ -1,80 +0,0 @@
1
- import React from "react";
2
- import { Box } from "@mui/material";
3
- import { useDataView } from "../Providers/DataViewProvider";
4
- import ColumnView from "./ColumnView";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- import { jsxs as _jsxs } from "react/jsx-runtime";
7
- const RenderRow = props => {
8
- const {
9
- rowIndex,
10
- row,
11
- properties,
12
- onSelect,
13
- selected,
14
- readOnly
15
- } = props;
16
- const showProperties = properties?.filter(f => f.visible);
17
- return showProperties?.map((property, i) => {
18
- return /*#__PURE__*/_jsx(ColumnView, {
19
- needAnchor: i === 0,
20
- row: row,
21
- rowIndex: rowIndex,
22
- property: property,
23
- onSelect: onSelect,
24
- selected: selected,
25
- readOnly: readOnly
26
- }, `${property.key}_${i}`);
27
- });
28
- };
29
- const ViewData = props => {
30
- const {
31
- attributes,
32
- children,
33
- customProps
34
- } = props;
35
- const {
36
- readOnly
37
- } = customProps || {};
38
- const {
39
- properties,
40
- rows,
41
- selectedRows,
42
- setSelectedRows
43
- } = useDataView();
44
- const onSelect = (id, checked) => {
45
- if (checked) {
46
- setSelectedRows([...selectedRows, id]);
47
- } else {
48
- setSelectedRows([...selectedRows?.filter(f => f !== id)]);
49
- }
50
- };
51
- return /*#__PURE__*/_jsxs(Box, {
52
- component: "tbody",
53
- ...attributes,
54
- contentEditable: false,
55
- children: [rows?.map((row, i) => {
56
- return /*#__PURE__*/_jsx(Box, {
57
- component: "tr",
58
- className: "tv-act-row",
59
- children: /*#__PURE__*/_jsx(RenderRow, {
60
- rowIndex: row?.id,
61
- row: row,
62
- properties: properties,
63
- onSelect: onSelect,
64
- selected: selectedRows?.includes(row?.id),
65
- readOnly: readOnly
66
- })
67
- }, i);
68
- }), /*#__PURE__*/_jsx("tr", {
69
- style: {
70
- visibility: "hidden",
71
- display: "none"
72
- },
73
- "aria-hidden": "true",
74
- children: /*#__PURE__*/_jsx("td", {
75
- children: children
76
- })
77
- })]
78
- });
79
- };
80
- export default ViewData;
@@ -1,10 +0,0 @@
1
- const useColumnStyles = theme => ({
2
- root: {
3
- zIndex: 1000,
4
- marginTop: "20px !important",
5
- [theme?.breakpoints?.between("xs", "md")]: {
6
- left: "-32px !important"
7
- }
8
- }
9
- });
10
- export default useColumnStyles;
@@ -1,25 +0,0 @@
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;
@@ -1,281 +0,0 @@
1
- import React, { createContext, useContext, useEffect, useState } from "react";
2
- import { Editor, Transforms, Node } 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
- data: initialData,
33
- path,
34
- editor,
35
- users: peoples
36
- } = props;
37
- const dataViewNode = Node.get(editor, path);
38
- const [layouts, setLayouts] = useState(initialData?.layouts || []);
39
- const [seletectedLayout, setSelectedLayout] = useState({
40
- ...(layouts[0] || {})
41
- });
42
- const [layoutType, setLayoutType] = useState(seletectedLayout?.type || "table");
43
- const [properties, setProperties] = useState(initialData?.properties || [...DEFAULT_PROPERTIES]);
44
- const [sort, setSort] = useState(seletectedLayout?.sort || []);
45
- const [filter, setFilter] = useState(seletectedLayout?.filter || []);
46
- const [rows, setRows] = useState(initialData?.rows || []);
47
- const [selectedRows, setSelectedRows] = useState([]);
48
- const [search, setSearch] = useState("");
49
- const users = peoples?.map(m => {
50
- return {
51
- value: m?.name
52
- };
53
- });
54
-
55
- // for undo and redo
56
- // minimal added for perforamnce issue avoid
57
- useEffect(() => {
58
- setRows(dataViewNode?.rows);
59
- }, [dataViewNode?.rows?.length]);
60
- useEffect(() => {
61
- setProperties(dataViewNode?.properties);
62
- }, [dataViewNode?.properties?.length]);
63
-
64
- // re-order when sort val changes
65
- useEffect(() => {
66
- if ((sort?.length > 0 || search) && rows?.length > 0) {
67
- const reOrderRows = sort?.length > 0 ? multiSortRows(initialData?.rows, sort, properties) : [...initialData?.rows];
68
- setRows(globalSearch(reOrderRows, search));
69
- } else {
70
- // reset to default order
71
- setRows(globalSearch(initialData?.rows || [], search));
72
- }
73
- }, [sort, search]);
74
- const onAddProperty = (data, overrides = {}) => {
75
- try {
76
- const {
77
- type
78
- } = data;
79
- const key = `col_${new Date().getTime()}`;
80
- const newProperty = {
81
- ...(PROPERTY_DEFAULTS[type] || {}),
82
- ...overrides,
83
- key: key,
84
- type
85
- };
86
- const updatedProperties = [...properties, {
87
- ...newProperty
88
- }];
89
- Transforms.setNodes(editor, {
90
- properties: [...updatedProperties]
91
- }, {
92
- at: path
93
- });
94
- setProperties([...updatedProperties]);
95
- return newProperty;
96
- } catch (err) {
97
- console.log(err);
98
- }
99
- };
100
- const onUpdateProperty = (data, isDelete = false) => {
101
- try {
102
- const {
103
- key
104
- } = data;
105
- let up = {
106
- ...data
107
- };
108
- const updatedProperties = properties?.map(m => {
109
- if (m.key === key) {
110
- up = {
111
- ...m,
112
- ...data
113
- };
114
- return up;
115
- }
116
- return m;
117
- });
118
- if (isDelete) {
119
- const deleteIndex = updatedProperties.findIndex(f => f.key === key);
120
- updatedProperties.splice(deleteIndex, 1);
121
- }
122
- Transforms.setNodes(editor, {
123
- properties: [...updatedProperties]
124
- }, {
125
- at: path
126
- });
127
- setProperties([...updatedProperties]);
128
- return up;
129
- } catch (err) {
130
- console.log(err);
131
- }
132
- };
133
- const onChange = (rowIndex, rowData) => {
134
- try {
135
- const updatedRows = rows?.map(m => {
136
- if (m?.id === rowIndex) {
137
- m = {
138
- ...m,
139
- ...rowData
140
- };
141
- }
142
- return m;
143
- });
144
- Transforms.setNodes(editor, {
145
- rows: [...updatedRows]
146
- }, {
147
- at: path
148
- });
149
- setRows(updatedRows);
150
- } catch (err) {
151
- console.log(err);
152
- }
153
- };
154
- const onAddRow = () => {
155
- try {
156
- const newRow = properties?.reduce((a, b) => {
157
- a[b.key] = "";
158
- return a;
159
- }, {
160
- id: `row_${new Date().getTime()}`
161
- });
162
- const updatedRows = [...rows, newRow];
163
- Transforms.setNodes(editor, {
164
- rows: [...updatedRows]
165
- }, {
166
- at: path
167
- });
168
- setRows(updatedRows);
169
- } catch (err) {
170
- console.log(err);
171
- }
172
- };
173
- const formatSort = (sorts = [], sortData, isDelete = false) => {
174
- let upSort = [];
175
- const isUpdate = sorts?.find(f => f.key === sortData?.key);
176
- if (isUpdate) {
177
- // update if any
178
- upSort = sorts?.map(m => {
179
- if (m.key === sortData.key) {
180
- // if update col
181
- if (sortData["newKey"]) {
182
- sortData["key"] = sortData["newKey"];
183
- delete sortData["newKey"];
184
- }
185
- return {
186
- ...sortData
187
- };
188
- }
189
- return m;
190
- });
191
- } else {
192
- upSort = [...sorts, {
193
- ...sortData
194
- }];
195
- }
196
-
197
- // if no sort
198
- if (sorts?.length === 0 && !isDelete) {
199
- upSort = [{
200
- ...sortData
201
- }];
202
- }
203
-
204
- // if delete
205
- if (isDelete) {
206
- const deleteIndex = upSort.findIndex(f => f.key === sortData.key);
207
- upSort.splice(deleteIndex, 1);
208
- }
209
- return upSort;
210
- };
211
- const onUpdateSort = (sortData = {}, isDelete = false, deleteAll = false) => {
212
- try {
213
- let upSort = {};
214
- const updatedLayouts = layouts?.map((m, i) => {
215
- if (seletectedLayout?.key === m.key) {
216
- upSort = !deleteAll ? formatSort(m?.sort || [], sortData, isDelete) : [];
217
- return {
218
- ...m,
219
- sort: [...upSort]
220
- };
221
- }
222
- return m;
223
- });
224
- Transforms.setNodes(editor, {
225
- layouts: [...updatedLayouts]
226
- }, {
227
- at: path
228
- });
229
- setLayouts(updatedLayouts);
230
- setSort(upSort);
231
- } catch (err) {
232
- console.log(err);
233
- }
234
- };
235
- const onDeleteRows = () => {
236
- try {
237
- const updatedRows = [...rows].filter(f => selectedRows.includes(f.id) === false);
238
- Transforms.setNodes(editor, {
239
- rows: [...updatedRows]
240
- }, {
241
- at: path
242
- });
243
- setRows(updatedRows);
244
- setSelectedRows([]);
245
- } catch (err) {
246
- console.log(err);
247
- }
248
- };
249
- const onSearch = e => {
250
- setSearch(e?.target?.value);
251
- };
252
- const value = {
253
- layoutType,
254
- setLayoutType,
255
- properties,
256
- setProperties,
257
- rows,
258
- setRows,
259
- onAddProperty,
260
- layouts,
261
- setLayouts,
262
- onUpdateProperty,
263
- onChange,
264
- onAddRow,
265
- users: users,
266
- onUpdateSort,
267
- sort,
268
- filter,
269
- setSelectedLayout,
270
- setFilter,
271
- selectedRows,
272
- setSelectedRows,
273
- onDeleteRows,
274
- search,
275
- onSearch
276
- };
277
- return /*#__PURE__*/_jsx(DataViewContext.Provider, {
278
- value: value,
279
- children: children
280
- });
281
- };
@@ -1,15 +0,0 @@
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;
@@ -1,74 +0,0 @@
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
- if (Array.isArray(valueA) && Array.isArray(valueB)) {
53
- comparison = Array.isArray(valueA) ? valueA?.map(m => m?.value).join(", ").localeCompare(valueB?.map(m => m?.value).join(", "), undefined, {
54
- sensitivity: "base"
55
- }) : 0;
56
- }
57
- break;
58
- case "date":
59
- comparison = sortByDate(valueA, valueB);
60
- break;
61
- case "check":
62
- return valueA && operator === "desc" ? 1 : -1;
63
- default:
64
- break;
65
- }
66
- if (comparison !== 0) {
67
- return operator === "asc" ? comparison : -comparison;
68
- }
69
- }
70
- return 0; // Rows are equal based on all criteria
71
- });
72
- };
73
-
74
- export default multiSortRows;