@shapesos/clay 0.14.0 → 0.16.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.
Files changed (37) hide show
  1. package/README.md +14 -0
  2. package/dist/ai-elements.cjs +112 -7
  3. package/dist/ai-elements.cjs.map +1 -1
  4. package/dist/ai-elements.d.cts +30 -2
  5. package/dist/ai-elements.d.ts +30 -2
  6. package/dist/ai-elements.js +1 -1
  7. package/dist/artifacts.cjs +85 -34
  8. package/dist/artifacts.cjs.map +1 -1
  9. package/dist/artifacts.js +2 -2
  10. package/dist/blocks.cjs +85 -34
  11. package/dist/blocks.cjs.map +1 -1
  12. package/dist/blocks.css +1 -1
  13. package/dist/blocks.js +3 -3
  14. package/dist/chart.cjs +85 -34
  15. package/dist/chart.cjs.map +1 -1
  16. package/dist/chart.d.cts +12 -10
  17. package/dist/chart.d.ts +12 -10
  18. package/dist/chart.js +1 -1
  19. package/dist/chat.cjs +85 -34
  20. package/dist/chat.cjs.map +1 -1
  21. package/dist/chat.js +4 -4
  22. package/dist/{chunk-XFJ6XMJZ.js → chunk-2YCBDSPK.js} +2 -2
  23. package/dist/{chunk-BR5S37SC.js → chunk-4VE6ZXXW.js} +113 -8
  24. package/dist/chunk-4VE6ZXXW.js.map +1 -0
  25. package/dist/{chunk-3THOTQO3.js → chunk-GAZRZZRF.js} +3 -3
  26. package/dist/{chunk-YZB6YXKK.js → chunk-U3IXCSV6.js} +86 -35
  27. package/dist/chunk-U3IXCSV6.js.map +1 -0
  28. package/dist/{chunk-MDAWYZBI.js → chunk-UZKNSAAD.js} +2 -2
  29. package/dist/index.cjs +197 -41
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.js +5 -5
  32. package/package.json +1 -1
  33. package/dist/chunk-BR5S37SC.js.map +0 -1
  34. package/dist/chunk-YZB6YXKK.js.map +0 -1
  35. /package/dist/{chunk-XFJ6XMJZ.js.map → chunk-2YCBDSPK.js.map} +0 -0
  36. /package/dist/{chunk-3THOTQO3.js.map → chunk-GAZRZZRF.js.map} +0 -0
  37. /package/dist/{chunk-MDAWYZBI.js.map → chunk-UZKNSAAD.js.map} +0 -0
@@ -981,6 +981,11 @@ var CHART_PALETTE = [
981
981
  ];
982
982
  var OTHERS_SLICE_COLOR = colors["brown-60"];
983
983
  var DEFAULT_OTHERS_CATEGORY_LABELS = ["others", "other"];
984
+ var NONE_CATEGORY_VALUES = ["", "(none)", "none", "null", "undefined", "n/a", "-"];
985
+ function isNoneCategory(value) {
986
+ if (value === null || value === void 0) return true;
987
+ return NONE_CATEGORY_VALUES.includes(String(value).trim().toLowerCase());
988
+ }
984
989
  function isOthersCategory(value, labels) {
985
990
  if (value === null || value === void 0) return false;
986
991
  if (labels.length === 0) return false;
@@ -1036,6 +1041,13 @@ function truncateLabel(value, maxChars) {
1036
1041
  if (s.length <= maxChars) return s;
1037
1042
  return s.slice(0, Math.max(1, maxChars - 1)).trimEnd() + "\u2026";
1038
1043
  }
1044
+ var compactNumberFormat = new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 });
1045
+ function compactNumberTickFormatter(value) {
1046
+ if (value === null || value === void 0) return "";
1047
+ const n = typeof value === "number" ? value : Number(value);
1048
+ if (!Number.isFinite(n)) return String(value);
1049
+ return compactNumberFormat.format(n);
1050
+ }
1039
1051
  function evenlyDistributedVisibleIndices(n, target) {
1040
1052
  if (n <= target) {
1041
1053
  return new Set(Array.from({ length: n }, (_, i) => i));
@@ -1075,6 +1087,11 @@ function coerceNumericColumns(rows, numericKeys) {
1075
1087
 
1076
1088
  // src/components/chart/bar-chart/bar-chart.tsx
1077
1089
  var import_jsx_runtime12 = require("react/jsx-runtime");
1090
+ var STACK_TOTAL_KEY = "__stackTotal";
1091
+ var VALUE_LABEL_HEADROOM = 20;
1092
+ function sumSeries(row, keys) {
1093
+ return keys.reduce((sum, key) => sum + (Number(row[key]) || 0), 0);
1094
+ }
1078
1095
  function BarChart({
1079
1096
  data,
1080
1097
  xKey,
@@ -1100,15 +1117,24 @@ function BarChart({
1100
1117
  [data, seriesKeys]
1101
1118
  );
1102
1119
  const resolvedShowLegend = showLegend ?? series.length > 1;
1103
- const resolvedShowValueLabels = showValueLabels ?? (!stacked && series.length === 1);
1120
+ const resolvedShowValueLabels = showValueLabels ?? true;
1121
+ const plotData = (0, import_react9.useMemo)(() => {
1122
+ if (!stacked || !resolvedShowValueLabels) return coercedData;
1123
+ return coercedData.map((row) => ({ ...row, [STACK_TOTAL_KEY]: sumSeries(row, seriesKeys) }));
1124
+ }, [coercedData, stacked, resolvedShowValueLabels, seriesKeys]);
1104
1125
  const resolvedAngle = xAxisAngle ?? (coercedData.length >= 8 ? -30 : 0);
1105
1126
  const resolvedTickFormatter = (0, import_react9.useMemo)(
1106
1127
  () => xAxisTickFormatter ?? defaultBarTickFormatter(coercedData.length),
1107
1128
  [xAxisTickFormatter, coercedData.length]
1108
1129
  );
1109
1130
  const angledLabelPad = resolvedAngle === 0 ? 0 : Math.min(Math.abs(resolvedAngle) * 0.7, 40);
1110
- const chartMargin = { ...CHART_MARGIN, bottom: CHART_MARGIN.bottom + angledLabelPad };
1111
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_recharts2.BarChart, { data: coercedData, margin: chartMargin, barCategoryGap: "22%", children: [
1131
+ const valueLabelHeadroom = resolvedShowValueLabels ? VALUE_LABEL_HEADROOM : 0;
1132
+ const chartMargin = {
1133
+ ...CHART_MARGIN,
1134
+ top: CHART_MARGIN.top + valueLabelHeadroom,
1135
+ bottom: CHART_MARGIN.bottom + angledLabelPad
1136
+ };
1137
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_recharts2.BarChart, { data: plotData, margin: chartMargin, barCategoryGap: "22%", children: [
1112
1138
  showGrid ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.CartesianGrid, { ...CHART_GRID_PROPS }) : null,
1113
1139
  showXAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1114
1140
  import_recharts2.XAxis,
@@ -1123,7 +1149,7 @@ function BarChart({
1123
1149
  tickFormatter: resolvedTickFormatter
1124
1150
  }
1125
1151
  ) : null,
1126
- showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
1152
+ showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.YAxis, { ...CHART_AXIS_PROPS, width: 40, tickFormatter: compactNumberTickFormatter }) : null,
1127
1153
  showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.Tooltip, { cursor: { fill: BAR_TOOLTIP_CURSOR_FILL }, content: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartTooltipContent, {}) }) : null,
1128
1154
  resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1129
1155
  import_recharts2.Legend,
@@ -1135,18 +1161,23 @@ function BarChart({
1135
1161
  content: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartLegendContent, { iconType: "square" })
1136
1162
  }
1137
1163
  ) : null,
1138
- series.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1139
- import_recharts2.Bar,
1140
- {
1141
- dataKey: s.key,
1142
- name: s.label,
1143
- fill: colorForSeriesIndex(i, palette),
1144
- stackId: stacked ? "default" : s.key,
1145
- radius: barRadius(stacked, i, series.length),
1146
- children: resolvedShowValueLabels ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.LabelList, { dataKey: s.key, position: "top", style: CHART_VALUE_LABEL_STYLE }) : null
1147
- },
1148
- s.key
1149
- ))
1164
+ series.map((s, i) => {
1165
+ const isTopSegment = i === series.length - 1;
1166
+ const labelDataKey = stacked ? STACK_TOTAL_KEY : s.key;
1167
+ const showLabel = resolvedShowValueLabels && (!stacked || isTopSegment);
1168
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1169
+ import_recharts2.Bar,
1170
+ {
1171
+ dataKey: s.key,
1172
+ name: s.label,
1173
+ fill: colorForSeriesIndex(i, palette),
1174
+ stackId: stacked ? "default" : s.key,
1175
+ radius: barRadius(stacked, i, series.length),
1176
+ children: showLabel ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.LabelList, { dataKey: labelDataKey, position: "top", style: CHART_VALUE_LABEL_STYLE }) : null
1177
+ },
1178
+ s.key
1179
+ );
1180
+ })
1150
1181
  ] }) });
1151
1182
  }
1152
1183
  function barRadius(stacked, seriesIndex, seriesCount) {
@@ -1262,7 +1293,7 @@ function LineChart({
1262
1293
  tickFormatter: resolvedTickFormatter
1263
1294
  }
1264
1295
  ) : null,
1265
- showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
1296
+ showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.YAxis, { ...CHART_AXIS_PROPS, width: 40, tickFormatter: compactNumberTickFormatter }) : null,
1266
1297
  showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChartTooltipContent, {}) }) : null,
1267
1298
  resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1268
1299
  import_recharts3.Legend,
@@ -1320,6 +1351,42 @@ var LineChartVariantService = {
1320
1351
  // src/components/chart/pie-chart/pie-chart.tsx
1321
1352
  var import_react11 = require("react");
1322
1353
  var import_recharts4 = require("recharts");
1354
+
1355
+ // src/components/chart/pie-chart/utils.ts
1356
+ function mergedOthersLabel(leftoverRows, categoryKey, othersCategoryLabels) {
1357
+ const explicit = leftoverRows.find((row) => isOthersCategory(row[categoryKey], othersCategoryLabels));
1358
+ if (explicit) return String(explicit[categoryKey]);
1359
+ const fallback = othersCategoryLabels[0] ?? "Other";
1360
+ return fallback.charAt(0).toUpperCase() + fallback.slice(1);
1361
+ }
1362
+ function buildPieSlices(data, categoryKey, valueKey, othersCategoryLabels, palette) {
1363
+ const namedRows = [];
1364
+ const namedColors = [];
1365
+ const leftoverRows = [];
1366
+ for (const row of data) {
1367
+ const isLeftover = othersCategoryLabels.length > 0 && (isNoneCategory(row[categoryKey]) || isOthersCategory(row[categoryKey], othersCategoryLabels));
1368
+ if (isLeftover) {
1369
+ leftoverRows.push(row);
1370
+ } else {
1371
+ namedRows.push(row);
1372
+ namedColors.push(colorForSeriesIndex(namedRows.length - 1, palette));
1373
+ }
1374
+ }
1375
+ if (leftoverRows.length === 0) {
1376
+ return { orderedData: namedRows, sliceColors: namedColors };
1377
+ }
1378
+ const total = leftoverRows.reduce((sum, row) => sum + (Number(row[valueKey]) || 0), 0);
1379
+ const mergedRow = {
1380
+ [categoryKey]: mergedOthersLabel(leftoverRows, categoryKey, othersCategoryLabels),
1381
+ [valueKey]: total
1382
+ };
1383
+ return {
1384
+ orderedData: [...namedRows, mergedRow],
1385
+ sliceColors: [...namedColors, OTHERS_SLICE_COLOR]
1386
+ };
1387
+ }
1388
+
1389
+ // src/components/chart/pie-chart/pie-chart.tsx
1323
1390
  var import_jsx_runtime16 = require("react/jsx-runtime");
1324
1391
  function PieChart({
1325
1392
  data,
@@ -1338,23 +1405,7 @@ function PieChart({
1338
1405
  }) {
1339
1406
  const { orderedData, sliceColors } = (0, import_react11.useMemo)(() => {
1340
1407
  const coerced = coerceNumericColumns(data, [valueKey]);
1341
- const namedRows = [];
1342
- const namedColors = [];
1343
- const othersRows = [];
1344
- const othersColors = [];
1345
- for (const row of coerced) {
1346
- if (isOthersCategory(row[categoryKey], othersCategoryLabels)) {
1347
- othersRows.push(row);
1348
- othersColors.push(OTHERS_SLICE_COLOR);
1349
- } else {
1350
- namedRows.push(row);
1351
- namedColors.push(colorForSeriesIndex(namedRows.length - 1, palette));
1352
- }
1353
- }
1354
- return {
1355
- orderedData: [...namedRows, ...othersRows],
1356
- sliceColors: [...namedColors, ...othersColors]
1357
- };
1408
+ return buildPieSlices(coerced, categoryKey, valueKey, othersCategoryLabels, palette);
1358
1409
  }, [data, valueKey, categoryKey, othersCategoryLabels, palette]);
1359
1410
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_recharts4.PieChart, { margin: PIE_CHART_MARGIN, children: [
1360
1411
  showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_recharts4.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChartTooltipContent, {}) }) : null,