@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
101 lines • 5.37 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 { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { useMediaProvider } from '../ui/hooks/useMediaProvider';
import { MediaGroupNext } from './mediaGroupNext';
var selector = function selector(states) {
var _states$editorDisable, _states$editorViewMod;
return {
editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled,
editorViewMode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
};
};
function MediaGroupNodeViewInternal(_ref) {
var renderFn = _ref.renderFn,
pluginInjectionApi = _ref.pluginInjectionApi;
var _useSharedPluginState = useSharedPluginStateWithSelector(pluginInjectionApi, ['editorDisabled', 'editorViewMode'], selector),
editorDisabled = _useSharedPluginState.editorDisabled,
editorViewMode = _useSharedPluginState.editorViewMode;
var mediaProvider = useMediaProvider(pluginInjectionApi);
return renderFn({
editorDisabled: editorDisabled,
editorViewMode: editorViewMode,
mediaProvider: mediaProvider
});
}
var MediaGroupNodeView = /*#__PURE__*/function (_ReactNodeView) {
function MediaGroupNodeView() {
_classCallCheck(this, MediaGroupNodeView);
return _callSuper(this, MediaGroupNodeView, arguments);
}
_inherits(MediaGroupNodeView, _ReactNodeView);
return _createClass(MediaGroupNodeView, [{
key: "render",
value: function render(props, forwardRef) {
var _this = this;
var providerFactory = props.providerFactory,
mediaOptions = props.mediaOptions,
pluginInjectionApi = props.pluginInjectionApi;
var getPos = this.getPos;
return /*#__PURE__*/React.createElement(WithProviders
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
, {
providers: ['contextIdentifierProvider'],
providerFactory: providerFactory
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
renderNode: function renderNode(_ref2) {
var contextIdentifierProvider = _ref2.contextIdentifierProvider;
var renderFn = function renderFn(_ref3) {
var mediaProviderFromState = _ref3.mediaProvider,
editorDisabled = _ref3.editorDisabled,
editorViewMode = _ref3.editorViewMode;
var mediaProvider = mediaProviderFromState ? Promise.resolve(mediaProviderFromState) : undefined;
if (!mediaProvider && !expValEquals('platform_editor_media_vc_fixes', 'isEnabled', true)) {
return null;
}
return /*#__PURE__*/React.createElement(MediaGroupNext, {
node: _this.node,
getPos: getPos,
view: _this.view,
forwardRef: forwardRef,
disabled: editorDisabled,
allowLazyLoading: mediaOptions.allowLazyLoading,
mediaProvider: mediaProvider,
contextIdentifierProvider: contextIdentifierProvider,
isCopyPasteEnabled: mediaOptions.isCopyPasteEnabled,
anchorPos: _this.view.state.selection.$anchor.pos,
headPos: _this.view.state.selection.$head.pos,
mediaOptions: mediaOptions,
editorViewMode: editorViewMode === 'view'
});
};
return /*#__PURE__*/React.createElement(MediaGroupNodeViewInternal, {
renderFn: renderFn,
pluginInjectionApi: pluginInjectionApi
});
}
});
}
}]);
}(ReactNodeView);
export var ReactMediaGroupNode = function ReactMediaGroupNode(portalProviderAPI, eventDispatcher, providerFactory) {
var mediaOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var pluginInjectionApi = arguments.length > 4 ? arguments[4] : undefined;
return function (node, view, getPos) {
return new MediaGroupNodeView(node, view, getPos, portalProviderAPI, eventDispatcher, {
providerFactory: providerFactory,
mediaOptions: mediaOptions,
pluginInjectionApi: pluginInjectionApi
}).init();
};
};