@flozy/editor 3.8.7 → 3.8.9

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.
Files changed (188) hide show
  1. package/dist/Editor/ChatEditor.js +2 -2
  2. package/dist/Editor/CommonEditor.js +170 -166
  3. package/dist/Editor/DialogWrapper.js +4 -3
  4. package/dist/Editor/Editor.css +4 -7
  5. package/dist/Editor/Elements/AI/AIInput.js +5 -16
  6. package/dist/Editor/Elements/AI/PopoverAIInput.js +64 -67
  7. package/dist/Editor/Elements/AI/Styles.js +1 -2
  8. package/dist/Editor/Elements/AppHeader/AppHeader.js +40 -49
  9. package/dist/Editor/Elements/Button/EditorButton.js +33 -38
  10. package/dist/Editor/Elements/Color Picker/ColorButtons.js +17 -60
  11. package/dist/Editor/Elements/Color Picker/ColorPicker.css +1 -25
  12. package/dist/Editor/Elements/Color Picker/ColorPicker.js +4 -4
  13. package/dist/Editor/Elements/Color Picker/Styles.js +1 -2
  14. package/dist/Editor/Elements/Embed/Image.js +15 -14
  15. package/dist/Editor/Elements/Embed/Video.js +12 -8
  16. package/dist/Editor/Elements/Emoji/EmojiButton.js +11 -7
  17. package/dist/Editor/Elements/Form/Workflow/FormWorkflow.js +3 -12
  18. package/dist/Editor/Elements/Form/Workflow/UserInputs.js +1 -2
  19. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +391 -0
  20. package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +193 -0
  21. package/dist/Editor/Elements/FreeGrid/FreeGridButton.js +23 -0
  22. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +184 -0
  23. package/dist/Editor/Elements/FreeGrid/Options/AddElement.js +36 -0
  24. package/dist/Editor/Elements/FreeGrid/Options/More.js +24 -0
  25. package/dist/Editor/Elements/FreeGrid/Options/SectionSettings.js +47 -0
  26. package/dist/Editor/Elements/FreeGrid/Options/sectionItemOptions.js +11 -0
  27. package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +75 -0
  28. package/dist/Editor/Elements/FreeGrid/styles.js +159 -0
  29. package/dist/Editor/Elements/Grid/Grid.js +14 -34
  30. package/dist/Editor/Elements/Grid/GridItem.js +31 -23
  31. package/dist/Editor/Elements/Link/Link.js +1 -6
  32. package/dist/Editor/Elements/Link/LinkButton.js +2 -4
  33. package/dist/Editor/Elements/Link/LinkPopup.js +3 -10
  34. package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +3 -3
  35. package/dist/Editor/Elements/Signature/SignaturePopup.js +3 -14
  36. package/dist/Editor/Elements/SimpleText/index.js +9 -8
  37. package/dist/Editor/Elements/SimpleText/style.js +37 -0
  38. package/dist/Editor/Elements/Table/Styles.js +1 -23
  39. package/dist/Editor/Elements/Table/Table.js +1 -2
  40. package/dist/Editor/Elements/Table/TableCell.js +7 -69
  41. package/dist/Editor/Elements/TableContextMenu/TableContextMenu.js +0 -1
  42. package/dist/Editor/ErrorBoundary.js +30 -0
  43. package/dist/Editor/MiniEditor.js +1 -3
  44. package/dist/Editor/Styles/EditorStyles.js +23 -0
  45. package/dist/Editor/Toolbar/Basic/index.js +2 -4
  46. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +2 -26
  47. package/dist/Editor/Toolbar/FormatTools/MarkButton.js +2 -2
  48. package/dist/Editor/Toolbar/FormatTools/TextSize.js +18 -29
  49. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +2 -4
  50. package/dist/Editor/Toolbar/Mini/Options/Options.js +0 -10
  51. package/dist/Editor/Toolbar/Mini/Styles.js +0 -7
  52. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectFontSize.js +11 -4
  53. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +86 -213
  54. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +1 -2
  55. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +13 -20
  56. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +8 -52
  57. package/dist/Editor/Toolbar/PopupTool/index.js +13 -6
  58. package/dist/Editor/Toolbar/Toolbar.js +7 -0
  59. package/dist/Editor/Toolbar/toolbarGroups.js +11 -48
  60. package/dist/Editor/assets/svg/AIIcons.js +1 -153
  61. package/dist/Editor/assets/svg/AddTemplateIcon.js +10 -13
  62. package/dist/Editor/assets/svg/TextIcon.js +5 -8
  63. package/dist/Editor/common/ColorPickerButton.js +9 -25
  64. package/dist/Editor/common/DnD/DragHandleButton.js +47 -56
  65. package/dist/Editor/common/Icon.js +8 -41
  66. package/dist/Editor/common/LinkSettings/NavComponents.js +2 -5
  67. package/dist/Editor/common/LinkSettings/index.js +2 -4
  68. package/dist/Editor/common/LinkSettings/navOptions.js +2 -7
  69. package/dist/Editor/common/LinkSettings/style.js +8 -11
  70. package/dist/Editor/common/MentionsPopup/index.js +12 -8
  71. package/dist/Editor/common/RnD/ContextMenu/CMenus.js +105 -0
  72. package/dist/Editor/common/RnD/ContextMenu/index.js +38 -0
  73. package/dist/Editor/common/RnD/ContextMenu/styles.js +21 -0
  74. package/dist/Editor/common/RnD/DragInfo/index.js +31 -0
  75. package/dist/Editor/common/RnD/DragInfo/styles.js +15 -0
  76. package/dist/Editor/common/RnD/DragOver/index.js +46 -0
  77. package/dist/Editor/common/RnD/DragOver/styles.js +23 -0
  78. package/dist/Editor/common/RnD/ElementOptions/Actions.js +82 -0
  79. package/dist/Editor/common/RnD/ElementOptions/Icons/LinkIcon.js +26 -0
  80. package/dist/Editor/common/RnD/ElementOptions/index.js +93 -0
  81. package/dist/Editor/common/RnD/ElementOptions/styles.js +41 -0
  82. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Link.js +153 -0
  83. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Settings.js +58 -0
  84. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/index.js +7 -0
  85. package/dist/Editor/common/RnD/ElementSettings/Settings/BoxSettings.js +46 -0
  86. package/dist/Editor/common/RnD/ElementSettings/Settings/ButtonSettings.js +46 -0
  87. package/dist/Editor/common/RnD/ElementSettings/Settings/ImageSettings.js +46 -0
  88. package/dist/Editor/common/RnD/ElementSettings/Settings/TextSettings.js +30 -0
  89. package/dist/Editor/common/RnD/ElementSettings/Settings/VideoSettings.js +46 -0
  90. package/dist/Editor/common/RnD/ElementSettings/Settings/index.js +13 -0
  91. package/dist/Editor/common/RnD/ElementSettings/index.js +17 -0
  92. package/dist/Editor/common/RnD/ElementSettings/settingsConstants.js +14 -0
  93. package/dist/Editor/common/RnD/ElementSettings/styles.js +76 -0
  94. package/dist/Editor/common/RnD/GuideLines/BoundaryLine.js +52 -0
  95. package/dist/Editor/common/RnD/GuideLines/index.js +33 -0
  96. package/dist/Editor/common/RnD/GuideLines/styles.js +60 -0
  97. package/dist/Editor/common/RnD/OptionsPopup/index.js +50 -0
  98. package/dist/Editor/common/RnD/OptionsPopup/style.js +36 -0
  99. package/dist/Editor/common/RnD/RnDCopy.js +23 -0
  100. package/dist/Editor/common/RnD/ShadowElement.js +34 -0
  101. package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +40 -0
  102. package/dist/Editor/common/RnD/SwitchViewport/styles.js +24 -0
  103. package/dist/Editor/common/RnD/Theme/ViewportStimulator.js +63 -0
  104. package/dist/Editor/common/RnD/TransformHandles/CornerHandle.js +19 -0
  105. package/dist/Editor/common/RnD/TransformHandles/Icons/BottomRightIcon.js +13 -0
  106. package/dist/Editor/common/RnD/TransformHandles/SizeHandle.js +18 -0
  107. package/dist/Editor/common/RnD/TransformHandles/index.js +62 -0
  108. package/dist/Editor/common/RnD/Utils/alignmentDetection.js +26 -0
  109. package/dist/Editor/common/RnD/Utils/calculateDropItem.js +98 -0
  110. package/dist/Editor/common/RnD/Utils/collisionDetection.js +52 -0
  111. package/dist/Editor/common/RnD/Utils/gridDropItem.js +148 -0
  112. package/dist/Editor/common/RnD/Utils/index.js +251 -0
  113. package/dist/Editor/common/RnD/VirtualElement/index.js +76 -0
  114. package/dist/Editor/common/RnD/VirtualElement/styles.js +27 -0
  115. package/dist/Editor/common/RnD/VirtualElement/updateAutoProps.js +28 -0
  116. package/dist/Editor/common/RnD/index.js +503 -0
  117. package/dist/Editor/common/RnD/styles.js +4 -0
  118. package/dist/Editor/common/Section/index.js +28 -69
  119. package/dist/Editor/common/Section/styles.js +6 -12
  120. package/dist/Editor/common/Shorthands/elements.js +12 -54
  121. package/dist/Editor/common/StyleBuilder/boxStyle.js +30 -0
  122. package/dist/Editor/common/StyleBuilder/buttonStyle.js +2 -4
  123. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +16 -19
  124. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +7 -15
  125. package/dist/Editor/common/StyleBuilder/fieldTypes/buttonLink.js +1 -1
  126. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +7 -31
  127. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +4 -13
  128. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +4 -2
  129. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +4 -14
  130. package/dist/Editor/common/StyleBuilder/index.js +1 -1
  131. package/dist/Editor/common/StyleBuilder/sectionStyle.js +13 -2
  132. package/dist/Editor/common/iconslist.js +31 -0
  133. package/dist/Editor/helper/RnD/focusOnNewItem.js +39 -0
  134. package/dist/Editor/helper/RnD/scrollToNewSection.js +24 -0
  135. package/dist/Editor/helper/breakpoint.js +5 -0
  136. package/dist/Editor/helper/index.js +139 -0
  137. package/dist/Editor/helper/theme.js +48 -185
  138. package/dist/Editor/hooks/useBreakpoints.js +34 -0
  139. package/dist/Editor/hooks/useMouseMove.js +37 -12
  140. package/dist/Editor/hooks/useWindowMessage.js +7 -10
  141. package/dist/Editor/hooks/withCommon.js +2 -1
  142. package/dist/Editor/hooks/withErrorHandling.js +14 -0
  143. package/dist/Editor/plugins/withEmbeds.js +1 -1
  144. package/dist/Editor/plugins/withHTML.js +1 -1
  145. package/dist/Editor/plugins/withTable.js +1 -1
  146. package/dist/Editor/theme/ThemeList.js +173 -50
  147. package/dist/Editor/utils/RnD/RnDCtrlCmds.js +168 -0
  148. package/dist/Editor/utils/SlateUtilityFunctions.js +47 -163
  149. package/dist/Editor/utils/button.js +17 -1
  150. package/dist/Editor/utils/events.js +7 -54
  151. package/dist/Editor/utils/font.js +37 -40
  152. package/dist/Editor/utils/freegrid.js +49 -0
  153. package/dist/Editor/utils/helper.js +31 -31
  154. package/dist/Editor/utils/table.js +43 -51
  155. package/package.json +6 -4
  156. package/dist/Editor/Elements/AI/VoiceToText/AudioWave.js +0 -73
  157. package/dist/Editor/Elements/AI/VoiceToText/index.js +0 -167
  158. package/dist/Editor/Elements/AI/VoiceToText/style.js +0 -40
  159. package/dist/Editor/Elements/Link/LinkPopupStyles.js +0 -28
  160. package/dist/Editor/Elements/Redo/RedoButton.js +0 -14
  161. package/dist/Editor/Elements/Undo/UndoButton.js +0 -14
  162. package/dist/Editor/Toolbar/PopupTool/ThemeTextFormat.js +0 -438
  163. package/dist/Editor/assets/svg/RedoIcon.js +0 -27
  164. package/dist/Editor/assets/svg/SettingsIcon.js +0 -28
  165. package/dist/Editor/assets/svg/ThemeIcons.js +0 -291
  166. package/dist/Editor/assets/svg/UndoIcon.js +0 -27
  167. package/dist/Editor/common/CustomColorPicker/index.js +0 -106
  168. package/dist/Editor/common/CustomColorPicker/style.js +0 -53
  169. package/dist/Editor/common/CustomDialog/index.js +0 -94
  170. package/dist/Editor/common/CustomDialog/style.js +0 -67
  171. package/dist/Editor/common/CustomSelect.js +0 -33
  172. package/dist/Editor/hooks/useEditorTheme.js +0 -139
  173. package/dist/Editor/theme/index.js +0 -144
  174. package/dist/Editor/themeSettings/ActiveTheme.js +0 -72
  175. package/dist/Editor/themeSettings/buttons/index.js +0 -290
  176. package/dist/Editor/themeSettings/buttons/style.js +0 -21
  177. package/dist/Editor/themeSettings/colorTheme/index.js +0 -290
  178. package/dist/Editor/themeSettings/colorTheme/style.js +0 -77
  179. package/dist/Editor/themeSettings/fonts/PreviewElement.js +0 -123
  180. package/dist/Editor/themeSettings/fonts/index.js +0 -213
  181. package/dist/Editor/themeSettings/fonts/style.js +0 -44
  182. package/dist/Editor/themeSettings/icons.js +0 -60
  183. package/dist/Editor/themeSettings/index.js +0 -320
  184. package/dist/Editor/themeSettings/style.js +0 -152
  185. package/dist/Editor/themeSettingsAI/icons.js +0 -96
  186. package/dist/Editor/themeSettingsAI/index.js +0 -356
  187. package/dist/Editor/themeSettingsAI/saveTheme.js +0 -190
  188. package/dist/Editor/themeSettingsAI/style.js +0 -247
@@ -0,0 +1,148 @@
1
+ import { Transforms, Node } from "slate";
2
+ import { ReactEditor } from "slate-react";
3
+ export const ROW_HEIGHT = 50;
4
+ const MARGIN_OF = {
5
+ xs: 160,
6
+ lg: 490
7
+ };
8
+
9
+ /**
10
+ * This method will update the grid template rows of parent section based on height
11
+ * @param {*} path
12
+ */
13
+ export function updateRows() {}
14
+
15
+ /**
16
+ * This method will update the grid template columns of parent section based on height
17
+ * @param {*} path
18
+ */
19
+ export function updateCols() {}
20
+ const handleMoveNode = (editor, path, newPath, {
21
+ isEmpty
22
+ }) => {
23
+ try {
24
+ const replaceNode = Node.get(editor, path);
25
+ if (isEmpty) {
26
+ const toPath = [...newPath, 0];
27
+ Transforms.insertNodes(editor, [{
28
+ ...replaceNode
29
+ }], {
30
+ at: toPath
31
+ });
32
+ Transforms.removeNodes(editor, {
33
+ at: path
34
+ });
35
+ return toPath;
36
+ } else {
37
+ Transforms.insertNodes(editor, [{
38
+ ...replaceNode
39
+ }], {
40
+ at: newPath
41
+ });
42
+ Transforms.removeNodes(editor, {
43
+ at: path
44
+ });
45
+ return newPath;
46
+ }
47
+ } catch (err) {
48
+ console.log(err);
49
+ console.log("Drop Node error");
50
+ return null;
51
+ }
52
+ };
53
+
54
+ /**
55
+ * This method will update prop in child node so it will re-render and update the path
56
+ * @param {*} path - contains the parent section path
57
+ */
58
+ const reRenderChildNodes = (editor, path) => {
59
+ try {
60
+ const sectionNode = Node.get(editor, path);
61
+ // parent node
62
+ Transforms.setNodes(editor, {
63
+ updated_at: new Date().getTime()
64
+ }, {
65
+ at: path
66
+ });
67
+ sectionNode?.children?.forEach((item, itemIndex) => {
68
+ Transforms.setNodes(editor, {
69
+ updated_at: new Date().getTime()
70
+ }, {
71
+ at: [...path, itemIndex]
72
+ });
73
+ });
74
+ } catch (err) {
75
+ console.log(err);
76
+ }
77
+ };
78
+ export function onDropItem(props, parentClass) {
79
+ try {
80
+ const {
81
+ editor,
82
+ startPosition,
83
+ endPosition,
84
+ dragOver,
85
+ parentPath,
86
+ path,
87
+ diffX,
88
+ x: cx,
89
+ breakpoint
90
+ } = props;
91
+ const posX = parseInt(cx - window.innerWidth / 2 + MARGIN_OF[breakpoint] - diffX);
92
+ const needMove = dragOver !== parentPath;
93
+ const moveTo = dragOver.split("|").map(m => parseInt(m));
94
+ const from = parentPath.split("|").map(m => parseInt(m));
95
+ let newPath = [];
96
+ newPath = moveTo;
97
+ const toSectionNode = Node.get(editor, newPath);
98
+ const addToSectionDOM = ReactEditor.toDOMNode(editor, toSectionNode);
99
+ const rect = addToSectionDOM.getBoundingClientRect();
100
+ const y = endPosition.y - startPosition.diffY - rect.top;
101
+
102
+ // Calculate grid position
103
+ const row = Math.floor(y / ROW_HEIGHT) + 1;
104
+
105
+ // to calculate difference inside the grid
106
+ const marginTop = Math.abs((row - 1) * ROW_HEIGHT - y);
107
+
108
+ // Update grid area
109
+ const gridArea = `${row} / 1 / ${row + 1} / 2`;
110
+ const appenBp = breakpoint === "lg" ? "" : `_${breakpoint}`;
111
+ Transforms.setNodes(editor, {
112
+ [`gridArea${appenBp}`]: gridArea,
113
+ [`left${appenBp}`]: posX,
114
+ [`marginTop${appenBp}`]: marginTop,
115
+ // to avoid auto position / resize of the element
116
+ [`${breakpoint}_updatedOn`]: new Date().getTime()
117
+ }, {
118
+ at: path
119
+ });
120
+ reRenderChildNodes(editor, from);
121
+
122
+ // move the node if section parent changed
123
+ if (needMove) {
124
+ // move the node
125
+ const isEmpty = toSectionNode?.children[0]?.type === undefined;
126
+ if (!isEmpty) {
127
+ newPath = [...newPath, toSectionNode?.children?.length];
128
+ }
129
+ const rPath = handleMoveNode(editor, path, newPath, {
130
+ isEmpty
131
+ });
132
+ reRenderChildNodes(editor, moveTo);
133
+ return {
134
+ updated_at: rPath
135
+ };
136
+ } else {
137
+ return {
138
+ updated_at: path
139
+ };
140
+ }
141
+ } catch (err) {
142
+ console.log(err);
143
+ }
144
+ }
145
+ export function calculateGridArea(y) {
146
+ const row = Math.floor(y / ROW_HEIGHT) + 1;
147
+ return `${row} / 1 / ${row + 1} / 2`;
148
+ }
@@ -0,0 +1,251 @@
1
+ import { Transforms, Node } from "slate";
2
+ import { ReactEditor } from "slate-react";
3
+ import { getNearestItem } from "./calculateDropItem";
4
+ const GUIDE_LINE_THRESHOLD = 5;
5
+ const GUIDE_LINE_OVERLAP_THRESHOLD = 50;
6
+ const handleMoveNode = (editor, path, newPath, {
7
+ isEmpty
8
+ }) => {
9
+ try {
10
+ const replaceNode = Node.get(editor, path);
11
+ if (isEmpty) {
12
+ const toPath = [...newPath, 0];
13
+ Transforms.insertNodes(editor, [{
14
+ ...replaceNode
15
+ }], {
16
+ at: toPath
17
+ });
18
+ Transforms.removeNodes(editor, {
19
+ at: path
20
+ });
21
+ return toPath;
22
+ } else {
23
+ Transforms.insertNodes(editor, [{
24
+ ...replaceNode
25
+ }], {
26
+ at: newPath
27
+ });
28
+ Transforms.removeNodes(editor, {
29
+ at: path
30
+ });
31
+ return newPath;
32
+ }
33
+ } catch (err) {
34
+ console.log(err);
35
+ console.log("Drop Node error");
36
+ return null;
37
+ }
38
+ };
39
+ export function triggerClick(editor, path = []) {
40
+ try {
41
+ const triggerNode = Node.get(editor, path);
42
+ const triggerNodeDOM = ReactEditor.toDOMNode(editor, triggerNode);
43
+ triggerNodeDOM?.closest(".freegrid-item")?.click();
44
+ } catch (err) {
45
+ console.log(err);
46
+ }
47
+ }
48
+ export function updatePositions(props, closestClass) {
49
+ try {
50
+ const {
51
+ editor,
52
+ path,
53
+ offsetY,
54
+ dragOver,
55
+ x,
56
+ y,
57
+ diffX,
58
+ parentPath
59
+ } = props;
60
+ const posY = y - offsetY;
61
+ const posX = parseInt(x - window.innerWidth / 2 + 490 - diffX);
62
+ let addToSectionDOMRect = null;
63
+ let newPath = [];
64
+ let toSectionNode = null;
65
+ const needMove = dragOver !== parentPath;
66
+ const moveTo = dragOver.split("|").map(m => parseInt(m));
67
+ const from = parentPath.split("|").map(m => parseInt(m));
68
+ newPath = moveTo;
69
+ toSectionNode = Node.get(editor, newPath);
70
+ const addToSectionDOM = ReactEditor.toDOMNode(editor, toSectionNode);
71
+ addToSectionDOMRect = addToSectionDOM?.getBoundingClientRect();
72
+
73
+ // update top and left properties
74
+ const newProperties = {};
75
+ newProperties.left = posX;
76
+ newProperties.marginTop = posY > addToSectionDOMRect.top ? posY - addToSectionDOMRect.top : addToSectionDOMRect.top - posY;
77
+ Transforms.setNodes(editor, newProperties, {
78
+ at: path
79
+ });
80
+ const returnData = {};
81
+ if (needMove) {
82
+ const isEmpty = toSectionNode?.children[0]?.type === undefined;
83
+ if (!isEmpty) {
84
+ newPath = [...newPath, toSectionNode?.children?.length];
85
+ }
86
+ newPath = newPath.map(m => parseInt(m));
87
+ const rPath = handleMoveNode(editor, path, newPath, {
88
+ isEmpty
89
+ });
90
+ // to update path index need to re-render items in parent sections
91
+ Transforms.setNodes(editor, {
92
+ updated_at: new Date().getTime
93
+ }, {
94
+ at: parentPath.split("|").map(m => parseInt(m))
95
+ });
96
+ returnData.updated_at = rPath;
97
+ }
98
+ returnData.updated_at = path;
99
+ if (needMove) {
100
+ getNearestItem(editor, moveTo, {
101
+ currentItem: path
102
+ });
103
+ } else {
104
+ getNearestItem(editor, from, {
105
+ currentItem: path
106
+ });
107
+ }
108
+ return returnData;
109
+ } catch (err) {
110
+ console.log(err);
111
+ }
112
+ }
113
+ const isOverLapLine = ({
114
+ x,
115
+ y
116
+ }, lines) => {
117
+ return lines.find(f => Math.abs(f.x - x) <= GUIDE_LINE_OVERLAP_THRESHOLD || Math.abs(f.y - y) <= GUIDE_LINE_OVERLAP_THRESHOLD);
118
+ };
119
+ export function getClosestDraggable(x, y, className, activeClassName) {
120
+ const draggables = document.querySelectorAll(className);
121
+ const activeDragEle = document.querySelectorAll(activeClassName)[0];
122
+ const {
123
+ left: aLeft,
124
+ top: aTop,
125
+ width: aWidth,
126
+ height: aHeight
127
+ } = activeDragEle?.getBoundingClientRect() || {};
128
+ let lines = [];
129
+ draggables.forEach(draggable => {
130
+ const {
131
+ left,
132
+ top,
133
+ width,
134
+ height
135
+ } = draggable.getBoundingClientRect();
136
+ let xVal = 0;
137
+ let yVal = 0;
138
+
139
+ // top match
140
+ xVal = x < left ? aLeft : left;
141
+ yVal = top;
142
+ if (Math.abs(top - aTop) <= GUIDE_LINE_THRESHOLD && !isOverLapLine({
143
+ x: xVal,
144
+ y: yVal
145
+ }, lines)) {
146
+ lines.push({
147
+ y: top,
148
+ x: xVal,
149
+ width: x > left ? Math.abs(aLeft + aWidth - left) : Math.abs(aLeft - (left + width)),
150
+ height: 1
151
+ });
152
+ }
153
+
154
+ // bottom match
155
+ xVal = x < left ? aLeft : left;
156
+ yVal = top + height;
157
+ if (Math.abs(top + height - (aTop + aHeight)) <= GUIDE_LINE_THRESHOLD && !isOverLapLine({
158
+ x: xVal,
159
+ y: yVal
160
+ }, lines)) {
161
+ lines.push({
162
+ y: yVal,
163
+ x: xVal,
164
+ width: x > left ? Math.abs(aLeft + aWidth - left) : Math.abs(aLeft - (left + width)),
165
+ height: 1
166
+ });
167
+ }
168
+
169
+ // center match
170
+ xVal = x < left ? aLeft : left;
171
+ yVal = top + height / 2;
172
+ if (Math.abs(top + height / 2 - (aTop + aHeight / 2)) <= GUIDE_LINE_THRESHOLD && !isOverLapLine({
173
+ x: xVal,
174
+ y: yVal
175
+ }, lines, "y")) {
176
+ lines.push({
177
+ y: yVal,
178
+ x: xVal,
179
+ width: x > left ? Math.abs(aLeft + aWidth - left) : Math.abs(aLeft - (left + width)),
180
+ height: 1
181
+ });
182
+ }
183
+
184
+ // right match
185
+ xVal = left + width;
186
+ yVal = top < aTop ? top : aTop;
187
+ if ((Math.abs(left + width - aLeft) <= GUIDE_LINE_THRESHOLD || Math.abs(left - aLeft) <= GUIDE_LINE_THRESHOLD) && !isOverLapLine({
188
+ x: xVal,
189
+ y: yVal
190
+ }, lines)) {
191
+ lines.push({
192
+ y: yVal,
193
+ x: xVal,
194
+ width: 1,
195
+ height: Math.abs(aTop - top)
196
+ });
197
+ }
198
+
199
+ // left match
200
+ xVal = left;
201
+ yVal = top < aTop ? top : aTop;
202
+ if ((Math.abs(aLeft + aWidth - left) <= GUIDE_LINE_THRESHOLD || Math.abs(aLeft - left) <= GUIDE_LINE_THRESHOLD) && !isOverLapLine({
203
+ x: xVal,
204
+ y: yVal
205
+ }, lines)) {
206
+ lines.push({
207
+ y: yVal,
208
+ x: xVal,
209
+ width: 1,
210
+ height: Math.abs(aTop - top)
211
+ });
212
+ }
213
+
214
+ // middle match
215
+ xVal = left + width / 2;
216
+ yVal = top < aTop ? top : aTop;
217
+ if (Math.abs(aLeft + aWidth / 2 - (left + width / 2)) <= GUIDE_LINE_THRESHOLD && !isOverLapLine({
218
+ x: xVal,
219
+ y: yVal
220
+ }, lines)) {
221
+ lines.push({
222
+ y: yVal,
223
+ x: xVal,
224
+ width: 1,
225
+ height: Math.abs(aTop - top)
226
+ });
227
+ }
228
+ });
229
+ return lines;
230
+ }
231
+ export function isDragOver(rect, mousePosition) {
232
+ const {
233
+ x,
234
+ y
235
+ } = mousePosition;
236
+ if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) {
237
+ return true;
238
+ }
239
+ return false;
240
+ }
241
+ export function getParentSectionPath(props, closestClass) {
242
+ try {
243
+ const {
244
+ ref
245
+ } = props;
246
+ const parentDom = ref?.closest(closestClass);
247
+ return parentDom?.dataset?.path;
248
+ } catch (err) {
249
+ console.log(err);
250
+ }
251
+ }
@@ -0,0 +1,76 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { Box } from "@mui/material";
3
+ import useVirtualElementStyles from "./styles";
4
+ import updateAutoProps from "./updateAutoProps";
5
+ import { calculateGridArea } from "../Utils/gridDropItem";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const VirtualElement = props => {
8
+ const classes = useVirtualElementStyles();
9
+ const {
10
+ editor,
11
+ path,
12
+ parentEle,
13
+ updated_at
14
+ } = props;
15
+ const cloneNode = parentEle?.cloneNode(true);
16
+ const virtualRef = useRef();
17
+ useEffect(() => {
18
+ if (virtualRef?.current) {
19
+ setTimeout(() => {
20
+ calculateProps();
21
+ }, 0);
22
+ }
23
+ }, [updated_at, virtualRef?.current]);
24
+ const calculateProps = () => {
25
+ const rect = virtualRef?.current?.getBoundingClientRect();
26
+ const sectionProps = {
27
+ path,
28
+ props: {
29
+ height: rect.height
30
+ }
31
+ };
32
+ const itemsData = [];
33
+ const items = virtualRef?.current?.querySelectorAll(".freegrid-item");
34
+ let sectionHeight = 0;
35
+ for (let i = 0; i < items.length; i++) {
36
+ const itemRect = items[i]?.getBoundingClientRect();
37
+ const y = Math.abs(rect.top - itemRect?.top);
38
+ itemsData.push({
39
+ path: items[i]?.dataset.path,
40
+ props: {
41
+ top: y,
42
+ left: 24,
43
+ marginTop: 12,
44
+ width: itemRect?.width,
45
+ height: itemRect?.height,
46
+ gridArea: calculateGridArea(y)
47
+ }
48
+ });
49
+ sectionHeight += itemRect?.height;
50
+ }
51
+ if (sectionHeight > sectionProps?.props?.height) {
52
+ sectionProps.props.height = sectionHeight;
53
+ }
54
+ const allData = [sectionProps, itemsData]?.flat();
55
+ // it should trigger by auto alignment or on clicking mobile view change
56
+ updateAutoProps(editor, allData, "xs");
57
+ };
58
+ const getItems = () => {
59
+ const items = cloneNode?.querySelectorAll(".freegrid-item") || [];
60
+ let itemsHTML = "";
61
+ for (let i = 0; i < items?.length; i++) {
62
+ items[i].classList.add("exclude-virtual");
63
+ itemsHTML += items[i].outerHTML;
64
+ }
65
+ return itemsHTML;
66
+ };
67
+ return /*#__PURE__*/_jsx(Box, {
68
+ className: "mobile-virtual-mode",
69
+ ref: virtualRef,
70
+ sx: classes.root,
71
+ dangerouslySetInnerHTML: {
72
+ __html: getItems()
73
+ }
74
+ });
75
+ };
76
+ export default VirtualElement;
@@ -0,0 +1,27 @@
1
+ const useVirtualElementStyles = () => ({
2
+ root: {
3
+ width: "320px",
4
+ position: "fixed",
5
+ backgroundColor: "red",
6
+ height: "auto",
7
+ overflow: "visible",
8
+ pointerEvents: "none",
9
+ opacity: 0,
10
+ right: 0,
11
+ top: 0,
12
+ "& .freegrid-item": {
13
+ gridArea: "none !important",
14
+ width: "calc(100% - 48px) !important",
15
+ height: "auto !important",
16
+ left: "24px !important",
17
+ marginTop: "24px !important",
18
+ "& .debug-info, & .editor-blocker": {
19
+ display: "none"
20
+ },
21
+ "& .embed": {
22
+ minHeight: "300px"
23
+ }
24
+ }
25
+ }
26
+ });
27
+ export default useVirtualElementStyles;
@@ -0,0 +1,28 @@
1
+ import { Node, Transforms } from "slate";
2
+ const updateAutoProps = (editor, datas = [], breakpoint = "") => {
3
+ try {
4
+ for (let i = 0; i < datas.length; i++) {
5
+ const {
6
+ path,
7
+ props
8
+ } = datas[i] || {};
9
+ const int_path = path.split("|").map(m => parseInt(m));
10
+ const updatedProps = Object.keys(props).reduce((a, b) => {
11
+ const key = breakpoint ? `${b}_${breakpoint}` : b;
12
+ a[key] = props[b];
13
+ return a;
14
+ }, {});
15
+ const oldProps = Node.get(editor, int_path);
16
+ if (!oldProps?.xs_updatedOn) {
17
+ Transforms.setNodes(editor, {
18
+ ...updatedProps
19
+ }, {
20
+ at: int_path
21
+ });
22
+ }
23
+ }
24
+ } catch (err) {
25
+ console.log(err);
26
+ }
27
+ };
28
+ export default updateAutoProps;