preact-intlayer 8.1.2 → 8.1.3

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.
Files changed (228) hide show
  1. package/dist/cjs/IntlayerNode.cjs +1 -16
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -1
  3. package/dist/cjs/UI/ContentSelector.cjs +1 -98
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
  6. package/dist/cjs/client/IntlayerProvider.cjs +1 -91
  7. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  8. package/dist/cjs/client/format/index.cjs +1 -18
  9. package/dist/cjs/client/format/useCompact.cjs +1 -29
  10. package/dist/cjs/client/format/useCompact.cjs.map +1 -1
  11. package/dist/cjs/client/format/useCurrency.cjs +1 -43
  12. package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
  13. package/dist/cjs/client/format/useDate.cjs +1 -45
  14. package/dist/cjs/client/format/useDate.cjs.map +1 -1
  15. package/dist/cjs/client/format/useIntl.cjs +1 -33
  16. package/dist/cjs/client/format/useIntl.cjs.map +1 -1
  17. package/dist/cjs/client/format/useList.cjs +1 -40
  18. package/dist/cjs/client/format/useList.cjs.map +1 -1
  19. package/dist/cjs/client/format/useNumber.cjs +1 -41
  20. package/dist/cjs/client/format/useNumber.cjs.map +1 -1
  21. package/dist/cjs/client/format/usePercentage.cjs +1 -37
  22. package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
  23. package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
  24. package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
  25. package/dist/cjs/client/format/useUnit.cjs +1 -36
  26. package/dist/cjs/client/format/useUnit.cjs.map +1 -1
  27. package/dist/cjs/client/index.cjs +1 -32
  28. package/dist/cjs/client/t.cjs +1 -21
  29. package/dist/cjs/client/t.cjs.map +1 -1
  30. package/dist/cjs/client/useContent.cjs +1 -19
  31. package/dist/cjs/client/useContent.cjs.map +1 -1
  32. package/dist/cjs/client/useDictionary.cjs +1 -27
  33. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  34. package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
  35. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  36. package/dist/cjs/client/useDictionaryDynamic.cjs +1 -23
  37. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  38. package/dist/cjs/client/useIntlayer.cjs +1 -42
  39. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  40. package/dist/cjs/client/useLoadDynamic.cjs +1 -27
  41. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
  42. package/dist/cjs/client/useLocale.cjs +1 -56
  43. package/dist/cjs/client/useLocale.cjs.map +1 -1
  44. package/dist/cjs/client/useLocaleBase.cjs +1 -26
  45. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  46. package/dist/cjs/client/useLocaleStorage.cjs +1 -58
  47. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
  48. package/dist/cjs/client/useTraduction.cjs +1 -35
  49. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  50. package/dist/cjs/editor/CommunicatorContext.cjs +1 -39
  51. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
  52. package/dist/cjs/editor/ConfigurationContext.cjs +1 -26
  53. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
  54. package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -58
  55. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
  56. package/dist/cjs/editor/DictionariesRecordContext.cjs +1 -48
  57. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
  58. package/dist/cjs/editor/EditedContentContext.cjs +1 -163
  59. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
  60. package/dist/cjs/editor/EditorEnabledContext.cjs +1 -34
  61. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
  62. package/dist/cjs/editor/EditorProvider.cjs +1 -64
  63. package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
  64. package/dist/cjs/editor/FocusDictionaryContext.cjs +1 -54
  65. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
  66. package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -63
  67. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
  68. package/dist/cjs/editor/index.cjs +1 -4
  69. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -78
  70. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
  71. package/dist/cjs/editor/useCrossFrameState.cjs +1 -108
  72. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
  73. package/dist/cjs/editor/useCrossURLPathState.cjs +1 -67
  74. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
  75. package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -29
  76. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
  77. package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -24
  78. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
  79. package/dist/cjs/getDictionary.cjs +1 -19
  80. package/dist/cjs/getDictionary.cjs.map +1 -1
  81. package/dist/cjs/getIntlayer.cjs +1 -19
  82. package/dist/cjs/getIntlayer.cjs.map +1 -1
  83. package/dist/cjs/html/HTMLProvider.cjs +1 -19
  84. package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
  85. package/dist/cjs/html/HTMLRenderer.cjs +1 -61
  86. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
  87. package/dist/cjs/html/index.cjs +1 -10
  88. package/dist/cjs/index.cjs +1 -57
  89. package/dist/cjs/markdown/MarkdownProvider.cjs +1 -49
  90. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  91. package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -77
  92. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  93. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -31
  94. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
  95. package/dist/cjs/markdown/compiler.cjs +1 -24
  96. package/dist/cjs/markdown/compiler.cjs.map +1 -1
  97. package/dist/cjs/markdown/index.cjs +1 -23
  98. package/dist/cjs/markdown/runtime.cjs +1 -18
  99. package/dist/cjs/markdown/runtime.cjs.map +1 -1
  100. package/dist/cjs/plugins.cjs +1 -197
  101. package/dist/cjs/plugins.cjs.map +1 -1
  102. package/dist/cjs/preactElement/renderPreactElement.cjs +1 -42
  103. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
  104. package/dist/esm/IntlayerNode.mjs +1 -14
  105. package/dist/esm/IntlayerNode.mjs.map +1 -1
  106. package/dist/esm/UI/ContentSelector.mjs +1 -96
  107. package/dist/esm/UI/ContentSelector.mjs.map +1 -1
  108. package/dist/esm/client/IntlayerProvider.mjs +1 -85
  109. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  110. package/dist/esm/client/format/index.mjs +1 -10
  111. package/dist/esm/client/format/useCompact.mjs +1 -27
  112. package/dist/esm/client/format/useCompact.mjs.map +1 -1
  113. package/dist/esm/client/format/useCurrency.mjs +1 -41
  114. package/dist/esm/client/format/useCurrency.mjs.map +1 -1
  115. package/dist/esm/client/format/useDate.mjs +1 -43
  116. package/dist/esm/client/format/useDate.mjs.map +1 -1
  117. package/dist/esm/client/format/useIntl.mjs +1 -31
  118. package/dist/esm/client/format/useIntl.mjs.map +1 -1
  119. package/dist/esm/client/format/useList.mjs +1 -38
  120. package/dist/esm/client/format/useList.mjs.map +1 -1
  121. package/dist/esm/client/format/useNumber.mjs +1 -39
  122. package/dist/esm/client/format/useNumber.mjs.map +1 -1
  123. package/dist/esm/client/format/usePercentage.mjs +1 -35
  124. package/dist/esm/client/format/usePercentage.mjs.map +1 -1
  125. package/dist/esm/client/format/useRelativeTime.mjs +1 -35
  126. package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
  127. package/dist/esm/client/format/useUnit.mjs +1 -34
  128. package/dist/esm/client/format/useUnit.mjs.map +1 -1
  129. package/dist/esm/client/index.mjs +1 -13
  130. package/dist/esm/client/t.mjs +1 -19
  131. package/dist/esm/client/t.mjs.map +1 -1
  132. package/dist/esm/client/useContent.mjs +1 -18
  133. package/dist/esm/client/useContent.mjs.map +1 -1
  134. package/dist/esm/client/useDictionary.mjs +1 -25
  135. package/dist/esm/client/useDictionary.mjs.map +1 -1
  136. package/dist/esm/client/useDictionaryAsync.mjs +1 -21
  137. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  138. package/dist/esm/client/useDictionaryDynamic.mjs +1 -21
  139. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  140. package/dist/esm/client/useIntlayer.mjs +1 -40
  141. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  142. package/dist/esm/client/useLoadDynamic.mjs +1 -25
  143. package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
  144. package/dist/esm/client/useLocale.mjs +1 -53
  145. package/dist/esm/client/useLocale.mjs.map +1 -1
  146. package/dist/esm/client/useLocaleBase.mjs +1 -23
  147. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  148. package/dist/esm/client/useLocaleStorage.mjs +1 -51
  149. package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
  150. package/dist/esm/client/useTraduction.mjs +1 -33
  151. package/dist/esm/client/useTraduction.mjs.map +1 -1
  152. package/dist/esm/editor/CommunicatorContext.mjs +1 -35
  153. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
  154. package/dist/esm/editor/ConfigurationContext.mjs +1 -22
  155. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
  156. package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -56
  157. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
  158. package/dist/esm/editor/DictionariesRecordContext.mjs +1 -44
  159. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
  160. package/dist/esm/editor/EditedContentContext.mjs +1 -157
  161. package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
  162. package/dist/esm/editor/EditorEnabledContext.mjs +1 -28
  163. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
  164. package/dist/esm/editor/EditorProvider.mjs +1 -62
  165. package/dist/esm/editor/EditorProvider.mjs.map +1 -1
  166. package/dist/esm/editor/FocusDictionaryContext.mjs +1 -50
  167. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
  168. package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -60
  169. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
  170. package/dist/esm/editor/index.mjs +1 -3
  171. package/dist/esm/editor/useCrossFrameMessageListener.mjs +1 -76
  172. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
  173. package/dist/esm/editor/useCrossFrameState.mjs +1 -106
  174. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
  175. package/dist/esm/editor/useCrossURLPathState.mjs +1 -64
  176. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
  177. package/dist/esm/editor/useEditedContentRenderer.mjs +1 -26
  178. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
  179. package/dist/esm/editor/useIframeClickInterceptor.mjs +1 -21
  180. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
  181. package/dist/esm/getDictionary.mjs +1 -17
  182. package/dist/esm/getDictionary.mjs.map +1 -1
  183. package/dist/esm/getIntlayer.mjs +1 -17
  184. package/dist/esm/getIntlayer.mjs.map +1 -1
  185. package/dist/esm/html/HTMLProvider.mjs +1 -16
  186. package/dist/esm/html/HTMLProvider.mjs.map +1 -1
  187. package/dist/esm/html/HTMLRenderer.mjs +1 -56
  188. package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
  189. package/dist/esm/html/index.mjs +1 -4
  190. package/dist/esm/index.mjs +1 -22
  191. package/dist/esm/markdown/MarkdownProvider.mjs +1 -46
  192. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  193. package/dist/esm/markdown/MarkdownRenderer.mjs +1 -73
  194. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  195. package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -28
  196. package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
  197. package/dist/esm/markdown/compiler.mjs +1 -17
  198. package/dist/esm/markdown/compiler.mjs.map +1 -1
  199. package/dist/esm/markdown/index.mjs +1 -7
  200. package/dist/esm/markdown/runtime.mjs +1 -15
  201. package/dist/esm/markdown/runtime.mjs.map +1 -1
  202. package/dist/esm/plugins.mjs +1 -190
  203. package/dist/esm/plugins.mjs.map +1 -1
  204. package/dist/esm/preactElement/renderPreactElement.mjs +1 -40
  205. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
  206. package/dist/types/IntlayerNode.d.ts +1 -1
  207. package/dist/types/client/format/useDate.d.ts +1 -1
  208. package/dist/types/client/useDictionary.d.ts +2 -2
  209. package/dist/types/client/useDictionary.d.ts.map +1 -1
  210. package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
  211. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
  212. package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
  213. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
  214. package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
  215. package/dist/types/getDictionary.d.ts +1 -1
  216. package/dist/types/getIntlayer.d.ts +1 -1
  217. package/dist/types/getIntlayer.d.ts.map +1 -1
  218. package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
  219. package/dist/types/html/types.d.ts +1 -1
  220. package/dist/types/html/types.d.ts.map +1 -1
  221. package/dist/types/index.d.ts +1 -1
  222. package/dist/types/index.d.ts.map +1 -1
  223. package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
  224. package/dist/types/markdown/compiler.d.ts +1 -1
  225. package/dist/types/markdown/runtime.d.ts +1 -1
  226. package/dist/types/plugins.d.ts +2 -2
  227. package/dist/types/plugins.d.ts.map +1 -1
  228. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"EditedContentContext.cjs","names":["useCrossFrameMessageListener","MessageKey","useDictionariesRecord","useCrossFrameState","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 FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { type StateUpdater, 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: CrossFrameStateUpdater<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,>(\n state?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: CrossFrameStateUpdater<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\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":"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"}
1
+ {"version":3,"file":"EditedContentContext.cjs","names":["useCrossFrameMessageListener","MessageKey","useDictionariesRecord","useCrossFrameState","NodeType"],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\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 FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\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: CrossFrameStateUpdater<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,>(\n state?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: CrossFrameStateUpdater<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\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 = { ...prev };\n delete filtered[dictionaryLocalId];\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":"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"}
@@ -1,35 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
6
- const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
7
- let preact = require("preact");
8
- let _intlayer_editor = require("@intlayer/editor");
9
- let preact_hooks = require("preact/hooks");
10
- let preact_jsx_runtime = require("preact/jsx-runtime");
11
-
12
- //#region src/editor/EditorEnabledContext.tsx
13
- const EditorEnabledContext = (0, preact.createContext)({ enabled: false });
14
- const useEditorEnabledState = (options) => require_editor_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_EDITOR_ENABLED, false, options);
15
- const usePostEditorEnabledState = (onEventTriggered) => require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${_intlayer_editor.MessageKey.INTLAYER_EDITOR_ENABLED}/post`, onEventTriggered);
16
- const useGetEditorEnabledState = (onEventTriggered) => require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${_intlayer_editor.MessageKey.INTLAYER_EDITOR_ENABLED}/get`, onEventTriggered);
17
- const EditorEnabledProvider = ({ children }) => {
18
- const [isEnabled] = useEditorEnabledState({
19
- emit: false,
20
- receive: true
21
- });
22
- return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(EditorEnabledContext.Provider, {
23
- value: { enabled: isEnabled },
24
- children
25
- });
26
- };
27
- const useEditorEnabled = () => (0, preact_hooks.useContext)(EditorEnabledContext);
28
-
29
- //#endregion
30
- exports.EditorEnabledProvider = EditorEnabledProvider;
31
- exports.useEditorEnabled = useEditorEnabled;
32
- exports.useEditorEnabledState = useEditorEnabledState;
33
- exports.useGetEditorEnabledState = useGetEditorEnabledState;
34
- exports.usePostEditorEnabledState = usePostEditorEnabledState;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`);let n=require(`preact`),r=require(`@intlayer/editor`),i=require(`preact/hooks`),a=require(`preact/jsx-runtime`);const o=(0,n.createContext)({enabled:!1}),s=e=>t.useCrossFrameState(r.MessageKey.INTLAYER_EDITOR_ENABLED,!1,e),c=t=>e.useCrossFrameMessageListener(`${r.MessageKey.INTLAYER_EDITOR_ENABLED}/post`,t),l=t=>e.useCrossFrameMessageListener(`${r.MessageKey.INTLAYER_EDITOR_ENABLED}/get`,t),u=({children:e})=>{let[t]=s({emit:!1,receive:!0});return(0,a.jsx)(o.Provider,{value:{enabled:t},children:e})},d=()=>(0,i.useContext)(o);exports.EditorEnabledProvider=u,exports.useEditorEnabled=d,exports.useEditorEnabledState=s,exports.useGetEditorEnabledState=l,exports.usePostEditorEnabledState=c;
35
2
  //# sourceMappingURL=EditorEnabledContext.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditorEnabledContext.cjs","names":["useCrossFrameState","MessageKey","useCrossFrameMessageListener"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\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: FunctionalComponent<\n RenderableProps<{}>\n> = ({ 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,iDAA8D,EAClE,SAAS,OACV,CAAC;AAEF,MAAa,yBAAyB,YACpCA,qDAAmBC,4BAAW,yBAAyB,OAAO,QAAQ;AAExE,MAAa,6BACX,qBAEAC,yEACE,GAAGD,4BAAW,wBAAwB,QACtC,iBACD;AAEH,MAAa,4BACX,qBAEAC,yEACE,GAAGD,4BAAW,wBAAwB,OACtC,iBACD;AAEH,MAAa,yBAER,EAAE,eAAe;CACpB,MAAM,CAAC,aAAa,sBAAsB;EACxC,MAAM;EACN,SAAS;EACV,CAAC;AAEF,QACE,4CAAC,qBAAqB;EAAS,OAAO,EAAE,SAAS,WAAW;EACzD;GAC6B;;AAIpC,MAAa,sDAAoC,qBAAqB"}
1
+ {"version":3,"file":"EditorEnabledContext.cjs","names":["useCrossFrameState","MessageKey","useCrossFrameMessageListener"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\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: FunctionalComponent<\n RenderableProps<{}>\n> = ({ 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":"yUAmBA,MAAM,GAAA,EAAA,EAAA,eAA8D,CAClE,QAAS,GACV,CAAC,CAEW,EAAyB,GACpCA,EAAAA,mBAAmBC,EAAAA,WAAW,wBAAyB,GAAO,EAAQ,CAE3D,EACX,GAEAC,EAAAA,6BACE,GAAGD,EAAAA,WAAW,wBAAwB,OACtC,EACD,CAEU,EACX,GAEAC,EAAAA,6BACE,GAAGD,EAAAA,WAAW,wBAAwB,MACtC,EACD,CAEU,GAER,CAAE,cAAe,CACpB,GAAM,CAAC,GAAa,EAAsB,CACxC,KAAM,GACN,QAAS,GACV,CAAC,CAEF,OACE,EAAA,EAAA,KAAC,EAAqB,SAAA,CAAS,MAAO,CAAE,QAAS,EAAW,CACzD,YAC6B,EAIvB,OAAA,EAAA,EAAA,YAAoC,EAAqB"}
@@ -1,65 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
6
- const require_editor_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
7
- const require_editor_EditorEnabledContext = require('./EditorEnabledContext.cjs');
8
- const require_editor_ConfigurationContext = require('./ConfigurationContext.cjs');
9
- const require_editor_EditedContentContext = require('./EditedContentContext.cjs');
10
- const require_editor_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
11
- let preact_hooks = require("preact/hooks");
12
- let preact_jsx_runtime = require("preact/jsx-runtime");
13
-
14
- //#region src/editor/EditorProvider.tsx
15
- /**
16
- * This component add all the providers needed by the editor.
17
- * It is used to wrap the application, or the editor to work together.
18
- */
19
- const EditorProvidersWrapper = ({ children }) => {
20
- const getEditedContentState = require_editor_EditedContentContext.useGetEditedContentState();
21
- (0, preact_hooks.useEffect)(() => {
22
- getEditedContentState();
23
- }, []);
24
- return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_DictionariesRecordContext.DictionariesRecordProvider, { children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_EditedContentContext.EditedContentProvider, { children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_FocusDictionaryContext.FocusDictionaryProvider, { children }) }) });
25
- };
26
- /**
27
- * This component check if the editor is enabled to render the editor providers.
28
- */
29
- const EditorEnabledCheckRenderer = ({ children, fallback }) => {
30
- const getEditorEnabled = require_editor_EditorEnabledContext.useGetEditorEnabledState();
31
- const { enabled } = require_editor_EditorEnabledContext.useEditorEnabled();
32
- (0, preact_hooks.useEffect)(() => {
33
- if (enabled) return;
34
- getEditorEnabled();
35
- }, [enabled]);
36
- return enabled ? children : fallback;
37
- };
38
- /**
39
- * This component is used to check if the editor is wrapping the application.
40
- * It avoid to send window.postMessage to the application if the editor is not wrapping the application.
41
- */
42
- const IframeCheckRenderer = ({ children, fallback }) => {
43
- const [isInIframe, setIsInIframe] = (0, preact_hooks.useState)(false);
44
- (0, preact_hooks.useEffect)(() => {
45
- setIsInIframe(window.self !== window.top);
46
- }, []);
47
- return isInIframe ? children : fallback;
48
- };
49
- const EditorProvider = ({ children, configuration, ...props }) => /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_EditorEnabledContext.EditorEnabledProvider, { children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_ConfigurationContext.ConfigurationProvider, {
50
- configuration,
51
- children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(IframeCheckRenderer, {
52
- fallback: children,
53
- children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_CommunicatorContext.CommunicatorProvider, {
54
- ...props,
55
- children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(EditorEnabledCheckRenderer, {
56
- fallback: children,
57
- children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(EditorProvidersWrapper, { children })
58
- })
59
- })
60
- })
61
- }) });
62
-
63
- //#endregion
64
- exports.EditorProvider = EditorProvider;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`),t=require(`./DictionariesRecordContext.cjs`),n=require(`./EditorEnabledContext.cjs`),r=require(`./ConfigurationContext.cjs`),i=require(`./EditedContentContext.cjs`),a=require(`./FocusDictionaryContext.cjs`);let o=require(`preact/hooks`),s=require(`preact/jsx-runtime`);const c=({children:e})=>{let n=i.useGetEditedContentState();return(0,o.useEffect)(()=>{n()},[]),(0,s.jsx)(t.DictionariesRecordProvider,{children:(0,s.jsx)(i.EditedContentProvider,{children:(0,s.jsx)(a.FocusDictionaryProvider,{children:e})})})},l=({children:e,fallback:t})=>{let r=n.useGetEditorEnabledState(),{enabled:i}=n.useEditorEnabled();return(0,o.useEffect)(()=>{i||r()},[i]),i?e:t},u=({children:e,fallback:t})=>{let[n,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{r(window.self!==window.top)},[]),n?e:t},d=({children:t,configuration:i,...a})=>(0,s.jsx)(n.EditorEnabledProvider,{children:(0,s.jsx)(r.ConfigurationProvider,{configuration:i,children:(0,s.jsx)(u,{fallback:t,children:(0,s.jsx)(e.CommunicatorProvider,{...a,children:(0,s.jsx)(l,{fallback:t,children:(0,s.jsx)(c,{children:t})})})})})});exports.EditorProvider=d;
65
2
  //# sourceMappingURL=EditorProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditorProvider.cjs","names":["useGetEditedContentState","DictionariesRecordProvider","EditedContentProvider","FocusDictionaryProvider","useGetEditorEnabledState","useEditorEnabled","EditorEnabledProvider","ConfigurationProvider","CommunicatorProvider"],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport type {\n ComponentChildren,\n FunctionalComponent,\n RenderableProps,\n} from 'preact';\nimport { useEffect, useState } from 'preact/hooks';\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: FunctionalComponent<RenderableProps<{}>> = ({\n children,\n}) => {\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: ComponentChildren;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FunctionalComponent<\n RenderableProps<FallbackProps>\n> = ({ children, fallback }) => {\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: FunctionalComponent<\n RenderableProps<FallbackProps>\n> = ({ children, fallback }) => {\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: FunctionalComponent<\n RenderableProps<EditorProviderProps>\n> = ({ children, configuration, ...props }) => (\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":";;;;;;;;;;;;;;;;;;AAgCA,MAAM,0BAAoE,EACxE,eACI;CACJ,MAAM,wBAAwBA,8DAA0B;AAExD,mCAAgB;AACd,yBAAuB;IACtB,EAAE,CAAC;AAEN,QACE,4CAACC,iFACC,4CAACC,uEACC,4CAACC,iEAAyB,WAAmC,GACvC,GACG;;;;;AAWjC,MAAM,8BAED,EAAE,UAAU,eAAe;CAC9B,MAAM,mBAAmBC,8DAA0B;CAEnD,MAAM,EAAE,YAAYC,sDAAkB;AAEtC,mCAAgB;AACd,MAAI,QAAS;AAGb,oBAAkB;IACjB,CAAC,QAAQ,CAAC;AAEb,QAAO,UAAU,WAAW;;;;;;AAO9B,MAAM,uBAED,EAAE,UAAU,eAAe;CAC9B,MAAM,CAAC,YAAY,4CAA0B,MAAM;AAEnD,mCAAgB;AACd,gBAAc,OAAO,SAAS,OAAO,IAAI;IACxC,EAAE,CAAC;AAEN,QAAO,aAAa,WAAW;;AAMjC,MAAa,kBAER,EAAE,UAAU,eAAe,GAAG,YACjC,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"}
1
+ {"version":3,"file":"EditorProvider.cjs","names":["useGetEditedContentState","DictionariesRecordProvider","EditedContentProvider","FocusDictionaryProvider","useGetEditorEnabledState","useEditorEnabled","EditorEnabledProvider","ConfigurationProvider","CommunicatorProvider"],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport type {\n ComponentChildren,\n FunctionalComponent,\n RenderableProps,\n} from 'preact';\nimport { useEffect, useState } from 'preact/hooks';\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: FunctionalComponent<RenderableProps<{}>> = ({\n children,\n}) => {\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: ComponentChildren;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FunctionalComponent<\n RenderableProps<FallbackProps>\n> = ({ children, fallback }) => {\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: FunctionalComponent<\n RenderableProps<FallbackProps>\n> = ({ children, fallback }) => {\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: FunctionalComponent<\n RenderableProps<EditorProviderProps>\n> = ({ children, configuration, ...props }) => (\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":"ubAgCA,MAAM,GAAoE,CACxE,cACI,CACJ,IAAM,EAAwBA,EAAAA,0BAA0B,CAMxD,OAJA,EAAA,EAAA,eAAgB,CACd,GAAuB,EACtB,EAAE,CAAC,EAGJ,EAAA,EAAA,KAACC,EAAAA,2BAAAA,CAAAA,UACC,EAAA,EAAA,KAACC,EAAAA,sBAAAA,CAAAA,UACC,EAAA,EAAA,KAACC,EAAAA,wBAAAA,CAAyB,WAAA,CAAmC,CAAA,CACvC,CAAA,CACG,EAW3B,GAED,CAAE,WAAU,cAAe,CAC9B,IAAM,EAAmBC,EAAAA,0BAA0B,CAE7C,CAAE,WAAYC,EAAAA,kBAAkB,CAStC,OAPA,EAAA,EAAA,eAAgB,CACV,GAGJ,GAAkB,EACjB,CAAC,EAAQ,CAAC,CAEN,EAAU,EAAW,GAOxB,GAED,CAAE,WAAU,cAAe,CAC9B,GAAM,CAAC,EAAY,IAAA,EAAA,EAAA,UAA0B,GAAM,CAMnD,OAJA,EAAA,EAAA,eAAgB,CACd,EAAc,OAAO,OAAS,OAAO,IAAI,EACxC,EAAE,CAAC,CAEC,EAAa,EAAW,GAMpB,GAER,CAAE,WAAU,gBAAe,GAAG,MACjC,EAAA,EAAA,KAACC,EAAAA,sBAAAA,CAAAA,UACC,EAAA,EAAA,KAACC,EAAAA,sBAAAA,CAAqC,0BACpC,EAAA,EAAA,KAAC,EAAA,CAAoB,SAAU,YAC7B,EAAA,EAAA,KAACC,EAAAA,qBAAAA,CAAqB,GAAI,YACxB,EAAA,EAAA,KAAC,EAAA,CAA2B,SAAU,YACpC,EAAA,EAAA,KAAC,EAAA,CAAwB,WAAA,CAAkC,EAChC,EACR,EACH,EACA,CAAA,CACF"}
@@ -1,55 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
6
- let preact = require("preact");
7
- let _intlayer_editor = require("@intlayer/editor");
8
- let preact_hooks = require("preact/hooks");
9
- let preact_jsx_runtime = require("preact/jsx-runtime");
10
-
11
- //#region src/editor/FocusDictionaryContext.tsx
12
- const FocusDictionaryStateContext = (0, preact.createContext)(void 0);
13
- const FocusDictionaryActionsContext = (0, preact.createContext)(void 0);
14
- const FocusDictionaryProvider = ({ children }) => {
15
- const [focusedContent, setFocusedContent] = require_editor_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED, null);
16
- const setFocusedContentKeyPath = (keyPath) => {
17
- setFocusedContent((prev) => {
18
- if (!prev) return prev;
19
- return {
20
- ...prev,
21
- keyPath
22
- };
23
- });
24
- };
25
- return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(FocusDictionaryStateContext.Provider, {
26
- value: { focusedContent },
27
- children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(FocusDictionaryActionsContext.Provider, {
28
- value: {
29
- setFocusedContent,
30
- setFocusedContentKeyPath
31
- },
32
- children
33
- })
34
- });
35
- };
36
- const useFocusDictionaryActions = () => {
37
- const context = (0, preact_hooks.useContext)(FocusDictionaryActionsContext);
38
- if (context === void 0) throw new Error("useFocusDictionaryActions must be used within a FocusDictionaryProvider");
39
- return context;
40
- };
41
- const useFocusDictionary = () => {
42
- const actionContext = useFocusDictionaryActions();
43
- const stateContext = (0, preact_hooks.useContext)(FocusDictionaryStateContext);
44
- if (stateContext === void 0) throw new Error("useFocusDictionaryState must be used within a FocusDictionaryProvider");
45
- return {
46
- ...stateContext,
47
- ...actionContext
48
- };
49
- };
50
-
51
- //#endregion
52
- exports.FocusDictionaryProvider = FocusDictionaryProvider;
53
- exports.useFocusDictionary = useFocusDictionary;
54
- exports.useFocusDictionaryActions = useFocusDictionaryActions;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameState.cjs`);let t=require(`preact`),n=require(`@intlayer/editor`),r=require(`preact/hooks`),i=require(`preact/jsx-runtime`);const a=(0,t.createContext)(void 0),o=(0,t.createContext)(void 0),s=({children:t})=>{let[r,s]=e.useCrossFrameState(n.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,null);return(0,i.jsx)(a.Provider,{value:{focusedContent:r},children:(0,i.jsx)(o.Provider,{value:{setFocusedContent:s,setFocusedContentKeyPath:e=>{s(t=>t&&{...t,keyPath:e})}},children:t})})},c=()=>{let e=(0,r.useContext)(o);if(e===void 0)throw Error(`useFocusDictionaryActions must be used within a FocusDictionaryProvider`);return e},l=()=>{let e=c(),t=(0,r.useContext)(a);if(t===void 0)throw Error(`useFocusDictionaryState must be used within a FocusDictionaryProvider`);return{...t,...e}};exports.FocusDictionaryProvider=s,exports.useFocusDictionary=l,exports.useFocusDictionaryActions=c;
55
2
  //# sourceMappingURL=FocusDictionaryContext.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"FocusDictionaryContext.cjs","names":["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 FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport {\n type CrossFrameStateUpdater,\n useCrossFrameState,\n} 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: CrossFrameStateUpdater<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: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\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":";;;;;;;;;;;AAgCA,MAAM,wDAEJ,OAAU;AACZ,MAAM,0DAEJ,OAAU;AAEZ,MAAa,2BAER,EAAE,eAAe;CACpB,MAAM,CAAC,gBAAgB,qBACrBA,qDACEC,4BAAW,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,uCAAqB,8BAA8B;AACzD,KAAI,YAAY,OACd,OAAM,IAAI,MACR,0EACD;AAEH,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,gBAAgB,2BAA2B;CACjD,MAAM,4CAA0B,4BAA4B;AAE5D,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,wEACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
1
+ {"version":3,"file":"FocusDictionaryContext.cjs","names":["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 FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport {\n type CrossFrameStateUpdater,\n useCrossFrameState,\n} 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: CrossFrameStateUpdater<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: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\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":"yRAgCA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CACN,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,GAER,CAAE,cAAe,CACpB,GAAM,CAAC,EAAgB,GACrBA,EAAAA,mBACEC,EAAAA,WAAW,iCACX,KACD,CAWH,OACE,EAAA,EAAA,KAAC,EAA4B,SAAA,CAAS,MAAO,CAAE,iBAAgB,WAC7D,EAAA,EAAA,KAAC,EAA8B,SAAA,CAC7B,MAAO,CAAE,oBAAmB,yBAZA,GAAuB,CACvD,EAAmB,GACZ,GAGE,CAAE,GAAG,EAAM,UAAS,CAC3B,EAMwD,CAErD,YACsC,EACJ,EAI9B,MAAkC,CAC7C,IAAM,GAAA,EAAA,EAAA,YAAqB,EAA8B,CACzD,GAAI,IAAY,IAAA,GACd,MAAU,MACR,0EACD,CAEH,OAAO,GAGI,MAA2B,CACtC,IAAM,EAAgB,GAA2B,CAC3C,GAAA,EAAA,EAAA,YAA0B,EAA4B,CAE5D,GAAI,IAAiB,IAAA,GACnB,MAAU,MACR,wEACD,CAGH,MAAO,CAAE,GAAG,EAAc,GAAG,EAAe"}
@@ -1,64 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
6
- const require_editor_EditorEnabledContext = require('./EditorEnabledContext.cjs');
7
- const require_editor_EditorProvider = require('./EditorProvider.cjs');
8
- const require_editor_useCrossURLPathState = require('./useCrossURLPathState.cjs');
9
- const require_editor_useIframeClickInterceptor = require('./useIframeClickInterceptor.cjs');
10
- let preact_hooks = require("preact/hooks");
11
- let _intlayer_config_built = require("@intlayer/config/built");
12
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
13
- let preact_jsx_runtime = require("preact/jsx-runtime");
14
-
15
- //#region src/editor/IntlayerEditorProvider.tsx
16
- const IntlayerEditorHooksEnabled = () => {
17
- /**
18
- * URL Messages
19
- */
20
- require_editor_useCrossURLPathState.useCrossURLPathSetter();
21
- /**
22
- * Click Messages
23
- */
24
- require_editor_useIframeClickInterceptor.useIframeClickInterceptor();
25
- /**
26
- * Sent local dictionaries to editor
27
- */
28
- const { setLocaleDictionaries } = require_editor_DictionariesRecordContext.useDictionariesRecordActions() ?? {};
29
- (0, preact_hooks.useEffect)(() => {
30
- import("@intlayer/unmerged-dictionaries-entry").then((mod) => {
31
- const unmergedDictionaries = mod.getUnmergedDictionaries();
32
- const dictionariesList = Object.fromEntries(Object.values(unmergedDictionaries).flat().map((dictionary) => [dictionary.localId, dictionary]));
33
- setLocaleDictionaries?.(dictionariesList);
34
- });
35
- }, []);
36
- return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(preact_jsx_runtime.Fragment, {});
37
- };
38
- const { editor } = _intlayer_config_built.default;
39
- const IntlayerEditorHook = () => {
40
- const { enabled } = require_editor_EditorEnabledContext.useEditorEnabled();
41
- return enabled ? /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(preact_jsx_runtime.Fragment, {});
42
- };
43
- const IntlayerEditorProvider = ({ children }) => {
44
- return /* @__PURE__ */ (0, preact_jsx_runtime.jsxs)(require_editor_EditorProvider.EditorProvider, {
45
- postMessage: (data) => {
46
- if (typeof window === "undefined") return;
47
- if (!(window.self !== window.top)) return;
48
- if (editor.applicationURL.length > 0) window?.postMessage(data, editor.applicationURL);
49
- if (editor.editorURL.length > 0) window.parent?.postMessage(data, editor.editorURL);
50
- if (editor.cmsURL.length > 0) window.parent?.postMessage(data, editor.cmsURL);
51
- },
52
- allowedOrigins: [
53
- editor?.editorURL,
54
- editor?.cmsURL,
55
- editor?.applicationURL
56
- ],
57
- configuration: _intlayer_config_built.default,
58
- children: [/* @__PURE__ */ (0, preact_jsx_runtime.jsx)(IntlayerEditorHook, {}), children]
59
- });
60
- };
61
-
62
- //#endregion
63
- exports.IntlayerEditorProvider = IntlayerEditorProvider;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./DictionariesRecordContext.cjs`),n=require(`./EditorEnabledContext.cjs`),r=require(`./EditorProvider.cjs`),i=require(`./useCrossURLPathState.cjs`),a=require(`./useIframeClickInterceptor.cjs`);let o=require(`preact/hooks`),s=require(`@intlayer/config/built`);s=e.__toESM(s);let c=require(`preact/jsx-runtime`);const l=()=>{i.useCrossURLPathSetter(),a.useIframeClickInterceptor();let{setLocaleDictionaries:e}=t.useDictionariesRecordActions()??{};return(0,o.useEffect)(()=>{import(`@intlayer/unmerged-dictionaries-entry`).then(t=>{let n=t.getUnmergedDictionaries(),r=Object.fromEntries(Object.values(n).flat().map(e=>[e.localId,e]));e?.(r)})},[]),(0,c.jsx)(c.Fragment,{})},{editor:u}=s.default,d=()=>{let{enabled:e}=n.useEditorEnabled();return e?(0,c.jsx)(l,{}):(0,c.jsx)(c.Fragment,{})},f=({children:e})=>(0,c.jsxs)(r.EditorProvider,{postMessage:e=>{typeof window>`u`||window.self!==window.top&&(u.applicationURL.length>0&&window?.postMessage(e,u.applicationURL),u.editorURL.length>0&&window.parent?.postMessage(e,u.editorURL),u.cmsURL.length>0&&window.parent?.postMessage(e,u.cmsURL))},allowedOrigins:[u?.editorURL,u?.cmsURL,u?.applicationURL],configuration:s.default,children:[(0,c.jsx)(d,{}),e]});exports.IntlayerEditorProvider=f;
64
2
  //# sourceMappingURL=IntlayerEditorProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerEditorProvider.cjs","names":["useDictionariesRecordActions","configuration","useEditorEnabled","EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect } from 'preact/hooks';\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 // Load dictionaries dynamically to do not impact the bundle, and send them to the editor\n import('@intlayer/unmerged-dictionaries-entry').then((mod) => {\n const unmergedDictionaries = mod.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\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":";;;;;;;;;;;;;;;AAWA,MAAM,mCAAsD;;;;AAI1D,4DAAuB;;;;AAKvB,qEAA2B;;;;CAK3B,MAAM,EAAE,0BAA0BA,uEAA8B,IAAI,EAAE;AAEtE,mCAAgB;AAEd,SAAO,yCAAyC,MAAM,QAAQ;GAC5D,MAAM,uBAAuB,IAAI,yBAAyB;GAC1D,MAAM,mBAAmB,OAAO,YAC9B,OAAO,OAAO,qBAAqB,CAChC,MAAM,CACN,KAAK,eAAe,CAAC,WAAW,SAAS,WAAW,CAAC,CACzD;AAED,2BAAwB,iBAAiB;IACzC;IACD,EAAE,CAAC;AAEN,QAAO,4EAAK;;AAGd,MAAM,EAAE,WAAWC;AAEnB,MAAM,2BAA8C;CAClD,MAAM,EAAE,YAAYC,sDAAkB;AAEtC,QAAO,UAAU,4CAAC,+BAA6B,GAAG,4EAAK;;AAGzD,MAAa,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,eAAeF;aAEf,4CAAC,uBAAqB,EACrB;GACc"}
1
+ {"version":3,"file":"IntlayerEditorProvider.cjs","names":["useDictionariesRecordActions","configuration","useEditorEnabled","EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect } from 'preact/hooks';\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 // Load dictionaries dynamically to do not impact the bundle, and send them to the editor\n import('@intlayer/unmerged-dictionaries-entry').then((mod) => {\n const unmergedDictionaries = mod.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\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":"scAWA,MAAM,MAAsD,CAI1D,EAAA,uBAAuB,CAKvB,EAAA,2BAA2B,CAK3B,GAAM,CAAE,yBAA0BA,EAAAA,8BAA8B,EAAI,EAAE,CAgBtE,OAdA,EAAA,EAAA,eAAgB,CAEd,OAAO,yCAAyC,KAAM,GAAQ,CAC5D,IAAM,EAAuB,EAAI,yBAAyB,CACpD,EAAmB,OAAO,YAC9B,OAAO,OAAO,EAAqB,CAChC,MAAM,CACN,IAAK,GAAe,CAAC,EAAW,QAAS,EAAW,CAAC,CACzD,CAED,IAAwB,EAAiB,EACzC,EACD,EAAE,CAAC,EAEC,EAAA,EAAA,KAAA,EAAA,SAAA,EAAA,CAAK,EAGR,CAAE,UAAWC,EAAAA,QAEb,MAA8C,CAClD,GAAM,CAAE,WAAYC,EAAAA,kBAAkB,CAEtC,OAAO,GAAU,EAAA,EAAA,KAAC,EAAA,EAAA,CAA6B,EAAG,EAAA,EAAA,KAAA,EAAA,SAAA,EAAA,CAAK,EAG5C,GAEP,CAAE,eAEJ,EAAA,EAAA,MAACC,EAAAA,eAAAA,CACC,YAAc,GAAc,CACtB,OAAO,OAAW,KAEH,OAAO,OAAS,OAAO,MAGtC,EAAO,eAAe,OAAS,GACjC,QAAQ,YACN,EAGA,EAAO,eACR,CAGC,EAAO,UAAU,OAAS,GAC5B,OAAO,QAAQ,YACb,EAGA,EAAO,UACR,CAGC,EAAO,OAAO,OAAS,GACzB,OAAO,QAAQ,YACb,EAGA,EAAO,OACR,GAGL,eAAgB,CACd,GAAQ,UACR,GAAQ,OACR,GAAQ,eACT,CACD,cAAeF,EAAAA,mBAEf,EAAA,EAAA,KAAC,EAAA,EAAA,CAAqB,CACrB,EAAA,EACc"}
@@ -1,4 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_editor_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
3
-
4
- exports.ContentSelectorRenderer = require_editor_ContentSelectorWrapper.ContentSelectorRenderer;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./ContentSelectorWrapper.cjs`);exports.ContentSelectorRenderer=e.ContentSelectorRenderer;
@@ -1,79 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
6
- let _intlayer_editor = require("@intlayer/editor");
7
- let preact_hooks = require("preact/hooks");
8
-
9
- //#region src/editor/useCrossFrameMessageListener.tsx
10
- /**
11
- * useCrossFrameMessageListener
12
- *
13
- * This React hook listens for messages sent via the `postMessage` API and triggers a callback
14
- * whenever a message of the specified type (`key`) is received. It is useful for synchronizing
15
- * state or events across different windows, iframes, or contexts.
16
- *
17
- * @template S - The type of the data payload in the message.
18
- * @param key - A unique identifier for the message type to listen for.
19
- * @param [onEventTriggered] - A callback function triggered when a message
20
- * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state
21
- * with the specified key is received. The callback receives the message data as its argument.
22
- *
23
- * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function
24
- * that allows broadcasting messages with the specified key and data.
25
- */
26
- const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
27
- const { allowedOrigins, postMessage, senderId } = require_editor_CommunicatorContext.useCommunicator();
28
- (0, preact_hooks.useEffect)(() => {
29
- if (onEventTriggered) {
30
- /**
31
- * Message handler to process incoming messages.
32
- *
33
- * - **Message Filtering:** Ensures only messages with the specified `key` are processed.
34
- * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.
35
- *
36
- * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.
37
- */
38
- const handleMessage = (event) => {
39
- const { type, data, senderId: msgSenderId } = event.data;
40
- if (type !== key) return;
41
- if (msgSenderId === senderId) return;
42
- if (typeof allowedOrigins === "undefined" || allowedOrigins?.filter((url) => ![
43
- null,
44
- void 0,
45
- "",
46
- "*"
47
- ].includes(url)).some((url) => (0, _intlayer_editor.compareUrls)(url, event.origin)) || allowedOrigins?.includes("*")) onEventTriggered(data);
48
- };
49
- window.addEventListener("message", handleMessage);
50
- return () => window.removeEventListener("message", handleMessage);
51
- }
52
- }, [
53
- allowedOrigins,
54
- postMessage,
55
- senderId,
56
- revalidator
57
- ]);
58
- /**
59
- * A wrapper function around the `postMessage` function to broadcast messages efficiently.
60
- *
61
- * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.
62
- * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.
63
- *
64
- * @param {S} data - The data payload to include in the message.
65
- * @returns {void}
66
- */
67
- const postMessageWrapper = (data) => {
68
- postMessage({
69
- type: key,
70
- data,
71
- senderId
72
- });
73
- };
74
- return postMessageWrapper;
75
- };
76
-
77
- //#endregion
78
- exports.useCrossFrameMessageListener = useCrossFrameMessageListener;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`);let t=require(`@intlayer/editor`),n=require(`preact/hooks`);const r=(r,i,a)=>{let{allowedOrigins:o,postMessage:s,senderId:c}=e.useCommunicator();return(0,n.useEffect)(()=>{if(i){let e=e=>{let{type:n,data:a,senderId:s}=e.data;n===r&&s!==c&&(o===void 0||o?.filter(e=>![null,void 0,``,`*`].includes(e)).some(n=>(0,t.compareUrls)(n,e.origin))||o?.includes(`*`))&&i(a)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)}},[o,s,c,a]),e=>{s({type:r,data:e,senderId:c})}};exports.useCrossFrameMessageListener=r;
79
2
  //# sourceMappingURL=useCrossFrameMessageListener.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator"],"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,0CAAoB,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,MAAM,sBAA0C,SAAS;AACvD,cAAY;GAAE,MAAM;GAAK;GAAM;GAAU,CAAC;;AAG5C,QAAO"}
1
+ {"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator"],"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":"sOAsBA,MAAa,GACX,EACA,EACA,IACG,CACH,GAAM,CAAE,iBAAgB,cAAa,YAAaA,EAAAA,iBAAiB,CAwDnE,OAtDA,EAAA,EAAA,eAAgB,CACd,GAAI,EAAkB,CASpB,IAAM,EACJ,GACG,CACH,GAAM,CAAE,OAAM,OAAM,SAAU,GAAgB,EAAM,KAGhD,IAAS,GAGT,IAAgB,IAIX,IAAmB,QAC1B,GACI,OAAQ,GAAQ,CAAC,CAAC,KAAM,IAAA,GAAW,GAAI,IAAI,CAAC,SAAS,EAAI,CAAC,CAC3D,KAAM,IAAA,EAAA,EAAA,aAAoB,EAAK,EAAM,OAAO,CAAC,EAChD,GAAgB,SAAS,IAAI,GAG7B,EAAiB,EAAK,EAO1B,OAHA,OAAO,iBAAiB,UAAW,EAAc,KAGpC,OAAO,oBAAoB,UAAW,EAAc,GAElE,CAAC,EAAgB,EAAa,EAAU,EAAY,CAAC,CAWR,GAAS,CACvD,EAAY,CAAE,KAAM,EAAK,OAAM,WAAU,CAAC"}
@@ -1,109 +1,2 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
6
- const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
7
- let preact_hooks = require("preact/hooks");
8
-
9
- //#region src/editor/useCrossFrameState.tsx
10
- const resolveState = (valueOrUpdater, prevState) => typeof valueOrUpdater === "function" ? valueOrUpdater(prevState) : valueOrUpdater;
11
- /**
12
- * Configuration options for `useCrossFrameState`.
13
- * @typedef {Object} CrossFrameStateOptions
14
- * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.
15
- * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.
16
- */
17
- /**
18
- * useCrossFrameState
19
- *
20
- * This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).
21
- * It uses the `postMessage` API to communicate state changes and updates between instances.
22
- *
23
- * @template S - The type of the state.
24
- * @param key - A unique identifier for the state to synchronize.
25
- * @param initialState - The initial state value or a function to compute it lazily.
26
- * @param options - Configuration options to control emitting and receiving messages.
27
- * - `emit` (default: true): Whether to broadcast state changes to other instances.
28
- * - `receive` (default: true): Whether to listen for state updates from other instances.
29
- *
30
- * @returns {[S, CrossFrameStateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.
31
- */
32
- const useCrossFrameState = (key, initialState, options) => {
33
- const { postMessage, senderId } = require_editor_CommunicatorContext.useCommunicator();
34
- const { emit, receive } = options ?? {
35
- emit: true,
36
- receive: true
37
- };
38
- const handleStateChange = (valueOrUpdater, prevState) => {
39
- const resolvedState = resolveState(valueOrUpdater, prevState);
40
- if (emit && typeof postMessage === "function" && typeof resolvedState !== "undefined") postMessage({
41
- type: `${key}/post`,
42
- data: resolvedState,
43
- senderId
44
- });
45
- return resolvedState;
46
- };
47
- const postState = () => {
48
- if (typeof postMessage !== "function") return;
49
- postMessage({
50
- type: `${key}/post`,
51
- data: state,
52
- senderId
53
- });
54
- };
55
- const [state, setState] = (0, preact_hooks.useState)(() => handleStateChange(initialState));
56
- /**
57
- * A wrapper function around the `setState` function to handle messaging efficiently.
58
- *
59
- * This approach has several advantages over using an additional `useEffect`:
60
- * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,
61
- * it prevents the extra render cycle that would be triggered when using `useEffect`.
62
- * - **Consistency:** Ensures the message is emitted immediately when the state is updated,
63
- * avoiding potential delays caused by the asynchronous nature of `useEffect`.
64
- *
65
- * This function keeps the same API as `setState` and is memoized using `useCallback`
66
- * to prevent unnecessary re-renders of dependent components.
67
- *
68
- * @template S - The type of the state.
69
- * @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.
70
- * @returns {void}
71
- */
72
- const setStateWrapper = (valueOrUpdater) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));
73
- /**
74
- * Listen for messages with the specified key and update the state accordingly.
75
- */
76
- require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${key}/post`, receive ? (data) => {
77
- setState(data);
78
- } : void 0);
79
- const onGetMessage = (_, originSenderId) => {
80
- if (!emit) return;
81
- if (typeof postMessage !== "function") return;
82
- if (originSenderId === senderId) return;
83
- if (typeof state === "undefined") return;
84
- postMessage({
85
- type: `${key}/post`,
86
- data: state,
87
- senderId
88
- });
89
- };
90
- /**
91
- * Listen for messages request to get the state content and send it back.
92
- */
93
- require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${key}/get`, emit ? onGetMessage : void 0, state);
94
- (0, preact_hooks.useEffect)(() => {
95
- if (receive && typeof postMessage === "function" && typeof state === "undefined") postMessage({
96
- type: `${key}/get`,
97
- senderId
98
- });
99
- }, []);
100
- return [
101
- state,
102
- setStateWrapper,
103
- postState
104
- ];
105
- };
106
-
107
- //#endregion
108
- exports.useCrossFrameState = useCrossFrameState;
1
+ "use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`),t=require(`./useCrossFrameMessageListener.cjs`);let n=require(`preact/hooks`);const r=(e,t)=>typeof e==`function`?e(t):e,i=(i,a,o)=>{let{postMessage:s,senderId:c}=e.useCommunicator(),{emit:l,receive:u}=o??{emit:!0,receive:!0},d=(e,t)=>{let n=r(e,t);return l&&typeof s==`function`&&n!==void 0&&s({type:`${i}/post`,data:n,senderId:c}),n},f=()=>{typeof s==`function`&&s({type:`${i}/post`,data:p,senderId:c})},[p,m]=(0,n.useState)(()=>d(a));return t.useCrossFrameMessageListener(`${i}/post`,u?e=>{m(e)}:void 0),t.useCrossFrameMessageListener(`${i}/get`,l?(e,t)=>{l&&typeof s==`function`&&t!==c&&p!==void 0&&s({type:`${i}/post`,data:p,senderId:c})}:void 0,p),(0,n.useEffect)(()=>{u&&typeof s==`function`&&p===void 0&&s({type:`${i}/get`,senderId:c})},[]),[p,e=>m(t=>d(e,t)),f]};exports.useCrossFrameState=i;
109
2
  //# sourceMappingURL=useCrossFrameState.cjs.map