@atlaskit/editor-plugin-toolbar 0.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE.md +11 -0
  3. package/README.md +1 -0
  4. package/afm-cc/tsconfig.json +36 -0
  5. package/afm-jira/tsconfig.json +30 -0
  6. package/afm-post-office/tsconfig.json +30 -0
  7. package/build/tsconfig.json +17 -0
  8. package/dist/cjs/index.js +12 -0
  9. package/dist/cjs/toolbarPlugin.js +34 -0
  10. package/dist/cjs/toolbarPluginType.js +5 -0
  11. package/dist/cjs/ui/SelectionToolbar/index.js +86 -0
  12. package/dist/cjs/ui/consts.js +7 -0
  13. package/dist/cjs/ui/toolbar-components.js +56 -0
  14. package/dist/es2019/index.js +4 -0
  15. package/dist/es2019/toolbarPlugin.js +29 -0
  16. package/dist/es2019/toolbarPluginType.js +1 -0
  17. package/dist/es2019/ui/SelectionToolbar/index.js +76 -0
  18. package/dist/es2019/ui/consts.js +1 -0
  19. package/dist/es2019/ui/toolbar-components.js +51 -0
  20. package/dist/esm/index.js +4 -0
  21. package/dist/esm/toolbarPlugin.js +27 -0
  22. package/dist/esm/toolbarPluginType.js +1 -0
  23. package/dist/esm/ui/SelectionToolbar/index.js +79 -0
  24. package/dist/esm/ui/consts.js +1 -0
  25. package/dist/esm/ui/toolbar-components.js +49 -0
  26. package/dist/types/index.d.ts +2 -0
  27. package/dist/types/toolbarPlugin.d.ts +2 -0
  28. package/dist/types/toolbarPluginType.d.ts +11 -0
  29. package/dist/types/ui/SelectionToolbar/index.d.ts +10 -0
  30. package/dist/types/ui/consts.d.ts +1 -0
  31. package/dist/types/ui/toolbar-components.d.ts +2 -0
  32. package/dist/types-ts4.5/index.d.ts +2 -0
  33. package/dist/types-ts4.5/toolbarPlugin.d.ts +2 -0
  34. package/dist/types-ts4.5/toolbarPluginType.d.ts +14 -0
  35. package/dist/types-ts4.5/ui/SelectionToolbar/index.d.ts +10 -0
  36. package/dist/types-ts4.5/ui/consts.d.ts +1 -0
  37. package/dist/types-ts4.5/ui/toolbar-components.d.ts +2 -0
  38. package/docs/0-intro.tsx +43 -0
  39. package/package.json +84 -0
  40. package/tsconfig.json +8 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @atlaskit/editor-plugin-toolbar
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#192090](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/192090)
8
+ [`d1a5fb90b8bfd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d1a5fb90b8bfd) -
9
+ Add editor-plugin-toolbar package, which stores toolbar components and provides an api to register
10
+ them, using editor-toolbar-model libary as state manager. This plugin also renders a new selection
11
+ toolbar based on the new components.
12
+ - Updated dependencies
package/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
4
+ compliance with the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is
9
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10
+ implied. See the License for the specific language governing permissions and limitations under the
11
+ License.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Editor plugin toolbar
@@ -0,0 +1,36 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.confluence.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "composite": true,
6
+ "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-toolbar",
7
+ "rootDir": "../"
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-cc/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-user-intent/afm-cc/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-toolbar/afm-cc/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-toolbar-model/afm-cc/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-common/afm-cc/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.jira.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../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-toolbar/afm-jira/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-toolbar-model/afm-jira/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-common/afm-jira/tsconfig.json"
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.post-office.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../post-office/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-toolbar/afm-post-office/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-toolbar-model/afm-post-office/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "paths": {}
6
+ },
7
+ "include": [
8
+ "../src/**/*.ts",
9
+ "../src/**/*.tsx"
10
+ ],
11
+ "exclude": [
12
+ "../src/**/__tests__/*",
13
+ "../src/**/*.test.*",
14
+ "../src/**/test.*",
15
+ "../src/**/examples.*"
16
+ ]
17
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "toolbarPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _toolbarPlugin.toolbarPlugin;
10
+ }
11
+ });
12
+ var _toolbarPlugin = require("./toolbarPlugin");
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.toolbarPlugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
10
+ var _SelectionToolbar = require("./ui/SelectionToolbar");
11
+ var _toolbarComponents = require("./ui/toolbar-components");
12
+ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
13
+ var api = _ref.api;
14
+ var registry = (0, _editorToolbarModel.createComponentRegistry)();
15
+ registry.register((0, _toolbarComponents.getToolbarComponents)());
16
+ return {
17
+ name: 'toolbar',
18
+ actions: {
19
+ registerComponents: function registerComponents(toolbarComponents) {
20
+ registry.register(toolbarComponents);
21
+ },
22
+ getComponents: function getComponents() {
23
+ return registry.components;
24
+ }
25
+ },
26
+ contentComponent: function contentComponent(_ref2) {
27
+ var editorView = _ref2.editorView;
28
+ return /*#__PURE__*/_react.default.createElement(_SelectionToolbar.SelectionToolbar, {
29
+ api: api,
30
+ editorView: editorView
31
+ });
32
+ }
33
+ };
34
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SelectionToolbar = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _coreUtils = require("@atlaskit/editor-common/core-utils");
10
+ var _ui = require("@atlaskit/editor-common/ui");
11
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
12
+ var _utils = require("@atlaskit/editor-common/utils");
13
+ var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
16
+ var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
17
+ var _consts = require("../consts");
18
+ var isToolbarComponent = function isToolbarComponent(component) {
19
+ return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
20
+ };
21
+ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
22
+ var api = _ref.api,
23
+ editorView = _ref.editorView;
24
+ var components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
25
+ var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
26
+ return isToolbarComponent(component);
27
+ });
28
+ var currentUserIntent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userIntent.currentUserIntent');
29
+ // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
30
+ // @ts-expect-error
31
+ var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
32
+ var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof _state.TextSelection;
33
+ if (!components || !toolbar) {
34
+ return null;
35
+ }
36
+ if (!isTextSelection || currentUserIntent === 'dragging' || (0, _coreUtils.isSSR)()) {
37
+ return null;
38
+ }
39
+ return /*#__PURE__*/_react.default.createElement(_ui.Popup, {
40
+ offset: [0, 10],
41
+ target: getDomRefFromSelection(editorView),
42
+ onPositionCalculated: function onPositionCalculated(position) {
43
+ return (0, _utils.calculateToolbarPositionTrackHead)(_consts.TOOLBAR_LABEL)(editorView, position);
44
+ }
45
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbarModel.ToolbarModelRenderer, {
46
+ toolbar: toolbar,
47
+ components: components,
48
+ fallbacks: {
49
+ section: _editorToolbar.ToolbarSection,
50
+ menuSection: _editorToolbar.ToolbarDropdownItemSection,
51
+ group: _editorToolbar.ToolbarButtonGroup
52
+ }
53
+ }));
54
+ };
55
+ var getDomRefFromSelection = function getDomRefFromSelection(view
56
+ // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
57
+ ) {
58
+ try {
59
+ // Ignored via go/ees005
60
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
61
+ return (0, _utils2.findDomRefAtPos)(view.state.selection.from, view.domAtPos.bind(view));
62
+ // Ignored via go/ees005
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ } catch (error) {
65
+ // // eslint-disable-next-line no-console
66
+ // console.warn(error);
67
+ // if (dispatchAnalyticsEvent) {
68
+ // const payload: AnalyticsEventPayload = {
69
+ // action: ACTION.ERRORED,
70
+ // actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
71
+ // eventType: EVENT_TYPE.OPERATIONAL,
72
+ // attributes: {
73
+ // component: CONTENT_COMPONENT.FLOATING_TOOLBAR,
74
+ // selection: view.state.selection.toJSON(),
75
+ // position: view.state.selection.from,
76
+ // docSize: view.state.doc.nodeSize,
77
+ // error: error.toString(),
78
+ // // @ts-expect-error - Object literal may only specify known properties, 'errorStack' does not exist in type
79
+ // // This error was introduced after upgrading to TypeScript 5
80
+ // errorStack: error.stack || undefined,
81
+ // },
82
+ // };
83
+ // dispatchAnalyticsEvent(payload);
84
+ // }
85
+ }
86
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TOOLBAR_LABEL = void 0;
7
+ var TOOLBAR_LABEL = exports.TOOLBAR_LABEL = 'Editor Toolbar';
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
10
+ var _consts = require("./consts");
11
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents() {
12
+ return [{
13
+ type: 'toolbar',
14
+ key: 'inline-text-toolbar',
15
+ component: function component(_ref) {
16
+ var children = _ref.children;
17
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.Toolbar, {
18
+ label: _consts.TOOLBAR_LABEL
19
+ }, children);
20
+ }
21
+ },
22
+ // TODO: ED-28684 - clean up AI code and move to AI package
23
+ {
24
+ type: 'section',
25
+ key: 'ai-section',
26
+ parents: [{
27
+ type: 'toolbar',
28
+ key: 'inline-text-toolbar',
29
+ rank: 100
30
+ }]
31
+ }, {
32
+ type: 'group',
33
+ key: 'ai-group',
34
+ parents: [{
35
+ type: 'section',
36
+ key: 'ai-section',
37
+ rank: 100
38
+ }]
39
+ }, {
40
+ type: 'button',
41
+ key: 'ai-button',
42
+ parents: [{
43
+ type: 'group',
44
+ key: 'ai-group',
45
+ rank: 100
46
+ }],
47
+ component: function component(_ref2) {
48
+ var groupLocation = _ref2.groupLocation;
49
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
50
+ label: "AI",
51
+ icon: _editorToolbar.AIChatIcon,
52
+ groupLocation: groupLocation
53
+ }, "AI");
54
+ }
55
+ }];
56
+ };
@@ -0,0 +1,4 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ // Entry file in package.json
3
+
4
+ export { toolbarPlugin } from './toolbarPlugin';
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
3
+ import { SelectionToolbar } from './ui/SelectionToolbar';
4
+ import { getToolbarComponents } from './ui/toolbar-components';
5
+ export const toolbarPlugin = ({
6
+ api
7
+ }) => {
8
+ const registry = createComponentRegistry();
9
+ registry.register(getToolbarComponents());
10
+ return {
11
+ name: 'toolbar',
12
+ actions: {
13
+ registerComponents: toolbarComponents => {
14
+ registry.register(toolbarComponents);
15
+ },
16
+ getComponents: () => {
17
+ return registry.components;
18
+ }
19
+ },
20
+ contentComponent: ({
21
+ editorView
22
+ }) => {
23
+ return /*#__PURE__*/React.createElement(SelectionToolbar, {
24
+ api: api,
25
+ editorView: editorView
26
+ });
27
+ }
28
+ };
29
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import React from 'react';
2
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { Popup } from '@atlaskit/editor-common/ui';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
6
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
+ import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
9
+ import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
10
+ import { TOOLBAR_LABEL } from '../consts';
11
+ const isToolbarComponent = component => {
12
+ return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
13
+ };
14
+ export const SelectionToolbar = ({
15
+ api,
16
+ editorView
17
+ }) => {
18
+ const components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
19
+ const toolbar = components === null || components === void 0 ? void 0 : components.find(component => isToolbarComponent(component));
20
+ const currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
21
+ // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
22
+ // @ts-expect-error
23
+ const selection = useSharedPluginStateSelector(api, 'selection.selection');
24
+ const isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
25
+ if (!components || !toolbar) {
26
+ return null;
27
+ }
28
+ if (!isTextSelection || currentUserIntent === 'dragging' || isSSR()) {
29
+ return null;
30
+ }
31
+ return /*#__PURE__*/React.createElement(Popup, {
32
+ offset: [0, 10],
33
+ target: getDomRefFromSelection(editorView),
34
+ onPositionCalculated: position => calculateToolbarPositionTrackHead(TOOLBAR_LABEL)(editorView, position)
35
+ }, /*#__PURE__*/React.createElement(ToolbarModelRenderer, {
36
+ toolbar: toolbar,
37
+ components: components,
38
+ fallbacks: {
39
+ section: ToolbarSection,
40
+ menuSection: ToolbarDropdownItemSection,
41
+ group: ToolbarButtonGroup
42
+ }
43
+ }));
44
+ };
45
+ const getDomRefFromSelection = (view
46
+ // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
47
+ ) => {
48
+ try {
49
+ // Ignored via go/ees005
50
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
51
+ return findDomRefAtPos(view.state.selection.from, view.domAtPos.bind(view));
52
+ // Ignored via go/ees005
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ } catch (error) {
55
+ // // eslint-disable-next-line no-console
56
+ // console.warn(error);
57
+ // if (dispatchAnalyticsEvent) {
58
+ // const payload: AnalyticsEventPayload = {
59
+ // action: ACTION.ERRORED,
60
+ // actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
61
+ // eventType: EVENT_TYPE.OPERATIONAL,
62
+ // attributes: {
63
+ // component: CONTENT_COMPONENT.FLOATING_TOOLBAR,
64
+ // selection: view.state.selection.toJSON(),
65
+ // position: view.state.selection.from,
66
+ // docSize: view.state.doc.nodeSize,
67
+ // error: error.toString(),
68
+ // // @ts-expect-error - Object literal may only specify known properties, 'errorStack' does not exist in type
69
+ // // This error was introduced after upgrading to TypeScript 5
70
+ // errorStack: error.stack || undefined,
71
+ // },
72
+ // };
73
+ // dispatchAnalyticsEvent(payload);
74
+ // }
75
+ }
76
+ };
@@ -0,0 +1 @@
1
+ export const TOOLBAR_LABEL = 'Editor Toolbar';
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { AIChatIcon, Toolbar, ToolbarButton } from '@atlaskit/editor-toolbar';
3
+ import { TOOLBAR_LABEL } from './consts';
4
+ export const getToolbarComponents = () => {
5
+ return [{
6
+ type: 'toolbar',
7
+ key: 'inline-text-toolbar',
8
+ component: ({
9
+ children
10
+ }) => {
11
+ return /*#__PURE__*/React.createElement(Toolbar, {
12
+ label: TOOLBAR_LABEL
13
+ }, children);
14
+ }
15
+ },
16
+ // TODO: ED-28684 - clean up AI code and move to AI package
17
+ {
18
+ type: 'section',
19
+ key: 'ai-section',
20
+ parents: [{
21
+ type: 'toolbar',
22
+ key: 'inline-text-toolbar',
23
+ rank: 100
24
+ }]
25
+ }, {
26
+ type: 'group',
27
+ key: 'ai-group',
28
+ parents: [{
29
+ type: 'section',
30
+ key: 'ai-section',
31
+ rank: 100
32
+ }]
33
+ }, {
34
+ type: 'button',
35
+ key: 'ai-button',
36
+ parents: [{
37
+ type: 'group',
38
+ key: 'ai-group',
39
+ rank: 100
40
+ }],
41
+ component: ({
42
+ groupLocation
43
+ }) => {
44
+ return /*#__PURE__*/React.createElement(ToolbarButton, {
45
+ label: "AI",
46
+ icon: AIChatIcon,
47
+ groupLocation: groupLocation
48
+ }, "AI");
49
+ }
50
+ }];
51
+ };
@@ -0,0 +1,4 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ // Entry file in package.json
3
+
4
+ export { toolbarPlugin } from './toolbarPlugin';
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
3
+ import { SelectionToolbar } from './ui/SelectionToolbar';
4
+ import { getToolbarComponents } from './ui/toolbar-components';
5
+ export var toolbarPlugin = function toolbarPlugin(_ref) {
6
+ var api = _ref.api;
7
+ var registry = createComponentRegistry();
8
+ registry.register(getToolbarComponents());
9
+ return {
10
+ name: 'toolbar',
11
+ actions: {
12
+ registerComponents: function registerComponents(toolbarComponents) {
13
+ registry.register(toolbarComponents);
14
+ },
15
+ getComponents: function getComponents() {
16
+ return registry.components;
17
+ }
18
+ },
19
+ contentComponent: function contentComponent(_ref2) {
20
+ var editorView = _ref2.editorView;
21
+ return /*#__PURE__*/React.createElement(SelectionToolbar, {
22
+ api: api,
23
+ editorView: editorView
24
+ });
25
+ }
26
+ };
27
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { Popup } from '@atlaskit/editor-common/ui';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
6
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
+ import { ToolbarSection, ToolbarButtonGroup, ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
9
+ import { ToolbarModelRenderer } from '@atlaskit/editor-toolbar-model';
10
+ import { TOOLBAR_LABEL } from '../consts';
11
+ var isToolbarComponent = function isToolbarComponent(component) {
12
+ return component.type === 'toolbar' && component.key === 'inline-text-toolbar';
13
+ };
14
+ export var SelectionToolbar = function SelectionToolbar(_ref) {
15
+ var api = _ref.api,
16
+ editorView = _ref.editorView;
17
+ var components = api === null || api === void 0 ? void 0 : api.toolbar.actions.getComponents();
18
+ var toolbar = components === null || components === void 0 ? void 0 : components.find(function (component) {
19
+ return isToolbarComponent(component);
20
+ });
21
+ var currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
22
+ // TODO: ED-28735 - figure out a better way to control this - needed to re-render on selection change
23
+ // @ts-expect-error
24
+ var selection = useSharedPluginStateSelector(api, 'selection.selection');
25
+ var isTextSelection = !editorView.state.selection.empty && editorView.state.selection instanceof TextSelection;
26
+ if (!components || !toolbar) {
27
+ return null;
28
+ }
29
+ if (!isTextSelection || currentUserIntent === 'dragging' || isSSR()) {
30
+ return null;
31
+ }
32
+ return /*#__PURE__*/React.createElement(Popup, {
33
+ offset: [0, 10],
34
+ target: getDomRefFromSelection(editorView),
35
+ onPositionCalculated: function onPositionCalculated(position) {
36
+ return calculateToolbarPositionTrackHead(TOOLBAR_LABEL)(editorView, position);
37
+ }
38
+ }, /*#__PURE__*/React.createElement(ToolbarModelRenderer, {
39
+ toolbar: toolbar,
40
+ components: components,
41
+ fallbacks: {
42
+ section: ToolbarSection,
43
+ menuSection: ToolbarDropdownItemSection,
44
+ group: ToolbarButtonGroup
45
+ }
46
+ }));
47
+ };
48
+ var getDomRefFromSelection = function getDomRefFromSelection(view
49
+ // dispatchAnalyticsEvent?: DispatchAnalyticsEvent,
50
+ ) {
51
+ try {
52
+ // Ignored via go/ees005
53
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
54
+ return findDomRefAtPos(view.state.selection.from, view.domAtPos.bind(view));
55
+ // Ignored via go/ees005
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ } catch (error) {
58
+ // // eslint-disable-next-line no-console
59
+ // console.warn(error);
60
+ // if (dispatchAnalyticsEvent) {
61
+ // const payload: AnalyticsEventPayload = {
62
+ // action: ACTION.ERRORED,
63
+ // actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
64
+ // eventType: EVENT_TYPE.OPERATIONAL,
65
+ // attributes: {
66
+ // component: CONTENT_COMPONENT.FLOATING_TOOLBAR,
67
+ // selection: view.state.selection.toJSON(),
68
+ // position: view.state.selection.from,
69
+ // docSize: view.state.doc.nodeSize,
70
+ // error: error.toString(),
71
+ // // @ts-expect-error - Object literal may only specify known properties, 'errorStack' does not exist in type
72
+ // // This error was introduced after upgrading to TypeScript 5
73
+ // errorStack: error.stack || undefined,
74
+ // },
75
+ // };
76
+ // dispatchAnalyticsEvent(payload);
77
+ // }
78
+ }
79
+ };
@@ -0,0 +1 @@
1
+ export var TOOLBAR_LABEL = 'Editor Toolbar';
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { AIChatIcon, Toolbar, ToolbarButton } from '@atlaskit/editor-toolbar';
3
+ import { TOOLBAR_LABEL } from './consts';
4
+ export var getToolbarComponents = function getToolbarComponents() {
5
+ return [{
6
+ type: 'toolbar',
7
+ key: 'inline-text-toolbar',
8
+ component: function component(_ref) {
9
+ var children = _ref.children;
10
+ return /*#__PURE__*/React.createElement(Toolbar, {
11
+ label: TOOLBAR_LABEL
12
+ }, children);
13
+ }
14
+ },
15
+ // TODO: ED-28684 - clean up AI code and move to AI package
16
+ {
17
+ type: 'section',
18
+ key: 'ai-section',
19
+ parents: [{
20
+ type: 'toolbar',
21
+ key: 'inline-text-toolbar',
22
+ rank: 100
23
+ }]
24
+ }, {
25
+ type: 'group',
26
+ key: 'ai-group',
27
+ parents: [{
28
+ type: 'section',
29
+ key: 'ai-section',
30
+ rank: 100
31
+ }]
32
+ }, {
33
+ type: 'button',
34
+ key: 'ai-button',
35
+ parents: [{
36
+ type: 'group',
37
+ key: 'ai-group',
38
+ rank: 100
39
+ }],
40
+ component: function component(_ref2) {
41
+ var groupLocation = _ref2.groupLocation;
42
+ return /*#__PURE__*/React.createElement(ToolbarButton, {
43
+ label: "AI",
44
+ icon: AIChatIcon,
45
+ groupLocation: groupLocation
46
+ }, "AI");
47
+ }
48
+ }];
49
+ };
@@ -0,0 +1,2 @@
1
+ export { toolbarPlugin } from './toolbarPlugin';
2
+ export type { ToolbarPlugin } from './toolbarPluginType';
@@ -0,0 +1,2 @@
1
+ import type { ToolbarPlugin } from './toolbarPluginType';
2
+ export declare const toolbarPlugin: ToolbarPlugin;
@@ -0,0 +1,11 @@
1
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
3
+ import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
4
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
5
+ export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
6
+ dependencies: [OptionalPlugin<UserIntentPlugin>, OptionalPlugin<SelectionPlugin>];
7
+ actions: {
8
+ registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
9
+ getComponents: () => Array<RegisterComponent>;
10
+ };
11
+ }>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { ToolbarPlugin } from '../../toolbarPluginType';
5
+ type SelectionToolbarProps = {
6
+ editorView: EditorView;
7
+ api?: ExtractInjectionAPI<ToolbarPlugin>;
8
+ };
9
+ export declare const SelectionToolbar: ({ api, editorView }: SelectionToolbarProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1 @@
1
+ export declare const TOOLBAR_LABEL = "Editor Toolbar";
@@ -0,0 +1,2 @@
1
+ import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
2
+ export declare const getToolbarComponents: () => RegisterComponent[];
@@ -0,0 +1,2 @@
1
+ export { toolbarPlugin } from './toolbarPlugin';
2
+ export type { ToolbarPlugin } from './toolbarPluginType';
@@ -0,0 +1,2 @@
1
+ import type { ToolbarPlugin } from './toolbarPluginType';
2
+ export declare const toolbarPlugin: ToolbarPlugin;
@@ -0,0 +1,14 @@
1
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
3
+ import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
4
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
5
+ export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
6
+ dependencies: [
7
+ OptionalPlugin<UserIntentPlugin>,
8
+ OptionalPlugin<SelectionPlugin>
9
+ ];
10
+ actions: {
11
+ registerComponents: (toolbarComponents: Array<RegisterComponent>) => void;
12
+ getComponents: () => Array<RegisterComponent>;
13
+ };
14
+ }>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { ToolbarPlugin } from '../../toolbarPluginType';
5
+ type SelectionToolbarProps = {
6
+ editorView: EditorView;
7
+ api?: ExtractInjectionAPI<ToolbarPlugin>;
8
+ };
9
+ export declare const SelectionToolbar: ({ api, editorView }: SelectionToolbarProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1 @@
1
+ export declare const TOOLBAR_LABEL = "Editor Toolbar";
@@ -0,0 +1,2 @@
1
+ import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
2
+ export declare const getToolbarComponents: () => RegisterComponent[];
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+
3
+ import { AtlassianInternalWarning, code, md } from '@atlaskit/docs';
4
+ // eslint-disable-next-line @atlassian/tangerine/import/entry-points
5
+ import { createEditorUseOnlyNotice } from '@atlaskit/editor-common/doc-utils';
6
+ import { token } from '@atlaskit/tokens';
7
+
8
+ export default md`
9
+
10
+ ${createEditorUseOnlyNotice('Editor Plugin Toolbar', [
11
+ { name: 'Editor Core', link: '/packages/editor/editor-core' },
12
+ ])}
13
+
14
+
15
+ ${
16
+ (
17
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
18
+ <div style={{ marginTop: token('space.100', '8px') }}>
19
+ <AtlassianInternalWarning />
20
+ </div>
21
+ )
22
+ }
23
+
24
+ This package includes the toolbar plugin used by \`@atlaskit/editor-core\`.
25
+
26
+ ## Usage
27
+ ---
28
+
29
+ The \`dependencies\`, \`configuration\`, \`state\`, \`actions\`, and \`commands\` of the plugin are defined
30
+ below:
31
+
32
+ ${code`
33
+ type ToolbarPlugin = NextEditorPlugin<'toolbar'>
34
+ `}
35
+
36
+
37
+ ## Support
38
+ ---
39
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
40
+ ## License
41
+ ---
42
+ Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
43
+ `;
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-toolbar",
3
+ "version": "0.0.1",
4
+ "description": "Toolbar plugin for @atlaskit/editor-core",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "atlassian": {
11
+ "team": "Editor: Jenga",
12
+ "releaseModel": "continuous",
13
+ "singleton": true
14
+ },
15
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
16
+ "main": "dist/cjs/index.js",
17
+ "module": "dist/esm/index.js",
18
+ "module:es2019": "dist/es2019/index.js",
19
+ "types": "dist/types/index.d.ts",
20
+ "typesVersions": {
21
+ ">=4.5 <4.9": {
22
+ "*": [
23
+ "dist/types-ts4.5/*",
24
+ "dist/types-ts4.5/index.d.ts"
25
+ ]
26
+ }
27
+ },
28
+ "sideEffects": false,
29
+ "atlaskit:src": "src/index.ts",
30
+ "af:exports": {
31
+ ".": "./src/index.ts"
32
+ },
33
+ "dependencies": {
34
+ "@atlaskit/editor-plugin-selection": "^3.0.0",
35
+ "@atlaskit/editor-plugin-user-intent": "^1.1.0",
36
+ "@atlaskit/editor-prosemirror": "7.0.0",
37
+ "@atlaskit/editor-toolbar": "^0.0.5",
38
+ "@atlaskit/editor-toolbar-model": "^0.0.1",
39
+ "@babel/runtime": "^7.0.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@atlaskit/editor-common": "^107.14.0",
43
+ "react": "^18.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "typescript": "~5.4.2"
47
+ },
48
+ "techstack": {
49
+ "@atlassian/frontend": {
50
+ "code-structure": [
51
+ "editor-plugin"
52
+ ],
53
+ "import-structure": [
54
+ "atlassian-conventions"
55
+ ],
56
+ "circular-dependencies": [
57
+ "file-and-folder-level"
58
+ ]
59
+ },
60
+ "@repo/internal": {
61
+ "dom-events": "use-bind-event-listener",
62
+ "analytics": [
63
+ "analytics-next"
64
+ ],
65
+ "design-tokens": [
66
+ "color"
67
+ ],
68
+ "theming": [
69
+ "react-context"
70
+ ],
71
+ "ui-components": [
72
+ "lite-mode"
73
+ ],
74
+ "deprecation": "no-deprecated-imports",
75
+ "styling": [
76
+ "emotion",
77
+ "emotion"
78
+ ],
79
+ "imports": [
80
+ "import-no-extraneous-disable-for-examples-and-docs"
81
+ ]
82
+ }
83
+ }
84
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": [
4
+ "src/**/*.ts",
5
+ "src/**/*.tsx"
6
+ ],
7
+ "compilerOptions": {}
8
+ }