pxengine 0.1.150 → 0.1.152

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/dist/index.cjs CHANGED
@@ -11565,6 +11565,37 @@ ChatSkeleton.displayName = "ChatSkeleton";
11565
11565
  // src/molecules/generic/EditableField/EditableField.tsx
11566
11566
  var import_react59 = __toESM(require("react"), 1);
11567
11567
 
11568
+ // src/lib/format-utils.ts
11569
+ function isPlainRecord(value) {
11570
+ return typeof value === "object" && value !== null && !Array.isArray(value);
11571
+ }
11572
+ function devWarnUnexpectedObject(context, value) {
11573
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
11574
+ console.warn(
11575
+ `[PXEngine-UI] formatCellValue received an object/array where a primitive value was expected (context: "${context}"). This usually means the rendered schema and the data feeding it don't match \u2014 worth flagging to whatever generated this data.`,
11576
+ value
11577
+ );
11578
+ }
11579
+ function formatCellValue(value, context = "cell") {
11580
+ if (value === null || value === void 0 || value === "") return "";
11581
+ if (typeof value !== "object") return String(value);
11582
+ devWarnUnexpectedObject(context, value);
11583
+ if (Array.isArray(value)) {
11584
+ if (value.length === 0) return "";
11585
+ if (value.every((item) => item === null || item === void 0 || typeof item !== "object")) {
11586
+ return value.map((item) => String(item ?? "")).join(", ");
11587
+ }
11588
+ return `${value.length} item${value.length === 1 ? "" : "s"}`;
11589
+ }
11590
+ if (isPlainRecord(value)) {
11591
+ const meaningful = value.label ?? value.name ?? value.title ?? value.id ?? value.value;
11592
+ if (typeof meaningful === "string" || typeof meaningful === "number") {
11593
+ return String(meaningful);
11594
+ }
11595
+ }
11596
+ return "Complex value";
11597
+ }
11598
+
11568
11599
  // src/components/ui/hover-card.tsx
11569
11600
  var React85 = __toESM(require("react"), 1);
11570
11601
  var HoverCardPrimitive = __toESM(require("@radix-ui/react-hover-card"), 1);
@@ -12016,7 +12047,7 @@ var EditableField = import_react59.default.memo(
12016
12047
  if (!value) {
12017
12048
  return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)("span", { className: "opacity-0", children: "-" });
12018
12049
  }
12019
- return typeof value === "object" ? JSON.stringify(value) : String(value ?? "");
12050
+ return formatCellValue(value, "label");
12020
12051
  };
12021
12052
  return /* @__PURE__ */ (0, import_jsx_runtime97.jsxs)(
12022
12053
  "div",
@@ -12270,7 +12301,7 @@ var FormCard = import_react61.default.memo(
12270
12301
  if (Array.isArray(val)) {
12271
12302
  return val.map((item) => {
12272
12303
  if (typeof item === "object" && item !== null) {
12273
- return item.label || item.value || item.name || JSON.stringify(item);
12304
+ return item.label || item.value || item.name || formatCellValue(item, "label");
12274
12305
  }
12275
12306
  return String(item);
12276
12307
  }).join(", ");
@@ -12539,7 +12570,7 @@ var StatsGrid = ({
12539
12570
  {
12540
12571
  id: `stat-label-${index}`,
12541
12572
  type: "text",
12542
- content: typeof item.label === "object" ? JSON.stringify(item.label) : String(item.label ?? ""),
12573
+ content: formatCellValue(item.label, "label"),
12543
12574
  variant: "small",
12544
12575
  className: cn(!hasPxVars && "text-muted-foreground", "font-medium tracking-wide uppercase text-[10px]"),
12545
12576
  style: textColor ? { color: textColor } : void 0
@@ -12579,7 +12610,7 @@ var StatsGrid = ({
12579
12610
  ),
12580
12611
  children: [
12581
12612
  TrendIcon && /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(TrendIcon, { className: "w-3 h-3 mr-0.5" }),
12582
- typeof item.trend === "object" ? JSON.stringify(item.trend) : String(item.trend ?? "")
12613
+ formatCellValue(item.trend, "label")
12583
12614
  ]
12584
12615
  }
12585
12616
  )
@@ -12865,7 +12896,7 @@ var DataGrid = ({
12865
12896
  variant: "secondary",
12866
12897
  className: "border-gold/20 bg-gold/10 text-gold",
12867
12898
  style: s.accent,
12868
- children: typeof value === "object" ? JSON.stringify(value) : String(value ?? "")
12899
+ children: formatCellValue(value, "badge")
12869
12900
  }
12870
12901
  );
12871
12902
  case "avatar":
@@ -12881,7 +12912,7 @@ var DataGrid = ({
12881
12912
  case "number":
12882
12913
  return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("span", { className: "font-mono font-medium text-cardText", style: s.text, children: Number(value ?? 0).toLocaleString() });
12883
12914
  default:
12884
- return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("span", { className: "text-cardText", style: s.text, children: typeof value === "object" ? JSON.stringify(value) : String(value ?? "") });
12915
+ return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("span", { className: "text-cardText", style: s.text, children: formatCellValue(value, "cell") });
12885
12916
  }
12886
12917
  };
12887
12918
  return /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)(
@@ -15023,11 +15054,7 @@ function stringifyValue(value, atomName, props) {
15023
15054
  }
15024
15055
  if (Array.isArray(value)) return value.join(", ");
15025
15056
  if (typeof value === "object") {
15026
- try {
15027
- return JSON.stringify(value);
15028
- } catch {
15029
- return String(value);
15030
- }
15057
+ return formatCellValue(value, "label");
15031
15058
  }
15032
15059
  return String(value);
15033
15060
  }
@@ -15183,7 +15210,7 @@ var ApprovalCard = import_react71.default.memo(
15183
15210
  style: i < details.length - 1 ? { borderBottomColor: theme?.border } : {},
15184
15211
  children: [
15185
15212
  /* @__PURE__ */ (0, import_jsx_runtime128.jsx)("span", { className: "text-cardText/50", style: s.muted, children: d.label }),
15186
- /* @__PURE__ */ (0, import_jsx_runtime128.jsx)("span", { className: "font-medium text-cardText", style: s.text, children: typeof d.value === "object" ? JSON.stringify(d.value) : String(d.value ?? "") })
15213
+ /* @__PURE__ */ (0, import_jsx_runtime128.jsx)("span", { className: "font-medium text-cardText", style: s.text, children: formatCellValue(d.value, "label") })
15187
15214
  ]
15188
15215
  },
15189
15216
  i
@@ -15470,7 +15497,7 @@ var DataTableCard = import_react74.default.memo(
15470
15497
  isHighlight ? "font-semibold text-gold" : colIdx === 0 ? "font-medium text-cardText" : "text-cardText/60"
15471
15498
  ),
15472
15499
  style: isHighlight ? s.accent : colIdx === 0 ? s.text : s.muted,
15473
- children: typeof cell === "object" ? JSON.stringify(cell) : String(cell)
15500
+ children: typeof cell === "object" ? formatCellValue(cell, "cell") : String(cell)
15474
15501
  },
15475
15502
  colIdx
15476
15503
  );
@@ -16465,7 +16492,7 @@ var ResearchBriefCard = ({
16465
16492
  item.label,
16466
16493
  ": "
16467
16494
  ] }),
16468
- /* @__PURE__ */ (0, import_jsx_runtime138.jsx)("span", { className: "text-muted-foreground", children: typeof item.value === "object" ? JSON.stringify(item.value) : String(item.value ?? "") })
16495
+ /* @__PURE__ */ (0, import_jsx_runtime138.jsx)("span", { className: "text-muted-foreground", children: formatCellValue(item.value, "label") })
16469
16496
  ] }, `${item.label}-${idx}`)) })
16470
16497
  ] })
16471
16498
  ]
@@ -16560,8 +16587,8 @@ var CampaignBriefCard = ({
16560
16587
  ] }),
16561
16588
  constraints.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime140.jsx)("ul", { className: "mt-4 space-y-1.5 text-sm text-foreground/90", children: constraints.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime140.jsxs)("li", { children: [
16562
16589
  "- ",
16563
- typeof item === "object" ? JSON.stringify(item) : String(item ?? "")
16564
- ] }, `${item}-${i}`)) }) : null
16590
+ formatCellValue(item, "label")
16591
+ ] }, `${typeof item === "object" ? i : item}-${i}`)) }) : null
16565
16592
  ] });
16566
16593
  };
16567
16594
 
@@ -21359,7 +21386,7 @@ var MCQCard = import_react88.default.memo(
21359
21386
  };
21360
21387
  const optionsEntries = resolvedOptions && Object.keys(resolvedOptions).length > 0 ? Object.entries(resolvedOptions).map(([key, val]) => [
21361
21388
  key,
21362
- typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || JSON.stringify(val) : String(val ?? "")
21389
+ typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || formatCellValue(val, "label") : String(val ?? "")
21363
21390
  ]) : [];
21364
21391
  const labelFor = (key) => {
21365
21392
  const found = optionsEntries.find(([k]) => k === key);
@@ -21398,6 +21425,22 @@ A: ${label}`);
21398
21425
  const selectedCount = selectedKeys.length;
21399
21426
  const meetsMin = (selectedCount || (recommended ? 1 : 0)) >= minSel;
21400
21427
  const isContinueDisabled = disabled || !isLatestMessage || isProceeded || isDiscovery;
21428
+ if (optionsEntries.length === 0) {
21429
+ return /* @__PURE__ */ (0, import_jsx_runtime160.jsxs)(
21430
+ "div",
21431
+ {
21432
+ "data-testid": "mcq-card-error",
21433
+ className: cn(
21434
+ "p-4 rounded-lg border border-red-500/30 bg-red-500/5 text-sm text-red-300 w-full",
21435
+ className
21436
+ ),
21437
+ children: [
21438
+ resolvedQuestion || "This question",
21439
+ " couldn't be displayed \u2014 its answer options are missing or in an unexpected format. Ask the agent to regenerate this question."
21440
+ ]
21441
+ }
21442
+ );
21443
+ }
21401
21444
  const guidance = !isMulti ? "Select one option" : isSelectAll ? "Select all that apply" : minSel === maxSel ? `Select ${maxSel} options` : minSel <= 1 ? `Choose up to ${maxSel} options` : `Select between ${minSel} and ${maxSel} options`;
21402
21445
  return /* @__PURE__ */ (0, import_jsx_runtime160.jsxs)(
21403
21446
  "div",
@@ -22299,7 +22342,7 @@ var CampaignConceptCard = import_react90.default.memo(
22299
22342
  if (val.length === 0)
22300
22343
  return /* @__PURE__ */ (0, import_jsx_runtime172.jsx)("span", { className: "text-muted-foreground text-sm", children: "-" });
22301
22344
  return /* @__PURE__ */ (0, import_jsx_runtime172.jsx)("div", { className: "flex flex-wrap gap-2 pt-1", children: val.map((item, idx) => {
22302
- const label = typeof item === "object" && item !== null ? item.label || item.value || item.name || JSON.stringify(item) : String(item);
22345
+ const label = typeof item === "object" && item !== null ? item.label || item.value || item.name || formatCellValue(item, "badge") : String(item);
22303
22346
  return /* @__PURE__ */ (0, import_jsx_runtime172.jsx)(
22304
22347
  "span",
22305
22348
  {
@@ -22339,7 +22382,7 @@ var CampaignConceptCard = import_react90.default.memo(
22339
22382
  index !== void 0 ? index : "",
22340
22383
  " :",
22341
22384
  " ",
22342
- typeof cardTitle === "object" ? JSON.stringify(cardTitle) : String(cardTitle)
22385
+ typeof cardTitle === "object" ? formatCellValue(cardTitle, "title") : String(cardTitle)
22343
22386
  ] }),
22344
22387
  /* @__PURE__ */ (0, import_jsx_runtime172.jsxs)("div", { className: "flex flex-wrap gap-2", children: [
22345
22388
  isRecommended && /* @__PURE__ */ (0, import_jsx_runtime172.jsx)("span", { className: "text-[10px] font-semibold uppercase tracking-widest text-gold", children: "Recommended" }),
@@ -22397,7 +22440,7 @@ var CampaignConceptCard = import_react90.default.memo(
22397
22440
  FormCard,
22398
22441
  {
22399
22442
  ...formCardProps,
22400
- title: typeof cardTitle === "object" ? JSON.stringify(cardTitle) : String(cardTitle),
22443
+ title: typeof cardTitle === "object" ? formatCellValue(cardTitle, "title") : String(cardTitle),
22401
22444
  data,
22402
22445
  fields,
22403
22446
  showTimeline: true,