@atlaskit/editor-plugin-selection 10.0.16 → 10.0.18
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 +12 -0
- package/dist/cjs/editor-actions/index.js +3 -115
- package/dist/es2019/editor-actions/index.js +2 -102
- package/dist/esm/editor-actions/index.js +2 -113
- package/dist/types/editor-actions/index.d.ts +1 -12
- package/dist/types-ts4.5/editor-actions/index.d.ts +1 -12
- package/package.json +3 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,106 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
6
|
+
exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
|
|
9
7
|
var _selection2 = require("@atlaskit/editor-common/selection");
|
|
10
|
-
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
11
|
-
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
12
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
-
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; } } }; }
|
|
15
|
-
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; } }
|
|
16
|
-
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; }
|
|
17
|
-
var listDepth = 3;
|
|
18
|
-
var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
|
|
19
|
-
// Block level lists
|
|
20
|
-
var listParents = ['bulletList', 'orderedList'];
|
|
21
|
-
if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
|
|
22
|
-
var _greatGrandparentFrom, _greatGrandparentFrom2;
|
|
23
|
-
// Get grandparents (from)
|
|
24
|
-
var grandparentFrom = $from.node($from.depth - 1);
|
|
25
|
-
var greatGrandparentFrom = $from.node($from.depth - 2);
|
|
26
|
-
// Get grandparents (to)
|
|
27
|
-
var grandparentTo = $to.node($from.depth - 1);
|
|
28
|
-
var greatGrandparentTo = $to.node($from.depth - 2);
|
|
29
|
-
if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
|
|
30
|
-
(_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get the slice of the document corresponding to the selection.
|
|
39
|
-
* This is similar to the prosemirror `selection.content()` - but
|
|
40
|
-
* does not include the parents (unless the result is inline)
|
|
41
|
-
*
|
|
42
|
-
* @param selection The selection to get the slice for.
|
|
43
|
-
* @returns The slice of the document corresponding to the selection.
|
|
44
|
-
*/
|
|
45
|
-
var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFromSelection(selection) {
|
|
46
|
-
var from = selection.from,
|
|
47
|
-
to = selection.to;
|
|
48
|
-
if (from === to) {
|
|
49
|
-
return _model.Fragment.empty;
|
|
50
|
-
}
|
|
51
|
-
var frag = _model.Fragment.empty;
|
|
52
|
-
var sortedRanges = (0, _toConsumableArray2.default)(selection.ranges.slice()).sort(function (a, b) {
|
|
53
|
-
return a.$from.pos - b.$from.pos;
|
|
54
|
-
});
|
|
55
|
-
var _iterator = _createForOfIteratorHelper(sortedRanges),
|
|
56
|
-
_step;
|
|
57
|
-
try {
|
|
58
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
59
|
-
var range = _step.value;
|
|
60
|
-
var $from = range.$from,
|
|
61
|
-
$to = range.$to;
|
|
62
|
-
var _to = $to.pos;
|
|
63
|
-
var depth =
|
|
64
|
-
// If we're in a text selection, and share the parent node across the anchor->head
|
|
65
|
-
// make the depth the parent node
|
|
66
|
-
selection instanceof _state.TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
|
|
67
|
-
var finalDepth = depth;
|
|
68
|
-
// For block-level lists (non-nested) specifically use the selection
|
|
69
|
-
if (selectionCoversAllListItems($from, $to)) {
|
|
70
|
-
finalDepth = $from.depth - listDepth;
|
|
71
|
-
}
|
|
72
|
-
var start = $from.start(finalDepth);
|
|
73
|
-
var node = $from.node(finalDepth);
|
|
74
|
-
var content = node.content.cut($from.pos - start, $to.pos - start);
|
|
75
|
-
frag = frag.append(content);
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_iterator.e(err);
|
|
79
|
-
} finally {
|
|
80
|
-
_iterator.f();
|
|
81
|
-
}
|
|
82
|
-
return frag;
|
|
83
|
-
};
|
|
84
8
|
var getSelectionFragment = exports.getSelectionFragment = function getSelectionFragment(api) {
|
|
85
9
|
return function () {
|
|
86
10
|
var _api$selection$shared;
|
|
87
11
|
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;
|
|
88
|
-
|
|
89
|
-
return (0, _selection2.getFragmentsFromSelection)(selection);
|
|
90
|
-
} else {
|
|
91
|
-
var _api$core$sharedState;
|
|
92
|
-
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;
|
|
93
|
-
if (!selection || !schema || selection.empty) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
var slice = getSliceFromSelection(selection);
|
|
97
|
-
var content = slice.content;
|
|
98
|
-
var fragment = [];
|
|
99
|
-
content.forEach(function (node) {
|
|
100
|
-
fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
|
|
101
|
-
});
|
|
102
|
-
return fragment;
|
|
103
|
-
}
|
|
12
|
+
return (0, _selection2.getFragmentsFromSelection)(selection);
|
|
104
13
|
};
|
|
105
14
|
};
|
|
106
15
|
var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
@@ -116,27 +25,6 @@ var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionL
|
|
|
116
25
|
return null;
|
|
117
26
|
});
|
|
118
27
|
}
|
|
119
|
-
|
|
120
|
-
return (0, _selection2.getLocalIdsFromSelection)(selection);
|
|
121
|
-
} else {
|
|
122
|
-
if (!selection) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
if (selection instanceof _state.NodeSelection) {
|
|
126
|
-
return [selection.node.attrs.localId];
|
|
127
|
-
} else if (selection.empty) {
|
|
128
|
-
return [selection.$from.parent.attrs.localId];
|
|
129
|
-
}
|
|
130
|
-
var content = getSliceFromSelection(selection).content;
|
|
131
|
-
var ids = [];
|
|
132
|
-
content.forEach(function (node) {
|
|
133
|
-
var _node$attrs;
|
|
134
|
-
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
135
|
-
if (localId) {
|
|
136
|
-
ids.push(localId);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return ids;
|
|
140
|
-
}
|
|
28
|
+
return (0, _selection2.getLocalIdsFromSelection)(selection);
|
|
141
29
|
};
|
|
142
30
|
};
|
|
@@ -1,87 +1,8 @@
|
|
|
1
1
|
import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection';
|
|
2
|
-
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
3
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
const listDepth = 3;
|
|
7
|
-
const selectionCoversAllListItems = ($from, $to) => {
|
|
8
|
-
// Block level lists
|
|
9
|
-
const listParents = ['bulletList', 'orderedList'];
|
|
10
|
-
if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
|
|
11
|
-
var _greatGrandparentFrom, _greatGrandparentFrom2;
|
|
12
|
-
// Get grandparents (from)
|
|
13
|
-
const grandparentFrom = $from.node($from.depth - 1);
|
|
14
|
-
const greatGrandparentFrom = $from.node($from.depth - 2);
|
|
15
|
-
// Get grandparents (to)
|
|
16
|
-
const grandparentTo = $to.node($from.depth - 1);
|
|
17
|
-
const greatGrandparentTo = $to.node($from.depth - 2);
|
|
18
|
-
if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
|
|
19
|
-
(_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get the slice of the document corresponding to the selection.
|
|
28
|
-
* This is similar to the prosemirror `selection.content()` - but
|
|
29
|
-
* does not include the parents (unless the result is inline)
|
|
30
|
-
*
|
|
31
|
-
* @param selection The selection to get the slice for.
|
|
32
|
-
* @returns The slice of the document corresponding to the selection.
|
|
33
|
-
*/
|
|
34
|
-
export const getSliceFromSelection = selection => {
|
|
35
|
-
const {
|
|
36
|
-
from,
|
|
37
|
-
to
|
|
38
|
-
} = selection;
|
|
39
|
-
if (from === to) {
|
|
40
|
-
return Fragment.empty;
|
|
41
|
-
}
|
|
42
|
-
let frag = Fragment.empty;
|
|
43
|
-
const sortedRanges = [...selection.ranges.slice()].sort((a, b) => a.$from.pos - b.$from.pos);
|
|
44
|
-
for (const range of sortedRanges) {
|
|
45
|
-
const {
|
|
46
|
-
$from,
|
|
47
|
-
$to
|
|
48
|
-
} = range;
|
|
49
|
-
const to = $to.pos;
|
|
50
|
-
const depth =
|
|
51
|
-
// If we're in a text selection, and share the parent node across the anchor->head
|
|
52
|
-
// make the depth the parent node
|
|
53
|
-
selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(to) - 1) : $from.sharedDepth(to);
|
|
54
|
-
let finalDepth = depth;
|
|
55
|
-
// For block-level lists (non-nested) specifically use the selection
|
|
56
|
-
if (selectionCoversAllListItems($from, $to)) {
|
|
57
|
-
finalDepth = $from.depth - listDepth;
|
|
58
|
-
}
|
|
59
|
-
const start = $from.start(finalDepth);
|
|
60
|
-
const node = $from.node(finalDepth);
|
|
61
|
-
const content = node.content.cut($from.pos - start, $to.pos - start);
|
|
62
|
-
frag = frag.append(content);
|
|
63
|
-
}
|
|
64
|
-
return frag;
|
|
65
|
-
};
|
|
66
2
|
export const getSelectionFragment = api => () => {
|
|
67
3
|
var _api$selection$shared, _api$selection$shared2;
|
|
68
4
|
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;
|
|
69
|
-
|
|
70
|
-
return getFragmentsFromSelection(selection);
|
|
71
|
-
} else {
|
|
72
|
-
var _api$core$sharedState;
|
|
73
|
-
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;
|
|
74
|
-
if (!selection || !schema || selection.empty) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
const slice = getSliceFromSelection(selection);
|
|
78
|
-
const content = slice.content;
|
|
79
|
-
const fragment = [];
|
|
80
|
-
content.forEach(node => {
|
|
81
|
-
fragment.push(nodeToJSON(node));
|
|
82
|
-
});
|
|
83
|
-
return fragment;
|
|
84
|
-
}
|
|
5
|
+
return getFragmentsFromSelection(selection);
|
|
85
6
|
};
|
|
86
7
|
export const getSelectionLocalIds = api => () => {
|
|
87
8
|
var _api$selection$shared3, _api$selection$shared4, _selection;
|
|
@@ -96,26 +17,5 @@ export const getSelectionLocalIds = api => () => {
|
|
|
96
17
|
return null;
|
|
97
18
|
});
|
|
98
19
|
}
|
|
99
|
-
|
|
100
|
-
return getLocalIdsFromSelection(selection);
|
|
101
|
-
} else {
|
|
102
|
-
if (!selection) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
if (selection instanceof NodeSelection) {
|
|
106
|
-
return [selection.node.attrs.localId];
|
|
107
|
-
} else if (selection.empty) {
|
|
108
|
-
return [selection.$from.parent.attrs.localId];
|
|
109
|
-
}
|
|
110
|
-
const content = getSliceFromSelection(selection).content;
|
|
111
|
-
const ids = [];
|
|
112
|
-
content.forEach(node => {
|
|
113
|
-
var _node$attrs;
|
|
114
|
-
const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
115
|
-
if (localId) {
|
|
116
|
-
ids.push(localId);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
return ids;
|
|
120
|
-
}
|
|
20
|
+
return getLocalIdsFromSelection(selection);
|
|
121
21
|
};
|
|
@@ -1,99 +1,9 @@
|
|
|
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
1
|
import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection';
|
|
6
|
-
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
7
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
8
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
|
-
var listDepth = 3;
|
|
11
|
-
var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
|
|
12
|
-
// Block level lists
|
|
13
|
-
var listParents = ['bulletList', 'orderedList'];
|
|
14
|
-
if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
|
|
15
|
-
var _greatGrandparentFrom, _greatGrandparentFrom2;
|
|
16
|
-
// Get grandparents (from)
|
|
17
|
-
var grandparentFrom = $from.node($from.depth - 1);
|
|
18
|
-
var greatGrandparentFrom = $from.node($from.depth - 2);
|
|
19
|
-
// Get grandparents (to)
|
|
20
|
-
var grandparentTo = $to.node($from.depth - 1);
|
|
21
|
-
var greatGrandparentTo = $to.node($from.depth - 2);
|
|
22
|
-
if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
|
|
23
|
-
(_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Get the slice of the document corresponding to the selection.
|
|
32
|
-
* This is similar to the prosemirror `selection.content()` - but
|
|
33
|
-
* does not include the parents (unless the result is inline)
|
|
34
|
-
*
|
|
35
|
-
* @param selection The selection to get the slice for.
|
|
36
|
-
* @returns The slice of the document corresponding to the selection.
|
|
37
|
-
*/
|
|
38
|
-
export var getSliceFromSelection = function getSliceFromSelection(selection) {
|
|
39
|
-
var from = selection.from,
|
|
40
|
-
to = selection.to;
|
|
41
|
-
if (from === to) {
|
|
42
|
-
return Fragment.empty;
|
|
43
|
-
}
|
|
44
|
-
var frag = Fragment.empty;
|
|
45
|
-
var sortedRanges = _toConsumableArray(selection.ranges.slice()).sort(function (a, b) {
|
|
46
|
-
return a.$from.pos - b.$from.pos;
|
|
47
|
-
});
|
|
48
|
-
var _iterator = _createForOfIteratorHelper(sortedRanges),
|
|
49
|
-
_step;
|
|
50
|
-
try {
|
|
51
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
|
-
var range = _step.value;
|
|
53
|
-
var $from = range.$from,
|
|
54
|
-
$to = range.$to;
|
|
55
|
-
var _to = $to.pos;
|
|
56
|
-
var depth =
|
|
57
|
-
// If we're in a text selection, and share the parent node across the anchor->head
|
|
58
|
-
// make the depth the parent node
|
|
59
|
-
selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
|
|
60
|
-
var finalDepth = depth;
|
|
61
|
-
// For block-level lists (non-nested) specifically use the selection
|
|
62
|
-
if (selectionCoversAllListItems($from, $to)) {
|
|
63
|
-
finalDepth = $from.depth - listDepth;
|
|
64
|
-
}
|
|
65
|
-
var start = $from.start(finalDepth);
|
|
66
|
-
var node = $from.node(finalDepth);
|
|
67
|
-
var content = node.content.cut($from.pos - start, $to.pos - start);
|
|
68
|
-
frag = frag.append(content);
|
|
69
|
-
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_iterator.e(err);
|
|
72
|
-
} finally {
|
|
73
|
-
_iterator.f();
|
|
74
|
-
}
|
|
75
|
-
return frag;
|
|
76
|
-
};
|
|
77
2
|
export var getSelectionFragment = function getSelectionFragment(api) {
|
|
78
3
|
return function () {
|
|
79
4
|
var _api$selection$shared;
|
|
80
5
|
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;
|
|
81
|
-
|
|
82
|
-
return getFragmentsFromSelection(selection);
|
|
83
|
-
} else {
|
|
84
|
-
var _api$core$sharedState;
|
|
85
|
-
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;
|
|
86
|
-
if (!selection || !schema || selection.empty) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
var slice = getSliceFromSelection(selection);
|
|
90
|
-
var content = slice.content;
|
|
91
|
-
var fragment = [];
|
|
92
|
-
content.forEach(function (node) {
|
|
93
|
-
fragment.push(nodeToJSON(node));
|
|
94
|
-
});
|
|
95
|
-
return fragment;
|
|
96
|
-
}
|
|
6
|
+
return getFragmentsFromSelection(selection);
|
|
97
7
|
};
|
|
98
8
|
};
|
|
99
9
|
export var getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
@@ -109,27 +19,6 @@ export var getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
|
109
19
|
return null;
|
|
110
20
|
});
|
|
111
21
|
}
|
|
112
|
-
|
|
113
|
-
return getLocalIdsFromSelection(selection);
|
|
114
|
-
} else {
|
|
115
|
-
if (!selection) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
if (selection instanceof NodeSelection) {
|
|
119
|
-
return [selection.node.attrs.localId];
|
|
120
|
-
} else if (selection.empty) {
|
|
121
|
-
return [selection.$from.parent.attrs.localId];
|
|
122
|
-
}
|
|
123
|
-
var content = getSliceFromSelection(selection).content;
|
|
124
|
-
var ids = [];
|
|
125
|
-
content.forEach(function (node) {
|
|
126
|
-
var _node$attrs;
|
|
127
|
-
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
128
|
-
if (localId) {
|
|
129
|
-
ids.push(localId);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return ids;
|
|
133
|
-
}
|
|
22
|
+
return getLocalIdsFromSelection(selection);
|
|
134
23
|
};
|
|
135
24
|
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import {
|
|
3
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { type Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
5
3
|
import type { SelectionPlugin } from '../selectionPluginType';
|
|
6
|
-
/**
|
|
7
|
-
* Get the slice of the document corresponding to the selection.
|
|
8
|
-
* This is similar to the prosemirror `selection.content()` - but
|
|
9
|
-
* does not include the parents (unless the result is inline)
|
|
10
|
-
*
|
|
11
|
-
* @param selection The selection to get the slice for.
|
|
12
|
-
* @returns The slice of the document corresponding to the selection.
|
|
13
|
-
*/
|
|
14
|
-
export declare const getSliceFromSelection: (selection: Selection) => Fragment;
|
|
15
4
|
export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
|
|
16
5
|
export declare const getSelectionLocalIds: (api?: ExtractInjectionAPI<SelectionPlugin>) => () => string[] | null;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import {
|
|
3
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { type Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { JSONNode } from '@atlaskit/editor-json-transformer';
|
|
5
3
|
import type { SelectionPlugin } from '../selectionPluginType';
|
|
6
|
-
/**
|
|
7
|
-
* Get the slice of the document corresponding to the selection.
|
|
8
|
-
* This is similar to the prosemirror `selection.content()` - but
|
|
9
|
-
* does not include the parents (unless the result is inline)
|
|
10
|
-
*
|
|
11
|
-
* @param selection The selection to get the slice for.
|
|
12
|
-
* @returns The slice of the document corresponding to the selection.
|
|
13
|
-
*/
|
|
14
|
-
export declare const getSliceFromSelection: (selection: Selection) => Fragment;
|
|
15
4
|
export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
|
|
16
5
|
export declare const getSelectionLocalIds: (api?: ExtractInjectionAPI<SelectionPlugin>) => () => string[] | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.18",
|
|
4
4
|
"description": "Selection plugin for @atlaskit/editor-core",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
26
26
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
27
27
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
28
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
28
|
+
"@atlaskit/tmp-editor-statsig": "^80.0.0",
|
|
29
29
|
"@atlaskit/tokens": "^13.0.0",
|
|
30
30
|
"@babel/runtime": "^7.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@atlaskit/editor-common": "^114.
|
|
33
|
+
"@atlaskit/editor-common": "^114.30.0",
|
|
34
34
|
"react": "^18.2.0"
|
|
35
35
|
},
|
|
36
36
|
"techstack": {
|
|
@@ -73,10 +73,5 @@
|
|
|
73
73
|
"no-unused-dependencies": {
|
|
74
74
|
"checkDevDependencies": true
|
|
75
75
|
}
|
|
76
|
-
},
|
|
77
|
-
"platform-feature-flags": {
|
|
78
|
-
"platform_editor_renderer_selection_context": {
|
|
79
|
-
"type": "boolean"
|
|
80
|
-
}
|
|
81
76
|
}
|
|
82
77
|
}
|