@atlaskit/adf-schema 21.0.0 → 22.0.2

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 (48) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/cjs/json-schema/index.js +23 -0
  3. package/dist/cjs/schema/nodes/bodied-extension.js +1 -1
  4. package/dist/cjs/schema/nodes/doc.js +1 -1
  5. package/dist/cjs/schema/nodes/expand.js +1 -1
  6. package/dist/cjs/schema/nodes/layout-column.js +1 -1
  7. package/dist/cjs/schema/nodes/list-item.js +1 -1
  8. package/dist/cjs/schema/nodes/media-group.js +1 -1
  9. package/dist/cjs/schema/nodes/nested-expand.js +1 -1
  10. package/dist/cjs/schema/nodes/paragraph.js +24 -145
  11. package/dist/cjs/schema/nodes/tableNodes.js +2 -2
  12. package/dist/cjs/version.json +1 -1
  13. package/dist/es2019/json-schema/index.js +2 -0
  14. package/dist/es2019/schema/marks/data-consumer.js +8 -1
  15. package/dist/es2019/schema/nodes/bodied-extension.js +1 -1
  16. package/dist/es2019/schema/nodes/doc.js +1 -1
  17. package/dist/es2019/schema/nodes/expand.js +1 -1
  18. package/dist/es2019/schema/nodes/layout-column.js +1 -1
  19. package/dist/es2019/schema/nodes/list-item.js +1 -1
  20. package/dist/es2019/schema/nodes/media-group.js +1 -1
  21. package/dist/es2019/schema/nodes/nested-expand.js +1 -1
  22. package/dist/es2019/schema/nodes/paragraph.js +24 -142
  23. package/dist/es2019/schema/nodes/tableNodes.js +2 -2
  24. package/dist/es2019/version.json +1 -1
  25. package/dist/esm/json-schema/index.js +2 -0
  26. package/dist/esm/schema/marks/data-consumer.js +8 -1
  27. package/dist/esm/schema/nodes/bodied-extension.js +1 -1
  28. package/dist/esm/schema/nodes/doc.js +1 -1
  29. package/dist/esm/schema/nodes/expand.js +1 -1
  30. package/dist/esm/schema/nodes/layout-column.js +1 -1
  31. package/dist/esm/schema/nodes/list-item.js +1 -1
  32. package/dist/esm/schema/nodes/media-group.js +1 -1
  33. package/dist/esm/schema/nodes/nested-expand.js +1 -1
  34. package/dist/esm/schema/nodes/paragraph.js +24 -144
  35. package/dist/esm/schema/nodes/tableNodes.js +2 -2
  36. package/dist/esm/version.json +1 -1
  37. package/dist/json-schema/package.json +7 -0
  38. package/dist/types/json-schema/index.d.ts +2 -0
  39. package/dist/types/schema/marks/data-consumer.d.ts +8 -1
  40. package/dist/types/schema/nodes/media.d.ts +1 -1
  41. package/json-schema/package.json +7 -0
  42. package/package.json +10 -3
  43. package/schema/package.json +7 -0
  44. package/url/package.json +7 -0
  45. package/test-helpers/html-helpers.ts +0 -40
  46. package/test-helpers/matches.ts +0 -8
  47. package/test-helpers/schema-builder.ts +0 -329
  48. package/test-helpers/schema.ts +0 -80
@@ -183,7 +183,7 @@ export const tableCell = {
183
183
  content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaSingle | mediaGroup | decisionList | taskList | blockCard | embedCard | extension | nestedExpand | unsupportedBlock)+',
184
184
  attrs: cellAttrs,
185
185
  tableRole: 'cell',
186
- marks: 'link alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
186
+ marks: 'alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
187
187
  isolating: true,
188
188
  parseDOM: [// Ignore number cell copied from renderer
189
189
  {
@@ -210,7 +210,7 @@ export const tableHeader = {
210
210
  attrs: cellAttrs,
211
211
  tableRole: 'header_cell',
212
212
  isolating: true,
213
- marks: 'link alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
213
+ marks: 'alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
214
214
  parseDOM: [{
215
215
  tag: 'th',
216
216
  getAttrs: dom => getCellAttrs(dom, {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "21.0.0",
3
+ "version": "22.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ export { default as fullSchema } from '../../json-schema/v1/full.json';
2
+ export { default as stageZeroSchema } from '../../json-schema/v1/stage-0.json';
@@ -1,6 +1,13 @@
1
1
  import { isDOMElement } from '../../utils/parseDOM';
2
2
  /**
3
- * @minLength 1
3
+ * This annotation is purely for reference, & does _nothing_ given annotating
4
+ * `minLength` on an array of strings is not supported with our schema+spec
5
+ * generator.
6
+ *
7
+ * We're keeping it to signal that data consumer `sources` shouldn't be empty
8
+ * strings
9
+ *
10
+ * // @minLength 1
4
11
  */
5
12
 
6
13
  var parseDataConsumer = function parseDataConsumer(maybeValue) {
@@ -4,7 +4,7 @@ var createBodiedExtensionNodeSpec = function createBodiedExtensionNodeSpec() {
4
4
  var nodeSpec = {
5
5
  inline: false,
6
6
  group: 'block',
7
- marks: 'link dataConsumer fragment',
7
+ marks: 'dataConsumer fragment',
8
8
  content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaGroup | mediaSingle | decisionList | taskList | table | blockCard | extension | unsupportedBlock | embedCard)+',
9
9
  defining: true,
10
10
  selectable: true,
@@ -3,5 +3,5 @@
3
3
  */
4
4
  export var doc = {
5
5
  content: '(block|layoutSection)+',
6
- marks: 'alignment breakout dataConsumer fragment indentation link unsupportedMark unsupportedNodeAttribute'
6
+ marks: 'alignment breakout dataConsumer fragment indentation unsupportedMark unsupportedNodeAttribute'
7
7
  };
@@ -20,7 +20,7 @@ function getExpandAttrs(domNode) {
20
20
  export var expand = {
21
21
  inline: false,
22
22
  group: 'block',
23
- marks: 'link dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
23
+ marks: 'dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
24
24
  content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaGroup | mediaSingle | decisionList | taskList | table | blockCard | embedCard | extension | unsupportedBlock)+',
25
25
  isolating: true,
26
26
  selectable: true,
@@ -4,7 +4,7 @@
4
4
  export var layoutColumn = {
5
5
  content: '(block|unsupportedBlock)+',
6
6
  isolating: true,
7
- marks: 'link alignment indentation dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
7
+ marks: 'alignment indentation dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
8
8
  selectable: false,
9
9
  attrs: {
10
10
  width: {
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export var listItem = {
8
8
  content: '(paragraph | mediaSingle | codeBlock) (paragraph | bulletList | orderedList | mediaSingle | codeBlock)*',
9
- marks: 'link unsupportedMark unsupportedNodeAttribute',
9
+ marks: 'unsupportedMark unsupportedNodeAttribute',
10
10
  defining: true,
11
11
  selectable: false,
12
12
  parseDOM: [{
@@ -6,7 +6,7 @@ export var mediaGroup = {
6
6
  group: 'block',
7
7
  content: '(media|unsupportedBlock)+',
8
8
  attrs: {},
9
- marks: 'unsupportedMark unsupportedNodeAttribute link',
9
+ marks: 'unsupportedMark unsupportedNodeAttribute',
10
10
  selectable: false,
11
11
  parseDOM: [{
12
12
  tag: 'div[data-node-type="mediaGroup"]'
@@ -13,7 +13,7 @@
13
13
  */
14
14
  export var nestedExpand = {
15
15
  inline: false,
16
- marks: 'link unsupportedMark unsupportedNodeAttribute',
16
+ marks: 'unsupportedMark unsupportedNodeAttribute',
17
17
  content: '(paragraph | heading | mediaSingle | mediaGroup | unsupportedBlock)+',
18
18
  isolating: true,
19
19
  selectable: true,
@@ -1,68 +1,27 @@
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
-
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
+ */
66
25
  var isImageNode = function isImageNode(node) {
67
26
  return Boolean(node && node.nodeName.toLowerCase() === 'img');
68
27
  };
@@ -85,21 +44,6 @@ var hasInlineImage = function hasInlineImage(node) {
85
44
  });
86
45
  };
87
46
 
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-task-local-id])', ':not([data-task-state])', ':not([data-pm-slice])', ':not([data-mark-type])', ':not([data-layout-content])', ':not([data-panel-content])'].join('');
103
47
  var pDOM = ['p', 0];
104
48
  export var paragraph = {
105
49
  selectable: false,
@@ -108,70 +52,6 @@ export var paragraph = {
108
52
  marks: 'strong code em link strike subsup textColor typeAheadQuery underline confluenceInlineComment action annotation unsupportedMark unsupportedNodeAttribute dataConsumer fragment',
109
53
  parseDOM: [{
110
54
  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
175
55
  }],
176
56
  toDOM: function toDOM() {
177
57
  return pDOM;
@@ -189,7 +189,7 @@ export var tableCell = {
189
189
  content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaSingle | mediaGroup | decisionList | taskList | blockCard | embedCard | extension | nestedExpand | unsupportedBlock)+',
190
190
  attrs: cellAttrs,
191
191
  tableRole: 'cell',
192
- marks: 'link alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
192
+ marks: 'alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
193
193
  isolating: true,
194
194
  parseDOM: [// Ignore number cell copied from renderer
195
195
  {
@@ -222,7 +222,7 @@ export var tableHeader = {
222
222
  attrs: cellAttrs,
223
223
  tableRole: 'header_cell',
224
224
  isolating: true,
225
- marks: 'link alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
225
+ marks: 'alignment dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
226
226
  parseDOM: [{
227
227
  tag: 'th',
228
228
  getAttrs: function getAttrs(dom) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "21.0.0",
3
+ "version": "22.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/adf-schema/json-schema",
3
+ "main": "../dist/cjs/json-schema/index.js",
4
+ "module": "../dist/esm/json-schema/index.js",
5
+ "module:es2019": "../dist/es2019/json-schema/index.js",
6
+ "types": "../dist/types/json-schema/index.d.ts"
7
+ }
@@ -0,0 +1,2 @@
1
+ export { default as fullSchema } from '../../json-schema/v1/full.json';
2
+ export { default as stageZeroSchema } from '../../json-schema/v1/stage-0.json';
@@ -1,6 +1,13 @@
1
1
  import { Mark, MarkSpec } from 'prosemirror-model';
2
2
  /**
3
- * @minLength 1
3
+ * This annotation is purely for reference, & does _nothing_ given annotating
4
+ * `minLength` on an array of strings is not supported with our schema+spec
5
+ * generator.
6
+ *
7
+ * We're keeping it to signal that data consumer `sources` shouldn't be empty
8
+ * strings
9
+ *
10
+ * // @minLength 1
4
11
  */
5
12
  declare type DataConsumerSource = string;
6
13
  export interface DataConsumerAttributes {
@@ -35,7 +35,7 @@ export interface MediaBaseAttributes {
35
35
  __fileSize?: number | null;
36
36
  __fileMimeType?: string | null;
37
37
  __displayType?: DisplayType | null;
38
- __contextId?: string;
38
+ __contextId?: string | null;
39
39
  __external?: boolean;
40
40
  }
41
41
  export interface MediaAttributes extends MediaBaseAttributes {
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/adf-schema/json-schema",
3
+ "main": "../dist/cjs/json-schema/index.js",
4
+ "module": "../dist/esm/json-schema/index.js",
5
+ "module:es2019": "../dist/es2019/json-schema/index.js",
6
+ "types": "../dist/types/json-schema/index.d.ts"
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "21.0.0",
3
+ "version": "22.0.2",
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/"
@@ -16,10 +16,16 @@
16
16
  "atlaskit:src": "src/index.ts",
17
17
  "atlassian": {
18
18
  "team": "Editor",
19
- "deprecatedAutoEntryPoints": true,
20
19
  "inPublicMirror": true,
21
20
  "releaseModel": "scheduled"
22
21
  },
22
+ "af:exports": {
23
+ ".": "./src/index.ts",
24
+ "./steps": "./src/steps.ts",
25
+ "./schema": "./src/schema/index.ts",
26
+ "./json-schema": "./src/json-schema/index.ts",
27
+ "./url": "./src/utils/url.ts"
28
+ },
23
29
  "scripts": {
24
30
  "build:json-schema": "mkdir -p dist && cp -r json-schema dist",
25
31
  "generate:json-schema": "mkdir -p json-schema/v1/ && yarn generate:json-schema:full && yarn generate:json-schema:stage-0",
@@ -40,8 +46,9 @@
40
46
  "prosemirror-transform": "1.3.2"
41
47
  },
42
48
  "devDependencies": {
49
+ "@atlaskit/adf-utils": "^16.0.0",
43
50
  "@atlaskit/editor-json-transformer": "^8.7.0",
44
- "@atlaskit/editor-test-helpers": "^16.0.0",
51
+ "@atlaskit/editor-test-helpers": "^16.1.0",
45
52
  "@atlaskit/json-schema-generator": "^3.2.0",
46
53
  "@atlassian/adf-sample": "^1.0.0",
47
54
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/adf-schema/schema",
3
+ "main": "../dist/cjs/schema/index.js",
4
+ "module": "../dist/esm/schema/index.js",
5
+ "module:es2019": "../dist/es2019/schema/index.js",
6
+ "types": "../dist/types/schema/index.d.ts"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/adf-schema/url",
3
+ "main": "../dist/cjs/utils/url.js",
4
+ "module": "../dist/esm/utils/url.js",
5
+ "module:es2019": "../dist/es2019/utils/url.js",
6
+ "types": "../dist/types/utils/url.d.ts"
7
+ }
@@ -1,40 +0,0 @@
1
- import {
2
- DOMParser,
3
- DOMSerializer,
4
- Fragment,
5
- Schema,
6
- Node as PMNode,
7
- ParseOptions,
8
- } from 'prosemirror-model';
9
- import { DocBuilder } from '@atlaskit/editor-test-helpers/doc-builder';
10
- import { TextSelection } from 'prosemirror-state';
11
-
12
- export const fromHTML = (
13
- html: string,
14
- schema: Schema,
15
- options?: ParseOptions,
16
- ): PMNode => {
17
- const el = document.createElement('div');
18
- el.innerHTML = html;
19
-
20
- return DOMParser.fromSchema(schema).parse(el, options);
21
- };
22
-
23
- export const toDOM = (node: PMNode, schema: Schema): Node => {
24
- const serializer = DOMSerializer.fromSchema(schema);
25
- return serializer.serializeFragment(Fragment.from(node));
26
- };
27
-
28
- export const toContext = (node: DocBuilder, schema: Schema) => {
29
- const document = node(schema);
30
- const selection = TextSelection.near(
31
- document.resolve(document.refs['<>'] || 0),
32
- );
33
- return selection.$from;
34
- };
35
-
36
- export const toHTML = (node: PMNode, schema: Schema): string => {
37
- const el = document.createElement('div');
38
- el.appendChild(toDOM(node, schema));
39
- return el.innerHTML;
40
- };
@@ -1,8 +0,0 @@
1
- export default (text: string, regexp: RegExp) => {
2
- const results: RegExpExecArray[] = [];
3
- let match: RegExpExecArray | null;
4
- while ((match = regexp.exec(text))) {
5
- results.push(match);
6
- }
7
- return results;
8
- };