@reforma/components 0.1.5 → 0.2.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/Scrollable/Scrollable.d.ts +1 -2
- package/dist/Scrollable/Scrollable.d.ts.map +1 -1
- package/dist/Scrollable/Scrollable.js +45 -38
- package/dist/Scrollable/Scrollable.js.map +1 -1
- package/dist/Scrollable/useScrollChrome.d.ts +1 -2
- package/dist/Scrollable/useScrollChrome.d.ts.map +1 -1
- package/dist/Scrollable/useScrollChrome.js +125 -110
- package/dist/Scrollable/useScrollChrome.js.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.d.ts +2 -1
- package/dist/chat/ComposerBanner/ComposerBanner.d.ts.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.js +37 -29
- package/dist/chat/ComposerBanner/ComposerBanner.js.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.module.css +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.module.css.js +5 -3
- package/dist/chat/ComposerBanner/ComposerBanner.module.css.js.map +1 -1
- package/dist/chat/Tool/agent/AgentTool.d.ts.map +1 -1
- package/dist/chat/Tool/agent/AgentTool.js +89 -90
- package/dist/chat/Tool/agent/AgentTool.js.map +1 -1
- package/dist/chat/Tool/edit/EditTool.js +1 -1
- package/dist/chat/Tool/edit/EditTool.js.map +1 -1
- package/dist/node_modules/zod/v4/classic/errors.js +38 -0
- package/dist/node_modules/zod/v4/classic/errors.js.map +1 -0
- package/dist/node_modules/zod/v4/classic/parse.js +21 -0
- package/dist/node_modules/zod/v4/classic/parse.js.map +1 -0
- package/dist/node_modules/zod/v4/classic/schemas.js +822 -0
- package/dist/node_modules/zod/v4/classic/schemas.js.map +1 -0
- package/dist/node_modules/zod/v4/core/api.js +561 -0
- package/dist/node_modules/zod/v4/core/api.js.map +1 -0
- package/dist/node_modules/zod/v4/core/checks.js +262 -0
- package/dist/node_modules/zod/v4/core/checks.js.map +1 -0
- package/dist/node_modules/zod/v4/core/core.js +97 -0
- package/dist/node_modules/zod/v4/core/core.js.map +1 -0
- package/dist/node_modules/zod/v4/core/doc.js +35 -0
- package/dist/node_modules/zod/v4/core/doc.js.map +1 -0
- package/dist/node_modules/zod/v4/core/errors.js +79 -0
- package/dist/node_modules/zod/v4/core/errors.js.map +1 -0
- package/dist/node_modules/zod/v4/core/json-schema-processors.js +308 -0
- package/dist/node_modules/zod/v4/core/json-schema-processors.js.map +1 -0
- package/dist/node_modules/zod/v4/core/memoizer.js +203 -0
- package/dist/node_modules/zod/v4/core/memoizer.js.map +1 -0
- package/dist/node_modules/zod/v4/core/parse.js +113 -0
- package/dist/node_modules/zod/v4/core/parse.js.map +1 -0
- package/dist/node_modules/zod/v4/core/regexes.js +59 -0
- package/dist/node_modules/zod/v4/core/regexes.js.map +1 -0
- package/dist/node_modules/zod/v4/core/registries.js +41 -0
- package/dist/node_modules/zod/v4/core/registries.js.map +1 -0
- package/dist/node_modules/zod/v4/core/schemas.js +1104 -0
- package/dist/node_modules/zod/v4/core/schemas.js.map +1 -0
- package/dist/node_modules/zod/v4/core/to-json-schema.js +380 -0
- package/dist/node_modules/zod/v4/core/to-json-schema.js.map +1 -0
- package/dist/node_modules/zod/v4/core/util.js +465 -0
- package/dist/node_modules/zod/v4/core/util.js.map +1 -0
- package/dist/node_modules/zod/v4/core/versions.js +9 -0
- package/dist/node_modules/zod/v4/core/versions.js.map +1 -0
- package/dist/node_modules/zod/v4/locales/en.js +97 -0
- package/dist/node_modules/zod/v4/locales/en.js.map +1 -0
- package/dist/openui/actions.d.ts +16 -0
- package/dist/openui/actions.d.ts.map +1 -0
- package/dist/openui/actions.js +58 -0
- package/dist/openui/actions.js.map +1 -0
- package/dist/openui/components/controls.d.ts +34 -0
- package/dist/openui/components/controls.d.ts.map +1 -0
- package/dist/openui/components/controls.js +40 -0
- package/dist/openui/components/controls.js.map +1 -0
- package/dist/openui/components/layout.d.ts +74 -0
- package/dist/openui/components/layout.d.ts.map +1 -0
- package/dist/openui/components/layout.js +154 -0
- package/dist/openui/components/layout.js.map +1 -0
- package/dist/openui/components/list.d.ts +17 -0
- package/dist/openui/components/list.d.ts.map +1 -0
- package/dist/openui/components/list.js +96 -0
- package/dist/openui/components/list.js.map +1 -0
- package/dist/openui/components/svg.d.ts +100 -0
- package/dist/openui/components/svg.d.ts.map +1 -0
- package/dist/openui/components/svg.js +246 -0
- package/dist/openui/components/svg.js.map +1 -0
- package/dist/openui/components/table.d.ts +6 -0
- package/dist/openui/components/table.d.ts.map +1 -0
- package/dist/openui/components/table.js +54 -0
- package/dist/openui/components/table.js.map +1 -0
- package/dist/openui/components/text.d.ts +89 -0
- package/dist/openui/components/text.d.ts.map +1 -0
- package/dist/openui/components/text.js +181 -0
- package/dist/openui/components/text.js.map +1 -0
- package/dist/openui/functions/colors.d.ts +12 -0
- package/dist/openui/functions/colors.d.ts.map +1 -0
- package/dist/openui/functions/colors.js +32 -0
- package/dist/openui/functions/colors.js.map +1 -0
- package/dist/openui/functions/data.d.ts +170 -0
- package/dist/openui/functions/data.d.ts.map +1 -0
- package/dist/openui/functions/data.js +308 -0
- package/dist/openui/functions/data.js.map +1 -0
- package/dist/openui/functions/dates.d.ts +57 -0
- package/dist/openui/functions/dates.d.ts.map +1 -0
- package/dist/openui/functions/dates.js +184 -0
- package/dist/openui/functions/dates.js.map +1 -0
- package/dist/openui/functions/index.d.ts +136 -0
- package/dist/openui/functions/index.d.ts.map +1 -0
- package/dist/openui/functions/index.js +11 -0
- package/dist/openui/functions/index.js.map +1 -0
- package/dist/openui/functions/lists.d.ts +102 -0
- package/dist/openui/functions/lists.d.ts.map +1 -0
- package/dist/openui/functions/lists.js +305 -0
- package/dist/openui/functions/lists.js.map +1 -0
- package/dist/openui/functions/numbers.d.ts +72 -0
- package/dist/openui/functions/numbers.d.ts.map +1 -0
- package/dist/openui/functions/numbers.js +201 -0
- package/dist/openui/functions/numbers.js.map +1 -0
- package/dist/openui/functions/shared.d.ts +28 -0
- package/dist/openui/functions/shared.d.ts.map +1 -0
- package/dist/openui/functions/shared.js +69 -0
- package/dist/openui/functions/shared.js.map +1 -0
- package/dist/openui/functions/text.d.ts +97 -0
- package/dist/openui/functions/text.d.ts.map +1 -0
- package/dist/openui/functions/text.js +223 -0
- package/dist/openui/functions/text.js.map +1 -0
- package/dist/openui/index.d.ts +5 -0
- package/dist/openui/index.d.ts.map +1 -0
- package/dist/openui/index.js +14 -0
- package/dist/openui/index.js.map +1 -0
- package/dist/openui/library.d.ts +8 -0
- package/dist/openui/library.d.ts.map +1 -0
- package/dist/openui/library.js +37 -0
- package/dist/openui/library.js.map +1 -0
- package/dist/openui/schema.d.ts +36 -0
- package/dist/openui/schema.d.ts.map +1 -0
- package/dist/openui/schema.js +24 -0
- package/dist/openui/schema.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { defineFunction as w } from "@openuidev/react-lang";
|
|
2
|
+
import { parseDate as _, isoDay as S } from "./dates.js";
|
|
3
|
+
import { groups as k, aggregate as b, agg as x, toNum as v, read as M, list as g, MAX_ITEMS as F, finite as q, numbers as A } from "./shared.js";
|
|
4
|
+
import { object as d, string as f, array as C, record as z, union as P, enum as E, any as U, number as c } from "../../node_modules/zod/v4/classic/schemas.js";
|
|
5
|
+
const K = () => C(d({
|
|
6
|
+
key: P([f(), c()]),
|
|
7
|
+
value: c()
|
|
8
|
+
})), N = (t) => t.filter((e) => typeof e == "number" && Number.isFinite(e)), Y = (t, e) => e ?? (t ? "sum" : "count");
|
|
9
|
+
function O(t, e, n) {
|
|
10
|
+
return t.map((o, a) => e ? {
|
|
11
|
+
...o,
|
|
12
|
+
[e]: n[a]
|
|
13
|
+
} : n[a]);
|
|
14
|
+
}
|
|
15
|
+
const G = w({
|
|
16
|
+
name: "GroupBy",
|
|
17
|
+
description: 'One row per distinct key, in first-seen order; value is agg of field (default "sum"), or the row count without a field',
|
|
18
|
+
params: d({
|
|
19
|
+
rows: g(),
|
|
20
|
+
key: f(),
|
|
21
|
+
field: f().optional(),
|
|
22
|
+
agg: x().optional()
|
|
23
|
+
}),
|
|
24
|
+
returns: K(),
|
|
25
|
+
fn: ({
|
|
26
|
+
rows: t,
|
|
27
|
+
key: e,
|
|
28
|
+
field: n,
|
|
29
|
+
agg: o
|
|
30
|
+
}) => [...k(t, e)].map(([a, r]) => ({
|
|
31
|
+
key: a,
|
|
32
|
+
value: b(r, n, Y(n, o))
|
|
33
|
+
}))
|
|
34
|
+
}), H = w({
|
|
35
|
+
name: "Pivot",
|
|
36
|
+
description: "One row per rowKey value with a column per colKey value holding agg of field, for stacked or grouped charts",
|
|
37
|
+
params: d({
|
|
38
|
+
rows: g(),
|
|
39
|
+
rowKey: f(),
|
|
40
|
+
colKey: f(),
|
|
41
|
+
field: f().optional(),
|
|
42
|
+
agg: x().optional()
|
|
43
|
+
}),
|
|
44
|
+
returns: C(z(f(), P([f(), c()]))),
|
|
45
|
+
fn: ({
|
|
46
|
+
rows: t,
|
|
47
|
+
rowKey: e,
|
|
48
|
+
colKey: n,
|
|
49
|
+
field: o,
|
|
50
|
+
agg: a
|
|
51
|
+
}) => {
|
|
52
|
+
const r = [...k(t, n).keys()].map(String);
|
|
53
|
+
return [...k(t, e)].map(([s, i]) => {
|
|
54
|
+
const l = {
|
|
55
|
+
key: s
|
|
56
|
+
};
|
|
57
|
+
for (const m of r) l[m] = 0;
|
|
58
|
+
for (const [m, p] of k(i, n)) l[String(m)] = b(p, o, Y(o, a));
|
|
59
|
+
return l;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}), R = w({
|
|
63
|
+
name: "Top",
|
|
64
|
+
description: 'The n rows with the largest field ("asc": the smallest)',
|
|
65
|
+
params: d({
|
|
66
|
+
rows: g(),
|
|
67
|
+
field: f(),
|
|
68
|
+
n: c(),
|
|
69
|
+
direction: E(["desc", "asc"]).optional()
|
|
70
|
+
}),
|
|
71
|
+
returns: g(),
|
|
72
|
+
fn: ({
|
|
73
|
+
rows: t,
|
|
74
|
+
field: e,
|
|
75
|
+
n,
|
|
76
|
+
direction: o = "desc"
|
|
77
|
+
}) => {
|
|
78
|
+
const a = o === "asc" ? 1 : -1;
|
|
79
|
+
return t.map((s, i) => ({
|
|
80
|
+
row: s,
|
|
81
|
+
i,
|
|
82
|
+
v: v(M(s, e))
|
|
83
|
+
})).sort((s, i) => s.v === null || i.v === null ? s.v === i.v ? s.i - i.i : s.v === null ? 1 : -1 : (s.v - i.v) * a || s.i - i.i).slice(0, Math.max(0, Math.trunc(n))).map((s) => s.row);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
function B(t, e) {
|
|
87
|
+
const n = v(t), o = v(e);
|
|
88
|
+
if (n !== null && o !== null) return n - o;
|
|
89
|
+
const a = String(t), r = String(e);
|
|
90
|
+
return a < r ? -1 : a > r ? 1 : 0;
|
|
91
|
+
}
|
|
92
|
+
const j = w({
|
|
93
|
+
name: "Between",
|
|
94
|
+
description: 'Rows whose field is from min to max, both included; compares numbers, or text such as "YYYY-MM-DD" dates. Leave min or max null for an open end',
|
|
95
|
+
params: d({
|
|
96
|
+
rows: g(),
|
|
97
|
+
field: f(),
|
|
98
|
+
min: U().optional(),
|
|
99
|
+
max: U().optional()
|
|
100
|
+
}),
|
|
101
|
+
returns: g(),
|
|
102
|
+
fn: ({
|
|
103
|
+
rows: t,
|
|
104
|
+
field: e,
|
|
105
|
+
min: n,
|
|
106
|
+
max: o
|
|
107
|
+
}) => t.filter((a) => {
|
|
108
|
+
const r = M(a, e);
|
|
109
|
+
return r == null ? !1 : (n == null || B(r, n) >= 0) && (o == null || B(r, o) <= 0);
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
function I(t, e) {
|
|
113
|
+
if (e === "day") return t;
|
|
114
|
+
if (e === "week") return t - (new Date(t * 864e5).getUTCDay() + 6) % 7;
|
|
115
|
+
const n = new Date(t * 864e5);
|
|
116
|
+
return Date.UTC(n.getUTCFullYear(), n.getUTCMonth(), 1) / 864e5;
|
|
117
|
+
}
|
|
118
|
+
function L(t, e) {
|
|
119
|
+
if (e === "day") return t + 1;
|
|
120
|
+
if (e === "week") return t + 7;
|
|
121
|
+
const n = new Date(t * 864e5);
|
|
122
|
+
return Date.UTC(n.getUTCFullYear(), n.getUTCMonth() + 1, 1) / 864e5;
|
|
123
|
+
}
|
|
124
|
+
const V = w({
|
|
125
|
+
name: "Bucket",
|
|
126
|
+
description: 'Rows per day, week (from Monday) or month of dateField, in date order, empty periods 0 for sum and count; key is "YYYY-MM-DD", or "YYYY-MM" for months',
|
|
127
|
+
params: d({
|
|
128
|
+
rows: g(),
|
|
129
|
+
dateField: f(),
|
|
130
|
+
unit: E(["day", "week", "month"]),
|
|
131
|
+
field: f().optional(),
|
|
132
|
+
agg: x().optional()
|
|
133
|
+
}),
|
|
134
|
+
returns: K(),
|
|
135
|
+
fn: ({
|
|
136
|
+
rows: t,
|
|
137
|
+
dateField: e,
|
|
138
|
+
unit: n,
|
|
139
|
+
field: o,
|
|
140
|
+
agg: a
|
|
141
|
+
}) => {
|
|
142
|
+
const r = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const u of t) {
|
|
144
|
+
const h = M(u, e);
|
|
145
|
+
if (typeof h != "string" && typeof h != "number") continue;
|
|
146
|
+
let y;
|
|
147
|
+
try {
|
|
148
|
+
y = _(h).day;
|
|
149
|
+
} catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const D = I(y, n), T = r.get(D);
|
|
153
|
+
T ? T.push(u) : r.set(D, [u]);
|
|
154
|
+
}
|
|
155
|
+
if (!r.size) return [];
|
|
156
|
+
const s = Y(o, a), i = s === "sum" || s === "count", l = (u) => n === "month" ? S(u).slice(0, 7) : S(u), m = [...r.keys()].sort((u, h) => u - h), p = [];
|
|
157
|
+
for (let u = m[0]; u <= m[m.length - 1]; u = L(u, n)) {
|
|
158
|
+
const h = r.get(u);
|
|
159
|
+
if (h ? p.push({
|
|
160
|
+
key: l(u),
|
|
161
|
+
value: b(h, o, s)
|
|
162
|
+
}) : i && p.push({
|
|
163
|
+
key: l(u),
|
|
164
|
+
value: 0
|
|
165
|
+
}), p.length > F) throw new Error(`more than ${F} periods`);
|
|
166
|
+
}
|
|
167
|
+
return p;
|
|
168
|
+
}
|
|
169
|
+
}), X = w({
|
|
170
|
+
name: "Cumulative",
|
|
171
|
+
description: 'Copy of the rows with field replaced by its running total (field "" for a list of numbers)',
|
|
172
|
+
params: d({
|
|
173
|
+
rows: g(),
|
|
174
|
+
field: f()
|
|
175
|
+
}),
|
|
176
|
+
returns: g(),
|
|
177
|
+
fn: ({
|
|
178
|
+
rows: t,
|
|
179
|
+
field: e
|
|
180
|
+
}) => {
|
|
181
|
+
let n = 0;
|
|
182
|
+
return O(t, e, t.map((o) => n += v(M(o, e)) ?? 0));
|
|
183
|
+
}
|
|
184
|
+
}), $ = w({
|
|
185
|
+
name: "MovingAvg",
|
|
186
|
+
description: 'Copy of the rows with field replaced by the average of its last window values (field "" for a list of numbers)',
|
|
187
|
+
params: d({
|
|
188
|
+
rows: g(),
|
|
189
|
+
field: f(),
|
|
190
|
+
window: c()
|
|
191
|
+
}),
|
|
192
|
+
returns: g(),
|
|
193
|
+
fn: ({
|
|
194
|
+
rows: t,
|
|
195
|
+
field: e,
|
|
196
|
+
window: n
|
|
197
|
+
}) => {
|
|
198
|
+
const o = Math.trunc(n);
|
|
199
|
+
if (o < 1) throw new Error("window must be at least 1");
|
|
200
|
+
const a = t.map((s) => v(M(s, e)) ?? 0), r = a.map((s, i) => {
|
|
201
|
+
const l = a.slice(Math.max(0, i - o + 1), i + 1);
|
|
202
|
+
return l.reduce((m, p) => m + p, 0) / l.length;
|
|
203
|
+
});
|
|
204
|
+
return O(t, e, r);
|
|
205
|
+
}
|
|
206
|
+
}), J = w({
|
|
207
|
+
name: "Change",
|
|
208
|
+
description: "Percent change from previous to current, e.g. @Change(120, 100) is 20; null when previous is 0",
|
|
209
|
+
params: d({
|
|
210
|
+
current: c(),
|
|
211
|
+
previous: c()
|
|
212
|
+
}),
|
|
213
|
+
returns: c().nullable(),
|
|
214
|
+
// No previous value is normal while data loads, so it is null without an error
|
|
215
|
+
fn: ({
|
|
216
|
+
current: t,
|
|
217
|
+
previous: e
|
|
218
|
+
}) => e === 0 ? null : q((t - e) / Math.abs(e) * 100)
|
|
219
|
+
}), Q = w({
|
|
220
|
+
name: "Histogram",
|
|
221
|
+
description: "Counts numbers into equal-width bins (value is the count); min and max fix the range, default the data's",
|
|
222
|
+
params: d({
|
|
223
|
+
values: A(),
|
|
224
|
+
bins: c(),
|
|
225
|
+
min: c().optional(),
|
|
226
|
+
max: c().optional()
|
|
227
|
+
}),
|
|
228
|
+
returns: C(d({
|
|
229
|
+
key: f(),
|
|
230
|
+
value: c(),
|
|
231
|
+
start: c(),
|
|
232
|
+
end: c()
|
|
233
|
+
})),
|
|
234
|
+
fn: ({
|
|
235
|
+
values: t,
|
|
236
|
+
bins: e,
|
|
237
|
+
min: n,
|
|
238
|
+
max: o
|
|
239
|
+
}) => {
|
|
240
|
+
const a = N(t), r = Math.trunc(e);
|
|
241
|
+
if (r < 1 || r > 500) throw new Error("bins must be from 1 to 500");
|
|
242
|
+
const s = n ?? (a.length ? Math.min(...a) : 0);
|
|
243
|
+
let i = o ?? (a.length ? Math.max(...a) : 1);
|
|
244
|
+
i <= s && (i = s + 1);
|
|
245
|
+
const l = (i - s) / r, m = Math.max(0, 1 - Math.floor(Math.log10(l))), p = new Array(r).fill(0);
|
|
246
|
+
for (const u of a)
|
|
247
|
+
u < s || u > i || p[Math.min(r - 1, Math.floor((u - s) / l))]++;
|
|
248
|
+
return p.map((u, h) => {
|
|
249
|
+
const y = s + h * l;
|
|
250
|
+
return {
|
|
251
|
+
key: String(Number(y.toFixed(m))),
|
|
252
|
+
value: u,
|
|
253
|
+
start: y,
|
|
254
|
+
end: y + l
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}), W = w({
|
|
259
|
+
name: "Stats",
|
|
260
|
+
description: "Summary of numbers, all zeros for an empty list",
|
|
261
|
+
params: d({
|
|
262
|
+
values: A()
|
|
263
|
+
}),
|
|
264
|
+
returns: d({
|
|
265
|
+
count: c(),
|
|
266
|
+
min: c(),
|
|
267
|
+
max: c(),
|
|
268
|
+
mean: c(),
|
|
269
|
+
median: c(),
|
|
270
|
+
stdev: c()
|
|
271
|
+
}),
|
|
272
|
+
fn: ({
|
|
273
|
+
values: t
|
|
274
|
+
}) => {
|
|
275
|
+
const e = N(t), n = e.length;
|
|
276
|
+
if (!n) return {
|
|
277
|
+
count: 0,
|
|
278
|
+
min: 0,
|
|
279
|
+
max: 0,
|
|
280
|
+
mean: 0,
|
|
281
|
+
median: 0,
|
|
282
|
+
stdev: 0
|
|
283
|
+
};
|
|
284
|
+
const o = [...e].sort((l, m) => l - m), a = e.reduce((l, m) => l + m, 0) / n, r = Math.floor(n / 2), s = n % 2 ? o[r] : (o[r - 1] + o[r]) / 2, i = Math.sqrt(e.reduce((l, m) => l + (m - a) ** 2, 0) / n);
|
|
285
|
+
return {
|
|
286
|
+
count: n,
|
|
287
|
+
min: o[0],
|
|
288
|
+
max: o[n - 1],
|
|
289
|
+
mean: a,
|
|
290
|
+
median: s,
|
|
291
|
+
stdev: i
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}), oe = [G, H, R, j, V, X, $, J, Q, W];
|
|
295
|
+
export {
|
|
296
|
+
j as Between,
|
|
297
|
+
V as Bucket,
|
|
298
|
+
J as Change,
|
|
299
|
+
X as Cumulative,
|
|
300
|
+
G as GroupBy,
|
|
301
|
+
Q as Histogram,
|
|
302
|
+
$ as MovingAvg,
|
|
303
|
+
H as Pivot,
|
|
304
|
+
W as Stats,
|
|
305
|
+
R as Top,
|
|
306
|
+
oe as dataFunctions
|
|
307
|
+
};
|
|
308
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sources":["../../../src/openui/functions/data.ts"],"sourcesContent":["import { defineFunction } from \"@openuidev/react-lang\";\nimport { z } from \"zod/v4\";\nimport { isoDay, parseDate } from \"./dates\";\nimport { agg, aggregate, finite, groups, list, MAX_ITEMS, numbers, read, toNum, type Agg } from \"./shared\";\n\nconst keyValue = () => z.array(z.object({ key: z.union([z.string(), z.number()]), value: z.number() }));\n// Untyped arrays (a pluck over rows that lack the field) can still hold nulls\nconst finiteOnly = (values: unknown[]) => values.filter((v): v is number => typeof v === \"number\" && Number.isFinite(v));\nconst defaultAgg = (field: string | undefined, how: Agg | undefined): Agg => how ?? (field ? \"sum\" : \"count\");\n\n/** Copy of each row with `field` replaced; field \"\" maps a list of numbers. */\nfunction mapField(rows: unknown[], field: string, values: number[]): unknown[] {\n return rows.map((row, i) => (field ? { ...(row as object), [field]: values[i] } : values[i]));\n}\n\nexport const GroupBy = defineFunction({\n name: \"GroupBy\",\n description:\n 'One row per distinct key, in first-seen order; value is agg of field (default \"sum\"), or the row count without a field',\n params: z.object({ rows: list(), key: z.string(), field: z.string().optional(), agg: agg().optional() }),\n returns: keyValue(),\n fn: ({ rows, key, field, agg: how }) =>\n [...groups(rows, key)].map(([k, members]) => ({ key: k, value: aggregate(members, field, defaultAgg(field, how)) })),\n});\n\nexport const Pivot = defineFunction({\n name: \"Pivot\",\n description: \"One row per rowKey value with a column per colKey value holding agg of field, for stacked or grouped charts\",\n params: z.object({\n rows: list(),\n rowKey: z.string(),\n colKey: z.string(),\n field: z.string().optional(),\n agg: agg().optional(),\n }),\n returns: z.array(z.record(z.string(), z.union([z.string(), z.number()]))),\n fn: ({ rows, rowKey, colKey, field, agg: how }) => {\n const cols = [...groups(rows, colKey).keys()].map(String);\n return [...groups(rows, rowKey)].map(([k, members]) => {\n const out: Record<string, string | number> = { key: k };\n for (const col of cols) out[col] = 0;\n for (const [c, cell] of groups(members, colKey)) out[String(c)] = aggregate(cell, field, defaultAgg(field, how));\n return out;\n });\n },\n});\n\nexport const Top = defineFunction({\n name: \"Top\",\n description: 'The n rows with the largest field (\"asc\": the smallest)',\n params: z.object({ rows: list(), field: z.string(), n: z.number(), direction: z.enum([\"desc\", \"asc\"]).optional() }),\n returns: list(),\n fn: ({ rows, field, n, direction = \"desc\" }) => {\n const sign = direction === \"asc\" ? 1 : -1;\n const ranked = rows\n .map((row, i) => ({ row, i, v: toNum(read(row, field)) }))\n .sort((a, b) => {\n if (a.v === null || b.v === null) return a.v === b.v ? a.i - b.i : a.v === null ? 1 : -1;\n return (a.v - b.v) * sign || a.i - b.i;\n });\n return ranked.slice(0, Math.max(0, Math.trunc(n))).map((r) => r.row);\n },\n});\n\n/** Orders two field values: numbers by value, anything else (such as \"YYYY-MM-DD\") as text. */\nfunction compare(a: unknown, b: unknown): number {\n const x = toNum(a);\n const y = toNum(b);\n if (x !== null && y !== null) return x - y;\n const s = String(a);\n const t = String(b);\n return s < t ? -1 : s > t ? 1 : 0;\n}\n\nexport const Between = defineFunction({\n name: \"Between\",\n description:\n 'Rows whose field is from min to max, both included; compares numbers, or text such as \"YYYY-MM-DD\" dates. Leave min or max null for an open end',\n params: z.object({ rows: list(), field: z.string(), min: z.any().optional(), max: z.any().optional() }),\n returns: list(),\n fn: ({ rows, field, min, max }) =>\n rows.filter((row) => {\n const v = read(row, field);\n if (v == null) return false;\n return (min == null || compare(v, min) >= 0) && (max == null || compare(v, max) <= 0);\n }),\n});\n\nfunction periodStart(day: number, unit: \"day\" | \"week\" | \"month\"): number {\n if (unit === \"day\") return day;\n if (unit === \"week\") return day - ((new Date(day * 86_400_000).getUTCDay() + 6) % 7); // Monday\n const d = new Date(day * 86_400_000);\n return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1) / 86_400_000;\n}\n\nfunction nextPeriod(start: number, unit: \"day\" | \"week\" | \"month\"): number {\n if (unit === \"day\") return start + 1;\n if (unit === \"week\") return start + 7;\n const d = new Date(start * 86_400_000);\n return Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1) / 86_400_000;\n}\n\nexport const Bucket = defineFunction({\n name: \"Bucket\",\n description:\n 'Rows per day, week (from Monday) or month of dateField, in date order, empty periods 0 for sum and count; key is \"YYYY-MM-DD\", or \"YYYY-MM\" for months',\n params: z.object({\n rows: list(),\n dateField: z.string(),\n unit: z.enum([\"day\", \"week\", \"month\"]),\n field: z.string().optional(),\n agg: agg().optional(),\n }),\n returns: keyValue(),\n fn: ({ rows, dateField, unit, field, agg: how }) => {\n const byPeriod = new Map<number, unknown[]>();\n for (const row of rows) {\n const raw = read(row, dateField);\n if (typeof raw !== \"string\" && typeof raw !== \"number\") continue;\n let day: number;\n try {\n day = parseDate(raw).day;\n } catch {\n continue;\n }\n const start = periodStart(day, unit);\n const bucket = byPeriod.get(start);\n if (bucket) bucket.push(row);\n else byPeriod.set(start, [row]);\n }\n if (!byPeriod.size) return [];\n const mode = defaultAgg(field, how);\n const fill = mode === \"sum\" || mode === \"count\";\n const label = (start: number) => (unit === \"month\" ? isoDay(start).slice(0, 7) : isoDay(start));\n const starts = [...byPeriod.keys()].sort((a, b) => a - b);\n const out: { key: string; value: number }[] = [];\n for (let s = starts[0]!; s <= starts[starts.length - 1]!; s = nextPeriod(s, unit)) {\n const members = byPeriod.get(s);\n if (members) out.push({ key: label(s), value: aggregate(members, field, mode) });\n else if (fill) out.push({ key: label(s), value: 0 });\n if (out.length > MAX_ITEMS) throw new Error(`more than ${MAX_ITEMS} periods`);\n }\n return out;\n },\n});\n\nexport const Cumulative = defineFunction({\n name: \"Cumulative\",\n description: 'Copy of the rows with field replaced by its running total (field \"\" for a list of numbers)',\n params: z.object({ rows: list(), field: z.string() }),\n returns: list(),\n fn: ({ rows, field }) => {\n let total = 0;\n return mapField(rows, field, rows.map((row) => (total += toNum(read(row, field)) ?? 0)));\n },\n});\n\nexport const MovingAvg = defineFunction({\n name: \"MovingAvg\",\n description: 'Copy of the rows with field replaced by the average of its last window values (field \"\" for a list of numbers)',\n params: z.object({ rows: list(), field: z.string(), window: z.number() }),\n returns: list(),\n fn: ({ rows, field, window }) => {\n const w = Math.trunc(window);\n if (w < 1) throw new Error(\"window must be at least 1\");\n const values = rows.map((row) => toNum(read(row, field)) ?? 0);\n const averages = values.map((_, i) => {\n const span = values.slice(Math.max(0, i - w + 1), i + 1);\n return span.reduce((a, b) => a + b, 0) / span.length;\n });\n return mapField(rows, field, averages);\n },\n});\n\nexport const Change = defineFunction({\n name: \"Change\",\n description: \"Percent change from previous to current, e.g. @Change(120, 100) is 20; null when previous is 0\",\n params: z.object({ current: z.number(), previous: z.number() }),\n returns: z.number().nullable(),\n // No previous value is normal while data loads, so it is null without an error\n fn: ({ current, previous }) => (previous === 0 ? null : finite(((current - previous) / Math.abs(previous)) * 100)),\n});\n\nexport const Histogram = defineFunction({\n name: \"Histogram\",\n description:\n \"Counts numbers into equal-width bins (value is the count); min and max fix the range, default the data's\",\n params: z.object({ values: numbers(), bins: z.number(), min: z.number().optional(), max: z.number().optional() }),\n returns: z.array(z.object({ key: z.string(), value: z.number(), start: z.number(), end: z.number() })),\n fn: ({ values: raw, bins, min, max }) => {\n const values = finiteOnly(raw);\n const n = Math.trunc(bins);\n if (n < 1 || n > 500) throw new Error(\"bins must be from 1 to 500\");\n const lo = min ?? (values.length ? Math.min(...values) : 0);\n let hi = max ?? (values.length ? Math.max(...values) : 1);\n if (hi <= lo) hi = lo + 1;\n const width = (hi - lo) / n;\n const decimals = Math.max(0, 1 - Math.floor(Math.log10(width)));\n const counts = new Array<number>(n).fill(0);\n for (const v of values) {\n if (v < lo || v > hi) continue;\n counts[Math.min(n - 1, Math.floor((v - lo) / width))]!++;\n }\n return counts.map((value, i) => {\n const start = lo + i * width;\n return { key: String(Number(start.toFixed(decimals))), value, start, end: start + width };\n });\n },\n});\n\nexport const Stats = defineFunction({\n name: \"Stats\",\n description: \"Summary of numbers, all zeros for an empty list\",\n params: z.object({ values: numbers() }),\n returns: z.object({\n count: z.number(),\n min: z.number(),\n max: z.number(),\n mean: z.number(),\n median: z.number(),\n stdev: z.number(),\n }),\n fn: ({ values: raw }) => {\n const values = finiteOnly(raw);\n const count = values.length;\n if (!count) return { count: 0, min: 0, max: 0, mean: 0, median: 0, stdev: 0 };\n const sorted = [...values].sort((a, b) => a - b);\n const mean = values.reduce((a, b) => a + b, 0) / count;\n const mid = Math.floor(count / 2);\n const median = count % 2 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2;\n const stdev = Math.sqrt(values.reduce((a, v) => a + (v - mean) ** 2, 0) / count);\n return { count, min: sorted[0]!, max: sorted[count - 1]!, mean, median, stdev };\n },\n});\n\nexport const dataFunctions = [GroupBy, Pivot, Top, Between, Bucket, Cumulative, MovingAvg, Change, Histogram, Stats];\n"],"names":["keyValue","z.array","z.object","z.union","z.string","z.number","finiteOnly","values","v","defaultAgg","field","how","mapField","rows","row","i","GroupBy","defineFunction","list","agg","key","groups","k","members","aggregate","Pivot","z.record","rowKey","colKey","cols","out","col","c","cell","Top","z.enum","direction","sign","toNum","read","a","b","r","compare","x","y","s","t","Between","z.any","min","max","periodStart","day","unit","d","nextPeriod","start","Bucket","dateField","byPeriod","raw","parseDate","bucket","mode","fill","label","isoDay","starts","MAX_ITEMS","Cumulative","total","MovingAvg","window","w","averages","_","span","Change","current","previous","finite","Histogram","numbers","bins","n","lo","hi","width","decimals","counts","value","Stats","count","sorted","mean","mid","median","stdev","dataFunctions"],"mappings":";;;;AAIA,MAAMA,IAAW,MAAMC,EAAQC,EAAS;AAAA,EACtC,KAAKC,EAAQ,CAACC,KAAYC,EAAE,CAAQ,CAAC;AAAA,EACrC,OAAOA,EAAE;AACX,CAAC,CAAC,GAEIC,IAAa,CAAAC,MAAUA,EAAO,OAAO,CAAAC,MAAK,OAAOA,KAAM,YAAY,OAAO,SAASA,CAAC,CAAC,GACrFC,IAAa,CAACC,GAAOC,MAAQA,MAAQD,IAAQ,QAAQ;AAG3D,SAASE,EAASC,GAAMH,GAAOH,GAAQ;AACrC,SAAOM,EAAK,IAAI,CAACC,GAAKC,MAAML,IAAQ;AAAA,IA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|
|
2
|
+
/**
|
|
3
|
+
* A date as a calendar day (days since 1970-01-01) plus, for a timestamp, the
|
|
4
|
+
* instant. "YYYY-MM-DD" is a calendar date with no time zone; a timestamp or an
|
|
5
|
+
* ISO date-time is read in the viewer's time zone.
|
|
6
|
+
*/
|
|
7
|
+
type Parsed = {
|
|
8
|
+
day: number;
|
|
9
|
+
instant: Date | null;
|
|
10
|
+
};
|
|
11
|
+
export declare function parseDate(value: string | number): Parsed;
|
|
12
|
+
export declare function isoDay(day: number): string;
|
|
13
|
+
export declare const Now: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{}, z.core.$strip>, z.ZodString>;
|
|
14
|
+
export declare const FormatDate: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
15
|
+
date: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
16
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
17
|
+
date: "date";
|
|
18
|
+
datetime: "datetime";
|
|
19
|
+
iso: "iso";
|
|
20
|
+
long: "long";
|
|
21
|
+
month: "month";
|
|
22
|
+
short: "short";
|
|
23
|
+
time: "time";
|
|
24
|
+
weekday: "weekday";
|
|
25
|
+
}>>;
|
|
26
|
+
}, z.core.$strip>, z.ZodString>;
|
|
27
|
+
export declare const AddDays: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
28
|
+
date: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
29
|
+
days: z.ZodNumber;
|
|
30
|
+
}, z.core.$strip>, z.ZodString>;
|
|
31
|
+
export declare const DaysBetween: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
32
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
33
|
+
to: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
34
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
35
|
+
export declare const Today: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{}, z.core.$strip>, z.ZodString>;
|
|
36
|
+
export declare const AddMonths: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
37
|
+
date: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
38
|
+
months: z.ZodNumber;
|
|
39
|
+
}, z.core.$strip>, z.ZodString>;
|
|
40
|
+
export declare const MonthsBetween: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
41
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
42
|
+
to: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
43
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
44
|
+
export declare const StartOf: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
45
|
+
date: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
46
|
+
unit: z.ZodEnum<{
|
|
47
|
+
month: "month";
|
|
48
|
+
week: "week";
|
|
49
|
+
year: "year";
|
|
50
|
+
}>;
|
|
51
|
+
}, z.core.$strip>, z.ZodString>;
|
|
52
|
+
export declare const dateFunctions: (import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
53
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
54
|
+
to: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
55
|
+
}, z.core.$strip>, z.ZodNumber>)[];
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../../src/openui/functions/dates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B;;;;GAIG;AACH,KAAK,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAAC;AAEpD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAcxD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAYD,eAAO,MAAM,GAAG,6FAMd,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;+BAgBrB,CAAC;AAEH,eAAO,MAAM,OAAO;;;+BAMlB,CAAC;AAEH,eAAO,MAAM,WAAW;;;+BAMtB,CAAC;AAEH,eAAO,MAAM,KAAK,6FAMhB,CAAC;AAQH,eAAO,MAAM,SAAS;;;+BAWpB,CAAC;AAEH,eAAO,MAAM,aAAa;;;+BAaxB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;;;;+BAWlB,CAAC;AAEH,eAAO,MAAM,aAAa;;;kCAAoF,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { defineFunction as d } from "@openuidev/react-lang";
|
|
2
|
+
import { date as s } from "./shared.js";
|
|
3
|
+
import { string as u, object as m, enum as p, number as w } from "../../node_modules/zod/v4/classic/schemas.js";
|
|
4
|
+
const i = 864e5, Y = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
5
|
+
function o(e) {
|
|
6
|
+
if (typeof e == "string") {
|
|
7
|
+
const n = Y.exec(e.trim());
|
|
8
|
+
if (n) {
|
|
9
|
+
const [a, r, c] = [Number(n[1]), Number(n[2]), Number(n[3])], h = Date.UTC(a, r - 1, c), D = new Date(h);
|
|
10
|
+
if (D.getUTCMonth() !== r - 1 || D.getUTCDate() !== c) throw new Error(`invalid date "${e}"`);
|
|
11
|
+
return {
|
|
12
|
+
day: h / i,
|
|
13
|
+
instant: null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const t = new Date(e);
|
|
18
|
+
if (Number.isNaN(t.getTime())) throw new Error(`invalid date "${e}"`);
|
|
19
|
+
return {
|
|
20
|
+
day: Date.UTC(t.getFullYear(), t.getMonth(), t.getDate()) / i,
|
|
21
|
+
instant: t
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function y(e) {
|
|
25
|
+
return new Date(e * i).toISOString().slice(0, 10);
|
|
26
|
+
}
|
|
27
|
+
const l = {
|
|
28
|
+
date: {
|
|
29
|
+
month: "short",
|
|
30
|
+
day: "numeric",
|
|
31
|
+
year: "numeric"
|
|
32
|
+
},
|
|
33
|
+
short: {
|
|
34
|
+
month: "short",
|
|
35
|
+
day: "numeric"
|
|
36
|
+
},
|
|
37
|
+
long: {
|
|
38
|
+
weekday: "long",
|
|
39
|
+
month: "long",
|
|
40
|
+
day: "numeric",
|
|
41
|
+
year: "numeric"
|
|
42
|
+
},
|
|
43
|
+
weekday: {
|
|
44
|
+
weekday: "short"
|
|
45
|
+
},
|
|
46
|
+
month: {
|
|
47
|
+
month: "short",
|
|
48
|
+
year: "numeric"
|
|
49
|
+
},
|
|
50
|
+
time: {
|
|
51
|
+
hour: "numeric",
|
|
52
|
+
minute: "2-digit"
|
|
53
|
+
},
|
|
54
|
+
datetime: {
|
|
55
|
+
month: "short",
|
|
56
|
+
day: "numeric",
|
|
57
|
+
hour: "numeric",
|
|
58
|
+
minute: "2-digit"
|
|
59
|
+
}
|
|
60
|
+
}, M = d({
|
|
61
|
+
name: "Now",
|
|
62
|
+
description: "The current date and time as an ISO string",
|
|
63
|
+
params: m({}),
|
|
64
|
+
returns: u(),
|
|
65
|
+
fn: () => (/* @__PURE__ */ new Date()).toISOString()
|
|
66
|
+
}), T = d({
|
|
67
|
+
name: "FormatDate",
|
|
68
|
+
description: 'A date as text: "date" Oct 9, 2026 (default), "short" Oct 9, "long" Friday, October 9, 2026, "weekday" Fri, "month" Oct 2026, "time" 9:30 PM, "datetime", "iso" 2026-10-09. Dates are "YYYY-MM-DD", ISO or a timestamp',
|
|
69
|
+
params: m({
|
|
70
|
+
date: s(),
|
|
71
|
+
style: p(["date", "short", "long", "weekday", "month", "time", "datetime", "iso"]).optional()
|
|
72
|
+
}),
|
|
73
|
+
returns: u(),
|
|
74
|
+
fn: ({
|
|
75
|
+
date: e,
|
|
76
|
+
style: t = "date"
|
|
77
|
+
}) => {
|
|
78
|
+
const {
|
|
79
|
+
day: n,
|
|
80
|
+
instant: a
|
|
81
|
+
} = o(e);
|
|
82
|
+
return t === "iso" ? y(n) : (a ?? new Date(n * i)).toLocaleString("en-US", {
|
|
83
|
+
...l[t],
|
|
84
|
+
...a ? {} : {
|
|
85
|
+
timeZone: "UTC"
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}), C = d({
|
|
90
|
+
name: "AddDays",
|
|
91
|
+
description: 'The date days later (negative: earlier), as "YYYY-MM-DD"',
|
|
92
|
+
params: m({
|
|
93
|
+
date: s(),
|
|
94
|
+
days: w()
|
|
95
|
+
}),
|
|
96
|
+
returns: u(),
|
|
97
|
+
fn: ({
|
|
98
|
+
date: e,
|
|
99
|
+
days: t
|
|
100
|
+
}) => y(o(e).day + Math.trunc(t))
|
|
101
|
+
}), U = d({
|
|
102
|
+
name: "DaysBetween",
|
|
103
|
+
description: "Calendar days from one date to another (negative if to is earlier)",
|
|
104
|
+
params: m({
|
|
105
|
+
from: s(),
|
|
106
|
+
to: s()
|
|
107
|
+
}),
|
|
108
|
+
returns: w(),
|
|
109
|
+
fn: ({
|
|
110
|
+
from: e,
|
|
111
|
+
to: t
|
|
112
|
+
}) => o(t).day - o(e).day
|
|
113
|
+
}), S = d({
|
|
114
|
+
name: "Today",
|
|
115
|
+
description: `Today's date in the viewer's time zone, as "YYYY-MM-DD"`,
|
|
116
|
+
params: m({}),
|
|
117
|
+
returns: u(),
|
|
118
|
+
fn: () => y(o(Date.now()).day)
|
|
119
|
+
});
|
|
120
|
+
function g(e) {
|
|
121
|
+
const t = new Date(e * i);
|
|
122
|
+
return [t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate()];
|
|
123
|
+
}
|
|
124
|
+
const F = d({
|
|
125
|
+
name: "AddMonths",
|
|
126
|
+
description: 'The date months later (negative: earlier), kept within the month (Jan 31 + 1 is Feb 28), as "YYYY-MM-DD"; 12 months is a year',
|
|
127
|
+
params: m({
|
|
128
|
+
date: s(),
|
|
129
|
+
months: w()
|
|
130
|
+
}),
|
|
131
|
+
returns: u(),
|
|
132
|
+
fn: ({
|
|
133
|
+
date: e,
|
|
134
|
+
months: t
|
|
135
|
+
}) => {
|
|
136
|
+
const [n, a, r] = g(o(e).day), c = a + Math.trunc(t), h = new Date(Date.UTC(n, c + 1, 0)).getUTCDate();
|
|
137
|
+
return y(Date.UTC(n, c, Math.min(r, h)) / i);
|
|
138
|
+
}
|
|
139
|
+
}), O = d({
|
|
140
|
+
name: "MonthsBetween",
|
|
141
|
+
description: "Whole months from one date to another (negative if to is earlier); @Floor(@MonthsBetween(birthday, @Today()) / 12) is an age",
|
|
142
|
+
params: m({
|
|
143
|
+
from: s(),
|
|
144
|
+
to: s()
|
|
145
|
+
}),
|
|
146
|
+
returns: w(),
|
|
147
|
+
fn: ({
|
|
148
|
+
from: e,
|
|
149
|
+
to: t
|
|
150
|
+
}) => {
|
|
151
|
+
const [n, a, r] = g(o(e).day), [c, h, D] = g(o(t).day);
|
|
152
|
+
let f = (c - n) * 12 + (h - a);
|
|
153
|
+
return f > 0 && D < r && (f -= 1), f < 0 && D > r && (f += 1), f;
|
|
154
|
+
}
|
|
155
|
+
}), k = d({
|
|
156
|
+
name: "StartOf",
|
|
157
|
+
description: `First day of the date's "week" (Monday), "month" or "year", as "YYYY-MM-DD"`,
|
|
158
|
+
params: m({
|
|
159
|
+
date: s(),
|
|
160
|
+
unit: p(["week", "month", "year"])
|
|
161
|
+
}),
|
|
162
|
+
returns: u(),
|
|
163
|
+
fn: ({
|
|
164
|
+
date: e,
|
|
165
|
+
unit: t
|
|
166
|
+
}) => {
|
|
167
|
+
const n = o(e).day, [a, r] = g(n);
|
|
168
|
+
return y(t === "week" ? n - (new Date(n * i).getUTCDay() + 6) % 7 : Date.UTC(a, t === "month" ? r : 0, 1) / i);
|
|
169
|
+
}
|
|
170
|
+
}), B = [M, S, T, C, F, U, O, k];
|
|
171
|
+
export {
|
|
172
|
+
C as AddDays,
|
|
173
|
+
F as AddMonths,
|
|
174
|
+
U as DaysBetween,
|
|
175
|
+
T as FormatDate,
|
|
176
|
+
O as MonthsBetween,
|
|
177
|
+
M as Now,
|
|
178
|
+
k as StartOf,
|
|
179
|
+
S as Today,
|
|
180
|
+
B as dateFunctions,
|
|
181
|
+
y as isoDay,
|
|
182
|
+
o as parseDate
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sources":["../../../src/openui/functions/dates.ts"],"sourcesContent":["import { defineFunction } from \"@openuidev/react-lang\";\nimport { z } from \"zod/v4\";\nimport { date } from \"./shared\";\n\nconst DAY = 86_400_000;\nconst DATE_ONLY = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * A date as a calendar day (days since 1970-01-01) plus, for a timestamp, the\n * instant. \"YYYY-MM-DD\" is a calendar date with no time zone; a timestamp or an\n * ISO date-time is read in the viewer's time zone.\n */\ntype Parsed = { day: number; instant: Date | null };\n\nexport function parseDate(value: string | number): Parsed {\n if (typeof value === \"string\") {\n const m = DATE_ONLY.exec(value.trim());\n if (m) {\n const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];\n const utc = Date.UTC(y, mo - 1, d);\n const check = new Date(utc);\n if (check.getUTCMonth() !== mo - 1 || check.getUTCDate() !== d) throw new Error(`invalid date \"${value}\"`);\n return { day: utc / DAY, instant: null };\n }\n }\n const instant = new Date(value);\n if (Number.isNaN(instant.getTime())) throw new Error(`invalid date \"${value}\"`);\n return { day: Date.UTC(instant.getFullYear(), instant.getMonth(), instant.getDate()) / DAY, instant };\n}\n\nexport function isoDay(day: number): string {\n return new Date(day * DAY).toISOString().slice(0, 10);\n}\n\nconst STYLES: Record<string, Intl.DateTimeFormatOptions> = {\n date: { month: \"short\", day: \"numeric\", year: \"numeric\" },\n short: { month: \"short\", day: \"numeric\" },\n long: { weekday: \"long\", month: \"long\", day: \"numeric\", year: \"numeric\" },\n weekday: { weekday: \"short\" },\n month: { month: \"short\", year: \"numeric\" },\n time: { hour: \"numeric\", minute: \"2-digit\" },\n datetime: { month: \"short\", day: \"numeric\", hour: \"numeric\", minute: \"2-digit\" },\n};\n\nexport const Now = defineFunction({\n name: \"Now\",\n description: \"The current date and time as an ISO string\",\n params: z.object({}),\n returns: z.string(),\n fn: () => new Date().toISOString(),\n});\n\nexport const FormatDate = defineFunction({\n name: \"FormatDate\",\n description:\n 'A date as text: \"date\" Oct 9, 2026 (default), \"short\" Oct 9, \"long\" Friday, October 9, 2026, \"weekday\" Fri, \"month\" Oct 2026, \"time\" 9:30 PM, \"datetime\", \"iso\" 2026-10-09. Dates are \"YYYY-MM-DD\", ISO or a timestamp',\n params: z.object({\n date: date(),\n style: z.enum([\"date\", \"short\", \"long\", \"weekday\", \"month\", \"time\", \"datetime\", \"iso\"]).optional(),\n }),\n returns: z.string(),\n fn: ({ date, style = \"date\" }) => {\n const { day, instant } = parseDate(date);\n if (style === \"iso\") return isoDay(day);\n // A calendar date formats in UTC so its day never shifts with the viewer's zone\n const at = instant ?? new Date(day * DAY);\n return at.toLocaleString(\"en-US\", { ...STYLES[style], ...(instant ? {} : { timeZone: \"UTC\" }) });\n },\n});\n\nexport const AddDays = defineFunction({\n name: \"AddDays\",\n description: 'The date days later (negative: earlier), as \"YYYY-MM-DD\"',\n params: z.object({ date: date(), days: z.number() }),\n returns: z.string(),\n fn: ({ date, days }) => isoDay(parseDate(date).day + Math.trunc(days)),\n});\n\nexport const DaysBetween = defineFunction({\n name: \"DaysBetween\",\n description: \"Calendar days from one date to another (negative if to is earlier)\",\n params: z.object({ from: date(), to: date() }),\n returns: z.number(),\n fn: ({ from, to }) => parseDate(to).day - parseDate(from).day,\n});\n\nexport const Today = defineFunction({\n name: \"Today\",\n description: 'Today\\'s date in the viewer\\'s time zone, as \"YYYY-MM-DD\"',\n params: z.object({}),\n returns: z.string(),\n fn: () => isoDay(parseDate(Date.now()).day),\n});\n\n/** Year, month (0-11) and day of a calendar day. */\nfunction ymd(day: number): [number, number, number] {\n const d = new Date(day * DAY);\n return [d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()];\n}\n\nexport const AddMonths = defineFunction({\n name: \"AddMonths\",\n description: 'The date months later (negative: earlier), kept within the month (Jan 31 + 1 is Feb 28), as \"YYYY-MM-DD\"; 12 months is a year',\n params: z.object({ date: date(), months: z.number() }),\n returns: z.string(),\n fn: ({ date, months }) => {\n const [y, m, d] = ymd(parseDate(date).day);\n const target = m + Math.trunc(months);\n const last = new Date(Date.UTC(y, target + 1, 0)).getUTCDate();\n return isoDay(Date.UTC(y, target, Math.min(d, last)) / DAY);\n },\n});\n\nexport const MonthsBetween = defineFunction({\n name: \"MonthsBetween\",\n description: \"Whole months from one date to another (negative if to is earlier); @Floor(@MonthsBetween(birthday, @Today()) / 12) is an age\",\n params: z.object({ from: date(), to: date() }),\n returns: z.number(),\n fn: ({ from, to }) => {\n const [y1, m1, d1] = ymd(parseDate(from).day);\n const [y2, m2, d2] = ymd(parseDate(to).day);\n let months = (y2 - y1) * 12 + (m2 - m1);\n if (months > 0 && d2 < d1) months -= 1;\n if (months < 0 && d2 > d1) months += 1;\n return months;\n },\n});\n\nexport const StartOf = defineFunction({\n name: \"StartOf\",\n description: 'First day of the date\\'s \"week\" (Monday), \"month\" or \"year\", as \"YYYY-MM-DD\"',\n params: z.object({ date: date(), unit: z.enum([\"week\", \"month\", \"year\"]) }),\n returns: z.string(),\n fn: ({ date, unit }) => {\n const day = parseDate(date).day;\n const [y, m] = ymd(day);\n if (unit === \"week\") return isoDay(day - ((new Date(day * DAY).getUTCDay() + 6) % 7));\n return isoDay(Date.UTC(y, unit === \"month\" ? m : 0, 1) / DAY);\n },\n});\n\nexport const dateFunctions = [Now, Today, FormatDate, AddDays, AddMonths, DaysBetween, MonthsBetween, StartOf];\n"],"names":["DAY","DATE_ONLY","parseDate","value","m","y","mo","d","utc","check","instant","isoDay","day","STYLES","Now","defineFunction","z.object","z.string","FormatDate","date","z.enum","style","AddDays","z.number","days","DaysBetween","from","to","Today","ymd","AddMonths","months","target","last","MonthsBetween","y1","m1","d1","y2","m2","d2","StartOf","unit","dateFunctions"],"mappings":";;;AAGA,MAAMA,IAAM,OACNC,IAAY;AAQX,SAASC,EAAUC,GAAO;AAC/B,MAAI,OAAOA,KAAU,UAAU;AAC7B,UAAMC,IAAIH,EAAU,KAAKE,EAAM,MAAM;AACrC,QAAIC,GAAG;AACL,YAAM,CAACC,GAAGC,GAAIC,CAAC,IAAI,CAAC,OAAOH,EAAE,CAAC,CAAC,GAAG,OAAOA,EAAE,CAAC,CAAC,GAAG,OAAOA,EAAE,CAAC,CAAC,CAAC,GACtDI,IAAM,KAAK,IAAIH,GAAGC,IAAK,GAAGC,CAAC,GAC3BE,IAAQ,IAAI,KAAKD,CAAG;AAC1B,UAAIC,EAAM,YAAA,MAAkBH,IAAK,KAAKG,EAAM,WAAA,MAAiBF,EAAG,OAAM,IAAI,MAAM,iBAAiBJ,CAAK,GAAG;AACzG,aAAO;AAAA,QACL,KAAKK,IAAMR;AAAA,QACX,SAAS;AAAA,MAAA;AAAA,IAEb;AAAA,EACF;AACA,QAAMU,IAAU,IAAI,KAAKP,CAAK;AAC9B,MAAI,OAAO,MAAMO,EAAQ,QAAA,CAAS,EAAG,OAAM,IAAI,MAAM,iBAAiBP,CAAK,GAAG;AAC9E,SAAO;AAAA,IACL,KAAK,KAAK,IAAIO,EAAQ,YAAA,GAAeA,EAAQ,YAAYA,EAAQ,QAAA,CAAS,IAAIV;AAAA,IAC9E,SAAAU;AAAA,EAAA;AAEJ;AACO,SAASC,EAAOC,GAAK;AAC1B,SAAO,IAAI,KAAKA,IAAMZ,CAAG,EAAE,cAAc,MAAM,GAAG,EAAE;AACtD;AACA,MAAMa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