@atlaskit/editor-plugin-selection-toolbar 1.8.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-selection-toolbar
2
2
 
3
+ ## 1.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#117435](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/117435)
8
+ [`2526289f60537`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2526289f60537) -
9
+ [ux] ED-26675 Docked primary toolbar overflow menu
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 1.9.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#116013](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/116013)
20
+ [`18e022766bfd3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/18e022766bfd3) -
21
+ [ux] ED-26464 Hiding primary toolbar and docking contextual toolbar items to top
22
+
3
23
  ## 1.8.1
4
24
 
5
25
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toggleToolbar = void 0;
6
+ exports.toggleToolbar = exports.setToolbarDocking = void 0;
7
7
  var _pluginKey = require("./plugin-key");
8
8
  var toggleToolbar = exports.toggleToolbar = function toggleToolbar(_ref) {
9
9
  var hide = _ref.hide;
@@ -14,4 +14,14 @@ var toggleToolbar = exports.toggleToolbar = function toggleToolbar(_ref) {
14
14
  });
15
15
  return tr;
16
16
  };
17
+ };
18
+ var setToolbarDocking = exports.setToolbarDocking = function setToolbarDocking(_ref3) {
19
+ var toolbarDocking = _ref3.toolbarDocking;
20
+ return function (_ref4) {
21
+ var tr = _ref4.tr;
22
+ tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
23
+ toolbarDocking: toolbarDocking
24
+ });
25
+ return tr;
26
+ };
17
27
  };
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.selectionToolbarPlugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _react = _interopRequireDefault(require("react"));
10
11
  var _bindEventListener = require("bind-event-listener");
11
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
13
  var _utils = require("@atlaskit/editor-common/utils");
@@ -15,25 +16,61 @@ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
15
16
  var _commands = require("./pm-plugins/commands");
16
17
  var _pluginKey = require("./pm-plugins/plugin-key");
17
18
  var _overflowToolbarConfig = require("./ui/overflow-toolbar-config");
19
+ var _PrimaryToolbarComponent = require("./ui/PrimaryToolbarComponent");
18
20
  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
21
  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; }
20
- var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selectionToolbarPlugin(options) {
22
+ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selectionToolbarPlugin(_ref) {
23
+ var api = _ref.api,
24
+ config = _ref.config;
21
25
  var __selectionToolbarHandlers = [];
26
+ var primaryToolbarComponent;
27
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
28
+ exposure: true
29
+ })) {
30
+ var _api$primaryToolbar;
31
+ primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
32
+ var popupsBoundariesElement = _ref2.popupsBoundariesElement,
33
+ popupsMountPoint = _ref2.popupsMountPoint,
34
+ popupsScrollableElement = _ref2.popupsScrollableElement;
35
+ return /*#__PURE__*/_react.default.createElement(_PrimaryToolbarComponent.PrimaryToolbarComponent, {
36
+ api: api,
37
+ popupsBoundariesElement: popupsBoundariesElement,
38
+ popupsMountPoint: popupsMountPoint,
39
+ popupsScrollableElement: popupsScrollableElement
40
+ });
41
+ };
42
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
43
+ name: 'overflowMenu',
44
+ component: primaryToolbarComponent
45
+ });
46
+ }
22
47
  return {
23
48
  name: 'selectionToolbar',
24
49
  actions: {
25
50
  suppressToolbar: function suppressToolbar() {
26
- var _options$api$core$act, _options$api;
27
- return (_options$api$core$act = (_options$api = options.api) === null || _options$api === void 0 ? void 0 : _options$api.core.actions.execute((0, _commands.toggleToolbar)({
51
+ var _api$core$actions$exe;
52
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute((0, _commands.toggleToolbar)({
28
53
  hide: true
29
- }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
54
+ }))) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
30
55
  },
31
56
  unsuppressToolbar: function unsuppressToolbar() {
32
- var _options$api$core$act2, _options$api2;
33
- return (_options$api$core$act2 = (_options$api2 = options.api) === null || _options$api2 === void 0 ? void 0 : _options$api2.core.actions.execute((0, _commands.toggleToolbar)({
57
+ var _api$core$actions$exe2;
58
+ return (_api$core$actions$exe2 = api === null || api === void 0 ? void 0 : api.core.actions.execute((0, _commands.toggleToolbar)({
34
59
  hide: false
35
- }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
60
+ }))) !== null && _api$core$actions$exe2 !== void 0 ? _api$core$actions$exe2 : false;
61
+ },
62
+ setToolbarDocking: function setToolbarDocking(toolbarDocking) {
63
+ var _api$core$actions$exe3;
64
+ return (_api$core$actions$exe3 = api === null || api === void 0 ? void 0 : api.core.actions.execute((0, _commands.setToolbarDocking)({
65
+ toolbarDocking: toolbarDocking
66
+ }))) !== null && _api$core$actions$exe3 !== void 0 ? _api$core$actions$exe3 : false;
67
+ }
68
+ },
69
+ getSharedState: function getSharedState(editorState) {
70
+ if (!editorState) {
71
+ return;
36
72
  }
73
+ return _pluginKey.selectionToolbarPluginKey.getState(editorState);
37
74
  },
38
75
  pmPlugins: function pmPlugins(selectionToolbarHandlers) {
39
76
  if (selectionToolbarHandlers) {
@@ -48,7 +85,8 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
48
85
  init: function init() {
49
86
  return {
50
87
  selectionStable: false,
51
- hide: false
88
+ hide: false,
89
+ toolbarDocking: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? 'none' : 'top'
52
90
  };
53
91
  },
54
92
  apply: function apply(tr, pluginState) {
@@ -63,12 +101,12 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
63
101
  var unbind = (0, _bindEventListener.bind)(_view.root, {
64
102
  type: 'mouseup',
65
103
  listener: function listener() {
66
- var _options$api3;
104
+ var _api$editorViewMode;
67
105
  // We only want to set selectionStable to true if the editor has focus
68
106
  // to prevent the toolbar from showing when the editor is blurred
69
107
  // due to a click outside the editor.
70
108
 
71
- var editorViewModePlugin = (_options$api3 = options.api) === null || _options$api3 === void 0 || (_options$api3 = _options$api3.editorViewMode) === null || _options$api3 === void 0 ? void 0 : _options$api3.sharedState.currentState();
109
+ var editorViewModePlugin = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
72
110
  var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
73
111
  _view.dispatch(_view.state.tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
74
112
  selectionStable: !isViewModeEnabled ? _view.hasFocus() : true
@@ -129,11 +167,11 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
129
167
  // they add to the selection toolbar.
130
168
  // ie. if you want to have your plugin's group appear first, set rank to -10 if there is currently another
131
169
  // plugin you expect to be run at the same time as with an rank of -9
132
- resolved.sort(function (_ref, _ref2) {
133
- var _ref$rank = _ref.rank,
134
- rankA = _ref$rank === void 0 ? 0 : _ref$rank;
135
- var _ref2$rank = _ref2.rank,
136
- rankB = _ref2$rank === void 0 ? 0 : _ref2$rank;
170
+ resolved.sort(function (_ref3, _ref4) {
171
+ var _ref3$rank = _ref3.rank,
172
+ rankA = _ref3$rank === void 0 ? 0 : _ref3$rank;
173
+ var _ref4$rank = _ref4.rank,
174
+ rankB = _ref4$rank === void 0 ? 0 : _ref4$rank;
137
175
  if (rankA < rankB) {
138
176
  return 1;
139
177
  }
@@ -168,9 +206,11 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
168
206
  }
169
207
  }
170
208
  if (items.length > 0 && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
171
- items.push.apply(items, (0, _toConsumableArray2.default)(_overflowToolbarConfig.overflowToolbarConfig));
209
+ items.push.apply(items, (0, _toConsumableArray2.default)((0, _overflowToolbarConfig.getOverflowFloatingToolbarConfig)({
210
+ api: api
211
+ })));
172
212
  }
173
- var calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? _utils.calculateToolbarPositionAboveSelection : _utils.calculateToolbarPositionTrackHead;
213
+ var calcToolbarPosition = config.preferenceToolbarAboveSelection ? _utils.calculateToolbarPositionAboveSelection : _utils.calculateToolbarPositionTrackHead;
174
214
  var toolbarTitle = 'Selection toolbar';
175
215
  var onPositionCalculated = calcToolbarPosition(toolbarTitle);
176
216
  var nodeType = getSelectionNodeTypes(state);
@@ -181,7 +221,10 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
181
221
  onPositionCalculated: onPositionCalculated
182
222
  };
183
223
  }
184
- }
224
+ },
225
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
226
+ exposure: true
227
+ }) ? primaryToolbarComponent : undefined
185
228
  };
186
229
  };
187
230
  function getSelectionNodeTypes(state) {
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PrimaryToolbarComponent = PrimaryToolbarComponent;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
13
+ var _showMoreHorizontal = _interopRequireDefault(require("@atlaskit/icon/core/show-more-horizontal"));
14
+ var _overflowToolbarConfig = require("./overflow-toolbar-config");
15
+ /**
16
+ * @jsxRuntime classic
17
+ * @jsx jsx
18
+ * @jsxFrag
19
+ */
20
+
21
+ // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
22
+
23
+ var DROPDOWN_WIDTH = 240;
24
+ function PrimaryToolbarComponent(_ref) {
25
+ var api = _ref.api,
26
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
27
+ popupsMountPoint = _ref.popupsMountPoint,
28
+ popupsScrollableElement = _ref.popupsScrollableElement;
29
+ var _useState = (0, _react.useState)(false),
30
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
31
+ isOpen = _useState2[0],
32
+ setIsOpen = _useState2[1];
33
+ var items = (0, _react.useMemo)(function () {
34
+ return (0, _overflowToolbarConfig.getOverflowPrimaryToolbarConfig)({
35
+ api: api
36
+ });
37
+ }, [api]);
38
+ var content = 'Show more items';
39
+ var onClick = (0, _react.useCallback)(function () {
40
+ setIsOpen(!isOpen);
41
+ }, [isOpen]);
42
+ var onMenuItemActivated = (0, _react.useCallback)(function (_ref2) {
43
+ var _item$onClick;
44
+ var item = _ref2.item;
45
+ item === null || item === void 0 || (_item$onClick = item.onClick) === null || _item$onClick === void 0 || _item$onClick.call(item);
46
+ }, []);
47
+ return (0, _react2.jsx)(_uiMenu.DropdownMenu, {
48
+ isOpen: isOpen,
49
+ onOpenChange: function onOpenChange(attrs) {
50
+ return setIsOpen(attrs.isOpen);
51
+ },
52
+ items: items,
53
+ arrowKeyNavigationProviderOptions: {
54
+ type: _uiMenu.ArrowKeyNavigationType.MENU
55
+ },
56
+ boundariesElement: popupsBoundariesElement,
57
+ mountTo: popupsMountPoint,
58
+ scrollableElement: popupsScrollableElement,
59
+ section: {
60
+ hasSeparator: true
61
+ },
62
+ onItemActivated: onMenuItemActivated,
63
+ fitWidth: DROPDOWN_WIDTH
64
+ }, (0, _react2.jsx)(_uiMenu.ToolbarButton, {
65
+ onClick: onClick,
66
+ "aria-haspopup": "dialog",
67
+ "aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.addLink),
68
+ "aria-label": content,
69
+ testId: content,
70
+ spacing: "default",
71
+ title: content
72
+ // eslint-disable-next-line @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
73
+ ,
74
+ css: buttonStyles
75
+ }, (0, _react2.jsx)(_showMoreHorizontal.default, {
76
+ label: "Show more items"
77
+ })));
78
+ }
79
+ var buttonStyles = (0, _react2.css)({
80
+ padding: "var(--ds-space-075, 6px)"
81
+ });
@@ -1,38 +1,88 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.overflowToolbarConfig = void 0;
8
- var _react = _interopRequireDefault(require("react"));
6
+ exports.getOverflowPrimaryToolbarConfig = exports.getOverflowFloatingToolbarConfig = void 0;
7
+ var _react = require("@emotion/react");
8
+ var _menu = require("@atlaskit/menu");
9
9
  var _ContextualToolbarIcon = require("./icons/ContextualToolbarIcon");
10
10
  var _FixedToolbarIcon = require("./icons/FixedToolbarIcon");
11
+ /**
12
+ * @jsxRuntime classic
13
+ * @jsx jsx
14
+ * @jsxFrag
15
+ */
16
+ // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
17
+
11
18
  // New editor controls
12
- var overflowToolbarConfig = exports.overflowToolbarConfig = [{
13
- type: 'separator'
14
- }, {
15
- type: 'overflow-dropdown',
16
- options: [{
19
+ var getOverflowFloatingToolbarConfig = exports.getOverflowFloatingToolbarConfig = function getOverflowFloatingToolbarConfig(_ref) {
20
+ var api = _ref.api;
21
+ return [{
17
22
  type: 'separator'
18
23
  }, {
19
- type: 'overflow-dropdown-heading',
20
- title: 'Toolbar position'
21
- }, {
22
- title: 'Contextual',
23
- onClick: function onClick() {
24
- return true;
25
- },
26
- icon: /*#__PURE__*/_react.default.createElement(_ContextualToolbarIcon.ContextualToolbarIcon, {
27
- label: "Contextual toolbar"
28
- })
29
- }, {
30
- title: 'Fixed at top',
31
- onClick: function onClick() {
32
- return true;
33
- },
34
- icon: /*#__PURE__*/_react.default.createElement(_FixedToolbarIcon.FixedToolbarIcon, {
35
- label: "Fixed toolbar"
36
- })
37
- }]
38
- }];
24
+ type: 'overflow-dropdown',
25
+ options: [{
26
+ type: 'separator'
27
+ }, {
28
+ type: 'overflow-dropdown-heading',
29
+ title: 'Toolbar position'
30
+ }, {
31
+ title: 'Contextual',
32
+ onClick: function onClick() {
33
+ var _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
34
+ return (_api$selectionToolbar = api === null || api === void 0 || (_api$selectionToolbar2 = api.selectionToolbar.actions) === null || _api$selectionToolbar2 === void 0 || (_api$selectionToolbar3 = _api$selectionToolbar2.setToolbarDocking) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.call(_api$selectionToolbar2, 'none')) !== null && _api$selectionToolbar !== void 0 ? _api$selectionToolbar : false;
35
+ },
36
+ icon: (0, _react.jsx)(_ContextualToolbarIcon.ContextualToolbarIcon, {
37
+ label: "Contextual toolbar"
38
+ })
39
+ }, {
40
+ title: 'Fixed at top',
41
+ onClick: function onClick() {
42
+ var _api$selectionToolbar4, _api$selectionToolbar5, _api$selectionToolbar6;
43
+ return (_api$selectionToolbar4 = api === null || api === void 0 || (_api$selectionToolbar5 = api.selectionToolbar.actions) === null || _api$selectionToolbar5 === void 0 || (_api$selectionToolbar6 = _api$selectionToolbar5.setToolbarDocking) === null || _api$selectionToolbar6 === void 0 ? void 0 : _api$selectionToolbar6.call(_api$selectionToolbar5, 'top')) !== null && _api$selectionToolbar4 !== void 0 ? _api$selectionToolbar4 : false;
44
+ },
45
+ icon: (0, _react.jsx)(_FixedToolbarIcon.FixedToolbarIcon, {
46
+ label: "Fixed toolbar"
47
+ })
48
+ }]
49
+ }];
50
+ };
51
+ var getOverflowPrimaryToolbarConfig = exports.getOverflowPrimaryToolbarConfig = function getOverflowPrimaryToolbarConfig(_ref2) {
52
+ var api = _ref2.api;
53
+ return [{
54
+ items: [{
55
+ content:
56
+ // eslint-disable-next-line @atlaskit/design-system/use-primitives
57
+ (0, _react.jsx)("div", {
58
+ css: headingContainerStyles
59
+ }, (0, _react.jsx)(_menu.HeadingItem, null, "Toolbar position")),
60
+ value: {
61
+ name: ''
62
+ },
63
+ isDisabled: true
64
+ }, {
65
+ content: 'Contextual',
66
+ value: {
67
+ name: 'contextual'
68
+ },
69
+ onClick: function onClick() {
70
+ var _api$selectionToolbar7, _api$selectionToolbar8, _api$selectionToolbar9;
71
+ return (_api$selectionToolbar7 = api === null || api === void 0 || (_api$selectionToolbar8 = api.selectionToolbar.actions) === null || _api$selectionToolbar8 === void 0 || (_api$selectionToolbar9 = _api$selectionToolbar8.setToolbarDocking) === null || _api$selectionToolbar9 === void 0 ? void 0 : _api$selectionToolbar9.call(_api$selectionToolbar8, 'none')) !== null && _api$selectionToolbar7 !== void 0 ? _api$selectionToolbar7 : false;
72
+ }
73
+ }, {
74
+ content: 'Fixed at top',
75
+ value: {
76
+ name: 'fixed'
77
+ },
78
+ onClick: function onClick() {
79
+ var _api$selectionToolbar10, _api$selectionToolbar11, _api$selectionToolbar12;
80
+ return (_api$selectionToolbar10 = api === null || api === void 0 || (_api$selectionToolbar11 = api.selectionToolbar.actions) === null || _api$selectionToolbar11 === void 0 || (_api$selectionToolbar12 = _api$selectionToolbar11.setToolbarDocking) === null || _api$selectionToolbar12 === void 0 ? void 0 : _api$selectionToolbar12.call(_api$selectionToolbar11, 'top')) !== null && _api$selectionToolbar10 !== void 0 ? _api$selectionToolbar10 : false;
81
+ }
82
+ }]
83
+ }];
84
+ };
85
+ var headingContainerStyles = (0, _react.css)({
86
+ padding: "var(--ds-space-100, 8px)".concat(" 0"),
87
+ margin: "var(--ds-space-negative-100, -8px)".concat(" 0")
88
+ });
@@ -8,4 +8,14 @@ export const toggleToolbar = ({
8
8
  hide
9
9
  });
10
10
  return tr;
11
+ };
12
+ export const setToolbarDocking = ({
13
+ toolbarDocking
14
+ }) => ({
15
+ tr
16
+ }) => {
17
+ tr.setMeta(selectionToolbarPluginKey, {
18
+ toolbarDocking
19
+ });
20
+ return tr;
11
21
  };
@@ -1,28 +1,65 @@
1
+ import React from 'react';
1
2
  import { bind } from 'bind-event-listener';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
4
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
- import { toggleToolbar } from './pm-plugins/commands';
7
+ import { setToolbarDocking, toggleToolbar } from './pm-plugins/commands';
7
8
  import { selectionToolbarPluginKey } from './pm-plugins/plugin-key';
8
- import { overflowToolbarConfig } from './ui/overflow-toolbar-config';
9
- export const selectionToolbarPlugin = options => {
9
+ import { getOverflowFloatingToolbarConfig } from './ui/overflow-toolbar-config';
10
+ import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
11
+ export const selectionToolbarPlugin = ({
12
+ api,
13
+ config
14
+ }) => {
10
15
  const __selectionToolbarHandlers = [];
16
+ let primaryToolbarComponent;
17
+ if (editorExperiment('platform_editor_controls', 'variant1', {
18
+ exposure: true
19
+ })) {
20
+ var _api$primaryToolbar;
21
+ primaryToolbarComponent = ({
22
+ popupsBoundariesElement,
23
+ popupsMountPoint,
24
+ popupsScrollableElement
25
+ }) => /*#__PURE__*/React.createElement(PrimaryToolbarComponent, {
26
+ api: api,
27
+ popupsBoundariesElement: popupsBoundariesElement,
28
+ popupsMountPoint: popupsMountPoint,
29
+ popupsScrollableElement: popupsScrollableElement
30
+ });
31
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
32
+ name: 'overflowMenu',
33
+ component: primaryToolbarComponent
34
+ });
35
+ }
11
36
  return {
12
37
  name: 'selectionToolbar',
13
38
  actions: {
14
39
  suppressToolbar: () => {
15
- var _options$api$core$act, _options$api;
16
- return (_options$api$core$act = (_options$api = options.api) === null || _options$api === void 0 ? void 0 : _options$api.core.actions.execute(toggleToolbar({
40
+ var _api$core$actions$exe;
41
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleToolbar({
17
42
  hide: true
18
- }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
43
+ }))) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
19
44
  },
20
45
  unsuppressToolbar: () => {
21
- var _options$api$core$act2, _options$api2;
22
- return (_options$api$core$act2 = (_options$api2 = options.api) === null || _options$api2 === void 0 ? void 0 : _options$api2.core.actions.execute(toggleToolbar({
46
+ var _api$core$actions$exe2;
47
+ return (_api$core$actions$exe2 = api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleToolbar({
23
48
  hide: false
24
- }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
49
+ }))) !== null && _api$core$actions$exe2 !== void 0 ? _api$core$actions$exe2 : false;
50
+ },
51
+ setToolbarDocking: toolbarDocking => {
52
+ var _api$core$actions$exe3;
53
+ return (_api$core$actions$exe3 = api === null || api === void 0 ? void 0 : api.core.actions.execute(setToolbarDocking({
54
+ toolbarDocking
55
+ }))) !== null && _api$core$actions$exe3 !== void 0 ? _api$core$actions$exe3 : false;
56
+ }
57
+ },
58
+ getSharedState(editorState) {
59
+ if (!editorState) {
60
+ return;
25
61
  }
62
+ return selectionToolbarPluginKey.getState(editorState);
26
63
  },
27
64
  pmPlugins(selectionToolbarHandlers) {
28
65
  if (selectionToolbarHandlers) {
@@ -37,7 +74,8 @@ export const selectionToolbarPlugin = options => {
37
74
  init() {
38
75
  return {
39
76
  selectionStable: false,
40
- hide: false
77
+ hide: false,
78
+ toolbarDocking: editorExperiment('platform_editor_controls', 'variant1') ? 'none' : 'top'
41
79
  };
42
80
  },
43
81
  apply(tr, pluginState) {
@@ -55,12 +93,12 @@ export const selectionToolbarPlugin = options => {
55
93
  const unbind = bind(view.root, {
56
94
  type: 'mouseup',
57
95
  listener: () => {
58
- var _options$api3, _options$api3$editorV;
96
+ var _api$editorViewMode;
59
97
  // We only want to set selectionStable to true if the editor has focus
60
98
  // to prevent the toolbar from showing when the editor is blurred
61
99
  // due to a click outside the editor.
62
100
 
63
- const editorViewModePlugin = (_options$api3 = options.api) === null || _options$api3 === void 0 ? void 0 : (_options$api3$editorV = _options$api3.editorViewMode) === null || _options$api3$editorV === void 0 ? void 0 : _options$api3$editorV.sharedState.currentState();
101
+ const editorViewModePlugin = api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
64
102
  const isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
65
103
  view.dispatch(view.state.tr.setMeta(selectionToolbarPluginKey, {
66
104
  selectionStable: !isViewModeEnabled ? view.hasFocus() : true
@@ -157,9 +195,11 @@ export const selectionToolbarPlugin = options => {
157
195
  }
158
196
  }
159
197
  if (items.length > 0 && editorExperiment('platform_editor_controls', 'variant1')) {
160
- items.push(...overflowToolbarConfig);
198
+ items.push(...getOverflowFloatingToolbarConfig({
199
+ api
200
+ }));
161
201
  }
162
- const calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
202
+ const calcToolbarPosition = config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
163
203
  const toolbarTitle = 'Selection toolbar';
164
204
  const onPositionCalculated = calcToolbarPosition(toolbarTitle);
165
205
  const nodeType = getSelectionNodeTypes(state);
@@ -170,7 +210,10 @@ export const selectionToolbarPlugin = options => {
170
210
  onPositionCalculated
171
211
  };
172
212
  }
173
- }
213
+ },
214
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'variant1', {
215
+ exposure: true
216
+ }) ? primaryToolbarComponent : undefined
174
217
  };
175
218
  };
176
219
  function getSelectionNodeTypes(state) {
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ * @jsxFrag
5
+ */
6
+ import { useCallback, useMemo, useState } from 'react';
7
+ import { css, jsx } from '@emotion/react'; // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
8
+
9
+ import { addLink, getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
10
+ import { ArrowKeyNavigationType, DropdownMenu, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
11
+ import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
12
+ import { getOverflowPrimaryToolbarConfig } from './overflow-toolbar-config';
13
+ const DROPDOWN_WIDTH = 240;
14
+ export function PrimaryToolbarComponent({
15
+ api,
16
+ popupsBoundariesElement,
17
+ popupsMountPoint,
18
+ popupsScrollableElement
19
+ }) {
20
+ const [isOpen, setIsOpen] = useState(false);
21
+ const items = useMemo(() => getOverflowPrimaryToolbarConfig({
22
+ api
23
+ }), [api]);
24
+ const content = 'Show more items';
25
+ const onClick = useCallback(() => {
26
+ setIsOpen(!isOpen);
27
+ }, [isOpen]);
28
+ const onMenuItemActivated = useCallback(({
29
+ item
30
+ }) => {
31
+ var _item$onClick;
32
+ item === null || item === void 0 ? void 0 : (_item$onClick = item.onClick) === null || _item$onClick === void 0 ? void 0 : _item$onClick.call(item);
33
+ }, []);
34
+ return jsx(DropdownMenu, {
35
+ isOpen: isOpen,
36
+ onOpenChange: attrs => setIsOpen(attrs.isOpen),
37
+ items: items,
38
+ arrowKeyNavigationProviderOptions: {
39
+ type: ArrowKeyNavigationType.MENU
40
+ },
41
+ boundariesElement: popupsBoundariesElement,
42
+ mountTo: popupsMountPoint,
43
+ scrollableElement: popupsScrollableElement,
44
+ section: {
45
+ hasSeparator: true
46
+ },
47
+ onItemActivated: onMenuItemActivated,
48
+ fitWidth: DROPDOWN_WIDTH
49
+ }, jsx(ToolbarButton, {
50
+ onClick: onClick,
51
+ "aria-haspopup": "dialog",
52
+ "aria-keyshortcuts": getAriaKeyshortcuts(addLink),
53
+ "aria-label": content,
54
+ testId: content,
55
+ spacing: "default",
56
+ title: content
57
+ // eslint-disable-next-line @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
58
+ ,
59
+ css: buttonStyles
60
+ }, jsx(ShowMoreHorizontalIcon, {
61
+ label: "Show more items"
62
+ })));
63
+ }
64
+ const buttonStyles = css({
65
+ padding: "var(--ds-space-075, 6px)"
66
+ });
@@ -1,9 +1,17 @@
1
- import React from 'react';
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ * @jsxFrag
5
+ */
6
+ import { css, jsx } from '@emotion/react'; // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
7
+
8
+ import { HeadingItem } from '@atlaskit/menu';
2
9
  import { ContextualToolbarIcon } from './icons/ContextualToolbarIcon';
3
10
  import { FixedToolbarIcon } from './icons/FixedToolbarIcon';
4
-
5
11
  // New editor controls
6
- export const overflowToolbarConfig = [{
12
+ export const getOverflowFloatingToolbarConfig = ({
13
+ api
14
+ }) => [{
7
15
  type: 'separator'
8
16
  }, {
9
17
  type: 'overflow-dropdown',
@@ -15,18 +23,57 @@ export const overflowToolbarConfig = [{
15
23
  }, {
16
24
  title: 'Contextual',
17
25
  onClick: () => {
18
- return true;
26
+ var _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
27
+ return (_api$selectionToolbar = api === null || api === void 0 ? void 0 : (_api$selectionToolbar2 = api.selectionToolbar.actions) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.setToolbarDocking) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.call(_api$selectionToolbar2, 'none')) !== null && _api$selectionToolbar !== void 0 ? _api$selectionToolbar : false;
19
28
  },
20
- icon: /*#__PURE__*/React.createElement(ContextualToolbarIcon, {
29
+ icon: jsx(ContextualToolbarIcon, {
21
30
  label: "Contextual toolbar"
22
31
  })
23
32
  }, {
24
33
  title: 'Fixed at top',
25
34
  onClick: () => {
26
- return true;
35
+ var _api$selectionToolbar4, _api$selectionToolbar5, _api$selectionToolbar6;
36
+ return (_api$selectionToolbar4 = api === null || api === void 0 ? void 0 : (_api$selectionToolbar5 = api.selectionToolbar.actions) === null || _api$selectionToolbar5 === void 0 ? void 0 : (_api$selectionToolbar6 = _api$selectionToolbar5.setToolbarDocking) === null || _api$selectionToolbar6 === void 0 ? void 0 : _api$selectionToolbar6.call(_api$selectionToolbar5, 'top')) !== null && _api$selectionToolbar4 !== void 0 ? _api$selectionToolbar4 : false;
27
37
  },
28
- icon: /*#__PURE__*/React.createElement(FixedToolbarIcon, {
38
+ icon: jsx(FixedToolbarIcon, {
29
39
  label: "Fixed toolbar"
30
40
  })
31
41
  }]
32
- }];
42
+ }];
43
+ export const getOverflowPrimaryToolbarConfig = ({
44
+ api
45
+ }) => [{
46
+ items: [{
47
+ content:
48
+ // eslint-disable-next-line @atlaskit/design-system/use-primitives
49
+ jsx("div", {
50
+ css: headingContainerStyles
51
+ }, jsx(HeadingItem, null, "Toolbar position")),
52
+ value: {
53
+ name: ''
54
+ },
55
+ isDisabled: true
56
+ }, {
57
+ content: 'Contextual',
58
+ value: {
59
+ name: 'contextual'
60
+ },
61
+ onClick: () => {
62
+ var _api$selectionToolbar7, _api$selectionToolbar8, _api$selectionToolbar9;
63
+ return (_api$selectionToolbar7 = api === null || api === void 0 ? void 0 : (_api$selectionToolbar8 = api.selectionToolbar.actions) === null || _api$selectionToolbar8 === void 0 ? void 0 : (_api$selectionToolbar9 = _api$selectionToolbar8.setToolbarDocking) === null || _api$selectionToolbar9 === void 0 ? void 0 : _api$selectionToolbar9.call(_api$selectionToolbar8, 'none')) !== null && _api$selectionToolbar7 !== void 0 ? _api$selectionToolbar7 : false;
64
+ }
65
+ }, {
66
+ content: 'Fixed at top',
67
+ value: {
68
+ name: 'fixed'
69
+ },
70
+ onClick: () => {
71
+ var _api$selectionToolbar10, _api$selectionToolbar11, _api$selectionToolbar12;
72
+ return (_api$selectionToolbar10 = api === null || api === void 0 ? void 0 : (_api$selectionToolbar11 = api.selectionToolbar.actions) === null || _api$selectionToolbar11 === void 0 ? void 0 : (_api$selectionToolbar12 = _api$selectionToolbar11.setToolbarDocking) === null || _api$selectionToolbar12 === void 0 ? void 0 : _api$selectionToolbar12.call(_api$selectionToolbar11, 'top')) !== null && _api$selectionToolbar10 !== void 0 ? _api$selectionToolbar10 : false;
73
+ }
74
+ }]
75
+ }];
76
+ const headingContainerStyles = css({
77
+ padding: `${"var(--ds-space-100, 8px)"} 0`,
78
+ margin: `${"var(--ds-space-negative-100, -8px)"} 0`
79
+ });
@@ -8,4 +8,14 @@ export var toggleToolbar = function toggleToolbar(_ref) {
8
8
  });
9
9
  return tr;
10
10
  };
11
+ };
12
+ export var setToolbarDocking = function setToolbarDocking(_ref3) {
13
+ var toolbarDocking = _ref3.toolbarDocking;
14
+ return function (_ref4) {
15
+ var tr = _ref4.tr;
16
+ tr.setMeta(selectionToolbarPluginKey, {
17
+ toolbarDocking: toolbarDocking
18
+ });
19
+ return tr;
20
+ };
11
21
  };
@@ -2,31 +2,68 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  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; }
4
4
  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; }
5
+ import React from 'react';
5
6
  import { bind } from 'bind-event-listener';
6
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
8
  import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
8
9
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
- import { toggleToolbar } from './pm-plugins/commands';
11
+ import { setToolbarDocking as _setToolbarDocking, toggleToolbar } from './pm-plugins/commands';
11
12
  import { selectionToolbarPluginKey } from './pm-plugins/plugin-key';
12
- import { overflowToolbarConfig } from './ui/overflow-toolbar-config';
13
- export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
13
+ import { getOverflowFloatingToolbarConfig } from './ui/overflow-toolbar-config';
14
+ import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
15
+ export var selectionToolbarPlugin = function selectionToolbarPlugin(_ref) {
16
+ var api = _ref.api,
17
+ config = _ref.config;
14
18
  var __selectionToolbarHandlers = [];
19
+ var primaryToolbarComponent;
20
+ if (editorExperiment('platform_editor_controls', 'variant1', {
21
+ exposure: true
22
+ })) {
23
+ var _api$primaryToolbar;
24
+ primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
25
+ var popupsBoundariesElement = _ref2.popupsBoundariesElement,
26
+ popupsMountPoint = _ref2.popupsMountPoint,
27
+ popupsScrollableElement = _ref2.popupsScrollableElement;
28
+ return /*#__PURE__*/React.createElement(PrimaryToolbarComponent, {
29
+ api: api,
30
+ popupsBoundariesElement: popupsBoundariesElement,
31
+ popupsMountPoint: popupsMountPoint,
32
+ popupsScrollableElement: popupsScrollableElement
33
+ });
34
+ };
35
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
36
+ name: 'overflowMenu',
37
+ component: primaryToolbarComponent
38
+ });
39
+ }
15
40
  return {
16
41
  name: 'selectionToolbar',
17
42
  actions: {
18
43
  suppressToolbar: function suppressToolbar() {
19
- var _options$api$core$act, _options$api;
20
- return (_options$api$core$act = (_options$api = options.api) === null || _options$api === void 0 ? void 0 : _options$api.core.actions.execute(toggleToolbar({
44
+ var _api$core$actions$exe;
45
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleToolbar({
21
46
  hide: true
22
- }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
47
+ }))) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
23
48
  },
24
49
  unsuppressToolbar: function unsuppressToolbar() {
25
- var _options$api$core$act2, _options$api2;
26
- return (_options$api$core$act2 = (_options$api2 = options.api) === null || _options$api2 === void 0 ? void 0 : _options$api2.core.actions.execute(toggleToolbar({
50
+ var _api$core$actions$exe2;
51
+ return (_api$core$actions$exe2 = api === null || api === void 0 ? void 0 : api.core.actions.execute(toggleToolbar({
27
52
  hide: false
28
- }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
53
+ }))) !== null && _api$core$actions$exe2 !== void 0 ? _api$core$actions$exe2 : false;
54
+ },
55
+ setToolbarDocking: function setToolbarDocking(toolbarDocking) {
56
+ var _api$core$actions$exe3;
57
+ return (_api$core$actions$exe3 = api === null || api === void 0 ? void 0 : api.core.actions.execute(_setToolbarDocking({
58
+ toolbarDocking: toolbarDocking
59
+ }))) !== null && _api$core$actions$exe3 !== void 0 ? _api$core$actions$exe3 : false;
60
+ }
61
+ },
62
+ getSharedState: function getSharedState(editorState) {
63
+ if (!editorState) {
64
+ return;
29
65
  }
66
+ return selectionToolbarPluginKey.getState(editorState);
30
67
  },
31
68
  pmPlugins: function pmPlugins(selectionToolbarHandlers) {
32
69
  if (selectionToolbarHandlers) {
@@ -41,7 +78,8 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
41
78
  init: function init() {
42
79
  return {
43
80
  selectionStable: false,
44
- hide: false
81
+ hide: false,
82
+ toolbarDocking: editorExperiment('platform_editor_controls', 'variant1') ? 'none' : 'top'
45
83
  };
46
84
  },
47
85
  apply: function apply(tr, pluginState) {
@@ -56,12 +94,12 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
56
94
  var unbind = bind(_view.root, {
57
95
  type: 'mouseup',
58
96
  listener: function listener() {
59
- var _options$api3;
97
+ var _api$editorViewMode;
60
98
  // We only want to set selectionStable to true if the editor has focus
61
99
  // to prevent the toolbar from showing when the editor is blurred
62
100
  // due to a click outside the editor.
63
101
 
64
- var editorViewModePlugin = (_options$api3 = options.api) === null || _options$api3 === void 0 || (_options$api3 = _options$api3.editorViewMode) === null || _options$api3 === void 0 ? void 0 : _options$api3.sharedState.currentState();
102
+ var editorViewModePlugin = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState();
65
103
  var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
66
104
  _view.dispatch(_view.state.tr.setMeta(selectionToolbarPluginKey, {
67
105
  selectionStable: !isViewModeEnabled ? _view.hasFocus() : true
@@ -122,11 +160,11 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
122
160
  // they add to the selection toolbar.
123
161
  // ie. if you want to have your plugin's group appear first, set rank to -10 if there is currently another
124
162
  // plugin you expect to be run at the same time as with an rank of -9
125
- resolved.sort(function (_ref, _ref2) {
126
- var _ref$rank = _ref.rank,
127
- rankA = _ref$rank === void 0 ? 0 : _ref$rank;
128
- var _ref2$rank = _ref2.rank,
129
- rankB = _ref2$rank === void 0 ? 0 : _ref2$rank;
163
+ resolved.sort(function (_ref3, _ref4) {
164
+ var _ref3$rank = _ref3.rank,
165
+ rankA = _ref3$rank === void 0 ? 0 : _ref3$rank;
166
+ var _ref4$rank = _ref4.rank,
167
+ rankB = _ref4$rank === void 0 ? 0 : _ref4$rank;
130
168
  if (rankA < rankB) {
131
169
  return 1;
132
170
  }
@@ -161,9 +199,11 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
161
199
  }
162
200
  }
163
201
  if (items.length > 0 && editorExperiment('platform_editor_controls', 'variant1')) {
164
- items.push.apply(items, _toConsumableArray(overflowToolbarConfig));
202
+ items.push.apply(items, _toConsumableArray(getOverflowFloatingToolbarConfig({
203
+ api: api
204
+ })));
165
205
  }
166
- var calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
206
+ var calcToolbarPosition = config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
167
207
  var toolbarTitle = 'Selection toolbar';
168
208
  var onPositionCalculated = calcToolbarPosition(toolbarTitle);
169
209
  var nodeType = getSelectionNodeTypes(state);
@@ -174,7 +214,10 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
174
214
  onPositionCalculated: onPositionCalculated
175
215
  };
176
216
  }
177
- }
217
+ },
218
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'variant1', {
219
+ exposure: true
220
+ }) ? primaryToolbarComponent : undefined
178
221
  };
179
222
  };
180
223
  function getSelectionNodeTypes(state) {
@@ -0,0 +1,72 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /**
3
+ * @jsxRuntime classic
4
+ * @jsx jsx
5
+ * @jsxFrag
6
+ */
7
+ import { useCallback, useMemo, useState } from 'react';
8
+ import { css, jsx } from '@emotion/react'; // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
9
+
10
+ import { addLink, getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
11
+ import { ArrowKeyNavigationType, DropdownMenu, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
12
+ import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
13
+ import { getOverflowPrimaryToolbarConfig } from './overflow-toolbar-config';
14
+ var DROPDOWN_WIDTH = 240;
15
+ export function PrimaryToolbarComponent(_ref) {
16
+ var api = _ref.api,
17
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
18
+ popupsMountPoint = _ref.popupsMountPoint,
19
+ popupsScrollableElement = _ref.popupsScrollableElement;
20
+ var _useState = useState(false),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ isOpen = _useState2[0],
23
+ setIsOpen = _useState2[1];
24
+ var items = useMemo(function () {
25
+ return getOverflowPrimaryToolbarConfig({
26
+ api: api
27
+ });
28
+ }, [api]);
29
+ var content = 'Show more items';
30
+ var onClick = useCallback(function () {
31
+ setIsOpen(!isOpen);
32
+ }, [isOpen]);
33
+ var onMenuItemActivated = useCallback(function (_ref2) {
34
+ var _item$onClick;
35
+ var item = _ref2.item;
36
+ item === null || item === void 0 || (_item$onClick = item.onClick) === null || _item$onClick === void 0 || _item$onClick.call(item);
37
+ }, []);
38
+ return jsx(DropdownMenu, {
39
+ isOpen: isOpen,
40
+ onOpenChange: function onOpenChange(attrs) {
41
+ return setIsOpen(attrs.isOpen);
42
+ },
43
+ items: items,
44
+ arrowKeyNavigationProviderOptions: {
45
+ type: ArrowKeyNavigationType.MENU
46
+ },
47
+ boundariesElement: popupsBoundariesElement,
48
+ mountTo: popupsMountPoint,
49
+ scrollableElement: popupsScrollableElement,
50
+ section: {
51
+ hasSeparator: true
52
+ },
53
+ onItemActivated: onMenuItemActivated,
54
+ fitWidth: DROPDOWN_WIDTH
55
+ }, jsx(ToolbarButton, {
56
+ onClick: onClick,
57
+ "aria-haspopup": "dialog",
58
+ "aria-keyshortcuts": getAriaKeyshortcuts(addLink),
59
+ "aria-label": content,
60
+ testId: content,
61
+ spacing: "default",
62
+ title: content
63
+ // eslint-disable-next-line @atlaskit/design-system/no-unsafe-style-overrides -- Ignored via go/DSP-18766
64
+ ,
65
+ css: buttonStyles
66
+ }, jsx(ShowMoreHorizontalIcon, {
67
+ label: "Show more items"
68
+ })));
69
+ }
70
+ var buttonStyles = css({
71
+ padding: "var(--ds-space-075, 6px)"
72
+ });
@@ -1,32 +1,81 @@
1
- import React from 'react';
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ * @jsxFrag
5
+ */
6
+ import { css, jsx } from '@emotion/react'; // eslint-disable-line @atlaskit/ui-styling-standard/use-compiled
7
+
8
+ import { HeadingItem } from '@atlaskit/menu';
2
9
  import { ContextualToolbarIcon } from './icons/ContextualToolbarIcon';
3
10
  import { FixedToolbarIcon } from './icons/FixedToolbarIcon';
4
-
5
11
  // New editor controls
6
- export var overflowToolbarConfig = [{
7
- type: 'separator'
8
- }, {
9
- type: 'overflow-dropdown',
10
- options: [{
12
+ export var getOverflowFloatingToolbarConfig = function getOverflowFloatingToolbarConfig(_ref) {
13
+ var api = _ref.api;
14
+ return [{
11
15
  type: 'separator'
12
16
  }, {
13
- type: 'overflow-dropdown-heading',
14
- title: 'Toolbar position'
15
- }, {
16
- title: 'Contextual',
17
- onClick: function onClick() {
18
- return true;
19
- },
20
- icon: /*#__PURE__*/React.createElement(ContextualToolbarIcon, {
21
- label: "Contextual toolbar"
22
- })
23
- }, {
24
- title: 'Fixed at top',
25
- onClick: function onClick() {
26
- return true;
27
- },
28
- icon: /*#__PURE__*/React.createElement(FixedToolbarIcon, {
29
- label: "Fixed toolbar"
30
- })
31
- }]
32
- }];
17
+ type: 'overflow-dropdown',
18
+ options: [{
19
+ type: 'separator'
20
+ }, {
21
+ type: 'overflow-dropdown-heading',
22
+ title: 'Toolbar position'
23
+ }, {
24
+ title: 'Contextual',
25
+ onClick: function onClick() {
26
+ var _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
27
+ return (_api$selectionToolbar = api === null || api === void 0 || (_api$selectionToolbar2 = api.selectionToolbar.actions) === null || _api$selectionToolbar2 === void 0 || (_api$selectionToolbar3 = _api$selectionToolbar2.setToolbarDocking) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.call(_api$selectionToolbar2, 'none')) !== null && _api$selectionToolbar !== void 0 ? _api$selectionToolbar : false;
28
+ },
29
+ icon: jsx(ContextualToolbarIcon, {
30
+ label: "Contextual toolbar"
31
+ })
32
+ }, {
33
+ title: 'Fixed at top',
34
+ onClick: function onClick() {
35
+ var _api$selectionToolbar4, _api$selectionToolbar5, _api$selectionToolbar6;
36
+ return (_api$selectionToolbar4 = api === null || api === void 0 || (_api$selectionToolbar5 = api.selectionToolbar.actions) === null || _api$selectionToolbar5 === void 0 || (_api$selectionToolbar6 = _api$selectionToolbar5.setToolbarDocking) === null || _api$selectionToolbar6 === void 0 ? void 0 : _api$selectionToolbar6.call(_api$selectionToolbar5, 'top')) !== null && _api$selectionToolbar4 !== void 0 ? _api$selectionToolbar4 : false;
37
+ },
38
+ icon: jsx(FixedToolbarIcon, {
39
+ label: "Fixed toolbar"
40
+ })
41
+ }]
42
+ }];
43
+ };
44
+ export var getOverflowPrimaryToolbarConfig = function getOverflowPrimaryToolbarConfig(_ref2) {
45
+ var api = _ref2.api;
46
+ return [{
47
+ items: [{
48
+ content:
49
+ // eslint-disable-next-line @atlaskit/design-system/use-primitives
50
+ jsx("div", {
51
+ css: headingContainerStyles
52
+ }, jsx(HeadingItem, null, "Toolbar position")),
53
+ value: {
54
+ name: ''
55
+ },
56
+ isDisabled: true
57
+ }, {
58
+ content: 'Contextual',
59
+ value: {
60
+ name: 'contextual'
61
+ },
62
+ onClick: function onClick() {
63
+ var _api$selectionToolbar7, _api$selectionToolbar8, _api$selectionToolbar9;
64
+ return (_api$selectionToolbar7 = api === null || api === void 0 || (_api$selectionToolbar8 = api.selectionToolbar.actions) === null || _api$selectionToolbar8 === void 0 || (_api$selectionToolbar9 = _api$selectionToolbar8.setToolbarDocking) === null || _api$selectionToolbar9 === void 0 ? void 0 : _api$selectionToolbar9.call(_api$selectionToolbar8, 'none')) !== null && _api$selectionToolbar7 !== void 0 ? _api$selectionToolbar7 : false;
65
+ }
66
+ }, {
67
+ content: 'Fixed at top',
68
+ value: {
69
+ name: 'fixed'
70
+ },
71
+ onClick: function onClick() {
72
+ var _api$selectionToolbar10, _api$selectionToolbar11, _api$selectionToolbar12;
73
+ return (_api$selectionToolbar10 = api === null || api === void 0 || (_api$selectionToolbar11 = api.selectionToolbar.actions) === null || _api$selectionToolbar11 === void 0 || (_api$selectionToolbar12 = _api$selectionToolbar11.setToolbarDocking) === null || _api$selectionToolbar12 === void 0 ? void 0 : _api$selectionToolbar12.call(_api$selectionToolbar11, 'top')) !== null && _api$selectionToolbar10 !== void 0 ? _api$selectionToolbar10 : false;
74
+ }
75
+ }]
76
+ }];
77
+ };
78
+ var headingContainerStyles = css({
79
+ padding: "var(--ds-space-100, 8px)".concat(" 0"),
80
+ margin: "var(--ds-space-negative-100, -8px)".concat(" 0")
81
+ });
@@ -1,4 +1,8 @@
1
1
  import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ import type { ToolbarDocking } from '../types';
2
3
  export declare const toggleToolbar: ({ hide }: {
3
4
  hide: boolean;
4
5
  }) => EditorCommand;
6
+ export declare const setToolbarDocking: ({ toolbarDocking }: {
7
+ toolbarDocking: ToolbarDocking;
8
+ }) => EditorCommand;
@@ -1,15 +1,21 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
3
+ import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
+ import type { ToolbarDocking } from './types';
3
5
  export type SelectionToolbarPlugin = NextEditorPlugin<'selectionToolbar', {
6
+ sharedState: {
7
+ toolbarDocking: ToolbarDocking;
8
+ };
4
9
  pluginConfiguration: {
5
10
  /**
6
11
  * Defaults to false
7
12
  */
8
13
  preferenceToolbarAboveSelection?: boolean;
9
14
  };
10
- dependencies: [OptionalPlugin<EditorViewModePlugin>];
15
+ dependencies: [OptionalPlugin<EditorViewModePlugin>, OptionalPlugin<PrimaryToolbarPlugin>];
11
16
  actions?: {
12
17
  suppressToolbar?: () => boolean;
13
18
  unsuppressToolbar?: () => boolean;
19
+ setToolbarDocking?: (toolbarDocking: ToolbarDocking) => boolean;
14
20
  };
15
21
  }>;
@@ -4,3 +4,4 @@ export type SelectionToolbarPluginOptions = {
4
4
  */
5
5
  preferenceToolbarAboveSelection?: boolean;
6
6
  };
7
+ export type ToolbarDocking = 'top' | 'none';
@@ -0,0 +1,11 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { SelectionToolbarPlugin } from '../selectionToolbarPluginType';
4
+ type Props = {
5
+ api?: ExtractInjectionAPI<SelectionToolbarPlugin>;
6
+ popupsBoundariesElement?: HTMLElement;
7
+ popupsMountPoint?: HTMLElement;
8
+ popupsScrollableElement?: HTMLElement;
9
+ };
10
+ export declare function PrimaryToolbarComponent({ api, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, }: Props): jsx.JSX.Element;
11
+ export {};
@@ -1,2 +1,12 @@
1
1
  import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
2
- export declare const overflowToolbarConfig: FloatingToolbarItem<Command>[];
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
4
+ import type { SelectionToolbarPlugin } from '../selectionToolbarPluginType';
5
+ type OverflowToobarConfigOptions = {
6
+ api?: ExtractInjectionAPI<SelectionToolbarPlugin>;
7
+ };
8
+ export declare const getOverflowFloatingToolbarConfig: ({ api, }: OverflowToobarConfigOptions) => FloatingToolbarItem<Command>[];
9
+ export declare const getOverflowPrimaryToolbarConfig: ({ api, }: OverflowToobarConfigOptions) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export {};
@@ -1,4 +1,8 @@
1
1
  import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ import type { ToolbarDocking } from '../types';
2
3
  export declare const toggleToolbar: ({ hide }: {
3
4
  hide: boolean;
4
5
  }) => EditorCommand;
6
+ export declare const setToolbarDocking: ({ toolbarDocking }: {
7
+ toolbarDocking: ToolbarDocking;
8
+ }) => EditorCommand;
@@ -1,6 +1,11 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
3
+ import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
+ import type { ToolbarDocking } from './types';
3
5
  export type SelectionToolbarPlugin = NextEditorPlugin<'selectionToolbar', {
6
+ sharedState: {
7
+ toolbarDocking: ToolbarDocking;
8
+ };
4
9
  pluginConfiguration: {
5
10
  /**
6
11
  * Defaults to false
@@ -8,10 +13,12 @@ export type SelectionToolbarPlugin = NextEditorPlugin<'selectionToolbar', {
8
13
  preferenceToolbarAboveSelection?: boolean;
9
14
  };
10
15
  dependencies: [
11
- OptionalPlugin<EditorViewModePlugin>
16
+ OptionalPlugin<EditorViewModePlugin>,
17
+ OptionalPlugin<PrimaryToolbarPlugin>
12
18
  ];
13
19
  actions?: {
14
20
  suppressToolbar?: () => boolean;
15
21
  unsuppressToolbar?: () => boolean;
22
+ setToolbarDocking?: (toolbarDocking: ToolbarDocking) => boolean;
16
23
  };
17
24
  }>;
@@ -4,3 +4,4 @@ export type SelectionToolbarPluginOptions = {
4
4
  */
5
5
  preferenceToolbarAboveSelection?: boolean;
6
6
  };
7
+ export type ToolbarDocking = 'top' | 'none';
@@ -0,0 +1,11 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { SelectionToolbarPlugin } from '../selectionToolbarPluginType';
4
+ type Props = {
5
+ api?: ExtractInjectionAPI<SelectionToolbarPlugin>;
6
+ popupsBoundariesElement?: HTMLElement;
7
+ popupsMountPoint?: HTMLElement;
8
+ popupsScrollableElement?: HTMLElement;
9
+ };
10
+ export declare function PrimaryToolbarComponent({ api, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, }: Props): jsx.JSX.Element;
11
+ export {};
@@ -1,2 +1,12 @@
1
1
  import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
2
- export declare const overflowToolbarConfig: FloatingToolbarItem<Command>[];
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
4
+ import type { SelectionToolbarPlugin } from '../selectionToolbarPluginType';
5
+ type OverflowToobarConfigOptions = {
6
+ api?: ExtractInjectionAPI<SelectionToolbarPlugin>;
7
+ };
8
+ export declare const getOverflowFloatingToolbarConfig: ({ api, }: OverflowToobarConfigOptions) => FloatingToolbarItem<Command>[];
9
+ export declare const getOverflowPrimaryToolbarConfig: ({ api, }: OverflowToobarConfigOptions) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-toolbar",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "description": "@atlaskit/editor-plugin-selection-toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,8 +31,9 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^99.18.0",
34
+ "@atlaskit/editor-common": "^99.19.0",
35
35
  "@atlaskit/editor-plugin-editor-viewmode": "^2.2.0",
36
+ "@atlaskit/editor-plugin-primary-toolbar": "^2.4.0",
36
37
  "@atlaskit/editor-prosemirror": "7.0.0",
37
38
  "@atlaskit/platform-feature-flags": "^1.1.0",
38
39
  "@atlaskit/tmp-editor-statsig": "^2.47.0",