@contentful/field-editor-slug 3.4.2-canary.29 → 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,48 +8,7 @@ Object.defineProperty(exports, "TrackingFieldConnector", {
8
8
  return TrackingFieldConnector;
9
9
  }
10
10
  });
11
- const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- function _getRequireWildcardCache(nodeInterop) {
13
- if (typeof WeakMap !== "function") return null;
14
- var cacheBabelInterop = new WeakMap();
15
- var cacheNodeInterop = new WeakMap();
16
- return (_getRequireWildcardCache = function(nodeInterop) {
17
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
- })(nodeInterop);
19
- }
20
- function _interop_require_wildcard(obj, nodeInterop) {
21
- if (!nodeInterop && obj && obj.__esModule) {
22
- return obj;
23
- }
24
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
- return {
26
- default: obj
27
- };
28
- }
29
- var cache = _getRequireWildcardCache(nodeInterop);
30
- if (cache && cache.has(obj)) {
31
- return cache.get(obj);
32
- }
33
- var newObj = {
34
- __proto__: null
35
- };
36
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
- for(var key in obj){
38
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
39
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
40
- if (desc && (desc.get || desc.set)) {
41
- Object.defineProperty(newObj, key, desc);
42
- } else {
43
- newObj[key] = obj[key];
44
- }
45
- }
46
- }
47
- newObj.default = obj;
48
- if (cache) {
49
- cache.set(obj, newObj);
50
- }
51
- return newObj;
52
- }
11
+ const _react = require("react");
53
12
  function getTitleField(sdk, trackingFieldId) {
54
13
  const { entry, contentType } = sdk;
55
14
  if (trackingFieldId && entry.fields[trackingFieldId]) {
@@ -58,7 +17,7 @@ function getTitleField(sdk, trackingFieldId) {
58
17
  return entry.fields[contentType.displayField];
59
18
  }
60
19
  function TrackingFieldConnector(props) {
61
- const [state, setState] = _react.useState(()=>{
20
+ const [state, setState] = (0, _react.useState)(()=>{
62
21
  const titleField = getTitleField(props.sdk, props.trackingFieldId);
63
22
  const entrySys = props.sdk.entry.getSys();
64
23
  return {
@@ -67,28 +26,32 @@ function TrackingFieldConnector(props) {
67
26
  isSame: titleField ? props.field.id === titleField.id : false
68
27
  };
69
28
  });
70
- _react.useEffect(()=>{
71
- const unsubscribeSysChanges = props.sdk.entry.onSysChanged((sys)=>{
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)=>{
72
35
  setState((currentState)=>({
73
36
  ...currentState,
74
37
  isPublished: Boolean(sys.publishedVersion)
75
38
  }));
76
39
  });
77
- const titleField = getTitleField(props.sdk, props.trackingFieldId);
40
+ const titleField = getTitleField(initialProps.sdk, initialProps.trackingFieldId);
78
41
  if (!titleField) {
79
42
  return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
80
43
  }
81
- const unsubscribeLocalizedValue = state.isSame ? undefined : titleField.onValueChanged(props.field.locale, (value)=>{
44
+ const unsubscribeLocalizedValue = initialIsSameRef.current ? undefined : titleField.onValueChanged(initialProps.field.locale, (value)=>{
82
45
  setState((currentState)=>({
83
46
  ...currentState,
84
47
  titleValue: value
85
48
  }));
86
49
  });
87
50
  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)) {
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)) {
92
55
  setState((currentState)=>({
93
56
  ...currentState,
94
57
  titleValue: value
@@ -108,13 +71,6 @@ function TrackingFieldConnector(props) {
108
71
  unsubscribeSysChanges();
109
72
  }
110
73
  };
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);
74
+ }, []);
75
+ return props.children ? props.children(state) : null;
120
76
  }
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { useLayoutEffect, useRef, useState } from 'react';
2
2
  function getTitleField(sdk, trackingFieldId) {
3
3
  const { entry, contentType } = sdk;
4
4
  if (trackingFieldId && entry.fields[trackingFieldId]) {
@@ -7,7 +7,7 @@ function getTitleField(sdk, trackingFieldId) {
7
7
  return entry.fields[contentType.displayField];
8
8
  }
9
9
  export function TrackingFieldConnector(props) {
10
- const [state, setState] = React.useState(()=>{
10
+ const [state, setState] = useState(()=>{
11
11
  const titleField = getTitleField(props.sdk, props.trackingFieldId);
12
12
  const entrySys = props.sdk.entry.getSys();
13
13
  return {
@@ -16,28 +16,32 @@ export function TrackingFieldConnector(props) {
16
16
  isSame: titleField ? props.field.id === titleField.id : false
17
17
  };
18
18
  });
19
- React.useEffect(()=>{
20
- const unsubscribeSysChanges = props.sdk.entry.onSysChanged((sys)=>{
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)=>{
21
25
  setState((currentState)=>({
22
26
  ...currentState,
23
27
  isPublished: Boolean(sys.publishedVersion)
24
28
  }));
25
29
  });
26
- const titleField = getTitleField(props.sdk, props.trackingFieldId);
30
+ const titleField = getTitleField(initialProps.sdk, initialProps.trackingFieldId);
27
31
  if (!titleField) {
28
32
  return typeof unsubscribeSysChanges === 'function' ? unsubscribeSysChanges : undefined;
29
33
  }
30
- const unsubscribeLocalizedValue = state.isSame ? undefined : titleField.onValueChanged(props.field.locale, (value)=>{
34
+ const unsubscribeLocalizedValue = initialIsSameRef.current ? undefined : titleField.onValueChanged(initialProps.field.locale, (value)=>{
31
35
  setState((currentState)=>({
32
36
  ...currentState,
33
37
  titleValue: value
34
38
  }));
35
39
  });
36
40
  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
+ 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)) {
41
45
  setState((currentState)=>({
42
46
  ...currentState,
43
47
  titleValue: value
@@ -57,13 +61,6 @@ export function TrackingFieldConnector(props) {
57
61
  unsubscribeSysChanges();
58
62
  }
59
63
  };
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);
64
+ }, []);
65
+ return props.children ? props.children(state) : null;
69
66
  }
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
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,7 +12,7 @@ interface TrackingFieldConnectorProps<ValueType> {
12
12
  defaultLocale: string;
13
13
  trackingFieldId?: string;
14
14
  isOptionalLocaleWithFallback: boolean;
15
- children?: (state: TrackingFieldConnectorState<ValueType>) => React.ReactNode;
15
+ children?: (state: TrackingFieldConnectorState<ValueType>) => ReactNode;
16
16
  }
17
- export declare function TrackingFieldConnector<ValueType>(props: TrackingFieldConnectorProps<ValueType>): React.JSX.Element;
17
+ export declare function TrackingFieldConnector<ValueType>(props: TrackingFieldConnectorProps<ValueType>): ReactNode;
18
18
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-slug",
3
- "version": "3.4.2-canary.29+3ee64435",
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.2-canary.29+3ee64435",
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": "3ee64435a6b1f0cb073174e7de406dc8cb4a74ad"
63
+ "gitHead": "69033935571ab64c941e30158340242c5a449c64"
64
64
  }