@atlaskit/editor-json-transformer 8.20.3 → 8.20.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 +9 -0
- package/afm-jira/tsconfig.json +23 -23
- package/afm-post-office/tsconfig.json +23 -23
- package/dist/cjs/index.js +22 -4
- package/dist/es2019/index.js +22 -5
- package/dist/esm/index.js +22 -4
- package/dist/types/index.d.ts +7 -1
- package/dist/types-ts4.5/index.d.ts +7 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-json-transformer
|
|
2
2
|
|
|
3
|
+
## 8.20.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`9a4a3df453d84`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9a4a3df453d84) -
|
|
8
|
+
Updated the JSONTransformer to support using an mention mapping. During the encoding of mentions
|
|
9
|
+
the text names can be pulled from the mention map and encoded.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 8.20.3
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/afm-jira/tsconfig.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.jira.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"outDir": "../../../../../tsDist/@atlaskit__editor-json-transformer/app",
|
|
7
|
+
"rootDir": "../",
|
|
8
|
+
"composite": true
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"../src/**/*.ts",
|
|
12
|
+
"../src/**/*.tsx"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"../src/**/__tests__/*",
|
|
16
|
+
"../src/**/*.test.*",
|
|
17
|
+
"../src/**/test.*"
|
|
18
|
+
],
|
|
19
|
+
"references": [
|
|
20
|
+
{
|
|
21
|
+
"path": "../../adf-utils/afm-jira/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.post-office.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"outDir": "../../../../../tsDist/@atlaskit__editor-json-transformer/app",
|
|
7
|
+
"rootDir": "../",
|
|
8
|
+
"composite": true
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"../src/**/*.ts",
|
|
12
|
+
"../src/**/*.tsx"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"../src/**/__tests__/*",
|
|
16
|
+
"../src/**/*.test.*",
|
|
17
|
+
"../src/**/test.*"
|
|
18
|
+
],
|
|
19
|
+
"references": [
|
|
20
|
+
{
|
|
21
|
+
"path": "../../adf-utils/afm-post-office/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -79,7 +79,7 @@ var emptyDoc = createDocFromContent([{
|
|
|
79
79
|
type: 'paragraph',
|
|
80
80
|
content: []
|
|
81
81
|
}]);
|
|
82
|
-
var toJSON = function toJSON(node) {
|
|
82
|
+
var toJSON = function toJSON(node, mentionMap) {
|
|
83
83
|
var obj = {
|
|
84
84
|
type: node.type.name
|
|
85
85
|
};
|
|
@@ -109,6 +109,16 @@ var toJSON = function toJSON(node) {
|
|
|
109
109
|
if (obj.attrs) {
|
|
110
110
|
obj.attrs = filterNull(obj.attrs);
|
|
111
111
|
}
|
|
112
|
+
if (isMentionNode(node) && mentionMap) {
|
|
113
|
+
var _text, _obj$attrs;
|
|
114
|
+
// If the mentionMap exists and has a name defined then we should use it and prepend @ to the begining of it.
|
|
115
|
+
var name = !!(mentionMap !== null && mentionMap !== void 0 && mentionMap[node.attrs.id]) ? "@".concat(mentionMap[node.attrs.id]) : '';
|
|
116
|
+
var text = (_text = (_obj$attrs = obj.attrs) === null || _obj$attrs === void 0 ? void 0 : _obj$attrs.text) !== null && _text !== void 0 ? _text : '';
|
|
117
|
+
obj.attrs = _objectSpread(_objectSpread({}, obj.attrs), {}, {
|
|
118
|
+
// If an explicit text value is set on the mention then that should take priority over the mentionMap value.
|
|
119
|
+
text: !!text ? text : name
|
|
120
|
+
});
|
|
121
|
+
}
|
|
112
122
|
|
|
113
123
|
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
114
124
|
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
@@ -125,7 +135,7 @@ var toJSON = function toJSON(node) {
|
|
|
125
135
|
} else {
|
|
126
136
|
node.content.forEach(function (child) {
|
|
127
137
|
obj.content = obj.content || [];
|
|
128
|
-
obj.content.push(toJSON(child));
|
|
138
|
+
obj.content.push(toJSON(child, mentionMap));
|
|
129
139
|
});
|
|
130
140
|
}
|
|
131
141
|
if (isParagraph(node) || isHeading(node)) {
|
|
@@ -190,17 +200,25 @@ var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark,
|
|
|
190
200
|
return attributes;
|
|
191
201
|
};
|
|
192
202
|
var JSONTransformer = exports.JSONTransformer = /*#__PURE__*/function () {
|
|
203
|
+
/**
|
|
204
|
+
* @param schema The current editor schema
|
|
205
|
+
* @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
|
|
206
|
+
* mention node.attr.text values with mapped names.
|
|
207
|
+
*/
|
|
193
208
|
function JSONTransformer() {
|
|
194
209
|
var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _schemaDefault.defaultSchema;
|
|
210
|
+
var mentionMap = arguments.length > 1 ? arguments[1] : undefined;
|
|
195
211
|
(0, _classCallCheck2.default)(this, JSONTransformer);
|
|
196
212
|
this.schema = schema;
|
|
213
|
+
this.mentionMap = mentionMap;
|
|
197
214
|
}
|
|
198
215
|
(0, _createClass2.default)(JSONTransformer, [{
|
|
199
216
|
key: "encode",
|
|
200
217
|
value: function encode(node) {
|
|
218
|
+
var _this = this;
|
|
201
219
|
var content = [];
|
|
202
220
|
node.content.forEach(function (child) {
|
|
203
|
-
content.push((0, _sanitizeNode.sanitizeNode)(toJSON(child)));
|
|
221
|
+
content.push((0, _sanitizeNode.sanitizeNode)(toJSON(child, _this.mentionMap)));
|
|
204
222
|
});
|
|
205
223
|
if (!content || (0, _isEqual.default)(content, emptyDoc.content)) {
|
|
206
224
|
return createDocFromContent([]);
|
|
@@ -233,7 +251,7 @@ var JSONTransformer = exports.JSONTransformer = /*#__PURE__*/function () {
|
|
|
233
251
|
}, {
|
|
234
252
|
key: "encodeNode",
|
|
235
253
|
value: function encodeNode(node) {
|
|
236
|
-
return (0, _sanitizeNode.sanitizeNode)(toJSON(node));
|
|
254
|
+
return (0, _sanitizeNode.sanitizeNode)(toJSON(node, this.mentionMap));
|
|
237
255
|
}
|
|
238
256
|
}]);
|
|
239
257
|
return JSONTransformer;
|
package/dist/es2019/index.js
CHANGED
|
@@ -59,7 +59,7 @@ const emptyDoc = createDocFromContent([{
|
|
|
59
59
|
type: 'paragraph',
|
|
60
60
|
content: []
|
|
61
61
|
}]);
|
|
62
|
-
const toJSON = node => {
|
|
62
|
+
const toJSON = (node, mentionMap) => {
|
|
63
63
|
const obj = {
|
|
64
64
|
type: node.type.name
|
|
65
65
|
};
|
|
@@ -89,6 +89,17 @@ const toJSON = node => {
|
|
|
89
89
|
if (obj.attrs) {
|
|
90
90
|
obj.attrs = filterNull(obj.attrs);
|
|
91
91
|
}
|
|
92
|
+
if (isMentionNode(node) && mentionMap) {
|
|
93
|
+
var _text, _obj$attrs;
|
|
94
|
+
// If the mentionMap exists and has a name defined then we should use it and prepend @ to the begining of it.
|
|
95
|
+
const name = !!(mentionMap !== null && mentionMap !== void 0 && mentionMap[node.attrs.id]) ? `@${mentionMap[node.attrs.id]}` : '';
|
|
96
|
+
const text = (_text = (_obj$attrs = obj.attrs) === null || _obj$attrs === void 0 ? void 0 : _obj$attrs.text) !== null && _text !== void 0 ? _text : '';
|
|
97
|
+
obj.attrs = {
|
|
98
|
+
...obj.attrs,
|
|
99
|
+
// If an explicit text value is set on the mention then that should take priority over the mentionMap value.
|
|
100
|
+
text: !!text ? text : name
|
|
101
|
+
};
|
|
102
|
+
}
|
|
92
103
|
|
|
93
104
|
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
94
105
|
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
@@ -105,7 +116,7 @@ const toJSON = node => {
|
|
|
105
116
|
} else {
|
|
106
117
|
node.content.forEach(child => {
|
|
107
118
|
obj.content = obj.content || [];
|
|
108
|
-
obj.content.push(toJSON(child));
|
|
119
|
+
obj.content.push(toJSON(child, mentionMap));
|
|
109
120
|
});
|
|
110
121
|
}
|
|
111
122
|
if (isParagraph(node) || isHeading(node)) {
|
|
@@ -174,13 +185,19 @@ const getUnwrappedNodeAttributes = (node, mark, obj) => {
|
|
|
174
185
|
return attributes;
|
|
175
186
|
};
|
|
176
187
|
export class JSONTransformer {
|
|
177
|
-
|
|
188
|
+
/**
|
|
189
|
+
* @param schema The current editor schema
|
|
190
|
+
* @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
|
|
191
|
+
* mention node.attr.text values with mapped names.
|
|
192
|
+
*/
|
|
193
|
+
constructor(schema = defaultSchema, mentionMap) {
|
|
178
194
|
this.schema = schema;
|
|
195
|
+
this.mentionMap = mentionMap;
|
|
179
196
|
}
|
|
180
197
|
encode(node) {
|
|
181
198
|
const content = [];
|
|
182
199
|
node.content.forEach(child => {
|
|
183
|
-
content.push(sanitizeNode(toJSON(child)));
|
|
200
|
+
content.push(sanitizeNode(toJSON(child, this.mentionMap)));
|
|
184
201
|
});
|
|
185
202
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
186
203
|
return createDocFromContent([]);
|
|
@@ -207,6 +224,6 @@ export class JSONTransformer {
|
|
|
207
224
|
* This method is used to encode a single node
|
|
208
225
|
*/
|
|
209
226
|
encodeNode(node) {
|
|
210
|
-
return sanitizeNode(toJSON(node));
|
|
227
|
+
return sanitizeNode(toJSON(node, this.mentionMap));
|
|
211
228
|
}
|
|
212
229
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -71,7 +71,7 @@ var emptyDoc = createDocFromContent([{
|
|
|
71
71
|
type: 'paragraph',
|
|
72
72
|
content: []
|
|
73
73
|
}]);
|
|
74
|
-
var toJSON = function toJSON(node) {
|
|
74
|
+
var toJSON = function toJSON(node, mentionMap) {
|
|
75
75
|
var obj = {
|
|
76
76
|
type: node.type.name
|
|
77
77
|
};
|
|
@@ -101,6 +101,16 @@ var toJSON = function toJSON(node) {
|
|
|
101
101
|
if (obj.attrs) {
|
|
102
102
|
obj.attrs = filterNull(obj.attrs);
|
|
103
103
|
}
|
|
104
|
+
if (isMentionNode(node) && mentionMap) {
|
|
105
|
+
var _text, _obj$attrs;
|
|
106
|
+
// If the mentionMap exists and has a name defined then we should use it and prepend @ to the begining of it.
|
|
107
|
+
var name = !!(mentionMap !== null && mentionMap !== void 0 && mentionMap[node.attrs.id]) ? "@".concat(mentionMap[node.attrs.id]) : '';
|
|
108
|
+
var text = (_text = (_obj$attrs = obj.attrs) === null || _obj$attrs === void 0 ? void 0 : _obj$attrs.text) !== null && _text !== void 0 ? _text : '';
|
|
109
|
+
obj.attrs = _objectSpread(_objectSpread({}, obj.attrs), {}, {
|
|
110
|
+
// If an explicit text value is set on the mention then that should take priority over the mentionMap value.
|
|
111
|
+
text: !!text ? text : name
|
|
112
|
+
});
|
|
113
|
+
}
|
|
104
114
|
|
|
105
115
|
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
106
116
|
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
@@ -117,7 +127,7 @@ var toJSON = function toJSON(node) {
|
|
|
117
127
|
} else {
|
|
118
128
|
node.content.forEach(function (child) {
|
|
119
129
|
obj.content = obj.content || [];
|
|
120
|
-
obj.content.push(toJSON(child));
|
|
130
|
+
obj.content.push(toJSON(child, mentionMap));
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
if (isParagraph(node) || isHeading(node)) {
|
|
@@ -182,17 +192,25 @@ var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark,
|
|
|
182
192
|
return attributes;
|
|
183
193
|
};
|
|
184
194
|
export var JSONTransformer = /*#__PURE__*/function () {
|
|
195
|
+
/**
|
|
196
|
+
* @param schema The current editor schema
|
|
197
|
+
* @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
|
|
198
|
+
* mention node.attr.text values with mapped names.
|
|
199
|
+
*/
|
|
185
200
|
function JSONTransformer() {
|
|
186
201
|
var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultSchema;
|
|
202
|
+
var mentionMap = arguments.length > 1 ? arguments[1] : undefined;
|
|
187
203
|
_classCallCheck(this, JSONTransformer);
|
|
188
204
|
this.schema = schema;
|
|
205
|
+
this.mentionMap = mentionMap;
|
|
189
206
|
}
|
|
190
207
|
_createClass(JSONTransformer, [{
|
|
191
208
|
key: "encode",
|
|
192
209
|
value: function encode(node) {
|
|
210
|
+
var _this = this;
|
|
193
211
|
var content = [];
|
|
194
212
|
node.content.forEach(function (child) {
|
|
195
|
-
content.push(sanitizeNode(toJSON(child)));
|
|
213
|
+
content.push(sanitizeNode(toJSON(child, _this.mentionMap)));
|
|
196
214
|
});
|
|
197
215
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
198
216
|
return createDocFromContent([]);
|
|
@@ -225,7 +243,7 @@ export var JSONTransformer = /*#__PURE__*/function () {
|
|
|
225
243
|
}, {
|
|
226
244
|
key: "encodeNode",
|
|
227
245
|
value: function encodeNode(node) {
|
|
228
|
-
return sanitizeNode(toJSON(node));
|
|
246
|
+
return sanitizeNode(toJSON(node, this.mentionMap));
|
|
229
247
|
}
|
|
230
248
|
}]);
|
|
231
249
|
return JSONTransformer;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,7 +11,13 @@ export declare enum SchemaStage {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
13
13
|
private schema;
|
|
14
|
-
|
|
14
|
+
private mentionMap;
|
|
15
|
+
/**
|
|
16
|
+
* @param schema The current editor schema
|
|
17
|
+
* @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
|
|
18
|
+
* mention node.attr.text values with mapped names.
|
|
19
|
+
*/
|
|
20
|
+
constructor(schema?: Schema, mentionMap?: Record<string, string | undefined>);
|
|
15
21
|
encode(node: PMNode): JSONDocNode;
|
|
16
22
|
private internalParse;
|
|
17
23
|
parse(content: JSONDocNode, stage?: SchemaStage): PMNode;
|
|
@@ -11,7 +11,13 @@ export declare enum SchemaStage {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
13
13
|
private schema;
|
|
14
|
-
|
|
14
|
+
private mentionMap;
|
|
15
|
+
/**
|
|
16
|
+
* @param schema The current editor schema
|
|
17
|
+
* @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
|
|
18
|
+
* mention node.attr.text values with mapped names.
|
|
19
|
+
*/
|
|
20
|
+
constructor(schema?: Schema, mentionMap?: Record<string, string | undefined>);
|
|
15
21
|
encode(node: PMNode): JSONDocNode;
|
|
16
22
|
private internalParse;
|
|
17
23
|
parse(content: JSONDocNode, stage?: SchemaStage): PMNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-json-transformer",
|
|
3
|
-
"version": "8.20.
|
|
3
|
+
"version": "8.20.4",
|
|
4
4
|
"description": "JSON transformer",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@atlaskit/adf-schema": "^44.2.0",
|
|
40
|
-
"@atlaskit/adf-utils": "^19.
|
|
40
|
+
"@atlaskit/adf-utils": "^19.11.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "6.0.0",
|
|
42
42
|
"@babel/runtime": "^7.0.0",
|
|
43
43
|
"lodash": "^4.17.21"
|