@atlaskit/adf-schema 19.2.3 → 19.2.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.
@@ -9,8 +9,6 @@ exports.toJSON = exports.link = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
12
- var _prosemirrorModel = require("prosemirror-model");
13
-
14
12
  var _groups = require("../groups");
15
13
 
16
14
  var _url = require("../../utils/url");
@@ -37,32 +35,6 @@ var getLinkAttrs = function getLinkAttrs(attribute) {
37
35
  };
38
36
  };
39
37
 
40
- var getLinkAttrsWithCheck = function getLinkAttrsWithCheck(attribute) {
41
- return function (domNode) {
42
- var dom = domNode;
43
- var hasTextOnlyChildren = Array.from(dom.childNodes).every(function (node) {
44
- return node.nodeType === Node.TEXT_NODE || node.nodeName === 'SPAN';
45
- });
46
-
47
- if (hasTextOnlyChildren) {
48
- var href = dom.getAttribute(attribute) || '';
49
- var attrs = {
50
- __confluenceMetadata: dom.hasAttribute('__confluenceMetadata') ? JSON.parse(dom.getAttribute('__confluenceMetadata') || '') : undefined
51
- };
52
-
53
- if ((0, _url.isSafeUrl)(href)) {
54
- attrs.href = (0, _url.normalizeUrl)(href);
55
- } else {
56
- return false;
57
- }
58
-
59
- return attrs;
60
- }
61
-
62
- return false;
63
- };
64
- };
65
-
66
38
  var link = {
67
39
  excludes: "".concat(_groups.LINK, " ").concat(_groups.COLOR),
68
40
  // ED-5844 No multiple links in media node
@@ -80,39 +52,14 @@ var link = {
80
52
  contentElement: function contentElement(node) {
81
53
  var clone = node.cloneNode(true);
82
54
  clone.removeAttribute('data-block-link');
55
+ clone.setAttribute('data-skip-paste', 'true');
83
56
  var wrapper = document.createElement('div');
84
57
  wrapper.appendChild(clone);
85
58
  return wrapper;
86
59
  }
87
60
  }, {
88
61
  tag: 'a[href]',
89
- context: 'mediaSingle/|taskItem/|decisionItem/',
90
62
  getAttrs: getLinkAttrs('href')
91
- }, {
92
- tag: 'a[href]',
93
- getAttrs: getLinkAttrsWithCheck('href')
94
- }, {
95
- /**
96
- * When links aren't wrapped in a paragraph and due to
97
- * the odd nature of how our schema is set up, prosemirror will
98
- * add the link to the paragraph node itself where it should be on
99
- * the text node, this satisfies our schema because link is allowed
100
- * in many places (e.g. listitem)
101
- * This change comes through via prosemirror-model@1.9.1
102
- */
103
- tag: 'a[href]',
104
- getAttrs: getLinkAttrsWithCheck('href'),
105
- getContent: function getContent(node, schema) {
106
- if (node instanceof HTMLAnchorElement) {
107
- var href = node.getAttribute('href');
108
- var text = node.innerText;
109
- return _prosemirrorModel.Fragment.from(schema.nodes.paragraph.createChecked(undefined, schema.text(text, [schema.marks.link.create({
110
- href: href
111
- })])));
112
- }
113
-
114
- return _prosemirrorModel.Fragment.empty;
115
- }
116
63
  }],
117
64
  toDOM: function toDOM(node, isInline) {
118
65
  var attrs = Object.keys(node.attrs).reduce(function (attrs, key) {
@@ -5,30 +5,109 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.paragraph = void 0;
7
7
 
8
- /**
9
- * @name paragraph_node
10
- */
11
-
12
- /**
13
- * @name paragraph_with_no_marks_node
14
- */
15
-
16
- /**
17
- * NOTE: Need this because TS is too smart and inline everything.
18
- * So we need to give them separate identity.
19
- * Probably there's a way to solve it but that will need time and exploration.
20
- * // http://bit.ly/2raXFX5
21
- * type T1 = X | Y
22
- * type T2 = A | T1 | B // T2 = A | X | Y | B
23
- */
24
-
25
- /**
26
- * @name paragraph_with_alignment_node
27
- */
28
-
29
- /**
30
- * @name paragraph_with_indentation_node
31
- */
8
+ var _prosemirrorModel = require("prosemirror-model");
9
+
10
+ var _url = require("../../utils/url");
11
+
12
+ var getLinkContent = function getLinkContent(node, schema) {
13
+ if (!(node instanceof HTMLAnchorElement)) {
14
+ return _prosemirrorModel.Fragment.empty;
15
+ }
16
+
17
+ var href = node.getAttribute('href') || '';
18
+ var text = node.innerText;
19
+
20
+ if (!text || text.length === 0) {
21
+ return _prosemirrorModel.Fragment.empty;
22
+ }
23
+
24
+ var marks = (0, _url.isSafeUrl)(href) ? [schema.marks.link.create({
25
+ href: href
26
+ })] : [];
27
+ var textNode = schema.text(text, marks);
28
+ return _prosemirrorModel.Fragment.from(textNode);
29
+ };
30
+
31
+ var blockTags = {
32
+ address: true,
33
+ article: true,
34
+ aside: true,
35
+ blockquote: true,
36
+ canvas: true,
37
+ dd: true,
38
+ div: true,
39
+ dl: true,
40
+ fieldset: true,
41
+ figcaption: true,
42
+ figure: true,
43
+ footer: true,
44
+ form: true,
45
+ h1: true,
46
+ h2: true,
47
+ h3: true,
48
+ h4: true,
49
+ h5: true,
50
+ h6: true,
51
+ header: true,
52
+ hgroup: true,
53
+ hr: true,
54
+ li: true,
55
+ noscript: true,
56
+ ol: true,
57
+ output: true,
58
+ p: true,
59
+ pre: true,
60
+ section: true,
61
+ table: true,
62
+ tfoot: true,
63
+ ul: true
64
+ };
65
+
66
+ var isListItemNode = function isListItemNode(node) {
67
+ return Boolean(node && node.nodeName.toLowerCase() === 'li');
68
+ };
69
+
70
+ var isTextNode = function isTextNode(node) {
71
+ return Boolean(node && node.nodeType === Node.TEXT_NODE);
72
+ };
73
+
74
+ var isImageNode = function isImageNode(node) {
75
+ return Boolean(node && node.nodeName.toLowerCase() === 'img');
76
+ };
77
+
78
+ var hasInlineImage = function hasInlineImage(node) {
79
+ if (!node) {
80
+ return false;
81
+ }
82
+
83
+ return Array.from(node.childNodes).some(function (child) {
84
+ var isImage = isImageNode(child);
85
+
86
+ if (!isImage && child.childNodes) {
87
+ return Array.from(node.childNodes).some(function (node) {
88
+ return hasInlineImage(node);
89
+ });
90
+ }
91
+
92
+ return isImage;
93
+ });
94
+ };
95
+
96
+ var hasWhiteSpacePre = function hasWhiteSpacePre(node) {
97
+ return Boolean(node instanceof HTMLElement && node.style.whiteSpace === 'pre');
98
+ };
99
+
100
+ var hasFontFamilyMonospace = function hasFontFamilyMonospace(node) {
101
+ return Boolean(node instanceof HTMLElement && node.style.fontFamily.includes('monospace'));
102
+ };
103
+
104
+ var isBlockLevelNode = function isBlockLevelNode(node) {
105
+ return Boolean(node && blockTags.hasOwnProperty(node.nodeName.toLowerCase()));
106
+ };
107
+
108
+ var NOT_INTERNAL_LINKS = [':not([data-inline-card])', ':not([data-block-card])', ':not([data-block-link])', ':not([data-skip-paste])'].join('');
109
+ var ANCHOR_LINK = "a[href]".concat(NOT_INTERNAL_LINKS);
110
+ var NOT_INTERNAL_ELEMENTS = [':not(.code-block)', ':not([data-node-type])', ':not([data-embed-card])', ':not([data-layout-section])', ':not([data-pm-slice])', ':not([data-mark-type])'].join('');
32
111
  var pDOM = ['p', 0];
33
112
  var paragraph = {
34
113
  selectable: false,
@@ -37,6 +116,70 @@ var paragraph = {
37
116
  marks: 'strong code em link strike subsup textColor typeAheadQuery underline confluenceInlineComment action annotation unsupportedMark unsupportedNodeAttribute dataConsumer',
38
117
  parseDOM: [{
39
118
  tag: 'p'
119
+ }, {
120
+ tag: "div".concat(NOT_INTERNAL_ELEMENTS, ", li:not([data-pm-slice])"),
121
+ priority: 100,
122
+ getAttrs: function getAttrs(node) {
123
+ if (!(node instanceof Node)) {
124
+ return false;
125
+ }
126
+
127
+ var isCodeBlock = hasWhiteSpacePre(node) || hasFontFamilyMonospace(node);
128
+
129
+ if (isCodeBlock || !node.hasChildNodes()) {
130
+ return false;
131
+ }
132
+
133
+ var hasInlineChildren = Array.from(node.childNodes).every(function (child) {
134
+ return !isBlockLevelNode(child) && // IMG is considered block for mediaSingle
135
+ !isImageNode(child);
136
+ });
137
+
138
+ if (!hasInlineChildren) {
139
+ return false;
140
+ }
141
+
142
+ if ( // We can skip this rule for pure list items
143
+ isListItemNode(node) && Array.from(node.childNodes).every(isTextNode)) {
144
+ return false;
145
+ }
146
+
147
+ return null;
148
+ }
149
+ }, {
150
+ tag: ":not(span) + ".concat(ANCHOR_LINK),
151
+ priority: 100,
152
+ getContent: getLinkContent
153
+ }, {
154
+ tag: ":not(span) > ".concat(ANCHOR_LINK, ":first-child"),
155
+ getAttrs: function getAttrs(node) {
156
+ if (!(node instanceof Node)) {
157
+ return false;
158
+ }
159
+
160
+ if (isBlockLevelNode(node.firstChild)) {
161
+ return null;
162
+ }
163
+
164
+ if (hasInlineImage(node)) {
165
+ return false;
166
+ }
167
+
168
+ var isNextSiblingValid = node.nextSibling === null || node.nextSibling instanceof Text && (node.nextSibling.textContent || '').trim().length === 0;
169
+
170
+ if (isNextSiblingValid) {
171
+ return null;
172
+ } // This rule should not match when there is any sibling after the anchor
173
+
174
+
175
+ if (!isBlockLevelNode(node.nextSibling)) {
176
+ return false;
177
+ }
178
+
179
+ return null;
180
+ },
181
+ priority: 100,
182
+ getContent: getLinkContent
40
183
  }],
41
184
  toDOM: function toDOM() {
42
185
  return pDOM;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "19.2.3",
3
+ "version": "19.2.4",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,3 @@
1
- import { Fragment } from 'prosemirror-model';
2
1
  import { LINK, COLOR } from '../groups';
3
2
  import { isSafeUrl, normalizeUrl } from '../../utils/url';
4
3
 
@@ -18,28 +17,6 @@ const getLinkAttrs = attribute => domNode => {
18
17
  return attrs;
19
18
  };
20
19
 
21
- const getLinkAttrsWithCheck = attribute => domNode => {
22
- const dom = domNode;
23
- const hasTextOnlyChildren = Array.from(dom.childNodes).every(node => node.nodeType === Node.TEXT_NODE || node.nodeName === 'SPAN');
24
-
25
- if (hasTextOnlyChildren) {
26
- const href = dom.getAttribute(attribute) || '';
27
- const attrs = {
28
- __confluenceMetadata: dom.hasAttribute('__confluenceMetadata') ? JSON.parse(dom.getAttribute('__confluenceMetadata') || '') : undefined
29
- };
30
-
31
- if (isSafeUrl(href)) {
32
- attrs.href = normalizeUrl(href);
33
- } else {
34
- return false;
35
- }
36
-
37
- return attrs;
38
- }
39
-
40
- return false;
41
- };
42
-
43
20
  export const link = {
44
21
  excludes: `${LINK} ${COLOR}`,
45
22
  // ED-5844 No multiple links in media node
@@ -57,39 +34,14 @@ export const link = {
57
34
  contentElement: node => {
58
35
  const clone = node.cloneNode(true);
59
36
  clone.removeAttribute('data-block-link');
37
+ clone.setAttribute('data-skip-paste', 'true');
60
38
  const wrapper = document.createElement('div');
61
39
  wrapper.appendChild(clone);
62
40
  return wrapper;
63
41
  }
64
42
  }, {
65
43
  tag: 'a[href]',
66
- context: 'mediaSingle/|taskItem/|decisionItem/',
67
44
  getAttrs: getLinkAttrs('href')
68
- }, {
69
- tag: 'a[href]',
70
- getAttrs: getLinkAttrsWithCheck('href')
71
- }, {
72
- /**
73
- * When links aren't wrapped in a paragraph and due to
74
- * the odd nature of how our schema is set up, prosemirror will
75
- * add the link to the paragraph node itself where it should be on
76
- * the text node, this satisfies our schema because link is allowed
77
- * in many places (e.g. listitem)
78
- * This change comes through via prosemirror-model@1.9.1
79
- */
80
- tag: 'a[href]',
81
- getAttrs: getLinkAttrsWithCheck('href'),
82
- getContent: (node, schema) => {
83
- if (node instanceof HTMLAnchorElement) {
84
- const href = node.getAttribute('href');
85
- const text = node.innerText;
86
- return Fragment.from(schema.nodes.paragraph.createChecked(undefined, schema.text(text, [schema.marks.link.create({
87
- href
88
- })])));
89
- }
90
-
91
- return Fragment.empty;
92
- }
93
45
  }],
94
46
 
95
47
  toDOM(node, isInline) {
@@ -1,27 +1,103 @@
1
- /**
2
- * @name paragraph_node
3
- */
4
-
5
- /**
6
- * @name paragraph_with_no_marks_node
7
- */
8
-
9
- /**
10
- * NOTE: Need this because TS is too smart and inline everything.
11
- * So we need to give them separate identity.
12
- * Probably there's a way to solve it but that will need time and exploration.
13
- * // http://bit.ly/2raXFX5
14
- * type T1 = X | Y
15
- * type T2 = A | T1 | B // T2 = A | X | Y | B
16
- */
17
-
18
- /**
19
- * @name paragraph_with_alignment_node
20
- */
21
-
22
- /**
23
- * @name paragraph_with_indentation_node
24
- */
1
+ import { Fragment } from 'prosemirror-model';
2
+ import { isSafeUrl } from '../../utils/url';
3
+
4
+ const getLinkContent = (node, schema) => {
5
+ if (!(node instanceof HTMLAnchorElement)) {
6
+ return Fragment.empty;
7
+ }
8
+
9
+ const href = node.getAttribute('href') || '';
10
+ const text = node.innerText;
11
+
12
+ if (!text || text.length === 0) {
13
+ return Fragment.empty;
14
+ }
15
+
16
+ const marks = isSafeUrl(href) ? [schema.marks.link.create({
17
+ href
18
+ })] : [];
19
+ const textNode = schema.text(text, marks);
20
+ return Fragment.from(textNode);
21
+ };
22
+
23
+ const blockTags = {
24
+ address: true,
25
+ article: true,
26
+ aside: true,
27
+ blockquote: true,
28
+ canvas: true,
29
+ dd: true,
30
+ div: true,
31
+ dl: true,
32
+ fieldset: true,
33
+ figcaption: true,
34
+ figure: true,
35
+ footer: true,
36
+ form: true,
37
+ h1: true,
38
+ h2: true,
39
+ h3: true,
40
+ h4: true,
41
+ h5: true,
42
+ h6: true,
43
+ header: true,
44
+ hgroup: true,
45
+ hr: true,
46
+ li: true,
47
+ noscript: true,
48
+ ol: true,
49
+ output: true,
50
+ p: true,
51
+ pre: true,
52
+ section: true,
53
+ table: true,
54
+ tfoot: true,
55
+ ul: true
56
+ };
57
+
58
+ const isListItemNode = node => {
59
+ return Boolean(node && node.nodeName.toLowerCase() === 'li');
60
+ };
61
+
62
+ const isTextNode = node => {
63
+ return Boolean(node && node.nodeType === Node.TEXT_NODE);
64
+ };
65
+
66
+ const isImageNode = node => {
67
+ return Boolean(node && node.nodeName.toLowerCase() === 'img');
68
+ };
69
+
70
+ const hasInlineImage = node => {
71
+ if (!node) {
72
+ return false;
73
+ }
74
+
75
+ return Array.from(node.childNodes).some(child => {
76
+ const isImage = isImageNode(child);
77
+
78
+ if (!isImage && child.childNodes) {
79
+ return Array.from(node.childNodes).some(node => hasInlineImage(node));
80
+ }
81
+
82
+ return isImage;
83
+ });
84
+ };
85
+
86
+ const hasWhiteSpacePre = node => {
87
+ return Boolean(node instanceof HTMLElement && node.style.whiteSpace === 'pre');
88
+ };
89
+
90
+ const hasFontFamilyMonospace = node => {
91
+ return Boolean(node instanceof HTMLElement && node.style.fontFamily.includes('monospace'));
92
+ };
93
+
94
+ const isBlockLevelNode = node => {
95
+ return Boolean(node && blockTags.hasOwnProperty(node.nodeName.toLowerCase()));
96
+ };
97
+
98
+ const NOT_INTERNAL_LINKS = [':not([data-inline-card])', ':not([data-block-card])', ':not([data-block-link])', ':not([data-skip-paste])'].join('');
99
+ const ANCHOR_LINK = `a[href]${NOT_INTERNAL_LINKS}`;
100
+ const NOT_INTERNAL_ELEMENTS = [':not(.code-block)', ':not([data-node-type])', ':not([data-embed-card])', ':not([data-layout-section])', ':not([data-pm-slice])', ':not([data-mark-type])'].join('');
25
101
  const pDOM = ['p', 0];
26
102
  export const paragraph = {
27
103
  selectable: false,
@@ -30,6 +106,68 @@ export const paragraph = {
30
106
  marks: 'strong code em link strike subsup textColor typeAheadQuery underline confluenceInlineComment action annotation unsupportedMark unsupportedNodeAttribute dataConsumer',
31
107
  parseDOM: [{
32
108
  tag: 'p'
109
+ }, {
110
+ tag: `div${NOT_INTERNAL_ELEMENTS}, li:not([data-pm-slice])`,
111
+ priority: 100,
112
+ getAttrs: node => {
113
+ if (!(node instanceof Node)) {
114
+ return false;
115
+ }
116
+
117
+ const isCodeBlock = hasWhiteSpacePre(node) || hasFontFamilyMonospace(node);
118
+
119
+ if (isCodeBlock || !node.hasChildNodes()) {
120
+ return false;
121
+ }
122
+
123
+ const hasInlineChildren = Array.from(node.childNodes).every(child => !isBlockLevelNode(child) && // IMG is considered block for mediaSingle
124
+ !isImageNode(child));
125
+
126
+ if (!hasInlineChildren) {
127
+ return false;
128
+ }
129
+
130
+ if ( // We can skip this rule for pure list items
131
+ isListItemNode(node) && Array.from(node.childNodes).every(isTextNode)) {
132
+ return false;
133
+ }
134
+
135
+ return null;
136
+ }
137
+ }, {
138
+ tag: `:not(span) + ${ANCHOR_LINK}`,
139
+ priority: 100,
140
+ getContent: getLinkContent
141
+ }, {
142
+ tag: `:not(span) > ${ANCHOR_LINK}:first-child`,
143
+ getAttrs: node => {
144
+ if (!(node instanceof Node)) {
145
+ return false;
146
+ }
147
+
148
+ if (isBlockLevelNode(node.firstChild)) {
149
+ return null;
150
+ }
151
+
152
+ if (hasInlineImage(node)) {
153
+ return false;
154
+ }
155
+
156
+ const isNextSiblingValid = node.nextSibling === null || node.nextSibling instanceof Text && (node.nextSibling.textContent || '').trim().length === 0;
157
+
158
+ if (isNextSiblingValid) {
159
+ return null;
160
+ } // This rule should not match when there is any sibling after the anchor
161
+
162
+
163
+ if (!isBlockLevelNode(node.nextSibling)) {
164
+ return false;
165
+ }
166
+
167
+ return null;
168
+ },
169
+ priority: 100,
170
+ getContent: getLinkContent
33
171
  }],
34
172
 
35
173
  toDOM() {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "19.2.3",
3
+ "version": "19.2.4",
4
4
  "sideEffects": false
5
5
  }
@@ -4,7 +4,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
4
4
 
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
6
 
7
- import { Fragment } from 'prosemirror-model';
8
7
  import { LINK, COLOR } from '../groups';
9
8
  import { isSafeUrl, normalizeUrl } from '../../utils/url';
10
9
 
@@ -26,32 +25,6 @@ var getLinkAttrs = function getLinkAttrs(attribute) {
26
25
  };
27
26
  };
28
27
 
29
- var getLinkAttrsWithCheck = function getLinkAttrsWithCheck(attribute) {
30
- return function (domNode) {
31
- var dom = domNode;
32
- var hasTextOnlyChildren = Array.from(dom.childNodes).every(function (node) {
33
- return node.nodeType === Node.TEXT_NODE || node.nodeName === 'SPAN';
34
- });
35
-
36
- if (hasTextOnlyChildren) {
37
- var href = dom.getAttribute(attribute) || '';
38
- var attrs = {
39
- __confluenceMetadata: dom.hasAttribute('__confluenceMetadata') ? JSON.parse(dom.getAttribute('__confluenceMetadata') || '') : undefined
40
- };
41
-
42
- if (isSafeUrl(href)) {
43
- attrs.href = normalizeUrl(href);
44
- } else {
45
- return false;
46
- }
47
-
48
- return attrs;
49
- }
50
-
51
- return false;
52
- };
53
- };
54
-
55
28
  export var link = {
56
29
  excludes: "".concat(LINK, " ").concat(COLOR),
57
30
  // ED-5844 No multiple links in media node
@@ -69,39 +42,14 @@ export var link = {
69
42
  contentElement: function contentElement(node) {
70
43
  var clone = node.cloneNode(true);
71
44
  clone.removeAttribute('data-block-link');
45
+ clone.setAttribute('data-skip-paste', 'true');
72
46
  var wrapper = document.createElement('div');
73
47
  wrapper.appendChild(clone);
74
48
  return wrapper;
75
49
  }
76
50
  }, {
77
51
  tag: 'a[href]',
78
- context: 'mediaSingle/|taskItem/|decisionItem/',
79
52
  getAttrs: getLinkAttrs('href')
80
- }, {
81
- tag: 'a[href]',
82
- getAttrs: getLinkAttrsWithCheck('href')
83
- }, {
84
- /**
85
- * When links aren't wrapped in a paragraph and due to
86
- * the odd nature of how our schema is set up, prosemirror will
87
- * add the link to the paragraph node itself where it should be on
88
- * the text node, this satisfies our schema because link is allowed
89
- * in many places (e.g. listitem)
90
- * This change comes through via prosemirror-model@1.9.1
91
- */
92
- tag: 'a[href]',
93
- getAttrs: getLinkAttrsWithCheck('href'),
94
- getContent: function getContent(node, schema) {
95
- if (node instanceof HTMLAnchorElement) {
96
- var href = node.getAttribute('href');
97
- var text = node.innerText;
98
- return Fragment.from(schema.nodes.paragraph.createChecked(undefined, schema.text(text, [schema.marks.link.create({
99
- href: href
100
- })])));
101
- }
102
-
103
- return Fragment.empty;
104
- }
105
53
  }],
106
54
  toDOM: function toDOM(node, isInline) {
107
55
  var attrs = Object.keys(node.attrs).reduce(function (attrs, key) {
@@ -1,27 +1,105 @@
1
- /**
2
- * @name paragraph_node
3
- */
4
-
5
- /**
6
- * @name paragraph_with_no_marks_node
7
- */
8
-
9
- /**
10
- * NOTE: Need this because TS is too smart and inline everything.
11
- * So we need to give them separate identity.
12
- * Probably there's a way to solve it but that will need time and exploration.
13
- * // http://bit.ly/2raXFX5
14
- * type T1 = X | Y
15
- * type T2 = A | T1 | B // T2 = A | X | Y | B
16
- */
17
-
18
- /**
19
- * @name paragraph_with_alignment_node
20
- */
21
-
22
- /**
23
- * @name paragraph_with_indentation_node
24
- */
1
+ import { Fragment } from 'prosemirror-model';
2
+ import { isSafeUrl } from '../../utils/url';
3
+
4
+ var getLinkContent = function getLinkContent(node, schema) {
5
+ if (!(node instanceof HTMLAnchorElement)) {
6
+ return Fragment.empty;
7
+ }
8
+
9
+ var href = node.getAttribute('href') || '';
10
+ var text = node.innerText;
11
+
12
+ if (!text || text.length === 0) {
13
+ return Fragment.empty;
14
+ }
15
+
16
+ var marks = isSafeUrl(href) ? [schema.marks.link.create({
17
+ href: href
18
+ })] : [];
19
+ var textNode = schema.text(text, marks);
20
+ return Fragment.from(textNode);
21
+ };
22
+
23
+ var blockTags = {
24
+ address: true,
25
+ article: true,
26
+ aside: true,
27
+ blockquote: true,
28
+ canvas: true,
29
+ dd: true,
30
+ div: true,
31
+ dl: true,
32
+ fieldset: true,
33
+ figcaption: true,
34
+ figure: true,
35
+ footer: true,
36
+ form: true,
37
+ h1: true,
38
+ h2: true,
39
+ h3: true,
40
+ h4: true,
41
+ h5: true,
42
+ h6: true,
43
+ header: true,
44
+ hgroup: true,
45
+ hr: true,
46
+ li: true,
47
+ noscript: true,
48
+ ol: true,
49
+ output: true,
50
+ p: true,
51
+ pre: true,
52
+ section: true,
53
+ table: true,
54
+ tfoot: true,
55
+ ul: true
56
+ };
57
+
58
+ var isListItemNode = function isListItemNode(node) {
59
+ return Boolean(node && node.nodeName.toLowerCase() === 'li');
60
+ };
61
+
62
+ var isTextNode = function isTextNode(node) {
63
+ return Boolean(node && node.nodeType === Node.TEXT_NODE);
64
+ };
65
+
66
+ var isImageNode = function isImageNode(node) {
67
+ return Boolean(node && node.nodeName.toLowerCase() === 'img');
68
+ };
69
+
70
+ var hasInlineImage = function hasInlineImage(node) {
71
+ if (!node) {
72
+ return false;
73
+ }
74
+
75
+ return Array.from(node.childNodes).some(function (child) {
76
+ var isImage = isImageNode(child);
77
+
78
+ if (!isImage && child.childNodes) {
79
+ return Array.from(node.childNodes).some(function (node) {
80
+ return hasInlineImage(node);
81
+ });
82
+ }
83
+
84
+ return isImage;
85
+ });
86
+ };
87
+
88
+ var hasWhiteSpacePre = function hasWhiteSpacePre(node) {
89
+ return Boolean(node instanceof HTMLElement && node.style.whiteSpace === 'pre');
90
+ };
91
+
92
+ var hasFontFamilyMonospace = function hasFontFamilyMonospace(node) {
93
+ return Boolean(node instanceof HTMLElement && node.style.fontFamily.includes('monospace'));
94
+ };
95
+
96
+ var isBlockLevelNode = function isBlockLevelNode(node) {
97
+ return Boolean(node && blockTags.hasOwnProperty(node.nodeName.toLowerCase()));
98
+ };
99
+
100
+ var NOT_INTERNAL_LINKS = [':not([data-inline-card])', ':not([data-block-card])', ':not([data-block-link])', ':not([data-skip-paste])'].join('');
101
+ var ANCHOR_LINK = "a[href]".concat(NOT_INTERNAL_LINKS);
102
+ var NOT_INTERNAL_ELEMENTS = [':not(.code-block)', ':not([data-node-type])', ':not([data-embed-card])', ':not([data-layout-section])', ':not([data-pm-slice])', ':not([data-mark-type])'].join('');
25
103
  var pDOM = ['p', 0];
26
104
  export var paragraph = {
27
105
  selectable: false,
@@ -30,6 +108,70 @@ export var paragraph = {
30
108
  marks: 'strong code em link strike subsup textColor typeAheadQuery underline confluenceInlineComment action annotation unsupportedMark unsupportedNodeAttribute dataConsumer',
31
109
  parseDOM: [{
32
110
  tag: 'p'
111
+ }, {
112
+ tag: "div".concat(NOT_INTERNAL_ELEMENTS, ", li:not([data-pm-slice])"),
113
+ priority: 100,
114
+ getAttrs: function getAttrs(node) {
115
+ if (!(node instanceof Node)) {
116
+ return false;
117
+ }
118
+
119
+ var isCodeBlock = hasWhiteSpacePre(node) || hasFontFamilyMonospace(node);
120
+
121
+ if (isCodeBlock || !node.hasChildNodes()) {
122
+ return false;
123
+ }
124
+
125
+ var hasInlineChildren = Array.from(node.childNodes).every(function (child) {
126
+ return !isBlockLevelNode(child) && // IMG is considered block for mediaSingle
127
+ !isImageNode(child);
128
+ });
129
+
130
+ if (!hasInlineChildren) {
131
+ return false;
132
+ }
133
+
134
+ if ( // We can skip this rule for pure list items
135
+ isListItemNode(node) && Array.from(node.childNodes).every(isTextNode)) {
136
+ return false;
137
+ }
138
+
139
+ return null;
140
+ }
141
+ }, {
142
+ tag: ":not(span) + ".concat(ANCHOR_LINK),
143
+ priority: 100,
144
+ getContent: getLinkContent
145
+ }, {
146
+ tag: ":not(span) > ".concat(ANCHOR_LINK, ":first-child"),
147
+ getAttrs: function getAttrs(node) {
148
+ if (!(node instanceof Node)) {
149
+ return false;
150
+ }
151
+
152
+ if (isBlockLevelNode(node.firstChild)) {
153
+ return null;
154
+ }
155
+
156
+ if (hasInlineImage(node)) {
157
+ return false;
158
+ }
159
+
160
+ var isNextSiblingValid = node.nextSibling === null || node.nextSibling instanceof Text && (node.nextSibling.textContent || '').trim().length === 0;
161
+
162
+ if (isNextSiblingValid) {
163
+ return null;
164
+ } // This rule should not match when there is any sibling after the anchor
165
+
166
+
167
+ if (!isBlockLevelNode(node.nextSibling)) {
168
+ return false;
169
+ }
170
+
171
+ return null;
172
+ },
173
+ priority: 100,
174
+ getContent: getLinkContent
33
175
  }],
34
176
  toDOM: function toDOM() {
35
177
  return pDOM;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "19.2.3",
3
+ "version": "19.2.4",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "19.2.3",
3
+ "version": "19.2.4",
4
4
  "description": "Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"