@unpackjs/plugin-react 1.7.4 → 1.7.6
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.
- package/dist/click-to-component/index.cjs +99 -88
- package/dist/click-to-component/index.d.ts.map +1 -1
- package/dist/click-to-component/index.js +55 -70
- package/dist/click-to-component/injectScript.js +103 -121
- package/dist/index.cjs +153 -126
- package/dist/index.js +109 -111
- package/dist/mpa.cjs +144 -138
- package/dist/mpa.js +99 -126
- package/dist/react-compiler-loader/index.cjs +95 -63
- package/dist/react-compiler-loader/index.js +48 -44
- package/dist/splitChunks.cjs +55 -52
- package/dist/splitChunks.js +25 -42
- package/package.json +6 -6
|
@@ -1,72 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = function(module) {
|
|
5
|
+
var getter = module && module.__esModule ? function() {
|
|
6
|
+
return module['default'];
|
|
7
|
+
} : function() {
|
|
8
|
+
return module;
|
|
9
|
+
};
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = function(obj, prop) {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.r = function(exports1) {
|
|
31
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
32
|
+
value: 'Module'
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
applyClickToComponentConfig: ()=>applyClickToComponentConfig
|
|
31
43
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
45
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
46
|
+
const external_node_http_namespaceObject = require("node:http");
|
|
47
|
+
var external_node_http_default = /*#__PURE__*/ __webpack_require__.n(external_node_http_namespaceObject);
|
|
48
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
49
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
50
|
+
const core_namespaceObject = require("@unpackjs/core");
|
|
51
|
+
const external_launch_editor_namespaceObject = require("launch-editor");
|
|
52
|
+
var external_launch_editor_default = /*#__PURE__*/ __webpack_require__.n(external_launch_editor_namespaceObject);
|
|
53
|
+
const createServer = ()=>new Promise((resolve)=>{
|
|
54
|
+
const server = external_node_http_default().createServer((req, res)=>{
|
|
55
|
+
const params = new URLSearchParams(req.url.slice(1));
|
|
56
|
+
const file = decodeURIComponent(params.get('file'));
|
|
57
|
+
const line = Number(params.get('line'));
|
|
58
|
+
const column = Number(params.get('column'));
|
|
59
|
+
res.writeHead(200, {
|
|
60
|
+
'Access-Control-Allow-Origin': '*',
|
|
61
|
+
'Access-Control-Allow-Methods': '*',
|
|
62
|
+
'Access-Control-Allow-Headers': '*',
|
|
63
|
+
'Access-Control-Allow-Private-Network': 'true'
|
|
64
|
+
});
|
|
65
|
+
res.end('ok');
|
|
66
|
+
external_launch_editor_default()(`${file}:${line}:${column}`);
|
|
67
|
+
});
|
|
68
|
+
(0, core_namespaceObject.getPort)(3100).then((port)=>{
|
|
69
|
+
server.listen(port, ()=>{
|
|
70
|
+
resolve({
|
|
71
|
+
port
|
|
72
|
+
});
|
|
73
|
+
});
|
|
58
74
|
});
|
|
59
|
-
|
|
75
|
+
core_namespaceObject.restartCleaners.push(()=>new Promise((resolve)=>server.close(()=>resolve())));
|
|
60
76
|
});
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
unpackConfig
|
|
66
|
-
}) => {
|
|
67
|
-
const { port } = await createServer();
|
|
68
|
-
const injectScript = import_node_fs.default.readFileSync(import_node_path.default.resolve(__dirname, "./injectScript.js"), "utf-8");
|
|
69
|
-
const scriptTpl = `
|
|
77
|
+
const applyClickToComponentConfig = async ({ config, unpackConfig })=>{
|
|
78
|
+
const { port } = await createServer();
|
|
79
|
+
const injectScript = external_node_fs_default().readFileSync(external_node_path_default().resolve(__dirname, './injectScript.js'), 'utf-8');
|
|
80
|
+
const scriptTpl = `
|
|
70
81
|
if (!document.querySelector('#__click-to-component__')) {
|
|
71
82
|
const script = document.createElement('script')
|
|
72
83
|
window['CLICK_TO_COMPONENT'] = { port: ${port} }
|
|
@@ -74,30 +85,30 @@ if (!document.querySelector('#__click-to-component__')) {
|
|
|
74
85
|
script.textContent = \`${injectScript}\`
|
|
75
86
|
document.body.appendChild(script)
|
|
76
87
|
}`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
import_node_fs.default.writeFileSync(filePath, `${scriptTpl}
|
|
82
|
-
${content}`, "utf-8");
|
|
88
|
+
if (unpackConfig.mpa) Object.values(config.entry).forEach((entryConfig)=>{
|
|
89
|
+
const filePath = entryConfig.import[0];
|
|
90
|
+
const content = external_node_fs_default().readFileSync(filePath, 'utf-8');
|
|
91
|
+
external_node_fs_default().writeFileSync(filePath, `${scriptTpl}\n${content}`, 'utf-8');
|
|
83
92
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
else {
|
|
94
|
+
const realEntryPath = external_node_path_default().resolve(config.context, core_namespaceObject.TEMP_DIR, 'entries', `index.${port}.jsx`);
|
|
95
|
+
const tpl = `
|
|
87
96
|
${scriptTpl}
|
|
88
|
-
import '${(0,
|
|
97
|
+
import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(Object.values(config.entry)[0]))}'
|
|
89
98
|
`;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
const dir = external_node_path_default().dirname(realEntryPath);
|
|
100
|
+
if (!external_node_fs_default().existsSync(dir)) external_node_fs_default().mkdirSync(dir, {
|
|
101
|
+
recursive: true
|
|
102
|
+
});
|
|
103
|
+
external_node_fs_default().writeFileSync(realEntryPath, tpl, 'utf-8');
|
|
104
|
+
config.entry = {
|
|
105
|
+
main: realEntryPath
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return config;
|
|
99
109
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
var __webpack_export_target__ = exports;
|
|
111
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
112
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
113
|
+
value: true
|
|
103
114
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/click-to-component/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/click-to-component/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAIlB,MAAM,gBAAgB,CAAA;AA6BvB,eAAO,MAAM,2BAA2B,8BAGrC;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,oBAAoB,CA+B/B,CAAA"}
|
|
@@ -1,53 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
res.end("ok");
|
|
33
|
-
launchEditor(`${file}:${line}:${column}`);
|
|
34
|
-
});
|
|
35
|
-
getPort(3100).then((port) => {
|
|
36
|
-
server.listen(port, () => {
|
|
37
|
-
resolve({
|
|
38
|
-
port
|
|
1
|
+
import __rslib_shim_module__ from 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
|
+
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_http_2dc67212__ from "node:http";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__ from "@unpackjs/core";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_launch_editor_c6c8c971__ from "launch-editor";
|
|
10
|
+
var click_to_component_rslib_entry_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
11
|
+
const createServer = ()=>new Promise((resolve)=>{
|
|
12
|
+
const server = __WEBPACK_EXTERNAL_MODULE_node_http_2dc67212__["default"].createServer((req, res)=>{
|
|
13
|
+
const params = new URLSearchParams(req.url.slice(1));
|
|
14
|
+
const file = decodeURIComponent(params.get('file'));
|
|
15
|
+
const line = Number(params.get('line'));
|
|
16
|
+
const column = Number(params.get('column'));
|
|
17
|
+
res.writeHead(200, {
|
|
18
|
+
'Access-Control-Allow-Origin': '*',
|
|
19
|
+
'Access-Control-Allow-Methods': '*',
|
|
20
|
+
'Access-Control-Allow-Headers': '*',
|
|
21
|
+
'Access-Control-Allow-Private-Network': 'true'
|
|
22
|
+
});
|
|
23
|
+
res.end('ok');
|
|
24
|
+
(0, __WEBPACK_EXTERNAL_MODULE_launch_editor_c6c8c971__["default"])(`${file}:${line}:${column}`);
|
|
25
|
+
});
|
|
26
|
+
(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getPort)(3100).then((port)=>{
|
|
27
|
+
server.listen(port, ()=>{
|
|
28
|
+
resolve({
|
|
29
|
+
port
|
|
30
|
+
});
|
|
31
|
+
});
|
|
39
32
|
});
|
|
40
|
-
|
|
33
|
+
__WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.restartCleaners.push(()=>new Promise((resolve)=>server.close(()=>resolve())));
|
|
41
34
|
});
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
unpackConfig
|
|
47
|
-
}) => {
|
|
48
|
-
const { port } = await createServer();
|
|
49
|
-
const injectScript = fs.readFileSync(path2.resolve(__dirname, "./injectScript.js"), "utf-8");
|
|
50
|
-
const scriptTpl = `
|
|
35
|
+
const applyClickToComponentConfig = async ({ config, unpackConfig })=>{
|
|
36
|
+
const { port } = await createServer();
|
|
37
|
+
const injectScript = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(click_to_component_rslib_entry_dirname, './injectScript.js'), 'utf-8');
|
|
38
|
+
const scriptTpl = `
|
|
51
39
|
if (!document.querySelector('#__click-to-component__')) {
|
|
52
40
|
const script = document.createElement('script')
|
|
53
41
|
window['CLICK_TO_COMPONENT'] = { port: ${port} }
|
|
@@ -55,29 +43,26 @@ if (!document.querySelector('#__click-to-component__')) {
|
|
|
55
43
|
script.textContent = \`${injectScript}\`
|
|
56
44
|
document.body.appendChild(script)
|
|
57
45
|
}`;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
fs.writeFileSync(filePath, `${scriptTpl}
|
|
63
|
-
${content}`, "utf-8");
|
|
46
|
+
if (unpackConfig.mpa) Object.values(config.entry).forEach((entryConfig)=>{
|
|
47
|
+
const filePath = entryConfig.import[0];
|
|
48
|
+
const content = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(filePath, 'utf-8');
|
|
49
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(filePath, `${scriptTpl}\n${content}`, 'utf-8');
|
|
64
50
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
else {
|
|
52
|
+
const realEntryPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.context, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.TEMP_DIR, 'entries', `index.${port}.jsx`);
|
|
53
|
+
const tpl = `
|
|
68
54
|
${scriptTpl}
|
|
69
|
-
import '${getPathInJs(
|
|
55
|
+
import '${(0, __WEBPACK_EXTERNAL_MODULE__unpackjs_core_a401ca19__.getPathInJs)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(Object.values(config.entry)[0]))}'
|
|
70
56
|
`;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export {
|
|
82
|
-
applyClickToComponentConfig
|
|
57
|
+
const dir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(realEntryPath);
|
|
58
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(dir)) __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(dir, {
|
|
59
|
+
recursive: true
|
|
60
|
+
});
|
|
61
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(realEntryPath, tpl, 'utf-8');
|
|
62
|
+
config.entry = {
|
|
63
|
+
main: realEntryPath
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return config;
|
|
83
67
|
};
|
|
68
|
+
export { applyClickToComponentConfig };
|
|
@@ -1,137 +1,119 @@
|
|
|
1
|
-
const COVER_ID = '__click-to-component__'
|
|
2
|
-
let cover = null
|
|
3
|
-
let currentDebugSource = null
|
|
4
|
-
let enabled = false
|
|
1
|
+
const COVER_ID = '__click-to-component__';
|
|
2
|
+
let cover = null;
|
|
3
|
+
let currentDebugSource = null;
|
|
4
|
+
let enabled = false;
|
|
5
5
|
function debounce(fn, delay = 200) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
let timer = null;
|
|
7
|
+
return (...args)=>{
|
|
8
|
+
clearTimeout(timer);
|
|
9
|
+
timer = setTimeout(()=>{
|
|
10
|
+
fn(...args);
|
|
11
|
+
}, delay);
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
14
|
function applyStyles(target, styles) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
Object.entries(styles).forEach(([key, value])=>{
|
|
16
|
+
target.style[key] = value;
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
19
|
function createCover() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
cover = document.createElement('div');
|
|
21
|
+
cover.id = COVER_ID;
|
|
22
|
+
applyStyles(cover, {
|
|
23
|
+
position: 'fixed',
|
|
24
|
+
zIndex: '999999',
|
|
25
|
+
background: 'rgba(120, 170, 210, 0.6)',
|
|
26
|
+
display: 'none',
|
|
27
|
+
pointerEvents: 'none'
|
|
28
|
+
});
|
|
29
|
+
document.body.appendChild(cover);
|
|
30
30
|
}
|
|
31
31
|
function updateCover(target) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
if ('function' != typeof target.getBoundingClientRect) {
|
|
33
|
+
currentDebugSource = null;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const { top, left, width, height } = target.getBoundingClientRect();
|
|
37
|
+
applyStyles(cover, {
|
|
38
|
+
top: top + 'px',
|
|
39
|
+
left: left + 'px',
|
|
40
|
+
width: width + 'px',
|
|
41
|
+
height: height + 'px',
|
|
42
|
+
display: 'block'
|
|
43
|
+
});
|
|
44
44
|
}
|
|
45
45
|
function hideCover() {
|
|
46
|
-
|
|
46
|
+
cover.style.display = 'none';
|
|
47
47
|
}
|
|
48
48
|
function getFiberWithDebugSourceByTarget(target) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return doNext(fiber._debugOwner, depth + 1)
|
|
63
|
-
}
|
|
64
|
-
console.warn('[WARN] click-to-component cannot work with the minified version of React.')
|
|
65
|
-
}
|
|
66
|
-
return doNext(target[fiberKey])
|
|
49
|
+
const fiberKey = Object.keys(target).find((key)=>key.includes('__reactFiber'));
|
|
50
|
+
const maxDepth = 10;
|
|
51
|
+
const doNext = (fiber, depth = 0)=>{
|
|
52
|
+
if (!fiber) return;
|
|
53
|
+
if (depth > maxDepth) {
|
|
54
|
+
console.warn('Recursion depth exceeded. Aborting to prevent stack overflow.');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (fiber._debugSource) return fiber;
|
|
58
|
+
if (fiber._debugOwner) return doNext(fiber._debugOwner, depth + 1);
|
|
59
|
+
console.warn('[WARN] click-to-component cannot work with the minified version of React.');
|
|
60
|
+
};
|
|
61
|
+
return doNext(target[fiberKey]);
|
|
67
62
|
}
|
|
68
63
|
function getClosestNodeFromFiber(fiber) {
|
|
69
|
-
|
|
70
|
-
return fiber.
|
|
71
|
-
}
|
|
72
|
-
return getClosestNodeFromFiber(fiber.return)
|
|
64
|
+
if (fiber.stateNode) return fiber.stateNode;
|
|
65
|
+
return getClosestNodeFromFiber(fiber.return);
|
|
73
66
|
}
|
|
74
67
|
function openEditor() {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
sendXHR()
|
|
68
|
+
if (!currentDebugSource) return;
|
|
69
|
+
const port = window.CLICK_TO_COMPONENT.port;
|
|
70
|
+
const { fileName, lineNumber, columnNumber } = currentDebugSource;
|
|
71
|
+
const url = [
|
|
72
|
+
'http://localhost:',
|
|
73
|
+
port,
|
|
74
|
+
'/?file=',
|
|
75
|
+
fileName,
|
|
76
|
+
'&line=',
|
|
77
|
+
lineNumber,
|
|
78
|
+
'&column=',
|
|
79
|
+
columnNumber
|
|
80
|
+
].join('');
|
|
81
|
+
const sendXHR = ()=>{
|
|
82
|
+
const xhr = new XMLHttpRequest();
|
|
83
|
+
xhr.open('GET', url, true);
|
|
84
|
+
xhr.send();
|
|
85
|
+
xhr.addEventListener('error', ()=>{
|
|
86
|
+
const img = document.createElement('img');
|
|
87
|
+
img.src = url;
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
sendXHR();
|
|
99
91
|
}
|
|
100
|
-
document.addEventListener(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
document.addEventListener('keyup', (e) => {
|
|
131
|
-
if (e.key === 'Alt') {
|
|
132
|
-
enabled = false
|
|
133
|
-
hideCover()
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
createCover()
|
|
92
|
+
document.addEventListener('mouseover', debounce((e)=>{
|
|
93
|
+
if (!enabled) return;
|
|
94
|
+
const target = e.target;
|
|
95
|
+
const fiber = getFiberWithDebugSourceByTarget(target);
|
|
96
|
+
if (!fiber) return;
|
|
97
|
+
const closestNode = getClosestNodeFromFiber(fiber);
|
|
98
|
+
if (!closestNode) return;
|
|
99
|
+
currentDebugSource = fiber._debugSource;
|
|
100
|
+
updateCover(closestNode);
|
|
101
|
+
}, 30));
|
|
102
|
+
document.addEventListener('click', (e)=>{
|
|
103
|
+
if (!enabled) return;
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
openEditor();
|
|
107
|
+
hideCover();
|
|
108
|
+
enabled = false;
|
|
109
|
+
}, true);
|
|
110
|
+
document.addEventListener('keydown', (e)=>{
|
|
111
|
+
if ('Alt' === e.key) enabled = true;
|
|
112
|
+
});
|
|
113
|
+
document.addEventListener('keyup', (e)=>{
|
|
114
|
+
if ('Alt' === e.key) {
|
|
115
|
+
enabled = false;
|
|
116
|
+
hideCover();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
createCover();
|