@vonaffenfels/slate-editor 1.1.25 → 1.1.27
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 +1 -1
- package/dist/BlockEditor.js +76 -8
- package/dist/Renderer.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +71 -3
- package/package.json +2 -2
- package/src/Nodes/StorybookDisplay.js +3 -3
- package/src/SidebarEditor/Fields/MultiSelect.js +14 -0
- package/src/SidebarEditor/Fields/RemoteSelect.js +33 -0
- package/src/SidebarEditor/Fields/Select.js +48 -0
- package/src/SidebarEditor/SidebarEditorField.js +13 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"cssnano": "^5.0.1",
|
|
73
73
|
"escape-html": "^1.0.3"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "78986d6bb0100171800ced4a7c77c3d08de9e002",
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
}
|
|
@@ -130,9 +130,9 @@ const BlockComponent = ({
|
|
|
130
130
|
"editor-mr-large": loadedAttributes?.margin?.right,
|
|
131
131
|
"editor-mb-large": loadedAttributes?.margin?.bottom,
|
|
132
132
|
"editor-ml-large": loadedAttributes?.margin?.left,
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
133
|
+
"block-hide-on-desktop": loadedAttributes?.hideOnDesktop && !isEditor,
|
|
134
|
+
"block-hide-on-tablet": loadedAttributes?.hideOnTablet && !isEditor,
|
|
135
|
+
"block-hide-on-smartphone": loadedAttributes?.hideOnSmartphone && !isEditor,
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
if (!wrapperClassName) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {renderFieldSelectOptions} from "./Select";
|
|
2
|
+
import {
|
|
3
|
+
useEffect, useState,
|
|
4
|
+
} from "react";
|
|
5
|
+
|
|
6
|
+
export const RemoteSelect = ({
|
|
7
|
+
value,
|
|
8
|
+
field,
|
|
9
|
+
onChange,
|
|
10
|
+
}) => {
|
|
11
|
+
const [options, setOptions] = useState([]);
|
|
12
|
+
|
|
13
|
+
const reloadOptions = async () => {
|
|
14
|
+
setOptions(await fetch(field.control.url).then(res => res.json()));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
reloadOptions();
|
|
19
|
+
}, [field]);
|
|
20
|
+
|
|
21
|
+
return <select
|
|
22
|
+
value={value || ""}
|
|
23
|
+
onChange={onChange}>
|
|
24
|
+
<option value="">Auswählen</option>
|
|
25
|
+
{renderFieldSelectOptions({
|
|
26
|
+
...field,
|
|
27
|
+
control: {
|
|
28
|
+
...field.control,
|
|
29
|
+
options,
|
|
30
|
+
},
|
|
31
|
+
})}
|
|
32
|
+
</select>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
export const Select = ({
|
|
3
|
+
value,
|
|
4
|
+
field,
|
|
5
|
+
onChange,
|
|
6
|
+
}) => {
|
|
7
|
+
return <select
|
|
8
|
+
value={value || ""}
|
|
9
|
+
onChange={onChange}>
|
|
10
|
+
<option value="">Auswählen</option>
|
|
11
|
+
{renderFieldSelectOptions(field)}
|
|
12
|
+
</select>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const renderFieldSelectOptions = field => {
|
|
16
|
+
if (field.options) {
|
|
17
|
+
field.control.options = field.options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (field?.control?.labels) {
|
|
21
|
+
field.control.options = field.control.labels;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!field?.control?.options) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (Array.isArray(field.control.options)) {
|
|
29
|
+
return field.control.options.map(option => {
|
|
30
|
+
if (option && typeof option === "object") {
|
|
31
|
+
return <option key={`select-option-${option.value}`} value={option.value}>{option.label}</option>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return <option key={`select-option-${option}`} value={option}>{option}</option>;
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
return Object.keys(field.control.options).map(key => {
|
|
38
|
+
// Prevents false values being a string, e.g. "false"
|
|
39
|
+
if (!field.control.options[key]) {
|
|
40
|
+
field.control.options[key] = "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<option key={`select-option-${key}`} value={field.control.options[key]}>{key}</option>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
Asset, AssetList,
|
|
6
6
|
} from "./AssetList";
|
|
7
7
|
import {Switch} from "./Switch";
|
|
8
|
+
import {Select} from "./Fields/Select";
|
|
9
|
+
import {RemoteSelect} from "./Fields/RemoteSelect";
|
|
10
|
+
import {MultiSelect} from "./Fields/MultiSelect";
|
|
8
11
|
|
|
9
12
|
export const SidebarEditorField = ({
|
|
10
13
|
field,
|
|
@@ -37,37 +40,6 @@ export const SidebarEditorField = ({
|
|
|
37
40
|
onChange(fieldKey, swapArrayElements(value, index, newIndex));
|
|
38
41
|
};
|
|
39
42
|
|
|
40
|
-
const renderFieldSelectOptions = field => {
|
|
41
|
-
if (field.options) {
|
|
42
|
-
field.control.options = field.options;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (field?.control?.labels) {
|
|
46
|
-
field.control.options = field.control.labels;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!field?.control?.options) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (Array.isArray(field.control.options)) {
|
|
54
|
-
return field.control.options.map(value => (
|
|
55
|
-
<option key={`select-option-${value}`} value={value}>{value}</option>
|
|
56
|
-
));
|
|
57
|
-
} else {
|
|
58
|
-
return Object.keys(field.control.options).map(key => {
|
|
59
|
-
// Prevents false values being a string, e.g. "false"
|
|
60
|
-
if (!field.control.options[key]) {
|
|
61
|
-
field.control.options[key] = "";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<option key={`select-option-${key}`} value={field.control.options[key]}>{key}</option>
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
43
|
const getInputByField = (field, fieldKey) => {
|
|
72
44
|
if (!field) {
|
|
73
45
|
return null;
|
|
@@ -114,14 +86,9 @@ export const SidebarEditorField = ({
|
|
|
114
86
|
</div>
|
|
115
87
|
);
|
|
116
88
|
case "select":
|
|
117
|
-
return (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
onChange={e => onChange(fieldKey, e.target.value)}>
|
|
121
|
-
<option value="">Auswählen</option>
|
|
122
|
-
{renderFieldSelectOptions(field)}
|
|
123
|
-
</select>
|
|
124
|
-
);
|
|
89
|
+
return <Select onChange={e => onChange(fieldKey, e.target.value)} field={field} value={value} />;
|
|
90
|
+
case "remote-select":
|
|
91
|
+
return <RemoteSelect onChange={e => onChange(fieldKey, e.target.value)} field={field} value={value} />;
|
|
125
92
|
case "data-stream":
|
|
126
93
|
return (
|
|
127
94
|
<select
|
|
@@ -268,18 +235,14 @@ export const SidebarEditorField = ({
|
|
|
268
235
|
onChange={e => onChange(fieldKey, e.target.value)}/>
|
|
269
236
|
);
|
|
270
237
|
case "multi-select":
|
|
271
|
-
return
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
let v = Array.from(e.target.selectedOptions, option => option.value);
|
|
238
|
+
return <MultiSelect
|
|
239
|
+
value={value}
|
|
240
|
+
field={field}
|
|
241
|
+
onChange={e => {
|
|
242
|
+
let v = Array.from(e.target.selectedOptions, option => option.value);
|
|
277
243
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
{renderFieldSelectOptions(field)}
|
|
281
|
-
</select>
|
|
282
|
-
);
|
|
244
|
+
onChange(fieldKey, v);
|
|
245
|
+
}} />;
|
|
283
246
|
case "contentful-content":
|
|
284
247
|
return (
|
|
285
248
|
<>
|