@altertable/data-app-react 0.79.0 → 0.80.0
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/chunks/{SectionHeading-BAZB-Fnf.js → SectionHeading-DR8RX7YZ.js} +77 -53
- package/dist/chunks/SectionHeading-DR8RX7YZ.js.map +1 -0
- package/dist/index.js +217 -4
- package/dist/index.js.map +1 -1
- package/dist/types/chunks/DateTimeRangePicker.d.ts +3 -3
- package/dist/types/index.d.ts +12 -1
- package/dist/types/ui/index.d.ts +1 -1
- package/dist/ui/index.js +9 -4
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/SectionHeading-BAZB-Fnf.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,228 @@
|
|
|
1
|
-
import { $t as
|
|
2
|
-
import { getDataAppTransport, navigateNewTab, navigateNewWindowOrTab } from "@altertable/data-app/client";
|
|
3
|
-
import { KEY_SEPARATOR, fixedUnitMilliseconds, invariant } from "@altertable/data-app/internal";
|
|
4
|
-
import { useCallback, useContext, useEffect, useEffectEvent, useImperativeHandle, useReducer, useRef, useState } from "react";
|
|
1
|
+
import { $t as Kbd, At as errorPresentation, C as DataAppFrame, Ct as resolveActions, D as TextContent, Dt as DetailView, E as useAppAppearance, Et as DetailRoutes, Ft as mountDataApp, G as useDeclaredResult, Gt as Sheet, H as AppViewResultsContext, Ht as TabPanels, Jt as subscribeSearch, L as IconButton, Lt as SegmentedTab, Nt as ownedSource, O as Stack, Ot as useDetailNavigation, R as useDataAppAnnotations, Rt as SegmentedTabList, S as LoadingStatus, T as useDataAppPresentation, Tt as DetailContent, U as assertAppFilters, Ut as Tabs, V as createDataHooks, Vt as TabPanel, W as getViewDefinition, Xt as TooltipProvider, Yt as Tooltip, _ as ContentSkeleton, _t as datasetTable, a as DataTable, an as Button, at as Skeleton, b as Notice, bt as DateDisplay, cn as DateFormattingContext, dn as injectDataAppStyles, dt as SearchSuggestionsContext, en as shortcuts, fn as injectStyles, g as withWidgetBoundary, gt as RegisteredBinding, h as DataWidget, ht as MetricRecords, i as chartColor, in as EmptyState, jt as StatusPanel, kt as DataSectionBoundary, l as ExplorationActionControl, ln as useDateFormatting, mt as sectionContent, n as createDataContext, nn as useInspectionDefaults, nt as Select, o as DataTableEmptyRow, pt as searchItems, qt as searchParams, rn as AppIcon, rt as dateTimeRangeLabel, sn as classNames, t as SectionHeading, tn as InspectionContext, tt as DateTimeRangePicker, un as useDataApp, v as ContentSkeletonBody, vt as exportDatasets, w as useDataAppTransport, wt as breakdownState, x as WidgetFrameContext, xt as DateTimeTooltip, y as getAnnotationProps, yt as registeredEvidence, z as AnnotationTooltip } from "./chunks/SectionHeading-DR8RX7YZ.js";
|
|
2
|
+
import { appDiagnostics, getDataAppTransport, navigateNewTab, navigateNewWindowOrTab } from "@altertable/data-app/client";
|
|
3
|
+
import { KEY_SEPARATOR, appUrlKeys, fixedUnitMilliseconds, invariant, readWidgetCaptureRequest, readWidgetId, reportWidgetCapture } from "@altertable/data-app/internal";
|
|
4
|
+
import { Component, Suspense, useCallback, useContext, useEffect, useEffectEvent, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { autoUpdate, flip, offset, shift, useFloating, useMergeRefs } from "@floating-ui/react";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { Eye, EyeOff, GripVertical, LoaderCircle, Minus, Trash2, X } from "lucide-react";
|
|
8
8
|
import { formatCount, formatDateRange, formatDateTime, formatMetric, formatPercent, parseDateTime, pluralize } from "@altertable/data-app/format";
|
|
9
9
|
import { parseDataAppAnnotationDraft, parseExternalUrl } from "@altertable/data-app/contract";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
|
+
//#region src/ui/FocusedWidget.tsx
|
|
12
|
+
function readThemeOverride() {
|
|
13
|
+
const [theme, ...rest] = searchParams().getAll(appUrlKeys.theme);
|
|
14
|
+
if (rest.length === 0 && (theme === "light" || theme === "dark")) return theme;
|
|
15
|
+
}
|
|
16
|
+
function currentSearch() {
|
|
17
|
+
return searchParams().toString();
|
|
18
|
+
}
|
|
19
|
+
function FocusedWidgetSurface({ capture, ...props }) {
|
|
20
|
+
const transport = useDataAppTransport();
|
|
21
|
+
const subscribe = useCallback((listener) => transport?.subscribe(listener) ?? (() => {}), [transport]);
|
|
22
|
+
const search = useSyncExternalStore(subscribeSearch, currentSearch, () => "");
|
|
23
|
+
const request = useSyncExternalStore(subscribe, () => readWidgetCaptureRequest(transport?.snapshot(), search), () => void 0);
|
|
24
|
+
const { state } = capture;
|
|
25
|
+
const widgetId = "widgetId" in capture ? capture.widgetId : void 0;
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
if (!request) return;
|
|
28
|
+
transport?.[reportWidgetCapture]?.(request, widgetId === void 0 ? { state: "invalid-target" } : {
|
|
29
|
+
state,
|
|
30
|
+
widgetId
|
|
31
|
+
});
|
|
32
|
+
}, [
|
|
33
|
+
transport,
|
|
34
|
+
request,
|
|
35
|
+
state,
|
|
36
|
+
widgetId
|
|
37
|
+
]);
|
|
38
|
+
return /* @__PURE__ */ jsx("main", {
|
|
39
|
+
...props,
|
|
40
|
+
className: "altertable-focused-widget",
|
|
41
|
+
"data-widget-state": state,
|
|
42
|
+
"data-focused-widget": widgetId
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function useFocusedTarget(registry) {
|
|
46
|
+
const id = useSyncExternalStore(subscribeSearch, () => readWidgetId(searchParams()), () => void 0);
|
|
47
|
+
if (!registry || id === void 0) return null;
|
|
48
|
+
if (id === null) return {
|
|
49
|
+
kind: "invalid",
|
|
50
|
+
reason: "Provide one valid widget ID in the URL."
|
|
51
|
+
};
|
|
52
|
+
const widget = registry.get(id);
|
|
53
|
+
return widget ? {
|
|
54
|
+
kind: "widget",
|
|
55
|
+
widget
|
|
56
|
+
} : {
|
|
57
|
+
kind: "invalid",
|
|
58
|
+
reason: `No widget is registered as “${id}”.`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function FocusedWidget({ target }) {
|
|
62
|
+
const identity = useId();
|
|
63
|
+
const app = useDataApp();
|
|
64
|
+
const transport = useDataAppTransport();
|
|
65
|
+
const presentation = useDataAppPresentation(transport);
|
|
66
|
+
const theme = useSyncExternalStore(subscribeSearch, readThemeOverride, () => void 0);
|
|
67
|
+
const search = useSyncExternalStore(subscribeSearch, currentSearch, () => "");
|
|
68
|
+
useAppAppearance(app.appearance, theme ?? presentation?.theme);
|
|
69
|
+
if (target.kind === "invalid") return /* @__PURE__ */ jsx(FocusedWidgetSurface, {
|
|
70
|
+
capture: { state: "invalid-target" },
|
|
71
|
+
children: /* @__PURE__ */ jsx(StatusPanel, {
|
|
72
|
+
status: "error",
|
|
73
|
+
title: "Widget unavailable",
|
|
74
|
+
description: target.reason
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
const { widget } = target;
|
|
78
|
+
return /* @__PURE__ */ jsx(WidgetFrameContext, {
|
|
79
|
+
value: false,
|
|
80
|
+
children: /* @__PURE__ */ jsx(FocusedRenderBoundary, {
|
|
81
|
+
id: widget.id,
|
|
82
|
+
identity,
|
|
83
|
+
resetKey: search,
|
|
84
|
+
children: /* @__PURE__ */ jsx(FocusedWidgetResult, { widget })
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
var FocusedRenderBoundary = class extends Component {
|
|
89
|
+
state = {
|
|
90
|
+
failed: false,
|
|
91
|
+
resetKey: this.props.resetKey
|
|
92
|
+
};
|
|
93
|
+
static getDerivedStateFromProps(props, state) {
|
|
94
|
+
return props.resetKey === state.resetKey ? null : {
|
|
95
|
+
failed: false,
|
|
96
|
+
resetKey: props.resetKey
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
static getDerivedStateFromError() {
|
|
100
|
+
return { failed: true };
|
|
101
|
+
}
|
|
102
|
+
componentDidCatch(error) {
|
|
103
|
+
appDiagnostics.record("render", this.props.id, error, this.props.identity);
|
|
104
|
+
}
|
|
105
|
+
componentDidUpdate(_, previous) {
|
|
106
|
+
if (previous.failed && !this.state.failed) appDiagnostics.clear("render", this.props.id, this.props.identity);
|
|
107
|
+
}
|
|
108
|
+
componentWillUnmount() {
|
|
109
|
+
appDiagnostics.clear("render", this.props.id, this.props.identity);
|
|
110
|
+
}
|
|
111
|
+
render() {
|
|
112
|
+
return this.state.failed ? /* @__PURE__ */ jsx(FocusedWidgetSurface, {
|
|
113
|
+
capture: {
|
|
114
|
+
state: "error",
|
|
115
|
+
widgetId: this.props.id
|
|
116
|
+
},
|
|
117
|
+
children: /* @__PURE__ */ jsx(StatusPanel, {
|
|
118
|
+
status: "error",
|
|
119
|
+
title: "This widget couldn’t render"
|
|
120
|
+
})
|
|
121
|
+
}) : this.props.children;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function FocusedWidgetResult({ widget }) {
|
|
125
|
+
const section = sectionContent(widget.content);
|
|
126
|
+
const result = useDeclaredResult(section.view);
|
|
127
|
+
const view = result.view;
|
|
128
|
+
const { kind } = view;
|
|
129
|
+
const data = result.snapshot?.data;
|
|
130
|
+
const input = result.snapshot?.input;
|
|
131
|
+
const element = useRef(null);
|
|
132
|
+
const drawing = useMemo(() => kind === "ready" ? {
|
|
133
|
+
widget,
|
|
134
|
+
data,
|
|
135
|
+
input
|
|
136
|
+
} : void 0, [
|
|
137
|
+
kind,
|
|
138
|
+
data,
|
|
139
|
+
input,
|
|
140
|
+
widget
|
|
141
|
+
]);
|
|
142
|
+
const [outcome, setOutcome] = useState();
|
|
143
|
+
const drawn = drawing && outcome?.drawing === drawing ? outcome.state : void 0;
|
|
144
|
+
const requestError = kind === "error" || kind === "stale-error" ? errorPresentation(view.error) : void 0;
|
|
145
|
+
let state = "loading";
|
|
146
|
+
if (requestError) state = "error";
|
|
147
|
+
else if (kind === "empty") state = "empty";
|
|
148
|
+
else if (drawn) state = drawn;
|
|
149
|
+
return /* @__PURE__ */ jsx(FocusedWidgetSurface, {
|
|
150
|
+
ref: element,
|
|
151
|
+
capture: {
|
|
152
|
+
state,
|
|
153
|
+
widgetId: widget.id
|
|
154
|
+
},
|
|
155
|
+
"aria-busy": state === "loading",
|
|
156
|
+
inert: true,
|
|
157
|
+
children: requestError ? /* @__PURE__ */ jsx(StatusPanel, {
|
|
158
|
+
status: "error",
|
|
159
|
+
title: requestError.title,
|
|
160
|
+
description: requestError.description
|
|
161
|
+
}) : kind === "empty" ? /* @__PURE__ */ jsx(EmptyState, { ...result.emptyFallback }) : drawn === "error" ? /* @__PURE__ */ jsx(StatusPanel, {
|
|
162
|
+
status: "error",
|
|
163
|
+
title: "This widget couldn’t finish rendering"
|
|
164
|
+
}) : /* @__PURE__ */ jsxs(Suspense, {
|
|
165
|
+
fallback: /* @__PURE__ */ jsx(WidgetLoading, { reset: setOutcome }),
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ jsx(DateFormattingContext, {
|
|
168
|
+
value: { timeZone: result.timeZone },
|
|
169
|
+
children: /* @__PURE__ */ jsx(WidgetContent, { render: () => kind === "ready" ? section.children(view.data, view.input) : section.loadingFallback })
|
|
170
|
+
}),
|
|
171
|
+
state === "loading" && /* @__PURE__ */ jsx(LoadingStatus, { label: "Loading widget" }),
|
|
172
|
+
drawing && /* @__PURE__ */ jsx(DrawingObserver, {
|
|
173
|
+
element,
|
|
174
|
+
drawing,
|
|
175
|
+
settle: setOutcome
|
|
176
|
+
})
|
|
177
|
+
]
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function WidgetLoading({ reset }) {
|
|
182
|
+
useLayoutEffect(() => reset(void 0), [reset]);
|
|
183
|
+
return /* @__PURE__ */ jsx(LoadingStatus, { label: "Loading widget" });
|
|
184
|
+
}
|
|
185
|
+
function WidgetContent({ render }) {
|
|
186
|
+
return render();
|
|
187
|
+
}
|
|
188
|
+
/** Settles a drawing once custom rendering, fonts, and the next frame are done. */
|
|
189
|
+
function DrawingObserver({ element, drawing, settle }) {
|
|
190
|
+
useLayoutEffect(() => {
|
|
191
|
+
const abort = new AbortController();
|
|
192
|
+
const { signal } = abort;
|
|
193
|
+
async function wait() {
|
|
194
|
+
await Promise.resolve();
|
|
195
|
+
if (signal.aborted || !element.current) return;
|
|
196
|
+
await drawing.widget.waitForReady?.(element.current, signal);
|
|
197
|
+
if (signal.aborted) return;
|
|
198
|
+
await document.fonts.ready;
|
|
199
|
+
if (signal.aborted) return;
|
|
200
|
+
await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
201
|
+
}
|
|
202
|
+
wait().then(() => {
|
|
203
|
+
if (!signal.aborted) settle({
|
|
204
|
+
drawing,
|
|
205
|
+
state: "ready"
|
|
206
|
+
});
|
|
207
|
+
}, () => {
|
|
208
|
+
if (!signal.aborted) settle({
|
|
209
|
+
drawing,
|
|
210
|
+
state: "error"
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
return () => abort.abort();
|
|
214
|
+
}, [
|
|
215
|
+
element,
|
|
216
|
+
drawing,
|
|
217
|
+
settle
|
|
218
|
+
]);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
11
222
|
//#region src/ui/DataApp.tsx
|
|
12
223
|
function DataApp(props) {
|
|
224
|
+
const target = useFocusedTarget((props.view && getViewDefinition(props.view).clientFilters)?.widgets);
|
|
225
|
+
if (target) return /* @__PURE__ */ jsx(FocusedWidget, { target }, target.kind === "widget" ? target.widget.id : void 0);
|
|
13
226
|
if (!props.view) return /* @__PURE__ */ jsx(DataAppFrame, { ...props });
|
|
14
227
|
return /* @__PURE__ */ jsx(ViewDataApp, { ...props });
|
|
15
228
|
}
|