@atlaskit/editor-json-transformer 9.1.0 → 9.3.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/JSONTransformer-2.js +82 -0
  3. package/dist/cjs/SchemaStage.js +11 -0
  4. package/dist/cjs/index.js +7 -5
  5. package/dist/cjs/jsonTransformer.js +18 -260
  6. package/dist/cjs/sanitize/remove-marks.js +15 -10
  7. package/dist/cjs/sanitize/remove-non-annotation-marks.js +19 -0
  8. package/dist/cjs/sanitize/sanitize-node.js +6 -5
  9. package/dist/cjs/toJSON.js +189 -0
  10. package/dist/es2019/JSONTransformer-2.js +59 -0
  11. package/dist/es2019/SchemaStage.js +5 -0
  12. package/dist/es2019/index.js +4 -2
  13. package/dist/es2019/jsonTransformer.js +13 -236
  14. package/dist/es2019/sanitize/remove-marks.js +9 -9
  15. package/dist/es2019/sanitize/remove-non-annotation-marks.js +9 -0
  16. package/dist/es2019/sanitize/sanitize-node.js +2 -1
  17. package/dist/es2019/sanitize.js +7 -0
  18. package/dist/es2019/toJSON.js +176 -0
  19. package/dist/esm/JSONTransformer-2.js +75 -0
  20. package/dist/esm/SchemaStage.js +5 -0
  21. package/dist/esm/index.js +4 -2
  22. package/dist/esm/jsonTransformer.js +13 -258
  23. package/dist/esm/sanitize/remove-marks.js +9 -9
  24. package/dist/esm/sanitize/remove-non-annotation-marks.js +12 -0
  25. package/dist/esm/sanitize/sanitize-node.js +2 -1
  26. package/dist/esm/sanitize.js +7 -0
  27. package/dist/esm/toJSON.js +182 -0
  28. package/dist/types/JSONTransformer-2.d.ts +27 -0
  29. package/dist/types/SchemaStage.d.ts +4 -0
  30. package/dist/types/index.d.ts +4 -2
  31. package/dist/types/jsonTransformer.d.ts +10 -37
  32. package/dist/types/sanitize/remove-marks.d.ts +4 -7
  33. package/dist/types/sanitize/remove-non-annotation-marks.d.ts +8 -0
  34. package/dist/types/sanitize.d.ts +6 -0
  35. package/dist/types/toJSON.d.ts +11 -0
  36. package/main/package.json +4 -4
  37. package/markOverrideRules/package.json +4 -4
  38. package/package.json +5 -5
  39. package/sanitize/remove-marks/package.json +4 -4
  40. package/sanitize/sanitize-node/package.json +4 -4
  41. package/tsconfig.json +5 -15
  42. package/types/package.json +4 -4
  43. package/dist/cjs/entry-points/main.js +0 -12
  44. package/dist/cjs/entry-points/markOverrideRules.js +0 -12
  45. package/dist/cjs/entry-points/sanitize-remove-marks.js +0 -12
  46. package/dist/cjs/entry-points/sanitize-sanitize-node.js +0 -12
  47. package/dist/cjs/entry-points/types.js +0 -1
  48. package/dist/es2019/entry-points/main.js +0 -2
  49. package/dist/es2019/entry-points/markOverrideRules.js +0 -2
  50. package/dist/es2019/entry-points/sanitize-remove-marks.js +0 -2
  51. package/dist/es2019/entry-points/sanitize-sanitize-node.js +0 -2
  52. package/dist/es2019/entry-points/types.js +0 -0
  53. package/dist/esm/entry-points/main.js +0 -2
  54. package/dist/esm/entry-points/markOverrideRules.js +0 -2
  55. package/dist/esm/entry-points/sanitize-remove-marks.js +0 -2
  56. package/dist/esm/entry-points/sanitize-sanitize-node.js +0 -2
  57. package/dist/esm/entry-points/types.js +0 -0
  58. package/dist/types/entry-points/main.d.ts +0 -1
  59. package/dist/types/entry-points/markOverrideRules.d.ts +0 -1
  60. package/dist/types/entry-points/sanitize-remove-marks.d.ts +0 -1
  61. package/dist/types/entry-points/sanitize-sanitize-node.d.ts +0 -1
  62. package/dist/types/entry-points/types.d.ts +0 -1
  63. package/editor-json-transformer.docs.tsx +0 -43
@@ -0,0 +1,176 @@
1
+ import { codeBlockToJSON, dataConsumerToJSON, expandToJSON, fragmentToJSON, linkToJSON, mediaSingleToJSON, mediaToJSON, mentionToJSON, tableToJSON, toJSONTableCell, toJSONTableHeader } from '@atlaskit/adf-schema';
2
+ import { markOverrideRuleFor } from './markOverrideRules';
3
+ const isType = type => node => node.type.name === type;
4
+
5
+ // Create a Set of node types that should have empty attrs removed
6
+ const NODES_WITH_EMPTY_ATTRS_REMOVAL = new Set(['paragraph', 'layoutSection', 'blockquote', 'nestedExpand', 'bulletList', 'listItem', 'orderedList', 'rule', 'caption', 'tableRow', 'media', 'mediaSingle', 'mediaInline']);
7
+ const isCodeBlock = isType('codeBlock');
8
+ const isMediaNode = isType('media');
9
+ const isMediaInline = isType('mediaInline');
10
+ const isMediaSingleNode = isType('mediaSingle');
11
+ const isMentionNode = isType('mention');
12
+ const isParagraph = isType('paragraph');
13
+ const isHeading = isType('heading');
14
+ const isTable = isType('table');
15
+ const isTableCell = isType('tableCell');
16
+ const isTableHeader = isType('tableHeader');
17
+ const isLinkMark = isType('link');
18
+ const isUnsupportedMark = isType('unsupportedMark');
19
+ const isUnsupportedNodeAttributeMark = isType('unsupportedNodeAttribute');
20
+ const isExpand = isType('expand');
21
+ const isNestedExpand = isType('nestedExpand');
22
+ const isUnsupportedNode = node => isType('unsupportedBlock')(node) || isType('unsupportedInline')(node);
23
+ const isDataConsumer = isType('dataConsumer');
24
+ const isFragmentMark = isType('fragment');
25
+ const isHardBreak = isType('hardBreak');
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ const filterNull = subject => {
29
+ let output = {
30
+ ...subject
31
+ };
32
+ // eslint-disable-next-line guard-for-in
33
+ for (const key in output) {
34
+ const current = output[key];
35
+ if (current === null) {
36
+ const {
37
+ [key]: unusedKey,
38
+ ...filteredObj
39
+ } = output;
40
+ output = filteredObj;
41
+ } else if (typeof current === 'object' && !Array.isArray(current)) {
42
+ output[key] = filterNull(current);
43
+ }
44
+ }
45
+ return output;
46
+ };
47
+ const canOverrideMark = (mark, existingMarks) => {
48
+ if (existingMarks.some(e => mark.attrs.originalValue.type === e.type.name)) {
49
+ return markOverrideRuleFor(mark.attrs.originalValue.type).canOverrideUnsupportedMark();
50
+ }
51
+ return false;
52
+ };
53
+ const getUnwrappedNodeAttributes = (node, mark, obj) => {
54
+ const nodeAttributes = node.type.spec.attrs;
55
+ const attributes = {
56
+ ...mark.attrs.unsupported,
57
+ ...obj.attrs
58
+ };
59
+ // Ignored via go/ees005
60
+ // eslint-disable-next-line no-var
61
+ for (var key in obj.attrs) {
62
+ if (obj.attrs.hasOwnProperty(key)) {
63
+ const attribute = nodeAttributes ? nodeAttributes[key] : null;
64
+ if (attribute) {
65
+ if (attribute.default === node.attrs[key] && mark.attrs.unsupported[key]) {
66
+ return {
67
+ ...attributes,
68
+ [key]: mark.attrs.unsupported[key]
69
+ };
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return attributes;
75
+ };
76
+
77
+ /**
78
+ * Transforms a Prosemirror node into a JSON representation. Compared with
79
+ * native Prosemirror JSON, this representation ensures we have valid ADF attrs.
80
+ *
81
+ * @param node The Prosemirror node to transform.
82
+ * @param mentionMap A map of mention IDs to their display names.
83
+ * @returns The JSON representation of the node.
84
+ */
85
+ export const toJSON = (node, mentionMap) => {
86
+ const obj = {
87
+ type: node.type.name
88
+ };
89
+ if (isUnsupportedNode(node)) {
90
+ return node.attrs.originalValue;
91
+ } else if (isMediaNode(node)) {
92
+ obj.attrs = mediaToJSON(node).attrs;
93
+ } else if (isMediaSingleNode(node)) {
94
+ obj.attrs = mediaSingleToJSON(node).attrs;
95
+ } else if (isMediaInline(node)) {
96
+ obj.attrs = mediaToJSON(node).attrs;
97
+ } else if (isMentionNode(node)) {
98
+ obj.attrs = mentionToJSON(node).attrs;
99
+ } else if (isCodeBlock(node)) {
100
+ obj.attrs = codeBlockToJSON(node).attrs;
101
+ } else if (isTable(node)) {
102
+ obj.attrs = tableToJSON(node).attrs;
103
+ } else if (isTableCell(node)) {
104
+ obj.attrs = toJSONTableCell(node).attrs;
105
+ } else if (isTableHeader(node)) {
106
+ obj.attrs = toJSONTableHeader(node).attrs;
107
+ } else if (isExpand(node) || isNestedExpand(node)) {
108
+ obj.attrs = expandToJSON(node).attrs;
109
+ } else if (node.attrs && Object.keys(node.attrs).length) {
110
+ obj.attrs = node.attrs;
111
+ }
112
+ if (obj.attrs) {
113
+ obj.attrs = filterNull(obj.attrs);
114
+ }
115
+ if (isMentionNode(node) && mentionMap) {
116
+ var _text, _obj$attrs;
117
+ // If the mentionMap exists and has a name defined then we should use it and prepend @ to the begining of it.
118
+ const name = !!(mentionMap !== null && mentionMap !== void 0 && mentionMap[node.attrs.id]) ? `@${mentionMap[node.attrs.id]}` : '';
119
+ // Ignored via go/ees005
120
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
+ const text = (_text = (_obj$attrs = obj.attrs) === null || _obj$attrs === void 0 ? void 0 : _obj$attrs.text) !== null && _text !== void 0 ? _text : '';
122
+ obj.attrs = {
123
+ ...obj.attrs,
124
+ // If an explicit text value is set on the mention then that should take priority over the mentionMap value.
125
+ text: !!text ? text : name
126
+ };
127
+ }
128
+ if (NODES_WITH_EMPTY_ATTRS_REMOVAL.has(node.type.name) && obj.attrs && !Object.keys(obj.attrs).length || isHardBreak(node)) {
129
+ delete obj.attrs;
130
+ }
131
+ if (node.isText) {
132
+ obj.text = node.textContent;
133
+ } else {
134
+ node.content.forEach(child => {
135
+ obj.content = obj.content || [];
136
+ obj.content.push(toJSON(child, mentionMap));
137
+ });
138
+ }
139
+ if (isParagraph(node) || isHeading(node)) {
140
+ obj.content = obj.content || [];
141
+ }
142
+ if (node.marks.length) {
143
+ // Run any custom mark serialisers
144
+ const parsedMarks = node.marks.map(mark => {
145
+ if (isUnsupportedMark(mark)) {
146
+ return canOverrideMark(mark, node.marks) ? null : mark.attrs.originalValue;
147
+ } else if (isUnsupportedNodeAttributeMark(mark)) {
148
+ return null;
149
+ } else if (isLinkMark(mark)) {
150
+ return linkToJSON(mark);
151
+ } else if (isDataConsumer(mark)) {
152
+ var _serialised$attrs$sou;
153
+ const serialised = dataConsumerToJSON(mark);
154
+ 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;
155
+ } else if (isFragmentMark(mark)) {
156
+ const fragmentMark = fragmentToJSON(mark);
157
+ if (!fragmentMark.attrs.localId) {
158
+ return null;
159
+ }
160
+ return fragmentMark;
161
+ } else {
162
+ return mark.toJSON();
163
+ }
164
+ }).filter(maybeMark => maybeMark !== null);
165
+
166
+ // Only set if we have a non-empty array, otherwise explicitly undefine it (as we only run this path if `node.marks.length`)
167
+ obj.marks = (parsedMarks === null || parsedMarks === void 0 ? void 0 : parsedMarks.length) > 0 ? parsedMarks : undefined;
168
+ const nodeAttributeMark = node.marks.find(isUnsupportedNodeAttributeMark);
169
+ if (nodeAttributeMark && nodeAttributeMark.attrs.type.nodeType === obj.type) {
170
+ obj.attrs = {
171
+ ...getUnwrappedNodeAttributes(node, nodeAttributeMark, obj)
172
+ };
173
+ }
174
+ }
175
+ return obj;
176
+ };
@@ -0,0 +1,75 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import isEqual from 'lodash/isEqual';
4
+ import { defaultSchema, getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
5
+ import { sanitizeNode } from './sanitize/sanitize-node';
6
+ import { toJSON } from './toJSON';
7
+ var createDocFromContent = function createDocFromContent(content) {
8
+ return {
9
+ version: 1,
10
+ type: 'doc',
11
+ content: content || []
12
+ };
13
+ };
14
+ var emptyDoc = createDocFromContent([{
15
+ type: 'paragraph',
16
+ content: []
17
+ }]);
18
+ export var JSONTransformer = /*#__PURE__*/function () {
19
+ /**
20
+ * Creates a new JSONTransformer instance.
21
+ * @param schema The current editor schema
22
+ * @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
23
+ * mention node.attr.text values with mapped names.
24
+ */
25
+ function JSONTransformer() {
26
+ var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultSchema;
27
+ var mentionMap = arguments.length > 1 ? arguments[1] : undefined;
28
+ _classCallCheck(this, JSONTransformer);
29
+ this.schema = schema;
30
+ this.mentionMap = mentionMap;
31
+ }
32
+ return _createClass(JSONTransformer, [{
33
+ key: "encode",
34
+ value: function encode(node) {
35
+ var _this = this;
36
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ var content = [];
38
+ node.content.forEach(function (child) {
39
+ content.push(sanitizeNode(toJSON(child, _this.mentionMap), options));
40
+ });
41
+ if (!content || isEqual(content, emptyDoc.content)) {
42
+ return createDocFromContent([]);
43
+ }
44
+ return createDocFromContent(content);
45
+ }
46
+ }, {
47
+ key: "internalParse",
48
+ value: function internalParse(content, schema) {
49
+ var doc = schema.nodeFromJSON(content);
50
+ doc.check();
51
+ return doc;
52
+ }
53
+ }, {
54
+ key: "parse",
55
+ value: function parse(content, stage) {
56
+ if (content.type !== 'doc') {
57
+ throw new Error('Expected content format to be ADF');
58
+ }
59
+ var schema = !!stage ? getSchemaBasedOnStage(stage) : this.schema;
60
+ if (!content.content || content.content.length === 0) {
61
+ return this.internalParse(emptyDoc, schema);
62
+ }
63
+ return this.internalParse(content, schema);
64
+ }
65
+
66
+ /**
67
+ * This method is used to encode a single node
68
+ */
69
+ }, {
70
+ key: "encodeNode",
71
+ value: function encodeNode(node) {
72
+ return sanitizeNode(toJSON(node, this.mentionMap));
73
+ }
74
+ }]);
75
+ }();
@@ -0,0 +1,5 @@
1
+ export var SchemaStage = /*#__PURE__*/function (SchemaStage) {
2
+ SchemaStage["FINAL"] = "final";
3
+ SchemaStage["STAGE_0"] = "stage0";
4
+ return SchemaStage;
5
+ }({});
package/dist/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Disable no-re-export rule for entry point files
2
2
  /* eslint-disable @atlaskit/editor/no-re-export */
3
3
 
4
- export { JSONTransformer, SchemaStage, toJSON as nodeToJSON } from './jsonTransformer';
5
- export { isJSONDocNode } from './entry-points/main';
4
+ export { JSONTransformer } from './JSONTransformer-2';
5
+ export { SchemaStage } from './SchemaStage';
6
+ export { toJSON as nodeToJSON } from './toJSON';
7
+ export { isJSONDocNode } from './main';
@@ -1,261 +1,16 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _typeof from "@babel/runtime/helpers/typeof";
4
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
- import isEqual from 'lodash/isEqual';
11
- import { codeBlockToJSON, dataConsumerToJSON, expandToJSON, fragmentToJSON, linkToJSON, mediaSingleToJSON, mediaToJSON, mentionToJSON, tableToJSON, toJSONTableCell, toJSONTableHeader } from '@atlaskit/adf-schema';
12
- import { defaultSchema, getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
13
- import { markOverrideRuleFor } from './markOverrideRules';
14
- import { sanitizeNode } from './sanitize/sanitize-node';
15
- export var SchemaStage = /*#__PURE__*/function (SchemaStage) {
16
- SchemaStage["FINAL"] = "final";
17
- SchemaStage["STAGE_0"] = "stage0";
18
- return SchemaStage;
19
- }({});
20
- var isType = function isType(type) {
21
- return function (node) {
22
- return node.type.name === type;
23
- };
24
- };
25
-
26
- // Create a Set of node types that should have empty attrs removed
27
- var NODES_WITH_EMPTY_ATTRS_REMOVAL = new Set(['paragraph', 'layoutSection', 'blockquote', 'nestedExpand', 'bulletList', 'listItem', 'orderedList', 'rule', 'caption', 'tableRow', 'media', 'mediaSingle', 'mediaInline']);
28
- var isCodeBlock = isType('codeBlock');
29
- var isMediaNode = isType('media');
30
- var isMediaInline = isType('mediaInline');
31
- var isMediaSingleNode = isType('mediaSingle');
32
- var isMentionNode = isType('mention');
33
- var isParagraph = isType('paragraph');
34
- var isHeading = isType('heading');
35
- var isTable = isType('table');
36
- var isTableCell = isType('tableCell');
37
- var isTableHeader = isType('tableHeader');
38
- var isLinkMark = isType('link');
39
- var isUnsupportedMark = isType('unsupportedMark');
40
- var isUnsupportedNodeAttributeMark = isType('unsupportedNodeAttribute');
41
- var isExpand = isType('expand');
42
- var isNestedExpand = isType('nestedExpand');
43
- var isUnsupportedNode = function isUnsupportedNode(node) {
44
- return isType('unsupportedBlock')(node) || isType('unsupportedInline')(node);
45
- };
46
- var isDataConsumer = isType('dataConsumer');
47
- var isFragmentMark = isType('fragment');
48
- var isHardBreak = isType('hardBreak');
49
- var createDocFromContent = function createDocFromContent(content) {
50
- return {
51
- version: 1,
52
- type: 'doc',
53
- content: content || []
54
- };
55
- };
56
- var emptyDoc = createDocFromContent([{
57
- type: 'paragraph',
58
- content: []
59
- }]);
60
-
61
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- var _filterNull = function filterNull(subject) {
63
- var output = _objectSpread({}, subject);
64
- // eslint-disable-next-line guard-for-in
65
- for (var key in output) {
66
- var current = output[key];
67
- if (current === null) {
68
- var _output = output,
69
- unusedKey = _output[key],
70
- filteredObj = _objectWithoutProperties(_output, [key].map(_toPropertyKey));
71
- output = filteredObj;
72
- } else if (_typeof(current) === 'object' && !Array.isArray(current)) {
73
- output[key] = _filterNull(current);
74
- }
75
- }
76
- return output;
77
- };
78
- var canOverrideMark = function canOverrideMark(mark, existingMarks) {
79
- if (existingMarks.some(function (e) {
80
- return mark.attrs.originalValue.type === e.type.name;
81
- })) {
82
- return markOverrideRuleFor(mark.attrs.originalValue.type).canOverrideUnsupportedMark();
83
- }
84
- return false;
85
- };
86
- var getUnwrappedNodeAttributes = function getUnwrappedNodeAttributes(node, mark, obj) {
87
- var nodeAttributes = node.type.spec.attrs;
88
- var attributes = _objectSpread(_objectSpread({}, mark.attrs.unsupported), obj.attrs);
89
- // Ignored via go/ees005
90
- // eslint-disable-next-line no-var
91
- for (var key in obj.attrs) {
92
- if (obj.attrs.hasOwnProperty(key)) {
93
- var attribute = nodeAttributes ? nodeAttributes[key] : null;
94
- if (attribute) {
95
- if (attribute.default === node.attrs[key] && mark.attrs.unsupported[key]) {
96
- return _objectSpread(_objectSpread({}, attributes), {}, _defineProperty({}, key, mark.attrs.unsupported[key]));
97
- }
98
- }
99
- }
100
- }
101
- return attributes;
102
- };
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
2
+ // Disable no-re-export rule for entry point files
3
+ /* eslint-disable @atlaskit/editor/no-re-export */
103
4
 
104
5
  /**
105
- * Transforms a Prosemirror node into a JSON representation. Compared with
106
- * native Prosemirror JSON, this representation ensures we have valid ADF attrs.
107
- *
108
- * @param node The Prosemirror node to transform.
109
- * @param mentionMap A map of mention IDs to their display names.
110
- * @returns The JSON representation of the node.
6
+ * @deprecated Use `import { SchemaStage } from '@atlaskit/editor-json-transformer'` instead.
111
7
  */
112
- var _toJSON = function toJSON(node, mentionMap) {
113
- var obj = {
114
- type: node.type.name
115
- };
116
- if (isUnsupportedNode(node)) {
117
- return node.attrs.originalValue;
118
- } else if (isMediaNode(node)) {
119
- obj.attrs = mediaToJSON(node).attrs;
120
- } else if (isMediaSingleNode(node)) {
121
- obj.attrs = mediaSingleToJSON(node).attrs;
122
- } else if (isMediaInline(node)) {
123
- obj.attrs = mediaToJSON(node).attrs;
124
- } else if (isMentionNode(node)) {
125
- obj.attrs = mentionToJSON(node).attrs;
126
- } else if (isCodeBlock(node)) {
127
- obj.attrs = codeBlockToJSON(node).attrs;
128
- } else if (isTable(node)) {
129
- obj.attrs = tableToJSON(node).attrs;
130
- } else if (isTableCell(node)) {
131
- obj.attrs = toJSONTableCell(node).attrs;
132
- } else if (isTableHeader(node)) {
133
- obj.attrs = toJSONTableHeader(node).attrs;
134
- } else if (isExpand(node) || isNestedExpand(node)) {
135
- obj.attrs = expandToJSON(node).attrs;
136
- } else if (node.attrs && Object.keys(node.attrs).length) {
137
- obj.attrs = node.attrs;
138
- }
139
- if (obj.attrs) {
140
- obj.attrs = _filterNull(obj.attrs);
141
- }
142
- if (isMentionNode(node) && mentionMap) {
143
- var _text, _obj$attrs;
144
- // If the mentionMap exists and has a name defined then we should use it and prepend @ to the begining of it.
145
- var name = !!(mentionMap !== null && mentionMap !== void 0 && mentionMap[node.attrs.id]) ? "@".concat(mentionMap[node.attrs.id]) : '';
146
- // Ignored via go/ees005
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- var text = (_text = (_obj$attrs = obj.attrs) === null || _obj$attrs === void 0 ? void 0 : _obj$attrs.text) !== null && _text !== void 0 ? _text : '';
149
- obj.attrs = _objectSpread(_objectSpread({}, obj.attrs), {}, {
150
- // If an explicit text value is set on the mention then that should take priority over the mentionMap value.
151
- text: !!text ? text : name
152
- });
153
- }
154
- if (NODES_WITH_EMPTY_ATTRS_REMOVAL.has(node.type.name) && obj.attrs && !Object.keys(obj.attrs).length || isHardBreak(node)) {
155
- delete obj.attrs;
156
- }
157
- if (node.isText) {
158
- obj.text = node.textContent;
159
- } else {
160
- node.content.forEach(function (child) {
161
- obj.content = obj.content || [];
162
- obj.content.push(_toJSON(child, mentionMap));
163
- });
164
- }
165
- if (isParagraph(node) || isHeading(node)) {
166
- obj.content = obj.content || [];
167
- }
168
- if (node.marks.length) {
169
- // Run any custom mark serialisers
170
- var parsedMarks = node.marks.map(function (mark) {
171
- if (isUnsupportedMark(mark)) {
172
- return canOverrideMark(mark, node.marks) ? null : mark.attrs.originalValue;
173
- } else if (isUnsupportedNodeAttributeMark(mark)) {
174
- return null;
175
- } else if (isLinkMark(mark)) {
176
- return linkToJSON(mark);
177
- } else if (isDataConsumer(mark)) {
178
- var _serialised$attrs$sou;
179
- var serialised = dataConsumerToJSON(mark);
180
- 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;
181
- } else if (isFragmentMark(mark)) {
182
- var fragmentMark = fragmentToJSON(mark);
183
- if (!fragmentMark.attrs.localId) {
184
- return null;
185
- }
186
- return fragmentMark;
187
- } else {
188
- return mark.toJSON();
189
- }
190
- }).filter(function (maybeMark) {
191
- return maybeMark !== null;
192
- });
193
-
194
- // Only set if we have a non-empty array, otherwise explicitly undefine it (as we only run this path if `node.marks.length`)
195
- obj.marks = (parsedMarks === null || parsedMarks === void 0 ? void 0 : parsedMarks.length) > 0 ? parsedMarks : undefined;
196
- var nodeAttributeMark = node.marks.find(isUnsupportedNodeAttributeMark);
197
- if (nodeAttributeMark && nodeAttributeMark.attrs.type.nodeType === obj.type) {
198
- obj.attrs = _objectSpread({}, getUnwrappedNodeAttributes(node, nodeAttributeMark, obj));
199
- }
200
- }
201
- return obj;
202
- };
203
- export { _toJSON as toJSON };
204
- export var JSONTransformer = /*#__PURE__*/function () {
205
- /**
206
- * Creates a new JSONTransformer instance.
207
- * @param schema The current editor schema
208
- * @param mentionMap An optional mapping of user IDs to mention names. This is used by the encoder to substitute empty
209
- * mention node.attr.text values with mapped names.
210
- */
211
- function JSONTransformer() {
212
- var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultSchema;
213
- var mentionMap = arguments.length > 1 ? arguments[1] : undefined;
214
- _classCallCheck(this, JSONTransformer);
215
- this.schema = schema;
216
- this.mentionMap = mentionMap;
217
- }
218
- return _createClass(JSONTransformer, [{
219
- key: "encode",
220
- value: function encode(node) {
221
- var _this = this;
222
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
223
- var content = [];
224
- node.content.forEach(function (child) {
225
- content.push(sanitizeNode(_toJSON(child, _this.mentionMap), options));
226
- });
227
- if (!content || isEqual(content, emptyDoc.content)) {
228
- return createDocFromContent([]);
229
- }
230
- return createDocFromContent(content);
231
- }
232
- }, {
233
- key: "internalParse",
234
- value: function internalParse(content, schema) {
235
- var doc = schema.nodeFromJSON(content);
236
- doc.check();
237
- return doc;
238
- }
239
- }, {
240
- key: "parse",
241
- value: function parse(content, stage) {
242
- if (content.type !== 'doc') {
243
- throw new Error('Expected content format to be ADF');
244
- }
245
- var schema = !!stage ? getSchemaBasedOnStage(stage) : this.schema;
246
- if (!content.content || content.content.length === 0) {
247
- return this.internalParse(emptyDoc, schema);
248
- }
249
- return this.internalParse(content, schema);
250
- }
251
-
252
- /**
253
- * This method is used to encode a single node
254
- */
255
- }, {
256
- key: "encodeNode",
257
- value: function encodeNode(node) {
258
- return sanitizeNode(_toJSON(node, this.mentionMap));
259
- }
260
- }]);
261
- }();
8
+ export { SchemaStage } from './SchemaStage';
9
+ /**
10
+ * @deprecated Use `import { toJSON } from '@atlaskit/editor-json-transformer/jsonTransformer'` instead.
11
+ */
12
+ export { toJSON } from './toJSON';
13
+ /**
14
+ * @deprecated Use `import { JSONTransformer } from '@atlaskit/editor-json-transformer/jsonTransformer'` instead.
15
+ */
16
+ export { JSONTransformer } from './JSONTransformer-2';
@@ -1,17 +1,17 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
5
+ // Disable no-re-export rule for entry point files
6
+ /* eslint-disable @atlaskit/editor/no-re-export */
7
+
4
8
  export function removeMarks(node) {
5
9
  var newNode = _objectSpread({}, node);
6
10
  delete newNode.marks;
7
11
  return newNode;
8
12
  }
9
- export function removeNonAnnotationMarks(node) {
10
- var newNode = _objectSpread({}, node);
11
- if (node.marks) {
12
- newNode.marks = node.marks.filter(function (mark) {
13
- return mark.type === 'annotation';
14
- });
15
- }
16
- return newNode;
17
- }
13
+
14
+ /**
15
+ * @deprecated Use `import { removeNonAnnotationMarks } from '@atlaskit/editor-json-transformer/sanitize/remove-marks'` instead.
16
+ */
17
+ export { removeNonAnnotationMarks } from './remove-non-annotation-marks';
@@ -0,0 +1,12 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ export function removeNonAnnotationMarks(node) {
5
+ var newNode = _objectSpread({}, node);
6
+ if (node.marks) {
7
+ newNode.marks = node.marks.filter(function (mark) {
8
+ return mark.type === 'annotation';
9
+ });
10
+ }
11
+ return newNode;
12
+ }
@@ -3,7 +3,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import { transformNestedTableNodeOutgoingDocument } from '@atlaskit/adf-utils/transforms';
5
5
  import { traverse } from '@atlaskit/adf-utils/traverse';
6
- import { removeMarks, removeNonAnnotationMarks } from './remove-marks';
6
+ import { removeMarks } from './remove-marks';
7
+ import { removeNonAnnotationMarks } from './remove-non-annotation-marks';
7
8
  var hasNestedTable = function hasNestedTable(tableCellNode) {
8
9
  var _tableCellNode$conten;
9
10
  return (_tableCellNode$conten = tableCellNode.content) === null || _tableCellNode$conten === void 0 ? void 0 : _tableCellNode$conten.some(function (node) {
@@ -1,5 +1,12 @@
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
1
2
  // Disable no-re-export rule for entry point files
2
3
  /* eslint-disable @atlaskit/editor/no-re-export */
3
4
 
5
+ /**
6
+ * @deprecated Use `import { sanitizeNode } from '@atlaskit/editor-json-transformer/sanitize/sanitize-node'` instead.
7
+ */
4
8
  export { sanitizeNode } from './sanitize/sanitize-node';
9
+ /**
10
+ * @deprecated Use `import { removeMarks } from '@atlaskit/editor-json-transformer/sanitize/remove-marks'` instead.
11
+ */
5
12
  export { removeMarks } from './sanitize/remove-marks';