@flozy/editor 1.7.5 → 1.7.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/CommonEditor.js +30 -12
- package/dist/Editor/DialogWrapper.js +2 -10
- package/dist/Editor/Editor.css +105 -0
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +14 -4
- package/dist/Editor/Elements/Color Picker/ColorPicker.js +9 -6
- package/dist/Editor/Elements/Color Picker/LogoIcon.js +15 -49
- package/dist/Editor/Elements/Color Picker/Styles.js +25 -4
- package/dist/Editor/Elements/Color Picker/defaultColors.js +1 -1
- package/dist/Editor/Elements/Embed/Image.js +25 -31
- package/dist/Editor/Elements/Embed/Video.js +49 -40
- package/dist/Editor/Elements/Form/Workflow/Styles.js +3 -2
- package/dist/Editor/Elements/Grid/Grid.js +67 -114
- package/dist/Editor/Elements/Grid/GridItem.js +9 -23
- package/dist/Editor/Elements/Grid/templates/default_grid.js +0 -23
- package/dist/Editor/Elements/Link/Link.js +58 -20
- package/dist/Editor/Elements/Link/LinkButton.js +37 -97
- package/dist/Editor/Elements/Link/LinkPopup.js +106 -0
- package/dist/Editor/Elements/List/CheckList.js +28 -22
- package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +11 -5
- package/dist/Editor/Elements/Signature/SignaturePopup.js +15 -4
- package/dist/Editor/Elements/SimpleText.js +30 -26
- package/dist/Editor/MiniEditor.js +4 -6
- package/dist/Editor/Styles/EditorStyles.js +72 -1
- package/dist/Editor/Toolbar/FormatTools/TextSize.js +2 -1
- package/dist/Editor/Toolbar/Mini/MiniToolbar.js +5 -1
- package/dist/Editor/Toolbar/PopupTool/AddTemplates.js +3 -1
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +4 -0
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +96 -19
- package/dist/Editor/Toolbar/toolbarGroups.js +1 -1
- package/dist/Editor/common/Section/index.js +118 -0
- package/dist/Editor/common/Shorthands/elements.js +1 -1
- package/dist/Editor/common/StyleBuilder/appHeaderStyle.js +5 -1
- package/dist/Editor/common/StyleBuilder/buttonStyle.js +44 -51
- package/dist/Editor/common/StyleBuilder/embedImageStyle.js +2 -24
- package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +0 -3
- package/dist/Editor/common/StyleBuilder/fieldStyle.js +0 -3
- package/dist/Editor/common/StyleBuilder/fieldTypes/alignment.js +52 -62
- package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +2 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +100 -74
- package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +41 -10
- package/dist/Editor/common/StyleBuilder/fieldTypes/buttonLink.js +3 -3
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +27 -77
- package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +7 -5
- package/dist/Editor/common/StyleBuilder/fieldTypes/gridSize.js +19 -15
- package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +2 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/menusArray.js +2 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +67 -8
- package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +2 -3
- package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +21 -32
- package/dist/Editor/common/StyleBuilder/fieldTypes/textAlign.js +37 -41
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +26 -24
- package/dist/Editor/common/StyleBuilder/formStyle.js +0 -6
- package/dist/Editor/common/StyleBuilder/gridItemStyle.js +38 -54
- package/dist/Editor/common/StyleBuilder/gridStyle.js +20 -26
- package/dist/Editor/common/StyleBuilder/index.js +14 -58
- package/dist/Editor/common/StyleBuilder/sectionStyle.js +16 -0
- package/dist/Editor/helper/index.js +63 -1
- package/dist/Editor/utils/Decorators/index.js +5 -0
- package/dist/Editor/utils/Decorators/link.js +26 -0
- package/dist/Editor/utils/SlateUtilityFunctions.js +36 -8
- package/dist/Editor/utils/accordion.js +17 -4
- package/dist/Editor/utils/button.js +15 -1
- package/dist/Editor/utils/customHooks/useElement.js +28 -0
- package/dist/Editor/utils/embed.js +1 -7
- package/dist/Editor/utils/events.js +92 -43
- package/dist/Editor/utils/gridItem.js +1 -1
- package/dist/Editor/utils/link.js +10 -9
- package/package.json +1 -1
|
@@ -8,23 +8,10 @@ const gridStyle = [{
|
|
|
8
8
|
type: "text",
|
|
9
9
|
placeholder: "Id should be unique for the page..."
|
|
10
10
|
}]
|
|
11
|
-
}, {
|
|
12
|
-
tab: "Size",
|
|
13
|
-
value: "gridSize",
|
|
14
|
-
fields: [{
|
|
15
|
-
label: "Grid Size",
|
|
16
|
-
key: "gridSize",
|
|
17
|
-
type: "gridSize"
|
|
18
|
-
}]
|
|
19
11
|
}, {
|
|
20
12
|
tab: "Colors",
|
|
21
13
|
value: "colors",
|
|
22
14
|
fields: [{
|
|
23
|
-
label: "Text Color",
|
|
24
|
-
key: "textColor",
|
|
25
|
-
type: "color",
|
|
26
|
-
needPreview: false
|
|
27
|
-
}, {
|
|
28
15
|
label: "Background Color",
|
|
29
16
|
key: "bgColor",
|
|
30
17
|
type: "color"
|
|
@@ -37,14 +24,6 @@ const gridStyle = [{
|
|
|
37
24
|
key: "borderColor",
|
|
38
25
|
type: "color"
|
|
39
26
|
}]
|
|
40
|
-
}, {
|
|
41
|
-
tab: "Position",
|
|
42
|
-
value: "position",
|
|
43
|
-
fields: [{
|
|
44
|
-
label: "Set Postion (Vertical & Horizantal)",
|
|
45
|
-
key: "alignment",
|
|
46
|
-
type: "alignment"
|
|
47
|
-
}]
|
|
48
27
|
}, {
|
|
49
28
|
tab: "Background",
|
|
50
29
|
value: "backgroundImage",
|
|
@@ -57,11 +36,19 @@ const gridStyle = [{
|
|
|
57
36
|
key: "backgroundImage",
|
|
58
37
|
type: "backgroundImage"
|
|
59
38
|
}]
|
|
39
|
+
}, {
|
|
40
|
+
tab: "Position",
|
|
41
|
+
value: "position",
|
|
42
|
+
fields: [{
|
|
43
|
+
label: "Set Postion (Vertical & Horizantal)",
|
|
44
|
+
key: "alignment",
|
|
45
|
+
type: "alignment"
|
|
46
|
+
}]
|
|
60
47
|
}, {
|
|
61
48
|
tab: "Padding",
|
|
62
49
|
value: "bannerSpacing",
|
|
63
50
|
fields: [{
|
|
64
|
-
label: "
|
|
51
|
+
label: "Banner Spacing",
|
|
65
52
|
key: "bannerSpacing",
|
|
66
53
|
type: "bannerSpacing"
|
|
67
54
|
}]
|
|
@@ -76,11 +63,13 @@ const gridStyle = [{
|
|
|
76
63
|
label: "Border Width",
|
|
77
64
|
key: "borderWidth",
|
|
78
65
|
type: "text",
|
|
79
|
-
placeholder: "1px"
|
|
66
|
+
placeholder: "1px",
|
|
67
|
+
width: 6
|
|
80
68
|
}, {
|
|
81
69
|
label: "Border Style",
|
|
82
70
|
key: "borderStyle",
|
|
83
71
|
type: "textOptions",
|
|
72
|
+
width: 6,
|
|
84
73
|
options: [{
|
|
85
74
|
text: "Solid",
|
|
86
75
|
value: "solid"
|
|
@@ -93,13 +82,18 @@ const gridStyle = [{
|
|
|
93
82
|
}],
|
|
94
83
|
renderOption: option => {
|
|
95
84
|
return /*#__PURE__*/_jsx("span", {
|
|
96
|
-
style: {
|
|
97
|
-
fontFamily: option.value
|
|
98
|
-
},
|
|
99
85
|
children: option.text
|
|
100
86
|
});
|
|
101
87
|
}
|
|
102
88
|
}]
|
|
89
|
+
}, {
|
|
90
|
+
tab: "Size",
|
|
91
|
+
value: "gridSize",
|
|
92
|
+
fields: [{
|
|
93
|
+
label: "Grid Size",
|
|
94
|
+
key: "gridSize",
|
|
95
|
+
type: "gridSize"
|
|
96
|
+
}]
|
|
103
97
|
}, {
|
|
104
98
|
tab: "Save As Template",
|
|
105
99
|
value: "saveAsTemplate",
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
// Dialog,
|
|
4
|
-
DialogTitle, DialogContent, DialogActions, Button,
|
|
5
|
-
// Tabs,
|
|
6
|
-
// Tab,
|
|
7
|
-
Grid, IconButton, Typography, Drawer } from "@mui/material";
|
|
2
|
+
import { DialogTitle, DialogContent, DialogActions, Button, Grid, IconButton, Typography, Drawer } from "@mui/material";
|
|
8
3
|
import FieldMap from "./fieldTypes";
|
|
9
4
|
import CloseIcon from "@mui/icons-material/Close";
|
|
10
5
|
import commonStyle from "../../commonStyle";
|
|
@@ -29,51 +24,20 @@ const StyleContent = props => {
|
|
|
29
24
|
return /*#__PURE__*/_jsx(Grid, {
|
|
30
25
|
container: true,
|
|
31
26
|
spacing: 2,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
onChange: onChange,
|
|
44
|
-
elementProps: element,
|
|
45
|
-
customProps: customProps,
|
|
46
|
-
handleClose: handleClose
|
|
47
|
-
}, `ei_stt_tab_${value}_${m.key}_${i}`) : null;
|
|
48
|
-
})
|
|
27
|
+
className: "sidebar-wrpr-eds",
|
|
28
|
+
children: [...fields].map((m, i) => {
|
|
29
|
+
const FieldComponent = FieldMap[m.type];
|
|
30
|
+
return FieldComponent ? /*#__PURE__*/_jsx(FieldComponent, {
|
|
31
|
+
data: m,
|
|
32
|
+
value: element[m.key],
|
|
33
|
+
onChange: onChange,
|
|
34
|
+
elementProps: element,
|
|
35
|
+
customProps: customProps,
|
|
36
|
+
handleClose: handleClose
|
|
37
|
+
}, `ei_stt_tab_${value}_${m.key}_${i}`) : null;
|
|
49
38
|
})
|
|
50
39
|
}, value);
|
|
51
40
|
};
|
|
52
|
-
|
|
53
|
-
// const StyleTabs = (props) => {
|
|
54
|
-
// const { value, handleChange, renderTabs } = props;
|
|
55
|
-
// return (
|
|
56
|
-
// <Tabs
|
|
57
|
-
// value={value}
|
|
58
|
-
// onChange={handleChange}
|
|
59
|
-
// variant="scrollable"
|
|
60
|
-
// scrollButtons="auto"
|
|
61
|
-
// aria-label="scrollable auto tabs example"
|
|
62
|
-
// className="editorTabs"
|
|
63
|
-
// >
|
|
64
|
-
// {renderTabs.map((m, i) => {
|
|
65
|
-
// return (
|
|
66
|
-
// <Tab
|
|
67
|
-
// key={`editor-stt-tab-${m.value}`}
|
|
68
|
-
// value={m.value}
|
|
69
|
-
// label={m.tab}
|
|
70
|
-
// />
|
|
71
|
-
// );
|
|
72
|
-
// })}
|
|
73
|
-
// </Tabs>
|
|
74
|
-
// );
|
|
75
|
-
// };
|
|
76
|
-
|
|
77
41
|
const StyleBuilder = props => {
|
|
78
42
|
const {
|
|
79
43
|
title,
|
|
@@ -83,10 +47,8 @@ const StyleBuilder = props => {
|
|
|
83
47
|
onClose,
|
|
84
48
|
onDelete,
|
|
85
49
|
customProps
|
|
86
|
-
// className,
|
|
87
50
|
} = props;
|
|
88
51
|
const [elementProps, setElementProps] = useState(element);
|
|
89
|
-
// const [tab, setTab] = useState(renderTabs[0]?.value);
|
|
90
52
|
const [tab] = useState(renderTabs[0]?.value);
|
|
91
53
|
const tabVal = renderTabs?.find(f => f.value === tab);
|
|
92
54
|
const {
|
|
@@ -104,11 +66,6 @@ const StyleBuilder = props => {
|
|
|
104
66
|
}
|
|
105
67
|
};
|
|
106
68
|
}, []);
|
|
107
|
-
|
|
108
|
-
// const handleChange = (e, newValue) => {
|
|
109
|
-
// setTab(newValue);
|
|
110
|
-
// };
|
|
111
|
-
|
|
112
69
|
const onElementPropsChange = data => {
|
|
113
70
|
setElementProps({
|
|
114
71
|
...elementProps,
|
|
@@ -160,9 +117,8 @@ const StyleBuilder = props => {
|
|
|
160
117
|
})
|
|
161
118
|
}), /*#__PURE__*/_jsx(DialogContent, {
|
|
162
119
|
sx: {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
// padding: "16px",
|
|
120
|
+
maxHeight: `${window.innerHeight - 125}px`,
|
|
121
|
+
padding: "8px"
|
|
166
122
|
},
|
|
167
123
|
children: renderTabs.map((m, i) => {
|
|
168
124
|
return /*#__PURE__*/_jsx(StyleContent, {
|
|
@@ -34,5 +34,21 @@ const gridStyle = [{
|
|
|
34
34
|
key: "sectionBorderRadius",
|
|
35
35
|
type: "borderRadius"
|
|
36
36
|
}]
|
|
37
|
+
}, {
|
|
38
|
+
tab: "Position",
|
|
39
|
+
value: "position",
|
|
40
|
+
fields: [{
|
|
41
|
+
label: "Set Postion (Vertical & Horizantal)",
|
|
42
|
+
key: "sectionAlignment",
|
|
43
|
+
type: "alignment"
|
|
44
|
+
}]
|
|
45
|
+
}, {
|
|
46
|
+
tab: "Size",
|
|
47
|
+
value: "gridSize",
|
|
48
|
+
fields: [{
|
|
49
|
+
label: "Grid Size",
|
|
50
|
+
key: "sectionGridSize",
|
|
51
|
+
type: "gridSize"
|
|
52
|
+
}]
|
|
37
53
|
}];
|
|
38
54
|
export default gridStyle;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import html2canvas from "html2canvas";
|
|
2
2
|
import { rectIntersection, closestCenter } from "@dnd-kit/core";
|
|
3
|
+
import { getQueryStrings } from "../utils/SlateUtilityFunctions";
|
|
4
|
+
import { Node } from "slate";
|
|
5
|
+
const HIDE_PLACHOLDERS = ["grid", "grid-item", "table"];
|
|
3
6
|
export const getThumbnailImage = async (dom, options = {}) => {
|
|
4
7
|
try {
|
|
5
8
|
const canvas = await html2canvas(dom, options);
|
|
@@ -20,4 +23,63 @@ export function customCollisionDetectionAlgorithm(args) {
|
|
|
20
23
|
|
|
21
24
|
// If there are no collisions with the pointer, return rectangle intersections
|
|
22
25
|
return [];
|
|
23
|
-
}
|
|
26
|
+
}
|
|
27
|
+
function componentToHex(c) {
|
|
28
|
+
var hex = Number(c).toString(16);
|
|
29
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
30
|
+
}
|
|
31
|
+
function rgbToHex(rgb) {
|
|
32
|
+
return "#" + rgb.match(/\d+/g).map(componentToHex).join("");
|
|
33
|
+
}
|
|
34
|
+
export function invertColor(hex) {
|
|
35
|
+
try {
|
|
36
|
+
if (hex?.indexOf("#") === -1) {
|
|
37
|
+
hex = rgbToHex(hex);
|
|
38
|
+
}
|
|
39
|
+
if (hex.indexOf("#") === 0) {
|
|
40
|
+
hex = hex.slice(1);
|
|
41
|
+
}
|
|
42
|
+
// convert 3-digit hex to 6-digits.
|
|
43
|
+
if (hex.length === 3) {
|
|
44
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
45
|
+
}
|
|
46
|
+
if (hex.length !== 6) {
|
|
47
|
+
// throw new Error("Invalid HEX color.");
|
|
48
|
+
}
|
|
49
|
+
// invert color components
|
|
50
|
+
var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16),
|
|
51
|
+
g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16),
|
|
52
|
+
b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16);
|
|
53
|
+
// pad each with zeros and return
|
|
54
|
+
return "#" + padZero(r) + padZero(g) + padZero(b) + "80";
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.log(err);
|
|
57
|
+
return "#FFF";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function padZero(str, len) {
|
|
61
|
+
len = len || 2;
|
|
62
|
+
var zeros = new Array(len).join("0");
|
|
63
|
+
return (zeros + str).slice(-len);
|
|
64
|
+
}
|
|
65
|
+
export function getEmbedURL(element) {
|
|
66
|
+
let refUrl = element.href ? element.href : element.url;
|
|
67
|
+
refUrl = refUrl ? refUrl.includes("http") ? refUrl : `//${refUrl}` : "Link";
|
|
68
|
+
let embedUrl = refUrl;
|
|
69
|
+
if (embedUrl.includes("youtube")) embedUrl = getQueryStrings(embedUrl);
|
|
70
|
+
if (embedUrl.includes("youtu.be")) embedUrl = getQueryStrings(embedUrl);
|
|
71
|
+
if (embedUrl.includes("loom")) embedUrl = embedUrl.replace(/\/share\//, "/embed/");
|
|
72
|
+
if (embedUrl.includes("vimeo")) embedUrl = embedUrl.replace(/\/vimeo.com\//, "/player.vimeo.com/video/");
|
|
73
|
+
if (embedUrl.includes("dailymotion") && embedUrl.includes("video")) embedUrl = embedUrl.replace(/www.dailymotion.com\//, "www.dailymotion.com/embed/");
|
|
74
|
+
if (embedUrl.includes("dai.ly")) embedUrl = embedUrl.replace(/dai.ly\//, "www.dailymotion.com/embed/video/");
|
|
75
|
+
return embedUrl;
|
|
76
|
+
}
|
|
77
|
+
export const isEmptyTextNode = element => {
|
|
78
|
+
try {
|
|
79
|
+
const showPlaceholder = element?.children?.filter(f => HIDE_PLACHOLDERS.indexOf(f.type) > -1).length === 0;
|
|
80
|
+
return Node.string(element)?.length === 0 && showPlaceholder;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.log(err);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const findUrlsInText = text => {
|
|
2
|
+
const urlRegex =
|
|
3
|
+
// eslint-disable-next-line no-useless-escape
|
|
4
|
+
/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])/gim;
|
|
5
|
+
const matches = text.match(urlRegex);
|
|
6
|
+
return matches ? matches.map(m => [m.trim(), text.indexOf(m.trim())]) : [];
|
|
7
|
+
};
|
|
8
|
+
const link = ([node, path]) => {
|
|
9
|
+
const nodeText = node.text;
|
|
10
|
+
if (!nodeText) return [];
|
|
11
|
+
const urls = findUrlsInText(nodeText);
|
|
12
|
+
return urls.map(([url, index]) => {
|
|
13
|
+
return {
|
|
14
|
+
anchor: {
|
|
15
|
+
path,
|
|
16
|
+
offset: index
|
|
17
|
+
},
|
|
18
|
+
focus: {
|
|
19
|
+
path,
|
|
20
|
+
offset: index + url.length
|
|
21
|
+
},
|
|
22
|
+
decoration: "link"
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export default link;
|
|
@@ -32,9 +32,14 @@ import InlineIcon from "../Elements/InlineIcon/InlineIcon";
|
|
|
32
32
|
import EmbedLink from "../Elements/Embed/link";
|
|
33
33
|
import SimpleText from "../Elements/SimpleText";
|
|
34
34
|
import CheckList from "../Elements/List/CheckList";
|
|
35
|
+
import { isEmptyTextNode } from "../helper";
|
|
35
36
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
36
37
|
const alignment = ["alignLeft", "alignRight", "alignCenter"];
|
|
37
38
|
const list_types = ["orderedList", "unorderedList"];
|
|
39
|
+
const LIST_FORMAT_TYPE = {
|
|
40
|
+
orderedList: "list-item",
|
|
41
|
+
unorderedList: "list-item"
|
|
42
|
+
};
|
|
38
43
|
export const toggleBlock = (editor, format, selection = true, attr = {}) => {
|
|
39
44
|
const isActive = isBlockActive(editor, format);
|
|
40
45
|
const isList = list_types.includes(format);
|
|
@@ -68,7 +73,7 @@ export const toggleBlock = (editor, format, selection = true, attr = {}) => {
|
|
|
68
73
|
Transforms.insertText(editor, "");
|
|
69
74
|
}
|
|
70
75
|
Transforms.setNodes(editor, {
|
|
71
|
-
type: isActive ? "paragraph" : isList ?
|
|
76
|
+
type: isActive ? "paragraph" : isList ? LIST_FORMAT_TYPE[format] : format,
|
|
72
77
|
...attr
|
|
73
78
|
});
|
|
74
79
|
if (isList && !isActive) {
|
|
@@ -181,9 +186,9 @@ export const getMarked = (leaf, children) => {
|
|
|
181
186
|
}
|
|
182
187
|
if (leaf.color) {
|
|
183
188
|
const textStyles = leaf?.color?.indexOf("gradient") >= 0 ? {
|
|
184
|
-
background: leaf
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
background: leaf?.color?.concat("text"),
|
|
190
|
+
WebkitBackgroundClip: "text",
|
|
191
|
+
WebkitTextFillColor: "transparent"
|
|
187
192
|
} : {
|
|
188
193
|
color: leaf.color
|
|
189
194
|
};
|
|
@@ -228,6 +233,17 @@ export const getMarked = (leaf, children) => {
|
|
|
228
233
|
children: children
|
|
229
234
|
});
|
|
230
235
|
}
|
|
236
|
+
if (leaf.decoration === "link") {
|
|
237
|
+
children = /*#__PURE__*/_jsx("a", {
|
|
238
|
+
style: {
|
|
239
|
+
cursor: "pointer"
|
|
240
|
+
},
|
|
241
|
+
rel: "noreferrer",
|
|
242
|
+
target: "_blank",
|
|
243
|
+
href: leaf.text,
|
|
244
|
+
children: children
|
|
245
|
+
});
|
|
246
|
+
}
|
|
231
247
|
return children;
|
|
232
248
|
};
|
|
233
249
|
export const getBlock = props => {
|
|
@@ -236,23 +252,30 @@ export const getBlock = props => {
|
|
|
236
252
|
children
|
|
237
253
|
} = props;
|
|
238
254
|
const attributes = props.attributes ?? {};
|
|
255
|
+
const isEmpty = isEmptyTextNode(element);
|
|
239
256
|
switch (element.type) {
|
|
240
257
|
case "headingOne":
|
|
241
258
|
return /*#__PURE__*/_jsx("h1", {
|
|
242
259
|
...attributes,
|
|
243
260
|
...element.attr,
|
|
261
|
+
className: `content-editable ${isEmpty ? "empty" : ""}`,
|
|
262
|
+
placeholder: "Heading 1",
|
|
244
263
|
children: children
|
|
245
264
|
});
|
|
246
265
|
case "headingTwo":
|
|
247
266
|
return /*#__PURE__*/_jsx("h2", {
|
|
248
267
|
...attributes,
|
|
249
268
|
...element.attr,
|
|
269
|
+
className: `content-editable ${isEmpty ? "empty" : ""}`,
|
|
270
|
+
placeholder: "Heading 2",
|
|
250
271
|
children: children
|
|
251
272
|
});
|
|
252
273
|
case "headingThree":
|
|
253
274
|
return /*#__PURE__*/_jsx("h3", {
|
|
254
275
|
...attributes,
|
|
255
276
|
...element.attr,
|
|
277
|
+
className: `content-editable ${isEmpty ? "empty" : ""}`,
|
|
278
|
+
placeholder: "Heading 3",
|
|
256
279
|
children: children
|
|
257
280
|
});
|
|
258
281
|
case "blockquote":
|
|
@@ -306,6 +329,8 @@ export const getBlock = props => {
|
|
|
306
329
|
return /*#__PURE__*/_jsx("li", {
|
|
307
330
|
...attributes,
|
|
308
331
|
...element.attr,
|
|
332
|
+
className: `content-editable ${isEmpty ? "empty" : ""}`,
|
|
333
|
+
placeholder: "List",
|
|
309
334
|
children: children
|
|
310
335
|
});
|
|
311
336
|
case "orderedList":
|
|
@@ -319,9 +344,10 @@ export const getBlock = props => {
|
|
|
319
344
|
...attributes,
|
|
320
345
|
children: children
|
|
321
346
|
});
|
|
322
|
-
case "
|
|
347
|
+
case "check-list-item":
|
|
323
348
|
return /*#__PURE__*/_jsx(CheckList, {
|
|
324
|
-
...props
|
|
349
|
+
...props,
|
|
350
|
+
isEmpty: isEmpty
|
|
325
351
|
});
|
|
326
352
|
case "link":
|
|
327
353
|
return /*#__PURE__*/_jsx(Link, {
|
|
@@ -373,7 +399,8 @@ export const getBlock = props => {
|
|
|
373
399
|
});
|
|
374
400
|
case "grid-item":
|
|
375
401
|
return /*#__PURE__*/_jsx(GridItem, {
|
|
376
|
-
...props
|
|
402
|
+
...props,
|
|
403
|
+
isEmpty: isEmpty
|
|
377
404
|
});
|
|
378
405
|
case "accordion":
|
|
379
406
|
return /*#__PURE__*/_jsx(Accordion, {
|
|
@@ -445,7 +472,8 @@ export const getBlock = props => {
|
|
|
445
472
|
});
|
|
446
473
|
default:
|
|
447
474
|
return /*#__PURE__*/_jsx(SimpleText, {
|
|
448
|
-
...props
|
|
475
|
+
...props,
|
|
476
|
+
isEmpty: isEmpty
|
|
449
477
|
});
|
|
450
478
|
}
|
|
451
479
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transforms } from "slate";
|
|
2
2
|
import insertNewLine from "./insertNewLine";
|
|
3
|
-
export const insertAccordion = editor => {
|
|
3
|
+
export const insertAccordion = (editor, path) => {
|
|
4
4
|
try {
|
|
5
5
|
const accordion = {
|
|
6
6
|
type: "accordion",
|
|
@@ -22,9 +22,22 @@ export const insertAccordion = editor => {
|
|
|
22
22
|
}]
|
|
23
23
|
}]
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const props = path ? {
|
|
26
|
+
at: path,
|
|
27
|
+
select: true
|
|
28
|
+
} : {
|
|
29
|
+
select: true
|
|
30
|
+
};
|
|
31
|
+
Transforms.insertNodes(editor, accordion, props);
|
|
32
|
+
const curPath = [...editor?.selection?.anchor?.path];
|
|
33
|
+
const upPath = [...curPath];
|
|
34
|
+
// get title index
|
|
35
|
+
const summaryIndex = upPath.length - 3;
|
|
36
|
+
upPath[summaryIndex] = upPath[summaryIndex] === 0 ? 0 : upPath[summaryIndex] - 1;
|
|
37
|
+
// select accordion title by default
|
|
38
|
+
Transforms.select(editor, {
|
|
39
|
+
path: upPath,
|
|
40
|
+
offset: 0
|
|
28
41
|
});
|
|
29
42
|
insertNewLine(editor);
|
|
30
43
|
} catch (err) {
|
|
@@ -8,7 +8,21 @@ export const insertButton = editor => {
|
|
|
8
8
|
buttonLink: {
|
|
9
9
|
linkType: "webAddress"
|
|
10
10
|
},
|
|
11
|
-
iconPosition: "start"
|
|
11
|
+
iconPosition: "start",
|
|
12
|
+
bgColor: "#2563EB",
|
|
13
|
+
textColor: "#FFF",
|
|
14
|
+
borderRadius: {
|
|
15
|
+
topLeft: 8,
|
|
16
|
+
topRight: 8,
|
|
17
|
+
bottomLeft: 8,
|
|
18
|
+
bottomRight: 8
|
|
19
|
+
},
|
|
20
|
+
bannerSpacing: {
|
|
21
|
+
left: 16,
|
|
22
|
+
top: 8,
|
|
23
|
+
right: 16,
|
|
24
|
+
bottom: 8
|
|
25
|
+
}
|
|
12
26
|
};
|
|
13
27
|
Transforms.insertNodes(editor, button);
|
|
14
28
|
Transforms.move(editor);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { Editor, Element } from "slate";
|
|
3
|
+
|
|
4
|
+
// This hook returns if the node in the current selection matches the format passed to it.
|
|
5
|
+
const useElement = (editor, format) => {
|
|
6
|
+
const [isElement, setIsElement] = useState(false);
|
|
7
|
+
const matchFormat = n => {
|
|
8
|
+
if (format) {
|
|
9
|
+
return format.indexOf(n.type) > -1;
|
|
10
|
+
} else {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (editor.selection) {
|
|
16
|
+
// It matches at the editor.selection location by default, so if null handle it seperately.
|
|
17
|
+
const [node] = Editor.nodes(editor, {
|
|
18
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && matchFormat(n)
|
|
19
|
+
});
|
|
20
|
+
setIsElement(node);
|
|
21
|
+
} else {
|
|
22
|
+
setIsElement(null);
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
}, [editor.selection]);
|
|
26
|
+
return isElement;
|
|
27
|
+
};
|
|
28
|
+
export default useElement;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transforms } from "slate";
|
|
2
2
|
import insertNewLine from "./insertNewLine";
|
|
3
3
|
export const insertDefaultEmbed = (editor, type, defaultURL = "") => {
|
|
4
|
-
const url = defaultURL ? defaultURL : type === "image" ? "
|
|
4
|
+
const url = defaultURL ? defaultURL : type === "image" ? "" : "";
|
|
5
5
|
insertEmbed(editor, {
|
|
6
6
|
url,
|
|
7
7
|
images: []
|
|
@@ -29,13 +29,7 @@ export const createEmbedNode = (type, {
|
|
|
29
29
|
});
|
|
30
30
|
export const insertEmbed = (editor, embedData, format) => {
|
|
31
31
|
try {
|
|
32
|
-
const {
|
|
33
|
-
url,
|
|
34
|
-
images
|
|
35
|
-
} = embedData;
|
|
36
|
-
if (!url && images.length === 0) return;
|
|
37
32
|
const embed = createEmbedNode(format, embedData);
|
|
38
|
-
console.log(embed);
|
|
39
33
|
Transforms.insertNodes(editor, embed, {
|
|
40
34
|
at: editor.selection.anchor.path
|
|
41
35
|
});
|