@flozy/editor 9.4.8 → 9.4.9

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.
@@ -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,
@@ -208,7 +208,8 @@ const ELEMENTS_LIST = [{
208
208
  Transforms.delete(editor, editor.selection);
209
209
  const table = new TableUtil(editor);
210
210
  table.insertTable(3, 3);
211
- }
211
+ },
212
+ hideFor: ["table", "dataView"]
212
213
  }, {
213
214
  name: "Emoji",
214
215
  group: "Elements",
@@ -350,7 +351,8 @@ const ELEMENTS_LIST = [{
350
351
  onInsert: editor => {
351
352
  Transforms.delete(editor, editor.selection);
352
353
  insertDataView(editor);
353
- }
354
+ },
355
+ hideFor: ["table", "dataView"]
354
356
  }];
355
357
  const elements = props => {
356
358
  const {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "9.4.8",
3
+ "version": "9.4.9",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"