@atlaskit/editor-plugin-block-menu 1.0.6 → 1.0.7
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/container-transforms.js +45 -21
- package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +5 -0
- package/dist/es2019/editor-commands/transforms/container-transforms.js +43 -21
- package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +7 -2
- package/dist/esm/editor-commands/transforms/container-transforms.js +45 -21
- package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +7 -2
- 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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 1.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`34871606f04ba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/34871606f04ba) -
|
|
8
|
+
[ux] Updates unwrapAndConvertToList to support codeBlock to list case and cases where contnent is
|
|
9
|
+
not textblock.
|
|
10
|
+
|
|
3
11
|
## 1.0.6
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -171,18 +171,16 @@ var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAnd
|
|
|
171
171
|
sourcePos = _ref3.sourcePos,
|
|
172
172
|
targetNodeType = _ref3.targetNodeType,
|
|
173
173
|
targetAttrs = _ref3.targetAttrs;
|
|
174
|
-
if (sourcePos === null) {
|
|
175
|
-
return tr;
|
|
176
|
-
}
|
|
177
174
|
var schema = tr.doc.type.schema;
|
|
178
175
|
var _schema$nodes2 = schema.nodes,
|
|
179
176
|
listItem = _schema$nodes2.listItem,
|
|
180
177
|
paragraph = _schema$nodes2.paragraph,
|
|
181
178
|
taskList = _schema$nodes2.taskList,
|
|
182
|
-
taskItem = _schema$nodes2.taskItem
|
|
179
|
+
taskItem = _schema$nodes2.taskItem,
|
|
180
|
+
heading = _schema$nodes2.heading;
|
|
183
181
|
var isTargetTaskList = targetNodeType === taskList;
|
|
184
|
-
var createListItemFromInline = function createListItemFromInline(
|
|
185
|
-
return isTargetTaskList ? taskItem.create(null,
|
|
182
|
+
var createListItemFromInline = function createListItemFromInline(content) {
|
|
183
|
+
return isTargetTaskList ? taskItem.create(null, content) : listItem.create(null, paragraph.create(null, content));
|
|
186
184
|
};
|
|
187
185
|
var getInlineContent = function getInlineContent(textblock) {
|
|
188
186
|
var inlineContent = [];
|
|
@@ -191,30 +189,56 @@ var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAnd
|
|
|
191
189
|
});
|
|
192
190
|
return inlineContent;
|
|
193
191
|
};
|
|
194
|
-
var
|
|
195
|
-
|
|
192
|
+
var resultContent = [];
|
|
193
|
+
var currentListItems = [];
|
|
194
|
+
var targetListItemType = isTargetTaskList ? taskItem : listItem;
|
|
196
195
|
// Expand's title should become the first item of the list
|
|
197
196
|
if (sourceNode.type.name === 'expand') {
|
|
198
197
|
var _sourceNode$attrs2;
|
|
199
198
|
var title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
200
199
|
if (title) {
|
|
201
200
|
var titleContent = schema.text(title);
|
|
202
|
-
|
|
201
|
+
currentListItems.push(createListItemFromInline(titleContent));
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
var createListAndAddToContent = function createListAndAddToContent() {
|
|
205
|
+
if (currentListItems.length) {
|
|
206
|
+
var currentList = targetNodeType.create(targetAttrs || null, _model.Fragment.from(currentListItems));
|
|
207
|
+
currentListItems = [];
|
|
208
|
+
resultContent.push(currentList);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
if (sourceNode.type.name === 'codeBlock') {
|
|
212
|
+
var codeText = sourceNode.textContent;
|
|
213
|
+
if (codeText) {
|
|
214
|
+
var lines = codeText.split('\n');
|
|
215
|
+
// Remove empty lines
|
|
216
|
+
var nonEmptyLines = lines.filter(function (line) {
|
|
217
|
+
return line.trim().length > 0;
|
|
218
|
+
});
|
|
219
|
+
nonEmptyLines.forEach(function (line) {
|
|
220
|
+
var lineText = schema.text(line);
|
|
221
|
+
currentListItems.push(createListItemFromInline(lineText));
|
|
222
|
+
});
|
|
211
223
|
}
|
|
212
|
-
|
|
213
|
-
|
|
224
|
+
} else {
|
|
225
|
+
sourceNode.forEach(function (child) {
|
|
226
|
+
if (targetListItemType.validContent(_model.Fragment.from(child))) {
|
|
227
|
+
currentListItems.push(targetListItemType.create(null, child));
|
|
228
|
+
} else if (heading === child.type || isTargetTaskList && paragraph === child.type) {
|
|
229
|
+
var inline = _model.Fragment.from(getInlineContent(child));
|
|
230
|
+
currentListItems.push(createListItemFromInline(inline));
|
|
231
|
+
} else {
|
|
232
|
+
// Create list and add list first
|
|
233
|
+
createListAndAddToContent();
|
|
234
|
+
// Then add content that can't be converted into listItem
|
|
235
|
+
resultContent.push(child);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
214
238
|
}
|
|
215
|
-
if (!
|
|
216
|
-
return
|
|
239
|
+
if (!resultContent.length && !currentListItems.length) {
|
|
240
|
+
return null;
|
|
217
241
|
}
|
|
218
|
-
|
|
219
|
-
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize,
|
|
242
|
+
createListAndAddToContent();
|
|
243
|
+
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, _model.Fragment.from(resultContent));
|
|
220
244
|
};
|
|
@@ -47,6 +47,11 @@ function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
|
47
47
|
if ((0, _utils.isLayoutNodeType)(targetNodeType)) {
|
|
48
48
|
return (0, _layoutTransforms.convertToLayout)(transformationContext);
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
// special case codeblock to listType
|
|
52
|
+
if (sourceNode.type.name === 'codeBlock' && (0, _utils.isListNodeType)(targetNodeType)) {
|
|
53
|
+
return (0, _containerTransforms.unwrapAndConvertToList)(transformationContext);
|
|
54
|
+
}
|
|
50
55
|
if ((0, _utils.isBlockNode)(sourceNode)) {
|
|
51
56
|
return (0, _blockTransforms.transformBlockNode)(transformationContext);
|
|
52
57
|
}
|
|
@@ -167,9 +167,6 @@ export const unwrapAndConvertToList = ({
|
|
|
167
167
|
targetNodeType,
|
|
168
168
|
targetAttrs
|
|
169
169
|
}) => {
|
|
170
|
-
if (sourcePos === null) {
|
|
171
|
-
return tr;
|
|
172
|
-
}
|
|
173
170
|
const {
|
|
174
171
|
schema
|
|
175
172
|
} = tr.doc.type;
|
|
@@ -177,11 +174,12 @@ export const unwrapAndConvertToList = ({
|
|
|
177
174
|
listItem,
|
|
178
175
|
paragraph,
|
|
179
176
|
taskList,
|
|
180
|
-
taskItem
|
|
177
|
+
taskItem,
|
|
178
|
+
heading
|
|
181
179
|
} = schema.nodes;
|
|
182
180
|
const isTargetTaskList = targetNodeType === taskList;
|
|
183
|
-
const createListItemFromInline =
|
|
184
|
-
return isTargetTaskList ? taskItem.create(null,
|
|
181
|
+
const createListItemFromInline = content => {
|
|
182
|
+
return isTargetTaskList ? taskItem.create(null, content) : listItem.create(null, paragraph.create(null, content));
|
|
185
183
|
};
|
|
186
184
|
const getInlineContent = textblock => {
|
|
187
185
|
const inlineContent = [];
|
|
@@ -190,30 +188,54 @@ export const unwrapAndConvertToList = ({
|
|
|
190
188
|
});
|
|
191
189
|
return inlineContent;
|
|
192
190
|
};
|
|
193
|
-
const
|
|
194
|
-
|
|
191
|
+
const resultContent = [];
|
|
192
|
+
let currentListItems = [];
|
|
193
|
+
const targetListItemType = isTargetTaskList ? taskItem : listItem;
|
|
195
194
|
// Expand's title should become the first item of the list
|
|
196
195
|
if (sourceNode.type.name === 'expand') {
|
|
197
196
|
var _sourceNode$attrs2;
|
|
198
197
|
const title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
199
198
|
if (title) {
|
|
200
199
|
const titleContent = schema.text(title);
|
|
201
|
-
|
|
200
|
+
currentListItems.push(createListItemFromInline(titleContent));
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
const createListAndAddToContent = () => {
|
|
204
|
+
if (currentListItems.length) {
|
|
205
|
+
const currentList = targetNodeType.create(targetAttrs || null, Fragment.from(currentListItems));
|
|
206
|
+
currentListItems = [];
|
|
207
|
+
resultContent.push(currentList);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
if (sourceNode.type.name === 'codeBlock') {
|
|
211
|
+
const codeText = sourceNode.textContent;
|
|
212
|
+
if (codeText) {
|
|
213
|
+
const lines = codeText.split('\n');
|
|
214
|
+
// Remove empty lines
|
|
215
|
+
const nonEmptyLines = lines.filter(line => line.trim().length > 0);
|
|
216
|
+
nonEmptyLines.forEach(line => {
|
|
217
|
+
const lineText = schema.text(line);
|
|
218
|
+
currentListItems.push(createListItemFromInline(lineText));
|
|
219
|
+
});
|
|
210
220
|
}
|
|
211
|
-
|
|
212
|
-
|
|
221
|
+
} else {
|
|
222
|
+
sourceNode.forEach(child => {
|
|
223
|
+
if (targetListItemType.validContent(Fragment.from(child))) {
|
|
224
|
+
currentListItems.push(targetListItemType.create(null, child));
|
|
225
|
+
} else if (heading === child.type || isTargetTaskList && paragraph === child.type) {
|
|
226
|
+
const inline = Fragment.from(getInlineContent(child));
|
|
227
|
+
currentListItems.push(createListItemFromInline(inline));
|
|
228
|
+
} else {
|
|
229
|
+
// Create list and add list first
|
|
230
|
+
createListAndAddToContent();
|
|
231
|
+
// Then add content that can't be converted into listItem
|
|
232
|
+
resultContent.push(child);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
213
235
|
}
|
|
214
|
-
if (!
|
|
215
|
-
return
|
|
236
|
+
if (!resultContent.length && !currentListItems.length) {
|
|
237
|
+
return null;
|
|
216
238
|
}
|
|
217
|
-
|
|
218
|
-
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize,
|
|
239
|
+
createListAndAddToContent();
|
|
240
|
+
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, Fragment.from(resultContent));
|
|
219
241
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { transformBlockNode } from './block-transforms';
|
|
2
|
-
import { transformContainerNode } from './container-transforms';
|
|
2
|
+
import { transformContainerNode, unwrapAndConvertToList } from './container-transforms';
|
|
3
3
|
import { convertToLayout } from './layout-transforms';
|
|
4
4
|
import { transformListNode } from './list-transforms';
|
|
5
|
-
import { getTargetNodeInfo, isBlockNode, isListNode, isContainerNode, isLayoutNodeType } from './utils';
|
|
5
|
+
import { getTargetNodeInfo, isBlockNode, isListNode, isListNodeType, isContainerNode, isLayoutNodeType } from './utils';
|
|
6
6
|
export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
7
7
|
const {
|
|
8
8
|
nodes
|
|
@@ -45,6 +45,11 @@ export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType)
|
|
|
45
45
|
if (isLayoutNodeType(targetNodeType)) {
|
|
46
46
|
return convertToLayout(transformationContext);
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
// special case codeblock to listType
|
|
50
|
+
if (sourceNode.type.name === 'codeBlock' && isListNodeType(targetNodeType)) {
|
|
51
|
+
return unwrapAndConvertToList(transformationContext);
|
|
52
|
+
}
|
|
48
53
|
if (isBlockNode(sourceNode)) {
|
|
49
54
|
return transformBlockNode(transformationContext);
|
|
50
55
|
}
|
|
@@ -164,18 +164,16 @@ export var unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
|
|
|
164
164
|
sourcePos = _ref3.sourcePos,
|
|
165
165
|
targetNodeType = _ref3.targetNodeType,
|
|
166
166
|
targetAttrs = _ref3.targetAttrs;
|
|
167
|
-
if (sourcePos === null) {
|
|
168
|
-
return tr;
|
|
169
|
-
}
|
|
170
167
|
var schema = tr.doc.type.schema;
|
|
171
168
|
var _schema$nodes2 = schema.nodes,
|
|
172
169
|
listItem = _schema$nodes2.listItem,
|
|
173
170
|
paragraph = _schema$nodes2.paragraph,
|
|
174
171
|
taskList = _schema$nodes2.taskList,
|
|
175
|
-
taskItem = _schema$nodes2.taskItem
|
|
172
|
+
taskItem = _schema$nodes2.taskItem,
|
|
173
|
+
heading = _schema$nodes2.heading;
|
|
176
174
|
var isTargetTaskList = targetNodeType === taskList;
|
|
177
|
-
var createListItemFromInline = function createListItemFromInline(
|
|
178
|
-
return isTargetTaskList ? taskItem.create(null,
|
|
175
|
+
var createListItemFromInline = function createListItemFromInline(content) {
|
|
176
|
+
return isTargetTaskList ? taskItem.create(null, content) : listItem.create(null, paragraph.create(null, content));
|
|
179
177
|
};
|
|
180
178
|
var getInlineContent = function getInlineContent(textblock) {
|
|
181
179
|
var inlineContent = [];
|
|
@@ -184,30 +182,56 @@ export var unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
|
|
|
184
182
|
});
|
|
185
183
|
return inlineContent;
|
|
186
184
|
};
|
|
187
|
-
var
|
|
188
|
-
|
|
185
|
+
var resultContent = [];
|
|
186
|
+
var currentListItems = [];
|
|
187
|
+
var targetListItemType = isTargetTaskList ? taskItem : listItem;
|
|
189
188
|
// Expand's title should become the first item of the list
|
|
190
189
|
if (sourceNode.type.name === 'expand') {
|
|
191
190
|
var _sourceNode$attrs2;
|
|
192
191
|
var title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
|
|
193
192
|
if (title) {
|
|
194
193
|
var titleContent = schema.text(title);
|
|
195
|
-
|
|
194
|
+
currentListItems.push(createListItemFromInline(titleContent));
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
var createListAndAddToContent = function createListAndAddToContent() {
|
|
198
|
+
if (currentListItems.length) {
|
|
199
|
+
var currentList = targetNodeType.create(targetAttrs || null, Fragment.from(currentListItems));
|
|
200
|
+
currentListItems = [];
|
|
201
|
+
resultContent.push(currentList);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
if (sourceNode.type.name === 'codeBlock') {
|
|
205
|
+
var codeText = sourceNode.textContent;
|
|
206
|
+
if (codeText) {
|
|
207
|
+
var lines = codeText.split('\n');
|
|
208
|
+
// Remove empty lines
|
|
209
|
+
var nonEmptyLines = lines.filter(function (line) {
|
|
210
|
+
return line.trim().length > 0;
|
|
211
|
+
});
|
|
212
|
+
nonEmptyLines.forEach(function (line) {
|
|
213
|
+
var lineText = schema.text(line);
|
|
214
|
+
currentListItems.push(createListItemFromInline(lineText));
|
|
215
|
+
});
|
|
204
216
|
}
|
|
205
|
-
|
|
206
|
-
|
|
217
|
+
} else {
|
|
218
|
+
sourceNode.forEach(function (child) {
|
|
219
|
+
if (targetListItemType.validContent(Fragment.from(child))) {
|
|
220
|
+
currentListItems.push(targetListItemType.create(null, child));
|
|
221
|
+
} else if (heading === child.type || isTargetTaskList && paragraph === child.type) {
|
|
222
|
+
var inline = Fragment.from(getInlineContent(child));
|
|
223
|
+
currentListItems.push(createListItemFromInline(inline));
|
|
224
|
+
} else {
|
|
225
|
+
// Create list and add list first
|
|
226
|
+
createListAndAddToContent();
|
|
227
|
+
// Then add content that can't be converted into listItem
|
|
228
|
+
resultContent.push(child);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
207
231
|
}
|
|
208
|
-
if (!
|
|
209
|
-
return
|
|
232
|
+
if (!resultContent.length && !currentListItems.length) {
|
|
233
|
+
return null;
|
|
210
234
|
}
|
|
211
|
-
|
|
212
|
-
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize,
|
|
235
|
+
createListAndAddToContent();
|
|
236
|
+
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, Fragment.from(resultContent));
|
|
213
237
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { transformBlockNode } from './block-transforms';
|
|
2
|
-
import { transformContainerNode } from './container-transforms';
|
|
2
|
+
import { transformContainerNode, unwrapAndConvertToList } from './container-transforms';
|
|
3
3
|
import { convertToLayout } from './layout-transforms';
|
|
4
4
|
import { transformListNode } from './list-transforms';
|
|
5
|
-
import { getTargetNodeInfo, isBlockNode, isListNode, isContainerNode, isLayoutNodeType } from './utils';
|
|
5
|
+
import { getTargetNodeInfo, isBlockNode, isListNode, isListNodeType, isContainerNode, isLayoutNodeType } from './utils';
|
|
6
6
|
export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
7
7
|
var nodes = tr.doc.type.schema.nodes;
|
|
8
8
|
var targetNodeInfo = getTargetNodeInfo(targetType, nodes);
|
|
@@ -41,6 +41,11 @@ export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType)
|
|
|
41
41
|
if (isLayoutNodeType(targetNodeType)) {
|
|
42
42
|
return convertToLayout(transformationContext);
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
// special case codeblock to listType
|
|
46
|
+
if (sourceNode.type.name === 'codeBlock' && isListNodeType(targetNodeType)) {
|
|
47
|
+
return unwrapAndConvertToList(transformationContext);
|
|
48
|
+
}
|
|
44
49
|
if (isBlockNode(sourceNode)) {
|
|
45
50
|
return transformBlockNode(transformationContext);
|
|
46
51
|
}
|
|
@@ -14,4 +14,4 @@ export declare const unwrapAndConvertToBlockType: (context: TransformContext) =>
|
|
|
14
14
|
/**
|
|
15
15
|
* Unwrap container node and convert content to list
|
|
16
16
|
*/
|
|
17
|
-
export declare const unwrapAndConvertToList: ({ tr, sourceNode, sourcePos, targetNodeType, targetAttrs, }: TransformContext) => import("prosemirror-state").Transaction;
|
|
17
|
+
export declare const unwrapAndConvertToList: ({ tr, sourceNode, sourcePos, targetNodeType, targetAttrs, }: TransformContext) => import("prosemirror-state").Transaction | null;
|
|
@@ -14,4 +14,4 @@ export declare const unwrapAndConvertToBlockType: (context: TransformContext) =>
|
|
|
14
14
|
/**
|
|
15
15
|
* Unwrap container node and convert content to list
|
|
16
16
|
*/
|
|
17
|
-
export declare const unwrapAndConvertToList: ({ tr, sourceNode, sourcePos, targetNodeType, targetAttrs, }: TransformContext) => import("prosemirror-state").Transaction;
|
|
17
|
+
export declare const unwrapAndConvertToList: ({ tr, sourceNode, sourcePos, targetNodeType, targetAttrs, }: TransformContext) => import("prosemirror-state").Transaction | null;
|