@leav/ui 1.13.0-6f2d667e → 1.13.0-95c8de41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_gqlTypes/index.d.ts +224 -72
- package/dist/_gqlTypes/index.js +143 -61
- package/dist/_gqlTypes/index.js.map +1 -1
- package/dist/_queries/attributes/attributeDetailsFragment.js +3 -0
- package/dist/_queries/attributes/attributeDetailsFragment.js.map +1 -1
- package/dist/components/Explorer/Explorer.d.ts +5 -1
- package/dist/components/Explorer/Explorer.js +7 -0
- package/dist/components/Explorer/Explorer.js.map +1 -1
- package/dist/components/Explorer/_types.d.ts +6 -0
- package/dist/components/Explorer/_types.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/EditMonoDependencyWorkflowTreeAttribute.d.ts +8 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/EditMonoDependencyWorkflowTreeAttribute.js +34 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/EditMonoDependencyWorkflowTreeAttribute.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.d.ts +3 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.js +12 -14
- package/dist/components/Explorer/actions-mass/edit-attribute/EditTreeAttributeValuesMapping.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/_types.d.ts +15 -3
- package/dist/components/Explorer/actions-mass/edit-attribute/_types.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useDependencyValues.d.ts +13 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useDependencyValues.js +47 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useDependencyValues.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useEditionMappingState.d.ts +13 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useEditionMappingState.js +73 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useEditionMappingState.js.map +1 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useMassEditableAttributes.js +14 -17
- package/dist/components/Explorer/actions-mass/edit-attribute/useMassEditableAttributes.js.map +1 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodesCandidates.d.ts +23 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodesCandidates.js +68 -0
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodesCandidates.js.map +1 -0
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js +16 -50
- package/dist/components/Explorer/actions-mass/useEditAttributeMassAction.js.map +1 -1
- package/dist/components/Explorer/manage-view-settings/filter-items/FilterItems.js +6 -6
- package/dist/components/Explorer/manage-view-settings/filter-items/FilterItems.js.map +1 -1
- package/dist/components/Explorer/manage-view-settings/store-view-settings/viewSettingsReducer.d.ts +7 -31
- package/dist/components/Explorer/manage-view-settings/store-view-settings/viewSettingsReducer.js +9 -20
- package/dist/components/Explorer/manage-view-settings/store-view-settings/viewSettingsReducer.js.map +1 -1
- package/dist/components/Explorer/useNotifyFiltersChange.d.ts +15 -0
- package/dist/components/Explorer/useNotifyFiltersChange.js +26 -0
- package/dist/components/Explorer/useNotifyFiltersChange.js.map +1 -0
- package/dist/components/Filters/_types.d.ts +14 -0
- package/dist/components/Filters/_types.js +2 -1
- package/dist/components/Filters/_types.js.map +1 -1
- package/dist/components/Filters/context/filtersReducer.d.ts +14 -1
- package/dist/components/Filters/context/filtersReducer.js +39 -8
- package/dist/components/Filters/context/filtersReducer.js.map +1 -1
- package/dist/components/Filters/filter-items/CommonFilterItem.js +4 -1
- package/dist/components/Filters/filter-items/CommonFilterItem.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/FilterDropDown.js +15 -3
- package/dist/components/Filters/filter-items/filter-type/FilterDropDown.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/FilterDropdownContent.d.ts +3 -1
- package/dist/components/Filters/filter-items/filter-type/FilterDropdownContent.js +2 -2
- package/dist/components/Filters/filter-items/filter-type/FilterDropdownContent.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/_types.d.ts +3 -1
- package/dist/components/Filters/filter-items/filter-type/_types.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/smart-filter/SmartFilterAttributeDropdown.js +2 -3
- package/dist/components/Filters/filter-items/filter-type/smart-filter/SmartFilterAttributeDropdown.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/smart-filter/useGetSmartFilterData.d.ts +2 -4
- package/dist/components/Filters/filter-items/filter-type/smart-filter/useGetSmartFilterData.js +22 -16
- package/dist/components/Filters/filter-items/filter-type/smart-filter/useGetSmartFilterData.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js +39 -83
- package/dist/components/Filters/filter-items/filter-type/tree/TreeAttributeDropDown.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.d.ts +1 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useGetTreeData.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/tree/useTreeNodeSelection.d.ts +21 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreeNodeSelection.js +85 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreeNodeSelection.js.map +1 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreePermissions.d.ts +8 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreePermissions.js +40 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreePermissions.js.map +1 -0
- package/dist/components/Filters/filter-items/filter-type/tree/useTreesSearch.d.ts +2 -3
- package/dist/components/Filters/filter-items/filter-type/tree/useTreesSearch.js +2 -3
- package/dist/components/Filters/filter-items/filter-type/tree/useTreesSearch.js.map +1 -1
- package/dist/components/Filters/filter-items/filter-type/tree/utils/filterTreeByPermission.d.ts +1 -1
- package/dist/components/Filters/filter-items/filter-type/tree/utils/filterTreeByPermission.js +3 -4
- package/dist/components/Filters/filter-items/filter-type/tree/utils/filterTreeByPermission.js.map +1 -1
- package/dist/components/Filters/filter-items/shared/EmptyValueCheckbox.js +1 -7
- package/dist/components/Filters/filter-items/shared/EmptyValueCheckbox.js.map +1 -1
- package/dist/components/Filters/prepareFiltersForRequest.js +37 -14
- package/dist/components/Filters/prepareFiltersForRequest.js.map +1 -1
- package/dist/components/Filters/useFilters.d.ts +312 -0
- package/dist/components/Filters/useTransformFilters.js +1 -0
- package/dist/components/Filters/useTransformFilters.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useDelayedLoading/index.d.ts +1 -0
- package/dist/hooks/useDelayedLoading/index.js +5 -0
- package/dist/hooks/useDelayedLoading/index.js.map +1 -0
- package/dist/hooks/useDelayedLoading/useDelayedLoading.d.ts +17 -0
- package/dist/hooks/useDelayedLoading/useDelayedLoading.js +54 -0
- package/dist/hooks/useDelayedLoading/useDelayedLoading.js.map +1 -0
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.d.ts +3 -1
- package/dist/hooks/useIFrameMessenger/iFrameMessengerContext.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/messageHandlers.d.ts +2 -1
- package/dist/hooks/useIFrameMessenger/messageHandlers.js +9 -0
- package/dist/hooks/useIFrameMessenger/messageHandlers.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/types.d.ts +21 -2
- package/dist/hooks/useIFrameMessenger/types.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/useIFrameMessenger.d.ts +1 -0
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js +29 -7
- package/dist/hooks/useIFrameMessenger/useIFrameMessengerContext.js.map +1 -1
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.d.ts +14 -0
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.js +22 -0
- package/dist/hooks/useIFrameMessenger/useNativePanelMessengerHandlers.js.map +1 -0
- package/dist/hooks/useIFrameMessengerClient/iFrameMessengerClientContext.d.ts +1 -0
- package/dist/hooks/useIFrameMessengerClient/useIFrameMessengerClient.d.ts +1 -0
- package/dist/locales/en/shared.json +3 -1
- package/dist/locales/fr/shared.json +3 -1
- package/package.json +2 -2
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.d.ts +0 -12
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.js +0 -24
- package/dist/components/Explorer/actions-mass/edit-attribute/useTreeNodeRemapping.js.map +0 -1
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.d.ts +0 -13
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.js +0 -28
- package/dist/components/Explorer/actions-mass/edit-attribute/useValuesDistribution.js.map +0 -1
|
@@ -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,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;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"]}
|
|
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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W,CAAC,MAAM,CAAC,KAAK,CAAC;wBACzB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;wBACnD,CAAC,CAAC,SAAS;gBACjB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACf,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;wBACzB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC,CAAC;wBAC3F,CAAC,CAAC,SAAS;gBACjB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK;gBAC9B,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;gBAC9B,SAAS,EAAE;oBACP,GAAG,mBAAmB;oBACtB,UAAU,EAAE,aAAa,CAAC,WAAY;iBACzC;gBACD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,qBAAqB,CAAC,KAAK;gBAC1D,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,KAAK;aACnD,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;IAEX,OAAO;QACH,cAAc;QACd,WAAW;KACd,CAAC;AACN,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {\n type AttributeDetailsLinkAttributeFragment,\n type AttributeDetailsTreeAttributeFragment,\n AttributeFormat,\n AttributeType,\n type ExplorerAttributesQuery,\n type ExplorerLinkAttributeQuery,\n type GetViewsListQuery,\n type LinkAttributeDetailsFragment,\n RecordFilterCondition,\n type StandardAttributeDetailsFragment,\n type ViewDetailsFilterFragment,\n} from '_ui/_gqlTypes';\nimport {\n type UIFilter,\n type IUIFilterBaseAttribute,\n type IUIFilterLink,\n type IUIFilterLinkValueList,\n type IUIFilterStandard,\n type IUIFilterStandardValueList,\n type IUIFilterThrough,\n type IUIFilterTree,\n type ValidFieldFilter,\n type ValidFieldFilterLinkValuesList,\n type ValidFieldFilterStandardValuesList,\n type ValidFieldFilterThrough,\n type ValidFilter,\n} from './_types';\nimport {ThroughConditionFilter} from '_ui/types';\nimport {isLinkAttribute, isStandardAttribute, isTreeAttribute} from '_ui/_utils/attributeType';\nimport {localizedTranslation} from '@leav/utils';\nimport {useLang} from '_ui/hooks';\nimport {valueListTextConditions} from './filter-items/filter-type/useConditionOptionsByType';\nimport dayjs from 'dayjs';\nimport {type TFunction} from 'i18next';\nimport {type ITreeFilters} from './context/useGetTreeFilters';\n\nconst _isValidFieldFilter = (filter: ViewDetailsFilterFragment | UIFilter): filter is ValidFieldFilter =>\n !!filter.field;\n\nconst _isValidFieldFilterThrough = (filter: ValidFilter): filter is ValidFieldFilterThrough =>\n filter.condition === ThroughConditionFilter.THROUGH && !!filter.subCondition && !!filter.subField;\n\nconst _isValidFieldFilterStandardValuesList = (\n filter: ValidFilter,\n attribute: NonNullable<ExplorerAttributesQuery['attributes']>['list'][number],\n): filter is ValidFieldFilterStandardValuesList & {attribute: StandardAttributeDetailsFragment} =>\n valueListTextConditions.includes(filter.condition 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 smartFilter: (attributeData as StandardAttributeDetailsFragment).smart_filter ?? undefined,\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"]}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export { useIFrameMessengerHandlers } from './useIFrameMessenger/useIFrameMessen
|
|
|
20
20
|
export { IFrameMessengerProvider } from './useIFrameMessenger/useIFrameMessengerContext';
|
|
21
21
|
export { useGetRecordIdCard } from './useGetRecordIdCard';
|
|
22
22
|
export { useConfirmModal } from './useConfirmModal';
|
|
23
|
+
export { useDelayedLoading } from './useDelayedLoading';
|
package/dist/hooks/index.js
CHANGED
|
@@ -23,4 +23,5 @@ export { useIFrameMessengerHandlers } from './useIFrameMessenger/useIFrameMessen
|
|
|
23
23
|
export { IFrameMessengerProvider } from './useIFrameMessenger/useIFrameMessengerContext';
|
|
24
24
|
export { useGetRecordIdCard } from './useGetRecordIdCard';
|
|
25
25
|
export { useConfirmModal } from './useConfirmModal';
|
|
26
|
+
export { useDelayedLoading } from './useDelayedLoading';
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -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;AAChE,OAAO,EAAC,0BAA0B,EAAC,MAAM,iDAAiD,CAAC;AAC3F,OAAO,EAAC,uBAAuB,EAAC,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,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';\nexport {useConfirmModal} from './useConfirmModal';\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;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,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';\nexport {useConfirmModal} from './useConfirmModal';\nexport {useDelayedLoading} from './useDelayedLoading';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDelayedLoading';
|
|
@@ -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 * from './useDelayedLoading';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/useDelayedLoading/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,cAAc,qBAAqB,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 * from './useDelayedLoading';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prevents loader flickering by applying two UX rules:
|
|
3
|
+
*
|
|
4
|
+
* 1. **Show delay (200 ms)** — if loading ends before 200 ms, the loader is never shown.
|
|
5
|
+
* Avoids a flash for fast requests.
|
|
6
|
+
*
|
|
7
|
+
* 2. **Minimum display duration (300 ms)** — once the loader has appeared,
|
|
8
|
+
* it stays visible for at least 300 ms. Avoids a jarring disappearance for slightly slow requests.
|
|
9
|
+
*
|
|
10
|
+
* @param loading - raw loading state (e.g. `queryResult.loading`)
|
|
11
|
+
* @returns `true` only when the loader should be rendered
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const isLoaderVisible = useDelayedLoading(loading);
|
|
15
|
+
* return isLoaderVisible ? <KitLoader /> : <Content />;
|
|
16
|
+
*/
|
|
17
|
+
export declare const useDelayedLoading: (loading: boolean) => boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { useEffect, useRef, useState } from 'react';
|
|
5
|
+
const LOADER_SHOW_DELAY_MS = 200;
|
|
6
|
+
const LOADER_MIN_DURATION_MS = 300;
|
|
7
|
+
/**
|
|
8
|
+
* Prevents loader flickering by applying two UX rules:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Show delay (200 ms)** — if loading ends before 200 ms, the loader is never shown.
|
|
11
|
+
* Avoids a flash for fast requests.
|
|
12
|
+
*
|
|
13
|
+
* 2. **Minimum display duration (300 ms)** — once the loader has appeared,
|
|
14
|
+
* it stays visible for at least 300 ms. Avoids a jarring disappearance for slightly slow requests.
|
|
15
|
+
*
|
|
16
|
+
* @param loading - raw loading state (e.g. `queryResult.loading`)
|
|
17
|
+
* @returns `true` only when the loader should be rendered
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const isLoaderVisible = useDelayedLoading(loading);
|
|
21
|
+
* return isLoaderVisible ? <KitLoader /> : <Content />;
|
|
22
|
+
*/
|
|
23
|
+
export const useDelayedLoading = (loading) => {
|
|
24
|
+
const loadingStartRef = useRef(null);
|
|
25
|
+
const [isLoaderVisible, setIsLoaderVisible] = useState(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!loading) {
|
|
28
|
+
if (loadingStartRef.current === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const elapsed = Date.now() - loadingStartRef.current;
|
|
32
|
+
const loaderHasBeenShown = elapsed >= LOADER_SHOW_DELAY_MS;
|
|
33
|
+
if (!loaderHasBeenShown) {
|
|
34
|
+
loadingStartRef.current = null;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const remaining = LOADER_SHOW_DELAY_MS + LOADER_MIN_DURATION_MS - elapsed;
|
|
38
|
+
loadingStartRef.current = null;
|
|
39
|
+
if (remaining <= 0) {
|
|
40
|
+
setIsLoaderVisible(false);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const timer = setTimeout(() => setIsLoaderVisible(false), remaining);
|
|
44
|
+
return () => clearTimeout(timer);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
loadingStartRef.current = Date.now();
|
|
49
|
+
const showTimer = setTimeout(() => setIsLoaderVisible(true), LOADER_SHOW_DELAY_MS);
|
|
50
|
+
return () => clearTimeout(showTimer);
|
|
51
|
+
}, [loading]);
|
|
52
|
+
return isLoaderVisible;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=useDelayedLoading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDelayedLoading.js","sourceRoot":"","sources":["../../../src/hooks/useDelayedLoading/useDelayedLoading.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAA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C,kBAAkB,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACnF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,eAAe,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 {useEffect, useRef, useState} from 'react';\n\nconst LOADER_SHOW_DELAY_MS = 200;\nconst LOADER_MIN_DURATION_MS = 300;\n\n/**\n * Prevents loader flickering by applying two UX rules:\n *\n * 1. **Show delay (200 ms)** — if loading ends before 200 ms, the loader is never shown.\n * Avoids a flash for fast requests.\n *\n * 2. **Minimum display duration (300 ms)** — once the loader has appeared,\n * it stays visible for at least 300 ms. Avoids a jarring disappearance for slightly slow requests.\n *\n * @param loading - raw loading state (e.g. `queryResult.loading`)\n * @returns `true` only when the loader should be rendered\n *\n * @example\n * const isLoaderVisible = useDelayedLoading(loading);\n * return isLoaderVisible ? <KitLoader /> : <Content />;\n */\nexport const useDelayedLoading = (loading: boolean): boolean => {\n const loadingStartRef = useRef<number | null>(null);\n const [isLoaderVisible, setIsLoaderVisible] = useState(false);\n\n useEffect(() => {\n if (!loading) {\n if (loadingStartRef.current === null) {\n return;\n }\n const elapsed = Date.now() - loadingStartRef.current;\n const loaderHasBeenShown = elapsed >= LOADER_SHOW_DELAY_MS;\n\n if (!loaderHasBeenShown) {\n loadingStartRef.current = null;\n return;\n }\n\n const remaining = LOADER_SHOW_DELAY_MS + LOADER_MIN_DURATION_MS - elapsed;\n loadingStartRef.current = null;\n\n if (remaining <= 0) {\n setIsLoaderVisible(false);\n } else {\n const timer = setTimeout(() => setIsLoaderVisible(false), remaining);\n return () => clearTimeout(timer);\n }\n return;\n }\n\n loadingStartRef.current = Date.now();\n\n const showTimer = setTimeout(() => setIsLoaderVisible(true), LOADER_SHOW_DELAY_MS);\n return () => clearTimeout(showTimer);\n }, [loading]);\n\n return isLoaderVisible;\n};\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { type RegisterHandlers } from './types';
|
|
1
|
+
import { type DispatchToNativePanel, type RegisterHandlers, type RegisterNativePanelHandlers } from './types';
|
|
2
2
|
export interface IIFrameMessengerContext {
|
|
3
3
|
registerHandlers: RegisterHandlers;
|
|
4
|
+
registerNativePanelHandlers: RegisterNativePanelHandlers;
|
|
5
|
+
dispatchToNativePanel: DispatchToNativePanel;
|
|
4
6
|
changeLangInAllFrames: (language: string) => void;
|
|
5
7
|
}
|
|
6
8
|
export declare const IFrameMessengerContext: import("react").Context<IIFrameMessengerContext>;
|
|
@@ -1 +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;
|
|
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;AAUpC,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 DispatchToNativePanel, type RegisterHandlers, type RegisterNativePanelHandlers} from './types';\n\nexport interface IIFrameMessengerContext {\n registerHandlers: RegisterHandlers;\n registerNativePanelHandlers: RegisterNativePanelHandlers;\n dispatchToNativePanel: DispatchToNativePanel;\n changeLangInAllFrames: (language: string) => void;\n}\n\nexport const IFrameMessengerContext = createContext<IIFrameMessengerContext>(null);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MutableRefObject } from 'react';
|
|
2
|
-
import { type AlertMessage, type Callbacks, type CallCbFunction, type ClosePanelMessage, type IUseIFrameMessengerOptions, type GetUrlMessage, type Message, type MessageDispatcher, type MessageHandler, type MessageToPanelMessage, type ModalConfirmMessage, type NavigateToIframeMessage, type NavigateToPanelMessage, type NotificationMessage, type SimpleMessage, type OpenFlapPanelMessage, type GetPanelConfigMessage } from './types';
|
|
2
|
+
import { type AlertMessage, type Callbacks, type CallCbFunction, type ClosePanelMessage, type ExplorerViewChangedMessage, type IUseIFrameMessengerOptions, type GetUrlMessage, type Message, type MessageDispatcher, type MessageHandler, type MessageToPanelMessage, type ModalConfirmMessage, type NavigateToIframeMessage, type NavigateToPanelMessage, type NotificationMessage, type SimpleMessage, type OpenFlapPanelMessage, type GetPanelConfigMessage } from './types';
|
|
3
3
|
export declare const encodeMessage: (message: Message) => string;
|
|
4
4
|
export declare const decodeMessage: (raw: string) => Message | undefined;
|
|
5
5
|
export declare const initClientHandlers: (callCb: CallCbFunction, options?: IUseIFrameMessengerOptions, callbacksList?: MutableRefObject<Callbacks>) => MessageHandler;
|
|
@@ -16,4 +16,5 @@ export declare const getExposedMethods: (callbacksStore: MutableRefObject<Callba
|
|
|
16
16
|
closeFlapPanel: () => void;
|
|
17
17
|
getPanelConfig: (data: GetPanelConfigMessage["data"]) => void;
|
|
18
18
|
getUrl: (data: GetUrlMessage["data"]) => void;
|
|
19
|
+
explorerViewChanged: (data: ExplorerViewChangedMessage["data"]) => void;
|
|
19
20
|
};
|
|
@@ -75,6 +75,12 @@ export const initClientHandlers = (callCb, options, callbacksList) => (message,
|
|
|
75
75
|
case 'get-url':
|
|
76
76
|
options?.handlers?.onGetUrl?.(setCallbacks(message.id, message.__frameId, message.data, callCb, message.overrides));
|
|
77
77
|
break;
|
|
78
|
+
case 'explorer-view-changed':
|
|
79
|
+
options?.handlers?.onExplorerViewChanged?.(message.data);
|
|
80
|
+
break;
|
|
81
|
+
case 'view-config-update':
|
|
82
|
+
options?.handlers?.onViewConfigUpdate?.(message.data);
|
|
83
|
+
break;
|
|
78
84
|
default:
|
|
79
85
|
break;
|
|
80
86
|
}
|
|
@@ -141,5 +147,8 @@ export const getExposedMethods = (callbacksStore, dispatch) => ({
|
|
|
141
147
|
const { data: nextData, overrides } = storeCallbacks(data, id, callbacksStore);
|
|
142
148
|
dispatch?.({ type: 'get-url', data: nextData, id, overrides });
|
|
143
149
|
},
|
|
150
|
+
explorerViewChanged: (data) => {
|
|
151
|
+
dispatch?.({ type: 'explorer-view-changed', data });
|
|
152
|
+
},
|
|
144
153
|
});
|
|
145
154
|
//# sourceMappingURL=messageHandlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageHandlers.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/messageHandlers.ts"],"names":[],"mappings":"AAIA,OAAO,EAiBH,QAAQ,GAIX,MAAM,SAAS,CAAC;AAEjB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAU,EAAE,CACtD,IAAI,CAAC,SAAS,CAAC;IACX,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;IAChC,CAAC,QAAQ,CAAC,EAAE,IAAI;CACnB,CAAC,CAAC;AAEP,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAuB,EAAE;IAC9D,IAAI,CAAC;QACD,MAAM,OAAO,GAAoB,IAAI,CAAC,KAAK,CAAC,GAAG,CAA+B,CAAC;QAC/E,IAAI,QAAQ,IA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;QAClD,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAC,CAAC,CAAC;IAChD,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACjB,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,kBAAkB,EAAC,CAAC,CAAC;IAC3C,CAAC;IACD,cAAc,EAAE,CAAC,IAAmC,EAAE,EAAE;QACpD,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAC,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;QAC7E,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAyC,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC3G,CAAC;IACD,MAAM,EAAE,CAAC,IAA2B,EAAE,EAAE;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAC,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;QAC7E,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAiC,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC1F,CAAC;CACJ,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type MutableRefObject} from 'react';\nimport {\n type AlertMessage,\n type CallbackFunction,\n type Callbacks,\n type CallCbFunction,\n type ClosePanelMessage,\n type IEncodedMessage,\n type IUseIFrameMessengerOptions,\n type GetUrlMessage,\n type Message,\n type MessageDispatcher,\n type MessageHandler,\n type MessageToPanelMessage,\n type ModalConfirmMessage,\n type NavigateToIframeMessage,\n type NavigateToPanelMessage,\n type NotificationMessage,\n packetId,\n type SimpleMessage,\n type OpenFlapPanelMessage,\n type GetPanelConfigMessage,\n} from './types';\n\nexport const encodeMessage = (message: Message): string =>\n JSON.stringify({\n payload: JSON.stringify(message),\n [packetId]: true,\n });\n\nexport const decodeMessage = (raw: string): Message | undefined => {\n try {\n const decoded: IEncodedMessage = JSON.parse(raw) as unknown as IEncodedMessage;\n if (packetId in decoded && decoded[packetId] === true) {\n return JSON.parse(decoded.payload) as Message;\n }\n } catch (e) {\n return undefined;\n }\n return undefined;\n};\n\nconst getCallback = (path: string, callbacksList?: MutableRefObject<Callbacks>): CallbackFunction | null => {\n if (!callbacksList?.current) {\n return null;\n }\n const pathArray = path.split('.');\n let callback: CallbackFunction | Callbacks | Record<string, CallbackFunction> = callbacksList.current;\n pathArray.forEach(part => (callback = (callback as Callbacks | Record<string, CallbackFunction>)?.[part]));\n return typeof callback === 'function' ? callback : null;\n};\n\nconst setCallbacks = (\n id: string,\n frameId: string,\n data: unknown,\n callCb: CallCbFunction,\n overrides?: string[],\n): unknown => {\n if (!overrides) {\n return data;\n }\n\n const nextData = {...(data as Record<string, unknown>)};\n overrides.forEach((key: string) => {\n nextData[key] = (...args: unknown[]) => {\n callCb(`${id}.${key}`, args, frameId);\n };\n });\n return nextData;\n};\n\nexport const initClientHandlers: (\n callCb: CallCbFunction,\n options?: IUseIFrameMessengerOptions,\n callbacksList?: MutableRefObject<Callbacks>,\n) => MessageHandler = (callCb, options, callbacksList) => (message, dispatch) => {\n switch (message.type) {\n case 'modal-confirm':\n options?.handlers?.onModalConfirm?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as ModalConfirmMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'alert':\n options?.handlers?.onAlert?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as AlertMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'notification':\n options?.handlers?.onNotification?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as NotificationMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'message':\n options?.handlers?.onMessage?.(message.data, message.id, dispatch, callCb);\n break;\n case 'on-call-callback':\n // TODO How to know if handler can be removed from callbacksList ?\n getCallback(message.path, callbacksList)?.(...(message.data as never[]));\n break;\n case 'navigate-to-panel':\n options?.handlers?.onNavigateToPanel?.(message.data);\n break;\n case 'close-panel':\n options?.handlers?.onClosePanel?.(message.data);\n break;\n case 'navigate-to-iframe':\n options?.handlers?.onNavigateToIframe?.(message.data);\n break;\n case 'open-flap-panel':\n options?.handlers?.onOpenFlapPanel?.(message.data);\n break;\n case 'close-flap-panel':\n options?.handlers?.onCloseFlapPanel?.();\n break;\n case 'get-panel-config':\n options?.handlers?.onGetPanelConfig?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetPanelConfigMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'get-url':\n options?.handlers?.onGetUrl?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetUrlMessage['data'],\n );\n break;\n default:\n break;\n }\n};\n\nconst storeCallbacks = (\n data: unknown,\n id: string,\n callbacksStore: MutableRefObject<Callbacks>,\n): {data: unknown; overrides: string[]} => {\n const nextData = {...(data as Record<string, unknown>)};\n const overrides: string[] = [];\n Object.entries(nextData).forEach(([key, value]) => {\n if (typeof value === 'function') {\n callbacksStore.current[id] = {\n ...callbacksStore.current[id],\n [key]: value as CallbackFunction,\n };\n overrides.push(key);\n }\n });\n return {data: nextData, overrides};\n};\n\nexport const getExposedMethods = (callbacksStore: MutableRefObject<Callbacks>, dispatch?: MessageDispatcher) => ({\n showModalConfirm: (data: ModalConfirmMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'modal-confirm', data: nextData as ModalConfirmMessage['data'], id, overrides});\n },\n showAlert: (data: AlertMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'alert', data: nextData as AlertMessage['data'], id, overrides});\n },\n showNotification: (data: NotificationMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'notification', data: nextData as NotificationMessage['data'], id, overrides});\n },\n messageToParent: (data: SimpleMessage['data']) => {\n const id = Date.now().toString();\n dispatch?.({type: 'message', data, id});\n },\n navigateToPanel: (data: NavigateToPanelMessage['data']) => {\n dispatch?.({type: 'navigate-to-panel', data});\n },\n closePanel: (data: ClosePanelMessage['data']) => {\n dispatch?.({type: 'close-panel', data});\n },\n navigateToIframe: (data: NavigateToIframeMessage['data']) => {\n dispatch?.({type: 'navigate-to-iframe', data});\n },\n messageToPanel: (data: MessageToPanelMessage['data']) => {\n dispatch?.({type: 'message-to-panel', data});\n },\n openFlapPanel: (data: OpenFlapPanelMessage['data']) => {\n dispatch?.({type: 'open-flap-panel', data});\n },\n closeFlapPanel: () => {\n dispatch?.({type: 'close-flap-panel'});\n },\n getPanelConfig: (data: GetPanelConfigMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-panel-config', data: nextData as GetPanelConfigMessage['data'], id, overrides});\n },\n getUrl: (data: GetUrlMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-url', data: nextData as GetUrlMessage['data'], id, overrides});\n },\n});\n"]}
|
|
1
|
+
{"version":3,"file":"messageHandlers.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/messageHandlers.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G,CAAC;IACD,MAAM,EAAE,CAAC,IAA2B,EAAE,EAAE;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAC,GAAG,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;QAC7E,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAiC,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC,CAAC;IAC1F,CAAC;IACD,mBAAmB,EAAE,CAAC,IAAwC,EAAE,EAAE;QAC9D,QAAQ,EAAE,CAAC,EAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAC,CAAC,CAAC;IACtD,CAAC;CACJ,CAAC,CAAC","sourcesContent":["// 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} from 'react';\nimport {\n type AlertMessage,\n type CallbackFunction,\n type Callbacks,\n type CallCbFunction,\n type ClosePanelMessage,\n type ExplorerViewChangedMessage,\n type IEncodedMessage,\n type IUseIFrameMessengerOptions,\n type GetUrlMessage,\n type Message,\n type MessageDispatcher,\n type MessageHandler,\n type MessageToPanelMessage,\n type ModalConfirmMessage,\n type NavigateToIframeMessage,\n type NavigateToPanelMessage,\n type NotificationMessage,\n packetId,\n type SimpleMessage,\n type OpenFlapPanelMessage,\n type GetPanelConfigMessage,\n type ViewConfigUpdateMessage,\n} from './types';\n\nexport const encodeMessage = (message: Message): string =>\n JSON.stringify({\n payload: JSON.stringify(message),\n [packetId]: true,\n });\n\nexport const decodeMessage = (raw: string): Message | undefined => {\n try {\n const decoded: IEncodedMessage = JSON.parse(raw) as unknown as IEncodedMessage;\n if (packetId in decoded && decoded[packetId] === true) {\n return JSON.parse(decoded.payload) as Message;\n }\n } catch (e) {\n return undefined;\n }\n return undefined;\n};\n\nconst getCallback = (path: string, callbacksList?: MutableRefObject<Callbacks>): CallbackFunction | null => {\n if (!callbacksList?.current) {\n return null;\n }\n const pathArray = path.split('.');\n let callback: CallbackFunction | Callbacks | Record<string, CallbackFunction> = callbacksList.current;\n pathArray.forEach(part => (callback = (callback as Callbacks | Record<string, CallbackFunction>)?.[part]));\n return typeof callback === 'function' ? callback : null;\n};\n\nconst setCallbacks = (\n id: string,\n frameId: string,\n data: unknown,\n callCb: CallCbFunction,\n overrides?: string[],\n): unknown => {\n if (!overrides) {\n return data;\n }\n\n const nextData = {...(data as Record<string, unknown>)};\n overrides.forEach((key: string) => {\n nextData[key] = (...args: unknown[]) => {\n callCb(`${id}.${key}`, args, frameId);\n };\n });\n return nextData;\n};\n\nexport const initClientHandlers: (\n callCb: CallCbFunction,\n options?: IUseIFrameMessengerOptions,\n callbacksList?: MutableRefObject<Callbacks>,\n) => MessageHandler = (callCb, options, callbacksList) => (message, dispatch) => {\n switch (message.type) {\n case 'modal-confirm':\n options?.handlers?.onModalConfirm?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as ModalConfirmMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'alert':\n options?.handlers?.onAlert?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as AlertMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'notification':\n options?.handlers?.onNotification?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as NotificationMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'message':\n options?.handlers?.onMessage?.(message.data, message.id, dispatch, callCb);\n break;\n case 'on-call-callback':\n // TODO How to know if handler can be removed from callbacksList ?\n getCallback(message.path, callbacksList)?.(...(message.data as never[]));\n break;\n case 'navigate-to-panel':\n options?.handlers?.onNavigateToPanel?.(message.data);\n break;\n case 'close-panel':\n options?.handlers?.onClosePanel?.(message.data);\n break;\n case 'navigate-to-iframe':\n options?.handlers?.onNavigateToIframe?.(message.data);\n break;\n case 'open-flap-panel':\n options?.handlers?.onOpenFlapPanel?.(message.data);\n break;\n case 'close-flap-panel':\n options?.handlers?.onCloseFlapPanel?.();\n break;\n case 'get-panel-config':\n options?.handlers?.onGetPanelConfig?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetPanelConfigMessage['data'],\n message.id,\n dispatch,\n callCb,\n );\n break;\n case 'get-url':\n options?.handlers?.onGetUrl?.(\n setCallbacks(\n message.id,\n message.__frameId,\n message.data,\n callCb,\n message.overrides,\n ) as GetUrlMessage['data'],\n );\n break;\n case 'explorer-view-changed':\n options?.handlers?.onExplorerViewChanged?.(message.data as ExplorerViewChangedMessage['data']);\n break;\n case 'view-config-update':\n options?.handlers?.onViewConfigUpdate?.(message.data as ViewConfigUpdateMessage['data']);\n break;\n default:\n break;\n }\n};\n\nconst storeCallbacks = (\n data: unknown,\n id: string,\n callbacksStore: MutableRefObject<Callbacks>,\n): {data: unknown; overrides: string[]} => {\n const nextData = {...(data as Record<string, unknown>)};\n const overrides: string[] = [];\n Object.entries(nextData).forEach(([key, value]) => {\n if (typeof value === 'function') {\n callbacksStore.current[id] = {\n ...callbacksStore.current[id],\n [key]: value as CallbackFunction,\n };\n overrides.push(key);\n }\n });\n return {data: nextData, overrides};\n};\n\nexport const getExposedMethods = (callbacksStore: MutableRefObject<Callbacks>, dispatch?: MessageDispatcher) => ({\n showModalConfirm: (data: ModalConfirmMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'modal-confirm', data: nextData as ModalConfirmMessage['data'], id, overrides});\n },\n showAlert: (data: AlertMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'alert', data: nextData as AlertMessage['data'], id, overrides});\n },\n showNotification: (data: NotificationMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'notification', data: nextData as NotificationMessage['data'], id, overrides});\n },\n messageToParent: (data: SimpleMessage['data']) => {\n const id = Date.now().toString();\n dispatch?.({type: 'message', data, id});\n },\n navigateToPanel: (data: NavigateToPanelMessage['data']) => {\n dispatch?.({type: 'navigate-to-panel', data});\n },\n closePanel: (data: ClosePanelMessage['data']) => {\n dispatch?.({type: 'close-panel', data});\n },\n navigateToIframe: (data: NavigateToIframeMessage['data']) => {\n dispatch?.({type: 'navigate-to-iframe', data});\n },\n messageToPanel: (data: MessageToPanelMessage['data']) => {\n dispatch?.({type: 'message-to-panel', data});\n },\n openFlapPanel: (data: OpenFlapPanelMessage['data']) => {\n dispatch?.({type: 'open-flap-panel', data});\n },\n closeFlapPanel: () => {\n dispatch?.({type: 'close-flap-panel'});\n },\n getPanelConfig: (data: GetPanelConfigMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-panel-config', data: nextData as GetPanelConfigMessage['data'], id, overrides});\n },\n getUrl: (data: GetUrlMessage['data']) => {\n const id = Date.now().toString();\n const {data: nextData, overrides} = storeCallbacks(data, id, callbacksStore);\n dispatch?.({type: 'get-url', data: nextData as GetUrlMessage['data'], id, overrides});\n },\n explorerViewChanged: (data: ExplorerViewChangedMessage['data']) => {\n dispatch?.({type: 'explorer-view-changed', data});\n },\n});\n"]}
|
|
@@ -6,6 +6,7 @@ import { type ToastedAlertProps } from 'aristid-ds/dist/Kit/Feedback/Alert/types
|
|
|
6
6
|
import { type LibraryIdSchema, type WhereSchema, type PanelIdSchema, type PanelSchema, type PanelIFrameSchema, type FlapPanelIdSchema, type attributeExplorerPanelSchema, type baseExplorerPanelSchema } from '../../hooks/useIFrameMessenger/schema';
|
|
7
7
|
import { type AnyPrimitive } from '@leav/utils';
|
|
8
8
|
import { type IRecordIdentity, type ITreeNodeWithRecord } from '../../types';
|
|
9
|
+
import { type SerializedView } from '../../components/Explorer/_types';
|
|
9
10
|
export declare const packetId = "__fromIframeMessenger";
|
|
10
11
|
export interface IEncodedMessage {
|
|
11
12
|
payload: string;
|
|
@@ -16,6 +17,7 @@ export type ComponentPropsWithKey<T extends keyof JSX.IntrinsicElements | JSXEle
|
|
|
16
17
|
};
|
|
17
18
|
export interface IMessageBase {
|
|
18
19
|
__frameId?: string;
|
|
20
|
+
__targetPanelId?: string;
|
|
19
21
|
}
|
|
20
22
|
export type ModalConfirmMessage = IMessageBase & {
|
|
21
23
|
type: 'modal-confirm';
|
|
@@ -145,12 +147,25 @@ export type GetPanelConfigMessage = IMessageBase & {
|
|
|
145
147
|
};
|
|
146
148
|
overrides?: string[];
|
|
147
149
|
};
|
|
148
|
-
export type
|
|
150
|
+
export type ExplorerViewChangedMessage = IMessageBase & {
|
|
151
|
+
type: 'explorer-view-changed';
|
|
152
|
+
data: {
|
|
153
|
+
serializedView: SerializedView;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export type ViewConfigUpdateMessage = IMessageBase & {
|
|
157
|
+
type: 'view-config-update';
|
|
158
|
+
data: {
|
|
159
|
+
targetPanelId: string;
|
|
160
|
+
serializedView: SerializedView;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
export type MessageToParent = ModalConfirmMessage | AlertMessage | NotificationMessage | SimpleMessage | RegisterMessage | UnregisterMessage | NavigateToPanelMessage | ClosePanelMessage | NavigateToIframeMessage | MessageToPanelMessage | OpenFlapPanelMessage | CloseFlapPanelMessage | GetUrlMessage | GetPanelConfigMessage | ExplorerViewChangedMessage;
|
|
149
164
|
export type MessageFromParent = (IMessageBase & {
|
|
150
165
|
type: 'on-call-callback';
|
|
151
166
|
path: string;
|
|
152
167
|
data: unknown;
|
|
153
|
-
}) | IsRegisteredMessage | ChangeLanguageMessage;
|
|
168
|
+
}) | IsRegisteredMessage | ChangeLanguageMessage | ViewConfigUpdateMessage;
|
|
154
169
|
export type Message = MessageToParent | MessageFromParent;
|
|
155
170
|
export type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;
|
|
156
171
|
export type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;
|
|
@@ -161,6 +176,8 @@ export type MessageToPanelMessageHandler = (data: MessageToPanelMessage['data'][
|
|
|
161
176
|
export type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) => void;
|
|
162
177
|
export type UnregisterHandlers = () => void;
|
|
163
178
|
export type RegisterHandlers = (iframeRef: RefObject<HTMLIFrameElement>, handlers: IUseIFrameMessengerOptions['handlers']) => UnregisterHandlers;
|
|
179
|
+
export type RegisterNativePanelHandlers = (panelId: string, handlers: IUseIFrameMessengerOptions['handlers']) => UnregisterHandlers;
|
|
180
|
+
export type DispatchToNativePanel = (panelId: string, message: Message) => void;
|
|
164
181
|
export interface IUseIFrameMessengerOptions {
|
|
165
182
|
ref?: RefObject<HTMLIFrameElement>;
|
|
166
183
|
id?: string;
|
|
@@ -177,6 +194,8 @@ export interface IUseIFrameMessengerOptions {
|
|
|
177
194
|
onGetUrl?: (data: GetUrlMessage['data']) => void;
|
|
178
195
|
onGetPanelConfig?: (data: GetPanelConfigMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;
|
|
179
196
|
onCloseFlapPanel?: () => void;
|
|
197
|
+
onExplorerViewChanged?: (data: ExplorerViewChangedMessage['data']) => void;
|
|
198
|
+
onViewConfigUpdate?: (data: ViewConfigUpdateMessage['data']) => void;
|
|
180
199
|
};
|
|
181
200
|
}
|
|
182
201
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/types.ts"],"names":[],"mappings":"AAsBA,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';\nimport {type SerializedView} from '_ui/components/Explorer/_types';\n\nexport const packetId = '__fromIframeMessenger';\n\nexport interface IEncodedMessage {\n payload: string;\n [packetId]: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ComponentPropsWithKey<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> =\n ComponentProps<T> & {\n key?: Key;\n };\n\nexport interface IMessageBase {\n __frameId?: string;\n __targetPanelId?: string;\n}\n\nexport type ModalConfirmMessage = IMessageBase & {\n type: 'modal-confirm';\n id: string;\n data: IKitConfirmDialog;\n overrides?: string[];\n};\n\nexport type AlertMessage = IMessageBase & {\n type: 'alert';\n id: string;\n data: ToastedAlertProps;\n overrides?: string[];\n};\n\nexport type NotificationMessage = IMessageBase & {\n type: 'notification';\n id: string;\n data: ComponentPropsWithKey<typeof KitNotification>;\n overrides?: string[];\n};\n\nexport type ChangeLanguageMessage = IMessageBase & {\n type: 'change-language';\n language: string;\n};\n\nexport type SimpleMessage = IMessageBase & {\n type: 'message';\n id: string;\n data: unknown;\n};\n\nexport type RegisterMessage = IMessageBase & {\n type: 'register';\n id: string;\n};\n\nexport type UnregisterMessage = IMessageBase & {\n type: 'unregister';\n id: string;\n};\n\nexport type IsRegisteredMessage = IMessageBase & {\n type: 'is-registered';\n id: string;\n};\n\nexport type Panel = z.infer<typeof PanelSchema>;\n\nexport type AttributeExplorerPanel = Panel &\n z.infer<typeof baseExplorerPanelSchema> &\n z.infer<typeof attributeExplorerPanelSchema>;\n\nexport type LibraryId = z.infer<typeof LibraryIdSchema>;\n\nexport type PanelId = z.infer<typeof PanelIdSchema>;\n\nexport type Where = z.infer<typeof WhereSchema>;\n\nexport type PanelIFrame = z.infer<typeof PanelIFrameSchema>;\n\ntype FlapPanelId = z.infer<typeof FlapPanelIdSchema>;\n\nexport type NavigateToPanelMessage = IMessageBase & {\n type: 'navigate-to-panel';\n data: {\n where: Where;\n libraryId: LibraryId;\n panelId?: PanelId;\n recordId?: string;\n flapRecordId?: string;\n flapLibraryId?: LibraryId;\n flapPanelId?: FlapPanelId;\n queryParams?: Record<string, string> & {\n redirectUrl?: string;\n formInitialValues?: Record<string, Array<AnyPrimitive | IRecordIdentity | ITreeNodeWithRecord>>;\n };\n };\n};\n\nexport type ClosePanelMessage = IMessageBase & {\n type: 'close-panel';\n data: {\n recordId: string;\n where: string;\n recordPanelId: string;\n };\n};\n\nexport type NavigateToIframeMessage = IMessageBase & {\n type: 'navigate-to-iframe';\n data: {\n panel: PanelIFrame;\n destination: {libraryId: LibraryId};\n where: Where;\n recordId: string;\n recordPanelId: string;\n };\n};\n\nexport type MessageToPanelMessage = IMessageBase & {\n type: 'message-to-panel';\n data: {\n type: string;\n target?: string;\n payload: unknown;\n };\n};\n\nexport type OpenFlapPanelMessage = IMessageBase & {\n type: 'open-flap-panel';\n data: {\n flapRecordId: string;\n flapLibraryId: LibraryId;\n flapPanelId: FlapPanelId;\n };\n};\n\nexport type CloseFlapPanelMessage = IMessageBase & {\n type: 'close-flap-panel';\n};\n\nexport type GetUrlMessage = IMessageBase & {\n type: 'get-url';\n id: string;\n data: {\n onGetUrl: (url: string) => void;\n flapParams?: {\n flapRecordId: string;\n flapLibraryId: LibraryId;\n flapPanelId: FlapPanelId;\n };\n panelParams?: {\n recordId: string;\n where: Where;\n recordPanelId: PanelId;\n };\n };\n overrides?: string[];\n};\n\nexport type GetPanelConfigMessage = IMessageBase & {\n type: 'get-panel-config';\n id: string;\n data: {\n panelId?: string;\n onGetPanelConfig: (data: PanelIFrame) => void;\n };\n overrides?: string[];\n};\n\nexport type ExplorerViewChangedMessage = IMessageBase & {\n type: 'explorer-view-changed';\n data: {\n serializedView: SerializedView;\n };\n};\n\nexport type ViewConfigUpdateMessage = IMessageBase & {\n type: 'view-config-update';\n data: {\n targetPanelId: string;\n serializedView: SerializedView;\n };\n};\n\nexport type MessageToParent =\n | ModalConfirmMessage\n | AlertMessage\n | NotificationMessage\n | SimpleMessage\n | RegisterMessage\n | UnregisterMessage\n | NavigateToPanelMessage\n | ClosePanelMessage\n | NavigateToIframeMessage\n | MessageToPanelMessage\n | OpenFlapPanelMessage\n | CloseFlapPanelMessage\n | GetUrlMessage\n | GetPanelConfigMessage\n | ExplorerViewChangedMessage;\n\nexport type MessageFromParent =\n | (IMessageBase & {\n type: 'on-call-callback';\n path: string;\n data: unknown;\n })\n | IsRegisteredMessage\n | ChangeLanguageMessage\n | ViewConfigUpdateMessage;\n\nexport type Message = MessageToParent | MessageFromParent;\n\nexport type MessageHandler<T = Message> = (message: T, dispatch: MessageDispatcher<T>) => void;\nexport type MessageDispatcher<T = Message> = (message: T, frameId?: string) => void;\n\nexport type CallCbFunction = (path: string, data: unknown, frameId: string) => void;\n\nexport type CallbackFunction = (...args: never[]) => void;\nexport type Callbacks = Record<string, Record<string, CallbackFunction>>;\n\nexport type MessageToPanelMessageHandler = (data: MessageToPanelMessage['data']['payload']) => void;\nexport type AddMessageToPanelMessageHandler = (type: string, handler: MessageToPanelMessageHandler) => void;\n\nexport type UnregisterHandlers = () => void;\nexport type RegisterHandlers = (\n iframeRef: RefObject<HTMLIFrameElement>,\n handlers: IUseIFrameMessengerOptions['handlers'],\n) => UnregisterHandlers;\nexport type RegisterNativePanelHandlers = (\n panelId: string,\n handlers: IUseIFrameMessengerOptions['handlers'],\n) => UnregisterHandlers;\nexport type DispatchToNativePanel = (panelId: string, message: Message) => void;\n\nexport interface IUseIFrameMessengerOptions {\n ref?: RefObject<HTMLIFrameElement>;\n id?: string;\n onMessageReceived?: (\n senderWindow: Window | null,\n message: Message,\n panelId: string | null,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n callbacksStore: MutableRefObject<Callbacks>,\n ) => void;\n handlers?: {\n onModalConfirm?: (\n data: ModalConfirmMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onAlert?: (data: AlertMessage['data'], id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;\n onNotification?: (\n data: NotificationMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onMessage?: (data: unknown, id: string, dispatch: MessageDispatcher, callCb: CallCbFunction) => void;\n onNavigateToPanel?: (data: NavigateToPanelMessage['data']) => void;\n onClosePanel?: (data: ClosePanelMessage['data']) => void;\n onNavigateToIframe?: (data: NavigateToIframeMessage['data']) => void;\n onOpenFlapPanel?: (data: OpenFlapPanelMessage['data']) => void;\n onGetUrl?: (data: GetUrlMessage['data']) => void;\n onGetPanelConfig?: (\n data: GetPanelConfigMessage['data'],\n id: string,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n ) => void;\n onCloseFlapPanel?: () => void;\n onExplorerViewChanged?: (data: ExplorerViewChangedMessage['data']) => void;\n onViewConfigUpdate?: (data: ViewConfigUpdateMessage['data']) => void;\n };\n}\n"]}
|
|
@@ -29,4 +29,5 @@ export declare const useIFrameMessenger: (options?: IUseIFrameMessengerOptions)
|
|
|
29
29
|
closeFlapPanel: () => void;
|
|
30
30
|
getPanelConfig: (data: import("./types").GetPanelConfigMessage["data"]) => void;
|
|
31
31
|
getUrl: (data: import("./types").GetUrlMessage["data"]) => void;
|
|
32
|
+
explorerViewChanged: (data: import("./types").ExplorerViewChangedMessage["data"]) => void;
|
|
32
33
|
};
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
5
5
|
import { useCallback, useMemo, useRef } from 'react';
|
|
6
6
|
import { useIFrameMessenger } from './useIFrameMessenger';
|
|
7
|
-
import { initClientHandlers } from './messageHandlers';
|
|
7
|
+
import { encodeMessage, initClientHandlers } from './messageHandlers';
|
|
8
8
|
import { IFrameMessengerContext } from './iFrameMessengerContext';
|
|
9
9
|
/**
|
|
10
10
|
* Singleton Provider for the IFrameMessenger system.
|
|
@@ -20,14 +20,32 @@ export const IFrameMessengerProvider = ({ children }) => {
|
|
|
20
20
|
// Using RefObject as key (instead of Window) avoids timing issues: contentWindow
|
|
21
21
|
// may not be available yet when the iframe mounts and registers its handlers.
|
|
22
22
|
const handlersMap = useRef(new Map());
|
|
23
|
+
// Maps native React panel IDs to their handlers.
|
|
24
|
+
// Same-window postMessage is used as transport: __targetPanelId in the envelope routes to the right entry.
|
|
25
|
+
const nativePanelHandlersMap = useRef(new Map());
|
|
23
26
|
// Called by useIFrameMessenger for every non-system message.
|
|
24
|
-
// Finds the handlers registered for the sender
|
|
27
|
+
// Finds the handlers registered for the sender and dispatches the message to them.
|
|
25
28
|
const onMessageReceived = useCallback((senderWindow, message, panelId, dispatch, callCb, callbacksStore) => {
|
|
26
29
|
// event.source is null when the sender iframe was unmounted before the message
|
|
27
30
|
// was processed — the browser clears the reference on iframe removal.
|
|
28
31
|
if (!senderWindow) {
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
34
|
+
// Same-window message: dispatched via dispatchToNativePanel.
|
|
35
|
+
// Route to the native panel identified by __targetPanelId.
|
|
36
|
+
if (senderWindow === window) {
|
|
37
|
+
const targetPanelId = message.__targetPanelId;
|
|
38
|
+
if (!targetPanelId) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const handlers = nativePanelHandlersMap.current.get(targetPanelId);
|
|
42
|
+
if (!handlers) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const clientHandlers = initClientHandlers(callCb, { handlers }, callbacksStore);
|
|
46
|
+
clientHandlers(message, dispatch);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
31
49
|
let matchedHandlers;
|
|
32
50
|
for (const [ref, handlers] of handlersMap.current) {
|
|
33
51
|
if (ref.current?.contentWindow === senderWindow) {
|
|
@@ -48,12 +66,16 @@ export const IFrameMessengerProvider = ({ children }) => {
|
|
|
48
66
|
const { changeLangInAllFrames } = useIFrameMessenger({ onMessageReceived });
|
|
49
67
|
const registerHandlers = useCallback((iframeRef, handlers) => {
|
|
50
68
|
handlersMap.current.set(iframeRef, handlers);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
return () => handlersMap.current.delete(iframeRef);
|
|
70
|
+
}, []);
|
|
71
|
+
const registerNativePanelHandlers = useCallback((panelId, handlers) => {
|
|
72
|
+
nativePanelHandlersMap.current.set(panelId, handlers);
|
|
73
|
+
return () => nativePanelHandlersMap.current.delete(panelId);
|
|
74
|
+
}, []);
|
|
75
|
+
const dispatchToNativePanel = useCallback((panelId, message) => {
|
|
76
|
+
window.postMessage(encodeMessage({ ...message, __targetPanelId: panelId }), '*');
|
|
55
77
|
}, []);
|
|
56
|
-
const contextValue = useMemo(() => ({ registerHandlers, changeLangInAllFrames }), []);
|
|
78
|
+
const contextValue = useMemo(() => ({ registerHandlers, registerNativePanelHandlers, dispatchToNativePanel, changeLangInAllFrames }), []);
|
|
57
79
|
return _jsx(IFrameMessengerContext.Provider, { value: contextValue, children: children });
|
|
58
80
|
};
|
|
59
81
|
//# sourceMappingURL=useIFrameMessengerContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerContext.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAwD,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC1G,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useIFrameMessengerContext.js","sourceRoot":"","sources":["../../../src/hooks/useIFrameMessenger/useIFrameMessengerContext.tsx"],"names":[],"mappings":";AAAA,oFAAoF;AACpF,sCAAsC;AACtC,sEAAsE;AACtE,OAAO,EAAwD,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC1G,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAUpE,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAEhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EAAC,QAAQ,EAAwB,EAAE,EAAE;IACzE,uDAAuD;IACvD,iFAAiF;IACjF,8EAA8E;IAC9E,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,EAAwE,CAAC,CAAC;IAE5G,iDAAiD;IACjD,2GAA2G;IAC3G,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAkD,CAAC,CAAC;IAEjG,6DAA6D;IAC7D,mFAAmF;IACnF,MAAM,iBAAiB,GAAG,WAAW,CACjC,CACI,YAA2B,EAC3B,OAAgB,EAChB,OAAsB,EACtB,QAA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AAC;AAC9G,CAAC,CAAC","sourcesContent":["// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06\n// This file is released under LGPL V3\n// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt\nimport {type MutableRefObject, type ReactNode, type RefObject, useCallback, useMemo, useRef} from 'react';\nimport {useIFrameMessenger} from './useIFrameMessenger';\nimport {encodeMessage, initClientHandlers} from './messageHandlers';\nimport {\n type Callbacks,\n type CallCbFunction,\n type Message,\n type MessageDispatcher,\n type IUseIFrameMessengerOptions,\n type RegisterHandlers,\n type RegisterNativePanelHandlers,\n} from './types';\nimport {IFrameMessengerContext} from './iFrameMessengerContext';\n\n/**\n * Singleton Provider for the IFrameMessenger system.\n * Must be mounted once above all `PanelCustom` instances.\n *\n * Owns a single `window.addEventListener('message')` (via `useIFrameMessenger`)\n * and routes incoming messages to the correct iframe's handlers using `handlersMap`.\n *\n * Each `PanelCustom` registers/deregisters its handlers via `useIFrameMessengerHandlers`.\n */\nexport const IFrameMessengerProvider = ({children}: {children: ReactNode}) => {\n // Maps each iframe's RefObject to its set of handlers.\n // Using RefObject as key (instead of Window) avoids timing issues: contentWindow\n // may not be available yet when the iframe mounts and registers its handlers.\n const handlersMap = useRef(new Map<RefObject<HTMLIFrameElement>, IUseIFrameMessengerOptions['handlers']>());\n\n // Maps native React panel IDs to their handlers.\n // Same-window postMessage is used as transport: __targetPanelId in the envelope routes to the right entry.\n const nativePanelHandlersMap = useRef(new Map<string, IUseIFrameMessengerOptions['handlers']>());\n\n // Called by useIFrameMessenger for every non-system message.\n // Finds the handlers registered for the sender and dispatches the message to them.\n const onMessageReceived = useCallback(\n (\n senderWindow: Window | null,\n message: Message,\n panelId: string | null,\n dispatch: MessageDispatcher,\n callCb: CallCbFunction,\n callbacksStore: MutableRefObject<Callbacks>,\n ) => {\n // event.source is null when the sender iframe was unmounted before the message\n // was processed — the browser clears the reference on iframe removal.\n if (!senderWindow) {\n return;\n }\n\n // Same-window message: dispatched via dispatchToNativePanel.\n // Route to the native panel identified by __targetPanelId.\n if (senderWindow === window) {\n const targetPanelId = message.__targetPanelId;\n if (!targetPanelId) {\n return;\n }\n const handlers = nativePanelHandlersMap.current.get(targetPanelId);\n if (!handlers) {\n return;\n }\n const clientHandlers = initClientHandlers(callCb, {handlers}, callbacksStore);\n clientHandlers(message, dispatch);\n return;\n }\n\n let matchedHandlers: IUseIFrameMessengerOptions['handlers'] | undefined;\n for (const [ref, handlers] of handlersMap.current) {\n if (ref.current?.contentWindow === senderWindow) {\n matchedHandlers = handlers;\n break;\n }\n }\n\n // No registered handlers for this sender: either the iframe called unregisterHandlers\n // before its last message was processed (race condition on unmount), or the message\n // originates from an unrelated frame that passed decodeMessage validation.\n if (!matchedHandlers) {\n return;\n }\n\n const enrichedMessage =\n message.type === 'get-panel-config' ? {...message, data: {...message.data, panelId}} : message;\n\n const clientHandlers = initClientHandlers(callCb, {handlers: matchedHandlers}, callbacksStore);\n clientHandlers(enrichedMessage, dispatch);\n },\n [],\n );\n\n const {changeLangInAllFrames} = useIFrameMessenger({onMessageReceived});\n\n const registerHandlers: RegisterHandlers = useCallback((iframeRef, handlers) => {\n handlersMap.current.set(iframeRef, handlers);\n return () => handlersMap.current.delete(iframeRef);\n }, []);\n\n const registerNativePanelHandlers: RegisterNativePanelHandlers = useCallback((panelId, handlers) => {\n nativePanelHandlersMap.current.set(panelId, handlers);\n return () => nativePanelHandlersMap.current.delete(panelId);\n }, []);\n\n const dispatchToNativePanel = useCallback((panelId: string, message: Message) => {\n window.postMessage(encodeMessage({...message, __targetPanelId: panelId}), '*');\n }, []);\n\n const contextValue = useMemo(\n () => ({registerHandlers, registerNativePanelHandlers, dispatchToNativePanel, changeLangInAllFrames}),\n [],\n );\n\n return <IFrameMessengerContext.Provider value={contextValue}>{children}</IFrameMessengerContext.Provider>;\n};\n"]}
|