UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

44 lines (42 loc) 1.74 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.MountPluginHooks = MountPluginHooks; var _react = _interopRequireDefault(require("react")); function MountPluginHook(_ref) { var usePluginHook = _ref.usePluginHook, editorView = _ref.editorView, containerElement = _ref.containerElement; usePluginHook({ editorView: editorView, containerElement: containerElement }); return null; } 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.default.createElement(_react.default.Fragment, null, pluginHooks === null || pluginHooks === void 0 ? void 0 : pluginHooks.map(function (usePluginHook, index) { var pluginName = usePluginHook.pluginName; return /*#__PURE__*/_react.default.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 }); })); }