@flozy/editor 9.8.9 → 9.9.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.
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, useState } from "react";
1
+ import React, { createContext, useContext, useEffect, useRef, useState } from "react";
2
2
  import { Path, Transforms, Node } from "slate";
3
3
  import { ReactEditor, useSlateStatic } from "slate-react";
4
4
  import { Box, useTheme } from "@mui/material";
@@ -27,6 +27,12 @@ const MAX_DEVICE_WIDTH = {
27
27
  lg: 980,
28
28
  xs: 320
29
29
  };
30
+
31
+ // Create a Context
32
+ export const FreeGridContext = /*#__PURE__*/createContext(null);
33
+ export const useFreeGrid = () => {
34
+ return useContext(FreeGridContext);
35
+ };
30
36
  const FreeGrid = props => {
31
37
  const theme = useTheme();
32
38
  const breakpoint = useBreakpoints(theme);
@@ -68,6 +74,7 @@ const FreeGrid = props => {
68
74
  const [autoAlign, setAutoAlign] = useState(false);
69
75
  const count = useRef(2);
70
76
  const childrenCountRef = useRef(element?.children?.length);
77
+ const [isInteracting, setIsInteracting] = useState(false);
71
78
  const onChange = data => {
72
79
  const append = breakpoint === "lg" ? "" : `_${breakpoint}`;
73
80
  const updateData = {
@@ -466,127 +473,134 @@ const FreeGrid = props => {
466
473
  // return eleId;
467
474
  // }, [autoAlign, updated_at, breakpoint, path]);
468
475
 
469
- return /*#__PURE__*/_jsx(RnD, {
470
- id: `freegrid_container_${path.join("|")}_${updated_at}_${breakpoint}`,
471
- className: `
476
+ return /*#__PURE__*/_jsx(FreeGridContext.Provider, {
477
+ value: {
478
+ isInteracting,
479
+ setIsInteracting
480
+ },
481
+ children: /*#__PURE__*/_jsx(RnD, {
482
+ id: `freegrid_container_${path.join("|")}_${updated_at}_${breakpoint}`,
483
+ className: `
472
484
  freegrid-section breakpoint-${breakpoint}
473
485
  freegrid-section_${path.join("_")}
474
486
  `,
475
- editor: editor,
476
- path: path,
477
- disableDragging: true,
478
- style: {
479
- position: "relative",
480
- "--height": `${height}px`
481
- },
482
- dataSets: {
483
- "data-height-xs": height_xs
484
- },
485
- defaultStyle: {
486
- width: "100%",
487
- height: height ? `${height}px` : "auto"
488
- },
489
- enableResizing: {
490
- bottom: true,
491
- top: false,
492
- left: false,
493
- right: false,
494
- topLeft: false,
495
- topRight: false,
496
- bottomLeft: false,
497
- bottomRight: false
498
- },
499
- actions: sectionTypeOptions,
500
- type: "parent",
501
- optionsProps: {
502
- placement: "right",
503
- sx: {
504
- ...classes.sectionPopper,
505
- ...(customSX?.sectionPopper || {})
506
- }
507
- },
508
- settingsProps: {
509
- settings: "freeGrid",
510
- customProps
511
- },
512
- onChange: onChange,
513
- handleActionClick: handleActionClick,
514
- actionsMap: {
515
- addElement: {
516
- Component: AddElement,
517
- placement: "left",
518
- title: "Add Element",
519
- props: {
520
- handleClick: handleAddElementClick,
521
- hideTools: hideTools || [],
522
- translation: {
523
- translation
524
- },
525
- customProps: {
526
- customProps
527
- }
528
- }
487
+ editor: editor,
488
+ path: path,
489
+ disableDragging: true,
490
+ style: {
491
+ position: "relative",
492
+ "--height": `${height}px`
529
493
  },
530
- more: {
531
- Component: More,
532
- placement: "left",
533
- title: "More Options",
534
- props: {
535
- handleClick: handleMoreClick,
536
- translation: {
537
- translation
538
- },
539
- customProps: {
540
- customProps
541
- },
542
- breakpoint
543
- }
494
+ dataSets: {
495
+ "data-height-xs": height_xs
544
496
  },
545
- settings: {
546
- Component: SectionSettings,
547
- placement: "left",
548
- title: "Section Settings",
549
- props: {
550
- editor,
551
- path,
552
- classes,
553
- translation
497
+ defaultStyle: {
498
+ width: "100%",
499
+ height: height ? `${height}px` : "auto"
500
+ },
501
+ enableResizing: {
502
+ bottom: true,
503
+ top: false,
504
+ left: false,
505
+ right: false,
506
+ topLeft: false,
507
+ topRight: false,
508
+ bottomLeft: false,
509
+ bottomRight: false
510
+ },
511
+ actions: sectionTypeOptions,
512
+ type: "parent",
513
+ optionsProps: {
514
+ placement: "right",
515
+ sx: {
516
+ ...classes.sectionPopper,
517
+ ...(customSX?.sectionPopper || {})
554
518
  }
555
- }
556
- },
557
- readOnly: readOnly,
558
- updated_at: updated_at,
559
- breakpoint: breakpoint,
560
- handleContextMenuClick: handleContextMenuClick,
561
- translation: translation,
562
- customProps: customProps,
563
- sectionElement: element,
564
- autoAlign: autoAlign,
565
- setAutoAlign: setAutoAlign,
566
- children: /*#__PURE__*/_jsxs(Box, {
567
- ...attributes,
568
- id: sectionName,
569
- "data-event": "rnd-click",
570
- className: "freegrid-container freegrid-container-parent",
571
- sx: {
572
- ...classes.root,
573
- ...freegridSX,
574
- background: sectionBgColor || "rgba(255,255,255,1)",
575
- backgroundImage: sectionBackgroundImage ? `url('${sectionBackgroundImage}')` : "",
576
- backgroundSize: "cover"
577
519
  },
578
- "data-path": path.join("|"),
579
- "data-dragoverid": path.join("|"),
580
- "data-dragovertype": "parent",
581
- style: {
582
- "--cols": `100%`,
583
- "--rows": `repeat(${repeatTimes}, ${ROW_HEIGHT}px)`
520
+ settingsProps: {
521
+ settings: "freeGrid",
522
+ customProps
523
+ },
524
+ onChange: onChange,
525
+ handleActionClick: handleActionClick,
526
+ actionsMap: {
527
+ addElement: {
528
+ Component: AddElement,
529
+ placement: "left",
530
+ title: "Add Element",
531
+ props: {
532
+ handleClick: handleAddElementClick,
533
+ hideTools: hideTools || [],
534
+ translation: {
535
+ translation
536
+ },
537
+ customProps: {
538
+ customProps
539
+ }
540
+ }
541
+ },
542
+ more: {
543
+ Component: More,
544
+ placement: "left",
545
+ title: "More Options",
546
+ props: {
547
+ handleClick: handleMoreClick,
548
+ breakpoint,
549
+ translation: {
550
+ translation
551
+ },
552
+ customProps: {
553
+ customProps
554
+ }
555
+ }
556
+ },
557
+ settings: {
558
+ Component: SectionSettings,
559
+ placement: "left",
560
+ title: "Section Settings",
561
+ props: {
562
+ editor,
563
+ path,
564
+ classes,
565
+ customProps,
566
+ translation
567
+ }
568
+ }
584
569
  },
585
- children: [children, !readOnly ? /*#__PURE__*/_jsx("span", {
586
- placeholder: `${translation("Section")} (${sectionName || "Welcome"})`,
587
- className: "freegrid-section-infos",
588
- contentEditable: false
589
- }) : null]
570
+ readOnly: readOnly,
571
+ updated_at: updated_at,
572
+ breakpoint: breakpoint,
573
+ handleContextMenuClick: handleContextMenuClick,
574
+ sectionElement: element,
575
+ autoAlign: autoAlign,
576
+ setAutoAlign: setAutoAlign,
577
+ translation: translation,
578
+ customProps: customProps,
579
+ children: /*#__PURE__*/_jsxs(Box, {
580
+ ...attributes,
581
+ id: sectionName,
582
+ "data-event": "rnd-click",
583
+ className: "freegrid-container freegrid-container-parent",
584
+ sx: {
585
+ ...classes.root,
586
+ ...freegridSX,
587
+ background: sectionBgColor || "rgba(255,255,255,1)",
588
+ backgroundImage: sectionBackgroundImage ? `url('${sectionBackgroundImage}')` : "",
589
+ backgroundSize: "cover"
590
+ },
591
+ "data-path": path.join("|"),
592
+ "data-dragoverid": path.join("|"),
593
+ "data-dragovertype": "parent",
594
+ style: {
595
+ "--cols": `100%`,
596
+ "--rows": `repeat(${repeatTimes}, ${ROW_HEIGHT}px)`
597
+ },
598
+ children: [children, !readOnly ? /*#__PURE__*/_jsx("span", {
599
+ placeholder: `${translation("Section")} (${sectionName || "Welcome"})`,
600
+ className: "freegrid-section-infos",
601
+ contentEditable: false
602
+ }) : null]
603
+ })
590
604
  })
591
605
  });
592
606
  };
@@ -209,10 +209,10 @@ const FreeGridBox = props => {
209
209
  left: left || 0
210
210
  },
211
211
  type: "parent-container",
212
- customProps: customProps,
213
- translation: translation,
214
212
  breakpoint: breakpoint,
215
213
  isBoxHeader: isBoxHeader,
214
+ customProps: customProps,
215
+ translation: translation,
216
216
  children: /*#__PURE__*/_jsx(Box, {
217
217
  component: "div",
218
218
  ...attributes,
@@ -317,9 +317,9 @@ const FreeGridItem = props => {
317
317
  itemData: {
318
318
  left: left || 0
319
319
  },
320
+ breakpoint: breakpoint,
320
321
  customProps: customProps,
321
322
  translation: translation,
322
- breakpoint: breakpoint,
323
323
  children: /*#__PURE__*/_jsxs(Box, {
324
324
  component: "div",
325
325
  ...attributes,
@@ -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, getDevice } 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";
@@ -28,14 +28,11 @@ const SimpleText = props => {
28
28
  editorPlaceholder,
29
29
  translation
30
30
  } = customProps;
31
- const {
32
- activeBreakPoint
33
- } = useEditorContext();
34
31
  // const { element: pageSt } = getPageSettings(editor) || {};
35
32
  // const { pageColor } = pageSt?.pageProps || {};
36
- const isMobile = window.matchMedia("(max-width: 899px)")?.matches || false;
33
+ const breakpoint = getDevice(window.innerWidth);
37
34
  const lineH = element?.children[0]?.lineHeight;
38
- const lineHeight = getBreakpointLineSpacing(lineH, activeBreakPoint || (isMobile ? "xs" : "lg"));
35
+ const lineHeight = getBreakpointLineSpacing(lineH, breakpoint);
39
36
  const classes = SimpleTextStyle({
40
37
  pageColor: "#FFFFFF",
41
38
  lineHeight
@@ -18,6 +18,7 @@ import FontFamilyAutocomplete from "../FormatTools/FontFamilyAutocomplete";
18
18
  import { useEditorContext } from "../../hooks/useMouseMove";
19
19
  import LineSpacing from "../../common/StyleBuilder/fieldTypes/lineSpacing";
20
20
  import { getPageSettings } from "../../utils/pageSettings";
21
+ import { getDevice } from "../../helper/theme";
21
22
  import { jsx as _jsx } from "react/jsx-runtime";
22
23
  import { jsxs as _jsxs } from "react/jsx-runtime";
23
24
  const allTools = toolbarGroups.flat();
@@ -46,10 +47,7 @@ const TextFormat = props => {
46
47
  fontFamilies,
47
48
  theme: appTheme
48
49
  } = useEditorContext();
49
- const {
50
- activeBreakPoint
51
- } = useEditorContext();
52
- const breakpoint = activeBreakPoint === "" ? "lg" : activeBreakPoint;
50
+ const breakpoint = getDevice(window.innerWidth);
53
51
  const fontWeight = allTools.find(f => f.format === "fontWeight");
54
52
  const fontStyle = allTools.filter(f => f.type === "mark" && f.format !== "strikethrough" && f.format !== "superscript" && f.format !== "subscript");
55
53
  const fontAlign = allTools.filter(f => f.format?.indexOf("align") >= 0);
@@ -15,8 +15,7 @@ const SwitchViewport = props => {
15
15
  } = props;
16
16
  const classes = useSwitchViewport();
17
17
  const {
18
- setSelectedElement,
19
- setActiveBreakPoint
18
+ setSelectedElement
20
19
  } = useEditorContext();
21
20
  useEffect(() => {
22
21
  // to reset selection on viewport changes - FS-6589
@@ -32,7 +31,6 @@ const SwitchViewport = props => {
32
31
  children: /*#__PURE__*/_jsx(IconButton, {
33
32
  className: `${!breakpoint || breakpoint === "lg" ? "active" : ""}`,
34
33
  onClick: () => {
35
- setActiveBreakPoint("");
36
34
  onChange("");
37
35
  },
38
36
  children: /*#__PURE__*/_jsx(PersonalVideoIcon, {})
@@ -42,7 +40,6 @@ const SwitchViewport = props => {
42
40
  children: /*#__PURE__*/_jsx(IconButton, {
43
41
  className: `${breakpoint === "xs" ? "active" : ""}`,
44
42
  onClick: () => {
45
- setActiveBreakPoint("xs");
46
43
  onChange("xs");
47
44
  },
48
45
  children: /*#__PURE__*/_jsx(PhoneIphoneIcon, {})
@@ -24,6 +24,8 @@ import VirtualTextElement from "./VirtualElement/VirtualTextElement";
24
24
  import useAutoScroll from "../../hooks/useAutoScroll";
25
25
  import ForceAutoAlignment from "./VirtualElement/ForceAutoAlignment";
26
26
  import BoxHeaderAutoAlignment from "./VirtualElement/BoxHeaderAutoAlignment";
27
+ import { reRenderChildNodes } from "./Utils/gridDropItem";
28
+ import { useFreeGrid } from "../../Elements/FreeGrid/FreeGrid";
27
29
  import { jsx as _jsx } from "react/jsx-runtime";
28
30
  import { jsxs as _jsxs } from "react/jsx-runtime";
29
31
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -70,12 +72,12 @@ const RnD = props => {
70
72
  breakpoint = "",
71
73
  handleContextMenuClick = () => {},
72
74
  itemData = {},
73
- customProps,
74
75
  sectionElement,
75
76
  dataSets,
76
77
  autoAlign,
77
78
  setAutoAlign,
78
- isBoxHeader
79
+ isBoxHeader,
80
+ customProps
79
81
  } = props;
80
82
  const {
81
83
  isSelectedElement,
@@ -117,13 +119,17 @@ const RnD = props => {
117
119
  y: 0
118
120
  });
119
121
  const parentSectionPath = str_path?.split("|").slice(0, 2).join("_");
120
- const {
121
- translation
122
- } = customProps;
123
122
  const {
124
123
  startAutoScroll,
125
124
  stopAutoScroll
126
125
  } = useAutoScroll(10, "slate-wrapper-scroll-container");
126
+ const {
127
+ isInteracting,
128
+ setIsInteracting
129
+ } = useFreeGrid();
130
+ const {
131
+ translation
132
+ } = customProps;
127
133
  useEffect(() => {
128
134
  if (ITEM_TYPES.includes(type)) {
129
135
  if (enable === 1) {
@@ -298,7 +304,7 @@ const RnD = props => {
298
304
  const {
299
305
  updated_at
300
306
  } = updated_data || {};
301
- setSelectedElement({});
307
+ // setSelectedElement({});
302
308
  // to maitain absolute
303
309
  rndRef.current.posUpdated = false;
304
310
  // need to retain drag option if section changes
@@ -317,6 +323,7 @@ const RnD = props => {
317
323
  };
318
324
  const onDragStart = e => {
319
325
  e.preventDefault();
326
+ setIsInteracting(true);
320
327
  if (e?.target?.dataset?.path?.split(",").join("|") === sp) {
321
328
  const {
322
329
  left,
@@ -418,6 +425,7 @@ const RnD = props => {
418
425
  e.preventDefault();
419
426
  e.stopPropagation();
420
427
  stopAutoScroll();
428
+ setIsInteracting(false);
421
429
  if (dragging?.isDragging === 2 && dragging?.position?.strXY && dragging?.dragOver) {
422
430
  d.x = e.x;
423
431
  d.y = e.y;
@@ -460,6 +468,7 @@ const RnD = props => {
460
468
  };
461
469
  const onResizeStop = (e, direction, ref, d, position) => {
462
470
  e.preventDefault();
471
+ setIsInteracting(false);
463
472
  let updatedPosition = {};
464
473
  if (type !== "parent") {
465
474
  // update element position while resizing, (for free grid box and item)
@@ -485,17 +494,12 @@ const RnD = props => {
485
494
  ...updatedSize
486
495
  });
487
496
  handleResizeEvent("stop");
488
-
489
- // const parentPath = getParentSectionPath(
490
- // { ref },
491
- // ".freegrid-container-parent"
492
- // );
493
-
494
- // const formatParentPath = parentPath?.split("|")?.map((m) => parseInt(m));
495
-
496
- // reRenderChildNodes(editor, formatParentPath);
497
+ const parentPath = getParentSectionPath({
498
+ ref
499
+ }, ".freegrid-container-parent");
500
+ const formatParentPath = parentPath?.split("|")?.map(m => parseInt(m));
501
+ reRenderChildNodes(editor, formatParentPath);
497
502
  };
498
-
499
503
  const onCloseSettings = () => {
500
504
  setSelectedElement({
501
505
  ...selectedElementProps,
@@ -553,6 +557,7 @@ const RnD = props => {
553
557
  return {
554
558
  onResizeStart: e => {
555
559
  e.preventDefault();
560
+ setIsInteracting(true);
556
561
  },
557
562
  onDragStart: onDragStart,
558
563
  onDrag: onDrag,
@@ -626,7 +631,7 @@ const RnD = props => {
626
631
  "data-dragoverid": str_path,
627
632
  "data-dragovertype": type
628
633
  }) : null]
629
- }, eId), !active && rndRef?.current && open ? /*#__PURE__*/_jsx(ElementOptions, {
634
+ }, eId), !active && rndRef?.current && open && !isInteracting ? /*#__PURE__*/_jsx(ElementOptions, {
630
635
  id: `opt_ref_${str_path}`,
631
636
  open: open,
632
637
  anchorEl: rndRef?.current,
@@ -133,7 +133,7 @@ const useCommonStyle = theme => ({
133
133
  background: theme?.palette?.editor?.inputFieldBgColor,
134
134
  border: `1px solid ${theme?.palette?.editor?.inputFieldBorder}`,
135
135
  borderRadius: "10px",
136
- width: "46px !important",
136
+ width: "52px !important",
137
137
  marginLeft: "10px",
138
138
  height: "36px !important"
139
139
  },
@@ -39,7 +39,6 @@ export const EditorProvider = ({
39
39
  path: null
40
40
  });
41
41
  const [fontFamilies, setFontFamilies] = useState(defaultFontFamilies);
42
- const [activeBreakPoint, setActiveBreakPoint] = useState("");
43
42
  useEffect(() => {
44
43
  window.updateSelectedItem = d => {
45
44
  setSelectedElement(d);
@@ -105,10 +104,8 @@ export const EditorProvider = ({
105
104
  setFontFamilies,
106
105
  openTheme,
107
106
  setOpenTheme,
108
- activeBreakPoint,
109
- setActiveBreakPoint,
110
107
  triggerRender
111
- }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop, openTheme, activeBreakPoint]);
108
+ }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop, openTheme]);
112
109
  return /*#__PURE__*/_jsx(EditorContext.Provider, {
113
110
  value: otherValues,
114
111
  children: children
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "9.8.9",
3
+ "version": "9.9.1",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"