@atlaskit/adf-schema 44.3.0 → 44.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/adf-schema
2
2
 
3
+ ## 44.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bca057f: - fix content expressions cleanup logic
8
+ - add separate entry point for sanitizeNodes
9
+
10
+ ## 44.4.0
11
+
12
+ ### Minor Changes
13
+
14
+ - bd599ae: Give heading marks in pm-spec
15
+
3
16
  ## 44.3.0
4
17
 
5
18
  ### Minor Changes
@@ -407,6 +407,7 @@ var hardBreak = exports.hardBreak = (0, _createPMSpecFactory.createPMNodeSpecFac
407
407
  });
408
408
  var heading = exports.heading = (0, _createPMSpecFactory.createPMNodeSpecFactory)({
409
409
  content: 'inline*',
410
+ marks: 'link em strong strike subsup underline textColor annotation backgroundColor typeAheadQuery confluenceInlineComment unsupportedNodeAttribute unsupportedMark code dataConsumer fragment border',
410
411
  group: 'block',
411
412
  attrs: {
412
413
  level: {
@@ -13,9 +13,7 @@ var _unsupportedNodeAttribute = require("../marks/unsupportedNodeAttribute");
13
13
  var heading = exports.heading = (0, _adfSchemaGenerator.adfNode)('heading').define({
14
14
  defining: true,
15
15
  selectable: false,
16
- // Marks don't make it into the PM node spec, as they get overridden by the marks in
17
- // packages/adf-schema-generator/src/transforms/adfToPm/buildPmSpec.ts
18
- // marks: [unsupportedMark, unsupportedNodeAttribute],
16
+ marks: [_unsupportedMark.unsupportedMark, _unsupportedNodeAttribute.unsupportedNodeAttribute],
19
17
  hasEmptyMarks: true,
20
18
  attrs: {
21
19
  level: {
@@ -30,19 +28,7 @@ var heading = exports.heading = (0, _adfSchemaGenerator.adfNode)('heading').defi
30
28
  default: null
31
29
  }
32
30
  },
33
- content: [(0, _adfSchemaGenerator.$zeroPlus)((0, _adfSchemaGenerator.$or)(_inlineGroup.inlineGroup, _inlineContentGroup.inlineContentGroup))],
34
- DANGEROUS_MANUAL_OVERRIDE: {
35
- 'validator-spec': {
36
- 'props.marks': {
37
- value: {
38
- type: 'array',
39
- items: [],
40
- optional: true
41
- },
42
- reason: 'In old types, some nodes have marks: Array<any>, which is not possible to represent in new DSL'
43
- }
44
- }
45
- }
31
+ content: [(0, _adfSchemaGenerator.$zeroPlus)((0, _adfSchemaGenerator.$or)(_inlineGroup.inlineGroup, _inlineContentGroup.inlineContentGroup))]
46
32
  }).variant('with_alignment', {
47
33
  marks: [_alignmentAndIndentation.alignment, _unsupportedMark.unsupportedMark, _unsupportedNodeAttribute.unsupportedNodeAttribute],
48
34
  content: [],
@@ -21,19 +21,7 @@ var paragraph = exports.paragraph = (0, _adfSchemaGenerator.adfNode)('paragraph'
21
21
  selectable: false,
22
22
  marks: [_unsupportedMark.unsupportedMark, _unsupportedNodeAttribute.unsupportedNodeAttribute],
23
23
  hasEmptyMarks: true,
24
- content: [(0, _adfSchemaGenerator.$zeroPlus)((0, _adfSchemaGenerator.$or)(_inlineGroup.inlineGroup, _inlineContentGroup.inlineContentGroup))],
25
- DANGEROUS_MANUAL_OVERRIDE: {
26
- 'validator-spec': {
27
- 'props.marks': {
28
- value: {
29
- type: 'array',
30
- items: [],
31
- optional: true
32
- },
33
- reason: 'NoMark type used in old schema had a hack maxItems: 0 to mark nodes that should not have any marks. This is not possible to represent in new DSL.'
34
- }
35
- }
36
- }
24
+ content: [(0, _adfSchemaGenerator.$zeroPlus)((0, _adfSchemaGenerator.$or)(_inlineGroup.inlineGroup, _inlineContentGroup.inlineContentGroup))]
37
25
  }).variant('with_alignment', {
38
26
  marks: [_alignmentAndIndentation.alignment, _unsupportedMark.unsupportedMark, _unsupportedNodeAttribute.unsupportedNodeAttribute],
39
27
  content: [],
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.allowCustomPanel = void 0;
8
7
  exports.createSchema = createSchema;
9
8
  exports.getNodesAndMarksMap = getNodesAndMarksMap;
10
- exports.sanitizeNodeSpecContent = sanitizeNodeSpecContent;
11
- exports.sanitizeNodes = sanitizeNodes;
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
9
  var _model = require("@atlaskit/editor-prosemirror/model");
14
10
  var _groups = require("./groups");
11
+ var _sanitizeNodes = require("./sanitizeNodes");
15
12
  var _marks = require("./marks");
16
13
  var _nodes = require("./nodes");
17
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
14
  function addItems(builtInItems, config) {
20
15
  var customSpecs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
21
16
  if (!config) {
@@ -305,63 +300,10 @@ function createSchema(config) {
305
300
  var marksConfig = Object.keys(customMarkSpecs || {}).concat(config.marks || []).concat(markGroupDeclarationsNames);
306
301
  var nodes = addItems(nodesInOrder, nodesConfig, customNodeSpecs);
307
302
  var marks = addItems(marksInOrder, marksConfig, customMarkSpecs);
308
- nodes = sanitizeNodes(nodes, marks);
303
+ nodes = (0, _sanitizeNodes.sanitizeNodes)(nodes, marks);
309
304
  return new _model.Schema({
310
305
  nodes: nodes,
311
306
  marks: marks
312
307
  });
313
308
  }
314
- function sanitizeNodes(nodes, supportedMarks) {
315
- var nodeNames = Object.keys(nodes);
316
- nodeNames.forEach(function (nodeKey) {
317
- var nodeSpec = _objectSpread({}, nodes[nodeKey]);
318
- if (nodeSpec.marks && nodeSpec.marks !== '_') {
319
- nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
320
- return !!supportedMarks[mark];
321
- }).join(' ');
322
- }
323
- if (nodeSpec.content) {
324
- nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
325
- }
326
- nodes[nodeKey] = nodeSpec;
327
- });
328
- return nodes;
329
- }
330
- function sanitizeNodeSpecContent(nodes, rawContent) {
331
- var content = rawContent.replace(/\W/g, ' ');
332
- var contentKeys = content.split(' ');
333
- var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
334
- return !isContentSupported(nodes, contentKey);
335
- });
336
- return unsupportedContentKeys.reduce(function (newContent, nodeName) {
337
- return sanitizedContent(newContent, nodeName);
338
- }, rawContent);
339
- }
340
- function sanitizedContent(content, invalidContent) {
341
- if (!invalidContent.length) {
342
- return content || '';
343
- }
344
- if (!content || !content.match(/\w/)) {
345
- return '';
346
- }
347
- var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, ")|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
348
- return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
349
- }
350
- function isContentSupported(nodes, contentKey) {
351
- var nodeKeys = Object.keys(nodes);
352
-
353
- // content is with valid node
354
- if (nodeKeys.indexOf(contentKey) > -1) {
355
- return true;
356
- }
357
-
358
- // content is with valid group
359
- for (var supportedKey in nodes) {
360
- var nodeSpec = nodes[supportedKey];
361
- if (nodeSpec && nodeSpec.group === contentKey) {
362
- return true;
363
- }
364
- }
365
- return false;
366
- }
367
309
  var allowCustomPanel = exports.allowCustomPanel = true;
@@ -540,7 +540,7 @@ Object.defineProperty(exports, "rule", {
540
540
  Object.defineProperty(exports, "sanitizeNodes", {
541
541
  enumerable: true,
542
542
  get: function get() {
543
- return _createSchema.sanitizeNodes;
543
+ return _sanitizeNodes.sanitizeNodes;
544
544
  }
545
545
  });
546
546
  Object.defineProperty(exports, "status", {
@@ -776,4 +776,5 @@ var _marks = require("./marks");
776
776
  var _unsupported = require("./unsupported");
777
777
  var _inlineNodes = require("./inline-nodes");
778
778
  var _createSchema = require("./create-schema");
779
+ var _sanitizeNodes = require("./sanitizeNodes");
779
780
  var _createPMSpecFactory = require("./createPMSpecFactory");
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.sanitizeNodes = sanitizeNodes;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function sanitizeNodes(nodes, supportedMarks) {
12
+ var nodeNames = Object.keys(nodes);
13
+ nodeNames.forEach(function (nodeKey) {
14
+ var nodeSpec = _objectSpread({}, nodes[nodeKey]);
15
+ if (nodeSpec.marks && nodeSpec.marks !== '_') {
16
+ nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
17
+ return !!supportedMarks[mark];
18
+ }).join(' ');
19
+ }
20
+ if (nodeSpec.content) {
21
+ nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
22
+ }
23
+ nodes[nodeKey] = nodeSpec;
24
+ });
25
+ return nodes;
26
+ }
27
+ function sanitizeNodeSpecContent(nodes, rawContent) {
28
+ var content = rawContent.replace(/\W/g, ' ');
29
+ var contentKeys = content.split(' ');
30
+ var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
31
+ return !isContentSupported(nodes, contentKey);
32
+ });
33
+ return unsupportedContentKeys.reduce(function (newContent, nodeName) {
34
+ return sanitizedContent(newContent, nodeName);
35
+ }, rawContent);
36
+ }
37
+ function sanitizedContent(content, invalidContent) {
38
+ if (!invalidContent.length) {
39
+ return content || '';
40
+ }
41
+ if (!content || !content.match(/\w/)) {
42
+ return '';
43
+ }
44
+ var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, "(\\+|\\*)?)|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
45
+ return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
46
+ }
47
+ function isContentSupported(nodes, contentKey) {
48
+ var nodeKeys = Object.keys(nodes);
49
+
50
+ // content is with valid node
51
+ if (nodeKeys.indexOf(contentKey) > -1) {
52
+ return true;
53
+ }
54
+
55
+ // content is with valid group
56
+ for (var supportedKey in nodes) {
57
+ var nodeSpec = nodes[supportedKey];
58
+ if (nodeSpec && nodeSpec.group === contentKey) {
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
@@ -401,6 +401,7 @@ export const hardBreak = createPMNodeSpecFactory({
401
401
  });
402
402
  export const heading = createPMNodeSpecFactory({
403
403
  content: 'inline*',
404
+ marks: 'link em strong strike subsup underline textColor annotation backgroundColor typeAheadQuery confluenceInlineComment unsupportedNodeAttribute unsupportedMark code dataConsumer fragment border',
404
405
  group: 'block',
405
406
  attrs: {
406
407
  level: {
@@ -7,9 +7,7 @@ import { unsupportedNodeAttribute } from '../marks/unsupportedNodeAttribute';
7
7
  export const heading = adfNode('heading').define({
8
8
  defining: true,
9
9
  selectable: false,
10
- // Marks don't make it into the PM node spec, as they get overridden by the marks in
11
- // packages/adf-schema-generator/src/transforms/adfToPm/buildPmSpec.ts
12
- // marks: [unsupportedMark, unsupportedNodeAttribute],
10
+ marks: [unsupportedMark, unsupportedNodeAttribute],
13
11
  hasEmptyMarks: true,
14
12
  attrs: {
15
13
  level: {
@@ -24,19 +22,7 @@ export const heading = adfNode('heading').define({
24
22
  default: null
25
23
  }
26
24
  },
27
- content: [$zeroPlus($or(inlineGroup, inlineContentGroup))],
28
- DANGEROUS_MANUAL_OVERRIDE: {
29
- 'validator-spec': {
30
- 'props.marks': {
31
- value: {
32
- type: 'array',
33
- items: [],
34
- optional: true
35
- },
36
- reason: 'In old types, some nodes have marks: Array<any>, which is not possible to represent in new DSL'
37
- }
38
- }
39
- }
25
+ content: [$zeroPlus($or(inlineGroup, inlineContentGroup))]
40
26
  }).variant('with_alignment', {
41
27
  marks: [alignment, unsupportedMark, unsupportedNodeAttribute],
42
28
  content: [],
@@ -15,19 +15,7 @@ export const paragraph = adfNode('paragraph').define({
15
15
  selectable: false,
16
16
  marks: [unsupportedMark, unsupportedNodeAttribute],
17
17
  hasEmptyMarks: true,
18
- content: [$zeroPlus($or(inlineGroup, inlineContentGroup))],
19
- DANGEROUS_MANUAL_OVERRIDE: {
20
- 'validator-spec': {
21
- 'props.marks': {
22
- value: {
23
- type: 'array',
24
- items: [],
25
- optional: true
26
- },
27
- reason: 'NoMark type used in old schema had a hack maxItems: 0 to mark nodes that should not have any marks. This is not possible to represent in new DSL.'
28
- }
29
- }
30
- }
18
+ content: [$zeroPlus($or(inlineGroup, inlineContentGroup))]
31
19
  }).variant('with_alignment', {
32
20
  marks: [alignment, unsupportedMark, unsupportedNodeAttribute],
33
21
  content: [],
@@ -1,5 +1,6 @@
1
1
  import { Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import { COLOR, FONT_STYLE, SEARCH_QUERY, LINK } from './groups';
3
+ import { sanitizeNodes } from './sanitizeNodes';
3
4
  import { link, em, strong, textColor, strike, subsup, underline, code, typeAheadQuery, confluenceInlineComment, breakout, alignment, indentation, annotation, unsupportedMark, unsupportedNodeAttribute, dataConsumer, fragment, border, backgroundColor } from './marks';
4
5
  import { confluenceJiraIssue, confluenceUnsupportedBlock, confluenceUnsupportedInline, doc, paragraph, text, bulletList, orderedListWithOrder, listItemWithTask, heading, blockquoteWithNestedCodeblockOrMedia, codeBlock, extendedPanel, rule, image, mention, media, mediaInline, mediaSingleFull, mediaGroup, hardBreak, emoji, table, tableCell, tableHeader, tableRow, decisionList, decisionItem, taskList, taskItem, unknownBlock, extension, inlineExtension, bodiedExtension, multiBodiedExtension, extensionFrame, date, placeholder, layoutSection, layoutColumn, inlineCard, blockCard, unsupportedBlock, unsupportedInline, status, expandWithNestedExpand, nestedExpand, embedCard, caption } from './nodes';
5
6
  function addItems(builtInItems, config, customSpecs = {}) {
@@ -299,53 +300,4 @@ export function createSchema(config) {
299
300
  marks
300
301
  });
301
302
  }
302
- export function sanitizeNodes(nodes, supportedMarks) {
303
- const nodeNames = Object.keys(nodes);
304
- nodeNames.forEach(nodeKey => {
305
- const nodeSpec = {
306
- ...nodes[nodeKey]
307
- };
308
- if (nodeSpec.marks && nodeSpec.marks !== '_') {
309
- nodeSpec.marks = nodeSpec.marks.split(' ').filter(mark => !!supportedMarks[mark]).join(' ');
310
- }
311
- if (nodeSpec.content) {
312
- nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
313
- }
314
- nodes[nodeKey] = nodeSpec;
315
- });
316
- return nodes;
317
- }
318
- export function sanitizeNodeSpecContent(nodes, rawContent) {
319
- const content = rawContent.replace(/\W/g, ' ');
320
- const contentKeys = content.split(' ');
321
- const unsupportedContentKeys = contentKeys.filter(contentKey => !isContentSupported(nodes, contentKey));
322
- return unsupportedContentKeys.reduce((newContent, nodeName) => sanitizedContent(newContent, nodeName), rawContent);
323
- }
324
- function sanitizedContent(content, invalidContent) {
325
- if (!invalidContent.length) {
326
- return content || '';
327
- }
328
- if (!content || !content.match(/\w/)) {
329
- return '';
330
- }
331
- const pattern = `(${invalidContent}((\\s)*\\|)+)|((\\|(\\s)*)+${invalidContent})|(${invalidContent}$)|(${invalidContent}(\\+|\\*))`;
332
- return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
333
- }
334
- function isContentSupported(nodes, contentKey) {
335
- const nodeKeys = Object.keys(nodes);
336
-
337
- // content is with valid node
338
- if (nodeKeys.indexOf(contentKey) > -1) {
339
- return true;
340
- }
341
-
342
- // content is with valid group
343
- for (const supportedKey in nodes) {
344
- const nodeSpec = nodes[supportedKey];
345
- if (nodeSpec && nodeSpec.group === contentKey) {
346
- return true;
347
- }
348
- }
349
- return false;
350
- }
351
303
  export const allowCustomPanel = true;
@@ -3,7 +3,8 @@ export { AnnotationTypes, alignment, alignmentPositionMap, annotation, breakout,
3
3
  colorPaletteExtended, confluenceInlineComment, dataConsumer, dataConsumerToJSON, em, fragment, fragmentToJSON, indentation, link, linkToJSON, strike, strong, subsup, textColor, typeAheadQuery, underline, buildAnnotationMarkDataAttributes, AnnotationMarkStates, unsupportedMark, unsupportedNodeAttribute, border, borderColorPalette, backgroundColor, backgroundColorPalette } from './marks';
4
4
  export { unsupportedNodeTypesForMediaCards } from './unsupported';
5
5
  export { inlineNodes } from './inline-nodes';
6
- export { sanitizeNodes, createSchema } from './create-schema';
6
+ export { createSchema } from './create-schema';
7
+ export { sanitizeNodes } from './sanitizeNodes';
7
8
 
8
9
  // ADF createPMSpecFactory
9
10
 
@@ -0,0 +1,49 @@
1
+ export function sanitizeNodes(nodes, supportedMarks) {
2
+ const nodeNames = Object.keys(nodes);
3
+ nodeNames.forEach(nodeKey => {
4
+ const nodeSpec = {
5
+ ...nodes[nodeKey]
6
+ };
7
+ if (nodeSpec.marks && nodeSpec.marks !== '_') {
8
+ nodeSpec.marks = nodeSpec.marks.split(' ').filter(mark => !!supportedMarks[mark]).join(' ');
9
+ }
10
+ if (nodeSpec.content) {
11
+ nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
12
+ }
13
+ nodes[nodeKey] = nodeSpec;
14
+ });
15
+ return nodes;
16
+ }
17
+ function sanitizeNodeSpecContent(nodes, rawContent) {
18
+ const content = rawContent.replace(/\W/g, ' ');
19
+ const contentKeys = content.split(' ');
20
+ const unsupportedContentKeys = contentKeys.filter(contentKey => !isContentSupported(nodes, contentKey));
21
+ return unsupportedContentKeys.reduce((newContent, nodeName) => sanitizedContent(newContent, nodeName), rawContent);
22
+ }
23
+ function sanitizedContent(content, invalidContent) {
24
+ if (!invalidContent.length) {
25
+ return content || '';
26
+ }
27
+ if (!content || !content.match(/\w/)) {
28
+ return '';
29
+ }
30
+ const pattern = `(${invalidContent}((\\s)*\\|)+)|((\\|(\\s)*)+${invalidContent}(\\+|\\*)?)|(${invalidContent}$)|(${invalidContent}(\\+|\\*))`;
31
+ return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
32
+ }
33
+ function isContentSupported(nodes, contentKey) {
34
+ const nodeKeys = Object.keys(nodes);
35
+
36
+ // content is with valid node
37
+ if (nodeKeys.indexOf(contentKey) > -1) {
38
+ return true;
39
+ }
40
+
41
+ // content is with valid group
42
+ for (const supportedKey in nodes) {
43
+ const nodeSpec = nodes[supportedKey];
44
+ if (nodeSpec && nodeSpec.group === contentKey) {
45
+ return true;
46
+ }
47
+ }
48
+ return false;
49
+ }
@@ -401,6 +401,7 @@ export var hardBreak = createPMNodeSpecFactory({
401
401
  });
402
402
  export var heading = createPMNodeSpecFactory({
403
403
  content: 'inline*',
404
+ marks: 'link em strong strike subsup underline textColor annotation backgroundColor typeAheadQuery confluenceInlineComment unsupportedNodeAttribute unsupportedMark code dataConsumer fragment border',
404
405
  group: 'block',
405
406
  attrs: {
406
407
  level: {
@@ -7,9 +7,7 @@ import { unsupportedNodeAttribute } from '../marks/unsupportedNodeAttribute';
7
7
  export var heading = adfNode('heading').define({
8
8
  defining: true,
9
9
  selectable: false,
10
- // Marks don't make it into the PM node spec, as they get overridden by the marks in
11
- // packages/adf-schema-generator/src/transforms/adfToPm/buildPmSpec.ts
12
- // marks: [unsupportedMark, unsupportedNodeAttribute],
10
+ marks: [unsupportedMark, unsupportedNodeAttribute],
13
11
  hasEmptyMarks: true,
14
12
  attrs: {
15
13
  level: {
@@ -24,19 +22,7 @@ export var heading = adfNode('heading').define({
24
22
  default: null
25
23
  }
26
24
  },
27
- content: [$zeroPlus($or(inlineGroup, inlineContentGroup))],
28
- DANGEROUS_MANUAL_OVERRIDE: {
29
- 'validator-spec': {
30
- 'props.marks': {
31
- value: {
32
- type: 'array',
33
- items: [],
34
- optional: true
35
- },
36
- reason: 'In old types, some nodes have marks: Array<any>, which is not possible to represent in new DSL'
37
- }
38
- }
39
- }
25
+ content: [$zeroPlus($or(inlineGroup, inlineContentGroup))]
40
26
  }).variant('with_alignment', {
41
27
  marks: [alignment, unsupportedMark, unsupportedNodeAttribute],
42
28
  content: [],
@@ -15,19 +15,7 @@ export var paragraph = adfNode('paragraph').define({
15
15
  selectable: false,
16
16
  marks: [unsupportedMark, unsupportedNodeAttribute],
17
17
  hasEmptyMarks: true,
18
- content: [$zeroPlus($or(inlineGroup, inlineContentGroup))],
19
- DANGEROUS_MANUAL_OVERRIDE: {
20
- 'validator-spec': {
21
- 'props.marks': {
22
- value: {
23
- type: 'array',
24
- items: [],
25
- optional: true
26
- },
27
- reason: 'NoMark type used in old schema had a hack maxItems: 0 to mark nodes that should not have any marks. This is not possible to represent in new DSL.'
28
- }
29
- }
30
- }
18
+ content: [$zeroPlus($or(inlineGroup, inlineContentGroup))]
31
19
  }).variant('with_alignment', {
32
20
  marks: [alignment, unsupportedMark, unsupportedNodeAttribute],
33
21
  content: [],
@@ -1,8 +1,6 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
1
  import { Schema } from '@atlaskit/editor-prosemirror/model';
5
2
  import { COLOR, FONT_STYLE, SEARCH_QUERY, LINK } from './groups';
3
+ import { sanitizeNodes } from './sanitizeNodes';
6
4
  import { link, em, strong, textColor, strike, subsup, underline, code, typeAheadQuery, confluenceInlineComment, breakout, alignment, indentation, annotation, unsupportedMark, unsupportedNodeAttribute, dataConsumer, fragment, border, backgroundColor } from './marks';
7
5
  import { confluenceJiraIssue, confluenceUnsupportedBlock, confluenceUnsupportedInline, doc, paragraph, text, bulletList, orderedListWithOrder, listItemWithTask, heading, blockquoteWithNestedCodeblockOrMedia, codeBlock, extendedPanel, rule, image, mention, media, mediaInline, mediaSingleFull, mediaGroup, hardBreak, emoji, table, tableCell, tableHeader, tableRow, decisionList, decisionItem, taskList, taskItem, unknownBlock, extension, inlineExtension, bodiedExtension, multiBodiedExtension, extensionFrame, date, placeholder, layoutSection, layoutColumn, inlineCard, blockCard, unsupportedBlock, unsupportedInline, status, expandWithNestedExpand, nestedExpand, embedCard, caption } from './nodes';
8
6
  function addItems(builtInItems, config) {
@@ -300,57 +298,4 @@ export function createSchema(config) {
300
298
  marks: marks
301
299
  });
302
300
  }
303
- export function sanitizeNodes(nodes, supportedMarks) {
304
- var nodeNames = Object.keys(nodes);
305
- nodeNames.forEach(function (nodeKey) {
306
- var nodeSpec = _objectSpread({}, nodes[nodeKey]);
307
- if (nodeSpec.marks && nodeSpec.marks !== '_') {
308
- nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
309
- return !!supportedMarks[mark];
310
- }).join(' ');
311
- }
312
- if (nodeSpec.content) {
313
- nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
314
- }
315
- nodes[nodeKey] = nodeSpec;
316
- });
317
- return nodes;
318
- }
319
- export function sanitizeNodeSpecContent(nodes, rawContent) {
320
- var content = rawContent.replace(/\W/g, ' ');
321
- var contentKeys = content.split(' ');
322
- var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
323
- return !isContentSupported(nodes, contentKey);
324
- });
325
- return unsupportedContentKeys.reduce(function (newContent, nodeName) {
326
- return sanitizedContent(newContent, nodeName);
327
- }, rawContent);
328
- }
329
- function sanitizedContent(content, invalidContent) {
330
- if (!invalidContent.length) {
331
- return content || '';
332
- }
333
- if (!content || !content.match(/\w/)) {
334
- return '';
335
- }
336
- var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, ")|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
337
- return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
338
- }
339
- function isContentSupported(nodes, contentKey) {
340
- var nodeKeys = Object.keys(nodes);
341
-
342
- // content is with valid node
343
- if (nodeKeys.indexOf(contentKey) > -1) {
344
- return true;
345
- }
346
-
347
- // content is with valid group
348
- for (var supportedKey in nodes) {
349
- var nodeSpec = nodes[supportedKey];
350
- if (nodeSpec && nodeSpec.group === contentKey) {
351
- return true;
352
- }
353
- }
354
- return false;
355
- }
356
301
  export var allowCustomPanel = true;
@@ -3,7 +3,8 @@ export { AnnotationTypes, alignment, alignmentPositionMap, annotation, breakout,
3
3
  colorPaletteExtended, confluenceInlineComment, dataConsumer, dataConsumerToJSON, em, fragment, fragmentToJSON, indentation, link, linkToJSON, strike, strong, subsup, textColor, typeAheadQuery, underline, buildAnnotationMarkDataAttributes, AnnotationMarkStates, unsupportedMark, unsupportedNodeAttribute, border, borderColorPalette, backgroundColor, backgroundColorPalette } from './marks';
4
4
  export { unsupportedNodeTypesForMediaCards } from './unsupported';
5
5
  export { inlineNodes } from './inline-nodes';
6
- export { sanitizeNodes, createSchema } from './create-schema';
6
+ export { createSchema } from './create-schema';
7
+ export { sanitizeNodes } from './sanitizeNodes';
7
8
 
8
9
  // ADF createPMSpecFactory
9
10
 
@@ -0,0 +1,56 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ export function sanitizeNodes(nodes, supportedMarks) {
5
+ var nodeNames = Object.keys(nodes);
6
+ nodeNames.forEach(function (nodeKey) {
7
+ var nodeSpec = _objectSpread({}, nodes[nodeKey]);
8
+ if (nodeSpec.marks && nodeSpec.marks !== '_') {
9
+ nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
10
+ return !!supportedMarks[mark];
11
+ }).join(' ');
12
+ }
13
+ if (nodeSpec.content) {
14
+ nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
15
+ }
16
+ nodes[nodeKey] = nodeSpec;
17
+ });
18
+ return nodes;
19
+ }
20
+ function sanitizeNodeSpecContent(nodes, rawContent) {
21
+ var content = rawContent.replace(/\W/g, ' ');
22
+ var contentKeys = content.split(' ');
23
+ var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
24
+ return !isContentSupported(nodes, contentKey);
25
+ });
26
+ return unsupportedContentKeys.reduce(function (newContent, nodeName) {
27
+ return sanitizedContent(newContent, nodeName);
28
+ }, rawContent);
29
+ }
30
+ function sanitizedContent(content, invalidContent) {
31
+ if (!invalidContent.length) {
32
+ return content || '';
33
+ }
34
+ if (!content || !content.match(/\w/)) {
35
+ return '';
36
+ }
37
+ var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, "(\\+|\\*)?)|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
38
+ return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
39
+ }
40
+ function isContentSupported(nodes, contentKey) {
41
+ var nodeKeys = Object.keys(nodes);
42
+
43
+ // content is with valid node
44
+ if (nodeKeys.indexOf(contentKey) > -1) {
45
+ return true;
46
+ }
47
+
48
+ // content is with valid group
49
+ for (var supportedKey in nodes) {
50
+ var nodeSpec = nodes[supportedKey];
51
+ if (nodeSpec && nodeSpec.group === contentKey) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ }
@@ -295,6 +295,7 @@ export declare const hardBreak: ({ parseDOM, toDOM, toDebugString }: import("../
295
295
  export interface HeadingDefinition {
296
296
  type: 'heading';
297
297
  content: Array<InlineDefinition>;
298
+ marks: Array<UnsupportedMarkMark | UnsupportedNodeAttributeMark>;
298
299
  attrs: {
299
300
  level: number;
300
301
  localId?: string;
@@ -7,16 +7,6 @@ export declare function getNodesAndMarksMap(): {
7
7
  * Creates a schema preserving order of marks and nodes.
8
8
  */
9
9
  export declare function createSchema<N extends string = string, M extends string = string>(config: SchemaConfig<N, M>): Schema<N, M>;
10
- export declare function sanitizeNodes(nodes: {
11
- [key: string]: NodeSpec;
12
- }, supportedMarks: {
13
- [key: string]: MarkSpec;
14
- }): {
15
- [key: string]: NodeSpec;
16
- };
17
- export declare function sanitizeNodeSpecContent(nodes: {
18
- [key: string]: NodeSpec;
19
- }, rawContent: string): string;
20
10
  export interface SchemaConfig<N = string, M = string> {
21
11
  nodes: N[];
22
12
  customNodeSpecs?: SchemaCustomNodeSpecs;
@@ -6,6 +6,7 @@ colorPaletteExtended, confluenceInlineComment, dataConsumer, dataConsumerToJSON,
6
6
  export type { AlignmentAttributes, AlignmentMarkDefinition, AnnotationMarkAttributes, AnnotationMarkDefinition, BreakoutMarkAttrs, BreakoutMarkDefinition, CodeDefinition, EmDefinition, FragmentAttributes, FragmentDefinition, IndentationMarkAttributes, IndentationMarkDefinition, LinkAttributes, LinkDefinition, StrikeDefinition, StrongDefinition, SubSupAttributes, SubSupDefinition, TextColorAttributes, TextColorDefinition, UnderlineDefinition, AnnotationId, AnnotationDataAttributes, DataConsumerAttributes, DataConsumerDefinition, BorderMarkAttributes, BorderMarkDefinition, BackgroundColorDefinition, } from './marks';
7
7
  export { unsupportedNodeTypesForMediaCards } from './unsupported';
8
8
  export { inlineNodes } from './inline-nodes';
9
- export { sanitizeNodes, createSchema } from './create-schema';
9
+ export { createSchema } from './create-schema';
10
+ export { sanitizeNodes } from './sanitizeNodes';
10
11
  export type { NodeSpecOptions, MarkSpecOptions } from './createPMSpecFactory';
11
12
  export { createPMNodeSpecFactory, createPMMarkSpecFactory, } from './createPMSpecFactory';
@@ -0,0 +1,8 @@
1
+ import { NodeSpec, MarkSpec } from '@atlaskit/editor-prosemirror/model';
2
+ export declare function sanitizeNodes(nodes: {
3
+ [key: string]: NodeSpec;
4
+ }, supportedMarks: {
5
+ [key: string]: MarkSpec;
6
+ }): {
7
+ [key: string]: NodeSpec;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/adf-schema",
3
- "version": "44.3.0",
3
+ "version": "44.5.0",
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/"
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@atlassian/adf-schema-json": "^1.24.0",
49
- "@atlaskit/adf-schema-generator": "^1.36.1",
49
+ "@atlaskit/adf-schema-generator": "^1.37.0",
50
50
  "@atlaskit/codemod-utils": "^4.2.4",
51
51
  "@babel/cli": "^7.22.9",
52
52
  "@babel/core": "^7.22.9",
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@atlaskit/adf-schema/sanitize-nodes",
3
+ "main": "../dist/cjs/schema/sanitizeNodes.js",
4
+ "module": "../dist/esm/schema/sanitizeNodes.js",
5
+ "module:es2019": "../dist/es2019/schema/sanitizeNodes.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/schema/sanitizeNodes.d.ts"
8
+ }