@atlaskit/editor-plugin-selection-extension 3.3.1 → 3.4.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 +17 -0
- package/dist/cjs/pm-plugins/actions/insertAdfAtEndOfDoc.js +27 -0
- package/dist/cjs/pm-plugins/actions/replaceWithAdf.js +50 -0
- package/dist/cjs/selectionExtensionPlugin.js +90 -34
- package/dist/cjs/ui/LegacyToolbarComponent.js +120 -0
- package/dist/cjs/ui/extensions.js +60 -0
- package/dist/cjs/ui/selectionToolbar.js +32 -5
- package/dist/es2019/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
- package/dist/es2019/pm-plugins/actions/replaceWithAdf.js +44 -0
- package/dist/es2019/selectionExtensionPlugin.js +80 -26
- package/dist/es2019/ui/LegacyToolbarComponent.js +109 -0
- package/dist/es2019/ui/extensions.js +54 -0
- package/dist/es2019/ui/selectionToolbar.js +38 -14
- package/dist/esm/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
- package/dist/esm/pm-plugins/actions/replaceWithAdf.js +44 -0
- package/dist/esm/selectionExtensionPlugin.js +90 -34
- package/dist/esm/ui/LegacyToolbarComponent.js +111 -0
- package/dist/esm/ui/extensions.js +54 -0
- package/dist/esm/ui/selectionToolbar.js +31 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/actions/insertAdfAtEndOfDoc.d.ts +5 -0
- package/dist/types/pm-plugins/actions/replaceWithAdf.d.ts +5 -0
- package/dist/types/selectionExtensionPluginType.d.ts +5 -1
- package/dist/types/types/index.d.ts +44 -1
- package/dist/types/ui/LegacyToolbarComponent.d.ts +16 -0
- package/dist/types/ui/extensions.d.ts +27 -0
- package/dist/types/ui/selectionToolbar.d.ts +7 -17
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/actions/insertAdfAtEndOfDoc.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/actions/replaceWithAdf.d.ts +5 -0
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +5 -1
- package/dist/types-ts4.5/types/index.d.ts +44 -1
- package/dist/types-ts4.5/ui/LegacyToolbarComponent.d.ts +16 -0
- package/dist/types-ts4.5/ui/extensions.d.ts +27 -0
- package/dist/types-ts4.5/ui/selectionToolbar.d.ts +7 -17
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#192343](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/192343)
|
|
8
|
+
[`9cb0878241016`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9cb0878241016) -
|
|
9
|
+
ED-28736 more extensible selection extensions API
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 3.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#193092](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193092)
|
|
17
|
+
[`1e21bb09f7d00`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1e21bb09f7d00) -
|
|
18
|
+
new api to insert ADF at the bottom of document
|
|
19
|
+
|
|
3
20
|
## 3.3.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.insertAdfAtEndOfDoc = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var insertAdfAtEndOfDoc = exports.insertAdfAtEndOfDoc = function insertAdfAtEndOfDoc(nodeAdf) {
|
|
9
|
+
return function (state, dispatch) {
|
|
10
|
+
var tr = state.tr,
|
|
11
|
+
schema = state.schema;
|
|
12
|
+
try {
|
|
13
|
+
var docEnd = state.doc.content.size;
|
|
14
|
+
var modifiedNode = _model.Node.fromJSON(schema, nodeAdf);
|
|
15
|
+
modifiedNode.check();
|
|
16
|
+
tr.insert(tr.mapping.map(docEnd), modifiedNode).scrollIntoView();
|
|
17
|
+
dispatch(tr);
|
|
18
|
+
return {
|
|
19
|
+
status: 'success'
|
|
20
|
+
};
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
status: 'failed'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.replaceWithAdf = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _types = require("../../types");
|
|
9
|
+
var _main = require("../main");
|
|
10
|
+
var replaceWithAdf = exports.replaceWithAdf = function replaceWithAdf(nodeAdf) {
|
|
11
|
+
return function (state, dispatch) {
|
|
12
|
+
var _selectionExtensionPl;
|
|
13
|
+
var tr = state.tr,
|
|
14
|
+
schema = state.schema;
|
|
15
|
+
|
|
16
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
17
|
+
var docChangedAfterClick = ((_selectionExtensionPl = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
18
|
+
tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
19
|
+
type: _types.SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
20
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
21
|
+
});
|
|
22
|
+
if (docChangedAfterClick) {
|
|
23
|
+
dispatch(tr);
|
|
24
|
+
return {
|
|
25
|
+
status: 'document-changed'
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
30
|
+
var selectedNode = (_selectionExtensionPl2 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
31
|
+
var nodePos = (_selectionExtensionPl3 = _main.selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
32
|
+
if (!selectedNode || nodePos === undefined) {
|
|
33
|
+
throw new Error('No selected node or node position found');
|
|
34
|
+
}
|
|
35
|
+
var endPos = selectedNode.nodeSize + nodePos;
|
|
36
|
+
var modifiedNode = _model.Node.fromJSON(schema, nodeAdf);
|
|
37
|
+
modifiedNode.check();
|
|
38
|
+
tr.replaceWith(nodePos, endPos, modifiedNode).scrollIntoView();
|
|
39
|
+
dispatch(tr);
|
|
40
|
+
return {
|
|
41
|
+
status: 'success'
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
dispatch(tr);
|
|
45
|
+
return {
|
|
46
|
+
status: 'failed-to-replace'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -11,11 +11,15 @@ 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
13
|
var _actions = require("./pm-plugins/actions");
|
|
14
|
+
var _insertAdfAtEndOfDoc2 = require("./pm-plugins/actions/insertAdfAtEndOfDoc");
|
|
15
|
+
var _replaceWithAdf2 = require("./pm-plugins/actions/replaceWithAdf");
|
|
14
16
|
var _main = require("./pm-plugins/main");
|
|
15
17
|
var _utils = require("./pm-plugins/utils");
|
|
16
18
|
var _types = require("./types");
|
|
17
19
|
var _SelectionExtensionComponentWrapper = require("./ui/extension/SelectionExtensionComponentWrapper");
|
|
20
|
+
var _extensions = require("./ui/extensions");
|
|
18
21
|
var _getBoundingBoxFromSelection = require("./ui/getBoundingBoxFromSelection");
|
|
22
|
+
var _LegacyToolbarComponent = require("./ui/LegacyToolbarComponent");
|
|
19
23
|
var _selectionToolbar2 = require("./ui/selectionToolbar");
|
|
20
24
|
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
21
25
|
var api = _ref.api,
|
|
@@ -25,6 +29,30 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
25
29
|
};
|
|
26
30
|
var cachedSelection;
|
|
27
31
|
var cachedOverflowMenuOptions;
|
|
32
|
+
var _ref2 = config || {},
|
|
33
|
+
_ref2$extensionList = _ref2.extensionList,
|
|
34
|
+
extensionList = _ref2$extensionList === void 0 ? [] : _ref2$extensionList,
|
|
35
|
+
_ref2$extensions = _ref2.extensions,
|
|
36
|
+
extensions = _ref2$extensions === void 0 ? {} : _ref2$extensions;
|
|
37
|
+
var _ref3 = extensions || {},
|
|
38
|
+
_ref3$firstParty = _ref3.firstParty,
|
|
39
|
+
firstParty = _ref3$firstParty === void 0 ? [] : _ref3$firstParty,
|
|
40
|
+
_ref3$external = _ref3.external,
|
|
41
|
+
external = _ref3$external === void 0 ? [] : _ref3$external;
|
|
42
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2')) {
|
|
43
|
+
var primaryToolbarItemExtensions = (0, _extensions.getToolbarItemExtensions)(extensionList, 'primaryToolbar');
|
|
44
|
+
if (primaryToolbarItemExtensions !== null && primaryToolbarItemExtensions !== void 0 && primaryToolbarItemExtensions.length) {
|
|
45
|
+
var _api$primaryToolbar;
|
|
46
|
+
api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || (_api$primaryToolbar = _api$primaryToolbar.actions) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.registerComponent({
|
|
47
|
+
name: 'selectionExtension',
|
|
48
|
+
component: function component() {
|
|
49
|
+
return /*#__PURE__*/_react.default.createElement(_LegacyToolbarComponent.LegacyPrimaryToolbarComponent, {
|
|
50
|
+
primaryToolbarItemExtensions: primaryToolbarItemExtensions
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
28
56
|
return {
|
|
29
57
|
name: 'selectionExtension',
|
|
30
58
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -35,8 +63,8 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
35
63
|
},
|
|
36
64
|
commands: {
|
|
37
65
|
setActiveExtension: function setActiveExtension(extension) {
|
|
38
|
-
return function (
|
|
39
|
-
var tr =
|
|
66
|
+
return function (_ref4) {
|
|
67
|
+
var tr = _ref4.tr;
|
|
40
68
|
return tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
41
69
|
type: 'set-active-extension',
|
|
42
70
|
extension: extension
|
|
@@ -44,8 +72,8 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
44
72
|
};
|
|
45
73
|
},
|
|
46
74
|
clearActiveExtension: function clearActiveExtension() {
|
|
47
|
-
return function (
|
|
48
|
-
var tr =
|
|
75
|
+
return function (_ref5) {
|
|
76
|
+
var tr = _ref5.tr;
|
|
49
77
|
return tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
50
78
|
type: 'clear-active-extension'
|
|
51
79
|
});
|
|
@@ -64,11 +92,37 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
64
92
|
state = _editorViewRef$curren.state,
|
|
65
93
|
dispatch = _editorViewRef$curren.dispatch;
|
|
66
94
|
return (0, _actions.insertSmartLinks)(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
95
|
+
},
|
|
96
|
+
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
97
|
+
if (!editorViewRef.current) {
|
|
98
|
+
return {
|
|
99
|
+
status: 'failed-to-replace'
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var _editorViewRef$curren2 = editorViewRef.current,
|
|
103
|
+
state = _editorViewRef$curren2.state,
|
|
104
|
+
dispatch = _editorViewRef$curren2.dispatch;
|
|
105
|
+
return (0, _replaceWithAdf2.replaceWithAdf)(nodeAdf)(state, dispatch);
|
|
106
|
+
},
|
|
107
|
+
insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
|
|
108
|
+
if (!editorViewRef.current) {
|
|
109
|
+
return {
|
|
110
|
+
status: 'failed'
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var _editorViewRef$curren3 = editorViewRef.current,
|
|
114
|
+
state = _editorViewRef$curren3.state,
|
|
115
|
+
dispatch = _editorViewRef$curren3.dispatch;
|
|
116
|
+
return (0, _insertAdfAtEndOfDoc2.insertAdfAtEndOfDoc)(nodeAdf)(state, dispatch);
|
|
67
117
|
}
|
|
118
|
+
// NEXT PR: Implement this to return selectedNodeAdf, selectionRanges
|
|
119
|
+
// getSelectionAdf: () => {},
|
|
120
|
+
// NEXT PR: Implement this to return text, coords
|
|
121
|
+
// getSelectionText: () => {},
|
|
68
122
|
},
|
|
69
|
-
contentComponent: function contentComponent(
|
|
123
|
+
contentComponent: function contentComponent(_ref6) {
|
|
70
124
|
var _api$analytics;
|
|
71
|
-
var editorView =
|
|
125
|
+
var editorView = _ref6.editorView;
|
|
72
126
|
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionComponentWrapper.SelectionExtensionComponentWrapper, {
|
|
73
127
|
editorView: editorView,
|
|
74
128
|
api: api,
|
|
@@ -81,25 +135,17 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
81
135
|
if (!config) {
|
|
82
136
|
return;
|
|
83
137
|
}
|
|
84
|
-
var pageModes = config.pageModes
|
|
85
|
-
extensions = config.extensions;
|
|
138
|
+
var pageModes = config.pageModes;
|
|
86
139
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* Check whether plugin contains any selection extensions
|
|
91
|
-
*/
|
|
92
|
-
if ((!(extensions !== null && extensions !== void 0 && extensions.firstParty) || extensions.firstParty.length === 0) && (!(extensions !== null && extensions !== void 0 && extensions.external) || extensions.external.length === 0)) {
|
|
140
|
+
// Extensions Config Validation
|
|
141
|
+
// Check whether plugin contains any selection extensions
|
|
142
|
+
if (!(firstParty !== null && firstParty !== void 0 && firstParty.length) && !(external !== null && external !== void 0 && external.length) && !(extensionList !== null && extensionList !== void 0 && extensionList.length)) {
|
|
93
143
|
return;
|
|
94
144
|
}
|
|
95
145
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* Check if pageModes is provided and matches against current content mode
|
|
100
|
-
*
|
|
101
|
-
* TODO: This will eventially transition from mode to contentMode
|
|
102
|
-
*/
|
|
146
|
+
// Content Mode Validation
|
|
147
|
+
// Check if pageModes is provided and matches against current content mode
|
|
148
|
+
// This will eventially transition from mode to contentMode
|
|
103
149
|
var editorContentMode = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode;
|
|
104
150
|
if (pageModes) {
|
|
105
151
|
// Early Exit: consumer has set pageModes but editorContentMode is undefined
|
|
@@ -116,11 +162,8 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
116
162
|
}
|
|
117
163
|
}
|
|
118
164
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
* Check if there is an active extension and hide the selection extension dropdown
|
|
123
|
-
*/
|
|
165
|
+
// Active Extension
|
|
166
|
+
// Check if there is an active extension and hide the selection extension dropdown
|
|
124
167
|
var selectionExtensionState = _main.selectionExtensionPluginKey.getState(state);
|
|
125
168
|
if (selectionExtensionState !== null && selectionExtensionState !== void 0 && selectionExtensionState.activeExtension) {
|
|
126
169
|
return;
|
|
@@ -163,8 +206,8 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
163
206
|
selectionRanges: selectionRanges
|
|
164
207
|
};
|
|
165
208
|
(_extension$onClick = extension.onClick) === null || _extension$onClick === void 0 || _extension$onClick.call(extension, onClickCallbackOptions);
|
|
166
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (
|
|
167
|
-
var tr =
|
|
209
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref7) {
|
|
210
|
+
var tr = _ref7.tr;
|
|
168
211
|
tr.setMeta(_main.selectionExtensionPluginKey, {
|
|
169
212
|
type: _types.SelectionExtensionActionTypes.SET_SELECTED_NODE,
|
|
170
213
|
selectedNode: selectedNode,
|
|
@@ -227,9 +270,7 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
227
270
|
});
|
|
228
271
|
};
|
|
229
272
|
|
|
230
|
-
|
|
231
|
-
* Add a heading to the external extensions
|
|
232
|
-
*/
|
|
273
|
+
// Add a heading to the external extensions
|
|
233
274
|
var getExternalExtensions = function getExternalExtensions(extensions) {
|
|
234
275
|
var prefilteredExtensions = prefilterExtensions(extensions);
|
|
235
276
|
var externalExtensions = [];
|
|
@@ -246,13 +287,28 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
246
287
|
}
|
|
247
288
|
return externalExtensions;
|
|
248
289
|
};
|
|
290
|
+
|
|
291
|
+
// NEXT PR: Make sure we cache the whole generated selection toolbar
|
|
292
|
+
// also debug this to make sure it's actually preventing unnecessary re-renders / work
|
|
249
293
|
if (cachedOverflowMenuOptions && state.selection.eq(cachedSelection) && (0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2')) {
|
|
250
|
-
return (0, _selectionToolbar2.selectionToolbar)(
|
|
294
|
+
return (0, _selectionToolbar2.selectionToolbar)({
|
|
295
|
+
overflowOptions: cachedOverflowMenuOptions,
|
|
296
|
+
extensionList: extensionList
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
var allFirstParty = (0, _toConsumableArray2.default)(firstParty);
|
|
300
|
+
var allExternal = (0, _toConsumableArray2.default)(external);
|
|
301
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2')) {
|
|
302
|
+
allFirstParty = [].concat((0, _toConsumableArray2.default)(firstParty), (0, _toConsumableArray2.default)((0, _extensions.getMenuItemExtensions)(extensionList, 'first-party')));
|
|
303
|
+
allExternal = [].concat((0, _toConsumableArray2.default)(external), (0, _toConsumableArray2.default)((0, _extensions.getMenuItemExtensions)(extensionList, 'external')));
|
|
251
304
|
}
|
|
252
|
-
var groupedExtensionsArray = [].concat((0, _toConsumableArray2.default)(getFirstPartyExtensions(
|
|
305
|
+
var groupedExtensionsArray = [].concat((0, _toConsumableArray2.default)(getFirstPartyExtensions(allFirstParty)), (0, _toConsumableArray2.default)(getExternalExtensions(allExternal)));
|
|
253
306
|
cachedOverflowMenuOptions = groupedExtensionsArray;
|
|
254
307
|
cachedSelection = state.selection;
|
|
255
|
-
return (0, _selectionToolbar2.selectionToolbar)(
|
|
308
|
+
return (0, _selectionToolbar2.selectionToolbar)({
|
|
309
|
+
overflowOptions: cachedOverflowMenuOptions,
|
|
310
|
+
extensionList: extensionList
|
|
311
|
+
});
|
|
256
312
|
}
|
|
257
313
|
},
|
|
258
314
|
pmPlugins: function pmPlugins() {
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.LegacyPrimaryToolbarComponent = exports.LegacyExtensionToolbarItem = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
13
|
+
var LegacyPrimaryToolbarComponent = exports.LegacyPrimaryToolbarComponent = function LegacyPrimaryToolbarComponent(_ref) {
|
|
14
|
+
var primaryToolbarItemExtensions = _ref.primaryToolbarItemExtensions;
|
|
15
|
+
// NEXT PR: need to render a separator after – if there are extensions added
|
|
16
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, primaryToolbarItemExtensions.map(function (toolbarItemExtension, i) {
|
|
17
|
+
var toolbarItem = toolbarItemExtension.getToolbarItem();
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(LegacyExtensionToolbarItem, {
|
|
19
|
+
key: toolbarItem.tooltip,
|
|
20
|
+
toolbarItem: toolbarItem
|
|
21
|
+
});
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
var LegacyExtensionToolbarItem = exports.LegacyExtensionToolbarItem = function LegacyExtensionToolbarItem(_ref2) {
|
|
25
|
+
var toolbarItem = _ref2.toolbarItem,
|
|
26
|
+
getMenuItems = _ref2.getMenuItems;
|
|
27
|
+
var _useState = (0, _react.useState)(false),
|
|
28
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
29
|
+
isOpen = _useState2[0],
|
|
30
|
+
setIsOpen = _useState2[1];
|
|
31
|
+
var Icon = toolbarItem.icon,
|
|
32
|
+
tooltip = toolbarItem.tooltip,
|
|
33
|
+
isDisabled = toolbarItem.isDisabled,
|
|
34
|
+
onClick = toolbarItem.onClick,
|
|
35
|
+
_label = toolbarItem.label;
|
|
36
|
+
if (!getMenuItems) {
|
|
37
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
|
|
38
|
+
spacing: "default",
|
|
39
|
+
disabled: isDisabled,
|
|
40
|
+
selected: isOpen,
|
|
41
|
+
title: tooltip,
|
|
42
|
+
"aria-label": tooltip,
|
|
43
|
+
"aria-expanded": isOpen,
|
|
44
|
+
"aria-haspopup": true,
|
|
45
|
+
onClick: onClick,
|
|
46
|
+
iconBefore: /*#__PURE__*/_react.default.createElement(Icon, {
|
|
47
|
+
label: tooltip
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var toggleOpen = function toggleOpen() {
|
|
52
|
+
setIsOpen(function (prev) {
|
|
53
|
+
return !prev;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var toggleOpenByKeyboard = function toggleOpenByKeyboard(event) {
|
|
57
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
toggleOpen();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var handleItemActivated = function handleItemActivated(_ref3) {
|
|
63
|
+
var _item$onClick;
|
|
64
|
+
var item = _ref3.item,
|
|
65
|
+
_ref3$shouldCloseMenu = _ref3.shouldCloseMenu,
|
|
66
|
+
shouldCloseMenu = _ref3$shouldCloseMenu === void 0 ? true : _ref3$shouldCloseMenu;
|
|
67
|
+
(_item$onClick = item.onClick) === null || _item$onClick === void 0 || _item$onClick.call(item);
|
|
68
|
+
if (shouldCloseMenu) {
|
|
69
|
+
setIsOpen(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var handleOnOpenChange = function handleOnOpenChange(attrs) {
|
|
73
|
+
setIsOpen(!!(attrs !== null && attrs !== void 0 && attrs.isOpen));
|
|
74
|
+
};
|
|
75
|
+
var items = isOpen ? getMenuItems().map(function (menuItem, i) {
|
|
76
|
+
return {
|
|
77
|
+
key: "menu-item-".concat(i),
|
|
78
|
+
content: menuItem.label,
|
|
79
|
+
elemBefore: /*#__PURE__*/_react.default.createElement(menuItem.icon, {
|
|
80
|
+
label: menuItem.label
|
|
81
|
+
}),
|
|
82
|
+
onClick: function onClick() {
|
|
83
|
+
var _menuItem$onClick;
|
|
84
|
+
(_menuItem$onClick = menuItem.onClick) === null || _menuItem$onClick === void 0 || _menuItem$onClick.call(menuItem);
|
|
85
|
+
// NEXT PR: here we need to set the active extension so the contentComponent can render
|
|
86
|
+
// menuItem.contentComponent
|
|
87
|
+
},
|
|
88
|
+
isDisabled: menuItem.isDisabled,
|
|
89
|
+
'aria-label': menuItem.label,
|
|
90
|
+
value: {
|
|
91
|
+
name: menuItem.label
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}) : [];
|
|
95
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownMenuWithKeyboardNavigation, {
|
|
96
|
+
arrowKeyNavigationProviderOptions: {
|
|
97
|
+
type: _uiMenu.ArrowKeyNavigationType.MENU
|
|
98
|
+
},
|
|
99
|
+
items: [{
|
|
100
|
+
items: items
|
|
101
|
+
}],
|
|
102
|
+
isOpen: isOpen,
|
|
103
|
+
onItemActivated: handleItemActivated,
|
|
104
|
+
onOpenChange: handleOnOpenChange,
|
|
105
|
+
fitWidth: 200
|
|
106
|
+
}, /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
|
|
107
|
+
spacing: "default",
|
|
108
|
+
disabled: isDisabled,
|
|
109
|
+
selected: isOpen,
|
|
110
|
+
title: tooltip,
|
|
111
|
+
"aria-label": tooltip,
|
|
112
|
+
"aria-expanded": isOpen,
|
|
113
|
+
"aria-haspopup": true,
|
|
114
|
+
onClick: toggleOpen,
|
|
115
|
+
onKeyDown: toggleOpenByKeyboard,
|
|
116
|
+
iconBefore: /*#__PURE__*/_react.default.createElement(Icon, {
|
|
117
|
+
label: tooltip
|
|
118
|
+
})
|
|
119
|
+
}));
|
|
120
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getToolbarItemExtensions = exports.getMenuItemExtensions = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* From the full list of extensions, extract only those that have a toolbar item configuration
|
|
9
|
+
* for the specified type (either 'primaryToolbar' or 'inlineToolbar').
|
|
10
|
+
*
|
|
11
|
+
* @param extensionList - List of all extensions
|
|
12
|
+
* @param toolbarType - Type of toolbar ('primaryToolbar' or 'inlineToolbar')
|
|
13
|
+
* @returns Array of ToolbarItemExtension objects
|
|
14
|
+
* @example
|
|
15
|
+
*/
|
|
16
|
+
var getToolbarItemExtensions = exports.getToolbarItemExtensions = function getToolbarItemExtensions(extensionList, toolbarType) {
|
|
17
|
+
return extensionList.reduce(function (acc, extension) {
|
|
18
|
+
var toolbarConfig = extension[toolbarType];
|
|
19
|
+
if (toolbarConfig !== null && toolbarConfig !== void 0 && toolbarConfig.getToolbarItem) {
|
|
20
|
+
acc.push({
|
|
21
|
+
getToolbarItem: toolbarConfig.getToolbarItem,
|
|
22
|
+
getMenuItems: toolbarConfig.getMenuItems
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
}, []);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* From the full list of extensions, extract only those that have a menu item configuration
|
|
31
|
+
* for the specified source (either 'first-party' or 'external').
|
|
32
|
+
*
|
|
33
|
+
* Map each to the legacy format for SelectionExtensionConfig.
|
|
34
|
+
*
|
|
35
|
+
* @param extensionList - List of all extensions
|
|
36
|
+
* @param targetSource - Source of the extensions ('first-party' or 'external')
|
|
37
|
+
* @returns Array of SelectionExtensionConfig objects
|
|
38
|
+
* @example
|
|
39
|
+
*/
|
|
40
|
+
var getMenuItemExtensions = exports.getMenuItemExtensions = function getMenuItemExtensions(extensionList, targetSource) {
|
|
41
|
+
return extensionList.reduce(function (acc, extension) {
|
|
42
|
+
var source = extension.source,
|
|
43
|
+
inlineToolbar = extension.inlineToolbar;
|
|
44
|
+
if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) {
|
|
45
|
+
var menuItems = inlineToolbar.getMenuItems();
|
|
46
|
+
menuItems.forEach(function (menuItem) {
|
|
47
|
+
acc.push({
|
|
48
|
+
name: menuItem.label,
|
|
49
|
+
icon: menuItem.icon,
|
|
50
|
+
onClick: menuItem.onClick,
|
|
51
|
+
isDisabled: function isDisabled() {
|
|
52
|
+
return !!menuItem.isDisabled;
|
|
53
|
+
},
|
|
54
|
+
component: menuItem.contentComponent
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return acc;
|
|
59
|
+
}, []);
|
|
60
|
+
};
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.selectionToolbar = void 0;
|
|
7
|
-
var
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _extensions = require("./extensions");
|
|
12
|
+
var _LegacyToolbarComponent = require("./LegacyToolbarComponent");
|
|
13
|
+
var selectionToolbar = exports.selectionToolbar = function selectionToolbar(_ref) {
|
|
14
|
+
var overflowOptions = _ref.overflowOptions,
|
|
15
|
+
_ref$extensionList = _ref.extensionList,
|
|
16
|
+
extensionList = _ref$extensionList === void 0 ? [] : _ref$extensionList;
|
|
17
|
+
var inlineToolbarItemExtensions = (0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2') ? (0, _extensions.getToolbarItemExtensions)(extensionList, 'inlineToolbar') : [];
|
|
8
18
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
items: [].concat((0, _toConsumableArray2.default)(inlineToolbarItemExtensions.length ? [{
|
|
20
|
+
type: 'separator',
|
|
21
|
+
fullHeight: true,
|
|
22
|
+
supportsViewMode: true
|
|
23
|
+
}].concat((0, _toConsumableArray2.default)(inlineToolbarItemExtensions.map(function (_ref2) {
|
|
24
|
+
var getToolbarItem = _ref2.getToolbarItem,
|
|
25
|
+
getMenuItems = _ref2.getMenuItems;
|
|
26
|
+
return {
|
|
27
|
+
type: 'custom',
|
|
28
|
+
render: function render() {
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement(_LegacyToolbarComponent.LegacyExtensionToolbarItem, {
|
|
30
|
+
toolbarItem: getToolbarItem(),
|
|
31
|
+
getMenuItems: getMenuItems
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
fallback: [],
|
|
35
|
+
supportsViewMode: true
|
|
36
|
+
};
|
|
37
|
+
}))) : []), [{
|
|
11
38
|
type: 'separator',
|
|
12
39
|
fullHeight: true,
|
|
13
40
|
supportsViewMode: true
|
|
@@ -15,8 +42,8 @@ var selectionToolbar = exports.selectionToolbar = function selectionToolbar(opti
|
|
|
15
42
|
type: 'overflow-dropdown',
|
|
16
43
|
dropdownWidth: 240,
|
|
17
44
|
supportsViewMode: true,
|
|
18
|
-
options:
|
|
19
|
-
}],
|
|
45
|
+
options: overflowOptions
|
|
46
|
+
}]),
|
|
20
47
|
rank: -6
|
|
21
48
|
};
|
|
22
49
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export const insertAdfAtEndOfDoc = nodeAdf => (state, dispatch) => {
|
|
3
|
+
const {
|
|
4
|
+
tr,
|
|
5
|
+
schema
|
|
6
|
+
} = state;
|
|
7
|
+
try {
|
|
8
|
+
const docEnd = state.doc.content.size;
|
|
9
|
+
const modifiedNode = Node.fromJSON(schema, nodeAdf);
|
|
10
|
+
modifiedNode.check();
|
|
11
|
+
tr.insert(tr.mapping.map(docEnd), modifiedNode).scrollIntoView();
|
|
12
|
+
dispatch(tr);
|
|
13
|
+
return {
|
|
14
|
+
status: 'success'
|
|
15
|
+
};
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return {
|
|
18
|
+
status: 'failed'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { SelectionExtensionActionTypes } from '../../types';
|
|
3
|
+
import { selectionExtensionPluginKey } from '../main';
|
|
4
|
+
export const replaceWithAdf = nodeAdf => (state, dispatch) => {
|
|
5
|
+
var _selectionExtensionPl;
|
|
6
|
+
const {
|
|
7
|
+
tr,
|
|
8
|
+
schema
|
|
9
|
+
} = state;
|
|
10
|
+
|
|
11
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
12
|
+
const docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
13
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
14
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
15
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
16
|
+
});
|
|
17
|
+
if (docChangedAfterClick) {
|
|
18
|
+
dispatch(tr);
|
|
19
|
+
return {
|
|
20
|
+
status: 'document-changed'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
25
|
+
const selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
26
|
+
const nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
27
|
+
if (!selectedNode || nodePos === undefined) {
|
|
28
|
+
throw new Error('No selected node or node position found');
|
|
29
|
+
}
|
|
30
|
+
const endPos = selectedNode.nodeSize + nodePos;
|
|
31
|
+
const modifiedNode = Node.fromJSON(schema, nodeAdf);
|
|
32
|
+
modifiedNode.check();
|
|
33
|
+
tr.replaceWith(nodePos, endPos, modifiedNode).scrollIntoView();
|
|
34
|
+
dispatch(tr);
|
|
35
|
+
return {
|
|
36
|
+
status: 'success'
|
|
37
|
+
};
|
|
38
|
+
} catch (error) {
|
|
39
|
+
dispatch(tr);
|
|
40
|
+
return {
|
|
41
|
+
status: 'failed-to-replace'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|