@atlaskit/editor-plugin-toolbar 2.1.3 → 2.1.4
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 +8 -0
- package/afm-dev-agents/tsconfig.json +3 -0
- package/afm-jira/tsconfig.json +3 -0
- package/afm-passionfruit/tsconfig.json +3 -0
- package/afm-post-office/tsconfig.json +3 -0
- package/afm-rovo-extension/tsconfig.json +3 -0
- package/afm-townsquare/tsconfig.json +3 -0
- package/dist/cjs/toolbarPlugin.js +65 -5
- package/dist/cjs/ui/SelectionToolbar/index.js +10 -7
- package/dist/es2019/toolbarPlugin.js +63 -5
- package/dist/es2019/ui/SelectionToolbar/index.js +10 -7
- package/dist/esm/toolbarPlugin.js +65 -5
- package/dist/esm/ui/SelectionToolbar/index.js +10 -7
- package/dist/types/toolbarPlugin.d.ts +0 -3
- package/dist/types/toolbarPluginType.d.ts +11 -3
- package/dist/types-ts4.5/toolbarPlugin.d.ts +0 -3
- package/dist/types-ts4.5/toolbarPluginType.d.ts +11 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-toolbar
|
|
2
2
|
|
|
3
|
+
## 2.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e24c73c66f022`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e24c73c66f022) -
|
|
8
|
+
[ux] ED-29268 [SoftServ] Toolbar doesn’t move with text when text alignment change
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 2.1.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/afm-jira/tsconfig.json
CHANGED
|
@@ -9,7 +9,10 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _bindEventListener = require("bind-event-listener");
|
|
11
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
14
|
var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
|
|
15
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
13
16
|
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
14
17
|
var _consts = require("./ui/consts");
|
|
15
18
|
var _SelectionToolbar = require("./ui/SelectionToolbar");
|
|
@@ -17,6 +20,51 @@ var _toolbarComponents = require("./ui/toolbar-components");
|
|
|
17
20
|
var _toolbar = require("./ui/utils/toolbar");
|
|
18
21
|
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; }
|
|
19
22
|
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; }
|
|
23
|
+
function getSelectedNode(editorState) {
|
|
24
|
+
var selection = editorState.selection;
|
|
25
|
+
if (selection instanceof _state.NodeSelection) {
|
|
26
|
+
return {
|
|
27
|
+
node: selection.node,
|
|
28
|
+
pos: selection.from,
|
|
29
|
+
nodeType: selection.node.type.name,
|
|
30
|
+
marks: selection.node.marks.map(function (mark) {
|
|
31
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var nodes = editorState.schema.nodes;
|
|
36
|
+
var selectedNode = (0, _utils.findSelectedNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock])(selection);
|
|
37
|
+
if (selectedNode) {
|
|
38
|
+
return {
|
|
39
|
+
node: selectedNode.node,
|
|
40
|
+
pos: selectedNode.pos,
|
|
41
|
+
nodeType: selectedNode.node.type.name,
|
|
42
|
+
marks: selectedNode.node.marks.map(function (mark) {
|
|
43
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var parentNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.listItem, nodes.taskItem])(selection);
|
|
48
|
+
if (parentNode) {
|
|
49
|
+
return {
|
|
50
|
+
node: parentNode.node,
|
|
51
|
+
pos: parentNode.pos,
|
|
52
|
+
nodeType: parentNode.node.type.name,
|
|
53
|
+
marks: parentNode.node.marks.map(function (mark) {
|
|
54
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var $pos = selection.$from;
|
|
59
|
+
return {
|
|
60
|
+
node: $pos.parent,
|
|
61
|
+
pos: $pos.pos,
|
|
62
|
+
nodeType: $pos.parent.type.name,
|
|
63
|
+
marks: $pos.marks().map(function (mark) {
|
|
64
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
}
|
|
20
68
|
var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
21
69
|
var api = _ref.api,
|
|
22
70
|
_ref$config = _ref.config,
|
|
@@ -57,16 +105,28 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
57
105
|
return new _safePlugin.SafePlugin({
|
|
58
106
|
key: _pluginKey.editorToolbarPluginKey,
|
|
59
107
|
state: {
|
|
60
|
-
init: function init() {
|
|
108
|
+
init: function init(_, editorState) {
|
|
61
109
|
return {
|
|
62
|
-
shouldShowToolbar: false
|
|
110
|
+
shouldShowToolbar: false,
|
|
111
|
+
selectedNode: getSelectedNode(editorState)
|
|
63
112
|
};
|
|
64
113
|
},
|
|
65
|
-
apply: function apply(tr, pluginState) {
|
|
114
|
+
apply: function apply(tr, pluginState, _, newState) {
|
|
66
115
|
var meta = tr.getMeta(_pluginKey.editorToolbarPluginKey);
|
|
67
|
-
var newPluginState = pluginState;
|
|
116
|
+
var newPluginState = _objectSpread({}, pluginState);
|
|
117
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true)) {
|
|
118
|
+
var shouldUpdateNode = tr.docChanged || tr.selectionSet;
|
|
119
|
+
if (shouldUpdateNode) {
|
|
120
|
+
var newSelectedNode = getSelectedNode(newState);
|
|
121
|
+
var oldNode = pluginState.selectedNode;
|
|
122
|
+
var hasNodeChanged = !oldNode || !newSelectedNode || oldNode.nodeType !== newSelectedNode.nodeType || oldNode.pos !== newSelectedNode.pos || JSON.stringify(oldNode.marks) !== JSON.stringify(newSelectedNode.marks);
|
|
123
|
+
if (hasNodeChanged) {
|
|
124
|
+
newPluginState.selectedNode = newSelectedNode;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
68
128
|
if (meta) {
|
|
69
|
-
|
|
129
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), meta);
|
|
70
130
|
}
|
|
71
131
|
return newPluginState;
|
|
72
132
|
}
|
|
@@ -28,11 +28,12 @@ var usePluginState = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(fun
|
|
|
28
28
|
return (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_3', 'isEnabled', true);
|
|
29
29
|
}, function (api) {
|
|
30
30
|
return (0, _hooks.useSharedPluginStateWithSelector)(api, ['connectivity', 'userPreferences', 'toolbar', 'selection', 'userIntent', 'editorViewMode'], function (state) {
|
|
31
|
-
var _state$connectivitySt, _state$userPreference, _state$toolbarState, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
31
|
+
var _state$connectivitySt, _state$userPreference, _state$toolbarState, _state$toolbarState2, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
32
32
|
return {
|
|
33
33
|
connectivityStateMode: (_state$connectivitySt = state.connectivityState) === null || _state$connectivitySt === void 0 ? void 0 : _state$connectivitySt.mode,
|
|
34
34
|
editorToolbarDockingPreference: (_state$userPreference = state.userPreferencesState) === null || _state$userPreference === void 0 || (_state$userPreference = _state$userPreference.preferences) === null || _state$userPreference === void 0 ? void 0 : _state$userPreference.toolbarDockingPosition,
|
|
35
35
|
shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar,
|
|
36
|
+
selectedNode: (_state$toolbarState2 = state.toolbarState) === null || _state$toolbarState2 === void 0 ? void 0 : _state$toolbarState2.selectedNode,
|
|
36
37
|
selection: (_state$selectionState = state.selectionState) === null || _state$selectionState === void 0 ? void 0 : _state$selectionState.selection,
|
|
37
38
|
currentUserIntent: (_state$userIntentStat = state.userIntentState) === null || _state$userIntentStat === void 0 ? void 0 : _state$userIntentStat.currentUserIntent,
|
|
38
39
|
editorViewMode: (_state$editorViewMode = state.editorViewModeState) === null || _state$editorViewMode === void 0 ? void 0 : _state$editorViewMode.mode
|
|
@@ -44,19 +45,22 @@ var usePluginState = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(fun
|
|
|
44
45
|
var currentUserIntent = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'userIntent.currentUserIntent');
|
|
45
46
|
var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
|
|
46
47
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['toolbar'], function (state) {
|
|
47
|
-
var _state$
|
|
48
|
+
var _state$toolbarState3, _state$toolbarState4;
|
|
48
49
|
return {
|
|
49
|
-
shouldShowToolbar: (_state$
|
|
50
|
+
shouldShowToolbar: (_state$toolbarState3 = state.toolbarState) === null || _state$toolbarState3 === void 0 ? void 0 : _state$toolbarState3.shouldShowToolbar,
|
|
51
|
+
selectedNode: (_state$toolbarState4 = state.toolbarState) === null || _state$toolbarState4 === void 0 ? void 0 : _state$toolbarState4.selectedNode
|
|
50
52
|
};
|
|
51
53
|
}),
|
|
52
|
-
shouldShowToolbar = _useSharedPluginState.shouldShowToolbar
|
|
54
|
+
shouldShowToolbar = _useSharedPluginState.shouldShowToolbar,
|
|
55
|
+
selectedNode = _useSharedPluginState.selectedNode;
|
|
53
56
|
return {
|
|
54
57
|
connectivityStateMode: connectivityStateMode,
|
|
55
58
|
editorToolbarDockingPreference: editorToolbarDockingPreference,
|
|
56
59
|
currentUserIntent: currentUserIntent,
|
|
57
60
|
shouldShowToolbar: shouldShowToolbar,
|
|
58
61
|
selection: selection,
|
|
59
|
-
editorViewMode: undefined
|
|
62
|
+
editorViewMode: undefined,
|
|
63
|
+
selectedNode: selectedNode
|
|
60
64
|
};
|
|
61
65
|
});
|
|
62
66
|
var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref) {
|
|
@@ -89,8 +93,7 @@ var SelectionToolbar = exports.SelectionToolbar = function SelectionToolbar(_ref
|
|
|
89
93
|
if (isCellSelection && isEditorControlsEnabled) {
|
|
90
94
|
return (0, _utils.calculateToolbarPositionOnCellSelection)(toolbarTitle)(editorView, position);
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
return calc(toolbarTitle)(editorView, position);
|
|
96
|
+
return (0, _utils.calculateToolbarPositionTrackHead)(toolbarTitle)(editorView, position);
|
|
94
97
|
}, [editorView]);
|
|
95
98
|
if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && editorToolbarDockingPreference === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
|
|
96
99
|
return null;
|
|
@@ -1,12 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { bind } from 'bind-event-listener';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { findSelectedNodeOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
6
|
import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
|
|
7
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
5
8
|
import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
|
|
6
9
|
import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
|
|
7
10
|
import { SelectionToolbar } from './ui/SelectionToolbar';
|
|
8
11
|
import { getToolbarComponents } from './ui/toolbar-components';
|
|
9
12
|
import { isEventInContainer } from './ui/utils/toolbar';
|
|
13
|
+
function getSelectedNode(editorState) {
|
|
14
|
+
const {
|
|
15
|
+
selection
|
|
16
|
+
} = editorState;
|
|
17
|
+
if (selection instanceof NodeSelection) {
|
|
18
|
+
return {
|
|
19
|
+
node: selection.node,
|
|
20
|
+
pos: selection.from,
|
|
21
|
+
nodeType: selection.node.type.name,
|
|
22
|
+
marks: selection.node.marks.map(mark => `${mark.type.name}:${JSON.stringify(mark.attrs)}`)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const {
|
|
26
|
+
nodes
|
|
27
|
+
} = editorState.schema;
|
|
28
|
+
const selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock])(selection);
|
|
29
|
+
if (selectedNode) {
|
|
30
|
+
return {
|
|
31
|
+
node: selectedNode.node,
|
|
32
|
+
pos: selectedNode.pos,
|
|
33
|
+
nodeType: selectedNode.node.type.name,
|
|
34
|
+
marks: selectedNode.node.marks.map(mark => `${mark.type.name}:${JSON.stringify(mark.attrs)}`)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const parentNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.listItem, nodes.taskItem])(selection);
|
|
38
|
+
if (parentNode) {
|
|
39
|
+
return {
|
|
40
|
+
node: parentNode.node,
|
|
41
|
+
pos: parentNode.pos,
|
|
42
|
+
nodeType: parentNode.node.type.name,
|
|
43
|
+
marks: parentNode.node.marks.map(mark => `${mark.type.name}:${JSON.stringify(mark.attrs)}`)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const $pos = selection.$from;
|
|
47
|
+
return {
|
|
48
|
+
node: $pos.parent,
|
|
49
|
+
pos: $pos.pos,
|
|
50
|
+
nodeType: $pos.parent.type.name,
|
|
51
|
+
marks: $pos.marks().map(mark => `${mark.type.name}:${JSON.stringify(mark.attrs)}`)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
10
54
|
export const toolbarPlugin = ({
|
|
11
55
|
api,
|
|
12
56
|
config = {
|
|
@@ -48,16 +92,30 @@ export const toolbarPlugin = ({
|
|
|
48
92
|
return new SafePlugin({
|
|
49
93
|
key: editorToolbarPluginKey,
|
|
50
94
|
state: {
|
|
51
|
-
init() {
|
|
95
|
+
init(_, editorState) {
|
|
52
96
|
return {
|
|
53
|
-
shouldShowToolbar: false
|
|
97
|
+
shouldShowToolbar: false,
|
|
98
|
+
selectedNode: getSelectedNode(editorState)
|
|
54
99
|
};
|
|
55
100
|
},
|
|
56
|
-
apply(tr, pluginState) {
|
|
101
|
+
apply(tr, pluginState, _, newState) {
|
|
57
102
|
const meta = tr.getMeta(editorToolbarPluginKey);
|
|
58
|
-
|
|
103
|
+
let newPluginState = {
|
|
104
|
+
...pluginState
|
|
105
|
+
};
|
|
106
|
+
if (expValEquals('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true)) {
|
|
107
|
+
const shouldUpdateNode = tr.docChanged || tr.selectionSet;
|
|
108
|
+
if (shouldUpdateNode) {
|
|
109
|
+
const newSelectedNode = getSelectedNode(newState);
|
|
110
|
+
const oldNode = pluginState.selectedNode;
|
|
111
|
+
const hasNodeChanged = !oldNode || !newSelectedNode || oldNode.nodeType !== newSelectedNode.nodeType || oldNode.pos !== newSelectedNode.pos || JSON.stringify(oldNode.marks) !== JSON.stringify(newSelectedNode.marks);
|
|
112
|
+
if (hasNodeChanged) {
|
|
113
|
+
newPluginState.selectedNode = newSelectedNode;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
59
117
|
if (meta) {
|
|
60
|
-
|
|
118
|
+
newPluginState = {
|
|
61
119
|
...newPluginState,
|
|
62
120
|
...meta
|
|
63
121
|
};
|
|
@@ -18,11 +18,12 @@ const isToolbarComponent = component => {
|
|
|
18
18
|
};
|
|
19
19
|
const usePluginState = conditionalHooksFactory(() => expValEquals('platform_editor_toolbar_aifc_patch_3', 'isEnabled', true), api => {
|
|
20
20
|
return useSharedPluginStateWithSelector(api, ['connectivity', 'userPreferences', 'toolbar', 'selection', 'userIntent', 'editorViewMode'], state => {
|
|
21
|
-
var _state$connectivitySt, _state$userPreference, _state$userPreference2, _state$toolbarState, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
21
|
+
var _state$connectivitySt, _state$userPreference, _state$userPreference2, _state$toolbarState, _state$toolbarState2, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
22
22
|
return {
|
|
23
23
|
connectivityStateMode: (_state$connectivitySt = state.connectivityState) === null || _state$connectivitySt === void 0 ? void 0 : _state$connectivitySt.mode,
|
|
24
24
|
editorToolbarDockingPreference: (_state$userPreference = state.userPreferencesState) === null || _state$userPreference === void 0 ? void 0 : (_state$userPreference2 = _state$userPreference.preferences) === null || _state$userPreference2 === void 0 ? void 0 : _state$userPreference2.toolbarDockingPosition,
|
|
25
25
|
shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar,
|
|
26
|
+
selectedNode: (_state$toolbarState2 = state.toolbarState) === null || _state$toolbarState2 === void 0 ? void 0 : _state$toolbarState2.selectedNode,
|
|
26
27
|
selection: (_state$selectionState = state.selectionState) === null || _state$selectionState === void 0 ? void 0 : _state$selectionState.selection,
|
|
27
28
|
currentUserIntent: (_state$userIntentStat = state.userIntentState) === null || _state$userIntentStat === void 0 ? void 0 : _state$userIntentStat.currentUserIntent,
|
|
28
29
|
editorViewMode: (_state$editorViewMode = state.editorViewModeState) === null || _state$editorViewMode === void 0 ? void 0 : _state$editorViewMode.mode
|
|
@@ -34,11 +35,13 @@ const usePluginState = conditionalHooksFactory(() => expValEquals('platform_edit
|
|
|
34
35
|
const currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
|
|
35
36
|
const selection = useSharedPluginStateSelector(api, 'selection.selection');
|
|
36
37
|
const {
|
|
37
|
-
shouldShowToolbar
|
|
38
|
+
shouldShowToolbar,
|
|
39
|
+
selectedNode
|
|
38
40
|
} = useSharedPluginStateWithSelector(api, ['toolbar'], state => {
|
|
39
|
-
var _state$
|
|
41
|
+
var _state$toolbarState3, _state$toolbarState4;
|
|
40
42
|
return {
|
|
41
|
-
shouldShowToolbar: (_state$
|
|
43
|
+
shouldShowToolbar: (_state$toolbarState3 = state.toolbarState) === null || _state$toolbarState3 === void 0 ? void 0 : _state$toolbarState3.shouldShowToolbar,
|
|
44
|
+
selectedNode: (_state$toolbarState4 = state.toolbarState) === null || _state$toolbarState4 === void 0 ? void 0 : _state$toolbarState4.selectedNode
|
|
42
45
|
};
|
|
43
46
|
});
|
|
44
47
|
return {
|
|
@@ -47,7 +50,8 @@ const usePluginState = conditionalHooksFactory(() => expValEquals('platform_edit
|
|
|
47
50
|
currentUserIntent,
|
|
48
51
|
shouldShowToolbar,
|
|
49
52
|
selection,
|
|
50
|
-
editorViewMode: undefined
|
|
53
|
+
editorViewMode: undefined,
|
|
54
|
+
selectedNode
|
|
51
55
|
};
|
|
52
56
|
});
|
|
53
57
|
export const SelectionToolbar = ({
|
|
@@ -81,8 +85,7 @@ export const SelectionToolbar = ({
|
|
|
81
85
|
if (isCellSelection && isEditorControlsEnabled) {
|
|
82
86
|
return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
return calc(toolbarTitle)(editorView, position);
|
|
88
|
+
return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
|
|
86
89
|
}, [editorView]);
|
|
87
90
|
if (expValEquals('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && editorToolbarDockingPreference === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
|
|
88
91
|
return null;
|
|
@@ -4,12 +4,60 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { bind } from 'bind-event-listener';
|
|
6
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { findSelectedNodeOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
7
9
|
import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
|
|
10
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
8
11
|
import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
|
|
9
12
|
import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
|
|
10
13
|
import { SelectionToolbar } from './ui/SelectionToolbar';
|
|
11
14
|
import { getToolbarComponents } from './ui/toolbar-components';
|
|
12
15
|
import { isEventInContainer } from './ui/utils/toolbar';
|
|
16
|
+
function getSelectedNode(editorState) {
|
|
17
|
+
var selection = editorState.selection;
|
|
18
|
+
if (selection instanceof NodeSelection) {
|
|
19
|
+
return {
|
|
20
|
+
node: selection.node,
|
|
21
|
+
pos: selection.from,
|
|
22
|
+
nodeType: selection.node.type.name,
|
|
23
|
+
marks: selection.node.marks.map(function (mark) {
|
|
24
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
25
|
+
})
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var nodes = editorState.schema.nodes;
|
|
29
|
+
var selectedNode = findSelectedNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock])(selection);
|
|
30
|
+
if (selectedNode) {
|
|
31
|
+
return {
|
|
32
|
+
node: selectedNode.node,
|
|
33
|
+
pos: selectedNode.pos,
|
|
34
|
+
nodeType: selectedNode.node.type.name,
|
|
35
|
+
marks: selectedNode.node.marks.map(function (mark) {
|
|
36
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var parentNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.listItem, nodes.taskItem])(selection);
|
|
41
|
+
if (parentNode) {
|
|
42
|
+
return {
|
|
43
|
+
node: parentNode.node,
|
|
44
|
+
pos: parentNode.pos,
|
|
45
|
+
nodeType: parentNode.node.type.name,
|
|
46
|
+
marks: parentNode.node.marks.map(function (mark) {
|
|
47
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var $pos = selection.$from;
|
|
52
|
+
return {
|
|
53
|
+
node: $pos.parent,
|
|
54
|
+
pos: $pos.pos,
|
|
55
|
+
nodeType: $pos.parent.type.name,
|
|
56
|
+
marks: $pos.marks().map(function (mark) {
|
|
57
|
+
return "".concat(mark.type.name, ":").concat(JSON.stringify(mark.attrs));
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
13
61
|
export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
14
62
|
var api = _ref.api,
|
|
15
63
|
_ref$config = _ref.config,
|
|
@@ -50,16 +98,28 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
50
98
|
return new SafePlugin({
|
|
51
99
|
key: editorToolbarPluginKey,
|
|
52
100
|
state: {
|
|
53
|
-
init: function init() {
|
|
101
|
+
init: function init(_, editorState) {
|
|
54
102
|
return {
|
|
55
|
-
shouldShowToolbar: false
|
|
103
|
+
shouldShowToolbar: false,
|
|
104
|
+
selectedNode: getSelectedNode(editorState)
|
|
56
105
|
};
|
|
57
106
|
},
|
|
58
|
-
apply: function apply(tr, pluginState) {
|
|
107
|
+
apply: function apply(tr, pluginState, _, newState) {
|
|
59
108
|
var meta = tr.getMeta(editorToolbarPluginKey);
|
|
60
|
-
var newPluginState = pluginState;
|
|
109
|
+
var newPluginState = _objectSpread({}, pluginState);
|
|
110
|
+
if (expValEquals('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true)) {
|
|
111
|
+
var shouldUpdateNode = tr.docChanged || tr.selectionSet;
|
|
112
|
+
if (shouldUpdateNode) {
|
|
113
|
+
var newSelectedNode = getSelectedNode(newState);
|
|
114
|
+
var oldNode = pluginState.selectedNode;
|
|
115
|
+
var hasNodeChanged = !oldNode || !newSelectedNode || oldNode.nodeType !== newSelectedNode.nodeType || oldNode.pos !== newSelectedNode.pos || JSON.stringify(oldNode.marks) !== JSON.stringify(newSelectedNode.marks);
|
|
116
|
+
if (hasNodeChanged) {
|
|
117
|
+
newPluginState.selectedNode = newSelectedNode;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
61
121
|
if (meta) {
|
|
62
|
-
|
|
122
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), meta);
|
|
63
123
|
}
|
|
64
124
|
return newPluginState;
|
|
65
125
|
}
|
|
@@ -20,11 +20,12 @@ var usePluginState = conditionalHooksFactory(function () {
|
|
|
20
20
|
return expValEquals('platform_editor_toolbar_aifc_patch_3', 'isEnabled', true);
|
|
21
21
|
}, function (api) {
|
|
22
22
|
return useSharedPluginStateWithSelector(api, ['connectivity', 'userPreferences', 'toolbar', 'selection', 'userIntent', 'editorViewMode'], function (state) {
|
|
23
|
-
var _state$connectivitySt, _state$userPreference, _state$toolbarState, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
23
|
+
var _state$connectivitySt, _state$userPreference, _state$toolbarState, _state$toolbarState2, _state$selectionState, _state$userIntentStat, _state$editorViewMode;
|
|
24
24
|
return {
|
|
25
25
|
connectivityStateMode: (_state$connectivitySt = state.connectivityState) === null || _state$connectivitySt === void 0 ? void 0 : _state$connectivitySt.mode,
|
|
26
26
|
editorToolbarDockingPreference: (_state$userPreference = state.userPreferencesState) === null || _state$userPreference === void 0 || (_state$userPreference = _state$userPreference.preferences) === null || _state$userPreference === void 0 ? void 0 : _state$userPreference.toolbarDockingPosition,
|
|
27
27
|
shouldShowToolbar: (_state$toolbarState = state.toolbarState) === null || _state$toolbarState === void 0 ? void 0 : _state$toolbarState.shouldShowToolbar,
|
|
28
|
+
selectedNode: (_state$toolbarState2 = state.toolbarState) === null || _state$toolbarState2 === void 0 ? void 0 : _state$toolbarState2.selectedNode,
|
|
28
29
|
selection: (_state$selectionState = state.selectionState) === null || _state$selectionState === void 0 ? void 0 : _state$selectionState.selection,
|
|
29
30
|
currentUserIntent: (_state$userIntentStat = state.userIntentState) === null || _state$userIntentStat === void 0 ? void 0 : _state$userIntentStat.currentUserIntent,
|
|
30
31
|
editorViewMode: (_state$editorViewMode = state.editorViewModeState) === null || _state$editorViewMode === void 0 ? void 0 : _state$editorViewMode.mode
|
|
@@ -36,19 +37,22 @@ var usePluginState = conditionalHooksFactory(function () {
|
|
|
36
37
|
var currentUserIntent = useSharedPluginStateSelector(api, 'userIntent.currentUserIntent');
|
|
37
38
|
var selection = useSharedPluginStateSelector(api, 'selection.selection');
|
|
38
39
|
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['toolbar'], function (state) {
|
|
39
|
-
var _state$
|
|
40
|
+
var _state$toolbarState3, _state$toolbarState4;
|
|
40
41
|
return {
|
|
41
|
-
shouldShowToolbar: (_state$
|
|
42
|
+
shouldShowToolbar: (_state$toolbarState3 = state.toolbarState) === null || _state$toolbarState3 === void 0 ? void 0 : _state$toolbarState3.shouldShowToolbar,
|
|
43
|
+
selectedNode: (_state$toolbarState4 = state.toolbarState) === null || _state$toolbarState4 === void 0 ? void 0 : _state$toolbarState4.selectedNode
|
|
42
44
|
};
|
|
43
45
|
}),
|
|
44
|
-
shouldShowToolbar = _useSharedPluginState.shouldShowToolbar
|
|
46
|
+
shouldShowToolbar = _useSharedPluginState.shouldShowToolbar,
|
|
47
|
+
selectedNode = _useSharedPluginState.selectedNode;
|
|
45
48
|
return {
|
|
46
49
|
connectivityStateMode: connectivityStateMode,
|
|
47
50
|
editorToolbarDockingPreference: editorToolbarDockingPreference,
|
|
48
51
|
currentUserIntent: currentUserIntent,
|
|
49
52
|
shouldShowToolbar: shouldShowToolbar,
|
|
50
53
|
selection: selection,
|
|
51
|
-
editorViewMode: undefined
|
|
54
|
+
editorViewMode: undefined,
|
|
55
|
+
selectedNode: selectedNode
|
|
52
56
|
};
|
|
53
57
|
});
|
|
54
58
|
export var SelectionToolbar = function SelectionToolbar(_ref) {
|
|
@@ -81,8 +85,7 @@ export var SelectionToolbar = function SelectionToolbar(_ref) {
|
|
|
81
85
|
if (isCellSelection && isEditorControlsEnabled) {
|
|
82
86
|
return calculateToolbarPositionOnCellSelection(toolbarTitle)(editorView, position);
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
return calc(toolbarTitle)(editorView, position);
|
|
88
|
+
return calculateToolbarPositionTrackHead(toolbarTitle)(editorView, position);
|
|
86
89
|
}, [editorView]);
|
|
87
90
|
if (expValEquals('platform_editor_toolbar_aifc_template_editor', 'isEnabled', true) && editorToolbarDockingPreference === 'top' && disableSelectionToolbarWhenPinned || !components || !toolbar) {
|
|
88
91
|
return null;
|
|
@@ -5,8 +5,18 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
8
9
|
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
9
10
|
import type { RegisterComponentsAction, ToolbarPluginOptions } from './types';
|
|
11
|
+
export type EditorToolbarPluginState = {
|
|
12
|
+
selectedNode?: {
|
|
13
|
+
marks: string[];
|
|
14
|
+
node: PMNode;
|
|
15
|
+
nodeType: string;
|
|
16
|
+
pos: number;
|
|
17
|
+
};
|
|
18
|
+
shouldShowToolbar: boolean;
|
|
19
|
+
};
|
|
10
20
|
export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
11
21
|
actions: {
|
|
12
22
|
getComponents: () => Array<RegisterComponent>;
|
|
@@ -21,7 +31,5 @@ export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
|
21
31
|
OptionalPlugin<AnalyticsPlugin>
|
|
22
32
|
];
|
|
23
33
|
pluginConfiguration?: ToolbarPluginOptions;
|
|
24
|
-
sharedState:
|
|
25
|
-
shouldShowToolbar: boolean;
|
|
26
|
-
};
|
|
34
|
+
sharedState: EditorToolbarPluginState;
|
|
27
35
|
}>;
|
|
@@ -5,8 +5,18 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
8
9
|
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
9
10
|
import type { RegisterComponentsAction, ToolbarPluginOptions } from './types';
|
|
11
|
+
export type EditorToolbarPluginState = {
|
|
12
|
+
selectedNode?: {
|
|
13
|
+
marks: string[];
|
|
14
|
+
node: PMNode;
|
|
15
|
+
nodeType: string;
|
|
16
|
+
pos: number;
|
|
17
|
+
};
|
|
18
|
+
shouldShowToolbar: boolean;
|
|
19
|
+
};
|
|
10
20
|
export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
11
21
|
actions: {
|
|
12
22
|
getComponents: () => Array<RegisterComponent>;
|
|
@@ -21,7 +31,5 @@ export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
|
21
31
|
OptionalPlugin<AnalyticsPlugin>
|
|
22
32
|
];
|
|
23
33
|
pluginConfiguration?: ToolbarPluginOptions;
|
|
24
|
-
sharedState:
|
|
25
|
-
shouldShowToolbar: boolean;
|
|
26
|
-
};
|
|
34
|
+
sharedState: EditorToolbarPluginState;
|
|
27
35
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-toolbar",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Toolbar plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"@atlaskit/editor-toolbar": "^0.9.0",
|
|
39
39
|
"@atlaskit/editor-toolbar-model": "^0.2.0",
|
|
40
40
|
"@atlaskit/platform-feature-flags-react": "^0.3.0",
|
|
41
|
-
"@atlaskit/tmp-editor-statsig": "^12.
|
|
41
|
+
"@atlaskit/tmp-editor-statsig": "^12.24.0",
|
|
42
42
|
"@babel/runtime": "^7.0.0",
|
|
43
43
|
"bind-event-listener": "^3.0.0",
|
|
44
44
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@atlaskit/editor-common": "^109.
|
|
47
|
+
"@atlaskit/editor-common": "^109.8.0",
|
|
48
48
|
"react": "^18.2.0"
|
|
49
49
|
},
|
|
50
50
|
"techstack": {
|