@atlaskit/editor-plugin-selection-extension 3.4.6 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/pm-plugins/utils/index.js +2 -8
- package/dist/cjs/selectionExtensionPlugin.js +5 -30
- package/dist/cjs/ui/LegacyToolbarComponent.js +24 -18
- package/dist/cjs/ui/extensions.js +12 -9
- package/dist/cjs/ui/getBoundingBoxFromSelection.js +1 -1
- package/dist/es2019/pm-plugins/utils/index.js +1 -7
- package/dist/es2019/selectionExtensionPlugin.js +0 -27
- package/dist/es2019/ui/LegacyToolbarComponent.js +23 -19
- package/dist/es2019/ui/extensions.js +10 -7
- package/dist/es2019/ui/getBoundingBoxFromSelection.js +1 -1
- package/dist/esm/pm-plugins/utils/index.js +1 -7
- package/dist/esm/selectionExtensionPlugin.js +5 -30
- package/dist/esm/ui/LegacyToolbarComponent.js +24 -18
- package/dist/esm/ui/extensions.js +12 -9
- package/dist/esm/ui/getBoundingBoxFromSelection.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/utils/index.d.ts +0 -1
- package/dist/types/selectionExtensionPluginType.d.ts +1 -6
- package/dist/types/types/index.d.ts +16 -6
- package/dist/types/ui/getBoundingBoxFromSelection.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +0 -1
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +1 -6
- package/dist/types-ts4.5/types/index.d.ts +16 -6
- package/dist/types-ts4.5/ui/getBoundingBoxFromSelection.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/pm-plugins/actions.js +0 -90
- package/dist/es2019/pm-plugins/actions.js +0 -90
- package/dist/esm/pm-plugins/actions.js +0 -84
- package/dist/types/pm-plugins/actions.d.ts +0 -8
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`364b31a9e1f44`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/364b31a9e1f44) -
|
|
8
|
+
Extend the extension configuration type to support grouping
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 3.5.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`abd3e6fd40ac6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/abd3e6fd40ac6) -
|
|
16
|
+
Remove unused getSelectionText and inserSmartLinks api
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 3.4.6
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.getFragmentInfoFromSelection = void 0;
|
|
8
8
|
exports.getSelectionAdfInfo = getSelectionAdfInfo;
|
|
9
|
-
exports.
|
|
9
|
+
exports.getSelectionTextInfo = void 0;
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
12
11
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
13
12
|
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
14
13
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
@@ -132,9 +131,4 @@ function getSelectionAdfInfo(state) {
|
|
|
132
131
|
return _objectSpread(_objectSpread({}, selectionInfo), {}, {
|
|
133
132
|
selectedNodeAdf: selectedNodeAdf
|
|
134
133
|
});
|
|
135
|
-
}
|
|
136
|
-
var validateSelectedNode = exports.validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
|
|
137
|
-
var serializer = new _editorJsonTransformer.JSONTransformer();
|
|
138
|
-
var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
139
|
-
return (0, _isEqual.default)(selectedNodeAdf, selectedNodeAdfFromState);
|
|
140
|
-
};
|
|
134
|
+
}
|
|
@@ -10,7 +10,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
12
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
|
-
var _actions = require("./pm-plugins/actions");
|
|
14
13
|
var _insertAdfAtEndOfDoc2 = require("./pm-plugins/actions/insertAdfAtEndOfDoc");
|
|
15
14
|
var _replaceWithAdf2 = require("./pm-plugins/actions/replaceWithAdf");
|
|
16
15
|
var _main = require("./pm-plugins/main");
|
|
@@ -80,27 +79,15 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
80
79
|
}
|
|
81
80
|
},
|
|
82
81
|
actions: {
|
|
83
|
-
|
|
82
|
+
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
84
83
|
if (!editorViewRef.current) {
|
|
85
84
|
return {
|
|
86
|
-
status: '
|
|
87
|
-
message: 'Editor view is not available'
|
|
85
|
+
status: 'failed-to-replace'
|
|
88
86
|
};
|
|
89
87
|
}
|
|
90
88
|
var _editorViewRef$curren = editorViewRef.current,
|
|
91
89
|
state = _editorViewRef$curren.state,
|
|
92
90
|
dispatch = _editorViewRef$curren.dispatch;
|
|
93
|
-
return (0, _actions.insertSmartLinks)(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
94
|
-
},
|
|
95
|
-
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
96
|
-
if (!editorViewRef.current) {
|
|
97
|
-
return {
|
|
98
|
-
status: 'failed-to-replace'
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
var _editorViewRef$curren2 = editorViewRef.current,
|
|
102
|
-
state = _editorViewRef$curren2.state,
|
|
103
|
-
dispatch = _editorViewRef$curren2.dispatch;
|
|
104
91
|
return (0, _replaceWithAdf2.replaceWithAdf)(nodeAdf)(state, dispatch);
|
|
105
92
|
},
|
|
106
93
|
insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
|
|
@@ -109,9 +96,9 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
109
96
|
status: 'failed'
|
|
110
97
|
};
|
|
111
98
|
}
|
|
112
|
-
var _editorViewRef$
|
|
113
|
-
state = _editorViewRef$
|
|
114
|
-
dispatch = _editorViewRef$
|
|
99
|
+
var _editorViewRef$curren2 = editorViewRef.current,
|
|
100
|
+
state = _editorViewRef$curren2.state,
|
|
101
|
+
dispatch = _editorViewRef$curren2.dispatch;
|
|
115
102
|
return (0, _insertAdfAtEndOfDoc2.insertAdfAtEndOfDoc)(nodeAdf)(state, dispatch);
|
|
116
103
|
},
|
|
117
104
|
getSelectionAdf: function getSelectionAdf() {
|
|
@@ -137,18 +124,6 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
137
124
|
return {
|
|
138
125
|
selectedNodeAdf: selectedNodeAdf
|
|
139
126
|
};
|
|
140
|
-
},
|
|
141
|
-
getSelectionText: function getSelectionText() {
|
|
142
|
-
if (!editorViewRef.current) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
var _getSelectionTextInfo = (0, _utils.getSelectionTextInfo)(editorViewRef.current, api),
|
|
146
|
-
text = _getSelectionTextInfo.text,
|
|
147
|
-
coords = _getSelectionTextInfo.coords;
|
|
148
|
-
return {
|
|
149
|
-
text: text,
|
|
150
|
-
coords: coords
|
|
151
|
-
};
|
|
152
127
|
}
|
|
153
128
|
},
|
|
154
129
|
contentComponent: function contentComponent(_ref6) {
|
|
@@ -73,24 +73,30 @@ var LegacyExtensionToolbarItem = exports.LegacyExtensionToolbarItem = function L
|
|
|
73
73
|
setIsOpen(!!(attrs !== null && attrs !== void 0 && attrs.isOpen));
|
|
74
74
|
};
|
|
75
75
|
var items = isOpen ? getMenuItems().map(function (menuItem, i) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
77
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
78
|
+
return {
|
|
79
|
+
key: "menu-item-".concat(i),
|
|
80
|
+
content: menuItem.label,
|
|
81
|
+
elemBefore: /*#__PURE__*/_react.default.createElement(menuItem.icon, {
|
|
82
|
+
label: menuItem.label
|
|
83
|
+
}),
|
|
84
|
+
onClick: function onClick() {
|
|
85
|
+
var _menuItem$onClick;
|
|
86
|
+
(_menuItem$onClick = menuItem.onClick) === null || _menuItem$onClick === void 0 || _menuItem$onClick.call(menuItem);
|
|
87
|
+
// NEXT PR: here we need to set the active extension so the contentComponent can render
|
|
88
|
+
// menuItem.contentComponent
|
|
89
|
+
},
|
|
90
|
+
isDisabled: menuItem.isDisabled,
|
|
91
|
+
'aria-label': menuItem.label,
|
|
92
|
+
value: {
|
|
93
|
+
name: menuItem.label
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}).filter(function (item) {
|
|
99
|
+
return item !== undefined;
|
|
94
100
|
}) : [];
|
|
95
101
|
return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownMenuWithKeyboardNavigation, {
|
|
96
102
|
arrowKeyNavigationProviderOptions: {
|
|
@@ -44,15 +44,18 @@ var getMenuItemExtensions = exports.getMenuItemExtensions = function getMenuItem
|
|
|
44
44
|
if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) {
|
|
45
45
|
var menuItems = inlineToolbar.getMenuItems();
|
|
46
46
|
menuItems.forEach(function (menuItem) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
48
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
49
|
+
acc.push({
|
|
50
|
+
name: menuItem.label,
|
|
51
|
+
icon: menuItem.icon,
|
|
52
|
+
onClick: menuItem.onClick,
|
|
53
|
+
isDisabled: function isDisabled() {
|
|
54
|
+
return !!menuItem.isDisabled;
|
|
55
|
+
},
|
|
56
|
+
component: menuItem.contentComponent
|
|
57
|
+
});
|
|
58
|
+
}
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
61
|
return acc;
|
|
@@ -10,7 +10,7 @@ exports.getBoundingBoxFromSelection = void 0;
|
|
|
10
10
|
* @param view - The editor view instance.
|
|
11
11
|
* @param from - The starting position of the selection.
|
|
12
12
|
* @param to - The ending position of the selection.
|
|
13
|
-
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box
|
|
13
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.
|
|
14
14
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
15
15
|
*/
|
|
16
16
|
var getBoundingBoxFromSelection = exports.getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isEqual from 'lodash/isEqual';
|
|
2
1
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
2
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
4
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -135,9 +134,4 @@ export function getSelectionAdfInfo(state) {
|
|
|
135
134
|
...selectionInfo,
|
|
136
135
|
selectedNodeAdf
|
|
137
136
|
};
|
|
138
|
-
}
|
|
139
|
-
export const validateSelectedNode = (selectedNodeAdf, selectedNode) => {
|
|
140
|
-
const serializer = new JSONTransformer();
|
|
141
|
-
const selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
142
|
-
return isEqual(selectedNodeAdf, selectedNodeAdfFromState);
|
|
143
|
-
};
|
|
137
|
+
}
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
-
import { insertSmartLinks } from './pm-plugins/actions';
|
|
6
5
|
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
7
6
|
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
8
7
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
@@ -67,19 +66,6 @@ export const selectionExtensionPlugin = ({
|
|
|
67
66
|
}
|
|
68
67
|
},
|
|
69
68
|
actions: {
|
|
70
|
-
insertSmartLinks: (linkInsertionOptions, selectedNodeAdf) => {
|
|
71
|
-
if (!editorViewRef.current) {
|
|
72
|
-
return {
|
|
73
|
-
status: 'error',
|
|
74
|
-
message: 'Editor view is not available'
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const {
|
|
78
|
-
state,
|
|
79
|
-
dispatch
|
|
80
|
-
} = editorViewRef.current;
|
|
81
|
-
return insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
82
|
-
},
|
|
83
69
|
replaceWithAdf: nodeAdf => {
|
|
84
70
|
if (!editorViewRef.current) {
|
|
85
71
|
return {
|
|
@@ -133,19 +119,6 @@ export const selectionExtensionPlugin = ({
|
|
|
133
119
|
return {
|
|
134
120
|
selectedNodeAdf
|
|
135
121
|
};
|
|
136
|
-
},
|
|
137
|
-
getSelectionText: () => {
|
|
138
|
-
if (!editorViewRef.current) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const {
|
|
142
|
-
text,
|
|
143
|
-
coords
|
|
144
|
-
} = getSelectionTextInfo(editorViewRef.current, api);
|
|
145
|
-
return {
|
|
146
|
-
text,
|
|
147
|
-
coords
|
|
148
|
-
};
|
|
149
122
|
}
|
|
150
123
|
},
|
|
151
124
|
contentComponent: ({
|
|
@@ -62,25 +62,29 @@ export const LegacyExtensionToolbarItem = ({
|
|
|
62
62
|
setIsOpen(!!(attrs !== null && attrs !== void 0 && attrs.isOpen));
|
|
63
63
|
};
|
|
64
64
|
const items = isOpen ? getMenuItems().map((menuItem, i) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
66
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
67
|
+
return {
|
|
68
|
+
key: `menu-item-${i}`,
|
|
69
|
+
content: menuItem.label,
|
|
70
|
+
elemBefore: /*#__PURE__*/React.createElement(menuItem.icon, {
|
|
71
|
+
label: menuItem.label
|
|
72
|
+
}),
|
|
73
|
+
onClick: () => {
|
|
74
|
+
var _menuItem$onClick;
|
|
75
|
+
(_menuItem$onClick = menuItem.onClick) === null || _menuItem$onClick === void 0 ? void 0 : _menuItem$onClick.call(menuItem);
|
|
76
|
+
// NEXT PR: here we need to set the active extension so the contentComponent can render
|
|
77
|
+
// menuItem.contentComponent
|
|
78
|
+
},
|
|
79
|
+
isDisabled: menuItem.isDisabled,
|
|
80
|
+
'aria-label': menuItem.label,
|
|
81
|
+
value: {
|
|
82
|
+
name: menuItem.label
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}).filter(item => item !== undefined) : [];
|
|
84
88
|
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
85
89
|
arrowKeyNavigationProviderOptions: {
|
|
86
90
|
type: ArrowKeyNavigationType.MENU
|
|
@@ -40,13 +40,16 @@ export const getMenuItemExtensions = (extensionList, targetSource) => {
|
|
|
40
40
|
if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) {
|
|
41
41
|
const menuItems = inlineToolbar.getMenuItems();
|
|
42
42
|
menuItems.forEach(menuItem => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
44
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
45
|
+
acc.push({
|
|
46
|
+
name: menuItem.label,
|
|
47
|
+
icon: menuItem.icon,
|
|
48
|
+
onClick: menuItem.onClick,
|
|
49
|
+
isDisabled: () => !!menuItem.isDisabled,
|
|
50
|
+
component: menuItem.contentComponent
|
|
51
|
+
});
|
|
52
|
+
}
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
return acc;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param view - The editor view instance.
|
|
5
5
|
* @param from - The starting position of the selection.
|
|
6
6
|
* @param to - The ending position of the selection.
|
|
7
|
-
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box
|
|
7
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.
|
|
8
8
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
9
9
|
*/
|
|
10
10
|
export const getBoundingBoxFromSelection = (view, from, to, offset = {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
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
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 isEqual from 'lodash/isEqual';
|
|
5
4
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
6
5
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
7
6
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -123,9 +122,4 @@ export function getSelectionAdfInfo(state) {
|
|
|
123
122
|
return _objectSpread(_objectSpread({}, selectionInfo), {}, {
|
|
124
123
|
selectedNodeAdf: selectedNodeAdf
|
|
125
124
|
});
|
|
126
|
-
}
|
|
127
|
-
export var validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
|
|
128
|
-
var serializer = new JSONTransformer();
|
|
129
|
-
var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
130
|
-
return isEqual(selectedNodeAdf, selectedNodeAdfFromState);
|
|
131
|
-
};
|
|
125
|
+
}
|
|
@@ -3,7 +3,6 @@ import React from 'react';
|
|
|
3
3
|
import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
|
|
7
6
|
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
8
7
|
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
9
8
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
@@ -73,27 +72,15 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
73
72
|
}
|
|
74
73
|
},
|
|
75
74
|
actions: {
|
|
76
|
-
|
|
75
|
+
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
77
76
|
if (!editorViewRef.current) {
|
|
78
77
|
return {
|
|
79
|
-
status: '
|
|
80
|
-
message: 'Editor view is not available'
|
|
78
|
+
status: 'failed-to-replace'
|
|
81
79
|
};
|
|
82
80
|
}
|
|
83
81
|
var _editorViewRef$curren = editorViewRef.current,
|
|
84
82
|
state = _editorViewRef$curren.state,
|
|
85
83
|
dispatch = _editorViewRef$curren.dispatch;
|
|
86
|
-
return _insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
87
|
-
},
|
|
88
|
-
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
89
|
-
if (!editorViewRef.current) {
|
|
90
|
-
return {
|
|
91
|
-
status: 'failed-to-replace'
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
var _editorViewRef$curren2 = editorViewRef.current,
|
|
95
|
-
state = _editorViewRef$curren2.state,
|
|
96
|
-
dispatch = _editorViewRef$curren2.dispatch;
|
|
97
84
|
return _replaceWithAdf(nodeAdf)(state, dispatch);
|
|
98
85
|
},
|
|
99
86
|
insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
|
|
@@ -102,9 +89,9 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
102
89
|
status: 'failed'
|
|
103
90
|
};
|
|
104
91
|
}
|
|
105
|
-
var _editorViewRef$
|
|
106
|
-
state = _editorViewRef$
|
|
107
|
-
dispatch = _editorViewRef$
|
|
92
|
+
var _editorViewRef$curren2 = editorViewRef.current,
|
|
93
|
+
state = _editorViewRef$curren2.state,
|
|
94
|
+
dispatch = _editorViewRef$curren2.dispatch;
|
|
108
95
|
return _insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
|
|
109
96
|
},
|
|
110
97
|
getSelectionAdf: function getSelectionAdf() {
|
|
@@ -130,18 +117,6 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
130
117
|
return {
|
|
131
118
|
selectedNodeAdf: selectedNodeAdf
|
|
132
119
|
};
|
|
133
|
-
},
|
|
134
|
-
getSelectionText: function getSelectionText() {
|
|
135
|
-
if (!editorViewRef.current) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
var _getSelectionTextInfo = getSelectionTextInfo(editorViewRef.current, api),
|
|
139
|
-
text = _getSelectionTextInfo.text,
|
|
140
|
-
coords = _getSelectionTextInfo.coords;
|
|
141
|
-
return {
|
|
142
|
-
text: text,
|
|
143
|
-
coords: coords
|
|
144
|
-
};
|
|
145
120
|
}
|
|
146
121
|
},
|
|
147
122
|
contentComponent: function contentComponent(_ref6) {
|
|
@@ -64,24 +64,30 @@ export var LegacyExtensionToolbarItem = function LegacyExtensionToolbarItem(_ref
|
|
|
64
64
|
setIsOpen(!!(attrs !== null && attrs !== void 0 && attrs.isOpen));
|
|
65
65
|
};
|
|
66
66
|
var items = isOpen ? getMenuItems().map(function (menuItem, i) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
68
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
69
|
+
return {
|
|
70
|
+
key: "menu-item-".concat(i),
|
|
71
|
+
content: menuItem.label,
|
|
72
|
+
elemBefore: /*#__PURE__*/React.createElement(menuItem.icon, {
|
|
73
|
+
label: menuItem.label
|
|
74
|
+
}),
|
|
75
|
+
onClick: function onClick() {
|
|
76
|
+
var _menuItem$onClick;
|
|
77
|
+
(_menuItem$onClick = menuItem.onClick) === null || _menuItem$onClick === void 0 || _menuItem$onClick.call(menuItem);
|
|
78
|
+
// NEXT PR: here we need to set the active extension so the contentComponent can render
|
|
79
|
+
// menuItem.contentComponent
|
|
80
|
+
},
|
|
81
|
+
isDisabled: menuItem.isDisabled,
|
|
82
|
+
'aria-label': menuItem.label,
|
|
83
|
+
value: {
|
|
84
|
+
name: menuItem.label
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}).filter(function (item) {
|
|
90
|
+
return item !== undefined;
|
|
85
91
|
}) : [];
|
|
86
92
|
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
87
93
|
arrowKeyNavigationProviderOptions: {
|
|
@@ -38,15 +38,18 @@ export var getMenuItemExtensions = function getMenuItemExtensions(extensionList,
|
|
|
38
38
|
if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) {
|
|
39
39
|
var menuItems = inlineToolbar.getMenuItems();
|
|
40
40
|
menuItems.forEach(function (menuItem) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
// Only process ExtensionMenuItemConfiguration, skip ExtensionMenuSectionConfiguration
|
|
42
|
+
if ('label' in menuItem && 'icon' in menuItem) {
|
|
43
|
+
acc.push({
|
|
44
|
+
name: menuItem.label,
|
|
45
|
+
icon: menuItem.icon,
|
|
46
|
+
onClick: menuItem.onClick,
|
|
47
|
+
isDisabled: function isDisabled() {
|
|
48
|
+
return !!menuItem.isDisabled;
|
|
49
|
+
},
|
|
50
|
+
component: menuItem.contentComponent
|
|
51
|
+
});
|
|
52
|
+
}
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
return acc;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param view - The editor view instance.
|
|
5
5
|
* @param from - The starting position of the selection.
|
|
6
6
|
* @param to - The ending position of the selection.
|
|
7
|
-
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box
|
|
7
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.
|
|
8
8
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
9
9
|
*/
|
|
10
10
|
export var getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult,
|
|
3
|
+
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, } from './types';
|
|
@@ -17,5 +17,4 @@ export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
|
17
17
|
selectedNodeAdf: ADFEntity;
|
|
18
18
|
};
|
|
19
19
|
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
20
|
-
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
21
20
|
export {};
|
|
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
-
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult,
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
9
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
10
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
11
11
|
dependencies: [
|
|
@@ -24,16 +24,11 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
24
24
|
clearActiveExtension: () => EditorCommand;
|
|
25
25
|
};
|
|
26
26
|
actions: {
|
|
27
|
-
insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
|
|
28
|
-
status: 'success' | 'error';
|
|
29
|
-
message?: string;
|
|
30
|
-
};
|
|
31
27
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
28
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
29
|
getSelectionAdf: () => SelectionAdfResult;
|
|
34
30
|
getDocumentFromSelection: () => {
|
|
35
31
|
selectedNodeAdf?: ADFEntity;
|
|
36
32
|
} | null;
|
|
37
|
-
getSelectionText: () => SelectionTextResult;
|
|
38
33
|
};
|
|
39
34
|
}>;
|
|
@@ -125,10 +125,6 @@ export type SelectionAdfResult = {
|
|
|
125
125
|
selectedNodeAdf?: ADFEntity;
|
|
126
126
|
selectionRanges?: SelectionRange[];
|
|
127
127
|
} | null;
|
|
128
|
-
export type SelectionTextResult = {
|
|
129
|
-
text: string;
|
|
130
|
-
coords: SelectionExtensionCoords;
|
|
131
|
-
} | null;
|
|
132
128
|
export type ExtensionSource = 'first-party' | 'external';
|
|
133
129
|
export type ExtensionConfiguration = {
|
|
134
130
|
key: string;
|
|
@@ -138,13 +134,15 @@ export type ExtensionConfiguration = {
|
|
|
138
134
|
blockMenu?: BlockMenuExtensionConfiguration;
|
|
139
135
|
};
|
|
140
136
|
export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
|
|
141
|
-
export type GetMenuItemsFn = () => ExtensionMenuItemConfiguration
|
|
137
|
+
export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
|
|
138
|
+
export type GetMenuItemFn = () => Omit<ExtensionMenuItemConfiguration, 'section'>;
|
|
142
139
|
export type ToolbarExtensionConfiguration = {
|
|
143
140
|
getToolbarItem?: GetToolbarItemFn;
|
|
144
141
|
getMenuItems?: GetMenuItemsFn;
|
|
145
142
|
};
|
|
146
143
|
export type BlockMenuExtensionConfiguration = {
|
|
147
|
-
|
|
144
|
+
getMenuItem: GetMenuItemFn;
|
|
145
|
+
getNestedMenuItems?: GetMenuItemsFn;
|
|
148
146
|
};
|
|
149
147
|
export type ExtensionToolbarItemConfiguration = {
|
|
150
148
|
icon: React.ComponentType<React.PropsWithChildren<{
|
|
@@ -163,5 +161,17 @@ export type ExtensionMenuItemConfiguration = {
|
|
|
163
161
|
onClick?: () => void;
|
|
164
162
|
isDisabled?: boolean;
|
|
165
163
|
contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
|
|
164
|
+
/**
|
|
165
|
+
* Optional menu-section to declare grouping - only used for menu items
|
|
166
|
+
*/
|
|
167
|
+
section?: {
|
|
168
|
+
key: string;
|
|
169
|
+
rank: number;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
export type ExtensionMenuSectionConfiguration = {
|
|
173
|
+
key: string;
|
|
174
|
+
rank: number;
|
|
175
|
+
title?: string;
|
|
166
176
|
};
|
|
167
177
|
export {};
|
|
@@ -6,7 +6,7 @@ import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
|
|
|
6
6
|
* @param view - The editor view instance.
|
|
7
7
|
* @param from - The starting position of the selection.
|
|
8
8
|
* @param to - The ending position of the selection.
|
|
9
|
-
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box
|
|
9
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.
|
|
10
10
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
11
11
|
*/
|
|
12
12
|
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult,
|
|
3
|
+
export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, SelectionAdfResult, } from './types';
|
|
@@ -17,5 +17,4 @@ export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
|
17
17
|
selectedNodeAdf: ADFEntity;
|
|
18
18
|
};
|
|
19
19
|
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
20
|
-
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
21
20
|
export {};
|
|
@@ -5,7 +5,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
5
5
|
import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
|
|
6
6
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
7
7
|
import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
|
|
8
|
-
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult,
|
|
8
|
+
import type { DynamicSelectionExtension, SelectionAdfResult, InsertAdfAtEndOfDocResult, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
9
9
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
10
10
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
11
11
|
dependencies: [
|
|
@@ -24,16 +24,11 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
24
24
|
clearActiveExtension: () => EditorCommand;
|
|
25
25
|
};
|
|
26
26
|
actions: {
|
|
27
|
-
insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => {
|
|
28
|
-
status: 'success' | 'error';
|
|
29
|
-
message?: string;
|
|
30
|
-
};
|
|
31
27
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
28
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
29
|
getSelectionAdf: () => SelectionAdfResult;
|
|
34
30
|
getDocumentFromSelection: () => {
|
|
35
31
|
selectedNodeAdf?: ADFEntity;
|
|
36
32
|
} | null;
|
|
37
|
-
getSelectionText: () => SelectionTextResult;
|
|
38
33
|
};
|
|
39
34
|
}>;
|
|
@@ -125,10 +125,6 @@ export type SelectionAdfResult = {
|
|
|
125
125
|
selectedNodeAdf?: ADFEntity;
|
|
126
126
|
selectionRanges?: SelectionRange[];
|
|
127
127
|
} | null;
|
|
128
|
-
export type SelectionTextResult = {
|
|
129
|
-
text: string;
|
|
130
|
-
coords: SelectionExtensionCoords;
|
|
131
|
-
} | null;
|
|
132
128
|
export type ExtensionSource = 'first-party' | 'external';
|
|
133
129
|
export type ExtensionConfiguration = {
|
|
134
130
|
key: string;
|
|
@@ -138,13 +134,15 @@ export type ExtensionConfiguration = {
|
|
|
138
134
|
blockMenu?: BlockMenuExtensionConfiguration;
|
|
139
135
|
};
|
|
140
136
|
export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
|
|
141
|
-
export type GetMenuItemsFn = () => ExtensionMenuItemConfiguration
|
|
137
|
+
export type GetMenuItemsFn = () => Array<ExtensionMenuItemConfiguration | ExtensionMenuSectionConfiguration>;
|
|
138
|
+
export type GetMenuItemFn = () => Omit<ExtensionMenuItemConfiguration, 'section'>;
|
|
142
139
|
export type ToolbarExtensionConfiguration = {
|
|
143
140
|
getToolbarItem?: GetToolbarItemFn;
|
|
144
141
|
getMenuItems?: GetMenuItemsFn;
|
|
145
142
|
};
|
|
146
143
|
export type BlockMenuExtensionConfiguration = {
|
|
147
|
-
|
|
144
|
+
getMenuItem: GetMenuItemFn;
|
|
145
|
+
getNestedMenuItems?: GetMenuItemsFn;
|
|
148
146
|
};
|
|
149
147
|
export type ExtensionToolbarItemConfiguration = {
|
|
150
148
|
icon: React.ComponentType<React.PropsWithChildren<{
|
|
@@ -163,5 +161,17 @@ export type ExtensionMenuItemConfiguration = {
|
|
|
163
161
|
onClick?: () => void;
|
|
164
162
|
isDisabled?: boolean;
|
|
165
163
|
contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
|
|
164
|
+
/**
|
|
165
|
+
* Optional menu-section to declare grouping - only used for menu items
|
|
166
|
+
*/
|
|
167
|
+
section?: {
|
|
168
|
+
key: string;
|
|
169
|
+
rank: number;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
export type ExtensionMenuSectionConfiguration = {
|
|
173
|
+
key: string;
|
|
174
|
+
rank: number;
|
|
175
|
+
title?: string;
|
|
166
176
|
};
|
|
167
177
|
export {};
|
|
@@ -6,7 +6,7 @@ import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
|
|
|
6
6
|
* @param view - The editor view instance.
|
|
7
7
|
* @param from - The starting position of the selection.
|
|
8
8
|
* @param to - The ending position of the selection.
|
|
9
|
-
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box
|
|
9
|
+
* @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.
|
|
10
10
|
* @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
|
|
11
11
|
*/
|
|
12
12
|
export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@atlaskit/adf-utils": "^19.21.0",
|
|
39
|
-
"@atlaskit/editor-json-transformer": "^8.
|
|
39
|
+
"@atlaskit/editor-json-transformer": "^8.26.0",
|
|
40
40
|
"@atlaskit/editor-plugin-analytics": "^3.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
|
|
42
42
|
"@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"@atlaskit/icon": "^27.12.0",
|
|
49
49
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
50
50
|
"@atlaskit/primitives": "^14.11.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^11.
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^11.3.0",
|
|
52
52
|
"@babel/runtime": "^7.0.0",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
54
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
55
55
|
"uuid": "^3.1.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@atlaskit/editor-common": "^107.
|
|
58
|
+
"@atlaskit/editor-common": "^107.26.0",
|
|
59
59
|
"react": "^18.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.insertSmartLinks = void 0;
|
|
7
|
-
var _types = require("../types");
|
|
8
|
-
var _main = require("./main");
|
|
9
|
-
var _utils = require("./utils");
|
|
10
|
-
var _getOffsetByPath = require("./utils/getOffsetByPath");
|
|
11
|
-
var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
|
|
12
|
-
var newFromPos = tr.mapping.map(offset.from);
|
|
13
|
-
var newToPos = tr.mapping.map(offset.to || offset.from);
|
|
14
|
-
var smartLink = schema.nodes.inlineCard.createChecked({
|
|
15
|
-
url: link
|
|
16
|
-
});
|
|
17
|
-
return tr.replaceWith(newFromPos, newToPos, smartLink);
|
|
18
|
-
};
|
|
19
|
-
var insertSmartLinks = exports.insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
|
|
20
|
-
return function (state, dispatch) {
|
|
21
|
-
var _selectionExtensionPl;
|
|
22
|
-
var tr = state.tr,
|
|
23
|
-
schema = state.schema;
|
|
24
|
-
if (linkInsertionOption.length === 0) {
|
|
25
|
-
return {
|
|
26
|
-
status: 'error',
|
|
27
|
-
message: 'No link insertion options provided'
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// we need to track if any changes were made since user click the toolbar button
|
|
32
|
-
// if there is change, we insert the links at the bottom of the page instead
|
|
33
|
-
var docChangedAfterClick = ((_selectionExtensionPl = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
34
|
-
if (docChangedAfterClick) {
|
|
35
|
-
var docEnd = state.doc.content.size;
|
|
36
|
-
linkInsertionOption.forEach(function (option) {
|
|
37
|
-
var link = option.link;
|
|
38
|
-
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
39
|
-
url: link
|
|
40
|
-
}));
|
|
41
|
-
});
|
|
42
|
-
tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
43
|
-
type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
44
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
45
|
-
});
|
|
46
|
-
dispatch(tr);
|
|
47
|
-
return {
|
|
48
|
-
status: 'success',
|
|
49
|
-
message: 'Links inserted to page bottom successfully'
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
var newTr = tr;
|
|
53
|
-
try {
|
|
54
|
-
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
55
|
-
var selectedNode = (_selectionExtensionPl2 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
56
|
-
var nodePos = (_selectionExtensionPl3 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
57
|
-
if (!selectedNode || nodePos === undefined) {
|
|
58
|
-
throw new Error('No selected node or node position found');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Validate if the selectedNodeAdf matches the selected node we have in the state
|
|
62
|
-
if (!(0, _utils.validateSelectedNode)(selectedNodeAdf, selectedNode)) {
|
|
63
|
-
throw new Error('Selected node ADF does not match the previous stored node');
|
|
64
|
-
}
|
|
65
|
-
linkInsertionOption.forEach(function (option) {
|
|
66
|
-
var link = option.link,
|
|
67
|
-
insertPosition = option.insertPosition;
|
|
68
|
-
var pointer = insertPosition.pointer,
|
|
69
|
-
from = insertPosition.from,
|
|
70
|
-
to = insertPosition.to;
|
|
71
|
-
var offset = (0, _getOffsetByPath.getOffsetByPath)(selectedNode, nodePos, pointer, from, to);
|
|
72
|
-
newTr = insertLinkTr(tr, link, offset, schema);
|
|
73
|
-
});
|
|
74
|
-
} catch (error) {
|
|
75
|
-
return {
|
|
76
|
-
status: 'error',
|
|
77
|
-
message: error instanceof Error ? error.message : 'Unknown error'
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
newTr.setMeta(_main.selectionExtensionPluginKey, {
|
|
81
|
-
type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
82
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
83
|
-
});
|
|
84
|
-
dispatch(newTr);
|
|
85
|
-
return {
|
|
86
|
-
status: 'success',
|
|
87
|
-
message: 'Links inserted successfully'
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { SelectionExtensionActionTypes } from '../types';
|
|
2
|
-
import { selectionExtensionPluginKey } from './main';
|
|
3
|
-
import { validateSelectedNode } from './utils';
|
|
4
|
-
import { getOffsetByPath } from './utils/getOffsetByPath';
|
|
5
|
-
const insertLinkTr = (tr, link, offset, schema) => {
|
|
6
|
-
const newFromPos = tr.mapping.map(offset.from);
|
|
7
|
-
const newToPos = tr.mapping.map(offset.to || offset.from);
|
|
8
|
-
const smartLink = schema.nodes.inlineCard.createChecked({
|
|
9
|
-
url: link
|
|
10
|
-
});
|
|
11
|
-
return tr.replaceWith(newFromPos, newToPos, smartLink);
|
|
12
|
-
};
|
|
13
|
-
export const insertSmartLinks = (linkInsertionOption, selectedNodeAdf) => (state, dispatch) => {
|
|
14
|
-
var _selectionExtensionPl;
|
|
15
|
-
const {
|
|
16
|
-
tr,
|
|
17
|
-
schema
|
|
18
|
-
} = state;
|
|
19
|
-
if (linkInsertionOption.length === 0) {
|
|
20
|
-
return {
|
|
21
|
-
status: 'error',
|
|
22
|
-
message: 'No link insertion options provided'
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// we need to track if any changes were made since user click the toolbar button
|
|
27
|
-
// if there is change, we insert the links at the bottom of the page instead
|
|
28
|
-
const docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
29
|
-
if (docChangedAfterClick) {
|
|
30
|
-
const docEnd = state.doc.content.size;
|
|
31
|
-
linkInsertionOption.forEach(option => {
|
|
32
|
-
const {
|
|
33
|
-
link
|
|
34
|
-
} = option;
|
|
35
|
-
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
36
|
-
url: link
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
tr.setMeta(selectionExtensionPluginKey, {
|
|
40
|
-
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
41
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
42
|
-
});
|
|
43
|
-
dispatch(tr);
|
|
44
|
-
return {
|
|
45
|
-
status: 'success',
|
|
46
|
-
message: 'Links inserted to page bottom successfully'
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
let newTr = tr;
|
|
50
|
-
try {
|
|
51
|
-
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
52
|
-
const selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
53
|
-
const nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
54
|
-
if (!selectedNode || nodePos === undefined) {
|
|
55
|
-
throw new Error('No selected node or node position found');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Validate if the selectedNodeAdf matches the selected node we have in the state
|
|
59
|
-
if (!validateSelectedNode(selectedNodeAdf, selectedNode)) {
|
|
60
|
-
throw new Error('Selected node ADF does not match the previous stored node');
|
|
61
|
-
}
|
|
62
|
-
linkInsertionOption.forEach(option => {
|
|
63
|
-
const {
|
|
64
|
-
link,
|
|
65
|
-
insertPosition
|
|
66
|
-
} = option;
|
|
67
|
-
const {
|
|
68
|
-
pointer,
|
|
69
|
-
from,
|
|
70
|
-
to
|
|
71
|
-
} = insertPosition;
|
|
72
|
-
const offset = getOffsetByPath(selectedNode, nodePos, pointer, from, to);
|
|
73
|
-
newTr = insertLinkTr(tr, link, offset, schema);
|
|
74
|
-
});
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return {
|
|
77
|
-
status: 'error',
|
|
78
|
-
message: error instanceof Error ? error.message : 'Unknown error'
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
newTr.setMeta(selectionExtensionPluginKey, {
|
|
82
|
-
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
83
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
84
|
-
});
|
|
85
|
-
dispatch(newTr);
|
|
86
|
-
return {
|
|
87
|
-
status: 'success',
|
|
88
|
-
message: 'Links inserted successfully'
|
|
89
|
-
};
|
|
90
|
-
};
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { SelectionExtensionActionTypes } from '../types';
|
|
2
|
-
import { selectionExtensionPluginKey } from './main';
|
|
3
|
-
import { validateSelectedNode } from './utils';
|
|
4
|
-
import { getOffsetByPath } from './utils/getOffsetByPath';
|
|
5
|
-
var insertLinkTr = function insertLinkTr(tr, link, offset, schema) {
|
|
6
|
-
var newFromPos = tr.mapping.map(offset.from);
|
|
7
|
-
var newToPos = tr.mapping.map(offset.to || offset.from);
|
|
8
|
-
var smartLink = schema.nodes.inlineCard.createChecked({
|
|
9
|
-
url: link
|
|
10
|
-
});
|
|
11
|
-
return tr.replaceWith(newFromPos, newToPos, smartLink);
|
|
12
|
-
};
|
|
13
|
-
export var insertSmartLinks = function insertSmartLinks(linkInsertionOption, selectedNodeAdf) {
|
|
14
|
-
return function (state, dispatch) {
|
|
15
|
-
var _selectionExtensionPl;
|
|
16
|
-
var tr = state.tr,
|
|
17
|
-
schema = state.schema;
|
|
18
|
-
if (linkInsertionOption.length === 0) {
|
|
19
|
-
return {
|
|
20
|
-
status: 'error',
|
|
21
|
-
message: 'No link insertion options provided'
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// we need to track if any changes were made since user click the toolbar button
|
|
26
|
-
// if there is change, we insert the links at the bottom of the page instead
|
|
27
|
-
var docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
28
|
-
if (docChangedAfterClick) {
|
|
29
|
-
var docEnd = state.doc.content.size;
|
|
30
|
-
linkInsertionOption.forEach(function (option) {
|
|
31
|
-
var link = option.link;
|
|
32
|
-
tr.insert(tr.mapping.map(docEnd), schema.nodes.inlineCard.createChecked({
|
|
33
|
-
url: link
|
|
34
|
-
}));
|
|
35
|
-
});
|
|
36
|
-
tr.setMeta(selectionExtensionPluginKey, {
|
|
37
|
-
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
38
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
39
|
-
});
|
|
40
|
-
dispatch(tr);
|
|
41
|
-
return {
|
|
42
|
-
status: 'success',
|
|
43
|
-
message: 'Links inserted to page bottom successfully'
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
var newTr = tr;
|
|
47
|
-
try {
|
|
48
|
-
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
49
|
-
var selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
50
|
-
var nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
51
|
-
if (!selectedNode || nodePos === undefined) {
|
|
52
|
-
throw new Error('No selected node or node position found');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Validate if the selectedNodeAdf matches the selected node we have in the state
|
|
56
|
-
if (!validateSelectedNode(selectedNodeAdf, selectedNode)) {
|
|
57
|
-
throw new Error('Selected node ADF does not match the previous stored node');
|
|
58
|
-
}
|
|
59
|
-
linkInsertionOption.forEach(function (option) {
|
|
60
|
-
var link = option.link,
|
|
61
|
-
insertPosition = option.insertPosition;
|
|
62
|
-
var pointer = insertPosition.pointer,
|
|
63
|
-
from = insertPosition.from,
|
|
64
|
-
to = insertPosition.to;
|
|
65
|
-
var offset = getOffsetByPath(selectedNode, nodePos, pointer, from, to);
|
|
66
|
-
newTr = insertLinkTr(tr, link, offset, schema);
|
|
67
|
-
});
|
|
68
|
-
} catch (error) {
|
|
69
|
-
return {
|
|
70
|
-
status: 'error',
|
|
71
|
-
message: error instanceof Error ? error.message : 'Unknown error'
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
newTr.setMeta(selectionExtensionPluginKey, {
|
|
75
|
-
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
76
|
-
startTrackChanges: false // Reset the flag when starting to track changes
|
|
77
|
-
});
|
|
78
|
-
dispatch(newTr);
|
|
79
|
-
return {
|
|
80
|
-
status: 'success',
|
|
81
|
-
message: 'Links inserted successfully'
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
-
import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
3
|
-
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { type LinkInsertionOption } from '../types';
|
|
5
|
-
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status: "success" | "error";
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
-
import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
3
|
-
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { type LinkInsertionOption } from '../types';
|
|
5
|
-
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status: "success" | "error";
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|