@contentful/field-editor-slug 3.4.1 → 3.4.2-canary.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.
|
@@ -8,61 +8,7 @@ Object.defineProperty(exports, "TrackingFieldConnector", {
|
|
|
8
8
|
return TrackingFieldConnector;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _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
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
26
|
-
if (typeof WeakMap !== "function") return null;
|
|
27
|
-
var cacheBabelInterop = new WeakMap();
|
|
28
|
-
var cacheNodeInterop = new WeakMap();
|
|
29
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
30
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
31
|
-
})(nodeInterop);
|
|
32
|
-
}
|
|
33
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
34
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
35
|
-
return obj;
|
|
36
|
-
}
|
|
37
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
38
|
-
return {
|
|
39
|
-
default: obj
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
43
|
-
if (cache && cache.has(obj)) {
|
|
44
|
-
return cache.get(obj);
|
|
45
|
-
}
|
|
46
|
-
var newObj = {
|
|
47
|
-
__proto__: null
|
|
48
|
-
};
|
|
49
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
50
|
-
for(var key in obj){
|
|
51
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
52
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
53
|
-
if (desc && (desc.get || desc.set)) {
|
|
54
|
-
Object.defineProperty(newObj, key, desc);
|
|
55
|
-
} else {
|
|
56
|
-
newObj[key] = obj[key];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
newObj.default = obj;
|
|
61
|
-
if (cache) {
|
|
62
|
-
cache.set(obj, newObj);
|
|
63
|
-
}
|
|
64
|
-
return newObj;
|
|
65
|
-
}
|
|
11
|
+
const _react = require("react");
|
|
66
12
|
function getTitleField(sdk, trackingFieldId) {
|
|
67
13
|
const { entry, contentType } = sdk;
|
|
68
14
|
if (trackingFieldId && entry.fields[trackingFieldId]) {
|
|
@@ -70,67 +16,61 @@ function getTitleField(sdk, trackingFieldId) {
|
|
|
70
16
|
}
|
|
71
17
|
return entry.fields[contentType.displayField];
|
|
72
18
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
19
|
+
function TrackingFieldConnector(props) {
|
|
20
|
+
const [state, setState] = (0, _react.useState)(()=>{
|
|
21
|
+
const titleField = getTitleField(props.sdk, props.trackingFieldId);
|
|
22
|
+
const entrySys = props.sdk.entry.getSys();
|
|
23
|
+
return {
|
|
24
|
+
titleValue: titleField ? titleField.getValue() : '',
|
|
25
|
+
isPublished: Boolean(entrySys.publishedVersion),
|
|
26
|
+
isSame: titleField ? props.field.id === titleField.id : false
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
const propsRef = (0, _react.useRef)(props);
|
|
30
|
+
propsRef.current = props;
|
|
31
|
+
const initialIsSameRef = (0, _react.useRef)(state.isSame);
|
|
32
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
33
|
+
const initialProps = propsRef.current;
|
|
34
|
+
const unsubscribeSysChanges = initialProps.sdk.entry.onSysChanged((sys)=>{
|
|
35
|
+
setState((currentState)=>({
|
|
36
|
+
...currentState,
|
|
37
|
+
isPublished: Boolean(sys.publishedVersion)
|
|
38
|
+
}));
|
|
80
39
|
});
|
|
81
|
-
const titleField = getTitleField(
|
|
40
|
+
const titleField = getTitleField(initialProps.sdk, initialProps.trackingFieldId);
|
|
82
41
|
if (!titleField) {
|
|
83
|
-
return;
|
|
42
|
+
return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
|
|
84
43
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
44
|
+
const unsubscribeLocalizedValue = initialIsSameRef.current ? undefined : titleField.onValueChanged(initialProps.field.locale, (value)=>{
|
|
45
|
+
setState((currentState)=>({
|
|
46
|
+
...currentState,
|
|
88
47
|
titleValue: value
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
if (!titleField.getValue(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
let unsubscribeValue;
|
|
51
|
+
if (initialProps.field.locale !== initialProps.defaultLocale) {
|
|
52
|
+
if (!initialProps.isOptionalLocaleWithFallback) {
|
|
53
|
+
unsubscribeValue = titleField.onValueChanged(initialProps.defaultLocale, (value)=>{
|
|
54
|
+
if (!titleField.getValue(propsRef.current.field.locale)) {
|
|
55
|
+
setState((currentState)=>({
|
|
56
|
+
...currentState,
|
|
57
|
+
titleValue: value
|
|
58
|
+
}));
|
|
99
59
|
}
|
|
100
60
|
});
|
|
101
61
|
}
|
|
102
62
|
}
|
|
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
|
|
63
|
+
return ()=>{
|
|
64
|
+
if (typeof unsubscribeValue === 'function') {
|
|
65
|
+
unsubscribeValue();
|
|
66
|
+
}
|
|
67
|
+
if (typeof unsubscribeLocalizedValue === 'function') {
|
|
68
|
+
unsubscribeLocalizedValue();
|
|
69
|
+
}
|
|
70
|
+
if (typeof unsubscribeSysChanges === 'function') {
|
|
71
|
+
unsubscribeSysChanges();
|
|
72
|
+
}
|
|
129
73
|
};
|
|
130
|
-
}
|
|
74
|
+
}, []);
|
|
75
|
+
return props.children ? props.children(state) : null;
|
|
131
76
|
}
|
|
132
|
-
_define_property(TrackingFieldConnector, "defaultProps", {
|
|
133
|
-
children: ()=>{
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
import * as React from 'react';
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
15
2
|
function getTitleField(sdk, trackingFieldId) {
|
|
16
3
|
const { entry, contentType } = sdk;
|
|
17
4
|
if (trackingFieldId && entry.fields[trackingFieldId]) {
|
|
@@ -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] = 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 = useRef(props);
|
|
20
|
+
propsRef.current = props;
|
|
21
|
+
const initialIsSameRef = useRef(state.isSame);
|
|
22
|
+
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
|
-
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import { FieldAPI, FieldAppSDK } from '@contentful/app-sdk';
|
|
3
3
|
type Nullable = null | undefined;
|
|
4
4
|
interface TrackingFieldConnectorState<ValueType> {
|
|
@@ -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>) => ReactNode;
|
|
28
16
|
}
|
|
17
|
+
export declare function TrackingFieldConnector<ValueType>(props: TrackingFieldConnectorProps<ValueType>): 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.30+69033935",
|
|
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.30+69033935",
|
|
44
44
|
"@emotion/css": "^11.13.5",
|
|
45
45
|
"@types/speakingurl": "^13.0.2",
|
|
46
46
|
"speakingurl": "^14.0.1",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"registry": "https://npm.pkg.github.com/"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "69033935571ab64c941e30158340242c5a449c64"
|
|
64
64
|
}
|