@iyulab/data-components 0.1.7 → 0.1.8

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;
@@ -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;
@@ -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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/data-components",
3
3
  "description": "iyulab data visualization components",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "web-components",