@atlaskit/editor-json-transformer 8.24.4 → 8.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/afm-cc/tsconfig.json +22 -22
- package/afm-townsquare/tsconfig.json +24 -0
- package/dist/cjs/index.js +6 -10
- package/dist/cjs/sanitize/sanitize-node.js +5 -2
- package/dist/es2019/index.js +6 -11
- package/dist/es2019/sanitize/sanitize-node.js +6 -3
- package/dist/esm/index.js +6 -10
- package/dist/esm/sanitize/sanitize-node.js +5 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/sanitize/sanitize-node.d.ts +8 -1
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/sanitize/sanitize-node.d.ts +8 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-json-transformer
|
|
2
2
|
|
|
3
|
+
## 8.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#193192](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193192)
|
|
8
|
+
[`8e0b7ecbc293f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8e0b7ecbc293f) -
|
|
9
|
+
[ux] EDITOR-1186 - keep nested table in adf
|
|
10
|
+
|
|
11
|
+
## 8.24.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#191913](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/191913)
|
|
16
|
+
[`6d1e56695e91d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6d1e56695e91d) -
|
|
17
|
+
EDITOR-1131 Bump adf-schema package to 50.0.0
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 8.24.4
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/afm-cc/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
|
-
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.confluence.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"composite": true,
|
|
7
|
+
"outDir": "../../../../../confluence/tsDist/@atlaskit__editor-json-transformer",
|
|
8
|
+
"rootDir": "../"
|
|
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-cc/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
24
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.townsquare.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"outDir": "../../../../../townsquare/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-townsquare/tsconfig.json"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,9 @@ var isType = function isType(type) {
|
|
|
31
31
|
return node.type.name === type;
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
// Create a Set of node types that should have empty attrs removed
|
|
36
|
+
var NODES_WITH_EMPTY_ATTRS_REMOVAL = new Set(['paragraph', 'layoutSection', 'blockquote', 'nestedExpand', 'bulletList', 'listItem', 'orderedList', 'rule', 'caption', 'tableRow', 'media', 'mediaSingle', 'mediaInline']);
|
|
34
37
|
var isCodeBlock = isType('codeBlock');
|
|
35
38
|
var isMediaNode = isType('media');
|
|
36
39
|
var isMediaInline = isType('mediaInline');
|
|
@@ -123,15 +126,7 @@ var _toJSON = function toJSON(node, mentionMap) {
|
|
|
123
126
|
text: !!text ? text : name
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
|
-
|
|
127
|
-
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
128
|
-
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
129
|
-
delete obj.attrs;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Hard break has optional attr.text which was added for PM <-> ADF compatibility.
|
|
133
|
-
// No need to preserve it.
|
|
134
|
-
if (isHardBreak(node)) {
|
|
129
|
+
if (NODES_WITH_EMPTY_ATTRS_REMOVAL.has(node.type.name) && obj.attrs && !Object.keys(obj.attrs).length || isHardBreak(node)) {
|
|
135
130
|
delete obj.attrs;
|
|
136
131
|
}
|
|
137
132
|
if (node.isText) {
|
|
@@ -222,9 +217,10 @@ var JSONTransformer = exports.JSONTransformer = /*#__PURE__*/function () {
|
|
|
222
217
|
key: "encode",
|
|
223
218
|
value: function encode(node) {
|
|
224
219
|
var _this = this;
|
|
220
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
225
221
|
var content = [];
|
|
226
222
|
node.content.forEach(function (child) {
|
|
227
|
-
content.push((0, _sanitizeNode.sanitizeNode)(_toJSON(child, _this.mentionMap)));
|
|
223
|
+
content.push((0, _sanitizeNode.sanitizeNode)(_toJSON(child, _this.mentionMap), options));
|
|
228
224
|
});
|
|
229
225
|
if (!content || (0, _isEqual.default)(content, emptyDoc.content)) {
|
|
230
226
|
return createDocFromContent([]);
|
|
@@ -18,6 +18,9 @@ var hasNestedTable = function hasNestedTable(tableCellNode) {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
function sanitizeNode(json) {
|
|
21
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
var _options$keepNestedTa = options.keepNestedTables,
|
|
23
|
+
keepNestedTables = _options$keepNestedTa === void 0 ? false : _options$keepNestedTa;
|
|
21
24
|
var sanitizedJSON = (0, _traverse.traverse)(json, {
|
|
22
25
|
text: function text(node) {
|
|
23
26
|
if (!node || !Array.isArray(node.marks)) {
|
|
@@ -43,12 +46,12 @@ function sanitizeNode(json) {
|
|
|
43
46
|
},
|
|
44
47
|
tableCell: function tableCell(node) {
|
|
45
48
|
if (hasNestedTable(node)) {
|
|
46
|
-
return (0, _transforms.transformNestedTableNodeOutgoingDocument)(node);
|
|
49
|
+
return keepNestedTables ? node : (0, _transforms.transformNestedTableNodeOutgoingDocument)(node);
|
|
47
50
|
}
|
|
48
51
|
},
|
|
49
52
|
tableHeader: function tableHeader(node) {
|
|
50
53
|
if (hasNestedTable(node)) {
|
|
51
|
-
return (0, _transforms.transformNestedTableNodeOutgoingDocument)(node);
|
|
54
|
+
return keepNestedTables ? node : (0, _transforms.transformNestedTableNodeOutgoingDocument)(node);
|
|
52
55
|
}
|
|
53
56
|
},
|
|
54
57
|
emoji: _removeMarks.removeNonAnnotationMarks,
|
package/dist/es2019/index.js
CHANGED
|
@@ -12,6 +12,9 @@ export let SchemaStage = /*#__PURE__*/function (SchemaStage) {
|
|
|
12
12
|
return SchemaStage;
|
|
13
13
|
}({});
|
|
14
14
|
const isType = type => node => node.type.name === type;
|
|
15
|
+
|
|
16
|
+
// Create a Set of node types that should have empty attrs removed
|
|
17
|
+
const NODES_WITH_EMPTY_ATTRS_REMOVAL = new Set(['paragraph', 'layoutSection', 'blockquote', 'nestedExpand', 'bulletList', 'listItem', 'orderedList', 'rule', 'caption', 'tableRow', 'media', 'mediaSingle', 'mediaInline']);
|
|
15
18
|
const isCodeBlock = isType('codeBlock');
|
|
16
19
|
const isMediaNode = isType('media');
|
|
17
20
|
const isMediaInline = isType('mediaInline');
|
|
@@ -106,15 +109,7 @@ const toJSON = (node, mentionMap) => {
|
|
|
106
109
|
text: !!text ? text : name
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
|
-
|
|
110
|
-
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
111
|
-
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
112
|
-
delete obj.attrs;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Hard break has optional attr.text which was added for PM <-> ADF compatibility.
|
|
116
|
-
// No need to preserve it.
|
|
117
|
-
if (isHardBreak(node)) {
|
|
112
|
+
if (NODES_WITH_EMPTY_ATTRS_REMOVAL.has(node.type.name) && obj.attrs && !Object.keys(obj.attrs).length || isHardBreak(node)) {
|
|
118
113
|
delete obj.attrs;
|
|
119
114
|
}
|
|
120
115
|
if (node.isText) {
|
|
@@ -202,10 +197,10 @@ export class JSONTransformer {
|
|
|
202
197
|
this.schema = schema;
|
|
203
198
|
this.mentionMap = mentionMap;
|
|
204
199
|
}
|
|
205
|
-
encode(node) {
|
|
200
|
+
encode(node, options = {}) {
|
|
206
201
|
const content = [];
|
|
207
202
|
node.content.forEach(child => {
|
|
208
|
-
content.push(sanitizeNode(toJSON(child, this.mentionMap)));
|
|
203
|
+
content.push(sanitizeNode(toJSON(child, this.mentionMap), options));
|
|
209
204
|
});
|
|
210
205
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
211
206
|
return createDocFromContent([]);
|
|
@@ -5,7 +5,10 @@ const hasNestedTable = tableCellNode => {
|
|
|
5
5
|
var _tableCellNode$conten;
|
|
6
6
|
return (_tableCellNode$conten = tableCellNode.content) === null || _tableCellNode$conten === void 0 ? void 0 : _tableCellNode$conten.some(node => (node === null || node === void 0 ? void 0 : node.type) === 'table');
|
|
7
7
|
};
|
|
8
|
-
export function sanitizeNode(json) {
|
|
8
|
+
export function sanitizeNode(json, options = {}) {
|
|
9
|
+
const {
|
|
10
|
+
keepNestedTables = false
|
|
11
|
+
} = options;
|
|
9
12
|
const sanitizedJSON = traverse(json, {
|
|
10
13
|
text: node => {
|
|
11
14
|
if (!node || !Array.isArray(node.marks)) {
|
|
@@ -30,12 +33,12 @@ export function sanitizeNode(json) {
|
|
|
30
33
|
},
|
|
31
34
|
tableCell: node => {
|
|
32
35
|
if (hasNestedTable(node)) {
|
|
33
|
-
return transformNestedTableNodeOutgoingDocument(node);
|
|
36
|
+
return keepNestedTables ? node : transformNestedTableNodeOutgoingDocument(node);
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
39
|
tableHeader: node => {
|
|
37
40
|
if (hasNestedTable(node)) {
|
|
38
|
-
return transformNestedTableNodeOutgoingDocument(node);
|
|
41
|
+
return keepNestedTables ? node : transformNestedTableNodeOutgoingDocument(node);
|
|
39
42
|
}
|
|
40
43
|
},
|
|
41
44
|
emoji: removeNonAnnotationMarks,
|
package/dist/esm/index.js
CHANGED
|
@@ -25,6 +25,9 @@ var isType = function isType(type) {
|
|
|
25
25
|
return node.type.name === type;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
// Create a Set of node types that should have empty attrs removed
|
|
30
|
+
var NODES_WITH_EMPTY_ATTRS_REMOVAL = new Set(['paragraph', 'layoutSection', 'blockquote', 'nestedExpand', 'bulletList', 'listItem', 'orderedList', 'rule', 'caption', 'tableRow', 'media', 'mediaSingle', 'mediaInline']);
|
|
28
31
|
var isCodeBlock = isType('codeBlock');
|
|
29
32
|
var isMediaNode = isType('media');
|
|
30
33
|
var isMediaInline = isType('mediaInline');
|
|
@@ -117,15 +120,7 @@ var _toJSON = function toJSON(node, mentionMap) {
|
|
|
117
120
|
text: !!text ? text : name
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
|
-
|
|
121
|
-
// Remove the attrs property if it's empty, this is currently limited to paragraph nodes.
|
|
122
|
-
if (isParagraph(node) && obj.attrs && !Object.keys(obj.attrs).length) {
|
|
123
|
-
delete obj.attrs;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Hard break has optional attr.text which was added for PM <-> ADF compatibility.
|
|
127
|
-
// No need to preserve it.
|
|
128
|
-
if (isHardBreak(node)) {
|
|
123
|
+
if (NODES_WITH_EMPTY_ATTRS_REMOVAL.has(node.type.name) && obj.attrs && !Object.keys(obj.attrs).length || isHardBreak(node)) {
|
|
129
124
|
delete obj.attrs;
|
|
130
125
|
}
|
|
131
126
|
if (node.isText) {
|
|
@@ -216,9 +211,10 @@ export var JSONTransformer = /*#__PURE__*/function () {
|
|
|
216
211
|
key: "encode",
|
|
217
212
|
value: function encode(node) {
|
|
218
213
|
var _this = this;
|
|
214
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
219
215
|
var content = [];
|
|
220
216
|
node.content.forEach(function (child) {
|
|
221
|
-
content.push(sanitizeNode(_toJSON(child, _this.mentionMap)));
|
|
217
|
+
content.push(sanitizeNode(_toJSON(child, _this.mentionMap), options));
|
|
222
218
|
});
|
|
223
219
|
if (!content || isEqual(content, emptyDoc.content)) {
|
|
224
220
|
return createDocFromContent([]);
|
|
@@ -11,6 +11,9 @@ var hasNestedTable = function hasNestedTable(tableCellNode) {
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
export function sanitizeNode(json) {
|
|
14
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
var _options$keepNestedTa = options.keepNestedTables,
|
|
16
|
+
keepNestedTables = _options$keepNestedTa === void 0 ? false : _options$keepNestedTa;
|
|
14
17
|
var sanitizedJSON = traverse(json, {
|
|
15
18
|
text: function text(node) {
|
|
16
19
|
if (!node || !Array.isArray(node.marks)) {
|
|
@@ -36,12 +39,12 @@ export function sanitizeNode(json) {
|
|
|
36
39
|
},
|
|
37
40
|
tableCell: function tableCell(node) {
|
|
38
41
|
if (hasNestedTable(node)) {
|
|
39
|
-
return transformNestedTableNodeOutgoingDocument(node);
|
|
42
|
+
return keepNestedTables ? node : transformNestedTableNodeOutgoingDocument(node);
|
|
40
43
|
}
|
|
41
44
|
},
|
|
42
45
|
tableHeader: function tableHeader(node) {
|
|
43
46
|
if (hasNestedTable(node)) {
|
|
44
|
-
return transformNestedTableNodeOutgoingDocument(node);
|
|
47
|
+
return keepNestedTables ? node : transformNestedTableNodeOutgoingDocument(node);
|
|
45
48
|
}
|
|
46
49
|
},
|
|
47
50
|
emoji: removeNonAnnotationMarks,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { type SanitizeNodeOptions } from './sanitize/sanitize-node';
|
|
2
3
|
import type { JSONDocNode, JSONNode } from './types';
|
|
3
4
|
export type { JSONDocNode, JSONNode } from './types';
|
|
4
5
|
interface Transformer<T> {
|
|
@@ -18,7 +19,7 @@ export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
|
18
19
|
* mention node.attr.text values with mapped names.
|
|
19
20
|
*/
|
|
20
21
|
constructor(schema?: Schema, mentionMap?: Record<string, string | undefined>);
|
|
21
|
-
encode(node: PMNode): JSONDocNode;
|
|
22
|
+
encode(node: PMNode, options?: SanitizeNodeOptions): JSONDocNode;
|
|
22
23
|
private internalParse;
|
|
23
24
|
parse(content: JSONDocNode, stage?: SchemaStage): PMNode;
|
|
24
25
|
/**
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { type JSONNode } from '../types';
|
|
2
|
-
export
|
|
2
|
+
export interface SanitizeNodeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If true, nested tables will not be transformed to a extension.
|
|
5
|
+
* This is useful when you want to keep the nested structure for further processing.
|
|
6
|
+
*/
|
|
7
|
+
keepNestedTables?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function sanitizeNode(json: JSONNode, options?: SanitizeNodeOptions): JSONNode;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { type SanitizeNodeOptions } from './sanitize/sanitize-node';
|
|
2
3
|
import type { JSONDocNode, JSONNode } from './types';
|
|
3
4
|
export type { JSONDocNode, JSONNode } from './types';
|
|
4
5
|
interface Transformer<T> {
|
|
@@ -18,7 +19,7 @@ export declare class JSONTransformer implements Transformer<JSONDocNode> {
|
|
|
18
19
|
* mention node.attr.text values with mapped names.
|
|
19
20
|
*/
|
|
20
21
|
constructor(schema?: Schema, mentionMap?: Record<string, string | undefined>);
|
|
21
|
-
encode(node: PMNode): JSONDocNode;
|
|
22
|
+
encode(node: PMNode, options?: SanitizeNodeOptions): JSONDocNode;
|
|
22
23
|
private internalParse;
|
|
23
24
|
parse(content: JSONDocNode, stage?: SchemaStage): PMNode;
|
|
24
25
|
/**
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { type JSONNode } from '../types';
|
|
2
|
-
export
|
|
2
|
+
export interface SanitizeNodeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If true, nested tables will not be transformed to a extension.
|
|
5
|
+
* This is useful when you want to keep the nested structure for further processing.
|
|
6
|
+
*/
|
|
7
|
+
keepNestedTables?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function sanitizeNode(json: JSONNode, options?: SanitizeNodeOptions): JSONNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-json-transformer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.25.0",
|
|
4
4
|
"description": "JSON transformer",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"./types": "./src/types.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@atlaskit/adf-schema": "^
|
|
38
|
+
"@atlaskit/adf-schema": "^50.0.1",
|
|
39
39
|
"@atlaskit/adf-utils": "^19.20.0",
|
|
40
40
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
41
41
|
"@babel/runtime": "^7.0.0",
|