@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
54 lines (52 loc) • 2.72 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useEditorToolbar = exports.EditorToolbarProvider = void 0;
var _react = _interopRequireWildcard(require("react"));
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var EditorToolbarContext = /*#__PURE__*/(0, _react.createContext)({
editorView: null,
editorAppearance: undefined,
editorViewMode: undefined,
editorToolbarDockingPreference: undefined
});
/**
* Access editor specific config and state within a toolbar component
*/
var useEditorToolbar = exports.useEditorToolbar = function useEditorToolbar() {
var context = (0, _react.useContext)(EditorToolbarContext);
if (!context) {
throw new Error('useEditorToolbar must be used within EditorToolbarContext');
}
return context;
};
var EditorToolbarProvider = exports.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 = (0, _react.useMemo)(function () {
return {
editorView: editorView,
editorAppearance: editorAppearance,
editorViewMode: editorViewMode,
editorToolbarDockingPreference: editorToolbarDockingPreference,
isOffline: isOffline
};
}, [editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline]);
var contextValue = (0, _expValEquals.expValEquals)('platform_editor_perf_lint_cleanup', 'isEnabled', true) ? memoizedValue : {
editorView: editorView,
editorAppearance: editorAppearance,
editorViewMode: editorViewMode,
editorToolbarDockingPreference: editorToolbarDockingPreference,
isOffline: isOffline
};
return /*#__PURE__*/_react.default.createElement(EditorToolbarContext.Provider, {
value: contextValue
}, children);
};