@moda-grid/vue2 0.1.0 → 0.2.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.
- package/package.json +2 -3
- package/src/DataGrid.vue +0 -1215
- package/src/index.ts +0 -26
- package/src/shim-vue.d.ts +0 -5
- package/src/styles.css +0 -1
- package/src/useGrid.ts +0 -38
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moda-grid/vue2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vue 2.7 adapter for @moda-grid — DataGrid SFC and useGrid composable",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
},
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
|
-
"src",
|
|
17
16
|
"dist"
|
|
18
17
|
],
|
|
19
18
|
"sideEffects": [
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"grid"
|
|
37
36
|
],
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@moda-grid/core": "0.
|
|
38
|
+
"@moda-grid/core": "0.2.0"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
41
|
"vue": "^2.7.0"
|
package/src/DataGrid.vue
DELETED
|
@@ -1,1215 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, nextTick, ref, watch, watchEffect } from "vue";
|
|
3
|
-
import type { CSSProperties, PropType } from "vue";
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_COLUMN_WIDTH,
|
|
6
|
-
DEFAULT_OPERATOR_BY_TYPE,
|
|
7
|
-
FILTER_OPERATOR_LABELS,
|
|
8
|
-
FILTER_OPERATORS_BY_TYPE,
|
|
9
|
-
formatAggregate,
|
|
10
|
-
} from "@moda-grid/core";
|
|
11
|
-
import type {
|
|
12
|
-
CellEditorContext,
|
|
13
|
-
CellNavigation,
|
|
14
|
-
ColumnDef,
|
|
15
|
-
ColumnFilter,
|
|
16
|
-
DisplayRow,
|
|
17
|
-
FilterOperator,
|
|
18
|
-
Grid,
|
|
19
|
-
GroupNode,
|
|
20
|
-
LeafDisplayRow,
|
|
21
|
-
SelectionMode,
|
|
22
|
-
ServerSideOptions,
|
|
23
|
-
TreeDataOptions,
|
|
24
|
-
} from "@moda-grid/core";
|
|
25
|
-
import { useGrid, useGridState } from "./useGrid.js";
|
|
26
|
-
|
|
27
|
-
// Vue 2.7 script setup — runtime props 선언 사용
|
|
28
|
-
const props = defineProps({
|
|
29
|
-
columns: { type: Array as PropType<ColumnDef[]>, required: true },
|
|
30
|
-
/** 행 데이터. `grid`를 직접 넘기는 제어 모드에서는 생략 가능 */
|
|
31
|
-
data: { type: Array as PropType<Record<string, unknown>[]>, default: undefined },
|
|
32
|
-
/** 외부에서 생성/관리하는 GridCore. 생략하면 내부 인스턴스 생성 */
|
|
33
|
-
grid: { type: Object as PropType<Grid<any>>, default: undefined },
|
|
34
|
-
getRowId: { type: Function as PropType<(row: Record<string, unknown>) => string>, default: undefined },
|
|
35
|
-
/** 행 클릭 시 선택 토글 */
|
|
36
|
-
selectable: { type: Boolean, default: true },
|
|
37
|
-
/** 가상 스크롤: 뷰포트 높이(px). `rowHeight`와 함께 지정 시 활성 */
|
|
38
|
-
height: { type: Number, default: undefined },
|
|
39
|
-
/** 가상 스크롤: 행 높이(px) */
|
|
40
|
-
rowHeight: { type: Number, default: undefined },
|
|
41
|
-
/** 가상 스크롤: overscan 행 수 */
|
|
42
|
-
overscan: { type: Number, default: undefined },
|
|
43
|
-
/** 헤더 리사이저 핸들 표시 */
|
|
44
|
-
resizable: { type: Boolean, default: true },
|
|
45
|
-
/** 헤더 드래그로 컬럼 순서 변경 허용 */
|
|
46
|
-
reorderable: { type: Boolean, default: true },
|
|
47
|
-
/** 셀 선택 모드: 방향키 이동 + Shift 범위 확장 */
|
|
48
|
-
selectionMode: { type: String as PropType<SelectionMode>, default: undefined },
|
|
49
|
-
/** 서버 사이드 데이터 소스 (내부 GridCore 생성 모드에서만 적용) */
|
|
50
|
-
serverSide: { type: Object as PropType<ServerSideOptions>, default: undefined },
|
|
51
|
-
/** 계층형 데이터: flat parentId 또는 nested children (내부 GridCore 생성 모드에서만 적용) */
|
|
52
|
-
treeData: { type: Object as PropType<TreeDataOptions>, default: undefined },
|
|
53
|
-
/** 우상단 컬럼 관리 도구(체크박스 팝오버 + 전체 선택/해제) 표시 */
|
|
54
|
-
columnController: { type: Boolean, default: false },
|
|
55
|
-
/** 우상단 필터 행 표시/숨김 토글 버튼 표시 — filterable 컬럼이 있을 때만 렌더 */
|
|
56
|
-
filterToggle: { type: Boolean, default: false },
|
|
57
|
-
/** 행 체크박스 선택 컬럼 표시 — 헤더에 전체선택 체크박스 포함 */
|
|
58
|
-
rowCheckboxes: { type: Boolean, default: false },
|
|
59
|
-
/** 맨 왼쪽 행 상태 컬럼 표시 — I(입력)/U(수정)/D(삭제) 마킹 */
|
|
60
|
-
rowStatus: { type: Boolean, default: false },
|
|
61
|
-
/** 선택 영역 집계 상태바 표시 */
|
|
62
|
-
statusBar: { type: Boolean, default: true },
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// 내부 GridCore (grid prop이 없을 때만 생성)
|
|
66
|
-
const internal = props.grid
|
|
67
|
-
? null
|
|
68
|
-
: useGrid({
|
|
69
|
-
columns: props.columns,
|
|
70
|
-
data: props.data ?? [],
|
|
71
|
-
getRowId: props.getRowId,
|
|
72
|
-
serverSide: props.serverSide,
|
|
73
|
-
treeData: props.treeData,
|
|
74
|
-
virtualScroll:
|
|
75
|
-
props.height != null && props.rowHeight != null && props.rowHeight > 0
|
|
76
|
-
? {
|
|
77
|
-
rowHeight: props.rowHeight,
|
|
78
|
-
viewportHeight: props.height,
|
|
79
|
-
overscan: props.overscan,
|
|
80
|
-
}
|
|
81
|
-
: undefined,
|
|
82
|
-
});
|
|
83
|
-
const grid = props.grid ?? internal!.grid;
|
|
84
|
-
const state = props.grid ? useGridState(grid).state : internal!.state;
|
|
85
|
-
// 컬럼 관리 도구 팝오버 열림 상태
|
|
86
|
-
const colCtlOpen = ref(false);
|
|
87
|
-
|
|
88
|
-
// props → core 동기화
|
|
89
|
-
watchEffect(() => {
|
|
90
|
-
if (props.data) grid.setData(props.data);
|
|
91
|
-
});
|
|
92
|
-
watchEffect(() => {
|
|
93
|
-
grid.setColumns(props.columns);
|
|
94
|
-
});
|
|
95
|
-
watchEffect(() => {
|
|
96
|
-
if (props.height != null && props.rowHeight != null && props.rowHeight > 0) {
|
|
97
|
-
grid.setVirtualScroll({
|
|
98
|
-
rowHeight: props.rowHeight,
|
|
99
|
-
viewportHeight: props.height,
|
|
100
|
-
overscan: props.overscan,
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
grid.setVirtualScroll(null);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
watchEffect(() => {
|
|
107
|
-
if (props.selectionMode) grid.setSelectionMode(props.selectionMode);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// 가상 스크롤: 코어가 보정한 scrollTop을 DOM에 동기화 (키보드 scrollIntoView)
|
|
111
|
-
const scrollEl = ref<HTMLElement | null>(null);
|
|
112
|
-
watchEffect(() => {
|
|
113
|
-
const v = state.value.virtual;
|
|
114
|
-
const el = scrollEl.value;
|
|
115
|
-
if (v && el && el.scrollTop !== v.scrollTop) el.scrollTop = v.scrollTop;
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const virtual = computed(() => state.value.virtual);
|
|
119
|
-
// 그룹화 시: displayRows(그룹 헤더 포함)를 virtual 인덱스로 슬라이스
|
|
120
|
-
type RowT = Record<string, unknown>;
|
|
121
|
-
type AnyRow = DisplayRow<RowT> | RowT;
|
|
122
|
-
const bodyRows = computed<AnyRow[]>(() => {
|
|
123
|
-
const displayRows = state.value.displayRows;
|
|
124
|
-
if (displayRows) {
|
|
125
|
-
const v = virtual.value;
|
|
126
|
-
return v ? displayRows.slice(v.startIndex, v.endIndex) : displayRows;
|
|
127
|
-
}
|
|
128
|
-
return (state.value.virtualRows || state.value.rows) as AnyRow[];
|
|
129
|
-
});
|
|
130
|
-
const colSpan = computed(
|
|
131
|
-
() =>
|
|
132
|
-
(state.value.visibleColumns.length || 1) +
|
|
133
|
-
(props.rowCheckboxes ? 1 : 0) +
|
|
134
|
-
(props.rowStatus ? 1 : 0),
|
|
135
|
-
);
|
|
136
|
-
const hasFilterable = computed(() =>
|
|
137
|
-
state.value.visibleColumns.some((c) => c.filterable),
|
|
138
|
-
);
|
|
139
|
-
const hasFilterRow = computed(
|
|
140
|
-
() => hasFilterable.value && state.value.filterRowVisible,
|
|
141
|
-
);
|
|
142
|
-
const showOverlay = computed(
|
|
143
|
-
() => props.columnController || (props.filterToggle && hasFilterable.value),
|
|
144
|
-
);
|
|
145
|
-
const activeFilterCount = computed(
|
|
146
|
-
() => Object.keys(state.value.filters).length,
|
|
147
|
-
);
|
|
148
|
-
const bottomOffset = computed(() =>
|
|
149
|
-
virtual.value && props.rowHeight
|
|
150
|
-
? Math.max(0, virtual.value.totalHeight - virtual.value.endIndex * props.rowHeight)
|
|
151
|
-
: 0,
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// ── 컬럼 고정: [Left | Scrollable | Right] 파티션 + sticky 오프셋 ──
|
|
155
|
-
const lastLeftPinIdx = computed(() =>
|
|
156
|
-
state.value.visibleColumns.reduce(
|
|
157
|
-
(acc, c, i) => (c.pinned === "left" ? i : acc),
|
|
158
|
-
-1,
|
|
159
|
-
),
|
|
160
|
-
);
|
|
161
|
-
const firstRightPinIdx = computed(() =>
|
|
162
|
-
state.value.visibleColumns.findIndex((c) => c.pinned === "right"),
|
|
163
|
-
);
|
|
164
|
-
const hasPinned = computed(
|
|
165
|
-
() => lastLeftPinIdx.value >= 0 || firstRightPinIdx.value >= 0,
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
function pinStyleOf(col: ColumnDef<RowT>): CSSProperties | undefined {
|
|
169
|
-
if (!col.pinned) return undefined;
|
|
170
|
-
const side = col.pinned === "left" ? "left" : "right";
|
|
171
|
-
return {
|
|
172
|
-
position: "sticky",
|
|
173
|
-
width: `${col.width ?? DEFAULT_COLUMN_WIDTH}px`,
|
|
174
|
-
[side]: `${state.value.pinOffsets[col.field] ?? 0}px`,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ── 다중 정렬 ──
|
|
179
|
-
function sortEntryOf(field: string) {
|
|
180
|
-
return state.value.sortState.find((s) => s.columnKey === field);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function sortAria(field: string) {
|
|
184
|
-
const s = sortEntryOf(field);
|
|
185
|
-
if (!s) return "none";
|
|
186
|
-
return s.direction === "asc" ? "ascending" : "descending";
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Vue2 템플릿에서 non-null assertion을 피하기 위한 헬퍼
|
|
190
|
-
function sortArrowOf(field: string) {
|
|
191
|
-
const s = sortEntryOf(field);
|
|
192
|
-
return !s ? "" : s.direction === "asc" ? "▲" : "▼";
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function sortPriorityOf(field: string) {
|
|
196
|
-
const s = sortEntryOf(field);
|
|
197
|
-
return s && state.value.sortState.length > 1 ? String(s.priority) : "";
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function isSelected(row: Record<string, unknown>) {
|
|
201
|
-
return state.value.selectedRowIds.has(grid.getRowId(row));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function onColumnToggle(field: string, event: Event) {
|
|
205
|
-
grid.setColumnVisible(field, (event.target as HTMLInputElement).checked);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function onScroll(event: Event) {
|
|
209
|
-
grid.handleScroll((event.target as HTMLElement).scrollTop);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// ── 연산자 기반 필터 ──
|
|
213
|
-
function filterOpsOf(col: ColumnDef<Record<string, unknown>>) {
|
|
214
|
-
return FILTER_OPERATORS_BY_TYPE[col.filterType || "text"];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function filterOpOf(col: ColumnDef<Record<string, unknown>>): FilterOperator {
|
|
218
|
-
const f = state.value.filters[col.field];
|
|
219
|
-
return f ? f.operator : DEFAULT_OPERATOR_BY_TYPE[col.filterType || "text"];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function filterInputType(col: ColumnDef<Record<string, unknown>>) {
|
|
223
|
-
const t = col.filterType || "text";
|
|
224
|
-
return t === "number" ? "number" : t === "date" ? "date" : "text";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function filterValueOf(col: ColumnDef<Record<string, unknown>>, key: "value" | "valueTo") {
|
|
228
|
-
const f = state.value.filters[col.field];
|
|
229
|
-
return f ? f[key] || "" : "";
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function updateFilter(col: ColumnDef<Record<string, unknown>>, patch: Partial<ColumnFilter>) {
|
|
233
|
-
const f = state.value.filters[col.field];
|
|
234
|
-
grid.setFilter(col.field, {
|
|
235
|
-
operator: filterOpOf(col),
|
|
236
|
-
value: f ? f.value : "",
|
|
237
|
-
valueTo: f ? f.valueTo : undefined,
|
|
238
|
-
...patch,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function onFilterOpChange(col: ColumnDef<Record<string, unknown>>, event: Event) {
|
|
243
|
-
updateFilter(col, {
|
|
244
|
-
operator: (event.target as HTMLSelectElement).value as FilterOperator,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function onFilterInput(col: ColumnDef<Record<string, unknown>>, key: "value" | "valueTo", event: Event) {
|
|
249
|
-
updateFilter(col, { [key]: (event.target as HTMLInputElement).value });
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// ── Set 필터 (엑셀식 값 체크리스트) ──
|
|
253
|
-
function isSetFilter(col: ColumnDef<Record<string, unknown>>) {
|
|
254
|
-
return (col.filterType || "text") === "set";
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function setValuesOf(col: ColumnDef<Record<string, unknown>>): string[] {
|
|
258
|
-
return grid.getUniqueValues(col.field);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function setFilterLabel(col: ColumnDef<Record<string, unknown>>) {
|
|
262
|
-
const f = state.value.filters[col.field];
|
|
263
|
-
const vals = f && f.values;
|
|
264
|
-
return vals ? `${vals.length}개 선택` : "전체";
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function setCheckedOf(col: ColumnDef<Record<string, unknown>>, v: string) {
|
|
268
|
-
const f = state.value.filters[col.field];
|
|
269
|
-
const vals = f && f.values;
|
|
270
|
-
return vals ? vals.includes(v) : true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function setAllCheckedOf(col: ColumnDef<Record<string, unknown>>) {
|
|
274
|
-
const f = state.value.filters[col.field];
|
|
275
|
-
const vals = f && f.values;
|
|
276
|
-
return !vals || vals.length >= setValuesOf(col).length;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function onSetToggle(col: ColumnDef<Record<string, unknown>>, v: string, event: Event) {
|
|
280
|
-
const checked = (event.target as HTMLInputElement).checked;
|
|
281
|
-
const all = setValuesOf(col);
|
|
282
|
-
const f = state.value.filters[col.field];
|
|
283
|
-
const next = new Set((f && f.values) || all);
|
|
284
|
-
if (checked) next.add(v);
|
|
285
|
-
else next.delete(v);
|
|
286
|
-
if (next.size >= all.length) grid.setFilter(col.field, null);
|
|
287
|
-
else {
|
|
288
|
-
grid.setFilter(col.field, {
|
|
289
|
-
operator: "set",
|
|
290
|
-
value: "",
|
|
291
|
-
values: [...next],
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// ── 컬럼 그룹 헤더 (다단계 헤더) ──
|
|
297
|
-
type HeaderCell =
|
|
298
|
-
| { kind: "group"; key: string; header: string; colSpan: number }
|
|
299
|
-
| {
|
|
300
|
-
kind: "col";
|
|
301
|
-
key: string;
|
|
302
|
-
col: ColumnDef<Record<string, unknown>>;
|
|
303
|
-
colIndex: number;
|
|
304
|
-
rowSpan?: number;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const headerRows = computed<HeaderCell[][]>(() => {
|
|
308
|
-
const spans = state.value.headerGroups;
|
|
309
|
-
const cols = state.value.visibleColumns;
|
|
310
|
-
if (!spans) {
|
|
311
|
-
return [
|
|
312
|
-
cols.map((col, colIndex) => ({
|
|
313
|
-
kind: "col" as const,
|
|
314
|
-
key: col.field,
|
|
315
|
-
col,
|
|
316
|
-
colIndex,
|
|
317
|
-
})),
|
|
318
|
-
];
|
|
319
|
-
}
|
|
320
|
-
const row1: HeaderCell[] = spans.map((s) =>
|
|
321
|
-
s.groupId
|
|
322
|
-
? {
|
|
323
|
-
kind: "group",
|
|
324
|
-
key: `g${s.startIndex}`,
|
|
325
|
-
header: s.header || "",
|
|
326
|
-
colSpan: s.colSpan,
|
|
327
|
-
}
|
|
328
|
-
: {
|
|
329
|
-
kind: "col",
|
|
330
|
-
key: cols[s.startIndex]!.field,
|
|
331
|
-
col: cols[s.startIndex]!,
|
|
332
|
-
colIndex: s.startIndex,
|
|
333
|
-
rowSpan: 2,
|
|
334
|
-
},
|
|
335
|
-
);
|
|
336
|
-
const row2: HeaderCell[] = spans.flatMap((s) =>
|
|
337
|
-
s.groupId
|
|
338
|
-
? cols
|
|
339
|
-
.slice(s.startIndex, s.startIndex + s.colSpan)
|
|
340
|
-
.map((col, i) => ({
|
|
341
|
-
kind: "col" as const,
|
|
342
|
-
key: col.field,
|
|
343
|
-
col,
|
|
344
|
-
colIndex: s.startIndex + i,
|
|
345
|
-
}))
|
|
346
|
-
: [],
|
|
347
|
-
);
|
|
348
|
-
return row2.length > 0 ? [row1, row2] : [row1];
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
const headerRowSpan = computed(() => headerRows.value.length);
|
|
352
|
-
|
|
353
|
-
// ── 컬럼 리사이즈: document mousemove를 rAF로 스로틀 ──
|
|
354
|
-
let resizeRaf = 0;
|
|
355
|
-
let pendingWidth: { field: string; width: number } | null = null;
|
|
356
|
-
|
|
357
|
-
function onResizeStart(col: ColumnDef, event: MouseEvent) {
|
|
358
|
-
const th = (event.currentTarget as HTMLElement).closest("th");
|
|
359
|
-
const startWidth = th?.getBoundingClientRect().width ?? 0;
|
|
360
|
-
const startX = event.clientX;
|
|
361
|
-
const field = col.field;
|
|
362
|
-
|
|
363
|
-
const onMove = (ev: MouseEvent) => {
|
|
364
|
-
pendingWidth = { field, width: startWidth + (ev.clientX - startX) };
|
|
365
|
-
if (resizeRaf === 0) {
|
|
366
|
-
resizeRaf = requestAnimationFrame(() => {
|
|
367
|
-
resizeRaf = 0;
|
|
368
|
-
if (pendingWidth) grid.setColumnWidth(pendingWidth.field, pendingWidth.width);
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
const onUp = () => {
|
|
373
|
-
document.removeEventListener("mousemove", onMove);
|
|
374
|
-
document.removeEventListener("mouseup", onUp);
|
|
375
|
-
if (resizeRaf !== 0) {
|
|
376
|
-
cancelAnimationFrame(resizeRaf);
|
|
377
|
-
resizeRaf = 0;
|
|
378
|
-
}
|
|
379
|
-
if (pendingWidth) grid.setColumnWidth(pendingWidth.field, pendingWidth.width);
|
|
380
|
-
pendingWidth = null;
|
|
381
|
-
};
|
|
382
|
-
document.addEventListener("mousemove", onMove);
|
|
383
|
-
document.addEventListener("mouseup", onUp);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// 키보드 리사이즈 (방향키 ±10px)
|
|
387
|
-
function onResizerKeydown(col: ColumnDef, event: KeyboardEvent) {
|
|
388
|
-
const delta = event.key === "ArrowLeft" ? -10 : event.key === "ArrowRight" ? 10 : 0;
|
|
389
|
-
if (delta === 0) return;
|
|
390
|
-
event.preventDefault();
|
|
391
|
-
const th = (event.currentTarget as HTMLElement).closest("th");
|
|
392
|
-
const w = th?.getBoundingClientRect().width ?? col.width ?? 0;
|
|
393
|
-
grid.setColumnWidth(col.field, w + delta);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// ── 컬럼 드래그 재배치 (HTML5 DnD) ──
|
|
397
|
-
const dragOverField = ref<string | null>(null);
|
|
398
|
-
let dragField: string | null = null;
|
|
399
|
-
|
|
400
|
-
function onDragStart(col: ColumnDef, event: DragEvent) {
|
|
401
|
-
dragField = col.field;
|
|
402
|
-
if (event.dataTransfer) {
|
|
403
|
-
event.dataTransfer.effectAllowed = "move";
|
|
404
|
-
event.dataTransfer.setData("text/plain", col.field);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function onDragOver(col: ColumnDef, event: DragEvent) {
|
|
409
|
-
if (!props.reorderable || !dragField || dragField === col.field) return;
|
|
410
|
-
event.preventDefault();
|
|
411
|
-
if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
|
|
412
|
-
if (dragOverField.value !== col.field) dragOverField.value = col.field;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
function onDrop(col: ColumnDef, event: DragEvent) {
|
|
416
|
-
event.preventDefault();
|
|
417
|
-
if (dragField && dragField !== col.field) {
|
|
418
|
-
grid.reorderColumn(dragField, col.field);
|
|
419
|
-
}
|
|
420
|
-
onDragEnd();
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function onDragEnd() {
|
|
424
|
-
dragField = null;
|
|
425
|
-
dragOverField.value = null;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// ── 행 드래그앤드롭 (HTML5 DnD) ──
|
|
429
|
-
// 정렬/그룹화/서버 모드에서는 표시 순서가 rawData와 무관 — 비활성 (스냅샷에서 유도)
|
|
430
|
-
const rowDraggable = computed(
|
|
431
|
-
() =>
|
|
432
|
-
!state.value.serverSide &&
|
|
433
|
-
state.value.sortState.length === 0 &&
|
|
434
|
-
state.value.groupBy.length === 0,
|
|
435
|
-
);
|
|
436
|
-
const rowCount = computed(() => state.value.rows.length);
|
|
437
|
-
// 자기 자신 위/바로 아래 갭은 제자리 드롭 — 인디케이터를 숨긴다
|
|
438
|
-
const dropGap = computed(() => {
|
|
439
|
-
const rd = state.value.rowDrag;
|
|
440
|
-
if (!rd || rd.dropIndex == null) return null;
|
|
441
|
-
if (rd.dropIndex === rd.draggingIndex || rd.dropIndex === rd.draggingIndex + 1)
|
|
442
|
-
return null;
|
|
443
|
-
return rd.dropIndex;
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
function rowClassOf(entry: AnyRow, rowIdx: number) {
|
|
447
|
-
const rowIndex = entryIndexOf(entry, rowIdx);
|
|
448
|
-
const rd = state.value.rowDrag;
|
|
449
|
-
const row = rowDataOf(entry);
|
|
450
|
-
const status = row ? rowStateOf(row) : undefined;
|
|
451
|
-
return [
|
|
452
|
-
{
|
|
453
|
-
"mg-selected": isSelected(row),
|
|
454
|
-
"mg-row-dragging": rd?.draggingIndex === rowIndex,
|
|
455
|
-
"mg-drop-before": dropGap.value === rowIndex,
|
|
456
|
-
"mg-drop-after":
|
|
457
|
-
dropGap.value === rowCount.value && rowIndex === rowCount.value - 1,
|
|
458
|
-
},
|
|
459
|
-
status ? `mg-row-${status}` : "",
|
|
460
|
-
// 커스텀 행 클래스 (GridOptions/ColumnDef.rowClass)
|
|
461
|
-
row == null ? "" : grid.getRowClass(row, rowIndex),
|
|
462
|
-
];
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function rowStateOf(row: RowT | null | undefined) {
|
|
466
|
-
return row ? state.value.rowStates[grid.getRowId(row)] : undefined;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/** 변경(I/U/D) 행의 셀 유효성 에러 — required/validate 검사. 없으면 null. */
|
|
470
|
-
function cellErrorOf(entry: AnyRow, col: ColumnDef): string | null {
|
|
471
|
-
const row = rowDataOf(entry);
|
|
472
|
-
if (!row || !rowStateOf(row)) return null;
|
|
473
|
-
if (!col.required && !col.validate) return null;
|
|
474
|
-
return grid.getCellError(row, col);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function cellClassOf(entry: AnyRow, rowIdx: number, col: ColumnDef) {
|
|
478
|
-
const row = rowDataOf(entry);
|
|
479
|
-
if (row == null) return "";
|
|
480
|
-
return grid.getCellClass(row, entryIndexOf(entry, rowIdx), col);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function onRowDragStart(rowIndex: number, event: DragEvent) {
|
|
484
|
-
if (!grid.beginRowDrag(rowIndex)) {
|
|
485
|
-
event.preventDefault();
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
if (event.dataTransfer) {
|
|
489
|
-
event.dataTransfer.effectAllowed = "move";
|
|
490
|
-
event.dataTransfer.setData("text/plain", "");
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function onRowDragOver(rowIndex: number, event: DragEvent) {
|
|
495
|
-
if (!state.value.rowDrag) return;
|
|
496
|
-
event.preventDefault();
|
|
497
|
-
if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
|
|
498
|
-
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
499
|
-
const gap =
|
|
500
|
-
event.clientY < rect.top + rect.height / 2 ? rowIndex : rowIndex + 1;
|
|
501
|
-
grid.updateRowDropPosition(gap);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function onRowDrop(event: DragEvent) {
|
|
505
|
-
if (!state.value.rowDrag) return;
|
|
506
|
-
event.preventDefault();
|
|
507
|
-
grid.endRowDrag(true);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function onRowDragEnd() {
|
|
511
|
-
grid.endRowDrag(false);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// ── 셀 선택: 방향키/Home/End/PageUp·Down → 코어 네비게이션 ──
|
|
515
|
-
const CELL_KEYS: Record<string, CellNavigation> = {
|
|
516
|
-
ArrowUp: "up",
|
|
517
|
-
ArrowDown: "down",
|
|
518
|
-
ArrowLeft: "left",
|
|
519
|
-
ArrowRight: "right",
|
|
520
|
-
Home: "home",
|
|
521
|
-
End: "end",
|
|
522
|
-
PageUp: "pageUp",
|
|
523
|
-
PageDown: "pageDown",
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
function onGridKeydown(event: KeyboardEvent) {
|
|
527
|
-
if ((event.target as HTMLElement).closest("input, textarea, select")) return;
|
|
528
|
-
// 클립보드/이력: Ctrl+C 복사, Ctrl+Shift+C 헤더 포함 복사,
|
|
529
|
-
// Ctrl+V 붙여넣기, Ctrl+Z 되돌리기, Ctrl+Y·Ctrl+Shift+Z 다시 실행
|
|
530
|
-
if (event.ctrlKey || event.metaKey) {
|
|
531
|
-
const key = event.key.toLowerCase();
|
|
532
|
-
if (key === "c") {
|
|
533
|
-
const tsv = grid.getSelectionTsv({ includeHeaders: event.shiftKey });
|
|
534
|
-
if (tsv != null) {
|
|
535
|
-
event.preventDefault();
|
|
536
|
-
void navigator.clipboard?.writeText(tsv);
|
|
537
|
-
}
|
|
538
|
-
} else if (key === "v") {
|
|
539
|
-
event.preventDefault();
|
|
540
|
-
void navigator.clipboard?.readText().then((text) => grid.pasteTsv(text));
|
|
541
|
-
} else if (key === "z") {
|
|
542
|
-
event.preventDefault();
|
|
543
|
-
if (event.shiftKey) grid.redo();
|
|
544
|
-
else grid.undo();
|
|
545
|
-
} else if (key === "y") {
|
|
546
|
-
event.preventDefault();
|
|
547
|
-
grid.redo();
|
|
548
|
-
}
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
if (event.key === "Escape") {
|
|
552
|
-
if (state.value.rowDrag) grid.endRowDrag(false);
|
|
553
|
-
else grid.clearCellSelection();
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
const active = state.value.activeCell;
|
|
557
|
-
if (event.key === "Enter" || event.key === "F2") {
|
|
558
|
-
// 활성 셀에서 Enter → 편집 진입
|
|
559
|
-
if (active) {
|
|
560
|
-
event.preventDefault();
|
|
561
|
-
grid.startEditing(active.rowIndex, active.columnIndex);
|
|
562
|
-
}
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
const dir = CELL_KEYS[event.key];
|
|
566
|
-
if (dir) {
|
|
567
|
-
event.preventDefault();
|
|
568
|
-
grid.navigateCell(dir, event.shiftKey);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
// 인쇄 가능한 문자 직접 입력 → 값을 교체하며 편집 진입
|
|
572
|
-
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey && active) {
|
|
573
|
-
event.preventDefault();
|
|
574
|
-
grid.startEditing(active.rowIndex, active.columnIndex, event.key);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// 가상 스크롤/그룹화 시 행 인덱스 → visibleData 기준 인덱스
|
|
579
|
-
function isGroupRow(entry: AnyRow) {
|
|
580
|
-
return (entry as DisplayRow<RowT> | undefined)?.type === "group";
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function groupOf(entry: AnyRow): GroupNode<RowT> {
|
|
584
|
-
return entry as GroupNode<RowT>;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function leafOf(entry: AnyRow): LeafDisplayRow<RowT> | null {
|
|
588
|
-
const e = entry as DisplayRow<RowT>;
|
|
589
|
-
return e && e.type === "leaf" ? (e as LeafDisplayRow<RowT>) : null;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
function rowDataOf(entry: AnyRow): RowT {
|
|
593
|
-
const l = leafOf(entry);
|
|
594
|
-
return l ? l.row : (entry as RowT);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function leafDepthOf(entry: AnyRow) {
|
|
598
|
-
const l = leafOf(entry);
|
|
599
|
-
return l ? l.depth : 0;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// 트리 노드 헬퍼 — 템플릿에서 non-null 단언(!)을 쓸 수 없어 함수로 노출
|
|
603
|
-
function leafHasChildren(entry: AnyRow): boolean | undefined {
|
|
604
|
-
return leafOf(entry)?.hasChildren;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
function leafExpanded(entry: AnyRow): boolean {
|
|
608
|
-
return leafOf(entry)?.expanded === true;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
function entryIndexOf(entry: AnyRow, rowIdx: number) {
|
|
612
|
-
const l = leafOf(entry);
|
|
613
|
-
if (l) return l.rowIndex;
|
|
614
|
-
return virtual.value ? virtual.value.startIndex + rowIdx : rowIdx;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
function rowKeyOf(entry: AnyRow) {
|
|
618
|
-
return isGroupRow(entry)
|
|
619
|
-
? groupOf(entry).key
|
|
620
|
-
: grid.getRowId(rowDataOf(entry));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function groupLabelOf(entry: AnyRow) {
|
|
624
|
-
const n = groupOf(entry);
|
|
625
|
-
const col = state.value.columns.find((c) => c.field === n.field);
|
|
626
|
-
const header = col && col.header ? col.header : n.field;
|
|
627
|
-
return `${header}: ${String(n.value == null ? "(빈 값)" : n.value)}`;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
function groupAggOf(entry: AnyRow, col: ColumnDef<RowT>) {
|
|
631
|
-
if (!col.aggregationFn) return "";
|
|
632
|
-
return formatAggregate(groupOf(entry).aggregates[col.field]);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
function onToggleGroup(entry: AnyRow) {
|
|
636
|
-
grid.toggleGroupExpanded(groupOf(entry).key);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// ── 인라인 셀 편집 ──
|
|
640
|
-
function isEditingCell(rowIndex: number, col: ColumnDef) {
|
|
641
|
-
const cell = state.value.editingCell;
|
|
642
|
-
return !!cell && cell.rowIndex === rowIndex && cell.columnKey === col.field;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
function editorContext(rowIndex: number, colIndex: number) {
|
|
646
|
-
return grid.getEditorContext(rowIndex, colIndex) as CellEditorContext;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
function editorInputType(col: ColumnDef) {
|
|
650
|
-
return col.cellEditor === "number"
|
|
651
|
-
? "number"
|
|
652
|
-
: col.cellEditor === "date"
|
|
653
|
-
? "date"
|
|
654
|
-
: "text";
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function onEditorInput(event: Event) {
|
|
658
|
-
grid.updateEditValue((event.target as HTMLInputElement | HTMLSelectElement).value);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
// 편집기 내부 키: Enter 저장, Tab 저장+이동, Escape 취소
|
|
662
|
-
function onEditorKeydown(event: KeyboardEvent) {
|
|
663
|
-
event.stopPropagation();
|
|
664
|
-
if (event.key === "Enter") {
|
|
665
|
-
event.preventDefault();
|
|
666
|
-
if (grid.commitEditing()) grid.navigateCell("down");
|
|
667
|
-
} else if (event.key === "Tab") {
|
|
668
|
-
event.preventDefault();
|
|
669
|
-
if (grid.commitEditing()) grid.navigateCell(event.shiftKey ? "left" : "right");
|
|
670
|
-
} else if (event.key === "Escape") {
|
|
671
|
-
event.preventDefault();
|
|
672
|
-
grid.cancelEditing();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// 편집 진입 시 에디터 포커스
|
|
677
|
-
watch(
|
|
678
|
-
() => state.value.editingCell,
|
|
679
|
-
async (cell) => {
|
|
680
|
-
if (!cell) return;
|
|
681
|
-
await nextTick();
|
|
682
|
-
scrollEl.value?.querySelector<HTMLElement>(".mg-editor")?.focus();
|
|
683
|
-
},
|
|
684
|
-
);
|
|
685
|
-
</script>
|
|
686
|
-
|
|
687
|
-
<template>
|
|
688
|
-
<div :class="showOverlay ? 'mg-colctl-host' : undefined">
|
|
689
|
-
<div v-if="showOverlay" class="mg-colctl">
|
|
690
|
-
<button
|
|
691
|
-
v-if="filterToggle && hasFilterable"
|
|
692
|
-
type="button"
|
|
693
|
-
class="mg-colctl-btn"
|
|
694
|
-
:aria-pressed="state.filterRowVisible"
|
|
695
|
-
@click="grid.setFilterRowVisible(!state.filterRowVisible)"
|
|
696
|
-
>
|
|
697
|
-
필터 {{ state.filterRowVisible ? "▾" : "▸"
|
|
698
|
-
}}<template v-if="activeFilterCount > 0">
|
|
699
|
-
({{ activeFilterCount }})</template
|
|
700
|
-
>
|
|
701
|
-
</button>
|
|
702
|
-
<button
|
|
703
|
-
v-if="columnController"
|
|
704
|
-
type="button"
|
|
705
|
-
class="mg-colctl-btn"
|
|
706
|
-
:aria-expanded="colCtlOpen"
|
|
707
|
-
@click="colCtlOpen = !colCtlOpen"
|
|
708
|
-
>
|
|
709
|
-
컬럼 ▾
|
|
710
|
-
</button>
|
|
711
|
-
<template v-if="colCtlOpen">
|
|
712
|
-
<div class="mg-colctl-overlay" @click="colCtlOpen = false"></div>
|
|
713
|
-
<div
|
|
714
|
-
class="mg-colctl-panel"
|
|
715
|
-
role="dialog"
|
|
716
|
-
aria-label="컬럼 관리"
|
|
717
|
-
@keydown.esc="colCtlOpen = false"
|
|
718
|
-
>
|
|
719
|
-
<div class="mg-colctl-actions">
|
|
720
|
-
<button type="button" @click="grid.setAllColumnsVisible(true)">
|
|
721
|
-
전체 선택
|
|
722
|
-
</button>
|
|
723
|
-
<button type="button" @click="grid.setAllColumnsVisible(false)">
|
|
724
|
-
전체 해제
|
|
725
|
-
</button>
|
|
726
|
-
</div>
|
|
727
|
-
<label
|
|
728
|
-
v-for="col in state.columns"
|
|
729
|
-
:key="col.field"
|
|
730
|
-
class="mg-colctl-item"
|
|
731
|
-
>
|
|
732
|
-
<input
|
|
733
|
-
type="checkbox"
|
|
734
|
-
:checked="col.visible !== false"
|
|
735
|
-
@change="onColumnToggle(col.field, $event)"
|
|
736
|
-
/>
|
|
737
|
-
{{ col.header ?? col.field }}
|
|
738
|
-
</label>
|
|
739
|
-
</div>
|
|
740
|
-
</template>
|
|
741
|
-
</div>
|
|
742
|
-
<div
|
|
743
|
-
ref="scrollEl"
|
|
744
|
-
:class="{ 'mg-scroll': virtual || hasPinned }"
|
|
745
|
-
:style="
|
|
746
|
-
virtual && height
|
|
747
|
-
? { height: `${height}px`, overflow: 'auto' }
|
|
748
|
-
: hasPinned
|
|
749
|
-
? { overflowX: 'auto' }
|
|
750
|
-
: undefined
|
|
751
|
-
"
|
|
752
|
-
@scroll="onScroll"
|
|
753
|
-
>
|
|
754
|
-
<table class="mg-table" role="grid" tabindex="0" @keydown="onGridKeydown">
|
|
755
|
-
<thead>
|
|
756
|
-
<tr v-for="(row, rowIdx) in headerRows" :key="rowIdx">
|
|
757
|
-
<th
|
|
758
|
-
v-if="rowStatus && rowIdx === 0"
|
|
759
|
-
:rowspan="headerRowSpan"
|
|
760
|
-
class="mg-status-cell"
|
|
761
|
-
title="행 상태 — I: 입력, U: 수정, D: 삭제"
|
|
762
|
-
>
|
|
763
|
-
상태
|
|
764
|
-
</th>
|
|
765
|
-
<th
|
|
766
|
-
v-if="rowCheckboxes && rowIdx === 0"
|
|
767
|
-
:rowspan="headerRowSpan"
|
|
768
|
-
class="mg-check-cell"
|
|
769
|
-
>
|
|
770
|
-
<input
|
|
771
|
-
type="checkbox"
|
|
772
|
-
aria-label="전체 행 선택"
|
|
773
|
-
:checked="grid.isAllSelected()"
|
|
774
|
-
:indeterminate.prop="grid.isSomeSelected()"
|
|
775
|
-
@click.stop
|
|
776
|
-
@change="grid.toggleAllRows()"
|
|
777
|
-
/>
|
|
778
|
-
</th>
|
|
779
|
-
<template v-for="cell in row" :key="cell.key">
|
|
780
|
-
<th
|
|
781
|
-
v-if="cell.kind === 'group'"
|
|
782
|
-
:colspan="cell.colSpan"
|
|
783
|
-
class="mg-colgroup"
|
|
784
|
-
>
|
|
785
|
-
{{ cell.header }}
|
|
786
|
-
</th>
|
|
787
|
-
<th
|
|
788
|
-
v-else
|
|
789
|
-
:rowspan="cell.rowSpan"
|
|
790
|
-
:style="
|
|
791
|
-
cell.col.pinned
|
|
792
|
-
? pinStyleOf(cell.col)
|
|
793
|
-
: cell.col.width
|
|
794
|
-
? { width: `${cell.col.width}px` }
|
|
795
|
-
: undefined
|
|
796
|
-
"
|
|
797
|
-
:class="{
|
|
798
|
-
'mg-sortable': cell.col.sortable !== false,
|
|
799
|
-
'mg-col-dragover': dragOverField === cell.col.field,
|
|
800
|
-
'mg-pinned': !!cell.col.pinned,
|
|
801
|
-
'mg-pin-left-edge': cell.colIndex === lastLeftPinIdx,
|
|
802
|
-
'mg-pin-right-edge': cell.colIndex === firstRightPinIdx,
|
|
803
|
-
}"
|
|
804
|
-
:aria-sort="sortAria(cell.col.field)"
|
|
805
|
-
:draggable="reorderable"
|
|
806
|
-
@dragstart="onDragStart(cell.col, $event)"
|
|
807
|
-
@dragover="onDragOver(cell.col, $event)"
|
|
808
|
-
@drop="onDrop(cell.col, $event)"
|
|
809
|
-
@dragend="onDragEnd"
|
|
810
|
-
@click="grid.toggleSort(cell.col.field, $event.shiftKey)"
|
|
811
|
-
>
|
|
812
|
-
{{ cell.col.header || cell.col.field }}
|
|
813
|
-
<span v-if="cell.col.required" class="mg-required-mark">*</span>
|
|
814
|
-
<span v-if="sortArrowOf(cell.col.field)" class="mg-sort-arrow">
|
|
815
|
-
{{ sortArrowOf(cell.col.field) }}
|
|
816
|
-
</span>
|
|
817
|
-
<span v-if="sortPriorityOf(cell.col.field)" class="mg-sort-priority">
|
|
818
|
-
{{ sortPriorityOf(cell.col.field) }}
|
|
819
|
-
</span>
|
|
820
|
-
<button
|
|
821
|
-
v-if="resizable && cell.col.resizable !== false"
|
|
822
|
-
type="button"
|
|
823
|
-
class="mg-resizer"
|
|
824
|
-
:aria-label="`${cell.col.field} 너비 조절`"
|
|
825
|
-
@mousedown.stop.prevent="onResizeStart(cell.col, $event)"
|
|
826
|
-
@keydown.stop="onResizerKeydown(cell.col, $event)"
|
|
827
|
-
@click.stop
|
|
828
|
-
/>
|
|
829
|
-
</th>
|
|
830
|
-
</template>
|
|
831
|
-
</tr>
|
|
832
|
-
<tr v-if="hasFilterRow" class="mg-filter-row">
|
|
833
|
-
<th v-if="rowStatus" class="mg-status-cell" />
|
|
834
|
-
<th v-if="rowCheckboxes" class="mg-check-cell" />
|
|
835
|
-
<th
|
|
836
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
837
|
-
:key="col.field"
|
|
838
|
-
:class="{
|
|
839
|
-
'mg-pinned': !!col.pinned,
|
|
840
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
841
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
842
|
-
}"
|
|
843
|
-
:style="pinStyleOf(col)"
|
|
844
|
-
>
|
|
845
|
-
<div v-if="col.filterable" class="mg-filter-cell">
|
|
846
|
-
<details v-if="isSetFilter(col)" class="mg-setfilter">
|
|
847
|
-
<summary>{{ setFilterLabel(col) }}</summary>
|
|
848
|
-
<div class="mg-setfilter-panel">
|
|
849
|
-
<label class="mg-setfilter-item">
|
|
850
|
-
<input
|
|
851
|
-
type="checkbox"
|
|
852
|
-
:checked="setAllCheckedOf(col)"
|
|
853
|
-
@change="grid.setFilter(col.field, null)"
|
|
854
|
-
/>
|
|
855
|
-
(전체 선택)
|
|
856
|
-
</label>
|
|
857
|
-
<label
|
|
858
|
-
v-for="v in setValuesOf(col)"
|
|
859
|
-
:key="v"
|
|
860
|
-
class="mg-setfilter-item"
|
|
861
|
-
>
|
|
862
|
-
<input
|
|
863
|
-
type="checkbox"
|
|
864
|
-
:checked="setCheckedOf(col, v)"
|
|
865
|
-
@change="onSetToggle(col, v, $event)"
|
|
866
|
-
/>
|
|
867
|
-
{{ v }}
|
|
868
|
-
</label>
|
|
869
|
-
</div>
|
|
870
|
-
</details>
|
|
871
|
-
<template v-else>
|
|
872
|
-
<select
|
|
873
|
-
class="mg-filter-op"
|
|
874
|
-
:value="filterOpOf(col)"
|
|
875
|
-
@change="onFilterOpChange(col, $event)"
|
|
876
|
-
>
|
|
877
|
-
<option v-for="op in filterOpsOf(col)" :key="op" :value="op">
|
|
878
|
-
{{ FILTER_OPERATOR_LABELS[op] }}
|
|
879
|
-
</option>
|
|
880
|
-
</select>
|
|
881
|
-
<input
|
|
882
|
-
class="mg-filter-input"
|
|
883
|
-
:type="filterInputType(col)"
|
|
884
|
-
:value="filterValueOf(col, 'value')"
|
|
885
|
-
:placeholder="`${col.header || col.field} 필터`"
|
|
886
|
-
@input="onFilterInput(col, 'value', $event)"
|
|
887
|
-
/>
|
|
888
|
-
<input
|
|
889
|
-
v-if="filterOpOf(col) === 'inRange'"
|
|
890
|
-
class="mg-filter-input mg-filter-to"
|
|
891
|
-
:type="filterInputType(col)"
|
|
892
|
-
:value="filterValueOf(col, 'valueTo')"
|
|
893
|
-
placeholder="~ 까지"
|
|
894
|
-
@input="onFilterInput(col, 'valueTo', $event)"
|
|
895
|
-
/>
|
|
896
|
-
</template>
|
|
897
|
-
</div>
|
|
898
|
-
</th>
|
|
899
|
-
</tr>
|
|
900
|
-
</thead>
|
|
901
|
-
<tbody>
|
|
902
|
-
<tr
|
|
903
|
-
v-for="(prow, pIdx) in state.pinnedTopRows"
|
|
904
|
-
:key="`pin-top-${pIdx}`"
|
|
905
|
-
class="mg-pinned-top-row"
|
|
906
|
-
>
|
|
907
|
-
<td v-if="rowStatus" class="mg-status-cell" />
|
|
908
|
-
<td v-if="rowCheckboxes" class="mg-check-cell" />
|
|
909
|
-
<td
|
|
910
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
911
|
-
:key="col.field"
|
|
912
|
-
:class="{
|
|
913
|
-
'mg-pinned': !!col.pinned,
|
|
914
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
915
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
916
|
-
}"
|
|
917
|
-
:style="pinStyleOf(col)"
|
|
918
|
-
>
|
|
919
|
-
{{ grid.getCellText(prow, col) }}
|
|
920
|
-
</td>
|
|
921
|
-
</tr>
|
|
922
|
-
<tr
|
|
923
|
-
v-if="virtual && virtual.startOffset > 0"
|
|
924
|
-
class="mg-spacer"
|
|
925
|
-
aria-hidden="true"
|
|
926
|
-
>
|
|
927
|
-
<td :colspan="colSpan" :style="{ height: `${virtual.startOffset}px`, padding: 0 }" />
|
|
928
|
-
</tr>
|
|
929
|
-
<tr v-if="bodyRows.length === 0">
|
|
930
|
-
<td class="mg-empty" :colspan="colSpan">No rows</td>
|
|
931
|
-
</tr>
|
|
932
|
-
<template v-for="(entry, rowIdx) in bodyRows" :key="rowKeyOf(entry)">
|
|
933
|
-
<!-- 그룹 헤더 행 -->
|
|
934
|
-
<tr
|
|
935
|
-
v-if="isGroupRow(entry)"
|
|
936
|
-
class="mg-group-row"
|
|
937
|
-
@click="onToggleGroup(entry)"
|
|
938
|
-
>
|
|
939
|
-
<td v-if="rowStatus" class="mg-status-cell" />
|
|
940
|
-
<td v-if="rowCheckboxes" class="mg-check-cell" />
|
|
941
|
-
<td
|
|
942
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
943
|
-
:key="col.field"
|
|
944
|
-
class="mg-group-cell"
|
|
945
|
-
:class="{
|
|
946
|
-
'mg-pinned': !!col.pinned,
|
|
947
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
948
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
949
|
-
}"
|
|
950
|
-
:style="pinStyleOf(col)"
|
|
951
|
-
>
|
|
952
|
-
<span
|
|
953
|
-
v-if="colIndex === 0"
|
|
954
|
-
class="mg-group-label"
|
|
955
|
-
:style="{ paddingLeft: `${groupOf(entry).depth * 16}px` }"
|
|
956
|
-
>
|
|
957
|
-
<span class="mg-group-toggle">
|
|
958
|
-
{{ groupOf(entry).expanded ? "▾" : "▸" }}
|
|
959
|
-
</span>
|
|
960
|
-
<strong>{{ groupLabelOf(entry) }}</strong>
|
|
961
|
-
<span class="mg-group-count">({{ groupOf(entry).rowCount }})</span>
|
|
962
|
-
</span>
|
|
963
|
-
<span v-else-if="groupAggOf(entry, col)" class="mg-agg">
|
|
964
|
-
{{ groupAggOf(entry, col) }}
|
|
965
|
-
</span>
|
|
966
|
-
</td>
|
|
967
|
-
</tr>
|
|
968
|
-
<!-- 서버 사이드 미로드 행 → 스켈레톤 -->
|
|
969
|
-
<tr
|
|
970
|
-
v-else-if="rowDataOf(entry) == null"
|
|
971
|
-
class="mg-skeleton-row"
|
|
972
|
-
aria-hidden="true"
|
|
973
|
-
>
|
|
974
|
-
<td v-if="rowStatus" class="mg-status-cell" />
|
|
975
|
-
<td v-if="rowCheckboxes" class="mg-check-cell" />
|
|
976
|
-
<td
|
|
977
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
978
|
-
:key="col.field"
|
|
979
|
-
:class="{
|
|
980
|
-
'mg-pinned': !!col.pinned,
|
|
981
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
982
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
983
|
-
}"
|
|
984
|
-
:style="pinStyleOf(col)"
|
|
985
|
-
>
|
|
986
|
-
<span class="mg-skeleton-bar" />
|
|
987
|
-
</td>
|
|
988
|
-
</tr>
|
|
989
|
-
<!-- 리프(데이터) 행 -->
|
|
990
|
-
<tr
|
|
991
|
-
v-else
|
|
992
|
-
:class="rowClassOf(entry, rowIdx)"
|
|
993
|
-
:style="virtual && rowHeight ? { height: `${rowHeight}px` } : undefined"
|
|
994
|
-
@click="selectable && grid.toggleRowSelection(grid.getRowId(rowDataOf(entry)))"
|
|
995
|
-
@dragover="onRowDragOver(entryIndexOf(entry, rowIdx), $event)"
|
|
996
|
-
@drop="onRowDrop($event)"
|
|
997
|
-
>
|
|
998
|
-
<td
|
|
999
|
-
v-if="rowStatus"
|
|
1000
|
-
class="mg-status-cell"
|
|
1001
|
-
:class="
|
|
1002
|
-
rowStateOf(rowDataOf(entry))
|
|
1003
|
-
? `mg-status-${rowStateOf(rowDataOf(entry))}`
|
|
1004
|
-
: undefined
|
|
1005
|
-
"
|
|
1006
|
-
>
|
|
1007
|
-
{{ rowStateOf(rowDataOf(entry)) ?? "" }}
|
|
1008
|
-
</td>
|
|
1009
|
-
<td
|
|
1010
|
-
v-if="rowCheckboxes"
|
|
1011
|
-
class="mg-check-cell"
|
|
1012
|
-
@click.stop
|
|
1013
|
-
>
|
|
1014
|
-
<input
|
|
1015
|
-
type="checkbox"
|
|
1016
|
-
aria-label="행 선택"
|
|
1017
|
-
:checked="isSelected(rowDataOf(entry))"
|
|
1018
|
-
@change="
|
|
1019
|
-
grid.toggleRowSelection(grid.getRowId(rowDataOf(entry)))
|
|
1020
|
-
"
|
|
1021
|
-
/>
|
|
1022
|
-
</td>
|
|
1023
|
-
<td
|
|
1024
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
1025
|
-
:key="col.field"
|
|
1026
|
-
:class="[
|
|
1027
|
-
{
|
|
1028
|
-
'mg-cell-active': grid.isActiveCell(entryIndexOf(entry, rowIdx), colIndex),
|
|
1029
|
-
'mg-cell-selected': grid.isCellInRange(entryIndexOf(entry, rowIdx), colIndex),
|
|
1030
|
-
'mg-cell-editing': isEditingCell(entryIndexOf(entry, rowIdx), col),
|
|
1031
|
-
'mg-cell-invalid': !!cellErrorOf(entry, col),
|
|
1032
|
-
'mg-pinned': !!col.pinned,
|
|
1033
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
1034
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
1035
|
-
},
|
|
1036
|
-
cellClassOf(entry, rowIdx, col),
|
|
1037
|
-
]"
|
|
1038
|
-
:title="cellErrorOf(entry, col) || undefined"
|
|
1039
|
-
:style="[
|
|
1040
|
-
pinStyleOf(col),
|
|
1041
|
-
colIndex === 0 && leafDepthOf(entry)
|
|
1042
|
-
? { paddingLeft: `${leafDepthOf(entry) * 16 + 12}px` }
|
|
1043
|
-
: undefined,
|
|
1044
|
-
]"
|
|
1045
|
-
@click="grid.setActiveCell(entryIndexOf(entry, rowIdx), colIndex)"
|
|
1046
|
-
@dblclick="grid.startEditing(entryIndexOf(entry, rowIdx), colIndex)"
|
|
1047
|
-
>
|
|
1048
|
-
<button
|
|
1049
|
-
v-if="colIndex === 0 && leafHasChildren(entry) !== undefined"
|
|
1050
|
-
type="button"
|
|
1051
|
-
class="mg-tree-toggle"
|
|
1052
|
-
:class="{ 'mg-tree-leaf': !leafHasChildren(entry) }"
|
|
1053
|
-
:aria-label="leafExpanded(entry) ? '접기' : '펼치기'"
|
|
1054
|
-
:disabled="!leafHasChildren(entry)"
|
|
1055
|
-
@click.stop="grid.toggleTreeExpanded(grid.getRowId(rowDataOf(entry)))"
|
|
1056
|
-
>
|
|
1057
|
-
{{ leafHasChildren(entry) ? (leafExpanded(entry) ? "▾" : "▸") : "" }}
|
|
1058
|
-
</button>
|
|
1059
|
-
<span
|
|
1060
|
-
v-if="col.rowDrag && !isEditingCell(entryIndexOf(entry, rowIdx), col)"
|
|
1061
|
-
class="mg-row-drag-handle"
|
|
1062
|
-
:class="{ 'mg-disabled': !rowDraggable }"
|
|
1063
|
-
:draggable="rowDraggable"
|
|
1064
|
-
title="행 이동"
|
|
1065
|
-
@dragstart="onRowDragStart(entryIndexOf(entry, rowIdx), $event)"
|
|
1066
|
-
@dragend="onRowDragEnd"
|
|
1067
|
-
>⠿</span
|
|
1068
|
-
>
|
|
1069
|
-
<template v-if="isEditingCell(entryIndexOf(entry, rowIdx), col)">
|
|
1070
|
-
<!-- 커스텀 에디터 슬롯: #editor-{field}="ctx" -->
|
|
1071
|
-
<slot
|
|
1072
|
-
:name="`editor-${col.field}`"
|
|
1073
|
-
v-bind="editorContext(entryIndexOf(entry, rowIdx), colIndex)"
|
|
1074
|
-
>
|
|
1075
|
-
<select
|
|
1076
|
-
v-if="col.cellEditor === 'select'"
|
|
1077
|
-
class="mg-editor"
|
|
1078
|
-
:class="{ 'mg-editor-error': state.editError }"
|
|
1079
|
-
:value="String(state.editValue || '')"
|
|
1080
|
-
@change="onEditorInput"
|
|
1081
|
-
@keydown="onEditorKeydown"
|
|
1082
|
-
@click.stop
|
|
1083
|
-
@mousedown.stop
|
|
1084
|
-
>
|
|
1085
|
-
<option v-for="opt in col.editorOptions || []" :key="opt" :value="opt">
|
|
1086
|
-
{{ opt }}
|
|
1087
|
-
</option>
|
|
1088
|
-
</select>
|
|
1089
|
-
<input
|
|
1090
|
-
v-else
|
|
1091
|
-
:type="editorInputType(col)"
|
|
1092
|
-
class="mg-editor"
|
|
1093
|
-
:class="{ 'mg-editor-error': state.editError }"
|
|
1094
|
-
:value="String(state.editValue || '')"
|
|
1095
|
-
@input="onEditorInput"
|
|
1096
|
-
@keydown="onEditorKeydown"
|
|
1097
|
-
@click.stop
|
|
1098
|
-
@mousedown.stop
|
|
1099
|
-
/>
|
|
1100
|
-
</slot>
|
|
1101
|
-
<span v-if="state.editError" class="mg-edit-error">{{ state.editError }}</span>
|
|
1102
|
-
</template>
|
|
1103
|
-
<!-- 커스텀 셀 슬롯: #cell-{field}="{ value, row, column }" -->
|
|
1104
|
-
<slot
|
|
1105
|
-
v-else
|
|
1106
|
-
:name="`cell-${col.field}`"
|
|
1107
|
-
:value="grid.getCellValue(rowDataOf(entry), col)"
|
|
1108
|
-
:row="rowDataOf(entry)"
|
|
1109
|
-
:column="col"
|
|
1110
|
-
>
|
|
1111
|
-
{{ grid.getCellText(rowDataOf(entry), col) }}
|
|
1112
|
-
</slot>
|
|
1113
|
-
</td>
|
|
1114
|
-
</tr>
|
|
1115
|
-
</template>
|
|
1116
|
-
<tr
|
|
1117
|
-
v-if="virtual && bottomOffset > 0"
|
|
1118
|
-
class="mg-spacer"
|
|
1119
|
-
aria-hidden="true"
|
|
1120
|
-
>
|
|
1121
|
-
<td :colspan="colSpan" :style="{ height: `${bottomOffset}px`, padding: 0 }" />
|
|
1122
|
-
</tr>
|
|
1123
|
-
<tr
|
|
1124
|
-
v-for="(prow, pIdx) in state.pinnedBottomRows"
|
|
1125
|
-
:key="`pin-bottom-${pIdx}`"
|
|
1126
|
-
class="mg-pinned-bottom-row"
|
|
1127
|
-
>
|
|
1128
|
-
<td v-if="rowStatus" class="mg-status-cell" />
|
|
1129
|
-
<td v-if="rowCheckboxes" class="mg-check-cell" />
|
|
1130
|
-
<td
|
|
1131
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
1132
|
-
:key="col.field"
|
|
1133
|
-
:class="{
|
|
1134
|
-
'mg-pinned': !!col.pinned,
|
|
1135
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
1136
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
1137
|
-
}"
|
|
1138
|
-
:style="pinStyleOf(col)"
|
|
1139
|
-
>
|
|
1140
|
-
{{ grid.getCellText(prow, col) }}
|
|
1141
|
-
</td>
|
|
1142
|
-
</tr>
|
|
1143
|
-
</tbody>
|
|
1144
|
-
<tfoot v-if="state.grandTotals">
|
|
1145
|
-
<tr class="mg-total-row">
|
|
1146
|
-
<td v-if="rowStatus" class="mg-status-cell" />
|
|
1147
|
-
<td v-if="rowCheckboxes" class="mg-check-cell" />
|
|
1148
|
-
<td
|
|
1149
|
-
v-for="(col, colIndex) in state.visibleColumns"
|
|
1150
|
-
:key="col.field"
|
|
1151
|
-
:class="{
|
|
1152
|
-
'mg-pinned': !!col.pinned,
|
|
1153
|
-
'mg-pin-left-edge': colIndex === lastLeftPinIdx,
|
|
1154
|
-
'mg-pin-right-edge': colIndex === firstRightPinIdx,
|
|
1155
|
-
}"
|
|
1156
|
-
:style="pinStyleOf(col)"
|
|
1157
|
-
>
|
|
1158
|
-
<span
|
|
1159
|
-
v-if="col.aggregationFn && state.grandTotals[col.field] != null"
|
|
1160
|
-
class="mg-agg"
|
|
1161
|
-
>
|
|
1162
|
-
{{ formatAggregate(state.grandTotals[col.field]) }}
|
|
1163
|
-
</span>
|
|
1164
|
-
<template v-else-if="colIndex === 0">합계</template>
|
|
1165
|
-
</td>
|
|
1166
|
-
</tr>
|
|
1167
|
-
</tfoot>
|
|
1168
|
-
</table>
|
|
1169
|
-
<div v-if="state.serverSide?.loading" class="mg-loading">Loading…</div>
|
|
1170
|
-
</div>
|
|
1171
|
-
<div
|
|
1172
|
-
v-if="statusBar && state.selectionAggregates"
|
|
1173
|
-
class="mg-statusbar"
|
|
1174
|
-
>
|
|
1175
|
-
<span>
|
|
1176
|
-
<span class="mg-status-value">
|
|
1177
|
-
{{ state.selectionAggregates.cells }}
|
|
1178
|
-
</span>
|
|
1179
|
-
셀 선택
|
|
1180
|
-
</span>
|
|
1181
|
-
<template v-if="state.selectionAggregates.count > 0">
|
|
1182
|
-
<span>
|
|
1183
|
-
개수
|
|
1184
|
-
<span class="mg-status-value">
|
|
1185
|
-
{{ state.selectionAggregates.count }}
|
|
1186
|
-
</span>
|
|
1187
|
-
</span>
|
|
1188
|
-
<span>
|
|
1189
|
-
합계
|
|
1190
|
-
<span class="mg-status-value">
|
|
1191
|
-
{{ formatAggregate(state.selectionAggregates.sum) }}
|
|
1192
|
-
</span>
|
|
1193
|
-
</span>
|
|
1194
|
-
<span>
|
|
1195
|
-
평균
|
|
1196
|
-
<span class="mg-status-value">
|
|
1197
|
-
{{ formatAggregate(state.selectionAggregates.avg) }}
|
|
1198
|
-
</span>
|
|
1199
|
-
</span>
|
|
1200
|
-
<span>
|
|
1201
|
-
최소
|
|
1202
|
-
<span class="mg-status-value">
|
|
1203
|
-
{{ formatAggregate(state.selectionAggregates.min) }}
|
|
1204
|
-
</span>
|
|
1205
|
-
</span>
|
|
1206
|
-
<span>
|
|
1207
|
-
최대
|
|
1208
|
-
<span class="mg-status-value">
|
|
1209
|
-
{{ formatAggregate(state.selectionAggregates.max) }}
|
|
1210
|
-
</span>
|
|
1211
|
-
</span>
|
|
1212
|
-
</template>
|
|
1213
|
-
</div>
|
|
1214
|
-
</div>
|
|
1215
|
-
</template>
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export { useGrid, useGridState } from "./useGrid.js";
|
|
2
|
-
export type { UseGridReturn } from "./useGrid.js";
|
|
3
|
-
export { default as DataGrid } from "./DataGrid.vue";
|
|
4
|
-
export type {
|
|
5
|
-
Grid,
|
|
6
|
-
GridSnapshot,
|
|
7
|
-
ColumnDef,
|
|
8
|
-
GridOptions,
|
|
9
|
-
RowData,
|
|
10
|
-
SortState,
|
|
11
|
-
VirtualScrollState,
|
|
12
|
-
} from "@moda-grid/core";
|
|
13
|
-
|
|
14
|
-
// 서버 사이드 데이터 모델 (무한 스크롤/스켈레톤)
|
|
15
|
-
export { matchFilterValue } from "@moda-grid/core";
|
|
16
|
-
export type {
|
|
17
|
-
ServerSideDataSource,
|
|
18
|
-
ServerSideGetRowsParams,
|
|
19
|
-
ServerSideGetRowsResult,
|
|
20
|
-
ServerSideOptions,
|
|
21
|
-
ServerSideState,
|
|
22
|
-
TreeDataOptions,
|
|
23
|
-
CellClassParams,
|
|
24
|
-
ClassSource,
|
|
25
|
-
RowClassParams,
|
|
26
|
-
} from "@moda-grid/core";
|
package/src/shim-vue.d.ts
DELETED
package/src/styles.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import "@moda-grid/core/styles.css";
|
package/src/useGrid.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { getCurrentScope, onScopeDispose, shallowRef } from "vue";
|
|
2
|
-
import type { ShallowRef } from "vue";
|
|
3
|
-
import { createGrid } from "@moda-grid/core";
|
|
4
|
-
import type { Grid, GridOptions, GridSnapshot, RowData, Unsubscribe } from "@moda-grid/core";
|
|
5
|
-
|
|
6
|
-
export interface UseGridReturn<TData extends object> {
|
|
7
|
-
grid: Grid<TData>;
|
|
8
|
-
/** 현재 그리드 스냅샷 — 읽기 전용으로 취급할 것 */
|
|
9
|
-
state: ShallowRef<GridSnapshot<TData>>;
|
|
10
|
-
/** 수동 구독 해제 (컴포넌트 스코프 외에서 사용 시) */
|
|
11
|
-
unsubscribe: Unsubscribe;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** 외부에서 생성한 GridCore 인스턴스의 스냅샷만 구독한다. */
|
|
15
|
-
export function useGridState<TData extends object>(
|
|
16
|
-
grid: Grid<TData>,
|
|
17
|
-
): Pick<UseGridReturn<TData>, "state" | "unsubscribe"> {
|
|
18
|
-
const state = shallowRef<GridSnapshot<TData>>(grid.getSnapshot());
|
|
19
|
-
const unsubscribe = grid.subscribe(() => {
|
|
20
|
-
state.value = grid.getSnapshot();
|
|
21
|
-
});
|
|
22
|
-
if (getCurrentScope()) onScopeDispose(unsubscribe);
|
|
23
|
-
return { state, unsubscribe };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Grid 인스턴스를 생성하고 반응형 스냅샷을 반환한다.
|
|
28
|
-
* Vue 2.7의 내장 Composition API 기반이며, 컴포넌트 스코프 안에서
|
|
29
|
-
* 호출하면 스코프 종료 시 자동으로 구독 해제된다.
|
|
30
|
-
*/
|
|
31
|
-
export function useGrid<TData extends object = RowData>(
|
|
32
|
-
options: GridOptions<TData>,
|
|
33
|
-
): UseGridReturn<TData> {
|
|
34
|
-
const grid = createGrid<TData>(options);
|
|
35
|
-
const { state, unsubscribe } = useGridState(grid);
|
|
36
|
-
|
|
37
|
-
return { grid, state, unsubscribe };
|
|
38
|
-
}
|