UNPKG

@atlaskit/adf-schema

Version:

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

71 lines (70 loc) 3.08 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.annotation = exports.AnnotationTypes = exports.AnnotationMarkStates = void 0; exports.buildDataAttributes = buildDataAttributes; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _markTypes = require("../../next-schema/generated/markTypes"); 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) { (0, _defineProperty2.default)(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; } /** * @name annotation_mark */ var AnnotationTypes = exports.AnnotationTypes = /*#__PURE__*/function (AnnotationTypes) { AnnotationTypes["INLINE_COMMENT"] = "inlineComment"; return AnnotationTypes; }({}); var AnnotationMarkStates = exports.AnnotationMarkStates = /*#__PURE__*/function (AnnotationMarkStates) { AnnotationMarkStates["RESOLVED"] = "resolved"; AnnotationMarkStates["ACTIVE"] = "active"; return AnnotationMarkStates; }({}); 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; } var annotation = exports.annotation = (0, _markTypes.annotation)({ 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]; } });