@atlaskit/editor-plugin-primary-toolbar 1.3.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-primary-toolbar
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#126478](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/126478)
8
+ [`ca1665ebbfe4d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ca1665ebbfe4d) -
9
+ [ED-23435] Store primary toolbar component registry in a plugin variable instead of in plugin
10
+ state to avoid having to add effects to all plugins and enable SSR for the toolbar. [Breaking
11
+ change] Converted registerComponent from the primary toolbar plugin into an action.
12
+
13
+ ## 1.3.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#124654](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124654)
18
+ [`3eace5ec6b539`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3eace5ec6b539) -
19
+ [ux] Updated the primary toolbar plugin to allow have a spellcheck button which is next to the
20
+ undo/redo buttons. Also update the ai plugin to support this and fallback to the original "append
21
+ to end" implementation if the toolbar plugin is not enabled
22
+
3
23
  ## 1.3.1
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.registerComponent = void 0;
7
+ var registerComponent = exports.registerComponent = function registerComponent(componentRegistry) {
8
+ return function (_ref) {
9
+ var name = _ref.name,
10
+ component = _ref.component;
11
+ componentRegistry.set(name, component);
12
+ };
13
+ };
@@ -1,22 +1,31 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.primaryToolbarPlugin = void 0;
7
- var _commands = require("./commands");
8
+ var _actions = require("./actions");
8
9
  var _pmPlugin = require("./pm-plugin");
10
+ var _separator = _interopRequireDefault(require("./ui/separator"));
9
11
  var primaryToolbarPlugin = exports.primaryToolbarPlugin = function primaryToolbarPlugin() {
12
+ // We use a plugin variable to store the component registry to avoid having to use
13
+ // effects in each plugin, and to enable rendering the toolbar in SSR
14
+ // TODO: Replace this with something in plugin state once we have a way to initialise across plugins on plugin initialisation
15
+ var componentRegistry = new Map();
16
+
17
+ // Pre-fill registry with the separator component
18
+ componentRegistry.set('separator', _separator.default);
10
19
  return {
11
20
  name: 'primaryToolbar',
12
- commands: {
13
- registerComponent: _commands.registerComponent
21
+ actions: {
22
+ registerComponent: (0, _actions.registerComponent)(componentRegistry)
14
23
  },
15
24
  pmPlugins: function pmPlugins() {
16
25
  return [{
17
26
  name: 'primaryToolbar',
18
27
  plugin: function plugin() {
19
- return (0, _pmPlugin.createPlugin)();
28
+ return (0, _pmPlugin.createPlugin)(componentRegistry);
20
29
  }
21
30
  }];
22
31
  },
@@ -1,51 +1,24 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.primaryToolbarPluginKey = exports.createPlugin = exports.PrimaryToolbarPluginAction = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
6
+ exports.primaryToolbarPluginKey = exports.createPlugin = void 0;
9
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
8
  var _state = require("@atlaskit/editor-prosemirror/state");
11
9
  var _toolbarConfiguration = require("./toolbar-configuration");
12
- var _separator = _interopRequireDefault(require("./ui/separator"));
13
- 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; }
14
- 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; }
15
10
  var primaryToolbarPluginKey = exports.primaryToolbarPluginKey = new _state.PluginKey('primaryToolbar');
16
- var PrimaryToolbarPluginAction = exports.PrimaryToolbarPluginAction = /*#__PURE__*/function (PrimaryToolbarPluginAction) {
17
- PrimaryToolbarPluginAction[PrimaryToolbarPluginAction["REGISTER"] = 0] = "REGISTER";
18
- return PrimaryToolbarPluginAction;
19
- }({});
20
- var createPlugin = exports.createPlugin = function createPlugin() {
11
+ var createPlugin = exports.createPlugin = function createPlugin(componentRegistry) {
21
12
  return new _safePlugin.SafePlugin({
22
13
  key: primaryToolbarPluginKey,
23
14
  state: {
24
15
  init: function init() {
25
- var componentRegistry = new Map();
26
-
27
- // Pre-fill registry with the separator component
28
- componentRegistry.set('separator', _separator.default);
29
16
  return {
30
- componentRegistry: componentRegistry,
31
- components: []
17
+ components: (0, _toolbarConfiguration.getToolbarComponents)(componentRegistry)
32
18
  };
33
19
  },
34
- apply: function apply(tr, pluginState) {
35
- var _tr$getMeta;
36
- var action = (_tr$getMeta = tr.getMeta(primaryToolbarPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
37
- switch (action) {
38
- case PrimaryToolbarPluginAction.REGISTER:
39
- var _tr$getMeta2 = tr.getMeta(primaryToolbarPluginKey),
40
- name = _tr$getMeta2.name,
41
- component = _tr$getMeta2.component;
42
- pluginState.componentRegistry.set(name, component);
43
- return _objectSpread(_objectSpread({}, pluginState), {}, {
44
- components: (0, _toolbarConfiguration.getToolbarComponents)(pluginState)
45
- });
46
- default:
47
- return pluginState;
48
- }
20
+ apply: function apply(_tr, pluginState) {
21
+ return pluginState;
49
22
  }
50
23
  }
51
24
  });
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getToolbarComponents = void 0;
7
- var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(pluginState) {
7
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(componentRegistry) {
8
8
  return toolbarConfiguration.filter(function (toolbarElement) {
9
- return typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(pluginState.componentRegistry);
9
+ return typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(componentRegistry);
10
10
  }).reduce(function (acc, toolbarElement) {
11
- if (pluginState.componentRegistry.has(toolbarElement.name)) {
12
- var component = pluginState.componentRegistry.get(toolbarElement.name);
11
+ if (componentRegistry.has(toolbarElement.name)) {
12
+ var component = componentRegistry.get(toolbarElement.name);
13
13
  if (!!component) {
14
14
  acc.push(component);
15
15
  }
@@ -25,6 +25,14 @@ var undoRedoGroup = [{
25
25
  return componentRegistry.has('undoRedoPlugin');
26
26
  }
27
27
  }];
28
+ var spellCheckGroup = [{
29
+ name: 'spellCheck'
30
+ }, {
31
+ name: 'separator',
32
+ enabled: function enabled(componentRegistry) {
33
+ return componentRegistry.has('spellCheck');
34
+ }
35
+ }];
28
36
  var blockTypeGroup = [{
29
37
  name: 'blockType'
30
38
  }, {
@@ -89,4 +97,4 @@ var others = [{
89
97
  }, {
90
98
  name: 'loom'
91
99
  }];
92
- var toolbarConfiguration = [].concat(undoRedoGroup, blockTypeGroup, textFormattingGroup, alignmentGroup, textColorGroup, listFormatting, insertBlockGroup, others);
100
+ var toolbarConfiguration = [].concat(undoRedoGroup, spellCheckGroup, blockTypeGroup, textFormattingGroup, alignmentGroup, textColorGroup, listFormatting, insertBlockGroup, others);
@@ -0,0 +1,6 @@
1
+ export const registerComponent = componentRegistry => ({
2
+ name,
3
+ component
4
+ }) => {
5
+ componentRegistry.set(name, component);
6
+ };
@@ -1,18 +1,28 @@
1
- import { registerComponent } from './commands';
1
+ import { registerComponent } from './actions';
2
2
  import { createPlugin, primaryToolbarPluginKey } from './pm-plugin';
3
- export const primaryToolbarPlugin = () => ({
4
- name: 'primaryToolbar',
5
- commands: {
6
- registerComponent
7
- },
8
- pmPlugins: () => [{
3
+ import Separator from './ui/separator';
4
+ export const primaryToolbarPlugin = () => {
5
+ // We use a plugin variable to store the component registry to avoid having to use
6
+ // effects in each plugin, and to enable rendering the toolbar in SSR
7
+ // TODO: Replace this with something in plugin state once we have a way to initialise across plugins on plugin initialisation
8
+ const componentRegistry = new Map();
9
+
10
+ // Pre-fill registry with the separator component
11
+ componentRegistry.set('separator', Separator);
12
+ return {
9
13
  name: 'primaryToolbar',
10
- plugin: () => createPlugin()
11
- }],
12
- getSharedState(editorState) {
13
- if (!editorState) {
14
- return;
14
+ actions: {
15
+ registerComponent: registerComponent(componentRegistry)
16
+ },
17
+ pmPlugins: () => [{
18
+ name: 'primaryToolbar',
19
+ plugin: () => createPlugin(componentRegistry)
20
+ }],
21
+ getSharedState(editorState) {
22
+ if (!editorState) {
23
+ return;
24
+ }
25
+ return primaryToolbarPluginKey.getState(editorState);
15
26
  }
16
- return primaryToolbarPluginKey.getState(editorState);
17
- }
18
- });
27
+ };
28
+ };
@@ -1,44 +1,15 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { getToolbarComponents } from './toolbar-configuration';
4
- import Separator from './ui/separator';
5
4
  export const primaryToolbarPluginKey = new PluginKey('primaryToolbar');
6
- export let PrimaryToolbarPluginAction = /*#__PURE__*/function (PrimaryToolbarPluginAction) {
7
- PrimaryToolbarPluginAction[PrimaryToolbarPluginAction["REGISTER"] = 0] = "REGISTER";
8
- return PrimaryToolbarPluginAction;
9
- }({});
10
- export const createPlugin = () => {
5
+ export const createPlugin = componentRegistry => {
11
6
  return new SafePlugin({
12
7
  key: primaryToolbarPluginKey,
13
8
  state: {
14
- init: () => {
15
- const componentRegistry = new Map();
16
-
17
- // Pre-fill registry with the separator component
18
- componentRegistry.set('separator', Separator);
19
- return {
20
- componentRegistry,
21
- components: []
22
- };
23
- },
24
- apply: (tr, pluginState) => {
25
- var _tr$getMeta;
26
- const action = (_tr$getMeta = tr.getMeta(primaryToolbarPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
27
- switch (action) {
28
- case PrimaryToolbarPluginAction.REGISTER:
29
- const {
30
- name,
31
- component
32
- } = tr.getMeta(primaryToolbarPluginKey);
33
- pluginState.componentRegistry.set(name, component);
34
- return {
35
- ...pluginState,
36
- components: getToolbarComponents(pluginState)
37
- };
38
- default:
39
- return pluginState;
40
- }
41
- }
9
+ init: () => ({
10
+ components: getToolbarComponents(componentRegistry)
11
+ }),
12
+ apply: (_tr, pluginState) => pluginState
42
13
  }
43
14
  });
44
15
  };
@@ -1,6 +1,6 @@
1
- export const getToolbarComponents = pluginState => toolbarConfiguration.filter(toolbarElement => typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(pluginState.componentRegistry)).reduce((acc, toolbarElement) => {
2
- if (pluginState.componentRegistry.has(toolbarElement.name)) {
3
- const component = pluginState.componentRegistry.get(toolbarElement.name);
1
+ export const getToolbarComponents = componentRegistry => toolbarConfiguration.filter(toolbarElement => typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(componentRegistry)).reduce((acc, toolbarElement) => {
2
+ if (componentRegistry.has(toolbarElement.name)) {
3
+ const component = componentRegistry.get(toolbarElement.name);
4
4
  if (!!component) {
5
5
  acc.push(component);
6
6
  }
@@ -13,6 +13,12 @@ const undoRedoGroup = [{
13
13
  name: 'separator',
14
14
  enabled: componentRegistry => componentRegistry.has('undoRedoPlugin')
15
15
  }];
16
+ const spellCheckGroup = [{
17
+ name: 'spellCheck'
18
+ }, {
19
+ name: 'separator',
20
+ enabled: componentRegistry => componentRegistry.has('spellCheck')
21
+ }];
16
22
  const blockTypeGroup = [{
17
23
  name: 'blockType'
18
24
  }, {
@@ -65,4 +71,4 @@ const others = [{
65
71
  }, {
66
72
  name: 'loom'
67
73
  }];
68
- const toolbarConfiguration = [...undoRedoGroup, ...blockTypeGroup, ...textFormattingGroup, ...alignmentGroup, ...textColorGroup, ...listFormatting, ...insertBlockGroup, ...others];
74
+ const toolbarConfiguration = [...undoRedoGroup, ...spellCheckGroup, ...blockTypeGroup, ...textFormattingGroup, ...alignmentGroup, ...textColorGroup, ...listFormatting, ...insertBlockGroup, ...others];
@@ -0,0 +1,7 @@
1
+ export var registerComponent = function registerComponent(componentRegistry) {
2
+ return function (_ref) {
3
+ var name = _ref.name,
4
+ component = _ref.component;
5
+ componentRegistry.set(name, component);
6
+ };
7
+ };
@@ -1,16 +1,24 @@
1
- import { registerComponent } from './commands';
1
+ import { registerComponent } from './actions';
2
2
  import { createPlugin, primaryToolbarPluginKey } from './pm-plugin';
3
+ import Separator from './ui/separator';
3
4
  export var primaryToolbarPlugin = function primaryToolbarPlugin() {
5
+ // We use a plugin variable to store the component registry to avoid having to use
6
+ // effects in each plugin, and to enable rendering the toolbar in SSR
7
+ // TODO: Replace this with something in plugin state once we have a way to initialise across plugins on plugin initialisation
8
+ var componentRegistry = new Map();
9
+
10
+ // Pre-fill registry with the separator component
11
+ componentRegistry.set('separator', Separator);
4
12
  return {
5
13
  name: 'primaryToolbar',
6
- commands: {
7
- registerComponent: registerComponent
14
+ actions: {
15
+ registerComponent: registerComponent(componentRegistry)
8
16
  },
9
17
  pmPlugins: function pmPlugins() {
10
18
  return [{
11
19
  name: 'primaryToolbar',
12
20
  plugin: function plugin() {
13
- return createPlugin();
21
+ return createPlugin(componentRegistry);
14
22
  }
15
23
  }];
16
24
  },
@@ -1,44 +1,18 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
3
- 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; }
4
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
3
  import { getToolbarComponents } from './toolbar-configuration';
7
- import Separator from './ui/separator';
8
4
  export var primaryToolbarPluginKey = new PluginKey('primaryToolbar');
9
- export var PrimaryToolbarPluginAction = /*#__PURE__*/function (PrimaryToolbarPluginAction) {
10
- PrimaryToolbarPluginAction[PrimaryToolbarPluginAction["REGISTER"] = 0] = "REGISTER";
11
- return PrimaryToolbarPluginAction;
12
- }({});
13
- export var createPlugin = function createPlugin() {
5
+ export var createPlugin = function createPlugin(componentRegistry) {
14
6
  return new SafePlugin({
15
7
  key: primaryToolbarPluginKey,
16
8
  state: {
17
9
  init: function init() {
18
- var componentRegistry = new Map();
19
-
20
- // Pre-fill registry with the separator component
21
- componentRegistry.set('separator', Separator);
22
10
  return {
23
- componentRegistry: componentRegistry,
24
- components: []
11
+ components: getToolbarComponents(componentRegistry)
25
12
  };
26
13
  },
27
- apply: function apply(tr, pluginState) {
28
- var _tr$getMeta;
29
- var action = (_tr$getMeta = tr.getMeta(primaryToolbarPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
30
- switch (action) {
31
- case PrimaryToolbarPluginAction.REGISTER:
32
- var _tr$getMeta2 = tr.getMeta(primaryToolbarPluginKey),
33
- name = _tr$getMeta2.name,
34
- component = _tr$getMeta2.component;
35
- pluginState.componentRegistry.set(name, component);
36
- return _objectSpread(_objectSpread({}, pluginState), {}, {
37
- components: getToolbarComponents(pluginState)
38
- });
39
- default:
40
- return pluginState;
41
- }
14
+ apply: function apply(_tr, pluginState) {
15
+ return pluginState;
42
16
  }
43
17
  }
44
18
  });
@@ -1,9 +1,9 @@
1
- export var getToolbarComponents = function getToolbarComponents(pluginState) {
1
+ export var getToolbarComponents = function getToolbarComponents(componentRegistry) {
2
2
  return toolbarConfiguration.filter(function (toolbarElement) {
3
- return typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(pluginState.componentRegistry);
3
+ return typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(componentRegistry);
4
4
  }).reduce(function (acc, toolbarElement) {
5
- if (pluginState.componentRegistry.has(toolbarElement.name)) {
6
- var component = pluginState.componentRegistry.get(toolbarElement.name);
5
+ if (componentRegistry.has(toolbarElement.name)) {
6
+ var component = componentRegistry.get(toolbarElement.name);
7
7
  if (!!component) {
8
8
  acc.push(component);
9
9
  }
@@ -19,6 +19,14 @@ var undoRedoGroup = [{
19
19
  return componentRegistry.has('undoRedoPlugin');
20
20
  }
21
21
  }];
22
+ var spellCheckGroup = [{
23
+ name: 'spellCheck'
24
+ }, {
25
+ name: 'separator',
26
+ enabled: function enabled(componentRegistry) {
27
+ return componentRegistry.has('spellCheck');
28
+ }
29
+ }];
22
30
  var blockTypeGroup = [{
23
31
  name: 'blockType'
24
32
  }, {
@@ -83,4 +91,4 @@ var others = [{
83
91
  }, {
84
92
  name: 'loom'
85
93
  }];
86
- var toolbarConfiguration = [].concat(undoRedoGroup, blockTypeGroup, textFormattingGroup, alignmentGroup, textColorGroup, listFormatting, insertBlockGroup, others);
94
+ var toolbarConfiguration = [].concat(undoRedoGroup, spellCheckGroup, blockTypeGroup, textFormattingGroup, alignmentGroup, textColorGroup, listFormatting, insertBlockGroup, others);
@@ -0,0 +1,6 @@
1
+ import type { ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
+ import type { ComponentRegistry, ToolbarElementNames } from './types';
3
+ export declare const registerComponent: (componentRegistry: ComponentRegistry) => ({ name, component, }: {
4
+ name: ToolbarElementNames;
5
+ component: ToolbarUIComponentFactory;
6
+ }) => void;
@@ -1,8 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import type { PrimaryToolbarPluginState } from './types';
3
+ import type { ComponentRegistry, PrimaryToolbarPluginState } from './types';
4
4
  export declare const primaryToolbarPluginKey: PluginKey<PrimaryToolbarPluginState>;
5
- export declare enum PrimaryToolbarPluginAction {
6
- REGISTER = 0
7
- }
8
- export declare const createPlugin: () => SafePlugin<PrimaryToolbarPluginState>;
5
+ export declare const createPlugin: (componentRegistry: ComponentRegistry) => SafePlugin<PrimaryToolbarPluginState>;
@@ -1,3 +1,3 @@
1
1
  import type { ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
- import type { PrimaryToolbarPluginState } from './types';
3
- export declare const getToolbarComponents: (pluginState: PrimaryToolbarPluginState) => ToolbarUIComponentFactory[];
2
+ import type { ComponentRegistry } from './types';
3
+ export declare const getToolbarComponents: (componentRegistry: ComponentRegistry) => ToolbarUIComponentFactory[];
@@ -1,21 +1,19 @@
1
- import type { EditorCommand, NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
2
  export type PrimaryToolbarPlugin = NextEditorPlugin<'primaryToolbar', {
3
3
  sharedState: PrimaryToolbarPluginState | undefined;
4
- commands: {
4
+ actions: {
5
5
  registerComponent: ({ name, component, }: {
6
6
  name: ToolbarElementNames;
7
7
  component: ToolbarUIComponentFactory;
8
- }) => EditorCommand;
8
+ }) => void;
9
9
  };
10
10
  }>;
11
- type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
- export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom';
11
+ export type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
+ export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom' | 'spellCheck';
13
13
  export type ToolbarElementConfig = {
14
14
  name: ToolbarElementNames;
15
15
  enabled?: (componentRegistry: ComponentRegistry) => boolean;
16
16
  };
17
17
  export type PrimaryToolbarPluginState = {
18
- componentRegistry: ComponentRegistry;
19
18
  components: ToolbarUIComponentFactory[];
20
19
  };
21
- export {};
@@ -0,0 +1,6 @@
1
+ import type { ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
+ import type { ComponentRegistry, ToolbarElementNames } from './types';
3
+ export declare const registerComponent: (componentRegistry: ComponentRegistry) => ({ name, component, }: {
4
+ name: ToolbarElementNames;
5
+ component: ToolbarUIComponentFactory;
6
+ }) => void;
@@ -1,8 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import type { PrimaryToolbarPluginState } from './types';
3
+ import type { ComponentRegistry, PrimaryToolbarPluginState } from './types';
4
4
  export declare const primaryToolbarPluginKey: PluginKey<PrimaryToolbarPluginState>;
5
- export declare enum PrimaryToolbarPluginAction {
6
- REGISTER = 0
7
- }
8
- export declare const createPlugin: () => SafePlugin<PrimaryToolbarPluginState>;
5
+ export declare const createPlugin: (componentRegistry: ComponentRegistry) => SafePlugin<PrimaryToolbarPluginState>;
@@ -1,3 +1,3 @@
1
1
  import type { ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
- import type { PrimaryToolbarPluginState } from './types';
3
- export declare const getToolbarComponents: (pluginState: PrimaryToolbarPluginState) => ToolbarUIComponentFactory[];
2
+ import type { ComponentRegistry } from './types';
3
+ export declare const getToolbarComponents: (componentRegistry: ComponentRegistry) => ToolbarUIComponentFactory[];
@@ -1,21 +1,19 @@
1
- import type { EditorCommand, NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
2
  export type PrimaryToolbarPlugin = NextEditorPlugin<'primaryToolbar', {
3
3
  sharedState: PrimaryToolbarPluginState | undefined;
4
- commands: {
4
+ actions: {
5
5
  registerComponent: ({ name, component, }: {
6
6
  name: ToolbarElementNames;
7
7
  component: ToolbarUIComponentFactory;
8
- }) => EditorCommand;
8
+ }) => void;
9
9
  };
10
10
  }>;
11
- type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
- export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom';
11
+ export type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
+ export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom' | 'spellCheck';
13
13
  export type ToolbarElementConfig = {
14
14
  name: ToolbarElementNames;
15
15
  enabled?: (componentRegistry: ComponentRegistry) => boolean;
16
16
  };
17
17
  export type PrimaryToolbarPluginState = {
18
- componentRegistry: ComponentRegistry;
19
18
  components: ToolbarUIComponentFactory[];
20
19
  };
21
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-primary-toolbar",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "Primary toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,7 +38,7 @@
38
38
  ".": "./src/index.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@atlaskit/editor-common": "^87.0.0",
41
+ "@atlaskit/editor-common": "^87.3.0",
42
42
  "@atlaskit/editor-prosemirror": "5.0.1",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@emotion/react": "^11.7.1"
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.registerComponent = void 0;
7
- var _pmPlugin = require("./pm-plugin");
8
- var registerComponent = exports.registerComponent = function registerComponent(_ref) {
9
- var name = _ref.name,
10
- component = _ref.component;
11
- return function (_ref2) {
12
- var tr = _ref2.tr;
13
- tr.setMeta(_pmPlugin.primaryToolbarPluginKey, {
14
- type: _pmPlugin.PrimaryToolbarPluginAction.REGISTER,
15
- name: name,
16
- component: component
17
- });
18
- return tr;
19
- };
20
- };
@@ -1,14 +0,0 @@
1
- import { PrimaryToolbarPluginAction, primaryToolbarPluginKey } from './pm-plugin';
2
- export const registerComponent = ({
3
- name,
4
- component
5
- }) => ({
6
- tr
7
- }) => {
8
- tr.setMeta(primaryToolbarPluginKey, {
9
- type: PrimaryToolbarPluginAction.REGISTER,
10
- name,
11
- component
12
- });
13
- return tr;
14
- };
@@ -1,14 +0,0 @@
1
- import { PrimaryToolbarPluginAction, primaryToolbarPluginKey } from './pm-plugin';
2
- export var registerComponent = function registerComponent(_ref) {
3
- var name = _ref.name,
4
- component = _ref.component;
5
- return function (_ref2) {
6
- var tr = _ref2.tr;
7
- tr.setMeta(primaryToolbarPluginKey, {
8
- type: PrimaryToolbarPluginAction.REGISTER,
9
- name: name,
10
- component: component
11
- });
12
- return tr;
13
- };
14
- };
@@ -1,6 +0,0 @@
1
- import type { EditorCommand, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
- import type { ToolbarElementNames } from './types';
3
- export declare const registerComponent: ({ name, component, }: {
4
- name: ToolbarElementNames;
5
- component: ToolbarUIComponentFactory;
6
- }) => EditorCommand;
@@ -1,6 +0,0 @@
1
- import type { EditorCommand, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
- import type { ToolbarElementNames } from './types';
3
- export declare const registerComponent: ({ name, component, }: {
4
- name: ToolbarElementNames;
5
- component: ToolbarUIComponentFactory;
6
- }) => EditorCommand;