@atlaskit/editor-plugin-toolbar 0.1.0 → 0.2.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,37 @@
1
1
  # @atlaskit/editor-plugin-toolbar
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#199487](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199487)
14
+ [`54098ba4cc83c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/54098ba4cc83c) -
15
+ Add LinkSection and TextSection and add logic to hide them when toolbar is pinned. Add
16
+ UserPreferencesPlugin and EditorViewModePlugin as a dependency to editor-plugin-toolbar.
17
+
18
+ ### Patch Changes
19
+
20
+ - [#199353](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199353)
21
+ [`22cab8325fc62`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22cab8325fc62) -
22
+ [ux] [ED-28760] Fix editor lose focus and hence editing flow is interrupted. This is done for 2
23
+ components
24
+
25
+ - Dropdown
26
+ - Create context ToolbarUIContext for toolbar consumers to access consumer specific state and
27
+ callbacks
28
+ - Define onDropdownOpenChanged callback for selection toolbars so that editor regains focus
29
+ after dropdown is closed
30
+ - Button
31
+ - Call preventDefault on mouseDown to prevent button takes away focus
32
+
33
+ - Updated dependencies
34
+
3
35
  ## 0.1.0
4
36
 
5
37
  ### Minor Changes
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-cc/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-cc/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-cc/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-cc/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-cc/tsconfig.json"
28
34
  },
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-dev-agents/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-dev-agents/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-dev-agents/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-dev-agents/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-dev-agents/tsconfig.json"
28
34
  },
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-jira/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-jira/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-jira/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-jira/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-jira/tsconfig.json"
28
34
  },
@@ -0,0 +1,42 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.passionfruit.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../passionfruit/tsDist/@atlaskit__editor-plugin-toolbar/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-passionfruit/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-selection/afm-passionfruit/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-user-intent/afm-passionfruit/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-passionfruit/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-toolbar/afm-passionfruit/tsconfig.json"
34
+ },
35
+ {
36
+ "path": "../../editor-toolbar-model/afm-passionfruit/tsconfig.json"
37
+ },
38
+ {
39
+ "path": "../../editor-common/afm-passionfruit/tsconfig.json"
40
+ }
41
+ ]
42
+ }
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-post-office/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-post-office/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-post-office/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-post-office/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-post-office/tsconfig.json"
28
34
  },
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-rovo-extension/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-rovo-extension/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-rovo-extension/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-rovo-extension/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-rovo-extension/tsconfig.json"
28
34
  },
@@ -17,12 +17,18 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
+ {
21
+ "path": "../../editor-plugin-editor-viewmode/afm-townsquare/tsconfig.json"
22
+ },
20
23
  {
21
24
  "path": "../../editor-plugin-selection/afm-townsquare/tsconfig.json"
22
25
  },
23
26
  {
24
27
  "path": "../../editor-plugin-user-intent/afm-townsquare/tsconfig.json"
25
28
  },
29
+ {
30
+ "path": "../../editor-plugin-user-preferences/afm-townsquare/tsconfig.json"
31
+ },
26
32
  {
27
33
  "path": "../../editor-toolbar/afm-townsquare/tsconfig.json"
28
34
  },
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.volt.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../volt/tsDist/@atlaskit__editor-plugin-toolbar/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*"
18
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../editor-plugin-selection/afm-volt/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-user-intent/afm-volt/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-toolbar/afm-volt/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-toolbar-model/afm-volt/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-common/afm-volt/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -12,7 +12,7 @@ var _toolbarComponents = require("./ui/toolbar-components");
12
12
  var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
13
13
  var api = _ref.api;
14
14
  var registry = (0, _editorToolbarModel.createComponentRegistry)();
15
- registry.register((0, _toolbarComponents.getToolbarComponents)());
15
+ registry.register((0, _toolbarComponents.getToolbarComponents)(api));
16
16
  return {
17
17
  name: 'toolbar',
18
18
  actions: {
@@ -45,6 +45,8 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
45
45
  }
46
46
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
47
47
  editorView: editorView
48
+ }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarUIProvider, {
49
+ api: api
48
50
  }, /*#__PURE__*/_react.default.createElement(_editorToolbarModel.ToolbarModelRenderer, {
49
51
  toolbar: toolbar,
50
52
  components: components,
@@ -53,7 +55,7 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
53
55
  menuSection: _editorToolbar.ToolbarDropdownItemSection,
54
56
  group: _editorToolbar.ToolbarButtonGroup
55
57
  }
56
- })));
58
+ }))));
57
59
  };
58
60
  var getDomRefFromSelection = function getDomRefFromSelection(view
59
61
  // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TextSection = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
11
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
12
+ var shouldShowTextSection = function shouldShowTextSection(editMode, toolbar, toolbarDocking) {
13
+ if (editMode === 'view') {
14
+ return false;
15
+ }
16
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
17
+ return true;
18
+ }
19
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.PRIMARY_TOOLBAR && toolbarDocking !== 'none') {
20
+ return true;
21
+ }
22
+ return false;
23
+ };
24
+ var TextSection = exports.TextSection = function TextSection(_ref) {
25
+ var children = _ref.children,
26
+ parents = _ref.parents,
27
+ api = _ref.api;
28
+ var editMode = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'editorViewMode.mode');
29
+ var toolbarDocking = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userPreferences.preferences.toolbarDockingPosition');
30
+ var toolbar = parents.find(function (parent) {
31
+ return parent.type === 'toolbar';
32
+ });
33
+ if (!shouldShowTextSection(editMode, toolbar, toolbarDocking)) {
34
+ return null;
35
+ }
36
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarSection, {
37
+ testId: "text-section"
38
+ }, children);
39
+ };
@@ -10,7 +10,8 @@ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
10
  var _editorToolbar = require("@atlaskit/editor-toolbar");
11
11
  var _consts = require("./consts");
12
12
  var _OverflowMenu = require("./OverflowMenu");
13
- var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents() {
13
+ var _TextSection = require("./TextSection");
14
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
14
15
  return [{
15
16
  type: 'toolbar',
16
17
  key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -21,13 +22,34 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
21
22
  }, children);
22
23
  }
23
24
  }, {
24
- type: 'section',
25
- key: 'text-section',
25
+ type: 'toolbar',
26
+ key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
27
+ component: function component(_ref2) {
28
+ var children = _ref2.children;
29
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.PrimaryToolbar, {
30
+ label: "Primary Toolbar"
31
+ }, children);
32
+ }
33
+ }, {
34
+ type: _toolbar.TEXT_SECTION.type,
35
+ key: _toolbar.TEXT_SECTION.key,
26
36
  parents: [{
27
37
  type: 'toolbar',
28
- key: 'inline-text-toolbar',
29
- rank: 200
30
- }]
38
+ key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
39
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION.key]
40
+ }, {
41
+ type: 'toolbar',
42
+ key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
43
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.TEXT_SECTION.key]
44
+ }],
45
+ component: function component(_ref3) {
46
+ var children = _ref3.children,
47
+ parents = _ref3.parents;
48
+ return /*#__PURE__*/_react.default.createElement(_TextSection.TextSection, {
49
+ parents: parents,
50
+ api: api
51
+ }, children);
52
+ }
31
53
  }, {
32
54
  type: _toolbar.OVERFLOW_SECTION.type,
33
55
  key: _toolbar.OVERFLOW_SECTION.key,
@@ -52,8 +74,8 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
52
74
  key: _toolbar.OVERFLOW_GROUP.key,
53
75
  rank: _toolbar.OVERFLOW_GROUP_RANK[_toolbar.OVERFLOW_MENU.key]
54
76
  }],
55
- component: function component(_ref2) {
56
- var children = _ref2.children;
77
+ component: function component(_ref4) {
78
+ var children = _ref4.children;
57
79
  return /*#__PURE__*/_react.default.createElement(_OverflowMenu.OverflowMenu, null, children);
58
80
  }
59
81
  }];
@@ -6,7 +6,7 @@ export const toolbarPlugin = ({
6
6
  api
7
7
  }) => {
8
8
  const registry = createComponentRegistry();
9
- registry.register(getToolbarComponents());
9
+ registry.register(getToolbarComponents(api));
10
10
  return {
11
11
  name: 'toolbar',
12
12
  actions: {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { isSSR } from '@atlaskit/editor-common/core-utils';
3
- import { EditorToolbarProvider } from '@atlaskit/editor-common/toolbar';
3
+ import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor-common/toolbar';
4
4
  import { Popup } from '@atlaskit/editor-common/ui';
5
5
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
6
  import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
@@ -35,6 +35,8 @@ export const SelectionToolbar = ({
35
35
  onPositionCalculated: position => calculateToolbarPositionTrackHead(TOOLBAR_LABEL)(editorView, position)
36
36
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
37
37
  editorView: editorView
38
+ }, /*#__PURE__*/React.createElement(EditorToolbarUIProvider, {
39
+ api: api
38
40
  }, /*#__PURE__*/React.createElement(ToolbarModelRenderer, {
39
41
  toolbar: toolbar,
40
42
  components: components,
@@ -43,7 +45,7 @@ export const SelectionToolbar = ({
43
45
  menuSection: ToolbarDropdownItemSection,
44
46
  group: ToolbarButtonGroup
45
47
  }
46
- })));
48
+ }))));
47
49
  };
48
50
  const getDomRefFromSelection = (view
49
51
  // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
+ import { ToolbarSection } from '@atlaskit/editor-toolbar';
5
+ const shouldShowTextSection = (editMode, toolbar, toolbarDocking) => {
6
+ if (editMode === 'view') {
7
+ return false;
8
+ }
9
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
10
+ return true;
11
+ }
12
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.PRIMARY_TOOLBAR && toolbarDocking !== 'none') {
13
+ return true;
14
+ }
15
+ return false;
16
+ };
17
+ export const TextSection = ({
18
+ children,
19
+ parents,
20
+ api
21
+ }) => {
22
+ const editMode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
23
+ const toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
24
+ const toolbar = parents.find(parent => parent.type === 'toolbar');
25
+ if (!shouldShowTextSection(editMode, toolbar, toolbarDocking)) {
26
+ return null;
27
+ }
28
+ return /*#__PURE__*/React.createElement(ToolbarSection, {
29
+ testId: "text-section"
30
+ }, children);
31
+ };
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- import { OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
- import { Toolbar } from '@atlaskit/editor-toolbar';
2
+ import { OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { PrimaryToolbar, Toolbar } from '@atlaskit/editor-toolbar';
4
4
  import { TOOLBAR_LABEL } from './consts';
5
5
  import { OverflowMenu } from './OverflowMenu';
6
- export const getToolbarComponents = () => {
6
+ import { TextSection } from './TextSection';
7
+ export const getToolbarComponents = api => {
7
8
  return [{
8
9
  type: 'toolbar',
9
10
  key: TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -15,13 +16,34 @@ export const getToolbarComponents = () => {
15
16
  }, children);
16
17
  }
17
18
  }, {
18
- type: 'section',
19
- key: 'text-section',
19
+ type: 'toolbar',
20
+ key: TOOLBARS.PRIMARY_TOOLBAR,
21
+ component: ({
22
+ children
23
+ }) => /*#__PURE__*/React.createElement(PrimaryToolbar, {
24
+ label: "Primary Toolbar"
25
+ }, children)
26
+ }, {
27
+ type: TEXT_SECTION.type,
28
+ key: TEXT_SECTION.key,
20
29
  parents: [{
21
30
  type: 'toolbar',
22
- key: 'inline-text-toolbar',
23
- rank: 200
24
- }]
31
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
32
+ rank: TOOLBAR_RANK[TEXT_SECTION.key]
33
+ }, {
34
+ type: 'toolbar',
35
+ key: TOOLBARS.PRIMARY_TOOLBAR,
36
+ rank: TOOLBAR_RANK[TEXT_SECTION.key]
37
+ }],
38
+ component: ({
39
+ children,
40
+ parents
41
+ }) => {
42
+ return /*#__PURE__*/React.createElement(TextSection, {
43
+ parents: parents,
44
+ api: api
45
+ }, children);
46
+ }
25
47
  }, {
26
48
  type: OVERFLOW_SECTION.type,
27
49
  key: OVERFLOW_SECTION.key,
@@ -5,7 +5,7 @@ import { getToolbarComponents } from './ui/toolbar-components';
5
5
  export var toolbarPlugin = function toolbarPlugin(_ref) {
6
6
  var api = _ref.api;
7
7
  var registry = createComponentRegistry();
8
- registry.register(getToolbarComponents());
8
+ registry.register(getToolbarComponents(api));
9
9
  return {
10
10
  name: 'toolbar',
11
11
  actions: {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { isSSR } from '@atlaskit/editor-common/core-utils';
3
- import { EditorToolbarProvider } from '@atlaskit/editor-common/toolbar';
3
+ import { EditorToolbarProvider, EditorToolbarUIProvider } from '@atlaskit/editor-common/toolbar';
4
4
  import { Popup } from '@atlaskit/editor-common/ui';
5
5
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
6
  import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
@@ -38,6 +38,8 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
38
38
  }
39
39
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
40
40
  editorView: editorView
41
+ }, /*#__PURE__*/React.createElement(EditorToolbarUIProvider, {
42
+ api: api
41
43
  }, /*#__PURE__*/React.createElement(ToolbarModelRenderer, {
42
44
  toolbar: toolbar,
43
45
  components: components,
@@ -46,7 +48,7 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
46
48
  menuSection: ToolbarDropdownItemSection,
47
49
  group: ToolbarButtonGroup
48
50
  }
49
- })));
51
+ }))));
50
52
  };
51
53
  var getDomRefFromSelection = function getDomRefFromSelection(view
52
54
  // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
+ import { ToolbarSection } from '@atlaskit/editor-toolbar';
5
+ var shouldShowTextSection = function shouldShowTextSection(editMode, toolbar, toolbarDocking) {
6
+ if (editMode === 'view') {
7
+ return false;
8
+ }
9
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
10
+ return true;
11
+ }
12
+ if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.PRIMARY_TOOLBAR && toolbarDocking !== 'none') {
13
+ return true;
14
+ }
15
+ return false;
16
+ };
17
+ export var TextSection = function TextSection(_ref) {
18
+ var children = _ref.children,
19
+ parents = _ref.parents,
20
+ api = _ref.api;
21
+ var editMode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
22
+ var toolbarDocking = useSharedPluginStateSelector(api, 'userPreferences.preferences.toolbarDockingPosition');
23
+ var toolbar = parents.find(function (parent) {
24
+ return parent.type === 'toolbar';
25
+ });
26
+ if (!shouldShowTextSection(editMode, toolbar, toolbarDocking)) {
27
+ return null;
28
+ }
29
+ return /*#__PURE__*/React.createElement(ToolbarSection, {
30
+ testId: "text-section"
31
+ }, children);
32
+ };
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- import { OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
- import { Toolbar } from '@atlaskit/editor-toolbar';
2
+ import { OVERFLOW_GROUP, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_SECTION, OVERFLOW_SECTION_RANK, TEXT_SECTION, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { PrimaryToolbar, Toolbar } from '@atlaskit/editor-toolbar';
4
4
  import { TOOLBAR_LABEL } from './consts';
5
5
  import { OverflowMenu } from './OverflowMenu';
6
- export var getToolbarComponents = function getToolbarComponents() {
6
+ import { TextSection } from './TextSection';
7
+ export var getToolbarComponents = function getToolbarComponents(api) {
7
8
  return [{
8
9
  type: 'toolbar',
9
10
  key: TOOLBARS.INLINE_TEXT_TOOLBAR,
@@ -14,13 +15,34 @@ export var getToolbarComponents = function getToolbarComponents() {
14
15
  }, children);
15
16
  }
16
17
  }, {
17
- type: 'section',
18
- key: 'text-section',
18
+ type: 'toolbar',
19
+ key: TOOLBARS.PRIMARY_TOOLBAR,
20
+ component: function component(_ref2) {
21
+ var children = _ref2.children;
22
+ return /*#__PURE__*/React.createElement(PrimaryToolbar, {
23
+ label: "Primary Toolbar"
24
+ }, children);
25
+ }
26
+ }, {
27
+ type: TEXT_SECTION.type,
28
+ key: TEXT_SECTION.key,
19
29
  parents: [{
20
30
  type: 'toolbar',
21
- key: 'inline-text-toolbar',
22
- rank: 200
23
- }]
31
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
32
+ rank: TOOLBAR_RANK[TEXT_SECTION.key]
33
+ }, {
34
+ type: 'toolbar',
35
+ key: TOOLBARS.PRIMARY_TOOLBAR,
36
+ rank: TOOLBAR_RANK[TEXT_SECTION.key]
37
+ }],
38
+ component: function component(_ref3) {
39
+ var children = _ref3.children,
40
+ parents = _ref3.parents;
41
+ return /*#__PURE__*/React.createElement(TextSection, {
42
+ parents: parents,
43
+ api: api
44
+ }, children);
45
+ }
24
46
  }, {
25
47
  type: OVERFLOW_SECTION.type,
26
48
  key: OVERFLOW_SECTION.key,
@@ -45,8 +67,8 @@ export var getToolbarComponents = function getToolbarComponents() {
45
67
  key: OVERFLOW_GROUP.key,
46
68
  rank: OVERFLOW_GROUP_RANK[OVERFLOW_MENU.key]
47
69
  }],
48
- component: function component(_ref2) {
49
- var children = _ref2.children;
70
+ component: function component(_ref4) {
71
+ var children = _ref4.children;
50
72
  return /*#__PURE__*/React.createElement(OverflowMenu, null, children);
51
73
  }
52
74
  }];
@@ -1,9 +1,16 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
2
3
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
3
4
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
5
+ import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
4
6
  import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
5
7
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
6
- dependencies: [OptionalPlugin<UserIntentPlugin>, OptionalPlugin<SelectionPlugin>];
8
+ dependencies: [
9
+ OptionalPlugin<UserIntentPlugin>,
10
+ OptionalPlugin<SelectionPlugin>,
11
+ OptionalPlugin<UserPreferencesPlugin>,
12
+ OptionalPlugin<EditorViewModePlugin>
13
+ ];
7
14
  actions: {
8
15
  registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
9
16
  getComponents: () => Array<RegisterComponent>;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { ToolbarComponentTypes } from '@atlaskit/editor-toolbar-model';
4
+ import type { ToolbarPlugin } from '../toolbarPluginType';
5
+ type TextSectionProps = {
6
+ children: React.ReactNode;
7
+ parents: ToolbarComponentTypes;
8
+ api?: ExtractInjectionAPI<ToolbarPlugin>;
9
+ };
10
+ export declare const TextSection: ({ children, parents, api }: TextSectionProps) => React.JSX.Element | null;
11
+ export {};
@@ -1,2 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
2
  import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
2
- export declare const getToolbarComponents: () => RegisterComponent[];
3
+ import type { ToolbarPlugin } from '../toolbarPluginType';
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>) => RegisterComponent[];
@@ -1,11 +1,15 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
2
3
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
3
4
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
5
+ import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
4
6
  import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
5
7
  export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
6
8
  dependencies: [
7
9
  OptionalPlugin<UserIntentPlugin>,
8
- OptionalPlugin<SelectionPlugin>
10
+ OptionalPlugin<SelectionPlugin>,
11
+ OptionalPlugin<UserPreferencesPlugin>,
12
+ OptionalPlugin<EditorViewModePlugin>
9
13
  ];
10
14
  actions: {
11
15
  registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { ToolbarComponentTypes } from '@atlaskit/editor-toolbar-model';
4
+ import type { ToolbarPlugin } from '../toolbarPluginType';
5
+ type TextSectionProps = {
6
+ children: React.ReactNode;
7
+ parents: ToolbarComponentTypes;
8
+ api?: ExtractInjectionAPI<ToolbarPlugin>;
9
+ };
10
+ export declare const TextSection: ({ children, parents, api }: TextSectionProps) => React.JSX.Element | null;
11
+ export {};
@@ -1,2 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
2
  import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
2
- export declare const getToolbarComponents: () => RegisterComponent[];
3
+ import type { ToolbarPlugin } from '../toolbarPluginType';
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>) => RegisterComponent[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-toolbar",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,16 +31,18 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
+ "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
34
35
  "@atlaskit/editor-plugin-selection": "^3.0.0",
35
36
  "@atlaskit/editor-plugin-user-intent": "^1.1.0",
37
+ "@atlaskit/editor-plugin-user-preferences": "^1.2.0",
36
38
  "@atlaskit/editor-prosemirror": "7.0.0",
37
- "@atlaskit/editor-toolbar": "^0.1.0",
38
- "@atlaskit/editor-toolbar-model": "^0.0.4",
39
+ "@atlaskit/editor-toolbar": "^0.3.0",
40
+ "@atlaskit/editor-toolbar-model": "^0.1.0",
39
41
  "@babel/runtime": "^7.0.0",
40
42
  "react-intl-next": "npm:react-intl@^5.18.1"
41
43
  },
42
44
  "peerDependencies": {
43
- "@atlaskit/editor-common": "^107.19.0",
45
+ "@atlaskit/editor-common": "^107.23.0",
44
46
  "react": "^18.2.0"
45
47
  },
46
48
  "techstack": {