@atlaskit/editor-plugin-toolbar 1.0.0 → 1.1.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,24 @@
1
1
  # @atlaskit/editor-plugin-toolbar
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`50976babce55d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/50976babce55d) -
8
+ Add new 'onClick' to dropdown menu, hook up new toolbar api to regsiter components on selection
9
+ change, add new safeRegistry method to replace existing objects
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 1.0.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [`cb63aae8c8554`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cb63aae8c8554) -
20
+ Add a check to ensure selection toolbar renders when all doc is selected
21
+
3
22
  ## 1.0.0
4
23
 
5
24
  ### Patch Changes
@@ -32,7 +32,12 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
32
32
  name: 'toolbar',
33
33
  actions: {
34
34
  registerComponents: function registerComponents(toolbarComponents) {
35
- registry.register(toolbarComponents);
35
+ var replaceItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
36
+ if (replaceItems) {
37
+ registry.safeRegister(toolbarComponents);
38
+ } else {
39
+ registry.register(toolbarComponents);
40
+ }
36
41
  },
37
42
  getComponents: function getComponents() {
38
43
  return registry.components;
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -24,7 +24,7 @@ var isToolbarComponent = function isToolbarComponent(component) {
24
24
  return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
25
25
  };
26
26
  var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
27
- var _api$toolbar, _api$toolbar$getCompo;
27
+ var _api$toolbar;
28
28
  var api = _ref.api,
29
29
  editorView = _ref.editorView,
30
30
  mountPoint = _ref.mountPoint,
@@ -36,19 +36,20 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
36
36
  };
37
37
  }),
38
38
  shouldShowToolbar = _useSharedPluginState.shouldShowToolbar;
39
- var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || (_api$toolbar = _api$toolbar.actions) === null || _api$toolbar === void 0 || (_api$toolbar$getCompo = _api$toolbar.getComponents) === null || _api$toolbar$getCompo === void 0 ? void 0 : _api$toolbar$getCompo.call(_api$toolbar);
39
+ var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.getComponents();
40
40
  var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
41
41
  return isToolbarComponent(component);
42
42
  });
43
43
  var currentUserIntent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userIntent.currentUserIntent');
44
44
  var connectivityStateMode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'connectivity.mode');
45
+ var toolbarDocking = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userPreferences.preferences.toolbarDockingPosition');
45
46
  var isOffline = connectivityStateMode === 'offline';
46
47
  // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
47
48
  // @ts-expect-error
48
49
  var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
49
50
  var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.TextSelection;
51
+ var isAllSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.AllSelection && (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_2', 'isEnabled', true);
50
52
  var isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
51
- var toolbarDocking = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userPreferences.preferences.toolbarDockingPosition');
52
53
  var onPositionCalculated = (0, _react.useCallback)(function (position) {
53
54
  var toolbarTitle = _consts.SELECTION_TOOLBAR_LABEL;
54
55
 
@@ -64,7 +65,7 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
64
65
  if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && toolbarDocking === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
65
66
  return null;
66
67
  }
67
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || (0, _coreUtils.isSSR)()) {
68
+ if (!(isTextSelection || isCellSelection || isAllSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) || (0, _coreUtils.isSSR)()) {
68
69
  return null;
69
70
  }
70
71
  return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
@@ -23,8 +23,12 @@ export const toolbarPlugin = ({
23
23
  return {
24
24
  name: 'toolbar',
25
25
  actions: {
26
- registerComponents: toolbarComponents => {
27
- registry.register(toolbarComponents);
26
+ registerComponents: (toolbarComponents, replaceItems = false) => {
27
+ if (replaceItems) {
28
+ registry.safeRegister(toolbarComponents);
29
+ } else {
30
+ registry.register(toolbarComponents);
31
+ }
28
32
  },
29
33
  getComponents: () => {
30
34
  return registry.components;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor
5
5
  import { Popup } from '@atlaskit/editor-common/ui';
6
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
7
  import { calculateToolbarPositionTrackHead, calculateToolbarPositionOnCellSelection } from '@atlaskit/editor-common/utils';
8
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { AllSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
11
11
  import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
@@ -21,7 +21,7 @@ export const SelectionToolbar = ({
21
21
  mountPoint,
22
22
  disableSelectionToolbarWhenPinned
23
23
  }) => {
24
- var _api$toolbar, _api$toolbar$actions, _api$toolbar$actions$;
24
+ var _api$toolbar;
25
25
  const {
26
26
  shouldShowToolbar
27
27
  } = useSharedPluginStateWithSelector(api, ['toolbar'], state => {
@@ -30,17 +30,18 @@ export const SelectionToolbar = ({
30
30
  shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar
31
31
  };
32
32
  });
33
- const components = api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : (_api$toolbar$actions = _api$toolbar.actions) === null || _api$toolbar$actions === void 0 ? void 0 : (_api$toolbar$actions$ = _api$toolbar$actions.getComponents) === null || _api$toolbar$actions$ === void 0 ? void 0 : _api$toolbar$actions$.call(_api$toolbar$actions);
33
+ const components = api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.getComponents();
34
34
  const toolbar = components === null || components === void 0 ? void 0 : components.find(component => isToolbarComponent(component));
35
35
  const currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
36
36
  const connectivityStateMode = useSharedPluginStateSelector(api, 'connectivity.mode');
37
+ const toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
37
38
  const isOffline = connectivityStateMode === 'offline';
38
39
  // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
39
40
  // @ts-expect-error
40
41
  const selection = useSharedPluginStateSelector(api, 'selection.selection');
41
42
  const isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
43
+ const isAllSelection = !editorView.state.selection.empty && editorView.state.selection instanceof AllSelection && expValEquals('platform_editor_toolbar_aifc_patch_2', 'isEnabled', true);
42
44
  const isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
43
- const toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
44
45
  const onPositionCalculated = useCallback(position => {
45
46
  const toolbarTitle = SELECTION_TOOLBAR_LABEL;
46
47
 
@@ -56,7 +57,7 @@ export const SelectionToolbar = ({
56
57
  if (expValEquals('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && toolbarDocking === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
57
58
  return null;
58
59
  }
59
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
60
+ if (!(isTextSelection || isCellSelection || isAllSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
60
61
  return null;
61
62
  }
62
63
  return /*#__PURE__*/React.createElement(Popup, {
@@ -25,7 +25,12 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
25
25
  name: 'toolbar',
26
26
  actions: {
27
27
  registerComponents: function registerComponents(toolbarComponents) {
28
- registry.register(toolbarComponents);
28
+ var replaceItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
29
+ if (replaceItems) {
30
+ registry.safeRegister(toolbarComponents);
31
+ } else {
32
+ registry.register(toolbarComponents);
33
+ }
29
34
  },
30
35
  getComponents: function getComponents() {
31
36
  return registry.components;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor
5
5
  import { Popup } from '@atlaskit/editor-common/ui';
6
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
7
  import { calculateToolbarPositionTrackHead, calculateToolbarPositionOnCellSelection } from '@atlaskit/editor-common/utils';
8
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { AllSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
11
11
  import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
@@ -16,7 +16,7 @@ var isToolbarComponent = function isToolbarComponent(component) {
16
16
  return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
17
17
  };
18
18
  export var SelectionToolbar = function SelectionToolbar(_ref) {
19
- var _api$toolbar, _api$toolbar$getCompo;
19
+ var _api$toolbar;
20
20
  var api = _ref.api,
21
21
  editorView = _ref.editorView,
22
22
  mountPoint = _ref.mountPoint,
@@ -28,19 +28,20 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
28
28
  };
29
29
  }),
30
30
  shouldShowToolbar = _useSharedPluginState.shouldShowToolbar;
31
- var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || (_api$toolbar = _api$toolbar.actions) === null || _api$toolbar === void 0 || (_api$toolbar$getCompo = _api$toolbar.getComponents) === null || _api$toolbar$getCompo === void 0 ? void 0 : _api$toolbar$getCompo.call(_api$toolbar);
31
+ var components = api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.getComponents();
32
32
  var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
33
33
  return isToolbarComponent(component);
34
34
  });
35
35
  var currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
36
36
  var connectivityStateMode = useSharedPluginStateSelector(api, 'connectivity.mode');
37
+ var toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
37
38
  var isOffline = connectivityStateMode === 'offline';
38
39
  // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
39
40
  // @ts-expect-error
40
41
  var selection = useSharedPluginStateSelector(api, 'selection.selection');
41
42
  var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
43
+ var isAllSelection = !editorView.state.selection.empty && editorView.state.selection instanceof AllSelection && expValEquals('platform_editor_toolbar_aifc_patch_2', 'isEnabled', true);
42
44
  var isCellSelection = !editorView.state.selection.empty && '$anchorCell' in editorView.state.selection;
43
- var toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
44
45
  var onPositionCalculated = useCallback(function (position) {
45
46
  var toolbarTitle = SELECTION_TOOLBAR_LABEL;
46
47
 
@@ -56,7 +57,7 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
56
57
  if (expValEquals('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && toolbarDocking === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
57
58
  return null;
58
59
  }
59
- if (!(isTextSelection || isCellSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
60
+ if (!(isTextSelection || isCellSelection || isAllSelection) || currentUserIntent === 'dragging' || !shouldShowToolbar || currentUserIntent === 'blockMenuOpen' && expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) || isSSR()) {
60
61
  return null;
61
62
  }
62
63
  return /*#__PURE__*/React.createElement(Popup, {
@@ -5,11 +5,11 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
5
5
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
6
6
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
7
7
  import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
8
- import type { ToolbarPluginOptions } from './types';
8
+ import type { RegisterComponentsAction, ToolbarPluginOptions } from './types';
9
9
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
10
10
  actions: {
11
11
  getComponents: () => Array<RegisterComponent>;
12
- registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
12
+ registerComponents: RegisterComponentsAction;
13
13
  };
14
14
  dependencies: [
15
15
  OptionalPlugin<UserIntentPlugin>,
@@ -1,4 +1,6 @@
1
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
1
2
  export type ToolbarPluginOptions = {
2
3
  disableSelectionToolbar?: boolean;
3
4
  disableSelectionToolbarWhenPinned?: boolean;
4
5
  };
6
+ export type RegisterComponentsAction = (toolbarComponents: Array<RegisterComponent>, replaceItems?: boolean) => void;
@@ -4,9 +4,9 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { ToolbarPlugin } from '../../toolbarPluginType';
5
5
  type SelectionToolbarProps = {
6
6
  api?: ExtractInjectionAPI<ToolbarPlugin>;
7
+ disableSelectionToolbarWhenPinned: boolean;
7
8
  editorView: EditorView;
8
9
  mountPoint: HTMLElement | undefined;
9
- disableSelectionToolbarWhenPinned: boolean;
10
10
  };
11
11
  export declare const SelectionToolbar: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element | null;
12
12
  export {};
@@ -5,11 +5,11 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
5
5
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
6
6
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
7
7
  import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
8
- import type { ToolbarPluginOptions } from './types';
8
+ import type { RegisterComponentsAction, ToolbarPluginOptions } from './types';
9
9
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
10
10
  actions: {
11
11
  getComponents: () => Array<RegisterComponent>;
12
- registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
12
+ registerComponents: RegisterComponentsAction;
13
13
  };
14
14
  dependencies: [
15
15
  OptionalPlugin<UserIntentPlugin>,
@@ -1,4 +1,6 @@
1
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
1
2
  export type ToolbarPluginOptions = {
2
3
  disableSelectionToolbar?: boolean;
3
4
  disableSelectionToolbarWhenPinned?: boolean;
4
5
  };
6
+ export type RegisterComponentsAction = (toolbarComponents: Array<RegisterComponent>, replaceItems?: boolean) => void;
@@ -4,9 +4,9 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { ToolbarPlugin } from '../../toolbarPluginType';
5
5
  type SelectionToolbarProps = {
6
6
  api?: ExtractInjectionAPI<ToolbarPlugin>;
7
+ disableSelectionToolbarWhenPinned: boolean;
7
8
  editorView: EditorView;
8
9
  mountPoint: HTMLElement | undefined;
9
- disableSelectionToolbarWhenPinned: boolean;
10
10
  };
11
11
  export declare const SelectionToolbar: ({ api, editorView, mountPoint, disableSelectionToolbarWhenPinned, }: SelectionToolbarProps) => React.JSX.Element | null;
12
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-toolbar",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,15 +34,15 @@
34
34
  "@atlaskit/editor-plugin-user-intent": "^2.0.0",
35
35
  "@atlaskit/editor-plugin-user-preferences": "^2.0.0",
36
36
  "@atlaskit/editor-prosemirror": "7.0.0",
37
- "@atlaskit/editor-toolbar": "^0.6.0",
37
+ "@atlaskit/editor-toolbar": "^0.7.0",
38
38
  "@atlaskit/editor-toolbar-model": "^0.2.0",
39
- "@atlaskit/tmp-editor-statsig": "^12.0.0",
39
+ "@atlaskit/tmp-editor-statsig": "^12.2.0",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "bind-event-listener": "^3.0.0",
42
42
  "react-intl-next": "npm:react-intl@^5.18.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@atlaskit/editor-common": "^108.0.0",
45
+ "@atlaskit/editor-common": "^108.1.0",
46
46
  "react": "^18.2.0"
47
47
  },
48
48
  "techstack": {