@flozy/editor 4.8.5 → 4.8.7

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.
@@ -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__*/_jsxs(GridContainer, {
309
- container: true,
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: "grid-c-wrpr",
315
+ className: `grid-container ${grid} has-hover element-root dpath ${equalItems ? "equal-cols" : ""}`,
316
+ ...attributes,
317
+ ...sectionId,
372
318
  sx: {
373
- display: "flex",
374
- ...gridcwrprProps,
375
- alignItems: vertical || "start",
376
- justifyContent: horizantal || "start",
377
- flexDirection: flexDirection || "row",
378
- width: "100%",
379
- height: "auto"
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: children
383
- }), /*#__PURE__*/_jsx(NewLineButtons, {})]
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
- setTemplates({
30
- ...templates,
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: "Grid",
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, getBRValue, getTRBLBreakPoints } from "../../helper/theme";
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 { wrapThemeBreakpoints } from "../FreeGrid/breakpointConstants";
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 GridItemToolbar = ({
16
- selected,
17
- showTool,
18
- onSettings
20
+ const Resizer = ({
21
+ classes,
22
+ onMouseDown,
23
+ className
19
24
  }) => {
20
- return selected && !showTool ? /*#__PURE__*/_jsx("div", {
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: "-14px",
25
- left: "-14px"
49
+ top: "-34px",
50
+ left: "-4px",
51
+ display: "flex",
52
+ flexDirection: "row"
26
53
  },
27
- children: /*#__PURE__*/_jsx(Tooltip, {
28
- title: "Grid Item Settings",
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) {
143
+ initDoms();
144
+ }
145
+ } catch (err) {
146
+ console.log(err);
147
+ }
148
+ }, [columnRef?.current]);
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]);
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,19 @@ 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
+ });
224
+ } catch (err) {
225
+ console.log(err);
226
+ }
227
+ };
106
228
  const getBorderColor = () => {
107
229
  return borderColor || "transparent";
108
230
  };
@@ -138,6 +260,10 @@ const GridItem = props => {
138
260
  component: "div",
139
261
  className: `grid-item element-root gi-top-wrpr dpath`,
140
262
  ...attributes,
263
+ style: {
264
+ textAlign: element.alignment || "left",
265
+ "--minWidth": minWidthInPercent
266
+ },
141
267
  sx: {
142
268
  ...getBRProps,
143
269
  display: "flex",
@@ -153,9 +279,6 @@ const GridItem = props => {
153
279
  }
154
280
  },
155
281
  "data-path": path.join(","),
156
- style: {
157
- textAlign: element.alignment || "left"
158
- },
159
282
  children: [!readOnly && /*#__PURE__*/_jsxs("div", {
160
283
  className: `element-selector ${selected ? "selected" : ""}`,
161
284
  contentEditable: false,
@@ -177,9 +300,11 @@ const GridItem = props => {
177
300
  }), /*#__PURE__*/_jsx(GridItemToolbar, {
178
301
  selected: selected,
179
302
  showTool: showTool,
180
- onSettings: onSettings
303
+ onSettings: onSettings,
304
+ onAddColumn: onAddColumn
181
305
  })]
182
306
  }), /*#__PURE__*/_jsx(Box, {
307
+ ref: columnRef,
183
308
  className: `gi-inner-cw ${animation || ""} content-editable ${isEmpty} np`,
184
309
  component: "div",
185
310
  "data-path": path.join(","),
@@ -194,7 +319,7 @@ const GridItem = props => {
194
319
  borderColor: borderColorHover || borderColor || "transparent"
195
320
  }
196
321
  },
197
- placeholder: "Grid Item",
322
+ placeholder: "Column",
198
323
  children: children
199
324
  }), openSetttings ? /*#__PURE__*/_jsx(GridItemPopup, {
200
325
  element: element,
@@ -202,7 +327,12 @@ const GridItem = props => {
202
327
  onClose: onClose,
203
328
  onDelete: onDelete,
204
329
  customProps: customProps
205
- }) : null]
330
+ }) : null, /*#__PURE__*/_jsx(Resizer, {
331
+ classes: classes,
332
+ className: resizing ? "resizing" : "",
333
+ onMouseDown: onMouseDown,
334
+ height: "auto"
335
+ })]
206
336
  });
207
337
  };
208
338
  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,61 @@ 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
+ flex: "1 1 0",
36
+ [theme?.breakpoints?.between("xs", "md")]: {
37
+ flex: "1 1 100%",
38
+ padding: "0px !important",
39
+ minWidth: "100% !important",
40
+ maxWidth: "100% !important",
41
+ "& .col-width-resizer": {
42
+ display: "none !important"
43
+ }
44
+ }
45
+ },
46
+ "& .col-width-resizer": {
47
+ position: "absolute",
48
+ width: "4px",
49
+ height: "100%",
50
+ backgroundColor: "#CCC",
51
+ left: "calc(100% + 4px)",
52
+ top: "0px",
53
+ cursor: "col-resize",
54
+ opacity: 0,
55
+ borderRadius: "7px",
56
+ "&.resizing": {
57
+ opacity: 1
58
+ },
59
+ "&:hover": {
60
+ opacity: 1
61
+ }
62
+ }
63
+ }
9
64
  }
10
65
  });
11
66
  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: "alignLeft",
9
+ type: "paragraph",
9
10
  children: [{
10
- type: "paragraph",
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: "16",
57
- left: "16",
58
- right: "16",
59
- bottom: "16"
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: "alignLeft",
31
+ type: "paragraph",
69
32
  children: [{
70
- type: "paragraph",
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: "16",
98
- left: "16",
99
- right: "16",
100
- bottom: "16"
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: "16",
109
- left: "16",
110
- right: "16",
111
- bottom: "16"
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);
@@ -293,7 +293,7 @@ const editorStyles = ({
293
293
  fullScreenWrapper: {
294
294
  "& .MuiPaper-root": {
295
295
  borderRadius: "0px !important",
296
- paddingTop: '20px',
296
+ paddingTop: "20px",
297
297
  "& .MuiDialogTitle-root": {
298
298
  position: "absolute",
299
299
  top: 0,
@@ -50,7 +50,8 @@ const SectionStyle = (themeReact, theme) => ({
50
50
  },
51
51
  "& .ed-section-inner": {
52
52
  [themeReact.breakpoints.between("xs", "md")]: {
53
- maxWidth: `320px !important`
53
+ maxWidth: `320px !important`,
54
+ minWidth: "90%"
54
55
  }
55
56
  },
56
57
  "&.is-temp": {
@@ -174,7 +174,7 @@ const ELEMENTS_LIST = [{
174
174
  insertDivider(editor);
175
175
  }
176
176
  }, {
177
- name: "Grid",
177
+ name: "Column",
178
178
  group: "Elements",
179
179
  desc: "",
180
180
  type: "grid",
@@ -80,10 +80,10 @@ const gridItemStyle = [{
80
80
  key: "grid",
81
81
  type: "gridSize"
82
82
  }, {
83
- label: "Force Full Width on Mobile",
83
+ label: "Full Width on Mobile",
84
84
  key: "forceFullWidth",
85
85
  type: "selectBox",
86
- placeholder: "Force Full Width on Mobile"
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",
@@ -82,7 +82,6 @@ const getStartEnd = ({
82
82
  }
83
83
  };
84
84
  export const checkTypings = editor => {
85
- console.log(editor?.selection);
86
85
  if (editor?.selection) {
87
86
  const {
88
87
  target,
@@ -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: "16",
12
- left: "16",
13
- right: "16",
14
- bottom: "16"
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: "16",
27
- left: "16",
28
- right: "16",
29
- bottom: "16"
29
+ top: "0",
30
+ left: "0",
31
+ right: "0",
32
+ bottom: "0"
30
33
  },
31
- gridSize: 8
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,44 @@ export const gridItem = (props = {}) => {
19
20
  ...(props || {})
20
21
  };
21
22
  };
23
+ export const onAddGridItem = ({
24
+ editor,
25
+ element,
26
+ children
27
+ }) => {
28
+ const currentPath = editor.selection?.anchor?.path;
29
+ const ancestorsPath = Path.ancestors(currentPath, {
30
+ reverse: true
31
+ });
32
+ const insertPath = ancestorsPath[1];
33
+ if (insertPath) {
34
+ insertPath[insertPath.length - 1] = element.children.length;
35
+ const lp = ReactEditor.findPath(editor, element);
36
+ const lastElement = {
37
+ ...element.children[element.children.length - 1]
38
+ };
39
+ Transforms.insertNodes(editor, gridItem({
40
+ ...lastElement,
41
+ children: [{
42
+ type: "paragraph",
43
+ children: [{
44
+ text: ""
45
+ }]
46
+ }]
47
+ }), {
48
+ at: [...lp, children.length]
49
+ });
50
+ // new line
51
+ Transforms.insertNodes(editor, [{
52
+ type: "paragraph",
53
+ children: [{
54
+ text: ""
55
+ }]
56
+ }], {
57
+ at: [editor.children.length]
58
+ });
59
+ }
60
+ };
22
61
  export const insertGridItem = editor => {
23
62
  Transforms.insertNodes(editor, {
24
63
  ...gridItem()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.8.5",
3
+ "version": "4.8.7",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"