UNPKG

@atlaskit/adf-schema

Version:

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

111 lines (109 loc) 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.orderedListWithOrderAndLocalId = exports.orderedListWithOrder = exports.orderedListWithLocalId = exports.orderedListSelector = exports.orderedList = void 0; var _utils = require("../../utils"); 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]; } }); var orderedListWithLocalId = exports.orderedListWithLocalId = (0, _nodeTypes.orderedList)({ parseDOM: [{ tag: 'ol', getAttrs: function getAttrs() { return { localId: _utils.uuid.generate() }; } }], toDOM: function toDOM(node) { var _node$attrs; var attrs = { class: orderedListSelector.substr(1), '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 }; 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$attrs2; var start = resolveStart(node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.order); var attrs = { start: typeof start === 'number' ? String(start) : undefined, class: orderedListSelector.substr(1) }; return ['ol', attrs, 0]; } }); var orderedListWithOrderAndLocalId = exports.orderedListWithOrderAndLocalId = (0, _nodeTypes.orderedList)({ parseDOM: [{ tag: 'ol', getAttrs: function getAttrs(domNode) { var dom = domNode; var startDOMAttr = dom.getAttribute('start'); var localId = _utils.uuid.generate(); if (startDOMAttr) { var start = resolveStart(startDOMAttr); if (typeof start === 'number') { return { order: start, localId: localId }; } } return { localId: localId }; } }], toDOM: function toDOM(node) { var _node$attrs3, _node$attrs4; var start = resolveStart(node === null || node === void 0 ? void 0 : (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.order); var attrs = { start: typeof start === 'number' ? String(start) : undefined, class: orderedListSelector.substr(1), 'data-local-id': (node === null || node === void 0 ? void 0 : (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.localId) || undefined }; return ['ol', attrs, 0]; } });