@flozy/editor 9.3.4 → 9.3.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/ChatEditor.js +3 -2
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/MultiSelect.js +422 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +18 -5
- package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +5 -1
- package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +3 -2
- package/dist/Editor/Elements/DataView/Layouts/Options/index.js +11 -0
- package/dist/Editor/Elements/Embed/Image.js +2 -1
- package/dist/Editor/Elements/FreeGrid/FreeGrid.js +44 -9
- package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +16 -2
- package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +26 -2
- package/dist/Editor/Elements/FreeGrid/Options/More.js +7 -2
- package/dist/Editor/Elements/Table/TableCell.js +4 -0
- package/dist/Editor/MiniEditor.js +2 -1
- package/dist/Editor/assets/svg/ClearAllRounded.js +31 -0
- package/dist/Editor/common/RnD/Utils/gridDropItem.js +58 -7
- package/dist/Editor/common/RnD/Utils/index.js +3 -0
- package/dist/Editor/common/RnD/VirtualElement/ForceAutoAlignment.js +110 -0
- package/dist/Editor/common/RnD/VirtualElement/VirtualTextElement.js +112 -0
- package/dist/Editor/common/RnD/VirtualElement/helper.js +267 -0
- package/dist/Editor/common/RnD/VirtualElement/index.js +185 -102
- package/dist/Editor/common/RnD/VirtualElement/styles.js +95 -8
- package/dist/Editor/common/RnD/VirtualElement/updateAutoProps.js +5 -3
- package/dist/Editor/common/RnD/index.js +50 -5
- package/dist/Editor/common/SnackBar/index.js +43 -0
- package/dist/Editor/hooks/useAutoScroll.js +38 -0
- package/dist/Editor/hooks/useMouseMove.js +5 -2
- package/dist/Editor/hooks/useTable.js +4 -1
- package/dist/Editor/utils/divider.js +11 -3
- package/dist/Editor/utils/freegrid.js +2 -2
- package/dist/Editor/utils/helper.js +62 -9
- package/dist/Editor/utils/table.js +45 -37
- package/package.json +1 -1
@@ -0,0 +1,267 @@
|
|
1
|
+
import { ROW_HEIGHT } from "../Utils/gridDropItem";
|
2
|
+
import { Transforms, Editor } from "slate";
|
3
|
+
export const findFirstRowOverlap = (gridItems, startRow, endRow, textItemIndex) => {
|
4
|
+
let firstOverlapRow;
|
5
|
+
gridItems.forEach((gridItem, index) => {
|
6
|
+
const {
|
7
|
+
gridArea_xs: gridArea
|
8
|
+
} = gridItem;
|
9
|
+
if (!gridArea) {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
const [itemStartRow] = getGridArea(gridArea);
|
13
|
+
const isItemOverlap = itemStartRow >= startRow && itemStartRow <= endRow;
|
14
|
+
const isCurrentEle = textItemIndex === index;
|
15
|
+
if (isItemOverlap && !isCurrentEle && gridArea) {
|
16
|
+
firstOverlapRow = firstOverlapRow ? Math.min(firstOverlapRow, itemStartRow) : itemStartRow;
|
17
|
+
}
|
18
|
+
});
|
19
|
+
return firstOverlapRow;
|
20
|
+
};
|
21
|
+
export const getHeight = (oldHeight, newHeight) => {
|
22
|
+
const changeHeight = oldHeight && oldHeight < newHeight;
|
23
|
+
const height = changeHeight ? newHeight : oldHeight;
|
24
|
+
return {
|
25
|
+
height,
|
26
|
+
changeHeight
|
27
|
+
};
|
28
|
+
};
|
29
|
+
export const getGridArea = gridArea => {
|
30
|
+
return gridArea.split("/").map(num => parseInt(num));
|
31
|
+
};
|
32
|
+
const getBoxToAutoAlign = (editor, sectionPath) => {
|
33
|
+
const [boxData] = Editor.nodes(editor, {
|
34
|
+
at: sectionPath,
|
35
|
+
match: node => node.type === "freegridBox" && node.autoAlign
|
36
|
+
});
|
37
|
+
return boxData;
|
38
|
+
};
|
39
|
+
const handleGridItems = (gridItems, lastRow) => {
|
40
|
+
// to find the previously occupied rows
|
41
|
+
gridItems.forEach(item => {
|
42
|
+
const {
|
43
|
+
gridArea_xs: gridArea,
|
44
|
+
marginTop_xs,
|
45
|
+
height_xs,
|
46
|
+
type
|
47
|
+
} = item;
|
48
|
+
if (type === "paragraph") {
|
49
|
+
// non-freegridItem,
|
50
|
+
// some "paragraph" node is defaulty coming inside in box's children
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
const [startRow] = getGridArea(gridArea);
|
54
|
+
const marginTop = marginTop_xs ? Number(marginTop_xs) : 0;
|
55
|
+
const fullHeight = Number(height_xs) + marginTop;
|
56
|
+
const endRow = startRow + Math.floor(fullHeight / ROW_HEIGHT) + 1;
|
57
|
+
lastRow = Math.max(endRow, lastRow);
|
58
|
+
});
|
59
|
+
return {
|
60
|
+
lastRow
|
61
|
+
};
|
62
|
+
};
|
63
|
+
const handleNonGridItems = (nonGridItems, lastRow, editor, boxPath) => {
|
64
|
+
let containerHeight = (lastRow - 1) * ROW_HEIGHT;
|
65
|
+
let newlyAddedHeight = 0;
|
66
|
+
|
67
|
+
//place it on the next rows that are available
|
68
|
+
nonGridItems.forEach((item, index) => {
|
69
|
+
const {
|
70
|
+
height_xs,
|
71
|
+
type,
|
72
|
+
itemIndex
|
73
|
+
} = item;
|
74
|
+
if (type === "paragraph") {
|
75
|
+
// non-freegridItem
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
const startRow = lastRow || 1;
|
79
|
+
const DEFAULT_NEW_ELEMENT_MARGIN_TOP = 12;
|
80
|
+
let fullHeight = height_xs + DEFAULT_NEW_ELEMENT_MARGIN_TOP;
|
81
|
+
const endRow = startRow + Math.floor(fullHeight / ROW_HEIGHT) + 1;
|
82
|
+
const newGridArea = `${startRow} / 1 / ${startRow + 1} / 2`;
|
83
|
+
const currentElementPath = [...boxPath, itemIndex];
|
84
|
+
Transforms.setNodes(editor, {
|
85
|
+
gridArea_xs: newGridArea,
|
86
|
+
marginTop_xs: 12,
|
87
|
+
left_xs: 12,
|
88
|
+
xs_updatedOn: new Date().getTime()
|
89
|
+
}, {
|
90
|
+
at: currentElementPath
|
91
|
+
});
|
92
|
+
lastRow = Math.max(endRow, lastRow);
|
93
|
+
containerHeight += fullHeight;
|
94
|
+
newlyAddedHeight += fullHeight;
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
lastRow,
|
98
|
+
containerHeight,
|
99
|
+
newlyAddedHeight
|
100
|
+
};
|
101
|
+
};
|
102
|
+
const alignNewElementInContainer = (editor, boxPath, containerItems) => {
|
103
|
+
let lastRow = 1;
|
104
|
+
const gridItems = [];
|
105
|
+
const nonGridItems = [];
|
106
|
+
containerItems.forEach((item, index) => {
|
107
|
+
if (item?.gridArea_xs) {
|
108
|
+
gridItems.push({
|
109
|
+
...item,
|
110
|
+
itemIndex: index
|
111
|
+
});
|
112
|
+
} else {
|
113
|
+
nonGridItems.push({
|
114
|
+
...item,
|
115
|
+
itemIndex: index
|
116
|
+
});
|
117
|
+
}
|
118
|
+
});
|
119
|
+
const {
|
120
|
+
lastRow: lastRowOccupied
|
121
|
+
} = handleGridItems(gridItems, lastRow);
|
122
|
+
lastRow = lastRowOccupied;
|
123
|
+
const {
|
124
|
+
lastRow: lastRowTaken,
|
125
|
+
containerHeight,
|
126
|
+
newlyAddedHeight
|
127
|
+
} = handleNonGridItems(nonGridItems, lastRow, editor, boxPath);
|
128
|
+
lastRow = lastRowTaken;
|
129
|
+
return {
|
130
|
+
lastRow,
|
131
|
+
containerHeight,
|
132
|
+
newlyAddedHeight
|
133
|
+
};
|
134
|
+
};
|
135
|
+
const getAncestorFreeGridContainers = (editor, path) => {
|
136
|
+
const containers = [...Editor.nodes(editor, {
|
137
|
+
at: path,
|
138
|
+
// Start from the current path
|
139
|
+
match: (node, nodePath) => {
|
140
|
+
const container = ["freegridBox", "freegrid"].includes(node.type);
|
141
|
+
return container;
|
142
|
+
},
|
143
|
+
reverse: true // Go upwards in the document tree
|
144
|
+
})].filter(([node, nodePath]) => nodePath.length <= path.length);
|
145
|
+
return containers;
|
146
|
+
};
|
147
|
+
export const handleContainers = (editor, boxPath, extraHeight) => {
|
148
|
+
const containers = getAncestorFreeGridContainers(editor, boxPath);
|
149
|
+
let lastChildStartRow;
|
150
|
+
let lastChildEndRow;
|
151
|
+
let lastChildPath;
|
152
|
+
const containerData = [];
|
153
|
+
for (let i = containers.length - 1; i >= 0; i--) {
|
154
|
+
const container = containers[i];
|
155
|
+
const childContainer = containers[i + 1];
|
156
|
+
const [containerNode, containerPath] = container;
|
157
|
+
const {
|
158
|
+
gridArea_xs,
|
159
|
+
height_xs,
|
160
|
+
marginTop_xs
|
161
|
+
} = containerNode;
|
162
|
+
const [startRow] = gridArea_xs ? getGridArea(gridArea_xs) : [0]; // there is no grid area for section nodes
|
163
|
+
|
164
|
+
let newHeight = Number(height_xs) + extraHeight;
|
165
|
+
let fullHeight = newHeight + Number(marginTop_xs); // to find end row
|
166
|
+
|
167
|
+
if (!childContainer) {
|
168
|
+
const endRow = startRow + Math.floor(fullHeight / ROW_HEIGHT) + 1;
|
169
|
+
containerData.push({
|
170
|
+
moveRows: 0,
|
171
|
+
extraHeight,
|
172
|
+
containerPath,
|
173
|
+
newHeight,
|
174
|
+
containerNode,
|
175
|
+
lastChildStartRow
|
176
|
+
});
|
177
|
+
lastChildStartRow = startRow;
|
178
|
+
lastChildEndRow = endRow;
|
179
|
+
} else {
|
180
|
+
const lastChildIndex = lastChildPath[containerPath.length];
|
181
|
+
const firstOverlappedRow = findFirstRowOverlap(containerNode?.children, lastChildStartRow, lastChildEndRow, lastChildIndex);
|
182
|
+
const moveRows = firstOverlappedRow ? lastChildEndRow - firstOverlappedRow : 0;
|
183
|
+
newHeight = newHeight + moveRows * ROW_HEIGHT;
|
184
|
+
fullHeight = newHeight + Number(marginTop_xs);
|
185
|
+
const newEndRow = startRow + Math.floor(fullHeight / ROW_HEIGHT) + 1;
|
186
|
+
containerData.push({
|
187
|
+
moveRows,
|
188
|
+
extraHeight,
|
189
|
+
childIndex: lastChildIndex,
|
190
|
+
newHeight,
|
191
|
+
containerPath,
|
192
|
+
containerNode,
|
193
|
+
lastChildStartRow
|
194
|
+
});
|
195
|
+
lastChildStartRow = startRow;
|
196
|
+
lastChildEndRow = newEndRow;
|
197
|
+
}
|
198
|
+
lastChildPath = containerPath;
|
199
|
+
}
|
200
|
+
return containerData;
|
201
|
+
};
|
202
|
+
export const moveOverlappedItems = (editor, moveRows, containerItems, containerPath, childIndex, lastChildStartRow) => {
|
203
|
+
containerItems?.forEach((gridItem, index) => {
|
204
|
+
const isChildEle = childIndex === index;
|
205
|
+
if (isChildEle) {
|
206
|
+
return;
|
207
|
+
}
|
208
|
+
if (gridItem.type === "paragraph") {
|
209
|
+
return;
|
210
|
+
}
|
211
|
+
const {
|
212
|
+
gridArea_xs: gridArea
|
213
|
+
} = gridItem;
|
214
|
+
const [itemStartRow] = getGridArea(gridArea);
|
215
|
+
if (itemStartRow >= lastChildStartRow) {
|
216
|
+
const row = itemStartRow + moveRows;
|
217
|
+
const newGridArea = `${row} / 1 / ${row + 1} / 2`;
|
218
|
+
const currentElementPath = [...containerPath, index];
|
219
|
+
Transforms.setNodes(editor, {
|
220
|
+
gridArea_xs: newGridArea
|
221
|
+
}, {
|
222
|
+
at: currentElementPath
|
223
|
+
});
|
224
|
+
}
|
225
|
+
});
|
226
|
+
};
|
227
|
+
export const handleBoxAlignment = (editor, sectionNode, sectionPath) => {
|
228
|
+
const [boxNode, boxPath] = getBoxToAutoAlign(editor, sectionPath);
|
229
|
+
Transforms.setNodes(editor, {
|
230
|
+
autoAlign: false
|
231
|
+
}, {
|
232
|
+
at: boxPath
|
233
|
+
});
|
234
|
+
const containerItems = boxNode?.children || [];
|
235
|
+
const {
|
236
|
+
containerHeight
|
237
|
+
} = alignNewElementInContainer(editor, boxPath, containerItems);
|
238
|
+
const bufferHeight = 12;
|
239
|
+
const newHeight = containerHeight + bufferHeight;
|
240
|
+
const {
|
241
|
+
height_xs
|
242
|
+
} = boxNode;
|
243
|
+
const oldHeight = Number(height_xs);
|
244
|
+
const extraHeight = newHeight - oldHeight;
|
245
|
+
if (extraHeight > 0) {
|
246
|
+
const containerData = handleContainers(editor, boxPath, extraHeight);
|
247
|
+
containerData.forEach(container => {
|
248
|
+
const {
|
249
|
+
moveRows,
|
250
|
+
containerNode,
|
251
|
+
containerPath,
|
252
|
+
newHeight,
|
253
|
+
childIndex,
|
254
|
+
lastChildStartRow
|
255
|
+
} = container;
|
256
|
+
if (moveRows) {
|
257
|
+
moveOverlappedItems(editor, moveRows, containerNode?.children, containerPath, childIndex, lastChildStartRow);
|
258
|
+
}
|
259
|
+
Transforms.setNodes(editor, {
|
260
|
+
height_xs: newHeight,
|
261
|
+
xs_updatedOn: new Date().getTime()
|
262
|
+
}, {
|
263
|
+
at: containerPath
|
264
|
+
});
|
265
|
+
});
|
266
|
+
}
|
267
|
+
};
|
@@ -1,149 +1,232 @@
|
|
1
|
-
import React, { useEffect, useRef } from "react";
|
1
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
2
2
|
import { Box } from "@mui/material";
|
3
3
|
import useVirtualElementStyles from "./styles";
|
4
4
|
import updateAutoProps from "./updateAutoProps";
|
5
|
-
import { calculateGridArea } from "../Utils/gridDropItem";
|
5
|
+
import { ROW_HEIGHT, calculateGridArea } from "../Utils/gridDropItem";
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
7
7
|
const ROOT_ITEM_CLASS = ".freegrid-item.path-3";
|
8
|
+
export function getStartRow(el) {
|
9
|
+
const gridArea = el.dataset.gridAreaXs;
|
10
|
+
if (gridArea) {
|
11
|
+
const [startRow] = gridArea.split("/").map(num => parseInt(num));
|
12
|
+
return startRow;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
function appendGridOccupied(domItem, startRow, fullHeight, lastRow) {
|
16
|
+
const endRow = startRow + Math.floor(fullHeight / ROW_HEIGHT) + 1;
|
17
|
+
lastRow = Math.max(endRow, lastRow);
|
18
|
+
const gridArea = `${startRow}/1/${endRow}/2`;
|
19
|
+
domItem.style.setProperty("--gridArea_xs", gridArea);
|
20
|
+
domItem.dataset.gridAreaXs = gridArea;
|
21
|
+
domItem.classList.add("exclude-virtual");
|
22
|
+
return {
|
23
|
+
domItem,
|
24
|
+
updatedLastRow: lastRow,
|
25
|
+
gridArea
|
26
|
+
};
|
27
|
+
}
|
8
28
|
|
9
29
|
// Function to group items by path and calculate heights
|
10
|
-
function groupByPathAndCalculateHeight(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
// Step 1: Group items based on their path
|
15
|
-
data.forEach(item => {
|
16
|
-
const segments = item.path.split("|");
|
17
|
-
let current = root;
|
18
|
-
segments.forEach((segment, index) => {
|
19
|
-
if (!current[segment]) {
|
20
|
-
current[segment] = {
|
21
|
-
children: {},
|
22
|
-
props: {
|
23
|
-
height: 0
|
24
|
-
}
|
25
|
-
};
|
26
|
-
}
|
27
|
-
if (index === segments.length - 1) {
|
28
|
-
// Assign the properties of the item including height
|
29
|
-
current[segment] = {
|
30
|
-
...item,
|
31
|
-
children: current[segment].children
|
32
|
-
};
|
33
|
-
}
|
34
|
-
current = current[segment].children;
|
35
|
-
});
|
36
|
-
});
|
30
|
+
// function groupByPathAndCalculateHeight(allData) {
|
31
|
+
// const data = JSON.parse(JSON.stringify([...allData]));
|
32
|
+
// const root = {};
|
33
|
+
// const heightData = {};
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
return node.props.height;
|
43
|
-
}
|
35
|
+
// // Step 1: Group items based on their path
|
36
|
+
// data.forEach((item) => {
|
37
|
+
// const segments = item.path.split("|");
|
38
|
+
// let current = root;
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
});
|
40
|
+
// segments.forEach((segment, index) => {
|
41
|
+
// if (!current[segment]) {
|
42
|
+
// current[segment] = { children: {}, props: { height: 0 } };
|
43
|
+
// }
|
50
44
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
return totalHeight;
|
57
|
-
};
|
45
|
+
// if (index === segments.length - 1) {
|
46
|
+
// // Assign the properties of the item including height
|
47
|
+
// current[segment] = { ...item, children: current[segment].children };
|
48
|
+
// }
|
58
49
|
|
59
|
-
|
60
|
-
|
50
|
+
// current = current[segment].children;
|
51
|
+
// });
|
52
|
+
// });
|
53
|
+
|
54
|
+
// // Step 2: Recursively calculate the height of each parent based on children
|
55
|
+
// const calculateHeight = (node) => {
|
56
|
+
// if (!node.children || Object.keys(node.children).length === 0) {
|
57
|
+
// // Base case: If there are no children, return the node's height
|
58
|
+
// return node.props.height;
|
59
|
+
// }
|
60
|
+
|
61
|
+
// // Calculate the height by summing the heights of all children
|
62
|
+
// let totalHeight = 0;
|
63
|
+
// Object.values(node.children).forEach((child) => {
|
64
|
+
// totalHeight += calculateHeight(child);
|
65
|
+
// });
|
66
|
+
|
67
|
+
// // Update the parent's height to be the total height of its children
|
68
|
+
// node.props.height = totalHeight;
|
69
|
+
// if (node?.path) {
|
70
|
+
// heightData[node.path] = totalHeight;
|
71
|
+
// }
|
72
|
+
// return totalHeight;
|
73
|
+
// };
|
74
|
+
|
75
|
+
// // Start calculation from the root
|
76
|
+
// Object.values(root).forEach((node) => calculateHeight(node));
|
77
|
+
|
78
|
+
// return { root, heightData };
|
79
|
+
// }
|
80
|
+
|
81
|
+
const handleGridItem = (dom, lastRow) => {
|
82
|
+
const startRow = getStartRow(dom);
|
83
|
+
const {
|
84
|
+
marginTopXs,
|
85
|
+
heightXs
|
86
|
+
} = dom.dataset;
|
87
|
+
const marginTop = marginTopXs ? Number(marginTopXs) : 0;
|
88
|
+
const fullHeight = Number(heightXs) + marginTop;
|
89
|
+
return appendGridOccupied(dom, startRow, fullHeight, lastRow);
|
90
|
+
};
|
91
|
+
const handleNonGridItem = (dom, lastRow) => {
|
92
|
+
const rect = dom.getBoundingClientRect();
|
93
|
+
dom.style.setProperty("--height_xs", rect.height + "px"); // assign the auto height that taken
|
94
|
+
const startRow = lastRow || 1;
|
95
|
+
const DEFAULT_NEW_ELEMENT_MARGIN_TOP = 12;
|
96
|
+
let fullHeight = rect.height + DEFAULT_NEW_ELEMENT_MARGIN_TOP;
|
97
|
+
const gridOccupiedData = appendGridOccupied(dom, startRow, fullHeight, lastRow);
|
61
98
|
return {
|
62
|
-
|
63
|
-
|
99
|
+
...gridOccupiedData,
|
100
|
+
fullHeight
|
64
101
|
};
|
65
|
-
}
|
102
|
+
};
|
103
|
+
const appendContainerItems = async (sectionCls, virtualRef, dataSets) => {
|
104
|
+
const cloneNode = document.querySelector(sectionCls)?.cloneNode(true);
|
105
|
+
const items = cloneNode?.querySelectorAll(ROOT_ITEM_CLASS) || [];
|
106
|
+
if (!cloneNode || !items?.length || !virtualRef.current) {
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
|
110
|
+
// Remove all existing elements inside virtualRef.current
|
111
|
+
virtualRef.current.innerHTML = "";
|
112
|
+
virtualRef.current.style.height = `auto`;
|
113
|
+
virtualRef.current.style.gridTemplateRows = `unset`;
|
114
|
+
|
115
|
+
// temporary append section items to get the dom styles
|
116
|
+
virtualRef.current.append(...items);
|
117
|
+
let itemsHTML = "";
|
118
|
+
let lastRow = 0;
|
119
|
+
const gridItems = [];
|
120
|
+
const nonGridItems = [];
|
121
|
+
items.forEach(item => {
|
122
|
+
if (getStartRow(item)) {
|
123
|
+
gridItems.push(item);
|
124
|
+
} else {
|
125
|
+
nonGridItems.push(item);
|
126
|
+
}
|
127
|
+
});
|
128
|
+
|
129
|
+
// to find the previously occupied rows
|
130
|
+
gridItems.forEach(item => {
|
131
|
+
const {
|
132
|
+
updatedLastRow,
|
133
|
+
domItem
|
134
|
+
} = handleGridItem(item, lastRow);
|
135
|
+
lastRow = updatedLastRow;
|
136
|
+
itemsHTML += domItem.outerHTML;
|
137
|
+
});
|
138
|
+
let containerHeight = lastRow ? (lastRow - 1) * ROW_HEIGHT : 0;
|
139
|
+
|
140
|
+
//place it on the next rows that are available
|
141
|
+
nonGridItems.forEach(item => {
|
142
|
+
const {
|
143
|
+
domItem,
|
144
|
+
updatedLastRow,
|
145
|
+
fullHeight
|
146
|
+
} = handleNonGridItem(item, lastRow);
|
147
|
+
lastRow = updatedLastRow;
|
148
|
+
itemsHTML += domItem.outerHTML;
|
149
|
+
containerHeight += fullHeight;
|
150
|
+
});
|
151
|
+
const oldSectionHeight = dataSets["data-height-xs"];
|
152
|
+
const newHeight = oldSectionHeight && oldSectionHeight > containerHeight ? oldSectionHeight : containerHeight;
|
153
|
+
virtualRef.current.style.height = `${newHeight}px`;
|
154
|
+
virtualRef.current.style.gridTemplateRows = `repeat(${lastRow - 1}, ${ROW_HEIGHT}px)`;
|
155
|
+
virtualRef.current.innerHTML = itemsHTML;
|
156
|
+
};
|
66
157
|
const VirtualElement = props => {
|
67
158
|
const classes = useVirtualElementStyles();
|
68
159
|
const {
|
69
160
|
editor,
|
70
161
|
path,
|
71
|
-
|
72
|
-
|
162
|
+
updated_at,
|
163
|
+
sectionCls,
|
164
|
+
dataSets
|
73
165
|
} = props;
|
74
|
-
const cloneNode = parentEle?.cloneNode(true);
|
75
166
|
const virtualRef = useRef();
|
167
|
+
const [toggleUpdate, setToggleUpdate] = useState(false);
|
76
168
|
useEffect(() => {
|
77
169
|
if (virtualRef?.current) {
|
78
170
|
setTimeout(() => {
|
79
171
|
const allData = calculateProps(path, virtualRef?.current, ROOT_ITEM_CLASS, []);
|
80
|
-
const groupData = groupByPathAndCalculateHeight(allData);
|
172
|
+
// const groupData = groupByPathAndCalculateHeight(allData);
|
173
|
+
// console.log("allData", allData);
|
81
174
|
// it should trigger by auto alignment or on clicking mobile view change
|
82
|
-
updateAutoProps(editor, allData, "xs"
|
175
|
+
updateAutoProps(editor, allData, "xs");
|
83
176
|
}, 100);
|
177
|
+
setToggleUpdate(prev => !prev);
|
84
178
|
}
|
85
179
|
}, [updated_at, virtualRef?.current]);
|
86
180
|
const calculateProps = (curPath, dom, domClass, allData) => {
|
87
181
|
const rect = dom?.getBoundingClientRect();
|
88
|
-
|
182
|
+
|
183
|
+
// const sectionRect = virtualRef?.current?.getBoundingClientRect();
|
184
|
+
|
185
|
+
const bufferHeight = 12; // for spacing
|
186
|
+
|
89
187
|
const sectionProps = {
|
90
188
|
path: curPath,
|
91
189
|
props: {
|
92
|
-
height: rect?.height
|
190
|
+
height: rect?.height + bufferHeight
|
93
191
|
}
|
94
192
|
};
|
95
193
|
const itemsData = [];
|
96
|
-
const items = dom.querySelectorAll(domClass);
|
97
|
-
const nextItemPathLength = curPath?.split("|").length + 2;
|
98
|
-
let sectionHeight = 12;
|
194
|
+
const items = dom ? dom.querySelectorAll(domClass) : [];
|
99
195
|
for (let i = 0; i < items.length; i++) {
|
100
|
-
const
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
}
|
118
|
-
}
|
119
|
-
if (dom?.classList.contains("type_box")) {
|
120
|
-
const y = Math.abs(sectionRect.top - rect?.top);
|
121
|
-
sectionProps.props.gridArea = calculateGridArea(y);
|
122
|
-
}
|
123
|
-
if (sectionHeight > sectionProps?.props?.height) {
|
124
|
-
sectionProps.props.height = sectionHeight;
|
196
|
+
const item = items[i];
|
197
|
+
const itemRect = item?.getBoundingClientRect();
|
198
|
+
const {
|
199
|
+
path
|
200
|
+
} = item?.dataset;
|
201
|
+
const y = Math.abs(rect.top - itemRect?.top);
|
202
|
+
itemsData.push({
|
203
|
+
path,
|
204
|
+
props: {
|
205
|
+
top: y,
|
206
|
+
left: 24,
|
207
|
+
marginTop: 12,
|
208
|
+
width: itemRect?.width,
|
209
|
+
height: itemRect?.height,
|
210
|
+
gridArea: calculateGridArea(y)
|
211
|
+
}
|
212
|
+
});
|
125
213
|
}
|
126
214
|
allData = [sectionProps, [...allData, ...itemsData]]?.flat();
|
127
215
|
return allData;
|
128
216
|
};
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
for (let i = 0; i < items?.length; i++) {
|
133
|
-
items[i].classList.add("exclude-virtual");
|
134
|
-
itemsHTML += items[i].outerHTML;
|
135
|
-
}
|
136
|
-
return itemsHTML;
|
137
|
-
};
|
217
|
+
useMemo(() => {
|
218
|
+
return appendContainerItems(sectionCls, virtualRef, dataSets);
|
219
|
+
}, [toggleUpdate]);
|
138
220
|
return /*#__PURE__*/_jsx(Box, {
|
139
221
|
className: "mobile-virtual-mode",
|
140
222
|
ref: virtualRef,
|
141
|
-
sx:
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
223
|
+
sx: {
|
224
|
+
display: "grid",
|
225
|
+
gridTemplateColumns: "100%",
|
226
|
+
visibility: "hidden",
|
227
|
+
// height: `${containerHeight}px !important`,
|
228
|
+
// gridTemplateRows: `repeat(${lastRow - 1}, ${ROW_HEIGHT}px)`,
|
229
|
+
...classes.root
|
147
230
|
},
|
148
231
|
"aria-hidden": "true"
|
149
232
|
});
|