@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
37 lines (36 loc) • 1.48 kB
JavaScript
import React from 'react';
function MountPluginHook(_ref) {
var usePluginHook = _ref.usePluginHook,
editorView = _ref.editorView,
containerElement = _ref.containerElement;
usePluginHook({
editorView: editorView,
containerElement: containerElement
});
return null;
}
export function MountPluginHooks(_ref2) {
var pluginHooks = _ref2.pluginHooks,
editorView = _ref2.editorView,
containerElement = _ref2.containerElement;
if (!editorView) {
return null;
}
// Key each fiber by the plugin name carried on the hook function (set by
// `processPluginsList`). This keeps fibers stable across `reconfigureState`
// calls that change the plugin set — keying by array index would let React
// reuse the same fiber for a different `usePluginHook`, which calls a
// different sequence of hooks (Rules of Hooks violation).
// Falls back to the array index for any hook that wasn't annotated.
return /*#__PURE__*/React.createElement(React.Fragment, null, pluginHooks === null || pluginHooks === void 0 ? void 0 : pluginHooks.map(function (usePluginHook, index) {
var pluginName = usePluginHook.pluginName;
return /*#__PURE__*/React.createElement(MountPluginHook
// eslint-disable-next-line react/no-array-index-key
, {
key: pluginName !== null && pluginName !== void 0 ? pluginName : index,
usePluginHook: usePluginHook,
editorView: editorView,
containerElement: containerElement
});
}));
}