@atlaskit/adf-utils 19.14.0 → 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 +17 -0
- package/afm-jira/tsconfig.json +1 -5
- package/afm-post-office/tsconfig.json +1 -5
- 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 +10 -3
- package/dist/cjs/transforms/errors.js +4 -5
- package/dist/cjs/transforms/nested-table-transform.js +14 -10
- 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 +130 -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 +15 -11
- 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 +139 -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 +10 -3
- package/dist/esm/transforms/errors.js +4 -5
- package/dist/esm/transforms/nested-table-transform.js +13 -9
- 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 +131 -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
|
@@ -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,8 +687,12 @@ 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 = {};
|
|
695
|
+
// eslint-disable-next-line guard-for-in
|
|
601
696
|
for (var invalidAttr in invalidAttrs) {
|
|
602
697
|
invalidValues[invalidAttrs[invalidAttr]] = prevEntity.attrs && prevEntity.attrs[invalidAttrs[invalidAttr]];
|
|
603
698
|
if (newEntity.attrs) {
|
|
@@ -625,13 +720,20 @@ function validator(nodes, marks, options) {
|
|
|
625
720
|
return [unsupportedNodeAttributeValues];
|
|
626
721
|
}
|
|
627
722
|
}
|
|
723
|
+
|
|
724
|
+
// Ignored via go/ees005
|
|
725
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
628
726
|
function extraPropsValidationFor(validatorSpec, prevEntity, err, newEntity, type) {
|
|
629
727
|
var result = {
|
|
630
728
|
valid: true,
|
|
631
729
|
entity: prevEntity
|
|
632
730
|
};
|
|
633
731
|
var _partitionObject5 = partitionObject(prevEntity, function (k) {
|
|
634
|
-
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
|
+
);
|
|
635
737
|
}),
|
|
636
738
|
_partitionObject6 = (0, _slicedToArray2.default)(_partitionObject5, 2),
|
|
637
739
|
requiredProps = _partitionObject6[0],
|
|
@@ -654,7 +756,13 @@ function validator(nodes, marks, options) {
|
|
|
654
756
|
}
|
|
655
757
|
return result;
|
|
656
758
|
}
|
|
657
|
-
|
|
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) {
|
|
658
766
|
var specBasedValidationResult = {
|
|
659
767
|
hasValidated: false
|
|
660
768
|
};
|
|
@@ -747,6 +855,8 @@ function validator(nodes, marks, options) {
|
|
|
747
855
|
if (validatorSpec.props.content) {
|
|
748
856
|
var contentValidatorSpec = validatorSpec.props.content;
|
|
749
857
|
if (prevEntity.content) {
|
|
858
|
+
// Ignored via go/ees005
|
|
859
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
750
860
|
var validateChildNode = function validateChildNode(child, index) {
|
|
751
861
|
if (child === undefined) {
|
|
752
862
|
return child;
|
|
@@ -758,12 +868,17 @@ function validator(nodes, marks, options) {
|
|
|
758
868
|
var validMarks = marksValidationOutput.filter(function (mark) {
|
|
759
869
|
return mark.valid;
|
|
760
870
|
});
|
|
871
|
+
// Ignored via go/ees005
|
|
872
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
761
873
|
var finalMarks = marksValidationOutput.map(function (mr) {
|
|
762
874
|
if (mr.valid) {
|
|
763
875
|
return mr.newMark;
|
|
764
876
|
} else {
|
|
765
877
|
if (validMarks.length || isLastValidationSpec || isParentTupleLike || mr.errorCode === 'INVALID_TYPE' || mr.errorCode === 'INVALID_CONTENT' || mr.errorCode === 'REDUNDANT_ATTRIBUTES' || mr.errorCode === 'INVALID_ATTRIBUTES') {
|
|
766
|
-
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);
|
|
767
882
|
}
|
|
768
883
|
return;
|
|
769
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);
|
|
@@ -30,7 +30,7 @@ const maybeRemoveDisallowedDuplicateMarks = node => {
|
|
|
30
30
|
discardedMarks
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const dedupedMarks = node.marks.filter(mark => {
|
|
34
34
|
const markType = mark.type;
|
|
35
35
|
if (markType === 'annotation') {
|
|
36
36
|
var _mark$attrs;
|
|
@@ -64,7 +64,7 @@ const maybeRemoveDisallowedDuplicateMarks = node => {
|
|
|
64
64
|
};
|
|
65
65
|
export const transformDedupeMarks = adf => {
|
|
66
66
|
let isTransformed = false;
|
|
67
|
-
|
|
67
|
+
const discardedMarks = [];
|
|
68
68
|
const transformedAdf = traverse(adf, {
|
|
69
69
|
text: node => {
|
|
70
70
|
if (maybeHasDisallowedDuplicateMarks(node)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { traverse } from '../traverse/traverse';
|
|
2
2
|
import { isEmpty } from './helpers';
|
|
3
3
|
const getChildrenTypeCounts = (nodeContent, allowedTypes) => {
|
|
4
|
-
|
|
4
|
+
const childrenTypes = {};
|
|
5
5
|
nodeContent.forEach((childNode, index) => {
|
|
6
6
|
if (!(childNode !== null && childNode !== void 0 && childNode.type) || !allowedTypes.includes(childNode.type)) {
|
|
7
7
|
return;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { traverse } from '../traverse/traverse';
|
|
2
2
|
import { extension } from '../builders';
|
|
3
3
|
import { NodeNestingTransformError } from './errors';
|
|
4
|
-
const NESTED_TABLE_EXTENSION_TYPE = 'com.atlassian.
|
|
4
|
+
const NESTED_TABLE_EXTENSION_TYPE = 'com.atlassian.confluence.migration',
|
|
5
5
|
NESTED_TABLE_EXTENSION_KEY = 'nested-table';
|
|
6
|
-
const isNestedTableExtension = extensionNode => {
|
|
6
|
+
export const isNestedTableExtension = extensionNode => {
|
|
7
7
|
var _extensionNode$attrs, _extensionNode$attrs2;
|
|
8
8
|
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;
|
|
9
9
|
};
|
|
10
10
|
const transformNestedTableExtension = nestedTableExtension => {
|
|
11
|
-
var _nestedTableExtension, _nestedTableExtension2
|
|
11
|
+
var _nestedTableExtension, _nestedTableExtension2;
|
|
12
12
|
// No content - drop the extension node
|
|
13
|
-
if (!((_nestedTableExtension = nestedTableExtension.attrs) !== null && _nestedTableExtension !== void 0 && (_nestedTableExtension2 = _nestedTableExtension.parameters) !== null && _nestedTableExtension2 !== void 0 &&
|
|
13
|
+
if (!((_nestedTableExtension = nestedTableExtension.attrs) !== null && _nestedTableExtension !== void 0 && (_nestedTableExtension2 = _nestedTableExtension.parameters) !== null && _nestedTableExtension2 !== void 0 && _nestedTableExtension2.adf)) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
try {
|
|
17
|
-
var
|
|
18
|
-
|
|
17
|
+
var _nestedTableExtension3, _nestedTableExtension4;
|
|
18
|
+
const adf = JSON.parse((_nestedTableExtension3 = nestedTableExtension.attrs) === null || _nestedTableExtension3 === void 0 ? void 0 : (_nestedTableExtension4 = _nestedTableExtension3.parameters) === null || _nestedTableExtension4 === void 0 ? void 0 : _nestedTableExtension4.adf);
|
|
19
|
+
if (!adf.content || adf.content.length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return adf.content[0];
|
|
19
23
|
} catch (e) {
|
|
20
24
|
throw new NodeNestingTransformError('Failed to parse nested table content');
|
|
21
25
|
}
|
|
@@ -47,11 +51,11 @@ export const transformNestedTableNodeOutgoingDocument = tableCellNode => {
|
|
|
47
51
|
extensionType: NESTED_TABLE_EXTENSION_TYPE,
|
|
48
52
|
extensionKey: NESTED_TABLE_EXTENSION_KEY,
|
|
49
53
|
parameters: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
54
|
+
adf: JSON.stringify({
|
|
55
|
+
type: 'doc',
|
|
56
|
+
version: 1,
|
|
57
|
+
content: [childNode]
|
|
58
|
+
})
|
|
55
59
|
}
|
|
56
60
|
});
|
|
57
61
|
}
|
|
@@ -56,6 +56,8 @@ const tryCreateValidListItemWrappedChildren = parentListNode => {
|
|
|
56
56
|
case 'text':
|
|
57
57
|
return listItem([paragraph(childNode)]);
|
|
58
58
|
default:
|
|
59
|
+
// Ignored via go/ees005
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
61
|
return listItem([childNode]);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -7,6 +7,6 @@ export { transformDedupeMarks } from './transforms/dedupe-marks-transform';
|
|
|
7
7
|
export { transformNodesMissingContent } from './transforms/nodes-missing-content-transform';
|
|
8
8
|
export { transformIndentationMarks } from './transforms/indentation-marks-transform';
|
|
9
9
|
export { transformInvalidMediaContent } from './transforms/invalid-media-content-transform';
|
|
10
|
-
export { transformNestedTablesIncomingDocument } from './transforms/nested-table-transform';
|
|
10
|
+
export { transformNestedTablesIncomingDocument, isNestedTableExtension } from './transforms/nested-table-transform';
|
|
11
11
|
export { transformNestedTableNodeOutgoingDocument } from './transforms/nested-table-transform';
|
|
12
12
|
export { NodeNestingTransformError } from './transforms/errors';
|
|
@@ -19,6 +19,9 @@ export function traverse(adf, visitors) {
|
|
|
19
19
|
node: undefined
|
|
20
20
|
}, visitors, 0, 0);
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
22
25
|
function traverseNode(adfNode, parent, visitors, index, depth) {
|
|
23
26
|
const visitor = visitors[adfNode.type] || visitors['any'];
|
|
24
27
|
let newNode = {
|
|
@@ -6,7 +6,12 @@ export const isBoolean = x => x === true || x === false || toString.call(x) ===
|
|
|
6
6
|
// This is a kludge, might replace with something like _.isString in future
|
|
7
7
|
export const isString = s => typeof s === 'string' || s instanceof String;
|
|
8
8
|
export const isPlainObject = x => typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
9
|
+
|
|
10
|
+
// Ignored via go/ees005
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
12
|
export const copy = (source, dest, key) => {
|
|
13
|
+
// Ignored via go/ees005
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
15
|
dest[key] = source[key];
|
|
11
16
|
return dest;
|
|
12
17
|
};
|