@atlaskit/editor-plugin-selection 3.0.7 → 3.1.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 +11 -0
- package/dist/cjs/editor-actions/index.js +57 -0
- package/dist/cjs/selectionPlugin.js +4 -1
- package/dist/es2019/editor-actions/index.js +48 -0
- package/dist/es2019/selectionPlugin.js +4 -1
- package/dist/esm/editor-actions/index.js +51 -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,16 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`7b86b50272e47`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7b86b50272e47) -
|
|
8
|
+
Introduce new APIs for selection: getSelectionLocalIds and getSelectionFragment
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 3.0.7
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
|
|
7
|
+
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var getSelectionFragment = exports.getSelectionFragment = function getSelectionFragment(api) {
|
|
10
|
+
return function () {
|
|
11
|
+
var _api$selection$shared, _api$core$sharedState;
|
|
12
|
+
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;
|
|
13
|
+
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;
|
|
14
|
+
if (!selection || !schema || selection.empty) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
var content = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
18
|
+
var fragment = [];
|
|
19
|
+
content.forEach(function (node) {
|
|
20
|
+
fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
|
|
21
|
+
});
|
|
22
|
+
return fragment;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
26
|
+
return function () {
|
|
27
|
+
var _api$selection$shared2, _selection;
|
|
28
|
+
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;
|
|
29
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
30
|
+
// If we have an empty selection the current state might not be correct
|
|
31
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
32
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref) {
|
|
33
|
+
var tr = _ref.tr;
|
|
34
|
+
selection = tr.selection;
|
|
35
|
+
return null;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!selection) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (selection instanceof _state.NodeSelection) {
|
|
42
|
+
return [selection.node.attrs.localId];
|
|
43
|
+
} else if (selection.empty) {
|
|
44
|
+
return [selection.$from.parent.attrs.localId];
|
|
45
|
+
}
|
|
46
|
+
var content = selection.content().content;
|
|
47
|
+
var ids = [];
|
|
48
|
+
content.forEach(function (node) {
|
|
49
|
+
var _node$attrs;
|
|
50
|
+
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
51
|
+
if (localId) {
|
|
52
|
+
ids.push(localId);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return ids;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -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,48 @@
|
|
|
1
|
+
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export const getSelectionFragment = api => () => {
|
|
4
|
+
var _api$selection$shared, _api$selection$shared2, _api$core$sharedState;
|
|
5
|
+
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;
|
|
6
|
+
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;
|
|
7
|
+
if (!selection || !schema || selection.empty) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const content = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
11
|
+
const fragment = [];
|
|
12
|
+
content.forEach(node => {
|
|
13
|
+
fragment.push(nodeToJSON(node));
|
|
14
|
+
});
|
|
15
|
+
return fragment;
|
|
16
|
+
};
|
|
17
|
+
export const getSelectionLocalIds = api => () => {
|
|
18
|
+
var _api$selection$shared3, _api$selection$shared4, _selection;
|
|
19
|
+
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;
|
|
20
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
21
|
+
// If we have an empty selection the current state might not be correct
|
|
22
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
23
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
24
|
+
tr
|
|
25
|
+
}) => {
|
|
26
|
+
selection = tr.selection;
|
|
27
|
+
return null;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!selection) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (selection instanceof NodeSelection) {
|
|
34
|
+
return [selection.node.attrs.localId];
|
|
35
|
+
} else if (selection.empty) {
|
|
36
|
+
return [selection.$from.parent.attrs.localId];
|
|
37
|
+
}
|
|
38
|
+
const content = selection.content().content;
|
|
39
|
+
const ids = [];
|
|
40
|
+
content.forEach(node => {
|
|
41
|
+
var _node$attrs;
|
|
42
|
+
const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
43
|
+
if (localId) {
|
|
44
|
+
ids.push(localId);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return ids;
|
|
48
|
+
};
|
|
@@ -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,51 @@
|
|
|
1
|
+
import { nodeToJSON } from '@atlaskit/editor-json-transformer';
|
|
2
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export var getSelectionFragment = function getSelectionFragment(api) {
|
|
4
|
+
return function () {
|
|
5
|
+
var _api$selection$shared, _api$core$sharedState;
|
|
6
|
+
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;
|
|
7
|
+
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;
|
|
8
|
+
if (!selection || !schema || selection.empty) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
var content = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
12
|
+
var fragment = [];
|
|
13
|
+
content.forEach(function (node) {
|
|
14
|
+
fragment.push(nodeToJSON(node));
|
|
15
|
+
});
|
|
16
|
+
return fragment;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export var getSelectionLocalIds = function getSelectionLocalIds(api) {
|
|
20
|
+
return function () {
|
|
21
|
+
var _api$selection$shared2, _selection;
|
|
22
|
+
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;
|
|
23
|
+
if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
|
|
24
|
+
// If we have an empty selection the current state might not be correct
|
|
25
|
+
// We have a hack here to retrieve the current selection - but not dispatch a transaction
|
|
26
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref) {
|
|
27
|
+
var tr = _ref.tr;
|
|
28
|
+
selection = tr.selection;
|
|
29
|
+
return null;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!selection) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (selection instanceof NodeSelection) {
|
|
36
|
+
return [selection.node.attrs.localId];
|
|
37
|
+
} else if (selection.empty) {
|
|
38
|
+
return [selection.$from.parent.attrs.localId];
|
|
39
|
+
}
|
|
40
|
+
var content = selection.content().content;
|
|
41
|
+
var ids = [];
|
|
42
|
+
content.forEach(function (node) {
|
|
43
|
+
var _node$attrs;
|
|
44
|
+
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
45
|
+
if (localId) {
|
|
46
|
+
ids.push(localId);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return ids;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -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.0
|
|
3
|
+
"version": "3.1.0",
|
|
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.26.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.26.0",
|
|
33
34
|
"react": "^18.2.0"
|
|
34
35
|
},
|
|
35
36
|
"techstack": {
|