@flozy/editor 9.1.9 → 9.2.1

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.
@@ -1280,8 +1280,8 @@ blockquote {
1280
1280
  }
1281
1281
  @media (max-width: 899px) {
1282
1282
  /* Qa validation required */
1283
- /* .MuiPopover-root {
1284
- z-index: 1302 !important;
1283
+ /* .MuiPopover-root {
1284
+ z-index: 1302 !important;
1285
1285
  } */
1286
1286
 
1287
1287
  canvas {
@@ -5,7 +5,7 @@ import { Box } from "@mui/material";
5
5
  import { isTextSelected } from "../../utils/helper";
6
6
  import { useEditorContext } from "../../hooks/useMouseMove";
7
7
  import SimpleTextStyle from "./style";
8
- import { getBreakpointLineSpacing } from "../../helper/theme";
8
+ // import { getBreakpointLineSpacing } from "../../helper/theme";
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  import { Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -155,7 +155,7 @@ const TableCell = props => {
155
155
  };
156
156
  useEffect(() => {
157
157
  const currentPath = path?.toString();
158
- setTimeout(() => {
158
+ const timeoutId = setTimeout(() => {
159
159
  if (tableResizing === currentPath) {
160
160
  setTableResizing(null);
161
161
 
@@ -171,6 +171,7 @@ const TableCell = props => {
171
171
  if (resizing) {
172
172
  setTableResizing(currentPath);
173
173
  }
174
+ return () => clearTimeout(timeoutId);
174
175
  }, [resizing]);
175
176
  const onMouseEnter = path => {
176
177
  setHoverPath(path);
@@ -33,17 +33,14 @@ const TextFormat = props => {
33
33
  const [anchorEl, setAnchorEl] = useState(null);
34
34
  const [type, setType] = useState(null);
35
35
  const open = Boolean(anchorEl);
36
- const {
37
- element: pageSt
38
- } = getPageSettings(editor) || {};
36
+
37
+ // const { element: pageSt } = getPageSettings(editor) || {};
39
38
  // const pageSettingLine = pageSt?.pageProps?.lineHeight;
40
39
  const {
41
40
  fontFamilies,
42
41
  theme
43
42
  } = useEditorContext();
44
- const {
45
- activeBreakPoint
46
- } = useEditorContext();
43
+ // const { activeBreakPoint } = useEditorContext();
47
44
  // const breakpoint = activeBreakPoint === "" ? "lg" : activeBreakPoint;
48
45
  const fontWeight = allTools.find(f => f.format === "fontWeight");
49
46
  const fontStyle = allTools.filter(f => f.type === "mark" && f.format !== "strikethrough" && f.format !== "superscript" && f.format !== "subscript");
@@ -14,7 +14,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
14
14
  const PopupTool = props => {
15
15
  const {
16
16
  theme,
17
- setIsTextSelected,
18
17
  customProps,
19
18
  editorWrapper
20
19
  } = props;
@@ -35,6 +34,9 @@ const PopupTool = props => {
35
34
  const [size] = useWindowResize();
36
35
  const updateAnchorEl = isScroll => {
37
36
  try {
37
+ const {
38
+ selection
39
+ } = editor;
38
40
  const isHavingSelection = selection && !Range.isCollapsed(selection);
39
41
  if (isHavingSelection && event === "end") {
40
42
  const domRange = ReactEditor.toDOMRange(editor, editor.selection);
@@ -74,29 +76,39 @@ const PopupTool = props => {
74
76
  if (!isCarouselEdit) {
75
77
  setOpen(true);
76
78
  setPopupType("textFormat");
77
- setIsTextSelected(true);
79
+ // setIsTextSelected(true);
78
80
  }
79
81
  } else if (!anchorEl) {
80
82
  setOpen(false);
81
83
  setPopupType("");
82
- setIsTextSelected(false);
84
+ // setIsTextSelected(false);
83
85
  }
84
86
  }, [event, anchorEl]);
85
87
  useEffect(() => {
86
- if (!selection || Range.isCollapsed(selection) || Editor.string(editor, selection) === "" || selectedElement?.enable === 1) {
88
+ console.log("Editor useEffect", selection);
89
+ const {
90
+ path,
91
+ enable
92
+ } = selectedElement || {};
93
+ const isFreeGridElement = path && path.split("|").length > 2;
94
+ const isFreeGridEnabled = enable === 1 && isFreeGridElement;
95
+ if (!selection || Range.isCollapsed(selection) || Editor.string(editor, selection) === "" || isFreeGridEnabled) {
87
96
  setAnchorEl(null);
88
97
  } else {
98
+ console.log("Editor updateAnchorEl", selection);
89
99
  updateAnchorEl();
90
100
  hideSlateSelection(); // removes slate selection background, when there is no selection
91
101
  }
92
102
  }, [selection, event, selectedElement?.enable]);
93
103
  const handleClose = () => {
104
+ console.log("Editor closing");
94
105
  // setAnchorEl(null);
95
106
  setOpen(false);
96
107
  setPopupType("");
97
108
  };
98
109
  return open && !openAI ? /*#__PURE__*/_jsx(ClickAwayListener, {
99
110
  onClickAway: e => {
111
+ console.log("ClickAwayListener", e.target, document.body, e.target !== document.body);
100
112
  // close the mini toolbar, if user clicks outside the editor (in Flozy app.)
101
113
  if (e.target !== document.body) {
102
114
  // e.target returns body, if the user clicks material ui select popup inside the tool bar, on that time, we don't need to close
@@ -19,7 +19,7 @@ const Upload = props => {
19
19
  xs: 12,
20
20
  sx: {
21
21
  padding: "10px",
22
- height: '100%'
22
+ height: "100%"
23
23
  },
24
24
  className: "ims-right",
25
25
  children: /*#__PURE__*/_jsx(Uploader, {
@@ -5,9 +5,9 @@ const UploadStyles = theme => ({
5
5
  borderRadius: "11px",
6
6
  boxShadow: "0px 4px 10px rgba(0, 0, 0, 0.16)",
7
7
  background: theme?.palette?.editor?.uploadFileBg,
8
- height: '100%',
9
- minHeight: '150px',
10
- height: 'inherit'
8
+ height: "100%",
9
+ minHeight: "150px",
10
+ height: "inherit"
11
11
  },
12
12
  uploadField: {
13
13
  width: "100%",
@@ -19,21 +19,21 @@ const UploadStyles = theme => ({
19
19
  backgroundColor: theme?.palette?.editor?.uploadFileInnerBg,
20
20
  borderRadius: "9px",
21
21
  border: "1px dashed #2563EB",
22
- minHeight: '150px'
22
+ minHeight: "150px"
23
23
  },
24
24
  uploadIcon: {
25
25
  display: "grid !important",
26
26
  "& svg": {
27
- display: 'flex',
28
- width: '100%',
27
+ display: "flex",
28
+ width: "100%",
29
29
  "& path": {
30
30
  stroke: "#2563EB"
31
31
  }
32
32
  },
33
- '& span': {
34
- display: 'flex',
35
- width: '100%',
36
- marginTop: '5px'
33
+ "& span": {
34
+ display: "flex",
35
+ width: "100%",
36
+ marginTop: "5px"
37
37
  }
38
38
  }
39
39
  });
@@ -58,6 +58,7 @@ const useElementSettingsStyle = theme => ({
58
58
  maxHeight: "500px",
59
59
  overflowX: "hidden",
60
60
  overflowY: "auto",
61
+ paddingLeft: "4px",
61
62
  background: theme?.palette?.editor?.background,
62
63
  paddingLeft: "4px",
63
64
  "& .MuiTypography-root, .MuiInputBase-root, input": {
@@ -1,19 +1,9 @@
1
1
  import React from "react";
2
- import { useTheme, ThemeProvider, createTheme } from "@mui/material";
2
+ import { useTheme, ThemeProvider, createTheme, useMediaQuery } from "@mui/material";
3
3
  import { isStimulator, STIMULATOR_MOCK } from "../../../hooks/useBreakpoints";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- const isPdf = () => {
6
- try {
7
- const hash = window.location.hash;
8
- const queryString = hash.split("?")[1]; // Get part after "?"
9
- const params = new URLSearchParams(queryString);
10
- return params.get("isPdf");
11
- } catch (err) {
12
- console.log(err);
13
- }
14
- };
15
4
 
16
5
  // Custom breakpoints functions
6
+ import { jsx as _jsx } from "react/jsx-runtime";
17
7
  const customUp = (key, breakpoints) => {
18
8
  const MOCK_BREAKPOINT = isStimulator();
19
9
  if (key === "xs") {
@@ -59,9 +49,9 @@ const getBreakPoints = prevTheme => {
59
49
  };
60
50
 
61
51
  // Extend the existing theme with custom breakpoint functions
62
- const extendedTheme = prevTheme => createTheme({
52
+ const extendedTheme = (prevTheme, isPrintMode) => createTheme({
63
53
  ...prevTheme,
64
- breakpoints: isPdf() ? {
54
+ breakpoints: isPrintMode ? {
65
55
  values: {
66
56
  ...prevTheme.breakpoints.values,
67
57
  md: 400 // To resolve, while taking pdf on A4 size, it is getting mobile view because of breakpoint
@@ -72,7 +62,8 @@ const ViewportStimulator = ({
72
62
  children
73
63
  }) => {
74
64
  const theme = useTheme();
75
- const viewportTheme = extendedTheme(theme);
65
+ const isPrintMode = useMediaQuery("print");
66
+ const viewportTheme = extendedTheme(theme, isPrintMode);
76
67
  return /*#__PURE__*/_jsx(ThemeProvider, {
77
68
  theme: viewportTheme,
78
69
  children: children
@@ -75,12 +75,13 @@ const VirtualElement = props => {
75
75
  const virtualRef = useRef();
76
76
  useEffect(() => {
77
77
  if (virtualRef?.current) {
78
- setTimeout(() => {
78
+ const timeoutId = setTimeout(() => {
79
79
  const allData = calculateProps(path, virtualRef?.current, ROOT_ITEM_CLASS, []);
80
80
  const groupData = groupByPathAndCalculateHeight(allData);
81
81
  // it should trigger by auto alignment or on clicking mobile view change
82
82
  updateAutoProps(editor, allData, "xs", groupData);
83
83
  }, 100);
84
+ return () => clearTimeout(timeoutId);
84
85
  }
85
86
  }, [updated_at, virtualRef?.current]);
86
87
  const calculateProps = (curPath, dom, domClass, allData) => {
@@ -287,18 +287,22 @@ export const bringItemToFB = (editor, {
287
287
  };
288
288
  export const debounce = function (func, wait, immediate) {
289
289
  let timeout;
290
- return function () {
291
- const context = this,
292
- args = arguments,
293
- later = function () {
294
- timeout = null;
295
- if (!immediate) func.apply(context, args);
296
- },
297
- callNow = immediate && !timeout;
290
+ function debounced(...args) {
291
+ const context = this;
292
+ const later = function () {
293
+ timeout = null;
294
+ if (!immediate) func.apply(context, args);
295
+ };
296
+ const callNow = immediate && !timeout;
298
297
  clearTimeout(timeout);
299
298
  timeout = setTimeout(later, wait);
300
299
  if (callNow) func.apply(context, args);
300
+ }
301
+ debounced.cancel = function () {
302
+ clearTimeout(timeout);
303
+ timeout = null;
301
304
  };
305
+ return debounced;
302
306
  };
303
307
  export const getTextColor = (color = "") => {
304
308
  return color?.indexOf("gradient") >= 0 ? {
@@ -337,14 +341,14 @@ export const isCarouselSelected = editor => {
337
341
  return false;
338
342
  }
339
343
  const [nodeEntry] = Editor.nodes(editor, {
340
- match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === 'carousel'
344
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "carousel"
341
345
  });
342
346
  if (!nodeEntry) {
343
347
  return false;
344
348
  }
345
349
  const [node] = nodeEntry;
346
350
  const carouselDom = ReactEditor.toDOMNode(editor, node);
347
- const isEdit = carouselDom.classList.contains('carousel_slider_edit');
351
+ const isEdit = carouselDom.classList.contains("carousel_slider_edit");
348
352
  return !isEdit;
349
353
  } catch (err) {
350
354
  console.log(err);
@@ -1,26 +1,20 @@
1
- import { useEffect, useState } from "react";
1
+ import { useCallback, useEffect, useState } from "react";
2
2
  const useDrag = () => {
3
3
  const [event, setEvent] = useState("");
4
4
  useEffect(() => {
5
- addListener();
6
- return () => {
7
- removeListener();
5
+ const onMouseDown = () => {
6
+ setEvent("start");
7
+ };
8
+ const onMouseUp = () => {
9
+ setEvent("end");
8
10
  };
9
- }, []);
10
- const onMouseDown = () => {
11
- setEvent("start");
12
- };
13
- const onMouseUp = () => {
14
- setEvent("end");
15
- };
16
- const addListener = () => {
17
11
  document.addEventListener("pointerdown", onMouseDown);
18
12
  document.addEventListener("pointerup", onMouseUp);
19
- };
20
- const removeListener = () => {
21
- document.removeEventListener("pointerdown", onMouseDown);
22
- document.removeEventListener("pointerup", onMouseUp);
23
- };
13
+ return () => {
14
+ document.removeEventListener("pointerdown", onMouseDown);
15
+ document.removeEventListener("pointerup", onMouseUp);
16
+ };
17
+ }, []);
24
18
  return [event];
25
19
  };
26
20
  export default useDrag;
@@ -3,22 +3,18 @@ function useEditorScroll(editorWrapper = {
3
3
  current: null
4
4
  }, callback) {
5
5
  useEffect(() => {
6
+ if (!editorWrapper?.current) return;
6
7
  const handleScroll = () => {
7
- if (editorWrapper.current) {
8
- callback("scroll");
9
- }
8
+ console.log("Editor debug useEditorScroll ====>", editorWrapper, callback);
9
+ callback("scroll");
10
10
  };
11
11
  const currentEditorWrapper = editorWrapper.current;
12
- if (currentEditorWrapper) {
13
- currentEditorWrapper.addEventListener("scroll", handleScroll);
14
- }
12
+ currentEditorWrapper.addEventListener("scroll", handleScroll);
15
13
 
16
14
  // Cleanup the event listener on component unmount
17
15
  return () => {
18
- if (currentEditorWrapper) {
19
- currentEditorWrapper.removeEventListener("scroll", handleScroll);
20
- }
16
+ currentEditorWrapper.removeEventListener("scroll", handleScroll);
21
17
  };
22
- }, [editorWrapper.current, callback]);
18
+ }, [editorWrapper, callback]);
23
19
  }
24
20
  export default useEditorScroll;
@@ -1,4 +1,4 @@
1
- import { useEffect, useState, createContext, useContext, useMemo } from "react";
1
+ import { useEffect, useState, createContext, useContext, useMemo, useCallback } from "react";
2
2
  import { getSelectedText } from "../utils/helper";
3
3
  import { debounce } from "../helper";
4
4
  import { defaultFontFamilies } from "../common/FontLoader/FontList";
@@ -115,13 +115,7 @@ const useMouseMove = dragging => {
115
115
  const [event, setEvent] = useState({
116
116
  target: null
117
117
  });
118
- useEffect(() => {
119
- addListener();
120
- return () => {
121
- removeListener();
122
- };
123
- }, []);
124
- const onMouseMove = e => {
118
+ const onMouseMove = useCallback(debounce(e => {
125
119
  if (!dragging?.id) {
126
120
  const dpath = e?.target?.closest(".dpath");
127
121
  if (dpath) {
@@ -130,14 +124,14 @@ const useMouseMove = dragging => {
130
124
  });
131
125
  }
132
126
  }
133
- };
134
- const debounceMouseMove = debounce(onMouseMove, 100);
135
- const addListener = () => {
136
- document.addEventListener("mousemove", debounceMouseMove);
137
- };
138
- const removeListener = () => {
139
- document.removeEventListener("mousemove", debounceMouseMove);
140
- };
127
+ }, 100), [dragging]);
128
+ useEffect(() => {
129
+ document.addEventListener("mousemove", onMouseMove);
130
+ return () => {
131
+ document.removeEventListener("mousemove", onMouseMove);
132
+ onMouseMove.cancel(); // Cancel any pending debounced calls
133
+ };
134
+ }, [onMouseMove]);
141
135
  return [event];
142
136
  };
143
137
  export default useMouseMove;
@@ -184,7 +184,7 @@ export const TableProvider = ({
184
184
  window.removeEventListener("copy", handleCopy);
185
185
  window.removeEventListener("cut", handleCut);
186
186
  };
187
- }, [tableSelection, editor, tableSelection]);
187
+ }, [tableSelection, editor]);
188
188
 
189
189
  // useEffect(() => {
190
190
  // selectFirstCell(tablePath, editor, updateTableSelection);
@@ -149,6 +149,7 @@ const getFocusedNode = (editor, nodeType = "") => {
149
149
  console.log(err);
150
150
  }
151
151
  };
152
+ const voidTypes = ["image", "page-settings"];
152
153
  const withHtml = editor => {
153
154
  const {
154
155
  insertData,
@@ -159,7 +160,7 @@ const withHtml = editor => {
159
160
  return element.type === "link" ? true : isInline(element);
160
161
  };
161
162
  editor.isVoid = element => {
162
- return element.type === "image" ? true : isVoid(element);
163
+ return voidTypes.includes(element.type) ? true : isVoid(element);
163
164
  };
164
165
  editor.insertData = data => {
165
166
  const slateHTML = data?.getData("application/x-slate-fragment");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "9.1.9",
3
+ "version": "9.2.1",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"
@@ -61,7 +61,7 @@
61
61
  "scripts": {
62
62
  "prepare": "husky install .husky",
63
63
  "analyze": "source-map-explorer build/static/js/*.js",
64
- "lint": "./node_modules/.bin/eslint --ignore-path .gitignore .",
64
+ "lint": "./node_modules/. bin/eslint --ignore-path .gitignore .",
65
65
  "start": "craco start",
66
66
  "build": "NODE_OPTIONS='--max_old_space_size=4096' craco build",
67
67
  "test": "craco test --passWithNoTests",