UNPKG

@atlaskit/editor-common

Version:

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

76 lines (75 loc) 3.44 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { Component } from 'react'; import { ProviderFactory, WithProviders } from '../provider-factory'; import { ExtensionComponent } from './ExtensionComponent'; // Ignored via go/ees005 // eslint-disable-next-line @repo/internal/react/no-class-components, @typescript-eslint/no-explicit-any export class Extension extends Component { constructor(props) { super(props); _defineProperty(this, "renderWithProvider", ({ extensionProvider }) => { var _pluginInjectionApi$e, _pluginInjectionApi$e2; const { node, getPos, editorView, handleContentDOMRef, extensionHandlers, references, editorAppearance, pluginInjectionApi, eventDispatcher, macroInteractionDesignFeatureFlags, showLivePagesBodiedMacrosRendererView, showUpdatedLivePages1PBodiedExtensionUI, rendererExtensionHandlers } = this.props; // Extensions are not yet using the new plugin architecture, and the use of the pluginInjectionApi // is not type safe in editor-common. // @ts-ignore const currentState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 ? void 0 : (_pluginInjectionApi$e2 = _pluginInjectionApi$e.sharedState) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.currentState(); const { contentMode, mode } = currentState || {}; const isLivePageViewMode = contentMode === 'live-view' || mode === 'view'; return /*#__PURE__*/React.createElement(ExtensionComponent, { editorView: editorView, node: node, getPos: getPos, references: references, extensionProvider: extensionProvider, handleContentDOMRef: handleContentDOMRef, extensionHandlers: extensionHandlers, editorAppearance: editorAppearance, pluginInjectionApi: pluginInjectionApi, eventDispatcher: eventDispatcher, macroInteractionDesignFeatureFlags: macroInteractionDesignFeatureFlags, showLivePagesBodiedMacrosRendererView: showLivePagesBodiedMacrosRendererView, showUpdatedLivePages1PBodiedExtensionUI: showUpdatedLivePages1PBodiedExtensionUI, rendererExtensionHandlers: rendererExtensionHandlers, isLivePageViewMode: isLivePageViewMode }); }); this.providerFactory = props.providerFactory || new ProviderFactory(); } componentWillUnmount() { if (!this.props.providerFactory) { // new ProviderFactory is created if no `providers` has been set // in this case when component is unmounted it's safe to destroy this providerFactory this.providerFactory.destroy(); } } render() { return /*#__PURE__*/React.createElement(WithProviders // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- there seems to be an existing bug where the Extension component can't be resized if this is memoised because it doesn't rerender so this can't be memoised without a larger refactor , { providers: ['extensionProvider'], providerFactory: this.providerFactory, renderNode: this.renderWithProvider }); } } _defineProperty(Extension, "displayName", 'Extension');