@contentful/field-editor-slug 3.4.1 → 3.4.2-canary.sha-cf70e54f.30
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.
|
@@ -9,19 +9,6 @@ Object.defineProperty(exports, "TrackingFieldConnector", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
-
function _define_property(obj, key, value) {
|
|
13
|
-
if (key in obj) {
|
|
14
|
-
Object.defineProperty(obj, key, {
|
|
15
|
-
value: value,
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true
|
|
19
|
-
});
|
|
20
|
-
} else {
|
|
21
|
-
obj[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
12
|
function _getRequireWildcardCache(nodeInterop) {
|
|
26
13
|
if (typeof WeakMap !== "function") return null;
|
|
27
14
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -70,67 +57,61 @@ function getTitleField(sdk, trackingFieldId) {
|
|
|
70
57
|
}
|
|
71
58
|
return entry.fields[contentType.displayField];
|
|
72
59
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
function TrackingFieldConnector(props) {
|
|
61
|
+
const [state, setState] = _react.useState(()=>{
|
|
62
|
+
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
63
|
+
const entrySys = props.sdk.entry.getSys();
|
|
64
|
+
return {
|
|
65
|
+
titleValue: titleField ? titleField.getValue() : '',
|
|
66
|
+
isPublished: Boolean(entrySys.publishedVersion),
|
|
67
|
+
isSame: titleField ? props.field.id === titleField.id : false
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const propsRef = _react.useRef(props);
|
|
71
|
+
propsRef.current = props;
|
|
72
|
+
const initialIsSameRef = _react.useRef(state.isSame);
|
|
73
|
+
_react.useLayoutEffect(()=>{
|
|
74
|
+
const initialProps = propsRef.current;
|
|
75
|
+
const unsubscribeSysChanges = initialProps.sdk.entry.onSysChanged((sys)=>{
|
|
76
|
+
setState((currentState)=>({
|
|
77
|
+
...currentState,
|
|
78
|
+
isPublished: Boolean(sys.publishedVersion)
|
|
79
|
+
}));
|
|
80
80
|
});
|
|
81
|
-
const titleField = getTitleField(
|
|
81
|
+
const titleField = getTitleField(initialProps.sdk, initialProps.trackingFieldId);
|
|
82
82
|
if (!titleField) {
|
|
83
|
-
return;
|
|
83
|
+
return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const unsubscribeLocalizedValue = initialIsSameRef.current ? undefined : titleField.onValueChanged(initialProps.field.locale, (value)=>{
|
|
86
|
+
setState((currentState)=>({
|
|
87
|
+
...currentState,
|
|
88
88
|
titleValue: value
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
if (!titleField.getValue(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
}));
|
|
90
|
+
});
|
|
91
|
+
let unsubscribeValue;
|
|
92
|
+
if (initialProps.field.locale !== initialProps.defaultLocale) {
|
|
93
|
+
if (!initialProps.isOptionalLocaleWithFallback) {
|
|
94
|
+
unsubscribeValue = titleField.onValueChanged(initialProps.defaultLocale, (value)=>{
|
|
95
|
+
if (!titleField.getValue(propsRef.current.field.locale)) {
|
|
96
|
+
setState((currentState)=>({
|
|
97
|
+
...currentState,
|
|
98
|
+
titleValue: value
|
|
99
|
+
}));
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
render() {
|
|
116
|
-
return this.props.children({
|
|
117
|
-
...this.state
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
constructor(props){
|
|
121
|
-
super(props), _define_property(this, "unsubscribeValue", null), _define_property(this, "unsubscribeLocalizedValue", null), _define_property(this, "unsubscribeSysChanges", null);
|
|
122
|
-
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
123
|
-
const entrySys = props.sdk.entry.getSys();
|
|
124
|
-
const isSame = titleField ? props.field.id === titleField.id : false;
|
|
125
|
-
this.state = {
|
|
126
|
-
titleValue: titleField ? titleField.getValue() : '',
|
|
127
|
-
isPublished: Boolean(entrySys.publishedVersion),
|
|
128
|
-
isSame
|
|
104
|
+
return ()=>{
|
|
105
|
+
if (typeof unsubscribeValue === 'function') {
|
|
106
|
+
unsubscribeValue();
|
|
107
|
+
}
|
|
108
|
+
if (typeof unsubscribeLocalizedValue === 'function') {
|
|
109
|
+
unsubscribeLocalizedValue();
|
|
110
|
+
}
|
|
111
|
+
if (typeof unsubscribeSysChanges === 'function') {
|
|
112
|
+
unsubscribeSysChanges();
|
|
113
|
+
}
|
|
129
114
|
};
|
|
130
|
-
}
|
|
115
|
+
}, []);
|
|
116
|
+
return props.children ? props.children(state) : null;
|
|
131
117
|
}
|
|
132
|
-
_define_property(TrackingFieldConnector, "defaultProps", {
|
|
133
|
-
children: ()=>{
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
1
|
import * as React from 'react';
|
|
15
2
|
function getTitleField(sdk, trackingFieldId) {
|
|
16
3
|
const { entry, contentType } = sdk;
|
|
@@ -19,67 +6,61 @@ function getTitleField(sdk, trackingFieldId) {
|
|
|
19
6
|
}
|
|
20
7
|
return entry.fields[contentType.displayField];
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
export function TrackingFieldConnector(props) {
|
|
10
|
+
const [state, setState] = React.useState(()=>{
|
|
11
|
+
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
12
|
+
const entrySys = props.sdk.entry.getSys();
|
|
13
|
+
return {
|
|
14
|
+
titleValue: titleField ? titleField.getValue() : '',
|
|
15
|
+
isPublished: Boolean(entrySys.publishedVersion),
|
|
16
|
+
isSame: titleField ? props.field.id === titleField.id : false
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
const propsRef = React.useRef(props);
|
|
20
|
+
propsRef.current = props;
|
|
21
|
+
const initialIsSameRef = React.useRef(state.isSame);
|
|
22
|
+
React.useLayoutEffect(()=>{
|
|
23
|
+
const initialProps = propsRef.current;
|
|
24
|
+
const unsubscribeSysChanges = initialProps.sdk.entry.onSysChanged((sys)=>{
|
|
25
|
+
setState((currentState)=>({
|
|
26
|
+
...currentState,
|
|
27
|
+
isPublished: Boolean(sys.publishedVersion)
|
|
28
|
+
}));
|
|
29
29
|
});
|
|
30
|
-
const titleField = getTitleField(
|
|
30
|
+
const titleField = getTitleField(initialProps.sdk, initialProps.trackingFieldId);
|
|
31
31
|
if (!titleField) {
|
|
32
|
-
return;
|
|
32
|
+
return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const unsubscribeLocalizedValue = initialIsSameRef.current ? undefined : titleField.onValueChanged(initialProps.field.locale, (value)=>{
|
|
35
|
+
setState((currentState)=>({
|
|
36
|
+
...currentState,
|
|
37
37
|
titleValue: value
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
if (!
|
|
43
|
-
|
|
44
|
-
if (!titleField.getValue(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
40
|
+
let unsubscribeValue;
|
|
41
|
+
if (initialProps.field.locale !== initialProps.defaultLocale) {
|
|
42
|
+
if (!initialProps.isOptionalLocaleWithFallback) {
|
|
43
|
+
unsubscribeValue = titleField.onValueChanged(initialProps.defaultLocale, (value)=>{
|
|
44
|
+
if (!titleField.getValue(propsRef.current.field.locale)) {
|
|
45
|
+
setState((currentState)=>({
|
|
46
|
+
...currentState,
|
|
47
|
+
titleValue: value
|
|
48
|
+
}));
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
render() {
|
|
65
|
-
return this.props.children({
|
|
66
|
-
...this.state
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
constructor(props){
|
|
70
|
-
super(props), _define_property(this, "unsubscribeValue", null), _define_property(this, "unsubscribeLocalizedValue", null), _define_property(this, "unsubscribeSysChanges", null);
|
|
71
|
-
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
72
|
-
const entrySys = props.sdk.entry.getSys();
|
|
73
|
-
const isSame = titleField ? props.field.id === titleField.id : false;
|
|
74
|
-
this.state = {
|
|
75
|
-
titleValue: titleField ? titleField.getValue() : '',
|
|
76
|
-
isPublished: Boolean(entrySys.publishedVersion),
|
|
77
|
-
isSame
|
|
53
|
+
return ()=>{
|
|
54
|
+
if (typeof unsubscribeValue === 'function') {
|
|
55
|
+
unsubscribeValue();
|
|
56
|
+
}
|
|
57
|
+
if (typeof unsubscribeLocalizedValue === 'function') {
|
|
58
|
+
unsubscribeLocalizedValue();
|
|
59
|
+
}
|
|
60
|
+
if (typeof unsubscribeSysChanges === 'function') {
|
|
61
|
+
unsubscribeSysChanges();
|
|
62
|
+
}
|
|
78
63
|
};
|
|
79
|
-
}
|
|
64
|
+
}, []);
|
|
65
|
+
return props.children ? props.children(state) : null;
|
|
80
66
|
}
|
|
81
|
-
_define_property(TrackingFieldConnector, "defaultProps", {
|
|
82
|
-
children: ()=>{
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
@@ -12,18 +12,7 @@ interface TrackingFieldConnectorProps<ValueType> {
|
|
|
12
12
|
defaultLocale: string;
|
|
13
13
|
trackingFieldId?: string;
|
|
14
14
|
isOptionalLocaleWithFallback: boolean;
|
|
15
|
-
children
|
|
16
|
-
}
|
|
17
|
-
export declare class TrackingFieldConnector<ValueType> extends React.Component<TrackingFieldConnectorProps<ValueType>, TrackingFieldConnectorState<ValueType>> {
|
|
18
|
-
static defaultProps: {
|
|
19
|
-
children: () => null;
|
|
20
|
-
};
|
|
21
|
-
constructor(props: TrackingFieldConnectorProps<ValueType>);
|
|
22
|
-
unsubscribeValue: Function | null;
|
|
23
|
-
unsubscribeLocalizedValue: Function | null;
|
|
24
|
-
unsubscribeSysChanges: Function | null;
|
|
25
|
-
componentDidMount(): void;
|
|
26
|
-
componentWillUnmount(): void;
|
|
27
|
-
render(): React.ReactNode;
|
|
15
|
+
children?: (state: TrackingFieldConnectorState<ValueType>) => React.ReactNode;
|
|
28
16
|
}
|
|
17
|
+
export declare function TrackingFieldConnector<ValueType>(props: TrackingFieldConnectorProps<ValueType>): React.ReactNode;
|
|
29
18
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-slug",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2-canary.sha-cf70e54f.30+cf70e54f",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@contentful/f36-icons": "^6.7.1",
|
|
41
41
|
"@contentful/f36-note": "^6.7.0",
|
|
42
42
|
"@contentful/f36-tokens": "^6.1.2",
|
|
43
|
-
"@contentful/field-editor-shared": "^4.5.
|
|
43
|
+
"@contentful/field-editor-shared": "^4.5.2-canary.sha-cf70e54f.30+cf70e54f",
|
|
44
44
|
"@emotion/css": "^11.13.5",
|
|
45
45
|
"@types/speakingurl": "^13.0.2",
|
|
46
46
|
"speakingurl": "^14.0.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@contentful/app-sdk": "^4.45.0",
|
|
51
|
-
"@contentful/field-editor-test-utils": "^3.1.
|
|
51
|
+
"@contentful/field-editor-test-utils": "^3.1.3-canary.sha-cf70e54f.34+cf70e54f",
|
|
52
52
|
"@lingui/core": "5.3.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"registry": "https://npm.pkg.github.com/"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "cf70e54f33a6ecad25723afee834f3fe75bef531"
|
|
64
64
|
}
|