UNPKG

@atlaskit/adf-schema

Version:

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

75 lines (73 loc) 1.65 kB
export let 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 const mention = { inline: true, group: 'inline', selectable: true, attrs: { id: { default: '' }, text: { default: '' }, accessLevel: { default: '' }, userType: { default: null } }, parseDOM: [{ tag: 'span[data-mention-id]', getAttrs: domNode => { const dom = domNode; const 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 }; const userType = dom.getAttribute('data-user-type'); if (USER_TYPES[userType]) { attrs.userType = userType; } return attrs; } }], toDOM(node) { const { id, accessLevel, text, userType } = node.attrs; const attrs = { 'data-mention-id': id, 'data-access-level': accessLevel, contenteditable: 'false' }; if (userType) { attrs['data-user-type'] = userType; } return ['span', attrs, text]; } }; const isOptional = key => { return ['userType'].indexOf(key) > -1; }; export const toJSON = node => ({ attrs: Object.keys(node.attrs).reduce((obj, key) => { if (isOptional(key) && !node.attrs[key]) { return obj; } obj[key] = node.attrs[key]; return obj; }, {}) });