@leav/ui 1.11.0 → 1.12.0-046f71f9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/_gqlTypes/index.d.ts +40 -61
  2. package/dist/_gqlTypes/index.js +12 -5
  3. package/dist/_gqlTypes/index.js.map +1 -1
  4. package/dist/_queries/attributes/attributeDetailsFragment.js +3 -0
  5. package/dist/_queries/attributes/attributeDetailsFragment.js.map +1 -1
  6. package/dist/components/Explorer/DataView.js +22 -11
  7. package/dist/components/Explorer/DataView.js.map +1 -1
  8. package/dist/components/Explorer/Explorer.js +3 -2
  9. package/dist/components/Explorer/Explorer.js.map +1 -1
  10. package/dist/components/Explorer/TableNameCell.js +1 -4
  11. package/dist/components/Explorer/TableNameCell.js.map +1 -1
  12. package/dist/components/Explorer/actions-mass/ResultsCount.js +2 -2
  13. package/dist/components/Explorer/actions-mass/ResultsCount.js.map +1 -1
  14. package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js +14 -6
  15. package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js.map +1 -1
  16. package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js +6 -4
  17. package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js.map +1 -1
  18. package/dist/components/Filters/_types.d.ts +3 -0
  19. package/dist/components/Filters/_types.js.map +1 -1
  20. package/dist/components/Filters/context/filtersReducer.js +14 -1
  21. package/dist/components/Filters/context/filtersReducer.js.map +1 -1
  22. package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js +11 -0
  23. package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js.map +1 -1
  24. package/dist/components/Filters/filter-items/filter-type/tree/utils/countSelectedTreeChildren.d.ts +2 -0
  25. package/dist/components/Filters/filter-items/filter-type/tree/utils/countSelectedTreeChildren.js +10 -0
  26. package/dist/components/Filters/filter-items/filter-type/tree/utils/countSelectedTreeChildren.js.map +1 -0
  27. package/dist/components/Filters/useFilters.d.ts +198 -0
  28. package/dist/components/Filters/useTransformFilters.js +4 -2
  29. package/dist/components/Filters/useTransformFilters.js.map +1 -1
  30. package/dist/hooks/index.d.ts +2 -0
  31. package/dist/hooks/index.js +2 -0
  32. package/dist/hooks/index.js.map +1 -1
  33. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.d.ts +6 -0
  34. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js +8 -0
  35. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js.map +1 -0
  36. package/dist/hooks/useIFrameMessenger/types.d.ts +10 -3
  37. package/dist/hooks/useIFrameMessenger/types.js.map +1 -1
  38. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.d.ts +11 -2
  39. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js +25 -13
  40. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js.map +1 -1
  41. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.d.ts +13 -0
  42. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js +59 -0
  43. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js.map +1 -0
  44. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.d.ts +13 -0
  45. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js +29 -0
  46. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js.map +1 -0
  47. package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js +3 -0
  48. package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js.map +1 -1
  49. package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.d.ts +1 -0
  50. package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.d.ts +1 -0
  51. package/package.json +10 -10
@@ -1 +1 @@
1
- {"version":3,"file":"useTransformFilters.js","sourceRoot":"","sources":["../../../src/components/Filters/useTransformFilters.tsx"],"names":[],"mappings":"AAAA,oF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C,MAAM,CAAC,KAAK,CAAC;oBAChB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;wBACzB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;wBACnD,CAAC,CAAC,SAAS;gBACjB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACf,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;wBACzB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC,CAAC;wBAC3F,CAAC,CAAC,SAAS;gBACjB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK;gBAC9B,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;gBAC9B,SAAS,EAAE;oBACP,GAAG,mBAAmB;oBACtB,UAAU,EAAE,aAAa,CAAC,WAAY;iBACzC;gBACD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,qBAAqB,CAAC,KAAK;gBAC1D,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,KAAK;aACnD,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;IAEX,OAAO;QACH,cAAc;QACd,WAAW;KACd,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {\n type AttributeDetailsLinkAttributeFragment,\n type AttributeDetailsTreeAttributeFragment,\n AttributeFormat,\n AttributeType,\n type ExplorerAttributesQuery,\n type ExplorerLinkAttributeQuery,\n type GetViewsListQuery,\n type LinkAttributeDetailsFragment,\n RecordFilterCondition,\n type StandardAttributeDetailsFragment,\n type ViewDetailsFilterFragment,\n} from '_ui/_gqlTypes';\nimport {\n type UIFilter,\n type IUIFilterBaseAttribute,\n type IUIFilterLink,\n type IUIFilterLinkValueList,\n type IUIFilterStandard,\n type IUIFilterStandardValueList,\n type IUIFilterThrough,\n type IUIFilterTree,\n type ValidFieldFilter,\n type ValidFieldFilterLinkValuesList,\n type ValidFieldFilterStandardValuesList,\n type ValidFieldFilterThrough,\n type ValidFilter,\n} from './_types';\nimport {ThroughConditionFilter} from '_ui/types';\nimport {isLinkAttribute, isStandardAttribute, isTreeAttribute} from '_ui/_utils/attributeType';\nimport {localizedTranslation} from '@leav/utils';\nimport {useLang} from '_ui/hooks';\nimport {valueListTextConditions} from './filter-items/filter-type/useConditionOptionsByType';\nimport dayjs from 'dayjs';\nimport {type TFunction} from 'i18next';\nimport {type ITreeFilters} from './context/useGetTreeFilters';\n\nconst _isValidFieldFilter = (filter: ViewDetailsFilterFragment | UIFilter): filter is ValidFieldFilter =>\n !!filter.field;\n\nconst _isValidFieldFilterThrough = (filter: ValidFilter): filter is ValidFieldFilterThrough =>\n filter.condition === ThroughConditionFilter.THROUGH && !!filter.subCondition && !!filter.subField;\n\nconst _isValidFieldFilterStandardValuesList = (\n filter: ValidFilter,\n attribute: NonNullable<ExplorerAttributesQuery['attributes']>['list'][number],\n): filter is ValidFieldFilterStandardValuesList & {attribute: StandardAttributeDetailsFragment} =>\n valueListTextConditions.includes(filter.condition) &&\n [AttributeType.simple, AttributeType.advanced].includes(attribute.type) &&\n 'valuesList' in attribute &&\n !!attribute.valuesList?.enable;\n\nconst _isValidFieldFilterLinkValuesList = (\n filter: ValidFilter,\n attribute: NonNullable<ExplorerAttributesQuery['attributes']>['list'][number],\n): filter is ValidFieldFilterLinkValuesList & {attribute: LinkAttributeDetailsFragment} =>\n valueListTextConditions.includes(filter.condition) &&\n [AttributeType.simple_link, AttributeType.advanced_link].includes(attribute.type) &&\n 'valuesList' in attribute &&\n !!attribute.valuesList?.enable;\n\ntype AttributeDetailsLinkAttributeWithPermissionsFragment = AttributeDetailsLinkAttributeFragment & {\n permissions: {\n access_attribute: boolean;\n };\n};\ntype AttributeDetailsTreeAttributeWithPermissionsFragment = AttributeDetailsTreeAttributeFragment & {\n permissions: {\n access_attribute: boolean;\n };\n};\n\nexport const isLinkAttributeDetails = (\n linkAttributeData: NonNullable<ExplorerLinkAttributeQuery['attributes']>['list'][number],\n): linkAttributeData is LinkAttributeDetailsFragment & {\n id: string;\n multiple_values: boolean;\n permissions: {\n access_attribute: boolean;\n edit_value: boolean;\n };\n} => 'linked_library' in linkAttributeData;\n\nexport type ValidFiltersArgument = GetViewsListQuery['views']['list'][number]['filters'] | UIFilter[];\n\nexport type AttributesById = Record<string, NonNullable<ExplorerAttributesQuery['attributes']>['list'][number]>;\n\nexport const useTransformFilters = () => {\n const {lang} = useLang();\n\n const toValidFilters = (filters: ValidFiltersArgument): ValidFilter[] =>\n (filters ?? []).reduce<ValidFilter[]>((acc, filter) => {\n if (!_isValidFieldFilter(filter)) {\n return acc;\n }\n const _isThroughFilter = filter.field.includes('.');\n\n if (_isThroughFilter) {\n const [field, subField] = filter.field.split('.');\n const throughFilter: ValidFieldFilterThrough = {\n field,\n subField,\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n condition: ThroughConditionFilter.THROUGH,\n subCondition: filter.condition,\n };\n acc.push(throughFilter);\n } else {\n acc.push(filter);\n }\n\n return acc;\n }, []);\n\n const toUIFilters = ({\n filters,\n treeFilters,\n attributesDataById,\n t,\n }: {\n filters: ValidFilter[];\n treeFilters: ITreeFilters;\n attributesDataById: AttributesById;\n t: TFunction;\n }): UIFilter[] =>\n (filters ?? []).reduce<UIFilter[]>((acc, filter) => {\n if (!attributesDataById[filter.field]) {\n console.warn(`Attribute ${filter.field} from user view not found in database.`);\n return acc;\n }\n\n const filterAttributeBase: IUIFilterBaseAttribute = {\n id: attributesDataById[filter.field].id,\n label: localizedTranslation(attributesDataById[filter.field].label, lang),\n type: attributesDataById[filter.field].type,\n };\n\n // filter is standardFilter\n if (isStandardAttribute(filterAttributeBase.type)) {\n const attributeData = attributesDataById[filter.field];\n if (_isValidFieldFilterStandardValuesList(filter, attributeData)) {\n const newFilter: IUIFilterStandardValueList = {\n field: filter.field,\n // TODO : save filter values as string[] when filter and handle fields with libraries\n value: filter.value ? [filter.value] : [],\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: (filter.condition as RecordFilterCondition) ?? null,\n attribute: {\n ...filterAttributeBase,\n format: attributeData.format!,\n valuesList: (attributeData as StandardAttributeDetailsFragment).valuesList!,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n } else {\n let formattedValue: string;\n if (attributeData.format === AttributeFormat.boolean && filter.value) {\n formattedValue = filter.value === 'true' ? t('explorer.true') : t('explorer.false');\n }\n\n if (attributeData.format === AttributeFormat.date && filter.value) {\n formattedValue = dayjs(filter.value).format('YYYY-MM-DD');\n }\n\n const newFilter: IUIFilterStandard = {\n field: filter.field,\n value: filter.value ?? null,\n formattedValue,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: (filter.condition as RecordFilterCondition) ?? null,\n attribute: {\n ...filterAttributeBase,\n format: attributeData.format!,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n }\n }\n\n if (isLinkAttribute(filterAttributeBase.type)) {\n const attributeData = attributesDataById[\n filter.field\n ] as AttributeDetailsLinkAttributeWithPermissionsFragment;\n if (_isValidFieldFilterThrough(filter)) {\n const newFilter: IUIFilterThrough = {\n field: filter.field,\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n subCondition: filter.subCondition ?? null,\n subField: filter.subField,\n };\n acc.push(newFilter);\n } else if (_isValidFieldFilterLinkValuesList(filter, attributeData)) {\n const newFilter: IUIFilterLinkValueList = {\n field: filter.field,\n // TODO : save filter values as string[] when filter and handle fields with libraries\n value: filter.value ? [filter.value] : [],\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n valuesList: (attributeData as LinkAttributeDetailsFragment).valuesList!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n\n acc.push(newFilter);\n } else {\n const newFilter: IUIFilterLink = {\n field: filter.field,\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n };\n\n acc.push(newFilter);\n }\n }\n\n if (isTreeAttribute(filterAttributeBase.type) && !_isValidFieldFilterThrough(filter)) {\n const attributeData = attributesDataById[\n filter.field\n ] as AttributeDetailsTreeAttributeWithPermissionsFragment;\n const newFilter: IUIFilterTree = {\n field: [filter.field],\n // TODO : save filter values as string[] when tree filter and handle fields with libraries\n value: filter.value\n ? [filter.value]\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => tree.value)\n : null,\n formattedValue: filter.value\n ? [filter.value]\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => tree.label)\n : undefined,\n nodes: filter.value\n ? undefined\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => ({libraryId: tree.libraryId, nodeId: tree.nodeId}))\n : undefined,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n attribute: {\n ...filterAttributeBase,\n linkedTree: attributeData.linked_tree!,\n },\n condition: filter.condition ?? RecordFilterCondition.EQUAL,\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n }\n\n return acc;\n }, []);\n\n return {\n toValidFilters,\n toUIFilters,\n };\n};\n"]}
1
+ {"version":3,"file":"useTransformFilters.js","sourceRoot":"","sources":["../../../src/components/Filters/useTransformFilters.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAGH,eAAe,EACf,aAAa,EAKb,qBAAqB,GAGxB,MAAM,eAAe,CAAC;AAgBvB,OAAO,EAAC,sBAAsB,EAAC,MAAM,WAAW,CAAC;AACjD,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,uBAAuB,EAAC,MAAM,sDAAsD,CAAC;AAC7F,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,mBAAmB,GAAG,CAAC,MAA4C,EAA8B,EAAE,CACrG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAEnB,MAAM,0BAA0B,GAAG,CAAC,MAAmB,EAAqC,EAAE,CAC1F,MAAM,CAAC,SAAS,KAAK,sBAAsB,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;AAEtG,MAAM,qCAAqC,GAAG,CAC1C,MAAmB,EACnB,SAA6E,EACe,EAAE,CAC9F,uBAAuB,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;IAClD,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC;IACvE,YAAY,IAAI,SAAS;IACzB,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,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ACxB,CAAC;QAED,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;IAEX,OAAO;QACH,cAAc;QACd,WAAW;KACd,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {\n type AttributeDetailsLinkAttributeFragment,\n type AttributeDetailsTreeAttributeFragment,\n AttributeFormat,\n AttributeType,\n type ExplorerAttributesQuery,\n type ExplorerLinkAttributeQuery,\n type GetViewsListQuery,\n type LinkAttributeDetailsFragment,\n RecordFilterCondition,\n type StandardAttributeDetailsFragment,\n type ViewDetailsFilterFragment,\n} from '_ui/_gqlTypes';\nimport {\n type UIFilter,\n type IUIFilterBaseAttribute,\n type IUIFilterLink,\n type IUIFilterLinkValueList,\n type IUIFilterStandard,\n type IUIFilterStandardValueList,\n type IUIFilterThrough,\n type IUIFilterTree,\n type ValidFieldFilter,\n type ValidFieldFilterLinkValuesList,\n type ValidFieldFilterStandardValuesList,\n type ValidFieldFilterThrough,\n type ValidFilter,\n} from './_types';\nimport {ThroughConditionFilter} from '_ui/types';\nimport {isLinkAttribute, isStandardAttribute, isTreeAttribute} from '_ui/_utils/attributeType';\nimport {localizedTranslation} from '@leav/utils';\nimport {useLang} from '_ui/hooks';\nimport {valueListTextConditions} from './filter-items/filter-type/useConditionOptionsByType';\nimport dayjs from 'dayjs';\nimport {type TFunction} from 'i18next';\nimport {type ITreeFilters} from './context/useGetTreeFilters';\n\nconst _isValidFieldFilter = (filter: ViewDetailsFilterFragment | UIFilter): filter is ValidFieldFilter =>\n !!filter.field;\n\nconst _isValidFieldFilterThrough = (filter: ValidFilter): filter is ValidFieldFilterThrough =>\n filter.condition === ThroughConditionFilter.THROUGH && !!filter.subCondition && !!filter.subField;\n\nconst _isValidFieldFilterStandardValuesList = (\n filter: ValidFilter,\n attribute: NonNullable<ExplorerAttributesQuery['attributes']>['list'][number],\n): filter is ValidFieldFilterStandardValuesList & {attribute: StandardAttributeDetailsFragment} =>\n valueListTextConditions.includes(filter.condition) &&\n [AttributeType.simple, AttributeType.advanced].includes(attribute.type) &&\n 'valuesList' in attribute &&\n !!attribute.valuesList?.enable;\n\nconst _isValidFieldFilterLinkValuesList = (\n filter: ValidFilter,\n attribute: NonNullable<ExplorerAttributesQuery['attributes']>['list'][number],\n): filter is ValidFieldFilterLinkValuesList & {attribute: LinkAttributeDetailsFragment} =>\n valueListTextConditions.includes(filter.condition) &&\n [AttributeType.simple_link, AttributeType.advanced_link].includes(attribute.type) &&\n 'valuesList' in attribute &&\n !!attribute.valuesList?.enable;\n\ntype AttributeDetailsLinkAttributeWithPermissionsFragment = AttributeDetailsLinkAttributeFragment & {\n permissions: {\n access_attribute: boolean;\n };\n};\ntype AttributeDetailsTreeAttributeWithPermissionsFragment = AttributeDetailsTreeAttributeFragment & {\n permissions: {\n access_attribute: boolean;\n };\n};\n\nexport const isLinkAttributeDetails = (\n linkAttributeData: NonNullable<ExplorerLinkAttributeQuery['attributes']>['list'][number],\n): linkAttributeData is LinkAttributeDetailsFragment & {\n id: string;\n multiple_values: boolean;\n permissions: {\n access_attribute: boolean;\n edit_value: boolean;\n };\n} => 'linked_library' in linkAttributeData;\n\nexport type ValidFiltersArgument = GetViewsListQuery['views']['list'][number]['filters'] | UIFilter[];\n\nexport type AttributesById = Record<string, NonNullable<ExplorerAttributesQuery['attributes']>['list'][number]>;\n\nexport const useTransformFilters = () => {\n const {lang} = useLang();\n\n const toValidFilters = (filters: ValidFiltersArgument): ValidFilter[] =>\n (filters ?? []).reduce<ValidFilter[]>((acc, filter) => {\n if (!_isValidFieldFilter(filter)) {\n return acc;\n }\n const _isThroughFilter = filter.field.includes('.');\n\n if (_isThroughFilter) {\n // Hack because view filters does not have the necessary data to be transformed directly to UI filter,\n // we need to split the field to get the subCondition and subField for through filter, may be fix after LEAVC-569\n const [field, ...subFields] = filter.field.split('.');\n const throughFilter: ValidFieldFilterThrough = {\n field,\n subField: subFields.join('.'),\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n condition: ThroughConditionFilter.THROUGH,\n subCondition: filter.condition,\n };\n acc.push(throughFilter);\n } else {\n acc.push(filter);\n }\n\n return acc;\n }, []);\n\n const toUIFilters = ({\n filters,\n treeFilters,\n attributesDataById,\n t,\n }: {\n filters: ValidFilter[];\n treeFilters: ITreeFilters;\n attributesDataById: AttributesById;\n t: TFunction;\n }): UIFilter[] =>\n (filters ?? []).reduce<UIFilter[]>((acc, filter) => {\n if (!attributesDataById[filter.field]) {\n console.warn(`Attribute ${filter.field} from user view not found in database.`);\n return acc;\n }\n\n const filterAttributeBase: IUIFilterBaseAttribute = {\n id: attributesDataById[filter.field].id,\n label: localizedTranslation(attributesDataById[filter.field].label, lang),\n type: attributesDataById[filter.field].type,\n };\n\n // filter is standardFilter\n if (isStandardAttribute(filterAttributeBase.type)) {\n const attributeData = attributesDataById[filter.field];\n if (_isValidFieldFilterStandardValuesList(filter, attributeData)) {\n const newFilter: IUIFilterStandardValueList = {\n field: filter.field,\n // TODO : save filter values as string[] when filter and handle fields with libraries\n value: filter.value ? [filter.value] : [],\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: (filter.condition as RecordFilterCondition) ?? null,\n attribute: {\n ...filterAttributeBase,\n format: attributeData.format!,\n valuesList: (attributeData as StandardAttributeDetailsFragment).valuesList!,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n } else {\n let formattedValue: string;\n if (attributeData.format === AttributeFormat.boolean && filter.value) {\n formattedValue = filter.value === 'true' ? t('explorer.true') : t('explorer.false');\n }\n\n if (attributeData.format === AttributeFormat.date && filter.value) {\n formattedValue = dayjs(filter.value).format('YYYY-MM-DD');\n }\n\n const newFilter: IUIFilterStandard = {\n field: filter.field,\n value: filter.value ?? null,\n formattedValue,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: (filter.condition as RecordFilterCondition) ?? null,\n attribute: {\n ...filterAttributeBase,\n format: attributeData.format!,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n }\n }\n\n if (isLinkAttribute(filterAttributeBase.type)) {\n const attributeData = attributesDataById[\n filter.field\n ] as AttributeDetailsLinkAttributeWithPermissionsFragment;\n if (_isValidFieldFilterThrough(filter)) {\n const newFilter: IUIFilterThrough = {\n field: filter.field,\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n subCondition: filter.subCondition ?? null,\n subField: filter.subField,\n };\n acc.push(newFilter);\n } else if (_isValidFieldFilterLinkValuesList(filter, attributeData)) {\n const newFilter: IUIFilterLinkValueList = {\n field: filter.field,\n // TODO : save filter values as string[] when filter and handle fields with libraries\n value: filter.value ? [filter.value] : [],\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n valuesList: (attributeData as LinkAttributeDetailsFragment).valuesList!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n\n acc.push(newFilter);\n } else {\n const newFilter: IUIFilterLink = {\n field: filter.field,\n value: filter.value ?? null,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n condition: filter.condition,\n attribute: {\n ...filterAttributeBase,\n linkedLibrary: attributeData.linked_library!,\n smartFilter: attributeData.smart_filter ?? undefined,\n },\n };\n\n acc.push(newFilter);\n }\n }\n\n if (isTreeAttribute(filterAttributeBase.type) && !_isValidFieldFilterThrough(filter)) {\n const attributeData = attributesDataById[\n filter.field\n ] as AttributeDetailsTreeAttributeWithPermissionsFragment;\n const newFilter: IUIFilterTree = {\n field: [filter.field],\n // TODO : save filter values as string[] when tree filter and handle fields with libraries\n value: filter.value\n ? [filter.value]\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => tree.value)\n : null,\n formattedValue: filter.value\n ? [filter.value]\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => tree.label)\n : undefined,\n nodes: filter.value\n ? undefined\n : treeFilters[filter.field]\n ? treeFilters[filter.field].map(tree => ({libraryId: tree.libraryId, nodeId: tree.nodeId}))\n : undefined,\n hidden: filter.hidden ?? false,\n id: window.crypto.randomUUID(),\n attribute: {\n ...filterAttributeBase,\n linkedTree: attributeData.linked_tree!,\n },\n condition: filter.condition ?? RecordFilterCondition.EQUAL,\n withEmptyValues: filter.withEmptyValues ?? false,\n };\n acc.push(newFilter);\n }\n\n return acc;\n }, []);\n\n return {\n toValidFilters,\n toUIFilters,\n };\n};\n"]}
@@ -16,3 +16,5 @@ export { useIFrameMessenger } from './useIFrameMessenger/useIFrameMessenger';
16
16
  export { useIFrameMessengerClient } from './useIFrameMessengerClient/useIFrameMessengerClient';
17
17
  export { IFrameMessengerClient } from './useIFrameMessengerClient/IFrameMessengerClient';
18
18
  export { creationPanelSchema } from './useIFrameMessenger/schema';
19
+ export { useIFrameMessengerHandlers } from './useIFrameMessenger/useIFrameMessengerHandlers';
20
+ export { IFrameMessengerProvider } from './useIFrameMessenger/useIFrameMessengerContext';
@@ -19,4 +19,6 @@ export { useIFrameMessenger } from './useIFrameMessenger/useIFrameMessenger';
19
19
  export { useIFrameMessengerClient } from './useIFrameMessengerClient/useIFrameMessengerClient';
20
20
  export { IFrameMessengerClient } from './useIFrameMessengerClient/IFrameMessengerClient';
21
21
  export { creationPanelSchema } from './useIFrameMessenger/schema';
22
+ export { useIFrameMessengerHandlers } from './useIFrameMessenger/useIFrameMessengerHandlers';
23
+ export { IFrameMessengerProvider } from './useIFrameMessenger/useIFrameMessengerContext';
22
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AAEtE,OAAO,EAAC,0BAA0B,EAAC,MAAM,cAAc,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAC,+BAA+B,EAAC,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,6BAA6B,EAAC,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAC,wBAAwB,EAAC,MAAM,qDAAqD,CAAC;AAC7F,OAAO,EAAC,qBAAqB,EAAC,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\n\nexport {useSaveApplicationMutation} from '../_gqlTypes';\nexport {useAntdLocale} from './useAntdLocale';\nexport {default as useAppLang} from './useAppLang';\nexport {default as useAuth} from './useAuth';\nexport {default as useGetRecordForm} from './useGetRecordForm';\nexport {useGetRecordUpdatesSubscription} from './useGetRecordUpdatesSubscription';\nexport {default as useLang} from './useLang';\nexport {default as useLocalStorage} from './useLocalStorage';\nexport {default as useRecordsConsultationHistory} from './useRecordsConsultationHistory';\nexport {useRefreshFieldValues} from './useRefreshFieldValues';\nexport {default as useLoginChecker} from './useLoginChecker';\nexport {default as useRedirectToLogin} from './useRedirectToLogin';\nexport {useUser} from './useUser';\nexport {useValuesCacheUpdate} from './useValuesCacheUpdate';\nexport {useIFrameMessenger} from './useIFrameMessenger/useIFrameMessenger';\nexport {useIFrameMessengerClient} from './useIFrameMessengerClient/useIFrameMessengerClient';\nexport {IFrameMessengerClient} from './useIFrameMessengerClient/IFrameMessengerClient';\nexport {creationPanelSchema} from './useIFrameMessenger/schema';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AAEtE,OAAO,EAAC,0BAA0B,EAAC,MAAM,cAAc,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAC,+BAA+B,EAAC,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,6BAA6B,EAAC,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAC,wBAAwB,EAAC,MAAM,qDAAqD,CAAC;AAC7F,OAAO,EAAC,qBAAqB,EAAC,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAC,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAC,0BAA0B,EAAC,MAAM,iDAAiD,CAAC;AAC3F,OAAO,EAAC,uBAAuB,EAAC,MAAM,gDAAgD,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\n\nexport {useSaveApplicationMutation} from '../_gqlTypes';\nexport {useAntdLocale} from './useAntdLocale';\nexport {default as useAppLang} from './useAppLang';\nexport {default as useAuth} from './useAuth';\nexport {default as useGetRecordForm} from './useGetRecordForm';\nexport {useGetRecordUpdatesSubscription} from './useGetRecordUpdatesSubscription';\nexport {default as useLang} from './useLang';\nexport {default as useLocalStorage} from './useLocalStorage';\nexport {default as useRecordsConsultationHistory} from './useRecordsConsultationHistory';\nexport {useRefreshFieldValues} from './useRefreshFieldValues';\nexport {default as useLoginChecker} from './useLoginChecker';\nexport {default as useRedirectToLogin} from './useRedirectToLogin';\nexport {useUser} from './useUser';\nexport {useValuesCacheUpdate} from './useValuesCacheUpdate';\nexport {useIFrameMessenger} from './useIFrameMessenger/useIFrameMessenger';\nexport {useIFrameMessengerClient} from './useIFrameMessengerClient/useIFrameMessengerClient';\nexport {IFrameMessengerClient} from './useIFrameMessengerClient/IFrameMessengerClient';\nexport {creationPanelSchema} from './useIFrameMessenger/schema';\nexport {useIFrameMessengerHandlers} from './useIFrameMessenger/useIFrameMessengerHandlers';\nexport {IFrameMessengerProvider} from './useIFrameMessenger/useIFrameMessengerContext';\n"]}
@@ -0,0 +1,6 @@
1
+ import { type RegisterHandlers } from './types';
2
+ export interface IIFrameMessengerContext {
3
+ registerHandlers: RegisterHandlers;
4
+ changeLangInAllFrames: (language: string) => void;
5
+ }
6
+ export declare const IFrameMessengerContext: import("react").Context<IIFrameMessengerContext>;
@@ -0,0 +1,8 @@
1
+ // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
+ // This file is released under LGPL V3
3
+ // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
+ // Kept in a separate file from the Provider component to satisfy the
5
+ // react-refresh/only-export-components ESLint rule (Context is not a component).
6
+ import { createContext } from 'react';
7
+ export const IFrameMessengerContext = createContext(null);
8
+ //# sourceMappingURL=iFrameMessengerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/iFrameMessengerContext.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AAEtE,qEAAqE;AACrE,iFAAiF;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAQpC,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\n\n// 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 RegisterHandlers} from './types';\n\nexport interface IIFrameMessengerContext {\n registerHandlers: RegisterHandlers;\n changeLangInAllFrames: (language: string) => void;\n}\n\nexport const IFrameMessengerContext = createContext<IIFrameMessengerContext>(null);\n"]}
@@ -1,4 +1,4 @@
1
- import { type RefObject, type ComponentProps, type Key, type JSXElementConstructor } from 'react';
1
+ import { type MutableRefObject, type RefObject, type ComponentProps, type Key, type JSXElementConstructor } from 'react';
2
2
  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';
@@ -52,6 +52,10 @@ export type UnregisterMessage = IMessageBase & {
52
52
  type: 'unregister';
53
53
  id: string;
54
54
  };
55
+ export type IsRegisteredMessage = IMessageBase & {
56
+ type: 'is-registered';
57
+ id: string;
58
+ };
55
59
  export type Panel = z.infer<typeof PanelSchema>;
56
60
  export type AttributeExplorerPanel = Panel & z.infer<typeof baseExplorerPanelSchema> & z.infer<typeof attributeExplorerPanelSchema>;
57
61
  export type LibraryId = z.infer<typeof LibraryIdSchema>;
@@ -70,6 +74,7 @@ export type NavigateToPanelMessage = IMessageBase & {
70
74
  flapLibraryId?: LibraryId;
71
75
  flapPanelId?: FlapPanelId;
72
76
  queryParams?: Record<string, string> & {
77
+ redirectUrl?: string;
73
78
  formInitialValues?: Record<string, Array<AnyPrimitive | IRecordIdentity | ITreeNodeWithRecord>>;
74
79
  };
75
80
  };
@@ -108,7 +113,6 @@ export type OpenFlapPanelMessage = IMessageBase & {
108
113
  flapRecordId: string;
109
114
  flapLibraryId: LibraryId;
110
115
  flapPanelId: FlapPanelId;
111
- redirectUrl?: string;
112
116
  };
113
117
  };
114
118
  export type CloseFlapPanelMessage = IMessageBase & {
@@ -146,7 +150,7 @@ export type MessageFromParent = (IMessageBase & {
146
150
  type: 'on-call-callback';
147
151
  path: string;
148
152
  data: unknown;
149
- }) | ChangeLanguageMessage;
153
+ }) | IsRegisteredMessage | ChangeLanguageMessage;
150
154
  export type Message = MessageToParent | MessageFromParent;
151
155
  export type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;
152
156
  export type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;
@@ -155,9 +159,12 @@ export type CallbackFunction = (...args: never[]) => void;
155
159
  export type Callbacks = Record<string, Record<string, CallbackFunction>>;
156
160
  export type MessageToPanelMessageHandler = (data: MessageToPanelMessage['data']['payload']) => void;
157
161
  export type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) => void;
162
+ export type UnregisterHandlers = () => void;
163
+ export type RegisterHandlers = (iframeRef: RefObject<HTMLIFrameElement>, handlers: IUseIFrameMessengerOptions['handlers']) => UnregisterHandlers;
158
164
  export interface IUseIFrameMessengerOptions {
159
165
  ref?: RefObject<HTMLIFrameElement>;
160
166
  id?: string;
167
+ onMessageReceived?: (senderWindow: Window | null, message: Message, panelId: string | null, dispatch: MessageDispatcher, callCb: CallCbFunction, callbacksStore: MutableRefObject<Callbacks>) => void;
161
168
  handlers?: {
162
169
  onModalConfirm?: (data: ModalConfirmMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
163
170
  onAlert?: (data: AlertMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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';\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}\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 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 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 redirectUrl?: string;\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 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\nexport type MessageFromParent =\n | (IMessageBase & {\n type: 'on-call-callback';\n path: string;\n data: unknown;\n })\n | ChangeLanguageMessage;\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 interface IUseIFrameMessengerOptions {\n ref?: RefObject<HTMLIFrameElement>;\n id?: string;\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 };\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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';\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}\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 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\nexport type MessageFromParent =\n | (IMessageBase & {\n type: 'on-call-callback';\n path: string;\n data: unknown;\n })\n | IsRegisteredMessage\n | ChangeLanguageMessage;\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;\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 };\n}\n"]}
@@ -1,10 +1,19 @@
1
1
  import { type AddMessageToPanelMessageHandler, type IUseIFrameMessengerOptions } from './types';
2
2
  export { IUseIFrameMessengerOptions };
3
3
  /**
4
- * This is the core of `useIFrameMessenger`. Should be used for top-level apps, such as **app-studio**.
5
- * For client apps (apps that need to consume the messenger), please use the `useIFrameMessengerClient`
4
+ * Core hook of the IFrameMessenger system. Registers a single `window.addEventListener('message')`
5
+ * and manages a registry of connected child frames.
6
+ *
7
+ * **Usage:**
8
+ * - Top-level apps (e.g. app-studio): use via `IFrameMessengerProvider` which calls this hook once as a singleton.
9
+ * - Client apps (child iframes): use `useIFrameMessengerClient` instead.
10
+ *
11
+ * **`onMessageReceived` option:** when provided, all non-system messages are delegated to this callback
12
+ * instead of being handled locally. Used by `IFrameMessengerProvider` to route messages to the correct
13
+ * per-iframe handlers without registering multiple listeners.
6
14
  */
7
15
  export declare const useIFrameMessenger: (options?: IUseIFrameMessengerOptions) => {
16
+ isRegistered: boolean;
8
17
  unregister: () => void;
9
18
  changeLangInAllFrames: (newLanguage: string) => void;
10
19
  addPanelMessageHandler: AddMessageToPanelMessageHandler;
@@ -1,16 +1,25 @@
1
1
  // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
2
  // This file is released under LGPL V3
3
3
  // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
- import { useCallback, useContext, useEffect, useRef } from 'react';
4
+ import { useCallback, useContext, useEffect, useRef, useState } from 'react';
5
5
  import { LangContext } from '../../contexts';
6
- import { encodeMessage, decodeMessage, getExposedMethods, initClientHandlers } from './messageHandlers';
6
+ import { encodeMessage, decodeMessage, getExposedMethods } from './messageHandlers';
7
7
  /**
8
- * This is the core of `useIFrameMessenger`. Should be used for top-level apps, such as **app-studio**.
9
- * For client apps (apps that need to consume the messenger), please use the `useIFrameMessengerClient`
8
+ * Core hook of the IFrameMessenger system. Registers a single `window.addEventListener('message')`
9
+ * and manages a registry of connected child frames.
10
+ *
11
+ * **Usage:**
12
+ * - Top-level apps (e.g. app-studio): use via `IFrameMessengerProvider` which calls this hook once as a singleton.
13
+ * - Client apps (child iframes): use `useIFrameMessengerClient` instead.
14
+ *
15
+ * **`onMessageReceived` option:** when provided, all non-system messages are delegated to this callback
16
+ * instead of being handled locally. Used by `IFrameMessengerProvider` to route messages to the correct
17
+ * per-iframe handlers without registering multiple listeners.
10
18
  */
11
19
  export const useIFrameMessenger = (options) => {
12
20
  const registry = useRef({});
13
21
  const selfId = useRef(options?.id ?? window.crypto.randomUUID());
22
+ const [isRegistered, setIsRegistered] = useState(window === window.top);
14
23
  const { setLang } = useContext(LangContext);
15
24
  const changeLangInAllFrames = (newLanguage) => {
16
25
  dispatch({
@@ -64,7 +73,6 @@ export const useIFrameMessenger = (options) => {
64
73
  return null;
65
74
  };
66
75
  useEffect(() => {
67
- const clientHandlers = initClientHandlers(callCb, { ...options, id: selfId.current }, callbacksStore);
68
76
  const onMessage = (event) => {
69
77
  const message = decodeMessage(event.data);
70
78
  if (message === undefined) {
@@ -80,12 +88,16 @@ export const useIFrameMessenger = (options) => {
80
88
  registry.current[message.id] = frames[i];
81
89
  }
82
90
  }
91
+ dispatch({ type: 'is-registered', id: message.id }, message.id);
83
92
  break;
84
93
  case 'unregister':
85
94
  if (registry.current[message.id]) {
86
95
  delete registry.current[message.id];
87
96
  }
88
97
  break;
98
+ case 'is-registered':
99
+ setIsRegistered(true);
100
+ break;
89
101
  case 'message-to-panel':
90
102
  panelMessageHandlerRegistry.current[message.data.type]?.(message.data.payload);
91
103
  if (window === window.top) {
@@ -93,17 +105,14 @@ export const useIFrameMessenger = (options) => {
93
105
  dispatch(message, target);
94
106
  }
95
107
  break;
96
- case 'get-panel-config':
97
- clientHandlers({
98
- ...message,
99
- data: { ...message.data, panelId: getPanelIdFromEvent(event) },
100
- }, dispatch);
101
108
  default:
102
109
  if (message.type === 'change-language') {
103
110
  setLang(message.language);
104
111
  }
105
- else {
106
- clientHandlers(message, dispatch);
112
+ else if (options?.onMessageReceived) {
113
+ // Singleton mode: delegate routing to the Provider (IFrameMessengerProvider).
114
+ // The Provider resolves which iframe sent the message and calls the matching handlers.
115
+ options.onMessageReceived(event.source, message, getPanelIdFromEvent(event), dispatch, callCb, callbacksStore);
107
116
  }
108
117
  break;
109
118
  }
@@ -117,6 +126,9 @@ export const useIFrameMessenger = (options) => {
117
126
  window.removeEventListener('message', onMessage);
118
127
  };
119
128
  }, []);
120
- return methods.current;
129
+ return {
130
+ ...methods.current,
131
+ isRegistered,
132
+ };
121
133
  };
122
134
  //# sourceMappingURL=useIFrameMessenger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIFrameMessenger.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/use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C;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,OAAO,CAAC,OAAO,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {useCallback, useContext, useEffect, useRef} 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 * This is the core of `useIFrameMessenger`. Should be used for top-level apps, such as **app-studio**.\n * For client apps (apps that need to consume the messenger), please use the `useIFrameMessengerClient`\n */\nexport const useIFrameMessenger = (options?: IUseIFrameMessengerOptions) => {\n const registry = useRef<Record<string, Window>>({});\n const selfId = useRef(options?.id ?? window.crypto.randomUUID());\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 break;\n case 'unregister':\n if (registry.current[message.id]) {\n delete registry.current[message.id];\n }\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 case 'get-panel-config':\n clientHandlers(\n {\n ...message,\n data: {...message.data, panelId: getPanelIdFromEvent(event)},\n },\n dispatch,\n );\n default:\n if (message.type === 'change-language') {\n setLang(message.language);\n } else {\n clientHandlers(message, 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 methods.current;\n};\n"]}
1
+ {"version":3,"file":"useIFrameMessenger.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessenger.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,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,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAIlF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAoC,EAAE,EAAE;IACvE,MAAM,QAAQ,GAAG,MAAM,CAAyB,EAAE,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC;IAExE,MAAM,EAAC,OAAO,EAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAE1C,MAAM,qBAAqB,GAAG,CAAC,WAAmB,EAAE,EAAE;QAClD,QAAQ,CACJ;YACI,IAAI,EAAE,iBAAiB;YACv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I,KAAK,CAAC;wBAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC9B,CAAC;oBACD,MAAM;gBACV;oBACI,IAAI,OAAO,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;wBACrC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBAC9B,CAAC;yBAAM,IAAI,OAAO,EAAE,iBAAiB,EAAE,CAAC;wBACpC,8EAA8E;wBAC9E,uFAAuF;wBACvF,OAAO,CAAC,iBAAiB,CACrB,KAAK,CAAC,MAAgB,EACtB,OAAO,EACP,mBAAmB,CAAC,KAAK,CAAC,EAC1B,QAAQ,EACR,MAAM,EACN,cAAc,CACjB,CAAC;oBACN,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":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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} 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 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 }\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;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
3
+ // This file is released under LGPL V3
4
+ // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
5
+ import { useCallback, useMemo, useRef } from 'react';
6
+ import { useIFrameMessenger } from './useIFrameMessenger';
7
+ import { initClientHandlers } from './messageHandlers';
8
+ import { IFrameMessengerContext } from './iFrameMessengerContext';
9
+ /**
10
+ * Singleton Provider for the IFrameMessenger system.
11
+ * Must be mounted once above all `PanelCustom` instances.
12
+ *
13
+ * Owns a single `window.addEventListener('message')` (via `useIFrameMessenger`)
14
+ * and routes incoming messages to the correct iframe's handlers using `handlersMap`.
15
+ *
16
+ * Each `PanelCustom` registers/deregisters its handlers via `useIFrameMessengerHandlers`.
17
+ */
18
+ export const IFrameMessengerProvider = ({ children }) => {
19
+ // Maps each iframe's RefObject to its set of handlers.
20
+ // Using RefObject as key (instead of Window) avoids timing issues: contentWindow
21
+ // may not be available yet when the iframe mounts and registers its handlers.
22
+ const handlersMap = useRef(new Map());
23
+ // Called by useIFrameMessenger for every non-system message.
24
+ // Finds the handlers registered for the sender iframe and dispatches the message to them.
25
+ const onMessageReceived = useCallback((senderWindow, message, panelId, dispatch, callCb, callbacksStore) => {
26
+ // event.source is null when the sender iframe was unmounted before the message
27
+ // was processed — the browser clears the reference on iframe removal.
28
+ if (!senderWindow) {
29
+ return;
30
+ }
31
+ let matchedHandlers;
32
+ for (const [ref, handlers] of handlersMap.current) {
33
+ if (ref.current?.contentWindow === senderWindow) {
34
+ matchedHandlers = handlers;
35
+ break;
36
+ }
37
+ }
38
+ // No registered handlers for this sender: either the iframe called unregisterHandlers
39
+ // before its last message was processed (race condition on unmount), or the message
40
+ // originates from an unrelated frame that passed decodeMessage validation.
41
+ if (!matchedHandlers) {
42
+ return;
43
+ }
44
+ const enrichedMessage = message.type === 'get-panel-config' ? { ...message, data: { ...message.data, panelId } } : message;
45
+ const clientHandlers = initClientHandlers(callCb, { handlers: matchedHandlers }, callbacksStore);
46
+ clientHandlers(enrichedMessage, dispatch);
47
+ }, []);
48
+ const { changeLangInAllFrames } = useIFrameMessenger({ onMessageReceived });
49
+ const registerHandlers = useCallback((iframeRef, handlers) => {
50
+ handlersMap.current.set(iframeRef, handlers);
51
+ const cleanup = () => {
52
+ handlersMap.current.delete(iframeRef);
53
+ };
54
+ return cleanup;
55
+ }, []);
56
+ const contextValue = useMemo(() => ({ registerHandlers, changeLangInAllFrames }), []);
57
+ return _jsx(IFrameMessengerContext.Provider, { value: contextValue, children: children });
58
+ };
59
+ //# sourceMappingURL=useIFrameMessengerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerContext.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAwD,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC1G,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAUrD,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB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ExE,MAAM,gBAAgB,GAAqB,WAAW,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;QAC3E,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAE7C,MAAM,OAAO,GAAG,GAAG,EAAE;YACjB,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAC,gBAAgB,EAAE,qBAAqB,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpF,OAAO,KAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAAG,QAAQ,GAAmC,CAAC;AAC9G,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type MutableRefObject, type ReactNode, type RefObject, useCallback, useMemo, useRef} from 'react';\nimport {useIFrameMessenger} from './useIFrameMessenger';\nimport {initClientHandlers} from './messageHandlers';\nimport {\n type Callbacks,\n type CallCbFunction,\n type Message,\n type MessageDispatcher,\n type IUseIFrameMessengerOptions,\n type RegisterHandlers,\n type UnregisterHandlers,\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 // Called by useIFrameMessenger for every non-system message.\n // Finds the handlers registered for the sender iframe 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 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\n const cleanup = () => {\n handlersMap.current.delete(iframeRef);\n };\n\n return cleanup;\n }, []);\n\n const contextValue = useMemo(() => ({registerHandlers, changeLangInAllFrames}), []);\n\n return <IFrameMessengerContext.Provider value={contextValue}>{children}</IFrameMessengerContext.Provider>;\n};\n"]}
@@ -0,0 +1,13 @@
1
+ import { type RefObject } from 'react';
2
+ import { type IUseIFrameMessengerOptions } from './types';
3
+ /**
4
+ * Per-iframe hook for `PanelCustom`. Registers the iframe's handlers into the singleton
5
+ * `IFrameMessengerProvider` and cleans them up on unmount.
6
+ *
7
+ * Returns `changeLangInFrame` which posts `change-language` directly to this specific iframe's
8
+ * `contentWindow` — intentionally NOT using the shared registry to avoid broadcasting the language
9
+ * change to all other open iframes (which would cause unintended refreshes).
10
+ */
11
+ export declare const useIFrameMessengerHandlers: (iframeRef: RefObject<HTMLIFrameElement>, handlers: IUseIFrameMessengerOptions["handlers"]) => {
12
+ changeLangInFrame: (language: string) => void;
13
+ };
@@ -0,0 +1,29 @@
1
+ // Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
2
+ // This file is released under LGPL V3
3
+ // License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
4
+ import { useCallback, useContext, useEffect } from 'react';
5
+ import { IFrameMessengerContext } from './iFrameMessengerContext';
6
+ import { encodeMessage } from './messageHandlers';
7
+ /**
8
+ * Per-iframe hook for `PanelCustom`. Registers the iframe's handlers into the singleton
9
+ * `IFrameMessengerProvider` and cleans them up on unmount.
10
+ *
11
+ * Returns `changeLangInFrame` which posts `change-language` directly to this specific iframe's
12
+ * `contentWindow` — intentionally NOT using the shared registry to avoid broadcasting the language
13
+ * change to all other open iframes (which would cause unintended refreshes).
14
+ */
15
+ export const useIFrameMessengerHandlers = (iframeRef, handlers) => {
16
+ const { registerHandlers } = useContext(IFrameMessengerContext);
17
+ // Register on mount, deregister on unmount via the returned cleanup function.
18
+ useEffect(() => registerHandlers(iframeRef, handlers), []);
19
+ // Post directly to contentWindow instead of going through the registry,
20
+ // which would broadcast to all registered iframes.
21
+ const changeLangInFrame = useCallback((language) => {
22
+ if (iframeRef.current?.contentWindow) {
23
+ const message = { type: 'change-language', language };
24
+ iframeRef.current.contentWindow.postMessage(encodeMessage(message), '*');
25
+ }
26
+ }, [iframeRef]);
27
+ return { changeLangInFrame };
28
+ };
29
+ //# sourceMappingURL=useIFrameMessengerHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIFrameMessengerHandlers.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerHandlers.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,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":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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"]}
@@ -8,6 +8,9 @@ import { IframeMessengerClientContext } from './iFrameMessengerClientContext';
8
8
  export const IFrameMessengerClient = ({ children, id }) => {
9
9
  const iFrameMessenger = useIFrameMessenger({ id });
10
10
  useEffect(() => () => iFrameMessenger.unregister(), []);
11
+ if (!iFrameMessenger.isRegistered) {
12
+ return null;
13
+ }
11
14
  return (_jsx(IframeMessengerClientContext.Provider, { value: iFrameMessenger, children: children }));
12
15
  };
13
16
  //# sourceMappingURL=IFrameMessengerClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IFrameMessengerClient.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessengerClient/IFrameMessengerClient.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,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,OAAO,CACH,KAAC,4BAA4B,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,YACxD,QAAQ,GAC2B,CAC3C,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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 return (\n <IframeMessengerClientContext.Provider value={iFrameMessenger}>\n {children}\n </IframeMessengerClientContext.Provider>\n );\n};\n"]}
1
+ {"version":3,"file":"IFrameMessengerClient.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessengerClient/IFrameMessengerClient.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,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":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {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"]}
@@ -1,4 +1,5 @@
1
1
  export declare const IframeMessengerClientContext: import("react").Context<{
2
+ isRegistered: boolean;
2
3
  unregister: () => void;
3
4
  changeLangInAllFrames: (newLanguage: string) => void;
4
5
  addPanelMessageHandler: import("../useIFrameMessenger/types").AddMessageToPanelMessageHandler;
@@ -1,4 +1,5 @@
1
1
  export declare const useIFrameMessengerClient: () => {
2
+ isRegistered: boolean;
2
3
  unregister: () => void;
3
4
  changeLangInAllFrames: (newLanguage: string) => void;
4
5
  addPanelMessageHandler: import("../useIFrameMessenger/types").AddMessageToPanelMessageHandler;