@flozy/editor 4.8.5 → 4.8.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor/Elements/Grid/Grid.js +79 -72
- package/dist/Editor/Elements/Grid/GridButton.js +4 -23
- package/dist/Editor/Elements/Grid/GridItem.js +152 -21
- package/dist/Editor/Elements/Grid/Providers/GridProvider.js +100 -0
- package/dist/Editor/Elements/Grid/Styles.js +61 -1
- package/dist/Editor/Elements/Grid/templates/default_grid.js +25 -80
- package/dist/Editor/Styles/EditorStyles.js +1 -1
- package/dist/Editor/common/Section/styles.js +2 -1
- package/dist/Editor/common/Shorthands/elements.js +1 -1
- package/dist/Editor/common/StyleBuilder/gridItemStyle.js +2 -2
- package/dist/Editor/common/StyleBuilder/gridStyle.js +9 -0
- package/dist/Editor/hooks/useMentions.js +0 -1
- package/dist/Editor/utils/customHooks/useTableResize.js +8 -3
- package/dist/Editor/utils/grid.js +27 -10
- package/dist/Editor/utils/gridItem.js +56 -1
- package/package.json +1 -1
@@ -15,6 +15,8 @@ import { gridItem } from "../../utils/gridItem";
|
|
15
15
|
import { useEditorContext, useEditorSelection } from "../../hooks/useMouseMove";
|
16
16
|
import { getTRBLBreakPoints, getBreakPointsValue, groupByBreakpoint } from "../../helper/theme";
|
17
17
|
import useWindowResize from "../../hooks/useWindowResize";
|
18
|
+
import GridStyles from "./Styles";
|
19
|
+
import { GridProvider } from "./Providers/GridProvider";
|
18
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
19
21
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
20
22
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
@@ -92,6 +94,7 @@ const getParentEl = (editor, path) => {
|
|
92
94
|
};
|
93
95
|
const Grid = props => {
|
94
96
|
const theme = useTheme();
|
97
|
+
const classes = GridStyles(theme);
|
95
98
|
const {
|
96
99
|
attributes,
|
97
100
|
children,
|
@@ -105,6 +108,7 @@ const Grid = props => {
|
|
105
108
|
const {
|
106
109
|
id,
|
107
110
|
grid,
|
111
|
+
equalItems,
|
108
112
|
bannerSpacing,
|
109
113
|
bgColor,
|
110
114
|
alignment,
|
@@ -305,82 +309,85 @@ const Grid = props => {
|
|
305
309
|
...getBreakPointsValue(flexWrap || "wrap")
|
306
310
|
}
|
307
311
|
}, theme);
|
308
|
-
return /*#__PURE__*/
|
309
|
-
|
310
|
-
className: `grid-container ${grid} has-hover element-root dpath`,
|
311
|
-
...attributes,
|
312
|
-
...sectionId,
|
313
|
-
sx: {
|
314
|
-
display: {
|
315
|
-
lg: "flex",
|
316
|
-
xs: xsHidden ? "none" : "flex"
|
317
|
-
},
|
318
|
-
background: bgColor,
|
319
|
-
alignContent: vertical,
|
320
|
-
...bgImage,
|
321
|
-
borderColor: borderColor || "transparent",
|
322
|
-
borderWidth: borderWidth || "1px",
|
323
|
-
borderRadius: `${topLeft}px ${topRight}px ${bottomRight}px ${bottomLeft}px`,
|
324
|
-
borderStyle: borderStyle || "solid",
|
325
|
-
height: "auto"
|
326
|
-
},
|
327
|
-
"data-path": path.join(","),
|
328
|
-
children: [fgColor && /*#__PURE__*/_jsx("div", {
|
329
|
-
style: {
|
330
|
-
position: "absolute",
|
331
|
-
pointerEvents: "none",
|
332
|
-
width: "100%",
|
333
|
-
height: "100%",
|
334
|
-
background: fgColor,
|
335
|
-
backgroundRepeat: "no-repeat",
|
336
|
-
backgroundSize: "cover"
|
337
|
-
}
|
338
|
-
}), !readOnly && /*#__PURE__*/_jsxs("div", {
|
339
|
-
className: `element-selector ${selected ? "selected" : ""}`,
|
340
|
-
contentEditable: false,
|
341
|
-
children: [/*#__PURE__*/_jsx("div", {
|
342
|
-
className: "element-selector-dots tl",
|
343
|
-
children: " "
|
344
|
-
}), /*#__PURE__*/_jsx("div", {
|
345
|
-
className: "element-selector-dots tr",
|
346
|
-
children: " "
|
347
|
-
}), /*#__PURE__*/_jsx("div", {
|
348
|
-
className: "element-selector-dots bl",
|
349
|
-
children: " "
|
350
|
-
}), /*#__PURE__*/_jsx("div", {
|
351
|
-
className: "element-selector-dots br",
|
352
|
-
children: " "
|
353
|
-
}), /*#__PURE__*/_jsx(GridToolBar, {
|
354
|
-
selected: selected,
|
355
|
-
showTool: showTool,
|
356
|
-
onSettings: onSettings,
|
357
|
-
onAddGridItem: onAddGridItem,
|
358
|
-
onAddSection: onAddSection,
|
359
|
-
onMoveSection: onMoveSection,
|
360
|
-
path: path,
|
361
|
-
isSectionFullWidth: isSectionFullWidth
|
362
|
-
})]
|
363
|
-
}), openSetttings ? /*#__PURE__*/_jsx(PoupComp, {
|
364
|
-
element: element,
|
365
|
-
onSave: onSave,
|
366
|
-
onClose: onClose,
|
367
|
-
onDelete: onDelete,
|
368
|
-
customProps: customProps
|
369
|
-
}) : null, /*#__PURE__*/_jsx(GridContainer, {
|
312
|
+
return /*#__PURE__*/_jsx(GridProvider, {
|
313
|
+
children: /*#__PURE__*/_jsxs(GridContainer, {
|
370
314
|
container: true,
|
371
|
-
className:
|
315
|
+
className: `grid-container ${grid} has-hover element-root dpath ${equalItems ? "equal-cols" : ""}`,
|
316
|
+
...attributes,
|
317
|
+
...sectionId,
|
372
318
|
sx: {
|
373
|
-
display:
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
319
|
+
display: {
|
320
|
+
lg: "flex",
|
321
|
+
xs: xsHidden ? "none" : "flex"
|
322
|
+
},
|
323
|
+
background: bgColor,
|
324
|
+
alignContent: vertical,
|
325
|
+
...bgImage,
|
326
|
+
borderColor: borderColor || "transparent",
|
327
|
+
borderWidth: borderWidth || "1px",
|
328
|
+
borderRadius: `${topLeft}px ${topRight}px ${bottomRight}px ${bottomLeft}px`,
|
329
|
+
borderStyle: borderStyle || "solid",
|
330
|
+
height: "auto",
|
331
|
+
...classes?.gridEqual
|
380
332
|
},
|
381
333
|
"data-path": path.join(","),
|
382
|
-
children:
|
383
|
-
|
334
|
+
children: [fgColor && /*#__PURE__*/_jsx("div", {
|
335
|
+
style: {
|
336
|
+
position: "absolute",
|
337
|
+
pointerEvents: "none",
|
338
|
+
width: "100%",
|
339
|
+
height: "100%",
|
340
|
+
background: fgColor,
|
341
|
+
backgroundRepeat: "no-repeat",
|
342
|
+
backgroundSize: "cover"
|
343
|
+
}
|
344
|
+
}), !readOnly && /*#__PURE__*/_jsxs("div", {
|
345
|
+
className: `element-selector grid-s ${selected ? "selected" : ""}`,
|
346
|
+
contentEditable: false,
|
347
|
+
children: [/*#__PURE__*/_jsx("div", {
|
348
|
+
className: "element-selector-dots tl",
|
349
|
+
children: " "
|
350
|
+
}), /*#__PURE__*/_jsx("div", {
|
351
|
+
className: "element-selector-dots tr",
|
352
|
+
children: " "
|
353
|
+
}), /*#__PURE__*/_jsx("div", {
|
354
|
+
className: "element-selector-dots bl",
|
355
|
+
children: " "
|
356
|
+
}), /*#__PURE__*/_jsx("div", {
|
357
|
+
className: "element-selector-dots br",
|
358
|
+
children: " "
|
359
|
+
}), /*#__PURE__*/_jsx(GridToolBar, {
|
360
|
+
selected: selected,
|
361
|
+
showTool: showTool,
|
362
|
+
onSettings: onSettings,
|
363
|
+
onAddGridItem: onAddGridItem,
|
364
|
+
onAddSection: onAddSection,
|
365
|
+
onMoveSection: onMoveSection,
|
366
|
+
path: path,
|
367
|
+
isSectionFullWidth: isSectionFullWidth
|
368
|
+
})]
|
369
|
+
}), openSetttings ? /*#__PURE__*/_jsx(PoupComp, {
|
370
|
+
element: element,
|
371
|
+
onSave: onSave,
|
372
|
+
onClose: onClose,
|
373
|
+
onDelete: onDelete,
|
374
|
+
customProps: customProps
|
375
|
+
}) : null, /*#__PURE__*/_jsx(GridContainer, {
|
376
|
+
container: true,
|
377
|
+
className: "grid-c-wrpr",
|
378
|
+
sx: {
|
379
|
+
display: "flex",
|
380
|
+
...gridcwrprProps,
|
381
|
+
alignItems: vertical || "start",
|
382
|
+
justifyContent: horizantal || "start",
|
383
|
+
flexDirection: flexDirection || "row",
|
384
|
+
width: "100%",
|
385
|
+
height: "auto"
|
386
|
+
},
|
387
|
+
"data-path": path.join(","),
|
388
|
+
children: children
|
389
|
+
}), /*#__PURE__*/_jsx(NewLineButtons, {})]
|
390
|
+
})
|
384
391
|
});
|
385
392
|
};
|
386
393
|
export default Grid;
|
@@ -1,10 +1,7 @@
|
|
1
1
|
import React, { useState } from "react";
|
2
|
-
import { Button, Dialog, DialogContent, DialogTitle, Grid,
|
3
|
-
// ImageListItemBar,
|
4
|
-
Tooltip, Box } from "@mui/material";
|
2
|
+
import { Button, Dialog, DialogContent, DialogTitle, Grid, Tooltip, Box } from "@mui/material";
|
5
3
|
import { insertGrid, insertPlainGrid } from "../../utils/grid";
|
6
4
|
import { GridIcon } from "../../common/iconslist";
|
7
|
-
// import { ImageList, ImageListItem } from "@mui/material";
|
8
5
|
import ToolbarIcon from "../../common/ToolbarIcon";
|
9
6
|
import GridStyles from "./Styles";
|
10
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
@@ -14,28 +11,12 @@ const GridButton = props => {
|
|
14
11
|
const classes = GridStyles();
|
15
12
|
const {
|
16
13
|
editor,
|
17
|
-
customProps,
|
18
14
|
icoBtnType
|
19
15
|
} = props;
|
20
|
-
const {
|
21
|
-
services
|
22
|
-
} = customProps;
|
23
16
|
const [open, setOpen] = useState(false);
|
24
|
-
const [templates, setTemplates] = useState({
|
25
|
-
loading: false,
|
26
|
-
list: []
|
27
|
-
});
|
28
17
|
const onButtonClick = async () => {
|
29
|
-
|
30
|
-
|
31
|
-
loading: true
|
32
|
-
});
|
33
|
-
setOpen(true);
|
34
|
-
const result = await services("listTemplates", {});
|
35
|
-
setTemplates({
|
36
|
-
...templates,
|
37
|
-
list: result?.data || []
|
38
|
-
});
|
18
|
+
insertGrid(editor, insertPlainGrid(2));
|
19
|
+
handleClose();
|
39
20
|
};
|
40
21
|
const handleInsertGrid = item => () => {
|
41
22
|
try {
|
@@ -63,7 +44,7 @@ const GridButton = props => {
|
|
63
44
|
|
64
45
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
65
46
|
children: [/*#__PURE__*/_jsx(ToolbarIcon, {
|
66
|
-
title: "
|
47
|
+
title: "Column",
|
67
48
|
onClick: onButtonClick,
|
68
49
|
icon: /*#__PURE__*/_jsx(GridIcon, {}),
|
69
50
|
icoBtnType: icoBtnType
|
@@ -1,42 +1,92 @@
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
2
|
-
import React, { useState } from "react";
|
2
|
+
import React, { useEffect, useState, useRef } from "react";
|
3
3
|
import { useTheme } from "@mui/material";
|
4
|
-
import { Transforms } from "slate";
|
4
|
+
import { Node, Path, Transforms } from "slate";
|
5
5
|
import { useSlateStatic, ReactEditor } from "slate-react";
|
6
6
|
import GridItemPopup from "./GridItemPopup";
|
7
7
|
import { IconButton, Tooltip, Box, Grid as Item } from "@mui/material";
|
8
8
|
import { GridSettingsIcon } from "../../common/iconslist";
|
9
9
|
import { useEditorContext, useEditorSelection } from "../../hooks/useMouseMove";
|
10
|
-
import { groupByBreakpoint, getBreakPointsValue,
|
10
|
+
import { groupByBreakpoint, getBreakPointsValue, getTRBLBreakPoints } from "../../helper/theme";
|
11
|
+
import AddIcon from "@mui/icons-material/Add";
|
11
12
|
import { isEmptyNode } from "../../utils/helper";
|
12
|
-
import {
|
13
|
+
import { onAddGridItem } from "../../utils/gridItem";
|
14
|
+
import useTableResize from "../../utils/customHooks/useTableResize";
|
15
|
+
import GridStyles from "./Styles";
|
16
|
+
import { useGrid } from "./Providers/GridProvider";
|
13
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
18
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
14
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
const Resizer = ({
|
21
|
+
classes,
|
22
|
+
onMouseDown,
|
23
|
+
className
|
19
24
|
}) => {
|
20
|
-
return
|
25
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
26
|
+
children: /*#__PURE__*/_jsx(Box, {
|
27
|
+
component: "div",
|
28
|
+
className: `col-width-resizer ${className}`,
|
29
|
+
contentEditable: false,
|
30
|
+
onPointerDown: onMouseDown,
|
31
|
+
sx: classes.gridEqual,
|
32
|
+
style: {
|
33
|
+
height: `100%`
|
34
|
+
}
|
35
|
+
})
|
36
|
+
});
|
37
|
+
};
|
38
|
+
const GridItemToolbar = props => {
|
39
|
+
const {
|
40
|
+
selected,
|
41
|
+
showTool,
|
42
|
+
onSettings,
|
43
|
+
onAddColumn
|
44
|
+
} = props;
|
45
|
+
return selected && !showTool ? /*#__PURE__*/_jsxs("div", {
|
21
46
|
contentEditable: false,
|
22
47
|
className: "grid-item-toolbar",
|
23
48
|
style: {
|
24
|
-
top: "-
|
25
|
-
left: "-
|
49
|
+
top: "-34px",
|
50
|
+
left: "-4px",
|
51
|
+
display: "flex",
|
52
|
+
flexDirection: "row"
|
26
53
|
},
|
27
|
-
children: /*#__PURE__*/_jsx(Tooltip, {
|
28
|
-
title: "
|
54
|
+
children: [/*#__PURE__*/_jsx(Tooltip, {
|
55
|
+
title: "Column Settings",
|
29
56
|
arrow: true,
|
30
57
|
children: /*#__PURE__*/_jsx(IconButton, {
|
58
|
+
sx: {
|
59
|
+
marginRight: "4px"
|
60
|
+
},
|
31
61
|
size: "small",
|
32
62
|
onClick: onSettings,
|
33
63
|
children: /*#__PURE__*/_jsx(GridSettingsIcon, {})
|
34
64
|
})
|
35
|
-
})
|
65
|
+
}), /*#__PURE__*/_jsx(Tooltip, {
|
66
|
+
title: "Add Column",
|
67
|
+
arrow: true,
|
68
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
69
|
+
sx: {
|
70
|
+
marginRight: "4px"
|
71
|
+
},
|
72
|
+
size: "small",
|
73
|
+
onClick: onAddColumn,
|
74
|
+
children: /*#__PURE__*/_jsx(AddIcon, {})
|
75
|
+
})
|
76
|
+
})]
|
36
77
|
}) : null;
|
37
78
|
};
|
38
79
|
const GridItem = props => {
|
80
|
+
const {
|
81
|
+
columnWidths,
|
82
|
+
widths,
|
83
|
+
initColumnWidth,
|
84
|
+
updateColumnWidth,
|
85
|
+
updateColNodes
|
86
|
+
} = useGrid();
|
87
|
+
const columnRef = useRef(null);
|
39
88
|
const theme = useTheme();
|
89
|
+
const classes = GridStyles(theme);
|
40
90
|
const {
|
41
91
|
attributes,
|
42
92
|
children,
|
@@ -63,7 +113,8 @@ const GridItem = props => {
|
|
63
113
|
animation,
|
64
114
|
cellGHeight,
|
65
115
|
xsHidden,
|
66
|
-
forceFullWidth
|
116
|
+
forceFullWidth,
|
117
|
+
minWidth
|
67
118
|
} = element;
|
68
119
|
const {
|
69
120
|
vertical,
|
@@ -77,7 +128,65 @@ const GridItem = props => {
|
|
77
128
|
} = useEditorContext();
|
78
129
|
const selected = hoverPath === path.join(",");
|
79
130
|
const [showTool] = useEditorSelection(editor);
|
131
|
+
const [parentDOM, setParentDOM] = useState({});
|
132
|
+
const [size, onMouseDown, resizing, onLoad, isDone] = useTableResize({
|
133
|
+
...parentDOM
|
134
|
+
});
|
80
135
|
const isEmpty = !readOnly && isEmptyNode(editor, element?.children, path) ? "empty" : "";
|
136
|
+
const cmWidth = resizing && size?.width && parentDOM?.gridWidth && widths?.left ? `${widths?.left}%` : minWidth ? `${minWidth}%` : "auto";
|
137
|
+
// for right column width update
|
138
|
+
const isRightCol = path?.join() === columnWidths?.rightPath && !resizing && widths?.right;
|
139
|
+
const minWidthInPercent = isRightCol ? `${widths?.right}%` : cmWidth;
|
140
|
+
useEffect(() => {
|
141
|
+
try {
|
142
|
+
if (columnRef?.current && (!parentDOM?.parentDOM || !minWidth)) {
|
143
|
+
initDoms();
|
144
|
+
}
|
145
|
+
} catch (err) {
|
146
|
+
console.log(err);
|
147
|
+
}
|
148
|
+
}, [columnRef?.current, minWidth]);
|
149
|
+
useEffect(() => {
|
150
|
+
if (isDone || isRightCol) {
|
151
|
+
initDoms();
|
152
|
+
}
|
153
|
+
}, [minWidth, isDone]);
|
154
|
+
useEffect(() => {
|
155
|
+
if (!resizing && isDone) {
|
156
|
+
updateColNodes(path);
|
157
|
+
} else if (resizing) {
|
158
|
+
// set init width
|
159
|
+
initColumnWidth(path, size?.width / parentDOM?.gridWidth * 100);
|
160
|
+
}
|
161
|
+
}, [resizing, isDone]);
|
162
|
+
useEffect(() => {
|
163
|
+
if (resizing) {
|
164
|
+
updateColumnWidth({
|
165
|
+
left: size?.width / parentDOM?.gridWidth * 100
|
166
|
+
});
|
167
|
+
}
|
168
|
+
}, [resizing, size]);
|
169
|
+
const initDoms = () => {
|
170
|
+
try {
|
171
|
+
const gridNode = Node.get(editor, Path.parent(path));
|
172
|
+
if (gridNode) {
|
173
|
+
const gridDOM = ReactEditor.toDOMNode(editor, gridNode);
|
174
|
+
setParentDOM({
|
175
|
+
gridWidth: gridDOM?.offsetWidth,
|
176
|
+
parentDOM: columnRef?.current,
|
177
|
+
size: {
|
178
|
+
width: columnRef?.current?.offsetWidth
|
179
|
+
}
|
180
|
+
});
|
181
|
+
onLoad({
|
182
|
+
width: columnRef?.current?.offsetWidth,
|
183
|
+
height: 100
|
184
|
+
});
|
185
|
+
}
|
186
|
+
} catch (err) {
|
187
|
+
console.log(err);
|
188
|
+
}
|
189
|
+
};
|
81
190
|
const onSettings = () => {
|
82
191
|
setOpenSettings(true);
|
83
192
|
};
|
@@ -103,6 +212,20 @@ const GridItem = props => {
|
|
103
212
|
});
|
104
213
|
}
|
105
214
|
};
|
215
|
+
const onAddColumn = () => {
|
216
|
+
try {
|
217
|
+
const gridPath = Path.parent(path);
|
218
|
+
const gridNode = Node.get(editor, gridPath);
|
219
|
+
onAddGridItem({
|
220
|
+
editor,
|
221
|
+
element: gridNode,
|
222
|
+
children: gridNode?.children || [],
|
223
|
+
isColumn: gridNode?.equalItems
|
224
|
+
});
|
225
|
+
} catch (err) {
|
226
|
+
console.log(err);
|
227
|
+
}
|
228
|
+
};
|
106
229
|
const getBorderColor = () => {
|
107
230
|
return borderColor || "transparent";
|
108
231
|
};
|
@@ -138,6 +261,10 @@ const GridItem = props => {
|
|
138
261
|
component: "div",
|
139
262
|
className: `grid-item element-root gi-top-wrpr dpath`,
|
140
263
|
...attributes,
|
264
|
+
style: {
|
265
|
+
textAlign: element.alignment || "left",
|
266
|
+
"--minWidth": minWidthInPercent
|
267
|
+
},
|
141
268
|
sx: {
|
142
269
|
...getBRProps,
|
143
270
|
display: "flex",
|
@@ -153,9 +280,6 @@ const GridItem = props => {
|
|
153
280
|
}
|
154
281
|
},
|
155
282
|
"data-path": path.join(","),
|
156
|
-
style: {
|
157
|
-
textAlign: element.alignment || "left"
|
158
|
-
},
|
159
283
|
children: [!readOnly && /*#__PURE__*/_jsxs("div", {
|
160
284
|
className: `element-selector ${selected ? "selected" : ""}`,
|
161
285
|
contentEditable: false,
|
@@ -177,9 +301,11 @@ const GridItem = props => {
|
|
177
301
|
}), /*#__PURE__*/_jsx(GridItemToolbar, {
|
178
302
|
selected: selected,
|
179
303
|
showTool: showTool,
|
180
|
-
onSettings: onSettings
|
304
|
+
onSettings: onSettings,
|
305
|
+
onAddColumn: onAddColumn
|
181
306
|
})]
|
182
307
|
}), /*#__PURE__*/_jsx(Box, {
|
308
|
+
ref: columnRef,
|
183
309
|
className: `gi-inner-cw ${animation || ""} content-editable ${isEmpty} np`,
|
184
310
|
component: "div",
|
185
311
|
"data-path": path.join(","),
|
@@ -194,7 +320,7 @@ const GridItem = props => {
|
|
194
320
|
borderColor: borderColorHover || borderColor || "transparent"
|
195
321
|
}
|
196
322
|
},
|
197
|
-
placeholder: "
|
323
|
+
placeholder: "Column",
|
198
324
|
children: children
|
199
325
|
}), openSetttings ? /*#__PURE__*/_jsx(GridItemPopup, {
|
200
326
|
element: element,
|
@@ -202,7 +328,12 @@ const GridItem = props => {
|
|
202
328
|
onClose: onClose,
|
203
329
|
onDelete: onDelete,
|
204
330
|
customProps: customProps
|
205
|
-
}) : null
|
331
|
+
}) : null, /*#__PURE__*/_jsx(Resizer, {
|
332
|
+
classes: classes,
|
333
|
+
className: resizing ? "resizing" : "",
|
334
|
+
onMouseDown: onMouseDown,
|
335
|
+
height: "auto"
|
336
|
+
})]
|
206
337
|
});
|
207
338
|
};
|
208
339
|
export default GridItem;
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import React, { createContext, useContext, useState } from "react";
|
2
|
+
import { Path, Node, Transforms } from "slate";
|
3
|
+
import { ReactEditor, useSlateStatic } from "slate-react";
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
+
const GridContext = /*#__PURE__*/createContext();
|
6
|
+
const getAdjacentColumnPath = (editor, currentPath, direction = "next") => {
|
7
|
+
const parentPath = Path.parent(currentPath); // Get the parent grid path
|
8
|
+
const gridNode = Node.get(editor, parentPath); // Get the grid node
|
9
|
+
|
10
|
+
const currentIndex = currentPath[currentPath.length - 1]; // Index of the current column
|
11
|
+
const isNext = direction === "next";
|
12
|
+
const adjacentIndex = isNext ? currentIndex + 1 : currentIndex - 1;
|
13
|
+
|
14
|
+
// Ensure the adjacent index is valid
|
15
|
+
if (adjacentIndex < 0 || adjacentIndex >= gridNode.children.length) {
|
16
|
+
return null; // No adjacent column exists in the given direction
|
17
|
+
}
|
18
|
+
|
19
|
+
return [...parentPath, adjacentIndex]; // Return the adjacent column's path
|
20
|
+
};
|
21
|
+
|
22
|
+
export const GridProvider = ({
|
23
|
+
children
|
24
|
+
}) => {
|
25
|
+
const editor = useSlateStatic();
|
26
|
+
const [columnWidths, setColumnWidths] = useState({});
|
27
|
+
const [widths, setWidths] = useState({});
|
28
|
+
const initColumnWidth = (currentColPath = [], currentMinWidth = 0) => {
|
29
|
+
try {
|
30
|
+
let right = 0;
|
31
|
+
const rightColPath = getAdjacentColumnPath(editor, currentColPath);
|
32
|
+
if (rightColPath) {
|
33
|
+
const parentPath = Path.parent(rightColPath); // Get the parent grid path
|
34
|
+
const gridNode = Node.get(editor, parentPath);
|
35
|
+
const gridNodeDom = ReactEditor.toDOMNode(editor, gridNode);
|
36
|
+
const rightColNode = Node.get(editor, rightColPath);
|
37
|
+
const rightColDom = ReactEditor.toDOMNode(editor, rightColNode);
|
38
|
+
right = rightColNode?.minWidth || rightColDom?.offsetWidth / gridNodeDom?.offsetWidth * 100;
|
39
|
+
}
|
40
|
+
setColumnWidths({
|
41
|
+
left: currentMinWidth,
|
42
|
+
right,
|
43
|
+
rightPath: rightColPath?.join(),
|
44
|
+
rightIndex: rightColPath
|
45
|
+
});
|
46
|
+
} catch (err) {
|
47
|
+
console.log(err);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* @param {*} data - contains {left: calculatedWidth}
|
54
|
+
*/
|
55
|
+
const updateColumnWidth = data => {
|
56
|
+
// logic to update right column width
|
57
|
+
const right = columnWidths?.right - (data?.left - columnWidths?.left);
|
58
|
+
const diff = right !== widths?.right;
|
59
|
+
if (right && right > 10 && data?.left > 10 && diff) {
|
60
|
+
setWidths({
|
61
|
+
...data,
|
62
|
+
right: right
|
63
|
+
});
|
64
|
+
}
|
65
|
+
};
|
66
|
+
const updateColNodes = (currentColPath = []) => {
|
67
|
+
try {
|
68
|
+
if (widths?.left) {
|
69
|
+
Transforms.setNodes(editor, {
|
70
|
+
minWidth: widths?.left
|
71
|
+
}, {
|
72
|
+
at: currentColPath
|
73
|
+
});
|
74
|
+
// update right column node
|
75
|
+
if (columnWidths?.rightPath) {
|
76
|
+
Transforms.setNodes(editor, {
|
77
|
+
minWidth: widths?.right
|
78
|
+
}, {
|
79
|
+
at: columnWidths?.rightIndex
|
80
|
+
});
|
81
|
+
}
|
82
|
+
}
|
83
|
+
setColumnWidths({});
|
84
|
+
setWidths({});
|
85
|
+
} catch (err) {
|
86
|
+
console.log(err);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
return /*#__PURE__*/_jsx(GridContext.Provider, {
|
90
|
+
value: {
|
91
|
+
widths,
|
92
|
+
updateColumnWidth,
|
93
|
+
initColumnWidth,
|
94
|
+
columnWidths,
|
95
|
+
updateColNodes
|
96
|
+
},
|
97
|
+
children: children
|
98
|
+
});
|
99
|
+
};
|
100
|
+
export const useGrid = () => useContext(GridContext);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const GridStyles =
|
1
|
+
const GridStyles = theme => ({
|
2
2
|
gridButton: {
|
3
3
|
background: "#007FFF",
|
4
4
|
color: "#fff",
|
@@ -6,6 +6,66 @@ const GridStyles = () => ({
|
|
6
6
|
background: "#0066CC",
|
7
7
|
color: "#FFF"
|
8
8
|
}
|
9
|
+
},
|
10
|
+
gridEqual: {
|
11
|
+
"&.equal-cols": {
|
12
|
+
display: "flex",
|
13
|
+
"& .element-selector.grid-s": {
|
14
|
+
display: "none !important"
|
15
|
+
},
|
16
|
+
"& .element-selector-ctrl": {
|
17
|
+
display: "none !important"
|
18
|
+
},
|
19
|
+
"& .grid-c-wrpr": {
|
20
|
+
gap: "16px",
|
21
|
+
flexWrap: "nowrap",
|
22
|
+
[theme?.breakpoints?.between("xs", "md")]: {
|
23
|
+
flexWrap: "wrap"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"& .grid-item": {
|
27
|
+
minWidth: "var(--minWidth)",
|
28
|
+
maxWidth: "var(--minWidth)",
|
29
|
+
"& .element-selector": {
|
30
|
+
border: "1px solid transparent",
|
31
|
+
"& .element-selector-dots": {
|
32
|
+
display: "none !important"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"&:last-child": {
|
36
|
+
"& .col-width-resizer": {
|
37
|
+
display: "none"
|
38
|
+
}
|
39
|
+
},
|
40
|
+
flex: "1 1 0",
|
41
|
+
[theme?.breakpoints?.between("xs", "md")]: {
|
42
|
+
flex: "1 1 100%",
|
43
|
+
padding: "0px !important",
|
44
|
+
minWidth: "100% !important",
|
45
|
+
maxWidth: "100% !important",
|
46
|
+
"& .col-width-resizer": {
|
47
|
+
display: "none !important"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
},
|
51
|
+
"& .col-width-resizer": {
|
52
|
+
position: "absolute",
|
53
|
+
width: "4px",
|
54
|
+
height: "100%",
|
55
|
+
backgroundColor: "#CCC",
|
56
|
+
left: "calc(100% + 4px)",
|
57
|
+
top: "0px",
|
58
|
+
cursor: "col-resize",
|
59
|
+
opacity: 0,
|
60
|
+
borderRadius: "7px",
|
61
|
+
"&.resizing": {
|
62
|
+
opacity: 1
|
63
|
+
},
|
64
|
+
"&:hover": {
|
65
|
+
opacity: 1
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
9
69
|
}
|
10
70
|
});
|
11
71
|
export default GridStyles;
|
@@ -1,114 +1,59 @@
|
|
1
1
|
const default_grid = [{
|
2
2
|
type: "grid",
|
3
3
|
grid: "container",
|
4
|
+
equalItems: true,
|
4
5
|
children: [{
|
5
6
|
type: "grid-item",
|
6
7
|
grid: 6,
|
7
8
|
children: [{
|
8
|
-
type: "
|
9
|
+
type: "paragraph",
|
9
10
|
children: [{
|
10
|
-
|
11
|
-
children: [{
|
12
|
-
text: "Ship Sites with Style.",
|
13
|
-
fontSize: "huge",
|
14
|
-
fontFamily: "PoppinsBold"
|
15
|
-
}]
|
16
|
-
}, {
|
17
|
-
type: "paragraph",
|
18
|
-
children: [{
|
19
|
-
fontSize: "16px",
|
20
|
-
fontFamily: "PoppinsRegular",
|
21
|
-
text: ""
|
22
|
-
}]
|
23
|
-
}, {
|
24
|
-
type: "paragraph",
|
25
|
-
children: [{
|
26
|
-
fontSize: "16px",
|
27
|
-
fontFamily: "PoppinsRegular",
|
28
|
-
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
|
29
|
-
}]
|
30
|
-
}, {
|
31
|
-
type: "paragraph",
|
32
|
-
children: [{
|
33
|
-
fontSize: "16px",
|
34
|
-
fontFamily: "PoppinsRegular",
|
35
|
-
text: ""
|
36
|
-
}]
|
37
|
-
}, {
|
38
|
-
type: "paragraph",
|
39
|
-
children: [{
|
40
|
-
fontSize: "16px",
|
41
|
-
fontFamily: "PoppinsRegular",
|
42
|
-
text: ""
|
43
|
-
}]
|
44
|
-
}, {
|
45
|
-
type: "paragraph",
|
46
|
-
children: [{
|
47
|
-
fontSize: "16px",
|
48
|
-
fontFamily: "PoppinsRegular",
|
49
|
-
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
|
50
|
-
}]
|
11
|
+
text: ""
|
51
12
|
}]
|
52
13
|
}],
|
53
14
|
bgColor: "rgba(255, 255, 255, 0)",
|
54
15
|
lockSpacing: true,
|
55
16
|
bannerSpacing: {
|
56
|
-
top: "
|
57
|
-
left: "
|
58
|
-
right: "
|
59
|
-
bottom: "
|
17
|
+
top: "0",
|
18
|
+
left: "0",
|
19
|
+
right: "0",
|
20
|
+
bottom: "0"
|
60
21
|
},
|
61
22
|
alignment: {
|
62
23
|
horizantal: "center"
|
63
|
-
}
|
24
|
+
},
|
25
|
+
forceFullWidth: true,
|
26
|
+
borderWidth: "0px"
|
64
27
|
}, {
|
65
28
|
type: "grid-item",
|
66
29
|
grid: 6,
|
67
30
|
children: [{
|
68
|
-
type: "
|
31
|
+
type: "paragraph",
|
69
32
|
children: [{
|
70
|
-
|
71
|
-
children: [{
|
72
|
-
text: ""
|
73
|
-
}]
|
74
|
-
}, {
|
75
|
-
type: "paragraph",
|
76
|
-
children: [{
|
77
|
-
type: "image",
|
78
|
-
url: "https://developers.elementor.com/docs/assets/img/elementor-placeholder-image.png",
|
79
|
-
images: [],
|
80
|
-
children: [{
|
81
|
-
text: " "
|
82
|
-
}],
|
83
|
-
size: {
|
84
|
-
width: 570.1953125,
|
85
|
-
height: 450,
|
86
|
-
widthInPercent: 89.06583684178412
|
87
|
-
},
|
88
|
-
alignment: {
|
89
|
-
horizantal: "center"
|
90
|
-
}
|
91
|
-
}]
|
33
|
+
text: ""
|
92
34
|
}]
|
93
35
|
}],
|
94
36
|
bgColor: "rgba(255, 255, 255, 0)",
|
95
37
|
lockSpacing: true,
|
96
38
|
bannerSpacing: {
|
97
|
-
top: "
|
98
|
-
left: "
|
99
|
-
right: "
|
100
|
-
bottom: "
|
101
|
-
}
|
39
|
+
top: "0",
|
40
|
+
left: "0",
|
41
|
+
right: "0",
|
42
|
+
bottom: "0"
|
43
|
+
},
|
44
|
+
forceFullWidth: true,
|
45
|
+
borderWidth: "0px"
|
102
46
|
}],
|
103
47
|
alignment: {
|
104
48
|
flexDirection: "row"
|
105
49
|
},
|
106
50
|
lockSpacing: true,
|
107
51
|
bannerSpacing: {
|
108
|
-
top: "
|
109
|
-
left: "
|
110
|
-
right: "
|
111
|
-
bottom: "
|
112
|
-
}
|
52
|
+
top: "0",
|
53
|
+
left: "0",
|
54
|
+
right: "0",
|
55
|
+
bottom: "0"
|
56
|
+
},
|
57
|
+
borderWidth: "0px"
|
113
58
|
}];
|
114
59
|
export default JSON.stringify(default_grid);
|
@@ -80,10 +80,10 @@ const gridItemStyle = [{
|
|
80
80
|
key: "grid",
|
81
81
|
type: "gridSize"
|
82
82
|
}, {
|
83
|
-
label: "
|
83
|
+
label: "Full Width on Mobile",
|
84
84
|
key: "forceFullWidth",
|
85
85
|
type: "selectBox",
|
86
|
-
placeholder: "
|
86
|
+
placeholder: "Full Width on Mobile"
|
87
87
|
}, {
|
88
88
|
label: "Height",
|
89
89
|
key: "cellGHeight",
|
@@ -119,6 +119,15 @@ const gridStyle = [{
|
|
119
119
|
});
|
120
120
|
}
|
121
121
|
}]
|
122
|
+
}, {
|
123
|
+
tab: "Grid Item Size",
|
124
|
+
value: "equalItems",
|
125
|
+
fields: [{
|
126
|
+
label: "Equal Column Size",
|
127
|
+
key: "equalItems",
|
128
|
+
type: "selectBox",
|
129
|
+
placeholder: "Hide on Mobile"
|
130
|
+
}]
|
122
131
|
}, {
|
123
132
|
tab: "Save As Template",
|
124
133
|
value: "saveAsTemplate",
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { useState } from "react";
|
2
2
|
const useTableResize = ({
|
3
3
|
parentDOM,
|
4
|
-
size: defaultSize
|
4
|
+
size: defaultSize,
|
5
|
+
onDone
|
5
6
|
}) => {
|
6
7
|
const {
|
7
8
|
width
|
@@ -15,6 +16,7 @@ const useTableResize = ({
|
|
15
16
|
width
|
16
17
|
});
|
17
18
|
const [resizing, setResizing] = useState(false);
|
19
|
+
const [isDone, setIsDone] = useState(0);
|
18
20
|
const onLoad = defaultSize => {
|
19
21
|
setSize({
|
20
22
|
widthInPercent: 100,
|
@@ -22,15 +24,18 @@ const useTableResize = ({
|
|
22
24
|
...defaultSize
|
23
25
|
});
|
24
26
|
};
|
25
|
-
const onMouseDown =
|
27
|
+
const onMouseDown = e => {
|
28
|
+
e.preventDefault();
|
26
29
|
document.addEventListener("pointermove", onMouseMove);
|
27
30
|
document.addEventListener("pointerup", onMouseUp);
|
28
31
|
setResizing(true);
|
32
|
+
setIsDone(0);
|
29
33
|
};
|
30
34
|
const onMouseUp = () => {
|
31
35
|
document.removeEventListener("pointermove", onMouseMove);
|
32
36
|
document.removeEventListener("pointerup", onMouseUp);
|
33
37
|
setResizing(false);
|
38
|
+
setIsDone(1);
|
34
39
|
};
|
35
40
|
const onMouseMove = e => {
|
36
41
|
setSize(currentSize => {
|
@@ -42,6 +47,6 @@ const useTableResize = ({
|
|
42
47
|
};
|
43
48
|
});
|
44
49
|
};
|
45
|
-
return [size, onMouseDown, resizing, onLoad];
|
50
|
+
return [size, onMouseDown, resizing, onLoad, isDone];
|
46
51
|
};
|
47
52
|
export default useTableResize;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Node, Path, Transforms } from "slate";
|
1
2
|
import default_grid from "../Elements/Grid/templates/default_grid";
|
2
3
|
import { gridItem } from "./gridItem";
|
3
4
|
import { customInsertNode } from "./helper";
|
@@ -8,11 +9,13 @@ export const insertPlainGrid = count => {
|
|
8
9
|
cellGHeight: "100%",
|
9
10
|
lockSpacing: true,
|
10
11
|
bannerSpacing: {
|
11
|
-
top: "
|
12
|
-
left: "
|
13
|
-
right: "
|
14
|
-
bottom: "
|
15
|
-
}
|
12
|
+
top: "0",
|
13
|
+
left: "0",
|
14
|
+
right: "0",
|
15
|
+
bottom: "0"
|
16
|
+
},
|
17
|
+
forceFullWidth: true,
|
18
|
+
borderWidth: "0px"
|
16
19
|
}));
|
17
20
|
return {
|
18
21
|
type: "grid",
|
@@ -23,12 +26,14 @@ export const insertPlainGrid = count => {
|
|
23
26
|
},
|
24
27
|
lockSpacing: true,
|
25
28
|
bannerSpacing: {
|
26
|
-
top: "
|
27
|
-
left: "
|
28
|
-
right: "
|
29
|
-
bottom: "
|
29
|
+
top: "0",
|
30
|
+
left: "0",
|
31
|
+
right: "0",
|
32
|
+
bottom: "0"
|
30
33
|
},
|
31
|
-
|
34
|
+
equalItems: true,
|
35
|
+
gridSize: 8,
|
36
|
+
borderWidth: "0px"
|
32
37
|
};
|
33
38
|
};
|
34
39
|
export const insertGrid = (editor, item, path) => {
|
@@ -41,6 +46,18 @@ export const insertGrid = (editor, item, path) => {
|
|
41
46
|
at: path || selection.focus.path,
|
42
47
|
select: true
|
43
48
|
});
|
49
|
+
// insert new line after grid / column
|
50
|
+
const currentNode = Node.get(editor, selection.focus.path);
|
51
|
+
if (currentNode?.type === "grid") {
|
52
|
+
Transforms.insertNodes(editor, {
|
53
|
+
type: "paragraph",
|
54
|
+
children: [{
|
55
|
+
text: ""
|
56
|
+
}]
|
57
|
+
}, {
|
58
|
+
at: Path.next(Path.parent(selection.focus.path))
|
59
|
+
});
|
60
|
+
}
|
44
61
|
} catch (err) {
|
45
62
|
console.log(err);
|
46
63
|
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Transforms } from "slate";
|
1
|
+
import { Transforms, Path } from "slate";
|
2
|
+
import { ReactEditor } from "slate-react";
|
2
3
|
export const gridItem = (props = {}) => {
|
3
4
|
return {
|
4
5
|
type: "grid-item",
|
@@ -19,6 +20,60 @@ export const gridItem = (props = {}) => {
|
|
19
20
|
...(props || {})
|
20
21
|
};
|
21
22
|
};
|
23
|
+
const updateLastSiblingWidths = (editor, lastChildPath = []) => {
|
24
|
+
try {
|
25
|
+
Transforms.setNodes(editor, {
|
26
|
+
minWidth: ""
|
27
|
+
}, {
|
28
|
+
at: lastChildPath
|
29
|
+
});
|
30
|
+
} catch (err) {
|
31
|
+
console.log(err);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
export const onAddGridItem = ({
|
35
|
+
editor,
|
36
|
+
element,
|
37
|
+
children,
|
38
|
+
isColumn
|
39
|
+
}) => {
|
40
|
+
const currentPath = editor.selection?.anchor?.path;
|
41
|
+
const ancestorsPath = Path.ancestors(currentPath, {
|
42
|
+
reverse: true
|
43
|
+
});
|
44
|
+
const insertPath = ancestorsPath[1];
|
45
|
+
if (insertPath) {
|
46
|
+
insertPath[insertPath.length - 1] = element.children.length;
|
47
|
+
const lp = ReactEditor.findPath(editor, element);
|
48
|
+
const lastElement = {
|
49
|
+
...element.children[element.children.length - 1]
|
50
|
+
};
|
51
|
+
if (isColumn && children?.length - 1 > 0) {
|
52
|
+
updateLastSiblingWidths(editor, [...lp, children.length - 1]);
|
53
|
+
}
|
54
|
+
Transforms.insertNodes(editor, gridItem({
|
55
|
+
...(lastElement || {}),
|
56
|
+
minWidth: null,
|
57
|
+
children: [{
|
58
|
+
type: "paragraph",
|
59
|
+
children: [{
|
60
|
+
text: ""
|
61
|
+
}]
|
62
|
+
}]
|
63
|
+
}), {
|
64
|
+
at: [...lp, children.length]
|
65
|
+
});
|
66
|
+
// new line
|
67
|
+
Transforms.insertNodes(editor, [{
|
68
|
+
type: "paragraph",
|
69
|
+
children: [{
|
70
|
+
text: ""
|
71
|
+
}]
|
72
|
+
}], {
|
73
|
+
at: [editor.children.length]
|
74
|
+
});
|
75
|
+
}
|
76
|
+
};
|
22
77
|
export const insertGridItem = editor => {
|
23
78
|
Transforms.insertNodes(editor, {
|
24
79
|
...gridItem()
|