@vonaffenfels/portal-slug-field 1.1.21 → 1.1.40

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/portal-slug-field",
3
- "version": "1.1.21",
3
+ "version": "1.1.40",
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": "ea7b5eec618b6dad81ecd09ec76ea6cd8b4cfbe3"
104
+ "gitHead": "6b708b3a2b8b1e61077b6d504dd94ec9665b47f4"
105
105
  }
@@ -1,106 +1,106 @@
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
- sdk.field.setValue(localValue);
45
- setValue(localValue);
46
-
47
- checkDuplicate(localValue);
48
- };
49
-
50
- const checkDuplicate = async (value) => {
51
- if (!value) {
52
- sdk.field.setInvalid(true);
53
- return;
54
- }
55
-
56
- const client = getContentfulClient();
57
- const entries = await client.getEntries({
58
- content_type: sdk.entry.getSys().contentType.sys.id,
59
- limit: 1,
60
- [`fields.${sdk.field.id}`]: value,
61
- [`fields.portal`]: sdk.entry.fields.portal.getValue(),
62
- [`sys.id[ne]`]: sdk.entry.getSys().id,
63
- });
64
-
65
- const hasDuplicate = !!entries.items.at(0);
66
-
67
- if (hasDuplicate) {
68
- sdk.field.setValue("");
69
- }
70
-
71
- sdk.field.setInvalid(!!entries.items.at(0));
72
- setError(entries.items.at(0) || false);
73
- };
74
-
75
- const openError = () => {
76
- sdk.navigator.openEntry(error.sys.id, {slideIn: true});
77
- };
78
-
79
- return (
80
- <>
81
- <TextInput
82
- value={value}
83
- onBlur={(e) => onChange(e.target.value, true)}
84
- type="text"
85
- name="slug"
86
- placeholder=""
87
- onChange={(e) => onChange(e.target.value)}
88
- />
89
- {!!error && <>
90
- <Note variant="negative">
91
- Slug wird bereits von <InlineEntryCard
92
- actions={[
93
- <MenuItem key="open" onClick={openError}>Öffnen</MenuItem>,
94
- ]}
95
- status={error.sys.publishedVersion ? "published" : "draft"}
96
- title={error.fields.title.de}
97
- entry={error}
98
- /> verwendet.
99
- </Note>
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
+ sdk.field.setValue(localValue);
45
+ setValue(localValue);
46
+
47
+ checkDuplicate(localValue);
48
+ };
49
+
50
+ const checkDuplicate = async (value) => {
51
+ if (!value) {
52
+ sdk.field.setInvalid(true);
53
+ return;
54
+ }
55
+
56
+ const client = getContentfulClient();
57
+ const entries = await client.getEntries({
58
+ content_type: sdk.entry.getSys().contentType.sys.id,
59
+ limit: 1,
60
+ [`fields.${sdk.field.id}`]: value,
61
+ [`fields.portal`]: sdk.entry.fields.portal.getValue(),
62
+ [`sys.id[ne]`]: sdk.entry.getSys().id,
63
+ });
64
+
65
+ const hasDuplicate = !!entries.items.at(0);
66
+
67
+ if (hasDuplicate) {
68
+ sdk.field.setValue("");
69
+ }
70
+
71
+ sdk.field.setInvalid(!!entries.items.at(0));
72
+ setError(entries.items.at(0) || false);
73
+ };
74
+
75
+ const openError = () => {
76
+ sdk.navigator.openEntry(error.sys.id, {slideIn: true});
77
+ };
78
+
79
+ return (
80
+ <>
81
+ <TextInput
82
+ value={value}
83
+ onBlur={(e) => onChange(e.target.value, true)}
84
+ type="text"
85
+ name="slug"
86
+ placeholder=""
87
+ onChange={(e) => onChange(e.target.value)}
88
+ />
89
+ {!!error && <>
90
+ <Note variant="negative">
91
+ Slug wird bereits von <InlineEntryCard
92
+ actions={[
93
+ <MenuItem key="open" onClick={openError}>Öffnen</MenuItem>,
94
+ ]}
95
+ status={error.sys.publishedVersion ? "published" : "draft"}
96
+ title={error.fields.title.de}
97
+ entry={error}
98
+ /> verwendet.
99
+ </Note>
100
+
101
+ </>}
102
+ </>
103
+ );
104
+ };
105
+
106
106
  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: {postcssOptions: {
92
+ options: {
97
93
  postcssOptions: {
98
- plugins: {
99
- 'postcss-import': {},
100
- tailwindcss: {},
101
- autoprefixer: {},
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: {postcssOptions: {
117
+ options: {
120
118
  postcssOptions: {
121
- plugins: {
122
- 'postcss-import': {},
123
- tailwindcss: {},
124
- autoprefixer: {},
119
+ postcssOptions: {
120
+ plugins: {
121
+ 'postcss-import': {},
122
+ tailwindcss: {},
123
+ autoprefixer: {},
124
+ },
125
125
  },
126
126
  },
127
- }},
127
+ },
128
128
  },
129
129
  ],
130
130
  },
@@ -142,6 +142,19 @@ module.exports = {
142
142
  'url-loader',
143
143
  ],
144
144
  },
145
+ {
146
+ test: /\.svg$/,
147
+ resourceQuery: /url/, // include if *.svg?url
148
+ use: [
149
+ {
150
+ loader: 'file-loader',
151
+ options: {
152
+ name: '[name].[ext]',
153
+ outputPath: 'svgs/',
154
+ },
155
+ },
156
+ ],
157
+ },
145
158
  {
146
159
  test: /\.(woff(2)?|ttf|eot|png)(\?v=\d+\.\d+\.\d+)?$/,
147
160
  use: [
@@ -172,6 +185,8 @@ module.exports = {
172
185
  stream: false,
173
186
  path: false,
174
187
  timers: false,
188
+ fs: false,
189
+ zlib: false,
175
190
  },
176
191
  },
177
192
  output: {
@@ -181,7 +196,5 @@ module.exports = {
181
196
  globalObject: "this",
182
197
  path: path.resolve("./dist"),
183
198
  },
184
- snapshot: {
185
- managedPaths: [],
186
- },
199
+ snapshot: {managedPaths: []},
187
200
  };