@atlaskit/adf-schema 36.14.0 → 36.14.1

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 (65) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/next-schema/full-schema.adf.js +3 -2
  3. package/dist/cjs/next-schema/generated/markTypes.js +23 -23
  4. package/dist/cjs/next-schema/generated/nodeTypes.js +135 -202
  5. package/dist/cjs/next-schema/groups/blockGroup.js +5 -1
  6. package/dist/cjs/next-schema/groups/inlineGroup.js +1 -3
  7. package/dist/cjs/next-schema/nodes/blockCard.js +7 -3
  8. package/dist/cjs/next-schema/nodes/codeBlock.js +2 -2
  9. package/dist/cjs/next-schema/nodes/inlineExtension.js +5 -1
  10. package/dist/cjs/next-schema/nodes/layoutColumn.js +2 -1
  11. package/dist/cjs/next-schema/nodes/media.js +2 -2
  12. package/dist/cjs/next-schema/nodes/mediaInline.js +29 -12
  13. package/dist/cjs/next-schema/nodes/mediaSingle.js +2 -1
  14. package/dist/cjs/next-schema/nodes/mention.js +2 -1
  15. package/dist/cjs/next-schema/nodes/placeholder.js +1 -0
  16. package/dist/cjs/next-schema/nodes/table.js +1 -0
  17. package/dist/cjs/next-schema/nodes/tableCell.js +2 -2
  18. package/dist/cjs/next-schema/nodes/tableHeader.js +2 -2
  19. package/dist/cjs/next-schema/nodes/tableRow.js +2 -1
  20. package/dist/es2019/next-schema/full-schema.adf.js +3 -2
  21. package/dist/es2019/next-schema/generated/markTypes.js +23 -23
  22. package/dist/es2019/next-schema/generated/nodeTypes.js +134 -201
  23. package/dist/es2019/next-schema/groups/blockGroup.js +5 -1
  24. package/dist/es2019/next-schema/groups/inlineGroup.js +1 -3
  25. package/dist/es2019/next-schema/nodes/blockCard.js +7 -3
  26. package/dist/es2019/next-schema/nodes/codeBlock.js +1 -1
  27. package/dist/es2019/next-schema/nodes/inlineExtension.js +5 -1
  28. package/dist/es2019/next-schema/nodes/layoutColumn.js +2 -1
  29. package/dist/es2019/next-schema/nodes/media.js +2 -2
  30. package/dist/es2019/next-schema/nodes/mediaInline.js +29 -12
  31. package/dist/es2019/next-schema/nodes/mediaSingle.js +2 -1
  32. package/dist/es2019/next-schema/nodes/mention.js +2 -1
  33. package/dist/es2019/next-schema/nodes/placeholder.js +1 -0
  34. package/dist/es2019/next-schema/nodes/table.js +1 -0
  35. package/dist/es2019/next-schema/nodes/tableCell.js +2 -2
  36. package/dist/es2019/next-schema/nodes/tableHeader.js +2 -2
  37. package/dist/es2019/next-schema/nodes/tableRow.js +2 -1
  38. package/dist/esm/next-schema/full-schema.adf.js +3 -2
  39. package/dist/esm/next-schema/generated/markTypes.js +23 -23
  40. package/dist/esm/next-schema/generated/nodeTypes.js +134 -201
  41. package/dist/esm/next-schema/groups/blockGroup.js +5 -1
  42. package/dist/esm/next-schema/groups/inlineGroup.js +1 -3
  43. package/dist/esm/next-schema/nodes/blockCard.js +7 -3
  44. package/dist/esm/next-schema/nodes/codeBlock.js +1 -1
  45. package/dist/esm/next-schema/nodes/inlineExtension.js +5 -1
  46. package/dist/esm/next-schema/nodes/layoutColumn.js +2 -1
  47. package/dist/esm/next-schema/nodes/media.js +2 -2
  48. package/dist/esm/next-schema/nodes/mediaInline.js +29 -12
  49. package/dist/esm/next-schema/nodes/mediaSingle.js +2 -1
  50. package/dist/esm/next-schema/nodes/mention.js +2 -1
  51. package/dist/esm/next-schema/nodes/placeholder.js +1 -0
  52. package/dist/esm/next-schema/nodes/table.js +1 -0
  53. package/dist/esm/next-schema/nodes/tableCell.js +2 -2
  54. package/dist/esm/next-schema/nodes/tableHeader.js +2 -2
  55. package/dist/esm/next-schema/nodes/tableRow.js +2 -1
  56. package/dist/types/next-schema/generated/markTypes.d.ts +36 -36
  57. package/dist/types/next-schema/generated/nodeGroupTypes.d.ts +4 -4
  58. package/dist/types/next-schema/generated/nodeTypes.d.ts +59 -120
  59. package/dist/types/next-schema/nodes/codeBlock.d.ts +1 -1
  60. package/dist/types/next-schema/nodes/inlineExtension.d.ts +2 -0
  61. package/package.json +1 -1
  62. package/schema-generators/__tests__/helpers/_utils.ts +123 -0
  63. package/schema-generators/__tests__/helpers/utils.unit.ts +66 -0
  64. package/schema-generators/__tests__/unit/json-full-schema.unit.ts +1142 -1231
  65. package/schema-generators/__tests__/unit/validate-pm-schema.unit.ts +162 -36
@@ -19,7 +19,7 @@ export declare const codeBlock: import("@atlaskit/adf-schema-generator/dist/type
19
19
  } & {
20
20
  marks: import("@atlaskit/adf-schema-generator/dist/types/adfMark").ADFMark<import("@atlaskit/adf-schema-generator/dist/types/types/ADFMarkSpec").ADFMarkSpec>[];
21
21
  }>;
22
- export declare const codeBlockWithMarks: import("@atlaskit/adf-schema-generator/dist/types/adfNode").ADFNode<[string, "with_marks", "with_no_marks"], {
22
+ export declare const codeBlockWithNoMarks: import("@atlaskit/adf-schema-generator/dist/types/adfNode").ADFNode<[string, "with_marks", "with_no_marks"], {
23
23
  ignore?: import("@atlaskit/adf-schema-generator/dist/types/transforms/transformerNames").TransformerNames[];
24
24
  root?: boolean;
25
25
  atom?: boolean;
@@ -16,4 +16,6 @@ export declare const inlineExtension: import("@atlaskit/adf-schema-generator/dis
16
16
  marks?: import("@atlaskit/adf-schema-generator/dist/types/adfMark").ADFMark<unknown>[];
17
17
  selectable?: boolean;
18
18
  whitespace?: "pre" | "normal";
19
+ } & {
20
+ marks: import("@atlaskit/adf-schema-generator/dist/types/adfMark").ADFMark<import("@atlaskit/adf-schema-generator/dist/types/types/ADFMarkSpec").ADFMarkSpec>[];
19
21
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "36.14.0",
3
+ "version": "36.14.1",
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/"
@@ -0,0 +1,123 @@
1
+ export const filterAndSortMarks = (marks: string, excluded = []) => {
2
+ return marks
3
+ .split(' ')
4
+ .filter((v) => !excluded.includes(v))
5
+ .sort()
6
+ .join(' ');
7
+ };
8
+
9
+ /**
10
+ * filter out the unsupported nodes in content expression
11
+ * @param skipLists list includes node name need to be excluded
12
+ * @returns content without node name defined in skipList
13
+ */
14
+ const unSupportedExp =
15
+ (skipLists: string[] = []) =>
16
+ (str: string) => {
17
+ // this is used to treat cases like 'unsupportedBlock*'
18
+ if (str.endsWith('*')) {
19
+ return !skipLists.includes(str.substring(0, str.length - 1));
20
+ }
21
+ if (str.endsWith('+')) {
22
+ return !skipLists.includes(str.substring(0, str.length - 1));
23
+ }
24
+ return !skipLists.includes(str);
25
+ };
26
+
27
+ /**
28
+ * Sort the nodes in (), and also exclude the node if matched in skipList
29
+ * @param input content expression, e.g. "(paragrah | heading)"
30
+ * @param skipLists a list defined node name can be removed from content expression.
31
+ * @param enableWrap flag to add back ()
32
+ * @returns
33
+ */
34
+ const sortAndFilterOrsExp = (
35
+ input: string,
36
+ skipLists = [],
37
+ enableWrap = false,
38
+ ) => {
39
+ const filteredOr = input.split('|').filter(unSupportedExp(skipLists));
40
+ if (filteredOr.length === 1) {
41
+ return `${filteredOr[0]}`;
42
+ }
43
+ if (enableWrap) {
44
+ return `(${filteredOr.sort().join('|')})`;
45
+ }
46
+ return `${filteredOr.sort().join('|')}`;
47
+ };
48
+
49
+ /**
50
+ * Find the string inside () of provided string
51
+ * @param inputString input string likely have () in it
52
+ * @returns
53
+ */
54
+ function findStringInParentheses(inputString: string) {
55
+ const regex = /\((.*?)\)/g;
56
+ const matches = inputString.match(regex);
57
+ if (matches) {
58
+ return matches.map((match) => match.replace('(', '').replace(')', ''));
59
+ } else {
60
+ return null;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Format the content expression
66
+ * @param exp content expression string, e.g. (aTest, bTest)+
67
+ * @param operatorStart could be {, +, *
68
+ * @param skipLists
69
+ * @returns sorted and removed node defined in skipList
70
+ */
71
+ function formatExp(exp: string, operatorStart = '', skipLists = []) {
72
+ const orEnd = exp.indexOf(operatorStart);
73
+ const suffix = exp.substring(orEnd);
74
+ const matches = findStringInParentheses(exp);
75
+ if (matches) {
76
+ const temp = sortAndFilterOrsExp(matches[0], skipLists);
77
+ if (temp.includes('|')) {
78
+ return `(${temp})${suffix}`;
79
+ }
80
+ return `${temp}${suffix}`;
81
+ }
82
+ return sortAndFilterOrsExp(exp, skipLists);
83
+ }
84
+
85
+ const expFormatter =
86
+ (skipLists = []) =>
87
+ (content: string) => {
88
+ if (content.includes('|')) {
89
+ if (content.endsWith('}')) {
90
+ return formatExp(content, '{', skipLists);
91
+ }
92
+ if (content.endsWith('+')) {
93
+ return formatExp(content, '+', skipLists);
94
+ }
95
+ if (content.endsWith('*')) {
96
+ return formatExp(content, '*', skipLists);
97
+ }
98
+ if (!content.includes('+') && !content.includes('*')) {
99
+ if (content.startsWith('(') && content.endsWith(')')) {
100
+ const temp = content.substring(1, content.length - 1);
101
+ return `(${sortAndFilterOrsExp(temp, skipLists)})`;
102
+ }
103
+ return sortAndFilterOrsExp(content, skipLists);
104
+ }
105
+ }
106
+ return sortAndFilterOrsExp(content, skipLists);
107
+ };
108
+
109
+ /**
110
+ * Sort the node inside of () in contents string,
111
+ * remove spaces around '|', because there were inconsistence in legacy PM schema
112
+ * remove not supported nodes defined in skipList
113
+ * @param content contents string, e.g. (aTest | bTest)+ (cTest | dTest)*
114
+ * @param skipLists a list contains node name can be removed from contents string
115
+ * @returns sorted content string, without node defined in skipList
116
+ */
117
+ export const formatContent = (content: string, skipLists = []) => {
118
+ const result = content.replace(/\s*\|\s*/g, '|');
119
+ if (result.includes(' ')) {
120
+ return result.split(' ').map(expFormatter(skipLists)).join(' ').trim();
121
+ }
122
+ return expFormatter(skipLists)(result).trim();
123
+ };
@@ -0,0 +1,66 @@
1
+ import { filterAndSortMarks, formatContent } from './_utils';
2
+
3
+ describe('formatContent', () => {
4
+ it('should reorder within () with multiple content', () => {
5
+ expect(formatContent('(dTest | aTest)+ (dTest | aTest)*')).toEqual(
6
+ '(aTest|dTest)+ (aTest|dTest)*',
7
+ );
8
+ });
9
+
10
+ it('should reorder within () with multiple content, and if first content has no operator', () => {
11
+ expect(formatContent('(dTest | aTest) (dTest | aTest)*')).toEqual(
12
+ '(aTest|dTest) (aTest|dTest)*',
13
+ );
14
+ });
15
+
16
+ it('should reorder within (), and no operator for single content', () => {
17
+ expect(formatContent('dTest | aTest')).toEqual('aTest|dTest');
18
+ });
19
+
20
+ it('should keep parentheses with multiple content', () => {
21
+ expect(formatContent('(taskItem)+ (dTest|aTest)*')).toEqual(
22
+ '(taskItem)+ (aTest|dTest)*',
23
+ );
24
+ });
25
+
26
+ it('should keep parentheses with single content', () => {
27
+ expect(formatContent('(taskItem)+')).toEqual('(taskItem)+');
28
+ });
29
+
30
+ it('should remove unsupported strings and unnessary braces with onePlus and zeroPlus exps', () => {
31
+ expect(
32
+ formatContent(
33
+ '(taskItem|unsupportedBlock)+ (testA|testB|unsupportedBlock)*',
34
+ ['unsupportedBlock'],
35
+ ),
36
+ ).toEqual('taskItem+ (testA|testB)*');
37
+ });
38
+
39
+ it('should remove unsupported strings with range exp', () => {
40
+ expect(
41
+ formatContent(
42
+ '(layoutColumn|unsupportedBlock){1,3} (testA|testB|unsupportedBlock)*',
43
+ ['unsupportedBlock'],
44
+ ),
45
+ ).toEqual('layoutColumn{1,3} (testA|testB)*');
46
+ });
47
+
48
+ it('should remove all unsupported strings in between "|"', () => {
49
+ expect(
50
+ formatContent('aTest | unsupportedBlock* | unsupportedBlock+', [
51
+ 'unsupportedBlock',
52
+ ]),
53
+ ).toEqual('aTest');
54
+ });
55
+ });
56
+
57
+ describe('filterMarks', () => {
58
+ it('should remove marks if excludes defined', () => {
59
+ expect(
60
+ filterAndSortMarks(
61
+ 'unsupportedMark unsupportedNodeAttributes testMarkA testMarkB',
62
+ ['unsupportedMark', 'unsupportedNodeAttributes'],
63
+ ),
64
+ ).toEqual('testMarkA testMarkB');
65
+ });
66
+ });