@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nine-lab/nine-mu",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "description": "AI-Driven Full-Stack Code Fabrication Engine",
5
5
  "type": "module",
6
6
  "main": "./dist/nine-mu.umd.js",
@@ -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 = (data) => {
145
- this.#diffPopup.popup().data(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
- let finalAsis = asis;
79
-
80
- // 1. 약속된 접두어 감지 (url: 또는 file:)
81
- const isRemote = typeof asis === 'string' && (asis.startsWith('url:') || asis.startsWith('file:'));
82
-
83
- if (isRemote) {
84
- // 접두어를 제거하고 실제 경로만 추출
85
- const targetUrl = asis.replace(/^(url:|file:)/, '');
86
-
87
- try {
88
- trace.log(`📡 원격 소스 로드 시도: ${targetUrl}`);
89
- const res = await fetch(targetUrl);
90
- if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
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 tobe === 'object' ? JSON.stringify(tobe, null, 2) : tobe;
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 });