ide-assi 0.437.0 → 0.439.0

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.
@@ -24,6 +24,10 @@ import { diff_match_patch } from 'diff-match-patch';
24
24
  const setAsisDecorationsEffect = StateEffect.define();
25
25
  const setTobeDecorationsEffect = StateEffect.define();
26
26
 
27
+ // --- 버튼 데코레이션을 위한 새로운 StateEffect 정의 ---
28
+ const setAsisButtonDecorationsEffect = StateEffect.define();
29
+ const setTobeButtonDecorationsEffect = StateEffect.define();
30
+
27
31
  // --- Diff 데코레이션을 위한 StateField 정의 ---
28
32
  const asisDiffDecorations = StateField.define({
29
33
  create() {
@@ -57,32 +61,58 @@ const tobeDiffDecorations = StateField.define({
57
61
  provide: f => EditorView.decorations.from(f)
58
62
  });
59
63
 
64
+ // --- 버튼 데코레이션을 위한 새로운 StateField 정의 ---
65
+ const asisButtonDecorations = StateField.define({
66
+ create() {
67
+ return Decoration.none;
68
+ },
69
+ update(decorations, tr) {
70
+ decorations = decorations.map(tr.changes);
71
+ for (let effect of tr.effects) {
72
+ if (effect.is(setAsisButtonDecorationsEffect)) {
73
+ return effect.value;
74
+ }
75
+ }
76
+ return decorations;
77
+ },
78
+ provide: f => EditorView.decorations.from(f)
79
+ });
80
+
81
+ const tobeButtonDecorations = StateField.define({
82
+ create() {
83
+ return Decoration.none;
84
+ },
85
+ update(decorations, tr) {
86
+ decorations = decorations.map(tr.changes);
87
+ for (let effect of tr.effects) {
88
+ if (effect.is(setTobeButtonDecorationsEffect)) {
89
+ return effect.value;
90
+ }
91
+ }
92
+ return decorations;
93
+ },
94
+ provide: f => EditorView.decorations.from(f)
95
+ });
96
+
60
97
 
61
98
  // IdeDiff 클래스 외부 (파일 상단 or 하단)에 추가
62
99
  class MergeButtonWidget extends WidgetType {
63
- // ⭐️ diffRange는 변경이 발생할 대상 에디터의 범위입니다.
64
- // ⭐️ isAsisButton: ASIS 에디터 쪽에 붙는 버튼인가? (true면 ASIS -> TOBE 적용)
65
- // ⭐️ isAsisButton이 false면 TOBE 에디터 쪽에 붙는 버튼 (TOBE -> ASIS 되돌리기)
66
100
  constructor(isAsisButton, textToApply, targetEditorView, diffRange, hostComponent) {
67
101
  super();
68
- this.isAsisButton = isAsisButton; // 이 버튼이 ASIS 에디터에 붙는 버튼인가 (true) TOBE 에디터에 붙는 버튼인가 (false)
69
- this.textToApply = textToApply; // 적용할 텍스트
70
- this.targetEditorView = targetEditorView; // 텍스트를 적용할 에디터 뷰 (상대편 에디터)
71
- this.diffRange = diffRange; // 대상 에디터에서 변경이 일어날 정확한 from/to 오프셋
72
- this.hostComponent = hostComponent; // IdeDiff 인스턴스 참조
102
+ this.isAsisButton = isAsisButton;
103
+ this.textToApply = textToApply;
104
+ this.targetEditorView = targetEditorView;
105
+ this.diffRange = diffRange;
106
+ this.hostComponent = hostComponent;
73
107
  }
74
108
 
75
- // 위젯이 차지할 공간을 텍스트 줄에 할당할지 여부. false로 설정하여 버튼이 줄 사이에 끼어들지 않도록 함.
76
109
  eq(other) { return false; }
77
110
 
78
- // 위젯의 DOM 요소를 생성합니다.
79
111
  toDOM(view) {
80
112
  const button = document.createElement("button");
81
- // 버튼 클래스 및 텍스트는 버튼의 위치(ASIS/TOBE)에 따라 결정됩니다.
82
113
  button.className = `cm-merge-button ${this.isAsisButton ? 'accept' : 'revert'}`;
83
- button.textContent = this.isAsisButton ? "→ 적용" : "← 되돌리기"; // ASIS 버튼: TOBE로 적용, TOBE 버튼: ASIS로 되돌리기
114
+ button.textContent = this.isAsisButton ? "→ 적용" : "← 되돌리기";
84
115
 
85
- // 클릭 이벤트 핸들러
86
116
  button.addEventListener("click", () => {
87
117
  console.log(`버튼 클릭: ${this.isAsisButton ? 'ASIS -> TOBE' : 'TOBE -> ASIS'}`, this.textToApply);
88
118
  console.log("대상 에디터:", this.targetEditorView === this.hostComponent.#asisEditorView ? "ASIS" : "TOBE");
@@ -97,13 +127,22 @@ class MergeButtonWidget extends WidgetType {
97
127
  return container;
98
128
  }
99
129
 
100
- // 실제 변경 적용 로직
101
130
  applyChanges(text, editorView, range) {
102
131
  if (!editorView || !range) {
103
132
  console.error("Target editor view or range is undefined.", editorView, range);
104
133
  return;
105
134
  }
106
135
 
136
+ // 특정 줄의 시작 오프셋과 끝 오프셋을 정확히 계산하여 적용해야 합니다.
137
+ // 현재 로직은 단순 치환이므로 Diff 유형에 따라 복잡해질 수 있습니다.
138
+ // 예를 들어, TOBE에 삽입된 내용을 ASIS에서 되돌릴 경우, ASIS에서 해당 내용 길이만큼의 공백을 지워야 합니다.
139
+ // ASIS에서 삭제된 내용을 TOBE에 적용할 경우, TOBE의 해당 위치에 내용을 삽입해야 합니다.
140
+
141
+ // CodeMirror의 Doc에서 특정 범위를 가져오는 것은 `state.sliceDoc(from, to)`
142
+ // `dmp.diff_main`의 결과는 줄 단위로 매핑된 문자열이므로,
143
+ // 실제 오프셋 계산 및 적용 로직은 더 정교해야 합니다.
144
+ // 지금은 임시로 range.from, range.to를 사용합니다.
145
+
107
146
  editorView.dispatch({
108
147
  changes: {
109
148
  from: range.from,
@@ -112,9 +151,6 @@ class MergeButtonWidget extends WidgetType {
112
151
  }
113
152
  });
114
153
 
115
- // 변경 후 Diff를 다시 계산하고 데코레이션을 업데이트합니다.
116
- // requestAnimationFrame으로 감싸서 다음 렌더링 사이클에서 Diff 계산이 이루어지도록 합니다.
117
- // 이렇게 하면 UI 블로킹을 줄일 수 있습니다.
118
154
  requestAnimationFrame(() => {
119
155
  this.hostComponent.recalculateDiff();
120
156
  });
@@ -143,65 +179,8 @@ export class IdeDiff extends HTMLElement {
143
179
  connectedCallback() {
144
180
  this.shadowRoot.innerHTML = `
145
181
  <style>
146
- /* ninegrid CSS 및 필요한 기본 스타일 */
147
182
  @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/ideDiff.css";
148
183
  ${ninegrid.getCustomPath(this, "ideDiff.css")}
149
-
150
- /* --- 추가된 CSS 규칙 (버튼 및 선택 관련) --- */
151
- .cm-line {
152
- position: relative;
153
- }
154
- .cm-merge-button-container {
155
- position: absolute;
156
- right: 5px;
157
- top: 50%;
158
- transform: translateY(-50%);
159
- z-index: 10;
160
- display: flex;
161
- gap: 5px;
162
- }
163
- .cm-merge-button {
164
- background-color: #f0f0f0;
165
- border: 1px solid #ccc;
166
- border-radius: 3px;
167
- padding: 2px 6px;
168
- cursor: pointer;
169
- font-size: 0.8em;
170
- line-height: 1;
171
- white-space: nowrap;
172
- opacity: 0.7;
173
- transition: opacity 0.2s ease-in-out;
174
- }
175
- .cm-merge-button:hover {
176
- opacity: 1;
177
- background-color: #e0e0e0;
178
- }
179
- .cm-merge-button.accept {
180
- background-color: #4CAF50;
181
- color: white;
182
- border-color: #4CAF50;
183
- }
184
- .cm-merge-button.revert {
185
- background-color: #f44336;
186
- color: white;
187
- border-color: #f44336;
188
- }
189
- /* Diff 데코레이션 CSS (ideDiff.css에 없으면 여기에 추가) */
190
- .cm-inserted-line-bg { background-color: #e6ffed; border-left: 3px solid #66bb6a; }
191
- .cm-deleted-line-bg { background-color: #ffebe9; border-left: 3px solid #ef5350; }
192
-
193
- /* CodeMirror 선택 스타일 (ideDiff.css에 없으면 여기에 추가) */
194
- .cm-selectionBackground {
195
- background-color: #d7d4f9 !important;
196
- }
197
- .cm-editor ::selection {
198
- background-color: #d7d4f9 !important;
199
- color: inherit !important;
200
- }
201
- .cm-editor::-moz-selection {
202
- background-color: #d7d4f9 !important;
203
- color: inherit !important;
204
- }
205
184
  </style>
206
185
 
207
186
  <div class="wrapper">
@@ -258,22 +237,22 @@ export class IdeDiff extends HTMLElement {
258
237
  ...historyKeymap,
259
238
  ...lintKeymap,
260
239
  ...completionKeymap,
261
- indentWithTab, // ⭐️ 함수가 아닌 확장 자체를 전달
262
- selectAll // ⭐️ 함수가 아닌 확장 자체를 전달
240
+ indentWithTab,
241
+ selectAll
263
242
  ]),
264
243
  syntaxHighlighting(defaultHighlightStyle),
265
244
  autocompletion(),
266
245
  ];
267
246
 
268
- // ASIS 에디터 뷰 초기화
269
247
  this.#asisEditorView = new EditorView({
270
248
  state: EditorState.create({
271
249
  doc: '',
272
250
  extensions: [
273
251
  basicExtensions,
274
252
  this.#languageCompartment.of(javascript()),
275
- EditorState.readOnly.of(true), // ASIS는 읽기 전용 유지
253
+ EditorState.readOnly.of(true),
276
254
  asisDiffDecorations,
255
+ asisButtonDecorations, // ⭐️ 새로운 StateField 추가
277
256
  EditorView.updateListener.of((update) => {
278
257
  if (update.view.contentDOM.firstChild && !update.view._initialAsisContentLoaded) {
279
258
  update.view._initialAsisContentLoaded = true;
@@ -285,15 +264,14 @@ export class IdeDiff extends HTMLElement {
285
264
  parent: this.#asisEditorEl
286
265
  });
287
266
 
288
- // TOBE 에디터 뷰 초기화
289
267
  this.#tobeEditorView = new EditorView({
290
268
  state: EditorState.create({
291
269
  doc: '',
292
270
  extensions: [
293
271
  basicExtensions,
294
272
  this.#languageCompartment.of(javascript()),
295
- // EditorState.readOnly.of(true), // TOBE는 편집 가능하도록 주석 처리 유지
296
273
  tobeDiffDecorations,
274
+ tobeButtonDecorations, // ⭐️ 새로운 StateField 추가
297
275
  EditorView.updateListener.of((update) => {
298
276
  if (update.view.contentDOM.firstChild && !update.view._initialTobeContentLoaded) {
299
277
  update.view._initialTobeContentLoaded = true;
@@ -355,13 +333,15 @@ export class IdeDiff extends HTMLElement {
355
333
  dmp.diff_cleanupSemantic(diffs);
356
334
  dmp.diff_charsToLines_(diffs, lineArray);
357
335
 
358
- console.log("Calculated Diffs:", diffs); // Diff 결과 확인용
336
+ console.log("Calculated Diffs:", diffs);
359
337
 
360
338
  const asisLineBuilder = new RangeSetBuilder();
361
339
  const tobeLineBuilder = new RangeSetBuilder();
340
+ const asisButtonBuilder = new RangeSetBuilder(); // ⭐️ 새로운 빌더
341
+ const tobeButtonBuilder = new RangeSetBuilder(); // ⭐️ 새로운 빌더
362
342
 
363
- let asisCursor = 0; // ASIS 텍스트에서의 현재 오프셋
364
- let tobeCursor = 0; // TOBE 텍스트에서의 현재 오프셋
343
+ let asisCursor = 0;
344
+ let tobeCursor = 0;
365
345
 
366
346
  const insertedLineDeco = Decoration.line({ class: "cm-inserted-line-bg" });
367
347
  const deletedLineDeco = Decoration.line({ class: "cm-deleted-line-bg" });
@@ -371,7 +351,6 @@ export class IdeDiff extends HTMLElement {
371
351
  for (const [op, text] of diffs) {
372
352
  const len = text.length;
373
353
 
374
- // 각 diff op 이전에 현재 커서 위치를 저장
375
354
  const asisRangeStart = asisCursor;
376
355
  const tobeRangeStart = tobeCursor;
377
356
 
@@ -386,20 +365,22 @@ export class IdeDiff extends HTMLElement {
386
365
  tobeCursor += tobeLines[i].length + (i < tobeLines.length - 1 ? 1 : 0);
387
366
  }
388
367
 
389
- // ⭐️ TOBE 에디터에 버튼 추가: TOBE의 추가 내용을 ASIS로 '되돌리기' (ASIS에서 삭제)
390
- // 즉, TOBE에서 삽입된 내용을 ASIS에서 '없애는' 작업
391
- tobeLineBuilder.add(
368
+ // ⭐️ TOBE 에디터에 버튼 추가: TOBE의 추가 내용을 ASIS로 '되돌리기' (ASIS에서 제거)
369
+ // TOBE 해당 Diff가 끝나는 지점에 버튼을 붙이는 것이 자연스럽습니다.
370
+ // tobeRangeStart는 Diff 청크의 시작 오프셋입니다.
371
+ // 버튼을 Line Decoration과 같은 위치에 추가하되, 별도의 builder 사용
372
+ tobeButtonBuilder.add(
392
373
  tobeRangeStart, // TOBE에서의 해당 Diff 청크 시작 오프셋
393
374
  tobeRangeStart,
394
375
  Decoration.widget({
395
376
  widget: new MergeButtonWidget(
396
377
  false, // 이 버튼은 TOBE 에디터에 붙는 버튼 (되돌리기)
397
- "", // 텍스트를 ""로 삽입하면 삭제 효과 (ASIS에서 없앨 내용)
378
+ "", // ASIS에서 해당 내용을 제거하므로 삽입할 텍스트는 없음 (즉, 삭제)
398
379
  currentInstance.#asisEditorView, // 대상 에디터는 ASIS
399
- { from: asisRangeStart, to: asisRangeStart + 0 }, // ASIS에서의 대상 범위 (삽입 지점)
380
+ { from: asisRangeStart, to: asisRangeStart + text.length }, // ASIS에서 '삭제될' 범위
400
381
  currentInstance
401
382
  ),
402
- side: 1 // 텍스트 뒤에 삽입
383
+ side: 1 // 텍스트 뒤에 삽입 (이전에 `side: -1`로 시도했다면 `-1`이 우선순위가 더 높습니다.)
403
384
  })
404
385
  );
405
386
  break;
@@ -414,9 +395,8 @@ export class IdeDiff extends HTMLElement {
414
395
  asisCursor += asisLines[i].length + (i < asisLines.length - 1 ? 1 : 0);
415
396
  }
416
397
 
417
- // ⭐️ ASIS 에디터에 버튼 추가: ASIS의 삭제 내용을 TOBE로 '적용' (TOBE에 삽입)
418
- // 즉, ASIS에서 삭제된 내용을 TOBE에 '넣는' 작업
419
- asisLineBuilder.add(
398
+ // ⭐️ ASIS 에디터에 버튼 추가: ASIS의 삭제 내용을 TOBE로 '적용' (TOBE에 해당 내용 삽입)
399
+ asisButtonBuilder.add(
420
400
  asisRangeStart, // ASIS에서의 해당 Diff 청크 시작 오프셋
421
401
  asisRangeStart,
422
402
  Decoration.widget({
@@ -424,7 +404,7 @@ export class IdeDiff extends HTMLElement {
424
404
  true, // 이 버튼은 ASIS 에디터에 붙는 버튼 (적용)
425
405
  text, // ASIS에서 삭제된 내용을 TOBE에 삽입
426
406
  currentInstance.#tobeEditorView, // 대상 에디터는 TOBE
427
- { from: tobeRangeStart, to: tobeRangeStart + 0 }, // TOBE에서의 대상 범위 (삽입 지점)
407
+ { from: tobeRangeStart, to: tobeRangeStart + 0 }, // TOBE에서 '삽입될' 위치
428
408
  currentInstance
429
409
  ),
430
410
  side: 1 // 텍스트 뒤에 삽입
@@ -441,7 +421,9 @@ export class IdeDiff extends HTMLElement {
441
421
 
442
422
  return {
443
423
  asisDecorations: asisLineBuilder.finish(),
444
- tobeDecorations: tobeLineBuilder.finish()
424
+ tobeDecorations: tobeLineBuilder.finish(),
425
+ asisButtonDecorations: asisButtonBuilder.finish(), // ⭐️ 추가 반환
426
+ tobeButtonDecorations: tobeButtonBuilder.finish() // ⭐️ 추가 반환
445
427
  };
446
428
  };
447
429
 
@@ -449,13 +431,19 @@ export class IdeDiff extends HTMLElement {
449
431
  const asisDoc = this.#asisEditorView.state.doc.toString();
450
432
  const tobeDoc = this.#tobeEditorView.state.doc.toString();
451
433
 
452
- const { asisDecorations, tobeDecorations } = this.#applyDiffDecorations(asisDoc, tobeDoc);
434
+ const { asisDecorations, tobeDecorations, asisButtonDecorations, tobeButtonDecorations } = this.#applyDiffDecorations(asisDoc, tobeDoc);
453
435
 
454
436
  this.#asisEditorView.dispatch({
455
- effects: [setAsisDecorationsEffect.of(asisDecorations)]
437
+ effects: [
438
+ setAsisDecorationsEffect.of(asisDecorations),
439
+ setAsisButtonDecorationsEffect.of(asisButtonDecorations) // ⭐️ Effect 추가
440
+ ]
456
441
  });
457
442
  this.#tobeEditorView.dispatch({
458
- effects: [setTobeDecorationsEffect.of(tobeDecorations)]
443
+ effects: [
444
+ setTobeDecorationsEffect.of(tobeDecorations),
445
+ setTobeButtonDecorationsEffect.of(tobeButtonDecorations) // ⭐️ Effect 추가
446
+ ]
459
447
  });
460
448
  };
461
449
 
@@ -491,13 +479,19 @@ export class IdeDiff extends HTMLElement {
491
479
  });
492
480
 
493
481
  requestAnimationFrame(() => {
494
- const { asisDecorations, tobeDecorations } = this.#applyDiffDecorations(src1, src2);
482
+ const { asisDecorations, tobeDecorations, asisButtonDecorations, tobeButtonDecorations } = this.#applyDiffDecorations(src1, src2);
495
483
 
496
484
  this.#asisEditorView.dispatch({
497
- effects: [setAsisDecorationsEffect.of(asisDecorations)]
485
+ effects: [
486
+ setAsisDecorationsEffect.of(asisDecorations),
487
+ setAsisButtonDecorationsEffect.of(asisButtonDecorations)
488
+ ]
498
489
  });
499
490
  this.#tobeEditorView.dispatch({
500
- effects: [setTobeDecorationsEffect.of(tobeDecorations)]
491
+ effects: [
492
+ setTobeDecorationsEffect.of(tobeDecorations),
493
+ setTobeButtonDecorationsEffect.of(tobeButtonDecorations)
494
+ ]
501
495
  });
502
496
 
503
497
  requestAnimationFrame(() => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ide-assi",
3
3
  "type": "module",
4
- "version": "0.437.0",
4
+ "version": "0.439.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {