Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@atlaskit/adf-schema-generator

Package Overview
Dependencies
Maintainers
2
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlaskit/adf-schema-generator - npm Package Compare versions

Comparing version 1.13.0 to 1.14.0

src/__tests__/unit/adfToPM/buildContentExpression.ts

4

CHANGELOG.md
# @atlaskit/adf-schema-generator
## 1.13.0
## 1.14.0
### Minor Changes
- 8df4b1b: Sync generated Pm Spec files
- e0c8b0e: Add suuport for all and no child marks in DSL

@@ -52,3 +52,3 @@ "use strict";

nodeGroupMap[_group.group] = _group.members.map(function (m) {
return m.getType();
return m.getName();
});

@@ -55,0 +55,0 @@ return {

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -7,8 +8,10 @@ value: true

exports.buildContentExpression = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var buildContentExpression = exports.buildContentExpression = function buildContentExpression(expr, operator) {
var expression = expr.join(' | ');
var exprs = Array.apply(void 0, (0, _toConsumableArray2.default)(new Set(expr)));
var expression = exprs.length === 1 ? exprs[0] : "(".concat(exprs.join(' | '), ")");
if (operator) {
expression = expr.length === 1 ? "".concat(expression).concat(operator) : "(".concat(expression, ")").concat(operator);
expression = "".concat(expression).concat(operator);
}
return expression;
};

@@ -19,2 +19,4 @@ "use strict";

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; }
var allowLinkMarkInNodes = ['mediaInline', 'media', 'mediaGroup', 'paragraph', 'mediaSingle'];
var excludesIndentationNodes = ['tableHeader', 'tableCell'];
var buildAttrs = exports.buildAttrs = function buildAttrs(attrs) {

@@ -53,2 +55,13 @@ var attributes = attrs;

};
var filterMarks = function filterMarks(node) {
return function (mark) {
if (mark === 'link') {
return allowLinkMarkInNodes.includes(node.getType());
}
if (mark === 'indentation') {
return !excludesIndentationNodes.includes(node.getType());
}
return true;
};
};
var buildMarkSpec = exports.buildMarkSpec = function buildMarkSpec(mark) {

@@ -71,2 +84,3 @@ var pmMarkSpec = {};

};
var NODES_WITH_UNDEFINED_MARKS = new Set(['heading']);
var buildNodeSpec = exports.buildNodeSpec = function buildNodeSpec(node, content) {

@@ -80,5 +94,6 @@ var pmNodeSpec = {};

for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _marks;
var child = _step.value;
contents.push((0, _buildContentExpression.buildContentExpression)(child.expr));
marks.push.apply(marks, (0, _toConsumableArray2.default)(child.marks));
(_marks = marks).push.apply(_marks, (0, _toConsumableArray2.default)(child.marks));
}

@@ -90,4 +105,17 @@ } catch (err) {

}
pmNodeSpec.content = Array.apply(void 0, (0, _toConsumableArray2.default)(new Set(contents))).join(' ');
pmNodeSpec.marks = Array.apply(void 0, (0, _toConsumableArray2.default)(new Set(marks))).join(' ');
if (NODES_WITH_UNDEFINED_MARKS.has(node.getType())) {
marks = [];
} else if (node.getSpec().allowAnyChildMark) {
marks = ['_'];
} else if (node.getSpec().allowNoChildMark) {
marks = [''];
} else {
marks = Array.apply(void 0, (0, _toConsumableArray2.default)(new Set(marks))).filter(filterMarks(node));
}
if (content.length) {
pmNodeSpec.content = Array.apply(void 0, (0, _toConsumableArray2.default)(new Set(contents))).join(' ');
}
if (marks.length) {
pmNodeSpec.marks = marks.join(' ');
}
pmNodeSpec.group = node.getGroup();

@@ -105,2 +133,3 @@ pmNodeSpec.inline = node.getSpec().inline;

pmNodeSpec.isolating = node.getSpec().isolating;
pmNodeSpec.tableRole = node.getSpec().tableRole;
return Object.entries(pmNodeSpec).reduce(function (acc, _ref5) {

@@ -110,3 +139,3 @@ var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),

value = _ref6[1];
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
acc[key] = value;

@@ -113,0 +142,0 @@ }

@@ -41,3 +41,3 @@ import { traverse } from '../../traverse';

group: (group, members) => {
nodeGroupMap[group.group] = group.members.map(m => m.getType());
nodeGroupMap[group.group] = group.members.map(m => m.getName());
return {

@@ -44,0 +44,0 @@ group: group.group,

export const buildContentExpression = (expr, operator) => {
let expression = expr.join(' | ');
const exprs = Array(...new Set(expr));
let expression = exprs.length === 1 ? exprs[0] : `(${exprs.join(' | ')})`;
if (operator) {
expression = expr.length === 1 ? `${expression}${operator}` : `(${expression})${operator}`;
expression = `${expression}${operator}`;
}
return expression;
};
import merge from 'lodash/merge';
import { ADFMark } from '../../adfMark';
import { buildContentExpression } from './buildContentExpression';
const allowLinkMarkInNodes = ['mediaInline', 'media', 'mediaGroup', 'paragraph', 'mediaSingle'];
const excludesIndentationNodes = ['tableHeader', 'tableCell'];
export const buildAttrs = attrs => {

@@ -40,2 +42,11 @@ let attributes = attrs;

};
const filterMarks = node => mark => {
if (mark === 'link') {
return allowLinkMarkInNodes.includes(node.getType());
}
if (mark === 'indentation') {
return !excludesIndentationNodes.includes(node.getType());
}
return true;
};
export const buildMarkSpec = mark => {

@@ -55,5 +66,6 @@ const pmMarkSpec = {};

};
const NODES_WITH_UNDEFINED_MARKS = new Set(['heading']);
export const buildNodeSpec = (node, content) => {
const pmNodeSpec = {};
const marks = [];
let marks = [];
const contents = [];

@@ -64,4 +76,17 @@ for (const child of content) {

}
pmNodeSpec.content = Array(...new Set(contents)).join(' ');
pmNodeSpec.marks = Array(...new Set(marks)).join(' ');
if (NODES_WITH_UNDEFINED_MARKS.has(node.getType())) {
marks = [];
} else if (node.getSpec().allowAnyChildMark) {
marks = ['_'];
} else if (node.getSpec().allowNoChildMark) {
marks = [''];
} else {
marks = Array(...new Set(marks)).filter(filterMarks(node));
}
if (content.length) {
pmNodeSpec.content = Array(...new Set(contents)).join(' ');
}
if (marks.length) {
pmNodeSpec.marks = marks.join(' ');
}
pmNodeSpec.group = node.getGroup();

@@ -79,4 +104,5 @@ pmNodeSpec.inline = node.getSpec().inline;

pmNodeSpec.isolating = node.getSpec().isolating;
pmNodeSpec.tableRole = node.getSpec().tableRole;
return Object.entries(pmNodeSpec).reduce((acc, [key, value]) => {
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
acc[key] = value;

@@ -83,0 +109,0 @@ }

@@ -45,3 +45,3 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

nodeGroupMap[_group.group] = _group.members.map(function (m) {
return m.getType();
return m.getName();
});

@@ -48,0 +48,0 @@ return {

@@ -0,7 +1,9 @@

import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
export var buildContentExpression = function buildContentExpression(expr, operator) {
var expression = expr.join(' | ');
var exprs = Array.apply(void 0, _toConsumableArray(new Set(expr)));
var expression = exprs.length === 1 ? exprs[0] : "(".concat(exprs.join(' | '), ")");
if (operator) {
expression = expr.length === 1 ? "".concat(expression).concat(operator) : "(".concat(expression, ")").concat(operator);
expression = "".concat(expression).concat(operator);
}
return expression;
};

@@ -12,2 +12,4 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

import { buildContentExpression } from './buildContentExpression';
var allowLinkMarkInNodes = ['mediaInline', 'media', 'mediaGroup', 'paragraph', 'mediaSingle'];
var excludesIndentationNodes = ['tableHeader', 'tableCell'];
export var buildAttrs = function buildAttrs(attrs) {

@@ -46,2 +48,13 @@ var attributes = attrs;

};
var filterMarks = function filterMarks(node) {
return function (mark) {
if (mark === 'link') {
return allowLinkMarkInNodes.includes(node.getType());
}
if (mark === 'indentation') {
return !excludesIndentationNodes.includes(node.getType());
}
return true;
};
};
export var buildMarkSpec = function buildMarkSpec(mark) {

@@ -64,2 +77,3 @@ var pmMarkSpec = {};

};
var NODES_WITH_UNDEFINED_MARKS = new Set(['heading']);
export var buildNodeSpec = function buildNodeSpec(node, content) {

@@ -73,5 +87,6 @@ var pmNodeSpec = {};

for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _marks;
var child = _step.value;
contents.push(buildContentExpression(child.expr));
marks.push.apply(marks, _toConsumableArray(child.marks));
(_marks = marks).push.apply(_marks, _toConsumableArray(child.marks));
}

@@ -83,4 +98,17 @@ } catch (err) {

}
pmNodeSpec.content = Array.apply(void 0, _toConsumableArray(new Set(contents))).join(' ');
pmNodeSpec.marks = Array.apply(void 0, _toConsumableArray(new Set(marks))).join(' ');
if (NODES_WITH_UNDEFINED_MARKS.has(node.getType())) {
marks = [];
} else if (node.getSpec().allowAnyChildMark) {
marks = ['_'];
} else if (node.getSpec().allowNoChildMark) {
marks = [''];
} else {
marks = Array.apply(void 0, _toConsumableArray(new Set(marks))).filter(filterMarks(node));
}
if (content.length) {
pmNodeSpec.content = Array.apply(void 0, _toConsumableArray(new Set(contents))).join(' ');
}
if (marks.length) {
pmNodeSpec.marks = marks.join(' ');
}
pmNodeSpec.group = node.getGroup();

@@ -98,2 +126,3 @@ pmNodeSpec.inline = node.getSpec().inline;

pmNodeSpec.isolating = node.getSpec().isolating;
pmNodeSpec.tableRole = node.getSpec().tableRole;
return Object.entries(pmNodeSpec).reduce(function (acc, _ref5) {

@@ -103,3 +132,3 @@ var _ref6 = _slicedToArray(_ref5, 2),

value = _ref6[1];
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
acc[key] = value;

@@ -106,0 +135,0 @@ }

@@ -8,4 +8,4 @@ import { DOMOutputSpec, Node as PMNode, NodeSpec, Mark, MarkSpec } from '@atlaskit/editor-prosemirror/model';

export type MarkSpecOptions<M extends Mark> = {
toDOM: (mark: M, inline: boolean) => DOMOutputSpec;
parseDOM: MarkSpec['parseDOM'];
toDOM?: (mark: M, inline: boolean) => DOMOutputSpec;
parseDOM?: MarkSpec['parseDOM'];
};

@@ -22,3 +22,3 @@ export type MarkSpecFactory = typeof createPMMarkSpecFactory;

*/
export declare const createPMNodeSpecFactory: <N extends Omit<PMNode, "parseDOM" | "toDom">>(nodeSpec: NodeSpec) => ({ parseDOM, toDOM }: NodeSpecOptions<N>) => NodeSpec;
export declare const createPMNodeSpecFactory: <N extends Omit<PMNode, "parseDOM" | "toDOM">>(nodeSpec: NodeSpec) => ({ parseDOM, toDOM }: NodeSpecOptions<N>) => NodeSpec;
/**

@@ -33,2 +33,2 @@ * Factory method to attach custom parseDOM and/or toDOM for markSpec

*/
export declare const createPMMarkSpecFactory: <M extends Omit<Mark, "parseDOM" | "toDom">>(markSpec: MarkSpec) => ({ parseDOM, toDOM }: MarkSpecOptions<M>) => MarkSpec;
export declare const createPMMarkSpecFactory: <M extends Omit<Mark, "parseDOM" | "toDOM">>(markSpec: MarkSpec) => ({ parseDOM, toDOM }: MarkSpecOptions<M>) => MarkSpec;

@@ -97,2 +97,14 @@ import { ADFNode } from '../adfNode';

/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.marks
*
* If true, it's equivalent to marks: '_'. Which means allow any mark on a child node.
*/
allowAnyChildMark?: boolean;
/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.marks
*
* If true, it's equivalent to marks: ''. Which means disallow any mark on a child node.
*/
allowNoChildMark?: boolean;
/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.selectable

@@ -112,2 +124,7 @@ *

whitespace?: 'pre' | 'normal';
/**
* Non-standard attributes that are used to define the role of the node in the document.
* These attributes don't exist in the ProseMirror schema docs. And were migrated from the prosemirror-tables package.
*/
tableRole?: 'table' | 'cell' | 'header_cell' | 'row';
};

@@ -114,0 +131,0 @@ type ADFTextNodeSpec = never;

{
"name": "@atlaskit/adf-schema-generator",
"version": "1.13.0",
"version": "1.14.0",
"description": "Generates ADF and PM schemas",

@@ -5,0 +5,0 @@ "repository": "https://bitbucket.org/atlassian/adf-schema",

@@ -61,3 +61,11 @@ import {

});
const inlineGroup = adfNodeGroup('inline', [text.use('code_inline'), emoji]);
const placeholder = adfNode('placeholder').define({
inline: true,
allowNoChildMark: true,
});
const inlineGroup = adfNodeGroup('inline', [
text.use('code_inline'),
emoji,
placeholder,
]);
const paragraph = adfNode('paragraph')

@@ -72,5 +80,11 @@ .define({

.variant('with_no_marks', {});
const decisionList = adfNode('decisionList').define({
selectable: false,
allowAnyChildMark: true,
content: [$onePlus($or(paragraph.use('with_alignment')))],
});
const blockGroup = adfNodeGroup('block', [
paragraph.use('with_alignment'),
paragraph.use('with_no_marks'),
decisionList,
]);

@@ -77,0 +91,0 @@ const blockRootOnlyGroup = adfNodeGroup('blockRootOnly');

@@ -33,5 +33,9 @@ import { adfToPm, transform } from '../../../transforms/adfToPm/adfToPm';

expect(transform(testDoc).nodeGroupMap).toEqual({
block: ['paragraph', 'paragraph'],
block: [
'paragraph_with_alignment',
'paragraph_with_no_marks',
'decisionList',
],
blockRootOnly: [],
inline: ['text', 'emoji'],
inline: ['text_code_inline', 'emoji', 'placeholder'],
});

@@ -114,2 +118,29 @@ });

},
decisionList: {
nodeTypeDefintion: {
attrs: undefined,
content: ['ParagraphWithAlignmentDefinition'],
marks: [],
type: 'decisionList',
},
pmNodeSpec: {
content: 'paragraph+',
selectable: false,
group: 'block',
marks: '_',
},
},
placeholder: {
nodeTypeDefintion: {
attrs: undefined,
content: [],
marks: [],
type: 'placeholder',
},
pmNodeSpec: {
group: 'inline',
inline: true,
marks: '',
},
},
});

@@ -116,0 +147,0 @@ });

@@ -59,3 +59,3 @@ import type { ADFNode } from '../../adfNode';

group: (group, members) => {
nodeGroupMap[group.group] = group.members.map((m) => m.getType());
nodeGroupMap[group.group] = group.members.map((m) => m.getName());
return { group: group.group, members };

@@ -62,0 +62,0 @@ },

@@ -5,10 +5,8 @@ export const buildContentExpression = (

): string => {
let expression = expr.join(' | ');
const exprs = Array(...new Set(expr));
let expression = exprs.length === 1 ? exprs[0] : `(${exprs.join(' | ')})`;
if (operator) {
expression =
expr.length === 1
? `${expression}${operator}`
: `(${expression})${operator}`;
expression = `${expression}${operator}`;
}
return expression;
};

@@ -10,2 +10,12 @@ import { MarkSpec, NodeSpec } from '@atlaskit/editor-prosemirror/model';

const allowLinkMarkInNodes = [
'mediaInline',
'media',
'mediaGroup',
'paragraph',
'mediaSingle',
];
const excludesIndentationNodes = ['tableHeader', 'tableCell'];
export const buildAttrs = (

@@ -56,2 +66,12 @@ attrs?: ADFAttributes,

const filterMarks = (node: ADFNode<any>) => (mark: string) => {
if (mark === 'link') {
return allowLinkMarkInNodes.includes(node.getType());
}
if (mark === 'indentation') {
return !excludesIndentationNodes.includes(node.getType());
}
return true;
};
export const buildMarkSpec = (mark: ADFMark<ADFMarkSpec>): MarkSpec => {

@@ -74,2 +94,4 @@ const pmMarkSpec: MarkSpec = {};

const NODES_WITH_UNDEFINED_MARKS = new Set(['heading']);
export const buildNodeSpec = (

@@ -80,3 +102,3 @@ node: ADFNode<any>,

const pmNodeSpec: NodeSpec = {};
const marks = [];
let marks: string[] = [];
const contents = [];

@@ -87,4 +109,21 @@ for (const child of content) {

}
pmNodeSpec.content = Array(...new Set(contents)).join(' ');
pmNodeSpec.marks = Array(...new Set(marks)).join(' ');
if (NODES_WITH_UNDEFINED_MARKS.has(node.getType())) {
marks = [];
} else if (node.getSpec().allowAnyChildMark) {
marks = ['_'];
} else if (node.getSpec().allowNoChildMark) {
marks = [''];
} else {
marks = Array(...new Set(marks)).filter(filterMarks(node));
}
if (content.length) {
pmNodeSpec.content = Array(...new Set(contents)).join(' ');
}
if (marks.length) {
pmNodeSpec.marks = marks.join(' ');
}
pmNodeSpec.group = node.getGroup();

@@ -102,5 +141,6 @@ pmNodeSpec.inline = node.getSpec().inline;

pmNodeSpec.isolating = node.getSpec().isolating;
pmNodeSpec.tableRole = node.getSpec().tableRole;
return Object.entries(pmNodeSpec).reduce((acc, [key, value]) => {
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
acc[key] = value;

@@ -107,0 +147,0 @@ }

@@ -17,4 +17,4 @@ import {

export type MarkSpecOptions<M extends Mark> = {
toDOM: (mark: M, inline: boolean) => DOMOutputSpec;
parseDOM: MarkSpec['parseDOM'];
toDOM?: (mark: M, inline: boolean) => DOMOutputSpec;
parseDOM?: MarkSpec['parseDOM'];
};

@@ -34,3 +34,3 @@

export const createPMNodeSpecFactory =
<N extends Omit<PMNode, 'toDom' | 'parseDOM'>>(nodeSpec: NodeSpec) =>
<N extends Omit<PMNode, 'toDOM' | 'parseDOM'>>(nodeSpec: NodeSpec) =>
({ parseDOM, toDOM }: NodeSpecOptions<N>): NodeSpec => {

@@ -54,3 +54,3 @@ return {

export const createPMMarkSpecFactory =
<M extends Omit<Mark, 'toDom' | 'parseDOM'>>(markSpec: MarkSpec) =>
<M extends Omit<Mark, 'toDOM' | 'parseDOM'>>(markSpec: MarkSpec) =>
({ parseDOM, toDOM }: MarkSpecOptions<M>): MarkSpec => {

@@ -57,0 +57,0 @@ return {

@@ -114,2 +114,16 @@ import { ADFNode } from '../adfNode';

/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.marks
*
* If true, it's equivalent to marks: '_'. Which means allow any mark on a child node.
*/
allowAnyChildMark?: boolean;
/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.marks
*
* If true, it's equivalent to marks: ''. Which means disallow any mark on a child node.
*/
allowNoChildMark?: boolean;
/**
* https://prosemirror.net/docs/ref/#model.NodeSpec.selectable

@@ -130,2 +144,8 @@ *

whitespace?: 'pre' | 'normal';
/**
* Non-standard attributes that are used to define the role of the node in the document.
* These attributes don't exist in the ProseMirror schema docs. And were migrated from the prosemirror-tables package.
*/
tableRole?: 'table' | 'cell' | 'header_cell' | 'row';
};

@@ -132,0 +152,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc