@iyulab/data-components 0.3.0 → 0.3.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.
- package/CHANGELOG.md +40 -2
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/data-grid/UDataGrid.js +144 -172
- package/dist/components/data-view/UDataView.d.ts +44 -3
- package/dist/components/data-view/UDataView.js +172 -4
- package/dist/components/data-view/UDataView.styles.js +4 -83
- package/dist/components/simple-sheet/USimpleSheet.d.ts +167 -3
- package/dist/components/simple-sheet/USimpleSheet.js +934 -4
- package/dist/components/simple-sheet/USimpleSheet.styles.js +4 -4
- package/dist/components/u-rich-table/URichTable.d.ts +70 -3
- package/dist/components/u-rich-table/URichTable.js +617 -4
- package/dist/components/u-rich-table/styles.js +4 -4
- package/dist/components/u-rich-table/utils/clipboard.js +26 -29
- package/dist/index.js +5 -7
- package/package.json +19 -37
- package/dist/components/data-view/UDataView.component.d.ts +0 -47
- package/dist/components/data-view/UDataView.component.js +0 -226
- package/dist/components/simple-sheet/USimpleSheet.component.d.ts +0 -167
- package/dist/components/simple-sheet/USimpleSheet.component.js +0 -1034
- package/dist/components/u-rich-table/URichTable.component.d.ts +0 -70
- package/dist/components/u-rich-table/URichTable.component.js +0 -672
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import { LitElement, html } from 'lit';
|
|
2
|
-
import { property, state } from 'lit/decorators.js';
|
|
3
|
-
import { richTableStyles } from './styles.js';
|
|
4
|
-
import { toTSV, parseTSV } from './utils/clipboard.js';
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
8
|
-
var result = void 0 ;
|
|
9
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
10
|
-
if (decorator = decorators[i])
|
|
11
|
-
result = (decorator(target, key, result) ) || result;
|
|
12
|
-
if (result) __defProp(target, key, result);
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
class URichTable extends LitElement {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.columns = [];
|
|
19
|
-
this.data = [];
|
|
20
|
-
this.totalCount = 0;
|
|
21
|
-
this.pageSize = 25;
|
|
22
|
-
this.currentPage = 1;
|
|
23
|
-
this.loading = false;
|
|
24
|
-
this.emptyMessage = "데이터가 없습니다";
|
|
25
|
-
this.selectable = false;
|
|
26
|
-
this.editable = false;
|
|
27
|
-
this.addable = false;
|
|
28
|
-
this.filterable = false;
|
|
29
|
-
this.expandable = false;
|
|
30
|
-
this.selectedIds = /* @__PURE__ */ new Set();
|
|
31
|
-
this.focusedCell = null;
|
|
32
|
-
this.editingCell = null;
|
|
33
|
-
this.editValue = "";
|
|
34
|
-
this.expandedIds = /* @__PURE__ */ new Set();
|
|
35
|
-
this.sort = null;
|
|
36
|
-
this.filters = {};
|
|
37
|
-
this.validationErrors = /* @__PURE__ */ new Map();
|
|
38
|
-
this.rowErrors = /* @__PURE__ */ new Map();
|
|
39
|
-
this._lastSelectedIndex = -1;
|
|
40
|
-
// --- Clipboard & Keyboard ---
|
|
41
|
-
this._onGlobalKeyDown = (e) => {
|
|
42
|
-
if (e.ctrlKey || e.metaKey) {
|
|
43
|
-
if (e.key === "c") this._handleCopy();
|
|
44
|
-
else if (e.key === "v") this._handlePaste();
|
|
45
|
-
else if (e.key === "a" && !this.editingCell) {
|
|
46
|
-
e.preventDefault();
|
|
47
|
-
this._selectAll();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!this.editingCell && this.focusedCell) {
|
|
51
|
-
if (e.key === "ArrowUp") {
|
|
52
|
-
e.preventDefault();
|
|
53
|
-
this._moveFocus(0, -1);
|
|
54
|
-
}
|
|
55
|
-
if (e.key === "ArrowDown") {
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
this._moveFocus(0, 1);
|
|
58
|
-
}
|
|
59
|
-
if (e.key === "ArrowLeft") {
|
|
60
|
-
e.preventDefault();
|
|
61
|
-
this._moveFocus(-1, 0);
|
|
62
|
-
}
|
|
63
|
-
if (e.key === "ArrowRight") {
|
|
64
|
-
e.preventDefault();
|
|
65
|
-
this._moveFocus(1, 0);
|
|
66
|
-
}
|
|
67
|
-
if (e.key === "Enter") {
|
|
68
|
-
const col = this.columns[this.focusedCell.colIndex];
|
|
69
|
-
if (col?.editable) {
|
|
70
|
-
const value = this.data[this.focusedCell.rowIndex]?.[col.key];
|
|
71
|
-
this._onCellDblClick(this.focusedCell.rowIndex, this.focusedCell.colIndex, value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (e.key === " " && this.selectable) {
|
|
75
|
-
e.preventDefault();
|
|
76
|
-
const rowId = this.data[this.focusedCell.rowIndex]?._id;
|
|
77
|
-
if (rowId) this._onRowSelect(rowId);
|
|
78
|
-
}
|
|
79
|
-
if (e.key === "Delete" && this.selectedIds.size > 0) {
|
|
80
|
-
for (const row of this.getSelectedRows()) {
|
|
81
|
-
this.dispatchEvent(new CustomEvent("row-delete", { detail: { row }, bubbles: true, composed: true }));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
static {
|
|
88
|
-
this.styles = richTableStyles;
|
|
89
|
-
}
|
|
90
|
-
// --- Public API ---
|
|
91
|
-
revertRow(_rowId) {
|
|
92
|
-
}
|
|
93
|
-
setRowError(rowId, message) {
|
|
94
|
-
this.rowErrors = new Map(this.rowErrors).set(rowId, message);
|
|
95
|
-
}
|
|
96
|
-
clearRowError(rowId) {
|
|
97
|
-
const next = new Map(this.rowErrors);
|
|
98
|
-
next.delete(rowId);
|
|
99
|
-
this.rowErrors = next;
|
|
100
|
-
}
|
|
101
|
-
getSelectedRows() {
|
|
102
|
-
return this.data.filter((row) => this.selectedIds.has(row._id));
|
|
103
|
-
}
|
|
104
|
-
// --- Rendering ---
|
|
105
|
-
render() {
|
|
106
|
-
return html`
|
|
107
|
-
${this._renderToolbar()}
|
|
108
|
-
<table>
|
|
109
|
-
${this._renderHeader()}
|
|
110
|
-
<tbody>
|
|
111
|
-
${this.filterable ? this._renderFilterRow() : ""}
|
|
112
|
-
${this._renderBody()}
|
|
113
|
-
${this.addable ? this._renderNewRow() : ""}
|
|
114
|
-
</tbody>
|
|
115
|
-
</table>
|
|
116
|
-
${this._renderPagination()}
|
|
117
|
-
`;
|
|
118
|
-
}
|
|
119
|
-
_renderToolbar() {
|
|
120
|
-
const selectedCount = this.selectedIds.size;
|
|
121
|
-
return html`
|
|
122
|
-
<div class="toolbar">
|
|
123
|
-
${this.selectable ? html`
|
|
124
|
-
<div class="selection-info">
|
|
125
|
-
<input type="checkbox"
|
|
126
|
-
.checked=${selectedCount > 0 && selectedCount === this.data.length}
|
|
127
|
-
.indeterminate=${selectedCount > 0 && selectedCount < this.data.length}
|
|
128
|
-
@change=${this._onSelectAll} />
|
|
129
|
-
${selectedCount > 0 ? html`<span>${selectedCount}건 선택됨</span>` : ""}
|
|
130
|
-
</div>
|
|
131
|
-
${selectedCount > 0 ? html`<slot name="bulk-actions"></slot>` : ""}
|
|
132
|
-
` : ""}
|
|
133
|
-
<div style="flex:1"></div>
|
|
134
|
-
<slot name="toolbar-end"></slot>
|
|
135
|
-
${this.addable ? html`
|
|
136
|
-
<button class="btn btn-success" @click=${this._onAddRowClick}>+ 새 행</button>
|
|
137
|
-
` : ""}
|
|
138
|
-
</div>
|
|
139
|
-
`;
|
|
140
|
-
}
|
|
141
|
-
_renderHeader() {
|
|
142
|
-
return html`
|
|
143
|
-
<thead>
|
|
144
|
-
<tr>
|
|
145
|
-
${this.selectable ? html`<th class="checkbox-cell"></th>` : ""}
|
|
146
|
-
${this.expandable ? html`<th class="expand-cell"></th>` : ""}
|
|
147
|
-
${this.columns.map((col) => html`
|
|
148
|
-
<th
|
|
149
|
-
class=${col.sortable ? "sortable" : ""}
|
|
150
|
-
style=${col.width ? `width: ${col.width}` : ""}
|
|
151
|
-
@click=${() => col.sortable && this._onSortClick(col.key)}>
|
|
152
|
-
${col.label}
|
|
153
|
-
${this.sort?.field === col.key ? html`
|
|
154
|
-
<span class="sort-indicator">${this.sort.direction === "asc" ? "▲" : "▼"}</span>
|
|
155
|
-
` : ""}
|
|
156
|
-
</th>
|
|
157
|
-
`)}
|
|
158
|
-
<th class="actions-cell"></th>
|
|
159
|
-
</tr>
|
|
160
|
-
</thead>
|
|
161
|
-
`;
|
|
162
|
-
}
|
|
163
|
-
_renderFilterRow() {
|
|
164
|
-
return html`
|
|
165
|
-
<tr class="filter-row">
|
|
166
|
-
${this.selectable ? html`<td></td>` : ""}
|
|
167
|
-
${this.expandable ? html`<td></td>` : ""}
|
|
168
|
-
${this.columns.map((col) => html`
|
|
169
|
-
<td>
|
|
170
|
-
${col.filterable !== false ? col.filterType === "select" && col.options ? html`<select @change=${(e) => this._onFilterChange(col.key, e.target.value)}>
|
|
171
|
-
<option value="">전체</option>
|
|
172
|
-
${col.options.map((o) => html`<option value=${o.value}>${o.label}</option>`)}
|
|
173
|
-
</select>` : html`<input
|
|
174
|
-
placeholder="필터..."
|
|
175
|
-
@input=${(e) => this._onFilterChange(col.key, e.target.value)} />` : ""}
|
|
176
|
-
</td>
|
|
177
|
-
`)}
|
|
178
|
-
<td></td>
|
|
179
|
-
</tr>
|
|
180
|
-
`;
|
|
181
|
-
}
|
|
182
|
-
_renderBody() {
|
|
183
|
-
if (this.loading) {
|
|
184
|
-
return html`<tr><td colspan=${this._colSpan()}><div class="loading-overlay">로딩 중...</div></td></tr>`;
|
|
185
|
-
}
|
|
186
|
-
if (this.data.length === 0) {
|
|
187
|
-
return html`<tr><td colspan=${this._colSpan()}><div class="empty-message">${this.emptyMessage}</div></td></tr>`;
|
|
188
|
-
}
|
|
189
|
-
return this.data.map((row, rowIdx) => {
|
|
190
|
-
const rowId = row._id;
|
|
191
|
-
const isSelected = this.selectedIds.has(rowId);
|
|
192
|
-
const isExpanded = this.expandedIds.has(rowId);
|
|
193
|
-
const hasError = this.rowErrors.has(rowId);
|
|
194
|
-
return html`
|
|
195
|
-
<tr class="${isSelected ? "selected" : ""} ${hasError ? "error" : ""} ${this.editingCell?.rowIndex === rowIdx ? "editing" : ""}">
|
|
196
|
-
${this.selectable ? html`
|
|
197
|
-
<td class="checkbox-cell">
|
|
198
|
-
<input type="checkbox" .checked=${isSelected}
|
|
199
|
-
@change=${() => this._onRowSelect(rowId)}
|
|
200
|
-
@click=${(e) => e.shiftKey && this._onShiftSelect(rowIdx)} />
|
|
201
|
-
</td>
|
|
202
|
-
` : ""}
|
|
203
|
-
${this.expandable ? html`
|
|
204
|
-
<td class="expand-cell" @click=${() => this._onExpandToggle(rowId)}>
|
|
205
|
-
${isExpanded ? "▼" : "▶"}
|
|
206
|
-
</td>
|
|
207
|
-
` : ""}
|
|
208
|
-
${this.columns.map((col, colIdx) => this._renderCell(row, rowIdx, col, colIdx))}
|
|
209
|
-
<td class="actions-cell">
|
|
210
|
-
<span style="cursor:pointer;color:#94a3b8" @click=${() => this._onRowMenu(row)}>⋯</span>
|
|
211
|
-
</td>
|
|
212
|
-
</tr>
|
|
213
|
-
${isExpanded && this.detailRenderer ? html`
|
|
214
|
-
<tr class="detail-row">
|
|
215
|
-
<td colspan=${this._colSpan()}>${this.detailRenderer(row)}</td>
|
|
216
|
-
</tr>
|
|
217
|
-
` : ""}
|
|
218
|
-
${hasError ? html`
|
|
219
|
-
<tr><td colspan=${this._colSpan()} style="padding:2px 8px;background:#fef2f2;color:#ef4444;font-size:11px;">
|
|
220
|
-
${this.rowErrors.get(rowId)}
|
|
221
|
-
</td></tr>
|
|
222
|
-
` : ""}
|
|
223
|
-
`;
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
_renderCell(row, rowIdx, col, colIdx) {
|
|
227
|
-
const isEditing = this.editingCell?.rowIndex === rowIdx && this.editingCell?.colIndex === colIdx;
|
|
228
|
-
const isFocused = this.focusedCell?.rowIndex === rowIdx && this.focusedCell?.colIndex === colIdx;
|
|
229
|
-
const value = row[col.key];
|
|
230
|
-
if (isEditing && col.editable) {
|
|
231
|
-
const validationError = this.validationErrors.get(`${rowIdx}-${colIdx}`);
|
|
232
|
-
if (col.type === "select" && col.options) {
|
|
233
|
-
return html`
|
|
234
|
-
<td>
|
|
235
|
-
<select class="cell-edit-input" @change=${this._onCellEditConfirm} @keydown=${this._onEditKeyDown}>
|
|
236
|
-
${col.options.map((o) => html`<option value=${o.value} ?selected=${o.value === String(value)}>${o.label}</option>`)}
|
|
237
|
-
</select>
|
|
238
|
-
</td>
|
|
239
|
-
`;
|
|
240
|
-
}
|
|
241
|
-
return html`
|
|
242
|
-
<td>
|
|
243
|
-
<input class="cell-edit-input ${validationError ? "invalid" : ""}"
|
|
244
|
-
type=${col.type === "number" ? "number" : col.type === "date" ? "date" : "text"}
|
|
245
|
-
.value=${this.editValue}
|
|
246
|
-
@input=${(e) => this.editValue = e.target.value}
|
|
247
|
-
@keydown=${this._onEditKeyDown}
|
|
248
|
-
@blur=${this._onCellEditConfirm} />
|
|
249
|
-
${validationError ? html`<div class="validation-error">${validationError}</div>` : ""}
|
|
250
|
-
</td>
|
|
251
|
-
`;
|
|
252
|
-
}
|
|
253
|
-
return html`
|
|
254
|
-
<td class=${isFocused ? "focused-cell" : ""}
|
|
255
|
-
style=${col.align ? `text-align: ${col.align}` : ""}
|
|
256
|
-
@click=${() => this._onCellClick(rowIdx, colIdx)}
|
|
257
|
-
@dblclick=${() => col.editable && this._onCellDblClick(rowIdx, colIdx, value)}>
|
|
258
|
-
${this._renderCellContent(col, value, row)}
|
|
259
|
-
</td>
|
|
260
|
-
`;
|
|
261
|
-
}
|
|
262
|
-
_renderCellContent(col, value, row) {
|
|
263
|
-
if (col.render) {
|
|
264
|
-
const result = col.render(value, row);
|
|
265
|
-
if (typeof result === "string") return result;
|
|
266
|
-
if (result instanceof HTMLElement) {
|
|
267
|
-
const container = document.createElement("span");
|
|
268
|
-
container.appendChild(result);
|
|
269
|
-
return html`${container}`;
|
|
270
|
-
}
|
|
271
|
-
return String(value ?? "");
|
|
272
|
-
}
|
|
273
|
-
if (col.type === "badge" && col.badgeColors) {
|
|
274
|
-
const color = col.badgeColors[String(value)] ?? "#f3f4f6";
|
|
275
|
-
return html`<span class="badge" style="background:${color}">${this._getOptionLabel(col, value)}</span>`;
|
|
276
|
-
}
|
|
277
|
-
if (col.type === "select" && col.options) {
|
|
278
|
-
return this._getOptionLabel(col, value);
|
|
279
|
-
}
|
|
280
|
-
if (col.type === "number" && value != null) {
|
|
281
|
-
return Number(value).toLocaleString();
|
|
282
|
-
}
|
|
283
|
-
return String(value ?? "");
|
|
284
|
-
}
|
|
285
|
-
_renderNewRow() {
|
|
286
|
-
return html`
|
|
287
|
-
<tr class="new-row">
|
|
288
|
-
${this.selectable ? html`<td class="checkbox-cell"><span style="color:#86efac">+</span></td>` : ""}
|
|
289
|
-
${this.expandable ? html`<td></td>` : ""}
|
|
290
|
-
${this.columns.map((col, colIdx) => html`
|
|
291
|
-
<td>
|
|
292
|
-
${col.editable !== false ? html`
|
|
293
|
-
<input placeholder=${col.label}
|
|
294
|
-
data-new-col=${colIdx}
|
|
295
|
-
@keydown=${this._onNewRowKeyDown}
|
|
296
|
-
@focus=${this._onNewRowFocus} />
|
|
297
|
-
` : html`<span></span>`}
|
|
298
|
-
</td>
|
|
299
|
-
`)}
|
|
300
|
-
<td></td>
|
|
301
|
-
</tr>
|
|
302
|
-
`;
|
|
303
|
-
}
|
|
304
|
-
_renderPagination() {
|
|
305
|
-
if (this.totalCount <= 0) return html``;
|
|
306
|
-
const totalPages = Math.ceil(this.totalCount / this.pageSize);
|
|
307
|
-
const start = (this.currentPage - 1) * this.pageSize + 1;
|
|
308
|
-
const end = Math.min(this.currentPage * this.pageSize, this.totalCount);
|
|
309
|
-
return html`
|
|
310
|
-
<div class="pagination">
|
|
311
|
-
<span>전체 ${this.totalCount.toLocaleString()}건 중 ${start}-${end} 표시</span>
|
|
312
|
-
<div class="page-buttons">
|
|
313
|
-
<button ?disabled=${this.currentPage <= 1} @click=${() => this._onPageChange(this.currentPage - 1)}>◀</button>
|
|
314
|
-
${this._getPageNumbers(totalPages).map((p) => html`
|
|
315
|
-
<button class=${p === this.currentPage ? "active" : ""} @click=${() => this._onPageChange(p)}>${p}</button>
|
|
316
|
-
`)}
|
|
317
|
-
<button ?disabled=${this.currentPage >= totalPages} @click=${() => this._onPageChange(this.currentPage + 1)}>▶</button>
|
|
318
|
-
<select @change=${(e) => this._onPageSizeChange(Number(e.target.value))}>
|
|
319
|
-
${[25, 50, 100].map((s) => html`<option value=${s} ?selected=${s === this.pageSize}>${s}행</option>`)}
|
|
320
|
-
</select>
|
|
321
|
-
</div>
|
|
322
|
-
</div>
|
|
323
|
-
`;
|
|
324
|
-
}
|
|
325
|
-
// --- Event Handlers ---
|
|
326
|
-
_onSelectAll(e) {
|
|
327
|
-
const checked = e.target.checked;
|
|
328
|
-
if (checked) {
|
|
329
|
-
this.selectedIds = new Set(this.data.map((r) => r._id));
|
|
330
|
-
} else {
|
|
331
|
-
this.selectedIds = /* @__PURE__ */ new Set();
|
|
332
|
-
}
|
|
333
|
-
this._fireSelectionChange();
|
|
334
|
-
}
|
|
335
|
-
_onRowSelect(rowId) {
|
|
336
|
-
const next = new Set(this.selectedIds);
|
|
337
|
-
if (next.has(rowId)) next.delete(rowId);
|
|
338
|
-
else next.add(rowId);
|
|
339
|
-
this.selectedIds = next;
|
|
340
|
-
this._fireSelectionChange();
|
|
341
|
-
}
|
|
342
|
-
_onShiftSelect(rowIdx) {
|
|
343
|
-
if (this._lastSelectedIndex < 0) return;
|
|
344
|
-
const start = Math.min(this._lastSelectedIndex, rowIdx);
|
|
345
|
-
const end = Math.max(this._lastSelectedIndex, rowIdx);
|
|
346
|
-
const next = new Set(this.selectedIds);
|
|
347
|
-
for (let i = start; i <= end; i++) {
|
|
348
|
-
next.add(this.data[i]._id);
|
|
349
|
-
}
|
|
350
|
-
this.selectedIds = next;
|
|
351
|
-
this._fireSelectionChange();
|
|
352
|
-
}
|
|
353
|
-
_onSortClick(field) {
|
|
354
|
-
if (this.sort?.field === field) {
|
|
355
|
-
if (this.sort.direction === "asc") {
|
|
356
|
-
this.sort = { field, direction: "desc" };
|
|
357
|
-
} else {
|
|
358
|
-
this.sort = null;
|
|
359
|
-
}
|
|
360
|
-
} else {
|
|
361
|
-
this.sort = { field, direction: "asc" };
|
|
362
|
-
}
|
|
363
|
-
this.dispatchEvent(new CustomEvent("sort-change", {
|
|
364
|
-
detail: this.sort ? { field: this.sort.field, direction: this.sort.direction } : { field, direction: null },
|
|
365
|
-
bubbles: true,
|
|
366
|
-
composed: true
|
|
367
|
-
}));
|
|
368
|
-
}
|
|
369
|
-
_onFilterChange(field, value) {
|
|
370
|
-
if (value) {
|
|
371
|
-
this.filters = { ...this.filters, [field]: value };
|
|
372
|
-
} else {
|
|
373
|
-
const { [field]: _, ...rest } = this.filters;
|
|
374
|
-
this.filters = rest;
|
|
375
|
-
}
|
|
376
|
-
this.dispatchEvent(new CustomEvent("filter-change", {
|
|
377
|
-
detail: { filters: this.filters },
|
|
378
|
-
bubbles: true,
|
|
379
|
-
composed: true
|
|
380
|
-
}));
|
|
381
|
-
}
|
|
382
|
-
_onCellClick(rowIdx, colIdx) {
|
|
383
|
-
this.focusedCell = { rowIndex: rowIdx, colIndex: colIdx };
|
|
384
|
-
this._lastSelectedIndex = rowIdx;
|
|
385
|
-
}
|
|
386
|
-
_onCellDblClick(rowIdx, colIdx, value) {
|
|
387
|
-
this.editingCell = { rowIndex: rowIdx, colIndex: colIdx };
|
|
388
|
-
this.editValue = String(value ?? "");
|
|
389
|
-
this.requestUpdate();
|
|
390
|
-
requestAnimationFrame(() => {
|
|
391
|
-
const input = this.shadowRoot?.querySelector(".cell-edit-input");
|
|
392
|
-
input?.focus();
|
|
393
|
-
input?.select();
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
_onEditKeyDown(e) {
|
|
397
|
-
if (e.key === "Enter") {
|
|
398
|
-
e.preventDefault();
|
|
399
|
-
this._onCellEditConfirm();
|
|
400
|
-
if (this.editingCell && this.editingCell.rowIndex < this.data.length - 1) {
|
|
401
|
-
const nextRow = this.editingCell.rowIndex + 1;
|
|
402
|
-
const col = this.editingCell.colIndex;
|
|
403
|
-
const nextValue = this.data[nextRow][this.columns[col].key];
|
|
404
|
-
this._onCellDblClick(nextRow, col, nextValue);
|
|
405
|
-
}
|
|
406
|
-
} else if (e.key === "Escape") {
|
|
407
|
-
this.editingCell = null;
|
|
408
|
-
this.editValue = "";
|
|
409
|
-
} else if (e.key === "Tab") {
|
|
410
|
-
e.preventDefault();
|
|
411
|
-
this._onCellEditConfirm();
|
|
412
|
-
this._moveToNextEditableCell(e.shiftKey);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
_onCellEditConfirm() {
|
|
416
|
-
if (!this.editingCell) return;
|
|
417
|
-
const { rowIndex, colIndex } = this.editingCell;
|
|
418
|
-
const col = this.columns[colIndex];
|
|
419
|
-
const row = this.data[rowIndex];
|
|
420
|
-
const oldValue = row[col.key];
|
|
421
|
-
let newValue = this.editValue;
|
|
422
|
-
if (col.type === "number") newValue = Number(newValue);
|
|
423
|
-
if (col.required && !newValue && newValue !== 0) {
|
|
424
|
-
this.validationErrors = new Map(this.validationErrors).set(`${rowIndex}-${colIndex}`, "필수 항목입니다");
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (col.validator) {
|
|
428
|
-
const error = col.validator(newValue, row);
|
|
429
|
-
if (error) {
|
|
430
|
-
this.validationErrors = new Map(this.validationErrors).set(`${rowIndex}-${colIndex}`, error);
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
const nextErrors = new Map(this.validationErrors);
|
|
435
|
-
nextErrors.delete(`${rowIndex}-${colIndex}`);
|
|
436
|
-
this.validationErrors = nextErrors;
|
|
437
|
-
if (newValue !== oldValue) {
|
|
438
|
-
this.dispatchEvent(new CustomEvent("row-update", {
|
|
439
|
-
detail: { row, field: col.key, value: newValue, oldValue },
|
|
440
|
-
bubbles: true,
|
|
441
|
-
composed: true
|
|
442
|
-
}));
|
|
443
|
-
}
|
|
444
|
-
this.editingCell = null;
|
|
445
|
-
this.editValue = "";
|
|
446
|
-
}
|
|
447
|
-
_onExpandToggle(rowId) {
|
|
448
|
-
const next = new Set(this.expandedIds);
|
|
449
|
-
const expanded = !next.has(rowId);
|
|
450
|
-
if (expanded) next.add(rowId);
|
|
451
|
-
else next.delete(rowId);
|
|
452
|
-
this.expandedIds = next;
|
|
453
|
-
this.dispatchEvent(new CustomEvent("row-expand", {
|
|
454
|
-
detail: { row: this.data.find((r) => r._id === rowId), expanded },
|
|
455
|
-
bubbles: true,
|
|
456
|
-
composed: true
|
|
457
|
-
}));
|
|
458
|
-
}
|
|
459
|
-
_onAddRowClick() {
|
|
460
|
-
const input = this.shadowRoot?.querySelector(".new-row input");
|
|
461
|
-
input?.focus();
|
|
462
|
-
}
|
|
463
|
-
_onNewRowFocus() {
|
|
464
|
-
}
|
|
465
|
-
_onNewRowKeyDown(e) {
|
|
466
|
-
if (e.key === "Enter") {
|
|
467
|
-
e.preventDefault();
|
|
468
|
-
const inputs = Array.from(this.shadowRoot?.querySelectorAll(".new-row input") ?? []);
|
|
469
|
-
const newRow = {};
|
|
470
|
-
this.columns.forEach((col, i) => {
|
|
471
|
-
if (col.editable !== false && inputs[i]) {
|
|
472
|
-
let val = inputs[i].value;
|
|
473
|
-
if (col.type === "number") val = Number(val);
|
|
474
|
-
newRow[col.key] = val;
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
this.dispatchEvent(new CustomEvent("row-create", {
|
|
478
|
-
detail: { row: newRow },
|
|
479
|
-
bubbles: true,
|
|
480
|
-
composed: true
|
|
481
|
-
}));
|
|
482
|
-
inputs.forEach((input) => input.value = "");
|
|
483
|
-
inputs[0]?.focus();
|
|
484
|
-
} else if (e.key === "Tab" && !e.shiftKey) {
|
|
485
|
-
const target = e.target;
|
|
486
|
-
const colIdx = Number(target.dataset.newCol);
|
|
487
|
-
if (colIdx >= this.columns.filter((c) => c.editable !== false).length - 1) {
|
|
488
|
-
e.preventDefault();
|
|
489
|
-
this._onNewRowKeyDown(new KeyboardEvent("keydown", { key: "Enter" }));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
_onRowMenu(row) {
|
|
494
|
-
this.dispatchEvent(new CustomEvent("row-delete", {
|
|
495
|
-
detail: { row },
|
|
496
|
-
bubbles: true,
|
|
497
|
-
composed: true
|
|
498
|
-
}));
|
|
499
|
-
}
|
|
500
|
-
_onPageChange(page) {
|
|
501
|
-
this.dispatchEvent(new CustomEvent("page-change", {
|
|
502
|
-
detail: { page, pageSize: this.pageSize },
|
|
503
|
-
bubbles: true,
|
|
504
|
-
composed: true
|
|
505
|
-
}));
|
|
506
|
-
}
|
|
507
|
-
_onPageSizeChange(pageSize) {
|
|
508
|
-
this.dispatchEvent(new CustomEvent("page-change", {
|
|
509
|
-
detail: { page: 1, pageSize },
|
|
510
|
-
bubbles: true,
|
|
511
|
-
composed: true
|
|
512
|
-
}));
|
|
513
|
-
}
|
|
514
|
-
// --- Helpers ---
|
|
515
|
-
_colSpan() {
|
|
516
|
-
let span = this.columns.length + 1;
|
|
517
|
-
if (this.selectable) span++;
|
|
518
|
-
if (this.expandable) span++;
|
|
519
|
-
return span;
|
|
520
|
-
}
|
|
521
|
-
_getOptionLabel(col, value) {
|
|
522
|
-
return col.options?.find((o) => o.value === String(value))?.label ?? String(value ?? "");
|
|
523
|
-
}
|
|
524
|
-
_getPageNumbers(totalPages) {
|
|
525
|
-
const pages = [];
|
|
526
|
-
const start = Math.max(1, this.currentPage - 2);
|
|
527
|
-
const end = Math.min(totalPages, start + 4);
|
|
528
|
-
for (let i = start; i <= end; i++) pages.push(i);
|
|
529
|
-
return pages;
|
|
530
|
-
}
|
|
531
|
-
_moveToNextEditableCell(reverse) {
|
|
532
|
-
if (!this.editingCell) return;
|
|
533
|
-
let { rowIndex, colIndex } = this.editingCell;
|
|
534
|
-
const editableCols = this.columns.map((c, i) => c.editable ? i : -1).filter((i) => i >= 0);
|
|
535
|
-
const currentIdx = editableCols.indexOf(colIndex);
|
|
536
|
-
if (reverse) {
|
|
537
|
-
if (currentIdx > 0) {
|
|
538
|
-
colIndex = editableCols[currentIdx - 1];
|
|
539
|
-
} else if (rowIndex > 0) {
|
|
540
|
-
rowIndex--;
|
|
541
|
-
colIndex = editableCols[editableCols.length - 1];
|
|
542
|
-
}
|
|
543
|
-
} else {
|
|
544
|
-
if (currentIdx < editableCols.length - 1) {
|
|
545
|
-
colIndex = editableCols[currentIdx + 1];
|
|
546
|
-
} else if (rowIndex < this.data.length - 1) {
|
|
547
|
-
rowIndex++;
|
|
548
|
-
colIndex = editableCols[0];
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
const value = this.data[rowIndex]?.[this.columns[colIndex]?.key];
|
|
552
|
-
this._onCellDblClick(rowIndex, colIndex, value);
|
|
553
|
-
}
|
|
554
|
-
_fireSelectionChange() {
|
|
555
|
-
this.dispatchEvent(new CustomEvent("selection-change", {
|
|
556
|
-
detail: { selectedRows: this.getSelectedRows() },
|
|
557
|
-
bubbles: true,
|
|
558
|
-
composed: true
|
|
559
|
-
}));
|
|
560
|
-
}
|
|
561
|
-
// --- Lifecycle ---
|
|
562
|
-
connectedCallback() {
|
|
563
|
-
super.connectedCallback();
|
|
564
|
-
this.addEventListener("keydown", this._onGlobalKeyDown);
|
|
565
|
-
}
|
|
566
|
-
disconnectedCallback() {
|
|
567
|
-
super.disconnectedCallback();
|
|
568
|
-
this.removeEventListener("keydown", this._onGlobalKeyDown);
|
|
569
|
-
}
|
|
570
|
-
async _handleCopy() {
|
|
571
|
-
const rows = this.getSelectedRows();
|
|
572
|
-
if (rows.length === 0) return;
|
|
573
|
-
const tsv = toTSV(rows, this.columns);
|
|
574
|
-
await navigator.clipboard.writeText(tsv);
|
|
575
|
-
}
|
|
576
|
-
async _handlePaste() {
|
|
577
|
-
if (this.editingCell) return;
|
|
578
|
-
const text = await navigator.clipboard.readText();
|
|
579
|
-
if (!text.trim()) return;
|
|
580
|
-
const parsedRows = parseTSV(text, this.columns);
|
|
581
|
-
if (parsedRows.length === 0) return;
|
|
582
|
-
this.dispatchEvent(new CustomEvent("paste", {
|
|
583
|
-
detail: { rows: parsedRows },
|
|
584
|
-
bubbles: true,
|
|
585
|
-
composed: true
|
|
586
|
-
}));
|
|
587
|
-
}
|
|
588
|
-
_moveFocus(dx, dy) {
|
|
589
|
-
if (!this.focusedCell) return;
|
|
590
|
-
const newCol = Math.max(0, Math.min(this.columns.length - 1, this.focusedCell.colIndex + dx));
|
|
591
|
-
const newRow = Math.max(0, Math.min(this.data.length - 1, this.focusedCell.rowIndex + dy));
|
|
592
|
-
this.focusedCell = { rowIndex: newRow, colIndex: newCol };
|
|
593
|
-
}
|
|
594
|
-
_selectAll() {
|
|
595
|
-
this.selectedIds = new Set(this.data.map((r) => r._id));
|
|
596
|
-
this._fireSelectionChange();
|
|
597
|
-
}
|
|
598
|
-
// define helper (follows existing pattern)
|
|
599
|
-
static define(tagName = "u-rich-table") {
|
|
600
|
-
if (!customElements.get(tagName)) {
|
|
601
|
-
customElements.define(tagName, this);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
__decorateClass([
|
|
606
|
-
property({ type: Array })
|
|
607
|
-
], URichTable.prototype, "columns");
|
|
608
|
-
__decorateClass([
|
|
609
|
-
property({ type: Array })
|
|
610
|
-
], URichTable.prototype, "data");
|
|
611
|
-
__decorateClass([
|
|
612
|
-
property({ type: Number })
|
|
613
|
-
], URichTable.prototype, "totalCount");
|
|
614
|
-
__decorateClass([
|
|
615
|
-
property({ type: Number })
|
|
616
|
-
], URichTable.prototype, "pageSize");
|
|
617
|
-
__decorateClass([
|
|
618
|
-
property({ type: Number })
|
|
619
|
-
], URichTable.prototype, "currentPage");
|
|
620
|
-
__decorateClass([
|
|
621
|
-
property({ type: Boolean })
|
|
622
|
-
], URichTable.prototype, "loading");
|
|
623
|
-
__decorateClass([
|
|
624
|
-
property({ type: String })
|
|
625
|
-
], URichTable.prototype, "emptyMessage");
|
|
626
|
-
__decorateClass([
|
|
627
|
-
property({ type: Boolean })
|
|
628
|
-
], URichTable.prototype, "selectable");
|
|
629
|
-
__decorateClass([
|
|
630
|
-
property({ type: Boolean })
|
|
631
|
-
], URichTable.prototype, "editable");
|
|
632
|
-
__decorateClass([
|
|
633
|
-
property({ type: Boolean })
|
|
634
|
-
], URichTable.prototype, "addable");
|
|
635
|
-
__decorateClass([
|
|
636
|
-
property({ type: Boolean })
|
|
637
|
-
], URichTable.prototype, "filterable");
|
|
638
|
-
__decorateClass([
|
|
639
|
-
property({ type: Boolean })
|
|
640
|
-
], URichTable.prototype, "expandable");
|
|
641
|
-
__decorateClass([
|
|
642
|
-
property({ attribute: false })
|
|
643
|
-
], URichTable.prototype, "detailRenderer");
|
|
644
|
-
__decorateClass([
|
|
645
|
-
state()
|
|
646
|
-
], URichTable.prototype, "selectedIds");
|
|
647
|
-
__decorateClass([
|
|
648
|
-
state()
|
|
649
|
-
], URichTable.prototype, "focusedCell");
|
|
650
|
-
__decorateClass([
|
|
651
|
-
state()
|
|
652
|
-
], URichTable.prototype, "editingCell");
|
|
653
|
-
__decorateClass([
|
|
654
|
-
state()
|
|
655
|
-
], URichTable.prototype, "editValue");
|
|
656
|
-
__decorateClass([
|
|
657
|
-
state()
|
|
658
|
-
], URichTable.prototype, "expandedIds");
|
|
659
|
-
__decorateClass([
|
|
660
|
-
state()
|
|
661
|
-
], URichTable.prototype, "sort");
|
|
662
|
-
__decorateClass([
|
|
663
|
-
state()
|
|
664
|
-
], URichTable.prototype, "filters");
|
|
665
|
-
__decorateClass([
|
|
666
|
-
state()
|
|
667
|
-
], URichTable.prototype, "validationErrors");
|
|
668
|
-
__decorateClass([
|
|
669
|
-
state()
|
|
670
|
-
], URichTable.prototype, "rowErrors");
|
|
671
|
-
|
|
672
|
-
export { URichTable };
|