@atlaskit/adf-utils 19.14.1 → 19.15.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 +9 -0
- package/dist/cjs/builders/utils/create-text-nodes.js +5 -0
- package/dist/cjs/builders/utils/is-duplicate-mark.js +5 -0
- package/dist/cjs/scrub/default-node-replacements.js +2 -0
- package/dist/cjs/scrub/scrub-adf.js +3 -0
- package/dist/cjs/scrub/scrub-content.js +7 -0
- package/dist/cjs/transforms/nested-table-transform.js +2 -2
- package/dist/cjs/transforms/nodes-missing-content-transform.js +2 -0
- package/dist/cjs/transforms.js +6 -0
- package/dist/cjs/traverse/map.js +2 -0
- package/dist/cjs/traverse/reduce.js +2 -0
- package/dist/cjs/traverse/traverse.js +3 -0
- package/dist/cjs/validator/utils.js +5 -0
- package/dist/cjs/validator/validator.js +129 -15
- package/dist/es2019/builders/utils/create-text-nodes.js +6 -0
- package/dist/es2019/builders/utils/is-duplicate-mark.js +5 -0
- package/dist/es2019/scrub/default-node-replacements.js +4 -0
- package/dist/es2019/scrub/scrub-adf.js +3 -0
- package/dist/es2019/scrub/scrub-content.js +7 -0
- package/dist/es2019/transforms/dedupe-marks-transform.js +2 -2
- package/dist/es2019/transforms/invalid-media-content-transform.js +1 -1
- package/dist/es2019/transforms/nested-table-transform.js +1 -1
- package/dist/es2019/transforms/nodes-missing-content-transform.js +2 -0
- package/dist/es2019/transforms.js +1 -1
- package/dist/es2019/traverse/map.js +3 -0
- package/dist/es2019/traverse/reduce.js +3 -0
- package/dist/es2019/traverse/traverse.js +3 -0
- package/dist/es2019/validator/utils.js +5 -0
- package/dist/es2019/validator/validator.js +138 -19
- package/dist/esm/builders/utils/create-text-nodes.js +6 -0
- package/dist/esm/builders/utils/is-duplicate-mark.js +5 -0
- package/dist/esm/scrub/default-node-replacements.js +2 -0
- package/dist/esm/scrub/scrub-adf.js +3 -0
- package/dist/esm/scrub/scrub-content.js +7 -0
- package/dist/esm/transforms/nested-table-transform.js +1 -1
- package/dist/esm/transforms/nodes-missing-content-transform.js +2 -0
- package/dist/esm/transforms.js +1 -1
- package/dist/esm/traverse/map.js +3 -0
- package/dist/esm/traverse/reduce.js +3 -0
- package/dist/esm/traverse/traverse.js +3 -0
- package/dist/esm/validator/utils.js +5 -0
- package/dist/esm/validator/validator.js +130 -14
- package/dist/types/transforms/nested-table-transform.d.ts +1 -0
- package/dist/types/transforms.d.ts +1 -1
- package/dist/types-ts4.5/transforms/nested-table-transform.d.ts +1 -0
- package/dist/types-ts4.5/transforms.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/adf-utils
|
|
2
2
|
|
|
3
|
+
## 19.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#100845](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100845)
|
|
8
|
+
[`bd4c63b5f9688`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bd4c63b5f9688) -
|
|
9
|
+
[ED-26055] Export a function from adf-utils used to detect the use of the nested-tables extension,
|
|
10
|
+
and add calculation of unexpectedly nested tables to editor-common utils
|
|
11
|
+
|
|
3
12
|
## 19.14.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -6,9 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createTextFromString = createTextFromString;
|
|
7
7
|
exports.createTextNodes = createTextNodes;
|
|
8
8
|
var _text = require("../nodes/text");
|
|
9
|
+
// Ignored via go/ees005
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
11
|
function createTextNodes(nodes) {
|
|
10
12
|
return nodes.map(createTextFromString);
|
|
11
13
|
}
|
|
14
|
+
|
|
15
|
+
// Ignored via go/ees005
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
17
|
function createTextFromString(str) {
|
|
13
18
|
return typeof str === 'string' ? (0, _text.text)(str) : str;
|
|
14
19
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.duplicateMarkError = duplicateMarkError;
|
|
7
7
|
exports.isDuplicateMark = isDuplicateMark;
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
10
|
function isDuplicateMark(node, type) {
|
|
9
11
|
if (node.marks && node.marks.some(function (mark) {
|
|
10
12
|
return mark.type === type;
|
|
@@ -13,6 +15,9 @@ function isDuplicateMark(node, type) {
|
|
|
13
15
|
}
|
|
14
16
|
return false;
|
|
15
17
|
}
|
|
18
|
+
|
|
19
|
+
// Ignored via go/ees005
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
21
|
function duplicateMarkError(node, type) {
|
|
17
22
|
return "Mark with the same name '".concat(type, "' already exists on a node: ").concat(JSON.stringify(node));
|
|
18
23
|
}
|
|
@@ -23,6 +23,8 @@ var mediaParent = function mediaParent(node) {
|
|
|
23
23
|
var _node$content;
|
|
24
24
|
return {
|
|
25
25
|
type: node.type,
|
|
26
|
+
// Ignored via go/ees005
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
28
|
attrs: node.attrs ? (0, _scrubContent.scrubAttrs)(node.type, node.attrs) : undefined,
|
|
27
29
|
content: (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.filter(function (c) {
|
|
28
30
|
return (c === null || c === void 0 ? void 0 : c.type) === 'media';
|
|
@@ -29,6 +29,9 @@ var _default = exports.default = function _default(adf) {
|
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
// Ignored via go/ees005
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
35
|
var updatedNode = {};
|
|
33
36
|
Object.entries(node).forEach(function (_ref) {
|
|
34
37
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
@@ -33,6 +33,8 @@ var BYPASS_ATTR_LIST = {
|
|
|
33
33
|
tableRow: ['defaultMarks'],
|
|
34
34
|
taskItem: ['state']
|
|
35
35
|
};
|
|
36
|
+
// Ignored via go/ees005
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
38
|
var fromEntries = function fromEntries(iterable) {
|
|
37
39
|
return (0, _toConsumableArray2.default)(iterable).reduce(function (obj, _ref) {
|
|
38
40
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
@@ -98,6 +100,8 @@ var scrubLink = exports.scrubLink = function scrubLink(marks, _ref3) {
|
|
|
98
100
|
});
|
|
99
101
|
};
|
|
100
102
|
var scrubObj = function scrubObj(nodeType, attrsObj) {
|
|
103
|
+
// Ignored via go/ees005
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
105
|
var entries = Object.entries(attrsObj).map(function (_ref4) {
|
|
102
106
|
var _BYPASS_ATTR_LIST$nod;
|
|
103
107
|
var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
|
|
@@ -107,6 +111,9 @@ var scrubObj = function scrubObj(nodeType, attrsObj) {
|
|
|
107
111
|
});
|
|
108
112
|
return fromEntries(entries);
|
|
109
113
|
};
|
|
114
|
+
|
|
115
|
+
// Ignored via go/ees005
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
117
|
var scrubAttrs = exports.scrubAttrs = function scrubAttrs(nodeType, attrs) {
|
|
111
118
|
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
112
119
|
if (typeof attrs === 'number') {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.transformNestedTablesIncomingDocument = exports.transformNestedTableNodeOutgoingDocument = void 0;
|
|
7
|
+
exports.transformNestedTablesIncomingDocument = exports.transformNestedTableNodeOutgoingDocument = exports.isNestedTableExtension = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _traverse = require("../traverse/traverse");
|
|
10
10
|
var _builders = require("../builders");
|
|
@@ -13,7 +13,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
13
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
14
|
var NESTED_TABLE_EXTENSION_TYPE = 'com.atlassian.confluence.migration',
|
|
15
15
|
NESTED_TABLE_EXTENSION_KEY = 'nested-table';
|
|
16
|
-
var isNestedTableExtension = function isNestedTableExtension(extensionNode) {
|
|
16
|
+
var isNestedTableExtension = exports.isNestedTableExtension = function isNestedTableExtension(extensionNode) {
|
|
17
17
|
var _extensionNode$attrs, _extensionNode$attrs2;
|
|
18
18
|
return ((_extensionNode$attrs = extensionNode.attrs) === null || _extensionNode$attrs === void 0 ? void 0 : _extensionNode$attrs.extensionType) === NESTED_TABLE_EXTENSION_TYPE && ((_extensionNode$attrs2 = extensionNode.attrs) === null || _extensionNode$attrs2 === void 0 ? void 0 : _extensionNode$attrs2.extensionKey) === NESTED_TABLE_EXTENSION_KEY;
|
|
19
19
|
};
|
|
@@ -70,6 +70,8 @@ var tryCreateValidListItemWrappedChildren = function tryCreateValidListItemWrapp
|
|
|
70
70
|
case 'text':
|
|
71
71
|
return (0, _builders.listItem)([(0, _builders.paragraph)(childNode)]);
|
|
72
72
|
default:
|
|
73
|
+
// Ignored via go/ees005
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
75
|
return (0, _builders.listItem)([childNode]);
|
|
74
76
|
}
|
|
75
77
|
}
|
package/dist/cjs/transforms.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "NodeNestingTransformError", {
|
|
|
9
9
|
return _errors.NodeNestingTransformError;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "isNestedTableExtension", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _nestedTableTransform.isNestedTableExtension;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "transformDedupeMarks", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function get() {
|
package/dist/cjs/traverse/map.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.map = map;
|
|
7
7
|
var _traverse = require("./traverse");
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
10
|
function map(adf, callback) {
|
|
9
11
|
var result = [];
|
|
10
12
|
(0, _traverse.traverse)(adf, {
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.reduce = reduce;
|
|
7
7
|
var _traverse = require("./traverse");
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
10
|
function reduce(adf, callback, initial) {
|
|
9
11
|
var result = initial;
|
|
10
12
|
(0, _traverse.traverse)(adf, {
|
|
@@ -30,6 +30,9 @@ function traverse(adf, visitors) {
|
|
|
30
30
|
node: undefined
|
|
31
31
|
}, visitors, 0, 0);
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
// Ignored via go/ees005
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
33
36
|
function traverseNode(adfNode, parent, visitors, index, depth) {
|
|
34
37
|
var visitor = visitors[adfNode.type] || visitors['any'];
|
|
35
38
|
var newNode = _objectSpread({}, adfNode);
|
|
@@ -26,7 +26,12 @@ var isString = exports.isString = function isString(s) {
|
|
|
26
26
|
var isPlainObject = exports.isPlainObject = function isPlainObject(x) {
|
|
27
27
|
return (0, _typeof2.default)(x) === 'object' && x !== null && !Array.isArray(x);
|
|
28
28
|
};
|
|
29
|
+
|
|
30
|
+
// Ignored via go/ees005
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
32
|
var copy = exports.copy = function copy(source, dest, key) {
|
|
33
|
+
// Ignored via go/ees005
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
35
|
dest[key] = source[key];
|
|
31
36
|
return dest;
|
|
32
37
|
};
|
|
@@ -13,16 +13,21 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
13
13
|
var specs = _interopRequireWildcard(require("./specs"));
|
|
14
14
|
var _utils = require("./utils");
|
|
15
15
|
var _rules = require("./rules");
|
|
16
|
-
var _excluded = ["items"];
|
|
16
|
+
var _excluded = ["items"]; // Ignored via go/ees005
|
|
17
|
+
// eslint-disable-next-line import/no-namespace
|
|
17
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
20
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
|
+
// Ignored via go/ees005
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
24
|
function mapMarksItems(spec) {
|
|
22
25
|
var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (x) {
|
|
23
26
|
return x;
|
|
24
27
|
};
|
|
25
28
|
if (spec.props && spec.props.marks) {
|
|
29
|
+
// Ignored via go/ees005
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
31
|
var _ref = spec.props.marks,
|
|
27
32
|
items = _ref.items,
|
|
28
33
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
@@ -41,6 +46,9 @@ function mapMarksItems(spec) {
|
|
|
41
46
|
return spec;
|
|
42
47
|
}
|
|
43
48
|
}
|
|
49
|
+
|
|
50
|
+
// Ignored via go/ees005
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
52
|
var partitionObject = function partitionObject(obj, predicate) {
|
|
45
53
|
return Object.keys(obj).reduce(function (acc, key) {
|
|
46
54
|
var result = predicate(key, obj[key], obj);
|
|
@@ -54,13 +62,19 @@ var partitionObject = function partitionObject(obj, predicate) {
|
|
|
54
62
|
* We denormalised the spec to save bundle size.
|
|
55
63
|
*/
|
|
56
64
|
function createSpec(nodes, marks) {
|
|
65
|
+
// Ignored via go/ees005
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
67
|
return Object.keys(specs).reduce(function (newSpecs, k) {
|
|
68
|
+
// Ignored via go/ees005
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
70
|
var spec = _objectSpread({}, specs[k]);
|
|
59
71
|
if (spec.props) {
|
|
60
72
|
spec.props = _objectSpread({}, spec.props);
|
|
61
73
|
if (spec.props.content) {
|
|
62
74
|
// 'tableCell_content' => { type: 'array', items: [ ... ] }
|
|
63
75
|
if ((0, _utils.isString)(spec.props.content)) {
|
|
76
|
+
// Ignored via go/ees005
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
78
|
spec.props.content = specs[spec.props.content];
|
|
65
79
|
}
|
|
66
80
|
|
|
@@ -88,14 +102,27 @@ function createSpec(nodes, marks) {
|
|
|
88
102
|
// ['inline'] => [['emoji', 'hr', ...]]
|
|
89
103
|
// ['media'] => [['media']]
|
|
90
104
|
.map(function (item) {
|
|
91
|
-
return (0, _utils.isString)(item) ?
|
|
105
|
+
return (0, _utils.isString)(item) ?
|
|
106
|
+
// Ignored via go/ees005
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
Array.isArray(specs[item]) ?
|
|
109
|
+
// Ignored via go/ees005
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
specs[item] : [item] : item;
|
|
92
112
|
})
|
|
93
113
|
// [['emoji', 'hr', 'inline_code']] => [['emoji', 'hr', ['text', { marks: {} }]]]
|
|
94
114
|
.map(function (item) {
|
|
95
115
|
return item.map(function (subItem) {
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
return (
|
|
117
|
+
// Ignored via go/ees005
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
+
Array.isArray(specs[subItem]) ?
|
|
120
|
+
// Ignored via go/ees005
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
+
specs[subItem] : (0, _utils.isString)(subItem) ? subItem :
|
|
123
|
+
// Now `NoMark` produces `items: []`, should be fixed in generator
|
|
124
|
+
['text', subItem]
|
|
125
|
+
);
|
|
99
126
|
})
|
|
100
127
|
// Remove unsupported nodes & marks
|
|
101
128
|
// Filter nodes
|
|
@@ -133,6 +160,9 @@ function createSpec(nodes, marks) {
|
|
|
133
160
|
return newSpecs;
|
|
134
161
|
}, {});
|
|
135
162
|
}
|
|
163
|
+
|
|
164
|
+
// Ignored via go/ees005
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
166
|
function getOptionsForType(type, list) {
|
|
137
167
|
if (!list) {
|
|
138
168
|
return {};
|
|
@@ -162,7 +192,11 @@ function validateAttrs(spec, value) {
|
|
|
162
192
|
if (isValidatorSpecAttrs(spec)) {
|
|
163
193
|
// If spec has ".props" it is ValidatorSpecAttrs and need to pipe back in recursively
|
|
164
194
|
var _partitionObject = partitionObject(spec.props, function (key, subSpec) {
|
|
165
|
-
return
|
|
195
|
+
return (
|
|
196
|
+
// Ignored via go/ees005
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
validateAttrs(subSpec, value[key])
|
|
199
|
+
);
|
|
166
200
|
}),
|
|
167
201
|
_partitionObject2 = (0, _slicedToArray2.default)(_partitionObject, 2),
|
|
168
202
|
_ = _partitionObject2[0],
|
|
@@ -184,7 +218,13 @@ function validateAttrs(spec, value) {
|
|
|
184
218
|
var validatorFnPassed = function validatorFnPassed(rule) {
|
|
185
219
|
return typeof value === 'string' && (0, _utils.isDefined)(_rules.validatorFnMap[rule]) && _rules.validatorFnMap[rule](value);
|
|
186
220
|
};
|
|
187
|
-
return (0, _utils.isString)(value) && (
|
|
221
|
+
return (0, _utils.isString)(value) && (
|
|
222
|
+
// Ignored via go/ees005
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
224
|
+
(0, _utils.isDefined)(spec.minLength) ? spec.minLength <= value.length : true) && ((0, _utils.isDefined)(spec.validatorFn) ? validatorFnPassed(spec.validatorFn) : true) && (
|
|
225
|
+
// Ignored via go/ees005
|
|
226
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
227
|
+
spec.pattern ? new RegExp(spec.pattern).test(value) : true);
|
|
188
228
|
case 'object':
|
|
189
229
|
return (0, _utils.isPlainObject)(value);
|
|
190
230
|
case 'array':
|
|
@@ -243,7 +283,10 @@ var invalidChildContent = function invalidChildContent(child, errorCallback, par
|
|
|
243
283
|
}, getUnsupportedOptions(parentSpec));
|
|
244
284
|
}
|
|
245
285
|
};
|
|
246
|
-
var unsupportedMarkContent = function unsupportedMarkContent(errorCode, mark, errorCallback, errorMessage
|
|
286
|
+
var unsupportedMarkContent = function unsupportedMarkContent(errorCode, mark, errorCallback, errorMessage
|
|
287
|
+
// Ignored via go/ees005
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
289
|
+
) {
|
|
247
290
|
var message = errorMessage || errorMessageFor(mark.type, 'unsupported mark');
|
|
248
291
|
if (!errorCallback) {
|
|
249
292
|
throw new Error(message);
|
|
@@ -259,7 +302,10 @@ var unsupportedMarkContent = function unsupportedMarkContent(errorCode, mark, er
|
|
|
259
302
|
});
|
|
260
303
|
}
|
|
261
304
|
};
|
|
262
|
-
var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent(entity, errorCode, invalidAttributes, message, errorCallback
|
|
305
|
+
var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent(entity, errorCode, invalidAttributes, message, errorCallback
|
|
306
|
+
// Ignored via go/ees005
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
308
|
+
) {
|
|
263
309
|
if (!errorCallback) {
|
|
264
310
|
throw new Error(message);
|
|
265
311
|
} else {
|
|
@@ -284,6 +330,8 @@ function validator(nodes, marks, options) {
|
|
|
284
330
|
mode = _ref2$mode === void 0 ? 'strict' : _ref2$mode,
|
|
285
331
|
_ref2$allowPrivateAtt = _ref2.allowPrivateAttributes,
|
|
286
332
|
allowPrivateAttributes = _ref2$allowPrivateAtt === void 0 ? false : _ref2$allowPrivateAtt;
|
|
333
|
+
// Ignored via go/ees005
|
|
334
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
287
335
|
var validate = function validate(entity, errorCallback, allowed, parentSpec) {
|
|
288
336
|
var validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
|
|
289
337
|
return {
|
|
@@ -334,6 +382,9 @@ function validator(nodes, marks, options) {
|
|
|
334
382
|
};
|
|
335
383
|
};
|
|
336
384
|
return validate;
|
|
385
|
+
|
|
386
|
+
// Ignored via go/ees005
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
337
388
|
function marksValidationFor(validator, entity, errorCallback, newEntity, err) {
|
|
338
389
|
var validationResult;
|
|
339
390
|
if (validator.props && validator.props.marks) {
|
|
@@ -349,11 +400,16 @@ function validator(nodes, marks, options) {
|
|
|
349
400
|
}
|
|
350
401
|
return validationResult;
|
|
351
402
|
}
|
|
403
|
+
// Ignored via go/ees005
|
|
404
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
352
405
|
function validatorFor(spec, typeOptions) {
|
|
353
406
|
return _objectSpread(_objectSpread(_objectSpread({}, spec), typeOptions), spec.props ? {
|
|
354
407
|
props: _objectSpread(_objectSpread({}, spec.props), typeOptions['props'] || {})
|
|
355
408
|
} : {});
|
|
356
409
|
}
|
|
410
|
+
|
|
411
|
+
// Ignored via go/ees005
|
|
412
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
357
413
|
function marksAfterValidation(entity, errorCallback, marksSet, validator) {
|
|
358
414
|
return entity.marks ? entity.marks.map(function (mark) {
|
|
359
415
|
var isAKnownMark = marks ? marks.indexOf(mark.type) > -1 : true;
|
|
@@ -393,11 +449,16 @@ function validator(nodes, marks, options) {
|
|
|
393
449
|
}) : [];
|
|
394
450
|
}
|
|
395
451
|
function allowedMarksFor(validator) {
|
|
452
|
+
// Ignored via go/ees005
|
|
453
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
396
454
|
var _ref3 = validator.props.marks,
|
|
397
455
|
items = _ref3.items;
|
|
398
456
|
var marksSet = items.length ? Array.isArray(items[0]) ? items[0] : items : [];
|
|
399
457
|
return marksSet;
|
|
400
458
|
}
|
|
459
|
+
|
|
460
|
+
// Ignored via go/ees005
|
|
461
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
401
462
|
function marksForEntitySpecNotSupportingMarks(prevEntity, newEntity, errorCallback, err) {
|
|
402
463
|
var errorCode = 'REDUNDANT_MARKS';
|
|
403
464
|
var currentMarks = prevEntity.marks || [];
|
|
@@ -439,8 +500,13 @@ function validator(nodes, marks, options) {
|
|
|
439
500
|
valid: true,
|
|
440
501
|
entity: prevEntity
|
|
441
502
|
};
|
|
503
|
+
// Ignored via go/ees005
|
|
504
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
442
505
|
if (validatorSpec.props.text) {
|
|
443
|
-
if ((0, _utils.isDefined)(prevEntity.text) &&
|
|
506
|
+
if ((0, _utils.isDefined)(prevEntity.text) &&
|
|
507
|
+
// Ignored via go/ees005
|
|
508
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
509
|
+
!validateAttrs(validatorSpec.props.text, prevEntity.text)) {
|
|
444
510
|
result = err('INVALID_TEXT', "'text' validation failed");
|
|
445
511
|
}
|
|
446
512
|
}
|
|
@@ -451,7 +517,11 @@ function validator(nodes, marks, options) {
|
|
|
451
517
|
valid: true,
|
|
452
518
|
entity: prevEntity
|
|
453
519
|
};
|
|
520
|
+
// Ignored via go/ees005
|
|
521
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
454
522
|
if (validatorSpec.props.content && prevEntity.content) {
|
|
523
|
+
// Ignored via go/ees005
|
|
524
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
455
525
|
var _content = validatorSpec.props.content,
|
|
456
526
|
minItems = _content.minItems,
|
|
457
527
|
maxItems = _content.maxItems;
|
|
@@ -474,6 +544,8 @@ function validator(nodes, marks, options) {
|
|
|
474
544
|
}
|
|
475
545
|
function invalidAttributesFor(validatorSpec, prevEntity) {
|
|
476
546
|
var invalidAttrs = [];
|
|
547
|
+
// Ignored via go/ees005
|
|
548
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
477
549
|
var validatorAttrs = {};
|
|
478
550
|
if (validatorSpec.props && validatorSpec.props.attrs) {
|
|
479
551
|
var attrOptions = (0, _utils.makeArray)(validatorSpec.props.attrs);
|
|
@@ -486,12 +558,16 @@ function validator(nodes, marks, options) {
|
|
|
486
558
|
var attrOption = attrOptions[i];
|
|
487
559
|
if (attrOption && attrOption.props) {
|
|
488
560
|
var _partitionObject3 = partitionObject(attrOption.props, function (key, spec) {
|
|
561
|
+
// Ignored via go/ees005
|
|
562
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
489
563
|
var valueToValidate = prevEntity.attrs[key];
|
|
490
564
|
return validateAttrs(spec, valueToValidate);
|
|
491
565
|
});
|
|
492
566
|
var _partitionObject4 = (0, _slicedToArray2.default)(_partitionObject3, 2);
|
|
493
567
|
invalidAttrs = _partitionObject4[1];
|
|
494
568
|
}
|
|
569
|
+
// Ignored via go/ees005
|
|
570
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
495
571
|
validatorAttrs = attrOption;
|
|
496
572
|
if (!invalidAttrs.length) {
|
|
497
573
|
break;
|
|
@@ -503,6 +579,9 @@ function validator(nodes, marks, options) {
|
|
|
503
579
|
validatorAttrs: validatorAttrs
|
|
504
580
|
};
|
|
505
581
|
}
|
|
582
|
+
|
|
583
|
+
// Ignored via go/ees005
|
|
584
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
506
585
|
function attributesValidationFor(validatorSpec, prevEntity, newEntity, isMark, errorCallback) {
|
|
507
586
|
var validatorSpecAllowsAttributes = validatorSpec.props && validatorSpec.props.attrs;
|
|
508
587
|
if (prevEntity.attrs) {
|
|
@@ -529,13 +608,19 @@ function validator(nodes, marks, options) {
|
|
|
529
608
|
entity: prevEntity
|
|
530
609
|
};
|
|
531
610
|
}
|
|
532
|
-
function validateAttributes(validatorSpec, prevEntity,
|
|
611
|
+
function validateAttributes(validatorSpec, prevEntity,
|
|
612
|
+
// Ignored via go/ees005
|
|
613
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
614
|
+
attributes) {
|
|
533
615
|
var invalidAttributesResult = invalidAttributesFor(validatorSpec, prevEntity);
|
|
534
616
|
var invalidAttrs = invalidAttributesResult.invalidAttrs;
|
|
535
617
|
var validatorAttrs = invalidAttributesResult.validatorAttrs;
|
|
536
618
|
var attrs = Object.keys(attributes).filter(function (k) {
|
|
537
619
|
return !(allowPrivateAttributes && k.startsWith('__'));
|
|
538
620
|
});
|
|
621
|
+
|
|
622
|
+
// Ignored via go/ees005
|
|
623
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
539
624
|
var redundantAttrs = attrs.filter(function (a) {
|
|
540
625
|
return !validatorAttrs.props[a];
|
|
541
626
|
});
|
|
@@ -547,6 +632,9 @@ function validator(nodes, marks, options) {
|
|
|
547
632
|
redundantAttrs: redundantAttrs
|
|
548
633
|
};
|
|
549
634
|
}
|
|
635
|
+
|
|
636
|
+
// Ignored via go/ees005
|
|
637
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
550
638
|
function handleUnsupportedNodeAttributes(prevEntity, newEntity, invalidAttrs, redundantAttrs, errorCallback) {
|
|
551
639
|
var attr = invalidAttrs.concat(redundantAttrs);
|
|
552
640
|
var result = {
|
|
@@ -582,7 +670,10 @@ function validator(nodes, marks, options) {
|
|
|
582
670
|
marksValidationOutput: [markValidationResult]
|
|
583
671
|
};
|
|
584
672
|
}
|
|
585
|
-
function handleNoAttibutesAllowedInSpecForMark(prevEntity,
|
|
673
|
+
function handleNoAttibutesAllowedInSpecForMark(prevEntity,
|
|
674
|
+
// Ignored via go/ees005
|
|
675
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
676
|
+
attributes) {
|
|
586
677
|
var message = errorMessageFor('redundant attributes found', Object.keys(attributes).join(', '));
|
|
587
678
|
var errorCode = 'REDUNDANT_ATTRIBUTES';
|
|
588
679
|
var markValidationResult = {
|
|
@@ -596,6 +687,9 @@ function validator(nodes, marks, options) {
|
|
|
596
687
|
marksValidationOutput: [markValidationResult]
|
|
597
688
|
};
|
|
598
689
|
}
|
|
690
|
+
|
|
691
|
+
// Ignored via go/ees005
|
|
692
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
599
693
|
function wrapUnSupportedNodeAttributes(prevEntity, newEntity, invalidAttrs, errorCode, message, errorCallback) {
|
|
600
694
|
var invalidValues = {};
|
|
601
695
|
// eslint-disable-next-line guard-for-in
|
|
@@ -626,13 +720,20 @@ function validator(nodes, marks, options) {
|
|
|
626
720
|
return [unsupportedNodeAttributeValues];
|
|
627
721
|
}
|
|
628
722
|
}
|
|
723
|
+
|
|
724
|
+
// Ignored via go/ees005
|
|
725
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
629
726
|
function extraPropsValidationFor(validatorSpec, prevEntity, err, newEntity, type) {
|
|
630
727
|
var result = {
|
|
631
728
|
valid: true,
|
|
632
729
|
entity: prevEntity
|
|
633
730
|
};
|
|
634
731
|
var _partitionObject5 = partitionObject(prevEntity, function (k) {
|
|
635
|
-
return (
|
|
732
|
+
return (
|
|
733
|
+
// Ignored via go/ees005
|
|
734
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
735
|
+
(0, _utils.isDefined)(validatorSpec.props[k])
|
|
736
|
+
);
|
|
636
737
|
}),
|
|
637
738
|
_partitionObject6 = (0, _slicedToArray2.default)(_partitionObject5, 2),
|
|
638
739
|
requiredProps = _partitionObject6[0],
|
|
@@ -655,7 +756,13 @@ function validator(nodes, marks, options) {
|
|
|
655
756
|
}
|
|
656
757
|
return result;
|
|
657
758
|
}
|
|
658
|
-
|
|
759
|
+
|
|
760
|
+
// Ignored via go/ees005
|
|
761
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
762
|
+
function specBasedValidationFor(spec,
|
|
763
|
+
// Ignored via go/ees005
|
|
764
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
765
|
+
typeOptions, prevEntity, err, newEntity, type, errorCallback, isMark) {
|
|
659
766
|
var specBasedValidationResult = {
|
|
660
767
|
hasValidated: false
|
|
661
768
|
};
|
|
@@ -748,6 +855,8 @@ function validator(nodes, marks, options) {
|
|
|
748
855
|
if (validatorSpec.props.content) {
|
|
749
856
|
var contentValidatorSpec = validatorSpec.props.content;
|
|
750
857
|
if (prevEntity.content) {
|
|
858
|
+
// Ignored via go/ees005
|
|
859
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
751
860
|
var validateChildNode = function validateChildNode(child, index) {
|
|
752
861
|
if (child === undefined) {
|
|
753
862
|
return child;
|
|
@@ -759,12 +868,17 @@ function validator(nodes, marks, options) {
|
|
|
759
868
|
var validMarks = marksValidationOutput.filter(function (mark) {
|
|
760
869
|
return mark.valid;
|
|
761
870
|
});
|
|
871
|
+
// Ignored via go/ees005
|
|
872
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
762
873
|
var finalMarks = marksValidationOutput.map(function (mr) {
|
|
763
874
|
if (mr.valid) {
|
|
764
875
|
return mr.newMark;
|
|
765
876
|
} else {
|
|
766
877
|
if (validMarks.length || isLastValidationSpec || isParentTupleLike || mr.errorCode === 'INVALID_TYPE' || mr.errorCode === 'INVALID_CONTENT' || mr.errorCode === 'REDUNDANT_ATTRIBUTES' || mr.errorCode === 'INVALID_ATTRIBUTES') {
|
|
767
|
-
return unsupportedMarkContent(
|
|
878
|
+
return unsupportedMarkContent(
|
|
879
|
+
// Ignored via go/ees005
|
|
880
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
881
|
+
mr.errorCode, mr.originalMark, errorCallback, mr.message);
|
|
768
882
|
}
|
|
769
883
|
return;
|
|
770
884
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { text } from '../nodes/text';
|
|
2
|
+
|
|
3
|
+
// Ignored via go/ees005
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
5
|
export function createTextNodes(nodes) {
|
|
3
6
|
return nodes.map(createTextFromString);
|
|
4
7
|
}
|
|
8
|
+
|
|
9
|
+
// Ignored via go/ees005
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
11
|
export function createTextFromString(str) {
|
|
6
12
|
return typeof str === 'string' ? text(str) : str;
|
|
7
13
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
// Ignored via go/ees005
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1
3
|
export function isDuplicateMark(node, type) {
|
|
2
4
|
if (node.marks && node.marks.some(mark => mark.type === type)) {
|
|
3
5
|
return true;
|
|
4
6
|
}
|
|
5
7
|
return false;
|
|
6
8
|
}
|
|
9
|
+
|
|
10
|
+
// Ignored via go/ees005
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
12
|
export function duplicateMarkError(node, type) {
|
|
8
13
|
return `Mark with the same name '${type}' already exists on a node: ${JSON.stringify(node)}`;
|
|
9
14
|
}
|
|
@@ -15,6 +15,8 @@ const mediaParent = node => {
|
|
|
15
15
|
var _node$content;
|
|
16
16
|
return {
|
|
17
17
|
type: node.type,
|
|
18
|
+
// Ignored via go/ees005
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
20
|
attrs: node.attrs ? scrubAttrs(node.type, node.attrs) : undefined,
|
|
19
21
|
content: (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.filter(c => (c === null || c === void 0 ? void 0 : c.type) === 'media')
|
|
20
22
|
};
|
|
@@ -62,6 +64,8 @@ export const defaultNodeReplacements = {
|
|
|
62
64
|
return {
|
|
63
65
|
type: 'media',
|
|
64
66
|
attrs: {
|
|
67
|
+
// Ignored via go/ees005
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
69
|
...scrubAttrs('media', node.attrs),
|
|
66
70
|
type: 'external',
|
|
67
71
|
url: `https://dummyimage.com/${width}x${height}/f4f5f7/a5adba`
|
|
@@ -23,6 +23,9 @@ export default ((adf, options = {}) => {
|
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
// Ignored via go/ees005
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
29
|
const updatedNode = {};
|
|
27
30
|
Object.entries(node).forEach(([key, value]) => {
|
|
28
31
|
if (['version', 'type', 'content', 'marks'].includes(key)) {
|
|
@@ -20,6 +20,8 @@ const BYPASS_ATTR_LIST = {
|
|
|
20
20
|
tableRow: ['defaultMarks'],
|
|
21
21
|
taskItem: ['state']
|
|
22
22
|
};
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
25
|
const fromEntries = iterable => {
|
|
24
26
|
return [...iterable].reduce((obj, [key, val]) => {
|
|
25
27
|
obj[key] = val;
|
|
@@ -83,12 +85,17 @@ export const scrubLink = (marks, {
|
|
|
83
85
|
});
|
|
84
86
|
};
|
|
85
87
|
const scrubObj = (nodeType, attrsObj) => {
|
|
88
|
+
// Ignored via go/ees005
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
90
|
const entries = Object.entries(attrsObj).map(([key, value]) => {
|
|
87
91
|
var _BYPASS_ATTR_LIST$nod;
|
|
88
92
|
return (_BYPASS_ATTR_LIST$nod = BYPASS_ATTR_LIST[nodeType]) !== null && _BYPASS_ATTR_LIST$nod !== void 0 && _BYPASS_ATTR_LIST$nod.includes(key) ? [key, value] : [key, scrubAttrs(nodeType, value)];
|
|
89
93
|
});
|
|
90
94
|
return fromEntries(entries);
|
|
91
95
|
};
|
|
96
|
+
|
|
97
|
+
// Ignored via go/ees005
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
99
|
export const scrubAttrs = (nodeType, attrs, offset = 0) => {
|
|
93
100
|
if (typeof attrs === 'number') {
|
|
94
101
|
return scrubNum(attrs, offset);
|