react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
94 lines • 3.35 kB
JavaScript
"use client";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ContentSelectorWrapper_exports = {};
__export(ContentSelectorWrapper_exports, {
ContentSelectorRenderer: () => ContentSelectorRenderer
});
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_core = require("@intlayer/core");
var import_editor_react = require("@intlayer/editor-react");
var import_react = require("react");
var import_client = require('../client/index.cjs');
var import_ContentSelector = require('../UI/ContentSelector.cjs');
const ContentSelectorWrapperContent = ({
children,
dictionaryKey,
keyPath
}) => {
const { focusedContent, setFocusedContent } = (0, import_editor_react.useFocusDictionary)();
const { postMessage, senderId } = (0, import_editor_react.useCommunicator)();
const handleSelect = (0, import_react.useCallback)(
() => setFocusedContent({
dictionaryKey,
keyPath
}),
[dictionaryKey, keyPath]
);
const handleHover = (0, import_react.useCallback)(
() => postMessage({
type: `${import_editor_react.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
data: {
dictionaryKey,
keyPath
},
senderId
}),
[dictionaryKey, keyPath]
);
const handleUnhover = (0, import_react.useCallback)(
() => postMessage({
type: `${import_editor_react.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
data: null,
senderId
}),
[senderId]
);
const isSelected = (0, import_react.useMemo)(
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
[focusedContent, keyPath, dictionaryKey]
);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_ContentSelector.ContentSelector,
{
onPress: handleSelect,
onHover: handleHover,
onUnhover: handleUnhover,
isSelecting: isSelected,
children
}
);
};
const ContentSelectorRenderer = ({
children,
...props
}) => {
const { enabled } = (0, import_editor_react.useEditorEnabled)();
const { disableEditor } = (0, import_client.useIntlayerContext)();
if (enabled && !disableEditor) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentSelectorWrapperContent, { ...props, children });
}
return children;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ContentSelectorRenderer
});
//# sourceMappingURL=ContentSelectorWrapper.cjs.map
;