@atlaskit/editor-plugin-toolbar 3.2.1 → 3.3.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 (32) hide show
  1. package/CHANGELOG.md +23 -3
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +3 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/dist/cjs/pm-plugins/experiences/ContextualToolbarOpenExperience.js +73 -0
  10. package/dist/cjs/toolbarPlugin.js +17 -1
  11. package/dist/cjs/ui/SelectionToolbar/index.js +66 -93
  12. package/dist/cjs/ui/SelectionToolbar/keyboard-config.js +70 -0
  13. package/dist/cjs/ui/SelectionToolbar/utils.js +42 -0
  14. package/dist/es2019/pm-plugins/experiences/ContextualToolbarOpenExperience.js +61 -0
  15. package/dist/es2019/toolbarPlugin.js +16 -3
  16. package/dist/es2019/ui/SelectionToolbar/index.js +63 -91
  17. package/dist/es2019/ui/SelectionToolbar/keyboard-config.js +64 -0
  18. package/dist/es2019/ui/SelectionToolbar/utils.js +36 -0
  19. package/dist/esm/pm-plugins/experiences/ContextualToolbarOpenExperience.js +66 -0
  20. package/dist/esm/toolbarPlugin.js +19 -3
  21. package/dist/esm/ui/SelectionToolbar/index.js +64 -91
  22. package/dist/esm/ui/SelectionToolbar/keyboard-config.js +64 -0
  23. package/dist/esm/ui/SelectionToolbar/utils.js +36 -0
  24. package/dist/types/pm-plugins/experiences/ContextualToolbarOpenExperience.d.ts +5 -0
  25. package/dist/types/ui/SelectionToolbar/index.d.ts +2 -1
  26. package/dist/types/ui/SelectionToolbar/keyboard-config.d.ts +6 -0
  27. package/dist/types/ui/SelectionToolbar/utils.d.ts +3 -0
  28. package/dist/types-ts4.5/pm-plugins/experiences/ContextualToolbarOpenExperience.d.ts +5 -0
  29. package/dist/types-ts4.5/ui/SelectionToolbar/index.d.ts +2 -1
  30. package/dist/types-ts4.5/ui/SelectionToolbar/keyboard-config.d.ts +6 -0
  31. package/dist/types-ts4.5/ui/SelectionToolbar/utils.d.ts +3 -0
  32. package/package.json +13 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @atlaskit/editor-plugin-toolbar
2
2
 
3
+ ## 3.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`916133ef0c6dd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/916133ef0c6dd) -
8
+ [ux] Editor experience tracking foundation
9
+ - [`4f5569bde5e64`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4f5569bde5e64) -
10
+ Add new 'dragHandleSelected' user intent, use this to control table toolbar when drag handle is
11
+ selected
12
+ - Updated dependencies
13
+
14
+ ## 3.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [`d3e3f3fdb9cee`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d3e3f3fdb9cee) -
19
+ Add new selection toolbar type to event, add errorboundary for selection toolbar and try/catch
20
+ blocks with log exceptions to sentry
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+
3
26
  ## 3.2.1
4
27
 
5
28
  ### Patch Changes
@@ -273,7 +296,6 @@
273
296
 
274
297
  - [`286abb4d35eba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/286abb4d35eba) -
275
298
  [ux] [ED-28960] Finish full page primary toolbar migration
276
-
277
299
  - Align with design update (separator, gap, height, icon size)
278
300
  - Add keyboard shortcut to focus toolbar and arrow key navigation
279
301
  - Address accessibility
@@ -311,7 +333,6 @@
311
333
 
312
334
  - [`3145f278b1f7a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3145f278b1f7a) -
313
335
  [ux] [ED-28473] minor UI updates for editor-toolbar
314
-
315
336
  - Use ADS ButtonGroup for ToolbarButtonGroup
316
337
  - Remove groupLocation prop and use CSS instead
317
338
  - Use DropdownItemGroup for ToolbarDropdownItemSection and expand props for section separator and
@@ -343,7 +364,6 @@
343
364
  [`22cab8325fc62`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22cab8325fc62) -
344
365
  [ux] [ED-28760] Fix editor lose focus and hence editing flow is interrupted. This is done for 2
345
366
  components
346
-
347
367
  - Dropdown
348
368
  - Create context ToolbarUIContext for toolbar consumers to access consumer specific state and
349
369
  callbacks
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-cc/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-cc/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-dev-agents/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-dev-agents/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-dev-agents/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-jira/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-jira/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-jira/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-passionfruit/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-passionfruit/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-passionfruit/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-post-office/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-post-office/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-post-office/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-rovo-extension/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-rovo-extension/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-rovo-extension/tsconfig.json"
49
52
  },
@@ -44,6 +44,9 @@
44
44
  {
45
45
  "path": "../../editor-toolbar-model/afm-townsquare/tsconfig.json"
46
46
  },
47
+ {
48
+ "path": "../../../platform/feature-flags/afm-townsquare/tsconfig.json"
49
+ },
47
50
  {
48
51
  "path": "../../../platform/feature-flags-react/afm-townsquare/tsconfig.json"
49
52
  },
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _experiences = require("@atlaskit/editor-common/experiences");
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _state = require("@atlaskit/editor-prosemirror/state");
12
+ 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; }
13
+ 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; }
14
+ var pluginKey = new _state.PluginKey('contextualToolbarOpenExperience');
15
+ var _default = exports.default = function _default() {
16
+ var contextualToolbarOpenExperience = new _experiences.Experience('platform-editor-contextual-toolbar-open-experience', {
17
+ checks: [new _experiences.ExperienceCheckTimeout(500), new _experiences.ExperienceCheckDomMutation({
18
+ onDomMutation: function onDomMutation(_ref) {
19
+ var mutations = _ref.mutations;
20
+ if (mutations.some(isMutationAddingContextualToolbar)) {
21
+ return {
22
+ status: 'success'
23
+ };
24
+ }
25
+ },
26
+ observeConfig: function observeConfig() {
27
+ return {
28
+ target: document.body,
29
+ options: {
30
+ childList: true,
31
+ subtree: true
32
+ }
33
+ };
34
+ }
35
+ })]
36
+ });
37
+ return new _safePlugin.SafePlugin({
38
+ key: pluginKey,
39
+ state: {
40
+ init: function init() {
41
+ return {
42
+ shouldShowContextualToolbar: false
43
+ };
44
+ },
45
+ apply: function apply(_tr, pluginState, _, newState) {
46
+ var isTextSelection = newState.selection instanceof _state.TextSelection;
47
+ var isNotEmptySelection = !newState.selection.empty;
48
+ var shouldShowContextualToolbar = isTextSelection && isNotEmptySelection;
49
+ if (shouldShowContextualToolbar && !pluginState.shouldShowContextualToolbar) {
50
+ contextualToolbarOpenExperience.start();
51
+ } else if (!shouldShowContextualToolbar && pluginState.shouldShowContextualToolbar) {
52
+ contextualToolbarOpenExperience.abort();
53
+ }
54
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
55
+ shouldShowContextualToolbar: shouldShowContextualToolbar
56
+ });
57
+ }
58
+ },
59
+ view: function view() {
60
+ return {
61
+ destroy: function destroy() {
62
+ contextualToolbarOpenExperience.abort();
63
+ }
64
+ };
65
+ }
66
+ });
67
+ };
68
+ var isMutationAddingContextualToolbar = function isMutationAddingContextualToolbar(mutation) {
69
+ return mutation.type === 'childList' && Array.from(mutation.addedNodes).some(nodeIncludesContextualToolbar);
70
+ };
71
+ var nodeIncludesContextualToolbar = function nodeIncludesContextualToolbar(node) {
72
+ return node instanceof HTMLElement && node.getAttribute('data-testid') === 'popup-wrapper' && node.querySelector('[data-testid="text-section"]');
73
+ };
@@ -6,13 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.toolbarPlugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
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 _state = require("@atlaskit/editor-prosemirror/state");
13
14
  var _utils = require("@atlaskit/editor-prosemirror/utils");
14
15
  var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
16
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
17
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
18
+ var _ContextualToolbarOpenExperience = _interopRequireDefault(require("./pm-plugins/experiences/ContextualToolbarOpenExperience"));
16
19
  var _pluginKey = require("./pm-plugins/plugin-key");
17
20
  var _consts = require("./ui/consts");
18
21
  var _SelectionToolbar = require("./ui/SelectionToolbar");
@@ -176,7 +179,12 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
176
179
  }
177
180
  });
178
181
  }
179
- }];
182
+ }].concat((0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_experience_tracking', 'isEnabled', true) ? [{
183
+ name: 'contextualToolbarOpenExperience',
184
+ plugin: function plugin() {
185
+ return (0, _ContextualToolbarOpenExperience.default)();
186
+ }
187
+ }] : []));
180
188
  },
181
189
  contentComponent: !disableSelectionToolbar ? function (_ref2) {
182
190
  var editorView = _ref2.editorView,
@@ -184,6 +192,14 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
184
192
  if (!editorView) {
185
193
  return null;
186
194
  }
195
+ if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_patch_7')) {
196
+ return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbarWithErrorBoundary, {
197
+ api: api,
198
+ editorView: editorView,
199
+ mountPoint: popupsMountPoint,
200
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned !== null && disableSelectionToolbarWhenPinned !== void 0 ? disableSelectionToolbarWhenPinned : false
201
+ });
202
+ }
187
203
  return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbar, {
188
204
  api: api,
189
205
  editorView: editorView,
@@ -4,26 +4,28 @@ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.SelectionToolbar = void 0;
7
+ exports.SelectionToolbarWithErrorBoundary = exports.SelectionToolbar = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _reactIntlNext = require("react-intl-next");
10
- var _browserApis = require("@atlaskit/browser-apis");
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _coreUtils = require("@atlaskit/editor-common/core-utils");
12
+ var _errorBoundary = require("@atlaskit/editor-common/error-boundary");
12
13
  var _hooks = require("@atlaskit/editor-common/hooks");
13
- var _messages = require("@atlaskit/editor-common/messages");
14
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
14
15
  var _toolbar = require("@atlaskit/editor-common/toolbar");
15
16
  var _ui = require("@atlaskit/editor-common/ui");
16
17
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
17
18
  var _utils = require("@atlaskit/editor-common/utils");
18
19
  var _state = require("@atlaskit/editor-prosemirror/state");
19
- var _utils2 = require("@atlaskit/editor-prosemirror/utils");
20
20
  var _editorToolbar = require("@atlaskit/editor-toolbar");
21
21
  var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
22
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
23
  var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
23
24
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
24
25
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
25
26
  var _consts = require("../consts");
26
- var _toolbar2 = require("../utils/toolbar");
27
+ var _keyboardConfig = require("./keyboard-config");
28
+ var _utils2 = require("./utils");
27
29
  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); }
28
30
  var isToolbarComponent = function isToolbarComponent(component) {
29
31
  return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
@@ -67,6 +69,42 @@ var usePluginState = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(fun
67
69
  selectedNode: selectedNode
68
70
  };
69
71
  });
72
+ var useOnPositionCalculated = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(function () {
73
+ return (0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_patch_7');
74
+ }, function (editorView) {
75
+ var onPositionCalculated = (0, _react.useCallback)(function (position) {
76
+ try {
77
+ var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
78
+
79
+ // Show special position on cell selection only when editor controls experiment is enabled
80
+ var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
81
+ var isCellSelection = ('$anchorCell' in editorView.state.selection);
82
+ if (isCellSelection && isEditorControlsEnabled) {
83
+ return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
84
+ }
85
+ return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
86
+ } catch (error) {
87
+ (0, _monitoring.logException)(error, {
88
+ location: 'editor-plugin-toolbar/selectionToolbar'
89
+ });
90
+ return position;
91
+ }
92
+ }, [editorView]);
93
+ return onPositionCalculated;
94
+ }, function (editorView) {
95
+ var onPositionCalculated = (0, _react.useCallback)(function (position) {
96
+ var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
97
+
98
+ // Show special position on cell selection only when editor controls experiment is enabled
99
+ var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
100
+ var isCellSelection = ('$anchorCell' in editorView.state.selection);
101
+ if (isCellSelection && isEditorControlsEnabled) {
102
+ return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
103
+ }
104
+ return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
105
+ }, [editorView]);
106
+ return onPositionCalculated;
107
+ });
70
108
  var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
71
109
  var _api$toolbar;
72
110
  var api = _ref.api,
@@ -86,7 +124,7 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
86
124
  return isToolbarComponent(component);
87
125
  });
88
126
  var keyboardNavigation = (0, _react.useMemo)(function () {
89
- return getKeyboardNavigationConfig(editorView, intl, api);
127
+ return (0, _keyboardConfig.getKeyboardNavigationConfig)(editorView, intl, api);
90
128
  }, [editorView, intl, api]);
91
129
  var _useToolbarUI = (0, _editorToolbar.useToolbarUI)(),
92
130
  isDisabled = _useToolbarUI.isDisabled;
@@ -95,26 +133,18 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
95
133
  var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.TextSelection;
96
134
  var isAllSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.AllSelection;
97
135
  var isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
98
- var onPositionCalculated = (0, _react.useCallback)(function (position) {
99
- var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
100
-
101
- // Show special position on cell selection only when editor controls experiment is enabled
102
- var isEditorControlsEnabled = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1');
103
- var isCellSelection = ('$anchorCell' in editorView.state.selection);
104
- if (isCellSelection && isEditorControlsEnabled) {
105
- return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
106
- }
107
- return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
108
- }, [editorView]);
136
+ var onPositionCalculated = useOnPositionCalculated(editorView);
109
137
  if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && editorToolbarDockingPreference === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
110
138
  return null;
111
139
  }
112
- if (!(isTextSelection || isCellSelection || isAllSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || currentUserIntent && currentUserIntent !== 'default' || (0, _coreUtils.isSSR)()) {
140
+ if (!(isTextSelection || isCellSelection || isAllSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_user_intent_fix') ?
141
+ // hide toolbar when user intent is not default, except when it's dragHandleSelected without cell selection
142
+ currentUserIntent && currentUserIntent !== 'default' && !(currentUserIntent === 'dragHandleSelected' && !isCellSelection) : currentUserIntent && currentUserIntent !== 'default') || (0, _coreUtils.isSSR)()) {
113
143
  return null;
114
144
  }
115
145
  return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
116
146
  offset: [0, 10],
117
- target: getDomRefFromSelection(editorView),
147
+ target: (0, _utils2.getDomRefFromSelection)(editorView),
118
148
  onPositionCalculated: onPositionCalculated,
119
149
  mountTo: mountPoint
120
150
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
@@ -142,78 +172,21 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
142
172
  }
143
173
  }))));
144
174
  };
145
- var getDomRefFromSelection = function getDomRefFromSelection(view
146
- // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
147
- ) {
148
- try {
149
- // Ignored via go/ees005
150
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
151
- return (0, _utils2.findDomRefAtPos)(view.state.selection.from, view.domAtPos.bind(view));
152
- // Ignored via go/ees005
153
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
- } catch (error) {
155
- // // eslint-disable-next-line no-console
156
- // console.warn(error);
157
- // if (dispatchAnalyticsEvent) {
158
- // const payload: AnalyticsEventPayload = {
159
- // action: ACTION.ERRORED,
160
- // actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
161
- // eventType: EVENT_TYPE.OPERATIONAL,
162
- // attributes: {
163
- // component: CONTENT_COMPONENT.FLOATING_TOOLBAR,
164
- // selection: view.state.selection.toJSON(),
165
- // position: view.state.selection.from,
166
- // docSize: view.state.doc.nodeSize,
167
- // error: error.toString(),
168
- // // @ts-expect-error - Object literal may only specify known properties, 'errorStack' does not exist in type
169
- // // This error was introduced after upgrading to TypeScript 5
170
- // errorStack: error.stack || undefined,
171
- // },
172
- // };
173
- // dispatchAnalyticsEvent(payload);
174
- // }
175
- }
176
- };
177
- var getKeyboardNavigationConfig = function getKeyboardNavigationConfig(editorView, intl, api) {
178
- if (!(editorView.dom instanceof HTMLElement)) {
179
- return;
180
- }
181
- var toolbarSelector = "[data-testid='editor-floating-toolbar']";
182
- return {
183
- childComponentSelector: toolbarSelector,
184
- dom: editorView.dom,
185
- isShortcutToFocusToolbar: _toolbar2.isShortcutToFocusToolbar,
186
- handleFocus: function handleFocus(event) {
187
- var _getDocument, _filteredFocusableEle, _filteredFocusableEle2, _filteredFocusableEle3;
188
- var toolbar = (_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.querySelector(toolbarSelector);
189
- if (!(toolbar instanceof HTMLElement)) {
190
- return;
191
- }
192
- var filteredFocusableElements = (0, _toolbar2.getFocusableElements)(toolbar);
193
- (_filteredFocusableEle = filteredFocusableElements[0]) === null || _filteredFocusableEle === void 0 || _filteredFocusableEle.focus();
194
-
195
- // the button element removes the focus ring so this class adds it back
196
- if (((_filteredFocusableEle2 = filteredFocusableElements[0]) === null || _filteredFocusableEle2 === void 0 ? void 0 : _filteredFocusableEle2.tagName) === 'BUTTON') {
197
- filteredFocusableElements[0].classList.add('first-floating-toolbar-button');
198
- }
199
- (_filteredFocusableEle3 = filteredFocusableElements[0]) === null || _filteredFocusableEle3 === void 0 || _filteredFocusableEle3.scrollIntoView({
200
- behavior: 'smooth',
201
- block: 'center',
202
- inline: 'nearest'
203
- });
204
- event.preventDefault();
205
- event.stopPropagation();
206
- },
207
- handleEscape: function handleEscape(event) {
208
- var isDropdownOpen = !!document.querySelector('[data-toolbar-component="menu-section"]');
209
- if (isDropdownOpen) {
210
- return;
211
- }
212
- api === null || api === void 0 || api.core.actions.focus();
213
- event.preventDefault();
214
- event.stopPropagation();
215
- },
216
- ariaControls: _ui.EDIT_AREA_ID,
217
- ariaLabel: intl.formatMessage(_messages.fullPageMessages.toolbarLabel)
218
- };
175
+ var SelectionToolbarWithErrorBoundary = exports.SelectionToolbarWithErrorBoundary = function SelectionToolbarWithErrorBoundary(_ref2) {
176
+ var _api$analytics2;
177
+ var api = _ref2.api,
178
+ editorView = _ref2.editorView,
179
+ mountPoint = _ref2.mountPoint,
180
+ disableSelectionToolbarWhenPinned = _ref2.disableSelectionToolbarWhenPinned;
181
+ return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
182
+ component: _analytics.ACTION_SUBJECT.TOOLBAR,
183
+ componentId: _analytics.ACTION_SUBJECT_ID.SELECTION_TOOLBAR,
184
+ dispatchAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
185
+ fallbackComponent: null
186
+ }, /*#__PURE__*/_react.default.createElement(SelectionToolbar, {
187
+ api: api,
188
+ editorView: editorView,
189
+ mountPoint: mountPoint,
190
+ disableSelectionToolbarWhenPinned: disableSelectionToolbarWhenPinned
191
+ }));
219
192
  };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getKeyboardNavigationConfig = void 0;
7
+ var _browserApis = require("@atlaskit/browser-apis");
8
+ var _messages = require("@atlaskit/editor-common/messages");
9
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
10
+ var _ui = require("@atlaskit/editor-common/ui");
11
+ var _toolbar = require("../utils/toolbar");
12
+ var getKeyboardNavigationConfig = exports.getKeyboardNavigationConfig = function getKeyboardNavigationConfig(editorView, intl, api) {
13
+ if (!(editorView.dom instanceof HTMLElement)) {
14
+ return;
15
+ }
16
+ var toolbarSelector = "[data-testid='editor-floating-toolbar']";
17
+ return {
18
+ childComponentSelector: toolbarSelector,
19
+ dom: editorView.dom,
20
+ isShortcutToFocusToolbar: _toolbar.isShortcutToFocusToolbar,
21
+ handleFocus: function handleFocus(event) {
22
+ try {
23
+ var _getDocument, _filteredFocusableEle, _filteredFocusableEle2, _filteredFocusableEle3;
24
+ var toolbar = (_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.querySelector(toolbarSelector);
25
+ if (!(toolbar instanceof HTMLElement)) {
26
+ return;
27
+ }
28
+ var filteredFocusableElements = (0, _toolbar.getFocusableElements)(toolbar);
29
+ (_filteredFocusableEle = filteredFocusableElements[0]) === null || _filteredFocusableEle === void 0 || _filteredFocusableEle.focus();
30
+
31
+ // the button element removes the focus ring so this class adds it back
32
+ if (((_filteredFocusableEle2 = filteredFocusableElements[0]) === null || _filteredFocusableEle2 === void 0 ? void 0 : _filteredFocusableEle2.tagName) === 'BUTTON') {
33
+ filteredFocusableElements[0].classList.add('first-floating-toolbar-button');
34
+ }
35
+ (_filteredFocusableEle3 = filteredFocusableElements[0]) === null || _filteredFocusableEle3 === void 0 || _filteredFocusableEle3.scrollIntoView({
36
+ behavior: 'smooth',
37
+ block: 'center',
38
+ inline: 'nearest'
39
+ });
40
+ event.preventDefault();
41
+ event.stopPropagation();
42
+ } catch (error) {
43
+ if (error instanceof Error) {
44
+ (0, _monitoring.logException)(error, {
45
+ location: 'editor-plugin-toolbar/selectionToolbar'
46
+ });
47
+ }
48
+ }
49
+ },
50
+ handleEscape: function handleEscape(event) {
51
+ try {
52
+ var isDropdownOpen = !!document.querySelector('[data-toolbar-component="menu-section"]');
53
+ if (isDropdownOpen) {
54
+ return;
55
+ }
56
+ api === null || api === void 0 || api.core.actions.focus();
57
+ event.preventDefault();
58
+ event.stopPropagation();
59
+ } catch (error) {
60
+ if (error instanceof Error) {
61
+ (0, _monitoring.logException)(error, {
62
+ location: 'editor-plugin-toolbar/selectionToolbar'
63
+ });
64
+ }
65
+ }
66
+ },
67
+ ariaControls: _ui.EDIT_AREA_ID,
68
+ ariaLabel: intl.formatMessage(_messages.fullPageMessages.toolbarLabel)
69
+ };
70
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDomRefFromSelection = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
9
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
10
+ var getDomRefFromSelection = exports.getDomRefFromSelection = function getDomRefFromSelection(view, dispatchAnalyticsEvent) {
11
+ try {
12
+ var domRef = (0, _utils.findDomRefAtPos)(view.state.selection.from, view.domAtPos.bind(view));
13
+ if (domRef instanceof HTMLElement) {
14
+ return domRef;
15
+ }
16
+ throw new Error('Invalid DOM reference');
17
+ } catch (error) {
18
+ if (dispatchAnalyticsEvent) {
19
+ var payload = {
20
+ action: _analytics.ACTION.ERRORED,
21
+ actionSubject: _analytics.ACTION_SUBJECT.CONTENT_COMPONENT,
22
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
23
+ attributes: {
24
+ component: _analytics.CONTENT_COMPONENT.SELECTION_TOOLBAR,
25
+ selection: view.state.selection.toJSON(),
26
+ position: view.state.selection.from,
27
+ docSize: view.state.doc.nodeSize,
28
+ error: error instanceof Error ? error.toString() : String(error),
29
+ // @ts-expect-error - Object literal may only specify known properties, 'errorStack' does not exist in type
30
+ // This error was introduced after upgrading to TypeScript 5
31
+ errorStack: error instanceof Error ? error.stack : undefined
32
+ }
33
+ };
34
+ dispatchAnalyticsEvent(payload);
35
+ }
36
+ if (error instanceof Error) {
37
+ (0, _monitoring.logException)(error, {
38
+ location: 'editor-plugin-toolbar/selectionToolbar'
39
+ });
40
+ }
41
+ }
42
+ };
@@ -0,0 +1,61 @@
1
+ import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
4
+ const pluginKey = new PluginKey('contextualToolbarOpenExperience');
5
+ export default (() => {
6
+ const contextualToolbarOpenExperience = new Experience('platform-editor-contextual-toolbar-open-experience', {
7
+ checks: [new ExperienceCheckTimeout(500), new ExperienceCheckDomMutation({
8
+ onDomMutation: ({
9
+ mutations
10
+ }) => {
11
+ if (mutations.some(isMutationAddingContextualToolbar)) {
12
+ return {
13
+ status: 'success'
14
+ };
15
+ }
16
+ },
17
+ observeConfig: () => ({
18
+ target: document.body,
19
+ options: {
20
+ childList: true,
21
+ subtree: true
22
+ }
23
+ })
24
+ })]
25
+ });
26
+ return new SafePlugin({
27
+ key: pluginKey,
28
+ state: {
29
+ init: () => ({
30
+ shouldShowContextualToolbar: false
31
+ }),
32
+ apply: (_tr, pluginState, _, newState) => {
33
+ const isTextSelection = newState.selection instanceof TextSelection;
34
+ const isNotEmptySelection = !newState.selection.empty;
35
+ const shouldShowContextualToolbar = isTextSelection && isNotEmptySelection;
36
+ if (shouldShowContextualToolbar && !pluginState.shouldShowContextualToolbar) {
37
+ contextualToolbarOpenExperience.start();
38
+ } else if (!shouldShowContextualToolbar && pluginState.shouldShowContextualToolbar) {
39
+ contextualToolbarOpenExperience.abort();
40
+ }
41
+ return {
42
+ ...pluginState,
43
+ shouldShowContextualToolbar
44
+ };
45
+ }
46
+ },
47
+ view: () => {
48
+ return {
49
+ destroy: () => {
50
+ contextualToolbarOpenExperience.abort();
51
+ }
52
+ };
53
+ }
54
+ });
55
+ });
56
+ const isMutationAddingContextualToolbar = mutation => {
57
+ return mutation.type === 'childList' && Array.from(mutation.addedNodes).some(nodeIncludesContextualToolbar);
58
+ };
59
+ const nodeIncludesContextualToolbar = node => {
60
+ return node instanceof HTMLElement && node.getAttribute('data-testid') === 'popup-wrapper' && node.querySelector('[data-testid="text-section"]');
61
+ };