@smallwebco/tinypivot-react 1.0.27 → 1.0.28

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
@@ -464,9 +464,7 @@ function usePivotTable(data) {
464
464
  }
465
465
  }, [availableFields, requirePro]);
466
466
  const addCalculatedField = (0, import_react3.useCallback)((field) => {
467
- console.log("[usePivotTable] addCalculatedField called with:", field);
468
467
  setCalculatedFields((prev) => {
469
- console.log("[usePivotTable] Previous calculatedFields:", prev);
470
468
  const existing = prev.findIndex((f) => f.id === field.id);
471
469
  let updated;
472
470
  if (existing >= 0) {
@@ -474,7 +472,6 @@ function usePivotTable(data) {
474
472
  } else {
475
473
  updated = [...prev, field];
476
474
  }
477
- console.log("[usePivotTable] Updated calculatedFields:", updated);
478
475
  (0, import_tinypivot_core3.saveCalculatedFields)(updated);
479
476
  return updated;
480
477
  });
@@ -1044,15 +1041,11 @@ function CalculatedFieldModal({
1044
1041
  });
1045
1042
  }, []);
1046
1043
  const handleSave = (0, import_react6.useCallback)(() => {
1047
- console.log("[CalculatedFieldModal] handleSave called");
1048
- console.log("[CalculatedFieldModal] name:", name, "formula:", formula);
1049
- console.log("[CalculatedFieldModal] availableFields:", availableFields);
1050
1044
  if (!name.trim()) {
1051
1045
  setError("Name is required");
1052
1046
  return;
1053
1047
  }
1054
1048
  const validationResult = (0, import_tinypivot_core5.validateSimpleFormula)(formula, availableFields);
1055
- console.log("[CalculatedFieldModal] validationResult:", validationResult);
1056
1049
  if (validationResult) {
1057
1050
  setError(validationResult);
1058
1051
  return;
@@ -1064,7 +1057,6 @@ function CalculatedFieldModal({
1064
1057
  formatAs,
1065
1058
  decimals
1066
1059
  };
1067
- console.log("[CalculatedFieldModal] Calling onSave with:", field);
1068
1060
  onSave(field);
1069
1061
  onClose();
1070
1062
  }, [name, formula, formatAs, decimals, existingField, availableFields, onSave, onClose]);
@@ -1225,9 +1217,8 @@ function PivotConfig({
1225
1217
  [availableFields]
1226
1218
  );
1227
1219
  const calculatedFieldsAsStats = (0, import_react7.useMemo)(() => {
1228
- console.log("[PivotConfig] calculatedFields prop:", calculatedFields);
1229
1220
  if (!calculatedFields) return [];
1230
- const stats = calculatedFields.map((calc) => ({
1221
+ return calculatedFields.map((calc) => ({
1231
1222
  field: `calc:${calc.id}`,
1232
1223
  type: "number",
1233
1224
  uniqueCount: 0,
@@ -1237,17 +1228,11 @@ function PivotConfig({
1237
1228
  calcName: calc.name,
1238
1229
  calcFormula: calc.formula
1239
1230
  }));
1240
- console.log("[PivotConfig] calculatedFieldsAsStats:", stats);
1241
- return stats;
1242
1231
  }, [calculatedFields]);
1243
- const allAvailableFields = (0, import_react7.useMemo)(() => {
1244
- const all = [
1245
- ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1246
- ...calculatedFieldsAsStats
1247
- ];
1248
- console.log("[PivotConfig] allAvailableFields:", all.length, "items, calc fields:", calculatedFieldsAsStats.length);
1249
- return all;
1250
- }, [availableFields, calculatedFieldsAsStats]);
1232
+ const allAvailableFields = (0, import_react7.useMemo)(() => [
1233
+ ...availableFields.map((f) => ({ ...f, isCalculated: false })),
1234
+ ...calculatedFieldsAsStats
1235
+ ], [availableFields, calculatedFieldsAsStats]);
1251
1236
  const assignedFields = (0, import_react7.useMemo)(() => {
1252
1237
  const rowSet = new Set(rowFields);
1253
1238
  const colSet = new Set(columnFields);
@@ -1329,14 +1314,9 @@ function PivotConfig({
1329
1314
  setShowCalcModal(true);
1330
1315
  }, []);
1331
1316
  const handleSaveCalcField = (0, import_react7.useCallback)((field) => {
1332
- console.log("[PivotConfig] handleSaveCalcField called with:", field);
1333
- console.log("[PivotConfig] editingCalcField:", editingCalcField);
1334
- console.log("[PivotConfig] onAddCalculatedField exists:", !!onAddCalculatedField);
1335
1317
  if (editingCalcField && onUpdateCalculatedField) {
1336
- console.log("[PivotConfig] Calling onUpdateCalculatedField");
1337
1318
  onUpdateCalculatedField(field);
1338
1319
  } else if (onAddCalculatedField) {
1339
- console.log("[PivotConfig] Calling onAddCalculatedField");
1340
1320
  onAddCalculatedField(field);
1341
1321
  }
1342
1322
  setShowCalcModal(false);
@@ -1588,6 +1568,7 @@ function PivotSkeleton({
1588
1568
  rowFields,
1589
1569
  columnFields,
1590
1570
  valueFields,
1571
+ calculatedFields,
1591
1572
  isConfigured,
1592
1573
  draggingField,
1593
1574
  pivotResult,
@@ -1605,6 +1586,17 @@ function PivotSkeleton({
1605
1586
  onReorderColumnFields
1606
1587
  }) {
1607
1588
  const { showWatermark, canUsePivot, isDemo } = useLicense();
1589
+ const getValueFieldDisplayName = (0, import_react8.useCallback)((field) => {
1590
+ if (field.startsWith("calc:")) {
1591
+ const calcId = field.replace("calc:", "");
1592
+ const calcField = calculatedFields?.find((c) => c.id === calcId);
1593
+ return calcField?.name || field;
1594
+ }
1595
+ return field;
1596
+ }, [calculatedFields]);
1597
+ const isCalculatedField = (0, import_react8.useCallback)((field) => {
1598
+ return field.startsWith("calc:");
1599
+ }, []);
1608
1600
  const [dragOverArea, setDragOverArea] = (0, import_react8.useState)(null);
1609
1601
  const [reorderDragSource, setReorderDragSource] = (0, import_react8.useState)(null);
1610
1602
  const [reorderDropTarget, setReorderDropTarget] = (0, import_react8.useState)(null);
@@ -1646,7 +1638,7 @@ function PivotSkeleton({
1646
1638
  if (!pivotResult || pivotResult.headers.length === 0) {
1647
1639
  return [
1648
1640
  valueFields.map((vf) => ({
1649
- label: `${vf.field} (${(0, import_tinypivot_core7.getAggregationLabel)(vf.aggregation)})`,
1641
+ label: `${getValueFieldDisplayName(vf.field)} (${(0, import_tinypivot_core7.getAggregationLabel)(vf.aggregation)})`,
1650
1642
  colspan: 1
1651
1643
  }))
1652
1644
  ];
@@ -2014,10 +2006,10 @@ function PivotSkeleton({
2014
2006
  valueFields.map((vf) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2015
2007
  "div",
2016
2008
  {
2017
- className: "vpg-mini-chip vpg-value-chip",
2009
+ className: `vpg-mini-chip vpg-value-chip${isCalculatedField(vf.field) ? " vpg-calc-chip" : ""}`,
2018
2010
  children: [
2019
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "vpg-agg-symbol", children: (0, import_tinypivot_core7.getAggregationSymbol)(vf.aggregation) }),
2020
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "vpg-mini-name", children: vf.field }),
2011
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "vpg-agg-symbol", children: isCalculatedField(vf.field) ? "\u0192" : (0, import_tinypivot_core7.getAggregationSymbol)(vf.aggregation) }),
2012
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "vpg-mini-name", children: getValueFieldDisplayName(vf.field) }),
2021
2013
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2022
2014
  "button",
2023
2015
  {
@@ -3054,6 +3046,7 @@ function DataGrid({
3054
3046
  rowFields: pivotRowFields,
3055
3047
  columnFields: pivotColumnFields,
3056
3048
  valueFields: pivotValueFields,
3049
+ calculatedFields: pivotCalculatedFields,
3057
3050
  isConfigured: pivotIsConfigured,
3058
3051
  draggingField,
3059
3052
  pivotResult,