@atlaskit/editor-plugin-toolbar 4.0.2 → 4.0.4

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,23 @@
1
1
  # @atlaskit/editor-plugin-toolbar
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ba05557f777bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ba05557f777bf) -
8
+ Add support to render selection toolbar in editors which have an ancestor elemenent which has
9
+ position fixed, most common use case is for the chromeless appearance when rendered inside modals,
10
+ popups etc.
11
+ - Updated dependencies
12
+
13
+ ## 4.0.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [`1265c260f9bad`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1265c260f9bad) -
18
+ [ED-29455] clean up experiment platform_editor_toolbar_migrate_loom
19
+ - Updated dependencies
20
+
3
21
  ## 4.0.2
4
22
 
5
23
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../../../tsconfig.entry-points.confluence.json",
2
+ "extends": "../../../../tsconfig.local-consumption.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-toolbar",
@@ -10,8 +10,9 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
  var _bindEventListener = require("bind-event-listener");
12
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
+ var _utils = require("@atlaskit/editor-common/utils");
13
14
  var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _utils = require("@atlaskit/editor-prosemirror/utils");
15
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
16
  var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
16
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
18
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
@@ -36,7 +37,7 @@ function getSelectedNode(editorState) {
36
37
  };
37
38
  }
38
39
  var nodes = editorState.schema.nodes;
39
- var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock])(selection);
40
+ var selectedNode = (0, _utils2.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock])(selection);
40
41
  if (selectedNode) {
41
42
  return {
42
43
  node: selectedNode.node,
@@ -47,7 +48,7 @@ function getSelectedNode(editorState) {
47
48
  })
48
49
  };
49
50
  }
50
- var parentNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.listItem, nodes.taskItem])(selection);
51
+ var parentNode = (0, _utils2.findParentNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.listItem, nodes.taskItem])(selection);
51
52
  if (parentNode) {
52
53
  return {
53
54
  node: parentNode.node,
@@ -83,6 +84,7 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
83
84
  breakpointPreset = config.breakpointPreset;
84
85
  var registry = (0, _editorToolbarModel.createComponentRegistry)();
85
86
  registry.register((0, _toolbarComponents.getToolbarComponents)(contextualFormattingEnabled, api, disableSelectionToolbar, breakpointPreset));
87
+ var cachedCalculateToolbarPosition = (0, _expValEquals.expValEquals)('platform_editor_sel_toolbar_fix', 'isEnabled', true) ? (0, _utils.calculateToolbarPositionTrackHead)(_consts.SELECTION_TOOLBAR_LABEL) : undefined;
86
88
  return {
87
89
  name: 'toolbar',
88
90
  actions: {
@@ -209,19 +211,12 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
209
211
  if (!editorView) {
210
212
  return null;
211
213
  }
212
- if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_patch_7')) {
213
- return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbarWithErrorBoundary, {
214
- api: api,
215
- editorView: editorView,
216
- mountPoint: popupsMountPoint,
217
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
218
- });
219
- }
220
- return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbar, {
214
+ return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbarWithErrorBoundary, {
221
215
  api: api,
222
216
  editorView: editorView,
223
217
  mountPoint: popupsMountPoint,
224
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
218
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false,
219
+ calculateToolbarPosition: cachedCalculateToolbarPosition
225
220
  });
226
221
  } : undefined
227
222
  };
@@ -70,42 +70,25 @@ var usePluginState = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(fun
70
70
  selectedNode: selectedNode
71
71
  };
72
72
  });
73
- var useOnPositionCalculated = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(function () {
74
- return (0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_patch_7');
75
- }, function (editorView) {
73
+ var useOnPositionCalculated = function useOnPositionCalculated(editorView, cachedCalculateToolbarPosition) {
76
74
  var onPositionCalculated = (0, _react.useCallback)(function (position) {
77
75
  try {
78
- var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
79
-
80
76
  // Show special position on cell selection only when editor controls experiment is enabled
81
77
  var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
82
78
  var isCellSelection = ('$anchorCell' in editorView.state.selection);
83
79
  if (isCellSelection && isEditorControlsEnabled) {
84
- return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
80
+ return (0, _utils.calculateToolbarPositionOnCellSelection)(_consts.SELECTION_TOOLBAR_LABEL)(editorView, position);
85
81
  }
86
- return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
82
+ return cachedCalculateToolbarPosition ? cachedCalculateToolbarPosition(editorView, position) : (0, _utils.calculateToolbarPositionTrackHead)(_consts.SELECTION_TOOLBAR_LABEL)(editorView, position);
87
83
  } catch (error) {
88
84
  (0, _monitoring.logException)(error, {
89
85
  location: 'editor-plugin-toolbar/selectionToolbar'
90
86
  });
91
87
  return position;
92
88
  }
93
- }, [editorView]);
89
+ }, [editorView, cachedCalculateToolbarPosition]);
94
90
  return onPositionCalculated;
95
- }, function (editorView) {
96
- var onPositionCalculated = (0, _react.useCallback)(function (position) {
97
- var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
98
-
99
- // Show special position on cell selection only when editor controls experiment is enabled
100
- var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
101
- var isCellSelection = ('$anchorCell' in editorView.state.selection);
102
- if (isCellSelection && isEditorControlsEnabled) {
103
- return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
104
- }
105
- return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
106
- }, [editorView]);
107
- return onPositionCalculated;
108
- });
91
+ };
109
92
  var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
110
93
  var _api$toolbar$actions$, _api$toolbar, _api$toolbar2;
111
94
  var api = _ref.api,
@@ -118,7 +101,7 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
118
101
  currentUserIntent = _usePluginState.currentUserIntent,
119
102
  shouldShowToolbar = _usePluginState.shouldShowToolbar,
120
103
  editorViewMode = _usePluginState.editorViewMode,
121
- selection = _usePluginState.selection;
104
+ _selection = _usePluginState.selection;
122
105
  var contextualFormattingEnabled = (_api$toolbar$actions$ = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.contextualFormattingMode()) !== null && _api$toolbar$actions$ !== void 0 ? _api$toolbar$actions$ : 'always-pinned';
123
106
  var selectionToolbarConfigEnabled = (0, _toolbar.shouldShowSelectionToolbar)(contextualFormattingEnabled, editorToolbarDockingPreference);
124
107
  var intl = (0, _reactIntlNext.useIntl)();
@@ -178,7 +161,8 @@ var SelectionToolbarWithErrorBoundary = exports.SelectionToolbarWithErrorBoundar
178
161
  var api = _ref2.api,
179
162
  editorView = _ref2.editorView,
180
163
  mountPoint = _ref2.mountPoint,
181
- disableSelectionToolbarWhenPinned = _ref2.disableSelectionToolbarWhenPinned;
164
+ disableSelectionToolbarWhenPinned = _ref2.disableSelectionToolbarWhenPinned,
165
+ calculateToolbarPosition = _ref2.calculateToolbarPosition;
182
166
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
183
167
  component: _analytics.ACTION_SUBJECT.TOOLBAR,
184
168
  componentId: _analytics.ACTION_SUBJECT_ID.SELECTION_TOOLBAR,
@@ -188,6 +172,7 @@ var SelectionToolbarWithErrorBoundary = exports.SelectionToolbarWithErrorBoundar
188
172
  api: api,
189
173
  editorView: editorView,
190
174
  mountPoint: mountPoint,
191
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned
175
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned,
176
+ calculateToolbarPosition: calculateToolbarPosition
192
177
  }));
193
178
  };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -246,41 +246,39 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
246
246
  }, children);
247
247
  } : undefined
248
248
  }]);
249
- if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_migrate_loom', 'isEnabled', true)) {
250
- components.push({
249
+ components.push({
250
+ type: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
251
+ key: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
252
+ parents: [{
253
+ type: 'toolbar',
254
+ key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
255
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
256
+ }],
257
+ component: function component(_ref1) {
258
+ var children = _ref1.children;
259
+ return /*#__PURE__*/_react.default.createElement(_OverflowSection.OverflowSection, null, children);
260
+ }
261
+ }, {
262
+ type: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
263
+ key: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
264
+ parents: [{
251
265
  type: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
252
266
  key: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
253
- parents: [{
254
- type: 'toolbar',
255
- key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
256
- rank: _toolbar.TOOLBAR_RANK[_toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
257
- }],
258
- component: function component(_ref1) {
259
- var children = _ref1.children;
260
- return /*#__PURE__*/_react.default.createElement(_OverflowSection.OverflowSection, null, children);
261
- }
262
- }, {
267
+ rank: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
268
+ }]
269
+ }, {
270
+ type: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
271
+ key: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
272
+ parents: [{
263
273
  type: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
264
274
  key: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
265
- parents: [{
266
- type: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
267
- key: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
268
- rank: _toolbar.OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
269
- }]
270
- }, {
271
- type: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
272
- key: _toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
273
- parents: [{
274
- type: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
275
- key: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
276
- rank: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
277
- }],
278
- component: function component(_ref10) {
279
- var children = _ref10.children;
280
- return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children);
281
- }
282
- });
283
- }
275
+ rank: _toolbar.OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[_toolbar.OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
276
+ }],
277
+ component: function component(_ref10) {
278
+ var children = _ref10.children;
279
+ return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children);
280
+ }
281
+ });
284
282
  if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_placement_config')) {
285
283
  switch (contextualFormattingEnabled) {
286
284
  case 'always-inline':
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { bind } from 'bind-event-listener';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
4
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
6
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
7
  import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
@@ -8,8 +9,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
10
  import { getSelectionToolbarOpenExperiencePlugin } from './pm-plugins/experiences/selection-toolbar-open-experience';
10
11
  import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
11
- import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
12
- import { SelectionToolbar, SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
12
+ import { DEFAULT_POPUP_SELECTORS, SELECTION_TOOLBAR_LABEL } from './ui/consts';
13
+ import { SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
13
14
  import { getToolbarComponents } from './ui/toolbar-components';
14
15
  import { isEventInContainer } from './ui/utils/toolbar';
15
16
  function getSelectedNode(editorState) {
@@ -69,6 +70,7 @@ export const toolbarPlugin = ({
69
70
  } = config;
70
71
  const registry = createComponentRegistry();
71
72
  registry.register(getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar, breakpointPreset));
73
+ const cachedCalculateToolbarPosition = expValEquals('platform_editor_sel_toolbar_fix', 'isEnabled', true) ? calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL) : undefined;
72
74
  return {
73
75
  name: 'toolbar',
74
76
  actions: {
@@ -198,19 +200,12 @@ export const toolbarPlugin = ({
198
200
  if (!editorView) {
199
201
  return null;
200
202
  }
201
- if (fg('platform_editor_toolbar_aifc_patch_7')) {
202
- return /*#__PURE__*/React.createElement(SelectionToolbarWithErrorBoundary, {
203
- api: api,
204
- editorView: editorView,
205
- mountPoint: popupsMountPoint,
206
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
207
- });
208
- }
209
- return /*#__PURE__*/React.createElement(SelectionToolbar, {
203
+ return /*#__PURE__*/React.createElement(SelectionToolbarWithErrorBoundary, {
210
204
  api: api,
211
205
  editorView: editorView,
212
206
  mountPoint: popupsMountPoint,
213
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
207
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false,
208
+ calculateToolbarPosition: cachedCalculateToolbarPosition
214
209
  });
215
210
  } : undefined
216
211
  };
@@ -61,40 +61,25 @@ const usePluginState = conditionalHooksFactory(() => expValEquals('platform_edit
61
61
  selectedNode
62
62
  };
63
63
  });
64
- const useOnPositionCalculated = conditionalHooksFactory(() => fg('platform_editor_toolbar_aifc_patch_7'), editorView => {
64
+ const useOnPositionCalculated = (editorView, cachedCalculateToolbarPosition) => {
65
65
  const onPositionCalculated = useCallback(position => {
66
66
  try {
67
- const toolbarTitle = SELECTION_TOOLBAR_LABEL;
68
-
69
67
  // Show special position on cell selection only when editor controls experiment is enabled
70
68
  const isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
71
69
  const isCellSelection = ('$anchorCell' in editorView.state.selection);
72
70
  if (isCellSelection && isEditorControlsEnabled) {
73
- return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
71
+ return calculateToolbarPositionOnCellSelection(SELECTION_TOOLBAR_LABEL)(editorView, position);
74
72
  }
75
- return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
73
+ return cachedCalculateToolbarPosition ? cachedCalculateToolbarPosition(editorView, position) : calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL)(editorView, position);
76
74
  } catch (error) {
77
75
  logException(error, {
78
76
  location: 'editor-plugin-toolbar/selectionToolbar'
79
77
  });
80
78
  return position;
81
79
  }
82
- }, [editorView]);
80
+ }, [editorView, cachedCalculateToolbarPosition]);
83
81
  return onPositionCalculated;
84
- }, editorView => {
85
- const onPositionCalculated = useCallback(position => {
86
- const toolbarTitle = SELECTION_TOOLBAR_LABEL;
87
-
88
- // Show special position on cell selection only when editor controls experiment is enabled
89
- const isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
90
- const isCellSelection = ('$anchorCell' in editorView.state.selection);
91
- if (isCellSelection && isEditorControlsEnabled) {
92
- return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
93
- }
94
- return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
95
- }, [editorView]);
96
- return onPositionCalculated;
97
- });
82
+ };
98
83
  export const SelectionToolbar = ({
99
84
  api,
100
85
  editorView,
@@ -109,7 +94,7 @@ export const SelectionToolbar = ({
109
94
  shouldShowToolbar,
110
95
  editorViewMode,
111
96
  // @ts-ignore
112
- selection
97
+ selection: _selection
113
98
  } = usePluginState(api);
114
99
  const contextualFormattingEnabled = (_api$toolbar$actions$ = api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.contextualFormattingMode()) !== null && _api$toolbar$actions$ !== void 0 ? _api$toolbar$actions$ : 'always-pinned';
115
100
  const selectionToolbarConfigEnabled = shouldShowSelectionToolbar(contextualFormattingEnabled, editorToolbarDockingPreference);
@@ -168,7 +153,8 @@ export const SelectionToolbarWithErrorBoundary = ({
168
153
  api,
169
154
  editorView,
170
155
  mountPoint,
171
- disableSelectionToolbarWhenPinned
156
+ disableSelectionToolbarWhenPinned,
157
+ calculateToolbarPosition
172
158
  }) => {
173
159
  var _api$analytics2;
174
160
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
@@ -180,6 +166,7 @@ export const SelectionToolbarWithErrorBoundary = ({
180
166
  api: api,
181
167
  editorView: editorView,
182
168
  mountPoint: mountPoint,
183
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned
169
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned,
170
+ calculateToolbarPosition: calculateToolbarPosition
184
171
  }));
185
172
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -240,43 +240,41 @@ export const getToolbarComponents = (contextualFormattingEnabled, api, disableSe
240
240
  }, children);
241
241
  } : undefined
242
242
  }];
243
- if (expValEquals('platform_editor_toolbar_migrate_loom', 'isEnabled', true)) {
244
- components.push({
243
+ components.push({
244
+ type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
245
+ key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
246
+ parents: [{
247
+ type: 'toolbar',
248
+ key: TOOLBARS.PRIMARY_TOOLBAR,
249
+ rank: TOOLBAR_RANK[OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
250
+ }],
251
+ component: ({
252
+ children
253
+ }) => {
254
+ return /*#__PURE__*/React.createElement(OverflowSection, null, children);
255
+ }
256
+ }, {
257
+ type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
258
+ key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
259
+ parents: [{
245
260
  type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
246
261
  key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
247
- parents: [{
248
- type: 'toolbar',
249
- key: TOOLBARS.PRIMARY_TOOLBAR,
250
- rank: TOOLBAR_RANK[OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
251
- }],
252
- component: ({
253
- children
254
- }) => {
255
- return /*#__PURE__*/React.createElement(OverflowSection, null, children);
256
- }
257
- }, {
262
+ rank: OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
263
+ }]
264
+ }, {
265
+ type: OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
266
+ key: OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
267
+ parents: [{
258
268
  type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
259
269
  key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
260
- parents: [{
261
- type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
262
- key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
263
- rank: OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
264
- }]
265
- }, {
266
- type: OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
267
- key: OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
268
- parents: [{
269
- type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
270
- key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
271
- rank: OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
272
- }],
273
- component: ({
274
- children
275
- }) => {
276
- return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
277
- }
278
- });
279
- }
270
+ rank: OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
271
+ }],
272
+ component: ({
273
+ children
274
+ }) => {
275
+ return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
276
+ }
277
+ });
280
278
  if (fg('platform_editor_toolbar_aifc_placement_config')) {
281
279
  switch (contextualFormattingEnabled) {
282
280
  case 'always-inline':
@@ -5,6 +5,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  import React from 'react';
6
6
  import { bind } from 'bind-event-listener';
7
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
+ import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
8
9
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
10
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
11
  import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
@@ -12,8 +13,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
12
13
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
14
  import { getSelectionToolbarOpenExperiencePlugin } from './pm-plugins/experiences/selection-toolbar-open-experience';
14
15
  import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
15
- import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
16
- import { SelectionToolbar, SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
16
+ import { DEFAULT_POPUP_SELECTORS, SELECTION_TOOLBAR_LABEL } from './ui/consts';
17
+ import { SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
17
18
  import { getToolbarComponents } from './ui/toolbar-components';
18
19
  import { isEventInContainer } from './ui/utils/toolbar';
19
20
  function getSelectedNode(editorState) {
@@ -76,6 +77,7 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
76
77
  breakpointPreset = config.breakpointPreset;
77
78
  var registry = createComponentRegistry();
78
79
  registry.register(getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar, breakpointPreset));
80
+ var cachedCalculateToolbarPosition = expValEquals('platform_editor_sel_toolbar_fix', 'isEnabled', true) ? calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL) : undefined;
79
81
  return {
80
82
  name: 'toolbar',
81
83
  actions: {
@@ -202,19 +204,12 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
202
204
  if (!editorView) {
203
205
  return null;
204
206
  }
205
- if (fg('platform_editor_toolbar_aifc_patch_7')) {
206
- return /*#__PURE__*/React.createElement(SelectionToolbarWithErrorBoundary, {
207
- api: api,
208
- editorView: editorView,
209
- mountPoint: popupsMountPoint,
210
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
211
- });
212
- }
213
- return /*#__PURE__*/React.createElement(SelectionToolbar, {
207
+ return /*#__PURE__*/React.createElement(SelectionToolbarWithErrorBoundary, {
214
208
  api: api,
215
209
  editorView: editorView,
216
210
  mountPoint: popupsMountPoint,
217
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
211
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false,
212
+ calculateToolbarPosition: cachedCalculateToolbarPosition
218
213
  });
219
214
  } : undefined
220
215
  };
@@ -62,42 +62,25 @@ var usePluginState = conditionalHooksFactory(function () {
62
62
  selectedNode: selectedNode
63
63
  };
64
64
  });
65
- var useOnPositionCalculated = conditionalHooksFactory(function () {
66
- return fg('platform_editor_toolbar_aifc_patch_7');
67
- }, function (editorView) {
65
+ var useOnPositionCalculated = function useOnPositionCalculated(editorView, cachedCalculateToolbarPosition) {
68
66
  var onPositionCalculated = useCallback(function (position) {
69
67
  try {
70
- var toolbarTitle = SELECTION_TOOLBAR_LABEL;
71
-
72
68
  // Show special position on cell selection only when editor controls experiment is enabled
73
69
  var isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
74
70
  var isCellSelection = ('$anchorCell' in editorView.state.selection);
75
71
  if (isCellSelection && isEditorControlsEnabled) {
76
- return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
72
+ return calculateToolbarPositionOnCellSelection(SELECTION_TOOLBAR_LABEL)(editorView, position);
77
73
  }
78
- return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
74
+ return cachedCalculateToolbarPosition ? cachedCalculateToolbarPosition(editorView, position) : calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL)(editorView, position);
79
75
  } catch (error) {
80
76
  logException(error, {
81
77
  location: 'editor-plugin-toolbar/selectionToolbar'
82
78
  });
83
79
  return position;
84
80
  }
85
- }, [editorView]);
81
+ }, [editorView, cachedCalculateToolbarPosition]);
86
82
  return onPositionCalculated;
87
- }, function (editorView) {
88
- var onPositionCalculated = useCallback(function (position) {
89
- var toolbarTitle = SELECTION_TOOLBAR_LABEL;
90
-
91
- // Show special position on cell selection only when editor controls experiment is enabled
92
- var isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
93
- var isCellSelection = ('$anchorCell' in editorView.state.selection);
94
- if (isCellSelection && isEditorControlsEnabled) {
95
- return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
96
- }
97
- return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
98
- }, [editorView]);
99
- return onPositionCalculated;
100
- });
83
+ };
101
84
  export var SelectionToolbar = function SelectionToolbar(_ref) {
102
85
  var _api$toolbar$actions$, _api$toolbar, _api$toolbar2;
103
86
  var api = _ref.api,
@@ -110,7 +93,7 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
110
93
  currentUserIntent = _usePluginState.currentUserIntent,
111
94
  shouldShowToolbar = _usePluginState.shouldShowToolbar,
112
95
  editorViewMode = _usePluginState.editorViewMode,
113
- selection = _usePluginState.selection;
96
+ _selection = _usePluginState.selection;
114
97
  var contextualFormattingEnabled = (_api$toolbar$actions$ = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.contextualFormattingMode()) !== null && _api$toolbar$actions$ !== void 0 ? _api$toolbar$actions$ : 'always-pinned';
115
98
  var selectionToolbarConfigEnabled = shouldShowSelectionToolbar(contextualFormattingEnabled, editorToolbarDockingPreference);
116
99
  var intl = useIntl();
@@ -170,7 +153,8 @@ export var SelectionToolbarWithErrorBoundary = function SelectionToolbarWithErro
170
153
  var api = _ref2.api,
171
154
  editorView = _ref2.editorView,
172
155
  mountPoint = _ref2.mountPoint,
173
- disableSelectionToolbarWhenPinned = _ref2.disableSelectionToolbarWhenPinned;
156
+ disableSelectionToolbarWhenPinned = _ref2.disableSelectionToolbarWhenPinned,
157
+ calculateToolbarPosition = _ref2.calculateToolbarPosition;
174
158
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
175
159
  component: ACTION_SUBJECT.TOOLBAR,
176
160
  componentId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR,
@@ -180,6 +164,7 @@ export var SelectionToolbarWithErrorBoundary = function SelectionToolbarWithErro
180
164
  api: api,
181
165
  editorView: editorView,
182
166
  mountPoint: mountPoint,
183
- disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned
167
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned,
168
+ calculateToolbarPosition: calculateToolbarPosition
184
169
  }));
185
170
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -239,41 +239,39 @@ export var getToolbarComponents = function getToolbarComponents(contextualFormat
239
239
  }, children);
240
240
  } : undefined
241
241
  }]);
242
- if (expValEquals('platform_editor_toolbar_migrate_loom', 'isEnabled', true)) {
243
- components.push({
242
+ components.push({
243
+ type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
244
+ key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
245
+ parents: [{
246
+ type: 'toolbar',
247
+ key: TOOLBARS.PRIMARY_TOOLBAR,
248
+ rank: TOOLBAR_RANK[OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
249
+ }],
250
+ component: function component(_ref1) {
251
+ var children = _ref1.children;
252
+ return /*#__PURE__*/React.createElement(OverflowSection, null, children);
253
+ }
254
+ }, {
255
+ type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
256
+ key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
257
+ parents: [{
244
258
  type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
245
259
  key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
246
- parents: [{
247
- type: 'toolbar',
248
- key: TOOLBARS.PRIMARY_TOOLBAR,
249
- rank: TOOLBAR_RANK[OVERFLOW_SECTION_PRIMARY_TOOLBAR.key]
250
- }],
251
- component: function component(_ref1) {
252
- var children = _ref1.children;
253
- return /*#__PURE__*/React.createElement(OverflowSection, null, children);
254
- }
255
- }, {
260
+ rank: OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
261
+ }]
262
+ }, {
263
+ type: OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
264
+ key: OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
265
+ parents: [{
256
266
  type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
257
267
  key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
258
- parents: [{
259
- type: OVERFLOW_SECTION_PRIMARY_TOOLBAR.type,
260
- key: OVERFLOW_SECTION_PRIMARY_TOOLBAR.key,
261
- rank: OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK[OVERFLOW_GROUP_PRIMARY_TOOLBAR.key]
262
- }]
263
- }, {
264
- type: OVERFLOW_MENU_PRIMARY_TOOLBAR.type,
265
- key: OVERFLOW_MENU_PRIMARY_TOOLBAR.key,
266
- parents: [{
267
- type: OVERFLOW_GROUP_PRIMARY_TOOLBAR.type,
268
- key: OVERFLOW_GROUP_PRIMARY_TOOLBAR.key,
269
- rank: OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
270
- }],
271
- component: function component(_ref10) {
272
- var children = _ref10.children;
273
- return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
274
- }
275
- });
276
- }
268
+ rank: OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK[OVERFLOW_MENU_PRIMARY_TOOLBAR.key]
269
+ }],
270
+ component: function component(_ref10) {
271
+ var children = _ref10.children;
272
+ return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
273
+ }
274
+ });
277
275
  if (fg('platform_editor_toolbar_aifc_placement_config')) {
278
276
  switch (contextualFormattingEnabled) {
279
277
  case 'always-inline':
@@ -2,12 +2,14 @@ import React from 'react';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { ToolbarPlugin } from '../../toolbarPluginType';
5
+ import type { CalculateToolbarPosition } from './types';
5
6
  type SelectionToolbarProps = {
6
7
  api?: ExtractInjectionAPI<ToolbarPlugin>;
8
+ calculateToolbarPosition?: CalculateToolbarPosition;
7
9
  disableSelectionToolbarWhenPinned: boolean;
8
10
  editorView: EditorView;
9
11
  mountPoint: HTMLElement | undefined;
10
12
  };
11
13
  export declare const SelectionToolbar: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element | null;
12
- export declare const SelectionToolbarWithErrorBoundary: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element;
14
+ export declare const SelectionToolbarWithErrorBoundary: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, calculateToolbarPosition, }: SelectionToolbarProps) => React.JSX.Element;
13
15
  export {};
@@ -0,0 +1,6 @@
1
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export type Position = {
3
+ left?: number;
4
+ top?: number;
5
+ };
6
+ export type CalculateToolbarPosition = (editorView: EditorView, position: Position) => Position;
@@ -2,12 +2,14 @@ import React from 'react';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { ToolbarPlugin } from '../../toolbarPluginType';
5
+ import type { CalculateToolbarPosition } from './types';
5
6
  type SelectionToolbarProps = {
6
7
  api?: ExtractInjectionAPI<ToolbarPlugin>;
8
+ calculateToolbarPosition?: CalculateToolbarPosition;
7
9
  disableSelectionToolbarWhenPinned: boolean;
8
10
  editorView: EditorView;
9
11
  mountPoint: HTMLElement | undefined;
10
12
  };
11
13
  export declare const SelectionToolbar: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element | null;
12
- export declare const SelectionToolbarWithErrorBoundary: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element;
14
+ export declare const SelectionToolbarWithErrorBoundary: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, calculateToolbarPosition, }: SelectionToolbarProps) => React.JSX.Element;
13
15
  export {};
@@ -0,0 +1,6 @@
1
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export type Position = {
3
+ left?: number;
4
+ top?: number;
5
+ };
6
+ export type CalculateToolbarPosition = (editorView: EditorView, position: Position) => Position;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-toolbar",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/editor-toolbar-model": "^0.2.0",
41
41
  "@atlaskit/platform-feature-flags": "^1.1.0",
42
42
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
43
- "@atlaskit/tmp-editor-statsig": "^16.11.0",
43
+ "@atlaskit/tmp-editor-statsig": "^16.18.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "bind-event-listener": "^3.0.0",
46
46
  "react-intl-next": "npm:react-intl@^5.18.1"