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

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.
@@ -0,0 +1,38 @@
1
+ import { jsx as d, jsxs as a } from "react/jsx-runtime";
2
+ import { c as f } from "react/compiler-runtime";
3
+ import { AlertTitle as m, Alert as h } from "@mui/material";
4
+ import { u } from "./widget-store-DNyVElxd.js";
5
+ import { useShallow as p } from "zustand/shallow";
6
+ function W(g) {
7
+ const r = f(7), {
8
+ id: l,
9
+ children: c
10
+ } = g;
11
+ let s;
12
+ r[0] !== l ? (s = (o) => {
13
+ const e = o.widgets[l];
14
+ return {
15
+ isLoading: e?.isLoading,
16
+ isFetching: e?.isFetching,
17
+ error: e?.error
18
+ };
19
+ }, r[0] = l, r[1] = s) : s = r[1];
20
+ const i = u(p(s));
21
+ if (i?.isLoading || i?.isFetching)
22
+ return c;
23
+ if (i?.error) {
24
+ const o = i.error.title ?? "Error", e = i.error.message ?? "An error occurred while loading the widget. Please try again.";
25
+ let t;
26
+ r[2] !== o ? (t = /* @__PURE__ */ d(m, { children: o }), r[2] = o, r[3] = t) : t = r[3];
27
+ let n;
28
+ return r[4] !== e || r[5] !== t ? (n = /* @__PURE__ */ a(h, { severity: "error", children: [
29
+ t,
30
+ e
31
+ ] }), r[4] = e, r[5] = t, r[6] = n) : n = r[6], n;
32
+ }
33
+ return c;
34
+ }
35
+ export {
36
+ W
37
+ };
38
+ //# sourceMappingURL=error-DGzuzmn1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-DGzuzmn1.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;"}
@@ -0,0 +1,61 @@
1
+ import { jsx as g, jsxs as h } from "react/jsx-runtime";
2
+ import { c as x } from "react/compiler-runtime";
3
+ import { Typography as y, Box as v } from "@mui/material";
4
+ import { useShallow as w } from "zustand/shallow";
5
+ import { u as b } from "./widget-store-DNyVElxd.js";
6
+ const j = {
7
+ root: {
8
+ display: "flex",
9
+ flexDirection: "column",
10
+ gap: 1,
11
+ // 8px
12
+ paddingTop: 1,
13
+ // 8px
14
+ paddingBottom: 2,
15
+ // 16px
16
+ paddingX: 2,
17
+ // 16px
18
+ width: "100%",
19
+ minHeight: "100%"
20
+ }
21
+ };
22
+ function k(i) {
23
+ const t = x(9), {
24
+ id: s,
25
+ children: c,
26
+ title: f,
27
+ description: p,
28
+ isEmpty: u
29
+ } = i, a = f === void 0 ? "No data available" : f, l = p === void 0 ? "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" : p, m = u === void 0 ? A : u;
30
+ let o;
31
+ t[0] !== s ? (o = (r) => {
32
+ const e = r.widgets[s];
33
+ return {
34
+ isLoading: e?.isLoading,
35
+ isFetching: e?.isFetching,
36
+ data: e?.data
37
+ };
38
+ }, t[0] = s, t[1] = o) : o = t[1];
39
+ const d = b(w(o));
40
+ if (d?.isLoading || d?.isFetching)
41
+ return c;
42
+ if (m(d?.data)) {
43
+ let r;
44
+ t[2] !== a ? (r = /* @__PURE__ */ g(y, { variant: "body2", color: "text.primary", children: a }), t[2] = a, t[3] = r) : r = t[3];
45
+ let e;
46
+ t[4] !== l ? (e = /* @__PURE__ */ g(y, { variant: "caption", color: "text.secondary", children: l }), t[4] = l, t[5] = e) : e = t[5];
47
+ let n;
48
+ return t[6] !== r || t[7] !== e ? (n = /* @__PURE__ */ h(v, { sx: j.root, children: [
49
+ r,
50
+ e
51
+ ] }), t[6] = r, t[7] = e, t[8] = n) : n = t[8], n;
52
+ }
53
+ return c;
54
+ }
55
+ function A(i) {
56
+ return i == null ? !0 : Array.isArray(i) ? !!(i.length === 0 || i.every((t) => Array.isArray(t) && t.length === 0)) : typeof i == "object" ? Object.keys(i).length === 0 : !1;
57
+ }
58
+ export {
59
+ k as W
60
+ };
61
+ //# sourceMappingURL=no-data-BBAoT1vK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-data-BBAoT1vK.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":";;;;;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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;"}
@@ -18,4 +18,4 @@ export declare const SEARCHER_TOOL_ID = "searcher";
18
18
  * />
19
19
  * ```
20
20
  */
21
- export declare function Searcher({ id, filterFn, order, labels, TextFieldProps, ClearIcon, }: SearcherProps): import("react/jsx-runtime").JSX.Element | null;
21
+ export declare function Searcher({ id, filterFn, order, labels, TextFieldProps, ClearIcon, debounceDelay, }: SearcherProps): import("react/jsx-runtime").JSX.Element | null;
@@ -59,4 +59,6 @@ export interface SearcherProps {
59
59
  TextFieldProps?: Omit<TextFieldProps, 'value' | 'onChange' | 'size'>;
60
60
  /** Custom icon for clear button */
61
61
  ClearIcon?: ReactNode;
62
+ /** Debounce delay in milliseconds for search input. Defaults to 300ms */
63
+ debounceDelay?: number;
62
64
  }
@@ -0,0 +1,2 @@
1
+ import { WidgetErrorProps } from './types';
2
+ export declare function WidgetError({ id, children }: WidgetErrorProps): string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -0,0 +1,2 @@
1
+ export { WidgetError } from './error';
2
+ export type { WidgetErrorProps } from './types';
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { WidgetState } from '../stores/types';
3
+ export interface WidgetErrorProps {
4
+ /**
5
+ * Widget ID to fetch error state from store
6
+ */
7
+ id: WidgetState['id'];
8
+ /**
9
+ * Children to render when no error exists
10
+ */
11
+ children: ReactNode;
12
+ }
@@ -1,2 +1,6 @@
1
1
  export { useWidgetStore } from './stores/widget-store';
2
2
  export type { BaseWidgetState, WidgetsStoreProps, WidgetState, WidgetStore, WidgetStoreActions, WidgetStoreState, } from './stores/types';
3
+ export { WidgetNoData } from './no-data';
4
+ export type { WidgetNoDataProps } from './no-data';
5
+ export { WidgetError } from './error';
6
+ export type { WidgetErrorProps } from './error';
@@ -0,0 +1,2 @@
1
+ export { WidgetNoData } from './no-data';
2
+ export type { WidgetNoDataProps } from './types';
@@ -0,0 +1,35 @@
1
+ import { WidgetNoDataProps } from './types';
2
+ /**
3
+ * NoData wrapper component that displays empty state UI when widget has no data
4
+ *
5
+ * Integrates with widget store to check loading/fetching state and data availability.
6
+ * Works in conjunction with SkeletonLoader for complete loading/empty state handling.
7
+ *
8
+ * @example Basic usage
9
+ * ```tsx
10
+ * <NoData id="my-widget">
11
+ * <WidgetContent id="my-widget" />
12
+ * </NoData>
13
+ * ```
14
+ *
15
+ * @example With SkeletonLoader
16
+ * ```tsx
17
+ * <SkeletonLoader id="my-widget" Skeleton={MySkeleton}>
18
+ * <NoData id="my-widget">
19
+ * <WidgetContent id="my-widget" />
20
+ * </NoData>
21
+ * </SkeletonLoader>
22
+ * ```
23
+ *
24
+ * @example With custom messages
25
+ * ```tsx
26
+ * <NoData
27
+ * id="my-widget"
28
+ * title="No results found"
29
+ * description="Try adjusting your filters"
30
+ * >
31
+ * <WidgetContent id="my-widget" />
32
+ * </NoData>
33
+ * ```
34
+ */
35
+ export declare function WidgetNoData({ id, children, title, description, isEmpty, }: WidgetNoDataProps): string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -0,0 +1,6 @@
1
+ import { SxProps, Theme } from '@mui/material';
2
+ /**
3
+ * Styles for NoData component matching Figma design specifications
4
+ * Design reference: node 5781-11028
5
+ */
6
+ export declare const styles: Record<string, SxProps<Theme>>;
@@ -0,0 +1,67 @@
1
+ import { ReactNode } from 'react';
2
+ import { WidgetState } from '../stores/types';
3
+ /**
4
+ * Props for the WidgetNoData wrapper component
5
+ *
6
+ * @example Basic usage
7
+ * ```tsx
8
+ * <WidgetNoData id="my-widget">
9
+ * <WidgetContent id="my-widget" />
10
+ * </WidgetNoData>
11
+ * ```
12
+ *
13
+ * @example With custom messages
14
+ * ```tsx
15
+ * <WidgetNoData
16
+ * id="my-widget"
17
+ * title="No results found"
18
+ * description="Try adjusting your filters"
19
+ * >
20
+ * <WidgetContent id="my-widget" />
21
+ * </WidgetNoData>
22
+ * ```
23
+ *
24
+ * @example With custom isEmpty logic
25
+ * ```tsx
26
+ * <WidgetNoData
27
+ * id="my-widget"
28
+ * isEmpty={(data) => {
29
+ * const d = data as CustomData
30
+ * return !d?.items?.length
31
+ * }}
32
+ * >
33
+ * <WidgetContent id="my-widget" />
34
+ * </WidgetNoData>
35
+ * ```
36
+ */
37
+ export interface WidgetNoDataProps {
38
+ /**
39
+ * Widget ID to fetch state from store
40
+ */
41
+ id: WidgetState['id'];
42
+ /**
43
+ * Children to render when data is available
44
+ */
45
+ children: ReactNode;
46
+ /**
47
+ * Optional custom title for empty state
48
+ * @default "No data available"
49
+ */
50
+ title?: string;
51
+ /**
52
+ * Optional custom description for empty state
53
+ * @default "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"
54
+ */
55
+ description?: string;
56
+ /**
57
+ * Optional custom function to determine if data is empty
58
+ * If not provided, uses default isEmpty logic that handles:
59
+ * - null/undefined → empty
60
+ * - [] (empty array) → empty
61
+ * - [[]] (nested empty arrays) → empty
62
+ * - {} (empty object) → empty
63
+ * - Primitives → not empty
64
+ * - Arrays/objects with content → not empty
65
+ */
66
+ isEmpty?: (data: unknown) => boolean;
67
+ }
@@ -1,3 +1,3 @@
1
- export { Root } from './root';
1
+ export { WidgetRoot } from './root';
2
2
  export { mergeWidgetConfig } from './utils';
3
- export type { RootProps, ConfigProps } from './types';
3
+ export type { WidgetRootProps, ConfigProps } from './types';
@@ -1,2 +1,2 @@
1
- import { RootProps } from './types';
2
- export declare function Root<T>(props: RootProps<T>): import("react/jsx-runtime").JSX.Element;
1
+ import { WidgetRootProps } from './types';
2
+ export declare function WidgetRoot<T>(props: WidgetRootProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { WidgetsStoreProps, WidgetState } from '../stores/types';
3
- export interface RootProps<T> extends WidgetsStoreProps {
3
+ export interface WidgetRootProps<T> extends WidgetsStoreProps {
4
4
  children: ReactNode;
5
5
  config?: T;
6
6
  }
@@ -62,7 +62,10 @@ export interface WidgetsStoreProps {
62
62
  /** Fetching state (e.g., for async data) */
63
63
  isFetching: boolean;
64
64
  /** Error message if any */
65
- error?: string;
65
+ error?: {
66
+ title?: string;
67
+ message?: string;
68
+ };
66
69
  /** Whether widget is visible */
67
70
  visible?: boolean;
68
71
  /** Reference to the widget ui instance */