@atlaskit/editor-core 205.1.1 → 205.1.3

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,25 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 205.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#132362](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/132362)
8
+ [`2e90b51d52288`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2e90b51d52288) -
9
+ [ux] [ED-26841] Do not autofocus editor when it is a live page with content. Additionally hide
10
+ cursor marks and ensure cursor starts at the very start of document to prevent selection
11
+ appearance and toolbars.
12
+ - Updated dependencies
13
+
14
+ ## 205.1.2
15
+
16
+ ### Patch Changes
17
+
18
+ - [#134683](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/134683)
19
+ [`92c5bd796d74f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/92c5bd796d74f) -
20
+ [ux] ED-27348 ED-27448 remove toolbar header spacing
21
+ - Updated dependencies
22
+
3
23
  ## 205.1.1
4
24
 
5
25
  ### Patch Changes
@@ -22,6 +22,7 @@ var _preset = require("@atlaskit/editor-common/preset");
22
22
  var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
23
23
  var _uiReact = require("@atlaskit/editor-common/ui-react");
24
24
  var _analytics2 = require("@atlaskit/editor-common/utils/analytics");
25
+ var _document = require("@atlaskit/editor-common/utils/document");
25
26
  var _state2 = require("@atlaskit/editor-prosemirror/state");
26
27
  var _view = require("@atlaskit/editor-prosemirror/view");
27
28
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -45,6 +46,14 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
45
46
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
46
47
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
47
48
  var EDIT_AREA_ID = 'ak-editor-textarea';
49
+ var focusElementOutsideEditor = function focusElementOutsideEditor() {
50
+ // TODO: ED-26841 - This is an awful way of selecting this, would love a
51
+ // better way be that a ref or even an id or data attibute.
52
+ var aiButton = document.querySelector('[data-testid="platform-ai-button"]');
53
+ if (aiButton && aiButton instanceof HTMLElement) {
54
+ aiButton.focus();
55
+ }
56
+ };
48
57
  function ReactEditorView(props) {
49
58
  var _pluginInjectionAPI$c, _media, _linking, _props$render, _props$render2;
50
59
  var preset = props.preset,
@@ -53,7 +62,11 @@ function ReactEditorView(props) {
53
62
  disabled = _props$editorProps.disabled,
54
63
  editorPropFeatureFlags = _props$editorProps.featureFlags,
55
64
  errorReporterHandler = _props$editorProps.errorReporterHandler,
56
- defaultValue = _props$editorProps.defaultValue;
65
+ defaultValue = _props$editorProps.defaultValue,
66
+ shouldFocus = _props$editorProps.shouldFocus,
67
+ __livePage = _props$editorProps.__livePage,
68
+ onEditorCreated = props.onEditorCreated,
69
+ onEditorDestroyed = props.onEditorDestroyed;
57
70
  var _useState = (0, _react.useState)(undefined),
58
71
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
59
72
  editorAPI = _useState2[0],
@@ -185,6 +198,30 @@ function ReactEditorView(props) {
185
198
  selection = options.selectionAtStart ? _state2.Selection.atStart(doc) : _state2.Selection.atEnd(doc);
186
199
  }
187
200
  }
201
+ if ((0, _platformFeatureFlags.fg)('platform_editor_no_cursor_on_live_doc_init')) {
202
+ if (!options.selectionAtStart) {
203
+ // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
204
+ selection = selection ? _state2.Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
205
+ }
206
+
207
+ // When in live mode, unless the document is empty we do not focus the editor and
208
+ // want to avoid placing the cursor inside any nodes which may show selection states
209
+ // or toolbar based on the cursor being inside them. As such we hard set the
210
+ // selection to the very start of the document regardless of whether that is a
211
+ // gapCursor or not.
212
+ // __livePage necessary because editorViewMode still thinks it is in 'edit' mode
213
+ // when this is called
214
+ if (doc && options.selectionAtStart && __livePage) {
215
+ selection = _state2.NodeSelection.create(doc, 0);
216
+ }
217
+ return _state2.EditorState.create({
218
+ schema: schema,
219
+ plugins: plugins,
220
+ doc: doc,
221
+ selection: selection
222
+ });
223
+ }
224
+
188
225
  // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
189
226
  var patchedSelection = selection ? _state2.Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
190
227
  return _state2.EditorState.create({
@@ -193,7 +230,7 @@ function ReactEditorView(props) {
193
230
  doc: doc,
194
231
  selection: patchedSelection
195
232
  });
196
- }, [errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
233
+ }, [__livePage, errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
197
234
  var initialEditorState = (0, _react.useMemo)(function () {
198
235
  return createEditorState({
199
236
  props: props,
@@ -460,15 +497,17 @@ function ReactEditorView(props) {
460
497
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
461
498
  editorView = _useState4[0],
462
499
  setEditorView = _useState4[1];
463
- var onEditorCreated = props.onEditorCreated,
464
- onEditorDestroyed = props.onEditorDestroyed,
465
- shouldFocus = props.editorProps.shouldFocus;
466
500
  (0, _react.useLayoutEffect)(function () {
467
501
  var _editorView$props$edi, _editorView$props;
468
502
  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')) {
469
- focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(editorView);
503
+ var liveDocWithContent = __livePage && !(0, _document.isEmptyDocument)(editorView.state.doc);
504
+ if (liveDocWithContent && (0, _platformFeatureFlags.fg)('platform_editor_no_cursor_on_live_doc_init')) {
505
+ focusElementOutsideEditor();
506
+ } else {
507
+ focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(editorView);
508
+ }
470
509
  }
471
- }, [editorView, shouldFocus]);
510
+ }, [editorView, shouldFocus, __livePage]);
472
511
  var handleEditorViewRef = (0, _react.useCallback)(function (node) {
473
512
  if (!viewRef.current && node) {
474
513
  var view = createEditorView(node);
@@ -493,9 +532,11 @@ function ReactEditorView(props) {
493
532
  setEditorView(view);
494
533
  });
495
534
  } else {
496
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
535
+ var isLivePageWithContent = __livePage && !(0, _document.isEmptyDocument)(view.state.doc) && (0, _platformFeatureFlags.fg)('platform_editor_no_cursor_on_live_doc_init');
536
+ if (!isLivePageWithContent && shouldFocus && view.props.editable && view.props.editable(view.state)) {
497
537
  focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(view);
498
538
  }
539
+
499
540
  // Force React to re-render so consumers get a reference to the editor view
500
541
  setEditorView(view);
501
542
  }
@@ -521,7 +562,7 @@ function ReactEditorView(props) {
521
562
  }
522
563
  viewRef.current = undefined;
523
564
  }
524
- }, [createEditorView, handleAnalyticsEvent, onEditorDestroyed, onEditorCreated, shouldFocus, eventDispatcher]);
565
+ }, [createEditorView, onEditorCreated, eventDispatcher, shouldFocus, __livePage, onEditorDestroyed, handleAnalyticsEvent]);
525
566
  var createEditor = (0, _react.useCallback)(function (assistiveLabel, assistiveDescribedBy) {
526
567
  return /*#__PURE__*/_react.default.createElement("div", {
527
568
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -557,11 +598,12 @@ function ReactEditorView(props) {
557
598
  return !disabled;
558
599
  }
559
600
  });
560
- if (!disabled && shouldFocus) {
601
+ var isLivePageWithContent = __livePage && !(0, _document.isEmptyDocument)(viewRef.current.state.doc) && (0, _platformFeatureFlags.fg)('platform_editor_no_cursor_on_live_doc_init');
602
+ if (!disabled && shouldFocus && !isLivePageWithContent) {
561
603
  focusTimeoutId.current = (0, _handleEditorFocus.handleEditorFocus)(viewRef.current);
562
604
  }
563
605
  }
564
- }, [disabled, shouldFocus, previousDisabledState]);
606
+ }, [disabled, shouldFocus, previousDisabledState, __livePage]);
565
607
  (0, _useFireFullWidthEvent.useFireFullWidthEvent)(nextAppearance, dispatchAnalyticsEvent);
566
608
  var editor = (0, _react.useMemo)(function () {
567
609
  return createEditor(props.editorProps.assistiveLabel, props.editorProps.assistiveDescribedBy);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.sidebarArea = exports.fullPageEditorWrapper = exports.editorContentGutterStyle = exports.editorContentAreaStyle = exports.editorContentAreaHideContainer = exports.contentAreaWrapper = exports.contentAreaHeightNoToolbar = exports.contentArea = exports.ScrollContainer = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _react = require("@emotion/react");
10
11
  var _adfSchema = require("@atlaskit/adf-schema");
11
12
  var _commonStyles = require("@atlaskit/editor-plugins/table/ui/common-styles");
@@ -151,13 +152,11 @@ var editorContentAreaStyle = exports.editorContentAreaStyle = function editorCon
151
152
  var layoutMaxWidth = _ref.layoutMaxWidth,
152
153
  fullWidthMode = _ref.fullWidthMode,
153
154
  isEditorToolbarHidden = _ref.isEditorToolbarHidden;
154
- return [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle(), (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
155
- exposure: true
156
- }) &&
155
+ return [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle()].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.fg)('platform_editor_controls_no_toolbar_space') ? [] : [(0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') &&
157
156
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
158
157
  contentAreaReducedHeaderSpace, isEditorToolbarHidden && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') &&
159
158
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
160
- contentAreaReservedPrimaryToolbarSpace];
159
+ contentAreaReservedPrimaryToolbarSpace]));
161
160
  };
162
161
  var editorContentAreaWithLayoutWith = function editorContentAreaWithLayoutWith(layoutMaxWidth) {
163
162
  return (0, _react.css)({
@@ -33,7 +33,7 @@ var LegacyEditorContext = exports.LegacyEditorContext = /*#__PURE__*/function (_
33
33
  return (0, _createClass2.default)(LegacyEditorContext, [{
34
34
  key: "render",
35
35
  value: function render() {
36
- if ((0, _platformFeatureFlags.fg)('platform_editor_react18_phase2_v2')) {
36
+ if ((0, _platformFeatureFlags.fg)('platform_editor_react18_phase2_v2') || (0, _platformFeatureFlags.fg)('platform_editor_react18_phase2_v2_extended')) {
37
37
  // Ignored via go/ees005
38
38
  // eslint-disable-next-line react/jsx-props-no-spreading
39
39
  return /*#__PURE__*/_react.default.createElement(LegacyEditorContextNew, this.props, this.props.children);
@@ -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 = "205.1.1";
8
+ var version = exports.version = "205.1.3";
@@ -11,7 +11,8 @@ import { EditorPluginInjectionAPI } from '@atlaskit/editor-common/preset';
11
11
  import { processRawValue, processRawValueWithoutValidation } from '@atlaskit/editor-common/process-raw-value';
12
12
  import { ReactEditorViewContext } from '@atlaskit/editor-common/ui-react';
13
13
  import { analyticsEventKey, getAnalyticsEventSeverity } from '@atlaskit/editor-common/utils/analytics';
14
- import { EditorState, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
14
+ import { isEmptyDocument } from '@atlaskit/editor-common/utils/document';
15
+ import { EditorState, NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
15
16
  import { EditorView } from '@atlaskit/editor-prosemirror/view';
16
17
  import { fg } from '@atlaskit/platform-feature-flags';
17
18
  import { useProviders } from '../composable-editor/hooks/useProviders';
@@ -30,6 +31,14 @@ import { handleEditorFocus } from './ReactEditorView/handleEditorFocus';
30
31
  import { useDispatchTransaction } from './ReactEditorView/useDispatchTransaction';
31
32
  import { useFireFullWidthEvent } from './ReactEditorView/useFireFullWidthEvent';
32
33
  const EDIT_AREA_ID = 'ak-editor-textarea';
34
+ const focusElementOutsideEditor = () => {
35
+ // TODO: ED-26841 - This is an awful way of selecting this, would love a
36
+ // better way be that a ref or even an id or data attibute.
37
+ const aiButton = document.querySelector('[data-testid="platform-ai-button"]');
38
+ if (aiButton && aiButton instanceof HTMLElement) {
39
+ aiButton.focus();
40
+ }
41
+ };
33
42
  export function ReactEditorView(props) {
34
43
  var _pluginInjectionAPI$c, _pluginInjectionAPI$c2, _pluginInjectionAPI$c3, _media, _linking, _linking$smartLinks, _props$render, _props$render2;
35
44
  const {
@@ -39,8 +48,12 @@ export function ReactEditorView(props) {
39
48
  disabled,
40
49
  featureFlags: editorPropFeatureFlags,
41
50
  errorReporterHandler,
42
- defaultValue
43
- }
51
+ defaultValue,
52
+ shouldFocus,
53
+ __livePage
54
+ },
55
+ onEditorCreated,
56
+ onEditorDestroyed
44
57
  } = props;
45
58
  const [editorAPI, setEditorAPI] = useState(undefined);
46
59
  const editorRef = useRef(null);
@@ -160,6 +173,30 @@ export function ReactEditorView(props) {
160
173
  selection = options.selectionAtStart ? Selection.atStart(doc) : Selection.atEnd(doc);
161
174
  }
162
175
  }
176
+ if (fg('platform_editor_no_cursor_on_live_doc_init')) {
177
+ if (!options.selectionAtStart) {
178
+ // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
179
+ selection = selection ? Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
180
+ }
181
+
182
+ // When in live mode, unless the document is empty we do not focus the editor and
183
+ // want to avoid placing the cursor inside any nodes which may show selection states
184
+ // or toolbar based on the cursor being inside them. As such we hard set the
185
+ // selection to the very start of the document regardless of whether that is a
186
+ // gapCursor or not.
187
+ // __livePage necessary because editorViewMode still thinks it is in 'edit' mode
188
+ // when this is called
189
+ if (doc && options.selectionAtStart && __livePage) {
190
+ selection = NodeSelection.create(doc, 0);
191
+ }
192
+ return EditorState.create({
193
+ schema,
194
+ plugins: plugins,
195
+ doc,
196
+ selection
197
+ });
198
+ }
199
+
163
200
  // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
164
201
  const patchedSelection = selection ? Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
165
202
  return EditorState.create({
@@ -168,7 +205,7 @@ export function ReactEditorView(props) {
168
205
  doc,
169
206
  selection: patchedSelection
170
207
  });
171
- }, [errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
208
+ }, [__livePage, errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
172
209
  const initialEditorState = useMemo(() => createEditorState({
173
210
  props,
174
211
  doc: defaultValue,
@@ -430,19 +467,17 @@ export function ReactEditorView(props) {
430
467
  return view;
431
468
  }, [getDirectEditorProps, dispatchAnalyticsEvent]);
432
469
  const [editorView, setEditorView] = useState(undefined);
433
- const {
434
- onEditorCreated,
435
- onEditorDestroyed,
436
- editorProps: {
437
- shouldFocus
438
- }
439
- } = props;
440
470
  useLayoutEffect(() => {
441
471
  var _editorView$props$edi, _editorView$props;
442
472
  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')) {
443
- focusTimeoutId.current = handleEditorFocus(editorView);
473
+ const liveDocWithContent = __livePage && !isEmptyDocument(editorView.state.doc);
474
+ if (liveDocWithContent && fg('platform_editor_no_cursor_on_live_doc_init')) {
475
+ focusElementOutsideEditor();
476
+ } else {
477
+ focusTimeoutId.current = handleEditorFocus(editorView);
478
+ }
444
479
  }
445
- }, [editorView, shouldFocus]);
480
+ }, [editorView, shouldFocus, __livePage]);
446
481
  const handleEditorViewRef = useCallback(node => {
447
482
  if (!viewRef.current && node) {
448
483
  const view = createEditorView(node);
@@ -465,9 +500,11 @@ export function ReactEditorView(props) {
465
500
  setEditorView(view);
466
501
  });
467
502
  } else {
468
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
503
+ const isLivePageWithContent = __livePage && !isEmptyDocument(view.state.doc) && fg('platform_editor_no_cursor_on_live_doc_init');
504
+ if (!isLivePageWithContent && shouldFocus && view.props.editable && view.props.editable(view.state)) {
469
505
  focusTimeoutId.current = handleEditorFocus(view);
470
506
  }
507
+
471
508
  // Force React to re-render so consumers get a reference to the editor view
472
509
  setEditorView(view);
473
510
  }
@@ -493,7 +530,7 @@ export function ReactEditorView(props) {
493
530
  }
494
531
  viewRef.current = undefined;
495
532
  }
496
- }, [createEditorView, handleAnalyticsEvent, onEditorDestroyed, onEditorCreated, shouldFocus, eventDispatcher]);
533
+ }, [createEditorView, onEditorCreated, eventDispatcher, shouldFocus, __livePage, onEditorDestroyed, handleAnalyticsEvent]);
497
534
  const createEditor = useCallback((assistiveLabel, assistiveDescribedBy) => {
498
535
  return /*#__PURE__*/React.createElement("div", {
499
536
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -527,11 +564,12 @@ export function ReactEditorView(props) {
527
564
  viewRef.current.setProps({
528
565
  editable: _state => !disabled
529
566
  });
530
- if (!disabled && shouldFocus) {
567
+ const isLivePageWithContent = __livePage && !isEmptyDocument(viewRef.current.state.doc) && fg('platform_editor_no_cursor_on_live_doc_init');
568
+ if (!disabled && shouldFocus && !isLivePageWithContent) {
531
569
  focusTimeoutId.current = handleEditorFocus(viewRef.current);
532
570
  }
533
571
  }
534
- }, [disabled, shouldFocus, previousDisabledState]);
572
+ }, [disabled, shouldFocus, previousDisabledState, __livePage]);
535
573
  useFireFullWidthEvent(nextAppearance, dispatchAnalyticsEvent);
536
574
  const editor = useMemo(() => createEditor(props.editorProps.assistiveLabel, props.editorProps.assistiveDescribedBy),
537
575
  // `createEditor` changes a little too frequently - we don't want to recreate the editor view in this case
@@ -139,13 +139,11 @@ export const editorContentAreaStyle = ({
139
139
  layoutMaxWidth,
140
140
  fullWidthMode,
141
141
  isEditorToolbarHidden
142
- }) => [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle(), editorExperiment('platform_editor_controls', 'variant1', {
143
- exposure: true
144
- }) &&
142
+ }) => [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle(), ...(fg('platform_editor_controls_no_toolbar_space') ? [] : [editorExperiment('platform_editor_controls', 'variant1') &&
145
143
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
146
144
  contentAreaReducedHeaderSpace, isEditorToolbarHidden && editorExperiment('platform_editor_controls', 'variant1') &&
147
145
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
148
- contentAreaReservedPrimaryToolbarSpace];
146
+ contentAreaReservedPrimaryToolbarSpace])];
149
147
  const editorContentAreaWithLayoutWith = layoutMaxWidth => css({
150
148
  // this restricts max width
151
149
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
@@ -13,7 +13,7 @@ export class LegacyEditorContext extends React.Component {
13
13
  super(props);
14
14
  }
15
15
  render() {
16
- if (fg('platform_editor_react18_phase2_v2')) {
16
+ if (fg('platform_editor_react18_phase2_v2') || fg('platform_editor_react18_phase2_v2_extended')) {
17
17
  // Ignored via go/ees005
18
18
  // eslint-disable-next-line react/jsx-props-no-spreading
19
19
  return /*#__PURE__*/React.createElement(LegacyEditorContextNew, this.props, this.props.children);
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "205.1.1";
2
+ export const version = "205.1.3";
@@ -15,7 +15,8 @@ import { EditorPluginInjectionAPI } from '@atlaskit/editor-common/preset';
15
15
  import { processRawValue, processRawValueWithoutValidation } from '@atlaskit/editor-common/process-raw-value';
16
16
  import { ReactEditorViewContext } from '@atlaskit/editor-common/ui-react';
17
17
  import { analyticsEventKey, getAnalyticsEventSeverity } from '@atlaskit/editor-common/utils/analytics';
18
- import { EditorState, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
18
+ import { isEmptyDocument } from '@atlaskit/editor-common/utils/document';
19
+ import { EditorState, NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
19
20
  import { EditorView } from '@atlaskit/editor-prosemirror/view';
20
21
  import { fg } from '@atlaskit/platform-feature-flags';
21
22
  import { useProviders } from '../composable-editor/hooks/useProviders';
@@ -34,6 +35,14 @@ import { handleEditorFocus } from './ReactEditorView/handleEditorFocus';
34
35
  import { useDispatchTransaction } from './ReactEditorView/useDispatchTransaction';
35
36
  import { useFireFullWidthEvent } from './ReactEditorView/useFireFullWidthEvent';
36
37
  var EDIT_AREA_ID = 'ak-editor-textarea';
38
+ var focusElementOutsideEditor = function focusElementOutsideEditor() {
39
+ // TODO: ED-26841 - This is an awful way of selecting this, would love a
40
+ // better way be that a ref or even an id or data attibute.
41
+ var aiButton = document.querySelector('[data-testid="platform-ai-button"]');
42
+ if (aiButton && aiButton instanceof HTMLElement) {
43
+ aiButton.focus();
44
+ }
45
+ };
37
46
  export function ReactEditorView(props) {
38
47
  var _pluginInjectionAPI$c, _media, _linking, _props$render, _props$render2;
39
48
  var preset = props.preset,
@@ -42,7 +51,11 @@ export function ReactEditorView(props) {
42
51
  disabled = _props$editorProps.disabled,
43
52
  editorPropFeatureFlags = _props$editorProps.featureFlags,
44
53
  errorReporterHandler = _props$editorProps.errorReporterHandler,
45
- defaultValue = _props$editorProps.defaultValue;
54
+ defaultValue = _props$editorProps.defaultValue,
55
+ shouldFocus = _props$editorProps.shouldFocus,
56
+ __livePage = _props$editorProps.__livePage,
57
+ onEditorCreated = props.onEditorCreated,
58
+ onEditorDestroyed = props.onEditorDestroyed;
46
59
  var _useState = useState(undefined),
47
60
  _useState2 = _slicedToArray(_useState, 2),
48
61
  editorAPI = _useState2[0],
@@ -174,6 +187,30 @@ export function ReactEditorView(props) {
174
187
  selection = options.selectionAtStart ? Selection.atStart(doc) : Selection.atEnd(doc);
175
188
  }
176
189
  }
190
+ if (fg('platform_editor_no_cursor_on_live_doc_init')) {
191
+ if (!options.selectionAtStart) {
192
+ // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
193
+ selection = selection ? Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
194
+ }
195
+
196
+ // When in live mode, unless the document is empty we do not focus the editor and
197
+ // want to avoid placing the cursor inside any nodes which may show selection states
198
+ // or toolbar based on the cursor being inside them. As such we hard set the
199
+ // selection to the very start of the document regardless of whether that is a
200
+ // gapCursor or not.
201
+ // __livePage necessary because editorViewMode still thinks it is in 'edit' mode
202
+ // when this is called
203
+ if (doc && options.selectionAtStart && __livePage) {
204
+ selection = NodeSelection.create(doc, 0);
205
+ }
206
+ return EditorState.create({
207
+ schema: schema,
208
+ plugins: plugins,
209
+ doc: doc,
210
+ selection: selection
211
+ });
212
+ }
213
+
177
214
  // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
178
215
  var patchedSelection = selection ? Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
179
216
  return EditorState.create({
@@ -182,7 +219,7 @@ export function ReactEditorView(props) {
182
219
  doc: doc,
183
220
  selection: patchedSelection
184
221
  });
185
- }, [errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
222
+ }, [__livePage, errorReporter, featureFlags, props.intl, props.portalProviderAPI, props.nodeViewPortalProviderAPI, props.editorProps, dispatchAnalyticsEvent, eventDispatcher, dispatch]);
186
223
  var initialEditorState = useMemo(function () {
187
224
  return createEditorState({
188
225
  props: props,
@@ -449,15 +486,17 @@ export function ReactEditorView(props) {
449
486
  _useState4 = _slicedToArray(_useState3, 2),
450
487
  editorView = _useState4[0],
451
488
  setEditorView = _useState4[1];
452
- var onEditorCreated = props.onEditorCreated,
453
- onEditorDestroyed = props.onEditorDestroyed,
454
- shouldFocus = props.editorProps.shouldFocus;
455
489
  useLayoutEffect(function () {
456
490
  var _editorView$props$edi, _editorView$props;
457
491
  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')) {
458
- focusTimeoutId.current = handleEditorFocus(editorView);
492
+ var liveDocWithContent = __livePage && !isEmptyDocument(editorView.state.doc);
493
+ if (liveDocWithContent && fg('platform_editor_no_cursor_on_live_doc_init')) {
494
+ focusElementOutsideEditor();
495
+ } else {
496
+ focusTimeoutId.current = handleEditorFocus(editorView);
497
+ }
459
498
  }
460
- }, [editorView, shouldFocus]);
499
+ }, [editorView, shouldFocus, __livePage]);
461
500
  var handleEditorViewRef = useCallback(function (node) {
462
501
  if (!viewRef.current && node) {
463
502
  var view = createEditorView(node);
@@ -482,9 +521,11 @@ export function ReactEditorView(props) {
482
521
  setEditorView(view);
483
522
  });
484
523
  } else {
485
- if (shouldFocus && view.props.editable && view.props.editable(view.state)) {
524
+ var isLivePageWithContent = __livePage && !isEmptyDocument(view.state.doc) && fg('platform_editor_no_cursor_on_live_doc_init');
525
+ if (!isLivePageWithContent && shouldFocus && view.props.editable && view.props.editable(view.state)) {
486
526
  focusTimeoutId.current = handleEditorFocus(view);
487
527
  }
528
+
488
529
  // Force React to re-render so consumers get a reference to the editor view
489
530
  setEditorView(view);
490
531
  }
@@ -510,7 +551,7 @@ export function ReactEditorView(props) {
510
551
  }
511
552
  viewRef.current = undefined;
512
553
  }
513
- }, [createEditorView, handleAnalyticsEvent, onEditorDestroyed, onEditorCreated, shouldFocus, eventDispatcher]);
554
+ }, [createEditorView, onEditorCreated, eventDispatcher, shouldFocus, __livePage, onEditorDestroyed, handleAnalyticsEvent]);
514
555
  var createEditor = useCallback(function (assistiveLabel, assistiveDescribedBy) {
515
556
  return /*#__PURE__*/React.createElement("div", {
516
557
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -546,11 +587,12 @@ export function ReactEditorView(props) {
546
587
  return !disabled;
547
588
  }
548
589
  });
549
- if (!disabled && shouldFocus) {
590
+ var isLivePageWithContent = __livePage && !isEmptyDocument(viewRef.current.state.doc) && fg('platform_editor_no_cursor_on_live_doc_init');
591
+ if (!disabled && shouldFocus && !isLivePageWithContent) {
550
592
  focusTimeoutId.current = handleEditorFocus(viewRef.current);
551
593
  }
552
594
  }
553
- }, [disabled, shouldFocus, previousDisabledState]);
595
+ }, [disabled, shouldFocus, previousDisabledState, __livePage]);
554
596
  useFireFullWidthEvent(nextAppearance, dispatchAnalyticsEvent);
555
597
  var editor = useMemo(function () {
556
598
  return createEditor(props.editorProps.assistiveLabel, props.editorProps.assistiveDescribedBy);
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
3
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
4
  import { css } from '@emotion/react';
4
5
  import { decisionListSelector, taskListSelector } from '@atlaskit/adf-schema';
@@ -144,13 +145,11 @@ export var editorContentAreaStyle = function editorContentAreaStyle(_ref) {
144
145
  var layoutMaxWidth = _ref.layoutMaxWidth,
145
146
  fullWidthMode = _ref.fullWidthMode,
146
147
  isEditorToolbarHidden = _ref.isEditorToolbarHidden;
147
- return [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle(), editorExperiment('platform_editor_controls', 'variant1', {
148
- exposure: true
149
- }) &&
148
+ return [editorContentArea, !fullWidthMode && editorContentAreaWithLayoutWith(layoutMaxWidth), editorContentAreaContainerStyle()].concat(_toConsumableArray(fg('platform_editor_controls_no_toolbar_space') ? [] : [editorExperiment('platform_editor_controls', 'variant1') &&
150
149
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
151
150
  contentAreaReducedHeaderSpace, isEditorToolbarHidden && editorExperiment('platform_editor_controls', 'variant1') &&
152
151
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values
153
- contentAreaReservedPrimaryToolbarSpace];
152
+ contentAreaReservedPrimaryToolbarSpace]));
154
153
  };
155
154
  var editorContentAreaWithLayoutWith = function editorContentAreaWithLayoutWith(layoutMaxWidth) {
156
155
  return css({
@@ -26,7 +26,7 @@ export var LegacyEditorContext = /*#__PURE__*/function (_React$Component) {
26
26
  return _createClass(LegacyEditorContext, [{
27
27
  key: "render",
28
28
  value: function render() {
29
- if (fg('platform_editor_react18_phase2_v2')) {
29
+ if (fg('platform_editor_react18_phase2_v2') || fg('platform_editor_react18_phase2_v2_extended')) {
30
30
  // Ignored via go/ees005
31
31
  // eslint-disable-next-line react/jsx-props-no-spreading
32
32
  return /*#__PURE__*/React.createElement(LegacyEditorContextNew, this.props, this.props.children);
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "205.1.1";
2
+ export var version = "205.1.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "205.1.1",
3
+ "version": "205.1.3",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -46,7 +46,7 @@
46
46
  "@atlaskit/analytics-next-stable-react-context": "1.0.1",
47
47
  "@atlaskit/button": "^23.0.0",
48
48
  "@atlaskit/css": "^0.10.0",
49
- "@atlaskit/editor-common": "^102.16.0",
49
+ "@atlaskit/editor-common": "^102.17.0",
50
50
  "@atlaskit/editor-json-transformer": "^8.24.0",
51
51
  "@atlaskit/editor-performance-metrics": "^2.0.0",
52
52
  "@atlaskit/editor-plugin-quick-insert": "^2.2.0",
@@ -240,6 +240,10 @@
240
240
  "type": "boolean",
241
241
  "referenceOnly": true
242
242
  },
243
+ "platform_editor_react18_phase2_v2_extended": {
244
+ "type": "boolean",
245
+ "referenceOnly": true
246
+ },
243
247
  "platform_editor_vs_code_block_paste": {
244
248
  "type": "boolean",
245
249
  "referenceOnly": true
@@ -532,6 +536,10 @@
532
536
  "type": "boolean",
533
537
  "referenceOnly": true
534
538
  },
539
+ "editor_a11y_remove_redundant_wrap_icon_label": {
540
+ "type": "boolean",
541
+ "referenceOnly": true
542
+ },
535
543
  "platform_editor_tables_numbered_column_correction": {
536
544
  "type": "boolean",
537
545
  "referenceOnly": true
@@ -550,6 +558,13 @@
550
558
  "type": "boolean",
551
559
  "referenceOnly": true
552
560
  },
561
+ "platform_editor_no_cursor_on_live_doc_init": {
562
+ "type": "boolean"
563
+ },
564
+ "platform_editor_controls_no_toolbar_space": {
565
+ "type": "boolean",
566
+ "referenceOnly": true
567
+ },
553
568
  "platform_editor_collab_text_selection_override": {
554
569
  "type": "boolean",
555
570
  "referenceOnly": true
@@ -574,10 +589,6 @@
574
589
  "type": "boolean",
575
590
  "referenceOnly": true
576
591
  },
577
- "platform_editor_dnd_handle_highlight_fix_firefox": {
578
- "type": "boolean",
579
- "referenceOnly": true
580
- },
581
592
  "platform_editor_elements_dnd_multi_select_patch_3": {
582
593
  "type": "boolean",
583
594
  "referenceOnly": true