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