@flozy/editor 5.9.1 → 5.9.2

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.
@@ -54,13 +54,14 @@ const Item = /*#__PURE__*/forwardRef(({
54
54
  });
55
55
  });
56
56
  Item.displayName = "Item";
57
- const Element = props => {
57
+ const Element = /*#__PURE__*/React.memo(props => {
58
58
  return /*#__PURE__*/_jsx(Section, {
59
59
  ...props,
60
60
  children: getBlock(props)
61
61
  });
62
- };
63
- const Leaf = ({
62
+ });
63
+ Element.displayName = "Element";
64
+ const Leaf = /*#__PURE__*/React.memo(({
64
65
  attributes,
65
66
  children,
66
67
  leaf
@@ -71,12 +72,13 @@ const Leaf = ({
71
72
  ...attributes,
72
73
  children: children
73
74
  });
74
- };
75
+ });
76
+ Leaf.displayName = "Leaf";
75
77
  const updateTopBanner = (content = [], setTopBanner) => {
76
- setTopBanner(() => {
77
- const firstNode = content ? content[0] : {};
78
- return firstNode?.type === "topbanner" ? firstNode : null;
79
- });
78
+ // setTopBanner(() => {
79
+ // const firstNode = content ? content[0] : {};
80
+ // return firstNode?.type === "topbanner" ? firstNode : null;
81
+ // });
80
82
  };
81
83
  const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
82
84
  const {
@@ -311,7 +313,7 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
311
313
  updateTopBanner(newValue, setTopBanner);
312
314
  debounced(newValue);
313
315
  if (!isInteracted) {
314
- setIsInteracted(true);
316
+ // setIsInteracted(true);
315
317
  }
316
318
  }
317
319
  };
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { useSlateStatic, useSelected, ReactEditor } from "slate-react";
3
3
  import { Box } from "@mui/material";
4
- import { getPageSettings } from "../../utils/pageSettings";
4
+ // import { getPageSettings } from "../../utils/pageSettings";
5
5
  import { isTextSelected } from "../../utils/helper";
6
6
  import { useEditorContext } from "../../hooks/useMouseMove";
7
7
  import SimpleTextStyle from "./style";
@@ -11,7 +11,6 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { createElement as _createElement } from "react";
12
12
  const SimpleText = props => {
13
13
  const {
14
- theme,
15
14
  openAI
16
15
  } = useEditorContext() || {};
17
16
  const editor = useSlateStatic();
@@ -27,14 +26,10 @@ const SimpleText = props => {
27
26
  readOnly,
28
27
  editorPlaceholder
29
28
  } = customProps;
30
- const {
31
- element: pageSt
32
- } = getPageSettings(editor) || {};
33
- const {
34
- pageColor
35
- } = pageSt?.pageProps || {};
29
+ // const { element: pageSt } = getPageSettings(editor) || {};
30
+ // const { pageColor } = pageSt?.pageProps || {};
36
31
  const classes = SimpleTextStyle({
37
- pageColor: pageColor || theme?.palette?.editor?.background || "#FFFFFF"
32
+ pageColor: "#FFFFFF"
38
33
  });
39
34
  const selected = useSelected();
40
35
  const path = ReactEditor.findPath(editor, element);
@@ -52,14 +47,14 @@ const SimpleText = props => {
52
47
  contentEditable: false,
53
48
  className: "placeholder-simple-text",
54
49
  children: isEmptyEditor ? editorPlaceholder || "Write Something..." : showPlaceHolder ? opacity && selected ? /*#__PURE__*/_jsxs(_Fragment, {
55
- children: ["Type ", /*#__PURE__*/_jsx("span", {
50
+ children: ["Type", " ", /*#__PURE__*/_jsx("span", {
56
51
  style: {
57
- backgroundColor: '#F2F6FA',
52
+ backgroundColor: "#F2F6FA",
58
53
  padding: "0px 2px",
59
54
  borderRadius: "2px"
60
55
  },
61
56
  children: "/"
62
- }), " to browse elements"]
57
+ }), " ", "to browse elements"]
63
58
  }) : "" : ""
64
59
  }));
65
60
  };
@@ -1,5 +1,5 @@
1
- import React, { useCallback, useEffect, useState } from "react";
2
- import { Popper, Fade, Paper, ClickAwayListener } from "@mui/material";
1
+ import React, { useEffect, useState } from "react";
2
+ import { Popper, Paper, ClickAwayListener } from "@mui/material";
3
3
  import { Editor, Range, Transforms } from "slate";
4
4
  import { ReactEditor, useSlate } from "slate-react";
5
5
  import useDrag from "../../hooks/useDrag";
@@ -20,7 +20,8 @@ const PopupTool = props => {
20
20
  const classes = usePopupStyles(theme);
21
21
  const {
22
22
  setPopupType,
23
- openAI
23
+ openAI,
24
+ selectedElement
24
25
  } = useEditorContext();
25
26
  const [anchorEl, setAnchorEl] = useState(null);
26
27
  const [open, setOpen] = useState(false);
@@ -31,13 +32,10 @@ const PopupTool = props => {
31
32
  const [event] = useDrag(anchorEl);
32
33
  const id = open ? "popup-edit-tool" : "";
33
34
  const [size] = useWindowResize();
34
- const {
35
- selectedElement
36
- } = useEditorContext();
37
- const updateAnchorEl = useCallback(() => {
35
+ const updateAnchorEl = isScroll => {
38
36
  try {
39
37
  const isHavingSelection = selection && !Range.isCollapsed(selection);
40
- if (isHavingSelection) {
38
+ if (isHavingSelection && event === "end") {
41
39
  const domRange = ReactEditor.toDOMRange(editor, editor.selection);
42
40
  const editorContainer = document.querySelector("#slate-wrapper-scroll-container")?.getBoundingClientRect();
43
41
  const rect = domRange.getBoundingClientRect();
@@ -46,16 +44,21 @@ const PopupTool = props => {
46
44
  rect.y = -500; // hide the popper
47
45
  }
48
46
 
49
- setAnchorEl({
50
- clientWidth: rect.width,
51
- clientHeight: rect.height,
52
- getBoundingClientRect: () => rect
53
- });
47
+ // Create a dummy anchor element to match Popper's requirements
48
+ const anchor = document.createElement("div");
49
+ anchor.style.position = "absolute";
50
+ anchor.style.top = `${rect.top + window.scrollY}px`;
51
+ anchor.style.left = `${rect.left + window.scrollX}px`;
52
+ document.body.appendChild(anchor);
53
+ if (!anchorEl || isScroll === "scroll") {
54
+ setAnchorEl(anchor);
55
+ setOpen(true);
56
+ }
54
57
  }
55
58
  } catch (err) {
56
59
  console.log(err);
57
60
  }
58
- }, [selection]);
61
+ };
59
62
  useEditorScroll(editorWrapper, updateAnchorEl);
60
63
  useEffect(() => {
61
64
  const userStoppedSelection = size?.device === "xs" ? true : event === "end"; // for mobile, when user starts the selection, we are gonna show the popup tool
@@ -79,17 +82,12 @@ const PopupTool = props => {
79
82
  }
80
83
  }, [event, anchorEl]);
81
84
  useEffect(() => {
82
- if (!selection || Range.isCollapsed(selection) || Editor.string(editor, selection) === "") {
85
+ if (!selection || Range.isCollapsed(selection) || Editor.string(editor, selection) === "" || selectedElement?.enable === 1) {
83
86
  setAnchorEl(null);
84
87
  } else {
85
88
  updateAnchorEl();
86
89
  }
87
- }, [selection]);
88
- useEffect(() => {
89
- if (selectedElement?.enable === 1) {
90
- setAnchorEl(null);
91
- }
92
- }, [selection, selectedElement?.path, selectedElement?.enable]);
90
+ }, [selection, event, selectedElement?.enable]);
93
91
  const handleClose = () => {
94
92
  // setAnchorEl(null);
95
93
  setOpen(false);
@@ -115,24 +113,18 @@ const PopupTool = props => {
115
113
  id: id,
116
114
  open: open,
117
115
  anchorEl: anchorEl,
118
- transition: true,
119
116
  sx: classes.popupWrapper,
120
117
  placement: "top-start",
121
- children: ({
122
- TransitionProps
123
- }) => /*#__PURE__*/_jsx(Fade, {
124
- ...TransitionProps,
125
- children: /*#__PURE__*/_jsx(Paper, {
126
- style: {
127
- borderRadius: "6px",
128
- border: "1px solid #8360FD"
129
- },
130
- children: /*#__PURE__*/_jsx(MiniTextFormat, {
131
- editor: editor,
132
- classes: classes,
133
- closeMainPopup: handleClose,
134
- customProps: customProps
135
- })
118
+ children: /*#__PURE__*/_jsx(Paper, {
119
+ style: {
120
+ borderRadius: "6px",
121
+ border: "1px solid #8360FD"
122
+ },
123
+ children: /*#__PURE__*/_jsx(MiniTextFormat, {
124
+ editor: editor,
125
+ classes: classes,
126
+ closeMainPopup: handleClose,
127
+ customProps: customProps
136
128
  })
137
129
  })
138
130
  })
@@ -1,7 +1,9 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useState } from "react";
2
2
  import WebFont from "webfontloader";
3
+ import { Backdrop, CircularProgress } from "@mui/material";
3
4
  import { useEditorContext } from "../../hooks/useMouseMove";
4
5
  import { defaultFonts, googleFontList, otherFonts } from "./FontList";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
5
7
  const FontLoader = props => {
6
8
  const {
7
9
  otherProps,
@@ -10,12 +12,14 @@ const FontLoader = props => {
10
12
  const {
11
13
  setFontFamilies
12
14
  } = useEditorContext();
15
+ const [loader, setLoader] = useState(true);
13
16
  const loadFontsInBatches = (families, batchSize = 5, maxRetries = 3) => {
14
17
  let currentIndex = 0;
15
18
  let retryCount = 0;
16
19
  function loadNextBatch() {
17
20
  if (currentIndex >= families?.length) {
18
21
  // console.log("All fonts have been loaded");
22
+ setLoader(false);
19
23
  return;
20
24
  }
21
25
  const batch = families?.slice(currentIndex, currentIndex + batchSize);
@@ -93,6 +97,15 @@ const FontLoader = props => {
93
97
  loadFontsInBatches(families);
94
98
  }
95
99
  }, []);
96
- return null;
100
+ return /*#__PURE__*/_jsx(Backdrop, {
101
+ open: loader,
102
+ sx: {
103
+ color: "#fff",
104
+ zIndex: 9999 // Ensure it's above other UI elements
105
+ },
106
+ children: /*#__PURE__*/_jsx(CircularProgress, {
107
+ color: "inherit"
108
+ })
109
+ });
97
110
  };
98
111
  export default FontLoader;
@@ -2,18 +2,44 @@ import React, { useRef, useState } from "react";
2
2
  import { useTheme } from "@mui/material";
3
3
  import { Transforms } from "slate";
4
4
  import { ReactEditor, useSlateStatic } from "slate-react";
5
- import { Box, IconButton, Popper, Tooltip } from "@mui/material";
5
+ import { Box, IconButton, Tooltip } from "@mui/material";
6
6
  import SectionPopup from "../../Elements/Grid/SectionPopup";
7
7
  import { getBreakPointsValue, getTRBLBreakPoints, groupByBreakpoint } from "../../helper/theme";
8
- import DragHandle from "../DnD/DragHandleButton";
9
- import { useEditorSelection } from "../../hooks/useMouseMove";
8
+ // import DragHandle from "../DnD/DragHandleButton";
9
+ // import { useEditorSelection } from "../../hooks/useMouseMove";
10
10
  import SectionStyle from "./styles";
11
11
  import useWindowResize from "../../hooks/useWindowResize";
12
12
  import { SectionSettingIcon } from "../iconListV2";
13
+
14
+ // const list_types = ["orderedList", "unorderedList"];
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
14
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
- import { Fragment as _Fragment } from "react/jsx-runtime";
16
- const list_types = ["orderedList", "unorderedList"];
17
+ const Toolbar = ({
18
+ readOnly,
19
+ showTool,
20
+ onSettings,
21
+ isSectionFullWidth
22
+ }) => {
23
+ return !readOnly && !showTool ? /*#__PURE__*/_jsx(Box, {
24
+ component: "div",
25
+ className: `element-toolbar no-border-button hr section-tw sectionIcon`,
26
+ contentEditable: false,
27
+ sx: {
28
+ left: isSectionFullWidth ? "0px" : "-28px",
29
+ top: isSectionFullWidth ? "-28px" : "1px",
30
+ "&:hover": {
31
+ backgroundColor: "rgba(0,0,0,0.5)"
32
+ }
33
+ },
34
+ children: /*#__PURE__*/_jsx(Tooltip, {
35
+ title: "Section Settings",
36
+ children: /*#__PURE__*/_jsx(IconButton, {
37
+ onClick: onSettings,
38
+ children: /*#__PURE__*/_jsx(SectionSettingIcon, {})
39
+ })
40
+ })
41
+ }) : null;
42
+ };
17
43
  const Section = props => {
18
44
  const themeReact = useTheme();
19
45
  const theme = props?.theme;
@@ -27,7 +53,8 @@ const Section = props => {
27
53
  readOnly
28
54
  } = customProps;
29
55
  const editor = useSlateStatic();
30
- const [showTool] = useEditorSelection(editor);
56
+ // const [isHovering, setIsHovering] = useState(false);
57
+ const [size] = useWindowResize();
31
58
  const [openSetttings, setOpenSettings] = useState(false);
32
59
  const {
33
60
  sectionBgColor,
@@ -44,67 +71,11 @@ const Section = props => {
44
71
  } = sectionAlignment || {};
45
72
  const path = ReactEditor.findPath(editor, element);
46
73
  const anchorEl = useRef(null);
47
- const popperEl = useRef(null);
48
- const [size] = useWindowResize();
74
+ // const popperEl = useRef(null);
75
+ // const [showTool] = useEditorSelection(editor);
49
76
  const isSectionFullWidth = sectionGridSize && sectionGridSize[size?.device] >= 12;
50
- const [isHovering, setIsHovering] = useState(false);
51
- const onMouseEnter = () => {
52
- setIsHovering(true);
53
- };
54
- const onMouseLeave = () => {
55
- setIsHovering(false);
56
- };
57
- const onSettings = () => {
58
- setOpenSettings(true);
59
- };
60
- const Toolbar = ({
61
- fromPopper
62
- }) => {
63
- return !readOnly && !showTool ? /*#__PURE__*/_jsx(Box, {
64
- component: "div",
65
- className: `element-toolbar no-border-button hr section-tw sectionIcon`,
66
- contentEditable: false,
67
- style: fromPopper ? {
68
- position: "unset",
69
- marginLeft: "28px",
70
- paddingTop: "4px",
71
- marginRight: "10px",
72
- height: "100%"
73
- } : {
74
- left: "-28px",
75
- top: "1px"
76
- },
77
- children: /*#__PURE__*/_jsx(Tooltip, {
78
- title: "Section Settings",
79
- children: /*#__PURE__*/_jsx(IconButton, {
80
- onClick: onSettings,
81
- children: /*#__PURE__*/_jsx(SectionSettingIcon, {})
82
- })
83
- })
84
- }) : null;
85
- };
86
- const onSave = data => {
87
- const updateData = {
88
- ...data
89
- };
90
- delete updateData.children;
91
- Transforms.setNodes(editor, {
92
- ...updateData
93
- }, {
94
- at: path
95
- });
96
- onClose();
97
- };
98
- const onClose = () => {
99
- setOpenSettings(false);
100
- };
101
- const onDelete = () => {
102
- Transforms.removeNodes(editor, {
103
- at: path
104
- });
105
- };
106
- const isFreeGrid = element?.children?.find(f => f.type === "freegrid");
107
- const needHover = element?.children?.find(f => f.type === "grid" && !list_types.includes(element.type)) ? "" : "";
77
+ const isFreeGrid = element?.children[0]?.type === "freegrid";
78
+ const needHover = false;
108
79
  let tempProps = {};
109
80
  if (element?.type === "temp") {
110
81
  tempProps = {
@@ -128,6 +99,38 @@ const Section = props => {
128
99
  ...getBreakPointsValue(sectionGridSize || 8, null, "overrideGridSize", true)
129
100
  }
130
101
  }, themeReact);
102
+
103
+ // const onMouseEnter = () => {
104
+ // setIsHovering(true);
105
+ // };
106
+
107
+ // const onMouseLeave = () => {
108
+ // setIsHovering(false);
109
+ // };
110
+
111
+ const onSettings = () => {
112
+ setOpenSettings(true);
113
+ };
114
+ const onSave = data => {
115
+ const updateData = {
116
+ ...data
117
+ };
118
+ delete updateData.children;
119
+ Transforms.setNodes(editor, {
120
+ ...updateData
121
+ }, {
122
+ at: path
123
+ });
124
+ onClose();
125
+ };
126
+ const onClose = () => {
127
+ setOpenSettings(false);
128
+ };
129
+ const onDelete = () => {
130
+ Transforms.removeNodes(editor, {
131
+ at: path
132
+ });
133
+ };
131
134
  return path.length === 1 && !isFreeGrid ? /*#__PURE__*/_jsxs(Box, {
132
135
  component: "div",
133
136
  className: `ed-section-wrapper ${readOnly ? "" : "hselect"} ${needHover} is-${element?.type}`,
@@ -142,9 +145,10 @@ const Section = props => {
142
145
  flexDirection: flexDirection || "column",
143
146
  alignItems: horizantal,
144
147
  justifyContent: vertical
145
- },
146
- onMouseEnter: onMouseEnter,
147
- onMouseLeave: onMouseLeave,
148
+ }
149
+ // onMouseEnter={onMouseEnter}
150
+ // onMouseLeave={onMouseLeave}
151
+ ,
148
152
  children: [/*#__PURE__*/_jsxs(Box, {
149
153
  className: "ed-section-inner",
150
154
  sx: {
@@ -152,34 +156,11 @@ const Section = props => {
152
156
  ...edInnerSp
153
157
  },
154
158
  ref: anchorEl,
155
- children: [isHovering && isSectionFullWidth ? /*#__PURE__*/_jsx(Popper, {
156
- open: isHovering && isSectionFullWidth,
157
- anchorEl: anchorEl?.current,
158
- placement: "top-start",
159
- sx: {
160
- zIndex: 9999
161
- },
162
- disablePortal: true,
163
- ref: popperEl,
164
- className: "sectionPopper",
165
- children: /*#__PURE__*/_jsxs(Box, {
166
- sx: {
167
- bgcolor: "background.paper",
168
- height: "30px",
169
- position: "relative",
170
- background: theme?.palette?.type === 'dark' ? theme?.palette?.editor?.miniToolBarBackground : '#F6F6F6'
171
- },
172
- children: [!readOnly && !showTool ? /*#__PURE__*/_jsx(DragHandle, {
173
- ...props,
174
- fromPopper: true
175
- }) : null, /*#__PURE__*/_jsx(Toolbar, {
176
- fromPopper: true
177
- })]
178
- })
179
- }) : /*#__PURE__*/_jsxs(_Fragment, {
180
- children: [!readOnly && !showTool ? /*#__PURE__*/_jsx(DragHandle, {
181
- ...props
182
- }) : null, /*#__PURE__*/_jsx(Toolbar, {})]
159
+ children: [/*#__PURE__*/_jsx(Toolbar, {
160
+ isSectionFullWidth: isSectionFullWidth,
161
+ readOnly: readOnly,
162
+ showTool: false,
163
+ onSettings: onSettings
183
164
  }), children]
184
165
  }), openSetttings ? /*#__PURE__*/_jsx(SectionPopup, {
185
166
  element: {
@@ -5,7 +5,7 @@ function useEditorScroll(editorWrapper = {
5
5
  useEffect(() => {
6
6
  const handleScroll = () => {
7
7
  if (editorWrapper.current) {
8
- callback();
8
+ callback("scroll");
9
9
  }
10
10
  };
11
11
  const currentEditorWrapper = editorWrapper.current;
@@ -614,6 +614,11 @@ export const getBlock = props => {
614
614
  children: children
615
615
  });
616
616
  default:
617
+ // return (
618
+ // <span {...attributes} {...element.attr}>
619
+ // {children}
620
+ // </span>
621
+ // );
617
622
  return /*#__PURE__*/_jsx(SimpleText, {
618
623
  ...props,
619
624
  isEmpty: isEmpty
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "5.9.1",
3
+ "version": "5.9.2",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"
@@ -69,7 +69,7 @@
69
69
  "storybook": "storybook dev -p 6006",
70
70
  "build-storybook": "NODE_OPTIONS='--max_old_space_size=4096' storybook build",
71
71
  "publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
72
- "publish:local": "rm -rf /Users/agmac30/Documents/CODE_BASE/flozy/client/node_modules/@flozy/editor/dist && babel src/components -d /Users/agmac30/Documents/CODE_BASE/flozy/client/node_modules/@flozy/editor/dist --copy-files"
72
+ "publish:local": "rm -rf /Users/agmac03/flozy/client/node_modules/@flozy/editor/dist && babel src/components -d /Users/agmac03/flozy/client/node_modules/@flozy/editor/dist --copy-files"
73
73
  },
74
74
  "eslintConfig": {
75
75
  "extends": [