@krak-stack/registry 0.11.5 → 0.11.6

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.
@@ -614,6 +614,13 @@ import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
614
614
  import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/krakstack-provider/react";
615
615
 
616
616
  // ../../src/components/data-table/classes.ts
617
+ var booleanCellControl = "flex min-h-16 w-full items-center justify-start px-2 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0 has-[:focus-visible]:outline-2 has-[:focus-visible]:-outline-offset-2 has-[:focus-visible]:outline-ring";
618
+ var cellTriggerFocus = "focus-visible:ring-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring";
619
+ var tableBadgeTones = {
620
+ success: "border-emerald-200 bg-emerald-100 text-emerald-900 dark:border-emerald-900/50 dark:bg-emerald-950/50 dark:text-emerald-200",
621
+ info: "border-blue-200 bg-blue-100 text-blue-900 dark:border-blue-900/50 dark:bg-blue-950/50 dark:text-blue-200",
622
+ muted: "border-muted bg-muted text-muted-foreground dark:bg-muted/50"
623
+ };
617
624
  var tableClasses = {
618
625
  selectionCell: "w-10 p-0 align-middle",
619
626
  selectionCenter: "grid place-items-center",
@@ -625,16 +632,16 @@ var tableClasses = {
625
632
  menubar: "h-auto w-full flex-wrap justify-start border border-input bg-transparent",
626
633
  cell: "overflow-hidden",
627
634
  cellContent: "min-w-0 wrap-anywhere",
628
- actionTrigger: "size-8 focus-visible:ring-inset",
635
+ actionTrigger: `size-8 ${cellTriggerFocus}`,
629
636
  actionsCell: "sticky right-0 z-20 w-10 min-w-10 cursor-default bg-background p-0 transition-colors group-hover/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))]",
630
637
  actionsAlign: "flex min-h-12 items-center justify-end pe-1",
631
638
  header: "relative h-12 p-0",
632
639
  stickyHeader: "sticky top-0 z-30 bg-background",
633
640
  stickyHeaderRule: "after:border-border after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:border-b",
634
- headerTrigger: "absolute inset-0 h-full w-full min-w-0 justify-start rounded-none px-2 pe-4 focus-visible:ring-inset",
641
+ headerTrigger: `absolute inset-0 h-full w-full min-w-0 justify-start rounded-none px-2 pe-4 ${cellTriggerFocus}`,
635
642
  resizeHandle: "absolute inset-y-0 right-0 z-10 w-2 cursor-col-resize touch-none outline-none after:absolute after:inset-y-3 after:right-0 after:w-px after:bg-border hover:after:w-0.5 hover:after:bg-primary/60 focus-visible:after:w-0.5 focus-visible:after:bg-ring",
636
643
  relationshipCell: "grid min-h-16 in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0",
637
- relationshipTrigger: "h-full w-full min-w-0 justify-between rounded-none px-2 text-start focus-visible:ring-inset",
644
+ relationshipTrigger: `h-full w-full min-w-0 justify-between rounded-none px-2 text-start ${cellTriggerFocus}`,
638
645
  reference: "flex min-w-0 items-center gap-2",
639
646
  referenceAvatar: "relative grid size-8 shrink-0 place-items-center overflow-hidden bg-muted text-xs font-medium",
640
647
  referenceText: "flex min-w-0 flex-col leading-tight",
@@ -656,7 +663,7 @@ import { Csv } from "effect/encoding";
656
663
  import { Command, Component as Component2, Subscription, UiSchema as UiSchema2 } from "effect/ui";
657
664
 
658
665
  // ../../src/components/data-table/schema.ts
659
- import { DateTime as DateTime2, Option as Option2, Schema as Schema4, Struct as Struct2, Tuple } from "effect";
666
+ import { DateTime as DateTime2, Option as Option2, Predicate, Schema as Schema4, Struct as Struct2, Tuple } from "effect";
660
667
  var TableClassesOverridesSchema = Schema4.Record(Schema4.Literals(Struct2.keys(tableClasses)), Schema4.optionalKey(Schema4.String)).annotate({ identifier: "TableClassesOverrides" });
661
668
  var DataTableCommonPropsSchema = Schema4.Struct({
662
669
  classes: Schema4.optional(TableClassesOverridesSchema),
@@ -764,8 +771,33 @@ var column = {
764
771
  emptyLabel: Schema4.optionalKey(Schema4.String),
765
772
  nulls: Schema4.optionalKey(Schema4.Literals(["first", "last"]))
766
773
  };
774
+ var DataTableBadgeOptionSchema = Schema4.Struct({
775
+ value: Schema4.NonEmptyString,
776
+ label: Schema4.optionalKey(Schema4.String),
777
+ variant: Schema4.optionalKey(Schema4.Literals([
778
+ "default",
779
+ "secondary",
780
+ "outline",
781
+ "destructive",
782
+ "success",
783
+ "info",
784
+ "muted"
785
+ ]))
786
+ }).annotate({ identifier: "DataTableBadgeOption" });
787
+ var BadgeIcon = Schema4.declare((value) => Predicate.isFunction(value)).annotate({ identifier: "DataTableBadgeIcon" });
788
+ var DataTableBadgeOptionsSchema = Schema4.Struct({
789
+ options: Schema4.optionalKey(Schema4.Array(DataTableBadgeOptionSchema.mapFields((fields) => ({
790
+ ...fields,
791
+ icon: Schema4.optionalKey(BadgeIcon)
792
+ }))))
793
+ }).annotate({ identifier: "DataTableBadgeOptions" });
767
794
  var DataTableFieldSchema = Schema4.Union([
768
- Schema4.Struct({ ...column, type: Schema4.Literal("text") }),
795
+ Schema4.Struct({
796
+ ...column,
797
+ type: Schema4.Literal("text"),
798
+ display: Schema4.optionalKey(Schema4.Literal("badge")),
799
+ typeOptions: Schema4.optionalKey(DataTableBadgeOptionsSchema)
800
+ }),
769
801
  Schema4.Struct({
770
802
  ...column,
771
803
  type: Schema4.Literal("number"),
@@ -808,7 +840,7 @@ var DataTableFieldSchema = Schema4.Union([
808
840
  options: Schema4.optionalKey(Schema4.Array(DataTableItemSchema)),
809
841
  allowRemove: Schema4.optionalKey(Schema4.Boolean),
810
842
  itemActions: Schema4.optionalKey(Schema4.Array(DataTableActionSchema)),
811
- display: Schema4.optionalKey(Schema4.Literals(["list", "icon"])),
843
+ display: Schema4.optionalKey(Schema4.Literals(["list", "icon", "badge"])),
812
844
  visibleCount: Schema4.optionalKey(Schema4.Int.check(Schema4.isGreaterThanOrEqualTo(0))),
813
845
  actionsLabel: Schema4.optionalKey(Schema4.String),
814
846
  manageLabel: Schema4.optionalKey(Schema4.String)
@@ -1102,7 +1134,33 @@ var matchesFilterText = (value, filter) => {
1102
1134
  return text.endsWith(query);
1103
1135
  }
1104
1136
  };
1105
- var tableFilterKind = (column, hasOptions = false) => hasOptions || column.type === "list" ? "values" : column.type === "reference" ? "text" : column.type === "dateTime" ? "date" : column.type ?? "text";
1137
+ var tableFilterKind = (column, hasOptions = false) => hasOptions || column.type === "list" || column.display === "badge" ? "values" : column.type === "reference" ? "text" : column.type === "dateTime" ? "date" : column.type ?? "text";
1138
+ var tableBadgeValue = (value) => isTableText(value) && value !== "" ? value : null;
1139
+ var tableBadge = (input, config) => {
1140
+ const value = tableBadgeValue(input);
1141
+ if (value === null)
1142
+ return null;
1143
+ const option = config?.options?.find((option) => option.value === value);
1144
+ return {
1145
+ value,
1146
+ label: option?.label ?? value,
1147
+ variant: option?.variant ?? "secondary",
1148
+ option
1149
+ };
1150
+ };
1151
+ var tableBadgeFilterOptions = (values, config) => {
1152
+ const options = new Map(config?.options?.map(({ value, label }) => [value, label ?? value]));
1153
+ for (const input of values) {
1154
+ const value = tableBadgeValue(input);
1155
+ if (value !== null && !options.has(value))
1156
+ options.set(value, value);
1157
+ }
1158
+ return [...options].map(([value, label]) => ({ value, label }));
1159
+ };
1160
+ var tableBadgeSearchText = (value, config) => {
1161
+ const badge = tableBadge(value, config);
1162
+ return badge ? `${badge.label} ${badge.value}` : "";
1163
+ };
1106
1164
  var matchesTableFilter = (filter, value, type, text, values) => {
1107
1165
  switch (filter.kind) {
1108
1166
  case "text":
@@ -1136,13 +1194,20 @@ var filterTableColumns = (rows, columns, filters) => {
1136
1194
  return rows;
1137
1195
  return rows.filter((row) => active.every((filter) => {
1138
1196
  const value = row.cells[filter.id];
1139
- return matchesTableFilter(filter, value, byId.get(filter.id)?.type, () => isTableText(value) ? value : isTableReference(value) ? `${value.label} ${value.description ?? ""}`.trim() : "", () => isTableList(value) ? value.map(({ value }) => value) : []);
1197
+ const column = byId.get(filter.id);
1198
+ return matchesTableFilter(filter, value, column?.type, () => isTableText(value) ? value : isTableReference(value) ? `${value.label} ${value.description ?? ""}`.trim() : "", () => {
1199
+ if (column?.type === "text" && column.display === "badge") {
1200
+ const key = tableBadgeValue(value);
1201
+ return key === null ? [] : [key];
1202
+ }
1203
+ return isTableList(value) ? value.map(({ value }) => value) : [];
1204
+ });
1140
1205
  }));
1141
1206
  };
1142
1207
  var columnValue = (column, value) => {
1143
1208
  switch (column.type) {
1144
1209
  case "text":
1145
- return isTableText(value) ? value : null;
1210
+ return column.display === "badge" ? tableBadgeValue(value) : isTableText(value) ? value : null;
1146
1211
  case "number":
1147
1212
  case "boolean":
1148
1213
  case "date":
@@ -1196,6 +1261,8 @@ var filterTableRows = (rows, columns, search, locale) => {
1196
1261
  const searchable = columns.filter(({ searchable }) => searchable !== false);
1197
1262
  return rows.filter((row) => searchable.some((column) => {
1198
1263
  const value = row.cells[column.id];
1264
+ if (column.type === "text" && column.display === "badge")
1265
+ return tableBadgeSearchText(value, column.typeOptions).toLocaleLowerCase(locale).includes(query);
1199
1266
  if (column.type === "date" || column.type === "dateTime") {
1200
1267
  const date = resolveDate(value, column.type);
1201
1268
  return !!date && `${formatDateValue(date, column, locale)} ${dateIsoValue(date)}`.toLocaleLowerCase(locale).includes(query);
@@ -2125,6 +2192,8 @@ var booleanLabel = (value, options) => value ? options?.trueLabel : options?.fal
2125
2192
  var getDataTableExportValue = (row, column, locale = "en") => {
2126
2193
  const value = row.values.get(column.id);
2127
2194
  const colDef = column.colDef;
2195
+ if (colDef.type === "text" && colDef.display === "badge")
2196
+ return tableBadgeValue(value);
2128
2197
  if (colDef.type === "number") {
2129
2198
  const number = Option4.getOrUndefined(decodeNumberValue(value));
2130
2199
  if (number === undefined)
@@ -2153,7 +2222,9 @@ var filterDataTableRows = (rows, columns, globalFilter, locale = "en") => {
2153
2222
  const value = row.values.get(column.id);
2154
2223
  const colDef = column.colDef;
2155
2224
  let text = dataTableValueText(value);
2156
- if (colDef.type === "date" || colDef.type === "dateTime") {
2225
+ if (colDef.type === "text" && colDef.display === "badge") {
2226
+ text = tableBadgeSearchText(value, colDef.typeOptions);
2227
+ } else if (colDef.type === "date" || colDef.type === "dateTime") {
2157
2228
  const date = resolveDate(value, colDef.type);
2158
2229
  text = date ? `${formatDateValue(date, colDef, locale)} ${dateIsoValue(date)}` : "";
2159
2230
  } else if (colDef.type === "number") {
@@ -2169,11 +2240,14 @@ var filterDataTableRows = (rows, columns, globalFilter, locale = "en") => {
2169
2240
  var getDataTableFilterColumns = (columns) => columns.flatMap((column) => column.colDef.filterable === false ? [] : ((column.colDef.fields?.length) ? getDataTableFieldColumns(column) : [column]).filter(({ colDef }) => colDef.filterable !== false));
2170
2241
  var getDataTableFilterKind = ({
2171
2242
  colDef
2172
- }) => tableFilterKind(colDef, !!colDef.filterOptions);
2243
+ }) => tableFilterKind(colDef.type === "text" ? colDef : { type: colDef.type }, !!colDef.filterOptions);
2173
2244
  var getDataTableFilterOptions = (rows, column) => {
2174
2245
  const { colDef } = column;
2175
2246
  if (colDef.filterOptions)
2176
2247
  return colDef.filterOptions;
2248
+ if (colDef.type === "text" && colDef.display === "badge") {
2249
+ return tableBadgeFilterOptions(rows.map((row) => row.values.get(column.id)), colDef.typeOptions);
2250
+ }
2177
2251
  const options = new Map;
2178
2252
  if (colDef.type === "list") {
2179
2253
  for (const row of rows) {
@@ -2198,7 +2272,15 @@ var filterDataTableColumnRows = (rows, columns, filters) => {
2198
2272
  colDef: column.colDef
2199
2273
  }) : row.values.get(column.id);
2200
2274
  const { colDef } = column;
2201
- return matchesTableFilter(filter, value, colDef.type, () => dataTableValueText(value), () => colDef.type === "list" ? colDef.typeOptions.getItems(row.data).map((item) => item.value ?? item.label) : [dataTableValueText(value)]);
2275
+ return matchesTableFilter(filter, value, colDef.type, () => dataTableValueText(value), () => {
2276
+ if (colDef.type === "list")
2277
+ return colDef.typeOptions.getItems(row.data).map((item) => item.value ?? item.label);
2278
+ if (colDef.type === "text" && colDef.display === "badge") {
2279
+ const key = tableBadgeValue(value);
2280
+ return key === null ? [] : [key];
2281
+ }
2282
+ return [dataTableValueText(value)];
2283
+ });
2202
2284
  }));
2203
2285
  };
2204
2286
  var sortDataTableRows = (rows, columns, sorting) => {
@@ -2214,6 +2296,12 @@ var sortDataTableRows = (rows, columns, sorting) => {
2214
2296
  const leftValue = left.row.values.get(sort.id);
2215
2297
  const rightValue = right.row.values.get(sort.id);
2216
2298
  const colDef = column.colDef;
2299
+ if (!colDef.comparator && colDef.type === "text" && colDef.display === "badge") {
2300
+ const comparison = compareTableSortValues(tableBadgeValue(leftValue), tableBadgeValue(rightValue), sort.direction);
2301
+ if (comparison !== 0)
2302
+ return comparison;
2303
+ continue;
2304
+ }
2217
2305
  if (!colDef.comparator && (colDef.type === "number" || colDef.type === "boolean" || colDef.type === "date" || colDef.type === "dateTime")) {
2218
2306
  const comparison = compareTableSortValues(tableSortScalar(colDef.type, leftValue), tableSortScalar(colDef.type, rightValue), sort.direction, colDef.typeOptions?.nulls);
2219
2307
  if (comparison !== 0)
@@ -2370,6 +2458,27 @@ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)
2370
2458
  ...params
2371
2459
  });
2372
2460
  const colDef = column.colDef;
2461
+ if (colDef.type === "text" && colDef.display === "badge") {
2462
+ if (colDef.valueFormatter)
2463
+ return colDef.valueFormatter(params);
2464
+ const badge = tableBadge(value, colDef.typeOptions);
2465
+ if (!badge)
2466
+ return colDef.typeOptions?.emptyLabel ?? "—";
2467
+ const { variant, label, option } = badge;
2468
+ const tone = variant === "success" || variant === "info" || variant === "muted" ? tableBadgeTones[variant] : undefined;
2469
+ return /* @__PURE__ */ jsxs3(Badge, {
2470
+ variant: variant === "success" || variant === "info" || variant === "muted" ? "outline" : variant,
2471
+ className: tone,
2472
+ children: [
2473
+ option?.icon && /* @__PURE__ */ jsx3("span", {
2474
+ "aria-hidden": "true",
2475
+ className: "inline-flex shrink-0 [&_svg]:size-3",
2476
+ children: option.icon
2477
+ }),
2478
+ label
2479
+ ]
2480
+ });
2481
+ }
2373
2482
  if (colDef.type === "reference") {
2374
2483
  if (colDef.valueFormatter)
2375
2484
  return colDef.valueFormatter(params);
@@ -2397,7 +2506,7 @@ var renderCell = (row, column, locale = "en", labels = dataTableMessages(locale)
2397
2506
  const options = colDef.typeOptions;
2398
2507
  return /* @__PURE__ */ jsx3("label", {
2399
2508
  "data-slot": "data-table-boolean-cell",
2400
- className: cn("focus-within:border-ring focus-within:ring-ring/50 flex min-h-16 w-full items-center justify-start border border-transparent px-2 outline-none focus-within:ring-3 focus-within:ring-inset in-[[data-slot=table-cell]]:absolute in-[[data-slot=table-cell]]:inset-0 in-[[data-slot=table-cell]]:min-h-0", options?.onChange && !options.disabled?.(row.data) && "hover:bg-muted/50 cursor-pointer"),
2509
+ className: cn(booleanCellControl, options?.onChange && !options.disabled?.(row.data) && "hover:bg-muted/50 cursor-pointer"),
2401
2510
  onClick: (event) => event.stopPropagation(),
2402
2511
  onPointerDown: (event) => event.stopPropagation(),
2403
2512
  children: /* @__PURE__ */ jsx3(Checkbox, {
@@ -4069,7 +4178,9 @@ var GalleryTag = ({
4069
4178
  if ((value == null || value === "") && !column.colDef.cellRenderer)
4070
4179
  return null;
4071
4180
  const content = renderCell(row, column, locale, labels);
4072
- return column.colDef.cellRenderer || column.colDef.valueFormatter ? /* @__PURE__ */ jsxs3("div", {
4181
+ const { colDef } = column;
4182
+ const displaysBadges = colDef.type === "text" && colDef.display === "badge" || colDef.type === "list" && colDef.typeOptions.display === "badge";
4183
+ return colDef.cellRenderer || colDef.valueFormatter || displaysBadges ? /* @__PURE__ */ jsxs3("div", {
4073
4184
  className: "flex min-w-0 items-center gap-1",
4074
4185
  children: [
4075
4186
  icon,
@@ -4786,7 +4897,7 @@ var EditableDataTableListCell = ({
4786
4897
  } : undefined,
4787
4898
  trigger: /* @__PURE__ */ jsxs3(Button2, {
4788
4899
  "aria-label": manageLabel,
4789
- className: "h-full w-full min-w-0 justify-between rounded-none px-2 focus-visible:ring-inset",
4900
+ className: tableClasses.relationshipTrigger,
4790
4901
  variant: "ghost",
4791
4902
  children: [
4792
4903
  /* @__PURE__ */ jsx3(DataTableListSummaryContent, {
@@ -5027,6 +5138,32 @@ var DataTableListSummaryContent = ({
5027
5138
  })
5028
5139
  });
5029
5140
  }
5141
+ if (display === "badge") {
5142
+ return /* @__PURE__ */ jsxs3("span", {
5143
+ className: "inline-flex min-w-0 flex-wrap items-center gap-1",
5144
+ children: [
5145
+ visible.map((item, index) => /* @__PURE__ */ jsx3(Badge, {
5146
+ variant: "secondary",
5147
+ children: item.label
5148
+ }, item.value ?? `${item.label}-${index}`)),
5149
+ remaining ? /* @__PURE__ */ jsxs3(Badge, {
5150
+ variant: "secondary",
5151
+ children: [
5152
+ "+",
5153
+ remaining
5154
+ ]
5155
+ }) : null,
5156
+ remaining && showMenu ? /* @__PURE__ */ jsx3(DataTableListMenu, {
5157
+ actions: [],
5158
+ display,
5159
+ force: true,
5160
+ items: normalized,
5161
+ locale,
5162
+ messages
5163
+ }) : null
5164
+ ]
5165
+ });
5166
+ }
5030
5167
  return /* @__PURE__ */ jsxs3("span", {
5031
5168
  className: "inline-flex min-w-0 items-center gap-2 text-sm",
5032
5169
  children: [