react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
41 lines • 1.41 kB
JavaScript
"use client";
import { jsx } from "react/jsx-runtime";
import { isSameKeyPath } from "@intlayer/core";
import { useFocusDictionary, useEditorEnabled } from "@intlayer/editor-react";
import { useCallback, useMemo } from "react";
import { useIntlayerContext } from "../client/index.mjs";
import { ContentSelector } from "../UI/ContentSelector.mjs";
const ContentSelectorWrapperContent = ({
children,
dictionaryKey,
keyPath
}) => {
const { focusedContent, setFocusedContent } = useFocusDictionary();
const handleSelect = useCallback(
() => setFocusedContent({
dictionaryKey,
keyPath
}),
[dictionaryKey, keyPath]
);
const isSelected = useMemo(
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
[focusedContent, keyPath, dictionaryKey]
);
return /* @__PURE__ */ jsx(ContentSelector, { onPress: handleSelect, isSelecting: isSelected, children });
};
const ContentSelectorRenderer = ({
children,
...props
}) => {
const { enabled } = useEditorEnabled();
const { disableEditor } = useIntlayerContext();
if (enabled && !disableEditor) {
return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, { ...props, children });
}
return children;
};
export {
ContentSelectorRenderer
};
//# sourceMappingURL=ContentSelectorWrapper.mjs.map