@flozy/editor 5.8.0 → 5.8.2
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.
- package/dist/Editor/Elements/Table/Table.js +3 -3
- package/dist/Editor/Elements/Table/TableCell.js +14 -9
- package/dist/Editor/Elements/Variables/Style.js +2 -1
- package/dist/Editor/Elements/Variables/VariableButton.js +10 -1
- package/dist/Editor/MiniEditor.js +4 -2
- package/dist/Editor/common/Section/index.js +39 -29
- package/dist/Editor/helper/ensureWrappedVariables.js +28 -0
- package/dist/Editor/plugins/withHTML.js +8 -8
- package/dist/Editor/utils/customHooks/useTableResize.js +2 -1
- package/dist/Editor/utils/table.js +21 -0
- package/package.json +2 -2
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Editor, Transforms } from "slate";
|
3
3
|
import { ReactEditor, useSelected, useSlateStatic } from "slate-react";
|
4
4
|
import { Box, IconButton, Tooltip, Table as TableComp, TableBody, useTheme, Popper, ClickAwayListener } from "@mui/material";
|
5
|
-
import { TableUtil } from "../../utils/table";
|
5
|
+
import { TableUtil, getTableColumns, getTableRows } from "../../utils/table";
|
6
6
|
import TablePopup from "./TablePopup";
|
7
7
|
import { useEditorContext, useEditorSelection } from "../../hooks/useMouseMove";
|
8
8
|
import TableStyles from "./Styles";
|
@@ -206,7 +206,7 @@ const Table = props => {
|
|
206
206
|
}
|
207
207
|
}, theme);
|
208
208
|
const addRow = () => {
|
209
|
-
const lastRow = element
|
209
|
+
const lastRow = getTableRows(element) - 1;
|
210
210
|
const firstCol = 0;
|
211
211
|
const lastRowPath = [...path, lastRow, firstCol];
|
212
212
|
const position = Editor.start(editor, lastRowPath);
|
@@ -221,7 +221,7 @@ const Table = props => {
|
|
221
221
|
Transforms.deselect(editor);
|
222
222
|
};
|
223
223
|
const addCol = () => {
|
224
|
-
const lastCol = element
|
224
|
+
const lastCol = getTableColumns(element) - 1;
|
225
225
|
const firstRow = 0;
|
226
226
|
const lastColumnPath = [...path, firstRow, lastCol];
|
227
227
|
const position = Editor.start(editor, lastColumnPath);
|
@@ -50,6 +50,7 @@ const TableCell = props => {
|
|
50
50
|
const {
|
51
51
|
readOnly
|
52
52
|
} = customProps;
|
53
|
+
const isMobile = window.matchMedia("(max-width: 899px)")?.matches || false;
|
53
54
|
const {
|
54
55
|
bgColor,
|
55
56
|
borderColor,
|
@@ -247,20 +248,24 @@ const TableCell = props => {
|
|
247
248
|
isDragging: false
|
248
249
|
});
|
249
250
|
};
|
250
|
-
const
|
251
|
-
|
252
|
-
|
251
|
+
const eventProps = isMobile ? {
|
252
|
+
// mobile events for selection
|
253
|
+
onTouchStart: onMouseDownInCell,
|
254
|
+
onTouchMove: handleTouchMove,
|
255
|
+
onTouchEnd: handleTouchEnd
|
253
256
|
} : {
|
254
|
-
...commonTdProps,
|
255
257
|
onMouseEnter: () => onMouseEnter(path),
|
256
258
|
onMouseLeave,
|
257
259
|
onMouseDown: onMouseDownInCell,
|
258
260
|
onMouseUp,
|
259
|
-
onClick
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
261
|
+
onClick
|
262
|
+
};
|
263
|
+
const tbProps = tableResizing || resizing || over || readOnly ? {
|
264
|
+
...commonTdProps,
|
265
|
+
contentEditable: false
|
266
|
+
} : {
|
267
|
+
...commonTdProps,
|
268
|
+
...eventProps
|
264
269
|
};
|
265
270
|
const dndProps = {
|
266
271
|
id: cellId,
|
@@ -39,7 +39,8 @@ const VariableStyles = theme => ({
|
|
39
39
|
},
|
40
40
|
"& .MuiPaper-root": {
|
41
41
|
borderRadius: '8px',
|
42
|
-
backgroundColor: `${theme?.palette?.editor?.miniToolBarBackground} !important
|
42
|
+
backgroundColor: `${theme?.palette?.editor?.miniToolBarBackground} !important`,
|
43
|
+
marginTop: '5px'
|
43
44
|
},
|
44
45
|
"& .MuiList-root": {
|
45
46
|
padding: '0px'
|
@@ -34,7 +34,8 @@ const VariableButton = props => {
|
|
34
34
|
PaperProps: {
|
35
35
|
style: {
|
36
36
|
maxHeight: 300,
|
37
|
-
overflowY: "auto"
|
37
|
+
overflowY: "auto",
|
38
|
+
transformOrigin: 'top left'
|
38
39
|
},
|
39
40
|
sx: {
|
40
41
|
"&::-webkit-scrollbar-track": {
|
@@ -44,6 +45,14 @@ const VariableButton = props => {
|
|
44
45
|
borderRadius: "16px"
|
45
46
|
}
|
46
47
|
}
|
48
|
+
},
|
49
|
+
anchorOrigin: {
|
50
|
+
vertical: 'bottom',
|
51
|
+
horizontal: 'right'
|
52
|
+
},
|
53
|
+
transformOrigin: {
|
54
|
+
vertical: 'top',
|
55
|
+
horizontal: 'right'
|
47
56
|
}
|
48
57
|
},
|
49
58
|
children: [/*#__PURE__*/_jsx(MenuItem, {
|
@@ -11,6 +11,7 @@ import withCommon from "./hooks/withCommon";
|
|
11
11
|
import { serializeToText } from "./utils/serializeToText";
|
12
12
|
import "./Editor.css";
|
13
13
|
import { EditorProvider } from "./hooks/useMouseMove";
|
14
|
+
import { ensureWrappedVariables } from "./helper/ensureWrappedVariables";
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
15
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
16
17
|
const MiniEditor = props => {
|
@@ -36,7 +37,8 @@ const MiniEditor = props => {
|
|
36
37
|
needLayout: false
|
37
38
|
}));
|
38
39
|
const [isInteracted, setIsInteracted] = useState(false);
|
39
|
-
const
|
40
|
+
const updatedContent = ensureWrappedVariables(content);
|
41
|
+
const [value, setValue] = useState(ensureWrappedVariables(updatedContent));
|
40
42
|
const [deboundedValue] = useDebounce(value, 500);
|
41
43
|
const isReadOnly = readOnly === "readonly";
|
42
44
|
const customProps = {
|
@@ -149,7 +151,7 @@ const MiniEditor = props => {
|
|
149
151
|
theme: theme,
|
150
152
|
children: /*#__PURE__*/_jsxs(Slate, {
|
151
153
|
editor: editor,
|
152
|
-
initialValue:
|
154
|
+
initialValue: updatedContent,
|
153
155
|
onChange: onChange,
|
154
156
|
children: [/*#__PURE__*/_jsx(BasicToolbar, {
|
155
157
|
...props,
|
@@ -13,6 +13,35 @@ import { SectionSettingIcon } from "../iconListV2";
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
14
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
15
15
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
16
|
+
const Toolbar = ({
|
17
|
+
fromPopper,
|
18
|
+
readOnly,
|
19
|
+
showTool,
|
20
|
+
onSettings
|
21
|
+
}) => {
|
22
|
+
return !readOnly && !showTool ? /*#__PURE__*/_jsx(Box, {
|
23
|
+
component: "div",
|
24
|
+
className: `element-toolbar no-border-button hr section-tw sectionIcon`,
|
25
|
+
contentEditable: false,
|
26
|
+
style: fromPopper ? {
|
27
|
+
position: "unset",
|
28
|
+
marginLeft: "28px",
|
29
|
+
paddingTop: "4px",
|
30
|
+
marginRight: "10px",
|
31
|
+
height: "100%"
|
32
|
+
} : {
|
33
|
+
left: "-28px",
|
34
|
+
top: "1px"
|
35
|
+
},
|
36
|
+
children: /*#__PURE__*/_jsx(Tooltip, {
|
37
|
+
title: "Section Settings",
|
38
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
39
|
+
onClick: onSettings,
|
40
|
+
children: /*#__PURE__*/_jsx(SectionSettingIcon, {})
|
41
|
+
})
|
42
|
+
})
|
43
|
+
}) : null;
|
44
|
+
};
|
16
45
|
const list_types = ["orderedList", "unorderedList"];
|
17
46
|
const Section = props => {
|
18
47
|
const themeReact = useTheme();
|
@@ -57,32 +86,6 @@ const Section = props => {
|
|
57
86
|
const onSettings = () => {
|
58
87
|
setOpenSettings(true);
|
59
88
|
};
|
60
|
-
const Toolbar = ({
|
61
|
-
fromPopper
|
62
|
-
}) => {
|
63
|
-
return !readOnly && !showTool ? /*#__PURE__*/_jsx(Box, {
|
64
|
-
component: "div",
|
65
|
-
className: `element-toolbar no-border-button hr section-tw sectionIcon`,
|
66
|
-
contentEditable: false,
|
67
|
-
style: fromPopper ? {
|
68
|
-
position: "unset",
|
69
|
-
marginLeft: "28px",
|
70
|
-
paddingTop: "4px",
|
71
|
-
marginRight: "10px",
|
72
|
-
height: "100%"
|
73
|
-
} : {
|
74
|
-
left: "-28px",
|
75
|
-
top: "1px"
|
76
|
-
},
|
77
|
-
children: /*#__PURE__*/_jsx(Tooltip, {
|
78
|
-
title: "Section Settings",
|
79
|
-
children: /*#__PURE__*/_jsx(IconButton, {
|
80
|
-
onClick: onSettings,
|
81
|
-
children: /*#__PURE__*/_jsx(SectionSettingIcon, {})
|
82
|
-
})
|
83
|
-
})
|
84
|
-
}) : null;
|
85
|
-
};
|
86
89
|
const onSave = data => {
|
87
90
|
const updateData = {
|
88
91
|
...data
|
@@ -167,19 +170,26 @@ const Section = props => {
|
|
167
170
|
bgcolor: "background.paper",
|
168
171
|
height: "30px",
|
169
172
|
position: "relative",
|
170
|
-
background: theme?.palette?.type ===
|
173
|
+
background: theme?.palette?.type === "dark" ? theme?.palette?.editor?.miniToolBarBackground : "#F6F6F6"
|
171
174
|
},
|
172
175
|
children: [!readOnly && !showTool ? /*#__PURE__*/_jsx(DragHandle, {
|
173
176
|
...props,
|
174
177
|
fromPopper: true
|
175
178
|
}) : null, /*#__PURE__*/_jsx(Toolbar, {
|
176
|
-
fromPopper: true
|
179
|
+
fromPopper: true,
|
180
|
+
readOnly: readOnly,
|
181
|
+
showTool: showTool,
|
182
|
+
onSettings: onSettings
|
177
183
|
})]
|
178
184
|
})
|
179
185
|
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
180
186
|
children: [!readOnly && !showTool ? /*#__PURE__*/_jsx(DragHandle, {
|
181
187
|
...props
|
182
|
-
}) : null, /*#__PURE__*/_jsx(Toolbar, {
|
188
|
+
}) : null, /*#__PURE__*/_jsx(Toolbar, {
|
189
|
+
readOnly: readOnly,
|
190
|
+
showTool: showTool,
|
191
|
+
onSettings: onSettings
|
192
|
+
})]
|
183
193
|
}), children]
|
184
194
|
}), openSetttings ? /*#__PURE__*/_jsx(SectionPopup, {
|
185
195
|
element: {
|
@@ -0,0 +1,28 @@
|
|
1
|
+
export const ensureWrappedVariables = content => {
|
2
|
+
return content.map(node => {
|
3
|
+
if (node.children) {
|
4
|
+
return {
|
5
|
+
...node,
|
6
|
+
children: node.children.reduce((result, child, index, arr) => {
|
7
|
+
if (child.type === "variables") {
|
8
|
+
if (index === 0 || !arr[index - 1].text || arr[index - 1].text.trim() === "") {
|
9
|
+
result.push({
|
10
|
+
text: ""
|
11
|
+
});
|
12
|
+
}
|
13
|
+
result.push(child);
|
14
|
+
if (index === arr.length - 1 || !arr[index + 1]?.text || arr[index + 1]?.text.trim() === "") {
|
15
|
+
result.push({
|
16
|
+
text: ""
|
17
|
+
});
|
18
|
+
}
|
19
|
+
} else {
|
20
|
+
result.push(child);
|
21
|
+
}
|
22
|
+
return result;
|
23
|
+
}, [])
|
24
|
+
};
|
25
|
+
}
|
26
|
+
return node;
|
27
|
+
});
|
28
|
+
};
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { Transforms, Editor, Element, Node, Path } from "slate";
|
2
2
|
import deserialize from "../helper/deserialize";
|
3
3
|
import { decodeAndParseBase64 } from "../utils/helper";
|
4
|
-
import convertMDToHTML from "../helper/markdown";
|
4
|
+
// import convertMDToHTML from "../helper/markdown";
|
5
|
+
|
5
6
|
const avoidDefaultInsert = ["table", "grid"];
|
6
7
|
const NON_TEXT_TAGS = ["ol", "ul", "img", "table", "video", "a", "button", "GOOGLE-SHEETS-HTML-ORIGIN"];
|
7
8
|
const ALLOWED_TEXT_NODES = ["paragraph", "title", "headingOne", "headingTwo", "headingThree"];
|
@@ -275,15 +276,14 @@ const withHtml = editor => {
|
|
275
276
|
Transforms.insertFragment(editor, formattedFragment);
|
276
277
|
return;
|
277
278
|
} else {
|
278
|
-
const html = convertMDToHTML(data.getData("text/plain"));
|
279
|
-
let parsed = new DOMParser().parseFromString(html, "text/html");
|
280
|
-
parsed = parseCopiedHTML(html);
|
281
|
-
const fragment = deserialize(parsed.body);
|
282
|
-
Transforms.insertFragment(editor, fragment);
|
283
|
-
|
279
|
+
// const html = convertMDToHTML(data.getData("text/plain"));
|
280
|
+
// let parsed = new DOMParser().parseFromString(html, "text/html");
|
281
|
+
// parsed = parseCopiedHTML(html);
|
282
|
+
// const fragment = deserialize(parsed.body);
|
283
|
+
// Transforms.insertFragment(editor, fragment);
|
284
|
+
insertData(data);
|
284
285
|
}
|
285
286
|
};
|
286
|
-
|
287
287
|
return editor;
|
288
288
|
};
|
289
289
|
export default withHtml;
|
@@ -43,7 +43,8 @@ const useTableResize = ({
|
|
43
43
|
minWidth
|
44
44
|
} = minMaxProps || {};
|
45
45
|
setSize(currentSize => {
|
46
|
-
const
|
46
|
+
const width = currentSize?.width || parentDOM?.clientWidth;
|
47
|
+
const calcWidth = width + e.movementX;
|
47
48
|
return {
|
48
49
|
width: minWidth && calcWidth < minWidth ? minWidth : calcWidth,
|
49
50
|
height: currentSize.height + e.movementY,
|
@@ -753,4 +753,25 @@ export const clearCellText = (editor, currentCellPath) => {
|
|
753
753
|
} catch (err) {
|
754
754
|
console.log(err);
|
755
755
|
}
|
756
|
+
};
|
757
|
+
export const getTableColumns = element => {
|
758
|
+
const {
|
759
|
+
columns,
|
760
|
+
children
|
761
|
+
} = element || {};
|
762
|
+
if (columns) {
|
763
|
+
return columns;
|
764
|
+
}
|
765
|
+
const firstRow = children?.length ? children[0] : {};
|
766
|
+
return firstRow?.children?.length || 0;
|
767
|
+
};
|
768
|
+
export const getTableRows = element => {
|
769
|
+
const {
|
770
|
+
rows,
|
771
|
+
children
|
772
|
+
} = element || {};
|
773
|
+
if (rows) {
|
774
|
+
return rows;
|
775
|
+
}
|
776
|
+
return children?.length || 0;
|
756
777
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flozy/editor",
|
3
|
-
"version": "5.8.
|
3
|
+
"version": "5.8.2",
|
4
4
|
"description": "An Editor for flozy app brain",
|
5
5
|
"files": [
|
6
6
|
"dist"
|
@@ -69,7 +69,7 @@
|
|
69
69
|
"storybook": "storybook dev -p 6006",
|
70
70
|
"build-storybook": "NODE_OPTIONS='--max_old_space_size=4096' storybook build",
|
71
71
|
"publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
|
72
|
-
"publish:local": "rm -rf /Users/
|
72
|
+
"publish:local": "rm -rf /Users/agmac03/flozy/client/node_modules/@flozy/editor/dist && babel src/components -d /Users/agmac03/flozy/client/node_modules/@flozy/editor/dist --copy-files"
|
73
73
|
},
|
74
74
|
"eslintConfig": {
|
75
75
|
"extends": [
|