@flozy/editor 1.8.6 → 1.8.8

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.
@@ -18,7 +18,7 @@ const Attachments = props => {
18
18
  date
19
19
  } = element;
20
20
  const getLastName = url?.split("/").pop();
21
- const fileName = `${decodeURI(getLastName)}`;
21
+ const fileName = `${decodeURIComponent(getLastName)}`;
22
22
  return /*#__PURE__*/_jsxs(Box, {
23
23
  component: "div",
24
24
  className: "attachment-wrpr-ev2",
@@ -63,7 +63,7 @@ const Image = ({
63
63
  const selected = hoverPath === path.join(",");
64
64
  useEffect(() => {
65
65
  if (editor && ele && ele[1] !== undefined) {
66
- const dom = ReactEditor.toDOMNode(editor, Node.get(editor, ele[1]));
66
+ const dom = ReactEditor.toDOMNode(editor, element);
67
67
  setParentDOM(dom);
68
68
  onLoad(element?.size || {});
69
69
  }
@@ -97,13 +97,22 @@ const editorStyles = ({
97
97
  justifyContent: "center",
98
98
  alignItems: "center",
99
99
  position: "relative",
100
+ padding: "0px 12px",
100
101
  "&:hover": {
101
102
  "& .ed-section-inner": {
102
103
  "& .element-toolbar.ss": {
103
104
  display: "block",
104
105
  left: "8px",
105
106
  top: "8px",
106
- width: "fit-content"
107
+ width: "fit-content",
108
+ "& button": {
109
+ boxShadow: "none",
110
+ color: "rgb(85, 85, 85)",
111
+ background: "rgb(221, 221, 221, 0.1)",
112
+ "&:hover": {
113
+ background: "rgb(221, 221, 221, 0.8)"
114
+ }
115
+ }
107
116
  }
108
117
  },
109
118
  "&.hselect:before": {
@@ -14,7 +14,7 @@ const AddElements = props => {
14
14
  const {
15
15
  hideTools
16
16
  } = customProps;
17
- const filteredElements = elements.filter(f => hideTools.indexOf(f.type) === -1);
17
+ const filteredElements = elements.filter(f => (hideTools || []).indexOf(f.type) === -1);
18
18
  return /*#__PURE__*/_jsx(Grid, {
19
19
  container: true,
20
20
  sx: classes.textFormatWrapper,
@@ -12,7 +12,7 @@ const DragHandleStyle = () => ({
12
12
  root: {
13
13
  position: "relative",
14
14
  "&:hover": {
15
- "& > .dh-para:first-child": {
15
+ "& > .dh-para:first-of-type": {
16
16
  opacity: 1
17
17
  }
18
18
  },
@@ -74,7 +74,6 @@ const DragHandle = props => {
74
74
  if (moved) {
75
75
  const upPath = ReactEditor.findPath(editor, element);
76
76
  try {
77
- alert(upPath);
78
77
  Transforms.removeNodes(editor, {
79
78
  at: upPath
80
79
  });
@@ -89,7 +88,7 @@ const DragHandle = props => {
89
88
  return canDraggable ? /*#__PURE__*/_jsxs(Box, {
90
89
  ...attributes,
91
90
  component: "div",
92
- className: `${dragging ? "dragging" : ""}`,
91
+ className: `drag-wrpr ${dragging ? "dragging" : ""}`,
93
92
  sx: classes.root,
94
93
  children: [/*#__PURE__*/_jsx(Droppable, {
95
94
  id: id,
@@ -0,0 +1,100 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { ReactEditor, useSlateStatic } from "slate-react";
3
+ import { Box } from "@mui/material";
4
+ import Draggable from "./Draggable";
5
+ import Droppable from "./Droppable";
6
+ import { useEditorContext } from "../../hooks/useMouseMove";
7
+ import { Transforms } from "slate";
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ const DRAGGABLE_TYPES = ["paragraph", "headingOne", "headinTwo", "headingThree", "grid"];
11
+ const DragHandleStyle = () => ({
12
+ dragHandle: {
13
+ opacity: 0,
14
+ content: '" "',
15
+ position: "absolute",
16
+ top: "2px",
17
+ left: "-52px",
18
+ borderRadius: "0px",
19
+ padding: "0px",
20
+ width: "20px",
21
+ height: "20px",
22
+ border: 0,
23
+ display: "flex",
24
+ alignItems: "center",
25
+ justifyContent: "center",
26
+ cursor: "grab",
27
+ color: "rgb(85, 85, 85)",
28
+ background: "rgb(221, 221, 221, 0.1)",
29
+ "& svg": {
30
+ width: "20px"
31
+ },
32
+ "&:hover": {
33
+ opacity: 1,
34
+ background: "rgb(221, 221, 221, 0.8)"
35
+ },
36
+ "&.active": {
37
+ opacity: 1,
38
+ cursor: "grabbing"
39
+ }
40
+ },
41
+ dropArea: {
42
+ position: "absolute",
43
+ left: 0,
44
+ top: 0,
45
+ width: "100%",
46
+ height: "100%",
47
+ "&.dragging": {
48
+ backgroundColor: "#def4ff"
49
+ }
50
+ },
51
+ dropAreaOver: {
52
+ height: "4px"
53
+ }
54
+ });
55
+ const DragHandle = props => {
56
+ const classes = DragHandleStyle();
57
+ const editor = useSlateStatic();
58
+ const [dragging, setDragging] = useState(false);
59
+ const {
60
+ element
61
+ } = props;
62
+ const path = ReactEditor.findPath(editor, element);
63
+ const canDraggable = DRAGGABLE_TYPES.indexOf(element?.type) > -1;
64
+ const id = `${element.type}_${[...path].join("|")}`;
65
+ const {
66
+ moved
67
+ } = element;
68
+ const {
69
+ drop
70
+ } = useEditorContext();
71
+ useEffect(() => {
72
+ if (moved) {
73
+ const upPath = ReactEditor.findPath(editor, element);
74
+ try {
75
+ Transforms.removeNodes(editor, {
76
+ at: upPath
77
+ });
78
+ } catch (err) {
79
+ console.log(err, upPath);
80
+ }
81
+ }
82
+ }, [moved]);
83
+ const handleOnDrag = isDragging => {
84
+ setDragging(isDragging);
85
+ };
86
+ return canDraggable ? /*#__PURE__*/_jsxs("div", {
87
+ children: [/*#__PURE__*/_jsx(Box, {
88
+ className: dragging ? "dragging" : "",
89
+ sx: classes.dropArea
90
+ }), /*#__PURE__*/_jsx(Droppable, {
91
+ id: id,
92
+ classes: classes
93
+ }), /*#__PURE__*/_jsx(Draggable, {
94
+ id: id,
95
+ classes: classes,
96
+ onDrag: handleOnDrag
97
+ })]
98
+ }, `${id}_${drop}`) : null;
99
+ };
100
+ export default DragHandle;
@@ -14,7 +14,7 @@ const Droppable = props => {
14
14
  id: id
15
15
  });
16
16
  const dropStyle = {
17
- backgroundColor: isOver ? "green" : undefined
17
+ backgroundColor: isOver ? "#47bbf5" : undefined
18
18
  };
19
19
  return /*#__PURE__*/_jsx(Box, {
20
20
  ref: setNodeRef,
@@ -22,7 +22,7 @@ const Droppable = props => {
22
22
  className: `droppable-para`,
23
23
  contentEditable: false,
24
24
  style: dropStyle,
25
- sx: classes.dropArea
25
+ sx: classes.dropAreaOver
26
26
  });
27
27
  };
28
28
  export default Droppable;
@@ -5,9 +5,25 @@ import { Box, IconButton, Tooltip } from "@mui/material";
5
5
  import TuneIcon from "@mui/icons-material/Tune";
6
6
  import SectionPopup from "../../Elements/Grid/SectionPopup";
7
7
  import { getBreakPointsValue, getTRBLBreakPoints } from "../../helper/theme";
8
+ import DragHandle from "../DnD/DragHandleButton";
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ const SectionStyle = () => ({
12
+ root: {
13
+ "&:hover": {
14
+ "& .dh-para": {
15
+ opacity: 1
16
+ }
17
+ },
18
+ "& .element-toolbar": {
19
+ "&:hover": {
20
+ display: "block"
21
+ }
22
+ }
23
+ }
24
+ });
10
25
  const Section = props => {
26
+ const classes = SectionStyle();
11
27
  const {
12
28
  children,
13
29
  element,
@@ -86,6 +102,7 @@ const Section = props => {
86
102
  component: "section",
87
103
  className: `ed-section-wrapper ${readOnly ? "" : "hselect"} ${needHover}`,
88
104
  sx: {
105
+ ...classes.root,
89
106
  background: sectionBgColor,
90
107
  ...sectionBgImage,
91
108
  padding: {
@@ -104,7 +121,9 @@ const Section = props => {
104
121
  ...getBreakPointsValue(sectionGridSize || 8, null, "overrideGridSize", true)
105
122
  }
106
123
  },
107
- children: [children, /*#__PURE__*/_jsx(Toolbar, {})]
124
+ children: [/*#__PURE__*/_jsx(DragHandle, {
125
+ ...props
126
+ }), children, /*#__PURE__*/_jsx(Toolbar, {})]
108
127
  }), openSetttings ? /*#__PURE__*/_jsx(SectionPopup, {
109
128
  element: {
110
129
  ...element,
@@ -206,7 +206,7 @@ const elements = props => {
206
206
  search,
207
207
  hideTools
208
208
  } = props;
209
- const filteredElements = ELEMENTS_LIST.filter(f => hideTools.indexOf(f.type) === -1);
209
+ const filteredElements = ELEMENTS_LIST.filter(f => (hideTools || []).indexOf(f.type) === -1);
210
210
  return filteredElements.filter(c => c.name.toLowerCase().includes(search?.toLowerCase()));
211
211
  };
212
212
  export default elements;
@@ -17,14 +17,14 @@ const StyleContent = props => {
17
17
  } = props;
18
18
  const {
19
19
  hideTools
20
- } = customProps;
20
+ } = customProps || {};
21
21
  const tabContent = renderTabs.find(f => f.value === value);
22
22
  const {
23
23
  fields
24
24
  } = tabContent || {
25
25
  fields: []
26
26
  };
27
- const filteredFields = hideTools?.length > 0 ? fields.filter(f => hideTools.indexOf(f.key) === -1) : fields;
27
+ const filteredFields = (hideTools || [])?.length > 0 ? fields.filter(f => (hideTools || []).indexOf(f.key) === -1) : fields;
28
28
  return /*#__PURE__*/_jsx(Grid, {
29
29
  container: true,
30
30
  spacing: 2,
@@ -37,6 +37,7 @@ import { isEmptyTextNode } from "../helper";
37
37
  import Attachments from "../Elements/Attachments/Attachments";
38
38
  import { getBreakPointsValue } from "../helper/theme";
39
39
  import Variables from "../Elements/Variables/Variable";
40
+ import insertNewLine from "./insertNewLine";
40
41
  import { jsx as _jsx } from "react/jsx-runtime";
41
42
  const alignment = ["alignLeft", "alignRight", "alignCenter"];
42
43
  const list_types = ["orderedList", "unorderedList"];
@@ -44,6 +45,7 @@ const LIST_FORMAT_TYPE = {
44
45
  orderedList: "list-item",
45
46
  unorderedList: "list-item"
46
47
  };
48
+ const NEWLINESAFTER = ["headingOne", "headingTwo", "headingThree"];
47
49
  export const toggleBlock = (editor, format, selection = true, attr = {}) => {
48
50
  const isActive = isBlockActive(editor, format);
49
51
  const isList = list_types.includes(format);
@@ -86,6 +88,9 @@ export const toggleBlock = (editor, format, selection = true, attr = {}) => {
86
88
  children: []
87
89
  });
88
90
  }
91
+ if (NEWLINESAFTER.indexOf(format) > -1) {
92
+ insertNewLine(editor);
93
+ }
89
94
  };
90
95
  export const addMarkData = (editor, data) => {
91
96
  try {
@@ -127,7 +127,12 @@ export const escapeEvent = props => {
127
127
  };
128
128
  export const enterEvent = (e, editor, ele) => {
129
129
  try {
130
- if (ele && ele[0]) {
130
+ // on shift enter break line in same node
131
+ if (e.shiftKey) {
132
+ console.log("shif enter");
133
+ e.preventDefault();
134
+ Transforms.insertText(editor, "\n");
135
+ } else if (ele && ele[0]) {
131
136
  const {
132
137
  type
133
138
  } = ele[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"