@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
74 lines (73 loc) • 2.92 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/**
* @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 = {
inclusive: true,
group: 'annotation',
excludes: '',
attrs: {
id: {
default: ''
},
annotationType: {
default: AnnotationTypes.INLINE_COMMENT
}
},
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];
}
};