UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

60 lines (58 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.orderedListWithOrder = exports.orderedListSelector = exports.orderedList = void 0; var _nodeTypes = require("../../next-schema/generated/nodeTypes"); var orderedListSelector = exports.orderedListSelector = '.ak-ol'; var orderedList = exports.orderedList = (0, _nodeTypes.orderedList)({ parseDOM: [{ tag: 'ol' }], toDOM: function toDOM() { var 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 var resolveStart = function resolveStart(start) { var num = Number(start); if (Number.isNaN(num)) { return; } if (num < 0) { return; } return Math.floor(Math.max(num, 0)); }; var orderedListWithOrder = exports.orderedListWithOrder = (0, _nodeTypes.orderedList)({ parseDOM: [{ tag: 'ol', getAttrs: function getAttrs(domNode) { var dom = domNode; var startDOMAttr = dom.getAttribute('start'); if (startDOMAttr) { var start = resolveStart(startDOMAttr); if (typeof start === 'number') { return { order: start }; } } return null; } }], toDOM: function toDOM(node) { var _node$attrs; var start = resolveStart(node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.order); var attrs = { start: typeof start === 'number' ? String(start) : undefined, class: orderedListSelector.substr(1) }; return ['ol', attrs, 0]; } });