Skip to content

Commit fd0b795

Browse files
improve
1 parent 6c637fb commit fd0b795

File tree

10 files changed

+238
-50
lines changed

10 files changed

+238
-50
lines changed

chrome/public/bundle/detector.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@
964964
DevToolMessageEnum["source"] = "source";
965965
DevToolMessageEnum["detail"] = "detail";
966966
DevToolMessageEnum["unmount"] = "unmount";
967+
DevToolMessageEnum["select-sync"] = "select-sync";
967968
DevToolMessageEnum["select-unmount"] = "select-unmount";
968969
DevToolMessageEnum["message"] = "message";
969970
DevToolMessageEnum["warn"] = "warn";
@@ -2064,6 +2065,8 @@
20642065
this._warn = {};
20652066
this._hoverId = "";
20662067
this._selectId = "";
2068+
this._selectDom = null;
2069+
this._hasSelectChange = false;
20672070
this._tempDomHoverId = "";
20682071
this._domHoverId = "";
20692072
this._trigger = {};
@@ -2089,6 +2092,7 @@
20892092
_this.notifyDispatch(dispatch);
20902093
});
20912094
}
2095+
_this.notifySelectSync();
20922096
_this.notifyConfig();
20932097
_this.notifyDir();
20942098
_this.notifyTrigger();
@@ -2369,7 +2373,23 @@
23692373
return current;
23702374
};
23712375
DevToolCore.prototype.setSelect = function (id) {
2376+
var fiber = getFiberNodeById(id);
2377+
if (!fiber)
2378+
return;
2379+
var domArray = getElementNodesFromFiber(fiber);
2380+
this._selectId = id;
2381+
this._selectDom = domArray[0];
2382+
};
2383+
DevToolCore.prototype.setSelectDom = function (dom) {
2384+
var fiber = getComponentFiberByDom(dom);
2385+
if (!fiber)
2386+
return;
2387+
var id = getPlainNodeIdByFiber(fiber);
2388+
if (id === this._selectId)
2389+
return;
23722390
this._selectId = id;
2391+
this._selectDom = dom;
2392+
this._hasSelectChange = true;
23732393
};
23742394
DevToolCore.prototype.setHover = function (id) {
23752395
this._hoverId = id;
@@ -2397,22 +2417,20 @@
23972417
DevToolCore.prototype.inspectDom = function () {
23982418
if (!this.hasEnable)
23992419
return;
2400-
var fiber = getFiberNodeById(this._selectId);
2401-
var domArray = getElementNodesFromFiber(fiber);
2402-
var dom = domArray[0];
2403-
if (typeof inspect === "function" && dom) {
2404-
inspect(dom);
2420+
var dom = this._selectDom;
2421+
if (typeof globalThis['inspect'] === "function" && dom) {
2422+
globalThis['inspect'](dom);
24052423
return;
24062424
}
24072425
this.notifyMessage("current id: ".concat(this._selectId, " of fiber not contain dom node"), "warning");
24082426
};
24092427
DevToolCore.prototype.inspectSource = function () {
24102428
if (!this.hasEnable)
24112429
return;
2412-
if (typeof this._source === "function") {
2430+
if (typeof this._source === "function" && typeof globalThis['inspect'] === "function") {
24132431
var s = this._source;
24142432
this._source = null;
2415-
inspect(s);
2433+
globalThis['inspect'](s);
24162434
return;
24172435
}
24182436
this.notifyMessage("can not view source for current item", "warning");
@@ -2501,6 +2519,14 @@
25012519
this._notify({ type: exports.DevToolMessageEnum.detail, data: null });
25022520
}
25032521
};
2522+
DevToolCore.prototype.notifySelectSync = function () {
2523+
if (!this.hasEnable)
2524+
return;
2525+
if (this._hasSelectChange) {
2526+
this._hasSelectChange = false;
2527+
this._notify({ type: exports.DevToolMessageEnum["select-sync"], data: this._selectId });
2528+
}
2529+
};
25042530
DevToolCore.prototype.notifyUnSelect = function () {
25052531
if (!this.hasEnable)
25062532
return;
@@ -2571,6 +2597,7 @@
25712597
this._hmr = {};
25722598
this._hoverId = "";
25732599
this._selectId = "";
2600+
this._selectDom = null;
25742601
this._source = null;
25752602
this._hmrStatus = {};
25762603
this._domHoverId = "";

chrome/public/bundle/hook.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@
966966
DevToolMessageEnum["source"] = "source";
967967
DevToolMessageEnum["detail"] = "detail";
968968
DevToolMessageEnum["unmount"] = "unmount";
969+
DevToolMessageEnum["select-sync"] = "select-sync";
969970
DevToolMessageEnum["select-unmount"] = "select-unmount";
970971
DevToolMessageEnum["message"] = "message";
971972
DevToolMessageEnum["warn"] = "warn";
@@ -2066,6 +2067,8 @@
20662067
this._warn = {};
20672068
this._hoverId = "";
20682069
this._selectId = "";
2070+
this._selectDom = null;
2071+
this._hasSelectChange = false;
20692072
this._tempDomHoverId = "";
20702073
this._domHoverId = "";
20712074
this._trigger = {};
@@ -2091,6 +2094,7 @@
20912094
_this.notifyDispatch(dispatch);
20922095
});
20932096
}
2097+
_this.notifySelectSync();
20942098
_this.notifyConfig();
20952099
_this.notifyDir();
20962100
_this.notifyTrigger();
@@ -2371,7 +2375,23 @@
23712375
return current;
23722376
};
23732377
DevToolCore.prototype.setSelect = function (id) {
2378+
var fiber = getFiberNodeById(id);
2379+
if (!fiber)
2380+
return;
2381+
var domArray = getElementNodesFromFiber(fiber);
2382+
this._selectId = id;
2383+
this._selectDom = domArray[0];
2384+
};
2385+
DevToolCore.prototype.setSelectDom = function (dom) {
2386+
var fiber = getComponentFiberByDom(dom);
2387+
if (!fiber)
2388+
return;
2389+
var id = getPlainNodeIdByFiber(fiber);
2390+
if (id === this._selectId)
2391+
return;
23742392
this._selectId = id;
2393+
this._selectDom = dom;
2394+
this._hasSelectChange = true;
23752395
};
23762396
DevToolCore.prototype.setHover = function (id) {
23772397
this._hoverId = id;
@@ -2399,22 +2419,20 @@
23992419
DevToolCore.prototype.inspectDom = function () {
24002420
if (!this.hasEnable)
24012421
return;
2402-
var fiber = getFiberNodeById(this._selectId);
2403-
var domArray = getElementNodesFromFiber(fiber);
2404-
var dom = domArray[0];
2405-
if (typeof inspect === "function" && dom) {
2406-
inspect(dom);
2422+
var dom = this._selectDom;
2423+
if (typeof globalThis['inspect'] === "function" && dom) {
2424+
globalThis['inspect'](dom);
24072425
return;
24082426
}
24092427
this.notifyMessage("current id: ".concat(this._selectId, " of fiber not contain dom node"), "warning");
24102428
};
24112429
DevToolCore.prototype.inspectSource = function () {
24122430
if (!this.hasEnable)
24132431
return;
2414-
if (typeof this._source === "function") {
2432+
if (typeof this._source === "function" && typeof globalThis['inspect'] === "function") {
24152433
var s = this._source;
24162434
this._source = null;
2417-
inspect(s);
2435+
globalThis['inspect'](s);
24182436
return;
24192437
}
24202438
this.notifyMessage("can not view source for current item", "warning");
@@ -2503,6 +2521,14 @@
25032521
this._notify({ type: exports.DevToolMessageEnum.detail, data: null });
25042522
}
25052523
};
2524+
DevToolCore.prototype.notifySelectSync = function () {
2525+
if (!this.hasEnable)
2526+
return;
2527+
if (this._hasSelectChange) {
2528+
this._hasSelectChange = false;
2529+
this._notify({ type: exports.DevToolMessageEnum["select-sync"], data: this._selectId });
2530+
}
2531+
};
25062532
DevToolCore.prototype.notifyUnSelect = function () {
25072533
if (!this.hasEnable)
25082534
return;
@@ -2573,6 +2599,7 @@
25732599
this._hmr = {};
25742600
this._hoverId = "";
25752601
this._selectId = "";
2602+
this._selectDom = null;
25762603
this._source = null;
25772604
this._hmrStatus = {};
25782605
this._domHoverId = "";

chrome/public/bundle/panel.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@
10351035
DevToolMessageEnum["source"] = "source";
10361036
DevToolMessageEnum["detail"] = "detail";
10371037
DevToolMessageEnum["unmount"] = "unmount";
1038+
DevToolMessageEnum["select-sync"] = "select-sync";
10381039
DevToolMessageEnum["select-unmount"] = "select-unmount";
10391040
DevToolMessageEnum["message"] = "message";
10401041
DevToolMessageEnum["warn"] = "warn";
@@ -2135,6 +2136,8 @@
21352136
this._warn = {};
21362137
this._hoverId = "";
21372138
this._selectId = "";
2139+
this._selectDom = null;
2140+
this._hasSelectChange = false;
21382141
this._tempDomHoverId = "";
21392142
this._domHoverId = "";
21402143
this._trigger = {};
@@ -2160,6 +2163,7 @@
21602163
_this.notifyDispatch(dispatch);
21612164
});
21622165
}
2166+
_this.notifySelectSync();
21632167
_this.notifyConfig();
21642168
_this.notifyDir();
21652169
_this.notifyTrigger();
@@ -2440,7 +2444,23 @@
24402444
return current;
24412445
};
24422446
DevToolCore.prototype.setSelect = function (id) {
2447+
var fiber = getFiberNodeById(id);
2448+
if (!fiber)
2449+
return;
2450+
var domArray = getElementNodesFromFiber(fiber);
2451+
this._selectId = id;
2452+
this._selectDom = domArray[0];
2453+
};
2454+
DevToolCore.prototype.setSelectDom = function (dom) {
2455+
var fiber = getComponentFiberByDom(dom);
2456+
if (!fiber)
2457+
return;
2458+
var id = getPlainNodeIdByFiber(fiber);
2459+
if (id === this._selectId)
2460+
return;
24432461
this._selectId = id;
2462+
this._selectDom = dom;
2463+
this._hasSelectChange = true;
24442464
};
24452465
DevToolCore.prototype.setHover = function (id) {
24462466
this._hoverId = id;
@@ -2468,22 +2488,20 @@
24682488
DevToolCore.prototype.inspectDom = function () {
24692489
if (!this.hasEnable)
24702490
return;
2471-
var fiber = getFiberNodeById(this._selectId);
2472-
var domArray = getElementNodesFromFiber(fiber);
2473-
var dom = domArray[0];
2474-
if (typeof inspect === "function" && dom) {
2475-
inspect(dom);
2491+
var dom = this._selectDom;
2492+
if (typeof globalThis['inspect'] === "function" && dom) {
2493+
globalThis['inspect'](dom);
24762494
return;
24772495
}
24782496
this.notifyMessage("current id: ".concat(this._selectId, " of fiber not contain dom node"), "warning");
24792497
};
24802498
DevToolCore.prototype.inspectSource = function () {
24812499
if (!this.hasEnable)
24822500
return;
2483-
if (typeof this._source === "function") {
2501+
if (typeof this._source === "function" && typeof globalThis['inspect'] === "function") {
24842502
var s = this._source;
24852503
this._source = null;
2486-
inspect(s);
2504+
globalThis['inspect'](s);
24872505
return;
24882506
}
24892507
this.notifyMessage("can not view source for current item", "warning");
@@ -2572,6 +2590,14 @@
25722590
this._notify({ type: exports.DevToolMessageEnum.detail, data: null });
25732591
}
25742592
};
2593+
DevToolCore.prototype.notifySelectSync = function () {
2594+
if (!this.hasEnable)
2595+
return;
2596+
if (this._hasSelectChange) {
2597+
this._hasSelectChange = false;
2598+
this._notify({ type: exports.DevToolMessageEnum["select-sync"], data: this._selectId });
2599+
}
2600+
};
25752601
DevToolCore.prototype.notifyUnSelect = function () {
25762602
if (!this.hasEnable)
25772603
return;
@@ -2642,6 +2668,7 @@
26422668
this._hmr = {};
26432669
this._hoverId = "";
26442670
this._selectId = "";
2671+
this._selectDom = null;
26452672
this._source = null;
26462673
this._hmrStatus = {};
26472674
this._domHoverId = "";

chrome/public/bundle/proxy.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@
964964
DevToolMessageEnum["source"] = "source";
965965
DevToolMessageEnum["detail"] = "detail";
966966
DevToolMessageEnum["unmount"] = "unmount";
967+
DevToolMessageEnum["select-sync"] = "select-sync";
967968
DevToolMessageEnum["select-unmount"] = "select-unmount";
968969
DevToolMessageEnum["message"] = "message";
969970
DevToolMessageEnum["warn"] = "warn";
@@ -2064,6 +2065,8 @@
20642065
this._warn = {};
20652066
this._hoverId = "";
20662067
this._selectId = "";
2068+
this._selectDom = null;
2069+
this._hasSelectChange = false;
20672070
this._tempDomHoverId = "";
20682071
this._domHoverId = "";
20692072
this._trigger = {};
@@ -2089,6 +2092,7 @@
20892092
_this.notifyDispatch(dispatch);
20902093
});
20912094
}
2095+
_this.notifySelectSync();
20922096
_this.notifyConfig();
20932097
_this.notifyDir();
20942098
_this.notifyTrigger();
@@ -2369,7 +2373,23 @@
23692373
return current;
23702374
};
23712375
DevToolCore.prototype.setSelect = function (id) {
2376+
var fiber = getFiberNodeById(id);
2377+
if (!fiber)
2378+
return;
2379+
var domArray = getElementNodesFromFiber(fiber);
2380+
this._selectId = id;
2381+
this._selectDom = domArray[0];
2382+
};
2383+
DevToolCore.prototype.setSelectDom = function (dom) {
2384+
var fiber = getComponentFiberByDom(dom);
2385+
if (!fiber)
2386+
return;
2387+
var id = getPlainNodeIdByFiber(fiber);
2388+
if (id === this._selectId)
2389+
return;
23722390
this._selectId = id;
2391+
this._selectDom = dom;
2392+
this._hasSelectChange = true;
23732393
};
23742394
DevToolCore.prototype.setHover = function (id) {
23752395
this._hoverId = id;
@@ -2397,22 +2417,20 @@
23972417
DevToolCore.prototype.inspectDom = function () {
23982418
if (!this.hasEnable)
23992419
return;
2400-
var fiber = getFiberNodeById(this._selectId);
2401-
var domArray = getElementNodesFromFiber(fiber);
2402-
var dom = domArray[0];
2403-
if (typeof inspect === "function" && dom) {
2404-
inspect(dom);
2420+
var dom = this._selectDom;
2421+
if (typeof globalThis['inspect'] === "function" && dom) {
2422+
globalThis['inspect'](dom);
24052423
return;
24062424
}
24072425
this.notifyMessage("current id: ".concat(this._selectId, " of fiber not contain dom node"), "warning");
24082426
};
24092427
DevToolCore.prototype.inspectSource = function () {
24102428
if (!this.hasEnable)
24112429
return;
2412-
if (typeof this._source === "function") {
2430+
if (typeof this._source === "function" && typeof globalThis['inspect'] === "function") {
24132431
var s = this._source;
24142432
this._source = null;
2415-
inspect(s);
2433+
globalThis['inspect'](s);
24162434
return;
24172435
}
24182436
this.notifyMessage("can not view source for current item", "warning");
@@ -2501,6 +2519,14 @@
25012519
this._notify({ type: exports.DevToolMessageEnum.detail, data: null });
25022520
}
25032521
};
2522+
DevToolCore.prototype.notifySelectSync = function () {
2523+
if (!this.hasEnable)
2524+
return;
2525+
if (this._hasSelectChange) {
2526+
this._hasSelectChange = false;
2527+
this._notify({ type: exports.DevToolMessageEnum["select-sync"], data: this._selectId });
2528+
}
2529+
};
25042530
DevToolCore.prototype.notifyUnSelect = function () {
25052531
if (!this.hasEnable)
25062532
return;
@@ -2571,6 +2597,7 @@
25712597
this._hmr = {};
25722598
this._hoverId = "";
25732599
this._selectId = "";
2600+
this._selectDom = null;
25742601
this._source = null;
25752602
this._hmrStatus = {};
25762603
this._domHoverId = "";

0 commit comments

Comments
 (0)