@atlaskit/editor-plugin-block-menu 3.0.1 → 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 +19 -0
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/cjs/editor-commands/transforms/layout/utils.js +102 -52
- package/dist/cjs/editor-commands/transforms/list-transforms.js +5 -52
- package/dist/cjs/editor-commands/transforms/utils.js +3 -14
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/es2019/editor-commands/transforms/layout/utils.js +93 -47
- package/dist/es2019/editor-commands/transforms/list-transforms.js +3 -54
- package/dist/es2019/editor-commands/transforms/utils.js +2 -13
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/esm/editor-commands/transforms/layout/utils.js +96 -46
- package/dist/esm/editor-commands/transforms/list-transforms.js +3 -50
- package/dist/esm/editor-commands/transforms/utils.js +2 -13
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +2 -1
- package/dist/types/editor-commands/transforms/layout/utils.d.ts +1 -1
- package/dist/types/editor-commands/transforms/layout-transforms.d.ts +1 -1
- package/dist/types/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +1 -1
- package/dist/types/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +1 -1
- package/dist/types/editor-commands/transforms/list-transforms.d.ts +2 -5
- package/dist/types/editor-commands/transforms/types.d.ts +1 -8
- package/dist/types/editor-commands/transforms/utils.d.ts +0 -4
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +2 -1
- package/dist/types-ts4.5/editor-commands/transforms/layout/utils.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transforms/layout-transforms.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +2 -5
- package/dist/types-ts4.5/editor-commands/transforms/types.d.ts +1 -8
- package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +0 -4
- package/package.json +3 -3
- package/dist/cjs/editor-commands/transforms/list/transformBetweenListTypes.js +0 -142
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +0 -144
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +0 -137
- package/dist/types/editor-commands/transforms/list/transformBetweenListTypes.d.ts +0 -18
- package/dist/types-ts4.5/editor-commands/transforms/list/transformBetweenListTypes.d.ts +0 -18
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { getSupportedListTypesSet, isBulletOrOrderedList, isTaskList } from '../utils';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Convert a block node to inline content suitable for task items
|
|
5
|
-
*/
|
|
6
|
-
const convertBlockToInlineContent = (node, schema) => {
|
|
7
|
-
const {
|
|
8
|
-
paragraph
|
|
9
|
-
} = schema.nodes;
|
|
10
|
-
if (node.type === paragraph) {
|
|
11
|
-
return [...node.content.content];
|
|
12
|
-
}
|
|
13
|
-
if (node.isBlock) {
|
|
14
|
-
const textContent = node.textContent;
|
|
15
|
-
return textContent ? [schema.text(textContent)] : [];
|
|
16
|
-
}
|
|
17
|
-
return [node];
|
|
18
|
-
};
|
|
19
|
-
export const transformListRecursively = props => {
|
|
20
|
-
const transformedItems = [];
|
|
21
|
-
const {
|
|
22
|
-
listNode,
|
|
23
|
-
isSourceBulletOrOrdered,
|
|
24
|
-
isTargetBulletOrOrdered,
|
|
25
|
-
isSourceTask,
|
|
26
|
-
isTargetTask,
|
|
27
|
-
supportedListTypes,
|
|
28
|
-
schema,
|
|
29
|
-
targetNodeType
|
|
30
|
-
} = props;
|
|
31
|
-
const {
|
|
32
|
-
taskList,
|
|
33
|
-
listItem,
|
|
34
|
-
taskItem,
|
|
35
|
-
paragraph
|
|
36
|
-
} = schema.nodes;
|
|
37
|
-
listNode.forEach(child => {
|
|
38
|
-
if (isSourceBulletOrOrdered && isTargetTask) {
|
|
39
|
-
// Convert bullet/ordered => task
|
|
40
|
-
if (child.type === listItem) {
|
|
41
|
-
const inlineContent = [];
|
|
42
|
-
const nestedTaskLists = [];
|
|
43
|
-
child.forEach(grandChild => {
|
|
44
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== taskList) {
|
|
45
|
-
nestedTaskLists.push(transformListRecursively({
|
|
46
|
-
...props,
|
|
47
|
-
listNode: grandChild
|
|
48
|
-
}));
|
|
49
|
-
} else {
|
|
50
|
-
inlineContent.push(...convertBlockToInlineContent(grandChild, schema));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (inlineContent.length > 0) {
|
|
54
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
55
|
-
}
|
|
56
|
-
transformedItems.push(...nestedTaskLists);
|
|
57
|
-
}
|
|
58
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
59
|
-
// Convert task => bullet/ordered
|
|
60
|
-
if (child.type === taskItem) {
|
|
61
|
-
const inlineContent = [...child.content.content];
|
|
62
|
-
if (inlineContent.length > 0) {
|
|
63
|
-
const paragraphNode = paragraph.create(null, inlineContent);
|
|
64
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
65
|
-
}
|
|
66
|
-
} else if (child.type === taskList) {
|
|
67
|
-
const transformedNestedList = transformListRecursively({
|
|
68
|
-
...props,
|
|
69
|
-
listNode: child
|
|
70
|
-
});
|
|
71
|
-
const lastItem = transformedItems[transformedItems.length - 1];
|
|
72
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
73
|
-
// Attach nested list to previous item
|
|
74
|
-
const updatedContent = [...lastItem.content.content, transformedNestedList];
|
|
75
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
76
|
-
} else {
|
|
77
|
-
// No previous item, flatten nested items
|
|
78
|
-
transformedItems.push(...transformedNestedList.content.content);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
82
|
-
if (child.type === listItem) {
|
|
83
|
-
const convertedNestedLists = [];
|
|
84
|
-
child.forEach(grandChild => {
|
|
85
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
86
|
-
const convertedNode = transformListRecursively({
|
|
87
|
-
...props,
|
|
88
|
-
listNode: grandChild
|
|
89
|
-
});
|
|
90
|
-
convertedNestedLists.push(convertedNode);
|
|
91
|
-
} else {
|
|
92
|
-
convertedNestedLists.push(grandChild);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return targetNodeType.create(null, transformedItems);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Transform list structure between different list types
|
|
104
|
-
*/
|
|
105
|
-
export const transformListStructure = context => {
|
|
106
|
-
const {
|
|
107
|
-
tr,
|
|
108
|
-
sourceNode,
|
|
109
|
-
sourcePos,
|
|
110
|
-
targetNodeType
|
|
111
|
-
} = context;
|
|
112
|
-
const nodes = tr.doc.type.schema.nodes;
|
|
113
|
-
try {
|
|
114
|
-
const listNode = {
|
|
115
|
-
node: sourceNode,
|
|
116
|
-
pos: sourcePos
|
|
117
|
-
};
|
|
118
|
-
const {
|
|
119
|
-
node: sourceList,
|
|
120
|
-
pos: listPos
|
|
121
|
-
} = listNode;
|
|
122
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
123
|
-
|
|
124
|
-
const isSourceBulletOrOrdered = isBulletOrOrderedList(sourceList.type);
|
|
125
|
-
const isTargetTask = isTaskList(targetNodeType);
|
|
126
|
-
const isSourceTask = isTaskList(sourceList.type);
|
|
127
|
-
const isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
128
|
-
const supportedListTypes = getSupportedListTypesSet(nodes);
|
|
129
|
-
const newList = transformListRecursively({
|
|
130
|
-
isSourceBulletOrOrdered,
|
|
131
|
-
isSourceTask,
|
|
132
|
-
isTargetBulletOrOrdered,
|
|
133
|
-
isTargetTask,
|
|
134
|
-
listNode: sourceList,
|
|
135
|
-
schema: tr.doc.type.schema,
|
|
136
|
-
supportedListTypes,
|
|
137
|
-
targetNodeType
|
|
138
|
-
});
|
|
139
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
140
|
-
return tr;
|
|
141
|
-
} catch {
|
|
142
|
-
return tr;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
-
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; }
|
|
4
|
-
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; }
|
|
5
|
-
import { getSupportedListTypesSet, isBulletOrOrderedList, isTaskList } from '../utils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Convert a block node to inline content suitable for task items
|
|
9
|
-
*/
|
|
10
|
-
var convertBlockToInlineContent = function convertBlockToInlineContent(node, schema) {
|
|
11
|
-
var paragraph = schema.nodes.paragraph;
|
|
12
|
-
if (node.type === paragraph) {
|
|
13
|
-
return _toConsumableArray(node.content.content);
|
|
14
|
-
}
|
|
15
|
-
if (node.isBlock) {
|
|
16
|
-
var textContent = node.textContent;
|
|
17
|
-
return textContent ? [schema.text(textContent)] : [];
|
|
18
|
-
}
|
|
19
|
-
return [node];
|
|
20
|
-
};
|
|
21
|
-
var _transformListRecursively = function transformListRecursively(props) {
|
|
22
|
-
var transformedItems = [];
|
|
23
|
-
var listNode = props.listNode,
|
|
24
|
-
isSourceBulletOrOrdered = props.isSourceBulletOrOrdered,
|
|
25
|
-
isTargetBulletOrOrdered = props.isTargetBulletOrOrdered,
|
|
26
|
-
isSourceTask = props.isSourceTask,
|
|
27
|
-
isTargetTask = props.isTargetTask,
|
|
28
|
-
supportedListTypes = props.supportedListTypes,
|
|
29
|
-
schema = props.schema,
|
|
30
|
-
targetNodeType = props.targetNodeType;
|
|
31
|
-
var _schema$nodes = schema.nodes,
|
|
32
|
-
taskList = _schema$nodes.taskList,
|
|
33
|
-
listItem = _schema$nodes.listItem,
|
|
34
|
-
taskItem = _schema$nodes.taskItem,
|
|
35
|
-
paragraph = _schema$nodes.paragraph;
|
|
36
|
-
listNode.forEach(function (child) {
|
|
37
|
-
if (isSourceBulletOrOrdered && isTargetTask) {
|
|
38
|
-
// Convert bullet/ordered => task
|
|
39
|
-
if (child.type === listItem) {
|
|
40
|
-
var inlineContent = [];
|
|
41
|
-
var nestedTaskLists = [];
|
|
42
|
-
child.forEach(function (grandChild) {
|
|
43
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== taskList) {
|
|
44
|
-
nestedTaskLists.push(_transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
45
|
-
listNode: grandChild
|
|
46
|
-
})));
|
|
47
|
-
} else {
|
|
48
|
-
inlineContent.push.apply(inlineContent, _toConsumableArray(convertBlockToInlineContent(grandChild, schema)));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
if (inlineContent.length > 0) {
|
|
52
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
53
|
-
}
|
|
54
|
-
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
55
|
-
}
|
|
56
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
57
|
-
// Convert task => bullet/ordered
|
|
58
|
-
if (child.type === taskItem) {
|
|
59
|
-
var _inlineContent = _toConsumableArray(child.content.content);
|
|
60
|
-
if (_inlineContent.length > 0) {
|
|
61
|
-
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
62
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
63
|
-
}
|
|
64
|
-
} else if (child.type === taskList) {
|
|
65
|
-
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
66
|
-
listNode: child
|
|
67
|
-
}));
|
|
68
|
-
var lastItem = transformedItems[transformedItems.length - 1];
|
|
69
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
70
|
-
// Attach nested list to previous item
|
|
71
|
-
var updatedContent = [].concat(_toConsumableArray(lastItem.content.content), [transformedNestedList]);
|
|
72
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
73
|
-
} else {
|
|
74
|
-
// No previous item, flatten nested items
|
|
75
|
-
transformedItems.push.apply(transformedItems, _toConsumableArray(transformedNestedList.content.content));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
79
|
-
if (child.type === listItem) {
|
|
80
|
-
var convertedNestedLists = [];
|
|
81
|
-
child.forEach(function (grandChild) {
|
|
82
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
83
|
-
var convertedNode = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
84
|
-
listNode: grandChild
|
|
85
|
-
}));
|
|
86
|
-
convertedNestedLists.push(convertedNode);
|
|
87
|
-
} else {
|
|
88
|
-
convertedNestedLists.push(grandChild);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return targetNodeType.create(null, transformedItems);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Transform list structure between different list types
|
|
100
|
-
*/
|
|
101
|
-
export { _transformListRecursively as transformListRecursively };
|
|
102
|
-
export var transformListStructure = function transformListStructure(context) {
|
|
103
|
-
var tr = context.tr,
|
|
104
|
-
sourceNode = context.sourceNode,
|
|
105
|
-
sourcePos = context.sourcePos,
|
|
106
|
-
targetNodeType = context.targetNodeType;
|
|
107
|
-
var nodes = tr.doc.type.schema.nodes;
|
|
108
|
-
try {
|
|
109
|
-
var listNode = {
|
|
110
|
-
node: sourceNode,
|
|
111
|
-
pos: sourcePos
|
|
112
|
-
};
|
|
113
|
-
var sourceList = listNode.node,
|
|
114
|
-
listPos = listNode.pos;
|
|
115
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
116
|
-
|
|
117
|
-
var isSourceBulletOrOrdered = isBulletOrOrderedList(sourceList.type);
|
|
118
|
-
var isTargetTask = isTaskList(targetNodeType);
|
|
119
|
-
var isSourceTask = isTaskList(sourceList.type);
|
|
120
|
-
var isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
121
|
-
var supportedListTypes = getSupportedListTypesSet(nodes);
|
|
122
|
-
var newList = _transformListRecursively({
|
|
123
|
-
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
124
|
-
isSourceTask: isSourceTask,
|
|
125
|
-
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
126
|
-
isTargetTask: isTargetTask,
|
|
127
|
-
listNode: sourceList,
|
|
128
|
-
schema: tr.doc.type.schema,
|
|
129
|
-
supportedListTypes: supportedListTypes,
|
|
130
|
-
targetNodeType: targetNodeType
|
|
131
|
-
});
|
|
132
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
133
|
-
return tr;
|
|
134
|
-
} catch (_unused) {
|
|
135
|
-
return tr;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import type { TransformContext } from '../types';
|
|
3
|
-
type TransformListRecursivelyProps = {
|
|
4
|
-
isSourceBulletOrOrdered: boolean;
|
|
5
|
-
isSourceTask: boolean;
|
|
6
|
-
isTargetBulletOrOrdered: boolean;
|
|
7
|
-
isTargetTask: boolean;
|
|
8
|
-
listNode: PMNode;
|
|
9
|
-
schema: Schema;
|
|
10
|
-
supportedListTypes: Set<NodeType>;
|
|
11
|
-
targetNodeType: NodeType;
|
|
12
|
-
};
|
|
13
|
-
export declare const transformListRecursively: (props: TransformListRecursivelyProps) => PMNode;
|
|
14
|
-
/**
|
|
15
|
-
* Transform list structure between different list types
|
|
16
|
-
*/
|
|
17
|
-
export declare const transformListStructure: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
18
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import type { TransformContext } from '../types';
|
|
3
|
-
type TransformListRecursivelyProps = {
|
|
4
|
-
isSourceBulletOrOrdered: boolean;
|
|
5
|
-
isSourceTask: boolean;
|
|
6
|
-
isTargetBulletOrOrdered: boolean;
|
|
7
|
-
isTargetTask: boolean;
|
|
8
|
-
listNode: PMNode;
|
|
9
|
-
schema: Schema;
|
|
10
|
-
supportedListTypes: Set<NodeType>;
|
|
11
|
-
targetNodeType: NodeType;
|
|
12
|
-
};
|
|
13
|
-
export declare const transformListRecursively: (props: TransformListRecursivelyProps) => PMNode;
|
|
14
|
-
/**
|
|
15
|
-
* Transform list structure between different list types
|
|
16
|
-
*/
|
|
17
|
-
export declare const transformListStructure: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
18
|
-
export {};
|