@stackone/malachite 2.86.0 → 2.87.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/COMPONENTS.md +3 -2
- package/dist/components/Card.js +128 -75
- package/dist/components/Card.js.map +1 -1
- package/dist/components/FilterSearch.js +228 -224
- package/dist/components/FilterSearch.js.map +1 -1
- package/dist/components/FrameHeader.js +36 -0
- package/dist/components/FrameHeader.js.map +1 -0
- package/dist/components/LoadingBar.js +5 -5
- package/dist/components/LoadingBar.js.map +1 -1
- package/dist/components/MultiSelect.js +431 -382
- package/dist/components/MultiSelect.js.map +1 -1
- package/dist/components/Table/Table.js +630 -606
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/TimeBarChart/TimeBarChart.js +241 -0
- package/dist/components/TimeBarChart/TimeBarChart.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartAxes.js +49 -0
- package/dist/components/TimeBarChart/TimeBarChartAxes.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartBars.js +58 -0
- package/dist/components/TimeBarChart/TimeBarChartBars.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartLegend.js +29 -0
- package/dist/components/TimeBarChart/TimeBarChartLegend.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartTable.js +33 -0
- package/dist/components/TimeBarChart/TimeBarChartTable.js.map +1 -0
- package/dist/components/TimeBarChart/TimeBarChartTooltip.js +77 -0
- package/dist/components/TimeBarChart/TimeBarChartTooltip.js.map +1 -0
- package/dist/components/TimeBarChart/stackLayout.js +25 -0
- package/dist/components/TimeBarChart/stackLayout.js.map +1 -0
- package/dist/components/TimeBarChart/timeBuckets.js +133 -0
- package/dist/components/TimeBarChart/timeBuckets.js.map +1 -0
- package/dist/components/TimeBarChart/tones.js +10 -0
- package/dist/components/TimeBarChart/tones.js.map +1 -0
- package/dist/components/dateMath.js +1 -0
- package/dist/components/dateMath.js.map +1 -1
- package/dist/components/filterSearchModel.js +53 -45
- package/dist/components/filterSearchModel.js.map +1 -1
- package/dist/components/frameStyles.js +14 -0
- package/dist/components/frameStyles.js.map +1 -0
- package/dist/components/headerContent.js +10 -0
- package/dist/components/headerContent.js.map +1 -0
- package/dist/index.d.ts +123 -3
- package/dist/index.js +24 -22
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/dist/theme.js +340 -340
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { MONTHS_SHORT as D, daysInMonth as k } from "../dateMath.js";
|
|
2
|
+
const M = 6e4, g = 60 * M, h = 24 * g, _ = {
|
|
3
|
+
minute: M,
|
|
4
|
+
hour: g,
|
|
5
|
+
day: h,
|
|
6
|
+
week: 7 * h
|
|
7
|
+
}, $ = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?$/, P = (t) => {
|
|
8
|
+
if (typeof t == "number") return t;
|
|
9
|
+
if (t instanceof Date) return t.getTime();
|
|
10
|
+
const n = t.trim();
|
|
11
|
+
if ($.test(n)) {
|
|
12
|
+
const [e, o = "00:00:00"] = n.split(/[ T]/);
|
|
13
|
+
return Date.parse(`${e}T${o}Z`);
|
|
14
|
+
}
|
|
15
|
+
return Date.parse(n);
|
|
16
|
+
}, T = (t) => Math.max(1, Math.floor(t.step ?? 1)), C = (t, n, e = 1) => {
|
|
17
|
+
const o = _[n.unit];
|
|
18
|
+
if (o !== void 0) return t + o * T(n) * e;
|
|
19
|
+
const r = new Date(t);
|
|
20
|
+
return Date.UTC(
|
|
21
|
+
r.getUTCFullYear(),
|
|
22
|
+
r.getUTCMonth() + T(n) * e,
|
|
23
|
+
r.getUTCDate(),
|
|
24
|
+
r.getUTCHours(),
|
|
25
|
+
r.getUTCMinutes()
|
|
26
|
+
);
|
|
27
|
+
}, w = 4 * h, i = (t, n) => {
|
|
28
|
+
const e = T(n);
|
|
29
|
+
if (n.unit === "month") {
|
|
30
|
+
const a = new Date(t), s = a.getUTCFullYear() * 12 + a.getUTCMonth(), u = s - s % e;
|
|
31
|
+
return Date.UTC(Math.floor(u / 12), u % 12, 1);
|
|
32
|
+
}
|
|
33
|
+
const o = (_[n.unit] ?? h) * e, r = n.unit === "week" ? w : 0;
|
|
34
|
+
return Math.floor((t - r) / o) * o + r;
|
|
35
|
+
}, U = 2e3, Z = (t, n, e) => {
|
|
36
|
+
const o = [], r = i(n, e), a = Math.max(i(t, e), C(r, e, 1 - U));
|
|
37
|
+
for (let s = a; s <= r && o.length < U; ) {
|
|
38
|
+
const u = C(s, e);
|
|
39
|
+
o.push({ start: s, end: u }), s = u;
|
|
40
|
+
}
|
|
41
|
+
return o;
|
|
42
|
+
}, K = (t, n) => {
|
|
43
|
+
if (!Number.isFinite(n)) return -1;
|
|
44
|
+
let e = 0, o = t.length - 1;
|
|
45
|
+
for (; e <= o; ) {
|
|
46
|
+
const r = e + o >> 1;
|
|
47
|
+
if (n < t[r].start) o = r - 1;
|
|
48
|
+
else if (n >= t[r].end) e = r + 1;
|
|
49
|
+
else return r;
|
|
50
|
+
}
|
|
51
|
+
return -1;
|
|
52
|
+
}, y = [
|
|
53
|
+
"January",
|
|
54
|
+
"February",
|
|
55
|
+
"March",
|
|
56
|
+
"April",
|
|
57
|
+
"May",
|
|
58
|
+
"June",
|
|
59
|
+
"July",
|
|
60
|
+
"August",
|
|
61
|
+
"September",
|
|
62
|
+
"October",
|
|
63
|
+
"November",
|
|
64
|
+
"December"
|
|
65
|
+
], I = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], f = (t) => String(t).padStart(2, "0"), p = (t) => `${f(t.getUTCHours())}:${f(t.getUTCMinutes())}`, Y = (t) => `${I[t.getUTCDay()]} ${t.getUTCDate()}`, S = (t) => `${D[t.getUTCMonth()]} ${f(t.getUTCDate())}`, j = (t, n) => {
|
|
66
|
+
const e = new Date(t);
|
|
67
|
+
return n === "month" ? `${y[e.getUTCMonth()]} ${e.getUTCFullYear()}` : n === "day" || n === "week" ? `${S(e)}, ${e.getUTCFullYear()}` : `${S(e)} ${p(e)}`;
|
|
68
|
+
}, b = 3 * g, H = 72 * g, E = 92 * h, L = (t, n) => t === "month" || n >= E ? "month" : t === "day" || t === "week" || n >= H ? "day" : t === "hour" || n >= b ? "hour" : "minute", N = {
|
|
69
|
+
minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],
|
|
70
|
+
hour: [1, 2, 3, 4, 6, 12, 24],
|
|
71
|
+
day: [1, 2, 3, 7, 14],
|
|
72
|
+
month: [1, 2, 3, 6, 12]
|
|
73
|
+
}, R = (t, n, e) => {
|
|
74
|
+
const o = new Date(t);
|
|
75
|
+
if (n === "minute") return (o.getUTCHours() * 60 + o.getUTCMinutes()) % e === 0;
|
|
76
|
+
if (n === "hour") return o.getUTCHours() % e === 0;
|
|
77
|
+
if (n === "month") return o.getUTCMonth() % e === 0;
|
|
78
|
+
const r = k({ year: o.getUTCFullYear(), month: o.getUTCMonth() });
|
|
79
|
+
return (o.getUTCDate() - 1) % e === 0 && o.getUTCDate() + e <= r + 1;
|
|
80
|
+
}, F = (t, n) => {
|
|
81
|
+
if (n === "minute") return t + M;
|
|
82
|
+
if (n === "hour") return t + g;
|
|
83
|
+
if (n === "day") return t + h;
|
|
84
|
+
const e = new Date(t);
|
|
85
|
+
return Date.UTC(e.getUTCFullYear(), e.getUTCMonth() + 1, 1);
|
|
86
|
+
}, X = (t, n) => {
|
|
87
|
+
const e = i(t, {
|
|
88
|
+
unit: n === "month" ? "month" : n
|
|
89
|
+
});
|
|
90
|
+
return e < t ? F(e, n) : e;
|
|
91
|
+
}, B = 64, x = {
|
|
92
|
+
minute: "hour",
|
|
93
|
+
hour: "day",
|
|
94
|
+
day: "month",
|
|
95
|
+
month: void 0
|
|
96
|
+
}, q = (t, n, e, o) => O(t, n, L(e, n - t), o), O = (t, n, e, o) => {
|
|
97
|
+
const r = [];
|
|
98
|
+
for (let c = X(t, e); c <= n && r.length < 5e3; c = F(c, e))
|
|
99
|
+
r.push(c);
|
|
100
|
+
const a = Math.max(1, Math.floor(o / B)), s = N[e], u = s.find((c) => r.length / c <= a), l = x[e];
|
|
101
|
+
if (u === void 0 && l) return O(t, n, l, o);
|
|
102
|
+
const A = u ?? s[s.length - 1], m = r.filter((c) => R(c, e, A));
|
|
103
|
+
return m.map((c, d) => ({
|
|
104
|
+
at: c,
|
|
105
|
+
label: J(c, e, d === 0 ? c - 1 : m[d - 1])
|
|
106
|
+
}));
|
|
107
|
+
}, J = (t, n, e) => {
|
|
108
|
+
const o = new Date(t), r = new Date(e);
|
|
109
|
+
return o.getUTCFullYear() !== r.getUTCFullYear() ? String(o.getUTCFullYear()) : o.getUTCMonth() !== r.getUTCMonth() ? y[o.getUTCMonth()] : n === "month" ? D[o.getUTCMonth()] : o.getUTCDate() !== r.getUTCDate() || n === "day" ? Y(o) : p(o);
|
|
110
|
+
}, z = (t, n = 4) => {
|
|
111
|
+
if (t <= 0) return [0, 1];
|
|
112
|
+
const e = t / n, o = 10 ** Math.floor(Math.log10(e)), r = Math.max(
|
|
113
|
+
1,
|
|
114
|
+
[1, 2, 5, 10].map((s) => s * o).find((s) => s >= e) ?? 10 * o
|
|
115
|
+
), a = Math.ceil(t / r) * r;
|
|
116
|
+
return Array.from({ length: a / r + 1 }, (s, u) => u * r);
|
|
117
|
+
}, G = (t) => t.toLocaleString("en", { notation: "compact", maximumFractionDigits: 1 }), Q = (t) => t.toLocaleString("en");
|
|
118
|
+
export {
|
|
119
|
+
B as AXIS_LABEL_WIDTH_PX,
|
|
120
|
+
U as MAX_SLOTS,
|
|
121
|
+
C as addBuckets,
|
|
122
|
+
q as axisTicks,
|
|
123
|
+
L as axisUnitFor,
|
|
124
|
+
Z as bucketSlots,
|
|
125
|
+
i as bucketStart,
|
|
126
|
+
j as formatBucket,
|
|
127
|
+
G as formatCompact,
|
|
128
|
+
Q as formatCount,
|
|
129
|
+
K as slotIndexOf,
|
|
130
|
+
P as toInstant,
|
|
131
|
+
z as valueTicks
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=timeBuckets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeBuckets.js","sources":["../../../src/components/TimeBarChart/timeBuckets.ts"],"sourcesContent":["import { MONTHS_SHORT, daysInMonth } from '../dateMath';\n\n// UTC time arithmetic for TimeBarChart, kept free of a date library so the component adds no\n// dependency. Every instant is milliseconds since the epoch, read and written in UTC.\n\nexport type TimeBarChartUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';\n\nexport interface TimeBarChartInterval {\n unit: TimeBarChartUnit;\n /** How many `unit`s one bucket spans, e.g. 3 with `hour` for 3-hour buckets. Default 1. */\n step?: number;\n}\n\nexport type TimeInput = string | number | Date;\n\nexport interface TimeSlot {\n start: number;\n end: number;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nconst FIXED_UNIT_MS: Partial<Record<TimeBarChartUnit, number>> = {\n minute: MINUTE_MS,\n hour: HOUR_MS,\n day: DAY_MS,\n week: 7 * DAY_MS,\n};\n\n// A date and time with no zone, as APIs often send bucket starts (\"2026-10-14 12:00:00\").\nconst ZONELESS = /^\\d{4}-\\d{2}-\\d{2}(?:[ T]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?)?$/;\n\n/** An instant in ms. A string with no zone is read as UTC, not as the viewer's local time. */\nexport const toInstant = (value: TimeInput): number => {\n if (typeof value === 'number') return value;\n if (value instanceof Date) return value.getTime();\n const text = value.trim();\n if (ZONELESS.test(text)) {\n const [date, time = '00:00:00'] = text.split(/[ T]/);\n return Date.parse(`${date}T${time}Z`);\n }\n return Date.parse(text);\n};\n\nconst stepOf = (interval: TimeBarChartInterval) => Math.max(1, Math.floor(interval.step ?? 1));\n\n/** `instant` moved on by `count` buckets. Months move by calendar month, keeping the day. */\nexport const addBuckets = (instant: number, interval: TimeBarChartInterval, count = 1): number => {\n const fixed = FIXED_UNIT_MS[interval.unit];\n if (fixed !== undefined) return instant + fixed * stepOf(interval) * count;\n const date = new Date(instant);\n return Date.UTC(\n date.getUTCFullYear(),\n date.getUTCMonth() + stepOf(interval) * count,\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n );\n};\n\n// The Unix epoch was a Thursday; ISO weeks start on Monday, three days later.\nconst FIRST_MONDAY_MS = 4 * DAY_MS;\n\n/**\n * The start of the bucket holding `instant`. Minute, hour and day buckets count from the epoch,\n * as bucketing APIs do, weeks from a Monday and months from the 1st.\n */\nexport const bucketStart = (instant: number, interval: TimeBarChartInterval): number => {\n const step = stepOf(interval);\n if (interval.unit === 'month') {\n const date = new Date(instant);\n const months = date.getUTCFullYear() * 12 + date.getUTCMonth();\n const first = months - (months % step);\n return Date.UTC(Math.floor(first / 12), first % 12, 1);\n }\n const length = (FIXED_UNIT_MS[interval.unit] ?? DAY_MS) * step;\n const origin = interval.unit === 'week' ? FIRST_MONDAY_MS : 0;\n return Math.floor((instant - origin) / length) * length + origin;\n};\n\n/** Bounded so a range thousands of buckets wide cannot hang the page. */\nexport const MAX_SLOTS = 2000;\n\n/**\n * A slot for every bucket from the one holding `from` to the one holding `to`, empty ones\n * included, so an empty bucket can still be hovered and selected. Past `MAX_SLOTS` the newest\n * are kept, so a live window still ends at \"now\".\n */\nexport const bucketSlots = (\n from: number,\n to: number,\n interval: TimeBarChartInterval,\n): TimeSlot[] => {\n const slots: TimeSlot[] = [];\n const last = bucketStart(to, interval);\n const first = Math.max(bucketStart(from, interval), addBuckets(last, interval, 1 - MAX_SLOTS));\n for (let start = first; start <= last && slots.length < MAX_SLOTS; ) {\n const end = addBuckets(start, interval);\n slots.push({ start, end });\n start = end;\n }\n return slots;\n};\n\n/** The index of the slot whose span holds `instant`, or -1. */\nexport const slotIndexOf = (slots: TimeSlot[], instant: number): number => {\n if (!Number.isFinite(instant)) return -1;\n let low = 0;\n let high = slots.length - 1;\n while (low <= high) {\n const middle = (low + high) >> 1;\n if (instant < slots[middle].start) high = middle - 1;\n else if (instant >= slots[middle].end) low = middle + 1;\n else return middle;\n }\n return -1;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n];\nconst WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst pad = (value: number) => String(value).padStart(2, '0');\n\nconst clock = (date: Date) => `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;\nconst weekday = (date: Date) => `${WEEKDAYS[date.getUTCDay()]} ${date.getUTCDate()}`;\nconst shortDate = (date: Date) => `${MONTHS_SHORT[date.getUTCMonth()]} ${pad(date.getUTCDate())}`;\n\n/** How a bucket is named in the tooltip, e.g. \"Oct 29 14:00\" or \"Oct 29, 2026\". */\nexport const formatBucket = (instant: number, unit: TimeBarChartUnit): string => {\n const date = new Date(instant);\n if (unit === 'month') return `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;\n if (unit === 'day' || unit === 'week') {\n return `${shortDate(date)}, ${date.getUTCFullYear()}`;\n }\n return `${shortDate(date)} ${clock(date)}`;\n};\n\nexport type AxisUnit = 'minute' | 'hour' | 'day' | 'month';\n\n// Below these spans a minute or hour axis is labelled in its own unit; from them, in a coarser\n// one, as 3-hour buckets over 14 days read better against days.\nconst HOUR_AXIS_FROM_MS = 3 * HOUR_MS;\nconst DAY_AXIS_FROM_MS = 72 * HOUR_MS;\nconst MONTH_AXIS_FROM_MS = 92 * DAY_MS;\n\nexport const axisUnitFor = (unit: TimeBarChartUnit, span: number): AxisUnit => {\n if (unit === 'month' || span >= MONTH_AXIS_FROM_MS) return 'month';\n if (unit === 'day' || unit === 'week' || span >= DAY_AXIS_FROM_MS) return 'day';\n if (unit === 'hour' || span >= HOUR_AXIS_FROM_MS) return 'hour';\n return 'minute';\n};\n\n// Steps a label may sit on, smallest first. Minute and hour steps divide a day and day steps\n// start each month on the 1st, so labels stay even and land on the boundaries.\nconst LABEL_STEPS: Record<AxisUnit, number[]> = {\n minute: [1, 5, 10, 15, 30, 60, 120, 180, 360, 720],\n hour: [1, 2, 3, 4, 6, 12, 24],\n day: [1, 2, 3, 7, 14],\n month: [1, 2, 3, 6, 12],\n};\n\nconst isOnStep = (instant: number, unit: AxisUnit, step: number): boolean => {\n const date = new Date(instant);\n if (unit === 'minute') return (date.getUTCHours() * 60 + date.getUTCMinutes()) % step === 0;\n if (unit === 'hour') return date.getUTCHours() % step === 0;\n if (unit === 'month') return date.getUTCMonth() % step === 0;\n // Day 1 is always on the step, so a day too close to the next month's 1st is dropped\n // rather than crowding it.\n const monthLength = daysInMonth({ year: date.getUTCFullYear(), month: date.getUTCMonth() });\n return (date.getUTCDate() - 1) % step === 0 && date.getUTCDate() + step <= monthLength + 1;\n};\n\nconst nextBoundary = (instant: number, unit: AxisUnit): number => {\n if (unit === 'minute') return instant + MINUTE_MS;\n if (unit === 'hour') return instant + HOUR_MS;\n if (unit === 'day') return instant + DAY_MS;\n const date = new Date(instant);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 1);\n};\n\nconst firstBoundary = (from: number, unit: AxisUnit): number => {\n const start = bucketStart(from, {\n unit: unit === 'month' ? 'month' : unit,\n });\n return start < from ? nextBoundary(start, unit) : start;\n};\n\n/** Roughly the width a label needs, gap included. */\nexport const AXIS_LABEL_WIDTH_PX = 64;\n\nexport interface AxisTick {\n at: number;\n label: string;\n}\n\nconst COARSER_AXIS: Record<AxisUnit, AxisUnit | undefined> = {\n minute: 'hour',\n hour: 'day',\n day: 'month',\n month: undefined,\n};\n\n/**\n * The labelled ticks between `from` and `to`, on the smallest clock- or calendar-aligned step\n * that fits `width`, moving to a coarser unit when no step of this one does. A tick names a\n * boundary it passes instead of its short form: the year on a new year, the month on a new\n * month, the day on a new day.\n */\nexport const axisTicks = (\n from: number,\n to: number,\n unit: TimeBarChartUnit,\n width: number,\n): AxisTick[] => ticksOn(from, to, axisUnitFor(unit, to - from), width);\n\nconst ticksOn = (from: number, to: number, axisUnit: AxisUnit, width: number): AxisTick[] => {\n const boundaries: number[] = [];\n for (\n let at = firstBoundary(from, axisUnit);\n at <= to && boundaries.length < 5000;\n at = nextBoundary(at, axisUnit)\n ) {\n boundaries.push(at);\n }\n const capacity = Math.max(1, Math.floor(width / AXIS_LABEL_WIDTH_PX));\n const steps = LABEL_STEPS[axisUnit];\n const fitting = steps.find((candidate) => boundaries.length / candidate <= capacity);\n const coarser = COARSER_AXIS[axisUnit];\n if (fitting === undefined && coarser) return ticksOn(from, to, coarser, width);\n const step = fitting ?? steps[steps.length - 1];\n const kept = boundaries.filter((at) => isOnStep(at, axisUnit, step));\n return kept.map((at, index) => ({\n at,\n label: tickLabel(at, axisUnit, index === 0 ? at - 1 : kept[index - 1]),\n }));\n};\n\nconst tickLabel = (at: number, unit: AxisUnit, previousAt: number): string => {\n const date = new Date(at);\n const previous = new Date(previousAt);\n if (date.getUTCFullYear() !== previous.getUTCFullYear()) return String(date.getUTCFullYear());\n if (date.getUTCMonth() !== previous.getUTCMonth()) return MONTHS[date.getUTCMonth()];\n if (unit === 'month') return MONTHS_SHORT[date.getUTCMonth()];\n if (date.getUTCDate() !== previous.getUTCDate() || unit === 'day') return weekday(date);\n return clock(date);\n};\n\n/**\n * A y-axis that ends on a round number, with about `count` steps of 1, 2 or 5 times a power of\n * ten, never below 1 since the values are counts.\n */\nexport const valueTicks = (max: number, count = 4): number[] => {\n if (max <= 0) return [0, 1];\n const rough = max / count;\n const magnitude = 10 ** Math.floor(Math.log10(rough));\n const step = Math.max(\n 1,\n [1, 2, 5, 10].map((factor) => factor * magnitude).find((size) => size >= rough) ??\n 10 * magnitude,\n );\n const top = Math.ceil(max / step) * step;\n return Array.from({ length: top / step + 1 }, (_unused, index) => index * step);\n};\n\n// Built per call rather than at module scope: nothing in the library may run at import time.\nexport const formatCompact = (value: number): string =>\n value.toLocaleString('en', { notation: 'compact', maximumFractionDigits: 1 });\nexport const formatCount = (value: number): string => value.toLocaleString('en');\n"],"names":["MINUTE_MS","HOUR_MS","DAY_MS","FIXED_UNIT_MS","ZONELESS","toInstant","value","text","date","time","stepOf","interval","addBuckets","instant","count","fixed","FIRST_MONDAY_MS","bucketStart","step","months","first","length","origin","MAX_SLOTS","bucketSlots","from","to","slots","last","start","end","slotIndexOf","low","high","middle","MONTHS","WEEKDAYS","pad","clock","weekday","shortDate","MONTHS_SHORT","formatBucket","unit","HOUR_AXIS_FROM_MS","DAY_AXIS_FROM_MS","MONTH_AXIS_FROM_MS","axisUnitFor","span","LABEL_STEPS","isOnStep","monthLength","daysInMonth","nextBoundary","firstBoundary","AXIS_LABEL_WIDTH_PX","COARSER_AXIS","axisTicks","width","ticksOn","axisUnit","boundaries","at","capacity","steps","fitting","candidate","coarser","kept","index","tickLabel","previousAt","previous","valueTicks","max","rough","magnitude","factor","size","top","_unused","formatCompact","formatCount"],"mappings":";AAoBA,MAAMA,IAAY,KACZC,IAAU,KAAKD,GACfE,IAAS,KAAKD,GAEdE,IAA2D;AAAA,EAC7D,QAAQH;AAAA,EACR,MAAMC;AAAA,EACN,KAAKC;AAAA,EACL,MAAM,IAAIA;AACd,GAGME,IAAW,gEAGJC,IAAY,CAACC,MAA6B;AACnD,MAAI,OAAOA,KAAU,SAAU,QAAOA;AACtC,MAAIA,aAAiB,KAAM,QAAOA,EAAM,QAAA;AACxC,QAAMC,IAAOD,EAAM,KAAA;AACnB,MAAIF,EAAS,KAAKG,CAAI,GAAG;AACrB,UAAM,CAACC,GAAMC,IAAO,UAAU,IAAIF,EAAK,MAAM,MAAM;AACnD,WAAO,KAAK,MAAM,GAAGC,CAAI,IAAIC,CAAI,GAAG;AAAA,EACxC;AACA,SAAO,KAAK,MAAMF,CAAI;AAC1B,GAEMG,IAAS,CAACC,MAAmC,KAAK,IAAI,GAAG,KAAK,MAAMA,EAAS,QAAQ,CAAC,CAAC,GAGhFC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|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const r = { neutral: 0, success: 1, error: 2 }, e = {
|
|
2
|
+
success: "var(--malachite-success-background, rgb(0, 175, 102))",
|
|
3
|
+
error: "var(--malachite-error-background, rgb(197, 63, 63))",
|
|
4
|
+
neutral: "var(--malachite-text-dimmed, rgb(161, 161, 161))"
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
e as TONE_FILL,
|
|
8
|
+
r as TONE_STACK
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=tones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tones.js","sources":["../../../src/components/TimeBarChart/tones.ts"],"sourcesContent":["import type { TimeBarChartTone } from './TimeBarChart';\n\n/** Stacking order by tone, so failures sit on top whatever order the series come in: position\n * then separates them where the success and error colours alone might not. */\nexport const TONE_STACK: Record<TimeBarChartTone, number> = { neutral: 0, success: 1, error: 2 };\n\nexport const TONE_FILL: Record<TimeBarChartTone, string> = {\n success: 'var(--malachite-success-background, rgb(0, 175, 102))',\n error: 'var(--malachite-error-background, rgb(197, 63, 63))',\n neutral: 'var(--malachite-text-dimmed, rgb(161, 161, 161))',\n};\n"],"names":["TONE_STACK","TONE_FILL"],"mappings":"AAIO,MAAMA,IAA+C,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,EAAA,GAEhFC,IAA8C;AAAA,EACvD,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACb;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateMath.js","sources":["../../src/components/dateMath.ts"],"sourcesContent":["export type DatePickerTimeZone = 'local' | 'utc';\n\nexport type DatePickerPrecision = 'day' | 'minute' | 'second';\n\nexport type WeekStart = 'monday' | 'sunday';\n\nexport interface DayKey {\n year: number;\n month: number;\n day: number;\n}\n\nexport interface MonthKey {\n year: number;\n month: number;\n}\n\nexport interface DateTimeParts extends DayKey {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport interface DateRange {\n start: Date;\n end: Date;\n}\n\nconst MONTHS_SHORT = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n] as const;\n\nconst WEEKDAYS_SHORT = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] as const;\nconst WEEKDAYS_LONG = [\n 'Sunday',\n 'Monday',\n 'Tuesday',\n 'Wednesday',\n 'Thursday',\n 'Friday',\n 'Saturday',\n] as const;\n\nexport const partsOf = (date: Date, zone: DatePickerTimeZone): DateTimeParts =>\n zone === 'utc'\n ? {\n year: date.getUTCFullYear(),\n month: date.getUTCMonth(),\n day: date.getUTCDate(),\n hours: date.getUTCHours(),\n minutes: date.getUTCMinutes(),\n seconds: date.getUTCSeconds(),\n }\n : {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n hours: date.getHours(),\n minutes: date.getMinutes(),\n seconds: date.getSeconds(),\n };\n\n// `Date` reads years 0-99 as 19xx; build 400 years on (same calendar) and move back.\nconst YEAR_SHIFT = 400;\n\nexport const fromParts = (\n { year, month, day, hours = 0, minutes = 0, seconds = 0 }: DayKey & Partial<DateTimeParts>,\n zone: DatePickerTimeZone,\n milliseconds = 0,\n): Date => {\n const shift = year >= 0 && year < 100 ? YEAR_SHIFT : 0;\n if (zone === 'utc') {\n const date = new Date(\n Date.UTC(year + shift, month, day, hours, minutes, seconds, milliseconds),\n );\n if (shift) {\n date.setUTCFullYear(date.getUTCFullYear() - shift);\n }\n return date;\n }\n const date = new Date(year + shift, month, day, hours, minutes, seconds, milliseconds);\n if (shift) {\n date.setFullYear(date.getFullYear() - shift);\n }\n return date;\n};\n\nexport const dayKeyOf = (date: Date, zone: DatePickerTimeZone): DayKey => {\n const { year, month, day } = partsOf(date, zone);\n return { year, month, day };\n};\n\nexport const compareDays = (a: DayKey, b: DayKey): number =>\n a.year - b.year || a.month - b.month || a.day - b.day;\n\nexport const sameDay = (a: DayKey | null | undefined, b: DayKey | null | undefined): boolean =>\n !!a && !!b && compareDays(a, b) === 0;\n\nexport const dayKeyString = ({ year, month, day }: DayKey): string =>\n `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;\n\nexport const startOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day }, zone);\n\nexport const endOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day, hours: 23, minutes: 59, seconds: 59 }, zone, 999);\n\nexport const addDays = (day: DayKey, amount: number): DayKey =>\n dayKeyOf(fromParts({ year: day.year, month: day.month, day: day.day + amount }, 'utc'), 'utc');\n\nexport const daysInMonth = ({ year, month }: MonthKey): number =>\n dayKeyOf(fromParts({ year, month: month + 1, day: 0 }, 'utc'), 'utc').day;\n\nexport const addMonths = ({ year, month }: MonthKey, amount: number): MonthKey => {\n const total = year * 12 + month + amount;\n return { year: Math.floor(total / 12), month: ((total % 12) + 12) % 12 };\n};\n\nexport const addMonthsToDay = (day: DayKey, amount: number): DayKey => {\n const target = addMonths(day, amount);\n return { ...target, day: Math.min(day.day, daysInMonth(target)) };\n};\n\nexport const weekdayOf = (day: DayKey): number => fromParts(day, 'utc').getUTCDay();\n\nconst WEEK_START_INDEX: Record<WeekStart, number> = { sunday: 0, monday: 1 };\n\nexport const weekdayLabels = (weekStart: WeekStart): { short: string; long: string }[] =>\n Array.from({ length: 7 }, (_, index) => {\n const weekday = (index + WEEK_START_INDEX[weekStart]) % 7;\n return { short: WEEKDAYS_SHORT[weekday], long: WEEKDAYS_LONG[weekday] };\n });\n\nexport const monthWeeks = (view: MonthKey, weekStart: WeekStart): DayKey[][] => {\n const first: DayKey = { ...view, day: 1 };\n const lead = (weekdayOf(first) - WEEK_START_INDEX[weekStart] + 7) % 7;\n const start = addDays(first, -lead);\n const weeks: DayKey[][] = [];\n for (let index = 0; index < 42; index++) {\n if (index % 7 === 0) {\n weeks.push([]);\n }\n weeks[weeks.length - 1].push(addDays(start, index));\n }\n return weeks;\n};\n\nexport const startOfWeek = (day: DayKey, weekStart: WeekStart): DayKey =>\n addDays(day, -((weekdayOf(day) - WEEK_START_INDEX[weekStart] + 7) % 7));\n\nexport const monthLabel = ({ year, month }: MonthKey): string => `${MONTHS_SHORT[month]} ${year}`;\n\nconst pad = (value: number): string => String(value).padStart(2, '0');\n\nexport const formatTime = (\n parts: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n precision: DatePickerPrecision,\n): string =>\n precision === 'second'\n ? `${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`\n : `${pad(parts.hours)}:${pad(parts.minutes)}`;\n\nconst zoneSuffix = (zone: DatePickerTimeZone): string => (zone === 'utc' ? ' UTC' : '');\n\nexport const formatDate = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string => {\n const parts = partsOf(date, zone);\n const day = `${MONTHS_SHORT[parts.month]} ${parts.day} ${parts.year}`;\n return precision === 'day' ? day : `${day}, ${formatTime(parts, precision)}${zoneSuffix(zone)}`;\n};\n\nexport const formatTimeReadout = (\n date: Date | null,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string =>\n `${date ? formatTime(partsOf(date, zone), precision) : precision === 'second' ? '--:--:--' : '--:--'}${zoneSuffix(zone)}`;\n\n// Lazy, so importing the module has no side effects.\nlet spokenDayFormat: Intl.DateTimeFormat | undefined;\n\nexport const spokenDay = (day: DayKey): string => {\n spokenDayFormat ??= new Intl.DateTimeFormat('en-US', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n timeZone: 'UTC',\n });\n return spokenDayFormat.format(fromParts(day, 'utc'));\n};\n\nexport const clampDate = (date: Date, min?: Date, max?: Date): Date => {\n if (min && date.getTime() < min.getTime()) {\n return new Date(min.getTime());\n }\n if (max && date.getTime() > max.getTime()) {\n return new Date(max.getTime());\n }\n return date;\n};\n\nexport const overlapsBounds = (from: Date, to: Date, min?: Date, max?: Date): boolean =>\n (!min || to.getTime() >= min.getTime()) && (!max || from.getTime() <= max.getTime());\n\nconst isValidDate = (value: unknown): value is Date =>\n value instanceof Date && !Number.isNaN(value.getTime());\n\nconst ZONELESS = /^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?)?$/;\n\nexport const toDate = (\n value: Date | string | number | null | undefined,\n zone: DatePickerTimeZone,\n): Date | null => {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n // Without an offset, a string names a wall-clock time in `zone`, not in the browser's.\n const zoneless = typeof value === 'string' ? ZONELESS.exec(value) : null;\n if (zoneless) {\n const [, year, month, day, hours = '0', minutes = '0', seconds = '0', ms = ''] = zoneless;\n const parts = {\n year: Number(year),\n month: Number(month) - 1,\n day: Number(day),\n hours: Number(hours),\n minutes: Number(minutes),\n seconds: Number(seconds),\n };\n if (parts.hours > 23 || parts.minutes > 59 || parts.seconds > 59) {\n return null;\n }\n const date = fromParts(parts, zone, Number(ms.padEnd(3, '0')));\n return sameDay(dayKeyOf(date, zone), parts) ? date : null;\n }\n const date = value instanceof Date ? value : new Date(value);\n return isValidDate(date) ? date : null;\n};\n\nexport const withTime = (\n day: DayKey,\n time: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n zone: DatePickerTimeZone,\n): Date =>\n fromParts(\n {\n year: day.year,\n month: day.month,\n day: day.day,\n hours: time.hours,\n minutes: time.minutes,\n seconds: time.seconds,\n },\n zone,\n );\n\nconst UNIT_MS: Record<Exclude<DatePickerPrecision, 'day'>, number> = {\n minute: 60_000,\n second: 1_000,\n};\n\n// Arithmetic, not a rebuild from local fields, which moves the repeated hour when clocks go back.\nexport const truncateTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return startOfDay(partsOf(date, zone), zone);\n }\n if (zone === 'local' && !Number.isInteger(date.getTimezoneOffset())) {\n const parts = partsOf(date, zone);\n return fromParts({ ...parts, seconds: precision === 'second' ? parts.seconds : 0 }, zone);\n }\n const unit = UNIT_MS[precision];\n return new Date(Math.floor(date.getTime() / unit) * unit);\n};\n\n/** The last millisecond of the unit `date` falls in, so a range end covers the whole of it. */\nexport const endOfUnit = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date =>\n precision === 'day'\n ? endOfDay(dayKeyOf(date, zone), zone)\n : new Date(truncateTo(date, zone, precision).getTime() + UNIT_MS[precision] - 1);\n\nexport const ceilTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return date;\n }\n const floor = truncateTo(date, zone, precision);\n return floor.getTime() < date.getTime()\n ? new Date(floor.getTime() + UNIT_MS[precision])\n : floor;\n};\n"],"names":["MONTHS_SHORT","WEEKDAYS_SHORT","WEEKDAYS_LONG","partsOf","date","zone","fromParts","year","month","day","hours","minutes","seconds","milliseconds","shift","dayKeyOf","compareDays","a","b","sameDay","dayKeyString","startOfDay","endOfDay","addDays","amount","daysInMonth","addMonths","total","addMonthsToDay","target","weekdayOf","WEEK_START_INDEX","weekdayLabels","weekStart","_","index","weekday","monthWeeks","view","first","lead","start","weeks","startOfWeek","monthLabel","pad","value","formatTime","parts","precision","zoneSuffix","formatDate","formatTimeReadout","spokenDayFormat","spokenDay","clampDate","min","max","overlapsBounds","from","to","isValidDate","ZONELESS","toDate","zoneless","ms","withTime","time","UNIT_MS","truncateTo","unit","endOfUnit","ceilTo","floor"],"mappings":"AA4BA,MAAMA,IAAe;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAEMC,IAAiB,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI,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EE+D,IAA+D;AAAA,EACjE,QAAQ;AAAA,EACR,QAAQ;AACZ,GAGaC,IAAa,CACtBjE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO5B,EAAWlB,EAAQC,GAAMC,CAAI,GAAGA,CAAI;AAE/C,MAAIA,MAAS,WAAW,CAAC,OAAO,UAAUD,EAAK,kBAAA,CAAmB,GAAG;AACjE,UAAM4C,IAAQ7C,EAAQC,GAAMC,CAAI;AAChC,WAAOC,EAAU,EAAE,GAAG0C,GAAO,SAASC,MAAc,WAAWD,EAAM,UAAU,EAAA,GAAK3C,CAAI;AAAA,EAC5F;AACA,QAAMiE,IAAOF,EAAQnB,CAAS;AAC9B,SAAO,IAAI,KAAK,KAAK,MAAM7C,EAAK,QAAA,IAAYkE,CAAI,IAAIA,CAAI;AAC5D,GAGaC,IAAY,CACrBnE,GACAC,GACA4C,MAEAA,MAAc,QACR3B,EAASP,EAASX,GAAMC,CAAI,GAAGA,CAAI,IACnC,IAAI,KAAKgE,EAAWjE,GAAMC,GAAM4C,CAAS,EAAE,QAAA,IAAYmB,EAAQnB,CAAS,IAAI,CAAC,GAE1EuB,IAAS,CAClBpE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO7C;AAEX,QAAMqE,IAAQJ,EAAWjE,GAAMC,GAAM4C,CAAS;AAC9C,SAAOwB,EAAM,QAAA,IAAYrE,EAAK,YACxB,IAAI,KAAKqE,EAAM,QAAA,IAAYL,EAAQnB,CAAS,CAAC,IAC7CwB;AACV;"}
|
|
1
|
+
{"version":3,"file":"dateMath.js","sources":["../../src/components/dateMath.ts"],"sourcesContent":["export type DatePickerTimeZone = 'local' | 'utc';\n\nexport type DatePickerPrecision = 'day' | 'minute' | 'second';\n\nexport type WeekStart = 'monday' | 'sunday';\n\nexport interface DayKey {\n year: number;\n month: number;\n day: number;\n}\n\nexport interface MonthKey {\n year: number;\n month: number;\n}\n\nexport interface DateTimeParts extends DayKey {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport interface DateRange {\n start: Date;\n end: Date;\n}\n\nexport const MONTHS_SHORT = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n] as const;\n\nconst WEEKDAYS_SHORT = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] as const;\nconst WEEKDAYS_LONG = [\n 'Sunday',\n 'Monday',\n 'Tuesday',\n 'Wednesday',\n 'Thursday',\n 'Friday',\n 'Saturday',\n] as const;\n\nexport const partsOf = (date: Date, zone: DatePickerTimeZone): DateTimeParts =>\n zone === 'utc'\n ? {\n year: date.getUTCFullYear(),\n month: date.getUTCMonth(),\n day: date.getUTCDate(),\n hours: date.getUTCHours(),\n minutes: date.getUTCMinutes(),\n seconds: date.getUTCSeconds(),\n }\n : {\n year: date.getFullYear(),\n month: date.getMonth(),\n day: date.getDate(),\n hours: date.getHours(),\n minutes: date.getMinutes(),\n seconds: date.getSeconds(),\n };\n\n// `Date` reads years 0-99 as 19xx; build 400 years on (same calendar) and move back.\nconst YEAR_SHIFT = 400;\n\nexport const fromParts = (\n { year, month, day, hours = 0, minutes = 0, seconds = 0 }: DayKey & Partial<DateTimeParts>,\n zone: DatePickerTimeZone,\n milliseconds = 0,\n): Date => {\n const shift = year >= 0 && year < 100 ? YEAR_SHIFT : 0;\n if (zone === 'utc') {\n const date = new Date(\n Date.UTC(year + shift, month, day, hours, minutes, seconds, milliseconds),\n );\n if (shift) {\n date.setUTCFullYear(date.getUTCFullYear() - shift);\n }\n return date;\n }\n const date = new Date(year + shift, month, day, hours, minutes, seconds, milliseconds);\n if (shift) {\n date.setFullYear(date.getFullYear() - shift);\n }\n return date;\n};\n\nexport const dayKeyOf = (date: Date, zone: DatePickerTimeZone): DayKey => {\n const { year, month, day } = partsOf(date, zone);\n return { year, month, day };\n};\n\nexport const compareDays = (a: DayKey, b: DayKey): number =>\n a.year - b.year || a.month - b.month || a.day - b.day;\n\nexport const sameDay = (a: DayKey | null | undefined, b: DayKey | null | undefined): boolean =>\n !!a && !!b && compareDays(a, b) === 0;\n\nexport const dayKeyString = ({ year, month, day }: DayKey): string =>\n `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;\n\nexport const startOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day }, zone);\n\nexport const endOfDay = ({ year, month, day }: DayKey, zone: DatePickerTimeZone): Date =>\n fromParts({ year, month, day, hours: 23, minutes: 59, seconds: 59 }, zone, 999);\n\nexport const addDays = (day: DayKey, amount: number): DayKey =>\n dayKeyOf(fromParts({ year: day.year, month: day.month, day: day.day + amount }, 'utc'), 'utc');\n\nexport const daysInMonth = ({ year, month }: MonthKey): number =>\n dayKeyOf(fromParts({ year, month: month + 1, day: 0 }, 'utc'), 'utc').day;\n\nexport const addMonths = ({ year, month }: MonthKey, amount: number): MonthKey => {\n const total = year * 12 + month + amount;\n return { year: Math.floor(total / 12), month: ((total % 12) + 12) % 12 };\n};\n\nexport const addMonthsToDay = (day: DayKey, amount: number): DayKey => {\n const target = addMonths(day, amount);\n return { ...target, day: Math.min(day.day, daysInMonth(target)) };\n};\n\nexport const weekdayOf = (day: DayKey): number => fromParts(day, 'utc').getUTCDay();\n\nconst WEEK_START_INDEX: Record<WeekStart, number> = { sunday: 0, monday: 1 };\n\nexport const weekdayLabels = (weekStart: WeekStart): { short: string; long: string }[] =>\n Array.from({ length: 7 }, (_, index) => {\n const weekday = (index + WEEK_START_INDEX[weekStart]) % 7;\n return { short: WEEKDAYS_SHORT[weekday], long: WEEKDAYS_LONG[weekday] };\n });\n\nexport const monthWeeks = (view: MonthKey, weekStart: WeekStart): DayKey[][] => {\n const first: DayKey = { ...view, day: 1 };\n const lead = (weekdayOf(first) - WEEK_START_INDEX[weekStart] + 7) % 7;\n const start = addDays(first, -lead);\n const weeks: DayKey[][] = [];\n for (let index = 0; index < 42; index++) {\n if (index % 7 === 0) {\n weeks.push([]);\n }\n weeks[weeks.length - 1].push(addDays(start, index));\n }\n return weeks;\n};\n\nexport const startOfWeek = (day: DayKey, weekStart: WeekStart): DayKey =>\n addDays(day, -((weekdayOf(day) - WEEK_START_INDEX[weekStart] + 7) % 7));\n\nexport const monthLabel = ({ year, month }: MonthKey): string => `${MONTHS_SHORT[month]} ${year}`;\n\nconst pad = (value: number): string => String(value).padStart(2, '0');\n\nexport const formatTime = (\n parts: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n precision: DatePickerPrecision,\n): string =>\n precision === 'second'\n ? `${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`\n : `${pad(parts.hours)}:${pad(parts.minutes)}`;\n\nconst zoneSuffix = (zone: DatePickerTimeZone): string => (zone === 'utc' ? ' UTC' : '');\n\nexport const formatDate = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string => {\n const parts = partsOf(date, zone);\n const day = `${MONTHS_SHORT[parts.month]} ${parts.day} ${parts.year}`;\n return precision === 'day' ? day : `${day}, ${formatTime(parts, precision)}${zoneSuffix(zone)}`;\n};\n\nexport const formatTimeReadout = (\n date: Date | null,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): string =>\n `${date ? formatTime(partsOf(date, zone), precision) : precision === 'second' ? '--:--:--' : '--:--'}${zoneSuffix(zone)}`;\n\n// Lazy, so importing the module has no side effects.\nlet spokenDayFormat: Intl.DateTimeFormat | undefined;\n\nexport const spokenDay = (day: DayKey): string => {\n spokenDayFormat ??= new Intl.DateTimeFormat('en-US', {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n timeZone: 'UTC',\n });\n return spokenDayFormat.format(fromParts(day, 'utc'));\n};\n\nexport const clampDate = (date: Date, min?: Date, max?: Date): Date => {\n if (min && date.getTime() < min.getTime()) {\n return new Date(min.getTime());\n }\n if (max && date.getTime() > max.getTime()) {\n return new Date(max.getTime());\n }\n return date;\n};\n\nexport const overlapsBounds = (from: Date, to: Date, min?: Date, max?: Date): boolean =>\n (!min || to.getTime() >= min.getTime()) && (!max || from.getTime() <= max.getTime());\n\nconst isValidDate = (value: unknown): value is Date =>\n value instanceof Date && !Number.isNaN(value.getTime());\n\nconst ZONELESS = /^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?)?$/;\n\nexport const toDate = (\n value: Date | string | number | null | undefined,\n zone: DatePickerTimeZone,\n): Date | null => {\n if (value === null || value === undefined || value === '') {\n return null;\n }\n // Without an offset, a string names a wall-clock time in `zone`, not in the browser's.\n const zoneless = typeof value === 'string' ? ZONELESS.exec(value) : null;\n if (zoneless) {\n const [, year, month, day, hours = '0', minutes = '0', seconds = '0', ms = ''] = zoneless;\n const parts = {\n year: Number(year),\n month: Number(month) - 1,\n day: Number(day),\n hours: Number(hours),\n minutes: Number(minutes),\n seconds: Number(seconds),\n };\n if (parts.hours > 23 || parts.minutes > 59 || parts.seconds > 59) {\n return null;\n }\n const date = fromParts(parts, zone, Number(ms.padEnd(3, '0')));\n return sameDay(dayKeyOf(date, zone), parts) ? date : null;\n }\n const date = value instanceof Date ? value : new Date(value);\n return isValidDate(date) ? date : null;\n};\n\nexport const withTime = (\n day: DayKey,\n time: Pick<DateTimeParts, 'hours' | 'minutes' | 'seconds'>,\n zone: DatePickerTimeZone,\n): Date =>\n fromParts(\n {\n year: day.year,\n month: day.month,\n day: day.day,\n hours: time.hours,\n minutes: time.minutes,\n seconds: time.seconds,\n },\n zone,\n );\n\nconst UNIT_MS: Record<Exclude<DatePickerPrecision, 'day'>, number> = {\n minute: 60_000,\n second: 1_000,\n};\n\n// Arithmetic, not a rebuild from local fields, which moves the repeated hour when clocks go back.\nexport const truncateTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return startOfDay(partsOf(date, zone), zone);\n }\n if (zone === 'local' && !Number.isInteger(date.getTimezoneOffset())) {\n const parts = partsOf(date, zone);\n return fromParts({ ...parts, seconds: precision === 'second' ? parts.seconds : 0 }, zone);\n }\n const unit = UNIT_MS[precision];\n return new Date(Math.floor(date.getTime() / unit) * unit);\n};\n\n/** The last millisecond of the unit `date` falls in, so a range end covers the whole of it. */\nexport const endOfUnit = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date =>\n precision === 'day'\n ? endOfDay(dayKeyOf(date, zone), zone)\n : new Date(truncateTo(date, zone, precision).getTime() + UNIT_MS[precision] - 1);\n\nexport const ceilTo = (\n date: Date,\n zone: DatePickerTimeZone,\n precision: DatePickerPrecision,\n): Date => {\n if (precision === 'day') {\n return date;\n }\n const floor = truncateTo(date, zone, precision);\n return floor.getTime() < date.getTime()\n ? new Date(floor.getTime() + UNIT_MS[precision])\n : floor;\n};\n"],"names":["MONTHS_SHORT","WEEKDAYS_SHORT","WEEKDAYS_LONG","partsOf","date","zone","fromParts","year","month","day","hours","minutes","seconds","milliseconds","shift","dayKeyOf","compareDays","a","b","sameDay","dayKeyString","startOfDay","endOfDay","addDays","amount","daysInMonth","addMonths","total","addMonthsToDay","target","weekdayOf","WEEK_START_INDEX","weekdayLabels","weekStart","_","index","weekday","monthWeeks","view","first","lead","start","weeks","startOfWeek","monthLabel","pad","value","formatTime","parts","precision","zoneSuffix","formatDate","formatTimeReadout","spokenDayFormat","spokenDay","clampDate","min","max","overlapsBounds","from","to","isValidDate","ZONELESS","toDate","zoneless","ms","withTime","time","UNIT_MS","truncateTo","unit","endOfUnit","ceilTo","floor"],"mappings":"AA4BO,MAAMA,IAAe;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAEMC,IAAiB,CAAC,MAAM,MAAM,MAAM,MAAM,MAA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ElB9D;AACJ,GAEE+D,IAA+D;AAAA,EACjE,QAAQ;AAAA,EACR,QAAQ;AACZ,GAGaC,IAAa,CACtBjE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO5B,EAAWlB,EAAQC,GAAMC,CAAI,GAAGA,CAAI;AAE/C,MAAIA,MAAS,WAAW,CAAC,OAAO,UAAUD,EAAK,kBAAA,CAAmB,GAAG;AACjE,UAAM4C,IAAQ7C,EAAQC,GAAMC,CAAI;AAChC,WAAOC,EAAU,EAAE,GAAG0C,GAAO,SAASC,MAAc,WAAWD,EAAM,UAAU,EAAA,GAAK3C,CAAI;AAAA,EAC5F;AACA,QAAMiE,IAAOF,EAAQnB,CAAS;AAC9B,SAAO,IAAI,KAAK,KAAK,MAAM7C,EAAK,QAAA,IAAYkE,CAAI,IAAIA,CAAI;AAC5D,GAGaC,IAAY,CACrBnE,GACAC,GACA4C,MAEAA,MAAc,QACR3B,EAASP,EAASX,GAAMC,CAAI,GAAGA,CAAI,IACnC,IAAI,KAAKgE,EAAWjE,GAAMC,GAAM4C,CAAS,EAAE,QAAA,IAAYmB,EAAQnB,CAAS,IAAI,CAAC,GAE1EuB,IAAS,CAClBpE,GACAC,GACA4C,MACO;AACP,MAAIA,MAAc;AACd,WAAO7C;AAEX,QAAMqE,IAAQJ,EAAWjE,GAAMC,GAAM4C,CAAS;AAC9C,SAAOwB,EAAM,QAAA,IAAYrE,EAAK,YACxB,IAAI,KAAKqE,EAAM,QAAA,IAAYL,EAAQnB,CAAS,CAAC,IAC7CwB;AACV;"}
|
|
@@ -1,76 +1,84 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w = (e, t) => e !== null ? "items" : t.trim().length > 0 ? "search" : "filters", u = (e, t) => {
|
|
2
2
|
const s = t.trim().toLowerCase();
|
|
3
3
|
return e.label.toLowerCase().includes(s) || e.value.toLowerCase().includes(s);
|
|
4
4
|
}, c = (e, t) => {
|
|
5
5
|
var s;
|
|
6
6
|
return new Set(((s = e.find((l) => l.filter === t)) == null ? void 0 : s.items) ?? []);
|
|
7
|
-
},
|
|
7
|
+
}, p = (e, t) => e.flatMap((s) => {
|
|
8
8
|
const l = c(t, s.value);
|
|
9
9
|
return s.items.map((o) => ({ item: o, filter: s, selected: l.has(o.value) }));
|
|
10
|
-
}),
|
|
11
|
-
const s = e.filter((
|
|
12
|
-
if (!s.some((
|
|
13
|
-
const l = e.every((
|
|
10
|
+
}), g = (e, t) => {
|
|
11
|
+
const s = e.filter((n) => u(n.item, t));
|
|
12
|
+
if (!s.some((n) => !n.item.disabled)) return null;
|
|
13
|
+
const l = e.every((n) => n.item.disabled || n.selected), o = t.trim().length > 0 && s.filter((n) => !n.item.disabled).every((n) => n.selected);
|
|
14
14
|
return l || o ? "deselect" : "select";
|
|
15
|
-
},
|
|
16
|
-
toggle:
|
|
17
|
-
items: e.filter((s) =>
|
|
18
|
-
}),
|
|
15
|
+
}, v = (e, t) => ({
|
|
16
|
+
toggle: g(e, t),
|
|
17
|
+
items: e.filter((s) => u(s.item, t))
|
|
18
|
+
}), S = (e, t, s, l) => {
|
|
19
|
+
var f;
|
|
20
|
+
if (e === null) return;
|
|
21
|
+
const o = t.find((i) => i.value === e), n = s == null ? void 0 : s.find((i) => i.value === e);
|
|
22
|
+
if (!o || !n) return o ?? n;
|
|
23
|
+
const r = new Set((f = l.find((i) => i.filter === e)) == null ? void 0 : f.items), a = new Set(o.items.map((i) => i.value)), m = n.items.filter((i) => r.has(i.value) && !a.has(i.value));
|
|
24
|
+
return m.length ? { ...o, items: [...o.items, ...m] } : o;
|
|
25
|
+
}, y = (e, t, s) => e ? v(p([e], t), s) : { toggle: null, items: [] }, C = (e, t, s) => v(p(e, t), s), h = (e, t) => {
|
|
19
26
|
const s = new Set(t);
|
|
20
27
|
return e.length === s.size && e.every((l) => s.has(l));
|
|
21
|
-
},
|
|
28
|
+
}, d = (e, t) => {
|
|
22
29
|
const s = t.filter(
|
|
23
|
-
(
|
|
24
|
-
), l = new Map(s.map((
|
|
25
|
-
filter:
|
|
26
|
-
items: l.get(
|
|
27
|
-
})).filter((
|
|
28
|
-
(
|
|
30
|
+
(r) => !h(r.items, [...c(e, r.filter)])
|
|
31
|
+
), l = new Map(s.map((r) => [r.filter, r.items])), o = e.map((r) => ({
|
|
32
|
+
filter: r.filter,
|
|
33
|
+
items: l.get(r.filter) ?? r.items
|
|
34
|
+
})).filter((r) => r.items.length > 0), n = s.filter(
|
|
35
|
+
(r) => r.items.length > 0 && !e.some((a) => a.filter === r.filter)
|
|
29
36
|
);
|
|
30
|
-
return { next: [...o, ...
|
|
31
|
-
},
|
|
32
|
-
const l = [...c(e, t)], o = l.includes(s) ? l.filter((
|
|
33
|
-
return
|
|
34
|
-
},
|
|
37
|
+
return { next: [...o, ...n], changes: s };
|
|
38
|
+
}, M = (e, t, s) => {
|
|
39
|
+
const l = [...c(e, t)], o = l.includes(s) ? l.filter((n) => n !== s) : [...l, s];
|
|
40
|
+
return d(e, [{ filter: t, items: o }]);
|
|
41
|
+
}, $ = (e, t, s) => d(
|
|
35
42
|
t,
|
|
36
43
|
e.map((l) => {
|
|
37
|
-
const o = c(t, l.value),
|
|
38
|
-
(
|
|
39
|
-
).map((
|
|
40
|
-
return { filter: l.value, items: [...o, ...
|
|
44
|
+
const o = c(t, l.value), n = l.items.filter(
|
|
45
|
+
(r) => !o.has(r.value) && !r.disabled && u(r, s)
|
|
46
|
+
).map((r) => r.value);
|
|
47
|
+
return { filter: l.value, items: [...o, ...n] };
|
|
41
48
|
})
|
|
42
|
-
),
|
|
49
|
+
), b = (e, t, s) => d(
|
|
43
50
|
t,
|
|
44
51
|
e.map((l) => {
|
|
45
|
-
const o = c(t, l.value),
|
|
46
|
-
l.items.filter((
|
|
52
|
+
const o = c(t, l.value), n = new Set(
|
|
53
|
+
l.items.filter((r) => !r.disabled && u(r, s)).map((r) => r.value)
|
|
47
54
|
);
|
|
48
55
|
return {
|
|
49
56
|
filter: l.value,
|
|
50
|
-
items: [...o].filter((
|
|
57
|
+
items: [...o].filter((r) => !n.has(r))
|
|
51
58
|
};
|
|
52
59
|
})
|
|
53
|
-
),
|
|
60
|
+
), k = (e, t) => d(e, [{ filter: t, items: [] }]), x = (e) => d(
|
|
54
61
|
e,
|
|
55
62
|
e.map((t) => ({ filter: t.filter, items: [] }))
|
|
56
|
-
),
|
|
57
|
-
const l = new Set(e.map((
|
|
63
|
+
), A = (e, t) => t.length === 0 ? e : t.length === 1 ? `${e}: ${t[0]}` : `${e}: (${t.join(", ")})`, R = (e, t, s = null) => {
|
|
64
|
+
const l = new Set(e.map((n) => n.filter)), o = t.filter((n) => l.has(n) || n === s);
|
|
58
65
|
return [
|
|
59
66
|
...o,
|
|
60
|
-
...e.map((
|
|
67
|
+
...e.map((n) => n.filter).filter((n) => !o.includes(n))
|
|
61
68
|
];
|
|
62
69
|
};
|
|
63
70
|
export {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
A as chipText,
|
|
72
|
+
x as clearAll,
|
|
73
|
+
b as deselectAll,
|
|
74
|
+
y as filterRows,
|
|
75
|
+
u as matchesQuery,
|
|
76
|
+
S as openFilterOf,
|
|
77
|
+
R as orderSelections,
|
|
78
|
+
k as removeFilter,
|
|
79
|
+
w as resolveMode,
|
|
80
|
+
C as searchRows,
|
|
81
|
+
$ as selectAll,
|
|
82
|
+
M as toggleValue
|
|
75
83
|
};
|
|
76
84
|
//# sourceMappingURL=filterSearchModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["export interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/** The values of one filter, as the menu lists them once that filter is picked. */\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\nexport const clearAll = (selections: FilterSearchSelection[]): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections.map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","chipText","filterLabel","itemLabels","orderSelections","order","keep","present","f"],"mappings":"AAgDO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,OAAa,UAC3BC,EAAM,KAAA,EAAO,SAAS,IAAI,WAAW,WAGnCC,IAAe,CAACC,GAAwBF,MAA2B;AAC5E,QAAMG,IAASH,EAAM,KAAA,EAAO,YAAA;AAC5B,SAAOE,EAAK,MAAM,YAAA,EAAc,SAASC,CAAM,KAAKD,EAAK,MAAM,cAAc,SAASC,CAAM;AAChG,GAEMC,IAAiB,CAACC,GAAqCC,MAAA;AAVtD,MAAAC;AAWH,aAAI,MAAIA,IAAAF,EAAW,KAAK,CAACG,MAAcA,EAAU,WAAWF,CAAM,MAA1D,gBAAAC,EAA6D,UAAS,CAAA,CAAE;AAAA,GAE9EE,IAAS,CACXC,GACAL,MAEAK,EAAQ,QAAQ,CAACJ,MAAW;AACxB,QAAMK,IAAWP,EAAeC,GAAYC,EAAO,KAAK;AACxD,SAAOA,EAAO,MAAM,IAAI,CAACJ,OAAU,EAAE,MAAAA,GAAM,QAAAI,GAAQ,UAAUK,EAAS,IAAIT,EAAK,KAAK,IAAI;AAC5F,CAAC,GAMCU,IAAY,CAACC,GAA4Bb,MAA6C;AACxF,QAAMc,IAAUD,EAAI,OAAO,CAACE,MAAQd,EAAac,EAAI,MAAMf,CAAK,CAAC;AACjE,MAAI,CAACc,EAAQ,KAAK,CAACC,MAAQ,CAACA,EAAI,KAAK,QAAQ,EAAG,QAAO;AAEvD,QAAMC,IAAuBH,EAAI,MAAM,CAACE,MAAQA,EAAI,KAAK,YAAYA,EAAI,QAAQ,GAC3EE,IACFjB,EAAM,KAAA,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;AAAA,MACf,OAAO,CAAC,GAAGK,CAAQ,EAAE,OAAO,CAACc,MAAU,CAACa,EAAQ,IAAIb,CAAK,CAAC;AAAA,IAAA;AAAA,EAElE,CAAC;AACL,GAESc,IAAe,CACxBlC,GACAC,MACqBoB,EAAarB,GAAY,CAAC,EAAE,QAAAC,GAAQ,OAAO,CAAA,GAAI,CAAC,GAE5DkC,IAAW,CAACnC,MACrBqB;AAAA,EACIrB;AAAA,EACAA,EAAW,IAAI,CAACG,OAAe,EAAE,QAAQA,EAAU,QAAQ,OAAO,CAAA,IAAK;AAC3E,GAGSiC,IAAW,CAACC,GAAqBC,MACtCA,EAAW,WAAW,IAAUD,IAChCC,EAAW,WAAW,IAAU,GAAGD,CAAW,KAAKC,EAAW,CAAC,CAAC,KAC7D,GAAGD,CAAW,MAAMC,EAAW,KAAK,IAAI,CAAC,KAOvCC,IAAkB,CAC3BvC,GACAwC,GAEAC,IAAsB,SACX;AACX,QAAMC,IAAU,IAAI,IAAI1C,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,CAAC,GACjEuB,IAAOc,EAAM,OAAO,CAACvC,MAAWyC,EAAQ,IAAIzC,CAAM,KAAKA,MAAWwC,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGf;AAAA,IACH,GAAG1B,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACwC,MAAM,CAACjB,EAAK,SAASiB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
|
1
|
+
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["export interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/** The values of one filter, as the menu lists them once that filter is picked. */\n/**\n * The open filter as its menu lists it: `filters`' entry, with any picked value only\n * `searchFilters` holds added back, so a value picked through search can be unticked from its\n * own chip. A filter only `searchFilters` holds is listed from there.\n */\nexport const openFilterOf = (\n active: string | null,\n filters: FilterSearchFilter[],\n searchFilters: FilterSearchFilter[] | undefined,\n selections: FilterSearchSelection[],\n): FilterSearchFilter | undefined => {\n if (active === null) return undefined;\n const narrowed = filters.find((filter) => filter.value === active);\n const wide = searchFilters?.find((filter) => filter.value === active);\n if (!narrowed || !wide) return narrowed ?? wide;\n const picked = new Set(selections.find((selection) => selection.filter === active)?.items);\n const listed = new Set(narrowed.items.map((item) => item.value));\n const missing = wide.items.filter((item) => picked.has(item.value) && !listed.has(item.value));\n return missing.length ? { ...narrowed, items: [...narrowed.items, ...missing] } : narrowed;\n};\n\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\nexport const clearAll = (selections: FilterSearchSelection[]): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections.map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","openFilterOf","active","searchFilters","narrowed","wide","picked","listed","missing","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","chipText","filterLabel","itemLabels","orderSelections","order","keep","present","f"],"mappings":"AAgDO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,OAAa,UAC3BC,EAAM,KAAA,EAAO,SAAS,IAAI,WAAW,WAGnCC,IAAe,CAACC,GAAwBF,MAA2B;AAC5E,QAAMG,IAASH,EAAM,KAAA,EAAO,YAAA;AAC5B,SAAOE,EAAK,MAAM,YAAA,EAAc,SAASC,CAAM,KAAKD,EAAK,MAAM,cAAc,SAASC,CAAM;AAChG,GAEMC,IAAiB,CAACC,GAAqCC,MAAA;AAVtD,MAAAC;AAWH,aAAI,MAAIA,IAAAF,EAAW,KAAK,CAACG,MAAcA,EAAU,WAAWF,CAAM,MAA1D,gBAAAC,EAA6D,UAAS,CAAA,CAAE;AAAA,GAE9EE,IAAS,CACXC,GACAL,MAEAK,EAAQ,QAAQ,CAACJ,MAAW;AACxB,QAAMK,IAAWP,EAAeC,GAAYC,EAAO,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AA,IAAA;AAAA,EAElE,CAAC;AACL,GAESc,IAAe,CACxB1C,GACAC,MACqB4B,EAAa7B,GAAY,CAAC,EAAE,QAAAC,GAAQ,OAAO,CAAA,GAAI,CAAC,GAE5D0C,IAAW,CAAC3C,MACrB6B;AAAA,EACI7B;AAAA,EACAA,EAAW,IAAI,CAACG,OAAe,EAAE,QAAQA,EAAU,QAAQ,OAAO,CAAA,IAAK;AAC3E,GAGSyC,IAAW,CAACC,GAAqBC,MACtCA,EAAW,WAAW,IAAUD,IAChCC,EAAW,WAAW,IAAU,GAAGD,CAAW,KAAKC,EAAW,CAAC,CAAC,KAC7D,GAAGD,CAAW,MAAMC,EAAW,KAAK,IAAI,CAAC,KAOvCC,IAAkB,CAC3B/C,GACAgD,GAEAC,IAAsB,SACX;AACX,QAAMC,IAAU,IAAI,IAAIlD,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,CAAC,GACjE+B,IAAOc,EAAM,OAAO,CAAC/C,MAAWiD,EAAQ,IAAIjD,CAAM,KAAKA,MAAWgD,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGf;AAAA,IACH,GAAGlC,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACgD,MAAM,CAACjB,EAAK,SAASiB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const r = "bg-[var(--malachite-table-background,#f7f7f7)] p-[4px] rounded-xl", o = 4, c = "var(--malachite-radius-xl, 12px)", e = 8, a = "1px solid var(--malachite-card-border, #e8e8e8)", t = {
|
|
2
|
+
background: "var(--malachite-table-row-background, #fff)",
|
|
3
|
+
border: a,
|
|
4
|
+
borderRadius: 8
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
r as FRAME_CLASS,
|
|
8
|
+
o as FRAME_PADDING,
|
|
9
|
+
c as FRAME_RADIUS,
|
|
10
|
+
a as FRAME_SECTION_BORDER,
|
|
11
|
+
e as FRAME_SECTION_RADIUS,
|
|
12
|
+
t as FRAME_SECTION_STYLE
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=frameStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameStyles.js","sources":["../../src/components/frameStyles.ts"],"sourcesContent":["import type React from 'react';\n\n/**\n * The grey frame the detached Table draws around its header and rows, shared with Card's\n * `framed` variant so a card and the table beside it read as one set in both themes.\n */\nexport const FRAME_CLASS = 'bg-[var(--malachite-table-background,#f7f7f7)] p-[4px] rounded-xl';\n/** The `p-[4px]` in `FRAME_CLASS`, for geometry that has to offset it. */\nexport const FRAME_PADDING = 4;\n/** The radius `rounded-xl` in `FRAME_CLASS` resolves to. Read from the same token, or overriding\n * `radius.xl` pinches the corners of anything drawn to match them. */\nexport const FRAME_RADIUS = 'var(--malachite-radius-xl, 12px)';\n\n/** The bordered section inside the frame is clipped to this radius. The detached Table's first\n * and last rows echo it, so a selected row's accent bar curves into the corner instead of\n * being cut off by the clip. */\nexport const FRAME_SECTION_RADIUS = 8;\nexport const FRAME_SECTION_BORDER = '1px solid var(--malachite-card-border, #e8e8e8)';\n\n/** The bordered section a framed Card's children sit in, as the detached Table's rows do. */\nexport const FRAME_SECTION_STYLE: React.CSSProperties = {\n background: 'var(--malachite-table-row-background, #fff)',\n border: FRAME_SECTION_BORDER,\n borderRadius: FRAME_SECTION_RADIUS,\n};\n"],"names":["FRAME_CLASS","FRAME_PADDING","FRAME_RADIUS","FRAME_SECTION_RADIUS","FRAME_SECTION_BORDER","FRAME_SECTION_STYLE"],"mappings":"AAMO,MAAMA,IAAc,qEAEdC,IAAgB,GAGhBC,IAAe,oCAKfC,IAAuB,GACvBC,IAAuB,mDAGvBC,IAA2C;AAAA,EACpD,YAAY;AAAA,EACZ,QAAQD;AAAA,EACR,cAAc;AAClB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headerContent.js","sources":["../../src/components/headerContent.ts"],"sourcesContent":["import type React from 'react';\n\n/** Whether a header slot has something to draw: `0` does, `null`, `false` and `''` do not. */\nexport const isShown = (node: React.ReactNode): boolean =>\n node !== undefined && node !== null && node !== false && node !== '';\n\nexport const hasHeaderContent = ({\n title,\n subtitle,\n extra,\n}: {\n title?: React.ReactNode;\n subtitle?: React.ReactNode;\n extra?: React.ReactNode;\n}): boolean => isShown(title) || isShown(subtitle) || isShown(extra);\n"],"names":["isShown","node","hasHeaderContent","title","subtitle","extra"],"mappings":"AAGO,MAAMA,IAAU,CAACC,MACEA,KAAS,QAAQA,MAAS,MAASA,MAAS,IAEzDC,IAAmB,CAAC;AAAA,EAC7B,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AACJ,MAIeL,EAAQG,CAAK,KAAKH,EAAQI,CAAQ,KAAKJ,EAAQK,CAAK;"}
|