@empathyco/x-components 3.0.0-alpha.76 → 3.0.0-alpha.79

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 (193) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/core/index.js +0 -1
  3. package/core/index.js.map +1 -1
  4. package/design-system/default-theme.css +100 -100
  5. package/docs/API-reference/api/x-components.actionstree.md +1 -1
  6. package/docs/API-reference/api/x-components.anyactionstree.md +1 -1
  7. package/docs/API-reference/api/x-components.anygetterstree.md +1 -1
  8. package/docs/API-reference/api/x-components.anymutationstree.md +1 -1
  9. package/docs/API-reference/api/x-components.compilemessage.md +1 -1
  10. package/docs/API-reference/api/x-components.extraparams.md +2 -2
  11. package/docs/API-reference/api/x-components.extraparamsmutations.setparams.md +1 -1
  12. package/docs/API-reference/api/x-components.extraparamsstate.md +1 -1
  13. package/docs/API-reference/api/x-components.extraparamsxevents.md +4 -4
  14. package/docs/API-reference/api/x-components.getterstree.md +1 -1
  15. package/docs/API-reference/api/x-components.identifierresultsmutations.setparams.md +1 -1
  16. package/docs/API-reference/api/x-components.identifierresultsstate.md +1 -1
  17. package/docs/API-reference/api/x-components.md +0 -8
  18. package/docs/API-reference/api/x-components.mutationstree.md +1 -1
  19. package/docs/API-reference/api/x-components.nextqueriesmutations.setparams.md +1 -1
  20. package/docs/API-reference/api/x-components.nextqueriesstate.md +1 -1
  21. package/docs/API-reference/api/x-components.popularsearchesmutations.setparams.md +1 -1
  22. package/docs/API-reference/api/x-components.popularsearchesstate.md +1 -1
  23. package/docs/API-reference/api/x-components.querysuggestionsmutations.setparams.md +1 -1
  24. package/docs/API-reference/api/x-components.querysuggestionsstate.md +1 -1
  25. package/docs/API-reference/api/x-components.recommendationsmutations.setparams.md +1 -1
  26. package/docs/API-reference/api/x-components.recommendationsstate.md +1 -1
  27. package/docs/API-reference/api/x-components.relatedtagsmutations.setparams.md +1 -1
  28. package/docs/API-reference/api/x-components.relatedtagsstate.md +1 -1
  29. package/docs/API-reference/api/x-components.renderlessextraparams.md +1 -1
  30. package/docs/API-reference/api/x-components.returns.md +0 -2
  31. package/docs/API-reference/api/x-components.scrollstate.md +1 -1
  32. package/docs/API-reference/api/x-components.searchmutations.setparams.md +1 -1
  33. package/docs/API-reference/api/x-components.searchstate.md +2 -2
  34. package/docs/API-reference/api/x-components.setextraparams.md +1 -1
  35. package/docs/API-reference/api/x-components.setidentifierresultsextraparams.md +1 -1
  36. package/docs/API-reference/api/x-components.setinitialextraparams.md +1 -1
  37. package/docs/API-reference/api/x-components.setnextqueriesextraparams.md +1 -1
  38. package/docs/API-reference/api/x-components.setpopularsearchesextraparams.md +1 -1
  39. package/docs/API-reference/api/x-components.setquerysuggestionsextraparams.md +1 -1
  40. package/docs/API-reference/api/x-components.setrecommendationsextraparams.md +1 -1
  41. package/docs/API-reference/api/x-components.setrelatedtagsextraparams.md +1 -1
  42. package/docs/API-reference/api/x-components.setsearchextraparams.md +1 -1
  43. package/docs/API-reference/api/x-components.simplestateselector.md +0 -2
  44. package/docs/API-reference/api/x-components.snippetconfigextraparams.md +1 -1
  45. package/docs/API-reference/api/x-components.urlhandler.md +1 -1
  46. package/docs/API-reference/api/x-components.urlmutations.setinitialextraparams.md +1 -1
  47. package/docs/API-reference/api/x-components.urlstate.md +1 -1
  48. package/docs/API-reference/api/x-components.urlxevents.extraparamsloadedfromurl.md +1 -1
  49. package/docs/API-reference/api/x-components.urlxevents.md +1 -1
  50. package/docs/API-reference/api/x-components.vuecssclasses.md +0 -2
  51. package/docs/API-reference/api/x-components.wiring.md +1 -1
  52. package/js/components/global-x-bus.vue.js.map +1 -1
  53. package/js/components/global-x-bus.vue_rollup-plugin-vue_script.vue.js +1 -1
  54. package/js/components/global-x-bus.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  55. package/js/components/snippet-callbacks.vue.js.map +1 -1
  56. package/js/components/snippet-callbacks.vue_rollup-plugin-vue_script.vue.js +1 -1
  57. package/js/components/snippet-callbacks.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  58. package/js/components/suggestions/base-suggestion.vue.js.map +1 -1
  59. package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js +1 -1
  60. package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  61. package/js/filters/compile-message.filter.js.map +1 -1
  62. package/js/index.js +0 -1
  63. package/js/index.js.map +1 -1
  64. package/js/plugins/x-emitters.js +1 -1
  65. package/js/plugins/x-emitters.js.map +1 -1
  66. package/js/plugins/x-plugin.js +1 -2
  67. package/js/plugins/x-plugin.js.map +1 -1
  68. package/js/store/utils/getters-proxy.utils.js +1 -1
  69. package/js/store/utils/getters-proxy.utils.js.map +1 -1
  70. package/js/store/utils/store-emitters.utils.js.map +1 -1
  71. package/js/x-installer/x-installer/x-installer.js +1 -1
  72. package/js/x-installer/x-installer/x-installer.js.map +1 -1
  73. package/js/x-modules/extra-params/components/extra-params.vue.js.map +1 -1
  74. package/js/x-modules/extra-params/components/extra-params.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  75. package/js/x-modules/extra-params/components/renderless-extra-param.vue.js.map +1 -1
  76. package/js/x-modules/extra-params/components/renderless-extra-param.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  77. package/js/x-modules/extra-params/components/snippet-config-extra-params.vue.js.map +1 -1
  78. package/js/x-modules/extra-params/components/snippet-config-extra-params.vue_rollup-plugin-vue_script.vue.js +1 -2
  79. package/js/x-modules/extra-params/components/snippet-config-extra-params.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  80. package/js/x-modules/facets/components/facets/facets.vue.js +2 -2
  81. package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
  82. package/js/x-modules/facets/components/facets/facets.vue_rollup-plugin-vue_script.vue.js +1 -1
  83. package/js/x-modules/facets/components/facets/facets.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  84. package/js/x-modules/facets/store/getters/facets.getter.js +1 -1
  85. package/js/x-modules/facets/store/getters/facets.getter.js.map +1 -1
  86. package/js/x-modules/facets/store/getters/selected-filters-by-facet.getter.js +1 -1
  87. package/js/x-modules/facets/store/getters/selected-filters-by-facet.getter.js.map +1 -1
  88. package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
  89. package/js/x-modules/scroll/components/scroll-to-top.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  90. package/js/x-modules/search/store/actions/reset-state.action.js +1 -1
  91. package/js/x-modules/search/store/actions/reset-state.action.js.map +1 -1
  92. package/js/x-modules/url/components/url-handler.vue.js.map +1 -1
  93. package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js +1 -1
  94. package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js.map +1 -1
  95. package/js/x-modules/url/store/getters/url-params.getter.js +1 -1
  96. package/js/x-modules/url/store/getters/url-params.getter.js.map +1 -1
  97. package/js/x-modules/url/store/mutations/set-params.mutation.js +1 -1
  98. package/js/x-modules/url/store/mutations/set-params.mutation.js.map +1 -1
  99. package/package.json +13 -15
  100. package/report/tsdoc-metadata.json +1 -1
  101. package/report/x-adapter.api.json +1 -1
  102. package/report/x-components.api.json +688 -1054
  103. package/report/x-components.api.md +1 -24
  104. package/report/x-types.api.json +1 -1
  105. package/types/components/snippet-callbacks.vue.d.ts.map +1 -1
  106. package/types/components/suggestions/base-suggestion.vue.d.ts.map +1 -1
  107. package/types/filters/compile-message.filter.d.ts +1 -1
  108. package/types/filters/compile-message.filter.d.ts.map +1 -1
  109. package/types/plugins/x-emitters.d.ts.map +1 -1
  110. package/types/plugins/x-plugin.d.ts.map +1 -1
  111. package/types/store/actions.types.d.ts +2 -1
  112. package/types/store/actions.types.d.ts.map +1 -1
  113. package/types/store/getters.types.d.ts +1 -1
  114. package/types/store/getters.types.d.ts.map +1 -1
  115. package/types/store/mutations.types.d.ts +1 -1
  116. package/types/store/mutations.types.d.ts.map +1 -1
  117. package/types/store/utils/getters-proxy.utils.d.ts.map +1 -1
  118. package/types/store/utils/store-emitters.utils.d.ts +2 -1
  119. package/types/store/utils/store-emitters.utils.d.ts.map +1 -1
  120. package/types/utils/index.d.ts +0 -1
  121. package/types/utils/index.d.ts.map +1 -1
  122. package/types/utils/types.d.ts +1 -9
  123. package/types/utils/types.d.ts.map +1 -1
  124. package/types/wiring/wiring.types.d.ts +2 -1
  125. package/types/wiring/wiring.types.d.ts.map +1 -1
  126. package/types/x-installer/x-installer/x-installer.d.ts.map +1 -1
  127. package/types/x-modules/extra-params/components/extra-params.vue.d.ts +1 -1
  128. package/types/x-modules/extra-params/components/extra-params.vue.d.ts.map +1 -1
  129. package/types/x-modules/extra-params/components/renderless-extra-param.vue.d.ts +1 -1
  130. package/types/x-modules/extra-params/components/renderless-extra-param.vue.d.ts.map +1 -1
  131. package/types/x-modules/extra-params/components/snippet-config-extra-params.vue.d.ts +1 -1
  132. package/types/x-modules/extra-params/components/snippet-config-extra-params.vue.d.ts.map +1 -1
  133. package/types/x-modules/extra-params/events.types.d.ts +1 -1
  134. package/types/x-modules/extra-params/events.types.d.ts.map +1 -1
  135. package/types/x-modules/extra-params/store/emitters.d.ts +1 -1
  136. package/types/x-modules/extra-params/store/types.d.ts +1 -1
  137. package/types/x-modules/extra-params/store/types.d.ts.map +1 -1
  138. package/types/x-modules/extra-params/wiring.d.ts +4 -4
  139. package/types/x-modules/extra-params/wiring.d.ts.map +1 -1
  140. package/types/x-modules/facets/components/facets/facets.vue.d.ts +1 -1
  141. package/types/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
  142. package/types/x-modules/identifier-results/store/types.d.ts +1 -1
  143. package/types/x-modules/identifier-results/store/types.d.ts.map +1 -1
  144. package/types/x-modules/identifier-results/wiring.d.ts +2 -2
  145. package/types/x-modules/identifier-results/wiring.d.ts.map +1 -1
  146. package/types/x-modules/next-queries/store/types.d.ts +1 -1
  147. package/types/x-modules/next-queries/store/types.d.ts.map +1 -1
  148. package/types/x-modules/next-queries/wiring.d.ts +2 -2
  149. package/types/x-modules/next-queries/wiring.d.ts.map +1 -1
  150. package/types/x-modules/popular-searches/store/types.d.ts +1 -1
  151. package/types/x-modules/popular-searches/store/types.d.ts.map +1 -1
  152. package/types/x-modules/popular-searches/wiring.d.ts +2 -2
  153. package/types/x-modules/popular-searches/wiring.d.ts.map +1 -1
  154. package/types/x-modules/query-suggestions/store/types.d.ts +1 -1
  155. package/types/x-modules/query-suggestions/store/types.d.ts.map +1 -1
  156. package/types/x-modules/query-suggestions/wiring.d.ts +2 -2
  157. package/types/x-modules/query-suggestions/wiring.d.ts.map +1 -1
  158. package/types/x-modules/recommendations/store/types.d.ts +1 -1
  159. package/types/x-modules/recommendations/store/types.d.ts.map +1 -1
  160. package/types/x-modules/recommendations/wiring.d.ts +2 -2
  161. package/types/x-modules/recommendations/wiring.d.ts.map +1 -1
  162. package/types/x-modules/related-tags/store/types.d.ts +1 -1
  163. package/types/x-modules/related-tags/store/types.d.ts.map +1 -1
  164. package/types/x-modules/related-tags/wiring.d.ts +2 -2
  165. package/types/x-modules/related-tags/wiring.d.ts.map +1 -1
  166. package/types/x-modules/scroll/components/scroll-to-top.vue.d.ts +1 -1
  167. package/types/x-modules/scroll/components/scroll-to-top.vue.d.ts.map +1 -1
  168. package/types/x-modules/scroll/store/types.d.ts +1 -1
  169. package/types/x-modules/scroll/store/types.d.ts.map +1 -1
  170. package/types/x-modules/search/store/types.d.ts +1 -1
  171. package/types/x-modules/search/store/types.d.ts.map +1 -1
  172. package/types/x-modules/search/wiring.d.ts +2 -2
  173. package/types/x-modules/search/wiring.d.ts.map +1 -1
  174. package/types/x-modules/url/components/url-handler.vue.d.ts +1 -1
  175. package/types/x-modules/url/components/url-handler.vue.d.ts.map +1 -1
  176. package/types/x-modules/url/events.types.d.ts +3 -2
  177. package/types/x-modules/url/events.types.d.ts.map +1 -1
  178. package/types/x-modules/url/store/types.d.ts +1 -1
  179. package/types/x-modules/url/store/types.d.ts.map +1 -1
  180. package/types/x-modules/url/wiring.d.ts +2 -2
  181. package/types/x-modules/url/wiring.d.ts.map +1 -1
  182. package/docs/API-reference/api/x-components.cleanundefined.md +0 -26
  183. package/docs/API-reference/api/x-components.dictionary.md +0 -13
  184. package/docs/API-reference/api/x-components.every.md +0 -27
  185. package/docs/API-reference/api/x-components.foreach.md +0 -25
  186. package/docs/API-reference/api/x-components.getnewandupdatedkeys.md +0 -27
  187. package/docs/API-reference/api/x-components.map.md +0 -27
  188. package/docs/API-reference/api/x-components.objectfilter.md +0 -27
  189. package/docs/API-reference/api/x-components.reduce.md +0 -28
  190. package/js/utils/object.js +0 -115
  191. package/js/utils/object.js.map +0 -1
  192. package/types/utils/object.d.ts +0 -70
  193. package/types/utils/object.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"url-handler.vue.js","sources":["../../../../../src/x-modules/url/components/url-handler.vue"],"sourcesContent":["<template>\n <GlobalEvents @pageshow=\"onPageShow\" @popstate=\"emitEvents\" target=\"window\" />\n</template>\n\n<script lang=\"ts\">\n import Vue from 'vue';\n import GlobalEvents from 'vue-global-events';\n import { Component, Inject } from 'vue-property-decorator';\n import { State } from '../../../components';\n import { XOn } from '../../../components/decorators/bus.decorators';\n import { xComponentMixin } from '../../../components/x-component.mixin';\n import { FeatureLocation } from '../../../types/origin';\n import { UrlParams } from '../../../types/url-params';\n import { isArrayEmpty } from '../../../utils/array';\n import { objectFilter } from '../../../utils/object';\n import { Dictionary } from '../../../utils/types';\n import { WireMetadata } from '../../../wiring/wiring.types';\n import { SnippetConfig } from '../../../x-installer/api/api.types';\n import { initialUrlState } from '../store/initial-state';\n import { UrlParamValue } from '../store/types';\n import { urlXModule } from '../x-module';\n\n interface ParsedUrlParams {\n all: UrlParams;\n extra: Dictionary<unknown>;\n }\n\n /**\n * This component manage the browser URL parameters to perserve them through reloads and browser\n * history navigation. It allow to configure the default url parameter names using its attributes.\n * This component doesn't render elements to the DOM.\n *\n * @public\n */\n @Component({\n components: {\n GlobalEvents\n },\n mixins: [xComponentMixin(urlXModule)]\n })\n export default class UrlHandler extends Vue {\n /**\n * The {@link SnippetConfig} provided by an ancestor.\n *\n * @internal\n */\n @Inject({ default: undefined })\n protected snippetConfig?: SnippetConfig;\n\n /**\n * Flag to know if the params were already loaded from the URL.\n *\n * @internal\n */\n protected urlLoaded = false;\n\n /**\n * The page URL. It is used to compare against the current URL to check navigation state.\n *\n * @internal\n */\n protected url?: URL;\n\n /**\n * Flag to know if the page has been persisted by the browser's back-forward cache.\n *\n * @internal\n */\n protected isPagePersisted = false;\n\n /**\n * Computed to know which params we must get from URL. It gets the params names from the initial\n * state, to get all default params names, and also from the `$attrs` to get the extra params\n * names to take into account.\n *\n * @returns An array with the name of the params.\n *\n * @internal\n */\n protected get managedParamsNames(): string[] {\n return Object.keys({ ...initialUrlState, ...this.$attrs });\n }\n\n @State('url', 'initialExtraParams')\n public initialExtraParams!: Dictionary<unknown>;\n\n /**\n * Returns the mapping of the param keys used in the URL is configured through $attrs. This way\n * we can support any param and extra param, no matters its name.\n *\n * @param paramName - The param name to get the Url key.\n * @returns The key used in the URL for the `paramName` passed.\n *\n * @internal\n */\n protected getUrlKey(paramName: string): string {\n return this.$attrs[paramName] ?? paramName;\n }\n\n /**\n * To emit the Url events just when the URL is load, and before the components mounted events\n * and state changes, we do it in the created of this component.\n */\n created(): void {\n this.emitEvents();\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `pushState` method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('PushableUrlStateChanged')\n updateUrlWithPush(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.pushState.bind(window.history));\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `replaceState`\n * method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('ReplaceableUrlStateChanged')\n updateUrlWithReplace(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.replaceState.bind(window.history));\n }\n\n /**\n * Handler of the\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event | pageshow }\n * event.\n *\n * @remarks The pageshow event is listened to check if the browser has performed a navigation\n * using the back-forward cache. This information is available in the\n * PageTransitionEvent.persisted property.\n *\n * @param event - The page transition event.\n * @internal\n */\n protected onPageShow(event: PageTransitionEvent): void {\n this.isPagePersisted = event.persisted;\n if (event.persisted) {\n // The internal url is reset due to the back-forward cache storing the previous value which\n // is no longer valid.\n this.url = undefined;\n }\n }\n\n /**\n * Emits the {@link UrlXEvents.ParamsLoadedFromUrl} XEvent,\n * the {@link UrlXEvents.ExtraParamsLoadedFromUrl} XEvent and, if there is query, also emits\n * the {@link XEventsTypes.UserOpenXProgrammatically}.\n *\n * @internal\n */\n protected emitEvents(): void {\n const { all, extra } = this.parseUrlParams();\n const metadata = this.createWireMetadata();\n this.$x.emit('ParamsLoadedFromUrl', all, metadata);\n this.$x.emit('ExtraParamsLoadedFromUrl', extra, metadata);\n // TODO: Move this logic from here.\n if (all.query) {\n this.$x.emit('UserOpenXProgrammatically', undefined, metadata);\n }\n this.urlLoaded = true;\n }\n\n /**\n * Creates the wire metadata to include in every emitted {@link XEvent | XEvents}.\n *\n * @returns The {@link WireMetadata | metadata}.\n * @internal\n */\n protected createWireMetadata(): Pick<WireMetadata, 'feature' | 'location'> {\n return {\n feature: 'url',\n location: this.detectLocation()\n };\n }\n\n /**\n * Detects the {@link FeatureLocation | location} used to build the\n * {@link QueryOriginInit | events metadata origin}.\n *\n * @returns The {@link FeatureLocation | location}.\n * @internal\n */\n protected detectLocation(): FeatureLocation {\n const currentUrl = new URL(window.location.href);\n const previousUrl = this.url;\n this.url = currentUrl;\n\n const isInternalNavigation =\n previousUrl?.search !== currentUrl.search && previousUrl?.pathname === currentUrl.pathname;\n if (isInternalNavigation) {\n return 'url_history';\n }\n\n if (this.isNavigatingFromPdp()) {\n return 'url_history_pdp';\n }\n\n return 'external';\n }\n\n /**\n * Check if the navigation is from a product page.\n *\n * @remarks Due to Safari 14 not supporting the new and standard PerformanceNavigationTiming\n * API, we are falling back to the deprecated one, PerformanceNavigation. We also fallback to\n * this API whenever we get a navigationType equal to reload, because Safari has a bug that the\n * navigationType is permanently set to reload after you have reload the page and it never\n * resets. As some browsers have a back-forward cache implemented, we also take into account if\n * the page is persisted.\n *\n * @returns True if the navigation is from a product page, false otherwise.\n * @internal\n */\n protected isNavigatingFromPdp(): boolean {\n const isPagePersisted = this.isPagePersisted;\n const navigationEntries = window.performance.getEntriesByType('navigation');\n const navigationType = (navigationEntries[0] as PerformanceNavigationTiming)?.type;\n const useFallbackStrategy =\n window.performance.navigation &&\n (isArrayEmpty(navigationEntries) || navigationType === 'reload');\n\n // Reset internal isPagePersisted property value\n this.isPagePersisted = false;\n\n if (useFallbackStrategy) {\n const {\n type: fallbackNavigationType,\n TYPE_BACK_FORWARD,\n TYPE_NAVIGATE\n } = window.performance.navigation;\n const isNavigatingInSpa =\n !!this.snippetConfig?.isSpa && fallbackNavigationType === TYPE_NAVIGATE;\n return fallbackNavigationType === TYPE_BACK_FORWARD || isNavigatingInSpa || isPagePersisted;\n } else {\n const isNavigatingInSpa = !!this.snippetConfig?.isSpa && navigationType === 'navigate';\n return navigationType === 'back_forward' || isNavigatingInSpa || isPagePersisted;\n }\n }\n\n /**\n * Gets the {@link UrlParams} from the URL, including only the params defined by `paramsNames`.\n *\n * @returns ParsedUrlParams obtained from URL.\n * @internal\n */\n protected parseUrlParams(): ParsedUrlParams {\n const urlSearchParams = new URL(window.location.href).searchParams;\n return this.managedParamsNames.reduce<ParsedUrlParams>(\n (params, name) => {\n const urlKey = this.getUrlKey(name);\n if (urlSearchParams.has(urlKey)) {\n if (name in initialUrlState) {\n const urlValue = urlSearchParams.getAll(urlKey);\n params.all[name] = this.parseUrlParam(name, urlValue);\n } else {\n params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);\n }\n }\n return params;\n },\n { all: { ...initialUrlState }, extra: { ...this.initialExtraParams } }\n );\n }\n\n /**\n * Updates the browser URL with the passed `newUrlParams` and using the browser history method\n * passed as `historyMethod`. It only updates the browser history if the new URL is different\n * from the current.\n *\n * @param newUrlParams - The new params to add to the browser URL.\n * @param historyMethod - The browser history method used to add the new URL.\n *\n * @internal\n */\n protected updateUrl(\n newUrlParams: UrlParams,\n historyMethod: History['pushState'] | History['replaceState']\n ): void {\n if (this.urlLoaded) {\n const url = new URL(window.location.href);\n this.deleteUrlParameters(url);\n this.setUrlParameters(url, newUrlParams);\n if (url.href.replace(/\\+/g, '%20') !== window.location.href) {\n historyMethod({ ...window.history.state }, document.title, url.href);\n }\n this.url = url;\n }\n }\n\n /**\n * Deletes all the parameters in the passed URL.\n *\n * @param url - The URL to remove parameters from.\n * @internal\n * **/\n protected deleteUrlParameters(url: URL): void {\n this.managedParamsNames.forEach(paramName =>\n url.searchParams.delete(this.getUrlKey(paramName))\n );\n }\n\n /**\n * Set all the provided parameters to the url with the mapped key.\n *\n * @param url - The current URL.\n * @param urlParams - The list of parameters to add.\n * @remarks The params are filtered because there maybe received extra params which will not be\n * managed by URL. This is defined by the `managedParamsNames` computed. Also, the parameters\n * are sorted Alphabetically to produce always the same URL with the same parameters.This is\n * important for SEO purposes.\n *\n * @internal\n * **/\n protected setUrlParameters(url: URL, urlParams: UrlParams): void {\n const filteredParams = objectFilter(urlParams, paramName =>\n this.managedParamsNames.includes(paramName as string)\n );\n const sortedParameters = this.sortParams(filteredParams);\n sortedParameters.forEach(([paramName, paramValue]) => {\n const urlParamKey = this.getUrlKey(paramName);\n if (Array.isArray(paramValue)) {\n paramValue.forEach(value => {\n url.searchParams.append(urlParamKey, String(value));\n });\n } else {\n url.searchParams.set(urlParamKey, String(paramValue));\n }\n });\n }\n\n /**\n * Sorts the params in a tuple array [key,value] to generate always the same URL with the params\n * in the same order.\n *\n * @param urlParams - The {@link UrlParams} to sort.\n * @returns An array of tuples with the key-value of each paramter, sorted by key.\n * @internal\n */\n protected sortParams(urlParams: UrlParams): Array<[string, unknown]> {\n return Object.entries(urlParams).sort(([param1], [param2]) => {\n return param1 < param2 ? -1 : 1;\n });\n }\n\n /**\n * Returns the URL param value parsed depending on its type in the initial store state. As we\n * can not know what type can have an extra param, all extra params are parsed as strings. We\n * know if it is an extra param because it is not in the initial state.\n *\n * @param name - The name of the param in {@link UrlParams}.\n * @param value - The `URLSearchParams` value as an arry of strings.\n * @returns The parsed value.\n *\n * @internal\n */\n protected parseUrlParam(name: string, value: string[]): UrlParamValue {\n switch (typeof initialUrlState[name]) {\n case 'number':\n return Number(value[0]);\n case 'boolean':\n return value[0].toLowerCase() === 'true';\n case 'string':\n return value[0];\n default:\n // array\n return value;\n }\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the following events:\n\n- [`ParamsLoadedFromUrl`](./../../api/x-components.urlxevents.paramsloadedfromurl.md)\n- [`ExtraParamsLoadedFromUrl`](./../../api/x-components.urlxevents.extraparamsloadedfromurl.md)\n- [`UserOpenXProgrammatically`](./../../api/x-components.xeventstypes.useropenxprogrammatically.md)\n\n## See it in action\n\nThis component manages the browser URL parameters to preserve them through reloads and browser\nhistory navigation. It allow to configure the default url parameter names using its attributes. This\ncomponent doesn't render elements to the DOM.\n\n_Try to make some requests and take a look to the url!_\n\n```vue\n<template>\n <UrlHandler />\n</template>\n\n<script>\n import { UrlHandler } from '@empathyco/x-components/url-handler';\n\n export default {\n name: 'UrlHandlerDemo',\n components: {\n UrlHandler\n }\n };\n</script>\n```\n\n### Play with props\n\nIn this example, the `UrlHandler` component changes the following query parameter names:\n\n- `query` to be `q`.\n- `page` to be `p`.\n- `filter` to be `f`\n- `sort` to be `s`\n\n_Try to make some requests and take a look to the url!_\n\n```vue\n<template>\n <UrlHandler query=\"q\" page=\"p\" filter=\"f\" sort=\"s\" />\n</template>\n\n<script>\n import { UrlHandler } from '@empathyco/x-components/url-handler';\n\n export default {\n name: 'UrlHandlerDemo',\n components: {\n UrlHandler\n }\n };\n</script>\n```\n\n### Play with events\n\nThe `UrlHandler` will emit the `ParamsLoadedFromUrl` when the page is loaded.\n\nThe `UrlHandler` will emit the `ExtraParamsLoadedFromUrl` when the page is loaded with an extra\nparam configured and with a value in URL.\n\nThe `UrlHandler` will emit the `UserOpenXProgrammatically` when the page is loaded with a query in\nthe URL.\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"url-handler.vue.js","sources":["../../../../../src/x-modules/url/components/url-handler.vue"],"sourcesContent":["<template>\n <GlobalEvents @pageshow=\"onPageShow\" @popstate=\"emitEvents\" target=\"window\" />\n</template>\n\n<script lang=\"ts\">\n import { Dictionary, objectFilter } from '@empathyco/x-utils';\n import Vue from 'vue';\n import GlobalEvents from 'vue-global-events';\n import { Component, Inject } from 'vue-property-decorator';\n import { State } from '../../../components';\n import { XOn } from '../../../components/decorators/bus.decorators';\n import { xComponentMixin } from '../../../components/x-component.mixin';\n import { FeatureLocation } from '../../../types/origin';\n import { UrlParams } from '../../../types/url-params';\n import { isArrayEmpty } from '../../../utils/array';\n import { WireMetadata } from '../../../wiring/wiring.types';\n import { SnippetConfig } from '../../../x-installer/api/api.types';\n import { initialUrlState } from '../store/initial-state';\n import { UrlParamValue } from '../store/types';\n import { urlXModule } from '../x-module';\n\n interface ParsedUrlParams {\n all: UrlParams;\n extra: Dictionary<unknown>;\n }\n\n /**\n * This component manage the browser URL parameters to perserve them through reloads and browser\n * history navigation. It allow to configure the default url parameter names using its attributes.\n * This component doesn't render elements to the DOM.\n *\n * @public\n */\n @Component({\n components: {\n GlobalEvents\n },\n mixins: [xComponentMixin(urlXModule)]\n })\n export default class UrlHandler extends Vue {\n /**\n * The {@link SnippetConfig} provided by an ancestor.\n *\n * @internal\n */\n @Inject({ default: undefined })\n protected snippetConfig?: SnippetConfig;\n\n /**\n * Flag to know if the params were already loaded from the URL.\n *\n * @internal\n */\n protected urlLoaded = false;\n\n /**\n * The page URL. It is used to compare against the current URL to check navigation state.\n *\n * @internal\n */\n protected url?: URL;\n\n /**\n * Flag to know if the page has been persisted by the browser's back-forward cache.\n *\n * @internal\n */\n protected isPagePersisted = false;\n\n /**\n * Computed to know which params we must get from URL. It gets the params names from the initial\n * state, to get all default params names, and also from the `$attrs` to get the extra params\n * names to take into account.\n *\n * @returns An array with the name of the params.\n *\n * @internal\n */\n protected get managedParamsNames(): string[] {\n return Object.keys({ ...initialUrlState, ...this.$attrs });\n }\n\n @State('url', 'initialExtraParams')\n public initialExtraParams!: Dictionary<unknown>;\n\n /**\n * Returns the mapping of the param keys used in the URL is configured through $attrs. This way\n * we can support any param and extra param, no matters its name.\n *\n * @param paramName - The param name to get the Url key.\n * @returns The key used in the URL for the `paramName` passed.\n *\n * @internal\n */\n protected getUrlKey(paramName: string): string {\n return this.$attrs[paramName] ?? paramName;\n }\n\n /**\n * To emit the Url events just when the URL is load, and before the components mounted events\n * and state changes, we do it in the created of this component.\n */\n created(): void {\n this.emitEvents();\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `pushState` method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('PushableUrlStateChanged')\n updateUrlWithPush(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.pushState.bind(window.history));\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `replaceState`\n * method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('ReplaceableUrlStateChanged')\n updateUrlWithReplace(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.replaceState.bind(window.history));\n }\n\n /**\n * Handler of the\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event | pageshow }\n * event.\n *\n * @remarks The pageshow event is listened to check if the browser has performed a navigation\n * using the back-forward cache. This information is available in the\n * PageTransitionEvent.persisted property.\n *\n * @param event - The page transition event.\n * @internal\n */\n protected onPageShow(event: PageTransitionEvent): void {\n this.isPagePersisted = event.persisted;\n if (event.persisted) {\n // The internal url is reset due to the back-forward cache storing the previous value which\n // is no longer valid.\n this.url = undefined;\n }\n }\n\n /**\n * Emits the {@link UrlXEvents.ParamsLoadedFromUrl} XEvent,\n * the {@link UrlXEvents.ExtraParamsLoadedFromUrl} XEvent and, if there is query, also emits\n * the {@link XEventsTypes.UserOpenXProgrammatically}.\n *\n * @internal\n */\n protected emitEvents(): void {\n const { all, extra } = this.parseUrlParams();\n const metadata = this.createWireMetadata();\n this.$x.emit('ParamsLoadedFromUrl', all, metadata);\n this.$x.emit('ExtraParamsLoadedFromUrl', extra, metadata);\n // TODO: Move this logic from here.\n if (all.query) {\n this.$x.emit('UserOpenXProgrammatically', undefined, metadata);\n }\n this.urlLoaded = true;\n }\n\n /**\n * Creates the wire metadata to include in every emitted {@link XEvent | XEvents}.\n *\n * @returns The {@link WireMetadata | metadata}.\n * @internal\n */\n protected createWireMetadata(): Pick<WireMetadata, 'feature' | 'location'> {\n return {\n feature: 'url',\n location: this.detectLocation()\n };\n }\n\n /**\n * Detects the {@link FeatureLocation | location} used to build the\n * {@link QueryOriginInit | events metadata origin}.\n *\n * @returns The {@link FeatureLocation | location}.\n * @internal\n */\n protected detectLocation(): FeatureLocation {\n const currentUrl = new URL(window.location.href);\n const previousUrl = this.url;\n this.url = currentUrl;\n\n const isInternalNavigation =\n previousUrl?.search !== currentUrl.search && previousUrl?.pathname === currentUrl.pathname;\n if (isInternalNavigation) {\n return 'url_history';\n }\n\n if (this.isNavigatingFromPdp()) {\n return 'url_history_pdp';\n }\n\n return 'external';\n }\n\n /**\n * Check if the navigation is from a product page.\n *\n * @remarks Due to Safari 14 not supporting the new and standard PerformanceNavigationTiming\n * API, we are falling back to the deprecated one, PerformanceNavigation. We also fallback to\n * this API whenever we get a navigationType equal to reload, because Safari has a bug that the\n * navigationType is permanently set to reload after you have reload the page and it never\n * resets. As some browsers have a back-forward cache implemented, we also take into account if\n * the page is persisted.\n *\n * @returns True if the navigation is from a product page, false otherwise.\n * @internal\n */\n protected isNavigatingFromPdp(): boolean {\n const isPagePersisted = this.isPagePersisted;\n const navigationEntries = window.performance.getEntriesByType('navigation');\n const navigationType = (navigationEntries[0] as PerformanceNavigationTiming)?.type;\n const useFallbackStrategy =\n window.performance.navigation &&\n (isArrayEmpty(navigationEntries) || navigationType === 'reload');\n\n // Reset internal isPagePersisted property value\n this.isPagePersisted = false;\n\n if (useFallbackStrategy) {\n const {\n type: fallbackNavigationType,\n TYPE_BACK_FORWARD,\n TYPE_NAVIGATE\n } = window.performance.navigation;\n const isNavigatingInSpa =\n !!this.snippetConfig?.isSpa && fallbackNavigationType === TYPE_NAVIGATE;\n return fallbackNavigationType === TYPE_BACK_FORWARD || isNavigatingInSpa || isPagePersisted;\n } else {\n const isNavigatingInSpa = !!this.snippetConfig?.isSpa && navigationType === 'navigate';\n return navigationType === 'back_forward' || isNavigatingInSpa || isPagePersisted;\n }\n }\n\n /**\n * Gets the {@link UrlParams} from the URL, including only the params defined by `paramsNames`.\n *\n * @returns ParsedUrlParams obtained from URL.\n * @internal\n */\n protected parseUrlParams(): ParsedUrlParams {\n const urlSearchParams = new URL(window.location.href).searchParams;\n return this.managedParamsNames.reduce<ParsedUrlParams>(\n (params, name) => {\n const urlKey = this.getUrlKey(name);\n if (urlSearchParams.has(urlKey)) {\n if (name in initialUrlState) {\n const urlValue = urlSearchParams.getAll(urlKey);\n params.all[name] = this.parseUrlParam(name, urlValue);\n } else {\n params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);\n }\n }\n return params;\n },\n { all: { ...initialUrlState }, extra: { ...this.initialExtraParams } }\n );\n }\n\n /**\n * Updates the browser URL with the passed `newUrlParams` and using the browser history method\n * passed as `historyMethod`. It only updates the browser history if the new URL is different\n * from the current.\n *\n * @param newUrlParams - The new params to add to the browser URL.\n * @param historyMethod - The browser history method used to add the new URL.\n *\n * @internal\n */\n protected updateUrl(\n newUrlParams: UrlParams,\n historyMethod: History['pushState'] | History['replaceState']\n ): void {\n if (this.urlLoaded) {\n const url = new URL(window.location.href);\n this.deleteUrlParameters(url);\n this.setUrlParameters(url, newUrlParams);\n if (url.href.replace(/\\+/g, '%20') !== window.location.href) {\n historyMethod({ ...window.history.state }, document.title, url.href);\n }\n this.url = url;\n }\n }\n\n /**\n * Deletes all the parameters in the passed URL.\n *\n * @param url - The URL to remove parameters from.\n * @internal\n * **/\n protected deleteUrlParameters(url: URL): void {\n this.managedParamsNames.forEach(paramName =>\n url.searchParams.delete(this.getUrlKey(paramName))\n );\n }\n\n /**\n * Set all the provided parameters to the url with the mapped key.\n *\n * @param url - The current URL.\n * @param urlParams - The list of parameters to add.\n * @remarks The params are filtered because there maybe received extra params which will not be\n * managed by URL. This is defined by the `managedParamsNames` computed. Also, the parameters\n * are sorted Alphabetically to produce always the same URL with the same parameters.This is\n * important for SEO purposes.\n *\n * @internal\n * **/\n protected setUrlParameters(url: URL, urlParams: UrlParams): void {\n const filteredParams = objectFilter(urlParams, paramName =>\n this.managedParamsNames.includes(paramName as string)\n );\n const sortedParameters = this.sortParams(filteredParams);\n sortedParameters.forEach(([paramName, paramValue]) => {\n const urlParamKey = this.getUrlKey(paramName);\n if (Array.isArray(paramValue)) {\n paramValue.forEach(value => {\n url.searchParams.append(urlParamKey, String(value));\n });\n } else {\n url.searchParams.set(urlParamKey, String(paramValue));\n }\n });\n }\n\n /**\n * Sorts the params in a tuple array [key,value] to generate always the same URL with the params\n * in the same order.\n *\n * @param urlParams - The {@link UrlParams} to sort.\n * @returns An array of tuples with the key-value of each paramter, sorted by key.\n * @internal\n */\n protected sortParams(urlParams: UrlParams): Array<[string, unknown]> {\n return Object.entries(urlParams).sort(([param1], [param2]) => {\n return param1 < param2 ? -1 : 1;\n });\n }\n\n /**\n * Returns the URL param value parsed depending on its type in the initial store state. As we\n * can not know what type can have an extra param, all extra params are parsed as strings. We\n * know if it is an extra param because it is not in the initial state.\n *\n * @param name - The name of the param in {@link UrlParams}.\n * @param value - The `URLSearchParams` value as an arry of strings.\n * @returns The parsed value.\n *\n * @internal\n */\n protected parseUrlParam(name: string, value: string[]): UrlParamValue {\n switch (typeof initialUrlState[name]) {\n case 'number':\n return Number(value[0]);\n case 'boolean':\n return value[0].toLowerCase() === 'true';\n case 'string':\n return value[0];\n default:\n // array\n return value;\n }\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits the following events:\n\n- [`ParamsLoadedFromUrl`](./../../api/x-components.urlxevents.paramsloadedfromurl.md)\n- [`ExtraParamsLoadedFromUrl`](./../../api/x-components.urlxevents.extraparamsloadedfromurl.md)\n- [`UserOpenXProgrammatically`](./../../api/x-components.xeventstypes.useropenxprogrammatically.md)\n\n## See it in action\n\nThis component manages the browser URL parameters to preserve them through reloads and browser\nhistory navigation. It allow to configure the default url parameter names using its attributes. This\ncomponent doesn't render elements to the DOM.\n\n_Try to make some requests and take a look to the url!_\n\n```vue\n<template>\n <UrlHandler />\n</template>\n\n<script>\n import { UrlHandler } from '@empathyco/x-components/url-handler';\n\n export default {\n name: 'UrlHandlerDemo',\n components: {\n UrlHandler\n }\n };\n</script>\n```\n\n### Play with props\n\nIn this example, the `UrlHandler` component changes the following query parameter names:\n\n- `query` to be `q`.\n- `page` to be `p`.\n- `filter` to be `f`\n- `sort` to be `s`\n\n_Try to make some requests and take a look to the url!_\n\n```vue\n<template>\n <UrlHandler query=\"q\" page=\"p\" filter=\"f\" sort=\"s\" />\n</template>\n\n<script>\n import { UrlHandler } from '@empathyco/x-components/url-handler';\n\n export default {\n name: 'UrlHandlerDemo',\n components: {\n UrlHandler\n }\n };\n</script>\n```\n\n### Play with events\n\nThe `UrlHandler` will emit the `ParamsLoadedFromUrl` when the page is loaded.\n\nThe `UrlHandler` will emit the `ExtraParamsLoadedFromUrl` when the page is loaded with an extra\nparam configured and with a value in URL.\n\nThe `UrlHandler` will emit the `UserOpenXProgrammatically` when the page is loaded with a query in\nthe URL.\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { __decorate } from 'tslib';
2
+ import { objectFilter } from '@empathyco/x-utils';
2
3
  import Vue from 'vue';
3
4
  import GlobalEvents from 'vue-global-events';
4
5
  import { Inject, Component } from 'vue-property-decorator';
@@ -117,7 +118,6 @@ import { isArrayEmpty } from '../../../utils/array.js';
117
118
  import { State } from '../../../components/decorators/store.decorators.js';
118
119
  import '../../../components/items-list-injection.mixin.js';
119
120
  import { xComponentMixin } from '../../../components/x-component.mixin.js';
120
- import { objectFilter } from '../../../utils/object.js';
121
121
  import { initialUrlState } from '../store/initial-state.js';
122
122
  import { urlXModule } from '../x-module.js';
123
123
 
@@ -1 +1 @@
1
- {"version":3,"file":"url-handler.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../../src/x-modules/url/components/url-handler.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\nimport Vue from 'vue';\nimport GlobalEvents from 'vue-global-events';\nimport { Component, Inject } from 'vue-property-decorator';\nimport { State } from '../../../components';\nimport { XOn } from '../../../components/decorators/bus.decorators';\nimport { xComponentMixin } from '../../../components/x-component.mixin';\nimport { FeatureLocation } from '../../../types/origin';\nimport { UrlParams } from '../../../types/url-params';\nimport { isArrayEmpty } from '../../../utils/array';\nimport { objectFilter } from '../../../utils/object';\nimport { Dictionary } from '../../../utils/types';\nimport { WireMetadata } from '../../../wiring/wiring.types';\nimport { SnippetConfig } from '../../../x-installer/api/api.types';\nimport { initialUrlState } from '../store/initial-state';\nimport { UrlParamValue } from '../store/types';\nimport { urlXModule } from '../x-module';\n\ninterface ParsedUrlParams {\n all: UrlParams;\n extra: Dictionary<unknown>;\n}\n\n/**\n * This component manage the browser URL parameters to perserve them through reloads and browser\n * history navigation. It allow to configure the default url parameter names using its attributes.\n * This component doesn't render elements to the DOM.\n *\n * @public\n */\n@Component({\n components: {\n GlobalEvents\n },\n mixins: [xComponentMixin(urlXModule)]\n})\nexport default class UrlHandler extends Vue {\n /**\n * The {@link SnippetConfig} provided by an ancestor.\n *\n * @internal\n */\n @Inject({ default: undefined })\n protected snippetConfig?: SnippetConfig;\n\n /**\n * Flag to know if the params were already loaded from the URL.\n *\n * @internal\n */\n protected urlLoaded = false;\n\n /**\n * The page URL. It is used to compare against the current URL to check navigation state.\n *\n * @internal\n */\n protected url?: URL;\n\n /**\n * Flag to know if the page has been persisted by the browser's back-forward cache.\n *\n * @internal\n */\n protected isPagePersisted = false;\n\n /**\n * Computed to know which params we must get from URL. It gets the params names from the initial\n * state, to get all default params names, and also from the `$attrs` to get the extra params\n * names to take into account.\n *\n * @returns An array with the name of the params.\n *\n * @internal\n */\n protected get managedParamsNames(): string[] {\n return Object.keys({ ...initialUrlState, ...this.$attrs });\n }\n\n @State('url', 'initialExtraParams')\n public initialExtraParams!: Dictionary<unknown>;\n\n /**\n * Returns the mapping of the param keys used in the URL is configured through $attrs. This way\n * we can support any param and extra param, no matters its name.\n *\n * @param paramName - The param name to get the Url key.\n * @returns The key used in the URL for the `paramName` passed.\n *\n * @internal\n */\n protected getUrlKey(paramName: string): string {\n return this.$attrs[paramName] ?? paramName;\n }\n\n /**\n * To emit the Url events just when the URL is load, and before the components mounted events\n * and state changes, we do it in the created of this component.\n */\n created(): void {\n this.emitEvents();\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `pushState` method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('PushableUrlStateChanged')\n updateUrlWithPush(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.pushState.bind(window.history));\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `replaceState`\n * method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('ReplaceableUrlStateChanged')\n updateUrlWithReplace(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.replaceState.bind(window.history));\n }\n\n /**\n * Handler of the\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event | pageshow }\n * event.\n *\n * @remarks The pageshow event is listened to check if the browser has performed a navigation\n * using the back-forward cache. This information is available in the\n * PageTransitionEvent.persisted property.\n *\n * @param event - The page transition event.\n * @internal\n */\n protected onPageShow(event: PageTransitionEvent): void {\n this.isPagePersisted = event.persisted;\n if (event.persisted) {\n // The internal url is reset due to the back-forward cache storing the previous value which\n // is no longer valid.\n this.url = undefined;\n }\n }\n\n /**\n * Emits the {@link UrlXEvents.ParamsLoadedFromUrl} XEvent,\n * the {@link UrlXEvents.ExtraParamsLoadedFromUrl} XEvent and, if there is query, also emits\n * the {@link XEventsTypes.UserOpenXProgrammatically}.\n *\n * @internal\n */\n protected emitEvents(): void {\n const { all, extra } = this.parseUrlParams();\n const metadata = this.createWireMetadata();\n this.$x.emit('ParamsLoadedFromUrl', all, metadata);\n this.$x.emit('ExtraParamsLoadedFromUrl', extra, metadata);\n // TODO: Move this logic from here.\n if (all.query) {\n this.$x.emit('UserOpenXProgrammatically', undefined, metadata);\n }\n this.urlLoaded = true;\n }\n\n /**\n * Creates the wire metadata to include in every emitted {@link XEvent | XEvents}.\n *\n * @returns The {@link WireMetadata | metadata}.\n * @internal\n */\n protected createWireMetadata(): Pick<WireMetadata, 'feature' | 'location'> {\n return {\n feature: 'url',\n location: this.detectLocation()\n };\n }\n\n /**\n * Detects the {@link FeatureLocation | location} used to build the\n * {@link QueryOriginInit | events metadata origin}.\n *\n * @returns The {@link FeatureLocation | location}.\n * @internal\n */\n protected detectLocation(): FeatureLocation {\n const currentUrl = new URL(window.location.href);\n const previousUrl = this.url;\n this.url = currentUrl;\n\n const isInternalNavigation =\n previousUrl?.search !== currentUrl.search && previousUrl?.pathname === currentUrl.pathname;\n if (isInternalNavigation) {\n return 'url_history';\n }\n\n if (this.isNavigatingFromPdp()) {\n return 'url_history_pdp';\n }\n\n return 'external';\n }\n\n /**\n * Check if the navigation is from a product page.\n *\n * @remarks Due to Safari 14 not supporting the new and standard PerformanceNavigationTiming\n * API, we are falling back to the deprecated one, PerformanceNavigation. We also fallback to\n * this API whenever we get a navigationType equal to reload, because Safari has a bug that the\n * navigationType is permanently set to reload after you have reload the page and it never\n * resets. As some browsers have a back-forward cache implemented, we also take into account if\n * the page is persisted.\n *\n * @returns True if the navigation is from a product page, false otherwise.\n * @internal\n */\n protected isNavigatingFromPdp(): boolean {\n const isPagePersisted = this.isPagePersisted;\n const navigationEntries = window.performance.getEntriesByType('navigation');\n const navigationType = (navigationEntries[0] as PerformanceNavigationTiming)?.type;\n const useFallbackStrategy =\n window.performance.navigation &&\n (isArrayEmpty(navigationEntries) || navigationType === 'reload');\n\n // Reset internal isPagePersisted property value\n this.isPagePersisted = false;\n\n if (useFallbackStrategy) {\n const {\n type: fallbackNavigationType,\n TYPE_BACK_FORWARD,\n TYPE_NAVIGATE\n } = window.performance.navigation;\n const isNavigatingInSpa =\n !!this.snippetConfig?.isSpa && fallbackNavigationType === TYPE_NAVIGATE;\n return fallbackNavigationType === TYPE_BACK_FORWARD || isNavigatingInSpa || isPagePersisted;\n } else {\n const isNavigatingInSpa = !!this.snippetConfig?.isSpa && navigationType === 'navigate';\n return navigationType === 'back_forward' || isNavigatingInSpa || isPagePersisted;\n }\n }\n\n /**\n * Gets the {@link UrlParams} from the URL, including only the params defined by `paramsNames`.\n *\n * @returns ParsedUrlParams obtained from URL.\n * @internal\n */\n protected parseUrlParams(): ParsedUrlParams {\n const urlSearchParams = new URL(window.location.href).searchParams;\n return this.managedParamsNames.reduce<ParsedUrlParams>(\n (params, name) => {\n const urlKey = this.getUrlKey(name);\n if (urlSearchParams.has(urlKey)) {\n if (name in initialUrlState) {\n const urlValue = urlSearchParams.getAll(urlKey);\n params.all[name] = this.parseUrlParam(name, urlValue);\n } else {\n params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);\n }\n }\n return params;\n },\n { all: { ...initialUrlState }, extra: { ...this.initialExtraParams } }\n );\n }\n\n /**\n * Updates the browser URL with the passed `newUrlParams` and using the browser history method\n * passed as `historyMethod`. It only updates the browser history if the new URL is different\n * from the current.\n *\n * @param newUrlParams - The new params to add to the browser URL.\n * @param historyMethod - The browser history method used to add the new URL.\n *\n * @internal\n */\n protected updateUrl(\n newUrlParams: UrlParams,\n historyMethod: History['pushState'] | History['replaceState']\n ): void {\n if (this.urlLoaded) {\n const url = new URL(window.location.href);\n this.deleteUrlParameters(url);\n this.setUrlParameters(url, newUrlParams);\n if (url.href.replace(/\\+/g, '%20') !== window.location.href) {\n historyMethod({ ...window.history.state }, document.title, url.href);\n }\n this.url = url;\n }\n }\n\n /**\n * Deletes all the parameters in the passed URL.\n *\n * @param url - The URL to remove parameters from.\n * @internal\n * **/\n protected deleteUrlParameters(url: URL): void {\n this.managedParamsNames.forEach(paramName =>\n url.searchParams.delete(this.getUrlKey(paramName))\n );\n }\n\n /**\n * Set all the provided parameters to the url with the mapped key.\n *\n * @param url - The current URL.\n * @param urlParams - The list of parameters to add.\n * @remarks The params are filtered because there maybe received extra params which will not be\n * managed by URL. This is defined by the `managedParamsNames` computed. Also, the parameters\n * are sorted Alphabetically to produce always the same URL with the same parameters.This is\n * important for SEO purposes.\n *\n * @internal\n * **/\n protected setUrlParameters(url: URL, urlParams: UrlParams): void {\n const filteredParams = objectFilter(urlParams, paramName =>\n this.managedParamsNames.includes(paramName as string)\n );\n const sortedParameters = this.sortParams(filteredParams);\n sortedParameters.forEach(([paramName, paramValue]) => {\n const urlParamKey = this.getUrlKey(paramName);\n if (Array.isArray(paramValue)) {\n paramValue.forEach(value => {\n url.searchParams.append(urlParamKey, String(value));\n });\n } else {\n url.searchParams.set(urlParamKey, String(paramValue));\n }\n });\n }\n\n /**\n * Sorts the params in a tuple array [key,value] to generate always the same URL with the params\n * in the same order.\n *\n * @param urlParams - The {@link UrlParams} to sort.\n * @returns An array of tuples with the key-value of each paramter, sorted by key.\n * @internal\n */\n protected sortParams(urlParams: UrlParams): Array<[string, unknown]> {\n return Object.entries(urlParams).sort(([param1], [param2]) => {\n return param1 < param2 ? -1 : 1;\n });\n }\n\n /**\n * Returns the URL param value parsed depending on its type in the initial store state. As we\n * can not know what type can have an extra param, all extra params are parsed as strings. We\n * know if it is an extra param because it is not in the initial state.\n *\n * @param name - The name of the param in {@link UrlParams}.\n * @param value - The `URLSearchParams` value as an arry of strings.\n * @returns The parsed value.\n *\n * @internal\n */\n protected parseUrlParam(name: string, value: string[]): UrlParamValue {\n switch (typeof initialUrlState[name]) {\n case 'number':\n return Number(value[0]);\n case 'boolean':\n return value[0].toLowerCase() === 'true';\n case 'string':\n return value[0];\n default:\n // array\n return value;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;;;;;;AAaA,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,GAAG;IAA3C;;;;;;;QAcY,cAAS,GAAG,KAAK,CAAC;;;;;;QAclB,oBAAe,GAAG,KAAK,CAAC;KAkTnC;;;;;;;;;;IAvSC,IAAc,kBAAkB;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,eAAe,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5D;;;;;;;;;;IAcS,SAAS,CAAC,SAAiB;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;KAC5C;;;;;IAMD,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAC;KACnB;;;;;;IAQD,iBAAiB,CAAC,YAAuB;QACvC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7E;;;;;;;IASD,oBAAoB,CAAC,YAAuB;QAC1C,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,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BACX,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;YAC3C,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB;;gBAEE,OAAO,KAAK,CAAC;SAChB;KACF;CACF,CAAA;AAvUC;IADC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;iDACS;AAqCxC;IADC,KAAK,CAAC,KAAK,EAAE,oBAAoB,CAAC;sDACa;AA6BhD;IADC,GAAG,CAAC,yBAAyB,CAAC;mDAG9B;AASD;IADC,GAAG,CAAC,4BAA4B,CAAC;sDAGjC;AAtFkB,UAAU;IAN9B,SAAS,CAAC;QACT,UAAU,EAAE;YACV,YAAY;SACb;QACD,MAAM,EAAE,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;KACtC,CAAC;GACmB,UAAU,CA8U9B;aA9UoB,UAAU;;;;"}
1
+ {"version":3,"file":"url-handler.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../../src/x-modules/url/components/url-handler.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\nimport { Dictionary, objectFilter } from '@empathyco/x-utils';\nimport Vue from 'vue';\nimport GlobalEvents from 'vue-global-events';\nimport { Component, Inject } from 'vue-property-decorator';\nimport { State } from '../../../components';\nimport { XOn } from '../../../components/decorators/bus.decorators';\nimport { xComponentMixin } from '../../../components/x-component.mixin';\nimport { FeatureLocation } from '../../../types/origin';\nimport { UrlParams } from '../../../types/url-params';\nimport { isArrayEmpty } from '../../../utils/array';\nimport { WireMetadata } from '../../../wiring/wiring.types';\nimport { SnippetConfig } from '../../../x-installer/api/api.types';\nimport { initialUrlState } from '../store/initial-state';\nimport { UrlParamValue } from '../store/types';\nimport { urlXModule } from '../x-module';\n\ninterface ParsedUrlParams {\n all: UrlParams;\n extra: Dictionary<unknown>;\n}\n\n/**\n * This component manage the browser URL parameters to perserve them through reloads and browser\n * history navigation. It allow to configure the default url parameter names using its attributes.\n * This component doesn't render elements to the DOM.\n *\n * @public\n */\n@Component({\n components: {\n GlobalEvents\n },\n mixins: [xComponentMixin(urlXModule)]\n})\nexport default class UrlHandler extends Vue {\n /**\n * The {@link SnippetConfig} provided by an ancestor.\n *\n * @internal\n */\n @Inject({ default: undefined })\n protected snippetConfig?: SnippetConfig;\n\n /**\n * Flag to know if the params were already loaded from the URL.\n *\n * @internal\n */\n protected urlLoaded = false;\n\n /**\n * The page URL. It is used to compare against the current URL to check navigation state.\n *\n * @internal\n */\n protected url?: URL;\n\n /**\n * Flag to know if the page has been persisted by the browser's back-forward cache.\n *\n * @internal\n */\n protected isPagePersisted = false;\n\n /**\n * Computed to know which params we must get from URL. It gets the params names from the initial\n * state, to get all default params names, and also from the `$attrs` to get the extra params\n * names to take into account.\n *\n * @returns An array with the name of the params.\n *\n * @internal\n */\n protected get managedParamsNames(): string[] {\n return Object.keys({ ...initialUrlState, ...this.$attrs });\n }\n\n @State('url', 'initialExtraParams')\n public initialExtraParams!: Dictionary<unknown>;\n\n /**\n * Returns the mapping of the param keys used in the URL is configured through $attrs. This way\n * we can support any param and extra param, no matters its name.\n *\n * @param paramName - The param name to get the Url key.\n * @returns The key used in the URL for the `paramName` passed.\n *\n * @internal\n */\n protected getUrlKey(paramName: string): string {\n return this.$attrs[paramName] ?? paramName;\n }\n\n /**\n * To emit the Url events just when the URL is load, and before the components mounted events\n * and state changes, we do it in the created of this component.\n */\n created(): void {\n this.emitEvents();\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `pushState` method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('PushableUrlStateChanged')\n updateUrlWithPush(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.pushState.bind(window.history));\n }\n\n /**\n * Updates the browser URL with the new {@link UrlParams} using the history `replaceState`\n * method.\n *\n * @param newUrlParams - The new params to update browser URL.\n */\n @XOn('ReplaceableUrlStateChanged')\n updateUrlWithReplace(newUrlParams: UrlParams): void {\n this.updateUrl(newUrlParams, window.history.replaceState.bind(window.history));\n }\n\n /**\n * Handler of the\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event | pageshow }\n * event.\n *\n * @remarks The pageshow event is listened to check if the browser has performed a navigation\n * using the back-forward cache. This information is available in the\n * PageTransitionEvent.persisted property.\n *\n * @param event - The page transition event.\n * @internal\n */\n protected onPageShow(event: PageTransitionEvent): void {\n this.isPagePersisted = event.persisted;\n if (event.persisted) {\n // The internal url is reset due to the back-forward cache storing the previous value which\n // is no longer valid.\n this.url = undefined;\n }\n }\n\n /**\n * Emits the {@link UrlXEvents.ParamsLoadedFromUrl} XEvent,\n * the {@link UrlXEvents.ExtraParamsLoadedFromUrl} XEvent and, if there is query, also emits\n * the {@link XEventsTypes.UserOpenXProgrammatically}.\n *\n * @internal\n */\n protected emitEvents(): void {\n const { all, extra } = this.parseUrlParams();\n const metadata = this.createWireMetadata();\n this.$x.emit('ParamsLoadedFromUrl', all, metadata);\n this.$x.emit('ExtraParamsLoadedFromUrl', extra, metadata);\n // TODO: Move this logic from here.\n if (all.query) {\n this.$x.emit('UserOpenXProgrammatically', undefined, metadata);\n }\n this.urlLoaded = true;\n }\n\n /**\n * Creates the wire metadata to include in every emitted {@link XEvent | XEvents}.\n *\n * @returns The {@link WireMetadata | metadata}.\n * @internal\n */\n protected createWireMetadata(): Pick<WireMetadata, 'feature' | 'location'> {\n return {\n feature: 'url',\n location: this.detectLocation()\n };\n }\n\n /**\n * Detects the {@link FeatureLocation | location} used to build the\n * {@link QueryOriginInit | events metadata origin}.\n *\n * @returns The {@link FeatureLocation | location}.\n * @internal\n */\n protected detectLocation(): FeatureLocation {\n const currentUrl = new URL(window.location.href);\n const previousUrl = this.url;\n this.url = currentUrl;\n\n const isInternalNavigation =\n previousUrl?.search !== currentUrl.search && previousUrl?.pathname === currentUrl.pathname;\n if (isInternalNavigation) {\n return 'url_history';\n }\n\n if (this.isNavigatingFromPdp()) {\n return 'url_history_pdp';\n }\n\n return 'external';\n }\n\n /**\n * Check if the navigation is from a product page.\n *\n * @remarks Due to Safari 14 not supporting the new and standard PerformanceNavigationTiming\n * API, we are falling back to the deprecated one, PerformanceNavigation. We also fallback to\n * this API whenever we get a navigationType equal to reload, because Safari has a bug that the\n * navigationType is permanently set to reload after you have reload the page and it never\n * resets. As some browsers have a back-forward cache implemented, we also take into account if\n * the page is persisted.\n *\n * @returns True if the navigation is from a product page, false otherwise.\n * @internal\n */\n protected isNavigatingFromPdp(): boolean {\n const isPagePersisted = this.isPagePersisted;\n const navigationEntries = window.performance.getEntriesByType('navigation');\n const navigationType = (navigationEntries[0] as PerformanceNavigationTiming)?.type;\n const useFallbackStrategy =\n window.performance.navigation &&\n (isArrayEmpty(navigationEntries) || navigationType === 'reload');\n\n // Reset internal isPagePersisted property value\n this.isPagePersisted = false;\n\n if (useFallbackStrategy) {\n const {\n type: fallbackNavigationType,\n TYPE_BACK_FORWARD,\n TYPE_NAVIGATE\n } = window.performance.navigation;\n const isNavigatingInSpa =\n !!this.snippetConfig?.isSpa && fallbackNavigationType === TYPE_NAVIGATE;\n return fallbackNavigationType === TYPE_BACK_FORWARD || isNavigatingInSpa || isPagePersisted;\n } else {\n const isNavigatingInSpa = !!this.snippetConfig?.isSpa && navigationType === 'navigate';\n return navigationType === 'back_forward' || isNavigatingInSpa || isPagePersisted;\n }\n }\n\n /**\n * Gets the {@link UrlParams} from the URL, including only the params defined by `paramsNames`.\n *\n * @returns ParsedUrlParams obtained from URL.\n * @internal\n */\n protected parseUrlParams(): ParsedUrlParams {\n const urlSearchParams = new URL(window.location.href).searchParams;\n return this.managedParamsNames.reduce<ParsedUrlParams>(\n (params, name) => {\n const urlKey = this.getUrlKey(name);\n if (urlSearchParams.has(urlKey)) {\n if (name in initialUrlState) {\n const urlValue = urlSearchParams.getAll(urlKey);\n params.all[name] = this.parseUrlParam(name, urlValue);\n } else {\n params.all[name] = params.extra[name] = urlSearchParams.get(urlKey);\n }\n }\n return params;\n },\n { all: { ...initialUrlState }, extra: { ...this.initialExtraParams } }\n );\n }\n\n /**\n * Updates the browser URL with the passed `newUrlParams` and using the browser history method\n * passed as `historyMethod`. It only updates the browser history if the new URL is different\n * from the current.\n *\n * @param newUrlParams - The new params to add to the browser URL.\n * @param historyMethod - The browser history method used to add the new URL.\n *\n * @internal\n */\n protected updateUrl(\n newUrlParams: UrlParams,\n historyMethod: History['pushState'] | History['replaceState']\n ): void {\n if (this.urlLoaded) {\n const url = new URL(window.location.href);\n this.deleteUrlParameters(url);\n this.setUrlParameters(url, newUrlParams);\n if (url.href.replace(/\\+/g, '%20') !== window.location.href) {\n historyMethod({ ...window.history.state }, document.title, url.href);\n }\n this.url = url;\n }\n }\n\n /**\n * Deletes all the parameters in the passed URL.\n *\n * @param url - The URL to remove parameters from.\n * @internal\n * **/\n protected deleteUrlParameters(url: URL): void {\n this.managedParamsNames.forEach(paramName =>\n url.searchParams.delete(this.getUrlKey(paramName))\n );\n }\n\n /**\n * Set all the provided parameters to the url with the mapped key.\n *\n * @param url - The current URL.\n * @param urlParams - The list of parameters to add.\n * @remarks The params are filtered because there maybe received extra params which will not be\n * managed by URL. This is defined by the `managedParamsNames` computed. Also, the parameters\n * are sorted Alphabetically to produce always the same URL with the same parameters.This is\n * important for SEO purposes.\n *\n * @internal\n * **/\n protected setUrlParameters(url: URL, urlParams: UrlParams): void {\n const filteredParams = objectFilter(urlParams, paramName =>\n this.managedParamsNames.includes(paramName as string)\n );\n const sortedParameters = this.sortParams(filteredParams);\n sortedParameters.forEach(([paramName, paramValue]) => {\n const urlParamKey = this.getUrlKey(paramName);\n if (Array.isArray(paramValue)) {\n paramValue.forEach(value => {\n url.searchParams.append(urlParamKey, String(value));\n });\n } else {\n url.searchParams.set(urlParamKey, String(paramValue));\n }\n });\n }\n\n /**\n * Sorts the params in a tuple array [key,value] to generate always the same URL with the params\n * in the same order.\n *\n * @param urlParams - The {@link UrlParams} to sort.\n * @returns An array of tuples with the key-value of each paramter, sorted by key.\n * @internal\n */\n protected sortParams(urlParams: UrlParams): Array<[string, unknown]> {\n return Object.entries(urlParams).sort(([param1], [param2]) => {\n return param1 < param2 ? -1 : 1;\n });\n }\n\n /**\n * Returns the URL param value parsed depending on its type in the initial store state. As we\n * can not know what type can have an extra param, all extra params are parsed as strings. We\n * know if it is an extra param because it is not in the initial state.\n *\n * @param name - The name of the param in {@link UrlParams}.\n * @param value - The `URLSearchParams` value as an arry of strings.\n * @returns The parsed value.\n *\n * @internal\n */\n protected parseUrlParam(name: string, value: string[]): UrlParamValue {\n switch (typeof initialUrlState[name]) {\n case 'number':\n return Number(value[0]);\n case 'boolean':\n return value[0].toLowerCase() === 'true';\n case 'string':\n return value[0];\n default:\n // array\n return value;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;;;;AAaA,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,GAAG;IAA3C;;;;;;;QAcY,cAAS,GAAG,KAAK,CAAC;;;;;;QAclB,oBAAe,GAAG,KAAK,CAAC;KAkTnC;;;;;;;;;;IAvSC,IAAc,kBAAkB;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,eAAe,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5D;;;;;;;;;;IAcS,SAAS,CAAC,SAAiB;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;KAC5C;;;;;IAMD,OAAO;QACL,IAAI,CAAC,UAAU,EAAE,CAAC;KACnB;;;;;;IAQD,iBAAiB,CAAC,YAAuB;QACvC,IAAI,CAAC,SA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AAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC;YACvD,OAAO,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;SACjC,CAAC,CAAC;KACJ;;;;;;;;;;;;IAaS,aAAa,CAAC,IAAY,EAAE,KAAe;QACnD,QAAQ,OAAO,eAAe,CAAC,IAAI,CAAC;YAClC,KAAK,QAAQ;gBACX,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;YAC3C,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB;;gBAEE,OAAO,KAAK,CAAC;SAChB;KACF;CACF,CAAA;AAvUC;IADC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;iDACS;AAqCxC;IADC,KAAK,CAAC,KAAK,EAAE,oBAAoB,CAAC;sDACa;AA6BhD;IADC,GAAG,CAAC,yBAAyB,CAAC;mDAG9B;AASD;IADC,GAAG,CAAC,4BAA4B,CAAC;sDAGjC;AAtFkB,UAAU;IAN9B,SAAS,CAAC;QACT,UAAU,EAAE;YACV,YAAY;SACb;QACD,MAAM,EAAE,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;KACtC,CAAC;GACmB,UAAU,CA8U9B;aA9UoB,UAAU;;;;"}
@@ -1,4 +1,4 @@
1
- import { objectFilter } from '../../../../utils/object.js';
1
+ import { objectFilter } from '@empathyco/x-utils';
2
2
  import { initialUrlState } from '../initial-state.js';
3
3
 
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"url-params.getter.js","sources":["../../../../../../src/x-modules/url/store/getters/url-params.getter.ts"],"sourcesContent":["import { objectFilter } from '../../../../utils/object';\nimport { initialUrlState } from '../initial-state';\nimport { UrlParamValue, UrlXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link UrlGetters.urlParams} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the url module.\n *\n * @returns The url params.\n *\n * @public\n */\nexport const urlParams: UrlXStoreModule['getters']['urlParams'] = ({\n initialExtraParams,\n ...params\n}) =>\n objectFilter(params, (paramKey, paramValue) => {\n return paramKey in initialUrlState\n ? isNotDefaultValue(paramKey, paramValue, initialUrlState)\n : isNotEmptyParam(paramValue) && isNotDefaultValue(paramKey, paramValue, initialExtraParams);\n });\n\n/**\n * Checks if a parameter is not empty to avoid adding it to the URL.\n *\n * @param value - The value of the key parameter.\n *\n * @returns True if is not empty, False otherwise.\n */\nfunction isNotEmptyParam(value: UrlParamValue | unknown): boolean {\n return Array.isArray(value) ? value.length > 0 : value != null && value !== '';\n}\n\n/**\n * Checks if a parameter is not the default state value to avoid adding it to the URL.\n *\n * @param key - The key parameter.\n * @param value - The value of the key parameter.\n * @param defaultValues - The default values to compare.\n *\n * @returns True if is not the default state value, False otherwise.\n */\nfunction isNotDefaultValue<Key extends string | number, Value extends UrlParamValue | unknown>(\n key: Key,\n value: Value,\n defaultValues: Record<Key, Value>\n): boolean {\n return Array.isArray(value) ? value.length > 0 : defaultValues[key] !== value;\n}\n"],"names":[],"mappings":";;;AAIA;;;;;;;;;MASa,SAAS,GAA4C,CAAC,EACjE,kBAAkB,EAClB,GAAG,MAAM,EACV,KACC,YAAY,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,UAAU;IACxC,OAAO,QAAQ,IAAI,eAAe;UAC9B,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,eAAe,CAAC;UACxD,eAAe,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;AACjG,CAAC,EAAE;AAEL;;;;;;;AAOA,SAAS,eAAe,CAAC,KAA8B;IACrD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;AACjF,CAAC;AAED;;;;;;;;;AASA,SAAS,iBAAiB,CACxB,GAAQ,EACR,KAAY,EACZ,aAAiC;IAEjC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;AAChF;;;;"}
1
+ {"version":3,"file":"url-params.getter.js","sources":["../../../../../../src/x-modules/url/store/getters/url-params.getter.ts"],"sourcesContent":["import { objectFilter } from '@empathyco/x-utils';\nimport { initialUrlState } from '../initial-state';\nimport { UrlParamValue, UrlXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link UrlGetters.urlParams} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the url module.\n *\n * @returns The url params.\n *\n * @public\n */\nexport const urlParams: UrlXStoreModule['getters']['urlParams'] = ({\n initialExtraParams,\n ...params\n}) =>\n objectFilter(params, (paramKey, paramValue) => {\n return paramKey in initialUrlState\n ? isNotDefaultValue(paramKey, paramValue, initialUrlState)\n : isNotEmptyParam(paramValue) && isNotDefaultValue(paramKey, paramValue, initialExtraParams);\n });\n\n/**\n * Checks if a parameter is not empty to avoid adding it to the URL.\n *\n * @param value - The value of the key parameter.\n *\n * @returns True if is not empty, False otherwise.\n */\nfunction isNotEmptyParam(value: UrlParamValue | unknown): boolean {\n return Array.isArray(value) ? value.length > 0 : value != null && value !== '';\n}\n\n/**\n * Checks if a parameter is not the default state value to avoid adding it to the URL.\n *\n * @param key - The key parameter.\n * @param value - The value of the key parameter.\n * @param defaultValues - The default values to compare.\n *\n * @returns True if is not the default state value, False otherwise.\n */\nfunction isNotDefaultValue<Key extends string | number, Value extends UrlParamValue | unknown>(\n key: Key,\n value: Value,\n defaultValues: Record<Key, Value>\n): boolean {\n return Array.isArray(value) ? value.length > 0 : defaultValues[key] !== value;\n}\n"],"names":[],"mappings":";;;AAIA;;;;;;;;;MASa,SAAS,GAA4C,CAAC,EACjE,kBAAkB,EAClB,GAAG,MAAM,EACV,KACC,YAAY,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,UAAU;IACxC,OAAO,QAAQ,IAAI,eAAe;UAC9B,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,eAAe,CAAC;UACxD,eAAe,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;AACjG,CAAC,EAAE;AAEL;;;;;;;AAOA,SAAS,eAAe,CAAC,KAA8B;IACrD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;AACjF,CAAC;AAED;;;;;;;;;AASA,SAAS,iBAAiB,CACxB,GAAQ,EACR,KAAY,EACZ,aAAiC;IAEjC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;AAChF;;;;"}
@@ -1,5 +1,5 @@
1
+ import { forEach } from '@empathyco/x-utils';
1
2
  import Vue from 'vue';
2
- import { forEach } from '../../../../utils/object.js';
3
3
 
4
4
  /**
5
5
  * Default implementation for the {@link UrlMutations.setParams} mutation.
@@ -1 +1 @@
1
- {"version":3,"file":"set-params.mutation.js","sources":["../../../../../../src/x-modules/url/store/mutations/set-params.mutation.ts"],"sourcesContent":["import Vue from 'vue';\nimport { forEach } from '../../../../utils/object';\nimport { UrlXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link UrlMutations.setParams} mutation.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the history\n * queries module.\n * @param params - The mutation payload with the extra params to set in the state.\n * @remarks The change is done using `Vue.set` because we are adding new fields to the state. So\n * this is necessary to make them reactive.\n * @public\n */\nexport const setParams: UrlXStoreModule['mutations']['setParams'] = (state, params) => {\n forEach(params, (key, value) => {\n Vue.set(state, key, value);\n });\n};\n"],"names":[],"mappings":";;;AAIA;;;;;;;;;;MAUa,SAAS,GAA8C,CAAC,KAAK,EAAE,MAAM;IAChF,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK;QACzB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;KAC5B,CAAC,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"set-params.mutation.js","sources":["../../../../../../src/x-modules/url/store/mutations/set-params.mutation.ts"],"sourcesContent":["import { forEach } from '@empathyco/x-utils';\nimport Vue from 'vue';\nimport { UrlXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link UrlMutations.setParams} mutation.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the history\n * queries module.\n * @param params - The mutation payload with the extra params to set in the state.\n * @remarks The change is done using `Vue.set` because we are adding new fields to the state. So\n * this is necessary to make them reactive.\n * @public\n */\nexport const setParams: UrlXStoreModule['mutations']['setParams'] = (state, params) => {\n forEach(params, (key, value) => {\n Vue.set(state, key, value);\n });\n};\n"],"names":[],"mappings":";;;AAIA;;;;;;;;;;MAUa,SAAS,GAA8C,CAAC,KAAK,EAAE,MAAM;IAChF,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK;QACzB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;KAC5B,CAAC,CAAC;AACL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-components",
3
- "version": "3.0.0-alpha.76",
3
+ "version": "3.0.0-alpha.79",
4
4
  "description": "Empathy X Components",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -59,12 +59,12 @@
59
59
  "cypress:open:component": "cypress open-ct"
60
60
  },
61
61
  "dependencies": {
62
- "@empathyco/x-adapter": "^7.0.0-alpha.17",
63
- "@empathyco/x-deep-merge": "^1.3.0-alpha.5",
62
+ "@empathyco/x-adapter": "^7.0.0-alpha.19",
63
+ "@empathyco/x-deep-merge": "^1.3.0-alpha.7",
64
64
  "@empathyco/x-logger": "^1.2.0-alpha.3",
65
65
  "@empathyco/x-storage-service": "^2.0.0-alpha.2",
66
66
  "@empathyco/x-types": "^10.0.0-alpha.20",
67
- "@empathyco/x-utils": "^0.1.0-alpha.4",
67
+ "@empathyco/x-utils": "^0.1.0-alpha.6",
68
68
  "@types/resize-observer-browser": "~0.1.5",
69
69
  "nanoid": "~3.1.31",
70
70
  "reflect-metadata": "~0.1.13",
@@ -78,23 +78,20 @@
78
78
  "vuex": "^3.0.0"
79
79
  },
80
80
  "devDependencies": {
81
- "@cucumber/cucumber": "~7.0.0-rc.0",
82
- "@cypress/browserify-preprocessor": "~3.0.1",
83
- "@cypress/vue": "~2.2.3",
84
- "@cypress/webpack-dev-server": "~1.4.0",
85
- "@cypress/webpack-preprocessor": "~5.1.1",
81
+ "@cypress/vue": "~2.2.4",
82
+ "@cypress/webpack-dev-server": "~1.8.4",
86
83
  "@microsoft/api-documenter": "~7.15.3",
87
- "@microsoft/api-extractor": "~7.19.4",
84
+ "@microsoft/api-extractor": "~7.20.0",
88
85
  "@rollup/plugin-commonjs": "~21.0.1",
89
86
  "@testing-library/jest-dom": "~5.11.1",
90
87
  "@types/autoprefixer": "~9.6.1",
91
88
  "@types/jest": "~27.0.3",
92
89
  "@types/node": "~16.4.12",
93
90
  "@types/testing-library__jest-dom": "~5.9.1",
94
- "@vue/cli-plugin-e2e-cypress": "~4.5.16",
95
- "@vue/cli-plugin-typescript": "~4.5.16",
96
- "@vue/cli-plugin-vuex": "~4.5.16",
97
- "@vue/cli-service": "~4.5.16",
91
+ "@vue/cli-plugin-e2e-cypress": "~5.0.4",
92
+ "@vue/cli-plugin-typescript": "~5.0.4",
93
+ "@vue/cli-plugin-vuex": "~5.0.4",
94
+ "@vue/cli-service": "~5.0.4",
98
95
  "@vue/test-utils": "~1.0.3",
99
96
  "@vue/vue2-jest": "~27.0.0-alpha.3",
100
97
  "autoprefixer": "~9.7.4",
@@ -104,6 +101,7 @@
104
101
  "glob": "~7.1.6",
105
102
  "jest": "~27.3.1",
106
103
  "jest-scss-transform": "~1.0.1",
104
+ "postcss": "~8.4.12",
107
105
  "postcss-dir-pseudo-class": "~5.0.0",
108
106
  "postcss-logical": "~4.0.2",
109
107
  "rimraf": "~3.0.2",
@@ -128,5 +126,5 @@
128
126
  "access": "public",
129
127
  "directory": "dist"
130
128
  },
131
- "gitHead": "8efe7a9f47c1aad2fdfe6fc796a46ad0e2dc987d"
129
+ "gitHead": "2c69dfbdef710f47d32db3ef9831559adeac971f"
132
130
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.19.4"
8
+ "packageVersion": "7.20.0"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.19.4",
4
+ "toolVersion": "7.19.5",
5
5
  "schemaVersion": 1004,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {