UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

44 lines (42 loc) 2.58 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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) { _defineProperty(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; } // Disable no-re-export rule for entry point files /* eslint-disable @atlaskit/editor/no-re-export */ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model'; var isPMNode = function isPMNode(nodeOrMark) { return nodeOrMark instanceof PMNode || Array.isArray(nodeOrMark.marks); }; /** * 🧱 Internal Helper Function: Editor FE Platform * * Creates a set of generic metadata attributes for a ProseMirror node or mark. * These attributes are used to annotate the DOM representation with information * about the node or mark type. * * @param {PMNode | PMMark} nodeOrMark - The ProseMirror node or mark to create metadata for. * @returns {Record<string, string>} An object containing metadata attributes. * - `data-prosemirror-content-type`: Specifies if the content is a node or mark. * - `data-prosemirror-node-name` (if applicable): The name of the node. * - `data-prosemirror-node-block` (if applicable): Indicates if the node is a block. * - `data-prosemirror-node-inline` (if applicable): Indicates if the node is inline. * - `data-prosemirror-mark-name` (if applicable): The name of the mark. */ export var createProseMirrorMetadata = function createProseMirrorMetadata(nodeOrMark) { var name = nodeOrMark.type.name; var isNode = isPMNode(nodeOrMark); var commonAttributes = { 'data-prosemirror-content-type': isNode ? 'node' : 'mark' }; if (!isNode) { return _objectSpread(_objectSpread({}, commonAttributes), {}, _defineProperty({}, 'data-prosemirror-mark-name', name)); } commonAttributes['data-prosemirror-node-name'] = name; if (nodeOrMark.type.isBlock) { commonAttributes['data-prosemirror-node-block'] = 'true'; } if (nodeOrMark.type.isInline) { commonAttributes['data-prosemirror-node-inline'] = 'true'; } return commonAttributes; };