@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
55 lines • 2.33 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import ReactDOM from 'react-dom';
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
import uuid from 'uuid';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { isFontSizeMarkActive } from './utils/validation';
export var TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
export var TYPE_HANDLE_DEC = 'drag-handle';
export var TYPE_NODE_DEC = 'node-decoration';
export var NESTED_DEPTH = 100;
export var getNodeAnchor = function getNodeAnchor(node) {
var handleId = ObjHash.getForNode(node);
return "--node-anchor-".concat(node.type.name, "-").concat(handleId);
};
var getSubType = function getSubType(node) {
if (node.attrs.level) {
return "-".concat(node.attrs.level);
}
if (isFontSizeMarkActive(node)) {
return '-small';
}
return '';
};
export var getNodeTypeWithLevel = function getNodeTypeWithLevel(node) {
var subType = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getSubType(node) : node.attrs.level ? "-".concat(node.attrs.level) : '';
return node.type.name + subType;
};
var ObjHash = /*#__PURE__*/function () {
function ObjHash() {
_classCallCheck(this, ObjHash);
}
return _createClass(ObjHash, null, [{
key: "getForNode",
value: function getForNode(node) {
if (this.caching.has(node)) {
return this.caching.get(node);
}
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
var uniqueId = uuid();
this.caching.set(node, uniqueId);
return uniqueId;
}
}]);
}();
_defineProperty(ObjHash, "caching", new WeakMap());
export var unmountDecorations = function unmountDecorations(nodeViewPortalProviderAPI, selector, key) {
// Removing decorations manually instead of using native destroy function in prosemirror API
// as it was more responsive and causes less re-rendering
var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
decorationsToRemove.forEach(function (el) {
ReactDOM.unmountComponentAtNode(el);
});
};