@nine-lab/nine-mu 0.1.45 → 0.1.47
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 +34 -46
- 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/NineDiffPopup.js +34 -48
package/package.json
CHANGED
|
@@ -24,49 +24,26 @@ export class NineDiffPopup extends HTMLElement {
|
|
|
24
24
|
${customImport}
|
|
25
25
|
</style>
|
|
26
26
|
|
|
27
|
-
<
|
|
27
|
+
<nine-dialog>
|
|
28
28
|
<div class="main-layout">
|
|
29
29
|
<div class="diff-area">
|
|
30
|
-
<nine-diff
|
|
30
|
+
<nine-diff></nine-diff>
|
|
31
31
|
</div>
|
|
32
32
|
<div class="footer">
|
|
33
33
|
<button class="btn btn-cancel">취소</button>
|
|
34
34
|
<button class="btn btn-confirm">최종 확정 및 저장</button>
|
|
35
35
|
</div>
|
|
36
36
|
</div>
|
|
37
|
-
</
|
|
37
|
+
</nine-dialog>
|
|
38
38
|
`;
|
|
39
39
|
|
|
40
|
-
this.#dialog = this.shadowRoot.querySelector('
|
|
41
|
-
this.#diffView = this.shadowRoot.querySelector('
|
|
40
|
+
this.#dialog = this.shadowRoot.querySelector('nine-dialog');
|
|
41
|
+
this.#diffView = this.shadowRoot.querySelector('nine-diff');
|
|
42
42
|
|
|
43
43
|
this.shadowRoot.querySelector('.btn-confirm').onclick = () => this.#handleConfirm();
|
|
44
44
|
this.shadowRoot.querySelector('.btn-cancel').onclick = () => this.#handleCancel();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
async popup1(data) {
|
|
49
|
-
return new Promise((resolve) => {
|
|
50
|
-
this.#resolve = resolve;
|
|
51
|
-
this.#asisBackup = data?.asis || "";
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// 💡 에디터가 준비되었다는 신호를 받으면 데이터 주입
|
|
55
|
-
this.#diffView.addEventListener('ready', () => {
|
|
56
|
-
trace.log("NineDiff is Ready! Injecting data...");
|
|
57
|
-
|
|
58
|
-
const asisStr = typeof data.asis === 'object' ? JSON.stringify(data.asis, null, 2) : data.asis;
|
|
59
|
-
const tobeStr = typeof data.tobe === 'object' ? JSON.stringify(data.tobe, null, 2) : data.tobe;
|
|
60
|
-
|
|
61
|
-
trace.log(asisStr, tobeStr);
|
|
62
|
-
|
|
63
|
-
this.#diffView.initialize(asisStr, tobeStr, data.lang);
|
|
64
|
-
}, { once: true }); // 딱 한 번만 실행
|
|
65
|
-
|
|
66
|
-
this.#dialog.showModal();
|
|
67
|
-
});
|
|
68
|
-
} */
|
|
69
|
-
|
|
70
47
|
popup() {
|
|
71
48
|
// 초기화
|
|
72
49
|
this.#dialog.showModal();
|
|
@@ -74,32 +51,41 @@ export class NineDiffPopup extends HTMLElement {
|
|
|
74
51
|
return this;
|
|
75
52
|
}
|
|
76
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @param {string|object} asis - 소스 텍스트 또는 url:/file: 경로
|
|
56
|
+
* @param {string|object} tobe - 소스 텍스트 또는 url:/file: 경로
|
|
57
|
+
* @param {string} lang - 언어 설정
|
|
58
|
+
*/
|
|
77
59
|
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}`;
|
|
60
|
+
// 1. 데이터를 읽어오는 공통 로직 (내부 헬퍼)
|
|
61
|
+
const loadSource = async (src) => {
|
|
62
|
+
if (typeof src === 'string' && (src.startsWith('url:') || src.startsWith('file:'))) {
|
|
63
|
+
const targetUrl = src.replace(/^(url:|file:)/, '');
|
|
64
|
+
try {
|
|
65
|
+
trace.log(`📡 리모트 로드: ${targetUrl}`);
|
|
66
|
+
const res = await fetch(targetUrl);
|
|
67
|
+
if (!res.ok) throw new Error(`Status: ${res.status}`);
|
|
68
|
+
return await res.text();
|
|
69
|
+
} catch (e) {
|
|
70
|
+
trace.error(`로드 실패 [${targetUrl}]:`, e);
|
|
71
|
+
return `// 로드 실패: ${targetUrl}\n${e.message}`;
|
|
72
|
+
}
|
|
95
73
|
}
|
|
96
|
-
|
|
74
|
+
return src;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// 2. asis, tobe 둘 다 비동기로 병렬 로드
|
|
78
|
+
const [finalAsis, finalTobe] = await Promise.all([
|
|
79
|
+
loadSource(asis),
|
|
80
|
+
loadSource(tobe)
|
|
81
|
+
]);
|
|
97
82
|
|
|
98
|
-
// 2. 에디터 준비 대기 및 초기화
|
|
99
83
|
this.#asisBackup = finalAsis;
|
|
84
|
+
|
|
85
|
+
// 3. 에디터 준비 시 데이터 주입
|
|
100
86
|
this.#diffView.addEventListener('ready', () => {
|
|
101
87
|
const asisStr = typeof finalAsis === 'object' ? JSON.stringify(finalAsis, null, 2) : finalAsis;
|
|
102
|
-
const tobeStr = typeof
|
|
88
|
+
const tobeStr = typeof finalTobe === 'object' ? JSON.stringify(finalTobe, null, 2) : finalTobe;
|
|
103
89
|
|
|
104
90
|
this.#diffView.initialize(asisStr, tobeStr, lang);
|
|
105
91
|
}, { once: true });
|