@atlaskit/editor-core 203.11.13 → 203.11.14

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 203.11.14
4
+
5
+ ### Patch Changes
6
+
7
+ - [#107453](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107453)
8
+ [`2cdb4872aa8e0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2cdb4872aa8e0) -
9
+ EDF-2233: Fix autofocus in React 18 Concurrent Rendering mode - fix is behind
10
+ platform_editor_react_18_autofocus_fix.
11
+
3
12
  ## 203.11.13
4
13
 
5
14
  ### Patch Changes
@@ -1,15 +1,30 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.handleEditorFocus = handleEditorFocus;
8
+ var _react = _interopRequireDefault(require("react"));
7
9
  var _state = require("@atlaskit/editor-prosemirror/state");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
11
  function handleEditorFocus(view) {
9
12
  if (view !== null && view !== void 0 && view.hasFocus()) {
10
13
  return;
11
14
  }
12
- return window.setTimeout(function () {
15
+
16
+ /**
17
+ * If startTransition is available (in React 18),
18
+ * don't use setTimeout as startTransition will be used in ReactEditorViewNext.
19
+ * setTimeout(fn, 0) will not defer the focus reliably in React 18 with
20
+ * concurrent rendering.
21
+ */
22
+ var react16OnlySetTimeout = _react.default !== null && _react.default !== void 0 && _react.default.startTransition && (0, _platformFeatureFlags.fg)('platform_editor_react_18_autofocus_fix') ? function (fn) {
23
+ return fn();
24
+ } : function (fn) {
25
+ return window.setTimeout(fn, 0);
26
+ };
27
+ return react16OnlySetTimeout(function () {
13
28
  if (view !== null && view !== void 0 && view.hasFocus()) {
14
29
  return;
15
30
  }
@@ -42,5 +57,5 @@ function handleEditorFocus(view) {
42
57
  view.dispatch(tr);
43
58
  view.focus();
44
59
  }
45
- }, 0);
60
+ });
46
61
  }
@@ -451,11 +451,17 @@ function ReactEditorView(props) {
451
451
  }, [getDirectEditorProps, dispatchAnalyticsEvent]);
452
452
  var _useState3 = (0, _react.useState)(undefined),
453
453
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
454
- _ = _useState4[0],
454
+ editorView = _useState4[0],
455
455
  setEditorView = _useState4[1];
456
456
  var onEditorCreated = props.onEditorCreated,
457
457
  onEditorDestroyed = props.onEditorDestroyed,
458
458
  shouldFocus = props.editorProps.shouldFocus;
459
+ (0, _react.useLayoutEffect)(function () {
460
+ var _editorView$props$edi, _editorView$props;
461
+ if (shouldFocus && editorView !== null && editorView !== void 0 && (_editorView$props$edi = (_editorView$props = editorView.props).editable) !== null && _editorView$props$edi !== void 0 && _editorView$props$edi.call(_editorView$props, editorView.state) && (0, _platformFeatureFlags.fg)('platform_editor_react_18_autofocus_fix')) {
462
+ focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(editorView);
463
+ }
464
+ }, [editorView, shouldFocus]);
459
465
  var handleEditorViewRef = (0, _react.useCallback)(function (node) {
460
466
  if (!viewRef.current && node) {
461
467
  var view = createEditorView(node);
@@ -465,12 +471,27 @@ function ReactEditorView(props) {
465
471
  eventDispatcher: eventDispatcher,
466
472
  transformer: contentTransformer.current
467
473
  });
468
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
469
- focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(view);
474
+ if ((0, _platformFeatureFlags.fg)('platform_editor_react_18_autofocus_fix')) {
475
+ var _startTransition;
476
+ /**
477
+ * Defer using startTransition when it is available (in React 18) to fix
478
+ * autofocus bug where React 18's concurrent rendering mode interferes with
479
+ * setTimeout used in handleEditorFocus, causing autofocus to break.
480
+ */
481
+ var react18OnlyStartTransition = (_startTransition = _react.default === null || _react.default === void 0 ? void 0 : _react.default.startTransition) !== null && _startTransition !== void 0 ? _startTransition : function (fn) {
482
+ return fn();
483
+ };
484
+ react18OnlyStartTransition(function () {
485
+ // Force React to re-render so consumers get a reference to the editor view
486
+ setEditorView(view);
487
+ });
488
+ } else {
489
+ if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
490
+ focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(view);
491
+ }
492
+ // Force React to re-render so consumers get a reference to the editor view
493
+ setEditorView(view);
470
494
  }
471
-
472
- // Force React to re-render so consumers get a reference to the editor view
473
- setEditorView(view);
474
495
  } else if (viewRef.current && !node) {
475
496
  // When the appearance is changed, React will call handleEditorViewRef with node === null
476
497
  // to destroy the old EditorView, before calling this method again with node === div to
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "203.11.13";
8
+ var version = exports.version = "203.11.14";
@@ -1,9 +1,19 @@
1
+ import React from 'react';
1
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
2
4
  export function handleEditorFocus(view) {
3
5
  if (view !== null && view !== void 0 && view.hasFocus()) {
4
6
  return;
5
7
  }
6
- return window.setTimeout(() => {
8
+
9
+ /**
10
+ * If startTransition is available (in React 18),
11
+ * don't use setTimeout as startTransition will be used in ReactEditorViewNext.
12
+ * setTimeout(fn, 0) will not defer the focus reliably in React 18 with
13
+ * concurrent rendering.
14
+ */
15
+ const react16OnlySetTimeout = React !== null && React !== void 0 && React.startTransition && fg('platform_editor_react_18_autofocus_fix') ? fn => fn() : fn => window.setTimeout(fn, 0);
16
+ return react16OnlySetTimeout(() => {
7
17
  if (view !== null && view !== void 0 && view.hasFocus()) {
8
18
  return;
9
19
  }
@@ -36,5 +46,5 @@ export function handleEditorFocus(view) {
36
46
  view.dispatch(tr);
37
47
  view.focus();
38
48
  }
39
- }, 0);
49
+ });
40
50
  }
@@ -422,7 +422,7 @@ export function ReactEditorView(props) {
422
422
  });
423
423
  return view;
424
424
  }, [getDirectEditorProps, dispatchAnalyticsEvent]);
425
- const [_, setEditorView] = useState(undefined);
425
+ const [editorView, setEditorView] = useState(undefined);
426
426
  const {
427
427
  onEditorCreated,
428
428
  onEditorDestroyed,
@@ -430,6 +430,12 @@ export function ReactEditorView(props) {
430
430
  shouldFocus
431
431
  }
432
432
  } = props;
433
+ useLayoutEffect(() => {
434
+ var _editorView$props$edi, _editorView$props;
435
+ if (shouldFocus && editorView !== null && editorView !== void 0 && (_editorView$props$edi = (_editorView$props = editorView.props).editable) !== null && _editorView$props$edi !== void 0 && _editorView$props$edi.call(_editorView$props, editorView.state) && fg('platform_editor_react_18_autofocus_fix')) {
436
+ focusTimeoutId.current = handleEditorFocus(editorView);
437
+ }
438
+ }, [editorView, shouldFocus]);
433
439
  const handleEditorViewRef = useCallback(node => {
434
440
  if (!viewRef.current && node) {
435
441
  const view = createEditorView(node);
@@ -439,12 +445,25 @@ export function ReactEditorView(props) {
439
445
  eventDispatcher: eventDispatcher,
440
446
  transformer: contentTransformer.current
441
447
  });
442
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
443
- focusTimeoutId.current = handleEditorFocus(view);
448
+ if (fg('platform_editor_react_18_autofocus_fix')) {
449
+ var _startTransition;
450
+ /**
451
+ * Defer using startTransition when it is available (in React 18) to fix
452
+ * autofocus bug where React 18's concurrent rendering mode interferes with
453
+ * setTimeout used in handleEditorFocus, causing autofocus to break.
454
+ */
455
+ const react18OnlyStartTransition = (_startTransition = React === null || React === void 0 ? void 0 : React.startTransition) !== null && _startTransition !== void 0 ? _startTransition : fn => fn();
456
+ react18OnlyStartTransition(() => {
457
+ // Force React to re-render so consumers get a reference to the editor view
458
+ setEditorView(view);
459
+ });
460
+ } else {
461
+ if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
462
+ focusTimeoutId.current = handleEditorFocus(view);
463
+ }
464
+ // Force React to re-render so consumers get a reference to the editor view
465
+ setEditorView(view);
444
466
  }
445
-
446
- // Force React to re-render so consumers get a reference to the editor view
447
- setEditorView(view);
448
467
  } else if (viewRef.current && !node) {
449
468
  // When the appearance is changed, React will call handleEditorViewRef with node === null
450
469
  // to destroy the old EditorView, before calling this method again with node === div to
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "203.11.13";
2
+ export const version = "203.11.14";
@@ -1,9 +1,23 @@
1
+ import React from 'react';
1
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
2
4
  export function handleEditorFocus(view) {
3
5
  if (view !== null && view !== void 0 && view.hasFocus()) {
4
6
  return;
5
7
  }
6
- return window.setTimeout(function () {
8
+
9
+ /**
10
+ * If startTransition is available (in React 18),
11
+ * don't use setTimeout as startTransition will be used in ReactEditorViewNext.
12
+ * setTimeout(fn, 0) will not defer the focus reliably in React 18 with
13
+ * concurrent rendering.
14
+ */
15
+ var react16OnlySetTimeout = React !== null && React !== void 0 && React.startTransition && fg('platform_editor_react_18_autofocus_fix') ? function (fn) {
16
+ return fn();
17
+ } : function (fn) {
18
+ return window.setTimeout(fn, 0);
19
+ };
20
+ return react16OnlySetTimeout(function () {
7
21
  if (view !== null && view !== void 0 && view.hasFocus()) {
8
22
  return;
9
23
  }
@@ -36,5 +50,5 @@ export function handleEditorFocus(view) {
36
50
  view.dispatch(tr);
37
51
  view.focus();
38
52
  }
39
- }, 0);
53
+ });
40
54
  }
@@ -440,11 +440,17 @@ export function ReactEditorView(props) {
440
440
  }, [getDirectEditorProps, dispatchAnalyticsEvent]);
441
441
  var _useState3 = useState(undefined),
442
442
  _useState4 = _slicedToArray(_useState3, 2),
443
- _ = _useState4[0],
443
+ editorView = _useState4[0],
444
444
  setEditorView = _useState4[1];
445
445
  var onEditorCreated = props.onEditorCreated,
446
446
  onEditorDestroyed = props.onEditorDestroyed,
447
447
  shouldFocus = props.editorProps.shouldFocus;
448
+ useLayoutEffect(function () {
449
+ var _editorView$props$edi, _editorView$props;
450
+ if (shouldFocus && editorView !== null && editorView !== void 0 && (_editorView$props$edi = (_editorView$props = editorView.props).editable) !== null && _editorView$props$edi !== void 0 && _editorView$props$edi.call(_editorView$props, editorView.state) && fg('platform_editor_react_18_autofocus_fix')) {
451
+ focusTimeoutId.current = handleEditorFocus(editorView);
452
+ }
453
+ }, [editorView, shouldFocus]);
448
454
  var handleEditorViewRef = useCallback(function (node) {
449
455
  if (!viewRef.current && node) {
450
456
  var view = createEditorView(node);
@@ -454,12 +460,27 @@ export function ReactEditorView(props) {
454
460
  eventDispatcher: eventDispatcher,
455
461
  transformer: contentTransformer.current
456
462
  });
457
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
458
- focusTimeoutId.current = handleEditorFocus(view);
463
+ if (fg('platform_editor_react_18_autofocus_fix')) {
464
+ var _startTransition;
465
+ /**
466
+ * Defer using startTransition when it is available (in React 18) to fix
467
+ * autofocus bug where React 18's concurrent rendering mode interferes with
468
+ * setTimeout used in handleEditorFocus, causing autofocus to break.
469
+ */
470
+ var react18OnlyStartTransition = (_startTransition = React === null || React === void 0 ? void 0 : React.startTransition) !== null && _startTransition !== void 0 ? _startTransition : function (fn) {
471
+ return fn();
472
+ };
473
+ react18OnlyStartTransition(function () {
474
+ // Force React to re-render so consumers get a reference to the editor view
475
+ setEditorView(view);
476
+ });
477
+ } else {
478
+ if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
479
+ focusTimeoutId.current = handleEditorFocus(view);
480
+ }
481
+ // Force React to re-render so consumers get a reference to the editor view
482
+ setEditorView(view);
459
483
  }
460
-
461
- // Force React to re-render so consumers get a reference to the editor view
462
- setEditorView(view);
463
484
  } else if (viewRef.current && !node) {
464
485
  // When the appearance is changed, React will call handleEditorViewRef with node === null
465
486
  // to destroy the old EditorView, before calling this method again with node === div to
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "203.11.13";
2
+ export var version = "203.11.14";
@@ -1,2 +1,2 @@
1
1
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
2
- export declare function handleEditorFocus(view: EditorView | null): number | undefined;
2
+ export declare function handleEditorFocus(view: EditorView | undefined): number | undefined | void;
@@ -1,2 +1,2 @@
1
1
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
2
- export declare function handleEditorFocus(view: EditorView | null): number | undefined;
2
+ export declare function handleEditorFocus(view: EditorView | undefined): number | undefined | void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "203.11.13",
3
+ "version": "203.11.14",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -103,7 +103,7 @@
103
103
  "@atlaskit/visual-regression": "*",
104
104
  "@atlassian/adf-schema-json": "^1.22.0",
105
105
  "@atlassian/feature-flags-test-utils": "*",
106
- "@atlassian/search-provider": "3.0.27",
106
+ "@atlassian/search-provider": "3.0.28",
107
107
  "@emotion/jest": "^11.8.0",
108
108
  "@storybook/addon-knobs": "^6.4.0",
109
109
  "@testing-library/react": "^12.1.5",
@@ -407,6 +407,9 @@
407
407
  "platform_editor_nested_tables_paste_dupe_fix": {
408
408
  "type": "boolean",
409
409
  "referenceOnly": true
410
+ },
411
+ "platform_editor_react_18_autofocus_fix": {
412
+ "type": "boolean"
410
413
  }
411
414
  },
412
415
  "stricter": {