@vonaffenfels/slate-editor 1.1.71 → 1.2.10
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 +43 -43
- package/README.md +5 -5
- package/componentLoader.js +93 -93
- package/dist/BlockEditor.css +4 -1871
- package/dist/BlockEditor.js +336 -3960
- package/dist/BlockEditor.js.LICENSE.txt +61 -0
- package/dist/Renderer.js +2 -2081
- package/dist/Renderer.js.LICENSE.txt +15 -0
- package/dist/fromHTML.js +1 -78
- package/dist/index.css +4 -1871
- package/dist/index.js +336 -4037
- package/dist/index.js.LICENSE.txt +69 -0
- package/dist/toHTML.js +2 -1689
- package/dist/toHTML.js.LICENSE.txt +23 -0
- package/dist/toText.js +2 -1689
- package/dist/toText.js.LICENSE.txt +23 -0
- package/package.json +2 -2
- package/postcss.config.js +6 -6
- package/scss/demo.scss +148 -148
- package/scss/editor.scss +17 -5
- package/scss/sidebarEditor.scss +185 -181
- package/scss/toolbar.scss +161 -161
- package/src/BlockEditor.js +6 -3
- package/src/Blocks/EmptyBlock.js +11 -11
- package/src/Blocks/EmptyWrapper.js +4 -4
- package/src/Blocks/ErrorBoundary.js +40 -40
- package/src/Blocks/LayoutBlock.js +274 -274
- package/src/Blocks/LayoutSlot.js +90 -90
- package/src/CollapsableMenu/CollapsableMenu.js +48 -48
- package/src/Context/StorybookContext.js +6 -6
- package/src/ElementAutocomplete.js +133 -133
- package/src/Loader.js +137 -137
- package/src/Nodes/Default.js +158 -158
- package/src/Nodes/Leaf.js +54 -54
- package/src/Nodes/Text.js +97 -97
- package/src/ObjectId.js +3 -3
- package/src/Renderer.js +73 -73
- package/src/Serializer/Html.js +42 -42
- package/src/Serializer/Serializer.js +371 -371
- package/src/Serializer/Text.js +17 -17
- package/src/Serializer/ads.js +174 -174
- package/src/Serializer/index.js +3 -3
- package/src/SidebarEditor/AssetList.js +181 -181
- package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
- package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
- package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
- package/src/SidebarEditor/Fields/DateTime.js +55 -55
- package/src/SidebarEditor/Fields/MVP.js +66 -66
- package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
- package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
- package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
- package/src/SidebarEditor/Fields/Select.js +47 -47
- package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
- package/src/SidebarEditor/Fields/Switch.js +34 -34
- package/src/SidebarEditor/Fields/Textarea.js +21 -21
- package/src/SidebarEditor/Resizable.js +85 -85
- package/src/Storybook.js +151 -151
- package/src/Toolbar/Align.js +64 -64
- package/src/Toolbar/Anchor.js +94 -94
- package/src/Toolbar/Block.js +135 -135
- package/src/Toolbar/Element.js +44 -44
- package/src/Toolbar/Formats.js +71 -71
- package/src/Toolbar/Insert.js +28 -28
- package/src/Toolbar/Layout.js +399 -399
- package/src/Toolbar/Link.js +164 -164
- package/src/Toolbar/Toolbar.js +235 -235
- package/src/Tools/Margin.js +51 -51
- package/src/Translation/TranslationToolbarButton.js +119 -115
- package/src/dev/draftToSlate.json +3147 -3147
- package/src/dev/index.css +2 -2
- package/src/dev/index.html +10 -10
- package/src/dev/index.js +4 -4
- package/src/dev/sampleValue1.json +4294 -4294
- package/src/dev/sampleValueValid.json +410 -410
- package/src/dev/testComponents/TestStory.js +74 -74
- package/src/dev/testComponents/TestStory.stories.js +216 -216
- package/src/dev/testComponents/TestStory2.js +74 -74
- package/src/dev/testComponents/TestStory2.stories.js +197 -197
- package/src/dev/testComponents/TestStory3.js +74 -74
- package/src/dev/testComponents/TestStory3.stories.js +197 -197
- package/src/dev/testSampleValue.json +746 -746
- package/src/fromHTML.js +4 -4
- package/src/helper/array.js +8 -8
- package/src/index.js +10 -10
- package/src/plugins/ListItem.js +48 -48
- package/src/plugins/SoftBreak.js +23 -23
- package/src/toHTML.js +6 -6
- package/src/toText.js +6 -6
- package/src/util/reduceContentfulResponse.js +64 -64
- package/src/util.js +19 -19
- package/storyLoader.js +47 -47
- package/tailwind.config.js +4 -4
- package/webpack.config.build.js +55 -55
- package/webpack.config.dev.js +60 -60
- package/webpack.config.js +130 -130
- package/webpack.config.watch.js +4 -4
package/src/Storybook.js
CHANGED
|
@@ -1,152 +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);
|
|
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
152
|
}
|
package/src/Toolbar/Align.js
CHANGED
|
@@ -1,65 +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}/>;
|
|
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
65
|
};
|
package/src/Toolbar/Anchor.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ReactEditor, useSlate,
|
|
3
|
-
} from "slate-react";
|
|
4
|
-
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
5
|
-
import React, {
|
|
6
|
-
useEffect, useState,
|
|
7
|
-
} from "react";
|
|
8
|
-
import classNames from "classnames";
|
|
9
|
-
import {
|
|
10
|
-
Editor, Transforms, Element as SlateElement, Range, Node,
|
|
11
|
-
} from "slate";
|
|
12
|
-
import {
|
|
13
|
-
faAnchor, faLink,
|
|
14
|
-
} from "@fortawesome/free-solid-svg-icons";
|
|
15
|
-
|
|
16
|
-
export const AnchorButtonElement = ({
|
|
17
|
-
icon,
|
|
18
|
-
children,
|
|
19
|
-
}) => {
|
|
20
|
-
const editor = useSlate();
|
|
21
|
-
|
|
22
|
-
const [anchor, setAnchor] = useState("");
|
|
23
|
-
const [node, setNode] = useState(undefined);
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (editor?.selection?.anchor?.path?.[0] !== undefined) {
|
|
27
|
-
let node = Node.get(editor, [editor?.selection?.anchor?.path?.[0]]);
|
|
28
|
-
|
|
29
|
-
setAnchor(node?.attributes?.id || "");
|
|
30
|
-
setNode(node);
|
|
31
|
-
}
|
|
32
|
-
}, [editor?.selection?.anchor?.path?.[0], editor]);
|
|
33
|
-
|
|
34
|
-
const apply = (value) => {
|
|
35
|
-
// Node.get could return editor itself
|
|
36
|
-
if (!node?.type) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let path = ReactEditor.findPath(editor, node);
|
|
41
|
-
|
|
42
|
-
let newNode = {
|
|
43
|
-
...node,
|
|
44
|
-
attributes: {
|
|
45
|
-
...node.attributes,
|
|
46
|
-
id: anchor,
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
setNode(newNode);
|
|
51
|
-
|
|
52
|
-
Transforms.setNodes(editor, newNode, {at: path});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const reset = () => {
|
|
56
|
-
apply("");
|
|
57
|
-
|
|
58
|
-
return;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<span
|
|
63
|
-
className={
|
|
64
|
-
classNames({
|
|
65
|
-
"toolbar-btn": true,
|
|
66
|
-
"active": node?.attributes?.id,
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
>
|
|
70
|
-
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
71
|
-
{children}
|
|
72
|
-
<span className="toolbar-btn-config">
|
|
73
|
-
<span className="toolbar-btn-config-inner">
|
|
74
|
-
<span className="toolbar-btn-config-row">
|
|
75
|
-
<label className="toolbar-form-label">
|
|
76
|
-
Ankername
|
|
77
|
-
</label>
|
|
78
|
-
<span className="toolbar-form-input">
|
|
79
|
-
<input type="text" value={anchor} onChange={(e) => setAnchor(e.target.value)}/>
|
|
80
|
-
</span>
|
|
81
|
-
</span>
|
|
82
|
-
<span className="toolbar-btn-config-row">
|
|
83
|
-
<span className="toolbar-btn" onMouseDown={() => apply(anchor)}>Apply</span>
|
|
84
|
-
{node?.attributes?.id && <span className="toolbar-btn" onMouseDown={reset}>Remove</span>}
|
|
85
|
-
</span>
|
|
86
|
-
</span>
|
|
87
|
-
</span>
|
|
88
|
-
</span>
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export const AnchorButton = () => {
|
|
94
|
-
return <AnchorButtonElement icon={faAnchor}/>;
|
|
1
|
+
import {
|
|
2
|
+
ReactEditor, useSlate,
|
|
3
|
+
} from "slate-react";
|
|
4
|
+
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
|
5
|
+
import React, {
|
|
6
|
+
useEffect, useState,
|
|
7
|
+
} from "react";
|
|
8
|
+
import classNames from "classnames";
|
|
9
|
+
import {
|
|
10
|
+
Editor, Transforms, Element as SlateElement, Range, Node,
|
|
11
|
+
} from "slate";
|
|
12
|
+
import {
|
|
13
|
+
faAnchor, faLink,
|
|
14
|
+
} from "@fortawesome/free-solid-svg-icons";
|
|
15
|
+
|
|
16
|
+
export const AnchorButtonElement = ({
|
|
17
|
+
icon,
|
|
18
|
+
children,
|
|
19
|
+
}) => {
|
|
20
|
+
const editor = useSlate();
|
|
21
|
+
|
|
22
|
+
const [anchor, setAnchor] = useState("");
|
|
23
|
+
const [node, setNode] = useState(undefined);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (editor?.selection?.anchor?.path?.[0] !== undefined) {
|
|
27
|
+
let node = Node.get(editor, [editor?.selection?.anchor?.path?.[0]]);
|
|
28
|
+
|
|
29
|
+
setAnchor(node?.attributes?.id || "");
|
|
30
|
+
setNode(node);
|
|
31
|
+
}
|
|
32
|
+
}, [editor?.selection?.anchor?.path?.[0], editor]);
|
|
33
|
+
|
|
34
|
+
const apply = (value) => {
|
|
35
|
+
// Node.get could return editor itself
|
|
36
|
+
if (!node?.type) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let path = ReactEditor.findPath(editor, node);
|
|
41
|
+
|
|
42
|
+
let newNode = {
|
|
43
|
+
...node,
|
|
44
|
+
attributes: {
|
|
45
|
+
...node.attributes,
|
|
46
|
+
id: anchor,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
setNode(newNode);
|
|
51
|
+
|
|
52
|
+
Transforms.setNodes(editor, newNode, {at: path});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const reset = () => {
|
|
56
|
+
apply("");
|
|
57
|
+
|
|
58
|
+
return;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<span
|
|
63
|
+
className={
|
|
64
|
+
classNames({
|
|
65
|
+
"toolbar-btn": true,
|
|
66
|
+
"active": node?.attributes?.id,
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
>
|
|
70
|
+
{!!icon && <FontAwesomeIcon icon={icon} />}
|
|
71
|
+
{children}
|
|
72
|
+
<span className="toolbar-btn-config">
|
|
73
|
+
<span className="toolbar-btn-config-inner">
|
|
74
|
+
<span className="toolbar-btn-config-row">
|
|
75
|
+
<label className="toolbar-form-label">
|
|
76
|
+
Ankername
|
|
77
|
+
</label>
|
|
78
|
+
<span className="toolbar-form-input">
|
|
79
|
+
<input type="text" value={anchor} onChange={(e) => setAnchor(e.target.value)}/>
|
|
80
|
+
</span>
|
|
81
|
+
</span>
|
|
82
|
+
<span className="toolbar-btn-config-row">
|
|
83
|
+
<span className="toolbar-btn" onMouseDown={() => apply(anchor)}>Apply</span>
|
|
84
|
+
{node?.attributes?.id && <span className="toolbar-btn" onMouseDown={reset}>Remove</span>}
|
|
85
|
+
</span>
|
|
86
|
+
</span>
|
|
87
|
+
</span>
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export const AnchorButton = () => {
|
|
94
|
+
return <AnchorButtonElement icon={faAnchor}/>;
|
|
95
95
|
};
|