@beinformed/ui 1.65.26 → 1.65.28

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 (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/esm/hooks/useModularUI.js +1 -1
  3. package/esm/hooks/useModularUI.js.flow +1 -1
  4. package/esm/hooks/useModularUI.js.map +1 -1
  5. package/esm/hooks/useModularUIModel.js +1 -0
  6. package/esm/hooks/useModularUIModel.js.flow +1 -0
  7. package/esm/hooks/useModularUIModel.js.map +1 -1
  8. package/esm/modularui/ModularUIRequest.js +10 -8
  9. package/esm/modularui/ModularUIRequest.js.flow +8 -10
  10. package/esm/modularui/ModularUIRequest.js.map +1 -1
  11. package/esm/react-server/__tests__/serverUtil.spec.js.flow +1 -1
  12. package/esm/react-server/contextPath.js +0 -1
  13. package/esm/react-server/contextPath.js.flow +0 -2
  14. package/esm/react-server/contextPath.js.map +1 -1
  15. package/esm/react-server/serverUtil.js +11 -5
  16. package/esm/react-server/serverUtil.js.flow +13 -9
  17. package/esm/react-server/serverUtil.js.map +1 -1
  18. package/esm/redux/_i18n/I18nReducer.js +3 -1
  19. package/esm/redux/_i18n/I18nReducer.js.flow +2 -1
  20. package/esm/redux/_i18n/I18nReducer.js.map +1 -1
  21. package/esm/redux/_modularui/ModularUIActions.js +4 -1
  22. package/esm/redux/_modularui/ModularUIActions.js.flow +2 -1
  23. package/esm/redux/_modularui/ModularUIActions.js.map +1 -1
  24. package/esm/redux/actions/Preferences.js +16 -8
  25. package/esm/redux/actions/Preferences.js.flow +16 -8
  26. package/esm/redux/actions/Preferences.js.map +1 -1
  27. package/esm/utils/fetch/xhr.js +3 -1
  28. package/esm/utils/fetch/xhr.js.flow +2 -1
  29. package/esm/utils/fetch/xhr.js.map +1 -1
  30. package/lib/hooks/useModularUI.js +1 -1
  31. package/lib/hooks/useModularUI.js.map +1 -1
  32. package/lib/hooks/useModularUIModel.js +1 -0
  33. package/lib/hooks/useModularUIModel.js.map +1 -1
  34. package/lib/modularui/ModularUIRequest.js +10 -8
  35. package/lib/modularui/ModularUIRequest.js.map +1 -1
  36. package/lib/react-server/contextPath.js +0 -3
  37. package/lib/react-server/contextPath.js.map +1 -1
  38. package/lib/react-server/serverUtil.js +10 -3
  39. package/lib/react-server/serverUtil.js.map +1 -1
  40. package/lib/redux/_i18n/I18nReducer.js +3 -1
  41. package/lib/redux/_i18n/I18nReducer.js.map +1 -1
  42. package/lib/redux/_modularui/ModularUIActions.js +4 -1
  43. package/lib/redux/_modularui/ModularUIActions.js.map +1 -1
  44. package/lib/redux/actions/Preferences.js +16 -8
  45. package/lib/redux/actions/Preferences.js.map +1 -1
  46. package/lib/utils/fetch/xhr.js +3 -1
  47. package/lib/utils/fetch/xhr.js.map +1 -1
  48. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"serverUtil.js","names":["createMemoryHistory","has","deepmerge","configureStore","availableLocales","Locales","getPreferredLocale","setLocales","setServerPreference","setThemePreference","setPreference","setAllContentInDataSetting","setLoginPreferences","setDateTimeSettings","getEnabledLocales","IllegalArgumentException","initModels","getLocale","ModularUIRequest","createReduxStore","requestHref","customReducers","initialState","history","initialEntries","toString","store","setI18n","locales","request","Array","isArray","mergedLocales","_mapInstanceProperty","call","locale","code","customLocale","_findInstanceProperty","custLocale","forEach","some","push","enabledLocales","_filterInstanceProperty","_context","_includesInstanceProperty","localesInstance","preferredLocale","dispatch","setServerPreferencesFromArray","serverPreferences","serverPreference","name","defaultValue","type","setServerPreferences","preferencesProvider","isStudioContext","setConfigurationTheme","configTheme","configFileLocation","getLayoutConfigFileLocation","configFilePath","_startsWithInstanceProperty","dataFetcher","fetch","Error","setApplication","getState","application","fetchSync","connectKey","key","model","e","handleErrors","state","error","shouldThrowOnServer","dehydrate","modularui","status","lastModification","undefined","filteredState","_JSON$stringify","replace","createHead","sheet","UUID","helmetContext","style","getStyleTags","meta","helmet"],"sources":["../../src/react-server/serverUtil.js"],"sourcesContent":["// @flow\nimport { createMemoryHistory } from \"history\";\nimport { has } from \"../utils/helpers/objects\";\nimport deepmerge from \"deepmerge\";\n\nimport configureStore from \"../redux/store/configureStore\";\n\nimport { availableLocales } from \"../i18n/Locales\";\nimport Locales from \"../i18n/Locales\";\n\nimport { getPreferredLocale } from \"./requestInformation\";\nimport { setLocales } from \"../redux/_i18n/I18nActions\";\n\nimport {\n setServerPreference,\n setThemePreference,\n setPreference,\n setAllContentInDataSetting,\n setLoginPreferences,\n setDateTimeSettings,\n} from \"../redux/actions/Preferences\";\n\nimport { getEnabledLocales } from \"../constants/Settings\";\n\nimport IllegalArgumentException from \"../exceptions/IllegalArgumentException\";\n\nimport { initModels } from \"../redux/_modularui/ModularUIActions\";\nimport { getLocale } from \"../redux/selectors/i18n\";\n\nimport ModularUIRequest from \"../modularui/ModularUIRequest\";\n\nimport type { LocaleConfiguration } from \"../i18n/types\";\nimport type { ReduxState, ReduxStore } from \"../redux/types\";\nimport type Href from \"../models/href/Href\";\nimport type { RouterHistory } from \"react-router\";\n\nexport type PreferenceValue = {\n name: string,\n defaultValue?: string | null,\n type?: string,\n};\n\n/**\n */\nconst createReduxStore = (\n requestHref: Href,\n customReducers: Object,\n initialState?: $Shape<ReduxState>,\n): ReduxStore => {\n // $FlowExpectedError\n const history: RouterHistory = createMemoryHistory({\n initialEntries: [requestHref.toString()],\n });\n\n const { store } = configureStore(history, customReducers, initialState);\n\n return store;\n};\n\n/**\n */\nconst setI18n = (\n store: ReduxStore,\n locales: Array<LocaleConfiguration> = [],\n request: HttpServletRequestJava,\n) => {\n if (!Array.isArray(locales)) {\n throw new IllegalArgumentException(\"locales must be an array of objects\");\n }\n if (!request) {\n throw new IllegalArgumentException(\"missing request argument\");\n }\n\n const mergedLocales = availableLocales.map((locale) => {\n const code = locale.code;\n const customLocale = locales.find((custLocale) => custLocale.code === code);\n\n if (customLocale) {\n return deepmerge(locale, customLocale);\n }\n\n return locale;\n });\n\n locales.forEach((customLocale) => {\n if (!mergedLocales.some((locale) => locale.code === customLocale.code)) {\n mergedLocales.push(customLocale);\n }\n });\n\n const enabledLocales = mergedLocales.filter((locale: LocaleConfiguration) =>\n getEnabledLocales().includes(locale.code),\n );\n\n const localesInstance = new Locales(enabledLocales);\n const preferredLocale = getPreferredLocale(request, localesInstance);\n store.dispatch(setLocales(localesInstance, preferredLocale ?? \"en\"));\n};\n\nconst setServerPreferencesFromArray = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>,\n) => {\n serverPreferences.forEach((serverPreference) => {\n if (typeof serverPreference === \"object\") {\n const { name, defaultValue, type } = serverPreference;\n store.dispatch(setServerPreference(name, defaultValue, type));\n } else {\n store.dispatch(setServerPreference(serverPreference, null));\n }\n });\n};\n\n/**\n * Server preferences can be suplied by an array of preference names,\n * or an array of objects which has the name, an optional default value and an optional type.<br>\n * When the type is set to string, a comma separated value is not converted to an array:\n *\n * @example\n * // value becomes an array [default1, default2]\n * { name: \"prefName\", defaultValue: \"default1, default2\" }\n * // value remains a string \"default1, default2\"\n * { name: \"prefName\", defaultValue: \"default1, default2\", type: \"string\" }\n *\n * @param store\n * @param serverPreferences\n */\nconst setServerPreferences = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>,\n) => {\n if (Array.isArray(serverPreferences)) {\n setServerPreferencesFromArray(store, serverPreferences);\n }\n\n store.dispatch(setAllContentInDataSetting());\n store.dispatch(setLoginPreferences());\n store.dispatch(setDateTimeSettings());\n\n if (\n preferencesProvider &&\n preferencesProvider.isStudioContext &&\n preferencesProvider.isStudioContext()\n ) {\n store.dispatch(setPreference(\"isStudioContext\", true));\n }\n};\n\n/**\n */\nconst setConfigurationTheme = (store: ReduxStore) => {\n let configTheme = null;\n\n const configFileLocation = preferencesProvider.getLayoutConfigFileLocation();\n if (typeof configFileLocation === \"string\") {\n const configFilePath = configFileLocation.startsWith(\"/\")\n ? `/resource${configFileLocation}`\n : `/resource/${configFileLocation}`;\n\n configTheme = dataFetcher.fetch(configFilePath);\n\n if (configTheme) {\n store.dispatch(setThemePreference(configTheme));\n } else {\n throw new Error(\n `Could not read theme configuration file from: ${configFilePath}`,\n );\n }\n }\n};\n\n/**\n */\nconst setApplication = (store: ReduxStore) => {\n try {\n const locale = getLocale(store.getState());\n const application = new ModularUIRequest(\"/\", {\n locale: locale,\n }).fetchSync();\n\n application.connectKey = `application(/)(${locale})`;\n\n store.dispatch(\n initModels([\n {\n key: `application(/)(${locale})`,\n model: application,\n },\n ]),\n );\n } catch (e) {\n // swallow error, in this case we just don't pre-cache the webapplication,\n // which has not much difference for the end user\n }\n};\n\n/**\n */\nconst handleErrors = (store: ReduxStore) => {\n const state = store.getState();\n\n if (\n state.error &&\n (state.error.shouldThrowOnServer ||\n !has(state.error, \"shouldThrowOnServer\"))\n ) {\n throw state.error;\n }\n};\n\n/**\n */\nconst dehydrate = (store: ReduxStore): string => {\n const state = store.getState();\n\n const modularui: {\n [key: string]: { status: string, lastModification: number, model: ?Object },\n } = {};\n\n for (const key in state.modularui) {\n const { status, model, lastModification } = state.modularui[key];\n\n if (model) {\n modularui[key] = {\n status,\n lastModification,\n model: model.dehydrate(),\n };\n } else {\n modularui[key] = {\n status,\n lastModification,\n model: undefined,\n };\n }\n }\n\n const filteredState = {\n ...state,\n modularui,\n };\n\n return JSON.stringify(filteredState).replace(/</g, \"\\\\u003c\");\n};\n\n/**\n */\nconst createHead = (\n sheet: any,\n UUID: string,\n helmetContext?: Object,\n): Object => {\n const style = sheet.getStyleTags();\n const meta = helmetContext ? [...helmetContext.helmet.meta] : [];\n\n if (helmetContext) {\n return {\n ...helmetContext.helmet,\n style,\n meta,\n };\n }\n\n return {\n style,\n meta,\n };\n};\n\nexport {\n createReduxStore,\n setI18n,\n setApplication,\n setServerPreferences,\n setConfigurationTheme,\n createHead,\n handleErrors,\n dehydrate,\n};\n"],"mappings":";;;;;;AACA,SAASA,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,GAAG,QAAQ,0BAA0B;AAC9C,OAAOC,SAAS,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MAAMR,GAAG,IAAII,KAAK,CAACI,SAAS,EAAE;IACjC,MAAM;MAAEC,MAAM;MAAER,KAAK;MAAES;IAAiB,CAAC,GAAGN,KAAK,CAACI,SAAS,CAACR,GAAG,CAAC;IAEhE,IAAIC,KAAK,EAAE;MACTO,SAAS,CAACR,GAAG,CAAC,GAAG;QACfS,MAAM;QACNC,gBAAgB;QAChBT,KAAK,EAAEA,KAAK,CAACM,SAAS,CAAC;MACzB,CAAC;IACH,CAAC,MAAM;MACLC,SAAS,CAACR,GAAG,CAAC,GAAG;QACfS,MAAM;QACNC,gBAAgB;QAChBT,KAAK,EAAEU;MACT,CAAC;IACH;EACF;EAEA,MAAMC,aAAa,GAAG;IACpB,GAAGR,KAAK;IACRI;EACF,CAAC;EAED,OAAOK,eAAA,CAAeD,aAAa,CAAC,CAACE,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;AAC/D,CAAC;;AAED;AACA;AACA,MAAMC,UAAU,GAAGA,CACjBC,KAAU,EACVC,IAAY,EACZC,aAAsB,KACX;EACX,MAAMC,KAAK,GAAGH,KAAK,CAACI,YAAY,CAAC,CAAC;EAClC,MAAMC,IAAI,GAAGH,aAAa,GAAG,CAAC,GAAGA,aAAa,CAACI,MAAM,CAACD,IAAI,CAAC,GAAG,EAAE;EAEhE,IAAIH,aAAa,EAAE;IACjB,OAAO;MACL,GAAGA,aAAa,CAACI,MAAM;MACvBH,KAAK;MACLE;IACF,CAAC;EACH;EAEA,OAAO;IACLF,KAAK;IACLE;EACF,CAAC;AACH,CAAC;AAED,SACE3E,gBAAgB,EAChBQ,OAAO,EACPyC,cAAc,EACdZ,oBAAoB,EACpBG,qBAAqB,EACrB6B,UAAU,EACVZ,YAAY,EACZI,SAAS","ignoreList":[]}
1
+ {"version":3,"file":"serverUtil.js","names":["createMemoryHistory","has","deepmerge","configureStore","Locales","availableLocales","getPreferredLocale","setLocales","setServerPreference","setThemePreference","setPreference","setAllContentInDataSetting","setLoginPreferences","setDateTimeSettings","getEnabledLocales","IllegalArgumentException","initModels","getLocale","ModularUIRequest","createReduxStore","requestHref","customReducers","initialState","history","initialEntries","toString","store","setI18n","locales","request","Array","isArray","mergedLocales","_mapInstanceProperty","call","locale","code","customLocale","_findInstanceProperty","custLocale","forEach","some","push","enabledLocales","_filterInstanceProperty","_context","_includesInstanceProperty","localesInstance","preferredLocale","dispatch","setServerPreferencesFromArray","serverPreferences","serverPreference","name","defaultValue","type","setServerPreferences","_globalThis","preferencesProvider","isStudioContext","setConfigurationTheme","configTheme","configFileLocation","getLayoutConfigFileLocation","configFilePath","_startsWithInstanceProperty","dataFetcher","fetch","Error","setApplication","getState","application","fetchSync","connectKey","key","model","e","handleErrors","state","error","shouldThrowOnServer","dehydrate","modularui","status","lastModification","undefined","filteredState","_JSON$stringify","replace","createHead","sheet","UUID","helmetContext","style","getStyleTags","meta","helmet"],"sources":["../../src/react-server/serverUtil.js"],"sourcesContent":["// @flow\nimport { createMemoryHistory } from \"history\";\nimport { has } from \"../utils/helpers/objects\";\nimport deepmerge from \"deepmerge\";\n\nimport configureStore from \"../redux/store/configureStore\";\n\nimport Locales, { availableLocales } from \"../i18n/Locales\";\n\nimport { getPreferredLocale } from \"./requestInformation\";\nimport { setLocales } from \"../redux/_i18n/I18nActions\";\n\nimport {\n setServerPreference,\n setThemePreference,\n setPreference,\n setAllContentInDataSetting,\n setLoginPreferences,\n setDateTimeSettings,\n} from \"../redux/actions/Preferences\";\n\nimport { getEnabledLocales } from \"../constants/Settings\";\n\nimport IllegalArgumentException from \"../exceptions/IllegalArgumentException\";\n\nimport { initModels } from \"../redux/_modularui/ModularUIActions\";\nimport { getLocale } from \"../redux/selectors/i18n\";\n\nimport ModularUIRequest from \"../modularui/ModularUIRequest\";\n\nimport type { LocaleConfiguration } from \"../i18n/types\";\nimport type { ReduxState, ReduxStore } from \"../redux/types\";\nimport type Href from \"../models/href/Href\";\nimport type { RouterHistory } from \"react-router\";\n\nexport type PreferenceValue = {\n name: string,\n defaultValue?: string | null,\n type?: string,\n};\n\n/**\n */\nconst createReduxStore = (\n requestHref: Href,\n customReducers: Object,\n initialState?: $Shape<ReduxState>,\n): ReduxStore => {\n // $FlowExpectedError\n const history: RouterHistory = createMemoryHistory({\n initialEntries: [requestHref.toString()],\n });\n\n const { store } = configureStore(history, customReducers, initialState);\n\n return store;\n};\n\n/**\n */\nconst setI18n = (\n store: ReduxStore,\n locales: Array<LocaleConfiguration> = [],\n request: HttpServletRequestJava,\n) => {\n if (!Array.isArray(locales)) {\n throw new IllegalArgumentException(\"locales must be an array of objects\");\n }\n if (!request) {\n throw new IllegalArgumentException(\"missing request argument\");\n }\n\n const mergedLocales = availableLocales.map((locale) => {\n const code = locale.code;\n const customLocale = locales.find((custLocale) => custLocale.code === code);\n\n if (customLocale) {\n return deepmerge(locale, customLocale);\n }\n\n return locale;\n });\n\n locales.forEach((customLocale) => {\n if (!mergedLocales.some((locale) => locale.code === customLocale.code)) {\n mergedLocales.push(customLocale);\n }\n });\n\n const enabledLocales = mergedLocales.filter((locale: LocaleConfiguration) =>\n getEnabledLocales().includes(locale.code),\n );\n\n const localesInstance = new Locales(enabledLocales);\n const preferredLocale = getPreferredLocale(request, localesInstance);\n store.dispatch(setLocales(localesInstance, preferredLocale ?? \"en\"));\n};\n\nconst setServerPreferencesFromArray = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>,\n) => {\n serverPreferences.forEach((serverPreference) => {\n if (typeof serverPreference === \"object\") {\n const { name, defaultValue, type } = serverPreference;\n store.dispatch(setServerPreference(name, defaultValue, type));\n } else {\n store.dispatch(setServerPreference(serverPreference, null));\n }\n });\n};\n\n/**\n * Server preferences can be suplied by an array of preference names,\n * or an array of objects which has the name, an optional default value and an optional type.<br>\n * When the type is set to string, a comma separated value is not converted to an array:\n *\n * @example\n * // value becomes an array [default1, default2]\n * { name: \"prefName\", defaultValue: \"default1, default2\" }\n * // value remains a string \"default1, default2\"\n * { name: \"prefName\", defaultValue: \"default1, default2\", type: \"string\" }\n *\n * @param store\n * @param serverPreferences\n */\nconst setServerPreferences = (\n store: ReduxStore,\n serverPreferences: Array<string | PreferenceValue>,\n) => {\n if (Array.isArray(serverPreferences)) {\n setServerPreferencesFromArray(store, serverPreferences);\n }\n\n store.dispatch(setAllContentInDataSetting());\n store.dispatch(setLoginPreferences());\n store.dispatch(setDateTimeSettings());\n\n // $FlowIssue\n if (typeof globalThis.preferencesProvider?.isStudioContext === \"function\") {\n store.dispatch(\n setPreference(\n \"isStudioContext\",\n // $FlowIssue\n globalThis.preferencesProvider?.isStudioContext(),\n ),\n );\n }\n};\n\n/**\n */\nconst setConfigurationTheme = (store: ReduxStore) => {\n let configTheme = null;\n\n const configFileLocation =\n // $FlowIssue\n globalThis.preferencesProvider?.getLayoutConfigFileLocation();\n if (typeof configFileLocation === \"string\") {\n const configFilePath = configFileLocation.startsWith(\"/\")\n ? `/resource${configFileLocation}`\n : `/resource/${configFileLocation}`;\n\n configTheme = dataFetcher.fetch(configFilePath);\n\n if (configTheme) {\n store.dispatch(setThemePreference(configTheme));\n } else {\n throw new Error(\n `Could not read theme configuration file from: ${configFilePath}`,\n );\n }\n }\n};\n\n/**\n */\nconst setApplication = (store: ReduxStore) => {\n try {\n const locale = getLocale(store.getState());\n const application = new ModularUIRequest(\"/\", {\n locale: locale,\n }).fetchSync();\n\n application.connectKey = `application(/)(${locale})`;\n\n store.dispatch(\n initModels([\n {\n key: `application(/)(${locale})`,\n model: application,\n },\n ]),\n );\n } catch (e) {\n // swallow error, in this case we just don't pre-cache the webapplication,\n // which has not much difference for the end user\n }\n};\n\n/**\n */\nconst handleErrors = (store: ReduxStore) => {\n const state = store.getState();\n\n if (\n state.error &&\n (state.error.shouldThrowOnServer ||\n !has(state.error, \"shouldThrowOnServer\"))\n ) {\n throw state.error;\n }\n};\n\n/**\n */\nconst dehydrate = (store: ReduxStore): string => {\n const state = store.getState();\n\n const modularui: {\n [key: string]: { status: string, lastModification: number, model: ?Object },\n } = {};\n\n for (const key in state.modularui) {\n const { status, model, lastModification } = state.modularui[key];\n\n if (model) {\n modularui[key] = {\n status,\n lastModification,\n model: model.dehydrate(),\n };\n } else {\n modularui[key] = {\n status,\n lastModification,\n model: undefined,\n };\n }\n }\n\n const filteredState = {\n ...state,\n modularui,\n };\n\n return JSON.stringify(filteredState).replace(/</g, \"\\\\u003c\");\n};\n\n/**\n */\nconst createHead = (\n sheet: any,\n UUID: string,\n helmetContext?: Object,\n): Object => {\n const style = sheet.getStyleTags();\n const meta = helmetContext ? [...helmetContext.helmet.meta] : [];\n\n if (helmetContext) {\n return {\n ...helmetContext.helmet,\n style,\n meta,\n };\n }\n\n return {\n style,\n meta,\n };\n};\n\nexport {\n createReduxStore,\n setI18n,\n setApplication,\n setServerPreferences,\n setConfigurationTheme,\n createHead,\n handleErrors,\n dehydrate,\n};\n"],"mappings":";;;;;;;AACA,SAASA,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,GAAG,QAAQ,0BAA0B;AAC9C,OAAOC,SAAS,MAAM,WAAW;AAEjC,OAAOC,cAAc,MAAM,+BAA+B;AAE1D,OAAOC,OAAO,IAAIC,gBAAgB,QAAQ,iBAAiB;AAE3D,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,UAAU,QAAQ,4BAA4B;AAEvD,SACEC,mBAAmB,EACnBC,kBAAkB,EAClBC,aAAa,EACbC,0BAA0B,EAC1BC,mBAAmB,EACnBC,mBAAmB,QACd,8BAA8B;AAErC,SAASC,iBAAiB,QAAQ,uBAAuB;AAEzD,OAAOC,wBAAwB,MAAM,wCAAwC;AAE7E,SAASC,UAAU,QAAQ,sCAAsC;AACjE,SAASC,SAAS,QAAQ,yBAAyB;AAEnD,OAAOC,gBAAgB,MAAM,+BAA+B;AAa5D;AACA;AACA,MAAMC,gBAAgB,GAAGA,CACvBC,WAAiB,EACjBC,cAAsB,EACtBC,YAAiC,KAClB;EACf;EACA,MAAMC,OAAsB,GAAGvB,mBAAmB,CAAC;IACjDwB,cAAc,EAAE,CAAC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,GAAGA,CACjBC,KAAU,EACVC,IAAY,EACZC,aAAsB,KACX;EACX,MAAMC,KAAK,GAAGH,KAAK,CAACI,YAAY,CAAC,CAAC;EAClC,MAAMC,IAAI,GAAGH,aAAa,GAAG,CAAC,GAAGA,aAAa,CAACI,MAAM,CAACD,IAAI,CAAC,GAAG,EAAE;EAEhE,IAAIH,aAAa,EAAE;IACjB,OAAO;MACL,GAAGA,aAAa,CAACI,MAAM;MACvBH,KAAK;MACLE;IACF,CAAC;EACH;EAEA,OAAO;IACLF,KAAK;IACLE;EACF,CAAC;AACH,CAAC;AAED,SACE5E,gBAAgB,EAChBQ,OAAO,EACP0C,cAAc,EACdb,oBAAoB,EACpBI,qBAAqB,EACrB6B,UAAU,EACVZ,YAAY,EACZI,SAAS","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import _globalThis from "@babel/runtime-corejs3/core-js/global-this";
1
2
  import Cache from "../../utils/browser/Cache";
2
3
  import { setCookie, clearCookie } from "../../utils/browser/Cookies";
3
4
  import Locales from "../../i18n/Locales";
@@ -44,7 +45,8 @@ const setLocales = (state, {
44
45
  };
45
46
  };
46
47
  const getDefaultLocale = () => {
47
- return navigator?.language?.split("-")[0] || "en";
48
+ // $FlowIssue
49
+ return _globalThis.navigator?.language?.split("-")[0] || "en";
48
50
  };
49
51
 
50
52
  // REDUCER
@@ -55,7 +55,8 @@ const setLocales = (
55
55
  };
56
56
 
57
57
  const getDefaultLocale = () => {
58
- return navigator?.language?.split("-")[0] || "en";
58
+ // $FlowIssue
59
+ return globalThis.navigator?.language?.split("-")[0] || "en";
59
60
  };
60
61
 
61
62
  // REDUCER
@@ -1 +1 @@
1
- {"version":3,"file":"I18nReducer.js","names":["Cache","setCookie","clearCookie","Locales","updateLocale","state","locale","locales","length","clear","setLocales","getDefaultLocale","navigator","language","split","initialState","I18nReducer","action","type","payload"],"sources":["../../../src/redux/_i18n/I18nReducer.js"],"sourcesContent":["// @flow\nimport Cache from \"../../utils/browser/Cache\";\nimport { setCookie, clearCookie } from \"../../utils/browser/Cookies\";\n\nimport Locales from \"../../i18n/Locales\";\n\nimport type { Reducer } from \"redux\";\nimport type { I18nState } from \"./types\";\nimport type { ReduxAction } from \"../types\";\n\n/**\n */\nconst updateLocale = (state: I18nState, locale: string) => {\n // set locale in cookie\n if (state.locales?.length > 1) {\n setCookie(\"locale\", locale);\n } else {\n clearCookie(\"locale\");\n }\n\n // clear cache because of cached contributions\n Cache.clear();\n\n return {\n ...state,\n locale,\n };\n};\n\n/**\n */\nconst setLocales = (\n state: I18nState,\n { locale, locales }: { locale: string, locales: Locales },\n) => {\n // set locale in cookie\n if (state.locales.length > 1) {\n setCookie(\"locale\", locale);\n } else {\n clearCookie(\"locale\");\n }\n\n if (locale) {\n return {\n ...state,\n locales,\n locale,\n };\n }\n\n return {\n ...state,\n locales,\n };\n};\n\nconst getDefaultLocale = () => {\n return navigator?.language?.split(\"-\")[0] || \"en\";\n};\n\n// REDUCER\nconst initialState: I18nState = {\n locales: new Locales(),\n locale: getDefaultLocale(),\n};\n\n/**\n * Form reducer\n */\nexport const I18nReducer: Reducer<I18nState, ReduxAction> = (\n state = initialState,\n action = void 0,\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"SET_LOCALES\":\n return setLocales(state, action.payload);\n\n case \"UPDATE_LOCALE\":\n return updateLocale(state, action.payload);\n\n default:\n return state;\n }\n};\n"],"mappings":"AACA,OAAOA,KAAK,MAAM,2BAA2B;AAC7C,SAASC,SAAS,EAAEC,WAAW,QAAQ,6BAA6B;AAEpE,OAAOC,OAAO,MAAM,oBAAoB;AAMxC;AACA;AACA,MAAMC,YAAY,GAAGA,CAACC,KAAgB,EAAEC,MAAc,KAAK;EACzD;EACA,IAAID,KAAK,CAACE,OAAO,EAAEC,MAAM,GAAG,CAAC,EAAE;IAC7BP,SAAS,CAAC,QAAQ,EAAEK,MAAM,CAAC;EAC7B,CAAC,MAAM;IACLJ,WAAW,CAAC,QAAQ,CAAC;EACvB;;EA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","setCookie","clearCookie","Locales","updateLocale","state","locale","locales","length","clear","setLocales","getDefaultLocale","_globalThis","navigator","language","split","initialState","I18nReducer","action","type","payload"],"sources":["../../../src/redux/_i18n/I18nReducer.js"],"sourcesContent":["// @flow\nimport Cache from \"../../utils/browser/Cache\";\nimport { setCookie, clearCookie } from \"../../utils/browser/Cookies\";\n\nimport Locales from \"../../i18n/Locales\";\n\nimport type { Reducer } from \"redux\";\nimport type { I18nState } from \"./types\";\nimport type { ReduxAction } from \"../types\";\n\n/**\n */\nconst updateLocale = (state: I18nState, locale: string) => {\n // set locale in cookie\n if (state.locales?.length > 1) {\n setCookie(\"locale\", locale);\n } else {\n clearCookie(\"locale\");\n }\n\n // clear cache because of cached contributions\n Cache.clear();\n\n return {\n ...state,\n locale,\n };\n};\n\n/**\n */\nconst setLocales = (\n state: I18nState,\n { locale, locales }: { locale: string, locales: Locales },\n) => {\n // set locale in cookie\n if (state.locales.length > 1) {\n setCookie(\"locale\", locale);\n } else {\n clearCookie(\"locale\");\n }\n\n if (locale) {\n return {\n ...state,\n locales,\n locale,\n };\n }\n\n return {\n ...state,\n locales,\n };\n};\n\nconst getDefaultLocale = () => {\n // $FlowIssue\n return globalThis.navigator?.language?.split(\"-\")[0] || \"en\";\n};\n\n// REDUCER\nconst initialState: I18nState = {\n locales: new Locales(),\n locale: getDefaultLocale(),\n};\n\n/**\n * Form reducer\n */\nexport const I18nReducer: Reducer<I18nState, ReduxAction> = (\n state = initialState,\n action = void 0,\n) => {\n if (!action) {\n return state;\n }\n\n switch (action.type) {\n case \"SET_LOCALES\":\n return setLocales(state, action.payload);\n\n case \"UPDATE_LOCALE\":\n return updateLocale(state, action.payload);\n\n default:\n return state;\n }\n};\n"],"mappings":";AACA,OAAOA,KAAK,MAAM,2BAA2B;AAC7C,SAASC,SAAS,EAAEC,WAAW,QAAQ,6BAA6B;AAEpE,OAAOC,OAAO,MAAM,oBAAoB;AAMxC;AACA;AACA,MAAMC,YAAY,GAAGA,CAACC,KA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AU,CAACL,KAAK,EAAEa,MAAM,CAACE,OAAO,CAAC;IAE1C,KAAK,eAAe;MAClB,OAAOhB,YAAY,CAACC,KAAK,EAAEa,MAAM,CAACE,OAAO,CAAC;IAE5C;MACE,OAAOf,KAAK;EAChB;AACF,CAAC","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import _globalThis from "@babel/runtime-corejs3/core-js/global-this";
1
2
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
2
3
  import { HTTP_METHODS, MODULARUI_STATUS } from "../../constants/Constants";
3
4
  import Href from "../../models/href/Href";
@@ -80,7 +81,9 @@ const getRequestLocale = optionLocale => {
80
81
  if (optionLocale) {
81
82
  return optionLocale;
82
83
  }
83
- return navigator?.language?.split("-")[0] || "en";
84
+
85
+ // $FlowIssue
86
+ return _globalThis.navigator?.language?.split("-")[0] || "en";
84
87
  };
85
88
 
86
89
  /**
@@ -108,7 +108,8 @@ const getRequestLocale = (optionLocale: ?string): string => {
108
108
  return optionLocale;
109
109
  }
110
110
 
111
- return navigator?.language?.split("-")[0] || "en";
111
+ // $FlowIssue
112
+ return globalThis.navigator?.language?.split("-")[0] || "en";
112
113
  };
113
114
 
114
115
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","requestOptions","loadModelSuccessAction","updateHandler","getRequestLocale","optionLocale","navigator","language","split","loadModel","href","options","origin","contextPath","method","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","retryCount","retryDelay","dispatch","getState","modularuiStore","modularui","currentRequest","isLoading","LOADING","isDifferentRequest","toString","_Promise","resolve","setTimeout","loadModelPromise","then","catch","reloadModel","selfhref"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n InitModelAction,\n UpdateModelAction,\n UpdateFormAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type {\n RequestModularUIOptions,\n UpdateHandler,\n} from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel,\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const initModels = (\n models: Array<{ key: string, model: ModularUIModel }>,\n): InitModelAction => ({\n type: \"MODULARUI/INIT\",\n payload: models,\n});\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const updateForm = (model: ModularUIModel): UpdateFormAction => ({\n type: \"MODULARUI/UPDATE_FORM\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n requestOptions: any,\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status, requestOptions },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n updateHandler: UpdateHandler | void,\n): UpdateModelAction | SetModelAction => {\n if (updateHandler) {\n return updateModel(updateHandler(model));\n }\n return setModel(key, model);\n};\n\n/**\n * Retrieve the preferred language for this request, falls back to the browser language or english\n */\nconst getRequestLocale = (optionLocale: ?string): string => {\n if (optionLocale) {\n return optionLocale;\n }\n\n return navigator?.language?.split(\"-\")[0] || \"en\";\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n key,\n origin: options?.origin,\n contextPath: options?.contextPath,\n href:\n href instanceof Href\n ? href\n : new Href(href, \"\", {\n origin: options?.origin,\n contextPath: options?.contextPath,\n }),\n method: options?.method ?? HTTP_METHODS.GET,\n params: options?.params,\n data: options?.data,\n timeout: options?.timeout,\n headers: options?.headers,\n events: options?.events,\n onProgress: options?.onProgress,\n locale: getRequestLocale(options?.locale),\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n isReload: options?.isReload,\n withCredentials: options?.withCredentials,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateHandler),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key, {\n origin: options?.origin,\n contextPath: options?.contextPath,\n });\n if (\n errorResponse.isChangePassword ||\n errorResponse.isResourceNotFoundAfterReload\n ) {\n return removeModelByKey(key);\n }\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n retryCount: number = 3,\n retryDelay: number = 200,\n ): ThunkAction<> =>\n (dispatch: Dispatch, getState) => {\n const modularuiStore = getState()?.modularui;\n const currentRequest = modularuiStore?.[key];\n\n const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;\n\n if (isLoading) {\n const isDifferentRequest =\n currentRequest.requestOptions?.href?.toString() !== href.toString();\n if (isDifferentRequest && retryCount > 0) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(\n dispatch(\n loadModularUI(key, href, options, retryCount - 1, retryDelay),\n ),\n );\n }, retryDelay);\n });\n }\n\n // Same request is already loading — do nothing\n return Promise.resolve();\n }\n\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then(() => dispatch(finishProgress()))\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions,\n): ThunkAction<> =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\n"],"mappings":";AACA,SAASA,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAC1E,OAAOC,IAAI,MAAM,wBAAwB;AACzC,OAAOC,aAAa,MAAM,kCAAkC;AAC5D,SAASC,cAAc,EAAEC,aAAa,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAmB9C;AACA;AACA,OAAO,MAAMC,QAAQ,GAAGA,CACtBC,GAAW,EACXC,KAAqB,KACF;EACnB;EACAA,KAAK,CAACC,UAAU,GAAGF,GAAG;EACtB,OAAO;IACLG,IAAI,EAAE,eAAe;IACrBC,OAAO,EAAE;MACPJ,GAAG;MACHC;IACF;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,OAAO,MAAMI,UAAU,GACrBC,MAAqD,KAChC;EACrBH,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAEE;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMC,WAAW,GAAIN,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMO,UAAU,GAAIP,KAAqB,KAAwB;EACtEE,IAAI,EA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AK,CAAEtB,KAAK,IAAKQ,QAAQ,CAACrD,WAAW,CAAC6C,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;;AAEH;AACA;AACA,OAAO,MAAMuB,WAAW,GAAGA,CACzBjE,KAAqB,EACrBsB,OAAiC,KAEjCyB,aAAa,CAAC/C,KAAK,CAACC,UAAU,EAAED,KAAK,CAACkE,QAAQ,EAAE;EAC9C,GAAG5C,OAAO;EACVgB,QAAQ,EAAE;AACZ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ModularUIActions.js","names":["HTTP_METHODS","MODULARUI_STATUS","Href","ErrorResponse","finishProgress","startProgress","handleError","setModel","key","model","connectKey","type","payload","initModels","models","updateModel","updateForm","removeModelByKey","resetModularUI","updateStatus","status","requestOptions","loadModelSuccessAction","updateHandler","getRequestLocale","optionLocale","_globalThis","navigator","language","split","loadModel","href","options","origin","contextPath","method","GET","params","data","timeout","headers","events","onProgress","locale","childmodels","targetModel","forceTargetModel","cache","isReload","withCredentials","successAction","errorAction","error","errorResponse","isChangePassword","isResourceNotFoundAfterReload","ERROR","loadModularUI","retryCount","retryDelay","dispatch","getState","modularuiStore","modularui","currentRequest","isLoading","LOADING","isDifferentRequest","toString","_Promise","resolve","setTimeout","loadModelPromise","then","catch","reloadModel","selfhref"],"sources":["../../../src/redux/_modularui/ModularUIActions.js"],"sourcesContent":["// @flow\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../../constants/Constants\";\nimport Href from \"../../models/href/Href\";\nimport ErrorResponse from \"../../models/error/ErrorResponse\";\nimport { finishProgress, startProgress } from \"../actions/ProgressIndicator\";\nimport { handleError } from \"../actions/Error\";\n\nimport type { ModularUIModel } from \"../../models/types\";\nimport type { Dispatch, ThunkAction } from \"../types\";\nimport type {\n ModularUIAction,\n SetModelAction,\n InitModelAction,\n UpdateModelAction,\n UpdateFormAction,\n RemoveModelByKeyAction,\n ResetModularUIAction,\n UpdateStatusAction,\n} from \"./types\";\nimport type {\n RequestModularUIOptions,\n UpdateHandler,\n} from \"../../utils/fetch/types\";\n\n/**\n */\nexport const setModel = (\n key: string,\n model: ModularUIModel,\n): SetModelAction => {\n // set key on model for later reference\n model.connectKey = key;\n return {\n type: \"MODULARUI/SET\",\n payload: {\n key,\n model,\n },\n };\n};\n\n/**\n */\nexport const initModels = (\n models: Array<{ key: string, model: ModularUIModel }>,\n): InitModelAction => ({\n type: \"MODULARUI/INIT\",\n payload: models,\n});\n\n/**\n */\nexport const updateModel = (model: ModularUIModel): UpdateModelAction => ({\n type: \"MODULARUI/UPDATE\",\n payload: model,\n});\n\n/**\n */\nexport const updateForm = (model: ModularUIModel): UpdateFormAction => ({\n type: \"MODULARUI/UPDATE_FORM\",\n payload: model,\n});\n\n/**\n */\nexport const removeModelByKey = (key: string): RemoveModelByKeyAction => ({\n type: \"MODULARUI/REMOVE_KEY\",\n payload: key,\n});\n\n/**\n * Removes all models except the application model from the modular ui reducer\n */\nexport const resetModularUI = (): ResetModularUIAction => ({\n type: \"MODULARUI/RESET\",\n});\n\n/**\n */\nexport const updateStatus = (\n key: string,\n status: $Keys<typeof MODULARUI_STATUS>,\n requestOptions: any,\n): UpdateStatusAction => ({\n type: \"MODULARUI/STATUS\",\n payload: { key, status, requestOptions },\n});\n\n/**\n */\nconst loadModelSuccessAction = (\n key: string,\n model: ModularUIModel,\n updateHandler: UpdateHandler | void,\n): UpdateModelAction | SetModelAction => {\n if (updateHandler) {\n return updateModel(updateHandler(model));\n }\n return setModel(key, model);\n};\n\n/**\n * Retrieve the preferred language for this request, falls back to the browser language or english\n */\nconst getRequestLocale = (optionLocale: ?string): string => {\n if (optionLocale) {\n return optionLocale;\n }\n\n // $FlowIssue\n return globalThis.navigator?.language?.split(\"-\")[0] || \"en\";\n};\n\n/**\n * This action is handled by the modularui middleware\n */\nexport const loadModel = (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n): ModularUIAction => ({\n type: \"MODULARUI/FETCH\",\n payload: {\n key,\n origin: options?.origin,\n contextPath: options?.contextPath,\n href:\n href instanceof Href\n ? href\n : new Href(href, \"\", {\n origin: options?.origin,\n contextPath: options?.contextPath,\n }),\n method: options?.method ?? HTTP_METHODS.GET,\n params: options?.params,\n data: options?.data,\n timeout: options?.timeout,\n headers: options?.headers,\n events: options?.events,\n onProgress: options?.onProgress,\n locale: getRequestLocale(options?.locale),\n childmodels: options?.childmodels,\n targetModel: options?.targetModel,\n forceTargetModel: options?.forceTargetModel,\n cache: options?.cache,\n isReload: options?.isReload,\n withCredentials: options?.withCredentials,\n /**\n */\n successAction: (model) =>\n loadModelSuccessAction(key, model, options?.updateHandler),\n /**\n */\n errorAction: (error) => {\n const errorResponse = new ErrorResponse(error, key, {\n origin: options?.origin,\n contextPath: options?.contextPath,\n });\n if (\n errorResponse.isChangePassword ||\n errorResponse.isResourceNotFoundAfterReload\n ) {\n return removeModelByKey(key);\n }\n return updateStatus(key, MODULARUI_STATUS.ERROR);\n },\n },\n});\n\n/**\n */\nexport const loadModularUI =\n (\n key: string,\n href: Href | string,\n options?: RequestModularUIOptions,\n retryCount: number = 3,\n retryDelay: number = 200,\n ): ThunkAction<> =>\n (dispatch: Dispatch, getState) => {\n const modularuiStore = getState()?.modularui;\n const currentRequest = modularuiStore?.[key];\n\n const isLoading = currentRequest?.status === MODULARUI_STATUS.LOADING;\n\n if (isLoading) {\n const isDifferentRequest =\n currentRequest.requestOptions?.href?.toString() !== href.toString();\n if (isDifferentRequest && retryCount > 0) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(\n dispatch(\n loadModularUI(key, href, options, retryCount - 1, retryDelay),\n ),\n );\n }, retryDelay);\n });\n }\n\n // Same request is already loading — do nothing\n return Promise.resolve();\n }\n\n dispatch(startProgress());\n\n const loadModelPromise = dispatch(loadModel(key, href, options));\n\n return Promise.resolve(loadModelPromise)\n .then(() => dispatch(finishProgress()))\n .catch((error) => dispatch(handleError(error)));\n };\n\n/**\n */\nexport const reloadModel = (\n model: ModularUIModel,\n options?: RequestModularUIOptions,\n): ThunkAction<> =>\n loadModularUI(model.connectKey, model.selfhref, {\n ...options,\n isReload: true,\n });\n"],"mappings":";;AACA,SAASA,YAAY,EAAEC,gBAAgB,QAAQ,2BAA2B;AAC1E,OAAOC,IAAI,MAAM,wBAAwB;AACzC,OAAOC,aAAa,MAAM,kCAAkC;AAC5D,SAASC,cAAc,EAAEC,aAAa,QAAQ,8BAA8B;AAC5E,SAASC,WAAW,QAAQ,kBAAkB;AAmB9C;AACA;AACA,OAAO,MAAMC,QAAQ,GAAGA,CACtBC,GAAW,EACXC,KAAqB,KACF;EACnB;EACAA,KAAK,CAACC,UAAU,GAAGF,GAAG;EACtB,OAAO;IACLG,IAAI,EAAE,eAAe;IACrBC,OAAO,EAAE;MACPJ,GAAG;MACHC;IACF;EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA,OAAO,MAAMI,UAAU,GACrBC,MAAqD,KAChC;EACrBH,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAEE;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMC,WAAW,GAAIN,KAAqB,KAAyB;EACxEE,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMO,UAAU,GAAIP,KAAqB,KAAwB;EACtEE,IAAI,EAAE,uBAAuB;EAC7BC,OAAO,EAAEH;AACX,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMQ,gBAAgB,GAAIT,GAAW,KAA8B;EACxEG,IAAI,EAAE,sBAAsB;EAC5BC,OAAO,EAAEJ;AACX,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,MAAMU,cAAc,GAAGA,CAAA,MAA6B;EACzDP,IAAI,EAAE;AACR,CAAC,CAAC;;AAEF;AACA;AACA,OAAO,MAAMQ,YAAY,GAAGA,CAC1BX,GAAW,EACXY,MAAsC,EACtCC,cAAmB,MACK;EACxBV,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAE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perty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
3
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
3
4
  import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
@@ -9,10 +10,9 @@ import { ALL_CONTENT_IN_DATA_SETTING, INCLUDE_TIME_OFFSET, LOGIN_TYPE, LOGIN_PAS
9
10
  /**
10
11
  */
11
12
  const getServerPreferenceValue = (preferenceName, defaultValue = null, type) => {
12
- let value = null;
13
- if (typeof preferencesProvider !== "undefined") {
14
- value = preferencesProvider.getPreferenceByName(preferenceName);
15
- }
13
+ let value =
14
+ // $FlowIssue
15
+ _globalThis?.preferencesProvider?.getPreferenceByName(preferenceName);
16
16
  if (value == null) {
17
17
  value = defaultValue;
18
18
  }
@@ -68,8 +68,12 @@ export const setThemePreference = configTheme => {
68
68
  */
69
69
  export const setAllContentInDataSetting = state => {
70
70
  let allContentInDataSetting = false;
71
- if (typeof preferencesProvider?.getModularUIContentInData === "function") {
72
- allContentInDataSetting = preferencesProvider.getModularUIContentInData();
71
+ if (
72
+ // $FlowIssue
73
+ typeof _globalThis.preferencesProvider?.getModularUIContentInData === "function") {
74
+ allContentInDataSetting =
75
+ // $FlowIssue
76
+ _globalThis.preferencesProvider.getModularUIContentInData();
73
77
  } else if (typeof state?.preferences == "object") {
74
78
  allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];
75
79
  }
@@ -82,8 +86,12 @@ export const setAllContentInDataSetting = state => {
82
86
  */
83
87
  export const setDateTimeSettings = state => {
84
88
  let isIncludeTimeOffsetInDateTimes = false;
85
- if (typeof preferencesProvider?.isIncludeTimeOffsetInDateTimes === "function") {
86
- isIncludeTimeOffsetInDateTimes = preferencesProvider.isIncludeTimeOffsetInDateTimes();
89
+ if (
90
+ // $FlowIssue
91
+ typeof _globalThis.preferencesProvider?.isIncludeTimeOffsetInDateTimes === "function") {
92
+ isIncludeTimeOffsetInDateTimes =
93
+ // $FlowIssue
94
+ _globalThis.preferencesProvider.isIncludeTimeOffsetInDateTimes();
87
95
  } else if (typeof state?.preferences === "object") {
88
96
  isIncludeTimeOffsetInDateTimes = state.preferences[INCLUDE_TIME_OFFSET];
89
97
  }
@@ -28,10 +28,9 @@ const getServerPreferenceValue = (
28
28
  defaultValue: PreferenceValue = null,
29
29
  type?: string,
30
30
  ): PreferenceValue => {
31
- let value: PreferenceValue = null;
32
- if (typeof preferencesProvider !== "undefined") {
33
- value = preferencesProvider.getPreferenceByName(preferenceName);
34
- }
31
+ let value: PreferenceValue =
32
+ // $FlowIssue
33
+ globalThis?.preferencesProvider?.getPreferenceByName(preferenceName);
35
34
 
36
35
  if (value == null) {
37
36
  value = defaultValue;
@@ -104,8 +103,14 @@ export const setAllContentInDataSetting = (
104
103
  ): SetPreferenceAction => {
105
104
  let allContentInDataSetting: PreferenceValue = false;
106
105
 
107
- if (typeof preferencesProvider?.getModularUIContentInData === "function") {
108
- allContentInDataSetting = preferencesProvider.getModularUIContentInData();
106
+ if (
107
+ // $FlowIssue
108
+ typeof globalThis.preferencesProvider?.getModularUIContentInData ===
109
+ "function"
110
+ ) {
111
+ allContentInDataSetting =
112
+ // $FlowIssue
113
+ globalThis.preferencesProvider.getModularUIContentInData();
109
114
  } else if (typeof state?.preferences == "object") {
110
115
  allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];
111
116
  }
@@ -122,10 +127,13 @@ export const setDateTimeSettings = (
122
127
  ): SetPreferenceAction => {
123
128
  let isIncludeTimeOffsetInDateTimes: PreferenceValue = false;
124
129
  if (
125
- typeof preferencesProvider?.isIncludeTimeOffsetInDateTimes === "function"
130
+ // $FlowIssue
131
+ typeof globalThis.preferencesProvider?.isIncludeTimeOffsetInDateTimes ===
132
+ "function"
126
133
  ) {
127
134
  isIncludeTimeOffsetInDateTimes =
128
- preferencesProvider.isIncludeTimeOffsetInDateTimes();
135
+ // $FlowIssue
136
+ globalThis.preferencesProvider.isIncludeTimeOffsetInDateTimes();
129
137
  } else if (typeof state?.preferences === "object") {
130
138
  isIncludeTimeOffsetInDateTimes = state.preferences[INCLUDE_TIME_OFFSET];
131
139
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Preferences.js","names":["isPlainObject","JsonParseException","setSetting","setSettings","ALL_CONTENT_IN_DATA_SETTING","INCLUDE_TIME_OFFSET","LOGIN_TYPE","LOGIN_PASSWORD_SETTING","LOGIN_PATH_SETTING","LOGIN_USERNAME_SETTING","LOGOUT_PATH_SETTING","getServerPreferenceValue","preferenceName","defaultValue","type","value","preferencesProvider","getPreferenceByName","_includesInstanceProperty","call","_context","_mapInstanceProperty","split","val","_trimInstanceProperty","setServerPreference","propertyName","setPreference","propertyValue","payload","setPreferences","preferences","setThemePreference","configTheme","themeData","JSON","parse","error","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","setDateTimeSettings","isIncludeTimeOffsetInDateTimes","setLoginPreferences","loginSettings"],"sources":["../../../src/redux/actions/Preferences.js"],"sourcesContent":["// @flow\nimport { isPlainObject } from \"../../utils/helpers/objects\";\n\nimport { JsonParseException } from \"../../exceptions\";\nimport { setSetting, setSettings } from \"../../constants/Settings\";\n\nimport type {\n PreferenceValue,\n ReduxState,\n SetPreferenceAction,\n SetPreferencesAction,\n} from \"../types\";\n\nimport {\n ALL_CONTENT_IN_DATA_SETTING,\n INCLUDE_TIME_OFFSET,\n LOGIN_TYPE,\n LOGIN_PASSWORD_SETTING,\n LOGIN_PATH_SETTING,\n LOGIN_USERNAME_SETTING,\n LOGOUT_PATH_SETTING,\n} from \"../../constants\";\n\n/**\n */\nconst getServerPreferenceValue = (\n preferenceName: string,\n defaultValue: PreferenceValue = null,\n type?: string,\n): PreferenceValue => {\n let value: PreferenceValue = null;\n if (typeof preferencesProvider !== \"undefined\") {\n value = preferencesProvider.getPreferenceByName(preferenceName);\n }\n\n if (value == null) {\n value = defaultValue;\n }\n\n if (typeof value === \"string\" && type !== \"string\" && value.includes(\",\")) {\n value = value.split(\",\").map((val) => val.trim());\n }\n\n return (value: PreferenceValue);\n};\n\n/**\n */\nexport const setServerPreference = (\n propertyName: string,\n defaultValue: PreferenceValue = null,\n type?: string,\n): SetPreferenceAction => {\n const value = getServerPreferenceValue(propertyName, defaultValue, type);\n return setPreference(propertyName, value);\n};\n\n/**\n */\nexport const setPreference = (\n propertyName: string,\n propertyValue: PreferenceValue = null,\n): SetPreferenceAction => ({\n type: \"SET_PREFERENCE\",\n payload: {\n [propertyName]: propertyValue,\n },\n});\n\n/**\n */\nexport const setPreferences = (preferences: Object): SetPreferencesAction => ({\n type: \"SET_PREFERENCES\",\n payload: {\n ...preferences,\n },\n});\n\n/**\n */\nexport const setThemePreference = (\n configTheme: string,\n): SetPreferenceAction => {\n let themeData;\n\n try {\n themeData = configTheme ? JSON.parse(configTheme) : null;\n } catch (error) {\n throw new JsonParseException(`Theme file contains invalid JSON: ${error}`);\n }\n\n if (themeData && isPlainObject(themeData)) {\n setSettings(themeData.settings);\n }\n\n return setPreference(\"theme\", themeData);\n};\n\n/**\n * Make modular-ui-content-in-data preference available client side\n */\nexport const setAllContentInDataSetting = (\n state?: ReduxState,\n): SetPreferenceAction => {\n let allContentInDataSetting: PreferenceValue = false;\n\n if (typeof preferencesProvider?.getModularUIContentInData === \"function\") {\n allContentInDataSetting = preferencesProvider.getModularUIContentInData();\n } else if (typeof state?.preferences == \"object\") {\n allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];\n }\n\n setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);\n return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);\n};\n\n/**\n * Retrieve settings for date time conversion\n */\nexport const setDateTimeSettings = (\n state?: ReduxState,\n): SetPreferenceAction => {\n let isIncludeTimeOffsetInDateTimes: PreferenceValue = false;\n if (\n typeof preferencesProvider?.isIncludeTimeOffsetInDateTimes === \"function\"\n ) {\n isIncludeTimeOffsetInDateTimes =\n preferencesProvider.isIncludeTimeOffsetInDateTimes();\n } else if (typeof state?.preferences === \"object\") {\n isIncludeTimeOffsetInDateTimes = state.preferences[INCLUDE_TIME_OFFSET];\n }\n\n setSetting(INCLUDE_TIME_OFFSET, !!isIncludeTimeOffsetInDateTimes);\n return setPreference(INCLUDE_TIME_OFFSET, isIncludeTimeOffsetInDateTimes);\n};\n\n/**\n * Retrieves login settings from runtime preferences and sets them as setting in the preference reducer\n */\nexport const setLoginPreferences = (\n state?: ReduxState,\n): SetPreferencesAction => {\n const loginSettings = {\n [LOGIN_TYPE]: getServerPreferenceValue(\n LOGIN_TYPE,\n state?.preferences[LOGIN_TYPE],\n ),\n [LOGIN_PATH_SETTING]: getServerPreferenceValue(\n LOGIN_PATH_SETTING,\n state?.preferences[LOGIN_PATH_SETTING] ??\n `/callback?client_name=FormClient`,\n ),\n [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(\n LOGIN_USERNAME_SETTING,\n state?.preferences[LOGIN_USERNAME_SETTING] ?? \"j_username\",\n ),\n [LOGIN_PASSWORD_SETTING]: getServerPreferenceValue(\n LOGIN_PASSWORD_SETTING,\n state?.preferences[LOGIN_PASSWORD_SETTING] ?? \"j_password\",\n ),\n [LOGOUT_PATH_SETTING]: getServerPreferenceValue(\n LOGOUT_PATH_SETTING,\n state?.preferences[LOGOUT_PATH_SETTING] ?? `/logout`,\n ),\n };\n\n setSettings(loginSettings);\n return setPreferences(loginSettings);\n};\n"],"mappings":";;;AACA,SAASA,aAAa,QAAQ,6BAA6B;AAE3D,SAASC,kBAAkB,QAAQ,kBAAkB;AACrD,SAASC,UAAU,EAAEC,WAAW,QAAQ,0BAA0B;AASlE,SACEC,2BAA2B,EAC3BC,mBAAmB,EACnBC,UAAU,EACVC,sBAAsB,EACtBC,kBAAkB,EAClBC,sBAAsB,EACtBC,mBAAmB,QACd,iBAAiB;;AAExB;AACA;AACA,MAAMC,wBAAwB,GAAGA,CAC/BC,cAAsB,EACtBC,YAA6B,GAAG,IAAI,EACpCC,IAAa,K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1B,mBAAmB,CAAC;EACzE;EAEAH,UAAU,CAACG,mBAAmB,EAAE,CAAC,CAACuC,8BAA8B,CAAC;EACjE,OAAOjB,aAAa,CAACtB,mBAAmB,EAAEuC,8BAA8B,CAAC;AAC3E,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,GAC9BL,KAAkB,IACO;EACzB,MAAMM,aAAa,GAAG;IACpB,CAACxC,UAAU,GAAGK,wBAAwB,CACpCL,UAAU,EACVkC,KAAK,EAAET,WAAW,CAACzB,UAAU,CAC/B,CAAC;IACD,CAACE,kBAAkB,GAAGG,wBAAwB,CAC5CH,kBAAkB,EAClBgC,KAAK,EAAET,WAAW,CAACvB,kBAAkB,CAAC,IACpC,kCACJ,CAAC;IACD,CAACC,sBAAsB,GAAGE,wBAAwB,CAChDF,sBAAsB,EACtB+B,KAAK,EAAET,WAAW,CAACtB,sBAAsB,CAAC,IAAI,YAChD,CAAC;IACD,CAACF,sBAAsB,GAAGI,wBAAwB,CAChDJ,sBAAsB,EACtBiC,KAAK,EAAET,WAAW,CAACxB,sBAAsB,CAAC,IAAI,YAChD,CAAC;IACD,CAACG,mBAAmB,GAAGC,wBAAwB,CAC7CD,mBAAmB,EACnB8B,KAAK,EAAET,WAAW,CAACrB,mBAAmB,CAAC,IAAI,SAC7C;EACF,CAAC;EAEDP,WAAW,CAAC2C,aAAa,CAAC;EAC1B,OAAOhB,cAAc,CAACgB,aAAa,CAAC;AACtC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"Preferences.js","names":["isPlainObject","JsonParseException","setSetting","setSettings","ALL_CONTENT_IN_DATA_SETTING","INCLUDE_TIME_OFFSET","LOGIN_TYPE","LOGIN_PASSWORD_SETTING","LOGIN_PATH_SETTING","LOGIN_USERNAME_SETTING","LOGOUT_PATH_SETTING","getServerPreferenceValue","preferenceName","defaultValue","type","value","_globalThis","preferencesProvider","getPreferenceByName","_includesInstanceProperty","call","_context","_mapInstanceProperty","split","val","_trimInstanceProperty","setServerPreference","propertyName","setPreference","propertyValue","payload","setPreferences","preferences","setThemePreference","configTheme","themeData","JSON","parse","error","settings","setAllContentInDataSetting","state","allContentInDataSetting","getModularUIContentInData","setDateTimeSettings","isIncludeTimeOffsetInDateTimes","setLoginPreferences","loginSettings"],"sources":["../../../src/redux/actions/Preferences.js"],"sourcesContent":["// @flow\nimport { isPlainObject } from \"../../utils/helpers/objects\";\n\nimport { JsonParseException } from \"../../exceptions\";\nimport { setSetting, setSettings } from \"../../constants/Settings\";\n\nimport type {\n PreferenceValue,\n ReduxState,\n SetPreferenceAction,\n SetPreferencesAction,\n} from \"../types\";\n\nimport {\n ALL_CONTENT_IN_DATA_SETTING,\n INCLUDE_TIME_OFFSET,\n LOGIN_TYPE,\n LOGIN_PASSWORD_SETTING,\n LOGIN_PATH_SETTING,\n LOGIN_USERNAME_SETTING,\n LOGOUT_PATH_SETTING,\n} from \"../../constants\";\n\n/**\n */\nconst getServerPreferenceValue = (\n preferenceName: string,\n defaultValue: PreferenceValue = null,\n type?: string,\n): PreferenceValue => {\n let value: PreferenceValue =\n // $FlowIssue\n globalThis?.preferencesProvider?.getPreferenceByName(preferenceName);\n\n if (value == null) {\n value = defaultValue;\n }\n\n if (typeof value === \"string\" && type !== \"string\" && value.includes(\",\")) {\n value = value.split(\",\").map((val) => val.trim());\n }\n\n return (value: PreferenceValue);\n};\n\n/**\n */\nexport const setServerPreference = (\n propertyName: string,\n defaultValue: PreferenceValue = null,\n type?: string,\n): SetPreferenceAction => {\n const value = getServerPreferenceValue(propertyName, defaultValue, type);\n return setPreference(propertyName, value);\n};\n\n/**\n */\nexport const setPreference = (\n propertyName: string,\n propertyValue: PreferenceValue = null,\n): SetPreferenceAction => ({\n type: \"SET_PREFERENCE\",\n payload: {\n [propertyName]: propertyValue,\n },\n});\n\n/**\n */\nexport const setPreferences = (preferences: Object): SetPreferencesAction => ({\n type: \"SET_PREFERENCES\",\n payload: {\n ...preferences,\n },\n});\n\n/**\n */\nexport const setThemePreference = (\n configTheme: string,\n): SetPreferenceAction => {\n let themeData;\n\n try {\n themeData = configTheme ? JSON.parse(configTheme) : null;\n } catch (error) {\n throw new JsonParseException(`Theme file contains invalid JSON: ${error}`);\n }\n\n if (themeData && isPlainObject(themeData)) {\n setSettings(themeData.settings);\n }\n\n return setPreference(\"theme\", themeData);\n};\n\n/**\n * Make modular-ui-content-in-data preference available client side\n */\nexport const setAllContentInDataSetting = (\n state?: ReduxState,\n): SetPreferenceAction => {\n let allContentInDataSetting: PreferenceValue = false;\n\n if (\n // $FlowIssue\n typeof globalThis.preferencesProvider?.getModularUIContentInData ===\n \"function\"\n ) {\n allContentInDataSetting =\n // $FlowIssue\n globalThis.preferencesProvider.getModularUIContentInData();\n } else if (typeof state?.preferences == \"object\") {\n allContentInDataSetting = state.preferences[ALL_CONTENT_IN_DATA_SETTING];\n }\n\n setSetting(ALL_CONTENT_IN_DATA_SETTING, !!allContentInDataSetting);\n return setPreference(ALL_CONTENT_IN_DATA_SETTING, allContentInDataSetting);\n};\n\n/**\n * Retrieve settings for date time conversion\n */\nexport const setDateTimeSettings = (\n state?: ReduxState,\n): SetPreferenceAction => {\n let isIncludeTimeOffsetInDateTimes: PreferenceValue = false;\n if (\n // $FlowIssue\n typeof globalThis.preferencesProvider?.isIncludeTimeOffsetInDateTimes ===\n \"function\"\n ) {\n isIncludeTimeOffsetInDateTimes =\n // $FlowIssue\n globalThis.preferencesProvider.isIncludeTimeOffsetInDateTimes();\n } else if (typeof state?.preferences === \"object\") {\n isIncludeTimeOffsetInDateTimes = state.preferences[INCLUDE_TIME_OFFSET];\n }\n\n setSetting(INCLUDE_TIME_OFFSET, !!isIncludeTimeOffsetInDateTimes);\n return setPreference(INCLUDE_TIME_OFFSET, isIncludeTimeOffsetInDateTimes);\n};\n\n/**\n * Retrieves login settings from runtime preferences and sets them as setting in the preference reducer\n */\nexport const setLoginPreferences = (\n state?: ReduxState,\n): SetPreferencesAction => {\n const loginSettings = {\n [LOGIN_TYPE]: getServerPreferenceValue(\n LOGIN_TYPE,\n state?.preferences[LOGIN_TYPE],\n ),\n [LOGIN_PATH_SETTING]: getServerPreferenceValue(\n LOGIN_PATH_SETTING,\n state?.preferences[LOGIN_PATH_SETTING] ??\n `/callback?client_name=FormClient`,\n ),\n [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(\n LOGIN_USERNAME_SETTING,\n state?.preferences[LOGIN_USERNAME_SETTING] ?? \"j_username\",\n ),\n [LOGIN_PASSWORD_SETTING]: getServerPreferenceValue(\n LOGIN_PASSWORD_SETTING,\n state?.preferences[LOGIN_PASSWORD_SETTING] ?? \"j_password\",\n ),\n [LOGOUT_PATH_SETTING]: getServerPreferenceValue(\n LOGOUT_PATH_SETTING,\n state?.preferences[LOGOUT_PATH_SETTING] ?? `/logout`,\n ),\n };\n\n setSettings(loginSettings);\n return setPreferences(loginSettings);\n};\n"],"mappings":";;;;AACA,SAASA,aAAa,QAAQ,6BAA6B;AAE3D,SAASC,kBAAkB,QAAQ,kBAAkB;AACrD,SAASC,UAAU,EAAEC,WAAW,QAAQ,0BAA0B;AASlE,SACEC,2BAA2B,EAC3BC,mBAAmB,EACnBC,UAAU,EACVC,sBAAsB,EACtBC,kBAAkB,EAClBC,sBAAsB,EACtBC,mBAAmB,QACd,iBAAiB;;AAExB;AACA;AACA,MAAMC,wBAAwB,GAAGA,CAC/BC,cAAsB,EACtBC,YAA6B,GAAG,IAAI,EACpCC,IAAa,KACO;EACpB,IAAIC,KAAsB;EACxB;EACAC,WAAA,EAAYC,mBAAmB,EAAEC,mBAAmB,CAACN,cAAc,CAAC;EAEtE,IAAIG,KAAK,IAAI,IAAI,EAAE;IACjBA,KAAK,GAAGF,YAAY;EACtB;EAEA,IAAI,OAAOE,KAAK,KAAK,QAAQ,IAAID,IAAI,KAAK,QAAQ,IAAIK,yBAAA,CAAAJ,KAAK,EAAAK,IAAA,CAALL,KAAK,EAAU,GAAG,CAAC,EAAE;IAAA,IAAAM,QAAA;IACzEN,KAAK,GAAGO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AAU,CAC/B,CAAC;IACD,CAACE,kBAAkB,GAAGG,wBAAwB,CAC5CH,kBAAkB,EAClBiC,KAAK,EAAET,WAAW,CAACxB,kBAAkB,CAAC,IACpC,kCACJ,CAAC;IACD,CAACC,sBAAsB,GAAGE,wBAAwB,CAChDF,sBAAsB,EACtBgC,KAAK,EAAET,WAAW,CAACvB,sBAAsB,CAAC,IAAI,YAChD,CAAC;IACD,CAACF,sBAAsB,GAAGI,wBAAwB,CAChDJ,sBAAsB,EACtBkC,KAAK,EAAET,WAAW,CAACzB,sBAAsB,CAAC,IAAI,YAChD,CAAC;IACD,CAACG,mBAAmB,GAAGC,wBAAwB,CAC7CD,mBAAmB,EACnB+B,KAAK,EAAET,WAAW,CAACtB,mBAAmB,CAAC,IAAI,SAC7C;EACF,CAAC;EAEDP,WAAW,CAAC4C,aAAa,CAAC;EAC1B,OAAOhB,cAAc,CAACgB,aAAa,CAAC;AACtC,CAAC","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
2
2
  import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
3
+ import _globalThis from "@babel/runtime-corejs3/core-js/global-this";
3
4
  import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
4
5
  import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
5
6
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
@@ -133,7 +134,8 @@ class XHR {
133
134
  /**
134
135
  */
135
136
  getBaseLocale() {
136
- return navigator?.language?.split("-")[0] || "en";
137
+ // $FlowIssue
138
+ return _globalThis.navigator?.language?.split("-")[0] || "en";
137
139
  }
138
140
 
139
141
  /**
@@ -148,7 +148,8 @@ class XHR {
148
148
  /**
149
149
  */
150
150
  getBaseLocale(): string {
151
- return navigator?.language?.split("-")[0] || "en";
151
+ // $FlowIssue
152
+ return globalThis.navigator?.language?.split("-")[0] || "en";
152
153
  }
153
154
 
154
155
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","names":["has","isPlainObject","IllegalArgumentException","UnauthorizedException","FetchException","TimeoutException","NotFoundException","JsonParseException","NetworkException","Cache","HTTP_METHODS","getSetting","NETWORK_ERROR_CODE","SUCCESS_CODE","CLIENT_ERROR_CODE","UNAUTHORIZED_CODE","REDIRECTION_CODE","NOT_FOUND_CODE","JSON_TYPE","XHR","constructor","options","_defineProperty","_options","_attempts","xmlhttp","_xmlhttp","attempts","url","params","_includesInstanceProperty","call","aUrl","split","data","method","GET","timeout","responseType","onProgress","events","getBaseLocale","navigator","language","headers","baseHeaders","Accept","timeoutHandler","reject","errorHandler","responseJSON","status","isReload","getResponse","response","getResponseHeader","JSON","parse","error","responseHandler","resolve","setEventListeners","forEach","eventType","addEventListener","_Object$keys","eventName","openConnection","open","setBasicAuthentication","hasItem","basicToken","getItem","setRequestHeader","headerName","setCustomHeaders","setOtherOptions","withCredentials","sendData","send","stringData","_JSON$stringify","setXMLHttpRequest","_Promise","XMLHttpRequest","fetch","err","validateInputArguments","args","xhr"],"sources":["../../../src/utils/fetch/xhr.js"],"sourcesContent":["// @flow\nimport { has, isPlainObject } from \"../helpers/objects\";\n\nimport {\n IllegalArgumentException,\n UnauthorizedException,\n FetchException,\n TimeoutException,\n NotFoundException,\n JsonParseException,\n NetworkException,\n} from \"../../exceptions\";\n\nimport Cache from \"../browser/Cache\";\n\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport type { RequestOptions } from \"./types\";\n\nconst NETWORK_ERROR_CODE = 0;\nconst SUCCESS_CODE = 200;\nconst CLIENT_ERROR_CODE = 400;\nconst UNAUTHORIZED_CODE = 401;\nconst REDIRECTION_CODE = 300;\nconst NOT_FOUND_CODE = 404;\n\nconst JSON_TYPE = \"application/json\";\n\n/**\n * @private\n */\nclass XHR {\n _options: RequestOptions;\n _xmlhttp: XMLHttpRequest;\n _attempts: number;\n\n /**\n */\n constructor(options: RequestOptions) {\n this._options = options;\n this._attempts = 0;\n }\n\n /**\n */\n get xmlhttp(): XMLHttpRequest {\n return this._xmlhttp;\n }\n\n /**\n */\n set xmlhttp(xmlhttp: XMLHttpRequest) {\n this._xmlhttp = xmlhttp;\n }\n\n /**\n */\n get options(): RequestOptions {\n return this._options;\n }\n\n /**\n */\n set options(options: RequestOptions) {\n this._options = options;\n }\n\n /**\n */\n get attempts(): number {\n return this._attempts;\n }\n\n /**\n */\n set attempts(attempts: number) {\n this._attempts = attempts;\n }\n\n /**\n * Create and fix url when params or both querystring and params exist.\n */\n get url(): string {\n const { url } = this.options;\n if (this.params !== \"\") {\n if (url.includes(\"?\")) {\n const aUrl = url.split(\"?\");\n\n return `${aUrl[0]}?${aUrl[1]}&${this.params}`;\n }\n\n return `${url}?${this.params}`;\n }\n\n return url;\n }\n\n /**\n */\n get params(): string {\n return this.options.params || \"\";\n }\n\n /**\n */\n get data(): any | null {\n return this.options.data || null;\n }\n\n /**\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this.options.method || HTTP_METHODS.GET;\n }\n\n /**\n */\n get timeout(): number {\n return this.options.timeout || getSetting(\"XHR_TIMEOUT_MS\", 300000);\n }\n\n /**\n */\n get responseType(): string {\n return this.options.responseType || \"json\";\n }\n\n /**\n */\n get onProgress(): ProgressEventHandler {\n if (this.options.onProgress) {\n return this.options.onProgress;\n }\n\n return () => {\n // do nothing\n };\n }\n\n /**\n */\n get events(): { [eventName: string]: () => void } {\n return this.options.events || {};\n }\n\n /**\n */\n getBaseLocale(): string {\n return navigator?.language?.split(\"-\")[0] || \"en\";\n }\n\n /**\n */\n get headers(): { [string]: string } {\n const baseHeaders = {\n Accept: JSON_TYPE,\n \"Content-Type\": JSON_TYPE,\n\n // needed for csrf, see: https://plaza.beinformed.com/amdoc/csrf-protection-in-modular-ui-services-40054554.html\n \"X-Requested-With\": \"XMLHttpRequest\",\n\n \"Accept-Language\": this.getBaseLocale(),\n };\n\n if (this.options.headers) {\n // $FlowFixMe[cannot-spread-indexer]\n return {\n ...baseHeaders,\n ...this.options.headers,\n };\n }\n\n return baseHeaders;\n }\n\n /**\n */\n timeoutHandler(reject: Function): any {\n return reject(new TimeoutException(this.url, this.method));\n }\n\n /**\n */\n errorHandler(reject: Function, responseJSON: any = null): any {\n const { status } = this.xmlhttp;\n const { isReload } = this.options;\n\n if (status === NETWORK_ERROR_CODE) {\n return reject(new NetworkException(this.url, this.method));\n }\n\n if (status === NOT_FOUND_CODE) {\n return reject(new NotFoundException(this.url, this.method, isReload));\n }\n\n if (status === UNAUTHORIZED_CODE) {\n return reject(\n new UnauthorizedException(this.url, this.method, responseJSON),\n );\n }\n\n return reject(new FetchException(responseJSON, this.xmlhttp, this.options));\n }\n\n /**\n */\n getResponse(): any {\n const { responseType, response } = this.xmlhttp;\n\n if (\n (responseType === \"\" || responseType === \"text\") &&\n this.getResponseHeader(\"Content-Type\") === JSON_TYPE\n ) {\n if (isPlainObject(response)) {\n return response;\n }\n\n try {\n return JSON.parse(response);\n } catch (error) {\n throw new JsonParseException(error);\n }\n }\n\n return response;\n }\n\n /**\n */\n responseHandler(resolve: Function, reject: Function): any {\n const { status } = this.xmlhttp;\n\n let response = null;\n try {\n response = this.getResponse();\n } catch (error) {\n return reject(error);\n }\n\n if (\n (status >= SUCCESS_CODE && status < REDIRECTION_CODE) ||\n (status === CLIENT_ERROR_CODE && has(response, \"formresponse\"))\n ) {\n return resolve(response);\n }\n\n return this.errorHandler(reject, response);\n }\n\n /**\n */\n setEventListeners(resolve: Function, reject: Function) {\n if (this.options.onProgress) {\n [\"load\", \"loadend\", \"loadstart\", \"progress\"].forEach((eventType) => {\n this.xmlhttp.addEventListener(eventType, this.onProgress);\n });\n }\n\n [\"abort\", \"error\"].forEach((eventType) => {\n this.xmlhttp.addEventListener(eventType, () => this.errorHandler(reject));\n });\n\n this.xmlhttp.addEventListener(\"timeout\", () => this.timeoutHandler(reject));\n\n this.xmlhttp.addEventListener(\"load\", () =>\n this.responseHandler(resolve, reject),\n );\n\n // Set custom events\n Object.keys(this.events).forEach((eventName) => {\n this.xmlhttp.addEventListener(eventName, this.events[eventName]);\n });\n }\n\n /**\n */\n openConnection() {\n this.xmlhttp.open(this.method, this.url, true);\n }\n\n /**\n */\n setBasicAuthentication() {\n if (Cache.hasItem(\"basic\")) {\n const basicToken = Cache.getItem(\"basic\");\n\n if (typeof basicToken === \"string\") {\n this.xmlhttp.setRequestHeader(\"Authorization\", `Basic ${basicToken}`);\n }\n }\n }\n\n /**\n */\n getResponseHeader(headerName: string): string | null {\n return this.xmlhttp.getResponseHeader(headerName);\n }\n\n /**\n */\n setCustomHeaders() {\n Object.keys(this.headers).forEach((headerName) => {\n this.xmlhttp.setRequestHeader(headerName, this.headers[headerName]);\n });\n }\n\n /**\n */\n setOtherOptions() {\n if (\n this.options.withCredentials ||\n getSetting(\"XHR_ALWAYS_WITH_CREDENTIALS\", Cache.hasItem(\"basic\"))\n ) {\n this.xmlhttp.withCredentials = true;\n }\n this.xmlhttp.responseType = this.responseType;\n this.xmlhttp.timeout = this.timeout;\n }\n\n /**\n */\n sendData() {\n if (this.data == null) {\n this.xmlhttp.send();\n } else {\n const stringData = isPlainObject(this.data)\n ? JSON.stringify(this.data)\n : this.data;\n this.xmlhttp.send(stringData);\n }\n }\n\n /**\n */\n setXMLHttpRequest(): Promise<any> {\n return new Promise((resolve, reject) => {\n this.xmlhttp = new XMLHttpRequest();\n\n this.setEventListeners(resolve, reject);\n\n this.openConnection();\n\n this.setBasicAuthentication();\n\n this.setCustomHeaders();\n\n this.setOtherOptions();\n\n this.sendData();\n });\n }\n\n /**\n */\n async fetch(): Promise<any> {\n try {\n return await this.setXMLHttpRequest();\n } catch (err) {\n if (err instanceof NetworkException && this.attempts < 2) {\n this.attempts += 1;\n return this.fetch();\n }\n\n throw err;\n }\n }\n}\n\n/**\n */\nconst validateInputArguments = (args: RequestOptions) => {\n if (args == null) {\n throw new IllegalArgumentException(\n \"Missing request options, expecting an object as argument for xhr\",\n );\n }\n\n if (!isPlainObject(args)) {\n throw new IllegalArgumentException(\n `Expecting an object as argument for xhr, but received: ${typeof args}`,\n );\n }\n\n if (!has(args, \"url\")) {\n throw new IllegalArgumentException(\n `No url property found in arguments of xhr, received: ${JSON.stringify(\n args,\n )}`,\n );\n }\n\n return true;\n};\n\n/**\n */\nconst xhr = (args: RequestOptions): Promise<any> => {\n validateInputArguments(args);\n\n return new XHR(args).fetch();\n};\n\nexport default xhr;\n"],"mappings":";;;;;AACA,SAASA,GAAG,EAAEC,aAAa,QAAQ,oBAAoB;AAEvD,SACEC,wBAAwB,EACxBC,qBAAqB,EACrBC,cAAc,EACdC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,EAClBC,gBAAgB,QACX,kBAAkB;AAEzB,OAAOC,KAAK,MAAM,kBAAkB;AAEpC,SAASC,YAAY,QAAQ,2BAA2B;AAExD,SAASC,UAAU,QAAQ,0BAA0B;AAIrD,MAAMC,kBAAkB,GAAG,CAAC;AAC5B,MAAMC,YAAY,GAAG,GAAG;AACxB,MAAMC,iBAAiB,GAAG,GAAG;AAC7B,MAAMC,iBAAiB,GAAG,GAAG;AAC7B,MAAMC,gBAAgB,GAAG,GAAG;AAC5B,MAAMC,cAAc,GAAG,GAAG;AAE1B,MAAMC,SAAS,GAAG,kBAAkB;;AAEpC;AACA;AACA;AACA,MAAMC,GAAG,CAAC;EAKR;AACF;EACEC,WAAWA,CAACC,OAAuB,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACnC,IAAI,CAACC,QAAQ,GAAGF,OAAO;IACvB,IAAI,CAACG,SAAS,GAAG,CAAC;EACpB;;EAEA;AACF;EACE,IAAIC,OAAOA,CAAA,EAAmB;IAC5B,OAAO,IAAI,CAACC,QAAQ;EACtB;;EAEA;AACF;EACE,IAAID,OAAOA,CAACA,OAAuB,EAAE;IACnC,IAAI,CAACC,QAAQ,GAAGD,OAAO;EACzB;;EAEA;AACF;EACE,IAAIJ,O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CAAC,EAAE;QACxD,IAAI,CAACA,QAAQ,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC0D,KAAK,CAAC,CAAC;MACrB;MAEA,MAAMC,GAAG;IACX;EACF;AACF;;AAEA;AACA;AACA,MAAMC,sBAAsB,GAAIC,IAAoB,IAAK;EACvD,IAAIA,IAAI,IAAI,IAAI,EAAE;IAChB,MAAM,IAAItF,wBAAwB,CAChC,kEACF,CAAC;EACH;EAEA,IAAI,CAACD,aAAa,CAACuF,IAAI,CAAC,EAAE;IACxB,MAAM,IAAItF,wBAAwB,CAChC,0DAA0D,OAAOsF,IAAI,EACvE,CAAC;EACH;EAEA,IAAI,CAACxF,GAAG,CAACwF,IAAI,EAAE,KAAK,CAAC,EAAE;IACrB,MAAM,IAAItF,wBAAwB,CAChC,wDAAwD+E,eAAA,CACtDO,IACF,CAAC,EACH,CAAC;EACH;EAEA,OAAO,IAAI;AACb,CAAC;;AAED;AACA;AACA,MAAMC,GAAG,GAAID,IAAoB,IAAmB;EAClDD,sBAAsB,CAACC,IAAI,CAAC;EAE5B,OAAO,IAAIrE,GAAG,CAACqE,IAAI,CAAC,CAACH,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,eAAeI,GAAG","ignoreList":[]}
1
+ {"version":3,"file":"xhr.js","names":["has","isPlainObject","IllegalArgumentException","UnauthorizedException","FetchException","TimeoutException","NotFoundException","JsonParseException","NetworkException","Cache","HTTP_METHODS","getSetting","NETWORK_ERROR_CODE","SUCCESS_CODE","CLIENT_ERROR_CODE","UNAUTHORIZED_CODE","REDIRECTION_CODE","NOT_FOUND_CODE","JSON_TYPE","XHR","constructor","options","_defineProperty","_options","_attempts","xmlhttp","_xmlhttp","attempts","url","params","_includesInstanceProperty","call","aUrl","split","data","method","GET","timeout","responseType","onProgress","events","getBaseLocale","_globalThis","navigator","language","headers","baseHeaders","Accept","timeoutHandler","reject","errorHandler","responseJSON","status","isReload","getResponse","response","getResponseHeader","JSON","parse","error","responseHandler","resolve","setEventListeners","forEach","eventType","addEventListener","_Object$keys","eventName","openConnection","open","setBasicAuthentication","hasItem","basicToken","getItem","setRequestHeader","headerName","setCustomHeaders","setOtherOptions","withCredentials","sendData","send","stringData","_JSON$stringify","setXMLHttpRequest","_Promise","XMLHttpRequest","fetch","err","validateInputArguments","args","xhr"],"sources":["../../../src/utils/fetch/xhr.js"],"sourcesContent":["// @flow\nimport { has, isPlainObject } from \"../helpers/objects\";\n\nimport {\n IllegalArgumentException,\n UnauthorizedException,\n FetchException,\n TimeoutException,\n NotFoundException,\n JsonParseException,\n NetworkException,\n} from \"../../exceptions\";\n\nimport Cache from \"../browser/Cache\";\n\nimport { HTTP_METHODS } from \"../../constants/Constants\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport type { RequestOptions } from \"./types\";\n\nconst NETWORK_ERROR_CODE = 0;\nconst SUCCESS_CODE = 200;\nconst CLIENT_ERROR_CODE = 400;\nconst UNAUTHORIZED_CODE = 401;\nconst REDIRECTION_CODE = 300;\nconst NOT_FOUND_CODE = 404;\n\nconst JSON_TYPE = \"application/json\";\n\n/**\n * @private\n */\nclass XHR {\n _options: RequestOptions;\n _xmlhttp: XMLHttpRequest;\n _attempts: number;\n\n /**\n */\n constructor(options: RequestOptions) {\n this._options = options;\n this._attempts = 0;\n }\n\n /**\n */\n get xmlhttp(): XMLHttpRequest {\n return this._xmlhttp;\n }\n\n /**\n */\n set xmlhttp(xmlhttp: XMLHttpRequest) {\n this._xmlhttp = xmlhttp;\n }\n\n /**\n */\n get options(): RequestOptions {\n return this._options;\n }\n\n /**\n */\n set options(options: RequestOptions) {\n this._options = options;\n }\n\n /**\n */\n get attempts(): number {\n return this._attempts;\n }\n\n /**\n */\n set attempts(attempts: number) {\n this._attempts = attempts;\n }\n\n /**\n * Create and fix url when params or both querystring and params exist.\n */\n get url(): string {\n const { url } = this.options;\n if (this.params !== \"\") {\n if (url.includes(\"?\")) {\n const aUrl = url.split(\"?\");\n\n return `${aUrl[0]}?${aUrl[1]}&${this.params}`;\n }\n\n return `${url}?${this.params}`;\n }\n\n return url;\n }\n\n /**\n */\n get params(): string {\n return this.options.params || \"\";\n }\n\n /**\n */\n get data(): any | null {\n return this.options.data || null;\n }\n\n /**\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this.options.method || HTTP_METHODS.GET;\n }\n\n /**\n */\n get timeout(): number {\n return this.options.timeout || getSetting(\"XHR_TIMEOUT_MS\", 300000);\n }\n\n /**\n */\n get responseType(): string {\n return this.options.responseType || \"json\";\n }\n\n /**\n */\n get onProgress(): ProgressEventHandler {\n if (this.options.onProgress) {\n return this.options.onProgress;\n }\n\n return () => {\n // do nothing\n };\n }\n\n /**\n */\n get events(): { [eventName: string]: () => void } {\n return this.options.events || {};\n }\n\n /**\n */\n getBaseLocale(): string {\n // $FlowIssue\n return globalThis.navigator?.language?.split(\"-\")[0] || \"en\";\n }\n\n /**\n */\n get headers(): { [string]: string } {\n const baseHeaders = {\n Accept: JSON_TYPE,\n \"Content-Type\": JSON_TYPE,\n\n // needed for csrf, see: https://plaza.beinformed.com/amdoc/csrf-protection-in-modular-ui-services-40054554.html\n \"X-Requested-With\": \"XMLHttpRequest\",\n\n \"Accept-Language\": this.getBaseLocale(),\n };\n\n if (this.options.headers) {\n // $FlowFixMe[cannot-spread-indexer]\n return {\n ...baseHeaders,\n ...this.options.headers,\n };\n }\n\n return baseHeaders;\n }\n\n /**\n */\n timeoutHandler(reject: Function): any {\n return reject(new TimeoutException(this.url, this.method));\n }\n\n /**\n */\n errorHandler(reject: Function, responseJSON: any = null): any {\n const { status } = this.xmlhttp;\n const { isReload } = this.options;\n\n if (status === NETWORK_ERROR_CODE) {\n return reject(new NetworkException(this.url, this.method));\n }\n\n if (status === NOT_FOUND_CODE) {\n return reject(new NotFoundException(this.url, this.method, isReload));\n }\n\n if (status === UNAUTHORIZED_CODE) {\n return reject(\n new UnauthorizedException(this.url, this.method, responseJSON),\n );\n }\n\n return reject(new FetchException(responseJSON, this.xmlhttp, this.options));\n }\n\n /**\n */\n getResponse(): any {\n const { responseType, response } = this.xmlhttp;\n\n if (\n (responseType === \"\" || responseType === \"text\") &&\n this.getResponseHeader(\"Content-Type\") === JSON_TYPE\n ) {\n if (isPlainObject(response)) {\n return response;\n }\n\n try {\n return JSON.parse(response);\n } catch (error) {\n throw new JsonParseException(error);\n }\n }\n\n return response;\n }\n\n /**\n */\n responseHandler(resolve: Function, reject: Function): any {\n const { status } = this.xmlhttp;\n\n let response = null;\n try {\n response = this.getResponse();\n } catch (error) {\n return reject(error);\n }\n\n if (\n (status >= SUCCESS_CODE && status < REDIRECTION_CODE) ||\n (status === CLIENT_ERROR_CODE && has(response, \"formresponse\"))\n ) {\n return resolve(response);\n }\n\n return this.errorHandler(reject, response);\n }\n\n /**\n */\n setEventListeners(resolve: Function, reject: Function) {\n if (this.options.onProgress) {\n [\"load\", \"loadend\", \"loadstart\", \"progress\"].forEach((eventType) => {\n this.xmlhttp.addEventListener(eventType, this.onProgress);\n });\n }\n\n [\"abort\", \"error\"].forEach((eventType) => {\n this.xmlhttp.addEventListener(eventType, () => this.errorHandler(reject));\n });\n\n this.xmlhttp.addEventListener(\"timeout\", () => this.timeoutHandler(reject));\n\n this.xmlhttp.addEventListener(\"load\", () =>\n this.responseHandler(resolve, reject),\n );\n\n // Set custom events\n Object.keys(this.events).forEach((eventName) => {\n this.xmlhttp.addEventListener(eventName, this.events[eventName]);\n });\n }\n\n /**\n */\n openConnection() {\n this.xmlhttp.open(this.method, this.url, true);\n }\n\n /**\n */\n setBasicAuthentication() {\n if (Cache.hasItem(\"basic\")) {\n const basicToken = Cache.getItem(\"basic\");\n\n if (typeof basicToken === \"string\") {\n this.xmlhttp.setRequestHeader(\"Authorization\", `Basic ${basicToken}`);\n }\n }\n }\n\n /**\n */\n getResponseHeader(headerName: string): string | null {\n return this.xmlhttp.getResponseHeader(headerName);\n }\n\n /**\n */\n setCustomHeaders() {\n Object.keys(this.headers).forEach((headerName) => {\n this.xmlhttp.setRequestHeader(headerName, this.headers[headerName]);\n });\n }\n\n /**\n */\n setOtherOptions() {\n if (\n this.options.withCredentials ||\n getSetting(\"XHR_ALWAYS_WITH_CREDENTIALS\", Cache.hasItem(\"basic\"))\n ) {\n this.xmlhttp.withCredentials = true;\n }\n this.xmlhttp.responseType = this.responseType;\n this.xmlhttp.timeout = this.timeout;\n }\n\n /**\n */\n sendData() {\n if (this.data == null) {\n this.xmlhttp.send();\n } else {\n const stringData = isPlainObject(this.data)\n ? JSON.stringify(this.data)\n : this.data;\n this.xmlhttp.send(stringData);\n }\n }\n\n /**\n */\n setXMLHttpRequest(): Promise<any> {\n return new Promise((resolve, reject) => {\n this.xmlhttp = new XMLHttpRequest();\n\n this.setEventListeners(resolve, reject);\n\n this.openConnection();\n\n this.setBasicAuthentication();\n\n this.setCustomHeaders();\n\n this.setOtherOptions();\n\n this.sendData();\n });\n }\n\n /**\n */\n async fetch(): Promise<any> {\n try {\n return await this.setXMLHttpRequest();\n } catch (err) {\n if (err instanceof NetworkException && this.attempts < 2) {\n this.attempts += 1;\n return this.fetch();\n }\n\n throw err;\n }\n }\n}\n\n/**\n */\nconst validateInputArguments = (args: RequestOptions) => {\n if (args == null) {\n throw new IllegalArgumentException(\n \"Missing request options, expecting an object as argument for xhr\",\n );\n }\n\n if (!isPlainObject(args)) {\n throw new IllegalArgumentException(\n `Expecting an object as argument for xhr, but received: ${typeof args}`,\n );\n }\n\n if (!has(args, \"url\")) {\n throw new IllegalArgumentException(\n `No url property found in arguments of xhr, received: ${JSON.stringify(\n args,\n )}`,\n );\n }\n\n return true;\n};\n\n/**\n */\nconst xhr = (args: RequestOptions): Promise<any> => {\n validateInputArguments(args);\n\n return new XHR(args).fetch();\n};\n\nexport default xhr;\n"],"mappings":";;;;;;AACA,SAASA,GAAG,EAAEC,aAAa,QAAQ,oBAAoB;AAEvD,SACEC,wBAAwB,EACxBC,qBAAqB,EACrBC,cAAc,EACdC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,EAClBC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AI,EAAE,KAAK,CAAC,EAAE;IACrB,MAAM,IAAIvF,wBAAwB,CAChC,wDAAwDgF,eAAA,CACtDO,IACF,CAAC,EACH,CAAC;EACH;EAEA,OAAO,IAAI;AACb,CAAC;;AAED;AACA;AACA,MAAMC,GAAG,GAAID,IAAoB,IAAmB;EAClDD,sBAAsB,CAACC,IAAI,CAAC;EAE5B,OAAO,IAAItE,GAAG,CAACsE,IAAI,CAAC,CAACH,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,eAAeI,GAAG","ignoreList":[]}
@@ -47,7 +47,7 @@ const useModularUI = (modelKey, url, options = {}) => {
47
47
  const requestOptions = (0, _react.useMemo)(() => {
48
48
  const merged = {
49
49
  method: _constants.HTTP_METHODS.GET,
50
- removeOnUnmount: false,
50
+ removeOnUnmount: true,
51
51
  ...options
52
52
  };
53
53
  if (url instanceof _Href.default) {
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useModularUIKey","_Href","useModularUI","modelKey","url","options","dispatch","useDispatch","hrefInstance","useMemo","Href","requestUrl","toString","currentQueryString","querystring","prevQueryRef","useRef","key","useModularUIKey","model","useSelector","state","modularui","requestOptions","merged","method","HTTP_METHODS","GET","removeOnUnmount","origin","contextPath","location","useLocation","redirectLocation","shouldLoad","status","MODULARUI_STATUS","ERROR","current","equals","isReload","useEffect","useDeepCompareEffect","loadModularUI","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\nimport type { ModelEntry } from \"../redux\";\n\n/**\n * A custom hook to fetch and manage Be Informed modular UI resources.\n * It handles automatic data fetching based on URL/query changes, manages Redux state\n * synchronization, and provides cleanup logic when components unmount.\n *\n * @param {string} modelKey - A unique identifier for the type of model being fetched.\n * @param {string | Href} url - The endpoint URL or Href instance to fetch data from.\n * @param {RequestModularUIOptions} options - Configuration for the request (method, headers, etc.).\n * @returns {ModelEntry} The model data retrieved from the Redux store.\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = (({}: any): RequestModularUIOptions),\n): any => {\n const dispatch = useDispatch();\n\n // Normalize the URL input into a Href instance to safely access query params and paths\n const hrefInstance = useMemo(() => new Href(url), [url]);\n const requestUrl = useMemo(() => hrefInstance.toString(), [hrefInstance]);\n const currentQueryString = hrefInstance.querystring;\n\n // Persistence ref to detect if query parameters have changed between renders\n const prevQueryRef = useRef(currentQueryString);\n\n // Generate a unique key for the Redux store based on the model type and the full URL\n const key = useModularUIKey(modelKey, requestUrl);\n\n // Select the specific piece of state corresponding to this modular UI component\n const model = useSelector((state) => state.modularui[key]);\n\n /**\n * Memoize request options to prevent unnecessary re-renders.\n * Merges default settings (GET method, auto-cleanup) with user-provided options.\n */\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: false,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n /**\n * Determines if a network request should be initiated.\n * Logic includes:\n * - Model doesn't exist yet (Initial load)\n * - Previous request resulted in an error (Retry)\n * - The query parameters changed (Filtering/Paging)\n * - A redirect was triggered specifically for this URL\n * - Manual 'isReload' flag is passed in options\n */\n const shouldLoad =\n model == null ||\n model.status === MODULARUI_STATUS.ERROR ||\n prevQueryRef.current !== currentQueryString ||\n (redirectLocation instanceof Href\n ? redirectLocation.equals(requestUrl)\n : false) ||\n requestOptions.isReload === true;\n\n // Synchronize the ref after the render cycle determines if we should load\n useEffect(() => {\n prevQueryRef.current = currentQueryString;\n }, [currentQueryString]);\n\n // Execute the load action. Deep compare is used on options to prevent\n // infinite loops caused by passing inline object literals.\n useDeepCompareEffect(() => {\n if (requestUrl !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, requestUrl, requestOptions));\n }\n }, [key, requestUrl, requestOptions, shouldLoad]);\n\n // Cleanup Effect:\n // If 'removeOnUnmount' is true, this removes the model data from the Redux store\n // when the component using this hook is destroyed.\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,YAAY,GAAGA,CAC1BC,QAAgB,EAChBC,GAAkB,EAClBC,OAAgC,GAAK,CAAC,CAAiC,KAC/D;EACR,MAAMC,QAAQ,GAAG,IAAAC,uBAAW,EAAC,CAAC;;EAE9B;EACA,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAM,IAAIC,aAAI,CAACN,GAAG,CAAC,EAAE,CAACA,GAAG,CAAC,CAAC;EACxD,MAAMO,UAAU,GAAG,IAAAF,cAAO,EAAC,MAAMD,YAAY,CAACI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c,CAACiB,QAAQ,KAAK,IAAI;;EAElC;EACA,IAAAC,gBAAS,EAAC,MAAM;IACd1B,YAAY,CAACuB,OAAO,GAAGzB,kBAAkB;EAC3C,CAAC,EAAE,CAACA,kBAAkB,CAAC,CAAC;;EAExB;EACA;EACA,IAAA6B,6BAAoB,EAAC,MAAM;IACzB,IAAI/B,UAAU,KAAK,EAAE,IAAIuB,UAAU,EAAE;MACnC5B,QAAQ,CAAC,IAAAqC,+BAAa,EAAC1B,GAAG,EAAEN,UAAU,EAAEY,cAAc,CAAC,CAAC;IAC1D;EACF,CAAC,EAAE,CAACN,GAAG,EAAEN,UAAU,EAAEY,cAAc,EAAEW,UAAU,CAAC,CAAC;;EAEjD;EACA;EACA;EACA,IAAAO,gBAAS,EAAC,MAAM;IACd,IAAIlB,cAAc,CAACK,eAAe,EAAE;MAClC,OAAO,MAAM;QACXtB,QAAQ,CAAC,IAAAsC,kCAAgB,EAAC3B,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACX,QAAQ,EAAEW,GAAG,EAAEM,cAAc,CAACK,eAAe,CAAC,CAAC;EAEnD,OAAOT,KAAK;AACd,CAAC;AAAC0B,OAAA,CAAA3C,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUI.js","names":["_react","require","_reactRedux","_reactRouter","_constants","_ModularUIActions","_useDeepCompareEffect","_interopRequireDefault","_useModularUIKey","_Href","useModularUI","modelKey","url","options","dispatch","useDispatch","hrefInstance","useMemo","Href","requestUrl","toString","currentQueryString","querystring","prevQueryRef","useRef","key","useModularUIKey","model","useSelector","state","modularui","requestOptions","merged","method","HTTP_METHODS","GET","removeOnUnmount","origin","contextPath","location","useLocation","redirectLocation","shouldLoad","status","MODULARUI_STATUS","ERROR","current","equals","isReload","useEffect","useDeepCompareEffect","loadModularUI","removeModelByKey","exports"],"sources":["../../src/hooks/useModularUI.js"],"sourcesContent":["// @flow\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { useDispatch, useSelector } from \"react-redux\";\nimport { useLocation } from \"react-router\";\n\nimport { HTTP_METHODS, MODULARUI_STATUS } from \"../constants\";\nimport {\n loadModularUI,\n removeModelByKey,\n} from \"../redux/_modularui/ModularUIActions\";\n\nimport useDeepCompareEffect from \"./useDeepCompareEffect\";\nimport { useModularUIKey } from \"./useModularUIKey\";\n\nimport Href from \"../models/href/Href\";\n\nimport type { RequestModularUIOptions } from \"../utils\";\nimport type { ModelEntry } from \"../redux\";\n\n/**\n * A custom hook to fetch and manage Be Informed modular UI resources.\n * It handles automatic data fetching based on URL/query changes, manages Redux state\n * synchronization, and provides cleanup logic when components unmount.\n *\n * @param {string} modelKey - A unique identifier for the type of model being fetched.\n * @param {string | Href} url - The endpoint URL or Href instance to fetch data from.\n * @param {RequestModularUIOptions} options - Configuration for the request (method, headers, etc.).\n * @returns {ModelEntry} The model data retrieved from the Redux store.\n */\nexport const useModularUI = (\n modelKey: string,\n url: string | Href,\n options: RequestModularUIOptions = (({}: any): RequestModularUIOptions),\n): any => {\n const dispatch = useDispatch();\n\n // Normalize the URL input into a Href instance to safely access query params and paths\n const hrefInstance = useMemo(() => new Href(url), [url]);\n const requestUrl = useMemo(() => hrefInstance.toString(), [hrefInstance]);\n const currentQueryString = hrefInstance.querystring;\n\n // Persistence ref to detect if query parameters have changed between renders\n const prevQueryRef = useRef(currentQueryString);\n\n // Generate a unique key for the Redux store based on the model type and the full URL\n const key = useModularUIKey(modelKey, requestUrl);\n\n // Select the specific piece of state corresponding to this modular UI component\n const model = useSelector((state) => state.modularui[key]);\n\n /**\n * Memoize request options to prevent unnecessary re-renders.\n * Merges default settings (GET method, auto-cleanup) with user-provided options.\n */\n const requestOptions = useMemo(() => {\n const merged = {\n method: HTTP_METHODS.GET,\n removeOnUnmount: true,\n ...options,\n };\n\n if (url instanceof Href) {\n merged.origin = merged.origin ?? url.origin;\n merged.contextPath = merged.contextPath ?? url.contextPath;\n }\n return merged;\n }, [options, url]);\n\n const location = useLocation();\n const redirectLocation = location.state?.redirectLocation;\n\n /**\n * Determines if a network request should be initiated.\n * Logic includes:\n * - Model doesn't exist yet (Initial load)\n * - Previous request resulted in an error (Retry)\n * - The query parameters changed (Filtering/Paging)\n * - A redirect was triggered specifically for this URL\n * - Manual 'isReload' flag is passed in options\n */\n const shouldLoad =\n model == null ||\n model.status === MODULARUI_STATUS.ERROR ||\n prevQueryRef.current !== currentQueryString ||\n (redirectLocation instanceof Href\n ? redirectLocation.equals(requestUrl)\n : false) ||\n requestOptions.isReload === true;\n\n // Synchronize the ref after the render cycle determines if we should load\n useEffect(() => {\n prevQueryRef.current = currentQueryString;\n }, [currentQueryString]);\n\n // Execute the load action. Deep compare is used on options to prevent\n // infinite loops caused by passing inline object literals.\n useDeepCompareEffect(() => {\n if (requestUrl !== \"\" && shouldLoad) {\n dispatch(loadModularUI(key, requestUrl, requestOptions));\n }\n }, [key, requestUrl, requestOptions, shouldLoad]);\n\n // Cleanup Effect:\n // If 'removeOnUnmount' is true, this removes the model data from the Redux store\n // when the component using this hook is destroyed.\n useEffect(() => {\n if (requestOptions.removeOnUnmount) {\n return () => {\n dispatch(removeModelByKey(key));\n };\n }\n }, [dispatch, key, requestOptions.removeOnUnmount]);\n\n return model;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAKA,IAAAK,qBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAF,sBAAA,CAAAN,OAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,YAAY,GAAGA,CAC1BC,QAAgB,EAChBC,GAAkB,EAClBC,OAAgC,GAAK,CAAC,CAAiC,KAC/D;EACR,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f,KAAK,IAAI,IAAI,IACbA,KAAK,CAACgB,MAAM,KAAKC,2BAAgB,CAACC,KAAK,IACvCtB,YAAY,CAACuB,OAAO,KAAKzB,kBAAkB,KAC1CoB,gBAAgB,YAAYvB,aAAI,GAC7BuB,gBAAgB,CAACM,MAAM,CAAC5B,UAAU,CAAC,GACnC,KAAK,CAAC,IACVY,cAAc,CAACiB,QAAQ,KAAK,IAAI;;EAElC;EACA,IAAAC,gBAAS,EAAC,MAAM;IACd1B,YAAY,CAACuB,OAAO,GAAGzB,kBAAkB;EAC3C,CAAC,EAAE,CAACA,kBAAkB,CAAC,CAAC;;EAExB;EACA;EACA,IAAA6B,6BAAoB,EAAC,MAAM;IACzB,IAAI/B,UAAU,KAAK,EAAE,IAAIuB,UAAU,EAAE;MACnC5B,QAAQ,CAAC,IAAAqC,+BAAa,EAAC1B,GAAG,EAAEN,UAAU,EAAEY,cAAc,CAAC,CAAC;IAC1D;EACF,CAAC,EAAE,CAACN,GAAG,EAAEN,UAAU,EAAEY,cAAc,EAAEW,UAAU,CAAC,CAAC;;EAEjD;EACA;EACA;EACA,IAAAO,gBAAS,EAAC,MAAM;IACd,IAAIlB,cAAc,CAACK,eAAe,EAAE;MAClC,OAAO,MAAM;QACXtB,QAAQ,CAAC,IAAAsC,kCAAgB,EAAC3B,GAAG,CAAC,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACX,QAAQ,EAAEW,GAAG,EAAEM,cAAc,CAACK,eAAe,CAAC,CAAC;EAEnD,OAAOT,KAAK;AACd,CAAC;AAAC0B,OAAA,CAAA3C,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -18,6 +18,7 @@ var _useModularUIBasic = require("./useModularUIBasic");
18
18
  const useApplication = options => (0, _useModularUIBasic.useModularUIBasic)("application", "/", {
19
19
  expectedModels: ["Application"],
20
20
  targetModel: _ApplicationModel.default,
21
+ removeOnUnmount: options?.removeOnUnmount ?? false,
21
22
  ...options
22
23
  });
23
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIModel.js","names":["_ApplicationModel","_interopRequireDefault","require","_CaseViewModel","_TabModel","_GroupingPanelModel","_DetailModel","_UserProfileModel","_useModularUIBasic","useApplication","options","useModularUIBasic","expectedModels","targetModel","ApplicationModel","exports","useTab","href","TabModel","useCaseView","CaseViewModel","useGroupingPanel","GroupingPanelModel","useDetailPanel","DetailModel","useUserProfile","UserProfileModel"],"sources":["../../src/hooks/useModularUIModel.js"],"sourcesContent":["// @flow\nimport ApplicationModel from \"../models/application/ApplicationModel\";\nimport CaseViewModel from \"../models/caseview/CaseViewModel\";\nimport TabModel from \"../models/tab/TabModel\";\nimport GroupingPanelModel from \"../models/panels/GroupingPanelModel\";\nimport DetailModel from \"../models/detail/DetailModel\";\nimport UserProfileModel from \"../models/user/UserProfileModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\n\nimport type Href from \"../models/href/Href\";\nimport type { HookOptions } from \"./useModularUIBasic\";\n\n/**\n * Load application\n */\nexport const useApplication = (\n options?: HookOptions,\n): ApplicationModel | null =>\n useModularUIBasic(\"application\", \"/\", {\n expectedModels: [\"Application\"],\n targetModel: ApplicationModel,\n ...options,\n });\n\n/**\n * Load a tab by href\n */\nexport const useTab = (\n href: string | Href,\n options?: HookOptions,\n): TabModel | null =>\n useModularUIBasic(\"tab\", href, {\n expectedModels: [\"Tab\"],\n targetModel: TabModel,\n ...options,\n });\n\n/**\n * Load caseview by href\n */\nexport const useCaseView = (\n href: string | Href,\n options?: HookOptions,\n): CaseViewModel | null =>\n useModularUIBasic(\"caseview\", href, {\n expectedModels: [\"CaseView\"],\n targetModel: CaseViewModel,\n ...options,\n });\n\n/**\n */\nexport const useGroupingPanel = (\n href: string | Href,\n options?: HookOptions,\n): GroupingPanelModel | null =>\n useModularUIBasic(\"groupingpanel\", href, {\n expectedModels: [\"GroupingPanel\"],\n targetModel: GroupingPanelModel,\n ...options,\n });\n\n/**\n */\nexport const useDetailPanel = (\n href: string | Href,\n options?: HookOptions,\n): DetailModel | null =>\n useModularUIBasic(\"detailpanel\", href, {\n expectedModels: [\"Detail\"],\n targetModel: DetailModel,\n ...options,\n });\n\n/**\n */\nexport const useUserProfile = (\n href: string | Href,\n options?: HookOptions,\n): UserProfileModel | null =>\n useModularUIBasic(\"userprofile\", href, {\n expectedModels: [\"UserProfile\"],\n targetModel: UserProfileModel,\n ...options,\n });\n"],"mappings":";;;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,mBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,YAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,iBAAA,GAAAN,sBAAA,CAAAC,OAAA;AAEA,IAAAM,kBAAA,GAAAN,OAAA;AAKA;AACA;AACA;AACO,MAAMO,cAAc,GACzBC,OAAqB,IAErB,IAAAC,oCAAiB,EAAC,aAAa,EAAE,GAAG,EAAE;EACpCC,cAAc,EAAE,CAAC,aAAa,CAAC;EAC/BC,WAAW,EAAEC,yBAAgB;EAC7B,GAAGJ;AACL,CAAC,CAAC;;AAEJ;AACA;AACA;AAFAK,OAAA,CAAAN,cAAA,GAAAA,cAAA;AAGO,MAAMO,MAAM,GAAGA,CACpBC,IAAmB,EACnBP,OAAqB,KAErB,IAAAC,oCAAiB,EAAC,KAAK,EAAEM,IAAI,EAAE;EAC7BL,cAAc,EAAE,CAAC,KAAK,CAAC;EACvBC,WAAW,EAAEK,iBAAQ;EACrB,GAAGR;AACL,CAAC,CAAC;;AAEJ;AACA;AACA;AAFAK,OAAA,CAAAC,MAAA,GAAAA,MAAA;AAGO,MAAMG,WAAW,GAAGA,CACzBF,IAAmB,EACnBP,OAAqB,KAErB,IAAAC,oCAAiB,EAAC,UAAU,EAAEM,IAAI,EAAE;EAClCL,cAAc,EAAE,CAAC,UAAU,CAAC;EAC5BC,WAAW,EAAEO,sBAAa;EAC1B,GAAGV;AACL,CAAC,CAAC;;AAEJ;AACA;AADAK,OAAA,CAAAI,WAAA,GAAAA,WAAA;AAEO,MAAME,gBAAgB,GAAGA,CAC9BJ,IAAmB,EACnBP,OAAqB,KAErB,IAAAC,oCAAiB,EAAC,eAAe,EAAEM,IAAI,EAAE;EACvCL,cAAc,EAAE,CAAC,eAAe,CAAC;EACjCC,WAAW,EAAES,2BAAkB;EAC/B,GAAGZ;AACL,CAAC,CAAC;;AAEJ;AACA;AADAK,OAAA,CAAAM,gBAAA,GAAAA,gBAAA;AAEO,MAAME,cAAc,GAAGA,CAC5BN,IAAmB,EACnBP,OAAqB,KAErB,IAAAC,oCAAiB,EAAC,aAAa,EAAEM,IAAI,EAAE;EACrCL,cAAc,EAAE,CAAC,QAAQ,CAAC;EAC1BC,WAAW,EAAEW,oBAAW;EACxB,GAAGd;AACL,CAAC,CAAC;;AAEJ;AACA;AADAK,OAAA,CAAAQ,cAAA,GAAAA,cAAA;AAEO,MAAME,cAAc,GAAGA,CAC5BR,IAAmB,EACnBP,OAAqB,KAErB,IAAAC,oCAAiB,EAAC,aAAa,EAAEM,IAAI,EAAE;EACrCL,cAAc,EAAE,CAAC,aAAa,CAAC;EAC/BC,WAAW,EAAEa,yBAAgB;EAC7B,GAAGhB;AACL,CAAC,CAAC;AAACK,OAAA,CAAAU,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIModel.js","names":["_ApplicationModel","_interopRequireDefault","require","_CaseViewModel","_TabModel","_GroupingPanelModel","_DetailModel","_UserProfileModel","_useModularUIBasic","useApplication","options","useModularUIBasic","expectedModels","targetModel","ApplicationModel","removeOnUnmount","exports","useTab","href","TabModel","useCaseView","CaseViewModel","useGroupingPanel","GroupingPanelModel","useDetailPanel","DetailModel","useUserProfile","UserProfileModel"],"sources":["../../src/hooks/useModularUIModel.js"],"sourcesContent":["// @flow\nimport ApplicationModel from \"../models/application/ApplicationModel\";\nimport CaseViewModel from \"../models/caseview/CaseViewModel\";\nimport TabModel from \"../models/tab/TabModel\";\nimport GroupingPanelModel from \"../models/panels/GroupingPanelModel\";\nimport DetailModel from \"../models/detail/DetailModel\";\nimport UserProfileModel from \"../models/user/UserProfileModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\n\nimport type Href from \"../models/href/Href\";\nimport type { HookOptions } from \"./useModularUIBasic\";\n\n/**\n * Load application\n */\nexport const useApplication = (\n options?: HookOptions,\n): ApplicationModel | null =>\n useModularUIBasic(\"application\", \"/\", {\n expectedModels: [\"Application\"],\n targetModel: ApplicationModel,\n removeOnUnmount: options?.removeOnUnmount ?? false,\n ...options,\n });\n\n/**\n * Load a tab by href\n */\nexport const useTab = (\n href: string | Href,\n options?: HookOptions,\n): TabModel | null =>\n useModularUIBasic(\"tab\", href, {\n expectedModels: [\"Tab\"],\n targetModel: TabModel,\n ...options,\n });\n\n/**\n * Load caseview by href\n */\nexport const useCaseView = (\n href: string | Href,\n options?: HookOptions,\n): CaseViewModel | null =>\n useModularUIBasic(\"caseview\", href, {\n expectedModels: [\"CaseView\"],\n targetModel: CaseViewModel,\n ...options,\n });\n\n/**\n */\nexport const useGroupingPanel = (\n href: string | Href,\n options?: HookOptions,\n): GroupingPanelModel | null =>\n useModularUIBasic(\"groupingpanel\", href, {\n expectedModels: [\"GroupingPanel\"],\n targetModel: GroupingPanelModel,\n ...options,\n });\n\n/**\n */\nexport const useDetailPanel = (\n href: string | Href,\n options?: HookOptions,\n): DetailModel | null =>\n useModularUIBasic(\"detailpanel\", href, {\n expectedModels: [\"Detail\"],\n targetModel: DetailModel,\n ...options,\n });\n\n/**\n */\nexport const useUserProfile = (\n href: string | Href,\n options?: HookOptions,\n): UserProfileModel | null =>\n useModularUIBasic(\"userprofile\", href, {\n expectedModels: [\"UserProfile\"],\n targetModel: UserProfileModel,\n ...options,\n });\n"],"mappings":";;;;;;;AACA,IAAAA,iBAAA,GAAAC,sBAA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