@atlaskit/editor-plugin-toolbar 3.3.2 → 3.4.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/CHANGELOG.md +21 -0
- package/afm-products/tsconfig.json +60 -0
- package/dist/cjs/pm-plugins/experiences/SelectionToolbarOpenExperience.js +84 -0
- package/dist/cjs/toolbarPlugin.js +17 -5
- package/dist/cjs/ui/Section.js +10 -2
- package/dist/cjs/ui/toolbar-components.js +28 -4
- package/dist/es2019/pm-plugins/experiences/SelectionToolbarOpenExperience.js +78 -0
- package/dist/es2019/toolbarPlugin.js +16 -5
- package/dist/es2019/ui/Section.js +10 -2
- package/dist/es2019/ui/toolbar-components.js +28 -4
- package/dist/esm/pm-plugins/experiences/SelectionToolbarOpenExperience.js +78 -0
- package/dist/esm/toolbarPlugin.js +17 -5
- package/dist/esm/ui/Section.js +10 -2
- package/dist/esm/ui/toolbar-components.js +28 -4
- package/dist/types/pm-plugins/experiences/SelectionToolbarOpenExperience.d.ts +11 -0
- package/dist/types/toolbarPluginType.d.ts +13 -0
- package/dist/types/types/index.d.ts +53 -0
- package/dist/types/ui/toolbar-components.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/experiences/SelectionToolbarOpenExperience.d.ts +11 -0
- package/dist/types-ts4.5/toolbarPluginType.d.ts +13 -0
- package/dist/types-ts4.5/types/index.d.ts +53 -0
- package/dist/types-ts4.5/ui/toolbar-components.d.ts +2 -1
- package/package.json +5 -2
- package/dist/cjs/pm-plugins/experiences/ContextualToolbarOpenExperience.js +0 -73
- package/dist/es2019/pm-plugins/experiences/ContextualToolbarOpenExperience.js +0 -61
- package/dist/esm/pm-plugins/experiences/ContextualToolbarOpenExperience.js +0 -66
- package/dist/types/pm-plugins/experiences/ContextualToolbarOpenExperience.d.ts +0 -5
- package/dist/types-ts4.5/pm-plugins/experiences/ContextualToolbarOpenExperience.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-toolbar
|
|
2
2
|
|
|
3
|
+
## 3.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`301c7dd0ccdd2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/301c7dd0ccdd2) -
|
|
8
|
+
Adds new `contextualFormattingEnabled` plugin option to editor-plugin-toolbar. This has 3 options
|
|
9
|
+
(always-inline, always-pinned and controlled) to allow direct control over toolbar placement in
|
|
10
|
+
the editor.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 3.3.3
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- [`74c8f9fcfdf9d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/74c8f9fcfdf9d) -
|
|
21
|
+
Selection toolbar experience tracking
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 3.3.2
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.products.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": "../../../helpers/browser-apis/afm-products/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-plugin-analytics/afm-products/tsconfig.json"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../editor-plugin-connectivity/afm-products/tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../../editor-plugin-editor-viewmode/afm-products/tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../../editor-plugin-selection/afm-products/tsconfig.json"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "../../editor-plugin-user-intent/afm-products/tsconfig.json"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "../../editor-plugin-user-preferences/afm-products/tsconfig.json"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "../../editor-toolbar/afm-products/tsconfig.json"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"path": "../../editor-toolbar-model/afm-products/tsconfig.json"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "../../../platform/feature-flags/afm-products/tsconfig.json"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"path": "../../../platform/feature-flags-react/afm-products/tsconfig.json"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "../../tmp-editor-statsig/afm-products/tsconfig.json"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"path": "../../editor-common/afm-products/tsconfig.json"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _experiences = require("@atlaskit/editor-common/experiences");
|
|
8
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
|
+
var pluginKey = new _state.PluginKey('selectionToolbarOpenExperience');
|
|
11
|
+
var _default = exports.default = function _default(_ref) {
|
|
12
|
+
var popupsMountPointRef = _ref.popupsMountPointRef,
|
|
13
|
+
editorViewDomRef = _ref.editorViewDomRef;
|
|
14
|
+
var getTarget = function getTarget() {
|
|
15
|
+
var _editorViewDomRef$cur;
|
|
16
|
+
return popupsMountPointRef.current || ((_editorViewDomRef$cur = editorViewDomRef.current) === null || _editorViewDomRef$cur === void 0 ? void 0 : _editorViewDomRef$cur.closest('.ak-editor-content-area'));
|
|
17
|
+
};
|
|
18
|
+
var experience = new _experiences.Experience('selection-toolbar-open', {
|
|
19
|
+
checks: [new _experiences.ExperienceCheckTimeout(500), new _experiences.ExperienceCheckDomMutation({
|
|
20
|
+
onDomMutation: function onDomMutation(_ref2) {
|
|
21
|
+
var mutations = _ref2.mutations;
|
|
22
|
+
if (mutations.some(isSelectionToolbarAddedInMutation)) {
|
|
23
|
+
return {
|
|
24
|
+
status: 'success'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
observeConfig: function observeConfig() {
|
|
29
|
+
return {
|
|
30
|
+
target: getTarget(),
|
|
31
|
+
options: {
|
|
32
|
+
childList: true,
|
|
33
|
+
subtree: true
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
})]
|
|
38
|
+
});
|
|
39
|
+
return new _safePlugin.SafePlugin({
|
|
40
|
+
key: pluginKey,
|
|
41
|
+
state: {
|
|
42
|
+
init: function init() {
|
|
43
|
+
return {};
|
|
44
|
+
},
|
|
45
|
+
apply: function apply(_tr, pluginState, oldState, newState) {
|
|
46
|
+
if (!oldState.selection.empty && newState.selection.empty) {
|
|
47
|
+
experience.abort();
|
|
48
|
+
}
|
|
49
|
+
return pluginState;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
props: {
|
|
53
|
+
handleDOMEvents: {
|
|
54
|
+
mouseup: function mouseup(view) {
|
|
55
|
+
if (!view.state.selection.empty) {
|
|
56
|
+
experience.start();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
keydown: function keydown(_view, _ref3) {
|
|
60
|
+
var shiftKey = _ref3.shiftKey,
|
|
61
|
+
key = _ref3.key;
|
|
62
|
+
if (shiftKey && key.includes('Arrow') && !isSelectionToolbarWithinNode(getTarget())) {
|
|
63
|
+
experience.start();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
view: function view() {
|
|
69
|
+
return {
|
|
70
|
+
destroy: function destroy() {
|
|
71
|
+
experience.abort();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
var isSelectionToolbarAddedInMutation = function isSelectionToolbarAddedInMutation(_ref4) {
|
|
78
|
+
var type = _ref4.type,
|
|
79
|
+
addedNodes = _ref4.addedNodes;
|
|
80
|
+
return type === 'childList' && Array.from(addedNodes).some(isSelectionToolbarWithinNode);
|
|
81
|
+
};
|
|
82
|
+
var isSelectionToolbarWithinNode = function isSelectionToolbarWithinNode(node) {
|
|
83
|
+
return node instanceof HTMLElement && !!node.querySelector('[data-testid="editor-floating-toolbar"]');
|
|
84
|
+
};
|
|
@@ -15,7 +15,7 @@ var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
|
15
15
|
var _editorToolbarModel = require("@atlaskit/editor-toolbar-model");
|
|
16
16
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
17
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
18
|
-
var
|
|
18
|
+
var _SelectionToolbarOpenExperience = _interopRequireDefault(require("./pm-plugins/experiences/SelectionToolbarOpenExperience"));
|
|
19
19
|
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
20
20
|
var _consts = require("./ui/consts");
|
|
21
21
|
var _SelectionToolbar = require("./ui/SelectionToolbar");
|
|
@@ -75,10 +75,14 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
75
75
|
disableSelectionToolbar: false,
|
|
76
76
|
disableSelectionToolbarWhenPinned: false
|
|
77
77
|
} : _ref$config;
|
|
78
|
+
var popupsMountPointRef = {};
|
|
79
|
+
var editorViewDomRef = {};
|
|
78
80
|
var disableSelectionToolbar = config.disableSelectionToolbar,
|
|
79
|
-
disableSelectionToolbarWhenPinned = config.disableSelectionToolbarWhenPinned
|
|
81
|
+
disableSelectionToolbarWhenPinned = config.disableSelectionToolbarWhenPinned,
|
|
82
|
+
_config$contextualFor = config.contextualFormattingEnabled,
|
|
83
|
+
contextualFormattingEnabled = _config$contextualFor === void 0 ? 'always-pinned' : _config$contextualFor;
|
|
80
84
|
var registry = (0, _editorToolbarModel.createComponentRegistry)();
|
|
81
|
-
registry.register((0, _toolbarComponents.getToolbarComponents)(api, disableSelectionToolbar));
|
|
85
|
+
registry.register((0, _toolbarComponents.getToolbarComponents)(contextualFormattingEnabled, api, disableSelectionToolbar));
|
|
82
86
|
return {
|
|
83
87
|
name: 'toolbar',
|
|
84
88
|
actions: {
|
|
@@ -92,6 +96,9 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
92
96
|
},
|
|
93
97
|
getComponents: function getComponents() {
|
|
94
98
|
return registry.components;
|
|
99
|
+
},
|
|
100
|
+
contextualFormattingMode: function contextualFormattingMode() {
|
|
101
|
+
return contextualFormattingEnabled;
|
|
95
102
|
}
|
|
96
103
|
},
|
|
97
104
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -134,6 +141,7 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
134
141
|
}
|
|
135
142
|
},
|
|
136
143
|
view: function view(_view) {
|
|
144
|
+
editorViewDomRef.current = _view.dom;
|
|
137
145
|
var unbind = (0, _bindEventListener.bind)(_view.root, {
|
|
138
146
|
type: 'mouseup',
|
|
139
147
|
listener: function listener(ev) {
|
|
@@ -180,15 +188,19 @@ var toolbarPlugin = exports.toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
180
188
|
});
|
|
181
189
|
}
|
|
182
190
|
}].concat((0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_experience_tracking', 'isEnabled', true) ? [{
|
|
183
|
-
name: '
|
|
191
|
+
name: 'selectionToolbarOpenExperience',
|
|
184
192
|
plugin: function plugin() {
|
|
185
|
-
return (0,
|
|
193
|
+
return (0, _SelectionToolbarOpenExperience.default)({
|
|
194
|
+
popupsMountPointRef: popupsMountPointRef,
|
|
195
|
+
editorViewDomRef: editorViewDomRef
|
|
196
|
+
});
|
|
186
197
|
}
|
|
187
198
|
}] : []));
|
|
188
199
|
},
|
|
189
200
|
contentComponent: !disableSelectionToolbar ? function (_ref2) {
|
|
190
201
|
var editorView = _ref2.editorView,
|
|
191
202
|
popupsMountPoint = _ref2.popupsMountPoint;
|
|
203
|
+
popupsMountPointRef.current = popupsMountPoint;
|
|
192
204
|
if (!editorView) {
|
|
193
205
|
return null;
|
|
194
206
|
}
|
package/dist/cjs/ui/Section.js
CHANGED
|
@@ -9,14 +9,22 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
var _toolbar = require("@atlaskit/editor-common/toolbar");
|
|
10
10
|
var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
|
|
11
11
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
12
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
13
|
var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
|
|
13
14
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
14
15
|
var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar) {
|
|
15
16
|
if (editMode === 'view') {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This check is no longer needed with plugin config changes, the selection toolbar will not be registered and so
|
|
22
|
+
* no components will render
|
|
23
|
+
*/
|
|
24
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_placement_config')) {
|
|
25
|
+
if (disableSelectionToolbar) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
|
|
22
30
|
return true;
|
|
@@ -10,6 +10,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
11
|
var _toolbar = require("@atlaskit/editor-common/toolbar");
|
|
12
12
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
14
15
|
var _consts = require("./consts");
|
|
15
16
|
var _OverflowMenu = require("./OverflowMenu");
|
|
@@ -17,8 +18,8 @@ var _OverflowSection = require("./OverflowSection");
|
|
|
17
18
|
var _PrimaryToolbar = require("./PrimaryToolbar");
|
|
18
19
|
var _Section = require("./Section");
|
|
19
20
|
var _TextCollapsedMenu = require("./TextCollapsedMenu");
|
|
20
|
-
var
|
|
21
|
-
|
|
21
|
+
var getInlineTextToolbarComponents = function getInlineTextToolbarComponents() {
|
|
22
|
+
return [{
|
|
22
23
|
type: 'toolbar',
|
|
23
24
|
key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
|
|
24
25
|
component: function component(_ref) {
|
|
@@ -29,7 +30,10 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
|
|
|
29
30
|
testId: (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true) ? 'editor-floating-toolbar' : undefined
|
|
30
31
|
}, children);
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}];
|
|
34
|
+
};
|
|
35
|
+
var getPrimaryToolbarComponents = function getPrimaryToolbarComponents() {
|
|
36
|
+
return [{
|
|
33
37
|
type: 'toolbar',
|
|
34
38
|
key: _toolbar.TOOLBARS.PRIMARY_TOOLBAR,
|
|
35
39
|
component: (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_responsive', 'isEnabled', true) ? _PrimaryToolbar.PrimaryToolbar : function (_ref2) {
|
|
@@ -39,7 +43,10 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
|
|
|
39
43
|
testId: "primary-toolbar"
|
|
40
44
|
}, children);
|
|
41
45
|
}
|
|
42
|
-
}
|
|
46
|
+
}];
|
|
47
|
+
};
|
|
48
|
+
var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar) {
|
|
49
|
+
var components = [{
|
|
43
50
|
type: _toolbar.TEXT_SECTION.type,
|
|
44
51
|
key: _toolbar.TEXT_SECTION.key,
|
|
45
52
|
parents: [{
|
|
@@ -249,5 +256,22 @@ var getToolbarComponents = exports.getToolbarComponents = function getToolbarCom
|
|
|
249
256
|
}
|
|
250
257
|
});
|
|
251
258
|
}
|
|
259
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_placement_config')) {
|
|
260
|
+
switch (contextualFormattingEnabled) {
|
|
261
|
+
case 'always-inline':
|
|
262
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getInlineTextToolbarComponents()));
|
|
263
|
+
break;
|
|
264
|
+
case 'always-pinned':
|
|
265
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getPrimaryToolbarComponents()));
|
|
266
|
+
break;
|
|
267
|
+
case 'controlled':
|
|
268
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getInlineTextToolbarComponents()));
|
|
269
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getPrimaryToolbarComponents()));
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getInlineTextToolbarComponents()));
|
|
274
|
+
components.unshift.apply(components, (0, _toConsumableArray2.default)(getPrimaryToolbarComponents()));
|
|
275
|
+
}
|
|
252
276
|
return components;
|
|
253
277
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
const pluginKey = new PluginKey('selectionToolbarOpenExperience');
|
|
5
|
+
export default (({
|
|
6
|
+
popupsMountPointRef,
|
|
7
|
+
editorViewDomRef
|
|
8
|
+
}) => {
|
|
9
|
+
const getTarget = () => {
|
|
10
|
+
var _editorViewDomRef$cur;
|
|
11
|
+
return popupsMountPointRef.current || ((_editorViewDomRef$cur = editorViewDomRef.current) === null || _editorViewDomRef$cur === void 0 ? void 0 : _editorViewDomRef$cur.closest('.ak-editor-content-area'));
|
|
12
|
+
};
|
|
13
|
+
const experience = new Experience('selection-toolbar-open', {
|
|
14
|
+
checks: [new ExperienceCheckTimeout(500), new ExperienceCheckDomMutation({
|
|
15
|
+
onDomMutation: ({
|
|
16
|
+
mutations
|
|
17
|
+
}) => {
|
|
18
|
+
if (mutations.some(isSelectionToolbarAddedInMutation)) {
|
|
19
|
+
return {
|
|
20
|
+
status: 'success'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
observeConfig: () => ({
|
|
25
|
+
target: getTarget(),
|
|
26
|
+
options: {
|
|
27
|
+
childList: true,
|
|
28
|
+
subtree: true
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
33
|
+
return new SafePlugin({
|
|
34
|
+
key: pluginKey,
|
|
35
|
+
state: {
|
|
36
|
+
init: () => ({}),
|
|
37
|
+
apply: (_tr, pluginState, oldState, newState) => {
|
|
38
|
+
if (!oldState.selection.empty && newState.selection.empty) {
|
|
39
|
+
experience.abort();
|
|
40
|
+
}
|
|
41
|
+
return pluginState;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
props: {
|
|
45
|
+
handleDOMEvents: {
|
|
46
|
+
mouseup: view => {
|
|
47
|
+
if (!view.state.selection.empty) {
|
|
48
|
+
experience.start();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
keydown: (_view, {
|
|
52
|
+
shiftKey,
|
|
53
|
+
key
|
|
54
|
+
}) => {
|
|
55
|
+
if (shiftKey && key.includes('Arrow') && !isSelectionToolbarWithinNode(getTarget())) {
|
|
56
|
+
experience.start();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
view: () => {
|
|
62
|
+
return {
|
|
63
|
+
destroy: () => {
|
|
64
|
+
experience.abort();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const isSelectionToolbarAddedInMutation = ({
|
|
71
|
+
type,
|
|
72
|
+
addedNodes
|
|
73
|
+
}) => {
|
|
74
|
+
return type === 'childList' && Array.from(addedNodes).some(isSelectionToolbarWithinNode);
|
|
75
|
+
};
|
|
76
|
+
const isSelectionToolbarWithinNode = node => {
|
|
77
|
+
return node instanceof HTMLElement && !!node.querySelector('[data-testid="editor-floating-toolbar"]');
|
|
78
|
+
};
|
|
@@ -6,7 +6,7 @@ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-p
|
|
|
6
6
|
import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
|
|
7
7
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
8
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
9
|
-
import
|
|
9
|
+
import selectionToolbarOpenExperience from './pm-plugins/experiences/SelectionToolbarOpenExperience';
|
|
10
10
|
import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
|
|
11
11
|
import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
|
|
12
12
|
import { SelectionToolbar, SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
|
|
@@ -60,12 +60,15 @@ export const toolbarPlugin = ({
|
|
|
60
60
|
disableSelectionToolbarWhenPinned: false
|
|
61
61
|
}
|
|
62
62
|
}) => {
|
|
63
|
+
const popupsMountPointRef = {};
|
|
64
|
+
const editorViewDomRef = {};
|
|
63
65
|
const {
|
|
64
66
|
disableSelectionToolbar,
|
|
65
|
-
disableSelectionToolbarWhenPinned
|
|
67
|
+
disableSelectionToolbarWhenPinned,
|
|
68
|
+
contextualFormattingEnabled = 'always-pinned'
|
|
66
69
|
} = config;
|
|
67
70
|
const registry = createComponentRegistry();
|
|
68
|
-
registry.register(getToolbarComponents(api, disableSelectionToolbar));
|
|
71
|
+
registry.register(getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar));
|
|
69
72
|
return {
|
|
70
73
|
name: 'toolbar',
|
|
71
74
|
actions: {
|
|
@@ -78,6 +81,9 @@ export const toolbarPlugin = ({
|
|
|
78
81
|
},
|
|
79
82
|
getComponents: () => {
|
|
80
83
|
return registry.components;
|
|
84
|
+
},
|
|
85
|
+
contextualFormattingMode: () => {
|
|
86
|
+
return contextualFormattingEnabled;
|
|
81
87
|
}
|
|
82
88
|
},
|
|
83
89
|
getSharedState(editorState) {
|
|
@@ -125,6 +131,7 @@ export const toolbarPlugin = ({
|
|
|
125
131
|
}
|
|
126
132
|
},
|
|
127
133
|
view(view) {
|
|
134
|
+
editorViewDomRef.current = view.dom;
|
|
128
135
|
const unbind = bind(view.root, {
|
|
129
136
|
type: 'mouseup',
|
|
130
137
|
listener: function (ev) {
|
|
@@ -171,14 +178,18 @@ export const toolbarPlugin = ({
|
|
|
171
178
|
});
|
|
172
179
|
}
|
|
173
180
|
}, ...(expValEquals('platform_editor_experience_tracking', 'isEnabled', true) ? [{
|
|
174
|
-
name: '
|
|
175
|
-
plugin: () =>
|
|
181
|
+
name: 'selectionToolbarOpenExperience',
|
|
182
|
+
plugin: () => selectionToolbarOpenExperience({
|
|
183
|
+
popupsMountPointRef,
|
|
184
|
+
editorViewDomRef
|
|
185
|
+
})
|
|
176
186
|
}] : [])];
|
|
177
187
|
},
|
|
178
188
|
contentComponent: !disableSelectionToolbar ? ({
|
|
179
189
|
editorView,
|
|
180
190
|
popupsMountPoint
|
|
181
191
|
}) => {
|
|
192
|
+
popupsMountPointRef.current = popupsMountPoint;
|
|
182
193
|
if (!editorView) {
|
|
183
194
|
return null;
|
|
184
195
|
}
|
|
@@ -2,14 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { TOOLBARS, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
3
3
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
4
4
|
import { ToolbarSection, SeparatorPosition } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { conditionalHooksFactory } from '@atlaskit/platform-feature-flags-react';
|
|
6
7
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
8
|
const shouldShowSection = (editMode, toolbar, toolbarDocking, disableSelectionToolbar) => {
|
|
8
9
|
if (editMode === 'view') {
|
|
9
10
|
return false;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This check is no longer needed with plugin config changes, the selection toolbar will not be registered and so
|
|
15
|
+
* no components will render
|
|
16
|
+
*/
|
|
17
|
+
if (!fg('platform_editor_toolbar_aifc_placement_config')) {
|
|
18
|
+
if (disableSelectionToolbar) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
13
21
|
}
|
|
14
22
|
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
|
|
15
23
|
return true;
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_PRIMARY_TOOLBAR, OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_MENU_PRIMARY_TOOLBAR, OVERFLOW_SECTION, OVERFLOW_SECTION_PRIMARY_TOOLBAR, OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK, OVERFLOW_SECTION_RANK, PIN_SECTION, TEXT_COLLAPSED_GROUP, TEXT_SECTION, TEXT_SECTION_PRIMARY_TOOLBAR, TEXT_SECTION_COLLAPSED, TEXT_COLLAPSED_MENU, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
|
|
4
4
|
import { PrimaryToolbar as PrimaryToolbarBase, Show, Toolbar } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
7
|
import { SELECTION_TOOLBAR_LABEL } from './consts';
|
|
7
8
|
import { OverflowMenu } from './OverflowMenu';
|
|
@@ -9,8 +10,8 @@ import { OverflowSection } from './OverflowSection';
|
|
|
9
10
|
import { PrimaryToolbar } from './PrimaryToolbar';
|
|
10
11
|
import { Section } from './Section';
|
|
11
12
|
import { TextCollapsedMenu } from './TextCollapsedMenu';
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const getInlineTextToolbarComponents = () => {
|
|
14
|
+
return [{
|
|
14
15
|
type: 'toolbar',
|
|
15
16
|
key: TOOLBARS.INLINE_TEXT_TOOLBAR,
|
|
16
17
|
component: ({
|
|
@@ -22,7 +23,10 @@ export const getToolbarComponents = (api, disableSelectionToolbar) => {
|
|
|
22
23
|
testId: expValEquals('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true) ? 'editor-floating-toolbar' : undefined
|
|
23
24
|
}, children);
|
|
24
25
|
}
|
|
25
|
-
}
|
|
26
|
+
}];
|
|
27
|
+
};
|
|
28
|
+
const getPrimaryToolbarComponents = () => {
|
|
29
|
+
return [{
|
|
26
30
|
type: 'toolbar',
|
|
27
31
|
key: TOOLBARS.PRIMARY_TOOLBAR,
|
|
28
32
|
component: expValEquals('platform_editor_toolbar_aifc_responsive', 'isEnabled', true) ? PrimaryToolbar : ({
|
|
@@ -31,7 +35,10 @@ export const getToolbarComponents = (api, disableSelectionToolbar) => {
|
|
|
31
35
|
label: "Primary Toolbar",
|
|
32
36
|
testId: "primary-toolbar"
|
|
33
37
|
}, children)
|
|
34
|
-
}
|
|
38
|
+
}];
|
|
39
|
+
};
|
|
40
|
+
export const getToolbarComponents = (contextualFormattingEnabled, api, disableSelectionToolbar) => {
|
|
41
|
+
const components = [{
|
|
35
42
|
type: TEXT_SECTION.type,
|
|
36
43
|
key: TEXT_SECTION.key,
|
|
37
44
|
parents: [{
|
|
@@ -245,5 +252,22 @@ export const getToolbarComponents = (api, disableSelectionToolbar) => {
|
|
|
245
252
|
}
|
|
246
253
|
});
|
|
247
254
|
}
|
|
255
|
+
if (fg('platform_editor_toolbar_aifc_placement_config')) {
|
|
256
|
+
switch (contextualFormattingEnabled) {
|
|
257
|
+
case 'always-inline':
|
|
258
|
+
components.unshift(...getInlineTextToolbarComponents());
|
|
259
|
+
break;
|
|
260
|
+
case 'always-pinned':
|
|
261
|
+
components.unshift(...getPrimaryToolbarComponents());
|
|
262
|
+
break;
|
|
263
|
+
case 'controlled':
|
|
264
|
+
components.unshift(...getInlineTextToolbarComponents());
|
|
265
|
+
components.unshift(...getPrimaryToolbarComponents());
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
components.unshift(...getInlineTextToolbarComponents());
|
|
270
|
+
components.unshift(...getPrimaryToolbarComponents());
|
|
271
|
+
}
|
|
248
272
|
return components;
|
|
249
273
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
var pluginKey = new PluginKey('selectionToolbarOpenExperience');
|
|
5
|
+
export default (function (_ref) {
|
|
6
|
+
var popupsMountPointRef = _ref.popupsMountPointRef,
|
|
7
|
+
editorViewDomRef = _ref.editorViewDomRef;
|
|
8
|
+
var getTarget = function getTarget() {
|
|
9
|
+
var _editorViewDomRef$cur;
|
|
10
|
+
return popupsMountPointRef.current || ((_editorViewDomRef$cur = editorViewDomRef.current) === null || _editorViewDomRef$cur === void 0 ? void 0 : _editorViewDomRef$cur.closest('.ak-editor-content-area'));
|
|
11
|
+
};
|
|
12
|
+
var experience = new Experience('selection-toolbar-open', {
|
|
13
|
+
checks: [new ExperienceCheckTimeout(500), new ExperienceCheckDomMutation({
|
|
14
|
+
onDomMutation: function onDomMutation(_ref2) {
|
|
15
|
+
var mutations = _ref2.mutations;
|
|
16
|
+
if (mutations.some(isSelectionToolbarAddedInMutation)) {
|
|
17
|
+
return {
|
|
18
|
+
status: 'success'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
observeConfig: function observeConfig() {
|
|
23
|
+
return {
|
|
24
|
+
target: getTarget(),
|
|
25
|
+
options: {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
33
|
+
return new SafePlugin({
|
|
34
|
+
key: pluginKey,
|
|
35
|
+
state: {
|
|
36
|
+
init: function init() {
|
|
37
|
+
return {};
|
|
38
|
+
},
|
|
39
|
+
apply: function apply(_tr, pluginState, oldState, newState) {
|
|
40
|
+
if (!oldState.selection.empty && newState.selection.empty) {
|
|
41
|
+
experience.abort();
|
|
42
|
+
}
|
|
43
|
+
return pluginState;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
props: {
|
|
47
|
+
handleDOMEvents: {
|
|
48
|
+
mouseup: function mouseup(view) {
|
|
49
|
+
if (!view.state.selection.empty) {
|
|
50
|
+
experience.start();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
keydown: function keydown(_view, _ref3) {
|
|
54
|
+
var shiftKey = _ref3.shiftKey,
|
|
55
|
+
key = _ref3.key;
|
|
56
|
+
if (shiftKey && key.includes('Arrow') && !isSelectionToolbarWithinNode(getTarget())) {
|
|
57
|
+
experience.start();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
view: function view() {
|
|
63
|
+
return {
|
|
64
|
+
destroy: function destroy() {
|
|
65
|
+
experience.abort();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
var isSelectionToolbarAddedInMutation = function isSelectionToolbarAddedInMutation(_ref4) {
|
|
72
|
+
var type = _ref4.type,
|
|
73
|
+
addedNodes = _ref4.addedNodes;
|
|
74
|
+
return type === 'childList' && Array.from(addedNodes).some(isSelectionToolbarWithinNode);
|
|
75
|
+
};
|
|
76
|
+
var isSelectionToolbarWithinNode = function isSelectionToolbarWithinNode(node) {
|
|
77
|
+
return node instanceof HTMLElement && !!node.querySelector('[data-testid="editor-floating-toolbar"]');
|
|
78
|
+
};
|
|
@@ -10,7 +10,7 @@ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-p
|
|
|
10
10
|
import { createComponentRegistry } from '@atlaskit/editor-toolbar-model';
|
|
11
11
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
12
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
13
|
-
import
|
|
13
|
+
import selectionToolbarOpenExperience from './pm-plugins/experiences/SelectionToolbarOpenExperience';
|
|
14
14
|
import { editorToolbarPluginKey } from './pm-plugins/plugin-key';
|
|
15
15
|
import { DEFAULT_POPUP_SELECTORS } from './ui/consts';
|
|
16
16
|
import { SelectionToolbar, SelectionToolbarWithErrorBoundary } from './ui/SelectionToolbar';
|
|
@@ -68,10 +68,14 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
68
68
|
disableSelectionToolbar: false,
|
|
69
69
|
disableSelectionToolbarWhenPinned: false
|
|
70
70
|
} : _ref$config;
|
|
71
|
+
var popupsMountPointRef = {};
|
|
72
|
+
var editorViewDomRef = {};
|
|
71
73
|
var disableSelectionToolbar = config.disableSelectionToolbar,
|
|
72
|
-
disableSelectionToolbarWhenPinned = config.disableSelectionToolbarWhenPinned
|
|
74
|
+
disableSelectionToolbarWhenPinned = config.disableSelectionToolbarWhenPinned,
|
|
75
|
+
_config$contextualFor = config.contextualFormattingEnabled,
|
|
76
|
+
contextualFormattingEnabled = _config$contextualFor === void 0 ? 'always-pinned' : _config$contextualFor;
|
|
73
77
|
var registry = createComponentRegistry();
|
|
74
|
-
registry.register(getToolbarComponents(api, disableSelectionToolbar));
|
|
78
|
+
registry.register(getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar));
|
|
75
79
|
return {
|
|
76
80
|
name: 'toolbar',
|
|
77
81
|
actions: {
|
|
@@ -85,6 +89,9 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
85
89
|
},
|
|
86
90
|
getComponents: function getComponents() {
|
|
87
91
|
return registry.components;
|
|
92
|
+
},
|
|
93
|
+
contextualFormattingMode: function contextualFormattingMode() {
|
|
94
|
+
return contextualFormattingEnabled;
|
|
88
95
|
}
|
|
89
96
|
},
|
|
90
97
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -127,6 +134,7 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
127
134
|
}
|
|
128
135
|
},
|
|
129
136
|
view: function view(_view) {
|
|
137
|
+
editorViewDomRef.current = _view.dom;
|
|
130
138
|
var unbind = bind(_view.root, {
|
|
131
139
|
type: 'mouseup',
|
|
132
140
|
listener: function listener(ev) {
|
|
@@ -173,15 +181,19 @@ export var toolbarPlugin = function toolbarPlugin(_ref) {
|
|
|
173
181
|
});
|
|
174
182
|
}
|
|
175
183
|
}].concat(_toConsumableArray(expValEquals('platform_editor_experience_tracking', 'isEnabled', true) ? [{
|
|
176
|
-
name: '
|
|
184
|
+
name: 'selectionToolbarOpenExperience',
|
|
177
185
|
plugin: function plugin() {
|
|
178
|
-
return
|
|
186
|
+
return selectionToolbarOpenExperience({
|
|
187
|
+
popupsMountPointRef: popupsMountPointRef,
|
|
188
|
+
editorViewDomRef: editorViewDomRef
|
|
189
|
+
});
|
|
179
190
|
}
|
|
180
191
|
}] : []));
|
|
181
192
|
},
|
|
182
193
|
contentComponent: !disableSelectionToolbar ? function (_ref2) {
|
|
183
194
|
var editorView = _ref2.editorView,
|
|
184
195
|
popupsMountPoint = _ref2.popupsMountPoint;
|
|
196
|
+
popupsMountPointRef.current = popupsMountPoint;
|
|
185
197
|
if (!editorView) {
|
|
186
198
|
return null;
|
|
187
199
|
}
|
package/dist/esm/ui/Section.js
CHANGED
|
@@ -2,14 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { TOOLBARS, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
3
3
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
4
4
|
import { ToolbarSection, SeparatorPosition } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { conditionalHooksFactory } from '@atlaskit/platform-feature-flags-react';
|
|
6
7
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
8
|
var shouldShowSection = function shouldShowSection(editMode, toolbar, toolbarDocking, disableSelectionToolbar) {
|
|
8
9
|
if (editMode === 'view') {
|
|
9
10
|
return false;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This check is no longer needed with plugin config changes, the selection toolbar will not be registered and so
|
|
15
|
+
* no components will render
|
|
16
|
+
*/
|
|
17
|
+
if (!fg('platform_editor_toolbar_aifc_placement_config')) {
|
|
18
|
+
if (disableSelectionToolbar) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
13
21
|
}
|
|
14
22
|
if ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.key) === TOOLBARS.INLINE_TEXT_TOOLBAR && toolbarDocking !== 'top') {
|
|
15
23
|
return true;
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { INSERT_BLOCK_SECTION, LINKING_SECTION, OVERFLOW_GROUP, OVERFLOW_GROUP_PRIMARY_TOOLBAR, OVERFLOW_GROUP_PRIMARY_TOOLBAR_RANK, OVERFLOW_GROUP_RANK, OVERFLOW_MENU, OVERFLOW_MENU_PRIMARY_TOOLBAR, OVERFLOW_SECTION, OVERFLOW_SECTION_PRIMARY_TOOLBAR, OVERFLOW_SECTION_PRIMARY_TOOLBAR_RANK, OVERFLOW_SECTION_RANK, PIN_SECTION, TEXT_COLLAPSED_GROUP, TEXT_SECTION, TEXT_SECTION_PRIMARY_TOOLBAR, TEXT_SECTION_COLLAPSED, TEXT_COLLAPSED_MENU, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
|
|
5
5
|
import { PrimaryToolbar as PrimaryToolbarBase, Show, Toolbar } from '@atlaskit/editor-toolbar';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
8
|
import { SELECTION_TOOLBAR_LABEL } from './consts';
|
|
8
9
|
import { OverflowMenu } from './OverflowMenu';
|
|
@@ -10,8 +11,8 @@ import { OverflowSection } from './OverflowSection';
|
|
|
10
11
|
import { PrimaryToolbar } from './PrimaryToolbar';
|
|
11
12
|
import { Section } from './Section';
|
|
12
13
|
import { TextCollapsedMenu } from './TextCollapsedMenu';
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var getInlineTextToolbarComponents = function getInlineTextToolbarComponents() {
|
|
15
|
+
return [{
|
|
15
16
|
type: 'toolbar',
|
|
16
17
|
key: TOOLBARS.INLINE_TEXT_TOOLBAR,
|
|
17
18
|
component: function component(_ref) {
|
|
@@ -22,7 +23,10 @@ export var getToolbarComponents = function getToolbarComponents(api, disableSele
|
|
|
22
23
|
testId: expValEquals('platform_editor_toolbar_aifc_patch_5', 'isEnabled', true) ? 'editor-floating-toolbar' : undefined
|
|
23
24
|
}, children);
|
|
24
25
|
}
|
|
25
|
-
}
|
|
26
|
+
}];
|
|
27
|
+
};
|
|
28
|
+
var getPrimaryToolbarComponents = function getPrimaryToolbarComponents() {
|
|
29
|
+
return [{
|
|
26
30
|
type: 'toolbar',
|
|
27
31
|
key: TOOLBARS.PRIMARY_TOOLBAR,
|
|
28
32
|
component: expValEquals('platform_editor_toolbar_aifc_responsive', 'isEnabled', true) ? PrimaryToolbar : function (_ref2) {
|
|
@@ -32,7 +36,10 @@ export var getToolbarComponents = function getToolbarComponents(api, disableSele
|
|
|
32
36
|
testId: "primary-toolbar"
|
|
33
37
|
}, children);
|
|
34
38
|
}
|
|
35
|
-
}
|
|
39
|
+
}];
|
|
40
|
+
};
|
|
41
|
+
export var getToolbarComponents = function getToolbarComponents(contextualFormattingEnabled, api, disableSelectionToolbar) {
|
|
42
|
+
var components = [{
|
|
36
43
|
type: TEXT_SECTION.type,
|
|
37
44
|
key: TEXT_SECTION.key,
|
|
38
45
|
parents: [{
|
|
@@ -242,5 +249,22 @@ export var getToolbarComponents = function getToolbarComponents(api, disableSele
|
|
|
242
249
|
}
|
|
243
250
|
});
|
|
244
251
|
}
|
|
252
|
+
if (fg('platform_editor_toolbar_aifc_placement_config')) {
|
|
253
|
+
switch (contextualFormattingEnabled) {
|
|
254
|
+
case 'always-inline':
|
|
255
|
+
components.unshift.apply(components, _toConsumableArray(getInlineTextToolbarComponents()));
|
|
256
|
+
break;
|
|
257
|
+
case 'always-pinned':
|
|
258
|
+
components.unshift.apply(components, _toConsumableArray(getPrimaryToolbarComponents()));
|
|
259
|
+
break;
|
|
260
|
+
case 'controlled':
|
|
261
|
+
components.unshift.apply(components, _toConsumableArray(getInlineTextToolbarComponents()));
|
|
262
|
+
components.unshift.apply(components, _toConsumableArray(getPrimaryToolbarComponents()));
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
components.unshift.apply(components, _toConsumableArray(getInlineTextToolbarComponents()));
|
|
267
|
+
components.unshift.apply(components, _toConsumableArray(getPrimaryToolbarComponents()));
|
|
268
|
+
}
|
|
245
269
|
return components;
|
|
246
270
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
type SelectionToolbarOpenExperienceOptions = {
|
|
3
|
+
editorViewDomRef: {
|
|
4
|
+
current?: HTMLElement;
|
|
5
|
+
};
|
|
6
|
+
popupsMountPointRef: {
|
|
7
|
+
current?: HTMLElement;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare const _default: ({ popupsMountPointRef, editorViewDomRef, }: SelectionToolbarOpenExperienceOptions) => SafePlugin<{}>;
|
|
11
|
+
export default _default;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
4
|
import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
|
|
@@ -19,6 +20,18 @@ export type EditorToolbarPluginState = {
|
|
|
19
20
|
};
|
|
20
21
|
export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
21
22
|
actions: {
|
|
23
|
+
/**
|
|
24
|
+
* Returns the current contextual formatting toolbar mode configuration.
|
|
25
|
+
*
|
|
26
|
+
* This method retrieves the active setting that determines the behavior and placement
|
|
27
|
+
* of the contextual formatting toolbar in the editor.
|
|
28
|
+
*
|
|
29
|
+
* @returns The active contextual formatting mode:
|
|
30
|
+
* - `always-inline`: Formatting controls appear in a floating toolbar near selected text
|
|
31
|
+
* - `always-pinned`: Formatting controls are pinned to the top toolbar (default)
|
|
32
|
+
* - `controlled`: Both inline and primary toolbars are available
|
|
33
|
+
*/
|
|
34
|
+
contextualFormattingMode: () => ContextualFormattingEnabledOptions;
|
|
22
35
|
getComponents: () => Array<RegisterComponent>;
|
|
23
36
|
registerComponents: RegisterComponentsAction;
|
|
24
37
|
};
|
|
@@ -1,5 +1,58 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
2
3
|
export type ToolbarPluginOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Controls which toolbars are available for in the editor.
|
|
6
|
+
*
|
|
7
|
+
* The contextual formatting toolbar provides text formatting options (bold, italic, links, etc.)
|
|
8
|
+
* that appear contextually based on user selection and interaction.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This option determines where and when the formatting toolbar is displayed:
|
|
12
|
+
* - **Primary Toolbar**: The toolbar mounted at the top of the editor that is always visible
|
|
13
|
+
* - **Inline Text Toolbar**: A floating toolbar that appears near the selected text
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* // Always show formatting controls in a floating (inline) toolbar near selection
|
|
18
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
19
|
+
* contextualFormattingEnabled: 'always-inline',
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // Always show formatting controls pinned to the top (primary) toolbar
|
|
26
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
27
|
+
* contextualFormattingEnabled: 'always-pinned',
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* // Allow dynamic control of toolbar placement (both inline and primary available)
|
|
34
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
35
|
+
* contextualFormattingEnabled: 'controlled',
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
contextualFormattingEnabled?: ContextualFormattingEnabledOptions;
|
|
42
|
+
/**
|
|
43
|
+
* @private
|
|
44
|
+
* @deprecated
|
|
45
|
+
* @description
|
|
46
|
+
* This option is deprecated and will be removed in the future, replaced with `contextualFormattingEnabled`.
|
|
47
|
+
*
|
|
48
|
+
* To disable the selection toolbar (so only the primary toolbar is shown), use `contextualFormattingEnabled: 'always-pinned'`.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
52
|
+
* contextualFormattingEnabled: 'always-inline',
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
3
56
|
disableSelectionToolbar?: boolean;
|
|
4
57
|
disableSelectionToolbarWhenPinned?: boolean;
|
|
5
58
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
3
|
import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
3
4
|
import type { ToolbarPlugin } from '../toolbarPluginType';
|
|
4
|
-
export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
|
|
5
|
+
export declare const getToolbarComponents: (contextualFormattingEnabled: ContextualFormattingEnabledOptions, api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
type SelectionToolbarOpenExperienceOptions = {
|
|
3
|
+
editorViewDomRef: {
|
|
4
|
+
current?: HTMLElement;
|
|
5
|
+
};
|
|
6
|
+
popupsMountPointRef: {
|
|
7
|
+
current?: HTMLElement;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare const _default: ({ popupsMountPointRef, editorViewDomRef, }: SelectionToolbarOpenExperienceOptions) => SafePlugin<{}>;
|
|
11
|
+
export default _default;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
4
|
import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
|
|
@@ -19,6 +20,18 @@ export type EditorToolbarPluginState = {
|
|
|
19
20
|
};
|
|
20
21
|
export type ToolbarPlugin = NextEditorPlugin<'toolbar', {
|
|
21
22
|
actions: {
|
|
23
|
+
/**
|
|
24
|
+
* Returns the current contextual formatting toolbar mode configuration.
|
|
25
|
+
*
|
|
26
|
+
* This method retrieves the active setting that determines the behavior and placement
|
|
27
|
+
* of the contextual formatting toolbar in the editor.
|
|
28
|
+
*
|
|
29
|
+
* @returns The active contextual formatting mode:
|
|
30
|
+
* - `always-inline`: Formatting controls appear in a floating toolbar near selected text
|
|
31
|
+
* - `always-pinned`: Formatting controls are pinned to the top toolbar (default)
|
|
32
|
+
* - `controlled`: Both inline and primary toolbars are available
|
|
33
|
+
*/
|
|
34
|
+
contextualFormattingMode: () => ContextualFormattingEnabledOptions;
|
|
22
35
|
getComponents: () => Array<RegisterComponent>;
|
|
23
36
|
registerComponents: RegisterComponentsAction;
|
|
24
37
|
};
|
|
@@ -1,5 +1,58 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
2
3
|
export type ToolbarPluginOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Controls which toolbars are available for in the editor.
|
|
6
|
+
*
|
|
7
|
+
* The contextual formatting toolbar provides text formatting options (bold, italic, links, etc.)
|
|
8
|
+
* that appear contextually based on user selection and interaction.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This option determines where and when the formatting toolbar is displayed:
|
|
12
|
+
* - **Primary Toolbar**: The toolbar mounted at the top of the editor that is always visible
|
|
13
|
+
* - **Inline Text Toolbar**: A floating toolbar that appears near the selected text
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* // Always show formatting controls in a floating (inline) toolbar near selection
|
|
18
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
19
|
+
* contextualFormattingEnabled: 'always-inline',
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // Always show formatting controls pinned to the top (primary) toolbar
|
|
26
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
27
|
+
* contextualFormattingEnabled: 'always-pinned',
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* // Allow dynamic control of toolbar placement (both inline and primary available)
|
|
34
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
35
|
+
* contextualFormattingEnabled: 'controlled',
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
contextualFormattingEnabled?: ContextualFormattingEnabledOptions;
|
|
42
|
+
/**
|
|
43
|
+
* @private
|
|
44
|
+
* @deprecated
|
|
45
|
+
* @description
|
|
46
|
+
* This option is deprecated and will be removed in the future, replaced with `contextualFormattingEnabled`.
|
|
47
|
+
*
|
|
48
|
+
* To disable the selection toolbar (so only the primary toolbar is shown), use `contextualFormattingEnabled: 'always-pinned'`.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const toolbarPlugin = createToolbarPlugin({
|
|
52
|
+
* contextualFormattingEnabled: 'always-inline',
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
3
56
|
disableSelectionToolbar?: boolean;
|
|
4
57
|
disableSelectionToolbarWhenPinned?: boolean;
|
|
5
58
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { ContextualFormattingEnabledOptions } from '@atlaskit/editor-common/toolbar';
|
|
1
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
3
|
import { type RegisterComponent } from '@atlaskit/editor-toolbar-model';
|
|
3
4
|
import type { ToolbarPlugin } from '../toolbarPluginType';
|
|
4
|
-
export declare const getToolbarComponents: (api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
|
|
5
|
+
export declare const getToolbarComponents: (contextualFormattingEnabled: ContextualFormattingEnabledOptions, api?: ExtractInjectionAPI<ToolbarPlugin>, disableSelectionToolbar?: boolean) => RegisterComponent[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-toolbar",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Toolbar plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@atlaskit/editor-common": "^110.
|
|
49
|
+
"@atlaskit/editor-common": "^110.18.0",
|
|
50
50
|
"react": "^18.2.0"
|
|
51
51
|
},
|
|
52
52
|
"platform-feature-flags": {
|
|
@@ -55,6 +55,9 @@
|
|
|
55
55
|
},
|
|
56
56
|
"platform_editor_toolbar_aifc_user_intent_fix": {
|
|
57
57
|
"type": "boolean"
|
|
58
|
+
},
|
|
59
|
+
"platform_editor_toolbar_aifc_placement_config": {
|
|
60
|
+
"type": "boolean"
|
|
58
61
|
}
|
|
59
62
|
},
|
|
60
63
|
"techstack": {
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _experiences = require("@atlaskit/editor-common/experiences");
|
|
10
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
-
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; }
|
|
13
|
-
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; }
|
|
14
|
-
var pluginKey = new _state.PluginKey('contextualToolbarOpenExperience');
|
|
15
|
-
var _default = exports.default = function _default() {
|
|
16
|
-
var contextualToolbarOpenExperience = new _experiences.Experience('platform-editor-contextual-toolbar-open-experience', {
|
|
17
|
-
checks: [new _experiences.ExperienceCheckTimeout(500), new _experiences.ExperienceCheckDomMutation({
|
|
18
|
-
onDomMutation: function onDomMutation(_ref) {
|
|
19
|
-
var mutations = _ref.mutations;
|
|
20
|
-
if (mutations.some(isMutationAddingContextualToolbar)) {
|
|
21
|
-
return {
|
|
22
|
-
status: 'success'
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
observeConfig: function observeConfig() {
|
|
27
|
-
return {
|
|
28
|
-
target: document.body,
|
|
29
|
-
options: {
|
|
30
|
-
childList: true,
|
|
31
|
-
subtree: true
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
})]
|
|
36
|
-
});
|
|
37
|
-
return new _safePlugin.SafePlugin({
|
|
38
|
-
key: pluginKey,
|
|
39
|
-
state: {
|
|
40
|
-
init: function init() {
|
|
41
|
-
return {
|
|
42
|
-
shouldShowContextualToolbar: false
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
apply: function apply(_tr, pluginState, _, newState) {
|
|
46
|
-
var isTextSelection = newState.selection instanceof _state.TextSelection;
|
|
47
|
-
var isNotEmptySelection = !newState.selection.empty;
|
|
48
|
-
var shouldShowContextualToolbar = isTextSelection && isNotEmptySelection;
|
|
49
|
-
if (shouldShowContextualToolbar && !pluginState.shouldShowContextualToolbar) {
|
|
50
|
-
contextualToolbarOpenExperience.start();
|
|
51
|
-
} else if (!shouldShowContextualToolbar && pluginState.shouldShowContextualToolbar) {
|
|
52
|
-
contextualToolbarOpenExperience.abort();
|
|
53
|
-
}
|
|
54
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
55
|
-
shouldShowContextualToolbar: shouldShowContextualToolbar
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
view: function view() {
|
|
60
|
-
return {
|
|
61
|
-
destroy: function destroy() {
|
|
62
|
-
contextualToolbarOpenExperience.abort();
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
var isMutationAddingContextualToolbar = function isMutationAddingContextualToolbar(mutation) {
|
|
69
|
-
return mutation.type === 'childList' && Array.from(mutation.addedNodes).some(nodeIncludesContextualToolbar);
|
|
70
|
-
};
|
|
71
|
-
var nodeIncludesContextualToolbar = function nodeIncludesContextualToolbar(node) {
|
|
72
|
-
return node instanceof HTMLElement && node.getAttribute('data-testid') === 'popup-wrapper' && node.querySelector('[data-testid="text-section"]');
|
|
73
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
|
|
2
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
const pluginKey = new PluginKey('contextualToolbarOpenExperience');
|
|
5
|
-
export default (() => {
|
|
6
|
-
const contextualToolbarOpenExperience = new Experience('platform-editor-contextual-toolbar-open-experience', {
|
|
7
|
-
checks: [new ExperienceCheckTimeout(500), new ExperienceCheckDomMutation({
|
|
8
|
-
onDomMutation: ({
|
|
9
|
-
mutations
|
|
10
|
-
}) => {
|
|
11
|
-
if (mutations.some(isMutationAddingContextualToolbar)) {
|
|
12
|
-
return {
|
|
13
|
-
status: 'success'
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
observeConfig: () => ({
|
|
18
|
-
target: document.body,
|
|
19
|
-
options: {
|
|
20
|
-
childList: true,
|
|
21
|
-
subtree: true
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
})]
|
|
25
|
-
});
|
|
26
|
-
return new SafePlugin({
|
|
27
|
-
key: pluginKey,
|
|
28
|
-
state: {
|
|
29
|
-
init: () => ({
|
|
30
|
-
shouldShowContextualToolbar: false
|
|
31
|
-
}),
|
|
32
|
-
apply: (_tr, pluginState, _, newState) => {
|
|
33
|
-
const isTextSelection = newState.selection instanceof TextSelection;
|
|
34
|
-
const isNotEmptySelection = !newState.selection.empty;
|
|
35
|
-
const shouldShowContextualToolbar = isTextSelection && isNotEmptySelection;
|
|
36
|
-
if (shouldShowContextualToolbar && !pluginState.shouldShowContextualToolbar) {
|
|
37
|
-
contextualToolbarOpenExperience.start();
|
|
38
|
-
} else if (!shouldShowContextualToolbar && pluginState.shouldShowContextualToolbar) {
|
|
39
|
-
contextualToolbarOpenExperience.abort();
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
...pluginState,
|
|
43
|
-
shouldShowContextualToolbar
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
view: () => {
|
|
48
|
-
return {
|
|
49
|
-
destroy: () => {
|
|
50
|
-
contextualToolbarOpenExperience.abort();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
const isMutationAddingContextualToolbar = mutation => {
|
|
57
|
-
return mutation.type === 'childList' && Array.from(mutation.addedNodes).some(nodeIncludesContextualToolbar);
|
|
58
|
-
};
|
|
59
|
-
const nodeIncludesContextualToolbar = node => {
|
|
60
|
-
return node instanceof HTMLElement && node.getAttribute('data-testid') === 'popup-wrapper' && node.querySelector('[data-testid="text-section"]');
|
|
61
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
|
|
5
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
-
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
var pluginKey = new PluginKey('contextualToolbarOpenExperience');
|
|
8
|
-
export default (function () {
|
|
9
|
-
var contextualToolbarOpenExperience = new Experience('platform-editor-contextual-toolbar-open-experience', {
|
|
10
|
-
checks: [new ExperienceCheckTimeout(500), new ExperienceCheckDomMutation({
|
|
11
|
-
onDomMutation: function onDomMutation(_ref) {
|
|
12
|
-
var mutations = _ref.mutations;
|
|
13
|
-
if (mutations.some(isMutationAddingContextualToolbar)) {
|
|
14
|
-
return {
|
|
15
|
-
status: 'success'
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
observeConfig: function observeConfig() {
|
|
20
|
-
return {
|
|
21
|
-
target: document.body,
|
|
22
|
-
options: {
|
|
23
|
-
childList: true,
|
|
24
|
-
subtree: true
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
})]
|
|
29
|
-
});
|
|
30
|
-
return new SafePlugin({
|
|
31
|
-
key: pluginKey,
|
|
32
|
-
state: {
|
|
33
|
-
init: function init() {
|
|
34
|
-
return {
|
|
35
|
-
shouldShowContextualToolbar: false
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
apply: function apply(_tr, pluginState, _, newState) {
|
|
39
|
-
var isTextSelection = newState.selection instanceof TextSelection;
|
|
40
|
-
var isNotEmptySelection = !newState.selection.empty;
|
|
41
|
-
var shouldShowContextualToolbar = isTextSelection && isNotEmptySelection;
|
|
42
|
-
if (shouldShowContextualToolbar && !pluginState.shouldShowContextualToolbar) {
|
|
43
|
-
contextualToolbarOpenExperience.start();
|
|
44
|
-
} else if (!shouldShowContextualToolbar && pluginState.shouldShowContextualToolbar) {
|
|
45
|
-
contextualToolbarOpenExperience.abort();
|
|
46
|
-
}
|
|
47
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
48
|
-
shouldShowContextualToolbar: shouldShowContextualToolbar
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
view: function view() {
|
|
53
|
-
return {
|
|
54
|
-
destroy: function destroy() {
|
|
55
|
-
contextualToolbarOpenExperience.abort();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var isMutationAddingContextualToolbar = function isMutationAddingContextualToolbar(mutation) {
|
|
62
|
-
return mutation.type === 'childList' && Array.from(mutation.addedNodes).some(nodeIncludesContextualToolbar);
|
|
63
|
-
};
|
|
64
|
-
var nodeIncludesContextualToolbar = function nodeIncludesContextualToolbar(node) {
|
|
65
|
-
return node instanceof HTMLElement && node.getAttribute('data-testid') === 'popup-wrapper' && node.querySelector('[data-testid="text-section"]');
|
|
66
|
-
};
|