@atlaskit/adf-utils 16.0.0 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/builders/package.json +1 -0
- package/codemods/17.0.0-update-imports-to-new-entry-points.ts +175 -0
- package/codemods/__tests__/next-update-imports-to-new-entry-points.ts +175 -0
- package/codemods/helpers/entry-points.ts +33 -0
- package/codemods/types/entry-points.ts +12 -0
- package/dist/cjs/index.js +1 -447
- package/dist/cjs/scrub/scrub-content.js +5 -5
- package/dist/cjs/transforms/dedupe-marks-transform.js +120 -0
- package/dist/cjs/transforms/indentation-marks-transform.js +66 -0
- package/dist/cjs/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
- package/dist/cjs/transforms/nodes-missing-content-transform.js +205 -0
- package/dist/cjs/transforms.js +45 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +2 -7
- package/dist/es2019/transforms/dedupe-marks-transform.js +97 -0
- package/dist/es2019/transforms/indentation-marks-transform.js +45 -0
- package/dist/es2019/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
- package/dist/es2019/transforms/nodes-missing-content-transform.js +175 -0
- package/dist/es2019/transforms.js +5 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +2 -7
- package/dist/esm/scrub/scrub-content.js +5 -5
- package/dist/esm/transforms/dedupe-marks-transform.js +108 -0
- package/dist/esm/transforms/indentation-marks-transform.js +55 -0
- package/dist/esm/{media-link-transform.js → transforms/media-link-transform.js} +1 -1
- package/dist/esm/transforms/nodes-missing-content-transform.js +192 -0
- package/dist/esm/transforms.js +5 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/builders/marks/breakout.d.ts +1 -1
- package/dist/types/index.d.ts +1 -9
- package/dist/types/transforms/dedupe-marks-transform.d.ts +8 -0
- package/dist/types/transforms/indentation-marks-transform.d.ts +7 -0
- package/dist/types/{media-link-transform.d.ts → transforms/media-link-transform.d.ts} +1 -1
- package/dist/types/transforms/nodes-missing-content-transform.d.ts +7 -0
- package/dist/types/transforms.d.ts +5 -0
- package/dist/types/validator.d.ts +0 -1
- package/empty-adf/package.json +1 -0
- package/package.json +15 -4
- package/scrub/package.json +1 -0
- package/transforms/package.json +8 -0
- package/traverse/package.json +1 -0
- package/tsconfig.json +2 -1
- package/types/package.json +8 -0
- package/validator/package.json +1 -0
- package/validatorTypes/package.json +8 -0
- package/media-link-transform/package.json +0 -7
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.transformIndentationMarks = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _traverse = require("../traverse/traverse");
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
var hasChildHeadingWithIndentation = function hasChildHeadingWithIndentation(node) {
|
|
19
|
+
var _node$content$some, _node$content;
|
|
20
|
+
|
|
21
|
+
return (_node$content$some = (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.some(function (childNode) {
|
|
22
|
+
var _childNode$marks;
|
|
23
|
+
|
|
24
|
+
return (childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading' && (childNode === null || childNode === void 0 ? void 0 : (_childNode$marks = childNode.marks) === null || _childNode$marks === void 0 ? void 0 : _childNode$marks.some(function (mark) {
|
|
25
|
+
return mark.type === 'indentation';
|
|
26
|
+
}));
|
|
27
|
+
})) !== null && _node$content$some !== void 0 ? _node$content$some : false;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var removeIndentationFromHeadings = function removeIndentationFromHeadings(node) {
|
|
31
|
+
var _node$content2;
|
|
32
|
+
|
|
33
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
34
|
+
content: (_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.map(function (childNode) {
|
|
35
|
+
if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading') {
|
|
36
|
+
var _childNode$marks2;
|
|
37
|
+
|
|
38
|
+
return _objectSpread(_objectSpread({}, childNode), {}, {
|
|
39
|
+
marks: (_childNode$marks2 = childNode.marks) === null || _childNode$marks2 === void 0 ? void 0 : _childNode$marks2.filter(function (mark) {
|
|
40
|
+
return mark.type !== 'indentation';
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return childNode;
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var transformIndentationMarks = function transformIndentationMarks(adf) {
|
|
51
|
+
var isTransformed = false;
|
|
52
|
+
var transformedAdf = (0, _traverse.traverse)(adf, {
|
|
53
|
+
tableCell: function tableCell(node) {
|
|
54
|
+
if (hasChildHeadingWithIndentation(node)) {
|
|
55
|
+
isTransformed = true;
|
|
56
|
+
return removeIndentationFromHeadings(node);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
transformedAdf: transformedAdf,
|
|
62
|
+
isTransformed: isTransformed
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.transformIndentationMarks = transformIndentationMarks;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformMediaLinkMarks = void 0;
|
|
7
7
|
|
|
8
|
-
var _traverse = require("
|
|
8
|
+
var _traverse = require("../traverse/traverse");
|
|
9
9
|
|
|
10
10
|
// link mark on mediaSingle is deprecated, need to move link mark to child media node
|
|
11
11
|
// https://product-fabric.atlassian.net/browse/ED-14043
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.transformNodesMissingContent = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _traverse = require("../traverse/traverse");
|
|
15
|
+
|
|
16
|
+
var _builders = require("../builders");
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
var getMaxColumnsCountForTable = function getMaxColumnsCountForTable(tableNode) {
|
|
23
|
+
var _tableNode$content;
|
|
24
|
+
|
|
25
|
+
var colsInRow = 1;
|
|
26
|
+
(_tableNode$content = tableNode.content) === null || _tableNode$content === void 0 ? void 0 : _tableNode$content.forEach(function (childNode) {
|
|
27
|
+
var _childNode$content;
|
|
28
|
+
|
|
29
|
+
if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'tableRow' && typeof ((_childNode$content = childNode.content) === null || _childNode$content === void 0 ? void 0 : _childNode$content.length) === 'number' && childNode.content.length > colsInRow) {
|
|
30
|
+
colsInRow = childNode.content.length;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return colsInRow;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var createValidEmptyContent = function createValidEmptyContent(node) {
|
|
37
|
+
switch (node.type) {
|
|
38
|
+
case 'tableCell':
|
|
39
|
+
return [(0, _builders.paragraph)()];
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var isEmpty = function isEmpty(node) {
|
|
47
|
+
var _node$content;
|
|
48
|
+
|
|
49
|
+
return ((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.length) === 0;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var fixIfTableCellInvalidEmpty = function fixIfTableCellInvalidEmpty(reportTransform) {
|
|
53
|
+
return function (node) {
|
|
54
|
+
if (isEmpty(node)) {
|
|
55
|
+
reportTransform();
|
|
56
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
57
|
+
content: createValidEmptyContent(node)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var hasNonListItemChildren = function hasNonListItemChildren(node) {
|
|
64
|
+
var _node$content2;
|
|
65
|
+
|
|
66
|
+
return (_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.some(function (node) {
|
|
67
|
+
return (node === null || node === void 0 ? void 0 : node.type) !== 'listItem';
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var hasEmptyListItemChildren = function hasEmptyListItemChildren(node) {
|
|
72
|
+
var _node$content3;
|
|
73
|
+
|
|
74
|
+
return (_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.some(function (childNode) {
|
|
75
|
+
var _childNode$content2;
|
|
76
|
+
|
|
77
|
+
return (childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'listItem' && !((_childNode$content2 = childNode.content) !== null && _childNode$content2 !== void 0 && _childNode$content2.length);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var tryCreateValidListItemWrappedChildren = function tryCreateValidListItemWrappedChildren(parentListNode) {
|
|
82
|
+
var _parentListNode$conte;
|
|
83
|
+
|
|
84
|
+
return (_parentListNode$conte = parentListNode.content) === null || _parentListNode$conte === void 0 ? void 0 : _parentListNode$conte.map(function (childNode) {
|
|
85
|
+
if (childNode) {
|
|
86
|
+
switch (childNode.type) {
|
|
87
|
+
case 'listItem':
|
|
88
|
+
{
|
|
89
|
+
if (isEmpty(childNode)) {
|
|
90
|
+
var result = (0, _builders.listItem)([(0, _builders.paragraph)()]);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return childNode;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case 'text':
|
|
98
|
+
return (0, _builders.listItem)([(0, _builders.paragraph)(childNode)]);
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
return (0, _builders.listItem)([childNode]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return childNode;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var fixIfListParentWithInvalidListItemChildren = function fixIfListParentWithInvalidListItemChildren(reportTransform) {
|
|
110
|
+
return function (node) {
|
|
111
|
+
if (hasNonListItemChildren(node) || hasEmptyListItemChildren(node)) {
|
|
112
|
+
reportTransform();
|
|
113
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
114
|
+
content: tryCreateValidListItemWrappedChildren(node)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
var hasNonTableRowChildren = function hasNonTableRowChildren(node) {
|
|
121
|
+
var _node$content4;
|
|
122
|
+
|
|
123
|
+
return (_node$content4 = node.content) === null || _node$content4 === void 0 ? void 0 : _node$content4.some(function (node) {
|
|
124
|
+
return (node === null || node === void 0 ? void 0 : node.type) !== 'tableRow';
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var tryCreateValidTableRowWrappedChildren = function tryCreateValidTableRowWrappedChildren(parentTableNode) {
|
|
129
|
+
var _parentTableNode$cont;
|
|
130
|
+
|
|
131
|
+
var maxColsCount = getMaxColumnsCountForTable(parentTableNode);
|
|
132
|
+
return (_parentTableNode$cont = parentTableNode.content) === null || _parentTableNode$cont === void 0 ? void 0 : _parentTableNode$cont.map(function (childNode) {
|
|
133
|
+
if (childNode) {
|
|
134
|
+
switch (childNode.type) {
|
|
135
|
+
case 'text':
|
|
136
|
+
{
|
|
137
|
+
return (0, _builders.tableRow)([(0, _builders.tableCell)({})((0, _builders.paragraph)(childNode))].concat((0, _toConsumableArray2.default)(new Array(maxColsCount - 1).fill((0, _builders.tableCell)({})((0, _builders.paragraph)())))));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
case 'tableCell':
|
|
141
|
+
{
|
|
142
|
+
return (0, _builders.tableRow)([childNode]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
case 'tableRow':
|
|
146
|
+
{
|
|
147
|
+
if (isEmpty(childNode)) {
|
|
148
|
+
return (0, _builders.tableRow)((0, _toConsumableArray2.default)(new Array(maxColsCount).fill((0, _builders.tableCell)({})((0, _builders.paragraph)()))));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return childNode;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
default:
|
|
155
|
+
return childNode;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return childNode;
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
var hasEmptyTableRowChildren = function hasEmptyTableRowChildren(node) {
|
|
164
|
+
var _node$content5;
|
|
165
|
+
|
|
166
|
+
return node === null || node === void 0 ? void 0 : (_node$content5 = node.content) === null || _node$content5 === void 0 ? void 0 : _node$content5.some(function (node) {
|
|
167
|
+
var _node$content6;
|
|
168
|
+
|
|
169
|
+
return (node === null || node === void 0 ? void 0 : node.type) === 'tableRow' && (node === null || node === void 0 ? void 0 : (_node$content6 = node.content) === null || _node$content6 === void 0 ? void 0 : _node$content6.length) === 0;
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
var fixIfTableParentWithInvalidTableRowChildren = function fixIfTableParentWithInvalidTableRowChildren(reportTransform) {
|
|
174
|
+
return function (node) {
|
|
175
|
+
if (hasEmptyTableRowChildren(node) || hasNonTableRowChildren(node)) {
|
|
176
|
+
reportTransform();
|
|
177
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
178
|
+
content: tryCreateValidTableRowWrappedChildren(node)
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
var transformNodesMissingContent = function transformNodesMissingContent(adf) {
|
|
185
|
+
var isTransformed = false;
|
|
186
|
+
|
|
187
|
+
var reportTransform = function reportTransform() {
|
|
188
|
+
isTransformed = true;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
var transformedAdf = (0, _traverse.traverse)(adf, {
|
|
192
|
+
tableCell: fixIfTableCellInvalidEmpty(reportTransform)
|
|
193
|
+
});
|
|
194
|
+
transformedAdf = (0, _traverse.traverse)(transformedAdf || adf, {
|
|
195
|
+
bulletList: fixIfListParentWithInvalidListItemChildren(reportTransform),
|
|
196
|
+
orderedList: fixIfListParentWithInvalidListItemChildren(reportTransform),
|
|
197
|
+
table: fixIfTableParentWithInvalidTableRowChildren(reportTransform)
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
transformedAdf: transformedAdf,
|
|
201
|
+
isTransformed: isTransformed
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
exports.transformNodesMissingContent = transformNodesMissingContent;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "transformDedupeMarks", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _dedupeMarksTransform.transformDedupeMarks;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "transformIndentationMarks", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _indentationMarksTransform.transformIndentationMarks;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "transformMediaLinkMarks", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _mediaLinkTransform.transformMediaLinkMarks;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "transformNodesMissingContent", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _nodesMissingContentTransform.transformNodesMissingContent;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "transformTextLinkCodeMarks", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _textLinkCodeTransform.transformTextLinkCodeMarks;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
var _mediaLinkTransform = require("./transforms/media-link-transform");
|
|
38
|
+
|
|
39
|
+
var _textLinkCodeTransform = require("./transforms/text-link-code-transform");
|
|
40
|
+
|
|
41
|
+
var _dedupeMarksTransform = require("./transforms/dedupe-marks-transform");
|
|
42
|
+
|
|
43
|
+
var _nodesMissingContentTransform = require("./transforms/nodes-missing-content-transform");
|
|
44
|
+
|
|
45
|
+
var _indentationMarksTransform = require("./transforms/indentation-marks-transform");
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export { scrubAdf } from './scrub';
|
|
4
|
-
export { validateAttrs, validator } from './validator';
|
|
5
|
-
export { getEmptyADF } from './empty-adf';
|
|
6
|
-
export { transformMediaLinkMarks } from './media-link-transform';
|
|
7
|
-
export { transformTextLinkCodeMarks } from './transforms/text-link-code-transform';
|
|
1
|
+
// DO NOT EMPORT ANYTHING FROM THIS FILE. USE CHILD ENTRY POINTS.
|
|
2
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { traverse } from '../traverse/traverse';
|
|
2
|
+
// This is the set of marks that we wont allow in duplicate to
|
|
3
|
+
// exist on a given node, regardless of their attributes. We do
|
|
4
|
+
// not include annotations here, because we do allow duplicate
|
|
5
|
+
// annotations as long as they have unique id attributes (valid scenario)
|
|
6
|
+
const markDuplicatesDisallowed = new Set(['strong', 'underline', 'textColor', 'link', 'em', 'subsup', 'strike']);
|
|
7
|
+
|
|
8
|
+
const maybeHasDisallowedDuplicateMarks = node => {
|
|
9
|
+
var _node$marks, _node$marks$map;
|
|
10
|
+
|
|
11
|
+
const markTypes = (_node$marks = node.marks) === null || _node$marks === void 0 ? void 0 : (_node$marks$map = _node$marks.map(mark => mark.type)) === null || _node$marks$map === void 0 ? void 0 : _node$marks$map.filter(markType => // For annotations, we are performing the same cheap check
|
|
12
|
+
// for duplicates by type, without considering IDs, to quickly determine
|
|
13
|
+
// whether there may be potential deduping targets.
|
|
14
|
+
// In the actual deduping logic in maybeRemoveDisallowedDuplicateMarks,
|
|
15
|
+
// we correctly/safely dedupe annotations by their unique IDs.
|
|
16
|
+
markDuplicatesDisallowed.has(markType) || markType === 'annotation');
|
|
17
|
+
|
|
18
|
+
if (!(markTypes !== null && markTypes !== void 0 && markTypes.length)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return new Set(markTypes).size !== markTypes.length;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const maybeRemoveDisallowedDuplicateMarks = node => {
|
|
26
|
+
const quota = new Map();
|
|
27
|
+
const annotationsQuota = new Map();
|
|
28
|
+
const discardedMarks = [];
|
|
29
|
+
markDuplicatesDisallowed.forEach(mark => {
|
|
30
|
+
quota.set(mark, false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!node.marks) {
|
|
34
|
+
return {
|
|
35
|
+
discardedMarks
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let dedupedMarks = node.marks.filter(mark => {
|
|
40
|
+
const markType = mark.type;
|
|
41
|
+
|
|
42
|
+
if (markType === 'annotation') {
|
|
43
|
+
var _mark$attrs;
|
|
44
|
+
|
|
45
|
+
const id = (_mark$attrs = mark.attrs) === null || _mark$attrs === void 0 ? void 0 : _mark$attrs.id;
|
|
46
|
+
|
|
47
|
+
if (annotationsQuota.has(id)) {
|
|
48
|
+
discardedMarks.push(mark);
|
|
49
|
+
return false;
|
|
50
|
+
} else {
|
|
51
|
+
annotationsQuota.set(id, true);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (quota.has(markType)) {
|
|
57
|
+
if (!quota.get(markType)) {
|
|
58
|
+
quota.set(markType, true);
|
|
59
|
+
return true;
|
|
60
|
+
} else {
|
|
61
|
+
discardedMarks.push(mark);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
node: { ...node,
|
|
70
|
+
marks: dedupedMarks
|
|
71
|
+
},
|
|
72
|
+
discardedMarks
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const transformDedupeMarks = adf => {
|
|
77
|
+
let isTransformed = false;
|
|
78
|
+
let discardedMarks = [];
|
|
79
|
+
const transformedAdf = traverse(adf, {
|
|
80
|
+
text: node => {
|
|
81
|
+
if (maybeHasDisallowedDuplicateMarks(node)) {
|
|
82
|
+
const result = maybeRemoveDisallowedDuplicateMarks(node);
|
|
83
|
+
discardedMarks = result.discardedMarks;
|
|
84
|
+
|
|
85
|
+
if (discardedMarks.length) {
|
|
86
|
+
isTransformed = true;
|
|
87
|
+
return result.node;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
transformedAdf,
|
|
94
|
+
isTransformed,
|
|
95
|
+
discardedMarks
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { traverse } from '../traverse/traverse';
|
|
2
|
+
|
|
3
|
+
const hasChildHeadingWithIndentation = node => {
|
|
4
|
+
var _node$content$some, _node$content;
|
|
5
|
+
|
|
6
|
+
return (_node$content$some = (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.some(childNode => {
|
|
7
|
+
var _childNode$marks;
|
|
8
|
+
|
|
9
|
+
return (childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading' && (childNode === null || childNode === void 0 ? void 0 : (_childNode$marks = childNode.marks) === null || _childNode$marks === void 0 ? void 0 : _childNode$marks.some(mark => mark.type === 'indentation'));
|
|
10
|
+
})) !== null && _node$content$some !== void 0 ? _node$content$some : false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const removeIndentationFromHeadings = node => {
|
|
14
|
+
var _node$content2;
|
|
15
|
+
|
|
16
|
+
return { ...node,
|
|
17
|
+
content: (_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.map(childNode => {
|
|
18
|
+
if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'heading') {
|
|
19
|
+
var _childNode$marks2;
|
|
20
|
+
|
|
21
|
+
return { ...childNode,
|
|
22
|
+
marks: (_childNode$marks2 = childNode.marks) === null || _childNode$marks2 === void 0 ? void 0 : _childNode$marks2.filter(mark => mark.type !== 'indentation')
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return childNode;
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const transformIndentationMarks = adf => {
|
|
32
|
+
let isTransformed = false;
|
|
33
|
+
const transformedAdf = traverse(adf, {
|
|
34
|
+
tableCell: node => {
|
|
35
|
+
if (hasChildHeadingWithIndentation(node)) {
|
|
36
|
+
isTransformed = true;
|
|
37
|
+
return removeIndentationFromHeadings(node);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
transformedAdf,
|
|
43
|
+
isTransformed
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { traverse } from '
|
|
1
|
+
import { traverse } from '../traverse/traverse';
|
|
2
2
|
// link mark on mediaSingle is deprecated, need to move link mark to child media node
|
|
3
3
|
// https://product-fabric.atlassian.net/browse/ED-14043
|
|
4
4
|
export const transformMediaLinkMarks = adf => {
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { traverse } from '../traverse/traverse';
|
|
2
|
+
import { tableRow, tableCell, paragraph, listItem } from '../builders';
|
|
3
|
+
|
|
4
|
+
const getMaxColumnsCountForTable = tableNode => {
|
|
5
|
+
var _tableNode$content;
|
|
6
|
+
|
|
7
|
+
let colsInRow = 1;
|
|
8
|
+
(_tableNode$content = tableNode.content) === null || _tableNode$content === void 0 ? void 0 : _tableNode$content.forEach(childNode => {
|
|
9
|
+
var _childNode$content;
|
|
10
|
+
|
|
11
|
+
if ((childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'tableRow' && typeof ((_childNode$content = childNode.content) === null || _childNode$content === void 0 ? void 0 : _childNode$content.length) === 'number' && childNode.content.length > colsInRow) {
|
|
12
|
+
colsInRow = childNode.content.length;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return colsInRow;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const createValidEmptyContent = node => {
|
|
19
|
+
switch (node.type) {
|
|
20
|
+
case 'tableCell':
|
|
21
|
+
return [paragraph()];
|
|
22
|
+
|
|
23
|
+
default:
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isEmpty = node => {
|
|
29
|
+
var _node$content;
|
|
30
|
+
|
|
31
|
+
return ((_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.length) === 0;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fixIfTableCellInvalidEmpty = reportTransform => node => {
|
|
35
|
+
if (isEmpty(node)) {
|
|
36
|
+
reportTransform();
|
|
37
|
+
return { ...node,
|
|
38
|
+
content: createValidEmptyContent(node)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const hasNonListItemChildren = node => {
|
|
44
|
+
var _node$content2;
|
|
45
|
+
|
|
46
|
+
return (_node$content2 = node.content) === null || _node$content2 === void 0 ? void 0 : _node$content2.some(node => (node === null || node === void 0 ? void 0 : node.type) !== 'listItem');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const hasEmptyListItemChildren = node => {
|
|
50
|
+
var _node$content3;
|
|
51
|
+
|
|
52
|
+
return (_node$content3 = node.content) === null || _node$content3 === void 0 ? void 0 : _node$content3.some(childNode => {
|
|
53
|
+
var _childNode$content2;
|
|
54
|
+
|
|
55
|
+
return (childNode === null || childNode === void 0 ? void 0 : childNode.type) === 'listItem' && !((_childNode$content2 = childNode.content) !== null && _childNode$content2 !== void 0 && _childNode$content2.length);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const tryCreateValidListItemWrappedChildren = parentListNode => {
|
|
60
|
+
var _parentListNode$conte;
|
|
61
|
+
|
|
62
|
+
return (_parentListNode$conte = parentListNode.content) === null || _parentListNode$conte === void 0 ? void 0 : _parentListNode$conte.map(childNode => {
|
|
63
|
+
if (childNode) {
|
|
64
|
+
switch (childNode.type) {
|
|
65
|
+
case 'listItem':
|
|
66
|
+
{
|
|
67
|
+
if (isEmpty(childNode)) {
|
|
68
|
+
const result = listItem([paragraph()]);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return childNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
case 'text':
|
|
76
|
+
return listItem([paragraph(childNode)]);
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
return listItem([childNode]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return childNode;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const fixIfListParentWithInvalidListItemChildren = reportTransform => node => {
|
|
88
|
+
if (hasNonListItemChildren(node) || hasEmptyListItemChildren(node)) {
|
|
89
|
+
reportTransform();
|
|
90
|
+
return { ...node,
|
|
91
|
+
content: tryCreateValidListItemWrappedChildren(node)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const hasNonTableRowChildren = node => {
|
|
97
|
+
var _node$content4;
|
|
98
|
+
|
|
99
|
+
return (_node$content4 = node.content) === null || _node$content4 === void 0 ? void 0 : _node$content4.some(node => (node === null || node === void 0 ? void 0 : node.type) !== 'tableRow');
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const tryCreateValidTableRowWrappedChildren = parentTableNode => {
|
|
103
|
+
var _parentTableNode$cont;
|
|
104
|
+
|
|
105
|
+
const maxColsCount = getMaxColumnsCountForTable(parentTableNode);
|
|
106
|
+
return (_parentTableNode$cont = parentTableNode.content) === null || _parentTableNode$cont === void 0 ? void 0 : _parentTableNode$cont.map(childNode => {
|
|
107
|
+
if (childNode) {
|
|
108
|
+
switch (childNode.type) {
|
|
109
|
+
case 'text':
|
|
110
|
+
{
|
|
111
|
+
return tableRow([tableCell({})(paragraph(childNode)), ...new Array(maxColsCount - 1).fill(tableCell({})(paragraph()))]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
case 'tableCell':
|
|
115
|
+
{
|
|
116
|
+
return tableRow([childNode]);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
case 'tableRow':
|
|
120
|
+
{
|
|
121
|
+
if (isEmpty(childNode)) {
|
|
122
|
+
return tableRow([...new Array(maxColsCount).fill(tableCell({})(paragraph()))]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return childNode;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
default:
|
|
129
|
+
return childNode;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return childNode;
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const hasEmptyTableRowChildren = node => {
|
|
138
|
+
var _node$content5;
|
|
139
|
+
|
|
140
|
+
return node === null || node === void 0 ? void 0 : (_node$content5 = node.content) === null || _node$content5 === void 0 ? void 0 : _node$content5.some(node => {
|
|
141
|
+
var _node$content6;
|
|
142
|
+
|
|
143
|
+
return (node === null || node === void 0 ? void 0 : node.type) === 'tableRow' && (node === null || node === void 0 ? void 0 : (_node$content6 = node.content) === null || _node$content6 === void 0 ? void 0 : _node$content6.length) === 0;
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const fixIfTableParentWithInvalidTableRowChildren = reportTransform => node => {
|
|
148
|
+
if (hasEmptyTableRowChildren(node) || hasNonTableRowChildren(node)) {
|
|
149
|
+
reportTransform();
|
|
150
|
+
return { ...node,
|
|
151
|
+
content: tryCreateValidTableRowWrappedChildren(node)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const transformNodesMissingContent = adf => {
|
|
157
|
+
let isTransformed = false;
|
|
158
|
+
|
|
159
|
+
const reportTransform = () => {
|
|
160
|
+
isTransformed = true;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
let transformedAdf = traverse(adf, {
|
|
164
|
+
tableCell: fixIfTableCellInvalidEmpty(reportTransform)
|
|
165
|
+
});
|
|
166
|
+
transformedAdf = traverse(transformedAdf || adf, {
|
|
167
|
+
bulletList: fixIfListParentWithInvalidListItemChildren(reportTransform),
|
|
168
|
+
orderedList: fixIfListParentWithInvalidListItemChildren(reportTransform),
|
|
169
|
+
table: fixIfTableParentWithInvalidTableRowChildren(reportTransform)
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
transformedAdf,
|
|
173
|
+
isTransformed
|
|
174
|
+
};
|
|
175
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { transformMediaLinkMarks } from './transforms/media-link-transform';
|
|
2
|
+
export { transformTextLinkCodeMarks } from './transforms/text-link-code-transform';
|
|
3
|
+
export { transformDedupeMarks } from './transforms/dedupe-marks-transform';
|
|
4
|
+
export { transformNodesMissingContent } from './transforms/nodes-missing-content-transform';
|
|
5
|
+
export { transformIndentationMarks } from './transforms/indentation-marks-transform';
|
package/dist/es2019/version.json
CHANGED