@nine-lab/nine-mu 0.1.44 → 0.1.46
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 +31 -21
- package/dist/nine-mu.js.map +1 -1
- package/dist/nine-mu.umd.js +1 -1
- package/dist/nine-mu.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/NineChat.js +2 -2
- package/src/components/NineDiffPopup.js +29 -20
package/package.json
CHANGED
|
@@ -141,8 +141,8 @@ export class NineChat extends HTMLElement {
|
|
|
141
141
|
this.#diffPopup = this.shadowRoot.querySelector('nine-diff-popup');
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
showDiff = (
|
|
145
|
-
this.#diffPopup.popup().data(
|
|
144
|
+
showDiff = (asis, tobe, lang) => {
|
|
145
|
+
this.#diffPopup.popup().data(asis, tobe, lang);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -74,32 +74,41 @@ export class NineDiffPopup extends HTMLElement {
|
|
|
74
74
|
return this;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @param {string|object} asis - 소스 텍스트 또는 url:/file: 경로
|
|
79
|
+
* @param {string|object} tobe - 소스 텍스트 또는 url:/file: 경로
|
|
80
|
+
* @param {string} lang - 언어 설정
|
|
81
|
+
*/
|
|
77
82
|
async data(asis, tobe, lang = "javascript") {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
finalAsis = await res.text();
|
|
92
|
-
} catch (e) {
|
|
93
|
-
trace.error(`파일 로드 실패 [${targetUrl}]:`, e);
|
|
94
|
-
finalAsis = `// 파일을 불러오는데 실패했습니다.\n// 경로: ${targetUrl}`;
|
|
83
|
+
// 1. 데이터를 읽어오는 공통 로직 (내부 헬퍼)
|
|
84
|
+
const loadSource = async (src) => {
|
|
85
|
+
if (typeof src === 'string' && (src.startsWith('url:') || src.startsWith('file:'))) {
|
|
86
|
+
const targetUrl = src.replace(/^(url:|file:)/, '');
|
|
87
|
+
try {
|
|
88
|
+
trace.log(`📡 리모트 로드: ${targetUrl}`);
|
|
89
|
+
const res = await fetch(targetUrl);
|
|
90
|
+
if (!res.ok) throw new Error(`Status: ${res.status}`);
|
|
91
|
+
return await res.text();
|
|
92
|
+
} catch (e) {
|
|
93
|
+
trace.error(`로드 실패 [${targetUrl}]:`, e);
|
|
94
|
+
return `// 로드 실패: ${targetUrl}\n${e.message}`;
|
|
95
|
+
}
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
return src;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// 2. asis, tobe 둘 다 비동기로 병렬 로드
|
|
101
|
+
const [finalAsis, finalTobe] = await Promise.all([
|
|
102
|
+
loadSource(asis),
|
|
103
|
+
loadSource(tobe)
|
|
104
|
+
]);
|
|
97
105
|
|
|
98
|
-
// 2. 에디터 준비 대기 및 초기화
|
|
99
106
|
this.#asisBackup = finalAsis;
|
|
107
|
+
|
|
108
|
+
// 3. 에디터 준비 시 데이터 주입
|
|
100
109
|
this.#diffView.addEventListener('ready', () => {
|
|
101
110
|
const asisStr = typeof finalAsis === 'object' ? JSON.stringify(finalAsis, null, 2) : finalAsis;
|
|
102
|
-
const tobeStr = typeof
|
|
111
|
+
const tobeStr = typeof finalTobe === 'object' ? JSON.stringify(finalTobe, null, 2) : finalTobe;
|
|
103
112
|
|
|
104
113
|
this.#diffView.initialize(asisStr, tobeStr, lang);
|
|
105
114
|
}, { once: true });
|