@flozy/editor 10.5.8 → 10.6.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.
@@ -92,3 +92,7 @@
92
92
  border-width: 1px 0 0;
93
93
  border-color: rgba(55, 53, 47, .1607843137254902);
94
94
  }
95
+
96
+ .disablePointerEvent {
97
+ pointer-events: none;
98
+ }
@@ -3,7 +3,6 @@ import { Editor, Text } from "slate";
3
3
  import { useSlate } from "slate-react";
4
4
  import { getNodeText } from "../../utils/helper";
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
- import { jsxs as _jsxs } from "react/jsx-runtime";
7
6
  const isEmptyTextNode = node => {
8
7
  if (Text.isText(node)) {
9
8
  return !node.text.trim();
@@ -19,7 +18,7 @@ const Title = props => {
19
18
  } = props;
20
19
  const isEmpty = !customProps?.readOnly && isEmptyTextNode(element?.children[0]) ? "empty" : "";
21
20
  useDetectExitFromTitle(element, customProps?.getTitleSaveData);
22
- return /*#__PURE__*/_jsxs("div", {
21
+ return /*#__PURE__*/_jsx("div", {
23
22
  ...attributes,
24
23
  placeholder: "Title",
25
24
  className: `content-editable ${isEmpty}`,
@@ -27,9 +26,7 @@ const Title = props => {
27
26
  fontWeight: "bold",
28
27
  fontSize: "20px"
29
28
  },
30
- children: [children, /*#__PURE__*/_jsx("span", {
31
- contentEditable: false
32
- })]
29
+ children: children
33
30
  });
34
31
  };
35
32
  export default Title;
@@ -49,7 +49,6 @@ import ColumnView from "../Elements/DataView/Layouts/ColumnView";
49
49
  import SearchAttachment from "../Elements/Search/SearchAttachment";
50
50
  import { wrapThemeBreakpoints } from "../Elements/FreeGrid/breakpointConstants";
51
51
  import { jsx as _jsx } from "react/jsx-runtime";
52
- import { jsxs as _jsxs } from "react/jsx-runtime";
53
52
  const alignment = ["alignLeft", "alignRight", "alignCenter", "alignJustify"];
54
53
  const list_types = ["orderedList", "unorderedList"];
55
54
  const LIST_FORMAT_TYPE = {
@@ -421,52 +420,52 @@ export const getBlock = props => {
421
420
  const selectedLineHeight = getBreakpointLineSpacing(lineH, breakpoint);
422
421
  switch (element.type) {
423
422
  case "headingOne":
424
- return /*#__PURE__*/_jsxs("h1", {
425
- ...commonHeadingProps(),
423
+ return /*#__PURE__*/_jsx("h1", {
424
+ ...attributes,
425
+ ...element.attr,
426
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
426
427
  placeholder: translation("Heading 1"),
427
- children: [children, /*#__PURE__*/_jsx("span", {
428
- contentEditable: false
429
- })]
428
+ children: children
430
429
  });
431
430
  case "headingTwo":
432
- return /*#__PURE__*/_jsxs("h2", {
433
- ...commonHeadingProps(),
431
+ return /*#__PURE__*/_jsx("h2", {
432
+ ...attributes,
433
+ ...element.attr,
434
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
434
435
  placeholder: translation("Heading 2"),
435
- children: [children, /*#__PURE__*/_jsx("span", {
436
- contentEditable: false
437
- })]
436
+ children: children
438
437
  });
439
438
  case "headingThree":
440
- return /*#__PURE__*/_jsxs("h3", {
441
- ...commonHeadingProps(),
439
+ return /*#__PURE__*/_jsx("h3", {
440
+ ...attributes,
441
+ ...element.attr,
442
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
442
443
  placeholder: translation("Heading 3"),
443
- children: [children, /*#__PURE__*/_jsx("span", {
444
- contentEditable: false
445
- })]
444
+ children: children
446
445
  });
447
446
  case "headingFour":
448
- return /*#__PURE__*/_jsxs("h4", {
449
- ...commonHeadingProps(),
447
+ return /*#__PURE__*/_jsx("h4", {
448
+ ...attributes,
449
+ ...element.attr,
450
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
450
451
  placeholder: translation("Heading 4"),
451
- children: [children, /*#__PURE__*/_jsx("span", {
452
- contentEditable: false
453
- })]
452
+ children: children
454
453
  });
455
454
  case "headingFive":
456
- return /*#__PURE__*/_jsxs("h5", {
457
- ...commonHeadingProps(),
455
+ return /*#__PURE__*/_jsx("h5", {
456
+ ...attributes,
457
+ ...element.attr,
458
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
458
459
  placeholder: translation("Heading 5"),
459
- children: [children, /*#__PURE__*/_jsx("span", {
460
- contentEditable: false
461
- })]
460
+ children: children
462
461
  });
463
462
  case "headingSix":
464
- return /*#__PURE__*/_jsxs("h6", {
465
- ...commonHeadingProps(),
463
+ return /*#__PURE__*/_jsx("h6", {
464
+ ...attributes,
465
+ ...element.attr,
466
+ className: `edt-headings content-editable ${isEmpty ? "empty" : ""} disablePointerEvent`,
466
467
  placeholder: translation("Heading 6"),
467
- children: [children, /*#__PURE__*/_jsx("span", {
468
- contentEditable: false
469
- })]
468
+ children: children
470
469
  });
471
470
  case "paragraphOne":
472
471
  return /*#__PURE__*/_jsx("p", {
@@ -1,6 +1,5 @@
1
- import { Editor, Range, Transforms } from "slate";
1
+ import { Editor, Element, Transforms } from "slate";
2
2
  import insertNewLine from "./insertNewLine";
3
- import { getCurrentNodeText, getSelectedText } from "./helper";
4
3
  import { isMobileWindow } from "../helper";
5
4
  const focusAccordion = (editor, upPath) => {
6
5
  Transforms.select(editor, {
@@ -8,77 +7,52 @@ const focusAccordion = (editor, upPath) => {
8
7
  offset: 0
9
8
  });
10
9
  };
11
- function isSelectionInSingleNode(editor) {
12
- const {
13
- anchor,
14
- focus
15
- } = editor.selection;
16
- return Editor.path(editor, anchor).toString() === Editor.path(editor, focus).toString();
17
- }
18
10
  export const insertAccordion = (editor, path) => {
19
11
  try {
20
12
  const {
21
13
  selection
22
14
  } = editor;
23
- const isHavingSelection = selection && !Range.isCollapsed(selection);
24
- const selectedText = isHavingSelection ? getSelectedText(editor) : "";
25
- const isSingleNodeSelected = isHavingSelection && isSelectionInSingleNode(editor);
15
+ if (selection) {
16
+ const selectedNodes = Array.from(Editor.nodes(editor, {
17
+ at: selection,
18
+ match: n => Element.isElement(n),
19
+ mode: "lowest" // use 'lowest' to get individual blocks
20
+ }));
26
21
 
27
- // Fully select the heading text and convert it to an accordion.
28
- // An empty heading is inserted just before the newly created accordion.
29
- let fullySelected = false;
30
- if (isSingleNodeSelected) {
31
- const currentNodeText = selectedText ? getCurrentNodeText(editor) : "";
32
- fullySelected = selectedText?.length && currentNodeText.length === selectedText?.length;
33
- }
34
- const accordion = {
35
- type: "accordion",
36
- children: [{
37
- type: "accordion-summary",
38
- children: [{
39
- type: "paragraph",
40
- children: [{
41
- text: selectedText || ""
42
- }]
43
- }]
44
- }, {
45
- type: "accordion-details",
46
- children: [{
47
- type: "paragraph",
22
+ for (const [node, path] of selectedNodes) {
23
+ const accordion = {
24
+ type: "accordion",
48
25
  children: [{
49
- text: ""
26
+ type: "accordion-summary",
27
+ children: [node]
28
+ }, {
29
+ type: "accordion-details",
30
+ children: [{
31
+ type: "paragraph",
32
+ children: [{
33
+ text: ""
34
+ }]
35
+ }]
50
36
  }]
51
- }]
52
- }]
53
- };
54
- const props = path ? {
55
- at: path,
56
- select: true
57
- } : {
58
- select: true
59
- };
60
- if (fullySelected) {
61
- const insertPath = editor.selection.anchor.path;
62
- Transforms.removeNodes(editor, {
63
- at: insertPath
64
- });
65
- props.at = insertPath;
66
- }
67
- Transforms.insertNodes(editor, accordion, props);
68
- const curPath = [...editor?.selection?.anchor?.path];
69
- const upPath = [...curPath];
70
- // get title index
71
- const summaryIndex = upPath.length - 3;
72
- upPath[summaryIndex] = upPath[summaryIndex] === 0 ? 0 : upPath[summaryIndex] - 1;
73
-
74
- // select accordion title by default
75
- if (isMobileWindow()) {
76
- // timeout to resolve focus issue in mobile
77
- setTimeout(() => focusAccordion(editor, upPath), 0);
78
- } else {
79
- focusAccordion(editor, upPath);
37
+ };
38
+ Transforms.removeNodes(editor, {
39
+ at: path
40
+ });
41
+ Transforms.insertNodes(editor, accordion, {
42
+ at: path
43
+ });
44
+ }
45
+ const lastNode = selectedNodes[selectedNodes.length - 1];
46
+ const lastNodePath = lastNode[1];
47
+ const accordionPath = [...lastNodePath, 0, 0, 0];
48
+ if (isMobileWindow()) {
49
+ // timeout to resolve focus issue in mobile
50
+ setTimeout(() => focusAccordion(editor, accordionPath), 0);
51
+ } else {
52
+ focusAccordion(editor, accordionPath);
53
+ }
54
+ insertNewLine(editor);
80
55
  }
81
- insertNewLine(editor);
82
56
  } catch (err) {
83
57
  console.log(err);
84
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.5.8",
3
+ "version": "10.6.0",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"