@empathyco/x-components 3.0.0-alpha.177 → 3.0.0-alpha.179
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 +26 -0
- package/core/index.js +1 -0
- package/core/index.js.map +1 -1
- package/docs/API-reference/api/x-components.installxoptions.md +1 -0
- package/docs/API-reference/api/x-components.installxoptions.oncreateapp.md +13 -0
- package/docs/API-reference/api/x-components.md +1 -0
- package/docs/API-reference/api/x-components.setupdevtools.md +27 -0
- package/docs/API-reference/api/x-components.wiremetadata.component.md +13 -0
- package/docs/API-reference/api/x-components.wiremetadata.md +1 -0
- package/docs/API-reference/api/x-components.xeventstypes.md +1 -0
- package/docs/API-reference/api/x-components.xeventstypes.moduleregistered.md +13 -0
- package/docs/API-reference/api/x-components.xplugin.wiring.md +11 -0
- package/js/index.js +1 -0
- package/js/index.js.map +1 -1
- package/js/plugins/devtools/colors.utils.js +49 -0
- package/js/plugins/devtools/colors.utils.js.map +1 -0
- package/js/plugins/devtools/devtools.plugin.js +31 -0
- package/js/plugins/devtools/devtools.plugin.js.map +1 -0
- package/js/plugins/devtools/timeline.devtools.js +98 -0
- package/js/plugins/devtools/timeline.devtools.js.map +1 -0
- package/js/plugins/devtools/wiring.devtools.js +118 -0
- package/js/plugins/devtools/wiring.devtools.js.map +1 -0
- package/js/plugins/x-bus.js +3 -1
- package/js/plugins/x-bus.js.map +1 -1
- package/js/plugins/x-plugin.js +5 -1
- package/js/plugins/x-plugin.js.map +1 -1
- package/js/plugins/x-plugin.mixin.js +9 -2
- package/js/plugins/x-plugin.mixin.js.map +1 -1
- package/js/x-installer/x-installer/x-installer.js +3 -1
- package/js/x-installer/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/facets/service/facets.service.js +6 -0
- package/js/x-modules/facets/service/facets.service.js.map +1 -1
- package/js/x-modules/next-queries/components/next-queries-list.vue.js.map +1 -1
- package/js/x-modules/next-queries/components/next-queries-list.vue_rollup-plugin-vue_script.vue.js +2 -4
- package/js/x-modules/next-queries/components/next-queries-list.vue_rollup-plugin-vue_script.vue.js.map +1 -1
- package/js/x-modules/query-suggestions/store/actions/fetch-suggestions.action.js +6 -0
- package/js/x-modules/query-suggestions/store/actions/fetch-suggestions.action.js.map +1 -1
- package/js/x-modules/recommendations/store/actions/fetch-recommendations.action.js +6 -0
- package/js/x-modules/recommendations/store/actions/fetch-recommendations.action.js.map +1 -1
- package/js/x-modules/tagging/service/pdp-add-to-cart.service.js +6 -0
- package/js/x-modules/tagging/service/pdp-add-to-cart.service.js.map +1 -1
- package/package.json +4 -3
- package/report/x-components.api.json +210 -0
- package/report/x-components.api.md +9 -1
- package/types/plugins/devtools/colors.utils.d.ts +22 -0
- package/types/plugins/devtools/colors.utils.d.ts.map +1 -0
- package/types/plugins/devtools/devtools.plugin.d.ts +12 -0
- package/types/plugins/devtools/devtools.plugin.d.ts.map +1 -0
- package/types/plugins/devtools/timeline.devtools.d.ts +20 -0
- package/types/plugins/devtools/timeline.devtools.d.ts.map +1 -0
- package/types/plugins/devtools/wiring.devtools.d.ts +21 -0
- package/types/plugins/devtools/wiring.devtools.d.ts.map +1 -0
- package/types/plugins/index.d.ts +1 -0
- package/types/plugins/index.d.ts.map +1 -1
- package/types/plugins/x-bus.d.ts +1 -1
- package/types/plugins/x-bus.d.ts.map +1 -1
- package/types/plugins/x-plugin.d.ts +3 -1
- package/types/plugins/x-plugin.d.ts.map +1 -1
- package/types/plugins/x-plugin.mixin.d.ts.map +1 -1
- package/types/router.d.ts.map +1 -1
- package/types/wiring/events.types.d.ts +7 -1
- package/types/wiring/events.types.d.ts.map +1 -1
- package/types/wiring/wiring.types.d.ts +2 -0
- package/types/wiring/wiring.types.d.ts.map +1 -1
- package/types/x-installer/x-installer/types.d.ts +6 -0
- package/types/x-installer/x-installer/types.d.ts.map +1 -1
- package/types/x-installer/x-installer/x-installer.d.ts.map +1 -1
- package/types/x-modules/next-queries/components/next-queries-list.vue.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.0-alpha.179](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.178...@empathyco/x-components@3.0.0-alpha.179) (2022-09-27)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add `vue devtools` plugin to ease `XEvents` and `wiring` visualization (#215)
|
|
11
|
+
([bd148ec](https://github.com/empathyco/x/commit/bd148ecb9682f8d4161d278c03f110f8f050d323)),
|
|
12
|
+
closes [EX-7032](https://searchbroker.atlassian.net/browse/EX-7032)
|
|
13
|
+
|
|
14
|
+
# Change Log
|
|
15
|
+
|
|
16
|
+
All notable changes to this project will be documented in this file. See
|
|
17
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
18
|
+
|
|
19
|
+
## [3.0.0-alpha.178](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.177...@empathyco/x-components@3.0.0-alpha.178) (2022-09-21)
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
- Improve `tailwindcss` types (#730)
|
|
24
|
+
([b7ab20c](https://github.com/empathyco/x/commit/b7ab20cfb0faa7f21fdf4aaaa4ae3e6d44bc6a79)),
|
|
25
|
+
closes [EX-7041](https://searchbroker.atlassian.net/browse/EX-7041)
|
|
26
|
+
|
|
27
|
+
# Change Log
|
|
28
|
+
|
|
29
|
+
All notable changes to this project will be documented in this file. See
|
|
30
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
31
|
+
|
|
6
32
|
## [3.0.0-alpha.177](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.176...@empathyco/x-components@3.0.0-alpha.177) (2022-09-21)
|
|
7
33
|
|
|
8
34
|
### Features
|
package/core/index.js
CHANGED
|
@@ -128,6 +128,7 @@ export { ItemsListInjectionMixin } from '../js/components/items-list-injection.m
|
|
|
128
128
|
export { xComponentMixin } from '../js/components/x-component.mixin.js';
|
|
129
129
|
export { getXComponentXModuleName, isXComponent } from '../js/components/x-component.utils.js';
|
|
130
130
|
export { infiniteScroll } from '../js/directives/infinite-scroll/infinite-scroll.js';
|
|
131
|
+
export { setupDevtools } from '../js/plugins/devtools/devtools.plugin.js';
|
|
131
132
|
export { BaseXBus, bus } from '../js/plugins/x-bus.js';
|
|
132
133
|
export { XPlugin, xPlugin } from '../js/plugins/x-plugin.js';
|
|
133
134
|
export { createXComponentAPIMixin, getBusAPI, getRootXComponent } from '../js/plugins/x-plugin.mixin.js';
|
package/core/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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -21,6 +21,7 @@ export interface InstallXOptions<API extends XAPI = XAPI> extends XPluginOptions
|
|
|
21
21
|
| [app?](./x-components.installxoptions.app.md) | VueConstructor \| ComponentOptions<Vue> | <i>(Optional)</i> The Vue component used as root of the application. If it is not passed, no Vue Application is initialized, only plugin installed. |
|
|
22
22
|
| [bus?](./x-components.installxoptions.bus.md) | [XBus](./x-components.xbus.md) | <i>(Optional)</i> The [XBus](./x-components.xbus.md) used in the [XPlugin](./x-components.xplugin.md)<!-- -->. If not passed an instance of [BaseXBus](./x-components.basexbus.md) will be used. |
|
|
23
23
|
| [domElement?](./x-components.installxoptions.domelement.md) | Element \| string | <i>(Optional)</i> An Element \| string to indicate the HTML element that will contain the Vue application. If string selector is passed and the element doesn't exits, the [XInstaller](./x-components.xinstaller.md) will create it. |
|
|
24
|
+
| [onCreateApp?](./x-components.installxoptions.oncreateapp.md) | (app: Vue) => void | <i>(Optional)</i> Callback to invoke after instantiating the app. |
|
|
24
25
|
| [plugin?](./x-components.installxoptions.plugin.md) | PluginObject<[XPluginOptions](./x-components.xpluginoptions.md)<!-- -->> | <i>(Optional)</i> The XPlugin which will be installed. If not passed, an instance of [XPlugin](./x-components.xplugin.md) will be installed. |
|
|
25
26
|
| [vue?](./x-components.installxoptions.vue.md) | VueConstructor | <i>(Optional)</i> The Vue instance used to install the plugin and to create the Application. If not passed the default Vue instance is used. This can be useful to use the <code>localVue</code> in the unit tests. |
|
|
26
27
|
| [vueOptions?](./x-components.installxoptions.vueoptions.md) | [VueConstructorPartialArgument](./x-components.vueconstructorpartialargument.md) | <i>(Optional)</i> This object can contain any option to pass to Vue instance at the moment of creating the App instance. |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [InstallXOptions](./x-components.installxoptions.md) > [onCreateApp](./x-components.installxoptions.oncreateapp.md)
|
|
4
|
+
|
|
5
|
+
## InstallXOptions.onCreateApp property
|
|
6
|
+
|
|
7
|
+
Callback to invoke after instantiating the app.
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
onCreateApp?: (app: Vue) => void;
|
|
13
|
+
```
|
|
@@ -191,6 +191,7 @@ X-Components is a library usable everywhere not only for search experiences.
|
|
|
191
191
|
| [namespacedWireDispatchWithoutPayload(moduleName)](./x-components.namespacedwiredispatchwithoutpayload.md) | Creates a namespaced [wireDispatchWithoutPayload()](./x-components.wiredispatchwithoutpayload.md) for the module name passed. |
|
|
192
192
|
| [normalizeString(string)](./x-components.normalizestring.md) | Trims the string, transforms it to lower case, and removes [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) from it. |
|
|
193
193
|
| [setStatus(state, status)](./x-components.setstatus.md) | Sets the request status. Can be used as a mutation. |
|
|
194
|
+
| [setupDevtools(app)](./x-components.setupdevtools.md) | <b><i>(BETA)</i></b> Setups a plugin for the Vue's devtools adding: - [XEvent](./x-components.xevent.md)<!-- -->s timeline. Every event is recorded in time, and its payload and metadata can be inspected. - Wiring inspector. Events and its wires can be viewed and disabled. |
|
|
194
195
|
| [State(module, path)](./x-components.state.md) | Generates a computed property which returns the selected state.<!-- -->The decorated property needs to be public for type inference to work. |
|
|
195
196
|
| [throttle(wire, timeInMs, options)](./x-components.throttle.md) | Creates a throttled [Wire](./x-components.wire.md)<!-- -->. Being throttled means that it will only be executed once every couple of milliseconds given by the <code>timeInMs</code> parameter. |
|
|
196
197
|
| [toKebabCase(str)](./x-components.tokebabcase.md) | Util to transform string a into kebab case. |
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [setupDevtools](./x-components.setupdevtools.md)
|
|
4
|
+
|
|
5
|
+
## setupDevtools() function
|
|
6
|
+
|
|
7
|
+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
|
|
8
|
+
>
|
|
9
|
+
|
|
10
|
+
Setups a plugin for the Vue's devtools adding: - [XEvent](./x-components.xevent.md)<!-- -->s timeline. Every event is recorded in time, and its payload and metadata can be inspected. - Wiring inspector. Events and its wires can be viewed and disabled.
|
|
11
|
+
|
|
12
|
+
<b>Signature:</b>
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
export declare function setupDevtools(app: Vue): void;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| app | Vue | The Vue application the devtools should track. |
|
|
23
|
+
|
|
24
|
+
<b>Returns:</b>
|
|
25
|
+
|
|
26
|
+
void
|
|
27
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [WireMetadata](./x-components.wiremetadata.md) > [component](./x-components.wiremetadata.component.md)
|
|
4
|
+
|
|
5
|
+
## WireMetadata.component property
|
|
6
|
+
|
|
7
|
+
The component instance that triggered the event emission.
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
component?: Vue;
|
|
13
|
+
```
|
|
@@ -16,6 +16,7 @@ export interface WireMetadata
|
|
|
16
16
|
|
|
17
17
|
| Property | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
|
+
| [component?](./x-components.wiremetadata.component.md) | Vue | <i>(Optional)</i> The component instance that triggered the event emission. |
|
|
19
20
|
| [feature?](./x-components.wiremetadata.feature.md) | [QueryFeature](./x-components.queryfeature.md) | <i>(Optional)</i> The [QueryFeature](./x-components.queryfeature.md) that originated the event. |
|
|
20
21
|
| [id?](./x-components.wiremetadata.id.md) | string | <i>(Optional)</i> The id of the component origin. |
|
|
21
22
|
| [location?](./x-components.wiremetadata.location.md) | [FeatureLocation](./x-components.featurelocation.md) | <i>(Optional)</i> The [FeatureLocation](./x-components.featurelocation.md) from where the event has been emitted. |
|
|
@@ -22,6 +22,7 @@ Aside from common [XEvents](./x-components.xevent.md)<!-- -->, this interface al
|
|
|
22
22
|
| Property | Type | Description |
|
|
23
23
|
| --- | --- | --- |
|
|
24
24
|
| [ColumnsNumberProvided](./x-components.xeventstypes.columnsnumberprovided.md) | number | The number of columns of a grid has changed. Payload: the columns number. |
|
|
25
|
+
| [ModuleRegistered](./x-components.xeventstypes.moduleregistered.md) | [XModuleName](./x-components.xmodulename.md) | A new [XModule](./x-components.xmodule.md) has been registered. Payload: The name of the XModule that has been registered. |
|
|
25
26
|
| [SnippetCallbackExecuted](./x-components.xeventstypes.snippetcallbackexecuted.md) | { event: [XEvent](./x-components.xevent.md)<!-- -->; callbackReturn: unknown; payload: [ExtractPayload](./x-components.extractpayload.md)<!-- --><[XEvent](./x-components.xevent.md)<!-- -->>; metadata: [WireMetadata](./x-components.wiremetadata.md)<!-- -->; } | A callback from the snippet has been executed. Payload: An object containing the event that executed the callback, the callback result, and the original event payload and metadata. |
|
|
26
27
|
| [SuggestionsDisplayed](./x-components.xeventstypes.suggestionsdisplayed.md) | Suggestion\[\] | Any kind of suggestions have been displayed (query-suggestions, popular searches...) Payload: The displayed [suggestions](./x-types.suggestion.md)<!-- -->. |
|
|
27
28
|
| [TogglePanelStateChanged](./x-components.xeventstypes.togglepanelstatechanged.md) | boolean | The <code>BaseToggleIdPanel</code> <code>isOpen</code> state changed. Payload: the new state. |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [XEventsTypes](./x-components.xeventstypes.md) > [ModuleRegistered](./x-components.xeventstypes.moduleregistered.md)
|
|
4
|
+
|
|
5
|
+
## XEventsTypes.ModuleRegistered property
|
|
6
|
+
|
|
7
|
+
A new [XModule](./x-components.xmodule.md) has been registered. Payload: The name of the XModule that has been registered.
|
|
8
|
+
|
|
9
|
+
<b>Signature:</b>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
ModuleRegistered: XModuleName;
|
|
13
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [XPlugin](./x-components.xplugin.md) > [wiring](./x-components.xplugin.wiring.md)
|
|
4
|
+
|
|
5
|
+
## XPlugin.wiring property
|
|
6
|
+
|
|
7
|
+
<b>Signature:</b>
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
wiring: Partial<Record<XModuleName, Partial<Record<XEvent, string[]>>>>;
|
|
11
|
+
```
|
package/js/index.js
CHANGED
|
@@ -128,6 +128,7 @@ export { ItemsListInjectionMixin } from './components/items-list-injection.mixin
|
|
|
128
128
|
export { xComponentMixin } from './components/x-component.mixin.js';
|
|
129
129
|
export { getXComponentXModuleName, isXComponent } from './components/x-component.utils.js';
|
|
130
130
|
export { infiniteScroll } from './directives/infinite-scroll/infinite-scroll.js';
|
|
131
|
+
export { setupDevtools } from './plugins/devtools/devtools.plugin.js';
|
|
131
132
|
export { BaseXBus, bus } from './plugins/x-bus.js';
|
|
132
133
|
export { XPlugin, xPlugin } from './plugins/x-plugin.js';
|
|
133
134
|
export { createXComponentAPIMixin, getBusAPI, getRootXComponent } from './plugins/x-plugin.mixin.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { map } from '@empathyco/x-utils';
|
|
2
|
+
import { RootXStoreModule } from '../../store/x.module.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unique color values for the text and background of each module.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
const moduleColors = createModuleColors();
|
|
10
|
+
/**
|
|
11
|
+
* Creates a dictionary with unique colors for each {@link XModule}.
|
|
12
|
+
*
|
|
13
|
+
* @returns A dictionary with unique text and background colors for every {@link XModule}.
|
|
14
|
+
*/
|
|
15
|
+
function createModuleColors() {
|
|
16
|
+
const xState = RootXStoreModule.state();
|
|
17
|
+
const modulesCount = Object.keys(xState).length;
|
|
18
|
+
return map(xState, (moduleName, _, index) => {
|
|
19
|
+
const hue = Math.trunc((index * 360) / modulesCount);
|
|
20
|
+
return {
|
|
21
|
+
textColor: hslToHex(hue, 30, 97.5),
|
|
22
|
+
backgroundColor: hslToHex(hue, 80, 35)
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Transforms HSL values into a hex number.
|
|
28
|
+
*
|
|
29
|
+
* @param hue - The hue value, from 0 to 360.
|
|
30
|
+
* @param saturation - The saturation value, from 0 to 100.
|
|
31
|
+
* @param lightness - The lightness value, from 0 to 100.
|
|
32
|
+
* @returns The hex value of the color.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
function hslToHex(hue, saturation, lightness) {
|
|
36
|
+
lightness /= 100;
|
|
37
|
+
const a = (saturation * Math.min(lightness, 1 - lightness)) / 100;
|
|
38
|
+
const f = (n) => {
|
|
39
|
+
const k = (n + hue / 30) % 12;
|
|
40
|
+
const color = lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
41
|
+
return Math.round(255 * color)
|
|
42
|
+
.toString(16)
|
|
43
|
+
.padStart(2, '0');
|
|
44
|
+
};
|
|
45
|
+
return parseInt(`${f(0)}${f(8)}${f(4)}`, 16);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { hslToHex, moduleColors };
|
|
49
|
+
//# sourceMappingURL=colors.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.utils.js","sources":["../../../../src/plugins/devtools/colors.utils.ts"],"sourcesContent":["import { InspectorNodeTag } from '@vue/devtools-api';\nimport { map } from '@empathyco/x-utils';\nimport { RootXStoreModule, XModuleState } from '../../store/x.module';\nimport { XModuleName } from '../../x-modules/x-modules.types';\n\n/** Unique text and background colors for each module. */\ntype ModuleColors = Record<XModuleName, Pick<InspectorNodeTag, 'textColor' | 'backgroundColor'>>;\n/**\n * Unique color values for the text and background of each module.\n *\n * @internal\n */\nexport const moduleColors = createModuleColors();\n\n/**\n * Creates a dictionary with unique colors for each {@link XModule}.\n *\n * @returns A dictionary with unique text and background colors for every {@link XModule}.\n */\nfunction createModuleColors(): ModuleColors {\n const xState = (RootXStoreModule.state as () => XModuleState)();\n const modulesCount = Object.keys(xState).length;\n return map(xState, (moduleName, _, index) => {\n const hue = Math.trunc((index * 360) / modulesCount);\n return {\n textColor: hslToHex(hue, 30, 97.5),\n backgroundColor: hslToHex(hue, 80, 35)\n };\n });\n}\n\n/**\n * Transforms HSL values into a hex number.\n *\n * @param hue - The hue value, from 0 to 360.\n * @param saturation - The saturation value, from 0 to 100.\n * @param lightness - The lightness value, from 0 to 100.\n * @returns The hex value of the color.\n * @internal\n */\nexport function hslToHex(hue: number, saturation: number, lightness: number): number {\n lightness /= 100;\n const a = (saturation * Math.min(lightness, 1 - lightness)) / 100;\n const f = (n: number): string => {\n const k = (n + hue / 30) % 12;\n const color = lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return Math.round(255 * color)\n .toString(16)\n .padStart(2, '0');\n };\n return parseInt(`${f(0)}${f(8)}${f(4)}`, 16);\n}\n"],"names":[],"mappings":";;;AAOA;;;;;MAKa,YAAY,GAAG,kBAAkB,GAAG;AAEjD;;;;;AAKA,SAAS,kBAAkB;IACzB,MAAM,MAAM,GAAI,gBAAgB,CAAC,KAA4B,EAAE,CAAC;IAChE,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAChD,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,GAAG,IAAI,YAAY,CAAC,CAAC;QACrD,OAAO;YACL,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC;YAClC,eAAe,EAAE,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC;SACvC,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;SASgB,QAAQ,CAAC,GAAW,EAAE,UAAkB,EAAE,SAAiB;IACzE,SAAS,IAAI,GAAG,CAAC;IACjB,MAAM,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,IAAI,GAAG,CAAC;IAClE,MAAM,CAAC,GAAG,CAAC,CAAS;QAClB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,IAAI,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC;aAC3B,QAAQ,CAAC,EAAE,CAAC;aACZ,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACrB,CAAC;IACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC/C;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { setupDevtoolsPlugin } from '@vue/devtools-api';
|
|
2
|
+
import { setupTimelinePlugin } from './timeline.devtools.js';
|
|
3
|
+
import { setupWiringDevtools } from './wiring.devtools.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Setups a plugin for the Vue's devtools adding:
|
|
7
|
+
* - {@link XEvent}s timeline. Every event is recorded in time, and its payload and metadata can be
|
|
8
|
+
* inspected.
|
|
9
|
+
* - Wiring inspector. Events and its wires can be viewed and disabled.
|
|
10
|
+
*
|
|
11
|
+
* @param app - The Vue application the devtools should track.
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
function setupDevtools(app) {
|
|
15
|
+
setupDevtoolsPlugin({
|
|
16
|
+
id: 'x-components-devtools-plugin',
|
|
17
|
+
label: 'X Components',
|
|
18
|
+
packageName: '@empathyco/x-components',
|
|
19
|
+
homepage: 'https://empathy.co',
|
|
20
|
+
enableEarlyProxy: true,
|
|
21
|
+
app: app // FIXME: Infinite loop with types when inferred as a Vue2 app.
|
|
22
|
+
}, api => {
|
|
23
|
+
if (api) {
|
|
24
|
+
setupTimelinePlugin(api);
|
|
25
|
+
setupWiringDevtools(api);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { setupDevtools };
|
|
31
|
+
//# sourceMappingURL=devtools.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.plugin.js","sources":["../../../../src/plugins/devtools/devtools.plugin.ts"],"sourcesContent":["import { setupDevtoolsPlugin, App } from '@vue/devtools-api';\nimport Vue from 'vue';\nimport { setupTimelinePlugin } from './timeline.devtools';\nimport { setupWiringDevtools } from './wiring.devtools';\n\n/**\n * Setups a plugin for the Vue's devtools adding:\n * - {@link XEvent}s timeline. Every event is recorded in time, and its payload and metadata can be\n * inspected.\n * - Wiring inspector. Events and its wires can be viewed and disabled.\n *\n * @param app - The Vue application the devtools should track.\n * @beta\n */\nexport function setupDevtools(app: Vue): void {\n setupDevtoolsPlugin(\n {\n id: 'x-components-devtools-plugin',\n label: 'X Components',\n packageName: '@empathyco/x-components',\n homepage: 'https://empathy.co',\n enableEarlyProxy: true,\n app: app as App // FIXME: Infinite loop with types when inferred as a Vue2 app.\n },\n api => {\n if (api) {\n setupTimelinePlugin(api);\n setupWiringDevtools(api);\n }\n }\n );\n}\n"],"names":[],"mappings":";;;;AAKA;;;;;;;;;SASgB,aAAa,CAAC,GAAQ;IACpC,mBAAmB,CACjB;QACE,EAAE,EAAE,8BAA8B;QAClC,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,yBAAyB;QACtC,QAAQ,EAAE,oBAAoB;QAC9B,gBAAgB,EAAE,IAAI;QACtB,GAAG,EAAE,GAAU;KAChB,EACD,GAAG;QACD,IAAI,GAAG,EAAE;YACP,mBAAmB,CAAC,GAAG,CAAC,CAAC;YACzB,mBAAmB,CAAC,GAAG,CAAC,CAAC;SAC1B;KACF,CACF,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { hslToHex } from './colors.utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Contains the devtools API.
|
|
5
|
+
*/
|
|
6
|
+
let devtoolsAPI;
|
|
7
|
+
/**
|
|
8
|
+
* List of all the configured timeline layers for {@link XEvent}s.
|
|
9
|
+
*/
|
|
10
|
+
const timelineLayers = [
|
|
11
|
+
{
|
|
12
|
+
id: 'x-components-module-registered-events',
|
|
13
|
+
regex: /^ModuleRegistered$/,
|
|
14
|
+
label: 'X registered modules'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: 'x-components-user-events',
|
|
18
|
+
regex: /^User/,
|
|
19
|
+
label: 'X user events'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'x-components-request-events',
|
|
23
|
+
regex: /RequestChanged$/,
|
|
24
|
+
label: 'X request events'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'x-components-status-change-events',
|
|
28
|
+
regex: /Changed$/,
|
|
29
|
+
label: 'X status change events'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'x-components-miscellanea-events',
|
|
33
|
+
regex: /.*/,
|
|
34
|
+
label: 'X miscellanea events'
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
/** Set containing the different layer ids. */
|
|
38
|
+
const layerIds = new Set(timelineLayers.map(layer => layer.id));
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the timeline layer that an {@link XEvent} belongs to.
|
|
41
|
+
*
|
|
42
|
+
* @param event - The {@link XEvent} to retrieve its layer id.
|
|
43
|
+
* @returns The layer id for the {@link XEvent}.
|
|
44
|
+
*/
|
|
45
|
+
function getTimelineLayer(event) {
|
|
46
|
+
return timelineLayers.find(layer => layer.regex.test(event)).id;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Configures Vue's devtools timeline with new rows for {@link XEvent}s.
|
|
50
|
+
*
|
|
51
|
+
* @param api - Vue's devtools API.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function setupTimelinePlugin(api) {
|
|
55
|
+
devtoolsAPI = api;
|
|
56
|
+
timelineLayers.forEach(layer => api.addTimelineLayer({
|
|
57
|
+
id: layer.id,
|
|
58
|
+
label: layer.label,
|
|
59
|
+
color: hslToHex(329, 100, 50)
|
|
60
|
+
}));
|
|
61
|
+
api.on.inspectTimelineEvent(payload => {
|
|
62
|
+
if (layerIds.has(payload.layerId)) {
|
|
63
|
+
const component = payload.event.data.metadata.component;
|
|
64
|
+
if (component) {
|
|
65
|
+
api.highlightElement(component);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sends the emission of an {@link XEvent} to the devtools.
|
|
72
|
+
*
|
|
73
|
+
* @param event - The emitted {@link XEvent}.
|
|
74
|
+
* @param value - An object containing both the event payload and its metadata.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function logDevtoolsXEvent(event, value) {
|
|
78
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
79
|
+
devtoolsAPI?.addTimelineEvent({
|
|
80
|
+
event: {
|
|
81
|
+
title: event,
|
|
82
|
+
data: {
|
|
83
|
+
...value,
|
|
84
|
+
metadata: {
|
|
85
|
+
...value.metadata,
|
|
86
|
+
// FIX-ME: copying metadata.component as it is defined as a non-enumerable property.
|
|
87
|
+
component: value.metadata.component
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
time: devtoolsAPI?.now()
|
|
91
|
+
},
|
|
92
|
+
layerId: getTimelineLayer(event)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { logDevtoolsXEvent, setupTimelinePlugin };
|
|
98
|
+
//# sourceMappingURL=timeline.devtools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.devtools.js","sources":["../../../../src/plugins/devtools/timeline.devtools.ts"],"sourcesContent":["import { DevtoolsPluginApi } from '@vue/devtools-api';\nimport { Dictionary } from '@empathyco/x-utils';\nimport { XEvent, XEventPayload } from '../../wiring/events.types';\nimport { WirePayload } from '../../wiring/wiring.types';\nimport { hslToHex } from './colors.utils';\n\n/**\n * Contains the devtools API.\n */\nlet devtoolsAPI: DevtoolsPluginApi<Dictionary> | undefined;\n\n/**\n * List of all the configured timeline layers for {@link XEvent}s.\n */\nconst timelineLayers = [\n {\n id: 'x-components-module-registered-events',\n regex: /^ModuleRegistered$/,\n label: 'X registered modules'\n },\n {\n id: 'x-components-user-events',\n regex: /^User/,\n label: 'X user events'\n },\n\n {\n id: 'x-components-request-events',\n regex: /RequestChanged$/,\n label: 'X request events'\n },\n {\n id: 'x-components-status-change-events',\n regex: /Changed$/,\n label: 'X status change events'\n },\n {\n id: 'x-components-miscellanea-events',\n regex: /.*/,\n label: 'X miscellanea events'\n }\n];\n\n/** Set containing the different layer ids. */\nconst layerIds = new Set(timelineLayers.map(layer => layer.id));\n\n/**\n * Retrieves the timeline layer that an {@link XEvent} belongs to.\n *\n * @param event - The {@link XEvent} to retrieve its layer id.\n * @returns The layer id for the {@link XEvent}.\n */\nfunction getTimelineLayer(event: XEvent): string {\n return timelineLayers.find(layer => layer.regex.test(event))!.id;\n}\n\n/**\n * Configures Vue's devtools timeline with new rows for {@link XEvent}s.\n *\n * @param api - Vue's devtools API.\n * @internal\n */\nexport function setupTimelinePlugin(api: DevtoolsPluginApi<Dictionary>): void {\n devtoolsAPI = api;\n timelineLayers.forEach(layer =>\n api.addTimelineLayer({\n id: layer.id,\n label: layer.label,\n color: hslToHex(329, 100, 50)\n })\n );\n api.on.inspectTimelineEvent(payload => {\n if (layerIds.has(payload.layerId)) {\n const component = (<WirePayload<unknown>>payload.event.data).metadata.component;\n if (component) {\n api.highlightElement(component);\n }\n }\n });\n}\n\n/**\n * Sends the emission of an {@link XEvent} to the devtools.\n *\n * @param event - The emitted {@link XEvent}.\n * @param value - An object containing both the event payload and its metadata.\n * @internal\n */\nexport function logDevtoolsXEvent<Event extends XEvent>(\n event: Event,\n value: WirePayload<XEventPayload<Event>>\n): void {\n if (process.env.NODE_ENV !== 'production') {\n devtoolsAPI?.addTimelineEvent({\n event: {\n title: event,\n data: {\n ...value,\n metadata: {\n ...value.metadata,\n // FIX-ME: copying metadata.component as it is defined as a non-enumerable property.\n component: value.metadata.component\n }\n },\n time: devtoolsAPI?.now()\n },\n layerId: getTimelineLayer(event)\n });\n }\n}\n"],"names":[],"mappings":";;AAMA;;;AAGA,IAAI,WAAsD,CAAC;AAE3D;;;AAGA,MAAM,cAAc,GAAG;IACrB;QACE,EAAE,EAAE,uCAAuC;QAC3C,KAAK,EAAE,oBAAoB;QAC3B,KAAK,EAAE,sBAAsB;KAC9B;IACD;QACE,EAAE,EAAE,0BAA0B;QAC9B,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,eAAe;KACvB;IAED;QACE,EAAE,EAAE,6BAA6B;QACjC,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,kBAAkB;KAC1B;IACD;QACE,EAAE,EAAE,mCAAmC;QACvC,KAAK,EAAE,UAAU;QACjB,KAAK,EAAE,wBAAwB;KAChC;IACD;QACE,EAAE,EAAE,iCAAiC;QACrC,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,sBAAsB;KAC9B;CACF,CAAC;AAEF;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAEhE;;;;;;AAMA,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAE,CAAC,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;SAMgB,mBAAmB,CAAC,GAAkC;IACpE,WAAW,GAAG,GAAG,CAAC;IAClB,cAAc,CAAC,OAAO,CAAC,KAAK,IAC1B,GAAG,CAAC,gBAAgB,CAAC;QACnB,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;KAC9B,CAAC,CACH,CAAC;IACF,GAAG,CAAC,EAAE,CAAC,oBAAoB,CAAC,OAAO;QACjC,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACjC,MAAM,SAAS,GAA0B,OAAO,CAAC,KAAK,CAAC,IAAK,CAAC,QAAQ,CAAC,SAAS,CAAC;YAChF,IAAI,SAAS,EAAE;gBACb,GAAG,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;aACjC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;SAOgB,iBAAiB,CAC/B,KAAY,EACZ,KAAwC;IAExC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,WAAW,EAAE,gBAAgB,CAAC;YAC5B,KAAK,EAAE;gBACL,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE;oBACJ,GAAG,KAAK;oBACR,QAAQ,EAAE;wBACR,GAAG,KAAK,CAAC,QAAQ;;wBAEjB,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,SAAS;qBACpC;iBACF;gBACD,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;aACzB;YACD,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC;SACjC,CAAC,CAAC;KACJ;AACH;;;;"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { reduce, forEach } from '@empathyco/x-utils';
|
|
2
|
+
import { filter } from '../../wiring/wires.operators.js';
|
|
3
|
+
import { moduleColors, hslToHex } from './colors.utils.js';
|
|
4
|
+
|
|
5
|
+
/** The full list of wiring nodes for the inspector. */
|
|
6
|
+
const wiringNodes = {};
|
|
7
|
+
/**
|
|
8
|
+
* Record of the wires enabled/disabled status.
|
|
9
|
+
*/
|
|
10
|
+
const wiresStatus = {};
|
|
11
|
+
/**
|
|
12
|
+
* Creates tags given a node representing a wire.
|
|
13
|
+
*
|
|
14
|
+
* @param node - The inspector node representing a {@link Wire}.
|
|
15
|
+
* @returns A list of tags for the given node.
|
|
16
|
+
*/
|
|
17
|
+
function createWireTags({ tags = [], id }) {
|
|
18
|
+
const newTags = [...tags];
|
|
19
|
+
if (!wiresStatus[id]) {
|
|
20
|
+
newTags.push({
|
|
21
|
+
label: 'disabled',
|
|
22
|
+
backgroundColor: hslToHex(0, 88, 30),
|
|
23
|
+
textColor: hslToHex(0, 84, 90)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return newTags;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Setups an inspector in Vue's devtools to show the wiring.
|
|
30
|
+
*
|
|
31
|
+
* @param api - Vue's devtools API.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
function setupWiringDevtools(api) {
|
|
35
|
+
const inspectorId = 'wiring-inspector';
|
|
36
|
+
api.addInspector({
|
|
37
|
+
id: inspectorId,
|
|
38
|
+
label: 'X-Components Wiring'
|
|
39
|
+
});
|
|
40
|
+
api.on.getInspectorTree(payload => {
|
|
41
|
+
if (payload.inspectorId !== inspectorId) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const query = payload.filter.toLowerCase();
|
|
45
|
+
payload.rootNodes = reduce(wiringNodes, (nodes, event, eventWires) => {
|
|
46
|
+
const wiresNodes =
|
|
47
|
+
/* If there is no active search, or the event name includes the query, we include all the
|
|
48
|
+
available wires. */
|
|
49
|
+
!query || event.toLowerCase().includes(query)
|
|
50
|
+
? eventWires
|
|
51
|
+
: eventWires.filter(node => node.label.toLowerCase().includes(payload.filter.toLowerCase()));
|
|
52
|
+
if (wiresNodes.length) {
|
|
53
|
+
nodes.push({
|
|
54
|
+
id: event,
|
|
55
|
+
label: event,
|
|
56
|
+
children: wiresNodes.map(wireNode => ({
|
|
57
|
+
...wireNode,
|
|
58
|
+
tags: createWireTags(wireNode)
|
|
59
|
+
}))
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return nodes;
|
|
63
|
+
}, []);
|
|
64
|
+
});
|
|
65
|
+
api.on.getInspectorState(payload => {
|
|
66
|
+
if (payload.inspectorId !== inspectorId) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
payload.state = {
|
|
70
|
+
status: [
|
|
71
|
+
{
|
|
72
|
+
key: 'enabled',
|
|
73
|
+
value: wiresStatus[payload.nodeId],
|
|
74
|
+
editable: true
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
api.on.editInspectorState(payload => {
|
|
80
|
+
if (payload.inspectorId === inspectorId) {
|
|
81
|
+
wiresStatus[payload.nodeId] = payload.state.value;
|
|
82
|
+
api.sendInspectorTree(inspectorId);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sends the module wiring to Vue's devtools inspector. Additionally, it modifies each wire, adding
|
|
88
|
+
* a filter function to let it be enabled/disabled from the devtools.
|
|
89
|
+
*
|
|
90
|
+
* @param module - The module name this wiring belongs too.
|
|
91
|
+
* @param wiring - The wiring to save.
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
function sendWiringToDevtools(module, wiring) {
|
|
95
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
96
|
+
forEach(wiring, (event, wires) => {
|
|
97
|
+
const eventWiring = wiringNodes[event] ?? (wiringNodes[event] = []);
|
|
98
|
+
forEach(wires, (wireName, wire) => {
|
|
99
|
+
const id = `${module}-${event}-${wireName}`;
|
|
100
|
+
wiresStatus[id] = true;
|
|
101
|
+
wires[wireName] = filter(wire, () => wiresStatus[id]);
|
|
102
|
+
eventWiring.push({
|
|
103
|
+
id,
|
|
104
|
+
label: wireName,
|
|
105
|
+
tags: [
|
|
106
|
+
{
|
|
107
|
+
label: module,
|
|
108
|
+
...moduleColors[module]
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { sendWiringToDevtools, setupWiringDevtools };
|
|
118
|
+
//# sourceMappingURL=wiring.devtools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiring.devtools.js","sources":["../../../../src/plugins/devtools/wiring.devtools.ts"],"sourcesContent":["import { Dictionary, forEach, reduce } from '@empathyco/x-utils';\nimport { CustomInspectorNode, DevtoolsPluginApi, InspectorNodeTag } from '@vue/devtools-api';\nimport { XEvent } from '../../wiring/events.types';\nimport { filter } from '../../wiring/wires.operators';\nimport { AnyWire, Wiring } from '../../wiring/wiring.types';\nimport { XModuleName } from '../../x-modules/x-modules.types';\nimport { hslToHex, moduleColors } from './colors.utils';\n\n/** The full list of wiring nodes for the inspector. */\nconst wiringNodes: Partial<Record<XEvent, CustomInspectorNode[]>> = {};\n/**\n * Record of the wires enabled/disabled status.\n */\nconst wiresStatus: Record<string, boolean> = {};\n\n/**\n * Creates tags given a node representing a wire.\n *\n * @param node - The inspector node representing a {@link Wire}.\n * @returns A list of tags for the given node.\n */\nfunction createWireTags({ tags = [], id }: CustomInspectorNode): InspectorNodeTag[] {\n const newTags: InspectorNodeTag[] = [...tags];\n if (!wiresStatus[id]) {\n newTags.push({\n label: 'disabled',\n backgroundColor: hslToHex(0, 88, 30),\n textColor: hslToHex(0, 84, 90)\n });\n }\n return newTags;\n}\n\n/**\n * Setups an inspector in Vue's devtools to show the wiring.\n *\n * @param api - Vue's devtools API.\n * @internal\n */\nexport function setupWiringDevtools(api: DevtoolsPluginApi<Dictionary<unknown>>): void {\n const inspectorId = 'wiring-inspector';\n api.addInspector({\n id: inspectorId,\n label: 'X-Components Wiring'\n });\n api.on.getInspectorTree(payload => {\n if (payload.inspectorId !== inspectorId) {\n return;\n }\n const query = payload.filter.toLowerCase();\n payload.rootNodes = reduce(\n wiringNodes,\n (nodes, event, eventWires) => {\n const wiresNodes =\n /* If there is no active search, or the event name includes the query, we include all the\n available wires. */\n !query || event.toLowerCase().includes(query)\n ? eventWires\n : eventWires.filter(node =>\n node.label.toLowerCase().includes(payload.filter.toLowerCase())\n );\n if (wiresNodes.length) {\n nodes.push({\n id: event,\n label: event,\n children: wiresNodes.map(wireNode => ({\n ...wireNode,\n tags: createWireTags(wireNode)\n }))\n });\n }\n return nodes;\n },\n <CustomInspectorNode[]>[]\n );\n });\n\n api.on.getInspectorState(payload => {\n if (payload.inspectorId !== inspectorId) {\n return;\n }\n payload.state = {\n status: [\n {\n key: 'enabled',\n value: wiresStatus[payload.nodeId],\n editable: true\n }\n ]\n };\n });\n\n api.on.editInspectorState(payload => {\n if (payload.inspectorId === inspectorId) {\n wiresStatus[payload.nodeId] = payload.state.value;\n api.sendInspectorTree(inspectorId);\n }\n });\n}\n\n/**\n * Sends the module wiring to Vue's devtools inspector. Additionally, it modifies each wire, adding\n * a filter function to let it be enabled/disabled from the devtools.\n *\n * @param module - The module name this wiring belongs too.\n * @param wiring - The wiring to save.\n * @internal\n */\nexport function sendWiringToDevtools(module: XModuleName, wiring: Partial<Wiring>): void {\n if (process.env.NODE_ENV !== 'production') {\n forEach(wiring, (event, wires: Dictionary<AnyWire>) => {\n const eventWiring = wiringNodes[event] ?? (wiringNodes[event] = []);\n forEach(wires, (wireName, wire) => {\n const id = `${module}-${event}-${wireName}`;\n wiresStatus[id] = true;\n wires[wireName] = filter(wire, () => wiresStatus[id]);\n eventWiring.push({\n id,\n label: wireName,\n tags: [\n {\n label: module,\n ...moduleColors[module]\n }\n ]\n });\n });\n });\n }\n}\n"],"names":[],"mappings":"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"}
|
package/js/plugins/x-bus.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReplaySubject } from 'rxjs';
|
|
2
2
|
import { map } from 'rxjs/operators';
|
|
3
|
+
import { logDevtoolsXEvent } from './devtools/timeline.devtools.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Default {@link XBus} implementation.
|
|
@@ -29,6 +30,7 @@ class BaseXBus {
|
|
|
29
30
|
eventPayload: payload,
|
|
30
31
|
metadata
|
|
31
32
|
};
|
|
33
|
+
logDevtoolsXEvent(event, value);
|
|
32
34
|
const emitter = this.getOrCreateEmitter(event);
|
|
33
35
|
emitter.next(value);
|
|
34
36
|
}
|
|
@@ -61,7 +63,7 @@ class BaseXBus {
|
|
|
61
63
|
(this.emitters[event] = new ReplaySubject(1)));
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
|
-
/** @internal The bus instance. Will be replaced by injection */
|
|
66
|
+
/** @internal The bus instance. Will be replaced by injection. */
|
|
65
67
|
const bus = new BaseXBus();
|
|
66
68
|
// TODO Remove this instantiation and replace with injection where used
|
|
67
69
|
|
package/js/plugins/x-bus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x-bus.js","sources":["../../../src/plugins/x-bus.ts"],"sourcesContent":["import { Observable, ReplaySubject } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { XEvent, XEventPayload } from '../wiring/events.types';\nimport { WireMetadata, WirePayload } from '../wiring/wiring.types';\nimport { Emitter, Emitters, XBus } from './x-bus.types';\n\n/**\n * Default {@link XBus} implementation.\n *\n * @public\n */\nexport class BaseXBus implements XBus {\n /**\n * Dictionary to store the created event emitters.\n *\n * @internal\n */\n protected emitters: Emitters = {};\n\n /**\n * Emits an event. See {@link XBus.(emit:2)}.\n *\n * @param event - Event to be emitted.\n * @param payload - Event payload.\n * @param metadata - Information of who emits the event.\n */\n emit<Event extends XEvent>(\n event: Event,\n payload?: XEventPayload<Event>,\n metadata: WireMetadata = { moduleName: null }\n ): void {\n // Payload is defined here as an optional argument (which is wrong), but as this\n // implementation must be used with the type XBus there is no problem\n const value: WirePayload<XEventPayload<Event>> = {\n eventPayload: payload as any,\n metadata\n };\n const emitter = this.getOrCreateEmitter(event);\n emitter.next(value);\n }\n\n /**\n * Retrieves an observable. See {@link XBus.(on:3)}.\n *\n * @public\n * @param event - Event to listener.\n * @param withMetadata - Option to listener with info about event emitter.\n * @returns The emitter for the event passed.\n */\n on<Event extends XEvent>(\n event: Event,\n withMetadata = false\n ): Observable<WirePayload<XEventPayload<Event>> | XEventPayload<Event>> {\n return withMetadata\n ? this.getOrCreateEmitter(event)\n : this.getOrCreateEmitter(event).pipe(map(value => value.eventPayload));\n }\n\n /**\n * Retrieves an event emitter for a given event.\n *\n * @param event - The event to retrieve the emitter for.\n * @returns The emitter for the event passed.\n * @remarks The emitter is implemented with a\n * {@Link https://www.learnrxjs.io/learn-rxjs/subjects/replaysubject | ReplaySubject} to allow any\n * new subscriber receive the last emitted value.\n * @internal\n */\n protected getOrCreateEmitter<Event extends XEvent>(event: Event): Emitter<Event> {\n // TODO I Don't get why the types are not working here\n return (\n this.emitters[event] ??\n (this.emitters[event] = new ReplaySubject<WirePayload<XEventPayload<Event>>>(1) as any)\n );\n }\n}\n\n/** @internal The bus instance. Will be replaced by injection */\nexport const bus: XBus = new BaseXBus();\n// TODO Remove this instantiation and replace with injection where used\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"x-bus.js","sources":["../../../src/plugins/x-bus.ts"],"sourcesContent":["import { Observable, ReplaySubject } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { XEvent, XEventPayload } from '../wiring/events.types';\nimport { WireMetadata, WirePayload } from '../wiring/wiring.types';\nimport { logDevtoolsXEvent } from './devtools/timeline.devtools';\nimport { Emitter, Emitters, XBus } from './x-bus.types';\n\n/**\n * Default {@link XBus} implementation.\n *\n * @public\n */\nexport class BaseXBus implements XBus {\n /**\n * Dictionary to store the created event emitters.\n *\n * @internal\n */\n protected emitters: Emitters = {};\n\n /**\n * Emits an event. See {@link XBus.(emit:2)}.\n *\n * @param event - Event to be emitted.\n * @param payload - Event payload.\n * @param metadata - Information of who emits the event.\n */\n emit<Event extends XEvent>(\n event: Event,\n payload?: XEventPayload<Event>,\n metadata: WireMetadata = { moduleName: null }\n ): void {\n // Payload is defined here as an optional argument (which is wrong), but as this\n // implementation must be used with the type XBus there is no problem\n const value: WirePayload<XEventPayload<Event>> = {\n eventPayload: payload as any,\n metadata\n };\n logDevtoolsXEvent(event, value);\n const emitter = this.getOrCreateEmitter(event);\n emitter.next(value);\n }\n\n /**\n * Retrieves an observable. See {@link XBus.(on:3)}.\n *\n * @public\n * @param event - Event to listener.\n * @param withMetadata - Option to listener with info about event emitter.\n * @returns The emitter for the event passed.\n */\n on<Event extends XEvent>(\n event: Event,\n withMetadata = false\n ): Observable<WirePayload<XEventPayload<Event>> | XEventPayload<Event>> {\n return withMetadata\n ? this.getOrCreateEmitter(event)\n : this.getOrCreateEmitter(event).pipe(map(value => value.eventPayload));\n }\n\n /**\n * Retrieves an event emitter for a given event.\n *\n * @param event - The event to retrieve the emitter for.\n * @returns The emitter for the event passed.\n * @remarks The emitter is implemented with a\n * {@Link https://www.learnrxjs.io/learn-rxjs/subjects/replaysubject | ReplaySubject} to allow any\n * new subscriber receive the last emitted value.\n * @internal\n */\n protected getOrCreateEmitter<Event extends XEvent>(event: Event): Emitter<Event> {\n // TODO I Don't get why the types are not working here\n return (\n this.emitters[event] ??\n (this.emitters[event] = new ReplaySubject<WirePayload<XEventPayload<Event>>>(1) as any)\n );\n }\n}\n\n/** @internal The bus instance. Will be replaced by injection. */\nexport const bus: XBus = new BaseXBus();\n// TODO Remove this instantiation and replace with injection where used\n"],"names":[],"mappings":";;;;AAOA;;;;;MAKa,QAAQ;IAArB;;;;;;QAMY,aAAQ,GAAa,EAAE,CAAC;KA2DnC;;;;;;;;IAlDC,IAAI,CACF,KAAY,EACZ,OAA8B,EAC9B,WAAyB,EAAE,UAAU,EAAE,IAAI,EAAE;;;QAI7C,MAAM,KAAK,GAAsC;YAC/C,YAAY,EAAE,OAAc;YAC5B,QAAQ;SACT,CAAC;QACF,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACrB;;;;;;;;;IAUD,EAAE,CACA,KAAY,EACZ,YAAY,GAAG,KAAK;QAEpB,OAAO,YAAY;cACf,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;cAC9B,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;KAC3E;;;;;;;;;;;IAYS,kBAAkB,CAAuB,KAAY;;QAE7D,QACE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;aACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,aAAa,CAAoC,CAAC,CAAQ,CAAC,EACvF;KACH;CACF;AAED;MACa,GAAG,GAAS,IAAI,QAAQ,GAAG;AACxC;;;;"}
|
package/js/plugins/x-plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { forEach } from '@empathyco/x-utils';
|
|
|
3
3
|
import Vuex, { Store } from 'vuex';
|
|
4
4
|
import { cleanGettersProxyCache } from '../store/utils/getters-proxy.utils.js';
|
|
5
5
|
import { RootXStoreModule } from '../store/x.module.js';
|
|
6
|
+
import { sendWiringToDevtools } from './devtools/wiring.devtools.js';
|
|
6
7
|
import { bus } from './x-bus.js';
|
|
7
8
|
import { registerStoreEmitters } from './x-emitters.js';
|
|
8
9
|
import { createXComponentAPIMixin } from './x-plugin.mixin.js';
|
|
@@ -23,6 +24,7 @@ class XPlugin {
|
|
|
23
24
|
* @public
|
|
24
25
|
*/
|
|
25
26
|
constructor(bus) {
|
|
27
|
+
this.wiring = {};
|
|
26
28
|
/**
|
|
27
29
|
* Set of the already installed {@link XModule | XModules} to avoid re-registering them.
|
|
28
30
|
*
|
|
@@ -166,6 +168,7 @@ class XPlugin {
|
|
|
166
168
|
// to allow lazy loaded modules work properly.
|
|
167
169
|
this.registerWiring(customizedXModule);
|
|
168
170
|
this.installedXModules.add(xModule.name);
|
|
171
|
+
this.bus.emit('ModuleRegistered', xModule.name);
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
174
|
/**
|
|
@@ -197,7 +200,8 @@ class XPlugin {
|
|
|
197
200
|
*
|
|
198
201
|
* @internal
|
|
199
202
|
*/
|
|
200
|
-
registerWiring({ wiring }) {
|
|
203
|
+
registerWiring({ wiring, name }) {
|
|
204
|
+
sendWiringToDevtools(name, wiring);
|
|
201
205
|
forEach(wiring, (event, wires) => {
|
|
202
206
|
// Obtain the observable
|
|
203
207
|
const observable = this.bus.on(event, true);
|