@atlaskit/editor-plugin-floating-toolbar 4.1.3 → 4.1.5

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,20 @@
1
1
  # @atlaskit/editor-plugin-floating-toolbar
2
2
 
3
+ ## 4.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#147357](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/147357)
8
+ [`1eab8cfeaf029`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1eab8cfeaf029) -
9
+ Migrate extensions and floating toolbar plugins to use useSharedPluginStateSelector hook
10
+ - Updated dependencies
11
+
12
+ ## 4.1.4
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 4.1.3
4
19
 
5
20
  ### Patch Changes
@@ -19,6 +19,7 @@ var _hooks = require("@atlaskit/editor-common/hooks");
19
19
  var _providerFactory = require("@atlaskit/editor-common/provider-factory");
20
20
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
21
21
  var _ui = require("@atlaskit/editor-common/ui");
22
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
22
23
  var _state = require("@atlaskit/editor-prosemirror/state");
23
24
  var _utils = require("@atlaskit/editor-prosemirror/utils");
24
25
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -212,6 +213,62 @@ var floatingToolbarPlugin = exports.floatingToolbarPlugin = function floatingToo
212
213
  }
213
214
  };
214
215
  };
216
+ var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (pluginInjectionApi) {
217
+ // floatingToolbar
218
+ var configWithNodeInfo = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'floatingToolbar.configWithNodeInfo');
219
+ var floatingToolbarData = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'floatingToolbar.floatingToolbarData');
220
+
221
+ // editorDisabled
222
+ var editorDisabledState = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'editorDisabled.editorDisabled');
223
+
224
+ // editorViewMode
225
+ var mode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'editorViewMode.mode');
226
+ var contentMode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'editorViewMode.contentMode');
227
+ var isConsumption = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'editorViewMode.isConsumption');
228
+
229
+ // userIntent
230
+ var currentUserIntent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'userIntent.currentUserIntent');
231
+
232
+ // blockControls
233
+ var isDragging = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi,
234
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
235
+ 'blockControls.isDragging');
236
+ // isMenuOpen
237
+ var isMenuOpen = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi,
238
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
239
+ 'blockControls.isMenuOpen');
240
+ return {
241
+ configWithNodeInfo: configWithNodeInfo,
242
+ floatingToolbarData: floatingToolbarData,
243
+ editorDisabled: editorDisabledState,
244
+ mode: mode,
245
+ contentMode: contentMode,
246
+ isConsumption: isConsumption,
247
+ currentUserIntent: currentUserIntent,
248
+ isDragging: isDragging,
249
+ isMenuOpen: isMenuOpen
250
+ };
251
+ }, function (pluginInjectionApi) {
252
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['floatingToolbar', 'editorDisabled', 'editorViewMode', 'userIntent',
253
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
254
+ 'blockControls']),
255
+ floatingToolbarState = _useSharedPluginState.floatingToolbarState,
256
+ editorDisabledState = _useSharedPluginState.editorDisabledState,
257
+ editorViewModeState = _useSharedPluginState.editorViewModeState,
258
+ userIntentState = _useSharedPluginState.userIntentState,
259
+ blockControlsState = _useSharedPluginState.blockControlsState;
260
+ return {
261
+ configWithNodeInfo: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.configWithNodeInfo,
262
+ floatingToolbarData: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.floatingToolbarData,
263
+ editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
264
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
265
+ contentMode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode,
266
+ isConsumption: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.isConsumption,
267
+ currentUserIntent: userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent,
268
+ isDragging: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging,
269
+ isMenuOpen: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isMenuOpen
270
+ };
271
+ });
215
272
  function ContentComponent(_ref5) {
216
273
  var _configWithNodeInfo$c, _configWithNodeInfo$c2, _items, _pluginInjectionApi$c, _pluginInjectionApi$d;
217
274
  var pluginInjectionApi = _ref5.pluginInjectionApi,
@@ -221,22 +278,21 @@ function ContentComponent(_ref5) {
221
278
  popupsScrollableElement = _ref5.popupsScrollableElement,
222
279
  providerFactory = _ref5.providerFactory,
223
280
  dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent;
224
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['floatingToolbar', 'editorDisabled', 'editorViewMode', 'userIntent',
225
- // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
226
- 'blockControls']),
227
- floatingToolbarState = _useSharedPluginState.floatingToolbarState,
228
- editorDisabledState = _useSharedPluginState.editorDisabledState,
229
- editorViewModeState = _useSharedPluginState.editorViewModeState,
230
- userIntentState = _useSharedPluginState.userIntentState,
231
- blockControlsState = _useSharedPluginState.blockControlsState;
232
- var _ref6 = floatingToolbarState !== null && floatingToolbarState !== void 0 ? floatingToolbarState : {},
233
- configWithNodeInfo = _ref6.configWithNodeInfo,
234
- floatingToolbarData = _ref6.floatingToolbarData;
281
+ var _useSharedState = useSharedState(pluginInjectionApi),
282
+ configWithNodeInfo = _useSharedState.configWithNodeInfo,
283
+ contentMode = _useSharedState.contentMode,
284
+ currentUserIntent = _useSharedState.currentUserIntent,
285
+ editorDisabled = _useSharedState.editorDisabled,
286
+ floatingToolbarData = _useSharedState.floatingToolbarData,
287
+ isConsumption = _useSharedState.isConsumption,
288
+ isDragging = _useSharedState.isDragging,
289
+ isMenuOpen = _useSharedState.isMenuOpen,
290
+ mode = _useSharedState.mode;
235
291
  if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
236
292
  return null;
237
293
  }
238
294
  if ((0, _platformFeatureFlags.fg)('platform_editor_user_intent_plugin')) {
239
- if ((userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent) === 'dragging') {
295
+ if (currentUserIntent === 'dragging') {
240
296
  return null;
241
297
  }
242
298
 
@@ -245,10 +301,10 @@ function ContentComponent(_ref5) {
245
301
  // return null;
246
302
  // }
247
303
  } else {
248
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isDragging) {
304
+ if (isDragging) {
249
305
  return null;
250
306
  }
251
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isMenuOpen && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
307
+ if (isMenuOpen && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
252
308
  return null;
253
309
  }
254
310
  }
@@ -284,9 +340,8 @@ function ContentComponent(_ref5) {
284
340
  _config$stick = config.stick,
285
341
  stick = _config$stick === void 0 ? true : _config$stick;
286
342
  var targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
287
- var isEditorDisabled = editorDisabledState && editorDisabledState.editorDisabled;
288
- var isInViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
289
- if (!targetRef || isEditorDisabled && !isInViewMode) {
343
+ var isInViewMode = mode === 'view';
344
+ if (!targetRef || editorDisabled && !isInViewMode) {
290
345
  return null;
291
346
  }
292
347
 
@@ -336,7 +391,7 @@ function ContentComponent(_ref5) {
336
391
  }
337
392
  });
338
393
  if (!(0, _experiments.editorExperiment)('live_pages_graceful_edit', 'control') && viewModeToolbarEntry !== 'none') {
339
- if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode) === 'live-edit' && editorViewModeState !== null && editorViewModeState !== void 0 && editorViewModeState.isConsumption) {
394
+ if (contentMode === 'live-edit' && isConsumption) {
340
395
  var hasOtherToolbarItems = toolbarItems && toolbarItems.length !== 0;
341
396
  var shouldAddToolbarItems = viewModeToolbarEntry === 'expand-existing-only' ? hasOtherToolbarItems : true;
342
397
  if (shouldAddToolbarItems) {
@@ -372,8 +427,8 @@ function ContentComponent(_ref5) {
372
427
  };
373
428
 
374
429
  // Confirm dialog
375
- var _ref7 = floatingToolbarData || {},
376
- confirmDialogForItem = _ref7.confirmDialogForItem;
430
+ var _ref6 = floatingToolbarData || {},
431
+ confirmDialogForItem = _ref6.confirmDialogForItem;
377
432
  var confirmButtonItem = confirmDialogForItem ?
378
433
  // Ignored via go/ees005
379
434
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -13,6 +13,7 @@ var _new = require("@atlaskit/button/new");
13
13
  var _hooks = require("@atlaskit/editor-common/hooks");
14
14
  var _ui = require("@atlaskit/editor-common/ui");
15
15
  var _uiReact = require("@atlaskit/editor-common/ui-react");
16
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
16
17
  var _emoji = require("@atlaskit/emoji");
17
18
  var _emojiAdd = _interopRequireDefault(require("@atlaskit/icon/core/emoji-add"));
18
19
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -62,11 +63,17 @@ var emojiPickerButtonWrapperVisualRefresh = (0, _react2.css)({
62
63
  }
63
64
  }
64
65
  });
65
- var EmojiPickerWithProvider = function EmojiPickerWithProvider(props) {
66
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(props.pluginInjectionApi, ['emoji']),
66
+ var useEmojiProvider = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
67
+ var emojiProvider = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'emoji.emojiProvider');
68
+ return emojiProvider ? Promise.resolve(emojiProvider) : undefined;
69
+ }, function (api) {
70
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['emoji']),
67
71
  emojiState = _useSharedPluginState.emojiState;
72
+ return emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState.emojiProvider) : undefined;
73
+ });
74
+ var EmojiPickerWithProvider = function EmojiPickerWithProvider(props) {
75
+ var emojiProvider = useEmojiProvider(props.pluginInjectionApi);
68
76
  var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
69
- var emojiProvider = emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider) : undefined;
70
77
  if (!emojiProvider) {
71
78
  return null;
72
79
  }
@@ -2,10 +2,11 @@ import React from 'react';
2
2
  import camelCase from 'lodash/camelCase';
3
3
  import { ACTION, ACTION_SUBJECT, CONTENT_COMPONENT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
4
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
5
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
6
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
7
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
8
  import { Popup } from '@atlaskit/editor-common/ui';
9
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
10
  import { AllSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
10
11
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
11
12
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -195,16 +196,42 @@ export const floatingToolbarPlugin = ({
195
196
  }
196
197
  };
197
198
  };
198
- export function ContentComponent({
199
- pluginInjectionApi,
200
- editorView,
201
- popupsMountPoint,
202
- popupsBoundariesElement,
203
- popupsScrollableElement,
204
- providerFactory,
205
- dispatchAnalyticsEvent
206
- }) {
207
- var _configWithNodeInfo$c, _configWithNodeInfo$c2, _items, _pluginInjectionApi$c, _pluginInjectionApi$d;
199
+ const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
200
+ // floatingToolbar
201
+ const configWithNodeInfo = useSharedPluginStateSelector(pluginInjectionApi, 'floatingToolbar.configWithNodeInfo');
202
+ const floatingToolbarData = useSharedPluginStateSelector(pluginInjectionApi, 'floatingToolbar.floatingToolbarData');
203
+
204
+ // editorDisabled
205
+ const editorDisabledState = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled');
206
+
207
+ // editorViewMode
208
+ const mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
209
+ const contentMode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.contentMode');
210
+ const isConsumption = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.isConsumption');
211
+
212
+ // userIntent
213
+ const currentUserIntent = useSharedPluginStateSelector(pluginInjectionApi, 'userIntent.currentUserIntent');
214
+
215
+ // blockControls
216
+ const isDragging = useSharedPluginStateSelector(pluginInjectionApi,
217
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
218
+ 'blockControls.isDragging');
219
+ // isMenuOpen
220
+ const isMenuOpen = useSharedPluginStateSelector(pluginInjectionApi,
221
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
222
+ 'blockControls.isMenuOpen');
223
+ return {
224
+ configWithNodeInfo,
225
+ floatingToolbarData,
226
+ editorDisabled: editorDisabledState,
227
+ mode,
228
+ contentMode,
229
+ isConsumption,
230
+ currentUserIntent,
231
+ isDragging,
232
+ isMenuOpen
233
+ };
234
+ }, pluginInjectionApi => {
208
235
  const {
209
236
  floatingToolbarState,
210
237
  editorDisabledState,
@@ -215,15 +242,44 @@ export function ContentComponent({
215
242
  } = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorDisabled', 'editorViewMode', 'userIntent',
216
243
  // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
217
244
  'blockControls']);
245
+ return {
246
+ configWithNodeInfo: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.configWithNodeInfo,
247
+ floatingToolbarData: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.floatingToolbarData,
248
+ editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
249
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
250
+ contentMode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode,
251
+ isConsumption: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.isConsumption,
252
+ currentUserIntent: userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent,
253
+ isDragging: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging,
254
+ isMenuOpen: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isMenuOpen
255
+ };
256
+ });
257
+ export function ContentComponent({
258
+ pluginInjectionApi,
259
+ editorView,
260
+ popupsMountPoint,
261
+ popupsBoundariesElement,
262
+ popupsScrollableElement,
263
+ providerFactory,
264
+ dispatchAnalyticsEvent
265
+ }) {
266
+ var _configWithNodeInfo$c, _configWithNodeInfo$c2, _items, _pluginInjectionApi$c, _pluginInjectionApi$d;
218
267
  const {
219
268
  configWithNodeInfo,
220
- floatingToolbarData
221
- } = floatingToolbarState !== null && floatingToolbarState !== void 0 ? floatingToolbarState : {};
269
+ contentMode,
270
+ currentUserIntent,
271
+ editorDisabled,
272
+ floatingToolbarData,
273
+ isConsumption,
274
+ isDragging,
275
+ isMenuOpen,
276
+ mode
277
+ } = useSharedState(pluginInjectionApi);
222
278
  if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
223
279
  return null;
224
280
  }
225
281
  if (fg('platform_editor_user_intent_plugin')) {
226
- if ((userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent) === 'dragging') {
282
+ if (currentUserIntent === 'dragging') {
227
283
  return null;
228
284
  }
229
285
 
@@ -232,10 +288,10 @@ export function ContentComponent({
232
288
  // return null;
233
289
  // }
234
290
  } else {
235
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isDragging) {
291
+ if (isDragging) {
236
292
  return null;
237
293
  }
238
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isMenuOpen && editorExperiment('platform_editor_controls', 'variant1')) {
294
+ if (isMenuOpen && editorExperiment('platform_editor_controls', 'variant1')) {
239
295
  return null;
240
296
  }
241
297
  }
@@ -272,9 +328,8 @@ export function ContentComponent({
272
328
  stick = true
273
329
  } = config;
274
330
  const targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
275
- const isEditorDisabled = editorDisabledState && editorDisabledState.editorDisabled;
276
- const isInViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
277
- if (!targetRef || isEditorDisabled && !isInViewMode) {
331
+ const isInViewMode = mode === 'view';
332
+ if (!targetRef || editorDisabled && !isInViewMode) {
278
333
  return null;
279
334
  }
280
335
 
@@ -316,7 +371,7 @@ export function ContentComponent({
316
371
  typeGuard: value => typeof value === 'string' && ['text', 'nodes'].includes(value)
317
372
  });
318
373
  if (!editorExperiment('live_pages_graceful_edit', 'control') && viewModeToolbarEntry !== 'none') {
319
- if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode) === 'live-edit' && editorViewModeState !== null && editorViewModeState !== void 0 && editorViewModeState.isConsumption) {
374
+ if (contentMode === 'live-edit' && isConsumption) {
320
375
  const hasOtherToolbarItems = toolbarItems && toolbarItems.length !== 0;
321
376
  const shouldAddToolbarItems = viewModeToolbarEntry === 'expand-existing-only' ? hasOtherToolbarItems : true;
322
377
  if (shouldAddToolbarItems) {
@@ -7,9 +7,10 @@ import React, { useCallback, useContext } from 'react';
7
7
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
8
  import { css, jsx } from '@emotion/react';
9
9
  import { IconButton } from '@atlaskit/button/new';
10
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
11
  import { Popup } from '@atlaskit/editor-common/ui';
12
12
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
13
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
13
14
  import { EmojiPicker } from '@atlaskit/emoji';
14
15
  import EmojiAddIcon from '@atlaskit/icon/core/emoji-add';
15
16
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -51,12 +52,18 @@ const emojiPickerButtonWrapperVisualRefresh = css({
51
52
  }
52
53
  }
53
54
  });
54
- const EmojiPickerWithProvider = props => {
55
+ const useEmojiProvider = sharedPluginStateHookMigratorFactory(api => {
56
+ const emojiProvider = useSharedPluginStateSelector(api, 'emoji.emojiProvider');
57
+ return emojiProvider ? Promise.resolve(emojiProvider) : undefined;
58
+ }, api => {
55
59
  const {
56
60
  emojiState
57
- } = useSharedPluginState(props.pluginInjectionApi, ['emoji']);
61
+ } = useSharedPluginState(api, ['emoji']);
62
+ return emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState.emojiProvider) : undefined;
63
+ });
64
+ const EmojiPickerWithProvider = props => {
65
+ const emojiProvider = useEmojiProvider(props.pluginInjectionApi);
58
66
  const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
59
- const emojiProvider = emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider) : undefined;
60
67
  if (!emojiProvider) {
61
68
  return null;
62
69
  }
@@ -6,10 +6,11 @@ import React from 'react';
6
6
  import camelCase from 'lodash/camelCase';
7
7
  import { ACTION, ACTION_SUBJECT, CONTENT_COMPONENT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
8
8
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
9
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
9
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
10
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
11
11
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
12
12
  import { Popup } from '@atlaskit/editor-common/ui';
13
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
13
14
  import { AllSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
14
15
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
15
16
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -200,6 +201,62 @@ export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
200
201
  }
201
202
  };
202
203
  };
204
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
205
+ // floatingToolbar
206
+ var configWithNodeInfo = useSharedPluginStateSelector(pluginInjectionApi, 'floatingToolbar.configWithNodeInfo');
207
+ var floatingToolbarData = useSharedPluginStateSelector(pluginInjectionApi, 'floatingToolbar.floatingToolbarData');
208
+
209
+ // editorDisabled
210
+ var editorDisabledState = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled');
211
+
212
+ // editorViewMode
213
+ var mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
214
+ var contentMode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.contentMode');
215
+ var isConsumption = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.isConsumption');
216
+
217
+ // userIntent
218
+ var currentUserIntent = useSharedPluginStateSelector(pluginInjectionApi, 'userIntent.currentUserIntent');
219
+
220
+ // blockControls
221
+ var isDragging = useSharedPluginStateSelector(pluginInjectionApi,
222
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
223
+ 'blockControls.isDragging');
224
+ // isMenuOpen
225
+ var isMenuOpen = useSharedPluginStateSelector(pluginInjectionApi,
226
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
227
+ 'blockControls.isMenuOpen');
228
+ return {
229
+ configWithNodeInfo: configWithNodeInfo,
230
+ floatingToolbarData: floatingToolbarData,
231
+ editorDisabled: editorDisabledState,
232
+ mode: mode,
233
+ contentMode: contentMode,
234
+ isConsumption: isConsumption,
235
+ currentUserIntent: currentUserIntent,
236
+ isDragging: isDragging,
237
+ isMenuOpen: isMenuOpen
238
+ };
239
+ }, function (pluginInjectionApi) {
240
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorDisabled', 'editorViewMode', 'userIntent',
241
+ // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
242
+ 'blockControls']),
243
+ floatingToolbarState = _useSharedPluginState.floatingToolbarState,
244
+ editorDisabledState = _useSharedPluginState.editorDisabledState,
245
+ editorViewModeState = _useSharedPluginState.editorViewModeState,
246
+ userIntentState = _useSharedPluginState.userIntentState,
247
+ blockControlsState = _useSharedPluginState.blockControlsState;
248
+ return {
249
+ configWithNodeInfo: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.configWithNodeInfo,
250
+ floatingToolbarData: floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : floatingToolbarState.floatingToolbarData,
251
+ editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
252
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
253
+ contentMode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode,
254
+ isConsumption: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.isConsumption,
255
+ currentUserIntent: userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent,
256
+ isDragging: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging,
257
+ isMenuOpen: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isMenuOpen
258
+ };
259
+ });
203
260
  export function ContentComponent(_ref5) {
204
261
  var _configWithNodeInfo$c, _configWithNodeInfo$c2, _items, _pluginInjectionApi$c, _pluginInjectionApi$d;
205
262
  var pluginInjectionApi = _ref5.pluginInjectionApi,
@@ -209,22 +266,21 @@ export function ContentComponent(_ref5) {
209
266
  popupsScrollableElement = _ref5.popupsScrollableElement,
210
267
  providerFactory = _ref5.providerFactory,
211
268
  dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent;
212
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorDisabled', 'editorViewMode', 'userIntent',
213
- // @ts-expect-error - excluded from FloatingToolbarPlugin dependencies to avoid circular dependency
214
- 'blockControls']),
215
- floatingToolbarState = _useSharedPluginState.floatingToolbarState,
216
- editorDisabledState = _useSharedPluginState.editorDisabledState,
217
- editorViewModeState = _useSharedPluginState.editorViewModeState,
218
- userIntentState = _useSharedPluginState.userIntentState,
219
- blockControlsState = _useSharedPluginState.blockControlsState;
220
- var _ref6 = floatingToolbarState !== null && floatingToolbarState !== void 0 ? floatingToolbarState : {},
221
- configWithNodeInfo = _ref6.configWithNodeInfo,
222
- floatingToolbarData = _ref6.floatingToolbarData;
269
+ var _useSharedState = useSharedState(pluginInjectionApi),
270
+ configWithNodeInfo = _useSharedState.configWithNodeInfo,
271
+ contentMode = _useSharedState.contentMode,
272
+ currentUserIntent = _useSharedState.currentUserIntent,
273
+ editorDisabled = _useSharedState.editorDisabled,
274
+ floatingToolbarData = _useSharedState.floatingToolbarData,
275
+ isConsumption = _useSharedState.isConsumption,
276
+ isDragging = _useSharedState.isDragging,
277
+ isMenuOpen = _useSharedState.isMenuOpen,
278
+ mode = _useSharedState.mode;
223
279
  if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
224
280
  return null;
225
281
  }
226
282
  if (fg('platform_editor_user_intent_plugin')) {
227
- if ((userIntentState === null || userIntentState === void 0 ? void 0 : userIntentState.currentUserIntent) === 'dragging') {
283
+ if (currentUserIntent === 'dragging') {
228
284
  return null;
229
285
  }
230
286
 
@@ -233,10 +289,10 @@ export function ContentComponent(_ref5) {
233
289
  // return null;
234
290
  // }
235
291
  } else {
236
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isDragging) {
292
+ if (isDragging) {
237
293
  return null;
238
294
  }
239
- if (blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isMenuOpen && editorExperiment('platform_editor_controls', 'variant1')) {
295
+ if (isMenuOpen && editorExperiment('platform_editor_controls', 'variant1')) {
240
296
  return null;
241
297
  }
242
298
  }
@@ -272,9 +328,8 @@ export function ContentComponent(_ref5) {
272
328
  _config$stick = config.stick,
273
329
  stick = _config$stick === void 0 ? true : _config$stick;
274
330
  var targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
275
- var isEditorDisabled = editorDisabledState && editorDisabledState.editorDisabled;
276
- var isInViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
277
- if (!targetRef || isEditorDisabled && !isInViewMode) {
331
+ var isInViewMode = mode === 'view';
332
+ if (!targetRef || editorDisabled && !isInViewMode) {
278
333
  return null;
279
334
  }
280
335
 
@@ -324,7 +379,7 @@ export function ContentComponent(_ref5) {
324
379
  }
325
380
  });
326
381
  if (!editorExperiment('live_pages_graceful_edit', 'control') && viewModeToolbarEntry !== 'none') {
327
- if ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.contentMode) === 'live-edit' && editorViewModeState !== null && editorViewModeState !== void 0 && editorViewModeState.isConsumption) {
382
+ if (contentMode === 'live-edit' && isConsumption) {
328
383
  var hasOtherToolbarItems = toolbarItems && toolbarItems.length !== 0;
329
384
  var shouldAddToolbarItems = viewModeToolbarEntry === 'expand-existing-only' ? hasOtherToolbarItems : true;
330
385
  if (shouldAddToolbarItems) {
@@ -360,8 +415,8 @@ export function ContentComponent(_ref5) {
360
415
  };
361
416
 
362
417
  // Confirm dialog
363
- var _ref7 = floatingToolbarData || {},
364
- confirmDialogForItem = _ref7.confirmDialogForItem;
418
+ var _ref6 = floatingToolbarData || {},
419
+ confirmDialogForItem = _ref6.confirmDialogForItem;
365
420
  var confirmButtonItem = confirmDialogForItem ?
366
421
  // Ignored via go/ees005
367
422
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -8,9 +8,10 @@ import React, { useCallback, useContext } from 'react';
8
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
9
  import { css, jsx } from '@emotion/react';
10
10
  import { IconButton } from '@atlaskit/button/new';
11
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
12
  import { Popup } from '@atlaskit/editor-common/ui';
13
13
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
14
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
14
15
  import { EmojiPicker } from '@atlaskit/emoji';
15
16
  import EmojiAddIcon from '@atlaskit/icon/core/emoji-add';
16
17
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -52,11 +53,17 @@ var emojiPickerButtonWrapperVisualRefresh = css({
52
53
  }
53
54
  }
54
55
  });
55
- var EmojiPickerWithProvider = function EmojiPickerWithProvider(props) {
56
- var _useSharedPluginState = useSharedPluginState(props.pluginInjectionApi, ['emoji']),
56
+ var useEmojiProvider = sharedPluginStateHookMigratorFactory(function (api) {
57
+ var emojiProvider = useSharedPluginStateSelector(api, 'emoji.emojiProvider');
58
+ return emojiProvider ? Promise.resolve(emojiProvider) : undefined;
59
+ }, function (api) {
60
+ var _useSharedPluginState = useSharedPluginState(api, ['emoji']),
57
61
  emojiState = _useSharedPluginState.emojiState;
62
+ return emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState.emojiProvider) : undefined;
63
+ });
64
+ var EmojiPickerWithProvider = function EmojiPickerWithProvider(props) {
65
+ var emojiProvider = useEmojiProvider(props.pluginInjectionApi);
58
66
  var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
59
- var emojiProvider = emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider ? Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider) : undefined;
60
67
  if (!emojiProvider) {
61
68
  return null;
62
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-floating-toolbar",
3
- "version": "4.1.3",
3
+ "version": "4.1.5",
4
4
  "description": "Floating toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,9 +28,9 @@
28
28
  "@atlaskit/adf-utils": "^19.19.0",
29
29
  "@atlaskit/button": "^23.0.0",
30
30
  "@atlaskit/checkbox": "^17.1.0",
31
- "@atlaskit/editor-common": "^104.1.0",
31
+ "@atlaskit/editor-common": "^105.2.0",
32
32
  "@atlaskit/editor-palette": "^2.1.0",
33
- "@atlaskit/editor-plugin-analytics": "^2.2.0",
33
+ "@atlaskit/editor-plugin-analytics": "^2.3.0",
34
34
  "@atlaskit/editor-plugin-context-panel": "^4.1.0",
35
35
  "@atlaskit/editor-plugin-copy-button": "^2.0.0",
36
36
  "@atlaskit/editor-plugin-decorations": "^2.0.0",
@@ -42,15 +42,15 @@
42
42
  "@atlaskit/editor-plugin-table": "^10.9.0",
43
43
  "@atlaskit/editor-plugin-user-intent": "^0.1.0",
44
44
  "@atlaskit/editor-prosemirror": "7.0.0",
45
- "@atlaskit/emoji": "^69.1.0",
45
+ "@atlaskit/emoji": "^69.2.0",
46
46
  "@atlaskit/icon": "^26.0.0",
47
47
  "@atlaskit/menu": "^5.0.0",
48
- "@atlaskit/modal-dialog": "^14.1.0",
48
+ "@atlaskit/modal-dialog": "^14.2.0",
49
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
50
50
  "@atlaskit/primitives": "^14.7.0",
51
51
  "@atlaskit/select": "^20.4.0",
52
52
  "@atlaskit/theme": "^18.0.0",
53
- "@atlaskit/tmp-editor-statsig": "^4.19.0",
53
+ "@atlaskit/tmp-editor-statsig": "^4.21.0",
54
54
  "@atlaskit/tokens": "^4.8.0",
55
55
  "@atlaskit/tooltip": "^20.0.0",
56
56
  "@babel/runtime": "^7.0.0",