@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,9 +1,9 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { transformListRecursively, isBulletOrOrderedList, isTaskList, getSupportedListTypesSet } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
import { getInlineNodeTextContent } from '../inline-node-transforms';
|
|
5
|
-
import {
|
|
6
|
-
import { getContentSupportChecker, getSupportedListTypesSet, isBlockNode, isBlockNodeForExtraction, isBlockNodeType, isBulletOrOrderedList, isContainerNode, isContainerNodeType, isHeadingOrParagraphNode, isListNode, isListNodeType, isTaskList } from '../utils';
|
|
6
|
+
import { getContentSupportChecker, isBlockNode, isBlockNodeForExtraction, isBlockNodeType, isContainerNode, isContainerNodeType, isHeadingOrParagraphNode, isListNode, isListNodeType } from '../utils';
|
|
7
7
|
export var unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(context, finalTargetNodeType) {
|
|
8
8
|
var tr = context.tr,
|
|
9
9
|
sourceNode = context.sourceNode,
|
|
@@ -73,57 +73,104 @@ export var unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(
|
|
|
73
73
|
}
|
|
74
74
|
return [sourceNode];
|
|
75
75
|
};
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (lastItem.canBeTransformed) {
|
|
93
|
-
newNodes[newNodes.length - 1] = {
|
|
94
|
-
content: [].concat(_toConsumableArray(lastItem.content), [inlineTextContent]),
|
|
95
|
-
canBeTransformed: true
|
|
96
|
-
};
|
|
97
|
-
} else {
|
|
98
|
-
newNodes.push({
|
|
99
|
-
content: [inlineTextContent],
|
|
100
|
-
canBeTransformed: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
76
|
+
var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
77
|
+
var newNodes = [];
|
|
78
|
+
var addToNewNodes = function addToNewNodes(content) {
|
|
79
|
+
if (newNodes.length === 0) {
|
|
80
|
+
newNodes.push({
|
|
81
|
+
canBeTransformed: true,
|
|
82
|
+
content: content
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
// Check if last node can also be transformed, if yes then append content
|
|
86
|
+
var lastItem = newNodes[newNodes.length - 1];
|
|
87
|
+
if (lastItem.canBeTransformed) {
|
|
88
|
+
newNodes[newNodes.length - 1] = {
|
|
89
|
+
content: [].concat(_toConsumableArray(lastItem.content), _toConsumableArray(content)),
|
|
90
|
+
canBeTransformed: true
|
|
91
|
+
};
|
|
104
92
|
} else {
|
|
105
|
-
// If not text block, then cannot be transformed
|
|
106
93
|
newNodes.push({
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
content: content,
|
|
95
|
+
canBeTransformed: true
|
|
109
96
|
});
|
|
110
97
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
nodes.forEach(function (node) {
|
|
101
|
+
if (node.isTextblock) {
|
|
102
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node));
|
|
103
|
+
|
|
104
|
+
// For first node, add directly
|
|
105
|
+
addToNewNodes([inlineTextContent]);
|
|
106
|
+
} else if (isListNode(node)) {
|
|
107
|
+
var textContent = [];
|
|
108
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
109
|
+
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
110
|
+
return item.node;
|
|
111
|
+
});
|
|
112
|
+
listItems.forEach(function (listItem) {
|
|
113
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
114
|
+
var _inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem));
|
|
115
|
+
textContent.push(_inlineTextContent);
|
|
116
|
+
} else {
|
|
117
|
+
var _inlineTextContent2 = getInlineNodeTextContent(listItem.content);
|
|
118
|
+
textContent.push(_inlineTextContent2);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
});
|
|
121
|
+
addToNewNodes(textContent);
|
|
122
|
+
} else {
|
|
123
|
+
// If not text block or list node, then cannot be transformed
|
|
124
|
+
newNodes.push({
|
|
125
|
+
canBeTransformed: false,
|
|
126
|
+
content: node
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return newNodes.map(function (_ref) {
|
|
131
|
+
var canBeTransformed = _ref.canBeTransformed,
|
|
132
|
+
content = _ref.content;
|
|
133
|
+
if (canBeTransformed) {
|
|
134
|
+
var text = content.join('\n');
|
|
135
|
+
if (text === '') {
|
|
136
|
+
return undefined;
|
|
123
137
|
}
|
|
124
|
-
|
|
138
|
+
return schema.nodes.codeBlock.createChecked(null, schema.text(text));
|
|
139
|
+
} else {
|
|
140
|
+
return content;
|
|
141
|
+
}
|
|
142
|
+
}).filter(Boolean);
|
|
143
|
+
};
|
|
144
|
+
var transformToBlockNode = function transformToBlockNode(nodes, targetNodeType, schema) {
|
|
145
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
146
|
+
return transformToCodeBlock(nodes, schema);
|
|
125
147
|
}
|
|
126
|
-
|
|
148
|
+
var newNodes = [];
|
|
149
|
+
nodes.forEach(function (node) {
|
|
150
|
+
if (isListNode(node)) {
|
|
151
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
152
|
+
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
153
|
+
return item.node;
|
|
154
|
+
});
|
|
155
|
+
listItems.forEach(function (listItem) {
|
|
156
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
157
|
+
var inlineContent = _toConsumableArray(listItem.content.content);
|
|
158
|
+
if (inlineContent.length > 0) {
|
|
159
|
+
newNodes.push(targetNodeType.createChecked(null, inlineContent));
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
listItem.forEach(function (child) {
|
|
163
|
+
if (isHeadingOrParagraphNode(child)) {
|
|
164
|
+
newNodes.push(targetNodeType.createChecked(null, _toConsumableArray(child.content.content)));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
newNodes.push(node);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return newNodes;
|
|
127
174
|
};
|
|
128
175
|
var transformToContainerNode = function transformToContainerNode(nodes, targetNodeType) {
|
|
129
176
|
var newNodes = [];
|
|
@@ -269,6 +316,9 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
269
316
|
});
|
|
270
317
|
};
|
|
271
318
|
export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
|
|
319
|
+
if (nodes.length === 1 && nodes[0].content.size === 0) {
|
|
320
|
+
return nodes;
|
|
321
|
+
}
|
|
272
322
|
if (isBlockNodeType(targetNodeType)) {
|
|
273
323
|
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
274
324
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { transformBetweenListTypes, isTaskList } from '@atlaskit/editor-common/transforms';
|
|
2
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
-
import { transformListStructure } from './list/transformBetweenListTypes';
|
|
5
5
|
import { transformOrderedUnorderedListToBlockNodes } from './list/transformOrderedUnorderedListToBlockNodes';
|
|
6
6
|
import { transformTaskListToBlockNodes } from './list/transformTaskListToBlockNodes';
|
|
7
7
|
import { transformToTaskList } from './list/transformToTaskList';
|
|
8
|
-
import {
|
|
8
|
+
import { isBlockNodeType, isContainerNodeType, isListNodeType } from './utils';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Transform selection to list type
|
|
@@ -152,51 +152,4 @@ export var liftListToBlockType = function liftListToBlockType() {
|
|
|
152
152
|
return null;
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
* Transform between different list types
|
|
157
|
-
*/
|
|
158
|
-
export var transformBetweenListTypes = function transformBetweenListTypes(context) {
|
|
159
|
-
var tr = context.tr,
|
|
160
|
-
sourceNode = context.sourceNode,
|
|
161
|
-
sourcePos = context.sourcePos,
|
|
162
|
-
targetNodeType = context.targetNodeType;
|
|
163
|
-
var nodes = tr.doc.type.schema.nodes;
|
|
164
|
-
var sourceListType = sourceNode.type;
|
|
165
|
-
var isSourceBulletOrOrdered = isBulletOrOrderedList(sourceListType);
|
|
166
|
-
var isTargetTask = isTaskList(targetNodeType);
|
|
167
|
-
var isSourceTask = isTaskList(sourceListType);
|
|
168
|
-
var isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
169
|
-
|
|
170
|
-
// Check if we need structure transformation
|
|
171
|
-
var needsStructureTransform = isSourceBulletOrOrdered && isTargetTask || isSourceTask && isTargetBulletOrOrdered;
|
|
172
|
-
try {
|
|
173
|
-
if (!needsStructureTransform) {
|
|
174
|
-
// Simple type change for same structure lists (bullet <-> ordered)
|
|
175
|
-
// Apply to the main list
|
|
176
|
-
tr.setNodeMarkup(sourcePos, targetNodeType);
|
|
177
|
-
|
|
178
|
-
// Apply to nested lists
|
|
179
|
-
var listStart = sourcePos;
|
|
180
|
-
var listEnd = sourcePos + sourceNode.nodeSize;
|
|
181
|
-
var supportedListTypesSet = getSupportedListTypesSet(nodes);
|
|
182
|
-
tr.doc.nodesBetween(listStart, listEnd, function (node, pos, parent) {
|
|
183
|
-
// Only process nested lists (not the root list we already handled)
|
|
184
|
-
if (supportedListTypesSet.has(node.type) && pos !== sourcePos) {
|
|
185
|
-
var isNestedList = parent && (supportedListTypesSet.has(parent.type) || parent.type === nodes.listItem);
|
|
186
|
-
if (isNestedList) {
|
|
187
|
-
var shouldTransformNode = node.type === sourceListType || isBulletOrOrderedList(node.type) && isTargetBulletOrOrdered;
|
|
188
|
-
if (shouldTransformNode) {
|
|
189
|
-
tr.setNodeMarkup(pos, targetNodeType);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return true; // Continue traversing
|
|
194
|
-
});
|
|
195
|
-
return tr;
|
|
196
|
-
} else {
|
|
197
|
-
return transformListStructure(context);
|
|
198
|
-
}
|
|
199
|
-
} catch (_unused) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
155
|
+
// transformBetweenListTypes is now imported from @atlaskit/editor-common/transforms
|
|
@@ -110,19 +110,8 @@ export var isContainerNodeType = function isContainerNodeType(nodeType) {
|
|
|
110
110
|
return ['panel', 'expand', 'blockquote'].includes(nodeType.name);
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
// List type utilities
|
|
114
|
-
|
|
115
|
-
return nodeType.name === 'bulletList' || nodeType.name === 'orderedList';
|
|
116
|
-
};
|
|
117
|
-
export var isTaskList = function isTaskList(nodeType) {
|
|
118
|
-
return nodeType.name === 'taskList';
|
|
119
|
-
};
|
|
120
|
-
export var getSupportedListTypes = function getSupportedListTypes(nodes) {
|
|
121
|
-
return [nodes.bulletList, nodes.orderedList, nodes.taskList].filter(Boolean);
|
|
122
|
-
};
|
|
123
|
-
export var getSupportedListTypesSet = function getSupportedListTypesSet(nodes) {
|
|
124
|
-
return new Set(getSupportedListTypes(nodes));
|
|
125
|
-
};
|
|
113
|
+
// List type utilities moved to @atlaskit/editor-common/transforms
|
|
114
|
+
|
|
126
115
|
export var isLayoutNodeType = function isLayoutNodeType(nodeType) {
|
|
127
116
|
return nodeType.name === 'layoutSection';
|
|
128
117
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import type { TransformContext } from '../types';
|
|
3
3
|
export declare const unwrapLayoutNodesToTextNodes: (context: TransformContext, finalTargetNodeType: NodeType) => PMNode[];
|
|
4
4
|
export declare const transformToListNode: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
5
5
|
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TransformContext } from '
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
2
|
export declare const convertToLayout: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
3
3
|
export declare const transformLayoutNode: (context: TransformContext) => import("prosemirror-state").Transaction;
|
package/dist/types/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type { TransformContext } from '.././types';
|
|
3
3
|
export declare const transformOrderedUnorderedListToBlockNodes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type { TransformContext } from '.././types';
|
|
3
3
|
export declare const transformTaskListToBlockNodes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type {
|
|
3
|
+
import type { TransformFunction } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Transform selection to list type
|
|
5
6
|
*/
|
|
@@ -20,7 +21,3 @@ export declare const transformListNode: TransformFunction;
|
|
|
20
21
|
* Lift list content and convert to block type
|
|
21
22
|
*/
|
|
22
23
|
export declare const liftListToBlockType: () => null;
|
|
23
|
-
/**
|
|
24
|
-
* Transform between different list types
|
|
25
|
-
*/
|
|
26
|
-
export declare const transformBetweenListTypes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
4
|
-
export interface TransformContext {
|
|
5
|
-
sourceNode: PMNode;
|
|
6
|
-
sourcePos: number;
|
|
7
|
-
targetAttrs?: Record<string, unknown>;
|
|
8
|
-
targetNodeType: NodeType;
|
|
9
|
-
tr: Transaction;
|
|
10
|
-
}
|
|
11
4
|
export type TransformFunction = (context: TransformContext) => Transaction | null;
|
|
@@ -12,10 +12,6 @@ export declare const isContainerNode: (node: PMNode) => boolean;
|
|
|
12
12
|
export declare const isBlockNodeType: (nodeType: NodeType) => boolean;
|
|
13
13
|
export declare const isListNodeType: (nodeType: NodeType) => boolean;
|
|
14
14
|
export declare const isContainerNodeType: (nodeType: NodeType) => boolean;
|
|
15
|
-
export declare const isBulletOrOrderedList: (nodeType: NodeType) => boolean;
|
|
16
|
-
export declare const isTaskList: (nodeType: NodeType) => boolean;
|
|
17
|
-
export declare const getSupportedListTypes: (nodes: Record<string, NodeType>) => NodeType[];
|
|
18
|
-
export declare const getSupportedListTypesSet: (nodes: Record<string, NodeType>) => Set<NodeType>;
|
|
19
15
|
export declare const isLayoutNodeType: (nodeType: NodeType) => boolean;
|
|
20
16
|
export declare const isLayoutNode: (node: PMNode) => boolean;
|
|
21
17
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import type { TransformContext } from '../types';
|
|
3
3
|
export declare const unwrapLayoutNodesToTextNodes: (context: TransformContext, finalTargetNodeType: NodeType) => PMNode[];
|
|
4
4
|
export declare const transformToListNode: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
5
5
|
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TransformContext } from '
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
2
|
export declare const convertToLayout: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
3
3
|
export declare const transformLayoutNode: (context: TransformContext) => import("prosemirror-state").Transaction;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type { TransformContext } from '.././types';
|
|
3
3
|
export declare const transformOrderedUnorderedListToBlockNodes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type { TransformContext } from '.././types';
|
|
3
3
|
export declare const transformTaskListToBlockNodes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
1
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import type {
|
|
3
|
+
import type { TransformFunction } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Transform selection to list type
|
|
5
6
|
*/
|
|
@@ -20,7 +21,3 @@ export declare const transformListNode: TransformFunction;
|
|
|
20
21
|
* Lift list content and convert to block type
|
|
21
22
|
*/
|
|
22
23
|
export declare const liftListToBlockType: () => null;
|
|
23
|
-
/**
|
|
24
|
-
* Transform between different list types
|
|
25
|
-
*/
|
|
26
|
-
export declare const transformBetweenListTypes: (context: TransformContext) => Transaction | null;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransformContext } from '@atlaskit/editor-common/transforms';
|
|
2
2
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
4
|
-
export interface TransformContext {
|
|
5
|
-
sourceNode: PMNode;
|
|
6
|
-
sourcePos: number;
|
|
7
|
-
targetAttrs?: Record<string, unknown>;
|
|
8
|
-
targetNodeType: NodeType;
|
|
9
|
-
tr: Transaction;
|
|
10
|
-
}
|
|
11
4
|
export type TransformFunction = (context: TransformContext) => Transaction | null;
|
|
@@ -12,10 +12,6 @@ export declare const isContainerNode: (node: PMNode) => boolean;
|
|
|
12
12
|
export declare const isBlockNodeType: (nodeType: NodeType) => boolean;
|
|
13
13
|
export declare const isListNodeType: (nodeType: NodeType) => boolean;
|
|
14
14
|
export declare const isContainerNodeType: (nodeType: NodeType) => boolean;
|
|
15
|
-
export declare const isBulletOrOrderedList: (nodeType: NodeType) => boolean;
|
|
16
|
-
export declare const isTaskList: (nodeType: NodeType) => boolean;
|
|
17
|
-
export declare const getSupportedListTypes: (nodes: Record<string, NodeType>) => NodeType[];
|
|
18
|
-
export declare const getSupportedListTypesSet: (nodes: Record<string, NodeType>) => Set<NodeType>;
|
|
19
15
|
export declare const isLayoutNodeType: (nodeType: NodeType) => boolean;
|
|
20
16
|
export declare const isLayoutNode: (node: PMNode) => boolean;
|
|
21
17
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/css": "^0.14.0",
|
|
32
32
|
"@atlaskit/dropdown-menu": "^16.3.0",
|
|
33
|
-
"@atlaskit/editor-plugin-block-controls": "^6.
|
|
33
|
+
"@atlaskit/editor-plugin-block-controls": "^6.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-decorations": "^5.0.0",
|
|
35
35
|
"@atlaskit/editor-plugin-selection": "^5.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-user-intent": "^3.0.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@babel/runtime": "^7.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@atlaskit/editor-common": "^109.
|
|
49
|
+
"@atlaskit/editor-common": "^109.4.0",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
52
52
|
},
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.transformListStructure = exports.transformListRecursively = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
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; }
|
|
12
|
-
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) { (0, _defineProperty2.default)(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; }
|
|
13
|
-
/**
|
|
14
|
-
* Convert a block node to inline content suitable for task items
|
|
15
|
-
*/
|
|
16
|
-
var convertBlockToInlineContent = function convertBlockToInlineContent(node, schema) {
|
|
17
|
-
var paragraph = schema.nodes.paragraph;
|
|
18
|
-
if (node.type === paragraph) {
|
|
19
|
-
return (0, _toConsumableArray2.default)(node.content.content);
|
|
20
|
-
}
|
|
21
|
-
if (node.isBlock) {
|
|
22
|
-
var textContent = node.textContent;
|
|
23
|
-
return textContent ? [schema.text(textContent)] : [];
|
|
24
|
-
}
|
|
25
|
-
return [node];
|
|
26
|
-
};
|
|
27
|
-
var _transformListRecursively = exports.transformListRecursively = function transformListRecursively(props) {
|
|
28
|
-
var transformedItems = [];
|
|
29
|
-
var listNode = props.listNode,
|
|
30
|
-
isSourceBulletOrOrdered = props.isSourceBulletOrOrdered,
|
|
31
|
-
isTargetBulletOrOrdered = props.isTargetBulletOrOrdered,
|
|
32
|
-
isSourceTask = props.isSourceTask,
|
|
33
|
-
isTargetTask = props.isTargetTask,
|
|
34
|
-
supportedListTypes = props.supportedListTypes,
|
|
35
|
-
schema = props.schema,
|
|
36
|
-
targetNodeType = props.targetNodeType;
|
|
37
|
-
var _schema$nodes = schema.nodes,
|
|
38
|
-
taskList = _schema$nodes.taskList,
|
|
39
|
-
listItem = _schema$nodes.listItem,
|
|
40
|
-
taskItem = _schema$nodes.taskItem,
|
|
41
|
-
paragraph = _schema$nodes.paragraph;
|
|
42
|
-
listNode.forEach(function (child) {
|
|
43
|
-
if (isSourceBulletOrOrdered && isTargetTask) {
|
|
44
|
-
// Convert bullet/ordered => task
|
|
45
|
-
if (child.type === listItem) {
|
|
46
|
-
var inlineContent = [];
|
|
47
|
-
var nestedTaskLists = [];
|
|
48
|
-
child.forEach(function (grandChild) {
|
|
49
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== taskList) {
|
|
50
|
-
nestedTaskLists.push(_transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
51
|
-
listNode: grandChild
|
|
52
|
-
})));
|
|
53
|
-
} else {
|
|
54
|
-
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(convertBlockToInlineContent(grandChild, schema)));
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
if (inlineContent.length > 0) {
|
|
58
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
59
|
-
}
|
|
60
|
-
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
61
|
-
}
|
|
62
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
63
|
-
// Convert task => bullet/ordered
|
|
64
|
-
if (child.type === taskItem) {
|
|
65
|
-
var _inlineContent = (0, _toConsumableArray2.default)(child.content.content);
|
|
66
|
-
if (_inlineContent.length > 0) {
|
|
67
|
-
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
68
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
69
|
-
}
|
|
70
|
-
} else if (child.type === taskList) {
|
|
71
|
-
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
72
|
-
listNode: child
|
|
73
|
-
}));
|
|
74
|
-
var lastItem = transformedItems[transformedItems.length - 1];
|
|
75
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
76
|
-
// Attach nested list to previous item
|
|
77
|
-
var updatedContent = [].concat((0, _toConsumableArray2.default)(lastItem.content.content), [transformedNestedList]);
|
|
78
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
79
|
-
} else {
|
|
80
|
-
// No previous item, flatten nested items
|
|
81
|
-
transformedItems.push.apply(transformedItems, (0, _toConsumableArray2.default)(transformedNestedList.content.content));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
85
|
-
if (child.type === listItem) {
|
|
86
|
-
var convertedNestedLists = [];
|
|
87
|
-
child.forEach(function (grandChild) {
|
|
88
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
89
|
-
var convertedNode = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
90
|
-
listNode: grandChild
|
|
91
|
-
}));
|
|
92
|
-
convertedNestedLists.push(convertedNode);
|
|
93
|
-
} else {
|
|
94
|
-
convertedNestedLists.push(grandChild);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
return targetNodeType.create(null, transformedItems);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Transform list structure between different list types
|
|
106
|
-
*/
|
|
107
|
-
var transformListStructure = exports.transformListStructure = function transformListStructure(context) {
|
|
108
|
-
var tr = context.tr,
|
|
109
|
-
sourceNode = context.sourceNode,
|
|
110
|
-
sourcePos = context.sourcePos,
|
|
111
|
-
targetNodeType = context.targetNodeType;
|
|
112
|
-
var nodes = tr.doc.type.schema.nodes;
|
|
113
|
-
try {
|
|
114
|
-
var listNode = {
|
|
115
|
-
node: sourceNode,
|
|
116
|
-
pos: sourcePos
|
|
117
|
-
};
|
|
118
|
-
var sourceList = listNode.node,
|
|
119
|
-
listPos = listNode.pos;
|
|
120
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
121
|
-
|
|
122
|
-
var isSourceBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(sourceList.type);
|
|
123
|
-
var isTargetTask = (0, _utils.isTaskList)(targetNodeType);
|
|
124
|
-
var isSourceTask = (0, _utils.isTaskList)(sourceList.type);
|
|
125
|
-
var isTargetBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(targetNodeType);
|
|
126
|
-
var supportedListTypes = (0, _utils.getSupportedListTypesSet)(nodes);
|
|
127
|
-
var newList = _transformListRecursively({
|
|
128
|
-
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
129
|
-
isSourceTask: isSourceTask,
|
|
130
|
-
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
131
|
-
isTargetTask: isTargetTask,
|
|
132
|
-
listNode: sourceList,
|
|
133
|
-
schema: tr.doc.type.schema,
|
|
134
|
-
supportedListTypes: supportedListTypes,
|
|
135
|
-
targetNodeType: targetNodeType
|
|
136
|
-
});
|
|
137
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
138
|
-
return tr;
|
|
139
|
-
} catch (_unused) {
|
|
140
|
-
return tr;
|
|
141
|
-
}
|
|
142
|
-
};
|