UNPKG

@atlaskit/adf-schema

Version:

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

76 lines (74 loc) 1.82 kB
export var USER_TYPES = /*#__PURE__*/function (USER_TYPES) { USER_TYPES["DEFAULT"] = "DEFAULT"; USER_TYPES["SPECIAL"] = "SPECIAL"; USER_TYPES["APP"] = "APP"; return USER_TYPES; }({}); /** * @name mention_node */ export var mention = { inline: true, group: 'inline', selectable: true, attrs: { id: { default: '' }, text: { default: '' }, accessLevel: { default: '' }, userType: { default: null } }, parseDOM: [{ tag: 'span[data-mention-id]', getAttrs: function getAttrs(domNode) { var dom = domNode; var attrs = { id: dom.getAttribute('data-mention-id') || mention.attrs.id.default, text: dom.textContent || mention.attrs.text.default, accessLevel: dom.getAttribute('data-access-level') || mention.attrs.accessLevel.default }; var userType = dom.getAttribute('data-user-type'); if (USER_TYPES[userType]) { attrs.userType = userType; } return attrs; } }], toDOM: function toDOM(node) { var _node$attrs = node.attrs, id = _node$attrs.id, accessLevel = _node$attrs.accessLevel, text = _node$attrs.text, userType = _node$attrs.userType; var attrs = { 'data-mention-id': id, 'data-access-level': accessLevel, contenteditable: 'false' }; if (userType) { attrs['data-user-type'] = userType; } return ['span', attrs, text]; } }; var isOptional = function isOptional(key) { return ['userType'].indexOf(key) > -1; }; export var toJSON = function toJSON(node) { return { attrs: Object.keys(node.attrs).reduce(function (obj, key) { if (isOptional(key) && !node.attrs[key]) { return obj; } obj[key] = node.attrs[key]; return obj; }, {}) }; };