@vue/devtools-api 6.0.0-beta.15 → 6.0.0-beta.19
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/lib/cjs/const.js +2 -1
- package/lib/cjs/env.js +3 -2
- package/lib/cjs/index.js +10 -3
- package/lib/cjs/plugin.js +2 -0
- package/lib/cjs/proxy.js +105 -0
- package/lib/{cjs → esm}/api/api.d.ts +23 -11
- package/lib/{cjs → esm}/api/app.d.ts +0 -0
- package/lib/{cjs → esm}/api/component.d.ts +1 -1
- package/lib/{cjs → esm}/api/context.d.ts +0 -0
- package/lib/{cjs → esm}/api/hooks.d.ts +12 -2
- package/lib/{cjs → esm}/api/index.d.ts +0 -0
- package/lib/{cjs → esm}/api/util.d.ts +0 -0
- package/lib/esm/const.d.ts +2 -0
- package/lib/esm/const.js +1 -0
- package/lib/esm/env.d.ts +15 -0
- package/lib/esm/env.js +2 -1
- package/lib/esm/index.d.ts +7 -0
- package/lib/esm/index.js +11 -4
- package/lib/esm/plugin.d.ts +35 -0
- package/lib/esm/plugin.js +0 -0
- package/lib/esm/proxy.d.ts +20 -0
- package/lib/esm/proxy.js +101 -0
- package/package.json +5 -6
- package/lib/cjs/const.d.ts +0 -1
- package/lib/cjs/env.d.ts +0 -10
- package/lib/cjs/index.d.ts +0 -14
package/lib/cjs/const.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HOOK_SETUP = void 0;
|
|
3
|
+
exports.HOOK_PLUGIN_SETTINGS_SET = exports.HOOK_SETUP = void 0;
|
|
4
4
|
exports.HOOK_SETUP = 'devtools-plugin:setup';
|
|
5
|
+
exports.HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
|
package/lib/cjs/env.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTarget = exports.getDevtoolsGlobalHook = void 0;
|
|
3
|
+
exports.isProxyAvailable = exports.getTarget = exports.getDevtoolsGlobalHook = void 0;
|
|
4
4
|
function getDevtoolsGlobalHook() {
|
|
5
5
|
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
|
|
6
6
|
}
|
|
7
7
|
exports.getDevtoolsGlobalHook = getDevtoolsGlobalHook;
|
|
8
8
|
function getTarget() {
|
|
9
9
|
// @ts-ignore
|
|
10
|
-
return typeof navigator !== 'undefined'
|
|
10
|
+
return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
|
|
11
11
|
? window
|
|
12
12
|
: typeof global !== 'undefined'
|
|
13
13
|
? global
|
|
14
14
|
: {};
|
|
15
15
|
}
|
|
16
16
|
exports.getTarget = getTarget;
|
|
17
|
+
exports.isProxyAvailable = typeof Proxy === 'function';
|
package/lib/cjs/index.js
CHANGED
|
@@ -13,19 +13,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.setupDevtoolsPlugin = void 0;
|
|
14
14
|
const env_1 = require("./env");
|
|
15
15
|
const const_1 = require("./const");
|
|
16
|
+
const proxy_1 = require("./proxy");
|
|
16
17
|
__exportStar(require("./api"), exports);
|
|
18
|
+
__exportStar(require("./plugin"), exports);
|
|
17
19
|
function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
|
|
20
|
+
const target = env_1.getTarget();
|
|
18
21
|
const hook = env_1.getDevtoolsGlobalHook();
|
|
19
|
-
|
|
22
|
+
const enableProxy = env_1.isProxyAvailable && pluginDescriptor.enableEarlyProxy;
|
|
23
|
+
if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
|
|
20
24
|
hook.emit(const_1.HOOK_SETUP, pluginDescriptor, setupFn);
|
|
21
25
|
}
|
|
22
26
|
else {
|
|
23
|
-
const
|
|
27
|
+
const proxy = enableProxy ? new proxy_1.ApiProxy(pluginDescriptor, hook) : null;
|
|
24
28
|
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
|
|
25
29
|
list.push({
|
|
26
30
|
pluginDescriptor,
|
|
27
|
-
setupFn
|
|
31
|
+
setupFn,
|
|
32
|
+
proxy
|
|
28
33
|
});
|
|
34
|
+
if (proxy)
|
|
35
|
+
setupFn(proxy.proxiedTarget);
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
exports.setupDevtoolsPlugin = setupDevtoolsPlugin;
|
package/lib/cjs/proxy.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiProxy = void 0;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
class ApiProxy {
|
|
6
|
+
constructor(plugin, hook) {
|
|
7
|
+
this.target = null;
|
|
8
|
+
this.targetQueue = [];
|
|
9
|
+
this.onQueue = [];
|
|
10
|
+
this.plugin = plugin;
|
|
11
|
+
this.hook = hook;
|
|
12
|
+
const defaultSettings = {};
|
|
13
|
+
if (plugin.settings) {
|
|
14
|
+
for (const id in plugin.settings) {
|
|
15
|
+
const item = plugin.settings[id];
|
|
16
|
+
defaultSettings[id] = item.defaultValue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
|
|
20
|
+
let currentSettings = { ...defaultSettings };
|
|
21
|
+
try {
|
|
22
|
+
const raw = localStorage.getItem(localSettingsSaveId);
|
|
23
|
+
const data = JSON.parse(raw);
|
|
24
|
+
Object.assign(currentSettings, data);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// noop
|
|
28
|
+
}
|
|
29
|
+
this.fallbacks = {
|
|
30
|
+
getSettings() {
|
|
31
|
+
return currentSettings;
|
|
32
|
+
},
|
|
33
|
+
setSettings(value) {
|
|
34
|
+
try {
|
|
35
|
+
localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
// noop
|
|
39
|
+
}
|
|
40
|
+
currentSettings = value;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
hook.on(const_1.HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
|
|
44
|
+
if (pluginId === this.plugin.id) {
|
|
45
|
+
this.fallbacks.setSettings(value);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.proxiedOn = new Proxy({}, {
|
|
49
|
+
get: (_target, prop) => {
|
|
50
|
+
if (this.target) {
|
|
51
|
+
return this.target.on[prop];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return (...args) => {
|
|
55
|
+
this.onQueue.push({
|
|
56
|
+
method: prop,
|
|
57
|
+
args
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.proxiedTarget = new Proxy({}, {
|
|
64
|
+
get: (_target, prop) => {
|
|
65
|
+
if (this.target) {
|
|
66
|
+
return this.target[prop];
|
|
67
|
+
}
|
|
68
|
+
else if (prop === 'on') {
|
|
69
|
+
return this.proxiedOn;
|
|
70
|
+
}
|
|
71
|
+
else if (Object.keys(this.fallbacks).includes(prop)) {
|
|
72
|
+
return (...args) => {
|
|
73
|
+
this.targetQueue.push({
|
|
74
|
+
method: prop,
|
|
75
|
+
args,
|
|
76
|
+
resolve: () => { }
|
|
77
|
+
});
|
|
78
|
+
return this.fallbacks[prop](...args);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return (...args) => {
|
|
83
|
+
return new Promise(resolve => {
|
|
84
|
+
this.targetQueue.push({
|
|
85
|
+
method: prop,
|
|
86
|
+
args,
|
|
87
|
+
resolve
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async setRealTarget(target) {
|
|
96
|
+
this.target = target;
|
|
97
|
+
for (const item of this.onQueue) {
|
|
98
|
+
this.target.on[item.method](...item.args);
|
|
99
|
+
}
|
|
100
|
+
for (const item of this.targetQueue) {
|
|
101
|
+
item.resolve(await this.target[item.method](...item.args));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.ApiProxy = ApiProxy;
|
|
@@ -3,23 +3,28 @@ import { Context } from './context';
|
|
|
3
3
|
import { ComponentInstance, ComponentState, StateBase } from './component';
|
|
4
4
|
import { App } from './app';
|
|
5
5
|
import { ID } from './util';
|
|
6
|
-
export interface DevtoolsPluginApi {
|
|
6
|
+
export interface DevtoolsPluginApi<TSettings> {
|
|
7
7
|
on: Hookable<Context>;
|
|
8
|
-
notifyComponentUpdate(instance?: ComponentInstance):
|
|
9
|
-
addTimelineLayer(options: TimelineLayerOptions):
|
|
10
|
-
addTimelineEvent(options: TimelineEventOptions):
|
|
11
|
-
addInspector(options: CustomInspectorOptions):
|
|
12
|
-
sendInspectorTree(inspectorId: string):
|
|
13
|
-
sendInspectorState(inspectorId: string):
|
|
14
|
-
selectInspectorNode(inspectorId: string, nodeId: string):
|
|
8
|
+
notifyComponentUpdate(instance?: ComponentInstance): void;
|
|
9
|
+
addTimelineLayer(options: TimelineLayerOptions): void;
|
|
10
|
+
addTimelineEvent(options: TimelineEventOptions): void;
|
|
11
|
+
addInspector(options: CustomInspectorOptions): void;
|
|
12
|
+
sendInspectorTree(inspectorId: string): void;
|
|
13
|
+
sendInspectorState(inspectorId: string): void;
|
|
14
|
+
selectInspectorNode(inspectorId: string, nodeId: string): void;
|
|
15
15
|
getComponentBounds(instance: ComponentInstance): Promise<ComponentBounds>;
|
|
16
16
|
getComponentName(instance: ComponentInstance): Promise<string>;
|
|
17
17
|
getComponentInstances(app: App): Promise<ComponentInstance[]>;
|
|
18
|
-
highlightElement(instance: ComponentInstance):
|
|
19
|
-
unhighlightElement():
|
|
18
|
+
highlightElement(instance: ComponentInstance): void;
|
|
19
|
+
unhighlightElement(): void;
|
|
20
|
+
getSettings(pluginId?: string): TSettings;
|
|
21
|
+
/**
|
|
22
|
+
* @private Not implemented yet
|
|
23
|
+
*/
|
|
24
|
+
setSettings(values: TSettings): void;
|
|
20
25
|
}
|
|
21
26
|
export interface AppRecord {
|
|
22
|
-
id:
|
|
27
|
+
id: string;
|
|
23
28
|
name: string;
|
|
24
29
|
instanceMap: Map<string, ComponentInstance>;
|
|
25
30
|
rootInstance: ComponentInstance;
|
|
@@ -60,6 +65,13 @@ export interface TimelineEvent<TData = any, TMeta = any> {
|
|
|
60
65
|
title?: string;
|
|
61
66
|
subtitle?: string;
|
|
62
67
|
}
|
|
68
|
+
export interface TimelineMarkerOptions {
|
|
69
|
+
id: string;
|
|
70
|
+
time: number;
|
|
71
|
+
color: number;
|
|
72
|
+
label: string;
|
|
73
|
+
all?: boolean;
|
|
74
|
+
}
|
|
63
75
|
export interface CustomInspectorOptions {
|
|
64
76
|
id: string;
|
|
65
77
|
label: string;
|
|
File without changes
|
|
File without changes
|
|
@@ -22,7 +22,8 @@ export declare const enum Hooks {
|
|
|
22
22
|
TIMELINE_CLEARED = "timelineCleared",
|
|
23
23
|
GET_INSPECTOR_TREE = "getInspectorTree",
|
|
24
24
|
GET_INSPECTOR_STATE = "getInspectorState",
|
|
25
|
-
EDIT_INSPECTOR_STATE = "editInspectorState"
|
|
25
|
+
EDIT_INSPECTOR_STATE = "editInspectorState",
|
|
26
|
+
SET_PLUGIN_SETTINGS = "setPluginSettings"
|
|
26
27
|
}
|
|
27
28
|
export interface ComponentBounds {
|
|
28
29
|
left: number;
|
|
@@ -94,7 +95,7 @@ export declare type HookPayloads = {
|
|
|
94
95
|
path: string[];
|
|
95
96
|
type: string;
|
|
96
97
|
state: EditStatePayload;
|
|
97
|
-
set: (object: any, path
|
|
98
|
+
set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
|
|
98
99
|
};
|
|
99
100
|
[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
|
|
100
101
|
componentInstance: ComponentInstance;
|
|
@@ -133,6 +134,14 @@ export declare type HookPayloads = {
|
|
|
133
134
|
state: EditStatePayload;
|
|
134
135
|
set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void;
|
|
135
136
|
};
|
|
137
|
+
[Hooks.SET_PLUGIN_SETTINGS]: {
|
|
138
|
+
app: App;
|
|
139
|
+
pluginId: string;
|
|
140
|
+
key: string;
|
|
141
|
+
newValue: any;
|
|
142
|
+
oldValue: any;
|
|
143
|
+
settings: any;
|
|
144
|
+
};
|
|
136
145
|
};
|
|
137
146
|
export declare type EditStatePayload = {
|
|
138
147
|
value: any;
|
|
@@ -166,4 +175,5 @@ export interface Hookable<TContext> {
|
|
|
166
175
|
getInspectorTree(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>): any;
|
|
167
176
|
getInspectorState(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>): any;
|
|
168
177
|
editInspectorState(handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>): any;
|
|
178
|
+
setPluginSettings(handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>): any;
|
|
169
179
|
}
|
|
File without changes
|
|
File without changes
|
package/lib/esm/const.js
CHANGED
package/lib/esm/env.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginDescriptor, SetupFunction } from '.';
|
|
2
|
+
import { ApiProxy } from './proxy';
|
|
3
|
+
export interface PluginQueueItem {
|
|
4
|
+
pluginDescriptor: PluginDescriptor;
|
|
5
|
+
setupFn: SetupFunction;
|
|
6
|
+
proxy?: ApiProxy;
|
|
7
|
+
}
|
|
8
|
+
interface GlobalTarget {
|
|
9
|
+
__VUE_DEVTOOLS_PLUGINS__?: PluginQueueItem[];
|
|
10
|
+
__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function getDevtoolsGlobalHook(): any;
|
|
13
|
+
export declare function getTarget(): GlobalTarget;
|
|
14
|
+
export declare const isProxyAvailable: boolean;
|
|
15
|
+
export {};
|
package/lib/esm/env.js
CHANGED
|
@@ -3,9 +3,10 @@ export function getDevtoolsGlobalHook() {
|
|
|
3
3
|
}
|
|
4
4
|
export function getTarget() {
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
return typeof navigator !== 'undefined'
|
|
6
|
+
return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
|
|
7
7
|
? window
|
|
8
8
|
: typeof global !== 'undefined'
|
|
9
9
|
? global
|
|
10
10
|
: {};
|
|
11
11
|
}
|
|
12
|
+
export const isProxyAvailable = typeof Proxy === 'function';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DevtoolsPluginApi } from './api';
|
|
2
|
+
import { PluginDescriptor } from './plugin';
|
|
3
|
+
export * from './api';
|
|
4
|
+
export * from './plugin';
|
|
5
|
+
export { PluginQueueItem } from './env';
|
|
6
|
+
export declare type SetupFunction<TSettings = any> = (api: DevtoolsPluginApi<TSettings>) => void;
|
|
7
|
+
export declare function setupDevtoolsPlugin<TSettings = any>(pluginDescriptor: PluginDescriptor, setupFn: SetupFunction): void;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import { getTarget, getDevtoolsGlobalHook } from './env';
|
|
1
|
+
import { getTarget, getDevtoolsGlobalHook, isProxyAvailable } from './env';
|
|
2
2
|
import { HOOK_SETUP } from './const';
|
|
3
|
+
import { ApiProxy } from './proxy';
|
|
3
4
|
export * from './api';
|
|
5
|
+
export * from './plugin';
|
|
4
6
|
export function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
|
|
7
|
+
const target = getTarget();
|
|
5
8
|
const hook = getDevtoolsGlobalHook();
|
|
6
|
-
|
|
9
|
+
const enableProxy = isProxyAvailable && pluginDescriptor.enableEarlyProxy;
|
|
10
|
+
if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
|
|
7
11
|
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
|
|
8
12
|
}
|
|
9
13
|
else {
|
|
10
|
-
const
|
|
14
|
+
const proxy = enableProxy ? new ApiProxy(pluginDescriptor, hook) : null;
|
|
11
15
|
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
|
|
12
16
|
list.push({
|
|
13
17
|
pluginDescriptor,
|
|
14
|
-
setupFn
|
|
18
|
+
setupFn,
|
|
19
|
+
proxy
|
|
15
20
|
});
|
|
21
|
+
if (proxy)
|
|
22
|
+
setupFn(proxy.proxiedTarget);
|
|
16
23
|
}
|
|
17
24
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { App } from './api';
|
|
2
|
+
export interface PluginDescriptor {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
app: App;
|
|
6
|
+
packageName?: string;
|
|
7
|
+
homepage?: string;
|
|
8
|
+
componentStateTypes?: string[];
|
|
9
|
+
logo?: string;
|
|
10
|
+
disableAppScope?: boolean;
|
|
11
|
+
disablePluginScope?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Run the plugin setup and expose the api even if the devtools is not opened yet.
|
|
14
|
+
* Useful to record timeline events early.
|
|
15
|
+
*/
|
|
16
|
+
enableEarlyProxy?: boolean;
|
|
17
|
+
settings?: Record<string, PluginSettingsItem>;
|
|
18
|
+
}
|
|
19
|
+
export declare type PluginSettingsItem = {
|
|
20
|
+
label: string;
|
|
21
|
+
} & ({
|
|
22
|
+
type: 'boolean';
|
|
23
|
+
defaultValue: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'choice';
|
|
26
|
+
defaultValue: string | number;
|
|
27
|
+
options: {
|
|
28
|
+
value: string | number;
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
|
31
|
+
component?: 'select' | 'button-group';
|
|
32
|
+
} | {
|
|
33
|
+
type: 'text';
|
|
34
|
+
defaultValue: string;
|
|
35
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Context, DevtoolsPluginApi, Hookable } from './api';
|
|
2
|
+
import { PluginDescriptor } from './plugin';
|
|
3
|
+
interface QueueItem {
|
|
4
|
+
method: string;
|
|
5
|
+
args: any[];
|
|
6
|
+
resolve?: (value?: any) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class ApiProxy<TTarget extends DevtoolsPluginApi<any> = DevtoolsPluginApi<any>> {
|
|
9
|
+
target: TTarget | null;
|
|
10
|
+
targetQueue: QueueItem[];
|
|
11
|
+
proxiedTarget: TTarget;
|
|
12
|
+
onQueue: QueueItem[];
|
|
13
|
+
proxiedOn: Hookable<Context>;
|
|
14
|
+
plugin: PluginDescriptor;
|
|
15
|
+
hook: any;
|
|
16
|
+
fallbacks: Record<string, any>;
|
|
17
|
+
constructor(plugin: PluginDescriptor, hook: any);
|
|
18
|
+
setRealTarget(target: TTarget): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/lib/esm/proxy.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { HOOK_PLUGIN_SETTINGS_SET } from './const';
|
|
2
|
+
export class ApiProxy {
|
|
3
|
+
constructor(plugin, hook) {
|
|
4
|
+
this.target = null;
|
|
5
|
+
this.targetQueue = [];
|
|
6
|
+
this.onQueue = [];
|
|
7
|
+
this.plugin = plugin;
|
|
8
|
+
this.hook = hook;
|
|
9
|
+
const defaultSettings = {};
|
|
10
|
+
if (plugin.settings) {
|
|
11
|
+
for (const id in plugin.settings) {
|
|
12
|
+
const item = plugin.settings[id];
|
|
13
|
+
defaultSettings[id] = item.defaultValue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
|
|
17
|
+
let currentSettings = { ...defaultSettings };
|
|
18
|
+
try {
|
|
19
|
+
const raw = localStorage.getItem(localSettingsSaveId);
|
|
20
|
+
const data = JSON.parse(raw);
|
|
21
|
+
Object.assign(currentSettings, data);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
// noop
|
|
25
|
+
}
|
|
26
|
+
this.fallbacks = {
|
|
27
|
+
getSettings() {
|
|
28
|
+
return currentSettings;
|
|
29
|
+
},
|
|
30
|
+
setSettings(value) {
|
|
31
|
+
try {
|
|
32
|
+
localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
// noop
|
|
36
|
+
}
|
|
37
|
+
currentSettings = value;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
|
|
41
|
+
if (pluginId === this.plugin.id) {
|
|
42
|
+
this.fallbacks.setSettings(value);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.proxiedOn = new Proxy({}, {
|
|
46
|
+
get: (_target, prop) => {
|
|
47
|
+
if (this.target) {
|
|
48
|
+
return this.target.on[prop];
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return (...args) => {
|
|
52
|
+
this.onQueue.push({
|
|
53
|
+
method: prop,
|
|
54
|
+
args
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.proxiedTarget = new Proxy({}, {
|
|
61
|
+
get: (_target, prop) => {
|
|
62
|
+
if (this.target) {
|
|
63
|
+
return this.target[prop];
|
|
64
|
+
}
|
|
65
|
+
else if (prop === 'on') {
|
|
66
|
+
return this.proxiedOn;
|
|
67
|
+
}
|
|
68
|
+
else if (Object.keys(this.fallbacks).includes(prop)) {
|
|
69
|
+
return (...args) => {
|
|
70
|
+
this.targetQueue.push({
|
|
71
|
+
method: prop,
|
|
72
|
+
args,
|
|
73
|
+
resolve: () => { }
|
|
74
|
+
});
|
|
75
|
+
return this.fallbacks[prop](...args);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return (...args) => {
|
|
80
|
+
return new Promise(resolve => {
|
|
81
|
+
this.targetQueue.push({
|
|
82
|
+
method: prop,
|
|
83
|
+
args,
|
|
84
|
+
resolve
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async setRealTarget(target) {
|
|
93
|
+
this.target = target;
|
|
94
|
+
for (const item of this.onQueue) {
|
|
95
|
+
this.target.on[item.method](...item.args);
|
|
96
|
+
}
|
|
97
|
+
for (const item of this.targetQueue) {
|
|
98
|
+
item.resolve(await this.target[item.method](...item.args));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/devtools-api",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.19",
|
|
4
4
|
"description": "Interact with the Vue devtools from the page",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"browser": "lib/esm/index.js",
|
|
7
7
|
"module": "lib/esm/index.js",
|
|
8
|
-
"types": "lib/
|
|
8
|
+
"types": "lib/esm/index.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "Guillaume Chau"
|
|
@@ -25,10 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "rimraf lib && yarn build:esm && yarn build:cjs",
|
|
28
|
-
"build:esm": "tsc --module es2015 --outDir lib/esm",
|
|
29
|
-
"build:cjs": "tsc --module commonjs --outDir lib/cjs
|
|
30
|
-
"build:watch": "yarn tsc --module
|
|
31
|
-
"ts": "yarn build:esm"
|
|
28
|
+
"build:esm": "tsc --module es2015 --outDir lib/esm -d",
|
|
29
|
+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
|
|
30
|
+
"build:watch": "yarn tsc --module es2015 --outDir lib/esm -d -w --sourceMap"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/node": "^13.9.1",
|
package/lib/cjs/const.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const HOOK_SETUP = "devtools-plugin:setup";
|
package/lib/cjs/env.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PluginDescriptor, SetupFunction } from '.';
|
|
2
|
-
interface GlobalTarget {
|
|
3
|
-
__VUE_DEVTOOLS_PLUGINS__: Array<{
|
|
4
|
-
pluginDescriptor: PluginDescriptor;
|
|
5
|
-
setupFn: SetupFunction;
|
|
6
|
-
}>;
|
|
7
|
-
}
|
|
8
|
-
export declare function getDevtoolsGlobalHook(): any;
|
|
9
|
-
export declare function getTarget(): GlobalTarget;
|
|
10
|
-
export {};
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DevtoolsPluginApi, App } from './api';
|
|
2
|
-
export * from './api';
|
|
3
|
-
export interface PluginDescriptor {
|
|
4
|
-
id: string;
|
|
5
|
-
label: string;
|
|
6
|
-
app: App;
|
|
7
|
-
packageName?: string;
|
|
8
|
-
homepage?: string;
|
|
9
|
-
componentStateTypes?: string[];
|
|
10
|
-
logo?: string;
|
|
11
|
-
disableAppScope?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare type SetupFunction = (api: DevtoolsPluginApi) => void;
|
|
14
|
-
export declare function setupDevtoolsPlugin(pluginDescriptor: PluginDescriptor, setupFn: SetupFunction): void;
|