@flozy/editor 9.4.8 → 9.5.0

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.
@@ -352,7 +352,8 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
352
352
  ...mentions,
353
353
  CHARACTERS,
354
354
  hideTools: updatedHideTools || [],
355
- translation: translation || translationFn
355
+ translation: translation || translationFn,
356
+ editor
356
357
  }) : [];
357
358
  const handleEditorChange = newValue => {
358
359
  if (JSON.stringify(newValue) !== JSON.stringify(debouncedValue?.current)) {
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { Grid } from "@mui/material";
3
3
  import { toolbarGroups } from "../toolbarGroups";
4
4
  import { RenderToolbarIcon } from "../Toolbar";
5
+ import canOpen from "../../helper/canOpen";
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  const allTools = toolbarGroups.flat();
7
8
  const elements = allTools.filter(f => f?.group === "elements");
@@ -14,7 +15,10 @@ const AddElements = props => {
14
15
  const {
15
16
  hideTools
16
17
  } = customProps;
17
- const filteredElements = elements.filter(f => (hideTools || []).indexOf(f.type) === -1);
18
+ const nodeType = canOpen(editor);
19
+ const filteredElements = elements.filter(f => {
20
+ return (hideTools || []).indexOf(f.type) === -1 && (f.hideFor === undefined || f?.hideFor?.indexOf(nodeType) === -1);
21
+ });
18
22
  return /*#__PURE__*/_jsx(Grid, {
19
23
  container: true,
20
24
  className: "elements-wrpr-pp",
@@ -232,11 +232,13 @@ export const toolbarGroups = [[{
232
232
  }, {
233
233
  id: 42,
234
234
  type: "table",
235
- group: "elements"
235
+ group: "elements",
236
+ hideFor: ["table", "dataView"]
236
237
  }, {
237
238
  id: 51,
238
239
  type: "dataView",
239
- group: "elements"
240
+ group: "elements",
241
+ hideFor: ["table", "dataView"]
240
242
  }, {
241
243
  id: 48,
242
244
  format: "divider",
@@ -8,6 +8,7 @@ import { Typography, Popper, Box, Paper } from "@mui/material";
8
8
  import usePopupStyle from "./Styles";
9
9
  import { useEditorContext } from "../../hooks/useMouseMove";
10
10
  import { checkTypings } from "../../hooks/useMentions";
11
+ import canOpen from "../../helper/canOpen";
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
14
  const POPUP_LIST_TYPES = {
@@ -19,7 +20,7 @@ const MentionsPopup = /*#__PURE__*/forwardRef((props, ref) => {
19
20
  theme,
20
21
  index,
21
22
  target,
22
- chars,
23
+ chars: allChars,
23
24
  mentions,
24
25
  setMentions,
25
26
  type,
@@ -35,11 +36,19 @@ const MentionsPopup = /*#__PURE__*/forwardRef((props, ref) => {
35
36
  const editor = useSlate();
36
37
  const ListElement = POPUP_LIST_TYPES[type] || null;
37
38
  const [anchorEl, setAnchorEl] = useState(null);
39
+ const [nodeType, setNodeType] = useState(null);
38
40
  let open = Boolean(anchorEl);
39
41
  let prevGroup = "";
40
42
  const {
41
43
  setOpenAI
42
44
  } = useEditorContext();
45
+ const chars = allChars.filter(f => {
46
+ if (f.hideFor) {
47
+ return f.hideFor.indexOf(nodeType) === -1;
48
+ } else {
49
+ return true;
50
+ }
51
+ });
43
52
  useEffect(() => {
44
53
  const s = checkTypings(editor);
45
54
  if (s?.type !== mentions.type) {
@@ -55,9 +64,11 @@ const MentionsPopup = /*#__PURE__*/forwardRef((props, ref) => {
55
64
  }, [editor?.selection]);
56
65
  useEffect(() => {
57
66
  try {
58
- if (target && chars.length > 0) {
67
+ const onNodeType = canOpen(editor);
68
+ if (target && chars.length > 0 && onNodeType !== false) {
59
69
  const domRange = ReactEditor.toDOMRange(editor, target);
60
70
  const rect = domRange?.getBoundingClientRect();
71
+ setNodeType(onNodeType);
61
72
  setAnchorEl({
62
73
  clientWidth: rect.width,
63
74
  clientHeight: rect.height,
@@ -14,6 +14,7 @@ import { SectionSettingIcon } from "../iconListV2";
14
14
  // const list_types = ["orderedList", "unorderedList"];
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ const SECTION_PROPS = ["sectionBgColor", "sectionBackgroundImage", "sectionBannerSpacing", "sectionBorderRadius", "sectionGridSize", "sectionAlignment"];
17
18
  const Toolbar = ({
18
19
  readOnly,
19
20
  showTool,
@@ -118,11 +119,26 @@ const Section = props => {
118
119
  ...data
119
120
  };
120
121
  delete updateData.children;
121
- Transforms.setNodes(editor, {
122
- ...updateData
123
- }, {
124
- at: path
125
- });
122
+ if (element.type !== "paragraph") {
123
+ // remove section properties
124
+ Transforms.unsetNodes(editor, SECTION_PROPS, {
125
+ at: path
126
+ });
127
+ // wrap with paragraph with section properties
128
+ Transforms.wrapNodes(editor, {
129
+ ...updateData,
130
+ type: "paragraph",
131
+ children: []
132
+ }, {
133
+ at: path
134
+ });
135
+ } else {
136
+ Transforms.setNodes(editor, {
137
+ ...updateData
138
+ }, {
139
+ at: path
140
+ });
141
+ }
126
142
  onClose();
127
143
  };
128
144
  const onClose = () => {
@@ -15,6 +15,7 @@ import { Transforms } from "slate";
15
15
  import { insertInfinityAI } from "../../utils/infinityAI";
16
16
  import { insertDataView } from "../../utils/dataView";
17
17
  import SearchButton from "../../Elements/Search/SearchButton";
18
+ import canOpen from "../../helper/canOpen";
18
19
  import { jsx as _jsx } from "react/jsx-runtime";
19
20
  const ELEMENTS_LIST = [{
20
21
  name: "Heading 1",
@@ -208,7 +209,8 @@ const ELEMENTS_LIST = [{
208
209
  Transforms.delete(editor, editor.selection);
209
210
  const table = new TableUtil(editor);
210
211
  table.insertTable(3, 3);
211
- }
212
+ },
213
+ hideFor: ["table", "dataView"]
212
214
  }, {
213
215
  name: "Emoji",
214
216
  group: "Elements",
@@ -350,14 +352,17 @@ const ELEMENTS_LIST = [{
350
352
  onInsert: editor => {
351
353
  Transforms.delete(editor, editor.selection);
352
354
  insertDataView(editor);
353
- }
355
+ },
356
+ hideFor: ["table", "dataView"]
354
357
  }];
355
358
  const elements = props => {
356
359
  const {
357
360
  search,
358
361
  hideTools,
359
- translation
362
+ translation,
363
+ editor
360
364
  } = props;
365
+ const nodeType = canOpen(editor);
361
366
  const translatedElements = ELEMENTS_LIST.map(element => ({
362
367
  ...element,
363
368
  name: translation(element.name),
@@ -368,7 +373,7 @@ const elements = props => {
368
373
  });
369
374
  } : undefined
370
375
  }));
371
- const filteredElements = translatedElements.filter(f => (hideTools || []).indexOf(f.type) === -1);
376
+ const filteredElements = translatedElements.filter(f => (hideTools || []).indexOf(f.type) === -1 && (!f?.hideFor || f?.hideFor?.indexOf(nodeType) === -1));
372
377
  return filteredElements.filter(c => c.name.toLowerCase().includes(search?.toLowerCase()));
373
378
  };
374
379
  export default elements;
@@ -0,0 +1,18 @@
1
+ import { Editor, Element } from "slate";
2
+ const INVALID_TYPES = ["title"];
3
+ const canOpen = editor => {
4
+ try {
5
+ const [nodeEntry] = Editor.nodes(editor, {
6
+ at: editor.selection,
7
+ match: n => Element.isElement(n)
8
+ });
9
+ if (nodeEntry && nodeEntry[0]) {
10
+ const [node] = nodeEntry;
11
+ return INVALID_TYPES.indexOf(node.type) === -1 ? node.type : false;
12
+ }
13
+ } catch (err) {
14
+ console.log(err);
15
+ return true;
16
+ }
17
+ };
18
+ export default canOpen;
@@ -62,7 +62,6 @@ export const toggleBlock = (editor, format, selection = true, attr = {}) => {
62
62
  const isList = list_types.includes(format);
63
63
  const isIndent = alignment.includes(format);
64
64
  const isAligned = alignment.some(alignmentType => isBlockActive(editor, alignmentType));
65
- console.log(isAligned, isIndent);
66
65
 
67
66
  /*If the node is already aligned and change in indent is called we should unwrap it first and split the node to prevent
68
67
  messy, nested DOM structure and bugs due to that.*/
@@ -75,29 +74,10 @@ export const toggleBlock = (editor, format, selection = true, attr = {}) => {
75
74
 
76
75
  /* Wraping the nodes for alignment, to allow it to co-exist with other block level operations*/
77
76
  if (isIndent) {
78
- const [nodeEntry] = Editor.nodes(editor, {
79
- at: editor.selection,
80
- match: n => Element.isElement(n) && NEWLINESAFTER.indexOf(n.type) > -1
77
+ Transforms.wrapNodes(editor, {
78
+ type: format,
79
+ children: []
81
80
  });
82
- // for heading background preserve while alignment change
83
- if (nodeEntry) {
84
- // for headings alone
85
- Transforms.wrapNodes(editor, {
86
- type: format,
87
- children: []
88
- }, {
89
- at: editor.selection,
90
- match: n => {
91
- return Text.isText(n);
92
- }
93
- });
94
- } else {
95
- // follow old logic
96
- Transforms.wrapNodes(editor, {
97
- type: format,
98
- children: []
99
- });
100
- }
101
81
  return;
102
82
  }
103
83
  Transforms.unwrapNodes(editor, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "9.4.8",
3
+ "version": "9.5.0",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"