@flozy/editor 5.2.9 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -124,7 +124,9 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
124
124
  } = otherProps || {};
125
125
  const editor = useMemo(() => {
126
126
  if (collaborativeEditor) return collaborativeEditor;
127
- return withCommon(createEditor(), {
127
+ const editor = createEditor();
128
+ editor.needLayout = needLayout;
129
+ return withCommon(editor, {
128
130
  needLayout
129
131
  });
130
132
  }, [collaborativeEditor]);
@@ -510,7 +512,7 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
510
512
  children: [/*#__PURE__*/_jsx(DragAndDrop, {
511
513
  children: /*#__PURE__*/_jsxs(Overlay, {
512
514
  children: [/*#__PURE__*/_jsx(Box, {
513
- className: `pc-${editorClass || ""} ${hasTopBanner() ? "has-topbanner" : ""} ${!pageColor ? "no-color" : ""} scrollable-content scrollSmooth`,
515
+ className: `pc-${editorClass || ""} ${hasTopBanner() ? "has-topbanner" : ""} ${!pageColor ? "no-color" : ""} scrollable-content scrollSmooth ${readOnly ? "readOnlyContainer" : ""}`,
514
516
  sx: classes.slateWrapper,
515
517
  id: "slate-wrapper-scroll-container",
516
518
  ref: editorWrapper,
@@ -97,15 +97,15 @@ const DataView = props => {
97
97
  contentEditable: false,
98
98
  "data-title": title,
99
99
  children: /*#__PURE__*/_jsxs(DataViewProvider, {
100
- initialData: {
100
+ data: {
101
101
  properties,
102
102
  layouts,
103
- rows,
104
- users: users
103
+ rows
105
104
  },
106
105
  path: path,
107
106
  editor: editor,
108
107
  title: title,
108
+ users: users,
109
109
  children: [/*#__PURE__*/_jsx(FilterView, {
110
110
  classes: classes,
111
111
  onEnter: onEnter,
@@ -1,10 +1,12 @@
1
1
  import React, { useEffect, useRef, useState } from "react";
2
- import { Box, Checkbox, Popper } from "@mui/material";
2
+ import { Box, Checkbox, Popper, useTheme } from "@mui/material";
3
3
  import CheckBoxTwoToneIcon from "@mui/icons-material/CheckBoxTwoTone";
4
4
  import DataTypes from "./DataTypes";
5
+ import useColumnStyles from "./colStyles";
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  import { jsxs as _jsxs } from "react/jsx-runtime";
7
8
  const ColumnView = props => {
9
+ const theme = useTheme();
8
10
  const {
9
11
  needAnchor,
10
12
  rowIndex,
@@ -18,6 +20,7 @@ const ColumnView = props => {
18
20
  const anchorRef = useRef(null);
19
21
  const [anchorEl, setAnchorEl] = useState(null);
20
22
  const open = Boolean(anchorEl);
23
+ const classes = useColumnStyles(theme);
21
24
  useEffect(() => {
22
25
  if (anchorRef?.current) {
23
26
  setAnchorEl(anchorRef?.current);
@@ -42,14 +45,10 @@ const ColumnView = props => {
42
45
  label: property?.label,
43
46
  readOnly: readOnly
44
47
  }), needAnchor && !readOnly ? /*#__PURE__*/_jsx(Popper, {
45
- sx: {
46
- zIndex: 1000,
47
- marginTop: "20px !important"
48
- },
48
+ sx: classes.root,
49
49
  open: open,
50
50
  anchorEl: anchorEl,
51
51
  placement: "left",
52
- container: anchorRef?.current,
53
52
  className: `tv-tr-pop ${selected ? "active" : ""}`,
54
53
  disablePortal: true,
55
54
  children: /*#__PURE__*/_jsx(Checkbox, {
@@ -172,7 +172,7 @@ const useOptionsStyles = (theme, appTheme) => ({
172
172
  marginBottom: "8px"
173
173
  },
174
174
  [theme?.breakpoints?.between("xs", "md")]: {
175
- width: "calc(100% - 24px)"
175
+ width: "100%"
176
176
  }
177
177
  }
178
178
  });
@@ -2,7 +2,6 @@ import React from "react";
2
2
  import { Box } from "@mui/material";
3
3
  import { useDataView } from "../Providers/DataViewProvider";
4
4
  import ColumnView from "./ColumnView";
5
- // import Formula from "./Formula";
6
5
  import { jsx as _jsx } from "react/jsx-runtime";
7
6
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
7
  const RenderRow = props => {
@@ -0,0 +1,10 @@
1
+ const useColumnStyles = theme => ({
2
+ root: {
3
+ zIndex: 1000,
4
+ marginTop: "20px !important",
5
+ [theme?.breakpoints?.between("xs", "md")]: {
6
+ left: "-32px !important"
7
+ }
8
+ }
9
+ });
10
+ export default useColumnStyles;
@@ -1,5 +1,5 @@
1
1
  import React, { createContext, useContext, useEffect, useState } from "react";
2
- import { Transforms } from "slate";
2
+ import { Editor, Transforms, Node } from "slate";
3
3
  import { PROPERTY_DEFAULTS } from "../Layouts/Options/Constants";
4
4
  import multiSortRows from "../Utils/multiSortRows";
5
5
  import globalSearch from "../Utils/globalSearch";
@@ -29,10 +29,12 @@ export const DataViewProvider = ({
29
29
  ...props
30
30
  }) => {
31
31
  const {
32
- initialData,
32
+ data: initialData,
33
33
  path,
34
- editor
34
+ editor,
35
+ users: peoples
35
36
  } = props;
37
+ const dataViewNode = Node.get(editor, path);
36
38
  const [layouts, setLayouts] = useState(initialData?.layouts || []);
37
39
  const [seletectedLayout, setSelectedLayout] = useState({
38
40
  ...(layouts[0] || {})
@@ -44,15 +46,21 @@ export const DataViewProvider = ({
44
46
  const [rows, setRows] = useState(initialData?.rows || []);
45
47
  const [selectedRows, setSelectedRows] = useState([]);
46
48
  const [search, setSearch] = useState("");
47
- let {
48
- users
49
- } = initialData || {};
50
- users = users?.map(m => {
49
+ const users = peoples?.map(m => {
51
50
  return {
52
51
  value: m?.name
53
52
  };
54
53
  });
55
54
 
55
+ // for undo and redo
56
+ // minimal added for perforamnce issue avoid
57
+ useEffect(() => {
58
+ setRows(dataViewNode?.rows);
59
+ }, [dataViewNode?.rows?.length]);
60
+ useEffect(() => {
61
+ setProperties(dataViewNode?.properties);
62
+ }, [dataViewNode?.properties?.length]);
63
+
56
64
  // re-order when sort val changes
57
65
  useEffect(() => {
58
66
  if ((sort?.length > 0 || search) && rows?.length > 0) {
@@ -288,6 +288,11 @@ const editorStyles = ({
288
288
  "& ::selection": {
289
289
  color: "inherit",
290
290
  background: "#EAEBFE"
291
+ },
292
+ "&.readOnlyContainer": {
293
+ "& .max-content": {
294
+ paddingBottom: "0px !important"
295
+ }
291
296
  }
292
297
  },
293
298
  fullScreenWrapper: {
@@ -533,7 +533,7 @@ const RnD = props => {
533
533
  children: [/*#__PURE__*/_jsx("div", {
534
534
  id: `opt_ref_${str_path}`,
535
535
  style: {
536
- display: "block",
536
+ display: readOnly ? "none" : "block",
537
537
  position: "absolute",
538
538
  left: "-8px",
539
539
  top: "-30px",
@@ -2,7 +2,8 @@ import { Transforms, Editor, Element, Node, Path } from "slate";
2
2
  import deserialize from "../helper/deserialize";
3
3
  import { decodeAndParseBase64 } from "../utils/helper";
4
4
  const avoidDefaultInsert = ["table", "grid"];
5
- const LIST_TAGS = ["ol", "ul", "img", "table"];
5
+ const NON_TEXT_TAGS = ["ol", "ul", "img", "table", "video", "a", "button", "GOOGLE-SHEETS-HTML-ORIGIN"];
6
+ const ALLOWED_TEXT_NODES = ["paragraph", "title", "headingOne", "headingTwo", "headingThree"];
6
7
  const loopChildren = (children = [], defaultInsert) => {
7
8
  if (!children?.length) {
8
9
  return defaultInsert;
@@ -62,13 +63,18 @@ const insertAtNextNode = (editor, formattedFragment) => {
62
63
  console.log(err);
63
64
  }
64
65
  };
65
- const handleInsert = (editor, defaultInsert, fragment = []) => {
66
- if (getCurrentElementText(editor) && fragment.some(f => f.type === "table")) {
67
- insertAtNextNode(editor, fragment);
68
- } else {
69
- defaultInsert();
70
- }
71
- };
66
+
67
+ // const handleInsert = (editor, defaultInsert, fragment = []) => {
68
+ // if (
69
+ // getCurrentElementText(editor) &&
70
+ // fragment.some((f) => f.type === "table")
71
+ // ) {
72
+ // insertAtNextNode(editor, fragment);
73
+ // } else {
74
+ // defaultInsert();
75
+ // }
76
+ // };
77
+
72
78
  const getTableCellChild = (fragment = []) => {
73
79
  const table = fragment.find(node => node.type === "table");
74
80
  const row = table?.children?.find(node => node.type === "table-row");
@@ -122,20 +128,14 @@ const withHtml = editor => {
122
128
  const html = data?.getData("text/html");
123
129
  const currentEl = getCurrentElement(editor);
124
130
  const eltype = currentEl?.type;
125
- const isTitlePath = editor?.selection?.anchor?.path[0] === 0;
131
+ const firstNode = editor?.children?.[0];
132
+ const titlePath = firstNode?.type === "topbanner" ? 1 : 0;
133
+ const isTitlePath = editor.needLayout && editor?.selection?.anchor?.path[0] === titlePath;
126
134
  if (slateHTML && !formatFragment[eltype]) {
127
135
  const [tableCellNode] = Editor.nodes(editor, {
128
136
  match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
129
137
  });
130
138
  const decoded = decodeAndParseBase64(slateHTML);
131
- if (decoded && decoded[0] && decoded[0]?.type !== "paragraph" && isTitlePath) {
132
- decoded.unshift({
133
- type: "title",
134
- children: [{
135
- text: ""
136
- }]
137
- });
138
- }
139
139
  if (tableCellNode) {
140
140
  const tableCellChild = getTableCellChild(decoded);
141
141
  if (tableCellChild?.length) {
@@ -180,52 +180,38 @@ const withHtml = editor => {
180
180
  Transforms.insertText(editor, text);
181
181
  }
182
182
  } else {
183
- handleInsert(editor, () => {
184
- if (isTitlePath) {
185
- Transforms.insertNodes(editor, [{
186
- type: "title",
187
- children: [{
188
- text: ""
189
- }]
190
- }], {
191
- at: [0]
192
- });
193
- }
194
- insertData(data);
195
- }, decoded);
183
+ const isTextNode = ALLOWED_TEXT_NODES.includes(decoded?.[0]?.type);
184
+ if (isTitlePath && !isTextNode) {
185
+ insertAtNextNode(editor, decoded);
186
+ return;
187
+ }
188
+ const currentText = getCurrentElementText(editor);
189
+ if (currentText && !isTextNode) {
190
+ insertAtNextNode(editor, decoded);
191
+ return;
192
+ }
193
+ insertData(data);
196
194
  }
197
195
  } else if (html) {
198
196
  const parsed = new DOMParser().parseFromString(html, "text/html");
199
197
  const rootElement = parsed.body || parsed.documentElement;
200
- const isList = LIST_TAGS.includes(rootElement.firstChild.tagName.toLowerCase());
201
-
202
- // if selection is in title add the empty paragraph
203
- if (isTitlePath && isList) {
204
- // Check if the first child exists and is not a paragraph
205
- if (!rootElement.firstChild || rootElement.firstChild.tagName.toLowerCase() !== "p") {
206
- // Create a new empty paragraph element
207
- const emptyParagraph = parsed.createElement("p");
208
-
209
- // Insert the empty paragraph at the beginning
210
- if (rootElement.firstChild) {
211
- rootElement.insertBefore(emptyParagraph, rootElement.firstChild);
212
- } else {
213
- rootElement.appendChild(emptyParagraph);
214
- }
215
- }
216
- }
198
+ const isNonText = rootElement ? rootElement?.querySelector(NON_TEXT_TAGS.toString()) : false;
217
199
  const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
218
200
  if (isGoogleSheet) {
219
201
  if (editor.isChatEditor) {
220
202
  return;
221
203
  }
222
- const table = parsed.body.querySelector("table");
204
+ const table = rootElement.querySelector("table");
223
205
  const colGrp = table.querySelector("colgroup");
224
206
  if (colGrp) {
225
207
  colGrp.remove();
226
208
  }
227
209
  const fragment = deserialize(table);
228
- Transforms.insertFragment(editor, [fragment]);
210
+ if (isTitlePath) {
211
+ insertAtNextNode(editor, [fragment]);
212
+ } else {
213
+ Transforms.insertFragment(editor, [fragment]);
214
+ }
229
215
  return;
230
216
  }
231
217
  const fragment = deserialize(parsed.body);
@@ -239,7 +225,16 @@ const withHtml = editor => {
239
225
  if (editor.isChatEditor && is_img_table) {
240
226
  return;
241
227
  }
242
- handleInsert(editor, () => Transforms.insertFragment(editor, formattedFragment), formattedFragment);
228
+ if (isTitlePath && isNonText) {
229
+ insertAtNextNode(editor, formattedFragment);
230
+ return;
231
+ }
232
+ const currentText = getCurrentElementText(editor);
233
+ if (currentText && isNonText) {
234
+ insertAtNextNode(editor, formattedFragment);
235
+ return;
236
+ }
237
+ Transforms.insertFragment(editor, formattedFragment);
243
238
  return;
244
239
  } else {
245
240
  insertData(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "5.2.9",
3
+ "version": "5.3.1",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"