@atlaskit/editor-plugin-loom
Version:
Loom plugin for @atlaskit/editor-core
53 lines • 2.67 kB
JavaScript
import React, { useCallback } from 'react';
import { useIntl } from 'react-intl';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
import { logException } from '@atlaskit/editor-common/monitoring';
import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
import VideoIcon from '@atlaskit/icon/core/video';
import { recordVideo, recordVideoFailed } from '../../pm-plugins/commands';
import { loomPluginKey } from '../../pm-plugins/main';
export var LoomQuickInsertMenuItem = function LoomQuickInsertMenuItem(_ref) {
var api = _ref.api;
var _useIntl = useIntl(),
formatMessage = _useIntl.formatMessage;
var _useQuickInsertContex = useQuickInsertContext(),
isOffline = _useQuickInsertContex.isOffline;
var onSelect = useCallback(function (_ref2) {
var _recordVideo, _api$analytics2;
var editorView = _ref2.editorView,
insert = _ref2.insert;
var tr = insert(undefined);
var loomState = loomPluginKey.getState(editorView.state);
if (!(loomState !== null && loomState !== void 0 && loomState.isEnabled)) {
var _recordVideoFailed, _api$analytics;
logException(new Error(loomState === null || loomState === void 0 ? void 0 : loomState.error), {
location: 'editor-plugin-loom/quick-insert-record-video'
});
return (_recordVideoFailed = recordVideoFailed({
inputMethod: INPUT_METHOD.QUICK_INSERT,
error: loomState === null || loomState === void 0 ? void 0 : loomState.error,
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
})({
tr: tr
})) !== null && _recordVideoFailed !== void 0 ? _recordVideoFailed : false;
}
return (_recordVideo = recordVideo({
inputMethod: INPUT_METHOD.QUICK_INSERT,
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
})({
tr: tr
})) !== null && _recordVideo !== void 0 ? _recordVideo : false;
}, [api]);
return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
iconBefore: /*#__PURE__*/React.createElement(VideoIcon, {
label: "",
color: "var(--ds-icon-subtle, #505258)",
spacing: "spacious"
}),
isDisabled: isOffline,
onSelect: onSelect,
title: formatMessage(messages.recordVideo)
});
};