UNPKG

@atlaskit/adf-schema

Version:

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

74 lines (73 loc) 1.9 kB
/** * @name annotation_mark */ export let AnnotationTypes = /*#__PURE__*/function (AnnotationTypes) { AnnotationTypes["INLINE_COMMENT"] = "inlineComment"; return AnnotationTypes; }({}); export let AnnotationMarkStates = /*#__PURE__*/function (AnnotationMarkStates) { AnnotationMarkStates["RESOLVED"] = "resolved"; AnnotationMarkStates["ACTIVE"] = "active"; return AnnotationMarkStates; }({}); export function buildDataAttributes({ id, annotationType, state }) { const data = { 'data-mark-type': 'annotation', 'data-mark-annotation-type': annotationType, 'data-id': id }; if (state) { return { ...data, 'data-mark-annotation-state': state }; } return data; } export const annotation = { inclusive: true, group: 'annotation', excludes: '', attrs: { id: { default: '' }, annotationType: { default: AnnotationTypes.INLINE_COMMENT } }, parseDOM: [{ tag: 'span[data-mark-type="annotation"]', mark: 'annotation', getAttrs: domNode => { const dom = domNode; let attrs = { id: dom.getAttribute('data-id'), annotationType: dom.getAttribute('data-mark-annotation-type') }; return attrs; } }], toDOM(node) { /* Data attributes on the DOM node are a temporary means of incrementally switching over to the Annotation mark. Once renderer provides native support for inline comments the data attributes on the DOM nodes will be removed. */ return ['span', { // Prettier will remove the quotes around class. This would cause some browsers // to not add this attribute properly, as its a reserved word. // prettier-ignore 'class': 'fabric-editor-annotation', ...buildDataAttributes({ id: node.attrs.id, annotationType: node.attrs.annotationType }) }, 0]; } };