@flozy/editor 4.1.8 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,8 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
46
46
  const [deboundedValue] = useDebounce(value, 500);
47
47
  const editor = useMemo(() => {
48
48
  return withCommon(createEditor(), {
49
- needLayout
49
+ needLayout,
50
+ isChatEditor: true
50
51
  });
51
52
  }, []);
52
53
  const isReadOnly = readOnly === "readonly";
@@ -104,7 +104,6 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
104
104
  w: null,
105
105
  h: null
106
106
  });
107
- const [isScrolling, setIsScrolling] = useState(false);
108
107
  const [isTextSelected, setIsTextSelected] = useState(false);
109
108
  const [breakpoint, setBreakpoint] = useState("");
110
109
  const [size] = useWindowResize();
@@ -376,10 +375,10 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
376
375
  backgroundPosition: "-19px -19px"
377
376
  } : {};
378
377
  const handleScrollStop = useDebouncedCallback(() => {
379
- setIsScrolling(false);
378
+ editorWrapper?.current?.classList.add("hideScroll");
380
379
  }, 200);
381
380
  const handleScroll = () => {
382
- setIsScrolling(true);
381
+ editorWrapper?.current?.classList.remove("hideScroll");
383
382
  handleScrollStop();
384
383
  };
385
384
  const hasTopBanner = () => {
@@ -467,11 +466,9 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
467
466
  children: [/*#__PURE__*/_jsx(DragAndDrop, {
468
467
  children: /*#__PURE__*/_jsxs(Overlay, {
469
468
  children: [/*#__PURE__*/_jsx(Box, {
470
- className: `${hasTopBanner() ? "has-topbanner" : ""} ${!pageColor ? "no-color" : ""} ${isScrolling ? "" : "hideScroll"} scrollable-content scrollSmooth`,
469
+ className: `${hasTopBanner() ? "has-topbanner" : ""} ${!pageColor ? "no-color" : ""} scrollable-content scrollSmooth`,
471
470
  sx: classes.slateWrapper,
472
- id: "slate-wrapper-scroll-container"
473
- // style={editorWrapperStyle}
474
- ,
471
+ id: "slate-wrapper-scroll-container",
475
472
  ref: editorWrapper,
476
473
  onClick: e => {
477
474
  handleInsertLastElement(e, editor);
@@ -117,6 +117,9 @@ const useFreeGridStyles = ({
117
117
  },
118
118
  "& .fgi_type_button": {
119
119
  height: "100%",
120
+ "& .moreBtnShow": {
121
+ display: "none"
122
+ },
120
123
  "& .editor-btn-wrapper": {
121
124
  height: "100%",
122
125
  "& .editor-btn-wrapper-inner": {
@@ -140,7 +140,6 @@ export function onDropItem(props, parentClass) {
140
140
  // Update grid area
141
141
  const gridArea = `${row} / 1 / ${row + 1} / 2`;
142
142
  const appenBp = breakpoint === "lg" ? "" : `_${breakpoint}`;
143
- console.log(breakpoint, path);
144
143
  Transforms.setNodes(editor, {
145
144
  [`gridArea${appenBp}`]: gridArea,
146
145
  [`left${appenBp}`]: cCalx,
@@ -19,7 +19,6 @@ const VirtualElement = props => {
19
19
  if (virtualRef?.current) {
20
20
  setTimeout(() => {
21
21
  const allData = calculateProps(path, virtualRef?.current, ROOT_ITEM_CLASS, []);
22
- console.log(allData);
23
22
  // it should trigger by auto alignment or on clicking mobile view change
24
23
  updateAutoProps(editor, allData, "xs");
25
24
  }, 0);
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef, useState } from "react";
2
- import { Node, Path } from "slate";
2
+ import { Editor, Node, Path, Transforms } from "slate";
3
3
  import { ReactEditor } from "slate-react";
4
4
  import { Box } from "@mui/material";
5
5
  import { Rnd } from "react-rnd";
@@ -163,6 +163,12 @@ const RnD = props => {
163
163
  e.preventDefault();
164
164
  e.stopPropagation();
165
165
  }
166
+
167
+ // to prevent auto scroll to top
168
+ // when no editor.selection
169
+ if (!editor.selection) {
170
+ Transforms.select(editor, Editor.end(editor, []));
171
+ }
166
172
  switch (e.detail) {
167
173
  case 1:
168
174
  if (!enable) {
@@ -13,7 +13,7 @@ const getStartEnd = ({
13
13
  // Get start and end, modify it as we move along.
14
14
  let [start, end] = Range.edges(selection);
15
15
 
16
- // Move backwards
16
+ // Move backwards to find the start of the word
17
17
  while (true) {
18
18
  const before = Editor.before(editor, start, {
19
19
  unit: "character"
@@ -22,16 +22,15 @@ const getStartEnd = ({
22
22
  anchor: before,
23
23
  focus: start
24
24
  });
25
- if (before && wordBefore && SHORTHAND_CMDS.indexOf(wordBefore) < 0) {
26
- start = before;
27
- if (start.offset === 0) {
28
- // Means we've wrapped to beginning of another block
25
+ if (before) {
26
+ if (wordBefore.trim() === "") {
27
+ break;
28
+ } else if (SHORTHAND_CMDS.indexOf(wordBefore) < 0) {
29
+ start = before;
30
+ } else {
31
+ start = before;
29
32
  break;
30
33
  }
31
- } else if (SHORTHAND_CMDS.indexOf(wordBefore) >= 0) {
32
- // reached the character end
33
- start = before;
34
- break;
35
34
  } else {
36
35
  break;
37
36
  }
@@ -41,11 +40,38 @@ const getStartEnd = ({
41
40
  focus: end
42
41
  };
43
42
  const word = Editor.string(editor, wordRange);
43
+ const firstChar = word[0];
44
+
45
+ // Handle the commands
46
+ if (firstChar === '@') {
47
+ // Only trigger @ if preceded by a space
48
+ const isPrecededBySpace = Editor.string(editor, {
49
+ anchor: {
50
+ path: start.path,
51
+ offset: start.offset - 1
52
+ },
53
+ focus: start
54
+ }).trim() === "";
55
+ if (isPrecededBySpace) {
56
+ return {
57
+ word,
58
+ search: word.substring(1),
59
+ target: wordRange,
60
+ type: TYPES[firstChar]
61
+ };
62
+ }
63
+ } else if (firstChar === '/') {
64
+ return {
65
+ word,
66
+ search: word.substring(1),
67
+ target: wordRange,
68
+ type: TYPES[firstChar]
69
+ };
70
+ }
44
71
  return {
45
- word,
46
- search: word?.substring(1, word.length),
47
- target: wordRange,
48
- type: TYPES[word[0]]
72
+ word: "",
73
+ wordRange: null,
74
+ type: null
49
75
  };
50
76
  } catch (err) {
51
77
  return {
@@ -9,7 +9,12 @@ import withLayout from "../plugins/withLayout";
9
9
  import withHtml from "../plugins/withHTML";
10
10
  import withErrorHandling from "./withErrorHandling";
11
11
  import withCustomDeleteBackward from "../plugins/withCustomDeleteBackward";
12
- const withCommon = (props, rest = {}) => {
13
- return rest.needLayout ? withErrorHandling(withHtml(withEquation(withLayout(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))))) : withErrorHandling(withHtml(withEquation(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))));
12
+ const withCommon = (props, {
13
+ needLayout = false,
14
+ isChatEditor = false
15
+ }) => {
16
+ const editor = needLayout ? withErrorHandling(withHtml(withEquation(withLayout(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))))) : withErrorHandling(withHtml(withEquation(withHistory(withEmbeds(withTables(withLinks(withMentions(withCustomDeleteBackward(withReact(props))))))))));
17
+ editor.isChatEditor = isChatEditor;
18
+ return editor;
14
19
  };
15
20
  export default withCommon;
@@ -101,6 +101,9 @@ const withHtml = editor => {
101
101
  return element.type === "image" ? true : isVoid(element);
102
102
  };
103
103
  editor.insertData = data => {
104
+ if (editor.isChatEditor) {
105
+ return;
106
+ }
104
107
  const slateHTML = data?.getData("application/x-slate-fragment");
105
108
  const html = data?.getData("text/html");
106
109
  const currentEl = getCurrentElement(editor);
@@ -365,6 +365,6 @@ export const getBlock = props => {
365
365
  ...props
366
366
  });
367
367
  default:
368
- return;
368
+ return null;
369
369
  }
370
370
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.1.8",
3
+ "version": "4.2.0",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"