@altertable/data-app 0.71.0 → 0.73.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/AGENTS.md +5 -61
- package/CONTRIBUTING.md +93 -173
- package/README.md +3 -3
- package/REFERENCE.md +30 -341
- package/dist/chunks/contract-BeLPJwlO.js +558 -0
- package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
- package/dist/chunks/contract-Di8SP74I.js +462 -0
- package/dist/chunks/contract-Di8SP74I.js.map +1 -0
- package/dist/chunks/format-BdFlv_xa.js +148 -0
- package/dist/chunks/format-BdFlv_xa.js.map +1 -0
- package/dist/chunks/iframe-C3uCZEXh.js +809 -0
- package/dist/chunks/iframe-C3uCZEXh.js.map +1 -0
- package/dist/chunks/operation-CBxhjNhK.js +131 -0
- package/dist/chunks/operation-CBxhjNhK.js.map +1 -0
- package/dist/chunks/request-body-H1qPmmTN.js +50 -0
- package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
- package/dist/client/index.js +253 -285
- package/dist/client/index.js.map +1 -13
- package/dist/core/appearance.js +171 -162
- package/dist/core/appearance.js.map +1 -10
- package/dist/core/config.js +49 -11
- package/dist/core/config.js.map +1 -9
- package/dist/core/contract.js +3 -73
- package/dist/core/format.js +1 -26
- package/dist/index.js +1 -12
- package/dist/internal.js +352 -397
- package/dist/internal.js.map +1 -15
- package/dist/server/index.js +85 -97
- package/dist/server/index.js.map +1 -10
- package/dist/types/chunks/appearance.d.ts +45 -0
- package/dist/types/chunks/contract.d.ts +720 -0
- package/dist/types/chunks/index.d.ts +189 -0
- package/dist/types/client/index.d.ts +3 -13
- package/dist/types/core/appearance.d.ts +2 -42
- package/dist/types/core/config.d.ts +44 -48
- package/dist/types/core/contract.d.ts +2 -114
- package/dist/types/core/format.d.ts +44 -17
- package/dist/types/index.d.ts +3 -3
- package/dist/types/internal.d.ts +312 -22
- package/dist/types/server/index.d.ts +15 -4
- package/docs/app-authoring.md +72 -112
- package/docs/client.md +29 -63
- package/docs/composition.md +44 -75
- package/docs/contract.md +60 -100
- package/docs/data-context.md +35 -61
- package/docs/embed.md +83 -55
- package/docs/formatting-and-appearance.md +17 -38
- package/docs/hosted-apps.md +12 -15
- package/docs/layout.md +30 -47
- package/docs/local-data-apps.md +7 -7
- package/docs/react-embed.md +20 -26
- package/docs/react.md +10 -27
- package/docs/server-bun.md +3 -28
- package/docs/server.md +6 -12
- package/docs/stories-and-export.md +38 -40
- package/docs/styling.md +14 -22
- package/docs/ui-quality.md +5 -5
- package/docs/ui.md +68 -70
- package/docs/variables.md +142 -254
- package/docs/views.md +85 -116
- package/docs/widgets.md +100 -153
- package/docs/worker.md +15 -27
- package/package.json +3 -3
- package/dist/chunks/index-5a27erdg.js +0 -54
- package/dist/chunks/index-5a27erdg.js.map +0 -10
- package/dist/chunks/index-9yxr7nmm.js +0 -742
- package/dist/chunks/index-9yxr7nmm.js.map +0 -17
- package/dist/chunks/index-j5q5n3ra.js +0 -151
- package/dist/chunks/index-j5q5n3ra.js.map +0 -10
- package/dist/chunks/index-q75zm3a7.js +0 -153
- package/dist/chunks/index-q75zm3a7.js.map +0 -11
- package/dist/chunks/index-vhaec7m5.js +0 -30
- package/dist/chunks/index-vhaec7m5.js.map +0 -10
- package/dist/chunks/index-zp78caex.js +0 -1047
- package/dist/chunks/index-zp78caex.js.map +0 -19
- package/dist/core/contract.js.map +0 -9
- package/dist/core/format.js.map +0 -9
- package/dist/index.js.map +0 -9
- package/dist/types/client/annotations.d.ts +0 -27
- package/dist/types/client/data-client.d.ts +0 -43
- package/dist/types/client/download.d.ts +0 -5
- package/dist/types/client/iframe.d.ts +0 -59
- package/dist/types/client/location.d.ts +0 -13
- package/dist/types/client/logger.d.ts +0 -14
- package/dist/types/client/messages.d.ts +0 -7
- package/dist/types/client/navigation.d.ts +0 -15
- package/dist/types/client/transport.d.ts +0 -15
- package/dist/types/core/annotations.d.ts +0 -99
- package/dist/types/core/bridge-endpoint.d.ts +0 -21
- package/dist/types/core/bridge.d.ts +0 -172
- package/dist/types/core/data-view.d.ts +0 -46
- package/dist/types/core/date-format.d.ts +0 -24
- package/dist/types/core/date-range.d.ts +0 -20
- package/dist/types/core/dimension-source.d.ts +0 -64
- package/dist/types/core/dimension.d.ts +0 -71
- package/dist/types/core/facets.d.ts +0 -13
- package/dist/types/core/filters.d.ts +0 -45
- package/dist/types/core/invariant.d.ts +0 -2
- package/dist/types/core/keys.d.ts +0 -2
- package/dist/types/core/logger.d.ts +0 -12
- package/dist/types/core/messages.d.ts +0 -62
- package/dist/types/core/navigation.d.ts +0 -11
- package/dist/types/core/operation-types.d.ts +0 -80
- package/dist/types/core/operation.d.ts +0 -20
- package/dist/types/core/presentation.d.ts +0 -9
- package/dist/types/core/queries.d.ts +0 -84
- package/dist/types/core/reading.d.ts +0 -17
- package/dist/types/core/uuid.d.ts +0 -2
- package/dist/types/core/variables.d.ts +0 -133
- package/dist/types/server/handler.d.ts +0 -13
- package/dist/types/server/request-body.d.ts +0 -4
- package/examples/starter-data-app/index.tsx +0 -193
- package/examples/starter-local-data-app/.bun-version +0 -1
- package/examples/starter-local-data-app/.node-version +0 -1
- package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
- package/examples/starter-local-data-app/.oxlintrc.json +0 -33
- package/examples/starter-local-data-app/AGENTS.md +0 -22
- package/examples/starter-local-data-app/README.md +0 -56
- package/examples/starter-local-data-app/app.ts +0 -28
- package/examples/starter-local-data-app/bunfig.toml +0 -2
- package/examples/starter-local-data-app/package.json +0 -35
- package/examples/starter-local-data-app/src/App.tsx +0 -8
- package/examples/starter-local-data-app/src/assets.d.ts +0 -1
- package/examples/starter-local-data-app/src/data-context.ts +0 -21
- package/examples/starter-local-data-app/src/favicon.svg +0 -13
- package/examples/starter-local-data-app/src/index.html +0 -14
- package/examples/starter-local-data-app/src/main.tsx +0 -7
- package/examples/starter-local-data-app/src/operations.ts +0 -6
- package/examples/starter-local-data-app/src/server.ts +0 -6
- package/examples/starter-local-data-app/tsconfig.json +0 -21
package/dist/internal.js
CHANGED
|
@@ -1,418 +1,373 @@
|
|
|
1
|
-
import"./chunks/
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
RequestBodyTooLargeError2,
|
|
22
|
-
readRequestBody2
|
|
23
|
-
} from "./chunks/index-5a27erdg.js";
|
|
24
|
-
import {
|
|
25
|
-
toDataOperationFailure2
|
|
26
|
-
} from "./chunks/index-j5q5n3ra.js";
|
|
27
|
-
|
|
28
|
-
// packages/data-app/src/client/download.ts
|
|
29
|
-
function downloadBlob({
|
|
30
|
-
filename,
|
|
31
|
-
blob
|
|
32
|
-
}) {
|
|
33
|
-
const url = URL.createObjectURL(blob);
|
|
34
|
-
const link = document.createElement("a");
|
|
35
|
-
link.href = url;
|
|
36
|
-
link.download = filename;
|
|
37
|
-
document.body.append(link);
|
|
38
|
-
try {
|
|
39
|
-
link.click();
|
|
40
|
-
} finally {
|
|
41
|
-
link.remove();
|
|
42
|
-
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
43
|
-
}
|
|
1
|
+
import { T as invariant, b as dimensionMemberKey, p as dimensionSource, v as createDimensionFilter, w as KEY_SEPARATOR } from "./chunks/contract-BeLPJwlO.js";
|
|
2
|
+
import { y as numberOperatorLabels } from "./chunks/contract-Di8SP74I.js";
|
|
3
|
+
import { n as toDataOperationFailure } from "./chunks/operation-CBxhjNhK.js";
|
|
4
|
+
import { c as isDataAppPresentation, d as PARENT_PARAM, f as REQUEST_TIMEOUT_MS, i as localFrameBridge, l as createBridgeEndpoint, m as randomUuid, p as validId, u as MAX_PENDING } from "./chunks/iframe-C3uCZEXh.js";
|
|
5
|
+
import { n as readRequestBody, t as RequestBodyTooLargeError } from "./chunks/request-body-H1qPmmTN.js";
|
|
6
|
+
import { parseDate, today } from "@internationalized/date";
|
|
7
|
+
//#region src/client/download.ts
|
|
8
|
+
/** Start a browser download and release its temporary anchor and object URL. */
|
|
9
|
+
function downloadBlob({ filename, blob }) {
|
|
10
|
+
const url = URL.createObjectURL(blob);
|
|
11
|
+
const link = document.createElement("a");
|
|
12
|
+
link.href = url;
|
|
13
|
+
link.download = filename;
|
|
14
|
+
document.body.append(link);
|
|
15
|
+
try {
|
|
16
|
+
link.click();
|
|
17
|
+
} finally {
|
|
18
|
+
link.remove();
|
|
19
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
20
|
+
}
|
|
44
21
|
}
|
|
45
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/data-view.ts
|
|
24
|
+
/** The result currently shown to the reader, including the input that produced it. */
|
|
46
25
|
function displayedSnapshot(view) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
if (view.kind === "ready") return {
|
|
27
|
+
data: view.data,
|
|
28
|
+
input: view.input,
|
|
29
|
+
state: view.kind
|
|
30
|
+
};
|
|
31
|
+
if (view.kind === "updating" || view.kind === "stale-error") return {
|
|
32
|
+
data: view.data,
|
|
33
|
+
input: view.displayedInput,
|
|
34
|
+
state: view.kind
|
|
35
|
+
};
|
|
52
36
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return isEmpty(shown.data) ? { kind: "empty", input: shown.input } : { kind: "ready", data: shown.data, input: shown.input };
|
|
37
|
+
/** Keep the requested input separate from the input that produced visible data. */
|
|
38
|
+
function resolveDataView({ requestedInput, current, previous, pending, error, sameInput, describe, isEmpty }) {
|
|
39
|
+
const shown = current ?? previous;
|
|
40
|
+
if (!shown) return error ? {
|
|
41
|
+
kind: "error",
|
|
42
|
+
error
|
|
43
|
+
} : { kind: "loading" };
|
|
44
|
+
const currentInput = sameInput(shown.input, requestedInput);
|
|
45
|
+
if (error) return {
|
|
46
|
+
kind: "stale-error",
|
|
47
|
+
data: shown.data,
|
|
48
|
+
displayedInput: shown.input,
|
|
49
|
+
requestedInput,
|
|
50
|
+
error,
|
|
51
|
+
message: currentInput ? `Couldn’t refresh. Showing the last result for ${describe(shown.input)}.` : `Couldn’t refresh. Showing ${describe(shown.input)} while ${describe(requestedInput)} is unavailable.`
|
|
52
|
+
};
|
|
53
|
+
if (pending || !currentInput) return {
|
|
54
|
+
kind: "updating",
|
|
55
|
+
data: shown.data,
|
|
56
|
+
displayedInput: shown.input,
|
|
57
|
+
requestedInput,
|
|
58
|
+
message: currentInput ? `Updating ${describe(requestedInput)}…` : `Showing ${describe(shown.input)} while loading ${describe(requestedInput)}…`
|
|
59
|
+
};
|
|
60
|
+
return isEmpty(shown.data) ? {
|
|
61
|
+
kind: "empty",
|
|
62
|
+
input: shown.input
|
|
63
|
+
} : {
|
|
64
|
+
kind: "ready",
|
|
65
|
+
data: shown.data,
|
|
66
|
+
input: shown.input
|
|
67
|
+
};
|
|
85
68
|
}
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/core/date-range.ts
|
|
88
71
|
function inclusiveDays(range) {
|
|
89
|
-
|
|
72
|
+
return (parseDate(range.end).toDate("UTC").getTime() - parseDate(range.start).toDate("UTC").getTime()) / 864e5 + 1;
|
|
90
73
|
}
|
|
91
74
|
function monday(date) {
|
|
92
|
-
|
|
75
|
+
return date.subtract({ days: (date.toDate("UTC").getUTCDay() + 6) % 7 });
|
|
93
76
|
}
|
|
94
77
|
function withinBounds(range, minDate, maxDate, maxRangeDays) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
function availableDatePresets({
|
|
105
|
-
minDate,
|
|
106
|
-
maxDate,
|
|
107
|
-
maxRangeDays,
|
|
108
|
-
timeZone = "UTC"
|
|
109
|
-
}) {
|
|
110
|
-
const currentDay = today(timeZone);
|
|
111
|
-
const latest = maxDate && parseDate(maxDate).compare(currentDay) < 0 ? parseDate(maxDate) : currentDay;
|
|
112
|
-
const earliest = minDate ? parseDate(minDate) : null;
|
|
113
|
-
const completeDays = latest.compare(currentDay.subtract({ days: 1 })) === 0;
|
|
114
|
-
const historical = latest.compare(currentDay.subtract({ days: 1 })) < 0;
|
|
115
|
-
const options = [];
|
|
116
|
-
const seen = new Set;
|
|
117
|
-
function add(id, label, start, end = latest) {
|
|
118
|
-
const days = (end.toDate("UTC").getTime() - start.toDate("UTC").getTime()) / 86400000 + 1;
|
|
119
|
-
const range = { start: start.toString(), end: end.toString() };
|
|
120
|
-
const key = [range.start, range.end].join(KEY_SEPARATOR2);
|
|
121
|
-
if (days < 1 || maxRangeDays && days > maxRangeDays || earliest && start.compare(earliest) < 0 || end.compare(latest) > 0 || seen.has(key))
|
|
122
|
-
return;
|
|
123
|
-
seen.add(key);
|
|
124
|
-
options.push({ id, label, range });
|
|
125
|
-
}
|
|
126
|
-
add("day", historical ? "Latest available day" : completeDays ? "Yesterday" : "Today", latest);
|
|
127
|
-
for (const days of [3, 7, 14, 30, 90]) {
|
|
128
|
-
add(`last-${days}`, historical ? `Latest ${days} available days` : completeDays ? `Last ${days} complete days` : `Last ${days} days`, latest.subtract({ days: days - 1 }));
|
|
129
|
-
}
|
|
130
|
-
const weekStart = monday(currentDay);
|
|
131
|
-
if (latest.compare(weekStart) >= 0)
|
|
132
|
-
add("this-week", completeDays ? "This week through yesterday" : "This week", weekStart);
|
|
133
|
-
add("previous-week", "Previous week", weekStart.subtract({ days: 7 }), weekStart.subtract({ days: 1 }));
|
|
134
|
-
const monthStart = currentDay.set({ day: 1 });
|
|
135
|
-
if (latest.compare(monthStart) >= 0)
|
|
136
|
-
add("this-month", completeDays ? "This month through yesterday" : "This month", monthStart);
|
|
137
|
-
const previousMonthEnd = monthStart.subtract({ days: 1 });
|
|
138
|
-
add("previous-month", "Previous month", previousMonthEnd.set({ day: 1 }), previousMonthEnd);
|
|
139
|
-
return options;
|
|
78
|
+
try {
|
|
79
|
+
const start = parseDate(range.start);
|
|
80
|
+
const end = parseDate(range.end);
|
|
81
|
+
const days = inclusiveDays(range);
|
|
82
|
+
return days >= 1 && (!maxRangeDays || days <= maxRangeDays) && (!minDate || start.compare(parseDate(minDate)) >= 0) && (!maxDate || end.compare(parseDate(maxDate)) <= 0);
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
140
86
|
}
|
|
141
|
-
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
87
|
+
/** Only offer ranges the app says it can query. Dates and range lengths are inclusive. */
|
|
88
|
+
function availableDatePresets({ minDate, maxDate, maxRangeDays, timeZone = "UTC" }) {
|
|
89
|
+
const currentDay = today(timeZone);
|
|
90
|
+
const latest = maxDate && parseDate(maxDate).compare(currentDay) < 0 ? parseDate(maxDate) : currentDay;
|
|
91
|
+
const earliest = minDate ? parseDate(minDate) : null;
|
|
92
|
+
const completeDays = latest.compare(currentDay.subtract({ days: 1 })) === 0;
|
|
93
|
+
const historical = latest.compare(currentDay.subtract({ days: 1 })) < 0;
|
|
94
|
+
const options = [];
|
|
95
|
+
const seen = /* @__PURE__ */ new Set();
|
|
96
|
+
function add(id, label, start, end = latest) {
|
|
97
|
+
const days = (end.toDate("UTC").getTime() - start.toDate("UTC").getTime()) / 864e5 + 1;
|
|
98
|
+
const range = {
|
|
99
|
+
start: start.toString(),
|
|
100
|
+
end: end.toString()
|
|
101
|
+
};
|
|
102
|
+
const key = [range.start, range.end].join(":");
|
|
103
|
+
if (days < 1 || maxRangeDays && days > maxRangeDays || earliest && start.compare(earliest) < 0 || end.compare(latest) > 0 || seen.has(key)) return;
|
|
104
|
+
seen.add(key);
|
|
105
|
+
options.push({
|
|
106
|
+
id,
|
|
107
|
+
label,
|
|
108
|
+
range
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
add("day", historical ? "Latest available day" : completeDays ? "Yesterday" : "Today", latest);
|
|
112
|
+
for (const days of [
|
|
113
|
+
3,
|
|
114
|
+
7,
|
|
115
|
+
14,
|
|
116
|
+
30,
|
|
117
|
+
90
|
|
118
|
+
]) add(`last-${days}`, historical ? `Latest ${days} available days` : completeDays ? `Last ${days} complete days` : `Last ${days} days`, latest.subtract({ days: days - 1 }));
|
|
119
|
+
const weekStart = monday(currentDay);
|
|
120
|
+
if (latest.compare(weekStart) >= 0) add("this-week", completeDays ? "This week through yesterday" : "This week", weekStart);
|
|
121
|
+
add("previous-week", "Previous week", weekStart.subtract({ days: 7 }), weekStart.subtract({ days: 1 }));
|
|
122
|
+
const monthStart = currentDay.set({ day: 1 });
|
|
123
|
+
if (latest.compare(monthStart) >= 0) add("this-month", completeDays ? "This month through yesterday" : "This month", monthStart);
|
|
124
|
+
const previousMonthEnd = monthStart.subtract({ days: 1 });
|
|
125
|
+
add("previous-month", "Previous month", previousMonthEnd.set({ day: 1 }), previousMonthEnd);
|
|
126
|
+
return options;
|
|
147
127
|
}
|
|
148
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/core/variables.ts
|
|
130
|
+
/** Name variables once in the app. URL keys must be unique across its controls. */
|
|
149
131
|
function defineAppVariables(variables) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
132
|
+
const owners = /* @__PURE__ */ new Map();
|
|
133
|
+
for (const [name, variable] of Object.entries(variables)) {
|
|
134
|
+
const presentation = variable.presentation;
|
|
135
|
+
invariant(presentation === void 0 || presentation !== null && typeof presentation === "object" && !Array.isArray(presentation) && (presentation.control === void 0 || presentation.control === "toolbar" || presentation.control === "widget") && (presentation.group === void 0 || presentation.group === "scope" || presentation.group === "display") && (presentation.prominence === void 0 || presentation.prominence === "primary" || presentation.prominence === "secondary"), `Variable ${name} has invalid presentation.`);
|
|
136
|
+
for (const key of variable.urlKeys) {
|
|
137
|
+
invariant(![
|
|
138
|
+
"view",
|
|
139
|
+
"about",
|
|
140
|
+
"tab",
|
|
141
|
+
"present",
|
|
142
|
+
"step",
|
|
143
|
+
"details"
|
|
144
|
+
].includes(key), `Variable ${name} uses reserved URL key: ${key}.`);
|
|
145
|
+
invariant(!!key && !owners.has(key), `Variable ${name} has an empty or duplicate URL key: ${key}.`);
|
|
146
|
+
owners.set(key, name);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return variables;
|
|
161
150
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
same(left, right) {
|
|
186
|
-
return left === right;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
151
|
+
/** Search query state; typing replaces history by default. */
|
|
152
|
+
function searchVariable({ key, label, defaultValue = "", history = "replace" }) {
|
|
153
|
+
return {
|
|
154
|
+
kind: "search",
|
|
155
|
+
label: label ?? key,
|
|
156
|
+
urlKeys: [key],
|
|
157
|
+
defaultValue,
|
|
158
|
+
clearValue: "",
|
|
159
|
+
describe: (value) => value,
|
|
160
|
+
history,
|
|
161
|
+
read(params) {
|
|
162
|
+
return params.get(key) ?? defaultValue;
|
|
163
|
+
},
|
|
164
|
+
write(value) {
|
|
165
|
+
return { [key]: value === defaultValue ? null : value };
|
|
166
|
+
},
|
|
167
|
+
valid(value) {
|
|
168
|
+
return typeof value === "string";
|
|
169
|
+
},
|
|
170
|
+
same(left, right) {
|
|
171
|
+
return left === right;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
189
174
|
}
|
|
175
|
+
/** Validate labeled choices before controls or URL state consume them. */
|
|
190
176
|
function validateChoiceOptions(options) {
|
|
191
|
-
|
|
177
|
+
invariant(options.length > 0 && options.every((option) => !!option.id.trim() && !!option.label.trim()) && new Set(options.map((option) => option.id)).size === options.length, "Choices require nonempty, unique IDs and labels.");
|
|
192
178
|
}
|
|
193
|
-
function choiceVariable({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
},
|
|
219
|
-
write(value) {
|
|
220
|
-
return { [key]: value === defaultValue ? null : value };
|
|
221
|
-
},
|
|
222
|
-
valid,
|
|
223
|
-
same: (left, right) => left === right
|
|
224
|
-
};
|
|
179
|
+
function choiceVariable({ key, label, defaultValue, options, history = "push", presentation }) {
|
|
180
|
+
validateChoiceOptions(options);
|
|
181
|
+
function valid(value) {
|
|
182
|
+
return typeof value === "string" && options.some((option) => option.id === value);
|
|
183
|
+
}
|
|
184
|
+
invariant(valid(defaultValue), `Choice variable ${key} must include its default value.`);
|
|
185
|
+
return {
|
|
186
|
+
kind: "choice",
|
|
187
|
+
presentation,
|
|
188
|
+
label: label ?? key,
|
|
189
|
+
options,
|
|
190
|
+
urlKeys: [key],
|
|
191
|
+
defaultValue,
|
|
192
|
+
history,
|
|
193
|
+
describe: (value) => options.find((option) => option.id === value).label,
|
|
194
|
+
read(params) {
|
|
195
|
+
const value = params.get(key);
|
|
196
|
+
return value !== null && valid(value) ? value : defaultValue;
|
|
197
|
+
},
|
|
198
|
+
write(value) {
|
|
199
|
+
return { [key]: value === defaultValue ? null : value };
|
|
200
|
+
},
|
|
201
|
+
valid,
|
|
202
|
+
same: (left, right) => left === right
|
|
203
|
+
};
|
|
225
204
|
}
|
|
226
|
-
function multiChoiceVariable({
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return defaultValue;
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
write(value) {
|
|
266
|
-
return {
|
|
267
|
-
[key]: same(value, defaultValue) ? null : JSON.stringify(options.filter((option) => value.includes(option.id)).map((option) => option.id))
|
|
268
|
-
};
|
|
269
|
-
},
|
|
270
|
-
valid,
|
|
271
|
-
same
|
|
272
|
-
};
|
|
205
|
+
function multiChoiceVariable({ key, label, defaultValue = [], options, maxSelected = options.length, history = "push", presentation }) {
|
|
206
|
+
validateChoiceOptions(options);
|
|
207
|
+
invariant(Number.isSafeInteger(maxSelected) && maxSelected >= 1 && maxSelected <= options.length, "Invalid choice selection limit.");
|
|
208
|
+
function valid(value) {
|
|
209
|
+
return Array.isArray(value) && value.length <= maxSelected && new Set(value).size === value.length && value.every((id) => options.some((option) => option.id === id));
|
|
210
|
+
}
|
|
211
|
+
function same(left, right) {
|
|
212
|
+
return left.length === right.length && left.every((id) => right.includes(id));
|
|
213
|
+
}
|
|
214
|
+
invariant(valid(defaultValue), `Invalid default choices for ${key}.`);
|
|
215
|
+
return {
|
|
216
|
+
kind: "multiChoice",
|
|
217
|
+
presentation,
|
|
218
|
+
label: label ?? key,
|
|
219
|
+
options,
|
|
220
|
+
maxSelected,
|
|
221
|
+
urlKeys: [key],
|
|
222
|
+
defaultValue,
|
|
223
|
+
history,
|
|
224
|
+
describe: (values) => values.map((id) => options.find((option) => option.id === id).label).join(", ") || "None",
|
|
225
|
+
read(params) {
|
|
226
|
+
const raw = params.get(key);
|
|
227
|
+
if (raw === null || raw.length > 4096) return defaultValue;
|
|
228
|
+
try {
|
|
229
|
+
const values = JSON.parse(raw);
|
|
230
|
+
return valid(values) ? values : defaultValue;
|
|
231
|
+
} catch {
|
|
232
|
+
return defaultValue;
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
write(value) {
|
|
236
|
+
return { [key]: same(value, defaultValue) ? null : JSON.stringify(options.filter((option) => value.includes(option.id)).map((option) => option.id)) };
|
|
237
|
+
},
|
|
238
|
+
valid,
|
|
239
|
+
same
|
|
240
|
+
};
|
|
273
241
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
242
|
+
const PRESET_IDS = /* @__PURE__ */ new Set([
|
|
243
|
+
"day",
|
|
244
|
+
"last-3",
|
|
245
|
+
"last-7",
|
|
246
|
+
"last-14",
|
|
247
|
+
"last-30",
|
|
248
|
+
"last-90",
|
|
249
|
+
"this-week",
|
|
250
|
+
"previous-week",
|
|
251
|
+
"this-month",
|
|
252
|
+
"previous-month"
|
|
285
253
|
]);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
254
|
+
/** A date variable keeps relative presets relative and validates exact dates against source coverage. */
|
|
255
|
+
function dateRangeVariable({ key, label = "Date range", defaultValue, contract, history = "push", comparison = false, presentation }) {
|
|
256
|
+
const startKey = key === "period" ? "start" : [key, "start"].join("-");
|
|
257
|
+
const endKey = key === "period" ? "end" : [key, "end"].join("-");
|
|
258
|
+
const comparisonKey = key === "period" ? "compare" : [key, "compare"].join("-");
|
|
259
|
+
const bounds = contract.bounds;
|
|
260
|
+
function resolve(selection) {
|
|
261
|
+
const limits = bounds();
|
|
262
|
+
if (selection.kind === "preset") {
|
|
263
|
+
const preset = availableDatePresets(limits).find((item) => item.id === selection.id);
|
|
264
|
+
if (preset) return preset.range;
|
|
265
|
+
} else try {
|
|
266
|
+
return contract.parse(selection);
|
|
267
|
+
} catch {}
|
|
268
|
+
invariant(false, `Date variable ${key} is outside its available data range.`);
|
|
269
|
+
}
|
|
270
|
+
function same(left, right) {
|
|
271
|
+
return left.kind === right.kind && left.comparison === right.comparison && (left.kind === "preset" && right.kind === "preset" ? left.id === right.id : left.kind === "dates" && right.kind === "dates" && left.start === right.start && left.end === right.end);
|
|
272
|
+
}
|
|
273
|
+
const variable = {
|
|
274
|
+
kind: "dateRange",
|
|
275
|
+
presentation,
|
|
276
|
+
label,
|
|
277
|
+
describe: (selection) => contract.describeInput(variable.input(selection).range),
|
|
278
|
+
supportsComparison: comparison,
|
|
279
|
+
input(selection) {
|
|
280
|
+
return contract.request(resolve(selection), selection.comparison === "previous" && comparison);
|
|
281
|
+
},
|
|
282
|
+
describeInput(input) {
|
|
283
|
+
return contract.describeInput(input.range);
|
|
284
|
+
},
|
|
285
|
+
urlKeys: comparison ? [
|
|
286
|
+
key,
|
|
287
|
+
startKey,
|
|
288
|
+
endKey,
|
|
289
|
+
comparisonKey
|
|
290
|
+
] : [
|
|
291
|
+
key,
|
|
292
|
+
startKey,
|
|
293
|
+
endKey
|
|
294
|
+
],
|
|
295
|
+
defaultValue,
|
|
296
|
+
clearValue: defaultValue,
|
|
297
|
+
history,
|
|
298
|
+
bounds,
|
|
299
|
+
resolve,
|
|
300
|
+
previous(selection) {
|
|
301
|
+
return comparison ? contract.comparison(resolve(selection)) : null;
|
|
302
|
+
},
|
|
303
|
+
comparisonRange(selection) {
|
|
304
|
+
return selection.comparison === "previous" && comparison ? contract.comparison(resolve(selection)) : null;
|
|
305
|
+
},
|
|
306
|
+
same,
|
|
307
|
+
valid(value) {
|
|
308
|
+
try {
|
|
309
|
+
const range = resolve(value);
|
|
310
|
+
return value.comparison === void 0 || value.comparison === "previous" && comparison && contract.comparison(range) !== null;
|
|
311
|
+
} catch {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
read(params) {
|
|
316
|
+
function withComparison(selection) {
|
|
317
|
+
if (!comparison || params.get(comparisonKey) !== "previous") return selection;
|
|
318
|
+
const selected = {
|
|
319
|
+
...selection,
|
|
320
|
+
comparison: "previous"
|
|
321
|
+
};
|
|
322
|
+
return variable.valid(selected) ? selected : selection;
|
|
323
|
+
}
|
|
324
|
+
const presetId = params.get(key);
|
|
325
|
+
if (presetId && PRESET_IDS.has(presetId)) {
|
|
326
|
+
const selection = {
|
|
327
|
+
kind: "preset",
|
|
328
|
+
id: presetId
|
|
329
|
+
};
|
|
330
|
+
if (variable.valid(selection)) return withComparison(selection);
|
|
331
|
+
}
|
|
332
|
+
const start = params.get(startKey);
|
|
333
|
+
const end = params.get(endKey);
|
|
334
|
+
if (start && end) {
|
|
335
|
+
const selection = {
|
|
336
|
+
kind: "dates",
|
|
337
|
+
start,
|
|
338
|
+
end
|
|
339
|
+
};
|
|
340
|
+
if (variable.valid(selection)) return withComparison(selection);
|
|
341
|
+
}
|
|
342
|
+
return withComparison(defaultValue);
|
|
343
|
+
},
|
|
344
|
+
write(value) {
|
|
345
|
+
return {
|
|
346
|
+
...same(value, defaultValue) ? {
|
|
347
|
+
[key]: null,
|
|
348
|
+
[startKey]: null,
|
|
349
|
+
[endKey]: null
|
|
350
|
+
} : value.kind === "preset" ? {
|
|
351
|
+
[key]: value.id,
|
|
352
|
+
[startKey]: null,
|
|
353
|
+
[endKey]: null
|
|
354
|
+
} : {
|
|
355
|
+
[key]: null,
|
|
356
|
+
[startKey]: value.start,
|
|
357
|
+
[endKey]: value.end
|
|
358
|
+
},
|
|
359
|
+
...comparison ? { [comparisonKey]: value.comparison ?? null } : {}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
invariant(variable.valid(defaultValue), `Date variable ${key} has a default outside its available data range.`);
|
|
364
|
+
return variable;
|
|
382
365
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
REQUEST_TIMEOUT_MS2 as REQUEST_TIMEOUT_MS,
|
|
390
|
-
RequestBodyTooLargeError2 as RequestBodyTooLargeError,
|
|
391
|
-
availableDatePresets,
|
|
392
|
-
choiceVariable,
|
|
393
|
-
createBridgeEndpoint2 as createBridgeEndpoint,
|
|
394
|
-
createDimensionFilter2 as createDimensionFilter,
|
|
395
|
-
dateRangeVariable,
|
|
396
|
-
defineAppVariables,
|
|
397
|
-
dimensionMemberKey2 as dimensionMemberKey,
|
|
398
|
-
dimensionSource2 as dimensionSource,
|
|
399
|
-
displayedSnapshot,
|
|
400
|
-
downloadBlob,
|
|
401
|
-
facetSource,
|
|
402
|
-
inclusiveDays,
|
|
403
|
-
invariant2 as invariant,
|
|
404
|
-
isDataAppPresentation,
|
|
405
|
-
localFrameBridge2 as localFrameBridge,
|
|
406
|
-
multiChoiceVariable,
|
|
407
|
-
numberOperatorLabels2 as numberOperatorLabels,
|
|
408
|
-
randomUuid2 as randomUuid,
|
|
409
|
-
readRequestBody2 as readRequestBody,
|
|
410
|
-
resolveDataView,
|
|
411
|
-
searchVariable,
|
|
412
|
-
toDataOperationFailure2 as toDataOperationFailure,
|
|
413
|
-
validId2 as validId,
|
|
414
|
-
validateChoiceOptions,
|
|
415
|
-
withinBounds
|
|
416
|
-
};
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/core/facets.ts
|
|
368
|
+
/** Executable facet sources are attached only by the typed hooks factory. */
|
|
369
|
+
const facetSource = Symbol("data-app.facetSource");
|
|
370
|
+
//#endregion
|
|
371
|
+
export { KEY_SEPARATOR, MAX_PENDING, PARENT_PARAM, REQUEST_TIMEOUT_MS, RequestBodyTooLargeError, availableDatePresets, choiceVariable, createBridgeEndpoint, createDimensionFilter, dateRangeVariable, defineAppVariables, dimensionMemberKey, dimensionSource, displayedSnapshot, downloadBlob, facetSource, inclusiveDays, invariant, isDataAppPresentation, localFrameBridge, multiChoiceVariable, numberOperatorLabels, randomUuid, readRequestBody, resolveDataView, searchVariable, toDataOperationFailure, validId, validateChoiceOptions, withinBounds };
|
|
417
372
|
|
|
418
|
-
//#
|
|
373
|
+
//# sourceMappingURL=internal.js.map
|