@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.
- package/CHANGELOG.md +35 -0
- package/core/index.js +0 -1
- package/core/index.js.map +1 -1
- package/design-system/default-theme.css +100 -100
- package/docs/API-reference/api/x-components.actionstree.md +1 -1
- package/docs/API-reference/api/x-components.anyactionstree.md +1 -1
- package/docs/API-reference/api/x-components.anygetterstree.md +1 -1
- package/docs/API-reference/api/x-components.anymutationstree.md +1 -1
- package/docs/API-reference/api/x-components.compilemessage.md +1 -1
- package/docs/API-reference/api/x-components.extraparams.md +2 -2
- package/docs/API-reference/api/x-components.extraparamsmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.extraparamsstate.md +1 -1
- package/docs/API-reference/api/x-components.extraparamsxevents.md +4 -4
- package/docs/API-reference/api/x-components.getterstree.md +1 -1
- package/docs/API-reference/api/x-components.identifierresultsmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.identifierresultsstate.md +1 -1
- package/docs/API-reference/api/x-components.md +0 -8
- package/docs/API-reference/api/x-components.mutationstree.md +1 -1
- package/docs/API-reference/api/x-components.nextqueriesmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.nextqueriesstate.md +1 -1
- package/docs/API-reference/api/x-components.popularsearchesmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.popularsearchesstate.md +1 -1
- package/docs/API-reference/api/x-components.querysuggestionsmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.querysuggestionsstate.md +1 -1
- package/docs/API-reference/api/x-components.recommendationsmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.recommendationsstate.md +1 -1
- package/docs/API-reference/api/x-components.relatedtagsmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.relatedtagsstate.md +1 -1
- package/docs/API-reference/api/x-components.renderlessextraparams.md +1 -1
- package/docs/API-reference/api/x-components.returns.md +0 -2
- package/docs/API-reference/api/x-components.scrollstate.md +1 -1
- package/docs/API-reference/api/x-components.searchmutations.setparams.md +1 -1
- package/docs/API-reference/api/x-components.searchstate.md +2 -2
- package/docs/API-reference/api/x-components.setextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setidentifierresultsextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setinitialextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setnextqueriesextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setpopularsearchesextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setquerysuggestionsextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setrecommendationsextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setrelatedtagsextraparams.md +1 -1
- package/docs/API-reference/api/x-components.setsearchextraparams.md +1 -1
- package/docs/API-reference/api/x-components.simplestateselector.md +0 -2
- package/docs/API-reference/api/x-components.snippetconfigextraparams.md +1 -1
- package/docs/API-reference/api/x-components.urlhandler.md +1 -1
- package/docs/API-reference/api/x-components.urlmutations.setinitialextraparams.md +1 -1
- package/docs/API-reference/api/x-components.urlstate.md +1 -1
- package/docs/API-reference/api/x-components.urlxevents.extraparamsloadedfromurl.md +1 -1
- package/docs/API-reference/api/x-components.urlxevents.md +1 -1
- package/docs/API-reference/api/x-components.vuecssclasses.md +0 -2
- package/docs/API-reference/api/x-components.wiring.md +1 -1
- package/js/components/global-x-bus.vue.js.map +1 -1
- package/js/components/global-x-bus.vue_rollup-plugin-vue_script.vue.js +1 -1
- package/js/components/global-x-bus.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/snippet-callbacks.vue.js.map +1 -1
- package/js/components/snippet-callbacks.vue_rollup-plugin-vue_script.vue.js +1 -1
- package/js/components/snippet-callbacks.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/components/suggestions/base-suggestion.vue.js.map +1 -1
- package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js +1 -1
- package/js/components/suggestions/base-suggestion.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/filters/compile-message.filter.js.map +1 -1
- package/js/index.js +0 -1
- package/js/index.js.map +1 -1
- package/js/plugins/x-emitters.js +1 -1
- package/js/plugins/x-emitters.js.map +1 -1
- package/js/plugins/x-plugin.js +1 -2
- package/js/plugins/x-plugin.js.map +1 -1
- package/js/store/utils/getters-proxy.utils.js +1 -1
- package/js/store/utils/getters-proxy.utils.js.map +1 -1
- package/js/store/utils/store-emitters.utils.js.map +1 -1
- package/js/x-installer/x-installer/x-installer.js +1 -1
- package/js/x-installer/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/extra-params/components/extra-params.vue.js.map +1 -1
- package/js/x-modules/extra-params/components/extra-params.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/extra-params/components/renderless-extra-param.vue.js.map +1 -1
- package/js/x-modules/extra-params/components/renderless-extra-param.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/extra-params/components/snippet-config-extra-params.vue.js.map +1 -1
- package/js/x-modules/extra-params/components/snippet-config-extra-params.vue_rollup-plugin-vue_script.vue.js +1 -2
- package/js/x-modules/extra-params/components/snippet-config-extra-params.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js +2 -2
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue_rollup-plugin-vue_script.vue.js +1 -1
- package/js/x-modules/facets/components/facets/facets.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/facets/store/getters/facets.getter.js +1 -1
- package/js/x-modules/facets/store/getters/facets.getter.js.map +1 -1
- package/js/x-modules/facets/store/getters/selected-filters-by-facet.getter.js +1 -1
- package/js/x-modules/facets/store/getters/selected-filters-by-facet.getter.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/search/store/actions/reset-state.action.js +1 -1
- package/js/x-modules/search/store/actions/reset-state.action.js.map +1 -1
- package/js/x-modules/url/components/url-handler.vue.js.map +1 -1
- package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js +1 -1
- package/js/x-modules/url/components/url-handler.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/url/store/getters/url-params.getter.js +1 -1
- package/js/x-modules/url/store/getters/url-params.getter.js.map +1 -1
- package/js/x-modules/url/store/mutations/set-params.mutation.js +1 -1
- package/js/x-modules/url/store/mutations/set-params.mutation.js.map +1 -1
- package/package.json +13 -15
- package/report/tsdoc-metadata.json +1 -1
- package/report/x-adapter.api.json +1 -1
- package/report/x-components.api.json +688 -1054
- package/report/x-components.api.md +1 -24
- package/report/x-types.api.json +1 -1
- package/types/components/snippet-callbacks.vue.d.ts.map +1 -1
- package/types/components/suggestions/base-suggestion.vue.d.ts.map +1 -1
- package/types/filters/compile-message.filter.d.ts +1 -1
- package/types/filters/compile-message.filter.d.ts.map +1 -1
- package/types/plugins/x-emitters.d.ts.map +1 -1
- package/types/plugins/x-plugin.d.ts.map +1 -1
- package/types/store/actions.types.d.ts +2 -1
- package/types/store/actions.types.d.ts.map +1 -1
- package/types/store/getters.types.d.ts +1 -1
- package/types/store/getters.types.d.ts.map +1 -1
- package/types/store/mutations.types.d.ts +1 -1
- package/types/store/mutations.types.d.ts.map +1 -1
- package/types/store/utils/getters-proxy.utils.d.ts.map +1 -1
- package/types/store/utils/store-emitters.utils.d.ts +2 -1
- package/types/store/utils/store-emitters.utils.d.ts.map +1 -1
- package/types/utils/index.d.ts +0 -1
- package/types/utils/index.d.ts.map +1 -1
- package/types/utils/types.d.ts +1 -9
- package/types/utils/types.d.ts.map +1 -1
- package/types/wiring/wiring.types.d.ts +2 -1
- package/types/wiring/wiring.types.d.ts.map +1 -1
- package/types/x-installer/x-installer/x-installer.d.ts.map +1 -1
- package/types/x-modules/extra-params/components/extra-params.vue.d.ts +1 -1
- package/types/x-modules/extra-params/components/extra-params.vue.d.ts.map +1 -1
- package/types/x-modules/extra-params/components/renderless-extra-param.vue.d.ts +1 -1
- package/types/x-modules/extra-params/components/renderless-extra-param.vue.d.ts.map +1 -1
- package/types/x-modules/extra-params/components/snippet-config-extra-params.vue.d.ts +1 -1
- package/types/x-modules/extra-params/components/snippet-config-extra-params.vue.d.ts.map +1 -1
- package/types/x-modules/extra-params/events.types.d.ts +1 -1
- package/types/x-modules/extra-params/events.types.d.ts.map +1 -1
- package/types/x-modules/extra-params/store/emitters.d.ts +1 -1
- package/types/x-modules/extra-params/store/types.d.ts +1 -1
- package/types/x-modules/extra-params/store/types.d.ts.map +1 -1
- package/types/x-modules/extra-params/wiring.d.ts +4 -4
- package/types/x-modules/extra-params/wiring.d.ts.map +1 -1
- package/types/x-modules/facets/components/facets/facets.vue.d.ts +1 -1
- package/types/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
- package/types/x-modules/identifier-results/store/types.d.ts +1 -1
- package/types/x-modules/identifier-results/store/types.d.ts.map +1 -1
- package/types/x-modules/identifier-results/wiring.d.ts +2 -2
- package/types/x-modules/identifier-results/wiring.d.ts.map +1 -1
- package/types/x-modules/next-queries/store/types.d.ts +1 -1
- package/types/x-modules/next-queries/store/types.d.ts.map +1 -1
- package/types/x-modules/next-queries/wiring.d.ts +2 -2
- package/types/x-modules/next-queries/wiring.d.ts.map +1 -1
- package/types/x-modules/popular-searches/store/types.d.ts +1 -1
- package/types/x-modules/popular-searches/store/types.d.ts.map +1 -1
- package/types/x-modules/popular-searches/wiring.d.ts +2 -2
- package/types/x-modules/popular-searches/wiring.d.ts.map +1 -1
- package/types/x-modules/query-suggestions/store/types.d.ts +1 -1
- package/types/x-modules/query-suggestions/store/types.d.ts.map +1 -1
- package/types/x-modules/query-suggestions/wiring.d.ts +2 -2
- package/types/x-modules/query-suggestions/wiring.d.ts.map +1 -1
- package/types/x-modules/recommendations/store/types.d.ts +1 -1
- package/types/x-modules/recommendations/store/types.d.ts.map +1 -1
- package/types/x-modules/recommendations/wiring.d.ts +2 -2
- package/types/x-modules/recommendations/wiring.d.ts.map +1 -1
- package/types/x-modules/related-tags/store/types.d.ts +1 -1
- package/types/x-modules/related-tags/store/types.d.ts.map +1 -1
- package/types/x-modules/related-tags/wiring.d.ts +2 -2
- package/types/x-modules/related-tags/wiring.d.ts.map +1 -1
- package/types/x-modules/scroll/components/scroll-to-top.vue.d.ts +1 -1
- package/types/x-modules/scroll/components/scroll-to-top.vue.d.ts.map +1 -1
- package/types/x-modules/scroll/store/types.d.ts +1 -1
- package/types/x-modules/scroll/store/types.d.ts.map +1 -1
- package/types/x-modules/search/store/types.d.ts +1 -1
- package/types/x-modules/search/store/types.d.ts.map +1 -1
- package/types/x-modules/search/wiring.d.ts +2 -2
- package/types/x-modules/search/wiring.d.ts.map +1 -1
- package/types/x-modules/url/components/url-handler.vue.d.ts +1 -1
- package/types/x-modules/url/components/url-handler.vue.d.ts.map +1 -1
- package/types/x-modules/url/events.types.d.ts +3 -2
- package/types/x-modules/url/events.types.d.ts.map +1 -1
- package/types/x-modules/url/store/types.d.ts +1 -1
- package/types/x-modules/url/store/types.d.ts.map +1 -1
- package/types/x-modules/url/wiring.d.ts +2 -2
- package/types/x-modules/url/wiring.d.ts.map +1 -1
- package/docs/API-reference/api/x-components.cleanundefined.md +0 -26
- package/docs/API-reference/api/x-components.dictionary.md +0 -13
- package/docs/API-reference/api/x-components.every.md +0 -27
- package/docs/API-reference/api/x-components.foreach.md +0 -25
- package/docs/API-reference/api/x-components.getnewandupdatedkeys.md +0 -27
- package/docs/API-reference/api/x-components.map.md +0 -27
- package/docs/API-reference/api/x-components.objectfilter.md +0 -27
- package/docs/API-reference/api/x-components.reduce.md +0 -28
- package/js/utils/object.js +0 -115
- package/js/utils/object.js.map +0 -1
- package/types/utils/object.d.ts +0 -70
- package/types/utils/object.d.ts.map +0 -1
|
@@ -9,5 +9,5 @@ Sets the extra params of the [ExtraParamsXModule](./x-components.extraparamsxmod
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setExtraParams: import("../../wiring").Wire<import("
|
|
12
|
+
setExtraParams: import("../../wiring").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the identifier result state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setIdentifierResultsExtraParams: import("../..").Wire<import("
|
|
12
|
+
setIdentifierResultsExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the next queries state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setNextQueriesExtraParams: import("../..").Wire<import("
|
|
12
|
+
setNextQueriesExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the popular searches state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setPopularSearchesExtraParams: import("../..").Wire<import("
|
|
12
|
+
setPopularSearchesExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the query suggestions state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setQuerySuggestionsExtraParams: import("../..").Wire<import("
|
|
12
|
+
setQuerySuggestionsExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the recommendations state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setRecommendationsExtraParams: import("../..").Wire<import("
|
|
12
|
+
setRecommendationsExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the related tags state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setRelatedTagsExtraParams: import("../..").Wire<import("
|
|
12
|
+
setRelatedTagsExtraParams: import("../..").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -9,5 +9,5 @@ Sets the search state `params`<!-- -->.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
setSearchExtraParams: import("../../wiring/wiring.types").Wire<import("
|
|
12
|
+
setSearchExtraParams: import("../../wiring/wiring.types").Wire<import("@empathyco/x-utils").Dictionary<unknown>>
|
|
13
13
|
```
|
|
@@ -11,5 +11,3 @@ Selects a part of the store state or getters (AKA "getter" inside [Vuex](https:/
|
|
|
11
11
|
```typescript
|
|
12
12
|
export declare type SimpleStateSelector<ReturnType, State extends Dictionary, Getters extends Dictionary> = (state: State, getters: Getters) => ReturnType;
|
|
13
13
|
```
|
|
14
|
-
<b>References:</b> [Dictionary](./x-components.dictionary.md)
|
|
15
|
-
|
|
@@ -17,5 +17,5 @@ export default class SnippetConfigExtraParams extends Vue
|
|
|
17
17
|
|
|
18
18
|
| Property | Modifiers | Type | Description |
|
|
19
19
|
| --- | --- | --- | --- |
|
|
20
|
-
| [values?](./x-components.snippetconfigextraparams.values.md) | |
|
|
20
|
+
| [values?](./x-components.snippetconfigextraparams.values.md) | | Dictionary<unknown> | <i>(Optional)</i> A Dictionary where the keys are the extra param names and its values. |
|
|
21
21
|
|
|
@@ -17,7 +17,7 @@ export default class UrlHandler extends Vue
|
|
|
17
17
|
|
|
18
18
|
| Property | Modifiers | Type | Description |
|
|
19
19
|
| --- | --- | --- | --- |
|
|
20
|
-
| [initialExtraParams](./x-components.urlhandler.initialextraparams.md) | |
|
|
20
|
+
| [initialExtraParams](./x-components.urlhandler.initialextraparams.md) | | Dictionary<unknown> | |
|
|
21
21
|
|
|
22
22
|
## Methods
|
|
23
23
|
|
|
@@ -16,7 +16,7 @@ setInitialExtraParams(extraParams: Dictionary<unknown>): void;
|
|
|
16
16
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
|
-
| extraParams |
|
|
19
|
+
| extraParams | Dictionary<unknown> | The new initial extra params. |
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
@@ -17,5 +17,5 @@ export interface UrlState extends QueryState, UrlParams
|
|
|
17
17
|
|
|
18
18
|
| Property | Type | Description |
|
|
19
19
|
| --- | --- | --- |
|
|
20
|
-
| [initialExtraParams](./x-components.urlstate.initialextraparams.md) |
|
|
20
|
+
| [initialExtraParams](./x-components.urlstate.initialextraparams.md) | Dictionary<unknown> | |
|
|
21
21
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## UrlXEvents.ExtraParamsLoadedFromUrl property
|
|
6
6
|
|
|
7
|
-
Url loaded. \* Payload: The extra params form URL in form of
|
|
7
|
+
Url loaded. \* Payload: The extra params form URL in form of with `unknown` values.
|
|
8
8
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ export interface UrlXEvents
|
|
|
16
16
|
|
|
17
17
|
| Property | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
|
-
| [ExtraParamsLoadedFromUrl](./x-components.urlxevents.extraparamsloadedfromurl.md) |
|
|
19
|
+
| [ExtraParamsLoadedFromUrl](./x-components.urlxevents.extraparamsloadedfromurl.md) | Dictionary<unknown> | Url loaded. \* Payload: The extra params form URL in form of with <code>unknown</code> values. |
|
|
20
20
|
| [ParamsLoadedFromUrl](./x-components.urlxevents.paramsloadedfromurl.md) | [UrlParams](./x-components.urlparams.md) | Url loaded. \* Payload: The new [UrlParams](./x-components.urlparams.md) params. |
|
|
21
21
|
| [PushableUrlStateChanged](./x-components.urlxevents.pushableurlstatechanged.md) | [UrlParams](./x-components.urlparams.md) | Url state changed with a change to add new entry to browser URL History State. \* Payload: The new URL params. |
|
|
22
22
|
| [ReplaceableUrlStateChanged](./x-components.urlxevents.replaceableurlstatechanged.md) | [UrlParams](./x-components.urlparams.md) | Url state changed with a change to replace the current entry to browser URL History State. \* Payload: The new URL params. |
|
|
@@ -13,5 +13,5 @@ export declare type Wiring = {
|
|
|
13
13
|
[Event in XEvent]: Dictionary<WireForEvent<Event>>;
|
|
14
14
|
};
|
|
15
15
|
```
|
|
16
|
-
<b>References:</b> [XEvent](./x-components.xevent.md)<!-- -->, [
|
|
16
|
+
<b>References:</b> [XEvent](./x-components.xevent.md)<!-- -->, [WireForEvent](./x-components.wireforevent.md)
|
|
17
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-x-bus.vue.js","sources":["../../../src/components/global-x-bus.vue"],"sourcesContent":["<script lang=\"ts\">\n import {
|
|
1
|
+
{"version":3,"file":"global-x-bus.vue.js","sources":["../../../src/components/global-x-bus.vue"],"sourcesContent":["<script lang=\"ts\">\n import { reduce } from '@empathyco/x-utils';\n import { Component } from 'vue-property-decorator';\n import { Subscription } from 'rxjs';\n import { XEventListeners } from '../x-installer/api/api.types';\n import { NoElement } from './no-element';\n\n /**\n * This component helps subscribing to any {@link XEvent} with custom callbacks using Vue\n * listeners API.\n *\n * @public\n */\n @Component\n export default class GlobalXBus extends NoElement {\n /**\n * Object with the {@link XEvent} listeners.\n *\n * @internal\n */\n public $listeners!: XEventListeners;\n\n created(): void {\n this.handleXEventSubscription();\n }\n\n /**\n * Handles a subscription to all the events provided in the listeners with the function that\n * will execute the callback. Also unsubscribes on beforeDestroy.\n *\n * @internal\n */\n protected handleXEventSubscription(): void {\n const subscription = reduce(\n this.$listeners,\n (subscription, eventName, callback) => {\n subscription.add(\n this.$x.on(eventName, true).subscribe(({ eventPayload, metadata }) => {\n callback(eventPayload as never, metadata);\n })\n );\n return subscription;\n },\n new Subscription()\n );\n\n this.$on('hook:beforeDestroy', () => {\n subscription.unsubscribe();\n });\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nThis component emits no own events, but you can subscribe to any X Event using Vue listeners\n\n## See it in action\n\nThis component does not render anything. Its only responsibility is to facilitate listening to any X\nEvent by using Vue component listeners.\n\n```vue\n<template>\n <GlobalXBus @UserAcceptedAQuery=\"printQuery\" />\n</template>\n\n<script>\n import { GlobalXBus } from '@empathyco/x-components';\n export default {\n name: 'GlobalXBusTest',\n components: {\n GlobalXBus\n },\n methods: {\n printQuery(query, metadata) {\n console.log('My new query is:', query);\n console.log('And has been triggered by this DOM element:', metadata.target);\n }\n }\n };\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
+
import { reduce } from '@empathyco/x-utils';
|
|
2
3
|
import { Component } from 'vue-property-decorator';
|
|
3
4
|
import { Subscription } from 'rxjs';
|
|
4
|
-
import { reduce } from '../utils/object.js';
|
|
5
5
|
import { NoElement } from './no-element.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-x-bus.vue_rollup-plugin-vue_script.vue.js","sources":["../../../src/components/global-x-bus.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\nimport {
|
|
1
|
+
{"version":3,"file":"global-x-bus.vue_rollup-plugin-vue_script.vue.js","sources":["../../../src/components/global-x-bus.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\nimport { reduce } from '@empathyco/x-utils';\nimport { Component } from 'vue-property-decorator';\nimport { Subscription } from 'rxjs';\nimport { XEventListeners } from '../x-installer/api/api.types';\nimport { NoElement } from './no-element';\n\n/**\n * This component helps subscribing to any {@link XEvent} with custom callbacks using Vue\n * listeners API.\n *\n * @public\n */\n@Component\nexport default class GlobalXBus extends NoElement {\n /**\n * Object with the {@link XEvent} listeners.\n *\n * @internal\n */\n public $listeners!: XEventListeners;\n\n created(): void {\n this.handleXEventSubscription();\n }\n\n /**\n * Handles a subscription to all the events provided in the listeners with the function that\n * will execute the callback. Also unsubscribes on beforeDestroy.\n *\n * @internal\n */\n protected handleXEventSubscription(): void {\n const subscription = reduce(\n this.$listeners,\n (subscription, eventName, callback) => {\n subscription.add(\n this.$x.on(eventName, true).subscribe(({ eventPayload, metadata }) => {\n callback(eventPayload as never, metadata);\n })\n );\n return subscription;\n },\n new Subscription()\n );\n\n this.$on('hook:beforeDestroy', () => {\n subscription.unsubscribe();\n });\n }\n}\n"],"names":[],"mappings":";;;;;;AAOA;;;;;;AAOA,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,SAAS;IAQ/C,OAAO;QACL,IAAI,CAAC,wBAAwB,EAAE,CAAC;KACjC;;;;;;;IAQS,wBAAwB;QAChC,MAAM,YAAY,GAAG,MAAM,CACzB,IAAI,CAAC,UAAU,EACf,CAAC,YAAY,EAAE,SAAS,EAAE,QAAQ;YAChC,YAAY,CAAC,GAAG,CACd,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE;gBAC/D,QAAQ,CAAC,YAAqB,EAAE,QAAQ,CAAC,CAAC;aAC3C,CAAC,CACH,CAAC;YACF,OAAO,YAAY,CAAC;SACrB,EACD,IAAI,YAAY,EAAE,CACnB,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE;YAC7B,YAAY,CAAC,WAAW,EAAE,CAAC;SAC5B,CAAC,CAAC;KACJ;CACF,CAAA;AApCoB,UAAU;IAD9B,SAAS;GACW,UAAU,CAoC9B;aApCoB,UAAU;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-callbacks.vue.js","sources":["../../../src/components/snippet-callbacks.vue"],"sourcesContent":["<template>\n <GlobalXBus v-on=\"eventListeners\" />\n</template>\n\n<script lang=\"ts\">\n import {
|
|
1
|
+
{"version":3,"file":"snippet-callbacks.vue.js","sources":["../../../src/components/snippet-callbacks.vue"],"sourcesContent":["<template>\n <GlobalXBus v-on=\"eventListeners\" />\n</template>\n\n<script lang=\"ts\">\n import { map } from '@empathyco/x-utils';\n import { Component, Inject } from 'vue-property-decorator';\n import Vue from 'vue';\n import { WireMetadata } from '../wiring';\n import { SnippetConfig, XEventListeners } from '../x-installer/api/api.types';\n import GlobalXBus from './global-x-bus.vue';\n\n /**\n * This component subscribes to any {@link XEvent} with a custom callbacks provided by the snippet\n * configuration.\n *\n * @public\n */\n @Component({\n components: { GlobalXBus }\n })\n export default class SnippetCallbacks extends Vue {\n /**\n * Injects {@link SnippetConfig} provided by an ancestor as snippetConfig.\n *\n * @internal\n */\n @Inject('snippetConfig')\n public snippetConfig!: SnippetConfig;\n\n /**\n * It maps all the callbacks provided by the snippetConfig and adds an emit to each one.\n *\n * @returns The event listeners with the {@link XEventsTypes.SnippetCallbackExecuted} emit in\n * the callback.\n *\n * @internal\n *\n */\n protected get eventListeners(): XEventListeners {\n const { callbacks } = this.snippetConfig;\n return callbacks\n ? map(callbacks, (eventName, callback) => {\n return (payload: unknown, metadata: WireMetadata) => {\n const callbackReturn = callback(payload as never, metadata);\n this.$x.emit('SnippetCallbackExecuted', {\n event: eventName,\n callbackReturn,\n payload: payload as never,\n metadata\n });\n };\n })\n : ({} as XEventListeners);\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nThe `SnippetCallbacks` will emit the `SnippetCallbackExecuted` each time a callback provided by the\nsnippetConfig is fired.\n\n## See it in action\n\nThis component does not render anything. Its only responsibility is to receive any callback that\nwill be triggered once its listened event is emitted.\n\n```vue\n<template>\n <SnippetCallbacks />\n</template>\n\n<script>\n import { SnippetCallbacks } from '@empathyco/x-components';\n export default {\n name: 'SnippetCallbacksTest',\n components: {\n SnippetCallbacks\n }\n };\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
+
import { map } from '@empathyco/x-utils';
|
|
2
3
|
import { Inject, Component } from 'vue-property-decorator';
|
|
3
4
|
import Vue from 'vue';
|
|
4
|
-
import { map } from '../utils/object.js';
|
|
5
5
|
import __vue_component__ from './global-x-bus.vue.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-callbacks.vue_rollup-plugin-vue_script.vue.js","sources":["../../../src/components/snippet-callbacks.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\nimport { Component, Inject } from 'vue-property-decorator';\nimport Vue from 'vue';\nimport {
|
|
1
|
+
{"version":3,"file":"snippet-callbacks.vue_rollup-plugin-vue_script.vue.js","sources":["../../../src/components/snippet-callbacks.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\nimport { map } from '@empathyco/x-utils';\nimport { Component, Inject } from 'vue-property-decorator';\nimport Vue from 'vue';\nimport { WireMetadata } from '../wiring';\nimport { SnippetConfig, XEventListeners } from '../x-installer/api/api.types';\nimport GlobalXBus from './global-x-bus.vue';\n\n/**\n * This component subscribes to any {@link XEvent} with a custom callbacks provided by the snippet\n * configuration.\n *\n * @public\n */\n@Component({\n components: { GlobalXBus }\n})\nexport default class SnippetCallbacks extends Vue {\n /**\n * Injects {@link SnippetConfig} provided by an ancestor as snippetConfig.\n *\n * @internal\n */\n @Inject('snippetConfig')\n public snippetConfig!: SnippetConfig;\n\n /**\n * It maps all the callbacks provided by the snippetConfig and adds an emit to each one.\n *\n * @returns The event listeners with the {@link XEventsTypes.SnippetCallbackExecuted} emit in\n * the callback.\n *\n * @internal\n *\n */\n protected get eventListeners(): XEventListeners {\n const { callbacks } = this.snippetConfig;\n return callbacks\n ? map(callbacks, (eventName, callback) => {\n return (payload: unknown, metadata: WireMetadata) => {\n const callbackReturn = callback(payload as never, metadata);\n this.$x.emit('SnippetCallbackExecuted', {\n event: eventName,\n callbackReturn,\n payload: payload as never,\n metadata\n });\n };\n })\n : ({} as XEventListeners);\n }\n}\n"],"names":["GlobalXBus"],"mappings":";;;;;;AAYA;;;;;;AASA,IAAqB,gBAAgB,GAArC,MAAqB,gBAAiB,SAAQ,GAAG;;;;;;;;;;IAkB/C,IAAc,cAAc;QAC1B,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,OAAO,SAAS;cACZ,GAAG,CAAC,SAAS,EAAE,CAAC,SAAS,EAAE,QAAQ;gBACjC,OAAO,CAAC,OAAgB,EAAE,QAAsB;oBAC9C,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAgB,EAAE,QAAQ,CAAC,CAAC;oBAC5D,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE;wBACtC,KAAK,EAAE,SAAS;wBAChB,cAAc;wBACd,OAAO,EAAE,OAAgB;wBACzB,QAAQ;qBACT,CAAC,CAAC;iBACJ,CAAC;aACH,CAAC;cACD,EAAsB,CAAC;KAC7B;CACF,CAAA;AA3BC;IADC,MAAM,CAAC,eAAe,CAAC;uDACa;AAPlB,gBAAgB;IAHpC,SAAS,CAAC;QACT,UAAU,EAAE,cAAEA,iBAAU,EAAE;KAC3B,CAAC;GACmB,gBAAgB,CAkCpC;aAlCoB,gBAAgB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-suggestion.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue"],"sourcesContent":["<template>\n <button @click=\"emitEvents\" :class=\"dynamicCSSClasses\" class=\"x-suggestion\">\n <!-- eslint-disable max-len -->\n <!--\n @slot Button content\n @binding {Suggestion} suggestion - Suggestion data\n @binding {string} queryHTML - Suggestion's query with the matching part inside a `<span>` tag\n -->\n <!-- eslint-enable max-len -->\n <slot v-bind=\"{ suggestion, queryHTML }\">\n <span v-html=\"queryHTML\" :aria-label=\"suggestion.query\" class=\"x-suggestion__query\" />\n </slot>\n </button>\n</template>\n\n<script lang=\"ts\">\n import { Suggestion } from '@empathyco/x-types';\n import Vue from 'vue';\n import { Component, Prop } from 'vue-property-decorator';\n import { QueryFeature } from '../../types/origin';\n import {
|
|
1
|
+
{"version":3,"file":"base-suggestion.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue"],"sourcesContent":["<template>\n <button @click=\"emitEvents\" :class=\"dynamicCSSClasses\" class=\"x-suggestion\">\n <!-- eslint-disable max-len -->\n <!--\n @slot Button content\n @binding {Suggestion} suggestion - Suggestion data\n @binding {string} queryHTML - Suggestion's query with the matching part inside a `<span>` tag\n -->\n <!-- eslint-enable max-len -->\n <slot v-bind=\"{ suggestion, queryHTML }\">\n <span v-html=\"queryHTML\" :aria-label=\"suggestion.query\" class=\"x-suggestion__query\" />\n </slot>\n </button>\n</template>\n\n<script lang=\"ts\">\n import { Suggestion } from '@empathyco/x-types';\n import { forEach } from '@empathyco/x-utils';\n import Vue from 'vue';\n import { Component, Prop } from 'vue-property-decorator';\n import { QueryFeature } from '../../types/origin';\n import { normalizeString } from '../../utils/normalize';\n import { sanitize } from '../../utils/sanitize';\n import { VueCSSClasses } from '../../utils/types';\n import { XEventsTypes } from '../../wiring/events.types';\n\n /**\n * Renders a button with a default slot. It receives a query, which should be the query of the\n * module using this component, a suggestion, the {@link XEvent | XEvents} that will be emitted\n * on click with a given feature.\n *\n * The default slot receives the suggestion and the matched query has props.\n *\n * @public\n */\n @Component\n export default class BaseSuggestion extends Vue {\n /**\n * The normalized query of the module using this component.\n *\n * @public\n */\n @Prop({ default: '' })\n protected query!: string;\n\n /**\n * The suggestion to render and use in the default slot.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestion!: Suggestion;\n\n /**\n * The feature from which the events will be emitted.\n *\n * @public\n */\n @Prop() //TODO: set to true when the suggestions components pass it.\n protected feature?: QueryFeature;\n\n /**\n * The {@link XEvent | XEvents} that will be emitted when selecting a suggestion.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestionSelectedEvents!: Partial<XEventsTypes>;\n\n /**\n * Indicates if the curated suggestion should be highlighted.\n *\n * @public\n */\n @Prop({ default: false, type: Boolean })\n protected highlightCurated!: boolean;\n\n /**\n * The event handler that will be triggered when clicking on a suggestion.\n *\n * @remarks\n * * UserAcceptedAQuery: suggestion.query\n * * UserSelectedASuggestion: suggestion\n * * Merges the events defined in the suggestionSelectedEvents prop and also emits them\n *\n * @returns The {@link XEvent | XEvents} to emit.\n * @public\n */\n protected get events(): Partial<XEventsTypes> {\n return {\n UserAcceptedAQuery: this.suggestion.query,\n UserSelectedASuggestion: this.suggestion,\n ...this.suggestionSelectedEvents\n };\n }\n\n /**\n * Emits the events when the button is clicked.\n *\n * @public\n */\n protected emitEvents(): void {\n forEach(this.events, (event, payload) => {\n this.$x.emit(event, payload, {\n target: this.$el as HTMLElement,\n feature: this.feature\n });\n });\n }\n\n /**\n * Checks if the normalized suggestion query matches with the module's query so it has a\n * matching part.\n *\n * @returns If the query has a matching part or not.\n * @internal\n */\n protected get hasMatchingQuery(): boolean {\n return !!this.query && normalizeString(this.suggestion.query).includes(this.query);\n }\n\n /**\n * Checks if the suggestion is curated and if it should be highlighted.\n *\n * @returns True if the suggestion is curated and should be highlighted.\n *\n * @internal\n */\n protected get shouldHighlightCurated(): boolean {\n return this.highlightCurated && !!this.suggestion.isCurated;\n }\n\n /**\n * Generates css classes dynamically.\n *\n * @remarks\n * 'x-suggestion--matching added when the query should be matched.\n *\n * @returns The {@link VueCSSClasses} classes.\n * @public\n */\n protected get dynamicCSSClasses(): VueCSSClasses {\n return {\n 'x-suggestion--matching': this.hasMatchingQuery,\n 'x-suggestion--is-curated': this.shouldHighlightCurated\n };\n }\n\n /**\n * Highlights the matching part of the suggestion query with the query passed as prop of the\n * component putting it inside a `<span>` tag.\n *\n * @remarks\n * The query prop should be normalized.\n *\n * @returns The suggestion's query with the matching part inside a `<span>` tag.\n * @public\n */\n protected get queryHTML(): string {\n if (this.hasMatchingQuery) {\n const matcherIndex = normalizeString(this.suggestion.query).indexOf(this.query);\n\n const [beginning, matching, end] = this.splitAt(\n this.suggestion.query,\n matcherIndex,\n this.query.length\n );\n\n const attrsMatching = 'data-test=\"matching-part\" class=\"x-suggestion__matching-part\"';\n return `${beginning}<span ${attrsMatching}>${matching}</span>${end}`;\n }\n\n return sanitize(this.suggestion.query);\n }\n\n /**\n * Splits the label in three parts based on two indexes.\n *\n * @param label - The string that will be divided in three parts.\n * @param start - The first index that the label will be divided by.\n * @param skip - The second index that the label will be divided by.\n *\n * @returns The three parts of the divided label.\n * @internal\n */\n protected splitAt(label: string, start: number, skip: number): [string, string, string] {\n const startPart = label.substr(0, start);\n const matchingPart = label.substr(start, skip);\n const endPart = label.substr(start + skip);\n\n return [sanitize(startPart), sanitize(matchingPart), sanitize(endPart)];\n }\n }\n</script>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis default suggestion component expects a suggestion to render and pass to its default slot, a\nnormalized query to compare with the suggestion's query and highlight its matching parts and events\nto emit when the suggestion is selected.\n\n### Default usage\n\n```vue\n<BaseSuggestion v-bind=\"{ query, suggestion, suggestionSelectedEvents }\" />\n```\n\n### Customized usage\n\n```vue\n<BaseSuggestion v-bind=\"{ query, suggestion, suggestionSelectedEvents }\">\n <template #default=\"{ suggestion, queryHTML }\">\n <span\n class=\"my-suggestion\"\n v-html=\"queryHTML\"\n :aria-label=\"suggestion.query\"\n />\n </template>\n</BaseSuggestion>\n```\n\n## Events\n\nA list of events that the component will emit:\n\n- `UserAcceptedAQuery`: the event is emitted after the user clicks the button. The event payload is\n the suggestion query data.\n- `UserSelectedASuggestion`: the event is emitted after the user clicks the button. The event\n payload is the suggestion data.\n- The component can emit more events on click using the `suggestionSelectedEvents` prop.\n</docs>\n"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
+
import { forEach } from '@empathyco/x-utils';
|
|
2
3
|
import Vue from 'vue';
|
|
3
4
|
import { Prop, Component } from 'vue-property-decorator';
|
|
4
|
-
import { forEach } from '../../utils/object.js';
|
|
5
5
|
import { normalizeString } from '../../utils/normalize.js';
|
|
6
6
|
import { sanitize } from '../../utils/sanitize.js';
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-suggestion.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nimport { Suggestion } from '@empathyco/x-types';\nimport Vue from 'vue';\nimport { Component, Prop } from 'vue-property-decorator';\nimport { QueryFeature } from '../../types/origin';\nimport {
|
|
1
|
+
{"version":3,"file":"base-suggestion.vue_rollup-plugin-vue_script.vue.js","sources":["../../../../src/components/suggestions/base-suggestion.vue?rollup-plugin-vue=script.ts"],"sourcesContent":["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nimport { Suggestion } from '@empathyco/x-types';\nimport { forEach } from '@empathyco/x-utils';\nimport Vue from 'vue';\nimport { Component, Prop } from 'vue-property-decorator';\nimport { QueryFeature } from '../../types/origin';\nimport { normalizeString } from '../../utils/normalize';\nimport { sanitize } from '../../utils/sanitize';\nimport { VueCSSClasses } from '../../utils/types';\nimport { XEventsTypes } from '../../wiring/events.types';\n\n/**\n * Renders a button with a default slot. It receives a query, which should be the query of the\n * module using this component, a suggestion, the {@link XEvent | XEvents} that will be emitted\n * on click with a given feature.\n *\n * The default slot receives the suggestion and the matched query has props.\n *\n * @public\n */\n@Component\nexport default class BaseSuggestion extends Vue {\n /**\n * The normalized query of the module using this component.\n *\n * @public\n */\n @Prop({ default: '' })\n protected query!: string;\n\n /**\n * The suggestion to render and use in the default slot.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestion!: Suggestion;\n\n /**\n * The feature from which the events will be emitted.\n *\n * @public\n */\n @Prop() //TODO: set to true when the suggestions components pass it.\n protected feature?: QueryFeature;\n\n /**\n * The {@link XEvent | XEvents} that will be emitted when selecting a suggestion.\n *\n * @public\n */\n @Prop({ required: true })\n protected suggestionSelectedEvents!: Partial<XEventsTypes>;\n\n /**\n * Indicates if the curated suggestion should be highlighted.\n *\n * @public\n */\n @Prop({ default: false, type: Boolean })\n protected highlightCurated!: boolean;\n\n /**\n * The event handler that will be triggered when clicking on a suggestion.\n *\n * @remarks\n * * UserAcceptedAQuery: suggestion.query\n * * UserSelectedASuggestion: suggestion\n * * Merges the events defined in the suggestionSelectedEvents prop and also emits them\n *\n * @returns The {@link XEvent | XEvents} to emit.\n * @public\n */\n protected get events(): Partial<XEventsTypes> {\n return {\n UserAcceptedAQuery: this.suggestion.query,\n UserSelectedASuggestion: this.suggestion,\n ...this.suggestionSelectedEvents\n };\n }\n\n /**\n * Emits the events when the button is clicked.\n *\n * @public\n */\n protected emitEvents(): void {\n forEach(this.events, (event, payload) => {\n this.$x.emit(event, payload, {\n target: this.$el as HTMLElement,\n feature: this.feature\n });\n });\n }\n\n /**\n * Checks if the normalized suggestion query matches with the module's query so it has a\n * matching part.\n *\n * @returns If the query has a matching part or not.\n * @internal\n */\n protected get hasMatchingQuery(): boolean {\n return !!this.query && normalizeString(this.suggestion.query).includes(this.query);\n }\n\n /**\n * Checks if the suggestion is curated and if it should be highlighted.\n *\n * @returns True if the suggestion is curated and should be highlighted.\n *\n * @internal\n */\n protected get shouldHighlightCurated(): boolean {\n return this.highlightCurated && !!this.suggestion.isCurated;\n }\n\n /**\n * Generates css classes dynamically.\n *\n * @remarks\n * 'x-suggestion--matching added when the query should be matched.\n *\n * @returns The {@link VueCSSClasses} classes.\n * @public\n */\n protected get dynamicCSSClasses(): VueCSSClasses {\n return {\n 'x-suggestion--matching': this.hasMatchingQuery,\n 'x-suggestion--is-curated': this.shouldHighlightCurated\n };\n }\n\n /**\n * Highlights the matching part of the suggestion query with the query passed as prop of the\n * component putting it inside a `<span>` tag.\n *\n * @remarks\n * The query prop should be normalized.\n *\n * @returns The suggestion's query with the matching part inside a `<span>` tag.\n * @public\n */\n protected get queryHTML(): string {\n if (this.hasMatchingQuery) {\n const matcherIndex = normalizeString(this.suggestion.query).indexOf(this.query);\n\n const [beginning, matching, end] = this.splitAt(\n this.suggestion.query,\n matcherIndex,\n this.query.length\n );\n\n const attrsMatching = 'data-test=\"matching-part\" class=\"x-suggestion__matching-part\"';\n return `${beginning}<span ${attrsMatching}>${matching}</span>${end}`;\n }\n\n return sanitize(this.suggestion.query);\n }\n\n /**\n * Splits the label in three parts based on two indexes.\n *\n * @param label - The string that will be divided in three parts.\n * @param start - The first index that the label will be divided by.\n * @param skip - The second index that the label will be divided by.\n *\n * @returns The three parts of the divided label.\n * @internal\n */\n protected splitAt(label: string, start: number, skip: number): [string, string, string] {\n const startPart = label.substr(0, start);\n const matchingPart = label.substr(start, skip);\n const endPart = label.substr(start + skip);\n\n return [sanitize(startPart), sanitize(matchingPart), sanitize(endPart)];\n }\n}\n"],"names":[],"mappings":";;;;;;;AA0BA;;;;;;;;;AAUA,IAAqB,cAAc,GAAnC,MAAqB,cAAe,SAAQ,GAAG;;;;;;;;;;;;IAoD7C,IAAc,MAAM;QAClB,OAAO;YACL,kBAAkB,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK;YACzC,uBAAuB,EAAE,IAAI,CAAC,UAAU;YACxC,GAAG,IAAI,CAAC,wBAAwB;SACjC,CAAC;KACH;;;;;;IAOS,UAAU;QAClB,OAAO,CAAC,IA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C;;;;;;;;;;;IAYS,OAAO,CAAC,KAAa,EAAE,KAAa,EAAE,IAAY;QAC1D,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACzC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;QAE3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;KACzE;CACF,CAAA;AArJC;IADC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;6CACG;AAQzB;IADC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;kDACS;AAQlC;IADC,IAAI,EAAE;+CAC0B;AAQjC;IADC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gEACkC;AAQ3D;IADC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;wDACH;AAvClB,cAAc;IADlC,SAAS;GACW,cAAc,CA4JlC;aA5JoB,cAAc;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-message.filter.js","sources":["../../../src/filters/compile-message.filter.ts"],"sourcesContent":["import { Dictionary } from '
|
|
1
|
+
{"version":3,"file":"compile-message.filter.js","sources":["../../../src/filters/compile-message.filter.ts"],"sourcesContent":["import { Dictionary } from '@empathyco/x-utils';\n\n/**\n * Replaces a key in compiledMessage for the provided key's value.\n *\n * @param compiledMessage - String containing the key to be replaced.\n * @param keyValueEntry - Key would be the string replaced in compiledMessage and value the\n * string that will get replaced with.\n * @returns Formatted string.\n * @internal\n */\nconst replaceParams = (compiledMessage: string, [key, value]: [string, string | number]): string =>\n compiledMessage.replace(new RegExp(`{${key}}`, 'g'), value.toString());\n\n/**\n * Replaces each key in compiledMessage for the provided key's value.\n *\n * @param message - String containing the keys to be replaced.\n * @param params - Dictionary of key-values that will be used to format compiledMessage.\n * @returns Formatted string.\n * @public\n */\nexport function compileMessage(message: string, params: Dictionary<string | number>): string {\n return message && params\n ? Object.entries<string | number>(params).reduce(replaceParams, message)\n : message;\n}\n"],"names":[],"mappings":"AAEA;;;;;;;;;AASA,MAAM,aAAa,GAAG,CAAC,eAAuB,EAAE,CAAC,GAAG,EAAE,KAAK,CAA4B,KACrF,eAAe,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAEzE;;;;;;;;SAQgB,cAAc,CAAC,OAAe,EAAE,MAAmC;IACjF,OAAO,OAAO,IAAI,MAAM;UACpB,MAAM,CAAC,OAAO,CAAkB,MAAM,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC;UACtE,OAAO,CAAC;AACd;;;;"}
|
package/js/index.js
CHANGED
|
@@ -136,7 +136,6 @@ export { getURLParameter } from './utils/get-url-parameters.js';
|
|
|
136
136
|
export { isElementEqualOrContained } from './utils/html.js';
|
|
137
137
|
export { normalizeString } from './utils/normalize.js';
|
|
138
138
|
export { isInRange } from './utils/number.js';
|
|
139
|
-
export { cleanUndefined, every, forEach, getNewAndUpdatedKeys, map, objectFilter, reduce } from './utils/object.js';
|
|
140
139
|
export { createOrigin } from './utils/origin.js';
|
|
141
140
|
export { sanitize } from './utils/sanitize.js';
|
|
142
141
|
export { localStorageService } from './utils/storage.js';
|
package/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/js/plugins/x-emitters.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { forEach } from '@empathyco/x-utils';
|
|
1
2
|
import { getGettersProxyFromModule } from '../store/utils/getters-proxy.utils.js';
|
|
2
3
|
import { debounce } from '../utils/debounce.js';
|
|
3
|
-
import { forEach } from '../utils/object.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Registers the store emitters, making them emit the event when the part of the state selected
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x-emitters.js","sources":["../../../src/plugins/x-emitters.ts"],"sourcesContent":["import { Store } from 'vuex';\nimport { getGettersProxyFromModule } from '../store/utils/getters-proxy.utils';\nimport { AnySimpleStateSelector, AnyStateSelector } from '../store/utils/store-emitters.utils';\nimport { debounce } from '../utils/debounce';\nimport {
|
|
1
|
+
{"version":3,"file":"x-emitters.js","sources":["../../../src/plugins/x-emitters.ts"],"sourcesContent":["import { forEach, Dictionary } from '@empathyco/x-utils';\nimport { Store } from 'vuex';\nimport { getGettersProxyFromModule } from '../store/utils/getters-proxy.utils';\nimport { AnySimpleStateSelector, AnyStateSelector } from '../store/utils/store-emitters.utils';\nimport { debounce } from '../utils/debounce';\nimport { DebouncedFunction } from '../utils/types';\nimport { XEvent } from '../wiring/events.types';\nimport { AnyXModule } from '../x-modules/x-modules.types';\nimport { XBus } from './x-bus.types';\n\n/**\n * Registers the store emitters, making them emit the event when the part of the state selected\n * changes.\n *\n * @param xModule - The {@link XModule} to register its Store Emitters.\n * @param bus - The {@Link XBus} to emit the events by the Emitters.\n * @param store - The Vuex store to access to state and getters to watch them.\n *\n * @internal\n */\nexport function registerStoreEmitters(\n { name, storeEmitters, storeModule }: AnyXModule,\n bus: XBus,\n store: Store<any>\n): void {\n const safeGettersProxy = getGettersProxyFromModule(store.getters, name, storeModule);\n forEach(storeEmitters, (event, stateSelector: AnySimpleStateSelector | AnyStateSelector) => {\n const { selector, immediate, filter, ...options } = normalizeStateSelector(\n stateSelector,\n event\n );\n\n const emit = (value: unknown, oldValue?: unknown): void => {\n bus.emit(event, value, { moduleName: name, oldValue });\n };\n const watcherSelector = (): unknown => selector(store.state.x[name], safeGettersProxy);\n const debouncedEffect = debounceWatcherEffect(event, (newValue, oldValue) => {\n if (filter(newValue, oldValue)) {\n emit(newValue, oldValue);\n }\n });\n\n store.watch(watcherSelector, debouncedEffect, options);\n\n if (immediate) {\n Promise.resolve().then(() => {\n emit(watcherSelector());\n });\n }\n });\n}\n\n/**\n * This function \"wraps\" the watcher effect (the callback of the watcher) with debounce to avoid\n * repeating events and request. Right now this function wraps every effect in a debounce and adds\n * an extra debounce to the \"SecondLevelEvent\" events, to try to delay this events after the state\n * change events.\n *\n * @param event - The {@link XEvent} to emit.\n * @param watcherEffect - The callback to execute.\n * @returns A new function with the `watcherEffect` callback wrapped in debounce.\n */\nfunction debounceWatcherEffect(\n event: XEvent,\n watcherEffect: (newValue: unknown, oldValue: unknown) => void\n): (newValue: unknown, oldValue: unknown) => void {\n /*\n * Due the debounce added to the watch callback, the `oldValue` would be the one from the last\n * watcher execution instead of the last callback execution. This would cause problems receiving\n * unstable oldValues, used in the Emitter filter.\n * To solve this, we store the `oldValue` of the watcher in the `previousValue` variable, and we\n * keep there until the watcher callback is finally executed (after the debounce). Then this\n * `previousValue` is cleared to store the next `oldValue`.\n */\n let previousValue: unknown = undefined;\n\n let watcherCallback = debounce((newValue: unknown, oldValue: unknown): void => {\n watcherEffect(newValue, oldValue);\n previousValue = undefined;\n }, 0);\n /* Only applying the extra debounce to the \"SecondLevelEvent\" events to avoid repeating outer\n * effects (requests, URL changes). If we only apply the debounce to all the events we still have\n * the problem of outer effects. */\n if (isSecondLevelEventEmitter(event)) {\n const previousCallback = watcherCallback;\n const debouncedPreviousCallback = debounce(previousCallback, 0);\n watcherCallback = ((n, o) => {\n previousCallback.cancel();\n debouncedPreviousCallback(n, o);\n }) as DebouncedFunction<any>;\n }\n\n return (newValue, oldValue) => {\n previousValue = previousValue !== undefined ? previousValue : oldValue;\n watcherCallback(newValue, previousValue);\n };\n}\n\n/**\n * Transforms a {@link AnySimpleStateSelector} into a {@link AnyStateSelector}, and sets\n * default values for its properties.\n *\n * @param stateSelector - The state selector to normalize.\n * @param event - The event name of the emitter.\n * @returns A {@link AnyStateSelector} with all the properties set.\n *\n * @internal\n */\nfunction normalizeStateSelector(\n stateSelector: AnySimpleStateSelector | AnyStateSelector,\n event: XEvent\n): Required<AnyStateSelector> {\n const normalizedSelector = isSimpleSelector(stateSelector)\n ? { selector: stateSelector }\n : stateSelector;\n return {\n deep: false,\n immediate: false,\n filter: isSecondLevelEventEmitter(event)\n ? (newValue, oldValue) => !hasPayloadChanged(newValue, oldValue)\n : () => true,\n ...normalizedSelector\n };\n}\n\n/**\n * Checks if a the type of the store emitter selector is simple or complex. This selector can be\n * a function if it is simple or an object with the selector and other options if it is complex.\n *\n * @param stateSelector - The store emitter selector.\n * @returns A boolean which flags if the stateSelector is simple (function) or complex (object).\n *\n * @internal\n */\nexport function isSimpleSelector(\n stateSelector: AnySimpleStateSelector | AnyStateSelector\n): stateSelector is AnySimpleStateSelector {\n return typeof stateSelector === 'function';\n}\n\n// TODO: Generalize the Naming of the Events to take this into account\nconst secondLevelEvents: RegExp[] = [/RequestChanged$/, /UrlStateChanged$/];\n\n/**\n * Function to detect if an {@link XEvent} is a \"SecondLevelEvent\", to treat it differently.\n *\n * @param event - The name of the {@link XEvent} to check.\n * @returns True if is an `SecondLevelEvent`, False otherwise.\n *\n * @internal\n */\nfunction isSecondLevelEventEmitter(event: XEvent): boolean {\n return secondLevelEvents.some(regex => regex.test(event));\n}\n/**\n * Function to filter if a payload of an {@link XEvent} has really changed or not. It only\n * compares the first level of fields and not deeply, to avoid CPU consuming task here.\n *\n * @param request1 - First request to compare.\n * @param request2 - Second request to compare.\n * @returns True if the two objects are different, false otherwise.\n *\n * @internal\n */\nfunction hasPayloadChanged<T extends Dictionary>(request1?: T, request2?: T): boolean {\n if (request1 === request2) {\n return true;\n }\n if (!request1 || !request2) {\n return false;\n }\n const keys1 = Object.keys(request1);\n const keys2 = Object.keys(request2);\n if (keys1.length !== keys2.length) {\n return false;\n }\n return !keys1.some(key => request1[key] !== request2[key]);\n}\n"],"names":[],"mappings":";;;;AAUA;;;;;;;;;;SAUgB,qBAAqB,CACnC,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAc,EAChD,GAAS,EACT,KAAiB;IAEjB,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACrF,OAAO,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,aAAwD;QACrF,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,sBAAsB,CACxE,aAAa,EACb,KAAK,CACN,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,QAAkB;YAC9C,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;SACxD,CAAC;QACF,MAAM,eAAe,GAAG,MAAe,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACvF,MAAM,eAAe,GAAG,q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AAC,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D;;;;"}
|
package/js/plugins/x-plugin.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { deepMerge } from '@empathyco/x-deep-merge';
|
|
2
|
+
import { forEach } from '@empathyco/x-utils';
|
|
2
3
|
import Vuex, { Store } from 'vuex';
|
|
3
4
|
import { FILTERS_REGISTRY } from '../filters/filters.registry.js';
|
|
4
5
|
import { cleanGettersProxyCache } from '../store/utils/getters-proxy.utils.js';
|
|
5
6
|
import { RootXStoreModule } from '../store/x.module.js';
|
|
6
|
-
import { forEach } from '../utils/object.js';
|
|
7
|
-
import '../utils/storage.js';
|
|
8
7
|
import { bus } from './x-bus.js';
|
|
9
8
|
import { registerStoreEmitters } from './x-emitters.js';
|
|
10
9
|
import { createXComponentAPIMixin } from './x-plugin.mixin.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x-plugin.js","sources":["../../../src/plugins/x-plugin.ts"],"sourcesContent":["import { SearchAdapter } from '@empathyco/x-adapter';\nimport { deepMerge } from '@empathyco/x-deep-merge';\nimport { PluginObject, VueConstructor } from 'vue';\nimport Vuex, { Module, Store } from 'vuex';\nimport { FILTERS_REGISTRY } from '../filters/filters.registry';\nimport { AnyXStoreModule, RootXStoreState } from '../store/store.types';\nimport { cleanGettersProxyCache } from '../store/utils/getters-proxy.utils';\nimport { RootXStoreModule } from '../store/x.module';\nimport { Dictionary, forEach } from '../utils';\nimport { AnyWire } from '../wiring/wiring.types';\nimport { AnyXModule, XModuleName } from '../x-modules/x-modules.types';\nimport { bus } from './x-bus';\nimport { XBus } from './x-bus.types';\nimport { registerStoreEmitters } from './x-emitters';\nimport { createXComponentAPIMixin } from './x-plugin.mixin';\nimport { AnyXStoreModuleOption, XModuleOptions, XPluginOptions } from './x-plugin.types';\nimport { assertXPluginOptionsAreValid } from './x-plugin.utils';\n\n/**\n * Vue plugin that initializes the properties needed by the x-components, and exposes the events bus\n * and the adapter after it has been installed.\n *\n * @public\n */\nexport class XPlugin implements PluginObject<XPluginOptions> {\n /**\n * {@link @empathyco/x-adapter#SearchAdapter | SearchAdapter} Is the middleware between\n * the components and our API where data can be mapped to client needs.\n * This property is only available after installing the plugin.\n *\n * @returns The installed adapter.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get adapter(): SearchAdapter {\n return this.getInstance().adapter;\n }\n\n /**\n * Exposed {@link XBus}, so any kind of application can subscribe to {@link XEventsTypes}\n * without having to pass through a component.\n * This property is only available after installing the plugin.\n *\n * @returns The installed bus.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get bus(): XBus {\n return this.getInstance().bus;\n }\n\n /**\n * {@link https://vuex.vuejs.org | Vuex Store} Is the place where all shared data\n * is saved.\n *\n * @returns The installed store.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get store(): Store<RootXStoreState> {\n return this.getInstance().store;\n }\n\n /**\n * Safely retrieves the installed instance of the XPlugin.\n *\n * @returns The installed instance of the XPlugin.\n * @throws If this method is called before calling `Vue.use(xPlugin)`.\n * @internal\n */\n protected static getInstance(): XPlugin {\n if (!this.instance) {\n throw Error(\"XPlugin must be installed before accessing it's API.\");\n }\n return this.instance;\n }\n\n /**\n * Record of modules that have been tried to be installed before the installation of the plugin.\n *\n * @internal\n */\n protected static pendingXModules: Partial<Record<XModuleName, AnyXModule>> = {};\n\n /**\n * Instance of the installed plugin. Used to expose the bus and the adapter.\n *\n * @internal\n */\n protected static instance?: XPlugin;\n\n /**\n * Bus for retrieving the observables when registering the wiring.\n *\n * @internal\n */\n protected bus: XBus;\n\n /**\n * Adapter for the API, responsible for transforming requests and responses.\n *\n * @internal\n */\n protected adapter!: SearchAdapter;\n\n /**\n * Set of the already installed {@link XModule | XModules} to avoid re-registering them.\n *\n * @internal\n */\n protected installedXModules = new Set<string>();\n\n /**\n * True if the plugin has been installed in a Vue instance, in this case\n * {@link XModule |Xmodules} will be installed immediately. False otherwise, in this case\n * {@link XModule | XModules} will be installed lazily when the {@link XPlugin#install} method\n * is called.\n *\n * @internal\n */\n protected isInstalled = false;\n\n /**\n * The install options of the plugin, where all the customization of\n * {@link XModule | XModules} is done.\n *\n * @internal\n */\n protected options!: XPluginOptions;\n\n /**\n * The Vuex store, to pass to the wires for its registration, and to register the store\n * modules on it.\n *\n * @internal\n */\n protected store!: Store<any>;\n /**\n * The global Vue, passed by the install method. Used to apply the global mixin\n * {@link createXComponentAPIMixin}, and install the {@link https://vuex.vuejs.org/ | Vuex}\n * plugin.\n *\n * @internal\n */\n protected vue!: VueConstructor;\n\n /**\n * Creates a new instance of the XPlugin with the given bus passed as parameter.\n *\n * @param bus - The {@link XBus} implementation to use for the plugin.\n *\n * @public\n */\n public constructor(bus: XBus) {\n this.bus = bus;\n }\n\n /**\n * If the plugin has already been installed, it immediately registers a {@link XModule}. If it\n * has not been installed yet, it stores the module in a list until the plugin is installed.\n *\n * @param xModule - The module to register.\n *\n * @public\n */\n static registerXModule(xModule: AnyXModule): void {\n if (this.instance) {\n this.instance.registerXModule(xModule);\n } else {\n this.lazyRegisterXModule(xModule);\n }\n }\n\n /**\n * Utility method for resetting the installed instance of the plugin.\n *\n * @remarks Use only for testing.\n *\n * @internal\n */\n static resetInstance(): void {\n cleanGettersProxyCache();\n this.instance = undefined;\n }\n\n /**\n * Stores the {@link XModule} in a dictionary, so it can be registered later in the install\n * process.\n *\n * @param xModule - The module to register.\n *\n * @internal\n */\n protected static lazyRegisterXModule(xModule: AnyXModule): void {\n this.pendingXModules[xModule.name] = xModule;\n }\n\n /**\n * Installs the plugin into the Vue instance.\n *\n * @param vue - The GlobalVue object.\n * @param options - The options to install this plugin with.\n * @throws If the XPlugin has already been installed, or the options are not valid.\n *\n * @internal\n */\n install(vue: VueConstructor, options?: XPluginOptions): void {\n if (this.isInstalled) {\n throw new Error('XPlugin has already been installed');\n }\n assertXPluginOptionsAreValid(options);\n XPlugin.instance = this;\n this.vue = vue;\n this.options = options;\n this.adapter = options.adapter;\n this.createAdapterConfigChangedListener();\n this.registerStore();\n this.applyMixins();\n this.registerFilters();\n this.registerInitialModules();\n this.registerPendingXModules();\n this.isInstalled = true;\n }\n\n /**\n * Performs the registration of a {@link XModule}.\n *\n * @param xModule - The module to register.\n *\n * @internal\n */\n protected registerXModule(xModule: AnyXModule): void {\n if (!this.installedXModules.has(xModule.name)) {\n const customizedXModule = this.customizeXModule(xModule);\n this.registerStoreModule(customizedXModule);\n this.registerStoreEmitters(customizedXModule);\n // The wiring must be registered after the store emitters\n // to allow lazy loaded modules work properly.\n this.registerWiring(customizedXModule);\n this.installedXModules.add(xModule.name);\n }\n }\n\n /**\n * Performs a customization of a {@link XModule} using the XPlugin public and private options.\n *\n * @param xModule - The module to customize.\n * @returns The customized xModule.\n *\n * @internal\n */\n protected customizeXModule({\n name,\n wiring,\n storeModule,\n storeEmitters,\n ...restXModule\n }: AnyXModule): AnyXModule {\n const { wiring: wiringOptions, config }: XModuleOptions<XModuleName> =\n this.options.xModules?.[name] ?? {};\n\n const { storeModule: storeModuleOptions, storeEmitters: emittersOptions } =\n this.options.__PRIVATE__xModules?.[name] ?? {};\n\n return {\n name,\n wiring: wiringOptions ? deepMerge({}, wiring, wiringOptions) : wiring,\n storeModule: this.customizeStoreModule(storeModule, storeModuleOptions ?? {}, config),\n storeEmitters: emittersOptions\n ? deepMerge({}, storeEmitters, emittersOptions)\n : storeEmitters,\n ...restXModule\n };\n }\n\n /**\n * Performs the registration of the wiring, retrieving the observable for each event, and\n * executing each wire.\n *\n * @param xModule - The {@link XModule} to register its wiring.\n *\n * @internal\n */\n protected registerWiring({ wiring }: AnyXModule): void {\n forEach(wiring, (event, wires: Dictionary<AnyWire>) => {\n // Obtain the observable\n const observable = this.bus.on(event, true);\n // Register event wires\n forEach(wires, (_, wire) => {\n wire(observable, this.store, this.bus.on.bind(this.bus));\n });\n });\n }\n\n /**\n * Registers a {@link https://vuex.vuejs.org/ | Vuex} store module under the 'x' module.\n *\n * @param xModule - The {@link XModule} to register its Store Module.\n *\n * @internal\n */\n protected registerStoreModule({ name, storeModule }: AnyXModule): void {\n (storeModule as Module<any, any>).namespaced = true;\n this.store.registerModule(['x', name], storeModule);\n }\n\n /**\n * Overrides a {@link https://vuex.vuejs.org/ | Vuex} store module definition.\n *\n * Priority of configuration merging.\n * 1st {@link XPluginOptions.xModules | xModules XPlugin option}.\n * 2nd {@link XPluginOptions.__PRIVATE__xModules | Private xModules XPlugin option}.\n * 3rd {@link XStoreModule.state | Default state of the xModule}.\n *\n * @param defaultModule - The default store module to override.\n * @param moduleOptions - The state, actions, mutations and getters to override the defaultModule.\n * @param configOptions - The state config to override the moduleOptions.\n * @returns The {@link XStoreModule} customized.\n *\n * @internal\n */\n protected customizeStoreModule(\n { state: defaultState, ...actionsGettersMutations }: AnyXStoreModule,\n { state: xModuleState, ...newActionsGettersMutations }: AnyXStoreModuleOption,\n configOptions: unknown\n ): AnyXStoreModule {\n const configOptionsObject = configOptions ? { config: configOptions } : {};\n const customizedModule = deepMerge({}, actionsGettersMutations, newActionsGettersMutations);\n customizedModule.state = deepMerge(defaultState(), xModuleState, configOptionsObject);\n return customizedModule;\n }\n\n /**\n * Registers the store emitters, making them emit the event when the part of the state selected\n * changes.\n *\n * @param xModule - The {@link XModule} to register its Store Emitters.\n *\n * @internal\n */\n protected registerStoreEmitters(xModule: AnyXModule): void {\n registerStoreEmitters(xModule, this.bus, this.store);\n }\n\n /**\n * Registers the {@link https://vuex.vuejs.org/ | Vuex} store. If the store has not been passed\n * through the {@link XPluginOptions} object, it creates one, and injects it in the Vue\n * prototype. Then it register an x module in the store, to safe scope all the\n * {@link XModule | XModules} dynamically installed.\n *\n * @internal\n */\n protected registerStore(): void {\n this.vue.use(Vuex); // We can safely install Vuex because if it is already installed Vue\n // will simply ignore it\n this.store =\n this.options.store ??\n new Store({\n strict: process.env.NODE_ENV !== 'production'\n });\n if (!this.options.store) {\n this.vue.prototype.$store = this.store;\n }\n this.store.registerModule('x', RootXStoreModule);\n }\n\n /**\n * Applies the {@link createXComponentAPIMixin} mixin in the global Vue.\n *\n * @internal\n */\n protected applyMixins(): void {\n this.vue.mixin(createXComponentAPIMixin(this.bus));\n }\n\n /**\n * Registers the initial {@link XModule | XModules} during the {@link XPlugin} installation.\n *\n * @internal\n */\n protected registerInitialModules(): void {\n this.options.initialXModules?.forEach(xModule => {\n this.registerXModule(xModule);\n });\n }\n\n /**\n * Registers the pending {@link XModule | XModules}, that requested to be registered before the\n * installation of the plugin.\n *\n * @internal\n */\n protected registerPendingXModules(): void {\n forEach(XPlugin.pendingXModules, (_, xModule) => {\n this.registerXModule(xModule);\n });\n XPlugin.pendingXModules = {};\n }\n\n /**\n * If the received adapter supports it, it registers a listener to emit the\n * {@link XEventsTypes.AdapterConfigChanged} event whenever the config of it changes.\n *\n * @internal\n */\n protected createAdapterConfigChangedListener(): void {\n this.options.adapter.addConfigChangedListener?.(newAdapterConfig => {\n this.bus.emit('AdapterConfigChanged', newAdapterConfig);\n });\n }\n\n /**\n * Registers filters globally.\n *\n * @internal\n */\n protected registerFilters(): void {\n forEach(FILTERS_REGISTRY, (filterName, filterFunction) =>\n this.vue.filter(filterName, filterFunction)\n );\n }\n}\n\n/**\n * Vue plugin that modifies each component instance, extending them with the\n * {@link XComponentAPI | X Component API }.\n *\n * @example\n * Minimal installation example. A search adapter is needed for the plugin to work, and connect to\n * the API.\n * ```typescript\n * const adapter = new EmpathyAdapterBuilder()\n * .withConfiguration({instance: 'my-instance-id'})\n * .build();\n * Vue.use(xPlugin, { adapter });\n * ```\n *\n * @example\n * If you are using {@link https://vuex.vuejs.org/ | Vuex} in your project you must install its\n * plugin, and instantiate an store before installing the XPlugin:\n * ```typescript\n * Vue.use(Vuex);\n * const store = new Store({ ... });\n * Vue.use(xPlugin, { adapter, store });\n * ```\n * @public\n */\nexport const xPlugin = new XPlugin(bus);\n"],"names":[],"mappings":";;;;;;;;;;;;AAkBA;;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,eAAe,CAAC,OAAO,CAAC,CAAC;SAC/B,CAAC,CAAC;QACH,OAAO,CAAC,eAAe,GAAG,EAAE,CAAC;KAC9B;;;;;;;IAQS,kCAAkC;QAC1C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,GAAG,gBAAgB;YAC9D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;SACzD,CAAC,CAAC;KACJ;;;;;;IAOS,eAAe;QACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,UAAU,EAAE,cAAc,KACnD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAC5C,CAAC;KACH;;AAvVD;;;;;AAKiB,uBAAe,GAA6C,EAAE,CAAC;AAqVlF;;;;;;;;;;;;;;;;;;;;;;;;MAwBa,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"x-plugin.js","sources":["../../../src/plugins/x-plugin.ts"],"sourcesContent":["import { SearchAdapter } from '@empathyco/x-adapter';\nimport { deepMerge } from '@empathyco/x-deep-merge';\nimport { forEach, Dictionary } from '@empathyco/x-utils';\nimport { PluginObject, VueConstructor } from 'vue';\nimport Vuex, { Module, Store } from 'vuex';\nimport { FILTERS_REGISTRY } from '../filters/filters.registry';\nimport { AnyXStoreModule, RootXStoreState } from '../store/store.types';\nimport { cleanGettersProxyCache } from '../store/utils/getters-proxy.utils';\nimport { RootXStoreModule } from '../store/x.module';\nimport { AnyWire } from '../wiring/wiring.types';\nimport { AnyXModule, XModuleName } from '../x-modules/x-modules.types';\nimport { bus } from './x-bus';\nimport { XBus } from './x-bus.types';\nimport { registerStoreEmitters } from './x-emitters';\nimport { createXComponentAPIMixin } from './x-plugin.mixin';\nimport { AnyXStoreModuleOption, XModuleOptions, XPluginOptions } from './x-plugin.types';\nimport { assertXPluginOptionsAreValid } from './x-plugin.utils';\n\n/**\n * Vue plugin that initializes the properties needed by the x-components, and exposes the events bus\n * and the adapter after it has been installed.\n *\n * @public\n */\nexport class XPlugin implements PluginObject<XPluginOptions> {\n /**\n * {@link @empathyco/x-adapter#SearchAdapter | SearchAdapter} Is the middleware between\n * the components and our API where data can be mapped to client needs.\n * This property is only available after installing the plugin.\n *\n * @returns The installed adapter.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get adapter(): SearchAdapter {\n return this.getInstance().adapter;\n }\n\n /**\n * Exposed {@link XBus}, so any kind of application can subscribe to {@link XEventsTypes}\n * without having to pass through a component.\n * This property is only available after installing the plugin.\n *\n * @returns The installed bus.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get bus(): XBus {\n return this.getInstance().bus;\n }\n\n /**\n * {@link https://vuex.vuejs.org | Vuex Store} Is the place where all shared data\n * is saved.\n *\n * @returns The installed store.\n * @throws If this property is accessed before calling `Vue.use(xPlugin)`.\n * @public\n */\n public static get store(): Store<RootXStoreState> {\n return this.getInstance().store;\n }\n\n /**\n * Safely retrieves the installed instance of the XPlugin.\n *\n * @returns The installed instance of the XPlugin.\n * @throws If this method is called before calling `Vue.use(xPlugin)`.\n * @internal\n */\n protected static getInstance(): XPlugin {\n if (!this.instance) {\n throw Error(\"XPlugin must be installed before accessing it's API.\");\n }\n return this.instance;\n }\n\n /**\n * Record of modules that have been tried to be installed before the installation of the plugin.\n *\n * @internal\n */\n protected static pendingXModules: Partial<Record<XModuleName, AnyXModule>> = {};\n\n /**\n * Instance of the installed plugin. Used to expose the bus and the adapter.\n *\n * @internal\n */\n protected static instance?: XPlugin;\n\n /**\n * Bus for retrieving the observables when registering the wiring.\n *\n * @internal\n */\n protected bus: XBus;\n\n /**\n * Adapter for the API, responsible for transforming requests and responses.\n *\n * @internal\n */\n protected adapter!: SearchAdapter;\n\n /**\n * Set of the already installed {@link XModule | XModules} to avoid re-registering them.\n *\n * @internal\n */\n protected installedXModules = new Set<string>();\n\n /**\n * True if the plugin has been installed in a Vue instance, in this case\n * {@link XModule |Xmodules} will be installed immediately. False otherwise, in this case\n * {@link XModule | XModules} will be installed lazily when the {@link XPlugin#install} method\n * is called.\n *\n * @internal\n */\n protected isInstalled = false;\n\n /**\n * The install options of the plugin, where all the customization of\n * {@link XModule | XModules} is done.\n *\n * @internal\n */\n protected options!: XPluginOptions;\n\n /**\n * The Vuex store, to pass to the wires for its registration, and to register the store\n * modules on it.\n *\n * @internal\n */\n protected store!: Store<any>;\n /**\n * The global Vue, passed by the install method. Used to apply the global mixin\n * {@link createXComponentAPIMixin}, and install the {@link https://vuex.vuejs.org/ | Vuex}\n * plugin.\n *\n * @internal\n */\n protected vue!: VueConstructor;\n\n /**\n * Creates a new instance of the XPlugin with the given bus passed as parameter.\n *\n * @param bus - The {@link XBus} implementation to use for the plugin.\n *\n * @public\n */\n public constructor(bus: XBus) {\n this.bus = bus;\n }\n\n /**\n * If the plugin has already been installed, it immediately registers a {@link XModule}. If it\n * has not been installed yet, it stores the module in a list until the plugin is installed.\n *\n * @param xModule - The module to register.\n *\n * @public\n */\n static registerXModule(xModule: AnyXModule): void {\n if (this.instance) {\n this.instance.registerXModule(xModule);\n } else {\n this.lazyRegisterXModule(xModule);\n }\n }\n\n /**\n * Utility method for resetting the installed instance of the plugin.\n *\n * @remarks Use only for testing.\n *\n * @internal\n */\n static resetInstance(): void {\n cleanGettersProxyCache();\n this.instance = undefined;\n }\n\n /**\n * Stores the {@link XModule} in a dictionary, so it can be registered later in the install\n * process.\n *\n * @param xModule - The module to register.\n *\n * @internal\n */\n protected static lazyRegisterXModule(xModule: AnyXModule): void {\n this.pendingXModules[xModule.name] = xModule;\n }\n\n /**\n * Installs the plugin into the Vue instance.\n *\n * @param vue - The GlobalVue object.\n * @param options - The options to install this plugin with.\n * @throws If the XPlugin has already been installed, or the options are not valid.\n *\n * @internal\n */\n install(vue: VueConstructor, options?: XPluginOptions): void {\n if (this.isInstalled) {\n throw new Error('XPlugin has already been installed');\n }\n assertXPluginOptionsAreValid(options);\n XPlugin.instance = this;\n this.vue = vue;\n this.options = options;\n this.adapter = options.adapter;\n this.createAdapterConfigChangedListener();\n this.registerStore();\n this.applyMixins();\n this.registerFilters();\n this.registerInitialModules();\n this.registerPendingXModules();\n this.isInstalled = true;\n }\n\n /**\n * Performs the registration of a {@link XModule}.\n *\n * @param xModule - The module to register.\n *\n * @internal\n */\n protected registerXModule(xModule: AnyXModule): void {\n if (!this.installedXModules.has(xModule.name)) {\n const customizedXModule = this.customizeXModule(xModule);\n this.registerStoreModule(customizedXModule);\n this.registerStoreEmitters(customizedXModule);\n // The wiring must be registered after the store emitters\n // to allow lazy loaded modules work properly.\n this.registerWiring(customizedXModule);\n this.installedXModules.add(xModule.name);\n }\n }\n\n /**\n * Performs a customization of a {@link XModule} using the XPlugin public and private options.\n *\n * @param xModule - The module to customize.\n * @returns The customized xModule.\n *\n * @internal\n */\n protected customizeXModule({\n name,\n wiring,\n storeModule,\n storeEmitters,\n ...restXModule\n }: AnyXModule): AnyXModule {\n const { wiring: wiringOptions, config }: XModuleOptions<XModuleName> =\n this.options.xModules?.[name] ?? {};\n\n const { storeModule: storeModuleOptions, storeEmitters: emittersOptions } =\n this.options.__PRIVATE__xModules?.[name] ?? {};\n\n return {\n name,\n wiring: wiringOptions ? deepMerge({}, wiring, wiringOptions) : wiring,\n storeModule: this.customizeStoreModule(storeModule, storeModuleOptions ?? {}, config),\n storeEmitters: emittersOptions\n ? deepMerge({}, storeEmitters, emittersOptions)\n : storeEmitters,\n ...restXModule\n };\n }\n\n /**\n * Performs the registration of the wiring, retrieving the observable for each event, and\n * executing each wire.\n *\n * @param xModule - The {@link XModule} to register its wiring.\n *\n * @internal\n */\n protected registerWiring({ wiring }: AnyXModule): void {\n forEach(wiring, (event, wires: Dictionary<AnyWire>) => {\n // Obtain the observable\n const observable = this.bus.on(event, true);\n // Register event wires\n forEach(wires, (_, wire) => {\n wire(observable, this.store, this.bus.on.bind(this.bus));\n });\n });\n }\n\n /**\n * Registers a {@link https://vuex.vuejs.org/ | Vuex} store module under the 'x' module.\n *\n * @param xModule - The {@link XModule} to register its Store Module.\n *\n * @internal\n */\n protected registerStoreModule({ name, storeModule }: AnyXModule): void {\n (storeModule as Module<any, any>).namespaced = true;\n this.store.registerModule(['x', name], storeModule);\n }\n\n /**\n * Overrides a {@link https://vuex.vuejs.org/ | Vuex} store module definition.\n *\n * Priority of configuration merging.\n * 1st {@link XPluginOptions.xModules | xModules XPlugin option}.\n * 2nd {@link XPluginOptions.__PRIVATE__xModules | Private xModules XPlugin option}.\n * 3rd {@link XStoreModule.state | Default state of the xModule}.\n *\n * @param defaultModule - The default store module to override.\n * @param moduleOptions - The state, actions, mutations and getters to override the defaultModule.\n * @param configOptions - The state config to override the moduleOptions.\n * @returns The {@link XStoreModule} customized.\n *\n * @internal\n */\n protected customizeStoreModule(\n { state: defaultState, ...actionsGettersMutations }: AnyXStoreModule,\n { state: xModuleState, ...newActionsGettersMutations }: AnyXStoreModuleOption,\n configOptions: unknown\n ): AnyXStoreModule {\n const configOptionsObject = configOptions ? { config: configOptions } : {};\n const customizedModule = deepMerge({}, actionsGettersMutations, newActionsGettersMutations);\n customizedModule.state = deepMerge(defaultState(), xModuleState, configOptionsObject);\n return customizedModule;\n }\n\n /**\n * Registers the store emitters, making them emit the event when the part of the state selected\n * changes.\n *\n * @param xModule - The {@link XModule} to register its Store Emitters.\n *\n * @internal\n */\n protected registerStoreEmitters(xModule: AnyXModule): void {\n registerStoreEmitters(xModule, this.bus, this.store);\n }\n\n /**\n * Registers the {@link https://vuex.vuejs.org/ | Vuex} store. If the store has not been passed\n * through the {@link XPluginOptions} object, it creates one, and injects it in the Vue\n * prototype. Then it register an x module in the store, to safe scope all the\n * {@link XModule | XModules} dynamically installed.\n *\n * @internal\n */\n protected registerStore(): void {\n this.vue.use(Vuex); // We can safely install Vuex because if it is already installed Vue\n // will simply ignore it\n this.store =\n this.options.store ??\n new Store({\n strict: process.env.NODE_ENV !== 'production'\n });\n if (!this.options.store) {\n this.vue.prototype.$store = this.store;\n }\n this.store.registerModule('x', RootXStoreModule);\n }\n\n /**\n * Applies the {@link createXComponentAPIMixin} mixin in the global Vue.\n *\n * @internal\n */\n protected applyMixins(): void {\n this.vue.mixin(createXComponentAPIMixin(this.bus));\n }\n\n /**\n * Registers the initial {@link XModule | XModules} during the {@link XPlugin} installation.\n *\n * @internal\n */\n protected registerInitialModules(): void {\n this.options.initialXModules?.forEach(xModule => {\n this.registerXModule(xModule);\n });\n }\n\n /**\n * Registers the pending {@link XModule | XModules}, that requested to be registered before the\n * installation of the plugin.\n *\n * @internal\n */\n protected registerPendingXModules(): void {\n forEach(XPlugin.pendingXModules, (_, xModule) => {\n this.registerXModule(xModule);\n });\n XPlugin.pendingXModules = {};\n }\n\n /**\n * If the received adapter supports it, it registers a listener to emit the\n * {@link XEventsTypes.AdapterConfigChanged} event whenever the config of it changes.\n *\n * @internal\n */\n protected createAdapterConfigChangedListener(): void {\n this.options.adapter.addConfigChangedListener?.(newAdapterConfig => {\n this.bus.emit('AdapterConfigChanged', newAdapterConfig);\n });\n }\n\n /**\n * Registers filters globally.\n *\n * @internal\n */\n protected registerFilters(): void {\n forEach(FILTERS_REGISTRY, (filterName, filterFunction) =>\n this.vue.filter(filterName, filterFunction)\n );\n }\n}\n\n/**\n * Vue plugin that modifies each component instance, extending them with the\n * {@link XComponentAPI | X Component API }.\n *\n * @example\n * Minimal installation example. A search adapter is needed for the plugin to work, and connect to\n * the API.\n * ```typescript\n * const adapter = new EmpathyAdapterBuilder()\n * .withConfiguration({instance: 'my-instance-id'})\n * .build();\n * Vue.use(xPlugin, { adapter });\n * ```\n *\n * @example\n * If you are using {@link https://vuex.vuejs.org/ | Vuex} in your project you must install its\n * plugin, and instantiate an store before installing the XPlugin:\n * ```typescript\n * Vue.use(Vuex);\n * const store = new Store({ ... });\n * Vue.use(xPlugin, { adapter, store });\n * ```\n * @public\n */\nexport const xPlugin = new XPlugin(bus);\n"],"names":[],"mappings":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AO;YAC1C,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;SAC/B,CAAC,CAAC;QACH,OAAO,CAAC,eAAe,GAAG,EAAE,CAAC;KAC9B;;;;;;;IAQS,kCAAkC;QAC1C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,GAAG,gBAAgB;YAC9D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;SACzD,CAAC,CAAC;KACJ;;;;;;IAOS,eAAe;QACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,UAAU,EAAE,cAAc,KACnD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAC5C,CAAC;KACH;;AAvVD;;;;;AAKiB,uBAAe,GAA6C,EAAE,CAAC;AAqVlF;;;;;;;;;;;;;;;;;;;;;;;;MAwBa,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getters-proxy.utils.js","sources":["../../../../src/store/utils/getters-proxy.utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getters-proxy.utils.js","sources":["../../../../src/store/utils/getters-proxy.utils.ts"],"sourcesContent":["import { reduce, Dictionary } from '@empathyco/x-utils';\nimport { Store } from 'vuex';\nimport { ExtractGetters, XModuleName } from '../../x-modules/x-modules.types';\nimport { AnyXStoreModule } from '../store.types';\n\ntype Getters = { [ModuleName in XModuleName]?: ExtractGetters<ModuleName> };\nlet cache: Getters = {};\n/**\n * Creates or return a proxy object of the getters of the storeModule passed.\n *\n * @param getters - The Vuex Store Getters.\n * @param moduleName - The name of the module.\n * @param storeModule - The store module.\n * @returns A {@link GettersTree} object with only the getters of the {@link XModule}.\n *\n * @internal\n *\n * @remarks This proxy will be used by the stateSelector, of the module. This is done to ensure that\n * a Vuex stateSelector can only access the getters of the {@link XModule} where it is registered.\n * This function task can be done with {@link getGettersProxy}, just without passing the\n * storeModule. But in that case every time we register emitters in a module, it will loop over all\n * the getters of all the store. This way, passing the moduleNeeded, it only loops over the getters\n * of that module. It is a performance question to have this two different implementations.\n *\n */\nexport function getGettersProxyFromModule<ModuleName extends XModuleName>(\n getters: Pick<Store<any>, 'getters'>,\n moduleName: ModuleName,\n storeModule: AnyXStoreModule\n): ExtractGetters<ModuleName> {\n /* TODO: Review why TS is not able to exclude undefined types from the Getters cache */\n const cachedGetter = cache[moduleName];\n if (isCacheGetterDefined<ModuleName>(cachedGetter)) {\n return cachedGetter;\n }\n const modulePath = `x/${moduleName}/`;\n const safeGetters = reduce(\n storeModule.getters as Dictionary,\n (safeGettersProxy, getterName) =>\n defineGetterProxy(safeGettersProxy, getterName, `${modulePath}${getterName}`, getters),\n {} as ExtractGetters<ModuleName>\n );\n cache[moduleName] = safeGetters as unknown as Getters[ModuleName];\n return safeGetters;\n}\n\n/**\n * Creates or return a proxy object of the getters of the module with the moduleName passed.\n *\n * @param getters - The Vuex Store Getters.\n * @param moduleName - The name of the module.\n * @returns A {@link GettersTree} object with only the getters of the {@link XModule}.\n *\n * @internal\n *\n * @remarks This proxy will be used wireCommit to pass the module state and getters, to a function\n * that will return the payload to commit the mutation.\n */\nexport function getGettersProxy<ModuleName extends XModuleName>(\n getters: Pick<Store<any>, 'getters'>,\n moduleName: ModuleName\n): ExtractGetters<ModuleName> {\n /* TODO: Review why TS is not able to exclude undefined types from the Getters cache */\n const cachedGetter = cache[moduleName];\n if (isCacheGetterDefined<ModuleName>(cachedGetter)) {\n return cachedGetter;\n }\n const modulePath = `x/${moduleName}/`;\n const getterKeys: string[] = Object.keys(getters).filter(getterKey =>\n getterKey.startsWith(modulePath)\n );\n const safeGetters = getterKeys.reduce((safeGettersProxy, fullPathGetterName) => {\n const getterName = fullPathGetterName.replace(modulePath, '');\n return defineGetterProxy(safeGettersProxy, getterName, fullPathGetterName, getters);\n }, {} as ExtractGetters<ModuleName>);\n cache[moduleName] = safeGetters as unknown as Getters[ModuleName];\n return safeGetters;\n}\n\n/**\n * Defines a JS getter in safeGettersProxy object that returns the Vuex getter value.\n *\n * @param safeGettersProxy - The object where the proxy will be defined.\n * @param getterName - The name of the Getter without path. For example: 'trimQuery'.\n * @param fullPathGetterName - The name of the getter to be accessed with the full path.\n * For example: 'x/searchBox/trimmedQuery'.\n * @param getters - The Vuex Store Getters.\n * @returns The same safeGetterProxy with new get defined.\n *\n * @internal\n */\nfunction defineGetterProxy<ModuleName extends XModuleName>(\n safeGettersProxy: ExtractGetters<ModuleName>,\n getterName: string,\n fullPathGetterName: string,\n getters: Dictionary\n): ExtractGetters<ModuleName> {\n return Object.defineProperty(safeGettersProxy, getterName, {\n get() {\n return getters[fullPathGetterName];\n },\n enumerable: true\n });\n}\n\n/** Clean the cache (This is for testing purpose).\n *\n * @internal\n * */\nexport function cleanGettersProxyCache(): void {\n cache = {};\n}\n\n/**\n * Checks if the getter cached is defined.\n *\n * @param cachedGetter - The getter cached.\n * @returns If the getters is defined or not.\n *\n * @internal\n */\nfunction isCacheGetterDefined<ModuleName extends XModuleName>(\n cachedGetter: ExtractGetters<ModuleName> | undefined | unknown\n): cachedGetter is ExtractGetters<ModuleName> {\n return cachedGetter !== undefined;\n}\n"],"names":[],"mappings":";;AAMA,IAAI,KAAK,GAAY,EAAE,CAAC;AACxB;;;;;;;;;;;;;;;;;;SAkBgB,yBAAyB,CACvC,OAAoC,EACpC,UAAsB,EACtB,WAA4B;;IAG5B,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,IAAI,oBAAoB,CAAa,YAAY,CAAC,EAAE;QAClD,OAAO,YAAY,CAAC;KACrB;IACD,MAAM,UAAU,GAAG,KAAK,UAAU,GAAG,CAAC;IACtC,MAAM,WAAW,GAAG,MAAM,CACxB,WAAW,CAAC,OAAqB,EACjC,CAAC,gBAAgB,EAAE,UAAU,KAC3B,iBAAiB,CAAC,gBAAgB,EAAE,UAAU,EAAE,GAAG,UAAU,GAA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