@carto/ps-react-ui 5.0.0-widgets.5 → 5.0.0-widgets.7
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/{error-DGzuzmn1.js → error-G3sy6lw3.js} +2 -2
- package/dist/{error-DGzuzmn1.js.map → error-G3sy6lw3.js.map} +1 -1
- package/dist/{no-data-BBAoT1vK.js → no-data-DfkC_Kc_.js} +2 -2
- package/dist/{no-data-BBAoT1vK.js.map → no-data-DfkC_Kc_.js.map} +1 -1
- package/dist/{row-C_m1ovHv.js → row-B9hTUitn.js} +2 -2
- package/dist/{row-C_m1ovHv.js.map → row-B9hTUitn.js.map} +1 -1
- package/dist/{series-6xp-KQ0S.js → series-DojKkd_o.js} +3 -3
- package/dist/{series-6xp-KQ0S.js.map → series-DojKkd_o.js.map} +1 -1
- package/dist/types/widgets/category/config.d.ts +1 -0
- package/dist/types/widgets/category/types.d.ts +1 -0
- package/dist/types/widgets/root/utils.d.ts +1 -1
- package/dist/types/widgets/stores/types.d.ts +0 -75
- package/dist/types/widgets/table/config.d.ts +7 -1
- package/dist/types/widgets/table/hooks/use-pagination.d.ts +2 -16
- package/dist/types/widgets/table/hooks/use-selection.d.ts +0 -2
- package/dist/types/widgets/table/hooks/use-sort.d.ts +3 -10
- package/dist/types/widgets/table/index.d.ts +1 -1
- package/dist/types/widgets/table/types.d.ts +14 -19
- package/dist/widget-store-Dd7_sWZT.js +132 -0
- package/dist/widget-store-Dd7_sWZT.js.map +1 -0
- package/dist/widgets/actions.js +51 -51
- package/dist/widgets/actions.js.map +1 -1
- package/dist/widgets/bar.js +1 -1
- package/dist/widgets/category.js +134 -128
- package/dist/widgets/category.js.map +1 -1
- package/dist/widgets/echart.js +1 -1
- package/dist/widgets/error.js +1 -1
- package/dist/widgets/formula.js +3 -3
- package/dist/widgets/histogram.js +1 -1
- package/dist/widgets/markdown.js +1 -1
- package/dist/widgets/no-data.js +1 -1
- package/dist/widgets/pie.js +1 -1
- package/dist/widgets/range.js +2 -2
- package/dist/widgets/root.js +1 -1
- package/dist/widgets/root.js.map +1 -1
- package/dist/widgets/scatterplot.js +1 -1
- package/dist/widgets/skeleton-loader.js +1 -1
- package/dist/widgets/spread.js +3 -3
- package/dist/widgets/stores.js +1 -1
- package/dist/widgets/table.js +535 -537
- package/dist/widgets/table.js.map +1 -1
- package/dist/widgets/timeseries.js +1 -1
- package/dist/widgets/wrapper.js +1 -1
- package/dist/widgets.js +3 -3
- package/package.json +1 -1
- package/dist/widget-store-DNyVElxd.js +0 -190
- package/dist/widget-store-DNyVElxd.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as d, jsxs as a } from "react/jsx-runtime";
|
|
2
2
|
import { c as f } from "react/compiler-runtime";
|
|
3
3
|
import { AlertTitle as m, Alert as h } from "@mui/material";
|
|
4
|
-
import { u } from "./widget-store-
|
|
4
|
+
import { u } from "./widget-store-Dd7_sWZT.js";
|
|
5
5
|
import { useShallow as p } from "zustand/shallow";
|
|
6
6
|
function W(g) {
|
|
7
7
|
const r = f(7), {
|
|
@@ -35,4 +35,4 @@ function W(g) {
|
|
|
35
35
|
export {
|
|
36
36
|
W
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=error-
|
|
38
|
+
//# sourceMappingURL=error-G3sy6lw3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-
|
|
1
|
+
{"version":3,"file":"error-G3sy6lw3.js","sources":["../src/widgets/error/error.tsx"],"sourcesContent":["import { Alert, AlertTitle } from '@mui/material'\nimport { useWidgetStore } from '../stores/widget-store'\nimport { useShallow } from 'zustand/shallow'\nimport type { WidgetErrorProps } from './types'\n\nexport function WidgetError({ id, children }: WidgetErrorProps) {\n const widget = useWidgetStore(\n useShallow((state) => {\n const w = state.widgets[id]\n return {\n isLoading: w?.isLoading,\n isFetching: w?.isFetching,\n error: w?.error,\n }\n }),\n )\n\n // Don't show error during loading/fetching states\n if (widget?.isLoading || widget?.isFetching) {\n return children\n }\n\n // Show error UI if error exists\n if (widget?.error) {\n const errorTitle = widget.error.title ?? 'Error'\n const errorMessage =\n widget.error.message ??\n 'An error occurred while loading the widget. Please try again.'\n\n return (\n <Alert severity='error'>\n <AlertTitle>{errorTitle}</AlertTitle>\n {errorMessage}\n </Alert>\n )\n }\n\n // No error, render children\n return children\n}\n"],"names":["WidgetError","t0","$","_c","id","children","t1","state","w","widgets","isLoading","isFetching","error","widget","useWidgetStore","useShallow","errorTitle","title","errorMessage","message","t2","AlertTitle","t3","jsxs","Alert"],"mappings":";;;;;AAKO,SAAAA,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAAqB;AAAA,IAAAC,IAAAA;AAAAA,IAAAC,UAAAA;AAAAA,EAAAA,IAAAJ;AAAkC,MAAAK;AAAA,EAAAJ,SAAAE,KAE/CE,IAAAC,CAAAA,MAAA;AACT,UAAAC,IAAUD,EAAKE,QAASL,CAAE;AAAC,WACpB;AAAA,MAAAM,WACMF,GAACE;AAAAA,MAAWC,YACXH,GAACG;AAAAA,MAAYC,OAClBJ,GAACI;AAAAA,IAAAA;AAAAA,EACT,GACFV,OAAAE,GAAAF,OAAAI,KAAAA,IAAAJ,EAAA,CAAA;AARH,QAAAW,IAAeC,EACbC,EAAWT,CAOV,CACH;AAGA,MAAIO,GAAMH,aAAeG,GAAMF;AAAY,WAClCN;AAIT,MAAIQ,GAAMD,OAAO;AACf,UAAAI,IAAmBH,EAAMD,MAAMK,SAAZ,SACnBC,IACEL,EAAMD,MAAMO,WAAZ;AAC+D,QAAAC;AAAA,IAAAlB,SAAAc,KAI7DI,sBAACC,kBAAuB,GAAanB,OAAAc,GAAAd,OAAAkB,KAAAA,IAAAlB,EAAA,CAAA;AAAA,QAAAoB;AAAA,WAAApB,EAAA,CAAA,MAAAgB,KAAAhB,SAAAkB,KADvCE,IAAA,gBAAAC,EAACC,GAAA,EAAe,UAAA,SACdJ,UAAAA;AAAAA,MAAAA;AAAAA,MACCF;AAAAA,IAAAA,GACH,GAAQhB,OAAAgB,GAAAhB,OAAAkB,GAAAlB,OAAAoB,KAAAA,IAAApB,EAAA,CAAA,GAHRoB;AAAAA,EAGQ;AAEX,SAGMjB;AAAQ;"}
|
|
@@ -2,7 +2,7 @@ import { jsx as g, jsxs as h } from "react/jsx-runtime";
|
|
|
2
2
|
import { c as x } from "react/compiler-runtime";
|
|
3
3
|
import { Typography as y, Box as v } from "@mui/material";
|
|
4
4
|
import { useShallow as w } from "zustand/shallow";
|
|
5
|
-
import { u as b } from "./widget-store-
|
|
5
|
+
import { u as b } from "./widget-store-Dd7_sWZT.js";
|
|
6
6
|
const j = {
|
|
7
7
|
root: {
|
|
8
8
|
display: "flex",
|
|
@@ -58,4 +58,4 @@ function A(i) {
|
|
|
58
58
|
export {
|
|
59
59
|
k as W
|
|
60
60
|
};
|
|
61
|
-
//# sourceMappingURL=no-data-
|
|
61
|
+
//# sourceMappingURL=no-data-DfkC_Kc_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-data-
|
|
1
|
+
{"version":3,"file":"no-data-DfkC_Kc_.js","sources":["../src/widgets/no-data/style.ts","../src/widgets/no-data/no-data.tsx"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material'\n\n/**\n * Styles for NoData component matching Figma design specifications\n * Design reference: node 5781-11028\n */\nexport const styles: Record<string, SxProps<Theme>> = {\n root: {\n display: 'flex',\n flexDirection: 'column',\n gap: 1, // 8px\n paddingTop: 1, // 8px\n paddingBottom: 2, // 16px\n paddingX: 2, // 16px\n width: '100%',\n minHeight: '100%',\n },\n}\n","import { Box, Typography } from '@mui/material'\nimport { useShallow } from 'zustand/shallow'\nimport { useWidgetStore } from '../stores/widget-store'\nimport type { WidgetNoDataProps } from './types'\nimport { styles } from './style'\n\n/**\n * NoData wrapper component that displays empty state UI when widget has no data\n *\n * Integrates with widget store to check loading/fetching state and data availability.\n * Works in conjunction with SkeletonLoader for complete loading/empty state handling.\n *\n * @example Basic usage\n * ```tsx\n * <NoData id=\"my-widget\">\n * <WidgetContent id=\"my-widget\" />\n * </NoData>\n * ```\n *\n * @example With SkeletonLoader\n * ```tsx\n * <SkeletonLoader id=\"my-widget\" Skeleton={MySkeleton}>\n * <NoData id=\"my-widget\">\n * <WidgetContent id=\"my-widget\" />\n * </NoData>\n * </SkeletonLoader>\n * ```\n *\n * @example With custom messages\n * ```tsx\n * <NoData\n * id=\"my-widget\"\n * title=\"No results found\"\n * description=\"Try adjusting your filters\"\n * >\n * <WidgetContent id=\"my-widget\" />\n * </NoData>\n * ```\n */\nexport function WidgetNoData({\n id,\n children,\n title = 'No data available',\n description = 'There are no results for the combination of filters applied to your data. Try tweaking your filters, or zoom and pan the map to adjust filters',\n isEmpty = defaultIsEmpty,\n}: WidgetNoDataProps) {\n // Subscribe to widget store with selective subscription for optimal performance\n const widget = useWidgetStore(\n useShallow((state) => {\n const w = state.widgets[id]\n return {\n isLoading: w?.isLoading,\n isFetching: w?.isFetching,\n data: w?.data,\n }\n }),\n )\n\n // If loading or fetching, show children\n // SkeletonLoader handles loading state, this allows proper composition\n if (widget?.isLoading || widget?.isFetching) {\n return children\n }\n\n // Check if data is empty\n if (isEmpty(widget?.data)) {\n return (\n <Box sx={styles.root}>\n <Typography variant='body2' color='text.primary'>\n {title}\n </Typography>\n <Typography variant='caption' color='text.secondary'>\n {description}\n </Typography>\n </Box>\n )\n }\n\n // Data exists, render children\n return children\n}\n\n/**\n * Default function to determine if data is empty\n * Handles various data structures commonly used in widgets\n */\nfunction defaultIsEmpty(data: unknown): boolean {\n // Null or undefined\n if (data == null) {\n return true\n }\n\n // Arrays (most common case)\n if (Array.isArray(data)) {\n // Empty array\n if (data.length === 0) {\n return true\n }\n\n // Array of arrays (CategoryWidget pattern: [[],[]])\n // Check if all inner arrays are empty\n if (data.every((item) => Array.isArray(item) && item.length === 0)) {\n return true\n }\n\n return false\n }\n\n // Objects\n if (typeof data === 'object') {\n return Object.keys(data).length === 0\n }\n\n // Primitives (numbers, strings, booleans) are considered valid data\n return false\n}\n"],"names":["styles","root","display","flexDirection","gap","paddingTop","paddingBottom","paddingX","width","minHeight","WidgetNoData","t0","$","_c","id","children","title","t1","description","t2","isEmpty","t3","undefined","defaultIsEmpty","t4","state","w","widgets","isLoading","isFetching","data","widget","useWidgetStore","useShallow","t5","Typography","t6","t7","Box","Array","isArray","length","every","item","Object","keys"],"mappings":";;;;;AAMO,MAAMA,IAAyC;AAAA,EACpDC,MAAM;AAAA,IACJC,SAAS;AAAA,IACTC,eAAe;AAAA,IACfC,KAAK;AAAA;AAAA,IACLC,YAAY;AAAA;AAAA,IACZC,eAAe;AAAA;AAAA,IACfC,UAAU;AAAA;AAAA,IACVC,OAAO;AAAA,IACPC,WAAW;AAAA,EAAA;AAEf;ACsBO,SAAAC,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAAsB;AAAA,IAAAC,IAAAA;AAAAA,IAAAC,UAAAA;AAAAA,IAAAC,OAAAC;AAAAA,IAAAC,aAAAC;AAAAA,IAAAC,SAAAC;AAAAA,EAAAA,IAAAV,GAG3BK,IAAAC,MAAAK,SAAA,sBAAAL,GACAC,IAAAC,MAAAG,SAAA,mJAAAH,GACAC,IAAAC,MAAAC,SAAAC,IAAAF;AAAwB,MAAAG;AAAA,EAAAZ,SAAAE,KAIXU,IAAAC,CAAAA,MAAA;AACT,UAAAC,IAAUD,EAAKE,QAASb,CAAE;AAAC,WACpB;AAAA,MAAAc,WACMF,GAACE;AAAAA,MAAWC,YACXH,GAACG;AAAAA,MAAYC,MACnBJ,GAACI;AAAAA,IAAAA;AAAAA,EACR,GACFlB,OAAAE,GAAAF,OAAAY,KAAAA,IAAAZ,EAAA,CAAA;AARH,QAAAmB,IAAeC,EACbC,EAAWT,CAOV,CACH;AAIA,MAAIO,GAAMH,aAAeG,GAAMF;AAAY,WAClCd;AAIT,MAAIK,EAAQW,GAAMD,IAAM,GAAC;AAAA,QAAAI;AAAA,IAAAtB,SAAAI,KAGnBkB,sBAACC,GAAA,EAAmB,SAAA,SAAc,OAAA,gBAC/BnB,UAAAA,GACH,GAAaJ,OAAAI,GAAAJ,OAAAsB,KAAAA,IAAAtB,EAAA,CAAA;AAAA,QAAAwB;AAAA,IAAAxB,SAAAM,KACbkB,sBAACD,GAAA,EAAmB,SAAA,WAAgB,OAAA,kBACjCjB,UAAAA,GACH,GAAaN,OAAAM,GAAAN,OAAAwB,KAAAA,IAAAxB,EAAA,CAAA;AAAA,QAAAyB;AAAA,WAAAzB,EAAA,CAAA,MAAAsB,KAAAtB,SAAAwB,KANfC,sBAACC,GAAA,EAAQ,IAAAtC,EAAMC,MACbiC,UAAAA;AAAAA,MAAAA;AAAAA,MAGAE;AAAAA,IAAAA,GAGF,GAAMxB,OAAAsB,GAAAtB,OAAAwB,GAAAxB,OAAAyB,KAAAA,IAAAzB,EAAA,CAAA,GAPNyB;AAAAA,EAOM;AAET,SAGMtB;AAAQ;AAOjB,SAASQ,EAAeO,GAAwB;AAE9C,SAAIA,KAAQ,OACH,KAILS,MAAMC,QAAQV,CAAI,IAEhBA,GAAAA,EAAKW,WAAW,KAMhBX,EAAKY,MAAOC,CAAAA,MAASJ,MAAMC,QAAQG,CAAI,KAAKA,EAAKF,WAAW,CAAC,KAQ/D,OAAOX,KAAS,WACXc,OAAOC,KAAKf,CAAI,EAAEW,WAAW,IAI/B;AACT;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import { c as n } from "react/compiler-runtime";
|
|
3
3
|
import { Box as c } from "@mui/material";
|
|
4
|
-
import { u as m } from "./widget-store-
|
|
4
|
+
import { u as m } from "./widget-store-Dd7_sWZT.js";
|
|
5
5
|
import { useShallow as s } from "zustand/shallow";
|
|
6
6
|
const f = {
|
|
7
7
|
item: {
|
|
@@ -32,4 +32,4 @@ export {
|
|
|
32
32
|
y as R,
|
|
33
33
|
f as s
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=row-
|
|
35
|
+
//# sourceMappingURL=row-B9hTUitn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-
|
|
1
|
+
{"version":3,"file":"row-B9hTUitn.js","sources":["../src/widgets/formula/style.ts","../src/widgets/formula/components/row.tsx"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material'\n\nexport const styles = {\n root: {\n display: 'flex',\n flexDirection: 'column',\n gap: (theme: Theme) => theme.spacing(2),\n },\n item: {\n '&[data-disabled=\"true\"]': {\n color: (theme: Theme) => theme.palette.text.disabled,\n },\n },\n row: {\n display: 'flex',\n alignItems: 'center',\n gap: (theme: Theme) => theme.spacing(1),\n\n '& + &': {\n marginTop: (theme: Theme) => theme.spacing(1),\n },\n },\n} satisfies Record<string, SxProps<Theme>>\n","import { Box } from '@mui/material'\nimport { styles } from '../style'\nimport type { FormulaWidgetState, RowProps } from '../types'\nimport { useWidgetStore } from '../../stores/widget-store'\nimport { useShallow } from 'zustand/shallow'\n\nexport function Row(props: RowProps) {\n const data = useWidgetStore(\n useShallow((state) => state.getWidget<FormulaWidgetState>(props.id)?.data),\n )\n\n return data?.map((_, index) => {\n return (\n <Box sx={styles.row} key={index}>\n {typeof props.children === 'function'\n ? props.children({ index })\n : props.children}\n </Box>\n )\n })\n}\n"],"names":["styles","item","color","theme","palette","text","disabled","row","display","alignItems","gap","spacing","marginTop","Row","props","$","_c","t0","id","state","getWidget","data","useWidgetStore","useShallow","t1","map","_","index","jsx","Box","children"],"mappings":";;;;;AAEO,MAAMA,IAAS;AAAA,EAMpBC,MAAM;AAAA,IACJ,2BAA2B;AAAA,MACzBC,OAAOA,CAACC,MAAiBA,EAAMC,QAAQC,KAAKC;AAAAA,IAAAA;AAAAA,EAC9C;AAAA,EAEFC,KAAK;AAAA,IACHC,SAAS;AAAA,IACTC,YAAY;AAAA,IACZC,KAAKA,CAACP,MAAiBA,EAAMQ,QAAQ,CAAC;AAAA,IAEtC,SAAS;AAAA,MACPC,WAAWA,CAACT,MAAiBA,EAAMQ,QAAQ,CAAC;AAAA,IAAA;AAAA,EAC9C;AAEJ;AChBO,SAAAE,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAA,EAAAF,EAAA,CAAA,MAAAD,EAAAI,MAEQD,IAAAE,CAAAA,MAAWA,EAAKC,UAA+BN,EAAKI,EAAS,GAACG,MAAAN,EAAA,CAAA,IAAAD,EAAAI,IAAAH,OAAAE,KAAAA,IAAAF,EAAA,CAAA;AAD3E,QAAAM,IAAaC,EACXC,EAAWN,CAA8D,CAC3E;AAAC,MAAAO;AAAA,SAAAT,EAAA,CAAA,MAAAM,KAAAN,SAAAD,KAEMU,IAAAH,GAAII,IAAM,CAAAC,GAAAC,MAEb,gBAAAC,EAACC,GAAA,EAAQ,IAAA7B,EAAMO,KACZ,UAAA,OAAOO,EAAKgB,YAAc,aACvBhB,EAAKgB,SAAU;AAAA,IAAAH,OAAAA;AAAAA,EAAAA,CACF,IAAbb,EAAKgB,SAAAA,GAHeH,CAI1B,CAEH,GAACZ,OAAAM,GAAAN,OAAAD,GAAAC,OAAAS,KAAAA,IAAAT,EAAA,CAAA,GARKS;AAQL;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import { c as h } from "react/compiler-runtime";
|
|
3
|
-
import { u as g } from "./widget-store-
|
|
3
|
+
import { u as g } from "./widget-store-Dd7_sWZT.js";
|
|
4
4
|
import { useShallow as p } from "zustand/shallow";
|
|
5
5
|
import { Typography as S, Avatar as b } from "@mui/material";
|
|
6
|
-
import { s as P } from "./row-
|
|
6
|
+
import { s as P } from "./row-B9hTUitn.js";
|
|
7
7
|
function y(i) {
|
|
8
8
|
const e = h(4);
|
|
9
9
|
let t;
|
|
@@ -88,4 +88,4 @@ export {
|
|
|
88
88
|
j as S,
|
|
89
89
|
I as a
|
|
90
90
|
};
|
|
91
|
-
//# sourceMappingURL=series-
|
|
91
|
+
//# sourceMappingURL=series-DojKkd_o.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"series-
|
|
1
|
+
{"version":3,"file":"series-DojKkd_o.js","sources":["../src/widgets/formula/components/item.tsx","../src/widgets/formula/components/prefix.tsx","../src/widgets/formula/components/suffix.tsx","../src/widgets/formula/components/series.tsx"],"sourcesContent":["import { Typography } from '@mui/material'\nimport type { ItemProps } from '../types'\nimport { styles } from '../style'\n\nexport function Item(props: ItemProps) {\n return (\n <Typography\n sx={styles.item}\n variant='h5'\n fontWeight='medium'\n data-disabled={props.disabled}\n color='default'\n {...props.TypographyProps}\n >\n {props.children}\n </Typography>\n )\n}\n","import { type FormulaWidgetState, type ValueProps } from '../types'\nimport { useWidgetStore } from '../../stores/widget-store'\nimport { Item } from './item'\nimport { useShallow } from 'zustand/shallow'\n\nexport function Prefix({ id, index = 0, ...props }: ValueProps) {\n const prefix = useWidgetStore(\n useShallow(\n (state) => state.getWidget<FormulaWidgetState>(id)?.data?.[index]?.prefix,\n ),\n )\n\n if (!prefix) {\n return null\n }\n\n return <Item {...props}>{prefix}</Item>\n}\n","import { type FormulaWidgetState, type ValueProps } from '../types'\nimport { useWidgetStore } from '../../stores/widget-store'\nimport { Item } from './item'\nimport type { Theme } from '@mui/material'\nimport { useShallow } from 'zustand/shallow'\n\nexport function Suffix({ id, index = 0, ...props }: ValueProps) {\n const suffix = useWidgetStore(\n useShallow(\n (state) => state.getWidget<FormulaWidgetState>(id)?.data?.[index]?.suffix,\n ),\n )\n\n if (!suffix) {\n return null\n }\n\n return (\n <Item\n TypographyProps={{\n color: (theme: Theme) => theme.palette.text.secondary,\n }}\n {...props}\n >\n {suffix}\n </Item>\n )\n}\n","import { Avatar } from '@mui/material'\nimport type { FormulaWidgetState, ValueProps } from '../types'\nimport { useWidgetStore } from '../../stores/widget-store'\nimport { useShallow } from 'zustand/shallow'\n\nexport function Series({ id, index = 0 }: Pick<ValueProps, 'id' | 'index'>) {\n const serie = useWidgetStore(\n useShallow(\n (state) => state.getWidget<FormulaWidgetState>(id)?.series?.[index],\n ),\n )\n if (!serie) {\n return null\n }\n\n const { name, color } = serie\n\n return (\n <Avatar\n sx={{\n bgcolor: color,\n width: 32,\n height: 32,\n fontSize: '0.875rem',\n fontWeight: 'medium',\n ...(color && {\n color: (theme) => theme.palette.getContrastText(color),\n }),\n }}\n >\n {name.charAt(0).toUpperCase()}\n </Avatar>\n )\n}\n"],"names":["Item","props","$","_c","t0","TypographyProps","children","disabled","Typography","styles","item","Prefix","id","t1","index","undefined","t2","state","getWidget","data","prefix","useWidgetStore","useShallow","t3","jsx","Suffix","suffix","Symbol","for","color","_temp","t4","theme","palette","text","secondary","Series","series","serie","name","getContrastText","bgcolor","width","height","fontSize","fontWeight","t5","charAt","toUpperCase","t6","Avatar"],"mappings":";;;;;;AAIO,SAAAA,EAAAC,GAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAA,SAAAF,EAAA,CAAA,MAAAD,EAAAI,mBAAAH,EAAA,CAAA,MAAAD,EAAAK,YAAAJ,EAAA,CAAA,MAAAD,EAAAM,YAEHH,sBAACI,GAAA,EACK,IAAAC,EAAMC,MACF,SAAA,MACG,YAAA,UACI,iBAAAT,EAAKM,UACd,OAAA,WAAS,GACXN,EAAKI,iBAERJ,YAAKK,UACR,GAAaJ,EAAA,CAAA,IAAAD,EAAAI,iBAAAH,EAAA,CAAA,IAAAD,EAAAK,UAAAJ,EAAA,CAAA,IAAAD,EAAAM,UAAAL,OAAAE,KAAAA,IAAAF,EAAA,CAAA,GATbE;AASa;ACVV,SAAAO,EAAAP,GAAA;AAAA,QAAAF,IAAAC,EAAA,EAAA;AAAA,MAAAS,GAAAX,GAAAY;AAAA,EAAAX,SAAAE,KAAgB;AAAA,IAAAQ,IAAAA;AAAAA,IAAAE,OAAAD;AAAAA,IAAA,GAAAZ;AAAAA,EAAAA,IAAAG,GAAuCF,OAAAE,GA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,IAAArB,EAAA,CAAA;AAAA,MAAA6B;AAAA,EAAA7B,EAAA,CAAA,MAAA2B,KAAA3B,SAAAqB,KARCQ,IAAA;AAAA,IAAAU,SACOZ;AAAAA,IAAKa,OACP;AAAA,IAAEC,QACD;AAAA,IAAEC,UACA;AAAA,IAAUC,YACR;AAAA,IAAQ,GAChBtB;AAAAA,EAAAA,GAGLrB,OAAA2B,GAAA3B,OAAAqB,GAAArB,OAAA6B,KAAAA,IAAA7B,EAAA,CAAA;AAAA,MAAA4C;AAAA,EAAA5C,SAAAqC,KAEAO,IAAAP,EAAIQ,OAAQ,CAAC,EAACC,YAAAA,GAAc9C,OAAAqC,GAAArC,OAAA4C,KAAAA,IAAA5C,EAAA,CAAA;AAAA,MAAA+C;AAAA,SAAA/C,EAAA,EAAA,MAAA6B,KAAA7B,UAAA4C,KAZ/BG,IAAA,gBAAAzB,EAAC0B,GAAA,EACK,IAAAnB,GAWHe,UAAAA,GACH,GAAS5C,QAAA6B,GAAA7B,QAAA4C,GAAA5C,QAAA+C,KAAAA,IAAA/C,EAAA,EAAA,GAbT+C;AAaS;"}
|
|
@@ -10,6 +10,7 @@ export interface CategoryConfigProps {
|
|
|
10
10
|
formatter?: (value: number) => string;
|
|
11
11
|
maxItems?: number;
|
|
12
12
|
labels?: CategoryLabels;
|
|
13
|
+
max?: number;
|
|
13
14
|
}
|
|
14
15
|
export declare function categoryDownloadConfig({ refUI, series, }: CategoryDownloadConfigProps): DownloadItem<CategoryWidgetData>[];
|
|
15
16
|
export declare function categoryConfig(): CategoryWidgetConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function mergeWidgetConfig<T>(...options: [T | undefined, T | undefined]): T;
|
|
1
|
+
export declare function mergeWidgetConfig<T>(...options: [Partial<T> | undefined, Partial<T> | undefined]): T;
|
|
@@ -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;
|
|
@@ -172,30 +121,6 @@ export interface WidgetStoreActions {
|
|
|
172
121
|
* @returns Widget state or undefined if not found
|
|
173
122
|
*/
|
|
174
123
|
getWidget: <T extends WidgetState = WidgetState>(id: WidgetState['id']) => T | undefined;
|
|
175
|
-
/**
|
|
176
|
-
* Set table pagination state for a widget
|
|
177
|
-
* @param id - Widget ID
|
|
178
|
-
* @param pagination - Partial pagination state to merge
|
|
179
|
-
*/
|
|
180
|
-
setTablePagination: (id: WidgetState['id'], pagination: Partial<TablePaginationStoreState>) => void;
|
|
181
|
-
/**
|
|
182
|
-
* Set table sort state for a widget
|
|
183
|
-
* @param id - Widget ID
|
|
184
|
-
* @param sort - Partial sort state to merge
|
|
185
|
-
*/
|
|
186
|
-
setTableSort: (id: WidgetState['id'], sort: Partial<TableSortStoreState>) => void;
|
|
187
|
-
/**
|
|
188
|
-
* Set table selection state for a widget
|
|
189
|
-
* @param id - Widget ID
|
|
190
|
-
* @param selection - Partial selection state to merge
|
|
191
|
-
*/
|
|
192
|
-
setTableSelection: (id: WidgetState['id'], selection: Partial<TableSelectionStoreState>) => void;
|
|
193
|
-
/**
|
|
194
|
-
* Get table state for a widget
|
|
195
|
-
* @param id - Widget ID
|
|
196
|
-
* @returns Table state or undefined if not found
|
|
197
|
-
*/
|
|
198
|
-
getTableState: (id: WidgetState['id']) => TableStoreState | undefined;
|
|
199
124
|
/**
|
|
200
125
|
* Register a tool with the widget's transformation pipeline
|
|
201
126
|
* @param widgetId - Widget ID
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ConfigProps } from '../root/types';
|
|
2
|
-
import { TableDownloadConfig, TableWidgetConfig, TableColumn } from './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,18 +1,4 @@
|
|
|
1
|
-
import { TableRow
|
|
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> {
|
|
17
3
|
/** Current page (0-indexed) */
|
|
18
4
|
page: number;
|
|
@@ -42,4 +28,4 @@ export interface UsePaginationResult<T> {
|
|
|
42
28
|
* Supports both local (client-side) and remote (server-side) pagination
|
|
43
29
|
* State is persisted in the widget store for the given widgetId
|
|
44
30
|
*/
|
|
45
|
-
export declare function usePagination<T extends TableRow>(widgetId: string, data: T[]
|
|
31
|
+
export declare function usePagination<T extends TableRow>(widgetId: string, data: T[]): UsePaginationResult<T>;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { TableRow,
|
|
1
|
+
import { TableRow, SortDirection, SortState } from '../types';
|
|
2
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
3
|
/** Callback when sort changes (for remote sorting) */
|
|
10
4
|
onSortChange?: (columnId: string, direction: SortDirection) => void;
|
|
11
5
|
}
|
|
12
|
-
export interface UseSortResult<T> {
|
|
6
|
+
export interface UseSortResult<T> extends SortState {
|
|
13
7
|
/** Current sort state */
|
|
14
|
-
sortState: SortState;
|
|
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
|
|
22
|
+
export declare function useSort<T extends TableRow>(widgetId: string, data: T[], options?: UseSortOptions): 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,
|
|
12
|
+
export type { TableUIProps, TableColumn, TableRow, TableWidgetData, TablePaginationState, SortDirection, SortState, Mode, TableWidgetConfig, TableWidgetState, TableDownloadConfig, TableProps, CellHeaderProps, RowProps, PaginationProps, PaginationActionsProps, } from './types';
|
|
13
13
|
export type { UsePaginationOptions, UsePaginationResult, UseSortOptions, UseSortResult, UseSelectionOptions, UseSelectionResult, } from './hooks';
|
|
@@ -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
|
|
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: Set<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
|
-
/**
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
+
columnId: string | null;
|
|
98
96
|
/** Default sort direction */
|
|
99
|
-
|
|
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?: (
|
|
104
|
+
onSelectionChange?: (selected: Set<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
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { create as f } from "zustand";
|
|
2
|
+
const u = /* @__PURE__ */ new Map(), w = f()((c, T) => ({
|
|
3
|
+
// State
|
|
4
|
+
widgets: {},
|
|
5
|
+
// Actions
|
|
6
|
+
setWidget: (e, t) => c((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) => c((t) => {
|
|
20
|
+
const o = {
|
|
21
|
+
...t.widgets
|
|
22
|
+
};
|
|
23
|
+
return delete o[e], {
|
|
24
|
+
widgets: o
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
clearWidgets: () => c({
|
|
28
|
+
widgets: {}
|
|
29
|
+
}),
|
|
30
|
+
getWidget: (e) => T().widgets[e],
|
|
31
|
+
registerTool: (e, t) => c((o) => {
|
|
32
|
+
const r = o.widgets[e] ?? {}, l = (r.registeredTools ?? []).filter((g) => g.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) => c((o) => {
|
|
45
|
+
const r = o.widgets[e];
|
|
46
|
+
if (!r) return o;
|
|
47
|
+
const l = (r.registeredTools ?? []).filter((g) => g.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) => c((r) => {
|
|
59
|
+
const i = r.widgets[e];
|
|
60
|
+
if (!i) return r;
|
|
61
|
+
const g = (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: g
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
setToolEnabled: (e, t, o) => c((r) => {
|
|
79
|
+
const i = r.widgets[e];
|
|
80
|
+
if (!i) return r;
|
|
81
|
+
const g = (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: g
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
executeToolPipeline: async (e, t) => {
|
|
96
|
+
const o = T().widgets[e];
|
|
97
|
+
if (!o) return;
|
|
98
|
+
const r = (u.get(e) ?? 0) + 1;
|
|
99
|
+
u.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((d) => l.add(d));
|
|
103
|
+
const g = [...i.registeredTools ?? []].filter((s) => s.enabled && !l.has(s.id)).sort((s, d) => s.order - d.order);
|
|
104
|
+
let n = t;
|
|
105
|
+
for (const s of g) {
|
|
106
|
+
if (u.get(e) !== r)
|
|
107
|
+
return;
|
|
108
|
+
try {
|
|
109
|
+
const d = s.fn(n, s.config);
|
|
110
|
+
n = d instanceof Promise ? await d : d;
|
|
111
|
+
} catch (d) {
|
|
112
|
+
console.error(`Tool ${s.id} failed for widget ${e}:`, d);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
u.get(e) === r && (c((s) => {
|
|
116
|
+
const d = s.widgets[e];
|
|
117
|
+
return d ? {
|
|
118
|
+
widgets: {
|
|
119
|
+
...s.widgets,
|
|
120
|
+
[e]: {
|
|
121
|
+
...d,
|
|
122
|
+
data: n
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} : s;
|
|
126
|
+
}), u.get(e) === r && u.delete(e));
|
|
127
|
+
}
|
|
128
|
+
}));
|
|
129
|
+
export {
|
|
130
|
+
w as u
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=widget-store-Dd7_sWZT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-store-Dd7_sWZT.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 const result = tool.fn(transformedData, tool.config)\n\n // Await if Promise, otherwise use directly\n transformedData = result instanceof Promise ? await result : result\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 // Final check before updating store (in case cancelled during async operation)\n if (activePipelines.get(widgetId) !== currentExecution) {\n return\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","result","fn","Promise","error","console","currentWidget","data","delete"],"mappings":";AAIA,MAAMA,wBAAsBC,IAAAA,GAuCfC,IAAiBC,EAAAA,EAAsB,CAACC,GAAKC,OAAS;AAAA;AAAA,EAEjEC,SAAS,CAAA;AAAA;AAAA,EAGTC,WAAWA,CAACC,GAAIC,MACdL,EAAKM,CAAAA,MAAU;AACb,UAAMC,IACJD,EAAMJ,QAAQE,CAAE,KAAM,CAAA;AACxB,WAAO;AAAA,MACLF,SAAS;AAAA,QACP,GAAGI,EAAMJ;AAAAA,QACT,CAACE,CAAE,GAAG;AAAA,UACJ,GAAGG;AAAAA,UACH,GAAGF;AAAAA,UACHD,IA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