@leav/ui 1.12.0-d09cabfa → 1.12.0-e8c84be4

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 (64) hide show
  1. package/dist/__mocks__/utils.d.ts +3 -0
  2. package/dist/__mocks__/utils.js +2 -0
  3. package/dist/__mocks__/utils.js.map +1 -0
  4. package/dist/_gqlTypes/index.d.ts +129 -33
  5. package/dist/_gqlTypes/index.js +71 -3
  6. package/dist/_gqlTypes/index.js.map +1 -1
  7. package/dist/_queries/attributes/attributeDetailsFragment.js +3 -0
  8. package/dist/_queries/attributes/attributeDetailsFragment.js.map +1 -1
  9. package/dist/components/Explorer/DataView.js +30 -13
  10. package/dist/components/Explorer/DataView.js.map +1 -1
  11. package/dist/components/Explorer/actions-mass/ResultsCount.js +2 -2
  12. package/dist/components/Explorer/actions-mass/ResultsCount.js.map +1 -1
  13. package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js +14 -6
  14. package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js.map +1 -1
  15. package/dist/components/Explorer/actions-mass/useMassActions.js +12 -6
  16. package/dist/components/Explorer/actions-mass/useMassActions.js.map +1 -1
  17. package/dist/components/Explorer/conditionsHelper.d.ts +2 -1
  18. package/dist/components/Explorer/conditionsHelper.js.map +1 -1
  19. package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js +6 -4
  20. package/dist/components/Explorer/manage-view-settings/save-view/prepareViewForRequest.js.map +1 -1
  21. package/dist/components/Filters/_types.d.ts +3 -0
  22. package/dist/components/Filters/_types.js.map +1 -1
  23. package/dist/components/Filters/conditionsHelper.d.ts +2 -1
  24. package/dist/components/Filters/conditionsHelper.js.map +1 -1
  25. package/dist/components/Filters/context/filtersReducer.js +14 -1
  26. package/dist/components/Filters/context/filtersReducer.js.map +1 -1
  27. package/dist/components/Filters/filter-items/CommonFilterItem.js.map +1 -1
  28. package/dist/components/Filters/filter-items/filter-type/useConditionOptionsByType.js.map +1 -1
  29. package/dist/components/Filters/useFilters.d.ts +198 -0
  30. package/dist/components/Filters/useTransformFilters.js +4 -2
  31. package/dist/components/Filters/useTransformFilters.js.map +1 -1
  32. package/dist/components/RecordEdition/EditRecord/EditRecord.js +8 -1
  33. package/dist/components/RecordEdition/EditRecord/EditRecord.js.map +1 -1
  34. package/dist/hooks/index.d.ts +3 -0
  35. package/dist/hooks/index.js +3 -0
  36. package/dist/hooks/index.js.map +1 -1
  37. package/dist/hooks/useGetRecordIdCard/index.d.ts +1 -0
  38. package/dist/hooks/useGetRecordIdCard/index.js +5 -0
  39. package/dist/hooks/useGetRecordIdCard/index.js.map +1 -0
  40. package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.d.ts +18 -0
  41. package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.js +20 -0
  42. package/dist/hooks/useGetRecordIdCard/useGetRecordIdCard.js.map +1 -0
  43. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.d.ts +6 -0
  44. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js +8 -0
  45. package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js.map +1 -0
  46. package/dist/hooks/useIFrameMessenger/types.d.ts +10 -3
  47. package/dist/hooks/useIFrameMessenger/types.js.map +1 -1
  48. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.d.ts +11 -2
  49. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js +31 -10
  50. package/dist/hooks/useIFrameMessenger/useIFrameMessenger.js.map +1 -1
  51. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.d.ts +13 -0
  52. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js +59 -0
  53. package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js.map +1 -0
  54. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.d.ts +13 -0
  55. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js +29 -0
  56. package/dist/hooks/useIFrameMessenger/useIFrameMessengerHandlers.js.map +1 -0
  57. package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js +3 -0
  58. package/dist/hooks/useIFrameMessengerClient/IFrameMessengerClient.js.map +1 -1
  59. package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.d.ts +1 -0
  60. package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.d.ts +1 -0
  61. package/dist/hooks/useSharedTranslation/__mocks__/useSharedTranslation.js.map +1 -1
  62. package/dist/locales/en/shared.json +2 -0
  63. package/dist/locales/fr/shared.json +3 -1
  64. package/package.json +8 -8
@@ -1 +1 @@
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,EAC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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;AAEn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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 as RecordFilterCondition) &&\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 as RecordFilterCondition) &&\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"]}
@@ -7,7 +7,7 @@ import { useEffect, useReducer } from 'react';
7
7
  import styled from 'styled-components';
8
8
  import { ErrorDisplayTypes } from '../../../constants';
9
9
  import { useCanEditRecord } from '../../../hooks/useCanEditRecord';
10
- import { AttributeType, useActivateNewRecordMutation, } from '../../../_gqlTypes';
10
+ import { AttributeType, useActivateNewRecordMutation, useGetRecordIdCardQuery, } from '../../../_gqlTypes';
11
11
  import { ErrorBoundary } from '../../ErrorBoundary';
12
12
  import { ErrorDisplay } from '../../ErrorDisplay';
13
13
  import EditRecordContent from '../EditRecordContent';
@@ -48,6 +48,12 @@ export const EditRecord = ({ antdForm, formId, isFormCreationMode, formElementId
48
48
  const { data: libraryData } = useQuery(getLibraryByIdQuery, {
49
49
  variables: { id: [libraryId] },
50
50
  });
51
+ const { refetch: refetchRecordIdCardQuery } = useGetRecordIdCardQuery({
52
+ variables: {
53
+ id: record?.id ?? '',
54
+ libraryId,
55
+ },
56
+ });
51
57
  const { saveValues } = useSaveValueBatchMutation();
52
58
  const { deleteValue } = useExecuteDeleteValueMutation(record);
53
59
  const [activateNewRecordMutation] = useActivateNewRecordMutation();
@@ -114,6 +120,7 @@ export const EditRecord = ({ antdForm, formId, isFormCreationMode, formElementId
114
120
  if (errors == null || errors?.length === 0) {
115
121
  if (onCreate) {
116
122
  onCreate(activateNewRecordResult?.data?.activateNewRecord?.record?.whoAmI);
123
+ refetchRecordIdCardQuery(); // Force apollo to set cache with correct whoAmI instead of empty record
117
124
  }
118
125
  return;
119
126
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EditRecord.js","sourceRoot":"","sources":["../../../../src/components/RecordEdition/EditRecord/EditRecord.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAyB,SAAS,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AACpE,OAAO,MAAwB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EACH,aAAa,EAGb,4BAA4B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,aAAa,EAAC,MAAM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a,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,EAClB,cAAc,EAAE,mBAAmB,EACnC,aAAa,EAAE,kBAAkB,EACjC,aAAa,EAAE,WAAW,EAC1B,sBAAsB,EAAE,sBAAsB,EAC9C,QAAQ,EAAE,UAAU,GACtB,CACL,CAAC,CAAC,CAAC,CACA,KAAC,YAAY,IAAC,IAAI,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,GAAI,CACtF,GACK,EACT,CAAC,8BAA8B,IAAI,CAChC,KAAC,iBAAiB,IACd,gBAAgB,EAAE,gBAAgB,EAClC,sBAAsB,EAAE,sBAAsB,GAChD,CACL,IACO,GACoB,GACxB,CACnB,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 isEqual from 'lodash/isEqual';\nimport {type FunctionComponent, useEffect, useReducer} from 'react';\nimport styled, {type CSSObject} from 'styled-components';\nimport {ErrorDisplayTypes} from '../../../constants';\nimport {useCanEditRecord} from '../../../hooks/useCanEditRecord';\nimport {type IValueVersion} from '../../../types/values';\nimport {\n AttributeType,\n type RecordFormAttributeStandardAttributeFragment,\n type RecordIdentityFragment,\n useActivateNewRecordMutation,\n} from '../../../_gqlTypes';\nimport {ErrorBoundary} from '../../ErrorBoundary';\nimport {ErrorDisplay} from '../../ErrorDisplay';\nimport EditRecordContent from '../EditRecordContent';\nimport useExecuteDeleteValueMutation from '../EditRecordContent/hooks/useExecuteDeleteValueMutation';\nimport useSaveValueBatchMutation from '../EditRecordContent/hooks/useExecuteSaveValueBatchMutation';\nimport {\n type DeleteMultipleValuesFunc,\n type ISubmittedValueLink,\n type ISubmittedValueStandard,\n type ISubmittedValueTree,\n type IValueToSubmit,\n type SubmitValueFunc,\n} from '../EditRecordContent/_types';\nimport editRecordReducer, {EditRecordReducerActionsTypes, initialState} from '../editRecordReducer/editRecordReducer';\nimport {EditRecordReducerContext} from '../editRecordReducer/editRecordReducerContext';\nimport {type FormInstance} from 'antd/lib/form/Form';\nimport EditRecordSidebar from '../EditRecordSidebar';\nimport EditRecordSkeleton from '../EditRecordSkeleton';\nimport {useQuery} from '@apollo/client';\nimport {getLibraryByIdQuery} from '_ui/_queries/libraries/getLibraryByIdQuery';\nimport EditRecordButtons from '../EditRecordButtons';\n\ninterface IEditRecordProps {\n antdForm: FormInstance;\n formId: string;\n isFormCreationMode: boolean;\n formElementId?: string;\n record: RecordIdentityFragment['whoAmI'] | null;\n library: string;\n onCreate?: (newRecord: RecordIdentityFragment['whoAmI']) => void;\n valuesVersion?: IValueVersion;\n showSidebar?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n scrollAllRecordSummary?: boolean;\n enableSidebar?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n sidebarContainer?: HTMLElement; // TODO: Should be removed when sidebar is fully removed from EditRecord\n forceDisableSidebarInAppStudio?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n containerStyle?: CSSObject;\n withInfoButton: boolean;\n removePadding?: boolean; // TODO: This prop should be remove when EditRecord will be moved to app-studio or data-studio deleted\n}\n\nconst sidebarWidth = '352px';\n\nconst Container = styled.div<{$shouldUseLayoutWithSidebar: boolean; style: CSSObject}>`\n display: grid;\n grid-template-columns: ${props => (props.$shouldUseLayoutWithSidebar ? `minmax(0, auto) ${sidebarWidth}` : '1fr')};\n grid-template-areas: ${props => (props.$shouldUseLayoutWithSidebar ? '\"content sidebar\"' : '\"content\"')};\n overflow: hidden;\n`;\n\nconst Content = styled.div<{$shouldUseLayoutWithSidebar: boolean; $removePadding: boolean}>`\n grid-area: content;\n padding: ${props => (props.$removePadding ? 'unset' : '24px')};\n overflow-x: hidden;\n overflow-y: scroll;\n border-right: ${props =>\n props.$shouldUseLayoutWithSidebar ? '1px solid var(--general-utilities-border)' : 'none'};\n`;\n\nexport const EditRecord: FunctionComponent<IEditRecordProps> = ({\n antdForm,\n formId,\n isFormCreationMode,\n formElementId,\n record,\n library: libraryId,\n onCreate,\n valuesVersion,\n enableSidebar = false,\n showSidebar = false,\n scrollAllRecordSummary = false,\n sidebarContainer,\n forceDisableSidebarInAppStudio = false,\n containerStyle,\n withInfoButton,\n removePadding = false,\n}) => {\n const [state, dispatch] = useReducer(editRecordReducer, {\n ...initialState,\n record,\n libraryId,\n libraryLabel: null,\n valuesVersion,\n originValuesVersion: valuesVersion,\n withInfoButton,\n });\n\n const {\n loading: permissionsLoading,\n canEdit,\n isReadOnly,\n } = useCanEditRecord({...record?.library, id: libraryId}, record?.id);\n\n const {data: libraryData} = useQuery(getLibraryByIdQuery, {\n variables: {id: [libraryId]},\n });\n\n const {saveValues} = useSaveValueBatchMutation();\n const {deleteValue} = useExecuteDeleteValueMutation(record);\n const [activateNewRecordMutation] = useActivateNewRecordMutation();\n\n // Update record in reducer when it changes. Might happen on record identity change (after value save)\n useEffect(() => {\n if (libraryData) {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_LIBRARY_LABEL,\n label: libraryData.libraries.list[0].label,\n });\n }\n }, [libraryData]);\n\n useEffect(() => {\n if (record && !isEqual(record, state.record)) {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_RECORD,\n record,\n });\n }\n }, [record]);\n\n useEffect(() => {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_ENABLE_SIDEBAR,\n enabled: enableSidebar,\n });\n }, [enableSidebar]);\n\n useEffect(() => {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_SIDEBAR_IS_OPEN,\n isOpen: showSidebar,\n });\n }, [showSidebar]);\n\n const _handleValueSubmit: SubmitValueFunc = async (values, version) =>\n saveValues(\n record,\n values.map(val => {\n const savableValue = {...val, attribute: val.attribute.id, metadata: val.metadata};\n\n if (val.value) {\n switch (val.attribute.type) {\n case AttributeType.advanced_link:\n case AttributeType.simple_link:\n savableValue.value = (val as ISubmittedValueLink).value.id;\n break;\n case AttributeType.tree:\n savableValue.value = (val as ISubmittedValueTree).value.id;\n break;\n default:\n savableValue.value = (val as ISubmittedValueStandard).value;\n break;\n }\n }\n\n return savableValue as IValueToSubmit;\n }),\n version,\n true, // deleteEmpty\n );\n\n /**\n * Submit the whole record: create record and batch save all stored values\n */\n const _handleRecordSubmit = async (attributes: RecordFormAttributeStandardAttributeFragment[]) => {\n const activateNewRecordResult = await activateNewRecordMutation({\n fetchPolicy: 'network-only',\n variables: {\n libraryId,\n recordId: record.id,\n formId,\n },\n });\n const errors = activateNewRecordResult?.data?.activateNewRecord.valuesErrors;\n if (errors == null || errors?.length === 0) {\n if (onCreate) {\n onCreate(activateNewRecordResult?.data?.activateNewRecord?.record?.whoAmI);\n }\n return;\n }\n antdForm.setFields(\n errors.map(error => {\n const attributeInError = attributes.find(attribute => attribute.id === error.attribute);\n\n const doesAttributeHaveMultipleFields =\n attributeInError?.multiple_values &&\n ![AttributeType.simple_link, AttributeType.advanced_link].includes(attributeInError.type);\n\n return {\n name:\n doesAttributeHaveMultipleFields && error.type === 'REQUIRED_ATTRIBUTE'\n ? [error.attribute, 0]\n : error.attribute,\n errors: [error.message],\n };\n }),\n );\n };\n\n const _handleDeleteAllValues: DeleteMultipleValuesFunc = async (attribute, values, version) => {\n const valuesToSave = values.map(value => ({\n idValue: value.id_value,\n attribute,\n value: null,\n }));\n\n return saveValues(record, valuesToSave, version, true);\n };\n\n const shouldUseLayoutWithSidebar =\n state.enableSidebar && state.isOpenSidebar && sidebarContainer === undefined && !forceDisableSidebarInAppStudio;\n\n return (\n <ErrorBoundary>\n <EditRecordReducerContext.Provider value={{state, dispatch}}>\n <Container $shouldUseLayoutWithSidebar={shouldUseLayoutWithSidebar} style={containerStyle}>\n <EditRecordButtons />\n <Content\n className=\"edit-record-content-container\"\n $shouldUseLayoutWithSidebar={shouldUseLayoutWithSidebar}\n $removePadding={removePadding}\n >\n {permissionsLoading ? (\n <EditRecordSkeleton rows={5} />\n ) : canEdit ? (\n <EditRecordContent\n antdForm={antdForm}\n formId={formId}\n isFormCreationMode={isFormCreationMode}\n formElementId={formElementId}\n record={record}\n library={libraryId}\n onRecordSubmit={_handleRecordSubmit}\n onValueSubmit={_handleValueSubmit}\n onValueDelete={deleteValue}\n onDeleteMultipleValues={_handleDeleteAllValues}\n readonly={isReadOnly}\n />\n ) : (\n <ErrorDisplay type={ErrorDisplayTypes.PERMISSION_ERROR} showActionButton={false} />\n )}\n </Content>\n {!forceDisableSidebarInAppStudio && (\n <EditRecordSidebar\n sidebarContainer={sidebarContainer}\n scrollAllRecordSummary={scrollAllRecordSummary}\n />\n )}\n </Container>\n </EditRecordReducerContext.Provider>\n </ErrorBoundary>\n );\n};\n"]}
1
+ {"version":3,"file":"EditRecord.js","sourceRoot":"","sources":["../../../../src/components/RecordEdition/EditRecord/EditRecord.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAyB,SAAS,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AACpE,OAAO,MAAwB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EACH,aAAa,EAGb,4BAA4B,EAC5B,uBAAuB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,iBAAiB,MAAM,sBAAsB,CAAC;AACrD,OAAO,6BAA6B,MAAM,0DAA0D,CAAC;AACrG,OAAO,yBAAyB,MAAM,6DAA6D,CAAC;AASpG,OAAO,iBAAiB,EAAE,EAAC,6BAA6B,EAAE,YAAY,EAAC,MAAM,wCAAwC,CAAC;A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,EAClB,cAAc,EAAE,mBAAmB,EACnC,aAAa,EAAE,kBAAkB,EACjC,aAAa,EAAE,WAAW,EAC1B,sBAAsB,EAAE,sBAAsB,EAC9C,QAAQ,EAAE,UAAU,GACtB,CACL,CAAC,CAAC,CAAC,CACA,KAAC,YAAY,IAAC,IAAI,EAAE,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,GAAI,CACtF,GACK,EACT,CAAC,8BAA8B,IAAI,CAChC,KAAC,iBAAiB,IACd,gBAAgB,EAAE,gBAAgB,EAClC,sBAAsB,EAAE,sBAAsB,GAChD,CACL,IACO,GACoB,GACxB,CACnB,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 isEqual from 'lodash/isEqual';\nimport {type FunctionComponent, useEffect, useReducer} from 'react';\nimport styled, {type CSSObject} from 'styled-components';\nimport {ErrorDisplayTypes} from '../../../constants';\nimport {useCanEditRecord} from '../../../hooks/useCanEditRecord';\nimport {type IValueVersion} from '../../../types/values';\nimport {\n AttributeType,\n type RecordFormAttributeStandardAttributeFragment,\n type RecordIdentityFragment,\n useActivateNewRecordMutation,\n useGetRecordIdCardQuery,\n} from '../../../_gqlTypes';\nimport {ErrorBoundary} from '../../ErrorBoundary';\nimport {ErrorDisplay} from '../../ErrorDisplay';\nimport EditRecordContent from '../EditRecordContent';\nimport useExecuteDeleteValueMutation from '../EditRecordContent/hooks/useExecuteDeleteValueMutation';\nimport useSaveValueBatchMutation from '../EditRecordContent/hooks/useExecuteSaveValueBatchMutation';\nimport {\n type DeleteMultipleValuesFunc,\n type ISubmittedValueLink,\n type ISubmittedValueStandard,\n type ISubmittedValueTree,\n type IValueToSubmit,\n type SubmitValueFunc,\n} from '../EditRecordContent/_types';\nimport editRecordReducer, {EditRecordReducerActionsTypes, initialState} from '../editRecordReducer/editRecordReducer';\nimport {EditRecordReducerContext} from '../editRecordReducer/editRecordReducerContext';\nimport {type FormInstance} from 'antd/lib/form/Form';\nimport EditRecordSidebar from '../EditRecordSidebar';\nimport EditRecordSkeleton from '../EditRecordSkeleton';\nimport {useQuery} from '@apollo/client';\nimport {getLibraryByIdQuery} from '_ui/_queries/libraries/getLibraryByIdQuery';\nimport EditRecordButtons from '../EditRecordButtons';\n\ninterface IEditRecordProps {\n antdForm: FormInstance;\n formId: string;\n isFormCreationMode: boolean;\n formElementId?: string;\n record: RecordIdentityFragment['whoAmI'] | null;\n library: string;\n onCreate?: (newRecord: RecordIdentityFragment['whoAmI']) => void;\n valuesVersion?: IValueVersion;\n showSidebar?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n scrollAllRecordSummary?: boolean;\n enableSidebar?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n sidebarContainer?: HTMLElement; // TODO: Should be removed when sidebar is fully removed from EditRecord\n forceDisableSidebarInAppStudio?: boolean; // TODO: Should be removed when sidebar is fully removed from EditRecord\n containerStyle?: CSSObject;\n withInfoButton: boolean;\n removePadding?: boolean; // TODO: This prop should be remove when EditRecord will be moved to app-studio or data-studio deleted\n}\n\nconst sidebarWidth = '352px';\n\nconst Container = styled.div<{$shouldUseLayoutWithSidebar: boolean; style: CSSObject}>`\n display: grid;\n grid-template-columns: ${props => (props.$shouldUseLayoutWithSidebar ? `minmax(0, auto) ${sidebarWidth}` : '1fr')};\n grid-template-areas: ${props => (props.$shouldUseLayoutWithSidebar ? '\"content sidebar\"' : '\"content\"')};\n overflow: hidden;\n`;\n\nconst Content = styled.div<{$shouldUseLayoutWithSidebar: boolean; $removePadding: boolean}>`\n grid-area: content;\n padding: ${props => (props.$removePadding ? 'unset' : '24px')};\n overflow-x: hidden;\n overflow-y: scroll;\n border-right: ${props =>\n props.$shouldUseLayoutWithSidebar ? '1px solid var(--general-utilities-border)' : 'none'};\n`;\n\nexport const EditRecord: FunctionComponent<IEditRecordProps> = ({\n antdForm,\n formId,\n isFormCreationMode,\n formElementId,\n record,\n library: libraryId,\n onCreate,\n valuesVersion,\n enableSidebar = false,\n showSidebar = false,\n scrollAllRecordSummary = false,\n sidebarContainer,\n forceDisableSidebarInAppStudio = false,\n containerStyle,\n withInfoButton,\n removePadding = false,\n}) => {\n const [state, dispatch] = useReducer(editRecordReducer, {\n ...initialState,\n record,\n libraryId,\n libraryLabel: null,\n valuesVersion,\n originValuesVersion: valuesVersion,\n withInfoButton,\n });\n\n const {\n loading: permissionsLoading,\n canEdit,\n isReadOnly,\n } = useCanEditRecord({...record?.library, id: libraryId}, record?.id);\n\n const {data: libraryData} = useQuery(getLibraryByIdQuery, {\n variables: {id: [libraryId]},\n });\n\n const {refetch: refetchRecordIdCardQuery} = useGetRecordIdCardQuery({\n variables: {\n id: record?.id ?? '',\n libraryId,\n },\n });\n\n const {saveValues} = useSaveValueBatchMutation();\n const {deleteValue} = useExecuteDeleteValueMutation(record);\n const [activateNewRecordMutation] = useActivateNewRecordMutation();\n\n // Update record in reducer when it changes. Might happen on record identity change (after value save)\n useEffect(() => {\n if (libraryData) {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_LIBRARY_LABEL,\n label: libraryData.libraries.list[0].label,\n });\n }\n }, [libraryData]);\n\n useEffect(() => {\n if (record && !isEqual(record, state.record)) {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_RECORD,\n record,\n });\n }\n }, [record]);\n\n useEffect(() => {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_ENABLE_SIDEBAR,\n enabled: enableSidebar,\n });\n }, [enableSidebar]);\n\n useEffect(() => {\n dispatch({\n type: EditRecordReducerActionsTypes.SET_SIDEBAR_IS_OPEN,\n isOpen: showSidebar,\n });\n }, [showSidebar]);\n\n const _handleValueSubmit: SubmitValueFunc = async (values, version) =>\n saveValues(\n record,\n values.map(val => {\n const savableValue = {...val, attribute: val.attribute.id, metadata: val.metadata};\n\n if (val.value) {\n switch (val.attribute.type) {\n case AttributeType.advanced_link:\n case AttributeType.simple_link:\n savableValue.value = (val as ISubmittedValueLink).value.id;\n break;\n case AttributeType.tree:\n savableValue.value = (val as ISubmittedValueTree).value.id;\n break;\n default:\n savableValue.value = (val as ISubmittedValueStandard).value;\n break;\n }\n }\n\n return savableValue as IValueToSubmit;\n }),\n version,\n true, // deleteEmpty\n );\n\n /**\n * Submit the whole record: create record and batch save all stored values\n */\n const _handleRecordSubmit = async (attributes: RecordFormAttributeStandardAttributeFragment[]) => {\n const activateNewRecordResult = await activateNewRecordMutation({\n fetchPolicy: 'network-only',\n variables: {\n libraryId,\n recordId: record.id,\n formId,\n },\n });\n const errors = activateNewRecordResult?.data?.activateNewRecord.valuesErrors;\n if (errors == null || errors?.length === 0) {\n if (onCreate) {\n onCreate(activateNewRecordResult?.data?.activateNewRecord?.record?.whoAmI);\n refetchRecordIdCardQuery(); // Force apollo to set cache with correct whoAmI instead of empty record\n }\n return;\n }\n antdForm.setFields(\n errors.map(error => {\n const attributeInError = attributes.find(attribute => attribute.id === error.attribute);\n\n const doesAttributeHaveMultipleFields =\n attributeInError?.multiple_values &&\n ![AttributeType.simple_link, AttributeType.advanced_link].includes(attributeInError.type);\n\n return {\n name:\n doesAttributeHaveMultipleFields && error.type === 'REQUIRED_ATTRIBUTE'\n ? [error.attribute, 0]\n : error.attribute,\n errors: [error.message],\n };\n }),\n );\n };\n\n const _handleDeleteAllValues: DeleteMultipleValuesFunc = async (attribute, values, version) => {\n const valuesToSave = values.map(value => ({\n idValue: value.id_value,\n attribute,\n value: null,\n }));\n\n return saveValues(record, valuesToSave, version, true);\n };\n\n const shouldUseLayoutWithSidebar =\n state.enableSidebar && state.isOpenSidebar && sidebarContainer === undefined && !forceDisableSidebarInAppStudio;\n\n return (\n <ErrorBoundary>\n <EditRecordReducerContext.Provider value={{state, dispatch}}>\n <Container $shouldUseLayoutWithSidebar={shouldUseLayoutWithSidebar} style={containerStyle}>\n <EditRecordButtons />\n <Content\n className=\"edit-record-content-container\"\n $shouldUseLayoutWithSidebar={shouldUseLayoutWithSidebar}\n $removePadding={removePadding}\n >\n {permissionsLoading ? (\n <EditRecordSkeleton rows={5} />\n ) : canEdit ? (\n <EditRecordContent\n antdForm={antdForm}\n formId={formId}\n isFormCreationMode={isFormCreationMode}\n formElementId={formElementId}\n record={record}\n library={libraryId}\n onRecordSubmit={_handleRecordSubmit}\n onValueSubmit={_handleValueSubmit}\n onValueDelete={deleteValue}\n onDeleteMultipleValues={_handleDeleteAllValues}\n readonly={isReadOnly}\n />\n ) : (\n <ErrorDisplay type={ErrorDisplayTypes.PERMISSION_ERROR} showActionButton={false} />\n )}\n </Content>\n {!forceDisableSidebarInAppStudio && (\n <EditRecordSidebar\n sidebarContainer={sidebarContainer}\n scrollAllRecordSummary={scrollAllRecordSummary}\n />\n )}\n </Container>\n </EditRecordReducerContext.Provider>\n </ErrorBoundary>\n );\n};\n"]}
@@ -16,3 +16,6 @@ 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';
21
+ export { useGetRecordIdCard } from './useGetRecordIdCard';
@@ -19,4 +19,7 @@ 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';
24
+ export { useGetRecordIdCard } from './useGetRecordIdCard';
22
25
  //# 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;AACvF,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,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';\nexport {useGetRecordIdCard} from './useGetRecordIdCard';\n"]}
@@ -0,0 +1 @@
1
+ export { useGetRecordIdCard } from './useGetRecordIdCard';
@@ -0,0 +1,5 @@
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
+ export { useGetRecordIdCard } from './useGetRecordIdCard';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/useGetRecordIdCard/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,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\nexport {useGetRecordIdCard} from './useGetRecordIdCard';\n"]}
@@ -0,0 +1,18 @@
1
+ export declare const useGetRecordIdCard: (recordId: string, libraryId: string) => {
2
+ data: {
3
+ id: string;
4
+ whoAmI: {
5
+ id: string;
6
+ color?: string | null;
7
+ label?: string | null;
8
+ subLabel?: string | null;
9
+ preview?: import("@leav/utils").IPreviewScalar | null;
10
+ parentContext?: Array<{
11
+ id: string;
12
+ label?: string | null;
13
+ }> | null;
14
+ };
15
+ };
16
+ loading: boolean;
17
+ error: import("@apollo/client").ApolloError;
18
+ };
@@ -0,0 +1,20 @@
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 { useGetRecordIdCardQuery } from '../../_gqlTypes';
5
+ import { NEW_RECORD_ID } from '../../index';
6
+ export const useGetRecordIdCard = (recordId, libraryId) => {
7
+ const { data, loading, error } = useGetRecordIdCardQuery({
8
+ variables: {
9
+ id: recordId,
10
+ libraryId,
11
+ },
12
+ skip: !recordId || recordId === NEW_RECORD_ID || !libraryId,
13
+ });
14
+ return {
15
+ data: data?.records?.list?.[0],
16
+ loading,
17
+ error,
18
+ };
19
+ };
20
+ //# sourceMappingURL=useGetRecordIdCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGetRecordIdCard.js","sourceRoot":"","sources":["../../../src/hooks/useGetRecordIdCard/useGetRecordIdCard.tsx"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,uBAAuB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,SAAiB,EAAE,EAAE;IACtE,MAAM,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAC,GAAG,uBAAuB,CAAC;QACnD,SAAS,EAAE;YACP,EAAE,EAAE,QAAQ;YACZ,SAAS;SACZ;QACD,IAAI,EAAE,CAAC,QAAQ,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,SAAS;KAC9D,CAAC,CAAC;IAEH,OAAO;QACH,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC9B,OAAO;QACP,KAAK;KACR,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 {useGetRecordIdCardQuery} from '_ui/_gqlTypes';\nimport {NEW_RECORD_ID} from '_ui/index';\n\nexport const useGetRecordIdCard = (recordId: string, libraryId: string) => {\n const {data, loading, error} = useGetRecordIdCardQuery({\n variables: {\n id: recordId,\n libraryId,\n },\n skip: !recordId || recordId === NEW_RECORD_ID || !libraryId,\n });\n\n return {\n data: data?.records?.list?.[0],\n loading,\n error,\n };\n};\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
6
  import { encodeMessage, decodeMessage, getExposedMethods, initClientHandlers } 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({
@@ -80,12 +89,16 @@ export const useIFrameMessenger = (options) => {
80
89
  registry.current[message.id] = frames[i];
81
90
  }
82
91
  }
92
+ dispatch({ type: 'is-registered', id: message.id }, message.id);
83
93
  break;
84
94
  case 'unregister':
85
95
  if (registry.current[message.id]) {
86
96
  delete registry.current[message.id];
87
97
  }
88
98
  break;
99
+ case 'is-registered':
100
+ setIsRegistered(true);
101
+ break;
89
102
  case 'message-to-panel':
90
103
  panelMessageHandlerRegistry.current[message.data.type]?.(message.data.payload);
91
104
  if (window === window.top) {
@@ -93,17 +106,22 @@ export const useIFrameMessenger = (options) => {
93
106
  dispatch(message, target);
94
107
  }
95
108
  break;
96
- case 'get-panel-config':
97
- clientHandlers({
98
- ...message,
99
- data: { ...message.data, panelId: getPanelIdFromEvent(event) },
100
- }, dispatch);
101
109
  default:
102
110
  if (message.type === 'change-language') {
103
111
  setLang(message.language);
104
112
  }
113
+ else if (options?.onMessageReceived) {
114
+ // Singleton mode: delegate routing to the Provider (IFrameMessengerProvider).
115
+ // The Provider resolves which iframe sent the message and calls the matching handlers.
116
+ options.onMessageReceived(event.source, message, getPanelIdFromEvent(event), dispatch, callCb, callbacksStore);
117
+ }
105
118
  else {
106
- clientHandlers(message, dispatch);
119
+ // Legacy / client mode: handle messages directly with local clientHandlers.
120
+ // get-panel-config needs panelId enriched before dispatch.
121
+ const enrichedMessage = message.type === 'get-panel-config'
122
+ ? { ...message, data: { ...message.data, panelId: getPanelIdFromEvent(event) } }
123
+ : message;
124
+ clientHandlers(enrichedMessage, dispatch);
107
125
  }
108
126
  break;
109
127
  }
@@ -117,6 +135,9 @@ export const useIFrameMessenger = (options) => {
117
135
  window.removeEventListener('message', onMessage);
118
136
  };
119
137
  }, []);
120
- return methods.current;
138
+ return {
139
+ ...methods.current,
140
+ isRegistered,
141
+ };
121
142
  };
122
143
  //# sourceMappingURL=useIFrameMessenger.js.map
@@ -1 +1 @@
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,EAAC,MAAM,OAAO,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AASzC,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAItG;;;GAGG;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;IAEjE,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;YACvB,QAAQ,EAAE,WAAW;SACxB,EACD,KAAK,CACR,CAAC;IACN,CAAC,CAAC;IAEF,MAAM,2BAA2B,GAAG,MAAM,CAA+C,EAAE,CAAC,CAAC;IAC7F,MAAM,sBAAsB,GAAoC,CAC5D,IAAY,EACZ,OAAqC,EACvC,EAAE;QACA,2BAA2B,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACxD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,WAAW,CACxB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QACjB,IAAI,MAAM,KAAK,M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cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;oBACtC,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,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,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAItG;;;;;;;;;;;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,CAA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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, 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"]}