@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
46 lines (45 loc) • 1.77 kB
JavaScript
import React, { createContext, useContext, useMemo } from 'react';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
var EditorToolbarContext = /*#__PURE__*/createContext({
editorView: null,
editorAppearance: undefined,
editorViewMode: undefined,
editorToolbarDockingPreference: undefined
});
/**
* Access editor specific config and state within a toolbar component
*/
export var useEditorToolbar = function useEditorToolbar() {
var context = useContext(EditorToolbarContext);
if (!context) {
throw new Error('useEditorToolbar must be used within EditorToolbarContext');
}
return context;
};
export var EditorToolbarProvider = function EditorToolbarProvider(_ref) {
var children = _ref.children,
editorView = _ref.editorView,
editorAppearance = _ref.editorAppearance,
editorViewMode = _ref.editorViewMode,
editorToolbarDockingPreference = _ref.editorToolbarDockingPreference,
isOffline = _ref.isOffline;
var memoizedValue = useMemo(function () {
return {
editorView: editorView,
editorAppearance: editorAppearance,
editorViewMode: editorViewMode,
editorToolbarDockingPreference: editorToolbarDockingPreference,
isOffline: isOffline
};
}, [editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline]);
var contextValue = expValEquals('platform_editor_perf_lint_cleanup', 'isEnabled', true) ? memoizedValue : {
editorView: editorView,
editorAppearance: editorAppearance,
editorViewMode: editorViewMode,
editorToolbarDockingPreference: editorToolbarDockingPreference,
isOffline: isOffline
};
return /*#__PURE__*/React.createElement(EditorToolbarContext.Provider, {
value: contextValue
}, children);
};