@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
@@ -1,329 +0,0 @@
1
- import {
2
- Fragment,
3
- MarkType,
4
- Node,
5
- NodeType,
6
- Schema,
7
- Slice /*MediaAttributes */,
8
- } from 'prosemirror-model';
9
- import { MediaAttributes } from '../src/schema/nodes/media';
10
- import { MediaInlineAttributes } from '../src/schema/nodes/media-inline';
11
- import matches from './matches';
12
- import sampleSchema from './schema';
13
- import {
14
- TableAttributes,
15
- CellAttributes,
16
- } from '../src/schema/nodes/tableNodes';
17
-
18
- /**
19
- * Represents a ProseMirror "position" in a document.
20
- */
21
- export type position = number;
22
-
23
- /**
24
- * A useful feature of the builder is being able to declaratively mark positions
25
- * in content using the curly braces e.g. `{<>}`.
26
- *
27
- * These positions are called "refs" (inspired by React), and are tracked on
28
- * every node in the tree that has a ref on any of its descendants.
29
- */
30
- export type Refs = { [name: string]: position };
31
-
32
- /**
33
- * Content that contains refs information.
34
- */
35
- export type RefsContentItem = RefsNode | RefsTracker;
36
-
37
- /**
38
- * Content node or mark builders can consume, e.g.
39
- *
40
- * const builder = nodeFactory('p');
41
- * builder('string');
42
- * builder(aNode);
43
- * builder(aRefsNode);
44
- * builder(aRefsTracker);
45
- * builder([aNode, aRefsNode, aRefsTracker]);
46
- */
47
- export type BuilderContent =
48
- | string
49
- | Node
50
- | RefsContentItem
51
- | (Node | RefsContentItem)[];
52
-
53
- /**
54
- * ProseMirror doesn't support empty text nodes, which can be quite
55
- * inconvenient when you want to capture a position ref without introducing
56
- * text.
57
- *
58
- * Take a couple of examples:
59
- *
60
- * p('{<>}')
61
- * p('Hello ', '{<>}', 'world!')
62
- *
63
- * After the ref syntax is stripped you're left with:
64
- *
65
- * p('')
66
- * p('Hello ', '', 'world!')
67
- *
68
- * This violates the rule of text nodes being non-empty. This class solves the
69
- * problem by providing an alternative data structure that *only* stores refs,
70
- * and can be used in scenarios where an empty text would be forbidden.
71
- *
72
- * This is done under the hood when using `text()` factory, and instead of
73
- * always returning a text node, it'll instead return one of two things:
74
- *
75
- * - a text node -- when given a non-empty string
76
- * - a refs tracker -- when given a string that *only* contains refs.
77
- */
78
- export class RefsTracker {
79
- refs?: Refs;
80
- }
81
-
82
- /**
83
- * A standard ProseMirror Node that also tracks refs.
84
- */
85
- export interface RefsNode extends Node {
86
- refs: Refs;
87
- }
88
-
89
- /**
90
- * Create a text node.
91
- *
92
- * Special markers called "refs" can be put in the text. Refs provide a way to
93
- * declaratively describe a position within some text, and then access the
94
- * position in the resulting node.
95
- */
96
- export function text(value: string, schema: Schema): RefsContentItem {
97
- let stripped = '';
98
- let textIndex = 0;
99
- const refs: Refs = {};
100
-
101
- // Helpers
102
- const isEven = (n: number) => n % 2 === 0;
103
-
104
- for (const match of matches(value, /([\\]+)?{(\w+|<|>|<>)}/g)) {
105
- const [refToken, skipChars, refName] = match;
106
- let { index } = match;
107
-
108
- const skipLen = skipChars && skipChars.length;
109
- if (skipLen) {
110
- if (isEven(skipLen)) {
111
- index += skipLen / 2;
112
- } else {
113
- stripped += value.slice(textIndex, index + (skipLen - 1) / 2);
114
- stripped += value.slice(index + skipLen, index + refToken.length);
115
- textIndex = index + refToken.length;
116
- continue;
117
- }
118
- }
119
-
120
- stripped += value.slice(textIndex, index);
121
- refs[refName] = stripped.length;
122
- textIndex = match.index + refToken.length;
123
- }
124
-
125
- stripped += value.slice(textIndex);
126
-
127
- const node =
128
- stripped === '' ? new RefsTracker() : (schema.text(stripped) as RefsNode);
129
-
130
- node.refs = refs;
131
- return node;
132
- }
133
-
134
- /**
135
- * Offset ref position values by some amount.
136
- */
137
- export function offsetRefs(refs: Refs, offset: number): Refs {
138
- const result = {} as Refs;
139
- for (const name in refs) {
140
- result[name] = refs[name] + offset;
141
- }
142
- return result;
143
- }
144
-
145
- /**
146
- * Given a collection of nodes, sequence them in an array and return the result
147
- * along with the updated refs.
148
- */
149
- export function sequence(...content: RefsContentItem[]) {
150
- let position = 0;
151
- let refs = {} as Refs;
152
- const nodes = [] as RefsNode[];
153
-
154
- // It's bizarre that this is necessary. An if/else in the for...of should have
155
- // sufficient but it did not work at the time of writing.
156
- const isRefsTracker = (n: any): n is RefsTracker => n instanceof RefsTracker;
157
- const isRefsNode = (n: any): n is RefsNode => !isRefsTracker(n);
158
-
159
- for (const node of content) {
160
- if (isRefsTracker(node)) {
161
- refs = { ...refs, ...offsetRefs(node.refs!, position) };
162
- }
163
- if (isRefsNode(node)) {
164
- const thickness = node.isText ? 0 : 1;
165
- refs = { ...refs, ...offsetRefs(node.refs, position + thickness) };
166
- position += node.nodeSize;
167
- nodes.push(node as RefsNode);
168
- }
169
- }
170
- return { nodes, refs };
171
- }
172
-
173
- /**
174
- * Given a jagged array, flatten it down to a single level.
175
- */
176
- export function flatten<T>(deep: (T | T[])[]): T[] {
177
- const flat = [] as T[];
178
- for (const item of deep) {
179
- if (Array.isArray(item)) {
180
- flat.splice(flat.length, 0, ...item);
181
- } else {
182
- flat.push(item);
183
- }
184
- }
185
- return flat;
186
- }
187
-
188
- /**
189
- * Coerce builder content into ref nodes.
190
- */
191
- export function coerce(content: BuilderContent[], schema: Schema) {
192
- const refsContent = content.map((item) =>
193
- typeof item === 'string' ? text(item, schema) : item,
194
- ) as (RefsContentItem | RefsContentItem[])[];
195
- return sequence(...flatten<RefsContentItem>(refsContent));
196
- }
197
-
198
- /**
199
- * Create a factory for nodes.
200
- */
201
- export function nodeFactory(type: NodeType, attrs = {}) {
202
- return function (...content: BuilderContent[]): RefsNode {
203
- const { nodes, refs } = coerce(content, type.schema);
204
- const node = type.create(attrs, nodes) as RefsNode;
205
- node.refs = refs;
206
- return node;
207
- };
208
- }
209
-
210
- /**
211
- * Create a factory for marks.
212
- */
213
- export function markFactory(type: MarkType, attrs = {}) {
214
- const mark = type.create(attrs);
215
- return (...content: BuilderContent[]): RefsNode[] => {
216
- const { nodes } = coerce(content, type.schema);
217
- return nodes.map((node) => {
218
- if (mark.type.isInSet(node.marks)) {
219
- return node;
220
- } else {
221
- const refNode = node.mark(mark.addToSet(node.marks)) as RefsNode;
222
- refNode.refs = node.refs;
223
- return refNode;
224
- }
225
- });
226
- };
227
- }
228
-
229
- export const createCell = (colspan: number, rowspan: number) =>
230
- td({ colspan, rowspan })(p('x'));
231
- export const createHeaderCell = (colspan: number, rowspan: number) =>
232
- th({ colspan, rowspan })(p('x'));
233
-
234
- export const doc = nodeFactory(sampleSchema.nodes.doc, {});
235
- export const p = nodeFactory(sampleSchema.nodes.paragraph, {});
236
- export const blockquote = nodeFactory(sampleSchema.nodes.blockquote, {});
237
- export const h1 = nodeFactory(sampleSchema.nodes.heading, { level: 1 });
238
- export const h2 = nodeFactory(sampleSchema.nodes.heading, { level: 2 });
239
- export const h3 = nodeFactory(sampleSchema.nodes.heading, { level: 3 });
240
- export const h4 = nodeFactory(sampleSchema.nodes.heading, { level: 4 });
241
- export const h5 = nodeFactory(sampleSchema.nodes.heading, { level: 5 });
242
- export const h6 = nodeFactory(sampleSchema.nodes.heading, { level: 6 });
243
- export const li = nodeFactory(sampleSchema.nodes.listItem, {});
244
- export const ul = nodeFactory(sampleSchema.nodes.bulletList, {});
245
- export const ol = nodeFactory(sampleSchema.nodes.orderedList, {});
246
- export const br = sampleSchema.nodes.hardBreak.createChecked();
247
- export const extension = nodeFactory(sampleSchema.nodes.extension, {});
248
- export const panel = nodeFactory(sampleSchema.nodes.panel, {});
249
- export const panelNote = nodeFactory(sampleSchema.nodes.panel, {
250
- panelType: 'note',
251
- });
252
- export const plain = nodeFactory(sampleSchema.nodes.plain, {});
253
- export const hardBreak = nodeFactory(sampleSchema.nodes.hardBreak, {});
254
-
255
- export const code_block = (attrs: {} = {}) =>
256
- nodeFactory(sampleSchema.nodes.codeBlock, attrs);
257
- export const img = (attrs: { src: string; alt?: string; title?: string }) =>
258
- sampleSchema.nodes.image.createChecked(attrs);
259
- export const emoji = (attrs: {
260
- shortName: string;
261
- id?: string;
262
- fallback?: string;
263
- }) => {
264
- const emojiNodeAttrs = {
265
- shortName: attrs.shortName,
266
- id: attrs.id,
267
- text: attrs.fallback || attrs.shortName,
268
- };
269
- return sampleSchema.nodes.emoji.createChecked(emojiNodeAttrs);
270
- };
271
- export const mention = (attrs: { id: string; text?: string }) =>
272
- sampleSchema.nodes.mention.createChecked(attrs);
273
- export const hr = sampleSchema.nodes.rule.createChecked();
274
- export const em = markFactory(sampleSchema.marks.em, {});
275
- export const subsup = (attrs: { type: string }) =>
276
- markFactory(sampleSchema.marks.subsup, attrs);
277
- export const underline = markFactory(sampleSchema.marks.underline, {});
278
- export const strong = markFactory(sampleSchema.marks.strong, {});
279
- export const code = markFactory(sampleSchema.marks.code, {});
280
- export const strike = markFactory(sampleSchema.marks.strike, {});
281
- export const mentionQuery = (attrs = { active: true }) =>
282
- markFactory(sampleSchema.marks.mentionQuery, attrs ? attrs : {});
283
- export const a = (attrs: { href: string; title?: string }) =>
284
- markFactory(sampleSchema.marks.link, attrs);
285
- export const fragment = (...content: BuilderContent[]) =>
286
- flatten<BuilderContent>(content);
287
- export const slice = (...content: BuilderContent[]) =>
288
- new Slice(Fragment.from(coerce(content, sampleSchema).nodes), 0, 0);
289
- export const mediaSingle = (attrs = {}) =>
290
- nodeFactory(sampleSchema.nodes.mediaSingle, attrs);
291
- export const mediaGroup = nodeFactory(sampleSchema.nodes.mediaGroup);
292
- export const mediaInline = (attrs: MediaInlineAttributes) =>
293
- sampleSchema.nodes.media.create(attrs);
294
- export const media = (attrs: MediaAttributes) =>
295
- sampleSchema.nodes.media.create(attrs);
296
- export const textColor = (attrs: { color: string }) =>
297
- markFactory(sampleSchema.marks.textColor, attrs);
298
- export const table = (attrs?: TableAttributes) =>
299
- nodeFactory(sampleSchema.nodes.table, attrs);
300
- export const tr = nodeFactory(sampleSchema.nodes.tableRow, {});
301
- export const td = (attrs: CellAttributes) =>
302
- nodeFactory(sampleSchema.nodes.tableCell, attrs);
303
- export const th = (attrs: CellAttributes) =>
304
- nodeFactory(sampleSchema.nodes.tableHeader, attrs);
305
- export const tdEmpty = td({})(p(''));
306
- export const thEmpty = th({})(p(''));
307
- export const tdCursor = td({})(p('{<>}'));
308
- export const thCursor = th({})(p('{<>}'));
309
- export const td11 = createCell(1, 1);
310
- export const th11 = createHeaderCell(1, 1);
311
- export const decisionList = nodeFactory(sampleSchema.nodes.decisionList, {});
312
- export const decisionItem = nodeFactory(sampleSchema.nodes.decisionItem, {});
313
- export const taskList = nodeFactory(sampleSchema.nodes.taskList, {});
314
- export const taskItem = nodeFactory(sampleSchema.nodes.taskItem, {});
315
- export const confluenceUnsupportedBlock = (cxhtml: string) =>
316
- nodeFactory(sampleSchema.nodes.confluenceUnsupportedBlock, { cxhtml })();
317
- export const confluenceUnsupportedInline = (cxhtml: string) =>
318
- nodeFactory(sampleSchema.nodes.confluenceUnsupportedInline, { cxhtml })();
319
- export const confluenceJiraIssue = (attrs: {
320
- issueKey?: string;
321
- macroId?: string;
322
- schemaVersion?: string;
323
- server?: string;
324
- serverId?: string;
325
- }) => sampleSchema.nodes.confluenceJiraIssue.create(attrs);
326
- export const unsupportedBlock = (originalValue: object) =>
327
- nodeFactory(sampleSchema.nodes.unsupportedBlock, { originalValue })();
328
- export const unsupportedInline = (originalValue: object) =>
329
- nodeFactory(sampleSchema.nodes.unsupportedInline, { originalValue })();
@@ -1,80 +0,0 @@
1
- import {
2
- AttributeSpec,
3
- MarkSpec,
4
- Node,
5
- NodeSpec,
6
- ParseRule,
7
- Schema,
8
- } from 'prosemirror-model';
9
- import { paragraph, createSchema } from '../src/schema';
10
-
11
- export { Node, Schema };
12
- export type { AttributeSpec, MarkSpec, NodeSpec, ParseRule };
13
- export default createSchema({
14
- nodes: [
15
- 'doc',
16
- 'paragraph',
17
- 'text',
18
- 'bulletList',
19
- 'orderedList',
20
- 'listItem',
21
- 'heading',
22
- 'blockquote',
23
- 'codeBlock',
24
- 'panel',
25
- 'rule',
26
- 'hardBreak',
27
- 'mention',
28
- 'emoji',
29
- 'image',
30
- 'caption',
31
- 'media',
32
- 'mediaGroup',
33
- 'mediaInline',
34
- 'confluenceUnsupportedBlock',
35
- 'confluenceUnsupportedInline',
36
- 'confluenceJiraIssue',
37
- 'mediaSingle',
38
- 'plain',
39
- 'table',
40
- 'tableCell',
41
- 'tableHeader',
42
- 'tableRow',
43
- 'decisionList',
44
- 'decisionItem',
45
- 'taskList',
46
- 'taskItem',
47
- 'extension',
48
- 'inlineExtension',
49
- 'bodiedExtension',
50
- 'date',
51
- 'status',
52
- 'unknownBlock',
53
- 'placeholder',
54
- 'inlineCard',
55
- 'blockCard',
56
- 'embedCard',
57
- 'expand',
58
- 'nestedExpand',
59
- 'unsupportedBlock',
60
- 'unsupportedInline',
61
- ],
62
- marks: [
63
- 'em',
64
- 'strong',
65
- 'code',
66
- 'strike',
67
- 'underline',
68
- 'link',
69
- 'subsup',
70
- 'textColor',
71
- 'unsupportedMark',
72
- 'unsupportedNodeAttribute',
73
- 'annotation',
74
- 'dataConsumer',
75
- 'fragment',
76
- ],
77
- customNodeSpecs: {
78
- plain: { ...paragraph, content: 'text*', marks: '' },
79
- },
80
- });