UNPKG

@atlaskit/adf-schema

Version:

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

60 lines (57 loc) 1.7 kB
import { uuid } from '../../utils/uuid'; import { taskItem as taskItemFactory, blockTaskItem as blockTaskItemFactory } from '../../next-schema/generated/nodeTypes'; /** * @name taskItem_node */ /** * @name blockTaskItem_node */ export const taskItem = taskItemFactory({ parseDOM: [{ tag: 'div[data-task-local-id]', // Default priority is 50. We normally don't change this but since this node type is // also used by list-item we need to make sure that we run this parser first. priority: 100, getAttrs: dom => ({ localId: uuid.generate(), // eslint-disable-next-line @atlaskit/editor/no-as-casting state: dom.getAttribute('data-task-state') || 'TODO' }) }], toDOM(node) { const { localId, state } = node.attrs; const attrs = { 'data-task-local-id': localId || 'local-task', 'data-task-state': state || 'TODO' }; return ['div', attrs, 0]; } }); export const blockTaskItem = blockTaskItemFactory({ parseDOM: [{ tag: 'div[data-task-is-block]', // Default priority is 50. We normally don't change this but since this node type is // also used by list-item we need to make sure that we run this parser first. priority: 100, getAttrs: dom => ({ localId: uuid.generate(), // eslint-disable-next-line @atlaskit/editor/no-as-casting state: dom.getAttribute('data-task-state') || 'TODO' }) }], toDOM(node) { const { localId, state } = node.attrs; const attrs = { 'data-task-local-id': localId || 'local-task', 'data-task-state': state || 'TODO', 'data-task-is-block': 'true' }; return ['div', attrs, 0]; } });