@vonaffenfels/slate-editor 1.0.62 → 1.0.63
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/BlockEditor.css +2 -2
- package/dist/BlockEditor.js +1 -1
- package/dist/index.css +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/scss/sidebarEditor.scss +20 -0
- package/src/BlockEditor.js +0 -26
- package/src/CollapsableMenu/CollapsableMenu.js +46 -0
- package/src/SidebarEditor.js +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"cssnano": "^5.0.1",
|
|
72
72
|
"escape-html": "^1.0.3"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "fe0fcf870d95e0f1c3cc6e8edd31a4c70465df63",
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
}
|
package/scss/sidebarEditor.scss
CHANGED
|
@@ -156,4 +156,24 @@
|
|
|
156
156
|
.message.message--negative {
|
|
157
157
|
background-color: rgba(238, 26, 26, 0.2);
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
.collapsable-menu {
|
|
161
|
+
background-color: white !important;
|
|
162
|
+
border: 1px solid #cfd9e0 !important;
|
|
163
|
+
border-radius: 6px;
|
|
164
|
+
z-index: 2;
|
|
165
|
+
overflow: hidden;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.collapsable-menu-item {
|
|
169
|
+
color: rgb(90, 101, 124) !important;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.collapsable-menu-item:not(.disabled):hover {
|
|
173
|
+
background-color: rgb(248, 248, 248) !important;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.collapsable-menu-item:not(.disabled):active {
|
|
177
|
+
background-color: rgb(237, 237, 237) !important;
|
|
178
|
+
}
|
|
159
179
|
}
|
package/src/BlockEditor.js
CHANGED
|
@@ -93,32 +93,6 @@ export default function BlockEditor({
|
|
|
93
93
|
loadStories();
|
|
94
94
|
}, []);
|
|
95
95
|
|
|
96
|
-
const handleKeyDown = (e) => {
|
|
97
|
-
let keyCode = e.keyCode || e.which;
|
|
98
|
-
|
|
99
|
-
switch (keyCode) {
|
|
100
|
-
case 46: // delete
|
|
101
|
-
case 8: // backspace
|
|
102
|
-
handleSidebarDeleteClick();
|
|
103
|
-
break;
|
|
104
|
-
case 27: // escape
|
|
105
|
-
handleSidebarClose();
|
|
106
|
-
break;
|
|
107
|
-
default:
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (selectedStorybookElement) {
|
|
114
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
115
|
-
} else {
|
|
116
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
120
|
-
}, [selectedStorybookElement]);
|
|
121
|
-
|
|
122
96
|
const resetEditor = () => {
|
|
123
97
|
if (confirm("This action will delete all data in the editor, are you sure?")) {
|
|
124
98
|
onChange(emptyValue);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {useState} from "react";
|
|
2
|
+
|
|
3
|
+
export const CollapsableMenu = ({
|
|
4
|
+
button,
|
|
5
|
+
children,
|
|
6
|
+
...props
|
|
7
|
+
}) => {
|
|
8
|
+
const [collapsed, setCollapsed] = useState(true);
|
|
9
|
+
|
|
10
|
+
children = children.map(child => ({
|
|
11
|
+
...child,
|
|
12
|
+
props: {
|
|
13
|
+
...child.props,
|
|
14
|
+
onClick: () => {
|
|
15
|
+
child.props.onClick();
|
|
16
|
+
setCollapsed(true);
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="relative">
|
|
23
|
+
<div className="relative">
|
|
24
|
+
<div onClick={() => setCollapsed(!collapsed)}>
|
|
25
|
+
{button}
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
{!collapsed && (
|
|
29
|
+
<div className="collapsable-menu absolute right-0 mt-2 w-52">
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
)}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const CollapsableMenuItem = ({
|
|
38
|
+
children,
|
|
39
|
+
onClick,
|
|
40
|
+
}) => {
|
|
41
|
+
return (
|
|
42
|
+
<div className="collapsable-menu-item cursor-pointer px-4 py-2" onClick={onClick}>
|
|
43
|
+
{children}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
};
|
package/src/SidebarEditor.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
useState, useEffect,
|
|
3
3
|
} from "react";
|
|
4
4
|
import {SidebarEditorField} from "./SidebarEditor/SidebarEditorField";
|
|
5
5
|
import {ToolMargin} from "./Tools/Margin";
|
|
6
6
|
import "../scss/sidebarEditor.scss";
|
|
7
7
|
import {Spinner} from "@contentful/forma-36-react-components";
|
|
8
8
|
import {ElementAutocomplete} from "./ElementAutocomplete";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
CollapsableMenu, CollapsableMenuItem,
|
|
11
|
+
} from "./CollapsableMenu/CollapsableMenu";
|
|
11
12
|
|
|
12
13
|
const SidebarEditor = ({
|
|
13
14
|
sdk,
|
|
@@ -229,9 +230,14 @@ const SidebarEditor = ({
|
|
|
229
230
|
↓
|
|
230
231
|
</IconButton>
|
|
231
232
|
</div>
|
|
232
|
-
<IconButton title="Löschen" onClick={() => onDelete && onDelete(storybookElement)}>
|
|
233
|
+
<IconButton title="Löschen" className="mr-1" onClick={() => onDelete && onDelete(storybookElement)}>
|
|
233
234
|
🗑
|
|
234
235
|
</IconButton>
|
|
236
|
+
<CollapsableMenu button={<IconButton title="Funktionen">…</IconButton>}>
|
|
237
|
+
<CollapsableMenuItem onClick={onDuplicate}>Duplizieren</CollapsableMenuItem>
|
|
238
|
+
<CollapsableMenuItem onClick={() => onInsert("above")}>Davor hinzufügen</CollapsableMenuItem>
|
|
239
|
+
<CollapsableMenuItem onClick={() => onInsert("below")}>Danach hinzufügen</CollapsableMenuItem>
|
|
240
|
+
</CollapsableMenu>
|
|
235
241
|
</div>
|
|
236
242
|
)}
|
|
237
243
|
</div>
|
|
@@ -241,13 +247,6 @@ const SidebarEditor = ({
|
|
|
241
247
|
</div>
|
|
242
248
|
<div className="grow overflow-y-auto pr-2 pt-2">
|
|
243
249
|
{renderTitle()}
|
|
244
|
-
<div className="mb-2">
|
|
245
|
-
<button className="button button--tertiary" onClick={onDuplicate}>Duplizieren</button>
|
|
246
|
-
</div>
|
|
247
|
-
<div className="mb-2 flex">
|
|
248
|
-
<button className="button button--tertiary mr-1" onClick={() => onInsert("above")}>Davor hinzufügen</button>
|
|
249
|
-
<button className="button button--tertiary ml-1" onClick={() => onInsert("below")}>Danach hinzufügen</button>
|
|
250
|
-
</div>
|
|
251
250
|
<div className="mb-2">
|
|
252
251
|
<ElementAutocomplete
|
|
253
252
|
isLoading={isLoading}
|
|
@@ -330,6 +329,7 @@ export const IconButton = ({
|
|
|
330
329
|
disabled,
|
|
331
330
|
size = "medium",
|
|
332
331
|
className,
|
|
332
|
+
onClick = () => {},
|
|
333
333
|
...props
|
|
334
334
|
}) => {
|
|
335
335
|
let classNames = "icon-button cursor-pointer select-none !p-1";
|
|
@@ -355,7 +355,7 @@ export const IconButton = ({
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
return (
|
|
358
|
-
<div className={classNames} {...props}>
|
|
358
|
+
<div className={classNames} onClick={onClick} {...props}>
|
|
359
359
|
{children}
|
|
360
360
|
</div>
|
|
361
361
|
);
|