@carto/ps-react-ui 5.0.0-widgets.1 → 5.0.0-widgets.10

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 (110) hide show
  1. package/dist/error-B2IJ9d2h.js +38 -0
  2. package/dist/error-B2IJ9d2h.js.map +1 -0
  3. package/dist/no-data-C54XJt13.js +61 -0
  4. package/dist/no-data-C54XJt13.js.map +1 -0
  5. package/dist/note-Clng2ej6.js +124 -0
  6. package/dist/note-Clng2ej6.js.map +1 -0
  7. package/dist/{row-C_m1ovHv.js → row-DrHwXNvF.js} +2 -2
  8. package/dist/{row-C_m1ovHv.js.map → row-DrHwXNvF.js.map} +1 -1
  9. package/dist/{series-6xp-KQ0S.js → series-Do02NQUF.js} +3 -3
  10. package/dist/{series-6xp-KQ0S.js.map → series-Do02NQUF.js.map} +1 -1
  11. package/dist/types/widgets/actions/searcher/searcher.d.ts +1 -1
  12. package/dist/types/widgets/actions/searcher/types.d.ts +2 -0
  13. package/dist/types/widgets/bar/config.d.ts +1 -1
  14. package/dist/types/widgets/bar/types.d.ts +1 -1
  15. package/dist/types/widgets/category/config.d.ts +2 -1
  16. package/dist/types/widgets/category/types.d.ts +1 -0
  17. package/dist/types/widgets/echart/types.d.ts +1 -0
  18. package/dist/types/widgets/error/error.d.ts +2 -0
  19. package/dist/types/widgets/error/index.d.ts +2 -0
  20. package/dist/types/widgets/error/types.d.ts +12 -0
  21. package/dist/types/widgets/formula/config.d.ts +1 -1
  22. package/dist/types/widgets/histogram/config.d.ts +1 -1
  23. package/dist/types/widgets/histogram/types.d.ts +1 -1
  24. package/dist/types/widgets/index.d.ts +6 -0
  25. package/dist/types/widgets/loader/index.d.ts +3 -0
  26. package/dist/types/widgets/loader/loader.d.ts +2 -0
  27. package/dist/types/widgets/{root → loader}/types.d.ts +1 -1
  28. package/dist/types/widgets/loader/utils.d.ts +1 -0
  29. package/dist/types/widgets/markdown/types.d.ts +1 -1
  30. package/dist/types/widgets/no-data/index.d.ts +2 -0
  31. package/dist/types/widgets/no-data/no-data.d.ts +35 -0
  32. package/dist/types/widgets/no-data/style.d.ts +6 -0
  33. package/dist/types/widgets/no-data/types.d.ts +67 -0
  34. package/dist/types/widgets/note/index.d.ts +2 -2
  35. package/dist/types/widgets/note/note.d.ts +2 -2
  36. package/dist/types/widgets/note/types.d.ts +1 -1
  37. package/dist/types/widgets/pie/config.d.ts +1 -1
  38. package/dist/types/widgets/pie/types.d.ts +1 -1
  39. package/dist/types/widgets/scatterplot/config.d.ts +1 -1
  40. package/dist/types/widgets/scatterplot/types.d.ts +1 -1
  41. package/dist/types/widgets/selection-summary/index.d.ts +2 -2
  42. package/dist/types/widgets/selection-summary/selection-summary.d.ts +2 -2
  43. package/dist/types/widgets/selection-summary/types.d.ts +1 -1
  44. package/dist/types/widgets/spread/config.d.ts +1 -1
  45. package/dist/types/widgets/stores/types.d.ts +4 -76
  46. package/dist/types/widgets/stores/widget-store.d.ts +1 -1
  47. package/dist/types/widgets/subheader/index.d.ts +2 -2
  48. package/dist/types/widgets/subheader/subheader.d.ts +2 -2
  49. package/dist/types/widgets/subheader/types.d.ts +1 -1
  50. package/dist/types/widgets/table/config.d.ts +8 -2
  51. package/dist/types/widgets/table/hooks/index.d.ts +2 -2
  52. package/dist/types/widgets/table/hooks/use-pagination.d.ts +4 -16
  53. package/dist/types/widgets/table/hooks/use-selection.d.ts +3 -5
  54. package/dist/types/widgets/table/hooks/use-sort.d.ts +7 -14
  55. package/dist/types/widgets/table/index.d.ts +2 -2
  56. package/dist/types/widgets/table/table-ui.d.ts +3 -3
  57. package/dist/types/widgets/table/types.d.ts +14 -19
  58. package/dist/types/widgets/timeseries/config.d.ts +1 -1
  59. package/dist/types/widgets/timeseries/types.d.ts +1 -1
  60. package/dist/widget-store-CB6Trp_0.js +131 -0
  61. package/dist/widget-store-CB6Trp_0.js.map +1 -0
  62. package/dist/widgets/actions.js +588 -579
  63. package/dist/widgets/actions.js.map +1 -1
  64. package/dist/widgets/bar.js +8 -7
  65. package/dist/widgets/bar.js.map +1 -1
  66. package/dist/widgets/category.js +135 -128
  67. package/dist/widgets/category.js.map +1 -1
  68. package/dist/widgets/echart.js +1 -1
  69. package/dist/widgets/error.js +5 -0
  70. package/dist/widgets/error.js.map +1 -0
  71. package/dist/widgets/formula.js +19 -18
  72. package/dist/widgets/formula.js.map +1 -1
  73. package/dist/widgets/histogram.js +54 -53
  74. package/dist/widgets/histogram.js.map +1 -1
  75. package/dist/widgets/loader.js +57 -0
  76. package/dist/widgets/loader.js.map +1 -0
  77. package/dist/widgets/markdown.js +1 -1
  78. package/dist/widgets/no-data.js +5 -0
  79. package/dist/widgets/no-data.js.map +1 -0
  80. package/dist/widgets/note.js +2 -121
  81. package/dist/widgets/note.js.map +1 -1
  82. package/dist/widgets/pie.js +8 -7
  83. package/dist/widgets/pie.js.map +1 -1
  84. package/dist/widgets/range.js +2 -2
  85. package/dist/widgets/scatterplot.js +8 -7
  86. package/dist/widgets/scatterplot.js.map +1 -1
  87. package/dist/widgets/selection-summary.js +3 -3
  88. package/dist/widgets/selection-summary.js.map +1 -1
  89. package/dist/widgets/skeleton-loader.js +1 -1
  90. package/dist/widgets/spread.js +20 -19
  91. package/dist/widgets/spread.js.map +1 -1
  92. package/dist/widgets/stores.js +1 -1
  93. package/dist/widgets/subheader.js +6 -6
  94. package/dist/widgets/subheader.js.map +1 -1
  95. package/dist/widgets/table.js +562 -570
  96. package/dist/widgets/table.js.map +1 -1
  97. package/dist/widgets/timeseries.js +8 -7
  98. package/dist/widgets/timeseries.js.map +1 -1
  99. package/dist/widgets/wrapper.js +1 -1
  100. package/dist/widgets.js +8 -2
  101. package/dist/widgets.js.map +1 -1
  102. package/package.json +12 -4
  103. package/dist/types/widgets/root/index.d.ts +0 -3
  104. package/dist/types/widgets/root/root.d.ts +0 -2
  105. package/dist/types/widgets/root/style.d.ts +0 -8
  106. package/dist/types/widgets/root/utils.d.ts +0 -1
  107. package/dist/widget-store-DNyVElxd.js +0 -190
  108. package/dist/widget-store-DNyVElxd.js.map +0 -1
  109. package/dist/widgets/root.js +0 -68
  110. package/dist/widgets/root.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import { NoteProps } from './types';
2
- export declare function Note({ children, labels }: NoteProps): import("react/jsx-runtime").JSX.Element | null;
1
+ import { WidgetNoteProps } from './types';
2
+ export declare function WidgetNote({ children, labels, }: WidgetNoteProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,5 +1,5 @@
1
1
  import { MarkdownComponentProps } from '../markdown';
2
- export interface NoteProps {
2
+ export interface WidgetNoteProps {
3
3
  children: MarkdownComponentProps['children'];
4
4
  labels?: {
5
5
  showMore?: string;
@@ -1,5 +1,5 @@
1
1
  import { PieConfig, PieWidgetConfig, PieWidgetData } from './types';
2
2
  import { DownloadItem } from '../actions';
3
- import { ConfigProps } from '../root/types';
3
+ import { ConfigProps } from '../loader/types';
4
4
  export declare function pieDownloadConfig({ refUI, }: ConfigProps): DownloadItem<PieWidgetData>[];
5
5
  export declare function pieConfig(props: PieConfig): PieWidgetConfig;
@@ -1,6 +1,6 @@
1
1
  import { EchartWidgetData, EchartWidgetState } from '../echart';
2
2
  import { EchartWidgetOptionProps, EchartWidgetProps } from '../echart/types';
3
- import { ConfigProps } from '../root';
3
+ import { ConfigProps } from '../loader';
4
4
  export type PieWidgetData = EchartWidgetData;
5
5
  export type PieWidgetState = EchartWidgetState;
6
6
  export type PieWidgetConfig = EchartWidgetProps & {
@@ -1,5 +1,5 @@
1
1
  import { ScatterplotConfig, ScatterplotWidgetConfig, ScatterplotWidgetData } from './types';
2
2
  import { DownloadItem } from '../actions';
3
- import { ConfigProps } from '../root/types';
3
+ import { ConfigProps } from '../loader/types';
4
4
  export declare function scatterplotDownloadConfig({ refUI, }: ConfigProps): DownloadItem<ScatterplotWidgetData>[];
5
5
  export declare function scatterplotConfig(props: ScatterplotConfig): ScatterplotWidgetConfig;
@@ -1,6 +1,6 @@
1
1
  import { EchartWidgetState } from '../echart';
2
2
  import { EchartWidgetOptionProps, EchartWidgetProps } from '../echart/types';
3
- import { ConfigProps } from '../root';
3
+ import { ConfigProps } from '../loader';
4
4
  export type ScatterplotWidgetData = [number, number][][];
5
5
  export type ScatterplotWidgetState = EchartWidgetState;
6
6
  export type ScatterplotWidgetConfig = EchartWidgetProps & {
@@ -1,2 +1,2 @@
1
- export { SelectionSummary } from './selection-summary';
2
- export type { SelectedProps, SelectionSummaryLabels } from './types';
1
+ export { WidgetSelectionSummary } from './selection-summary';
2
+ export type { WidgetSelectionSummaryProps, SelectionSummaryLabels, } from './types';
@@ -1,2 +1,2 @@
1
- import { SelectedProps } from './types';
2
- export declare function SelectionSummary({ selections, onClear, labels, }: SelectedProps): import("react/jsx-runtime").JSX.Element;
1
+ import { WidgetSelectionSummaryProps } from './types';
2
+ export declare function WidgetSelectionSummary({ selections, onClear, labels, }: WidgetSelectionSummaryProps): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- export interface SelectedProps {
1
+ export interface WidgetSelectionSummaryProps {
2
2
  selections: number;
3
3
  onClear?: () => void;
4
4
  labels?: Partial<SelectionSummaryLabels>;
@@ -1,5 +1,5 @@
1
1
  import { DownloadItem } from '../actions';
2
- import { ConfigProps } from '../root/types';
2
+ import { ConfigProps } from '../loader/types';
3
3
  import { SpreadWidgetConfig, SpreadWidgetData } from './types';
4
4
  import { SeriesConfig } from '../formula/types';
5
5
  export interface SpreadConfigProps {
@@ -1,55 +1,4 @@
1
1
  import { RefObject } from 'react';
2
- /**
3
- * Sort direction for table columns
4
- */
5
- export type StoreSortDirection = 'asc' | 'desc';
6
- /**
7
- * Pagination mode for tables
8
- */
9
- export type StorePaginationMode = 'local' | 'remote';
10
- /**
11
- * Sort mode for tables
12
- */
13
- export type StoreSortMode = 'local' | 'remote';
14
- /**
15
- * Table pagination state stored in widget store
16
- */
17
- export interface TablePaginationStoreState {
18
- /** Current page (0-indexed) */
19
- page: number;
20
- /** Rows per page */
21
- rowsPerPage: number;
22
- /** Available rows per page options */
23
- rowsPerPageOptions: number[];
24
- /** Pagination mode: local or remote */
25
- mode: StorePaginationMode;
26
- }
27
- /**
28
- * Table sort state stored in widget store
29
- */
30
- export interface TableSortStoreState {
31
- /** Column ID being sorted */
32
- columnId: string | null;
33
- /** Sort direction */
34
- direction: StoreSortDirection;
35
- /** Sort mode: local or remote */
36
- mode: StoreSortMode;
37
- }
38
- /**
39
- * Table selection state stored in widget store
40
- */
41
- export interface TableSelectionStoreState {
42
- /** Set of selected row IDs */
43
- selectedIds: Set<string | number>;
44
- }
45
- /**
46
- * Combined table state for widget store
47
- */
48
- export interface TableStoreState {
49
- pagination?: TablePaginationStoreState;
50
- sort?: TableSortStoreState;
51
- selection?: TableSelectionStoreState;
52
- }
53
2
  export interface WidgetsStoreProps {
54
3
  /** Unique identifier for the widget */
55
4
  id: string;
@@ -62,7 +11,10 @@ export interface WidgetsStoreProps {
62
11
  /** Fetching state (e.g., for async data) */
63
12
  isFetching: boolean;
64
13
  /** Error message if any */
65
- error?: string;
14
+ error?: {
15
+ title?: string;
16
+ message?: string;
17
+ };
66
18
  /** Whether widget is visible */
67
19
  visible?: boolean;
68
20
  /** Reference to the widget ui instance */
@@ -169,30 +121,6 @@ export interface WidgetStoreActions {
169
121
  * @returns Widget state or undefined if not found
170
122
  */
171
123
  getWidget: <T extends WidgetState = WidgetState>(id: WidgetState['id']) => T | undefined;
172
- /**
173
- * Set table pagination state for a widget
174
- * @param id - Widget ID
175
- * @param pagination - Partial pagination state to merge
176
- */
177
- setTablePagination: (id: WidgetState['id'], pagination: Partial<TablePaginationStoreState>) => void;
178
- /**
179
- * Set table sort state for a widget
180
- * @param id - Widget ID
181
- * @param sort - Partial sort state to merge
182
- */
183
- setTableSort: (id: WidgetState['id'], sort: Partial<TableSortStoreState>) => void;
184
- /**
185
- * Set table selection state for a widget
186
- * @param id - Widget ID
187
- * @param selection - Partial selection state to merge
188
- */
189
- setTableSelection: (id: WidgetState['id'], selection: Partial<TableSelectionStoreState>) => void;
190
- /**
191
- * Get table state for a widget
192
- * @param id - Widget ID
193
- * @returns Table state or undefined if not found
194
- */
195
- getTableState: (id: WidgetState['id']) => TableStoreState | undefined;
196
124
  /**
197
125
  * Register a tool with the widget's transformation pipeline
198
126
  * @param widgetId - Widget ID
@@ -36,4 +36,4 @@ import { WidgetStore } from './types';
36
36
  * const formulaWidgets = getWidgetsByType('formula')
37
37
  * ```
38
38
  */
39
- export declare const useWidgetStore: import('zustand').UseBoundStore<import('zustand').StoreApi<WidgetStore>>;
39
+ export declare const useWidgetStore: import('node_modules/zustand/esm/react.mjs').UseBoundStore<import('node_modules/zustand/esm/vanilla.mjs').StoreApi<WidgetStore>>;
@@ -1,2 +1,2 @@
1
- export { Subheader } from './subheader';
2
- export type { SubheaderComponentProps } from './types';
1
+ export { WidgetSubHeader } from './subheader';
2
+ export type { WidgetSubHeaderProps } from './types';
@@ -1,2 +1,2 @@
1
- import { SubheaderComponentProps } from './types';
2
- export declare function Subheader({ slotLeft, slotRight, sx, }: SubheaderComponentProps): import("react/jsx-runtime").JSX.Element;
1
+ import { WidgetSubHeaderProps } from './types';
2
+ export declare function WidgetSubHeader({ slotLeft, slotRight, sx, }: WidgetSubHeaderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { SxProps, Theme } from '@mui/material';
2
2
  import { ReactNode } from 'react';
3
- export interface SubheaderComponentProps {
3
+ export interface WidgetSubHeaderProps {
4
4
  /** Content for the left slot */
5
5
  slotLeft?: ReactNode;
6
6
  /** Content for the right slot*/
@@ -1,5 +1,11 @@
1
- import { ConfigProps } from '../root/types';
2
- import { TableDownloadConfig, TableWidgetConfig, TableColumn } from './types';
1
+ import { ConfigProps } from '../loader/types';
2
+ import { TableDownloadConfig, TableWidgetConfig, TableColumn, Mode, SortDirection } from './types';
3
+ export declare const DEFAULT_MODE: Mode;
4
+ export declare const DEFAULT_PAGE = 0;
5
+ export declare const DEFAULT_ROWS_PER_PAGE = 10;
6
+ export declare const DEFAULT_ROWS_PER_PAGE_OPTIONS: number[];
7
+ export declare const DEFAULT_COLUMN_ID: null;
8
+ export declare const DEFAULT_DIRECTION: SortDirection;
3
9
  /**
4
10
  * Default table download configuration
5
11
  * Supports PNG export (screenshot) and CSV export (data)
@@ -1,6 +1,6 @@
1
1
  export { usePagination } from './use-pagination';
2
2
  export { useSort } from './use-sort';
3
3
  export { useSelection } from './use-selection';
4
- export type { UsePaginationOptions, UsePaginationResult, } from './use-pagination';
5
- export type { UseSortOptions, UseSortResult } from './use-sort';
4
+ export type { UsePaginationResult } from './use-pagination';
5
+ export type { UseSortResult } from './use-sort';
6
6
  export type { UseSelectionOptions, UseSelectionResult } from './use-selection';
@@ -1,19 +1,7 @@
1
- import { TableRow, PaginationMode } from '../types';
2
- export interface UsePaginationOptions {
3
- /** Pagination mode: local or remote */
4
- mode: PaginationMode;
5
- /** Initial page (0-indexed) */
6
- initialPage?: number;
7
- /** Initial rows per page */
8
- initialRowsPerPage?: number;
9
- /** Available rows per page options */
10
- rowsPerPageOptions?: number[];
11
- /** Total rows (for remote pagination) */
12
- total?: number;
13
- /** Callback when page changes (for remote pagination) */
14
- onPageChange?: (page: number, rowsPerPage: number) => void;
15
- }
1
+ import { TableRow } from '../types';
16
2
  export interface UsePaginationResult<T> {
3
+ /** Whether pagination is enabled */
4
+ paginationEnabled: boolean;
17
5
  /** Current page (0-indexed) */
18
6
  page: number;
19
7
  /** Rows per page */
@@ -42,4 +30,4 @@ export interface UsePaginationResult<T> {
42
30
  * Supports both local (client-side) and remote (server-side) pagination
43
31
  * State is persisted in the widget store for the given widgetId
44
32
  */
45
- export declare function usePagination<T extends TableRow>(widgetId: string, data: T[], options: UsePaginationOptions): UsePaginationResult<T>;
33
+ export declare function usePagination<T extends TableRow>(widgetId: string, data: T[]): UsePaginationResult<T>;
@@ -1,13 +1,11 @@
1
1
  import { TableRow } from '../types';
2
2
  export interface UseSelectionOptions {
3
- /** Initial selected IDs */
4
- initialSelectedIds?: Set<string | number>;
5
3
  /** Callback when selection changes */
6
- onSelectionChange?: (selectedIds: Set<string | number>) => void;
4
+ onSelectionChange?: (selectedIds: (string | number)[]) => void;
7
5
  }
8
6
  export interface UseSelectionResult {
9
- /** Set of selected row IDs */
10
- selectedIds: Set<string | number>;
7
+ /** Array of selected row IDs */
8
+ selectedIds: (string | number)[];
11
9
  /** Check if a row is selected */
12
10
  isSelected: (id: string | number) => boolean;
13
11
  /** Check if all provided rows are selected */
@@ -1,17 +1,10 @@
1
- import { TableRow, SortMode, SortDirection, SortState } from '../types';
2
- export interface UseSortOptions {
3
- /** Sort mode: local or remote */
4
- mode: SortMode;
5
- /** Initial sort column ID */
6
- initialColumnId?: string | null;
7
- /** Initial sort direction */
8
- initialDirection?: SortDirection;
9
- /** Callback when sort changes (for remote sorting) */
10
- onSortChange?: (columnId: string, direction: SortDirection) => void;
11
- }
12
- export interface UseSortResult<T> {
1
+ import { TableRow, SortDirection, SortState } from '../types';
2
+ export interface UseSortResult<T> extends SortState {
3
+ /** Whether sorting is enabled */
4
+ sortEnabled: boolean;
13
5
  /** Current sort state */
14
- sortState: SortState;
6
+ columnId: string | null;
7
+ direction: SortDirection;
15
8
  /** Sorted data (for local mode) */
16
9
  sortedData: T[];
17
10
  /** Toggle sort on a column */
@@ -26,4 +19,4 @@ export interface UseSortResult<T> {
26
19
  * Supports both local (client-side) and remote (server-side) sorting
27
20
  * State is persisted in the widget store for the given widgetId
28
21
  */
29
- export declare function useSort<T extends TableRow>(widgetId: string, data: T[], options: UseSortOptions): UseSortResult<T>;
22
+ export declare function useSort<T extends TableRow>(widgetId: string, data: T[]): UseSortResult<T>;
@@ -9,5 +9,5 @@ export { TableSkeleton } from './skeleton';
9
9
  export { sanitizeTableRow, sanitizeTableData } from './serializer';
10
10
  export { getCellValue, compareValues, sortData, paginateData } from './helpers';
11
11
  export { styles as tableStyles } from './style';
12
- export type { TableUIProps, TableColumn, TableRow, TableWidgetData, TablePaginationState, SortDirection, SortState, PaginationMode, SortMode, TableWidgetConfig, TableWidgetState, TableDownloadConfig, TableProps, CellHeaderProps, RowProps, PaginationProps, PaginationActionsProps, } from './types';
13
- export type { UsePaginationOptions, UsePaginationResult, UseSortOptions, UseSortResult, UseSelectionOptions, UseSelectionResult, } from './hooks';
12
+ export type { TableUIProps, TableColumn, TableRow, TableWidgetData, TablePaginationState, SortDirection, SortState, Mode, TableWidgetConfig, TableWidgetState, TableDownloadConfig, TableProps, CellHeaderProps, RowProps, PaginationProps, PaginationActionsProps, } from './types';
13
+ export type { UsePaginationResult, UseSortResult, UseSelectionOptions, UseSelectionResult, } from './hooks';
@@ -14,13 +14,13 @@ export interface TableComponentProps extends MuiTableProps {
14
14
  */
15
15
  declare function Table({ children, ref, stickyHeader, ...props }: TableComponentProps): import("react/jsx-runtime").JSX.Element;
16
16
  declare namespace Table {
17
- var Head: import("@mui/material/OverridableComponent").OverridableComponent<import("@mui/material").TableHeadTypeMap<{}, "thead">>;
17
+ var Head: import("node_modules/@mui/material/OverridableComponent").OverridableComponent<import("node_modules/@mui/material").TableHeadTypeMap<{}, "thead">>;
18
18
  var CellHeader: typeof import(".").CellHeader;
19
- var Body: import("@mui/material/OverridableComponent").OverridableComponent<import("@mui/material").TableBodyTypeMap<{}, "tbody">>;
19
+ var Body: import("node_modules/@mui/material/OverridableComponent").OverridableComponent<import("node_modules/@mui/material").TableBodyTypeMap<{}, "tbody">>;
20
20
  var Row: typeof import(".").Row;
21
21
  var Cell: typeof TableCell;
22
22
  var Container: typeof TableContainer;
23
- var Paper: import("@mui/material/OverridableComponent").OverridableComponent<import("@mui/material").PaperTypeMap<{}, "div">>;
23
+ var Paper: import("node_modules/@mui/material/OverridableComponent").OverridableComponent<import("node_modules/@mui/material").PaperTypeMap<{}, "div">>;
24
24
  var Pagination: typeof import(".").Pagination;
25
25
  var PaginationActions: typeof import(".").PaginationActions;
26
26
  }
@@ -63,13 +63,9 @@ export interface SortState {
63
63
  direction: SortDirection;
64
64
  }
65
65
  /**
66
- * Pagination mode
66
+ * Pagination and sort mode
67
67
  */
68
- export type PaginationMode = 'local' | 'remote';
69
- /**
70
- * Sort mode
71
- */
72
- export type SortMode = 'local' | 'remote';
68
+ export type Mode = 'local' | 'remote';
73
69
  /**
74
70
  * Table widget configuration
75
71
  */
@@ -78,45 +74,44 @@ export interface TableWidgetConfig {
78
74
  columns?: TableColumn[];
79
75
  /** Enable row selection with checkboxes */
80
76
  selectable?: boolean;
77
+ /** Currently selected row IDs */
78
+ selected: (string | number)[];
79
+ /** Pagination and sort mode: local (client-side) or remote (server-side) */
80
+ mode: Mode;
81
81
  /** Pagination configuration */
82
82
  pagination?: {
83
- /** Pagination mode: local (client-side) or remote (server-side) */
84
- mode: PaginationMode;
83
+ /** Current page (0-indexed) */
84
+ page?: number;
85
85
  /** Available rows per page options */
86
86
  rowsPerPageOptions?: number[];
87
87
  /** Default rows per page */
88
- defaultRowsPerPage?: number;
88
+ rowsPerPage?: number;
89
89
  /** Total rows for remote pagination */
90
90
  total?: number;
91
91
  };
92
92
  /** Sort configuration */
93
93
  sort?: {
94
- /** Sort mode: local (client-side) or remote (server-side) */
95
- mode: SortMode;
96
94
  /** Default sort column */
97
- defaultColumnId?: string;
95
+ columnId: string | null;
98
96
  /** Default sort direction */
99
- defaultDirection?: SortDirection;
97
+ direction?: SortDirection;
100
98
  };
101
99
  /** Callback when a row is clicked */
102
100
  onRowClick?: (row: TableRow) => void;
103
101
  /** Callback when hovering over a row (null when leaving table) */
104
102
  onRowHover?: (row: TableRow | null) => void;
105
103
  /** Callback when selection changes */
106
- onSelectionChange?: (selectedIds: Set<string | number>) => void;
104
+ onSelectionChange?: (selected: (string | number)[]) => void;
107
105
  /** Callback when page changes (for remote pagination) */
108
106
  onPageChange?: (page: number, rowsPerPage: number) => void;
109
107
  /** Callback when sort changes (for remote sorting) */
110
108
  onSortChange?: (columnId: string, direction: SortDirection) => void;
111
109
  }
112
110
  /**
113
- * Table widget state
111
+ * Table widget state - includes both configuration and runtime state
114
112
  */
115
- export type TableWidgetState = BaseWidgetState<WrapperState<TableWidgetConfig> & {
113
+ export type TableWidgetState = BaseWidgetState<WrapperState<TableWidgetConfig & {}> & {
116
114
  data: TableWidgetData;
117
- paginationState?: TablePaginationState;
118
- sortState?: SortState;
119
- selectedIds?: Set<string | number>;
120
115
  }>;
121
116
  /**
122
117
  * Table download configuration
@@ -1,5 +1,5 @@
1
1
  import { TimeseriesConfig, TimeseriesWidgetConfig, TimeseriesWidgetData } from './types';
2
2
  import { DownloadItem } from '../actions';
3
- import { ConfigProps } from '../root/types';
3
+ import { ConfigProps } from '../loader/types';
4
4
  export declare function timeseriesDownloadConfig({ refUI, }: ConfigProps): DownloadItem<TimeseriesWidgetData>[];
5
5
  export declare function timeseriesConfig(props: TimeseriesConfig): TimeseriesWidgetConfig;
@@ -1,6 +1,6 @@
1
1
  import { EchartWidgetData, EchartWidgetState } from '../echart';
2
2
  import { EchartWidgetOptionProps, EchartWidgetProps } from '../echart/types';
3
- import { ConfigProps } from '../root';
3
+ import { ConfigProps } from '../loader';
4
4
  export type TimeseriesWidgetData = EchartWidgetData;
5
5
  export type TimeseriesWidgetState = EchartWidgetState;
6
6
  export type TimeseriesWidgetConfig = EchartWidgetProps & {
@@ -0,0 +1,131 @@
1
+ import { create as f } from "zustand";
2
+ const T = /* @__PURE__ */ new Map(), w = f()((g, u) => ({
3
+ // State
4
+ widgets: {},
5
+ // Actions
6
+ setWidget: (e, t) => g((o) => {
7
+ const r = o.widgets[e] ?? {};
8
+ return {
9
+ widgets: {
10
+ ...o.widgets,
11
+ [e]: {
12
+ ...r,
13
+ ...t,
14
+ id: e
15
+ }
16
+ }
17
+ };
18
+ }),
19
+ removeWidget: (e) => g((t) => {
20
+ const o = {
21
+ ...t.widgets
22
+ };
23
+ return delete o[e], {
24
+ widgets: o
25
+ };
26
+ }),
27
+ clearWidgets: () => g({
28
+ widgets: {}
29
+ }),
30
+ getWidget: (e) => u().widgets[e],
31
+ registerTool: (e, t) => g((o) => {
32
+ const r = o.widgets[e] ?? {}, l = (r.registeredTools ?? []).filter((d) => d.id !== t.id);
33
+ return {
34
+ widgets: {
35
+ ...o.widgets,
36
+ [e]: {
37
+ ...r,
38
+ id: e,
39
+ registeredTools: [...l, t]
40
+ }
41
+ }
42
+ };
43
+ }),
44
+ unregisterTool: (e, t) => g((o) => {
45
+ const r = o.widgets[e];
46
+ if (!r) return o;
47
+ const l = (r.registeredTools ?? []).filter((d) => d.id !== t);
48
+ return {
49
+ widgets: {
50
+ ...o.widgets,
51
+ [e]: {
52
+ ...r,
53
+ registeredTools: l
54
+ }
55
+ }
56
+ };
57
+ }),
58
+ updateToolConfig: (e, t, o) => g((r) => {
59
+ const i = r.widgets[e];
60
+ if (!i) return r;
61
+ const d = (i.registeredTools ?? []).map((n) => n.id === t ? {
62
+ ...n,
63
+ config: {
64
+ ...n.config,
65
+ ...o
66
+ }
67
+ } : n);
68
+ return {
69
+ widgets: {
70
+ ...r.widgets,
71
+ [e]: {
72
+ ...i,
73
+ registeredTools: d
74
+ }
75
+ }
76
+ };
77
+ }),
78
+ setToolEnabled: (e, t, o) => g((r) => {
79
+ const i = r.widgets[e];
80
+ if (!i) return r;
81
+ const d = (i.registeredTools ?? []).map((n) => n.id === t ? {
82
+ ...n,
83
+ enabled: o
84
+ } : n);
85
+ return {
86
+ widgets: {
87
+ ...r.widgets,
88
+ [e]: {
89
+ ...i,
90
+ registeredTools: d
91
+ }
92
+ }
93
+ };
94
+ }),
95
+ executeToolPipeline: async (e, t) => {
96
+ const o = u().widgets[e];
97
+ if (!o) return;
98
+ const r = (T.get(e) ?? 0) + 1;
99
+ T.set(e, r);
100
+ const i = o, l = /* @__PURE__ */ new Set();
101
+ for (const s of i.registeredTools ?? [])
102
+ s.enabled && s.disables && s.disables.forEach((c) => l.add(c));
103
+ const d = [...i.registeredTools ?? []].filter((s) => s.enabled && !l.has(s.id)).sort((s, c) => s.order - c.order);
104
+ let n = t;
105
+ for (const s of d) {
106
+ if (T.get(e) !== r)
107
+ return;
108
+ try {
109
+ n = await s.fn(n, s.config);
110
+ } catch (c) {
111
+ console.error(`Tool ${s.id} failed for widget ${e}:`, c);
112
+ }
113
+ }
114
+ g((s) => {
115
+ const c = s.widgets[e];
116
+ return c ? {
117
+ widgets: {
118
+ ...s.widgets,
119
+ [e]: {
120
+ ...c,
121
+ data: n
122
+ }
123
+ }
124
+ } : s;
125
+ }), T.get(e) === r && T.delete(e);
126
+ }
127
+ }));
128
+ export {
129
+ w as u
130
+ };
131
+ //# sourceMappingURL=widget-store-CB6Trp_0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-store-CB6Trp_0.js","sources":["../src/widgets/stores/widget-store.ts"],"sourcesContent":["import { create } from 'zustand'\nimport type { WidgetState, WidgetStore, ToolRegistration } from './types'\n\n// Track active pipeline executions for cancellation\nconst activePipelines = new Map<string, number>()\n\n/**\n * Zustand store for managing widget state across the application.\n *\n * This store provides centralized state management for all widget UI components\n *\n * @example\n * ```tsx\n * // Import the store\n * import { useWidgetStore } from '@carto/ps-react-ui/widgets'\n *\n * // Use in a component\n * function MyWidget() {\n * const setWidget = useWidgetStore((state) => state.setWidget)\n * const widget = useWidgetStore((state) => state.widgets['my-widget'])\n *\n * useEffect(() => {\n * setWidget({\n * id: 'my-widget',\n * type: 'formula',\n * title: 'Total Sales',\n * isLoading: false,\n * visible: true,\n * data: { value: 1000, prefix: '$' }\n * })\n * }, [setWidget])\n *\n * return <div>{widget?.data?.value}</div>\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Get widgets by type\n * const getWidgetsByType = useWidgetStore((state) => state.getWidgetsByType)\n * const formulaWidgets = getWidgetsByType('formula')\n * ```\n */\nexport const useWidgetStore = create<WidgetStore>()((set, get) => ({\n // State\n widgets: {},\n\n // Actions\n setWidget: (id, widget) =>\n set((state) => {\n const current =\n state.widgets[id] ?? ({} as WidgetStore['widgets'][string])\n return {\n widgets: {\n ...state.widgets,\n [id]: {\n ...current,\n ...widget,\n id,\n },\n },\n }\n }),\n\n removeWidget: (id) =>\n set((state) => {\n const widgets = { ...state.widgets }\n\n delete widgets[id]\n\n return { widgets }\n }),\n\n clearWidgets: () =>\n set({\n widgets: {},\n }),\n\n getWidget: <T extends WidgetState>(id: string) => {\n return get().widgets[id] as T | undefined\n },\n\n registerTool: (widgetId: string, tool: ToolRegistration) =>\n set((state) => {\n const current = state.widgets[widgetId] ?? ({} as WidgetState)\n const registeredTools = current.registeredTools ?? []\n\n // Remove existing tool with same id if present\n const filteredTools = registeredTools.filter(\n (t: ToolRegistration) => t.id !== tool.id,\n )\n\n return {\n widgets: {\n ...state.widgets,\n [widgetId]: {\n ...current,\n id: widgetId,\n registeredTools: [...filteredTools, tool],\n },\n },\n }\n }),\n\n unregisterTool: (widgetId: string, toolId: string) =>\n set((state) => {\n const current = state.widgets[widgetId]\n if (!current) return state\n\n const registeredTools = current.registeredTools ?? []\n const filteredTools = registeredTools.filter(\n (t: ToolRegistration) => t.id !== toolId,\n )\n\n return {\n widgets: {\n ...state.widgets,\n [widgetId]: {\n ...current,\n registeredTools: filteredTools,\n },\n },\n }\n }),\n\n updateToolConfig: (\n widgetId: string,\n toolId: string,\n config: Record<string, unknown>,\n ) =>\n set((state) => {\n const current = state.widgets[widgetId]\n if (!current) return state\n\n const registeredTools = current.registeredTools ?? []\n const updatedTools = registeredTools.map((tool: ToolRegistration) =>\n tool.id === toolId\n ? {\n ...tool,\n config: { ...tool.config, ...config },\n }\n : tool,\n )\n\n return {\n widgets: {\n ...state.widgets,\n [widgetId]: {\n ...current,\n registeredTools: updatedTools,\n },\n },\n }\n }),\n\n setToolEnabled: (widgetId: string, toolId: string, enabled: boolean) =>\n set((state) => {\n const current = state.widgets[widgetId]\n if (!current) return state\n\n const registeredTools = current.registeredTools ?? []\n const updatedTools = registeredTools.map((tool: ToolRegistration) =>\n tool.id === toolId ? { ...tool, enabled } : tool,\n )\n\n return {\n widgets: {\n ...state.widgets,\n [widgetId]: {\n ...current,\n registeredTools: updatedTools,\n },\n },\n }\n }),\n\n executeToolPipeline: async (widgetId: string, sourceData: unknown) => {\n const widget = get().widgets[widgetId]\n if (!widget) return\n\n // Cancel any in-progress pipeline for this widget\n const currentExecution = (activePipelines.get(widgetId) ?? 0) + 1\n activePipelines.set(widgetId, currentExecution)\n\n const widgetWithTools = widget\n\n // Build set of tool IDs that should be disabled\n const disabledToolIds = new Set<string>()\n for (const tool of widgetWithTools.registeredTools ?? []) {\n if (tool.enabled && tool.disables) {\n tool.disables.forEach((id) => disabledToolIds.add(id))\n }\n }\n\n // Sort tools by order and filter enabled only, excluding disabled tools\n const sortedTools = [...(widgetWithTools.registeredTools ?? [])]\n .filter((tool) => tool.enabled && !disabledToolIds.has(tool.id))\n .sort((a, b) => a.order - b.order)\n\n // Execute pipeline - handle both sync and async tools\n let transformedData = sourceData\n for (const tool of sortedTools) {\n // Check if this execution was cancelled\n if (activePipelines.get(widgetId) !== currentExecution) {\n return\n }\n\n try {\n // Call tool function (may return Promise or direct value)\n transformedData = await tool.fn(transformedData, tool.config)\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Tool ${tool.id} failed for widget ${widgetId}:`, error)\n // Continue with current data to prevent one tool from breaking all\n }\n }\n\n // Single store update with final transformed data\n set((state) => {\n const currentWidget = state.widgets[widgetId]\n if (!currentWidget) return state\n\n return {\n widgets: {\n ...state.widgets,\n [widgetId]: {\n ...currentWidget,\n data: transformedData,\n },\n },\n }\n })\n\n // Clean up tracking\n if (activePipelines.get(widgetId) === currentExecution) {\n activePipelines.delete(widgetId)\n }\n },\n}))\n"],"names":["activePipelines","Map","useWidgetStore","create","set","get","widgets","setWidget","id","widget","state","current","removeWidget","clearWidgets","getWidget","registerTool","widgetId","tool","filteredTools","registeredTools","filter","t","unregisterTool","toolId","updateToolConfig","config","updatedTools","map","setToolEnabled","enabled","executeToolPipeline","sourceData","currentExecution","widgetWithTools","disabledToolIds","Set","disables","forEach","add","sortedTools","has","sort","a","b","order","transformedData","fn","error","console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