@flozy/editor 4.9.4 → 4.9.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor/ChatEditor.js +25 -34
- package/dist/Editor/Editor.css +25 -7
- package/dist/Editor/Elements/AI/AIInput.js +0 -1
- package/dist/Editor/Elements/AI/Styles.js +7 -7
- package/dist/Editor/Elements/Link/LinkButton.js +1 -1
- package/dist/Editor/Elements/Search/SearchButton.js +4 -4
- package/dist/Editor/Elements/Search/SearchList.js +7 -5
- package/dist/Editor/Elements/Signature/SignaturePopup.js +3 -2
- package/dist/Editor/Elements/Table/AddRowCol.js +3 -2
- package/dist/Editor/Elements/Table/DragButton.js +6 -2
- package/dist/Editor/Elements/Table/DragStyles.js +62 -36
- package/dist/Editor/Elements/Table/Styles.js +1 -1
- package/dist/Editor/Elements/Table/Table.js +8 -3
- package/dist/Editor/Elements/Table/TableCell.js +24 -10
- package/dist/Editor/Elements/Table/tableHelper.js +83 -0
- package/dist/Editor/Toolbar/FormatTools/Dropdown.js +2 -0
- package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +2 -0
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +3 -3
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +133 -31
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +2 -0
- package/dist/Editor/common/ColorPickerButton.js +3 -2
- package/dist/Editor/common/MentionsPopup/Styles.js +1 -7
- package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +1 -0
- package/dist/Editor/common/RnD/index.js +1 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +5 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +10 -2
- package/dist/Editor/common/Uploader.js +8 -0
- package/dist/Editor/common/iconListV2.js +2 -0
- package/dist/Editor/common/iconslist.js +1 -0
- package/dist/Editor/commonStyle.js +6 -2
- package/dist/Editor/helper/deserialize/index.js +5 -11
- package/dist/Editor/hooks/useTable.js +37 -30
- package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +14 -0
- package/dist/Editor/utils/events.js +0 -1
- package/dist/Editor/utils/helper.js +11 -0
- package/dist/Editor/utils/serializeToText.js +2 -0
- package/package.json +1 -1
@@ -1,9 +1,8 @@
|
|
1
1
|
import React, { useCallback, useMemo, useRef, useState, useEffect, useImperativeHandle, forwardRef } from "react";
|
2
2
|
import { Editable, Slate, ReactEditor } from 'slate-react';
|
3
3
|
import { createEditor, Transforms, Editor } from 'slate';
|
4
|
-
import { useDebounce } from "use-debounce";
|
5
4
|
import withCommon from "./hooks/withCommon";
|
6
|
-
import { getBlock, getMarked } from "./utils/chatEditor/SlateUtilityFunctions";
|
5
|
+
import { getBlock, getMarked, serializeMentions } from "./utils/chatEditor/SlateUtilityFunctions";
|
7
6
|
import MiniTextFormat from "./Toolbar/PopupTool/MiniTextFormat";
|
8
7
|
import { commands, mentionsEvent } from "./utils/events";
|
9
8
|
import { insertEmoji } from "./utils/emoji";
|
@@ -15,6 +14,7 @@ import Shorthands from "./common/Shorthands";
|
|
15
14
|
import usePopupStyle from "./Toolbar/PopupTool/PopupToolStyle";
|
16
15
|
import { EditorProvider } from "./hooks/useMouseMove";
|
17
16
|
import decorators from "./utils/Decorators";
|
17
|
+
import { useDebouncedCallback } from "use-debounce";
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
19
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
20
20
|
const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
@@ -42,8 +42,18 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
42
42
|
});
|
43
43
|
const [isInteracted, setIsInteracted] = useState(false);
|
44
44
|
const [value, setValue] = useState(convertedContent);
|
45
|
-
const
|
46
|
-
const
|
45
|
+
const debouncedValue = useRef(value);
|
46
|
+
const debounced = useDebouncedCallback(
|
47
|
+
// function
|
48
|
+
value => {
|
49
|
+
const {
|
50
|
+
value: strVal,
|
51
|
+
...restVal
|
52
|
+
} = getOnSaveData(value);
|
53
|
+
onSave(strVal, restVal);
|
54
|
+
},
|
55
|
+
// delay in ms
|
56
|
+
500);
|
47
57
|
const editor = useMemo(() => {
|
48
58
|
return withCommon(createEditor(), {
|
49
59
|
needLayout,
|
@@ -63,7 +73,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
63
73
|
const {
|
64
74
|
value: strVal,
|
65
75
|
...restVal
|
66
|
-
} = getOnSaveData(
|
76
|
+
} = getOnSaveData(debouncedValue?.current);
|
67
77
|
onsubmit(false, {
|
68
78
|
strVal,
|
69
79
|
restVal
|
@@ -99,7 +109,8 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
99
109
|
const newValue = draftToSlate({
|
100
110
|
data: content
|
101
111
|
});
|
102
|
-
|
112
|
+
debounced(newValue);
|
113
|
+
|
103
114
|
// setTimeout(() => {
|
104
115
|
if (editor.children.length === 0) {
|
105
116
|
Transforms.insertNodes(editor, newValue);
|
@@ -112,27 +123,14 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
112
123
|
}
|
113
124
|
}
|
114
125
|
}));
|
115
|
-
|
116
|
-
// useEffect(() => {
|
117
|
-
// setIsExternalUpdate(true);
|
118
|
-
// setValue(draftToSlate({ data: content }));
|
119
|
-
// }, [content]);
|
120
|
-
|
121
|
-
useEffect(() => {
|
122
|
-
if (JSON.stringify(loadedValue) !== JSON.stringify(deboundedValue) && isInteracted && onSave) {
|
123
|
-
const {
|
124
|
-
value: strVal,
|
125
|
-
...restVal
|
126
|
-
} = getOnSaveData(deboundedValue);
|
127
|
-
onSave(strVal, restVal);
|
128
|
-
}
|
129
|
-
}, [deboundedValue]);
|
130
126
|
const getOnSaveData = val => {
|
131
127
|
const text = serializeToText(val);
|
128
|
+
const mentions = serializeMentions(val);
|
132
129
|
const title = val?.find(f => f.type === "title");
|
133
130
|
return {
|
134
131
|
value: JSON.stringify(val),
|
135
132
|
text: text,
|
133
|
+
mentions: mentions,
|
136
134
|
title: serializeToText(title?.children) || "Untitled"
|
137
135
|
};
|
138
136
|
};
|
@@ -180,15 +178,8 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
180
178
|
});
|
181
179
|
};
|
182
180
|
const handleEditorChange = newValue => {
|
183
|
-
|
184
|
-
|
185
|
-
const {
|
186
|
-
value: strVal,
|
187
|
-
...restVal
|
188
|
-
} = getOnSaveData(newValue);
|
189
|
-
onSave(strVal, restVal);
|
190
|
-
}
|
191
|
-
setValue(newValue);
|
181
|
+
debounced(newValue);
|
182
|
+
debouncedValue.current = newValue;
|
192
183
|
if (!isInteracted) {
|
193
184
|
setIsInteracted(true);
|
194
185
|
}
|
@@ -228,7 +219,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
228
219
|
editor
|
229
220
|
});
|
230
221
|
} else if (event.key === "Enter" && !isMobile) {
|
231
|
-
const isEmpty =
|
222
|
+
const isEmpty = debouncedValue?.current.length === 1 && debouncedValue?.current[0].type === 'paragraph' && debouncedValue?.current[0].children.length === 1 && debouncedValue?.current[0].children[0].text === '';
|
232
223
|
if (isEmpty) {
|
233
224
|
event.preventDefault();
|
234
225
|
return;
|
@@ -237,7 +228,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
237
228
|
const {
|
238
229
|
value: strVal,
|
239
230
|
...restVal
|
240
|
-
} = getOnSaveData(
|
231
|
+
} = getOnSaveData(debouncedValue?.current);
|
241
232
|
onsubmit(false, {
|
242
233
|
strVal,
|
243
234
|
restVal
|
@@ -251,7 +242,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
251
242
|
const {
|
252
243
|
value: strVal,
|
253
244
|
...restVal
|
254
|
-
} = getOnSaveData(
|
245
|
+
} = getOnSaveData(debouncedValue?.current);
|
255
246
|
onBlur({
|
256
247
|
strVal,
|
257
248
|
restVal
|
@@ -272,7 +263,7 @@ const ChatEditor = /*#__PURE__*/forwardRef((props, ref) => {
|
|
272
263
|
editor: editor,
|
273
264
|
children: /*#__PURE__*/_jsxs(Slate, {
|
274
265
|
editor: editor,
|
275
|
-
initialValue:
|
266
|
+
initialValue: debouncedValue?.current,
|
276
267
|
onChange: handleEditorChange,
|
277
268
|
children: [toolBar && /*#__PURE__*/_jsx(MiniTextFormat, {
|
278
269
|
classes: classes,
|
package/dist/Editor/Editor.css
CHANGED
@@ -399,7 +399,7 @@ blockquote {
|
|
399
399
|
align-items: center;
|
400
400
|
border-width: 0px, 0px, 0px, 0px;
|
401
401
|
border-style: solid;
|
402
|
-
border-color: #
|
402
|
+
border-color: #2563EB66;
|
403
403
|
justify-content: center;
|
404
404
|
flex-direction: column;
|
405
405
|
width: 100%;
|
@@ -492,9 +492,9 @@ blockquote {
|
|
492
492
|
|
493
493
|
.MuiButton-root.primaryBtn.disabled,
|
494
494
|
.MuiButton-root.secondaryBtn.disabled {
|
495
|
-
background: #eee
|
496
|
-
color: #ccc
|
497
|
-
border: 1px solid #ccc
|
495
|
+
background: #eee;
|
496
|
+
color: #ccc;
|
497
|
+
border: 1px solid #ccc;
|
498
498
|
}
|
499
499
|
|
500
500
|
.MuiButton-root.secondaryBtn {
|
@@ -622,7 +622,21 @@ blockquote {
|
|
622
622
|
}
|
623
623
|
|
624
624
|
.MuiIconButton-root.btnActive {
|
625
|
-
|
625
|
+
svg path {
|
626
|
+
stroke: #2563EB;
|
627
|
+
}
|
628
|
+
|
629
|
+
svg text,
|
630
|
+
svg circle,
|
631
|
+
.fill-svg,
|
632
|
+
.fill-path,
|
633
|
+
.fill-path path {
|
634
|
+
fill: #2563EB;
|
635
|
+
}
|
636
|
+
|
637
|
+
path.fill-path {
|
638
|
+
stroke: none;
|
639
|
+
}
|
626
640
|
}
|
627
641
|
|
628
642
|
.embed .element-toolbar {
|
@@ -1221,7 +1235,10 @@ blockquote {
|
|
1221
1235
|
@media (max-width: 899px) {
|
1222
1236
|
.MuiPopover-root {
|
1223
1237
|
z-index: 1302 !important;
|
1224
|
-
}
|
1238
|
+
}
|
1239
|
+
canvas {
|
1240
|
+
max-width: 100% !important;
|
1241
|
+
}
|
1225
1242
|
}
|
1226
1243
|
|
1227
1244
|
.settingsHeader {
|
@@ -1242,4 +1259,5 @@ blockquote {
|
|
1242
1259
|
|
1243
1260
|
.hideScroll::-webkit-scrollbar-thumb:hover {
|
1244
1261
|
background: none !important;
|
1245
|
-
}
|
1262
|
+
}
|
1263
|
+
|
@@ -71,7 +71,6 @@ function AIInput({
|
|
71
71
|
}, [openAI]);
|
72
72
|
const isSendBtnDisabled = !inputValue || loading;
|
73
73
|
const props = getProps(openAI, generatedText) || {};
|
74
|
-
const fromToolBar = openAI === "fromToolBar";
|
75
74
|
const handleSendBtnClick = () => {
|
76
75
|
if (isSendBtnDisabled) {
|
77
76
|
return;
|
@@ -142,13 +142,13 @@ const Styles = theme => ({
|
|
142
142
|
gap: "8px"
|
143
143
|
},
|
144
144
|
"&:hover": {
|
145
|
-
backgroundColor: `${theme?.palette?.editor?.menuOptionSelectedOption} !important
|
146
|
-
|
147
|
-
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
}
|
145
|
+
backgroundColor: `${theme?.palette?.editor?.menuOptionSelectedOption} !important`
|
146
|
+
},
|
147
|
+
"& svg path": {
|
148
|
+
stroke: `${theme?.palette?.editor?.menuOptionTextColor} !important`
|
149
|
+
},
|
150
|
+
"& svg": {
|
151
|
+
color: `${theme?.palette?.editor?.menuOptionTextColor} !important`
|
152
152
|
},
|
153
153
|
"&.active": {
|
154
154
|
background: `${theme?.palette?.containers?.bg3 || "#E9F3FE"}`,
|
@@ -64,7 +64,7 @@ const LinkButton = props => {
|
|
64
64
|
title: "Link",
|
65
65
|
arrow: true,
|
66
66
|
children: /*#__PURE__*/_jsx(IconButton, {
|
67
|
-
className: `${showInput ? "clicked" : ""} ${isActive ? "btnActive" : ""}`,
|
67
|
+
className: `${showInput ? "clicked btnActive" : ""} ${isActive ? "btnActive" : ""}`,
|
68
68
|
format: "link",
|
69
69
|
onClick: toggleLink,
|
70
70
|
children: /*#__PURE__*/_jsx(Icon, {
|
@@ -110,8 +110,8 @@ const SearchButton = /*#__PURE__*/forwardRef((props, ref) => {
|
|
110
110
|
children: /*#__PURE__*/_jsx(Paper, {
|
111
111
|
sx: {
|
112
112
|
width: '100%',
|
113
|
-
background: theme?.palette?.
|
114
|
-
borderColor: theme?.palette?.type === 'dark' ? theme?.palette?.
|
113
|
+
background: theme?.palette?.editor?.miniToolBarBackground,
|
114
|
+
borderColor: theme?.palette?.type === 'dark' ? theme?.palette?.editor?.popUpBorderColor : 'transparent'
|
115
115
|
},
|
116
116
|
children: /*#__PURE__*/_jsx(SearchAndDocList, {
|
117
117
|
mapData: mapData,
|
@@ -143,9 +143,9 @@ const SearchButton = /*#__PURE__*/forwardRef((props, ref) => {
|
|
143
143
|
sx: {
|
144
144
|
padding: 0,
|
145
145
|
width: '330px',
|
146
|
-
background: theme?.palette?.
|
146
|
+
background: theme?.palette?.editor?.miniToolBarBackground,
|
147
147
|
border: '1px solid',
|
148
|
-
borderColor: theme?.palette?.type === 'dark' ? theme?.palette?.
|
148
|
+
borderColor: theme?.palette?.type === 'dark' ? theme?.palette?.editor?.popUpBorderColor : 'transparent',
|
149
149
|
borderRadius: '12px',
|
150
150
|
'&.MuiPaper-root-MuiPopover-paper': {
|
151
151
|
borderRadius: '12px !important'
|
@@ -36,7 +36,7 @@ const SearchAndDocList = ({
|
|
36
36
|
sx: {
|
37
37
|
borderRadius: "6px",
|
38
38
|
backgroundColor: theme?.palette?.containers?.bg7,
|
39
|
-
border: theme?.palette?.type === 'dark' ? `1px solid ${theme?.palette?.
|
39
|
+
border: theme?.palette?.type === 'dark' ? `1px solid ${theme?.palette?.editor?.popUpBorderColor}` : '',
|
40
40
|
padding: "5px",
|
41
41
|
"&:hover": {
|
42
42
|
backgroundColor: theme?.palette?.containers?.bg8,
|
@@ -111,24 +111,27 @@ const SearchAndDocList = ({
|
|
111
111
|
maxHeight: '400px',
|
112
112
|
minWidth: "275px",
|
113
113
|
overflowY: 'auto',
|
114
|
+
overflowX: 'hidden',
|
114
115
|
padding: '0px 16px 8px',
|
115
116
|
marginBottom: '20px',
|
116
117
|
scrollbarWidth: "thin",
|
117
118
|
scrollbarColor: `${theme?.palette?.primary?.slashBrainBorder} transparent`,
|
118
119
|
"&::-webkit-scrollbar": {
|
119
120
|
width: "3px",
|
120
|
-
height: "3px !important"
|
121
|
+
height: "3px !important",
|
122
|
+
borderRadius: "10px"
|
121
123
|
},
|
122
124
|
"&::-webkit-scrollbar-thumb": {
|
123
125
|
backgroundColor: theme?.palette?.primary?.slashBrainBorder,
|
124
|
-
borderRadius: "
|
126
|
+
borderRadius: "10px",
|
125
127
|
width: "3px !important"
|
126
128
|
},
|
127
129
|
"&::-webkit-scrollbar-thumb:hover": {
|
128
130
|
backgroundColor: theme?.palette?.primary?.slashBrainBorder
|
129
131
|
},
|
130
132
|
"&::-webkit-scrollbar-track": {
|
131
|
-
background: "transparent"
|
133
|
+
background: "transparent",
|
134
|
+
borderRadius: "10px"
|
132
135
|
}
|
133
136
|
},
|
134
137
|
children: [mapData?.map((doc, index) => {
|
@@ -206,7 +209,6 @@ const SearchAndDocList = ({
|
|
206
209
|
justifyContent: "center",
|
207
210
|
alignItems: 'center',
|
208
211
|
sx: {
|
209
|
-
minWidth: "330px",
|
210
212
|
minHeight: '400px',
|
211
213
|
padding: '0px 16px 8px',
|
212
214
|
position: 'absolute'
|
@@ -471,7 +471,8 @@ const SignaturePopup = props => {
|
|
471
471
|
classes: classes,
|
472
472
|
value: brush.color,
|
473
473
|
onSave: onBrushColor,
|
474
|
-
recentColors: []
|
474
|
+
recentColors: [],
|
475
|
+
hideGradient: true
|
475
476
|
}), /*#__PURE__*/_jsx("span", {
|
476
477
|
style: {
|
477
478
|
marginLeft: "10px",
|
@@ -515,7 +516,7 @@ const SignaturePopup = props => {
|
|
515
516
|
children: "Delete"
|
516
517
|
}) : null, /*#__PURE__*/_jsx(Button, {
|
517
518
|
onClick: handleSave,
|
518
|
-
className: `primaryBtn actionBtn ${isEmpty ? "disabled" : ""}`,
|
519
|
+
className: `primaryBtn actionBtn ${isEmpty ? "disabled disabledSaveBtn" : ""}`,
|
519
520
|
disabled: isEmpty,
|
520
521
|
children: "Save"
|
521
522
|
})]
|
@@ -59,11 +59,12 @@ function AddRowCol(props) {
|
|
59
59
|
children: /*#__PURE__*/_jsx(Button, {
|
60
60
|
sx: {
|
61
61
|
fontSize: "14px",
|
62
|
-
border: "1px
|
63
|
-
color: "#2563EB",
|
62
|
+
border: "1px dashed #8DA8E3",
|
63
|
+
color: "#2563EB !important",
|
64
64
|
padding: "0px 4px",
|
65
65
|
minWidth: "unset",
|
66
66
|
lineHeight: "18px",
|
67
|
+
fontWeight: "lighter !important",
|
67
68
|
...buttonStyle,
|
68
69
|
opacity: showBtn ? 1 : 0
|
69
70
|
},
|
@@ -73,7 +73,7 @@ function DragButton({
|
|
73
73
|
modifiers: [{
|
74
74
|
name: "offset",
|
75
75
|
options: {
|
76
|
-
offset: [0, -
|
76
|
+
offset: [0, -12]
|
77
77
|
}
|
78
78
|
}, {
|
79
79
|
name: "flip",
|
@@ -81,7 +81,7 @@ function DragButton({
|
|
81
81
|
}],
|
82
82
|
|
83
83
|
disablePortal: dragType !== "row",
|
84
|
-
className: className
|
84
|
+
className: `${className}`,
|
85
85
|
children: ({
|
86
86
|
TransitionProps
|
87
87
|
}) => /*#__PURE__*/_jsx(Fade, {
|
@@ -94,6 +94,10 @@ function DragButton({
|
|
94
94
|
sx: dragType === "row" ? {
|
95
95
|
transform: "rotate(90deg)"
|
96
96
|
} : {},
|
97
|
+
className: `${showTool ? "active" : ""}`,
|
98
|
+
style: {
|
99
|
+
lineHeight: 0
|
100
|
+
},
|
97
101
|
children: /*#__PURE__*/_jsx(IconButton, {
|
98
102
|
onClick: () => {
|
99
103
|
onDragClick();
|
@@ -1,43 +1,69 @@
|
|
1
|
-
const DragStyles = theme =>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
const DragStyles = theme => {
|
2
|
+
const {
|
3
|
+
containers,
|
4
|
+
editor
|
5
|
+
} = theme?.palette || {};
|
6
|
+
const {
|
7
|
+
buttonBorder,
|
8
|
+
background,
|
9
|
+
activeColor,
|
10
|
+
signaturePopUpTabButtonSelectedBg,
|
11
|
+
signaturePopUpTabButtonSelectedSvg
|
12
|
+
} = editor || {};
|
13
|
+
const onDragActive = {
|
14
|
+
outline: `1.5px solid ${activeColor || "#2563EB"}`,
|
15
|
+
background: `${signaturePopUpTabButtonSelectedBg} !important`,
|
16
|
+
"& svg ellipse": {
|
17
|
+
fill: `${signaturePopUpTabButtonSelectedSvg}`
|
18
|
+
}
|
19
|
+
};
|
20
|
+
return {
|
21
|
+
popper: {
|
22
|
+
zIndex: 1000,
|
23
|
+
"& .MuiPaper-root": {
|
24
|
+
borderRadius: "3px !important",
|
25
|
+
outline: `1.5px solid ${buttonBorder}`,
|
26
|
+
backgroundColor: `${background}`,
|
27
|
+
"&:hover": onDragActive,
|
28
|
+
"&.active": onDragActive
|
29
|
+
},
|
30
|
+
"& .MuiIconButton-root": {
|
31
|
+
padding: "4px 6px",
|
32
|
+
borderRadius: "none",
|
33
|
+
"& .dragIcon": {
|
34
|
+
width: "14px",
|
35
|
+
height: "10px"
|
36
|
+
},
|
37
|
+
"&:hover": {
|
38
|
+
background: "none"
|
39
|
+
}
|
8
40
|
}
|
9
41
|
},
|
10
|
-
|
11
|
-
|
12
|
-
"
|
13
|
-
|
42
|
+
toolPopper: {
|
43
|
+
zIndex: 4001,
|
44
|
+
"& .MuiPaper-root": {
|
45
|
+
borderRadius: "8px"
|
14
46
|
}
|
15
|
-
}
|
16
|
-
},
|
17
|
-
toolPopper: {
|
18
|
-
zIndex: 4001,
|
19
|
-
"& .MuiPaper-root": {
|
20
|
-
borderRadius: "8px"
|
21
|
-
}
|
22
|
-
},
|
23
|
-
mobileToolDrawer: {
|
24
|
-
"& .customSelectContainer": {
|
25
|
-
border: "none !important",
|
26
|
-
padding: "0px !important"
|
27
|
-
}
|
28
|
-
},
|
29
|
-
drawerContainer: {
|
30
|
-
"&.MuiDrawer-root": {
|
31
|
-
zIndex: 1301
|
32
47
|
},
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
48
|
+
mobileToolDrawer: {
|
49
|
+
"& .customSelectContainer": {
|
50
|
+
border: "none !important",
|
51
|
+
padding: "0px !important"
|
52
|
+
}
|
37
53
|
},
|
38
|
-
|
39
|
-
|
54
|
+
drawerContainer: {
|
55
|
+
"&.MuiDrawer-root": {
|
56
|
+
zIndex: 1301
|
57
|
+
},
|
58
|
+
"& .MuiDrawer-paper": {
|
59
|
+
borderTopLeftRadius: 8,
|
60
|
+
borderTopRightRadius: 8,
|
61
|
+
backgroundColor: containers?.card
|
62
|
+
},
|
63
|
+
"& .customSelectContainer": {
|
64
|
+
border: "none"
|
65
|
+
}
|
40
66
|
}
|
41
|
-
}
|
42
|
-
}
|
67
|
+
};
|
68
|
+
};
|
43
69
|
export default DragStyles;
|
@@ -8,7 +8,7 @@ import { useEditorContext, useEditorSelection } from "../../hooks/useMouseMove";
|
|
8
8
|
import TableStyles from "./Styles";
|
9
9
|
import "./table.css";
|
10
10
|
import { groupByBreakpoint } from "../../helper/theme";
|
11
|
-
import { TableProvider } from "../../hooks/useTable";
|
11
|
+
import useTable, { TableProvider } from "../../hooks/useTable";
|
12
12
|
import AddRowCol from "./AddRowCol";
|
13
13
|
import TableTool from "./TableTool";
|
14
14
|
import { useDebouncedCallback } from "use-debounce";
|
@@ -30,7 +30,11 @@ const ToolBar = props => {
|
|
30
30
|
handleAction,
|
31
31
|
exandTools
|
32
32
|
} = props;
|
33
|
-
|
33
|
+
const {
|
34
|
+
getSelectedCells
|
35
|
+
} = useTable();
|
36
|
+
const viewTool = selected && !showTool && getSelectedCells()?.length <= 1;
|
37
|
+
return viewTool ? /*#__PURE__*/_jsxs(Box, {
|
34
38
|
component: "div",
|
35
39
|
contentEditable: false,
|
36
40
|
className: `tableToolBar ${exandTools ? "active" : ""}`,
|
@@ -185,7 +189,8 @@ const Table = props => {
|
|
185
189
|
return /*#__PURE__*/_jsxs(TableProvider, {
|
186
190
|
editor: editor,
|
187
191
|
otherProps: {
|
188
|
-
dragRowBtnCls
|
192
|
+
dragRowBtnCls,
|
193
|
+
tablePath: path
|
189
194
|
},
|
190
195
|
children: [/*#__PURE__*/_jsxs("div", {
|
191
196
|
style: {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
1
|
+
import React, { useState, useEffect, useMemo } from "react";
|
2
2
|
import { Editor, Element, Path, Transforms } from "slate";
|
3
3
|
import { Box } from "@mui/material";
|
4
4
|
import { useSlateStatic, ReactEditor } from "slate-react";
|
@@ -190,11 +190,19 @@ const TableCell = props => {
|
|
190
190
|
if (!contentEditable) {
|
191
191
|
e.preventDefault();
|
192
192
|
}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
193
|
+
if (
|
194
|
+
// for shift selection
|
195
|
+
e.shiftKey && startCellPath?.length && startCellPath.toString() !== path.toString()) {
|
196
|
+
updateTableSelection({
|
197
|
+
endCellPath: path
|
198
|
+
});
|
199
|
+
} else {
|
200
|
+
updateTableSelection({
|
201
|
+
startCellPath: path,
|
202
|
+
endCellPath: [],
|
203
|
+
isDragging: true
|
204
|
+
});
|
205
|
+
}
|
198
206
|
};
|
199
207
|
const onMouseUp = e => {
|
200
208
|
if (startCellPath?.length) {
|
@@ -211,6 +219,7 @@ const TableCell = props => {
|
|
211
219
|
const isCellSelected = selectionPath?.length && Path.equals(selectionPath, path);
|
212
220
|
if (!isCellSelected) {
|
213
221
|
// focus the clicked cell
|
222
|
+
ReactEditor.focus(editor);
|
214
223
|
Transforms.select(editor, {
|
215
224
|
anchor: Editor.end(editor, path),
|
216
225
|
focus: Editor.end(editor, path)
|
@@ -225,10 +234,15 @@ const TableCell = props => {
|
|
225
234
|
const cellId = path.toString() + "table-cell";
|
226
235
|
const cellRef = document.getElementById(cellId);
|
227
236
|
const contentEditable = !readOnly && isCellEditable(startCellPath, path);
|
228
|
-
const commonTdProps = {
|
229
|
-
|
230
|
-
|
231
|
-
|
237
|
+
const commonTdProps = useMemo(() => {
|
238
|
+
const props = {
|
239
|
+
id: cellId
|
240
|
+
};
|
241
|
+
if (!contentEditable) {
|
242
|
+
props.contentEditable = false;
|
243
|
+
}
|
244
|
+
return props;
|
245
|
+
}, [contentEditable, cellId]);
|
232
246
|
const handleTouchMove = e => {
|
233
247
|
const touch = e.touches[0]; // Get the current touch point
|
234
248
|
const element = document.elementFromPoint(touch.clientX, touch.clientY);
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { getNode } from "../../utils/helper";
|
2
|
+
import { serializeToText } from "../../utils/serializeToText";
|
3
|
+
export const getRectangleBounds = tableSelection => {
|
4
|
+
const {
|
5
|
+
startCellPath,
|
6
|
+
endCellPath
|
7
|
+
} = tableSelection;
|
8
|
+
if (!startCellPath?.length) return [];
|
9
|
+
const startPath = startCellPath.slice(0, -2);
|
10
|
+
const startCell = startCellPath.slice(-2);
|
11
|
+
const endCell = endCellPath.slice(-2);
|
12
|
+
const [startRow, startCol] = startCell;
|
13
|
+
const [endRow, endCol] = endCell?.length ? endCell : startCell;
|
14
|
+
const minRow = Math.min(startRow, endRow);
|
15
|
+
const maxRow = Math.max(startRow, endRow);
|
16
|
+
const minCol = Math.min(startCol, endCol);
|
17
|
+
const maxCol = Math.max(startCol, endCol);
|
18
|
+
const selectedPaths = [];
|
19
|
+
for (let row = minRow; row <= maxRow; row++) {
|
20
|
+
for (let col = minCol; col <= maxCol; col++) {
|
21
|
+
selectedPaths.push([...startPath, row, col]);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return selectedPaths;
|
25
|
+
};
|
26
|
+
export const createCopiedTableStructure = (editor, tableSelection, currentTableNode, tablePath, selectedText) => {
|
27
|
+
const selectedCells = getRectangleBounds(tableSelection);
|
28
|
+
const formattedCells = selectedCells.map(cell => cell.slice(-2));
|
29
|
+
const tableChild = [];
|
30
|
+
const rowIndexes = [...new Set(formattedCells.map(cell => cell[0]))];
|
31
|
+
rowIndexes.forEach((rowIndex, row_i) => {
|
32
|
+
const row = {
|
33
|
+
type: "table-row",
|
34
|
+
children: []
|
35
|
+
};
|
36
|
+
|
37
|
+
// Filter cells that belong to the current row
|
38
|
+
const cellsInRow = formattedCells.filter(cell => cell[0] === rowIndex);
|
39
|
+
|
40
|
+
// Iterate over the columns of the row to create table cells
|
41
|
+
const columnIndexes = [...new Set(cellsInRow.map(cell => cell[1]))];
|
42
|
+
columnIndexes.forEach((columnIndex, col_i) => {
|
43
|
+
const cellPath = [...tablePath, rowIndex, columnIndex];
|
44
|
+
const columnNode = getNode(editor, cellPath);
|
45
|
+
const cellNode = selectedText // we can select text in only one column
|
46
|
+
? {
|
47
|
+
...columnNode,
|
48
|
+
type: "table-cell",
|
49
|
+
children: [{
|
50
|
+
type: "paragraph",
|
51
|
+
children: [{
|
52
|
+
text: selectedText
|
53
|
+
}],
|
54
|
+
cellBgColor: "#FFFFFF"
|
55
|
+
}]
|
56
|
+
} : columnNode;
|
57
|
+
row.children.push(cellNode);
|
58
|
+
});
|
59
|
+
tableChild.push(row);
|
60
|
+
});
|
61
|
+
const table = {
|
62
|
+
...currentTableNode,
|
63
|
+
children: tableChild,
|
64
|
+
rows: rowIndexes?.length,
|
65
|
+
columns: tableChild[0]?.children?.length // first row's children length
|
66
|
+
};
|
67
|
+
|
68
|
+
return table;
|
69
|
+
};
|
70
|
+
export const tableNodeToDom = (tableNode, selectedText) => {
|
71
|
+
const tableEle = document.createElement("table");
|
72
|
+
tableNode.children?.forEach(row => {
|
73
|
+
const rowEle = document.createElement("tr");
|
74
|
+
row?.children?.forEach(cell => {
|
75
|
+
const cellEle = document.createElement("td");
|
76
|
+
const cellText = selectedText || serializeToText(cell);
|
77
|
+
cellEle.innerHTML = cellText;
|
78
|
+
rowEle.appendChild(cellEle);
|
79
|
+
});
|
80
|
+
tableEle.appendChild(rowEle);
|
81
|
+
});
|
82
|
+
return tableEle;
|
83
|
+
};
|