@atlaskit/editor-plugin-toolbar 0.3.1 → 0.4.1

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/pm-plugins/plugin-key.js +8 -0
  3. package/dist/cjs/toolbarPlugin.js +84 -1
  4. package/dist/cjs/ui/Section.js +7 -3
  5. package/dist/cjs/ui/SelectionToolbar/index.js +28 -7
  6. package/dist/cjs/ui/consts.js +6 -2
  7. package/dist/cjs/ui/toolbar-components.js +10 -1
  8. package/dist/cjs/ui/utils/toolbar.js +13 -0
  9. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  10. package/dist/es2019/toolbarPlugin.js +84 -1
  11. package/dist/es2019/ui/Section.js +7 -3
  12. package/dist/es2019/ui/SelectionToolbar/index.js +28 -5
  13. package/dist/es2019/ui/consts.js +5 -1
  14. package/dist/es2019/ui/toolbar-components.js +11 -2
  15. package/dist/es2019/ui/utils/toolbar.js +7 -0
  16. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  17. package/dist/esm/toolbarPlugin.js +84 -1
  18. package/dist/esm/ui/Section.js +7 -3
  19. package/dist/esm/ui/SelectionToolbar/index.js +27 -7
  20. package/dist/esm/ui/consts.js +5 -1
  21. package/dist/esm/ui/toolbar-components.js +11 -2
  22. package/dist/esm/ui/utils/toolbar.js +7 -0
  23. package/dist/types/pm-plugins/plugin-key.d.ts +2 -0
  24. package/dist/types/toolbarPlugin.d.ts +3 -0
  25. package/dist/types/toolbarPluginType.d.ts +3 -0
  26. package/dist/types/ui/Section.d.ts +2 -1
  27. package/dist/types/ui/consts.d.ts +4 -0
  28. package/dist/types/ui/toolbar-components.d.ts +1 -1
  29. package/dist/types/ui/utils/toolbar.d.ts +1 -0
  30. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +2 -0
  31. package/dist/types-ts4.5/toolbarPlugin.d.ts +3 -0
  32. package/dist/types-ts4.5/toolbarPluginType.d.ts +3 -0
  33. package/dist/types-ts4.5/ui/Section.d.ts +2 -1
  34. package/dist/types-ts4.5/ui/consts.d.ts +4 -0
  35. package/dist/types-ts4.5/ui/toolbar-components.d.ts +1 -1
  36. package/dist/types-ts4.5/ui/utils/toolbar.d.ts +1 -0
  37. package/package.json +4 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/editor-plugin-toolbar
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`187540cdffa74`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/187540cdffa74) -
8
+ [ux] ED-29035 show text formatting option in comment toolbar regardless of pinning settings
9
+ - Updated dependencies
10
+
11
+ ## 0.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`e73faa5a52300`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e73faa5a52300) -
16
+ [ux] ED-28735 Fix selection toolbar opening and closing state
17
+
18
+ ### Patch Changes
19
+
20
+ - [`b27824f2875be`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b27824f2875be) -
21
+ [ux] [ED-28821] Add pin button to full page primary toolbar
22
+ - Updated dependencies
23
+
3
24
  ## 0.3.1
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.editorToolbarPluginKey = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var editorToolbarPluginKey = exports.editorToolbarPluginKey = new _state.PluginKey('editorToolbarPluginKey');
@@ -5,10 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.toolbarPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _react = _interopRequireDefault(require("react"));
10
+ var _bindEventListener = require("bind-event-listener");
11
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
12
  var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
13
+ var _pluginKey = require("./pm-plugins/plugin-key");
14
+ var _consts = require("./ui/consts");
10
15
  var _SelectionToolbar = require("./ui/SelectionToolbar");
11
16
  var _toolbarComponents = require("./ui/toolbar-components");
17
+ var _toolbar = require("./ui/utils/toolbar");
18
+ 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; }
19
+ 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; }
12
20
  var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
13
21
  var api = _ref.api,
14
22
  _ref$config = _ref.config,
@@ -17,7 +25,7 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
17
25
  } : _ref$config;
18
26
  var disableSelectionToolbar = config.disableSelectionToolbar;
19
27
  var registry = (0, _editorToolbarModel.createComponentRegistry)();
20
- registry.register((0, _toolbarComponents.getToolbarComponents)(api));
28
+ registry.register((0, _toolbarComponents.getToolbarComponents)(api, disableSelectionToolbar));
21
29
  return {
22
30
  name: 'toolbar',
23
31
  actions: {
@@ -28,6 +36,81 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
28
36
  return registry.components;
29
37
  }
30
38
  },
39
+ getSharedState: function getSharedState(editorState) {
40
+ if (!editorState) {
41
+ return undefined;
42
+ }
43
+ return _pluginKey.editorToolbarPluginKey.getState(editorState);
44
+ },
45
+ pmPlugins: function pmPlugins() {
46
+ return [{
47
+ name: 'editor-toolbar-selection',
48
+ plugin: function plugin() {
49
+ return new _safePlugin.SafePlugin({
50
+ key: _pluginKey.editorToolbarPluginKey,
51
+ state: {
52
+ init: function init() {
53
+ return {
54
+ shouldShowToolbar: false
55
+ };
56
+ },
57
+ apply: function apply(tr, pluginState) {
58
+ var meta = tr.getMeta(_pluginKey.editorToolbarPluginKey);
59
+ var newPluginState = pluginState;
60
+ if (meta) {
61
+ return _objectSpread(_objectSpread({}, newPluginState), meta);
62
+ }
63
+ return newPluginState;
64
+ }
65
+ },
66
+ view: function view(_view) {
67
+ var unbind = (0, _bindEventListener.bind)(_view.root, {
68
+ type: 'mouseup',
69
+ listener: function listener(ev) {
70
+ var _api$editorViewMode;
71
+ var event = ev;
72
+ var isInToolbar = (0, _toolbar.isEventInContainer)(event, _consts.DEFAULT_POPUP_SELECTORS.toolbarContainer);
73
+ var isInPortal = (0, _toolbar.isEventInContainer)(event, _consts.DEFAULT_POPUP_SELECTORS.portal);
74
+
75
+ // We only want to set selectionStable to true if the editor has focus
76
+ // to prevent the toolbar from showing when the editor is blurred
77
+ // due to a click outside the editor.
78
+ var editorViewModePlugin = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
79
+ var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
80
+ _view.dispatch(_view.state.tr.setMeta(_pluginKey.editorToolbarPluginKey, {
81
+ shouldShowToolbar: !isViewModeEnabled ? _view.hasFocus() || isInToolbar || isInPortal : true
82
+ }));
83
+ }
84
+ });
85
+ var unbindEditorViewFocus = (0, _bindEventListener.bind)(_view.dom, {
86
+ type: 'focus',
87
+ listener: function listener() {
88
+ _view.dispatch(_view.state.tr.setMeta(_pluginKey.editorToolbarPluginKey, {
89
+ shouldShowToolbar: true
90
+ }));
91
+ }
92
+ });
93
+ return {
94
+ destroy: function destroy() {
95
+ unbind();
96
+ unbindEditorViewFocus();
97
+ }
98
+ };
99
+ },
100
+ props: {
101
+ handleDOMEvents: {
102
+ mousedown: function mousedown(view) {
103
+ view.dispatch(view.state.tr.setMeta(_pluginKey.editorToolbarPluginKey, {
104
+ shouldShowToolbar: false
105
+ }));
106
+ return false;
107
+ }
108
+ }
109
+ }
110
+ });
111
+ }
112
+ }];
113
+ },
31
114
  contentComponent: !disableSelectionToolbar ? function (_ref2) {
32
115
  var editorView = _ref2.editorView,
33
116
  popupsMountPoint = _ref2.popupsMountPoint;
@@ -9,10 +9,13 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _toolbar = require("@atlaskit/editor-common/toolbar");
10
10
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
11
11
  var _editorToolbar = require("@atlaskit/editor-toolbar");
12
- var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking) {
12
+ var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar) {
13
13
  if (editMode === 'view') {
14
14
  return false;
15
15
  }
16
+ if (disableSelectionToolbar) {
17
+ return true;
18
+ }
16
19
  if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
17
20
  return true;
18
21
  }
@@ -28,7 +31,8 @@ var Section = exports.Section = function Section(_ref) {
28
31
  testId = _ref.testId,
29
32
  showSeparatorInFullPagePrimaryToolbar = _ref.showSeparatorInFullPagePrimaryToolbar,
30
33
  _ref$isSharedSection = _ref.isSharedSection,
31
- isSharedSection = _ref$isSharedSection === void 0 ? true : _ref$isSharedSection;
34
+ isSharedSection = _ref$isSharedSection === void 0 ? true : _ref$isSharedSection,
35
+ disableSelectionToolbar = _ref.disableSelectionToolbar;
32
36
  var editMode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'editorViewMode.mode');
33
37
  var toolbarDocking = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userPreferences.preferences.toolbarDockingPosition');
34
38
  var toolbar = parents.find(function (parent) {
@@ -36,7 +40,7 @@ var Section = exports.Section = function Section(_ref) {
36
40
  });
37
41
  var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
38
42
  editorAppearance = _useEditorToolbar.editorAppearance;
39
- if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking)) {
43
+ if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar)) {
40
44
  return null;
41
45
  }
42
46
  var isFullPage = editorAppearance === 'full-page';
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.SelectionToolbar = void 0;
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
  var _coreUtils = require("@atlaskit/editor-common/core-utils");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
10
11
  var _toolbar = require("@atlaskit/editor-common/toolbar");
11
12
  var _ui = require("@atlaskit/editor-common/ui");
12
13
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
@@ -15,16 +16,26 @@ var _state = require("@atlaskit/editor-prosemirror/state");
15
16
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
16
17
  var _editorToolbar = require("@atlaskit/editor-toolbar");
17
18
  var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
19
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
18
20
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
19
21
  var _consts = require("../consts");
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
23
  var isToolbarComponent = function isToolbarComponent(component) {
21
24
  return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
22
25
  };
23
26
  var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
27
+ var _api$toolbar, _api$toolbar$getCompo;
24
28
  var api = _ref.api,
25
29
  editorView = _ref.editorView,
26
30
  mountPoint = _ref.mountPoint;
27
- var components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
31
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['toolbar'], function (state) {
32
+ var _state$toolbarState;
33
+ return {
34
+ shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar
35
+ };
36
+ }),
37
+ shouldShowToolbar = _useSharedPluginState.shouldShowToolbar;
38
+ var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || (_api$toolbar = _api$toolbar.actions) === null || _api$toolbar === void 0 || (_api$toolbar$getCompo = _api$toolbar.getComponents) === null || _api$toolbar$getCompo === void 0 ? void 0 : _api$toolbar$getCompo.call(_api$toolbar);
28
39
  var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
29
40
  return isToolbarComponent(component);
30
41
  });
@@ -36,18 +47,28 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
36
47
  var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
37
48
  var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.TextSelection;
38
49
  var isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
50
+ var onPositionCalculated = (0, _react.useCallback)(function (position) {
51
+ var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
52
+
53
+ // Show special position on cell selection only when editor controls experiment is enabled
54
+ var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
55
+ var isCellSelection = ('$anchorCell' in editorView.state.selection);
56
+ if (isCellSelection && isEditorControlsEnabled) {
57
+ return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
58
+ }
59
+ var calc = _utils.calculateToolbarPositionTrackHead;
60
+ return calc(toolbarTitle)(editorView, position);
61
+ }, [editorView]);
39
62
  if (!components || !toolbar) {
40
63
  return null;
41
64
  }
42
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || (0, _coreUtils.isSSR)()) {
65
+ if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || (0, _coreUtils.isSSR)()) {
43
66
  return null;
44
67
  }
45
68
  return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
46
69
  offset: [0, 10],
47
70
  target: getDomRefFromSelection(editorView),
48
- onPositionCalculated: function onPositionCalculated(position) {
49
- return (0, _utils.calculateToolbarPositionTrackHead)(_consts.SELECTION_TOOLBAR_LABEL)(editorView, position);
50
- },
71
+ onPositionCalculated: onPositionCalculated,
51
72
  mountTo: mountPoint
52
73
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
53
74
  editorView: editorView
@@ -3,5 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SELECTION_TOOLBAR_LABEL = void 0;
7
- var SELECTION_TOOLBAR_LABEL = exports.SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
6
+ exports.SELECTION_TOOLBAR_LABEL = exports.DEFAULT_POPUP_SELECTORS = void 0;
7
+ var SELECTION_TOOLBAR_LABEL = exports.SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
8
+ var DEFAULT_POPUP_SELECTORS = exports.DEFAULT_POPUP_SELECTORS = {
9
+ toolbarContainer: '[role="toolbar"]',
10
+ portal: '.atlaskit-portal'
11
+ };
@@ -11,7 +11,7 @@ var _editorToolbar = require("@atlaskit/editor-toolbar");
11
11
  var _consts = require("./consts");
12
12
  var _OverflowMenu = require("./OverflowMenu");
13
13
  var _Section = require("./Section");
14
- var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
14
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api, disableSelectionToolbar) {
15
15
  return [{
16
16
  type: 'toolbar',
17
17
  key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -48,6 +48,7 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
48
48
  return /*#__PURE__*/_react.default.createElement(_Section.Section, {
49
49
  parents: parents,
50
50
  api: api,
51
+ disableSelectionToolbar: disableSelectionToolbar,
51
52
  testId: "text-section"
52
53
  }, children);
53
54
  }
@@ -120,5 +121,13 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
120
121
  var children = _ref6.children;
121
122
  return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children);
122
123
  }
124
+ }, {
125
+ type: _toolbar.PIN_SECTION.type,
126
+ key: _toolbar.PIN_SECTION.key,
127
+ parents: [{
128
+ type: 'toolbar',
129
+ key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
130
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.PIN_SECTION.key]
131
+ }]
123
132
  }];
124
133
  };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isEventInContainer = void 0;
7
+ var isEventInContainer = exports.isEventInContainer = function isEventInContainer(event, containerSelector) {
8
+ var target = event.target instanceof Element ? event.target : null;
9
+ if (!target) {
10
+ return false;
11
+ }
12
+ return !!target.closest(containerSelector);
13
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export const editorToolbarPluginKey = new PluginKey('editorToolbarPluginKey');
@@ -1,7 +1,12 @@
1
1
  import React from 'react';
2
+ import { bind } from 'bind-event-listener';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
4
  import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
5
+ import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
6
+ import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
3
7
  import { SelectionToolbar } from './ui/SelectionToolbar';
4
8
  import { getToolbarComponents } from './ui/toolbar-components';
9
+ import { isEventInContainer } from './ui/utils/toolbar';
5
10
  export const toolbarPlugin = ({
6
11
  api,
7
12
  config = {
@@ -12,7 +17,7 @@ export const toolbarPlugin = ({
12
17
  disableSelectionToolbar
13
18
  } = config;
14
19
  const registry = createComponentRegistry();
15
- registry.register(getToolbarComponents(api));
20
+ registry.register(getToolbarComponents(api, disableSelectionToolbar));
16
21
  return {
17
22
  name: 'toolbar',
18
23
  actions: {
@@ -23,6 +28,84 @@ export const toolbarPlugin = ({
23
28
  return registry.components;
24
29
  }
25
30
  },
31
+ getSharedState(editorState) {
32
+ if (!editorState) {
33
+ return undefined;
34
+ }
35
+ return editorToolbarPluginKey.getState(editorState);
36
+ },
37
+ pmPlugins() {
38
+ return [{
39
+ name: 'editor-toolbar-selection',
40
+ plugin: () => {
41
+ return new SafePlugin({
42
+ key: editorToolbarPluginKey,
43
+ state: {
44
+ init() {
45
+ return {
46
+ shouldShowToolbar: false
47
+ };
48
+ },
49
+ apply(tr, pluginState) {
50
+ const meta = tr.getMeta(editorToolbarPluginKey);
51
+ const newPluginState = pluginState;
52
+ if (meta) {
53
+ return {
54
+ ...newPluginState,
55
+ ...meta
56
+ };
57
+ }
58
+ return newPluginState;
59
+ }
60
+ },
61
+ view(view) {
62
+ const unbind = bind(view.root, {
63
+ type: 'mouseup',
64
+ listener: function (ev) {
65
+ var _api$editorViewMode;
66
+ const event = ev;
67
+ const isInToolbar = isEventInContainer(event, DEFAULT_POPUP_SELECTORS.toolbarContainer);
68
+ const isInPortal = isEventInContainer(event, DEFAULT_POPUP_SELECTORS.portal);
69
+
70
+ // We only want to set selectionStable to true if the editor has focus
71
+ // to prevent the toolbar from showing when the editor is blurred
72
+ // due to a click outside the editor.
73
+ const editorViewModePlugin = api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
74
+ const isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
75
+ view.dispatch(view.state.tr.setMeta(editorToolbarPluginKey, {
76
+ shouldShowToolbar: !isViewModeEnabled ? view.hasFocus() || isInToolbar || isInPortal : true
77
+ }));
78
+ }
79
+ });
80
+ const unbindEditorViewFocus = bind(view.dom, {
81
+ type: 'focus',
82
+ listener: () => {
83
+ view.dispatch(view.state.tr.setMeta(editorToolbarPluginKey, {
84
+ shouldShowToolbar: true
85
+ }));
86
+ }
87
+ });
88
+ return {
89
+ destroy() {
90
+ unbind();
91
+ unbindEditorViewFocus();
92
+ }
93
+ };
94
+ },
95
+ props: {
96
+ handleDOMEvents: {
97
+ mousedown: view => {
98
+ view.dispatch(view.state.tr.setMeta(editorToolbarPluginKey, {
99
+ shouldShowToolbar: false
100
+ }));
101
+ return false;
102
+ }
103
+ }
104
+ }
105
+ });
106
+ }
107
+ }];
108
+ },
26
109
  contentComponent: !disableSelectionToolbar ? ({
27
110
  editorView,
28
111
  popupsMountPoint
@@ -2,10 +2,13 @@ import React from 'react';
2
2
  import { TOOLBARS, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
3
3
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
4
  import { ToolbarSection } from '@atlaskit/editor-toolbar';
5
- const shouldShowSection = (editMode, toolbar, toolbarDocking) => {
5
+ const shouldShowSection = (editMode, toolbar, toolbarDocking, disableSelectionToolbar) => {
6
6
  if (editMode === 'view') {
7
7
  return false;
8
8
  }
9
+ if (disableSelectionToolbar) {
10
+ return true;
11
+ }
9
12
  if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
10
13
  return true;
11
14
  }
@@ -20,7 +23,8 @@ export const Section = ({
20
23
  api,
21
24
  testId,
22
25
  showSeparatorInFullPagePrimaryToolbar,
23
- isSharedSection = true
26
+ isSharedSection = true,
27
+ disableSelectionToolbar
24
28
  }) => {
25
29
  const editMode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
26
30
  const toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
@@ -28,7 +32,7 @@ export const Section = ({
28
32
  const {
29
33
  editorAppearance
30
34
  } = useEditorToolbar();
31
- if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking)) {
35
+ if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar)) {
32
36
  return null;
33
37
  }
34
38
  const isFullPage = editorAppearance === 'full-page';
@@ -1,13 +1,15 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor-common/toolbar';
4
5
  import { Popup } from '@atlaskit/editor-common/ui';
5
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
- import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
7
+ import { calculateToolbarPositionTrackHead, calculateToolbarPositionOnCellSelection } from '@atlaskit/editor-common/utils';
7
8
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
9
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
10
  import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
10
11
  import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
13
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
12
14
  import { SELECTION_TOOLBAR_LABEL } from '../consts';
13
15
  const isToolbarComponent = component => {
@@ -18,7 +20,16 @@ export const SelectionToolbar = ({
18
20
  editorView,
19
21
  mountPoint
20
22
  }) => {
21
- const components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
23
+ var _api$toolbar, _api$toolbar$actions, _api$toolbar$actions$;
24
+ const {
25
+ shouldShowToolbar
26
+ } = useSharedPluginStateWithSelector(api, ['toolbar'], state => {
27
+ var _state$toolbarState;
28
+ return {
29
+ shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar
30
+ };
31
+ });
32
+ const components = api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : (_api$toolbar$actions = _api$toolbar.actions) === null || _api$toolbar$actions === void 0 ? void 0 : (_api$toolbar$actions$ = _api$toolbar$actions.getComponents) === null || _api$toolbar$actions$ === void 0 ? void 0 : _api$toolbar$actions$.call(_api$toolbar$actions);
22
33
  const toolbar = components === null || components === void 0 ? void 0 : components.find(component => isToolbarComponent(component));
23
34
  const currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
24
35
  const connectivityStateMode = useSharedPluginStateSelector(api, 'connectivity.mode');
@@ -28,16 +39,28 @@ export const SelectionToolbar = ({
28
39
  const selection = useSharedPluginStateSelector(api, 'selection.selection');
29
40
  const isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
30
41
  const isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
42
+ const onPositionCalculated = useCallback(position => {
43
+ const toolbarTitle = SELECTION_TOOLBAR_LABEL;
44
+
45
+ // Show special position on cell selection only when editor controls experiment is enabled
46
+ const isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
47
+ const isCellSelection = ('$anchorCell' in editorView.state.selection);
48
+ if (isCellSelection && isEditorControlsEnabled) {
49
+ return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
50
+ }
51
+ const calc = calculateToolbarPositionTrackHead;
52
+ return calc(toolbarTitle)(editorView, position);
53
+ }, [editorView]);
31
54
  if (!components || !toolbar) {
32
55
  return null;
33
56
  }
34
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
57
+ if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
35
58
  return null;
36
59
  }
37
60
  return /*#__PURE__*/React.createElement(Popup, {
38
61
  offset: [0, 10],
39
62
  target: getDomRefFromSelection(editorView),
40
- onPositionCalculated: position => calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL)(editorView, position),
63
+ onPositionCalculated: onPositionCalculated,
41
64
  mountTo: mountPoint
42
65
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
43
66
  editorView: editorView
@@ -1 +1,5 @@
1
- export const SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
1
+ export const SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
2
+ export const DEFAULT_POPUP_SELECTORS = {
3
+ toolbarContainer: '[role="toolbar"]',
4
+ portal: '.atlaskit-portal'
5
+ };
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
2
+ import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, PIN_SECTION, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
3
  import { PrimaryToolbar, Toolbar } from '@atlaskit/editor-toolbar';
4
4
  import { SELECTION_TOOLBAR_LABEL } from './consts';
5
5
  import { OverflowMenu } from './OverflowMenu';
6
6
  import { Section } from './Section';
7
- export const getToolbarComponents = api => {
7
+ export const getToolbarComponents = (api, disableSelectionToolbar) => {
8
8
  return [{
9
9
  type: 'toolbar',
10
10
  key: TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -42,6 +42,7 @@ export const getToolbarComponents = api => {
42
42
  return /*#__PURE__*/React.createElement(Section, {
43
43
  parents: parents,
44
44
  api: api,
45
+ disableSelectionToolbar: disableSelectionToolbar,
45
46
  testId: "text-section"
46
47
  }, children);
47
48
  }
@@ -113,5 +114,13 @@ export const getToolbarComponents = api => {
113
114
  }) => {
114
115
  return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
115
116
  }
117
+ }, {
118
+ type: PIN_SECTION.type,
119
+ key: PIN_SECTION.key,
120
+ parents: [{
121
+ type: 'toolbar',
122
+ key: TOOLBARS.PRIMARY_TOOLBAR,
123
+ rank: TOOLBAR_RANK[PIN_SECTION.key]
124
+ }]
116
125
  }];
117
126
  };
@@ -0,0 +1,7 @@
1
+ export const isEventInContainer = (event, containerSelector) => {
2
+ const target = event.target instanceof Element ? event.target : null;
3
+ if (!target) {
4
+ return false;
5
+ }
6
+ return !!target.closest(containerSelector);
7
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var editorToolbarPluginKey = new PluginKey('editorToolbarPluginKey');
@@ -1,7 +1,15 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
1
4
  import React from 'react';
5
+ import { bind } from 'bind-event-listener';
6
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
7
  import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
8
+ import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
9
+ import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
3
10
  import { SelectionToolbar } from './ui/SelectionToolbar';
4
11
  import { getToolbarComponents } from './ui/toolbar-components';
12
+ import { isEventInContainer } from './ui/utils/toolbar';
5
13
  export var toolbarPlugin = function toolbarPlugin(_ref) {
6
14
  var api = _ref.api,
7
15
  _ref$config = _ref.config,
@@ -10,7 +18,7 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
10
18
  } : _ref$config;
11
19
  var disableSelectionToolbar = config.disableSelectionToolbar;
12
20
  var registry = createComponentRegistry();
13
- registry.register(getToolbarComponents(api));
21
+ registry.register(getToolbarComponents(api, disableSelectionToolbar));
14
22
  return {
15
23
  name: 'toolbar',
16
24
  actions: {
@@ -21,6 +29,81 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
21
29
  return registry.components;
22
30
  }
23
31
  },
32
+ getSharedState: function getSharedState(editorState) {
33
+ if (!editorState) {
34
+ return undefined;
35
+ }
36
+ return editorToolbarPluginKey.getState(editorState);
37
+ },
38
+ pmPlugins: function pmPlugins() {
39
+ return [{
40
+ name: 'editor-toolbar-selection',
41
+ plugin: function plugin() {
42
+ return new SafePlugin({
43
+ key: editorToolbarPluginKey,
44
+ state: {
45
+ init: function init() {
46
+ return {
47
+ shouldShowToolbar: false
48
+ };
49
+ },
50
+ apply: function apply(tr, pluginState) {
51
+ var meta = tr.getMeta(editorToolbarPluginKey);
52
+ var newPluginState = pluginState;
53
+ if (meta) {
54
+ return _objectSpread(_objectSpread({}, newPluginState), meta);
55
+ }
56
+ return newPluginState;
57
+ }
58
+ },
59
+ view: function view(_view) {
60
+ var unbind = bind(_view.root, {
61
+ type: 'mouseup',
62
+ listener: function listener(ev) {
63
+ var _api$editorViewMode;
64
+ var event = ev;
65
+ var isInToolbar = isEventInContainer(event, DEFAULT_POPUP_SELECTORS.toolbarContainer);
66
+ var isInPortal = isEventInContainer(event, DEFAULT_POPUP_SELECTORS.portal);
67
+
68
+ // We only want to set selectionStable to true if the editor has focus
69
+ // to prevent the toolbar from showing when the editor is blurred
70
+ // due to a click outside the editor.
71
+ var editorViewModePlugin = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
72
+ var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
73
+ _view.dispatch(_view.state.tr.setMeta(editorToolbarPluginKey, {
74
+ shouldShowToolbar: !isViewModeEnabled ? _view.hasFocus() || isInToolbar || isInPortal : true
75
+ }));
76
+ }
77
+ });
78
+ var unbindEditorViewFocus = bind(_view.dom, {
79
+ type: 'focus',
80
+ listener: function listener() {
81
+ _view.dispatch(_view.state.tr.setMeta(editorToolbarPluginKey, {
82
+ shouldShowToolbar: true
83
+ }));
84
+ }
85
+ });
86
+ return {
87
+ destroy: function destroy() {
88
+ unbind();
89
+ unbindEditorViewFocus();
90
+ }
91
+ };
92
+ },
93
+ props: {
94
+ handleDOMEvents: {
95
+ mousedown: function mousedown(view) {
96
+ view.dispatch(view.state.tr.setMeta(editorToolbarPluginKey, {
97
+ shouldShowToolbar: false
98
+ }));
99
+ return false;
100
+ }
101
+ }
102
+ }
103
+ });
104
+ }
105
+ }];
106
+ },
24
107
  contentComponent: !disableSelectionToolbar ? function (_ref2) {
25
108
  var editorView = _ref2.editorView,
26
109
  popupsMountPoint = _ref2.popupsMountPoint;
@@ -2,10 +2,13 @@ import React from 'react';
2
2
  import { TOOLBARS, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
3
3
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
4
  import { ToolbarSection } from '@atlaskit/editor-toolbar';
5
- var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking) {
5
+ var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar) {
6
6
  if (editMode === 'view') {
7
7
  return false;
8
8
  }
9
+ if (disableSelectionToolbar) {
10
+ return true;
11
+ }
9
12
  if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
10
13
  return true;
11
14
  }
@@ -21,7 +24,8 @@ export var Section = function Section(_ref) {
21
24
  testId = _ref.testId,
22
25
  showSeparatorInFullPagePrimaryToolbar = _ref.showSeparatorInFullPagePrimaryToolbar,
23
26
  _ref$isSharedSection = _ref.isSharedSection,
24
- isSharedSection = _ref$isSharedSection === void 0 ? true : _ref$isSharedSection;
27
+ isSharedSection = _ref$isSharedSection === void 0 ? true : _ref$isSharedSection,
28
+ disableSelectionToolbar = _ref.disableSelectionToolbar;
25
29
  var editMode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
26
30
  var toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
27
31
  var toolbar = parents.find(function (parent) {
@@ -29,7 +33,7 @@ export var Section = function Section(_ref) {
29
33
  });
30
34
  var _useEditorToolbar = useEditorToolbar(),
31
35
  editorAppearance = _useEditorToolbar.editorAppearance;
32
- if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking)) {
36
+ if (isSharedSection && !shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar)) {
33
37
  return null;
34
38
  }
35
39
  var isFullPage = editorAppearance === 'full-page';
@@ -1,23 +1,33 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor-common/toolbar';
4
5
  import { Popup } from '@atlaskit/editor-common/ui';
5
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
- import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
7
+ import { calculateToolbarPositionTrackHead, calculateToolbarPositionOnCellSelection } from '@atlaskit/editor-common/utils';
7
8
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
9
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
10
  import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
10
11
  import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
13
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
12
14
  import { SELECTION_TOOLBAR_LABEL } from '../consts';
13
15
  var isToolbarComponent = function isToolbarComponent(component) {
14
16
  return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
15
17
  };
16
18
  export var SelectionToolbar = function SelectionToolbar(_ref) {
19
+ var _api$toolbar, _api$toolbar$getCompo;
17
20
  var api = _ref.api,
18
21
  editorView = _ref.editorView,
19
22
  mountPoint = _ref.mountPoint;
20
- var components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
23
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['toolbar'], function (state) {
24
+ var _state$toolbarState;
25
+ return {
26
+ shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar
27
+ };
28
+ }),
29
+ shouldShowToolbar = _useSharedPluginState.shouldShowToolbar;
30
+ var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || (_api$toolbar = _api$toolbar.actions) === null || _api$toolbar === void 0 || (_api$toolbar$getCompo = _api$toolbar.getComponents) === null || _api$toolbar$getCompo === void 0 ? void 0 : _api$toolbar$getCompo.call(_api$toolbar);
21
31
  var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
22
32
  return isToolbarComponent(component);
23
33
  });
@@ -29,18 +39,28 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
29
39
  var selection = useSharedPluginStateSelector(api, 'selection.selection');
30
40
  var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
31
41
  var isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
42
+ var onPositionCalculated = useCallback(function (position) {
43
+ var toolbarTitle = SELECTION_TOOLBAR_LABEL;
44
+
45
+ // Show special position on cell selection only when editor controls experiment is enabled
46
+ var isEditorControlsEnabled = expValEquals('platform_editor_controls', 'cohort', 'variant1');
47
+ var isCellSelection = ('$anchorCell' in editorView.state.selection);
48
+ if (isCellSelection && isEditorControlsEnabled) {
49
+ return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
50
+ }
51
+ var calc = calculateToolbarPositionTrackHead;
52
+ return calc(toolbarTitle)(editorView, position);
53
+ }, [editorView]);
32
54
  if (!components || !toolbar) {
33
55
  return null;
34
56
  }
35
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
57
+ if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
36
58
  return null;
37
59
  }
38
60
  return /*#__PURE__*/React.createElement(Popup, {
39
61
  offset: [0, 10],
40
62
  target: getDomRefFromSelection(editorView),
41
- onPositionCalculated: function onPositionCalculated(position) {
42
- return calculateToolbarPositionTrackHead(SELECTION_TOOLBAR_LABEL)(editorView, position);
43
- },
63
+ onPositionCalculated: onPositionCalculated,
44
64
  mountTo: mountPoint
45
65
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
46
66
  editorView: editorView
@@ -1 +1,5 @@
1
- export var SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
1
+ export var SELECTION_TOOLBAR_LABEL = 'Selection toolbar';
2
+ export var DEFAULT_POPUP_SELECTORS = {
3
+ toolbarContainer: '[role="toolbar"]',
4
+ portal: '.atlaskit-portal'
5
+ };
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
2
+ import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, PIN_SECTION, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
3
  import { PrimaryToolbar, Toolbar } from '@atlaskit/editor-toolbar';
4
4
  import { SELECTION_TOOLBAR_LABEL } from './consts';
5
5
  import { OverflowMenu } from './OverflowMenu';
6
6
  import { Section } from './Section';
7
- export var getToolbarComponents = function getToolbarComponents(api) {
7
+ export var getToolbarComponents = function getToolbarComponents(api, disableSelectionToolbar) {
8
8
  return [{
9
9
  type: 'toolbar',
10
10
  key: TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -41,6 +41,7 @@ export var getToolbarComponents = function getToolbarComponents(api) {
41
41
  return /*#__PURE__*/React.createElement(Section, {
42
42
  parents: parents,
43
43
  api: api,
44
+ disableSelectionToolbar: disableSelectionToolbar,
44
45
  testId: "text-section"
45
46
  }, children);
46
47
  }
@@ -113,5 +114,13 @@ export var getToolbarComponents = function getToolbarComponents(api) {
113
114
  var children = _ref6.children;
114
115
  return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
115
116
  }
117
+ }, {
118
+ type: PIN_SECTION.type,
119
+ key: PIN_SECTION.key,
120
+ parents: [{
121
+ type: 'toolbar',
122
+ key: TOOLBARS.PRIMARY_TOOLBAR,
123
+ rank: TOOLBAR_RANK[PIN_SECTION.key]
124
+ }]
116
125
  }];
117
126
  };
@@ -0,0 +1,7 @@
1
+ export var isEventInContainer = function isEventInContainer(event, containerSelector) {
2
+ var target = event.target instanceof Element ? event.target : null;
3
+ if (!target) {
4
+ return false;
5
+ }
6
+ return !!target.closest(containerSelector);
7
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const editorToolbarPluginKey: PluginKey<any>;
@@ -1,2 +1,5 @@
1
1
  import type { ToolbarPlugin } from './toolbarPluginType';
2
+ export type EditorToolbarPluginState = {
3
+ shouldShowToolbar: boolean;
4
+ };
2
5
  export declare const toolbarPlugin: ToolbarPlugin;
@@ -8,6 +8,9 @@ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
8
8
  import type { ToolbarPluginOptions } from './types';
9
9
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
10
10
  pluginConfiguration?: ToolbarPluginOptions;
11
+ sharedState: {
12
+ shouldShowToolbar: boolean;
13
+ };
11
14
  dependencies: [
12
15
  OptionalPlugin<UserIntentPlugin>,
13
16
  OptionalPlugin<SelectionPlugin>,
@@ -9,6 +9,7 @@ type SectionProps = {
9
9
  testId?: string;
10
10
  showSeparatorInFullPagePrimaryToolbar?: boolean;
11
11
  isSharedSection?: boolean;
12
+ disableSelectionToolbar?: boolean;
12
13
  };
13
- export declare const Section: ({ children, parents, api, testId, showSeparatorInFullPagePrimaryToolbar, isSharedSection, }: SectionProps) => React.JSX.Element | null;
14
+ export declare const Section: ({ children, parents, api, testId, showSeparatorInFullPagePrimaryToolbar, isSharedSection, disableSelectionToolbar, }: SectionProps) => React.JSX.Element | null;
14
15
  export {};
@@ -1 +1,5 @@
1
1
  export declare const SELECTION_TOOLBAR_LABEL = "Selection toolbar";
2
+ export declare const DEFAULT_POPUP_SELECTORS: {
3
+ readonly toolbarContainer: "[role=\"toolbar\"]";
4
+ readonly portal: ".atlaskit-portal";
5
+ };
@@ -1,4 +1,4 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
3
  import type { ToolbarPlugin } from '../toolbarPluginType';
4
- export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>) => RegisterComponent[];
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
@@ -0,0 +1 @@
1
+ export declare const isEventInContainer: (event: Event, containerSelector: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const editorToolbarPluginKey: PluginKey<any>;
@@ -1,2 +1,5 @@
1
1
  import type { ToolbarPlugin } from './toolbarPluginType';
2
+ export type EditorToolbarPluginState = {
3
+ shouldShowToolbar: boolean;
4
+ };
2
5
  export declare const toolbarPlugin: ToolbarPlugin;
@@ -8,6 +8,9 @@ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
8
8
  import type { ToolbarPluginOptions } from './types';
9
9
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
10
10
  pluginConfiguration?: ToolbarPluginOptions;
11
+ sharedState: {
12
+ shouldShowToolbar: boolean;
13
+ };
11
14
  dependencies: [
12
15
  OptionalPlugin<UserIntentPlugin>,
13
16
  OptionalPlugin<SelectionPlugin>,
@@ -9,6 +9,7 @@ type SectionProps = {
9
9
  testId?: string;
10
10
  showSeparatorInFullPagePrimaryToolbar?: boolean;
11
11
  isSharedSection?: boolean;
12
+ disableSelectionToolbar?: boolean;
12
13
  };
13
- export declare const Section: ({ children, parents, api, testId, showSeparatorInFullPagePrimaryToolbar, isSharedSection, }: SectionProps) => React.JSX.Element | null;
14
+ export declare const Section: ({ children, parents, api, testId, showSeparatorInFullPagePrimaryToolbar, isSharedSection, disableSelectionToolbar, }: SectionProps) => React.JSX.Element | null;
14
15
  export {};
@@ -1 +1,5 @@
1
1
  export declare const SELECTION_TOOLBAR_LABEL = "Selection toolbar";
2
+ export declare const DEFAULT_POPUP_SELECTORS: {
3
+ readonly toolbarContainer: "[role=\"toolbar\"]";
4
+ readonly portal: ".atlaskit-portal";
5
+ };
@@ -1,4 +1,4 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
3
  import type { ToolbarPlugin } from '../toolbarPluginType';
4
- export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>) => RegisterComponent[];
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
@@ -0,0 +1 @@
1
+ export declare const isEventInContainer: (event: Event, containerSelector: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-toolbar",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,14 +33,15 @@
33
33
  "dependencies": {
34
34
  "@atlaskit/editor-plugin-connectivity": "^3.1.0",
35
35
  "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
36
- "@atlaskit/editor-plugin-selection": "^3.1.0",
36
+ "@atlaskit/editor-plugin-selection": "^3.2.0",
37
37
  "@atlaskit/editor-plugin-user-intent": "^1.1.0",
38
38
  "@atlaskit/editor-plugin-user-preferences": "^1.2.0",
39
39
  "@atlaskit/editor-prosemirror": "7.0.0",
40
40
  "@atlaskit/editor-toolbar": "^0.3.0",
41
41
  "@atlaskit/editor-toolbar-model": "^0.1.0",
42
- "@atlaskit/tmp-editor-statsig": "^11.4.0",
42
+ "@atlaskit/tmp-editor-statsig": "^11.5.0",
43
43
  "@babel/runtime": "^7.0.0",
44
+ "bind-event-listener": "^3.0.0",
44
45
  "react-intl-next": "npm:react-intl@^5.18.1"
45
46
  },
46
47
  "peerDependencies": {