ide-assi 0.438.0 → 0.440.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.
@@ -234824,6 +234824,10 @@ var diffMatchPatchExports = requireDiffMatchPatch();
234824
234824
  const setAsisDecorationsEffect = StateEffect.define();
234825
234825
  const setTobeDecorationsEffect = StateEffect.define();
234826
234826
 
234827
+ // --- 버튼 데코레이션을 위한 새로운 StateEffect 정의 ---
234828
+ const setAsisButtonDecorationsEffect = StateEffect.define();
234829
+ const setTobeButtonDecorationsEffect = StateEffect.define();
234830
+
234827
234831
  // --- Diff 데코레이션을 위한 StateField 정의 ---
234828
234832
  const asisDiffDecorations = StateField.define({
234829
234833
  create() {
@@ -234857,32 +234861,58 @@ const tobeDiffDecorations = StateField.define({
234857
234861
  provide: f => EditorView.decorations.from(f)
234858
234862
  });
234859
234863
 
234864
+ // --- 버튼 데코레이션을 위한 새로운 StateField 정의 ---
234865
+ const asisButtonDecorations = StateField.define({
234866
+ create() {
234867
+ return Decoration.none;
234868
+ },
234869
+ update(decorations, tr) {
234870
+ decorations = decorations.map(tr.changes);
234871
+ for (let effect of tr.effects) {
234872
+ if (effect.is(setAsisButtonDecorationsEffect)) {
234873
+ return effect.value;
234874
+ }
234875
+ }
234876
+ return decorations;
234877
+ },
234878
+ provide: f => EditorView.decorations.from(f)
234879
+ });
234880
+
234881
+ const tobeButtonDecorations = StateField.define({
234882
+ create() {
234883
+ return Decoration.none;
234884
+ },
234885
+ update(decorations, tr) {
234886
+ decorations = decorations.map(tr.changes);
234887
+ for (let effect of tr.effects) {
234888
+ if (effect.is(setTobeButtonDecorationsEffect)) {
234889
+ return effect.value;
234890
+ }
234891
+ }
234892
+ return decorations;
234893
+ },
234894
+ provide: f => EditorView.decorations.from(f)
234895
+ });
234896
+
234860
234897
 
234861
234898
  // IdeDiff 클래스 외부 (파일 상단 or 하단)에 추가
234862
234899
  class MergeButtonWidget extends WidgetType {
234863
- // ⭐️ diffRange는 변경이 발생할 대상 에디터의 범위입니다.
234864
- // ⭐️ isAsisButton: ASIS 에디터 쪽에 붙는 버튼인가? (true면 ASIS -> TOBE 적용)
234865
- // ⭐️ isAsisButton이 false면 TOBE 에디터 쪽에 붙는 버튼 (TOBE -> ASIS 되돌리기)
234866
234900
  constructor(isAsisButton, textToApply, targetEditorView, diffRange, hostComponent) {
234867
234901
  super();
234868
- this.isAsisButton = isAsisButton; // 이 버튼이 ASIS 에디터에 붙는 버튼인가 (true) TOBE 에디터에 붙는 버튼인가 (false)
234869
- this.textToApply = textToApply; // 적용할 텍스트
234870
- this.targetEditorView = targetEditorView; // 텍스트를 적용할 에디터 뷰 (상대편 에디터)
234871
- this.diffRange = diffRange; // 대상 에디터에서 변경이 일어날 정확한 from/to 오프셋
234872
- this.hostComponent = hostComponent; // IdeDiff 인스턴스 참조
234902
+ this.isAsisButton = isAsisButton;
234903
+ this.textToApply = textToApply;
234904
+ this.targetEditorView = targetEditorView;
234905
+ this.diffRange = diffRange;
234906
+ this.hostComponent = hostComponent;
234873
234907
  }
234874
234908
 
234875
- // 위젯이 차지할 공간을 텍스트 줄에 할당할지 여부. false로 설정하여 버튼이 줄 사이에 끼어들지 않도록 함.
234876
234909
  eq(other) { return false; }
234877
234910
 
234878
- // 위젯의 DOM 요소를 생성합니다.
234879
234911
  toDOM(view) {
234880
234912
  const button = document.createElement("button");
234881
- // 버튼 클래스 및 텍스트는 버튼의 위치(ASIS/TOBE)에 따라 결정됩니다.
234882
234913
  button.className = `cm-merge-button ${this.isAsisButton ? 'accept' : 'revert'}`;
234883
- button.textContent = this.isAsisButton ? "→ 적용" : "← 되돌리기"; // ASIS 버튼: TOBE로 적용, TOBE 버튼: ASIS로 되돌리기
234914
+ button.textContent = this.isAsisButton ? "→ 적용" : "← 되돌리기";
234884
234915
 
234885
- // 클릭 이벤트 핸들러
234886
234916
  button.addEventListener("click", () => {
234887
234917
  console.log(`버튼 클릭: ${this.isAsisButton ? 'ASIS -> TOBE' : 'TOBE -> ASIS'}`, this.textToApply);
234888
234918
  console.log("대상 에디터:", this.targetEditorView === this.hostComponent.asisEditorView ? "ASIS" : "TOBE");
@@ -234897,13 +234927,22 @@ class MergeButtonWidget extends WidgetType {
234897
234927
  return container;
234898
234928
  }
234899
234929
 
234900
- // 실제 변경 적용 로직
234901
234930
  applyChanges(text, editorView, range) {
234902
234931
  if (!editorView || !range) {
234903
234932
  console.error("Target editor view or range is undefined.", editorView, range);
234904
234933
  return;
234905
234934
  }
234906
234935
 
234936
+ // 특정 줄의 시작 오프셋과 끝 오프셋을 정확히 계산하여 적용해야 합니다.
234937
+ // 현재 로직은 단순 치환이므로 Diff 유형에 따라 복잡해질 수 있습니다.
234938
+ // 예를 들어, TOBE에 삽입된 내용을 ASIS에서 되돌릴 경우, ASIS에서 해당 내용 길이만큼의 공백을 지워야 합니다.
234939
+ // ASIS에서 삭제된 내용을 TOBE에 적용할 경우, TOBE의 해당 위치에 내용을 삽입해야 합니다.
234940
+
234941
+ // CodeMirror의 Doc에서 특정 범위를 가져오는 것은 `state.sliceDoc(from, to)`
234942
+ // `dmp.diff_main`의 결과는 줄 단위로 매핑된 문자열이므로,
234943
+ // 실제 오프셋 계산 및 적용 로직은 더 정교해야 합니다.
234944
+ // 지금은 임시로 range.from, range.to를 사용합니다.
234945
+
234907
234946
  editorView.dispatch({
234908
234947
  changes: {
234909
234948
  from: range.from,
@@ -234912,9 +234951,6 @@ class MergeButtonWidget extends WidgetType {
234912
234951
  }
234913
234952
  });
234914
234953
 
234915
- // 변경 후 Diff를 다시 계산하고 데코레이션을 업데이트합니다.
234916
- // requestAnimationFrame으로 감싸서 다음 렌더링 사이클에서 Diff 계산이 이루어지도록 합니다.
234917
- // 이렇게 하면 UI 블로킹을 줄일 수 있습니다.
234918
234954
  requestAnimationFrame(() => {
234919
234955
  this.hostComponent.recalculateDiff();
234920
234956
  });
@@ -234934,7 +234970,6 @@ class IdeDiff extends HTMLElement {
234934
234970
  _asisScrollHandler = null;
234935
234971
  _tobeScrollHandler = null;
234936
234972
 
234937
-
234938
234973
  get asisEditorView() {
234939
234974
  return this.#asisEditorView;
234940
234975
  };
@@ -234944,70 +234979,11 @@ class IdeDiff extends HTMLElement {
234944
234979
  this.attachShadow({ mode: 'open' });
234945
234980
  }
234946
234981
 
234947
-
234948
-
234949
234982
  connectedCallback() {
234950
234983
  this.shadowRoot.innerHTML = `
234951
234984
  <style>
234952
- /* ninegrid CSS 및 필요한 기본 스타일 */
234953
234985
  @import "https://cdn.jsdelivr.net/npm/ninegrid@${ninegrid.version}/dist/css/ideDiff.css";
234954
234986
  ${ninegrid.getCustomPath(this, "ideDiff.css")}
234955
-
234956
- /* --- 추가된 CSS 규칙 (버튼 및 선택 관련) --- */
234957
- .cm-line {
234958
- position: relative;
234959
- }
234960
- .cm-merge-button-container {
234961
- position: absolute;
234962
- right: 5px;
234963
- top: 50%;
234964
- transform: translateY(-50%);
234965
- z-index: 10;
234966
- display: flex;
234967
- gap: 5px;
234968
- }
234969
- .cm-merge-button {
234970
- background-color: #f0f0f0;
234971
- border: 1px solid #ccc;
234972
- border-radius: 3px;
234973
- padding: 2px 6px;
234974
- cursor: pointer;
234975
- font-size: 0.8em;
234976
- line-height: 1;
234977
- white-space: nowrap;
234978
- opacity: 0.7;
234979
- transition: opacity 0.2s ease-in-out;
234980
- }
234981
- .cm-merge-button:hover {
234982
- opacity: 1;
234983
- background-color: #e0e0e0;
234984
- }
234985
- .cm-merge-button.accept {
234986
- background-color: #4CAF50;
234987
- color: white;
234988
- border-color: #4CAF50;
234989
- }
234990
- .cm-merge-button.revert {
234991
- background-color: #f44336;
234992
- color: white;
234993
- border-color: #f44336;
234994
- }
234995
- /* Diff 데코레이션 CSS (ideDiff.css에 없으면 여기에 추가) */
234996
- .cm-inserted-line-bg { background-color: #e6ffed; border-left: 3px solid #66bb6a; }
234997
- .cm-deleted-line-bg { background-color: #ffebe9; border-left: 3px solid #ef5350; }
234998
-
234999
- /* CodeMirror 선택 스타일 (ideDiff.css에 없으면 여기에 추가) */
235000
- .cm-selectionBackground {
235001
- background-color: #d7d4f9 !important;
235002
- }
235003
- .cm-editor ::selection {
235004
- background-color: #d7d4f9 !important;
235005
- color: inherit !important;
235006
- }
235007
- .cm-editor::-moz-selection {
235008
- background-color: #d7d4f9 !important;
235009
- color: inherit !important;
235010
- }
235011
234987
  </style>
235012
234988
 
235013
234989
  <div class="wrapper">
@@ -235064,22 +235040,22 @@ class IdeDiff extends HTMLElement {
235064
235040
  ...historyKeymap,
235065
235041
  ...lintKeymap,
235066
235042
  ...completionKeymap,
235067
- indentWithTab, // ⭐️ 함수가 아닌 확장 자체를 전달
235068
- selectAll // ⭐️ 함수가 아닌 확장 자체를 전달
235043
+ indentWithTab,
235044
+ selectAll
235069
235045
  ]),
235070
235046
  syntaxHighlighting(defaultHighlightStyle),
235071
235047
  autocompletion(),
235072
235048
  ];
235073
235049
 
235074
- // ASIS 에디터 뷰 초기화
235075
235050
  this.#asisEditorView = new EditorView({
235076
235051
  state: EditorState.create({
235077
235052
  doc: '',
235078
235053
  extensions: [
235079
235054
  basicExtensions,
235080
235055
  this.#languageCompartment.of(javascript()),
235081
- EditorState.readOnly.of(true), // ASIS는 읽기 전용 유지
235056
+ EditorState.readOnly.of(true),
235082
235057
  asisDiffDecorations,
235058
+ asisButtonDecorations, // ⭐️ 새로운 StateField 추가
235083
235059
  EditorView.updateListener.of((update) => {
235084
235060
  if (update.view.contentDOM.firstChild && !update.view._initialAsisContentLoaded) {
235085
235061
  update.view._initialAsisContentLoaded = true;
@@ -235091,15 +235067,14 @@ class IdeDiff extends HTMLElement {
235091
235067
  parent: this.#asisEditorEl
235092
235068
  });
235093
235069
 
235094
- // TOBE 에디터 뷰 초기화
235095
235070
  this.#tobeEditorView = new EditorView({
235096
235071
  state: EditorState.create({
235097
235072
  doc: '',
235098
235073
  extensions: [
235099
235074
  basicExtensions,
235100
235075
  this.#languageCompartment.of(javascript()),
235101
- // EditorState.readOnly.of(true), // TOBE는 편집 가능하도록 주석 처리 유지
235102
235076
  tobeDiffDecorations,
235077
+ tobeButtonDecorations, // ⭐️ 새로운 StateField 추가
235103
235078
  EditorView.updateListener.of((update) => {
235104
235079
  if (update.view.contentDOM.firstChild && !update.view._initialTobeContentLoaded) {
235105
235080
  update.view._initialTobeContentLoaded = true;
@@ -235161,13 +235136,15 @@ class IdeDiff extends HTMLElement {
235161
235136
  dmp.diff_cleanupSemantic(diffs);
235162
235137
  dmp.diff_charsToLines_(diffs, lineArray);
235163
235138
 
235164
- console.log("Calculated Diffs:", diffs); // Diff 결과 확인용
235139
+ console.log("Calculated Diffs:", diffs);
235165
235140
 
235166
235141
  const asisLineBuilder = new RangeSetBuilder();
235167
235142
  const tobeLineBuilder = new RangeSetBuilder();
235143
+ const asisButtonBuilder = new RangeSetBuilder(); // ⭐️ 새로운 빌더
235144
+ const tobeButtonBuilder = new RangeSetBuilder(); // ⭐️ 새로운 빌더
235168
235145
 
235169
- let asisCursor = 0; // ASIS 텍스트에서의 현재 오프셋
235170
- let tobeCursor = 0; // TOBE 텍스트에서의 현재 오프셋
235146
+ let asisCursor = 0;
235147
+ let tobeCursor = 0;
235171
235148
 
235172
235149
  const insertedLineDeco = Decoration.line({ class: "cm-inserted-line-bg" });
235173
235150
  const deletedLineDeco = Decoration.line({ class: "cm-deleted-line-bg" });
@@ -235177,7 +235154,6 @@ class IdeDiff extends HTMLElement {
235177
235154
  for (const [op, text] of diffs) {
235178
235155
  const len = text.length;
235179
235156
 
235180
- // 각 diff op 이전에 현재 커서 위치를 저장
235181
235157
  const asisRangeStart = asisCursor;
235182
235158
  const tobeRangeStart = tobeCursor;
235183
235159
 
@@ -235192,20 +235168,22 @@ class IdeDiff extends HTMLElement {
235192
235168
  tobeCursor += tobeLines[i].length + (i < tobeLines.length - 1 ? 1 : 0);
235193
235169
  }
235194
235170
 
235195
- // ⭐️ TOBE 에디터에 버튼 추가: TOBE의 추가 내용을 ASIS로 '되돌리기' (ASIS에서 삭제)
235196
- // 즉, TOBE에서 삽입된 내용을 ASIS에서 '없애는' 작업
235197
- tobeLineBuilder.add(
235171
+ // ⭐️ TOBE 에디터에 버튼 추가: TOBE의 추가 내용을 ASIS로 '되돌리기' (ASIS에서 제거)
235172
+ // TOBE 해당 Diff가 끝나는 지점에 버튼을 붙이는 것이 자연스럽습니다.
235173
+ // tobeRangeStart는 Diff 청크의 시작 오프셋입니다.
235174
+ // 버튼을 Line Decoration과 같은 위치에 추가하되, 별도의 builder 사용
235175
+ tobeButtonBuilder.add(
235198
235176
  tobeRangeStart, // TOBE에서의 해당 Diff 청크 시작 오프셋
235199
235177
  tobeRangeStart,
235200
235178
  Decoration.widget({
235201
235179
  widget: new MergeButtonWidget(
235202
235180
  false, // 이 버튼은 TOBE 에디터에 붙는 버튼 (되돌리기)
235203
- "", // 텍스트를 ""로 삽입하면 삭제 효과 (ASIS에서 없앨 내용)
235181
+ "", // ASIS에서 해당 내용을 제거하므로 삽입할 텍스트는 없음 (즉, 삭제)
235204
235182
  currentInstance.#asisEditorView, // 대상 에디터는 ASIS
235205
- { from: asisRangeStart, to: asisRangeStart + 0 }, // ASIS에서의 대상 범위 (삽입 지점)
235183
+ { from: asisRangeStart, to: asisRangeStart + text.length }, // ASIS에서 '삭제될' 범위
235206
235184
  currentInstance
235207
235185
  ),
235208
- side: 1 // 텍스트 뒤에 삽입
235186
+ side: 1 // 텍스트 뒤에 삽입 (이전에 `side: -1`로 시도했다면 `-1`이 우선순위가 더 높습니다.)
235209
235187
  })
235210
235188
  );
235211
235189
  break;
@@ -235220,9 +235198,8 @@ class IdeDiff extends HTMLElement {
235220
235198
  asisCursor += asisLines[i].length + (i < asisLines.length - 1 ? 1 : 0);
235221
235199
  }
235222
235200
 
235223
- // ⭐️ ASIS 에디터에 버튼 추가: ASIS의 삭제 내용을 TOBE로 '적용' (TOBE에 삽입)
235224
- // 즉, ASIS에서 삭제된 내용을 TOBE에 '넣는' 작업
235225
- asisLineBuilder.add(
235201
+ // ⭐️ ASIS 에디터에 버튼 추가: ASIS의 삭제 내용을 TOBE로 '적용' (TOBE에 해당 내용 삽입)
235202
+ asisButtonBuilder.add(
235226
235203
  asisRangeStart, // ASIS에서의 해당 Diff 청크 시작 오프셋
235227
235204
  asisRangeStart,
235228
235205
  Decoration.widget({
@@ -235230,7 +235207,7 @@ class IdeDiff extends HTMLElement {
235230
235207
  true, // 이 버튼은 ASIS 에디터에 붙는 버튼 (적용)
235231
235208
  text, // ASIS에서 삭제된 내용을 TOBE에 삽입
235232
235209
  currentInstance.#tobeEditorView, // 대상 에디터는 TOBE
235233
- { from: tobeRangeStart, to: tobeRangeStart + 0 }, // TOBE에서의 대상 범위 (삽입 지점)
235210
+ { from: tobeRangeStart, to: tobeRangeStart + 0 }, // TOBE에서 '삽입될' 위치
235234
235211
  currentInstance
235235
235212
  ),
235236
235213
  side: 1 // 텍스트 뒤에 삽입
@@ -235247,7 +235224,9 @@ class IdeDiff extends HTMLElement {
235247
235224
 
235248
235225
  return {
235249
235226
  asisDecorations: asisLineBuilder.finish(),
235250
- tobeDecorations: tobeLineBuilder.finish()
235227
+ tobeDecorations: tobeLineBuilder.finish(),
235228
+ asisButtonDecorations: asisButtonBuilder.finish(), // ⭐️ 추가 반환
235229
+ tobeButtonDecorations: tobeButtonBuilder.finish() // ⭐️ 추가 반환
235251
235230
  };
235252
235231
  };
235253
235232
 
@@ -235255,13 +235234,19 @@ class IdeDiff extends HTMLElement {
235255
235234
  const asisDoc = this.#asisEditorView.state.doc.toString();
235256
235235
  const tobeDoc = this.#tobeEditorView.state.doc.toString();
235257
235236
 
235258
- const { asisDecorations, tobeDecorations } = this.#applyDiffDecorations(asisDoc, tobeDoc);
235237
+ const { asisDecorations, tobeDecorations, asisButtonDecorations, tobeButtonDecorations } = this.#applyDiffDecorations(asisDoc, tobeDoc);
235259
235238
 
235260
235239
  this.#asisEditorView.dispatch({
235261
- effects: [setAsisDecorationsEffect.of(asisDecorations)]
235240
+ effects: [
235241
+ setAsisDecorationsEffect.of(asisDecorations),
235242
+ setAsisButtonDecorationsEffect.of(asisButtonDecorations) // ⭐️ Effect 추가
235243
+ ]
235262
235244
  });
235263
235245
  this.#tobeEditorView.dispatch({
235264
- effects: [setTobeDecorationsEffect.of(tobeDecorations)]
235246
+ effects: [
235247
+ setTobeDecorationsEffect.of(tobeDecorations),
235248
+ setTobeButtonDecorationsEffect.of(tobeButtonDecorations) // ⭐️ Effect 추가
235249
+ ]
235265
235250
  });
235266
235251
  };
235267
235252
 
@@ -235297,13 +235282,19 @@ class IdeDiff extends HTMLElement {
235297
235282
  });
235298
235283
 
235299
235284
  requestAnimationFrame(() => {
235300
- const { asisDecorations, tobeDecorations } = this.#applyDiffDecorations(src1, src2);
235285
+ const { asisDecorations, tobeDecorations, asisButtonDecorations, tobeButtonDecorations } = this.#applyDiffDecorations(src1, src2);
235301
235286
 
235302
235287
  this.#asisEditorView.dispatch({
235303
- effects: [setAsisDecorationsEffect.of(asisDecorations)]
235288
+ effects: [
235289
+ setAsisDecorationsEffect.of(asisDecorations),
235290
+ setAsisButtonDecorationsEffect.of(asisButtonDecorations)
235291
+ ]
235304
235292
  });
235305
235293
  this.#tobeEditorView.dispatch({
235306
- effects: [setTobeDecorationsEffect.of(tobeDecorations)]
235294
+ effects: [
235295
+ setTobeDecorationsEffect.of(tobeDecorations),
235296
+ setTobeButtonDecorationsEffect.of(tobeButtonDecorations)
235297
+ ]
235307
235298
  });
235308
235299
 
235309
235300
  requestAnimationFrame(() => {