@flozy/editor 5.2.7 → 5.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,7 +72,7 @@ const Leaf = ({
72
72
  children: children
73
73
  });
74
74
  };
75
- const updateTopBanner = (content, setTopBanner) => {
75
+ const updateTopBanner = (content = [], setTopBanner) => {
76
76
  setTopBanner(() => {
77
77
  const firstNode = content[0];
78
78
  return firstNode?.type === "topbanner" ? firstNode : null;
@@ -1,5 +1,6 @@
1
1
  import { Transforms, Node, Path } from "slate";
2
2
  import { ReactEditor } from "slate-react";
3
+ import { handleNegativeInteger } from "../../../utils/helper";
3
4
  export const ROW_HEIGHT = 50;
4
5
  const MARGIN_OF = {
5
6
  xs: 160,
@@ -75,7 +76,7 @@ const reRenderChildNodes = (editor, path) => {
75
76
  console.log(err);
76
77
  }
77
78
  };
78
- function isContainerElement(editor, moveTopath, props) {
79
+ function isContainerElement(editor, moveTopath, props, appenBp) {
79
80
  try {
80
81
  const {
81
82
  path,
@@ -91,6 +92,7 @@ function isContainerElement(editor, moveTopath, props) {
91
92
  parentNode = Node.get(editor, Path.parent(dragItemPath));
92
93
  }
93
94
  const moveToNode = Node.get(editor, moveTopath);
95
+ const leftOfMoveToNode = moveToNode[`left${appenBp}`];
94
96
  if (moveToNode.type === "freegridBox") {
95
97
  if (parentNode.type === "freegridBox") {
96
98
  // same box
@@ -98,10 +100,10 @@ function isContainerElement(editor, moveTopath, props) {
98
100
  return props.calX;
99
101
  } else {
100
102
  // for different box
101
- return parseInt(props.x - window.innerWidth / 2 + MARGIN_OF[props.breakpoint] - props.diffX - moveToNode.left);
103
+ return parseInt(props.x - window.innerWidth / 2 + MARGIN_OF[props.breakpoint] - props.diffX - leftOfMoveToNode);
102
104
  }
103
105
  } else {
104
- return props.calX - moveToNode?.left;
106
+ return props.calX - leftOfMoveToNode;
105
107
  }
106
108
  } else if (moveToNode.type === "freegrid") {
107
109
  if (parentNode.type === "freegridBox") {
@@ -133,14 +135,16 @@ export function onDropItem(props, parentClass) {
133
135
  const from = parentPath.split("|").map(m => parseInt(m));
134
136
  let newPath = [];
135
137
  newPath = moveTo;
136
- const cCalx = isContainerElement(editor, moveTo, props);
138
+ const appenBp = breakpoint === "lg" ? "" : `_${breakpoint}`;
139
+ const cCalx = handleNegativeInteger(isContainerElement(editor, moveTo, props, appenBp));
140
+
137
141
  // const posX = parseInt(
138
142
  // cx - window.innerWidth / 2 + MARGIN_OF[breakpoint] - diffX
139
143
  // );
140
144
  const toSectionNode = Node.get(editor, newPath);
141
145
  const addToSectionDOM = ReactEditor.toDOMNode(editor, toSectionNode);
142
146
  const rect = addToSectionDOM.getBoundingClientRect();
143
- const y = endPosition.y - startPosition.diffY - rect.top;
147
+ const y = handleNegativeInteger(endPosition.y - startPosition.diffY - rect.top);
144
148
 
145
149
  // Calculate grid position
146
150
  const row = Math.floor(y / ROW_HEIGHT) + 1;
@@ -150,7 +154,6 @@ export function onDropItem(props, parentClass) {
150
154
 
151
155
  // Update grid area
152
156
  const gridArea = `${row} / 1 / ${row + 1} / 2`;
153
- const appenBp = breakpoint === "lg" ? "" : `_${breakpoint}`;
154
157
  Transforms.setNodes(editor, {
155
158
  [`gridArea${appenBp}`]: gridArea,
156
159
  [`left${appenBp}`]: cCalx,
@@ -683,4 +683,7 @@ export function getInitialValue(value = [], readOnly) {
683
683
  }
684
684
  export function getSelectedCls(defaultCls = "", selected, selectedClsName = "selected") {
685
685
  return `${defaultCls} ${selected ? selectedClsName : ""}`;
686
+ }
687
+ export function handleNegativeInteger(val) {
688
+ return val < 0 ? 0 : val;
686
689
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "5.2.7",
3
+ "version": "5.2.8",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"