@nine-lab/nine-mu 0.1.42 → 0.1.43

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.42",
3
+ "version": "0.1.43",
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,16 @@ 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);
144
+ /**
145
+ * 소스 비교 팝업을 띄우고 사용자의 최종 확정 본을 반환합니다.
146
+ * @param {Object} params - { asis, tobe, lang }
147
+ * @returns {Promise<string|null>} - 확정 시 소스코드, 취소 시 null
148
+ */
149
+ showDiff = async ({ asis, tobe, lang }) => {
150
+ // NineDiffPopup에 만들어둔 .wait() 또는 .open()을 연동
151
+ return await this.#diffPopup.popup()
152
+ .data(asis, tobe, lang)
153
+ .wait(); // 사용자가 버튼을 누를 때까지 여기서 await 걸림
146
154
  }
147
155
  }
148
156
 
@@ -44,11 +44,13 @@ export class NineDiffPopup extends HTMLElement {
44
44
  this.shadowRoot.querySelector('.btn-cancel').onclick = () => this.#handleCancel();
45
45
  }
46
46
 
47
- async popup(data) {
47
+ /**
48
+ async popup1(data) {
48
49
  return new Promise((resolve) => {
49
50
  this.#resolve = resolve;
50
51
  this.#asisBackup = data?.asis || "";
51
52
 
53
+
52
54
  // 💡 에디터가 준비되었다는 신호를 받으면 데이터 주입
53
55
  this.#diffView.addEventListener('ready', () => {
54
56
  trace.log("NineDiff is Ready! Injecting data...");
@@ -63,8 +65,49 @@ export class NineDiffPopup extends HTMLElement {
63
65
 
64
66
  this.#dialog.showModal();
65
67
  });
68
+ } */
69
+
70
+ popup() {
71
+ // 초기화
72
+ this.#dialog.showModal();
73
+
74
+ return this;
66
75
  }
67
76
 
77
+ 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}`;
95
+ }
96
+ }
97
+
98
+ // 2. 에디터 준비 대기 및 초기화
99
+ this.#asisBackup = finalAsis;
100
+ this.#diffView.addEventListener('ready', () => {
101
+ const asisStr = typeof finalAsis === 'object' ? JSON.stringify(finalAsis, null, 2) : finalAsis;
102
+ const tobeStr = typeof tobe === 'object' ? JSON.stringify(tobe, null, 2) : tobe;
103
+
104
+ this.#diffView.initialize(asisStr, tobeStr, lang);
105
+ }, { once: true });
106
+
107
+ return this;
108
+ }
109
+
110
+
68
111
  #handleConfirm() {
69
112
  // 에디터에서 직접 콘텐츠 추출
70
113
  const finalContent = this.#diffView ? this.#diffView.getContents() : this.#asisBackup;