@atlaskit/editor-plugin-block-menu 6.0.4 → 6.0.6
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 +15 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +46 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/mergeNeighbourListsStep.js +91 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/wrapBlockquoteToDecisionListStep.js +2 -12
- package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +69 -52
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +45 -30
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +10 -1
- package/dist/cjs/editor-commands/transformNode.js +65 -65
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +28 -0
- package/dist/es2019/editor-commands/transform-node-utils/steps/mergeNeighbourListsStep.js +75 -0
- package/dist/es2019/editor-commands/transform-node-utils/steps/wrapBlockquoteToDecisionListStep.js +1 -11
- package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +71 -53
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +44 -29
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +10 -0
- package/dist/es2019/editor-commands/transformNode.js +64 -67
- package/dist/esm/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +39 -0
- package/dist/esm/editor-commands/transform-node-utils/steps/mergeNeighbourListsStep.js +85 -0
- package/dist/esm/editor-commands/transform-node-utils/steps/wrapBlockquoteToDecisionListStep.js +1 -11
- package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +70 -53
- package/dist/esm/editor-commands/transform-node-utils/transform.js +44 -29
- package/dist/esm/editor-commands/transform-node-utils/utils.js +10 -0
- package/dist/esm/editor-commands/transformNode.js +64 -65
- package/dist/types/editor-commands/transform-node-utils/steps/convertEachNodeStep.d.ts +2 -0
- package/dist/types/editor-commands/transform-node-utils/steps/mergeNeighbourListsStep.d.ts +32 -0
- package/dist/types/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +17 -2
- package/dist/types/editor-commands/transform-node-utils/transform.d.ts +16 -1
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +5 -0
- package/dist/types/editor-commands/transformNode.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertEachNodeStep.d.ts +2 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/mergeNeighbourListsStep.d.ts +32 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +17 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/transform.d.ts +16 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +5 -0
- package/dist/types-ts4.5/editor-commands/transformNode.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/editor-commands/transform-node-utils/tranformContent.js +0 -19
- package/dist/cjs/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +0 -20
- package/dist/es2019/editor-commands/transform-node-utils/tranformContent.js +0 -13
- package/dist/es2019/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +0 -17
- package/dist/esm/editor-commands/transform-node-utils/tranformContent.js +0 -13
- package/dist/esm/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +0 -14
- package/dist/types/editor-commands/transform-node-utils/tranformContent.d.ts +0 -3
- package/dist/types/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +0 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/tranformContent.d.ts +0 -3
- package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 6.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`27a9a5b28e8a6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/27a9a5b28e8a6) -
|
|
8
|
+
[ux] Add ability to transform multiselected content to layouts
|
|
9
|
+
|
|
10
|
+
## 6.0.5
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`1c4801e3e64b4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1c4801e3e64b4) -
|
|
15
|
+
[ux] Add ability for multi selected block transformations to lists
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 6.0.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.convertEachNodeStep = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _transform = require("../transform");
|
|
10
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
+
var convertEachNodeStep = exports.convertEachNodeStep = function convertEachNodeStep(nodes, context) {
|
|
14
|
+
var schema = context.schema,
|
|
15
|
+
targetNodeTypeName = context.targetNodeTypeName,
|
|
16
|
+
targetAttrs = context.targetAttrs;
|
|
17
|
+
var targetNodeType = schema.nodes[targetNodeTypeName];
|
|
18
|
+
if (!targetNodeType) {
|
|
19
|
+
return nodes;
|
|
20
|
+
}
|
|
21
|
+
var resultNodes = [];
|
|
22
|
+
var _iterator = _createForOfIteratorHelper(nodes),
|
|
23
|
+
_step;
|
|
24
|
+
try {
|
|
25
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
26
|
+
var node = _step.value;
|
|
27
|
+
var transformedNodes = (0, _transform.convertNodesToTargetType)({
|
|
28
|
+
sourceNodes: [node],
|
|
29
|
+
targetNodeType: targetNodeType,
|
|
30
|
+
schema: schema,
|
|
31
|
+
isNested: false,
|
|
32
|
+
targetAttrs: targetAttrs
|
|
33
|
+
});
|
|
34
|
+
if (transformedNodes.length > 0) {
|
|
35
|
+
resultNodes.push.apply(resultNodes, (0, _toConsumableArray2.default)(transformedNodes));
|
|
36
|
+
} else {
|
|
37
|
+
resultNodes.push(node);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
_iterator.e(err);
|
|
42
|
+
} finally {
|
|
43
|
+
_iterator.f();
|
|
44
|
+
}
|
|
45
|
+
return resultNodes;
|
|
46
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergeNeighbourListsStep = void 0;
|
|
7
|
+
var _nodeChecks = require("../nodeChecks");
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
/**
|
|
12
|
+
* Merges consecutive lists of the same type into a single list.
|
|
13
|
+
* This step is useful after multiToListStep which may create multiple separate lists
|
|
14
|
+
* that should be combined.
|
|
15
|
+
*
|
|
16
|
+
* Handles both nestable lists (bulletList, orderedList, taskList) and
|
|
17
|
+
* non-nestable lists (decisionList).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* Input:
|
|
21
|
+
* - bulletList
|
|
22
|
+
* - listItem "1"
|
|
23
|
+
* - bulletList
|
|
24
|
+
* - listItem "2"
|
|
25
|
+
* - panel (non-list node)
|
|
26
|
+
* - bulletList
|
|
27
|
+
* - listItem "3"
|
|
28
|
+
*
|
|
29
|
+
* Output:
|
|
30
|
+
* - bulletList
|
|
31
|
+
* - listItem "1"
|
|
32
|
+
* - listItem "2"
|
|
33
|
+
* - panel (non-list node)
|
|
34
|
+
* - bulletList
|
|
35
|
+
* - listItem "3"
|
|
36
|
+
*
|
|
37
|
+
* @param nodes - The nodes to process
|
|
38
|
+
* @param context - The transformation context
|
|
39
|
+
* @returns The merged nodes
|
|
40
|
+
*/
|
|
41
|
+
var mergeNeighbourListsStep = exports.mergeNeighbourListsStep = function mergeNeighbourListsStep(nodes, context) {
|
|
42
|
+
if (nodes.length === 0) {
|
|
43
|
+
return nodes;
|
|
44
|
+
}
|
|
45
|
+
var schema = context.schema;
|
|
46
|
+
var resultNodes = [];
|
|
47
|
+
var currentList = null;
|
|
48
|
+
|
|
49
|
+
// Check if a node is any type of list (including decisionList)
|
|
50
|
+
var isList = function isList(node) {
|
|
51
|
+
return (0, _nodeChecks.isListWithIndentation)(node.type.name, schema) || node.type.name === 'decisionList';
|
|
52
|
+
};
|
|
53
|
+
var _iterator = _createForOfIteratorHelper(nodes),
|
|
54
|
+
_step;
|
|
55
|
+
try {
|
|
56
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
|
+
var node = _step.value;
|
|
58
|
+
// Check if this node is any type of list
|
|
59
|
+
if (isList(node)) {
|
|
60
|
+
if (currentList && currentList.type === node.type) {
|
|
61
|
+
// Merge with the current list by combining their children
|
|
62
|
+
var mergedContent = currentList.content.append(node.content);
|
|
63
|
+
currentList = currentList.type.create(currentList.attrs, mergedContent);
|
|
64
|
+
} else {
|
|
65
|
+
// Start a new list or switch to a different list type
|
|
66
|
+
if (currentList) {
|
|
67
|
+
resultNodes.push(currentList);
|
|
68
|
+
}
|
|
69
|
+
currentList = node;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
// Non-list node - push any accumulated list and then this node
|
|
73
|
+
if (currentList) {
|
|
74
|
+
resultNodes.push(currentList);
|
|
75
|
+
currentList = null;
|
|
76
|
+
}
|
|
77
|
+
resultNodes.push(node);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Don't forget the last list if we ended with one
|
|
82
|
+
} catch (err) {
|
|
83
|
+
_iterator.e(err);
|
|
84
|
+
} finally {
|
|
85
|
+
_iterator.f();
|
|
86
|
+
}
|
|
87
|
+
if (currentList) {
|
|
88
|
+
resultNodes.push(currentList);
|
|
89
|
+
}
|
|
90
|
+
return resultNodes;
|
|
91
|
+
};
|
package/dist/cjs/editor-commands/transform-node-utils/steps/wrapBlockquoteToDecisionListStep.js
CHANGED
|
@@ -4,17 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.wrapBlockquoteToDecisionListStep = void 0;
|
|
7
|
-
var
|
|
8
|
-
/**
|
|
9
|
-
* Determines if a node is a text node (heading or paragraph).
|
|
10
|
-
* Only text nodes should have their inline content extracted for decisionItem.
|
|
11
|
-
* All other nodes should break out.
|
|
12
|
-
*/
|
|
13
|
-
var isTextNode = function isTextNode(node) {
|
|
14
|
-
var category = _types.NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
15
|
-
return category === 'text';
|
|
16
|
-
};
|
|
17
|
-
|
|
7
|
+
var _utils = require("../utils");
|
|
18
8
|
/**
|
|
19
9
|
* Creates a decisionItem with the given inline content.
|
|
20
10
|
*/
|
|
@@ -74,7 +64,7 @@ var wrapBlockquoteToDecisionListStep = exports.wrapBlockquoteToDecisionListStep
|
|
|
74
64
|
}
|
|
75
65
|
};
|
|
76
66
|
nodes.forEach(function (node) {
|
|
77
|
-
var decisionItem = isTextNode(node) ? createDecisionItem(node.content, schema) : null;
|
|
67
|
+
var decisionItem = (0, _utils.isTextNode)(node) ? createDecisionItem(node.content, schema) : null;
|
|
78
68
|
if (decisionItem) {
|
|
79
69
|
// Accumulate consecutive decisionItems
|
|
80
70
|
currentDecisionItems.push(decisionItem);
|
|
@@ -10,33 +10,6 @@ var _model = require("@atlaskit/editor-prosemirror/model");
|
|
|
10
10
|
var _marks = require("../marks");
|
|
11
11
|
var _types = require("../types");
|
|
12
12
|
var _utils = require("../utils");
|
|
13
|
-
/**
|
|
14
|
-
* Determines if a node is a text node (heading or paragraph).
|
|
15
|
-
* Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
|
|
16
|
-
*/
|
|
17
|
-
var isTextNode = function isTextNode(node) {
|
|
18
|
-
var category = _types.NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
19
|
-
return category === 'text';
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Determines if a node can be wrapped in the target container type, removes block marks from the node during check.
|
|
24
|
-
* Uses the schema's validContent to check if the target container can hold this node.
|
|
25
|
-
*
|
|
26
|
-
* Note: What can be wrapped depends on the target container type - for example:
|
|
27
|
-
* - Tables and media CAN go inside expand nodes
|
|
28
|
-
* - Tables CANNOT go inside panels or blockquotes
|
|
29
|
-
*/
|
|
30
|
-
var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeTypeName) {
|
|
31
|
-
// Same-type containers should break out as separate containers
|
|
32
|
-
if (node.type.name === targetNodeTypeName) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Use the schema to determine if this node can be contained in the target
|
|
37
|
-
return targetNodeType.validContent(_model.Fragment.from((0, _marks.removeDisallowedMarks)([node], targetNodeType)));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
13
|
/**
|
|
41
14
|
* Handles the edge case where transforming from a container to another container results in
|
|
42
15
|
* all content breaking out (no valid children for the target). In this case, creates an empty
|
|
@@ -75,18 +48,33 @@ var handleEmptyContainerEdgeCase = function handleEmptyContainerEdgeCase(result,
|
|
|
75
48
|
* - Same-type containers break out as separate containers (preserved as-is)
|
|
76
49
|
* - NestedExpands break out as regular expands (converted since nestedExpand can't exist outside expand)
|
|
77
50
|
* - Container structures that can't be nested in target break out (not flattened)
|
|
78
|
-
* - Text/list nodes that can't be wrapped are
|
|
51
|
+
* - Text/list nodes that can't be wrapped are converted to paragraphs and merged into the container
|
|
79
52
|
* - Atomic nodes (tables, media, macros) break out
|
|
80
53
|
*
|
|
54
|
+
* Special handling for layouts:
|
|
55
|
+
* - Layout sections break out as separate layouts (preserved as-is, not wrapped)
|
|
56
|
+
* - Other nodes (including headings, paragraphs, lists) are wrapped into layout columns within a layout section
|
|
57
|
+
* - Layouts always require layoutColumns as children (never paragraphs directly)
|
|
58
|
+
* - Layout columns can contain most block content including headings, paragraphs, lists, etc.
|
|
59
|
+
*
|
|
60
|
+
* Edge case handling:
|
|
61
|
+
* - For regular containers: If all content breaks out (container → container transform with no
|
|
62
|
+
* valid children), an empty container with a paragraph is created to ensure the target type exists
|
|
63
|
+
* - For layouts: Edge case handling is skipped because layouts require columns, not direct paragraphs.
|
|
64
|
+
* If all content breaks out, only the broken-out nodes are returned (no empty layout created)
|
|
65
|
+
*
|
|
81
66
|
* What can be wrapped depends on the target container's schema:
|
|
82
67
|
* - expand → panel: tables break out, nestedExpands convert to expands and break out
|
|
83
|
-
* - expand → blockquote: tables/media break out, nestedExpands convert to expands and break out
|
|
68
|
+
* - expand → blockquote: tables/media break out, nestedExpands convert to expands and break out, headings converted to paragraphs
|
|
84
69
|
* - expand → expand: tables/media stay inside (expands can contain them)
|
|
70
|
+
* - multi → layoutSection: layout sections break out, headings/paragraphs/lists wrapped into layout columns
|
|
85
71
|
*
|
|
86
72
|
* Example: expand(p('a'), table(), p('b')) → panel: [panel(p('a')), table(), panel(p('b'))]
|
|
87
73
|
* Example: expand(p('a'), panel(p('x')), p('b')) → panel: [panel(p('a')), panel(p('x')), panel(p('b'))]
|
|
88
74
|
* Example: expand(p('a'), nestedExpand({title: 'inner'})(p('x')), p('b')) → panel: [panel(p('a')), expand({title: 'inner'})(p('x')), panel(p('b'))]
|
|
89
75
|
* Example: expand(nestedExpand()(p())) → panel: [panel(), expand()(p())] (empty panel when all content breaks out)
|
|
76
|
+
* Example: [p('a'), layoutSection(...), p('b')] → layoutSection: [layoutSection(layoutColumn(p('a'))), layoutSection(...), layoutSection(layoutColumn(p('b')))]
|
|
77
|
+
* Example: [h1('heading'), p('para')] → layoutSection: [layoutSection(layoutColumn(h1('heading'), p('para')))] (headings stay as headings in layouts)
|
|
90
78
|
*/
|
|
91
79
|
var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedContentStep(nodes, context) {
|
|
92
80
|
var schema = context.schema,
|
|
@@ -96,49 +84,78 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
|
|
|
96
84
|
if (!targetNodeType) {
|
|
97
85
|
return nodes;
|
|
98
86
|
}
|
|
87
|
+
var isLayout = targetNodeTypeName === 'layoutSection';
|
|
88
|
+
var _schema$nodes = schema.nodes,
|
|
89
|
+
layoutSection = _schema$nodes.layoutSection,
|
|
90
|
+
layoutColumn = _schema$nodes.layoutColumn;
|
|
99
91
|
var result = [];
|
|
100
92
|
var currentContainerContent = [];
|
|
101
93
|
var hasCreatedContainer = false;
|
|
102
94
|
var flushCurrentContainer = function flushCurrentContainer() {
|
|
103
|
-
if (currentContainerContent.length
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
if (currentContainerContent.length === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (isLayout) {
|
|
99
|
+
// For layouts, create layoutSection with two layoutColumns
|
|
100
|
+
var columnOne = layoutColumn.createAndFill({}, (0, _marks.removeDisallowedMarks)(currentContainerContent, layoutColumn));
|
|
101
|
+
var columnTwo = layoutColumn.createAndFill();
|
|
102
|
+
if (!columnOne || !columnTwo) {
|
|
103
|
+
currentContainerContent = [];
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
var layout = layoutSection.createAndFill({}, [columnOne, columnTwo]);
|
|
107
|
+
if (layout) {
|
|
108
|
+
result.push(layout);
|
|
107
109
|
hasCreatedContainer = true;
|
|
108
110
|
}
|
|
109
111
|
currentContainerContent = [];
|
|
112
|
+
return;
|
|
110
113
|
}
|
|
114
|
+
|
|
115
|
+
// For regular containers, create directly
|
|
116
|
+
var containerNode = targetNodeType.createAndFill({}, currentContainerContent);
|
|
117
|
+
if (containerNode) {
|
|
118
|
+
result.push(containerNode);
|
|
119
|
+
hasCreatedContainer = true;
|
|
120
|
+
}
|
|
121
|
+
currentContainerContent = [];
|
|
111
122
|
};
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
var processNode = function processNode(node) {
|
|
124
|
+
var validationType = isLayout ? layoutColumn : targetNodeType;
|
|
125
|
+
var canWrapNode = validationType.validContent(_model.Fragment.from((0, _marks.removeDisallowedMarks)([node], validationType)));
|
|
126
|
+
|
|
127
|
+
// Node can be wrapped - add to current container content
|
|
128
|
+
if (canWrapNode) {
|
|
114
129
|
var _currentContainerCont;
|
|
115
|
-
// Node can be wrapped - add to current container content
|
|
116
130
|
// remove marks from node as nested nodes don't usually support block marks
|
|
117
|
-
(_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)((0, _marks.removeDisallowedMarks)([node],
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
125
|
-
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
131
|
+
(_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)((0, _marks.removeDisallowedMarks)([node], validationType)));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
136
|
+
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
137
|
+
if ((0, _utils.isTextNode)(node)) {
|
|
126
138
|
var paragraph = (0, _utils.convertTextNodeToParagraph)(node, schema);
|
|
127
139
|
if (paragraph) {
|
|
128
140
|
currentContainerContent.push(paragraph);
|
|
129
141
|
}
|
|
130
|
-
|
|
131
|
-
// All other nodes that cannot be wrapped (lists, containers, tables, media, macros) - break out
|
|
132
|
-
// This includes list nodes like taskList that can't be placed in certain containers
|
|
133
|
-
flushCurrentContainer();
|
|
134
|
-
result.push(node);
|
|
142
|
+
return;
|
|
135
143
|
}
|
|
136
|
-
|
|
144
|
+
|
|
145
|
+
// All other nodes that cannot be wrapped in the target node - break out
|
|
146
|
+
// Examples: same-type containers, tables in panels, layoutSections in layouts
|
|
147
|
+
flushCurrentContainer();
|
|
148
|
+
result.push(node);
|
|
149
|
+
};
|
|
150
|
+
nodes.forEach(processNode);
|
|
137
151
|
|
|
138
152
|
// Flush any remaining content into a container
|
|
139
153
|
flushCurrentContainer();
|
|
140
154
|
|
|
141
|
-
//
|
|
155
|
+
// Skip edge case handling for layouts since layouts always have columns
|
|
156
|
+
if (isLayout) {
|
|
157
|
+
return result.length > 0 ? result : nodes;
|
|
158
|
+
}
|
|
142
159
|
var finalResult = handleEmptyContainerEdgeCase(result, hasCreatedContainer, fromNode, targetNodeType, targetNodeTypeName, schema);
|
|
143
160
|
return finalResult.length > 0 ? finalResult : nodes;
|
|
144
161
|
};
|
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isTransformDisabledBasedOnStepsConfig = exports.
|
|
6
|
+
exports.isTransformDisabledBasedOnStepsConfig = exports.convertNodesToTargetType = void 0;
|
|
7
7
|
var _utils = require("../transform-node-utils/utils");
|
|
8
8
|
var _flattenStep = require("./flattenStep");
|
|
9
9
|
var _applyTargetTextTypeStep = require("./steps/applyTargetTextTypeStep");
|
|
10
|
+
var _convertEachNodeStep = require("./steps/convertEachNodeStep");
|
|
10
11
|
var _decisionListToListStep = require("./steps/decisionListToListStep");
|
|
11
12
|
var _flattenListStep = require("./steps/flattenListStep");
|
|
12
13
|
var _listToDecisionListStep = require("./steps/listToDecisionListStep");
|
|
13
14
|
var _listToListStep = require("./steps/listToListStep");
|
|
15
|
+
var _mergeNeighbourListsStep = require("./steps/mergeNeighbourListsStep");
|
|
14
16
|
var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
|
|
15
17
|
var _unwrapListStep = require("./steps/unwrapListStep");
|
|
16
18
|
var _wrapBlockquoteToDecisionListStep = require("./steps/wrapBlockquoteToDecisionListStep");
|
|
@@ -19,7 +21,6 @@ var _wrapTextToCodeblock = require("./steps/wrapTextToCodeblock");
|
|
|
19
21
|
var _types = require("./types");
|
|
20
22
|
var _unwrapExpandStep = require("./unwrapExpandStep");
|
|
21
23
|
var _unwrapStep = require("./unwrapStep");
|
|
22
|
-
var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
|
|
23
24
|
var _wrapIntoListStep = require("./wrapIntoListStep");
|
|
24
25
|
var _wrapStep = require("./wrapStep");
|
|
25
26
|
// Transform steps for combinations of node categories (block/container/list/text)
|
|
@@ -55,10 +56,8 @@ var TRANSFORM_STEPS = {
|
|
|
55
56
|
multi: {
|
|
56
57
|
atomic: undefined,
|
|
57
58
|
container: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// TODO: EDITOR-4140 - Implement multi text transform
|
|
61
|
-
text: undefined,
|
|
59
|
+
list: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
|
|
60
|
+
text: [_convertEachNodeStep.convertEachNodeStep],
|
|
62
61
|
multi: undefined
|
|
63
62
|
}
|
|
64
63
|
};
|
|
@@ -70,15 +69,15 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
70
69
|
paragraph: {
|
|
71
70
|
paragraph: null,
|
|
72
71
|
codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
|
|
73
|
-
layoutSection: [
|
|
72
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
|
|
74
73
|
},
|
|
75
74
|
heading: {
|
|
76
75
|
codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
|
|
77
|
-
layoutSection: [
|
|
76
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
|
|
78
77
|
},
|
|
79
78
|
panel: {
|
|
80
79
|
panel: null,
|
|
81
|
-
layoutSection: [_unwrapStep.unwrapStep,
|
|
80
|
+
layoutSection: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
82
81
|
codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
|
|
83
82
|
blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
84
83
|
taskList: null,
|
|
@@ -90,7 +89,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
90
89
|
expand: null,
|
|
91
90
|
panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
92
91
|
blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
93
|
-
layoutSection: [_unwrapExpandStep.unwrapExpandStep,
|
|
92
|
+
layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
94
93
|
paragraph: [_unwrapExpandStep.unwrapExpandStep],
|
|
95
94
|
codeBlock: null,
|
|
96
95
|
heading: null
|
|
@@ -108,7 +107,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
108
107
|
blockquote: null,
|
|
109
108
|
expand: [_wrapStep.wrapStep],
|
|
110
109
|
nestedExpand: [_wrapStep.wrapStep],
|
|
111
|
-
layoutSection: [
|
|
110
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
112
111
|
codeBlock: null,
|
|
113
112
|
decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
|
|
114
113
|
},
|
|
@@ -126,34 +125,34 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
126
125
|
blockquote: [_wrapStep.wrapStep],
|
|
127
126
|
expand: [_wrapStep.wrapStep],
|
|
128
127
|
nestedExpand: [_wrapStep.wrapStep],
|
|
129
|
-
layoutSection: [
|
|
128
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
130
129
|
panel: [_wrapStep.wrapStep],
|
|
131
130
|
heading: null
|
|
132
131
|
},
|
|
133
132
|
bulletList: {
|
|
134
133
|
bulletList: null,
|
|
135
134
|
codeBlock: null,
|
|
136
|
-
layoutSection: [
|
|
135
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
137
136
|
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
138
137
|
heading: null
|
|
139
138
|
},
|
|
140
139
|
orderedList: {
|
|
141
140
|
orderedList: null,
|
|
142
141
|
codeBlock: null,
|
|
143
|
-
layoutSection: [
|
|
142
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
144
143
|
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
145
144
|
heading: null
|
|
146
145
|
},
|
|
147
146
|
taskList: {
|
|
148
147
|
blockquote: null,
|
|
149
148
|
codeBlock: null,
|
|
150
|
-
layoutSection: [
|
|
149
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
151
150
|
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
152
151
|
heading: null,
|
|
153
152
|
taskList: null
|
|
154
153
|
},
|
|
155
154
|
table: {
|
|
156
|
-
layoutSection: [
|
|
155
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
157
156
|
blockquote: null,
|
|
158
157
|
panel: null,
|
|
159
158
|
codeBlock: null,
|
|
@@ -163,13 +162,13 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
163
162
|
decisionList: null
|
|
164
163
|
},
|
|
165
164
|
mediaSingle: {
|
|
166
|
-
layoutSection: [
|
|
165
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
167
166
|
codeBlock: null,
|
|
168
167
|
decisionList: null,
|
|
169
168
|
taskList: null
|
|
170
169
|
},
|
|
171
170
|
mediaGroup: {
|
|
172
|
-
layoutSection: [
|
|
171
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
173
172
|
codeBlock: null,
|
|
174
173
|
decisionList: null,
|
|
175
174
|
bulletList: null,
|
|
@@ -181,10 +180,10 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
181
180
|
bulletList: [_decisionListToListStep.decisionListToListStep],
|
|
182
181
|
orderedList: [_decisionListToListStep.decisionListToListStep],
|
|
183
182
|
taskList: [_decisionListToListStep.decisionListToListStep],
|
|
184
|
-
layoutSection: [
|
|
183
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
|
|
185
184
|
},
|
|
186
185
|
blockCard: {
|
|
187
|
-
layoutSection: [
|
|
186
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
188
187
|
blockquote: null,
|
|
189
188
|
codeBlock: null,
|
|
190
189
|
orderedList: null,
|
|
@@ -193,7 +192,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
193
192
|
decisionList: null
|
|
194
193
|
},
|
|
195
194
|
embedCard: {
|
|
196
|
-
layoutSection: [
|
|
195
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
197
196
|
blockquote: null,
|
|
198
197
|
panel: null,
|
|
199
198
|
codeBlock: null,
|
|
@@ -203,7 +202,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
203
202
|
decisionList: null
|
|
204
203
|
},
|
|
205
204
|
extension: {
|
|
206
|
-
layoutSection: [
|
|
205
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
207
206
|
codeBlock: null,
|
|
208
207
|
decisionList: null,
|
|
209
208
|
taskList: null,
|
|
@@ -211,7 +210,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
211
210
|
bulletList: null
|
|
212
211
|
},
|
|
213
212
|
bodiedExtension: {
|
|
214
|
-
layoutSection: [
|
|
213
|
+
layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
|
|
215
214
|
blockquote: null,
|
|
216
215
|
expand: null,
|
|
217
216
|
panel: null,
|
|
@@ -222,8 +221,10 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
222
221
|
decisionList: null
|
|
223
222
|
},
|
|
224
223
|
multi: {
|
|
225
|
-
// TODO: EDITOR-
|
|
226
|
-
|
|
224
|
+
// TODO: EDITOR-4140 - Implement multiple paragraphs/headings/codeblocks to heading transform
|
|
225
|
+
heading: null,
|
|
226
|
+
// TODO: EDITOR-4141 - Implement multiple codeblocks/headings to paragraph transform
|
|
227
|
+
paragraph: null
|
|
227
228
|
}
|
|
228
229
|
};
|
|
229
230
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
@@ -237,7 +238,22 @@ var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selec
|
|
|
237
238
|
var steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
|
|
238
239
|
return steps;
|
|
239
240
|
};
|
|
240
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Convert a list of nodes to a target node type.
|
|
243
|
+
* If no steps are found, the source nodes are returned unchanged.
|
|
244
|
+
* If steps are found, they are applied to the source nodes in order.
|
|
245
|
+
* If a step returns an empty array, the source nodes are returned.
|
|
246
|
+
* If a step returns a non-empty array, that array is returned.
|
|
247
|
+
* @param args - The conversion arguments
|
|
248
|
+
* @param args.sourceNodes - The list of nodes to convert
|
|
249
|
+
* @param args.targetNodeType - The type of node to convert into
|
|
250
|
+
* @param args.schema - The schema to use for the conversion
|
|
251
|
+
* @param args.isNested - Whether the conversion is nested
|
|
252
|
+
* @param args.targetAttrs - The attributes to use for the conversion
|
|
253
|
+
* @param args.parentNode - The parent node of the selected node
|
|
254
|
+
* @returns The converted list of nodes
|
|
255
|
+
*/
|
|
256
|
+
var convertNodesToTargetType = exports.convertNodesToTargetType = function convertNodesToTargetType(_ref) {
|
|
241
257
|
var sourceNodes = _ref.sourceNodes,
|
|
242
258
|
targetNodeType = _ref.targetNodeType,
|
|
243
259
|
schema = _ref.schema,
|
|
@@ -246,14 +262,13 @@ var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
|
|
|
246
262
|
parentNode = _ref.parentNode;
|
|
247
263
|
var sourceNode = sourceNodes.at(0);
|
|
248
264
|
if (!sourceNode) {
|
|
249
|
-
return;
|
|
265
|
+
return sourceNodes;
|
|
250
266
|
}
|
|
251
267
|
var selectedNodeTypeName = (0, _types.toNodeTypeValue)((0, _types.getNodeName)(sourceNodes));
|
|
252
268
|
var initialTargetNodeTypeName = (0, _types.toNodeTypeValue)(targetNodeType.name);
|
|
253
269
|
var targetNodeTypeName = (0, _utils.getTargetNodeTypeNameInContext)(initialTargetNodeTypeName, isNested, parentNode);
|
|
254
270
|
if (!selectedNodeTypeName || !targetNodeTypeName) {
|
|
255
|
-
|
|
256
|
-
return;
|
|
271
|
+
return sourceNodes;
|
|
257
272
|
}
|
|
258
273
|
var steps = getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName);
|
|
259
274
|
var context = {
|
|
@@ -264,7 +279,7 @@ var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
|
|
|
264
279
|
targetAttrs: targetAttrs
|
|
265
280
|
};
|
|
266
281
|
if (!steps || steps.length === 0) {
|
|
267
|
-
return;
|
|
282
|
+
return sourceNodes;
|
|
268
283
|
}
|
|
269
284
|
return steps.reduce(function (nodes, step) {
|
|
270
285
|
return step(nodes, context);
|
|
@@ -3,10 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.createTextContent = exports.convertTextNodeToParagraph = exports.convertNestedExpandToExpand = exports.convertExpandToNestedExpand = void 0;
|
|
6
|
+
exports.isTextNode = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.createTextContent = exports.convertTextNodeToParagraph = exports.convertNestedExpandToExpand = exports.convertExpandToNestedExpand = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
8
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
9
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
10
|
+
var _types = require("./types");
|
|
11
|
+
/**
|
|
12
|
+
* Determines if a node is a text node (heading or paragraph).
|
|
13
|
+
* Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
|
|
14
|
+
*/
|
|
15
|
+
var isTextNode = exports.isTextNode = function isTextNode(node) {
|
|
16
|
+
var category = _types.NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
17
|
+
return category === 'text';
|
|
18
|
+
};
|
|
10
19
|
var getSelectedNode = exports.getSelectedNode = function getSelectedNode(selection) {
|
|
11
20
|
if (selection instanceof _state.NodeSelection) {
|
|
12
21
|
return {
|