@atlaskit/editor-plugin-selection 3.0.7 → 3.1.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 +18 -0
- package/dist/cjs/editor-actions/index.js +106 -0
- package/dist/cjs/selectionPlugin.js +4 -1
- package/dist/es2019/editor-actions/index.js +85 -0
- package/dist/es2019/selectionPlugin.js +4 -1
- package/dist/esm/editor-actions/index.js +99 -0
- package/dist/esm/selectionPlugin.js +4 -1
- package/dist/types/editor-actions/index.d.ts +5 -0
- package/dist/types/types/index.d.ts +11 -0
- package/dist/types-ts4.5/editor-actions/index.d.ts +5 -0
- package/dist/types-ts4.5/types/index.d.ts +11 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection
|
|
2
2
|
|
|
3
|
+
## 3.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`12618b43355c6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/12618b43355c6) -
|
|
8
|
+
Improve selection APIs by getting their fragment without the parent structure.
|
|
9
|
+
|
|
10
|
+
## 3.1.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [`7b86b50272e47`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7b86b50272e47) -
|
|
15
|
+
Introduce new APIs for selection: getSelectionLocalIds and getSelectionFragment
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 3.0.7
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
10
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
/**
|
|
16
|
+
* Get the slice of the document corresponding to the selection.
|
|
17
|
+
* This is similar to the prosemirror `selection.content()` - but
|
|
18
|
+
* does not include the parents (unless the result is inline)
|
|
19
|
+
*
|
|
20
|
+
* @param selection The selection to get the slice for.
|
|
21
|
+
* @returns The slice of the document corresponding to the selection.
|
|
22
|
+
*/
|
|
23
|
+
var getSlice = function getSlice(selection) {
|
|
24
|
+
var from = selection.from,
|
|
25
|
+
to = selection.to;
|
|
26
|
+
if (from === to) {
|
|
27
|
+
return _model.Fragment.empty;
|
|
28
|
+
}
|
|
29
|
+
var frag = _model.Fragment.empty;
|
|
30
|
+
var sortedRanges = (0, _toConsumableArray2.default)(selection.ranges.slice()).sort(function (a, b) {
|
|
31
|
+
return a.$from.pos - b.$from.pos;
|
|
32
|
+
});
|
|
33
|
+
var _iterator = _createForOfIteratorHelper(sortedRanges),
|
|
34
|
+
_step;
|
|
35
|
+
try {
|
|
36
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
+
var range = _step.value;
|
|
38
|
+
var $from = range.$from,
|
|
39
|
+
$to = range.$to;
|
|
40
|
+
var _to = $to.pos;
|
|
41
|
+
var depth =
|
|
42
|
+
// If we're in a text selection, and share the parent node across the anchor->head
|
|
43
|
+
// make the depth the parent node
|
|
44
|
+
selection instanceof _state.TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
|
|
45
|
+
var start = $from.start(depth);
|
|
46
|
+
var node = $from.node(depth);
|
|
47
|
+
var content = node.content.cut($from.pos - start, $to.pos - start);
|
|
48
|
+
frag = frag.append(content);
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_iterator.e(err);
|
|
52
|
+
} finally {
|
|
53
|
+
_iterator.f();
|
|
54
|
+
}
|
|
55
|
+
return frag;
|
|
56
|
+
};
|
|
57
|
+
var getSelectionFragment = exports.getSelectionFragment = function getSelectionFragment(api) {
|
|
58
|
+
return function () {
|
|
59
|
+
var _api$selection$shared, _api$core$sharedState;
|
|
60
|
+
var selection = api === null || api === void 0 || (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 || (_api$selection$shared = _api$selection$shared.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
|
|
61
|
+
var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
|
|
62
|
+
if (!selection || !schema || selection.empty) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
var slice = getSlice(selection);
|
|
66
|
+
var content = slice.content;
|
|
67
|
+
var fragment = [];
|
|
68
|
+
content.forEach(function (node) {
|
|
69
|
+
fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
|
|
70
|
+
});
|
|
71
|
+
return fragment;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
75
|
+
return function () {
|
|
76
|
+
var _api$selection$shared2, _selection;
|
|
77
|
+
var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
|
|
78
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
79
|
+
// If we have an empty selection the current state might not be correct
|
|
80
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
81
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref) {
|
|
82
|
+
var tr = _ref.tr;
|
|
83
|
+
selection = tr.selection;
|
|
84
|
+
return null;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (!selection) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (selection instanceof _state.NodeSelection) {
|
|
91
|
+
return [selection.node.attrs.localId];
|
|
92
|
+
} else if (selection.empty) {
|
|
93
|
+
return [selection.$from.parent.attrs.localId];
|
|
94
|
+
}
|
|
95
|
+
var content = getSlice(selection).content;
|
|
96
|
+
var ids = [];
|
|
97
|
+
content.forEach(function (node) {
|
|
98
|
+
var _node$attrs;
|
|
99
|
+
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
100
|
+
if (localId) {
|
|
101
|
+
ids.push(localId);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return ids;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.selectionPlugin = exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _editorActions = require("./editor-actions");
|
|
9
10
|
var _autoExpandSelectionRangeOnInlineNodeMain = require("./pm-plugins/auto-expand-selection-range-on-inline-node-main");
|
|
10
11
|
var _commands = require("./pm-plugins/commands");
|
|
11
12
|
var _gapCursorKeymap = _interopRequireDefault(require("./pm-plugins/gap-cursor-keymap"));
|
|
@@ -65,7 +66,9 @@ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref4)
|
|
|
65
66
|
tr: state.tr
|
|
66
67
|
}) || state.tr;
|
|
67
68
|
};
|
|
68
|
-
}
|
|
69
|
+
},
|
|
70
|
+
getSelectionFragment: (0, _editorActions.getSelectionFragment)(api),
|
|
71
|
+
getSelectionLocalIds: (0, _editorActions.getSelectionLocalIds)(api)
|
|
69
72
|
},
|
|
70
73
|
getSharedState: function getSharedState(editorState) {
|
|
71
74
|
if (!editorState) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
/**
|
|
5
|
+
* Get the slice of the document corresponding to the selection.
|
|
6
|
+
* This is similar to the prosemirror `selection.content()` - but
|
|
7
|
+
* does not include the parents (unless the result is inline)
|
|
8
|
+
*
|
|
9
|
+
* @param selection The selection to get the slice for.
|
|
10
|
+
* @returns The slice of the document corresponding to the selection.
|
|
11
|
+
*/
|
|
12
|
+
const getSlice = selection => {
|
|
13
|
+
const {
|
|
14
|
+
from,
|
|
15
|
+
to
|
|
16
|
+
} = selection;
|
|
17
|
+
if (from === to) {
|
|
18
|
+
return Fragment.empty;
|
|
19
|
+
}
|
|
20
|
+
let frag = Fragment.empty;
|
|
21
|
+
const sortedRanges = [...selection.ranges.slice()].sort((a, b) => a.$from.pos - b.$from.pos);
|
|
22
|
+
for (const range of sortedRanges) {
|
|
23
|
+
const {
|
|
24
|
+
$from,
|
|
25
|
+
$to
|
|
26
|
+
} = range;
|
|
27
|
+
const to = $to.pos;
|
|
28
|
+
const depth =
|
|
29
|
+
// If we're in a text selection, and share the parent node across the anchor->head
|
|
30
|
+
// make the depth the parent node
|
|
31
|
+
selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(to) - 1) : $from.sharedDepth(to);
|
|
32
|
+
const start = $from.start(depth);
|
|
33
|
+
const node = $from.node(depth);
|
|
34
|
+
const content = node.content.cut($from.pos - start, $to.pos - start);
|
|
35
|
+
frag = frag.append(content);
|
|
36
|
+
}
|
|
37
|
+
return frag;
|
|
38
|
+
};
|
|
39
|
+
export const getSelectionFragment = api => () => {
|
|
40
|
+
var _api$selection$shared, _api$selection$shared2, _api$core$sharedState;
|
|
41
|
+
const selection = api === null || api === void 0 ? void 0 : (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
|
|
42
|
+
const schema = api === null || api === void 0 ? void 0 : (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
|
|
43
|
+
if (!selection || !schema || selection.empty) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const slice = getSlice(selection);
|
|
47
|
+
const content = slice.content;
|
|
48
|
+
const fragment = [];
|
|
49
|
+
content.forEach(node => {
|
|
50
|
+
fragment.push(nodeToJSON(node));
|
|
51
|
+
});
|
|
52
|
+
return fragment;
|
|
53
|
+
};
|
|
54
|
+
export const getSelectionLocalIds = api => () => {
|
|
55
|
+
var _api$selection$shared3, _api$selection$shared4, _selection;
|
|
56
|
+
let selection = api === null || api === void 0 ? void 0 : (_api$selection$shared3 = api.selection.sharedState) === null || _api$selection$shared3 === void 0 ? void 0 : (_api$selection$shared4 = _api$selection$shared3.currentState()) === null || _api$selection$shared4 === void 0 ? void 0 : _api$selection$shared4.selection;
|
|
57
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
58
|
+
// If we have an empty selection the current state might not be correct
|
|
59
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
60
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
61
|
+
tr
|
|
62
|
+
}) => {
|
|
63
|
+
selection = tr.selection;
|
|
64
|
+
return null;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!selection) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (selection instanceof NodeSelection) {
|
|
71
|
+
return [selection.node.attrs.localId];
|
|
72
|
+
} else if (selection.empty) {
|
|
73
|
+
return [selection.$from.parent.attrs.localId];
|
|
74
|
+
}
|
|
75
|
+
const content = getSlice(selection).content;
|
|
76
|
+
const ids = [];
|
|
77
|
+
content.forEach(node => {
|
|
78
|
+
var _node$attrs;
|
|
79
|
+
const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
80
|
+
if (localId) {
|
|
81
|
+
ids.push(localId);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return ids;
|
|
85
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSelectionFragment, getSelectionLocalIds } from './editor-actions';
|
|
1
2
|
import { createAutoExpandSelectionRangeOnInlineNodePlugin } from './pm-plugins/auto-expand-selection-range-on-inline-node-main';
|
|
2
3
|
import { selectNearNode } from './pm-plugins/commands';
|
|
3
4
|
import gapCursorKeymapPlugin from './pm-plugins/gap-cursor-keymap';
|
|
@@ -53,7 +54,9 @@ export const selectionPlugin = ({
|
|
|
53
54
|
return selectNearNode(selectionRelativeToNode, selection)({
|
|
54
55
|
tr: state.tr
|
|
55
56
|
}) || state.tr;
|
|
56
|
-
}
|
|
57
|
+
},
|
|
58
|
+
getSelectionFragment: getSelectionFragment(api),
|
|
59
|
+
getSelectionLocalIds: getSelectionLocalIds(api)
|
|
57
60
|
},
|
|
58
61
|
getSharedState(editorState) {
|
|
59
62
|
if (!editorState) {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
6
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
/**
|
|
9
|
+
* Get the slice of the document corresponding to the selection.
|
|
10
|
+
* This is similar to the prosemirror `selection.content()` - but
|
|
11
|
+
* does not include the parents (unless the result is inline)
|
|
12
|
+
*
|
|
13
|
+
* @param selection The selection to get the slice for.
|
|
14
|
+
* @returns The slice of the document corresponding to the selection.
|
|
15
|
+
*/
|
|
16
|
+
var getSlice = function getSlice(selection) {
|
|
17
|
+
var from = selection.from,
|
|
18
|
+
to = selection.to;
|
|
19
|
+
if (from === to) {
|
|
20
|
+
return Fragment.empty;
|
|
21
|
+
}
|
|
22
|
+
var frag = Fragment.empty;
|
|
23
|
+
var sortedRanges = _toConsumableArray(selection.ranges.slice()).sort(function (a, b) {
|
|
24
|
+
return a.$from.pos - b.$from.pos;
|
|
25
|
+
});
|
|
26
|
+
var _iterator = _createForOfIteratorHelper(sortedRanges),
|
|
27
|
+
_step;
|
|
28
|
+
try {
|
|
29
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
30
|
+
var range = _step.value;
|
|
31
|
+
var $from = range.$from,
|
|
32
|
+
$to = range.$to;
|
|
33
|
+
var _to = $to.pos;
|
|
34
|
+
var depth =
|
|
35
|
+
// If we're in a text selection, and share the parent node across the anchor->head
|
|
36
|
+
// make the depth the parent node
|
|
37
|
+
selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
|
|
38
|
+
var start = $from.start(depth);
|
|
39
|
+
var node = $from.node(depth);
|
|
40
|
+
var content = node.content.cut($from.pos - start, $to.pos - start);
|
|
41
|
+
frag = frag.append(content);
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
_iterator.e(err);
|
|
45
|
+
} finally {
|
|
46
|
+
_iterator.f();
|
|
47
|
+
}
|
|
48
|
+
return frag;
|
|
49
|
+
};
|
|
50
|
+
export var getSelectionFragment = function getSelectionFragment(api) {
|
|
51
|
+
return function () {
|
|
52
|
+
var _api$selection$shared, _api$core$sharedState;
|
|
53
|
+
var selection = api === null || api === void 0 || (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 || (_api$selection$shared = _api$selection$shared.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection;
|
|
54
|
+
var schema = api === null || api === void 0 || (_api$core$sharedState = api.core.sharedState.currentState()) === null || _api$core$sharedState === void 0 ? void 0 : _api$core$sharedState.schema;
|
|
55
|
+
if (!selection || !schema || selection.empty) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
var slice = getSlice(selection);
|
|
59
|
+
var content = slice.content;
|
|
60
|
+
var fragment = [];
|
|
61
|
+
content.forEach(function (node) {
|
|
62
|
+
fragment.push(nodeToJSON(node));
|
|
63
|
+
});
|
|
64
|
+
return fragment;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export var getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
68
|
+
return function () {
|
|
69
|
+
var _api$selection$shared2, _selection;
|
|
70
|
+
var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
|
|
71
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
72
|
+
// If we have an empty selection the current state might not be correct
|
|
73
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
74
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref) {
|
|
75
|
+
var tr = _ref.tr;
|
|
76
|
+
selection = tr.selection;
|
|
77
|
+
return null;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (!selection) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (selection instanceof NodeSelection) {
|
|
84
|
+
return [selection.node.attrs.localId];
|
|
85
|
+
} else if (selection.empty) {
|
|
86
|
+
return [selection.$from.parent.attrs.localId];
|
|
87
|
+
}
|
|
88
|
+
var content = getSlice(selection).content;
|
|
89
|
+
var ids = [];
|
|
90
|
+
content.forEach(function (node) {
|
|
91
|
+
var _node$attrs;
|
|
92
|
+
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
93
|
+
if (localId) {
|
|
94
|
+
ids.push(localId);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return ids;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { getSelectionFragment, getSelectionLocalIds } from './editor-actions';
|
|
4
5
|
import { createAutoExpandSelectionRangeOnInlineNodePlugin } from './pm-plugins/auto-expand-selection-range-on-inline-node-main';
|
|
5
6
|
import { selectNearNode as _selectNearNode } from './pm-plugins/commands';
|
|
6
7
|
import gapCursorKeymapPlugin from './pm-plugins/gap-cursor-keymap';
|
|
@@ -58,7 +59,9 @@ export var selectionPlugin = function selectionPlugin(_ref4) {
|
|
|
58
59
|
tr: state.tr
|
|
59
60
|
}) || state.tr;
|
|
60
61
|
};
|
|
61
|
-
}
|
|
62
|
+
},
|
|
63
|
+
getSelectionFragment: getSelectionFragment(api),
|
|
64
|
+
getSelectionLocalIds: getSelectionLocalIds(api)
|
|
62
65
|
},
|
|
63
66
|
getSharedState: function getSharedState(editorState) {
|
|
64
67
|
if (!editorState) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type JSONNode } from '@atlaskit/editor-json-transformer';
|
|
3
|
+
import type { SelectionPlugin } from '../selectionPluginType';
|
|
4
|
+
export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
|
|
5
|
+
export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
|
|
2
2
|
export type { SelectionPluginState } from '@atlaskit/editor-common/selection';
|
|
3
3
|
import type { LongPressSelectionPluginOptions } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
4
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
export declare const selectionPluginKey: PluginKey<any>;
|
|
@@ -15,6 +16,16 @@ export type SetSelectionRelativeToNode = (props: {
|
|
|
15
16
|
}) => (state: EditorState) => Transaction;
|
|
16
17
|
export type EditorSelectionAPI = {
|
|
17
18
|
selectNearNode: SetSelectionRelativeToNode;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the current selection fragment.
|
|
21
|
+
* @returns The current selection fragment as an array of JSON nodes.
|
|
22
|
+
*/
|
|
23
|
+
getSelectionFragment: () => JSONNode[] | null;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the current selection local IDs. This includes all local IDs
|
|
26
|
+
* @returns The current selection local IDs as an array of strings.
|
|
27
|
+
*/
|
|
28
|
+
getSelectionLocalIds: () => string[] | null;
|
|
18
29
|
};
|
|
19
30
|
export interface SelectionPluginOptions extends LongPressSelectionPluginOptions {
|
|
20
31
|
/**
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type JSONNode } from '@atlaskit/editor-json-transformer';
|
|
3
|
+
import type { SelectionPlugin } from '../selectionPluginType';
|
|
4
|
+
export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
|
|
5
|
+
export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
|
|
2
2
|
export type { SelectionPluginState } from '@atlaskit/editor-common/selection';
|
|
3
3
|
import type { LongPressSelectionPluginOptions } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
4
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
export declare const selectionPluginKey: PluginKey<any>;
|
|
@@ -15,6 +16,16 @@ export type SetSelectionRelativeToNode = (props: {
|
|
|
15
16
|
}) => (state: EditorState) => Transaction;
|
|
16
17
|
export type EditorSelectionAPI = {
|
|
17
18
|
selectNearNode: SetSelectionRelativeToNode;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the current selection fragment.
|
|
21
|
+
* @returns The current selection fragment as an array of JSON nodes.
|
|
22
|
+
*/
|
|
23
|
+
getSelectionFragment: () => JSONNode[] | null;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the current selection local IDs. This includes all local IDs
|
|
26
|
+
* @returns The current selection local IDs as an array of strings.
|
|
27
|
+
*/
|
|
28
|
+
getSelectionLocalIds: () => string[] | null;
|
|
18
29
|
};
|
|
19
30
|
export interface SelectionPluginOptions extends LongPressSelectionPluginOptions {
|
|
20
31
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Selection plugin for @atlaskit/editor-core",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -19,17 +19,18 @@
|
|
|
19
19
|
"singleton": true
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@atlaskit/editor-json-transformer": "^8.27.0",
|
|
22
23
|
"@atlaskit/editor-plugin-interaction": "^5.0.0",
|
|
23
24
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
24
25
|
"@atlaskit/editor-shared-styles": "^3.6.0",
|
|
25
26
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
26
27
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
27
|
-
"@atlaskit/tmp-editor-statsig": "^11.
|
|
28
|
+
"@atlaskit/tmp-editor-statsig": "^11.3.0",
|
|
28
29
|
"@atlaskit/tokens": "^6.0.0",
|
|
29
30
|
"@babel/runtime": "^7.0.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"@atlaskit/editor-common": "^107.
|
|
33
|
+
"@atlaskit/editor-common": "^107.27.0",
|
|
33
34
|
"react": "^18.2.0"
|
|
34
35
|
},
|
|
35
36
|
"techstack": {
|