@contentful/field-editor-shared 4.3.0 → 4.4.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.
@@ -20,7 +20,8 @@ _export(exports, {
20
20
  }
21
21
  });
22
22
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
23
- const _reactdom = /*#__PURE__*/ _interop_require_default(require("react-dom"));
23
+ const _reactdom = require("react-dom");
24
+ const _client = require("react-dom/client");
24
25
  const _f36components = require("@contentful/f36-components");
25
26
  const _isNumber = /*#__PURE__*/ _interop_require_default(require("lodash/isNumber"));
26
27
  function _interop_require_default(obj) {
@@ -69,15 +70,18 @@ function _interop_require_wildcard(obj, nodeInterop) {
69
70
  }
70
71
  return newObj;
71
72
  }
73
+ const CLOSE_DELAY = 300;
72
74
  function open(componentRenderer) {
73
75
  let rootDom = null;
76
+ let reactRoot = null;
74
77
  const getRoot = ()=>{
75
78
  if (rootDom === null) {
76
79
  rootDom = document.createElement('div');
77
80
  rootDom.setAttribute('id', 'field-editor-modal-root');
78
81
  document.body.appendChild(rootDom);
82
+ reactRoot = (0, _client.createRoot)(rootDom);
79
83
  }
80
- return rootDom;
84
+ return reactRoot;
81
85
  };
82
86
  return new Promise((resolve)=>{
83
87
  let currentConfig = {
@@ -85,19 +89,23 @@ function open(componentRenderer) {
85
89
  isShown: true
86
90
  };
87
91
  function render({ onClose, isShown }) {
88
- _reactdom.default.render(componentRenderer({
89
- onClose,
90
- isShown
91
- }), getRoot());
92
+ (0, _reactdom.flushSync)(()=>{
93
+ getRoot().render(componentRenderer({
94
+ onClose,
95
+ isShown
96
+ }));
97
+ });
92
98
  }
93
- function onClose(...args) {
99
+ async function onClose(...args) {
94
100
  currentConfig = {
95
101
  ...currentConfig,
96
102
  isShown: false
97
103
  };
98
104
  render(currentConfig);
99
105
  resolve(...args);
100
- getRoot().remove();
106
+ await new Promise((r)=>setTimeout(r, CLOSE_DELAY));
107
+ reactRoot?.unmount();
108
+ rootDom?.remove();
101
109
  }
102
110
  render(currentConfig);
103
111
  });
@@ -1,16 +1,20 @@
1
1
  import * as React from 'react';
2
- import ReactDOM from 'react-dom';
2
+ import { flushSync } from 'react-dom';
3
+ import { createRoot } from 'react-dom/client';
3
4
  import { Modal, ModalHeader } from '@contentful/f36-components';
4
5
  import isNumber from 'lodash/isNumber';
6
+ const CLOSE_DELAY = 300;
5
7
  export function open(componentRenderer) {
6
8
  let rootDom = null;
9
+ let reactRoot = null;
7
10
  const getRoot = ()=>{
8
11
  if (rootDom === null) {
9
12
  rootDom = document.createElement('div');
10
13
  rootDom.setAttribute('id', 'field-editor-modal-root');
11
14
  document.body.appendChild(rootDom);
15
+ reactRoot = createRoot(rootDom);
12
16
  }
13
- return rootDom;
17
+ return reactRoot;
14
18
  };
15
19
  return new Promise((resolve)=>{
16
20
  let currentConfig = {
@@ -18,19 +22,23 @@ export function open(componentRenderer) {
18
22
  isShown: true
19
23
  };
20
24
  function render({ onClose, isShown }) {
21
- ReactDOM.render(componentRenderer({
22
- onClose,
23
- isShown
24
- }), getRoot());
25
+ flushSync(()=>{
26
+ getRoot().render(componentRenderer({
27
+ onClose,
28
+ isShown
29
+ }));
30
+ });
25
31
  }
26
- function onClose(...args) {
32
+ async function onClose(...args) {
27
33
  currentConfig = {
28
34
  ...currentConfig,
29
35
  isShown: false
30
36
  };
31
37
  render(currentConfig);
32
38
  resolve(...args);
33
- getRoot().remove();
39
+ await new Promise((r)=>setTimeout(r, CLOSE_DELAY));
40
+ reactRoot?.unmount();
41
+ rootDom?.remove();
34
42
  }
35
43
  render(currentConfig);
36
44
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@contentful/app-sdk": "^4.42.0",
46
- "@contentful/field-editor-test-utils": "^3.0.0",
46
+ "@contentful/field-editor-test-utils": "^3.1.0",
47
47
  "@lingui/core": "5.3.0",
48
48
  "@tanstack/react-query": "^4.3.9",
49
49
  "@testing-library/react": "16.3.0"
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "registry": "https://npm.pkg.github.com/"
75
75
  },
76
- "gitHead": "733a70780b8117fd54a6578c4653307cb1910ad8"
76
+ "gitHead": "b3a1d791df55536d6de78bb138b97224d6c0c70e"
77
77
  }