@atlaskit/editor-plugin-primary-toolbar 1.3.2 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-primary-toolbar
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#126478](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/126478)
14
+ [`ca1665ebbfe4d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ca1665ebbfe4d) -
15
+ [ED-23435] Store primary toolbar component registry in a plugin variable instead of in plugin
16
+ state to avoid having to add effects to all plugins and enable SSR for the toolbar. [Breaking
17
+ change] Converted registerComponent from the primary toolbar plugin into an action.
18
+
3
19
  ## 1.3.2
4
20
 
5
21
  ### 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
- init: function init() {
25
- var componentRegistry = new Map();
26
-
27
- // Pre-fill registry with the separator component
28
- componentRegistry.set('separator', _separator.default);
15
+ init: function init(_config, editorState) {
29
16
  return {
30
- componentRegistry: componentRegistry,
31
- components: []
17
+ components: (0, _toolbarConfiguration.getToolbarComponents)(componentRegistry, editorState)
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, editorState) {
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, editorState);
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
  }
@@ -37,8 +37,10 @@ var blockTypeGroup = [{
37
37
  name: 'blockType'
38
38
  }, {
39
39
  name: 'separator',
40
- enabled: function enabled(componentRegistry) {
41
- return componentRegistry.has('blockType');
40
+ enabled: function enabled(componentRegistry, editorState) {
41
+ return componentRegistry.has('blockType') &&
42
+ // Use case where you want to have the block plugin but not render any toolbar items (when you exclude headings), we should be able to get rid of this when we split block type plugin up and check for the presence of the heading plugin directly
43
+ !!editorState.schema.nodes.heading;
42
44
  }
43
45
  }];
44
46
  var textFormattingGroup = [{
@@ -77,13 +79,6 @@ var listFormatting = [{
77
79
  }];
78
80
  var insertBlockGroup = [{
79
81
  name: 'insertBlock'
80
- }, {
81
- name: 'separator',
82
- enabled: function enabled(componentRegistry) {
83
- return componentRegistry.has('insertBlock') &&
84
- // is last group in the toolbar
85
- !componentRegistry.has('beforePrimaryToolbar') && !componentRegistry.has('avatarGroup') && !componentRegistry.has('findReplace') && !componentRegistry.has('aiExperience') && !componentRegistry.has('loom');
86
- }
87
82
  }];
88
83
  var others = [{
89
84
  name: 'beforePrimaryToolbar'
@@ -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: (_config, editorState) => ({
10
+ components: getToolbarComponents(componentRegistry, editorState)
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, editorState) => toolbarConfiguration.filter(toolbarElement => typeof toolbarElement.enabled === 'undefined' || toolbarElement.enabled(componentRegistry, editorState)).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
  }
@@ -23,7 +23,9 @@ const blockTypeGroup = [{
23
23
  name: 'blockType'
24
24
  }, {
25
25
  name: 'separator',
26
- enabled: componentRegistry => componentRegistry.has('blockType')
26
+ enabled: (componentRegistry, editorState) => componentRegistry.has('blockType') &&
27
+ // Use case where you want to have the block plugin but not render any toolbar items (when you exclude headings), we should be able to get rid of this when we split block type plugin up and check for the presence of the heading plugin directly
28
+ !!editorState.schema.nodes.heading
27
29
  }];
28
30
  const textFormattingGroup = [{
29
31
  name: 'textFormatting'
@@ -53,11 +55,6 @@ const listFormatting = [{
53
55
  }];
54
56
  const insertBlockGroup = [{
55
57
  name: 'insertBlock'
56
- }, {
57
- name: 'separator',
58
- enabled: componentRegistry => componentRegistry.has('insertBlock') &&
59
- // is last group in the toolbar
60
- !componentRegistry.has('beforePrimaryToolbar') && !componentRegistry.has('avatarGroup') && !componentRegistry.has('findReplace') && !componentRegistry.has('aiExperience') && !componentRegistry.has('loom')
61
58
  }];
62
59
  const others = [{
63
60
  name: 'beforePrimaryToolbar'
@@ -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
- init: function init() {
18
- var componentRegistry = new Map();
19
-
20
- // Pre-fill registry with the separator component
21
- componentRegistry.set('separator', Separator);
9
+ init: function init(_config, editorState) {
22
10
  return {
23
- componentRegistry: componentRegistry,
24
- components: []
11
+ components: getToolbarComponents(componentRegistry, editorState)
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, editorState) {
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, editorState);
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
  }
@@ -31,8 +31,10 @@ var blockTypeGroup = [{
31
31
  name: 'blockType'
32
32
  }, {
33
33
  name: 'separator',
34
- enabled: function enabled(componentRegistry) {
35
- return componentRegistry.has('blockType');
34
+ enabled: function enabled(componentRegistry, editorState) {
35
+ return componentRegistry.has('blockType') &&
36
+ // Use case where you want to have the block plugin but not render any toolbar items (when you exclude headings), we should be able to get rid of this when we split block type plugin up and check for the presence of the heading plugin directly
37
+ !!editorState.schema.nodes.heading;
36
38
  }
37
39
  }];
38
40
  var textFormattingGroup = [{
@@ -71,13 +73,6 @@ var listFormatting = [{
71
73
  }];
72
74
  var insertBlockGroup = [{
73
75
  name: 'insertBlock'
74
- }, {
75
- name: 'separator',
76
- enabled: function enabled(componentRegistry) {
77
- return componentRegistry.has('insertBlock') &&
78
- // is last group in the toolbar
79
- !componentRegistry.has('beforePrimaryToolbar') && !componentRegistry.has('avatarGroup') && !componentRegistry.has('findReplace') && !componentRegistry.has('aiExperience') && !componentRegistry.has('loom');
80
- }
81
76
  }];
82
77
  var others = [{
83
78
  name: 'beforePrimaryToolbar'
@@ -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,4 @@
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 { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { ComponentRegistry } from './types';
4
+ export declare const getToolbarComponents: (componentRegistry: ComponentRegistry, editorState: EditorState) => ToolbarUIComponentFactory[];
@@ -1,21 +1,20 @@
1
- import type { EditorCommand, NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
3
  export type PrimaryToolbarPlugin = NextEditorPlugin<'primaryToolbar', {
3
4
  sharedState: PrimaryToolbarPluginState | undefined;
4
- commands: {
5
+ actions: {
5
6
  registerComponent: ({ name, component, }: {
6
7
  name: ToolbarElementNames;
7
8
  component: ToolbarUIComponentFactory;
8
- }) => EditorCommand;
9
+ }) => void;
9
10
  };
10
11
  }>;
11
- type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
+ export type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
13
  export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom' | 'spellCheck';
13
14
  export type ToolbarElementConfig = {
14
15
  name: ToolbarElementNames;
15
- enabled?: (componentRegistry: ComponentRegistry) => boolean;
16
+ enabled?: (componentRegistry: ComponentRegistry, editorState: EditorState) => boolean;
16
17
  };
17
18
  export type PrimaryToolbarPluginState = {
18
- componentRegistry: ComponentRegistry;
19
19
  components: ToolbarUIComponentFactory[];
20
20
  };
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,4 @@
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 { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { ComponentRegistry } from './types';
4
+ export declare const getToolbarComponents: (componentRegistry: ComponentRegistry, editorState: EditorState) => ToolbarUIComponentFactory[];
@@ -1,21 +1,20 @@
1
- import type { EditorCommand, NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin, ToolbarUIComponentFactory } from '@atlaskit/editor-common/types';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
3
  export type PrimaryToolbarPlugin = NextEditorPlugin<'primaryToolbar', {
3
4
  sharedState: PrimaryToolbarPluginState | undefined;
4
- commands: {
5
+ actions: {
5
6
  registerComponent: ({ name, component, }: {
6
7
  name: ToolbarElementNames;
7
8
  component: ToolbarUIComponentFactory;
8
- }) => EditorCommand;
9
+ }) => void;
9
10
  };
10
11
  }>;
11
- type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
+ export type ComponentRegistry = Map<string, ToolbarUIComponentFactory>;
12
13
  export type ToolbarElementNames = 'separator' | 'undoRedoPlugin' | 'blockType' | 'textFormatting' | 'alignment' | 'textColor' | 'highlight' | 'toolbarListsIndentation' | 'insertBlock' | 'beforePrimaryToolbar' | 'avatarGroup' | 'findReplace' | 'aiExperience' | 'loom' | 'spellCheck';
13
14
  export type ToolbarElementConfig = {
14
15
  name: ToolbarElementNames;
15
- enabled?: (componentRegistry: ComponentRegistry) => boolean;
16
+ enabled?: (componentRegistry: ComponentRegistry, editorState: EditorState) => boolean;
16
17
  };
17
18
  export type PrimaryToolbarPluginState = {
18
- componentRegistry: ComponentRegistry;
19
19
  components: ToolbarUIComponentFactory[];
20
20
  };
21
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-primary-toolbar",
3
- "version": "1.3.2",
3
+ "version": "2.0.1",
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.1.0",
41
+ "@atlaskit/editor-common": "^88.0.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;