@vonaffenfels/portal-slug-field 1.1.22 → 1.1.55
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 +2 -2
- package/src/components/Field.js +108 -105
- package/webpack.config.js +21 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/portal-slug-field",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.55",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublish": "yarn run build",
|
|
6
6
|
"dev": "yarn run start",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"publishConfig": {
|
|
102
102
|
"access": "public"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "89c27df1abbba105a49f90a689a614e06ec3b5a9"
|
|
105
105
|
}
|
package/src/components/Field.js
CHANGED
|
@@ -1,106 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TextInput, Note, InlineEntryCard, MenuItem,
|
|
3
|
-
} from '@contentful/f36-components';
|
|
4
|
-
import React, {
|
|
5
|
-
useState, useEffect,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import getSlug from "speakingurl";
|
|
8
|
-
import {getContentfulClient} from "../lib/contentfulClient";
|
|
9
|
-
|
|
10
|
-
const Field = ({sdk}) => {
|
|
11
|
-
const [value, setValue] = useState(sdk.field.getValue());
|
|
12
|
-
const [error, setError] = useState(false);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
// initial check
|
|
16
|
-
checkDuplicate(value);
|
|
17
|
-
}, []);
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (!value) {
|
|
21
|
-
// generate from title if empty
|
|
22
|
-
const title = sdk.entry.fields.title.getValue();
|
|
23
|
-
if (title) {
|
|
24
|
-
onChange(getSlug(title));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}, []);
|
|
28
|
-
|
|
29
|
-
const onChange = (value, sluggify = false) => {
|
|
30
|
-
const title = sdk.entry.fields.title.getValue();
|
|
31
|
-
let localValue = String(value || title).toLowerCase();
|
|
32
|
-
|
|
33
|
-
if (sluggify && localValue !== "/") {
|
|
34
|
-
if (localValue.startsWith("/") || localValue.endsWith("/")) {
|
|
35
|
-
localValue = localValue.replace(/^[/]*(.*?)[/]*$/, "$1");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
localValue = getSlug(localValue, {
|
|
39
|
-
lang: 'de',
|
|
40
|
-
custom:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
1
|
+
import {
|
|
2
|
+
TextInput, Note, InlineEntryCard, MenuItem,
|
|
3
|
+
} from '@contentful/f36-components';
|
|
4
|
+
import React, {
|
|
5
|
+
useState, useEffect,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import getSlug from "speakingurl";
|
|
8
|
+
import {getContentfulClient} from "../lib/contentfulClient";
|
|
9
|
+
|
|
10
|
+
const Field = ({sdk}) => {
|
|
11
|
+
const [value, setValue] = useState(sdk.field.getValue());
|
|
12
|
+
const [error, setError] = useState(false);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
// initial check
|
|
16
|
+
checkDuplicate(value);
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!value) {
|
|
21
|
+
// generate from title if empty
|
|
22
|
+
const title = sdk.entry.fields.title.getValue();
|
|
23
|
+
if (title) {
|
|
24
|
+
onChange(getSlug(title));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
const onChange = (value, sluggify = false) => {
|
|
30
|
+
const title = sdk.entry.fields.title.getValue();
|
|
31
|
+
let localValue = String(value || title).toLowerCase();
|
|
32
|
+
|
|
33
|
+
if (sluggify && localValue !== "/") {
|
|
34
|
+
if (localValue.startsWith("/") || localValue.endsWith("/")) {
|
|
35
|
+
localValue = localValue.replace(/^[/]*(.*?)[/]*$/, "$1");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
localValue = getSlug(localValue, {
|
|
39
|
+
lang: 'de',
|
|
40
|
+
custom: {
|
|
41
|
+
"/": "/",
|
|
42
|
+
"-": "-",
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
sdk.field.setValue(localValue);
|
|
48
|
+
setValue(localValue);
|
|
49
|
+
|
|
50
|
+
checkDuplicate(localValue);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const checkDuplicate = async (value) => {
|
|
54
|
+
if (!value) {
|
|
55
|
+
sdk.field.setInvalid(true);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const client = getContentfulClient();
|
|
60
|
+
const entries = await client.getEntries({
|
|
61
|
+
content_type: sdk.entry.getSys().contentType.sys.id,
|
|
62
|
+
limit: 1,
|
|
63
|
+
[`fields.${sdk.field.id}`]: value,
|
|
64
|
+
[`fields.portal`]: sdk.entry.fields.portal.getValue(),
|
|
65
|
+
[`sys.id[ne]`]: sdk.entry.getSys().id,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const hasDuplicate = !!entries.items.at(0);
|
|
69
|
+
|
|
70
|
+
if (hasDuplicate) {
|
|
71
|
+
sdk.field.setValue("");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
sdk.field.setInvalid(!!entries.items.at(0));
|
|
75
|
+
setError(entries.items.at(0) || false);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const openError = () => {
|
|
79
|
+
sdk.navigator.openEntry(error.sys.id, {slideIn: true});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<>
|
|
84
|
+
<TextInput
|
|
85
|
+
value={value}
|
|
86
|
+
onBlur={(e) => onChange(e.target.value, true)}
|
|
87
|
+
type="text"
|
|
88
|
+
name="slug"
|
|
89
|
+
placeholder=""
|
|
90
|
+
onChange={(e) => onChange(e.target.value)}
|
|
91
|
+
/>
|
|
92
|
+
{!!error && <>
|
|
93
|
+
<Note variant="negative">
|
|
94
|
+
Slug wird bereits von <InlineEntryCard
|
|
95
|
+
actions={[
|
|
96
|
+
<MenuItem key="open" onClick={openError}>Öffnen</MenuItem>,
|
|
97
|
+
]}
|
|
98
|
+
status={error.sys.publishedVersion ? "published" : "draft"}
|
|
99
|
+
title={error.fields.title.de}
|
|
100
|
+
entry={error}
|
|
101
|
+
/> verwendet.
|
|
102
|
+
</Note>
|
|
103
|
+
|
|
104
|
+
</>}
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
106
109
|
export default Field;
|
package/webpack.config.js
CHANGED
|
@@ -40,15 +40,11 @@ module.exports = {
|
|
|
40
40
|
"plugins": [
|
|
41
41
|
[
|
|
42
42
|
"@babel/plugin-proposal-private-property-in-object",
|
|
43
|
-
{
|
|
44
|
-
"loose": true,
|
|
45
|
-
},
|
|
43
|
+
{"loose": true},
|
|
46
44
|
],
|
|
47
45
|
[
|
|
48
46
|
"@babel/plugin-proposal-class-properties",
|
|
49
|
-
{
|
|
50
|
-
"loose": true,
|
|
51
|
-
},
|
|
47
|
+
{"loose": true},
|
|
52
48
|
],
|
|
53
49
|
"@babel/plugin-syntax-dynamic-import",
|
|
54
50
|
],
|
|
@@ -93,15 +89,17 @@ module.exports = {
|
|
|
93
89
|
},
|
|
94
90
|
{
|
|
95
91
|
loader: 'postcss-loader',
|
|
96
|
-
options: {
|
|
92
|
+
options: {
|
|
97
93
|
postcssOptions: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
postcssOptions: {
|
|
95
|
+
plugins: {
|
|
96
|
+
'postcss-import': {},
|
|
97
|
+
tailwindcss: {},
|
|
98
|
+
autoprefixer: {},
|
|
99
|
+
},
|
|
102
100
|
},
|
|
103
101
|
},
|
|
104
|
-
}
|
|
102
|
+
},
|
|
105
103
|
},
|
|
106
104
|
],
|
|
107
105
|
},
|
|
@@ -116,15 +114,17 @@ module.exports = {
|
|
|
116
114
|
},
|
|
117
115
|
{
|
|
118
116
|
loader: 'postcss-loader',
|
|
119
|
-
options: {
|
|
117
|
+
options: {
|
|
120
118
|
postcssOptions: {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
postcssOptions: {
|
|
120
|
+
plugins: {
|
|
121
|
+
'postcss-import': {},
|
|
122
|
+
tailwindcss: {},
|
|
123
|
+
autoprefixer: {},
|
|
124
|
+
},
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
|
-
}
|
|
127
|
+
},
|
|
128
128
|
},
|
|
129
129
|
],
|
|
130
130
|
},
|
|
@@ -185,6 +185,8 @@ module.exports = {
|
|
|
185
185
|
stream: false,
|
|
186
186
|
path: false,
|
|
187
187
|
timers: false,
|
|
188
|
+
fs: false,
|
|
189
|
+
zlib: false,
|
|
188
190
|
},
|
|
189
191
|
},
|
|
190
192
|
output: {
|
|
@@ -194,7 +196,5 @@ module.exports = {
|
|
|
194
196
|
globalObject: "this",
|
|
195
197
|
path: path.resolve("./dist"),
|
|
196
198
|
},
|
|
197
|
-
snapshot: {
|
|
198
|
-
managedPaths: [],
|
|
199
|
-
},
|
|
199
|
+
snapshot: {managedPaths: []},
|
|
200
200
|
};
|