@atlaskit/adf-utils 18.0.2 → 18.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/builders/marks/alignment.js +0 -3
- package/dist/cjs/builders/marks/annotation.js +0 -3
- package/dist/cjs/builders/marks/breakout.js +0 -3
- package/dist/cjs/builders/marks/code.js +0 -3
- package/dist/cjs/builders/marks/data-consumer.js +0 -3
- package/dist/cjs/builders/marks/em.js +0 -3
- package/dist/cjs/builders/marks/fragment.js +0 -3
- package/dist/cjs/builders/marks/indentation.js +0 -3
- package/dist/cjs/builders/marks/link.js +0 -3
- package/dist/cjs/builders/marks/strike.js +0 -3
- package/dist/cjs/builders/marks/strong.js +0 -3
- package/dist/cjs/builders/marks/subsup.js +0 -3
- package/dist/cjs/builders/marks/text-color.js +0 -3
- package/dist/cjs/builders/marks/underline.js +0 -3
- package/dist/cjs/builders/nodes/block-card.js +0 -2
- package/dist/cjs/builders/nodes/blockquote.js +0 -3
- package/dist/cjs/builders/nodes/bodied-extension.js +0 -3
- package/dist/cjs/builders/nodes/bullet-list.js +0 -3
- package/dist/cjs/builders/nodes/caption.js +0 -3
- package/dist/cjs/builders/nodes/code-block.js +0 -3
- package/dist/cjs/builders/nodes/date.js +0 -2
- package/dist/cjs/builders/nodes/decision-item.js +0 -3
- package/dist/cjs/builders/nodes/decision-list.js +0 -3
- package/dist/cjs/builders/nodes/doc.js +0 -3
- package/dist/cjs/builders/nodes/embed-card.js +0 -2
- package/dist/cjs/builders/nodes/emoji.js +0 -2
- package/dist/cjs/builders/nodes/expand.js +0 -3
- package/dist/cjs/builders/nodes/extension.js +0 -2
- package/dist/cjs/builders/nodes/hard-break.js +0 -2
- package/dist/cjs/builders/nodes/heading.js +0 -3
- package/dist/cjs/builders/nodes/inline-card.js +0 -2
- package/dist/cjs/builders/nodes/inline-extension.js +0 -2
- package/dist/cjs/builders/nodes/layout-column.js +0 -2
- package/dist/cjs/builders/nodes/layout-section.js +0 -2
- package/dist/cjs/builders/nodes/list-item.js +0 -2
- package/dist/cjs/builders/nodes/media-group.js +0 -3
- package/dist/cjs/builders/nodes/media-inline.js +0 -2
- package/dist/cjs/builders/nodes/media-single.js +0 -2
- package/dist/cjs/builders/nodes/media.js +0 -2
- package/dist/cjs/builders/nodes/mention.js +0 -6
- package/dist/cjs/builders/nodes/nested-expand.js +0 -3
- package/dist/cjs/builders/nodes/ordered-list.js +0 -3
- package/dist/cjs/builders/nodes/panel.js +0 -3
- package/dist/cjs/builders/nodes/paragraph.js +0 -4
- package/dist/cjs/builders/nodes/placeholder.js +0 -2
- package/dist/cjs/builders/nodes/rule.js +0 -2
- package/dist/cjs/builders/nodes/status.js +0 -2
- package/dist/cjs/builders/nodes/table-cell.js +0 -3
- package/dist/cjs/builders/nodes/table-header.js +0 -3
- package/dist/cjs/builders/nodes/table-row.js +0 -2
- package/dist/cjs/builders/nodes/table.js +0 -3
- package/dist/cjs/builders/nodes/task-item.js +0 -3
- package/dist/cjs/builders/nodes/task-list.js +0 -3
- package/dist/cjs/builders/nodes/text.js +0 -2
- package/dist/cjs/builders/utils/apply-mark.js +0 -5
- package/dist/cjs/builders/utils/create-text-nodes.js +0 -3
- package/dist/cjs/builders/utils/is-duplicate-mark.js +0 -3
- package/dist/cjs/builders.js +0 -51
- package/dist/cjs/empty-adf.js +0 -2
- package/dist/cjs/scrub/default-node-replacements.js +0 -11
- package/dist/cjs/scrub/default-value-replacements.js +0 -2
- package/dist/cjs/scrub/hash.js +0 -4
- package/dist/cjs/scrub/scrub-adf.js +2 -25
- package/dist/cjs/scrub/scrub-content.js +7 -37
- package/dist/cjs/scrub.js +0 -2
- package/dist/cjs/transforms/dedupe-marks-transform.js +2 -23
- package/dist/cjs/transforms/helpers.js +0 -3
- package/dist/cjs/transforms/indentation-marks-transform.js +6 -14
- package/dist/cjs/transforms/invalid-media-content-transform.js +3 -22
- package/dist/cjs/transforms/media-link-transform.js +2 -12
- package/dist/cjs/transforms/nodes-missing-content-transform.js +0 -44
- package/dist/cjs/transforms/text-link-code-transform.js +3 -13
- package/dist/cjs/transforms.js +0 -6
- package/dist/cjs/traverse/filter.js +0 -2
- package/dist/cjs/traverse/map.js +0 -2
- package/dist/cjs/traverse/reduce.js +0 -2
- package/dist/cjs/traverse/traverse.js +1 -18
- package/dist/cjs/traverse.js +0 -4
- package/dist/cjs/validator/rules.js +0 -2
- package/dist/cjs/validator/specs/block_content.js +1 -1
- package/dist/cjs/validator/specs/doc.js +1 -1
- package/dist/cjs/validator/specs/index.js +2 -85
- package/dist/cjs/validator/specs/listItem.js +1 -1
- package/dist/cjs/validator/specs/nestedExpand_content.js +1 -1
- package/dist/cjs/validator/specs/non_nestable_block_content.js +1 -1
- package/dist/cjs/validator/specs/panel.js +3 -3
- package/dist/cjs/validator/specs/tableCell_content.js +1 -1
- package/dist/cjs/validator/utils.js +4 -20
- package/dist/cjs/validator/validator.js +67 -218
- package/dist/cjs/validator.js +0 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/builders/utils/apply-mark.js +0 -2
- package/dist/es2019/builders/utils/is-duplicate-mark.js +0 -1
- package/dist/es2019/builders.js +4 -1
- package/dist/es2019/scrub/default-node-replacements.js +2 -7
- package/dist/es2019/scrub/hash.js +0 -2
- package/dist/es2019/scrub/scrub-adf.js +4 -10
- package/dist/es2019/scrub/scrub-content.js +7 -20
- package/dist/es2019/transforms/dedupe-marks-transform.js +4 -16
- package/dist/es2019/transforms/helpers.js +0 -1
- package/dist/es2019/transforms/indentation-marks-transform.js +10 -10
- package/dist/es2019/transforms/invalid-media-content-transform.js +5 -15
- package/dist/es2019/transforms/media-link-transform.js +2 -9
- package/dist/es2019/transforms/nodes-missing-content-transform.js +6 -38
- package/dist/es2019/transforms/text-link-code-transform.js +5 -8
- package/dist/es2019/traverse/traverse.js +5 -13
- package/dist/es2019/validator/specs/block_content.js +1 -1
- package/dist/es2019/validator/specs/doc.js +1 -1
- package/dist/es2019/validator/specs/index.js +2 -2
- package/dist/es2019/validator/specs/listItem.js +1 -1
- package/dist/es2019/validator/specs/nestedExpand_content.js +1 -1
- package/dist/es2019/validator/specs/non_nestable_block_content.js +1 -1
- package/dist/es2019/validator/specs/panel.js +3 -3
- package/dist/es2019/validator/specs/tableCell_content.js +1 -1
- package/dist/es2019/validator/utils.js +4 -2
- package/dist/es2019/validator/validator.js +60 -174
- package/dist/es2019/version.json +1 -1
- package/dist/esm/builders/nodes/blockquote.js +0 -1
- package/dist/esm/builders/nodes/bodied-extension.js +0 -1
- package/dist/esm/builders/nodes/bullet-list.js +0 -1
- package/dist/esm/builders/nodes/caption.js +0 -1
- package/dist/esm/builders/nodes/code-block.js +0 -1
- package/dist/esm/builders/nodes/decision-item.js +0 -1
- package/dist/esm/builders/nodes/decision-list.js +0 -1
- package/dist/esm/builders/nodes/doc.js +0 -1
- package/dist/esm/builders/nodes/expand.js +0 -1
- package/dist/esm/builders/nodes/heading.js +0 -1
- package/dist/esm/builders/nodes/media-group.js +0 -1
- package/dist/esm/builders/nodes/mention.js +0 -3
- package/dist/esm/builders/nodes/nested-expand.js +0 -1
- package/dist/esm/builders/nodes/ordered-list.js +0 -1
- package/dist/esm/builders/nodes/panel.js +0 -1
- package/dist/esm/builders/nodes/paragraph.js +0 -1
- package/dist/esm/builders/nodes/table-cell.js +0 -1
- package/dist/esm/builders/nodes/table-header.js +0 -1
- package/dist/esm/builders/nodes/table.js +0 -1
- package/dist/esm/builders/nodes/task-item.js +0 -1
- package/dist/esm/builders/nodes/task-list.js +0 -1
- package/dist/esm/builders/utils/apply-mark.js +0 -2
- package/dist/esm/builders/utils/is-duplicate-mark.js +0 -1
- package/dist/esm/builders.js +4 -1
- package/dist/esm/scrub/default-node-replacements.js +0 -9
- package/dist/esm/scrub/hash.js +0 -2
- package/dist/esm/scrub/scrub-adf.js +2 -17
- package/dist/esm/scrub/scrub-content.js +7 -28
- package/dist/esm/transforms/dedupe-marks-transform.js +2 -18
- package/dist/esm/transforms/helpers.js +0 -1
- package/dist/esm/transforms/indentation-marks-transform.js +6 -11
- package/dist/esm/transforms/invalid-media-content-transform.js +3 -18
- package/dist/esm/transforms/media-link-transform.js +2 -9
- package/dist/esm/transforms/nodes-missing-content-transform.js +0 -38
- package/dist/esm/transforms/text-link-code-transform.js +3 -10
- package/dist/esm/traverse/traverse.js +1 -15
- package/dist/esm/validator/specs/block_content.js +1 -1
- package/dist/esm/validator/specs/doc.js +1 -1
- package/dist/esm/validator/specs/index.js +2 -2
- package/dist/esm/validator/specs/listItem.js +1 -1
- package/dist/esm/validator/specs/nestedExpand_content.js +1 -1
- package/dist/esm/validator/specs/non_nestable_block_content.js +1 -1
- package/dist/esm/validator/specs/panel.js +3 -3
- package/dist/esm/validator/specs/tableCell_content.js +1 -1
- package/dist/esm/validator/utils.js +4 -2
- package/dist/esm/validator/validator.js +67 -209
- package/dist/esm/version.json +1 -1
- package/dist/types/validator/specs/index.d.ts +2 -2
- package/dist/types/validator/specs/panel.d.ts +3 -3
- package/package.json +2 -2
|
@@ -2,25 +2,19 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["items"];
|
|
5
|
-
|
|
6
5
|
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; }
|
|
7
|
-
|
|
8
6
|
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) { _defineProperty(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; }
|
|
9
|
-
|
|
10
7
|
import * as specs from './specs';
|
|
11
8
|
import { copy, isBoolean, isDefined, isInteger, isNumber, isPlainObject, isString, makeArray } from './utils';
|
|
12
9
|
import { validatorFnMap } from './rules';
|
|
13
|
-
|
|
14
10
|
function mapMarksItems(spec) {
|
|
15
11
|
var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (x) {
|
|
16
12
|
return x;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
if (spec.props && spec.props.marks) {
|
|
20
15
|
var _ref = spec.props.marks,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
items = _ref.items,
|
|
17
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
24
18
|
return _objectSpread(_objectSpread({}, spec), {}, {
|
|
25
19
|
props: _objectSpread(_objectSpread({}, spec.props), {}, {
|
|
26
20
|
marks: _objectSpread(_objectSpread({}, rest), {}, {
|
|
@@ -36,33 +30,29 @@ function mapMarksItems(spec) {
|
|
|
36
30
|
return spec;
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
var partitionObject = function partitionObject(obj, predicate) {
|
|
41
34
|
return Object.keys(obj).reduce(function (acc, key) {
|
|
42
35
|
acc[predicate(key, obj[key], obj) ? 0 : 1].push(key);
|
|
43
36
|
return acc;
|
|
44
37
|
}, [[], []]);
|
|
45
38
|
};
|
|
39
|
+
|
|
46
40
|
/**
|
|
47
41
|
* Normalizes the structure of files imported form './specs'.
|
|
48
42
|
* We denormalised the spec to save bundle size.
|
|
49
43
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
44
|
function createSpec(nodes, marks) {
|
|
53
45
|
return Object.keys(specs).reduce(function (newSpecs, k) {
|
|
54
46
|
var spec = _objectSpread({}, specs[k]);
|
|
55
|
-
|
|
56
47
|
if (spec.props) {
|
|
57
48
|
spec.props = _objectSpread({}, spec.props);
|
|
58
|
-
|
|
59
49
|
if (spec.props.content) {
|
|
60
50
|
// 'tableCell_content' => { type: 'array', items: [ ... ] }
|
|
61
51
|
if (isString(spec.props.content)) {
|
|
62
52
|
spec.props.content = specs[spec.props.content];
|
|
63
|
-
}
|
|
64
|
-
|
|
53
|
+
}
|
|
65
54
|
|
|
55
|
+
// ['inline', 'emoji']
|
|
66
56
|
if (Array.isArray(spec.props.content)) {
|
|
67
57
|
/**
|
|
68
58
|
* Flatten
|
|
@@ -82,17 +72,21 @@ function createSpec(nodes, marks) {
|
|
|
82
72
|
} else {
|
|
83
73
|
spec.props.content = _objectSpread({}, spec.props.content);
|
|
84
74
|
}
|
|
75
|
+
spec.props.content.items = spec.props.content.items
|
|
85
76
|
|
|
86
|
-
|
|
77
|
+
// ['inline'] => [['emoji', 'hr', ...]]
|
|
87
78
|
// ['media'] => [['media']]
|
|
88
79
|
.map(function (item) {
|
|
89
80
|
return isString(item) ? Array.isArray(specs[item]) ? specs[item] : [item] : item;
|
|
90
|
-
})
|
|
81
|
+
})
|
|
82
|
+
// [['emoji', 'hr', 'inline_code']] => [['emoji', 'hr', ['text', { marks: {} }]]]
|
|
91
83
|
.map(function (item) {
|
|
92
84
|
return item.map(function (subItem) {
|
|
93
|
-
return Array.isArray(specs[subItem]) ? specs[subItem] : isString(subItem) ? subItem :
|
|
85
|
+
return Array.isArray(specs[subItem]) ? specs[subItem] : isString(subItem) ? subItem :
|
|
86
|
+
// Now `NoMark` produces `items: []`, should be fixed in generator
|
|
94
87
|
['text', subItem];
|
|
95
|
-
})
|
|
88
|
+
})
|
|
89
|
+
// Remove unsupported nodes & marks
|
|
96
90
|
// Filter nodes
|
|
97
91
|
.filter(function (subItem) {
|
|
98
92
|
if (nodes) {
|
|
@@ -100,23 +94,19 @@ function createSpec(nodes, marks) {
|
|
|
100
94
|
// ['mediaSingle', { props: { content: { items: [ 'media', 'caption' ] } }}]
|
|
101
95
|
if (Array.isArray(subItem)) {
|
|
102
96
|
var _subItem$, _subItem$$props, _subItem$$props$conte;
|
|
103
|
-
|
|
104
97
|
var isMainNodeSupported = nodes.indexOf(subItem[0]) > -1;
|
|
105
|
-
|
|
106
98
|
if (isMainNodeSupported && (_subItem$ = subItem[1]) !== null && _subItem$ !== void 0 && (_subItem$$props = _subItem$.props) !== null && _subItem$$props !== void 0 && (_subItem$$props$conte = _subItem$$props.content) !== null && _subItem$$props$conte !== void 0 && _subItem$$props$conte.items) {
|
|
107
99
|
return subItem[1].props.content.items.every(function (item) {
|
|
108
100
|
return nodes.indexOf(item) > -1;
|
|
109
101
|
});
|
|
110
102
|
}
|
|
111
|
-
|
|
112
103
|
return isMainNodeSupported;
|
|
113
104
|
}
|
|
114
|
-
|
|
115
105
|
return nodes.indexOf(subItem) > -1;
|
|
116
106
|
}
|
|
117
|
-
|
|
118
107
|
return true;
|
|
119
|
-
})
|
|
108
|
+
})
|
|
109
|
+
// Filter marks
|
|
120
110
|
.map(function (subItem) {
|
|
121
111
|
return Array.isArray(subItem) && marks ?
|
|
122
112
|
/**
|
|
@@ -128,71 +118,54 @@ function createSpec(nodes, marks) {
|
|
|
128
118
|
});
|
|
129
119
|
}
|
|
130
120
|
}
|
|
131
|
-
|
|
132
121
|
newSpecs[k] = spec;
|
|
133
122
|
return newSpecs;
|
|
134
123
|
}, {});
|
|
135
124
|
}
|
|
136
|
-
|
|
137
125
|
function getOptionsForType(type, list) {
|
|
138
126
|
if (!list) {
|
|
139
127
|
return {};
|
|
140
128
|
}
|
|
141
|
-
|
|
142
129
|
for (var i = 0, len = list.length; i < len; i++) {
|
|
143
130
|
var spec = list[i];
|
|
144
131
|
var _name = spec;
|
|
145
132
|
var options = {};
|
|
146
|
-
|
|
147
133
|
if (Array.isArray(spec)) {
|
|
148
134
|
var _spec = _slicedToArray(spec, 2);
|
|
149
|
-
|
|
150
135
|
_name = _spec[0];
|
|
151
136
|
options = _spec[1];
|
|
152
137
|
}
|
|
153
|
-
|
|
154
138
|
if (_name === type) {
|
|
155
139
|
return options;
|
|
156
140
|
}
|
|
157
141
|
}
|
|
158
|
-
|
|
159
142
|
return false;
|
|
160
143
|
}
|
|
161
|
-
|
|
162
144
|
export function validateAttrs(spec, value) {
|
|
163
145
|
// extension_node parameters has no type
|
|
164
146
|
if (!isDefined(spec.type)) {
|
|
165
147
|
return !!spec.optional;
|
|
166
148
|
}
|
|
167
|
-
|
|
168
149
|
if (!isDefined(value)) {
|
|
169
150
|
return !!spec.optional;
|
|
170
151
|
}
|
|
171
|
-
|
|
172
152
|
switch (spec.type) {
|
|
173
153
|
case 'boolean':
|
|
174
154
|
return isBoolean(value);
|
|
175
|
-
|
|
176
155
|
case 'number':
|
|
177
156
|
return isNumber(value) && (isDefined(spec.minimum) ? spec.minimum <= value : true) && (isDefined(spec.maximum) ? spec.maximum >= value : true);
|
|
178
|
-
|
|
179
157
|
case 'integer':
|
|
180
158
|
return isInteger(value) && (isDefined(spec.minimum) ? spec.minimum <= value : true) && (isDefined(spec.maximum) ? spec.maximum >= value : true);
|
|
181
|
-
|
|
182
159
|
case 'string':
|
|
183
160
|
var validatorFnPassed = function validatorFnPassed(rule) {
|
|
184
161
|
return typeof value === 'string' && isDefined(validatorFnMap[rule]) && validatorFnMap[rule](value);
|
|
185
162
|
};
|
|
186
|
-
|
|
187
163
|
return isString(value) && (isDefined(spec.minLength) ? spec.minLength <= value.length : true) && (isDefined(spec.validatorFn) ? validatorFnPassed(spec.validatorFn) : true) && (spec.pattern ? new RegExp(spec.pattern).test(value) : true);
|
|
188
|
-
|
|
189
164
|
case 'object':
|
|
190
165
|
return isPlainObject(value);
|
|
191
|
-
|
|
192
166
|
case 'array':
|
|
193
167
|
var types = spec.items;
|
|
194
168
|
var lastTypeIndex = types.length - 1;
|
|
195
|
-
|
|
196
169
|
if (Array.isArray(value)) {
|
|
197
170
|
// We are doing this to support tuple which can be defined as [number, string]
|
|
198
171
|
// NOTE: Not validating tuples strictly
|
|
@@ -200,37 +173,29 @@ export function validateAttrs(spec, value) {
|
|
|
200
173
|
return validateAttrs(types[Math.min(i, lastTypeIndex)], x);
|
|
201
174
|
});
|
|
202
175
|
}
|
|
203
|
-
|
|
204
176
|
return false;
|
|
205
|
-
|
|
206
177
|
case 'enum':
|
|
207
178
|
return isString(value) && spec.values.indexOf(value) > -1;
|
|
208
179
|
}
|
|
209
|
-
|
|
210
180
|
return false;
|
|
211
181
|
}
|
|
212
|
-
|
|
213
182
|
var errorMessageFor = function errorMessageFor(type, message) {
|
|
214
183
|
return "".concat(type, ": ").concat(message, ".");
|
|
215
184
|
};
|
|
216
|
-
|
|
217
185
|
var getUnsupportedOptions = function getUnsupportedOptions(spec) {
|
|
218
186
|
if (spec && spec.props && spec.props.content) {
|
|
219
187
|
var _spec$props$content = spec.props.content,
|
|
220
|
-
|
|
221
|
-
|
|
188
|
+
allowUnsupportedBlock = _spec$props$content.allowUnsupportedBlock,
|
|
189
|
+
allowUnsupportedInline = _spec$props$content.allowUnsupportedInline;
|
|
222
190
|
return {
|
|
223
191
|
allowUnsupportedBlock: allowUnsupportedBlock,
|
|
224
192
|
allowUnsupportedInline: allowUnsupportedInline
|
|
225
193
|
};
|
|
226
194
|
}
|
|
227
|
-
|
|
228
195
|
return {};
|
|
229
196
|
};
|
|
230
|
-
|
|
231
197
|
var invalidChildContent = function invalidChildContent(child, errorCallback, parentSpec) {
|
|
232
198
|
var message = errorMessageFor(child.type, 'invalid content');
|
|
233
|
-
|
|
234
199
|
if (!errorCallback) {
|
|
235
200
|
throw new Error(message);
|
|
236
201
|
} else {
|
|
@@ -240,10 +205,8 @@ var invalidChildContent = function invalidChildContent(child, errorCallback, par
|
|
|
240
205
|
}, getUnsupportedOptions(parentSpec));
|
|
241
206
|
}
|
|
242
207
|
};
|
|
243
|
-
|
|
244
208
|
var unsupportedMarkContent = function unsupportedMarkContent(errorCode, mark, errorCallback, errorMessage) {
|
|
245
209
|
var message = errorMessage || errorMessageFor(mark.type, 'unsupported mark');
|
|
246
|
-
|
|
247
210
|
if (!errorCallback) {
|
|
248
211
|
throw new Error(message);
|
|
249
212
|
} else {
|
|
@@ -258,7 +221,6 @@ var unsupportedMarkContent = function unsupportedMarkContent(errorCode, mark, er
|
|
|
258
221
|
});
|
|
259
222
|
}
|
|
260
223
|
};
|
|
261
|
-
|
|
262
224
|
var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent(entity, errorCode, invalidAttributes, message, errorCallback) {
|
|
263
225
|
if (!errorCallback) {
|
|
264
226
|
throw new Error(message);
|
|
@@ -277,16 +239,13 @@ var unsupportedNodeAttributesContent = function unsupportedNodeAttributesContent
|
|
|
277
239
|
});
|
|
278
240
|
}
|
|
279
241
|
};
|
|
280
|
-
|
|
281
242
|
export function validator(nodes, marks, options) {
|
|
282
243
|
var validatorSpecs = createSpec(nodes, marks);
|
|
283
|
-
|
|
284
244
|
var _ref2 = options || {},
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
245
|
+
_ref2$mode = _ref2.mode,
|
|
246
|
+
mode = _ref2$mode === void 0 ? 'strict' : _ref2$mode,
|
|
247
|
+
_ref2$allowPrivateAtt = _ref2.allowPrivateAttributes,
|
|
248
|
+
allowPrivateAttributes = _ref2$allowPrivateAtt === void 0 ? false : _ref2$allowPrivateAtt;
|
|
290
249
|
var validate = function validate(entity, errorCallback, allowed, parentSpec) {
|
|
291
250
|
var validationResult = validateNode(entity, errorCallback, allowed, parentSpec);
|
|
292
251
|
return {
|
|
@@ -294,16 +253,12 @@ export function validator(nodes, marks, options) {
|
|
|
294
253
|
valid: validationResult.valid
|
|
295
254
|
};
|
|
296
255
|
};
|
|
297
|
-
|
|
298
256
|
var validateNode = function validateNode(entity, errorCallback, allowed, parentSpec) {
|
|
299
257
|
var isMark = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
300
258
|
var type = entity.type;
|
|
301
|
-
|
|
302
259
|
var newEntity = _objectSpread({}, entity);
|
|
303
|
-
|
|
304
260
|
var err = function err(code, msg, meta) {
|
|
305
261
|
var message = errorMessageFor(type, msg);
|
|
306
|
-
|
|
307
262
|
if (errorCallback) {
|
|
308
263
|
return {
|
|
309
264
|
valid: false,
|
|
@@ -317,42 +272,32 @@ export function validator(nodes, marks, options) {
|
|
|
317
272
|
throw new Error(message);
|
|
318
273
|
}
|
|
319
274
|
};
|
|
320
|
-
|
|
321
275
|
if (type) {
|
|
322
276
|
var typeOptions = getOptionsForType(type, allowed);
|
|
323
|
-
|
|
324
277
|
if (typeOptions === false) {
|
|
325
278
|
return isMark ? {
|
|
326
279
|
valid: false
|
|
327
280
|
} : err('INVALID_TYPE', 'type not allowed here');
|
|
328
281
|
}
|
|
329
|
-
|
|
330
282
|
var spec = validatorSpecs[type];
|
|
331
|
-
|
|
332
283
|
if (!spec) {
|
|
333
284
|
return err('INVALID_TYPE', "".concat(type, ": No validation spec found for type!"));
|
|
334
285
|
}
|
|
335
|
-
|
|
336
286
|
var specBasedValidationResult = specBasedValidationFor(spec, typeOptions, entity, err, newEntity, type, errorCallback, isMark);
|
|
337
|
-
|
|
338
287
|
if (specBasedValidationResult.hasValidated && specBasedValidationResult.result) {
|
|
339
288
|
return specBasedValidationResult.result;
|
|
340
289
|
}
|
|
341
290
|
} else {
|
|
342
291
|
return err('INVALID_TYPE', 'ProseMirror Node/Mark should contain a `type`');
|
|
343
292
|
}
|
|
344
|
-
|
|
345
293
|
return {
|
|
346
294
|
valid: true,
|
|
347
295
|
entity: newEntity
|
|
348
296
|
};
|
|
349
297
|
};
|
|
350
|
-
|
|
351
298
|
return validate;
|
|
352
|
-
|
|
353
299
|
function marksValidationFor(validator, entity, errorCallback, newEntity, err) {
|
|
354
300
|
var validationResult;
|
|
355
|
-
|
|
356
301
|
if (validator.props && validator.props.marks) {
|
|
357
302
|
var marksSet = allowedMarksFor(validator);
|
|
358
303
|
var marksValidationResult = marksAfterValidation(entity, errorCallback, marksSet, validator);
|
|
@@ -364,31 +309,27 @@ export function validator(nodes, marks, options) {
|
|
|
364
309
|
} else {
|
|
365
310
|
validationResult = marksForEntitySpecNotSupportingMarks(entity, newEntity, errorCallback, err);
|
|
366
311
|
}
|
|
367
|
-
|
|
368
312
|
return validationResult;
|
|
369
313
|
}
|
|
370
|
-
|
|
371
314
|
function validatorFor(spec, typeOptions) {
|
|
372
315
|
return _objectSpread(_objectSpread(_objectSpread({}, spec), typeOptions), spec.props ? {
|
|
373
316
|
props: _objectSpread(_objectSpread({}, spec.props), typeOptions['props'] || {})
|
|
374
317
|
} : {});
|
|
375
318
|
}
|
|
376
|
-
|
|
377
319
|
function marksAfterValidation(entity, errorCallback, marksSet, validator) {
|
|
378
320
|
return entity.marks ? entity.marks.map(function (mark) {
|
|
379
321
|
var isAKnownMark = marks ? marks.indexOf(mark.type) > -1 : true;
|
|
380
|
-
|
|
381
322
|
if (mode === 'strict' && isAKnownMark) {
|
|
382
323
|
var finalResult = validateNode(mark, errorCallback, marksSet, validator, true);
|
|
383
324
|
var finalMark = finalResult.entity;
|
|
384
|
-
|
|
385
325
|
if (finalMark) {
|
|
386
326
|
return {
|
|
387
327
|
valid: true,
|
|
388
328
|
originalMark: mark,
|
|
389
329
|
newMark: finalMark
|
|
390
330
|
};
|
|
391
|
-
}
|
|
331
|
+
}
|
|
332
|
+
// this checks for mark level attribute errors
|
|
392
333
|
// and propagates error code and message
|
|
393
334
|
else if (finalResult.marksValidationOutput && finalResult.marksValidationOutput.length) {
|
|
394
335
|
return {
|
|
@@ -413,27 +354,22 @@ export function validator(nodes, marks, options) {
|
|
|
413
354
|
}
|
|
414
355
|
}) : [];
|
|
415
356
|
}
|
|
416
|
-
|
|
417
357
|
function allowedMarksFor(validator) {
|
|
418
358
|
var _ref3 = validator.props.marks,
|
|
419
|
-
|
|
359
|
+
items = _ref3.items;
|
|
420
360
|
var marksSet = items.length ? Array.isArray(items[0]) ? items[0] : items : [];
|
|
421
361
|
return marksSet;
|
|
422
362
|
}
|
|
423
|
-
|
|
424
363
|
function marksForEntitySpecNotSupportingMarks(prevEntity, newEntity, errorCallback, err) {
|
|
425
364
|
var errorCode = 'REDUNDANT_MARKS';
|
|
426
365
|
var currentMarks = prevEntity.marks || [];
|
|
427
366
|
var newMarks = currentMarks.map(function (mark) {
|
|
428
367
|
var isUnsupportedNodeAttributeMark = mark.type === 'unsupportedNodeAttribute';
|
|
429
|
-
|
|
430
368
|
if (isUnsupportedNodeAttributeMark) {
|
|
431
369
|
return mark;
|
|
432
370
|
}
|
|
433
|
-
|
|
434
371
|
return unsupportedMarkContent(errorCode, mark, errorCallback);
|
|
435
372
|
});
|
|
436
|
-
|
|
437
373
|
if (newMarks.length) {
|
|
438
374
|
newEntity.marks = newMarks;
|
|
439
375
|
return {
|
|
@@ -446,13 +382,11 @@ export function validator(nodes, marks, options) {
|
|
|
446
382
|
});
|
|
447
383
|
}
|
|
448
384
|
}
|
|
449
|
-
|
|
450
385
|
function requiredPropertyValidationFor(validatorSpec, prevEntity, err) {
|
|
451
386
|
var result = {
|
|
452
387
|
valid: true,
|
|
453
388
|
entity: prevEntity
|
|
454
389
|
};
|
|
455
|
-
|
|
456
390
|
if (validatorSpec.required) {
|
|
457
391
|
if (!validatorSpec.required.every(function (prop) {
|
|
458
392
|
return isDefined(prevEntity[prop]);
|
|
@@ -460,37 +394,30 @@ export function validator(nodes, marks, options) {
|
|
|
460
394
|
result = err('MISSING_PROPERTIES', 'required prop missing');
|
|
461
395
|
}
|
|
462
396
|
}
|
|
463
|
-
|
|
464
397
|
return result;
|
|
465
398
|
}
|
|
466
|
-
|
|
467
399
|
function textPropertyValidationFor(validatorSpec, prevEntity, err) {
|
|
468
400
|
var result = {
|
|
469
401
|
valid: true,
|
|
470
402
|
entity: prevEntity
|
|
471
403
|
};
|
|
472
|
-
|
|
473
404
|
if (validatorSpec.props.text) {
|
|
474
405
|
if (isDefined(prevEntity.text) && !validateAttrs(validatorSpec.props.text, prevEntity.text)) {
|
|
475
406
|
result = err('INVALID_TEXT', "'text' validation failed");
|
|
476
407
|
}
|
|
477
408
|
}
|
|
478
|
-
|
|
479
409
|
return result;
|
|
480
410
|
}
|
|
481
|
-
|
|
482
411
|
function contentLengthValidationFor(validatorSpec, prevEntity, err) {
|
|
483
412
|
var result = {
|
|
484
413
|
valid: true,
|
|
485
414
|
entity: prevEntity
|
|
486
415
|
};
|
|
487
|
-
|
|
488
416
|
if (validatorSpec.props.content && prevEntity.content) {
|
|
489
417
|
var _content = validatorSpec.props.content,
|
|
490
|
-
|
|
491
|
-
|
|
418
|
+
minItems = _content.minItems,
|
|
419
|
+
maxItems = _content.maxItems;
|
|
492
420
|
var length = prevEntity.content.length;
|
|
493
|
-
|
|
494
421
|
if (isDefined(minItems) && minItems > length) {
|
|
495
422
|
result = err('INVALID_CONTENT_LENGTH', "'content' should have more than ".concat(minItems, " child"), {
|
|
496
423
|
length: length,
|
|
@@ -505,14 +432,11 @@ export function validator(nodes, marks, options) {
|
|
|
505
432
|
});
|
|
506
433
|
}
|
|
507
434
|
}
|
|
508
|
-
|
|
509
435
|
return result;
|
|
510
436
|
}
|
|
511
|
-
|
|
512
437
|
function invalidAttributesFor(validatorSpec, prevEntity) {
|
|
513
438
|
var invalidAttrs = [];
|
|
514
439
|
var validatorAttrs = {};
|
|
515
|
-
|
|
516
440
|
if (validatorSpec.props && validatorSpec.props.attrs) {
|
|
517
441
|
var attrOptions = makeArray(validatorSpec.props.attrs);
|
|
518
442
|
/**
|
|
@@ -520,67 +444,52 @@ export function validator(nodes, marks, options) {
|
|
|
520
444
|
* attrs: [{ props: { url: { type: 'string' } } }, { props: { data: {} } }],
|
|
521
445
|
* Gotcha: It will always report the last failure.
|
|
522
446
|
*/
|
|
523
|
-
|
|
524
447
|
for (var i = 0, length = attrOptions.length; i < length; ++i) {
|
|
525
448
|
var attrOption = attrOptions[i];
|
|
526
|
-
|
|
527
449
|
if (attrOption && attrOption.props) {
|
|
528
450
|
var _partitionObject = partitionObject(attrOption.props, function (k, v) {
|
|
529
451
|
return validateAttrs(v, prevEntity.attrs[k]);
|
|
530
452
|
});
|
|
531
|
-
|
|
532
453
|
var _partitionObject2 = _slicedToArray(_partitionObject, 2);
|
|
533
|
-
|
|
534
454
|
invalidAttrs = _partitionObject2[1];
|
|
535
455
|
}
|
|
536
|
-
|
|
537
456
|
validatorAttrs = attrOption;
|
|
538
|
-
|
|
539
457
|
if (!invalidAttrs.length) {
|
|
540
458
|
break;
|
|
541
459
|
}
|
|
542
460
|
}
|
|
543
461
|
}
|
|
544
|
-
|
|
545
462
|
return {
|
|
546
463
|
invalidAttrs: invalidAttrs,
|
|
547
464
|
validatorAttrs: validatorAttrs
|
|
548
465
|
};
|
|
549
466
|
}
|
|
550
|
-
|
|
551
467
|
function attributesValidationFor(validatorSpec, prevEntity, newEntity, isMark, errorCallback) {
|
|
552
468
|
var validatorSpecAllowsAttributes = validatorSpec.props && validatorSpec.props.attrs;
|
|
553
|
-
|
|
554
469
|
if (prevEntity.attrs) {
|
|
555
470
|
if (!validatorSpecAllowsAttributes) {
|
|
556
471
|
if (isMark) {
|
|
557
472
|
return handleNoAttibutesAllowedInSpecForMark(prevEntity, prevEntity.attrs);
|
|
558
473
|
}
|
|
559
|
-
|
|
560
474
|
var attrs = Object.keys(prevEntity.attrs);
|
|
561
475
|
return handleUnsupportedNodeAttributes(prevEntity, newEntity, [], attrs, errorCallback);
|
|
562
476
|
}
|
|
563
|
-
|
|
564
477
|
var _validateAttributes = validateAttributes(validatorSpec, prevEntity, prevEntity.attrs),
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
478
|
+
hasUnsupportedAttrs = _validateAttributes.hasUnsupportedAttrs,
|
|
479
|
+
redundantAttrs = _validateAttributes.redundantAttrs,
|
|
480
|
+
invalidAttrs = _validateAttributes.invalidAttrs;
|
|
569
481
|
if (hasUnsupportedAttrs) {
|
|
570
482
|
if (isMark) {
|
|
571
483
|
return handleUnsupportedMarkAttributes(prevEntity, invalidAttrs, redundantAttrs);
|
|
572
484
|
}
|
|
573
|
-
|
|
574
485
|
return handleUnsupportedNodeAttributes(prevEntity, newEntity, invalidAttrs, redundantAttrs, errorCallback);
|
|
575
486
|
}
|
|
576
487
|
}
|
|
577
|
-
|
|
578
488
|
return {
|
|
579
489
|
valid: true,
|
|
580
490
|
entity: prevEntity
|
|
581
491
|
};
|
|
582
492
|
}
|
|
583
|
-
|
|
584
493
|
function validateAttributes(validatorSpec, prevEntity, attributes) {
|
|
585
494
|
var invalidAttributesResult = invalidAttributesFor(validatorSpec, prevEntity);
|
|
586
495
|
var invalidAttrs = invalidAttributesResult.invalidAttrs;
|
|
@@ -599,7 +508,6 @@ export function validator(nodes, marks, options) {
|
|
|
599
508
|
redundantAttrs: redundantAttrs
|
|
600
509
|
};
|
|
601
510
|
}
|
|
602
|
-
|
|
603
511
|
function handleUnsupportedNodeAttributes(prevEntity, newEntity, invalidAttrs, redundantAttrs, errorCallback) {
|
|
604
512
|
var attr = invalidAttrs.concat(redundantAttrs);
|
|
605
513
|
var result = {
|
|
@@ -615,18 +523,15 @@ export function validator(nodes, marks, options) {
|
|
|
615
523
|
};
|
|
616
524
|
return result;
|
|
617
525
|
}
|
|
618
|
-
|
|
619
526
|
function handleUnsupportedMarkAttributes(prevEntity, invalidAttrs, redundantAttrs) {
|
|
620
527
|
var errorCode = 'INVALID_ATTRIBUTES';
|
|
621
528
|
var message = errorMessageFor(prevEntity.type, "'attrs' validation failed");
|
|
622
529
|
var hasRedundantAttrs = redundantAttrs.length;
|
|
623
530
|
var hasBothInvalidAndRedundantAttrs = hasRedundantAttrs && invalidAttrs.length;
|
|
624
|
-
|
|
625
531
|
if (!hasBothInvalidAndRedundantAttrs && hasRedundantAttrs) {
|
|
626
532
|
errorCode = 'REDUNDANT_ATTRIBUTES';
|
|
627
533
|
message = errorMessageFor('redundant attributes found', redundantAttrs.join(', '));
|
|
628
534
|
}
|
|
629
|
-
|
|
630
535
|
var markValidationResult = {
|
|
631
536
|
valid: true,
|
|
632
537
|
originalMark: prevEntity,
|
|
@@ -638,7 +543,6 @@ export function validator(nodes, marks, options) {
|
|
|
638
543
|
marksValidationOutput: [markValidationResult]
|
|
639
544
|
};
|
|
640
545
|
}
|
|
641
|
-
|
|
642
546
|
function handleNoAttibutesAllowedInSpecForMark(prevEntity, attributes) {
|
|
643
547
|
var message = errorMessageFor('redundant attributes found', Object.keys(attributes).join(', '));
|
|
644
548
|
var errorCode = 'REDUNDANT_ATTRIBUTES';
|
|
@@ -653,22 +557,16 @@ export function validator(nodes, marks, options) {
|
|
|
653
557
|
marksValidationOutput: [markValidationResult]
|
|
654
558
|
};
|
|
655
559
|
}
|
|
656
|
-
|
|
657
560
|
function wrapUnSupportedNodeAttributes(prevEntity, newEntity, invalidAttrs, errorCode, message, errorCallback) {
|
|
658
561
|
var invalidValues = {};
|
|
659
|
-
|
|
660
562
|
for (var invalidAttr in invalidAttrs) {
|
|
661
563
|
invalidValues[invalidAttrs[invalidAttr]] = prevEntity.attrs && prevEntity.attrs[invalidAttrs[invalidAttr]];
|
|
662
|
-
|
|
663
564
|
if (newEntity.attrs) {
|
|
664
565
|
delete newEntity.attrs[invalidAttrs[invalidAttr]];
|
|
665
566
|
}
|
|
666
567
|
}
|
|
667
|
-
|
|
668
568
|
var unsupportedNodeAttributeValues = unsupportedNodeAttributesContent(prevEntity, errorCode, invalidValues, message, errorCallback);
|
|
669
|
-
|
|
670
569
|
var finalEntity = _objectSpread({}, newEntity);
|
|
671
|
-
|
|
672
570
|
if (finalEntity.marks) {
|
|
673
571
|
unsupportedNodeAttributeValues && finalEntity.marks.push(unsupportedNodeAttributeValues);
|
|
674
572
|
return finalEntity.marks;
|
|
@@ -676,20 +574,17 @@ export function validator(nodes, marks, options) {
|
|
|
676
574
|
return [unsupportedNodeAttributeValues];
|
|
677
575
|
}
|
|
678
576
|
}
|
|
679
|
-
|
|
680
577
|
function extraPropsValidationFor(validatorSpec, prevEntity, err, newEntity, type) {
|
|
681
578
|
var result = {
|
|
682
579
|
valid: true,
|
|
683
580
|
entity: prevEntity
|
|
684
581
|
};
|
|
685
|
-
|
|
686
582
|
var _partitionObject3 = partitionObject(prevEntity, function (k) {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
583
|
+
return isDefined(validatorSpec.props[k]);
|
|
584
|
+
}),
|
|
585
|
+
_partitionObject4 = _slicedToArray(_partitionObject3, 2),
|
|
586
|
+
requiredProps = _partitionObject4[0],
|
|
587
|
+
redundantProps = _partitionObject4[1];
|
|
693
588
|
if (redundantProps.length) {
|
|
694
589
|
if (mode === 'loose') {
|
|
695
590
|
newEntity = {
|
|
@@ -706,34 +601,29 @@ export function validator(nodes, marks, options) {
|
|
|
706
601
|
}
|
|
707
602
|
}
|
|
708
603
|
}
|
|
709
|
-
|
|
710
604
|
return result;
|
|
711
605
|
}
|
|
712
|
-
|
|
713
606
|
function specBasedValidationFor(spec, typeOptions, prevEntity, err, newEntity, type, errorCallback, isMark) {
|
|
714
607
|
var specBasedValidationResult = {
|
|
715
608
|
hasValidated: false
|
|
716
609
|
};
|
|
717
610
|
var validatorSpec = validatorFor(spec, typeOptions);
|
|
718
|
-
|
|
719
611
|
if (!validatorSpec) {
|
|
720
612
|
return specBasedValidationResult;
|
|
721
|
-
}
|
|
722
|
-
// For array format where `required` is an array
|
|
723
|
-
|
|
613
|
+
}
|
|
724
614
|
|
|
615
|
+
// Required Props
|
|
616
|
+
// For array format where `required` is an array
|
|
725
617
|
var requiredPropertyValidatonResult = requiredPropertyValidationFor(validatorSpec, prevEntity, err);
|
|
726
|
-
|
|
727
618
|
if (!requiredPropertyValidatonResult.valid) {
|
|
728
619
|
return {
|
|
729
620
|
hasValidated: true,
|
|
730
621
|
result: requiredPropertyValidatonResult
|
|
731
622
|
};
|
|
732
623
|
}
|
|
733
|
-
|
|
734
624
|
if (!validatorSpec.props) {
|
|
735
|
-
var props = Object.keys(prevEntity);
|
|
736
|
-
|
|
625
|
+
var props = Object.keys(prevEntity);
|
|
626
|
+
// If there's no validator.props then there shouldn't be any key except `type`
|
|
737
627
|
if (props.length > 1) {
|
|
738
628
|
return {
|
|
739
629
|
hasValidated: true,
|
|
@@ -742,38 +632,33 @@ export function validator(nodes, marks, options) {
|
|
|
742
632
|
})
|
|
743
633
|
};
|
|
744
634
|
}
|
|
745
|
-
|
|
746
635
|
return specBasedValidationResult;
|
|
747
|
-
}
|
|
748
|
-
|
|
636
|
+
}
|
|
749
637
|
|
|
638
|
+
// Check text
|
|
750
639
|
var textPropertyValidationResult = textPropertyValidationFor(validatorSpec, prevEntity, err);
|
|
751
|
-
|
|
752
640
|
if (!textPropertyValidationResult.valid) {
|
|
753
641
|
return {
|
|
754
642
|
hasValidated: true,
|
|
755
643
|
result: textPropertyValidationResult
|
|
756
644
|
};
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
|
|
645
|
+
}
|
|
646
|
+
// Content Length
|
|
760
647
|
var contentLengthValidationResult = contentLengthValidationFor(validatorSpec, prevEntity, err);
|
|
761
|
-
|
|
762
648
|
if (!contentLengthValidationResult.valid) {
|
|
763
649
|
return {
|
|
764
650
|
hasValidated: true,
|
|
765
651
|
result: contentLengthValidationResult
|
|
766
652
|
};
|
|
767
|
-
}
|
|
768
|
-
// For object format based on `optional` property
|
|
769
|
-
|
|
653
|
+
}
|
|
770
654
|
|
|
655
|
+
// Required Props
|
|
656
|
+
// For object format based on `optional` property
|
|
771
657
|
var _partitionObject5 = partitionObject(validatorSpec.props, function (k, v) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
658
|
+
return v.optional || isDefined(prevEntity[k]);
|
|
659
|
+
}),
|
|
660
|
+
_partitionObject6 = _slicedToArray(_partitionObject5, 2),
|
|
661
|
+
missingProps = _partitionObject6[1];
|
|
777
662
|
if (missingProps.length) {
|
|
778
663
|
return {
|
|
779
664
|
hasValidated: true,
|
|
@@ -782,46 +667,38 @@ export function validator(nodes, marks, options) {
|
|
|
782
667
|
})
|
|
783
668
|
};
|
|
784
669
|
}
|
|
785
|
-
|
|
786
670
|
var attributesValidationResult = attributesValidationFor(validatorSpec, prevEntity, newEntity, isMark, errorCallback);
|
|
787
|
-
|
|
788
671
|
if (!attributesValidationResult.valid) {
|
|
789
672
|
return {
|
|
790
673
|
hasValidated: true,
|
|
791
674
|
result: attributesValidationResult
|
|
792
675
|
};
|
|
793
676
|
}
|
|
794
|
-
|
|
795
677
|
if (isMark && attributesValidationResult.valid) {
|
|
796
678
|
return {
|
|
797
679
|
hasValidated: true,
|
|
798
680
|
result: attributesValidationResult
|
|
799
681
|
};
|
|
800
682
|
}
|
|
801
|
-
|
|
802
683
|
var extraPropsValidationResult = extraPropsValidationFor(validatorSpec, prevEntity, err, newEntity, type);
|
|
803
|
-
|
|
804
684
|
if (!extraPropsValidationResult.valid) {
|
|
805
685
|
return {
|
|
806
686
|
hasValidated: true,
|
|
807
687
|
result: extraPropsValidationResult
|
|
808
688
|
};
|
|
809
|
-
}
|
|
810
|
-
|
|
689
|
+
}
|
|
811
690
|
|
|
691
|
+
// Children
|
|
812
692
|
if (validatorSpec.props.content) {
|
|
813
693
|
var contentValidatorSpec = validatorSpec.props.content;
|
|
814
|
-
|
|
815
694
|
if (prevEntity.content) {
|
|
816
695
|
var validateChildNode = function validateChildNode(child, index) {
|
|
817
696
|
if (child === undefined) {
|
|
818
697
|
return child;
|
|
819
698
|
}
|
|
820
|
-
|
|
821
699
|
var validateChildMarks = function validateChildMarks(childEntity, marksValidationOutput, errorCallback, isLastValidationSpec) {
|
|
822
700
|
var isParentTupleLike = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
823
701
|
var marksAreValid = true;
|
|
824
|
-
|
|
825
702
|
if (childEntity && childEntity.marks && marksValidationOutput) {
|
|
826
703
|
var validMarks = marksValidationOutput.filter(function (mark) {
|
|
827
704
|
return mark.valid;
|
|
@@ -833,11 +710,9 @@ export function validator(nodes, marks, options) {
|
|
|
833
710
|
if (validMarks.length || isLastValidationSpec || isParentTupleLike || mr.errorCode === 'INVALID_TYPE' || mr.errorCode === 'INVALID_CONTENT' || mr.errorCode === 'REDUNDANT_ATTRIBUTES' || mr.errorCode === 'INVALID_ATTRIBUTES') {
|
|
834
711
|
return unsupportedMarkContent(mr.errorCode, mr.originalMark, errorCallback, mr.message);
|
|
835
712
|
}
|
|
836
|
-
|
|
837
713
|
return;
|
|
838
714
|
}
|
|
839
715
|
}).filter(Boolean);
|
|
840
|
-
|
|
841
716
|
if (finalMarks.length) {
|
|
842
717
|
childEntity.marks = finalMarks;
|
|
843
718
|
} else {
|
|
@@ -845,77 +720,63 @@ export function validator(nodes, marks, options) {
|
|
|
845
720
|
marksAreValid = false;
|
|
846
721
|
}
|
|
847
722
|
}
|
|
848
|
-
|
|
849
723
|
return {
|
|
850
724
|
valid: marksAreValid,
|
|
851
725
|
entity: childEntity
|
|
852
726
|
};
|
|
853
727
|
};
|
|
854
|
-
|
|
855
728
|
var hasMultipleCombinationOfContentAllowed = !!contentValidatorSpec.isTupleLike;
|
|
856
|
-
|
|
857
729
|
if (hasMultipleCombinationOfContentAllowed) {
|
|
858
730
|
var _validateNode = validateNode(child, errorCallback, makeArray(contentValidatorSpec.items[index] || contentValidatorSpec.items[contentValidatorSpec.items.length - 1]), validatorSpec),
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
731
|
+
newChildEntity = _validateNode.entity,
|
|
732
|
+
marksValidationOutput = _validateNode.marksValidationOutput;
|
|
862
733
|
var _validateChildMarks = validateChildMarks(newChildEntity, marksValidationOutput, errorCallback, false, true),
|
|
863
|
-
|
|
864
|
-
|
|
734
|
+
entity = _validateChildMarks.entity;
|
|
865
735
|
return entity;
|
|
866
|
-
}
|
|
867
|
-
|
|
736
|
+
}
|
|
868
737
|
|
|
738
|
+
// Only go inside valid branch
|
|
869
739
|
var allowedSpecsForEntity = contentValidatorSpec.items.filter(function (item) {
|
|
870
|
-
return Array.isArray(item) ? item.some(
|
|
740
|
+
return Array.isArray(item) ? item.some(
|
|
741
|
+
// [p, hr, ...] or [p, [text, {}], ...]
|
|
871
742
|
function (spec) {
|
|
872
743
|
return (Array.isArray(spec) ? spec[0] : spec) === child.type;
|
|
873
744
|
}) : true;
|
|
874
745
|
});
|
|
875
|
-
|
|
876
746
|
if (allowedSpecsForEntity.length) {
|
|
877
747
|
if (allowedSpecsForEntity.length > 1) {
|
|
878
748
|
throw new Error('Consider using Tuple instead!');
|
|
879
749
|
}
|
|
880
|
-
|
|
881
750
|
var maybeArray = makeArray(allowedSpecsForEntity[0]);
|
|
882
751
|
var allowedSpecsForChild = maybeArray.filter(function (item) {
|
|
883
752
|
return (Array.isArray(item) ? item[0] : item) === child.type;
|
|
884
753
|
});
|
|
885
|
-
|
|
886
754
|
if (allowedSpecsForChild.length === 0) {
|
|
887
755
|
return invalidChildContent(child, errorCallback, validatorSpec);
|
|
888
756
|
}
|
|
757
|
+
|
|
889
758
|
/**
|
|
890
759
|
* When there's multiple possible branches try all of them.
|
|
891
760
|
* If all of them fails, throw the first one.
|
|
892
761
|
* e.g.- [['text', { marks: ['a'] }], ['text', { marks: ['b'] }]]
|
|
893
762
|
*/
|
|
894
|
-
|
|
895
|
-
|
|
896
763
|
var firstError;
|
|
897
764
|
var firstChild;
|
|
898
|
-
|
|
899
765
|
for (var i = 0, len = allowedSpecsForChild.length; i < len; i++) {
|
|
900
766
|
try {
|
|
901
767
|
var allowedValueForCurrentSpec = [allowedSpecsForChild[i]];
|
|
902
|
-
|
|
903
768
|
var _validateNode2 = validateNode(child, errorCallback, allowedValueForCurrentSpec, validatorSpec),
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
769
|
+
valid = _validateNode2.valid,
|
|
770
|
+
_newChildEntity = _validateNode2.entity,
|
|
771
|
+
_marksValidationOutput = _validateNode2.marksValidationOutput;
|
|
908
772
|
if (valid) {
|
|
909
773
|
var isLastValidationSpec = i === allowedSpecsForChild.length - 1;
|
|
910
|
-
|
|
911
774
|
var _validateChildMarks2 = validateChildMarks(_newChildEntity, _marksValidationOutput, errorCallback, isLastValidationSpec),
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
775
|
+
marksAreValid = _validateChildMarks2.valid,
|
|
776
|
+
_entity = _validateChildMarks2.entity;
|
|
915
777
|
var unsupportedMarks = _entity && _entity.marks && _entity.marks.filter(function (mark) {
|
|
916
778
|
return mark.type === 'unsupportedMark';
|
|
917
779
|
}) || [];
|
|
918
|
-
|
|
919
780
|
if (marksAreValid && !unsupportedMarks.length) {
|
|
920
781
|
return _entity;
|
|
921
782
|
} else {
|
|
@@ -928,7 +789,6 @@ export function validator(nodes, marks, options) {
|
|
|
928
789
|
firstError = firstError || error;
|
|
929
790
|
}
|
|
930
791
|
}
|
|
931
|
-
|
|
932
792
|
if (!errorCallback) {
|
|
933
793
|
throw firstError;
|
|
934
794
|
} else {
|
|
@@ -938,7 +798,6 @@ export function validator(nodes, marks, options) {
|
|
|
938
798
|
return invalidChildContent(child, errorCallback, validatorSpec);
|
|
939
799
|
}
|
|
940
800
|
};
|
|
941
|
-
|
|
942
801
|
newEntity.content = prevEntity.content.map(validateChildNode).filter(Boolean);
|
|
943
802
|
} else if (!contentValidatorSpec.optional) {
|
|
944
803
|
return {
|
|
@@ -946,16 +805,15 @@ export function validator(nodes, marks, options) {
|
|
|
946
805
|
result: err('MISSING_PROPERTIES', 'missing `content` prop')
|
|
947
806
|
};
|
|
948
807
|
}
|
|
949
|
-
}
|
|
950
|
-
|
|
808
|
+
}
|
|
951
809
|
|
|
810
|
+
// Marks
|
|
952
811
|
if (prevEntity.marks) {
|
|
953
812
|
return {
|
|
954
813
|
hasValidated: true,
|
|
955
814
|
result: marksValidationFor(validatorSpec, prevEntity, errorCallback, newEntity, err)
|
|
956
815
|
};
|
|
957
816
|
}
|
|
958
|
-
|
|
959
817
|
return specBasedValidationResult;
|
|
960
818
|
}
|
|
961
819
|
}
|