@canvas-components/react-pivot-table 0.2.2 → 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';
@@ -368,7 +368,7 @@ function PivotFieldPanel(props) {
368
368
  }
369
369
  )
370
370
  ] }),
371
- /* @__PURE__ */ jsxs("div", { className: "react-pivot-field-panel__field-list", children: [
371
+ /* @__PURE__ */ jsxs("div", { className: "react-pivot-field-panel__field-list canvas-react-scrollbar", children: [
372
372
  visibleFields.map((field) => {
373
373
  const fieldKey = resolvePivotDimensionKey(field);
374
374
  const area = findPivotFieldArea(props.layout, fieldKey);
@@ -495,7 +495,7 @@ function FieldArea(props) {
495
495
  /* @__PURE__ */ jsxs(
496
496
  "div",
497
497
  {
498
- className: "react-pivot-field-panel__area",
498
+ className: "react-pivot-field-panel__area canvas-react-scrollbar",
499
499
  "data-dragging": props.dragging || void 0,
500
500
  onDragOver: (event) => event.preventDefault(),
501
501
  onDragEnter: props.onDragEnter,
@@ -1175,19 +1175,26 @@ function SettingsIcon() {
1175
1175
  // src/features/chart/pivot-chart-panel.css
1176
1176
  styleInject('.react-pivot-chart-panel {\n display: flex;\n width: 100%;\n min-width: 0;\n height: 100%;\n min-height: 0;\n flex-direction: column;\n gap: 8px;\n padding: 0;\n overflow: auto;\n background: #fff;\n box-sizing: border-box;\n}\n.react-pivot-chart-card {\n display: flex;\n min-width: 0;\n min-height: 240px;\n flex: 0 0 260px;\n flex-direction: column;\n overflow: hidden;\n border-radius: 0;\n background: #fff;\n box-sizing: border-box;\n}\n.react-pivot-chart-card:only-child {\n min-height: 240px;\n flex: 1 1 auto;\n}\n.react-pivot-chart-card__header {\n display: flex;\n height: 42px;\n flex: 0 0 42px;\n align-items: center;\n justify-content: space-between;\n padding: 0 10px 0 14px;\n border-bottom: 1px solid #edf0f2;\n color: #1f2329;\n font-size: 13px;\n box-sizing: border-box;\n}\n.react-pivot-chart-card__remove {\n display: inline-flex;\n width: 24px;\n height: 24px;\n align-items: center;\n justify-content: center;\n padding: 0;\n border: 0;\n background: transparent;\n color: #646a73;\n cursor: pointer;\n font: 18px/24px "Segoe UI", sans-serif;\n}\n.react-pivot-chart-card__remove:hover {\n background: #f2f3f5;\n color: #d14343;\n}\n.react-pivot-chart-card__canvas {\n min-width: 0;\n min-height: 0;\n flex: 1 1 auto;\n}\n.react-pivot-chart-card__empty {\n display: grid;\n min-height: 0;\n flex: 1 1 auto;\n place-items: center;\n color: #8f959e;\n font-size: 12px;\n}\n');
1177
1177
  function PivotChartPanel(props) {
1178
- return /* @__PURE__ */ jsx("section", { className: "react-pivot-chart-panel", "aria-label": "\u900F\u89C6\u56FE\u8868", children: props.charts.map((chart, index) => /* @__PURE__ */ jsx(
1179
- PivotChartCard,
1178
+ return /* @__PURE__ */ jsx(
1179
+ "section",
1180
1180
  {
1181
- chart,
1182
- index,
1183
- model: props.model,
1184
- rows: props.rows,
1185
- columns: props.columns,
1186
- indicators: props.indicators,
1187
- onRemove: props.onRemove
1188
- },
1189
- chart.id
1190
- )) });
1181
+ className: "react-pivot-chart-panel canvas-react-scrollbar",
1182
+ "aria-label": "\u900F\u89C6\u56FE\u8868",
1183
+ children: props.charts.map((chart, index) => /* @__PURE__ */ jsx(
1184
+ PivotChartCard,
1185
+ {
1186
+ chart,
1187
+ index,
1188
+ model: props.model,
1189
+ rows: props.rows,
1190
+ columns: props.columns,
1191
+ indicators: props.indicators,
1192
+ onRemove: props.onRemove
1193
+ },
1194
+ chart.id
1195
+ ))
1196
+ }
1197
+ );
1191
1198
  }
1192
1199
  function PivotChartCard(props) {
1193
1200
  const option = useMemo(
@@ -1259,6 +1266,7 @@ function ReactPivotTableInner(props, ref) {
1259
1266
  null
1260
1267
  );
1261
1268
  const chartIdRef = useRef(0);
1269
+ const layoutRevisionRef = useRef(0);
1262
1270
  const [internalLayout, setInternalLayout] = useState(
1263
1271
  () => customizationOptions?.defaultLayout ?? createEmptyPivotFieldLayout()
1264
1272
  );
@@ -1364,7 +1372,13 @@ function ReactPivotTableInner(props, ref) {
1364
1372
  setCharts((current) => current.filter((chart) => chart.id !== chartId));
1365
1373
  };
1366
1374
  const applyLayout = (next) => {
1367
- 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
+ }
1368
1382
  customizationOptions?.onLayoutChange?.(next);
1369
1383
  };
1370
1384
  const moveField = (fieldKey, area, index, sourceArea) => {
@@ -1412,6 +1426,22 @@ function ReactPivotTableInner(props, ref) {
1412
1426
  table.updateOptions(options);
1413
1427
  refreshChartModel();
1414
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]);
1415
1445
  useEffect(() => {
1416
1446
  if (customizationOptions?.panelWidth != null) {
1417
1447
  setFieldPanelWidth(customizationOptions.panelWidth);