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