@flozy/editor 1.1.2 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/dist/Editor/CollaborativeEditor.js +7 -2
  2. package/dist/Editor/CommonEditor.js +53 -34
  3. package/dist/Editor/Editor.css +93 -17
  4. package/dist/Editor/Elements/Accordion/Accordion.js +67 -2
  5. package/dist/Editor/Elements/Accordion/AccordionBtnPopup.js +20 -0
  6. package/dist/Editor/Elements/Accordion/AccordionButton.js +2 -1
  7. package/dist/Editor/Elements/Accordion/AccordionSummary.js +59 -4
  8. package/dist/Editor/Elements/Accordion/AccordionTitlePopup.js +20 -0
  9. package/dist/Editor/Elements/Button/ButtonPopup.js +20 -0
  10. package/dist/Editor/Elements/Button/ButtonToolIcon.js +19 -0
  11. package/dist/Editor/Elements/Button/EditorButton.js +124 -0
  12. package/dist/Editor/Elements/Carousel/Arrows.js +39 -0
  13. package/dist/Editor/Elements/Carousel/Carousel.js +82 -0
  14. package/dist/Editor/Elements/Carousel/CarouselButton.js +19 -0
  15. package/dist/Editor/Elements/Carousel/CarouselItem.js +13 -0
  16. package/dist/Editor/Elements/Carousel/slick-theme.min.css +143 -0
  17. package/dist/Editor/Elements/Carousel/slick.min.css +83 -0
  18. package/dist/Editor/Elements/Color Picker/ColorPicker.js +1 -1
  19. package/dist/Editor/Elements/Embed/Embed.css +22 -2
  20. package/dist/Editor/Elements/Embed/Embed.js +89 -74
  21. package/dist/Editor/Elements/Embed/EmbedPopup.js +23 -0
  22. package/dist/Editor/Elements/Embed/Image.js +92 -10
  23. package/dist/Editor/Elements/Embed/Video.js +1 -0
  24. package/dist/Editor/Elements/Equation/EquationButton.js +12 -12
  25. package/dist/Editor/Elements/Grid/Grid.js +64 -8
  26. package/dist/Editor/Elements/Grid/GridButton.js +2 -4
  27. package/dist/Editor/Elements/Grid/GridItem.js +59 -5
  28. package/dist/Editor/Elements/Grid/GridItemPopup.js +20 -0
  29. package/dist/Editor/Elements/Grid/GridPopup.js +22 -0
  30. package/dist/Editor/Elements/ID/Id.js +1 -1
  31. package/dist/Editor/Elements/ImageText/ImageText.js +14 -0
  32. package/dist/Editor/Elements/ImageText/ImageTextWrapper.js +14 -0
  33. package/dist/Editor/Elements/Link/LinkButton.js +1 -1
  34. package/dist/Editor/Elements/NewLine/NewLineButton.js +2 -1
  35. package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +88 -0
  36. package/dist/Editor/Elements/PageSettings/PageSettingsPopup.js +22 -0
  37. package/dist/Editor/Elements/Signature/Signature.js +4 -2
  38. package/dist/Editor/Elements/Signature/SignatureButton.js +2 -1
  39. package/dist/Editor/Elements/Signature/SignatureOptions/DrawSignature.js +7 -2
  40. package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +2 -1
  41. package/dist/Editor/Elements/Signature/SignatureOptions/UploadSignature.js +50 -0
  42. package/dist/Editor/Elements/Signature/SignatureOptions/index.js +2 -1
  43. package/dist/Editor/Elements/Signature/SignaturePopup.js +79 -10
  44. package/dist/Editor/Elements/Table/DeleteCellIcon.js +24 -0
  45. package/dist/Editor/Elements/Table/DeleteRowIcon.js +24 -0
  46. package/dist/Editor/Elements/Table/Table.js +9 -1
  47. package/dist/Editor/Elements/Table/TableCell.js +181 -0
  48. package/dist/Editor/Elements/Table/TablePopup.js +22 -0
  49. package/dist/Editor/Elements/Table/TableRow.js +31 -0
  50. package/dist/Editor/Elements/Table/TableSelector.js +62 -68
  51. package/dist/Editor/Toolbar/Toolbar.js +22 -7
  52. package/dist/Editor/Toolbar/styles.css +20 -11
  53. package/dist/Editor/Toolbar/toolbarGroups.js +9 -9
  54. package/dist/Editor/common/Button.js +4 -8
  55. package/dist/Editor/common/StyleBuilder/accordionTitleBtnStyle.js +23 -0
  56. package/dist/Editor/common/StyleBuilder/accordionTitleStyle.js +35 -0
  57. package/dist/Editor/common/StyleBuilder/buttonStyle.js +47 -0
  58. package/dist/Editor/common/StyleBuilder/embedImageStyle.js +63 -0
  59. package/dist/Editor/common/StyleBuilder/fieldTypes/alignment.js +88 -0
  60. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +87 -0
  61. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +136 -0
  62. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +126 -0
  63. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +89 -0
  64. package/dist/Editor/common/StyleBuilder/fieldTypes/elementSize.js +110 -0
  65. package/dist/Editor/common/StyleBuilder/fieldTypes/gridSize.js +42 -0
  66. package/dist/Editor/common/StyleBuilder/fieldTypes/imageTexts.js +75 -0
  67. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +21 -0
  68. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +46 -0
  69. package/dist/Editor/common/StyleBuilder/gridItemStyle.js +51 -0
  70. package/dist/Editor/common/StyleBuilder/gridStyle.js +51 -0
  71. package/dist/Editor/common/StyleBuilder/index.js +114 -0
  72. package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +10 -0
  73. package/dist/Editor/common/StyleBuilder/tableStyle.js +38 -0
  74. package/dist/Editor/common/Uploader.js +87 -0
  75. package/dist/Editor/plugins/withEmbeds.js +12 -5
  76. package/dist/Editor/plugins/withTable.js +5 -4
  77. package/dist/Editor/service/fileupload.js +17 -0
  78. package/dist/Editor/utils/SlateUtilityFunctions.js +46 -12
  79. package/dist/Editor/utils/button.js +11 -0
  80. package/dist/Editor/utils/carousel.js +13 -0
  81. package/dist/Editor/utils/carouselItem.js +19 -0
  82. package/dist/Editor/utils/customHooks/useContextMenu.js +8 -8
  83. package/dist/Editor/utils/customHooks/useResize.js +1 -1
  84. package/dist/Editor/utils/font.js +4 -4
  85. package/dist/Editor/utils/helper.js +16 -0
  86. package/dist/Editor/utils/imageText.js +19 -0
  87. package/dist/Editor/utils/table.js +172 -0
  88. package/package.json +2 -1
@@ -1,103 +1,118 @@
1
- import React, { useRef, useState } from 'react';
2
- import Button from '../../common/Button';
3
- import Icon from '../../common/Icon';
4
- import { isBlockActive } from '../../utils/SlateUtilityFunctions';
5
- import usePopup from '../../utils/customHooks/usePopup';
6
- import { insertEmbed } from '../../utils/embed';
7
- import { Transforms } from 'slate';
8
- import { ReactEditor } from 'slate-react';
9
- import './Embed.css';
1
+ import React, { useRef, useState } from "react";
2
+ import { Transforms } from "slate";
3
+ import { ReactEditor } from "slate-react";
4
+ import { Grid, Dialog, DialogTitle, DialogContent, DialogActions, Button, TextField, IconButton } from "@mui/material";
5
+ import Icon from "../../common/Icon";
6
+ import { isBlockActive } from "../../utils/SlateUtilityFunctions";
7
+ import usePopup from "../../utils/customHooks/usePopup";
8
+ import { insertEmbed } from "../../utils/embed";
9
+ import Uploader from "../../common/Uploader";
10
+ import "./Embed.css";
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Fragment as _Fragment } from "react/jsx-runtime";
14
+ const EMBED_LABEL = {
15
+ image: "Image",
16
+ video: "Video"
17
+ };
12
18
  const Embed = ({
13
19
  editor,
14
- format
20
+ format,
21
+ customProps
15
22
  }) => {
16
23
  const urlInputRef = useRef();
24
+ const [open, setOpen] = useState(false);
17
25
  const [showInput, setShowInput] = usePopup(urlInputRef);
18
26
  const [formData, setFormData] = useState({
19
- url: '',
20
- alt: ''
27
+ url: "",
28
+ alt: ""
21
29
  });
22
30
  const [selection, setSelection] = useState();
23
- const handleButtonClick = e => {
31
+ const handleFormSubmit = () => {
32
+ if (formData?.url) {
33
+ selection && Transforms.select(editor, selection);
34
+ selection && ReactEditor.focus(editor);
35
+ insertEmbed(editor, {
36
+ ...formData
37
+ }, format);
38
+ setShowInput(false);
39
+ setFormData({
40
+ url: "",
41
+ alt: ""
42
+ });
43
+ }
44
+ };
45
+ const onToggle = e => {
24
46
  e.preventDefault();
25
47
  setSelection(editor.selection);
26
48
  selection && ReactEditor.focus(editor);
27
- setShowInput(prev => !prev);
49
+ setOpen(true);
28
50
  };
29
- const handleFormSubmit = e => {
30
- e.preventDefault();
31
- selection && Transforms.select(editor, selection);
32
- selection && ReactEditor.focus(editor);
33
- insertEmbed(editor, {
34
- ...formData
35
- }, format);
36
- setShowInput(false);
51
+ const onSave = () => {
52
+ handleFormSubmit();
53
+ setOpen(false);
54
+ };
55
+ const onClose = () => {
56
+ setOpen(false);
57
+ };
58
+ const onUploaded = uploadedData => {
37
59
  setFormData({
38
- url: '',
39
- alt: ''
60
+ ...formData,
61
+ ...uploadedData
40
62
  });
41
63
  };
42
- const handleImageUpload = () => {
43
- setShowInput(false);
64
+ const handleChange = e => {
65
+ setFormData({
66
+ ...formData,
67
+ [e.target.name]: e.target.value
68
+ });
44
69
  };
45
- return /*#__PURE__*/_jsxs("div", {
46
- ref: urlInputRef,
47
- className: "popup-wrapper",
48
- children: [/*#__PURE__*/_jsx(Button, {
49
- active: isBlockActive(editor, format),
70
+ return /*#__PURE__*/_jsxs(_Fragment, {
71
+ children: [/*#__PURE__*/_jsx(IconButton, {
72
+ className: isBlockActive(editor, format) ? "active" : "",
50
73
  style: {
51
- border: showInput ? '1px solid lightgray' : '',
52
- borderBottom: 'none'
74
+ border: showInput ? "1px solid lightgray" : "",
75
+ borderBottom: "none"
53
76
  },
54
77
  format: format,
55
- onClick: handleButtonClick,
78
+ onClick: onToggle,
56
79
  children: /*#__PURE__*/_jsx(Icon, {
57
80
  icon: format
58
81
  })
59
- }), showInput && /*#__PURE__*/_jsxs("div", {
60
- className: "popup",
61
- children: [format === 'image' && /*#__PURE__*/_jsxs("div", {
62
- children: [/*#__PURE__*/_jsxs("div", {
63
- style: {
64
- display: 'flex',
65
- gap: '10px'
66
- },
67
- onClick: handleImageUpload,
68
- children: [/*#__PURE__*/_jsx(Icon, {
69
- icon: "upload"
70
- }), /*#__PURE__*/_jsx("span", {
71
- children: "Upload"
82
+ }), /*#__PURE__*/_jsxs(Dialog, {
83
+ open: open,
84
+ fullWidth: true,
85
+ children: [/*#__PURE__*/_jsx(DialogTitle, {
86
+ children: EMBED_LABEL[format] || "Embed"
87
+ }), /*#__PURE__*/_jsx(DialogContent, {
88
+ children: /*#__PURE__*/_jsxs(Grid, {
89
+ container: true,
90
+ children: [/*#__PURE__*/_jsx(Grid, {
91
+ item: true,
92
+ xs: 12,
93
+ children: /*#__PURE__*/_jsx(TextField, {
94
+ name: "url",
95
+ placeholder: "Enter URL",
96
+ size: "small",
97
+ fullWidth: true,
98
+ onChange: handleChange,
99
+ value: formData?.url || ""
100
+ })
101
+ }), /*#__PURE__*/_jsx(Uploader, {
102
+ value: formData,
103
+ data: {
104
+ key: "url"
105
+ },
106
+ customProps: customProps,
107
+ onUploaded: onUploaded
72
108
  })]
73
- }), /*#__PURE__*/_jsx("p", {
74
- style: {
75
- textAlign: 'center',
76
- opacity: '0.7',
77
- width: '100%'
78
- },
79
- children: "OR"
80
- })]
81
- }), /*#__PURE__*/_jsxs("form", {
82
- onSubmit: handleFormSubmit,
83
- children: [/*#__PURE__*/_jsx("input", {
84
- type: "text",
85
- placeholder: "Enter url",
86
- value: formData.url,
87
- onChange: e => setFormData(prev => ({
88
- ...prev,
89
- url: e.target.value
90
- }))
91
- }), /*#__PURE__*/_jsx("input", {
92
- type: "text",
93
- placeholder: "Enter alt",
94
- value: formData.alt,
95
- onChange: e => setFormData(prev => ({
96
- ...prev,
97
- alt: e.target.value
98
- }))
109
+ })
110
+ }), /*#__PURE__*/_jsxs(DialogActions, {
111
+ children: [/*#__PURE__*/_jsx(Button, {
112
+ onClick: onClose,
113
+ children: "Cancel"
99
114
  }), /*#__PURE__*/_jsx(Button, {
100
- type: "submit",
115
+ onClick: onSave,
101
116
  children: "Save"
102
117
  })]
103
118
  })]
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import StyleBuilder from "../../common/StyleBuilder";
3
+ import embedImageStyle from "../../common/StyleBuilder/embedImageStyle";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const EmbedPopup = props => {
6
+ const {
7
+ element,
8
+ onSave,
9
+ onClose,
10
+ customProps,
11
+ format
12
+ } = props;
13
+ return /*#__PURE__*/_jsx(StyleBuilder, {
14
+ title: "Image",
15
+ type: format === "image" ? "embedImageStyle" : "embedImageStyle",
16
+ element: element,
17
+ onSave: onSave,
18
+ onClose: onClose,
19
+ renderTabs: format === "image" ? embedImageStyle : embedImageStyle,
20
+ customProps: customProps
21
+ });
22
+ };
23
+ export default EmbedPopup;
@@ -1,36 +1,59 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { useSlateStatic, useSelected, useFocused, ReactEditor } from "slate-react";
3
- import { Node, Transforms } from "slate";
2
+ import { useSlateStatic, useSelected, ReactEditor } from "slate-react";
3
+ import { Node, Transforms, Editor, Element, Path } from "slate";
4
4
  import Icon from "../../common/Icon";
5
5
  import useResize from "../../utils/customHooks/useResize";
6
+ import { insertImageText } from "../../utils/imageText";
7
+ import EmbedPopup from "./EmbedPopup";
6
8
  import { jsx as _jsx } from "react/jsx-runtime";
7
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
10
  const Image = ({
9
11
  attributes,
10
12
  element,
11
- children
13
+ children,
14
+ customProps
12
15
  }) => {
13
16
  const {
14
17
  url,
15
- alt
18
+ alt,
19
+ bannerSpacing,
20
+ alignment,
21
+ bgColor,
22
+ borderColor
16
23
  } = element;
24
+ const {
25
+ left,
26
+ top,
27
+ right,
28
+ bottom
29
+ } = bannerSpacing || {};
30
+ const {
31
+ vertical,
32
+ horizantal
33
+ } = alignment || {};
17
34
  const editor = useSlateStatic();
18
35
  const selected = useSelected();
19
- const focused = useFocused();
20
36
  const [parentDOM, setParentDOM] = useState(null);
37
+ const [openSetttings, setOpenSettings] = useState(false);
21
38
  const [size, onMouseDown, resizing, onLoad] = useResize({
22
39
  parentDOM,
23
40
  size: element?.size
24
41
  });
25
42
  const arr = Array.from(Node.elements(editor));
26
43
  const ele = arr.find(([elem]) => element === elem);
44
+ const path = ReactEditor.findPath(editor, element);
27
45
  useEffect(() => {
28
46
  if (editor && ele[1] !== undefined) {
29
47
  const dom = ReactEditor.toDOMNode(editor, Node.get(editor, ele[1]));
30
48
  setParentDOM(dom);
31
- onLoad(dom);
49
+ onLoad(element?.size || {});
32
50
  }
33
51
  }, []);
52
+ useEffect(() => {
53
+ if (!resizing) {
54
+ onLoad(element?.size || {});
55
+ }
56
+ }, [element?.size]);
34
57
  useEffect(() => {
35
58
  if (!resizing) {
36
59
  Transforms.setNodes(editor, {
@@ -38,17 +61,74 @@ const Image = ({
38
61
  });
39
62
  }
40
63
  }, [resizing]);
64
+ const handleImageClick = () => {
65
+ Transforms.select(editor, {
66
+ anchor: Editor.start(editor, path),
67
+ focus: Editor.end(editor, path)
68
+ });
69
+ };
70
+ const onSettings = () => {
71
+ setOpenSettings(true);
72
+ };
73
+ const onSave = data => {
74
+ const updateData = {
75
+ ...data
76
+ };
77
+ delete updateData.children;
78
+ Transforms.setNodes(editor, {
79
+ ...updateData
80
+ }, {
81
+ at: path
82
+ });
83
+ onClose();
84
+ };
85
+ const onClose = () => {
86
+ setOpenSettings(false);
87
+ };
88
+ const onAddText = () => {
89
+ Transforms.wrapNodes(editor, {
90
+ type: "image-text-wrapper",
91
+ children: []
92
+ });
93
+ insertImageText(editor, [...path, 1]);
94
+ };
95
+ const ToolBar = () => {
96
+ return selected ? /*#__PURE__*/_jsxs("div", {
97
+ className: "element-toolbar",
98
+ contentEditable: false,
99
+ children: [/*#__PURE__*/_jsx("button", {
100
+ onClick: onAddText,
101
+ children: "Add Text"
102
+ }), /*#__PURE__*/_jsx("button", {
103
+ onClick: onSettings,
104
+ children: "Settings"
105
+ })]
106
+ }) : null;
107
+ };
108
+ const totalMinus = (parseInt(left) || 0) + (parseInt(right) || 0);
41
109
  return /*#__PURE__*/_jsxs("div", {
42
110
  ...attributes,
43
111
  className: "embed",
44
112
  style: {
45
113
  display: "flex",
46
- width: "100%",
114
+ width: `calc(100% - ${totalMinus}px)`,
47
115
  maxWidth: "100%",
48
- boxShadow: selected && focused && "0 0 3px 3px lightgray"
116
+ paddingLeft: `${left}px`,
117
+ paddingRight: `${right}px`,
118
+ paddingTop: `${top}px`,
119
+ paddingBottom: `${bottom}px`,
120
+ backgroundColor: bgColor,
121
+ justifyContent: horizantal,
122
+ alignContent: vertical,
123
+ border: `1px solid ${borderColor}`
49
124
  },
50
125
  ...element.attr,
51
- children: [/*#__PURE__*/_jsxs("div", {
126
+ children: [/*#__PURE__*/_jsx(ToolBar, {}), openSetttings ? /*#__PURE__*/_jsx(EmbedPopup, {
127
+ element: element,
128
+ onSave: onSave,
129
+ onClose: onClose,
130
+ customProps: customProps
131
+ }) : null, /*#__PURE__*/_jsxs("div", {
52
132
  contentEditable: false,
53
133
  style: {
54
134
  position: "relative",
@@ -57,7 +137,8 @@ const Image = ({
57
137
  },
58
138
  children: [/*#__PURE__*/_jsx("img", {
59
139
  alt: alt,
60
- src: url
140
+ src: url,
141
+ onClick: handleImageClick
61
142
  }), selected && /*#__PURE__*/_jsx("button", {
62
143
  onPointerDown: onMouseDown,
63
144
  style: {
@@ -66,6 +147,7 @@ const Image = ({
66
147
  opacity: 1,
67
148
  background: "transparent"
68
149
  },
150
+ className: "resize",
69
151
  children: /*#__PURE__*/_jsx(Icon, {
70
152
  icon: "resize"
71
153
  })
@@ -82,6 +82,7 @@ const Video = ({
82
82
  opacity: 1,
83
83
  background: "transparent"
84
84
  },
85
+ className: "resize",
85
86
  children: /*#__PURE__*/_jsx(Icon, {
86
87
  icon: "resize"
87
88
  })
@@ -1,9 +1,9 @@
1
- import { useRef, useState } from 'react';
2
- import Button from '../../common/Button';
3
- import Icon from '../../common/Icon';
4
- import usePopup from '../../utils/customHooks/usePopup';
5
- import { insertEquation } from '../../utils/equation';
6
- import { Transforms } from 'slate';
1
+ import { useRef, useState } from "react";
2
+ import Button from "../../common/Button";
3
+ import Icon from "../../common/Icon";
4
+ import usePopup from "../../utils/customHooks/usePopup";
5
+ import { insertEquation } from "../../utils/equation";
6
+ import { Transforms } from "slate";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
9
  const EquationButton = ({
@@ -11,7 +11,7 @@ const EquationButton = ({
11
11
  }) => {
12
12
  const equationInputRef = useRef(null);
13
13
  const [showInput, setShowInput] = usePopup(equationInputRef);
14
- const [math, setMath] = useState('');
14
+ const [math, setMath] = useState("");
15
15
  const [displayInline, setDisplayInline] = useState(false);
16
16
  const [selection, setSelection] = useState();
17
17
  const toggleButton = () => {
@@ -22,7 +22,7 @@ const EquationButton = ({
22
22
  const handleInputChange = ({
23
23
  target
24
24
  }) => {
25
- if (target.type === 'checkbox') {
25
+ if (target.type === "checkbox") {
26
26
  setDisplayInline(prev => !prev);
27
27
  } else {
28
28
  setMath(target.value);
@@ -32,12 +32,12 @@ const EquationButton = ({
32
32
  if (!math) return;
33
33
  selection && Transforms.select(editor, selection);
34
34
  insertEquation(editor, math, displayInline);
35
- console.log('btn click');
35
+ console.log("btn click");
36
36
  setShowInput(false);
37
37
  };
38
38
  return /*#__PURE__*/_jsxs("div", {
39
39
  ref: equationInputRef,
40
- className: "popup-wrapper",
40
+ className: "popup-wrapper1",
41
41
  children: [/*#__PURE__*/_jsx(Button, {
42
42
  format: "equation",
43
43
  onClick: toggleButton,
@@ -48,8 +48,8 @@ const EquationButton = ({
48
48
  className: "popup",
49
49
  children: [/*#__PURE__*/_jsxs("div", {
50
50
  style: {
51
- display: 'flex',
52
- gap: '5px'
51
+ display: "flex",
52
+ gap: "5px"
53
53
  },
54
54
  children: [/*#__PURE__*/_jsx("input", {
55
55
  type: "text",
@@ -1,20 +1,39 @@
1
- import React from "react";
1
+ import React, { useState } from "react";
2
2
  import { Transforms, Path } from "slate";
3
- import { useSelected, useSlateStatic } from "slate-react";
3
+ import { useSelected, useSlateStatic, ReactEditor } from "slate-react";
4
4
  import { gridItem } from "../../utils/gridItem";
5
+ import GridPopup from "./GridPopup";
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  import { jsxs as _jsxs } from "react/jsx-runtime";
7
8
  const Grid = props => {
8
9
  const {
9
10
  attributes,
10
11
  children,
11
- element
12
+ element,
13
+ customProps
12
14
  } = props;
15
+ const [openSetttings, setOpenSettings] = useState(false);
13
16
  const {
14
- grid
17
+ grid,
18
+ bannerSpacing,
19
+ bgColor,
20
+ alignment,
21
+ backgroundImage,
22
+ borderColor
15
23
  } = element;
24
+ const {
25
+ left,
26
+ top,
27
+ right,
28
+ bottom
29
+ } = bannerSpacing || {};
30
+ const {
31
+ vertical,
32
+ horizantal
33
+ } = alignment || {};
16
34
  const editor = useSlateStatic();
17
35
  const selected = useSelected();
36
+ const path = ReactEditor.findPath(editor, element);
18
37
  const onAddGridItem = () => {
19
38
  const currentPath = editor.selection?.anchor?.path;
20
39
  const ancestorsPath = Path.ancestors(currentPath, {
@@ -39,20 +58,57 @@ const Grid = props => {
39
58
  });
40
59
  }
41
60
  };
61
+ const onSettings = () => {
62
+ setOpenSettings(true);
63
+ };
64
+ const onSave = data => {
65
+ const updateData = {
66
+ ...data
67
+ };
68
+ delete updateData.children;
69
+ Transforms.setNodes(editor, {
70
+ ...updateData
71
+ }, {
72
+ at: path
73
+ });
74
+ onClose();
75
+ };
76
+ const onClose = () => {
77
+ setOpenSettings(false);
78
+ };
42
79
  const GridToolBar = () => {
43
- return selected ? /*#__PURE__*/_jsx("div", {
80
+ return selected ? /*#__PURE__*/_jsxs("div", {
44
81
  className: "grid-container-toolbar",
45
82
  contentEditable: false,
46
- children: /*#__PURE__*/_jsx("button", {
83
+ children: [/*#__PURE__*/_jsx("button", {
84
+ onClick: onSettings,
85
+ children: "Settings"
86
+ }), /*#__PURE__*/_jsx("button", {
47
87
  onClick: onAddGridItem,
48
88
  children: "+ Add Item"
49
- })
89
+ })]
50
90
  }) : null;
51
91
  };
52
92
  return /*#__PURE__*/_jsxs("div", {
53
93
  className: `grid-container ${grid}`,
54
94
  ...attributes,
55
- children: [/*#__PURE__*/_jsx(GridToolBar, {}), children]
95
+ style: {
96
+ paddingLeft: `${left}px`,
97
+ paddingRight: `${right}px`,
98
+ paddingTop: `${top}px`,
99
+ paddingBottom: `${bottom}px`,
100
+ backgroundColor: bgColor,
101
+ justifyContent: horizantal,
102
+ alignContent: vertical,
103
+ backgroundImage: backgroundImage ? `url(${backgroundImage})` : "none",
104
+ border: `1px solid ${borderColor}`
105
+ },
106
+ children: [/*#__PURE__*/_jsx(GridToolBar, {}), openSetttings ? /*#__PURE__*/_jsx(GridPopup, {
107
+ element: element,
108
+ onSave: onSave,
109
+ onClose: onClose,
110
+ customProps: customProps
111
+ }) : null, children]
56
112
  });
57
113
  };
58
114
  export default Grid;
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { IconButton } from "@mui/material";
2
3
  import ViewComfyIcon from "@mui/icons-material/ViewComfy";
3
4
  import { insertGrid } from "../../utils/grid";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -9,12 +10,9 @@ const GridButton = props => {
9
10
  const handleInsertGrid = () => {
10
11
  insertGrid(editor);
11
12
  };
12
- return /*#__PURE__*/_jsx("button", {
13
+ return /*#__PURE__*/_jsx(IconButton, {
13
14
  onClick: handleInsertGrid,
14
15
  title: "Layout",
15
- style: {
16
- marginLeft: "8px"
17
- },
18
16
  children: /*#__PURE__*/_jsx(ViewComfyIcon, {})
19
17
  });
20
18
  };
@@ -1,6 +1,7 @@
1
- import React from "react";
1
+ import React, { useState } from "react";
2
2
  import { Transforms, Element } from "slate";
3
- import { useSelected, useSlateStatic } from "slate-react";
3
+ import { useSelected, useSlateStatic, ReactEditor } from "slate-react";
4
+ import GridItemPopup from "./GridItemPopup";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
6
  import { jsxs as _jsxs } from "react/jsx-runtime";
6
7
  const GridItem = props => {
@@ -9,12 +10,27 @@ const GridItem = props => {
9
10
  children,
10
11
  element
11
12
  } = props;
13
+ const [openSetttings, setOpenSettings] = useState(false);
12
14
  const {
13
- grid
15
+ grid,
16
+ bannerSpacing,
17
+ bgColor,
18
+ alignment
14
19
  } = element;
20
+ const {
21
+ left,
22
+ top,
23
+ right,
24
+ bottom
25
+ } = bannerSpacing || {};
26
+ const {
27
+ vertical,
28
+ horizantal
29
+ } = alignment || {};
15
30
  const editor = useSlateStatic();
16
31
  const selected = useSelected();
17
32
  const itemWidth = (grid || 6) / 12 * 100;
33
+ const path = ReactEditor.findPath(editor, element);
18
34
  const onItemSizeDecrease = () => {
19
35
  Transforms.setNodes(editor, {
20
36
  grid: grid <= 1 ? 1 : grid - 1
@@ -37,7 +53,13 @@ const GridItem = props => {
37
53
  return selected ? /*#__PURE__*/_jsxs("div", {
38
54
  contentEditable: false,
39
55
  className: "grid-item-toolbar",
56
+ style: {
57
+ top: "0px"
58
+ },
40
59
  children: [/*#__PURE__*/_jsx("button", {
60
+ onClick: onSettings,
61
+ children: "Settings"
62
+ }), /*#__PURE__*/_jsx("button", {
41
63
  onClick: onItemSizeDecrease,
42
64
  children: "-"
43
65
  }), /*#__PURE__*/_jsx("button", {
@@ -46,13 +68,45 @@ const GridItem = props => {
46
68
  })]
47
69
  }) : null;
48
70
  };
71
+ const onSettings = () => {
72
+ setOpenSettings(true);
73
+ };
74
+ const onSave = data => {
75
+ const updateData = {
76
+ ...data
77
+ };
78
+ delete updateData.children;
79
+ Transforms.setNodes(editor, {
80
+ ...updateData
81
+ }, {
82
+ at: path
83
+ });
84
+ onClose();
85
+ };
86
+ const onClose = () => {
87
+ setOpenSettings(false);
88
+ };
49
89
  return /*#__PURE__*/_jsxs("div", {
50
90
  className: `grid-item xs-${grid}`,
51
91
  ...attributes,
52
92
  style: {
53
- width: `${itemWidth}%`
93
+ display: "flex",
94
+ flexDirection: "column",
95
+ paddingLeft: `${left}px`,
96
+ paddingRight: `${right}px`,
97
+ paddingTop: `${top}px`,
98
+ paddingBottom: `${bottom}px`,
99
+ backgroundColor: bgColor,
100
+ alignItems: horizantal,
101
+ alignContent: vertical,
102
+ width: `${itemWidth}%`,
103
+ margin: "0px"
54
104
  },
55
- children: [children, /*#__PURE__*/_jsx(GridItemToolbar, {})]
105
+ children: [children, /*#__PURE__*/_jsx(GridItemToolbar, {}), openSetttings ? /*#__PURE__*/_jsx(GridItemPopup, {
106
+ element: element,
107
+ onSave: onSave,
108
+ onClose: onClose
109
+ }) : null]
56
110
  });
57
111
  };
58
112
  export default GridItem;