@atlaskit/editor-plugin-selection-toolbar 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +14 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +34 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin-key.js +8 -0
- package/dist/cjs/plugin.js +133 -0
- package/dist/cjs/types.js +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin-key.js +2 -0
- package/dist/es2019/plugin.js +122 -0
- package/dist/es2019/types.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin-key.js +2 -0
- package/dist/esm/plugin.js +126 -0
- package/dist/esm/types.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin-key.d.ts +2 -0
- package/dist/types/plugin.d.ts +10 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin-key.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +10 -0
- package/dist/types-ts4.5/types.d.ts +6 -0
- package/package.json +90 -0
- package/report.api.md +48 -0
- package/tmp/api-report-tmp.d.ts +21 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
+
},
|
|
6
|
+
overrides: [
|
|
7
|
+
{
|
|
8
|
+
files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
|
|
9
|
+
rules: {
|
|
10
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-selection-toolbar
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# EditorPluginSelectionToolbar
|
|
2
|
+
|
|
3
|
+
@atlaskit/editor-plugin-selection-toolbar for @atlaskit/editor-core
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
`import EditorPluginSelectionToolbar from '@atlaskit/editor-plugin-selection-toolbar';`
|
|
8
|
+
|
|
9
|
+
**Note:** This component is designed for internal Atlassian development.
|
|
10
|
+
External contributors will be able to use this component but will not be able to submit issues.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
---
|
|
14
|
+
- **Install** - *yarn add @atlaskit/editor-plugin-selection-toolbar*
|
|
15
|
+
- **npm** - [@atlaskit/editor-plugin-selection-toolbar](https://www.npmjs.com/package/@atlaskit/editor-plugin-selection-toolbar)
|
|
16
|
+
- **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-selection-toolbar)
|
|
17
|
+
- **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-selection-toolbar/dist/)
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
---
|
|
21
|
+
**Internal use only**
|
|
22
|
+
|
|
23
|
+
@atlaskit/editor-plugin-selection-toolbar is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
|
|
24
|
+
|
|
25
|
+
Direct use of this component is not supported.
|
|
26
|
+
|
|
27
|
+
Please see [Atlaskit - Editor plugin selection toolbar](https://atlaskit.atlassian.com/packages/editor/editor-plugin-selection-toolbar) for documentation and examples for this package.
|
|
28
|
+
|
|
29
|
+
## Support
|
|
30
|
+
---
|
|
31
|
+
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.
|
|
32
|
+
## License
|
|
33
|
+
---
|
|
34
|
+
Please see [Atlassian Frontend - License](https://developer.atlassian.com/cloud/framework/atlassian-frontend/#license) for more licensing information.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "selectionToolbarPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.selectionToolbarPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _plugin = require("./plugin");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.selectionToolbarPluginKey = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var selectionToolbarPluginKey = exports.selectionToolbarPluginKey = new _state.PluginKey('selectionToolbarPluginKey');
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.selectionToolbarPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _bindEventListener = require("bind-event-listener");
|
|
11
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
+
var _pluginKey = require("./plugin-key");
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
var selectionToolbarPlugin = exports.selectionToolbarPlugin = function selectionToolbarPlugin(options) {
|
|
17
|
+
var __selectionToolbarHandlers = [];
|
|
18
|
+
return {
|
|
19
|
+
name: 'selectionToolbar',
|
|
20
|
+
pmPlugins: function pmPlugins(selectionToolbarHandlers) {
|
|
21
|
+
if (selectionToolbarHandlers) {
|
|
22
|
+
__selectionToolbarHandlers.push.apply(__selectionToolbarHandlers, (0, _toConsumableArray2.default)(selectionToolbarHandlers));
|
|
23
|
+
}
|
|
24
|
+
return [{
|
|
25
|
+
name: 'selection-tracker',
|
|
26
|
+
plugin: function plugin() {
|
|
27
|
+
return new _safePlugin.SafePlugin({
|
|
28
|
+
key: _pluginKey.selectionToolbarPluginKey,
|
|
29
|
+
state: {
|
|
30
|
+
init: function init() {
|
|
31
|
+
return {
|
|
32
|
+
selectionStable: false
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
apply: function apply(tr, pluginState) {
|
|
36
|
+
var meta = tr.getMeta(_pluginKey.selectionToolbarPluginKey);
|
|
37
|
+
if (meta) {
|
|
38
|
+
return _objectSpread(_objectSpread({}, pluginState), meta);
|
|
39
|
+
}
|
|
40
|
+
return pluginState;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
view: function view(_view) {
|
|
44
|
+
var unbind = (0, _bindEventListener.bind)(_view.root, {
|
|
45
|
+
type: 'mouseup',
|
|
46
|
+
listener: function listener() {
|
|
47
|
+
// We only want to set selectionStable to true if the editor has focus
|
|
48
|
+
// to prevent the toolbar from showing when the editor is blurred
|
|
49
|
+
// due to a click outside the editor.
|
|
50
|
+
_view.dispatch(_view.state.tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
|
|
51
|
+
selectionStable: _view.hasFocus()
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
destroy: function destroy() {
|
|
57
|
+
unbind();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
props: {
|
|
62
|
+
handleDOMEvents: {
|
|
63
|
+
mousedown: function mousedown(view) {
|
|
64
|
+
view.dispatch(view.state.tr.setMeta(_pluginKey.selectionToolbarPluginKey, {
|
|
65
|
+
selectionStable: false
|
|
66
|
+
}));
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}];
|
|
74
|
+
},
|
|
75
|
+
pluginsOptions: {
|
|
76
|
+
floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
|
|
77
|
+
var _selectionToolbarPlug = _pluginKey.selectionToolbarPluginKey.getState(state),
|
|
78
|
+
selectionStable = _selectionToolbarPlug.selectionStable;
|
|
79
|
+
if (state.selection.empty || !selectionStable || 'node' in state.selection) {
|
|
80
|
+
// If there is no active selection, or the selection is not stable, or the selection is a node selection,
|
|
81
|
+
// do not show the toolbar.
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Resolve the selectionToolbarHandlers to a list of SelectionToolbarGroups
|
|
85
|
+
// and filter out any handlers which returned undefined
|
|
86
|
+
var resolved = __selectionToolbarHandlers.map(function (selectionToolbarHandler) {
|
|
87
|
+
return selectionToolbarHandler(state, intl, providerFactory);
|
|
88
|
+
}).filter(function (resolved) {
|
|
89
|
+
return resolved !== undefined;
|
|
90
|
+
});
|
|
91
|
+
// Sort the groups by rank
|
|
92
|
+
// This is intended to allow different plugins to control the order of the groups
|
|
93
|
+
// they add to the selection toolbar.
|
|
94
|
+
// ie. if you want to have your plugin's group appear first, set rank to -10 if there is currently another
|
|
95
|
+
// plugin you expect to be run at the same time as with an rank of -9
|
|
96
|
+
resolved.sort(function (_ref, _ref2) {
|
|
97
|
+
var _ref$rank = _ref.rank,
|
|
98
|
+
rankA = _ref$rank === void 0 ? 0 : _ref$rank;
|
|
99
|
+
var _ref2$rank = _ref2.rank,
|
|
100
|
+
rankB = _ref2$rank === void 0 ? 0 : _ref2$rank;
|
|
101
|
+
if (rankA < rankB) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
return -1;
|
|
105
|
+
});
|
|
106
|
+
// This flattens the groups passed into the floating toolbar into a single list of items
|
|
107
|
+
var items = resolved.reduce(function (acc, curr) {
|
|
108
|
+
acc.push.apply(acc, (0, _toConsumableArray2.default)(curr.items));
|
|
109
|
+
return acc;
|
|
110
|
+
}, []);
|
|
111
|
+
var calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? _utils.calculateToolbarPositionAboveSelection : _utils.calculateToolbarPositionTrackHead;
|
|
112
|
+
var toolbarTitle = 'Selection toolbar';
|
|
113
|
+
var onPositionCalculated = calcToolbarPosition(toolbarTitle);
|
|
114
|
+
var nodeType = getSelectionNodeTypes(state);
|
|
115
|
+
return {
|
|
116
|
+
title: 'Selection toolbar',
|
|
117
|
+
nodeType: nodeType,
|
|
118
|
+
items: items,
|
|
119
|
+
onPositionCalculated: onPositionCalculated
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
function getSelectionNodeTypes(state) {
|
|
126
|
+
var selectionNodeTypes = [];
|
|
127
|
+
state.doc.nodesBetween(state.selection.from, state.selection.to, function (node, _pos, parent) {
|
|
128
|
+
if (selectionNodeTypes.indexOf(node.type) !== 0) {
|
|
129
|
+
selectionNodeTypes.push(node.type);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return selectionNodeTypes;
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { selectionToolbarPlugin } from './plugin';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { bind } from 'bind-event-listener';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { selectionToolbarPluginKey } from './plugin-key';
|
|
5
|
+
export const selectionToolbarPlugin = options => {
|
|
6
|
+
let __selectionToolbarHandlers = [];
|
|
7
|
+
return {
|
|
8
|
+
name: 'selectionToolbar',
|
|
9
|
+
pmPlugins(selectionToolbarHandlers) {
|
|
10
|
+
if (selectionToolbarHandlers) {
|
|
11
|
+
__selectionToolbarHandlers.push(...selectionToolbarHandlers);
|
|
12
|
+
}
|
|
13
|
+
return [{
|
|
14
|
+
name: 'selection-tracker',
|
|
15
|
+
plugin: () => {
|
|
16
|
+
return new SafePlugin({
|
|
17
|
+
key: selectionToolbarPluginKey,
|
|
18
|
+
state: {
|
|
19
|
+
init() {
|
|
20
|
+
return {
|
|
21
|
+
selectionStable: false
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
apply(tr, pluginState) {
|
|
25
|
+
const meta = tr.getMeta(selectionToolbarPluginKey);
|
|
26
|
+
if (meta) {
|
|
27
|
+
return {
|
|
28
|
+
...pluginState,
|
|
29
|
+
...meta
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return pluginState;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
view(view) {
|
|
36
|
+
const unbind = bind(view.root, {
|
|
37
|
+
type: 'mouseup',
|
|
38
|
+
listener: () => {
|
|
39
|
+
// We only want to set selectionStable to true if the editor has focus
|
|
40
|
+
// to prevent the toolbar from showing when the editor is blurred
|
|
41
|
+
// due to a click outside the editor.
|
|
42
|
+
view.dispatch(view.state.tr.setMeta(selectionToolbarPluginKey, {
|
|
43
|
+
selectionStable: view.hasFocus()
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
destroy() {
|
|
49
|
+
unbind();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
props: {
|
|
54
|
+
handleDOMEvents: {
|
|
55
|
+
mousedown: view => {
|
|
56
|
+
view.dispatch(view.state.tr.setMeta(selectionToolbarPluginKey, {
|
|
57
|
+
selectionStable: false
|
|
58
|
+
}));
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}];
|
|
66
|
+
},
|
|
67
|
+
pluginsOptions: {
|
|
68
|
+
floatingToolbar(state, intl, providerFactory) {
|
|
69
|
+
const {
|
|
70
|
+
selectionStable
|
|
71
|
+
} = selectionToolbarPluginKey.getState(state);
|
|
72
|
+
if (state.selection.empty || !selectionStable || 'node' in state.selection) {
|
|
73
|
+
// If there is no active selection, or the selection is not stable, or the selection is a node selection,
|
|
74
|
+
// do not show the toolbar.
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Resolve the selectionToolbarHandlers to a list of SelectionToolbarGroups
|
|
78
|
+
// and filter out any handlers which returned undefined
|
|
79
|
+
const resolved = __selectionToolbarHandlers.map(selectionToolbarHandler => selectionToolbarHandler(state, intl, providerFactory)).filter(resolved => resolved !== undefined);
|
|
80
|
+
// Sort the groups by rank
|
|
81
|
+
// This is intended to allow different plugins to control the order of the groups
|
|
82
|
+
// they add to the selection toolbar.
|
|
83
|
+
// ie. if you want to have your plugin's group appear first, set rank to -10 if there is currently another
|
|
84
|
+
// plugin you expect to be run at the same time as with an rank of -9
|
|
85
|
+
resolved.sort(({
|
|
86
|
+
rank: rankA = 0
|
|
87
|
+
}, {
|
|
88
|
+
rank: rankB = 0
|
|
89
|
+
}) => {
|
|
90
|
+
if (rankA < rankB) {
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
return -1;
|
|
94
|
+
});
|
|
95
|
+
// This flattens the groups passed into the floating toolbar into a single list of items
|
|
96
|
+
const items = resolved.reduce((acc, curr) => {
|
|
97
|
+
acc.push(...curr.items);
|
|
98
|
+
return acc;
|
|
99
|
+
}, []);
|
|
100
|
+
const calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
|
|
101
|
+
const toolbarTitle = 'Selection toolbar';
|
|
102
|
+
const onPositionCalculated = calcToolbarPosition(toolbarTitle);
|
|
103
|
+
const nodeType = getSelectionNodeTypes(state);
|
|
104
|
+
return {
|
|
105
|
+
title: 'Selection toolbar',
|
|
106
|
+
nodeType: nodeType,
|
|
107
|
+
items: items,
|
|
108
|
+
onPositionCalculated
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
function getSelectionNodeTypes(state) {
|
|
115
|
+
let selectionNodeTypes = [];
|
|
116
|
+
state.doc.nodesBetween(state.selection.from, state.selection.to, (node, _pos, parent) => {
|
|
117
|
+
if (selectionNodeTypes.indexOf(node.type) !== 0) {
|
|
118
|
+
selectionNodeTypes.push(node.type);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return selectionNodeTypes;
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { selectionToolbarPlugin } from './plugin';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
import { bind } from 'bind-event-listener';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
|
|
8
|
+
import { selectionToolbarPluginKey } from './plugin-key';
|
|
9
|
+
export var selectionToolbarPlugin = function selectionToolbarPlugin(options) {
|
|
10
|
+
var __selectionToolbarHandlers = [];
|
|
11
|
+
return {
|
|
12
|
+
name: 'selectionToolbar',
|
|
13
|
+
pmPlugins: function pmPlugins(selectionToolbarHandlers) {
|
|
14
|
+
if (selectionToolbarHandlers) {
|
|
15
|
+
__selectionToolbarHandlers.push.apply(__selectionToolbarHandlers, _toConsumableArray(selectionToolbarHandlers));
|
|
16
|
+
}
|
|
17
|
+
return [{
|
|
18
|
+
name: 'selection-tracker',
|
|
19
|
+
plugin: function plugin() {
|
|
20
|
+
return new SafePlugin({
|
|
21
|
+
key: selectionToolbarPluginKey,
|
|
22
|
+
state: {
|
|
23
|
+
init: function init() {
|
|
24
|
+
return {
|
|
25
|
+
selectionStable: false
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
apply: function apply(tr, pluginState) {
|
|
29
|
+
var meta = tr.getMeta(selectionToolbarPluginKey);
|
|
30
|
+
if (meta) {
|
|
31
|
+
return _objectSpread(_objectSpread({}, pluginState), meta);
|
|
32
|
+
}
|
|
33
|
+
return pluginState;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
view: function view(_view) {
|
|
37
|
+
var unbind = bind(_view.root, {
|
|
38
|
+
type: 'mouseup',
|
|
39
|
+
listener: function listener() {
|
|
40
|
+
// We only want to set selectionStable to true if the editor has focus
|
|
41
|
+
// to prevent the toolbar from showing when the editor is blurred
|
|
42
|
+
// due to a click outside the editor.
|
|
43
|
+
_view.dispatch(_view.state.tr.setMeta(selectionToolbarPluginKey, {
|
|
44
|
+
selectionStable: _view.hasFocus()
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
destroy: function destroy() {
|
|
50
|
+
unbind();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
props: {
|
|
55
|
+
handleDOMEvents: {
|
|
56
|
+
mousedown: function mousedown(view) {
|
|
57
|
+
view.dispatch(view.state.tr.setMeta(selectionToolbarPluginKey, {
|
|
58
|
+
selectionStable: false
|
|
59
|
+
}));
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}];
|
|
67
|
+
},
|
|
68
|
+
pluginsOptions: {
|
|
69
|
+
floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
|
|
70
|
+
var _selectionToolbarPlug = selectionToolbarPluginKey.getState(state),
|
|
71
|
+
selectionStable = _selectionToolbarPlug.selectionStable;
|
|
72
|
+
if (state.selection.empty || !selectionStable || 'node' in state.selection) {
|
|
73
|
+
// If there is no active selection, or the selection is not stable, or the selection is a node selection,
|
|
74
|
+
// do not show the toolbar.
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Resolve the selectionToolbarHandlers to a list of SelectionToolbarGroups
|
|
78
|
+
// and filter out any handlers which returned undefined
|
|
79
|
+
var resolved = __selectionToolbarHandlers.map(function (selectionToolbarHandler) {
|
|
80
|
+
return selectionToolbarHandler(state, intl, providerFactory);
|
|
81
|
+
}).filter(function (resolved) {
|
|
82
|
+
return resolved !== undefined;
|
|
83
|
+
});
|
|
84
|
+
// Sort the groups by rank
|
|
85
|
+
// This is intended to allow different plugins to control the order of the groups
|
|
86
|
+
// they add to the selection toolbar.
|
|
87
|
+
// ie. if you want to have your plugin's group appear first, set rank to -10 if there is currently another
|
|
88
|
+
// plugin you expect to be run at the same time as with an rank of -9
|
|
89
|
+
resolved.sort(function (_ref, _ref2) {
|
|
90
|
+
var _ref$rank = _ref.rank,
|
|
91
|
+
rankA = _ref$rank === void 0 ? 0 : _ref$rank;
|
|
92
|
+
var _ref2$rank = _ref2.rank,
|
|
93
|
+
rankB = _ref2$rank === void 0 ? 0 : _ref2$rank;
|
|
94
|
+
if (rankA < rankB) {
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
return -1;
|
|
98
|
+
});
|
|
99
|
+
// This flattens the groups passed into the floating toolbar into a single list of items
|
|
100
|
+
var items = resolved.reduce(function (acc, curr) {
|
|
101
|
+
acc.push.apply(acc, _toConsumableArray(curr.items));
|
|
102
|
+
return acc;
|
|
103
|
+
}, []);
|
|
104
|
+
var calcToolbarPosition = options.config.preferenceToolbarAboveSelection ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
|
|
105
|
+
var toolbarTitle = 'Selection toolbar';
|
|
106
|
+
var onPositionCalculated = calcToolbarPosition(toolbarTitle);
|
|
107
|
+
var nodeType = getSelectionNodeTypes(state);
|
|
108
|
+
return {
|
|
109
|
+
title: 'Selection toolbar',
|
|
110
|
+
nodeType: nodeType,
|
|
111
|
+
items: items,
|
|
112
|
+
onPositionCalculated: onPositionCalculated
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
function getSelectionNodeTypes(state) {
|
|
119
|
+
var selectionNodeTypes = [];
|
|
120
|
+
state.doc.nodesBetween(state.selection.from, state.selection.to, function (node, _pos, parent) {
|
|
121
|
+
if (selectionNodeTypes.indexOf(node.type) !== 0) {
|
|
122
|
+
selectionNodeTypes.push(node.type);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return selectionNodeTypes;
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
export declare const selectionToolbarPlugin: NextEditorPlugin<'selectionToolbar', {
|
|
3
|
+
pluginConfiguration: {
|
|
4
|
+
/**
|
|
5
|
+
* Defaults to false
|
|
6
|
+
*/
|
|
7
|
+
preferenceToolbarAboveSelection?: boolean;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
export declare const selectionToolbarPlugin: NextEditorPlugin<'selectionToolbar', {
|
|
3
|
+
pluginConfiguration: {
|
|
4
|
+
/**
|
|
5
|
+
* Defaults to false
|
|
6
|
+
*/
|
|
7
|
+
preferenceToolbarAboveSelection?: boolean;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-selection-toolbar",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "@atlaskit/editor-plugin-selection-toolbar 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: AI",
|
|
12
|
+
"inPublicMirror": false,
|
|
13
|
+
"releaseModel": "continuous",
|
|
14
|
+
"website": {
|
|
15
|
+
"name": "EditorPluginSelectionToolbar",
|
|
16
|
+
"category": "Components"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend",
|
|
20
|
+
"main": "dist/cjs/index.js",
|
|
21
|
+
"module": "dist/esm/index.js",
|
|
22
|
+
"module:es2019": "dist/es2019/index.js",
|
|
23
|
+
"types": "dist/types/index.d.ts",
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
">=4.5 <4.9": {
|
|
26
|
+
"*": [
|
|
27
|
+
"dist/types-ts4.5/*",
|
|
28
|
+
"dist/types-ts4.5/index.d.ts"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"atlaskit:src": "src/index.ts",
|
|
34
|
+
"af:exports": {
|
|
35
|
+
".": "./src/index.ts"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@atlaskit/editor-common": "^76.11.4",
|
|
39
|
+
"@atlaskit/editor-prosemirror": "1.1.0",
|
|
40
|
+
"@babel/runtime": "^7.0.0",
|
|
41
|
+
"bind-event-listener": "^2.1.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^16.8.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@af/visual-regression": "*",
|
|
48
|
+
"@atlaskit/ssr": "*",
|
|
49
|
+
"@atlaskit/visual-regression": "*",
|
|
50
|
+
"@atlaskit/webdriver-runner": "*",
|
|
51
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
52
|
+
"@testing-library/react": "^12.1.5",
|
|
53
|
+
"react-dom": "^16.8.0",
|
|
54
|
+
"typescript": "~4.9.5",
|
|
55
|
+
"wait-for-expect": "^1.2.0"
|
|
56
|
+
},
|
|
57
|
+
"techstack": {
|
|
58
|
+
"@atlassian/frontend": {
|
|
59
|
+
"import-structure": [
|
|
60
|
+
"atlassian-conventions"
|
|
61
|
+
],
|
|
62
|
+
"circular-dependencies": [
|
|
63
|
+
"file-and-folder-level"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"@repo/internal": {
|
|
67
|
+
"dom-events": "use-bind-event-listener",
|
|
68
|
+
"analytics": [
|
|
69
|
+
"analytics-next"
|
|
70
|
+
],
|
|
71
|
+
"design-tokens": [
|
|
72
|
+
"color"
|
|
73
|
+
],
|
|
74
|
+
"theming": [
|
|
75
|
+
"react-context"
|
|
76
|
+
],
|
|
77
|
+
"ui-components": [
|
|
78
|
+
"lite-mode"
|
|
79
|
+
],
|
|
80
|
+
"deprecation": [
|
|
81
|
+
"no-deprecated-imports"
|
|
82
|
+
],
|
|
83
|
+
"styling": [
|
|
84
|
+
"static",
|
|
85
|
+
"emotion"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
|
|
90
|
+
}
|
package/report.api.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
|
+
|
|
3
|
+
## API Report File for "@atlaskit/editor-plugin-selection-toolbar"
|
|
4
|
+
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
9
|
+
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
11
|
+
- [Peer Dependencies](#peer-dependencies)
|
|
12
|
+
|
|
13
|
+
### Main Entry Types
|
|
14
|
+
|
|
15
|
+
<!--SECTION START: Main Entry Types-->
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
19
|
+
|
|
20
|
+
// @public (undocumented)
|
|
21
|
+
export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
|
|
22
|
+
|
|
23
|
+
// @public (undocumented)
|
|
24
|
+
export const selectionToolbarPlugin: NextEditorPlugin<
|
|
25
|
+
'selectionToolbar',
|
|
26
|
+
{
|
|
27
|
+
pluginConfiguration: {
|
|
28
|
+
preferenceToolbarAboveSelection?: boolean;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
// (No @packageDocumentation comment for this package)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
<!--SECTION END: Main Entry Types-->
|
|
37
|
+
|
|
38
|
+
### Peer Dependencies
|
|
39
|
+
|
|
40
|
+
<!--SECTION START: Peer Dependencies-->
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"react": "^16.8.0"
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
<!--SECTION END: Peer Dependencies-->
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## API Report File for "@atlaskit/editor-plugin-selection-toolbar"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
8
|
+
|
|
9
|
+
// @public (undocumented)
|
|
10
|
+
export type SelectionToolbarPlugin = typeof selectionToolbarPlugin;
|
|
11
|
+
|
|
12
|
+
// @public (undocumented)
|
|
13
|
+
export const selectionToolbarPlugin: NextEditorPlugin<'selectionToolbar', {
|
|
14
|
+
pluginConfiguration: {
|
|
15
|
+
preferenceToolbarAboveSelection?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
// (No @packageDocumentation comment for this package)
|
|
20
|
+
|
|
21
|
+
```
|