preact-intlayer 6.1.6 → 7.0.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerNode.cjs +15 -45
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +98 -130
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/client/IntlayerProvider.cjs +67 -95
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +17 -50
- package/dist/cjs/client/format/useCompact.cjs +29 -39
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +43 -39
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +45 -36
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +40 -39
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +41 -39
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +37 -39
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +37 -39
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +36 -39
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +29 -69
- package/dist/cjs/client/t.cjs +21 -34
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +16 -36
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +26 -36
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +23 -52
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +22 -42
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +26 -36
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +21 -50
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +36 -67
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +25 -53
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +60 -0
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/client/useTraduction.cjs +34 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +40 -62
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +26 -47
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +58 -94
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +47 -73
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +160 -211
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +34 -59
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +62 -66
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs +51 -75
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +45 -94
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +3 -23
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +73 -50
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +106 -73
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +67 -66
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +27 -59
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +24 -47
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +15 -40
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +15 -36
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +30 -62
- package/dist/cjs/markdown/MarkdownProvider.cjs +19 -39
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +39 -80
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +7 -25
- package/dist/cjs/plugins.cjs +97 -119
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +34 -59
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +13 -25
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -105
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +51 -54
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +2 -11
- package/dist/esm/client/format/useCompact.mjs +24 -13
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +38 -13
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +40 -10
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +35 -13
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +36 -13
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +32 -13
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +32 -13
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +31 -13
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +5 -32
- package/dist/esm/client/t.mjs +16 -8
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +14 -10
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +23 -11
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +18 -16
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +17 -15
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +23 -11
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +20 -26
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +31 -31
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +19 -16
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +52 -0
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/client/useTraduction.mjs +29 -9
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +28 -24
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +20 -24
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +50 -70
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +37 -47
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +146 -187
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +23 -33
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +57 -54
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs +42 -49
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +37 -55
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +3 -2
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +68 -24
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +102 -47
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +60 -40
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +23 -33
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +18 -20
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +13 -22
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +13 -18
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +13 -39
- package/dist/esm/markdown/MarkdownProvider.mjs +14 -16
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +34 -57
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +4 -3
- package/dist/esm/plugins.mjs +86 -92
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +31 -34
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +19 -12
- package/dist/types/IntlayerNode.d.ts.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts +12 -9
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts +22 -16
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/format/index.d.ts +9 -9
- package/dist/types/client/format/useCompact.d.ts +8 -2
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts +8 -2
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useDate.d.ts +7 -2
- package/dist/types/client/format/useDate.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts +8 -2
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts +8 -2
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts +8 -2
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts +9 -3
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts +8 -2
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +11 -12
- package/dist/types/client/t.d.ts +7 -3
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +10 -5
- package/dist/types/client/useContent.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +9 -3
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +7 -3
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +9 -3
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +8 -5
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +4 -1
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +16 -8
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +10 -5
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +45 -0
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/client/useTraduction.d.ts +7 -2
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/editor/CommunicatorContext.d.ts +15 -11
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/editor/ConfigurationContext.d.ts +12 -7
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +8 -4
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/DictionariesRecordContext.d.ts +15 -12
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts +32 -29
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/editor/EditorEnabledContext.d.ts +14 -9
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.d.ts +9 -5
- package/dist/types/editor/EditorProvider.d.ts.map +1 -1
- package/dist/types/editor/FocusDictionaryContext.d.ts +18 -15
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts +7 -3
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +2 -2
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +7 -2
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/editor/useCrossFrameState.d.ts +11 -7
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/editor/useCrossURLPathState.d.ts +8 -3
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentRenderer.d.ts +16 -10
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts +5 -2
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +8 -4
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +8 -4
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +8 -5
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +13 -11
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +3 -3
- package/dist/types/plugins.d.ts +33 -27
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/preactElement/renderPreactElement.d.ts +7 -3
- package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -1
- package/package.json +40 -46
- package/LICENSE +0 -202
- package/dist/cjs/client/format/index.cjs.map +0 -1
- package/dist/cjs/client/getBrowserLocale.cjs +0 -173
- package/dist/cjs/client/getBrowserLocale.cjs.map +0 -1
- package/dist/cjs/client/index.cjs.map +0 -1
- package/dist/cjs/client/useLocaleCookie.cjs +0 -60
- package/dist/cjs/client/useLocaleCookie.cjs.map +0 -1
- package/dist/cjs/editor/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/markdown/index.cjs.map +0 -1
- package/dist/esm/client/format/index.mjs.map +0 -1
- package/dist/esm/client/getBrowserLocale.mjs +0 -138
- package/dist/esm/client/getBrowserLocale.mjs.map +0 -1
- package/dist/esm/client/index.mjs.map +0 -1
- package/dist/esm/client/useLocaleCookie.mjs +0 -24
- package/dist/esm/client/useLocaleCookie.mjs.map +0 -1
- package/dist/esm/editor/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/markdown/index.mjs.map +0 -1
- package/dist/types/client/format/index.d.ts.map +0 -1
- package/dist/types/client/getBrowserLocale.d.ts +0 -25
- package/dist/types/client/getBrowserLocale.d.ts.map +0 -1
- package/dist/types/client/index.d.ts.map +0 -1
- package/dist/types/client/useLocaleCookie.d.ts +0 -17
- package/dist/types/client/useLocaleCookie.d.ts.map +0 -1
- package/dist/types/editor/index.d.ts.map +0 -1
- package/dist/types/markdown/index.d.ts.map +0 -1
|
@@ -1,53 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
3
4
|
import { useCommunicator } from "./CommunicatorContext.mjs";
|
|
4
5
|
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
6
|
+
import { useEffect, useState } from "preact/hooks";
|
|
7
|
+
|
|
8
|
+
//#region src/editor/useCrossFrameState.tsx
|
|
5
9
|
const resolveState = (valueOrUpdater, prevState) => typeof valueOrUpdater === "function" ? valueOrUpdater(prevState) : valueOrUpdater;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for `useCrossFrameState`.
|
|
12
|
+
* @typedef {Object} CrossFrameStateOptions
|
|
13
|
+
* @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.
|
|
14
|
+
* @property {boolean} [receive=true] - Whether to listen for state updates from other instances.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* useCrossFrameState
|
|
18
|
+
*
|
|
19
|
+
* This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).
|
|
20
|
+
* It uses the `postMessage` API to communicate state changes and updates between instances.
|
|
21
|
+
*
|
|
22
|
+
* @template S - The type of the state.
|
|
23
|
+
* @param key - A unique identifier for the state to synchronize.
|
|
24
|
+
* @param initialState - The initial state value or a function to compute it lazily.
|
|
25
|
+
* @param options - Configuration options to control emitting and receiving messages.
|
|
26
|
+
* - `emit` (default: true): Whether to broadcast state changes to other instances.
|
|
27
|
+
* - `receive` (default: true): Whether to listen for state updates from other instances.
|
|
28
|
+
*
|
|
29
|
+
* @returns {[S, StateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.
|
|
30
|
+
*/
|
|
6
31
|
const useCrossFrameState = (key, initialState, options) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
const { postMessage, senderId } = useCommunicator();
|
|
33
|
+
const { emit, receive } = options ?? {
|
|
34
|
+
emit: true,
|
|
35
|
+
receive: true
|
|
36
|
+
};
|
|
37
|
+
const handleStateChange = (valueOrUpdater, prevState) => {
|
|
38
|
+
const resolvedState = resolveState(valueOrUpdater, prevState);
|
|
39
|
+
if (emit && typeof postMessage === "function" && typeof resolvedState !== "undefined") postMessage({
|
|
40
|
+
type: `${key}/post`,
|
|
41
|
+
data: resolvedState,
|
|
42
|
+
senderId
|
|
43
|
+
});
|
|
44
|
+
return resolvedState;
|
|
45
|
+
};
|
|
46
|
+
const postState = () => {
|
|
47
|
+
if (typeof postMessage !== "function") return;
|
|
48
|
+
postMessage({
|
|
49
|
+
type: `${key}/post`,
|
|
50
|
+
data: state,
|
|
51
|
+
senderId
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const [state, setState] = useState(() => handleStateChange(initialState));
|
|
55
|
+
/**
|
|
56
|
+
* A wrapper function around the `setState` function to handle messaging efficiently.
|
|
57
|
+
*
|
|
58
|
+
* This approach has several advantages over using an additional `useEffect`:
|
|
59
|
+
* - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,
|
|
60
|
+
* it prevents the extra render cycle that would be triggered when using `useEffect`.
|
|
61
|
+
* - **Consistency:** Ensures the message is emitted immediately when the state is updated,
|
|
62
|
+
* avoiding potential delays caused by the asynchronous nature of `useEffect`.
|
|
63
|
+
*
|
|
64
|
+
* This function keeps the same API as `setState` and is memoized using `useCallback`
|
|
65
|
+
* to prevent unnecessary re-renders of dependent components.
|
|
66
|
+
*
|
|
67
|
+
* @template S - The type of the state.
|
|
68
|
+
* @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
const setStateWrapper = (valueOrUpdater) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));
|
|
72
|
+
/**
|
|
73
|
+
* Listen for messages with the specified key and update the state accordingly.
|
|
74
|
+
*/
|
|
75
|
+
useCrossFrameMessageListener(`${key}/post`, receive ? (data) => {
|
|
76
|
+
setState(data);
|
|
77
|
+
} : void 0);
|
|
78
|
+
const onGetMessage = (_, originSenderId) => {
|
|
79
|
+
if (!emit) return;
|
|
80
|
+
if (typeof postMessage !== "function") return;
|
|
81
|
+
if (originSenderId === senderId) return;
|
|
82
|
+
if (typeof state === "undefined") return;
|
|
83
|
+
postMessage({
|
|
84
|
+
type: `${key}/post`,
|
|
85
|
+
data: state,
|
|
86
|
+
senderId
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Listen for messages request to get the state content and send it back.
|
|
91
|
+
*/
|
|
92
|
+
useCrossFrameMessageListener(`${key}/get`, emit ? onGetMessage : void 0, state);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (receive && typeof postMessage === "function" && typeof state === "undefined") postMessage({
|
|
95
|
+
type: `${key}/get`,
|
|
96
|
+
senderId
|
|
97
|
+
});
|
|
98
|
+
}, []);
|
|
99
|
+
return [
|
|
100
|
+
state,
|
|
101
|
+
setStateWrapper,
|
|
102
|
+
postState
|
|
103
|
+
];
|
|
52
104
|
};
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { useCrossFrameState };
|
|
53
108
|
//# sourceMappingURL=useCrossFrameState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.mjs","names":["resolvedState: S","setStateWrapper: Dispatch<SetStateAction<S>>"],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport type { SetStateAction } from 'preact/compat';\nimport {\n type Dispatch,\n type StateUpdater,\n useEffect,\n useState,\n} from 'preact/hooks';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nconst resolveState = <S,>(\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevState?: S) => S)(prevState)\n : (valueOrUpdater as S);\n\n/**\n * Configuration options for `useCrossFrameState`.\n * @typedef {Object} CrossFrameStateOptions\n * @property {boolean} [emit=true] - Whether to broadcast state changes to other instances.\n * @property {boolean} [receive=true] - Whether to listen for state updates from other instances.\n */\n\n/**\n * useCrossFrameState\n *\n * This Preact hook synchronizes state across multiple instances (e.g., different iframes or windows).\n * It uses the `postMessage` API to communicate state changes and updates between instances.\n *\n * @template S - The type of the state.\n * @param key - A unique identifier for the state to synchronize.\n * @param initialState - The initial state value or a function to compute it lazily.\n * @param options - Configuration options to control emitting and receiving messages.\n * - `emit` (default: true): Whether to broadcast state changes to other instances.\n * - `receive` (default: true): Whether to listen for state updates from other instances.\n *\n * @returns {[S, StateUpdater<S>, typeof postState]} An array containing the current state and a setter function, and a function to manually post the state.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<S>>, typeof postState] => {\n const { postMessage, senderId } = useCommunicator();\n\n const { emit, receive } = options ?? { emit: true, receive: true };\n\n const handleStateChange = (\n valueOrUpdater?: S | ((prevState: S) => S),\n prevState?: S\n ): S => {\n // Initialize state from the provided initial value, if defined\n const resolvedState: S = resolveState(valueOrUpdater, prevState);\n\n // Emit the initial state if `emit` is enabled and initial state is defined\n if (\n emit &&\n typeof postMessage === 'function' &&\n typeof resolvedState !== 'undefined'\n ) {\n postMessage({ type: `${key}/post`, data: resolvedState, senderId });\n }\n\n return resolvedState;\n };\n\n const postState = () => {\n if (typeof postMessage !== 'function') return;\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n const [state, setState] = useState<S>(() => handleStateChange(initialState));\n\n /**\n * A wrapper function around the `setState` function to handle messaging efficiently.\n *\n * This approach has several advantages over using an additional `useEffect`:\n * - **Avoid Redundant Re-renders:** By emitting the message directly within the `setState` logic,\n * it prevents the extra render cycle that would be triggered when using `useEffect`.\n * - **Consistency:** Ensures the message is emitted immediately when the state is updated,\n * avoiding potential delays caused by the asynchronous nature of `useEffect`.\n *\n * This function keeps the same API as `setState` and is memoized using `useCallback`\n * to prevent unnecessary re-renders of dependent components.\n *\n * @template S - The type of the state.\n * @param {S | ((prevState: S) => S)} valueOrUpdater - The new state or a function to produce it.\n * @returns {void}\n */\n const setStateWrapper: Dispatch<SetStateAction<S>> = (\n valueOrUpdater: S | ((prevState: S) => S)\n ) => setState((prevState) => handleStateChange(valueOrUpdater, prevState));\n\n /**\n * Listen for messages with the specified key and update the state accordingly.\n */\n useCrossFrameMessageListener<S>(\n `${key}/post`,\n // Only activate the state listener if the `receive` option is true\n receive\n ? (data) => {\n setState(data);\n }\n : undefined\n );\n\n const onGetMessage = (_: unknown, originSenderId?: string) => {\n if (!emit) return;\n if (typeof postMessage !== 'function') return;\n if (originSenderId === senderId) return;\n if (typeof state === 'undefined') return;\n\n postMessage({ type: `${key}/post`, data: state, senderId });\n };\n\n /**\n * Listen for messages request to get the state content and send it back.\n */\n useCrossFrameMessageListener<S>(\n `${key}/get`,\n // Only activate the state listener if the `emit` option is true\n emit ? onGetMessage : undefined,\n state // Revalidate the listener if the state changes\n );\n\n useEffect(() => {\n // If the component is mounted and the hook in receive mode,\n // Request the state from the other instance\n if (\n receive &&\n typeof postMessage === 'function' &&\n typeof state === 'undefined'\n ) {\n postMessage({ type: `${key}/get`, senderId });\n }\n }, []);\n\n // Return the useState state and setter\n return [state, setStateWrapper, postState];\n};\n"],"mappings":";;;;;;;;AAkBA,MAAM,gBACJ,gBACA,cAEA,OAAO,mBAAmB,aACrB,eAAwC,UAAU,GAClD;;;;;;;;;;;;;;;;;;;;;;AAwBP,MAAa,sBACX,KACA,cACA,YACuD;CACvD,MAAM,EAAE,aAAa,aAAa,iBAAiB;CAEnD,MAAM,EAAE,MAAM,YAAY,WAAW;EAAE,MAAM;EAAM,SAAS;EAAM;CAElE,MAAM,qBACJ,gBACA,cACM;EAEN,MAAMA,gBAAmB,aAAa,gBAAgB,UAAU;AAGhE,MACE,QACA,OAAO,gBAAgB,cACvB,OAAO,kBAAkB,YAEzB,aAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAe;GAAU,CAAC;AAGrE,SAAO;;CAGT,MAAM,kBAAkB;AACtB,MAAI,OAAO,gBAAgB,WAAY;AACvC,cAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAO;GAAU,CAAC;;CAG7D,MAAM,CAAC,OAAO,YAAY,eAAkB,kBAAkB,aAAa,CAAC;;;;;;;;;;;;;;;;;CAkB5E,MAAMC,mBACJ,mBACG,UAAU,cAAc,kBAAkB,gBAAgB,UAAU,CAAC;;;;AAK1E,8BACE,GAAG,IAAI,QAEP,WACK,SAAS;AACR,WAAS,KAAK;KAEhB,OACL;CAED,MAAM,gBAAgB,GAAY,mBAA4B;AAC5D,MAAI,CAAC,KAAM;AACX,MAAI,OAAO,gBAAgB,WAAY;AACvC,MAAI,mBAAmB,SAAU;AACjC,MAAI,OAAO,UAAU,YAAa;AAElC,cAAY;GAAE,MAAM,GAAG,IAAI;GAAQ,MAAM;GAAO;GAAU,CAAC;;;;;AAM7D,8BACE,GAAG,IAAI,OAEP,OAAO,eAAe,QACtB,MACD;AAED,iBAAgB;AAGd,MACE,WACA,OAAO,gBAAgB,cACvB,OAAO,UAAU,YAEjB,aAAY;GAAE,MAAM,GAAG,IAAI;GAAO;GAAU,CAAC;IAE9C,EAAE,CAAC;AAGN,QAAO;EAAC;EAAO;EAAiB;EAAU"}
|
|
@@ -1,46 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
2
5
|
import { MessageKey } from "@intlayer/editor";
|
|
3
6
|
import { useEffect } from "preact/hooks";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./useCrossFrameState.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/editor/useCrossURLPathState.tsx
|
|
7
9
|
const useCrossURLPathState = (initialState, options) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);
|
|
8
10
|
const useCrossURLPathSetter = (initialState) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
const states = useCrossURLPathState(initialState, {
|
|
12
|
+
emit: true,
|
|
13
|
+
receive: false
|
|
14
|
+
});
|
|
15
|
+
const [_state, setState] = states;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
/**
|
|
18
|
+
* 1) Monkey patch history methods (pushState, replaceState)
|
|
19
|
+
* to dispatch a custom event whenever they are called.
|
|
20
|
+
*/
|
|
21
|
+
const originalPushState = history.pushState;
|
|
22
|
+
const originalReplaceState = history.replaceState;
|
|
23
|
+
const injectLocationChangeEvent = (method) => function(...args) {
|
|
24
|
+
method.apply(this, args);
|
|
25
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
26
|
+
};
|
|
27
|
+
history.pushState = injectLocationChangeEvent(originalPushState);
|
|
28
|
+
history.replaceState = injectLocationChangeEvent(originalReplaceState);
|
|
29
|
+
/**
|
|
30
|
+
* 2) The callback to update our state whenever the URL changes.
|
|
31
|
+
*/
|
|
32
|
+
const updateURLState = () => {
|
|
33
|
+
setState(window.location.pathname);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 3) Attach event listeners for locationchange, popstate, hashchange.
|
|
37
|
+
* - 'locationchange' is our custom event triggered by push/replaceState overrides.
|
|
38
|
+
* - 'popstate' is fired on back/forward navigation.
|
|
39
|
+
* - 'hashchange' is for URL hash (#) changes.
|
|
40
|
+
* - 'load' is when new page is loaded
|
|
41
|
+
*/
|
|
42
|
+
window.addEventListener("locationchange", updateURLState);
|
|
43
|
+
window.addEventListener("popstate", updateURLState);
|
|
44
|
+
window.addEventListener("hashchange", updateURLState);
|
|
45
|
+
window.addEventListener("load", updateURLState);
|
|
46
|
+
updateURLState();
|
|
47
|
+
/**
|
|
48
|
+
* 4) Cleanup when the component unmounts:
|
|
49
|
+
* - Remove event listeners.
|
|
50
|
+
* - Restore original pushState & replaceState to avoid side effects.
|
|
51
|
+
*/
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener("locationchange", updateURLState);
|
|
54
|
+
window.removeEventListener("popstate", updateURLState);
|
|
55
|
+
window.removeEventListener("hashchange", updateURLState);
|
|
56
|
+
window.removeEventListener("load", updateURLState);
|
|
57
|
+
history.pushState = originalPushState;
|
|
58
|
+
history.replaceState = originalReplaceState;
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return states;
|
|
45
62
|
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { useCrossURLPathSetter, useCrossURLPathState };
|
|
46
66
|
//# sourceMappingURL=useCrossURLPathState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport {\n
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.mjs","names":[],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n const states = useCrossURLPathState(initialState, {\n emit: true,\n receive: false,\n });\n const [_state, setState] = states;\n\n useEffect(() => {\n /**\n * 1) Monkey patch history methods (pushState, replaceState)\n * to dispatch a custom event whenever they are called.\n */\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n\n const injectLocationChangeEvent = (method: (...args: any[]) => void) =>\n function (this: typeof history, ...args: [any, string, string?]) {\n method.apply(this, args);\n window.dispatchEvent(new Event('locationchange'));\n };\n\n history.pushState = injectLocationChangeEvent(originalPushState);\n history.replaceState = injectLocationChangeEvent(originalReplaceState);\n\n /**\n * 2) The callback to update our state whenever the URL changes.\n */\n const updateURLState = () => {\n setState(window.location.pathname);\n };\n\n /**\n * 3) Attach event listeners for locationchange, popstate, hashchange.\n * - 'locationchange' is our custom event triggered by push/replaceState overrides.\n * - 'popstate' is fired on back/forward navigation.\n * - 'hashchange' is for URL hash (#) changes.\n * - 'load' is when new page is loaded\n */\n window.addEventListener('locationchange', updateURLState);\n window.addEventListener('popstate', updateURLState);\n window.addEventListener('hashchange', updateURLState);\n window.addEventListener('load', updateURLState);\n\n // Initialize our state immediately on mount\n updateURLState();\n\n /**\n * 4) Cleanup when the component unmounts:\n * - Remove event listeners.\n * - Restore original pushState & replaceState to avoid side effects.\n */\n return () => {\n window.removeEventListener('locationchange', updateURLState);\n window.removeEventListener('popstate', updateURLState);\n window.removeEventListener('hashchange', updateURLState);\n window.removeEventListener('load', updateURLState);\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n };\n }, []);\n\n return states;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,wBACX,cACA,YACG,mBAAmB,WAAW,qBAAqB,cAAc,QAAQ;AAE9E,MAAa,yBAAyB,iBAA0B;CAC9D,MAAM,SAAS,qBAAqB,cAAc;EAChD,MAAM;EACN,SAAS;EACV,CAAC;CACF,MAAM,CAAC,QAAQ,YAAY;AAE3B,iBAAgB;;;;;EAKd,MAAM,oBAAoB,QAAQ;EAClC,MAAM,uBAAuB,QAAQ;EAErC,MAAM,6BAA6B,WACjC,SAAgC,GAAG,MAA8B;AAC/D,UAAO,MAAM,MAAM,KAAK;AACxB,UAAO,cAAc,IAAI,MAAM,iBAAiB,CAAC;;AAGrD,UAAQ,YAAY,0BAA0B,kBAAkB;AAChE,UAAQ,eAAe,0BAA0B,qBAAqB;;;;EAKtE,MAAM,uBAAuB;AAC3B,YAAS,OAAO,SAAS,SAAS;;;;;;;;;AAUpC,SAAO,iBAAiB,kBAAkB,eAAe;AACzD,SAAO,iBAAiB,YAAY,eAAe;AACnD,SAAO,iBAAiB,cAAc,eAAe;AACrD,SAAO,iBAAiB,QAAQ,eAAe;AAG/C,kBAAgB;;;;;;AAOhB,eAAa;AACX,UAAO,oBAAoB,kBAAkB,eAAe;AAC5D,UAAO,oBAAoB,YAAY,eAAe;AACtD,UAAO,oBAAoB,cAAc,eAAe;AACxD,UAAO,oBAAoB,QAAQ,eAAe;AAClD,WAAQ,YAAY;AACpB,WAAQ,eAAe;;IAExB,EAAE,CAAC;AAEN,QAAO"}
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
3
4
|
import { useEditedContentActions } from "./EditedContentContext.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const editedValue = editedContentContext.getEditedContentValue(
|
|
12
|
-
dictionaryKey,
|
|
13
|
-
keyPath
|
|
14
|
-
);
|
|
15
|
-
const value = editedValue ?? children;
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
return children;
|
|
5
|
+
import { getContent } from "@intlayer/core";
|
|
6
|
+
|
|
7
|
+
//#region src/editor/useEditedContentRenderer.tsx
|
|
8
|
+
const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => {
|
|
9
|
+
const editedContentContext = useEditedContentActions();
|
|
10
|
+
if (editedContentContext) return editedContentContext.getEditedContentValue(dictionaryKey, keyPath) ?? children;
|
|
11
|
+
return children;
|
|
19
12
|
};
|
|
20
13
|
const EditedContentRenderer = (props) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return content;
|
|
33
|
-
};
|
|
34
|
-
export {
|
|
35
|
-
EditedContentRenderer,
|
|
36
|
-
useEditedContentRenderer
|
|
14
|
+
const content = useEditedContentRenderer(props);
|
|
15
|
+
if (typeof content === "object") {
|
|
16
|
+
const transformedEditedContent = getContent(content, props, props.locale);
|
|
17
|
+
if (typeof transformedEditedContent !== "string") {
|
|
18
|
+
console.error(`Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`);
|
|
19
|
+
return props.children;
|
|
20
|
+
}
|
|
21
|
+
return transformedEditedContent;
|
|
22
|
+
}
|
|
23
|
+
return content;
|
|
37
24
|
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { EditedContentRenderer, useEditedContentRenderer };
|
|
38
28
|
//# sourceMappingURL=useEditedContentRenderer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useEditedContentRenderer.mjs","names":["EditedContentRenderer: FC<EditedContentRendererProps>"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getContent } from '@intlayer/core';\nimport type { Dictionary, KeyPath, Locale } from '@intlayer/types';\nimport type { FC } from 'preact/compat';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: Dictionary['key'];\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FC<EditedContentRendererProps> = (\n props\n) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(content, props, props.locale);\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":";;;;;;;AAcA,MAAa,4BAA4B,EACvC,eACA,SACA,eACgC;CAChC,MAAM,uBAAuB,yBAAyB;AAEtD,KAAI,qBAQF,QAPoB,qBAAqB,sBACvC,eACA,QACD,IAE4B;AAK/B,QAAO;;AAGT,MAAaA,yBACX,UACG;CACH,MAAM,UAAU,yBAAyB,MAAM;AAE/C,KAAI,OAAO,YAAY,UAAU;EAC/B,MAAM,2BAA2B,WAAW,SAAS,OAAO,MAAM,OAAO;AAEzE,MAAI,OAAO,6BAA6B,UAAU;AAChD,WAAQ,MACN,kDAAkD,OAAO,yBAAyB,2BAA2B,KAAK,UAAU,yBAAyB,GACtJ;AAED,UAAO,MAAM;;AAGf,SAAO;;AAGT,QAAO"}
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
2
5
|
import { MessageKey, mergeIframeClick } from "@intlayer/editor";
|
|
3
6
|
import { useEffect } from "preact/hooks";
|
|
4
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/editor/useIframeClickInterceptor.tsx
|
|
5
9
|
const useIframeClickInterceptor = () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return () => window.removeEventListener("mousedown", handlePostMessageEvent);
|
|
15
|
-
}, [postMessage]);
|
|
16
|
-
};
|
|
17
|
-
const useIframeClickMerger = () => useCrossFrameMessageListener(
|
|
18
|
-
MessageKey.INTLAYER_IFRAME_CLICKED,
|
|
19
|
-
mergeIframeClick
|
|
20
|
-
);
|
|
21
|
-
export {
|
|
22
|
-
useIframeClickInterceptor,
|
|
23
|
-
useIframeClickMerger
|
|
10
|
+
const postMessage = useCrossFrameMessageListener(MessageKey.INTLAYER_IFRAME_CLICKED);
|
|
11
|
+
const handlePostMessageEvent = () => {
|
|
12
|
+
postMessage();
|
|
13
|
+
};
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
window.addEventListener("mousedown", handlePostMessageEvent);
|
|
16
|
+
return () => window.removeEventListener("mousedown", handlePostMessageEvent);
|
|
17
|
+
}, [postMessage]);
|
|
24
18
|
};
|
|
19
|
+
const useIframeClickMerger = () => useCrossFrameMessageListener(MessageKey.INTLAYER_IFRAME_CLICKED, mergeIframeClick);
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { useIframeClickInterceptor, useIframeClickMerger };
|
|
25
23
|
//# sourceMappingURL=useIframeClickInterceptor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n const postMessage = useCrossFrameMessageListener<undefined>(\n MessageKey.INTLAYER_IFRAME_CLICKED\n );\n const handlePostMessageEvent: EventListener = () => {\n postMessage();\n };\n\n useEffect(() => {\n window.addEventListener('mousedown', handlePostMessageEvent);\n\n return () =>\n window.removeEventListener('mousedown', handlePostMessageEvent);\n }, [postMessage]);\n};\n\nexport const useIframeClickMerger = () =>\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIframeClickInterceptor.mjs","names":["handlePostMessageEvent: EventListener"],"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n const postMessage = useCrossFrameMessageListener<undefined>(\n MessageKey.INTLAYER_IFRAME_CLICKED\n );\n const handlePostMessageEvent: EventListener = () => {\n postMessage();\n };\n\n useEffect(() => {\n window.addEventListener('mousedown', handlePostMessageEvent);\n\n return () =>\n window.removeEventListener('mousedown', handlePostMessageEvent);\n }, [postMessage]);\n};\n\nexport const useIframeClickMerger = () =>\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n"],"mappings":";;;;;;;;AAMA,MAAa,kCAAkC;CAC7C,MAAM,cAAc,6BAClB,WAAW,wBACZ;CACD,MAAMA,+BAA8C;AAClD,eAAa;;AAGf,iBAAgB;AACd,SAAO,iBAAiB,aAAa,uBAAuB;AAE5D,eACE,OAAO,oBAAoB,aAAa,uBAAuB;IAChE,CAAC,YAAY,CAAC;;AAGnB,MAAa,6BACX,6BACE,WAAW,yBACX,iBACD"}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
intlayerNodePlugins,
|
|
6
|
-
markdownPlugin,
|
|
7
|
-
preactNodePlugins
|
|
8
|
-
} from "./plugins.mjs";
|
|
1
|
+
import { intlayerNodePlugins, markdownPlugin, preactNodePlugins } from "./plugins.mjs";
|
|
2
|
+
import { getDictionary as getDictionary$1 } from "@intlayer/core";
|
|
3
|
+
|
|
4
|
+
//#region src/getDictionary.ts
|
|
9
5
|
const getDictionary = (dictionary, locale, additionalPlugins) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return getDictionaryCore(
|
|
17
|
-
dictionary,
|
|
18
|
-
locale,
|
|
19
|
-
plugins
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
getDictionary
|
|
6
|
+
return getDictionary$1(dictionary, locale, [
|
|
7
|
+
intlayerNodePlugins,
|
|
8
|
+
preactNodePlugins,
|
|
9
|
+
markdownPlugin,
|
|
10
|
+
...additionalPlugins ?? []
|
|
11
|
+
]);
|
|
24
12
|
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getDictionary };
|
|
25
16
|
//# sourceMappingURL=getDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import {\n getDictionary as getDictionaryCore,\n type Plugins,\n} from '@intlayer/core';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n): DeepTransformContent<T['content']> => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getDictionaryCore<T, L>(dictionary, locale as L, plugins);\n};\n"],"mappings":";;;;AAgBA,MAAa,iBAIX,YACA,QACA,sBACuC;AASvC,QAAOA,gBAAwB,YAAY,QARhB;EACzB;EACA;EACA;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAG+D"}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
intlayerNodePlugins,
|
|
6
|
-
markdownPlugin,
|
|
7
|
-
preactNodePlugins
|
|
8
|
-
} from "./plugins.mjs";
|
|
1
|
+
import { intlayerNodePlugins, markdownPlugin, preactNodePlugins } from "./plugins.mjs";
|
|
2
|
+
import { getIntlayer as getIntlayer$1 } from "@intlayer/core";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayer.ts
|
|
9
5
|
const getIntlayer = (key, locale, additionalPlugins) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return getIntlayerCore(key, locale, plugins);
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
getIntlayer
|
|
6
|
+
return getIntlayer$1(key, locale, [
|
|
7
|
+
intlayerNodePlugins,
|
|
8
|
+
preactNodePlugins,
|
|
9
|
+
markdownPlugin,
|
|
10
|
+
...additionalPlugins ?? []
|
|
11
|
+
]);
|
|
20
12
|
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getIntlayer };
|
|
21
16
|
//# sourceMappingURL=getIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore, type Plugins } from '@intlayer/core';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n intlayerNodePlugins,\n markdownPlugin,\n preactNodePlugins,\n} from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n additionalPlugins?: Plugins[]\n) => {\n const plugins: Plugins[] = [\n intlayerNodePlugins,\n preactNodePlugins,\n markdownPlugin,\n ...(additionalPlugins ?? []),\n ];\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayerCore<T, L>(key, locale, plugins) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n};\n"],"mappings":";;;;AAcA,MAAa,eAIX,KACA,QACA,sBACG;AASH,QAAOA,cAAsB,KAAK,QARP;EACzB;EACA;EACA;EACA,GAAI,qBAAqB,EAAE;EAC5B,CAGiD"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
useLoadDynamic,
|
|
15
|
-
useLocale,
|
|
16
|
-
useLocaleBase,
|
|
17
|
-
useLocaleCookie
|
|
18
|
-
} from "./client/index.mjs";
|
|
19
|
-
import { MarkdownProvider } from "./markdown/index.mjs";
|
|
20
|
-
export {
|
|
21
|
-
IntlayerClientContext,
|
|
22
|
-
IntlayerProvider,
|
|
23
|
-
IntlayerProviderContent,
|
|
24
|
-
MarkdownProvider,
|
|
25
|
-
getBrowserLocale,
|
|
26
|
-
localeCookie,
|
|
27
|
-
setLocaleCookie,
|
|
28
|
-
t,
|
|
29
|
-
useDictionary,
|
|
30
|
-
useDictionaryAsync,
|
|
31
|
-
useDictionaryDynamic,
|
|
32
|
-
useIntlayer,
|
|
33
|
-
useIntlayerContext,
|
|
34
|
-
useLoadDynamic,
|
|
35
|
-
useLocale,
|
|
36
|
-
useLocaleBase,
|
|
37
|
-
useLocaleCookie
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import { localeCookie, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./client/useLocaleStorage.mjs";
|
|
2
|
+
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./client/IntlayerProvider.mjs";
|
|
3
|
+
import { t } from "./client/t.mjs";
|
|
4
|
+
import { useDictionary } from "./client/useDictionary.mjs";
|
|
5
|
+
import { useDictionaryAsync } from "./client/useDictionaryAsync.mjs";
|
|
6
|
+
import { useLoadDynamic } from "./client/useLoadDynamic.mjs";
|
|
7
|
+
import { useDictionaryDynamic } from "./client/useDictionaryDynamic.mjs";
|
|
8
|
+
import { useIntlayer } from "./client/useIntlayer.mjs";
|
|
9
|
+
import { useLocale } from "./client/useLocale.mjs";
|
|
10
|
+
import { useLocaleBase } from "./client/useLocaleBase.mjs";
|
|
11
|
+
import { MarkdownProvider } from "./markdown/MarkdownProvider.mjs";
|
|
12
|
+
|
|
13
|
+
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, MarkdownProvider, localeCookie, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage };
|