@contentful/field-editor-slug 1.5.18 → 1.6.0
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 +7 -5
- package/dist/cjs/SlugEditor.test.js +7 -7
- package/dist/cjs/SlugEditorField.js +4 -3
- package/dist/cjs/TrackingFieldConnector.js +2 -5
- package/dist/cjs/services/slugify.js +1 -1
- package/dist/cjs/styles.js +1 -1
- package/dist/esm/SlugEditor.js +6 -4
- package/dist/esm/SlugEditor.test.js +6 -6
- package/dist/esm/SlugEditorField.js +2 -1
- package/dist/esm/TrackingFieldConnector.js +1 -4
- package/dist/types/SlugEditor.d.ts +5 -1
- package/dist/types/SlugEditorField.d.ts +1 -0
- package/package.json +3 -3
package/dist/cjs/SlugEditor.js
CHANGED
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "SlugEditor", {
|
|
|
8
8
|
return SlugEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
13
13
|
const _SlugEditorField = require("./SlugEditorField");
|
|
14
14
|
const _TrackingFieldConnector = require("./TrackingFieldConnector");
|
|
@@ -56,7 +56,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
56
|
function isSupportedFieldTypes(val) {
|
|
57
57
|
return val === 'Symbol';
|
|
58
58
|
}
|
|
59
|
-
function FieldConnectorCallback({ Component, value, disabled, setValue, errors, titleValue, isOptionalLocaleWithFallback, locale, createdAt, performUniqueCheck }) {
|
|
59
|
+
function FieldConnectorCallback({ Component, value, disabled, setValue, errors, titleValue, isOptionalLocaleWithFallback, locale, createdAt, performUniqueCheck, id }) {
|
|
60
60
|
const safeSetValue = _react.useCallback(async (...args)=>{
|
|
61
61
|
try {
|
|
62
62
|
await setValue(...args);
|
|
@@ -75,11 +75,12 @@ function FieldConnectorCallback({ Component, value, disabled, setValue, errors,
|
|
|
75
75
|
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
76
76
|
isDisabled: disabled,
|
|
77
77
|
titleValue: titleValue,
|
|
78
|
-
setValue: safeSetValue
|
|
78
|
+
setValue: safeSetValue,
|
|
79
|
+
id: id
|
|
79
80
|
}));
|
|
80
81
|
}
|
|
81
82
|
function SlugEditor(props) {
|
|
82
|
-
const { field, parameters } = props;
|
|
83
|
+
const { field, parameters, id } = props;
|
|
83
84
|
const { locales, entry, space } = props.baseSdk;
|
|
84
85
|
if (!isSupportedFieldTypes(field.type)) {
|
|
85
86
|
throw new Error(`"${field.type}" field type is not supported by SlugEditor`);
|
|
@@ -132,7 +133,8 @@ function SlugEditor(props) {
|
|
|
132
133
|
createdAt: entrySys.createdAt,
|
|
133
134
|
locale: field.locale,
|
|
134
135
|
performUniqueCheck: performUniqueCheck,
|
|
135
|
-
key: `slug-editor-${externalReset}
|
|
136
|
+
key: `slug-editor-${externalReset}`,
|
|
137
|
+
id: id
|
|
136
138
|
});
|
|
137
139
|
}));
|
|
138
140
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
7
7
|
const _react1 = require("@testing-library/react");
|
|
8
8
|
require("@testing-library/jest-dom/extend-expect");
|
|
@@ -72,7 +72,7 @@ function createMocks(initialValues = {}) {
|
|
|
72
72
|
}), initialValues.titleField || '');
|
|
73
73
|
const [descriptionField] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>({
|
|
74
74
|
...field,
|
|
75
|
-
id:
|
|
75
|
+
id: "description-id",
|
|
76
76
|
setValue: jest.fn().mockImplementation(field.setValue),
|
|
77
77
|
getValue: jest.fn().mockImplementation(field.getValue),
|
|
78
78
|
onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
|
|
@@ -99,7 +99,7 @@ function createMocks(initialValues = {}) {
|
|
|
99
99
|
fields: {
|
|
100
100
|
'title-id': titleField,
|
|
101
101
|
'entry-id': field,
|
|
102
|
-
|
|
102
|
+
"description-id": descriptionField
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
105
|
contentType: {
|
|
@@ -501,7 +501,7 @@ describe('SlugEditor', ()=>{
|
|
|
501
501
|
const { field, titleField, descriptionField, sdk } = createMocks({
|
|
502
502
|
field: '',
|
|
503
503
|
titleField: 'This is initial title value',
|
|
504
|
-
descriptionField:
|
|
504
|
+
descriptionField: "This is initial description value"
|
|
505
505
|
});
|
|
506
506
|
(0, _react1.render)(_react.createElement(_SlugEditor.SlugEditor, {
|
|
507
507
|
field: field,
|
|
@@ -509,7 +509,7 @@ describe('SlugEditor', ()=>{
|
|
|
509
509
|
isInitiallyDisabled: false,
|
|
510
510
|
parameters: {
|
|
511
511
|
instance: {
|
|
512
|
-
trackingFieldId:
|
|
512
|
+
trackingFieldId: "description-id"
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
}));
|
|
@@ -517,9 +517,9 @@ describe('SlugEditor', ()=>{
|
|
|
517
517
|
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
518
518
|
expect(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
519
519
|
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
520
|
-
expect(field.setValue).toHaveBeenLastCalledWith(
|
|
520
|
+
expect(field.setValue).toHaveBeenLastCalledWith("this-is-initial-description-value");
|
|
521
521
|
});
|
|
522
|
-
await sdk.entry.fields[
|
|
522
|
+
await sdk.entry.fields["description-id"].setValue('Hello world!');
|
|
523
523
|
await (0, _react1.waitFor)(()=>{
|
|
524
524
|
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
525
525
|
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
@@ -16,12 +16,12 @@ _export(exports, {
|
|
|
16
16
|
return SlugEditorFieldStatic;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
19
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
20
20
|
const _f36components = require("@contentful/f36-components");
|
|
21
21
|
const _f36icons = require("@contentful/f36-icons");
|
|
22
22
|
const _usedebounce = require("use-debounce");
|
|
23
23
|
const _makeSlug = require("./services/makeSlug");
|
|
24
|
-
const _styles = _interop_require_wildcard(require("./styles"));
|
|
24
|
+
const _styles = /*#__PURE__*/ _interop_require_wildcard(require("./styles"));
|
|
25
25
|
function _getRequireWildcardCache(nodeInterop) {
|
|
26
26
|
if (typeof WeakMap !== "function") return null;
|
|
27
27
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -109,7 +109,7 @@ function useUniqueChecker(props) {
|
|
|
109
109
|
return status;
|
|
110
110
|
}
|
|
111
111
|
function SlugEditorFieldStatic(props) {
|
|
112
|
-
const { hasError, isDisabled, value, setValue, onChange, onBlur } = props;
|
|
112
|
+
const { hasError, isDisabled, value, setValue, onChange, onBlur, id } = props;
|
|
113
113
|
const status = useUniqueChecker(props);
|
|
114
114
|
return _react.createElement("div", {
|
|
115
115
|
className: _styles.inputContainer
|
|
@@ -120,6 +120,7 @@ function SlugEditorFieldStatic(props) {
|
|
|
120
120
|
isInvalid: hasError || status === 'duplicate',
|
|
121
121
|
isDisabled: isDisabled,
|
|
122
122
|
value: value || '',
|
|
123
|
+
id: id,
|
|
123
124
|
onChange: (e)=>{
|
|
124
125
|
setValue(e.target.value);
|
|
125
126
|
if (onChange) {
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "TrackingFieldConnector", {
|
|
|
8
8
|
return TrackingFieldConnector;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
function _define_property(obj, key, value) {
|
|
13
13
|
if (key in obj) {
|
|
14
14
|
Object.defineProperty(obj, key, {
|
|
@@ -118,10 +118,7 @@ class TrackingFieldConnector extends (_React_Component = _react.Component) {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
constructor(props){
|
|
121
|
-
super(props);
|
|
122
|
-
_define_property(this, "unsubscribeValue", null);
|
|
123
|
-
_define_property(this, "unsubscribeLocalizedValue", null);
|
|
124
|
-
_define_property(this, "unsubscribeSysChanges", null);
|
|
121
|
+
super(props), _define_property(this, "unsubscribeValue", null), _define_property(this, "unsubscribeLocalizedValue", null), _define_property(this, "unsubscribeSysChanges", null);
|
|
125
122
|
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
126
123
|
const entrySys = props.sdk.entry.getSys();
|
|
127
124
|
const isSame = titleField ? props.field.id === titleField.id : false;
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "slugify", {
|
|
|
8
8
|
return slugify;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _speakingurl = _interop_require_default(require("speakingurl"));
|
|
11
|
+
const _speakingurl = /*#__PURE__*/ _interop_require_default(require("speakingurl"));
|
|
12
12
|
function _interop_require_default(obj) {
|
|
13
13
|
return obj && obj.__esModule ? obj : {
|
|
14
14
|
default: obj
|
package/dist/cjs/styles.js
CHANGED
|
@@ -28,7 +28,7 @@ _export(exports, {
|
|
|
28
28
|
return validationRow;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
31
|
+
const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
|
|
32
32
|
const _emotion = require("emotion");
|
|
33
33
|
function _interop_require_default(obj) {
|
|
34
34
|
return obj && obj.__esModule ? obj : {
|
package/dist/esm/SlugEditor.js
CHANGED
|
@@ -5,7 +5,7 @@ import { TrackingFieldConnector } from './TrackingFieldConnector';
|
|
|
5
5
|
function isSupportedFieldTypes(val) {
|
|
6
6
|
return val === 'Symbol';
|
|
7
7
|
}
|
|
8
|
-
function FieldConnectorCallback({ Component, value, disabled, setValue, errors, titleValue, isOptionalLocaleWithFallback, locale, createdAt, performUniqueCheck }) {
|
|
8
|
+
function FieldConnectorCallback({ Component, value, disabled, setValue, errors, titleValue, isOptionalLocaleWithFallback, locale, createdAt, performUniqueCheck, id }) {
|
|
9
9
|
const safeSetValue = React.useCallback(async (...args)=>{
|
|
10
10
|
try {
|
|
11
11
|
await setValue(...args);
|
|
@@ -24,11 +24,12 @@ function FieldConnectorCallback({ Component, value, disabled, setValue, errors,
|
|
|
24
24
|
isOptionalLocaleWithFallback: isOptionalLocaleWithFallback,
|
|
25
25
|
isDisabled: disabled,
|
|
26
26
|
titleValue: titleValue,
|
|
27
|
-
setValue: safeSetValue
|
|
27
|
+
setValue: safeSetValue,
|
|
28
|
+
id: id
|
|
28
29
|
}));
|
|
29
30
|
}
|
|
30
31
|
export function SlugEditor(props) {
|
|
31
|
-
const { field, parameters } = props;
|
|
32
|
+
const { field, parameters, id } = props;
|
|
32
33
|
const { locales, entry, space } = props.baseSdk;
|
|
33
34
|
if (!isSupportedFieldTypes(field.type)) {
|
|
34
35
|
throw new Error(`"${field.type}" field type is not supported by SlugEditor`);
|
|
@@ -81,7 +82,8 @@ export function SlugEditor(props) {
|
|
|
81
82
|
createdAt: entrySys.createdAt,
|
|
82
83
|
locale: field.locale,
|
|
83
84
|
performUniqueCheck: performUniqueCheck,
|
|
84
|
-
key: `slug-editor-${externalReset}
|
|
85
|
+
key: `slug-editor-${externalReset}`,
|
|
86
|
+
id: id
|
|
85
87
|
});
|
|
86
88
|
}));
|
|
87
89
|
}
|
|
@@ -27,7 +27,7 @@ function createMocks(initialValues = {}) {
|
|
|
27
27
|
}), initialValues.titleField || '');
|
|
28
28
|
const [descriptionField] = createFakeFieldAPI((field)=>({
|
|
29
29
|
...field,
|
|
30
|
-
id:
|
|
30
|
+
id: "description-id",
|
|
31
31
|
setValue: jest.fn().mockImplementation(field.setValue),
|
|
32
32
|
getValue: jest.fn().mockImplementation(field.getValue),
|
|
33
33
|
onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
|
|
@@ -54,7 +54,7 @@ function createMocks(initialValues = {}) {
|
|
|
54
54
|
fields: {
|
|
55
55
|
'title-id': titleField,
|
|
56
56
|
'entry-id': field,
|
|
57
|
-
|
|
57
|
+
"description-id": descriptionField
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
contentType: {
|
|
@@ -456,7 +456,7 @@ describe('SlugEditor', ()=>{
|
|
|
456
456
|
const { field, titleField, descriptionField, sdk } = createMocks({
|
|
457
457
|
field: '',
|
|
458
458
|
titleField: 'This is initial title value',
|
|
459
|
-
descriptionField:
|
|
459
|
+
descriptionField: "This is initial description value"
|
|
460
460
|
});
|
|
461
461
|
render(React.createElement(SlugEditor, {
|
|
462
462
|
field: field,
|
|
@@ -464,7 +464,7 @@ describe('SlugEditor', ()=>{
|
|
|
464
464
|
isInitiallyDisabled: false,
|
|
465
465
|
parameters: {
|
|
466
466
|
instance: {
|
|
467
|
-
trackingFieldId:
|
|
467
|
+
trackingFieldId: "description-id"
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
}));
|
|
@@ -472,9 +472,9 @@ describe('SlugEditor', ()=>{
|
|
|
472
472
|
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
473
473
|
expect(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
474
474
|
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
475
|
-
expect(field.setValue).toHaveBeenLastCalledWith(
|
|
475
|
+
expect(field.setValue).toHaveBeenLastCalledWith("this-is-initial-description-value");
|
|
476
476
|
});
|
|
477
|
-
await sdk.entry.fields[
|
|
477
|
+
await sdk.entry.fields["description-id"].setValue('Hello world!');
|
|
478
478
|
await waitFor(()=>{
|
|
479
479
|
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
480
480
|
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
@@ -50,7 +50,7 @@ function useUniqueChecker(props) {
|
|
|
50
50
|
return status;
|
|
51
51
|
}
|
|
52
52
|
export function SlugEditorFieldStatic(props) {
|
|
53
|
-
const { hasError, isDisabled, value, setValue, onChange, onBlur } = props;
|
|
53
|
+
const { hasError, isDisabled, value, setValue, onChange, onBlur, id } = props;
|
|
54
54
|
const status = useUniqueChecker(props);
|
|
55
55
|
return React.createElement("div", {
|
|
56
56
|
className: styles.inputContainer
|
|
@@ -61,6 +61,7 @@ export function SlugEditorFieldStatic(props) {
|
|
|
61
61
|
isInvalid: hasError || status === 'duplicate',
|
|
62
62
|
isDisabled: isDisabled,
|
|
63
63
|
value: value || '',
|
|
64
|
+
id: id,
|
|
64
65
|
onChange: (e)=>{
|
|
65
66
|
setValue(e.target.value);
|
|
66
67
|
if (onChange) {
|
|
@@ -67,10 +67,7 @@ export class TrackingFieldConnector extends (_React_Component = React.Component)
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
constructor(props){
|
|
70
|
-
super(props);
|
|
71
|
-
_define_property(this, "unsubscribeValue", null);
|
|
72
|
-
_define_property(this, "unsubscribeLocalizedValue", null);
|
|
73
|
-
_define_property(this, "unsubscribeSysChanges", null);
|
|
70
|
+
super(props), _define_property(this, "unsubscribeValue", null), _define_property(this, "unsubscribeLocalizedValue", null), _define_property(this, "unsubscribeSysChanges", null);
|
|
74
71
|
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
75
72
|
const entrySys = props.sdk.entry.getSys();
|
|
76
73
|
const isSame = titleField ? props.field.id === titleField.id : false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { FieldAppSDK, FieldAPI } from '@contentful/app-sdk';
|
|
2
|
+
import type { FieldAppSDK, FieldAPI } from '@contentful/app-sdk';
|
|
3
3
|
export interface SlugEditorProps {
|
|
4
4
|
/**
|
|
5
5
|
* is the field disabled initially
|
|
@@ -10,6 +10,10 @@ export interface SlugEditorProps {
|
|
|
10
10
|
* sdk.field
|
|
11
11
|
*/
|
|
12
12
|
field: FieldAPI;
|
|
13
|
+
/**
|
|
14
|
+
* id used for associating the input field with its label
|
|
15
|
+
*/
|
|
16
|
+
id?: string;
|
|
13
17
|
parameters?: {
|
|
14
18
|
instance: {
|
|
15
19
|
trackingFieldId?: string;
|
|
@@ -9,6 +9,7 @@ interface SlugEditorFieldProps {
|
|
|
9
9
|
createdAt: string;
|
|
10
10
|
setValue: (value: string | null | undefined) => void;
|
|
11
11
|
performUniqueCheck: (value: string) => Promise<boolean>;
|
|
12
|
+
id?: string;
|
|
12
13
|
}
|
|
13
14
|
export declare function SlugEditorFieldStatic(props: SlugEditorFieldProps & {
|
|
14
15
|
onChange?: Function;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-slug",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@contentful/f36-components": "^4.70.0",
|
|
39
39
|
"@contentful/f36-icons": "^4.29.0",
|
|
40
40
|
"@contentful/f36-tokens": "^4.0.5",
|
|
41
|
-
"@contentful/field-editor-shared": "^2.4.
|
|
41
|
+
"@contentful/field-editor-shared": "^2.4.1",
|
|
42
42
|
"@types/speakingurl": "^13.0.2",
|
|
43
43
|
"emotion": "^10.0.17",
|
|
44
44
|
"lodash": "^4.17.15",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"registry": "https://npm.pkg.github.com/"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "7ec565308c8d4da384b8fec6f5d840bdf6d4927d"
|
|
60
60
|
}
|