@atlaskit/editor-json-transformer 8.8.2 → 8.8.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 +15 -0
- package/dist/cjs/index.js +32 -64
- package/dist/cjs/markOverrideRules.js +0 -3
- package/dist/cjs/sanitize/remove-marks.js +0 -6
- package/dist/cjs/sanitize/sanitize-node.js +2 -10
- package/dist/cjs/sanitize.js +0 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +35 -57
- package/dist/es2019/markOverrideRules.js +0 -1
- package/dist/es2019/sanitize/remove-marks.js +2 -1
- package/dist/es2019/sanitize/sanitize-node.js +4 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +30 -54
- package/dist/esm/markOverrideRules.js +0 -1
- package/dist/esm/sanitize/remove-marks.js +0 -4
- package/dist/esm/sanitize/sanitize-node.js +2 -6
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +5 -1
- package/package.json +12 -19
- package/report.api.md +32 -6
- package/dist/types-ts4.0/index.d.ts +0 -16
- package/dist/types-ts4.0/markOverrideRules.d.ts +0 -13
- package/dist/types-ts4.0/sanitize/remove-marks.d.ts +0 -8
- package/dist/types-ts4.0/sanitize/sanitize-node.d.ts +0 -2
- package/dist/types-ts4.0/sanitize.d.ts +0 -2
- package/dist/types-ts4.0/types.d.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-json-transformer
|
|
2
2
|
|
|
3
|
+
## 8.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2e01c9c74b5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2e01c9c74b5) - DUMMY remove before merging to master; dupe adf-schema via adf-utils
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 8.8.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`43cb4da169a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/43cb4da169a) - Refactored filterNull to use a for loop rather than reduce
|
|
15
|
+
- [`3e03d26ca36`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3e03d26ca36) - [ESS-3031] Added the capability to parse ADF documents for the stage-0 schema
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 8.8.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
4
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.JSONTransformer = void 0;
|
|
9
|
-
|
|
8
|
+
exports.SchemaStage = exports.JSONTransformer = void 0;
|
|
10
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
11
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
17
|
-
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
14
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
19
|
-
|
|
20
15
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
21
|
-
|
|
22
16
|
var _schemaDefault = require("@atlaskit/adf-schema/schema-default");
|
|
23
|
-
|
|
24
17
|
var _markOverrideRules = require("./markOverrideRules");
|
|
25
|
-
|
|
26
18
|
var _sanitizeNode = require("./sanitize/sanitize-node");
|
|
27
|
-
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof3(key) === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (_typeof3(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof3(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
28
21
|
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; }
|
|
29
|
-
|
|
30
22
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
-
|
|
23
|
+
var SchemaStage;
|
|
24
|
+
exports.SchemaStage = SchemaStage;
|
|
25
|
+
(function (SchemaStage) {
|
|
26
|
+
SchemaStage["FINAL"] = "final";
|
|
27
|
+
SchemaStage["STAGE_0"] = "stage0";
|
|
28
|
+
})(SchemaStage || (exports.SchemaStage = SchemaStage = {}));
|
|
32
29
|
var isType = function isType(type) {
|
|
33
30
|
return function (node) {
|
|
34
31
|
return node.type.name === type;
|
|
35
32
|
};
|
|
36
33
|
};
|
|
37
|
-
|
|
38
34
|
var isCodeBlock = isType('codeBlock');
|
|
39
35
|
var isMediaNode = isType('media');
|
|
40
36
|
var isMediaInline = isType('mediaInline');
|
|
@@ -50,30 +46,26 @@ var isUnsupportedMark = isType('unsupportedMark');
|
|
|
50
46
|
var isUnsupportedNodeAttributeMark = isType('unsupportedNodeAttribute');
|
|
51
47
|
var isExpand = isType('expand');
|
|
52
48
|
var isNestedExpand = isType('nestedExpand');
|
|
53
|
-
|
|
54
49
|
var isUnsupportedNode = function isUnsupportedNode(node) {
|
|
55
50
|
return isType('unsupportedBlock')(node) || isType('unsupportedInline')(node);
|
|
56
51
|
};
|
|
57
|
-
|
|
58
52
|
var isDataConsumer = isType('dataConsumer');
|
|
59
53
|
var isFragmentMark = isType('fragment');
|
|
60
|
-
|
|
61
54
|
var filterNull = function filterNull(subject) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
var output = _objectSpread({}, subject);
|
|
56
|
+
for (var key in output) {
|
|
57
|
+
var current = output[key];
|
|
65
58
|
if (current === null) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
var _output = output,
|
|
60
|
+
unusedKey = _output[key],
|
|
61
|
+
filteredObj = (0, _objectWithoutProperties2.default)(_output, [key].map(_toPropertyKey));
|
|
62
|
+
output = filteredObj;
|
|
63
|
+
} else if ((0, _typeof2.default)(current) === 'object' && !Array.isArray(current)) {
|
|
64
|
+
output[key] = filterNull(current);
|
|
71
65
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, {});
|
|
66
|
+
}
|
|
67
|
+
return output;
|
|
75
68
|
};
|
|
76
|
-
|
|
77
69
|
var createDocFromContent = function createDocFromContent(content) {
|
|
78
70
|
return {
|
|
79
71
|
version: 1,
|
|
@@ -81,17 +73,14 @@ var createDocFromContent = function createDocFromContent(content) {
|
|
|
81
73
|
content: content || []
|
|
82
74
|
};
|
|
83
75
|
};
|
|
84
|
-
|
|
85
76
|
var emptyDoc = createDocFromContent([{
|
|
86
77
|
type: 'paragraph',
|
|
87
78
|
content: []
|
|
88
79
|
}]);
|
|
89
|
-
|
|
90
80
|
var toJSON = function toJSON(node) {
|
|
91
81
|
var obj = {
|
|
92
82
|
type: node.type.name
|
|
93
83
|
};
|
|
94
|
-
|
|
95
84
|
if (isUnsupportedNode(node)) {
|
|
96
85
|
return node.attrs.originalValue;
|
|
97
86
|
} else if (isMediaNode(node)) {
|
|
@@ -115,11 +104,9 @@ var toJSON = function toJSON(node) {
|
|
|
115
104
|
} else if (node.attrs && Object.keys(node.attrs).length) {
|
|
116
105
|
obj.attrs = node.attrs;
|
|
117
106
|
}
|
|
118
|
-
|
|
119
107
|
if (obj.attrs) {
|
|
120
108
|
obj.attrs = filterNull(obj.attrs);
|
|
121
109
|
}
|
|
122
|
-
|
|
123
110
|
if (node.isText) {
|
|
124
111
|
obj.text = node.textContent;
|
|
125
112
|
} else {
|
|
@@ -128,11 +115,9 @@ var toJSON = function toJSON(node) {
|
|
|
128
115
|
obj.content.push(toJSON(child));
|
|
129
116
|
});
|
|
130
117
|
}
|
|
131
|
-
|
|
132
118
|
if (isParagraph(node) || isHeading(node)) {
|
|
133
119
|
obj.content = obj.content || [];
|
|
134
120
|
}
|
|
135
|
-
|
|
136
121
|
if (node.marks.length) {
|
|
137
122
|
// Run any custom mark serialisers
|
|
138
123
|
var parsedMarks = node.marks.map(function (mark) {
|
|
@@ -144,54 +129,44 @@ var toJSON = function toJSON(node) {
|
|
|
144
129
|
return (0, _adfSchema.linkToJSON)(mark);
|
|
145
130
|
} else if (isDataConsumer(mark)) {
|
|
146
131
|
var _serialised$attrs$sou;
|
|
147
|
-
|
|
148
132
|
var serialised = (0, _adfSchema.dataConsumerToJSON)(mark);
|
|
149
133
|
return !serialised.attrs.sources || ((_serialised$attrs$sou = serialised.attrs.sources) === null || _serialised$attrs$sou === void 0 ? void 0 : _serialised$attrs$sou.length) === 0 ? null : serialised;
|
|
150
134
|
} else if (isFragmentMark(mark)) {
|
|
151
135
|
var fragmentMark = (0, _adfSchema.fragmentToJSON)(mark);
|
|
152
|
-
|
|
153
136
|
if (!fragmentMark.attrs.localId) {
|
|
154
137
|
return null;
|
|
155
138
|
}
|
|
156
|
-
|
|
157
139
|
return fragmentMark;
|
|
158
140
|
} else {
|
|
159
141
|
return mark.toJSON();
|
|
160
142
|
}
|
|
161
143
|
}).filter(function (maybeMark) {
|
|
162
144
|
return maybeMark !== null;
|
|
163
|
-
});
|
|
145
|
+
});
|
|
164
146
|
|
|
147
|
+
// Only set if we have a non-empty array, otherwise explicitly undefine it (as we only run this path if `node.marks.length`)
|
|
165
148
|
obj.marks = (parsedMarks === null || parsedMarks === void 0 ? void 0 : parsedMarks.length) > 0 ? parsedMarks : undefined;
|
|
166
149
|
var nodeAttributeMark = node.marks.find(isUnsupportedNodeAttributeMark);
|
|
167
|
-
|
|
168
150
|
if (nodeAttributeMark && nodeAttributeMark.attrs.type.nodeType === obj.type) {
|
|
169
151
|
obj.attrs = _objectSpread({}, getUnwrappedNodeAttributes(node, nodeAttributeMark, obj));
|
|
170
152
|
}
|
|
171
153
|
}
|
|
172
|
-
|
|
173
154
|
return obj;
|
|
174
155
|
};
|
|
175
|
-
|
|
176
156
|
var canOverrideMark = function canOverrideMark(mark, existingMarks) {
|
|
177
157
|
if (existingMarks.some(function (e) {
|
|
178
158
|
return mark.attrs.originalValue.type === e.type.name;
|
|
179
159
|
})) {
|
|
180
160
|
return (0, _markOverrideRules.markOverrideRuleFor)(mark.attrs.originalValue.type).canOverrideUnsupportedMark();
|
|
181
161
|
}
|
|
182
|
-
|
|
183
162
|
return false;
|
|
184
163
|
};
|
|
185
|
-
|
|
186
164
|
var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark, obj) {
|
|
187
165
|
var nodeAttributes = node.type.spec.attrs;
|
|
188
|
-
|
|
189
166
|
var attributes = _objectSpread(_objectSpread({}, mark.attrs.unsupported), obj.attrs);
|
|
190
|
-
|
|
191
167
|
for (var key in obj.attrs) {
|
|
192
168
|
if (obj.attrs.hasOwnProperty(key)) {
|
|
193
169
|
var attribute = nodeAttributes ? nodeAttributes[key] : null;
|
|
194
|
-
|
|
195
170
|
if (attribute) {
|
|
196
171
|
if (attribute.default === node.attrs[key] && mark.attrs.unsupported[key]) {
|
|
197
172
|
return _objectSpread(_objectSpread({}, attributes), {}, (0, _defineProperty2.default)({}, key, mark.attrs.unsupported[key]));
|
|
@@ -199,15 +174,12 @@ var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark,
|
|
|
199
174
|
}
|
|
200
175
|
}
|
|
201
176
|
}
|
|
202
|
-
|
|
203
177
|
return attributes;
|
|
204
178
|
};
|
|
205
|
-
|
|
206
179
|
var JSONTransformer = /*#__PURE__*/function () {
|
|
207
180
|
function JSONTransformer() {
|
|
208
181
|
(0, _classCallCheck2.default)(this, JSONTransformer);
|
|
209
182
|
}
|
|
210
|
-
|
|
211
183
|
(0, _createClass2.default)(JSONTransformer, [{
|
|
212
184
|
key: "encode",
|
|
213
185
|
value: function encode(node) {
|
|
@@ -215,38 +187,35 @@ var JSONTransformer = /*#__PURE__*/function () {
|
|
|
215
187
|
node.content.forEach(function (child) {
|
|
216
188
|
content.push((0, _sanitizeNode.sanitizeNode)(toJSON(child)));
|
|
217
189
|
});
|
|
218
|
-
|
|
219
190
|
if (!content || (0, _isEqual.default)(content, emptyDoc.content)) {
|
|
220
191
|
return createDocFromContent([]);
|
|
221
192
|
}
|
|
222
|
-
|
|
223
193
|
return createDocFromContent(content);
|
|
224
194
|
}
|
|
225
195
|
}, {
|
|
226
196
|
key: "internalParse",
|
|
227
197
|
value: function internalParse(content) {
|
|
228
|
-
var
|
|
229
|
-
|
|
198
|
+
var stage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SchemaStage.FINAL;
|
|
199
|
+
var schema = (0, _schemaDefault.getSchemaBasedOnStage)(stage);
|
|
200
|
+
var doc = schema.nodeFromJSON(content);
|
|
230
201
|
doc.check();
|
|
231
202
|
return doc;
|
|
232
203
|
}
|
|
233
204
|
}, {
|
|
234
205
|
key: "parse",
|
|
235
|
-
value: function parse(content) {
|
|
206
|
+
value: function parse(content, stage) {
|
|
236
207
|
if (content.type !== 'doc') {
|
|
237
208
|
throw new Error('Expected content format to be ADF');
|
|
238
209
|
}
|
|
239
|
-
|
|
240
210
|
if (!content.content || content.content.length === 0) {
|
|
241
|
-
return this.internalParse(emptyDoc);
|
|
211
|
+
return this.internalParse(emptyDoc, stage);
|
|
242
212
|
}
|
|
243
|
-
|
|
244
|
-
return this.internalParse(content);
|
|
213
|
+
return this.internalParse(content, stage);
|
|
245
214
|
}
|
|
215
|
+
|
|
246
216
|
/**
|
|
247
217
|
* This method is used to encode a single node
|
|
248
218
|
*/
|
|
249
|
-
|
|
250
219
|
}, {
|
|
251
220
|
key: "encodeNode",
|
|
252
221
|
value: function encodeNode(node) {
|
|
@@ -255,5 +224,4 @@ var JSONTransformer = /*#__PURE__*/function () {
|
|
|
255
224
|
}]);
|
|
256
225
|
return JSONTransformer;
|
|
257
226
|
}();
|
|
258
|
-
|
|
259
227
|
exports.JSONTransformer = JSONTransformer;
|
|
@@ -14,7 +14,6 @@ var defaultDoNotAllowOverrideBehaviour = {
|
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
var markOverrideRuleFor = function markOverrideRuleFor(type) {
|
|
19
18
|
switch (type) {
|
|
20
19
|
case 'link':
|
|
@@ -30,10 +29,8 @@ var markOverrideRuleFor = function markOverrideRuleFor(type) {
|
|
|
30
29
|
case 'alignment':
|
|
31
30
|
case 'indentation':
|
|
32
31
|
return defaultAllowOverrideBehaviour;
|
|
33
|
-
|
|
34
32
|
default:
|
|
35
33
|
return defaultDoNotAllowOverrideBehaviour;
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
|
-
|
|
39
36
|
exports.markOverrideRuleFor = markOverrideRuleFor;
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.removeMarks = removeMarks;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
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; }
|
|
13
|
-
|
|
14
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
-
|
|
16
11
|
function removeMarks(node) {
|
|
17
12
|
var newNode = _objectSpread({}, node);
|
|
18
|
-
|
|
19
13
|
delete newNode.marks;
|
|
20
14
|
return newNode;
|
|
21
15
|
}
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.sanitizeNode = sanitizeNode;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _traverse = require("@atlaskit/adf-utils/traverse");
|
|
13
|
-
|
|
14
10
|
var _removeMarks = require("./remove-marks");
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
20
13
|
function sanitizeNode(json) {
|
|
21
14
|
var sanitizedJSON = (0, _traverse.traverse)(json, {
|
|
22
15
|
text: function text(node) {
|
|
23
16
|
if (!node || !Array.isArray(node.marks)) {
|
|
24
17
|
return node;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
return _objectSpread(_objectSpread({}, node), {}, {
|
|
28
20
|
marks: node.marks.filter(function (mark) {
|
|
29
21
|
return mark.type !== 'typeAheadQuery';
|
|
@@ -34,16 +26,16 @@ function sanitizeNode(json) {
|
|
|
34
26
|
if (node.attrs && !!node.attrs.text) {
|
|
35
27
|
return (0, _removeMarks.removeMarks)(node);
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
return false; // empty status
|
|
39
30
|
},
|
|
31
|
+
|
|
40
32
|
caption: function caption(node) {
|
|
41
33
|
if (node.content) {
|
|
42
34
|
return node;
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
return false; // empty caption
|
|
46
37
|
},
|
|
38
|
+
|
|
47
39
|
emoji: _removeMarks.removeMarks,
|
|
48
40
|
mention: _removeMarks.removeMarks,
|
|
49
41
|
date: _removeMarks.removeMarks,
|
package/dist/cjs/sanitize.js
CHANGED
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import isEqual from 'lodash/isEqual';
|
|
2
2
|
import { codeBlockToJSON, dataConsumerToJSON, expandToJSON, fragmentToJSON, linkToJSON, mediaSingleToJSON, mediaToJSON, mentionToJSON, tableToJSON, toJSONTableCell, toJSONTableHeader } from '@atlaskit/adf-schema';
|
|
3
|
-
import {
|
|
3
|
+
import { getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
|
|
4
4
|
import { markOverrideRuleFor } from './markOverrideRules';
|
|
5
5
|
import { sanitizeNode } from './sanitize/sanitize-node';
|
|
6
|
-
|
|
6
|
+
export let SchemaStage;
|
|
7
|
+
(function (SchemaStage) {
|
|
8
|
+
SchemaStage["FINAL"] = "final";
|
|
9
|
+
SchemaStage["STAGE_0"] = "stage0";
|
|
10
|
+
})(SchemaStage || (SchemaStage = {}));
|
|
7
11
|
const isType = type => node => node.type.name === type;
|
|
8
|
-
|
|
9
12
|
const isCodeBlock = isType('codeBlock');
|
|
10
13
|
const isMediaNode = isType('media');
|
|
11
14
|
const isMediaInline = isType('mediaInline');
|
|
@@ -21,30 +24,27 @@ const isUnsupportedMark = isType('unsupportedMark');
|
|
|
21
24
|
const isUnsupportedNodeAttributeMark = isType('unsupportedNodeAttribute');
|
|
22
25
|
const isExpand = isType('expand');
|
|
23
26
|
const isNestedExpand = isType('nestedExpand');
|
|
24
|
-
|
|
25
27
|
const isUnsupportedNode = node => isType('unsupportedBlock')(node) || isType('unsupportedInline')(node);
|
|
26
|
-
|
|
27
28
|
const isDataConsumer = isType('dataConsumer');
|
|
28
29
|
const isFragmentMark = isType('fragment');
|
|
29
|
-
|
|
30
30
|
const filterNull = subject => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
let output = {
|
|
32
|
+
...subject
|
|
33
|
+
};
|
|
34
|
+
for (const key in output) {
|
|
35
|
+
const current = output[key];
|
|
34
36
|
if (current === null) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const {
|
|
38
|
+
[key]: unusedKey,
|
|
39
|
+
...filteredObj
|
|
40
|
+
} = output;
|
|
41
|
+
output = filteredObj;
|
|
42
|
+
} else if (typeof current === 'object' && !Array.isArray(current)) {
|
|
43
|
+
output[key] = filterNull(current);
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
[key]: current
|
|
44
|
-
};
|
|
45
|
-
}, {});
|
|
45
|
+
}
|
|
46
|
+
return output;
|
|
46
47
|
};
|
|
47
|
-
|
|
48
48
|
const createDocFromContent = content => {
|
|
49
49
|
return {
|
|
50
50
|
version: 1,
|
|
@@ -52,17 +52,14 @@ const createDocFromContent = content => {
|
|
|
52
52
|
content: content || []
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
|
-
|
|
56
55
|
const emptyDoc = createDocFromContent([{
|
|
57
56
|
type: 'paragraph',
|
|
58
57
|
content: []
|
|
59
58
|
}]);
|
|
60
|
-
|
|
61
59
|
const toJSON = node => {
|
|
62
60
|
const obj = {
|
|
63
61
|
type: node.type.name
|
|
64
62
|
};
|
|
65
|
-
|
|
66
63
|
if (isUnsupportedNode(node)) {
|
|
67
64
|
return node.attrs.originalValue;
|
|
68
65
|
} else if (isMediaNode(node)) {
|
|
@@ -86,11 +83,9 @@ const toJSON = node => {
|
|
|
86
83
|
} else if (node.attrs && Object.keys(node.attrs).length) {
|
|
87
84
|
obj.attrs = node.attrs;
|
|
88
85
|
}
|
|
89
|
-
|
|
90
86
|
if (obj.attrs) {
|
|
91
87
|
obj.attrs = filterNull(obj.attrs);
|
|
92
88
|
}
|
|
93
|
-
|
|
94
89
|
if (node.isText) {
|
|
95
90
|
obj.text = node.textContent;
|
|
96
91
|
} else {
|
|
@@ -99,11 +94,9 @@ const toJSON = node => {
|
|
|
99
94
|
obj.content.push(toJSON(child));
|
|
100
95
|
});
|
|
101
96
|
}
|
|
102
|
-
|
|
103
97
|
if (isParagraph(node) || isHeading(node)) {
|
|
104
98
|
obj.content = obj.content || [];
|
|
105
99
|
}
|
|
106
|
-
|
|
107
100
|
if (node.marks.length) {
|
|
108
101
|
// Run any custom mark serialisers
|
|
109
102
|
const parsedMarks = node.marks.map(mark => {
|
|
@@ -115,103 +108,88 @@ const toJSON = node => {
|
|
|
115
108
|
return linkToJSON(mark);
|
|
116
109
|
} else if (isDataConsumer(mark)) {
|
|
117
110
|
var _serialised$attrs$sou;
|
|
118
|
-
|
|
119
111
|
const serialised = dataConsumerToJSON(mark);
|
|
120
112
|
return !serialised.attrs.sources || ((_serialised$attrs$sou = serialised.attrs.sources) === null || _serialised$attrs$sou === void 0 ? void 0 : _serialised$attrs$sou.length) === 0 ? null : serialised;
|
|
121
113
|
} else if (isFragmentMark(mark)) {
|
|
122
114
|
const fragmentMark = fragmentToJSON(mark);
|
|
123
|
-
|
|
124
115
|
if (!fragmentMark.attrs.localId) {
|
|
125
116
|
return null;
|
|
126
117
|
}
|
|
127
|
-
|
|
128
118
|
return fragmentMark;
|
|
129
119
|
} else {
|
|
130
120
|
return mark.toJSON();
|
|
131
121
|
}
|
|
132
|
-
}).filter(maybeMark => maybeMark !== null);
|
|
122
|
+
}).filter(maybeMark => maybeMark !== null);
|
|
133
123
|
|
|
124
|
+
// Only set if we have a non-empty array, otherwise explicitly undefine it (as we only run this path if `node.marks.length`)
|
|
134
125
|
obj.marks = (parsedMarks === null || parsedMarks === void 0 ? void 0 : parsedMarks.length) > 0 ? parsedMarks : undefined;
|
|
135
126
|
const nodeAttributeMark = node.marks.find(isUnsupportedNodeAttributeMark);
|
|
136
|
-
|
|
137
127
|
if (nodeAttributeMark && nodeAttributeMark.attrs.type.nodeType === obj.type) {
|
|
138
|
-
obj.attrs = {
|
|
128
|
+
obj.attrs = {
|
|
129
|
+
...getUnwrappedNodeAttributes(node, nodeAttributeMark, obj)
|
|
139
130
|
};
|
|
140
131
|
}
|
|
141
132
|
}
|
|
142
|
-
|
|
143
133
|
return obj;
|
|
144
134
|
};
|
|
145
|
-
|
|
146
135
|
const canOverrideMark = (mark, existingMarks) => {
|
|
147
136
|
if (existingMarks.some(e => mark.attrs.originalValue.type === e.type.name)) {
|
|
148
137
|
return markOverrideRuleFor(mark.attrs.originalValue.type).canOverrideUnsupportedMark();
|
|
149
138
|
}
|
|
150
|
-
|
|
151
139
|
return false;
|
|
152
140
|
};
|
|
153
|
-
|
|
154
141
|
const getUnwrappedNodeAttributes = (node, mark, obj) => {
|
|
155
142
|
const nodeAttributes = node.type.spec.attrs;
|
|
156
|
-
const attributes = {
|
|
143
|
+
const attributes = {
|
|
144
|
+
...mark.attrs.unsupported,
|
|
157
145
|
...obj.attrs
|
|
158
146
|
};
|
|
159
|
-
|
|
160
147
|
for (var key in obj.attrs) {
|
|
161
148
|
if (obj.attrs.hasOwnProperty(key)) {
|
|
162
149
|
const attribute = nodeAttributes ? nodeAttributes[key] : null;
|
|
163
|
-
|
|
164
150
|
if (attribute) {
|
|
165
151
|
if (attribute.default === node.attrs[key] && mark.attrs.unsupported[key]) {
|
|
166
|
-
return {
|
|
152
|
+
return {
|
|
153
|
+
...attributes,
|
|
167
154
|
[key]: mark.attrs.unsupported[key]
|
|
168
155
|
};
|
|
169
156
|
}
|
|
170
157
|
}
|
|
171
158
|
}
|
|
172
159
|
}
|
|
173
|
-
|
|
174
160
|
return attributes;
|
|
175
161
|
};
|
|
176
|
-
|
|
177
162
|
export class JSONTransformer {
|
|
178
163
|
encode(node) {
|
|
179
164
|
const content = [];
|
|
180
165
|
node.content.forEach(child => {
|
|
181
166
|
content.push(sanitizeNode(toJSON(child)));
|
|
182
167
|
});
|
|
183
|
-
|
|
184
168
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
185
169
|
return createDocFromContent([]);
|
|
186
170
|
}
|
|
187
|
-
|
|
188
171
|
return createDocFromContent(content);
|
|
189
172
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const doc =
|
|
173
|
+
internalParse(content, stage = SchemaStage.FINAL) {
|
|
174
|
+
const schema = getSchemaBasedOnStage(stage);
|
|
175
|
+
const doc = schema.nodeFromJSON(content);
|
|
193
176
|
doc.check();
|
|
194
177
|
return doc;
|
|
195
178
|
}
|
|
196
|
-
|
|
197
|
-
parse(content) {
|
|
179
|
+
parse(content, stage) {
|
|
198
180
|
if (content.type !== 'doc') {
|
|
199
181
|
throw new Error('Expected content format to be ADF');
|
|
200
182
|
}
|
|
201
|
-
|
|
202
183
|
if (!content.content || content.content.length === 0) {
|
|
203
|
-
return this.internalParse(emptyDoc);
|
|
184
|
+
return this.internalParse(emptyDoc, stage);
|
|
204
185
|
}
|
|
205
|
-
|
|
206
|
-
return this.internalParse(content);
|
|
186
|
+
return this.internalParse(content, stage);
|
|
207
187
|
}
|
|
188
|
+
|
|
208
189
|
/**
|
|
209
190
|
* This method is used to encode a single node
|
|
210
191
|
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
192
|
encodeNode(node) {
|
|
214
193
|
return sanitizeNode(toJSON(node));
|
|
215
194
|
}
|
|
216
|
-
|
|
217
195
|
}
|
|
@@ -6,8 +6,8 @@ export function sanitizeNode(json) {
|
|
|
6
6
|
if (!node || !Array.isArray(node.marks)) {
|
|
7
7
|
return node;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return {
|
|
10
|
+
...node,
|
|
11
11
|
marks: node.marks.filter(mark => mark.type !== 'typeAheadQuery')
|
|
12
12
|
};
|
|
13
13
|
},
|
|
@@ -15,16 +15,16 @@ export function sanitizeNode(json) {
|
|
|
15
15
|
if (node.attrs && !!node.attrs.text) {
|
|
16
16
|
return removeMarks(node);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
return false; // empty status
|
|
20
19
|
},
|
|
20
|
+
|
|
21
21
|
caption: node => {
|
|
22
22
|
if (node.content) {
|
|
23
23
|
return node;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
25
|
return false; // empty caption
|
|
27
26
|
},
|
|
27
|
+
|
|
28
28
|
emoji: removeMarks,
|
|
29
29
|
mention: removeMarks,
|
|
30
30
|
date: removeMarks,
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
3
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
|
-
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
8
|
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
9
|
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
10
|
import isEqual from 'lodash/isEqual';
|
|
11
11
|
import { codeBlockToJSON, dataConsumerToJSON, expandToJSON, fragmentToJSON, linkToJSON, mediaSingleToJSON, mediaToJSON, mentionToJSON, tableToJSON, toJSONTableCell, toJSONTableHeader } from '@atlaskit/adf-schema';
|
|
12
|
-
import {
|
|
12
|
+
import { getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
|
|
13
13
|
import { markOverrideRuleFor } from './markOverrideRules';
|
|
14
14
|
import { sanitizeNode } from './sanitize/sanitize-node';
|
|
15
|
-
|
|
15
|
+
export var SchemaStage;
|
|
16
|
+
(function (SchemaStage) {
|
|
17
|
+
SchemaStage["FINAL"] = "final";
|
|
18
|
+
SchemaStage["STAGE_0"] = "stage0";
|
|
19
|
+
})(SchemaStage || (SchemaStage = {}));
|
|
16
20
|
var isType = function isType(type) {
|
|
17
21
|
return function (node) {
|
|
18
22
|
return node.type.name === type;
|
|
19
23
|
};
|
|
20
24
|
};
|
|
21
|
-
|
|
22
25
|
var isCodeBlock = isType('codeBlock');
|
|
23
26
|
var isMediaNode = isType('media');
|
|
24
27
|
var isMediaInline = isType('mediaInline');
|
|
@@ -34,30 +37,26 @@ var isUnsupportedMark = isType('unsupportedMark');
|
|
|
34
37
|
var isUnsupportedNodeAttributeMark = isType('unsupportedNodeAttribute');
|
|
35
38
|
var isExpand = isType('expand');
|
|
36
39
|
var isNestedExpand = isType('nestedExpand');
|
|
37
|
-
|
|
38
40
|
var isUnsupportedNode = function isUnsupportedNode(node) {
|
|
39
41
|
return isType('unsupportedBlock')(node) || isType('unsupportedInline')(node);
|
|
40
42
|
};
|
|
41
|
-
|
|
42
43
|
var isDataConsumer = isType('dataConsumer');
|
|
43
44
|
var isFragmentMark = isType('fragment');
|
|
44
|
-
|
|
45
45
|
var filterNull = function filterNull(subject) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
var output = _objectSpread({}, subject);
|
|
47
|
+
for (var key in output) {
|
|
48
|
+
var current = output[key];
|
|
49
49
|
if (current === null) {
|
|
50
|
-
|
|
50
|
+
var _output = output,
|
|
51
|
+
unusedKey = _output[key],
|
|
52
|
+
filteredObj = _objectWithoutProperties(_output, [key].map(_toPropertyKey));
|
|
53
|
+
output = filteredObj;
|
|
54
|
+
} else if (_typeof(current) === 'object' && !Array.isArray(current)) {
|
|
55
|
+
output[key] = filterNull(current);
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
current = filterNull(current);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, current));
|
|
58
|
-
}, {});
|
|
57
|
+
}
|
|
58
|
+
return output;
|
|
59
59
|
};
|
|
60
|
-
|
|
61
60
|
var createDocFromContent = function createDocFromContent(content) {
|
|
62
61
|
return {
|
|
63
62
|
version: 1,
|
|
@@ -65,17 +64,14 @@ var createDocFromContent = function createDocFromContent(content) {
|
|
|
65
64
|
content: content || []
|
|
66
65
|
};
|
|
67
66
|
};
|
|
68
|
-
|
|
69
67
|
var emptyDoc = createDocFromContent([{
|
|
70
68
|
type: 'paragraph',
|
|
71
69
|
content: []
|
|
72
70
|
}]);
|
|
73
|
-
|
|
74
71
|
var toJSON = function toJSON(node) {
|
|
75
72
|
var obj = {
|
|
76
73
|
type: node.type.name
|
|
77
74
|
};
|
|
78
|
-
|
|
79
75
|
if (isUnsupportedNode(node)) {
|
|
80
76
|
return node.attrs.originalValue;
|
|
81
77
|
} else if (isMediaNode(node)) {
|
|
@@ -99,11 +95,9 @@ var toJSON = function toJSON(node) {
|
|
|
99
95
|
} else if (node.attrs && Object.keys(node.attrs).length) {
|
|
100
96
|
obj.attrs = node.attrs;
|
|
101
97
|
}
|
|
102
|
-
|
|
103
98
|
if (obj.attrs) {
|
|
104
99
|
obj.attrs = filterNull(obj.attrs);
|
|
105
100
|
}
|
|
106
|
-
|
|
107
101
|
if (node.isText) {
|
|
108
102
|
obj.text = node.textContent;
|
|
109
103
|
} else {
|
|
@@ -112,11 +106,9 @@ var toJSON = function toJSON(node) {
|
|
|
112
106
|
obj.content.push(toJSON(child));
|
|
113
107
|
});
|
|
114
108
|
}
|
|
115
|
-
|
|
116
109
|
if (isParagraph(node) || isHeading(node)) {
|
|
117
110
|
obj.content = obj.content || [];
|
|
118
111
|
}
|
|
119
|
-
|
|
120
112
|
if (node.marks.length) {
|
|
121
113
|
// Run any custom mark serialisers
|
|
122
114
|
var parsedMarks = node.marks.map(function (mark) {
|
|
@@ -128,54 +120,44 @@ var toJSON = function toJSON(node) {
|
|
|
128
120
|
return linkToJSON(mark);
|
|
129
121
|
} else if (isDataConsumer(mark)) {
|
|
130
122
|
var _serialised$attrs$sou;
|
|
131
|
-
|
|
132
123
|
var serialised = dataConsumerToJSON(mark);
|
|
133
124
|
return !serialised.attrs.sources || ((_serialised$attrs$sou = serialised.attrs.sources) === null || _serialised$attrs$sou === void 0 ? void 0 : _serialised$attrs$sou.length) === 0 ? null : serialised;
|
|
134
125
|
} else if (isFragmentMark(mark)) {
|
|
135
126
|
var fragmentMark = fragmentToJSON(mark);
|
|
136
|
-
|
|
137
127
|
if (!fragmentMark.attrs.localId) {
|
|
138
128
|
return null;
|
|
139
129
|
}
|
|
140
|
-
|
|
141
130
|
return fragmentMark;
|
|
142
131
|
} else {
|
|
143
132
|
return mark.toJSON();
|
|
144
133
|
}
|
|
145
134
|
}).filter(function (maybeMark) {
|
|
146
135
|
return maybeMark !== null;
|
|
147
|
-
});
|
|
136
|
+
});
|
|
148
137
|
|
|
138
|
+
// Only set if we have a non-empty array, otherwise explicitly undefine it (as we only run this path if `node.marks.length`)
|
|
149
139
|
obj.marks = (parsedMarks === null || parsedMarks === void 0 ? void 0 : parsedMarks.length) > 0 ? parsedMarks : undefined;
|
|
150
140
|
var nodeAttributeMark = node.marks.find(isUnsupportedNodeAttributeMark);
|
|
151
|
-
|
|
152
141
|
if (nodeAttributeMark && nodeAttributeMark.attrs.type.nodeType === obj.type) {
|
|
153
142
|
obj.attrs = _objectSpread({}, getUnwrappedNodeAttributes(node, nodeAttributeMark, obj));
|
|
154
143
|
}
|
|
155
144
|
}
|
|
156
|
-
|
|
157
145
|
return obj;
|
|
158
146
|
};
|
|
159
|
-
|
|
160
147
|
var canOverrideMark = function canOverrideMark(mark, existingMarks) {
|
|
161
148
|
if (existingMarks.some(function (e) {
|
|
162
149
|
return mark.attrs.originalValue.type === e.type.name;
|
|
163
150
|
})) {
|
|
164
151
|
return markOverrideRuleFor(mark.attrs.originalValue.type).canOverrideUnsupportedMark();
|
|
165
152
|
}
|
|
166
|
-
|
|
167
153
|
return false;
|
|
168
154
|
};
|
|
169
|
-
|
|
170
155
|
var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark, obj) {
|
|
171
156
|
var nodeAttributes = node.type.spec.attrs;
|
|
172
|
-
|
|
173
157
|
var attributes = _objectSpread(_objectSpread({}, mark.attrs.unsupported), obj.attrs);
|
|
174
|
-
|
|
175
158
|
for (var key in obj.attrs) {
|
|
176
159
|
if (obj.attrs.hasOwnProperty(key)) {
|
|
177
160
|
var attribute = nodeAttributes ? nodeAttributes[key] : null;
|
|
178
|
-
|
|
179
161
|
if (attribute) {
|
|
180
162
|
if (attribute.default === node.attrs[key] && mark.attrs.unsupported[key]) {
|
|
181
163
|
return _objectSpread(_objectSpread({}, attributes), {}, _defineProperty({}, key, mark.attrs.unsupported[key]));
|
|
@@ -183,15 +165,12 @@ var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark,
|
|
|
183
165
|
}
|
|
184
166
|
}
|
|
185
167
|
}
|
|
186
|
-
|
|
187
168
|
return attributes;
|
|
188
169
|
};
|
|
189
|
-
|
|
190
170
|
export var JSONTransformer = /*#__PURE__*/function () {
|
|
191
171
|
function JSONTransformer() {
|
|
192
172
|
_classCallCheck(this, JSONTransformer);
|
|
193
173
|
}
|
|
194
|
-
|
|
195
174
|
_createClass(JSONTransformer, [{
|
|
196
175
|
key: "encode",
|
|
197
176
|
value: function encode(node) {
|
|
@@ -199,43 +178,40 @@ export var JSONTransformer = /*#__PURE__*/function () {
|
|
|
199
178
|
node.content.forEach(function (child) {
|
|
200
179
|
content.push(sanitizeNode(toJSON(child)));
|
|
201
180
|
});
|
|
202
|
-
|
|
203
181
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
204
182
|
return createDocFromContent([]);
|
|
205
183
|
}
|
|
206
|
-
|
|
207
184
|
return createDocFromContent(content);
|
|
208
185
|
}
|
|
209
186
|
}, {
|
|
210
187
|
key: "internalParse",
|
|
211
188
|
value: function internalParse(content) {
|
|
212
|
-
var
|
|
189
|
+
var stage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SchemaStage.FINAL;
|
|
190
|
+
var schema = getSchemaBasedOnStage(stage);
|
|
191
|
+
var doc = schema.nodeFromJSON(content);
|
|
213
192
|
doc.check();
|
|
214
193
|
return doc;
|
|
215
194
|
}
|
|
216
195
|
}, {
|
|
217
196
|
key: "parse",
|
|
218
|
-
value: function parse(content) {
|
|
197
|
+
value: function parse(content, stage) {
|
|
219
198
|
if (content.type !== 'doc') {
|
|
220
199
|
throw new Error('Expected content format to be ADF');
|
|
221
200
|
}
|
|
222
|
-
|
|
223
201
|
if (!content.content || content.content.length === 0) {
|
|
224
|
-
return this.internalParse(emptyDoc);
|
|
202
|
+
return this.internalParse(emptyDoc, stage);
|
|
225
203
|
}
|
|
226
|
-
|
|
227
|
-
return this.internalParse(content);
|
|
204
|
+
return this.internalParse(content, stage);
|
|
228
205
|
}
|
|
206
|
+
|
|
229
207
|
/**
|
|
230
208
|
* This method is used to encode a single node
|
|
231
209
|
*/
|
|
232
|
-
|
|
233
210
|
}, {
|
|
234
211
|
key: "encodeNode",
|
|
235
212
|
value: function encodeNode(node) {
|
|
236
213
|
return sanitizeNode(toJSON(node));
|
|
237
214
|
}
|
|
238
215
|
}]);
|
|
239
|
-
|
|
240
216
|
return JSONTransformer;
|
|
241
217
|
}();
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
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; }
|
|
4
|
-
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
export function removeMarks(node) {
|
|
8
5
|
var newNode = _objectSpread({}, node);
|
|
9
|
-
|
|
10
6
|
delete newNode.marks;
|
|
11
7
|
return newNode;
|
|
12
8
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
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; }
|
|
4
|
-
|
|
5
3
|
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; }
|
|
6
|
-
|
|
7
4
|
import { traverse } from '@atlaskit/adf-utils/traverse';
|
|
8
5
|
import { removeMarks } from './remove-marks';
|
|
9
6
|
export function sanitizeNode(json) {
|
|
@@ -12,7 +9,6 @@ export function sanitizeNode(json) {
|
|
|
12
9
|
if (!node || !Array.isArray(node.marks)) {
|
|
13
10
|
return node;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
return _objectSpread(_objectSpread({}, node), {}, {
|
|
17
13
|
marks: node.marks.filter(function (mark) {
|
|
18
14
|
return mark.type !== 'typeAheadQuery';
|
|
@@ -23,16 +19,16 @@ export function sanitizeNode(json) {
|
|
|
23
19
|
if (node.attrs && !!node.attrs.text) {
|
|
24
20
|
return removeMarks(node);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
return false; // empty status
|
|
28
23
|
},
|
|
24
|
+
|
|
29
25
|
caption: function caption(node) {
|
|
30
26
|
if (node.content) {
|
|
31
27
|
return node;
|
|
32
28
|
}
|
|
33
|
-
|
|
34
29
|
return false; // empty caption
|
|
35
30
|
},
|
|
31
|
+
|
|
36
32
|
emoji: removeMarks,
|
|
37
33
|
mention: removeMarks,
|
|
38
34
|
date: removeMarks,
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -5,10 +5,14 @@ interface Transformer<T> {
|
|
|
5
5
|
encode(node: PMNode): T;
|
|
6
6
|
parse(content: T): PMNode;
|
|
7
7
|
}
|
|
8
|
+
export declare enum SchemaStage {
|
|
9
|
+
FINAL = "final",
|
|
10
|
+
STAGE_0 = "stage0"
|
|
11
|
+
}
|
|
8
12
|
export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
9
13
|
encode(node: PMNode): JSONDocNode;
|
|
10
14
|
private internalParse;
|
|
11
|
-
parse(content: JSONDocNode): PMNode;
|
|
15
|
+
parse(content: JSONDocNode, stage?: SchemaStage): PMNode;
|
|
12
16
|
/**
|
|
13
17
|
* This method is used to encode a single node
|
|
14
18
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-json-transformer",
|
|
3
|
-
"version": "8.8.
|
|
3
|
+
"version": "8.8.4",
|
|
4
4
|
"description": "JSON transformer",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,14 +12,6 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"module:es2019": "dist/es2019/index.js",
|
|
14
14
|
"types": "dist/types/index.d.ts",
|
|
15
|
-
"typesVersions": {
|
|
16
|
-
">=4.0 <4.5": {
|
|
17
|
-
"*": [
|
|
18
|
-
"dist/types-ts4.0/*",
|
|
19
|
-
"dist/types-ts4.0/index.d.ts"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
15
|
"sideEffects": false,
|
|
24
16
|
"atlaskit:src": "src/index.ts",
|
|
25
17
|
"atlassian": {
|
|
@@ -37,29 +29,28 @@
|
|
|
37
29
|
"./types": "./src/types.ts"
|
|
38
30
|
},
|
|
39
31
|
"dependencies": {
|
|
40
|
-
"@atlaskit/adf-schema": "^
|
|
41
|
-
"@atlaskit/adf-utils": "^
|
|
32
|
+
"@atlaskit/adf-schema": "^25.5.0",
|
|
33
|
+
"@atlaskit/adf-utils": "^18.1.0",
|
|
42
34
|
"@babel/runtime": "^7.0.0",
|
|
43
35
|
"lodash": "^4.17.21",
|
|
44
36
|
"prosemirror-model": "1.14.3"
|
|
45
37
|
},
|
|
46
38
|
"devDependencies": {
|
|
47
39
|
"@atlaskit/docs": "*",
|
|
48
|
-
"@atlaskit/editor-bitbucket-transformer": "^
|
|
49
|
-
"@atlaskit/editor-common": "^
|
|
40
|
+
"@atlaskit/editor-bitbucket-transformer": "^8.0.0",
|
|
41
|
+
"@atlaskit/editor-common": "^72.8.0",
|
|
50
42
|
"@atlaskit/editor-confluence-transformer": "^8.1.0",
|
|
51
|
-
"@atlaskit/editor-core": "^
|
|
43
|
+
"@atlaskit/editor-core": "^182.1.0",
|
|
52
44
|
"@atlaskit/editor-jira-transformer": "^8.2.0",
|
|
53
|
-
"@atlaskit/editor-markdown-transformer": "^
|
|
54
|
-
"@atlaskit/editor-test-helpers": "^
|
|
45
|
+
"@atlaskit/editor-markdown-transformer": "^5.0.0",
|
|
46
|
+
"@atlaskit/editor-test-helpers": "^18.2.0",
|
|
55
47
|
"@atlaskit/editor-wikimarkup-transformer": "^11.1.0",
|
|
56
|
-
"@atlaskit/util-data-test": "^17.
|
|
48
|
+
"@atlaskit/util-data-test": "^17.7.0",
|
|
57
49
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
58
50
|
"@emotion/react": "^11.7.1",
|
|
59
51
|
"@types/prosemirror-model": "^1.11.0",
|
|
60
52
|
"prosemirror-view": "1.23.2",
|
|
61
53
|
"react": "^16.8.0",
|
|
62
|
-
"styled-components": "^3.2.6",
|
|
63
54
|
"typescript": "4.5.5"
|
|
64
55
|
},
|
|
65
56
|
"techstack": {
|
|
@@ -68,7 +59,9 @@
|
|
|
68
59
|
},
|
|
69
60
|
"@repo/internal": {
|
|
70
61
|
"deprecation": "no-deprecated-imports",
|
|
71
|
-
"
|
|
62
|
+
"design-tokens": [
|
|
63
|
+
"color"
|
|
64
|
+
],
|
|
72
65
|
"styling": [
|
|
73
66
|
"emotion"
|
|
74
67
|
]
|
package/report.api.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
|
+
|
|
1
3
|
## API Report File for "@atlaskit/editor-json-transformer"
|
|
2
4
|
|
|
3
|
-
> Do not edit this file.
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-->
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
11
|
+
- [Peer Dependencies](#peer-dependencies)
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
### Main Entry Types
|
|
14
|
+
|
|
15
|
+
<!--SECTION START: Main Entry Types-->
|
|
10
16
|
|
|
11
17
|
```ts
|
|
12
18
|
import { Node as Node_2 } from 'prosemirror-model';
|
|
@@ -33,7 +39,15 @@ export class JSONTransformer implements Transformer_2<JSONDocNode> {
|
|
|
33
39
|
encode(node: Node_2): JSONDocNode;
|
|
34
40
|
encodeNode(node: Node_2): JSONNode;
|
|
35
41
|
// (undocumented)
|
|
36
|
-
parse(content: JSONDocNode): Node_2;
|
|
42
|
+
parse(content: JSONDocNode, stage?: SchemaStage): Node_2;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// @public (undocumented)
|
|
46
|
+
export enum SchemaStage {
|
|
47
|
+
// (undocumented)
|
|
48
|
+
FINAL = 'final',
|
|
49
|
+
// (undocumented)
|
|
50
|
+
STAGE_0 = 'stage0',
|
|
37
51
|
}
|
|
38
52
|
|
|
39
53
|
// @public (undocumented)
|
|
@@ -46,3 +60,15 @@ interface Transformer_2<T> {
|
|
|
46
60
|
|
|
47
61
|
// (No @packageDocumentation comment for this package)
|
|
48
62
|
```
|
|
63
|
+
|
|
64
|
+
<!--SECTION END: Main Entry Types-->
|
|
65
|
+
|
|
66
|
+
### Peer Dependencies
|
|
67
|
+
|
|
68
|
+
<!--SECTION START: Peer Dependencies-->
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
<!--SECTION END: Peer Dependencies-->
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Node as PMNode } from 'prosemirror-model';
|
|
2
|
-
import { JSONDocNode, JSONNode } from './types';
|
|
3
|
-
export type { JSONDocNode, JSONNode } from './types';
|
|
4
|
-
interface Transformer<T> {
|
|
5
|
-
encode(node: PMNode): T;
|
|
6
|
-
parse(content: T): PMNode;
|
|
7
|
-
}
|
|
8
|
-
export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
9
|
-
encode(node: PMNode): JSONDocNode;
|
|
10
|
-
private internalParse;
|
|
11
|
-
parse(content: JSONDocNode): PMNode;
|
|
12
|
-
/**
|
|
13
|
-
* This method is used to encode a single node
|
|
14
|
-
*/
|
|
15
|
-
encodeNode(node: PMNode): JSONNode;
|
|
16
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface MarkJson {
|
|
2
|
-
type: string;
|
|
3
|
-
attrs: {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
declare type CanOverrideUnsupportedMark = (markJson?: MarkJson) => boolean;
|
|
8
|
-
interface MarkOverrideRule {
|
|
9
|
-
canOverrideUnsupportedMark: CanOverrideUnsupportedMark;
|
|
10
|
-
}
|
|
11
|
-
declare type MarkOverrideRules = (type: string) => MarkOverrideRule;
|
|
12
|
-
export declare const markOverrideRuleFor: MarkOverrideRules;
|
|
13
|
-
export {};
|