@stoa-dev/kit 0.1.4 → 1.0.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/CHANGELOG.md +64 -0
- package/README.md +23 -2
- package/dist/display/BarChart/index.js +70 -0
- package/dist/display/BarChart/index.js.map +1 -0
- package/dist/display/Marginalia/index.js +16 -0
- package/dist/display/Marginalia/index.js.map +1 -0
- package/dist/display/MarginaliaFramed/index.js +19 -0
- package/dist/display/MarginaliaFramed/index.js.map +1 -0
- package/dist/display/MarginaliaPair/index.js +32 -0
- package/dist/display/MarginaliaPair/index.js.map +1 -0
- package/dist/display/ProgressBar/index.js +72 -0
- package/dist/display/ProgressBar/index.js.map +1 -0
- package/dist/display/TimeMeasured/index.js +38 -0
- package/dist/display/TimeMeasured/index.js.map +1 -0
- package/dist/display/index.js +16 -0
- package/dist/display/index.js.map +1 -0
- package/dist/i18n/locales/at.json.js +8 -4
- package/dist/i18n/locales/at.json.js.map +1 -1
- package/dist/i18n/locales/de.json.js +8 -4
- package/dist/i18n/locales/de.json.js.map +1 -1
- package/dist/i18n/locales/en.json.js +8 -4
- package/dist/i18n/locales/en.json.js.map +1 -1
- package/dist/i18n/locales/it.json.js +10 -6
- package/dist/i18n/locales/it.json.js.map +1 -1
- package/dist/shell/AnimatedSwap/index.js +61 -0
- package/dist/shell/AnimatedSwap/index.js.map +1 -0
- package/dist/shell/AppNavigation/index.js +62 -43
- package/dist/shell/AppNavigation/index.js.map +1 -1
- package/dist/shell/BrandLines/index.js +14 -12
- package/dist/shell/BrandLines/index.js.map +1 -1
- package/dist/shell/DatePicker/index.js +16 -15
- package/dist/shell/DatePicker/index.js.map +1 -1
- package/dist/shell/ExternalLink/index.js +30 -0
- package/dist/shell/ExternalLink/index.js.map +1 -0
- package/dist/shell/PageHeading/index.js +15 -8
- package/dist/shell/PageHeading/index.js.map +1 -1
- package/dist/shell/SaveStatus/index.js +61 -0
- package/dist/shell/SaveStatus/index.js.map +1 -0
- package/dist/shell/SectionNavigation/index.js +29 -27
- package/dist/shell/SectionNavigation/index.js.map +1 -1
- package/dist/shell/StartupAnimation/index.js +88 -0
- package/dist/shell/StartupAnimation/index.js.map +1 -0
- package/dist/shell/StartupProvider/index.js +37 -0
- package/dist/shell/StartupProvider/index.js.map +1 -0
- package/dist/shell/TagInput/index.js +93 -0
- package/dist/shell/TagInput/index.js.map +1 -0
- package/dist/shell/ValidatedInput/index.js +31 -0
- package/dist/shell/ValidatedInput/index.js.map +1 -0
- package/dist/shell/index.js +41 -24
- package/dist/shell/index.js.map +1 -1
- package/dist/types/display/BarChart/index.d.ts +25 -0
- package/dist/types/display/BarChart/index.d.ts.map +1 -0
- package/dist/types/display/Marginalia/index.d.ts +8 -0
- package/dist/types/display/Marginalia/index.d.ts.map +1 -0
- package/dist/types/display/MarginaliaFramed/index.d.ts +8 -0
- package/dist/types/display/MarginaliaFramed/index.d.ts.map +1 -0
- package/dist/types/display/MarginaliaPair/index.d.ts +9 -0
- package/dist/types/display/MarginaliaPair/index.d.ts.map +1 -0
- package/dist/types/display/ProgressBar/index.d.ts +19 -0
- package/dist/types/display/ProgressBar/index.d.ts.map +1 -0
- package/dist/types/display/TimeMeasured/index.d.ts +16 -0
- package/dist/types/display/TimeMeasured/index.d.ts.map +1 -0
- package/dist/types/display/index.d.ts +7 -0
- package/dist/types/display/index.d.ts.map +1 -0
- package/dist/types/i18n/index.d.ts +44 -0
- package/dist/types/i18n/index.d.ts.map +1 -1
- package/dist/types/shell/AnimatedSwap/index.d.ts +13 -0
- package/dist/types/shell/AnimatedSwap/index.d.ts.map +1 -0
- package/dist/types/shell/AppNavigation/index.d.ts.map +1 -1
- package/dist/types/shell/BrandLines/index.d.ts.map +1 -1
- package/dist/types/shell/DatePicker/index.d.ts.map +1 -1
- package/dist/types/shell/ErrorBoundary/index.d.ts +1 -1
- package/dist/types/shell/ExternalLink/index.d.ts +10 -0
- package/dist/types/shell/ExternalLink/index.d.ts.map +1 -0
- package/dist/types/shell/PageHeading/index.d.ts.map +1 -1
- package/dist/types/shell/SaveStatus/index.d.ts +15 -0
- package/dist/types/shell/SaveStatus/index.d.ts.map +1 -0
- package/dist/types/shell/SectionNavigation/index.d.ts.map +1 -1
- package/dist/types/shell/StartupAnimation/index.d.ts +26 -0
- package/dist/types/shell/StartupAnimation/index.d.ts.map +1 -0
- package/dist/types/shell/StartupProvider/index.d.ts +22 -0
- package/dist/types/shell/StartupProvider/index.d.ts.map +1 -0
- package/dist/types/shell/TagInput/index.d.ts +20 -0
- package/dist/types/shell/TagInput/index.d.ts.map +1 -0
- package/dist/types/shell/ValidatedInput/index.d.ts +17 -0
- package/dist/types/shell/ValidatedInput/index.d.ts.map +1 -0
- package/dist/types/shell/index.d.ts +7 -0
- package/dist/types/shell/index.d.ts.map +1 -1
- package/dist/types/ui/field/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/saveFeedback.d.ts +35 -0
- package/dist/types/utils/saveFeedback.d.ts.map +1 -0
- package/dist/utils/index.js +5 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/saveFeedback.js +54 -0
- package/dist/utils/saveFeedback.js.map +1 -0
- package/package.json +8 -2
- package/styles/instrument.css +705 -0
- package/styles/theme.css +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { isTauri as a, invoke as u } from "@tauri-apps/api/core";
|
|
3
|
+
import { cn as f } from "../../utils/cn.js";
|
|
4
|
+
function s({
|
|
5
|
+
href: e,
|
|
6
|
+
className: n,
|
|
7
|
+
onClick: o,
|
|
8
|
+
children: t,
|
|
9
|
+
...i
|
|
10
|
+
}) {
|
|
11
|
+
return /* @__PURE__ */ l(
|
|
12
|
+
"a",
|
|
13
|
+
{
|
|
14
|
+
...i,
|
|
15
|
+
href: e,
|
|
16
|
+
target: "_blank",
|
|
17
|
+
rel: "noreferrer",
|
|
18
|
+
"data-slot": "external-link",
|
|
19
|
+
className: f("underline underline-offset-2", n),
|
|
20
|
+
onClick: (r) => {
|
|
21
|
+
o?.(r), !(r.defaultPrevented || !a()) && (r.preventDefault(), u("plugin:opener|open_url", { url: e }));
|
|
22
|
+
},
|
|
23
|
+
children: t
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
s as ExternalLink
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/ExternalLink/index.tsx"],"sourcesContent":["import { invoke, isTauri } from '@tauri-apps/api/core'\nimport type { ComponentProps } from 'react'\nimport { cn } from '../../utils/cn'\n\nexport type ExternalLinkProps = ComponentProps<'a'> & { href: string }\n\n/**\n * Opens http(s) links in the system browser inside Tauri (needs the opener\n * plugin on the Rust side) and in a new tab in the browser preview.\n */\nexport function ExternalLink({\n\thref,\n\tclassName,\n\tonClick,\n\tchildren,\n\t...props\n}: ExternalLinkProps) {\n\treturn (\n\t\t<a\n\t\t\t{...props}\n\t\t\thref={href}\n\t\t\ttarget='_blank'\n\t\t\trel='noreferrer'\n\t\t\tdata-slot='external-link'\n\t\t\tclassName={cn('underline underline-offset-2', className)}\n\t\t\tonClick={(event) => {\n\t\t\t\tonClick?.(event)\n\t\t\t\tif (event.defaultPrevented || !isTauri()) return\n\t\t\t\tevent.preventDefault()\n\t\t\t\tvoid invoke('plugin:opener|open_url', { url: href })\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</a>\n\t)\n}\n"],"names":["ExternalLink","href","className","onClick","children","props","jsx","cn","event","isTauri","invoke"],"mappings":";;;AAUO,SAASA,EAAa;AAAA,EAC5B,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACJ,GAAsB;AACrB,SACC,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,GAAGD;AAAA,MACJ,MAAAJ;AAAA,MACA,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,aAAU;AAAA,MACV,WAAWM,EAAG,gCAAgCL,CAAS;AAAA,MACvD,SAAS,CAACM,MAAU;AAEnB,QADAL,IAAUK,CAAK,GACX,EAAAA,EAAM,oBAAoB,CAACC,SAC/BD,EAAM,eAAA,GACDE,EAAO,0BAA0B,EAAE,KAAKT,GAAM;AAAA,MACpD;AAAA,MAEC,UAAAG;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { cn as
|
|
1
|
+
import { jsxs as i, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { cn as o } from "../../utils/cn.js";
|
|
3
3
|
import { BrandLines as s } from "../BrandLines/index.js";
|
|
4
4
|
import t from "./PageHeading.module.scss.js";
|
|
5
|
-
function
|
|
6
|
-
return /* @__PURE__ */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
function f({ children: r, className: e, plain: a }) {
|
|
6
|
+
return /* @__PURE__ */ i(
|
|
7
|
+
"h2",
|
|
8
|
+
{
|
|
9
|
+
"data-slot": "page-heading",
|
|
10
|
+
className: o(t.pageHeading, "shrink-0", e),
|
|
11
|
+
children: [
|
|
12
|
+
!a && /* @__PURE__ */ n(s, {}),
|
|
13
|
+
r
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
);
|
|
10
17
|
}
|
|
11
18
|
export {
|
|
12
|
-
|
|
19
|
+
f as PageHeading
|
|
13
20
|
};
|
|
14
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/shell/PageHeading/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { cn } from '../../utils/cn'\nimport { BrandLines } from '../BrandLines'\nimport styles from './PageHeading.module.scss'\n\nexport interface PageHeadingProps {\n\tchildren: ReactNode\n\tclassName?: string\n\t/** Hide the brand accent in front of the heading. */\n\tplain?: boolean\n}\n\nexport function PageHeading({ children, className, plain }: PageHeadingProps) {\n\treturn (\n\t\t<h2
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/PageHeading/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { cn } from '../../utils/cn'\nimport { BrandLines } from '../BrandLines'\nimport styles from './PageHeading.module.scss'\n\nexport interface PageHeadingProps {\n\tchildren: ReactNode\n\tclassName?: string\n\t/** Hide the brand accent in front of the heading. */\n\tplain?: boolean\n}\n\nexport function PageHeading({ children, className, plain }: PageHeadingProps) {\n\treturn (\n\t\t<h2\n\t\t\tdata-slot='page-heading'\n\t\t\tclassName={cn(styles.pageHeading, 'shrink-0', className)}\n\t\t>\n\t\t\t{!plain && <BrandLines />}\n\t\t\t{children}\n\t\t</h2>\n\t)\n}\n"],"names":["PageHeading","children","className","plain","jsxs","cn","styles","BrandLines"],"mappings":";;;;AAYO,SAASA,EAAY,EAAE,UAAAC,GAAU,WAAAC,GAAW,OAAAC,KAA2B;AAC7E,SACC,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,aAAU;AAAA,MACV,WAAWC,EAAGC,EAAO,aAAa,YAAYJ,CAAS;AAAA,MAEtD,UAAA;AAAA,QAAA,CAACC,uBAAUI,GAAA,EAAW;AAAA,QACtBN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsxs as s, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation as u } from "react-i18next";
|
|
3
|
+
import { STOA_NS as m } from "../../i18n/namespace.js";
|
|
4
|
+
import { Button as f } from "../../ui/button/index.js";
|
|
5
|
+
import { cn as o } from "../../utils/cn.js";
|
|
6
|
+
function N({
|
|
7
|
+
status: r,
|
|
8
|
+
message: e,
|
|
9
|
+
onRetry: n,
|
|
10
|
+
floating: a = !0,
|
|
11
|
+
className: i
|
|
12
|
+
}) {
|
|
13
|
+
const { t: l } = u(m);
|
|
14
|
+
if (!r && !e) return null;
|
|
15
|
+
const c = !!e || r === "error", d = /* @__PURE__ */ s(
|
|
16
|
+
"div",
|
|
17
|
+
{
|
|
18
|
+
"data-slot": "save-status",
|
|
19
|
+
"data-status": r ?? void 0,
|
|
20
|
+
className: o(
|
|
21
|
+
"flex items-center gap-2 text-xs text-muted-foreground",
|
|
22
|
+
!a && i
|
|
23
|
+
),
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ t(
|
|
26
|
+
"span",
|
|
27
|
+
{
|
|
28
|
+
role: c ? "alert" : "status",
|
|
29
|
+
"aria-live": "polite",
|
|
30
|
+
className: o(r === "error" && !e && "text-destructive"),
|
|
31
|
+
children: e ?? (r ? l(`autosave.${r}`) : null)
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
r === "error" && n && /* @__PURE__ */ t(f, { size: "sm", variant: "ghost", onClick: n, children: l("actions.retry") })
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
return a ? /* @__PURE__ */ s(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
className: o(
|
|
42
|
+
"fixed bottom-5 left-1/2 z-50 isolate max-w-[calc(100vw-2rem)] -translate-x-1/2 rounded-full px-4 py-2",
|
|
43
|
+
i
|
|
44
|
+
),
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ t(
|
|
47
|
+
"div",
|
|
48
|
+
{
|
|
49
|
+
"aria-hidden": "true",
|
|
50
|
+
className: "pointer-events-none absolute inset-0 -z-10 rounded-full bg-background/25 shadow-sm backdrop-blur-xs"
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
d
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
) : d;
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
N as SaveStatus
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/SaveStatus/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { STOA_NS } from '../../i18n/namespace'\nimport { Button } from '../../ui/button'\nimport { cn } from '../../utils/cn'\nimport type { VisibleSaveStatus } from '../../utils/saveFeedback'\n\nexport interface SaveStatusProps {\n\tstatus: VisibleSaveStatus\n\t/** Replaces the status text, e.g. a validation hint. Shown as an alert. */\n\tmessage?: ReactNode\n\t/** Shows a retry button next to an error. */\n\tonRetry?: () => void\n\t/** Floating pill at the bottom centre (default) or inline text. */\n\tfloating?: boolean\n\tclassName?: string\n}\n\n/** Autosave feedback: \"Saving …\", \"Changes saved\" or an error with retry. */\nexport function SaveStatus({\n\tstatus,\n\tmessage,\n\tonRetry,\n\tfloating = true,\n\tclassName,\n}: SaveStatusProps) {\n\tconst { t } = useTranslation(STOA_NS)\n\tif (!status && !message) return null\n\tconst alert = Boolean(message) || status === 'error'\n\n\tconst content = (\n\t\t<div\n\t\t\tdata-slot='save-status'\n\t\t\tdata-status={status ?? undefined}\n\t\t\tclassName={cn(\n\t\t\t\t'flex items-center gap-2 text-xs text-muted-foreground',\n\t\t\t\t!floating && className,\n\t\t\t)}\n\t\t>\n\t\t\t<span\n\t\t\t\trole={alert ? 'alert' : 'status'}\n\t\t\t\taria-live='polite'\n\t\t\t\tclassName={cn(status === 'error' && !message && 'text-destructive')}\n\t\t\t>\n\t\t\t\t{message ?? (status ? t(`autosave.${status}`) : null)}\n\t\t\t</span>\n\t\t\t{status === 'error' && onRetry && (\n\t\t\t\t<Button size='sm' variant='ghost' onClick={onRetry}>\n\t\t\t\t\t{t('actions.retry')}\n\t\t\t\t</Button>\n\t\t\t)}\n\t\t</div>\n\t)\n\n\tif (!floating) return content\n\treturn (\n\t\t<div\n\t\t\tclassName={cn(\n\t\t\t\t'fixed bottom-5 left-1/2 z-50 isolate max-w-[calc(100vw-2rem)] -translate-x-1/2 rounded-full px-4 py-2',\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t<div\n\t\t\t\taria-hidden='true'\n\t\t\t\tclassName='pointer-events-none absolute inset-0 -z-10 rounded-full bg-background/25 shadow-sm backdrop-blur-xs'\n\t\t\t/>\n\t\t\t{content}\n\t\t</div>\n\t)\n}\n"],"names":["SaveStatus","status","message","onRetry","floating","className","t","useTranslation","STOA_NS","alert","content","jsxs","cn","jsx","Button"],"mappings":";;;;;AAmBO,SAASA,EAAW;AAAA,EAC1B,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,WAAAC;AACD,GAAoB;AACnB,QAAM,EAAE,GAAAC,EAAA,IAAMC,EAAeC,CAAO;AACpC,MAAI,CAACP,KAAU,CAACC,EAAS,QAAO;AAChC,QAAMO,IAAQ,EAAQP,KAAYD,MAAW,SAEvCS,IACL,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,aAAU;AAAA,MACV,eAAaV,KAAU;AAAA,MACvB,WAAWW;AAAA,QACV;AAAA,QACA,CAACR,KAAYC;AAAA,MAAA;AAAA,MAGd,UAAA;AAAA,QAAA,gBAAAQ;AAAA,UAAC;AAAA,UAAA;AAAA,YACA,MAAMJ,IAAQ,UAAU;AAAA,YACxB,aAAU;AAAA,YACV,WAAWG,EAAGX,MAAW,WAAW,CAACC,KAAW,kBAAkB;AAAA,YAEjE,gBAAYD,IAASK,EAAE,YAAYL,CAAM,EAAE,IAAI;AAAA,UAAA;AAAA,QAAA;AAAA,QAEhDA,MAAW,WAAWE,KACtB,gBAAAU,EAACC,GAAA,EAAO,MAAK,MAAK,SAAQ,SAAQ,SAASX,GACzC,UAAAG,EAAE,eAAe,EAAA,CACnB;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAKH,SAAKF,IAEJ,gBAAAO;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,WAAWC;AAAA,QACV;AAAA,QACAP;AAAA,MAAA;AAAA,MAGD,UAAA;AAAA,QAAA,gBAAAQ;AAAA,UAAC;AAAA,UAAA;AAAA,YACA,eAAY;AAAA,YACZ,WAAU;AAAA,UAAA;AAAA,QAAA;AAAA,QAEVH;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,IAZmBA;AAevB;"}
|
|
@@ -6,23 +6,23 @@ import { useLocation as $, Link as j } from "react-router";
|
|
|
6
6
|
import { STOA_NS as I } from "../../i18n/namespace.js";
|
|
7
7
|
const q = 125, U = 75;
|
|
8
8
|
function S(r) {
|
|
9
|
-
let
|
|
10
|
-
for (;
|
|
11
|
-
if (/(auto|scroll)/.test(getComputedStyle(
|
|
12
|
-
|
|
9
|
+
let e = r?.parentElement;
|
|
10
|
+
for (; e; ) {
|
|
11
|
+
if (/(auto|scroll)/.test(getComputedStyle(e).overflowY)) return e;
|
|
12
|
+
e = e.parentElement;
|
|
13
13
|
}
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
function K({
|
|
17
17
|
scrollContainerRef: r,
|
|
18
|
-
sections:
|
|
18
|
+
sections: e,
|
|
19
19
|
label: k
|
|
20
20
|
}) {
|
|
21
21
|
const [E, T] = w(!1), H = z() ?? !1, { t: M } = F(I), { hash: d } = $(), m = N(null), [g, y] = w(
|
|
22
|
-
|
|
22
|
+
e[0]?.id ?? ""
|
|
23
23
|
), f = O(
|
|
24
|
-
(
|
|
25
|
-
const o = S(r.current), a = m.current, n = document.getElementById(
|
|
24
|
+
(t) => {
|
|
25
|
+
const o = S(r.current), a = m.current, n = document.getElementById(t);
|
|
26
26
|
if (!o || !a || !n) return;
|
|
27
27
|
const l = o.scrollTop + n.getBoundingClientRect().top - o.getBoundingClientRect().top - a.offsetHeight - 16;
|
|
28
28
|
o.scrollTo({ top: Math.max(0, l) }), n.focus({ preventScroll: !0 });
|
|
@@ -30,17 +30,17 @@ function K({
|
|
|
30
30
|
[r]
|
|
31
31
|
);
|
|
32
32
|
return B(() => {
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
const a =
|
|
33
|
+
const t = S(r.current), o = m.current;
|
|
34
|
+
if (!t || !o) return;
|
|
35
|
+
const a = e.map(({ id: i }) => document.getElementById(i));
|
|
36
36
|
let n;
|
|
37
37
|
function l() {
|
|
38
|
-
if (n = void 0, !
|
|
38
|
+
if (n = void 0, !t || !o) return;
|
|
39
39
|
T(
|
|
40
|
-
(s) => s ?
|
|
40
|
+
(s) => s ? t.scrollTop > U : t.scrollTop >= q
|
|
41
41
|
);
|
|
42
|
-
let i =
|
|
43
|
-
const v =
|
|
42
|
+
let i = e[0]?.id ?? "", p = 0;
|
|
43
|
+
const v = t.getBoundingClientRect(), C = Math.max(
|
|
44
44
|
v.top,
|
|
45
45
|
o.getBoundingClientRect().bottom
|
|
46
46
|
), L = Math.min(v.bottom, window.innerHeight);
|
|
@@ -52,7 +52,7 @@ function K({
|
|
|
52
52
|
);
|
|
53
53
|
b > p && (p = b, i = s.id);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
t.scrollHeight > t.clientHeight && t.scrollHeight - t.clientHeight - t.scrollTop <= 2 && (i = e[e.length - 1]?.id ?? ""), y(i);
|
|
56
56
|
}
|
|
57
57
|
function c() {
|
|
58
58
|
n === void 0 && (n = requestAnimationFrame(l));
|
|
@@ -62,18 +62,19 @@ function K({
|
|
|
62
62
|
passive: !0
|
|
63
63
|
}), window.addEventListener("resize", c);
|
|
64
64
|
const u = new ResizeObserver(c);
|
|
65
|
-
u.observe(
|
|
65
|
+
u.observe(t), u.observe(o);
|
|
66
66
|
for (const i of a) i && u.observe(i);
|
|
67
67
|
return l(), () => {
|
|
68
68
|
document.removeEventListener("scroll", c, !0), window.removeEventListener("resize", c), n !== void 0 && cancelAnimationFrame(n), u.disconnect();
|
|
69
69
|
};
|
|
70
|
-
}, [r,
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
}, [d, f,
|
|
70
|
+
}, [r, e]), B(() => {
|
|
71
|
+
const t = d.slice(1);
|
|
72
|
+
e.some((o) => o.id === t) && f(t);
|
|
73
|
+
}, [d, f, e]), e.length === 0 ? null : /* @__PURE__ */ R(
|
|
74
74
|
"nav",
|
|
75
75
|
{
|
|
76
76
|
ref: m,
|
|
77
|
+
"data-slot": "section-navigation",
|
|
77
78
|
"aria-label": k ?? M("app.navigation"),
|
|
78
79
|
className: "sticky top-1 z-20 isolate m-1 mt-4 flex flex-wrap gap-1 rounded-xl p-2",
|
|
79
80
|
children: [
|
|
@@ -87,24 +88,25 @@ function K({
|
|
|
87
88
|
transition: { duration: H ? 0 : 0.2, ease: "easeOut" }
|
|
88
89
|
}
|
|
89
90
|
),
|
|
90
|
-
|
|
91
|
+
e.map(({ id: t, label: o }) => /* @__PURE__ */ x(
|
|
91
92
|
j,
|
|
92
93
|
{
|
|
93
|
-
to: `#${
|
|
94
|
+
to: `#${t}`,
|
|
94
95
|
replace: !0,
|
|
95
|
-
"
|
|
96
|
+
"data-slot": "section-navigation-link",
|
|
97
|
+
"aria-current": g === t ? "location" : void 0,
|
|
96
98
|
onClick: () => {
|
|
97
|
-
d === `#${
|
|
99
|
+
d === `#${t}` && f(t);
|
|
98
100
|
},
|
|
99
101
|
className: `
|
|
100
102
|
rounded-full px-3 py-2
|
|
101
103
|
text-sm font-medium transition-colors
|
|
102
104
|
outline-none focus-visible:ring-2 focus-visible:ring-ring
|
|
103
|
-
${g ===
|
|
105
|
+
${g === t ? "bg-(--section-active) text-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground"}
|
|
104
106
|
`,
|
|
105
107
|
children: o
|
|
106
108
|
},
|
|
107
|
-
|
|
109
|
+
t
|
|
108
110
|
))
|
|
109
111
|
]
|
|
110
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/shell/SectionNavigation/index.tsx"],"sourcesContent":["import { motion, useReducedMotion } from 'motion/react'\nimport { type RefObject, useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { Link, useLocation } from 'react-router'\nimport { STOA_NS } from '../../i18n/namespace'\n\nexport type NavigationSection = { id: string; label: string }\n\nconst showBackgroundOffset = 125\nconst hideBackgroundOffset = 75\n\nfunction getScrollContainer(content: HTMLElement | null) {\n\tlet parent = content?.parentElement\n\twhile (parent) {\n\t\tif (/(auto|scroll)/.test(getComputedStyle(parent).overflowY)) return parent\n\t\tparent = parent.parentElement\n\t}\n\treturn null\n}\n\nexport interface SectionNavigationProps {\n\tsections: readonly NavigationSection[]\n\tlabel?: string\n\tscrollContainerRef: RefObject<HTMLDivElement | null>\n}\n\nexport function SectionNavigation({\n\tscrollContainerRef,\n\tsections,\n\tlabel,\n}: SectionNavigationProps) {\n\tconst [showBackground, setShowBackground] = useState(false)\n\tconst reducedMotion = useReducedMotion() ?? false\n\tconst { t } = useTranslation(STOA_NS)\n\tconst { hash } = useLocation()\n\tconst navigationRef = useRef<HTMLElement>(null)\n\tconst [activeSection, setActiveSection] = useState<string>(\n\t\tsections[0]?.id ?? '',\n\t)\n\n\tconst scrollToSection = useCallback(\n\t\t(id: string) => {\n\t\t\tconst container = getScrollContainer(scrollContainerRef.current)\n\t\t\tconst navigation = navigationRef.current\n\t\t\tconst section = document.getElementById(id)\n\n\t\t\tif (!container || !navigation || !section) return\n\n\t\t\tconst top =\n\t\t\t\tcontainer.scrollTop +\n\t\t\t\tsection.getBoundingClientRect().top -\n\t\t\t\tcontainer.getBoundingClientRect().top -\n\t\t\t\tnavigation.offsetHeight -\n\t\t\t\t16\n\t\t\tcontainer.scrollTo({ top: Math.max(0, top) })\n\t\t\tsection.focus({ preventScroll: true })\n\t\t},\n\t\t[scrollContainerRef],\n\t)\n\n\tuseEffect(() => {\n\t\tconst container = getScrollContainer(scrollContainerRef.current)\n\t\tconst navigation = navigationRef.current\n\n\t\tif (!container || !navigation) return\n\n\t\tconst targets = sections.map(({ id }) => document.getElementById(id))\n\t\tlet animationFrame: number | undefined\n\n\t\tfunction updateActiveSection() {\n\t\t\tanimationFrame = undefined\n\n\t\t\tif (!container || !navigation) return\n\n\t\t\tsetShowBackground((visible) =>\n\t\t\t\tvisible\n\t\t\t\t\t? container.scrollTop > hideBackgroundOffset\n\t\t\t\t\t: container.scrollTop >= showBackgroundOffset,\n\t\t\t)\n\n\t\t\tlet active: string = sections[0]?.id ?? ''\n\t\t\tlet largestVisibleHeight = 0\n\t\t\tconst viewport = container.getBoundingClientRect()\n\t\t\tconst visibleTop = Math.max(\n\t\t\t\tviewport.top,\n\t\t\t\tnavigation.getBoundingClientRect().bottom,\n\t\t\t)\n\t\t\tconst visibleBottom = Math.min(viewport.bottom, window.innerHeight)\n\n\t\t\tfor (const section of targets) {\n\t\t\t\tif (!section) continue\n\t\t\t\tconst bounds = section.getBoundingClientRect()\n\t\t\t\tconst visibleHeight = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\tMath.min(bounds.bottom, visibleBottom) -\n\t\t\t\t\t\tMath.max(bounds.top, visibleTop),\n\t\t\t\t)\n\t\t\t\tif (visibleHeight > largestVisibleHeight) {\n\t\t\t\t\tlargestVisibleHeight = visibleHeight\n\t\t\t\t\tactive = section.id\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tcontainer.scrollHeight > container.clientHeight &&\n\t\t\t\tcontainer.scrollHeight - container.clientHeight - container.scrollTop <=\n\t\t\t\t\t2\n\t\t\t) {\n\t\t\t\tactive = sections[sections.length - 1]?.id ?? ''\n\t\t\t}\n\t\t\tsetActiveSection(active)\n\t\t}\n\n\t\tfunction scheduleUpdate() {\n\t\t\tif (animationFrame === undefined)\n\t\t\t\tanimationFrame = requestAnimationFrame(updateActiveSection)\n\t\t}\n\n\t\t// Capture scrolls from the page and its ancestors, including native WebView scrolling.\n\t\tdocument.addEventListener('scroll', scheduleUpdate, {\n\t\t\tcapture: true,\n\t\t\tpassive: true,\n\t\t})\n\n\t\twindow.addEventListener('resize', scheduleUpdate)\n\t\tconst observer = new ResizeObserver(scheduleUpdate)\n\t\tobserver.observe(container)\n\t\tobserver.observe(navigation)\n\t\tfor (const target of targets) if (target) observer.observe(target)\n\t\tupdateActiveSection()\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('scroll', scheduleUpdate, true)\n\t\t\twindow.removeEventListener('resize', scheduleUpdate)\n\t\t\tif (animationFrame !== undefined) cancelAnimationFrame(animationFrame)\n\t\t\tobserver.disconnect()\n\t\t}\n\t}, [scrollContainerRef, sections])\n\n\tuseEffect(() => {\n\t\tconst id = hash.slice(1)\n\t\tif (sections.some((section) => section.id === id)) scrollToSection(id)\n\t}, [hash, scrollToSection, sections])\n\n\tif (sections.length === 0) return null\n\n\treturn (\n\t\t<nav\n\t\t\tref={navigationRef}\n\t\t\taria-label={label ?? t('app.navigation')}\n\t\t\tclassName='sticky top-1 z-20 isolate m-1 mt-4 flex flex-wrap gap-1 rounded-xl p-2'\n\t\t>\n\t\t\t<motion.div\n\t\t\t\taria-hidden='true'\n\t\t\t\tclassName='pointer-events-none absolute inset-0 -z-10 rounded-xl bg-background/25 shadow-sm backdrop-blur-xs'\n\t\t\t\tinitial={false}\n\t\t\t\tanimate={{ opacity: showBackground ? 1 : 0 }}\n\t\t\t\ttransition={{ duration: reducedMotion ? 0 : 0.2, ease: 'easeOut' }}\n\t\t\t/>\n\t\t\t{sections.map(({ id, label }) => (\n\t\t\t\t<Link\n\t\t\t\t\tkey={id}\n\t\t\t\t\tto={`#${id}`}\n\t\t\t\t\treplace\n\t\t\t\t\taria-current={activeSection === id ? 'location' : undefined}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tif (hash === `#${id}`) scrollToSection(id)\n\t\t\t\t\t}}\n\t\t\t\t\tclassName={`\n\t\t\t\t\t\trounded-full px-3 py-2\n\t\t\t\t\t\ttext-sm font-medium transition-colors\n\t\t\t\t\t\toutline-none focus-visible:ring-2 focus-visible:ring-ring\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\tactiveSection === id\n\t\t\t\t\t\t\t\t? 'bg-(--section-active) text-foreground'\n\t\t\t\t\t\t\t\t: 'text-muted-foreground hover:bg-muted hover:text-foreground'\n\t\t\t\t\t\t}\n\t\t\t\t\t`}\n\t\t\t\t>\n\t\t\t\t\t{label}\n\t\t\t\t</Link>\n\t\t\t))}\n\t\t</nav>\n\t)\n}\n"],"names":["showBackgroundOffset","hideBackgroundOffset","getScrollContainer","content","parent","SectionNavigation","scrollContainerRef","sections","label","showBackground","setShowBackground","useState","reducedMotion","useReducedMotion","t","useTranslation","STOA_NS","hash","useLocation","navigationRef","useRef","activeSection","setActiveSection","scrollToSection","useCallback","id","container","navigation","section","top","useEffect","targets","animationFrame","updateActiveSection","visible","active","largestVisibleHeight","viewport","visibleTop","visibleBottom","bounds","visibleHeight","scheduleUpdate","observer","target","jsxs","jsx","motion","Link"],"mappings":";;;;;;AAQA,MAAMA,IAAuB,KACvBC,IAAuB;AAE7B,SAASC,EAAmBC,GAA6B;AACxD,MAAIC,IAASD,GAAS;AACtB,SAAOC,KAAQ;AACd,QAAI,gBAAgB,KAAK,iBAAiBA,CAAM,EAAE,SAAS,EAAG,QAAOA;AACrE,IAAAA,IAASA,EAAO;AAAA,EACjB;AACA,SAAO;AACR;AAQO,SAASC,EAAkB;AAAA,EACjC,oBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AACD,GAA2B;AAC1B,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAS,EAAK,GACpDC,IAAgBC,OAAsB,IACtC,EAAE,GAAAC,EAAA,IAAMC,EAAeC,CAAO,GAC9B,EAAE,MAAAC,EAAA,IAASC,EAAA,GACXC,IAAgBC,EAAoB,IAAI,GACxC,CAACC,GAAeC,CAAgB,IAAIX;AAAA,IACzCJ,EAAS,CAAC,GAAG,MAAM;AAAA,EAAA,GAGdgB,IAAkBC;AAAA,IACvB,CAACC,MAAe;AACf,YAAMC,IAAYxB,EAAmBI,EAA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,eAAY;AAAA,YACZ,WAAU;AAAA,YACV,SAAS;AAAA,YACT,SAAS,EAAE,SAAStC,IAAiB,IAAI,EAAA;AAAA,YACzC,YAAY,EAAE,UAAUG,IAAgB,IAAI,KAAK,MAAM,UAAA;AAAA,UAAU;AAAA,QAAA;AAAA,QAEjEL,EAAS,IAAI,CAAC,EAAE,IAAAkB,GAAI,OAAAjB,QACpB,gBAAAsC;AAAA,UAACE;AAAA,UAAA;AAAA,YAEA,IAAI,IAAIvB,CAAE;AAAA,YACV,SAAO;AAAA,YACP,gBAAcJ,MAAkBI,IAAK,aAAa;AAAA,YAClD,SAAS,MAAM;AACd,cAAIR,MAAS,IAAIQ,CAAE,QAAoBA,CAAE;AAAA,YAC1C;AAAA,YACA,WAAW;AAAA;AAAA;AAAA;AAAA,QAKTJ,MAAkBI,IACf,0CACA,4DACJ;AAAA;AAAA,YAGA,UAAAjB;AAAAA,UAAA;AAAA,UAlBIiB;AAAA,QAAA,CAoBN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/SectionNavigation/index.tsx"],"sourcesContent":["import { motion, useReducedMotion } from 'motion/react'\nimport { type RefObject, useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { Link, useLocation } from 'react-router'\nimport { STOA_NS } from '../../i18n/namespace'\n\nexport type NavigationSection = { id: string; label: string }\n\nconst showBackgroundOffset = 125\nconst hideBackgroundOffset = 75\n\nfunction getScrollContainer(content: HTMLElement | null) {\n\tlet parent = content?.parentElement\n\twhile (parent) {\n\t\tif (/(auto|scroll)/.test(getComputedStyle(parent).overflowY)) return parent\n\t\tparent = parent.parentElement\n\t}\n\treturn null\n}\n\nexport interface SectionNavigationProps {\n\tsections: readonly NavigationSection[]\n\tlabel?: string\n\tscrollContainerRef: RefObject<HTMLDivElement | null>\n}\n\nexport function SectionNavigation({\n\tscrollContainerRef,\n\tsections,\n\tlabel,\n}: SectionNavigationProps) {\n\tconst [showBackground, setShowBackground] = useState(false)\n\tconst reducedMotion = useReducedMotion() ?? false\n\tconst { t } = useTranslation(STOA_NS)\n\tconst { hash } = useLocation()\n\tconst navigationRef = useRef<HTMLElement>(null)\n\tconst [activeSection, setActiveSection] = useState<string>(\n\t\tsections[0]?.id ?? '',\n\t)\n\n\tconst scrollToSection = useCallback(\n\t\t(id: string) => {\n\t\t\tconst container = getScrollContainer(scrollContainerRef.current)\n\t\t\tconst navigation = navigationRef.current\n\t\t\tconst section = document.getElementById(id)\n\n\t\t\tif (!container || !navigation || !section) return\n\n\t\t\tconst top =\n\t\t\t\tcontainer.scrollTop +\n\t\t\t\tsection.getBoundingClientRect().top -\n\t\t\t\tcontainer.getBoundingClientRect().top -\n\t\t\t\tnavigation.offsetHeight -\n\t\t\t\t16\n\t\t\tcontainer.scrollTo({ top: Math.max(0, top) })\n\t\t\tsection.focus({ preventScroll: true })\n\t\t},\n\t\t[scrollContainerRef],\n\t)\n\n\tuseEffect(() => {\n\t\tconst container = getScrollContainer(scrollContainerRef.current)\n\t\tconst navigation = navigationRef.current\n\n\t\tif (!container || !navigation) return\n\n\t\tconst targets = sections.map(({ id }) => document.getElementById(id))\n\t\tlet animationFrame: number | undefined\n\n\t\tfunction updateActiveSection() {\n\t\t\tanimationFrame = undefined\n\n\t\t\tif (!container || !navigation) return\n\n\t\t\tsetShowBackground((visible) =>\n\t\t\t\tvisible\n\t\t\t\t\t? container.scrollTop > hideBackgroundOffset\n\t\t\t\t\t: container.scrollTop >= showBackgroundOffset,\n\t\t\t)\n\n\t\t\tlet active: string = sections[0]?.id ?? ''\n\t\t\tlet largestVisibleHeight = 0\n\t\t\tconst viewport = container.getBoundingClientRect()\n\t\t\tconst visibleTop = Math.max(\n\t\t\t\tviewport.top,\n\t\t\t\tnavigation.getBoundingClientRect().bottom,\n\t\t\t)\n\t\t\tconst visibleBottom = Math.min(viewport.bottom, window.innerHeight)\n\n\t\t\tfor (const section of targets) {\n\t\t\t\tif (!section) continue\n\t\t\t\tconst bounds = section.getBoundingClientRect()\n\t\t\t\tconst visibleHeight = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\tMath.min(bounds.bottom, visibleBottom) -\n\t\t\t\t\t\tMath.max(bounds.top, visibleTop),\n\t\t\t\t)\n\t\t\t\tif (visibleHeight > largestVisibleHeight) {\n\t\t\t\t\tlargestVisibleHeight = visibleHeight\n\t\t\t\t\tactive = section.id\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tcontainer.scrollHeight > container.clientHeight &&\n\t\t\t\tcontainer.scrollHeight - container.clientHeight - container.scrollTop <=\n\t\t\t\t\t2\n\t\t\t) {\n\t\t\t\tactive = sections[sections.length - 1]?.id ?? ''\n\t\t\t}\n\t\t\tsetActiveSection(active)\n\t\t}\n\n\t\tfunction scheduleUpdate() {\n\t\t\tif (animationFrame === undefined)\n\t\t\t\tanimationFrame = requestAnimationFrame(updateActiveSection)\n\t\t}\n\n\t\t// Capture scrolls from the page and its ancestors, including native WebView scrolling.\n\t\tdocument.addEventListener('scroll', scheduleUpdate, {\n\t\t\tcapture: true,\n\t\t\tpassive: true,\n\t\t})\n\n\t\twindow.addEventListener('resize', scheduleUpdate)\n\t\tconst observer = new ResizeObserver(scheduleUpdate)\n\t\tobserver.observe(container)\n\t\tobserver.observe(navigation)\n\t\tfor (const target of targets) if (target) observer.observe(target)\n\t\tupdateActiveSection()\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('scroll', scheduleUpdate, true)\n\t\t\twindow.removeEventListener('resize', scheduleUpdate)\n\t\t\tif (animationFrame !== undefined) cancelAnimationFrame(animationFrame)\n\t\t\tobserver.disconnect()\n\t\t}\n\t}, [scrollContainerRef, sections])\n\n\tuseEffect(() => {\n\t\tconst id = hash.slice(1)\n\t\tif (sections.some((section) => section.id === id)) scrollToSection(id)\n\t}, [hash, scrollToSection, sections])\n\n\tif (sections.length === 0) return null\n\n\treturn (\n\t\t<nav\n\t\t\tref={navigationRef}\n\t\t\tdata-slot='section-navigation'\n\t\t\taria-label={label ?? t('app.navigation')}\n\t\t\tclassName='sticky top-1 z-20 isolate m-1 mt-4 flex flex-wrap gap-1 rounded-xl p-2'\n\t\t>\n\t\t\t<motion.div\n\t\t\t\taria-hidden='true'\n\t\t\t\tclassName='pointer-events-none absolute inset-0 -z-10 rounded-xl bg-background/25 shadow-sm backdrop-blur-xs'\n\t\t\t\tinitial={false}\n\t\t\t\tanimate={{ opacity: showBackground ? 1 : 0 }}\n\t\t\t\ttransition={{ duration: reducedMotion ? 0 : 0.2, ease: 'easeOut' }}\n\t\t\t/>\n\t\t\t{sections.map(({ id, label }) => (\n\t\t\t\t<Link\n\t\t\t\t\tkey={id}\n\t\t\t\t\tto={`#${id}`}\n\t\t\t\t\treplace\n\t\t\t\t\tdata-slot='section-navigation-link'\n\t\t\t\t\taria-current={activeSection === id ? 'location' : undefined}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tif (hash === `#${id}`) scrollToSection(id)\n\t\t\t\t\t}}\n\t\t\t\t\tclassName={`\n\t\t\t\t\t\trounded-full px-3 py-2\n\t\t\t\t\t\ttext-sm font-medium transition-colors\n\t\t\t\t\t\toutline-none focus-visible:ring-2 focus-visible:ring-ring\n\t\t\t\t\t\t${\n\t\t\t\t\t\t\tactiveSection === id\n\t\t\t\t\t\t\t\t? 'bg-(--section-active) text-foreground'\n\t\t\t\t\t\t\t\t: 'text-muted-foreground hover:bg-muted hover:text-foreground'\n\t\t\t\t\t\t}\n\t\t\t\t\t`}\n\t\t\t\t>\n\t\t\t\t\t{label}\n\t\t\t\t</Link>\n\t\t\t))}\n\t\t</nav>\n\t)\n}\n"],"names":["showBackgroundOffset","hideBackgroundOffset","getScrollContainer","content","parent","SectionNavigation","scrollContainerRef","sections","label","showBackground","setShowBackground","useState","reducedMotion","useReducedMotion","t","useTranslation","STOA_NS","hash","useLocation","navigationRef","useRef","activeSection","setActiveSection","scrollToSection","useCallback","id","container","navigation","section","top","useEffect","targets","animationFrame","updateActiveSection","visible","active","largestVisibleHeight","viewport","visibleTop","visibleBottom","bounds","visibleHeight","scheduleUpdate","observer","target","jsxs","jsx","motion","Link"],"mappings":";;;;;;AAQA,MAAMA,IAAuB,KACvBC,IAAuB;AAE7B,SAASC,EAAmBC,GAA6B;AACxD,MAAIC,IAASD,GAAS;AACtB,SAAOC,KAAQ;AACd,QAAI,gBAAgB,KAAK,iBAAiBA,CAAM,EAAE,SAAS,EAAG,QAAOA;AACrE,IAAAA,IAASA,EAAO;AAAA,EACjB;AACA,SAAO;AACR;AAQO,SAASC,EAAkB;AAAA,EACjC,oBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AACD,GAA2B;AAC1B,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAS,EAAK,GACpDC,IAAgBC,OAAsB,IACtC,EAAE,GAAAC,EAAA,IAAMC,EAAeC,CAAO,GAC9B,EAAE,MAAAC,EAAA,IAASC,EAAA,GACXC,IAAgBC,EAAoB,IAAI,GACxC,CAACC,GAAeC,CAAgB,IAAIX;AAAA,IACzCJ,EAAS,CAAC,GAAG,MAAM;AAAA,EAAA,GAGdgB,IAAkBC;AAAA,IACvB,CAACC,MAAe;AACf,YAAMC,IAAYxB,EAAmBI,EAAmB,OAAO,GACzDqB,IAAaR,EAAc,SAC3BS,IAAU,SAAS,eAAeH,CAAE;AAE1C,UAAI,CAACC,KAAa,CAACC,KAAc,CAACC,EAAS;AAE3C,YAAMC,IACLH,EAAU,YACVE,EAAQ,sBAAA,EAAwB,MAChCF,EAAU,sBAAA,EAAwB,MAClCC,EAAW,eACX;AACD,MAAAD,EAAU,SAAS,EAAE,KAAK,KAAK,IAAI,GAAGG,CAAG,GAAG,GAC5CD,EAAQ,MAAM,EAAE,eAAe,GAAA,CAAM;AAAA,IACtC;AAAA,IACA,CAACtB,CAAkB;AAAA,EAAA;AAuFpB,SApFAwB,EAAU,MAAM;AACf,UAAMJ,IAAYxB,EAAm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cAAIR,MAAS,IAAIQ,CAAE,QAAoBA,CAAE;AAAA,YAC1C;AAAA,YACA,WAAW;AAAA;AAAA;AAAA;AAAA,QAKTJ,MAAkBI,IACf,0CACA,4DACJ;AAAA;AAAA,YAGA,UAAAjB;AAAAA,UAAA;AAAA,UAnBIiB;AAAA,QAAA,CAqBN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as i, jsxs as z } from "react/jsx-runtime";
|
|
2
|
+
import { useReducedMotion as B, motion as h } from "motion/react";
|
|
3
|
+
import { useState as o, useEffect as c } from "react";
|
|
4
|
+
import { useTranslation as C } from "react-i18next";
|
|
5
|
+
import { STOA_NS as E } from "../../i18n/namespace.js";
|
|
6
|
+
import { cn as M } from "../../utils/cn.js";
|
|
7
|
+
import { BrandLines as O } from "../BrandLines/index.js";
|
|
8
|
+
function J({
|
|
9
|
+
ready: x,
|
|
10
|
+
phase: l,
|
|
11
|
+
onComplete: S,
|
|
12
|
+
name: N,
|
|
13
|
+
logo: s,
|
|
14
|
+
settingsPaths: r = [],
|
|
15
|
+
settingsInterval: d = 150,
|
|
16
|
+
finalMessageDelay: m = 0,
|
|
17
|
+
messages: v,
|
|
18
|
+
className: y
|
|
19
|
+
}) {
|
|
20
|
+
const { t: T } = C(E), e = B() ?? !1, [j, A] = o(!1), [u, p] = o(!1), [I, F] = o(!1), [f, k] = o(0), a = l === "license", n = a ? "license" : u ? l : "settings", w = x && (e || j && u && I);
|
|
21
|
+
c(() => {
|
|
22
|
+
const t = window.setTimeout(
|
|
23
|
+
() => A(!0),
|
|
24
|
+
e ? 0 : 2e3
|
|
25
|
+
);
|
|
26
|
+
return () => window.clearTimeout(t);
|
|
27
|
+
}, [e]), c(() => {
|
|
28
|
+
if (a) return;
|
|
29
|
+
if (e || r.length === 0) {
|
|
30
|
+
p(!0);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let t = 0;
|
|
34
|
+
const g = window.setInterval(() => {
|
|
35
|
+
t += 1, t < r.length ? k(t) : (p(!0), window.clearInterval(g));
|
|
36
|
+
}, d);
|
|
37
|
+
return () => window.clearInterval(g);
|
|
38
|
+
}, [a, e, r.length, d]), c(() => {
|
|
39
|
+
if (n !== "app") return;
|
|
40
|
+
const t = window.setTimeout(
|
|
41
|
+
() => F(!0),
|
|
42
|
+
e ? 0 : m
|
|
43
|
+
);
|
|
44
|
+
return () => window.clearTimeout(t);
|
|
45
|
+
}, [n, e, m]);
|
|
46
|
+
const L = v?.[n] ?? T(
|
|
47
|
+
n === "license" ? "licensing.gate.loading" : n === "settings" ? "app.loadingSettings" : "app.loadingApp"
|
|
48
|
+
);
|
|
49
|
+
return /* @__PURE__ */ i(
|
|
50
|
+
h.main,
|
|
51
|
+
{
|
|
52
|
+
role: "status",
|
|
53
|
+
"data-slot": "startup-animation",
|
|
54
|
+
className: M(
|
|
55
|
+
"app-shell relative flex h-screen items-center justify-center overflow-hidden p-6",
|
|
56
|
+
y
|
|
57
|
+
),
|
|
58
|
+
initial: !1,
|
|
59
|
+
animate: { opacity: w ? 0 : 1 },
|
|
60
|
+
transition: { duration: e ? 0 : 0.18 },
|
|
61
|
+
onAnimationComplete: () => {
|
|
62
|
+
w && S();
|
|
63
|
+
},
|
|
64
|
+
children: /* @__PURE__ */ z("div", { className: "relative grid justify-items-center gap-5", children: [
|
|
65
|
+
typeof s == "string" ? /* @__PURE__ */ i(
|
|
66
|
+
h.img,
|
|
67
|
+
{
|
|
68
|
+
src: s,
|
|
69
|
+
alt: "",
|
|
70
|
+
"aria-hidden": "true",
|
|
71
|
+
className: "size-28 rounded-3xl",
|
|
72
|
+
initial: { opacity: e ? 1 : 0 },
|
|
73
|
+
animate: { opacity: 1 },
|
|
74
|
+
transition: { duration: e ? 0 : 0.5 }
|
|
75
|
+
}
|
|
76
|
+
) : s,
|
|
77
|
+
/* @__PURE__ */ i("p", { className: "text-lg font-medium tracking-[0.18em]", children: N }),
|
|
78
|
+
/* @__PURE__ */ i(O, { loading: !e }),
|
|
79
|
+
/* @__PURE__ */ i("p", { className: "text-sm text-muted-foreground", children: L }),
|
|
80
|
+
/* @__PURE__ */ i("span", { "aria-hidden": "true", className: "h-5 text-xs text-muted-foreground", children: n === "settings" && !e && r[f] ? `/${r[f]}` : "" })
|
|
81
|
+
] })
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
J as StartupAnimation
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/StartupAnimation/index.tsx"],"sourcesContent":["import { motion, useReducedMotion } from 'motion/react'\nimport { type ReactNode, useEffect, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { STOA_NS } from '../../i18n/namespace'\nimport { cn } from '../../utils/cn'\nimport { BrandLines } from '../BrandLines'\n\nexport type StartupPhase = 'license' | 'settings' | 'app'\n\nexport interface StartupAnimationProps {\n\tready: boolean\n\tphase: StartupPhase\n\tonComplete: () => void\n\t/** App name shown under the logo. */\n\tname: string\n\t/** Image URL or a custom (e.g. animated inline SVG) logo. */\n\tlogo?: string | ReactNode\n\t/**\n\t * Already translated setting names that flicker by while settings load,\n\t * e.g. `['Sprache', 'Darstellung']` or deeper paths like `'Einstellungen/E-Mail/Server'`.\n\t */\n\tsettingsPaths?: readonly string[]\n\t/** Milliseconds per setting name. */\n\tsettingsInterval?: number\n\t/** Keeps the final message visible a moment before the overlay fades. */\n\tfinalMessageDelay?: number\n\t/** Per-phase status text; defaults come from the kit locales. */\n\tmessages?: Partial<Record<StartupPhase, string>>\n\tclassName?: string\n}\n\n/** Startup overlay: logo, app name, brand lines and the current loading step. */\nexport function StartupAnimation({\n\tready,\n\tphase,\n\tonComplete,\n\tname,\n\tlogo,\n\tsettingsPaths = [],\n\tsettingsInterval = 150,\n\tfinalMessageDelay = 0,\n\tmessages,\n\tclassName,\n}: StartupAnimationProps) {\n\tconst { t } = useTranslation(STOA_NS)\n\tconst reducedMotion = useReducedMotion() ?? false\n\tconst [introFinished, setIntroFinished] = useState(false)\n\tconst [settingsShown, setSettingsShown] = useState(false)\n\tconst [finalShown, setFinalShown] = useState(false)\n\tconst [index, setIndex] = useState(0)\n\tconst checkingLicense = phase === 'license'\n\tconst display: StartupPhase = checkingLicense\n\t\t? 'license'\n\t\t: settingsShown\n\t\t\t? phase\n\t\t\t: 'settings'\n\tconst exiting =\n\t\tready && (reducedMotion || (introFinished && settingsShown && finalShown))\n\n\tuseEffect(() => {\n\t\tconst timer = window.setTimeout(\n\t\t\t() => setIntroFinished(true),\n\t\t\treducedMotion ? 0 : 2000,\n\t\t)\n\t\treturn () => window.clearTimeout(timer)\n\t}, [reducedMotion])\n\n\tuseEffect(() => {\n\t\tif (checkingLicense) return\n\t\tif (reducedMotion || settingsPaths.length === 0) {\n\t\t\tsetSettingsShown(true)\n\t\t\treturn\n\t\t}\n\t\tlet current = 0\n\t\tconst timer = window.setInterval(() => {\n\t\t\tcurrent += 1\n\t\t\tif (current < settingsPaths.length) setIndex(current)\n\t\t\telse {\n\t\t\t\tsetSettingsShown(true)\n\t\t\t\twindow.clearInterval(timer)\n\t\t\t}\n\t\t}, settingsInterval)\n\t\treturn () => window.clearInterval(timer)\n\t}, [checkingLicense, reducedMotion, settingsPaths.length, settingsInterval])\n\n\tuseEffect(() => {\n\t\tif (display !== 'app') return\n\t\tconst timer = window.setTimeout(\n\t\t\t() => setFinalShown(true),\n\t\t\treducedMotion ? 0 : finalMessageDelay,\n\t\t)\n\t\treturn () => window.clearTimeout(timer)\n\t}, [display, reducedMotion, finalMessageDelay])\n\n\tconst text =\n\t\tmessages?.[display] ??\n\t\tt(\n\t\t\tdisplay === 'license'\n\t\t\t\t? 'licensing.gate.loading'\n\t\t\t\t: display === 'settings'\n\t\t\t\t\t? 'app.loadingSettings'\n\t\t\t\t\t: 'app.loadingApp',\n\t\t)\n\n\treturn (\n\t\t<motion.main\n\t\t\trole='status'\n\t\t\tdata-slot='startup-animation'\n\t\t\tclassName={cn(\n\t\t\t\t'app-shell relative flex h-screen items-center justify-center overflow-hidden p-6',\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\tinitial={false}\n\t\t\tanimate={{ opacity: exiting ? 0 : 1 }}\n\t\t\ttransition={{ duration: reducedMotion ? 0 : 0.18 }}\n\t\t\tonAnimationComplete={() => {\n\t\t\t\tif (exiting) onComplete()\n\t\t\t}}\n\t\t>\n\t\t\t<div className='relative grid justify-items-center gap-5'>\n\t\t\t\t{typeof logo === 'string' ? (\n\t\t\t\t\t<motion.img\n\t\t\t\t\t\tsrc={logo}\n\t\t\t\t\t\talt=''\n\t\t\t\t\t\taria-hidden='true'\n\t\t\t\t\t\tclassName='size-28 rounded-3xl'\n\t\t\t\t\t\tinitial={{ opacity: reducedMotion ? 1 : 0 }}\n\t\t\t\t\t\tanimate={{ opacity: 1 }}\n\t\t\t\t\t\ttransition={{ duration: reducedMotion ? 0 : 0.5 }}\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\tlogo\n\t\t\t\t)}\n\t\t\t\t<p className='text-lg font-medium tracking-[0.18em]'>{name}</p>\n\t\t\t\t<BrandLines loading={!reducedMotion} />\n\t\t\t\t<p className='text-sm text-muted-foreground'>{text}</p>\n\t\t\t\t<span aria-hidden='true' className='h-5 text-xs text-muted-foreground'>\n\t\t\t\t\t{display === 'settings' && !reducedMotion && settingsPaths[index]\n\t\t\t\t\t\t? `/${settingsPaths[index]}`\n\t\t\t\t\t\t: ''}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t</motion.main>\n\t)\n}\n"],"names":["StartupAnimation","ready","phase","onComplete","name","logo","settingsPaths","settingsInterval","finalMessageDelay","messages","className","t","useTranslation","STOA_NS","reducedMotion","useReducedMotion","introFinished","setIntroFinished","useState","settingsShown","setSettingsShown","finalShown","setFinalShown","index","setIndex","checkingLicense","display","exiting","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QACrC,gBAAAkB,EAAC,KAAA,EAAE,WAAU,iCAAiC,UAAAD,GAAK;AAAA,0BAClD,QAAA,EAAK,eAAY,QAAO,WAAU,qCACjC,gBAAY,cAAc,CAACjB,KAAiBR,EAAciB,CAAK,IAC7D,IAAIjB,EAAciB,CAAK,CAAC,KACxB,GAAA,CACJ;AAAA,MAAA,EAAA,CACD;AAAA,IAAA;AAAA,EAAA;AAGH;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsxs as m, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { useState as e, useCallback as c, useContext as h, createContext as x } from "react";
|
|
3
|
+
import { StartupAnimation as S } from "../StartupAnimation/index.js";
|
|
4
|
+
const u = x(null);
|
|
5
|
+
function P({ children: t, animation: l }) {
|
|
6
|
+
const [f, s] = e("license"), [d, n] = e(!1), [r, i] = e(!1), o = c(() => i(!0), []), p = c(() => {
|
|
7
|
+
s("settings"), n(!1), i(!1);
|
|
8
|
+
}, []);
|
|
9
|
+
return /* @__PURE__ */ m(
|
|
10
|
+
u.Provider,
|
|
11
|
+
{
|
|
12
|
+
value: { finished: r, setPhase: s, setReady: n, finish: o, beginDataLoading: p },
|
|
13
|
+
children: [
|
|
14
|
+
t,
|
|
15
|
+
!r && /* @__PURE__ */ a("div", { className: "fixed inset-0 z-100", children: /* @__PURE__ */ a(
|
|
16
|
+
S,
|
|
17
|
+
{
|
|
18
|
+
...l,
|
|
19
|
+
ready: d,
|
|
20
|
+
phase: f,
|
|
21
|
+
onComplete: o
|
|
22
|
+
}
|
|
23
|
+
) })
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function b() {
|
|
29
|
+
const t = h(u);
|
|
30
|
+
if (!t) throw new Error("StartupProvider is missing");
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
P as StartupProvider,
|
|
35
|
+
b as useStartup
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/StartupProvider/index.tsx"],"sourcesContent":["import {\n\tcreateContext,\n\ttype Dispatch,\n\ttype ReactNode,\n\ttype SetStateAction,\n\tuseCallback,\n\tuseContext,\n\tuseState,\n} from 'react'\nimport {\n\tStartupAnimation,\n\ttype StartupAnimationProps,\n\ttype StartupPhase,\n} from '../StartupAnimation'\n\ntype StartupContextValue = {\n\tfinished: boolean\n\tsetPhase: Dispatch<SetStateAction<StartupPhase>>\n\tsetReady: Dispatch<SetStateAction<boolean>>\n\tfinish: () => void\n\tbeginDataLoading: () => void\n}\n\nconst StartupContext = createContext<StartupContextValue | null>(null)\n\nexport interface StartupProviderProps {\n\tchildren: ReactNode\n\t/** Everything the overlay shows: name, logo, setting names, messages. */\n\tanimation: Omit<StartupAnimationProps, 'ready' | 'phase' | 'onComplete'>\n}\n\n/**\n * Shows the startup overlay above the app until `finish()` is called or the\n * data reports ready. Phases: license → settings → app.\n */\nexport function StartupProvider({ children, animation }: StartupProviderProps) {\n\tconst [phase, setPhase] = useState<StartupPhase>('license')\n\tconst [ready, setReady] = useState(false)\n\tconst [finished, setFinished] = useState(false)\n\tconst finish = useCallback(() => setFinished(true), [])\n\tconst beginDataLoading = useCallback(() => {\n\t\tsetPhase('settings')\n\t\tsetReady(false)\n\t\tsetFinished(false)\n\t}, [])\n\n\treturn (\n\t\t<StartupContext.Provider\n\t\t\tvalue={{ finished, setPhase, setReady, finish, beginDataLoading }}\n\t\t>\n\t\t\t{children}\n\t\t\t{!finished && (\n\t\t\t\t<div className='fixed inset-0 z-100'>\n\t\t\t\t\t<StartupAnimation\n\t\t\t\t\t\t{...animation}\n\t\t\t\t\t\tready={ready}\n\t\t\t\t\t\tphase={phase}\n\t\t\t\t\t\tonComplete={finish}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</StartupContext.Provider>\n\t)\n}\n\nexport function useStartup() {\n\tconst context = useContext(StartupContext)\n\tif (!context) throw new Error('StartupProvider is missing')\n\treturn context\n}\n"],"names":["StartupContext","createContext","StartupProvider","children","animation","phase","setPhase","useState","ready","setReady","finished","setFinished","finish","useCallback","beginDataLoading","jsxs","jsx","StartupAnimation","useStartup","context","useContext"],"mappings":";;;AAuBA,MAAMA,IAAiBC,EAA0C,IAAI;AAY9D,SAASC,EAAgB,EAAE,UAAAC,GAAU,WAAAC,KAAmC;AAC9E,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAuB,SAAS,GACpD,CAACC,GAAOC,CAAQ,IAAIF,EAAS,EAAK,GAClC,CAACG,GAAUC,CAAW,IAAIJ,EAAS,EAAK,GACxCK,IAASC,EAAY,MAAMF,EAAY,EAAI,GAAG,CAAA,CAAE,GAChDG,IAAmBD,EAAY,MAAM;AAC1C,IAAAP,EAAS,UAAU,GACnBG,EAAS,EAAK,GACdE,EAAY,EAAK;AAAA,EAClB,GAAG,CAAA,CAAE;AAEL,SACC,gBAAAI;AAAA,IAACf,EAAe;AAAA,IAAf;AAAA,MACA,OAAO,EAAE,UAAAU,GAAU,UAAAJ,GAAU,UAAAG,GAAU,QAAAG,GAAQ,kBAAAE,EAAA;AAAA,MAE9C,UAAA;AAAA,QAAAX;AAAA,QACA,CAACO,KACD,gBAAAM,EAAC,OAAA,EAAI,WAAU,uBACd,UAAA,gBAAAA;AAAA,UAACC;AAAA,UAAA;AAAA,YACC,GAAGb;AAAA,YACJ,OAAAI;AAAA,YACA,OAAAH;AAAA,YACA,YAAYO;AAAA,UAAA;AAAA,QAAA,EACb,CACD;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIJ;AAEO,SAASM,IAAa;AAC5B,QAAMC,IAAUC,EAAWpB,CAAc;AACzC,MAAI,CAACmB,EAAS,OAAM,IAAI,MAAM,4BAA4B;AAC1D,SAAOA;AACR;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsxs as g, jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import { X as y } from "lucide-react";
|
|
3
|
+
import { useId as w, useState as k } from "react";
|
|
4
|
+
import { useTranslation as L } from "react-i18next";
|
|
5
|
+
import { STOA_NS as N } from "../../i18n/namespace.js";
|
|
6
|
+
import { cn as T } from "../../utils/cn.js";
|
|
7
|
+
function S(c) {
|
|
8
|
+
const t = /* @__PURE__ */ new Set(), n = [];
|
|
9
|
+
for (const p of c) {
|
|
10
|
+
const o = p.trim().replace(/\s+/g, " "), a = o.toLocaleLowerCase();
|
|
11
|
+
!o || t.has(a) || (t.add(a), n.push(o));
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
function E({
|
|
16
|
+
id: c,
|
|
17
|
+
value: t,
|
|
18
|
+
onChange: n,
|
|
19
|
+
suggestions: p = [],
|
|
20
|
+
disabled: o,
|
|
21
|
+
placeholder: a,
|
|
22
|
+
prefix: h = "#",
|
|
23
|
+
className: x
|
|
24
|
+
}) {
|
|
25
|
+
const { t: f } = L(N), u = w(), [r, m] = k(""), d = (e) => {
|
|
26
|
+
const i = S([...t, ...e.split(",")]);
|
|
27
|
+
i.length !== t.length && n(i), m("");
|
|
28
|
+
};
|
|
29
|
+
function b(e) {
|
|
30
|
+
e.key === "Enter" && e.preventDefault(), (e.key === "Enter" || e.key === "," || e.key === "Tab") && r.trim() ? (e.preventDefault(), d(r)) : e.key === "Backspace" && !r && t.length && n(t.slice(0, -1));
|
|
31
|
+
}
|
|
32
|
+
const l = p.filter(
|
|
33
|
+
(e) => !t.some(
|
|
34
|
+
(i) => i.toLocaleLowerCase() === e.toLocaleLowerCase()
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
return /* @__PURE__ */ g(
|
|
38
|
+
"div",
|
|
39
|
+
{
|
|
40
|
+
"data-slot": "tag-input",
|
|
41
|
+
className: T(
|
|
42
|
+
"flex min-h-12 flex-wrap items-center gap-1.5 rounded-lg border border-input bg-background/70 px-2 py-1.5 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-disabled:opacity-60",
|
|
43
|
+
x
|
|
44
|
+
),
|
|
45
|
+
children: [
|
|
46
|
+
t.map((e) => /* @__PURE__ */ g(
|
|
47
|
+
"span",
|
|
48
|
+
{
|
|
49
|
+
"data-slot": "tag-input-tag",
|
|
50
|
+
className: "inline-flex items-center gap-1 rounded-full bg-(--accent-wash) py-0.5 pr-1 pl-2.5 text-xs font-medium",
|
|
51
|
+
children: [
|
|
52
|
+
h,
|
|
53
|
+
e,
|
|
54
|
+
!o && /* @__PURE__ */ s(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
type: "button",
|
|
58
|
+
className: "grid size-4 place-items-center rounded-full text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50",
|
|
59
|
+
"aria-label": f("tags.remove", { tag: e }),
|
|
60
|
+
onClick: () => n(t.filter((i) => i !== e)),
|
|
61
|
+
children: /* @__PURE__ */ s(y, { className: "size-3" })
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
e
|
|
67
|
+
)),
|
|
68
|
+
/* @__PURE__ */ s(
|
|
69
|
+
"input",
|
|
70
|
+
{
|
|
71
|
+
id: c,
|
|
72
|
+
list: l.length ? u : void 0,
|
|
73
|
+
className: "min-w-32 flex-1 bg-transparent px-1 py-1 text-sm outline-none placeholder:text-muted-foreground",
|
|
74
|
+
placeholder: t.length ? "" : a ?? f("tags.placeholder"),
|
|
75
|
+
value: r,
|
|
76
|
+
disabled: o,
|
|
77
|
+
onChange: (e) => {
|
|
78
|
+
l.includes(e.target.value) ? d(e.target.value) : m(e.target.value);
|
|
79
|
+
},
|
|
80
|
+
onKeyDown: b,
|
|
81
|
+
onBlur: () => r.trim() && d(r)
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
l.length > 0 && /* @__PURE__ */ s("datalist", { id: u, children: l.map((e) => /* @__PURE__ */ s("option", { value: e }, e)) })
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
E as TagInput,
|
|
91
|
+
S as normalizeTags
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/TagInput/index.tsx"],"sourcesContent":["import { X } from 'lucide-react'\nimport { type KeyboardEvent, useId, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { STOA_NS } from '../../i18n/namespace'\nimport { cn } from '../../utils/cn'\n\nexport interface TagInputProps {\n\tid?: string\n\tvalue: string[]\n\tonChange: (tags: string[]) => void\n\t/** Existing tags offered as suggestions. */\n\tsuggestions?: string[]\n\tdisabled?: boolean\n\tplaceholder?: string\n\t/** Shown before each tag, e.g. `#`. */\n\tprefix?: string\n\tclassName?: string\n}\n\n/** Trims, collapses whitespace and drops empty or case-insensitive duplicates. */\nexport function normalizeTags(value: readonly string[]) {\n\tconst seen = new Set<string>()\n\tconst tags: string[] = []\n\tfor (const item of value) {\n\t\tconst tag = item.trim().replace(/\\s+/g, ' ')\n\t\tconst key = tag.toLocaleLowerCase()\n\t\tif (!tag || seen.has(key)) continue\n\t\tseen.add(key)\n\t\ttags.push(tag)\n\t}\n\treturn tags\n}\n\n/**\n * Free-form tag list: Enter, comma or Tab adds the typed tag, Backspace in the\n * empty field removes the last one; suggestions come from a datalist.\n */\nexport function TagInput({\n\tid,\n\tvalue,\n\tonChange,\n\tsuggestions = [],\n\tdisabled,\n\tplaceholder,\n\tprefix = '#',\n\tclassName,\n}: TagInputProps) {\n\tconst { t } = useTranslation(STOA_NS)\n\tconst listId = useId()\n\tconst [text, setText] = useState('')\n\tconst add = (raw: string) => {\n\t\tconst next = normalizeTags([...value, ...raw.split(',')])\n\t\tif (next.length !== value.length) onChange(next)\n\t\tsetText('')\n\t}\n\tfunction onKeyDown(event: KeyboardEvent<HTMLInputElement>) {\n\t\t// Enter never submits the surrounding form from here.\n\t\tif (event.key === 'Enter') event.preventDefault()\n\t\tif (\n\t\t\t(event.key === 'Enter' || event.key === ',' || event.key === 'Tab') &&\n\t\t\ttext.trim()\n\t\t) {\n\t\t\tevent.preventDefault()\n\t\t\tadd(text)\n\t\t} else if (event.key === 'Backspace' && !text && value.length) {\n\t\t\tonChange(value.slice(0, -1))\n\t\t}\n\t}\n\tconst offered = suggestions.filter(\n\t\t(tag) =>\n\t\t\t!value.some(\n\t\t\t\t(item) => item.toLocaleLowerCase() === tag.toLocaleLowerCase(),\n\t\t\t),\n\t)\n\treturn (\n\t\t<div\n\t\t\tdata-slot='tag-input'\n\t\t\tclassName={cn(\n\t\t\t\t'flex min-h-12 flex-wrap items-center gap-1.5 rounded-lg border border-input bg-background/70 px-2 py-1.5 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-disabled:opacity-60',\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{value.map((tag) => (\n\t\t\t\t<span\n\t\t\t\t\tkey={tag}\n\t\t\t\t\tdata-slot='tag-input-tag'\n\t\t\t\t\tclassName='inline-flex items-center gap-1 rounded-full bg-(--accent-wash) py-0.5 pr-1 pl-2.5 text-xs font-medium'\n\t\t\t\t>\n\t\t\t\t\t{prefix}\n\t\t\t\t\t{tag}\n\t\t\t\t\t{!disabled && (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype='button'\n\t\t\t\t\t\t\tclassName='grid size-4 place-items-center rounded-full text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50'\n\t\t\t\t\t\t\taria-label={t('tags.remove', { tag })}\n\t\t\t\t\t\t\tonClick={() => onChange(value.filter((item) => item !== tag))}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<X className='size-3' />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t)}\n\t\t\t\t</span>\n\t\t\t))}\n\t\t\t<input\n\t\t\t\tid={id}\n\t\t\t\tlist={offered.length ? listId : undefined}\n\t\t\t\tclassName='min-w-32 flex-1 bg-transparent px-1 py-1 text-sm outline-none placeholder:text-muted-foreground'\n\t\t\t\tplaceholder={value.length ? '' : (placeholder ?? t('tags.placeholder'))}\n\t\t\t\tvalue={text}\n\t\t\t\tdisabled={disabled}\n\t\t\t\tonChange={(e) => {\n\t\t\t\t\t// Picking a suggestion from the datalist adds it right away.\n\t\t\t\t\tif (offered.includes(e.target.value)) add(e.target.value)\n\t\t\t\t\telse setText(e.target.value)\n\t\t\t\t}}\n\t\t\t\tonKeyDown={onKeyDown}\n\t\t\t\tonBlur={() => text.trim() && add(text)}\n\t\t\t/>\n\t\t\t{offered.length > 0 && (\n\t\t\t\t<datalist id={listId}>\n\t\t\t\t\t{offered.map((tag) => (\n\t\t\t\t\t\t<option key={tag} value={tag} />\n\t\t\t\t\t))}\n\t\t\t\t</datalist>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n"],"names":["normalizeTags","value","seen","tags","item","tag","key","TagInput","id","onChange","suggestions","disabled","placeholder","prefix","className","t","useTranslation","STOA_NS","listId","useId","text","setText","useState","add","raw","next","onKeyDown","event","offered","jsxs","cn","jsx","X"],"mappings":";;;;;;AAoBO,SAASA,EAAcC,GAA0B;AACvD,QAAMC,wBAAW,IAAA,GACXC,IAAiB,CAAA;AACvB,aAAWC,KAAQH,GAAO;AACzB,UAAMI,IAAMD,EAAK,KAAA,EAAO,QAAQ,QAAQ,GAAG,GACrCE,IAAMD,EAAI,kBAAA;AAChB,IAAI,CAACA,KAAOH,EAAK,IAAII,CAAG,MACxBJ,EAAK,IAAII,CAAG,GACZH,EAAK,KAAKE,CAAG;AAAA,EACd;AACA,SAAOF;AACR;AAMO,SAASI,EAAS;AAAA,EACxB,IAAAC;AAAA,EACA,OAAAP;AAAA,EACA,UAAAQ;AAAA,EACA,aAAAC,IAAc,CAAA;AAAA,EACd,UAAAC;AAAA,EACA,aAAAC;AAAA,EACA,QAAAC,IAAS;AAAA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AMI,EAASR,EAAM,OAAO,CAACG,MAASA,MAASC,CAAG,CAAC;AAAA,kBAE5D,UAAA,gBAAA0B,EAACC,GAAA,EAAE,WAAU,SAAA,CAAS;AAAA,gBAAA;AAAA,cAAA;AAAA,YACvB;AAAA,UAAA;AAAA,UAdI3B;AAAA,QAAA,CAiBN;AAAA,QACD,gBAAA0B;AAAA,UAAC;AAAA,UAAA;AAAA,YACA,IAAAvB;AAAA,YACA,MAAMoB,EAAQ,SAASV,IAAS;AAAA,YAChC,WAAU;AAAA,YACV,aAAajB,EAAM,SAAS,KAAMW,KAAeG,EAAE,kBAAkB;AAAA,YACrE,OAAOK;AAAA,YACP,UAAAT;AAAA,YACA,UAAU,CAAC,MAAM;AAEhB,cAAIiB,EAAQ,SAAS,EAAE,OAAO,KAAK,IAAGL,EAAI,EAAE,OAAO,KAAK,IACnDF,EAAQ,EAAE,OAAO,KAAK;AAAA,YAC5B;AAAA,YACA,WAAAK;AAAA,YACA,QAAQ,MAAMN,EAAK,KAAA,KAAUG,EAAIH,CAAI;AAAA,UAAA;AAAA,QAAA;AAAA,QAErCQ,EAAQ,SAAS,KACjB,gBAAAG,EAAC,YAAA,EAAS,IAAIb,GACZ,UAAAU,EAAQ,IAAI,CAACvB,MACb,gBAAA0B,EAAC,UAAA,EAAiB,OAAO1B,EAAA,GAAZA,CAAiB,CAC9B,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIJ;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { useState as f } from "react";
|
|
3
|
+
import { Input as s } from "../../ui/input/index.js";
|
|
4
|
+
function c(r, t, e) {
|
|
5
|
+
if (r)
|
|
6
|
+
return e ? "error" : t ? "warning" : "required";
|
|
7
|
+
}
|
|
8
|
+
function g({
|
|
9
|
+
problem: r,
|
|
10
|
+
submitted: t = !1,
|
|
11
|
+
onBlur: e,
|
|
12
|
+
...o
|
|
13
|
+
}) {
|
|
14
|
+
const [i, a] = f(!1), n = c(r, i, t);
|
|
15
|
+
return /* @__PURE__ */ d(
|
|
16
|
+
s,
|
|
17
|
+
{
|
|
18
|
+
...o,
|
|
19
|
+
"data-field-state": n,
|
|
20
|
+
"aria-invalid": n === "warning" || n === "error",
|
|
21
|
+
onBlur: (u) => {
|
|
22
|
+
a(!0), e?.(u);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
g as ValidatedInput,
|
|
29
|
+
c as fieldFeedback
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/shell/ValidatedInput/index.tsx"],"sourcesContent":["import { type ComponentProps, useState } from 'react'\nimport { Input } from '../../ui/input'\n\nexport type FieldFeedback = 'required' | 'warning' | 'error' | undefined\n\n/**\n * How loudly a field problem is shown: quietly before the first blur,\n * as a warning once touched, as an error after a submit attempt.\n */\nexport function fieldFeedback(\n\tproblem: boolean,\n\ttouched: boolean,\n\tsubmitted: boolean,\n): FieldFeedback {\n\tif (!problem) return undefined\n\treturn submitted ? 'error' : touched ? 'warning' : 'required'\n}\n\nexport type ValidatedInputProps = ComponentProps<typeof Input> & {\n\t/** The current value is invalid or missing. */\n\tproblem: boolean\n\t/** A submit was attempted; problems are shown as errors. */\n\tsubmitted?: boolean\n}\n\n/** Input that only flags a problem once the user has left the field. */\nexport function ValidatedInput({\n\tproblem,\n\tsubmitted = false,\n\tonBlur,\n\t...props\n}: ValidatedInputProps) {\n\tconst [touched, setTouched] = useState(false)\n\tconst state = fieldFeedback(problem, touched, submitted)\n\treturn (\n\t\t<Input\n\t\t\t{...props}\n\t\t\tdata-field-state={state}\n\t\t\taria-invalid={state === 'warning' || state === 'error'}\n\t\t\tonBlur={(event) => {\n\t\t\t\tsetTouched(true)\n\t\t\t\tonBlur?.(event)\n\t\t\t}}\n\t\t/>\n\t)\n}\n"],"names":["fieldFeedback","problem","touched","submitted","ValidatedInput","onBlur","props","setTouched","useState","state","jsx","Input","event"],"mappings":";;;AASO,SAASA,EACfC,GACAC,GACAC,GACgB;AAChB,MAAKF;AACL,WAAOE,IAAY,UAAUD,IAAU,YAAY;AACpD;AAUO,SAASE,EAAe;AAAA,EAC9B,SAAAH;AAAA,EACA,WAAAE,IAAY;AAAA,EACZ,QAAAE;AAAA,EACA,GAAGC;AACJ,GAAwB;AACvB,QAAM,CAACJ,GAASK,CAAU,IAAIC,EAAS,EAAK,GACtCC,IAAQT,EAAcC,GAASC,GAASC,CAAS;AACvD,SACC,gBAAAO;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,GAAGL;AAAA,MACJ,oBAAkBG;AAAA,MAClB,gBAAcA,MAAU,aAAaA,MAAU;AAAA,MAC/C,QAAQ,CAACG,MAAU;AAClB,QAAAL,EAAW,EAAI,GACfF,IAASO,CAAK;AAAA,MACf;AAAA,IAAA;AAAA,EAAA;AAGH;"}
|