@smallwebco/tinypivot-react 1.0.10 → 1.0.11

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
@@ -146,6 +146,7 @@ function useExcelGrid(options) {
146
146
  const column = table.getColumn(columnId);
147
147
  if (column) {
148
148
  column.setFilterValue(values.length === 0 ? void 0 : values);
149
+ setColumnFilters(table.getState().columnFilters);
149
150
  }
150
151
  },
151
152
  [table]
@@ -153,6 +154,7 @@ function useExcelGrid(options) {
153
154
  const clearAllFilters = (0, import_react.useCallback)(() => {
154
155
  table.resetColumnFilters();
155
156
  setGlobalFilter("");
157
+ setColumnFilters([]);
156
158
  }, [table]);
157
159
  const getColumnFilterValues = (0, import_react.useCallback)(
158
160
  (columnId) => {
@@ -1262,10 +1264,14 @@ function PivotSkeleton({
1262
1264
  onAddColumnField,
1263
1265
  onRemoveColumnField,
1264
1266
  onAddValueField,
1265
- onRemoveValueField
1267
+ onRemoveValueField,
1268
+ onReorderRowFields,
1269
+ onReorderColumnFields
1266
1270
  }) {
1267
1271
  const { showWatermark, canUsePivot, isDemo } = useLicense();
1268
1272
  const [dragOverArea, setDragOverArea] = (0, import_react7.useState)(null);
1273
+ const [reorderDragSource, setReorderDragSource] = (0, import_react7.useState)(null);
1274
+ const [reorderDropTarget, setReorderDropTarget] = (0, import_react7.useState)(null);
1269
1275
  const [sortDirection, setSortDirection] = (0, import_react7.useState)("asc");
1270
1276
  const [sortTarget, setSortTarget] = (0, import_react7.useState)("row");
1271
1277
  const toggleSort = (0, import_react7.useCallback)((target = "row") => {
@@ -1370,6 +1376,72 @@ function PivotSkeleton({
1370
1376
  },
1371
1377
  [rowFields, columnFields, valueFields, onAddRowField, onRemoveRowField, onAddColumnField, onRemoveColumnField, onAddValueField, onRemoveValueField]
1372
1378
  );
1379
+ const handleChipDragStart = (0, import_react7.useCallback)(
1380
+ (zone, index, event) => {
1381
+ setReorderDragSource({ zone, index });
1382
+ event.dataTransfer.effectAllowed = "move";
1383
+ event.dataTransfer.setData("text/plain", `reorder:${zone}:${index}`);
1384
+ requestAnimationFrame(() => {
1385
+ setDragOverArea(null);
1386
+ });
1387
+ },
1388
+ []
1389
+ );
1390
+ const handleChipDragEnd = (0, import_react7.useCallback)(() => {
1391
+ setReorderDragSource(null);
1392
+ setReorderDropTarget(null);
1393
+ }, []);
1394
+ const handleChipDragOver = (0, import_react7.useCallback)(
1395
+ (zone, index, event) => {
1396
+ event.preventDefault();
1397
+ if (reorderDragSource && reorderDragSource.zone === zone) {
1398
+ event.dataTransfer.dropEffect = "move";
1399
+ setReorderDropTarget({ zone, index });
1400
+ }
1401
+ },
1402
+ [reorderDragSource]
1403
+ );
1404
+ const handleChipDragLeave = (0, import_react7.useCallback)(() => {
1405
+ setReorderDropTarget(null);
1406
+ }, []);
1407
+ const handleChipDrop = (0, import_react7.useCallback)(
1408
+ (zone, targetIndex, event) => {
1409
+ event.preventDefault();
1410
+ event.stopPropagation();
1411
+ if (!reorderDragSource || reorderDragSource.zone !== zone) {
1412
+ return;
1413
+ }
1414
+ const sourceIndex = reorderDragSource.index;
1415
+ if (sourceIndex === targetIndex) {
1416
+ setReorderDragSource(null);
1417
+ setReorderDropTarget(null);
1418
+ return;
1419
+ }
1420
+ const fields = zone === "row" ? [...rowFields] : [...columnFields];
1421
+ const [movedField] = fields.splice(sourceIndex, 1);
1422
+ fields.splice(targetIndex, 0, movedField);
1423
+ if (zone === "row") {
1424
+ onReorderRowFields(fields);
1425
+ } else {
1426
+ onReorderColumnFields(fields);
1427
+ }
1428
+ setReorderDragSource(null);
1429
+ setReorderDropTarget(null);
1430
+ },
1431
+ [reorderDragSource, rowFields, columnFields, onReorderRowFields, onReorderColumnFields]
1432
+ );
1433
+ const isChipDragSource = (0, import_react7.useCallback)(
1434
+ (zone, index) => {
1435
+ return reorderDragSource?.zone === zone && reorderDragSource?.index === index;
1436
+ },
1437
+ [reorderDragSource]
1438
+ );
1439
+ const isChipDropTarget = (0, import_react7.useCallback)(
1440
+ (zone, index) => {
1441
+ return reorderDropTarget?.zone === zone && reorderDropTarget?.index === index;
1442
+ },
1443
+ [reorderDropTarget]
1444
+ );
1373
1445
  const currentFontSize = fontSize;
1374
1446
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1375
1447
  "div",
@@ -1468,17 +1540,34 @@ function PivotSkeleton({
1468
1540
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-zone-label", children: "Rows" })
1469
1541
  ] }),
1470
1542
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "vpg-zone-chips", children: [
1471
- rowFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "vpg-mini-chip vpg-row-chip", children: [
1472
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-mini-name", children: field }),
1473
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1474
- "button",
1475
- {
1476
- className: "vpg-mini-remove",
1477
- onClick: () => onRemoveRowField(field),
1478
- children: "\xD7"
1479
- }
1480
- )
1481
- ] }, field)),
1543
+ rowFields.map((field, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1544
+ "div",
1545
+ {
1546
+ className: `vpg-mini-chip vpg-row-chip ${isChipDragSource("row", idx) ? "vpg-chip-dragging" : ""} ${isChipDropTarget("row", idx) ? "vpg-chip-drop-target" : ""}`,
1547
+ draggable: true,
1548
+ onDragStart: (e) => handleChipDragStart("row", idx, e),
1549
+ onDragEnd: handleChipDragEnd,
1550
+ onDragOver: (e) => handleChipDragOver("row", idx, e),
1551
+ onDragLeave: handleChipDragLeave,
1552
+ onDrop: (e) => handleChipDrop("row", idx, e),
1553
+ children: [
1554
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-drag-handle", children: "\u22EE\u22EE" }),
1555
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-mini-name", children: field }),
1556
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1557
+ "button",
1558
+ {
1559
+ className: "vpg-mini-remove",
1560
+ onClick: (e) => {
1561
+ e.stopPropagation();
1562
+ onRemoveRowField(field);
1563
+ },
1564
+ children: "\xD7"
1565
+ }
1566
+ )
1567
+ ]
1568
+ },
1569
+ field
1570
+ )),
1482
1571
  rowFields.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-zone-hint", children: "Drop here" })
1483
1572
  ] })
1484
1573
  ]
@@ -1497,17 +1586,34 @@ function PivotSkeleton({
1497
1586
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-zone-label", children: "Columns" })
1498
1587
  ] }),
1499
1588
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "vpg-zone-chips", children: [
1500
- columnFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "vpg-mini-chip vpg-column-chip", children: [
1501
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-mini-name", children: field }),
1502
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1503
- "button",
1504
- {
1505
- className: "vpg-mini-remove",
1506
- onClick: () => onRemoveColumnField(field),
1507
- children: "\xD7"
1508
- }
1509
- )
1510
- ] }, field)),
1589
+ columnFields.map((field, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1590
+ "div",
1591
+ {
1592
+ className: `vpg-mini-chip vpg-column-chip ${isChipDragSource("column", idx) ? "vpg-chip-dragging" : ""} ${isChipDropTarget("column", idx) ? "vpg-chip-drop-target" : ""}`,
1593
+ draggable: true,
1594
+ onDragStart: (e) => handleChipDragStart("column", idx, e),
1595
+ onDragEnd: handleChipDragEnd,
1596
+ onDragOver: (e) => handleChipDragOver("column", idx, e),
1597
+ onDragLeave: handleChipDragLeave,
1598
+ onDrop: (e) => handleChipDrop("column", idx, e),
1599
+ children: [
1600
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-drag-handle", children: "\u22EE\u22EE" }),
1601
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-mini-name", children: field }),
1602
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1603
+ "button",
1604
+ {
1605
+ className: "vpg-mini-remove",
1606
+ onClick: (e) => {
1607
+ e.stopPropagation();
1608
+ onRemoveColumnField(field);
1609
+ },
1610
+ children: "\xD7"
1611
+ }
1612
+ )
1613
+ ]
1614
+ },
1615
+ field
1616
+ )),
1511
1617
  columnFields.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vpg-zone-hint", children: "Drop here" })
1512
1618
  ] })
1513
1619
  ]