@atlaskit/editor-plugin-block-menu 0.0.13 → 0.0.14
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 +6 -0
- package/dist/cjs/blockMenuPlugin.js +6 -0
- package/dist/cjs/editor-commands/formatNode.js +23 -0
- package/dist/cjs/editor-commands/transforms/block-transforms.js +37 -0
- package/dist/cjs/editor-commands/transforms/container-transforms.js +59 -0
- package/dist/cjs/editor-commands/transforms/list-transforms.js +53 -0
- package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +50 -0
- package/dist/cjs/editor-commands/transforms/types.js +5 -0
- package/dist/cjs/editor-commands/transforms/utils.js +109 -0
- package/dist/es2019/blockMenuPlugin.js +6 -0
- package/dist/es2019/editor-commands/formatNode.js +20 -0
- package/dist/es2019/editor-commands/transforms/block-transforms.js +38 -0
- package/dist/es2019/editor-commands/transforms/container-transforms.js +55 -0
- package/dist/es2019/editor-commands/transforms/list-transforms.js +49 -0
- package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +48 -0
- package/dist/es2019/editor-commands/transforms/types.js +1 -0
- package/dist/es2019/editor-commands/transforms/utils.js +103 -0
- package/dist/esm/blockMenuPlugin.js +6 -0
- package/dist/esm/editor-commands/formatNode.js +17 -0
- package/dist/esm/editor-commands/transforms/block-transforms.js +32 -0
- package/dist/esm/editor-commands/transforms/container-transforms.js +54 -0
- package/dist/esm/editor-commands/transforms/list-transforms.js +48 -0
- package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +44 -0
- package/dist/esm/editor-commands/transforms/types.js +1 -0
- package/dist/esm/editor-commands/transforms/utils.js +103 -0
- package/dist/types/blockMenuPluginType.d.ts +6 -1
- package/dist/types/editor-commands/formatNode.d.ts +9 -0
- package/dist/types/editor-commands/transforms/block-transforms.d.ts +5 -0
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +17 -0
- package/dist/types/editor-commands/transforms/list-transforms.d.ts +17 -0
- package/dist/types/editor-commands/transforms/transformNodeToTargetType.d.ts +4 -0
- package/dist/types/editor-commands/transforms/types.d.ts +11 -0
- package/dist/types/editor-commands/transforms/utils.d.ts +12 -0
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +6 -1
- package/dist/types-ts4.5/editor-commands/formatNode.d.ts +9 -0
- package/dist/types-ts4.5/editor-commands/transforms/block-transforms.d.ts +5 -0
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +17 -0
- package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +17 -0
- package/dist/types-ts4.5/editor-commands/transforms/transformNodeToTargetType.d.ts +4 -0
- package/dist/types-ts4.5/editor-commands/transforms/types.d.ts +11 -0
- package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +12 -0
- package/package.json +5 -8
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const getTargetNodeInfo = (targetType, nodes) => {
|
|
2
|
+
switch (targetType) {
|
|
3
|
+
case 'heading1':
|
|
4
|
+
return {
|
|
5
|
+
nodeType: nodes.heading,
|
|
6
|
+
attrs: {
|
|
7
|
+
level: 1
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
case 'heading2':
|
|
11
|
+
return {
|
|
12
|
+
nodeType: nodes.heading,
|
|
13
|
+
attrs: {
|
|
14
|
+
level: 2
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
case 'heading3':
|
|
18
|
+
return {
|
|
19
|
+
nodeType: nodes.heading,
|
|
20
|
+
attrs: {
|
|
21
|
+
level: 3
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
case 'heading4':
|
|
25
|
+
return {
|
|
26
|
+
nodeType: nodes.heading,
|
|
27
|
+
attrs: {
|
|
28
|
+
level: 4
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
case 'heading5':
|
|
32
|
+
return {
|
|
33
|
+
nodeType: nodes.heading,
|
|
34
|
+
attrs: {
|
|
35
|
+
level: 5
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
case 'heading6':
|
|
39
|
+
return {
|
|
40
|
+
nodeType: nodes.heading,
|
|
41
|
+
attrs: {
|
|
42
|
+
level: 6
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
case 'paragraph':
|
|
46
|
+
return {
|
|
47
|
+
nodeType: nodes.paragraph
|
|
48
|
+
};
|
|
49
|
+
case 'blockquote':
|
|
50
|
+
return {
|
|
51
|
+
nodeType: nodes.blockquote
|
|
52
|
+
};
|
|
53
|
+
case 'expand':
|
|
54
|
+
return {
|
|
55
|
+
nodeType: nodes.expand
|
|
56
|
+
};
|
|
57
|
+
case 'panel':
|
|
58
|
+
return {
|
|
59
|
+
nodeType: nodes.panel,
|
|
60
|
+
attrs: {
|
|
61
|
+
panelType: 'info'
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
case 'codeblock':
|
|
65
|
+
return {
|
|
66
|
+
nodeType: nodes.codeBlock
|
|
67
|
+
};
|
|
68
|
+
case 'bulletList':
|
|
69
|
+
return {
|
|
70
|
+
nodeType: nodes.bulletList
|
|
71
|
+
};
|
|
72
|
+
case 'orderedList':
|
|
73
|
+
return {
|
|
74
|
+
nodeType: nodes.orderedList
|
|
75
|
+
};
|
|
76
|
+
case 'taskList':
|
|
77
|
+
return {
|
|
78
|
+
nodeType: nodes.taskList
|
|
79
|
+
};
|
|
80
|
+
default:
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Helper functions to categorize node types
|
|
86
|
+
export const isBlockNode = node => {
|
|
87
|
+
return ['paragraph', 'heading', 'codeBlock'].includes(node.type.name);
|
|
88
|
+
};
|
|
89
|
+
export const isListNode = node => {
|
|
90
|
+
return ['bulletList', 'orderedList', 'taskList', 'listItem'].includes(node.type.name);
|
|
91
|
+
};
|
|
92
|
+
export const isContainerNode = node => {
|
|
93
|
+
return ['panel', 'expand', 'blockquote'].includes(node.type.name);
|
|
94
|
+
};
|
|
95
|
+
export const isBlockNodeType = nodeType => {
|
|
96
|
+
return ['paragraph', 'heading', 'codeBlock'].includes(nodeType.name);
|
|
97
|
+
};
|
|
98
|
+
export const isListNodeType = nodeType => {
|
|
99
|
+
return ['bulletList', 'orderedList', 'taskList'].includes(nodeType.name);
|
|
100
|
+
};
|
|
101
|
+
export const isContainerNodeType = nodeType => {
|
|
102
|
+
return ['panel', 'expand', 'blockquote'].includes(nodeType.name);
|
|
103
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { createBlockMenuRegistry } from './editor-actions';
|
|
3
|
+
import { formatNode as _formatNode } from './editor-commands/formatNode';
|
|
3
4
|
import { createPlugin } from './pm-plugins/main';
|
|
4
5
|
import BlockMenu from './ui/block-menu';
|
|
5
6
|
import { getBlockMenuComponents } from './ui/block-menu-components';
|
|
@@ -27,6 +28,11 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
27
28
|
return registry.components;
|
|
28
29
|
}
|
|
29
30
|
},
|
|
31
|
+
commands: {
|
|
32
|
+
formatNode: function formatNode(currentNode, targetType) {
|
|
33
|
+
return _formatNode(currentNode, targetType);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
30
36
|
contentComponent: function contentComponent(_ref2) {
|
|
31
37
|
var editorView = _ref2.editorView,
|
|
32
38
|
popupsMountPoint = _ref2.popupsMountPoint,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { transformNodeToTargetType } from './transforms/transformNodeToTargetType';
|
|
2
|
+
/**
|
|
3
|
+
* Formats the current node or selection to the specified target type
|
|
4
|
+
* @param currentNode - The current node
|
|
5
|
+
* @param targetType - The target node type to convert to
|
|
6
|
+
*/
|
|
7
|
+
export var formatNode = function formatNode(currentNode, targetType) {
|
|
8
|
+
return function (_ref) {
|
|
9
|
+
var tr = _ref.tr;
|
|
10
|
+
var selection = tr.selection;
|
|
11
|
+
try {
|
|
12
|
+
return transformNodeToTargetType(tr, currentNode, selection.from, targetType);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { transformToContainer } from './container-transforms';
|
|
2
|
+
import { transformToList } from './list-transforms';
|
|
3
|
+
import { isListNodeType, isContainerNodeType, isBlockNodeType } from './utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transform block nodes (paragraph, heading, codeblock)
|
|
7
|
+
*/
|
|
8
|
+
export var transformBlockNode = function transformBlockNode(context) {
|
|
9
|
+
var tr = context.tr,
|
|
10
|
+
targetNodeType = context.targetNodeType,
|
|
11
|
+
targetAttrs = context.targetAttrs;
|
|
12
|
+
var selection = tr.selection;
|
|
13
|
+
var $from = selection.$from,
|
|
14
|
+
$to = selection.$to;
|
|
15
|
+
|
|
16
|
+
// Handle transformation to list types
|
|
17
|
+
if (isListNodeType(targetNodeType)) {
|
|
18
|
+
return transformToList();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Handle transformation to container types (panel, expand, blockquote)
|
|
22
|
+
if (isContainerNodeType(targetNodeType)) {
|
|
23
|
+
return transformToContainer();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Handle block type transformation (paragraph, heading, codeblock)
|
|
27
|
+
if (isBlockNodeType(targetNodeType)) {
|
|
28
|
+
tr.setBlockType($from.pos, $to.pos, targetNodeType, targetAttrs);
|
|
29
|
+
return tr;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isBlockNodeType, isListNodeType, isContainerNodeType } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Transform selection to container type
|
|
5
|
+
*/
|
|
6
|
+
export var transformToContainer = function transformToContainer() {
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transform container nodes (panel, expand, blockquote)
|
|
12
|
+
*/
|
|
13
|
+
export var transformContainerNode = function transformContainerNode(_ref) {
|
|
14
|
+
var tr = _ref.tr,
|
|
15
|
+
sourcePos = _ref.sourcePos,
|
|
16
|
+
targetNodeType = _ref.targetNodeType,
|
|
17
|
+
targetAttrs = _ref.targetAttrs;
|
|
18
|
+
if (sourcePos === null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Transform container to block type - unwrap and convert content
|
|
23
|
+
if (isBlockNodeType(targetNodeType)) {
|
|
24
|
+
return unwrapAndConvertToBlockType();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Transform container to list type
|
|
28
|
+
if (isListNodeType(targetNodeType)) {
|
|
29
|
+
return unwrapAndConvertToList();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Transform between container types
|
|
33
|
+
if (isContainerNodeType(targetNodeType)) {
|
|
34
|
+
tr.setNodeMarkup(sourcePos, targetNodeType, targetAttrs);
|
|
35
|
+
return tr;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Unwrap container node and convert content to block type
|
|
42
|
+
*/
|
|
43
|
+
export var unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType() {
|
|
44
|
+
// Convert to block type directly
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Unwrap container node and convert content to list
|
|
50
|
+
*/
|
|
51
|
+
export var unwrapAndConvertToList = function unwrapAndConvertToList() {
|
|
52
|
+
// Convert to list directly
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isBlockNodeType, isContainerNodeType, isListNodeType } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Transform selection to list type
|
|
5
|
+
*/
|
|
6
|
+
export var transformToList = function transformToList() {
|
|
7
|
+
return null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Transform list nodes
|
|
12
|
+
*/
|
|
13
|
+
export var transformListNode = function transformListNode(_ref) {
|
|
14
|
+
var targetNodeType = _ref.targetNodeType;
|
|
15
|
+
// Transform list to block type
|
|
16
|
+
if (isBlockNodeType(targetNodeType)) {
|
|
17
|
+
// Lift list items out of the list and convert to target block type
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Transform list to container type
|
|
22
|
+
if (isContainerNodeType(targetNodeType)) {
|
|
23
|
+
// Lift list items out of the list and convert to container type
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Transform between list types
|
|
28
|
+
if (isListNodeType(targetNodeType)) {
|
|
29
|
+
// Lift list items out of the list and convert to the other list type
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Lift list content and convert to block type
|
|
37
|
+
*/
|
|
38
|
+
export var liftListToBlockType = function liftListToBlockType() {
|
|
39
|
+
// Convert to target block type directly
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Transform between different list types
|
|
45
|
+
*/
|
|
46
|
+
export var transformBetweenListTypes = function transformBetweenListTypes() {
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { transformBlockNode } from './block-transforms';
|
|
2
|
+
import { transformContainerNode } from './container-transforms';
|
|
3
|
+
import { transformListNode } from './list-transforms';
|
|
4
|
+
import { getTargetNodeInfo, isBlockNode, isListNode, isContainerNode } from './utils';
|
|
5
|
+
export function transformNodeToTargetType(tr, sourceNode, sourcePos, targetType) {
|
|
6
|
+
var nodes = tr.doc.type.schema.nodes;
|
|
7
|
+
var targetNodeInfo = getTargetNodeInfo(targetType, nodes);
|
|
8
|
+
if (!targetNodeInfo) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
var targetNodeType = targetNodeInfo.nodeType,
|
|
12
|
+
targetAttrs = targetNodeInfo.attrs;
|
|
13
|
+
|
|
14
|
+
// Early return if trying to transform to the same type
|
|
15
|
+
if (sourceNode.type === targetNodeType) {
|
|
16
|
+
return tr; // No transformation needed
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Prepare transformation context
|
|
20
|
+
var transformationContext = {
|
|
21
|
+
tr: tr,
|
|
22
|
+
sourceNode: sourceNode,
|
|
23
|
+
sourcePos: sourcePos,
|
|
24
|
+
targetNodeType: targetNodeType,
|
|
25
|
+
targetAttrs: targetAttrs
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Route to appropriate transformation strategy based on source node type
|
|
29
|
+
try {
|
|
30
|
+
if (isBlockNode(sourceNode)) {
|
|
31
|
+
return transformBlockNode(transformationContext);
|
|
32
|
+
}
|
|
33
|
+
if (isListNode(sourceNode)) {
|
|
34
|
+
return transformListNode(transformationContext);
|
|
35
|
+
}
|
|
36
|
+
if (isContainerNode(sourceNode)) {
|
|
37
|
+
return transformContainerNode(transformationContext);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
// Node transformation failed
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export var getTargetNodeInfo = function getTargetNodeInfo(targetType, nodes) {
|
|
2
|
+
switch (targetType) {
|
|
3
|
+
case 'heading1':
|
|
4
|
+
return {
|
|
5
|
+
nodeType: nodes.heading,
|
|
6
|
+
attrs: {
|
|
7
|
+
level: 1
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
case 'heading2':
|
|
11
|
+
return {
|
|
12
|
+
nodeType: nodes.heading,
|
|
13
|
+
attrs: {
|
|
14
|
+
level: 2
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
case 'heading3':
|
|
18
|
+
return {
|
|
19
|
+
nodeType: nodes.heading,
|
|
20
|
+
attrs: {
|
|
21
|
+
level: 3
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
case 'heading4':
|
|
25
|
+
return {
|
|
26
|
+
nodeType: nodes.heading,
|
|
27
|
+
attrs: {
|
|
28
|
+
level: 4
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
case 'heading5':
|
|
32
|
+
return {
|
|
33
|
+
nodeType: nodes.heading,
|
|
34
|
+
attrs: {
|
|
35
|
+
level: 5
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
case 'heading6':
|
|
39
|
+
return {
|
|
40
|
+
nodeType: nodes.heading,
|
|
41
|
+
attrs: {
|
|
42
|
+
level: 6
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
case 'paragraph':
|
|
46
|
+
return {
|
|
47
|
+
nodeType: nodes.paragraph
|
|
48
|
+
};
|
|
49
|
+
case 'blockquote':
|
|
50
|
+
return {
|
|
51
|
+
nodeType: nodes.blockquote
|
|
52
|
+
};
|
|
53
|
+
case 'expand':
|
|
54
|
+
return {
|
|
55
|
+
nodeType: nodes.expand
|
|
56
|
+
};
|
|
57
|
+
case 'panel':
|
|
58
|
+
return {
|
|
59
|
+
nodeType: nodes.panel,
|
|
60
|
+
attrs: {
|
|
61
|
+
panelType: 'info'
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
case 'codeblock':
|
|
65
|
+
return {
|
|
66
|
+
nodeType: nodes.codeBlock
|
|
67
|
+
};
|
|
68
|
+
case 'bulletList':
|
|
69
|
+
return {
|
|
70
|
+
nodeType: nodes.bulletList
|
|
71
|
+
};
|
|
72
|
+
case 'orderedList':
|
|
73
|
+
return {
|
|
74
|
+
nodeType: nodes.orderedList
|
|
75
|
+
};
|
|
76
|
+
case 'taskList':
|
|
77
|
+
return {
|
|
78
|
+
nodeType: nodes.taskList
|
|
79
|
+
};
|
|
80
|
+
default:
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Helper functions to categorize node types
|
|
86
|
+
export var isBlockNode = function isBlockNode(node) {
|
|
87
|
+
return ['paragraph', 'heading', 'codeBlock'].includes(node.type.name);
|
|
88
|
+
};
|
|
89
|
+
export var isListNode = function isListNode(node) {
|
|
90
|
+
return ['bulletList', 'orderedList', 'taskList', 'listItem'].includes(node.type.name);
|
|
91
|
+
};
|
|
92
|
+
export var isContainerNode = function isContainerNode(node) {
|
|
93
|
+
return ['panel', 'expand', 'blockquote'].includes(node.type.name);
|
|
94
|
+
};
|
|
95
|
+
export var isBlockNodeType = function isBlockNodeType(nodeType) {
|
|
96
|
+
return ['paragraph', 'heading', 'codeBlock'].includes(nodeType.name);
|
|
97
|
+
};
|
|
98
|
+
export var isListNodeType = function isListNodeType(nodeType) {
|
|
99
|
+
return ['bulletList', 'orderedList', 'taskList'].includes(nodeType.name);
|
|
100
|
+
};
|
|
101
|
+
export var isContainerNodeType = function isContainerNodeType(nodeType) {
|
|
102
|
+
return ['panel', 'expand', 'blockquote'].includes(nodeType.name);
|
|
103
|
+
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
3
3
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
4
4
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
5
5
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
6
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import type { FormatNodeTargetType } from './editor-commands/transforms/types';
|
|
6
8
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
7
9
|
actions: {
|
|
8
10
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
9
11
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
10
12
|
};
|
|
13
|
+
commands: {
|
|
14
|
+
formatNode: (currentNode: PMNode, targetType: FormatNodeTargetType) => EditorCommand;
|
|
15
|
+
};
|
|
11
16
|
dependencies: [
|
|
12
17
|
OptionalPlugin<BlockControlsPlugin>,
|
|
13
18
|
OptionalPlugin<UserIntentPlugin>,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { FormatNodeTargetType } from './transforms/types';
|
|
4
|
+
/**
|
|
5
|
+
* Formats the current node or selection to the specified target type
|
|
6
|
+
* @param currentNode - The current node
|
|
7
|
+
* @param targetType - The target node type to convert to
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatNode: (currentNode: PMNode, targetType: FormatNodeTargetType) => EditorCommand;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransformFunction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transform selection to container type
|
|
4
|
+
*/
|
|
5
|
+
export declare const transformToContainer: () => null;
|
|
6
|
+
/**
|
|
7
|
+
* Transform container nodes (panel, expand, blockquote)
|
|
8
|
+
*/
|
|
9
|
+
export declare const transformContainerNode: TransformFunction;
|
|
10
|
+
/**
|
|
11
|
+
* Unwrap container node and convert content to block type
|
|
12
|
+
*/
|
|
13
|
+
export declare const unwrapAndConvertToBlockType: () => null;
|
|
14
|
+
/**
|
|
15
|
+
* Unwrap container node and convert content to list
|
|
16
|
+
*/
|
|
17
|
+
export declare const unwrapAndConvertToList: () => null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransformFunction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transform selection to list type
|
|
4
|
+
*/
|
|
5
|
+
export declare const transformToList: () => null;
|
|
6
|
+
/**
|
|
7
|
+
* Transform list nodes
|
|
8
|
+
*/
|
|
9
|
+
export declare const transformListNode: TransformFunction;
|
|
10
|
+
/**
|
|
11
|
+
* Lift list content and convert to block type
|
|
12
|
+
*/
|
|
13
|
+
export declare const liftListToBlockType: () => null;
|
|
14
|
+
/**
|
|
15
|
+
* Transform between different list types
|
|
16
|
+
*/
|
|
17
|
+
export declare const transformBetweenListTypes: () => null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { FormatNodeTargetType } from './types';
|
|
4
|
+
export declare function transformNodeToTargetType(tr: Transaction, sourceNode: PMNode, sourcePos: number | null, targetType: FormatNodeTargetType): Transaction | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Node as PMNode, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'panel' | 'codeblock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
4
|
+
export interface TransformContext {
|
|
5
|
+
tr: Transaction;
|
|
6
|
+
sourceNode: PMNode;
|
|
7
|
+
sourcePos: number | null;
|
|
8
|
+
targetNodeType: NodeType;
|
|
9
|
+
targetAttrs?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export type TransformFunction = (context: TransformContext) => Transaction | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node as PMNode, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { FormatNodeTargetType } from './types';
|
|
3
|
+
export declare const getTargetNodeInfo: (targetType: FormatNodeTargetType, nodes: Record<string, NodeType>) => {
|
|
4
|
+
nodeType: NodeType;
|
|
5
|
+
attrs?: Record<string, unknown>;
|
|
6
|
+
} | null;
|
|
7
|
+
export declare const isBlockNode: (node: PMNode) => boolean;
|
|
8
|
+
export declare const isListNode: (node: PMNode) => boolean;
|
|
9
|
+
export declare const isContainerNode: (node: PMNode) => boolean;
|
|
10
|
+
export declare const isBlockNodeType: (nodeType: NodeType) => boolean;
|
|
11
|
+
export declare const isListNodeType: (nodeType: NodeType) => boolean;
|
|
12
|
+
export declare const isContainerNodeType: (nodeType: NodeType) => boolean;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
3
3
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
4
4
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
5
5
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
6
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
7
|
+
import type { FormatNodeTargetType } from './editor-commands/transforms/types';
|
|
6
8
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
7
9
|
actions: {
|
|
8
10
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
9
11
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
10
12
|
};
|
|
13
|
+
commands: {
|
|
14
|
+
formatNode: (currentNode: PMNode, targetType: FormatNodeTargetType) => EditorCommand;
|
|
15
|
+
};
|
|
11
16
|
dependencies: [
|
|
12
17
|
OptionalPlugin<BlockControlsPlugin>,
|
|
13
18
|
OptionalPlugin<UserIntentPlugin>,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { FormatNodeTargetType } from './transforms/types';
|
|
4
|
+
/**
|
|
5
|
+
* Formats the current node or selection to the specified target type
|
|
6
|
+
* @param currentNode - The current node
|
|
7
|
+
* @param targetType - The target node type to convert to
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatNode: (currentNode: PMNode, targetType: FormatNodeTargetType) => EditorCommand;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransformFunction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transform selection to container type
|
|
4
|
+
*/
|
|
5
|
+
export declare const transformToContainer: () => null;
|
|
6
|
+
/**
|
|
7
|
+
* Transform container nodes (panel, expand, blockquote)
|
|
8
|
+
*/
|
|
9
|
+
export declare const transformContainerNode: TransformFunction;
|
|
10
|
+
/**
|
|
11
|
+
* Unwrap container node and convert content to block type
|
|
12
|
+
*/
|
|
13
|
+
export declare const unwrapAndConvertToBlockType: () => null;
|
|
14
|
+
/**
|
|
15
|
+
* Unwrap container node and convert content to list
|
|
16
|
+
*/
|
|
17
|
+
export declare const unwrapAndConvertToList: () => null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransformFunction } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transform selection to list type
|
|
4
|
+
*/
|
|
5
|
+
export declare const transformToList: () => null;
|
|
6
|
+
/**
|
|
7
|
+
* Transform list nodes
|
|
8
|
+
*/
|
|
9
|
+
export declare const transformListNode: TransformFunction;
|
|
10
|
+
/**
|
|
11
|
+
* Lift list content and convert to block type
|
|
12
|
+
*/
|
|
13
|
+
export declare const liftListToBlockType: () => null;
|
|
14
|
+
/**
|
|
15
|
+
* Transform between different list types
|
|
16
|
+
*/
|
|
17
|
+
export declare const transformBetweenListTypes: () => null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { FormatNodeTargetType } from './types';
|
|
4
|
+
export declare function transformNodeToTargetType(tr: Transaction, sourceNode: PMNode, sourcePos: number | null, targetType: FormatNodeTargetType): Transaction | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Node as PMNode, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'panel' | 'codeblock' | 'bulletList' | 'orderedList' | 'taskList';
|
|
4
|
+
export interface TransformContext {
|
|
5
|
+
tr: Transaction;
|
|
6
|
+
sourceNode: PMNode;
|
|
7
|
+
sourcePos: number | null;
|
|
8
|
+
targetNodeType: NodeType;
|
|
9
|
+
targetAttrs?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export type TransformFunction = (context: TransformContext) => Transaction | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node as PMNode, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { FormatNodeTargetType } from './types';
|
|
3
|
+
export declare const getTargetNodeInfo: (targetType: FormatNodeTargetType, nodes: Record<string, NodeType>) => {
|
|
4
|
+
nodeType: NodeType;
|
|
5
|
+
attrs?: Record<string, unknown>;
|
|
6
|
+
} | null;
|
|
7
|
+
export declare const isBlockNode: (node: PMNode) => boolean;
|
|
8
|
+
export declare const isListNode: (node: PMNode) => boolean;
|
|
9
|
+
export declare const isContainerNode: (node: PMNode) => boolean;
|
|
10
|
+
export declare const isBlockNodeType: (nodeType: NodeType) => boolean;
|
|
11
|
+
export declare const isListNodeType: (nodeType: NodeType) => boolean;
|
|
12
|
+
export declare const isContainerNodeType: (nodeType: NodeType) => boolean;
|