@flozy/editor 10.2.8 → 10.3.0
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.
@@ -66,13 +66,13 @@ const elementXsValues = {
|
|
66
66
|
height_xs: 24
|
67
67
|
}
|
68
68
|
};
|
69
|
-
export const findMaxYValue = sectionItems => {
|
69
|
+
export const findMaxYValue = (sectionItems, breakpoint) => {
|
70
70
|
let maxY = 0;
|
71
71
|
sectionItems.forEach(item => {
|
72
72
|
if (item?.type && item?.type !== "paragraph") {
|
73
73
|
const {
|
74
74
|
bottom
|
75
|
-
} = getElementOffset(item);
|
75
|
+
} = getElementOffset(item, breakpoint === "lg" ? "lg" : "xs");
|
76
76
|
maxY = Math.max(maxY, bottom);
|
77
77
|
}
|
78
78
|
});
|
@@ -1,15 +1,15 @@
|
|
1
1
|
import { useEffect, useRef } from "react";
|
2
2
|
import { getNode } from "../../../utils/helper";
|
3
3
|
import { ROW_HEIGHT } from "../Utils/gridDropItem";
|
4
|
-
import { getGridArea, handleTextAlignment } from "./helper";
|
4
|
+
import { getGridArea, getNodeValues, handleTextAlignment } from "./helper";
|
5
5
|
import { Box } from "@mui/material";
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
-
export const getElementOffset = element => {
|
7
|
+
export const getElementOffset = (element, breakpoint) => {
|
8
8
|
const {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
} = element;
|
9
|
+
height,
|
10
|
+
gridArea,
|
11
|
+
marginTop
|
12
|
+
} = getNodeValues(element, breakpoint);
|
13
13
|
const [startRow] = getGridArea(gridArea);
|
14
14
|
const top = (startRow - 1) * ROW_HEIGHT + marginTop;
|
15
15
|
const bottom = top + height;
|
@@ -18,8 +18,8 @@ export const getElementOffset = element => {
|
|
18
18
|
bottom
|
19
19
|
};
|
20
20
|
};
|
21
|
-
const updateTextHeight = (editor, path,
|
22
|
-
if (!
|
21
|
+
export const updateTextHeight = (editor, path, currHeight, updateBreakpoint) => {
|
22
|
+
if (!currHeight) {
|
23
23
|
return;
|
24
24
|
}
|
25
25
|
const textItem = getNode(editor, path);
|
@@ -27,31 +27,21 @@ const updateTextHeight = (editor, path, height) => {
|
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
const {
|
30
|
-
|
31
|
-
|
30
|
+
height,
|
31
|
+
gridArea,
|
32
32
|
type
|
33
|
-
} = textItem;
|
34
|
-
if (!
|
33
|
+
} = getNodeValues(textItem, updateBreakpoint);
|
34
|
+
if (!gridArea && type !== "paragraph") {
|
35
35
|
return;
|
36
36
|
}
|
37
|
-
const oldHeight =
|
38
|
-
const newHeight =
|
37
|
+
const oldHeight = height;
|
38
|
+
const newHeight = currHeight;
|
39
39
|
const heightDiff = newHeight - oldHeight;
|
40
40
|
if (heightDiff !== 0) {
|
41
41
|
const textNode = [textItem, path];
|
42
|
-
handleTextAlignment(editor, textNode, heightDiff);
|
42
|
+
handleTextAlignment(editor, textNode, heightDiff, updateBreakpoint);
|
43
43
|
}
|
44
|
-
// else if (heightDiff < 0) {
|
45
|
-
// Transforms.setNodes(
|
46
|
-
// editor,
|
47
|
-
// {
|
48
|
-
// height_xs: newHeight,
|
49
|
-
// },
|
50
|
-
// { at: path }
|
51
|
-
// );
|
52
|
-
// }
|
53
44
|
};
|
54
|
-
|
55
45
|
function VirtualTextElement(props) {
|
56
46
|
const {
|
57
47
|
dataSets,
|
@@ -71,7 +61,7 @@ function VirtualTextElement(props) {
|
|
71
61
|
const currentText = currElement?.innerText;
|
72
62
|
const prevText = prevTextRef?.current;
|
73
63
|
if (currentText && currentText !== prevText) {
|
74
|
-
updateTextHeight(editor, path, height);
|
64
|
+
updateTextHeight(editor, path, height, "xs");
|
75
65
|
}
|
76
66
|
prevTextRef.current = currentText;
|
77
67
|
}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { ROW_HEIGHT, calculateGridArea } from "../Utils/gridDropItem";
|
2
2
|
import { Transforms, Editor } from "slate";
|
3
3
|
import { getElementOffset } from "./VirtualTextElement";
|
4
|
+
import { getNode } from "../../../utils/helper";
|
5
|
+
import { findMaxYValue } from "../../../Elements/FreeGrid/helper";
|
4
6
|
const isBulletOrTickIcon = (width, itemStartRow, startRow) => {
|
5
7
|
return width <= 40 && itemStartRow === startRow;
|
6
8
|
};
|
@@ -129,11 +131,36 @@ const getAncestorFreeGridContainers = (editor, path) => {
|
|
129
131
|
})].filter(([node, nodePath]) => nodePath.length <= path.length);
|
130
132
|
return containers;
|
131
133
|
};
|
132
|
-
export const handleTextAlignment = (editor, textNode, heightDiff) => {
|
133
|
-
const [, textPath] = textNode;
|
134
|
+
export const handleTextAlignment = (editor, textNode, heightDiff, updateBreakpoint) => {
|
135
|
+
const [textEle, textPath] = textNode;
|
134
136
|
let containers = getAncestorFreeGridContainers(editor, textPath);
|
135
|
-
|
136
|
-
|
137
|
+
for (let i = containers.length - 1; i >= 0; i--) {
|
138
|
+
const container = containers[i];
|
139
|
+
const childContainer = containers[i + 1];
|
140
|
+
if (!heightDiff) {
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
|
144
|
+
// get the data of elements to align inside container
|
145
|
+
const alignElements = alignElementsInsideContainer(container, childContainer || textNode, heightDiff, updateBreakpoint);
|
146
|
+
if (!childContainer) {
|
147
|
+
const {
|
148
|
+
height
|
149
|
+
} = getNodeValues(textEle, updateBreakpoint);
|
150
|
+
const appendBp = updateBreakpoint === "lg" ? "" : "_xs";
|
151
|
+
|
152
|
+
// update the height of the current text element, before updating the container
|
153
|
+
Transforms.setNodes(editor, {
|
154
|
+
[`height${appendBp}`]: height + heightDiff
|
155
|
+
}, {
|
156
|
+
at: textPath
|
157
|
+
});
|
158
|
+
}
|
159
|
+
const containerHeightDiff = updateContainer(editor, alignElements, container, updateBreakpoint, heightDiff);
|
160
|
+
|
161
|
+
// if container height incresed/decresed, need to auto align the parent container based on height differed
|
162
|
+
heightDiff = containerHeightDiff;
|
163
|
+
}
|
137
164
|
};
|
138
165
|
export const handleContainers = (editor, boxPath, extraHeight) => {
|
139
166
|
const containers = getAncestorFreeGridContainers(editor, boxPath);
|
@@ -220,6 +247,140 @@ export const moveOverlappedItems = (editor, moveRows, containerItems, containerP
|
|
220
247
|
}
|
221
248
|
});
|
222
249
|
};
|
250
|
+
export const causeOverlap = (container, currElementPath, updateBreakpoint, newTopPosition, firstNextElement) => {
|
251
|
+
const [containerNode, containerPath] = container;
|
252
|
+
let isOverlapped = false;
|
253
|
+
containerNode.children.forEach((item, index) => {
|
254
|
+
if (item.type === "paragraph") {
|
255
|
+
return;
|
256
|
+
}
|
257
|
+
const currPath = [...containerPath, index];
|
258
|
+
if (currPath.toString() === currElementPath.toString()) {
|
259
|
+
return;
|
260
|
+
}
|
261
|
+
const {
|
262
|
+
top,
|
263
|
+
bottom
|
264
|
+
} = getElementOffset(item, updateBreakpoint);
|
265
|
+
if (firstNextElement === top) {
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
if (newTopPosition > top && newTopPosition <= bottom) {
|
269
|
+
isOverlapped = true;
|
270
|
+
}
|
271
|
+
});
|
272
|
+
return isOverlapped;
|
273
|
+
};
|
274
|
+
export const alignElementsInsideContainer = (container, currentElement, heightDiff, updateBreakpoint) => {
|
275
|
+
const [containerNode, containerPath] = container;
|
276
|
+
const [currentElementNode, currElementPath] = currentElement || [];
|
277
|
+
const {
|
278
|
+
bottom: currElementBottom
|
279
|
+
} = getElementOffset(currentElementNode, updateBreakpoint);
|
280
|
+
const newCurrElementBottom = currElementBottom + heightDiff;
|
281
|
+
const bufferSpace = 12;
|
282
|
+
const nextElements = []; // Elements after the current element
|
283
|
+
let firstNextElement = 0; // first element position which is after the current element
|
284
|
+
|
285
|
+
const alignElements = {};
|
286
|
+
|
287
|
+
// find the elements present after the current element
|
288
|
+
containerNode.children.forEach((item, index) => {
|
289
|
+
if (item.type === "paragraph") {
|
290
|
+
return;
|
291
|
+
}
|
292
|
+
const currPath = [...containerPath, index];
|
293
|
+
const {
|
294
|
+
top: itemTop
|
295
|
+
} = getElementOffset(item, updateBreakpoint);
|
296
|
+
if (currPath.toString() === currElementPath.toString()) {
|
297
|
+
return;
|
298
|
+
}
|
299
|
+
const bufferPosition = 15;
|
300
|
+
if (itemTop + bufferPosition >= currElementBottom) {
|
301
|
+
const element = {
|
302
|
+
path: currPath,
|
303
|
+
node: item
|
304
|
+
};
|
305
|
+
nextElements.push(element);
|
306
|
+
firstNextElement = firstNextElement > 0 ? Math.min(firstNextElement, itemTop) : itemTop;
|
307
|
+
}
|
308
|
+
});
|
309
|
+
|
310
|
+
// check whether the new height is overlapping the next element
|
311
|
+
const isOverlapped = firstNextElement && newCurrElementBottom >= firstNextElement;
|
312
|
+
let moveElements = isOverlapped || heightDiff < 0; // if heightDiff is negative, move elements up
|
313
|
+
|
314
|
+
if (heightDiff < 0) {
|
315
|
+
// does flex elements cause overlap
|
316
|
+
const isCausingOverlap = causeOverlap(container, currElementPath, updateBreakpoint, firstNextElement + heightDiff, firstNextElement);
|
317
|
+
moveElements = !isCausingOverlap;
|
318
|
+
}
|
319
|
+
if (moveElements) {
|
320
|
+
const topPos = newCurrElementBottom - firstNextElement + bufferSpace; // position the element after the current element
|
321
|
+
alignElements.topPos = heightDiff < 0 ? heightDiff : topPos;
|
322
|
+
alignElements.nextElements = nextElements;
|
323
|
+
alignElements.moveElements = moveElements;
|
324
|
+
}
|
325
|
+
return alignElements;
|
326
|
+
};
|
327
|
+
export const updateContainer = (editor, alignElements, container, updateBreakpoint, heightDiff) => {
|
328
|
+
const [containerNode, containerPath] = container;
|
329
|
+
const {
|
330
|
+
moveElements,
|
331
|
+
topPos,
|
332
|
+
nextElements
|
333
|
+
} = alignElements || {};
|
334
|
+
const appendBp = updateBreakpoint === "lg" ? "" : "_xs";
|
335
|
+
|
336
|
+
// update the aligned data inside container
|
337
|
+
if (moveElements && topPos !== 0) {
|
338
|
+
nextElements.forEach(ele => {
|
339
|
+
const {
|
340
|
+
path,
|
341
|
+
node
|
342
|
+
} = ele;
|
343
|
+
const {
|
344
|
+
top
|
345
|
+
} = getElementOffset(node, updateBreakpoint);
|
346
|
+
const y = top + topPos;
|
347
|
+
|
348
|
+
// Calculate grid position
|
349
|
+
const row = Math.floor(y / ROW_HEIGHT) + 1;
|
350
|
+
|
351
|
+
// to calculate difference inside the grid
|
352
|
+
const marginTop = Math.abs((row - 1) * ROW_HEIGHT - y);
|
353
|
+
|
354
|
+
// Update grid area
|
355
|
+
const gridArea = `${row} / 1 / ${row + 1} / 2`;
|
356
|
+
Transforms.setNodes(editor, {
|
357
|
+
[`gridArea${appendBp}`]: gridArea,
|
358
|
+
[`marginTop${appendBp}`]: marginTop
|
359
|
+
}, {
|
360
|
+
at: path
|
361
|
+
});
|
362
|
+
});
|
363
|
+
}
|
364
|
+
|
365
|
+
// update the new height of the container
|
366
|
+
const newContainerNode = getNode(editor, containerPath);
|
367
|
+
const newHeight = findMaxYValue(newContainerNode?.children, updateBreakpoint) + 12;
|
368
|
+
const {
|
369
|
+
height: containerOldHeight
|
370
|
+
} = getNodeValues(containerNode, updateBreakpoint);
|
371
|
+
let currHeightDiff = newHeight - containerOldHeight;
|
372
|
+
const noUpdate = currHeightDiff < 0 && heightDiff > 0; // if current text height is increased, but container height is getting reduced, we don't want to reduce the height of the container
|
373
|
+
if (noUpdate) {
|
374
|
+
currHeightDiff = 0;
|
375
|
+
} else {
|
376
|
+
Transforms.setNodes(editor, {
|
377
|
+
[`height${appendBp}`]: newHeight + 12
|
378
|
+
}, {
|
379
|
+
at: containerPath
|
380
|
+
});
|
381
|
+
}
|
382
|
+
return currHeightDiff;
|
383
|
+
};
|
223
384
|
export const handleContainersAlignment = (editor, containers, heightDiff, bufferSpace = 0) => {
|
224
385
|
for (let i = containers.length - 1; i >= 0; i--) {
|
225
386
|
const container = containers[i];
|
@@ -391,4 +552,21 @@ export const sortElements = (items, container) => {
|
|
391
552
|
}
|
392
553
|
}
|
393
554
|
});
|
555
|
+
};
|
556
|
+
const nodeKeys = ["height", "width", "gridArea", "marginTop", "left"];
|
557
|
+
export const getNodeValues = (node, breakpoint = "xs") => {
|
558
|
+
// defaulty return xs breakpoint values, if breakpoint is not given
|
559
|
+
const appendBp = breakpoint === "lg" ? "" : "_xs";
|
560
|
+
const nodeVals = nodeKeys.reduce((a, b) => {
|
561
|
+
const key = b + appendBp;
|
562
|
+
a[b] = node[key];
|
563
|
+
if (b === "height" && !a[b]) {
|
564
|
+
a[b] = node.height;
|
565
|
+
}
|
566
|
+
return a;
|
567
|
+
}, {});
|
568
|
+
return {
|
569
|
+
...node,
|
570
|
+
...nodeVals
|
571
|
+
};
|
394
572
|
};
|
@@ -20,7 +20,7 @@ import useDragging from "../../hooks/useDragging";
|
|
20
20
|
import { dragOverOn } from "../../helper/RnD/focusNode";
|
21
21
|
import { focusSelection, clearSelection, clearSelectionOnly } from "../../helper";
|
22
22
|
// import { reRenderChildNodes } from "./Utils/gridDropItem";
|
23
|
-
import VirtualTextElement from "./VirtualElement/VirtualTextElement";
|
23
|
+
import VirtualTextElement, { updateTextHeight } from "./VirtualElement/VirtualTextElement";
|
24
24
|
import useAutoScroll from "../../hooks/useAutoScroll";
|
25
25
|
import ForceAutoAlignment from "./VirtualElement/ForceAutoAlignment";
|
26
26
|
import BoxHeaderAutoAlignment from "./VirtualElement/BoxHeaderAutoAlignment";
|
@@ -131,6 +131,7 @@ const RnD = props => {
|
|
131
131
|
const {
|
132
132
|
translation
|
133
133
|
} = customProps;
|
134
|
+
const timerId = useRef(0);
|
134
135
|
useEffect(() => {
|
135
136
|
if (ITEM_TYPES.includes(type)) {
|
136
137
|
if (enable === 1) {
|
@@ -140,6 +141,24 @@ const RnD = props => {
|
|
140
141
|
setAbsPosition({});
|
141
142
|
}
|
142
143
|
}
|
144
|
+
const textElement = getCurrentEle()?.querySelector(".fgi_type_text > .simple-text");
|
145
|
+
if (breakpoint && textElement && childType === "text" && !enable) {
|
146
|
+
timerId.current = setTimeout(() => {
|
147
|
+
const {
|
148
|
+
clientHeight
|
149
|
+
} = textElement;
|
150
|
+
const {
|
151
|
+
height
|
152
|
+
} = delta || {};
|
153
|
+
const heightDiff = Math.abs(clientHeight - height);
|
154
|
+
if (clientHeight && height && heightDiff >= 5) {
|
155
|
+
updateTextHeight(editor, path, clientHeight, breakpoint);
|
156
|
+
const parentSectionPath = path.slice(0, 2);
|
157
|
+
reRenderChildNodes(editor, parentSectionPath);
|
158
|
+
}
|
159
|
+
}, 200);
|
160
|
+
}
|
161
|
+
return () => clearTimeout(timerId.current);
|
143
162
|
}, [enable]);
|
144
163
|
const getCurrentEle = () => {
|
145
164
|
return positionRef.current?.resizableElement?.current;
|