preact-intlayer 7.0.7 → 7.0.9-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/cjs/IntlayerNode.cjs +0 -1
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +0 -2
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +0 -5
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/useCompact.cjs +0 -2
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +0 -2
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +0 -2
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +0 -2
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +0 -2
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +0 -2
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +0 -2
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +0 -2
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +0 -2
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +0 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +0 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +0 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +0 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +0 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +0 -2
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +0 -2
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +0 -4
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +0 -3
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +0 -5
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +0 -3
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +0 -5
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +0 -3
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +0 -2
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs +0 -3
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +0 -3
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +0 -2
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +0 -1
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +0 -2
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +0 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +0 -2
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +0 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +0 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +0 -2
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +0 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +0 -4
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +0 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/types/client/format/useCompact.d.ts +2 -2
- package/dist/types/client/format/useCurrency.d.ts +2 -2
- package/dist/types/client/format/useList.d.ts +2 -2
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts +2 -2
- package/dist/types/client/format/usePercentage.d.ts +2 -2
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts +2 -2
- package/dist/types/client/format/useUnit.d.ts +2 -2
- package/dist/types/client/useContent.d.ts +2 -2
- package/dist/types/client/useContent.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +3 -3
- package/dist/types/client/useLocaleBase.d.ts +5 -5
- package/dist/types/client/useLocaleStorage.d.ts +5 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +23 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps>","useFocusDictionary","useCommunicator","NodeType","ContentSelector","MessageKey","ContentSelectorRenderer: FC<ContentSelectorWrapperProps>","useEditorEnabled","useIntlayerContext"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type NodeProps } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport { NodeType } from '@intlayer/types';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\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 // Filter out translation nodes for more flexibility with the editor that can have different format\n const filteredKeyPath = useMemo(\n () => keyPath.filter((key) => key.type !== NodeType.Translation),\n [keyPath]\n );\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath: filteredKeyPath,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath: filteredKeyPath,\n },\n senderId,\n }),\n [dictionaryKey, filteredKeyPath]\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 ?? [], filteredKeyPath)) ??\n false,\n [focusedContent, filteredKeyPath, 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":"
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps>","useFocusDictionary","useCommunicator","NodeType","ContentSelector","MessageKey","ContentSelectorRenderer: FC<ContentSelectorWrapperProps>","useEditorEnabled","useIntlayerContext"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type NodeProps } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport { NodeType } from '@intlayer/types';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\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 // Filter out translation nodes for more flexibility with the editor that can have different format\n const filteredKeyPath = useMemo(\n () => keyPath.filter((key) => key.type !== NodeType.Translation),\n [keyPath]\n );\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath: filteredKeyPath,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath: filteredKeyPath,\n },\n senderId,\n }),\n [dictionaryKey, filteredKeyPath]\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 ?? [], filteredKeyPath)) ??\n false,\n [focusedContent, filteredKeyPath, 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":";;;;;;;;;;;;;;;;AAoBA,MAAMA,iCAAkE,EACtE,UACA,eACA,cACI;CACJ,MAAM,EAAE,gBAAgB,sBAAsBC,0DAAoB;CAClE,MAAM,EAAE,aAAa,aAAaC,oDAAiB;CAGnD,MAAM,mDACE,QAAQ,QAAQ,QAAQ,IAAI,SAASC,0BAAS,YAAY,EAChE,CAAC,QAAQ,CACV;AA2CD,QACE,4CAACC;EACC,8CAzCA,kBAAkB;GAChB;GACA,SAAS;GACV,CAAC,EACJ,CAAC,eAAe,gBAAgB,CACjC;EAqCG,8CAjCA,YAAY;GACV,MAAM,GAAGC,6BAAW,iCAAiC;GACrD,MAAM;IACJ;IACA,SAAS;IACV;GACD;GACD,CAAC,EACJ,CAAC,eAAe,gBAAgB,CACjC;EAyBG,gDArBA,YAAY;GACV,MAAM,GAAGA,6BAAW,iCAAiC;GACrD,MAAM;GACN;GACD,CAAC,EACJ,CAAC,SAAS,CACX;EAgBG,+CAZC,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,wCAC3B,gBAAgB,WAAW,EAAE,EAAE,gBAAgB,KAC/D,OACF;GAAC;GAAgB;GAAiB;GAAc,CACjD;EASI;GACe;;AAItB,MAAaC,2BAA4D,EACvE,SACA,GAAG,YACC;CACJ,MAAM,EAAE,YAAYC,sDAAkB;CACtC,MAAM,EAAE,kBAAkBC,oDAAoB;AAE9C,KAAI,WAAW,CAAC,cACd,QACE,4CAAC;EAA8B,GAAI;EAChC;GAC6B;AAIpC,QAAO"}
|
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
6
|
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
7
|
let preact_compat = require("preact/compat");
|
|
9
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
10
8
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
11
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
12
9
|
|
|
13
10
|
//#region src/editor/DictionariesRecordContext.tsx
|
|
14
11
|
const DictionariesRecordStatesContext = (0, preact_compat.createContext)(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["DictionariesRecordProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [String(dictionary.localId)]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["DictionariesRecordProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [String(dictionary.localId)]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,mEAEJ,OAAU;AACZ,MAAM,oEAEJ,OAAU;AAEZ,MAAaA,8BAAqD,EAChE,eACI;CACJ,MAAM,CAAC,oBAAoB,yBACzBC,qDACEC,6BAAW,sCACX,OACD;CAEH,MAAM,+CACG,EACL,oBAAoB,sBAAsB,EAAE,EAC7C,GACD,CAAC,mBAAmB,CACrB;CAED,MAAM,gDACG;EACL;EACA,sBAAsB,eAA2B;AAC/C,0BAAuB,kBAAkB;IACvC,GAAG;KACF,OAAO,WAAW,QAAQ,GAAG;IAC/B,EAAE;;EAEN,GACD,CAAC,sBAAsB,CACxB;AAED,QACE,4CAAC,gCAAgC;EAAS,OAAO;YAC/C,4CAAC,iCAAiC;GAAS,OAAO;GAC/C;IACyC;GACH;;AAI/C,MAAa,mEACA,iCAAiC;AAE9C,MAAa,8BAA8B;CACzC,MAAM,iBAAiB,8BAA8B;CACrD,MAAM,8CAA2B,gCAAgC;AAEjE,KAAI,CAAC,cACH,OAAM,IAAI,MACR,+EACD;AAGH,QAAO;EAAE,GAAG;EAAe,GAAG;EAAgB"}
|
|
@@ -6,15 +6,10 @@ const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMess
|
|
|
6
6
|
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
7
7
|
const require_editor_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
8
8
|
let __intlayer_core = require("@intlayer/core");
|
|
9
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
10
9
|
let __intlayer_types = require("@intlayer/types");
|
|
11
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
12
10
|
let __intlayer_editor = require("@intlayer/editor");
|
|
13
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
14
11
|
let preact_compat = require("preact/compat");
|
|
15
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
16
12
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
17
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
18
13
|
|
|
19
14
|
//#region src/editor/EditedContentContext.tsx
|
|
20
15
|
const EditedContentStateContext = (0, preact_compat.createContext)(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.cjs","names":["useCrossFrameMessageListener","MessageKey","EditedContentProvider: FC<PropsWithChildren>","useDictionariesRecord","useCrossFrameState","setEditedDictionary: Dispatch<SetStateAction<Dictionary>>","updatedDictionaries: Dictionary","lastKeyPath: KeyPath","NodeType"],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n NodeType,\n} from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'preact/compat';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<LocalDictionaryId, Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<LocalDictionaryId, Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryLocalId: LocalDictionaryId) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryLocalId];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (\n dictionaryLocalId: LocalDictionaryId\n ) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryLocalId) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n if (!editedContent) return undefined;\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n const currentContent =\n editedContent?.[localDictionaryIdOrKey as LocalDictionaryId]?.content ??\n {};\n\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n return contentNode;\n }\n\n const filteredDictionariesLocalId = Object.keys(editedContent).filter(\n (key) => key.startsWith(`${localDictionaryIdOrKey}:`)\n );\n\n for (const localDictionaryId of filteredDictionariesLocalId) {\n const currentContent =\n editedContent?.[localDictionaryId as LocalDictionaryId]?.content ?? {};\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n if (contentNode) return contentNode;\n }\n\n return undefined;\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkCA,MAAM,6DAEJ,OAAU;AAEZ,MAAa,6BACX,qBAEAA,yEACE,GAAGC,6BAAW,gCAAgC,QAC9C,iBACD;AAEH,MAAa,4BACX,qBAEAD,yEACE,GAAGC,6BAAW,gCAAgC,OAC9C,iBACD;AAmCH,MAAM,+DAEJ,OAAU;AAEZ,MAAM,gBAAoB,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,UAAU,GACzC;AAEP,MAAaC,yBAAgD,EAAE,eAAe;CAC5E,MAAM,EAAE,uBAAuBC,gEAAuB;CAEtD,MAAM,CAAC,eAAe,yBACpBC,qDACEH,6BAAW,gCACZ;CAEH,MAAMI,uBACJ,aACG;EACH,IAAIC,sBAAkC,aAAa,SAAS;AAE5D,yBAAuB,SAAS;AAC9B,yBAAsB,aACpB,UACA,OAAO,oBAAoB,KAC5B;AAED,UAAO;IACL,GAAG;KACF,oBAAoB,MAAM;IAC5B;IACD;AAEF,SAAO;;CAGT,MAAM,oBACJ,mBACA,aACG;AACH,yBAAuB,UAAU;GAC/B,GAAG;IACF,oBAAoB;IACnB,GAAG,OAAO;IACV,SAAS;IACV;GACF,EAAE;;CAGL,MAAM,oBACJ,mBACA,UACA,UAAqB,EAAE,EACvB,YAAqB,SAClB;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAC/D,MAAM,iBAAiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC;GAED,IAAI,aAAa;AACjB,OAAI,CAAC,WAAW;IAEd,IAAI,QAAQ;IACZ,MAAM,eAAe,QAAQ,MAAM,GAAG,GAAG;IACzC,MAAMC,cAAuB,QAAQ,QAAQ,SAAS;IACtD,IAAI,WAAW,YAAY;AAG3B,WACE,oDAA+B,gBAAgB,WAAW,KAC1D,aACA;AACA;AACA,gBACE,UAAU,IAAI,YAAY,MAAM,GAAG,YAAY,IAAI,IAAI,MAAM;AAC/D,kBAAa,CACX,GAAG,cACH;MAAE,GAAG;MAAa,KAAK;MAAU,CAClC;;;GAIL,MAAM,8DACJ,gBACA,YACA,SACD;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,uBACJ,mBACA,QACA,UAAqB,EAAE,KACpB;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAK/D,MAAM,sEAJiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC,EAIC,QACA,QACD;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,uBACJ,mBACA,YACG;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAS/D,MAAM,+DARiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC,EAQC,sDAL6C,iBAAiB,QAAQ,CAOvE;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,wBAAwB,sBAAyC;AACrE,yBAAuB,SAAS;GAC9B,MAAM,UAAU,EAAE,GAAG,MAAM;AAC3B,UAAO,QAAQ;AACf,UAAO;IACP;;CAGJ,MAAM,gCACJ,sBACG;AACH,yBAAuB,SAAS;AAO9B,UANiB,OAAO,QAAQ,KAAK,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAClE,QAAI,QAAQ,kBACV,QAAO;AAET,WAAO;KAAE,GAAG;MAAM,MAAM;KAAO;MAC9B,EAAE,CAAsB;IAE3B;;CAGJ,MAAM,2BAA2B;AAC/B,wBAAsB,EAAE,CAAC;;CAG3B,MAAM,yBACJ,wBACA,YAC4B;AAC5B,MAAI,CAAC,cAAe,QAAO;EAE3B,MAAM,kBAAkB,QAAQ,QAC7B,QAAQ,IAAI,SAASC,0BAAS,YAChC;AAMD,MAHE,uBAAuB,SAAS,UAAU,IAC1C,uBAAuB,SAAS,WAAW,CAY3C,qDARE,gBAAgB,yBAA8C,WAC9D,EAAE,EAIF,gBACD;EAKH,MAAM,8BAA8B,OAAO,KAAK,cAAc,CAAC,QAC5D,QAAQ,IAAI,WAAW,GAAG,uBAAuB,GAAG,CACtD;AAED,OAAK,MAAM,qBAAqB,6BAA6B;GAG3D,MAAM,2DADJ,gBAAgB,oBAAyC,WAAW,EAAE,EAGtE,gBACD;AAED,OAAI,YAAa,QAAO;;;AAM5B,QACE,4CAAC,0BAA0B;EACzB,OAAO,EACL,eACD;YAED,4CAAC,4BAA4B;GAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GAEA;IACoC;GACJ;;AAIzC,MAAa,8DACA,4BAA4B;AAEzC,MAAa,yBAAyB;CACpC,MAAM,6CAA0B,0BAA0B;CAC1D,MAAM,gBAAgB,yBAAyB;AAE/C,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
1
|
+
{"version":3,"file":"EditedContentContext.cjs","names":["useCrossFrameMessageListener","MessageKey","EditedContentProvider: FC<PropsWithChildren>","useDictionariesRecord","useCrossFrameState","setEditedDictionary: Dispatch<SetStateAction<Dictionary>>","updatedDictionaries: Dictionary","lastKeyPath: KeyPath","NodeType"],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n NodeType,\n} from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'preact/compat';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<LocalDictionaryId, Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<LocalDictionaryId, Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryLocalId: LocalDictionaryId) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryLocalId];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (\n dictionaryLocalId: LocalDictionaryId\n ) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryLocalId) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n if (!editedContent) return undefined;\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n const currentContent =\n editedContent?.[localDictionaryIdOrKey as LocalDictionaryId]?.content ??\n {};\n\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n return contentNode;\n }\n\n const filteredDictionariesLocalId = Object.keys(editedContent).filter(\n (key) => key.startsWith(`${localDictionaryIdOrKey}:`)\n );\n\n for (const localDictionaryId of filteredDictionariesLocalId) {\n const currentContent =\n editedContent?.[localDictionaryId as LocalDictionaryId]?.content ?? {};\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n if (contentNode) return contentNode;\n }\n\n return undefined;\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAM,6DAEJ,OAAU;AAEZ,MAAa,6BACX,qBAEAA,yEACE,GAAGC,6BAAW,gCAAgC,QAC9C,iBACD;AAEH,MAAa,4BACX,qBAEAD,yEACE,GAAGC,6BAAW,gCAAgC,OAC9C,iBACD;AAmCH,MAAM,+DAEJ,OAAU;AAEZ,MAAM,gBAAoB,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,UAAU,GACzC;AAEP,MAAaC,yBAAgD,EAAE,eAAe;CAC5E,MAAM,EAAE,uBAAuBC,gEAAuB;CAEtD,MAAM,CAAC,eAAe,yBACpBC,qDACEH,6BAAW,gCACZ;CAEH,MAAMI,uBACJ,aACG;EACH,IAAIC,sBAAkC,aAAa,SAAS;AAE5D,yBAAuB,SAAS;AAC9B,yBAAsB,aACpB,UACA,OAAO,oBAAoB,KAC5B;AAED,UAAO;IACL,GAAG;KACF,oBAAoB,MAAM;IAC5B;IACD;AAEF,SAAO;;CAGT,MAAM,oBACJ,mBACA,aACG;AACH,yBAAuB,UAAU;GAC/B,GAAG;IACF,oBAAoB;IACnB,GAAG,OAAO;IACV,SAAS;IACV;GACF,EAAE;;CAGL,MAAM,oBACJ,mBACA,UACA,UAAqB,EAAE,EACvB,YAAqB,SAClB;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAC/D,MAAM,iBAAiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC;GAED,IAAI,aAAa;AACjB,OAAI,CAAC,WAAW;IAEd,IAAI,QAAQ;IACZ,MAAM,eAAe,QAAQ,MAAM,GAAG,GAAG;IACzC,MAAMC,cAAuB,QAAQ,QAAQ,SAAS;IACtD,IAAI,WAAW,YAAY;AAG3B,WACE,oDAA+B,gBAAgB,WAAW,KAC1D,aACA;AACA;AACA,gBACE,UAAU,IAAI,YAAY,MAAM,GAAG,YAAY,IAAI,IAAI,MAAM;AAC/D,kBAAa,CACX,GAAG,cACH;MAAE,GAAG;MAAa,KAAK;MAAU,CAClC;;;GAIL,MAAM,8DACJ,gBACA,YACA,SACD;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,uBACJ,mBACA,QACA,UAAqB,EAAE,KACpB;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAK/D,MAAM,sEAJiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC,EAIC,QACA,QACD;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,uBACJ,mBACA,YACG;AACH,yBAAuB,SAAS;GAE9B,MAAM,kBAAkB,mBAAmB,oBAAoB;GAS/D,MAAM,+DARiB,gBACrB,OAAO,oBAAoB,WAAW,gBACvC,EAQC,sDAL6C,iBAAiB,QAAQ,CAOvE;AAED,UAAO;IACL,GAAG;KACF,oBAAoB;KACnB,GAAG,OAAO;KACV,SAAS;KACV;IACF;IACD;;CAGJ,MAAM,wBAAwB,sBAAyC;AACrE,yBAAuB,SAAS;GAC9B,MAAM,UAAU,EAAE,GAAG,MAAM;AAC3B,UAAO,QAAQ;AACf,UAAO;IACP;;CAGJ,MAAM,gCACJ,sBACG;AACH,yBAAuB,SAAS;AAO9B,UANiB,OAAO,QAAQ,KAAK,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAClE,QAAI,QAAQ,kBACV,QAAO;AAET,WAAO;KAAE,GAAG;MAAM,MAAM;KAAO;MAC9B,EAAE,CAAsB;IAE3B;;CAGJ,MAAM,2BAA2B;AAC/B,wBAAsB,EAAE,CAAC;;CAG3B,MAAM,yBACJ,wBACA,YAC4B;AAC5B,MAAI,CAAC,cAAe,QAAO;EAE3B,MAAM,kBAAkB,QAAQ,QAC7B,QAAQ,IAAI,SAASC,0BAAS,YAChC;AAMD,MAHE,uBAAuB,SAAS,UAAU,IAC1C,uBAAuB,SAAS,WAAW,CAY3C,qDARE,gBAAgB,yBAA8C,WAC9D,EAAE,EAIF,gBACD;EAKH,MAAM,8BAA8B,OAAO,KAAK,cAAc,CAAC,QAC5D,QAAQ,IAAI,WAAW,GAAG,uBAAuB,GAAG,CACtD;AAED,OAAK,MAAM,qBAAqB,6BAA6B;GAG3D,MAAM,2DADJ,gBAAgB,oBAAyC,WAAW,EAAE,EAGtE,gBACD;AAED,OAAI,YAAa,QAAO;;;AAM5B,QACE,4CAAC,0BAA0B;EACzB,OAAO,EACL,eACD;YAED,4CAAC,4BAA4B;GAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GAEA;IACoC;GACJ;;AAIzC,MAAa,8DACA,4BAA4B;AAEzC,MAAa,yBAAyB;CACpC,MAAM,6CAA0B,0BAA0B;CAC1D,MAAM,gBAAgB,yBAAyB;AAE/C,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
@@ -5,11 +5,8 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
5
5
|
const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
6
6
|
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
7
7
|
let __intlayer_editor = require("@intlayer/editor");
|
|
8
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
9
8
|
let preact_compat = require("preact/compat");
|
|
10
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
11
9
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
12
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
13
10
|
|
|
14
11
|
//#region src/editor/EditorEnabledContext.tsx
|
|
15
12
|
const EditorEnabledContext = (0, preact_compat.createContext)({ enabled: false });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["useCrossFrameState","MessageKey","useCrossFrameMessageListener","EditorEnabledProvider: FC<PropsWithChildren>"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useCrossFrameState","MessageKey","useCrossFrameMessageListener","EditorEnabledProvider: FC<PropsWithChildren>"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,wDAA8D,EAClE,SAAS,OACV,CAAC;AAEF,MAAa,yBAAyB,YACpCA,qDAAmBC,6BAAW,yBAAyB,OAAO,QAAQ;AAExE,MAAa,6BACX,qBAEAC,yEACE,GAAGD,6BAAW,wBAAwB,QACtC,iBACD;AAEH,MAAa,4BACX,qBAEAC,yEACE,GAAGD,6BAAW,wBAAwB,OACtC,iBACD;AAEH,MAAaE,yBAAgD,EAAE,eAAe;CAC5E,MAAM,CAAC,aAAa,sBAAsB;EACxC,MAAM;EACN,SAAS;EACV,CAAC;AAEF,QACE,4CAAC,qBAAqB;EAAS,OAAO,EAAE,SAAS,WAAW;EACzD;GAC6B;;AAIpC,MAAa,uDAAoC,qBAAqB"}
|
|
@@ -9,9 +9,7 @@ const require_editor_ConfigurationContext = require('./ConfigurationContext.cjs'
|
|
|
9
9
|
const require_editor_EditedContentContext = require('./EditedContentContext.cjs');
|
|
10
10
|
const require_editor_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
11
11
|
let preact_compat = require("preact/compat");
|
|
12
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
13
12
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
14
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
15
13
|
|
|
16
14
|
//#region src/editor/EditorProvider.tsx
|
|
17
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":["EditorProvidersWrapper: FC<PropsWithChildren>","useGetEditedContentState","DictionariesRecordProvider","EditedContentProvider","FocusDictionaryProvider","EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>>","useGetEditorEnabledState","useEditorEnabled","IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>>","EditorProvider: FC<PropsWithChildren<EditorProviderProps>>","EditorEnabledProvider","ConfigurationProvider","CommunicatorProvider"],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useState,\n} from 'preact/compat';\nimport {\n CommunicatorProvider,\n type CommunicatorProviderProps,\n} from './CommunicatorContext';\nimport {\n ConfigurationProvider,\n type ConfigurationProviderProps,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps;\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n </ConfigurationProvider>\n </EditorEnabledProvider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":["EditorProvidersWrapper: FC<PropsWithChildren>","useGetEditedContentState","DictionariesRecordProvider","EditedContentProvider","FocusDictionaryProvider","EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>>","useGetEditorEnabledState","useEditorEnabled","IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>>","EditorProvider: FC<PropsWithChildren<EditorProviderProps>>","EditorEnabledProvider","ConfigurationProvider","CommunicatorProvider"],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useState,\n} from 'preact/compat';\nimport {\n CommunicatorProvider,\n type CommunicatorProviderProps,\n} from './CommunicatorContext';\nimport {\n ConfigurationProvider,\n type ConfigurationProviderProps,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps;\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n </ConfigurationProvider>\n </EditorEnabledProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAMA,0BAAiD,EAAE,eAAe;CACtE,MAAM,wBAAwBC,8DAA0B;AAExD,oCAAgB;AACd,yBAAuB;IACtB,EAAE,CAAC;AAEN,QACE,4CAACC,iFACC,4CAACC,uEACC,4CAACC,iEAAyB,WAAmC,GACvC,GACG;;;;;AAWjC,MAAMC,8BAAoE,EACxE,UACA,eACI;CACJ,MAAM,mBAAmBC,8DAA0B;CAEnD,MAAM,EAAE,YAAYC,sDAAkB;AAEtC,oCAAgB;AACd,MAAI,QAAS;AAGb,oBAAkB;IACjB,CAAC,QAAQ,CAAC;AAEb,QAAO,UAAU,WAAW;;;;;;AAO9B,MAAMC,uBAA6D,EACjE,UACA,eACI;CACJ,MAAM,CAAC,YAAY,6CAA0B,MAAM;AAEnD,oCAAgB;AACd,gBAAc,OAAO,SAAS,OAAO,IAAI;IACxC,EAAE,CAAC;AAEN,QAAO,aAAa,WAAW;;AAMjC,MAAaC,kBAA8D,EACzE,UACA,cACA,GAAG,YAEH,4CAACC,uEACC,4CAACC;CAAqC;WACpC,4CAAC;EAAoB,UAAU;YAC7B,4CAACC;GAAqB,GAAI;aACxB,4CAAC;IAA2B,UAAU;cACpC,4CAAC,0BAAwB,WAAkC;KAChC;IACR;GACH;EACA,GACF"}
|
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
6
|
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
7
|
let preact_compat = require("preact/compat");
|
|
9
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
10
8
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
11
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
12
9
|
|
|
13
10
|
//#region src/editor/FocusDictionaryContext.tsx
|
|
14
11
|
const FocusDictionaryStateContext = (0, preact_compat.createContext)(void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n return { ...prev, keyPath };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n return { ...prev, keyPath };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;AA+BA,MAAM,+DAEJ,OAAU;AACZ,MAAM,iEAEJ,OAAU;AAEZ,MAAaA,2BAAkD,EAC7D,eACI;CACJ,MAAM,CAAC,gBAAgB,qBACrBC,qDACEC,6BAAW,kCACX,KACD;CAEH,MAAM,4BAA4B,YAAuB;AACvD,qBAAmB,SAAS;AAC1B,OAAI,CAAC,KACH,QAAO;AAET,UAAO;IAAE,GAAG;IAAM;IAAS;IAC3B;;AAGJ,QACE,4CAAC,4BAA4B;EAAS,OAAO,EAAE,gBAAgB;YAC7D,4CAAC,8BAA8B;GAC7B,OAAO;IAAE;IAAmB;IAA0B;GAErD;IACsC;GACJ;;AAI3C,MAAa,kCAAkC;CAC7C,MAAM,wCAAqB,8BAA8B;AACzD,KAAI,YAAY,OACd,OAAM,IAAI,MACR,0EACD;AAEH,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,gBAAgB,2BAA2B;CACjD,MAAM,6CAA0B,4BAA4B;AAE5D,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,wEACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
@@ -8,13 +8,10 @@ const require_editor_EditorProvider = require('./EditorProvider.cjs');
|
|
|
8
8
|
const require_editor_useCrossURLPathState = require('./useCrossURLPathState.cjs');
|
|
9
9
|
const require_editor_useIframeClickInterceptor = require('./useIframeClickInterceptor.cjs');
|
|
10
10
|
let preact_compat = require("preact/compat");
|
|
11
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
12
11
|
let __intlayer_config_built = require("@intlayer/config/built");
|
|
13
12
|
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
14
13
|
let __intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
15
|
-
__intlayer_unmerged_dictionaries_entry = require_rolldown_runtime.__toESM(__intlayer_unmerged_dictionaries_entry);
|
|
16
14
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
17
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
18
15
|
|
|
19
16
|
//#region src/editor/IntlayerEditorProvider.tsx
|
|
20
17
|
const IntlayerEditorHooksEnabled = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.cjs","names":["IntlayerEditorHooksEnabled: FunctionComponent","useDictionariesRecordActions","configuration","IntlayerEditorHook: FunctionComponent","useEditorEnabled","IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}>","EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect } from 'preact/compat';\nimport { useDictionariesRecordActions } from './DictionariesRecordContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { EditorProvider } from './EditorProvider';\nimport { useCrossURLPathSetter } from './useCrossURLPathState';\nimport { useIframeClickInterceptor } from './useIframeClickInterceptor';\n\nconst IntlayerEditorHooksEnabled: FunctionComponent = () => {\n /**\n * URL Messages\n */\n useCrossURLPathSetter();\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n /**\n * Sent local dictionaries to editor\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions() ?? {};\n\n useEffect(() => {\n const unmergedDictionaries = getUnmergedDictionaries();\n const dictionariesList = Object.fromEntries(\n Object.values(unmergedDictionaries)\n .flat()\n .map((dictionary) => [dictionary.localId, dictionary])\n );\n\n setLocaleDictionaries?.(dictionariesList);\n }, []);\n\n return <></>;\n};\n\nconst { editor } = configuration;\n\nconst IntlayerEditorHook: FunctionComponent = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}> = ({ children }) => {\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n if (!isInIframe) return;\n\n if (editor.applicationURL.length > 0) {\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n }\n\n if (editor.editorURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the editor URL to synchronize the locales states.\n editor.editorURL\n );\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the CMS for security reasons.\n // Correspond to the CMS URL.\n editor.cmsURL\n );\n }\n }}\n allowedOrigins={[\n editor?.editorURL,\n editor?.cmsURL,\n editor?.applicationURL,\n ]}\n configuration={configuration}\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerEditorProvider.cjs","names":["IntlayerEditorHooksEnabled: FunctionComponent","useDictionariesRecordActions","configuration","IntlayerEditorHook: FunctionComponent","useEditorEnabled","IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}>","EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect } from 'preact/compat';\nimport { useDictionariesRecordActions } from './DictionariesRecordContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { EditorProvider } from './EditorProvider';\nimport { useCrossURLPathSetter } from './useCrossURLPathState';\nimport { useIframeClickInterceptor } from './useIframeClickInterceptor';\n\nconst IntlayerEditorHooksEnabled: FunctionComponent = () => {\n /**\n * URL Messages\n */\n useCrossURLPathSetter();\n\n /**\n * Click Messages\n */\n useIframeClickInterceptor();\n\n /**\n * Sent local dictionaries to editor\n */\n const { setLocaleDictionaries } = useDictionariesRecordActions() ?? {};\n\n useEffect(() => {\n const unmergedDictionaries = getUnmergedDictionaries();\n const dictionariesList = Object.fromEntries(\n Object.values(unmergedDictionaries)\n .flat()\n .map((dictionary) => [dictionary.localId, dictionary])\n );\n\n setLocaleDictionaries?.(dictionariesList);\n }, []);\n\n return <></>;\n};\n\nconst { editor } = configuration;\n\nconst IntlayerEditorHook: FunctionComponent = () => {\n const { enabled } = useEditorEnabled();\n\n return enabled ? <IntlayerEditorHooksEnabled /> : <></>;\n};\n\nexport const IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}> = ({ children }) => {\n return (\n <EditorProvider\n postMessage={(data: any) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n if (!isInIframe) return;\n\n if (editor.applicationURL.length > 0) {\n window?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the current application URL to synchronize the locales states.\n editor.applicationURL\n );\n }\n\n if (editor.editorURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the editor for security reasons.\n // Correspond to the editor URL to synchronize the locales states.\n editor.editorURL\n );\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent?.postMessage(\n data,\n // Use to restrict the origin of the CMS for security reasons.\n // Correspond to the CMS URL.\n editor.cmsURL\n );\n }\n }}\n allowedOrigins={[\n editor?.editorURL,\n editor?.cmsURL,\n editor?.applicationURL,\n ]}\n configuration={configuration}\n >\n <IntlayerEditorHook />\n {children}\n </EditorProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,MAAMA,mCAAsD;;;;AAI1D,4DAAuB;;;;AAKvB,qEAA2B;;;;CAK3B,MAAM,EAAE,0BAA0BC,uEAA8B,IAAI,EAAE;AAEtE,oCAAgB;EACd,MAAM,4FAAgD;EACtD,MAAM,mBAAmB,OAAO,YAC9B,OAAO,OAAO,qBAAqB,CAChC,MAAM,CACN,KAAK,eAAe,CAAC,WAAW,SAAS,WAAW,CAAC,CACzD;AAED,0BAAwB,iBAAiB;IACxC,EAAE,CAAC;AAEN,QAAO,4EAAK;;AAGd,MAAM,EAAE,WAAWC;AAEnB,MAAMC,2BAA8C;CAClD,MAAM,EAAE,YAAYC,sDAAkB;AAEtC,QAAO,UAAU,4CAAC,+BAA6B,GAAG,4EAAK;;AAGzD,MAAaC,0BAEP,EAAE,eAAe;AACrB,QACE,6CAACC;EACC,cAAc,SAAc;AAC1B,OAAI,OAAO,WAAW,YAAa;AAGnC,OAAI,EADe,OAAO,SAAS,OAAO,KACzB;AAEjB,OAAI,OAAO,eAAe,SAAS,EACjC,SAAQ,YACN,MAGA,OAAO,eACR;AAGH,OAAI,OAAO,UAAU,SAAS,EAC5B,QAAO,QAAQ,YACb,MAGA,OAAO,UACR;AAGH,OAAI,OAAO,OAAO,SAAS,EACzB,QAAO,QAAQ,YACb,MAGA,OAAO,OACR;;EAGL,gBAAgB;GACd,QAAQ;GACR,QAAQ;GACR,QAAQ;GACT;EACD,eAAeJ;aAEf,4CAAC,uBAAqB,EACrB;GACc"}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
6
6
|
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
7
|
let preact_hooks = require("preact/hooks");
|
|
9
|
-
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
10
8
|
|
|
11
9
|
//#region src/editor/useCrossFrameMessageListener.tsx
|
|
12
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator","postMessageWrapper: (data?: S) => void"],"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins\n ?.filter((url) => ![null, undefined, '', '*'].includes(url))\n .some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator","postMessageWrapper: (data?: S) => void"],"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins\n ?.filter((url) => ![null, undefined, '', '*'].includes(url))\n .some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,EAAE,gBAAgB,aAAa,aAAaA,oDAAiB;AAEnE,mCAAgB;AACd,MAAI,kBAAkB;;;;;;;;;GASpB,MAAM,iBACJ,UACG;IACH,MAAM,EAAE,MAAM,MAAM,UAAU,gBAAgB,MAAM;AAGpD,QAAI,SAAS,IAAK;AAGlB,QAAI,gBAAgB,SAAU;AAG9B,QACE,OAAO,mBAAmB,eAC1B,gBACI,QAAQ,QAAQ,CAAC;KAAC;KAAM;KAAW;KAAI;KAAI,CAAC,SAAS,IAAI,CAAC,CAC3D,MAAM,2CAAoB,KAAK,MAAM,OAAO,CAAC,IAChD,gBAAgB,SAAS,IAAI,CAG7B,kBAAiB,KAAK;;AAI1B,UAAO,iBAAiB,WAAW,cAAc;AAGjD,gBAAa,OAAO,oBAAoB,WAAW,cAAc;;IAElE;EAAC;EAAgB;EAAa;EAAU;EAAY,CAAC;;;;;;;;;;CAWxD,MAAMC,sBAA0C,SAAS;AACvD,cAAY;GAAE,MAAM;GAAK;GAAM;GAAU,CAAC;;AAG5C,QAAO"}
|
|
@@ -5,7 +5,6 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
5
5
|
const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
6
6
|
const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
7
7
|
let preact_hooks = require("preact/hooks");
|
|
8
|
-
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
9
8
|
|
|
10
9
|
//#region src/editor/useCrossFrameState.tsx
|
|
11
10
|
const resolveState = (valueOrUpdater, prevState) => typeof valueOrUpdater === "function" ? valueOrUpdater(prevState) : valueOrUpdater;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.cjs","names":["useCommunicator","resolvedState: S","setStateWrapper: Dispatch<SetStateAction<S>>"],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport type { SetStateAction } from 'preact/compat';\nimport {\n type Dispatch,\n type StateUpdater,\n useEffect,\n useState,\n} from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nconst resolveState = <S,>(\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevState?: S) => S)(prevState)\n : (valueOrUpdater as S);\n\n/**\n * Configuration options for `useCrossFrameState`.\n * @typedef {Object} CrossFrameStateOptions\n * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.\n * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.\n */\n\n/**\n * useCrossFrameState\n *\n * This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).\n * It uses the `postMessage` API to communicate state changes and updates between instances.\n *\n * @template S - The type of the state.\n * @param key - A unique identifier for the state to synchronize.\n * @param initialState - The initial state value or a function to compute it lazily.\n * @param options - Configuration options to control emitting and receiving messages.\n * - `emit` (default: true): Whether to broadcast state changes to other instances.\n * - `receive` (default: true): Whether to listen for state updates from other instances.\n *\n * @returns {[S, StateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, typeof postState] => {\n const { postMessage, senderId } = useCommunicator();\n\n const { emit, receive } = options ?? { emit: true, receive: true };\n\n const handleStateChange = (\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n ): S => {\n // Initialize state from the provided initial value, if defined\n const resolvedState: S = resolveState(valueOrUpdater, prevState);\n\n // Emit the initial state if `emit` is enabled and initial state is defined\n if (\n emit &&\n typeof postMessage === 'function' &&\n typeof resolvedState !== 'undefined'\n ) {\n postMessage({ type: `${key}/post`, data: resolvedState, senderId });\n }\n\n return resolvedState;\n };\n\n const postState = () => {\n if (typeof postMessage !== 'function') return;\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n const [state, setState] = useState<S>(() => handleStateChange(initialState));\n\n /**\n * A wrapper function around the `setState` function to handle messaging efficiently.\n *\n * This approach has several advantages over using an additional `useEffect`:\n * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,\n * it prevents the extra render cycle that would be triggered when using `useEffect`.\n * - **Consistency:** Ensures the message is emitted immediately when the state is updated,\n * avoiding potential delays caused by the asynchronous nature of `useEffect`.\n *\n * This function keeps the same API as `setState` and is memoized using `useCallback`\n * to prevent unnecessary re-renders of dependent components.\n *\n * @template S - The type of the state.\n * @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.\n * @returns {void}\n */\n const setStateWrapper: Dispatch<SetStateAction<S>> = (\n valueOrUpdater: S | ((prevState: S) => S)\n ) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));\n\n /**\n * Listen for messages with the specified key and update the state accordingly.\n */\n useCrossFrameMessageListener<S>(\n `${key}/post`,\n // Only activate the state listener if the `receive` option is true\n receive\n ? (data) => {\n setState(data);\n }\n : undefined\n );\n\n const onGetMessage = (_: unknown, originSenderId?: string) => {\n if (!emit) return;\n if (typeof postMessage !== 'function') return;\n if (originSenderId === senderId) return;\n if (typeof state === 'undefined') return;\n\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n /**\n * Listen for messages request to get the state content and send it back.\n */\n useCrossFrameMessageListener<S>(\n `${key}/get`,\n // Only activate the state listener if the `emit` option is true\n emit ? onGetMessage : undefined,\n state // Revalidate the listener if the state changes\n );\n\n useEffect(() => {\n // If the component is mounted and the hook in receive mode,\n // Request the state from the other instance\n if (\n receive &&\n typeof postMessage === 'function' &&\n typeof state === 'undefined'\n ) {\n postMessage({ type: `${key}/get`, senderId });\n }\n }, []);\n\n // Return the useState state and setter\n return [state, setStateWrapper, postState];\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.cjs","names":["useCommunicator","resolvedState: S","setStateWrapper: Dispatch<SetStateAction<S>>"],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport type { SetStateAction } from 'preact/compat';\nimport {\n type Dispatch,\n type StateUpdater,\n useEffect,\n useState,\n} from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nconst resolveState = <S,>(\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevState?: S) => S)(prevState)\n : (valueOrUpdater as S);\n\n/**\n * Configuration options for `useCrossFrameState`.\n * @typedef {Object} CrossFrameStateOptions\n * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.\n * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.\n */\n\n/**\n * useCrossFrameState\n *\n * This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).\n * It uses the `postMessage` API to communicate state changes and updates between instances.\n *\n * @template S - The type of the state.\n * @param key - A unique identifier for the state to synchronize.\n * @param initialState - The initial state value or a function to compute it lazily.\n * @param options - Configuration options to control emitting and receiving messages.\n * - `emit` (default: true): Whether to broadcast state changes to other instances.\n * - `receive` (default: true): Whether to listen for state updates from other instances.\n *\n * @returns {[S, StateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, typeof postState] => {\n const { postMessage, senderId } = useCommunicator();\n\n const { emit, receive } = options ?? { emit: true, receive: true };\n\n const handleStateChange = (\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n ): S => {\n // Initialize state from the provided initial value, if defined\n const resolvedState: S = resolveState(valueOrUpdater, prevState);\n\n // Emit the initial state if `emit` is enabled and initial state is defined\n if (\n emit &&\n typeof postMessage === 'function' &&\n typeof resolvedState !== 'undefined'\n ) {\n postMessage({ type: `${key}/post`, data: resolvedState, senderId });\n }\n\n return resolvedState;\n };\n\n const postState = () => {\n if (typeof postMessage !== 'function') return;\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n const [state, setState] = useState<S>(() => handleStateChange(initialState));\n\n /**\n * A wrapper function around the `setState` function to handle messaging efficiently.\n *\n * This approach has several advantages over using an additional `useEffect`:\n * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,\n * it prevents the extra render cycle that would be triggered when using `useEffect`.\n * - **Consistency:** Ensures the message is emitted immediately when the state is updated,\n * avoiding potential delays caused by the asynchronous nature of `useEffect`.\n *\n * This function keeps the same API as `setState` and is memoized using `useCallback`\n * to prevent unnecessary re-renders of dependent components.\n *\n * @template S - The type of the state.\n * @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.\n * @returns {void}\n */\n const setStateWrapper: Dispatch<SetStateAction<S>> = (\n valueOrUpdater: S | ((prevState: S) => S)\n ) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));\n\n /**\n * Listen for messages with the specified key and update the state accordingly.\n */\n useCrossFrameMessageListener<S>(\n `${key}/post`,\n // Only activate the state listener if the `receive` option is true\n receive\n ? (data) => {\n setState(data);\n }\n : undefined\n );\n\n const onGetMessage = (_: unknown, originSenderId?: string) => {\n if (!emit) return;\n if (typeof postMessage !== 'function') return;\n if (originSenderId === senderId) return;\n if (typeof state === 'undefined') return;\n\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n /**\n * Listen for messages request to get the state content and send it back.\n */\n useCrossFrameMessageListener<S>(\n `${key}/get`,\n // Only activate the state listener if the `emit` option is true\n emit ? onGetMessage : undefined,\n state // Revalidate the listener if the state changes\n );\n\n useEffect(() => {\n // If the component is mounted and the hook in receive mode,\n // Request the state from the other instance\n if (\n receive &&\n typeof postMessage === 'function' &&\n typeof state === 'undefined'\n ) {\n postMessage({ type: `${key}/get`, senderId });\n }\n }, []);\n\n // Return the useState state and setter\n return [state, setStateWrapper, postState];\n};\n"],"mappings":";;;;;;;;;AAkBA,MAAM,gBACJ,gBACA,cAEA,OAAO,mBAAmB,aACrB,eAAwC,UAAU,GAClD;;;;;;;;;;;;;;;;;;;;;;AAwBP,MAAa,sBACX,KACA,cACA,YACuD;CACvD,MAAM,EAAE,aAAa,aAAaA,oDAAiB;CAEnD,MAAM,EAAE,MAAM,YAAY,WAAW;EAAE,MAAM;EAAM,SAAS;EAAM;CAElE,MAAM,qBACJ,gBACA,cACM;EAEN,MAAMC,gBAAmB,aAAa,gBAAgB,UAAU;AAGhE,MACE,QACA,OAAO,gBAAgB,cACvB,OAAO,kBAAkB,YAEzB,aAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAe;GAAU,CAAC;AAGrE,SAAO;;CAGT,MAAM,kBAAkB;AACtB,MAAI,OAAO,gBAAgB,WAAY;AACvC,cAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAO;GAAU,CAAC;;CAG7D,MAAM,CAAC,OAAO,6CAA8B,kBAAkB,aAAa,CAAC;;;;;;;;;;;;;;;;;CAkB5E,MAAMC,mBACJ,mBACG,UAAU,cAAc,kBAAkB,gBAAgB,UAAU,CAAC;;;;AAK1E,0EACE,GAAG,IAAI,QAEP,WACK,SAAS;AACR,WAAS,KAAK;KAEhB,OACL;CAED,MAAM,gBAAgB,GAAY,mBAA4B;AAC5D,MAAI,CAAC,KAAM;AACX,MAAI,OAAO,gBAAgB,WAAY;AACvC,MAAI,mBAAmB,SAAU;AACjC,MAAI,OAAO,UAAU,YAAa;AAElC,cAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAO;GAAU,CAAC;;;;;AAM7D,0EACE,GAAG,IAAI,OAEP,OAAO,eAAe,QACtB,MACD;AAED,mCAAgB;AAGd,MACE,WACA,OAAO,gBAAgB,cACvB,OAAO,UAAU,YAEjB,aAAY;GAAE,MAAM,GAAG,IAAI;GAAO;GAAU,CAAC;IAE9C,EAAE,CAAC;AAGN,QAAO;EAAC;EAAO;EAAiB;EAAU"}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
6
|
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
7
|
let preact_hooks = require("preact/hooks");
|
|
9
|
-
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
10
8
|
|
|
11
9
|
//#region src/editor/useCrossURLPathState.tsx
|
|
12
10
|
const useCrossURLPathState = (initialState, options) => require_editor_useCrossFrameState.useCrossFrameState(__intlayer_editor.MessageKey.INTLAYER_URL_CHANGE, initialState, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n const states = useCrossURLPathState(initialState, {\n emit: true,\n receive: false,\n });\n const [_state, setState] = states;\n\n useEffect(() => {\n /**\n * 1) Monkey patch history methods (pushState, replaceState)\n * to dispatch a custom event whenever they are called.\n */\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n\n const injectLocationChangeEvent = (method: (...args: any[]) => void) =>\n function (this: typeof history, ...args: [any, string, string?]) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChangeEvent(originalPushState);\n history.replaceState = injectLocationChangeEvent(originalReplaceState);\n\n /**\n * 2) The callback to update our state whenever the URL changes.\n */\n const updateURLState = () => {\n setState(window.location.pathname);\n };\n\n /**\n * 3) Attach event listeners for locationchange, popstate, hashchange.\n * - 'locationchange' is our custom event triggered by push/replaceState overrides.\n * - 'popstate' is fired on back/forward navigation.\n * - 'hashchange' is for URL hash (#) changes.\n * - 'load' is when new page is loaded\n */\n window.addEventListener('locationchange', updateURLState);\n window.addEventListener('popstate', updateURLState);\n window.addEventListener('hashchange', updateURLState);\n window.addEventListener('load', updateURLState);\n\n // Initialize our state immediately on mount\n updateURLState();\n\n /**\n * 4) Cleanup when the component unmounts:\n * - Remove event listeners.\n * - Restore original pushState & replaceState to avoid side effects.\n */\n return () => {\n window.removeEventListener('locationchange', updateURLState);\n window.removeEventListener('popstate', updateURLState);\n window.removeEventListener('hashchange', updateURLState);\n window.removeEventListener('load', updateURLState);\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n };\n }, []);\n\n return states;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n const states = useCrossURLPathState(initialState, {\n emit: true,\n receive: false,\n });\n const [_state, setState] = states;\n\n useEffect(() => {\n /**\n * 1) Monkey patch history methods (pushState, replaceState)\n * to dispatch a custom event whenever they are called.\n */\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n\n const injectLocationChangeEvent = (method: (...args: any[]) => void) =>\n function (this: typeof history, ...args: [any, string, string?]) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChangeEvent(originalPushState);\n history.replaceState = injectLocationChangeEvent(originalReplaceState);\n\n /**\n * 2) The callback to update our state whenever the URL changes.\n */\n const updateURLState = () => {\n setState(window.location.pathname);\n };\n\n /**\n * 3) Attach event listeners for locationchange, popstate, hashchange.\n * - 'locationchange' is our custom event triggered by push/replaceState overrides.\n * - 'popstate' is fired on back/forward navigation.\n * - 'hashchange' is for URL hash (#) changes.\n * - 'load' is when new page is loaded\n */\n window.addEventListener('locationchange', updateURLState);\n window.addEventListener('popstate', updateURLState);\n window.addEventListener('hashchange', updateURLState);\n window.addEventListener('load', updateURLState);\n\n // Initialize our state immediately on mount\n updateURLState();\n\n /**\n * 4) Cleanup when the component unmounts:\n * - Remove event listeners.\n * - Restore original pushState & replaceState to avoid side effects.\n */\n return () => {\n window.removeEventListener('locationchange', updateURLState);\n window.removeEventListener('popstate', updateURLState);\n window.removeEventListener('hashchange', updateURLState);\n window.removeEventListener('load', updateURLState);\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n };\n }, []);\n\n return states;\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,wBACX,cACA,YACGA,qDAAmBC,6BAAW,qBAAqB,cAAc,QAAQ;AAE9E,MAAa,yBAAyB,iBAA0B;CAC9D,MAAM,SAAS,qBAAqB,cAAc;EAChD,MAAM;EACN,SAAS;EACV,CAAC;CACF,MAAM,CAAC,QAAQ,YAAY;AAE3B,mCAAgB;;;;;EAKd,MAAM,oBAAoB,QAAQ;EAClC,MAAM,uBAAuB,QAAQ;EAErC,MAAM,6BAA6B,WACjC,SAAgC,GAAG,MAA8B;AAC/D,UAAO,MAAM,MAAM,KAAK;AACxB,UAAO,cAAc,IAAI,MAAM,iBAAiB,CAAC;;AAGrD,UAAQ,YAAY,0BAA0B,kBAAkB;AAChE,UAAQ,eAAe,0BAA0B,qBAAqB;;;;EAKtE,MAAM,uBAAuB;AAC3B,YAAS,OAAO,SAAS,SAAS;;;;;;;;;AAUpC,SAAO,iBAAiB,kBAAkB,eAAe;AACzD,SAAO,iBAAiB,YAAY,eAAe;AACnD,SAAO,iBAAiB,cAAc,eAAe;AACrD,SAAO,iBAAiB,QAAQ,eAAe;AAG/C,kBAAgB;;;;;;AAOhB,eAAa;AACX,UAAO,oBAAoB,kBAAkB,eAAe;AAC5D,UAAO,oBAAoB,YAAY,eAAe;AACtD,UAAO,oBAAoB,cAAc,eAAe;AACxD,UAAO,oBAAoB,QAAQ,eAAe;AAClD,WAAQ,YAAY;AACpB,WAAQ,eAAe;;IAExB,EAAE,CAAC;AAEN,QAAO"}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_EditedContentContext = require('./EditedContentContext.cjs');
|
|
6
6
|
let __intlayer_core = require("@intlayer/core");
|
|
7
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
8
7
|
|
|
9
8
|
//#region src/editor/useEditedContentRenderer.tsx
|
|
10
9
|
const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.cjs","names":["useEditedContentActions","EditedContentRenderer: FC<EditedContentRendererProps>"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getContent } from '@intlayer/core';\nimport type { Dictionary, KeyPath, Locale } from '@intlayer/types';\nimport type { FC } from 'preact/compat';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: Dictionary['key'];\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(content, props, props.locale);\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEditedContentRenderer.cjs","names":["useEditedContentActions","EditedContentRenderer: FC<EditedContentRendererProps>"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getContent } from '@intlayer/core';\nimport type { Dictionary, KeyPath, Locale } from '@intlayer/types';\nimport type { FC } from 'preact/compat';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: Dictionary['key'];\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(content, props, props.locale);\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;AAcA,MAAa,4BAA4B,EACvC,eACA,SACA,eACgC;CAChC,MAAM,uBAAuBA,6DAAyB;AAEtD,KAAI,qBAQF,QAPoB,qBAAqB,sBACvC,eACA,QACD,IAE4B;AAK/B,QAAO;;AAGT,MAAaC,yBACX,UACG;CACH,MAAM,UAAU,yBAAyB,MAAM;AAE/C,KAAI,OAAO,YAAY,UAAU;EAC/B,MAAM,2DAAsC,SAAS,OAAO,MAAM,OAAO;AAEzE,MAAI,OAAO,6BAA6B,UAAU;AAChD,WAAQ,MACN,kDAAkD,OAAO,yBAAyB,2BAA2B,KAAK,UAAU,yBAAyB,GACtJ;AAED,UAAO,MAAM;;AAGf,SAAO;;AAGT,QAAO"}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
6
6
|
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
-
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
7
|
let preact_hooks = require("preact/hooks");
|
|
9
|
-
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
10
8
|
|
|
11
9
|
//#region src/editor/useIframeClickInterceptor.tsx
|
|
12
10
|
const useIframeClickInterceptor = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["useCrossFrameMessageListener","MessageKey","handlePostMessageEvent: EventListener","mergeIframeClick"],"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n const postMessage = useCrossFrameMessageListener<undefined>(\n MessageKey.INTLAYER_IFRAME_CLICKED\n );\n const handlePostMessageEvent: EventListener = () => {\n postMessage();\n };\n\n useEffect(() => {\n window.addEventListener('mousedown', handlePostMessageEvent);\n\n return () =>\n window.removeEventListener('mousedown', handlePostMessageEvent);\n }, [postMessage]);\n};\n\nexport const useIframeClickMerger = () =>\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["useCrossFrameMessageListener","MessageKey","handlePostMessageEvent: EventListener","mergeIframeClick"],"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n const postMessage = useCrossFrameMessageListener<undefined>(\n MessageKey.INTLAYER_IFRAME_CLICKED\n );\n const handlePostMessageEvent: EventListener = () => {\n postMessage();\n };\n\n useEffect(() => {\n window.addEventListener('mousedown', handlePostMessageEvent);\n\n return () =>\n window.removeEventListener('mousedown', handlePostMessageEvent);\n }, [postMessage]);\n};\n\nexport const useIframeClickMerger = () =>\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n"],"mappings":";;;;;;;;;AAMA,MAAa,kCAAkC;CAC7C,MAAM,cAAcA,yEAClBC,6BAAW,wBACZ;CACD,MAAMC,+BAA8C;AAClD,eAAa;;AAGf,mCAAgB;AACd,SAAO,iBAAiB,aAAa,uBAAuB;AAE5D,eACE,OAAO,oBAAoB,aAAa,uBAAuB;IAChE,CAAC,YAAY,CAAC;;AAGnB,MAAa,6BACXF,yEACEC,6BAAW,yBACXE,mCACD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_plugins = require('./plugins.cjs');
|
|
3
3
|
let __intlayer_core = require("@intlayer/core");
|
|
4
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
5
4
|
|
|
6
5
|
//#region src/getDictionary.ts
|
|
7
6
|
const getDictionary = (dictionary, locale, additionalPlugins) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["intlayerNodePlugins","preactNodePlugins","markdownPlugin"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import {\n getDictionary as getDictionaryCore,\n type Plugins,\n} from '@intlayer/core';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<T['content']> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getDictionaryCore<T, L>(dictionary, locale as L, plugins);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["intlayerNodePlugins","preactNodePlugins","markdownPlugin"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import {\n getDictionary as getDictionaryCore,\n type Plugins,\n} from '@intlayer/core';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<T['content']> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getDictionaryCore<T, L>(dictionary, locale as L, plugins);\n};\n"],"mappings":";;;;;AAgBA,MAAa,iBAIX,YACA,QACA,sBACuC;AASvC,2CAA+B,YAAY,QARhB;EACzBA;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAG+D"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_plugins = require('./plugins.cjs');
|
|
3
3
|
let __intlayer_core = require("@intlayer/core");
|
|
4
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
5
4
|
|
|
6
5
|
//#region src/getIntlayer.ts
|
|
7
6
|
const getIntlayer = (key, locale, additionalPlugins) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["intlayerNodePlugins","preactNodePlugins","markdownPlugin"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore, type Plugins } from '@intlayer/core';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayerCore<T, L>(key, locale, plugins) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["intlayerNodePlugins","preactNodePlugins","markdownPlugin"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore, type Plugins } from '@intlayer/core';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayerCore<T, L>(key, locale, plugins) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n};\n"],"mappings":";;;;;AAcA,MAAa,eAIX,KACA,QACA,sBACG;AASH,yCAA6B,KAAK,QARP;EACzBA;EACAC;EACAC;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAGiD"}
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
5
|
let preact_compat = require("preact/compat");
|
|
6
|
-
preact_compat = require_rolldown_runtime.__toESM(preact_compat);
|
|
7
6
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
8
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
9
7
|
|
|
10
8
|
//#region src/markdown/MarkdownProvider.tsx
|
|
11
9
|
const MarkdownContext = (0, preact_compat.createContext)({ renderMarkdown: (markdown) => markdown });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownProvider.cjs","names":["MarkdownProvider: FC<MarkdownProviderProps>"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useContext,\n} from 'preact/compat';\n\ntype MarkdownContextValue = {\n renderMarkdown: (markdown: string) => ReactNode;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<MarkdownContextValue>;\n\nconst MarkdownContext = createContext<MarkdownContextValue>({\n renderMarkdown: (markdown: string) => markdown,\n});\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nexport const MarkdownProvider: FC<MarkdownProviderProps> = ({\n children,\n renderMarkdown,\n}) => (\n <MarkdownContext.Provider value={{ renderMarkdown }}>\n {children}\n </MarkdownContext.Provider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarkdownProvider.cjs","names":["MarkdownProvider: FC<MarkdownProviderProps>"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useContext,\n} from 'preact/compat';\n\ntype MarkdownContextValue = {\n renderMarkdown: (markdown: string) => ReactNode;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<MarkdownContextValue>;\n\nconst MarkdownContext = createContext<MarkdownContextValue>({\n renderMarkdown: (markdown: string) => markdown,\n});\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nexport const MarkdownProvider: FC<MarkdownProviderProps> = ({\n children,\n renderMarkdown,\n}) => (\n <MarkdownContext.Provider value={{ renderMarkdown }}>\n {children}\n </MarkdownContext.Provider>\n);\n"],"mappings":";;;;;;;;AAgBA,MAAM,mDAAsD,EAC1D,iBAAiB,aAAqB,UACvC,CAAC;AAEF,MAAa,yDAAsC,gBAAgB;AAEnE,MAAaA,oBAA+C,EAC1D,UACA,qBAEA,4CAAC,gBAAgB;CAAS,OAAO,EAAE,gBAAgB;CAChD;EACwB"}
|
|
@@ -5,7 +5,6 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
5
5
|
const require_editor_useEditedContentRenderer = require('../editor/useEditedContentRenderer.cjs');
|
|
6
6
|
const require_markdown_MarkdownProvider = require('./MarkdownProvider.cjs');
|
|
7
7
|
let __intlayer_core = require("@intlayer/core");
|
|
8
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
9
8
|
|
|
10
9
|
//#region src/markdown/MarkdownRenderer.tsx
|
|
11
10
|
const MarkdownRenderer = ({ dictionaryKey, keyPath, children, locale }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.cjs","names":["MarkdownRenderer: FC<MarkdownRendererProps>","useMarkdownContext","useEditedContentRenderer","MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps>"],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["'use client';\n\nimport {\n getContent,\n getContentNodeByKeyPath,\n getMarkdownMetadata,\n} from '@intlayer/core';\nimport type { ContentNode, KeyPath, LocalesValues } from '@intlayer/types';\nimport type { FC, ReactNode } from 'preact/compat';\nimport { useEditedContentRenderer } from '../editor/useEditedContentRenderer';\nimport { useMarkdownContext } from './MarkdownProvider';\n\ntype MarkdownRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n};\n\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n dictionaryKey,\n keyPath,\n children,\n locale,\n}): ReactNode => {\n const { renderMarkdown } = useMarkdownContext();\n const editedContentContext = useEditedContentRenderer({\n dictionaryKey,\n keyPath,\n children,\n });\n\n if (typeof editedContentContext !== 'string') {\n const transformedEditedContent = getContent(\n editedContentContext,\n {\n dictionaryKey,\n keyPath,\n },\n locale\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect Markdown content. Edited Markdown content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return renderMarkdown(children);\n }\n\n return renderMarkdown(transformedEditedContent);\n }\n\n return renderMarkdown(editedContentContext);\n};\n\ntype MarkdownMetadataRendererProps = MarkdownRendererProps & {\n metadataKeyPath: KeyPath[];\n};\n\nexport const MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps> = ({\n dictionaryKey,\n keyPath,\n children,\n metadataKeyPath,\n}): ReactNode => {\n const editedContentContext = useEditedContentRenderer({\n dictionaryKey,\n keyPath,\n children,\n });\n const metadata = getMarkdownMetadata(editedContentContext);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath\n );\n\n return metadataEl as ReactNode;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.cjs","names":["MarkdownRenderer: FC<MarkdownRendererProps>","useMarkdownContext","useEditedContentRenderer","MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps>"],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"sourcesContent":["'use client';\n\nimport {\n getContent,\n getContentNodeByKeyPath,\n getMarkdownMetadata,\n} from '@intlayer/core';\nimport type { ContentNode, KeyPath, LocalesValues } from '@intlayer/types';\nimport type { FC, ReactNode } from 'preact/compat';\nimport { useEditedContentRenderer } from '../editor/useEditedContentRenderer';\nimport { useMarkdownContext } from './MarkdownProvider';\n\ntype MarkdownRendererProps = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: LocalesValues;\n children: string;\n};\n\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n dictionaryKey,\n keyPath,\n children,\n locale,\n}): ReactNode => {\n const { renderMarkdown } = useMarkdownContext();\n const editedContentContext = useEditedContentRenderer({\n dictionaryKey,\n keyPath,\n children,\n });\n\n if (typeof editedContentContext !== 'string') {\n const transformedEditedContent = getContent(\n editedContentContext,\n {\n dictionaryKey,\n keyPath,\n },\n locale\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect Markdown content. Edited Markdown content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return renderMarkdown(children);\n }\n\n return renderMarkdown(transformedEditedContent);\n }\n\n return renderMarkdown(editedContentContext);\n};\n\ntype MarkdownMetadataRendererProps = MarkdownRendererProps & {\n metadataKeyPath: KeyPath[];\n};\n\nexport const MarkdownMetadataRenderer: FC<MarkdownMetadataRendererProps> = ({\n dictionaryKey,\n keyPath,\n children,\n metadataKeyPath,\n}): ReactNode => {\n const editedContentContext = useEditedContentRenderer({\n dictionaryKey,\n keyPath,\n children,\n });\n const metadata = getMarkdownMetadata(editedContentContext);\n\n const metadataEl = getContentNodeByKeyPath(\n metadata as ContentNode,\n metadataKeyPath\n );\n\n return metadataEl as ReactNode;\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAaA,oBAA+C,EAC1D,eACA,SACA,UACA,aACe;CACf,MAAM,EAAE,mBAAmBC,sDAAoB;CAC/C,MAAM,uBAAuBC,iEAAyB;EACpD;EACA;EACA;EACD,CAAC;AAEF,KAAI,OAAO,yBAAyB,UAAU;EAC5C,MAAM,2DACJ,sBACA;GACE;GACA;GACD,EACD,OACD;AAED,MAAI,OAAO,6BAA6B,UAAU;AAChD,WAAQ,MACN,6DAA6D,OAAO,yBAAyB,2BAA2B,KAAK,UAAU,yBAAyB,GACjK;AAED,UAAO,eAAe,SAAS;;AAGjC,SAAO,eAAe,yBAAyB;;AAGjD,QAAO,eAAe,qBAAqB;;AAO7C,MAAaC,4BAA+D,EAC1E,eACA,SACA,UACA,sBACe;AAaf,8FAZ6BD,iEAAyB;EACpD;EACA;EACA;EACD,CAAC,CACwD,EAIxD,gBACD"}
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -5,13 +5,9 @@ const require_editor_useEditedContentRenderer = require('./editor/useEditedConte
|
|
|
5
5
|
const require_markdown_MarkdownRenderer = require('./markdown/MarkdownRenderer.cjs');
|
|
6
6
|
const require_preactElement_renderPreactElement = require('./preactElement/renderPreactElement.cjs');
|
|
7
7
|
let preact = require("preact");
|
|
8
|
-
preact = require_rolldown_runtime.__toESM(preact);
|
|
9
8
|
let __intlayer_core = require("@intlayer/core");
|
|
10
|
-
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
11
9
|
let __intlayer_types = require("@intlayer/types");
|
|
12
|
-
__intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
|
|
13
10
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
14
|
-
preact_jsx_runtime = require_rolldown_runtime.__toESM(preact_jsx_runtime);
|
|
15
11
|
|
|
16
12
|
//#region src/plugins.tsx
|
|
17
13
|
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["intlayerNodePlugins: Plugins","renderIntlayerNode","ContentSelectorRenderer","EditedContentRenderer","preactNodePlugins: Plugins","renderPreactElement","markdownStringPlugin: Plugins","props","MarkdownMetadataRenderer","MarkdownRenderer","markdownPlugin: Plugins","NodeType","newKeyPath: KeyPath[]"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import {\n type DeepTransformContent as DeepTransformContentCore,\n getMarkdownMetadata,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type MarkdownContent,\n type Plugins,\n} from '@intlayer/core';\nimport type { DeclaredLocales, KeyPath, LocalesValues } from '@intlayer/types';\nimport { NodeType } from '@intlayer/types';\nimport type { ComponentChildren } from 'preact';\nimport { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { MarkdownMetadataRenderer, MarkdownRenderer } from './markdown';\nimport { renderPreactElement } from './preactElement/renderPreactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children: (\n <ContentSelectorRenderer {...rest} key={rest.children}>\n <EditedContentRenderer {...rest}>\n {rest.children}\n </EditedContentRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/** ---------------------------------------------\n * PREACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type PreactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ComponentChildren\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const preactNodePlugins: Plugins = {\n id: 'preact-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[preact-element]]',\n children: (\n <ContentSelectorRenderer {...rest}>\n {renderPreactElement(node)}\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins = {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node);\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n return renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRenderer {...rest}>{node}</MarkdownRenderer>\n </ContentSelectorRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n },\n};\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: infer M;\n metadata?: infer U;\n}\n ? IntlayerNode<DeepTransformContent<M>, { metadata: DeepTransformContent<U> }>\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Markdown,\n },\n ];\n\n const children = node[NodeType.Markdown];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginPreact<T> {\n preactNode: PreactNodeCond<T>;\n intlayerNode: IntlayerNodeCond<T>;\n markdown: MarkdownCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `preact-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = IInterpreterPluginStateCore & {\n preactNode: true;\n intlayerNode: true;\n markdown: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["intlayerNodePlugins: Plugins","renderIntlayerNode","ContentSelectorRenderer","EditedContentRenderer","preactNodePlugins: Plugins","renderPreactElement","markdownStringPlugin: Plugins","props","MarkdownMetadataRenderer","MarkdownRenderer","markdownPlugin: Plugins","NodeType","newKeyPath: KeyPath[]"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import {\n type DeepTransformContent as DeepTransformContentCore,\n getMarkdownMetadata,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n type MarkdownContent,\n type Plugins,\n} from '@intlayer/core';\nimport type { DeclaredLocales, KeyPath, LocalesValues } from '@intlayer/types';\nimport { NodeType } from '@intlayer/types';\nimport type { ComponentChildren } from 'preact';\nimport { ContentSelectorRenderer } from './editor';\nimport { EditedContentRenderer } from './editor/useEditedContentRenderer';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { MarkdownMetadataRenderer, MarkdownRenderer } from './markdown';\nimport { renderPreactElement } from './preactElement/renderPreactElement';\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children: (\n <ContentSelectorRenderer {...rest} key={rest.children}>\n <EditedContentRenderer {...rest}>\n {rest.children}\n </EditedContentRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/** ---------------------------------------------\n * PREACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type PreactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ComponentChildren\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const preactNodePlugins: Plugins = {\n id: 'preact-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[preact-element]]',\n children: (\n <ContentSelectorRenderer {...rest}>\n {renderPreactElement(node)}\n </ContentSelectorRenderer>\n ),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins = {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node);\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownMetadataRenderer\n {...rest}\n metadataKeyPath={props.keyPath}\n >\n {node}\n </MarkdownMetadataRenderer>\n </ContentSelectorRenderer>\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n return renderIntlayerNode({\n ...props,\n value: node,\n children: (\n <ContentSelectorRenderer {...rest}>\n <MarkdownRenderer {...rest}>{node}</MarkdownRenderer>\n </ContentSelectorRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n },\n};\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.Markdown]: infer M;\n metadata?: infer U;\n}\n ? IntlayerNode<DeepTransformContent<M>, { metadata: DeepTransformContent<U> }>\n : never;\n\nexport const markdownPlugin: Plugins = {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Markdown,\n },\n ];\n\n const children = node[NodeType.Markdown];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport interface IInterpreterPluginPreact<T> {\n preactNode: PreactNodeCond<T>;\n intlayerNode: IntlayerNodeCond<T>;\n markdown: MarkdownCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `preact-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = IInterpreterPluginStateCore & {\n preactNode: true;\n intlayerNode: true;\n markdown: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAaA,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,QACA,GAAG,WAGLC,wCAAmB;EACjB,GAAG;EACH,OAAO,KAAK;EACZ,UACE,0CAACC;GAAwB,GAAI;GAAM,KAAK,KAAK;KAC3C,4CAACC;GAAsB,GAAI;aACxB,KAAK;IACgB,CACA;EAE7B,CAAC;CACL;;AAcD,MAAaC,oBAA6B;CACxC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,KAAK,UAAU,eACtB,OAAO,KAAK,QAAQ;CAEtB,YACE,MACA,EACE,QACA,GAAG,WAGLH,wCAAmB;EACjB,GAAG;EACH,OAAO;EACP,UACE,4CAACC;GAAwB,GAAI;aAC1BG,8DAAoB,KAAK;IACF;EAE7B,CAAC;CACL;;AAWD,MAAaC,uBAAgC;CAC3C,IAAI;CACJ,YAAY,SAAS,OAAO,SAAS;CACrC,YAAY,MAAc,OAAO,sBAAsB;EACrD,MAAM,EACJ,QACA,GAAG,SACD;EA6BJ,MAAM,gBAAgB,2DA3Be,KAAK,EA2BQ;GAChD,SAAS,CA1BsB;IAC/B,IAAI;IACJ,YAAY,iBACV,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,YACxB,OAAO,iBAAiB,aACxB,CAAC;IACH,YAAY,cAAc,YACxBL,wCAAmB;KACjB,GAAGM;KACH,OAAO;KACP,UACE,4CAACL;MAAwB,GAAI;gBAC3B,4CAACM;OACC,GAAI;OACJ,iBAAiBD,QAAM;iBAEtB;QACwB;OACH;KAE7B,CAAC;IACL,CAI2B;GAC1B,eAAe,KAAK;GACpB,SAAS,EAAE;GACZ,CAAC;AAEF,SAAON,wCAAmB;GACxB,GAAG;GACH,OAAO;GACP,UACE,4CAACC;IAAwB,GAAI;cAC3B,4CAACO;KAAiB,GAAI;eAAO;MAAwB;KAC7B;GAE5B,iBAAiB,EACf,UAAU,eACX;GACF,CAAC;;CAEL;AAUD,MAAaC,iBAA0B;CACrC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaC,0BAAS;CAC1D,YAAY,MAAuB,OAAO,sBAAsB;EAC9D,MAAMC,aAAwB,CAC5B,GAAG,MAAM,SACT,EACE,MAAMD,0BAAS,UAChB,CACF;EAED,MAAM,WAAW,KAAKA,0BAAS;AAE/B,SAAO,kBAAkB,UAAU;GACjC,GAAG;GACH;GACA,SAAS;GACT,SAAS,CAAC,sBAAsB,GAAI,MAAM,WAAW,EAAE,CAAE;GAC1D,CAAC;;CAEL"}
|