UNPKG

@atlaskit/adf-schema

Version:

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

83 lines (82 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toJSON = exports.mention = exports.USER_TYPES = void 0; 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 */ exports.USER_TYPES = USER_TYPES; 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]; } }; exports.mention = mention; var isOptional = function isOptional(key) { return ['userType'].indexOf(key) > -1; }; 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; }, {}) }; }; exports.toJSON = toJSON;