@atlaskit/editor-plugin-selection-extension 3.4.3 → 3.4.5
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 +13 -0
- package/dist/cjs/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/cjs/pm-plugins/utils/index.js +38 -16
- package/dist/cjs/selectionExtensionPlugin.js +11 -0
- package/dist/es2019/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/es2019/pm-plugins/utils/index.js +35 -14
- package/dist/es2019/selectionExtensionPlugin.js +15 -1
- package/dist/esm/pm-plugins/utils/getOffsetByPath.js +1 -0
- package/dist/esm/pm-plugins/utils/index.js +35 -15
- package/dist/esm/selectionExtensionPlugin.js +12 -1
- package/dist/types/pm-plugins/actions.d.ts +1 -1
- package/dist/types/pm-plugins/main.d.ts +9 -9
- package/dist/types/pm-plugins/utils/index.d.ts +6 -3
- package/dist/types/selectionExtensionPluginType.d.ts +3 -0
- package/dist/types/types/index.d.ts +1 -2
- package/dist/types/ui/extensions.d.ts +1 -1
- package/dist/types/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +6 -6
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +9 -9
- package/dist/types-ts4.5/pm-plugins/utils/index.d.ts +6 -3
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +3 -0
- package/dist/types-ts4.5/types/index.d.ts +1 -2
- package/dist/types-ts4.5/ui/extensions.d.ts +1 -1
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +6 -6
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection-extension
|
|
2
2
|
|
|
3
|
+
## 3.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`fa1ff19077d8b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fa1ff19077d8b) -
|
|
8
|
+
Update getSelectionAdf api to return adf fragment under flag
|
|
9
|
+
|
|
10
|
+
## 3.4.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 3.4.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -20,6 +20,7 @@ function getOffsetByPath(root, pos, pointer) {
|
|
|
20
20
|
|
|
21
21
|
for (var i = 1; i < len; i++) {
|
|
22
22
|
var key = parts[i];
|
|
23
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
23
24
|
if (ref instanceof _model.Fragment && /^[0-9]+$/.test(key)) {
|
|
24
25
|
var index = parseInt(key, 10);
|
|
25
26
|
if (index >= ref.childCount) {
|
|
@@ -4,14 +4,22 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.getFragmentInfoFromSelection = void 0;
|
|
8
|
+
exports.getSelectionAdfInfo = getSelectionAdfInfo;
|
|
9
|
+
exports.validateSelectedNode = exports.getSelectionTextInfo = void 0;
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
11
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
12
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
9
13
|
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
14
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
10
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
11
17
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
18
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
13
19
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
20
|
var _getBoundingBoxFromSelection = require("../../ui/getBoundingBoxFromSelection");
|
|
21
|
+
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; }
|
|
22
|
+
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; }
|
|
15
23
|
var getSelectedRect = function getSelectedRect(selection) {
|
|
16
24
|
var $anchorCell = selection.$anchorCell,
|
|
17
25
|
$headCell = selection.$headCell;
|
|
@@ -33,7 +41,7 @@ var getSelectionInfoFromSameNode = function getSelectionInfoFromSameNode(selecti
|
|
|
33
41
|
},
|
|
34
42
|
end: {
|
|
35
43
|
pointer: "/content/".concat($from.index(), "/text"),
|
|
36
|
-
position: $to.parentOffset
|
|
44
|
+
position: $to.parentOffset
|
|
37
45
|
}
|
|
38
46
|
}],
|
|
39
47
|
nodePos: $from.before() // position before the selection
|
|
@@ -80,11 +88,32 @@ var getSelectionTextInfo = exports.getSelectionTextInfo = function getSelectionT
|
|
|
80
88
|
coords: coords
|
|
81
89
|
};
|
|
82
90
|
};
|
|
83
|
-
var
|
|
91
|
+
var getFragmentInfoFromSelection = exports.getFragmentInfoFromSelection = function getFragmentInfoFromSelection(state) {
|
|
92
|
+
var schema = state.schema,
|
|
93
|
+
selection = state.selection;
|
|
94
|
+
var slice = selection.content();
|
|
95
|
+
var newDoc;
|
|
96
|
+
try {
|
|
97
|
+
var _schema = state.schema;
|
|
98
|
+
var doc = _schema.node('doc', null, [_schema.node('paragraph', null, [])]);
|
|
99
|
+
var transform = new _transform.Transform(doc);
|
|
100
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
newDoc = schema.nodes.doc.createChecked({}, _model.Fragment.empty);
|
|
103
|
+
(0, _monitoring.logException)(error, {
|
|
104
|
+
location: 'editor-plugin-selection-extension'
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
var serializer = new _editorJsonTransformer.JSONTransformer();
|
|
108
|
+
var selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
109
|
+
return {
|
|
110
|
+
selectedNodeAdf: selectedNodeAdf
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
function getSelectionAdfInfo(state) {
|
|
84
114
|
var selection = state.selection;
|
|
85
115
|
var selectionInfo = {
|
|
86
116
|
selectedNode: selection.$from.node(),
|
|
87
|
-
selectionRanges: [],
|
|
88
117
|
nodePos: selection.$from.before() // default to the position before the selection
|
|
89
118
|
};
|
|
90
119
|
if (selection instanceof _state.TextSelection) {
|
|
@@ -99,18 +128,11 @@ var getSelectionAdfInfo = exports.getSelectionAdfInfo = function getSelectionAdf
|
|
|
99
128
|
selectionInfo = getSelectionInfoFromCellSelection(selection);
|
|
100
129
|
}
|
|
101
130
|
var serializer = new _editorJsonTransformer.JSONTransformer();
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
selectedNodeAdf: selectedNodeAdf,
|
|
109
|
-
selectionRanges: selectionRanges,
|
|
110
|
-
selectedNode: selectedNode,
|
|
111
|
-
nodePos: nodePos
|
|
112
|
-
};
|
|
113
|
-
};
|
|
131
|
+
var selectedNodeAdf = serializer.encodeNode(selectionInfo.selectedNode);
|
|
132
|
+
return _objectSpread(_objectSpread({}, selectionInfo), {}, {
|
|
133
|
+
selectedNodeAdf: selectedNodeAdf
|
|
134
|
+
});
|
|
135
|
+
}
|
|
114
136
|
var validateSelectedNode = exports.validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
|
|
115
137
|
var serializer = new _editorJsonTransformer.JSONTransformer();
|
|
116
138
|
var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
@@ -127,6 +127,17 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
|
|
|
127
127
|
selectionRanges: selectionRanges
|
|
128
128
|
};
|
|
129
129
|
},
|
|
130
|
+
getDocumentFromSelection: function getDocumentFromSelection() {
|
|
131
|
+
if (!editorViewRef.current) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
var state = editorViewRef.current.state;
|
|
135
|
+
var _getFragmentInfoFromS = (0, _utils.getFragmentInfoFromSelection)(state),
|
|
136
|
+
selectedNodeAdf = _getFragmentInfoFromS.selectedNodeAdf;
|
|
137
|
+
return {
|
|
138
|
+
selectedNodeAdf: selectedNodeAdf
|
|
139
|
+
};
|
|
140
|
+
},
|
|
130
141
|
getSelectionText: function getSelectionText() {
|
|
131
142
|
if (!editorViewRef.current) {
|
|
132
143
|
return null;
|
|
@@ -13,6 +13,7 @@ export function getOffsetByPath(root, pos, pointer, from = 0, to) {
|
|
|
13
13
|
|
|
14
14
|
for (let i = 1; i < len; i++) {
|
|
15
15
|
const key = parts[i];
|
|
16
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
16
17
|
if (ref instanceof Fragment && /^[0-9]+$/u.test(key)) {
|
|
17
18
|
let index = parseInt(key, 10);
|
|
18
19
|
if (index >= ref.childCount) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import isEqual from 'lodash/isEqual';
|
|
2
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
3
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
4
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
5
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { Transform } from '@atlaskit/editor-prosemirror/transform';
|
|
4
7
|
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
5
8
|
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
6
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -30,7 +33,7 @@ const getSelectionInfoFromSameNode = selection => {
|
|
|
30
33
|
},
|
|
31
34
|
end: {
|
|
32
35
|
pointer: `/content/${$from.index()}/text`,
|
|
33
|
-
position: $to.parentOffset
|
|
36
|
+
position: $to.parentOffset
|
|
34
37
|
}
|
|
35
38
|
}],
|
|
36
39
|
nodePos: $from.before() // position before the selection
|
|
@@ -81,11 +84,36 @@ export const getSelectionTextInfo = (view, api) => {
|
|
|
81
84
|
coords
|
|
82
85
|
};
|
|
83
86
|
};
|
|
84
|
-
export const
|
|
87
|
+
export const getFragmentInfoFromSelection = state => {
|
|
88
|
+
const {
|
|
89
|
+
schema,
|
|
90
|
+
selection
|
|
91
|
+
} = state;
|
|
92
|
+
const slice = selection.content();
|
|
93
|
+
let newDoc;
|
|
94
|
+
try {
|
|
95
|
+
const {
|
|
96
|
+
schema
|
|
97
|
+
} = state;
|
|
98
|
+
const doc = schema.node('doc', null, [schema.node('paragraph', null, [])]);
|
|
99
|
+
const transform = new Transform(doc);
|
|
100
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
newDoc = schema.nodes.doc.createChecked({}, Fragment.empty);
|
|
103
|
+
logException(error, {
|
|
104
|
+
location: 'editor-plugin-selection-extension'
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const serializer = new JSONTransformer();
|
|
108
|
+
const selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
109
|
+
return {
|
|
110
|
+
selectedNodeAdf
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export function getSelectionAdfInfo(state) {
|
|
85
114
|
const selection = state.selection;
|
|
86
115
|
let selectionInfo = {
|
|
87
116
|
selectedNode: selection.$from.node(),
|
|
88
|
-
selectionRanges: [],
|
|
89
117
|
nodePos: selection.$from.before() // default to the position before the selection
|
|
90
118
|
};
|
|
91
119
|
if (selection instanceof TextSelection) {
|
|
@@ -102,19 +130,12 @@ export const getSelectionAdfInfo = state => {
|
|
|
102
130
|
selectionInfo = getSelectionInfoFromCellSelection(selection);
|
|
103
131
|
}
|
|
104
132
|
const serializer = new JSONTransformer();
|
|
105
|
-
const
|
|
106
|
-
selectionRanges,
|
|
107
|
-
selectedNode,
|
|
108
|
-
nodePos
|
|
109
|
-
} = selectionInfo;
|
|
110
|
-
const selectedNodeAdf = serializer.encodeNode(selectedNode);
|
|
133
|
+
const selectedNodeAdf = serializer.encodeNode(selectionInfo.selectedNode);
|
|
111
134
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
selectedNode,
|
|
115
|
-
nodePos
|
|
135
|
+
...selectionInfo,
|
|
136
|
+
selectedNodeAdf
|
|
116
137
|
};
|
|
117
|
-
}
|
|
138
|
+
}
|
|
118
139
|
export const validateSelectedNode = (selectedNodeAdf, selectedNode) => {
|
|
119
140
|
const serializer = new JSONTransformer();
|
|
120
141
|
const selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
@@ -6,7 +6,7 @@ import { insertSmartLinks } from './pm-plugins/actions';
|
|
|
6
6
|
import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
7
7
|
import { replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
8
8
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
9
|
-
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
9
|
+
import { getFragmentInfoFromSelection, getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
10
10
|
import { SelectionExtensionActionTypes } from './types';
|
|
11
11
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
12
12
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
@@ -120,6 +120,20 @@ export const selectionExtensionPlugin = ({
|
|
|
120
120
|
selectionRanges
|
|
121
121
|
};
|
|
122
122
|
},
|
|
123
|
+
getDocumentFromSelection: () => {
|
|
124
|
+
if (!editorViewRef.current) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const {
|
|
128
|
+
state
|
|
129
|
+
} = editorViewRef.current;
|
|
130
|
+
const {
|
|
131
|
+
selectedNodeAdf
|
|
132
|
+
} = getFragmentInfoFromSelection(state);
|
|
133
|
+
return {
|
|
134
|
+
selectedNodeAdf
|
|
135
|
+
};
|
|
136
|
+
},
|
|
123
137
|
getSelectionText: () => {
|
|
124
138
|
if (!editorViewRef.current) {
|
|
125
139
|
return null;
|
|
@@ -15,6 +15,7 @@ export function getOffsetByPath(root, pos, pointer) {
|
|
|
15
15
|
|
|
16
16
|
for (var i = 1; i < len; i++) {
|
|
17
17
|
var key = parts[i];
|
|
18
|
+
// @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
|
|
18
19
|
if (ref instanceof Fragment && /^[0-9]+$/.test(key)) {
|
|
19
20
|
var index = parseInt(key, 10);
|
|
20
21
|
if (index >= ref.childCount) {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1
4
|
import isEqual from 'lodash/isEqual';
|
|
5
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
2
6
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
7
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
8
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
+
import { Transform } from '@atlaskit/editor-prosemirror/transform';
|
|
4
10
|
import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
|
|
5
11
|
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
6
12
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -26,7 +32,7 @@ var getSelectionInfoFromSameNode = function getSelectionInfoFromSameNode(selecti
|
|
|
26
32
|
},
|
|
27
33
|
end: {
|
|
28
34
|
pointer: "/content/".concat($from.index(), "/text"),
|
|
29
|
-
position: $to.parentOffset
|
|
35
|
+
position: $to.parentOffset
|
|
30
36
|
}
|
|
31
37
|
}],
|
|
32
38
|
nodePos: $from.before() // position before the selection
|
|
@@ -73,11 +79,32 @@ export var getSelectionTextInfo = function getSelectionTextInfo(view, api) {
|
|
|
73
79
|
coords: coords
|
|
74
80
|
};
|
|
75
81
|
};
|
|
76
|
-
export var
|
|
82
|
+
export var getFragmentInfoFromSelection = function getFragmentInfoFromSelection(state) {
|
|
83
|
+
var schema = state.schema,
|
|
84
|
+
selection = state.selection;
|
|
85
|
+
var slice = selection.content();
|
|
86
|
+
var newDoc;
|
|
87
|
+
try {
|
|
88
|
+
var _schema = state.schema;
|
|
89
|
+
var doc = _schema.node('doc', null, [_schema.node('paragraph', null, [])]);
|
|
90
|
+
var transform = new Transform(doc);
|
|
91
|
+
newDoc = transform.replaceRange(0, 2, slice).doc;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
newDoc = schema.nodes.doc.createChecked({}, Fragment.empty);
|
|
94
|
+
logException(error, {
|
|
95
|
+
location: 'editor-plugin-selection-extension'
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
var serializer = new JSONTransformer();
|
|
99
|
+
var selectedNodeAdf = serializer.encodeNode(newDoc);
|
|
100
|
+
return {
|
|
101
|
+
selectedNodeAdf: selectedNodeAdf
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export function getSelectionAdfInfo(state) {
|
|
77
105
|
var selection = state.selection;
|
|
78
106
|
var selectionInfo = {
|
|
79
107
|
selectedNode: selection.$from.node(),
|
|
80
|
-
selectionRanges: [],
|
|
81
108
|
nodePos: selection.$from.before() // default to the position before the selection
|
|
82
109
|
};
|
|
83
110
|
if (selection instanceof TextSelection) {
|
|
@@ -92,18 +119,11 @@ export var getSelectionAdfInfo = function getSelectionAdfInfo(state) {
|
|
|
92
119
|
selectionInfo = getSelectionInfoFromCellSelection(selection);
|
|
93
120
|
}
|
|
94
121
|
var serializer = new JSONTransformer();
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
selectedNodeAdf: selectedNodeAdf,
|
|
102
|
-
selectionRanges: selectionRanges,
|
|
103
|
-
selectedNode: selectedNode,
|
|
104
|
-
nodePos: nodePos
|
|
105
|
-
};
|
|
106
|
-
};
|
|
122
|
+
var selectedNodeAdf = serializer.encodeNode(selectionInfo.selectedNode);
|
|
123
|
+
return _objectSpread(_objectSpread({}, selectionInfo), {}, {
|
|
124
|
+
selectedNodeAdf: selectedNodeAdf
|
|
125
|
+
});
|
|
126
|
+
}
|
|
107
127
|
export var validateSelectedNode = function validateSelectedNode(selectedNodeAdf, selectedNode) {
|
|
108
128
|
var serializer = new JSONTransformer();
|
|
109
129
|
var selectedNodeAdfFromState = serializer.encodeNode(selectedNode);
|
|
@@ -7,7 +7,7 @@ import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
|
|
|
7
7
|
import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
|
|
8
8
|
import { replaceWithAdf as _replaceWithAdf } from './pm-plugins/actions/replaceWithAdf';
|
|
9
9
|
import { createPlugin, selectionExtensionPluginKey } from './pm-plugins/main';
|
|
10
|
-
import { getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
10
|
+
import { getFragmentInfoFromSelection, getSelectionAdfInfo, getSelectionTextInfo } from './pm-plugins/utils';
|
|
11
11
|
import { SelectionExtensionActionTypes } from './types';
|
|
12
12
|
import { SelectionExtensionComponentWrapper } from './ui/extension/SelectionExtensionComponentWrapper';
|
|
13
13
|
import { getMenuItemExtensions, getToolbarItemExtensions } from './ui/extensions';
|
|
@@ -120,6 +120,17 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
|
120
120
|
selectionRanges: selectionRanges
|
|
121
121
|
};
|
|
122
122
|
},
|
|
123
|
+
getDocumentFromSelection: function getDocumentFromSelection() {
|
|
124
|
+
if (!editorViewRef.current) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
var state = editorViewRef.current.state;
|
|
128
|
+
var _getFragmentInfoFromS = getFragmentInfoFromSelection(state),
|
|
129
|
+
selectedNodeAdf = _getFragmentInfoFromS.selectedNodeAdf;
|
|
130
|
+
return {
|
|
131
|
+
selectedNodeAdf: selectedNodeAdf
|
|
132
|
+
};
|
|
133
|
+
},
|
|
123
134
|
getSelectionText: function getSelectionText() {
|
|
124
135
|
if (!editorViewRef.current) {
|
|
125
136
|
return null;
|
|
@@ -3,6 +3,6 @@ import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
5
|
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status:
|
|
6
|
+
status: "success" | "error";
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -4,10 +4,10 @@ import { type SelectionExtensionPluginState } from '../types';
|
|
|
4
4
|
export declare const selectionExtensionPluginKey: PluginKey<SelectionExtensionPluginState>;
|
|
5
5
|
export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginState | {
|
|
6
6
|
activeExtension: any;
|
|
7
|
-
selectedNode?: import("prosemirror-model").Node
|
|
8
|
-
nodePos?: number
|
|
9
|
-
startTrackChanges?: boolean
|
|
10
|
-
docChangedAfterClick?: boolean
|
|
7
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
8
|
+
nodePos?: number;
|
|
9
|
+
startTrackChanges?: boolean;
|
|
10
|
+
docChangedAfterClick?: boolean;
|
|
11
11
|
} | {
|
|
12
12
|
selectedNode: any;
|
|
13
13
|
nodePos: any;
|
|
@@ -17,15 +17,15 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
17
17
|
extension: import("../types").SelectionExtension;
|
|
18
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
19
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
} | {
|
|
22
22
|
startTrackChanges: any;
|
|
23
23
|
activeExtension?: {
|
|
24
24
|
extension: import("../types").SelectionExtension;
|
|
25
25
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
26
|
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
-
}
|
|
28
|
-
selectedNode?: import("prosemirror-model").Node
|
|
29
|
-
nodePos?: number
|
|
30
|
-
docChangedAfterClick?: boolean
|
|
27
|
+
};
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
29
|
+
nodePos?: number;
|
|
30
|
+
docChangedAfterClick?: boolean;
|
|
31
31
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
-
import type
|
|
3
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { type EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
@@ -8,11 +8,14 @@ import type { SelectionExtensionSelectionInfo } from '../../types';
|
|
|
8
8
|
import { type SelectionRange } from '../../types';
|
|
9
9
|
type SelectionInfo = {
|
|
10
10
|
selectedNodeAdf: ADFEntity;
|
|
11
|
-
selectionRanges
|
|
11
|
+
selectionRanges?: SelectionRange[];
|
|
12
12
|
selectedNode: PMNode;
|
|
13
13
|
nodePos: number;
|
|
14
14
|
};
|
|
15
15
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
17
|
+
selectedNodeAdf: ADFEntity;
|
|
18
|
+
};
|
|
19
|
+
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
17
20
|
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
18
21
|
export {};
|
|
@@ -31,6 +31,9 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
31
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
33
|
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getDocumentFromSelection: () => {
|
|
35
|
+
selectedNodeAdf?: ADFEntity;
|
|
36
|
+
} | null;
|
|
34
37
|
getSelectionText: () => SelectionTextResult;
|
|
35
38
|
};
|
|
36
39
|
}>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
3
2
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
3
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
@@ -49,7 +48,7 @@ export type SelectionRange = {
|
|
|
49
48
|
};
|
|
50
49
|
export type SelectionExtensionFnOptions = {
|
|
51
50
|
selectedNodeAdf: ADFEntity;
|
|
52
|
-
selectionRanges
|
|
51
|
+
selectionRanges?: SelectionRange[];
|
|
53
52
|
};
|
|
54
53
|
export type SelectionExtensionFn = ({ selectedNodeAdf, selectionRanges, }: SelectionExtensionFnOptions) => DynamicSelectionExtension;
|
|
55
54
|
export type SelectionExtensionConfig = SelectionExtension | SelectionExtensionFn;
|
|
@@ -12,7 +12,7 @@ export type ToolbarItemExtension = {
|
|
|
12
12
|
* @returns Array of ToolbarItemExtension objects
|
|
13
13
|
* @example
|
|
14
14
|
*/
|
|
15
|
-
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType:
|
|
15
|
+
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: "primaryToolbar" | "inlineToolbar") => ToolbarItemExtension[];
|
|
16
16
|
/**
|
|
17
17
|
* From the full list of extensions, extract only those that have a menu item configuration
|
|
18
18
|
* for the specified source (either 'first-party' or 'external').
|
|
@@ -13,18 +13,18 @@ export type SelectionExtensionDropdownMenuProps = {
|
|
|
13
13
|
} & WrappedComponentProps;
|
|
14
14
|
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
15
15
|
items: MenuItemsType;
|
|
16
|
-
onItemActivated?: (
|
|
16
|
+
onItemActivated?: (attrs: {
|
|
17
17
|
item: MenuItem;
|
|
18
18
|
shouldCloseMenu?: boolean;
|
|
19
|
-
}) => void
|
|
20
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
19
|
+
}) => void;
|
|
20
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
21
21
|
} & WrappedComponentProps>> & {
|
|
22
22
|
WrappedComponent: React.ComponentType<{
|
|
23
23
|
items: MenuItemsType;
|
|
24
|
-
onItemActivated?: (
|
|
24
|
+
onItemActivated?: (attrs: {
|
|
25
25
|
item: MenuItem;
|
|
26
26
|
shouldCloseMenu?: boolean;
|
|
27
|
-
}) => void
|
|
28
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
27
|
+
}) => void;
|
|
28
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
29
29
|
} & WrappedComponentProps>;
|
|
30
30
|
};
|
|
@@ -3,6 +3,6 @@ import type { CommandDispatch } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { type LinkInsertionOption } from '../types';
|
|
5
5
|
export declare const insertSmartLinks: (linkInsertionOption: LinkInsertionOption[], selectedNodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => {
|
|
6
|
-
status:
|
|
6
|
+
status: "success" | "error";
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
@@ -4,10 +4,10 @@ import { type SelectionExtensionPluginState } from '../types';
|
|
|
4
4
|
export declare const selectionExtensionPluginKey: PluginKey<SelectionExtensionPluginState>;
|
|
5
5
|
export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginState | {
|
|
6
6
|
activeExtension: any;
|
|
7
|
-
selectedNode?: import("prosemirror-model").Node
|
|
8
|
-
nodePos?: number
|
|
9
|
-
startTrackChanges?: boolean
|
|
10
|
-
docChangedAfterClick?: boolean
|
|
7
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
8
|
+
nodePos?: number;
|
|
9
|
+
startTrackChanges?: boolean;
|
|
10
|
+
docChangedAfterClick?: boolean;
|
|
11
11
|
} | {
|
|
12
12
|
selectedNode: any;
|
|
13
13
|
nodePos: any;
|
|
@@ -17,15 +17,15 @@ export declare const createPlugin: () => SafePlugin<SelectionExtensionPluginStat
|
|
|
17
17
|
extension: import("../types").SelectionExtension;
|
|
18
18
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
19
19
|
coords: import("../types").SelectionExtensionCoords;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
} | {
|
|
22
22
|
startTrackChanges: any;
|
|
23
23
|
activeExtension?: {
|
|
24
24
|
extension: import("../types").SelectionExtension;
|
|
25
25
|
selection: import("../types").SelectionExtensionSelectionInfo;
|
|
26
26
|
coords: import("../types").SelectionExtensionCoords;
|
|
27
|
-
}
|
|
28
|
-
selectedNode?: import("prosemirror-model").Node
|
|
29
|
-
nodePos?: number
|
|
30
|
-
docChangedAfterClick?: boolean
|
|
27
|
+
};
|
|
28
|
+
selectedNode?: import("prosemirror-model").Node;
|
|
29
|
+
nodePos?: number;
|
|
30
|
+
docChangedAfterClick?: boolean;
|
|
31
31
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
-
import type
|
|
3
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { type EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { SelectionExtensionPlugin } from '../../selectionExtensionPluginType';
|
|
@@ -8,11 +8,14 @@ import type { SelectionExtensionSelectionInfo } from '../../types';
|
|
|
8
8
|
import { type SelectionRange } from '../../types';
|
|
9
9
|
type SelectionInfo = {
|
|
10
10
|
selectedNodeAdf: ADFEntity;
|
|
11
|
-
selectionRanges
|
|
11
|
+
selectionRanges?: SelectionRange[];
|
|
12
12
|
selectedNode: PMNode;
|
|
13
13
|
nodePos: number;
|
|
14
14
|
};
|
|
15
15
|
export declare const getSelectionTextInfo: (view: EditorView, api?: ExtractInjectionAPI<SelectionExtensionPlugin>) => SelectionExtensionSelectionInfo;
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const getFragmentInfoFromSelection: (state: EditorState) => {
|
|
17
|
+
selectedNodeAdf: ADFEntity;
|
|
18
|
+
};
|
|
19
|
+
export declare function getSelectionAdfInfo(state: EditorState): SelectionInfo;
|
|
17
20
|
export declare const validateSelectedNode: (selectedNodeAdf: ADFEntity, selectedNode: PMNode) => boolean;
|
|
18
21
|
export {};
|
|
@@ -31,6 +31,9 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
|
31
31
|
replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
|
|
32
32
|
insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
|
|
33
33
|
getSelectionAdf: () => SelectionAdfResult;
|
|
34
|
+
getDocumentFromSelection: () => {
|
|
35
|
+
selectedNodeAdf?: ADFEntity;
|
|
36
|
+
} | null;
|
|
34
37
|
getSelectionText: () => SelectionTextResult;
|
|
35
38
|
};
|
|
36
39
|
}>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
3
2
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
3
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
@@ -49,7 +48,7 @@ export type SelectionRange = {
|
|
|
49
48
|
};
|
|
50
49
|
export type SelectionExtensionFnOptions = {
|
|
51
50
|
selectedNodeAdf: ADFEntity;
|
|
52
|
-
selectionRanges
|
|
51
|
+
selectionRanges?: SelectionRange[];
|
|
53
52
|
};
|
|
54
53
|
export type SelectionExtensionFn = ({ selectedNodeAdf, selectionRanges, }: SelectionExtensionFnOptions) => DynamicSelectionExtension;
|
|
55
54
|
export type SelectionExtensionConfig = SelectionExtension | SelectionExtensionFn;
|
|
@@ -12,7 +12,7 @@ export type ToolbarItemExtension = {
|
|
|
12
12
|
* @returns Array of ToolbarItemExtension objects
|
|
13
13
|
* @example
|
|
14
14
|
*/
|
|
15
|
-
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType:
|
|
15
|
+
export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: "primaryToolbar" | "inlineToolbar") => ToolbarItemExtension[];
|
|
16
16
|
/**
|
|
17
17
|
* From the full list of extensions, extract only those that have a menu item configuration
|
|
18
18
|
* for the specified source (either 'first-party' or 'external').
|
|
@@ -13,18 +13,18 @@ export type SelectionExtensionDropdownMenuProps = {
|
|
|
13
13
|
} & WrappedComponentProps;
|
|
14
14
|
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
15
15
|
items: MenuItemsType;
|
|
16
|
-
onItemActivated?: (
|
|
16
|
+
onItemActivated?: (attrs: {
|
|
17
17
|
item: MenuItem;
|
|
18
18
|
shouldCloseMenu?: boolean;
|
|
19
|
-
}) => void
|
|
20
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
19
|
+
}) => void;
|
|
20
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
21
21
|
} & WrappedComponentProps>> & {
|
|
22
22
|
WrappedComponent: React.ComponentType<{
|
|
23
23
|
items: MenuItemsType;
|
|
24
|
-
onItemActivated?: (
|
|
24
|
+
onItemActivated?: (attrs: {
|
|
25
25
|
item: MenuItem;
|
|
26
26
|
shouldCloseMenu?: boolean;
|
|
27
|
-
}) => void
|
|
28
|
-
editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
27
|
+
}) => void;
|
|
28
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
29
29
|
} & WrappedComponentProps>;
|
|
30
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
4
4
|
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,27 +35,27 @@
|
|
|
35
35
|
".": "./src/index.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@atlaskit/adf-utils": "^19.
|
|
38
|
+
"@atlaskit/adf-utils": "^19.21.0",
|
|
39
39
|
"@atlaskit/editor-json-transformer": "^8.25.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",
|
|
43
|
-
"@atlaskit/editor-plugin-selection-toolbar": "^4.
|
|
43
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^4.3.0",
|
|
44
44
|
"@atlaskit/editor-plugin-user-preferences": "^1.2.0",
|
|
45
45
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
46
|
-
"@atlaskit/editor-shared-styles": "^3.
|
|
46
|
+
"@atlaskit/editor-shared-styles": "^3.6.0",
|
|
47
47
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
48
|
-
"@atlaskit/icon": "^27.
|
|
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": "^
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^10.0.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.25.0",
|
|
59
59
|
"react": "^18.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"@atlaskit/visual-regression": "workspace:^",
|
|
66
66
|
"@testing-library/react": "^13.4.0",
|
|
67
67
|
"react-dom": "^18.2.0",
|
|
68
|
-
"typescript": "~5.4.2",
|
|
69
68
|
"wait-for-expect": "^1.2.0"
|
|
70
69
|
},
|
|
71
70
|
"techstack": {
|