@iyulab/data-components 0.1.7 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.8] - 2026-03-08
4
+ ### Added
5
+ - USimpleSheet: `format` 속성 — Intl.NumberFormatOptions(통화, 퍼센트 등) 또는 콜백 함수로 표시 포맷 지정
6
+ - USimpleSheet: 셀 값 기반 자동 텍스트 정렬 (숫자 우측, 문자 좌측)
7
+
3
8
  ## [0.1.7] - 2026-03-08
4
9
  ### Added
5
10
  - USimpleSheet: `compute` 콜백을 통한 열 단위 자동 계산 기능
@@ -15,6 +15,8 @@ export interface SheetColumn {
15
15
  strict?: boolean;
16
16
  /** 자동 계산 함수. 설정 시 해당 열은 자동 readonly. 열 순서(좌→우), 행 순서(위→아래)로 계산. */
17
17
  compute?: (rowIndex: number, data: string[][]) => string;
18
+ /** 표시 포맷. Intl.NumberFormatOptions(숫자) 또는 커스텀 콜백. 원본 데이터는 유지. */
19
+ format?: Intl.NumberFormatOptions | ((value: string, rowIndex: number) => string);
18
20
  }
19
21
  /**
20
22
  * USimpleSheet - 심플 스프레드시트 컴포넌트
@@ -123,6 +125,9 @@ export declare class USimpleSheet extends UElement {
123
125
  private _getCellFromEvent;
124
126
  private _isColReadonly;
125
127
  private _isColComputed;
128
+ private _isNumeric;
129
+ /** 열의 format 설정에 따라 표시값을 반환. format 미설정 시 원본 반환. */
130
+ private _formatValue;
126
131
  /** compute 열을 재계산 (열 순서 좌→우, 행 순서 위→아래) */
127
132
  private _recompute;
128
133
  private _getColOptions;
@@ -146,6 +151,15 @@ export declare class USimpleSheet extends UElement {
146
151
  minCol: number;
147
152
  maxCol: number;
148
153
  } | null;
154
+ /** 선택 영역을 프로그래밍 방식으로 설정 */
155
+ setSelection(range: {
156
+ minRow: number;
157
+ maxRow: number;
158
+ minCol: number;
159
+ maxCol: number;
160
+ }): void;
161
+ /** 전체 셀 선택 */
162
+ selectAll(): void;
149
163
  /** Undo 가능 여부 */
150
164
  get canUndo(): boolean;
151
165
  /** Redo 가능 여부 */
@@ -624,13 +624,16 @@ const _USimpleSheet = class _USimpleSheet extends UElement {
624
624
  const value = this._data[r]?.[c] ?? "";
625
625
  const isColReadonly = this._isColReadonly(c);
626
626
  const isComputed = this._isColComputed(c);
627
+ const hasIntlFormat = this.columns?.[c]?.format && typeof this.columns[c].format !== "function";
628
+ const isNumeric = hasIntlFormat || this._isNumeric(value);
627
629
  const classes = [
628
630
  "cell",
629
631
  isSelected ? "selected" : "",
630
632
  isAnchor ? "anchor" : "",
631
633
  isEditing ? "editing" : "",
632
634
  isColReadonly ? "cell-readonly" : "",
633
- isComputed ? "cell-computed" : ""
635
+ isComputed ? "cell-computed" : "",
636
+ isNumeric ? "cell-numeric" : ""
634
637
  ].filter(Boolean).join(" ");
635
638
  const hasOptions = isEditing && this._getColOptions(r, c) !== null;
636
639
  const showDropdown = isEditing && this._dropdownItems.length > 0;
@@ -664,7 +667,7 @@ const _USimpleSheet = class _USimpleSheet extends UElement {
664
667
  <div class="dropdown-empty">일치하는 항목 없음</div>
665
668
  </div>
666
669
  ` : ""}
667
- ` : value}
670
+ ` : this._formatValue(value, c, r)}
668
671
  </td>
669
672
  `;
670
673
  }
@@ -871,6 +874,25 @@ const _USimpleSheet = class _USimpleSheet extends UElement {
871
874
  _isColComputed(col) {
872
875
  return typeof this.columns?.[col]?.compute === "function";
873
876
  }
877
+ _isNumeric(value) {
878
+ if (!value || !value.trim()) return false;
879
+ return !isNaN(Number(value.replace(/,/g, "")));
880
+ }
881
+ /** 열의 format 설정에 따라 표시값을 반환. format 미설정 시 원본 반환. */
882
+ _formatValue(value, col, row) {
883
+ const fmt = this.columns?.[col]?.format;
884
+ if (!fmt || !value) return value;
885
+ try {
886
+ if (typeof fmt === "function") {
887
+ return fmt(value, row);
888
+ }
889
+ const num = Number(value.replace(/,/g, ""));
890
+ if (isNaN(num)) return value;
891
+ return new Intl.NumberFormat("ko-KR", fmt).format(num);
892
+ } catch {
893
+ return value;
894
+ }
895
+ }
874
896
  /** compute 열을 재계산 (열 순서 좌→우, 행 순서 위→아래) */
875
897
  _recompute() {
876
898
  if (!this.columns?.some((c) => c.compute)) return;
@@ -945,6 +967,26 @@ const _USimpleSheet = class _USimpleSheet extends UElement {
945
967
  if (!this._sel) return null;
946
968
  return normalizeRange(this._sel);
947
969
  }
970
+ /** 선택 영역을 프로그래밍 방식으로 설정 */
971
+ setSelection(range) {
972
+ const minRow = Math.max(0, Math.min(range.minRow, this._rowCount - 1));
973
+ const maxRow = Math.max(0, Math.min(range.maxRow, this._rowCount - 1));
974
+ const minCol = Math.max(0, Math.min(range.minCol, this._colCount - 1));
975
+ const maxCol = Math.max(0, Math.min(range.maxCol, this._colCount - 1));
976
+ this._sel = {
977
+ anchor: { row: minRow, col: minCol },
978
+ focus: { row: maxRow, col: maxCol }
979
+ };
980
+ this.requestUpdate();
981
+ }
982
+ /** 전체 셀 선택 */
983
+ selectAll() {
984
+ this._sel = {
985
+ anchor: { row: 0, col: 0 },
986
+ focus: { row: this._rowCount - 1, col: this._colCount - 1 }
987
+ };
988
+ this.requestUpdate();
989
+ }
948
990
  /** Undo 가능 여부 */
949
991
  get canUndo() {
950
992
  return this._historyIndex > 0;
@@ -240,6 +240,11 @@ const styles = css`
240
240
  font-style: italic;
241
241
  }
242
242
 
243
+ /* Numeric cell (right-aligned like Excel) */
244
+ .cell.cell-numeric {
245
+ text-align: right;
246
+ }
247
+
243
248
  /* Readonly column/cell */
244
249
  .cell.cell-readonly {
245
250
  background: var(--u-neutral-50, #f8fafc);
@@ -0,0 +1,70 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { ColumnDef } from './types.js';
3
+ export declare class URichTable extends LitElement {
4
+ static styles: import('lit').CSSResult;
5
+ columns: ColumnDef[];
6
+ data: Record<string, unknown>[];
7
+ totalCount: number;
8
+ pageSize: number;
9
+ currentPage: number;
10
+ loading: boolean;
11
+ emptyMessage: string;
12
+ selectable: boolean;
13
+ editable: boolean;
14
+ addable: boolean;
15
+ filterable: boolean;
16
+ expandable: boolean;
17
+ detailRenderer?: (row: Record<string, unknown>) => TemplateResult;
18
+ private selectedIds;
19
+ private focusedCell;
20
+ private editingCell;
21
+ private editValue;
22
+ private expandedIds;
23
+ private sort;
24
+ private filters;
25
+ private validationErrors;
26
+ private rowErrors;
27
+ revertRow(_rowId: string): void;
28
+ setRowError(rowId: string, message: string): void;
29
+ clearRowError(rowId: string): void;
30
+ getSelectedRows(): Record<string, unknown>[];
31
+ render(): TemplateResult;
32
+ private _renderToolbar;
33
+ private _renderHeader;
34
+ private _renderFilterRow;
35
+ private _renderBody;
36
+ private _renderCell;
37
+ private _renderCellContent;
38
+ private _renderNewRow;
39
+ private _renderPagination;
40
+ private _onSelectAll;
41
+ private _onRowSelect;
42
+ private _lastSelectedIndex;
43
+ private _onShiftSelect;
44
+ private _onSortClick;
45
+ private _onFilterChange;
46
+ private _onCellClick;
47
+ private _onCellDblClick;
48
+ private _onEditKeyDown;
49
+ private _onCellEditConfirm;
50
+ private _onExpandToggle;
51
+ private _onAddRowClick;
52
+ private _onNewRowFocus;
53
+ private _onNewRowKeyDown;
54
+ private _onRowMenu;
55
+ private _onPageChange;
56
+ private _onPageSizeChange;
57
+ private _colSpan;
58
+ private _getOptionLabel;
59
+ private _getPageNumbers;
60
+ private _moveToNextEditableCell;
61
+ private _fireSelectionChange;
62
+ connectedCallback(): void;
63
+ disconnectedCallback(): void;
64
+ private _onGlobalKeyDown;
65
+ private _handleCopy;
66
+ private _handlePaste;
67
+ private _moveFocus;
68
+ private _selectAll;
69
+ static define(tagName?: string): void;
70
+ }