@vue/devtools-api 6.0.0-beta.9 → 6.0.3

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;
@@ -3,22 +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): any;
9
- addTimelineLayer(options: TimelineLayerOptions): any;
10
- addTimelineEvent(options: TimelineEventOptions): any;
11
- addInspector(options: CustomInspectorOptions): any;
12
- sendInspectorTree(inspectorId: string): any;
13
- 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;
14
15
  getComponentBounds(instance: ComponentInstance): Promise<ComponentBounds>;
15
16
  getComponentName(instance: ComponentInstance): Promise<string>;
16
17
  getComponentInstances(app: App): Promise<ComponentInstance[]>;
17
- highlightElement(instance: ComponentInstance): any;
18
- unhighlightElement(): any;
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;
19
25
  }
20
26
  export interface AppRecord {
21
- id: number;
27
+ id: string;
22
28
  name: string;
23
29
  instanceMap: Map<string, ComponentInstance>;
24
30
  rootInstance: ComponentInstance;
@@ -27,6 +33,9 @@ export interface TimelineLayerOptions<TData = any, TMeta = any> {
27
33
  id: string;
28
34
  label: string;
29
35
  color: number;
36
+ skipScreenshots?: boolean;
37
+ groupsOnly?: boolean;
38
+ ignoreNoDurationGroups?: boolean;
30
39
  screenshotOverlayRender?: (event: TimelineEvent<TData, TMeta> & ScreenshotOverlayEvent, ctx: ScreenshotOverlayRenderContext) => ScreenshotOverlayRenderResult | Promise<ScreenshotOverlayRenderResult>;
31
40
  }
32
41
  export interface ScreenshotOverlayEvent {
@@ -56,6 +65,13 @@ export interface TimelineEvent<TData = any, TMeta = any> {
56
65
  title?: string;
57
66
  subtitle?: string;
58
67
  }
68
+ export interface TimelineMarkerOptions {
69
+ id: string;
70
+ time: number;
71
+ color: number;
72
+ label: string;
73
+ all?: boolean;
74
+ }
59
75
  export interface CustomInspectorOptions {
60
76
  id: string;
61
77
  label: string;
@@ -63,6 +79,11 @@ export interface CustomInspectorOptions {
63
79
  treeFilterPlaceholder?: string;
64
80
  stateFilterPlaceholder?: string;
65
81
  noSelectionText?: string;
82
+ actions?: {
83
+ icon: string;
84
+ tooltip?: string;
85
+ action: () => void | Promise<void>;
86
+ }[];
66
87
  }
67
88
  export interface CustomInspectorNode {
68
89
  id: string;
@@ -74,6 +95,7 @@ export interface InspectorNodeTag {
74
95
  label: string;
75
96
  textColor: number;
76
97
  backgroundColor: number;
98
+ tooltip?: string;
77
99
  }
78
100
  export interface CustomInspectorState {
79
101
  [key: string]: (StateBase | Omit<ComponentState, 'type'>)[];
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,16 @@
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 | string;
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;
@@ -43,23 +44,32 @@ export interface ComponentPropState extends ComponentStateBase {
43
44
  }
44
45
  export declare type ComponentBuiltinCustomStateTypes = 'function' | 'map' | 'set' | 'reference' | 'component' | 'component-definition' | 'router' | 'store';
45
46
  export interface ComponentCustomState extends ComponentStateBase {
46
- value: {
47
- _custom: {
48
- type: ComponentBuiltinCustomStateTypes | string;
49
- display?: string;
50
- tooltip?: string;
51
- 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?: {
52
61
  abstract?: boolean;
53
- file?: string;
54
- uid?: number;
55
- readOnly?: boolean;
56
- /** Configure immediate child fields */
57
- fields?: {
58
- abstract?: boolean;
59
- };
60
62
  };
63
+ id?: any;
64
+ actions?: {
65
+ icon: string;
66
+ tooltip?: string;
67
+ action: () => void | Promise<void>;
68
+ }[];
69
+ /** internal */
70
+ _reviveId?: number;
61
71
  };
62
- }
72
+ };
63
73
  export declare type ComponentState = ComponentStateBase | ComponentPropState | ComponentCustomState;
64
74
  export interface ComponentDevtoolsOptions {
65
75
  hide?: boolean;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -17,10 +17,13 @@ export declare const enum Hooks {
17
17
  GET_COMPONENT_ROOT_ELEMENTS = "getComponentRootElements",
18
18
  EDIT_COMPONENT_STATE = "editComponentState",
19
19
  GET_COMPONENT_DEVTOOLS_OPTIONS = "getAppDevtoolsOptions",
20
+ GET_COMPONENT_RENDER_CODE = "getComponentRenderCode",
20
21
  INSPECT_TIMELINE_EVENT = "inspectTimelineEvent",
22
+ TIMELINE_CLEARED = "timelineCleared",
21
23
  GET_INSPECTOR_TREE = "getInspectorTree",
22
24
  GET_INSPECTOR_STATE = "getInspectorState",
23
- EDIT_INSPECTOR_STATE = "editInspectorState"
25
+ EDIT_INSPECTOR_STATE = "editInspectorState",
26
+ SET_PLUGIN_SETTINGS = "setPluginSettings"
24
27
  }
25
28
  export interface ComponentBounds {
26
29
  left: number;
@@ -52,6 +55,7 @@ export declare type HookPayloads = {
52
55
  filter: string;
53
56
  };
54
57
  [Hooks.VISIT_COMPONENT_TREE]: {
58
+ app: App;
55
59
  componentInstance: ComponentInstance;
56
60
  treeNode: ComponentTreeNode;
57
61
  filter: string;
@@ -61,6 +65,7 @@ export declare type HookPayloads = {
61
65
  parentInstances: ComponentInstance[];
62
66
  };
63
67
  [Hooks.INSPECT_COMPONENT]: {
68
+ app: App;
64
69
  componentInstance: ComponentInstance;
65
70
  instanceData: InspectedComponentData;
66
71
  };
@@ -85,14 +90,21 @@ export declare type HookPayloads = {
85
90
  rootElements: (HTMLElement | any)[];
86
91
  };
87
92
  [Hooks.EDIT_COMPONENT_STATE]: {
93
+ app: App;
88
94
  componentInstance: ComponentInstance;
89
95
  path: string[];
96
+ type: string;
90
97
  state: EditStatePayload;
98
+ set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
91
99
  };
92
100
  [Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
93
101
  componentInstance: ComponentInstance;
94
102
  options: ComponentDevtoolsOptions;
95
103
  };
104
+ [Hooks.GET_COMPONENT_RENDER_CODE]: {
105
+ componentInstance: ComponentInstance;
106
+ code: string;
107
+ };
96
108
  [Hooks.INSPECT_TIMELINE_EVENT]: {
97
109
  app: App;
98
110
  layerId: string;
@@ -100,6 +112,7 @@ export declare type HookPayloads = {
100
112
  all?: boolean;
101
113
  data: any;
102
114
  };
115
+ [Hooks.TIMELINE_CLEARED]: Record<string, never>;
103
116
  [Hooks.GET_INSPECTOR_TREE]: {
104
117
  app: App;
105
118
  inspectorId: string;
@@ -117,8 +130,17 @@ export declare type HookPayloads = {
117
130
  inspectorId: string;
118
131
  nodeId: string;
119
132
  path: string[];
133
+ type: string;
120
134
  state: EditStatePayload;
121
- set: (object: any, path: string | (string[]), value: any, cb?: (object: any, field: string, value: any) => void) => void;
135
+ set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
136
+ };
137
+ [Hooks.SET_PLUGIN_SETTINGS]: {
138
+ app: App;
139
+ pluginId: string;
140
+ key: string;
141
+ newValue: any;
142
+ oldValue: any;
143
+ settings: any;
122
144
  };
123
145
  };
124
146
  export declare type EditStatePayload = {
@@ -147,8 +169,11 @@ export interface Hookable<TContext> {
147
169
  getComponentRootElements(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>): any;
148
170
  editComponentState(handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>): any;
149
171
  getComponentDevtoolsOptions(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>): any;
172
+ getComponentRenderCode(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>): any;
150
173
  inspectTimelineEvent(handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>): any;
174
+ timelineCleared(handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>): any;
151
175
  getInspectorTree(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>): any;
152
176
  getInspectorState(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>): any;
153
177
  editInspectorState(handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>): any;
178
+ setPluginSettings(handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>): any;
154
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.9",
3
+ "version": "6.0.3",
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,13 +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
- }
12
- export declare type SetupFunction = (api: DevtoolsPluginApi) => void;
13
- export declare function setupDevtoolsPlugin(pluginDescriptor: PluginDescriptor, setupFn: SetupFunction): void;