@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
92 lines (91 loc) • 5.06 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React from 'react';
import ReactNodeView from '../react-node-view';
import { Extension } from './Extension';
import { ExtensionNodeWrapper } from './ExtensionNodeWrapper';
// getInlineNodeViewProducer is a new api to use instead of ReactNodeView
// when creating inline node views, however, it is difficult to test the impact
// on selections when migrating inlineExtension to use the new api.
// The ReactNodeView api will be visited in the second phase of the selections
// project whilst investigating block nodes. We will revisit the Extension node view there too.
export var ExtensionNode = /*#__PURE__*/function (_ReactNodeView) {
function ExtensionNode() {
_classCallCheck(this, ExtensionNode);
return _callSuper(this, ExtensionNode, arguments);
}
_inherits(ExtensionNode, _ReactNodeView);
return _createClass(ExtensionNode, [{
key: "ignoreMutation",
value: function ignoreMutation(mutation) {
// Extensions can perform async operations that will change the DOM.
// To avoid having their tree rebuilt, we need to ignore the mutation
// for atom based extensions if its not a layout, we need to give
// children a chance to recalc
return this.node.type.isAtom || mutation.type !== 'selection' && mutation.attributeName !== 'data-layout';
}
}, {
key: "getContentDOM",
value: function getContentDOM() {
if (this.node.isInline) {
return;
}
var dom = document.createElement('div');
dom.className = "".concat(this.node.type.name, "-content-dom-wrapper");
return {
dom: dom
};
}
}, {
key: "render",
value: function render(props, forwardRef) {
var _props$extensionNodeV;
return /*#__PURE__*/React.createElement(ExtensionNodeWrapper, {
nodeType: this.node.type.name,
macroInteractionDesignFeatureFlags: props.macroInteractionDesignFeatureFlags
}, /*#__PURE__*/React.createElement(Extension, {
editorView: this.view,
node: this.node,
eventDispatcher: this.eventDispatcher
// The getPos arg is always a function when used with nodes
// the version of the types we use has a union with the type
// for marks.
// This has been fixed in later versions of the definitly typed
// types (and also in prosmirror-views inbuilt types).
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57384
,
getPos: this.getPos,
providerFactory: props.providerFactory,
handleContentDOMRef: forwardRef,
extensionHandlers: props.extensionHandlers,
editorAppearance: (_props$extensionNodeV = props.extensionNodeViewOptions) === null || _props$extensionNodeV === void 0 ? void 0 : _props$extensionNodeV.appearance,
pluginInjectionApi: props.pluginInjectionApi,
macroInteractionDesignFeatureFlags: props.macroInteractionDesignFeatureFlags,
showLivePagesBodiedMacrosRendererView: props.showLivePagesBodiedMacrosRendererView,
showUpdatedLivePages1PBodiedExtensionUI: props.showUpdatedLivePages1PBodiedExtensionUI,
rendererExtensionHandlers: props.rendererExtensionHandlers
}));
}
}]);
}(ReactNodeView);
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/max-params
export default function ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi, macroInteractionDesignFeatureFlags, showLivePagesBodiedMacrosRendererView, showUpdatedLivePages1PBodiedExtensionUI, rendererExtensionHandlers) {
return function (node, view, getPos) {
return new ExtensionNode(node, view, getPos, portalProviderAPI, eventDispatcher, {
providerFactory: providerFactory,
extensionHandlers: extensionHandlers,
extensionNodeViewOptions: extensionNodeViewOptions,
pluginInjectionApi: pluginInjectionApi,
macroInteractionDesignFeatureFlags: macroInteractionDesignFeatureFlags,
showLivePagesBodiedMacrosRendererView: showLivePagesBodiedMacrosRendererView,
showUpdatedLivePages1PBodiedExtensionUI: showUpdatedLivePages1PBodiedExtensionUI,
rendererExtensionHandlers: rendererExtensionHandlers
}).init();
};
}