@t3q-ui/design-system 1.59.3 → 1.61.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.
@@ -3060,18 +3060,119 @@ function Panel({
3060
3060
  }
3061
3061
  );
3062
3062
  }
3063
- var Table = React12.forwardRef(
3064
- ({ className, ...props }, ref) => (
3065
- // 둥근 테두리 상자(AgGridTable 과 같은 8px·같은 선). overflow-auto 라 내용이 라운드로 잘린다 (2026-10-17 이슈 47 4차)
3066
- /* @__PURE__ */ jsx("div", { className: "w-full overflow-auto rounded-medium border border-sys-divider-subtle", children: /* @__PURE__ */ jsx(
3067
- "table",
3068
- {
3069
- ref,
3070
- className: cn("w-full table-auto border-collapse border-spacing-0 border-0", className),
3071
- ...props
3063
+
3064
+ // src/utils/columnWidths.ts
3065
+ var TEXT_COLUMN_GROW_LIMIT = 2;
3066
+ function distributeColumnWidths(cols, available) {
3067
+ const widths = cols.map((c) => c.content);
3068
+ let extra = available - widths.reduce((a, b) => a + b, 0);
3069
+ if (extra <= 0) return widths;
3070
+ const weight = (i) => Math.max(1, cols[i].content);
3071
+ const fill = (idx, cap) => {
3072
+ let active = idx.filter((i) => widths[i] < cap(i));
3073
+ while (extra > 0.01 && active.length > 0) {
3074
+ const total = active.reduce((s, i) => s + weight(i), 0);
3075
+ let used = 0;
3076
+ for (const i of active) {
3077
+ const give = Math.min(extra * weight(i) / total, cap(i) - widths[i]);
3078
+ widths[i] += give;
3079
+ used += give;
3072
3080
  }
3073
- ) })
3074
- )
3081
+ extra -= used;
3082
+ active = active.filter((i) => widths[i] < cap(i) - 0.01);
3083
+ }
3084
+ };
3085
+ const all = cols.map((_, i) => i);
3086
+ const grow = all.filter((i) => cols[i].grow);
3087
+ const maxOf = (i) => cols[i].max ?? Infinity;
3088
+ fill(grow, (i) => Math.min(maxOf(i), cols[i].content * TEXT_COLUMN_GROW_LIMIT));
3089
+ fill(all, maxOf);
3090
+ const last = grow.length > 0 ? grow : all;
3091
+ fill(last, () => Infinity);
3092
+ const rounded = widths.map((w) => Math.round(w));
3093
+ rounded[last[last.length - 1]] += Math.round(available) - rounded.reduce((a, b) => a + b, 0);
3094
+ return rounded;
3095
+ }
3096
+ var useIsoLayoutEffect = typeof window === "undefined" ? React12.useEffect : React12.useLayoutEffect;
3097
+ function measureColumnWidths(table) {
3098
+ const cells = Array.from(table.rows[0]?.cells ?? []);
3099
+ if (cells.length === 0 || cells.some((c) => c.colSpan > 1)) return null;
3100
+ const cols = Array.from(table.querySelectorAll(":scope > colgroup > col"));
3101
+ const saved = [table.style.width, table.style.tableLayout, ...cols.map((c) => c.style.width)];
3102
+ table.style.width = "max-content";
3103
+ table.style.tableLayout = "auto";
3104
+ cols.forEach((c) => c.style.width = "");
3105
+ const widths = cells.map((c) => c.getBoundingClientRect().width);
3106
+ table.style.width = saved[0];
3107
+ table.style.tableLayout = saved[1];
3108
+ cols.forEach((c, i) => c.style.width = saved[i + 2]);
3109
+ return widths.every((w) => w > 0) ? widths : null;
3110
+ }
3111
+ var sameWidths = (a, b) => a === b || !!a && !!b && a.length === b.length && a.every((w, i) => w === b[i]);
3112
+ var Table = React12.forwardRef(
3113
+ ({ className, children, ...props }, ref) => {
3114
+ const tableRef = React12.useRef(null);
3115
+ const setRef = React12.useCallback(
3116
+ (el) => {
3117
+ tableRef.current = el;
3118
+ if (typeof ref === "function") ref(el);
3119
+ else if (ref) ref.current = el;
3120
+ },
3121
+ [ref]
3122
+ );
3123
+ const [widths, setWidths] = React12.useState(null);
3124
+ const fit = !/(^|\s)table-fixed(\s|$)/.test(className ?? "");
3125
+ useIsoLayoutEffect(() => {
3126
+ const table = tableRef.current;
3127
+ const wrap = table?.parentElement;
3128
+ if (!fit || !table || !wrap) return;
3129
+ const update = () => {
3130
+ const content = measureColumnWidths(table);
3131
+ const available = wrap.clientWidth;
3132
+ let next = null;
3133
+ if (content && available > content.reduce((a, b) => a + b, 0)) {
3134
+ const firstIsNumber = table.rows[0].cells[0].dataset.align === "right";
3135
+ next = distributeColumnWidths(
3136
+ content.map((w, i) => ({ content: w, grow: i === 0 && !firstIsNumber })),
3137
+ available
3138
+ );
3139
+ }
3140
+ setWidths((prev) => sameWidths(prev, next) ? prev : next);
3141
+ };
3142
+ update();
3143
+ const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
3144
+ ro?.observe(wrap);
3145
+ const mo = new MutationObserver(update);
3146
+ mo.observe(table, { childList: true, subtree: true, characterData: true });
3147
+ return () => {
3148
+ ro?.disconnect();
3149
+ mo.disconnect();
3150
+ };
3151
+ }, [fit]);
3152
+ return (
3153
+ // 둥근 테두리 상자(AgGridTable 과 같은 8px·같은 선). overflow-auto 라 내용이 라운드로 잘린다 (2026-10-17 이슈 47 4차)
3154
+ /* @__PURE__ */ jsx("div", { className: "w-full overflow-auto rounded-medium border border-sys-divider-subtle", children: /* @__PURE__ */ jsxs(
3155
+ "table",
3156
+ {
3157
+ ref: setRef,
3158
+ className: cn(
3159
+ "w-full border-collapse border-spacing-0 border-0",
3160
+ widths ? "table-fixed" : "table-auto",
3161
+ className
3162
+ ),
3163
+ ...props,
3164
+ children: [
3165
+ widths && /* @__PURE__ */ jsx("colgroup", { children: widths.map((w, i) => (
3166
+ // 열은 순서로만 구분된다(첫 행 셀 순서)
3167
+ // eslint-disable-next-line react/no-array-index-key
3168
+ /* @__PURE__ */ jsx("col", { style: { width: w } }, i)
3169
+ )) }),
3170
+ children
3171
+ ]
3172
+ }
3173
+ ) })
3174
+ );
3175
+ }
3075
3176
  );
3076
3177
  var tableHeaderVariant = cva(
3077
3178
  // 헤더: 아주 연한 바탕(sys-table-header-background = o10) + 아래 1px 선(행 선과 같은 토큰). 양끝 라운드는 바깥 상자가 맡는다.
@@ -3128,7 +3229,7 @@ var TableRow = React12.forwardRef(
3128
3229
  }
3129
3230
  )
3130
3231
  );
3131
- var NUMBER_COLUMN_CLASS = "w-[140px] whitespace-nowrap";
3232
+ var NUMBER_COLUMN_CLASS = "whitespace-nowrap";
3132
3233
  var tableHeadVariant = cva(null, {
3133
3234
  variants: {
3134
3235
  align: {
@@ -3146,6 +3247,7 @@ var TableHead = React12.forwardRef(
3146
3247
  "th",
3147
3248
  {
3148
3249
  ref,
3250
+ "data-align": alignFromClassName(align, className) ?? "left",
3149
3251
  className: cn(tableHeadVariant({ align: alignFromClassName(align, className) }), className),
3150
3252
  ...props
3151
3253
  }
@@ -3156,7 +3258,7 @@ var tableCellMasterVariant = cva("align-middle px-[12px]", {
3156
3258
  align: {
3157
3259
  left: "",
3158
3260
  center: "[&>_.c-wrap-main]:justify-center",
3159
- // 머리글 없는 표는 첫 행이 열 폭을 정하므로 셀에도 숫자 열 폭을 준다
3261
+ // 머리글 없는 표도 숫자 셀은 한 줄
3160
3262
  right: `[&>_.c-wrap-main]:justify-end ${NUMBER_COLUMN_CLASS}`
3161
3263
  }
3162
3264
  },
@@ -3176,6 +3278,7 @@ var TableCell = React12.forwardRef(
3176
3278
  "td",
3177
3279
  {
3178
3280
  ref,
3281
+ "data-align": alignFromClassName(align, className) ?? "left",
3179
3282
  className: cn(
3180
3283
  tableCellMasterVariant({ align: alignFromClassName(align, className) }),
3181
3284
  className
@@ -3988,9 +4091,13 @@ function AgGridContent() {
3988
4091
  if (!target?.matches(".ag-cell, .ag-full-width-row")) return;
3989
4092
  onRowClicked({ ...e, type: "rowClicked" });
3990
4093
  };
4094
+ const growIds = useMemo(
4095
+ () => growColumnIds(restTableProps.columnDefs),
4096
+ [restTableProps.columnDefs]
4097
+ );
3991
4098
  const handleFirstDataRendered = (e) => {
3992
4099
  onFirstDataRendered?.(e);
3993
- if (fitToContent && !restTableProps.autoSizeStrategy) fitColumnsToContent(e.api);
4100
+ if (fitToContent && !restTableProps.autoSizeStrategy) fitColumnsToContent(e.api, growIds);
3994
4101
  };
3995
4102
  const mergedDefaultColDef = {
3996
4103
  ...userDefaultColDef,
@@ -4311,17 +4418,55 @@ function isFittable(col) {
4311
4418
  const def = col.getColDef();
4312
4419
  return col.isVisible() && !col.isPinned() && !col.getColId().startsWith("ag-Grid-") && !def.suppressAutoSize && !def.suppressSizeToFit;
4313
4420
  }
4314
- function fitColumnsToContent(api) {
4421
+ function growColumnIds(defs) {
4422
+ const ids = /* @__PURE__ */ new Set();
4423
+ const walk = (list) => {
4424
+ if (!Array.isArray(list)) return;
4425
+ for (const d of list) {
4426
+ if (!d || typeof d !== "object") continue;
4427
+ if (Array.isArray(d.children)) {
4428
+ walk(d.children);
4429
+ continue;
4430
+ }
4431
+ const types = columnTypesOf(d);
4432
+ if (types.includes("number") || !isFlex(d) && !types.includes("primary")) continue;
4433
+ const id = d.colId ?? d.field;
4434
+ if (typeof id === "string" && id !== "") ids.add(id);
4435
+ }
4436
+ };
4437
+ walk(defs);
4438
+ return ids;
4439
+ }
4440
+ function fitColumnsToContent(api, grow = /* @__PURE__ */ new Set()) {
4315
4441
  const onAutosized = (e) => {
4316
4442
  if (e.source !== "autosizeColumns" || !e.finished) return;
4317
4443
  api.removeEventListener("columnResized", onAutosized);
4318
- const cols = (api.getColumns() ?? []).filter(isFittable);
4444
+ const all = api.getColumns() ?? [];
4445
+ const cols = all.filter(isFittable);
4319
4446
  if (cols.length === 0) return;
4320
- api.applyColumnState({
4321
- state: cols.map((c) => ({
4322
- colId: c.getColId(),
4323
- flex: Math.max(1, Math.round(c.getActualWidth()))
4324
- }))
4447
+ let widths = cols.map((c) => c.getActualWidth());
4448
+ if (cols.some((c) => grow.has(c.getColId()))) {
4449
+ const range = api.getHorizontalPixelRange();
4450
+ const fixed = all.filter((c) => c.isVisible() && !c.isPinned() && !isFittable(c)).reduce((sum, c) => sum + c.getActualWidth(), 0);
4451
+ const available = range.right - range.left - fixed;
4452
+ if (available > 0)
4453
+ widths = distributeColumnWidths(
4454
+ cols.map((c, i) => ({
4455
+ content: widths[i],
4456
+ grow: grow.has(c.getColId()),
4457
+ max: c.getColDef().maxWidth ?? void 0
4458
+ })),
4459
+ available
4460
+ );
4461
+ }
4462
+ const state = cols.map((c, i) => ({
4463
+ colId: c.getColId(),
4464
+ flex: Math.max(1, Math.round(widths[i]))
4465
+ }));
4466
+ api.applyColumnState({ state });
4467
+ api.addEventListener("newColumnsLoaded", () => {
4468
+ const ids = new Set((api.getColumns() ?? []).map((c) => c.getColId()));
4469
+ api.applyColumnState({ state: state.filter((s) => ids.has(s.colId)) });
4325
4470
  });
4326
4471
  };
4327
4472
  api.addEventListener("columnResized", onAutosized);
@@ -4353,6 +4498,6 @@ function TwoLineCellRenderer(params) {
4353
4498
  ] });
4354
4499
  }
4355
4500
 
4356
- export { AG_GRID_LOCALE_KR, AgGridContext, AgGridTable, Alert, AlertActions, AlertDescription, AlertTitle, BADGE_OUTLINE_ACCENT, BALANCED_FILL_MIN_WIDTH, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardThumbnail, CardTitle, Checkbox, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyBoxIllustration, Form, FormControl, FormDescription, FormField, FormFooter, FormHeader, FormItem, FormLabel, FormMessage, FormSection, FormSectionLevelContext, FormValidMessage, HeaderCheckboxRenderer, IconButton, LucideIcon, NUMBER_COLUMN_CLASS, NUMBER_COLUMN_WIDTH, PageHeader, PageHeaderProvider, Pagination, PaginationContent, PaginationFirst, PaginationItem, PaginationLast, PaginationLink, PaginationNext, PaginationPrevious, PaginationWrapper, Panel, RowCheckboxRenderer, SORT_ICON_OFFSET_CLASS, Separator, Skeleton, SortIcon, Spinner, Stack, Table, TableBody, TableCell, TableHead, TableHeader, TablePagination, TableRow, TableSkeleton, Tabs, TabsContent, TabsList, TabsTrigger, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TwoLineCellRenderer, alignFromClassName, badgeVariants, buttonVariants, cn, estimateHeaderTextWidth, fitColumnsToContent, getPaginationRange, getSortedColumnState, sanitizeUserText, useFormControlContext, useFormField, usePageHeader, useRestoreFocusToOpener, withBalancedFill, withExplicitSortIcons, withFlexFill, withHeaderMinWidth, withNumberColumnWidth, withSortIconOffset, withTypeClasses, withWidthFloor };
4357
- //# sourceMappingURL=chunk-GOY465GH.js.map
4358
- //# sourceMappingURL=chunk-GOY465GH.js.map
4501
+ export { AG_GRID_LOCALE_KR, AgGridContext, AgGridTable, Alert, AlertActions, AlertDescription, AlertTitle, BADGE_OUTLINE_ACCENT, BALANCED_FILL_MIN_WIDTH, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardThumbnail, CardTitle, Checkbox, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyBoxIllustration, Form, FormControl, FormDescription, FormField, FormFooter, FormHeader, FormItem, FormLabel, FormMessage, FormSection, FormSectionLevelContext, FormValidMessage, HeaderCheckboxRenderer, IconButton, LucideIcon, NUMBER_COLUMN_CLASS, NUMBER_COLUMN_WIDTH, PageHeader, PageHeaderProvider, Pagination, PaginationContent, PaginationFirst, PaginationItem, PaginationLast, PaginationLink, PaginationNext, PaginationPrevious, PaginationWrapper, Panel, RowCheckboxRenderer, SORT_ICON_OFFSET_CLASS, Separator, Skeleton, SortIcon, Spinner, Stack, Table, TableBody, TableCell, TableHead, TableHeader, TablePagination, TableRow, TableSkeleton, Tabs, TabsContent, TabsList, TabsTrigger, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TwoLineCellRenderer, alignFromClassName, badgeVariants, buttonVariants, cn, estimateHeaderTextWidth, fitColumnsToContent, getPaginationRange, getSortedColumnState, growColumnIds, sanitizeUserText, useFormControlContext, useFormField, usePageHeader, useRestoreFocusToOpener, withBalancedFill, withExplicitSortIcons, withFlexFill, withHeaderMinWidth, withNumberColumnWidth, withSortIconOffset, withTypeClasses, withWidthFloor };
4502
+ //# sourceMappingURL=chunk-BGQ5WONC.js.map
4503
+ //# sourceMappingURL=chunk-BGQ5WONC.js.map