@atlaskit/editor-plugin-block-menu 1.0.5 → 1.0.6
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/transforms/block-transforms.js +7 -1
- package/dist/cjs/editor-commands/transforms/container-transforms.js +83 -11
- package/dist/es2019/editor-commands/transforms/block-transforms.js +8 -2
- package/dist/es2019/editor-commands/transforms/container-transforms.js +78 -7
- package/dist/esm/editor-commands/transforms/block-transforms.js +8 -2
- package/dist/esm/editor-commands/transforms/container-transforms.js +83 -12
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.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
|
+
## 1.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`40e6bcca6edd4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/40e6bcca6edd4) -
|
|
8
|
+
[ux] ED-29146: unwrap container to block nodes
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 1.0.5
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -33,7 +33,8 @@ var transformBlockNode = exports.transformBlockNode = function transformBlockNod
|
|
|
33
33
|
var transformToBlockNode = function transformToBlockNode(context) {
|
|
34
34
|
var tr = context.tr,
|
|
35
35
|
targetNodeType = context.targetNodeType,
|
|
36
|
-
targetAttrs = context.targetAttrs
|
|
36
|
+
targetAttrs = context.targetAttrs,
|
|
37
|
+
sourceNode = context.sourceNode;
|
|
37
38
|
var selection = tr.selection,
|
|
38
39
|
doc = tr.doc;
|
|
39
40
|
var $from = selection.$from,
|
|
@@ -44,6 +45,11 @@ var transformToBlockNode = function transformToBlockNode(context) {
|
|
|
44
45
|
var node = schema.nodes.codeBlock.createChecked(undefined, textContent);
|
|
45
46
|
return tr.replaceRangeWith(selection.from, selection.to, node);
|
|
46
47
|
}
|
|
48
|
+
|
|
49
|
+
// code block acts like a container, we need to unwrap it
|
|
50
|
+
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
51
|
+
return (0, _containerTransforms.unwrapAndConvertToBlockType)(context);
|
|
52
|
+
}
|
|
47
53
|
tr.setBlockType($from.pos, $to.pos, targetNodeType, targetAttrs);
|
|
48
54
|
return tr;
|
|
49
55
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.unwrapAndConvertToList = exports.unwrapAndConvertToBlockType = exports.transformToContainer = exports.transformContainerNode = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
10
|
var _utils = require("./utils");
|
|
9
11
|
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
@@ -60,7 +62,13 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
60
62
|
|
|
61
63
|
// Transform container to block type - unwrap and convert content
|
|
62
64
|
if ((0, _utils.isBlockNodeType)(targetNodeType)) {
|
|
63
|
-
return unwrapAndConvertToBlockType(
|
|
65
|
+
return unwrapAndConvertToBlockType({
|
|
66
|
+
tr: tr,
|
|
67
|
+
sourceNode: sourceNode,
|
|
68
|
+
sourcePos: sourcePos,
|
|
69
|
+
targetNodeType: targetNodeType,
|
|
70
|
+
targetAttrs: targetAttrs
|
|
71
|
+
});
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
// Transform container to list type
|
|
@@ -85,9 +93,73 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
85
93
|
/**
|
|
86
94
|
* Unwrap container node and convert content to block type
|
|
87
95
|
*/
|
|
88
|
-
var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType() {
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType(context) {
|
|
97
|
+
var tr = context.tr,
|
|
98
|
+
targetNodeType = context.targetNodeType,
|
|
99
|
+
targetAttrs = context.targetAttrs,
|
|
100
|
+
sourceNode = context.sourceNode,
|
|
101
|
+
sourcePos = context.sourcePos;
|
|
102
|
+
var selection = tr.selection;
|
|
103
|
+
var schema = selection.$from.doc.type.schema;
|
|
104
|
+
var _schema$nodes = schema.nodes,
|
|
105
|
+
paragraph = _schema$nodes.paragraph,
|
|
106
|
+
heading = _schema$nodes.heading,
|
|
107
|
+
codeBlock = _schema$nodes.codeBlock,
|
|
108
|
+
expand = _schema$nodes.expand;
|
|
109
|
+
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
110
|
+
var sourceChildren = (0, _toConsumableArray2.default)(sourceNode.children);
|
|
111
|
+
var transformedContent = [];
|
|
112
|
+
|
|
113
|
+
// If the container is expand, we need to extract the title and convert it to a paragraph
|
|
114
|
+
// and add it to the beginning of the content
|
|
115
|
+
if (sourceNode.type === expand) {
|
|
116
|
+
var _sourceNode$attrs;
|
|
117
|
+
var title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
|
|
118
|
+
if (title) {
|
|
119
|
+
var titleContent = schema.text(title);
|
|
120
|
+
sourceChildren.unshift(paragraph.createChecked({}, titleContent));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// if the container is a code block, convert text content to multiple paragraphs
|
|
125
|
+
if (sourceNode.type === codeBlock) {
|
|
126
|
+
var codeText = sourceNode.textContent;
|
|
127
|
+
var lines = codeText.split('\n');
|
|
128
|
+
var paragraphNodes = lines.map(function (line) {
|
|
129
|
+
return paragraph.create(null, line ? schema.text(line) : null);
|
|
130
|
+
});
|
|
131
|
+
sourceChildren = paragraphNodes;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// if target node is a paragraph, just do unwrap
|
|
135
|
+
if (targetNodeType === paragraph) {
|
|
136
|
+
transformedContent = sourceChildren;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// if target node is a headings, do unwrap and convert to heading
|
|
140
|
+
if (targetNodeType === heading && targetAttrs) {
|
|
141
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
142
|
+
sourceChildren.forEach(function (node, index) {
|
|
143
|
+
if (node.isTextblock) {
|
|
144
|
+
var headingNode = heading.create({
|
|
145
|
+
level: targetHeadingLevel
|
|
146
|
+
}, node.content);
|
|
147
|
+
sourceChildren[index] = headingNode;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
transformedContent = sourceChildren;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// if target node is code block, do unwrap and convert to code block
|
|
154
|
+
if (targetNodeType === codeBlock) {
|
|
155
|
+
var codeBlockContent = sourceChildren.map(function (node) {
|
|
156
|
+
return node.content.textBetween(0, node.content.size, '\n');
|
|
157
|
+
}).join('\n');
|
|
158
|
+
transformedContent = [codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
159
|
+
}
|
|
160
|
+
var slice = new _model.Slice(_model.Fragment.fromArray(transformedContent), 0, 0);
|
|
161
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
162
|
+
return tr;
|
|
91
163
|
};
|
|
92
164
|
|
|
93
165
|
/**
|
|
@@ -103,11 +175,11 @@ var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAnd
|
|
|
103
175
|
return tr;
|
|
104
176
|
}
|
|
105
177
|
var schema = tr.doc.type.schema;
|
|
106
|
-
var _schema$
|
|
107
|
-
listItem = _schema$
|
|
108
|
-
paragraph = _schema$
|
|
109
|
-
taskList = _schema$
|
|
110
|
-
taskItem = _schema$
|
|
178
|
+
var _schema$nodes2 = schema.nodes,
|
|
179
|
+
listItem = _schema$nodes2.listItem,
|
|
180
|
+
paragraph = _schema$nodes2.paragraph,
|
|
181
|
+
taskList = _schema$nodes2.taskList,
|
|
182
|
+
taskItem = _schema$nodes2.taskItem;
|
|
111
183
|
var isTargetTaskList = targetNodeType === taskList;
|
|
112
184
|
var createListItemFromInline = function createListItemFromInline(inlineFrag) {
|
|
113
185
|
return isTargetTaskList ? taskItem.create(null, inlineFrag) : listItem.create(null, paragraph.create(null, inlineFrag));
|
|
@@ -123,8 +195,8 @@ var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAnd
|
|
|
123
195
|
|
|
124
196
|
// Expand's title should become the first item of the list
|
|
125
197
|
if (sourceNode.type.name === 'expand') {
|
|
126
|
-
var _sourceNode$
|
|
127
|
-
var title = (_sourceNode$
|
|
198
|
+
var _sourceNode$attrs2;
|
|
199
|
+
var title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
128
200
|
if (title) {
|
|
129
201
|
var titleContent = schema.text(title);
|
|
130
202
|
items.push(isTargetTaskList ? taskItem.create(null, titleContent) : listItem.create(null, paragraph.create(null, titleContent)));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { transformToContainer } from './container-transforms';
|
|
1
|
+
import { transformToContainer, unwrapAndConvertToBlockType } from './container-transforms';
|
|
2
2
|
import { getInlineNodeTextContent } from './inline-node-transforms';
|
|
3
3
|
import { transformBlockToList } from './list-transforms';
|
|
4
4
|
import { isListNodeType, isContainerNodeType, isBlockNodeType } from './utils';
|
|
@@ -31,7 +31,8 @@ const transformToBlockNode = context => {
|
|
|
31
31
|
const {
|
|
32
32
|
tr,
|
|
33
33
|
targetNodeType,
|
|
34
|
-
targetAttrs
|
|
34
|
+
targetAttrs,
|
|
35
|
+
sourceNode
|
|
35
36
|
} = context;
|
|
36
37
|
const {
|
|
37
38
|
selection,
|
|
@@ -47,6 +48,11 @@ const transformToBlockNode = context => {
|
|
|
47
48
|
const node = schema.nodes.codeBlock.createChecked(undefined, textContent);
|
|
48
49
|
return tr.replaceRangeWith(selection.from, selection.to, node);
|
|
49
50
|
}
|
|
51
|
+
|
|
52
|
+
// code block acts like a container, we need to unwrap it
|
|
53
|
+
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
54
|
+
return unwrapAndConvertToBlockType(context);
|
|
55
|
+
}
|
|
50
56
|
tr.setBlockType($from.pos, $to.pos, targetNodeType, targetAttrs);
|
|
51
57
|
return tr;
|
|
52
58
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
1
|
+
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { isBlockNodeType, isListNodeType, isContainerNodeType } from './utils';
|
|
3
3
|
const convertInvalidNodeToValidNodeType = (sourceContent, sourceNodeType, validNodeType, withMarks) => {
|
|
4
4
|
const validTransformedContent = [];
|
|
@@ -56,7 +56,13 @@ export const transformContainerNode = ({
|
|
|
56
56
|
|
|
57
57
|
// Transform container to block type - unwrap and convert content
|
|
58
58
|
if (isBlockNodeType(targetNodeType)) {
|
|
59
|
-
return unwrapAndConvertToBlockType(
|
|
59
|
+
return unwrapAndConvertToBlockType({
|
|
60
|
+
tr,
|
|
61
|
+
sourceNode,
|
|
62
|
+
sourcePos,
|
|
63
|
+
targetNodeType,
|
|
64
|
+
targetAttrs
|
|
65
|
+
});
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
// Transform container to list type
|
|
@@ -81,9 +87,74 @@ export const transformContainerNode = ({
|
|
|
81
87
|
/**
|
|
82
88
|
* Unwrap container node and convert content to block type
|
|
83
89
|
*/
|
|
84
|
-
export const unwrapAndConvertToBlockType =
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
export const unwrapAndConvertToBlockType = context => {
|
|
91
|
+
const {
|
|
92
|
+
tr,
|
|
93
|
+
targetNodeType,
|
|
94
|
+
targetAttrs,
|
|
95
|
+
sourceNode,
|
|
96
|
+
sourcePos
|
|
97
|
+
} = context;
|
|
98
|
+
const {
|
|
99
|
+
selection
|
|
100
|
+
} = tr;
|
|
101
|
+
const schema = selection.$from.doc.type.schema;
|
|
102
|
+
const {
|
|
103
|
+
paragraph,
|
|
104
|
+
heading,
|
|
105
|
+
codeBlock,
|
|
106
|
+
expand
|
|
107
|
+
} = schema.nodes;
|
|
108
|
+
const rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
109
|
+
let sourceChildren = [...sourceNode.children];
|
|
110
|
+
let transformedContent = [];
|
|
111
|
+
|
|
112
|
+
// If the container is expand, we need to extract the title and convert it to a paragraph
|
|
113
|
+
// and add it to the beginning of the content
|
|
114
|
+
if (sourceNode.type === expand) {
|
|
115
|
+
var _sourceNode$attrs;
|
|
116
|
+
const title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
|
|
117
|
+
if (title) {
|
|
118
|
+
const titleContent = schema.text(title);
|
|
119
|
+
sourceChildren.unshift(paragraph.createChecked({}, titleContent));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// if the container is a code block, convert text content to multiple paragraphs
|
|
124
|
+
if (sourceNode.type === codeBlock) {
|
|
125
|
+
const codeText = sourceNode.textContent;
|
|
126
|
+
const lines = codeText.split('\n');
|
|
127
|
+
const paragraphNodes = lines.map(line => paragraph.create(null, line ? schema.text(line) : null));
|
|
128
|
+
sourceChildren = paragraphNodes;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// if target node is a paragraph, just do unwrap
|
|
132
|
+
if (targetNodeType === paragraph) {
|
|
133
|
+
transformedContent = sourceChildren;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// if target node is a headings, do unwrap and convert to heading
|
|
137
|
+
if (targetNodeType === heading && targetAttrs) {
|
|
138
|
+
const targetHeadingLevel = targetAttrs.level;
|
|
139
|
+
sourceChildren.forEach((node, index) => {
|
|
140
|
+
if (node.isTextblock) {
|
|
141
|
+
const headingNode = heading.create({
|
|
142
|
+
level: targetHeadingLevel
|
|
143
|
+
}, node.content);
|
|
144
|
+
sourceChildren[index] = headingNode;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
transformedContent = sourceChildren;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// if target node is code block, do unwrap and convert to code block
|
|
151
|
+
if (targetNodeType === codeBlock) {
|
|
152
|
+
const codeBlockContent = sourceChildren.map(node => node.content.textBetween(0, node.content.size, '\n')).join('\n');
|
|
153
|
+
transformedContent = [codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
154
|
+
}
|
|
155
|
+
const slice = new Slice(Fragment.fromArray(transformedContent), 0, 0);
|
|
156
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
157
|
+
return tr;
|
|
87
158
|
};
|
|
88
159
|
|
|
89
160
|
/**
|
|
@@ -123,8 +194,8 @@ export const unwrapAndConvertToList = ({
|
|
|
123
194
|
|
|
124
195
|
// Expand's title should become the first item of the list
|
|
125
196
|
if (sourceNode.type.name === 'expand') {
|
|
126
|
-
var _sourceNode$
|
|
127
|
-
const title = (_sourceNode$
|
|
197
|
+
var _sourceNode$attrs2;
|
|
198
|
+
const title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
128
199
|
if (title) {
|
|
129
200
|
const titleContent = schema.text(title);
|
|
130
201
|
items.push(isTargetTaskList ? taskItem.create(null, titleContent) : listItem.create(null, paragraph.create(null, titleContent)));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { transformToContainer } from './container-transforms';
|
|
1
|
+
import { transformToContainer, unwrapAndConvertToBlockType } from './container-transforms';
|
|
2
2
|
import { getInlineNodeTextContent } from './inline-node-transforms';
|
|
3
3
|
import { transformBlockToList } from './list-transforms';
|
|
4
4
|
import { isListNodeType, isContainerNodeType, isBlockNodeType } from './utils';
|
|
@@ -28,7 +28,8 @@ export var transformBlockNode = function transformBlockNode(context) {
|
|
|
28
28
|
var transformToBlockNode = function transformToBlockNode(context) {
|
|
29
29
|
var tr = context.tr,
|
|
30
30
|
targetNodeType = context.targetNodeType,
|
|
31
|
-
targetAttrs = context.targetAttrs
|
|
31
|
+
targetAttrs = context.targetAttrs,
|
|
32
|
+
sourceNode = context.sourceNode;
|
|
32
33
|
var selection = tr.selection,
|
|
33
34
|
doc = tr.doc;
|
|
34
35
|
var $from = selection.$from,
|
|
@@ -39,6 +40,11 @@ var transformToBlockNode = function transformToBlockNode(context) {
|
|
|
39
40
|
var node = schema.nodes.codeBlock.createChecked(undefined, textContent);
|
|
40
41
|
return tr.replaceRangeWith(selection.from, selection.to, node);
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
// code block acts like a container, we need to unwrap it
|
|
45
|
+
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
46
|
+
return unwrapAndConvertToBlockType(context);
|
|
47
|
+
}
|
|
42
48
|
tr.setBlockType($from.pos, $to.pos, targetNodeType, targetAttrs);
|
|
43
49
|
return tr;
|
|
44
50
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import { isBlockNodeType, isListNodeType, isContainerNodeType } from './utils';
|
|
3
4
|
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
4
5
|
var validTransformedContent = [];
|
|
@@ -54,7 +55,13 @@ export var transformContainerNode = function transformContainerNode(_ref2) {
|
|
|
54
55
|
|
|
55
56
|
// Transform container to block type - unwrap and convert content
|
|
56
57
|
if (isBlockNodeType(targetNodeType)) {
|
|
57
|
-
return unwrapAndConvertToBlockType(
|
|
58
|
+
return unwrapAndConvertToBlockType({
|
|
59
|
+
tr: tr,
|
|
60
|
+
sourceNode: sourceNode,
|
|
61
|
+
sourcePos: sourcePos,
|
|
62
|
+
targetNodeType: targetNodeType,
|
|
63
|
+
targetAttrs: targetAttrs
|
|
64
|
+
});
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
// Transform container to list type
|
|
@@ -79,9 +86,73 @@ export var transformContainerNode = function transformContainerNode(_ref2) {
|
|
|
79
86
|
/**
|
|
80
87
|
* Unwrap container node and convert content to block type
|
|
81
88
|
*/
|
|
82
|
-
export var unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType() {
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
export var unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType(context) {
|
|
90
|
+
var tr = context.tr,
|
|
91
|
+
targetNodeType = context.targetNodeType,
|
|
92
|
+
targetAttrs = context.targetAttrs,
|
|
93
|
+
sourceNode = context.sourceNode,
|
|
94
|
+
sourcePos = context.sourcePos;
|
|
95
|
+
var selection = tr.selection;
|
|
96
|
+
var schema = selection.$from.doc.type.schema;
|
|
97
|
+
var _schema$nodes = schema.nodes,
|
|
98
|
+
paragraph = _schema$nodes.paragraph,
|
|
99
|
+
heading = _schema$nodes.heading,
|
|
100
|
+
codeBlock = _schema$nodes.codeBlock,
|
|
101
|
+
expand = _schema$nodes.expand;
|
|
102
|
+
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
103
|
+
var sourceChildren = _toConsumableArray(sourceNode.children);
|
|
104
|
+
var transformedContent = [];
|
|
105
|
+
|
|
106
|
+
// If the container is expand, we need to extract the title and convert it to a paragraph
|
|
107
|
+
// and add it to the beginning of the content
|
|
108
|
+
if (sourceNode.type === expand) {
|
|
109
|
+
var _sourceNode$attrs;
|
|
110
|
+
var title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
|
|
111
|
+
if (title) {
|
|
112
|
+
var titleContent = schema.text(title);
|
|
113
|
+
sourceChildren.unshift(paragraph.createChecked({}, titleContent));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// if the container is a code block, convert text content to multiple paragraphs
|
|
118
|
+
if (sourceNode.type === codeBlock) {
|
|
119
|
+
var codeText = sourceNode.textContent;
|
|
120
|
+
var lines = codeText.split('\n');
|
|
121
|
+
var paragraphNodes = lines.map(function (line) {
|
|
122
|
+
return paragraph.create(null, line ? schema.text(line) : null);
|
|
123
|
+
});
|
|
124
|
+
sourceChildren = paragraphNodes;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// if target node is a paragraph, just do unwrap
|
|
128
|
+
if (targetNodeType === paragraph) {
|
|
129
|
+
transformedContent = sourceChildren;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// if target node is a headings, do unwrap and convert to heading
|
|
133
|
+
if (targetNodeType === heading && targetAttrs) {
|
|
134
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
135
|
+
sourceChildren.forEach(function (node, index) {
|
|
136
|
+
if (node.isTextblock) {
|
|
137
|
+
var headingNode = heading.create({
|
|
138
|
+
level: targetHeadingLevel
|
|
139
|
+
}, node.content);
|
|
140
|
+
sourceChildren[index] = headingNode;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
transformedContent = sourceChildren;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// if target node is code block, do unwrap and convert to code block
|
|
147
|
+
if (targetNodeType === codeBlock) {
|
|
148
|
+
var codeBlockContent = sourceChildren.map(function (node) {
|
|
149
|
+
return node.content.textBetween(0, node.content.size, '\n');
|
|
150
|
+
}).join('\n');
|
|
151
|
+
transformedContent = [codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
152
|
+
}
|
|
153
|
+
var slice = new Slice(Fragment.fromArray(transformedContent), 0, 0);
|
|
154
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
155
|
+
return tr;
|
|
85
156
|
};
|
|
86
157
|
|
|
87
158
|
/**
|
|
@@ -97,11 +168,11 @@ export var unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
|
|
|
97
168
|
return tr;
|
|
98
169
|
}
|
|
99
170
|
var schema = tr.doc.type.schema;
|
|
100
|
-
var _schema$
|
|
101
|
-
listItem = _schema$
|
|
102
|
-
paragraph = _schema$
|
|
103
|
-
taskList = _schema$
|
|
104
|
-
taskItem = _schema$
|
|
171
|
+
var _schema$nodes2 = schema.nodes,
|
|
172
|
+
listItem = _schema$nodes2.listItem,
|
|
173
|
+
paragraph = _schema$nodes2.paragraph,
|
|
174
|
+
taskList = _schema$nodes2.taskList,
|
|
175
|
+
taskItem = _schema$nodes2.taskItem;
|
|
105
176
|
var isTargetTaskList = targetNodeType === taskList;
|
|
106
177
|
var createListItemFromInline = function createListItemFromInline(inlineFrag) {
|
|
107
178
|
return isTargetTaskList ? taskItem.create(null, inlineFrag) : listItem.create(null, paragraph.create(null, inlineFrag));
|
|
@@ -117,8 +188,8 @@ export var unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
|
|
|
117
188
|
|
|
118
189
|
// Expand's title should become the first item of the list
|
|
119
190
|
if (sourceNode.type.name === 'expand') {
|
|
120
|
-
var _sourceNode$
|
|
121
|
-
var title = (_sourceNode$
|
|
191
|
+
var _sourceNode$attrs2;
|
|
192
|
+
var title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
122
193
|
if (title) {
|
|
123
194
|
var titleContent = schema.text(title);
|
|
124
195
|
items.push(isTargetTaskList ? taskItem.create(null, titleContent) : listItem.create(null, paragraph.create(null, titleContent)));
|
|
@@ -10,7 +10,7 @@ export declare const transformContainerNode: TransformFunction;
|
|
|
10
10
|
/**
|
|
11
11
|
* Unwrap container node and convert content to block type
|
|
12
12
|
*/
|
|
13
|
-
export declare const unwrapAndConvertToBlockType: () =>
|
|
13
|
+
export declare const unwrapAndConvertToBlockType: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
14
14
|
/**
|
|
15
15
|
* Unwrap container node and convert content to list
|
|
16
16
|
*/
|
|
@@ -10,7 +10,7 @@ export declare const transformContainerNode: TransformFunction;
|
|
|
10
10
|
/**
|
|
11
11
|
* Unwrap container node and convert content to block type
|
|
12
12
|
*/
|
|
13
|
-
export declare const unwrapAndConvertToBlockType: () =>
|
|
13
|
+
export declare const unwrapAndConvertToBlockType: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
14
14
|
/**
|
|
15
15
|
* Unwrap container node and convert content to list
|
|
16
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@babel/runtime": "^7.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@atlaskit/editor-common": "^108.
|
|
49
|
+
"@atlaskit/editor-common": "^108.5.0",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
52
52
|
},
|