angular-intlayer 6.1.6 → 7.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/UI/ContentSelector.component.cjs +94 -121
- package/dist/cjs/UI/ContentSelector.component.cjs.map +1 -1
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/client/index.cjs +19 -35
- package/dist/cjs/client/installIntlayer.cjs +39 -68
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +13 -36
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +23 -48
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +24 -52
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +16 -36
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +26 -42
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +35 -67
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +61 -0
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.component.cjs +41 -63
- package/dist/cjs/editor/ContentSelectorWrapper.component.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentRenderer.component.cjs +44 -75
- package/dist/cjs/editor/EditedContentRenderer.component.cjs.map +1 -1
- package/dist/cjs/editor/EditorSelectorRenderer.component.cjs +25 -45
- package/dist/cjs/editor/EditorSelectorRenderer.component.cjs.map +1 -1
- package/dist/cjs/editor/communicator.cjs +55 -73
- package/dist/cjs/editor/communicator.cjs.map +1 -1
- package/dist/cjs/editor/configuration.cjs +21 -54
- package/dist/cjs/editor/configuration.cjs.map +1 -1
- package/dist/cjs/editor/createSharedComposable.cjs +46 -63
- package/dist/cjs/editor/createSharedComposable.cjs.map +1 -1
- package/dist/cjs/editor/dictionariesRecord.cjs +47 -77
- package/dist/cjs/editor/dictionariesRecord.cjs.map +1 -1
- package/dist/cjs/editor/editedContent.cjs +58 -71
- package/dist/cjs/editor/editedContent.cjs.map +1 -1
- package/dist/cjs/editor/editorEnabled.cjs +45 -70
- package/dist/cjs/editor/editorEnabled.cjs.map +1 -1
- package/dist/cjs/editor/editorLocale.cjs +21 -45
- package/dist/cjs/editor/editorLocale.cjs.map +1 -1
- package/dist/cjs/editor/focusDictionary.cjs +58 -74
- package/dist/cjs/editor/focusDictionary.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +9 -38
- package/dist/cjs/editor/installIntlayerEditor.cjs +46 -64
- package/dist/cjs/editor/installIntlayerEditor.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +63 -72
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +108 -88
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +64 -69
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +25 -54
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +22 -44
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +38 -59
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +14 -39
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +14 -35
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +32 -31
- package/dist/cjs/markdown/index.cjs +6 -23
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +33 -60
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +77 -108
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +16 -56
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/cjs/webpack/index.cjs +3 -23
- package/dist/cjs/webpack/mergeConfig.cjs +33 -68
- package/dist/cjs/webpack/mergeConfig.cjs.map +1 -1
- package/dist/esm/UI/ContentSelector.component.mjs +89 -104
- package/dist/esm/UI/ContentSelector.component.mjs.map +1 -1
- package/dist/esm/client/index.mjs +9 -8
- package/dist/esm/client/installIntlayer.mjs +29 -27
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +10 -11
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +18 -12
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +18 -15
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +12 -10
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +23 -17
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +30 -31
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +54 -0
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.component.mjs +32 -34
- package/dist/esm/editor/ContentSelectorWrapper.component.mjs.map +1 -1
- package/dist/esm/editor/EditedContentRenderer.component.mjs +38 -49
- package/dist/esm/editor/EditedContentRenderer.component.mjs.map +1 -1
- package/dist/esm/editor/EditorSelectorRenderer.component.mjs +19 -18
- package/dist/esm/editor/EditorSelectorRenderer.component.mjs.map +1 -1
- package/dist/esm/editor/communicator.mjs +48 -35
- package/dist/esm/editor/communicator.mjs.map +1 -1
- package/dist/esm/editor/configuration.mjs +15 -18
- package/dist/esm/editor/configuration.mjs.map +1 -1
- package/dist/esm/editor/createSharedComposable.mjs +42 -37
- package/dist/esm/editor/createSharedComposable.mjs.map +1 -1
- package/dist/esm/editor/dictionariesRecord.mjs +38 -38
- package/dist/esm/editor/dictionariesRecord.mjs.map +1 -1
- package/dist/esm/editor/editedContent.mjs +49 -42
- package/dist/esm/editor/editedContent.mjs.map +1 -1
- package/dist/esm/editor/editorEnabled.mjs +37 -41
- package/dist/esm/editor/editorEnabled.mjs.map +1 -1
- package/dist/esm/editor/editorLocale.mjs +15 -18
- package/dist/esm/editor/editorLocale.mjs.map +1 -1
- package/dist/esm/editor/focusDictionary.mjs +50 -45
- package/dist/esm/editor/focusDictionary.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +3 -7
- package/dist/esm/editor/installIntlayerEditor.mjs +40 -26
- package/dist/esm/editor/installIntlayerEditor.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +58 -46
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +104 -62
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +57 -41
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +21 -33
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +16 -14
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +30 -30
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +12 -20
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +12 -16
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +13 -6
- package/dist/esm/markdown/index.mjs +3 -2
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +27 -32
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/plugins.mjs +70 -83
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs +15 -32
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/esm/webpack/index.mjs +3 -2
- package/dist/esm/webpack/mergeConfig.mjs +25 -31
- package/dist/esm/webpack/mergeConfig.mjs.map +1 -1
- package/dist/types/UI/ContentSelector.component.d.ts +32 -30
- package/dist/types/UI/ContentSelector.component.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +8 -8
- package/dist/types/client/installIntlayer.d.ts +15 -9
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +7 -4
- 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 +9 -7
- 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 +17 -8
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +49 -0
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.component.d.ts +18 -12
- package/dist/types/editor/ContentSelectorWrapper.component.d.ts.map +1 -1
- package/dist/types/editor/EditedContentRenderer.component.d.ts +20 -16
- package/dist/types/editor/EditedContentRenderer.component.d.ts.map +1 -1
- package/dist/types/editor/EditorSelectorRenderer.component.d.ts +11 -6
- package/dist/types/editor/EditorSelectorRenderer.component.d.ts.map +1 -1
- package/dist/types/editor/communicator.d.ts +14 -9
- package/dist/types/editor/communicator.d.ts.map +1 -1
- package/dist/types/editor/configuration.d.ts +4 -1
- package/dist/types/editor/configuration.d.ts.map +1 -1
- package/dist/types/editor/createSharedComposable.d.ts +6 -4
- package/dist/types/editor/createSharedComposable.d.ts.map +1 -1
- package/dist/types/editor/dictionariesRecord.d.ts +13 -10
- package/dist/types/editor/dictionariesRecord.d.ts.map +1 -1
- package/dist/types/editor/editedContent.d.ts +13 -10
- package/dist/types/editor/editedContent.d.ts.map +1 -1
- package/dist/types/editor/editorEnabled.d.ts +12 -8
- package/dist/types/editor/editorEnabled.d.ts.map +1 -1
- package/dist/types/editor/editorLocale.d.ts +6 -2
- package/dist/types/editor/editorLocale.d.ts.map +1 -1
- package/dist/types/editor/focusDictionary.d.ts +16 -13
- package/dist/types/editor/focusDictionary.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +5 -5
- package/dist/types/editor/installIntlayerEditor.d.ts +7 -2
- package/dist/types/editor/installIntlayerEditor.d.ts.map +1 -1
- 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 +12 -8
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/editor/useCrossURLPathState.d.ts +9 -3
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentRenderer.d.ts +15 -11
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
- package/dist/types/editor/useEditor.d.ts +4 -1
- package/dist/types/editor/useEditor.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 +16 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +2 -2
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +15 -12
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +29 -23
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/renderIntlayerNode.d.ts +16 -10
- package/dist/types/renderIntlayerNode.d.ts.map +1 -1
- package/dist/types/webpack/index.d.ts +2 -2
- package/dist/types/webpack/mergeConfig.d.ts +5 -2
- package/dist/types/webpack/mergeConfig.d.ts.map +1 -1
- package/package.json +43 -49
- package/LICENSE +0 -202
- 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/cjs/webpack/index.cjs.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/esm/webpack/index.mjs.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
- package/dist/types/webpack/index.d.ts.map +0 -1
|
@@ -1,80 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var focusDictionary_exports = {};
|
|
20
|
-
__export(focusDictionary_exports, {
|
|
21
|
-
createFocusDictionaryClient: () => createFocusDictionaryClient,
|
|
22
|
-
installFocusDictionary: () => installFocusDictionary,
|
|
23
|
-
useFocusDictionary: () => useFocusDictionary
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(focusDictionary_exports);
|
|
26
|
-
var import_core = require("@angular/core");
|
|
27
|
-
var import_editor = require("@intlayer/editor");
|
|
28
|
-
var import_createSharedComposable = require('./createSharedComposable.cjs');
|
|
29
|
-
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_editor_createSharedComposable = require('./createSharedComposable.cjs');
|
|
3
|
+
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
4
|
+
let __angular_core = require("@angular/core");
|
|
5
|
+
__angular_core = require_rolldown_runtime.__toESM(__angular_core);
|
|
6
|
+
let __intlayer_editor = require("@intlayer/editor");
|
|
7
|
+
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
8
|
+
|
|
9
|
+
//#region src/editor/focusDictionary.ts
|
|
10
|
+
/**
|
|
11
|
+
* Singleton instance
|
|
12
|
+
*/
|
|
30
13
|
let instance = null;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a focus dictionary client
|
|
16
|
+
*/
|
|
31
17
|
const createFocusDictionaryClient = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
if (instance) return instance;
|
|
19
|
+
const focusedContentSignal = (0, __angular_core.signal)(null);
|
|
20
|
+
const setFocusedContent = (focussedContent) => {
|
|
21
|
+
focusedContentSignal.set(focussedContent);
|
|
22
|
+
};
|
|
23
|
+
const setFocusedContentKeyPath = (keyPath) => {
|
|
24
|
+
const current = focusedContentSignal();
|
|
25
|
+
if (!current) return;
|
|
26
|
+
setFocusedContent({
|
|
27
|
+
...current,
|
|
28
|
+
keyPath
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
instance = {
|
|
32
|
+
focusedContent: focusedContentSignal.asReadonly(),
|
|
33
|
+
setFocusedContent,
|
|
34
|
+
setFocusedContentKeyPath
|
|
35
|
+
};
|
|
36
|
+
return instance;
|
|
48
37
|
};
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Helper to install the focus dictionary into the injector
|
|
40
|
+
*/
|
|
41
|
+
const installFocusDictionary = (_injector) => {
|
|
42
|
+
createFocusDictionaryClient();
|
|
51
43
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
(0, import_core.effect)(() => {
|
|
67
|
-
const newValue = focusedContent();
|
|
68
|
-
if (JSON.stringify(newValue) !== JSON.stringify(client.focusedContent())) {
|
|
69
|
-
client.setFocusedContent(newValue ?? null);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return client;
|
|
73
|
-
});
|
|
74
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
-
0 && (module.exports = {
|
|
76
|
-
createFocusDictionaryClient,
|
|
77
|
-
installFocusDictionary,
|
|
78
|
-
useFocusDictionary
|
|
44
|
+
/** consumer */
|
|
45
|
+
const useFocusDictionary = require_editor_createSharedComposable.createSharedComposable(() => {
|
|
46
|
+
const client = createFocusDictionaryClient();
|
|
47
|
+
const [focusedContent, setFocusedContent] = require_editor_useCrossFrameState.useCrossFrameState(__intlayer_editor.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED);
|
|
48
|
+
if (!client) throw new Error("FocusDictionary state not found");
|
|
49
|
+
(0, __angular_core.effect)(() => {
|
|
50
|
+
const newValue = client.focusedContent();
|
|
51
|
+
if (JSON.stringify(newValue) !== JSON.stringify(focusedContent())) setFocusedContent(newValue);
|
|
52
|
+
});
|
|
53
|
+
(0, __angular_core.effect)(() => {
|
|
54
|
+
const newValue = focusedContent();
|
|
55
|
+
if (JSON.stringify(newValue) !== JSON.stringify(client.focusedContent())) client.setFocusedContent(newValue ?? null);
|
|
56
|
+
});
|
|
57
|
+
return client;
|
|
79
58
|
});
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.createFocusDictionaryClient = createFocusDictionaryClient;
|
|
62
|
+
exports.installFocusDictionary = installFocusDictionary;
|
|
63
|
+
exports.useFocusDictionary = useFocusDictionary;
|
|
80
64
|
//# sourceMappingURL=focusDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/focusDictionary.ts"],"sourcesContent":["import { effect, Injector,
|
|
1
|
+
{"version":3,"file":"focusDictionary.cjs","names":["instance: FocusDictionaryClient | null","createSharedComposable","useCrossFrameState","MessageKey"],"sources":["../../../src/editor/focusDictionary.ts"],"sourcesContent":["import { effect, type Injector, type Signal, signal } from '@angular/core';\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types';\nimport { createSharedComposable } from './createSharedComposable';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: string;\n};\n\ntype FocusDictionaryClient = {\n focusedContent: Signal<FileContent | null>;\n setFocusedContent: (focussedContent: FileContent | null) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\n/**\n * Singleton instance\n */\nlet instance: FocusDictionaryClient | null = null;\n\n/**\n * Creates a focus dictionary client\n */\nexport const createFocusDictionaryClient = () => {\n if (instance) return instance;\n\n const focusedContentSignal = signal<FileContent | null>(null);\n\n const setFocusedContent = (focussedContent: FileContent | null) => {\n focusedContentSignal.set(focussedContent);\n };\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n const current = focusedContentSignal();\n if (!current) return;\n setFocusedContent({ ...current, keyPath });\n };\n\n instance = {\n focusedContent: focusedContentSignal.asReadonly(),\n setFocusedContent,\n setFocusedContentKeyPath,\n } as FocusDictionaryClient;\n\n return instance;\n};\n\n/**\n * Helper to install the focus dictionary into the injector\n */\nexport const installFocusDictionary = (_injector: Injector) => {\n const _client = createFocusDictionaryClient();\n\n // Angular doesn't have a direct equivalent to Vue's app.provide\n // The client is stored as a singleton and accessed via createFocusDictionaryClient\n};\n\n/** consumer */\nexport const useFocusDictionary = createSharedComposable(() => {\n const client = createFocusDictionaryClient();\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED\n );\n\n if (!client) {\n throw new Error('FocusDictionary state not found');\n }\n\n // Use Angular effects instead of Vue watchers\n // Watch local (client) and update cross-frame\n effect(() => {\n const newValue = client.focusedContent();\n if (JSON.stringify(newValue) !== JSON.stringify(focusedContent())) {\n setFocusedContent(newValue);\n }\n });\n\n // Watch cross-frame and update local\n effect(() => {\n const newValue = focusedContent();\n if (JSON.stringify(newValue) !== JSON.stringify(client.focusedContent())) {\n client.setFocusedContent(newValue ?? null);\n }\n });\n\n return client;\n});\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAIA,WAAyC;;;;AAK7C,MAAa,oCAAoC;AAC/C,KAAI,SAAU,QAAO;CAErB,MAAM,kDAAkD,KAAK;CAE7D,MAAM,qBAAqB,oBAAwC;AACjE,uBAAqB,IAAI,gBAAgB;;CAG3C,MAAM,4BAA4B,YAAuB;EACvD,MAAM,UAAU,sBAAsB;AACtC,MAAI,CAAC,QAAS;AACd,oBAAkB;GAAE,GAAG;GAAS;GAAS,CAAC;;AAG5C,YAAW;EACT,gBAAgB,qBAAqB,YAAY;EACjD;EACA;EACD;AAED,QAAO;;;;;AAMT,MAAa,0BAA0B,cAAwB;AAC7C,8BAA6B;;;AAO/C,MAAa,qBAAqBC,mEAA6B;CAC7D,MAAM,SAAS,6BAA6B;CAC5C,MAAM,CAAC,gBAAgB,qBACrBC,qDACEC,6BAAW,iCACZ;AAEH,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,kCAAkC;AAKpD,kCAAa;EACX,MAAM,WAAW,OAAO,gBAAgB;AACxC,MAAI,KAAK,UAAU,SAAS,KAAK,KAAK,UAAU,gBAAgB,CAAC,CAC/D,mBAAkB,SAAS;GAE7B;AAGF,kCAAa;EACX,MAAM,WAAW,gBAAgB;AACjC,MAAI,KAAK,UAAU,SAAS,KAAK,KAAK,UAAU,OAAO,gBAAgB,CAAC,CACtE,QAAO,kBAAkB,YAAY,KAAK;GAE5C;AAEF,QAAO;EACP"}
|
|
@@ -1,38 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var editor_exports = {};
|
|
21
|
-
__export(editor_exports, {
|
|
22
|
-
ContentSelectorWrapperComponent: () => import_ContentSelectorWrapper.ContentSelectorWrapperComponent,
|
|
23
|
-
EditedContentRendererComponent: () => import_EditedContentRenderer.EditedContentRendererComponent,
|
|
24
|
-
EditorSelectorRendererComponent: () => import_EditorSelectorRenderer.EditorSelectorRendererComponent
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(editor_exports);
|
|
27
|
-
var import_ContentSelectorWrapper = require('./ContentSelectorWrapper.component.cjs');
|
|
28
|
-
var import_EditedContentRenderer = require('./EditedContentRenderer.component.cjs');
|
|
29
|
-
var import_EditorSelectorRenderer = require('./EditorSelectorRenderer.component.cjs');
|
|
30
|
-
__reExport(editor_exports, require('./installIntlayerEditor.cjs'), module.exports);
|
|
31
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
-
0 && (module.exports = {
|
|
33
|
-
ContentSelectorWrapperComponent,
|
|
34
|
-
EditedContentRendererComponent,
|
|
35
|
-
EditorSelectorRendererComponent,
|
|
36
|
-
...require('./installIntlayerEditor.cjs')
|
|
37
|
-
});
|
|
38
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
const require_editor_ContentSelectorWrapper_component = require('./ContentSelectorWrapper.component.cjs');
|
|
2
|
+
const require_editor_EditedContentRenderer_component = require('./EditedContentRenderer.component.cjs');
|
|
3
|
+
const require_editor_EditorSelectorRenderer_component = require('./EditorSelectorRenderer.component.cjs');
|
|
4
|
+
const require_editor_installIntlayerEditor = require('./installIntlayerEditor.cjs');
|
|
5
|
+
|
|
6
|
+
exports.ContentSelectorWrapperComponent = require_editor_ContentSelectorWrapper_component.ContentSelectorWrapperComponent;
|
|
7
|
+
exports.EditedContentRendererComponent = require_editor_EditedContentRenderer_component.EditedContentRendererComponent;
|
|
8
|
+
exports.EditorSelectorRendererComponent = require_editor_EditorSelectorRenderer_component.EditorSelectorRendererComponent;
|
|
9
|
+
exports.installIntlayerEditor = require_editor_installIntlayerEditor.installIntlayerEditor;
|
|
@@ -1,70 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var installIntlayerEditor_exports = {};
|
|
30
|
-
__export(installIntlayerEditor_exports, {
|
|
31
|
-
installIntlayerEditor: () => installIntlayerEditor
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(installIntlayerEditor_exports);
|
|
34
|
-
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var import_communicator = require('./communicator.cjs');
|
|
36
|
-
var import_dictionariesRecord = require('./dictionariesRecord.cjs');
|
|
37
|
-
var import_editedContent = require('./editedContent.cjs');
|
|
38
|
-
var import_editorEnabled = require('./editorEnabled.cjs');
|
|
39
|
-
var import_focusDictionary = require('./focusDictionary.cjs');
|
|
40
|
-
const { editor } = import_built.default;
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_editor_communicator = require('./communicator.cjs');
|
|
3
|
+
const require_editor_editorEnabled = require('./editorEnabled.cjs');
|
|
4
|
+
const require_editor_focusDictionary = require('./focusDictionary.cjs');
|
|
5
|
+
const require_editor_dictionariesRecord = require('./dictionariesRecord.cjs');
|
|
6
|
+
const require_editor_editedContent = require('./editedContent.cjs');
|
|
7
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
9
|
+
|
|
10
|
+
//#region src/editor/installIntlayerEditor.ts
|
|
11
|
+
const { editor } = __intlayer_config_built.default;
|
|
41
12
|
const { applicationURL, editorURL, cmsURL } = editor ?? {};
|
|
42
13
|
const postMessage = (data) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
if (editor.editorURL.length > 0) {
|
|
50
|
-
window.parent.postMessage(data, editor.editorURL);
|
|
51
|
-
}
|
|
52
|
-
if (editor.cmsURL.length > 0) {
|
|
53
|
-
window.parent.postMessage(data, editor.cmsURL);
|
|
54
|
-
}
|
|
14
|
+
if (typeof window === "undefined") return;
|
|
15
|
+
if (!(window.self !== window.top)) return;
|
|
16
|
+
if (editor.applicationURL.length > 0) window.postMessage(data, editor.applicationURL);
|
|
17
|
+
if (editor.editorURL.length > 0) window.parent.postMessage(data, editor.editorURL);
|
|
18
|
+
if (editor.cmsURL.length > 0) window.parent.postMessage(data, editor.cmsURL);
|
|
55
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Angular-side replacement for the former <IntlayerEditorProvider> React component.
|
|
22
|
+
*
|
|
23
|
+
* Call **once** in your Angular application's bootstrap function or main module:
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { bootstrapApplication } from '@angular/platform-browser';
|
|
27
|
+
* import { AppComponent } from './app/app.component';
|
|
28
|
+
* import { installIntlayerEditor } from 'angular-intlayer';
|
|
29
|
+
*
|
|
30
|
+
* bootstrapApplication(AppComponent).then(appRef => {
|
|
31
|
+
* installIntlayerEditor(appRef.injector);
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
56
35
|
const installIntlayerEditor = (injector) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
require_editor_communicator.installCommunicator(injector, {
|
|
37
|
+
postMessage,
|
|
38
|
+
allowedOrigins: [
|
|
39
|
+
applicationURL,
|
|
40
|
+
editorURL,
|
|
41
|
+
cmsURL
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
require_editor_editorEnabled.installEditorEnabled(injector);
|
|
45
|
+
require_editor_dictionariesRecord.installDictionariesRecord(injector);
|
|
46
|
+
require_editor_editedContent.installEditedContent(injector);
|
|
47
|
+
require_editor_focusDictionary.installFocusDictionary(injector);
|
|
65
48
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.installIntlayerEditor = installIntlayerEditor;
|
|
70
52
|
//# sourceMappingURL=installIntlayerEditor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/installIntlayerEditor.ts"],"sourcesContent":["import { Injector } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport { installCommunicator } from './communicator';\nimport { installDictionariesRecord } from './dictionariesRecord';\nimport { installEditedContent } from './editedContent';\nimport { installEditorEnabled } from './editorEnabled';\nimport { installFocusDictionary } from './focusDictionary';\n\nconst { editor } = configuration;\nconst { applicationURL, editorURL, cmsURL } = editor ?? {};\n\nconst postMessage = (data: any) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n\n if (!isInIframe) return;\n\n if (editor.applicationURL.length > 0) {\n window.postMessage(data, editor.applicationURL);\n }\n\n if (editor.editorURL.length > 0) {\n window.parent.postMessage(data, editor.editorURL);\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent.postMessage(data, editor.cmsURL);\n }\n};\n\n/**\n * Angular-side replacement for the former <IntlayerEditorProvider> React component.\n *\n * Call **once** in your Angular application's bootstrap function or main module:\n *\n * ```typescript\n * import { bootstrapApplication } from '@angular/platform-browser';\n * import { AppComponent } from './app/app.component';\n * import { installIntlayerEditor } from 'angular-intlayer';\n *\n * bootstrapApplication(AppComponent).then(appRef => {\n * installIntlayerEditor(appRef.injector);\n * });\n * ```\n */\nexport const installIntlayerEditor = (injector: Injector): void => {\n /* ---------------------------------------------------------------------\n * 1. Base providers – always on\n * -------------------------------------------------------------------*/\n\n installCommunicator(injector, {\n postMessage,\n allowedOrigins: [applicationURL, editorURL, cmsURL] as string[],\n });\n installEditorEnabled(injector);\n installDictionariesRecord(injector);\n installEditedContent(injector);\n installFocusDictionary(injector);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"installIntlayerEditor.cjs","names":["configuration"],"sources":["../../../src/editor/installIntlayerEditor.ts"],"sourcesContent":["import type { Injector } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport { installCommunicator } from './communicator';\nimport { installDictionariesRecord } from './dictionariesRecord';\nimport { installEditedContent } from './editedContent';\nimport { installEditorEnabled } from './editorEnabled';\nimport { installFocusDictionary } from './focusDictionary';\n\nconst { editor } = configuration;\nconst { applicationURL, editorURL, cmsURL } = editor ?? {};\n\nconst postMessage = (data: any) => {\n if (typeof window === 'undefined') return;\n\n const isInIframe = window.self !== window.top;\n\n if (!isInIframe) return;\n\n if (editor.applicationURL.length > 0) {\n window.postMessage(data, editor.applicationURL);\n }\n\n if (editor.editorURL.length > 0) {\n window.parent.postMessage(data, editor.editorURL);\n }\n\n if (editor.cmsURL.length > 0) {\n window.parent.postMessage(data, editor.cmsURL);\n }\n};\n\n/**\n * Angular-side replacement for the former <IntlayerEditorProvider> React component.\n *\n * Call **once** in your Angular application's bootstrap function or main module:\n *\n * ```typescript\n * import { bootstrapApplication } from '@angular/platform-browser';\n * import { AppComponent } from './app/app.component';\n * import { installIntlayerEditor } from 'angular-intlayer';\n *\n * bootstrapApplication(AppComponent).then(appRef => {\n * installIntlayerEditor(appRef.injector);\n * });\n * ```\n */\nexport const installIntlayerEditor = (injector: Injector): void => {\n /* ---------------------------------------------------------------------\n * 1. Base providers – always on\n * -------------------------------------------------------------------*/\n\n installCommunicator(injector, {\n postMessage,\n allowedOrigins: [applicationURL, editorURL, cmsURL] as string[],\n });\n installEditorEnabled(injector);\n installDictionariesRecord(injector);\n installEditedContent(injector);\n installFocusDictionary(injector);\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAM,EAAE,WAAWA;AACnB,MAAM,EAAE,gBAAgB,WAAW,WAAW,UAAU,EAAE;AAE1D,MAAM,eAAe,SAAc;AACjC,KAAI,OAAO,WAAW,YAAa;AAInC,KAAI,EAFe,OAAO,SAAS,OAAO,KAEzB;AAEjB,KAAI,OAAO,eAAe,SAAS,EACjC,QAAO,YAAY,MAAM,OAAO,eAAe;AAGjD,KAAI,OAAO,UAAU,SAAS,EAC5B,QAAO,OAAO,YAAY,MAAM,OAAO,UAAU;AAGnD,KAAI,OAAO,OAAO,SAAS,EACzB,QAAO,OAAO,YAAY,MAAM,OAAO,OAAO;;;;;;;;;;;;;;;;;AAmBlD,MAAa,yBAAyB,aAA6B;AAKjE,iDAAoB,UAAU;EAC5B;EACA,gBAAgB;GAAC;GAAgB;GAAW;GAAO;EACpD,CAAC;AACF,mDAAqB,SAAS;AAC9B,6DAA0B,SAAS;AACnC,mDAAqB,SAAS;AAC9B,uDAAuB,SAAS"}
|
|
@@ -1,83 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var useCrossFrameMessageListener_exports = {};
|
|
21
|
-
__export(useCrossFrameMessageListener_exports, {
|
|
22
|
-
useCrossFrameMessageListener: () => useCrossFrameMessageListener
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(useCrossFrameMessageListener_exports);
|
|
25
|
-
var import_core = require("@angular/core");
|
|
26
|
-
var import_editor = require("@intlayer/editor");
|
|
27
|
-
var import_communicator = require('./communicator.cjs');
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_editor_communicator = require('./communicator.cjs');
|
|
6
|
+
let __angular_core = require("@angular/core");
|
|
7
|
+
__angular_core = require_rolldown_runtime.__toESM(__angular_core);
|
|
8
|
+
let __intlayer_editor = require("@intlayer/editor");
|
|
9
|
+
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
10
|
+
|
|
11
|
+
//#region src/editor/useCrossFrameMessageListener.ts
|
|
12
|
+
/** Map<key, Set<callback>> */
|
|
28
13
|
const subscribers = /* @__PURE__ */ new Map();
|
|
14
|
+
/** True once we've attached the single window listener */
|
|
29
15
|
let windowListenerAttached = false;
|
|
16
|
+
/** Helper to add/remove a callback for a key */
|
|
30
17
|
function addSubscriber(key, cb) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
let set = subscribers.get(key);
|
|
19
|
+
if (!set) {
|
|
20
|
+
set = /* @__PURE__ */ new Set();
|
|
21
|
+
subscribers.set(key, set);
|
|
22
|
+
}
|
|
23
|
+
set.add(cb);
|
|
37
24
|
}
|
|
38
25
|
function removeSubscriber(key, cb) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
const set = subscribers.get(key);
|
|
27
|
+
if (!set) return;
|
|
28
|
+
set.delete(cb);
|
|
29
|
+
if (set.size === 0) subscribers.delete(key);
|
|
43
30
|
}
|
|
31
|
+
/** The one global window listener */
|
|
44
32
|
function ensureGlobalListener(allowedOrigins, selfId) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
windowListenerAttached = true;
|
|
33
|
+
if (windowListenerAttached) return;
|
|
34
|
+
window.addEventListener("message", (event) => {
|
|
35
|
+
const { type, data, senderId } = event.data ?? {};
|
|
36
|
+
if (!type) return;
|
|
37
|
+
if (senderId === selfId) return;
|
|
38
|
+
if (!allowedOrigins || allowedOrigins.includes("*") || allowedOrigins.some((o) => (0, __intlayer_editor.compareUrls)(o, event.origin))) subscribers.get(type)?.forEach((cb) => cb(data));
|
|
39
|
+
});
|
|
40
|
+
windowListenerAttached = true;
|
|
55
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* useCrossFrameMessageListener
|
|
44
|
+
*
|
|
45
|
+
* @template S - type of the message payload
|
|
46
|
+
* @param key message type we care about
|
|
47
|
+
* @param onEventTriggered optional callback when a matching message arrives
|
|
48
|
+
* @returns postMessage(data?) helper scoped to this key
|
|
49
|
+
*/
|
|
56
50
|
const useCrossFrameMessageListener = (key, onEventTriggered) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
return postMessageWrapper;
|
|
51
|
+
const { allowedOrigins, postMessage, senderId } = require_editor_communicator.useCommunicator();
|
|
52
|
+
ensureGlobalListener(allowedOrigins, senderId);
|
|
53
|
+
if (onEventTriggered) {
|
|
54
|
+
addSubscriber(key, onEventTriggered);
|
|
55
|
+
try {
|
|
56
|
+
const destroyRef = (0, __angular_core.inject)(__angular_core.DestroyRef, { optional: true });
|
|
57
|
+
if (destroyRef) destroyRef.onDestroy(() => removeSubscriber(key, onEventTriggered));
|
|
58
|
+
} catch {
|
|
59
|
+
console.warn("useCrossFrameMessageListener called outside injection context; cleanup may not be available.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const postMessageWrapper = (data) => {
|
|
63
|
+
postMessage({
|
|
64
|
+
type: key,
|
|
65
|
+
data,
|
|
66
|
+
senderId
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return postMessageWrapper;
|
|
78
70
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.useCrossFrameMessageListener = useCrossFrameMessageListener;
|
|
83
74
|
//# sourceMappingURL=useCrossFrameMessageListener.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/useCrossFrameMessageListener.ts"],"sourcesContent":["'use client';\n\nimport { DestroyRef, inject } from '@angular/core';\nimport { type MessageKey
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator","DestroyRef"],"sources":["../../../src/editor/useCrossFrameMessageListener.ts"],"sourcesContent":["'use client';\n\nimport { DestroyRef, inject } from '@angular/core';\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useCommunicator } from './communicator';\n\n// ---------- module-level singletons ----------\ntype AnyFn = (data: unknown) => void;\n\n/** Map<key, Set<callback>> */\nconst subscribers = new Map<string, Set<AnyFn>>();\n\n/** True once we've attached the single window listener */\nlet windowListenerAttached = false;\n\n/** Helper to add/remove a callback for a key */\nfunction addSubscriber(key: string, cb: AnyFn) {\n let set = subscribers.get(key);\n if (!set) {\n set = new Set();\n subscribers.set(key, set);\n }\n set.add(cb);\n}\n\nfunction removeSubscriber(key: string, cb: AnyFn) {\n const set = subscribers.get(key);\n if (!set) return;\n set.delete(cb);\n if (set.size === 0) subscribers.delete(key);\n}\n\n/** The one global window listener */\nfunction ensureGlobalListener(\n allowedOrigins: string[] | undefined,\n selfId: string\n) {\n if (windowListenerAttached) return;\n window.addEventListener('message', (event) => {\n const { type, data, senderId } = event.data ?? {};\n if (!type) return; // guard malformed messages\n if (senderId === selfId) return; // ignore my own\n\n // origin check\n if (\n !allowedOrigins ||\n allowedOrigins.includes('*') ||\n allowedOrigins.some((o) => compareUrls(o, event.origin))\n ) {\n // broadcast to everyone interested in this key\n subscribers.get(type)?.forEach((cb) => cb(data));\n }\n });\n windowListenerAttached = true;\n}\n// ---------- end module-level code ----------\n\n/**\n * useCrossFrameMessageListener\n *\n * @template S - type of the message payload\n * @param key message type we care about\n * @param onEventTriggered optional callback when a matching message arrives\n * @returns postMessage(data?) helper scoped to this key\n */\nexport const useCrossFrameMessageListener = <S>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void\n) => {\n // Communicator is the same for everyone, so it's fine to call every time.\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n // --- 1. make sure the global listener exists ----\n ensureGlobalListener(allowedOrigins, senderId);\n\n // --- 2. register this caller's callback (if any) ---\n if (onEventTriggered) {\n addSubscriber(key, onEventTriggered as AnyFn);\n\n // Use Angular's DestroyRef for cleanup instead of Vue's onScopeDispose\n try {\n const destroyRef = inject(DestroyRef, { optional: true });\n if (destroyRef) {\n destroyRef.onDestroy(() =>\n removeSubscriber(key, onEventTriggered as AnyFn)\n );\n }\n } catch {\n // If called outside injection context, no cleanup available\n console.warn(\n 'useCrossFrameMessageListener called outside injection context; ' +\n 'cleanup may not be available.'\n );\n }\n }\n\n // --- 3. return a wrapper that tags outgoing messages with our key ---\n const postMessageWrapper = (data?: S) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,8BAAc,IAAI,KAAyB;;AAGjD,IAAI,yBAAyB;;AAG7B,SAAS,cAAc,KAAa,IAAW;CAC7C,IAAI,MAAM,YAAY,IAAI,IAAI;AAC9B,KAAI,CAAC,KAAK;AACR,wBAAM,IAAI,KAAK;AACf,cAAY,IAAI,KAAK,IAAI;;AAE3B,KAAI,IAAI,GAAG;;AAGb,SAAS,iBAAiB,KAAa,IAAW;CAChD,MAAM,MAAM,YAAY,IAAI,IAAI;AAChC,KAAI,CAAC,IAAK;AACV,KAAI,OAAO,GAAG;AACd,KAAI,IAAI,SAAS,EAAG,aAAY,OAAO,IAAI;;;AAI7C,SAAS,qBACP,gBACA,QACA;AACA,KAAI,uBAAwB;AAC5B,QAAO,iBAAiB,YAAY,UAAU;EAC5C,MAAM,EAAE,MAAM,MAAM,aAAa,MAAM,QAAQ,EAAE;AACjD,MAAI,CAAC,KAAM;AACX,MAAI,aAAa,OAAQ;AAGzB,MACE,CAAC,kBACD,eAAe,SAAS,IAAI,IAC5B,eAAe,MAAM,yCAAkB,GAAG,MAAM,OAAO,CAAC,CAGxD,aAAY,IAAI,KAAK,EAAE,SAAS,OAAO,GAAG,KAAK,CAAC;GAElD;AACF,0BAAyB;;;;;;;;;;AAY3B,MAAa,gCACX,KACA,qBACG;CAEH,MAAM,EAAE,gBAAgB,aAAa,aAAaA,6CAAiB;AAGnE,sBAAqB,gBAAgB,SAAS;AAG9C,KAAI,kBAAkB;AACpB,gBAAc,KAAK,iBAA0B;AAG7C,MAAI;GACF,MAAM,wCAAoBC,2BAAY,EAAE,UAAU,MAAM,CAAC;AACzD,OAAI,WACF,YAAW,gBACT,iBAAiB,KAAK,iBAA0B,CACjD;UAEG;AAEN,WAAQ,KACN,+FAED;;;CAKL,MAAM,sBAAsB,SAAa;AACvC,cAAY;GAAE,MAAM;GAAK;GAAM;GAAU,CAAC;;AAG5C,QAAO"}
|