@leav/ui 1.14.0-0b747e99 → 1.14.0-1
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/components/EditTreeModal/EditTree/EditTreeInfo/EditTreeInfoForm/TreeLibrariesForm/TreeLibrariesForm.js +1 -1
- package/dist/components/EditTreeModal/EditTree/EditTreeInfo/EditTreeInfoForm/TreeLibrariesForm/TreeLibrariesForm.js.map +1 -1
- package/dist/components/Explorer/ExplorerTitle.js +1 -1
- package/dist/components/Explorer/ExplorerTitle.js.map +1 -1
- package/dist/components/Explorer/TableCell.js +7 -6
- package/dist/components/Explorer/TableCell.js.map +1 -1
- package/dist/components/Explorer/TableNameCell.js +3 -2
- package/dist/components/Explorer/TableNameCell.js.map +1 -1
- package/dist/components/Explorer/actions-item/useEditStatusItemAction.js +1 -1
- package/dist/components/Explorer/actions-item/useEditStatusItemAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useDeactivateMassAction.js +1 -1
- package/dist/components/Explorer/actions-mass/useDeactivateMassAction.js.map +1 -1
- package/dist/components/Explorer/actions-mass/useDeleteLinkValues.js +1 -1
- package/dist/components/Explorer/actions-mass/useDeleteLinkValues.js.map +1 -1
- package/dist/components/ImportModal/ImportModalConfigStep/ImportSheetSettings/ImportSheetSettings.js +1 -1
- package/dist/components/ImportModal/ImportModalConfigStep/ImportSheetSettings/ImportSheetSettings.js.map +1 -1
- package/dist/components/RecordCard/RecordCard.js +1 -1
- package/dist/components/RecordCard/RecordCard.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordButtons/SidebarButton.js +1 -1
- package/dist/components/RecordEdition/EditRecordButtons/SidebarButton.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/tag/link-record/useLinkRecord.js +2 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/LinkField/tag/link-record/useLinkRecord.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/ComputeIndicator.js +2 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/ComputeIndicator.js.map +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/DeleteAllValuesButton.js +1 -1
- package/dist/components/RecordEdition/EditRecordContent/uiElements/shared/DeleteAllValuesButton.js.map +1 -1
- package/dist/components/RecordEdition/hooks/useCreateCancelConfirm/useCreateCancelConfirm.js +1 -1
- package/dist/components/RecordEdition/hooks/useCreateCancelConfirm/useCreateCancelConfirm.js.map +1 -1
- package/dist/components/SelectTreeNode/SelectTreeNode.js +1 -1
- package/dist/components/SelectTreeNode/SelectTreeNode.js.map +1 -1
- package/dist/components/TriggerPreviewsGenerationModal/TriggerPreviewsGenerationModal.js +1 -1
- package/dist/components/TriggerPreviewsGenerationModal/TriggerPreviewsGenerationModal.js.map +1 -1
- package/dist/components/ValuesVersionConfigurator/VersionTree/VersionTree.js +1 -1
- package/dist/components/ValuesVersionConfigurator/VersionTree/VersionTree.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/hooks/index.d.ts +8 -4
- package/dist/hooks/index.js +8 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useConfirmModal/__mocks__/index.d.ts +1 -0
- package/dist/hooks/useConfirmModal/__mocks__/index.js +2 -0
- package/dist/hooks/useConfirmModal/__mocks__/index.js.map +1 -0
- package/dist/hooks/useConfirmModal/index.d.ts +1 -0
- package/dist/hooks/useConfirmModal/index.js +2 -0
- package/dist/hooks/useConfirmModal/index.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.d.ts +8 -0
- package/dist/hooks/{usePanelMessenger/panelMessengerContext.js → useIFrameMessenger/iFrameMessengerContext.js} +2 -2
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js.map +1 -0
- package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/messageHandlers.d.ts +2 -2
- package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/messageHandlers.js +1 -1
- package/dist/hooks/useIFrameMessenger/messageHandlers.js.map +1 -0
- package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/schema.d.ts +0 -9
- package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/schema.js +0 -10
- package/dist/hooks/useIFrameMessenger/schema.js.map +1 -0
- package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/types.d.ts +9 -20
- package/dist/hooks/useIFrameMessenger/types.js.map +1 -0
- package/dist/hooks/{usePanelMessenger/usePanelMessenger.d.ts → useIFrameMessenger/useIFrameMessenger.d.ts} +3 -3
- package/dist/hooks/{usePanelMessenger/usePanelMessenger.js → useIFrameMessenger/useIFrameMessenger.js} +2 -16
- package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.d.ts +13 -0
- package/dist/hooks/{usePanelMessenger/PanelMessengerProvider.js → useIFrameMessenger/useIFrameMessengerContext.js} +12 -22
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js.map +1 -0
- package/dist/hooks/{usePanelMessenger/usePanelIFrameHandlers.d.ts → useIFrameMessenger/useIFrameMessengerHandlers.d.ts} +3 -3
- package/dist/hooks/{usePanelMessenger/usePanelIFrameHandlers.js → useIFrameMessenger/useIFrameMessengerHandlers.js} +5 -5
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.d.ts +14 -0
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.js +19 -0
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.js.map +1 -0
- package/dist/hooks/useIFrameMessengerClient/{IFrameMessengerClientProvider.d.ts → IFrameMessengerClient.d.ts} +1 -1
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js +13 -0
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js.map +1 -0
- package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.d.ts +19 -0
- package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.js +3 -0
- package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.js.map +1 -0
- package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.d.ts +13 -14
- package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.js +2 -2
- package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.js.map +1 -1
- package/dist/hooks/useLang/__mocks__/index.d.ts +2 -0
- package/dist/hooks/useLang/__mocks__/index.js +3 -0
- package/dist/hooks/useLang/__mocks__/index.js.map +1 -0
- package/dist/hooks/useLang/__mocks__/useLang.js.map +1 -1
- package/dist/hooks/useLang/index.d.ts +2 -0
- package/dist/hooks/useLang/index.js +3 -0
- package/dist/hooks/useLang/index.js.map +1 -0
- package/dist/hooks/useLang/useLang.js.map +1 -1
- package/dist/testing/MockedLangContextProvider/MockedLangContextProvider.js +1 -1
- package/dist/testing/MockedLangContextProvider/MockedLangContextProvider.js.map +1 -1
- package/package.json +10 -11
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClientContext.d.ts +0 -20
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClientContext.js +0 -3
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClientContext.js.map +0 -1
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClientProvider.js +0 -13
- package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClientProvider.js.map +0 -1
- package/dist/hooks/useIFrameMessengerClient/index.d.ts +0 -2
- package/dist/hooks/useIFrameMessengerClient/index.js +0 -3
- package/dist/hooks/useIFrameMessengerClient/index.js.map +0 -1
- package/dist/hooks/usePanelMessenger/PanelMessengerProvider.d.ts +0 -13
- package/dist/hooks/usePanelMessenger/PanelMessengerProvider.js.map +0 -1
- package/dist/hooks/usePanelMessenger/index.d.ts +0 -6
- package/dist/hooks/usePanelMessenger/index.js +0 -6
- package/dist/hooks/usePanelMessenger/index.js.map +0 -1
- package/dist/hooks/usePanelMessenger/messageHandlers.js.map +0 -1
- package/dist/hooks/usePanelMessenger/panelMessengerContext.d.ts +0 -10
- package/dist/hooks/usePanelMessenger/panelMessengerContext.js.map +0 -1
- package/dist/hooks/usePanelMessenger/schema.js.map +0 -1
- package/dist/hooks/usePanelMessenger/types.js.map +0 -1
- package/dist/hooks/usePanelMessenger/usePanelEventHandlers.d.ts +0 -10
- package/dist/hooks/usePanelMessenger/usePanelEventHandlers.js +0 -15
- package/dist/hooks/usePanelMessenger/usePanelEventHandlers.js.map +0 -1
- package/dist/hooks/usePanelMessenger/usePanelIFrameHandlers.js.map +0 -1
- package/dist/hooks/usePanelMessenger/usePanelMessenger.js.map +0 -1
- /package/dist/hooks/{usePanelMessenger → useIFrameMessenger}/types.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Kept in a separate file from the Provider component to satisfy the
|
|
2
2
|
// react-refresh/only-export-components ESLint rule (Context is not a component).
|
|
3
3
|
import { createContext } from 'react';
|
|
4
|
-
export const
|
|
5
|
-
//# sourceMappingURL=
|
|
4
|
+
export const IFrameMessengerContext = createContext(null);
|
|
5
|
+
//# sourceMappingURL=iFrameMessengerContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/iFrameMessengerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,iFAAiF;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAUpC,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC","sourcesContent":["// Kept in a separate file from the Provider component to satisfy the\n// react-refresh/only-export-components ESLint rule (Context is not a component).\nimport {createContext} from 'react';\nimport {type DispatchToNativePanel, type RegisterHandlers, type RegisterNativePanelHandlers} from './types';\n\nexport interface IIFrameMessengerContext {\n registerHandlers: RegisterHandlers;\n registerNativePanelHandlers: RegisterNativePanelHandlers;\n dispatchToNativePanel: DispatchToNativePanel;\n changeLangInAllFrames: (language: string) => void;\n}\n\nexport const IFrameMessengerContext = createContext<IIFrameMessengerContext>(null);\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type MutableRefObject } from 'react';
|
|
2
|
-
import { type AlertMessage, type Callbacks, type CallCbFunction, type ClosePanelMessage, type ExplorerViewChangedMessage, type
|
|
2
|
+
import { type AlertMessage, type Callbacks, type CallCbFunction, type ClosePanelMessage, type ExplorerViewChangedMessage, type IUseIFrameMessengerOptions, type GetUrlMessage, type Message, type MessageDispatcher, type MessageHandler, type MessageToPanelMessage, type ModalConfirmMessage, type NavigateToIframeMessage, type NavigateToPanelMessage, type NotificationMessage, type SimpleMessage, type OpenFlapPanelMessage, type GetPanelConfigMessage } from './types';
|
|
3
3
|
export declare const encodeMessage: (message: Message) => string;
|
|
4
4
|
export declare const decodeMessage: (raw: string) => Message | undefined;
|
|
5
|
-
export declare const initClientHandlers: (callCb: CallCbFunction, options?:
|
|
5
|
+
export declare const initClientHandlers: (callCb: CallCbFunction, options?: IUseIFrameMessengerOptions, callbacksList?: MutableRefObject<Callbacks>) => MessageHandler;
|
|
6
6
|
export declare const getExposedMethods: (callbacksStore: MutableRefObject<Callbacks>, dispatch?: MessageDispatcher) => {
|
|
7
7
|
showModalConfirm: (data: ModalConfirmMessage["data"]) => void;
|
|
8
8
|
showAlert: (data: AlertMessage["data"]) => void;
|
|
@@ -78,7 +78,7 @@ export const initClientHandlers = (callCb, options, callbacksList) => (message,
|
|
|
78
78
|
case 'explorer-view-changed':
|
|
79
79
|
options?.handlers?.onExplorerViewChanged?.(message.data);
|
|
80
80
|
break;
|
|
81
|
-
case 'view-
|
|
81
|
+
case 'view-config-update':
|
|
82
82
|
options?.handlers?.onViewConfigUpdate?.(message.data);
|
|
83
83
|
break;
|
|
84
84
|
default:
|
|
@@ -0,0 +1 @@
|
|
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BAAkB,EAAE,IAAI,EAAE,QAAyC,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC3G,CAAC;IACD,MAAM,EAAE,CAAC,IAA2B,EAAE,EAAE;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAC,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;QAC7E,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAiC,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC1F,CAAC;IACD,mBAAmB,EAAE,CAAC,IAAwC,EAAE,EAAE;QAC9D,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAC,CAAC,CAAC;IACtD,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import {type MutableRefObject} from 'react';\nimport {\n type AlertMessage,\n type CallbackFunction,\n type Callbacks,\n type CallCbFunction,\n type ClosePanelMessage,\n type ExplorerViewChangedMessage,\n type IEncodedMessage,\n type IUseIFrameMessengerOptions,\n type GetUrlMessage,\n type Message,\n type MessageDispatcher,\n type MessageHandler,\n type MessageToPanelMessage,\n type ModalConfirmMessage,\n type NavigateToIframeMessage,\n type NavigateToPanelMessage,\n type NotificationMessage,\n packetId,\n type SimpleMessage,\n type OpenFlapPanelMessage,\n type GetPanelConfigMessage,\n type ViewConfigUpdateMessage,\n} from './types';\n\nexport const encodeMessage = (message: Message): string =>\n JSON.stringify({\n payload: JSON.stringify(message),\n [packetId]: true,\n });\n\nexport const decodeMessage = (raw: string): Message | undefined => {\n try {\n const decoded: IEncodedMessage = JSON.parse(raw) as unknown as IEncodedMessage;\n if (packetId in decoded && decoded[packetId] === true) {\n return JSON.parse(decoded.payload) as Message;\n }\n } catch (e) {\n return undefined;\n }\n return undefined;\n};\n\nconst getCallback = (path: string, callbacksList?: MutableRefObject<Callbacks>): CallbackFunction | null => {\n if (!callbacksList?.current) {\n return null;\n }\n const pathArray = path.split('.');\n let callback: CallbackFunction | Callbacks | Record<string, CallbackFunction> = callbacksList.current;\n pathArray.forEach(part => (callback = (callback as Callbacks | Record<string, CallbackFunction>)?.[part]));\n return typeof callback === 'function' ? callback : null;\n};\n\nconst setCallbacks = (\n id: string,\n frameId: string,\n data: unknown,\n callCb: CallCbFunction,\n overrides?: string[],\n): unknown => {\n if (!overrides) {\n return data;\n }\n\n const nextData = {...(data as Record<string, unknown>)};\n overrides.forEach((key: string) => {\n nextData[key] = (...args: unknown[]) => {\n callCb(`${id}.${key}`, args, frameId);\n };\n });\n return nextData;\n};\n\nexport const initClientHandlers: (\n callCb: CallCbFunction,\n options?: IUseIFrameMessengerOptions,\n callbacksList?: MutableRefObject<Callbacks>,\n) => MessageHandler = (callCb, options, callbacksList) => (message, dispatch) => {\n switch (message.type) {\n case 'modal-confirm':\n options?.handlers?.onModalConfirm?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as ModalConfirmMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'alert':\n options?.handlers?.onAlert?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as AlertMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'notification':\n options?.handlers?.onNotification?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as NotificationMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'message':\n options?.handlers?.onMessage?.(message.data, message.id, dispatch, callCb);\n break;\n case 'on-call-callback':\n // TODO How to know if handler can be removed from callbacksList ?\n getCallback(message.path, callbacksList)?.(...(message.data as never[]));\n break;\n case 'navigate-to-panel':\n options?.handlers?.onNavigateToPanel?.(message.data);\n break;\n case 'close-panel':\n options?.handlers?.onClosePanel?.(message.data);\n break;\n case 'navigate-to-iframe':\n options?.handlers?.onNavigateToIframe?.(message.data);\n break;\n case 'open-flap-panel':\n options?.handlers?.onOpenFlapPanel?.(message.data);\n break;\n case 'close-flap-panel':\n options?.handlers?.onCloseFlapPanel?.();\n break;\n case 'get-panel-config':\n options?.handlers?.onGetPanelConfig?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetPanelConfigMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'get-url':\n options?.handlers?.onGetUrl?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetUrlMessage['data'],\n );\n break;\n case 'explorer-view-changed':\n options?.handlers?.onExplorerViewChanged?.(message.data as ExplorerViewChangedMessage['data']);\n break;\n case 'view-config-update':\n options?.handlers?.onViewConfigUpdate?.(message.data as ViewConfigUpdateMessage['data']);\n break;\n default:\n break;\n }\n};\n\nconst storeCallbacks = (\n data: unknown,\n id: string,\n callbacksStore: MutableRefObject<Callbacks>,\n): {data: unknown; overrides: string[]} => {\n const nextData = {...(data as Record<string, unknown>)};\n const overrides: string[] = [];\n Object.entries(nextData).forEach(([key, value]) => {\n if (typeof value === 'function') {\n callbacksStore.current[id] = {\n ...callbacksStore.current[id],\n [key]: value as CallbackFunction,\n };\n overrides.push(key);\n }\n });\n return {data: nextData, overrides};\n};\n\nexport const getExposedMethods = (callbacksStore: MutableRefObject<Callbacks>, dispatch?: MessageDispatcher) => ({\n showModalConfirm: (data: ModalConfirmMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'modal-confirm', data: nextData as ModalConfirmMessage['data'], id, overrides});\n },\n showAlert: (data: AlertMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'alert', data: nextData as AlertMessage['data'], id, overrides});\n },\n showNotification: (data: NotificationMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'notification', data: nextData as NotificationMessage['data'], id, overrides});\n },\n messageToParent: (data: SimpleMessage['data']) => {\n const id = Date.now().toString();\n dispatch?.({type: 'message', data, id});\n },\n navigateToPanel: (data: NavigateToPanelMessage['data']) => {\n dispatch?.({type: 'navigate-to-panel', data});\n },\n closePanel: (data: ClosePanelMessage['data']) => {\n dispatch?.({type: 'close-panel', data});\n },\n navigateToIframe: (data: NavigateToIframeMessage['data']) => {\n dispatch?.({type: 'navigate-to-iframe', data});\n },\n messageToPanel: (data: MessageToPanelMessage['data']) => {\n dispatch?.({type: 'message-to-panel', data});\n },\n openFlapPanel: (data: OpenFlapPanelMessage['data']) => {\n dispatch?.({type: 'open-flap-panel', data});\n },\n closeFlapPanel: () => {\n dispatch?.({type: 'close-flap-panel'});\n },\n getPanelConfig: (data: GetPanelConfigMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-panel-config', data: nextData as GetPanelConfigMessage['data'], id, overrides});\n },\n getUrl: (data: GetUrlMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-url', data: nextData as GetUrlMessage['data'], id, overrides});\n },\n explorerViewChanged: (data: ExplorerViewChangedMessage['data']) => {\n dispatch?.({type: 'explorer-view-changed', data});\n },\n});\n"]}
|
|
@@ -5,7 +5,6 @@ export declare const LanguageSchema: z.ZodString;
|
|
|
5
5
|
export declare const LibraryIdSchema: z.ZodString;
|
|
6
6
|
export declare const FontAwesomeIconSchema: z.ZodOptional<z.ZodString>;
|
|
7
7
|
export declare const WhereSchema: z.ZodUnion<readonly [z.ZodLiteral<"popup">, z.ZodLiteral<"slider">, z.ZodLiteral<"fullpage">]>;
|
|
8
|
-
export declare const ViewSettingsShortcutsSchema: z.ZodUnion<readonly [z.ZodLiteral<"display">, z.ZodLiteral<"filters">, z.ZodLiteral<"sorts">, z.ZodLiteral<"catalog">]>;
|
|
9
8
|
export declare const FlapPanelIdSchema: z.ZodUnion<readonly [z.ZodLiteral<"info-history">, z.ZodLiteral<"thread">]>;
|
|
10
9
|
export declare const ExplorerPropsSchema: z.ZodObject<{
|
|
11
10
|
showSearch: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -64,10 +63,6 @@ export declare const baseExplorerPanelSchema: z.ZodObject<{
|
|
|
64
63
|
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
65
64
|
onRowClick: z.ZodOptional<z.ZodBoolean>;
|
|
66
65
|
}, z.core.$strip>>;
|
|
67
|
-
targetLibraryId: z.ZodOptional<z.ZodString>;
|
|
68
|
-
selectedTab: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"display">, z.ZodLiteral<"filters">, z.ZodLiteral<"sorts">, z.ZodLiteral<"catalog">]>>;
|
|
69
|
-
currentViewId: z.ZodOptional<z.ZodString>;
|
|
70
|
-
isViewSettingsActive: z.ZodDefault<z.ZodBoolean>;
|
|
71
66
|
}, z.core.$strip>;
|
|
72
67
|
export declare const attributeExplorerPanelSchema: z.ZodObject<{
|
|
73
68
|
attributeSource: z.ZodString;
|
|
@@ -105,10 +100,6 @@ export declare const PanelSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
105
100
|
label: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
106
101
|
onRowClick: z.ZodOptional<z.ZodBoolean>;
|
|
107
102
|
}, z.core.$strip>>;
|
|
108
|
-
targetLibraryId: z.ZodOptional<z.ZodString>;
|
|
109
|
-
selectedTab: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"display">, z.ZodLiteral<"filters">, z.ZodLiteral<"sorts">, z.ZodLiteral<"catalog">]>>;
|
|
110
|
-
currentViewId: z.ZodOptional<z.ZodString>;
|
|
111
|
-
isViewSettingsActive: z.ZodDefault<z.ZodBoolean>;
|
|
112
103
|
}, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
|
|
113
104
|
attributeSource: z.ZodString;
|
|
114
105
|
deactivateOnUnlink: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -5,12 +5,6 @@ export const LanguageSchema = z.string();
|
|
|
5
5
|
export const LibraryIdSchema = z.string();
|
|
6
6
|
export const FontAwesomeIconSchema = z.string().regex(FONT_AWESOME_ICON_REGEX).optional();
|
|
7
7
|
export const WhereSchema = z.union([z.literal('popup'), z.literal('slider'), z.literal('fullpage')]);
|
|
8
|
-
export const ViewSettingsShortcutsSchema = z.union([
|
|
9
|
-
z.literal('display'),
|
|
10
|
-
z.literal('filters'),
|
|
11
|
-
z.literal('sorts'),
|
|
12
|
-
z.literal('catalog'),
|
|
13
|
-
]);
|
|
14
8
|
export const FlapPanelIdSchema = z.union([z.literal('info-history'), z.literal('thread')]);
|
|
15
9
|
export const ExplorerPropsSchema = z.object({
|
|
16
10
|
showSearch: z.boolean().optional(),
|
|
@@ -75,10 +69,6 @@ export const baseExplorerPanelSchema = z.object({
|
|
|
75
69
|
type: z.literal('explorer'),
|
|
76
70
|
viewId: z.string().optional(),
|
|
77
71
|
actions: ItemActionsSchema,
|
|
78
|
-
targetLibraryId: LibraryIdSchema.optional(),
|
|
79
|
-
selectedTab: ViewSettingsShortcutsSchema.optional(),
|
|
80
|
-
currentViewId: z.string().optional(),
|
|
81
|
-
isViewSettingsActive: z.boolean().default(false),
|
|
82
72
|
});
|
|
83
73
|
export const attributeExplorerPanelSchema = z.object({
|
|
84
74
|
attributeSource: z.string(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE9C,MAAM,CAAC,MAAM,aAAa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\nexport const FONT_AWESOME_ICON_REGEX = /^fa-/;\n\nexport const PanelIdSchema = z.string();\nexport const LanguageSchema = z.string();\nexport const LibraryIdSchema = z.string();\nexport const FontAwesomeIconSchema = z.string().regex(FONT_AWESOME_ICON_REGEX).optional();\n\nexport const WhereSchema = z.union([z.literal('popup'), z.literal('slider'), z.literal('fullpage')]);\n\nexport const FlapPanelIdSchema = z.union([z.literal('info-history'), z.literal('thread')]);\n\nexport const ExplorerPropsSchema = z.object({\n showSearch: z.boolean().optional(),\n showFilters: z.boolean().optional(),\n showSorts: z.boolean().optional(),\n freezeView: z.boolean().optional(),\n showAttributeLabels: z.boolean().optional(),\n creationFormId: z.string().optional(),\n noPagination: z.literal(true).optional(),\n showActionsLabels: z.boolean().optional(),\n defaultPrimaryActions: z.array(z.union([z.literal('create')])).optional(),\n defaultMassActions: z\n .array(z.union([z.literal('deactivate'), z.literal('export'), z.literal('editAttribute')]))\n .optional(),\n defaultActionsForItem: z\n .array(z.union([z.literal('replaceLink'), z.literal('remove'), z.literal('activate')]))\n .optional(),\n});\n\nexport const ItemActionsSchema = z\n .array(\n z.object({\n where: WhereSchema,\n what: z.literal('record'),\n targetPanelId: PanelIdSchema.optional(),\n targetFlapPanelId: FlapPanelIdSchema.optional(),\n icon: FontAwesomeIconSchema,\n label: z.record(LanguageSchema, z.string()),\n onRowClick: z.boolean().optional(),\n }),\n )\n .refine(actions => actions.reduce((acc, action) => (action.onRowClick ? acc + 1 : acc), 0) <= 1, {\n message: 'At most one action must have onRowClick set to true',\n });\n\nexport const basePanelSchema = z.object({\n id: PanelIdSchema,\n icon: FontAwesomeIconSchema,\n name: z.record(LanguageSchema, z.string()).optional(),\n isStandalone: z.boolean().optional(),\n hideInCompactMode: z.boolean().optional(),\n});\n\nexport const iframePanelSchema = z.object({\n type: z.literal('custom'),\n iframeSource: z.string(),\n viewId: z.string().optional(),\n isSelfContaining: z.boolean().optional(),\n popupProps: z\n .object({\n width: z.string().optional(),\n height: z.string().optional(),\n })\n .optional(),\n});\n\nconst editionPanelSchema = z.object({\n type: z.literal('editionForm'),\n formId: z.string(),\n});\n\nexport const creationPanelSchema = z.object({\n type: z.literal('creationForm'),\n formId: z.string(),\n attributeSource: z.string().optional(),\n isStandalone: z.literal(true),\n});\n\nexport const baseExplorerPanelSchema = z.object({\n type: z.literal('explorer'),\n viewId: z.string().optional(),\n actions: ItemActionsSchema,\n});\n\nexport const attributeExplorerPanelSchema = z.object({\n attributeSource: z.string(),\n deactivateOnUnlink: z.boolean().optional(),\n libraryId: LibraryIdSchema,\n explorerProps: ExplorerPropsSchema.optional(),\n});\n\nconst libraryExplorerPanelSchema = z.object({\n explorerProps: ExplorerPropsSchema.optional(),\n});\n\nconst explorerPanelSchema = baseExplorerPanelSchema.and(\n z.union([attributeExplorerPanelSchema, libraryExplorerPanelSchema]),\n);\n\nexport const PanelSchema = basePanelSchema.and(\n z.union([explorerPanelSchema, iframePanelSchema, editionPanelSchema, creationPanelSchema]),\n);\n\nexport const PanelIFrameSchema = basePanelSchema.and(iframePanelSchema);\n"]}
|
|
@@ -3,7 +3,7 @@ import type * as z from 'zod/v4';
|
|
|
3
3
|
import { type KitNotification } from 'aristid-ds';
|
|
4
4
|
import { type IKitConfirmDialog } from 'aristid-ds/dist/Kit/Feedback/Modal/types';
|
|
5
5
|
import { type ToastedAlertProps } from 'aristid-ds/dist/Kit/Feedback/Alert/types';
|
|
6
|
-
import { type LibraryIdSchema, type WhereSchema, type PanelIdSchema, type PanelSchema, type PanelIFrameSchema, type FlapPanelIdSchema, type attributeExplorerPanelSchema, type baseExplorerPanelSchema } from '../../hooks/
|
|
6
|
+
import { type LibraryIdSchema, type WhereSchema, type PanelIdSchema, type PanelSchema, type PanelIFrameSchema, type FlapPanelIdSchema, type attributeExplorerPanelSchema, type baseExplorerPanelSchema } from '../../hooks/useIFrameMessenger/schema';
|
|
7
7
|
import { type AnyPrimitive } from '@leav/utils';
|
|
8
8
|
import { type IRecordIdentity, type ITreeNodeWithRecord } from '../../types';
|
|
9
9
|
import { type SerializedView } from '../../components/Explorer/_types';
|
|
@@ -153,8 +153,8 @@ export type ExplorerViewChangedMessage = IMessageBase & {
|
|
|
153
153
|
serializedView: SerializedView;
|
|
154
154
|
};
|
|
155
155
|
};
|
|
156
|
-
export type
|
|
157
|
-
type: 'view-
|
|
156
|
+
export type ViewConfigUpdateMessage = IMessageBase & {
|
|
157
|
+
type: 'view-config-update';
|
|
158
158
|
data: {
|
|
159
159
|
targetPanelId: string;
|
|
160
160
|
serializedView: SerializedView;
|
|
@@ -165,7 +165,7 @@ export type MessageFromParent = (IMessageBase & {
|
|
|
165
165
|
type: 'on-call-callback';
|
|
166
166
|
path: string;
|
|
167
167
|
data: unknown;
|
|
168
|
-
}) | IsRegisteredMessage | ChangeLanguageMessage |
|
|
168
|
+
}) | IsRegisteredMessage | ChangeLanguageMessage | ViewConfigUpdateMessage;
|
|
169
169
|
export type Message = MessageToParent | MessageFromParent;
|
|
170
170
|
export type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;
|
|
171
171
|
export type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;
|
|
@@ -173,23 +173,12 @@ export type CallCbFunction = (path: string, data: unknown, frameId: string) => v
|
|
|
173
173
|
export type CallbackFunction = (...args: never[]) => void;
|
|
174
174
|
export type Callbacks = Record<string, Record<string, CallbackFunction>>;
|
|
175
175
|
export type MessageToPanelMessageHandler = (data: MessageToPanelMessage['data']['payload']) => void;
|
|
176
|
-
export type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) =>
|
|
177
|
-
export type InternalEventHandler<D = unknown> = (data: D) => void;
|
|
178
|
-
export type AddInternalEventHandler = (type: string, handler: InternalEventHandler) => () => void;
|
|
179
|
-
/**
|
|
180
|
-
* Typed message for internal app events dispatched between app-studio components
|
|
181
|
-
* or from child iframes. The `type` field is the event name (e.g. 'view-settings-changed').
|
|
182
|
-
* Add specific subtypes in types.ts as needed and register handlers via useIFramePanelMessageHandler.
|
|
183
|
-
*/
|
|
184
|
-
export type InternalEventMessage<T extends string = string, D = unknown> = {
|
|
185
|
-
type: T;
|
|
186
|
-
data: D;
|
|
187
|
-
};
|
|
176
|
+
export type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) => void;
|
|
188
177
|
export type UnregisterHandlers = () => void;
|
|
189
|
-
export type RegisterHandlers = (iframeRef: RefObject<HTMLIFrameElement>, handlers:
|
|
190
|
-
export type RegisterNativePanelHandlers = (panelId: string, handlers:
|
|
178
|
+
export type RegisterHandlers = (iframeRef: RefObject<HTMLIFrameElement>, handlers: IUseIFrameMessengerOptions['handlers']) => UnregisterHandlers;
|
|
179
|
+
export type RegisterNativePanelHandlers = (panelId: string, handlers: IUseIFrameMessengerOptions['handlers']) => UnregisterHandlers;
|
|
191
180
|
export type DispatchToNativePanel = (panelId: string, message: Message) => void;
|
|
192
|
-
export interface
|
|
181
|
+
export interface IUseIFrameMessengerOptions {
|
|
193
182
|
ref?: RefObject<HTMLIFrameElement>;
|
|
194
183
|
id?: string;
|
|
195
184
|
onMessageReceived?: (senderWindow: Window | null, message: Message, panelId: string | null, dispatch: MessageDispatcher, callCb: CallCbFunction, callbacksStore: MutableRefObject<Callbacks>) => void;
|
|
@@ -206,7 +195,7 @@ export interface IUsePanelMessengerOptions {
|
|
|
206
195
|
onGetPanelConfig?: (data: GetPanelConfigMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
|
|
207
196
|
onCloseFlapPanel?: () => void;
|
|
208
197
|
onExplorerViewChanged?: (data: ExplorerViewChangedMessage['data']) => void;
|
|
209
|
-
onViewConfigUpdate?: (data:
|
|
198
|
+
onViewConfigUpdate?: (data: ViewConfigUpdateMessage['data']) => void;
|
|
210
199
|
};
|
|
211
200
|
}
|
|
212
201
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC","sourcesContent":["import {type MutableRefObject, type RefObject, type ComponentProps, type Key, type JSXElementConstructor} from 'react';\nimport type * as z from 'zod/v4';\nimport {type KitNotification} from 'aristid-ds';\nimport {type IKitConfirmDialog} from 'aristid-ds/dist/Kit/Feedback/Modal/types';\nimport {type ToastedAlertProps} from 'aristid-ds/dist/Kit/Feedback/Alert/types';\nimport {\n type LibraryIdSchema,\n type WhereSchema,\n type PanelIdSchema,\n type PanelSchema,\n type PanelIFrameSchema,\n type FlapPanelIdSchema,\n type attributeExplorerPanelSchema,\n type baseExplorerPanelSchema,\n} from '_ui/hooks/useIFrameMessenger/schema';\nimport {type AnyPrimitive} from '@leav/utils';\nimport {type IRecordIdentity, type ITreeNodeWithRecord} from '_ui/types';\nimport {type SerializedView} from '_ui/components/Explorer/_types';\n\nexport const packetId = '__fromIframeMessenger';\n\nexport interface IEncodedMessage {\n payload: string;\n [packetId]: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ComponentPropsWithKey<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> =\n ComponentProps<T> & {\n key?: Key;\n };\n\nexport interface IMessageBase {\n __frameId?: string;\n __targetPanelId?: string;\n}\n\nexport type ModalConfirmMessage = IMessageBase & {\n type: 'modal-confirm';\n id: string;\n data: IKitConfirmDialog;\n overrides?: string[];\n};\n\nexport type AlertMessage = IMessageBase & {\n type: 'alert';\n id: string;\n data: ToastedAlertProps;\n overrides?: string[];\n};\n\nexport type NotificationMessage = IMessageBase & {\n type: 'notification';\n id: string;\n data: ComponentPropsWithKey<typeof KitNotification>;\n overrides?: string[];\n};\n\nexport type ChangeLanguageMessage = IMessageBase & {\n type: 'change-language';\n language: string;\n};\n\nexport type SimpleMessage = IMessageBase & {\n type: 'message';\n id: string;\n data: unknown;\n};\n\nexport type RegisterMessage = IMessageBase & {\n type: 'register';\n id: string;\n};\n\nexport type UnregisterMessage = IMessageBase & {\n type: 'unregister';\n id: string;\n};\n\nexport type IsRegisteredMessage = IMessageBase & {\n type: 'is-registered';\n id: string;\n};\n\nexport type Panel = z.infer<typeof PanelSchema>;\n\nexport type AttributeExplorerPanel = Panel &\n z.infer<typeof baseExplorerPanelSchema> &\n z.infer<typeof attributeExplorerPanelSchema>;\n\nexport type LibraryId = z.infer<typeof LibraryIdSchema>;\n\nexport type PanelId = z.infer<typeof PanelIdSchema>;\n\nexport type Where = z.infer<typeof WhereSchema>;\n\nexport type PanelIFrame = z.infer<typeof PanelIFrameSchema>;\n\ntype FlapPanelId = z.infer<typeof FlapPanelIdSchema>;\n\nexport type NavigateToPanelMessage = IMessageBase & {\n type: 'navigate-to-panel';\n data: {\n where: Where;\n libraryId: LibraryId;\n panelId?: PanelId;\n recordId?: string;\n flapRecordId?: string;\n flapLibraryId?: LibraryId;\n flapPanelId?: FlapPanelId;\n queryParams?: Record<string, string> & {\n redirectUrl?: string;\n formInitialValues?: Record<string, Array<AnyPrimitive | IRecordIdentity | ITreeNodeWithRecord>>;\n };\n };\n};\n\nexport type ClosePanelMessage = IMessageBase & {\n type: 'close-panel';\n data: {\n recordId: string;\n where: string;\n recordPanelId: string;\n };\n};\n\nexport type NavigateToIframeMessage = IMessageBase & {\n type: 'navigate-to-iframe';\n data: {\n panel: PanelIFrame;\n destination: {libraryId: LibraryId};\n where: Where;\n recordId: string;\n recordPanelId: string;\n };\n};\n\nexport type MessageToPanelMessage = IMessageBase & {\n type: 'message-to-panel';\n data: {\n type: string;\n target?: string;\n payload: unknown;\n };\n};\n\nexport type OpenFlapPanelMessage = IMessageBase & {\n type: 'open-flap-panel';\n data: {\n flapRecordId: string;\n flapLibraryId: LibraryId;\n flapPanelId: FlapPanelId;\n };\n};\n\nexport type CloseFlapPanelMessage = IMessageBase & {\n type: 'close-flap-panel';\n};\n\nexport type GetUrlMessage = IMessageBase & {\n type: 'get-url';\n id: string;\n data: {\n onGetUrl: (url: string) => void;\n flapParams?: {\n flapRecordId: string;\n flapLibraryId: LibraryId;\n flapPanelId: FlapPanelId;\n };\n panelParams?: {\n recordId: string;\n where: Where;\n recordPanelId: PanelId;\n };\n };\n overrides?: string[];\n};\n\nexport type GetPanelConfigMessage = IMessageBase & {\n type: 'get-panel-config';\n id: string;\n data: {\n panelId?: string;\n onGetPanelConfig: (data: PanelIFrame) => void;\n };\n overrides?: string[];\n};\n\nexport type ExplorerViewChangedMessage = IMessageBase & {\n type: 'explorer-view-changed';\n data: {\n serializedView: SerializedView;\n };\n};\n\nexport type ViewConfigUpdateMessage = IMessageBase & {\n type: 'view-config-update';\n data: {\n targetPanelId: string;\n serializedView: SerializedView;\n };\n};\n\nexport type MessageToParent =\n | ModalConfirmMessage\n | AlertMessage\n | NotificationMessage\n | SimpleMessage\n | RegisterMessage\n | UnregisterMessage\n | NavigateToPanelMessage\n | ClosePanelMessage\n | NavigateToIframeMessage\n | MessageToPanelMessage\n | OpenFlapPanelMessage\n | CloseFlapPanelMessage\n | GetUrlMessage\n | GetPanelConfigMessage\n | ExplorerViewChangedMessage;\n\nexport type MessageFromParent =\n | (IMessageBase & {\n type: 'on-call-callback';\n path: string;\n data: unknown;\n })\n | IsRegisteredMessage\n | ChangeLanguageMessage\n | ViewConfigUpdateMessage;\n\nexport type Message = MessageToParent | MessageFromParent;\n\nexport type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;\nexport type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;\n\nexport type CallCbFunction = (path: string, data: unknown, frameId: string) => void;\n\nexport type CallbackFunction = (...args: never[]) => void;\nexport type Callbacks = Record<string, Record<string, CallbackFunction>>;\n\nexport type MessageToPanelMessageHandler = (data: MessageToPanelMessage['data']['payload']) => void;\nexport type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) => void;\n\nexport type UnregisterHandlers = () => void;\nexport type RegisterHandlers = (\n iframeRef: RefObject<HTMLIFrameElement>,\n handlers: IUseIFrameMessengerOptions['handlers'],\n) => UnregisterHandlers;\nexport type RegisterNativePanelHandlers = (\n panelId: string,\n handlers: IUseIFrameMessengerOptions['handlers'],\n) => UnregisterHandlers;\nexport type DispatchToNativePanel = (panelId: string, message: Message) => void;\n\nexport interface IUseIFrameMessengerOptions {\n ref?: RefObject<HTMLIFrameElement>;\n id?: string;\n onMessageReceived?: (\n senderWindow: Window | null,\n message: Message,\n panelId: string | null,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n callbacksStore: MutableRefObject<Callbacks>,\n ) => void;\n handlers?: {\n onModalConfirm?: (\n data: ModalConfirmMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onAlert?: (data: AlertMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;\n onNotification?: (\n data: NotificationMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onMessage?: (data: unknown, id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;\n onNavigateToPanel?: (data: NavigateToPanelMessage['data']) => void;\n onClosePanel?: (data: ClosePanelMessage['data']) => void;\n onNavigateToIframe?: (data: NavigateToIframeMessage['data']) => void;\n onOpenFlapPanel?: (data: OpenFlapPanelMessage['data']) => void;\n onGetUrl?: (data: GetUrlMessage['data']) => void;\n onGetPanelConfig?: (\n data: GetPanelConfigMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onCloseFlapPanel?: () => void;\n onExplorerViewChanged?: (data: ExplorerViewChangedMessage['data']) => void;\n onViewConfigUpdate?: (data: ViewConfigUpdateMessage['data']) => void;\n };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AddMessageToPanelMessageHandler, type IUseIFrameMessengerOptions } from './types';
|
|
2
|
+
export { IUseIFrameMessengerOptions };
|
|
2
3
|
/**
|
|
3
4
|
* Core hook of the IFrameMessenger system. Registers a single `window.addEventListener('message')`
|
|
4
5
|
* and manages a registry of connected child frames.
|
|
@@ -11,12 +12,11 @@ import { type AddInternalEventHandler, type AddMessageToPanelMessageHandler, typ
|
|
|
11
12
|
* instead of being handled locally. Used by `IFrameMessengerProvider` to route messages to the correct
|
|
12
13
|
* per-iframe handlers without registering multiple listeners.
|
|
13
14
|
*/
|
|
14
|
-
export declare const
|
|
15
|
+
export declare const useIFrameMessenger: (options?: IUseIFrameMessengerOptions) => {
|
|
15
16
|
isRegistered: boolean;
|
|
16
17
|
unregister: () => void;
|
|
17
18
|
changeLangInAllFrames: (newLanguage: string) => void;
|
|
18
19
|
addPanelMessageHandler: AddMessageToPanelMessageHandler;
|
|
19
|
-
addInternalEventHandler: AddInternalEventHandler;
|
|
20
20
|
showModalConfirm: (data: import("./types").ModalConfirmMessage["data"]) => void;
|
|
21
21
|
showAlert: (data: import("./types").AlertMessage["data"]) => void;
|
|
22
22
|
showNotification: (data: import("./types").NotificationMessage["data"]) => void;
|
|
@@ -13,7 +13,7 @@ import { encodeMessage, decodeMessage, getExposedMethods, initClientHandlers } f
|
|
|
13
13
|
* instead of being handled locally. Used by `IFrameMessengerProvider` to route messages to the correct
|
|
14
14
|
* per-iframe handlers without registering multiple listeners.
|
|
15
15
|
*/
|
|
16
|
-
export const
|
|
16
|
+
export const useIFrameMessenger = (options) => {
|
|
17
17
|
const registry = useRef({});
|
|
18
18
|
const selfId = useRef(options?.id ?? window.crypto.randomUUID());
|
|
19
19
|
const [isRegistered, setIsRegistered] = useState(window === window.top);
|
|
@@ -27,16 +27,6 @@ export const usePanelMessenger = (options) => {
|
|
|
27
27
|
const panelMessageHandlerRegistry = useRef({});
|
|
28
28
|
const addPanelMessageHandler = (type, handler) => {
|
|
29
29
|
panelMessageHandlerRegistry.current[type] = handler;
|
|
30
|
-
return () => {
|
|
31
|
-
delete panelMessageHandlerRegistry.current[type];
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const internalEventRegistry = useRef({});
|
|
35
|
-
const addInternalEventHandler = (type, handler) => {
|
|
36
|
-
internalEventRegistry.current[type] = handler;
|
|
37
|
-
return () => {
|
|
38
|
-
delete internalEventRegistry.current[type];
|
|
39
|
-
};
|
|
40
30
|
};
|
|
41
31
|
const dispatch = useCallback((message, frameId) => {
|
|
42
32
|
if (window !== window.top) {
|
|
@@ -68,7 +58,6 @@ export const usePanelMessenger = (options) => {
|
|
|
68
58
|
unregister,
|
|
69
59
|
changeLangInAllFrames,
|
|
70
60
|
addPanelMessageHandler,
|
|
71
|
-
addInternalEventHandler,
|
|
72
61
|
});
|
|
73
62
|
const getPanelIdFromEvent = (event) => {
|
|
74
63
|
const iFrames = window.document.getElementsByTagName('iframe');
|
|
@@ -118,9 +107,6 @@ export const usePanelMessenger = (options) => {
|
|
|
118
107
|
if (message.type === 'change-language') {
|
|
119
108
|
setLang(message.language);
|
|
120
109
|
}
|
|
121
|
-
else if (internalEventRegistry.current[message.type]) {
|
|
122
|
-
internalEventRegistry.current[message.type](message.data);
|
|
123
|
-
}
|
|
124
110
|
else if (options?.onMessageReceived) {
|
|
125
111
|
// Singleton mode: delegate routing to the Provider (IFrameMessengerProvider).
|
|
126
112
|
// The Provider resolves which iframe sent the message and calls the matching handlers.
|
|
@@ -151,4 +137,4 @@ export const usePanelMessenger = (options) => {
|
|
|
151
137
|
isRegistered,
|
|
152
138
|
};
|
|
153
139
|
};
|
|
154
|
-
//# sourceMappingURL=
|
|
140
|
+
//# sourceMappingURL=useIFrameMessenger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIFrameMessenger.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AASzC,OAAO,EAAC,aA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C3D,MAAM,eAAe,GACjB,OAAO,CAAC,IAAI,KAAK,kBAAkB;4BAC/B,CAAC,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,EAAC,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,EAAC,EAAC;4BAC5E,CAAC,CAAC,OAAO,CAAC;wBAClB,cAAc,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;oBAC9C,CAAC;oBACD,MAAM;YACd,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,IAAI,MAAM,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;YACxB,qDAAqD;YACrD,QAAQ,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,EAAC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,GAAG,EAAE;YACR,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACH,GAAG,OAAO,CAAC,OAAO;QAClB,YAAY;KACf,CAAC;AACN,CAAC,CAAC","sourcesContent":["import {useCallback, useContext, useEffect, useRef, useState} from 'react';\nimport {LangContext} from '_ui/contexts';\nimport {\n type AddMessageToPanelMessageHandler,\n type MessageToPanelMessageHandler,\n type Callbacks,\n type CallCbFunction,\n type IUseIFrameMessengerOptions,\n type MessageDispatcher,\n} from './types';\nimport {encodeMessage, decodeMessage, getExposedMethods, initClientHandlers} from './messageHandlers';\n\nexport {IUseIFrameMessengerOptions};\n\n/**\n * Core hook of the IFrameMessenger system. Registers a single `window.addEventListener('message')`\n * and manages a registry of connected child frames.\n *\n * **Usage:**\n * - Top-level apps (e.g. app-studio): use via `IFrameMessengerProvider` which calls this hook once as a singleton.\n * - Client apps (child iframes): use `useIFrameMessengerClient` instead.\n *\n * **`onMessageReceived` option:** when provided, all non-system messages are delegated to this callback\n * instead of being handled locally. Used by `IFrameMessengerProvider` to route messages to the correct\n * per-iframe handlers without registering multiple listeners.\n */\nexport const useIFrameMessenger = (options?: IUseIFrameMessengerOptions) => {\n const registry = useRef<Record<string, Window>>({});\n const selfId = useRef(options?.id ?? window.crypto.randomUUID());\n const [isRegistered, setIsRegistered] = useState(window === window.top);\n\n const {setLang} = useContext(LangContext);\n\n const changeLangInAllFrames = (newLanguage: string) => {\n dispatch(\n {\n type: 'change-language',\n language: newLanguage,\n },\n 'all',\n );\n };\n\n const panelMessageHandlerRegistry = useRef<Record<string, MessageToPanelMessageHandler>>({});\n const addPanelMessageHandler: AddMessageToPanelMessageHandler = (\n type: string,\n handler: MessageToPanelMessageHandler,\n ) => {\n panelMessageHandlerRegistry.current[type] = handler;\n };\n\n const dispatch = useCallback<MessageDispatcher>(\n (message, frameId) => {\n if (window !== window.top) {\n window.parent.postMessage(encodeMessage({...message, __frameId: selfId.current}), '*');\n } else if (frameId && registry.current[frameId]) {\n (registry.current[frameId] as Window).postMessage(\n encodeMessage({...message, __frameId: selfId.current}),\n '*',\n );\n } else if (frameId === 'all') {\n Object.entries(registry.current).forEach(([id, frame]) => {\n if (id !== message.__frameId) {\n // DO not send the message to the sender\n frame.postMessage(encodeMessage({...message, __frameId: selfId.current}), '*');\n }\n });\n }\n },\n [registry.current],\n );\n\n const callCb = useCallback<CallCbFunction>(\n (path, data, frameId) => {\n dispatch({type: 'on-call-callback', path, data}, frameId);\n },\n [dispatch],\n );\n\n const unregister = () => {\n if (window !== window.top) {\n dispatch({type: 'unregister', id: selfId.current});\n }\n };\n\n const callbacksStore = useRef<Callbacks>({});\n const methods = useRef({\n ...getExposedMethods(callbacksStore, dispatch),\n unregister,\n changeLangInAllFrames,\n addPanelMessageHandler,\n });\n\n const getPanelIdFromEvent = (event: MessageEvent) => {\n const iFrames = window.document.getElementsByTagName('iframe');\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < iFrames.length; i++) {\n if (event.source === iFrames[i].contentWindow) {\n return iFrames[i].name;\n }\n }\n return null;\n };\n\n useEffect(() => {\n const clientHandlers = initClientHandlers(callCb, {...options, id: selfId.current}, callbacksStore);\n const onMessage = (event: MessageEvent) => {\n const message = decodeMessage(event.data);\n if (message === undefined) {\n return;\n }\n switch (message.type) {\n case 'register':\n const frames = window.frames;\n // Due to weak typing on Window, we cannot iterate directly on window.frames\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < frames.length; i++) {\n if (event.source === frames[i]) {\n registry.current[message.id] = frames[i];\n }\n }\n\n dispatch({type: 'is-registered', id: message.id}, message.id);\n break;\n case 'unregister':\n if (registry.current[message.id]) {\n delete registry.current[message.id];\n }\n break;\n case 'is-registered':\n setIsRegistered(true);\n break;\n case 'message-to-panel':\n panelMessageHandlerRegistry.current[message.data.type]?.(message.data.payload);\n if (window === window.top) {\n const target = message.data.target ?? 'all';\n dispatch(message, target);\n }\n break;\n default:\n if (message.type === 'change-language') {\n setLang(message.language);\n } else if (options?.onMessageReceived) {\n // Singleton mode: delegate routing to the Provider (IFrameMessengerProvider).\n // The Provider resolves which iframe sent the message and calls the matching handlers.\n options.onMessageReceived(\n event.source as Window,\n message,\n getPanelIdFromEvent(event),\n dispatch,\n callCb,\n callbacksStore,\n );\n } else {\n // Legacy / client mode: handle messages directly with local clientHandlers.\n // get-panel-config needs panelId enriched before dispatch.\n const enrichedMessage =\n message.type === 'get-panel-config'\n ? {...message, data: {...message.data, panelId: getPanelIdFromEvent(event)}}\n : message;\n clientHandlers(enrichedMessage, dispatch);\n }\n break;\n }\n };\n\n window.addEventListener('message', onMessage);\n\n if (window !== window.top) {\n // Register the message handler for the parent window\n dispatch({type: 'register', id: selfId.current});\n }\n\n return () => {\n window.removeEventListener('message', onMessage);\n };\n }, []);\n\n return {\n ...methods.current,\n isRegistered,\n };\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Singleton Provider for the IFrameMessenger system.
|
|
4
|
+
* Must be mounted once above all `PanelCustom` instances.
|
|
5
|
+
*
|
|
6
|
+
* Owns a single `window.addEventListener('message')` (via `useIFrameMessenger`)
|
|
7
|
+
* and routes incoming messages to the correct iframe's handlers using `handlersMap`.
|
|
8
|
+
*
|
|
9
|
+
* Each `PanelCustom` registers/deregisters its handlers via `useIFrameMessengerHandlers`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const IFrameMessengerProvider: ({ children }: {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}) => JSX.Element;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useMemo, useRef } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useIFrameMessenger } from './useIFrameMessenger';
|
|
4
4
|
import { encodeMessage, initClientHandlers } from './messageHandlers';
|
|
5
|
-
import {
|
|
5
|
+
import { IFrameMessengerContext } from './iFrameMessengerContext';
|
|
6
6
|
/**
|
|
7
|
-
* Singleton Provider for the
|
|
7
|
+
* Singleton Provider for the IFrameMessenger system.
|
|
8
8
|
* Must be mounted once above all `PanelCustom` instances.
|
|
9
9
|
*
|
|
10
|
-
* Owns a single `window.addEventListener('message')` (via `
|
|
11
|
-
* and routes incoming messages to the correct
|
|
10
|
+
* Owns a single `window.addEventListener('message')` (via `useIFrameMessenger`)
|
|
11
|
+
* and routes incoming messages to the correct iframe's handlers using `handlersMap`.
|
|
12
12
|
*
|
|
13
|
-
* Each `PanelCustom` registers/deregisters its handlers via `
|
|
13
|
+
* Each `PanelCustom` registers/deregisters its handlers via `useIFrameMessengerHandlers`.
|
|
14
14
|
*/
|
|
15
|
-
export const
|
|
15
|
+
export const IFrameMessengerProvider = ({ children }) => {
|
|
16
16
|
// Maps each iframe's RefObject to its set of handlers.
|
|
17
17
|
// Using RefObject as key (instead of Window) avoids timing issues: contentWindow
|
|
18
18
|
// may not be available yet when the iframe mounts and registers its handlers.
|
|
@@ -20,7 +20,7 @@ export const PanelMessengerProvider = ({ children }) => {
|
|
|
20
20
|
// Maps native React panel IDs to their handlers.
|
|
21
21
|
// Same-window postMessage is used as transport: __targetPanelId in the envelope routes to the right entry.
|
|
22
22
|
const nativePanelHandlersMap = useRef(new Map());
|
|
23
|
-
// Called by
|
|
23
|
+
// Called by useIFrameMessenger for every non-system message.
|
|
24
24
|
// Finds the handlers registered for the sender and dispatches the message to them.
|
|
25
25
|
const onMessageReceived = useCallback((senderWindow, message, panelId, dispatch, callCb, callbacksStore) => {
|
|
26
26
|
// event.source is null when the sender iframe was unmounted before the message
|
|
@@ -60,10 +60,7 @@ export const PanelMessengerProvider = ({ children }) => {
|
|
|
60
60
|
const clientHandlers = initClientHandlers(callCb, { handlers: matchedHandlers }, callbacksStore);
|
|
61
61
|
clientHandlers(enrichedMessage, dispatch);
|
|
62
62
|
}, []);
|
|
63
|
-
const { changeLangInAllFrames
|
|
64
|
-
const dispatchToSelf = useCallback((message) => {
|
|
65
|
-
window.postMessage(encodeMessage(message), '*');
|
|
66
|
-
}, []);
|
|
63
|
+
const { changeLangInAllFrames } = useIFrameMessenger({ onMessageReceived });
|
|
67
64
|
const registerHandlers = useCallback((iframeRef, handlers) => {
|
|
68
65
|
handlersMap.current.set(iframeRef, handlers);
|
|
69
66
|
return () => handlersMap.current.delete(iframeRef);
|
|
@@ -75,14 +72,7 @@ export const PanelMessengerProvider = ({ children }) => {
|
|
|
75
72
|
const dispatchToNativePanel = useCallback((panelId, message) => {
|
|
76
73
|
window.postMessage(encodeMessage({ ...message, __targetPanelId: panelId }), '*');
|
|
77
74
|
}, []);
|
|
78
|
-
const contextValue = useMemo(() => ({
|
|
79
|
-
|
|
80
|
-
registerNativePanelHandlers,
|
|
81
|
-
dispatchToNativePanel,
|
|
82
|
-
changeLangInAllFrames,
|
|
83
|
-
addInternalEventHandler,
|
|
84
|
-
dispatchToSelf,
|
|
85
|
-
}), []);
|
|
86
|
-
return _jsx(PanelMessengerContext.Provider, { value: contextValue, children: children });
|
|
75
|
+
const contextValue = useMemo(() => ({ registerHandlers, registerNativePanelHandlers, dispatchToNativePanel, changeLangInAllFrames }), []);
|
|
76
|
+
return _jsx(IFrameMessengerContext.Provider, { value: contextValue, children: children });
|
|
87
77
|
};
|
|
88
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=useIFrameMessengerContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAwD,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC1G,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAUpE,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EAAC,QAAQ,EAAwB,EAAE,EAAE;IACzE,uDAAuD;IACvD,iFAAiF;IACjF,8EAA8E;IAC9E,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,EAAwE,CAAC,CAAC;IAE5G,iDAAiD;IACjD,2GAA2G;IAC3G,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAkD,CAAC,CAAC;IAEjG,6DAA6D;IAC7D,mFAAmF;IACnF,MAAM,iBAAiB,GAAG,WAAW,CACjC,CACI,YAA2B,EAC3B,OAAgB,EAChB,OAAsB,EACtB,QAA2B,EAC3B,MAAsB,EACtB,cAA2C,EAC7C,EAAE;QACA,+EAA+E;QAC/E,sEAAsE;QACtE,IAAI,CAAC,YAAY,EAAE,CAA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IFrameMessenger';\nimport {encodeMessage, initClientHandlers} from './messageHandlers';\nimport {\n type Callbacks,\n type CallCbFunction,\n type Message,\n type MessageDispatcher,\n type IUseIFrameMessengerOptions,\n type RegisterHandlers,\n type RegisterNativePanelHandlers,\n} from './types';\nimport {IFrameMessengerContext} from './iFrameMessengerContext';\n\n/**\n * Singleton Provider for the IFrameMessenger system.\n * Must be mounted once above all `PanelCustom` instances.\n *\n * Owns a single `window.addEventListener('message')` (via `useIFrameMessenger`)\n * and routes incoming messages to the correct iframe's handlers using `handlersMap`.\n *\n * Each `PanelCustom` registers/deregisters its handlers via `useIFrameMessengerHandlers`.\n */\nexport const IFrameMessengerProvider = ({children}: {children: ReactNode}) => {\n // Maps each iframe's RefObject to its set of handlers.\n // Using RefObject as key (instead of Window) avoids timing issues: contentWindow\n // may not be available yet when the iframe mounts and registers its handlers.\n const handlersMap = useRef(new Map<RefObject<HTMLIFrameElement>, IUseIFrameMessengerOptions['handlers']>());\n\n // Maps native React panel IDs to their handlers.\n // Same-window postMessage is used as transport: __targetPanelId in the envelope routes to the right entry.\n const nativePanelHandlersMap = useRef(new Map<string, IUseIFrameMessengerOptions['handlers']>());\n\n // Called by useIFrameMessenger for every non-system message.\n // Finds the handlers registered for the sender and dispatches the message to them.\n const onMessageReceived = useCallback(\n (\n senderWindow: Window | null,\n message: Message,\n panelId: string | null,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n callbacksStore: MutableRefObject<Callbacks>,\n ) => {\n // event.source is null when the sender iframe was unmounted before the message\n // was processed — the browser clears the reference on iframe removal.\n if (!senderWindow) {\n return;\n }\n\n // Same-window message: dispatched via dispatchToNativePanel.\n // Route to the native panel identified by __targetPanelId.\n if (senderWindow === window) {\n const targetPanelId = message.__targetPanelId;\n if (!targetPanelId) {\n return;\n }\n const handlers = nativePanelHandlersMap.current.get(targetPanelId);\n if (!handlers) {\n return;\n }\n const clientHandlers = initClientHandlers(callCb, {handlers}, callbacksStore);\n clientHandlers(message, dispatch);\n return;\n }\n\n let matchedHandlers: IUseIFrameMessengerOptions['handlers'] | undefined;\n for (const [ref, handlers] of handlersMap.current) {\n if (ref.current?.contentWindow === senderWindow) {\n matchedHandlers = handlers;\n break;\n }\n }\n\n // No registered handlers for this sender: either the iframe called unregisterHandlers\n // before its last message was processed (race condition on unmount), or the message\n // originates from an unrelated frame that passed decodeMessage validation.\n if (!matchedHandlers) {\n return;\n }\n\n const enrichedMessage =\n message.type === 'get-panel-config' ? {...message, data: {...message.data, panelId}} : message;\n\n const clientHandlers = initClientHandlers(callCb, {handlers: matchedHandlers}, callbacksStore);\n clientHandlers(enrichedMessage, dispatch);\n },\n [],\n );\n\n const {changeLangInAllFrames} = useIFrameMessenger({onMessageReceived});\n\n const registerHandlers: RegisterHandlers = useCallback((iframeRef, handlers) => {\n handlersMap.current.set(iframeRef, handlers);\n return () => handlersMap.current.delete(iframeRef);\n }, []);\n\n const registerNativePanelHandlers: RegisterNativePanelHandlers = useCallback((panelId, handlers) => {\n nativePanelHandlersMap.current.set(panelId, handlers);\n return () => nativePanelHandlersMap.current.delete(panelId);\n }, []);\n\n const dispatchToNativePanel = useCallback((panelId: string, message: Message) => {\n window.postMessage(encodeMessage({...message, __targetPanelId: panelId}), '*');\n }, []);\n\n const contextValue = useMemo(\n () => ({registerHandlers, registerNativePanelHandlers, dispatchToNativePanel, changeLangInAllFrames}),\n [],\n );\n\n return <IFrameMessengerContext.Provider value={contextValue}>{children}</IFrameMessengerContext.Provider>;\n};\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type RefObject } from 'react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type IUseIFrameMessengerOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Per-iframe hook for `PanelCustom`. Registers the iframe's handlers into the singleton
|
|
5
|
-
* `
|
|
5
|
+
* `IFrameMessengerProvider` and cleans them up on unmount.
|
|
6
6
|
*
|
|
7
7
|
* Returns `changeLangInFrame` which posts `change-language` directly to this specific iframe's
|
|
8
8
|
* `contentWindow` — intentionally NOT using the shared registry to avoid broadcasting the language
|
|
9
9
|
* change to all other open iframes (which would cause unintended refreshes).
|
|
10
10
|
*/
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const useIFrameMessengerHandlers: (iframeRef: RefObject<HTMLIFrameElement>, handlers: IUseIFrameMessengerOptions["handlers"]) => {
|
|
12
12
|
changeLangInFrame: (language: string) => void;
|
|
13
13
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useCallback, useContext, useEffect } from 'react';
|
|
2
|
+
import { IFrameMessengerContext } from './iFrameMessengerContext';
|
|
2
3
|
import { encodeMessage } from './messageHandlers';
|
|
3
|
-
import { PanelMessengerContext } from '../../hooks/usePanelMessenger/panelMessengerContext';
|
|
4
4
|
/**
|
|
5
5
|
* Per-iframe hook for `PanelCustom`. Registers the iframe's handlers into the singleton
|
|
6
|
-
* `
|
|
6
|
+
* `IFrameMessengerProvider` and cleans them up on unmount.
|
|
7
7
|
*
|
|
8
8
|
* Returns `changeLangInFrame` which posts `change-language` directly to this specific iframe's
|
|
9
9
|
* `contentWindow` — intentionally NOT using the shared registry to avoid broadcasting the language
|
|
10
10
|
* change to all other open iframes (which would cause unintended refreshes).
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
13
|
-
const { registerHandlers } = useContext(
|
|
12
|
+
export const useIFrameMessengerHandlers = (iframeRef, handlers) => {
|
|
13
|
+
const { registerHandlers } = useContext(IFrameMessengerContext);
|
|
14
14
|
// Register on mount, deregister on unmount via the returned cleanup function.
|
|
15
15
|
useEffect(() => registerHandlers(iframeRef, handlers), []);
|
|
16
16
|
// Post directly to contentWindow instead of going through the registry,
|
|
@@ -23,4 +23,4 @@ export const usePanelIFrameHandlers = (iframeRef, handlers) => {
|
|
|
23
23
|
}, [iframeRef]);
|
|
24
24
|
return { changeLangInFrame };
|
|
25
25
|
};
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=useIFrameMessengerHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIFrameMessengerHandlers.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAiB,MAAM,OAAO,CAAC;AACzE,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACtC,SAAuC,EACvC,QAAgD,EAClD,EAAE;IACA,MAAM,EAAC,gBAAgB,EAAC,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAE9D,8EAA8E;IAC9E,SAAS,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3D,wEAAwE;IACxE,mDAAmD;IACnD,MAAM,iBAAiB,GAAG,WAAW,CACjC,CAAC,QAAgB,EAAE,EAAE;QACjB,IAAI,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;YACnC,MAAM,OAAO,GAA0B,EAAC,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAC,CAAC;YAC3E,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC,EACD,CAAC,SAAS,CAAC,CACd,CAAC;IAEF,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["import {useCallback, useContext, useEffect, type RefObject} from 'react';\nimport {IFrameMessengerContext} from './iFrameMessengerContext';\nimport {encodeMessage} from './messageHandlers';\nimport {type ChangeLanguageMessage, type IUseIFrameMessengerOptions} from './types';\n\n/**\n * Per-iframe hook for `PanelCustom`. Registers the iframe's handlers into the singleton\n * `IFrameMessengerProvider` and cleans them up on unmount.\n *\n * Returns `changeLangInFrame` which posts `change-language` directly to this specific iframe's\n * `contentWindow` — intentionally NOT using the shared registry to avoid broadcasting the language\n * change to all other open iframes (which would cause unintended refreshes).\n */\nexport const useIFrameMessengerHandlers = (\n iframeRef: RefObject<HTMLIFrameElement>,\n handlers: IUseIFrameMessengerOptions['handlers'],\n) => {\n const {registerHandlers} = useContext(IFrameMessengerContext);\n\n // Register on mount, deregister on unmount via the returned cleanup function.\n useEffect(() => registerHandlers(iframeRef, handlers), []);\n\n // Post directly to contentWindow instead of going through the registry,\n // which would broadcast to all registered iframes.\n const changeLangInFrame = useCallback(\n (language: string) => {\n if (iframeRef.current?.contentWindow) {\n const message: ChangeLanguageMessage = {type: 'change-language', language};\n iframeRef.current.contentWindow.postMessage(encodeMessage(message), '*');\n }\n },\n [iframeRef],\n );\n\n return {changeLangInFrame};\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type IUseIFrameMessengerOptions, type Message } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Per-panel hook for native React panels (non-iframe).
|
|
4
|
+
* Registers the panel's handlers into the singleton `IFrameMessengerProvider`
|
|
5
|
+
* and cleans them up on unmount.
|
|
6
|
+
*
|
|
7
|
+
* Uses same-window `window.postMessage` as transport, routed via `__targetPanelId`
|
|
8
|
+
* in the message envelope — same protocol as iframe panels, no postMessage cross-origin.
|
|
9
|
+
*
|
|
10
|
+
* Returns `dispatch` to send messages to another panel by its ID.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useNativePanelMessengerHandlers: (panelId: string, handlers: IUseIFrameMessengerOptions["handlers"]) => {
|
|
13
|
+
dispatch: (targetPanelId: string, message: Message) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect } from 'react';
|
|
2
|
+
import { IFrameMessengerContext } from './iFrameMessengerContext';
|
|
3
|
+
/**
|
|
4
|
+
* Per-panel hook for native React panels (non-iframe).
|
|
5
|
+
* Registers the panel's handlers into the singleton `IFrameMessengerProvider`
|
|
6
|
+
* and cleans them up on unmount.
|
|
7
|
+
*
|
|
8
|
+
* Uses same-window `window.postMessage` as transport, routed via `__targetPanelId`
|
|
9
|
+
* in the message envelope — same protocol as iframe panels, no postMessage cross-origin.
|
|
10
|
+
*
|
|
11
|
+
* Returns `dispatch` to send messages to another panel by its ID.
|
|
12
|
+
*/
|
|
13
|
+
export const useNativePanelMessengerHandlers = (panelId, handlers) => {
|
|
14
|
+
const { registerNativePanelHandlers, dispatchToNativePanel } = useContext(IFrameMessengerContext);
|
|
15
|
+
useEffect(() => registerNativePanelHandlers(panelId, handlers), []);
|
|
16
|
+
const dispatch = useCallback((targetPanelId, message) => dispatchToNativePanel(targetPanelId, message), [dispatchToNativePanel]);
|
|
17
|
+
return { dispatch };
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useNativePanelMessengerHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNativePanelMessengerHandlers.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AACzD,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAGhE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,OAAe,EAAE,QAAgD,EAAE,EAAE;IACjH,MAAM,EAAC,2BAA2B,EAAE,qBAAqB,EAAC,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAEhG,SAAS,CAAC,GAAG,EAAE,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpE,MAAM,QAAQ,GAAG,WAAW,CACxB,CAAC,aAAqB,EAAE,OAAgB,EAAE,EAAE,CAAC,qBAAqB,CAAC,aAAa,EAAE,OAAO,CAAC,EAC1F,CAAC,qBAAqB,CAAC,CAC1B,CAAC;IAEF,OAAO,EAAC,QAAQ,EAAC,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import {useCallback, useContext, useEffect} from 'react';\nimport {IFrameMessengerContext} from './iFrameMessengerContext';\nimport {type IUseIFrameMessengerOptions, type Message} from './types';\n\n/**\n * Per-panel hook for native React panels (non-iframe).\n * Registers the panel's handlers into the singleton `IFrameMessengerProvider`\n * and cleans them up on unmount.\n *\n * Uses same-window `window.postMessage` as transport, routed via `__targetPanelId`\n * in the message envelope — same protocol as iframe panels, no postMessage cross-origin.\n *\n * Returns `dispatch` to send messages to another panel by its ID.\n */\nexport const useNativePanelMessengerHandlers = (panelId: string, handlers: IUseIFrameMessengerOptions['handlers']) => {\n const {registerNativePanelHandlers, dispatchToNativePanel} = useContext(IFrameMessengerContext);\n\n useEffect(() => registerNativePanelHandlers(panelId, handlers), []);\n\n const dispatch = useCallback(\n (targetPanelId: string, message: Message) => dispatchToNativePanel(targetPanelId, message),\n [dispatchToNativePanel],\n );\n\n return {dispatch};\n};\n"]}
|
|
@@ -3,5 +3,5 @@ interface IFrameMessengerClientProps {
|
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
id?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const IFrameMessengerClient: FunctionComponent<IFrameMessengerClientProps>;
|
|
7
7
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useIFrameMessenger } from '../useIFrameMessenger/useIFrameMessenger';
|
|
4
|
+
import { IframeMessengerClientContext } from './iFrameMessengerClientContext';
|
|
5
|
+
export const IFrameMessengerClient = ({ children, id }) => {
|
|
6
|
+
const iFrameMessenger = useIFrameMessenger({ id });
|
|
7
|
+
useEffect(() => () => iFrameMessenger.unregister(), []);
|
|
8
|
+
if (!iFrameMessenger.isRegistered) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return (_jsx(IframeMessengerClientContext.Provider, { value: iFrameMessenger, children: children }));
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=IFrameMessengerClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFrameMessengerClient.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessengerClient/IFrameMessengerClient.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAyC,SAAS,EAAC,MAAM,OAAO,CAAC;AACxE,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAC,4BAA4B,EAAC,MAAM,gCAAgC,CAAC;AAO5E,MAAM,CAAC,MAAM,qBAAqB,GAAkD,CAAC,EAAC,QAAQ,EAAE,EAAE,EAAC,EAAE,EAAE;IACnG,MAAM,eAAe,GAAG,kBAAkB,CAAC,EAAC,EAAE,EAAC,CAAC,CAAC;IAEjD,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAExD,IAAI,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,CACH,KAAC,4BAA4B,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,YACxD,QAAQ,GAC2B,CAC3C,CAAC;AACN,CAAC,CAAC","sourcesContent":["import {type FunctionComponent, type ReactNode, useEffect} from 'react';\nimport {useIFrameMessenger} from '../useIFrameMessenger/useIFrameMessenger';\nimport {IframeMessengerClientContext} from './iFrameMessengerClientContext';\n\ninterface IFrameMessengerClientProps {\n children: ReactNode;\n id?: string;\n}\n\nexport const IFrameMessengerClient: FunctionComponent<IFrameMessengerClientProps> = ({children, id}) => {\n const iFrameMessenger = useIFrameMessenger({id});\n\n useEffect(() => () => iFrameMessenger.unregister(), []);\n\n if (!iFrameMessenger.isRegistered) {\n return null;\n }\n\n return (\n <IframeMessengerClientContext.Provider value={iFrameMessenger}>\n {children}\n </IframeMessengerClientContext.Provider>\n );\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const IframeMessengerClientContext: import("react").Context<{
|
|
2
|
+
isRegistered: boolean;
|
|
3
|
+
unregister: () => void;
|
|
4
|
+
changeLangInAllFrames: (newLanguage: string) => void;
|
|
5
|
+
addPanelMessageHandler: import("../useIFrameMessenger/types").AddMessageToPanelMessageHandler;
|
|
6
|
+
showModalConfirm: (data: import("../useIFrameMessenger/types").ModalConfirmMessage["data"]) => void;
|
|
7
|
+
showAlert: (data: import("../useIFrameMessenger/types").AlertMessage["data"]) => void;
|
|
8
|
+
showNotification: (data: import("../useIFrameMessenger/types").NotificationMessage["data"]) => void;
|
|
9
|
+
messageToParent: (data: import("../useIFrameMessenger/types").SimpleMessage["data"]) => void;
|
|
10
|
+
navigateToPanel: (data: import("../useIFrameMessenger/types").NavigateToPanelMessage["data"]) => void;
|
|
11
|
+
closePanel: (data: import("../useIFrameMessenger/types").ClosePanelMessage["data"]) => void;
|
|
12
|
+
navigateToIframe: (data: import("../useIFrameMessenger/types").NavigateToIframeMessage["data"]) => void;
|
|
13
|
+
messageToPanel: (data: import("../useIFrameMessenger/types").MessageToPanelMessage["data"]) => void;
|
|
14
|
+
openFlapPanel: (data: import("../useIFrameMessenger/types").OpenFlapPanelMessage["data"]) => void;
|
|
15
|
+
closeFlapPanel: () => void;
|
|
16
|
+
getPanelConfig: (data: import("../useIFrameMessenger/types").GetPanelConfigMessage["data"]) => void;
|
|
17
|
+
getUrl: (data: import("../useIFrameMessenger/types").GetUrlMessage["data"]) => void;
|
|
18
|
+
explorerViewChanged: (data: import("../useIFrameMessenger/types").ExplorerViewChangedMessage["data"]) => void;
|
|
19
|
+
}>;
|