@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
63 lines (62 loc) • 1.57 kB
JavaScript
export const orderedListSelector = '.ak-ol';
export const orderedList = {
group: 'block',
attrs: {
order: {
default: 1
}
},
content: 'listItem+',
marks: 'unsupportedMark unsupportedNodeAttribute',
selectable: false,
parseDOM: [{
tag: 'ol'
}],
toDOM() {
const attrs = {
class: orderedListSelector.substr(1)
};
return ['ol', attrs, 0];
}
};
// resolve "start" to a safe, 0+ integer, otherwise return undefined
// Note: Any changes to this function should also be made to "resolveOrder"
// in packages/editor/editor-common/src/utils/list.ts
const resolveStart = start => {
const num = Number(start);
if (Number.isNaN(num)) {
return;
}
if (num < 0) {
return;
}
return Math.floor(Math.max(num, 0));
};
export const orderedListWithOrder = {
...orderedList,
parseDOM: [{
tag: 'ol',
getAttrs: domNode => {
const dom = domNode;
let startDOMAttr = dom.getAttribute('start');
if (startDOMAttr) {
const start = resolveStart(startDOMAttr);
if (typeof start === 'number') {
return {
order: start
};
}
}
return null;
}
}],
toDOM(node) {
var _node$attrs;
const start = resolveStart(node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.order);
const attrs = {
start: typeof start === 'number' ? String(start) : undefined,
class: orderedListSelector.substr(1)
};
return ['ol', attrs, 0];
}
};