preact-intlayer 6.1.6 → 7.0.0-canary.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.
- 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,32 +1,26 @@
|
|
|
1
|
+
//#region src/client/useLoadDynamic.ts
|
|
1
2
|
const createSuspender = (promise) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (status === "pending") throw suspender;
|
|
17
|
-
if (status === "error") throw result;
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
3
|
+
let status = "pending";
|
|
4
|
+
let result;
|
|
5
|
+
const suspender = promise.then((r) => {
|
|
6
|
+
status = "success";
|
|
7
|
+
result = r;
|
|
8
|
+
}, (e) => {
|
|
9
|
+
status = "error";
|
|
10
|
+
result = e;
|
|
11
|
+
});
|
|
12
|
+
return { read() {
|
|
13
|
+
if (status === "pending") throw suspender;
|
|
14
|
+
if (status === "error") throw result;
|
|
15
|
+
return result;
|
|
16
|
+
} };
|
|
21
17
|
};
|
|
22
18
|
const cache = /* @__PURE__ */ new Map();
|
|
23
19
|
const useLoadDynamic = (key, promise) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return cache.get(key).read();
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
useLoadDynamic
|
|
20
|
+
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
|
+
return cache.get(key).read();
|
|
31
22
|
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useLoadDynamic };
|
|
32
26
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"AAEA,MAAM,
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":["status: Status","result: T"],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":";AAEA,MAAM,mBAAsB,YAAwB;CAClD,IAAIA,SAAiB;CACrB,IAAIC;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;AACL,WAAS;AACT,WAAS;KAEV,MAAM;AACL,WAAS;AACT,WAAS;GAEZ;AAED,QAAO,EACL,OAAO;AACL,MAAI,WAAW,UAAW,OAAM;AAChC,MAAI,WAAW,QAAS,OAAM;AAC9B,SAAO;IAEV;;AAGH,MAAM,wBAAQ,IAAI,KAAiD;AAEnE,MAAa,kBAAqB,KAAa,YAA2B;AACxE,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,OAAM,IAAI,KAAK,gBAAgB,QAAQ,CAAC;AAG1C,QAAQ,MAAM,IAAI,IAAI,CAAyC,MAAM"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
5
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
6
|
import configuration from "@intlayer/config/built";
|
|
3
7
|
import { useContext } from "preact/hooks";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// List of the available locales defined in config
|
|
28
|
-
setLocale
|
|
29
|
-
// Function to set the locale
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export {
|
|
33
|
-
useLocale
|
|
8
|
+
|
|
9
|
+
//#region src/client/useLocale.ts
|
|
10
|
+
/**
|
|
11
|
+
* On the client side, hook to get the current locale and all related fields
|
|
12
|
+
*/
|
|
13
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
14
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
15
|
+
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
|
|
16
|
+
const setLocale = (locale$1) => {
|
|
17
|
+
if (!availableLocales?.map(String).includes(locale$1)) {
|
|
18
|
+
console.error(`Locale ${locale$1} is not available`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
setLocaleState(locale$1);
|
|
22
|
+
setLocaleInStorage(locale$1, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
23
|
+
onLocaleChange?.(locale$1);
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
locale,
|
|
27
|
+
defaultLocale,
|
|
28
|
+
availableLocales,
|
|
29
|
+
setLocale
|
|
30
|
+
};
|
|
34
31
|
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useLocale };
|
|
35
35
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":["locale"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9B,eAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,sBAAsB;CAErC,MAAM,aAAa,aAA0B;AAC3C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAASA,SAAO,EAAE;AACnD,WAAQ,MAAM,UAAUA,SAAO,mBAAmB;AAClD;;AAGF,iBAAeA,SAAO;AAEtB,qBACEA,UACA,mBAAmB,0BAA0B,KAC9C;AAED,mBAAiBA,SAAO;;AAG1B,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
5
|
import configuration from "@intlayer/config/built";
|
|
3
6
|
import { useContext } from "preact/hooks";
|
|
4
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/client/useLocaleBase.ts
|
|
5
9
|
const { defaultLocale, locales: availableLocales } = configuration.internationalization;
|
|
10
|
+
/**
|
|
11
|
+
* On the client side, hook to get the current locale and all related fields
|
|
12
|
+
*/
|
|
6
13
|
const useLocaleBase = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// List of the available locales defined in config
|
|
15
|
-
setLocale
|
|
16
|
-
// Function to set the locale
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
useLocaleBase
|
|
14
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
15
|
+
return {
|
|
16
|
+
locale,
|
|
17
|
+
defaultLocale,
|
|
18
|
+
availableLocales,
|
|
19
|
+
setLocale
|
|
20
|
+
};
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { useLocaleBase };
|
|
22
25
|
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;AAMA,MAAM,EAAE,eAAe,SAAS,qBAC9B,cAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,cAAc,WAAW,sBAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LocaleStorage, getLocaleFromStorage, localeStorageOptions, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core";
|
|
2
|
+
import { useMemo } from "preact/hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/client/useLocaleStorage.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get the locale cookie
|
|
7
|
+
*/
|
|
8
|
+
const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use localeInStorage instead
|
|
11
|
+
*
|
|
12
|
+
* Get the locale cookie
|
|
13
|
+
*/
|
|
14
|
+
const localeCookie = localeInStorage;
|
|
15
|
+
/**
|
|
16
|
+
* Set the locale cookie
|
|
17
|
+
*/
|
|
18
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
|
|
19
|
+
...localeStorageOptions,
|
|
20
|
+
isCookieEnabled
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use setLocaleInStorage instead
|
|
24
|
+
*
|
|
25
|
+
* Set the locale cookie
|
|
26
|
+
*/
|
|
27
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Hook that provides the locale storage and a function to set it
|
|
30
|
+
*/
|
|
31
|
+
const useLocaleStorage = (isCookieEnabled) => useMemo(() => LocaleStorage({
|
|
32
|
+
...localeStorageOptions,
|
|
33
|
+
isCookieEnabled
|
|
34
|
+
}), [isCookieEnabled]);
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use useLocaleStorage instead
|
|
37
|
+
*
|
|
38
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
39
|
+
*
|
|
40
|
+
* Hook that provides the locale cookie and a function to set it
|
|
41
|
+
*/
|
|
42
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
43
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
44
|
+
return {
|
|
45
|
+
localeCookie: storage.getLocale(),
|
|
46
|
+
setLocaleCookie: storage.setLocale
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
52
|
+
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorage,\n LocaleStorage,\n localeStorageOptions,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;AAYA,MAAa,kBAAkB,qBAAqB,qBAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,qBAAuB,QAAQ;CAC7B,GAAG;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,cAEI,cAAc;CACZ,GAAG;CACH;CACD,CAAC,EACJ,CAAC,gBAAgB,CAClB;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AACjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
1
2
|
import { getTranslation } from "@intlayer/core";
|
|
2
3
|
import { useContext, useMemo } from "preact/hooks";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/client/useTraduction.ts
|
|
6
|
+
/**
|
|
7
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
8
|
+
*
|
|
9
|
+
* If not locale found, it will return the content related to the default locale.
|
|
10
|
+
*
|
|
11
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const content = useTranslation<string>({
|
|
17
|
+
* en: 'Hello',
|
|
18
|
+
* fr: 'Bonjour',
|
|
19
|
+
* }, 'fr');
|
|
20
|
+
* // 'Bonjour'
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Using TypeScript:
|
|
24
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
25
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
26
|
+
*/
|
|
4
27
|
const useTranslation = (languageContent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
() => getTranslation(languageContent, locale),
|
|
8
|
-
[languageContent, locale]
|
|
9
|
-
);
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
useTranslation
|
|
28
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
29
|
+
return useMemo(() => getTranslation(languageContent, locale), [languageContent, locale]);
|
|
13
30
|
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useTranslation };
|
|
14
34
|
//# sourceMappingURL=useTraduction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation
|
|
1
|
+
{"version":3,"file":"useTraduction.mjs","names":[],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core';\nimport type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBACX,oBACY;CACZ,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,cACC,eAAe,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { createContext } from "preact";
|
|
3
5
|
import configuration from "@intlayer/config/built";
|
|
4
|
-
import {
|
|
5
|
-
createContext
|
|
6
|
-
} from "preact";
|
|
7
6
|
import { useContext, useMemo, useRef } from "preact/hooks";
|
|
8
|
-
import { v4
|
|
7
|
+
import { v4 } from "uuid";
|
|
8
|
+
import { jsx } from "preact/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
//#region src/editor/CommunicatorContext.tsx
|
|
9
11
|
const { editor } = configuration;
|
|
10
12
|
const CommunicatorContext = createContext({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
postMessage: () => null,
|
|
14
|
+
allowedOrigins: [
|
|
15
|
+
editor?.applicationURL,
|
|
16
|
+
editor?.editorURL,
|
|
17
|
+
editor?.cmsURL
|
|
18
|
+
],
|
|
19
|
+
senderId: ""
|
|
18
20
|
});
|
|
19
21
|
const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const senderIdRef = useRef(v4());
|
|
23
|
+
const value = useMemo(() => ({
|
|
24
|
+
postMessage,
|
|
25
|
+
allowedOrigins,
|
|
26
|
+
senderId: senderIdRef.current
|
|
27
|
+
}), [postMessage, allowedOrigins]);
|
|
28
|
+
return /* @__PURE__ */ jsx(CommunicatorContext.Provider, {
|
|
29
|
+
value,
|
|
30
|
+
children
|
|
31
|
+
});
|
|
27
32
|
};
|
|
28
33
|
const useCommunicator = () => useContext(CommunicatorContext);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { CommunicatorProvider, useCommunicator };
|
|
33
37
|
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.mjs","names":["CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n>","uuid"],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration;\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins] // senderIdRef.current is stable\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,EAAE,WAAW;AAEnB,MAAM,sBAAsB,cAA0C;CACpE,mBAAmB;CACnB,gBAAgB;EACd,QAAQ;EACR,QAAQ;EACR,QAAQ;EACT;CACD,UAAU;CACX,CAAC;AAQF,MAAaA,wBAER,EAAE,UAAU,gBAAgB,kBAAkB;CAEjD,MAAM,cAAc,OAAOC,IAAM,CAAC;CAElC,MAAM,QAAQ,eACL;EAAE;EAAa;EAAgB,UAAU,YAAY;EAAS,GACrE,CAAC,aAAa,eAAe,CAC9B;AAED,QACE,oBAAC,oBAAoB;EAAgB;EAClC;GAC4B;;AAInC,MAAa,wBAAwB,WAAW,oBAAoB"}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useContext
|
|
7
|
-
} from "preact/compat";
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
8
4
|
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
20
|
-
|
|
5
|
+
import { MessageKey } from "@intlayer/editor";
|
|
6
|
+
import { createContext, useContext } from "preact/compat";
|
|
7
|
+
import { jsx } from "preact/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
//#region src/editor/ConfigurationContext.tsx
|
|
10
|
+
const ConfigurationStatesContext = createContext(void 0);
|
|
11
|
+
const useConfigurationState = () => useCrossFrameState(MessageKey.INTLAYER_CONFIGURATION, void 0, {
|
|
12
|
+
receive: false,
|
|
13
|
+
emit: true
|
|
14
|
+
});
|
|
15
|
+
const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext.Provider, {
|
|
16
|
+
value: configuration,
|
|
17
|
+
children
|
|
18
|
+
});
|
|
21
19
|
const useConfiguration = () => useContext(ConfigurationStatesContext);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
useConfigurationState
|
|
26
|
-
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ConfigurationProvider, useConfiguration, useConfigurationState };
|
|
27
23
|
//# sourceMappingURL=ConfigurationContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":["ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n>"],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":";;;;;;;;;AAYA,MAAM,6BAA6B,cACjC,OACD;AAED,MAAa,8BACX,mBACE,WAAW,wBACX,QACA;CACE,SAAS;CACT,MAAM;CACP,CACF;AAMH,MAAaA,yBAER,EAAE,UAAU,oBACf,oBAAC,2BAA2B;CAAS,OAAO;CACzC;EACmC;AAGxC,MAAa,yBAAyB,WAAW,2BAA2B"}
|
|
@@ -1,76 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { MessageKey } from "@intlayer/editor";
|
|
5
|
-
import {
|
|
6
|
-
useCallback,
|
|
7
|
-
useMemo
|
|
8
|
-
} from "preact/compat";
|
|
9
|
-
import { useIntlayerContext } from "../client/index.mjs";
|
|
10
|
-
import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
11
4
|
import { useCommunicator } from "./CommunicatorContext.mjs";
|
|
12
5
|
import { useEditorEnabled } from "./EditorEnabledContext.mjs";
|
|
13
6
|
import { useFocusDictionary } from "./FocusDictionaryContext.mjs";
|
|
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
|
-
return /* @__PURE__ */ jsx(
|
|
52
|
-
ContentSelector,
|
|
53
|
-
{
|
|
54
|
-
onPress: handleSelect,
|
|
55
|
-
onHover: handleHover,
|
|
56
|
-
onUnhover: handleUnhover,
|
|
57
|
-
isSelecting: isSelected,
|
|
58
|
-
children
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
const ContentSelectorRenderer = ({
|
|
63
|
-
children,
|
|
64
|
-
...props
|
|
65
|
-
}) => {
|
|
66
|
-
const { enabled } = useEditorEnabled();
|
|
67
|
-
const { disableEditor } = useIntlayerContext();
|
|
68
|
-
if (enabled && !disableEditor) {
|
|
69
|
-
return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, { ...props, children });
|
|
70
|
-
}
|
|
71
|
-
return children;
|
|
7
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
8
|
+
import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
9
|
+
import { isSameKeyPath } from "@intlayer/core";
|
|
10
|
+
import { MessageKey } from "@intlayer/editor";
|
|
11
|
+
import { useCallback, useMemo } from "preact/compat";
|
|
12
|
+
import { jsx } from "preact/jsx-runtime";
|
|
13
|
+
|
|
14
|
+
//#region src/editor/ContentSelectorWrapper.tsx
|
|
15
|
+
const ContentSelectorWrapperContent = ({ children, dictionaryKey, keyPath }) => {
|
|
16
|
+
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
17
|
+
const { postMessage, senderId } = useCommunicator();
|
|
18
|
+
return /* @__PURE__ */ jsx(ContentSelector, {
|
|
19
|
+
onPress: useCallback(() => setFocusedContent({
|
|
20
|
+
dictionaryKey,
|
|
21
|
+
keyPath
|
|
22
|
+
}), [dictionaryKey, keyPath]),
|
|
23
|
+
onHover: useCallback(() => postMessage({
|
|
24
|
+
type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
25
|
+
data: {
|
|
26
|
+
dictionaryKey,
|
|
27
|
+
keyPath
|
|
28
|
+
},
|
|
29
|
+
senderId
|
|
30
|
+
}), [dictionaryKey, keyPath]),
|
|
31
|
+
onUnhover: useCallback(() => postMessage({
|
|
32
|
+
type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
33
|
+
data: null,
|
|
34
|
+
senderId
|
|
35
|
+
}), [senderId]),
|
|
36
|
+
isSelecting: useMemo(() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false, [
|
|
37
|
+
focusedContent,
|
|
38
|
+
keyPath,
|
|
39
|
+
dictionaryKey
|
|
40
|
+
]),
|
|
41
|
+
children
|
|
42
|
+
});
|
|
72
43
|
};
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
const ContentSelectorRenderer = ({ children,...props }) => {
|
|
45
|
+
const { enabled } = useEditorEnabled();
|
|
46
|
+
const { disableEditor } = useIntlayerContext();
|
|
47
|
+
if (enabled && !disableEditor) return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, {
|
|
48
|
+
...props,
|
|
49
|
+
children
|
|
50
|
+
});
|
|
51
|
+
return children;
|
|
75
52
|
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ContentSelectorRenderer };
|
|
76
56
|
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.mjs","names":["ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps>","ContentSelectorRenderer: FC<ContentSelectorWrapperProps>"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { isSameKeyPath, type NodeProps } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath,\n },\n senderId,\n }),\n [dictionaryKey, keyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAMA,iCAAkE,EACtE,UACA,eACA,cACI;CACJ,MAAM,EAAE,gBAAgB,sBAAsB,oBAAoB;CAClE,MAAM,EAAE,aAAa,aAAa,iBAAiB;AA2CnD,QACE,oBAAC;EACC,SA3CiB,kBAEjB,kBAAkB;GAChB;GACA;GACD,CAAC,EACJ,CAAC,eAAe,QAAQ,CACzB;EAqCG,SAnCgB,kBAEhB,YAAY;GACV,MAAM,GAAG,WAAW,iCAAiC;GACrD,MAAM;IACJ;IACA;IACD;GACD;GACD,CAAC,EACJ,CAAC,eAAe,QAAQ,CACzB;EAyBG,WAvBkB,kBAElB,YAAY;GACV,MAAM,GAAG,WAAW,iCAAiC;GACrD,MAAM;GACN;GACD,CAAC,EACJ,CAAC,SAAS,CACX;EAgBG,aAde,eAEd,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,EAAE,EAAE,QAAQ,KACvD,OACF;GAAC;GAAgB;GAAS;GAAc,CACzC;EASI;GACe;;AAItB,MAAaC,2BAA4D,EACvE,SACA,GAAG,YACC;CACJ,MAAM,EAAE,YAAY,kBAAkB;CACtC,MAAM,EAAE,kBAAkB,oBAAoB;AAE9C,KAAI,WAAW,CAAC,cACd,QACE,oBAAC;EAA8B,GAAI;EAChC;GAC6B;AAIpC,QAAO"}
|