@atlaskit/editor-plugin-block-menu 3.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/editor-commands/transforms/layout/utils.js +33 -19
- package/dist/cjs/editor-commands/transforms/layout-transforms.js +1 -1
- package/dist/cjs/editor-commands/transforms/list-transforms.js +5 -52
- package/dist/cjs/editor-commands/transforms/utils.js +3 -14
- package/dist/cjs/ui/block-menu.js +1 -1
- package/dist/es2019/editor-commands/transforms/layout/utils.js +25 -11
- package/dist/es2019/editor-commands/transforms/layout-transforms.js +1 -1
- package/dist/es2019/editor-commands/transforms/list-transforms.js +3 -54
- package/dist/es2019/editor-commands/transforms/utils.js +2 -13
- package/dist/es2019/ui/block-menu.js +1 -1
- package/dist/esm/editor-commands/transforms/layout/utils.js +27 -13
- package/dist/esm/editor-commands/transforms/layout-transforms.js +1 -1
- package/dist/esm/editor-commands/transforms/list-transforms.js +3 -50
- package/dist/esm/editor-commands/transforms/utils.js +2 -13
- package/dist/esm/ui/block-menu.js +1 -1
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +2 -1
- package/dist/types/editor-commands/transforms/layout/utils.d.ts +2 -2
- 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 +2 -2
- 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 -138
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +0 -140
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +0 -133
- 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,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
|
-
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
5
|
+
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema, targetAttrs?: TransformContext["targetAttrs"]) => 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
|
-
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
|
|
5
|
+
export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema, targetAttrs?: TransformContext["targetAttrs"]) => 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.
|
|
3
|
+
"version": "3.1.1",
|
|
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.2.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.5.0",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
52
52
|
},
|
|
@@ -1,138 +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
|
-
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
58
|
-
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
59
|
-
}
|
|
60
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
61
|
-
// Convert task => bullet/ordered
|
|
62
|
-
if (child.type === taskItem) {
|
|
63
|
-
var _inlineContent = (0, _toConsumableArray2.default)(child.content.content);
|
|
64
|
-
var paragraphNode = paragraph.create(null, _inlineContent.length > 0 ? _inlineContent : null);
|
|
65
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
66
|
-
} else if (child.type === taskList) {
|
|
67
|
-
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
68
|
-
listNode: child
|
|
69
|
-
}));
|
|
70
|
-
var lastItem = transformedItems[transformedItems.length - 1];
|
|
71
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
72
|
-
// Attach nested list to previous item
|
|
73
|
-
var updatedContent = [].concat((0, _toConsumableArray2.default)(lastItem.content.content), [transformedNestedList]);
|
|
74
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
75
|
-
} else {
|
|
76
|
-
// No previous item, flatten nested items
|
|
77
|
-
transformedItems.push.apply(transformedItems, (0, _toConsumableArray2.default)(transformedNestedList.content.content));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
81
|
-
if (child.type === listItem) {
|
|
82
|
-
var convertedNestedLists = [];
|
|
83
|
-
child.forEach(function (grandChild) {
|
|
84
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
85
|
-
var convertedNode = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
86
|
-
listNode: grandChild
|
|
87
|
-
}));
|
|
88
|
-
convertedNestedLists.push(convertedNode);
|
|
89
|
-
} else {
|
|
90
|
-
convertedNestedLists.push(grandChild);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
return targetNodeType.create(null, transformedItems);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Transform list structure between different list types
|
|
102
|
-
*/
|
|
103
|
-
var transformListStructure = exports.transformListStructure = function transformListStructure(context) {
|
|
104
|
-
var tr = context.tr,
|
|
105
|
-
sourceNode = context.sourceNode,
|
|
106
|
-
sourcePos = context.sourcePos,
|
|
107
|
-
targetNodeType = context.targetNodeType;
|
|
108
|
-
var nodes = tr.doc.type.schema.nodes;
|
|
109
|
-
try {
|
|
110
|
-
var listNode = {
|
|
111
|
-
node: sourceNode,
|
|
112
|
-
pos: sourcePos
|
|
113
|
-
};
|
|
114
|
-
var sourceList = listNode.node,
|
|
115
|
-
listPos = listNode.pos;
|
|
116
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
117
|
-
|
|
118
|
-
var isSourceBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(sourceList.type);
|
|
119
|
-
var isTargetTask = (0, _utils.isTaskList)(targetNodeType);
|
|
120
|
-
var isSourceTask = (0, _utils.isTaskList)(sourceList.type);
|
|
121
|
-
var isTargetBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(targetNodeType);
|
|
122
|
-
var supportedListTypes = (0, _utils.getSupportedListTypesSet)(nodes);
|
|
123
|
-
var newList = _transformListRecursively({
|
|
124
|
-
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
125
|
-
isSourceTask: isSourceTask,
|
|
126
|
-
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
127
|
-
isTargetTask: isTargetTask,
|
|
128
|
-
listNode: sourceList,
|
|
129
|
-
schema: tr.doc.type.schema,
|
|
130
|
-
supportedListTypes: supportedListTypes,
|
|
131
|
-
targetNodeType: targetNodeType
|
|
132
|
-
});
|
|
133
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
134
|
-
return tr;
|
|
135
|
-
} catch (_unused) {
|
|
136
|
-
return tr;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
@@ -1,140 +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
|
-
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
54
|
-
transformedItems.push(...nestedTaskLists);
|
|
55
|
-
}
|
|
56
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
57
|
-
// Convert task => bullet/ordered
|
|
58
|
-
if (child.type === taskItem) {
|
|
59
|
-
const inlineContent = [...child.content.content];
|
|
60
|
-
const paragraphNode = paragraph.create(null, inlineContent.length > 0 ? inlineContent : null);
|
|
61
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
62
|
-
} else if (child.type === taskList) {
|
|
63
|
-
const transformedNestedList = transformListRecursively({
|
|
64
|
-
...props,
|
|
65
|
-
listNode: child
|
|
66
|
-
});
|
|
67
|
-
const lastItem = transformedItems[transformedItems.length - 1];
|
|
68
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
69
|
-
// Attach nested list to previous item
|
|
70
|
-
const updatedContent = [...lastItem.content.content, transformedNestedList];
|
|
71
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
72
|
-
} else {
|
|
73
|
-
// No previous item, flatten nested items
|
|
74
|
-
transformedItems.push(...transformedNestedList.content.content);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
78
|
-
if (child.type === listItem) {
|
|
79
|
-
const convertedNestedLists = [];
|
|
80
|
-
child.forEach(grandChild => {
|
|
81
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
82
|
-
const convertedNode = transformListRecursively({
|
|
83
|
-
...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 const transformListStructure = context => {
|
|
102
|
-
const {
|
|
103
|
-
tr,
|
|
104
|
-
sourceNode,
|
|
105
|
-
sourcePos,
|
|
106
|
-
targetNodeType
|
|
107
|
-
} = context;
|
|
108
|
-
const nodes = tr.doc.type.schema.nodes;
|
|
109
|
-
try {
|
|
110
|
-
const listNode = {
|
|
111
|
-
node: sourceNode,
|
|
112
|
-
pos: sourcePos
|
|
113
|
-
};
|
|
114
|
-
const {
|
|
115
|
-
node: sourceList,
|
|
116
|
-
pos: listPos
|
|
117
|
-
} = listNode;
|
|
118
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
119
|
-
|
|
120
|
-
const isSourceBulletOrOrdered = isBulletOrOrderedList(sourceList.type);
|
|
121
|
-
const isTargetTask = isTaskList(targetNodeType);
|
|
122
|
-
const isSourceTask = isTaskList(sourceList.type);
|
|
123
|
-
const isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
124
|
-
const supportedListTypes = getSupportedListTypesSet(nodes);
|
|
125
|
-
const newList = transformListRecursively({
|
|
126
|
-
isSourceBulletOrOrdered,
|
|
127
|
-
isSourceTask,
|
|
128
|
-
isTargetBulletOrOrdered,
|
|
129
|
-
isTargetTask,
|
|
130
|
-
listNode: sourceList,
|
|
131
|
-
schema: tr.doc.type.schema,
|
|
132
|
-
supportedListTypes,
|
|
133
|
-
targetNodeType
|
|
134
|
-
});
|
|
135
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
136
|
-
return tr;
|
|
137
|
-
} catch {
|
|
138
|
-
return tr;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
@@ -1,133 +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
|
-
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
52
|
-
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
53
|
-
}
|
|
54
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
55
|
-
// Convert task => bullet/ordered
|
|
56
|
-
if (child.type === taskItem) {
|
|
57
|
-
var _inlineContent = _toConsumableArray(child.content.content);
|
|
58
|
-
var paragraphNode = paragraph.create(null, _inlineContent.length > 0 ? _inlineContent : null);
|
|
59
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
60
|
-
} else if (child.type === taskList) {
|
|
61
|
-
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
62
|
-
listNode: child
|
|
63
|
-
}));
|
|
64
|
-
var lastItem = transformedItems[transformedItems.length - 1];
|
|
65
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
66
|
-
// Attach nested list to previous item
|
|
67
|
-
var updatedContent = [].concat(_toConsumableArray(lastItem.content.content), [transformedNestedList]);
|
|
68
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
69
|
-
} else {
|
|
70
|
-
// No previous item, flatten nested items
|
|
71
|
-
transformedItems.push.apply(transformedItems, _toConsumableArray(transformedNestedList.content.content));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
75
|
-
if (child.type === listItem) {
|
|
76
|
-
var convertedNestedLists = [];
|
|
77
|
-
child.forEach(function (grandChild) {
|
|
78
|
-
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
79
|
-
var convertedNode = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
80
|
-
listNode: grandChild
|
|
81
|
-
}));
|
|
82
|
-
convertedNestedLists.push(convertedNode);
|
|
83
|
-
} else {
|
|
84
|
-
convertedNestedLists.push(grandChild);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return targetNodeType.create(null, transformedItems);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Transform list structure between different list types
|
|
96
|
-
*/
|
|
97
|
-
export { _transformListRecursively as transformListRecursively };
|
|
98
|
-
export var transformListStructure = function transformListStructure(context) {
|
|
99
|
-
var tr = context.tr,
|
|
100
|
-
sourceNode = context.sourceNode,
|
|
101
|
-
sourcePos = context.sourcePos,
|
|
102
|
-
targetNodeType = context.targetNodeType;
|
|
103
|
-
var nodes = tr.doc.type.schema.nodes;
|
|
104
|
-
try {
|
|
105
|
-
var listNode = {
|
|
106
|
-
node: sourceNode,
|
|
107
|
-
pos: sourcePos
|
|
108
|
-
};
|
|
109
|
-
var sourceList = listNode.node,
|
|
110
|
-
listPos = listNode.pos;
|
|
111
|
-
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
112
|
-
|
|
113
|
-
var isSourceBulletOrOrdered = isBulletOrOrderedList(sourceList.type);
|
|
114
|
-
var isTargetTask = isTaskList(targetNodeType);
|
|
115
|
-
var isSourceTask = isTaskList(sourceList.type);
|
|
116
|
-
var isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
117
|
-
var supportedListTypes = getSupportedListTypesSet(nodes);
|
|
118
|
-
var newList = _transformListRecursively({
|
|
119
|
-
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
120
|
-
isSourceTask: isSourceTask,
|
|
121
|
-
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
122
|
-
isTargetTask: isTargetTask,
|
|
123
|
-
listNode: sourceList,
|
|
124
|
-
schema: tr.doc.type.schema,
|
|
125
|
-
supportedListTypes: supportedListTypes,
|
|
126
|
-
targetNodeType: targetNodeType
|
|
127
|
-
});
|
|
128
|
-
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
129
|
-
return tr;
|
|
130
|
-
} catch (_unused) {
|
|
131
|
-
return tr;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
@@ -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 {};
|