@atlaskit/editor-plugin-block-menu 5.2.2 → 5.2.4
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 +16 -0
- package/dist/cjs/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +232 -0
- package/dist/cjs/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -25
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/es2019/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +225 -0
- package/dist/es2019/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -22
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/esm/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +226 -0
- package/dist/esm/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -24
- package/dist/esm/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
- package/dist/types/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
- package/dist/types/editor-commands/transform-node-utils/{unwrapListStep.d.ts → steps/unwrapListStep.d.ts} +1 -1
- package/dist/types/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
- package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapListStep.d.ts → steps/unwrapListStep.d.ts} +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -34
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -62
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -39
- package/dist/cjs/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -90
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -27
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -55
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
- package/dist/es2019/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -86
- package/dist/esm/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -29
- package/dist/esm/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -57
- package/dist/esm/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
- package/dist/esm/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -85
- package/dist/types/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
- package/dist/types/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
- package/dist/types/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
- package/dist/types/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
- /package/dist/cjs/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
- /package/dist/es2019/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
- /package/dist/esm/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { TransformStep } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Transform step that converts between bulletList, orderedList, and taskList types.
|
|
4
|
+
* This step maintains the order and indentation of the list by recursively
|
|
5
|
+
* converting all nested lists while preserving the structure. It also handles
|
|
6
|
+
* conversion between listItem and taskItem types.
|
|
7
|
+
*
|
|
8
|
+
* When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* Input (bulletList with nested bulletList):
|
|
12
|
+
* - bulletList
|
|
13
|
+
* - listItem "1"
|
|
14
|
+
* - bulletList
|
|
15
|
+
* - listItem "1.1"
|
|
16
|
+
* - bulletList
|
|
17
|
+
* - listItem "1.1.1"
|
|
18
|
+
* - listItem "1.2"
|
|
19
|
+
* - listItem "2"
|
|
20
|
+
*
|
|
21
|
+
* Output (orderedList with nested orderedList):
|
|
22
|
+
* 1. orderedList
|
|
23
|
+
* 1. listItem "1"
|
|
24
|
+
* 1. orderedList
|
|
25
|
+
* 1. listItem "1.1"
|
|
26
|
+
* 1. orderedList
|
|
27
|
+
* 1. listItem "1.1.1"
|
|
28
|
+
* 2. listItem "1.2"
|
|
29
|
+
* 2. listItem "2"
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* Input (bulletList with nested taskList):
|
|
33
|
+
* - bulletList
|
|
34
|
+
* - listItem "Regular item"
|
|
35
|
+
* - taskList
|
|
36
|
+
* - taskItem "Task 1" (checked)
|
|
37
|
+
* - taskItem "Task 2" (unchecked)
|
|
38
|
+
*
|
|
39
|
+
* Output (orderedList with nested orderedList, taskItems converted to listItems):
|
|
40
|
+
* 1. orderedList
|
|
41
|
+
* 1. listItem "Regular item"
|
|
42
|
+
* 1. orderedList
|
|
43
|
+
* 1. listItem "Task 1"
|
|
44
|
+
* 2. listItem "Task 2"
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* Input (bulletList to taskList, with paragraph extraction):
|
|
48
|
+
* - bulletList
|
|
49
|
+
* - listItem
|
|
50
|
+
* - paragraph "Text content"
|
|
51
|
+
* - listItem
|
|
52
|
+
* - paragraph "Text"
|
|
53
|
+
* - codeBlock "code"
|
|
54
|
+
* - mediaSingle (image)
|
|
55
|
+
*
|
|
56
|
+
* Output (taskList with text extracted from paragraphs, unsupported content filtered):
|
|
57
|
+
* - taskList
|
|
58
|
+
* - taskItem "Text content" (text extracted from paragraph)
|
|
59
|
+
* - taskItem "Text" (text extracted, codeBlock and image filtered out)
|
|
60
|
+
*
|
|
61
|
+
* @param nodes - The nodes to transform
|
|
62
|
+
* @param context - The transformation context containing schema and target node type
|
|
63
|
+
* @returns The transformed nodes
|
|
64
|
+
*/
|
|
65
|
+
export declare const listToListStep: TransformStep;
|
package/package.json
CHANGED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.convertBulletListToTextStep = void 0;
|
|
7
|
-
var _createListToTextStep = require("./createListToTextStep");
|
|
8
|
-
/**
|
|
9
|
-
* Given an array of nodes, processes each bullet list by converting its items
|
|
10
|
-
* to paragraphs with "- " prefix.
|
|
11
|
-
*
|
|
12
|
-
* Handles nested bullet lists recursively with 3-space indentation per level.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* Input:
|
|
16
|
-
* - bulletList()(
|
|
17
|
-
* listItem()(p()('Item 1')),
|
|
18
|
-
* bulletList()(listItem()(p()('Sub item 1')))
|
|
19
|
-
* )
|
|
20
|
-
*
|
|
21
|
-
* Output:
|
|
22
|
-
* - p()('- Item 1')
|
|
23
|
-
* - p()(' - Sub item 1')
|
|
24
|
-
*/
|
|
25
|
-
var convertBulletListToTextStep = exports.convertBulletListToTextStep = (0, _createListToTextStep.createListToTextStep)({
|
|
26
|
-
listTypeName: 'bulletList',
|
|
27
|
-
itemTypeName: 'listItem',
|
|
28
|
-
indent: ' ',
|
|
29
|
-
// 3 spaces per nesting level
|
|
30
|
-
getPrefix: function getPrefix() {
|
|
31
|
-
return '- ';
|
|
32
|
-
},
|
|
33
|
-
unwrapParagraphContent: true
|
|
34
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.convertOrderedListToTextStep = void 0;
|
|
7
|
-
var _createListToTextStep = require("./createListToTextStep");
|
|
8
|
-
/**
|
|
9
|
-
* Converts a number to a letter (1=a, 2=b, etc.)
|
|
10
|
-
* For numbers > 26, continues with aa, ab, etc.
|
|
11
|
-
*/
|
|
12
|
-
var numberToLetter = function numberToLetter(num) {
|
|
13
|
-
var result = '';
|
|
14
|
-
var n = num;
|
|
15
|
-
while (n > 0) {
|
|
16
|
-
n--;
|
|
17
|
-
result = String.fromCharCode(97 + n % 26) + result;
|
|
18
|
-
n = Math.floor(n / 26);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Gets the appropriate prefix for an ordered list item based on depth and index.
|
|
25
|
-
* - Level 0: "1. ", "2. ", "3. ", etc.
|
|
26
|
-
* - Level 1+: "a. ", "b. ", "c. ", etc.
|
|
27
|
-
*/
|
|
28
|
-
var getOrderedListPrefix = function getOrderedListPrefix(depth, index) {
|
|
29
|
-
if (depth === 0) {
|
|
30
|
-
return "".concat(index, ". ");
|
|
31
|
-
}
|
|
32
|
-
return "".concat(numberToLetter(index), ". ");
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Given an array of nodes, processes each ordered list by converting its items
|
|
37
|
-
* to paragraphs with numbered prefixes (1., 2., 3.) at the top level and
|
|
38
|
-
* lettered prefixes (a., b., c.) for nested levels.
|
|
39
|
-
*
|
|
40
|
-
* Handles nested ordered lists recursively with 3-space indentation per level.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* Input:
|
|
44
|
-
* - orderedList({ order: 1 })(
|
|
45
|
-
* listItem()(p()('Item 1')),
|
|
46
|
-
* orderedList({ order: 1 })(listItem()(p()('Sub item 1')))
|
|
47
|
-
* )
|
|
48
|
-
*
|
|
49
|
-
* Output:
|
|
50
|
-
* - p()('1. Item 1')
|
|
51
|
-
* - p()(' a. Sub item 1')
|
|
52
|
-
*/
|
|
53
|
-
var convertOrderedListToTextStep = exports.convertOrderedListToTextStep = (0, _createListToTextStep.createListToTextStep)({
|
|
54
|
-
listTypeName: 'orderedList',
|
|
55
|
-
itemTypeName: 'listItem',
|
|
56
|
-
indent: ' ',
|
|
57
|
-
// 3 spaces per nesting level
|
|
58
|
-
getPrefix: function getPrefix(depth, index) {
|
|
59
|
-
return getOrderedListPrefix(depth, index);
|
|
60
|
-
},
|
|
61
|
-
unwrapParagraphContent: true
|
|
62
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.convertTaskListToTextStep = void 0;
|
|
7
|
-
var _createListToTextStep = require("./createListToTextStep");
|
|
8
|
-
/**
|
|
9
|
-
* Given an array of nodes, processes each task list by converting its items
|
|
10
|
-
* to paragraphs with a checkbox prefix. Uses "[] " for unchecked (TODO) tasks
|
|
11
|
-
* and "[x] " for checked (DONE) tasks.
|
|
12
|
-
*
|
|
13
|
-
* Handles nested task lists recursively with 4-space indentation per level.
|
|
14
|
-
*
|
|
15
|
-
* This is used when converting a task list to a container that doesn't support
|
|
16
|
-
* task items (like blockquote).
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* Input:
|
|
20
|
-
* - taskList()(
|
|
21
|
-
* taskItem({ state: 'TODO' })('Task list item'),
|
|
22
|
-
* taskList()(taskItem({ state: 'DONE' })('Nested done task'))
|
|
23
|
-
* )
|
|
24
|
-
*
|
|
25
|
-
* Output:
|
|
26
|
-
* - p()('[] Task list item')
|
|
27
|
-
* - p()(' [x] Nested done task')
|
|
28
|
-
*/
|
|
29
|
-
var convertTaskListToTextStep = exports.convertTaskListToTextStep = (0, _createListToTextStep.createListToTextStep)({
|
|
30
|
-
listTypeName: 'taskList',
|
|
31
|
-
itemTypeName: 'taskItem',
|
|
32
|
-
indent: ' ',
|
|
33
|
-
// 4 spaces per nesting level
|
|
34
|
-
getPrefix: function getPrefix(_, __, itemNode) {
|
|
35
|
-
var _itemNode$attrs;
|
|
36
|
-
return ((_itemNode$attrs = itemNode.attrs) === null || _itemNode$attrs === void 0 ? void 0 : _itemNode$attrs.state) === 'DONE' ? '[x] ' : '[] ';
|
|
37
|
-
},
|
|
38
|
-
unwrapParagraphContent: false
|
|
39
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createListToTextStep = void 0;
|
|
7
|
-
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
-
/**
|
|
9
|
-
* Configuration for creating a list-to-text transformation step.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Recursively extracts list items from a list (including nested lists)
|
|
14
|
-
* and converts them to paragraphs with configurable prefixes and indentation.
|
|
15
|
-
*/
|
|
16
|
-
var extractListItemsAsParagraphs = function extractListItemsAsParagraphs(node, schema, config) {
|
|
17
|
-
var paragraphs = [];
|
|
18
|
-
var paragraphType = schema.nodes.paragraph;
|
|
19
|
-
var listType = schema.nodes[config.listTypeName];
|
|
20
|
-
var itemType = schema.nodes[config.itemTypeName];
|
|
21
|
-
var _extract = function extract(currentNode) {
|
|
22
|
-
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
23
|
-
var itemIndex = 0;
|
|
24
|
-
currentNode.forEach(function (child) {
|
|
25
|
-
if (child.type === itemType) {
|
|
26
|
-
itemIndex++;
|
|
27
|
-
var indent = config.indent.repeat(depth);
|
|
28
|
-
var prefix = config.getPrefix(depth, itemIndex, child);
|
|
29
|
-
var listPrefix = schema.text("".concat(indent).concat(prefix));
|
|
30
|
-
|
|
31
|
-
// Collect inline content and nested lists separately
|
|
32
|
-
var inlineContent = [];
|
|
33
|
-
var nestedLists = [];
|
|
34
|
-
child.forEach(function (grandChild) {
|
|
35
|
-
if (grandChild.type === listType) {
|
|
36
|
-
nestedLists.push(grandChild);
|
|
37
|
-
} else if (config.unwrapParagraphContent && grandChild.type === paragraphType) {
|
|
38
|
-
// Extract content from paragraph nodes
|
|
39
|
-
grandChild.forEach(function (content) {
|
|
40
|
-
inlineContent.push(content);
|
|
41
|
-
});
|
|
42
|
-
} else {
|
|
43
|
-
inlineContent.push(grandChild);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Create paragraph with prefix + inline content
|
|
48
|
-
if (inlineContent.length > 0) {
|
|
49
|
-
var newContent = _model.Fragment.from(listPrefix).append(_model.Fragment.fromArray(inlineContent));
|
|
50
|
-
var newParagraph = paragraphType.create({}, newContent);
|
|
51
|
-
paragraphs.push(newParagraph);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Recursively process nested lists with increased depth
|
|
55
|
-
nestedLists.forEach(function (nestedList) {
|
|
56
|
-
_extract(nestedList, depth + 1);
|
|
57
|
-
});
|
|
58
|
-
} else if (child.type === listType) {
|
|
59
|
-
// Handle list that appears directly as a sibling
|
|
60
|
-
_extract(child, depth + 1);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
_extract(node, 0);
|
|
65
|
-
return paragraphs;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Creates a TransformStep that converts a list to paragraphs with text prefixes.
|
|
70
|
-
*
|
|
71
|
-
* Given an array of nodes, processes each list by converting its items
|
|
72
|
-
* to paragraphs with configurable prefixes.
|
|
73
|
-
*
|
|
74
|
-
* Handles nested lists recursively with configurable indentation per level.
|
|
75
|
-
*
|
|
76
|
-
* @param config - Configuration for the list-to-text transformation
|
|
77
|
-
* @returns A TransformStep function
|
|
78
|
-
*/
|
|
79
|
-
var createListToTextStep = exports.createListToTextStep = function createListToTextStep(config) {
|
|
80
|
-
return function (nodes, context) {
|
|
81
|
-
var schema = context.schema;
|
|
82
|
-
var listType = schema.nodes[config.listTypeName];
|
|
83
|
-
return nodes.flatMap(function (node) {
|
|
84
|
-
if (node.type === listType) {
|
|
85
|
-
return extractListItemsAsParagraphs(node, schema, config);
|
|
86
|
-
}
|
|
87
|
-
return node;
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
};
|
package/dist/es2019/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Given an array of nodes, processes each bullet list by converting its items
|
|
5
|
-
* to paragraphs with "- " prefix.
|
|
6
|
-
*
|
|
7
|
-
* Handles nested bullet lists recursively with 3-space indentation per level.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* Input:
|
|
11
|
-
* - bulletList()(
|
|
12
|
-
* listItem()(p()('Item 1')),
|
|
13
|
-
* bulletList()(listItem()(p()('Sub item 1')))
|
|
14
|
-
* )
|
|
15
|
-
*
|
|
16
|
-
* Output:
|
|
17
|
-
* - p()('- Item 1')
|
|
18
|
-
* - p()(' - Sub item 1')
|
|
19
|
-
*/
|
|
20
|
-
export const convertBulletListToTextStep = createListToTextStep({
|
|
21
|
-
listTypeName: 'bulletList',
|
|
22
|
-
itemTypeName: 'listItem',
|
|
23
|
-
indent: ' ',
|
|
24
|
-
// 3 spaces per nesting level
|
|
25
|
-
getPrefix: () => '- ',
|
|
26
|
-
unwrapParagraphContent: true
|
|
27
|
-
});
|
package/dist/es2019/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Converts a number to a letter (1=a, 2=b, etc.)
|
|
5
|
-
* For numbers > 26, continues with aa, ab, etc.
|
|
6
|
-
*/
|
|
7
|
-
const numberToLetter = num => {
|
|
8
|
-
let result = '';
|
|
9
|
-
let n = num;
|
|
10
|
-
while (n > 0) {
|
|
11
|
-
n--;
|
|
12
|
-
result = String.fromCharCode(97 + n % 26) + result;
|
|
13
|
-
n = Math.floor(n / 26);
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Gets the appropriate prefix for an ordered list item based on depth and index.
|
|
20
|
-
* - Level 0: "1. ", "2. ", "3. ", etc.
|
|
21
|
-
* - Level 1+: "a. ", "b. ", "c. ", etc.
|
|
22
|
-
*/
|
|
23
|
-
const getOrderedListPrefix = (depth, index) => {
|
|
24
|
-
if (depth === 0) {
|
|
25
|
-
return `${index}. `;
|
|
26
|
-
}
|
|
27
|
-
return `${numberToLetter(index)}. `;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Given an array of nodes, processes each ordered list by converting its items
|
|
32
|
-
* to paragraphs with numbered prefixes (1., 2., 3.) at the top level and
|
|
33
|
-
* lettered prefixes (a., b., c.) for nested levels.
|
|
34
|
-
*
|
|
35
|
-
* Handles nested ordered lists recursively with 3-space indentation per level.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* Input:
|
|
39
|
-
* - orderedList({ order: 1 })(
|
|
40
|
-
* listItem()(p()('Item 1')),
|
|
41
|
-
* orderedList({ order: 1 })(listItem()(p()('Sub item 1')))
|
|
42
|
-
* )
|
|
43
|
-
*
|
|
44
|
-
* Output:
|
|
45
|
-
* - p()('1. Item 1')
|
|
46
|
-
* - p()(' a. Sub item 1')
|
|
47
|
-
*/
|
|
48
|
-
export const convertOrderedListToTextStep = createListToTextStep({
|
|
49
|
-
listTypeName: 'orderedList',
|
|
50
|
-
itemTypeName: 'listItem',
|
|
51
|
-
indent: ' ',
|
|
52
|
-
// 3 spaces per nesting level
|
|
53
|
-
getPrefix: (depth, index) => getOrderedListPrefix(depth, index),
|
|
54
|
-
unwrapParagraphContent: true
|
|
55
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Given an array of nodes, processes each task list by converting its items
|
|
5
|
-
* to paragraphs with a checkbox prefix. Uses "[] " for unchecked (TODO) tasks
|
|
6
|
-
* and "[x] " for checked (DONE) tasks.
|
|
7
|
-
*
|
|
8
|
-
* Handles nested task lists recursively with 4-space indentation per level.
|
|
9
|
-
*
|
|
10
|
-
* This is used when converting a task list to a container that doesn't support
|
|
11
|
-
* task items (like blockquote).
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Input:
|
|
15
|
-
* - taskList()(
|
|
16
|
-
* taskItem({ state: 'TODO' })('Task list item'),
|
|
17
|
-
* taskList()(taskItem({ state: 'DONE' })('Nested done task'))
|
|
18
|
-
* )
|
|
19
|
-
*
|
|
20
|
-
* Output:
|
|
21
|
-
* - p()('[] Task list item')
|
|
22
|
-
* - p()(' [x] Nested done task')
|
|
23
|
-
*/
|
|
24
|
-
export const convertTaskListToTextStep = createListToTextStep({
|
|
25
|
-
listTypeName: 'taskList',
|
|
26
|
-
itemTypeName: 'taskItem',
|
|
27
|
-
indent: ' ',
|
|
28
|
-
// 4 spaces per nesting level
|
|
29
|
-
getPrefix: (_, __, itemNode) => {
|
|
30
|
-
var _itemNode$attrs;
|
|
31
|
-
return ((_itemNode$attrs = itemNode.attrs) === null || _itemNode$attrs === void 0 ? void 0 : _itemNode$attrs.state) === 'DONE' ? '[x] ' : '[] ';
|
|
32
|
-
},
|
|
33
|
-
unwrapParagraphContent: false
|
|
34
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for creating a list-to-text transformation step.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Recursively extracts list items from a list (including nested lists)
|
|
9
|
-
* and converts them to paragraphs with configurable prefixes and indentation.
|
|
10
|
-
*/
|
|
11
|
-
const extractListItemsAsParagraphs = (node, schema, config) => {
|
|
12
|
-
const paragraphs = [];
|
|
13
|
-
const paragraphType = schema.nodes.paragraph;
|
|
14
|
-
const listType = schema.nodes[config.listTypeName];
|
|
15
|
-
const itemType = schema.nodes[config.itemTypeName];
|
|
16
|
-
const extract = (currentNode, depth = 0) => {
|
|
17
|
-
let itemIndex = 0;
|
|
18
|
-
currentNode.forEach(child => {
|
|
19
|
-
if (child.type === itemType) {
|
|
20
|
-
itemIndex++;
|
|
21
|
-
const indent = config.indent.repeat(depth);
|
|
22
|
-
const prefix = config.getPrefix(depth, itemIndex, child);
|
|
23
|
-
const listPrefix = schema.text(`${indent}${prefix}`);
|
|
24
|
-
|
|
25
|
-
// Collect inline content and nested lists separately
|
|
26
|
-
const inlineContent = [];
|
|
27
|
-
const nestedLists = [];
|
|
28
|
-
child.forEach(grandChild => {
|
|
29
|
-
if (grandChild.type === listType) {
|
|
30
|
-
nestedLists.push(grandChild);
|
|
31
|
-
} else if (config.unwrapParagraphContent && grandChild.type === paragraphType) {
|
|
32
|
-
// Extract content from paragraph nodes
|
|
33
|
-
grandChild.forEach(content => {
|
|
34
|
-
inlineContent.push(content);
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
inlineContent.push(grandChild);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// Create paragraph with prefix + inline content
|
|
42
|
-
if (inlineContent.length > 0) {
|
|
43
|
-
const newContent = Fragment.from(listPrefix).append(Fragment.fromArray(inlineContent));
|
|
44
|
-
const newParagraph = paragraphType.create({}, newContent);
|
|
45
|
-
paragraphs.push(newParagraph);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Recursively process nested lists with increased depth
|
|
49
|
-
nestedLists.forEach(nestedList => {
|
|
50
|
-
extract(nestedList, depth + 1);
|
|
51
|
-
});
|
|
52
|
-
} else if (child.type === listType) {
|
|
53
|
-
// Handle list that appears directly as a sibling
|
|
54
|
-
extract(child, depth + 1);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
extract(node, 0);
|
|
59
|
-
return paragraphs;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Creates a TransformStep that converts a list to paragraphs with text prefixes.
|
|
64
|
-
*
|
|
65
|
-
* Given an array of nodes, processes each list by converting its items
|
|
66
|
-
* to paragraphs with configurable prefixes.
|
|
67
|
-
*
|
|
68
|
-
* Handles nested lists recursively with configurable indentation per level.
|
|
69
|
-
*
|
|
70
|
-
* @param config - Configuration for the list-to-text transformation
|
|
71
|
-
* @returns A TransformStep function
|
|
72
|
-
*/
|
|
73
|
-
export const createListToTextStep = config => {
|
|
74
|
-
return (nodes, context) => {
|
|
75
|
-
const {
|
|
76
|
-
schema
|
|
77
|
-
} = context;
|
|
78
|
-
const listType = schema.nodes[config.listTypeName];
|
|
79
|
-
return nodes.flatMap(node => {
|
|
80
|
-
if (node.type === listType) {
|
|
81
|
-
return extractListItemsAsParagraphs(node, schema, config);
|
|
82
|
-
}
|
|
83
|
-
return node;
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Given an array of nodes, processes each bullet list by converting its items
|
|
5
|
-
* to paragraphs with "- " prefix.
|
|
6
|
-
*
|
|
7
|
-
* Handles nested bullet lists recursively with 3-space indentation per level.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* Input:
|
|
11
|
-
* - bulletList()(
|
|
12
|
-
* listItem()(p()('Item 1')),
|
|
13
|
-
* bulletList()(listItem()(p()('Sub item 1')))
|
|
14
|
-
* )
|
|
15
|
-
*
|
|
16
|
-
* Output:
|
|
17
|
-
* - p()('- Item 1')
|
|
18
|
-
* - p()(' - Sub item 1')
|
|
19
|
-
*/
|
|
20
|
-
export var convertBulletListToTextStep = createListToTextStep({
|
|
21
|
-
listTypeName: 'bulletList',
|
|
22
|
-
itemTypeName: 'listItem',
|
|
23
|
-
indent: ' ',
|
|
24
|
-
// 3 spaces per nesting level
|
|
25
|
-
getPrefix: function getPrefix() {
|
|
26
|
-
return '- ';
|
|
27
|
-
},
|
|
28
|
-
unwrapParagraphContent: true
|
|
29
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Converts a number to a letter (1=a, 2=b, etc.)
|
|
5
|
-
* For numbers > 26, continues with aa, ab, etc.
|
|
6
|
-
*/
|
|
7
|
-
var numberToLetter = function numberToLetter(num) {
|
|
8
|
-
var result = '';
|
|
9
|
-
var n = num;
|
|
10
|
-
while (n > 0) {
|
|
11
|
-
n--;
|
|
12
|
-
result = String.fromCharCode(97 + n % 26) + result;
|
|
13
|
-
n = Math.floor(n / 26);
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Gets the appropriate prefix for an ordered list item based on depth and index.
|
|
20
|
-
* - Level 0: "1. ", "2. ", "3. ", etc.
|
|
21
|
-
* - Level 1+: "a. ", "b. ", "c. ", etc.
|
|
22
|
-
*/
|
|
23
|
-
var getOrderedListPrefix = function getOrderedListPrefix(depth, index) {
|
|
24
|
-
if (depth === 0) {
|
|
25
|
-
return "".concat(index, ". ");
|
|
26
|
-
}
|
|
27
|
-
return "".concat(numberToLetter(index), ". ");
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Given an array of nodes, processes each ordered list by converting its items
|
|
32
|
-
* to paragraphs with numbered prefixes (1., 2., 3.) at the top level and
|
|
33
|
-
* lettered prefixes (a., b., c.) for nested levels.
|
|
34
|
-
*
|
|
35
|
-
* Handles nested ordered lists recursively with 3-space indentation per level.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* Input:
|
|
39
|
-
* - orderedList({ order: 1 })(
|
|
40
|
-
* listItem()(p()('Item 1')),
|
|
41
|
-
* orderedList({ order: 1 })(listItem()(p()('Sub item 1')))
|
|
42
|
-
* )
|
|
43
|
-
*
|
|
44
|
-
* Output:
|
|
45
|
-
* - p()('1. Item 1')
|
|
46
|
-
* - p()(' a. Sub item 1')
|
|
47
|
-
*/
|
|
48
|
-
export var convertOrderedListToTextStep = createListToTextStep({
|
|
49
|
-
listTypeName: 'orderedList',
|
|
50
|
-
itemTypeName: 'listItem',
|
|
51
|
-
indent: ' ',
|
|
52
|
-
// 3 spaces per nesting level
|
|
53
|
-
getPrefix: function getPrefix(depth, index) {
|
|
54
|
-
return getOrderedListPrefix(depth, index);
|
|
55
|
-
},
|
|
56
|
-
unwrapParagraphContent: true
|
|
57
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { createListToTextStep } from './createListToTextStep';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Given an array of nodes, processes each task list by converting its items
|
|
5
|
-
* to paragraphs with a checkbox prefix. Uses "[] " for unchecked (TODO) tasks
|
|
6
|
-
* and "[x] " for checked (DONE) tasks.
|
|
7
|
-
*
|
|
8
|
-
* Handles nested task lists recursively with 4-space indentation per level.
|
|
9
|
-
*
|
|
10
|
-
* This is used when converting a task list to a container that doesn't support
|
|
11
|
-
* task items (like blockquote).
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Input:
|
|
15
|
-
* - taskList()(
|
|
16
|
-
* taskItem({ state: 'TODO' })('Task list item'),
|
|
17
|
-
* taskList()(taskItem({ state: 'DONE' })('Nested done task'))
|
|
18
|
-
* )
|
|
19
|
-
*
|
|
20
|
-
* Output:
|
|
21
|
-
* - p()('[] Task list item')
|
|
22
|
-
* - p()(' [x] Nested done task')
|
|
23
|
-
*/
|
|
24
|
-
export var convertTaskListToTextStep = createListToTextStep({
|
|
25
|
-
listTypeName: 'taskList',
|
|
26
|
-
itemTypeName: 'taskItem',
|
|
27
|
-
indent: ' ',
|
|
28
|
-
// 4 spaces per nesting level
|
|
29
|
-
getPrefix: function getPrefix(_, __, itemNode) {
|
|
30
|
-
var _itemNode$attrs;
|
|
31
|
-
return ((_itemNode$attrs = itemNode.attrs) === null || _itemNode$attrs === void 0 ? void 0 : _itemNode$attrs.state) === 'DONE' ? '[x] ' : '[] ';
|
|
32
|
-
},
|
|
33
|
-
unwrapParagraphContent: false
|
|
34
|
-
});
|