@flozy/editor 1.1.5 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor/CollaborativeEditor.js +6 -1
- package/dist/Editor/CommonEditor.js +17 -3
- package/dist/Editor/Editor.css +15 -3
- package/dist/Editor/Elements/AppHeader/AppHeader.js +221 -0
- package/dist/Editor/Elements/AppHeader/AppHeaderButton.js +19 -0
- package/dist/Editor/Elements/AppHeader/AppHeaderPopup.js +20 -0
- package/dist/Editor/Elements/Button/EditorButton.js +3 -3
- package/dist/Editor/Elements/Carousel/Carousel.js +19 -5
- package/dist/Editor/Elements/Carousel/CarouselItem.js +5 -1
- package/dist/Editor/Elements/ChipText/ChipText.js +44 -0
- package/dist/Editor/Elements/ChipText/ChipTextButton.js +64 -0
- package/dist/Editor/Elements/ChipText/ChipTextPopup.js +24 -0
- package/dist/Editor/Elements/DrawerMenu/DrawerMenu.js +66 -0
- package/dist/Editor/Elements/DrawerMenu/DrawerMenuButton.js +21 -0
- package/dist/Editor/Elements/Link/Link.js +5 -5
- package/dist/Editor/Elements/Link/LinkButton.js +50 -37
- package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +27 -21
- package/dist/Editor/Elements/Table/Table.js +160 -10
- package/dist/Editor/Elements/Table/TableCell.js +55 -143
- package/dist/Editor/Elements/Table/table.css +13 -0
- package/dist/Editor/Toolbar/Toolbar.js +18 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +9 -0
- package/dist/Editor/common/ColorPickerButton.js +65 -0
- package/dist/Editor/common/StyleBuilder/appHeaderStyle.js +63 -0
- package/dist/Editor/common/StyleBuilder/chipTextStyle.js +35 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +8 -14
- package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/menusArray.js +114 -0
- package/dist/Editor/common/StyleBuilder/index.js +8 -3
- package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +20 -0
- package/dist/Editor/plugins/withLinks.js +40 -2
- package/dist/Editor/plugins/withTable.js +10 -1
- package/dist/Editor/utils/SlateUtilityFunctions.js +15 -0
- package/dist/Editor/utils/customHooks/useTableResize.js +46 -0
- package/dist/Editor/utils/insertAppHeader.js +55 -0
- package/dist/Editor/utils/insertChipText.js +49 -0
- package/dist/Editor/utils/insertDrawerMenu.js +52 -0
- package/dist/Editor/utils/serializer.js +26 -16
- package/dist/Editor/utils/table.js +26 -3
- package/package.json +2 -1
@@ -1,8 +1,8 @@
|
|
1
|
-
import React from
|
2
|
-
import { useFocused, useSelected, useSlateStatic } from
|
3
|
-
import { removeLink } from
|
4
|
-
import unlink from
|
5
|
-
import
|
1
|
+
import React from "react";
|
2
|
+
import { useFocused, useSelected, useSlateStatic } from "slate-react";
|
3
|
+
import { removeLink } from "../../utils/link";
|
4
|
+
import unlink from "../../Toolbar/toolbarIcons/unlink.svg";
|
5
|
+
import "./styles.css";
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
7
7
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
8
8
|
const Link = ({
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { useRef, useState } from "react";
|
2
|
+
import { Transforms } from "slate";
|
3
|
+
import { Dialog, DialogActions, DialogContent, DialogTitle, FormControl, FormControlLabel, Grid, TextField, Button, IconButton } from "@mui/material";
|
4
|
+
import { CheckBox } from "@mui/icons-material";
|
2
5
|
import { insertLink } from "../../utils/link";
|
3
|
-
import Button from "../../common/Button";
|
4
6
|
import Icon from "../../common/Icon";
|
5
7
|
import { isBlockActive } from "../../utils/SlateUtilityFunctions";
|
6
|
-
import usePopup from "../../utils/customHooks/usePopup";
|
7
|
-
import { Transforms } from "slate";
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
9
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
10
10
|
const LinkButton = props => {
|
@@ -12,7 +12,7 @@ const LinkButton = props => {
|
|
12
12
|
editor
|
13
13
|
} = props;
|
14
14
|
const linkInputRef = useRef(null);
|
15
|
-
const [showInput, setShowInput] =
|
15
|
+
const [showInput, setShowInput] = useState(false);
|
16
16
|
const [url, setUrl] = useState("");
|
17
17
|
const [showInNewTab, setShowInNewTab] = useState(false);
|
18
18
|
const [selection, setSelection] = useState();
|
@@ -23,62 +23,75 @@ const LinkButton = props => {
|
|
23
23
|
showInNewTab
|
24
24
|
});
|
25
25
|
setUrl("");
|
26
|
-
setShowInput(
|
26
|
+
setShowInput(false);
|
27
27
|
setShowInNewTab(false);
|
28
28
|
};
|
29
29
|
const toggleLink = () => {
|
30
30
|
setSelection(editor.selection);
|
31
|
-
setShowInput(
|
31
|
+
setShowInput(true);
|
32
32
|
};
|
33
33
|
const handleInputChange = ({
|
34
34
|
target
|
35
35
|
}) => {
|
36
36
|
if (target.type === "checkbox") {
|
37
|
-
setShowInNewTab(
|
37
|
+
setShowInNewTab(target.checked);
|
38
38
|
} else {
|
39
39
|
setUrl(target.value);
|
40
40
|
}
|
41
41
|
};
|
42
|
+
const handleClose = () => {
|
43
|
+
setShowInput(false);
|
44
|
+
};
|
42
45
|
return /*#__PURE__*/_jsxs("div", {
|
43
46
|
ref: linkInputRef,
|
44
47
|
className: "popup-wrapper1",
|
45
|
-
children: [/*#__PURE__*/_jsx(
|
48
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
46
49
|
className: showInput ? "clicked" : "",
|
47
|
-
active: isBlockActive(editor, "link"),
|
50
|
+
active: isBlockActive(editor, "link") ? "active" : "",
|
48
51
|
format: "link",
|
49
52
|
onClick: toggleLink,
|
50
53
|
children: /*#__PURE__*/_jsx(Icon, {
|
51
54
|
icon: "link"
|
52
55
|
})
|
53
|
-
}), showInput && /*#__PURE__*/_jsxs(
|
54
|
-
|
55
|
-
children: [/*#__PURE__*/
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
}), showInput && /*#__PURE__*/_jsxs(Dialog, {
|
57
|
+
open: true,
|
58
|
+
children: [/*#__PURE__*/_jsx(DialogTitle, {
|
59
|
+
children: "Link"
|
60
|
+
}), /*#__PURE__*/_jsx(DialogContent, {
|
61
|
+
children: /*#__PURE__*/_jsxs(Grid, {
|
62
|
+
container: true,
|
63
|
+
spacing: 2,
|
64
|
+
children: [/*#__PURE__*/_jsx(Grid, {
|
65
|
+
item: true,
|
66
|
+
xs: 12,
|
67
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
68
|
+
size: "small",
|
69
|
+
fullWidth: true,
|
70
|
+
value: url,
|
71
|
+
placeholder: "https://google.com",
|
72
|
+
onChange: handleInputChange
|
73
|
+
})
|
74
|
+
}), /*#__PURE__*/_jsx(Grid, {
|
75
|
+
item: true,
|
76
|
+
xs: 12,
|
77
|
+
children: /*#__PURE__*/_jsx(FormControl, {
|
78
|
+
children: /*#__PURE__*/_jsx(FormControlLabel, {
|
79
|
+
control: /*#__PURE__*/_jsx(CheckBox, {
|
80
|
+
checked: showInNewTab,
|
81
|
+
onChange: handleInputChange
|
82
|
+
}),
|
83
|
+
label: "Open in new tab"
|
84
|
+
})
|
85
|
+
})
|
86
|
+
})]
|
87
|
+
})
|
88
|
+
}), /*#__PURE__*/_jsxs(DialogActions, {
|
89
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
90
|
+
onClick: handleClose,
|
91
|
+
children: "Cancel"
|
92
|
+
}), /*#__PURE__*/_jsx(Button, {
|
67
93
|
onClick: handleInsertLink,
|
68
|
-
children:
|
69
|
-
icon: "add"
|
70
|
-
})
|
71
|
-
})]
|
72
|
-
}), /*#__PURE__*/_jsxs("label", {
|
73
|
-
children: [/*#__PURE__*/_jsx("input", {
|
74
|
-
type: "checkbox",
|
75
|
-
checked: showInNewTab,
|
76
|
-
onChange: handleInputChange
|
77
|
-
}), /*#__PURE__*/_jsx("span", {
|
78
|
-
style: {
|
79
|
-
fontSize: "0.8em"
|
80
|
-
},
|
81
|
-
children: "Open in new tab"
|
94
|
+
children: "Add"
|
82
95
|
})]
|
83
96
|
})]
|
84
97
|
})]
|
@@ -5,22 +5,23 @@ import ArticleIcon from "@mui/icons-material/Article";
|
|
5
5
|
import { useSlateStatic, ReactEditor } from "slate-react";
|
6
6
|
import PageSettingsPopup from "./PageSettingsPopup";
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
8
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
8
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
10
|
const PageSettingsButton = props => {
|
10
11
|
const {
|
11
12
|
customProps
|
12
13
|
} = props;
|
13
14
|
const [openSetttings, setOpenSettings] = useState(false);
|
14
|
-
const [pageProps, setPageProps] = useState({});
|
15
15
|
const editor = useSlateStatic();
|
16
16
|
const onSettings = () => {
|
17
17
|
const {
|
18
|
-
element
|
18
|
+
element,
|
19
|
+
path
|
19
20
|
} = getPageSettingsPath();
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
21
|
+
setOpenSettings({
|
22
|
+
element: element?.pageProps || {},
|
23
|
+
path
|
24
|
+
});
|
24
25
|
};
|
25
26
|
const getPageSettingsPath = () => {
|
26
27
|
try {
|
@@ -30,11 +31,17 @@ const PageSettingsButton = props => {
|
|
30
31
|
return !Editor.isEditor(n) && Element.isElement(n) && n.type === "page-settings";
|
31
32
|
}
|
32
33
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
if (pageSettingsNode && pageSettingsNode[0]) {
|
35
|
+
const path = ReactEditor.findPath(editor, pageSettingsNode[0]);
|
36
|
+
return {
|
37
|
+
path,
|
38
|
+
element: pageSettingsNode[0]
|
39
|
+
};
|
40
|
+
} else {
|
41
|
+
return {
|
42
|
+
path: null
|
43
|
+
};
|
44
|
+
}
|
38
45
|
} catch (err) {
|
39
46
|
console.log(err);
|
40
47
|
return {
|
@@ -43,20 +50,17 @@ const PageSettingsButton = props => {
|
|
43
50
|
}
|
44
51
|
};
|
45
52
|
const onSave = data => {
|
46
|
-
const {
|
47
|
-
path
|
48
|
-
} = getPageSettingsPath();
|
49
53
|
const updateData = {
|
50
54
|
...data
|
51
55
|
};
|
52
56
|
delete updateData.children;
|
53
|
-
if (path) {
|
57
|
+
if (openSetttings?.path) {
|
54
58
|
Transforms.setNodes(editor, {
|
55
59
|
pageProps: {
|
56
60
|
...updateData
|
57
61
|
}
|
58
62
|
}, {
|
59
|
-
at: path
|
63
|
+
at: openSetttings?.path
|
60
64
|
});
|
61
65
|
} else {
|
62
66
|
Transforms.insertNodes(editor, [{
|
@@ -74,11 +78,13 @@ const PageSettingsButton = props => {
|
|
74
78
|
const onClose = () => {
|
75
79
|
setOpenSettings(false);
|
76
80
|
};
|
77
|
-
return /*#__PURE__*/_jsxs(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
82
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
83
|
+
title: "Page Settings",
|
84
|
+
onClick: onSettings,
|
85
|
+
children: /*#__PURE__*/_jsx(ArticleIcon, {})
|
86
|
+
}), openSetttings !== false ? /*#__PURE__*/_jsx(PageSettingsPopup, {
|
87
|
+
element: openSetttings?.element || {},
|
82
88
|
onSave: onSave,
|
83
89
|
onClose: onClose,
|
84
90
|
customProps: customProps
|
@@ -1,30 +1,180 @@
|
|
1
|
-
import React from "react";
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { Transforms } from "slate";
|
3
|
+
import { useSelected, useSlateStatic } from "slate-react";
|
4
|
+
import { IconButton } from "@mui/material";
|
5
|
+
import AlignHorizontalLeftIcon from "@mui/icons-material/AlignHorizontalLeft";
|
6
|
+
import AlignHorizontalRightIcon from "@mui/icons-material/AlignHorizontalRight";
|
7
|
+
import AlignVerticalTopIcon from "@mui/icons-material/AlignVerticalTop";
|
8
|
+
import AlignVerticalBottomIcon from "@mui/icons-material/AlignVerticalBottom";
|
9
|
+
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
10
|
+
import SettingsIcon from "@mui/icons-material/Settings";
|
11
|
+
import DeleteCellIcon from "./DeleteCellIcon";
|
12
|
+
import DeleteRowIcon from "./DeleteRowIcon";
|
13
|
+
import { TableUtil } from "../../utils/table";
|
14
|
+
import TablePopup from "./TablePopup";
|
15
|
+
import "./table.css";
|
2
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
17
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
18
|
+
const TABLE_MENUS = [{
|
19
|
+
Icon: AlignHorizontalRightIcon,
|
20
|
+
text: "Insert Columns to the Right",
|
21
|
+
action: {
|
22
|
+
type: "insertColumn",
|
23
|
+
position: "after"
|
24
|
+
}
|
25
|
+
}, {
|
26
|
+
Icon: AlignHorizontalLeftIcon,
|
27
|
+
text: "Insert Columns to the Left",
|
28
|
+
action: {
|
29
|
+
type: "insertColumn",
|
30
|
+
position: "at"
|
31
|
+
}
|
32
|
+
}, {
|
33
|
+
Icon: AlignVerticalTopIcon,
|
34
|
+
text: "Insert Row Above",
|
35
|
+
action: {
|
36
|
+
type: "insertRow",
|
37
|
+
positon: "at"
|
38
|
+
}
|
39
|
+
}, {
|
40
|
+
Icon: AlignVerticalBottomIcon,
|
41
|
+
text: "Insert Row Below",
|
42
|
+
action: {
|
43
|
+
type: "insertRow",
|
44
|
+
position: "after"
|
45
|
+
}
|
46
|
+
}, {
|
47
|
+
Icon: DeleteRowIcon,
|
48
|
+
text: "Delete Row",
|
49
|
+
action: {
|
50
|
+
type: "deleteRow"
|
51
|
+
}
|
52
|
+
}, {
|
53
|
+
Icon: DeleteCellIcon,
|
54
|
+
text: "Delete Column",
|
55
|
+
action: {
|
56
|
+
type: "deleteColumn"
|
57
|
+
}
|
58
|
+
}, {
|
59
|
+
Icon: SettingsIcon,
|
60
|
+
text: "Settings",
|
61
|
+
action: {
|
62
|
+
type: "settings"
|
63
|
+
}
|
64
|
+
}, {
|
65
|
+
Icon: DeleteForeverIcon,
|
66
|
+
text: "Remove Table",
|
67
|
+
action: {
|
68
|
+
type: "remove"
|
69
|
+
}
|
70
|
+
}];
|
71
|
+
const Table = props => {
|
72
|
+
const {
|
73
|
+
element,
|
74
|
+
attributes,
|
75
|
+
children,
|
76
|
+
customProps
|
77
|
+
} = props;
|
78
|
+
const [openSetttings, setOpenSettings] = useState(false);
|
8
79
|
const {
|
9
80
|
bgColor,
|
10
81
|
borderColor
|
11
82
|
} = element;
|
12
|
-
|
83
|
+
const editor = useSlateStatic();
|
84
|
+
const selected = useSelected();
|
85
|
+
const table = new TableUtil(editor);
|
86
|
+
const tableProps = table.getTableProps();
|
87
|
+
const handleAction = ({
|
88
|
+
type,
|
89
|
+
position
|
90
|
+
}) => () => {
|
91
|
+
Transforms.select(editor, editor.selection);
|
92
|
+
switch (type) {
|
93
|
+
case "insertRow":
|
94
|
+
table.insertRow(position);
|
95
|
+
break;
|
96
|
+
case "insertColumn":
|
97
|
+
table.insertColumn(position);
|
98
|
+
break;
|
99
|
+
case "deleteRow":
|
100
|
+
table.deleteRow();
|
101
|
+
break;
|
102
|
+
case "deleteColumn":
|
103
|
+
table.deleteColumn();
|
104
|
+
break;
|
105
|
+
case "remove":
|
106
|
+
table.removeTable();
|
107
|
+
break;
|
108
|
+
case "settings":
|
109
|
+
if (tableProps) {
|
110
|
+
onSettings(true);
|
111
|
+
}
|
112
|
+
break;
|
113
|
+
default:
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
};
|
117
|
+
const ToolBar = () => {
|
118
|
+
return selected ? /*#__PURE__*/_jsx("div", {
|
119
|
+
contentEditable: false,
|
120
|
+
style: {
|
121
|
+
position: "absolute",
|
122
|
+
top: "-40px",
|
123
|
+
left: 0,
|
124
|
+
backgroundColor: "#CCC"
|
125
|
+
},
|
126
|
+
children: TABLE_MENUS.map(({
|
127
|
+
Icon,
|
128
|
+
text,
|
129
|
+
action
|
130
|
+
}) => {
|
131
|
+
return /*#__PURE__*/_jsx(IconButton, {
|
132
|
+
title: text,
|
133
|
+
onClick: handleAction(action),
|
134
|
+
children: /*#__PURE__*/_jsx(Icon, {})
|
135
|
+
}, text);
|
136
|
+
})
|
137
|
+
}) : null;
|
138
|
+
};
|
139
|
+
const onSettings = () => {
|
140
|
+
setOpenSettings(true);
|
141
|
+
};
|
142
|
+
const onSave = data => {
|
143
|
+
const updateData = {
|
144
|
+
...data
|
145
|
+
};
|
146
|
+
delete updateData.children;
|
147
|
+
delete updateData.type;
|
148
|
+
table.updateTableStyle(updateData, {
|
149
|
+
...tableProps
|
150
|
+
});
|
151
|
+
onClose();
|
152
|
+
};
|
153
|
+
const onClose = () => {
|
154
|
+
setOpenSettings(false);
|
155
|
+
};
|
156
|
+
return /*#__PURE__*/_jsxs("div", {
|
13
157
|
style: {
|
14
158
|
minWidth: "100%",
|
15
159
|
maxWidth: "100%",
|
16
160
|
position: "relative"
|
17
161
|
},
|
18
|
-
children: /*#__PURE__*/_jsx("table", {
|
162
|
+
children: [/*#__PURE__*/_jsx("table", {
|
19
163
|
style: {
|
20
164
|
backgroundColor: bgColor,
|
21
|
-
border: `1px solid ${borderColor}
|
165
|
+
border: `1px solid ${borderColor}`,
|
166
|
+
width: "auto"
|
22
167
|
},
|
23
168
|
children: /*#__PURE__*/_jsx("tbody", {
|
24
169
|
...attributes,
|
25
170
|
children: children
|
26
171
|
})
|
27
|
-
})
|
172
|
+
}), /*#__PURE__*/_jsx(ToolBar, {}), openSetttings ? /*#__PURE__*/_jsx(TablePopup, {
|
173
|
+
element: tableProps?.styleProps || {},
|
174
|
+
onSave: onSave,
|
175
|
+
onClose: onClose,
|
176
|
+
customProps: customProps
|
177
|
+
}) : null]
|
28
178
|
});
|
29
179
|
};
|
30
180
|
export default Table;
|
@@ -1,89 +1,50 @@
|
|
1
|
-
import React, { useState } from "react";
|
2
|
-
import {
|
1
|
+
import React, { useState, useEffect } from "react";
|
2
|
+
import { Editor, Element } from "slate";
|
3
3
|
import { useSelected, useSlateStatic, ReactEditor } from "slate-react";
|
4
|
-
import
|
5
|
-
import AlignHorizontalLeftIcon from "@mui/icons-material/AlignHorizontalLeft";
|
6
|
-
import AlignHorizontalRightIcon from "@mui/icons-material/AlignHorizontalRight";
|
7
|
-
import AlignVerticalTopIcon from "@mui/icons-material/AlignVerticalTop";
|
8
|
-
import AlignVerticalBottomIcon from "@mui/icons-material/AlignVerticalBottom";
|
9
|
-
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
10
|
-
import SettingsIcon from "@mui/icons-material/Settings";
|
11
|
-
import DeleteCellIcon from "./DeleteCellIcon";
|
12
|
-
import DeleteRowIcon from "./DeleteRowIcon";
|
4
|
+
import useTableResize from "../../utils/customHooks/useTableResize";
|
13
5
|
import { TableUtil } from "../../utils/table";
|
14
|
-
import TablePopup from "./TablePopup";
|
15
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
16
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
17
|
-
const
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
type: "insertRow",
|
36
|
-
positon: "at"
|
37
|
-
}
|
38
|
-
}, {
|
39
|
-
Icon: AlignVerticalBottomIcon,
|
40
|
-
text: "Insert Row Below",
|
41
|
-
action: {
|
42
|
-
type: "insertRow",
|
43
|
-
position: "after"
|
44
|
-
}
|
45
|
-
}, {
|
46
|
-
Icon: DeleteRowIcon,
|
47
|
-
text: "Delete Row",
|
48
|
-
action: {
|
49
|
-
type: "deleteRow"
|
50
|
-
}
|
51
|
-
}, {
|
52
|
-
Icon: DeleteCellIcon,
|
53
|
-
text: "Delete Column",
|
54
|
-
action: {
|
55
|
-
type: "deleteColumn"
|
56
|
-
}
|
57
|
-
}, {
|
58
|
-
Icon: SettingsIcon,
|
59
|
-
text: "Settings",
|
60
|
-
action: {
|
61
|
-
type: "settings"
|
62
|
-
}
|
63
|
-
}, {
|
64
|
-
Icon: DeleteForeverIcon,
|
65
|
-
text: "Remove Table",
|
66
|
-
action: {
|
67
|
-
type: "remove"
|
68
|
-
}
|
69
|
-
}];
|
9
|
+
const Resizer = ({
|
10
|
+
onMouseDown
|
11
|
+
}) => {
|
12
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
13
|
+
children: /*#__PURE__*/_jsx("button", {
|
14
|
+
contentEditable: false,
|
15
|
+
onPointerDown: onMouseDown,
|
16
|
+
className: "cell-resizer",
|
17
|
+
style: {
|
18
|
+
width: "10px",
|
19
|
+
height: "100%",
|
20
|
+
position: "absolute",
|
21
|
+
right: "0px",
|
22
|
+
top: 0
|
23
|
+
}
|
24
|
+
})
|
25
|
+
});
|
26
|
+
};
|
70
27
|
const TableCell = props => {
|
71
28
|
const {
|
72
29
|
element,
|
73
30
|
attributes,
|
74
|
-
children
|
75
|
-
customProps
|
31
|
+
children
|
76
32
|
} = props;
|
77
|
-
const [openSetttings, setOpenSettings] = useState(false);
|
78
33
|
const {
|
79
34
|
bgColor,
|
80
35
|
borderColor
|
81
36
|
} = element;
|
37
|
+
const [parentDOM, setParentDOM] = useState(null);
|
82
38
|
const editor = useSlateStatic();
|
83
39
|
const selected = useSelected();
|
40
|
+
const path = ReactEditor.findPath(editor, element);
|
41
|
+
const isHeader = path.length >= 2 ? path[path.length - 2] === 0 : false;
|
42
|
+
const [size, onMouseDown, resizing, onLoad] = useTableResize({
|
43
|
+
parentDOM,
|
44
|
+
size: element?.size
|
45
|
+
});
|
84
46
|
const table = new TableUtil(editor);
|
85
47
|
const tableProps = table.getTableProps();
|
86
|
-
const path = ReactEditor.findPath(editor, element);
|
87
48
|
const [tableNode] = Editor.nodes(editor, {
|
88
49
|
at: path,
|
89
50
|
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
@@ -94,87 +55,38 @@ const TableCell = props => {
|
|
94
55
|
});
|
95
56
|
const [parentProps] = tableNode || [{}];
|
96
57
|
const [rowProps] = rowNode || [{}];
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
break;
|
106
|
-
case "insertColumn":
|
107
|
-
table.insertColumn(position);
|
108
|
-
break;
|
109
|
-
case "deleteRow":
|
110
|
-
table.deleteRow();
|
111
|
-
break;
|
112
|
-
case "deleteColumn":
|
113
|
-
table.deleteColumn();
|
114
|
-
break;
|
115
|
-
case "remove":
|
116
|
-
table.removeTable();
|
117
|
-
break;
|
118
|
-
case "settings":
|
119
|
-
if (tableProps) {
|
120
|
-
onSettings(true);
|
121
|
-
}
|
122
|
-
break;
|
123
|
-
default:
|
124
|
-
return;
|
58
|
+
useEffect(() => {
|
59
|
+
if (editor && element) {
|
60
|
+
const dom = ReactEditor.toDOMNode(editor, element);
|
61
|
+
setParentDOM(dom);
|
62
|
+
onLoad(element?.size || {
|
63
|
+
width: 100,
|
64
|
+
height: 100
|
65
|
+
});
|
125
66
|
}
|
126
|
-
};
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
Icon,
|
138
|
-
text,
|
139
|
-
action
|
140
|
-
}) => {
|
141
|
-
return /*#__PURE__*/_jsx(IconButton, {
|
142
|
-
title: text,
|
143
|
-
onClick: handleInsert(action),
|
144
|
-
children: /*#__PURE__*/_jsx(Icon, {})
|
145
|
-
}, text);
|
146
|
-
})
|
147
|
-
}) : null;
|
148
|
-
};
|
149
|
-
const onSettings = () => {
|
150
|
-
setOpenSettings(true);
|
151
|
-
};
|
152
|
-
const onSave = data => {
|
153
|
-
const updateData = {
|
154
|
-
...data
|
155
|
-
};
|
156
|
-
delete updateData.children;
|
157
|
-
delete updateData.type;
|
158
|
-
table.updateTableStyle(updateData, {
|
159
|
-
...tableProps
|
160
|
-
});
|
161
|
-
onClose();
|
162
|
-
};
|
163
|
-
const onClose = () => {
|
164
|
-
setOpenSettings(false);
|
165
|
-
};
|
67
|
+
}, []);
|
68
|
+
useEffect(() => {
|
69
|
+
if (!resizing && tableProps) {
|
70
|
+
table.updateTableStyle({
|
71
|
+
"col.size": size
|
72
|
+
}, tableProps);
|
73
|
+
}
|
74
|
+
}, [resizing]);
|
75
|
+
const sizeProps = isHeader ? {
|
76
|
+
width: size?.width || 100
|
77
|
+
} : {};
|
166
78
|
return /*#__PURE__*/_jsxs("td", {
|
167
79
|
...element.attr,
|
168
80
|
...attributes,
|
81
|
+
className: "editor-table-cell",
|
169
82
|
style: {
|
83
|
+
position: "relative",
|
170
84
|
backgroundColor: bgColor,
|
171
|
-
border: `3px solid ${borderColor || rowProps?.borderColor || parentProps?.borderColor}
|
85
|
+
border: `3px solid ${borderColor || rowProps?.borderColor || parentProps?.borderColor}`,
|
86
|
+
...(sizeProps || {})
|
172
87
|
},
|
173
|
-
children: [
|
174
|
-
|
175
|
-
onSave: onSave,
|
176
|
-
onClose: onClose,
|
177
|
-
customProps: customProps
|
88
|
+
children: [children, selected && isHeader ? /*#__PURE__*/_jsx(Resizer, {
|
89
|
+
onMouseDown: onMouseDown
|
178
90
|
}) : null]
|
179
91
|
});
|
180
92
|
};
|