@flanksource/clicky-ui 0.3.82 → 0.3.84
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/components/DateField.cjs.map +1 -1
- package/dist/components/DateField.d.ts +3 -2
- package/dist/components/DateField.d.ts.map +1 -1
- package/dist/components/DateField.js.map +1 -1
- package/dist/components/DatePicker.cjs +9 -61
- package/dist/components/DatePicker.cjs.map +1 -1
- package/dist/components/DatePicker.d.ts +5 -19
- package/dist/components/DatePicker.d.ts.map +1 -1
- package/dist/components/DatePicker.js +11 -63
- package/dist/components/DatePicker.js.map +1 -1
- package/dist/components/DateTimePicker.cjs +9 -78
- package/dist/components/DateTimePicker.cjs.map +1 -1
- package/dist/components/DateTimePicker.d.ts +5 -19
- package/dist/components/DateTimePicker.d.ts.map +1 -1
- package/dist/components/DateTimePicker.js +11 -80
- package/dist/components/DateTimePicker.js.map +1 -1
- package/dist/components/calendar-grid.cjs +83 -0
- package/dist/components/calendar-grid.cjs.map +1 -0
- package/dist/components/calendar-grid.d.ts +9 -0
- package/dist/components/calendar-grid.d.ts.map +1 -0
- package/dist/components/calendar-grid.js +83 -0
- package/dist/components/calendar-grid.js.map +1 -0
- package/dist/components/date-input-field.cjs +88 -0
- package/dist/components/date-input-field.cjs.map +1 -0
- package/dist/components/date-input-field.d.ts +37 -0
- package/dist/components/date-input-field.d.ts.map +1 -0
- package/dist/components/date-input-field.js +88 -0
- package/dist/components/date-input-field.js.map +1 -0
- package/dist/components/date-math.cjs +67 -0
- package/dist/components/date-math.cjs.map +1 -0
- package/dist/components/date-math.d.ts +33 -0
- package/dist/components/date-math.d.ts.map +1 -0
- package/dist/components/date-math.js +60 -0
- package/dist/components/date-math.js.map +1 -0
- package/dist/components/date-picker-menu.cjs +129 -0
- package/dist/components/date-picker-menu.cjs.map +1 -0
- package/dist/components/date-picker-menu.d.ts +18 -0
- package/dist/components/date-picker-menu.d.ts.map +1 -0
- package/dist/components/date-picker-menu.js +129 -0
- package/dist/components/date-picker-menu.js.map +1 -0
- package/dist/components/json-schema-form-date-math.cjs +15 -11
- package/dist/components/json-schema-form-date-math.cjs.map +1 -1
- package/dist/components/json-schema-form-date-math.d.ts +3 -0
- package/dist/components/json-schema-form-date-math.d.ts.map +1 -1
- package/dist/components/json-schema-form-date-math.js +15 -12
- package/dist/components/json-schema-form-date-math.js.map +1 -1
- package/dist/components.d.ts +1 -0
- package/dist/components.d.ts.map +1 -1
- package/dist/data/PromptDialog.cjs +19 -5
- package/dist/data/PromptDialog.cjs.map +1 -1
- package/dist/data/PromptDialog.d.ts +15 -1
- package/dist/data/PromptDialog.d.ts.map +1 -1
- package/dist/data/PromptDialog.js +19 -5
- package/dist/data/PromptDialog.js.map +1 -1
- package/dist/data/PromptIndicator.cjs +3 -2
- package/dist/data/PromptIndicator.cjs.map +1 -1
- package/dist/data/PromptIndicator.d.ts +4 -1
- package/dist/data/PromptIndicator.d.ts.map +1 -1
- package/dist/data/PromptIndicator.js +3 -2
- package/dist/data/PromptIndicator.js.map +1 -1
- package/dist/data/diagnostics/ErrorDetails.cjs +155 -110
- package/dist/data/diagnostics/ErrorDetails.cjs.map +1 -1
- package/dist/data/diagnostics/ErrorDetails.d.ts.map +1 -1
- package/dist/data/diagnostics/ErrorDetails.js +155 -110
- package/dist/data/diagnostics/ErrorDetails.js.map +1 -1
- package/dist/data/test-runner/TestDetailPanel.cjs +109 -46
- package/dist/data/test-runner/TestDetailPanel.cjs.map +1 -1
- package/dist/data/test-runner/TestDetailPanel.d.ts.map +1 -1
- package/dist/data/test-runner/TestDetailPanel.js +110 -47
- package/dist/data/test-runner/TestDetailPanel.js.map +1 -1
- package/dist/data/test-runner/TestTreeNode.cjs +84 -63
- package/dist/data/test-runner/TestTreeNode.cjs.map +1 -1
- package/dist/data/test-runner/TestTreeNode.d.ts.map +1 -1
- package/dist/data/test-runner/TestTreeNode.js +84 -63
- package/dist/data/test-runner/TestTreeNode.js.map +1 -1
- package/dist/data/test-runner/adapter.cjs.map +1 -1
- package/dist/data/test-runner/adapter.d.ts +2 -2
- package/dist/data/test-runner/adapter.d.ts.map +1 -1
- package/dist/data/test-runner/adapter.js.map +1 -1
- package/dist/data/test-runner/copy.cjs +62 -10
- package/dist/data/test-runner/copy.cjs.map +1 -1
- package/dist/data/test-runner/copy.d.ts +52 -9
- package/dist/data/test-runner/copy.d.ts.map +1 -1
- package/dist/data/test-runner/copy.js +60 -11
- package/dist/data/test-runner/copy.js.map +1 -1
- package/dist/data/test-runner/index.d.ts +1 -1
- package/dist/data/test-runner/index.d.ts.map +1 -1
- package/dist/data/verification/StepFilesView.cjs +90 -0
- package/dist/data/verification/StepFilesView.cjs.map +1 -0
- package/dist/data/verification/StepFilesView.d.ts +9 -0
- package/dist/data/verification/StepFilesView.d.ts.map +1 -0
- package/dist/data/verification/StepFilesView.js +90 -0
- package/dist/data/verification/StepFilesView.js.map +1 -0
- package/dist/data/verification/adapterViews.cjs +129 -69
- package/dist/data/verification/adapterViews.cjs.map +1 -1
- package/dist/data/verification/adapterViews.d.ts +3 -1
- package/dist/data/verification/adapterViews.d.ts.map +1 -1
- package/dist/data/verification/adapterViews.js +130 -70
- package/dist/data/verification/adapterViews.js.map +1 -1
- package/dist/data/verification/adapters.cjs +9 -0
- package/dist/data/verification/adapters.cjs.map +1 -1
- package/dist/data/verification/adapters.d.ts +2 -0
- package/dist/data/verification/adapters.d.ts.map +1 -1
- package/dist/data/verification/adapters.js +11 -2
- package/dist/data/verification/adapters.js.map +1 -1
- package/dist/data/verification/index.d.ts +2 -1
- package/dist/data/verification/index.d.ts.map +1 -1
- package/dist/data/verification/stepKind.cjs +63 -7
- package/dist/data/verification/stepKind.cjs.map +1 -1
- package/dist/data/verification/stepKind.d.ts +55 -6
- package/dist/data/verification/stepKind.d.ts.map +1 -1
- package/dist/data/verification/stepKind.js +62 -8
- package/dist/data/verification/stepKind.js.map +1 -1
- package/dist/data/verification/stepKindViews.cjs +318 -106
- package/dist/data/verification/stepKindViews.cjs.map +1 -1
- package/dist/data/verification/stepKindViews.d.ts +17 -6
- package/dist/data/verification/stepKindViews.d.ts.map +1 -1
- package/dist/data/verification/stepKindViews.js +319 -108
- package/dist/data/verification/stepKindViews.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/data.cjs +4 -0
- package/dist/data.d.ts +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +3 -2
- package/dist/hooks/use-prompts.cjs +52 -30
- package/dist/hooks/use-prompts.cjs.map +1 -1
- package/dist/hooks/use-prompts.d.ts +6 -0
- package/dist/hooks/use-prompts.d.ts.map +1 -1
- package/dist/hooks/use-prompts.js +52 -30
- package/dist/hooks/use-prompts.js.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.js +4 -3
- package/dist/runtime/barrels.json +5874 -5867
- package/dist/runtime/importmap.json +2175 -2170
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_Icon = require("../data/Icon.cjs");
|
|
2
|
+
const require_UiArrowLeft = require("../icons/components/UiArrowLeft.cjs");
|
|
3
|
+
const require_UiArrowRight = require("../icons/components/UiArrowRight.cjs");
|
|
4
|
+
const require_utils = require("../lib/utils.cjs");
|
|
5
|
+
const require_date_math = require("./date-math.cjs");
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
// src/components/calendar-grid.tsx
|
|
9
|
+
var weekdays = [
|
|
10
|
+
"Su",
|
|
11
|
+
"Mo",
|
|
12
|
+
"Tu",
|
|
13
|
+
"We",
|
|
14
|
+
"Th",
|
|
15
|
+
"Fr",
|
|
16
|
+
"Sa"
|
|
17
|
+
];
|
|
18
|
+
var navButtonClassName = "inline-flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
|
19
|
+
/**
|
|
20
|
+
* An inline month calendar. `value` is the selected `YYYY-MM-DD` ("" for none); the month shown
|
|
21
|
+
* follows it until the user pages away.
|
|
22
|
+
*/
|
|
23
|
+
function CalendarGrid({ value, onSelect }) {
|
|
24
|
+
const today = require_date_math.formatLocalDate(/* @__PURE__ */ new Date());
|
|
25
|
+
const [paged, setPaged] = (0, react.useState)(null);
|
|
26
|
+
const month = paged ?? (value || today).slice(0, 7);
|
|
27
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
29
|
+
className: "flex flex-col gap-1.5",
|
|
30
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
31
|
+
className: "flex items-center justify-between",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
34
|
+
type: "button",
|
|
35
|
+
"aria-label": "Previous month",
|
|
36
|
+
className: navButtonClassName,
|
|
37
|
+
onClick: () => setPaged(require_date_math.shiftMonth(month, -1)),
|
|
38
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Icon.Icon, {
|
|
39
|
+
icon: require_UiArrowLeft.UiArrowLeft,
|
|
40
|
+
className: "text-[12px]"
|
|
41
|
+
})
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
44
|
+
className: "text-xs font-semibold tabular-nums",
|
|
45
|
+
"aria-live": "polite",
|
|
46
|
+
children: new Date(year, monthNumber - 1, 1).toLocaleDateString("en-US", {
|
|
47
|
+
month: "long",
|
|
48
|
+
year: "numeric"
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
52
|
+
type: "button",
|
|
53
|
+
"aria-label": "Next month",
|
|
54
|
+
className: navButtonClassName,
|
|
55
|
+
onClick: () => setPaged(require_date_math.shiftMonth(month, 1)),
|
|
56
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Icon.Icon, {
|
|
57
|
+
icon: require_UiArrowRight.UiArrowRight,
|
|
58
|
+
className: "text-[12px]"
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
63
|
+
className: "grid grid-cols-7 gap-0.5 text-center",
|
|
64
|
+
children: [weekdays.map((weekday) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
65
|
+
className: "py-0.5 text-[10px] font-semibold uppercase text-muted-foreground",
|
|
66
|
+
children: weekday
|
|
67
|
+
}, weekday)), require_date_math.monthGrid(month).map(({ date, inMonth }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
68
|
+
type: "button",
|
|
69
|
+
"aria-label": date,
|
|
70
|
+
"aria-pressed": date === value,
|
|
71
|
+
className: require_utils.cn("h-7 rounded-md text-[11.5px] tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", date === value ? "bg-foreground font-semibold text-background" : require_utils.cn("hover:bg-muted", inMonth ? "text-foreground" : "text-muted-foreground/50"), date === today && date !== value && "ring-1 ring-border"),
|
|
72
|
+
onClick: () => {
|
|
73
|
+
setPaged(null);
|
|
74
|
+
onSelect(date);
|
|
75
|
+
},
|
|
76
|
+
children: Number(date.slice(8))
|
|
77
|
+
}, date))]
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.CalendarGrid = CalendarGrid;
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=calendar-grid.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-grid.cjs","names":["formatLocalDate","useState","shiftMonth","Icon","UiArrowLeft","UiArrowRight","monthGrid","cn"],"sources":["../../src/components/calendar-grid.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiArrowLeft, UiArrowRight } from \"../icons\";\nimport { cn } from \"../lib/utils\";\nimport { formatLocalDate, monthGrid, shiftMonth } from \"./date-math\";\n\nconst weekdays = [\"Su\", \"Mo\", \"Tu\", \"We\", \"Th\", \"Fr\", \"Sa\"];\n\nconst navButtonClassName =\n \"inline-flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n\n/**\n * An inline month calendar. `value` is the selected `YYYY-MM-DD` (\"\" for none); the month shown\n * follows it until the user pages away.\n */\nexport function CalendarGrid({ value, onSelect }: { value: string; onSelect: (date: string) => void }) {\n const today = formatLocalDate(new Date());\n const [paged, setPaged] = useState<string | null>(null);\n const month = paged ?? (value || today).slice(0, 7);\n const [year = 0, monthNumber = 1] = month.split(\"-\").map(Number);\n\n return (\n <div className=\"flex flex-col gap-1.5\">\n <div className=\"flex items-center justify-between\">\n <button type=\"button\" aria-label=\"Previous month\" className={navButtonClassName} onClick={() => setPaged(shiftMonth(month, -1))}>\n <Icon icon={UiArrowLeft} className=\"text-[12px]\" />\n </button>\n <span className=\"text-xs font-semibold tabular-nums\" aria-live=\"polite\">\n {new Date(year, monthNumber - 1, 1).toLocaleDateString(\"en-US\", { month: \"long\", year: \"numeric\" })}\n </span>\n <button type=\"button\" aria-label=\"Next month\" className={navButtonClassName} onClick={() => setPaged(shiftMonth(month, 1))}>\n <Icon icon={UiArrowRight} className=\"text-[12px]\" />\n </button>\n </div>\n <div className=\"grid grid-cols-7 gap-0.5 text-center\">\n {weekdays.map((weekday) => (\n <span key={weekday} className=\"py-0.5 text-[10px] font-semibold uppercase text-muted-foreground\">\n {weekday}\n </span>\n ))}\n {monthGrid(month).map(({ date, inMonth }) => (\n <button\n key={date}\n type=\"button\"\n aria-label={date}\n aria-pressed={date === value}\n className={cn(\n \"h-7 rounded-md text-[11.5px] tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n date === value\n ? \"bg-foreground font-semibold text-background\"\n : cn(\"hover:bg-muted\", inMonth ? \"text-foreground\" : \"text-muted-foreground/50\"),\n date === today && date !== value && \"ring-1 ring-border\",\n )}\n onClick={() => {\n setPaged(null);\n onSelect(date);\n }}\n >\n {Number(date.slice(8))}\n </button>\n ))}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,WAAW;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;AAE1D,IAAM,qBACJ;;;;;AAMF,SAAgB,aAAa,EAAE,OAAO,YAAiE;CACrG,MAAM,QAAQA,kBAAAA,gCAAgB,IAAI,KAAK,CAAC;CACxC,MAAM,CAAC,OAAO,aAAA,GAAYC,MAAAA,SAAAA,CAAwB,IAAI;CACtD,MAAM,QAAQ,UAAU,SAAS,MAAA,CAAO,MAAM,GAAG,CAAC;CAClD,MAAM,CAAC,OAAO,GAAG,cAAc,KAAK,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAE/D,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;KAAQ,MAAK;KAAS,cAAW;KAAiB,WAAW;KAAoB,eAAe,SAASC,kBAAAA,WAAW,OAAO,EAAE,CAAC;KAC5H,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,aAAAA,MAAD;MAAM,MAAMC,oBAAAA;MAAa,WAAU;KAAe,CAAA;IAC5C,CAAA;IACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAAM,WAAU;KAAqC,aAAU;KAC5D,UAAA,IAAI,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,mBAAmB,SAAS;MAAE,OAAO;MAAQ,MAAM;KAAU,CAAC;IAC9F,CAAA;IACN,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;KAAQ,MAAK;KAAS,cAAW;KAAa,WAAW;KAAoB,eAAe,SAASF,kBAAAA,WAAW,OAAO,CAAC,CAAC;KACvH,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,aAAAA,MAAD;MAAM,MAAME,qBAAAA;MAAc,WAAU;KAAe,CAAA;IAC7C,CAAA;GACL;EACL,CAAA,GAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,SAAS,KAAK,YACb,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IAAoB,WAAU;IAC3B,UAAA;GACG,GAFK,OAEL,CACP,GACAC,kBAAAA,UAAU,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,cAC7B,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;IAEE,MAAK;IACL,cAAY;IACZ,gBAAc,SAAS;IACvB,WAAWC,cAAAA,GACT,uIACA,SAAS,QACL,gDACAA,cAAAA,GAAG,kBAAkB,UAAU,oBAAoB,0BAA0B,GACjF,SAAS,SAAS,SAAS,SAAS,oBACtC;IACA,eAAe;KACb,SAAS,IAAI;KACb,SAAS,IAAI;IACf;IAEC,UAAA,OAAO,KAAK,MAAM,CAAC,CAAC;GACf,GAjBD,IAiBC,CACT,CACE;EACF,CAAA,CAAA;;AAET"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An inline month calendar. `value` is the selected `YYYY-MM-DD` ("" for none); the month shown
|
|
3
|
+
* follows it until the user pages away.
|
|
4
|
+
*/
|
|
5
|
+
export declare function CalendarGrid({ value, onSelect }: {
|
|
6
|
+
value: string;
|
|
7
|
+
onSelect: (date: string) => void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=calendar-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-grid.d.ts","sourceRoot":"","sources":["../../src/components/calendar-grid.tsx"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,+BAiDpG"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Icon } from "../data/Icon.js";
|
|
2
|
+
import { UiArrowLeft } from "../icons/components/UiArrowLeft.js";
|
|
3
|
+
import { UiArrowRight } from "../icons/components/UiArrowRight.js";
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { formatLocalDate, monthGrid, shiftMonth } from "./date-math.js";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/components/calendar-grid.tsx
|
|
9
|
+
var weekdays = [
|
|
10
|
+
"Su",
|
|
11
|
+
"Mo",
|
|
12
|
+
"Tu",
|
|
13
|
+
"We",
|
|
14
|
+
"Th",
|
|
15
|
+
"Fr",
|
|
16
|
+
"Sa"
|
|
17
|
+
];
|
|
18
|
+
var navButtonClassName = "inline-flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
|
19
|
+
/**
|
|
20
|
+
* An inline month calendar. `value` is the selected `YYYY-MM-DD` ("" for none); the month shown
|
|
21
|
+
* follows it until the user pages away.
|
|
22
|
+
*/
|
|
23
|
+
function CalendarGrid({ value, onSelect }) {
|
|
24
|
+
const today = formatLocalDate(/* @__PURE__ */ new Date());
|
|
25
|
+
const [paged, setPaged] = useState(null);
|
|
26
|
+
const month = paged ?? (value || today).slice(0, 7);
|
|
27
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
28
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
29
|
+
className: "flex flex-col gap-1.5",
|
|
30
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
31
|
+
className: "flex items-center justify-between",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx("button", {
|
|
34
|
+
type: "button",
|
|
35
|
+
"aria-label": "Previous month",
|
|
36
|
+
className: navButtonClassName,
|
|
37
|
+
onClick: () => setPaged(shiftMonth(month, -1)),
|
|
38
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
39
|
+
icon: UiArrowLeft,
|
|
40
|
+
className: "text-[12px]"
|
|
41
|
+
})
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx("span", {
|
|
44
|
+
className: "text-xs font-semibold tabular-nums",
|
|
45
|
+
"aria-live": "polite",
|
|
46
|
+
children: new Date(year, monthNumber - 1, 1).toLocaleDateString("en-US", {
|
|
47
|
+
month: "long",
|
|
48
|
+
year: "numeric"
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsx("button", {
|
|
52
|
+
type: "button",
|
|
53
|
+
"aria-label": "Next month",
|
|
54
|
+
className: navButtonClassName,
|
|
55
|
+
onClick: () => setPaged(shiftMonth(month, 1)),
|
|
56
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
57
|
+
icon: UiArrowRight,
|
|
58
|
+
className: "text-[12px]"
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
63
|
+
className: "grid grid-cols-7 gap-0.5 text-center",
|
|
64
|
+
children: [weekdays.map((weekday) => /* @__PURE__ */ jsx("span", {
|
|
65
|
+
className: "py-0.5 text-[10px] font-semibold uppercase text-muted-foreground",
|
|
66
|
+
children: weekday
|
|
67
|
+
}, weekday)), monthGrid(month).map(({ date, inMonth }) => /* @__PURE__ */ jsx("button", {
|
|
68
|
+
type: "button",
|
|
69
|
+
"aria-label": date,
|
|
70
|
+
"aria-pressed": date === value,
|
|
71
|
+
className: cn("h-7 rounded-md text-[11.5px] tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", date === value ? "bg-foreground font-semibold text-background" : cn("hover:bg-muted", inMonth ? "text-foreground" : "text-muted-foreground/50"), date === today && date !== value && "ring-1 ring-border"),
|
|
72
|
+
onClick: () => {
|
|
73
|
+
setPaged(null);
|
|
74
|
+
onSelect(date);
|
|
75
|
+
},
|
|
76
|
+
children: Number(date.slice(8))
|
|
77
|
+
}, date))]
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export { CalendarGrid };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=calendar-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-grid.js","names":[],"sources":["../../src/components/calendar-grid.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiArrowLeft, UiArrowRight } from \"../icons\";\nimport { cn } from \"../lib/utils\";\nimport { formatLocalDate, monthGrid, shiftMonth } from \"./date-math\";\n\nconst weekdays = [\"Su\", \"Mo\", \"Tu\", \"We\", \"Th\", \"Fr\", \"Sa\"];\n\nconst navButtonClassName =\n \"inline-flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n\n/**\n * An inline month calendar. `value` is the selected `YYYY-MM-DD` (\"\" for none); the month shown\n * follows it until the user pages away.\n */\nexport function CalendarGrid({ value, onSelect }: { value: string; onSelect: (date: string) => void }) {\n const today = formatLocalDate(new Date());\n const [paged, setPaged] = useState<string | null>(null);\n const month = paged ?? (value || today).slice(0, 7);\n const [year = 0, monthNumber = 1] = month.split(\"-\").map(Number);\n\n return (\n <div className=\"flex flex-col gap-1.5\">\n <div className=\"flex items-center justify-between\">\n <button type=\"button\" aria-label=\"Previous month\" className={navButtonClassName} onClick={() => setPaged(shiftMonth(month, -1))}>\n <Icon icon={UiArrowLeft} className=\"text-[12px]\" />\n </button>\n <span className=\"text-xs font-semibold tabular-nums\" aria-live=\"polite\">\n {new Date(year, monthNumber - 1, 1).toLocaleDateString(\"en-US\", { month: \"long\", year: \"numeric\" })}\n </span>\n <button type=\"button\" aria-label=\"Next month\" className={navButtonClassName} onClick={() => setPaged(shiftMonth(month, 1))}>\n <Icon icon={UiArrowRight} className=\"text-[12px]\" />\n </button>\n </div>\n <div className=\"grid grid-cols-7 gap-0.5 text-center\">\n {weekdays.map((weekday) => (\n <span key={weekday} className=\"py-0.5 text-[10px] font-semibold uppercase text-muted-foreground\">\n {weekday}\n </span>\n ))}\n {monthGrid(month).map(({ date, inMonth }) => (\n <button\n key={date}\n type=\"button\"\n aria-label={date}\n aria-pressed={date === value}\n className={cn(\n \"h-7 rounded-md text-[11.5px] tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n date === value\n ? \"bg-foreground font-semibold text-background\"\n : cn(\"hover:bg-muted\", inMonth ? \"text-foreground\" : \"text-muted-foreground/50\"),\n date === today && date !== value && \"ring-1 ring-border\",\n )}\n onClick={() => {\n setPaged(null);\n onSelect(date);\n }}\n >\n {Number(date.slice(8))}\n </button>\n ))}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,WAAW;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;AAE1D,IAAM,qBACJ;;;;;AAMF,SAAgB,aAAa,EAAE,OAAO,YAAiE;CACrG,MAAM,QAAQ,gCAAgB,IAAI,KAAK,CAAC;CACxC,MAAM,CAAC,OAAO,YAAY,SAAwB,IAAI;CACtD,MAAM,QAAQ,UAAU,SAAS,MAAA,CAAO,MAAM,GAAG,CAAC;CAClD,MAAM,CAAC,OAAO,GAAG,cAAc,KAAK,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAE/D,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,oBAAC,UAAD;KAAQ,MAAK;KAAS,cAAW;KAAiB,WAAW;KAAoB,eAAe,SAAS,WAAW,OAAO,EAAE,CAAC;KAC5H,UAAA,oBAAC,MAAD;MAAM,MAAM;MAAa,WAAU;KAAe,CAAA;IAC5C,CAAA;IACR,oBAAC,QAAD;KAAM,WAAU;KAAqC,aAAU;KAC5D,UAAA,IAAI,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,mBAAmB,SAAS;MAAE,OAAO;MAAQ,MAAM;KAAU,CAAC;IAC9F,CAAA;IACN,oBAAC,UAAD;KAAQ,MAAK;KAAS,cAAW;KAAa,WAAW;KAAoB,eAAe,SAAS,WAAW,OAAO,CAAC,CAAC;KACvH,UAAA,oBAAC,MAAD;MAAM,MAAM;MAAc,WAAU;KAAe,CAAA;IAC7C,CAAA;GACL;EACL,CAAA,GAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,SAAS,KAAK,YACb,oBAAC,QAAD;IAAoB,WAAU;IAC3B,UAAA;GACG,GAFK,OAEL,CACP,GACA,UAAU,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,cAC7B,oBAAC,UAAD;IAEE,MAAK;IACL,cAAY;IACZ,gBAAc,SAAS;IACvB,WAAW,GACT,uIACA,SAAS,QACL,gDACA,GAAG,kBAAkB,UAAU,oBAAoB,0BAA0B,GACjF,SAAS,SAAS,SAAS,SAAS,oBACtC;IACA,eAAe;KACb,SAAS,IAAI;KACb,SAAS,IAAI;IACf;IAEC,UAAA,OAAO,KAAK,MAAM,CAAC,CAAC;GACf,GAjBD,IAiBC,CACT,CACE;EACF,CAAA,CAAA;;AAET"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_utils = require("../lib/utils.cjs");
|
|
2
|
+
const require_date_math = require("./date-math.cjs");
|
|
3
|
+
const require_date_picker_menu = require("./date-picker-menu.cjs");
|
|
4
|
+
const require_field_clear_button = require("./field-clear-button.cjs");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
// src/components/date-input-field.tsx
|
|
8
|
+
function useForwardedRef(ref) {
|
|
9
|
+
const localRef = (0, react.useRef)(null);
|
|
10
|
+
const assign = (node) => {
|
|
11
|
+
localRef.current = node;
|
|
12
|
+
if (typeof ref === "function") ref(node);
|
|
13
|
+
else if (ref) ref.current = node;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
localRef,
|
|
17
|
+
assign
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function inputClasses({ prefix, suffix, showClear, inputClassName }) {
|
|
21
|
+
return require_utils.cn("h-control-h w-full rounded-md border border-input bg-background px-control-px pr-8 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", "[&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none", prefix && "pl-8", inputClassName, (showClear || suffix) && "pr-16", showClear && suffix && "pr-24");
|
|
22
|
+
}
|
|
23
|
+
function TrailingAdornments({ suffix, showClear, clearLabel, onClear }) {
|
|
24
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [suffix && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
25
|
+
className: require_utils.cn("absolute inset-y-0 flex items-center", showClear ? "right-14" : "right-7"),
|
|
26
|
+
children: suffix
|
|
27
|
+
}), showClear && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
28
|
+
className: "absolute inset-y-0 right-7 flex items-center",
|
|
29
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_field_clear_button.FieldClearButton, {
|
|
30
|
+
...clearLabel ? { clearLabel } : {},
|
|
31
|
+
onClear
|
|
32
|
+
})
|
|
33
|
+
})] });
|
|
34
|
+
}
|
|
35
|
+
var DateInputField = (0, react.forwardRef)(({ value = "", onChange, className, inputClassName, buttonClassName, openButtonLabel, suffix, prefix, clearable, onClear, clearLabel, dateMath = false, dateMathPresets, withTime, ...props }, ref) => {
|
|
36
|
+
const { localRef, assign } = useForwardedRef(ref);
|
|
37
|
+
const inactive = props.disabled || props.readOnly;
|
|
38
|
+
const showClear = !!clearable && value !== "" && !inactive;
|
|
39
|
+
const clear = () => {
|
|
40
|
+
if (onClear) onClear();
|
|
41
|
+
else onChange?.("");
|
|
42
|
+
localRef.current?.focus();
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
45
|
+
"data-jsf-control": true,
|
|
46
|
+
"data-clearable-field": true,
|
|
47
|
+
className: require_utils.cn("relative", className),
|
|
48
|
+
children: [
|
|
49
|
+
prefix && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
50
|
+
className: "absolute inset-y-0 left-1.5 flex items-center",
|
|
51
|
+
children: prefix
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
54
|
+
...props,
|
|
55
|
+
ref: assign,
|
|
56
|
+
type: withTime || dateMath ? "text" : "date",
|
|
57
|
+
value,
|
|
58
|
+
...dateMath && require_date_math.isInvalidDateMath(value) ? { "aria-invalid": true } : {},
|
|
59
|
+
className: inputClasses({
|
|
60
|
+
prefix,
|
|
61
|
+
suffix,
|
|
62
|
+
showClear,
|
|
63
|
+
inputClassName
|
|
64
|
+
}),
|
|
65
|
+
onChange: (event) => onChange?.(event.target.value)
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TrailingAdornments, {
|
|
68
|
+
suffix,
|
|
69
|
+
showClear,
|
|
70
|
+
clearLabel,
|
|
71
|
+
onClear: clear
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_date_picker_menu.DatePickerMenuButton, {
|
|
74
|
+
ariaLabel: openButtonLabel,
|
|
75
|
+
disabled: inactive,
|
|
76
|
+
className: require_utils.cn("absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", buttonClassName),
|
|
77
|
+
value,
|
|
78
|
+
presets: dateMath ? dateMathPresets : void 0,
|
|
79
|
+
withTime,
|
|
80
|
+
onSelect: (next) => onChange?.(next)
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
DateInputField.displayName = "DateInputField";
|
|
86
|
+
exports.DateInputField = DateInputField;
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=date-input-field.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-input-field.cjs","names":["useRef","cn","_Fragment","FieldClearButton","forwardRef","isInvalidDateMath","DatePickerMenuButton"],"sources":["../../src/components/date-input-field.tsx"],"sourcesContent":["import { forwardRef, useRef, type ForwardedRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { isInvalidDateMath, type DateMathProps } from \"./date-math\";\nimport { DatePickerMenuButton } from \"./date-picker-menu\";\nimport { FieldClearButton, type ClearableFieldProps } from \"./field-clear-button\";\n\nexport type DateFieldProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n // `prefix` is a global HTML attribute typed as string; omit it so our\n // ReactNode adornment prop below is not intersected down to `string & ReactNode`.\n \"type\" | \"value\" | \"onChange\" | \"prefix\"\n> & ClearableFieldProps & DateMathProps & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n /** Leading in-field adornment, rendered at the left edge of the input. */\n prefix?: ReactNode;\n};\n\nexport type DateInputFieldProps = DateFieldProps & {\n openButtonLabel: string;\n dateMathPresets: readonly string[];\n withTime: boolean;\n};\n\nfunction useForwardedRef(ref: ForwardedRef<HTMLInputElement>) {\n const localRef = useRef<HTMLInputElement | null>(null);\n const assign = (node: HTMLInputElement | null) => {\n localRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n };\n return { localRef, assign };\n}\n\nfunction inputClasses({\n prefix,\n suffix,\n showClear,\n inputClassName,\n}: {\n prefix: ReactNode;\n suffix: ReactNode;\n showClear: boolean;\n inputClassName: string | undefined;\n}) {\n return cn(\n \"h-control-h w-full rounded-md border border-input bg-background px-control-px pr-8 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n \"[&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none\",\n prefix && \"pl-8\",\n inputClassName,\n (showClear || suffix) && \"pr-16\",\n showClear && suffix && \"pr-24\",\n );\n}\n\nfunction TrailingAdornments({\n suffix,\n showClear,\n clearLabel,\n onClear,\n}: {\n suffix: ReactNode;\n showClear: boolean;\n clearLabel: string | undefined;\n onClear: () => void;\n}) {\n return (\n <>\n {suffix && (\n <div className={cn(\"absolute inset-y-0 flex items-center\", showClear ? \"right-14\" : \"right-7\")}>{suffix}</div>\n )}\n {showClear && (\n <span className=\"absolute inset-y-0 right-7 flex items-center\">\n <FieldClearButton {...(clearLabel ? { clearLabel } : {})} onClear={onClear} />\n </span>\n )}\n </>\n );\n}\n\nexport const DateInputField = forwardRef<HTMLInputElement, DateInputFieldProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel,\n suffix,\n prefix,\n clearable,\n onClear,\n clearLabel,\n dateMath = false,\n dateMathPresets,\n withTime,\n ...props\n },\n ref,\n ) => {\n const { localRef, assign } = useForwardedRef(ref);\n const inactive = props.disabled || props.readOnly;\n const showClear = !!clearable && value !== \"\" && !inactive;\n const clear = () => {\n if (onClear) onClear();\n else onChange?.(\"\");\n localRef.current?.focus();\n };\n\n return (\n <div data-jsf-control data-clearable-field className={cn(\"relative\", className)}>\n {prefix && <div className=\"absolute inset-y-0 left-1.5 flex items-center\">{prefix}</div>}\n <input\n {...props}\n ref={assign}\n // Date math needs free text: a native date input cannot hold `now-7d`.\n type={withTime || dateMath ? \"text\" : \"date\"}\n value={value}\n {...(dateMath && isInvalidDateMath(value) ? { \"aria-invalid\": true } : {})}\n className={inputClasses({ prefix, suffix, showClear, inputClassName })}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <TrailingAdornments suffix={suffix} showClear={showClear} clearLabel={clearLabel} onClear={clear} />\n <DatePickerMenuButton\n ariaLabel={openButtonLabel}\n disabled={inactive}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n value={value}\n presets={dateMath ? dateMathPresets : undefined}\n withTime={withTime}\n onSelect={(next) => onChange?.(next)}\n />\n </div>\n );\n },\n);\n\nDateInputField.displayName = \"DateInputField\";\n"],"mappings":";;;;;;;AA8BA,SAAS,gBAAgB,KAAqC;CAC5D,MAAM,YAAA,GAAWA,MAAAA,OAAAA,CAAgC,IAAI;CACrD,MAAM,UAAU,SAAkC;EAChD,SAAS,UAAU;EACnB,IAAI,OAAO,QAAQ,YAAY,IAAI,IAAI;OAClC,IAAI,KAAK,IAAI,UAAU;CAC9B;CACA,OAAO;EAAE;EAAU;CAAO;AAC5B;AAEA,SAAS,aAAa,EACpB,QACA,QACA,WACA,kBAMC;CACD,OAAOC,cAAAA,GACL,wMACA,wGACA,UAAU,QACV,iBACC,aAAa,WAAW,SACzB,aAAa,UAAU,OACzB;AACF;AAEA,SAAS,mBAAmB,EAC1B,QACA,WACA,YACA,WAMC;CACD,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAAC,kBAAAA,UAAA,EAAA,UAAA,CACG,UACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAWD,cAAAA,GAAG,wCAAwC,YAAY,aAAa,SAAS;EAAI,UAAA;CAAY,CAAA,GAE9G,aACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EAAM,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACE,2BAAAA,kBAAD;GAAkB,GAAK,aAAa,EAAE,WAAW,IAAI,CAAC;GAAa;EAAU,CAAA;CACzE,CAAA,CAER,EAAA,CAAA;AAEN;AAEA,IAAa,kBAAA,GAAiBC,MAAAA,WAAAA,EAE1B,EACE,QAAQ,IACR,UACA,WACA,gBACA,iBACA,iBACA,QACA,QACA,WACA,SACA,YACA,WAAW,OACX,iBACA,UACA,GAAG,SAEL,QACG;CACH,MAAM,EAAE,UAAU,WAAW,gBAAgB,GAAG;CAChD,MAAM,WAAW,MAAM,YAAY,MAAM;CACzC,MAAM,YAAY,CAAC,CAAC,aAAa,UAAU,MAAM,CAAC;CAClD,MAAM,cAAc;EAClB,IAAI,SAAS,QAAQ;OAChB,WAAW,EAAE;EAClB,SAAS,SAAS,MAAM;CAC1B;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,oBAAA;EAAiB,wBAAA;EAAqB,WAAWH,cAAAA,GAAG,YAAY,SAAS;EAA9E,UAAA;GACG,UAAU,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAAiD,UAAA;GAAY,CAAA;GACvF,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;IACE,GAAI;IACJ,KAAK;IAEL,MAAM,YAAY,WAAW,SAAS;IAC/B;IACP,GAAK,YAAYI,kBAAAA,kBAAkB,KAAK,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxE,WAAW,aAAa;KAAE;KAAQ;KAAQ;KAAW;IAAe,CAAC;IACrE,WAAW,UAAU,WAAW,MAAM,OAAO,KAAK;GACnD,CAAA;GACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,oBAAD;IAA4B;IAAmB;IAAuB;IAAY,SAAS;GAAQ,CAAA;GACnG,iBAAA,GAAA,kBAAA,IAAA,CAACC,yBAAAA,sBAAD;IACE,WAAW;IACX,UAAU;IACV,WAAWL,cAAAA,GACT,6HACA,eACF;IACO;IACP,SAAS,WAAW,kBAAkB,KAAA;IAC5B;IACV,WAAW,SAAS,WAAW,IAAI;GACpC,CAAA;EACE;;AAET,CACF;AAEA,eAAe,cAAc"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { InputHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { DateMathProps } from './date-math.js';
|
|
3
|
+
import { ClearableFieldProps } from './field-clear-button.js';
|
|
4
|
+
export type DateFieldProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "onChange" | "prefix"> & ClearableFieldProps & DateMathProps & {
|
|
5
|
+
value?: string;
|
|
6
|
+
onChange?: (value: string) => void;
|
|
7
|
+
className?: string;
|
|
8
|
+
inputClassName?: string;
|
|
9
|
+
buttonClassName?: string;
|
|
10
|
+
openButtonLabel?: string;
|
|
11
|
+
/** Trailing in-field adornment, rendered left of the calendar button. */
|
|
12
|
+
suffix?: ReactNode;
|
|
13
|
+
/** Leading in-field adornment, rendered at the left edge of the input. */
|
|
14
|
+
prefix?: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
export type DateInputFieldProps = DateFieldProps & {
|
|
17
|
+
openButtonLabel: string;
|
|
18
|
+
dateMathPresets: readonly string[];
|
|
19
|
+
withTime: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare const DateInputField: import('react').ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "prefix" | "type" | "value" | "onChange"> & ClearableFieldProps & DateMathProps & {
|
|
22
|
+
value?: string;
|
|
23
|
+
onChange?: (value: string) => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
inputClassName?: string;
|
|
26
|
+
buttonClassName?: string;
|
|
27
|
+
openButtonLabel?: string;
|
|
28
|
+
/** Trailing in-field adornment, rendered left of the calendar button. */
|
|
29
|
+
suffix?: ReactNode;
|
|
30
|
+
/** Leading in-field adornment, rendered at the left edge of the input. */
|
|
31
|
+
prefix?: ReactNode;
|
|
32
|
+
} & {
|
|
33
|
+
openButtonLabel: string;
|
|
34
|
+
dateMathPresets: readonly string[];
|
|
35
|
+
withTime: boolean;
|
|
36
|
+
} & import('react').RefAttributes<HTMLInputElement>>;
|
|
37
|
+
//# sourceMappingURL=date-input-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-input-field.d.ts","sourceRoot":"","sources":["../../src/components/date-input-field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAExG,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAElF,MAAM,MAAM,cAAc,GAAG,IAAI,CAC/B,mBAAmB,CAAC,gBAAgB,CAAC,EAGrC,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CACzC,GAAG,mBAAmB,GAAG,aAAa,GAAG;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AA0DF,eAAO,MAAM,cAAc;YA1EjB,MAAM;eACH,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;gBACtB,MAAM;qBACD,MAAM;sBACL,MAAM;sBACN,MAAM;IACxB,yEAAyE;aAChE,SAAS;IAClB,0EAA0E;aACjE,SAAS;;qBAID,MAAM;qBACN,SAAS,MAAM,EAAE;cACxB,OAAO;oDAsHlB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { cn } from "../lib/utils.js";
|
|
2
|
+
import { isInvalidDateMath } from "./date-math.js";
|
|
3
|
+
import { DatePickerMenuButton } from "./date-picker-menu.js";
|
|
4
|
+
import { FieldClearButton } from "./field-clear-button.js";
|
|
5
|
+
import { forwardRef, useRef } from "react";
|
|
6
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/components/date-input-field.tsx
|
|
8
|
+
function useForwardedRef(ref) {
|
|
9
|
+
const localRef = useRef(null);
|
|
10
|
+
const assign = (node) => {
|
|
11
|
+
localRef.current = node;
|
|
12
|
+
if (typeof ref === "function") ref(node);
|
|
13
|
+
else if (ref) ref.current = node;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
localRef,
|
|
17
|
+
assign
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function inputClasses({ prefix, suffix, showClear, inputClassName }) {
|
|
21
|
+
return cn("h-control-h w-full rounded-md border border-input bg-background px-control-px pr-8 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", "[&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none", prefix && "pl-8", inputClassName, (showClear || suffix) && "pr-16", showClear && suffix && "pr-24");
|
|
22
|
+
}
|
|
23
|
+
function TrailingAdornments({ suffix, showClear, clearLabel, onClear }) {
|
|
24
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [suffix && /* @__PURE__ */ jsx("div", {
|
|
25
|
+
className: cn("absolute inset-y-0 flex items-center", showClear ? "right-14" : "right-7"),
|
|
26
|
+
children: suffix
|
|
27
|
+
}), showClear && /* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "absolute inset-y-0 right-7 flex items-center",
|
|
29
|
+
children: /* @__PURE__ */ jsx(FieldClearButton, {
|
|
30
|
+
...clearLabel ? { clearLabel } : {},
|
|
31
|
+
onClear
|
|
32
|
+
})
|
|
33
|
+
})] });
|
|
34
|
+
}
|
|
35
|
+
var DateInputField = forwardRef(({ value = "", onChange, className, inputClassName, buttonClassName, openButtonLabel, suffix, prefix, clearable, onClear, clearLabel, dateMath = false, dateMathPresets, withTime, ...props }, ref) => {
|
|
36
|
+
const { localRef, assign } = useForwardedRef(ref);
|
|
37
|
+
const inactive = props.disabled || props.readOnly;
|
|
38
|
+
const showClear = !!clearable && value !== "" && !inactive;
|
|
39
|
+
const clear = () => {
|
|
40
|
+
if (onClear) onClear();
|
|
41
|
+
else onChange?.("");
|
|
42
|
+
localRef.current?.focus();
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
45
|
+
"data-jsf-control": true,
|
|
46
|
+
"data-clearable-field": true,
|
|
47
|
+
className: cn("relative", className),
|
|
48
|
+
children: [
|
|
49
|
+
prefix && /* @__PURE__ */ jsx("div", {
|
|
50
|
+
className: "absolute inset-y-0 left-1.5 flex items-center",
|
|
51
|
+
children: prefix
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsx("input", {
|
|
54
|
+
...props,
|
|
55
|
+
ref: assign,
|
|
56
|
+
type: withTime || dateMath ? "text" : "date",
|
|
57
|
+
value,
|
|
58
|
+
...dateMath && isInvalidDateMath(value) ? { "aria-invalid": true } : {},
|
|
59
|
+
className: inputClasses({
|
|
60
|
+
prefix,
|
|
61
|
+
suffix,
|
|
62
|
+
showClear,
|
|
63
|
+
inputClassName
|
|
64
|
+
}),
|
|
65
|
+
onChange: (event) => onChange?.(event.target.value)
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ jsx(TrailingAdornments, {
|
|
68
|
+
suffix,
|
|
69
|
+
showClear,
|
|
70
|
+
clearLabel,
|
|
71
|
+
onClear: clear
|
|
72
|
+
}),
|
|
73
|
+
/* @__PURE__ */ jsx(DatePickerMenuButton, {
|
|
74
|
+
ariaLabel: openButtonLabel,
|
|
75
|
+
disabled: inactive,
|
|
76
|
+
className: cn("absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50", buttonClassName),
|
|
77
|
+
value,
|
|
78
|
+
presets: dateMath ? dateMathPresets : void 0,
|
|
79
|
+
withTime,
|
|
80
|
+
onSelect: (next) => onChange?.(next)
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
DateInputField.displayName = "DateInputField";
|
|
86
|
+
export { DateInputField };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=date-input-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-input-field.js","names":["_Fragment"],"sources":["../../src/components/date-input-field.tsx"],"sourcesContent":["import { forwardRef, useRef, type ForwardedRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { isInvalidDateMath, type DateMathProps } from \"./date-math\";\nimport { DatePickerMenuButton } from \"./date-picker-menu\";\nimport { FieldClearButton, type ClearableFieldProps } from \"./field-clear-button\";\n\nexport type DateFieldProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n // `prefix` is a global HTML attribute typed as string; omit it so our\n // ReactNode adornment prop below is not intersected down to `string & ReactNode`.\n \"type\" | \"value\" | \"onChange\" | \"prefix\"\n> & ClearableFieldProps & DateMathProps & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n /** Leading in-field adornment, rendered at the left edge of the input. */\n prefix?: ReactNode;\n};\n\nexport type DateInputFieldProps = DateFieldProps & {\n openButtonLabel: string;\n dateMathPresets: readonly string[];\n withTime: boolean;\n};\n\nfunction useForwardedRef(ref: ForwardedRef<HTMLInputElement>) {\n const localRef = useRef<HTMLInputElement | null>(null);\n const assign = (node: HTMLInputElement | null) => {\n localRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n };\n return { localRef, assign };\n}\n\nfunction inputClasses({\n prefix,\n suffix,\n showClear,\n inputClassName,\n}: {\n prefix: ReactNode;\n suffix: ReactNode;\n showClear: boolean;\n inputClassName: string | undefined;\n}) {\n return cn(\n \"h-control-h w-full rounded-md border border-input bg-background px-control-px pr-8 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n \"[&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none\",\n prefix && \"pl-8\",\n inputClassName,\n (showClear || suffix) && \"pr-16\",\n showClear && suffix && \"pr-24\",\n );\n}\n\nfunction TrailingAdornments({\n suffix,\n showClear,\n clearLabel,\n onClear,\n}: {\n suffix: ReactNode;\n showClear: boolean;\n clearLabel: string | undefined;\n onClear: () => void;\n}) {\n return (\n <>\n {suffix && (\n <div className={cn(\"absolute inset-y-0 flex items-center\", showClear ? \"right-14\" : \"right-7\")}>{suffix}</div>\n )}\n {showClear && (\n <span className=\"absolute inset-y-0 right-7 flex items-center\">\n <FieldClearButton {...(clearLabel ? { clearLabel } : {})} onClear={onClear} />\n </span>\n )}\n </>\n );\n}\n\nexport const DateInputField = forwardRef<HTMLInputElement, DateInputFieldProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel,\n suffix,\n prefix,\n clearable,\n onClear,\n clearLabel,\n dateMath = false,\n dateMathPresets,\n withTime,\n ...props\n },\n ref,\n ) => {\n const { localRef, assign } = useForwardedRef(ref);\n const inactive = props.disabled || props.readOnly;\n const showClear = !!clearable && value !== \"\" && !inactive;\n const clear = () => {\n if (onClear) onClear();\n else onChange?.(\"\");\n localRef.current?.focus();\n };\n\n return (\n <div data-jsf-control data-clearable-field className={cn(\"relative\", className)}>\n {prefix && <div className=\"absolute inset-y-0 left-1.5 flex items-center\">{prefix}</div>}\n <input\n {...props}\n ref={assign}\n // Date math needs free text: a native date input cannot hold `now-7d`.\n type={withTime || dateMath ? \"text\" : \"date\"}\n value={value}\n {...(dateMath && isInvalidDateMath(value) ? { \"aria-invalid\": true } : {})}\n className={inputClasses({ prefix, suffix, showClear, inputClassName })}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <TrailingAdornments suffix={suffix} showClear={showClear} clearLabel={clearLabel} onClear={clear} />\n <DatePickerMenuButton\n ariaLabel={openButtonLabel}\n disabled={inactive}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n value={value}\n presets={dateMath ? dateMathPresets : undefined}\n withTime={withTime}\n onSelect={(next) => onChange?.(next)}\n />\n </div>\n );\n },\n);\n\nDateInputField.displayName = \"DateInputField\";\n"],"mappings":";;;;;;;AA8BA,SAAS,gBAAgB,KAAqC;CAC5D,MAAM,WAAW,OAAgC,IAAI;CACrD,MAAM,UAAU,SAAkC;EAChD,SAAS,UAAU;EACnB,IAAI,OAAO,QAAQ,YAAY,IAAI,IAAI;OAClC,IAAI,KAAK,IAAI,UAAU;CAC9B;CACA,OAAO;EAAE;EAAU;CAAO;AAC5B;AAEA,SAAS,aAAa,EACpB,QACA,QACA,WACA,kBAMC;CACD,OAAO,GACL,wMACA,wGACA,UAAU,QACV,iBACC,aAAa,WAAW,SACzB,aAAa,UAAU,OACzB;AACF;AAEA,SAAS,mBAAmB,EAC1B,QACA,WACA,YACA,WAMC;CACD,OACE,qBAAAA,YAAA,EAAA,UAAA,CACG,UACC,oBAAC,OAAD;EAAK,WAAW,GAAG,wCAAwC,YAAY,aAAa,SAAS;EAAI,UAAA;CAAY,CAAA,GAE9G,aACC,oBAAC,QAAD;EAAM,WAAU;EACd,UAAA,oBAAC,kBAAD;GAAkB,GAAK,aAAa,EAAE,WAAW,IAAI,CAAC;GAAa;EAAU,CAAA;CACzE,CAAA,CAER,EAAA,CAAA;AAEN;AAEA,IAAa,iBAAiB,YAE1B,EACE,QAAQ,IACR,UACA,WACA,gBACA,iBACA,iBACA,QACA,QACA,WACA,SACA,YACA,WAAW,OACX,iBACA,UACA,GAAG,SAEL,QACG;CACH,MAAM,EAAE,UAAU,WAAW,gBAAgB,GAAG;CAChD,MAAM,WAAW,MAAM,YAAY,MAAM;CACzC,MAAM,YAAY,CAAC,CAAC,aAAa,UAAU,MAAM,CAAC;CAClD,MAAM,cAAc;EAClB,IAAI,SAAS,QAAQ;OAChB,WAAW,EAAE;EAClB,SAAS,SAAS,MAAM;CAC1B;CAEA,OACE,qBAAC,OAAD;EAAK,oBAAA;EAAiB,wBAAA;EAAqB,WAAW,GAAG,YAAY,SAAS;EAA9E,UAAA;GACG,UAAU,oBAAC,OAAD;IAAK,WAAU;IAAiD,UAAA;GAAY,CAAA;GACvF,oBAAC,SAAD;IACE,GAAI;IACJ,KAAK;IAEL,MAAM,YAAY,WAAW,SAAS;IAC/B;IACP,GAAK,YAAY,kBAAkB,KAAK,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACxE,WAAW,aAAa;KAAE;KAAQ;KAAQ;KAAW;IAAe,CAAC;IACrE,WAAW,UAAU,WAAW,MAAM,OAAO,KAAK;GACnD,CAAA;GACD,oBAAC,oBAAD;IAA4B;IAAmB;IAAuB;IAAY,SAAS;GAAQ,CAAA;GACnG,oBAAC,sBAAD;IACE,WAAW;IACX,UAAU;IACV,WAAW,GACT,6HACA,eACF;IACO;IACP,SAAS,WAAW,kBAAkB,KAAA;IAC5B;IACV,WAAW,SAAS,WAAW,IAAI;GACpC,CAAA;EACE;;AAET,CACF;AAEA,eAAe,cAAc"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_timestamp_format = require("../data/cells/timestamp-format.cjs");
|
|
2
|
+
// src/components/date-math.ts
|
|
3
|
+
var DATE_PICKER_DATE_MATH_PRESETS = [
|
|
4
|
+
"now",
|
|
5
|
+
"now-1d",
|
|
6
|
+
"now-7d",
|
|
7
|
+
"now-30d",
|
|
8
|
+
"now/w",
|
|
9
|
+
"now/M"
|
|
10
|
+
];
|
|
11
|
+
var DATE_TIME_PICKER_DATE_MATH_PRESETS = [
|
|
12
|
+
"now",
|
|
13
|
+
"now-15m",
|
|
14
|
+
"now-1h",
|
|
15
|
+
"now-24h",
|
|
16
|
+
"now-7d",
|
|
17
|
+
"now-30d"
|
|
18
|
+
];
|
|
19
|
+
/** Splits an absolute `YYYY-MM-DD[THH:mm]` value; date math and anything else yields empty parts. */
|
|
20
|
+
function splitDateTimeValue(value) {
|
|
21
|
+
const match = /^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}))?/.exec(value.trim());
|
|
22
|
+
return {
|
|
23
|
+
date: match?.[1] ?? "",
|
|
24
|
+
time: match?.[2] ?? ""
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function joinDateTimeValue({ date, time }) {
|
|
28
|
+
if (!date) return "";
|
|
29
|
+
return time ? `${date}T${time}` : date;
|
|
30
|
+
}
|
|
31
|
+
var pad2 = (n) => String(n).padStart(2, "0");
|
|
32
|
+
/** `YYYY-MM-DD` in the local time zone. */
|
|
33
|
+
function formatLocalDate(date) {
|
|
34
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
|
|
35
|
+
}
|
|
36
|
+
/** The 42 days (six Sunday-first weeks) shown for a `YYYY-MM` month, flagging those outside it. */
|
|
37
|
+
function monthGrid(month) {
|
|
38
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
39
|
+
const offset = new Date(year, monthNumber - 1, 1).getDay();
|
|
40
|
+
return Array.from({ length: 42 }, (_, index) => {
|
|
41
|
+
const day = new Date(year, monthNumber - 1, 1 - offset + index);
|
|
42
|
+
return {
|
|
43
|
+
date: formatLocalDate(day),
|
|
44
|
+
inMonth: day.getMonth() === monthNumber - 1
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** `YYYY-MM` shifted by `delta` months. */
|
|
49
|
+
function shiftMonth(month, delta) {
|
|
50
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
51
|
+
const shifted = new Date(year, monthNumber - 1 + delta, 1);
|
|
52
|
+
return `${shifted.getFullYear()}-${pad2(shifted.getMonth() + 1)}`;
|
|
53
|
+
}
|
|
54
|
+
/** True when a non-empty value is neither a date nor a date-math expression. */
|
|
55
|
+
function isInvalidDateMath(value) {
|
|
56
|
+
return value.trim() !== "" && require_timestamp_format.resolveDateMath(value) === null;
|
|
57
|
+
}
|
|
58
|
+
exports.DATE_PICKER_DATE_MATH_PRESETS = DATE_PICKER_DATE_MATH_PRESETS;
|
|
59
|
+
exports.DATE_TIME_PICKER_DATE_MATH_PRESETS = DATE_TIME_PICKER_DATE_MATH_PRESETS;
|
|
60
|
+
exports.formatLocalDate = formatLocalDate;
|
|
61
|
+
exports.isInvalidDateMath = isInvalidDateMath;
|
|
62
|
+
exports.joinDateTimeValue = joinDateTimeValue;
|
|
63
|
+
exports.monthGrid = monthGrid;
|
|
64
|
+
exports.shiftMonth = shiftMonth;
|
|
65
|
+
exports.splitDateTimeValue = splitDateTimeValue;
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=date-math.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-math.cjs","names":["resolveDateMath"],"sources":["../../src/components/date-math.ts"],"sourcesContent":["import { resolveDateMath } from \"../data/cells/timestamp-format\";\n\nexport type DateMathProps = {\n /**\n * Opt in to date math: the field then also accepts relative expressions such as `now-7d` or\n * `now/M`, and the calendar button opens a menu of presets instead of the native picker alone.\n * Default false.\n */\n dateMath?: boolean;\n /** Expressions offered as presets in the date-math menu; defaults to a set suited to the field. */\n dateMathPresets?: readonly string[];\n};\n\nexport const DATE_PICKER_DATE_MATH_PRESETS = [\"now\", \"now-1d\", \"now-7d\", \"now-30d\", \"now/w\", \"now/M\"] as const;\n\nexport const DATE_TIME_PICKER_DATE_MATH_PRESETS = [\"now\", \"now-15m\", \"now-1h\", \"now-24h\", \"now-7d\", \"now-30d\"] as const;\n\n/** Splits an absolute `YYYY-MM-DD[THH:mm]` value; date math and anything else yields empty parts. */\nexport function splitDateTimeValue(value: string) {\n const match = /^(\\d{4}-\\d{2}-\\d{2})(?:[T ](\\d{2}:\\d{2}))?/.exec(value.trim());\n return { date: match?.[1] ?? \"\", time: match?.[2] ?? \"\" };\n}\n\nexport function joinDateTimeValue({ date, time }: { date: string; time: string }) {\n if (!date) return \"\";\n return time ? `${date}T${time}` : date;\n}\n\nconst pad2 = (n: number) => String(n).padStart(2, \"0\");\n\n/** `YYYY-MM-DD` in the local time zone. */\nexport function formatLocalDate(date: Date) {\n return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;\n}\n\n/** The 42 days (six Sunday-first weeks) shown for a `YYYY-MM` month, flagging those outside it. */\nexport function monthGrid(month: string) {\n const [year = 0, monthNumber = 1] = month.split(\"-\").map(Number);\n const offset = new Date(year, monthNumber - 1, 1).getDay();\n return Array.from({ length: 42 }, (_, index) => {\n const day = new Date(year, monthNumber - 1, 1 - offset + index);\n return { date: formatLocalDate(day), inMonth: day.getMonth() === monthNumber - 1 };\n });\n}\n\n/** `YYYY-MM` shifted by `delta` months. */\nexport function shiftMonth(month: string, delta: number) {\n const [year = 0, monthNumber = 1] = month.split(\"-\").map(Number);\n const shifted = new Date(year, monthNumber - 1 + delta, 1);\n return `${shifted.getFullYear()}-${pad2(shifted.getMonth() + 1)}`;\n}\n\n/** True when a non-empty value is neither a date nor a date-math expression. */\nexport function isInvalidDateMath(value: string) {\n return value.trim() !== \"\" && resolveDateMath(value) === null;\n}\n"],"mappings":";;AAaA,IAAa,gCAAgC;CAAC;CAAO;CAAU;CAAU;CAAW;CAAS;AAAO;AAEpG,IAAa,qCAAqC;CAAC;CAAO;CAAW;CAAU;CAAW;CAAU;AAAS;;AAG7G,SAAgB,mBAAmB,OAAe;CAChD,MAAM,QAAQ,6CAA6C,KAAK,MAAM,KAAK,CAAC;CAC5E,OAAO;EAAE,MAAM,QAAQ,MAAM;EAAI,MAAM,QAAQ,MAAM;CAAG;AAC1D;AAEA,SAAgB,kBAAkB,EAAE,MAAM,QAAwC;CAChF,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,OAAO,GAAG,KAAK,GAAG,SAAS;AACpC;AAEA,IAAM,QAAQ,MAAc,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;;AAGrD,SAAgB,gBAAgB,MAAY;CAC1C,OAAO,GAAG,KAAK,YAAY,EAAE,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC,EAAE,GAAG,KAAK,KAAK,QAAQ,CAAC;AAClF;;AAGA,SAAgB,UAAU,OAAe;CACvC,MAAM,CAAC,OAAO,GAAG,cAAc,KAAK,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC/D,MAAM,SAAS,IAAI,KAAK,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,OAAO;CACzD,OAAO,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU;EAC9C,MAAM,MAAM,IAAI,KAAK,MAAM,cAAc,GAAG,IAAI,SAAS,KAAK;EAC9D,OAAO;GAAE,MAAM,gBAAgB,GAAG;GAAG,SAAS,IAAI,SAAS,MAAM,cAAc;EAAE;CACnF,CAAC;AACH;;AAGA,SAAgB,WAAW,OAAe,OAAe;CACvD,MAAM,CAAC,OAAO,GAAG,cAAc,KAAK,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CAC/D,MAAM,UAAU,IAAI,KAAK,MAAM,cAAc,IAAI,OAAO,CAAC;CACzD,OAAO,GAAG,QAAQ,YAAY,EAAE,GAAG,KAAK,QAAQ,SAAS,IAAI,CAAC;AAChE;;AAGA,SAAgB,kBAAkB,OAAe;CAC/C,OAAO,MAAM,KAAK,MAAM,MAAMA,yBAAAA,gBAAgB,KAAK,MAAM;AAC3D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type DateMathProps = {
|
|
2
|
+
/**
|
|
3
|
+
* Opt in to date math: the field then also accepts relative expressions such as `now-7d` or
|
|
4
|
+
* `now/M`, and the calendar button opens a menu of presets instead of the native picker alone.
|
|
5
|
+
* Default false.
|
|
6
|
+
*/
|
|
7
|
+
dateMath?: boolean;
|
|
8
|
+
/** Expressions offered as presets in the date-math menu; defaults to a set suited to the field. */
|
|
9
|
+
dateMathPresets?: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const DATE_PICKER_DATE_MATH_PRESETS: readonly ["now", "now-1d", "now-7d", "now-30d", "now/w", "now/M"];
|
|
12
|
+
export declare const DATE_TIME_PICKER_DATE_MATH_PRESETS: readonly ["now", "now-15m", "now-1h", "now-24h", "now-7d", "now-30d"];
|
|
13
|
+
/** Splits an absolute `YYYY-MM-DD[THH:mm]` value; date math and anything else yields empty parts. */
|
|
14
|
+
export declare function splitDateTimeValue(value: string): {
|
|
15
|
+
date: string;
|
|
16
|
+
time: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function joinDateTimeValue({ date, time }: {
|
|
19
|
+
date: string;
|
|
20
|
+
time: string;
|
|
21
|
+
}): string;
|
|
22
|
+
/** `YYYY-MM-DD` in the local time zone. */
|
|
23
|
+
export declare function formatLocalDate(date: Date): string;
|
|
24
|
+
/** The 42 days (six Sunday-first weeks) shown for a `YYYY-MM` month, flagging those outside it. */
|
|
25
|
+
export declare function monthGrid(month: string): {
|
|
26
|
+
date: string;
|
|
27
|
+
inMonth: boolean;
|
|
28
|
+
}[];
|
|
29
|
+
/** `YYYY-MM` shifted by `delta` months. */
|
|
30
|
+
export declare function shiftMonth(month: string, delta: number): string;
|
|
31
|
+
/** True when a non-empty value is neither a date nor a date-math expression. */
|
|
32
|
+
export declare function isInvalidDateMath(value: string): boolean;
|
|
33
|
+
//# sourceMappingURL=date-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-math.d.ts","sourceRoot":"","sources":["../../src/components/date-math.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mGAAmG;IACnG,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF,eAAO,MAAM,6BAA6B,mEAAoE,CAAC;AAE/G,eAAO,MAAM,kCAAkC,uEAAwE,CAAC;AAExH,qGAAqG;AACrG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM;;;EAG/C;AAED,wBAAgB,iBAAiB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,UAG/E;AAID,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,UAEzC;AAED,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM;;;IAOtC;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAItD;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,WAE9C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { resolveDateMath } from "../data/cells/timestamp-format.js";
|
|
2
|
+
// src/components/date-math.ts
|
|
3
|
+
var DATE_PICKER_DATE_MATH_PRESETS = [
|
|
4
|
+
"now",
|
|
5
|
+
"now-1d",
|
|
6
|
+
"now-7d",
|
|
7
|
+
"now-30d",
|
|
8
|
+
"now/w",
|
|
9
|
+
"now/M"
|
|
10
|
+
];
|
|
11
|
+
var DATE_TIME_PICKER_DATE_MATH_PRESETS = [
|
|
12
|
+
"now",
|
|
13
|
+
"now-15m",
|
|
14
|
+
"now-1h",
|
|
15
|
+
"now-24h",
|
|
16
|
+
"now-7d",
|
|
17
|
+
"now-30d"
|
|
18
|
+
];
|
|
19
|
+
/** Splits an absolute `YYYY-MM-DD[THH:mm]` value; date math and anything else yields empty parts. */
|
|
20
|
+
function splitDateTimeValue(value) {
|
|
21
|
+
const match = /^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}))?/.exec(value.trim());
|
|
22
|
+
return {
|
|
23
|
+
date: match?.[1] ?? "",
|
|
24
|
+
time: match?.[2] ?? ""
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function joinDateTimeValue({ date, time }) {
|
|
28
|
+
if (!date) return "";
|
|
29
|
+
return time ? `${date}T${time}` : date;
|
|
30
|
+
}
|
|
31
|
+
var pad2 = (n) => String(n).padStart(2, "0");
|
|
32
|
+
/** `YYYY-MM-DD` in the local time zone. */
|
|
33
|
+
function formatLocalDate(date) {
|
|
34
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}`;
|
|
35
|
+
}
|
|
36
|
+
/** The 42 days (six Sunday-first weeks) shown for a `YYYY-MM` month, flagging those outside it. */
|
|
37
|
+
function monthGrid(month) {
|
|
38
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
39
|
+
const offset = new Date(year, monthNumber - 1, 1).getDay();
|
|
40
|
+
return Array.from({ length: 42 }, (_, index) => {
|
|
41
|
+
const day = new Date(year, monthNumber - 1, 1 - offset + index);
|
|
42
|
+
return {
|
|
43
|
+
date: formatLocalDate(day),
|
|
44
|
+
inMonth: day.getMonth() === monthNumber - 1
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** `YYYY-MM` shifted by `delta` months. */
|
|
49
|
+
function shiftMonth(month, delta) {
|
|
50
|
+
const [year = 0, monthNumber = 1] = month.split("-").map(Number);
|
|
51
|
+
const shifted = new Date(year, monthNumber - 1 + delta, 1);
|
|
52
|
+
return `${shifted.getFullYear()}-${pad2(shifted.getMonth() + 1)}`;
|
|
53
|
+
}
|
|
54
|
+
/** True when a non-empty value is neither a date nor a date-math expression. */
|
|
55
|
+
function isInvalidDateMath(value) {
|
|
56
|
+
return value.trim() !== "" && resolveDateMath(value) === null;
|
|
57
|
+
}
|
|
58
|
+
export { DATE_PICKER_DATE_MATH_PRESETS, DATE_TIME_PICKER_DATE_MATH_PRESETS, formatLocalDate, isInvalidDateMath, joinDateTimeValue, monthGrid, shiftMonth, splitDateTimeValue };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=date-math.js.map
|