@vingy/vuebugger 0.1.1 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.mjs +49 -19
  2. package/package.json +3 -1
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentInstance, toValue, watch } from "vue";
1
+ import { effectScope, getCurrentInstance, getCurrentScope, isReadonly, onScopeDispose, toValue, watch } from "vue";
2
2
 
3
3
  //#region node_modules/.pnpm/@vue+devtools-shared@8.0.5/node_modules/@vue/devtools-shared/dist/index.js
4
4
  var __create$1 = Object.create;
@@ -837,14 +837,14 @@ let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags$1) {
837
837
  /**
838
838
  * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/reactive.ts#L330-L332)
839
839
  */
840
- function isReadonly(value) {
840
+ function isReadonly$1(value) {
841
841
  return !!(value && value[ReactiveFlags.IS_READONLY]);
842
842
  }
843
843
  /**
844
844
  * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/reactive.ts#L312-L317)
845
845
  */
846
846
  function isReactive$1(value) {
847
- if (isReadonly(value)) return isReactive$1(value[ReactiveFlags.RAW]);
847
+ if (isReadonly$1(value)) return isReactive$1(value[ReactiveFlags.RAW]);
848
848
  return !!(value && value[ReactiveFlags.IS_REACTIVE]);
849
849
  }
850
850
  function isRef$1(r) {
@@ -3779,15 +3779,20 @@ target.__VUE_DEVTOOLS_KIT_VITE_RPC_SERVER__ ??= null;
3779
3779
  target.__VUE_DEVTOOLS_KIT_BROADCAST_RPC_SERVER__ ??= null;
3780
3780
  const MAX_SERIALIZED_SIZE = 2 * 1024 * 1024;
3781
3781
 
3782
+ //#endregion
3783
+ //#region src/constants.ts
3784
+ const INSPECTOR_ID = "vuebugger-inspector";
3785
+ const TIMELINE_ID = "vuebugger-timeline";
3786
+
3782
3787
  //#endregion
3783
3788
  //#region src/registry.ts
3784
3789
  const byUid = /* @__PURE__ */ new Map();
3785
3790
  const byGroupId = /* @__PURE__ */ new Map();
3786
3791
  const callbacks = [];
3787
- const runCallbacks = (componentInstance) => callbacks.forEach((cb) => cb(componentInstance));
3792
+ const runCallbacks = (entry) => callbacks.forEach((cb) => cb(entry));
3788
3793
  const withCallbacks = (fn) => (entry) => {
3789
3794
  fn(entry);
3790
- runCallbacks(entry.componentInstance);
3795
+ runCallbacks(entry);
3791
3796
  };
3792
3797
  const upsert = withCallbacks((entry) => {
3793
3798
  const { uid, groupId } = entry;
@@ -3809,7 +3814,6 @@ const onUpdate = (fn) => {
3809
3814
 
3810
3815
  //#endregion
3811
3816
  //#region src/devtools.ts
3812
- const INSPECTOR_ID = "composables";
3813
3817
  const handleGetInspectorTree = (payload) => {
3814
3818
  if (payload.inspectorId === INSPECTOR_ID) {
3815
3819
  const term = payload.filter;
@@ -3842,8 +3846,8 @@ const handleGetInspectorState = (api) => (payload) => {
3842
3846
  if (entry) {
3843
3847
  payload.state = { [payload.nodeId]: Object.entries(entry.debugState).map(([key, value]) => ({
3844
3848
  key,
3845
- value: toValue(value),
3846
- editable: true
3849
+ value,
3850
+ editable: !isReadonly(value)
3847
3851
  })) };
3848
3852
  if (entry.componentInstance) api.highlightElement(entry.componentInstance);
3849
3853
  }
@@ -3854,12 +3858,20 @@ const handleInspectComponent = (payload) => {
3854
3858
  return Object.entries(entry.debugState).map(([key, value]) => ({
3855
3859
  type: entry.uid,
3856
3860
  key,
3857
- value: toValue(value),
3858
- editable: true
3861
+ value,
3862
+ editable: !isReadonly(value)
3859
3863
  }));
3860
3864
  }).toArray();
3861
3865
  payload.instanceData.state.push(...entries);
3862
3866
  };
3867
+ const handleEditInspectorState = (payload) => {
3868
+ if (payload.inspectorId === INSPECTOR_ID) {
3869
+ const uid = payload.nodeId;
3870
+ const entry = byUid.get(uid);
3871
+ if (!entry) return;
3872
+ payload.set(entry.debugState);
3873
+ }
3874
+ };
3863
3875
  function setupComposableDevtools(app) {
3864
3876
  console.log("🐞 Vuebugger ready to use");
3865
3877
  setupDevToolsPlugin({
@@ -3874,14 +3886,29 @@ function setupComposableDevtools(app) {
3874
3886
  icon: "https://raw.githubusercontent.com/vinpogo/vuebugger/main/logo.png",
3875
3887
  treeFilterPlaceholder: "Search by composable or component name..."
3876
3888
  });
3877
- onUpdate((componentInstance) => {
3889
+ api.addTimelineLayer({
3890
+ id: TIMELINE_ID,
3891
+ label: "Vuebugger",
3892
+ color: 155
3893
+ });
3894
+ onUpdate((entry) => {
3878
3895
  api.sendInspectorTree(INSPECTOR_ID);
3879
3896
  api.sendInspectorState(INSPECTOR_ID);
3880
- api.notifyComponentUpdate(componentInstance);
3897
+ api.notifyComponentUpdate(entry.componentInstance);
3898
+ api.addTimelineEvent({
3899
+ layerId: TIMELINE_ID,
3900
+ event: {
3901
+ time: api.now(),
3902
+ data: entry,
3903
+ title: `${entry.uid} state change`,
3904
+ groupId: entry.uid
3905
+ }
3906
+ });
3881
3907
  });
3882
3908
  api.on.getInspectorTree(handleGetInspectorTree);
3883
3909
  api.on.getInspectorState(handleGetInspectorState(api));
3884
3910
  api.on.inspectComponent(handleInspectComponent);
3911
+ api.on.editInspectorState(handleEditInspectorState);
3885
3912
  });
3886
3913
  }
3887
3914
 
@@ -3892,24 +3919,27 @@ function debug(groupId, state) {
3892
3919
  const instance = getCurrentInstance();
3893
3920
  const componentName = instance?.type.name || instance?.type.__name || "No component";
3894
3921
  const uid = `${componentName}/${groupId}-${Math.random().toString(36).slice(2, 9)}`;
3895
- watch(() => state, (value, _, onCleanup) => {
3896
- upsert({
3922
+ (getCurrentScope() ?? effectScope()).run(() => {
3923
+ onScopeDispose(() => remove({
3897
3924
  groupId,
3898
3925
  uid,
3899
3926
  componentName,
3900
3927
  componentInstance: instance,
3901
- debugState: value
3902
- });
3903
- onCleanup(() => {
3904
- remove({
3928
+ debugState: state
3929
+ }));
3930
+ watch(() => state, (value, _) => {
3931
+ upsert({
3905
3932
  groupId,
3906
3933
  uid,
3907
3934
  componentName,
3908
3935
  componentInstance: instance,
3909
3936
  debugState: value
3910
3937
  });
3938
+ }, {
3939
+ immediate: true,
3940
+ deep: true
3911
3941
  });
3912
- }, { deep: true });
3942
+ });
3913
3943
  return state;
3914
3944
  }
3915
3945
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vingy/vuebugger",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Vue devtools plugin to debug anything.",
5
5
  "keywords": [
6
6
  "composable",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^25.0.10",
38
+ "@vitest/coverage-v8": "4.0.18",
38
39
  "@vue/devtools-api": "^8.0.5",
39
40
  "oxfmt": "^0.27.0",
40
41
  "oxlint": "^1.42.0",
@@ -47,6 +48,7 @@
47
48
  },
48
49
  "scripts": {
49
50
  "test": "vitest",
51
+ "test:ci": "vitest run --coverage",
50
52
  "build": "tsdown",
51
53
  "dev": "tsdown -w"
52
54
  }