@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
74 lines (70 loc) • 2.16 kB
JavaScript
import { layoutColumn as layoutColumnFactory } from '../../next-schema/generated/nodeTypes';
import { uuid } from '../../utils/uuid';
/**
* @name layoutColumn_node
*/
export var layoutColumn = layoutColumnFactory({
parseDOM: [{
context: 'layoutColumn//',
tag: 'div[data-layout-column]',
skip: true
}, {
tag: 'div[data-layout-column]',
getAttrs: function getAttrs(domNode) {
var dom = domNode;
return {
width: Number(dom.getAttribute('data-column-width')) || undefined
};
}
}],
toDOM: function toDOM(node) {
var attrs = {
'data-layout-column': 'true'
};
var width = node.attrs.width;
if (width) {
attrs['style'] = "flex-basis: ".concat(width, "%");
attrs['data-column-width'] = "".concat(width);
}
// We need to apply a attribute to the inner most child to help
// ProseMirror identify its boundaries better.
var contentAttrs = {
'data-layout-content': 'true'
};
return ['div', attrs, ['div', contentAttrs, 0]];
}
});
export var layoutColumnWithLocalId = layoutColumnFactory({
parseDOM: [{
context: 'layoutColumn//',
tag: 'div[data-layout-column]',
skip: true
}, {
tag: 'div[data-layout-column]',
getAttrs: function getAttrs(domNode) {
var dom = domNode;
return {
width: Number(dom.getAttribute('data-column-width')) || undefined,
localId: uuid.generate()
};
}
}],
toDOM: function toDOM(node) {
var _node$attrs;
var attrs = {
'data-layout-column': 'true',
'data-local-id': (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) || undefined
};
var width = node.attrs.width;
if (width) {
attrs['style'] = "flex-basis: ".concat(width, "%");
attrs['data-column-width'] = "".concat(width);
}
// We need to apply a attribute to the inner most child to help
// ProseMirror identify its boundaries better.
var contentAttrs = {
'data-layout-content': 'true'
};
return ['div', attrs, ['div', contentAttrs, 0]];
}
});