@atlaskit/editor-jira-transformer 8.2.4 → 8.2.6

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/dist/esm/utils.js CHANGED
@@ -1,34 +1,31 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
-
3
2
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
4
  import { normalizeHexColor } from '@atlaskit/adf-schema';
8
5
  import { isSchemaWithLists, isSchemaWithMentions, isSchemaWithLinks, isSchemaWithAdvancedTextFormattingMarks, isSchemaWithCodeBlock, isSchemaWithBlockQuotes, isSchemaWithMedia, isSchemaWithSubSupMark, isSchemaWithTextColor, isSchemaWithTables } from '@atlaskit/adf-schema/schema-jira';
9
6
  import { Fragment } from 'prosemirror-model';
10
7
  import { mapImageToEmoji } from './emojiHelper';
8
+
11
9
  /**
12
10
  * Ensure that each node in the fragment is a block, wrapping
13
11
  * in a block node if necessary.
14
12
  */
15
-
16
13
  export function ensureBlocks(fragment, schema, nodeType) {
17
14
  // If all the nodes are inline, we want to wrap in a single paragraph.
18
15
  if (schema.nodes.paragraph.validContent(fragment)) {
19
16
  return Fragment.fromArray([schema.nodes.paragraph.createChecked({}, fragment)]);
20
- } // Either all the nodes are blocks, or a mix of inline and blocks.
21
- // We convert each (if any) inline nodes to blocks.
17
+ }
22
18
 
19
+ // Either all the nodes are blocks, or a mix of inline and blocks.
20
+ // We convert each (if any) inline nodes to blocks.
21
+ var blockNodes = [];
23
22
 
24
- var blockNodes = []; // Following if condition has been added as fix for #ED-3431.
23
+ // Following if condition has been added as fix for #ED-3431.
25
24
  // First child of list-item should be paragraph,
26
25
  // if that is not the case paragraph requires to be added.
27
-
28
26
  if (nodeType && nodeType === schema.nodes.listItem && fragment.firstChild && (fragment.firstChild.type === schema.nodes.bulletList || fragment.firstChild.type === schema.nodes.orderedList)) {
29
27
  blockNodes.push(schema.nodes.paragraph.createAndFill());
30
28
  }
31
-
32
29
  fragment.forEach(function (child) {
33
30
  if (child.isBlock) {
34
31
  blockNodes.push(child);
@@ -38,10 +35,10 @@ export function ensureBlocks(fragment, schema, nodeType) {
38
35
  });
39
36
  return Fragment.fromArray(blockNodes);
40
37
  }
38
+
41
39
  /**
42
40
  * This function will convert all content to inline nodes
43
41
  */
44
-
45
42
  export var ensureInline = function ensureInline(schema, content, supportedMarks) {
46
43
  var result = [];
47
44
  content.forEach(function (node) {
@@ -51,9 +48,8 @@ export var ensureInline = function ensureInline(schema, content, supportedMarks)
51
48
  });
52
49
  result.push(node.mark(filteredMarks));
53
50
  return;
54
- } // We replace an non-inline node with UnsupportedInline node
55
-
56
-
51
+ }
52
+ // We replace an non-inline node with UnsupportedInline node
57
53
  result.push(schema.text(node.textContent));
58
54
  });
59
55
  return Fragment.fromArray(result);
@@ -63,59 +59,47 @@ export function convert(content, node, schema) {
63
59
  if (node.nodeType === Node.TEXT_NODE) {
64
60
  var text = node.textContent;
65
61
  return text ? schema.text(text) : null;
66
- } // marks and nodes
67
-
62
+ }
68
63
 
64
+ // marks and nodes
69
65
  if (node instanceof HTMLElement) {
70
66
  var tag = node.tagName.toUpperCase();
71
-
72
67
  switch (tag) {
73
68
  // Marks
74
69
  case 'DEL':
75
70
  if (!isSchemaWithAdvancedTextFormattingMarks(schema)) {
76
71
  return null;
77
72
  }
78
-
79
73
  return addMarks(content, [schema.marks.strike.create()]);
80
-
81
74
  case 'B':
82
75
  return addMarks(content, [schema.marks.strong.create()]);
83
-
84
76
  case 'EM':
85
77
  return addMarks(content, [schema.marks.em.create()]);
86
-
87
78
  case 'TT':
88
79
  if (!isSchemaWithAdvancedTextFormattingMarks(schema)) {
89
80
  return null;
90
81
  }
91
-
92
82
  return addMarks(content, [schema.marks.code.create()]);
93
-
94
83
  case 'SUB':
95
84
  case 'SUP':
96
85
  if (!isSchemaWithSubSupMark(schema)) {
97
86
  return null;
98
87
  }
99
-
100
88
  var type = tag === 'SUB' ? 'sub' : 'sup';
101
89
  return addMarks(content, [schema.marks.subsup.create({
102
90
  type: type
103
91
  })]);
104
-
105
92
  case 'INS':
106
93
  return addMarks(content, [schema.marks.underline.create()]);
107
-
108
94
  case 'FONT':
109
95
  if (!isSchemaWithTextColor(schema)) {
110
96
  return null;
111
97
  }
112
-
113
98
  var color = normalizeHexColor(node.getAttribute('color'), '#333333');
114
99
  return color ? addMarks(content, [schema.marks.textColor.create({
115
100
  color: color
116
101
  })]) : content;
117
102
  // Nodes
118
-
119
103
  case 'A':
120
104
  if (node.className === 'user-hover' && isSchemaWithMentions(schema)) {
121
105
  return schema.nodes.mention.createChecked({
@@ -123,18 +107,15 @@ export function convert(content, node, schema) {
123
107
  text: node.textContent
124
108
  });
125
109
  }
126
-
127
110
  if (node.className.match('jira-issue-macro-key') || !content || !isSchemaWithLinks(schema)) {
128
111
  return null;
129
112
  }
130
-
131
113
  var href = node.getAttribute('href');
132
114
  var title = node.getAttribute('title');
133
115
  return href ? addMarks(content, [schema.marks.link.create({
134
116
  href: href,
135
117
  title: title
136
118
  })]) : content;
137
-
138
119
  case 'SPAN':
139
120
  /**
140
121
  * JIRA ISSUE MACROS
@@ -152,14 +133,12 @@ export function convert(content, node, schema) {
152
133
  if (node.className.split(' ').indexOf('jira-issue-macro') > -1) {
153
134
  var jiraKey = node.getAttribute('data-jira-key');
154
135
  var link = node.getElementsByTagName('a')[0];
155
-
156
136
  if (jiraKey && link) {
157
137
  return addMarks(Fragment.from(schema.text(jiraKey)), [schema.marks.link.create({
158
138
  href: link.getAttribute('href'),
159
139
  title: link.getAttribute('title')
160
140
  })]);
161
141
  }
162
-
163
142
  return null;
164
143
  } else if (node.className.match('jira-macro-single-issue-export-pdf')) {
165
144
  return null;
@@ -168,12 +147,9 @@ export function convert(content, node, schema) {
168
147
  return null;
169
148
  } else if (isMedia(node) && isSchemaWithMedia(schema)) {
170
149
  var dataNode = node.querySelector('[data-media-services-id]');
171
-
172
150
  if (dataNode && dataNode instanceof HTMLElement) {
173
151
  var id = dataNode.getAttribute('data-media-services-id');
174
-
175
152
  var _type = dataNode.getAttribute('data-media-services-type');
176
-
177
153
  var collection = dataNode.getAttribute('data-media-services-collection') || '';
178
154
  var attachmentName = dataNode.getAttribute('data-attachment-name');
179
155
  var attachmentType = dataNode.getAttribute('data-attachment-type');
@@ -192,22 +168,17 @@ export function convert(content, node, schema) {
192
168
  });
193
169
  }
194
170
  }
195
-
196
171
  break;
197
-
198
172
  case 'IMG':
199
173
  if (node.parentElement && node.parentElement.className.match('jira-issue-macro-key')) {
200
174
  return null;
201
175
  } else if (node.className === 'emoticon') {
202
176
  var emojiResult = mapImageToEmoji(node);
203
-
204
177
  if (emojiResult) {
205
178
  return schema.text(emojiResult);
206
179
  }
207
180
  }
208
-
209
181
  break;
210
-
211
182
  case 'H1':
212
183
  case 'H2':
213
184
  case 'H3':
@@ -218,24 +189,23 @@ export function convert(content, node, schema) {
218
189
  var supportedMarks = [schema.marks.link].filter(function (mark) {
219
190
  return !!mark;
220
191
  });
221
- return schema.nodes.heading.createChecked( // @see ED-4708
192
+ return schema.nodes.heading.createChecked(
193
+ // @see ED-4708
222
194
  {
223
195
  level: level === 6 ? 5 : level
224
196
  }, schema.nodes.heading.validContent(content) ? content : ensureInline(schema, content, supportedMarks));
225
-
226
197
  case 'BR':
227
198
  return schema.nodes.hardBreak.createChecked();
228
-
229
199
  case 'HR':
230
200
  return schema.nodes.rule.createChecked();
231
-
232
201
  case 'P':
233
202
  if (node.firstElementChild && isMedia(node.firstElementChild)) {
234
203
  // Filter out whitespace text nodes
204
+
235
205
  var _schema$nodes = schema.nodes,
236
- mediaSingle = _schema$nodes.mediaSingle,
237
- mediaGroup = _schema$nodes.mediaGroup,
238
- paragraph = _schema$nodes.paragraph;
206
+ mediaSingle = _schema$nodes.mediaSingle,
207
+ mediaGroup = _schema$nodes.mediaGroup,
208
+ paragraph = _schema$nodes.paragraph;
239
209
  var mediaArray = [];
240
210
  var contentArray = [];
241
211
  var fragmentArray = [];
@@ -247,45 +217,37 @@ export function convert(content, node, schema) {
247
217
  } else if (!(child.isText && /^\s*$/.test(child.text || ''))) {
248
218
  hasNonMediaChildren = true;
249
219
  }
250
-
251
220
  contentArray.push(child);
252
221
  });
253
-
254
222
  if (hasNonMediaChildren && contentArray.length) {
255
223
  fragmentArray.push(paragraph.createChecked({}, contentArray));
256
224
  }
257
-
258
225
  if (isSchemaWithMedia(schema) && mediaArray.length) {
259
226
  var mediaNodeType = isMediaSingle(node.firstElementChild) ? mediaSingle : mediaGroup;
260
227
  fragmentArray.push(mediaNodeType.createChecked({}, mediaArray));
261
228
  }
262
-
263
229
  if (fragmentArray.length) {
264
230
  return Fragment.fromArray(fragmentArray);
265
231
  }
266
-
267
232
  return null;
268
233
  }
269
-
270
234
  return schema.nodes.paragraph.createChecked({}, content);
271
- } // lists
272
-
235
+ }
273
236
 
237
+ // lists
274
238
  if (isSchemaWithLists(schema)) {
275
239
  switch (tag) {
276
240
  case 'UL':
277
241
  return schema.nodes.bulletList.createChecked({}, content);
278
-
279
242
  case 'OL':
280
243
  return schema.nodes.orderedList.createChecked({}, content);
281
-
282
244
  case 'LI':
283
245
  var compatibleContent = schema.nodes.listItem.validContent(content) ? content : ensureBlocks(content, schema, schema.nodes.listItem);
284
246
  return schema.nodes.listItem.createChecked({}, compatibleContent);
285
247
  }
286
- } // code block
287
-
248
+ }
288
249
 
250
+ // code block
289
251
  if (isSchemaWithCodeBlock(schema)) {
290
252
  switch (tag) {
291
253
  case 'DIV':
@@ -293,98 +255,81 @@ export function convert(content, node, schema) {
293
255
  return null;
294
256
  } else if (node.className === 'code panel' || node.className === 'preformatted panel') {
295
257
  var pre = node.querySelector('pre');
296
-
297
258
  if (!pre) {
298
259
  return null;
299
260
  }
300
-
301
261
  var language = node.className === 'preformatted panel' ? 'plain' : pre.className.split('-')[1];
302
262
  var textContent = (pre.textContent || '').replace(/\r\n/g, '\n');
303
263
  return schema.nodes.codeBlock.createChecked({
304
264
  language: language
305
265
  }, textContent ? schema.text(textContent) : undefined);
306
266
  }
307
-
308
267
  break;
309
-
310
268
  case 'PRE':
311
269
  return null;
312
270
  }
313
271
  }
314
-
315
272
  if (isSchemaWithBlockQuotes(schema) && tag === 'BLOCKQUOTE') {
316
273
  var blockquoteContent = content && content.content.length ? content : schema.nodes.paragraph.createChecked();
317
274
  return schema.nodes.blockquote.createChecked({}, blockquoteContent);
318
- } // table
319
-
275
+ }
320
276
 
277
+ // table
321
278
  if (isSchemaWithTables(schema)) {
322
279
  switch (tag) {
323
280
  case 'TABLE':
324
281
  return schema.nodes.table.createChecked({}, content);
325
-
326
282
  case 'TR':
327
283
  return schema.nodes.tableRow.createChecked({}, content);
328
-
329
284
  case 'TD':
330
285
  var tdContent = schema.nodes.tableCell.validContent(content) ? content : ensureBlocks(content, schema);
331
286
  return schema.nodes.tableCell.createChecked({}, tdContent);
332
-
333
287
  case 'TH':
334
288
  var thContent = schema.nodes.tableHeader.validContent(content) ? content : ensureBlocks(content, schema);
335
289
  return schema.nodes.tableHeader.createChecked({}, thContent);
336
290
  }
337
291
  }
338
292
  }
339
-
340
293
  return;
341
294
  }
295
+
342
296
  /*
343
297
  * Flattens DOM tree into single array
344
298
  */
345
-
346
299
  export function bfsOrder(root) {
347
300
  var inqueue = [root];
348
301
  var outqueue = [];
349
302
  var elem;
350
-
351
303
  while (elem = inqueue.shift()) {
352
304
  outqueue.push(elem);
353
305
  var childIndex = void 0;
354
-
355
306
  for (childIndex = 0; childIndex < elem.childNodes.length; childIndex++) {
356
307
  var child = elem.childNodes[childIndex];
357
-
358
308
  switch (child.nodeType) {
359
309
  case Node.ELEMENT_NODE:
360
310
  case Node.TEXT_NODE:
361
311
  inqueue.push(child);
362
312
  break;
363
-
364
313
  default:
365
314
  // eslint-disable-next-line no-console
366
315
  console.error("Not pushing: ".concat(child.nodeType, " ").concat(child.nodeName));
367
316
  }
368
317
  }
369
318
  }
370
-
371
319
  outqueue.shift();
372
320
  return outqueue;
373
321
  }
322
+
374
323
  /**
375
324
  * Create a fragment by adding a set of marks to each node.
376
325
  */
377
-
378
326
  function addMarks(fragment, marks) {
379
327
  var result = fragment;
380
-
381
328
  for (var i = 0; i < fragment.childCount; i++) {
382
329
  var child = result.child(i);
383
330
  var newChild = child;
384
-
385
331
  var _iterator = _createForOfIteratorHelper(marks),
386
- _step;
387
-
332
+ _step;
388
333
  try {
389
334
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
390
335
  var mark = _step.value;
@@ -395,17 +340,13 @@ function addMarks(fragment, marks) {
395
340
  } finally {
396
341
  _iterator.f();
397
342
  }
398
-
399
343
  result = result.replaceChild(i, newChild);
400
344
  }
401
-
402
345
  return result;
403
346
  }
404
-
405
347
  function getNodeName(node) {
406
348
  return node.nodeName.toUpperCase();
407
349
  }
408
-
409
350
  function isMedia(node) {
410
351
  if (node && node instanceof HTMLElement) {
411
352
  if (node.parentNode && getNodeName(node.parentNode) === 'P') {
@@ -414,23 +355,18 @@ function isMedia(node) {
414
355
  }
415
356
  }
416
357
  }
417
-
418
358
  return false;
419
359
  }
420
-
421
360
  function isMediaSingle(node) {
422
361
  if (isMedia(node)) {
423
362
  var dataNode = node.querySelector('[data-media-services-id]');
424
-
425
363
  if (dataNode instanceof HTMLElement) {
426
364
  var width = parseInt(dataNode.getAttribute('data-width') || '', 10);
427
365
  var height = parseInt(dataNode.getAttribute('data-height') || '', 10);
428
-
429
366
  if (node.parentNode.classList.contains('mediaSingle') && width && height) {
430
367
  return true;
431
368
  }
432
369
  }
433
370
  }
434
-
435
371
  return false;
436
372
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-jira-transformer",
3
- "version": "8.2.4",
3
+ "version": "8.2.6",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-jira-transformer",
3
- "version": "8.2.4",
3
+ "version": "8.2.6",
4
4
  "description": "Editor JIRA transformer's",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -24,8 +24,8 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@atlaskit/adf-schema": "^25.0.0",
28
- "@atlaskit/editor-common": "^72.0.0",
27
+ "@atlaskit/adf-schema": "^25.5.0",
28
+ "@atlaskit/editor-common": "^73.0.0",
29
29
  "@babel/runtime": "^7.0.0",
30
30
  "collapse-whitespace": "^1.1.6",
31
31
  "prosemirror-model": "1.14.3"
@@ -36,11 +36,11 @@
36
36
  "devDependencies": {
37
37
  "@atlaskit/activity": "^1.0.1",
38
38
  "@atlaskit/docs": "*",
39
- "@atlaskit/editor-core": "^177.0.0",
39
+ "@atlaskit/editor-core": "^182.2.0",
40
40
  "@atlaskit/editor-json-transformer": "^8.8.0",
41
- "@atlaskit/editor-test-helpers": "^18.0.0",
42
- "@atlaskit/theme": "^12.2.0",
43
- "@atlaskit/util-data-test": "^17.6.0",
41
+ "@atlaskit/editor-test-helpers": "^18.2.0",
42
+ "@atlaskit/theme": "^12.4.0",
43
+ "@atlaskit/util-data-test": "^17.7.0",
44
44
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
45
45
  "@emotion/react": "^11.7.1",
46
46
  "@types/prosemirror-model": "^1.11.0",
@@ -49,7 +49,9 @@
49
49
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1",
50
50
  "techstack": {
51
51
  "@repo/internal": {
52
- "theming": "tokens",
52
+ "design-tokens": [
53
+ "color"
54
+ ],
53
55
  "deprecation": "no-deprecated-imports",
54
56
  "styling": [
55
57
  "emotion"
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
 
@@ -64,3 +65,15 @@ export interface MediaContextInfo {
64
65
  ```
65
66
 
66
67
  <!--SECTION END: Main Entry Types-->
68
+
69
+ ### Peer Dependencies
70
+
71
+ <!--SECTION START: Peer Dependencies-->
72
+
73
+ ```json
74
+ {
75
+ "react": "^16.8.0"
76
+ }
77
+ ```
78
+
79
+ <!--SECTION END: Peer Dependencies-->