@vonaffenfels/slate-editor 1.0.1
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/.babelrc +44 -0
- package/README.md +5 -0
- package/componentLoader.js +52 -0
- package/dist/BlockEditor.css +93 -0
- package/dist/BlockEditor.js +2 -0
- package/dist/BlockEditor.js.LICENSE.txt +61 -0
- package/dist/Renderer.js +2 -0
- package/dist/Renderer.js.LICENSE.txt +15 -0
- package/dist/fromHTML.js +1 -0
- package/dist/index.css +93 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +69 -0
- package/dist/toHTML.js +2 -0
- package/dist/toHTML.js.LICENSE.txt +23 -0
- package/dist/toText.js +2 -0
- package/dist/toText.js.LICENSE.txt +23 -0
- package/package.json +79 -0
- package/postcss.config.js +7 -0
- package/scss/demo.scss +142 -0
- package/scss/editor.scss +394 -0
- package/scss/storybook.scss +66 -0
- package/scss/toolbar.scss +160 -0
- package/src/BlockEditor.js +252 -0
- package/src/Blocks/EmptyBlock.js +12 -0
- package/src/Blocks/EmptyWrapper.js +5 -0
- package/src/Blocks/ErrorBoundary.js +41 -0
- package/src/Blocks/LayoutBlock.js +179 -0
- package/src/Blocks/LayoutSlot.js +61 -0
- package/src/Context/StorybookContext.js +7 -0
- package/src/Nodes/Default.js +151 -0
- package/src/Nodes/Element.js +72 -0
- package/src/Nodes/Leaf.js +40 -0
- package/src/Nodes/Storybook.js +170 -0
- package/src/Nodes/StorybookDisplay.js +118 -0
- package/src/Nodes/Text.js +67 -0
- package/src/Renderer.js +41 -0
- package/src/Serializer/Html.js +43 -0
- package/src/Serializer/Serializer.js +318 -0
- package/src/Serializer/Text.js +18 -0
- package/src/Serializer/ads.js +175 -0
- package/src/Serializer/index.js +4 -0
- package/src/SidebarEditor/SidebarEditorField.js +249 -0
- package/src/SidebarEditor.css +90 -0
- package/src/SidebarEditor.js +236 -0
- package/src/Storybook.js +152 -0
- package/src/Toolbar/Align.js +65 -0
- package/src/Toolbar/Block.js +121 -0
- package/src/Toolbar/Element.js +49 -0
- package/src/Toolbar/Formats.js +60 -0
- package/src/Toolbar/Insert.js +29 -0
- package/src/Toolbar/Layout.js +333 -0
- package/src/Toolbar/Link.js +165 -0
- package/src/Toolbar/Toolbar.js +164 -0
- package/src/Tools/Margin.js +52 -0
- package/src/dev/App.js +61 -0
- package/src/dev/draftToSlate.json +3148 -0
- package/src/dev/index.css +3 -0
- package/src/dev/index.html +11 -0
- package/src/dev/index.js +5 -0
- package/src/dev/sampleValue1.json +4295 -0
- package/src/dev/sampleValue2.json +0 -0
- package/src/dev/sampleValueValid.json +411 -0
- package/src/dev/testComponents/TestStory.js +9 -0
- package/src/dev/testComponents/TestStory.stories.js +172 -0
- package/src/dev/testSampleValue.json +747 -0
- package/src/fromHTML.js +5 -0
- package/src/index.js +9 -0
- package/src/plugins/ListItem.js +49 -0
- package/src/plugins/SoftBreak.js +24 -0
- package/src/toHTML.js +7 -0
- package/src/toText.js +7 -0
- package/src/util.js +20 -0
- package/storyLoader.js +46 -0
- package/tailwind.config.js +5 -0
- package/webpack.config.build.js +53 -0
- package/webpack.config.dev.js +61 -0
- package/webpack.config.js +117 -0
package/src/Storybook.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
|
|
2
|
+
import React, {
|
|
3
|
+
useRef, useCallback, useEffect, useContext,
|
|
4
|
+
} from "react";
|
|
5
|
+
import {createPortal} from "react-dom";
|
|
6
|
+
// eslint-disable-next-line import/no-unresolved
|
|
7
|
+
import "scss/storybook.scss";
|
|
8
|
+
import {StorybookContext} from "./Context/StorybookContext";
|
|
9
|
+
|
|
10
|
+
export const Storybook = ({
|
|
11
|
+
applyChanges,
|
|
12
|
+
block,
|
|
13
|
+
attributes,
|
|
14
|
+
}) => {
|
|
15
|
+
const storybookContext = useContext(StorybookContext);
|
|
16
|
+
const iframeRef = useRef();
|
|
17
|
+
|
|
18
|
+
const sendIframeMessage = (message) => {
|
|
19
|
+
if (!iframeRef.current) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
iframeRef.current.contentWindow.postMessage(message, '*');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const onLoad = () => {
|
|
27
|
+
sendIframeMessage({
|
|
28
|
+
type: "block-editor-ready",
|
|
29
|
+
current: {
|
|
30
|
+
block,
|
|
31
|
+
config: attributes,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const onMessageReceivedFromIframe = useCallback(event => {
|
|
37
|
+
try {
|
|
38
|
+
if (iframeRef.current.contentWindow !== event.source) {
|
|
39
|
+
// this does NOT work, iframes are weird... lets see if we really need this :D
|
|
40
|
+
// return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const message = event.data;
|
|
44
|
+
|
|
45
|
+
switch (message.type) {
|
|
46
|
+
case "block-editor-applyChanges":
|
|
47
|
+
applyChanges(message.data);
|
|
48
|
+
break;
|
|
49
|
+
case "block-editor-storybook-ready":
|
|
50
|
+
onLoad();
|
|
51
|
+
break;
|
|
52
|
+
case "storybook-control-cloudinary-image": {
|
|
53
|
+
if (!storybookContext.contentfulSdk) {
|
|
54
|
+
console.error("Contentful sdk missing :(");
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
storybookContext.contentfulSdk.dialogs.openCurrentApp({
|
|
59
|
+
width: "fullWidth",
|
|
60
|
+
title: "Select Image",
|
|
61
|
+
shouldCloseOnOverlayClick: true,
|
|
62
|
+
shouldCloseOnEscapePress: true,
|
|
63
|
+
parameters: {type: "cloudinary"},
|
|
64
|
+
}).then((image) => {
|
|
65
|
+
sendIframeMessage({
|
|
66
|
+
type: "storybook-control-cloudinary-image-response",
|
|
67
|
+
image: image?.assets?.[0] || null,
|
|
68
|
+
issuer: message.issuer,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "storybook-control-cloudinary-images": {
|
|
74
|
+
if (!storybookContext.contentfulSdk) {
|
|
75
|
+
console.error("Contentful sdk missing :(");
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
storybookContext.contentfulSdk.dialogs.openCurrentApp({
|
|
80
|
+
width: "fullWidth",
|
|
81
|
+
title: "Select Images",
|
|
82
|
+
shouldCloseOnOverlayClick: true,
|
|
83
|
+
shouldCloseOnEscapePress: true,
|
|
84
|
+
parameters: {
|
|
85
|
+
type: "cloudinary",
|
|
86
|
+
multiple: true,
|
|
87
|
+
},
|
|
88
|
+
}).then((images) => {
|
|
89
|
+
sendIframeMessage({
|
|
90
|
+
type: "storybook-control-cloudinary-images-response",
|
|
91
|
+
images: images?.assets || [],
|
|
92
|
+
issuer: message.issuer,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "storybook-control-contentful-content":
|
|
98
|
+
if (!storybookContext.contentfulSdk) {
|
|
99
|
+
console.error("Contentful sdk missing :(");
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
storybookContext.contentfulSdk.dialogs.selectSingleEntry({contentTypes: message.contentTypes}).then((content) => {
|
|
104
|
+
sendIframeMessage({
|
|
105
|
+
type: "storybook-control-contentful-content-response",
|
|
106
|
+
content: content,
|
|
107
|
+
issuer: message.issuer,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
break;
|
|
111
|
+
case "storybook-control-contentful-contents":
|
|
112
|
+
if (!storybookContext.contentfulSdk) {
|
|
113
|
+
console.error("Contentful sdk missing :(");
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
storybookContext.contentfulSdk.dialogs.selectMultipleEntries({contentTypes: message.contentTypes}).then((contents) => {
|
|
118
|
+
sendIframeMessage({
|
|
119
|
+
type: "storybook-control-contentful-contents-response",
|
|
120
|
+
contents: contents,
|
|
121
|
+
issuer: message.issuer,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error("Error while parsing storybook message");
|
|
128
|
+
console.error(e);
|
|
129
|
+
}
|
|
130
|
+
}, [iframeRef.current]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
window.addEventListener("message", onMessageReceivedFromIframe);
|
|
134
|
+
|
|
135
|
+
return () => {
|
|
136
|
+
return window.removeEventListener("message", onMessageReceivedFromIframe);
|
|
137
|
+
};
|
|
138
|
+
}, [onMessageReceivedFromIframe]);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<Portal target={storybookContext.target}>
|
|
142
|
+
<div className="storybook-frame">
|
|
143
|
+
<iframe ref={iframeRef} src={storybookContext.storybookUrl} frameBorder="none"/>
|
|
144
|
+
</div>
|
|
145
|
+
</Portal>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
function Portal(props) {
|
|
150
|
+
return createPortal(props.children,
|
|
151
|
+
props.target.current);
|
|
152
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {useSlate} from "slate-react";
|
|
2
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import {Editor, Transforms} from "slate";
|
|
6
|
+
import {faAlignLeft, faAlignCenter, faAlignRight, faHeading} from "@fortawesome/free-solid-svg-icons";
|
|
7
|
+
|
|
8
|
+
export const AlignButton = ({align, icon, children, label}) => {
|
|
9
|
+
const editor = useSlate();
|
|
10
|
+
const onClick = (event) => {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
toggleAlign(editor, align);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<span
|
|
17
|
+
onMouseDown={onClick}
|
|
18
|
+
className={
|
|
19
|
+
classNames({
|
|
20
|
+
"toolbar-btn": true,
|
|
21
|
+
"active": isAlignActive(editor, align),
|
|
22
|
+
})
|
|
23
|
+
}>
|
|
24
|
+
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
25
|
+
{children}
|
|
26
|
+
</span>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const toggleAlign = (editor, format) => {
|
|
31
|
+
const isActive = isAlignActive(editor, format);
|
|
32
|
+
|
|
33
|
+
Transforms.setNodes(
|
|
34
|
+
editor,
|
|
35
|
+
{align: isActive ? null : format},
|
|
36
|
+
{
|
|
37
|
+
at: editor.selection,
|
|
38
|
+
match: node => Editor.isBlock(editor, node),
|
|
39
|
+
split: false,
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const isAlignActive = (editor, format) => {
|
|
45
|
+
const {selection} = editor;
|
|
46
|
+
if (selection) {
|
|
47
|
+
const selectedNodes = [editor.children[selection.anchor.path[0]]];
|
|
48
|
+
|
|
49
|
+
return !!selectedNodes.find(v => v.align === format);
|
|
50
|
+
} else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const AlignButtonLeft = () => {
|
|
56
|
+
return <AlignButton align="left" icon={faAlignLeft}/>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const AlignButtonCenter = () => {
|
|
60
|
+
return <AlignButton align="center" icon={faAlignCenter}/>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const AlignButtonRight = () => {
|
|
64
|
+
return <AlignButton align="right" icon={faAlignRight}/>;
|
|
65
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {useSlate} from "slate-react";
|
|
2
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import {
|
|
6
|
+
Editor, Transforms, Element as SlateElement,
|
|
7
|
+
} from "slate";
|
|
8
|
+
import {
|
|
9
|
+
faListUl, faListOl, faHeading, faQuoteLeft, faArrowRight,
|
|
10
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
11
|
+
|
|
12
|
+
const LIST_TYPES = ['unordered-list', 'ordered-list', 'arrow-list'];
|
|
13
|
+
|
|
14
|
+
export const BlockButton = ({
|
|
15
|
+
block,
|
|
16
|
+
icon,
|
|
17
|
+
children,
|
|
18
|
+
attributes,
|
|
19
|
+
}) => {
|
|
20
|
+
const editor = useSlate();
|
|
21
|
+
const onClick = (event) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
toggleBlock(editor, block, attributes);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<span
|
|
28
|
+
onMouseDown={onClick}
|
|
29
|
+
className={
|
|
30
|
+
classNames({
|
|
31
|
+
"toolbar-btn": true,
|
|
32
|
+
"active": isBlockActive(editor, block, attributes),
|
|
33
|
+
})
|
|
34
|
+
}>
|
|
35
|
+
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
36
|
+
{children}
|
|
37
|
+
</span>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const toggleBlock = (editor, format, attributes) => {
|
|
42
|
+
const isActive = isBlockActive(editor, format, attributes);
|
|
43
|
+
const isList = LIST_TYPES.includes(format);
|
|
44
|
+
|
|
45
|
+
Transforms.unwrapNodes(editor, {
|
|
46
|
+
match: n => {
|
|
47
|
+
return LIST_TYPES.includes(!Editor.isEditor(n) && SlateElement.isElement(n) && n.type);
|
|
48
|
+
},
|
|
49
|
+
split: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let newFormat = isActive ? "paragraph" : format;
|
|
53
|
+
|
|
54
|
+
if (!isActive && isList) {
|
|
55
|
+
newFormat = "list-item";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Transforms.setNodes(editor,
|
|
59
|
+
{
|
|
60
|
+
type: newFormat,
|
|
61
|
+
attributes: attributes,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!isActive && isList) {
|
|
65
|
+
const block = {
|
|
66
|
+
type: format,
|
|
67
|
+
children: [],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
Transforms.wrapNodes(editor, block);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const isBlockActive = (editor, format, attributes) => {
|
|
75
|
+
const {selection} = editor;
|
|
76
|
+
if (selection) {
|
|
77
|
+
const selectedNodes = [editor.children[selection.anchor.path[0]]];
|
|
78
|
+
|
|
79
|
+
return !!selectedNodes.find(v => {
|
|
80
|
+
if (Editor.isEditor(v)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!SlateElement.isElement(v)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (v.type !== format) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (format === "heading") {
|
|
93
|
+
return attributes.level === v.attributes.level;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return true;
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const BlockButtonHeading = ({level}) => {
|
|
104
|
+
return <BlockButton block="heading" attributes={{level: level}} icon={faHeading}><small>{level}</small></BlockButton>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const BlockButtonBlockquote = () => {
|
|
108
|
+
return <BlockButton block="blockquote" icon={faQuoteLeft}/>;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const BlockButtonUnorderedList = () => {
|
|
112
|
+
return <BlockButton block="unordered-list" icon={faListUl}/>;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const BlockButtonOrderedList = () => {
|
|
116
|
+
return <BlockButton block="ordered-list" icon={faListOl}/>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const BlockButtonArrowList = () => {
|
|
120
|
+
return <BlockButton block="arrow-list" icon={faArrowRight}/>;
|
|
121
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {useSlate} from "slate-react";
|
|
2
|
+
import {Transforms} from "slate";
|
|
3
|
+
import React, {
|
|
4
|
+
useContext, useState,
|
|
5
|
+
} from "react";
|
|
6
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
7
|
+
import {faPlus} from "@fortawesome/free-solid-svg-icons";
|
|
8
|
+
import {Storybook} from "../Storybook";
|
|
9
|
+
import {StorybookContext} from "../Context/StorybookContext";
|
|
10
|
+
|
|
11
|
+
export const StorybookButton = () => {
|
|
12
|
+
const editor = useSlate();
|
|
13
|
+
|
|
14
|
+
const onClick = (e) => {
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
Transforms.insertNodes(editor, [
|
|
17
|
+
{
|
|
18
|
+
children: [{text: ''}],
|
|
19
|
+
block: "Blocks/Empty",
|
|
20
|
+
attributes: {blockWidth: "site"},
|
|
21
|
+
isEmpty: true,
|
|
22
|
+
type: "storybook",
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const onClickInline = (e) => {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
Transforms.insertNodes(editor, {
|
|
30
|
+
children: [{text: ''}],
|
|
31
|
+
block: "Blocks/Empty",
|
|
32
|
+
attributes: {},
|
|
33
|
+
isInline: true,
|
|
34
|
+
isEmpty: true,
|
|
35
|
+
type: "storybook",
|
|
36
|
+
}, {select: true});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return <>
|
|
40
|
+
<span className={"toolbar-btn"} onMouseDown={onClick}>
|
|
41
|
+
<FontAwesomeIcon icon={faPlus} />
|
|
42
|
+
<span> Element hinzufügen</span>
|
|
43
|
+
</span>
|
|
44
|
+
<span className={"toolbar-btn"} onMouseDown={onClickInline}>
|
|
45
|
+
<FontAwesomeIcon icon={faPlus} />
|
|
46
|
+
<span> Inline Element hinzufügen</span>
|
|
47
|
+
</span>
|
|
48
|
+
</>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {useSlate} from "slate-react";
|
|
2
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
3
|
+
import React, {useState} from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import {Editor, Text, Transforms} from "slate";
|
|
6
|
+
import {faBold, faItalic, faUnderline, faStrikethrough} from "@fortawesome/free-solid-svg-icons";
|
|
7
|
+
|
|
8
|
+
export const FormatButton = ({format, icon, children}) => {
|
|
9
|
+
const editor = useSlate();
|
|
10
|
+
const onClick = (event) => {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
toggleFormat(editor, format);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<span
|
|
17
|
+
onMouseDown={onClick}
|
|
18
|
+
className={
|
|
19
|
+
classNames({
|
|
20
|
+
"toolbar-btn": true,
|
|
21
|
+
"active": isFormatActive(editor, format),
|
|
22
|
+
})
|
|
23
|
+
}>
|
|
24
|
+
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
25
|
+
{children}
|
|
26
|
+
</span>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const toggleFormat = (editor, format) => {
|
|
31
|
+
const isActive = isFormatActive(editor, format);
|
|
32
|
+
Editor.addMark(editor, format, !isActive);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const isFormatActive = (editor, format) => {
|
|
36
|
+
try {
|
|
37
|
+
const marks = Editor.marks(editor);
|
|
38
|
+
return marks ? marks[format] === true : false;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(e);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const FormatButtonBold = () => {
|
|
47
|
+
return <FormatButton format="bold" icon={faBold}/>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const FormatButtonItalic = () => {
|
|
51
|
+
return <FormatButton format="italic" icon={faItalic}/>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const FormatButtonUnderline = () => {
|
|
55
|
+
return <FormatButton format="underlined" icon={faUnderline}/>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const FormatButtonStrikethrough = () => {
|
|
59
|
+
return <FormatButton format="strikethrough" icon={faStrikethrough}/>;
|
|
60
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {useSlate} from "slate-react";
|
|
2
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import {Transforms} from "slate";
|
|
5
|
+
|
|
6
|
+
export const InsertButton = ({insert, icon, children}) => {
|
|
7
|
+
const editor = useSlate();
|
|
8
|
+
const onClick = (event) => {
|
|
9
|
+
event.preventDefault();
|
|
10
|
+
Transforms.insertNodes(editor, [insert]);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<span onMouseDown={onClick} className="toolbar-btn">
|
|
15
|
+
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
16
|
+
{children}
|
|
17
|
+
</span>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export const InsertDividerButton = () => {
|
|
23
|
+
return <InsertButton insert={{
|
|
24
|
+
"type": "divider",
|
|
25
|
+
"children": [{"text": ""}],
|
|
26
|
+
}}>
|
|
27
|
+
<span>Trennlinie einfügen</span>
|
|
28
|
+
</InsertButton>;
|
|
29
|
+
};
|