@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
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from "react";
|
1
|
+
import React, { useEffect, useMemo, useRef } from "react";
|
2
2
|
import { Path, Transforms, Node } from "slate";
|
3
3
|
import { ReactEditor, useSlateStatic } from "slate-react";
|
4
4
|
import { Box, useTheme } from "@mui/material";
|
@@ -43,7 +43,8 @@ const FreeGrid = props => {
|
|
43
43
|
} = props;
|
44
44
|
const {
|
45
45
|
sectionName,
|
46
|
-
sectionBorderRadius
|
46
|
+
sectionBorderRadius,
|
47
|
+
height_xs
|
47
48
|
} = element;
|
48
49
|
const {
|
49
50
|
readOnly,
|
@@ -62,13 +63,17 @@ const FreeGrid = props => {
|
|
62
63
|
height
|
63
64
|
} = breakpointValues(element.type, breakpoint, element);
|
64
65
|
const {
|
65
|
-
setSelectedElement
|
66
|
+
setSelectedElement,
|
67
|
+
setAutoAlign,
|
68
|
+
autoAlign
|
66
69
|
} = useEditorContext();
|
70
|
+
const count = useRef(2);
|
71
|
+
const childrenCountRef = useRef(element?.children?.length);
|
67
72
|
const onChange = data => {
|
68
73
|
const append = breakpoint === "lg" ? "" : `_${breakpoint}`;
|
69
74
|
const updateData = {
|
70
75
|
...data,
|
71
|
-
[`height${append}`]:
|
76
|
+
[`height${append}`]: data.height
|
72
77
|
};
|
73
78
|
if (append !== "") {
|
74
79
|
delete updateData.height;
|
@@ -130,6 +135,10 @@ const FreeGrid = props => {
|
|
130
135
|
setSelectedElement
|
131
136
|
});
|
132
137
|
break;
|
138
|
+
case "forceAutoAlignment":
|
139
|
+
setAutoAlign(true);
|
140
|
+
setSelectedElement({});
|
141
|
+
break;
|
133
142
|
default:
|
134
143
|
}
|
135
144
|
} catch (err) {
|
@@ -144,9 +153,12 @@ const FreeGrid = props => {
|
|
144
153
|
console.log(err);
|
145
154
|
}
|
146
155
|
};
|
156
|
+
useEffect(() => {
|
157
|
+
childrenCountRef.current = element?.children?.length;
|
158
|
+
}, [element?.children?.length]);
|
147
159
|
const handleAddElementClick = type => () => {
|
148
160
|
const isEmpty = isEmptySection();
|
149
|
-
const insertAt = isEmpty ? [...path, 0] : [...path,
|
161
|
+
const insertAt = isEmpty ? [...path, 0] : [...path, childrenCountRef.current];
|
150
162
|
switch (type) {
|
151
163
|
case "addText":
|
152
164
|
Transforms.insertNodes(editor, [{
|
@@ -353,6 +365,17 @@ const FreeGrid = props => {
|
|
353
365
|
break;
|
354
366
|
default:
|
355
367
|
}
|
368
|
+
if (breakpoint === "lg") {
|
369
|
+
// auto align in mobile
|
370
|
+
Transforms.setNodes(editor, {
|
371
|
+
xs_updatedOn: null,
|
372
|
+
updated_at: new Date().getTime()
|
373
|
+
}, {
|
374
|
+
at: path
|
375
|
+
});
|
376
|
+
}
|
377
|
+
count.current = count.current + 1;
|
378
|
+
|
356
379
|
// focus on newly added element
|
357
380
|
focusOnNewItem(editor, insertAt, {
|
358
381
|
setSelectedElement
|
@@ -424,8 +447,16 @@ const FreeGrid = props => {
|
|
424
447
|
}
|
425
448
|
}, theme);
|
426
449
|
const sectionTypeOptions = (itemOptions?.section || []).filter(f => (hideTools || []).indexOf(f) === -1);
|
450
|
+
const id = useMemo(() => {
|
451
|
+
let eleId = `freegrid_container_${path.join("|")}_${breakpoint}`;
|
452
|
+
if (autoAlign) {
|
453
|
+
eleId += `_${updated_at}`; // re-render component on force auto align
|
454
|
+
}
|
455
|
+
|
456
|
+
return eleId;
|
457
|
+
}, [autoAlign, updated_at, breakpoint, path]);
|
427
458
|
return /*#__PURE__*/_jsx(RnD, {
|
428
|
-
id:
|
459
|
+
id: id,
|
429
460
|
className: `
|
430
461
|
freegrid-section breakpoint-${breakpoint}
|
431
462
|
freegrid-section_${path.join("_")}
|
@@ -437,6 +468,9 @@ const FreeGrid = props => {
|
|
437
468
|
position: "relative",
|
438
469
|
"--height": `${height}px`
|
439
470
|
},
|
471
|
+
dataSets: {
|
472
|
+
"data-height-xs": height_xs
|
473
|
+
},
|
440
474
|
defaultStyle: {
|
441
475
|
width: "100%",
|
442
476
|
height: height ? `${height}px` : "auto"
|
@@ -493,7 +527,8 @@ const FreeGrid = props => {
|
|
493
527
|
},
|
494
528
|
customProps: {
|
495
529
|
customProps
|
496
|
-
}
|
530
|
+
},
|
531
|
+
breakpoint
|
497
532
|
}
|
498
533
|
},
|
499
534
|
settings: {
|
@@ -505,8 +540,7 @@ const FreeGrid = props => {
|
|
505
540
|
path,
|
506
541
|
classes,
|
507
542
|
customProps,
|
508
|
-
translation
|
509
|
-
customProps
|
543
|
+
translation
|
510
544
|
}
|
511
545
|
}
|
512
546
|
},
|
@@ -516,6 +550,7 @@ const FreeGrid = props => {
|
|
516
550
|
handleContextMenuClick: handleContextMenuClick,
|
517
551
|
translation: translation,
|
518
552
|
customProps: customProps,
|
553
|
+
sectionElement: element,
|
519
554
|
children: /*#__PURE__*/_jsxs(Box, {
|
520
555
|
...attributes,
|
521
556
|
id: sectionName,
|
@@ -37,7 +37,11 @@ const FreeGridBox = props => {
|
|
37
37
|
sectionBorderRadius,
|
38
38
|
borderWidth,
|
39
39
|
borderColor,
|
40
|
-
borderStyle
|
40
|
+
borderStyle,
|
41
|
+
height_xs,
|
42
|
+
marginTop_xs,
|
43
|
+
gridArea_xs,
|
44
|
+
width_xs
|
41
45
|
} = element;
|
42
46
|
// get values based on breakpoint size
|
43
47
|
const {
|
@@ -168,12 +172,22 @@ const FreeGridBox = props => {
|
|
168
172
|
"--gridArea": `${gridArea}`,
|
169
173
|
"--width": `${width}px`,
|
170
174
|
"--height": `${height}px`,
|
171
|
-
"--zIndex": 100 + arrangeIndex
|
175
|
+
"--zIndex": 100 + arrangeIndex,
|
176
|
+
"--height_xs": height_xs ? `${height_xs}px` : "auto",
|
177
|
+
"--marginTop_xs": marginTop_xs ? `${marginTop_xs}px` : "24px"
|
178
|
+
// "--gridArea_xs": gridArea_xs ? gridArea_xs : "unset",
|
172
179
|
},
|
180
|
+
|
173
181
|
defaultStyle: {
|
174
182
|
height: `${height}px`,
|
175
183
|
width: `${width}px`
|
176
184
|
},
|
185
|
+
dataSets: {
|
186
|
+
"data-grid-area-xs": gridArea_xs,
|
187
|
+
"data-margin-top-xs": marginTop_xs,
|
188
|
+
"data-height-xs": height_xs,
|
189
|
+
"data-width-xs": width_xs
|
190
|
+
},
|
177
191
|
gridArea: gridArea,
|
178
192
|
onChange: onChange,
|
179
193
|
delta: {
|
@@ -35,7 +35,11 @@ const FreeGridItem = props => {
|
|
35
35
|
const {
|
36
36
|
updated_at,
|
37
37
|
childType,
|
38
|
-
zIndex
|
38
|
+
zIndex,
|
39
|
+
height_xs,
|
40
|
+
width_xs,
|
41
|
+
marginTop_xs,
|
42
|
+
gridArea_xs
|
39
43
|
} = element;
|
40
44
|
// get values based on breakpoint size
|
41
45
|
const {
|
@@ -53,6 +57,9 @@ const FreeGridItem = props => {
|
|
53
57
|
const arrangeIndex = zIndex === undefined ? path[path.length - 1] : zIndex;
|
54
58
|
const [popup, setPopup] = useState(null);
|
55
59
|
const onChangeSettings = () => {};
|
60
|
+
// const refInput = useRef();
|
61
|
+
// const [virtualHeight, setVirtualHeight] = useState(height || 0);
|
62
|
+
|
56
63
|
const onChange = data => {
|
57
64
|
let updateData = {
|
58
65
|
...data
|
@@ -108,6 +115,13 @@ const FreeGridItem = props => {
|
|
108
115
|
Transforms.removeNodes(editor, {
|
109
116
|
at: path
|
110
117
|
});
|
118
|
+
const parentPath = Path.parent(path);
|
119
|
+
Transforms.setNodes(editor, {
|
120
|
+
xs_updatedOn: null,
|
121
|
+
updated_at: new Date().getTime()
|
122
|
+
}, {
|
123
|
+
at: parentPath
|
124
|
+
});
|
111
125
|
} catch (err) {
|
112
126
|
console.log(err);
|
113
127
|
}
|
@@ -253,7 +267,17 @@ const FreeGridItem = props => {
|
|
253
267
|
"--gridArea": `${gridArea}`,
|
254
268
|
"--width": `${width}px`,
|
255
269
|
"--height": `${height}px`,
|
256
|
-
"--zIndex": 100 + arrangeIndex
|
270
|
+
"--zIndex": 100 + arrangeIndex,
|
271
|
+
"--height_xs": height_xs ? `${height_xs}px` : "auto",
|
272
|
+
"--marginTop_xs": marginTop_xs ? `${marginTop_xs}px` : "0px"
|
273
|
+
// "--gridArea_xs": gridArea_xs ? gridArea_xs : "unset",
|
274
|
+
},
|
275
|
+
|
276
|
+
dataSets: {
|
277
|
+
"data-grid-area-xs": gridArea_xs,
|
278
|
+
"data-margin-top-xs": marginTop_xs,
|
279
|
+
"data-height-xs": height_xs,
|
280
|
+
"data-width-xs": width_xs
|
257
281
|
},
|
258
282
|
defaultStyle: {
|
259
283
|
height: `${height}px`,
|
@@ -5,7 +5,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
const More = props => {
|
6
6
|
const {
|
7
7
|
handleClick,
|
8
|
-
translation
|
8
|
+
translation,
|
9
|
+
breakpoint
|
9
10
|
} = props;
|
10
11
|
return /*#__PURE__*/_jsx(Box, {
|
11
12
|
children: /*#__PURE__*/_jsxs(List, {
|
@@ -18,7 +19,11 @@ const More = props => {
|
|
18
19
|
className: "item-wrapper",
|
19
20
|
onClick: handleClick("duplicateSection"),
|
20
21
|
children: translation?.translation("Duplicate Section")
|
21
|
-
})
|
22
|
+
}), breakpoint === "xs" ? /*#__PURE__*/_jsx(ListItemButton, {
|
23
|
+
className: "item-wrapper",
|
24
|
+
onClick: handleClick("forceAutoAlignment"),
|
25
|
+
children: "Force Auto Alignment"
|
26
|
+
}) : null]
|
22
27
|
})
|
23
28
|
});
|
24
29
|
};
|
@@ -193,6 +193,7 @@ const TableCell = props => {
|
|
193
193
|
setHoverPath(null);
|
194
194
|
};
|
195
195
|
const onMouseDownInCell = e => {
|
196
|
+
setHoverPath(path);
|
196
197
|
if (
|
197
198
|
// for shift selection
|
198
199
|
e.shiftKey && startCellPath?.length && startCellPath.toString() !== path.toString()) {
|
@@ -376,6 +377,9 @@ const TableCell = props => {
|
|
376
377
|
setOpenSettings(false);
|
377
378
|
};
|
378
379
|
const onSave = data => {
|
380
|
+
const tableProps = table.getTableProps({
|
381
|
+
at: path
|
382
|
+
});
|
379
383
|
const updateData = {
|
380
384
|
...data
|
381
385
|
};
|
@@ -45,12 +45,13 @@ const MiniEditor = props => {
|
|
45
45
|
const {
|
46
46
|
translationMock
|
47
47
|
} = otherProps;
|
48
|
+
const dummyTranslation = () => {};
|
48
49
|
const customProps = {
|
49
50
|
...(otherProps || {}),
|
50
51
|
readOnly: isReadOnly,
|
51
52
|
editorPlaceholder: miniEditorPlaceholder,
|
52
53
|
page_id: id,
|
53
|
-
translation: translation || translationMock
|
54
|
+
translation: translation || translationMock || dummyTranslation
|
54
55
|
};
|
55
56
|
const [mentions, setMentions] = useMentions({
|
56
57
|
editor,
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
3
|
+
const ClearAllIcon = () => /*#__PURE__*/_jsxs("svg", {
|
4
|
+
xmlns: "http://www.w3.org/2000/svg",
|
5
|
+
width: "20",
|
6
|
+
height: "20",
|
7
|
+
viewBox: "0 0 20 20",
|
8
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
9
|
+
x: "4",
|
10
|
+
y: "5",
|
11
|
+
width: "12",
|
12
|
+
height: "2",
|
13
|
+
rx: "1",
|
14
|
+
fill: "currentColor"
|
15
|
+
}), /*#__PURE__*/_jsx("rect", {
|
16
|
+
x: "4",
|
17
|
+
y: "9",
|
18
|
+
width: "10",
|
19
|
+
height: "2",
|
20
|
+
rx: "1",
|
21
|
+
fill: "currentColor"
|
22
|
+
}), /*#__PURE__*/_jsx("rect", {
|
23
|
+
x: "4",
|
24
|
+
y: "13",
|
25
|
+
width: "12",
|
26
|
+
height: "2",
|
27
|
+
rx: "1",
|
28
|
+
fill: "currentColor"
|
29
|
+
})]
|
30
|
+
});
|
31
|
+
export default ClearAllIcon;
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import { Transforms, Node, Path } from "slate";
|
1
|
+
import { Transforms, Node, Path, Editor } from "slate";
|
2
2
|
import { ReactEditor } from "slate-react";
|
3
3
|
import { handleNegativeInteger } from "../../../utils/helper";
|
4
|
+
import { handleBoxAlignment } from "../VirtualElement/helper";
|
4
5
|
export const ROW_HEIGHT = 50;
|
5
6
|
|
6
7
|
// const MARGIN_OF = {
|
@@ -21,9 +22,18 @@ export function updateRows() {}
|
|
21
22
|
export function updateCols() {}
|
22
23
|
const handleMoveNode = (editor, path, newPath, {
|
23
24
|
isEmpty
|
24
|
-
}) => {
|
25
|
+
}, autoAlign) => {
|
25
26
|
try {
|
26
|
-
|
27
|
+
let replaceNode = Node.get(editor, path);
|
28
|
+
if (autoAlign) {
|
29
|
+
// reset node for auto alignment in mobile
|
30
|
+
replaceNode = {
|
31
|
+
...replaceNode,
|
32
|
+
gridArea_xs: null,
|
33
|
+
xs_updatedOn: null,
|
34
|
+
marginTop_xs: null
|
35
|
+
};
|
36
|
+
}
|
27
37
|
if (isEmpty) {
|
28
38
|
const toPath = [...newPath, 0];
|
29
39
|
Transforms.insertNodes(editor, [{
|
@@ -57,9 +67,10 @@ const handleMoveNode = (editor, path, newPath, {
|
|
57
67
|
* This method will update prop in child node so it will re-render and update the path
|
58
68
|
* @param {*} path - contains the parent section path
|
59
69
|
*/
|
60
|
-
const reRenderChildNodes = (editor, path) => {
|
70
|
+
export const reRenderChildNodes = (editor, path) => {
|
61
71
|
try {
|
62
72
|
const sectionNode = Node.get(editor, path);
|
73
|
+
console.log("sectionNode", sectionNode);
|
63
74
|
// parent node
|
64
75
|
Transforms.setNodes(editor, {
|
65
76
|
updated_at: new Date().getTime()
|
@@ -92,7 +103,9 @@ function isContainerElement(editor, moveTopath, props, appenBp) {
|
|
92
103
|
// get parent node
|
93
104
|
parentNode = Node.get(editor, Path.parent(dragItemPath));
|
94
105
|
}
|
106
|
+
console.log("moveTopath", moveTopath, path, parentPath, dragOver);
|
95
107
|
const moveToNode = Node.get(editor, moveTopath);
|
108
|
+
console.log("parentNode, moveToNode", parentNode, moveToNode);
|
96
109
|
const leftOfMoveToNode = moveToNode[`left${appenBp}`];
|
97
110
|
if (moveToNode.type === "freegridBox") {
|
98
111
|
if (parentNode.type === "freegridBox") {
|
@@ -127,6 +140,9 @@ function isContainerElement(editor, moveTopath, props, appenBp) {
|
|
127
140
|
console.log(err);
|
128
141
|
}
|
129
142
|
}
|
143
|
+
const isInsidePath = (from, moveTo) => {
|
144
|
+
return Path.isAncestor(from, moveTo);
|
145
|
+
};
|
130
146
|
export function onDropItem(props, parentClass) {
|
131
147
|
try {
|
132
148
|
const {
|
@@ -174,7 +190,17 @@ export function onDropItem(props, parentClass) {
|
|
174
190
|
}, {
|
175
191
|
at: path
|
176
192
|
});
|
177
|
-
|
193
|
+
let reRenderSectionPath;
|
194
|
+
const [sectionData] = Editor.nodes(editor, {
|
195
|
+
at: moveTo,
|
196
|
+
match: n => n.type === "freegrid"
|
197
|
+
});
|
198
|
+
const [sectionNode, sectionPath] = sectionData || [];
|
199
|
+
if (needMove && isInsidePath(from, moveTo)) {
|
200
|
+
reRenderSectionPath = sectionPath;
|
201
|
+
} else {
|
202
|
+
reRenderChildNodes(editor, from);
|
203
|
+
}
|
178
204
|
|
179
205
|
// move the node if section parent changed
|
180
206
|
if (needMove) {
|
@@ -183,10 +209,35 @@ export function onDropItem(props, parentClass) {
|
|
183
209
|
if (!isEmpty) {
|
184
210
|
newPath = [...newPath, toSectionNode?.children?.length];
|
185
211
|
}
|
212
|
+
const moveSectionToSection = from?.length === 2 && moveTo?.length === 2;
|
213
|
+
|
214
|
+
// const autoAlign = breakpoint === "lg" && moveSectionToSection;
|
215
|
+
const autoAlign = breakpoint === "lg";
|
216
|
+
|
217
|
+
// const boxNode = Node.get(editor, moveTo);
|
218
|
+
|
219
|
+
if (moveSectionToSection && autoAlign) {
|
220
|
+
// auto align in mobile
|
221
|
+
Transforms.setNodes(editor, {
|
222
|
+
xs_updatedOn: null
|
223
|
+
}, {
|
224
|
+
at: moveTo
|
225
|
+
});
|
226
|
+
} else if (autoAlign) {
|
227
|
+
Transforms.setNodes(editor, {
|
228
|
+
autoAlign: true,
|
229
|
+
xs_updatedOn: new Date().getTime()
|
230
|
+
}, {
|
231
|
+
at: moveTo
|
232
|
+
});
|
233
|
+
}
|
186
234
|
const rPath = handleMoveNode(editor, path, newPath, {
|
187
235
|
isEmpty
|
188
|
-
});
|
189
|
-
reRenderChildNodes(editor, moveTo);
|
236
|
+
}, autoAlign);
|
237
|
+
reRenderChildNodes(editor, reRenderSectionPath || moveTo);
|
238
|
+
if (autoAlign) {
|
239
|
+
handleBoxAlignment(editor, sectionNode, sectionPath);
|
240
|
+
}
|
190
241
|
return {
|
191
242
|
updated_at: rPath
|
192
243
|
};
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import { Box } from "@mui/material";
|
2
|
+
import { useAutoAlignStyles } from "./styles";
|
3
|
+
import { useEffect, useRef } from "react";
|
4
|
+
import { ROW_HEIGHT, calculateGridArea, reRenderChildNodes } from "../Utils/gridDropItem";
|
5
|
+
import updateAutoProps from "./updateAutoProps";
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
const ROOT_ITEM_CLASS = ".freegrid-item.path-3";
|
8
|
+
const getMarginTop = y => {
|
9
|
+
const calcMargin = y % ROW_HEIGHT;
|
10
|
+
return calcMargin <= 0 ? 0 : calcMargin;
|
11
|
+
};
|
12
|
+
function ForceAutoAlignment(props) {
|
13
|
+
const {
|
14
|
+
editor,
|
15
|
+
sectionCls,
|
16
|
+
path,
|
17
|
+
autoAlign,
|
18
|
+
setAutoAlign
|
19
|
+
} = props;
|
20
|
+
const classes = useAutoAlignStyles();
|
21
|
+
const virtualRef = useRef();
|
22
|
+
useEffect(() => {
|
23
|
+
let timeoutId;
|
24
|
+
if (virtualRef?.current && autoAlign) {
|
25
|
+
timeoutId = setTimeout(() => {
|
26
|
+
const allData = calculateProps(path, virtualRef?.current, ROOT_ITEM_CLASS, []);
|
27
|
+
updateAutoProps(editor, allData, "xs", true);
|
28
|
+
const currentSectionPath = path.split("|").map(m => parseInt(m));
|
29
|
+
reRenderChildNodes(editor, currentSectionPath);
|
30
|
+
setAutoAlign(false);
|
31
|
+
}, 100);
|
32
|
+
}
|
33
|
+
return () => {
|
34
|
+
if (timeoutId) {
|
35
|
+
clearTimeout(timeoutId);
|
36
|
+
}
|
37
|
+
};
|
38
|
+
}, [autoAlign, virtualRef?.current]);
|
39
|
+
const calculateProps = (curPath, dom, domClass, allData, parentDom) => {
|
40
|
+
const rect = dom?.getBoundingClientRect();
|
41
|
+
const bufferHeight = parentDom ? 0 : 12;
|
42
|
+
const sectionProps = {
|
43
|
+
path: curPath,
|
44
|
+
props: {
|
45
|
+
height: rect?.height + bufferHeight
|
46
|
+
}
|
47
|
+
};
|
48
|
+
const itemsData = [];
|
49
|
+
const items = dom.querySelectorAll(domClass);
|
50
|
+
const nextItemPathLength = curPath?.split("|").length + 2;
|
51
|
+
// let sectionHeight = 12;
|
52
|
+
for (let i = 0; i < items.length; i++) {
|
53
|
+
const itemRect = items[i]?.getBoundingClientRect();
|
54
|
+
if (items[i]?.classList.contains("type_box")) {
|
55
|
+
allData = calculateProps(items[i]?.dataset.path, items[i], `.freegrid-item.path-${nextItemPathLength}`, allData, dom);
|
56
|
+
} else {
|
57
|
+
const y = Math.abs(rect.top - itemRect?.top);
|
58
|
+
itemsData.push({
|
59
|
+
path: items[i]?.dataset.path,
|
60
|
+
props: {
|
61
|
+
top: y,
|
62
|
+
left: 24,
|
63
|
+
marginTop: getMarginTop(y),
|
64
|
+
width: itemRect?.width,
|
65
|
+
height: itemRect?.height,
|
66
|
+
gridArea: calculateGridArea(y)
|
67
|
+
}
|
68
|
+
});
|
69
|
+
// sectionHeight += itemRect?.height;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
if (dom?.classList.contains("type_box") && parentDom) {
|
74
|
+
const parentDomRect = parentDom?.getBoundingClientRect();
|
75
|
+
const y = Math.abs(parentDomRect.top - rect?.top);
|
76
|
+
sectionProps.props.gridArea = calculateGridArea(y);
|
77
|
+
sectionProps.props.left = 24;
|
78
|
+
sectionProps.props.marginTop = getMarginTop(y);
|
79
|
+
sectionProps.props.width = rect?.width;
|
80
|
+
}
|
81
|
+
allData = [sectionProps, [...allData, ...itemsData]]?.flat();
|
82
|
+
return allData;
|
83
|
+
};
|
84
|
+
const getItems = () => {
|
85
|
+
const cloneNode = document.querySelector(sectionCls)?.cloneNode(true);
|
86
|
+
const items = cloneNode?.querySelectorAll(ROOT_ITEM_CLASS) || [];
|
87
|
+
if (!cloneNode || !items?.length) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
let itemsHTML = "";
|
91
|
+
for (let i = 0; i < items?.length; i++) {
|
92
|
+
items[i].classList.add("exclude-virtual");
|
93
|
+
itemsHTML += items[i].outerHTML;
|
94
|
+
}
|
95
|
+
return itemsHTML;
|
96
|
+
};
|
97
|
+
return /*#__PURE__*/_jsx(Box, {
|
98
|
+
className: "force-mobile-virtual-mode",
|
99
|
+
ref: virtualRef,
|
100
|
+
sx: {
|
101
|
+
visibility: "hidden",
|
102
|
+
...classes.root
|
103
|
+
},
|
104
|
+
"aria-hidden": "true",
|
105
|
+
dangerouslySetInnerHTML: {
|
106
|
+
__html: getItems()
|
107
|
+
}
|
108
|
+
});
|
109
|
+
}
|
110
|
+
export default ForceAutoAlignment;
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import { useEffect, useRef } from "react";
|
2
|
+
import { Path, Transforms } from "slate";
|
3
|
+
import { getNode } from "../../../utils/helper";
|
4
|
+
import { ROW_HEIGHT } from "../Utils/gridDropItem";
|
5
|
+
import { findFirstRowOverlap, getGridArea, handleContainers, moveOverlappedItems } from "./helper";
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
const updateTextHeight = (editor, path, height) => {
|
8
|
+
if (!height) {
|
9
|
+
return;
|
10
|
+
}
|
11
|
+
const parentPath = Path.parent(path);
|
12
|
+
const currentNode = getNode(editor, parentPath);
|
13
|
+
const gridItems = currentNode?.children || [];
|
14
|
+
const isNewlyAddedElement = gridItems.some(gridItem => !gridItem.gridArea_xs && gridItem.type !== "paragraph");
|
15
|
+
if (isNewlyAddedElement) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
const textItemIndex = path[parentPath.length];
|
19
|
+
const textItem = gridItems.find((_, index) => textItemIndex === index);
|
20
|
+
const {
|
21
|
+
marginTop_xs: marginTop,
|
22
|
+
gridArea_xs: gridArea,
|
23
|
+
height_xs
|
24
|
+
} = textItem;
|
25
|
+
const oldHeight = height_xs + marginTop;
|
26
|
+
const newHeight = height + marginTop;
|
27
|
+
const extraHeight = newHeight - oldHeight;
|
28
|
+
let containerExtraHeight = extraHeight;
|
29
|
+
if (extraHeight > 0) {
|
30
|
+
const [startRow] = getGridArea(gridArea);
|
31
|
+
const newRows = Math.floor(newHeight / ROW_HEIGHT) + 1;
|
32
|
+
const endRow = startRow + newRows;
|
33
|
+
const firstOverlappedRow = findFirstRowOverlap(gridItems, startRow, endRow, textItemIndex);
|
34
|
+
if (firstOverlappedRow) {
|
35
|
+
const moveRows = endRow - firstOverlappedRow;
|
36
|
+
moveOverlappedItems(editor, moveRows, gridItems, parentPath, textItemIndex, startRow);
|
37
|
+
containerExtraHeight += moveRows * ROW_HEIGHT;
|
38
|
+
}
|
39
|
+
|
40
|
+
// handle containers (box and section)
|
41
|
+
const containerData = handleContainers(editor, parentPath, containerExtraHeight);
|
42
|
+
containerData.forEach(container => {
|
43
|
+
const {
|
44
|
+
moveRows,
|
45
|
+
containerNode,
|
46
|
+
containerPath,
|
47
|
+
newHeight,
|
48
|
+
childIndex,
|
49
|
+
lastChildStartRow
|
50
|
+
} = container;
|
51
|
+
if (moveRows) {
|
52
|
+
moveOverlappedItems(editor, moveRows, containerNode?.children, containerPath, childIndex, lastChildStartRow);
|
53
|
+
}
|
54
|
+
Transforms.setNodes(editor, {
|
55
|
+
height_xs: newHeight,
|
56
|
+
xs_updatedOn: new Date().getTime()
|
57
|
+
}, {
|
58
|
+
at: containerPath
|
59
|
+
});
|
60
|
+
});
|
61
|
+
Transforms.setNodes(editor, {
|
62
|
+
height_xs: height
|
63
|
+
}, {
|
64
|
+
at: path
|
65
|
+
});
|
66
|
+
}
|
67
|
+
};
|
68
|
+
function VirtualTextElement(props) {
|
69
|
+
const {
|
70
|
+
dataSets,
|
71
|
+
getCurrentEle,
|
72
|
+
path,
|
73
|
+
editor
|
74
|
+
} = props;
|
75
|
+
const textRef = useRef(null);
|
76
|
+
const currElement = getCurrentEle();
|
77
|
+
useEffect(() => {
|
78
|
+
const observer = new ResizeObserver(([entry]) => {
|
79
|
+
if (entry) {
|
80
|
+
const {
|
81
|
+
height
|
82
|
+
} = entry.contentRect;
|
83
|
+
updateTextHeight(editor, path, height);
|
84
|
+
}
|
85
|
+
});
|
86
|
+
const elementRef = textRef?.current;
|
87
|
+
if (elementRef) {
|
88
|
+
observer.observe(elementRef);
|
89
|
+
}
|
90
|
+
return () => {
|
91
|
+
const elementRef = textRef?.current;
|
92
|
+
if (elementRef) {
|
93
|
+
observer.unobserve(elementRef);
|
94
|
+
}
|
95
|
+
observer.disconnect();
|
96
|
+
};
|
97
|
+
}, []);
|
98
|
+
return /*#__PURE__*/_jsx("div", {
|
99
|
+
style: {
|
100
|
+
position: "fixed",
|
101
|
+
width: dataSets["data-width-xs"],
|
102
|
+
minHeight: "fit-content",
|
103
|
+
visibility: "hidden",
|
104
|
+
pointerEvents: "none",
|
105
|
+
right: 0,
|
106
|
+
top: 0
|
107
|
+
},
|
108
|
+
ref: textRef,
|
109
|
+
children: currElement?.innerText
|
110
|
+
});
|
111
|
+
}
|
112
|
+
export default VirtualTextElement;
|