@vonaffenfels/slate-editor 1.2.29 → 1.2.39
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.39",
|
|
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": "46607d2d7b190f03ad2b2fa84d466d7133dea27b",
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
}
|
|
@@ -1,182 +1,186 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useEffect, useState,
|
|
3
|
-
} from "react";
|
|
4
|
-
import {IconButton} from "../SidebarEditor";
|
|
5
|
-
import {swapArrayElements} from "../helper/array";
|
|
6
|
-
|
|
7
|
-
// Hallo :)
|
|
8
|
-
export const AssetList = ({
|
|
9
|
-
assets,
|
|
10
|
-
onChange,
|
|
11
|
-
sdk,
|
|
12
|
-
cloudinary = false,
|
|
13
|
-
onAddClick,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
newAssets
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (mediaUrl?.endsWith(".
|
|
136
|
-
assetType = "
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
case "
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
1
|
+
import {
|
|
2
|
+
useEffect, useState,
|
|
3
|
+
} from "react";
|
|
4
|
+
import {IconButton} from "../SidebarEditor";
|
|
5
|
+
import {swapArrayElements} from "../helper/array";
|
|
6
|
+
|
|
7
|
+
// Hallo :)
|
|
8
|
+
export const AssetList = ({
|
|
9
|
+
assets,
|
|
10
|
+
onChange,
|
|
11
|
+
sdk,
|
|
12
|
+
cloudinary = false,
|
|
13
|
+
onAddClick,
|
|
14
|
+
displayField,
|
|
15
|
+
}) => {
|
|
16
|
+
const renderAssets = assets.filter(Boolean).map((asset, index) => (
|
|
17
|
+
<>
|
|
18
|
+
<Asset
|
|
19
|
+
key={asset.sys?.id}
|
|
20
|
+
asset={asset}
|
|
21
|
+
index={index}
|
|
22
|
+
sdk={sdk}
|
|
23
|
+
cloudinary={cloudinary}
|
|
24
|
+
assetsLength={assets.length}
|
|
25
|
+
onMoveClick={(direction) => handleMoveClick(direction, index)}
|
|
26
|
+
onDeleteClick={() => handleDeleteClick(index)}
|
|
27
|
+
onChange={handleChange}
|
|
28
|
+
displayField={displayField}
|
|
29
|
+
/>
|
|
30
|
+
<hr className="my-2" style={{borderColor: "#cfd9e0"}}/>
|
|
31
|
+
{onAddClick && index === assets.length - 1 && <button onClick={onAddClick} className="button button--secondary">Hinzufügen</button>}
|
|
32
|
+
</>
|
|
33
|
+
));
|
|
34
|
+
|
|
35
|
+
const handleMoveClick = (direction, index) => {
|
|
36
|
+
let newIndex = direction === "up" ? index - 1 : index + 1;
|
|
37
|
+
|
|
38
|
+
if (direction === "up" && index === 0) {
|
|
39
|
+
return;
|
|
40
|
+
} else if (direction === "down" && index === assets.length - 1) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onChange(swapArrayElements(assets, index, newIndex));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const handleDeleteClick = (index) => {
|
|
48
|
+
let newAssets = assets;
|
|
49
|
+
|
|
50
|
+
newAssets.splice(index, 1);
|
|
51
|
+
|
|
52
|
+
onChange(newAssets);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleChange = (newAsset) => {
|
|
56
|
+
let newAssets = assets.map(asset => {
|
|
57
|
+
if (asset?.sys?.id === newAsset?.sys?.id) {
|
|
58
|
+
return newAsset;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return asset;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
onChange(newAssets);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>{renderAssets}</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const Asset = ({
|
|
73
|
+
asset,
|
|
74
|
+
index,
|
|
75
|
+
assetsLength,
|
|
76
|
+
onDeleteClick,
|
|
77
|
+
onMoveClick,
|
|
78
|
+
onChange,
|
|
79
|
+
sdk,
|
|
80
|
+
cloudinary = false,
|
|
81
|
+
displayField = "title",
|
|
82
|
+
}) => {
|
|
83
|
+
const [mediaUrl, setMediaUrl] = useState(null);
|
|
84
|
+
|
|
85
|
+
let id = asset?.sys?.id;
|
|
86
|
+
let fieldValue = asset?.fields?.[displayField];
|
|
87
|
+
let title = fieldValue?.["en-US"] || fieldValue?.["de"] || (typeof fieldValue === "string" ? fieldValue : null) || asset?.[displayField]?.toString() || asset?.fields?.title?.["en-US"] || asset?.fields?.title?.["de"];
|
|
88
|
+
let mediaAssetId = asset?.fields?.media?.["en-US"]?.sys?.id || asset?.fields?.media?.["de"]?.sys?.id || asset?.fields?.media?.sys?.id;
|
|
89
|
+
|
|
90
|
+
if (cloudinary) {
|
|
91
|
+
title = asset.public_id || asset.title;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (cloudinary) {
|
|
96
|
+
setMediaUrl(asset.url || asset?.media?.url);
|
|
97
|
+
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!mediaAssetId) {
|
|
102
|
+
if (asset?.media?.url) {
|
|
103
|
+
let params = new URLSearchParams({
|
|
104
|
+
w: "512",
|
|
105
|
+
q: "80",
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
setMediaUrl(`${asset?.media?.url}?${params}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
sdk.space.getAsset(mediaAssetId)
|
|
115
|
+
.then(a => {
|
|
116
|
+
let url = a?.fields?.file?.["en-US"]?.url || a?.fields?.file?.["de"]?.url;
|
|
117
|
+
|
|
118
|
+
if (url) {
|
|
119
|
+
let params = new URLSearchParams({
|
|
120
|
+
w: "512",
|
|
121
|
+
q: "80",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
setMediaUrl(`${url}?${params}`);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}, [mediaAssetId, sdk, asset, cloudinary]);
|
|
128
|
+
|
|
129
|
+
if (!asset) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let assetType = "image";
|
|
134
|
+
|
|
135
|
+
if (mediaUrl?.endsWith(".mp3")) {
|
|
136
|
+
assetType = "audio";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (mediaUrl?.endsWith(".mp4") || mediaUrl?.endsWith(".mov")) {
|
|
140
|
+
assetType = "video";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const renderMedia = () => {
|
|
144
|
+
switch (assetType) {
|
|
145
|
+
case "audio":
|
|
146
|
+
return <audio src={mediaUrl} className="mt-2 w-full" controls />;
|
|
147
|
+
case "video":
|
|
148
|
+
return <video src={mediaUrl} className="mt-2 w-full rounded-md" controls />;
|
|
149
|
+
case "image":
|
|
150
|
+
default:
|
|
151
|
+
return <img src={mediaUrl} width="100%" className="mt-2 rounded-md" />;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className="flex flex-col">
|
|
157
|
+
<div className="flex">
|
|
158
|
+
<div className="grow">
|
|
159
|
+
<b className="mt-[3px] block" style={{wordBreak: "break-word"}}>{title}</b>
|
|
160
|
+
</div>
|
|
161
|
+
<div className="ml-2 shrink-0">
|
|
162
|
+
{!!onMoveClick && (
|
|
163
|
+
<div className="icon-button-group mr-1">
|
|
164
|
+
<IconButton size="small" onClick={() => onMoveClick("up")} disabled={index === 0}>↑</IconButton>
|
|
165
|
+
<IconButton size="small" onClick={() => onMoveClick("down")} disabled={index === assetsLength - 1}>↓</IconButton>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
{!cloudinary && (
|
|
169
|
+
<IconButton
|
|
170
|
+
size="small"
|
|
171
|
+
className="mr-1"
|
|
172
|
+
onClick={() => {
|
|
173
|
+
sdk.navigator.openEntry(id, {slideIn: {waitForClose: true}}).then(({entity}) => {
|
|
174
|
+
if (onChange) {
|
|
175
|
+
onChange(entity);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}}>✎</IconButton>
|
|
179
|
+
)}
|
|
180
|
+
<IconButton size="small" onClick={onDeleteClick}>⨯</IconButton>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
{!!mediaUrl && renderMedia()}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
182
186
|
};
|
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Asset, AssetList,
|
|
3
|
-
} from "../AssetList";
|
|
4
|
-
import {reduceContentfulResponse} from "../../util/reduceContentfulResponse";
|
|
5
|
-
|
|
6
|
-
export const ContentfulContentSelect = ({
|
|
7
|
-
value,
|
|
8
|
-
onChange,
|
|
9
|
-
sdk,
|
|
10
|
-
multiple,
|
|
11
|
-
field,
|
|
12
|
-
}) => {
|
|
13
|
-
if (multiple) {
|
|
14
|
-
return (
|
|
15
|
-
<>
|
|
16
|
-
{value && value.length > 0 && (
|
|
17
|
-
<details className="mb-2">
|
|
18
|
-
<summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
|
|
19
|
-
<div className="mt-4">
|
|
20
|
-
<AssetList
|
|
21
|
-
assets={value}
|
|
22
|
-
sdk={sdk}
|
|
23
|
-
onChange={onChange}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import {
|
|
2
|
+
Asset, AssetList,
|
|
3
|
+
} from "../AssetList";
|
|
4
|
+
import {reduceContentfulResponse} from "../../util/reduceContentfulResponse";
|
|
5
|
+
|
|
6
|
+
export const ContentfulContentSelect = ({
|
|
7
|
+
value,
|
|
8
|
+
onChange,
|
|
9
|
+
sdk,
|
|
10
|
+
multiple,
|
|
11
|
+
field,
|
|
12
|
+
}) => {
|
|
13
|
+
if (multiple) {
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
{value && value.length > 0 && (
|
|
17
|
+
<details className="mb-2">
|
|
18
|
+
<summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
|
|
19
|
+
<div className="mt-4">
|
|
20
|
+
<AssetList
|
|
21
|
+
assets={value}
|
|
22
|
+
sdk={sdk}
|
|
23
|
+
onChange={onChange}
|
|
24
|
+
displayField={field.control.displayField}
|
|
25
|
+
onAddClick={() => {
|
|
26
|
+
sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
|
|
27
|
+
onChange(reduceContentfulResponse([...value, ...contents], field.control.paths));
|
|
28
|
+
});
|
|
29
|
+
}}/>
|
|
30
|
+
</div>
|
|
31
|
+
</details>
|
|
32
|
+
)}
|
|
33
|
+
<button
|
|
34
|
+
className="button"
|
|
35
|
+
onClick={() => {
|
|
36
|
+
sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
|
|
37
|
+
onChange(reduceContentfulResponse(contents, field.control.paths));
|
|
38
|
+
});
|
|
39
|
+
}}
|
|
40
|
+
>Auswählen
|
|
41
|
+
</button>
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
{!!value && <div className="mb-2"><Asset
|
|
49
|
+
sdk={sdk}
|
|
50
|
+
asset={value}
|
|
51
|
+
onDeleteClick={() => onChange(null)}
|
|
52
|
+
onChange={onChange}/></div>}
|
|
53
|
+
<button
|
|
54
|
+
className="button"
|
|
55
|
+
onClick={() => {
|
|
56
|
+
sdk.dialogs.selectSingleEntry({contentTypes: field.control.contentTypes}).then(content => {
|
|
57
|
+
onChange(reduceContentfulResponse(content, field.control.paths));
|
|
58
|
+
});
|
|
59
|
+
}}
|
|
60
|
+
>Auswählen
|
|
61
|
+
</button>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
63
64
|
};
|