@flozy/editor 1.1.4 → 1.1.6
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/CollaborativeEditor.js +6 -1
- package/dist/Editor/CommonEditor.js +16 -2
- package/dist/Editor/Editor.css +15 -3
- 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/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 +12 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +6 -0
- package/dist/Editor/common/ColorPickerButton.js +65 -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/index.js +8 -3
- package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +12 -0
- package/dist/Editor/plugins/withLinks.js +40 -2
- package/dist/Editor/plugins/withTable.js +10 -1
- package/dist/Editor/service/fileupload.js +1 -1
- package/dist/Editor/utils/SlateUtilityFunctions.js +10 -0
- package/dist/Editor/utils/customHooks/useTableResize.js +46 -0
- package/dist/Editor/utils/insertChipText.js +49 -0
- package/dist/Editor/utils/insertDrawerMenu.js +52 -0
- package/dist/Editor/utils/table.js +26 -3
- package/package.json +2 -1
|
@@ -23,6 +23,7 @@ const CollaborativeEditor = props => {
|
|
|
23
23
|
});
|
|
24
24
|
const [value] = useState(convertedContent);
|
|
25
25
|
const [connected, setConnected] = useState(null);
|
|
26
|
+
const [message, setMessage] = useState("");
|
|
26
27
|
const [authenticated, setAuthenticated] = useState({
|
|
27
28
|
status: null,
|
|
28
29
|
scope: null
|
|
@@ -100,12 +101,16 @@ const CollaborativeEditor = props => {
|
|
|
100
101
|
setConnected(false);
|
|
101
102
|
});
|
|
102
103
|
provider.on("close", () => {
|
|
104
|
+
provider.disconnect();
|
|
105
|
+
provider.destroy();
|
|
103
106
|
setConnected(false);
|
|
107
|
+
setMessage("Seems your connection is lost... Reload the page to edit the document...");
|
|
108
|
+
console.log("closed", provider);
|
|
104
109
|
});
|
|
105
110
|
if (authenticated.status === null || !connected === null || !editor) {
|
|
106
111
|
return /*#__PURE__*/_jsx("h1", {
|
|
107
112
|
"data-status": connected,
|
|
108
|
-
children: "Loading..."
|
|
113
|
+
children: message || "Loading..."
|
|
109
114
|
});
|
|
110
115
|
}
|
|
111
116
|
return /*#__PURE__*/_jsx(CommonEditor, {
|
|
@@ -48,6 +48,16 @@ const CommonEditor = props => {
|
|
|
48
48
|
const {
|
|
49
49
|
pageProps
|
|
50
50
|
} = pageSettings || {};
|
|
51
|
+
const {
|
|
52
|
+
bannerSpacing
|
|
53
|
+
} = pageProps || {
|
|
54
|
+
bannerSpacing: {
|
|
55
|
+
left: 8,
|
|
56
|
+
right: 8,
|
|
57
|
+
top: 8,
|
|
58
|
+
bottom: 8
|
|
59
|
+
}
|
|
60
|
+
};
|
|
51
61
|
useEffect(() => {
|
|
52
62
|
setValue(draftToSlate({
|
|
53
63
|
data: content
|
|
@@ -137,8 +147,12 @@ const CommonEditor = props => {
|
|
|
137
147
|
className: "editor-wrapper",
|
|
138
148
|
style: {
|
|
139
149
|
border: "1px solid #f3f3f3",
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
background: pageProps?.pageColor || "#FFF",
|
|
151
|
+
color: pageProps?.color || "#000",
|
|
152
|
+
paddingLeft: `${bannerSpacing?.left}px`,
|
|
153
|
+
paddingRight: `${bannerSpacing?.right}px`,
|
|
154
|
+
paddingTop: `${bannerSpacing?.top}px`,
|
|
155
|
+
paddingBottom: `${bannerSpacing?.bottom}px`
|
|
142
156
|
},
|
|
143
157
|
children: [/*#__PURE__*/_jsx(Editable, {
|
|
144
158
|
readOnly: isReadOnly,
|
package/dist/Editor/Editor.css
CHANGED
|
@@ -29,7 +29,7 @@ button{
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
table{
|
|
32
|
-
width:100%;
|
|
32
|
+
/* width:100%; */
|
|
33
33
|
}
|
|
34
34
|
td{
|
|
35
35
|
height: 50px;
|
|
@@ -286,14 +286,26 @@ html{
|
|
|
286
286
|
|
|
287
287
|
.empty-carousel-wrapper {
|
|
288
288
|
display: flex;
|
|
289
|
-
flex-direction:
|
|
289
|
+
flex-direction: column;
|
|
290
290
|
overflow-x: auto;
|
|
291
291
|
}
|
|
292
292
|
.empty-carousel-wrapper > div{
|
|
293
293
|
display: flex;
|
|
294
294
|
flex-direction: column;
|
|
295
|
-
width: 100%;
|
|
296
295
|
flex-shrink: 0;
|
|
296
|
+
border: 1px solid #000;
|
|
297
|
+
}
|
|
298
|
+
.empty-carousel-wrapper .carousel-item-inner {
|
|
299
|
+
width: 100%;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.editor-chip-text {
|
|
303
|
+
padding: 4px;
|
|
304
|
+
background-color: #CCC;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.drawer-menu {
|
|
308
|
+
display: inline-flex;
|
|
297
309
|
}
|
|
298
310
|
|
|
299
311
|
@media (max-width: 480px) {
|
|
@@ -56,7 +56,7 @@ const EditorButton = props => {
|
|
|
56
56
|
return;
|
|
57
57
|
case "delete":
|
|
58
58
|
Transforms.removeNodes(editor, {
|
|
59
|
-
at: [path]
|
|
59
|
+
at: [...path]
|
|
60
60
|
});
|
|
61
61
|
return;
|
|
62
62
|
default:
|
|
@@ -71,7 +71,7 @@ const EditorButton = props => {
|
|
|
71
71
|
Transforms.setNodes(editor, {
|
|
72
72
|
...updateData
|
|
73
73
|
}, {
|
|
74
|
-
at: [path]
|
|
74
|
+
at: [...path]
|
|
75
75
|
});
|
|
76
76
|
setEdit(false);
|
|
77
77
|
};
|
|
@@ -87,7 +87,7 @@ const EditorButton = props => {
|
|
|
87
87
|
contentEditable: false,
|
|
88
88
|
className: "editor-btn",
|
|
89
89
|
style: {
|
|
90
|
-
|
|
90
|
+
background: bgColor || "rgb(30, 75, 122)",
|
|
91
91
|
border: borderColor ? `1px solid ${borderColor}` : "none",
|
|
92
92
|
borderRadius: `${topLeft}px ${topRight}px ${bottomLeft}px ${bottomRight}px`,
|
|
93
93
|
paddingLeft: `${left || 8}px`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { Transforms, Path } from "slate";
|
|
3
|
-
import { useSelected, useSlateStatic } from "slate-react";
|
|
3
|
+
import { ReactEditor, useSelected, useSlateStatic } from "slate-react";
|
|
4
4
|
import Slider from "react-slick";
|
|
5
5
|
import "./slick-theme.min.css";
|
|
6
6
|
import "./slick.min.css";
|
|
@@ -25,6 +25,8 @@ const Carousel = props => {
|
|
|
25
25
|
const editor = useSlateStatic();
|
|
26
26
|
const selected = useSelected();
|
|
27
27
|
const [edit, setEdit] = useState(false);
|
|
28
|
+
const [reload, setReload] = useState(new Date().getTime());
|
|
29
|
+
const path = ReactEditor.findPath(editor, element);
|
|
28
30
|
const settings = {
|
|
29
31
|
dots: true,
|
|
30
32
|
infinite: true,
|
|
@@ -51,6 +53,14 @@ const Carousel = props => {
|
|
|
51
53
|
};
|
|
52
54
|
const onEdit = () => {
|
|
53
55
|
setEdit(!edit);
|
|
56
|
+
if (edit) {
|
|
57
|
+
setReload(new Date().getTime());
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const onDelete = () => {
|
|
61
|
+
Transforms.removeNodes(editor, {
|
|
62
|
+
at: [...path]
|
|
63
|
+
});
|
|
54
64
|
};
|
|
55
65
|
const ToolBar = () => {
|
|
56
66
|
return selected ? /*#__PURE__*/_jsxs("div", {
|
|
@@ -58,14 +68,16 @@ const Carousel = props => {
|
|
|
58
68
|
contentEditable: false,
|
|
59
69
|
children: [/*#__PURE__*/_jsx("button", {
|
|
60
70
|
onClick: onEdit,
|
|
61
|
-
children: "Edit"
|
|
71
|
+
children: edit ? "Save" : "Edit"
|
|
62
72
|
}), /*#__PURE__*/_jsx("button", {
|
|
63
73
|
onClick: onAddSlide,
|
|
64
74
|
children: "Add Slide"
|
|
75
|
+
}), /*#__PURE__*/_jsx("button", {
|
|
76
|
+
onClick: onDelete,
|
|
77
|
+
children: "Delete"
|
|
65
78
|
})]
|
|
66
79
|
}) : null;
|
|
67
80
|
};
|
|
68
|
-
const CarouselWrapper = edit ? Slider : Empty;
|
|
69
81
|
return /*#__PURE__*/_jsxs("div", {
|
|
70
82
|
...attributes,
|
|
71
83
|
style: {
|
|
@@ -73,10 +85,12 @@ const Carousel = props => {
|
|
|
73
85
|
backgroundColor: "#CCC",
|
|
74
86
|
position: "relative"
|
|
75
87
|
},
|
|
76
|
-
children: [/*#__PURE__*/_jsx(
|
|
88
|
+
children: [edit ? /*#__PURE__*/_jsx(Empty, {
|
|
89
|
+
children: children
|
|
90
|
+
}) : /*#__PURE__*/_jsx(Slider, {
|
|
77
91
|
...settings,
|
|
78
92
|
children: children
|
|
79
|
-
}), /*#__PURE__*/_jsx(ToolBar, {})]
|
|
93
|
+
}, reload), /*#__PURE__*/_jsx(ToolBar, {})]
|
|
80
94
|
});
|
|
81
95
|
};
|
|
82
96
|
export default Carousel;
|
|
@@ -7,7 +7,11 @@ const CarouselItem = props => {
|
|
|
7
7
|
} = props;
|
|
8
8
|
return /*#__PURE__*/_jsx("div", {
|
|
9
9
|
...attributes,
|
|
10
|
-
|
|
10
|
+
className: "carousel-item",
|
|
11
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
12
|
+
className: "carousel-item-inner",
|
|
13
|
+
children: children
|
|
14
|
+
})
|
|
11
15
|
});
|
|
12
16
|
};
|
|
13
17
|
export default CarouselItem;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
const ChipText = props => {
|
|
4
|
+
const {
|
|
5
|
+
attributes,
|
|
6
|
+
children,
|
|
7
|
+
element
|
|
8
|
+
} = props;
|
|
9
|
+
const {
|
|
10
|
+
bgColor,
|
|
11
|
+
textColor,
|
|
12
|
+
bannerSpacing,
|
|
13
|
+
borderRadius,
|
|
14
|
+
borderColor
|
|
15
|
+
} = element;
|
|
16
|
+
const {
|
|
17
|
+
left,
|
|
18
|
+
top,
|
|
19
|
+
right,
|
|
20
|
+
bottom
|
|
21
|
+
} = bannerSpacing || {};
|
|
22
|
+
const {
|
|
23
|
+
topLeft,
|
|
24
|
+
topRight,
|
|
25
|
+
bottomLeft,
|
|
26
|
+
bottomRight
|
|
27
|
+
} = borderRadius || {};
|
|
28
|
+
return /*#__PURE__*/_jsx("span", {
|
|
29
|
+
...attributes,
|
|
30
|
+
className: "editor-chip-text",
|
|
31
|
+
style: {
|
|
32
|
+
paddingLeft: `${left}px`,
|
|
33
|
+
paddingRight: `${right}px`,
|
|
34
|
+
paddingTop: `${top}px`,
|
|
35
|
+
paddingBottom: `${bottom}px`,
|
|
36
|
+
border: borderColor ? `1px solid ${borderColor}` : "none",
|
|
37
|
+
borderRadius: `${topLeft}px ${topRight}px ${bottomLeft}px ${bottomRight}px`,
|
|
38
|
+
background: bgColor || "#CCC",
|
|
39
|
+
color: textColor
|
|
40
|
+
},
|
|
41
|
+
children: children
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export default ChipText;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Editor, Transforms } from "slate";
|
|
3
|
+
import { IconButton } from "@mui/material";
|
|
4
|
+
import SmartButtonIcon from "@mui/icons-material/SmartButton";
|
|
5
|
+
import { insertChipText, removeChipText } from "../../utils/insertChipText";
|
|
6
|
+
import ChipTextPopup from "./ChipTextPopup";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const ChipTextButton = props => {
|
|
11
|
+
const {
|
|
12
|
+
editor,
|
|
13
|
+
customProps
|
|
14
|
+
} = props;
|
|
15
|
+
const [openSetttings, setOpenSettings] = useState(false);
|
|
16
|
+
const handleClick = () => {
|
|
17
|
+
const [parent, parentPath] = Editor.parent(editor, editor.selection.focus.path);
|
|
18
|
+
if (parent && parent?.type === "chip-text") {
|
|
19
|
+
setOpenSettings({
|
|
20
|
+
element: parent,
|
|
21
|
+
path: parentPath
|
|
22
|
+
});
|
|
23
|
+
// removeChipText(editor, parentPath);
|
|
24
|
+
} else {
|
|
25
|
+
insertChipText(editor, {
|
|
26
|
+
url: "",
|
|
27
|
+
showInNewTab: false
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const onSave = data => {
|
|
32
|
+
const updateData = {
|
|
33
|
+
...data
|
|
34
|
+
};
|
|
35
|
+
delete updateData.children;
|
|
36
|
+
Transforms.setNodes(editor, {
|
|
37
|
+
...updateData
|
|
38
|
+
}, {
|
|
39
|
+
at: openSetttings?.path
|
|
40
|
+
});
|
|
41
|
+
onClose();
|
|
42
|
+
};
|
|
43
|
+
const onClose = () => {
|
|
44
|
+
setOpenSettings(false);
|
|
45
|
+
};
|
|
46
|
+
const onDelete = () => {
|
|
47
|
+
removeChipText(editor, openSetttings?.path);
|
|
48
|
+
onClose();
|
|
49
|
+
};
|
|
50
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
51
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
52
|
+
title: "Chip Text",
|
|
53
|
+
onClick: handleClick,
|
|
54
|
+
children: /*#__PURE__*/_jsx(SmartButtonIcon, {})
|
|
55
|
+
}), openSetttings !== false ? /*#__PURE__*/_jsx(ChipTextPopup, {
|
|
56
|
+
element: openSetttings?.element || {},
|
|
57
|
+
onSave: onSave,
|
|
58
|
+
onClose: onClose,
|
|
59
|
+
onDelete: onDelete,
|
|
60
|
+
customProps: customProps
|
|
61
|
+
}) : null]
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export default ChipTextButton;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import StyleBuilder from "../../common/StyleBuilder";
|
|
3
|
+
import chipTextStyle from "../../common/StyleBuilder/chipTextStyle";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const ChipTextPopup = props => {
|
|
6
|
+
const {
|
|
7
|
+
element,
|
|
8
|
+
onSave,
|
|
9
|
+
onClose,
|
|
10
|
+
onDelete,
|
|
11
|
+
customProps
|
|
12
|
+
} = props;
|
|
13
|
+
return /*#__PURE__*/_jsx(StyleBuilder, {
|
|
14
|
+
title: "Chip Text",
|
|
15
|
+
type: "ChipTextPopup",
|
|
16
|
+
element: element,
|
|
17
|
+
onSave: onSave,
|
|
18
|
+
onClose: onClose,
|
|
19
|
+
onDelete: onDelete,
|
|
20
|
+
renderTabs: chipTextStyle,
|
|
21
|
+
customProps: customProps
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export default ChipTextPopup;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { ReactEditor, useSlateStatic } from "slate-react";
|
|
3
|
+
import { Grid, Drawer, IconButton, List, ListItem, ListItemButton, ListItemText, Box, Button } from "@mui/material";
|
|
4
|
+
import MenuIcon from "@mui/icons-material/Menu";
|
|
5
|
+
import { removeDrawerMenu } from "../../utils/insertDrawerMenu";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
const DrawerMenu = props => {
|
|
9
|
+
const {
|
|
10
|
+
attributes,
|
|
11
|
+
element
|
|
12
|
+
} = props;
|
|
13
|
+
const {
|
|
14
|
+
menus,
|
|
15
|
+
anchor
|
|
16
|
+
} = element;
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const editor = useSlateStatic();
|
|
19
|
+
const path = ReactEditor.findPath(editor, element);
|
|
20
|
+
const handleClick = () => {
|
|
21
|
+
setOpen(!open);
|
|
22
|
+
};
|
|
23
|
+
const handleDelete = () => {
|
|
24
|
+
removeDrawerMenu(editor, path);
|
|
25
|
+
};
|
|
26
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
27
|
+
...attributes,
|
|
28
|
+
className: "drawer-menu",
|
|
29
|
+
contentEditable: false,
|
|
30
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
31
|
+
onClick: handleClick,
|
|
32
|
+
children: /*#__PURE__*/_jsx(MenuIcon, {})
|
|
33
|
+
}), /*#__PURE__*/_jsx(Drawer, {
|
|
34
|
+
anchor: anchor || "left",
|
|
35
|
+
open: open,
|
|
36
|
+
onClose: handleClick,
|
|
37
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
|
38
|
+
sx: {
|
|
39
|
+
width: anchor === "top" || anchor === "bottom" ? "auto" : 250
|
|
40
|
+
},
|
|
41
|
+
children: [/*#__PURE__*/_jsx(List, {
|
|
42
|
+
children: menus.map((m, i) => {
|
|
43
|
+
return /*#__PURE__*/_jsx(ListItem, {
|
|
44
|
+
children: /*#__PURE__*/_jsx(ListItemButton, {
|
|
45
|
+
children: /*#__PURE__*/_jsx(ListItemText, {
|
|
46
|
+
children: m.text
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
}, `em-d-${i}-${m.title}`);
|
|
50
|
+
})
|
|
51
|
+
}), /*#__PURE__*/_jsx(Grid, {
|
|
52
|
+
style: {
|
|
53
|
+
display: "flex",
|
|
54
|
+
justifyContent: "center"
|
|
55
|
+
},
|
|
56
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
57
|
+
color: "error",
|
|
58
|
+
onClick: handleDelete,
|
|
59
|
+
children: "Delete"
|
|
60
|
+
})
|
|
61
|
+
})]
|
|
62
|
+
})
|
|
63
|
+
})]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
export default DrawerMenu;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconButton } from "@mui/material";
|
|
3
|
+
import ViewSidebarIcon from "@mui/icons-material/ViewSidebar";
|
|
4
|
+
import { insertDrawerMenu } from "../../utils/insertDrawerMenu";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const DrawerButton = props => {
|
|
7
|
+
const {
|
|
8
|
+
editor
|
|
9
|
+
} = props;
|
|
10
|
+
const handleClick = () => {
|
|
11
|
+
insertDrawerMenu(editor, {
|
|
12
|
+
text: ""
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/_jsx(IconButton, {
|
|
16
|
+
title: "Drawer Menu",
|
|
17
|
+
onClick: handleClick,
|
|
18
|
+
children: /*#__PURE__*/_jsx(ViewSidebarIcon, {})
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export default DrawerButton;
|
|
@@ -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
|
})]
|