@flozy/editor 4.4.8 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/dist/Editor/ChatEditor.js +2 -14
  2. package/dist/Editor/CommonEditor.js +17 -34
  3. package/dist/Editor/Editor.css +7 -1
  4. package/dist/Editor/Elements/AI/AIInput.js +4 -5
  5. package/dist/Editor/Elements/AI/PopoverAIInput.js +40 -29
  6. package/dist/Editor/Elements/AI/Styles.js +1 -1
  7. package/dist/Editor/Elements/Button/EditorButton.js +8 -4
  8. package/dist/Editor/Elements/Embed/Embed.css +1 -1
  9. package/dist/Editor/Elements/Embed/Image.js +4 -3
  10. package/dist/Editor/Elements/Embed/Video.js +4 -4
  11. package/dist/Editor/Elements/Form/Form.js +0 -1
  12. package/dist/Editor/Elements/Form/Workflow/FormWorkflow.js +3 -12
  13. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +27 -0
  14. package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +2 -0
  15. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +3 -1
  16. package/dist/Editor/Elements/FreeGrid/Options/AddElement.js +4 -0
  17. package/dist/Editor/Elements/FreeGrid/Options/sectionItemOptions.js +5 -1
  18. package/dist/Editor/Elements/FreeGrid/styles.js +74 -1
  19. package/dist/Editor/Elements/Mentions/Mentions.js +2 -3
  20. package/dist/Editor/Elements/Signature/SignaturePopup.js +7 -3
  21. package/dist/Editor/Elements/Signature/Signed.js +1 -1
  22. package/dist/Editor/Elements/SimpleText/index.js +3 -2
  23. package/dist/Editor/Elements/Table/TableRow.js +1 -1
  24. package/dist/Editor/Styles/EditorStyles.js +2 -2
  25. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +1 -2
  26. package/dist/Editor/Toolbar/PopupTool/ButtonTemplatesCard.js +35 -29
  27. package/dist/Editor/Toolbar/PopupTool/FullViewCard.js +35 -30
  28. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +4 -4
  29. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +22 -38
  30. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +0 -1
  31. package/dist/Editor/Toolbar/PopupTool/index.js +5 -5
  32. package/dist/Editor/common/FontLoader/FontLoader.js +6 -6
  33. package/dist/Editor/common/Icon.js +1 -1
  34. package/dist/Editor/common/RnD/DragOver/index.js +0 -1
  35. package/dist/Editor/common/RnD/ElementOptions/Actions.js +14 -1
  36. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Settings.js +1 -1
  37. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Signature.js +53 -0
  38. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/index.js +32 -2
  39. package/dist/Editor/common/RnD/ElementSettings/settingsConstants.js +2 -1
  40. package/dist/Editor/common/RnD/Utils/gridDropItem.js +5 -3
  41. package/dist/Editor/common/RnD/index.js +64 -30
  42. package/dist/Editor/common/Section/index.js +11 -1
  43. package/dist/Editor/common/Section/styles.js +16 -0
  44. package/dist/Editor/common/Shorthands/mentions.js +1 -1
  45. package/dist/Editor/helper/RnD/focusNode.js +74 -0
  46. package/dist/Editor/helper/index.js +4 -2
  47. package/dist/Editor/hooks/useBreakpoints.js +1 -1
  48. package/dist/Editor/hooks/useDragging.js +51 -0
  49. package/dist/Editor/hooks/useMentions.js +13 -39
  50. package/dist/Editor/hooks/useMouseMove.js +5 -1
  51. package/dist/Editor/hooks/withCommon.js +3 -7
  52. package/dist/Editor/hooks/withRestrictedNodes.js +48 -0
  53. package/dist/Editor/plugins/withHTML.js +0 -29
  54. package/dist/Editor/utils/Decorators/highlightSelection.js +16 -0
  55. package/dist/Editor/utils/Decorators/index.js +3 -2
  56. package/dist/Editor/utils/RnD/RnDCtrlCmds.js +13 -1
  57. package/dist/Editor/utils/SlateUtilityFunctions.js +18 -0
  58. package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +24 -1
  59. package/dist/Editor/utils/customHooks/useResize.js +4 -5
  60. package/dist/Editor/utils/events.js +36 -0
  61. package/dist/Editor/utils/helper.js +14 -5
  62. package/package.json +1 -1
@@ -0,0 +1,48 @@
1
+ import { Editor } from "slate";
2
+
3
+ // Custom insertText that prevents updates in specific node types
4
+ const withRestrictedNodes = editor => {
5
+ const {
6
+ insertText,
7
+ deleteBackward
8
+ } = editor;
9
+
10
+ // Override insertText
11
+ editor.insertText = text => {
12
+ const {
13
+ selection
14
+ } = editor;
15
+ if (selection) {
16
+ const [node] = Editor.node(editor, selection);
17
+ console.log(node);
18
+
19
+ // Prevent insertText if node type matches
20
+ if (node && node.type === "restrictedType") {
21
+ return; // Skip inserting text
22
+ }
23
+ }
24
+
25
+ // Call the original insertText if node type does not match
26
+ insertText(text);
27
+ };
28
+
29
+ // Similarly override deleteBackward if needed
30
+ editor.deleteBackward = (...args) => {
31
+ const {
32
+ selection
33
+ } = editor;
34
+ if (selection) {
35
+ const [node] = Editor.node(editor, selection);
36
+
37
+ // Prevent deletion if node type matches
38
+ if (node && node.type === "restrictedType") {
39
+ return; // Skip deleting text
40
+ }
41
+ }
42
+
43
+ // Call the original deleteBackward if node type does not match
44
+ deleteBackward(...args);
45
+ };
46
+ return editor;
47
+ };
48
+ export default withRestrictedNodes;
@@ -114,23 +114,6 @@ const withHtml = editor => {
114
114
  const defaultInsert = loopChildren(decoded, true);
115
115
  if (defaultInsert) {
116
116
  insertData(data);
117
- // } else if (editor.isChatEditor) {
118
- // // Only convert table to paragraphs if in chat editor mode
119
- // const paragraphs = decoded.map(row =>
120
- // row.children.map(cell =>
121
- // cell.children.map(paragraph =>
122
- // paragraph.children.map(textNode => textNode.text).join('')
123
- // ).join(' ')
124
- // ).join(' ')
125
- // ).join('\n'); // Joining with a newline for separate paragraphs
126
-
127
- // // Insert text as paragraphs
128
- // const textNodes = paragraphs.split('\n').map(text => ({
129
- // type: 'paragraph',
130
- // children: [{ text }]
131
- // }));
132
-
133
- // Transforms.insertNodes(editor, textNodes);
134
117
  } else {
135
118
  // do not paste table, grid inside table cell
136
119
  // only plain text for internal paste
@@ -144,9 +127,6 @@ const withHtml = editor => {
144
127
  const parsed = new DOMParser().parseFromString(html, "text/html");
145
128
  const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
146
129
  if (isGoogleSheet) {
147
- if (editor.isChatEditor) {
148
- return;
149
- }
150
130
  const table = parsed.body.querySelector("table");
151
131
  const colGrp = table.querySelector("colgroup");
152
132
  if (colGrp) {
@@ -158,15 +138,6 @@ const withHtml = editor => {
158
138
  }
159
139
  const fragment = deserialize(parsed.body);
160
140
  const formattedFragment = formatFragment[eltype] ? formatFragment[eltype](fragment) : fragment;
161
- let is_img_table = false;
162
- formattedFragment.map(f => {
163
- if (f.type === 'image' || f?.type?.includes('table')) {
164
- is_img_table = true;
165
- }
166
- });
167
- if (editor.isChatEditor && is_img_table) {
168
- return;
169
- }
170
141
  handleInsert(editor, () => Transforms.insertFragment(editor, formattedFragment), formattedFragment);
171
142
  return;
172
143
  } else {
@@ -0,0 +1,16 @@
1
+ import { Editor, Range, Text } from "slate";
2
+ const highlightSelection = ([node, path], editor) => {
3
+ if (Text.isText(node) && editor.selection) {
4
+ const intersection = Range.intersection(editor.selection, Editor.range(editor, path));
5
+ if (intersection == null) {
6
+ return [];
7
+ }
8
+ const range = {
9
+ highlight: true,
10
+ ...intersection
11
+ };
12
+ return [range];
13
+ }
14
+ return [];
15
+ };
16
+ export default highlightSelection;
@@ -1,5 +1,6 @@
1
+ import highlightSelection from "./highlightSelection";
1
2
  import link from "./link";
2
- const decorators = d => {
3
- return [...link(d)];
3
+ const decorators = (d, editor) => {
4
+ return [...link(d, editor), ...highlightSelection(d, editor)];
4
5
  };
5
6
  export default decorators;
@@ -157,7 +157,7 @@ const onBringBack = (event, {
157
157
  console.log(err);
158
158
  }
159
159
  };
160
- export const onInsertFragment = async ({
160
+ export const onInsertFragment = ({
161
161
  editor,
162
162
  slateNodes
163
163
  }) => {
@@ -181,6 +181,18 @@ export const onInsertFragment = async ({
181
181
  setSelectedElement: window.updateSelectedItem
182
182
  });
183
183
  }
184
+ } else {
185
+ // if no selection place items at last
186
+ const np = onPasteRnDNode(editor, {
187
+ path: [editor.children.length - 1, 0],
188
+ children: [],
189
+ slateNodes: slateNodes
190
+ });
191
+ if (np && window.updateSelectedItem) {
192
+ focusOnNewItem(editor, np, {
193
+ setSelectedElement: window.updateSelectedItem
194
+ });
195
+ }
184
196
  }
185
197
  } catch (err) {
186
198
  console.log(err);
@@ -232,6 +232,15 @@ export const getMarked = (leaf, children, theme) => {
232
232
  })
233
233
  });
234
234
  }
235
+ if (leaf.highlight) {
236
+ children = /*#__PURE__*/_jsx("span", {
237
+ style: {
238
+ background: "#EAEBFE",
239
+ color: "inherit"
240
+ },
241
+ children: children
242
+ });
243
+ }
235
244
  if (leaf.decoration === "link") {
236
245
  children = /*#__PURE__*/_jsx("a", {
237
246
  style: {
@@ -529,6 +538,15 @@ export const getBlock = props => {
529
538
  return /*#__PURE__*/_jsx(Code, {
530
539
  ...props
531
540
  });
541
+ // RnD Focus Node
542
+ case "temp":
543
+ return /*#__PURE__*/_jsx("span", {
544
+ ...attributes,
545
+ ...element.attr,
546
+ className: "temp-focus-node",
547
+ contentEditable: false,
548
+ children: children
549
+ });
532
550
  default:
533
551
  return /*#__PURE__*/_jsx(SimpleText, {
534
552
  ...props,
@@ -1,6 +1,9 @@
1
1
  import { Editor, Transforms, Element as SlateElement } from "slate";
2
2
  import { Box } from "@mui/material";
3
3
  import { fontFamilyMap, sizeMap } from "../font";
4
+ import Table from "../../Elements/Table/Table";
5
+ import TableRow from "../../Elements/Table/TableRow";
6
+ import TableCell from "../../Elements/Table/TableCell";
4
7
  import Mentions from "../../Elements/Mentions/Mentions";
5
8
  import CheckList from "../../Elements/List/CheckList";
6
9
  import { isEmptyTextNode } from "../../helper";
@@ -337,11 +340,31 @@ export const getBlock = props => {
337
340
  ...props,
338
341
  isEmpty: isEmpty
339
342
  });
343
+ case "table":
344
+ return /*#__PURE__*/_jsx(Table, {
345
+ ...props
346
+ });
347
+ case "table-head":
348
+ return /*#__PURE__*/_jsx("thead", {
349
+ children: children
350
+ });
351
+ case "table-body":
352
+ return /*#__PURE__*/_jsx("tbody", {
353
+ children: children
354
+ });
355
+ case "table-row":
356
+ return /*#__PURE__*/_jsx(TableRow, {
357
+ ...props
358
+ });
359
+ case "table-cell":
360
+ return /*#__PURE__*/_jsx(TableCell, {
361
+ ...props
362
+ });
340
363
  case "mention":
341
364
  return /*#__PURE__*/_jsx(Mentions, {
342
365
  ...props
343
366
  });
344
367
  default:
345
- return null;
368
+ return;
346
369
  }
347
370
  };
@@ -10,7 +10,7 @@ const useResize = ({
10
10
  const defaultSize = getBreakPointsValue(allSize);
11
11
  const {
12
12
  width,
13
- height = 370
13
+ height
14
14
  } = parentDOM?.getBoundingClientRect() || {
15
15
  ...defaultSize
16
16
  };
@@ -50,11 +50,10 @@ const useResize = ({
50
50
  setSize(currentSize => {
51
51
  const calcWidth = (currentSize.width || width) + e.movementX;
52
52
  const cWP = calcWidth / width * 100;
53
- const calcHeight = (parseInt(currentSize.height) || height) + e.movementY;
54
53
  const calc = {
55
- width: Math.max(calcWidth, 140),
56
- height: Math.max(calcHeight, 50),
57
- widthInPercent: cWP > 100 ? 100 : Math.max(cWP, 15)
54
+ width: calcWidth,
55
+ height: (parseInt(currentSize.height) || height) + e.movementY,
56
+ widthInPercent: cWP > 100 ? 100 : cWP
58
57
  };
59
58
  latest = calc;
60
59
  return calc;
@@ -285,4 +285,40 @@ export const enterEvent = (e, editor, isMobile) => {
285
285
  } catch (err) {
286
286
  console.log(err);
287
287
  }
288
+ };
289
+ export const upDownArrowKeyEvents = (e, editor) => {
290
+ try {
291
+ const {
292
+ selection
293
+ } = editor;
294
+ if (!selection || Range.isCollapsed(selection)) {
295
+ return;
296
+ }
297
+ const parentPath = selection.anchor.path.slice(0, -1);
298
+ const nextNodePath = [...parentPath];
299
+ const index = parentPath[parentPath.length - 1];
300
+ const parentNode = Editor.parent(editor, parentPath);
301
+ if (parentNode.children[index + 1]) {
302
+ nextNodePath[parentPath.length - 1] += 1;
303
+ } else {
304
+ return;
305
+ }
306
+ Transforms.move(editor, {
307
+ distance: 0,
308
+ unit: 'offset',
309
+ reverse: false
310
+ });
311
+ Transforms.select(editor, {
312
+ anchor: {
313
+ path: nextNodePath,
314
+ offset: 0
315
+ },
316
+ focus: {
317
+ path: nextNodePath,
318
+ offset: 0
319
+ }
320
+ });
321
+ } catch (err) {
322
+ console.log(err);
323
+ }
288
324
  };
@@ -471,10 +471,19 @@ export const editorThemeStyle = {
471
471
  export const getEditorTheme = (themeType = "light") => {
472
472
  return editorThemeStyle[themeType] || {};
473
473
  };
474
- export const getPreviousNode = editor => {
474
+ export const isFreeGrid = (nodes, types = ["freegrid", "freegridItem", "freegridBox"]) => {
475
475
  try {
476
- const parentPath = Path.parent(editor?.selection?.anchor?.path);
477
- const prevPath = Path.previous(parentPath);
478
- return getNode(editor, prevPath);
479
- } catch (err) {}
476
+ for (const node of nodes) {
477
+ if (types.includes(node.type)) {
478
+ return true;
479
+ }
480
+ if (node.children && isFreeGrid(node.children, types)) {
481
+ return true;
482
+ }
483
+ }
484
+ return false;
485
+ } catch (err) {
486
+ console.log('isFreeGrid error:', err);
487
+ return false;
488
+ }
480
489
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.4.8",
3
+ "version": "4.5.0",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"