@contentful/field-editor-slug 3.4.1 → 3.4.2-canary.29

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,64 @@ function getTitleField(sdk, trackingFieldId) {
70
57
  }
71
58
  return entry.fields[contentType.displayField];
72
59
  }
73
- var _React_Component;
74
- class TrackingFieldConnector extends (_React_Component = _react.Component) {
75
- componentDidMount() {
76
- this.unsubscribeSysChanges = this.props.sdk.entry.onSysChanged((sys)=>{
77
- this.setState({
78
- isPublished: Boolean(sys.publishedVersion)
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
+ _react.useEffect(()=>{
71
+ const unsubscribeSysChanges = props.sdk.entry.onSysChanged((sys)=>{
72
+ setState((currentState)=>({
73
+ ...currentState,
74
+ isPublished: Boolean(sys.publishedVersion)
75
+ }));
80
76
  });
81
- const titleField = getTitleField(this.props.sdk, this.props.trackingFieldId);
77
+ const titleField = getTitleField(props.sdk, props.trackingFieldId);
82
78
  if (!titleField) {
83
- return;
79
+ return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
84
80
  }
85
- if (!this.state.isSame) {
86
- this.unsubscribeLocalizedValue = titleField.onValueChanged(this.props.field.locale, (value)=>{
87
- this.setState({
81
+ const unsubscribeLocalizedValue = state.isSame ? undefined : titleField.onValueChanged(props.field.locale, (value)=>{
82
+ setState((currentState)=>({
83
+ ...currentState,
88
84
  titleValue: value
89
- });
90
- });
91
- }
92
- if (this.props.field.locale !== this.props.defaultLocale) {
93
- if (!this.props.isOptionalLocaleWithFallback) {
94
- this.unsubscribeValue = titleField.onValueChanged(this.props.defaultLocale, (value)=>{
95
- if (!titleField.getValue(this.props.field.locale)) {
96
- this.setState({
97
- titleValue: value
98
- });
85
+ }));
86
+ });
87
+ let unsubscribeValue;
88
+ if (props.field.locale !== props.defaultLocale) {
89
+ if (!props.isOptionalLocaleWithFallback) {
90
+ unsubscribeValue = titleField.onValueChanged(props.defaultLocale, (value)=>{
91
+ if (!titleField.getValue(props.field.locale)) {
92
+ setState((currentState)=>({
93
+ ...currentState,
94
+ titleValue: value
95
+ }));
99
96
  }
100
97
  });
101
98
  }
102
99
  }
103
- }
104
- componentWillUnmount() {
105
- if (typeof this.unsubscribeValue === 'function') {
106
- this.unsubscribeValue();
107
- }
108
- if (typeof this.unsubscribeLocalizedValue === 'function') {
109
- this.unsubscribeLocalizedValue();
110
- }
111
- if (typeof this.unsubscribeSysChanges === 'function') {
112
- this.unsubscribeSysChanges();
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
100
+ return ()=>{
101
+ if (typeof unsubscribeValue === 'function') {
102
+ unsubscribeValue();
103
+ }
104
+ if (typeof unsubscribeLocalizedValue === 'function') {
105
+ unsubscribeLocalizedValue();
106
+ }
107
+ if (typeof unsubscribeSysChanges === 'function') {
108
+ unsubscribeSysChanges();
109
+ }
129
110
  };
130
- }
111
+ }, [
112
+ props.defaultLocale,
113
+ props.field,
114
+ props.isOptionalLocaleWithFallback,
115
+ props.sdk,
116
+ props.trackingFieldId,
117
+ state.isSame
118
+ ]);
119
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, null, props.children?.(state) ?? null);
131
120
  }
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,64 @@ function getTitleField(sdk, trackingFieldId) {
19
6
  }
20
7
  return entry.fields[contentType.displayField];
21
8
  }
22
- var _React_Component;
23
- export class TrackingFieldConnector extends (_React_Component = React.Component) {
24
- componentDidMount() {
25
- this.unsubscribeSysChanges = this.props.sdk.entry.onSysChanged((sys)=>{
26
- this.setState({
27
- isPublished: Boolean(sys.publishedVersion)
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
+ React.useEffect(()=>{
20
+ const unsubscribeSysChanges = props.sdk.entry.onSysChanged((sys)=>{
21
+ setState((currentState)=>({
22
+ ...currentState,
23
+ isPublished: Boolean(sys.publishedVersion)
24
+ }));
29
25
  });
30
- const titleField = getTitleField(this.props.sdk, this.props.trackingFieldId);
26
+ const titleField = getTitleField(props.sdk, props.trackingFieldId);
31
27
  if (!titleField) {
32
- return;
28
+ return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
33
29
  }
34
- if (!this.state.isSame) {
35
- this.unsubscribeLocalizedValue = titleField.onValueChanged(this.props.field.locale, (value)=>{
36
- this.setState({
30
+ const unsubscribeLocalizedValue = state.isSame ? undefined : titleField.onValueChanged(props.field.locale, (value)=>{
31
+ setState((currentState)=>({
32
+ ...currentState,
37
33
  titleValue: value
38
- });
39
- });
40
- }
41
- if (this.props.field.locale !== this.props.defaultLocale) {
42
- if (!this.props.isOptionalLocaleWithFallback) {
43
- this.unsubscribeValue = titleField.onValueChanged(this.props.defaultLocale, (value)=>{
44
- if (!titleField.getValue(this.props.field.locale)) {
45
- this.setState({
46
- titleValue: value
47
- });
34
+ }));
35
+ });
36
+ let unsubscribeValue;
37
+ if (props.field.locale !== props.defaultLocale) {
38
+ if (!props.isOptionalLocaleWithFallback) {
39
+ unsubscribeValue = titleField.onValueChanged(props.defaultLocale, (value)=>{
40
+ if (!titleField.getValue(props.field.locale)) {
41
+ setState((currentState)=>({
42
+ ...currentState,
43
+ titleValue: value
44
+ }));
48
45
  }
49
46
  });
50
47
  }
51
48
  }
52
- }
53
- componentWillUnmount() {
54
- if (typeof this.unsubscribeValue === 'function') {
55
- this.unsubscribeValue();
56
- }
57
- if (typeof this.unsubscribeLocalizedValue === 'function') {
58
- this.unsubscribeLocalizedValue();
59
- }
60
- if (typeof this.unsubscribeSysChanges === 'function') {
61
- this.unsubscribeSysChanges();
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
49
+ return ()=>{
50
+ if (typeof unsubscribeValue === 'function') {
51
+ unsubscribeValue();
52
+ }
53
+ if (typeof unsubscribeLocalizedValue === 'function') {
54
+ unsubscribeLocalizedValue();
55
+ }
56
+ if (typeof unsubscribeSysChanges === 'function') {
57
+ unsubscribeSysChanges();
58
+ }
78
59
  };
79
- }
60
+ }, [
61
+ props.defaultLocale,
62
+ props.field,
63
+ props.isOptionalLocaleWithFallback,
64
+ props.sdk,
65
+ props.trackingFieldId,
66
+ state.isSame
67
+ ]);
68
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, props.children?.(state) ?? null);
80
69
  }
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: (state: TrackingFieldConnectorState<ValueType>) => React.ReactNode;
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.JSX.Element;
29
18
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-slug",
3
- "version": "3.4.1",
3
+ "version": "3.4.2-canary.29+3ee64435",
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.1",
43
+ "@contentful/field-editor-shared": "^4.5.2-canary.29+3ee64435",
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": "78ed76ca4a3207924294971766a40bb46e196203"
63
+ "gitHead": "3ee64435a6b1f0cb073174e7de406dc8cb4a74ad"
64
64
  }