@vue/devtools-api 6.0.0-beta.6 → 6.0.0

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.
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
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);
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./api"), exports);
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
@@ -7,25 +7,32 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
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);
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  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) {
18
- const hook = env_1.getDevtoolsGlobalHook();
19
- if (hook) {
20
+ const target = (0, env_1.getTarget)();
21
+ const hook = (0, env_1.getDevtoolsGlobalHook)();
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 target = env_1.getTarget();
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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,107 @@
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 = Object.assign({}, 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
+ if (hook) {
44
+ hook.on(const_1.HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
45
+ if (pluginId === this.plugin.id) {
46
+ this.fallbacks.setSettings(value);
47
+ }
48
+ });
49
+ }
50
+ this.proxiedOn = new Proxy({}, {
51
+ get: (_target, prop) => {
52
+ if (this.target) {
53
+ return this.target.on[prop];
54
+ }
55
+ else {
56
+ return (...args) => {
57
+ this.onQueue.push({
58
+ method: prop,
59
+ args,
60
+ });
61
+ };
62
+ }
63
+ },
64
+ });
65
+ this.proxiedTarget = new Proxy({}, {
66
+ get: (_target, prop) => {
67
+ if (this.target) {
68
+ return this.target[prop];
69
+ }
70
+ else if (prop === 'on') {
71
+ return this.proxiedOn;
72
+ }
73
+ else if (Object.keys(this.fallbacks).includes(prop)) {
74
+ return (...args) => {
75
+ this.targetQueue.push({
76
+ method: prop,
77
+ args,
78
+ resolve: () => { },
79
+ });
80
+ return this.fallbacks[prop](...args);
81
+ };
82
+ }
83
+ else {
84
+ return (...args) => {
85
+ return new Promise(resolve => {
86
+ this.targetQueue.push({
87
+ method: prop,
88
+ args,
89
+ resolve,
90
+ });
91
+ });
92
+ };
93
+ }
94
+ },
95
+ });
96
+ }
97
+ async setRealTarget(target) {
98
+ this.target = target;
99
+ for (const item of this.onQueue) {
100
+ this.target.on[item.method](...item.args);
101
+ }
102
+ for (const item of this.targetQueue) {
103
+ item.resolve(await this.target[item.method](...item.args));
104
+ }
105
+ }
106
+ }
107
+ exports.ApiProxy = ApiProxy;
@@ -1,20 +1,30 @@
1
1
  import { ComponentBounds, Hookable } from './hooks';
2
2
  import { Context } from './context';
3
3
  import { ComponentInstance, ComponentState, StateBase } from './component';
4
+ import { App } from './app';
4
5
  import { ID } from './util';
5
- export interface DevtoolsPluginApi {
6
+ export interface DevtoolsPluginApi<TSettings> {
6
7
  on: Hookable<Context>;
7
- notifyComponentUpdate(instance: ComponentInstance): any;
8
- addTimelineLayer(options: TimelineLayerOptions): any;
9
- addTimelineEvent(options: TimelineEventOptions): any;
10
- addInspector(options: CustomInspectorOptions): any;
11
- sendInspectorTree(inspectorId: string): any;
12
- sendInspectorState(inspectorId: string): any;
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;
13
15
  getComponentBounds(instance: ComponentInstance): Promise<ComponentBounds>;
14
16
  getComponentName(instance: ComponentInstance): Promise<string>;
17
+ getComponentInstances(app: App): Promise<ComponentInstance[]>;
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;
15
25
  }
16
26
  export interface AppRecord {
17
- id: number;
27
+ id: string;
18
28
  name: string;
19
29
  instanceMap: Map<string, ComponentInstance>;
20
30
  rootInstance: ComponentInstance;
@@ -23,6 +33,9 @@ export interface TimelineLayerOptions<TData = any, TMeta = any> {
23
33
  id: string;
24
34
  label: string;
25
35
  color: number;
36
+ skipScreenshots?: boolean;
37
+ groupsOnly?: boolean;
38
+ ignoreNoDurationGroups?: boolean;
26
39
  screenshotOverlayRender?: (event: TimelineEvent<TData, TMeta> & ScreenshotOverlayEvent, ctx: ScreenshotOverlayRenderContext) => ScreenshotOverlayRenderResult | Promise<ScreenshotOverlayRenderResult>;
27
40
  }
28
41
  export interface ScreenshotOverlayEvent {
@@ -52,12 +65,25 @@ export interface TimelineEvent<TData = any, TMeta = any> {
52
65
  title?: string;
53
66
  subtitle?: string;
54
67
  }
68
+ export interface TimelineMarkerOptions {
69
+ id: string;
70
+ time: number;
71
+ color: number;
72
+ label: string;
73
+ all?: boolean;
74
+ }
55
75
  export interface CustomInspectorOptions {
56
76
  id: string;
57
77
  label: string;
58
78
  icon?: string;
59
79
  treeFilterPlaceholder?: string;
60
80
  stateFilterPlaceholder?: string;
81
+ noSelectionText?: string;
82
+ actions?: {
83
+ icon: string;
84
+ tooltip?: string;
85
+ action: () => void | Promise<void>;
86
+ }[];
61
87
  }
62
88
  export interface CustomInspectorNode {
63
89
  id: string;
@@ -69,7 +95,8 @@ export interface InspectorNodeTag {
69
95
  label: string;
70
96
  textColor: number;
71
97
  backgroundColor: number;
98
+ tooltip?: string;
72
99
  }
73
100
  export interface CustomInspectorState {
74
- [key: string]: (StateBase | ComponentState)[];
101
+ [key: string]: (StateBase | Omit<ComponentState, 'type'>)[];
75
102
  }
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,21 @@
1
1
  import { InspectorNodeTag } from './api';
2
+ import { ID } from './util';
2
3
  export declare type ComponentInstance = any;
3
4
  export interface ComponentTreeNode {
4
- uid: number;
5
+ uid: ID;
5
6
  id: string;
6
7
  name: string;
7
- renderKey: string;
8
+ renderKey: string | number;
8
9
  inactive: boolean;
9
10
  isFragment: boolean;
10
11
  hasChildren: boolean;
11
12
  children: ComponentTreeNode[];
12
- positionTop?: number;
13
+ domOrder?: number[];
13
14
  consoleId?: string;
14
15
  isRouterView?: boolean;
15
16
  macthedRouteSegment?: string;
16
17
  tags: InspectorNodeTag[];
18
+ meta?: any;
17
19
  }
18
20
  export interface InspectedComponentData {
19
21
  id: string;
@@ -25,7 +27,7 @@ export interface InspectedComponentData {
25
27
  export interface StateBase {
26
28
  key: string;
27
29
  value: any;
28
- editable: boolean;
30
+ editable?: boolean;
29
31
  objectType?: 'ref' | 'reactive' | 'computed' | 'other';
30
32
  raw?: string;
31
33
  }
@@ -42,21 +44,33 @@ export interface ComponentPropState extends ComponentStateBase {
42
44
  }
43
45
  export declare type ComponentBuiltinCustomStateTypes = 'function' | 'map' | 'set' | 'reference' | 'component' | 'component-definition' | 'router' | 'store';
44
46
  export interface ComponentCustomState extends ComponentStateBase {
45
- value: {
46
- _custom: {
47
- type: ComponentBuiltinCustomStateTypes | string;
48
- display?: string;
49
- tooltip?: string;
50
- value?: any;
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?: {
51
61
  abstract?: boolean;
52
- file?: string;
53
- uid?: number;
54
- readOnly?: boolean;
55
- /** Configure immediate child fields */
56
- fields?: {
57
- abstract?: boolean;
58
- };
59
62
  };
63
+ id?: any;
64
+ actions?: {
65
+ icon: string;
66
+ tooltip?: string;
67
+ action: () => void | Promise<void>;
68
+ }[];
69
+ /** internal */
70
+ _reviveId?: number;
60
71
  };
61
- }
72
+ };
62
73
  export declare type ComponentState = ComponentStateBase | ComponentPropState | ComponentCustomState;
74
+ export interface ComponentDevtoolsOptions {
75
+ hide?: boolean;
76
+ }
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { ComponentTreeNode, InspectedComponentData, ComponentInstance } from './component';
1
+ import { ComponentTreeNode, InspectedComponentData, ComponentInstance, ComponentDevtoolsOptions } from './component';
2
2
  import { App } from './app';
3
3
  import { CustomInspectorNode, CustomInspectorState, TimelineEvent } from './api';
4
4
  export declare const enum Hooks {
@@ -7,17 +7,23 @@ export declare const enum Hooks {
7
7
  GET_APP_ROOT_INSTANCE = "getAppRootInstance",
8
8
  REGISTER_APPLICATION = "registerApplication",
9
9
  WALK_COMPONENT_TREE = "walkComponentTree",
10
+ VISIT_COMPONENT_TREE = "visitComponentTree",
10
11
  WALK_COMPONENT_PARENTS = "walkComponentParents",
11
12
  INSPECT_COMPONENT = "inspectComponent",
12
13
  GET_COMPONENT_BOUNDS = "getComponentBounds",
13
14
  GET_COMPONENT_NAME = "getComponentName",
15
+ GET_COMPONENT_INSTANCES = "getComponentInstances",
14
16
  GET_ELEMENT_COMPONENT = "getElementComponent",
15
17
  GET_COMPONENT_ROOT_ELEMENTS = "getComponentRootElements",
16
18
  EDIT_COMPONENT_STATE = "editComponentState",
19
+ GET_COMPONENT_DEVTOOLS_OPTIONS = "getAppDevtoolsOptions",
20
+ GET_COMPONENT_RENDER_CODE = "getComponentRenderCode",
17
21
  INSPECT_TIMELINE_EVENT = "inspectTimelineEvent",
22
+ TIMELINE_CLEARED = "timelineCleared",
18
23
  GET_INSPECTOR_TREE = "getInspectorTree",
19
24
  GET_INSPECTOR_STATE = "getInspectorState",
20
- EDIT_INSPECTOR_STATE = "editInspectorState"
25
+ EDIT_INSPECTOR_STATE = "editInspectorState",
26
+ SET_PLUGIN_SETTINGS = "setPluginSettings"
21
27
  }
22
28
  export interface ComponentBounds {
23
29
  left: number;
@@ -48,11 +54,18 @@ export declare type HookPayloads = {
48
54
  maxDepth: number;
49
55
  filter: string;
50
56
  };
57
+ [Hooks.VISIT_COMPONENT_TREE]: {
58
+ app: App;
59
+ componentInstance: ComponentInstance;
60
+ treeNode: ComponentTreeNode;
61
+ filter: string;
62
+ };
51
63
  [Hooks.WALK_COMPONENT_PARENTS]: {
52
64
  componentInstance: ComponentInstance;
53
65
  parentInstances: ComponentInstance[];
54
66
  };
55
67
  [Hooks.INSPECT_COMPONENT]: {
68
+ app: App;
56
69
  componentInstance: ComponentInstance;
57
70
  instanceData: InspectedComponentData;
58
71
  };
@@ -64,6 +77,10 @@ export declare type HookPayloads = {
64
77
  componentInstance: ComponentInstance;
65
78
  name: string;
66
79
  };
80
+ [Hooks.GET_COMPONENT_INSTANCES]: {
81
+ app: App;
82
+ componentInstances: ComponentInstance[];
83
+ };
67
84
  [Hooks.GET_ELEMENT_COMPONENT]: {
68
85
  element: HTMLElement | any;
69
86
  componentInstance: ComponentInstance;
@@ -73,16 +90,29 @@ export declare type HookPayloads = {
73
90
  rootElements: (HTMLElement | any)[];
74
91
  };
75
92
  [Hooks.EDIT_COMPONENT_STATE]: {
93
+ app: App;
76
94
  componentInstance: ComponentInstance;
77
95
  path: string[];
96
+ type: string;
78
97
  state: EditStatePayload;
98
+ set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
99
+ };
100
+ [Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
101
+ componentInstance: ComponentInstance;
102
+ options: ComponentDevtoolsOptions;
103
+ };
104
+ [Hooks.GET_COMPONENT_RENDER_CODE]: {
105
+ componentInstance: ComponentInstance;
106
+ code: string;
79
107
  };
80
108
  [Hooks.INSPECT_TIMELINE_EVENT]: {
109
+ app: App;
81
110
  layerId: string;
82
111
  event: TimelineEvent;
83
112
  all?: boolean;
84
113
  data: any;
85
114
  };
115
+ [Hooks.TIMELINE_CLEARED]: Record<string, never>;
86
116
  [Hooks.GET_INSPECTOR_TREE]: {
87
117
  app: App;
88
118
  inspectorId: string;
@@ -100,9 +130,18 @@ export declare type HookPayloads = {
100
130
  inspectorId: string;
101
131
  nodeId: string;
102
132
  path: string[];
133
+ type: string;
103
134
  state: EditStatePayload;
104
135
  set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void;
105
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
+ };
106
145
  };
107
146
  export declare type EditStatePayload = {
108
147
  value: any;
@@ -120,15 +159,21 @@ export interface Hookable<TContext> {
120
159
  getAppRootInstance(handler: HookHandler<HookPayloads[Hooks.GET_APP_ROOT_INSTANCE], TContext>): any;
121
160
  registerApplication(handler: HookHandler<HookPayloads[Hooks.REGISTER_APPLICATION], TContext>): any;
122
161
  walkComponentTree(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_TREE], TContext>): any;
162
+ visitComponentTree(handler: HookHandler<HookPayloads[Hooks.VISIT_COMPONENT_TREE], TContext>): any;
123
163
  walkComponentParents(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_PARENTS], TContext>): any;
124
164
  inspectComponent(handler: HookHandler<HookPayloads[Hooks.INSPECT_COMPONENT], TContext>): any;
125
165
  getComponentBounds(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_BOUNDS], TContext>): any;
126
166
  getComponentName(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_NAME], TContext>): any;
167
+ getComponentInstances(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_INSTANCES], TContext>): any;
127
168
  getElementComponent(handler: HookHandler<HookPayloads[Hooks.GET_ELEMENT_COMPONENT], TContext>): any;
128
169
  getComponentRootElements(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>): any;
129
170
  editComponentState(handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>): any;
171
+ getComponentDevtoolsOptions(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>): any;
172
+ getComponentRenderCode(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>): any;
130
173
  inspectTimelineEvent(handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>): any;
174
+ timelineCleared(handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>): any;
131
175
  getInspectorTree(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>): any;
132
176
  getInspectorState(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>): any;
133
177
  editInspectorState(handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>): any;
178
+ setPluginSettings(handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>): any;
134
179
  }
@@ -0,0 +1 @@
1
+ export {};
File without changes
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const HOOK_SETUP = "devtools-plugin:setup";
2
+ export declare const HOOK_PLUGIN_SETTINGS_SET = "plugin:settings:set";
package/lib/esm/const.js CHANGED
@@ -1 +1,2 @@
1
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 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
- if (hook) {
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 target = getTarget();
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -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,103 @@
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 = Object.assign({}, 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
+ if (hook) {
41
+ hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
42
+ if (pluginId === this.plugin.id) {
43
+ this.fallbacks.setSettings(value);
44
+ }
45
+ });
46
+ }
47
+ this.proxiedOn = new Proxy({}, {
48
+ get: (_target, prop) => {
49
+ if (this.target) {
50
+ return this.target.on[prop];
51
+ }
52
+ else {
53
+ return (...args) => {
54
+ this.onQueue.push({
55
+ method: prop,
56
+ args,
57
+ });
58
+ };
59
+ }
60
+ },
61
+ });
62
+ this.proxiedTarget = new Proxy({}, {
63
+ get: (_target, prop) => {
64
+ if (this.target) {
65
+ return this.target[prop];
66
+ }
67
+ else if (prop === 'on') {
68
+ return this.proxiedOn;
69
+ }
70
+ else if (Object.keys(this.fallbacks).includes(prop)) {
71
+ return (...args) => {
72
+ this.targetQueue.push({
73
+ method: prop,
74
+ args,
75
+ resolve: () => { },
76
+ });
77
+ return this.fallbacks[prop](...args);
78
+ };
79
+ }
80
+ else {
81
+ return (...args) => {
82
+ return new Promise(resolve => {
83
+ this.targetQueue.push({
84
+ method: prop,
85
+ args,
86
+ resolve,
87
+ });
88
+ });
89
+ };
90
+ }
91
+ },
92
+ });
93
+ }
94
+ async setRealTarget(target) {
95
+ this.target = target;
96
+ for (const item of this.onQueue) {
97
+ this.target.on[item.method](...item.args);
98
+ }
99
+ for (const item of this.targetQueue) {
100
+ item.resolve(await this.target[item.method](...item.args));
101
+ }
102
+ }
103
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@vue/devtools-api",
3
- "version": "6.0.0-beta.6",
3
+ "version": "6.0.0",
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/cjs/index.d.ts",
8
+ "types": "lib/esm/index.d.ts",
9
9
  "sideEffects": false,
10
10
  "author": {
11
11
  "name": "Guillaume Chau"
@@ -25,14 +25,13 @@
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 -d",
30
- "build:watch": "yarn tsc --module commonjs --outDir lib/cjs -d -w --sourceMap",
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",
35
34
  "@types/webpack-env": "^1.15.1",
36
- "typescript": "^3.8.3"
35
+ "typescript": "^4.5.2"
37
36
  }
38
37
  }
@@ -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 {};
@@ -1,12 +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
- }
11
- export declare type SetupFunction = (api: DevtoolsPluginApi) => void;
12
- export declare function setupDevtoolsPlugin(pluginDescriptor: PluginDescriptor, setupFn: SetupFunction): void;