@atlaskit/editor-plugin-block-menu 5.1.0 → 5.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 +8 -0
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +4 -2
- package/dist/cjs/editor-commands/transformNode.js +31 -15
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +4 -2
- package/dist/es2019/editor-commands/transformNode.js +33 -17
- package/dist/esm/editor-commands/transform-node-utils/utils.js +4 -2
- package/dist/esm/editor-commands/transformNode.js +31 -15
- package/dist/types/editor-commands/transformNode.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transformNode.d.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`55bf82f6468ac`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/55bf82f6468ac) -
|
|
8
|
+
Update transformNode command to work with preservedSelection
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 5.1.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -16,10 +16,12 @@ var getSelectedNode = exports.getSelectedNode = function getSelectedNode(selecti
|
|
|
16
16
|
// ?
|
|
17
17
|
depth: selection.$from.depth
|
|
18
18
|
};
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
|
+
if (selection instanceof _editorTables.CellSelection) {
|
|
20
21
|
var tableSelected = (0, _utils.findParentNodeOfType)(selection.$from.doc.type.schema.nodes.table)(selection);
|
|
21
22
|
return tableSelected;
|
|
22
|
-
}
|
|
23
|
+
}
|
|
24
|
+
if (selection instanceof _state.TextSelection) {
|
|
23
25
|
var _selection$$from$doc$ = selection.$from.doc.type.schema.nodes,
|
|
24
26
|
blockquote = _selection$$from$doc$.blockquote,
|
|
25
27
|
bulletList = _selection$$from$doc$.bulletList,
|
|
@@ -4,30 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transformNode = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
8
|
var _transform = require("./transform-node-utils/transform");
|
|
9
|
-
var transformNode = exports.transformNode =
|
|
10
|
-
// eslint-disable-next-line no-unused-vars
|
|
11
|
-
function transformNode(api) {
|
|
9
|
+
var transformNode = exports.transformNode = function transformNode(api) {
|
|
12
10
|
return (
|
|
13
11
|
// eslint-disable-next-line no-unused-vars
|
|
14
12
|
function (targetType, analyticsAttrs) {
|
|
15
13
|
return function (_ref) {
|
|
14
|
+
var _api$blockControls;
|
|
16
15
|
var tr = _ref.tr;
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
if (!source) {
|
|
16
|
+
var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
|
|
17
|
+
if (!preservedSelection) {
|
|
20
18
|
return tr;
|
|
21
19
|
}
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
var from = preservedSelection.from,
|
|
21
|
+
to = preservedSelection.to,
|
|
22
|
+
$from = preservedSelection.$from;
|
|
23
|
+
var selectedParent = $from.parent;
|
|
24
|
+
var fragment = _model.Fragment.empty;
|
|
25
|
+
// top level selections can safely be transformed without checking for depth
|
|
26
|
+
var isWithinSelectedRange = $from.depth === 0;
|
|
27
|
+
tr.doc.nodesBetween(from, to, function (node) {
|
|
28
|
+
// need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
|
|
29
|
+
if (!isWithinSelectedRange && node.eq(selectedParent)) {
|
|
30
|
+
isWithinSelectedRange = true;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (isWithinSelectedRange) {
|
|
34
|
+
var outputNode = (0, _transform.getOutputNodes)({
|
|
35
|
+
sourceNode: node,
|
|
36
|
+
targetNodeType: targetType,
|
|
37
|
+
schema: tr.doc.type.schema
|
|
38
|
+
});
|
|
39
|
+
if (outputNode) {
|
|
40
|
+
fragment = fragment.append(_model.Fragment.fromArray(outputNode));
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
26
45
|
});
|
|
27
|
-
|
|
28
|
-
return tr;
|
|
29
|
-
}
|
|
30
|
-
tr.replaceWith(source.pos, source.pos + source.node.nodeSize, outputNodes);
|
|
46
|
+
tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
|
|
31
47
|
return tr;
|
|
32
48
|
};
|
|
33
49
|
}
|
|
@@ -10,10 +10,12 @@ export const getSelectedNode = selection => {
|
|
|
10
10
|
// ?
|
|
11
11
|
depth: selection.$from.depth
|
|
12
12
|
};
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
if (selection instanceof CellSelection) {
|
|
14
15
|
const tableSelected = findParentNodeOfType(selection.$from.doc.type.schema.nodes.table)(selection);
|
|
15
16
|
return tableSelected;
|
|
16
|
-
}
|
|
17
|
+
}
|
|
18
|
+
if (selection instanceof TextSelection) {
|
|
17
19
|
const {
|
|
18
20
|
blockquote,
|
|
19
21
|
bulletList,
|
|
@@ -1,29 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { getOutputNodes } from './transform-node-utils/transform';
|
|
3
|
-
export const transformNode =
|
|
4
|
-
// eslint-disable-next-line no-unused-vars
|
|
5
|
-
api =>
|
|
3
|
+
export const transformNode = api =>
|
|
6
4
|
// eslint-disable-next-line no-unused-vars
|
|
7
5
|
(targetType, analyticsAttrs) => {
|
|
8
6
|
return ({
|
|
9
7
|
tr
|
|
10
8
|
}) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const source = getSelectedNode(selection);
|
|
15
|
-
if (!source) {
|
|
9
|
+
var _api$blockControls, _api$blockControls$sh;
|
|
10
|
+
const preservedSelection = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection;
|
|
11
|
+
if (!preservedSelection) {
|
|
16
12
|
return tr;
|
|
17
13
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const {
|
|
15
|
+
from,
|
|
16
|
+
to,
|
|
17
|
+
$from
|
|
18
|
+
} = preservedSelection;
|
|
19
|
+
const selectedParent = $from.parent;
|
|
20
|
+
let fragment = Fragment.empty;
|
|
21
|
+
// top level selections can safely be transformed without checking for depth
|
|
22
|
+
let isWithinSelectedRange = $from.depth === 0;
|
|
23
|
+
tr.doc.nodesBetween(from, to, node => {
|
|
24
|
+
// need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
|
|
25
|
+
if (!isWithinSelectedRange && node.eq(selectedParent)) {
|
|
26
|
+
isWithinSelectedRange = true;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (isWithinSelectedRange) {
|
|
30
|
+
const outputNode = getOutputNodes({
|
|
31
|
+
sourceNode: node,
|
|
32
|
+
targetNodeType: targetType,
|
|
33
|
+
schema: tr.doc.type.schema
|
|
34
|
+
});
|
|
35
|
+
if (outputNode) {
|
|
36
|
+
fragment = fragment.append(Fragment.fromArray(outputNode));
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
22
41
|
});
|
|
23
|
-
|
|
24
|
-
return tr;
|
|
25
|
-
}
|
|
26
|
-
tr.replaceWith(source.pos, source.pos + source.node.nodeSize, outputNodes);
|
|
42
|
+
tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
|
|
27
43
|
return tr;
|
|
28
44
|
};
|
|
29
45
|
};
|
|
@@ -10,10 +10,12 @@ export var getSelectedNode = function getSelectedNode(selection) {
|
|
|
10
10
|
// ?
|
|
11
11
|
depth: selection.$from.depth
|
|
12
12
|
};
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
if (selection instanceof CellSelection) {
|
|
14
15
|
var tableSelected = findParentNodeOfType(selection.$from.doc.type.schema.nodes.table)(selection);
|
|
15
16
|
return tableSelected;
|
|
16
|
-
}
|
|
17
|
+
}
|
|
18
|
+
if (selection instanceof TextSelection) {
|
|
17
19
|
var _selection$$from$doc$ = selection.$from.doc.type.schema.nodes,
|
|
18
20
|
blockquote = _selection$$from$doc$.blockquote,
|
|
19
21
|
bulletList = _selection$$from$doc$.bulletList,
|
|
@@ -1,27 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { getOutputNodes } from './transform-node-utils/transform';
|
|
3
|
-
export var transformNode =
|
|
4
|
-
// eslint-disable-next-line no-unused-vars
|
|
5
|
-
function transformNode(api) {
|
|
3
|
+
export var transformNode = function transformNode(api) {
|
|
6
4
|
return (
|
|
7
5
|
// eslint-disable-next-line no-unused-vars
|
|
8
6
|
function (targetType, analyticsAttrs) {
|
|
9
7
|
return function (_ref) {
|
|
8
|
+
var _api$blockControls;
|
|
10
9
|
var tr = _ref.tr;
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
if (!source) {
|
|
10
|
+
var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
|
|
11
|
+
if (!preservedSelection) {
|
|
14
12
|
return tr;
|
|
15
13
|
}
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
var from = preservedSelection.from,
|
|
15
|
+
to = preservedSelection.to,
|
|
16
|
+
$from = preservedSelection.$from;
|
|
17
|
+
var selectedParent = $from.parent;
|
|
18
|
+
var fragment = Fragment.empty;
|
|
19
|
+
// top level selections can safely be transformed without checking for depth
|
|
20
|
+
var isWithinSelectedRange = $from.depth === 0;
|
|
21
|
+
tr.doc.nodesBetween(from, to, function (node) {
|
|
22
|
+
// need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
|
|
23
|
+
if (!isWithinSelectedRange && node.eq(selectedParent)) {
|
|
24
|
+
isWithinSelectedRange = true;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (isWithinSelectedRange) {
|
|
28
|
+
var outputNode = getOutputNodes({
|
|
29
|
+
sourceNode: node,
|
|
30
|
+
targetNodeType: targetType,
|
|
31
|
+
schema: tr.doc.type.schema
|
|
32
|
+
});
|
|
33
|
+
if (outputNode) {
|
|
34
|
+
fragment = fragment.append(Fragment.fromArray(outputNode));
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
20
39
|
});
|
|
21
|
-
|
|
22
|
-
return tr;
|
|
23
|
-
}
|
|
24
|
-
tr.replaceWith(source.pos, source.pos + source.node.nodeSize, outputNodes);
|
|
40
|
+
tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
|
|
25
41
|
return tr;
|
|
26
42
|
};
|
|
27
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
4
|
import type { TransformNodeAnalyticsAttrs } from './transforms/types';
|
|
5
5
|
export declare const transformNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: NodeType, analyticsAttrs?: TransformNodeAnalyticsAttrs) => EditorCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type
|
|
2
|
+
import { type NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
4
|
import type { TransformNodeAnalyticsAttrs } from './transforms/types';
|
|
5
5
|
export declare const transformNode: (api?: ExtractInjectionAPI<BlockMenuPlugin>) => (targetType: NodeType, analyticsAttrs?: TransformNodeAnalyticsAttrs) => EditorCommand;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
45
45
|
"@atlaskit/platform-feature-flags-react": "^0.4.0",
|
|
46
46
|
"@atlaskit/primitives": "^16.4.0",
|
|
47
|
-
"@atlaskit/tmp-editor-statsig": "^14.
|
|
47
|
+
"@atlaskit/tmp-editor-statsig": "^14.3.0",
|
|
48
48
|
"@atlaskit/tokens": "^8.4.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0"
|
|
50
50
|
},
|