@atlaskit/editor-plugin-selection-toolbar 1.2.10 → 1.3.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,26 @@
1
1
  # @atlaskit/editor-plugin-selection-toolbar
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#159557](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/159557)
8
+ [`e4def56b93caa`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e4def56b93caa) -
9
+ [ux] 'EDF-1733: Hide selection toolbar on Define modal render, expose selection toolbar action
10
+ utilities, add AI definitions integration coverage'
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 1.2.11
17
+
18
+ ### Patch Changes
19
+
20
+ - [#155735](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/155735)
21
+ [`1beeeda29023a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1beeeda29023a) -
22
+ Upgrades editor packages to react 18
23
+
3
24
  ## 1.2.10
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toggleToolbar = void 0;
7
+ var _pluginKey = require("./plugin-key");
8
+ var toggleToolbar = exports.toggleToolbar = function toggleToolbar(_ref) {
9
+ var hide = _ref.hide;
10
+ return function (_ref2) {
11
+ var tr = _ref2.tr;
12
+ tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
13
+ hide: hide
14
+ });
15
+ return tr;
16
+ };
17
+ };
@@ -5,19 +5,37 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.selectionToolbarPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _bindEventListener = require("bind-event-listener");
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
12
  var _utils = require("@atlaskit/editor-common/utils");
13
13
  var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
15
+ var _commands = require("./commands");
14
16
  var _pluginKey = require("./plugin-key");
15
17
  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; }
16
18
  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; }
17
19
  var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selectionToolbarPlugin(options) {
18
20
  var __selectionToolbarHandlers = [];
19
- return {
20
- name: 'selectionToolbar',
21
+ return _objectSpread(_objectSpread({
22
+ name: 'selectionToolbar'
23
+ }, (0, _experiments.editorExperiment)('platform_editor_live_pages_ai_definitions', 'test') && {
24
+ actions: {
25
+ 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)({
28
+ hide: true
29
+ }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
30
+ },
31
+ 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)({
34
+ hide: false
35
+ }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
36
+ }
37
+ }
38
+ }), {}, {
21
39
  pmPlugins: function pmPlugins(selectionToolbarHandlers) {
22
40
  if (selectionToolbarHandlers) {
23
41
  __selectionToolbarHandlers.push.apply(__selectionToolbarHandlers, (0, _toConsumableArray2.default)(selectionToolbarHandlers));
@@ -30,7 +48,8 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
30
48
  state: {
31
49
  init: function init() {
32
50
  return {
33
- selectionStable: false
51
+ selectionStable: false,
52
+ hide: false
34
53
  };
35
54
  },
36
55
  apply: function apply(tr, pluginState) {
@@ -45,12 +64,12 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
45
64
  var unbind = (0, _bindEventListener.bind)(_view.root, {
46
65
  type: 'mouseup',
47
66
  listener: function listener() {
48
- var _options$api;
67
+ var _options$api3;
49
68
  // We only want to set selectionStable to true if the editor has focus
50
69
  // to prevent the toolbar from showing when the editor is blurred
51
70
  // due to a click outside the editor.
52
71
 
53
- var editorViewModePlugin = (_options$api = options.api) === null || _options$api === void 0 || (_options$api = _options$api.editorViewMode) === null || _options$api === void 0 ? void 0 : _options$api.sharedState.currentState();
72
+ 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();
54
73
  var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
55
74
  _view.dispatch(_view.state.tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
56
75
  selectionStable: !isViewModeEnabled ? _view.hasFocus() : true
@@ -89,8 +108,9 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
89
108
  pluginsOptions: {
90
109
  floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
91
110
  var _selectionToolbarPlug = _pluginKey.selectionToolbarPluginKey.getState(state),
92
- selectionStable = _selectionToolbarPlug.selectionStable;
93
- if (state.selection.empty || !selectionStable || state.selection instanceof _state.NodeSelection ||
111
+ selectionStable = _selectionToolbarPlug.selectionStable,
112
+ hide = _selectionToolbarPlug.hide;
113
+ if (state.selection.empty || !selectionStable || hide || state.selection instanceof _state.NodeSelection ||
94
114
  // $anchorCell is only available in CellSelection, this check is to
95
115
  // avoid importing CellSelection from @atlaskit/editor-tables
96
116
  '$anchorCell' in state.selection) {
@@ -144,7 +164,7 @@ var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selection
144
164
  };
145
165
  }
146
166
  }
147
- };
167
+ });
148
168
  };
149
169
  function getSelectionNodeTypes(state) {
150
170
  var selectionNodeTypes = [];
@@ -0,0 +1,11 @@
1
+ import { selectionToolbarPluginKey } from './plugin-key';
2
+ export const toggleToolbar = ({
3
+ hide
4
+ }) => ({
5
+ tr
6
+ }) => {
7
+ tr.setMeta(selectionToolbarPluginKey, {
8
+ hide
9
+ });
10
+ return tr;
11
+ };
@@ -2,11 +2,29 @@ import { bind } from 'bind-event-listener';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
+ import { toggleToolbar } from './commands';
5
7
  import { selectionToolbarPluginKey } from './plugin-key';
6
8
  export const selectionToolbarPlugin = options => {
7
9
  let __selectionToolbarHandlers = [];
8
10
  return {
9
11
  name: 'selectionToolbar',
12
+ ...(editorExperiment('platform_editor_live_pages_ai_definitions', 'test') && {
13
+ actions: {
14
+ 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({
17
+ hide: true
18
+ }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
19
+ },
20
+ 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({
23
+ hide: false
24
+ }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
25
+ }
26
+ }
27
+ }),
10
28
  pmPlugins(selectionToolbarHandlers) {
11
29
  if (selectionToolbarHandlers) {
12
30
  __selectionToolbarHandlers.push(...selectionToolbarHandlers);
@@ -19,7 +37,8 @@ export const selectionToolbarPlugin = options => {
19
37
  state: {
20
38
  init() {
21
39
  return {
22
- selectionStable: false
40
+ selectionStable: false,
41
+ hide: false
23
42
  };
24
43
  },
25
44
  apply(tr, pluginState) {
@@ -37,12 +56,12 @@ export const selectionToolbarPlugin = options => {
37
56
  const unbind = bind(view.root, {
38
57
  type: 'mouseup',
39
58
  listener: () => {
40
- var _options$api, _options$api$editorVi;
59
+ var _options$api3, _options$api3$editorV;
41
60
  // We only want to set selectionStable to true if the editor has focus
42
61
  // to prevent the toolbar from showing when the editor is blurred
43
62
  // due to a click outside the editor.
44
63
 
45
- const editorViewModePlugin = (_options$api = options.api) === null || _options$api === void 0 ? void 0 : (_options$api$editorVi = _options$api.editorViewMode) === null || _options$api$editorVi === void 0 ? void 0 : _options$api$editorVi.sharedState.currentState();
64
+ 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();
46
65
  const isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
47
66
  view.dispatch(view.state.tr.setMeta(selectionToolbarPluginKey, {
48
67
  selectionStable: !isViewModeEnabled ? view.hasFocus() : true
@@ -81,9 +100,10 @@ export const selectionToolbarPlugin = options => {
81
100
  pluginsOptions: {
82
101
  floatingToolbar(state, intl, providerFactory) {
83
102
  const {
84
- selectionStable
103
+ selectionStable,
104
+ hide
85
105
  } = selectionToolbarPluginKey.getState(state);
86
- if (state.selection.empty || !selectionStable || state.selection instanceof NodeSelection ||
106
+ if (state.selection.empty || !selectionStable || hide || state.selection instanceof NodeSelection ||
87
107
  // $anchorCell is only available in CellSelection, this check is to
88
108
  // avoid importing CellSelection from @atlaskit/editor-tables
89
109
  '$anchorCell' in state.selection) {
@@ -0,0 +1,11 @@
1
+ import { selectionToolbarPluginKey } from './plugin-key';
2
+ export var toggleToolbar = function toggleToolbar(_ref) {
3
+ var hide = _ref.hide;
4
+ return function (_ref2) {
5
+ var tr = _ref2.tr;
6
+ tr.setMeta(selectionToolbarPluginKey, {
7
+ hide: hide
8
+ });
9
+ return tr;
10
+ };
11
+ };
@@ -1,16 +1,34 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
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
5
  import { bind } from 'bind-event-listener';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
8
8
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
+ import { toggleToolbar } from './commands';
9
11
  import { selectionToolbarPluginKey } from './plugin-key';
10
12
  export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
11
13
  var __selectionToolbarHandlers = [];
12
- return {
13
- name: 'selectionToolbar',
14
+ return _objectSpread(_objectSpread({
15
+ name: 'selectionToolbar'
16
+ }, editorExperiment('platform_editor_live_pages_ai_definitions', 'test') && {
17
+ actions: {
18
+ 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({
21
+ hide: true
22
+ }))) !== null && _options$api$core$act !== void 0 ? _options$api$core$act : false;
23
+ },
24
+ 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({
27
+ hide: false
28
+ }))) !== null && _options$api$core$act2 !== void 0 ? _options$api$core$act2 : false;
29
+ }
30
+ }
31
+ }), {}, {
14
32
  pmPlugins: function pmPlugins(selectionToolbarHandlers) {
15
33
  if (selectionToolbarHandlers) {
16
34
  __selectionToolbarHandlers.push.apply(__selectionToolbarHandlers, _toConsumableArray(selectionToolbarHandlers));
@@ -23,7 +41,8 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
23
41
  state: {
24
42
  init: function init() {
25
43
  return {
26
- selectionStable: false
44
+ selectionStable: false,
45
+ hide: false
27
46
  };
28
47
  },
29
48
  apply: function apply(tr, pluginState) {
@@ -38,12 +57,12 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
38
57
  var unbind = bind(_view.root, {
39
58
  type: 'mouseup',
40
59
  listener: function listener() {
41
- var _options$api;
60
+ var _options$api3;
42
61
  // We only want to set selectionStable to true if the editor has focus
43
62
  // to prevent the toolbar from showing when the editor is blurred
44
63
  // due to a click outside the editor.
45
64
 
46
- var editorViewModePlugin = (_options$api = options.api) === null || _options$api === void 0 || (_options$api = _options$api.editorViewMode) === null || _options$api === void 0 ? void 0 : _options$api.sharedState.currentState();
65
+ 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();
47
66
  var isViewModeEnabled = (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view';
48
67
  _view.dispatch(_view.state.tr.setMeta(selectionToolbarPluginKey, {
49
68
  selectionStable: !isViewModeEnabled ? _view.hasFocus() : true
@@ -82,8 +101,9 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
82
101
  pluginsOptions: {
83
102
  floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
84
103
  var _selectionToolbarPlug = selectionToolbarPluginKey.getState(state),
85
- selectionStable = _selectionToolbarPlug.selectionStable;
86
- if (state.selection.empty || !selectionStable || state.selection instanceof NodeSelection ||
104
+ selectionStable = _selectionToolbarPlug.selectionStable,
105
+ hide = _selectionToolbarPlug.hide;
106
+ if (state.selection.empty || !selectionStable || hide || state.selection instanceof NodeSelection ||
87
107
  // $anchorCell is only available in CellSelection, this check is to
88
108
  // avoid importing CellSelection from @atlaskit/editor-tables
89
109
  '$anchorCell' in state.selection) {
@@ -137,7 +157,7 @@ export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
137
157
  };
138
158
  }
139
159
  }
140
- };
160
+ });
141
161
  };
142
162
  function getSelectionNodeTypes(state) {
143
163
  var selectionNodeTypes = [];
@@ -0,0 +1,4 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const toggleToolbar: ({ hide }: {
3
+ hide: boolean;
4
+ }) => EditorCommand;
@@ -8,5 +8,9 @@ export declare const selectionToolbarPlugin: NextEditorPlugin<'selectionToolbar'
8
8
  preferenceToolbarAboveSelection?: boolean;
9
9
  };
10
10
  dependencies: [OptionalPlugin<EditorViewModePlugin>];
11
+ actions?: {
12
+ suppressToolbar: () => boolean;
13
+ unsuppressToolbar: () => boolean;
14
+ };
11
15
  }>;
12
16
  export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
@@ -0,0 +1,4 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const toggleToolbar: ({ hide }: {
3
+ hide: boolean;
4
+ }) => EditorCommand;
@@ -10,5 +10,9 @@ export declare const selectionToolbarPlugin: NextEditorPlugin<'selectionToolbar'
10
10
  dependencies: [
11
11
  OptionalPlugin<EditorViewModePlugin>
12
12
  ];
13
+ actions?: {
14
+ suppressToolbar: () => boolean;
15
+ unsuppressToolbar: () => boolean;
16
+ };
13
17
  }>;
14
18
  export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-toolbar",
3
- "version": "1.2.10",
3
+ "version": "1.3.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,21 +31,22 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^94.0.0",
34
+ "@atlaskit/editor-common": "^94.11.0",
35
35
  "@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
36
36
  "@atlaskit/editor-prosemirror": "6.0.0",
37
+ "@atlaskit/tmp-editor-statsig": "^2.11.0",
37
38
  "@babel/runtime": "^7.0.0",
38
39
  "bind-event-listener": "^3.0.0"
39
40
  },
40
41
  "peerDependencies": {
41
- "react": "^16.8.0 || ^17.0.0 || ~18.2.0"
42
+ "react": "^16.8.0 || ^17.0.0 || ~18.2.0",
43
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.2.0"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@af/visual-regression": "*",
45
47
  "@atlaskit/ssr": "*",
46
48
  "@atlaskit/visual-regression": "*",
47
49
  "@testing-library/react": "^12.1.5",
48
- "react-dom": "^16.8.0",
49
50
  "typescript": "~5.4.2",
50
51
  "wait-for-expect": "^1.2.0"
51
52
  },