@atlaskit/editor-plugin-selection-extension 9.0.7 → 9.0.8
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/dist/cjs/pm-plugins/utils/index.js +1 -1
- package/dist/cjs/selectionExtensionPlugin.js +7 -5
- package/dist/cjs/ui/SelectionExtensionComponentContext.js +20 -0
- package/dist/cjs/ui/menu/SelectionExtensionDropdownItem.js +51 -1
- package/dist/cjs/ui/menu/SelectionExtensionMenuItems.js +2 -2
- package/dist/cjs/ui/menu/SelectionExtensionNestedDropdownMenu.js +26 -2
- package/dist/cjs/ui/utils/registerBlockMenuItems.js +31 -12
- package/dist/es2019/pm-plugins/utils/index.js +1 -1
- package/dist/es2019/selectionExtensionPlugin.js +7 -5
- package/dist/es2019/ui/SelectionExtensionComponentContext.js +15 -0
- package/dist/es2019/ui/menu/SelectionExtensionDropdownItem.js +54 -1
- package/dist/es2019/ui/menu/SelectionExtensionMenuItems.js +2 -2
- package/dist/es2019/ui/menu/SelectionExtensionNestedDropdownMenu.js +27 -2
- package/dist/es2019/ui/utils/registerBlockMenuItems.js +28 -8
- package/dist/esm/pm-plugins/utils/index.js +1 -1
- package/dist/esm/selectionExtensionPlugin.js +7 -5
- package/dist/esm/ui/SelectionExtensionComponentContext.js +15 -0
- package/dist/esm/ui/menu/SelectionExtensionDropdownItem.js +51 -1
- package/dist/esm/ui/menu/SelectionExtensionMenuItems.js +2 -2
- package/dist/esm/ui/menu/SelectionExtensionNestedDropdownMenu.js +26 -2
- package/dist/esm/ui/utils/registerBlockMenuItems.js +31 -12
- package/dist/types/pm-plugins/utils/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/ui/SelectionExtensionComponentContext.d.ts +12 -0
- package/dist/types/ui/menu/SelectionExtensionMenuItems.d.ts +1 -1
- package/dist/types/ui/utils/registerBlockMenuItems.d.ts +10 -1
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/types/index.d.ts +8 -0
- package/dist/types-ts4.5/ui/SelectionExtensionComponentContext.d.ts +12 -0
- package/dist/types-ts4.5/ui/menu/SelectionExtensionMenuItems.d.ts +1 -1
- package/dist/types-ts4.5/ui/utils/registerBlockMenuItems.d.ts +10 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 9.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`342bed74cf6e9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/342bed74cf6e9) -
|
|
8
|
+
EDITOR-4037 Block menu selection extension click handling
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 9.0.7
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -54,7 +54,7 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* @private
|
|
57
|
-
* @deprecated use
|
|
57
|
+
* @deprecated use getSelectionTextInfoNew instead
|
|
58
58
|
*/
|
|
59
59
|
var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
60
60
|
var _api$userPreferences, _api$editorViewMode;
|
|
@@ -26,9 +26,7 @@ var _registerBlockMenuItems = require("./ui/utils/registerBlockMenuItems");
|
|
|
26
26
|
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
27
27
|
var api = _ref.api,
|
|
28
28
|
config = _ref.config;
|
|
29
|
-
var editorViewRef = {
|
|
30
|
-
current: null
|
|
31
|
-
};
|
|
29
|
+
var editorViewRef = {};
|
|
32
30
|
var cachedSelection;
|
|
33
31
|
var cachedOverflowMenuOptions;
|
|
34
32
|
var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
|
|
@@ -57,7 +55,11 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
if ((0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true)) {
|
|
60
|
-
(0, _registerBlockMenuItems.registerBlockMenuItems)(
|
|
58
|
+
(0, _registerBlockMenuItems.registerBlockMenuItems)({
|
|
59
|
+
extensionList: extensionList,
|
|
60
|
+
api: api,
|
|
61
|
+
editorViewRef: editorViewRef
|
|
62
|
+
});
|
|
61
63
|
}
|
|
62
64
|
return {
|
|
63
65
|
name: 'selectionExtension',
|
|
@@ -313,7 +315,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
313
315
|
editorViewRef.current = editorView;
|
|
314
316
|
return {
|
|
315
317
|
destroy: function destroy() {
|
|
316
|
-
editorViewRef.current
|
|
318
|
+
delete editorViewRef.current;
|
|
317
319
|
}
|
|
318
320
|
};
|
|
319
321
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSelectionExtensionComponentContext = exports.SelectionExtensionComponentContextProvider = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
/*
|
|
9
|
+
* Common context passed down to selection extension components
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var SelectionExtensionComponentContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
13
|
+
var SelectionExtensionComponentContextProvider = exports.SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
|
|
14
|
+
var useSelectionExtensionComponentContext = exports.useSelectionExtensionComponentContext = function useSelectionExtensionComponentContext() {
|
|
15
|
+
var context = (0, _react.useContext)(SelectionExtensionComponentContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
@@ -6,15 +6,65 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.SelectionExtensionDropdownItem = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
10
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
11
|
+
var _main = require("../../pm-plugins/main");
|
|
12
|
+
var _utils = require("../../pm-plugins/utils");
|
|
13
|
+
var _types = require("../../types");
|
|
14
|
+
var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
|
|
10
15
|
var SelectionExtensionDropdownItem = exports.SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
|
|
11
16
|
var dropdownItem = _ref.dropdownItem;
|
|
12
17
|
var IconComponent = dropdownItem.icon;
|
|
18
|
+
var _useSelectionExtensio = (0, _SelectionExtensionComponentContext.useSelectionExtensionComponentContext)(),
|
|
19
|
+
api = _useSelectionExtensio.api,
|
|
20
|
+
editorView = _useSelectionExtensio.editorView,
|
|
21
|
+
extensionKey = _useSelectionExtensio.extensionKey,
|
|
22
|
+
extensionSource = _useSelectionExtensio.extensionSource,
|
|
23
|
+
extensionLocation = _useSelectionExtensio.extensionLocation;
|
|
24
|
+
var handleClick = function handleClick() {
|
|
25
|
+
var _api$analytics;
|
|
26
|
+
if (dropdownItem.contentComponent) {
|
|
27
|
+
var _api$blockControls;
|
|
28
|
+
var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
|
|
29
|
+
var selection = preservedSelection || editorView.state.selection;
|
|
30
|
+
var selectionInfo = (0, _utils.getSelectionTextInfoNew)(selection, editorView, api);
|
|
31
|
+
api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
|
|
32
|
+
extension: dropdownItem,
|
|
33
|
+
selection: selectionInfo
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
api.core.actions.execute(function (_ref2) {
|
|
37
|
+
var tr = _ref2.tr;
|
|
38
|
+
var _getSelectionAdfInfoN = (0, _utils.getSelectionAdfInfoNew)(tr.selection),
|
|
39
|
+
selectedNode = _getSelectionAdfInfoN.selectedNode,
|
|
40
|
+
nodePos = _getSelectionAdfInfoN.nodePos;
|
|
41
|
+
tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
42
|
+
type: _types.SelectionExtensionActionTypes.SET_SELECTED_NODE,
|
|
43
|
+
selectedNode: selectedNode,
|
|
44
|
+
nodePos: nodePos
|
|
45
|
+
});
|
|
46
|
+
return tr;
|
|
47
|
+
});
|
|
48
|
+
dropdownItem.onClick && dropdownItem.onClick();
|
|
49
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
50
|
+
action: _analytics.ACTION.CLICKED,
|
|
51
|
+
actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
|
|
52
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
|
|
53
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
54
|
+
attributes: {
|
|
55
|
+
extensionKey: extensionKey,
|
|
56
|
+
extensionSource: extensionSource,
|
|
57
|
+
extensionLocation: extensionLocation,
|
|
58
|
+
extensionElement: 'dropdown-item',
|
|
59
|
+
extensionItemKey: dropdownItem.key
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
13
63
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
14
64
|
elemBefore: IconComponent ? /*#__PURE__*/_react.default.createElement(IconComponent, {
|
|
15
65
|
label: ""
|
|
16
66
|
}) : undefined,
|
|
17
|
-
onClick:
|
|
67
|
+
onClick: handleClick,
|
|
18
68
|
isDisabled: dropdownItem.isDisabled
|
|
19
69
|
}, dropdownItem.label);
|
|
20
70
|
};
|
|
@@ -18,12 +18,12 @@ var SelectionExtensionMenuItems = exports.SelectionExtensionMenuItems = function
|
|
|
18
18
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, extensionMenuItems.map(function (item) {
|
|
19
19
|
if ((0, _menuItems.isNestedDropdownMenuConfiguration)(item)) {
|
|
20
20
|
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionNestedDropdownMenu.SelectionExtensionNestedDropdownMenu, {
|
|
21
|
-
key: item.label,
|
|
21
|
+
key: item.key || item.label,
|
|
22
22
|
nestedDropdownMenu: item
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
|
|
26
|
-
key: item.label,
|
|
26
|
+
key: item.key || item.label,
|
|
27
27
|
dropdownItem: item
|
|
28
28
|
});
|
|
29
29
|
}));
|
|
@@ -6,15 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.SelectionExtensionNestedDropdownMenu = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
10
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
10
11
|
var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
|
|
12
|
+
var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
|
|
11
13
|
var _SelectionExtensionDropdownItem = require("./SelectionExtensionDropdownItem");
|
|
12
14
|
var ChildItems = function ChildItems(_ref) {
|
|
13
15
|
var nestedDropdownMenu = _ref.nestedDropdownMenu;
|
|
14
16
|
var childItems = nestedDropdownMenu.getMenuItems();
|
|
15
17
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, null, childItems.map(function (dropdownItem) {
|
|
16
18
|
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownItem.SelectionExtensionDropdownItem, {
|
|
17
|
-
key: dropdownItem.label,
|
|
19
|
+
key: dropdownItem.key || dropdownItem.label,
|
|
18
20
|
dropdownItem: dropdownItem
|
|
19
21
|
});
|
|
20
22
|
}));
|
|
@@ -22,6 +24,27 @@ var ChildItems = function ChildItems(_ref) {
|
|
|
22
24
|
var SelectionExtensionNestedDropdownMenu = exports.SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
|
|
23
25
|
var nestedDropdownMenu = _ref2.nestedDropdownMenu;
|
|
24
26
|
var IconComponent = nestedDropdownMenu.icon;
|
|
27
|
+
var _useSelectionExtensio = (0, _SelectionExtensionComponentContext.useSelectionExtensionComponentContext)(),
|
|
28
|
+
api = _useSelectionExtensio.api,
|
|
29
|
+
extensionKey = _useSelectionExtensio.extensionKey,
|
|
30
|
+
extensionSource = _useSelectionExtensio.extensionSource,
|
|
31
|
+
extensionLocation = _useSelectionExtensio.extensionLocation;
|
|
32
|
+
var handleClick = function handleClick() {
|
|
33
|
+
var _api$analytics;
|
|
34
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
35
|
+
action: _analytics.ACTION.CLICKED,
|
|
36
|
+
actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
|
|
37
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
|
|
38
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
39
|
+
attributes: {
|
|
40
|
+
extensionKey: extensionKey,
|
|
41
|
+
extensionSource: extensionSource,
|
|
42
|
+
extensionLocation: extensionLocation,
|
|
43
|
+
extensionElement: 'nested-dropdown',
|
|
44
|
+
extensionItemKey: nestedDropdownMenu.key
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
25
48
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
|
|
26
49
|
text: nestedDropdownMenu.label,
|
|
27
50
|
elemBefore: IconComponent ? /*#__PURE__*/_react.default.createElement(IconComponent, {
|
|
@@ -29,7 +52,8 @@ var SelectionExtensionNestedDropdownMenu = exports.SelectionExtensionNestedDropd
|
|
|
29
52
|
}) : undefined,
|
|
30
53
|
elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
|
|
31
54
|
label: 'nested menu'
|
|
32
|
-
})
|
|
55
|
+
}),
|
|
56
|
+
onClick: handleClick
|
|
33
57
|
}, /*#__PURE__*/_react.default.createElement(ChildItems, {
|
|
34
58
|
nestedDropdownMenu: nestedDropdownMenu
|
|
35
59
|
}));
|
|
@@ -8,16 +8,39 @@ exports.registerBlockMenuItems = registerBlockMenuItems;
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _blockMenu = require("@atlaskit/editor-common/block-menu");
|
|
10
10
|
var _SelectionExtensionMenuItems = require("../menu/SelectionExtensionMenuItems");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
var _SelectionExtensionComponentContext = require("../SelectionExtensionComponentContext");
|
|
12
|
+
function registerBlockMenuItems(_ref) {
|
|
13
|
+
var extensionList = _ref.extensionList,
|
|
14
|
+
api = _ref.api,
|
|
15
|
+
editorViewRef = _ref.editorViewRef;
|
|
16
|
+
extensionList.forEach(function (_ref2) {
|
|
17
|
+
var source = _ref2.source,
|
|
18
|
+
key = _ref2.key,
|
|
19
|
+
blockMenu = _ref2.blockMenu;
|
|
17
20
|
if (source !== 'first-party' || !blockMenu) {
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
20
|
-
api
|
|
23
|
+
if (!(api !== null && api !== void 0 && api.blockMenu)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var component = function component() {
|
|
27
|
+
var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
|
|
28
|
+
if (!editorView) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionComponentContext.SelectionExtensionComponentContextProvider, {
|
|
32
|
+
value: {
|
|
33
|
+
api: api,
|
|
34
|
+
editorView: editorView,
|
|
35
|
+
extensionKey: key,
|
|
36
|
+
extensionSource: source,
|
|
37
|
+
extensionLocation: 'block-menu'
|
|
38
|
+
}
|
|
39
|
+
}, /*#__PURE__*/_react.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
|
|
40
|
+
getMenuItems: blockMenu.getMenuItems
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
api.blockMenu.actions.registerBlockMenuComponents([{
|
|
21
44
|
type: 'block-menu-item',
|
|
22
45
|
key: "selection-extension-".concat(key),
|
|
23
46
|
parent: {
|
|
@@ -25,11 +48,7 @@ function registerBlockMenuItems(extensionList, api) {
|
|
|
25
48
|
key: _blockMenu.TRANSFORM_CREATE_MENU_SECTION.key,
|
|
26
49
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
|
|
27
50
|
},
|
|
28
|
-
component:
|
|
29
|
-
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionMenuItems.SelectionExtensionMenuItems, {
|
|
30
|
-
getMenuItems: blockMenu.getMenuItems
|
|
31
|
-
});
|
|
32
|
-
}
|
|
51
|
+
component: component
|
|
33
52
|
}]);
|
|
34
53
|
});
|
|
35
54
|
}
|
|
@@ -43,7 +43,7 @@ const getSelectionInfoFromCellSelection = selection => {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* @private
|
|
46
|
-
* @deprecated use
|
|
46
|
+
* @deprecated use getSelectionTextInfoNew instead
|
|
47
47
|
*/
|
|
48
48
|
export const getSelectionTextInfo = (view, api) => {
|
|
49
49
|
var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$editorViewMode, _api$editorViewMode$s;
|
|
@@ -19,9 +19,7 @@ export const selectionExtensionPlugin = ({
|
|
|
19
19
|
api,
|
|
20
20
|
config
|
|
21
21
|
}) => {
|
|
22
|
-
const editorViewRef = {
|
|
23
|
-
current: null
|
|
24
|
-
};
|
|
22
|
+
const editorViewRef = {};
|
|
25
23
|
let cachedSelection;
|
|
26
24
|
let cachedOverflowMenuOptions;
|
|
27
25
|
const isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
|
|
@@ -46,7 +44,11 @@ export const selectionExtensionPlugin = ({
|
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
49
|
-
registerBlockMenuItems(
|
|
47
|
+
registerBlockMenuItems({
|
|
48
|
+
extensionList,
|
|
49
|
+
api,
|
|
50
|
+
editorViewRef
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
53
|
return {
|
|
52
54
|
name: 'selectionExtension',
|
|
@@ -308,7 +310,7 @@ export const selectionExtensionPlugin = ({
|
|
|
308
310
|
editorViewRef.current = editorView;
|
|
309
311
|
return {
|
|
310
312
|
destroy: () => {
|
|
311
|
-
editorViewRef.current
|
|
313
|
+
delete editorViewRef.current;
|
|
312
314
|
}
|
|
313
315
|
};
|
|
314
316
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Common context passed down to selection extension components
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SelectionExtensionComponentContext = /*#__PURE__*/createContext(undefined);
|
|
8
|
+
export const SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
|
|
9
|
+
export const useSelectionExtensionComponentContext = () => {
|
|
10
|
+
const context = useContext(SelectionExtensionComponentContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
@@ -1,14 +1,67 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
4
|
+
import { selectionExtensionPluginKey } from '../../pm-plugins/main';
|
|
5
|
+
import { getSelectionAdfInfoNew, getSelectionTextInfoNew } from '../../pm-plugins/utils';
|
|
6
|
+
import { SelectionExtensionActionTypes } from '../../types';
|
|
7
|
+
import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
|
|
3
8
|
export const SelectionExtensionDropdownItem = ({
|
|
4
9
|
dropdownItem
|
|
5
10
|
}) => {
|
|
6
11
|
const IconComponent = dropdownItem.icon;
|
|
12
|
+
const {
|
|
13
|
+
api,
|
|
14
|
+
editorView,
|
|
15
|
+
extensionKey,
|
|
16
|
+
extensionSource,
|
|
17
|
+
extensionLocation
|
|
18
|
+
} = useSelectionExtensionComponentContext();
|
|
19
|
+
const handleClick = () => {
|
|
20
|
+
var _api$analytics;
|
|
21
|
+
if (dropdownItem.contentComponent) {
|
|
22
|
+
var _api$blockControls, _api$blockControls$sh;
|
|
23
|
+
const preservedSelection = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection;
|
|
24
|
+
const selection = preservedSelection || editorView.state.selection;
|
|
25
|
+
const selectionInfo = getSelectionTextInfoNew(selection, editorView, api);
|
|
26
|
+
api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
|
|
27
|
+
extension: dropdownItem,
|
|
28
|
+
selection: selectionInfo
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
api.core.actions.execute(({
|
|
32
|
+
tr
|
|
33
|
+
}) => {
|
|
34
|
+
const {
|
|
35
|
+
selectedNode,
|
|
36
|
+
nodePos
|
|
37
|
+
} = getSelectionAdfInfoNew(tr.selection);
|
|
38
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
39
|
+
type: SelectionExtensionActionTypes.SET_SELECTED_NODE,
|
|
40
|
+
selectedNode,
|
|
41
|
+
nodePos
|
|
42
|
+
});
|
|
43
|
+
return tr;
|
|
44
|
+
});
|
|
45
|
+
dropdownItem.onClick && dropdownItem.onClick();
|
|
46
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
47
|
+
action: ACTION.CLICKED,
|
|
48
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
49
|
+
actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
|
|
50
|
+
eventType: EVENT_TYPE.TRACK,
|
|
51
|
+
attributes: {
|
|
52
|
+
extensionKey,
|
|
53
|
+
extensionSource,
|
|
54
|
+
extensionLocation,
|
|
55
|
+
extensionElement: 'dropdown-item',
|
|
56
|
+
extensionItemKey: dropdownItem.key
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
7
60
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
8
61
|
elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
|
|
9
62
|
label: ""
|
|
10
63
|
}) : undefined,
|
|
11
|
-
onClick:
|
|
64
|
+
onClick: handleClick,
|
|
12
65
|
isDisabled: dropdownItem.isDisabled
|
|
13
66
|
}, dropdownItem.label);
|
|
14
67
|
};
|
|
@@ -12,12 +12,12 @@ export const SelectionExtensionMenuItems = ({
|
|
|
12
12
|
return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(item => {
|
|
13
13
|
if (isNestedDropdownMenuConfiguration(item)) {
|
|
14
14
|
return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
|
|
15
|
-
key: item.label,
|
|
15
|
+
key: item.key || item.label,
|
|
16
16
|
nestedDropdownMenu: item
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
|
|
20
|
-
key: item.label,
|
|
20
|
+
key: item.key || item.label,
|
|
21
21
|
dropdownItem: item
|
|
22
22
|
});
|
|
23
23
|
}));
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
|
|
3
4
|
import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
|
|
5
|
+
import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
|
|
4
6
|
import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
|
|
5
7
|
const ChildItems = ({
|
|
6
8
|
nestedDropdownMenu
|
|
7
9
|
}) => {
|
|
8
10
|
const childItems = nestedDropdownMenu.getMenuItems();
|
|
9
11
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, childItems.map(dropdownItem => /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
|
|
10
|
-
key: dropdownItem.label,
|
|
12
|
+
key: dropdownItem.key || dropdownItem.label,
|
|
11
13
|
dropdownItem: dropdownItem
|
|
12
14
|
})));
|
|
13
15
|
};
|
|
@@ -15,6 +17,28 @@ export const SelectionExtensionNestedDropdownMenu = ({
|
|
|
15
17
|
nestedDropdownMenu
|
|
16
18
|
}) => {
|
|
17
19
|
const IconComponent = nestedDropdownMenu.icon;
|
|
20
|
+
const {
|
|
21
|
+
api,
|
|
22
|
+
extensionKey,
|
|
23
|
+
extensionSource,
|
|
24
|
+
extensionLocation
|
|
25
|
+
} = useSelectionExtensionComponentContext();
|
|
26
|
+
const handleClick = () => {
|
|
27
|
+
var _api$analytics;
|
|
28
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
29
|
+
action: ACTION.CLICKED,
|
|
30
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
31
|
+
actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
|
|
32
|
+
eventType: EVENT_TYPE.TRACK,
|
|
33
|
+
attributes: {
|
|
34
|
+
extensionKey,
|
|
35
|
+
extensionSource,
|
|
36
|
+
extensionLocation,
|
|
37
|
+
extensionElement: 'nested-dropdown',
|
|
38
|
+
extensionItemKey: nestedDropdownMenu.key
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
18
42
|
return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
|
|
19
43
|
text: nestedDropdownMenu.label,
|
|
20
44
|
elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
|
|
@@ -22,7 +46,8 @@ export const SelectionExtensionNestedDropdownMenu = ({
|
|
|
22
46
|
}) : undefined,
|
|
23
47
|
elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
|
|
24
48
|
label: 'nested menu'
|
|
25
|
-
})
|
|
49
|
+
}),
|
|
50
|
+
onClick: handleClick
|
|
26
51
|
}, /*#__PURE__*/React.createElement(ChildItems, {
|
|
27
52
|
nestedDropdownMenu: nestedDropdownMenu
|
|
28
53
|
}));
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
|
|
3
3
|
import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
|
|
4
|
-
|
|
4
|
+
import { SelectionExtensionComponentContextProvider } from '../SelectionExtensionComponentContext';
|
|
5
|
+
export function registerBlockMenuItems({
|
|
6
|
+
extensionList,
|
|
7
|
+
api,
|
|
8
|
+
editorViewRef
|
|
9
|
+
}) {
|
|
5
10
|
extensionList.forEach(({
|
|
6
11
|
source,
|
|
7
12
|
key,
|
|
8
13
|
blockMenu
|
|
9
14
|
}) => {
|
|
10
|
-
var _api$blockMenu;
|
|
11
15
|
if (source !== 'first-party' || !blockMenu) {
|
|
12
16
|
return;
|
|
13
17
|
}
|
|
14
|
-
api
|
|
18
|
+
if (!(api !== null && api !== void 0 && api.blockMenu)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const component = () => {
|
|
22
|
+
const editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
|
|
23
|
+
if (!editorView) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider, {
|
|
27
|
+
value: {
|
|
28
|
+
api,
|
|
29
|
+
editorView,
|
|
30
|
+
extensionKey: key,
|
|
31
|
+
extensionSource: source,
|
|
32
|
+
extensionLocation: 'block-menu'
|
|
33
|
+
}
|
|
34
|
+
}, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
|
|
35
|
+
getMenuItems: blockMenu.getMenuItems
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
38
|
+
api.blockMenu.actions.registerBlockMenuComponents([{
|
|
15
39
|
type: 'block-menu-item',
|
|
16
40
|
key: `selection-extension-${key}`,
|
|
17
41
|
parent: {
|
|
@@ -19,11 +43,7 @@ export function registerBlockMenuItems(extensionList, api) {
|
|
|
19
43
|
key: TRANSFORM_CREATE_MENU_SECTION.key,
|
|
20
44
|
rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
|
|
21
45
|
},
|
|
22
|
-
component
|
|
23
|
-
return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
|
|
24
|
-
getMenuItems: blockMenu.getMenuItems
|
|
25
|
-
});
|
|
26
|
-
}
|
|
46
|
+
component
|
|
27
47
|
}]);
|
|
28
48
|
});
|
|
29
49
|
}
|
|
@@ -44,7 +44,7 @@ var getSelectionInfoFromCellSelection = function getSelectionInfoFromCellSelecti
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* @private
|
|
47
|
-
* @deprecated use
|
|
47
|
+
* @deprecated use getSelectionTextInfoNew instead
|
|
48
48
|
*/
|
|
49
49
|
export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
50
50
|
var _api$userPreferences, _api$editorViewMode;
|
|
@@ -19,9 +19,7 @@ import { registerBlockMenuItems } from './ui/utils/registerBlockMenuItems';
|
|
|
19
19
|
export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
20
20
|
var api = _ref.api,
|
|
21
21
|
config = _ref.config;
|
|
22
|
-
var editorViewRef = {
|
|
23
|
-
current: null
|
|
24
|
-
};
|
|
22
|
+
var editorViewRef = {};
|
|
25
23
|
var cachedSelection;
|
|
26
24
|
var cachedOverflowMenuOptions;
|
|
27
25
|
var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
|
|
@@ -50,7 +48,11 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
if (expValEquals('platform_editor_block_menu', 'isEnabled', true)) {
|
|
53
|
-
registerBlockMenuItems(
|
|
51
|
+
registerBlockMenuItems({
|
|
52
|
+
extensionList: extensionList,
|
|
53
|
+
api: api,
|
|
54
|
+
editorViewRef: editorViewRef
|
|
55
|
+
});
|
|
54
56
|
}
|
|
55
57
|
return {
|
|
56
58
|
name: 'selectionExtension',
|
|
@@ -306,7 +308,7 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
306
308
|
editorViewRef.current = editorView;
|
|
307
309
|
return {
|
|
308
310
|
destroy: function destroy() {
|
|
309
|
-
editorViewRef.current
|
|
311
|
+
delete editorViewRef.current;
|
|
310
312
|
}
|
|
311
313
|
};
|
|
312
314
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Common context passed down to selection extension components
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var SelectionExtensionComponentContext = /*#__PURE__*/createContext(undefined);
|
|
8
|
+
export var SelectionExtensionComponentContextProvider = SelectionExtensionComponentContext.Provider;
|
|
9
|
+
export var useSelectionExtensionComponentContext = function useSelectionExtensionComponentContext() {
|
|
10
|
+
var context = useContext(SelectionExtensionComponentContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useSelectionExtensionComponentContext must be used within SelectionExtensionComponentContextProvider');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
@@ -1,13 +1,63 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
4
|
+
import { selectionExtensionPluginKey } from '../../pm-plugins/main';
|
|
5
|
+
import { getSelectionAdfInfoNew, getSelectionTextInfoNew } from '../../pm-plugins/utils';
|
|
6
|
+
import { SelectionExtensionActionTypes } from '../../types';
|
|
7
|
+
import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
|
|
3
8
|
export var SelectionExtensionDropdownItem = function SelectionExtensionDropdownItem(_ref) {
|
|
4
9
|
var dropdownItem = _ref.dropdownItem;
|
|
5
10
|
var IconComponent = dropdownItem.icon;
|
|
11
|
+
var _useSelectionExtensio = useSelectionExtensionComponentContext(),
|
|
12
|
+
api = _useSelectionExtensio.api,
|
|
13
|
+
editorView = _useSelectionExtensio.editorView,
|
|
14
|
+
extensionKey = _useSelectionExtensio.extensionKey,
|
|
15
|
+
extensionSource = _useSelectionExtensio.extensionSource,
|
|
16
|
+
extensionLocation = _useSelectionExtensio.extensionLocation;
|
|
17
|
+
var handleClick = function handleClick() {
|
|
18
|
+
var _api$analytics;
|
|
19
|
+
if (dropdownItem.contentComponent) {
|
|
20
|
+
var _api$blockControls;
|
|
21
|
+
var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
|
|
22
|
+
var selection = preservedSelection || editorView.state.selection;
|
|
23
|
+
var selectionInfo = getSelectionTextInfoNew(selection, editorView, api);
|
|
24
|
+
api.core.actions.execute(api.selectionExtension.commands.setActiveExtension({
|
|
25
|
+
extension: dropdownItem,
|
|
26
|
+
selection: selectionInfo
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
api.core.actions.execute(function (_ref2) {
|
|
30
|
+
var tr = _ref2.tr;
|
|
31
|
+
var _getSelectionAdfInfoN = getSelectionAdfInfoNew(tr.selection),
|
|
32
|
+
selectedNode = _getSelectionAdfInfoN.selectedNode,
|
|
33
|
+
nodePos = _getSelectionAdfInfoN.nodePos;
|
|
34
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
35
|
+
type: SelectionExtensionActionTypes.SET_SELECTED_NODE,
|
|
36
|
+
selectedNode: selectedNode,
|
|
37
|
+
nodePos: nodePos
|
|
38
|
+
});
|
|
39
|
+
return tr;
|
|
40
|
+
});
|
|
41
|
+
dropdownItem.onClick && dropdownItem.onClick();
|
|
42
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
43
|
+
action: ACTION.CLICKED,
|
|
44
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
45
|
+
actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_ITEM,
|
|
46
|
+
eventType: EVENT_TYPE.TRACK,
|
|
47
|
+
attributes: {
|
|
48
|
+
extensionKey: extensionKey,
|
|
49
|
+
extensionSource: extensionSource,
|
|
50
|
+
extensionLocation: extensionLocation,
|
|
51
|
+
extensionElement: 'dropdown-item',
|
|
52
|
+
extensionItemKey: dropdownItem.key
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
6
56
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
7
57
|
elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
|
|
8
58
|
label: ""
|
|
9
59
|
}) : undefined,
|
|
10
|
-
onClick:
|
|
60
|
+
onClick: handleClick,
|
|
11
61
|
isDisabled: dropdownItem.isDisabled
|
|
12
62
|
}, dropdownItem.label);
|
|
13
63
|
};
|
|
@@ -11,12 +11,12 @@ export var SelectionExtensionMenuItems = function SelectionExtensionMenuItems(_r
|
|
|
11
11
|
return /*#__PURE__*/React.createElement(React.Fragment, null, extensionMenuItems.map(function (item) {
|
|
12
12
|
if (isNestedDropdownMenuConfiguration(item)) {
|
|
13
13
|
return /*#__PURE__*/React.createElement(SelectionExtensionNestedDropdownMenu, {
|
|
14
|
-
key: item.label,
|
|
14
|
+
key: item.key || item.label,
|
|
15
15
|
nestedDropdownMenu: item
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
|
|
19
|
-
key: item.label,
|
|
19
|
+
key: item.key || item.label,
|
|
20
20
|
dropdownItem: item
|
|
21
21
|
});
|
|
22
22
|
}));
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
|
|
3
4
|
import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
|
|
5
|
+
import { useSelectionExtensionComponentContext } from '../SelectionExtensionComponentContext';
|
|
4
6
|
import { SelectionExtensionDropdownItem } from './SelectionExtensionDropdownItem';
|
|
5
7
|
var ChildItems = function ChildItems(_ref) {
|
|
6
8
|
var nestedDropdownMenu = _ref.nestedDropdownMenu;
|
|
7
9
|
var childItems = nestedDropdownMenu.getMenuItems();
|
|
8
10
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, childItems.map(function (dropdownItem) {
|
|
9
11
|
return /*#__PURE__*/React.createElement(SelectionExtensionDropdownItem, {
|
|
10
|
-
key: dropdownItem.label,
|
|
12
|
+
key: dropdownItem.key || dropdownItem.label,
|
|
11
13
|
dropdownItem: dropdownItem
|
|
12
14
|
});
|
|
13
15
|
}));
|
|
@@ -15,6 +17,27 @@ var ChildItems = function ChildItems(_ref) {
|
|
|
15
17
|
export var SelectionExtensionNestedDropdownMenu = function SelectionExtensionNestedDropdownMenu(_ref2) {
|
|
16
18
|
var nestedDropdownMenu = _ref2.nestedDropdownMenu;
|
|
17
19
|
var IconComponent = nestedDropdownMenu.icon;
|
|
20
|
+
var _useSelectionExtensio = useSelectionExtensionComponentContext(),
|
|
21
|
+
api = _useSelectionExtensio.api,
|
|
22
|
+
extensionKey = _useSelectionExtensio.extensionKey,
|
|
23
|
+
extensionSource = _useSelectionExtensio.extensionSource,
|
|
24
|
+
extensionLocation = _useSelectionExtensio.extensionLocation;
|
|
25
|
+
var handleClick = function handleClick() {
|
|
26
|
+
var _api$analytics;
|
|
27
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
28
|
+
action: ACTION.CLICKED,
|
|
29
|
+
actionSubject: ACTION_SUBJECT.BUTTON,
|
|
30
|
+
actionSubjectId: ACTION_SUBJECT_ID.EDITOR_PLUGIN_SELECTION_EXTENSION_DROPDOWN,
|
|
31
|
+
eventType: EVENT_TYPE.TRACK,
|
|
32
|
+
attributes: {
|
|
33
|
+
extensionKey: extensionKey,
|
|
34
|
+
extensionSource: extensionSource,
|
|
35
|
+
extensionLocation: extensionLocation,
|
|
36
|
+
extensionElement: 'nested-dropdown',
|
|
37
|
+
extensionItemKey: nestedDropdownMenu.key
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
18
41
|
return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
|
|
19
42
|
text: nestedDropdownMenu.label,
|
|
20
43
|
elemBefore: IconComponent ? /*#__PURE__*/React.createElement(IconComponent, {
|
|
@@ -22,7 +45,8 @@ export var SelectionExtensionNestedDropdownMenu = function SelectionExtensionNes
|
|
|
22
45
|
}) : undefined,
|
|
23
46
|
elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
|
|
24
47
|
label: 'nested menu'
|
|
25
|
-
})
|
|
48
|
+
}),
|
|
49
|
+
onClick: handleClick
|
|
26
50
|
}, /*#__PURE__*/React.createElement(ChildItems, {
|
|
27
51
|
nestedDropdownMenu: nestedDropdownMenu
|
|
28
52
|
}));
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_MENU_ITEM_RANK } from '@atlaskit/editor-common/block-menu';
|
|
3
3
|
import { SelectionExtensionMenuItems } from '../menu/SelectionExtensionMenuItems';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { SelectionExtensionComponentContextProvider } from '../SelectionExtensionComponentContext';
|
|
5
|
+
export function registerBlockMenuItems(_ref) {
|
|
6
|
+
var extensionList = _ref.extensionList,
|
|
7
|
+
api = _ref.api,
|
|
8
|
+
editorViewRef = _ref.editorViewRef;
|
|
9
|
+
extensionList.forEach(function (_ref2) {
|
|
10
|
+
var source = _ref2.source,
|
|
11
|
+
key = _ref2.key,
|
|
12
|
+
blockMenu = _ref2.blockMenu;
|
|
10
13
|
if (source !== 'first-party' || !blockMenu) {
|
|
11
14
|
return;
|
|
12
15
|
}
|
|
13
|
-
api
|
|
16
|
+
if (!(api !== null && api !== void 0 && api.blockMenu)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var component = function component() {
|
|
20
|
+
var editorView = editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current;
|
|
21
|
+
if (!editorView) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionComponentContextProvider, {
|
|
25
|
+
value: {
|
|
26
|
+
api: api,
|
|
27
|
+
editorView: editorView,
|
|
28
|
+
extensionKey: key,
|
|
29
|
+
extensionSource: source,
|
|
30
|
+
extensionLocation: 'block-menu'
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
|
|
33
|
+
getMenuItems: blockMenu.getMenuItems
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
api.blockMenu.actions.registerBlockMenuComponents([{
|
|
14
37
|
type: 'block-menu-item',
|
|
15
38
|
key: "selection-extension-".concat(key),
|
|
16
39
|
parent: {
|
|
@@ -18,11 +41,7 @@ export function registerBlockMenuItems(extensionList, api) {
|
|
|
18
41
|
key: TRANSFORM_CREATE_MENU_SECTION.key,
|
|
19
42
|
rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
|
|
20
43
|
},
|
|
21
|
-
component:
|
|
22
|
-
return /*#__PURE__*/React.createElement(SelectionExtensionMenuItems, {
|
|
23
|
-
getMenuItems: blockMenu.getMenuItems
|
|
24
|
-
});
|
|
25
|
-
}
|
|
44
|
+
component: component
|
|
26
45
|
}]);
|
|
27
46
|
});
|
|
28
47
|
}
|
|
@@ -14,7 +14,7 @@ type SelectionInfo = {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* @private
|
|
17
|
-
* @deprecated use
|
|
17
|
+
* @deprecated use getSelectionTextInfoNew instead
|
|
18
18
|
*/
|
|
19
19
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
20
20
|
export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
@@ -136,6 +136,10 @@ export type BlockMenuExtensionConfiguration = {
|
|
|
136
136
|
getMenuItems: GetMenuItemsFn;
|
|
137
137
|
};
|
|
138
138
|
export type ExtensionToolbarItemConfiguration = {
|
|
139
|
+
/**
|
|
140
|
+
* Optional key to identify the toolbar item in analytics events
|
|
141
|
+
*/
|
|
142
|
+
key?: string;
|
|
139
143
|
icon: ComponentType<PropsWithChildren<{
|
|
140
144
|
label: string;
|
|
141
145
|
}>>;
|
|
@@ -148,6 +152,10 @@ export type ExtensionToolbarItemConfiguration = {
|
|
|
148
152
|
* Common fields applicable to all extension menu items
|
|
149
153
|
*/
|
|
150
154
|
type ExtensionMenuItemBaseConfiguration = {
|
|
155
|
+
/**
|
|
156
|
+
* Optional key to identify the menu item in analytics events
|
|
157
|
+
*/
|
|
158
|
+
key?: string;
|
|
151
159
|
icon: ComponentType<PropsWithChildren<{
|
|
152
160
|
label: string;
|
|
153
161
|
size?: 'small' | 'medium';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import type { SelectionExtensionPlugin } from '../selectionExtensionPluginType';
|
|
4
|
+
export type SelectionExtensionComponentContextValue = {
|
|
5
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin>;
|
|
6
|
+
editorView: EditorView;
|
|
7
|
+
extensionKey: string;
|
|
8
|
+
extensionSource: string;
|
|
9
|
+
extensionLocation: 'inline-toolbar' | 'primary-toolbar' | 'block-menu';
|
|
10
|
+
};
|
|
11
|
+
export declare const SelectionExtensionComponentContextProvider: import("react").Provider<SelectionExtensionComponentContextValue | undefined>;
|
|
12
|
+
export declare const useSelectionExtensionComponentContext: () => SelectionExtensionComponentContextValue;
|
|
@@ -3,5 +3,5 @@ import type { ExtensionMenuItemConfiguration } from '../../types';
|
|
|
3
3
|
type SelectionExtensionMenuItemsProps = {
|
|
4
4
|
getMenuItems: () => ExtensionMenuItemConfiguration[];
|
|
5
5
|
};
|
|
6
|
-
export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
|
|
6
|
+
export declare const SelectionExtensionMenuItems: ({ getMenuItems, }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
|
|
7
7
|
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
3
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
3
4
|
import type { ExtensionConfiguration } from '../../types';
|
|
4
|
-
|
|
5
|
+
type RegisterBlockMenuItemsOptions = {
|
|
6
|
+
extensionList: ExtensionConfiguration[];
|
|
7
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
8
|
+
editorViewRef?: {
|
|
9
|
+
current?: EditorView;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function registerBlockMenuItems({ extensionList, api, editorViewRef, }: RegisterBlockMenuItemsOptions): void;
|
|
13
|
+
export {};
|
|
@@ -14,7 +14,7 @@ type SelectionInfo = {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* @private
|
|
17
|
-
* @deprecated use
|
|
17
|
+
* @deprecated use getSelectionTextInfoNew instead
|
|
18
18
|
*/
|
|
19
19
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
20
20
|
export declare const getSelectionTextInfoNew: (selection: Selection, view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
@@ -136,6 +136,10 @@ export type BlockMenuExtensionConfiguration = {
|
|
|
136
136
|
getMenuItems: GetMenuItemsFn;
|
|
137
137
|
};
|
|
138
138
|
export type ExtensionToolbarItemConfiguration = {
|
|
139
|
+
/**
|
|
140
|
+
* Optional key to identify the toolbar item in analytics events
|
|
141
|
+
*/
|
|
142
|
+
key?: string;
|
|
139
143
|
icon: ComponentType<PropsWithChildren<{
|
|
140
144
|
label: string;
|
|
141
145
|
}>>;
|
|
@@ -148,6 +152,10 @@ export type ExtensionToolbarItemConfiguration = {
|
|
|
148
152
|
* Common fields applicable to all extension menu items
|
|
149
153
|
*/
|
|
150
154
|
type ExtensionMenuItemBaseConfiguration = {
|
|
155
|
+
/**
|
|
156
|
+
* Optional key to identify the menu item in analytics events
|
|
157
|
+
*/
|
|
158
|
+
key?: string;
|
|
151
159
|
icon: ComponentType<PropsWithChildren<{
|
|
152
160
|
label: string;
|
|
153
161
|
size?: 'small' | 'medium';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import type { SelectionExtensionPlugin } from '../selectionExtensionPluginType';
|
|
4
|
+
export type SelectionExtensionComponentContextValue = {
|
|
5
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin>;
|
|
6
|
+
editorView: EditorView;
|
|
7
|
+
extensionKey: string;
|
|
8
|
+
extensionSource: string;
|
|
9
|
+
extensionLocation: 'inline-toolbar' | 'primary-toolbar' | 'block-menu';
|
|
10
|
+
};
|
|
11
|
+
export declare const SelectionExtensionComponentContextProvider: import("react").Provider<SelectionExtensionComponentContextValue | undefined>;
|
|
12
|
+
export declare const useSelectionExtensionComponentContext: () => SelectionExtensionComponentContextValue;
|
|
@@ -3,5 +3,5 @@ import type { ExtensionMenuItemConfiguration } from '../../types';
|
|
|
3
3
|
type SelectionExtensionMenuItemsProps = {
|
|
4
4
|
getMenuItems: () => ExtensionMenuItemConfiguration[];
|
|
5
5
|
};
|
|
6
|
-
export declare const SelectionExtensionMenuItems: ({ getMenuItems }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
|
|
6
|
+
export declare const SelectionExtensionMenuItems: ({ getMenuItems, }: SelectionExtensionMenuItemsProps) => React.JSX.Element | null;
|
|
7
7
|
export {};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
3
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
3
4
|
import type { ExtensionConfiguration } from '../../types';
|
|
4
|
-
|
|
5
|
+
type RegisterBlockMenuItemsOptions = {
|
|
6
|
+
extensionList: ExtensionConfiguration[];
|
|
7
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
8
|
+
editorViewRef?: {
|
|
9
|
+
current?: EditorView;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function registerBlockMenuItems({ extensionList, api, editorViewRef, }: RegisterBlockMenuItemsOptions): void;
|
|
13
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.8",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,31 +35,31 @@
|
|
|
35
35
|
"@atlaskit/adf-utils": "^19.26.0",
|
|
36
36
|
"@atlaskit/editor-json-transformer": "^8.31.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^6.2.0",
|
|
38
|
-
"@atlaskit/editor-plugin-block-controls": "^7.
|
|
38
|
+
"@atlaskit/editor-plugin-block-controls": "^7.17.0",
|
|
39
39
|
"@atlaskit/editor-plugin-block-menu": "^5.2.0",
|
|
40
40
|
"@atlaskit/editor-plugin-editor-viewmode": "^8.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode-effects": "^6.1.0",
|
|
42
42
|
"@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
|
|
43
|
-
"@atlaskit/editor-plugin-selection-toolbar": "^7.
|
|
44
|
-
"@atlaskit/editor-plugin-toolbar": "^3.
|
|
43
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^7.2.0",
|
|
44
|
+
"@atlaskit/editor-plugin-toolbar": "^3.5.0",
|
|
45
45
|
"@atlaskit/editor-plugin-user-preferences": "^4.0.0",
|
|
46
46
|
"@atlaskit/editor-prosemirror": "^7.2.0",
|
|
47
47
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
48
48
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
49
49
|
"@atlaskit/editor-toolbar": "^0.18.0",
|
|
50
50
|
"@atlaskit/icon": "^29.3.0",
|
|
51
|
-
"@atlaskit/lozenge": "^13.
|
|
51
|
+
"@atlaskit/lozenge": "^13.3.0",
|
|
52
52
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
53
53
|
"@atlaskit/platform-feature-flags-react": "^0.4.0",
|
|
54
54
|
"@atlaskit/primitives": "^17.0.0",
|
|
55
|
-
"@atlaskit/tmp-editor-statsig": "^16.
|
|
55
|
+
"@atlaskit/tmp-editor-statsig": "^16.2.0",
|
|
56
56
|
"@babel/runtime": "^7.0.0",
|
|
57
57
|
"lodash": "^4.17.21",
|
|
58
58
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
59
59
|
"uuid": "^3.1.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@atlaskit/editor-common": "^110.
|
|
62
|
+
"@atlaskit/editor-common": "^110.48.0",
|
|
63
63
|
"react": "^18.2.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|