@vue/devtools-api 6.0.0-beta.16

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.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./api"), exports);
14
+ __exportStar(require("./app"), exports);
15
+ __exportStar(require("./component"), exports);
16
+ __exportStar(require("./context"), exports);
17
+ __exportStar(require("./hooks"), exports);
18
+ __exportStar(require("./util"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HOOK_PLUGIN_SETTINGS_SET = exports.HOOK_SETUP = void 0;
4
+ exports.HOOK_SETUP = 'devtools-plugin:setup';
5
+ exports.HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
package/lib/cjs/env.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isProxyAvailable = exports.getTarget = exports.getDevtoolsGlobalHook = void 0;
4
+ function getDevtoolsGlobalHook() {
5
+ return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
6
+ }
7
+ exports.getDevtoolsGlobalHook = getDevtoolsGlobalHook;
8
+ function getTarget() {
9
+ // @ts-ignore
10
+ return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
11
+ ? window
12
+ : typeof global !== 'undefined'
13
+ ? global
14
+ : {};
15
+ }
16
+ exports.getTarget = getTarget;
17
+ exports.isProxyAvailable = typeof Proxy === 'function';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.setupDevtoolsPlugin = void 0;
14
+ const env_1 = require("./env");
15
+ const const_1 = require("./const");
16
+ const proxy_1 = require("./proxy");
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./plugin"), exports);
19
+ function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
20
+ const target = env_1.getTarget();
21
+ const hook = env_1.getDevtoolsGlobalHook();
22
+ const enableProxy = env_1.isProxyAvailable && pluginDescriptor.enableEarlyProxy;
23
+ if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
24
+ hook.emit(const_1.HOOK_SETUP, pluginDescriptor, setupFn);
25
+ }
26
+ else {
27
+ const proxy = enableProxy ? new proxy_1.ApiProxy(pluginDescriptor, hook) : null;
28
+ const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
29
+ list.push({
30
+ pluginDescriptor,
31
+ setupFn,
32
+ proxy
33
+ });
34
+ if (proxy)
35
+ setupFn(proxy.proxiedTarget);
36
+ }
37
+ }
38
+ exports.setupDevtoolsPlugin = setupDevtoolsPlugin;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,106 @@
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
+ console.log('settings set', pluginId, value);
45
+ if (pluginId === this.plugin.id) {
46
+ this.fallbacks.setSettings(value);
47
+ }
48
+ });
49
+ this.proxiedOn = new Proxy({}, {
50
+ get: (_target, prop) => {
51
+ if (this.target) {
52
+ return this.target.on[prop];
53
+ }
54
+ else {
55
+ return (...args) => {
56
+ this.onQueue.push({
57
+ method: prop,
58
+ args
59
+ });
60
+ };
61
+ }
62
+ }
63
+ });
64
+ this.proxiedTarget = new Proxy({}, {
65
+ get: (_target, prop) => {
66
+ if (this.target) {
67
+ return this.target[prop];
68
+ }
69
+ else if (prop === 'on') {
70
+ return this.proxiedOn;
71
+ }
72
+ else if (Object.keys(this.fallbacks).includes(prop)) {
73
+ return (...args) => {
74
+ this.targetQueue.push({
75
+ method: prop,
76
+ args,
77
+ resolve: () => { }
78
+ });
79
+ return this.fallbacks[prop](...args);
80
+ };
81
+ }
82
+ else {
83
+ return (...args) => {
84
+ return new Promise(resolve => {
85
+ this.targetQueue.push({
86
+ method: prop,
87
+ args,
88
+ resolve
89
+ });
90
+ });
91
+ };
92
+ }
93
+ }
94
+ });
95
+ }
96
+ async setRealTarget(target) {
97
+ this.target = target;
98
+ for (const item of this.onQueue) {
99
+ this.target.on[item.method](...item.args);
100
+ }
101
+ for (const item of this.targetQueue) {
102
+ item.resolve(await this.target[item.method](...item.args));
103
+ }
104
+ }
105
+ }
106
+ exports.ApiProxy = ApiProxy;
@@ -0,0 +1,102 @@
1
+ import { ComponentBounds, Hookable } from './hooks';
2
+ import { Context } from './context';
3
+ import { ComponentInstance, ComponentState, StateBase } from './component';
4
+ import { App } from './app';
5
+ import { ID } from './util';
6
+ export interface DevtoolsPluginApi<TSettings> {
7
+ on: Hookable<Context>;
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
+ getComponentBounds(instance: ComponentInstance): Promise<ComponentBounds>;
16
+ getComponentName(instance: ComponentInstance): Promise<string>;
17
+ getComponentInstances(app: App): Promise<ComponentInstance[]>;
18
+ highlightElement(instance: ComponentInstance): void;
19
+ unhighlightElement(): void;
20
+ getSettings(): TSettings;
21
+ /**
22
+ * @private Not implemented yet
23
+ */
24
+ setSettings(values: TSettings): void;
25
+ }
26
+ export interface AppRecord {
27
+ id: string;
28
+ name: string;
29
+ instanceMap: Map<string, ComponentInstance>;
30
+ rootInstance: ComponentInstance;
31
+ }
32
+ export interface TimelineLayerOptions<TData = any, TMeta = any> {
33
+ id: string;
34
+ label: string;
35
+ color: number;
36
+ skipScreenshots?: boolean;
37
+ groupsOnly?: boolean;
38
+ ignoreNoDurationGroups?: boolean;
39
+ screenshotOverlayRender?: (event: TimelineEvent<TData, TMeta> & ScreenshotOverlayEvent, ctx: ScreenshotOverlayRenderContext) => ScreenshotOverlayRenderResult | Promise<ScreenshotOverlayRenderResult>;
40
+ }
41
+ export interface ScreenshotOverlayEvent {
42
+ layerId: string;
43
+ renderMeta: any;
44
+ }
45
+ export interface ScreenshotOverlayRenderContext<TData = any, TMeta = any> {
46
+ screenshot: ScreenshotData;
47
+ events: (TimelineEvent<TData, TMeta> & ScreenshotOverlayEvent)[];
48
+ index: number;
49
+ }
50
+ export declare type ScreenshotOverlayRenderResult = HTMLElement | string | false;
51
+ export interface ScreenshotData {
52
+ time: number;
53
+ }
54
+ export interface TimelineEventOptions {
55
+ layerId: string;
56
+ event: TimelineEvent;
57
+ all?: boolean;
58
+ }
59
+ export interface TimelineEvent<TData = any, TMeta = any> {
60
+ time: number;
61
+ data: TData;
62
+ logType?: 'default' | 'warning' | 'error';
63
+ meta?: TMeta;
64
+ groupId?: ID;
65
+ title?: string;
66
+ subtitle?: string;
67
+ }
68
+ export interface TimelineMarkerOptions {
69
+ id: string;
70
+ time: number;
71
+ color: number;
72
+ label: string;
73
+ all?: boolean;
74
+ }
75
+ export interface CustomInspectorOptions {
76
+ id: string;
77
+ label: string;
78
+ icon?: string;
79
+ treeFilterPlaceholder?: string;
80
+ stateFilterPlaceholder?: string;
81
+ noSelectionText?: string;
82
+ actions?: {
83
+ icon: string;
84
+ tooltip?: string;
85
+ action: () => void | Promise<void>;
86
+ }[];
87
+ }
88
+ export interface CustomInspectorNode {
89
+ id: string;
90
+ label: string;
91
+ children?: CustomInspectorNode[];
92
+ tags?: InspectorNodeTag[];
93
+ }
94
+ export interface InspectorNodeTag {
95
+ label: string;
96
+ textColor: number;
97
+ backgroundColor: number;
98
+ tooltip?: string;
99
+ }
100
+ export interface CustomInspectorState {
101
+ [key: string]: (StateBase | Omit<ComponentState, 'type'>)[];
102
+ }
File without changes
@@ -0,0 +1 @@
1
+ export declare type App = any;
File without changes
@@ -0,0 +1,76 @@
1
+ import { InspectorNodeTag } from './api';
2
+ import { ID } from './util';
3
+ export declare type ComponentInstance = any;
4
+ export interface ComponentTreeNode {
5
+ uid: ID;
6
+ id: string;
7
+ name: string;
8
+ renderKey: string | number;
9
+ inactive: boolean;
10
+ isFragment: boolean;
11
+ hasChildren: boolean;
12
+ children: ComponentTreeNode[];
13
+ indexInParent?: number;
14
+ consoleId?: string;
15
+ isRouterView?: boolean;
16
+ macthedRouteSegment?: string;
17
+ tags: InspectorNodeTag[];
18
+ meta?: any;
19
+ }
20
+ export interface InspectedComponentData {
21
+ id: string;
22
+ name: string;
23
+ file: string;
24
+ state: ComponentState[];
25
+ functional?: boolean;
26
+ }
27
+ export interface StateBase {
28
+ key: string;
29
+ value: any;
30
+ editable?: boolean;
31
+ objectType?: 'ref' | 'reactive' | 'computed' | 'other';
32
+ raw?: string;
33
+ }
34
+ export interface ComponentStateBase extends StateBase {
35
+ type: string;
36
+ }
37
+ export interface ComponentPropState extends ComponentStateBase {
38
+ meta?: {
39
+ type: string;
40
+ required: boolean;
41
+ /** Vue 1 only */
42
+ mode?: 'default' | 'sync' | 'once';
43
+ };
44
+ }
45
+ export declare type ComponentBuiltinCustomStateTypes = 'function' | 'map' | 'set' | 'reference' | 'component' | 'component-definition' | 'router' | 'store';
46
+ export interface ComponentCustomState extends ComponentStateBase {
47
+ value: CustomState;
48
+ }
49
+ export declare type CustomState = {
50
+ _custom: {
51
+ type: ComponentBuiltinCustomStateTypes | string;
52
+ display?: string;
53
+ tooltip?: string;
54
+ value?: any;
55
+ abstract?: boolean;
56
+ file?: string;
57
+ uid?: number;
58
+ readOnly?: boolean;
59
+ /** Configure immediate child fields */
60
+ fields?: {
61
+ abstract?: boolean;
62
+ };
63
+ id?: any;
64
+ actions?: {
65
+ icon: string;
66
+ tooltip?: string;
67
+ action: () => void | Promise<void>;
68
+ }[];
69
+ /** internal */
70
+ _reviveId?: number;
71
+ };
72
+ };
73
+ export declare type ComponentState = ComponentStateBase | ComponentPropState | ComponentCustomState;
74
+ export interface ComponentDevtoolsOptions {
75
+ hide?: boolean;
76
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ import { AppRecord } from './api';
2
+ export interface Context {
3
+ currentTab: string;
4
+ currentAppRecord: AppRecord;
5
+ }
File without changes
@@ -0,0 +1,169 @@
1
+ import { ComponentTreeNode, InspectedComponentData, ComponentInstance, ComponentDevtoolsOptions } from './component';
2
+ import { App } from './app';
3
+ import { CustomInspectorNode, CustomInspectorState, TimelineEvent } from './api';
4
+ export declare const enum Hooks {
5
+ TRANSFORM_CALL = "transformCall",
6
+ GET_APP_RECORD_NAME = "getAppRecordName",
7
+ GET_APP_ROOT_INSTANCE = "getAppRootInstance",
8
+ REGISTER_APPLICATION = "registerApplication",
9
+ WALK_COMPONENT_TREE = "walkComponentTree",
10
+ VISIT_COMPONENT_TREE = "visitComponentTree",
11
+ WALK_COMPONENT_PARENTS = "walkComponentParents",
12
+ INSPECT_COMPONENT = "inspectComponent",
13
+ GET_COMPONENT_BOUNDS = "getComponentBounds",
14
+ GET_COMPONENT_NAME = "getComponentName",
15
+ GET_COMPONENT_INSTANCES = "getComponentInstances",
16
+ GET_ELEMENT_COMPONENT = "getElementComponent",
17
+ GET_COMPONENT_ROOT_ELEMENTS = "getComponentRootElements",
18
+ EDIT_COMPONENT_STATE = "editComponentState",
19
+ GET_COMPONENT_DEVTOOLS_OPTIONS = "getAppDevtoolsOptions",
20
+ GET_COMPONENT_RENDER_CODE = "getComponentRenderCode",
21
+ INSPECT_TIMELINE_EVENT = "inspectTimelineEvent",
22
+ TIMELINE_CLEARED = "timelineCleared",
23
+ GET_INSPECTOR_TREE = "getInspectorTree",
24
+ GET_INSPECTOR_STATE = "getInspectorState",
25
+ EDIT_INSPECTOR_STATE = "editInspectorState"
26
+ }
27
+ export interface ComponentBounds {
28
+ left: number;
29
+ top: number;
30
+ width: number;
31
+ height: number;
32
+ }
33
+ export declare type HookPayloads = {
34
+ [Hooks.TRANSFORM_CALL]: {
35
+ callName: string;
36
+ inArgs: any[];
37
+ outArgs: any[];
38
+ };
39
+ [Hooks.GET_APP_RECORD_NAME]: {
40
+ app: App;
41
+ name: string;
42
+ };
43
+ [Hooks.GET_APP_ROOT_INSTANCE]: {
44
+ app: App;
45
+ root: ComponentInstance;
46
+ };
47
+ [Hooks.REGISTER_APPLICATION]: {
48
+ app: App;
49
+ };
50
+ [Hooks.WALK_COMPONENT_TREE]: {
51
+ componentInstance: ComponentInstance;
52
+ componentTreeData: ComponentTreeNode[];
53
+ maxDepth: number;
54
+ filter: string;
55
+ };
56
+ [Hooks.VISIT_COMPONENT_TREE]: {
57
+ app: App;
58
+ componentInstance: ComponentInstance;
59
+ treeNode: ComponentTreeNode;
60
+ filter: string;
61
+ };
62
+ [Hooks.WALK_COMPONENT_PARENTS]: {
63
+ componentInstance: ComponentInstance;
64
+ parentInstances: ComponentInstance[];
65
+ };
66
+ [Hooks.INSPECT_COMPONENT]: {
67
+ app: App;
68
+ componentInstance: ComponentInstance;
69
+ instanceData: InspectedComponentData;
70
+ };
71
+ [Hooks.GET_COMPONENT_BOUNDS]: {
72
+ componentInstance: ComponentInstance;
73
+ bounds: ComponentBounds;
74
+ };
75
+ [Hooks.GET_COMPONENT_NAME]: {
76
+ componentInstance: ComponentInstance;
77
+ name: string;
78
+ };
79
+ [Hooks.GET_COMPONENT_INSTANCES]: {
80
+ app: App;
81
+ componentInstances: ComponentInstance[];
82
+ };
83
+ [Hooks.GET_ELEMENT_COMPONENT]: {
84
+ element: HTMLElement | any;
85
+ componentInstance: ComponentInstance;
86
+ };
87
+ [Hooks.GET_COMPONENT_ROOT_ELEMENTS]: {
88
+ componentInstance: ComponentInstance;
89
+ rootElements: (HTMLElement | any)[];
90
+ };
91
+ [Hooks.EDIT_COMPONENT_STATE]: {
92
+ app: App;
93
+ componentInstance: ComponentInstance;
94
+ path: string[];
95
+ type: string;
96
+ state: EditStatePayload;
97
+ set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void;
98
+ };
99
+ [Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
100
+ componentInstance: ComponentInstance;
101
+ options: ComponentDevtoolsOptions;
102
+ };
103
+ [Hooks.GET_COMPONENT_RENDER_CODE]: {
104
+ componentInstance: ComponentInstance;
105
+ code: string;
106
+ };
107
+ [Hooks.INSPECT_TIMELINE_EVENT]: {
108
+ app: App;
109
+ layerId: string;
110
+ event: TimelineEvent;
111
+ all?: boolean;
112
+ data: any;
113
+ };
114
+ [Hooks.TIMELINE_CLEARED]: Record<string, never>;
115
+ [Hooks.GET_INSPECTOR_TREE]: {
116
+ app: App;
117
+ inspectorId: string;
118
+ filter: string;
119
+ rootNodes: CustomInspectorNode[];
120
+ };
121
+ [Hooks.GET_INSPECTOR_STATE]: {
122
+ app: App;
123
+ inspectorId: string;
124
+ nodeId: string;
125
+ state: CustomInspectorState;
126
+ };
127
+ [Hooks.EDIT_INSPECTOR_STATE]: {
128
+ app: App;
129
+ inspectorId: string;
130
+ nodeId: string;
131
+ path: string[];
132
+ type: string;
133
+ state: EditStatePayload;
134
+ set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void;
135
+ };
136
+ };
137
+ export declare type EditStatePayload = {
138
+ value: any;
139
+ newKey?: string | null;
140
+ remove?: undefined | false;
141
+ } | {
142
+ value?: undefined;
143
+ newKey?: undefined;
144
+ remove: true;
145
+ };
146
+ export declare type HookHandler<TPayload, TContext> = (payload: TPayload, ctx: TContext) => void | Promise<void>;
147
+ export interface Hookable<TContext> {
148
+ transformCall(handler: HookHandler<HookPayloads[Hooks.TRANSFORM_CALL], TContext>): any;
149
+ getAppRecordName(handler: HookHandler<HookPayloads[Hooks.GET_APP_RECORD_NAME], TContext>): any;
150
+ getAppRootInstance(handler: HookHandler<HookPayloads[Hooks.GET_APP_ROOT_INSTANCE], TContext>): any;
151
+ registerApplication(handler: HookHandler<HookPayloads[Hooks.REGISTER_APPLICATION], TContext>): any;
152
+ walkComponentTree(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_TREE], TContext>): any;
153
+ visitComponentTree(handler: HookHandler<HookPayloads[Hooks.VISIT_COMPONENT_TREE], TContext>): any;
154
+ walkComponentParents(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_PARENTS], TContext>): any;
155
+ inspectComponent(handler: HookHandler<HookPayloads[Hooks.INSPECT_COMPONENT], TContext>): any;
156
+ getComponentBounds(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_BOUNDS], TContext>): any;
157
+ getComponentName(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_NAME], TContext>): any;
158
+ getComponentInstances(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_INSTANCES], TContext>): any;
159
+ getElementComponent(handler: HookHandler<HookPayloads[Hooks.GET_ELEMENT_COMPONENT], TContext>): any;
160
+ getComponentRootElements(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>): any;
161
+ editComponentState(handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>): any;
162
+ getComponentDevtoolsOptions(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>): any;
163
+ getComponentRenderCode(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>): any;
164
+ inspectTimelineEvent(handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>): any;
165
+ timelineCleared(handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>): any;
166
+ getInspectorTree(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>): any;
167
+ getInspectorState(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>): any;
168
+ editInspectorState(handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>): any;
169
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ export * from './api';
2
+ export * from './app';
3
+ export * from './component';
4
+ export * from './context';
5
+ export * from './hooks';
6
+ export * from './util';
@@ -0,0 +1,6 @@
1
+ export * from './api';
2
+ export * from './app';
3
+ export * from './component';
4
+ export * from './context';
5
+ export * from './hooks';
6
+ export * from './util';
@@ -0,0 +1,4 @@
1
+ export declare type ID = number | string;
2
+ export interface WithId {
3
+ id: ID;
4
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ export declare const HOOK_SETUP = "devtools-plugin:setup";
2
+ export declare const HOOK_PLUGIN_SETTINGS_SET = "plugin:settings:set";
@@ -0,0 +1,2 @@
1
+ export const HOOK_SETUP = 'devtools-plugin:setup';
2
+ export const HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
@@ -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 ADDED
@@ -0,0 +1,12 @@
1
+ export function getDevtoolsGlobalHook() {
2
+ return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
3
+ }
4
+ export function getTarget() {
5
+ // @ts-ignore
6
+ return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
7
+ ? window
8
+ : typeof global !== 'undefined'
9
+ ? global
10
+ : {};
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;
@@ -0,0 +1,24 @@
1
+ import { getTarget, getDevtoolsGlobalHook, isProxyAvailable } from './env';
2
+ import { HOOK_SETUP } from './const';
3
+ import { ApiProxy } from './proxy';
4
+ export * from './api';
5
+ export * from './plugin';
6
+ export function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
7
+ const target = getTarget();
8
+ const hook = getDevtoolsGlobalHook();
9
+ const enableProxy = isProxyAvailable && pluginDescriptor.enableEarlyProxy;
10
+ if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
11
+ hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
12
+ }
13
+ else {
14
+ const proxy = enableProxy ? new ApiProxy(pluginDescriptor, hook) : null;
15
+ const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
16
+ list.push({
17
+ pluginDescriptor,
18
+ setupFn,
19
+ proxy
20
+ });
21
+ if (proxy)
22
+ setupFn(proxy.proxiedTarget);
23
+ }
24
+ }
@@ -0,0 +1,34 @@
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
+ /**
12
+ * Run the plugin setup and expose the api even if the devtools is not opened yet.
13
+ * Useful to record timeline events early.
14
+ */
15
+ enableEarlyProxy?: boolean;
16
+ settings?: Record<string, PluginSettingsItem>;
17
+ }
18
+ export declare type PluginSettingsItem = {
19
+ label: string;
20
+ } & ({
21
+ type: 'boolean';
22
+ defaultValue: boolean;
23
+ } | {
24
+ type: 'choice';
25
+ defaultValue: string | number;
26
+ options: {
27
+ value: string | number;
28
+ label: string;
29
+ }[];
30
+ component?: 'select' | 'button-group';
31
+ } | {
32
+ type: 'text';
33
+ defaultValue: string;
34
+ });
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 {};
@@ -0,0 +1,102 @@
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
+ console.log('settings set', pluginId, value);
42
+ if (pluginId === this.plugin.id) {
43
+ this.fallbacks.setSettings(value);
44
+ }
45
+ });
46
+ this.proxiedOn = new Proxy({}, {
47
+ get: (_target, prop) => {
48
+ if (this.target) {
49
+ return this.target.on[prop];
50
+ }
51
+ else {
52
+ return (...args) => {
53
+ this.onQueue.push({
54
+ method: prop,
55
+ args
56
+ });
57
+ };
58
+ }
59
+ }
60
+ });
61
+ this.proxiedTarget = new Proxy({}, {
62
+ get: (_target, prop) => {
63
+ if (this.target) {
64
+ return this.target[prop];
65
+ }
66
+ else if (prop === 'on') {
67
+ return this.proxiedOn;
68
+ }
69
+ else if (Object.keys(this.fallbacks).includes(prop)) {
70
+ return (...args) => {
71
+ this.targetQueue.push({
72
+ method: prop,
73
+ args,
74
+ resolve: () => { }
75
+ });
76
+ return this.fallbacks[prop](...args);
77
+ };
78
+ }
79
+ else {
80
+ return (...args) => {
81
+ return new Promise(resolve => {
82
+ this.targetQueue.push({
83
+ method: prop,
84
+ args,
85
+ resolve
86
+ });
87
+ });
88
+ };
89
+ }
90
+ }
91
+ });
92
+ }
93
+ async setRealTarget(target) {
94
+ this.target = target;
95
+ for (const item of this.onQueue) {
96
+ this.target.on[item.method](...item.args);
97
+ }
98
+ for (const item of this.targetQueue) {
99
+ item.resolve(await this.target[item.method](...item.args));
100
+ }
101
+ }
102
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@vue/devtools-api",
3
+ "version": "6.0.0-beta.16",
4
+ "description": "Interact with the Vue devtools from the page",
5
+ "main": "lib/cjs/index.js",
6
+ "browser": "lib/esm/index.js",
7
+ "module": "lib/esm/index.js",
8
+ "types": "lib/esm/index.d.ts",
9
+ "sideEffects": false,
10
+ "author": {
11
+ "name": "Guillaume Chau"
12
+ },
13
+ "files": [
14
+ "lib/esm",
15
+ "lib/cjs"
16
+ ],
17
+ "license": "MIT",
18
+ "repository": {
19
+ "url": "https://github.com/vuejs/vue-devtools.git",
20
+ "type": "git",
21
+ "directory": "packages/api"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "rimraf lib && yarn build:esm && yarn build:cjs",
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"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^13.9.1",
34
+ "@types/webpack-env": "^1.15.1",
35
+ "typescript": "^3.8.3"
36
+ }
37
+ }