@contentful/field-editor-slug 1.2.0 → 1.3.1
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/cjs/SlugEditor.js +139 -0
- package/dist/cjs/SlugEditor.test.js +538 -0
- package/dist/cjs/SlugEditorField.js +186 -0
- package/dist/cjs/TrackingFieldConnector.js +137 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/services/makeSlug.js +42 -0
- package/dist/cjs/services/makeSlug.test.js +14 -0
- package/dist/cjs/services/slugify.js +64 -0
- package/dist/cjs/services/slugify.test.js +30 -0
- package/dist/cjs/styles.js +68 -0
- package/dist/esm/SlugEditor.js +90 -0
- package/dist/esm/SlugEditor.test.js +490 -0
- package/dist/esm/SlugEditorField.js +129 -0
- package/dist/esm/TrackingFieldConnector.js +88 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/services/makeSlug.js +24 -0
- package/dist/esm/services/makeSlug.test.js +10 -0
- package/dist/esm/services/slugify.js +49 -0
- package/dist/esm/services/slugify.test.js +26 -0
- package/dist/esm/styles.js +33 -0
- package/dist/{SlugEditor.d.ts → types/SlugEditor.d.ts} +24 -24
- package/dist/types/SlugEditor.test.d.ts +1 -0
- package/dist/{SlugEditorField.d.ts → types/SlugEditorField.d.ts} +18 -18
- package/dist/{TrackingFieldConnector.d.ts → types/TrackingFieldConnector.d.ts} +29 -29
- package/dist/{index.d.ts → types/index.d.ts} +3 -3
- package/dist/{services → types/services}/makeSlug.d.ts +8 -8
- package/dist/types/services/makeSlug.test.d.ts +1 -0
- package/dist/{services → types/services}/slugify.d.ts +12 -12
- package/dist/types/services/slugify.test.d.ts +1 -0
- package/dist/{styles.d.ts → types/styles.d.ts} +6 -6
- package/package.json +25 -11
- package/CHANGELOG.md +0 -206
- package/dist/field-editor-slug.cjs.development.js +0 -463
- package/dist/field-editor-slug.cjs.development.js.map +0 -1
- package/dist/field-editor-slug.cjs.production.min.js +0 -2
- package/dist/field-editor-slug.cjs.production.min.js.map +0 -1
- package/dist/field-editor-slug.esm.js +0 -454
- package/dist/field-editor-slug.esm.js.map +0 -1
- package/dist/index.js +0 -8
package/CHANGELOG.md
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.12...@contentful/field-editor-slug@1.2.0) (2023-04-19)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- upgrade cypress [TOL-1036] ([#1391](https://github.com/contentful/field-editors/issues/1391)) ([9c1aec9](https://github.com/contentful/field-editors/commit/9c1aec98aabbe464cdc3f1236c3bb1cc29b8208d))
|
|
11
|
-
|
|
12
|
-
## [1.1.12](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.11...@contentful/field-editor-slug@1.1.12) (2023-03-14)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
15
|
-
|
|
16
|
-
## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.10...@contentful/field-editor-slug@1.1.11) (2023-03-10)
|
|
17
|
-
|
|
18
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
19
|
-
|
|
20
|
-
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.9...@contentful/field-editor-slug@1.1.10) (2023-02-21)
|
|
21
|
-
|
|
22
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
23
|
-
|
|
24
|
-
## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.8...@contentful/field-editor-slug@1.1.9) (2023-02-07)
|
|
25
|
-
|
|
26
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
27
|
-
|
|
28
|
-
## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.7...@contentful/field-editor-slug@1.1.8) (2022-12-08)
|
|
29
|
-
|
|
30
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
31
|
-
|
|
32
|
-
## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.6...@contentful/field-editor-slug@1.1.7) (2022-07-29)
|
|
33
|
-
|
|
34
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
35
|
-
|
|
36
|
-
## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.5...@contentful/field-editor-slug@1.1.6) (2022-07-29)
|
|
37
|
-
|
|
38
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
39
|
-
|
|
40
|
-
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.4...@contentful/field-editor-slug@1.1.5) (2022-07-22)
|
|
41
|
-
|
|
42
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
43
|
-
|
|
44
|
-
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.3...@contentful/field-editor-slug@1.1.4) (2022-07-11)
|
|
45
|
-
|
|
46
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
47
|
-
|
|
48
|
-
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.2...@contentful/field-editor-slug@1.1.3) (2022-06-22)
|
|
49
|
-
|
|
50
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
51
|
-
|
|
52
|
-
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.1...@contentful/field-editor-slug@1.1.2) (2022-02-15)
|
|
53
|
-
|
|
54
|
-
### Bug Fixes
|
|
55
|
-
|
|
56
|
-
- bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
|
|
57
|
-
|
|
58
|
-
## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.1.0...@contentful/field-editor-slug@1.1.1) (2022-02-14)
|
|
59
|
-
|
|
60
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
61
|
-
|
|
62
|
-
# [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.0.3...@contentful/field-editor-slug@1.1.0) (2022-01-11)
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
- bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
|
|
67
|
-
|
|
68
|
-
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.0.2...@contentful/field-editor-slug@1.0.3) (2021-12-23)
|
|
69
|
-
|
|
70
|
-
### Bug Fixes
|
|
71
|
-
|
|
72
|
-
- markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
|
|
73
|
-
|
|
74
|
-
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.0.1...@contentful/field-editor-slug@1.0.2) (2021-12-20)
|
|
75
|
-
|
|
76
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
77
|
-
|
|
78
|
-
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@1.0.0...@contentful/field-editor-slug@1.0.1) (2021-11-17)
|
|
79
|
-
|
|
80
|
-
### Bug Fixes
|
|
81
|
-
|
|
82
|
-
- **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
|
|
83
|
-
|
|
84
|
-
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.14.0...@contentful/field-editor-slug@1.0.0) (2021-11-04)
|
|
85
|
-
|
|
86
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
87
|
-
|
|
88
|
-
# [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.13.1...@contentful/field-editor-slug@0.14.0) (2021-11-04)
|
|
89
|
-
|
|
90
|
-
### Features
|
|
91
|
-
|
|
92
|
-
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
93
|
-
|
|
94
|
-
### BREAKING CHANGES
|
|
95
|
-
|
|
96
|
-
- adopts a new Forma v4 beta
|
|
97
|
-
|
|
98
|
-
## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.13.0...@contentful/field-editor-slug@0.13.1) (2021-10-14)
|
|
99
|
-
|
|
100
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
101
|
-
|
|
102
|
-
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.12.3...@contentful/field-editor-slug@0.13.0) (2021-10-06)
|
|
103
|
-
|
|
104
|
-
### Features
|
|
105
|
-
|
|
106
|
-
- [EXT-3161] bump app sdk to v4 ([#881](https://github.com/contentful/field-editors/issues/881)) ([9c4a2af](https://github.com/contentful/field-editors/commit/9c4a2af07da203d59fb5f15c3a5188ecc64b1d44))
|
|
107
|
-
|
|
108
|
-
## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.12.2...@contentful/field-editor-slug@0.12.3) (2021-09-17)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
111
|
-
|
|
112
|
-
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.12.1...@contentful/field-editor-slug@0.12.2) (2021-09-16)
|
|
113
|
-
|
|
114
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
115
|
-
|
|
116
|
-
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.12.0...@contentful/field-editor-slug@0.12.1) (2021-08-19)
|
|
117
|
-
|
|
118
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
119
|
-
|
|
120
|
-
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.11.1...@contentful/field-editor-slug@0.12.0) (2021-08-11)
|
|
121
|
-
|
|
122
|
-
### Features
|
|
123
|
-
|
|
124
|
-
- throttle slug editor uniqueness requests ([#799](https://github.com/contentful/field-editors/issues/799)) ([bfadaf0](https://github.com/contentful/field-editors/commit/bfadaf03a2c1a032a56218287ec30929c3581a25))
|
|
125
|
-
|
|
126
|
-
## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.11.0...@contentful/field-editor-slug@0.11.1) (2021-07-29)
|
|
127
|
-
|
|
128
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
129
|
-
|
|
130
|
-
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.6...@contentful/field-editor-slug@0.11.0) (2021-07-23)
|
|
131
|
-
|
|
132
|
-
### Features
|
|
133
|
-
|
|
134
|
-
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
135
|
-
|
|
136
|
-
## [0.10.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.3...@contentful/field-editor-slug@0.10.6) (2021-07-06)
|
|
137
|
-
|
|
138
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
139
|
-
|
|
140
|
-
## [0.10.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.3...@contentful/field-editor-slug@0.10.5) (2021-07-06)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
143
|
-
|
|
144
|
-
## [0.10.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.3...@contentful/field-editor-slug@0.10.4) (2021-06-23)
|
|
145
|
-
|
|
146
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
147
|
-
|
|
148
|
-
## [0.10.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.2...@contentful/field-editor-slug@0.10.3) (2021-06-23)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
151
|
-
|
|
152
|
-
## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.1...@contentful/field-editor-slug@0.10.2) (2021-06-22)
|
|
153
|
-
|
|
154
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
155
|
-
|
|
156
|
-
## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.10.0...@contentful/field-editor-slug@0.10.1) (2021-03-05)
|
|
157
|
-
|
|
158
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
159
|
-
|
|
160
|
-
# [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.9.1...@contentful/field-editor-slug@0.10.0) (2021-02-19)
|
|
161
|
-
|
|
162
|
-
### Features
|
|
163
|
-
|
|
164
|
-
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
165
|
-
|
|
166
|
-
## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.9.0...@contentful/field-editor-slug@0.9.1) (2021-02-09)
|
|
167
|
-
|
|
168
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
169
|
-
|
|
170
|
-
# [0.9.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.8.0...@contentful/field-editor-slug@0.9.0) (2021-02-01)
|
|
171
|
-
|
|
172
|
-
### Features
|
|
173
|
-
|
|
174
|
-
- swap ui-extension-sdk to app-sdk ([#576](https://github.com/contentful/field-editors/issues/576)) ([ac88b4b](https://github.com/contentful/field-editors/commit/ac88b4bd4573a72f521246fc8fcc873520ca90d4))
|
|
175
|
-
|
|
176
|
-
# [0.8.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.7.0...@contentful/field-editor-slug@0.8.0) (2021-01-20)
|
|
177
|
-
|
|
178
|
-
### Features
|
|
179
|
-
|
|
180
|
-
- update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
|
|
181
|
-
|
|
182
|
-
# [0.7.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.5...@contentful/field-editor-slug@0.7.0) (2021-01-12)
|
|
183
|
-
|
|
184
|
-
### Features
|
|
185
|
-
|
|
186
|
-
- update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
|
|
187
|
-
|
|
188
|
-
## [0.6.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.4...@contentful/field-editor-slug@0.6.5) (2020-12-16)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
191
|
-
|
|
192
|
-
## [0.6.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.3...@contentful/field-editor-slug@0.6.4) (2020-11-06)
|
|
193
|
-
|
|
194
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
195
|
-
|
|
196
|
-
## [0.6.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.2...@contentful/field-editor-slug@0.6.3) (2020-11-06)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
199
|
-
|
|
200
|
-
## [0.6.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.1...@contentful/field-editor-slug@0.6.2) (2020-10-28)
|
|
201
|
-
|
|
202
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
203
|
-
|
|
204
|
-
## [0.6.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-slug@0.6.0...@contentful/field-editor-slug@0.6.1) (2020-08-24)
|
|
205
|
-
|
|
206
|
-
**Note:** Version bump only for package @contentful/field-editor-slug
|
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var React__default = _interopDefault(React);
|
|
9
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
10
|
-
var f36Components = require('@contentful/f36-components');
|
|
11
|
-
var f36Icons = require('@contentful/f36-icons');
|
|
12
|
-
var useDebounce = require('use-debounce');
|
|
13
|
-
var getSlug = _interopDefault(require('speakingurl'));
|
|
14
|
-
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
15
|
-
var emotion = require('emotion');
|
|
16
|
-
|
|
17
|
-
const CF_GENERATED_SLUG_MAX_LENGTH = 75;
|
|
18
|
-
const languages = ['ar', 'az', 'cs', 'de', 'dv', 'en', 'es', 'fa', 'fi', 'fr', 'ge', 'gr', 'hu', 'it', 'lt', 'lv', 'my', 'mk', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sr', 'tr', 'uk', 'vn'];
|
|
19
|
-
/**
|
|
20
|
-
* Extracts the first two lowercased characters from the locale,
|
|
21
|
-
* and returns the supported language prefix.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function supportedLanguage(locale) {
|
|
25
|
-
const prefix = locale.slice(0, 2).toLowerCase();
|
|
26
|
-
return languages[languages.indexOf(prefix)];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the slug for a given string and locale.
|
|
30
|
-
* If the locale belongs to a language supported by SpeakingURL, it
|
|
31
|
-
* is used as the symbol language. Otherwise, the symbol language
|
|
32
|
-
* is english.
|
|
33
|
-
* Slug suggestions are limited to 75 characters.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} text To be turned into a slug.
|
|
36
|
-
* @param {string?} locale
|
|
37
|
-
* @returns {string} Slug for provided text.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function slugify(text, locale = 'en') {
|
|
42
|
-
return getSlug(text, {
|
|
43
|
-
separator: '-',
|
|
44
|
-
lang: supportedLanguage(locale) || 'en',
|
|
45
|
-
truncate: CF_GENERATED_SLUG_MAX_LENGTH + 1,
|
|
46
|
-
custom: {
|
|
47
|
-
"'": '',
|
|
48
|
-
'`': '',
|
|
49
|
-
'’': '',
|
|
50
|
-
'‘': ''
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function formatTwoDigit(num) {
|
|
56
|
-
const asString = String(num);
|
|
57
|
-
return asString.length === 1 ? `0${asString}` : asString;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function formatUtcDate(date) {
|
|
61
|
-
const year = date.getFullYear();
|
|
62
|
-
const month = formatTwoDigit(date.getUTCMonth() + 1);
|
|
63
|
-
const day = formatTwoDigit(date.getUTCDate());
|
|
64
|
-
const hour = formatTwoDigit(date.getUTCHours());
|
|
65
|
-
const minutes = formatTwoDigit(date.getUTCMinutes());
|
|
66
|
-
const seconds = formatTwoDigit(date.getUTCSeconds());
|
|
67
|
-
return `${year} ${month} ${day} at ${hour} ${minutes} ${seconds}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function untitledSlug({
|
|
71
|
-
isOptionalLocaleWithFallback,
|
|
72
|
-
createdAt
|
|
73
|
-
}) {
|
|
74
|
-
if (isOptionalLocaleWithFallback) {
|
|
75
|
-
return ''; // Will result in `undefined` slug.
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const createdAtFormatted = formatUtcDate(new Date(createdAt));
|
|
79
|
-
return slugify('Untitled entry ' + createdAtFormatted, 'en-US');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function makeSlug(title, options) {
|
|
83
|
-
return title ? slugify(title, options.locale) : untitledSlug(options);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const inputContainer = /*#__PURE__*/emotion.css({
|
|
87
|
-
position: 'relative'
|
|
88
|
-
});
|
|
89
|
-
const input = /*#__PURE__*/emotion.css({
|
|
90
|
-
paddingLeft: '40px'
|
|
91
|
-
});
|
|
92
|
-
const icon = /*#__PURE__*/emotion.css({
|
|
93
|
-
position: 'absolute',
|
|
94
|
-
left: '10px',
|
|
95
|
-
top: '8px',
|
|
96
|
-
zIndex: 2,
|
|
97
|
-
width: '25px',
|
|
98
|
-
height: '25px',
|
|
99
|
-
fill: tokens.gray500
|
|
100
|
-
});
|
|
101
|
-
const spinnerContainer = /*#__PURE__*/emotion.css({
|
|
102
|
-
position: 'absolute',
|
|
103
|
-
zIndex: 2,
|
|
104
|
-
right: '8px',
|
|
105
|
-
top: '8px'
|
|
106
|
-
});
|
|
107
|
-
const uniqueValidationError = /*#__PURE__*/emotion.css({
|
|
108
|
-
marginTop: tokens.spacingS
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
function useSlugUpdater(props, check) {
|
|
112
|
-
const {
|
|
113
|
-
value,
|
|
114
|
-
setValue,
|
|
115
|
-
createdAt,
|
|
116
|
-
locale,
|
|
117
|
-
titleValue,
|
|
118
|
-
isOptionalLocaleWithFallback
|
|
119
|
-
} = props;
|
|
120
|
-
React__default.useEffect(() => {
|
|
121
|
-
if (check === false) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const newSlug = makeSlug(titleValue, {
|
|
126
|
-
isOptionalLocaleWithFallback,
|
|
127
|
-
locale,
|
|
128
|
-
createdAt
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (newSlug !== value) {
|
|
132
|
-
setValue(newSlug);
|
|
133
|
-
}
|
|
134
|
-
}, [value, titleValue, isOptionalLocaleWithFallback, check, createdAt, locale, setValue]);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function useUniqueChecker(props) {
|
|
138
|
-
const {
|
|
139
|
-
performUniqueCheck
|
|
140
|
-
} = props;
|
|
141
|
-
const [status, setStatus] = React__default.useState(props.value ? 'checking' : 'unique');
|
|
142
|
-
const [debouncedValue] = useDebounce.useDebounce(props.value, 1000);
|
|
143
|
-
/**
|
|
144
|
-
* Check the uniqueness of the slug in the current space.
|
|
145
|
-
* The slug is unique if there is no published entry other than the
|
|
146
|
-
* current one, with the same slug.
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
React__default.useEffect(() => {
|
|
150
|
-
if (!debouncedValue) {
|
|
151
|
-
setStatus('unique');
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
setStatus('checking');
|
|
156
|
-
performUniqueCheck(debouncedValue).then(unique => {
|
|
157
|
-
setStatus(unique ? 'unique' : 'duplicate');
|
|
158
|
-
}).catch(() => {
|
|
159
|
-
setStatus('checking');
|
|
160
|
-
});
|
|
161
|
-
}, [debouncedValue, performUniqueCheck]);
|
|
162
|
-
return status;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function SlugEditorFieldStatic(props) {
|
|
166
|
-
const {
|
|
167
|
-
hasError,
|
|
168
|
-
isDisabled,
|
|
169
|
-
value,
|
|
170
|
-
setValue,
|
|
171
|
-
onChange,
|
|
172
|
-
onBlur
|
|
173
|
-
} = props;
|
|
174
|
-
const status = useUniqueChecker(props);
|
|
175
|
-
return React__default.createElement("div", {
|
|
176
|
-
className: inputContainer
|
|
177
|
-
}, React__default.createElement(f36Icons.LinkIcon, {
|
|
178
|
-
className: icon
|
|
179
|
-
}), React__default.createElement(f36Components.TextInput, {
|
|
180
|
-
className: input,
|
|
181
|
-
isInvalid: hasError || status === 'duplicate',
|
|
182
|
-
isDisabled: isDisabled,
|
|
183
|
-
value: value || '',
|
|
184
|
-
onChange: e => {
|
|
185
|
-
setValue(e.target.value);
|
|
186
|
-
|
|
187
|
-
if (onChange) {
|
|
188
|
-
onChange();
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
onBlur: () => {
|
|
192
|
-
if (onBlur) {
|
|
193
|
-
onBlur();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}), status === 'checking' && React__default.createElement("div", {
|
|
197
|
-
className: spinnerContainer
|
|
198
|
-
}, React__default.createElement(f36Components.Spinner, {
|
|
199
|
-
testId: "slug-editor-spinner"
|
|
200
|
-
})), status === 'duplicate' && React__default.createElement(f36Components.ValidationMessage, {
|
|
201
|
-
testId: "slug-editor-duplicate-error",
|
|
202
|
-
className: uniqueValidationError
|
|
203
|
-
}, "This slug has already been published in another entry"));
|
|
204
|
-
}
|
|
205
|
-
function SlugEditorField(props) {
|
|
206
|
-
const {
|
|
207
|
-
titleValue,
|
|
208
|
-
isOptionalLocaleWithFallback,
|
|
209
|
-
locale,
|
|
210
|
-
createdAt,
|
|
211
|
-
value
|
|
212
|
-
} = props;
|
|
213
|
-
const areEqual = React__default.useCallback(() => {
|
|
214
|
-
const potentialSlug = makeSlug(titleValue, {
|
|
215
|
-
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
216
|
-
locale: locale,
|
|
217
|
-
createdAt: createdAt
|
|
218
|
-
});
|
|
219
|
-
return value === potentialSlug;
|
|
220
|
-
}, [titleValue, isOptionalLocaleWithFallback, locale, createdAt, value]);
|
|
221
|
-
const [check, setCheck] = React__default.useState(() => {
|
|
222
|
-
if (props.value) {
|
|
223
|
-
if (!props.titleValue) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return areEqual();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return true;
|
|
231
|
-
});
|
|
232
|
-
React__default.useEffect(() => {
|
|
233
|
-
if (areEqual()) {
|
|
234
|
-
setCheck(true);
|
|
235
|
-
}
|
|
236
|
-
}, [props.titleValue, areEqual]);
|
|
237
|
-
useSlugUpdater(props, check);
|
|
238
|
-
return React__default.createElement(SlugEditorFieldStatic, { ...props,
|
|
239
|
-
onChange: () => {
|
|
240
|
-
setCheck(false);
|
|
241
|
-
},
|
|
242
|
-
onBlur: () => {
|
|
243
|
-
if (areEqual()) {
|
|
244
|
-
setCheck(true);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function getTitleField(sdk, trackingFieldId) {
|
|
251
|
-
const {
|
|
252
|
-
entry,
|
|
253
|
-
contentType
|
|
254
|
-
} = sdk;
|
|
255
|
-
|
|
256
|
-
if (trackingFieldId && entry.fields[trackingFieldId]) {
|
|
257
|
-
return entry.fields[trackingFieldId];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return entry.fields[contentType.displayField];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
class TrackingFieldConnector extends React__default.Component {
|
|
264
|
-
constructor(props) {
|
|
265
|
-
super(props);
|
|
266
|
-
this.unsubscribeValue = null;
|
|
267
|
-
this.unsubscribeLocalizedValue = null;
|
|
268
|
-
this.unsubscribeSysChanges = null;
|
|
269
|
-
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
270
|
-
const entrySys = props.sdk.entry.getSys();
|
|
271
|
-
const isSame = titleField ? props.field.id === titleField.id : false;
|
|
272
|
-
this.state = {
|
|
273
|
-
titleValue: titleField ? titleField.getValue() : '',
|
|
274
|
-
isPublished: Boolean(entrySys.publishedVersion),
|
|
275
|
-
isSame
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
componentDidMount() {
|
|
280
|
-
this.unsubscribeSysChanges = this.props.sdk.entry.onSysChanged(sys => {
|
|
281
|
-
this.setState({
|
|
282
|
-
isPublished: Boolean(sys.publishedVersion)
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
const titleField = getTitleField(this.props.sdk, this.props.trackingFieldId); // the content type's display field might not exist
|
|
286
|
-
|
|
287
|
-
if (!titleField) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (!this.state.isSame) {
|
|
292
|
-
this.unsubscribeLocalizedValue = titleField.onValueChanged(this.props.field.locale, value => {
|
|
293
|
-
this.setState({
|
|
294
|
-
titleValue: value
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (this.props.field.locale !== this.props.defaultLocale) {
|
|
300
|
-
if (!this.props.isOptionalLocaleWithFallback) {
|
|
301
|
-
this.unsubscribeValue = titleField.onValueChanged(this.props.defaultLocale, value => {
|
|
302
|
-
if (!titleField.getValue(this.props.field.locale)) {
|
|
303
|
-
this.setState({
|
|
304
|
-
titleValue: value
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
componentWillUnmount() {
|
|
313
|
-
if (typeof this.unsubscribeValue === 'function') {
|
|
314
|
-
this.unsubscribeValue();
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (typeof this.unsubscribeLocalizedValue === 'function') {
|
|
318
|
-
this.unsubscribeLocalizedValue();
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (typeof this.unsubscribeSysChanges === 'function') {
|
|
322
|
-
this.unsubscribeSysChanges();
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
render() {
|
|
327
|
-
return this.props.children({ ...this.state
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
TrackingFieldConnector.defaultProps = {
|
|
333
|
-
children: () => {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
function isSupportedFieldTypes(val) {
|
|
339
|
-
return val === 'Symbol';
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function FieldConnectorCallback({
|
|
343
|
-
Component,
|
|
344
|
-
value,
|
|
345
|
-
disabled,
|
|
346
|
-
setValue,
|
|
347
|
-
errors,
|
|
348
|
-
titleValue,
|
|
349
|
-
isOptionalLocaleWithFallback,
|
|
350
|
-
locale,
|
|
351
|
-
createdAt,
|
|
352
|
-
performUniqueCheck
|
|
353
|
-
}) {
|
|
354
|
-
// it is needed to silent permission errors
|
|
355
|
-
// this happens when setValue is called on a field which is disabled for permission reasons
|
|
356
|
-
const safeSetValue = React.useCallback(async (...args) => {
|
|
357
|
-
try {
|
|
358
|
-
await setValue(...args);
|
|
359
|
-
} catch (e) {// do nothing
|
|
360
|
-
}
|
|
361
|
-
}, [setValue]);
|
|
362
|
-
return React.createElement("div", {
|
|
363
|
-
"data-test-id": "slug-editor"
|
|
364
|
-
}, React.createElement(Component, {
|
|
365
|
-
locale: locale,
|
|
366
|
-
createdAt: createdAt,
|
|
367
|
-
performUniqueCheck: performUniqueCheck,
|
|
368
|
-
hasError: errors.length > 0,
|
|
369
|
-
value: value,
|
|
370
|
-
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
371
|
-
isDisabled: disabled,
|
|
372
|
-
titleValue: titleValue,
|
|
373
|
-
setValue: safeSetValue
|
|
374
|
-
}));
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function SlugEditor(props) {
|
|
378
|
-
var _parameters$instance, _entrySys$contentType3, _entrySys$contentType4;
|
|
379
|
-
|
|
380
|
-
const {
|
|
381
|
-
field,
|
|
382
|
-
parameters
|
|
383
|
-
} = props;
|
|
384
|
-
const {
|
|
385
|
-
locales,
|
|
386
|
-
entry,
|
|
387
|
-
space
|
|
388
|
-
} = props.baseSdk;
|
|
389
|
-
|
|
390
|
-
if (!isSupportedFieldTypes(field.type)) {
|
|
391
|
-
throw new Error(`"${field.type}" field type is not supported by SlugEditor`);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const trackingFieldId = (parameters == null ? void 0 : (_parameters$instance = parameters.instance) == null ? void 0 : _parameters$instance.trackingFieldId) ?? undefined;
|
|
395
|
-
const entrySys = entry.getSys();
|
|
396
|
-
const isLocaleOptional = locales.optional[field.locale];
|
|
397
|
-
const localeFallbackCode = locales.fallbacks[field.locale]; // If the field or the locale are not required (there's a locale setting that
|
|
398
|
-
// allows publishing even if the field is required) and if the locale has a
|
|
399
|
-
// fallback than there's no need for a slug unless the user manually enters
|
|
400
|
-
// one or the title field is also localized with a custom value.
|
|
401
|
-
|
|
402
|
-
const isOptionalFieldLocale = Boolean(!field.required || isLocaleOptional);
|
|
403
|
-
const isOptionalLocaleWithFallback = Boolean(isOptionalFieldLocale && localeFallbackCode && locales.available.includes(localeFallbackCode));
|
|
404
|
-
const performUniqueCheck = React.useCallback(value => {
|
|
405
|
-
var _entrySys$contentType, _entrySys$contentType2;
|
|
406
|
-
|
|
407
|
-
const searchQuery = {
|
|
408
|
-
content_type: entrySys == null ? void 0 : (_entrySys$contentType = entrySys.contentType) == null ? void 0 : (_entrySys$contentType2 = _entrySys$contentType.sys) == null ? void 0 : _entrySys$contentType2.id,
|
|
409
|
-
[`fields.${field.id}.${field.locale}`]: value,
|
|
410
|
-
'sys.id[ne]': entrySys.id,
|
|
411
|
-
'sys.publishedAt[exists]': true,
|
|
412
|
-
limit: 0
|
|
413
|
-
};
|
|
414
|
-
return space.getEntries(searchQuery).then(res => {
|
|
415
|
-
return res.total === 0;
|
|
416
|
-
});
|
|
417
|
-
}, [entrySys == null ? void 0 : (_entrySys$contentType3 = entrySys.contentType) == null ? void 0 : (_entrySys$contentType4 = _entrySys$contentType3.sys) == null ? void 0 : _entrySys$contentType4.id, field.id, field.locale, entrySys.id, space]);
|
|
418
|
-
return React.createElement(TrackingFieldConnector, {
|
|
419
|
-
sdk: props.baseSdk,
|
|
420
|
-
field: field,
|
|
421
|
-
defaultLocale: locales.default,
|
|
422
|
-
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
423
|
-
trackingFieldId: trackingFieldId
|
|
424
|
-
}, ({
|
|
425
|
-
titleValue,
|
|
426
|
-
isPublished,
|
|
427
|
-
isSame
|
|
428
|
-
}) => React.createElement(fieldEditorShared.FieldConnector, {
|
|
429
|
-
field: field,
|
|
430
|
-
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
431
|
-
throttle: 0
|
|
432
|
-
}, ({
|
|
433
|
-
value,
|
|
434
|
-
errors,
|
|
435
|
-
disabled,
|
|
436
|
-
setValue,
|
|
437
|
-
externalReset
|
|
438
|
-
}) => {
|
|
439
|
-
const shouldTrackTitle = isPublished === false && isSame === false;
|
|
440
|
-
const Component = shouldTrackTitle ? SlugEditorField : SlugEditorFieldStatic;
|
|
441
|
-
return React.createElement(FieldConnectorCallback, {
|
|
442
|
-
Component: Component,
|
|
443
|
-
titleValue: titleValue,
|
|
444
|
-
value: value,
|
|
445
|
-
errors: errors,
|
|
446
|
-
disabled: disabled,
|
|
447
|
-
setValue: setValue,
|
|
448
|
-
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
449
|
-
createdAt: entrySys.createdAt,
|
|
450
|
-
locale: field.locale,
|
|
451
|
-
performUniqueCheck: performUniqueCheck,
|
|
452
|
-
key: `slug-editor-${externalReset}`
|
|
453
|
-
});
|
|
454
|
-
}));
|
|
455
|
-
}
|
|
456
|
-
SlugEditor.defaultProps = {
|
|
457
|
-
isInitiallyDisabled: true
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
exports.SlugEditor = SlugEditor;
|
|
461
|
-
exports.makeSlug = makeSlug;
|
|
462
|
-
exports.slugify = slugify;
|
|
463
|
-
//# sourceMappingURL=field-editor-slug.cjs.development.js.map
|