UNPKG

@atlaskit/adf-schema

Version:

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

65 lines (63 loc) 2.7 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { annotation as annotationFactory } from '../../next-schema/generated/markTypes'; /** * @name annotation_mark */ export var AnnotationTypes = /*#__PURE__*/function (AnnotationTypes) { AnnotationTypes["INLINE_COMMENT"] = "inlineComment"; return AnnotationTypes; }({}); export var AnnotationMarkStates = /*#__PURE__*/function (AnnotationMarkStates) { AnnotationMarkStates["RESOLVED"] = "resolved"; AnnotationMarkStates["ACTIVE"] = "active"; return AnnotationMarkStates; }({}); export function buildDataAttributes(_ref) { var id = _ref.id, annotationType = _ref.annotationType, state = _ref.state; var data = { 'data-mark-type': 'annotation', 'data-mark-annotation-type': annotationType, 'data-id': id }; if (state) { return _objectSpread(_objectSpread({}, data), {}, { 'data-mark-annotation-state': state }); } return data; } export var annotation = annotationFactory({ parseDOM: [{ tag: 'span[data-mark-type="annotation"]', mark: 'annotation', getAttrs: function getAttrs(domNode) { var dom = domNode; var attrs = { id: dom.getAttribute('data-id'), annotationType: dom.getAttribute('data-mark-annotation-type') }; return attrs; } }], toDOM: function 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', _objectSpread({ // 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]; } });