@nine-lab/nine-mu 0.1.332 โ 0.1.333
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/nine-mu.js +82 -6
- package/dist/nine-mu.js.map +1 -1
- package/dist/nine-mu.umd.js +3 -3
- package/dist/nine-mu.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/exception/ExceptionHook.js +94 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export class ExceptionHook extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
this.lastPath = window.location.pathname;
|
|
5
|
+
this.hasError = false;
|
|
6
|
+
|
|
7
|
+
// ๐ก ๊น๋ํ๊ฒ ๋ช
์นญ์ ์ฑํฌํ ์ธ๋ถ CSS ๊ฒฝ๋ก
|
|
8
|
+
this.cssPath = "/css/nine-exception-hook.css";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
this.injectStylesheet();
|
|
13
|
+
|
|
14
|
+
// ๋ฐํ์ ์๋ฌ ๋ฐ ๋น๋๊ธฐ ๊ฑฐ๋ถ(Promise Rejection)์ ๊ฐ๊ณ ๋ฆฌ(Hook)๋ฅผ ๊ฒ๋๋ค.
|
|
15
|
+
window.addEventListener('error', this.handleRuntimeError.bind(this), true);
|
|
16
|
+
window.addEventListener('unhandledrejection', this.handlePromiseError.bind(this), true);
|
|
17
|
+
window.addEventListener('popstate', this.handleLocationChange.bind(this));
|
|
18
|
+
document.addEventListener('click', this.handleLocationChange.bind(this), true);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
disconnectedCallback() {
|
|
22
|
+
window.removeEventListener('error', this.handleRuntimeError);
|
|
23
|
+
window.removeEventListener('unhandledrejection', this.handlePromiseError);
|
|
24
|
+
window.removeEventListener('popstate', this.handleLocationChange);
|
|
25
|
+
document.removeEventListener('click', this.handleLocationChange, true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
injectStylesheet() {
|
|
29
|
+
if (document.querySelector(`link[href="${this.cssPath}"]`)) return;
|
|
30
|
+
|
|
31
|
+
const link = document.createElement('link');
|
|
32
|
+
link.rel = 'stylesheet';
|
|
33
|
+
link.href = this.cssPath;
|
|
34
|
+
document.head.appendChild(link);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
handleRuntimeError(event) {
|
|
38
|
+
if (this.contains(event.target) || event.error) {
|
|
39
|
+
this.renderError(event.error?.message || event.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
handlePromiseError(event) {
|
|
44
|
+
this.renderError(event.reason?.message || String(event.reason));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handleLocationChange() {
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
// ์ฃผ์๊ฐ ๋ฐ๋๋ฉด ํ
(Hook)์ ์ผ์์ ์ผ๋ก ํ๊ณ ํ๋ฉด์ ๋ถ๋๋ฝ๊ฒ ๋ณต๊ตฌ
|
|
50
|
+
if (this.hasError && this.lastPath !== window.location.pathname) {
|
|
51
|
+
console.log("โจ [nine-exception-hook] ์์ธ ํด์ ๋ฐ ๋ ๋๋ง ์ ์ ๋ณต๊ตฌ");
|
|
52
|
+
this.lastPath = window.location.pathname;
|
|
53
|
+
this.hasError = false;
|
|
54
|
+
|
|
55
|
+
const errorBox = this.querySelector('.nine-error-container');
|
|
56
|
+
if (errorBox) errorBox.remove();
|
|
57
|
+
|
|
58
|
+
Array.from(this.children).forEach(child => {
|
|
59
|
+
if (child.tagName !== 'LINK') child.style.display = '';
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, 10);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
renderError(errorMessage) {
|
|
66
|
+
if (this.hasError) return;
|
|
67
|
+
this.hasError = true;
|
|
68
|
+
|
|
69
|
+
if (window.triggerAutoRecovery) {
|
|
70
|
+
window.triggerAutoRecovery(errorMessage);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Array.from(this.children).forEach(child => {
|
|
74
|
+
if (child.tagName !== 'LINK') child.style.display = 'none';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const errorHTML = `
|
|
78
|
+
<div class="nine-error-container">
|
|
79
|
+
<h3 class="nine-error-title">โ ๏ธ ์์คํ
์์ธ ๊ฐ์ง (${this.tagName.toLowerCase()})</h3>
|
|
80
|
+
<p class="nine-error-label">[์๋ฌ ์์ธ ๋ก๊ทธ]:</p>
|
|
81
|
+
<pre class="nine-error-log">${errorMessage}</pre>
|
|
82
|
+
<div class="nine-error-footer">
|
|
83
|
+
๐ ์๋ฌ ๋ก๊ทธ๊ฐ ๊ด์ ํ์ผ๋ก ์๋ ํผ๋๋ฐฑ๋์์ต๋๋ค. AI๊ฐ ์์ค ์ฝ๋๋ฅผ ์ฌ์์ ํ๋ ๋์ ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์...
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
`;
|
|
87
|
+
this.insertAdjacentHTML('beforeend', errorHTML);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ๐ก ์ ์ญ ๋ธ๋ผ์ฐ์ ํ
ํ๋ฆฟ ํ๊ทธ๋ก ๊ณต์ ๋ฑ๋ก
|
|
92
|
+
if (!customElements.get('nine-exception-hook')) {
|
|
93
|
+
customElements.define('nine-exception-hook', ExceptionHook);
|
|
94
|
+
}
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { NineDiff } from './components/NineDiff.js';
|
|
|
4
4
|
import { NineDiffPopup } from './components/NineDiffPopup.js';
|
|
5
5
|
import { NineMenuDiffPopup } from './components/NineMenuDiffPopup.js';
|
|
6
6
|
import './components/ChatMessage.js';
|
|
7
|
+
import './components/exception/ExceptionHook.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Nine-Mu ์์ง ๋ฉ์ธ ํด๋์ค
|