@atlaskit/editor-json-transformer 9.3.0 → 9.5.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # @atlaskit/editor-json-transformer
2
2
 
3
+ ## 9.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`52e80c8d44e5f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/52e80c8d44e5f) -
8
+ Behind `platform_editor_sanitize_selection_fragments`, `getFragmentsFromSelection` now sanitises
9
+ selection fragments via `JSONTransformer.encodeNode` instead of the raw `nodeToJSON`, so the
10
+ schema-only `panel_c1` container variant no longer leaks to Remix and other AI selection-context
11
+ consumers when `platform_editor_nest_table_in_panel` is enabled. `keepNestedTables: true` is
12
+ passed to keep nested tables intact. `encodeNode` and editor-common's `nodeToJSON` now accept
13
+ `SanitizeNodeOptions`, matching `encode`.
14
+
15
+ ## 9.4.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [`710e3d9ec4c65`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/710e3d9ec4c65) -
20
+ Add `upgradeContainerNodes` to `@atlaskit/adf-utils/transforms` — a schema-driven, flag-free
21
+ transform that promotes `panel` nodes to their table-allowing `panel_c1` variant wherever the
22
+ schema allows it (document root, layout column, synced block), regardless of the panel's content.
23
+
24
+ `JSONTransformer.parse` now applies it so table-in-panel deserialises consistently for all
25
+ `JSONTransformer` consumers. It is a no-op for schemas that do not declare `panel_c1`, and it is
26
+ best-effort (malformed input still surfaces the canonical `nodeFromJSON` validation error).
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies
31
+
3
32
  ## 9.3.0
4
33
 
5
34
  ### Minor Changes
@@ -9,6 +9,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
11
  var _schemaDefault = require("@atlaskit/adf-schema/schema-default");
12
+ var _transforms = require("@atlaskit/adf-utils/transforms");
12
13
  var _sanitizeNode = require("./sanitize/sanitize-node");
13
14
  var _toJSON = require("./toJSON");
14
15
  var createDocFromContent = function createDocFromContent(content) {
@@ -53,7 +54,21 @@ var JSONTransformer = exports.JSONTransformer = /*#__PURE__*/function () {
53
54
  }, {
54
55
  key: "internalParse",
55
56
  value: function internalParse(content, schema) {
56
- var doc = schema.nodeFromJSON(content);
57
+ // Upgrade container nodes (e.g. `panel` -> `panel_c1`) wherever the schema allows it, so
58
+ // table-in-panel deserialises consistently for JSONTransformer consumers. Schema-driven and
59
+ // flag-free, and best-effort: malformed input falls through to `nodeFromJSON`, which stays
60
+ // the source of truth for validation errors.
61
+ var promoted = content;
62
+ try {
63
+ var _upgradeContainerNode = (0, _transforms.upgradeContainerNodes)(content, schema),
64
+ transformedAdf = _upgradeContainerNode.transformedAdf;
65
+ if (transformedAdf) {
66
+ promoted = transformedAdf;
67
+ }
68
+ } catch (_unused) {
69
+ // Malformed input — leave `promoted` as the original `content`.
70
+ }
71
+ var doc = schema.nodeFromJSON(promoted);
57
72
  doc.check();
58
73
  return doc;
59
74
  }
@@ -76,7 +91,8 @@ var JSONTransformer = exports.JSONTransformer = /*#__PURE__*/function () {
76
91
  }, {
77
92
  key: "encodeNode",
78
93
  value: function encodeNode(node) {
79
- return (0, _sanitizeNode.sanitizeNode)((0, _toJSON.toJSON)(node, this.mentionMap));
94
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
95
+ return (0, _sanitizeNode.sanitizeNode)((0, _toJSON.toJSON)(node, this.mentionMap), options);
80
96
  }
81
97
  }]);
82
98
  }();
@@ -1,5 +1,6 @@
1
1
  import isEqual from 'lodash/isEqual';
2
2
  import { defaultSchema, getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
3
+ import { upgradeContainerNodes } from '@atlaskit/adf-utils/transforms';
3
4
  import { sanitizeNode } from './sanitize/sanitize-node';
4
5
  import { toJSON } from './toJSON';
5
6
  const createDocFromContent = content => {
@@ -35,7 +36,22 @@ export class JSONTransformer {
35
36
  return createDocFromContent(content);
36
37
  }
37
38
  internalParse(content, schema) {
38
- const doc = schema.nodeFromJSON(content);
39
+ // Upgrade container nodes (e.g. `panel` -> `panel_c1`) wherever the schema allows it, so
40
+ // table-in-panel deserialises consistently for JSONTransformer consumers. Schema-driven and
41
+ // flag-free, and best-effort: malformed input falls through to `nodeFromJSON`, which stays
42
+ // the source of truth for validation errors.
43
+ let promoted = content;
44
+ try {
45
+ const {
46
+ transformedAdf
47
+ } = upgradeContainerNodes(content, schema);
48
+ if (transformedAdf) {
49
+ promoted = transformedAdf;
50
+ }
51
+ } catch {
52
+ // Malformed input — leave `promoted` as the original `content`.
53
+ }
54
+ const doc = schema.nodeFromJSON(promoted);
39
55
  doc.check();
40
56
  return doc;
41
57
  }
@@ -53,7 +69,7 @@ export class JSONTransformer {
53
69
  /**
54
70
  * This method is used to encode a single node
55
71
  */
56
- encodeNode(node) {
57
- return sanitizeNode(toJSON(node, this.mentionMap));
72
+ encodeNode(node, options = {}) {
73
+ return sanitizeNode(toJSON(node, this.mentionMap), options);
58
74
  }
59
75
  }
@@ -2,6 +2,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import isEqual from 'lodash/isEqual';
4
4
  import { defaultSchema, getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
5
+ import { upgradeContainerNodes } from '@atlaskit/adf-utils/transforms';
5
6
  import { sanitizeNode } from './sanitize/sanitize-node';
6
7
  import { toJSON } from './toJSON';
7
8
  var createDocFromContent = function createDocFromContent(content) {
@@ -46,7 +47,21 @@ export var JSONTransformer = /*#__PURE__*/function () {
46
47
  }, {
47
48
  key: "internalParse",
48
49
  value: function internalParse(content, schema) {
49
- var doc = schema.nodeFromJSON(content);
50
+ // Upgrade container nodes (e.g. `panel` -> `panel_c1`) wherever the schema allows it, so
51
+ // table-in-panel deserialises consistently for JSONTransformer consumers. Schema-driven and
52
+ // flag-free, and best-effort: malformed input falls through to `nodeFromJSON`, which stays
53
+ // the source of truth for validation errors.
54
+ var promoted = content;
55
+ try {
56
+ var _upgradeContainerNode = upgradeContainerNodes(content, schema),
57
+ transformedAdf = _upgradeContainerNode.transformedAdf;
58
+ if (transformedAdf) {
59
+ promoted = transformedAdf;
60
+ }
61
+ } catch (_unused) {
62
+ // Malformed input — leave `promoted` as the original `content`.
63
+ }
64
+ var doc = schema.nodeFromJSON(promoted);
50
65
  doc.check();
51
66
  return doc;
52
67
  }
@@ -69,7 +84,8 @@ export var JSONTransformer = /*#__PURE__*/function () {
69
84
  }, {
70
85
  key: "encodeNode",
71
86
  value: function encodeNode(node) {
72
- return sanitizeNode(toJSON(node, this.mentionMap));
87
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
88
+ return sanitizeNode(toJSON(node, this.mentionMap), options);
73
89
  }
74
90
  }]);
75
91
  }();
@@ -22,6 +22,6 @@ export declare class JSONTransformer implements Transformer<JSONDocNode> {
22
22
  /**
23
23
  * This method is used to encode a single node
24
24
  */
25
- encodeNode(node: PMNode): JSONNode;
25
+ encodeNode(node: PMNode, options?: SanitizeNodeOptions): JSONNode;
26
26
  }
27
27
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-json-transformer",
3
- "version": "9.3.0",
3
+ "version": "9.5.0",
4
4
  "description": "JSON transformer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -21,14 +21,14 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@atlaskit/adf-schema": "^56.7.0",
25
- "@atlaskit/adf-utils": "^20.5.0",
24
+ "@atlaskit/adf-schema": "^57.0.0",
25
+ "@atlaskit/adf-utils": "^20.7.0",
26
26
  "@atlaskit/editor-prosemirror": "^8.0.0",
27
27
  "@babel/runtime": "^7.0.0",
28
28
  "lodash": "^4.17.21"
29
29
  },
30
30
  "devDependencies": {
31
- "@atlassian/a11y-jest-testing": "^0.15.0",
31
+ "@atlassian/a11y-jest-testing": "^0.16.0",
32
32
  "@atlassian/structured-docs-types": "workspace:^",
33
33
  "react": "^19.2.0"
34
34
  },