@canvas-components/react-pivot-table 0.2.3 → 0.2.4

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.d.cts CHANGED
@@ -14,6 +14,8 @@ interface ReactPivotTableCustomizationOptions<RecordType = Record<string, unknow
14
14
  layout?: PivotFieldLayout;
15
15
  /** 非受控字段区域初始布局。 */
16
16
  defaultLayout?: PivotFieldLayout;
17
+ /** 非受控字段布局的 IndexedDB 持久化键。 */
18
+ storageKey?: string;
17
19
  /** 面板宽度。 */
18
20
  panelWidth?: number;
19
21
  onOpenChange?: (open: boolean) => void;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@ interface ReactPivotTableCustomizationOptions<RecordType = Record<string, unknow
14
14
  layout?: PivotFieldLayout;
15
15
  /** 非受控字段区域初始布局。 */
16
16
  defaultLayout?: PivotFieldLayout;
17
+ /** 非受控字段布局的 IndexedDB 持久化键。 */
18
+ storageKey?: string;
17
19
  /** 面板宽度。 */
18
20
  panelWidth?: number;
19
21
  onOpenChange?: (open: boolean) => void;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle } from 'react';
2
- import { createEmptyPivotFieldLayout, createPivotFieldCatalog, resolvePivotDimensionKey, resolvePivotFieldLayoutOptions, PivotTable, getValueByDataIndex, resolvePivotDimensionTitle, findPivotFieldArea, removePivotField, movePivotField, resolvePivotValueFieldTitle, createPivotCellKey } from '@canvas-components/pivot-table';
2
+ import { createEmptyPivotFieldLayout, createPivotFieldCatalog, resolvePivotDimensionKey, resolvePivotFieldLayoutOptions, PivotTable, loadPivotFieldLayout, getValueByDataIndex, resolvePivotDimensionTitle, findPivotFieldArea, removePivotField, movePivotField, resolvePivotValueFieldTitle, savePivotFieldLayout, createPivotCellKey } from '@canvas-components/pivot-table';
3
3
  import { ReactResizablePanels, ReactFilterPanel, ReactPopup, ReactCheckbox, ReactInput, ReactSelect, ReactInputNumber } from '@canvas-components/react-components';
4
4
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
5
5
  import { createPortal } from 'react-dom';
@@ -1266,6 +1266,7 @@ function ReactPivotTableInner(props, ref) {
1266
1266
  null
1267
1267
  );
1268
1268
  const chartIdRef = useRef(0);
1269
+ const layoutRevisionRef = useRef(0);
1269
1270
  const [internalLayout, setInternalLayout] = useState(
1270
1271
  () => customizationOptions?.defaultLayout ?? createEmptyPivotFieldLayout()
1271
1272
  );
@@ -1371,7 +1372,13 @@ function ReactPivotTableInner(props, ref) {
1371
1372
  setCharts((current) => current.filter((chart) => chart.id !== chartId));
1372
1373
  };
1373
1374
  const applyLayout = (next) => {
1374
- if (customizationOptions?.layout === void 0) setInternalLayout(next);
1375
+ if (customizationOptions?.layout === void 0) {
1376
+ layoutRevisionRef.current += 1;
1377
+ setInternalLayout(next);
1378
+ if (customizationOptions?.storageKey) {
1379
+ void savePivotFieldLayout(customizationOptions.storageKey, next);
1380
+ }
1381
+ }
1375
1382
  customizationOptions?.onLayoutChange?.(next);
1376
1383
  };
1377
1384
  const moveField = (fieldKey, area, index, sourceArea) => {
@@ -1419,6 +1426,22 @@ function ReactPivotTableInner(props, ref) {
1419
1426
  table.updateOptions(options);
1420
1427
  refreshChartModel();
1421
1428
  }, [options]);
1429
+ useEffect(() => {
1430
+ const storageKey = customizationOptions?.storageKey;
1431
+ if (!storageKey || customizationOptions?.layout !== void 0) return;
1432
+ let active = true;
1433
+ const revision = layoutRevisionRef.current;
1434
+ void loadPivotFieldLayout(storageKey).then((storedLayout) => {
1435
+ if (!active || !storedLayout || layoutRevisionRef.current !== revision) {
1436
+ return;
1437
+ }
1438
+ setInternalLayout(storedLayout);
1439
+ customizationOptions?.onLayoutChange?.(storedLayout);
1440
+ });
1441
+ return () => {
1442
+ active = false;
1443
+ };
1444
+ }, [customizationOptions?.layout, customizationOptions?.storageKey]);
1422
1445
  useEffect(() => {
1423
1446
  if (customizationOptions?.panelWidth != null) {
1424
1447
  setFieldPanelWidth(customizationOptions.panelWidth);