@flozy/editor 8.0.2 → 8.0.4

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,6 +1,6 @@
1
1
  import React, { useCallback, useMemo, useRef, useState, useImperativeHandle, forwardRef } from "react";
2
- import { Editable, Slate, ReactEditor } from "slate-react";
3
- import { createEditor, Transforms, Editor } from "slate";
2
+ import { Editable, Slate, ReactEditor } from 'slate-react';
3
+ import { createEditor, Transforms, Editor } from 'slate';
4
4
  import withCommon from "./hooks/withCommon";
5
5
  import { getBlock, getMarked, serializeMentions } from "./utils/chatEditor/SlateUtilityFunctions";
6
6
  import MiniTextFormat from "./Toolbar/PopupTool/MiniTextFormat";
@@ -35,13 +35,13 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
35
35
  const classes = usePopupStyle(theme);
36
36
  const convertedContent = draftToSlate({
37
37
  data: content && content?.length > 0 ? content : [{
38
- type: "paragraph",
38
+ type: 'paragraph',
39
39
  children: [{
40
- text: ""
40
+ text: ''
41
41
  }]
42
42
  }]
43
43
  });
44
- const [value] = useState(convertedContent);
44
+ const [value, setValue] = useState(convertedContent);
45
45
  const debouncedValue = useRef(value);
46
46
  const debounced = useDebouncedCallback(
47
47
  // function
@@ -142,6 +142,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
142
142
  const mentionsRef = useRef();
143
143
  const customProps = {
144
144
  ...(otherProps || {}),
145
+ hideTools: ["settings", "add_column", "drag", "resize"],
145
146
  readOnly: isReadOnly,
146
147
  editorPlaceholder: "Write Something",
147
148
  page_id: 1
@@ -216,7 +217,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
216
217
  editor
217
218
  });
218
219
  } else if (event.key === "Enter" && !isMobile) {
219
- const isEmpty = debouncedValue?.current.length === 1 && debouncedValue?.current[0].type === "paragraph" && debouncedValue?.current[0].children.length === 1 && debouncedValue?.current[0].children[0].text === "";
220
+ const isEmpty = debouncedValue?.current.length === 1 && debouncedValue?.current[0].type === 'paragraph' && debouncedValue?.current[0].children.length === 1 && debouncedValue?.current[0].children[0].text === '';
220
221
  if (isEmpty) {
221
222
  event.preventDefault();
222
223
  return;
@@ -446,6 +446,12 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
446
446
  }
447
447
  }
448
448
  }
449
+ } else if (event.key === "Delete") {
450
+ const everythingSelect = isEverythingSelected(editor);
451
+ if (everythingSelect) {
452
+ event.preventDefault();
453
+ dialogRef.current?.handleOpen();
454
+ }
449
455
  }
450
456
  }, [chars, target, mentions, setMentions, search, type, mentionsRef]);
451
457
  const Overlay = collaborativeEditor && !isReadOnly ? RemoteCursorOverlay : React.Fragment;
@@ -133,7 +133,8 @@ const Table = props => {
133
133
  const classes = TableStyles(editorTheme);
134
134
  const {
135
135
  readOnly,
136
- isMobile
136
+ isMobile,
137
+ hideTools = []
137
138
  } = customProps;
138
139
  const [openSetttings, setOpenSettings] = useState(false);
139
140
  const [exandTools, setExpandTools] = useState(null);
@@ -304,16 +305,16 @@ const Table = props => {
304
305
  ...attributes,
305
306
  children: children
306
307
  })
307
- }), /*#__PURE__*/_jsx(AddRowCol, {
308
+ }), !hideTools.includes("add_column") && /*#__PURE__*/_jsx(AddRowCol, {
308
309
  ...commonAddBtnProps,
309
310
  addType: "col",
310
311
  onAdd: addCol
311
312
  })]
312
- }), /*#__PURE__*/_jsx(AddRowCol, {
313
+ }), !hideTools.includes("add_column") && /*#__PURE__*/_jsx(AddRowCol, {
313
314
  ...commonAddBtnProps,
314
315
  addType: "row",
315
316
  onAdd: addRow
316
- }), !readOnly && /*#__PURE__*/_jsx(ToolBar, {
317
+ }), !readOnly && !hideTools.includes("settings") && /*#__PURE__*/_jsx(ToolBar, {
317
318
  selected: selected,
318
319
  showTool: showTool,
319
320
  classes: classes,
@@ -48,7 +48,8 @@ const TableCell = props => {
48
48
  customProps
49
49
  } = props;
50
50
  const {
51
- readOnly
51
+ readOnly,
52
+ hideTools = []
52
53
  } = customProps;
53
54
  const isMobile = window.matchMedia("(max-width: 899px)")?.matches || false;
54
55
  const {
@@ -106,8 +107,8 @@ const TableCell = props => {
106
107
  const isFirstRow = row === 0;
107
108
  const isFirstColumn = column === 0;
108
109
  const [hoverRow, hoverCol] = hoverPath ? hoverPath.slice(-2) : [];
109
- const showColDrag = isFirstRow && hoverCol === column && !resizing && !readOnly;
110
- const showRowDrag = isFirstColumn && hoverRow === row && !resizing && !readOnly;
110
+ const showColDrag = isFirstRow && hoverCol === column && !resizing && !readOnly && !hideTools.includes("drag");
111
+ const showRowDrag = isFirstColumn && hoverRow === row && !resizing && !readOnly && !hideTools.includes("drag");
111
112
  const [parentProps] = tableNode || [{}];
112
113
  const [rowProps] = rowNode || [{}];
113
114
  const tableDOM = table.getDOMNode(path, true);
@@ -67,6 +67,7 @@ const MiniToolbar = props => {
67
67
  if (data) {
68
68
  setToolTip(false);
69
69
  setData(null);
70
+ setPopper(null);
70
71
  }
71
72
  }, [data]);
72
73
  useEffect(() => {
@@ -238,9 +238,9 @@ const withHtml = editor => {
238
238
  const isNonText = rootElement ? rootElement?.querySelector(NON_TEXT_TAGS.toString()) : false;
239
239
  const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
240
240
  if (isGoogleSheet) {
241
- if (editor.isChatEditor) {
242
- return;
243
- }
241
+ // if (editor.isChatEditor) {
242
+ // return;
243
+ // }
244
244
  const table = rootElement.querySelector("table");
245
245
  const colGrp = table.querySelector("colgroup");
246
246
  if (colGrp) {
@@ -256,15 +256,18 @@ const withHtml = editor => {
256
256
  }
257
257
  const fragment = deserialize(parsed.body);
258
258
  const formattedFragment = formatFragment[eltype] ? formatFragment[eltype](fragment) : fragment;
259
- let is_img_table = false;
260
- formattedFragment.map(f => {
261
- if (f.type === "image" || f?.type?.includes("table")) {
262
- is_img_table = true;
263
- }
264
- });
265
- if (editor.isChatEditor && is_img_table) {
266
- return;
267
- }
259
+
260
+ // let is_img_table = false;
261
+ // formattedFragment.map((f) => {
262
+ // if (f.type === "image" || f?.type?.includes("table")) {
263
+ // is_img_table = true;
264
+ // }
265
+ // });
266
+
267
+ // if (editor.isChatEditor && is_img_table) {
268
+ // return;
269
+ // }
270
+
268
271
  if (isTitlePath && isNonText) {
269
272
  insertAtNextNode(editor, formattedFragment);
270
273
  return;
@@ -8,6 +8,9 @@ import { isEmptyTextNode } from "../../helper";
8
8
  import { getBreakPointsValue } from "../../helper/theme";
9
9
  import insertNewLine from "../insertNewLine";
10
10
  import { getBorderColor } from "../helper";
11
+ import Table from "../../Elements/Table/Table";
12
+ import TableRow from "../../Elements/Table/TableRow";
13
+ import TableCell from "../../Elements/Table/TableCell";
11
14
  import { jsx as _jsx } from "react/jsx-runtime";
12
15
  const alignment = ["alignLeft", "alignRight", "alignCenter"];
13
16
  const list_types = ["orderedList", "unorderedList"];
@@ -406,6 +409,26 @@ export const getBlock = props => {
406
409
  return /*#__PURE__*/_jsx(Mentions, {
407
410
  ...props
408
411
  });
412
+ case "table":
413
+ return /*#__PURE__*/_jsx(Table, {
414
+ ...props
415
+ });
416
+ case "table-head":
417
+ return /*#__PURE__*/_jsx("thead", {
418
+ children: children
419
+ });
420
+ case "table-body":
421
+ return /*#__PURE__*/_jsx("tbody", {
422
+ children: children
423
+ });
424
+ case "table-row":
425
+ return /*#__PURE__*/_jsx(TableRow, {
426
+ ...props
427
+ });
428
+ case "table-cell":
429
+ return /*#__PURE__*/_jsx(TableCell, {
430
+ ...props
431
+ });
409
432
  default:
410
433
  return /*#__PURE__*/_jsx(SimpleText, {
411
434
  ...props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"