@atlaskit/adf-schema 28.1.12 → 28.2.0

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 (210) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/types/index.d.ts +1 -1
  3. package/package.json +1 -1
  4. package/src/__tests__/unit/json-schema/v1.ts +0 -55
  5. package/src/__tests__/unit/schema/create-schema.ts +0 -214
  6. package/src/__tests__/unit/schema/default-schema.ts +0 -192
  7. package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
  8. package/src/__tests__/unit/schema/marks/border.ts +0 -76
  9. package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
  10. package/src/__tests__/unit/schema/marks/code.ts +0 -44
  11. package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
  12. package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
  13. package/src/__tests__/unit/schema/marks/em.ts +0 -37
  14. package/src/__tests__/unit/schema/marks/link.ts +0 -188
  15. package/src/__tests__/unit/schema/marks/strike.ts +0 -37
  16. package/src/__tests__/unit/schema/marks/strong.ts +0 -43
  17. package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
  18. package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
  19. package/src/__tests__/unit/schema/marks/underline.ts +0 -36
  20. package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
  21. package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
  22. package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
  23. package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
  24. package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
  25. package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
  26. package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
  27. package/src/__tests__/unit/schema/nodes/date.ts +0 -51
  28. package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
  29. package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
  30. package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
  31. package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
  32. package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
  33. package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
  34. package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
  35. package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
  36. package/src/__tests__/unit/schema/nodes/image.ts +0 -32
  37. package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
  38. package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
  39. package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
  40. package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
  41. package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
  42. package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
  43. package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
  44. package/src/__tests__/unit/schema/nodes/media.ts +0 -384
  45. package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
  46. package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
  47. package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
  48. package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
  49. package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
  50. package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
  51. package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
  52. package/src/__tests__/unit/schema/nodes/status.ts +0 -120
  53. package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
  54. package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
  55. package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
  56. package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
  57. package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
  58. package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
  59. package/src/__tests__/unit/utils/colors.ts +0 -42
  60. package/src/__tests__/unit/utils/url.ts +0 -209
  61. package/src/schema/bitbucket-schema.ts +0 -43
  62. package/src/schema/confluence-schema.ts +0 -76
  63. package/src/schema/create-schema.ts +0 -337
  64. package/src/schema/default-schema.ts +0 -180
  65. package/src/schema/groups.ts +0 -30
  66. package/src/schema/inline-nodes.ts +0 -9
  67. package/src/schema/jira-schema.ts +0 -158
  68. package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
  69. package/src/schema/marks/alignment.ts +0 -48
  70. package/src/schema/marks/annotation.ts +0 -107
  71. package/src/schema/marks/border.ts +0 -74
  72. package/src/schema/marks/breakout.ts +0 -42
  73. package/src/schema/marks/code.ts +0 -45
  74. package/src/schema/marks/confluence-inline-comment.ts +0 -32
  75. package/src/schema/marks/data-consumer.ts +0 -100
  76. package/src/schema/marks/em.ts +0 -19
  77. package/src/schema/marks/fragment.ts +0 -77
  78. package/src/schema/marks/indentation.ts +0 -47
  79. package/src/schema/marks/link.ts +0 -139
  80. package/src/schema/marks/strike.ts +0 -26
  81. package/src/schema/marks/strong.ts +0 -45
  82. package/src/schema/marks/subsup.ts +0 -53
  83. package/src/schema/marks/text-color.ts +0 -172
  84. package/src/schema/marks/type-ahead-query.ts +0 -22
  85. package/src/schema/marks/underline.ts +0 -24
  86. package/src/schema/marks/unsupported-mark.ts +0 -9
  87. package/src/schema/marks/unsupported-node-attributes.ts +0 -8
  88. package/src/schema/nodes/block-card.ts +0 -121
  89. package/src/schema/nodes/blockquote.ts +0 -25
  90. package/src/schema/nodes/bodied-extension.ts +0 -75
  91. package/src/schema/nodes/bullet-list.ts +0 -17
  92. package/src/schema/nodes/caption.ts +0 -51
  93. package/src/schema/nodes/code-block.ts +0 -176
  94. package/src/schema/nodes/confluence-jira-issue.ts +0 -43
  95. package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
  96. package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
  97. package/src/schema/nodes/date.ts +0 -38
  98. package/src/schema/nodes/decision-item.ts +0 -50
  99. package/src/schema/nodes/decision-list.ts +0 -56
  100. package/src/schema/nodes/doc.ts +0 -30
  101. package/src/schema/nodes/embed-card.ts +0 -62
  102. package/src/schema/nodes/emoji.ts +0 -89
  103. package/src/schema/nodes/expand.ts +0 -101
  104. package/src/schema/nodes/extension.ts +0 -60
  105. package/src/schema/nodes/hard-break.ts +0 -21
  106. package/src/schema/nodes/heading.ts +0 -64
  107. package/src/schema/nodes/image.ts +0 -32
  108. package/src/schema/nodes/inline-card.ts +0 -70
  109. package/src/schema/nodes/inline-extension.ts +0 -57
  110. package/src/schema/nodes/layout-column.ts +0 -68
  111. package/src/schema/nodes/layout-section.ts +0 -93
  112. package/src/schema/nodes/list-item.ts +0 -13
  113. package/src/schema/nodes/media-group.ts +0 -44
  114. package/src/schema/nodes/media-inline.ts +0 -19
  115. package/src/schema/nodes/media-single.ts +0 -179
  116. package/src/schema/nodes/media.ts +0 -253
  117. package/src/schema/nodes/mention.ts +0 -86
  118. package/src/schema/nodes/nested-expand.ts +0 -77
  119. package/src/schema/nodes/ordered-list.ts +0 -62
  120. package/src/schema/nodes/panel.ts +0 -133
  121. package/src/schema/nodes/paragraph.ts +0 -79
  122. package/src/schema/nodes/placeholder.ts +0 -40
  123. package/src/schema/nodes/rule.ts +0 -17
  124. package/src/schema/nodes/status.ts +0 -58
  125. package/src/schema/nodes/tableNodes.ts +0 -478
  126. package/src/schema/nodes/task-item.ts +0 -51
  127. package/src/schema/nodes/task-list.ts +0 -61
  128. package/src/schema/nodes/text.ts +0 -19
  129. package/src/schema/nodes/types/block-content.ts +0 -51
  130. package/src/schema/nodes/types/extensions.ts +0 -36
  131. package/src/schema/nodes/types/inline-content.ts +0 -56
  132. package/src/schema/nodes/types/list.ts +0 -54
  133. package/src/schema/nodes/types/mark.ts +0 -16
  134. package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
  135. package/src/schema/nodes/types/rich-media-common.ts +0 -51
  136. package/src/schema/nodes/unknown-block.ts +0 -13
  137. package/src/schema/nodes/unsupported-block.ts +0 -28
  138. package/src/schema/nodes/unsupported-inline.ts +0 -27
  139. package/src/schema/unsupported.ts +0 -4
  140. package/src/steps/__tests__/unit/analytics.ts +0 -72
  141. package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
  142. package/src/steps/__tests__/unit/override-document-step.ts +0 -174
  143. package/src/steps/__tests__/unit/set-attrs.ts +0 -71
  144. package/src/steps/analytics.ts +0 -189
  145. package/src/steps/link-meta-step.ts +0 -105
  146. package/src/steps/override-document-step.ts +0 -97
  147. package/src/steps/set-attrs.tsx +0 -74
  148. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
  149. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
  150. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
  151. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
  152. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
  153. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
  154. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
  155. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
  156. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
  157. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
  158. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
  159. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
  160. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
  161. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
  162. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
  163. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
  164. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
  165. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
  166. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
  167. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
  168. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
  169. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
  170. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
  171. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
  172. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
  173. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
  174. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
  175. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
  176. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
  177. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
  178. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
  179. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
  180. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
  181. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
  182. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
  183. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
  184. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
  185. package/src/steps/table/__tests__/_utils.ts +0 -102
  186. package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
  187. package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
  188. package/src/steps/table/__tests__/add-column.ts +0 -638
  189. package/src/steps/table/add-column.ts +0 -443
  190. package/src/steps/table/constants.ts +0 -4
  191. package/src/steps/table/sort-column.ts +0 -57
  192. package/src/steps/table/types.ts +0 -48
  193. package/src/steps/table/utils/cell-step.ts +0 -239
  194. package/src/steps/table/utils/cells-at-column.ts +0 -75
  195. package/src/steps/table/utils/find-column.ts +0 -90
  196. package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
  197. package/src/steps/table/utils/side-effects/rows.ts +0 -327
  198. package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
  199. package/src/steps/table/utils/side-effects/table.ts +0 -112
  200. package/src/steps/table/utils/side-effects/types.ts +0 -34
  201. package/src/steps/table/utils/table-map.ts +0 -28
  202. package/src/steps/type-ahead.ts +0 -100
  203. package/src/steps.ts +0 -16
  204. package/src/utils/colors.ts +0 -171
  205. package/src/utils/confluence/emoji.ts +0 -99
  206. package/src/utils/extensions.ts +0 -32
  207. package/src/utils/parseDOM.ts +0 -2
  208. package/src/utils/url.ts +0 -173
  209. package/src/utils/uuid.ts +0 -19
  210. package/src/version.json +0 -6
@@ -1,44 +0,0 @@
1
- import { NodeSpec } from '@atlaskit/editor-prosemirror/model';
2
- import { MediaDefinition as Media } from './media';
3
-
4
- /**
5
- * @name mediaGroup_node
6
- */
7
- export interface MediaGroupDefinition {
8
- type: 'mediaGroup';
9
- /**
10
- * @minItems 1
11
- * @allowUnsupportedBlock true
12
- */
13
- content: Array<Media>;
14
- }
15
-
16
- // Temporary due to an existing issue in validator below:
17
- // https://product-fabric.atlassian.net/jira/servicedesk/projects/DTR/queues/issue/DTR-1429
18
- // TODO: Remove border and link marks from white list
19
- export const mediaGroup: NodeSpec = {
20
- inline: false,
21
- group: 'block',
22
- content: '(media|unsupportedBlock)+',
23
- attrs: {},
24
- marks: 'unsupportedMark unsupportedNodeAttribute border link',
25
- selectable: false,
26
- parseDOM: [
27
- {
28
- tag: 'div[data-node-type="mediaGroup"]',
29
- },
30
- {
31
- tag: 'div[class="MediaGroup"]',
32
- },
33
- ],
34
-
35
- toDOM() {
36
- return [
37
- 'div',
38
- {
39
- 'data-node-type': 'mediaGroup',
40
- },
41
- 0,
42
- ];
43
- },
44
- };
@@ -1,19 +0,0 @@
1
- import { NodeSpec } from '@atlaskit/editor-prosemirror/model';
2
- import { LinkDefinition } from '../marks/link';
3
- import { createMediaSpec, defaultAttrs, MediaBaseAttributes } from './media';
4
-
5
- export interface MediaInlineAttributes extends MediaBaseAttributes {
6
- data?: object;
7
- type?: 'file' | 'link';
8
- }
9
-
10
- /**
11
- * @name mediaInline_node
12
- */
13
- export interface MediaInlineDefinition {
14
- type: 'mediaInline';
15
- attrs: MediaInlineAttributes;
16
- marks?: Array<LinkDefinition>;
17
- }
18
-
19
- export const mediaInline: NodeSpec = createMediaSpec(defaultAttrs, true);
@@ -1,179 +0,0 @@
1
- import { NodeSpec, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import { MediaDefinition as Media } from './media';
3
- import { LinkDefinition } from '../marks/link';
4
-
5
- import { ExtendedMediaAttributes, WidthType } from './types/rich-media-common';
6
- import { CaptionDefinition as Caption } from './caption';
7
- import { isDOMElement } from '../../utils/parseDOM';
8
-
9
- export type MediaSingleDefinition =
10
- | MediaSingleFullDefinition
11
- | MediaSingleWithCaptionDefinition;
12
-
13
- /**
14
- * @name mediaSingle_node
15
- * @additionalProperties true
16
- */
17
- export interface MediaSingleBaseDefinition {
18
- type: 'mediaSingle';
19
- attrs?: ExtendedMediaAttributes;
20
- marks?: Array<LinkDefinition>;
21
- }
22
-
23
- /**
24
- * @additionalProperties true
25
- */
26
- export interface MediaCaptionContent {
27
- /**
28
- * @minItems 1
29
- * @maxItems 2
30
- * @allowUnsupportedBlock true
31
- */
32
- content: [Media, Caption?];
33
- }
34
- /**
35
- * @name mediaSingle_caption_node
36
- */
37
- export type MediaSingleWithCaptionDefinition = MediaSingleBaseDefinition &
38
- MediaCaptionContent;
39
-
40
- /**
41
- * @additionalProperties true
42
- */
43
- export interface MediaSingleFullContent {
44
- /**
45
- * @minItems 1
46
- * @maxItems 1
47
- * @allowUnsupportedBlock true
48
- */
49
- content: Array<Media>;
50
- }
51
-
52
- /**
53
- * @name mediaSingle_full_node
54
- */
55
- export type MediaSingleFullDefinition = MediaSingleBaseDefinition &
56
- MediaSingleFullContent;
57
-
58
- export const defaultAttrs: {
59
- width: {
60
- default: null;
61
- };
62
- layout: {
63
- default: string;
64
- };
65
- } = {
66
- width: { default: null }, // null makes small images to have original size by default
67
- layout: { default: 'center' },
68
- };
69
-
70
- export const mediaSingleSpec = ({
71
- withCaption = false,
72
- withExtendedWidthTypes = false,
73
- }: {
74
- withCaption?: boolean | undefined;
75
- withExtendedWidthTypes?: boolean | undefined;
76
- }): NodeSpec => {
77
- const content = withCaption
78
- ? 'media|unsupportedBlock+|media (caption|unsupportedBlock) unsupportedBlock*'
79
- : 'media|unsupportedBlock+|media unsupportedBlock+';
80
-
81
- const atom = !withCaption;
82
-
83
- const getAttrs = (dom: string | Node) => {
84
- if (!isDOMElement(dom)) {
85
- // this should never happen
86
- return { layout: 'center' };
87
- }
88
-
89
- const layout = dom.getAttribute('data-layout') || 'center';
90
- const width = Number(dom.getAttribute('data-width')) || null;
91
- const widthType = dom.getAttribute('data-width-type');
92
-
93
- if (withExtendedWidthTypes) {
94
- return { layout, width, widthType };
95
- } else if (widthType === WidthType.PIXEL) {
96
- // if editor does not support widthType attribute.
97
- // We ignore width and widthType together.
98
- return { layout };
99
- } else {
100
- return { layout, width };
101
- }
102
- };
103
-
104
- const getAttrsFromNode = (node: PMNode) => {
105
- const { layout, width } = node.attrs;
106
- const attrs = {
107
- 'data-node-type': 'mediaSingle',
108
- 'data-layout': layout,
109
- 'data-width': '',
110
- };
111
-
112
- if (width) {
113
- attrs['data-width'] =
114
- isFinite(width) && Math.floor(width) === width
115
- ? width
116
- : width.toFixed(2);
117
- }
118
-
119
- if (withExtendedWidthTypes && node.attrs.widthType) {
120
- const { widthType } = node.attrs;
121
- return {
122
- ...attrs,
123
- 'data-width-type': widthType || WidthType.PERCENTAGE,
124
- };
125
- }
126
-
127
- return attrs;
128
- };
129
-
130
- return {
131
- inline: false,
132
- group: 'block',
133
- selectable: true,
134
- atom,
135
- content,
136
- attrs: withExtendedWidthTypes
137
- ? { ...defaultAttrs, widthType: { default: null } }
138
- : defaultAttrs,
139
- marks: 'unsupportedMark unsupportedNodeAttribute border link',
140
- parseDOM: [
141
- {
142
- tag: 'div[data-node-type="mediaSingle"]',
143
- getAttrs,
144
- },
145
- ],
146
- toDOM(node: PMNode) {
147
- return ['div', getAttrsFromNode(node), 0];
148
- },
149
- };
150
- };
151
-
152
- export const mediaSingle: NodeSpec = mediaSingleSpec({
153
- withCaption: false,
154
- withExtendedWidthTypes: false,
155
- });
156
-
157
- export const mediaSingleWithCaption: NodeSpec = mediaSingleSpec({
158
- withCaption: true,
159
- withExtendedWidthTypes: false,
160
- });
161
-
162
- export const mediaSingleWithWidthType: NodeSpec = mediaSingleSpec({
163
- withCaption: false,
164
- withExtendedWidthTypes: true,
165
- });
166
-
167
- export const mediaSingleFull: NodeSpec = mediaSingleSpec({
168
- withCaption: true,
169
- withExtendedWidthTypes: true,
170
- });
171
-
172
- export const toJSON = (node: PMNode) => ({
173
- attrs: Object.keys(node.attrs).reduce<any>((obj, key) => {
174
- if (node.attrs[key] !== null) {
175
- obj[key] = node.attrs[key];
176
- }
177
- return obj;
178
- }, {}),
179
- });
@@ -1,253 +0,0 @@
1
- import {
2
- NodeSpec,
3
- Node as PMNode,
4
- ParseRule,
5
- } from '@atlaskit/editor-prosemirror/model';
6
- import { N30 } from '../../utils/colors';
7
- import { BorderMarkDefinition } from '../marks/border';
8
- import { LinkDefinition } from '../marks/link';
9
-
10
- export type MediaType = 'file' | 'link' | 'external';
11
- export type DisplayType = 'file' | 'thumbnail';
12
-
13
- export type DefaultAttributes<T> = {
14
- [P in keyof T]: {
15
- default?: T[P] | null;
16
- };
17
- };
18
-
19
- /**
20
- * @name media_node
21
- */
22
- export interface MediaDefinition {
23
- type: 'media';
24
- /**
25
- * @minItems 1
26
- */
27
- attrs: MediaADFAttrs;
28
-
29
- marks?: Array<LinkDefinition | BorderMarkDefinition>;
30
- }
31
-
32
- export interface MediaBaseAttributes {
33
- /**
34
- * @minLength 1
35
- */
36
- id: string;
37
- collection: string;
38
- height?: number;
39
- width?: number;
40
- /**
41
- * @minLength 1
42
- */
43
- occurrenceKey?: string;
44
- alt?: string;
45
- // For both CQ and JIRA
46
- __fileName?: string | null;
47
- // For CQ
48
- __fileSize?: number | null;
49
- __fileMimeType?: string | null;
50
- // For JIRA
51
- __displayType?: DisplayType | null;
52
- // For copy & paste
53
- __contextId?: string | null;
54
- // For tracing media operations
55
- __mediaTraceId?: string | null;
56
-
57
- // is set to true when new external media is inserted, false for external media in existing documents
58
- __external?: boolean;
59
- }
60
-
61
- export interface MediaAttributes extends MediaBaseAttributes {
62
- type: 'file' | 'link';
63
- }
64
-
65
- export interface ExternalMediaAttributes {
66
- type: 'external';
67
- url: string;
68
- alt?: string;
69
- width?: number;
70
- height?: number;
71
- __external?: boolean;
72
- }
73
-
74
- export type MediaADFAttrs = MediaAttributes | ExternalMediaAttributes;
75
-
76
- export const defaultAttrs: DefaultAttributes<MediaADFAttrs> = {
77
- id: { default: '' },
78
- type: { default: 'file' },
79
- collection: { default: '' },
80
- occurrenceKey: { default: null },
81
- alt: { default: '' },
82
- width: { default: null },
83
- height: { default: null },
84
- url: { default: null },
85
- __fileName: { default: null },
86
- __fileSize: { default: null },
87
- __fileMimeType: { default: null },
88
- __displayType: { default: null },
89
- __contextId: { default: null },
90
- __mediaTraceId: { default: null },
91
- __external: { default: false },
92
- };
93
-
94
- interface MutableMediaAttributes extends MediaAttributes {
95
- [key: string]: string | number | undefined | null | boolean;
96
- }
97
-
98
- export const createMediaSpec = (
99
- attributes: Partial<NodeSpec['attrs']>,
100
- inline: boolean = false,
101
- ): NodeSpec => {
102
- const domNodeType = inline ? 'span' : 'div';
103
- const nodeName = inline ? 'mediaInline' : 'media';
104
- const parseDOM: ParseRule[] = [
105
- {
106
- tag: `${domNodeType}[data-node-type="${nodeName}"]`,
107
- getAttrs: (dom) => {
108
- const attrs = {} as MutableMediaAttributes;
109
-
110
- if (attributes) {
111
- Object.keys(attributes).forEach((k) => {
112
- const key = camelCaseToKebabCase(k).replace(/^__/, '');
113
- const value =
114
- (dom as HTMLElement).getAttribute(`data-${key}`) || '';
115
- if (value) {
116
- attrs[k] = value;
117
- }
118
- });
119
- }
120
-
121
- // Need to do validation & type conversion manually
122
- if (attrs.__fileSize) {
123
- attrs.__fileSize = +attrs.__fileSize;
124
- }
125
-
126
- const width = Number(attrs.width);
127
- if (typeof width !== 'undefined' && !isNaN(width)) {
128
- attrs.width = width;
129
- }
130
-
131
- const height = Number(attrs.height);
132
- if (typeof height !== 'undefined' && !isNaN(height)) {
133
- attrs.height = height;
134
- }
135
-
136
- return attrs as MediaAttributes;
137
- },
138
- },
139
- // Don't match data URI
140
- {
141
- tag: 'img[src^="data:image"]',
142
- ignore: true,
143
- },
144
- ];
145
-
146
- // media-inline.ts uses this same function to generate the nodespec
147
- // this ensures that we don't make a media inline out of a copied image
148
- // https://product-fabric.atlassian.net/browse/EDM-2996
149
- if (!inline) {
150
- parseDOM.push({
151
- tag: 'img:not(.smart-link-icon)',
152
- getAttrs: (dom) => {
153
- return {
154
- type: 'external',
155
- url: (dom as HTMLElement).getAttribute('src') || '',
156
- alt: (dom as HTMLElement).getAttribute('alt') || '',
157
- } as ExternalMediaAttributes;
158
- },
159
- });
160
- }
161
-
162
- return {
163
- selectable: true,
164
- inline,
165
- group: inline ? 'inline' : undefined,
166
- attrs: attributes as NodeSpec['attrs'],
167
- parseDOM,
168
- toDOM(node: PMNode) {
169
- const attrs = {
170
- 'data-id': node.attrs.id,
171
- 'data-node-type': `${nodeName}`,
172
- 'data-type': node.attrs.type,
173
- 'data-collection': node.attrs.collection,
174
- 'data-occurrence-key': node.attrs.occurrenceKey,
175
- 'data-width': node.attrs.width,
176
- 'data-height': node.attrs.height,
177
- 'data-url': node.attrs.url,
178
- 'data-alt': node.attrs.alt,
179
- // toDOM is used for static rendering as well as editor rendering. This comes into play for
180
- // emails, copy/paste, etc, so the title and styling here *is* useful (despite a React-based
181
- // node view being used for editing).
182
- title: 'Attachment',
183
- // Manually kept in sync with the style of media cards. The goal is to render a plain gray
184
- // rectangle that provides an affordance for media.
185
- style: `display: inline-block; border-radius: 3px; background: ${N30}; box-shadow: 0 1px 1px rgba(9, 30, 66, 0.2), 0 0 1px 0 rgba(9, 30, 66, 0.24);`,
186
- };
187
-
188
- copyPrivateAttributes(
189
- node.attrs,
190
- attrs,
191
- (key) => `data-${camelCaseToKebabCase(key.slice(2))}`,
192
- );
193
-
194
- return [`${domNodeType}`, attrs];
195
- },
196
- };
197
- };
198
-
199
- export const media: NodeSpec = createMediaSpec(defaultAttrs);
200
-
201
- export const camelCaseToKebabCase = (str: string) =>
202
- str.replace(/([^A-Z]+)([A-Z])/g, (_, x, y) => `${x}-${y.toLowerCase()}`);
203
-
204
- export const copyPrivateAttributes: (
205
- from: Record<string, any>,
206
- to: Record<string, any>,
207
- map?: ((str: string) => string) | undefined,
208
- ) => void = (
209
- from: Record<string, any>,
210
- to: Record<string, any>,
211
- map?: (str: string) => string,
212
- ) => {
213
- if (media.attrs) {
214
- Object.keys(media.attrs).forEach((key) => {
215
- if (key[0] === '_' && key[1] === '_' && from[key]) {
216
- to[map ? map(key) : key] = from[key];
217
- }
218
- });
219
- }
220
- };
221
-
222
- /**
223
- * There's no concept of optional property in ProseMirror. It sets value as `null`
224
- * when there's no use of any property. We are filtering out all private & optional attrs here.
225
- */
226
- const optionalAttributes = ['occurrenceKey', 'width', 'height', 'url', 'alt'];
227
- const externalOnlyAttributes = ['type', 'url', 'width', 'height', 'alt'];
228
-
229
- export const toJSON = (node: PMNode) => ({
230
- attrs: Object.keys(node.attrs)
231
- // Strip private attributes e.g. __fileName, __fileSize, __fileMimeType, etc.
232
- .filter((key) => !(key[0] === '_' && key[1] === '_'))
233
- .reduce<Record<string, any>>((obj, key) => {
234
- if (
235
- node.attrs.type === 'external' &&
236
- externalOnlyAttributes.indexOf(key) === -1
237
- ) {
238
- return obj;
239
- }
240
- if (
241
- optionalAttributes.indexOf(key) > -1 &&
242
- (node.attrs[key] === null || node.attrs[key] === '')
243
- ) {
244
- return obj;
245
- }
246
- if (['width', 'height'].indexOf(key) !== -1) {
247
- obj[key] = Number(node.attrs[key]);
248
- return obj;
249
- }
250
- obj[key] = node.attrs[key];
251
- return obj;
252
- }, {}),
253
- });
@@ -1,86 +0,0 @@
1
- import { NodeSpec, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
-
3
- export enum USER_TYPES {
4
- DEFAULT = 'DEFAULT',
5
- SPECIAL = 'SPECIAL',
6
- APP = 'APP',
7
- }
8
-
9
- export type UserType = keyof typeof USER_TYPES;
10
-
11
- export interface MentionAttributes {
12
- id: string;
13
- text?: string;
14
- userType?: UserType;
15
- accessLevel?: string;
16
- }
17
-
18
- /**
19
- * @name mention_node
20
- */
21
- export interface MentionDefinition {
22
- type: 'mention';
23
- attrs: MentionAttributes;
24
- }
25
-
26
- export const mention: NodeSpec = {
27
- inline: true,
28
- group: 'inline',
29
- selectable: true,
30
- attrs: {
31
- id: { default: '' },
32
- text: { default: '' },
33
- accessLevel: { default: '' },
34
- userType: { default: null },
35
- },
36
- parseDOM: [
37
- {
38
- tag: 'span[data-mention-id]',
39
- getAttrs: (domNode) => {
40
- const dom = domNode as HTMLElement;
41
- const attrs: MentionAttributes = {
42
- id: dom.getAttribute('data-mention-id') || mention.attrs!.id.default,
43
- text: dom.textContent || mention.attrs!.text.default,
44
- accessLevel:
45
- dom.getAttribute('data-access-level') ||
46
- mention.attrs!.accessLevel.default,
47
- };
48
-
49
- const userType = dom.getAttribute('data-user-type') as USER_TYPES;
50
- if (USER_TYPES[userType]) {
51
- attrs.userType = userType;
52
- }
53
-
54
- return attrs;
55
- },
56
- },
57
- ],
58
- toDOM(node) {
59
- const { id, accessLevel, text, userType } = node.attrs;
60
- const attrs: any = {
61
- 'data-mention-id': id,
62
- 'data-access-level': accessLevel,
63
- contenteditable: 'false',
64
- };
65
- if (userType) {
66
- attrs['data-user-type'] = userType;
67
- }
68
- return ['span', attrs, text];
69
- },
70
- };
71
-
72
- const isOptional = (key: string) => {
73
- return ['userType'].indexOf(key) > -1;
74
- };
75
-
76
- export const toJSON = (node: PMNode) => ({
77
- attrs: Object.keys(node.attrs).reduce<typeof node.attrs>((obj, key) => {
78
- if (isOptional(key) && !node.attrs[key]) {
79
- return obj;
80
- }
81
- return {
82
- ...obj,
83
- [key]: node.attrs[key],
84
- };
85
- }, {}),
86
- });
@@ -1,77 +0,0 @@
1
- import { Node as PMNode, NodeSpec } from '@atlaskit/editor-prosemirror/model';
2
- import { NoMark } from './types/mark';
3
- import { ParagraphDefinition as Paragraph } from './paragraph';
4
- import { HeadingDefinition as Heading } from './heading';
5
- import { MediaSingleDefinition as MediaSingle } from './media-single';
6
- import { MediaGroupDefinition as MediaGroup } from './media-group';
7
-
8
- /**
9
- * @name nestedExpand_content
10
- * @minItems 1
11
- * @allowUnsupportedBlock true
12
- */
13
- export type NestedExpandContent = Array<
14
- Paragraph | Heading | MediaSingle | MediaGroup
15
- >;
16
-
17
- /**
18
- * @name nestedExpand_node
19
- */
20
- export interface NestedExpandBaseDefinition {
21
- type: 'nestedExpand';
22
- attrs: {
23
- title?: string;
24
- };
25
- content: NestedExpandContent;
26
- }
27
-
28
- /**
29
- * @name nestedExpand_with_no_marks_node
30
- */
31
- export type NestedExpandDefinition = NestedExpandBaseDefinition & NoMark;
32
-
33
- export const nestedExpand: NodeSpec = {
34
- inline: false,
35
- marks: 'unsupportedMark unsupportedNodeAttribute',
36
- content:
37
- '(paragraph | heading | mediaSingle | mediaGroup | unsupportedBlock)+',
38
- isolating: true,
39
- selectable: true,
40
- attrs: {
41
- title: { default: '' },
42
- __expanded: { default: true },
43
- },
44
- parseDOM: [
45
- {
46
- context: 'nestedExpand//',
47
- tag: '[data-node-type="nestedExpand"]',
48
- skip: true,
49
- },
50
- {
51
- tag: '[data-node-type="nestedExpand"] button',
52
- ignore: true,
53
- },
54
- {
55
- tag: '[data-node-type="expand"] button',
56
- ignore: true,
57
- },
58
- {
59
- tag: 'div[data-node-type="nestedExpand"]',
60
- getAttrs: (domNode) => {
61
- const dom = domNode as HTMLElement;
62
- return {
63
- title: dom.getAttribute('data-title'),
64
- __expanded: true,
65
- };
66
- },
67
- },
68
- ],
69
- toDOM(node: PMNode) {
70
- const attrs = {
71
- 'data-node-type': 'nestedExpand',
72
- 'data-title': node.attrs.title,
73
- 'data-expanded': node.attrs.__expanded,
74
- };
75
- return ['div', attrs, 0];
76
- },
77
- };