@flozy/editor 4.9.4 → 4.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/dist/Editor/ChatEditor.js +25 -34
  2. package/dist/Editor/Editor.css +25 -7
  3. package/dist/Editor/Elements/AI/AIInput.js +0 -1
  4. package/dist/Editor/Elements/AI/Styles.js +7 -7
  5. package/dist/Editor/Elements/Link/LinkButton.js +1 -1
  6. package/dist/Editor/Elements/Search/SearchButton.js +4 -4
  7. package/dist/Editor/Elements/Search/SearchList.js +7 -5
  8. package/dist/Editor/Elements/Signature/SignaturePopup.js +3 -2
  9. package/dist/Editor/Elements/Table/AddRowCol.js +3 -2
  10. package/dist/Editor/Elements/Table/DragButton.js +6 -2
  11. package/dist/Editor/Elements/Table/DragStyles.js +62 -36
  12. package/dist/Editor/Elements/Table/Styles.js +1 -1
  13. package/dist/Editor/Elements/Table/Table.js +8 -3
  14. package/dist/Editor/Elements/Table/TableCell.js +24 -10
  15. package/dist/Editor/Elements/Table/tableHelper.js +83 -0
  16. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +2 -0
  17. package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +2 -0
  18. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +3 -3
  19. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +133 -31
  20. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +2 -0
  21. package/dist/Editor/common/ColorPickerButton.js +3 -2
  22. package/dist/Editor/common/MentionsPopup/Styles.js +1 -7
  23. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +1 -0
  24. package/dist/Editor/common/RnD/index.js +1 -1
  25. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +5 -0
  26. package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +10 -2
  27. package/dist/Editor/common/Uploader.js +8 -0
  28. package/dist/Editor/common/iconListV2.js +2 -0
  29. package/dist/Editor/common/iconslist.js +1 -0
  30. package/dist/Editor/commonStyle.js +6 -2
  31. package/dist/Editor/helper/deserialize/index.js +5 -11
  32. package/dist/Editor/hooks/useTable.js +37 -30
  33. package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +14 -0
  34. package/dist/Editor/utils/events.js +0 -1
  35. package/dist/Editor/utils/helper.js +11 -0
  36. package/dist/Editor/utils/serializeToText.js +2 -0
  37. package/package.json +1 -1
@@ -1,8 +1,11 @@
1
1
  import { ClickAwayListener } from "@mui/material";
2
2
  import { createContext, useContext, useEffect, useMemo, useState } from "react";
3
3
  import { clearCellText } from "../utils/table";
4
- import { Editor, Element, Transforms } from "slate";
4
+ import { Editor, Element, Transforms, Range } from "slate";
5
5
  import { DndContext, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
6
+ import { encodeToBase64 } from "../utils/helper";
7
+ import { serializeToText } from "../utils/serializeToText";
8
+ import { createCopiedTableStructure, getRectangleBounds, tableNodeToDom } from "../Elements/Table/tableHelper";
6
9
  import { jsx as _jsx } from "react/jsx-runtime";
7
10
  const handleDragEnd = (dragData, editor, resetAll) => {
8
11
  const {
@@ -47,29 +50,6 @@ const handleDragEnd = (dragData, editor, resetAll) => {
47
50
  }
48
51
  }
49
52
  };
50
- const getRectangleBounds = tableSelection => {
51
- const {
52
- startCellPath,
53
- endCellPath
54
- } = tableSelection;
55
- if (!startCellPath?.length) return [];
56
- const startPath = startCellPath.slice(0, -2);
57
- const startCell = startCellPath.slice(-2);
58
- const endCell = endCellPath.slice(-2);
59
- const [startRow, startCol] = startCell;
60
- const [endRow, endCol] = endCell?.length ? endCell : startCell;
61
- const minRow = Math.min(startRow, endRow);
62
- const maxRow = Math.max(startRow, endRow);
63
- const minCol = Math.min(startCol, endCol);
64
- const maxCol = Math.max(startCol, endCol);
65
- const selectedPaths = [];
66
- for (let row = minRow; row <= maxRow; row++) {
67
- for (let col = minCol; col <= maxCol; col++) {
68
- selectedPaths.push([...startPath, row, col]);
69
- }
70
- }
71
- return selectedPaths;
72
- };
73
53
  const TableContext = /*#__PURE__*/createContext();
74
54
  export function getDefaultTableSelection() {
75
55
  return {
@@ -135,22 +115,49 @@ export const TableProvider = ({
135
115
  }
136
116
  }
137
117
  };
118
+ const handleCopy = event => {
119
+ try {
120
+ const isTextSelected = editor?.selection && !Range.isCollapsed(editor.selection);
121
+ const customCopy = tableSelection?.startCellPath?.length;
122
+ if (customCopy) {
123
+ event.preventDefault(); // Prevent default copy behavior
124
+
125
+ const {
126
+ tablePath
127
+ } = otherProps;
128
+ const [node] = Editor.node(editor, tablePath);
129
+ const selectedText = isTextSelected ? Editor.string(editor, editor.selection) : "";
130
+ const copiedTableNode = createCopiedTableStructure(editor, tableSelection, node, tablePath, selectedText);
131
+ const tableNode = [copiedTableNode];
132
+ const encodedTableNode = encodeToBase64(tableNode);
133
+ event.clipboardData.setData("application/x-slate-fragment", encodedTableNode);
134
+ const textData = selectedText || serializeToText(tableNode);
135
+ event.clipboardData.setData("text/plain", textData);
136
+ const tableDom = tableNodeToDom(copiedTableNode, selectedText);
137
+ event.clipboardData.setData("text/html", tableDom?.outerHTML);
138
+ }
139
+ } catch (err) {
140
+ console.log(err);
141
+ }
142
+ };
138
143
  window.addEventListener("keydown", handleKeyDown);
144
+ window.addEventListener("copy", handleCopy);
139
145
  return () => {
140
146
  window.removeEventListener("keydown", handleKeyDown);
147
+ window.removeEventListener("copy", handleCopy);
141
148
  };
142
- }, [tableSelection]);
149
+ }, [tableSelection, editor, tableSelection]);
143
150
  useEffect(() => {
144
151
  // on deselect table on insert
145
152
  Transforms.deselect(editor);
146
153
  }, []);
147
154
  return /*#__PURE__*/_jsx(TableContext.Provider, {
148
155
  value: values,
149
- children: /*#__PURE__*/_jsx(ClickAwayListener, {
150
- onClickAway: () => setTableSelection(getDefaultTableSelection()),
151
- children: /*#__PURE__*/_jsx(DndContext, {
152
- sensors: sensors,
153
- onDragEnd: data => handleDragEnd(data, editor, resetAll),
156
+ children: /*#__PURE__*/_jsx(DndContext, {
157
+ sensors: sensors,
158
+ onDragEnd: data => handleDragEnd(data, editor, resetAll),
159
+ children: /*#__PURE__*/_jsx(ClickAwayListener, {
160
+ onClickAway: () => setTableSelection(getDefaultTableSelection()),
154
161
  children: /*#__PURE__*/_jsx("div", {
155
162
  children: children
156
163
  })
@@ -15,6 +15,20 @@ const LIST_FORMAT_TYPE = {
15
15
  unorderedList: "list-item"
16
16
  };
17
17
  const NEWLINESAFTER = ["headingOne", "headingTwo", "headingThree"];
18
+ export const serializeMentions = node => {
19
+ try {
20
+ if (node?.type === 'mention') {
21
+ return [node.character];
22
+ }
23
+ let children = Array.isArray(node) ? node : node?.children;
24
+ children = children && Array.isArray(children) ? children : [];
25
+ let mentions = children.map(child => serializeMentions(child)).flat();
26
+ return mentions.filter(Boolean);
27
+ } catch (err) {
28
+ console.log(err);
29
+ return [];
30
+ }
31
+ };
18
32
  export const toggleBlock = (editor, format, selection = true, attr = {}) => {
19
33
  const isActive = isBlockActive(editor, format);
20
34
  const isList = list_types.includes(format);
@@ -5,7 +5,6 @@ import { insertAccordion } from "./accordion";
5
5
  import { isListItem } from "./helper";
6
6
  import RnDCtrlCmds from "./RnD/RnDCtrlCmds";
7
7
  import EDITORCMDS from "../common/EditorCmds";
8
- import { ReactEditor } from "slate-react";
9
8
  const HOTKEYS = {
10
9
  b: "bold",
11
10
  i: "italic",
@@ -209,6 +209,17 @@ export const decodeAndParseBase64 = encodedString => {
209
209
  const jsonData = JSON.parse(decodedURLString);
210
210
  return jsonData;
211
211
  };
212
+ export const encodeToBase64 = data => {
213
+ // Convert the data to a JSON string
214
+ const jsonString = JSON.stringify(data);
215
+
216
+ // URL-encode the JSON string
217
+ const encodedURLString = encodeURIComponent(jsonString);
218
+
219
+ // Base64-encode the URL-encoded string
220
+ const base64EncodedString = btoa(encodedURLString);
221
+ return base64EncodedString;
222
+ };
212
223
  export const hasVerticalScrollbar = (element = {}) => {
213
224
  return element.scrollHeight > element.clientHeight;
214
225
  };
@@ -2,6 +2,8 @@ export const serializeToText = node => {
2
2
  try {
3
3
  if (!node?.type && node?.text) {
4
4
  return node?.text;
5
+ } else if (node?.type === 'mention') {
6
+ return '@' + node?.character?.name || '';
5
7
  }
6
8
  let n = Array.isArray(node) ? node : node?.children;
7
9
  n = n && Array.isArray(n) ? n : n ? [n] : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.9.4",
3
+ "version": "4.9.6",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"