@atlaskit/editor-plugin-selection-extension 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/pm-plugins/actions/insertAdfAtEndOfDoc.js +27 -0
- package/dist/cjs/pm-plugins/actions/replaceWithAdf.js +50 -0
- package/dist/cjs/pm-plugins/main.js +7 -0
- package/dist/cjs/selectionExtensionPlugin.js +24 -0
- package/dist/es2019/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
- package/dist/es2019/pm-plugins/actions/replaceWithAdf.js +44 -0
- package/dist/es2019/pm-plugins/main.js +8 -0
- package/dist/es2019/selectionExtensionPlugin.js +26 -0
- package/dist/esm/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
- package/dist/esm/pm-plugins/actions/replaceWithAdf.js +44 -0
- package/dist/esm/pm-plugins/main.js +7 -0
- package/dist/esm/selectionExtensionPlugin.js +24 -0
- 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 +3 -1
- package/dist/types/types/index.d.ts +7 -0
- 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 +3 -1
- package/dist/types-ts4.5/types/index.d.ts +7 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#193092](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193092)
|
|
8
|
+
[`1e21bb09f7d00`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1e21bb09f7d00) -
|
|
9
|
+
new api to insert ADF at the bottom of document
|
|
10
|
+
|
|
11
|
+
## 3.3.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#191736](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/191736)
|
|
16
|
+
[`5c91794777225`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5c91794777225) -
|
|
17
|
+
Clear activeExtension when selection changed
|
|
18
|
+
|
|
3
19
|
## 3.3.0
|
|
4
20
|
|
|
5
21
|
### Minor 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
|
+
};
|
|
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
11
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
12
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
13
|
var _types = require("../types");
|
|
13
14
|
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; }
|
|
14
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -54,6 +55,12 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
54
55
|
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
55
56
|
});
|
|
56
57
|
}
|
|
58
|
+
// clear activeExtension if the selection has changed and not empty
|
|
59
|
+
if (tr.selectionSet && !tr.selection.empty && (0, _platformFeatureFlags.fg)('platform_editor_clear_active_extension_fix')) {
|
|
60
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
61
|
+
activeExtension: undefined // Clear active extension on selection change
|
|
62
|
+
});
|
|
63
|
+
}
|
|
57
64
|
return pluginState;
|
|
58
65
|
}
|
|
59
66
|
}
|
|
@@ -11,6 +11,8 @@ 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");
|
|
@@ -64,6 +66,28 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
64
66
|
state = _editorViewRef$curren.state,
|
|
65
67
|
dispatch = _editorViewRef$curren.dispatch;
|
|
66
68
|
return (0, _actions.insertSmartLinks)(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
69
|
+
},
|
|
70
|
+
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
71
|
+
if (!editorViewRef.current) {
|
|
72
|
+
return {
|
|
73
|
+
status: 'failed-to-replace'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var _editorViewRef$curren2 = editorViewRef.current,
|
|
77
|
+
state = _editorViewRef$curren2.state,
|
|
78
|
+
dispatch = _editorViewRef$curren2.dispatch;
|
|
79
|
+
return (0, _replaceWithAdf2.replaceWithAdf)(nodeAdf)(state, dispatch);
|
|
80
|
+
},
|
|
81
|
+
insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
|
|
82
|
+
if (!editorViewRef.current) {
|
|
83
|
+
return {
|
|
84
|
+
status: 'failed'
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
var _editorViewRef$curren3 = editorViewRef.current,
|
|
88
|
+
state = _editorViewRef$curren3.state,
|
|
89
|
+
dispatch = _editorViewRef$curren3.dispatch;
|
|
90
|
+
return (0, _insertAdfAtEndOfDoc2.insertAdfAtEndOfDoc)(nodeAdf)(state, dispatch);
|
|
67
91
|
}
|
|
68
92
|
},
|
|
69
93
|
contentComponent: function contentComponent(_ref4) {
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { SelectionExtensionActionTypes } from '../types';
|
|
5
6
|
export const selectionExtensionPluginKey = new PluginKey('selectionExtensionPlugin');
|
|
6
7
|
export const createPlugin = () => {
|
|
@@ -47,6 +48,13 @@ export const createPlugin = () => {
|
|
|
47
48
|
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
48
49
|
};
|
|
49
50
|
}
|
|
51
|
+
// clear activeExtension if the selection has changed and not empty
|
|
52
|
+
if (tr.selectionSet && !tr.selection.empty && fg('platform_editor_clear_active_extension_fix')) {
|
|
53
|
+
return {
|
|
54
|
+
...pluginState,
|
|
55
|
+
activeExtension: undefined // Clear active extension on selection change
|
|
56
|
+
};
|
|
57
|
+
}
|
|
50
58
|
return pluginState;
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -3,6 +3,8 @@ 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
5
|
import { insertSmartLinks } from './pm-plugins/actions';
|
|
6
|
+
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
7
|
+
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
6
8
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
7
9
|
import { getSelectionInfo } from './pm-plugins/utils';
|
|
8
10
|
import { SelectionExtensionActionTypes } from './types';
|
|
@@ -56,6 +58,30 @@ export const selectionExtensionPlugin = ({
|
|
|
56
58
|
dispatch
|
|
57
59
|
} = editorViewRef.current;
|
|
58
60
|
return insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
61
|
+
},
|
|
62
|
+
replaceWithAdf: nodeAdf => {
|
|
63
|
+
if (!editorViewRef.current) {
|
|
64
|
+
return {
|
|
65
|
+
status: 'failed-to-replace'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const {
|
|
69
|
+
state,
|
|
70
|
+
dispatch
|
|
71
|
+
} = editorViewRef.current;
|
|
72
|
+
return replaceWithAdf(nodeAdf)(state, dispatch);
|
|
73
|
+
},
|
|
74
|
+
insertAdfAtEndOfDoc: nodeAdf => {
|
|
75
|
+
if (!editorViewRef.current) {
|
|
76
|
+
return {
|
|
77
|
+
status: 'failed'
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const {
|
|
81
|
+
state,
|
|
82
|
+
dispatch
|
|
83
|
+
} = editorViewRef.current;
|
|
84
|
+
return insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
|
|
59
85
|
}
|
|
60
86
|
},
|
|
61
87
|
contentComponent: ({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export var insertAdfAtEndOfDoc = function insertAdfAtEndOfDoc(nodeAdf) {
|
|
3
|
+
return function (state, dispatch) {
|
|
4
|
+
var tr = state.tr,
|
|
5
|
+
schema = state.schema;
|
|
6
|
+
try {
|
|
7
|
+
var docEnd = state.doc.content.size;
|
|
8
|
+
var modifiedNode = Node.fromJSON(schema, nodeAdf);
|
|
9
|
+
modifiedNode.check();
|
|
10
|
+
tr.insert(tr.mapping.map(docEnd), modifiedNode).scrollIntoView();
|
|
11
|
+
dispatch(tr);
|
|
12
|
+
return {
|
|
13
|
+
status: 'success'
|
|
14
|
+
};
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return {
|
|
17
|
+
status: 'failed'
|
|
18
|
+
};
|
|
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 var replaceWithAdf = function replaceWithAdf(nodeAdf) {
|
|
5
|
+
return function (state, dispatch) {
|
|
6
|
+
var _selectionExtensionPl;
|
|
7
|
+
var tr = state.tr,
|
|
8
|
+
schema = state.schema;
|
|
9
|
+
|
|
10
|
+
// we need to track if any changes were made since user click the toolbar button
|
|
11
|
+
var docChangedAfterClick = ((_selectionExtensionPl = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl === void 0 ? void 0 : _selectionExtensionPl.docChangedAfterClick) || false;
|
|
12
|
+
tr.setMeta(selectionExtensionPluginKey, {
|
|
13
|
+
type: SelectionExtensionActionTypes.START_TRACK_CHANGES,
|
|
14
|
+
startTrackChanges: false // Reset the flag when starting to track changes
|
|
15
|
+
});
|
|
16
|
+
if (docChangedAfterClick) {
|
|
17
|
+
dispatch(tr);
|
|
18
|
+
return {
|
|
19
|
+
status: 'document-changed'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
var _selectionExtensionPl2, _selectionExtensionPl3;
|
|
24
|
+
var selectedNode = (_selectionExtensionPl2 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl2 === void 0 ? void 0 : _selectionExtensionPl2.selectedNode;
|
|
25
|
+
var nodePos = (_selectionExtensionPl3 = selectionExtensionPluginKey.getState(state)) === null || _selectionExtensionPl3 === void 0 ? void 0 : _selectionExtensionPl3.nodePos;
|
|
26
|
+
if (!selectedNode || nodePos === undefined) {
|
|
27
|
+
throw new Error('No selected node or node position found');
|
|
28
|
+
}
|
|
29
|
+
var endPos = selectedNode.nodeSize + nodePos;
|
|
30
|
+
var modifiedNode = Node.fromJSON(schema, nodeAdf);
|
|
31
|
+
modifiedNode.check();
|
|
32
|
+
tr.replaceWith(nodePos, endPos, modifiedNode).scrollIntoView();
|
|
33
|
+
dispatch(tr);
|
|
34
|
+
return {
|
|
35
|
+
status: 'success'
|
|
36
|
+
};
|
|
37
|
+
} catch (error) {
|
|
38
|
+
dispatch(tr);
|
|
39
|
+
return {
|
|
40
|
+
status: 'failed-to-replace'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
7
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
8
|
import { SelectionExtensionActionTypes } from '../types';
|
|
8
9
|
export var selectionExtensionPluginKey = new PluginKey('selectionExtensionPlugin');
|
|
9
10
|
export var createPlugin = function createPlugin() {
|
|
@@ -47,6 +48,12 @@ export var createPlugin = function createPlugin() {
|
|
|
47
48
|
startTrackChanges: false // Reset the flag to stop tracking after the document has changed
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
// clear activeExtension if the selection has changed and not empty
|
|
52
|
+
if (tr.selectionSet && !tr.selection.empty && fg('platform_editor_clear_active_extension_fix')) {
|
|
53
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
54
|
+
activeExtension: undefined // Clear active extension on selection change
|
|
55
|
+
});
|
|
56
|
+
}
|
|
50
57
|
return pluginState;
|
|
51
58
|
}
|
|
52
59
|
}
|
|
@@ -4,6 +4,8 @@ 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
6
|
import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
|
|
7
|
+
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
8
|
+
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
7
9
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
8
10
|
import { getSelectionInfo } from './pm-plugins/utils';
|
|
9
11
|
import { SelectionExtensionActionTypes } from './types';
|
|
@@ -57,6 +59,28 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
57
59
|
state = _editorViewRef$curren.state,
|
|
58
60
|
dispatch = _editorViewRef$curren.dispatch;
|
|
59
61
|
return _insertSmartLinks(linkInsertionOptions, selectedNodeAdf)(state, dispatch);
|
|
62
|
+
},
|
|
63
|
+
replaceWithAdf: function replaceWithAdf(nodeAdf) {
|
|
64
|
+
if (!editorViewRef.current) {
|
|
65
|
+
return {
|
|
66
|
+
status: 'failed-to-replace'
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var _editorViewRef$curren2 = editorViewRef.current,
|
|
70
|
+
state = _editorViewRef$curren2.state,
|
|
71
|
+
dispatch = _editorViewRef$curren2.dispatch;
|
|
72
|
+
return _replaceWithAdf(nodeAdf)(state, dispatch);
|
|
73
|
+
},
|
|
74
|
+
insertAdfAtEndOfDoc: function insertAdfAtEndOfDoc(nodeAdf) {
|
|
75
|
+
if (!editorViewRef.current) {
|
|
76
|
+
return {
|
|
77
|
+
status: 'failed'
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var _editorViewRef$curren3 = editorViewRef.current,
|
|
81
|
+
state = _editorViewRef$curren3.state,
|
|
82
|
+
dispatch = _editorViewRef$curren3.dispatch;
|
|
83
|
+
return _insertAdfAtEndOfDoc(nodeAdf)(state, dispatch);
|
|
60
84
|
}
|
|
61
85
|
},
|
|
62
86
|
contentComponent: function contentComponent(_ref4) {
|
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 { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, } from './types';
|
|
3
|
+
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, ReplaceWithAdfResult, InsertAdfAtEndOfDocResult, } from './types';
|
|
@@ -0,0 +1,5 @@
|
|
|
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 InsertAdfAtEndOfDocResult } from '../../types';
|
|
5
|
+
export declare const insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => InsertAdfAtEndOfDocResult;
|
|
@@ -0,0 +1,5 @@
|
|
|
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 ReplaceWithAdfResult } from '../../types';
|
|
5
|
+
export declare const replaceWithAdf: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => ReplaceWithAdfResult;
|
|
@@ -3,7 +3,7 @@ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/
|
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
4
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
5
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
6
|
-
import type { DynamicSelectionExtension, LinkInsertionOption, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
6
|
+
import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
7
7
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
8
8
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
9
9
|
dependencies: [
|
|
@@ -24,5 +24,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
24
24
|
status: 'success' | 'error';
|
|
25
25
|
message?: string;
|
|
26
26
|
};
|
|
27
|
+
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
28
|
+
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
27
29
|
};
|
|
28
30
|
}>;
|
|
@@ -110,4 +110,11 @@ export type SelectionExtensionPluginState = {
|
|
|
110
110
|
startTrackChanges?: boolean;
|
|
111
111
|
docChangedAfterClick?: boolean;
|
|
112
112
|
};
|
|
113
|
+
export type ReplaceWithAdfStatus = 'success' | 'document-changed' | 'failed-to-replace';
|
|
114
|
+
export type ReplaceWithAdfResult = {
|
|
115
|
+
status: ReplaceWithAdfStatus;
|
|
116
|
+
};
|
|
117
|
+
export type InsertAdfAtEndOfDocResult = {
|
|
118
|
+
status: 'success' | 'failed';
|
|
119
|
+
};
|
|
113
120
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { selectionExtensionPlugin } from './selectionExtensionPlugin';
|
|
2
2
|
export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
|
|
3
|
-
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, } from './types';
|
|
3
|
+
export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, ReplaceWithAdfResult, InsertAdfAtEndOfDocResult, } from './types';
|
|
@@ -0,0 +1,5 @@
|
|
|
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 InsertAdfAtEndOfDocResult } from '../../types';
|
|
5
|
+
export declare const insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => InsertAdfAtEndOfDocResult;
|
|
@@ -0,0 +1,5 @@
|
|
|
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 ReplaceWithAdfResult } from '../../types';
|
|
5
|
+
export declare const replaceWithAdf: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => ReplaceWithAdfResult;
|
|
@@ -3,7 +3,7 @@ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/
|
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
4
|
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
5
|
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
6
|
-
import type { DynamicSelectionExtension, LinkInsertionOption, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
6
|
+
import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
|
|
7
7
|
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
8
8
|
pluginConfiguration: SelectionExtensionPluginOptions | undefined;
|
|
9
9
|
dependencies: [
|
|
@@ -24,5 +24,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
24
24
|
status: 'success' | 'error';
|
|
25
25
|
message?: string;
|
|
26
26
|
};
|
|
27
|
+
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
28
|
+
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
27
29
|
};
|
|
28
30
|
}>;
|
|
@@ -110,4 +110,11 @@ export type SelectionExtensionPluginState = {
|
|
|
110
110
|
startTrackChanges?: boolean;
|
|
111
111
|
docChangedAfterClick?: boolean;
|
|
112
112
|
};
|
|
113
|
+
export type ReplaceWithAdfStatus = 'success' | 'document-changed' | 'failed-to-replace';
|
|
114
|
+
export type ReplaceWithAdfResult = {
|
|
115
|
+
status: ReplaceWithAdfStatus;
|
|
116
|
+
};
|
|
117
|
+
export type InsertAdfAtEndOfDocResult = {
|
|
118
|
+
status: 'success' | 'failed';
|
|
119
|
+
};
|
|
113
120
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
44
44
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
45
|
-
"@atlaskit/icon": "^27.
|
|
45
|
+
"@atlaskit/icon": "^27.8.0",
|
|
46
46
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
47
|
-
"@atlaskit/primitives": "^14.
|
|
48
|
-
"@atlaskit/tmp-editor-statsig": "^9.
|
|
47
|
+
"@atlaskit/primitives": "^14.11.0",
|
|
48
|
+
"@atlaskit/tmp-editor-statsig": "^9.17.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0",
|
|
50
50
|
"lodash": "^4.17.21",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
@@ -104,6 +104,9 @@
|
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
"platform-feature-flags": {
|
|
107
|
+
"platform_editor_clear_active_extension_fix": {
|
|
108
|
+
"type": "boolean"
|
|
109
|
+
},
|
|
107
110
|
"platform_editor_selection_extension_api_v2": {
|
|
108
111
|
"type": "boolean"
|
|
109
112
|
}
|