UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

1 lines 3.63 kB
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport {\n MessageKey,\n useCommunicator,\n useEditorEnabled,\n useFocusDictionary,\n} from '@intlayer/editor-react';\nimport { type FC, type HTMLAttributes, useCallback, useMemo } from 'react';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath,\n },\n senderId,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkEI;AAhEJ,kBAA8C;AAC9C,0BAKO;AACP,mBAAmE;AACnE,oBAAmC;AACnC,6BAAgC;AAKhC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,QAAI,wCAAmB;AACjE,QAAM,EAAE,aAAa,SAAS,QAAI,qCAAgB;AAElD,QAAM,mBAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,kBAAc;AAAA,IAClB,MACE,YAAY;AAAA,MACV,MAAM,GAAG,+BAAW,gCAAgC;AAAA,MACpD,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,oBAAgB;AAAA,IACpB,MACE,YAAY;AAAA,MACV,MAAM,GAAG,+BAAW,gCAAgC;AAAA,MACpD,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,IACH,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,iBAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,SACzC,2BAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,SAAS,aAAa;AAAA,EACzC;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,SAAS;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,M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