@moda-grid/vue2 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/dist/DataGrid.vue +92 -45
  2. package/package.json +2 -2
package/dist/DataGrid.vue CHANGED
@@ -115,6 +115,8 @@ const props = defineProps({
115
115
  /** 복사 시 표시 문자열(formatter/format 적용) 사용 */
116
116
  copyFormatted: { type: Boolean, default: false },
117
117
  singleClickEdit: { type: Boolean, default: false },
118
+ /** 편집 단위 — "cell"(기본) / "fullRow"(행 전체 동시 편집) */
119
+ editType: { type: String as () => "cell" | "fullRow", default: "cell" },
118
120
  /** 그리드 상단에 찾기 바 표시 — Enter 다음 매치 / Shift+Enter 이전 매치 */
119
121
  findBox: { type: Boolean, default: false },
120
122
  /** filterable 컬럼 헤더에 값 목록 필터 드롭다운 버튼 표시 — 엑셀 autofilter */
@@ -163,6 +165,7 @@ const internal = props.grid
163
165
  cellFlash: props.cellFlash,
164
166
  copyFormatted: props.copyFormatted,
165
167
  singleClickEdit: props.singleClickEdit,
168
+ editType: props.editType,
166
169
  headerHeight: props.headerHeight,
167
170
  hiddenRowIds: props.hiddenRowIds ? [...props.hiddenRowIds] : undefined,
168
171
  striped: props.striped,
@@ -282,6 +285,7 @@ watchEffect(() => grid.setCellFlash(!!props.cellFlash));
282
285
  // copyFormatted prop → core 동기화
283
286
  watchEffect(() => grid.setCopyFormatted(!!props.copyFormatted));
284
287
  watchEffect(() => grid.setSingleClickEdit(!!props.singleClickEdit));
288
+ watchEffect(() => grid.setEditType(props.editType ?? "cell"));
285
289
 
286
290
  // 찾기 바 — findNext로 다음/이전 매치 순환 (Enter / Shift+Enter)
287
291
  const findInputEl = ref<HTMLInputElement | null>(null);
@@ -481,12 +485,16 @@ function onPivotChipDragOver(e: DragEvent) {
481
485
  e.stopPropagation();
482
486
  }
483
487
 
484
- // 행 높이 — 가상 스크롤은 고정, 아니면 autoRowHeight 추정치 적용
485
- function rowStyleOf(entry: AnyRow) {
486
- if (virtual.value && props.rowHeight)
487
- return { height: `${props.rowHeight}px` };
488
- const h = grid.getRowHeight(rowDataOf(entry));
489
- return h ? { height: `${h}px` } : undefined;
488
+ // 행 높이 + rowStyle — 가상 스크롤은 고정, 아니면 autoRowHeight 추정치 적용
489
+ function rowStyleOf(entry: AnyRow, rowIdx: number) {
490
+ const row = rowDataOf(entry);
491
+ const base: Record<string, string> = {};
492
+ const h = virtual.value && props.rowHeight ? props.rowHeight : grid.getRowHeight(row);
493
+ if (h) base.height = `${h}px`;
494
+ // GridOptions/ColumnDef.rowStyle — kebab-case 맵 병합 (Vue :style이 그대로 적용)
495
+ const custom = grid.getRowStyle(row, entryIndexOf(entry, rowIdx));
496
+ if (custom) Object.assign(base, custom);
497
+ return Object.keys(base).length ? base : undefined;
490
498
  }
491
499
 
492
500
  // 그룹 패널 칩 — 클릭 시 해당 컬럼 그룹 해제
@@ -1256,9 +1264,22 @@ function cellSpanOf(row: RowT, col: ColumnDef<RowT>) {
1256
1264
  return grid.getCellSpan(row, col);
1257
1265
  }
1258
1266
 
1259
- function isEditingCell(rowIndex: number, col: ColumnDef) {
1260
- const cell = state.value.editingCell;
1261
- return !!cell && cell.rowIndex === rowIndex && cell.columnKey === col.field;
1267
+ function isEditingCell(rowIndex: number, colIndex: number) {
1268
+ return grid.isEditing(rowIndex, colIndex);
1269
+ }
1270
+
1271
+ // fullRow 편집 — 셀별 보류 값/에러 (cell 모드면 단일 editValue/editError)
1272
+ function editValueOf(col: ColumnDef) {
1273
+ const s = state.value;
1274
+ if (s.editType === "fullRow" && s.editingValues)
1275
+ return s.editingValues[col.field];
1276
+ return s.editValue;
1277
+ }
1278
+ function editErrorOf(col: ColumnDef) {
1279
+ const s = state.value;
1280
+ if (s.editType === "fullRow" && s.editingErrors)
1281
+ return s.editingErrors[col.field] ?? null;
1282
+ return s.editError;
1262
1283
  }
1263
1284
 
1264
1285
  // 마우스 드래그 범위 선택
@@ -1275,7 +1296,13 @@ function onCellMouseDown(
1275
1296
  colIndex: number,
1276
1297
  col: ColumnDef,
1277
1298
  ) {
1278
- if (e.button !== 0 || isEditingCell(rowIndex, col)) return;
1299
+ if (e.button !== 0 || isEditingCell(rowIndex, colIndex)) return;
1300
+ // fullRow — 편집 행 안 클릭은 커밋/선택 변경 없이 통과
1301
+ if (
1302
+ state.value.editType === "fullRow" &&
1303
+ state.value.editingCell?.rowIndex === rowIndex
1304
+ )
1305
+ return;
1279
1306
  suppressCellClick = false;
1280
1307
  if (state.value.editingCell) grid.commitEditing();
1281
1308
  if (e.ctrlKey || e.metaKey) {
@@ -1314,25 +1341,31 @@ function editorInputType(col: ColumnDef) {
1314
1341
  : "text";
1315
1342
  }
1316
1343
 
1317
- function onEditorInput(event: Event) {
1318
- grid.updateEditValue((event.target as HTMLInputElement | HTMLSelectElement).value);
1344
+ function onEditorInput(event: Event, col: ColumnDef) {
1345
+ grid.updateEditValue(
1346
+ (event.target as HTMLInputElement | HTMLSelectElement).value,
1347
+ col.field,
1348
+ );
1319
1349
  }
1320
1350
 
1321
1351
  // multiselect 에디터 — 선택된 옵션들을 배열로 저장
1322
- function isEditOptSelected(opt: string): boolean {
1323
- const v = state.value.editValue;
1352
+ function isEditOptSelected(opt: string, col: ColumnDef): boolean {
1353
+ const v = editValueOf(col);
1324
1354
  return Array.isArray(v) && (v as unknown[]).includes(opt);
1325
1355
  }
1326
1356
 
1327
- function onMultiselectChange(event: Event) {
1357
+ function onMultiselectChange(event: Event, col: ColumnDef) {
1328
1358
  const sel = event.target as HTMLSelectElement;
1329
- grid.updateEditValue(Array.from(sel.selectedOptions).map((o) => o.value));
1359
+ grid.updateEditValue(
1360
+ Array.from(sel.selectedOptions).map((o) => o.value),
1361
+ col.field,
1362
+ );
1330
1363
  }
1331
1364
 
1332
- // 라디오 에디터 — 선택 즉시 커밋 (타사 그리드와 동일 UX)
1333
- function onRadioPick(opt: string, _rowIndex: number, _colIndex: number) {
1334
- grid.updateEditValue(opt);
1335
- grid.commitEditing();
1365
+ // 라디오 에디터 — 선택 즉시 커밋 (fullRow에서는 보류 값만 반영)
1366
+ function onRadioPick(opt: string, col: ColumnDef) {
1367
+ grid.updateEditValue(opt, col.field);
1368
+ if (state.value.editType !== "fullRow") grid.commitEditing();
1336
1369
  }
1337
1370
 
1338
1371
  // 커밋 후 이동 시 편집기 언마운트로 빠진 포커스를 그리드로 되돌린다
@@ -1354,7 +1387,11 @@ function onTextareaKeydown(event: KeyboardEvent) {
1354
1387
  commitThenNavigate("down");
1355
1388
  } else if (event.key === "Tab") {
1356
1389
  event.preventDefault();
1357
- commitThenNavigate(event.shiftKey ? "tabLeft" : "tabRight");
1390
+ const dir = event.shiftKey ? "left" : "right";
1391
+ // fullRow — 행 안 다음 편집 셀로 포커스 이동, 끝이면 행 커밋
1392
+ if (state.value.editType === "fullRow" && grid.navigateEditingCell(dir))
1393
+ return;
1394
+ commitThenNavigate(dir === "left" ? "tabLeft" : "tabRight");
1358
1395
  } else if (event.key === "Escape") {
1359
1396
  event.preventDefault();
1360
1397
  grid.cancelEditing();
@@ -1373,20 +1410,30 @@ function onEditorKeydown(event: KeyboardEvent) {
1373
1410
  } else commitThenNavigate("down");
1374
1411
  } else if (event.key === "Tab") {
1375
1412
  event.preventDefault();
1376
- commitThenNavigate(event.shiftKey ? "tabLeft" : "tabRight");
1413
+ const dir = event.shiftKey ? "left" : "right";
1414
+ if (state.value.editType === "fullRow" && grid.navigateEditingCell(dir))
1415
+ return;
1416
+ commitThenNavigate(dir === "left" ? "tabLeft" : "tabRight");
1377
1417
  } else if (event.key === "Escape") {
1378
1418
  event.preventDefault();
1379
1419
  grid.cancelEditing();
1380
1420
  }
1381
1421
  }
1382
1422
 
1383
- // 편집 진입 시 에디터 포커스
1423
+ // 편집 진입 시 에디터 포커스 — fullRow에서는 포커스된 컬럼의 에디터를 찾는다
1384
1424
  watch(
1385
1425
  () => state.value.editingCell,
1386
1426
  async (cell) => {
1387
1427
  if (!cell) return;
1388
1428
  await nextTick();
1389
- scrollEl.value?.querySelector<HTMLElement>(".mg-editor")?.focus();
1429
+ const colIdx = state.value.visibleColumns.findIndex(
1430
+ (c) => c.field === cell.columnKey,
1431
+ );
1432
+ const target =
1433
+ scrollEl.value?.querySelector<HTMLElement>(
1434
+ `td[data-mg-col="${colIdx}"] .mg-editor`,
1435
+ ) ?? scrollEl.value?.querySelector<HTMLElement>(".mg-editor");
1436
+ target?.focus();
1390
1437
  },
1391
1438
  );
1392
1439
  </script>
@@ -1942,7 +1989,7 @@ watch(
1942
1989
  role="row"
1943
1990
  :aria-selected="state.selectedRowIds.has(grid.getRowId(rowDataOf(entry)))"
1944
1991
  :class="rowClassOf(entry, rowIdx)"
1945
- :style="rowStyleOf(entry)"
1992
+ :style="rowStyleOf(entry, rowIdx)"
1946
1993
  @click="selectable && grid.toggleRowSelection(grid.getRowId(rowDataOf(entry)))"
1947
1994
  @dragover="onRowDragOver(entryIndexOf(entry, rowIdx), $event)"
1948
1995
  @drop="onRowDrop($event)"
@@ -1996,7 +2043,7 @@ watch(
1996
2043
  'mg-cell-readonly': !grid.isCellEditable(entryIndexOf(entry, rowIdx), colIndex),
1997
2044
  'mg-cell-active': grid.isActiveCell(entryIndexOf(entry, rowIdx), colIndex),
1998
2045
  'mg-cell-selected': grid.isCellInRange(entryIndexOf(entry, rowIdx), colIndex),
1999
- 'mg-cell-editing': isEditingCell(entryIndexOf(entry, rowIdx), col),
2046
+ 'mg-cell-editing': isEditingCell(entryIndexOf(entry, rowIdx), colIndex),
2000
2047
  'mg-cell-invalid': !!cellErrorOf(entry, col),
2001
2048
  'mg-find-match': isFindMatch(entry, col),
2002
2049
  'mg-cell-flash': state.flashedCells?.has(grid.getRowId(rowDataOf(entry)) + '|' + String(col.field)),
@@ -2060,12 +2107,12 @@ watch(
2060
2107
  {{ leafHasChildren(entry) ? (leafExpanded(entry) ? "▾" : "▸") : "" }}
2061
2108
  </button>
2062
2109
  <span
2063
- v-if="grid.isActiveCell(entryIndexOf(entry, rowIdx), colIndex) && !isEditingCell(entryIndexOf(entry, rowIdx), col)"
2110
+ v-if="grid.isActiveCell(entryIndexOf(entry, rowIdx), colIndex) && !isEditingCell(entryIndexOf(entry, rowIdx), colIndex)"
2064
2111
  class="mg-fill-handle"
2065
2112
  @mousedown="onFillMouseDown"
2066
2113
  ></span>
2067
2114
  <span
2068
- v-if="col.rowDrag && !isEditingCell(entryIndexOf(entry, rowIdx), col)"
2115
+ v-if="col.rowDrag && !isEditingCell(entryIndexOf(entry, rowIdx), colIndex)"
2069
2116
  class="mg-row-drag-handle"
2070
2117
  :class="{ 'mg-disabled': !rowDraggable }"
2071
2118
  :draggable="rowDraggable"
@@ -2074,7 +2121,7 @@ watch(
2074
2121
  @dragend="onRowDragEnd"
2075
2122
  >⠿</span
2076
2123
  >
2077
- <template v-if="isEditingCell(entryIndexOf(entry, rowIdx), col)">
2124
+ <template v-if="isEditingCell(entryIndexOf(entry, rowIdx), colIndex)">
2078
2125
  <!-- 커스텀 에디터 슬롯: #editor-{field}="ctx" -->
2079
2126
  <slot
2080
2127
  :name="`editor-${col.field}`"
@@ -2083,9 +2130,9 @@ watch(
2083
2130
  <select
2084
2131
  v-if="col.cellEditor === 'select'"
2085
2132
  class="mg-editor"
2086
- :class="{ 'mg-editor-error': state.editError }"
2087
- :value="editorInputValue(state.editValue)"
2088
- @change="onEditorInput"
2133
+ :class="{ 'mg-editor-error': editErrorOf(col) }"
2134
+ :value="editorInputValue(editValueOf(col))"
2135
+ @change="onEditorInput($event, col)"
2089
2136
  @keydown="onEditorKeydown"
2090
2137
  @click.stop
2091
2138
  @mousedown.stop
@@ -2097,10 +2144,10 @@ watch(
2097
2144
  <select
2098
2145
  v-else-if="col.cellEditor === 'multiselect'"
2099
2146
  class="mg-editor"
2100
- :class="{ 'mg-editor-error': state.editError }"
2147
+ :class="{ 'mg-editor-error': editErrorOf(col) }"
2101
2148
  multiple
2102
2149
  :size="Math.min(Math.max((col.editorOptions || []).length, 2), 8)"
2103
- @change="onMultiselectChange"
2150
+ @change="onMultiselectChange($event, col)"
2104
2151
  @keydown="onEditorKeydown"
2105
2152
  @click.stop
2106
2153
  @mousedown.stop
@@ -2109,7 +2156,7 @@ watch(
2109
2156
  v-for="opt in col.editorOptions || []"
2110
2157
  :key="opt"
2111
2158
  :value="opt"
2112
- :selected="isEditOptSelected(opt)"
2159
+ :selected="isEditOptSelected(opt, col)"
2113
2160
  >
2114
2161
  {{ opt }}
2115
2162
  </option>
@@ -2126,8 +2173,8 @@ watch(
2126
2173
  >
2127
2174
  <input
2128
2175
  type="radio"
2129
- :checked="String(state.editValue ?? '') === opt"
2130
- @change="onRadioPick(opt, entryIndexOf(entry, rowIdx), colIndex)"
2176
+ :checked="String(editValueOf(col) ?? '') === opt"
2177
+ @change="onRadioPick(opt, col)"
2131
2178
  @click.stop
2132
2179
  @mousedown.stop
2133
2180
  />
@@ -2137,11 +2184,11 @@ watch(
2137
2184
  <textarea
2138
2185
  v-else-if="col.cellEditor === 'textarea'"
2139
2186
  class="mg-editor mg-editor-textarea"
2140
- :class="{ 'mg-editor-error': state.editError }"
2141
- :value="editorInputValue(state.editValue)"
2142
- @input="onEditorInput"
2187
+ :class="{ 'mg-editor-error': editErrorOf(col) }"
2188
+ :value="editorInputValue(editValueOf(col))"
2189
+ @input="onEditorInput($event, col)"
2143
2190
  @keydown="onTextareaKeydown"
2144
- @blur="grid.commitEditing()"
2191
+ @blur="state.editType !== 'fullRow' && grid.commitEditing()"
2145
2192
  @click.stop
2146
2193
  @dblclick.stop
2147
2194
  @mousedown.stop
@@ -2150,14 +2197,14 @@ watch(
2150
2197
  v-else
2151
2198
  :type="editorInputType(col)"
2152
2199
  class="mg-editor"
2153
- :class="{ 'mg-editor-error': state.editError }"
2154
- :value="editorInputValue(state.editValue)"
2200
+ :class="{ 'mg-editor-error': editErrorOf(col) }"
2201
+ :value="editorInputValue(editValueOf(col))"
2155
2202
  :list="
2156
2203
  editorInputType(col) === 'text' && col.editorOptions?.length
2157
2204
  ? `mg-dl-${col.field}`
2158
2205
  : undefined
2159
2206
  "
2160
- @input="onEditorInput"
2207
+ @input="onEditorInput($event, col)"
2161
2208
  @keydown="onEditorKeydown"
2162
2209
  @click.stop
2163
2210
  @mousedown.stop
@@ -2176,7 +2223,7 @@ watch(
2176
2223
  />
2177
2224
  </datalist>
2178
2225
  </slot>
2179
- <span v-if="state.editError" class="mg-edit-error">{{ state.editError }}</span>
2226
+ <span v-if="editErrorOf(col)" class="mg-edit-error">{{ editErrorOf(col) }}</span>
2180
2227
  </template>
2181
2228
  <!-- 커스텀 셀 슬롯: #cell-{field}="{ value, row, column }" -->
2182
2229
  <slot
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moda-grid/vue2",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Vue 2.7 adapter for @moda-grid — DataGrid SFC and useGrid composable",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "grid"
37
37
  ],
38
38
  "dependencies": {
39
- "@moda-grid/core": "1.0.0"
39
+ "@moda-grid/core": "1.0.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vue": "^2.7.0"