@atlaskit/editor-plugin-block-controls 13.1.3 → 13.1.5

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,19 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 13.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 13.1.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [`283c55290e6cc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/283c55290e6cc) -
14
+ Preserve visual selection after applying text color or highlight
15
+ - Updated dependencies
16
+
3
17
  ## 13.1.3
4
18
 
5
19
  ### Patch Changes
@@ -10,6 +10,7 @@ var _bindEventListener = require("bind-event-listener");
10
10
  var _browserApis = require("@atlaskit/browser-apis");
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
12
  var _styles = require("@atlaskit/editor-common/styles");
13
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
13
14
  var _main = require("../main");
14
15
  var _selection = require("../utils/selection");
15
16
  var _editorCommands = require("./editor-commands");
@@ -53,19 +54,37 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
53
54
  key: _pluginKey.selectionPreservationPluginKey,
54
55
  state: {
55
56
  init: function init() {
56
- return {
57
- preservedSelection: undefined
58
- };
57
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
58
+ return {
59
+ preservedSelection: undefined,
60
+ syncDomSelectionForDoc: undefined
61
+ };
62
+ } else {
63
+ return {
64
+ preservedSelection: undefined
65
+ };
66
+ }
59
67
  },
60
68
  apply: function apply(tr, pluginState) {
61
69
  var meta = (0, _utils.getSelectionPreservationMeta)(tr);
62
70
  var newState = _objectSpread({}, pluginState);
63
71
  if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'startPreserving') {
64
72
  newState.preservedSelection = (0, _selection.createPreservedSelection)(tr.doc.resolve(tr.selection.from), tr.doc.resolve(tr.selection.to));
73
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
74
+ newState.syncDomSelectionForDoc = undefined;
75
+ }
65
76
  } else if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'stopPreserving') {
66
77
  newState.preservedSelection = undefined;
67
- } else if (newState.preservedSelection && tr.docChanged) {
68
- newState.preservedSelection = (0, _selection.mapPreservedSelection)(newState.preservedSelection, tr);
78
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
79
+ newState.syncDomSelectionForDoc = undefined;
80
+ }
81
+ } else if (tr.docChanged) {
82
+ if (newState.preservedSelection) {
83
+ newState.preservedSelection = (0, _selection.mapPreservedSelection)(newState.preservedSelection, tr);
84
+ }
85
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
86
+ newState.syncDomSelectionForDoc = (0, _utils.hasFormatSelectionSyncMeta)(tr) ? tr.doc : undefined;
87
+ }
69
88
  }
70
89
  if (!(0, _utils.compareSelections)(newState.preservedSelection, pluginState.preservedSelection)) {
71
90
  if (newState.preservedSelection) {
@@ -111,6 +130,7 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
111
130
  view: function view(initialView) {
112
131
  var view = initialView;
113
132
  var doc = (0, _browserApis.getDocument)();
133
+ var pendingFormatSelectionSyncFrame;
114
134
  if (!doc) {
115
135
  return {
116
136
  update: function update() {},
@@ -158,10 +178,11 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
158
178
  });
159
179
  return {
160
180
  update: function update(updateView, prevState) {
161
- var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
181
+ var _selectionPreservatio, _key$getState, _key$getState2;
162
182
  view = updateView;
163
183
  var prevPreservedSelection = (_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
164
- var currPreservedSelection = (_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
184
+ var currPluginState = _pluginKey.selectionPreservationPluginKey.getState(view.state);
185
+ var currPreservedSelection = currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.preservedSelection;
165
186
  var prevActiveNode = (_key$getState = _main.key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
166
187
  var currActiveNode = (_key$getState2 = _main.key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
167
188
 
@@ -172,12 +193,33 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
172
193
  var preservedSelectionChanged = !(0, _utils.compareSelections)(prevPreservedSelection, currPreservedSelection);
173
194
  var activeNodeChanged = prevActiveNode !== currActiveNode;
174
195
  var docChanged = prevState.doc !== view.state.doc;
175
- var shouldSyncDOMSelection = hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) && docChanged;
196
+ var hasFormatSyncRequestForCurrentDoc = (currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.syncDomSelectionForDoc) === view.state.doc;
197
+ var shouldSyncDOMSelection = (hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) || (0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true) && hasFormatSyncRequestForCurrentDoc) && docChanged;
176
198
  if (shouldSyncDOMSelection) {
177
- (0, _utils.syncDOMSelection)(view.state.selection, view);
199
+ var syncSelection = view.state.selection;
200
+ if ((0, _expValEquals.expValEquals)('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
201
+ if (hasFormatSyncRequestForCurrentDoc) {
202
+ if (pendingFormatSelectionSyncFrame !== undefined) {
203
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
204
+ }
205
+ pendingFormatSelectionSyncFrame = requestAnimationFrame(function () {
206
+ pendingFormatSelectionSyncFrame = undefined;
207
+ (0, _utils.syncDOMSelection)(syncSelection, view, {
208
+ focusEditor: true
209
+ });
210
+ });
211
+ } else {
212
+ (0, _utils.syncDOMSelection)(syncSelection, view);
213
+ }
214
+ } else {
215
+ (0, _utils.syncDOMSelection)(syncSelection, view);
216
+ }
178
217
  }
179
218
  },
180
219
  destroy: function destroy() {
220
+ if (pendingFormatSelectionSyncFrame !== undefined) {
221
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
222
+ }
181
223
  unbindDocumentMouseDown();
182
224
  }
183
225
  };
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.syncDOMSelection = exports.hasUserSelectionChange = exports.getSelectionPreservationMeta = exports.compareSelections = void 0;
6
+ exports.syncDOMSelection = exports.hasUserSelectionChange = exports.hasFormatSelectionSyncMeta = exports.getSelectionPreservationMeta = exports.compareSelections = void 0;
7
7
  var _browserApis = require("@atlaskit/browser-apis");
8
+ var _selection = require("@atlaskit/editor-common/selection");
8
9
  var _pluginKey = require("./plugin-key");
9
10
  /**
10
11
  * Detects if any of the transactions include user-driven selection changes.
@@ -20,6 +21,9 @@ var hasUserSelectionChange = exports.hasUserSelectionChange = function hasUserSe
20
21
  var getSelectionPreservationMeta = exports.getSelectionPreservationMeta = function getSelectionPreservationMeta(tr) {
21
22
  return tr.getMeta(_pluginKey.selectionPreservationPluginKey);
22
23
  };
24
+ var hasFormatSelectionSyncMeta = exports.hasFormatSelectionSyncMeta = function hasFormatSelectionSyncMeta(tr) {
25
+ return tr.getMeta(_selection.FORMAT_SELECTION_SYNC_META) === true;
26
+ };
23
27
 
24
28
  /**
25
29
  * Compares two selections for equality based on their from and to positions.
@@ -42,8 +46,13 @@ var compareSelections = exports.compareSelections = function compareSelections(a
42
46
  * @param selection The current ProseMirror selection state to sync to DOM.
43
47
  * @param view The EditorView instance used to convert ProseMirror positions to DOM positions.
44
48
  */
45
- var syncDOMSelection = exports.syncDOMSelection = function syncDOMSelection(selection, view) {
49
+ var syncDOMSelection = exports.syncDOMSelection = function syncDOMSelection(selection, view, options) {
46
50
  try {
51
+ if (options !== null && options !== void 0 && options.focusEditor && !view.hasFocus()) {
52
+ // The native browser selection is only painted while the editor owns focus.
53
+ // Formatting toolbar interactions can move focus away before we restore the range.
54
+ view.focus();
55
+ }
47
56
  var domSelection = window.getSelection();
48
57
  if (!domSelection) {
49
58
  return;
@@ -2,11 +2,12 @@ import { bind } from 'bind-event-listener';
2
2
  import { getDocument } from '@atlaskit/browser-apis';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { DRAG_HANDLE_SELECTOR } from '@atlaskit/editor-common/styles';
5
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
6
  import { key } from '../main';
6
7
  import { createPreservedSelection, mapPreservedSelection } from '../utils/selection';
7
8
  import { stopPreservingSelection } from './editor-commands';
8
9
  import { selectionPreservationPluginKey } from './plugin-key';
9
- import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange, syncDOMSelection } from './utils';
10
+ import { compareSelections, getSelectionPreservationMeta, hasFormatSelectionSyncMeta, hasUserSelectionChange, syncDOMSelection } from './utils';
10
11
 
11
12
  /**
12
13
  * Selection Preservation Plugin
@@ -43,9 +44,16 @@ export const createSelectionPreservationPlugin = api => () => {
43
44
  key: selectionPreservationPluginKey,
44
45
  state: {
45
46
  init() {
46
- return {
47
- preservedSelection: undefined
48
- };
47
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
48
+ return {
49
+ preservedSelection: undefined,
50
+ syncDomSelectionForDoc: undefined
51
+ };
52
+ } else {
53
+ return {
54
+ preservedSelection: undefined
55
+ };
56
+ }
49
57
  },
50
58
  apply(tr, pluginState) {
51
59
  const meta = getSelectionPreservationMeta(tr);
@@ -54,10 +62,21 @@ export const createSelectionPreservationPlugin = api => () => {
54
62
  };
55
63
  if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'startPreserving') {
56
64
  newState.preservedSelection = createPreservedSelection(tr.doc.resolve(tr.selection.from), tr.doc.resolve(tr.selection.to));
65
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
66
+ newState.syncDomSelectionForDoc = undefined;
67
+ }
57
68
  } else if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'stopPreserving') {
58
69
  newState.preservedSelection = undefined;
59
- } else if (newState.preservedSelection && tr.docChanged) {
60
- newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
70
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
71
+ newState.syncDomSelectionForDoc = undefined;
72
+ }
73
+ } else if (tr.docChanged) {
74
+ if (newState.preservedSelection) {
75
+ newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
76
+ }
77
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
78
+ newState.syncDomSelectionForDoc = hasFormatSelectionSyncMeta(tr) ? tr.doc : undefined;
79
+ }
61
80
  }
62
81
  if (!compareSelections(newState.preservedSelection, pluginState.preservedSelection)) {
63
82
  if (newState.preservedSelection) {
@@ -103,6 +122,7 @@ export const createSelectionPreservationPlugin = api => () => {
103
122
  view(initialView) {
104
123
  let view = initialView;
105
124
  const doc = getDocument();
125
+ let pendingFormatSelectionSyncFrame;
106
126
  if (!doc) {
107
127
  return {
108
128
  update() {},
@@ -151,10 +171,11 @@ export const createSelectionPreservationPlugin = api => () => {
151
171
  });
152
172
  return {
153
173
  update(updateView, prevState) {
154
- var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
174
+ var _selectionPreservatio, _key$getState, _key$getState2;
155
175
  view = updateView;
156
176
  const prevPreservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
157
- const currPreservedSelection = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
177
+ const currPluginState = selectionPreservationPluginKey.getState(view.state);
178
+ const currPreservedSelection = currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.preservedSelection;
158
179
  const prevActiveNode = (_key$getState = key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
159
180
  const currActiveNode = (_key$getState2 = key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
160
181
 
@@ -165,12 +186,33 @@ export const createSelectionPreservationPlugin = api => () => {
165
186
  const preservedSelectionChanged = !compareSelections(prevPreservedSelection, currPreservedSelection);
166
187
  const activeNodeChanged = prevActiveNode !== currActiveNode;
167
188
  const docChanged = prevState.doc !== view.state.doc;
168
- const shouldSyncDOMSelection = hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) && docChanged;
189
+ const hasFormatSyncRequestForCurrentDoc = (currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.syncDomSelectionForDoc) === view.state.doc;
190
+ const shouldSyncDOMSelection = (hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) || expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true) && hasFormatSyncRequestForCurrentDoc) && docChanged;
169
191
  if (shouldSyncDOMSelection) {
170
- syncDOMSelection(view.state.selection, view);
192
+ const syncSelection = view.state.selection;
193
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
194
+ if (hasFormatSyncRequestForCurrentDoc) {
195
+ if (pendingFormatSelectionSyncFrame !== undefined) {
196
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
197
+ }
198
+ pendingFormatSelectionSyncFrame = requestAnimationFrame(() => {
199
+ pendingFormatSelectionSyncFrame = undefined;
200
+ syncDOMSelection(syncSelection, view, {
201
+ focusEditor: true
202
+ });
203
+ });
204
+ } else {
205
+ syncDOMSelection(syncSelection, view);
206
+ }
207
+ } else {
208
+ syncDOMSelection(syncSelection, view);
209
+ }
171
210
  }
172
211
  },
173
212
  destroy() {
213
+ if (pendingFormatSelectionSyncFrame !== undefined) {
214
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
215
+ }
174
216
  unbindDocumentMouseDown();
175
217
  }
176
218
  };
@@ -1,4 +1,5 @@
1
1
  import { getDocument } from '@atlaskit/browser-apis';
2
+ import { FORMAT_SELECTION_SYNC_META } from '@atlaskit/editor-common/selection';
2
3
  import { selectionPreservationPluginKey } from './plugin-key';
3
4
  /**
4
5
  * Detects if any of the transactions include user-driven selection changes.
@@ -12,6 +13,7 @@ export const hasUserSelectionChange = transactions => {
12
13
  export const getSelectionPreservationMeta = tr => {
13
14
  return tr.getMeta(selectionPreservationPluginKey);
14
15
  };
16
+ export const hasFormatSelectionSyncMeta = tr => tr.getMeta(FORMAT_SELECTION_SYNC_META) === true;
15
17
 
16
18
  /**
17
19
  * Compares two selections for equality based on their from and to positions.
@@ -34,8 +36,13 @@ export const compareSelections = (a, b) => {
34
36
  * @param selection The current ProseMirror selection state to sync to DOM.
35
37
  * @param view The EditorView instance used to convert ProseMirror positions to DOM positions.
36
38
  */
37
- export const syncDOMSelection = (selection, view) => {
39
+ export const syncDOMSelection = (selection, view, options) => {
38
40
  try {
41
+ if (options !== null && options !== void 0 && options.focusEditor && !view.hasFocus()) {
42
+ // The native browser selection is only painted while the editor owns focus.
43
+ // Formatting toolbar interactions can move focus away before we restore the range.
44
+ view.focus();
45
+ }
39
46
  const domSelection = window.getSelection();
40
47
  if (!domSelection) {
41
48
  return;
@@ -5,11 +5,12 @@ import { bind } from 'bind-event-listener';
5
5
  import { getDocument } from '@atlaskit/browser-apis';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { DRAG_HANDLE_SELECTOR } from '@atlaskit/editor-common/styles';
8
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
9
  import { key } from '../main';
9
10
  import { createPreservedSelection, mapPreservedSelection } from '../utils/selection';
10
11
  import { stopPreservingSelection } from './editor-commands';
11
12
  import { selectionPreservationPluginKey } from './plugin-key';
12
- import { compareSelections, getSelectionPreservationMeta, hasUserSelectionChange, syncDOMSelection } from './utils';
13
+ import { compareSelections, getSelectionPreservationMeta, hasFormatSelectionSyncMeta, hasUserSelectionChange, syncDOMSelection } from './utils';
13
14
 
14
15
  /**
15
16
  * Selection Preservation Plugin
@@ -47,19 +48,37 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
47
48
  key: selectionPreservationPluginKey,
48
49
  state: {
49
50
  init: function init() {
50
- return {
51
- preservedSelection: undefined
52
- };
51
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
52
+ return {
53
+ preservedSelection: undefined,
54
+ syncDomSelectionForDoc: undefined
55
+ };
56
+ } else {
57
+ return {
58
+ preservedSelection: undefined
59
+ };
60
+ }
53
61
  },
54
62
  apply: function apply(tr, pluginState) {
55
63
  var meta = getSelectionPreservationMeta(tr);
56
64
  var newState = _objectSpread({}, pluginState);
57
65
  if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'startPreserving') {
58
66
  newState.preservedSelection = createPreservedSelection(tr.doc.resolve(tr.selection.from), tr.doc.resolve(tr.selection.to));
67
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
68
+ newState.syncDomSelectionForDoc = undefined;
69
+ }
59
70
  } else if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'stopPreserving') {
60
71
  newState.preservedSelection = undefined;
61
- } else if (newState.preservedSelection && tr.docChanged) {
62
- newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
72
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
73
+ newState.syncDomSelectionForDoc = undefined;
74
+ }
75
+ } else if (tr.docChanged) {
76
+ if (newState.preservedSelection) {
77
+ newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
78
+ }
79
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
80
+ newState.syncDomSelectionForDoc = hasFormatSelectionSyncMeta(tr) ? tr.doc : undefined;
81
+ }
63
82
  }
64
83
  if (!compareSelections(newState.preservedSelection, pluginState.preservedSelection)) {
65
84
  if (newState.preservedSelection) {
@@ -105,6 +124,7 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
105
124
  view: function view(initialView) {
106
125
  var view = initialView;
107
126
  var doc = getDocument();
127
+ var pendingFormatSelectionSyncFrame;
108
128
  if (!doc) {
109
129
  return {
110
130
  update: function update() {},
@@ -152,10 +172,11 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
152
172
  });
153
173
  return {
154
174
  update: function update(updateView, prevState) {
155
- var _selectionPreservatio, _selectionPreservatio2, _key$getState, _key$getState2;
175
+ var _selectionPreservatio, _key$getState, _key$getState2;
156
176
  view = updateView;
157
177
  var prevPreservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(prevState)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
158
- var currPreservedSelection = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection;
178
+ var currPluginState = selectionPreservationPluginKey.getState(view.state);
179
+ var currPreservedSelection = currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.preservedSelection;
159
180
  var prevActiveNode = (_key$getState = key.getState(prevState)) === null || _key$getState === void 0 ? void 0 : _key$getState.activeNode;
160
181
  var currActiveNode = (_key$getState2 = key.getState(view.state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.activeNode;
161
182
 
@@ -166,12 +187,33 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
166
187
  var preservedSelectionChanged = !compareSelections(prevPreservedSelection, currPreservedSelection);
167
188
  var activeNodeChanged = prevActiveNode !== currActiveNode;
168
189
  var docChanged = prevState.doc !== view.state.doc;
169
- var shouldSyncDOMSelection = hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) && docChanged;
190
+ var hasFormatSyncRequestForCurrentDoc = (currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.syncDomSelectionForDoc) === view.state.doc;
191
+ var shouldSyncDOMSelection = (hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) || expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true) && hasFormatSyncRequestForCurrentDoc) && docChanged;
170
192
  if (shouldSyncDOMSelection) {
171
- syncDOMSelection(view.state.selection, view);
193
+ var syncSelection = view.state.selection;
194
+ if (expValEquals('platform_editor_fix_selection_text_color_change', 'isEnabled', true)) {
195
+ if (hasFormatSyncRequestForCurrentDoc) {
196
+ if (pendingFormatSelectionSyncFrame !== undefined) {
197
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
198
+ }
199
+ pendingFormatSelectionSyncFrame = requestAnimationFrame(function () {
200
+ pendingFormatSelectionSyncFrame = undefined;
201
+ syncDOMSelection(syncSelection, view, {
202
+ focusEditor: true
203
+ });
204
+ });
205
+ } else {
206
+ syncDOMSelection(syncSelection, view);
207
+ }
208
+ } else {
209
+ syncDOMSelection(syncSelection, view);
210
+ }
172
211
  }
173
212
  },
174
213
  destroy: function destroy() {
214
+ if (pendingFormatSelectionSyncFrame !== undefined) {
215
+ cancelAnimationFrame(pendingFormatSelectionSyncFrame);
216
+ }
175
217
  unbindDocumentMouseDown();
176
218
  }
177
219
  };
@@ -1,4 +1,5 @@
1
1
  import { getDocument } from '@atlaskit/browser-apis';
2
+ import { FORMAT_SELECTION_SYNC_META } from '@atlaskit/editor-common/selection';
2
3
  import { selectionPreservationPluginKey } from './plugin-key';
3
4
  /**
4
5
  * Detects if any of the transactions include user-driven selection changes.
@@ -14,6 +15,9 @@ export var hasUserSelectionChange = function hasUserSelectionChange(transactions
14
15
  export var getSelectionPreservationMeta = function getSelectionPreservationMeta(tr) {
15
16
  return tr.getMeta(selectionPreservationPluginKey);
16
17
  };
18
+ export var hasFormatSelectionSyncMeta = function hasFormatSelectionSyncMeta(tr) {
19
+ return tr.getMeta(FORMAT_SELECTION_SYNC_META) === true;
20
+ };
17
21
 
18
22
  /**
19
23
  * Compares two selections for equality based on their from and to positions.
@@ -36,8 +40,13 @@ export var compareSelections = function compareSelections(a, b) {
36
40
  * @param selection The current ProseMirror selection state to sync to DOM.
37
41
  * @param view The EditorView instance used to convert ProseMirror positions to DOM positions.
38
42
  */
39
- export var syncDOMSelection = function syncDOMSelection(selection, view) {
43
+ export var syncDOMSelection = function syncDOMSelection(selection, view, options) {
40
44
  try {
45
+ if (options !== null && options !== void 0 && options.focusEditor && !view.hasFocus()) {
46
+ // The native browser selection is only painted while the editor owns focus.
47
+ // Formatting toolbar interactions can move focus away before we restore the range.
48
+ view.focus();
49
+ }
41
50
  var domSelection = window.getSelection();
42
51
  if (!domSelection) {
43
52
  return;
@@ -1,6 +1,8 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
2
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
3
  export type SelectionPreservationPluginState = {
3
4
  preservedSelection?: Selection;
5
+ syncDomSelectionForDoc?: PMNode;
4
6
  };
5
7
  export type SelectionPreservationMeta = {
6
8
  type: 'startPreserving' | 'stopPreserving';
@@ -9,6 +9,7 @@ import type { SelectionPreservationMeta } from './types';
9
9
  */
10
10
  export declare const hasUserSelectionChange: (transactions: readonly Transaction[]) => boolean;
11
11
  export declare const getSelectionPreservationMeta: (tr: Transaction | ReadonlyTransaction) => SelectionPreservationMeta | undefined;
12
+ export declare const hasFormatSelectionSyncMeta: (tr: Transaction | ReadonlyTransaction) => boolean;
12
13
  /**
13
14
  * Compares two selections for equality based on their from and to positions.
14
15
  *
@@ -27,4 +28,6 @@ export declare const compareSelections: (a?: Selection, b?: Selection) => boolea
27
28
  * @param selection The current ProseMirror selection state to sync to DOM.
28
29
  * @param view The EditorView instance used to convert ProseMirror positions to DOM positions.
29
30
  */
30
- export declare const syncDOMSelection: (selection: Selection, view: EditorView) => void;
31
+ export declare const syncDOMSelection: (selection: Selection, view: EditorView, options?: {
32
+ focusEditor?: boolean;
33
+ }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "13.1.3",
3
+ "version": "13.1.5",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -20,8 +20,8 @@
20
20
  ],
21
21
  "atlaskit:src": "src/index.ts",
22
22
  "dependencies": {
23
- "@atlaskit/browser-apis": "^1.0.0",
24
- "@atlaskit/button": "^24.1.0",
23
+ "@atlaskit/browser-apis": "^1.1.0",
24
+ "@atlaskit/button": "^24.3.0",
25
25
  "@atlaskit/editor-plugin-accessibility-utils": "^12.0.0",
26
26
  "@atlaskit/editor-plugin-analytics": "^12.0.0",
27
27
  "@atlaskit/editor-plugin-editor-disabled": "^12.0.0",
@@ -39,18 +39,18 @@
39
39
  "@atlaskit/editor-prosemirror": "^8.0.0",
40
40
  "@atlaskit/editor-shared-styles": "^4.0.0",
41
41
  "@atlaskit/editor-tables": "^3.0.0",
42
- "@atlaskit/icon": "^36.0.0",
43
- "@atlaskit/icon-lab": "^7.1.0",
44
- "@atlaskit/link": "^4.0.0",
42
+ "@atlaskit/icon": "^36.1.0",
43
+ "@atlaskit/icon-lab": "^7.2.0",
44
+ "@atlaskit/link": "^4.1.0",
45
45
  "@atlaskit/platform-feature-flags": "^2.0.0",
46
46
  "@atlaskit/pragmatic-drag-and-drop": "^2.0.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^3.0.0",
48
- "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^4.0.0",
49
- "@atlaskit/primitives": "^20.0.0",
50
- "@atlaskit/theme": "^26.0.0",
51
- "@atlaskit/tmp-editor-statsig": "^114.0.0",
52
- "@atlaskit/tokens": "^15.0.0",
53
- "@atlaskit/tooltip": "^23.0.0",
48
+ "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^4.1.0",
49
+ "@atlaskit/primitives": "^20.2.0",
50
+ "@atlaskit/theme": "^26.1.0",
51
+ "@atlaskit/tmp-editor-statsig": "^115.0.0",
52
+ "@atlaskit/tokens": "^15.2.0",
53
+ "@atlaskit/tooltip": "^23.1.0",
54
54
  "@babel/runtime": "^7.0.0",
55
55
  "@emotion/react": "^11.7.1",
56
56
  "bind-event-listener": "^3.0.0",
@@ -59,7 +59,7 @@
59
59
  "uuid": "^3.1.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@atlaskit/editor-common": "^116.13.0",
62
+ "@atlaskit/editor-common": "^116.17.0",
63
63
  "react": "^18.2.0",
64
64
  "react-dom": "^18.2.0",
65
65
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"