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.mjs CHANGED
@@ -11217,6 +11217,37 @@ ChatSkeleton.displayName = "ChatSkeleton";
11217
11217
  // src/molecules/generic/EditableField/EditableField.tsx
11218
11218
  import React88, { useState as useState6, useEffect as useEffect5, useRef as useRef6 } from "react";
11219
11219
 
11220
+ // src/lib/format-utils.ts
11221
+ function isPlainRecord(value) {
11222
+ return typeof value === "object" && value !== null && !Array.isArray(value);
11223
+ }
11224
+ function devWarnUnexpectedObject(context, value) {
11225
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
11226
+ console.warn(
11227
+ `[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.`,
11228
+ value
11229
+ );
11230
+ }
11231
+ function formatCellValue(value, context = "cell") {
11232
+ if (value === null || value === void 0 || value === "") return "";
11233
+ if (typeof value !== "object") return String(value);
11234
+ devWarnUnexpectedObject(context, value);
11235
+ if (Array.isArray(value)) {
11236
+ if (value.length === 0) return "";
11237
+ if (value.every((item) => item === null || item === void 0 || typeof item !== "object")) {
11238
+ return value.map((item) => String(item ?? "")).join(", ");
11239
+ }
11240
+ return `${value.length} item${value.length === 1 ? "" : "s"}`;
11241
+ }
11242
+ if (isPlainRecord(value)) {
11243
+ const meaningful = value.label ?? value.name ?? value.title ?? value.id ?? value.value;
11244
+ if (typeof meaningful === "string" || typeof meaningful === "number") {
11245
+ return String(meaningful);
11246
+ }
11247
+ }
11248
+ return "Complex value";
11249
+ }
11250
+
11220
11251
  // src/components/ui/hover-card.tsx
11221
11252
  import * as React85 from "react";
11222
11253
  import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
@@ -11668,7 +11699,7 @@ var EditableField = React88.memo(
11668
11699
  if (!value) {
11669
11700
  return /* @__PURE__ */ jsx97("span", { className: "opacity-0", children: "-" });
11670
11701
  }
11671
- return typeof value === "object" ? JSON.stringify(value) : String(value ?? "");
11702
+ return formatCellValue(value, "label");
11672
11703
  };
11673
11704
  return /* @__PURE__ */ jsxs58(
11674
11705
  "div",
@@ -11922,7 +11953,7 @@ var FormCard = React90.memo(
11922
11953
  if (Array.isArray(val)) {
11923
11954
  return val.map((item) => {
11924
11955
  if (typeof item === "object" && item !== null) {
11925
- return item.label || item.value || item.name || JSON.stringify(item);
11956
+ return item.label || item.value || item.name || formatCellValue(item, "label");
11926
11957
  }
11927
11958
  return String(item);
11928
11959
  }).join(", ");
@@ -12191,7 +12222,7 @@ var StatsGrid = ({
12191
12222
  {
12192
12223
  id: `stat-label-${index}`,
12193
12224
  type: "text",
12194
- content: typeof item.label === "object" ? JSON.stringify(item.label) : String(item.label ?? ""),
12225
+ content: formatCellValue(item.label, "label"),
12195
12226
  variant: "small",
12196
12227
  className: cn(!hasPxVars && "text-muted-foreground", "font-medium tracking-wide uppercase text-[10px]"),
12197
12228
  style: textColor ? { color: textColor } : void 0
@@ -12231,7 +12262,7 @@ var StatsGrid = ({
12231
12262
  ),
12232
12263
  children: [
12233
12264
  TrendIcon && /* @__PURE__ */ jsx101(TrendIcon, { className: "w-3 h-3 mr-0.5" }),
12234
- typeof item.trend === "object" ? JSON.stringify(item.trend) : String(item.trend ?? "")
12265
+ formatCellValue(item.trend, "label")
12235
12266
  ]
12236
12267
  }
12237
12268
  )
@@ -12517,7 +12548,7 @@ var DataGrid = ({
12517
12548
  variant: "secondary",
12518
12549
  className: "border-gold/20 bg-gold/10 text-gold",
12519
12550
  style: s.accent,
12520
- children: typeof value === "object" ? JSON.stringify(value) : String(value ?? "")
12551
+ children: formatCellValue(value, "badge")
12521
12552
  }
12522
12553
  );
12523
12554
  case "avatar":
@@ -12533,7 +12564,7 @@ var DataGrid = ({
12533
12564
  case "number":
12534
12565
  return /* @__PURE__ */ jsx107("span", { className: "font-mono font-medium text-cardText", style: s.text, children: Number(value ?? 0).toLocaleString() });
12535
12566
  default:
12536
- return /* @__PURE__ */ jsx107("span", { className: "text-cardText", style: s.text, children: typeof value === "object" ? JSON.stringify(value) : String(value ?? "") });
12567
+ return /* @__PURE__ */ jsx107("span", { className: "text-cardText", style: s.text, children: formatCellValue(value, "cell") });
12537
12568
  }
12538
12569
  };
12539
12570
  return /* @__PURE__ */ jsxs67(
@@ -14675,11 +14706,7 @@ function stringifyValue(value, atomName, props) {
14675
14706
  }
14676
14707
  if (Array.isArray(value)) return value.join(", ");
14677
14708
  if (typeof value === "object") {
14678
- try {
14679
- return JSON.stringify(value);
14680
- } catch {
14681
- return String(value);
14682
- }
14709
+ return formatCellValue(value, "label");
14683
14710
  }
14684
14711
  return String(value);
14685
14712
  }
@@ -14835,7 +14862,7 @@ var ApprovalCard = React100.memo(
14835
14862
  style: i < details.length - 1 ? { borderBottomColor: theme?.border } : {},
14836
14863
  children: [
14837
14864
  /* @__PURE__ */ jsx128("span", { className: "text-cardText/50", style: s.muted, children: d.label }),
14838
- /* @__PURE__ */ jsx128("span", { className: "font-medium text-cardText", style: s.text, children: typeof d.value === "object" ? JSON.stringify(d.value) : String(d.value ?? "") })
14865
+ /* @__PURE__ */ jsx128("span", { className: "font-medium text-cardText", style: s.text, children: formatCellValue(d.value, "label") })
14839
14866
  ]
14840
14867
  },
14841
14868
  i
@@ -15122,7 +15149,7 @@ var DataTableCard = React103.memo(
15122
15149
  isHighlight ? "font-semibold text-gold" : colIdx === 0 ? "font-medium text-cardText" : "text-cardText/60"
15123
15150
  ),
15124
15151
  style: isHighlight ? s.accent : colIdx === 0 ? s.text : s.muted,
15125
- children: typeof cell === "object" ? JSON.stringify(cell) : String(cell)
15152
+ children: typeof cell === "object" ? formatCellValue(cell, "cell") : String(cell)
15126
15153
  },
15127
15154
  colIdx
15128
15155
  );
@@ -16117,7 +16144,7 @@ var ResearchBriefCard = ({
16117
16144
  item.label,
16118
16145
  ": "
16119
16146
  ] }),
16120
- /* @__PURE__ */ jsx138("span", { className: "text-muted-foreground", children: typeof item.value === "object" ? JSON.stringify(item.value) : String(item.value ?? "") })
16147
+ /* @__PURE__ */ jsx138("span", { className: "text-muted-foreground", children: formatCellValue(item.value, "label") })
16121
16148
  ] }, `${item.label}-${idx}`)) })
16122
16149
  ] })
16123
16150
  ]
@@ -16212,8 +16239,8 @@ var CampaignBriefCard = ({
16212
16239
  ] }),
16213
16240
  constraints.length > 0 ? /* @__PURE__ */ jsx140("ul", { className: "mt-4 space-y-1.5 text-sm text-foreground/90", children: constraints.map((item, i) => /* @__PURE__ */ jsxs100("li", { children: [
16214
16241
  "- ",
16215
- typeof item === "object" ? JSON.stringify(item) : String(item ?? "")
16216
- ] }, `${item}-${i}`)) }) : null
16242
+ formatCellValue(item, "label")
16243
+ ] }, `${typeof item === "object" ? i : item}-${i}`)) }) : null
16217
16244
  ] });
16218
16245
  };
16219
16246
 
@@ -21023,7 +21050,7 @@ var MCQCard = React114.memo(
21023
21050
  };
21024
21051
  const optionsEntries = resolvedOptions && Object.keys(resolvedOptions).length > 0 ? Object.entries(resolvedOptions).map(([key, val]) => [
21025
21052
  key,
21026
- typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || JSON.stringify(val) : String(val ?? "")
21053
+ typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || formatCellValue(val, "label") : String(val ?? "")
21027
21054
  ]) : [];
21028
21055
  const labelFor = (key) => {
21029
21056
  const found = optionsEntries.find(([k]) => k === key);
@@ -21062,6 +21089,22 @@ A: ${label}`);
21062
21089
  const selectedCount = selectedKeys.length;
21063
21090
  const meetsMin = (selectedCount || (recommended ? 1 : 0)) >= minSel;
21064
21091
  const isContinueDisabled = disabled || !isLatestMessage || isProceeded || isDiscovery;
21092
+ if (optionsEntries.length === 0) {
21093
+ return /* @__PURE__ */ jsxs118(
21094
+ "div",
21095
+ {
21096
+ "data-testid": "mcq-card-error",
21097
+ className: cn(
21098
+ "p-4 rounded-lg border border-red-500/30 bg-red-500/5 text-sm text-red-300 w-full",
21099
+ className
21100
+ ),
21101
+ children: [
21102
+ resolvedQuestion || "This question",
21103
+ " couldn't be displayed \u2014 its answer options are missing or in an unexpected format. Ask the agent to regenerate this question."
21104
+ ]
21105
+ }
21106
+ );
21107
+ }
21065
21108
  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`;
21066
21109
  return /* @__PURE__ */ jsxs118(
21067
21110
  "div",
@@ -21963,7 +22006,7 @@ var CampaignConceptCard = React116.memo(
21963
22006
  if (val.length === 0)
21964
22007
  return /* @__PURE__ */ jsx172("span", { className: "text-muted-foreground text-sm", children: "-" });
21965
22008
  return /* @__PURE__ */ jsx172("div", { className: "flex flex-wrap gap-2 pt-1", children: val.map((item, idx) => {
21966
- const label = typeof item === "object" && item !== null ? item.label || item.value || item.name || JSON.stringify(item) : String(item);
22009
+ const label = typeof item === "object" && item !== null ? item.label || item.value || item.name || formatCellValue(item, "badge") : String(item);
21967
22010
  return /* @__PURE__ */ jsx172(
21968
22011
  "span",
21969
22012
  {
@@ -22003,7 +22046,7 @@ var CampaignConceptCard = React116.memo(
22003
22046
  index !== void 0 ? index : "",
22004
22047
  " :",
22005
22048
  " ",
22006
- typeof cardTitle === "object" ? JSON.stringify(cardTitle) : String(cardTitle)
22049
+ typeof cardTitle === "object" ? formatCellValue(cardTitle, "title") : String(cardTitle)
22007
22050
  ] }),
22008
22051
  /* @__PURE__ */ jsxs129("div", { className: "flex flex-wrap gap-2", children: [
22009
22052
  isRecommended && /* @__PURE__ */ jsx172("span", { className: "text-[10px] font-semibold uppercase tracking-widest text-gold", children: "Recommended" }),
@@ -22061,7 +22104,7 @@ var CampaignConceptCard = React116.memo(
22061
22104
  FormCard,
22062
22105
  {
22063
22106
  ...formCardProps,
22064
- title: typeof cardTitle === "object" ? JSON.stringify(cardTitle) : String(cardTitle),
22107
+ title: typeof cardTitle === "object" ? formatCellValue(cardTitle, "title") : String(cardTitle),
22065
22108
  data,
22066
22109
  fields,
22067
22110
  showTimeline: true,