Skip to main content
Glama
ContentSelectorWrapper.tsx2.58 kB
'use client'; import { isSameKeyPath, type NodeProps } from '@intlayer/core'; import { MessageKey, useCommunicator, useEditorEnabled, useFocusDictionary, } from '@intlayer/editor-react'; import { NodeType } from '@intlayer/types'; import { type FC, type HTMLAttributes, useCallback, useMemo } from 'react'; import { useIntlayerContext } from '../client'; import { ContentSelector } from '../UI/ContentSelector'; export type ContentSelectorWrapperProps = NodeProps & Omit<HTMLAttributes<HTMLDivElement>, 'children'>; const ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({ children, dictionaryKey, keyPath, }) => { const { focusedContent, setFocusedContent } = useFocusDictionary(); const { postMessage, senderId } = useCommunicator(); // Filter out translation nodes for more flexibility with the editor that can have different format const filteredKeyPath = useMemo( () => keyPath.filter((key) => key.type !== NodeType.Translation), [keyPath] ); const handleSelect = useCallback( () => setFocusedContent({ dictionaryKey, keyPath: filteredKeyPath, }), [dictionaryKey, filteredKeyPath] ); const handleHover = useCallback( () => postMessage({ type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`, data: { dictionaryKey, keyPath: filteredKeyPath, }, senderId, }), [dictionaryKey, filteredKeyPath] ); const handleUnhover = useCallback( () => postMessage({ type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`, data: null, senderId, }), [senderId] ); const isSelected = useMemo( () => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ?? false, [focusedContent, filteredKeyPath, dictionaryKey] ); return ( <ContentSelector onPress={handleSelect} onHover={handleHover} onUnhover={handleUnhover} isSelecting={isSelected} > {children} </ContentSelector> ); }; export const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({ children, ...props }) => { const { enabled } = useEditorEnabled(); const { disableEditor } = useIntlayerContext(); if (enabled && !disableEditor) { return ( <ContentSelectorWrapperContent {...props}> {children} </ContentSelectorWrapperContent> ); } return children; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server