piral-debug-utils 0.13.7 → 0.14.0-alpha.3154
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/esm/DebugTracker.d.ts +3 -1
- package/esm/DebugTracker.js +4 -4
- package/esm/DebugTracker.js.map +1 -1
- package/esm/ExtensionCatalogue.d.ts +2 -0
- package/esm/ExtensionCatalogue.js +11 -0
- package/esm/ExtensionCatalogue.js.map +1 -0
- package/esm/VisualizationWrapper.d.ts +5 -2
- package/esm/VisualizationWrapper.js +31 -27
- package/esm/VisualizationWrapper.js.map +1 -1
- package/esm/debug.js +175 -121
- package/esm/debug.js.map +1 -1
- package/esm/decycle.d.ts +1 -0
- package/esm/decycle.js +53 -0
- package/esm/decycle.js.map +1 -0
- package/esm/emulator.d.ts +2 -7
- package/esm/emulator.js +6 -3
- package/esm/emulator.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/state.d.ts +26 -0
- package/esm/state.js +55 -0
- package/esm/state.js.map +1 -0
- package/esm/types.d.ts +52 -20
- package/lib/DebugTracker.d.ts +3 -1
- package/lib/DebugTracker.js +5 -5
- package/lib/DebugTracker.js.map +1 -1
- package/lib/ExtensionCatalogue.d.ts +2 -0
- package/lib/ExtensionCatalogue.js +15 -0
- package/lib/ExtensionCatalogue.js.map +1 -0
- package/lib/VisualizationWrapper.d.ts +5 -2
- package/lib/VisualizationWrapper.js +31 -27
- package/lib/VisualizationWrapper.js.map +1 -1
- package/lib/debug.js +175 -121
- package/lib/debug.js.map +1 -1
- package/lib/decycle.d.ts +1 -0
- package/lib/decycle.js +57 -0
- package/lib/decycle.js.map +1 -0
- package/lib/emulator.d.ts +2 -7
- package/lib/emulator.js +7 -4
- package/lib/emulator.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/state.d.ts +26 -0
- package/lib/state.js +62 -0
- package/lib/state.js.map +1 -0
- package/lib/types.d.ts +52 -20
- package/package.json +6 -4
- package/src/DebugTracker.tsx +7 -5
- package/src/ExtensionCatalogue.tsx +18 -0
- package/src/VisualizationWrapper.tsx +34 -26
- package/src/debug.ts +208 -147
- package/src/decycle.ts +55 -0
- package/src/elements.d.ts +10 -0
- package/src/emulator.ts +10 -11
- package/src/index.ts +1 -0
- package/src/state.ts +79 -0
- package/src/types.ts +56 -17
package/lib/state.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebugState = exports.subscribe = exports.getState = exports.setState = exports.initialSettings = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.initialSettings = {
|
|
6
|
+
viewState: sessionStorage.getItem('dbg:view-state') !== 'off',
|
|
7
|
+
loadPilets: sessionStorage.getItem('dbg:load-pilets') === 'on',
|
|
8
|
+
hardRefresh: sessionStorage.getItem('dbg:hard-refresh') === 'on',
|
|
9
|
+
viewOrigins: sessionStorage.getItem('dbg:view-origins') === 'on',
|
|
10
|
+
extensionCatalogue: sessionStorage.getItem('dbg:extension-catalogue') !== 'off',
|
|
11
|
+
cataloguePath: '/$debug-extension-catalogue',
|
|
12
|
+
};
|
|
13
|
+
const listeners = [];
|
|
14
|
+
let state = {
|
|
15
|
+
visualize: {
|
|
16
|
+
active: exports.initialSettings.viewOrigins,
|
|
17
|
+
force: false,
|
|
18
|
+
},
|
|
19
|
+
catalogue: {
|
|
20
|
+
active: exports.initialSettings.extensionCatalogue,
|
|
21
|
+
path: exports.initialSettings.cataloguePath,
|
|
22
|
+
},
|
|
23
|
+
route: undefined,
|
|
24
|
+
};
|
|
25
|
+
function setState(dispatch) {
|
|
26
|
+
const newState = dispatch(state);
|
|
27
|
+
if (newState !== state) {
|
|
28
|
+
state = newState;
|
|
29
|
+
listeners.forEach((listener) => listener());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.setState = setState;
|
|
33
|
+
function getState() {
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
exports.getState = getState;
|
|
37
|
+
function subscribe(select, notify) {
|
|
38
|
+
let prevState = select(state);
|
|
39
|
+
const cb = () => {
|
|
40
|
+
const nextState = select(state);
|
|
41
|
+
if (prevState !== nextState) {
|
|
42
|
+
prevState = nextState;
|
|
43
|
+
notify(nextState);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const unsubscribe = () => {
|
|
47
|
+
const idx = listeners.indexOf(cb);
|
|
48
|
+
if (idx !== -1) {
|
|
49
|
+
listeners.splice(idx, 1);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
listeners.push(cb);
|
|
53
|
+
return unsubscribe;
|
|
54
|
+
}
|
|
55
|
+
exports.subscribe = subscribe;
|
|
56
|
+
function useDebugState(select) {
|
|
57
|
+
const [state, setState] = (0, react_1.useState)(() => select(getState()));
|
|
58
|
+
(0, react_1.useEffect)(() => subscribe(select, setState), []);
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
exports.useDebugState = useDebugState;
|
|
62
|
+
//# sourceMappingURL=state.js.map
|
package/lib/state.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAE/B,QAAA,eAAe,GAAG;IAC7B,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,KAAK;IAC7D,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,IAAI;IAC9D,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI;IAChE,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,IAAI;IAChE,kBAAkB,EAAE,cAAc,CAAC,OAAO,CAAC,yBAAyB,CAAC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SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,OAAO,WAAW,CAAC;AACrB,CAAC;AAnBD,8BAmBC;AAED,SAAgB,aAAa,CAAI,MAAmC;IAClE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC7D,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC;AACf,CAAC;AAJD,sCAIC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,23 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export interface
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { Pilet, PiletApiCreator, PiletLoader, PiletMetadata } from 'piral-base';
|
|
3
|
+
export interface EmulatorConnectorOptions {
|
|
4
4
|
createApi: PiletApiCreator;
|
|
5
5
|
loadPilet: PiletLoader;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
injectPilet?(pilet: Pilet): void;
|
|
7
|
+
piletApiFallback?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ChangeSet {
|
|
10
|
+
state?: boolean;
|
|
11
|
+
pages?: boolean;
|
|
12
|
+
pilets?: boolean;
|
|
13
|
+
extensions?: boolean;
|
|
14
|
+
dependencies?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface DebugComponents {
|
|
17
|
+
wrappers: Record<string, FC>;
|
|
18
|
+
components: Record<string, FC>;
|
|
19
|
+
routes: Record<string, FC>;
|
|
20
|
+
onChange(previous: any, current: any, changed: ChangeSet): void;
|
|
21
|
+
}
|
|
22
|
+
export interface DebugCustomBooleanSetting {
|
|
23
|
+
value: boolean;
|
|
24
|
+
type: 'boolean';
|
|
25
|
+
onChange(newValue: boolean, prevValue: boolean): void;
|
|
26
|
+
}
|
|
27
|
+
export interface DebugCustomNumberSetting {
|
|
28
|
+
value: number;
|
|
29
|
+
type: 'number';
|
|
30
|
+
onChange(newValue: number, prevValue: number): void;
|
|
31
|
+
}
|
|
32
|
+
export interface DebugCustomStringSetting {
|
|
33
|
+
value: string;
|
|
34
|
+
type: 'string';
|
|
35
|
+
onChange(newValue: string, prevValue: string): void;
|
|
36
|
+
}
|
|
37
|
+
export declare type DebugCustomSetting = (DebugCustomBooleanSetting | DebugCustomNumberSetting | DebugCustomStringSetting) & {
|
|
38
|
+
label: string;
|
|
39
|
+
};
|
|
40
|
+
export interface DebuggerExtensionOptions {
|
|
41
|
+
customSettings?: Record<string, DebugCustomSetting>;
|
|
42
|
+
}
|
|
43
|
+
export interface DebuggerOptions extends DebuggerExtensionOptions {
|
|
44
|
+
getDependencies(): Array<string>;
|
|
45
|
+
createApi: PiletApiCreator;
|
|
46
|
+
loadPilet: PiletLoader;
|
|
47
|
+
injectPilet(pilet: Pilet): void;
|
|
48
|
+
fireEvent(name: string, arg: any): void;
|
|
49
|
+
getGlobalState(): any;
|
|
50
|
+
getPilets(): Array<PiletMetadata>;
|
|
51
|
+
getExtensions(): Array<string>;
|
|
52
|
+
getRoutes(): Array<string>;
|
|
53
|
+
setPilets(pilets: Array<PiletMetadata>): void;
|
|
54
|
+
integrate(components: DebugComponents): void;
|
|
23
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-debug-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-alpha.3154",
|
|
4
4
|
"description": "Utilities for debugging Piral instances.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -38,10 +38,12 @@
|
|
|
38
38
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"piral-
|
|
41
|
+
"piral-base": "^0.14.0-alpha.3154"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"piral-
|
|
44
|
+
"piral-base": "0.14.x",
|
|
45
|
+
"react": ">=16.8.0",
|
|
46
|
+
"react-router": ">=5.0.0"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "bc6cc60a59e6a8b1a154d187883cb794e8609939"
|
|
47
49
|
}
|
package/src/DebugTracker.tsx
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useHistory } from 'react-router
|
|
3
|
-
import {
|
|
2
|
+
import { useHistory } from 'react-router';
|
|
3
|
+
import { useDebugState } from './state';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export interface DebugTrackerProps {}
|
|
6
|
+
|
|
7
|
+
export const DebugTracker: React.FC<DebugTrackerProps> = () => {
|
|
8
|
+
const route = useDebugState((s) => s.route);
|
|
7
9
|
const history = useHistory();
|
|
8
10
|
|
|
9
11
|
React.useEffect(() => {
|
|
10
12
|
if (route) {
|
|
11
|
-
history.push(route);
|
|
13
|
+
history.push(route.path, route.state);
|
|
12
14
|
}
|
|
13
15
|
}, [route]);
|
|
14
16
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLocation } from 'react-router';
|
|
3
|
+
|
|
4
|
+
interface ExtensionCatalogueState {
|
|
5
|
+
name: string;
|
|
6
|
+
params: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ExtensionCatalogue: React.FC = () => {
|
|
10
|
+
const { state } = useLocation<ExtensionCatalogueState>();
|
|
11
|
+
|
|
12
|
+
if (state) {
|
|
13
|
+
const { name = '', params = {} } = state;
|
|
14
|
+
return <piral-extension name={name} params={JSON.stringify(params)} />;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { PiletApi } from 'piral-base';
|
|
3
|
+
import { useDebugState } from './state';
|
|
4
4
|
|
|
5
5
|
interface VisualizerProps {
|
|
6
6
|
pilet: string;
|
|
@@ -26,7 +26,6 @@ const Visualizer: React.FC<VisualizerProps> = ({ pilet, force, active }) => {
|
|
|
26
26
|
'#F012BE',
|
|
27
27
|
'#B10DC9',
|
|
28
28
|
];
|
|
29
|
-
const location = useLocation();
|
|
30
29
|
const container = React.useRef<HTMLDivElement>();
|
|
31
30
|
const color = React.useMemo(
|
|
32
31
|
() => moduleColor[pilet] || (moduleColor[pilet] = colors[Object.keys(moduleColor).length % colors.length]),
|
|
@@ -37,44 +36,49 @@ const Visualizer: React.FC<VisualizerProps> = ({ pilet, force, active }) => {
|
|
|
37
36
|
let sibling = container.current && (container.current.nextElementSibling as HTMLElement);
|
|
38
37
|
|
|
39
38
|
if (sibling && active) {
|
|
40
|
-
const style = container.current.style;
|
|
41
39
|
const target = container.current.parentNode;
|
|
42
40
|
|
|
43
41
|
const mouseIn = () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
if (container.current && sibling) {
|
|
43
|
+
const style = container.current.style;
|
|
44
|
+
style.display = 'block';
|
|
45
|
+
style.left = '0px';
|
|
46
|
+
style.top = '0px';
|
|
47
|
+
style.bottom = '0px';
|
|
48
|
+
style.right = '0px';
|
|
49
|
+
const targetRect = sibling.getBoundingClientRect();
|
|
50
|
+
const sourceRect = container.current.getBoundingClientRect();
|
|
51
|
+
style.left = targetRect.left - sourceRect.left + 'px';
|
|
52
|
+
style.top = targetRect.top - sourceRect.top + 'px';
|
|
53
|
+
style.bottom = -(targetRect.bottom - sourceRect.bottom) + 'px';
|
|
54
|
+
style.right = -(targetRect.right - sourceRect.right) + 'px';
|
|
55
|
+
}
|
|
55
56
|
};
|
|
56
57
|
const mouseOut = () => {
|
|
57
|
-
|
|
58
|
+
if (container.current) {
|
|
59
|
+
const style = container.current.style;
|
|
60
|
+
style.display = 'none';
|
|
61
|
+
}
|
|
58
62
|
};
|
|
59
63
|
const append = () => {
|
|
60
|
-
if (
|
|
64
|
+
if (force) {
|
|
65
|
+
mouseIn();
|
|
66
|
+
} else if (sibling) {
|
|
61
67
|
sibling.addEventListener('mouseover', mouseIn);
|
|
62
68
|
sibling.addEventListener('mouseout', mouseOut);
|
|
63
|
-
} else {
|
|
64
|
-
mouseIn();
|
|
65
69
|
}
|
|
66
70
|
};
|
|
67
71
|
const remove = () => {
|
|
68
|
-
if (
|
|
72
|
+
if (force) {
|
|
73
|
+
mouseOut();
|
|
74
|
+
} else if (sibling) {
|
|
69
75
|
sibling.removeEventListener('mouseover', mouseIn);
|
|
70
76
|
sibling.removeEventListener('mouseout', mouseOut);
|
|
71
|
-
} else {
|
|
72
|
-
mouseOut();
|
|
73
77
|
}
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
const observer = new MutationObserver(() => {
|
|
77
|
-
const newSibling = container.current
|
|
81
|
+
const newSibling = container.current?.nextElementSibling as HTMLElement;
|
|
78
82
|
|
|
79
83
|
if (newSibling !== sibling) {
|
|
80
84
|
remove();
|
|
@@ -91,7 +95,7 @@ const Visualizer: React.FC<VisualizerProps> = ({ pilet, force, active }) => {
|
|
|
91
95
|
observer.disconnect();
|
|
92
96
|
};
|
|
93
97
|
}
|
|
94
|
-
}, [
|
|
98
|
+
}, [active, force]);
|
|
95
99
|
|
|
96
100
|
if (active) {
|
|
97
101
|
const rect: React.CSSProperties = {
|
|
@@ -126,8 +130,12 @@ const Visualizer: React.FC<VisualizerProps> = ({ pilet, force, active }) => {
|
|
|
126
130
|
return null;
|
|
127
131
|
};
|
|
128
132
|
|
|
129
|
-
export
|
|
130
|
-
|
|
133
|
+
export interface VisualizationWrapperProps {
|
|
134
|
+
piral: PiletApi;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const VisualizationWrapper: React.FC<VisualizationWrapperProps> = ({ piral, children }) => {
|
|
138
|
+
const { active, force } = useDebugState((m) => m.visualize);
|
|
131
139
|
return (
|
|
132
140
|
<>
|
|
133
141
|
<Visualizer pilet={piral.meta.name} force={force} active={active} />
|