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/esm/DebugTracker.d.ts
CHANGED
package/esm/DebugTracker.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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
|
export const DebugTracker = () => {
|
|
5
|
-
const route =
|
|
5
|
+
const route = useDebugState((s) => s.route);
|
|
6
6
|
const history = useHistory();
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
if (route) {
|
|
9
|
-
history.push(route);
|
|
9
|
+
history.push(route.path, route.state);
|
|
10
10
|
}
|
|
11
11
|
}, [route]);
|
|
12
12
|
// tslint:disable-next-line:no-null-keyword
|
package/esm/DebugTracker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DebugTracker.js","sourceRoot":"","sources":["../src/DebugTracker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"DebugTracker.js","sourceRoot":"","sources":["../src/DebugTracker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,MAAM,CAAC,MAAM,YAAY,GAAgC,GAAG,EAAE;IAC5D,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,KAAK,EAAE;YACT,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;SACvC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLocation } from 'react-router';
|
|
3
|
+
export const ExtensionCatalogue = () => {
|
|
4
|
+
const { state } = useLocation();
|
|
5
|
+
if (state) {
|
|
6
|
+
const { name = '', params = {} } = state;
|
|
7
|
+
return React.createElement("piral-extension", { name: name, params: JSON.stringify(params) });
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=ExtensionCatalogue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionCatalogue.js","sourceRoot":"","sources":["../src/ExtensionCatalogue.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,MAAM,CAAC,MAAM,kBAAkB,GAAa,GAAG,EAAE;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,EAA2B,CAAC;IAEzD,IAAI,KAAK,EAAE;QACT,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;QACzC,OAAO,yCAAiB,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAI,CAAC;KACxE;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import type { PiletApi } from 'piral-base';
|
|
3
|
+
export interface VisualizationWrapperProps {
|
|
4
|
+
piral: PiletApi;
|
|
5
|
+
}
|
|
6
|
+
export declare const VisualizationWrapper: React.FC<VisualizationWrapperProps>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { useGlobalState } from 'piral-core';
|
|
2
|
+
import { useDebugState } from './state';
|
|
4
3
|
const moduleColor = {};
|
|
5
4
|
const Visualizer = ({ pilet, force, active }) => {
|
|
6
5
|
const colors = [
|
|
@@ -18,50 +17,55 @@ const Visualizer = ({ pilet, force, active }) => {
|
|
|
18
17
|
'#F012BE',
|
|
19
18
|
'#B10DC9',
|
|
20
19
|
];
|
|
21
|
-
const location = useLocation();
|
|
22
20
|
const container = React.useRef();
|
|
23
21
|
const color = React.useMemo(() => moduleColor[pilet] || (moduleColor[pilet] = colors[Object.keys(moduleColor).length % colors.length]), [pilet]);
|
|
24
22
|
React.useEffect(() => {
|
|
25
23
|
let sibling = container.current && container.current.nextElementSibling;
|
|
26
24
|
if (sibling && active) {
|
|
27
|
-
const style = container.current.style;
|
|
28
25
|
const target = container.current.parentNode;
|
|
29
26
|
const mouseIn = () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
if (container.current && sibling) {
|
|
28
|
+
const style = container.current.style;
|
|
29
|
+
style.display = 'block';
|
|
30
|
+
style.left = '0px';
|
|
31
|
+
style.top = '0px';
|
|
32
|
+
style.bottom = '0px';
|
|
33
|
+
style.right = '0px';
|
|
34
|
+
const targetRect = sibling.getBoundingClientRect();
|
|
35
|
+
const sourceRect = container.current.getBoundingClientRect();
|
|
36
|
+
style.left = targetRect.left - sourceRect.left + 'px';
|
|
37
|
+
style.top = targetRect.top - sourceRect.top + 'px';
|
|
38
|
+
style.bottom = -(targetRect.bottom - sourceRect.bottom) + 'px';
|
|
39
|
+
style.right = -(targetRect.right - sourceRect.right) + 'px';
|
|
40
|
+
}
|
|
41
41
|
};
|
|
42
42
|
const mouseOut = () => {
|
|
43
|
-
|
|
43
|
+
if (container.current) {
|
|
44
|
+
const style = container.current.style;
|
|
45
|
+
style.display = 'none';
|
|
46
|
+
}
|
|
44
47
|
};
|
|
45
48
|
const append = () => {
|
|
46
|
-
if (
|
|
49
|
+
if (force) {
|
|
50
|
+
mouseIn();
|
|
51
|
+
}
|
|
52
|
+
else if (sibling) {
|
|
47
53
|
sibling.addEventListener('mouseover', mouseIn);
|
|
48
54
|
sibling.addEventListener('mouseout', mouseOut);
|
|
49
55
|
}
|
|
50
|
-
else {
|
|
51
|
-
mouseIn();
|
|
52
|
-
}
|
|
53
56
|
};
|
|
54
57
|
const remove = () => {
|
|
55
|
-
if (
|
|
58
|
+
if (force) {
|
|
59
|
+
mouseOut();
|
|
60
|
+
}
|
|
61
|
+
else if (sibling) {
|
|
56
62
|
sibling.removeEventListener('mouseover', mouseIn);
|
|
57
63
|
sibling.removeEventListener('mouseout', mouseOut);
|
|
58
64
|
}
|
|
59
|
-
else {
|
|
60
|
-
mouseOut();
|
|
61
|
-
}
|
|
62
65
|
};
|
|
63
66
|
const observer = new MutationObserver(() => {
|
|
64
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
const newSibling = (_a = container.current) === null || _a === void 0 ? void 0 : _a.nextElementSibling;
|
|
65
69
|
if (newSibling !== sibling) {
|
|
66
70
|
remove();
|
|
67
71
|
sibling = newSibling;
|
|
@@ -75,7 +79,7 @@ const Visualizer = ({ pilet, force, active }) => {
|
|
|
75
79
|
observer.disconnect();
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
|
-
}, [
|
|
82
|
+
}, [active, force]);
|
|
79
83
|
if (active) {
|
|
80
84
|
const rect = {
|
|
81
85
|
border: '1px solid red',
|
|
@@ -104,7 +108,7 @@ const Visualizer = ({ pilet, force, active }) => {
|
|
|
104
108
|
return null;
|
|
105
109
|
};
|
|
106
110
|
export const VisualizationWrapper = ({ piral, children }) => {
|
|
107
|
-
const { active, force } =
|
|
111
|
+
const { active, force } = useDebugState((m) => m.visualize);
|
|
108
112
|
return (React.createElement(React.Fragment, null,
|
|
109
113
|
React.createElement(Visualizer, { pilet: piral.meta.name, force: force, active: active }),
|
|
110
114
|
children));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualizationWrapper.js","sourceRoot":"","sources":["../src/VisualizationWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"VisualizationWrapper.js","sourceRoot":"","sources":["../src/VisualizationWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQxC,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,MAAM,UAAU,GAA8B,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;IACzE,MAAM,MAAM,GAAG;QACb,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;QACT,SAAS;KACV,CAAC;IACF,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,EAAkB,CAAC;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,G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
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { isfunc } from 'piral-base';
|
|
13
1
|
import { DebugTracker } from './DebugTracker';
|
|
14
2
|
import { VisualizationWrapper } from './VisualizationWrapper';
|
|
3
|
+
import { ExtensionCatalogue } from './ExtensionCatalogue';
|
|
4
|
+
import { decycle } from './decycle';
|
|
5
|
+
import { setState, initialSettings } from './state';
|
|
15
6
|
export function installPiralDebug(options) {
|
|
16
|
-
const {
|
|
7
|
+
const { injectPilet, getGlobalState, getExtensions, getDependencies, getRoutes, getPilets, setPilets, fireEvent, integrate, createApi, loadPilet, customSettings = {}, } = options;
|
|
8
|
+
const events = [];
|
|
9
|
+
const legacyBrowser = !new Error().stack;
|
|
10
|
+
const excludedRoutes = [initialSettings.cataloguePath];
|
|
17
11
|
const selfSource = 'piral-debug-api';
|
|
18
12
|
const debugApiVersion = 'v1';
|
|
19
|
-
const settings = {
|
|
20
|
-
|
|
21
|
-
value: sessionStorage.getItem('dbg:view-state') !== 'off',
|
|
13
|
+
const settings = Object.assign(Object.assign({}, customSettings), { viewState: {
|
|
14
|
+
value: initialSettings.viewState,
|
|
22
15
|
type: 'boolean',
|
|
23
16
|
label: 'State container logging',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
onChange(value) {
|
|
18
|
+
sessionStorage.setItem('dbg:view-state', value ? 'on' : 'off');
|
|
19
|
+
},
|
|
20
|
+
}, loadPilets: {
|
|
21
|
+
value: initialSettings.loadPilets,
|
|
27
22
|
type: 'boolean',
|
|
28
23
|
label: 'Load available pilets',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
onChange(value) {
|
|
25
|
+
sessionStorage.setItem('dbg:load-pilets', value ? 'on' : 'off');
|
|
26
|
+
},
|
|
27
|
+
}, hardRefresh: {
|
|
28
|
+
value: initialSettings.hardRefresh,
|
|
32
29
|
type: 'boolean',
|
|
33
30
|
label: 'Full refresh on change',
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
onChange(value) {
|
|
32
|
+
sessionStorage.setItem('dbg:hard-refresh', value ? 'on' : 'off');
|
|
33
|
+
},
|
|
34
|
+
}, viewOrigins: {
|
|
35
|
+
value: initialSettings.viewOrigins,
|
|
37
36
|
type: 'boolean',
|
|
38
37
|
label: 'Visualize component origins',
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
onChange(value, prev) {
|
|
39
|
+
sessionStorage.setItem('dbg:view-origins', value ? 'on' : 'off');
|
|
40
|
+
if (prev !== value) {
|
|
41
|
+
updateVisualize(value);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}, extensionCatalogue: {
|
|
45
|
+
value: initialSettings.extensionCatalogue,
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
label: 'Enable extension catalogue',
|
|
48
|
+
onChange(value) {
|
|
49
|
+
sessionStorage.setItem('dbg:extension-catalogue', value ? 'on' : 'off');
|
|
50
|
+
},
|
|
51
|
+
} });
|
|
42
52
|
const sendMessage = (content) => {
|
|
43
53
|
window.postMessage({
|
|
44
54
|
content,
|
|
@@ -46,56 +56,62 @@ export function installPiralDebug(options) {
|
|
|
46
56
|
version: debugApiVersion,
|
|
47
57
|
}, '*');
|
|
48
58
|
};
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const sendCurrentRoutes = (pages, routes) => {
|
|
66
|
-
const registeredRoutes = Object.keys(pages);
|
|
67
|
-
const componentRoutes = Object.keys(routes);
|
|
68
|
-
sendMessage({
|
|
69
|
-
type: 'routes',
|
|
70
|
-
routes: [...componentRoutes, ...registeredRoutes],
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const setSetting = (setting, key, value) => {
|
|
74
|
-
setting.value = value;
|
|
75
|
-
sessionStorage.setItem(key, value ? 'on' : 'off');
|
|
59
|
+
const getSettings = () => {
|
|
60
|
+
return Object.keys(settings).reduce((obj, key) => {
|
|
61
|
+
const setting = settings[key];
|
|
62
|
+
if (setting &&
|
|
63
|
+
typeof setting === 'object' &&
|
|
64
|
+
typeof setting.label === 'string' &&
|
|
65
|
+
typeof setting.type === 'string' &&
|
|
66
|
+
['boolean', 'string', 'number'].includes(typeof setting.value)) {
|
|
67
|
+
obj[key] = {
|
|
68
|
+
label: setting.label,
|
|
69
|
+
value: setting.value,
|
|
70
|
+
type: setting.type,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return obj;
|
|
74
|
+
}, {});
|
|
76
75
|
};
|
|
77
76
|
const updateSettings = (values) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
Object.keys(values).forEach((key) => {
|
|
78
|
+
const setting = settings[key];
|
|
79
|
+
switch (setting.type) {
|
|
80
|
+
case 'boolean': {
|
|
81
|
+
const prev = setting.value;
|
|
82
|
+
const value = values[key];
|
|
83
|
+
setting.value = value;
|
|
84
|
+
setting.onChange(value, prev);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'number': {
|
|
88
|
+
const prev = setting.value;
|
|
89
|
+
const value = values[key];
|
|
90
|
+
setting.value = value;
|
|
91
|
+
setting.onChange(value, prev);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'string': {
|
|
95
|
+
const prev = setting.value;
|
|
96
|
+
const value = values[key];
|
|
97
|
+
setting.value = value;
|
|
98
|
+
setting.onChange(value, prev);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
87
103
|
sendMessage({
|
|
88
|
-
settings,
|
|
104
|
+
settings: getSettings(),
|
|
89
105
|
type: 'settings',
|
|
90
106
|
});
|
|
91
107
|
};
|
|
92
108
|
const togglePilet = (name) => {
|
|
93
|
-
const pilet =
|
|
109
|
+
const pilet = getPilets().find((m) => m.name === name);
|
|
94
110
|
if (pilet.disabled) {
|
|
95
111
|
try {
|
|
96
112
|
const { createApi } = options;
|
|
97
113
|
const newApi = createApi(pilet);
|
|
98
|
-
|
|
114
|
+
injectPilet(pilet.original);
|
|
99
115
|
pilet.original.setup(newApi);
|
|
100
116
|
}
|
|
101
117
|
catch (error) {
|
|
@@ -103,19 +119,20 @@ export function installPiralDebug(options) {
|
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
121
|
else {
|
|
106
|
-
|
|
122
|
+
injectPilet({ name, disabled: true, original: pilet });
|
|
107
123
|
}
|
|
108
124
|
};
|
|
109
125
|
const removePilet = (name) => {
|
|
110
|
-
|
|
111
|
-
|
|
126
|
+
const pilets = getPilets().filter((m) => m.name !== name);
|
|
127
|
+
injectPilet({ name });
|
|
128
|
+
setPilets(pilets);
|
|
112
129
|
};
|
|
113
130
|
const appendPilet = (meta) => {
|
|
114
131
|
const { createApi, loadPilet } = options;
|
|
115
132
|
loadPilet(meta).then((pilet) => {
|
|
116
133
|
try {
|
|
117
134
|
const newApi = createApi(pilet);
|
|
118
|
-
|
|
135
|
+
injectPilet(pilet);
|
|
119
136
|
pilet.setup(newApi);
|
|
120
137
|
}
|
|
121
138
|
catch (error) {
|
|
@@ -124,13 +141,16 @@ export function installPiralDebug(options) {
|
|
|
124
141
|
});
|
|
125
142
|
};
|
|
126
143
|
const toggleVisualize = () => {
|
|
127
|
-
|
|
144
|
+
setState((s) => (Object.assign(Object.assign({}, s), { visualize: Object.assign(Object.assign({}, s.visualize), { force: !s.visualize.force }) })));
|
|
128
145
|
};
|
|
129
146
|
const updateVisualize = (active) => {
|
|
130
|
-
|
|
147
|
+
setState((s) => (Object.assign(Object.assign({}, s), { visualize: Object.assign(Object.assign({}, s.visualize), { active }) })));
|
|
131
148
|
};
|
|
132
|
-
const goToRoute = (
|
|
133
|
-
|
|
149
|
+
const goToRoute = (path, state) => {
|
|
150
|
+
setState((s) => (Object.assign(Object.assign({}, s), { route: {
|
|
151
|
+
path,
|
|
152
|
+
state,
|
|
153
|
+
} })));
|
|
134
154
|
};
|
|
135
155
|
const eventDispatcher = document.body.dispatchEvent;
|
|
136
156
|
const debugApi = {
|
|
@@ -139,23 +159,24 @@ export function installPiralDebug(options) {
|
|
|
139
159
|
name: process.env.BUILD_PCKG_NAME,
|
|
140
160
|
version: process.env.BUILD_PCKG_VERSION,
|
|
141
161
|
dependencies: process.env.SHARED_DEPENDENCIES,
|
|
142
|
-
context,
|
|
143
162
|
},
|
|
144
163
|
build: {
|
|
145
164
|
date: process.env.BUILD_TIME_FULL,
|
|
146
165
|
cli: process.env.PIRAL_CLI_VERSION,
|
|
147
166
|
compat: process.env.DEBUG_PIRAL,
|
|
148
167
|
},
|
|
149
|
-
pilets
|
|
168
|
+
pilets: {
|
|
169
|
+
loadPilet,
|
|
170
|
+
createApi,
|
|
171
|
+
},
|
|
150
172
|
};
|
|
151
173
|
const start = () => {
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
.map((pilet) => ({
|
|
174
|
+
const container = decycle(getGlobalState());
|
|
175
|
+
const routes = getRoutes().filter((r) => !excludedRoutes.includes(r));
|
|
176
|
+
const extensions = getExtensions();
|
|
177
|
+
const settings = getSettings();
|
|
178
|
+
const dependencies = getDependencies();
|
|
179
|
+
const pilets = getPilets().map((pilet) => ({
|
|
159
180
|
name: pilet.name,
|
|
160
181
|
version: pilet.version,
|
|
161
182
|
disabled: pilet.disabled,
|
|
@@ -165,13 +186,16 @@ export function installPiralDebug(options) {
|
|
|
165
186
|
name: debugApi.instance.name,
|
|
166
187
|
version: debugApi.instance.version,
|
|
167
188
|
kind: debugApiVersion,
|
|
168
|
-
|
|
189
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
190
|
+
capabilities: ['events', 'container', 'routes', 'pilets', 'settings', 'extensions', 'dependencies'],
|
|
169
191
|
state: {
|
|
170
192
|
routes,
|
|
171
193
|
pilets,
|
|
172
194
|
container,
|
|
173
195
|
settings,
|
|
174
196
|
events,
|
|
197
|
+
extensions,
|
|
198
|
+
dependencies,
|
|
175
199
|
},
|
|
176
200
|
});
|
|
177
201
|
};
|
|
@@ -180,7 +204,7 @@ export function installPiralDebug(options) {
|
|
|
180
204
|
events.unshift({
|
|
181
205
|
id: events.length.toString(),
|
|
182
206
|
name: ev.type.replace('piral-', ''),
|
|
183
|
-
args: ev.detail.arg,
|
|
207
|
+
args: decycle(ev.detail.arg),
|
|
184
208
|
time: Date.now(),
|
|
185
209
|
});
|
|
186
210
|
sendMessage({
|
|
@@ -190,21 +214,15 @@ export function installPiralDebug(options) {
|
|
|
190
214
|
}
|
|
191
215
|
return eventDispatcher.call(this, ev);
|
|
192
216
|
};
|
|
193
|
-
context.dispatch((s) => (Object.assign(Object.assign({}, s), { $debug: {
|
|
194
|
-
visualize: {
|
|
195
|
-
active: settings.viewOrigins.value,
|
|
196
|
-
force: false,
|
|
197
|
-
},
|
|
198
|
-
route: undefined,
|
|
199
|
-
}, components: Object.assign(Object.assign({}, s.components), { Debug: DebugTracker }), registry: Object.assign(Object.assign({}, s.registry), { wrappers: Object.assign(Object.assign({}, s.registry.wrappers), { '*': VisualizationWrapper }) }) })));
|
|
200
217
|
window.addEventListener('storage', (event) => {
|
|
201
|
-
if (event.storageArea === sessionStorage) {
|
|
218
|
+
if (!legacyBrowser && event.storageArea === sessionStorage) {
|
|
202
219
|
// potentially unknowingly updated settings
|
|
203
220
|
updateSettings({
|
|
204
221
|
viewState: sessionStorage.getItem('dbg:view-state') !== 'off',
|
|
205
222
|
loadPilets: sessionStorage.getItem('dbg:load-pilets') === 'on',
|
|
206
223
|
hardRefresh: sessionStorage.getItem('dbg:hard-refresh') === 'on',
|
|
207
224
|
viewOrigins: sessionStorage.getItem('dbg:view-origins') === 'on',
|
|
225
|
+
extensionCatalogue: sessionStorage.getItem('dbg:extension-catalogue') !== 'off',
|
|
208
226
|
});
|
|
209
227
|
}
|
|
210
228
|
});
|
|
@@ -223,44 +241,80 @@ export function installPiralDebug(options) {
|
|
|
223
241
|
case 'toggle-pilet':
|
|
224
242
|
return togglePilet(content.name);
|
|
225
243
|
case 'emit-event':
|
|
226
|
-
return
|
|
244
|
+
return fireEvent(content.name, content.args);
|
|
227
245
|
case 'goto-route':
|
|
228
|
-
return goToRoute(content.route);
|
|
246
|
+
return goToRoute(content.route, content.state);
|
|
229
247
|
case 'visualize-all':
|
|
230
248
|
return toggleVisualize();
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
251
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
integrate({
|
|
253
|
+
components: {
|
|
254
|
+
Debug: DebugTracker,
|
|
255
|
+
},
|
|
256
|
+
routes: {
|
|
257
|
+
[initialSettings.cataloguePath]: ExtensionCatalogue,
|
|
258
|
+
},
|
|
259
|
+
wrappers: {
|
|
260
|
+
'*': VisualizationWrapper,
|
|
261
|
+
},
|
|
262
|
+
onChange(previous, current, changed) {
|
|
263
|
+
if (changed.state) {
|
|
264
|
+
if (settings.viewState.value) {
|
|
265
|
+
if (!legacyBrowser) {
|
|
266
|
+
// Chrome, Firefox, ... (full capability)
|
|
267
|
+
const err = new Error();
|
|
268
|
+
const lastLine = err.stack.split('\n')[7];
|
|
269
|
+
if (lastLine) {
|
|
270
|
+
const action = lastLine.replace(/^\s+at\s+(Atom\.|Object\.)?/, '');
|
|
271
|
+
console.group(`%c Piral State Change %c ${new Date().toLocaleTimeString()}`, 'color: gray; font-weight: lighter;', 'color: black; font-weight: bold;');
|
|
272
|
+
console.log('%c Previous', `color: #9E9E9E; font-weight: bold`, previous);
|
|
273
|
+
console.log('%c Action', `color: #03A9F4; font-weight: bold`, action);
|
|
274
|
+
console.log('%c Next', `color: #4CAF50; font-weight: bold`, current);
|
|
275
|
+
console.groupEnd();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// IE 11, ... (does not know colors etc.)
|
|
280
|
+
console.log('Changed state', previous, current);
|
|
248
281
|
}
|
|
249
282
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
283
|
+
sendMessage({
|
|
284
|
+
type: 'container',
|
|
285
|
+
container: decycle(getGlobalState()),
|
|
286
|
+
});
|
|
254
287
|
}
|
|
255
|
-
if (
|
|
256
|
-
|
|
288
|
+
if (changed.pilets) {
|
|
289
|
+
sendMessage({
|
|
290
|
+
type: 'pilets',
|
|
291
|
+
pilets: getPilets().map((pilet) => ({
|
|
292
|
+
name: pilet.name,
|
|
293
|
+
version: pilet.version,
|
|
294
|
+
disabled: !!pilet.disabled,
|
|
295
|
+
})),
|
|
296
|
+
});
|
|
257
297
|
}
|
|
258
|
-
if (
|
|
259
|
-
|
|
298
|
+
if (changed.pages) {
|
|
299
|
+
sendMessage({
|
|
300
|
+
type: 'routes',
|
|
301
|
+
routes: getRoutes().filter((r) => !excludedRoutes.includes(r)),
|
|
302
|
+
});
|
|
260
303
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
304
|
+
if (changed.extensions) {
|
|
305
|
+
sendMessage({
|
|
306
|
+
type: 'extensions',
|
|
307
|
+
extensions: getExtensions(),
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (changed.dependencies) {
|
|
311
|
+
sendMessage({
|
|
312
|
+
type: 'dependencies',
|
|
313
|
+
dependencies: getDependencies(),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
});
|
|
264
318
|
window['dbg:piral'] = debugApi;
|
|
265
319
|
start();
|
|
266
320
|
}
|