@cosmicdrift/kumiko-renderer 0.406.0 → 0.409.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/action-form-body.js +23 -8
- package/dist/app/action-form-support.d.ts +7 -0
- package/dist/app/action-form-support.js +14 -1
- package/dist/app/config-edit-action-row.d.ts +7 -0
- package/dist/app/config-edit-action-row.js +45 -0
- package/dist/app/config-edit-body.js +32 -4
- package/dist/app/entity-list-screen.js +8 -11
- package/dist/app/nav.js +2 -1
- package/dist/app/projection-detail-body.js +3 -1
- package/dist/app/projection-detail-header.d.ts +1 -0
- package/dist/app/projection-detail-header.js +1 -1
- package/dist/app/projection-detail-navigation.d.ts +2 -1
- package/dist/app/projection-detail-navigation.js +6 -3
- package/dist/app/projection-detail-shim.js +3 -1
- package/dist/app/projection-list-render-props.d.ts +1 -1
- package/dist/app/projection-list-render-props.js +4 -2
- package/dist/app/projection-list-render.js +1 -1
- package/dist/app/screen-access.js +4 -2
- package/dist/app/screen-shared.d.ts +3 -2
- package/dist/app/screen-shared.js +29 -1
- package/dist/app/use-embedded-screen.d.ts +2 -0
- package/dist/app/use-embedded-screen.js +7 -1
- package/dist/components/edit-mounts.d.ts +3 -1
- package/dist/components/edit-mounts.js +3 -3
- package/dist/components/related-list-section.d.ts +3 -1
- package/dist/components/related-list-section.js +2 -2
- package/dist/components/render-edit-field-grid.d.ts +2 -2
- package/dist/components/render-edit-field-grid.js +12 -4
- package/dist/components/render-edit-fields-section.js +6 -7
- package/dist/components/render-edit-helpers.d.ts +4 -0
- package/dist/components/render-edit-helpers.js +5 -0
- package/dist/components/render-edit-section-kinds.js +6 -4
- package/dist/components/render-edit-submit.js +18 -1
- package/dist/components/render-edit-titles.js +6 -6
- package/dist/components/render-edit-types.d.ts +6 -0
- package/dist/components/render-field-control.d.ts +2 -0
- package/dist/components/render-field-control.js +23 -1
- package/dist/components/render-field-write-only.d.ts +1 -1
- package/dist/components/render-field-write-only.js +12 -2
- package/dist/components/render-field.js +2 -1
- package/dist/components/use-render-edit-sections.js +4 -4
- package/dist/format-when.d.ts +1 -1
- package/dist/format-when.js +2 -2
- package/dist/headless/format/escape.js +3 -2
- package/dist/headless/view-model/edit.js +0 -2
- package/dist/headless/view-model/types.d.ts +0 -3
- package/dist/i18n-defaults.js +38 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/primitives.d.ts +30 -7
- package/dist/primitives.js +1 -51
- package/dist/status-tone.d.ts +6 -0
- package/dist/status-tone.js +51 -0
- package/dist/toggle-set-member.d.ts +1 -0
- package/dist/toggle-set-member.js +8 -0
- package/dist/web/app/dashboard-header.js +5 -1
- package/dist/web/app/dashboard-screen-tiles.js +19 -3
- package/dist/web/icons.d.ts +2 -0
- package/dist/web/icons.js +3 -1
- package/dist/web/index.d.ts +3 -2
- package/dist/web/index.js +2 -1
- package/dist/web/layout/default-app-shell.d.ts +4 -1
- package/dist/web/layout/default-app-shell.js +5 -2
- package/dist/web/layout/focus-aware-sidebar.d.ts +27 -0
- package/dist/web/layout/focus-aware-sidebar.js +23 -0
- package/dist/web/layout/focus-rail.d.ts +16 -0
- package/dist/web/layout/focus-rail.js +61 -0
- package/dist/web/layout/nav-tree.d.ts +2 -1
- package/dist/web/layout/nav-tree.js +3 -9
- package/dist/web/layout/shell-focus.d.ts +19 -0
- package/dist/web/layout/shell-focus.js +35 -0
- package/dist/web/layout/shell-header.d.ts +1 -1
- package/dist/web/layout/shell-header.js +12 -9
- package/dist/web/layout/sidebar-brand.js +1 -1
- package/dist/web/layout/workspace-shell.d.ts +4 -1
- package/dist/web/layout/workspace-shell.js +5 -2
- package/dist/web/primitives/banner.js +3 -1
- package/dist/web/primitives/data-table/toolbar.js +2 -2
- package/dist/web/primitives/default-form.js +12 -5
- package/dist/web/primitives/field.js +4 -1
- package/dist/web/primitives/input-text-kinds.js +8 -2
- package/dist/web/primitives/layout-elements.js +2 -4
- package/dist/web/primitives/tabs.d.ts +1 -1
- package/dist/web/primitives/tabs.js +21 -4
- package/dist/web/theme-plugin.d.ts +1 -1
- package/dist/web/theme-plugin.js +7 -0
- package/dist/web/ui/sidebar.js +5 -2
- package/dist/web/widgets/ai-text-end-action.d.ts +12 -0
- package/dist/web/widgets/ai-text-end-action.js +15 -0
- package/dist/web/widgets/ai-text-field.d.ts +3 -0
- package/dist/web/widgets/ai-text-field.js +4 -3
- package/dist/web/widgets/attachment-card.d.ts +6 -0
- package/dist/web/widgets/attachment-card.js +11 -0
- package/dist/web/widgets/attachment-chip.d.ts +8 -0
- package/dist/web/widgets/attachment-chip.js +21 -0
- package/dist/web/widgets/clamped-text.d.ts +11 -0
- package/dist/web/widgets/clamped-text.js +38 -0
- package/dist/web/widgets/html-mail-frame.d.ts +17 -0
- package/dist/web/widgets/html-mail-frame.js +56 -0
- package/dist/web/widgets/index.d.ts +10 -1
- package/dist/web/widgets/index.js +9 -1
- package/dist/web/widgets/infinity-list.d.ts +3 -1
- package/dist/web/widgets/infinity-list.js +2 -2
- package/dist/web/widgets/message-body-view.d.ts +10 -0
- package/dist/web/widgets/message-body-view.js +36 -0
- package/dist/web/widgets/message-reader.d.ts +4 -0
- package/dist/web/widgets/message-reader.js +31 -0
- package/dist/web/widgets/message-thread.d.ts +5 -0
- package/dist/web/widgets/message-thread.js +66 -0
- package/dist/web/widgets/message-types.d.ts +68 -0
- package/dist/web/widgets/message-types.js +1 -0
- package/dist/web/widgets/mobile-top-bar.d.ts +21 -0
- package/dist/web/widgets/mobile-top-bar.js +8 -0
- package/dist/web/widgets/pdf-document.d.ts +19 -0
- package/dist/web/widgets/pdf-document.js +70 -0
- package/dist/web/widgets/pdf-page.d.ts +35 -0
- package/dist/web/widgets/pdf-page.js +155 -0
- package/dist/web/widgets/pdf-preview.d.ts +27 -7
- package/dist/web/widgets/pdf-preview.js +21 -133
- package/dist/web/widgets/pdf-search.d.ts +43 -0
- package/dist/web/widgets/pdf-search.js +178 -0
- package/dist/web/widgets/pdf-thumbnails.d.ts +10 -0
- package/dist/web/widgets/pdf-thumbnails.js +35 -0
- package/dist/web/widgets/pdf-viewer-toolbar.d.ts +22 -0
- package/dist/web/widgets/pdf-viewer-toolbar.js +35 -0
- package/dist/web/widgets/pdf-viewer.d.ts +21 -0
- package/dist/web/widgets/pdf-viewer.js +176 -0
- package/dist/web/widgets/quoted-text.d.ts +16 -0
- package/dist/web/widgets/quoted-text.js +76 -0
- package/dist/web/widgets/status-badge.js +3 -1
- package/dist/web/widgets/step-list-fit.d.ts +25 -0
- package/dist/web/widgets/step-list-fit.js +79 -0
- package/dist/web/widgets/step-list-row.d.ts +50 -0
- package/dist/web/widgets/step-list-row.js +97 -0
- package/dist/web/widgets/step-list.d.ts +33 -0
- package/dist/web/widgets/step-list.js +36 -0
- package/dist/web/widgets/surfaces.d.ts +23 -0
- package/dist/web/widgets/surfaces.js +15 -0
- package/dist/web/widgets/use-in-view.d.ts +5 -0
- package/dist/web/widgets/use-in-view.js +18 -0
- package/package.json +5 -5
- package/src/changes.json +186 -0
- package/src/web/styles.css +22 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown, ChevronUp, Search } from "lucide-react";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { usePrimitives, useTranslation } from "../../index.js";
|
|
5
|
+
const INPUT_CLASS = "h-[26px] rounded border border-input bg-transparent px-1.5 text-center text-sm text-foreground";
|
|
6
|
+
// Bordered like the page input beside them, so the toolbar reads as controls of the document.
|
|
7
|
+
const TOOL_BUTTON_CLASS = "size-7";
|
|
8
|
+
function PageNumberInput({ currentPage, onGoToPage, }) {
|
|
9
|
+
const t = useTranslation();
|
|
10
|
+
const [draft, setDraft] = useState(String(currentPage));
|
|
11
|
+
useEffect(() => setDraft(String(currentPage)), [currentPage]);
|
|
12
|
+
return (_jsxs("label", { className: "flex items-center gap-1.5", children: [t("kumiko.widget.pdf-preview.page"), _jsx("input", { type: "text", inputMode: "numeric", "aria-label": t("kumiko.widget.pdf-preview.pageInput"), className: `${INPUT_CLASS} w-9`, value: draft, onChange: (event) => setDraft(event.target.value), onBlur: () => setDraft(String(currentPage)), onKeyDown: (event) => {
|
|
13
|
+
if (event.key === "Enter")
|
|
14
|
+
onGoToPage(Number.parseInt(draft, 10));
|
|
15
|
+
} })] }));
|
|
16
|
+
}
|
|
17
|
+
function SearchControls({ search, onTermChange, onStepMatch, }) {
|
|
18
|
+
const t = useTranslation();
|
|
19
|
+
const { Button } = usePrimitives();
|
|
20
|
+
const hasTerm = search.term.trim() !== "";
|
|
21
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { type: "search", "aria-label": t("kumiko.widget.pdf-preview.search"), className: `${INPUT_CLASS} w-40 text-left`, value: search.term, onChange: (event) => onTermChange(event.target.value), onKeyDown: (event) => {
|
|
22
|
+
if (event.key === "Enter")
|
|
23
|
+
onStepMatch(event.shiftKey ? -1 : 1);
|
|
24
|
+
} }), hasTerm && (_jsx("span", { className: "whitespace-nowrap text-muted-foreground", "data-testid": "pdf-match-count", children: search.matchCount === 0
|
|
25
|
+
? t("kumiko.widget.pdf-preview.noMatch")
|
|
26
|
+
: t("kumiko.widget.pdf-preview.matchCount", {
|
|
27
|
+
index: search.matchIndex + 1,
|
|
28
|
+
total: search.matchCount,
|
|
29
|
+
}) })), _jsx(Button, { size: "sm", variant: "ghost", ariaLabel: t("kumiko.widget.pdf-preview.previousMatch"), disabled: search.matchCount === 0, onClick: () => onStepMatch(-1), children: _jsx(ChevronUp, { "aria-hidden": "true", className: "size-4" }) }), _jsx(Button, { size: "sm", variant: "ghost", ariaLabel: t("kumiko.widget.pdf-preview.nextMatch"), disabled: search.matchCount === 0, onClick: () => onStepMatch(1), children: _jsx(ChevronDown, { "aria-hidden": "true", className: "size-4" }) })] }));
|
|
30
|
+
}
|
|
31
|
+
export function PdfViewerToolbar(props) {
|
|
32
|
+
const t = useTranslation();
|
|
33
|
+
const { Button } = usePrimitives();
|
|
34
|
+
return (_jsxs("div", { "data-testid": "pdf-toolbar", className: "flex h-10 shrink-0 items-center gap-2 border-b border-border bg-card px-2.5 text-[13px]", children: [_jsx(PageNumberInput, { currentPage: props.currentPage, onGoToPage: props.onGoToPage }), _jsx("span", { className: "text-muted-foreground", children: t("kumiko.widget.pdf-preview.pageCount", { pages: props.pageCount }) }), _jsx("span", { className: "grow" }), props.search.open && props.hideSearch !== true && (_jsx(SearchControls, { search: props.search, onTermChange: props.onTermChange, onStepMatch: props.onStepMatch })), _jsx(Button, { size: "icon", variant: "secondary", className: TOOL_BUTTON_CLASS, ariaLabel: t("kumiko.widget.pdf-preview.zoomOut"), onClick: props.onZoomOut, children: "\u2212" }), _jsxs("span", { className: "min-w-11 whitespace-nowrap text-center text-muted-foreground", "data-testid": "pdf-zoom", children: [Math.round(props.zoom * 100), " %"] }), _jsx(Button, { size: "icon", variant: "secondary", className: TOOL_BUTTON_CLASS, ariaLabel: t("kumiko.widget.pdf-preview.zoomIn"), onClick: props.onZoomIn, children: "+" }), props.hideSearch !== true && (_jsx(Button, { size: "icon", variant: "secondary", className: TOOL_BUTTON_CLASS, pressed: props.search.open, ariaLabel: t("kumiko.widget.pdf-preview.search"), onClick: props.onToggleSearch, children: _jsx(Search, { "aria-hidden": "true", className: "size-3.5" }) }))] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PDFDocumentProxy } from "pdfjs-dist";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { type PdfMatchInfo } from "./pdf-search.ts";
|
|
4
|
+
/** Thumbnail rail, toolbar (page jump, zoom, search) and lazily rendered pages on a sand frame;
|
|
5
|
+
* `pagesOnly` keeps just the pages on the frame. */
|
|
6
|
+
export declare function PdfViewer({ document, searchTerm, initialPage, onPageChange, matchIndex: controlledMatchIndex, onMatchesChange, hideSearchBar, markTerm, fill, pagesOnly, }: {
|
|
7
|
+
readonly document: PDFDocumentProxy;
|
|
8
|
+
readonly searchTerm?: string;
|
|
9
|
+
readonly initialPage?: number;
|
|
10
|
+
readonly onPageChange?: (page: number) => void;
|
|
11
|
+
/** 0-based active match; makes stepping host-controlled (the viewer scrolls to and marks that hit). */
|
|
12
|
+
readonly matchIndex?: number;
|
|
13
|
+
readonly onMatchesChange?: (info: PdfMatchInfo) => void;
|
|
14
|
+
/** Hides the toolbar's search toggle and controls, for hosts that render their own. */
|
|
15
|
+
readonly hideSearchBar?: boolean;
|
|
16
|
+
/** Marks a passage, e.g. the clause a step was read from, without opening the search; the toolbar search stays usable and wins while it has a term. */
|
|
17
|
+
readonly markTerm?: string;
|
|
18
|
+
readonly fill?: boolean;
|
|
19
|
+
/** Only the pages on the frame, without thumbnail rail and toolbar, for hosts that step through the hits themselves. */
|
|
20
|
+
readonly pagesOnly?: boolean;
|
|
21
|
+
}): ReactNode;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { pageTextItemsFor } from "./pdf-document.js";
|
|
5
|
+
import { PdfPageSlot, useFirstPageSize } from "./pdf-page.js";
|
|
6
|
+
import { clampPage, findMatches, mostVisiblePage, } from "./pdf-search.js";
|
|
7
|
+
import { PdfThumbnails } from "./pdf-thumbnails.js";
|
|
8
|
+
import { PdfViewerToolbar } from "./pdf-viewer-toolbar.js";
|
|
9
|
+
const ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3];
|
|
10
|
+
const DEFAULT_ZOOM_INDEX = ZOOM_STEPS.indexOf(1);
|
|
11
|
+
const VISIBILITY_THRESHOLDS = [0, 0.25, 0.5, 0.75, 1];
|
|
12
|
+
function pageSlotFor(scroller, page) {
|
|
13
|
+
return scroller?.querySelector(`[data-pdf-page="${page}"]`) ?? null;
|
|
14
|
+
}
|
|
15
|
+
function useCurrentPage(pageCount, initialPage, onPageChange) {
|
|
16
|
+
const [currentPage, setCurrentPage] = useState(clampPage(initialPage, pageCount));
|
|
17
|
+
const latest = useRef({ currentPage, onPageChange });
|
|
18
|
+
latest.current = { currentPage, onPageChange };
|
|
19
|
+
const commitPage = useCallback((page) => {
|
|
20
|
+
if (page === latest.current.currentPage)
|
|
21
|
+
return;
|
|
22
|
+
latest.current = { ...latest.current, currentPage: page };
|
|
23
|
+
setCurrentPage(page);
|
|
24
|
+
latest.current.onPageChange?.(page);
|
|
25
|
+
}, []);
|
|
26
|
+
return { currentPage, commitPage };
|
|
27
|
+
}
|
|
28
|
+
/** Height a whole page may take inside the scroller's padding; undefined unless `enabled`. */
|
|
29
|
+
function useScrollerContentHeight(scrollerRef, enabled) {
|
|
30
|
+
const [height, setHeight] = useState(undefined);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const scroller = scrollerRef.current;
|
|
33
|
+
if (!enabled || scroller === null)
|
|
34
|
+
return undefined;
|
|
35
|
+
// Padding is read from the computed style: the root font size, and so p-5, differs per app.
|
|
36
|
+
const measure = () => {
|
|
37
|
+
const style = getComputedStyle(scroller);
|
|
38
|
+
const padding = (Number.parseFloat(style.paddingTop) || 0) + (Number.parseFloat(style.paddingBottom) || 0);
|
|
39
|
+
setHeight(scroller.clientHeight - padding);
|
|
40
|
+
};
|
|
41
|
+
measure();
|
|
42
|
+
const observer = new ResizeObserver(measure);
|
|
43
|
+
observer.observe(scroller);
|
|
44
|
+
return () => {
|
|
45
|
+
observer.disconnect();
|
|
46
|
+
setHeight(undefined);
|
|
47
|
+
};
|
|
48
|
+
}, [scrollerRef, enabled]);
|
|
49
|
+
return height;
|
|
50
|
+
}
|
|
51
|
+
function useVisiblePageTracking(scrollerRef, onVisiblePage) {
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const scroller = scrollerRef.current;
|
|
54
|
+
if (scroller === null || typeof IntersectionObserver === "undefined")
|
|
55
|
+
return undefined;
|
|
56
|
+
const ratios = new Map();
|
|
57
|
+
const observer = new IntersectionObserver((entries) => {
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
const page = Number(entry.target.getAttribute("data-pdf-page"));
|
|
60
|
+
ratios.set(page, entry.intersectionRatio);
|
|
61
|
+
}
|
|
62
|
+
const page = mostVisiblePage(ratios);
|
|
63
|
+
if (page !== null)
|
|
64
|
+
onVisiblePage(page);
|
|
65
|
+
}, { root: scroller, threshold: VISIBILITY_THRESHOLDS });
|
|
66
|
+
for (const slot of scroller.querySelectorAll("[data-pdf-page]"))
|
|
67
|
+
observer.observe(slot);
|
|
68
|
+
return () => observer.disconnect();
|
|
69
|
+
}, [scrollerRef, onVisiblePage]);
|
|
70
|
+
}
|
|
71
|
+
function usePageTexts(document, wanted) {
|
|
72
|
+
const [pageTexts, setPageTexts] = useState(null);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!wanted)
|
|
75
|
+
return undefined;
|
|
76
|
+
let cancelled = false;
|
|
77
|
+
void pageTextItemsFor(document)
|
|
78
|
+
.then((texts) => {
|
|
79
|
+
if (!cancelled)
|
|
80
|
+
setPageTexts(texts);
|
|
81
|
+
})
|
|
82
|
+
.catch(() => undefined);
|
|
83
|
+
return () => {
|
|
84
|
+
cancelled = true;
|
|
85
|
+
};
|
|
86
|
+
}, [document, wanted]);
|
|
87
|
+
return pageTexts;
|
|
88
|
+
}
|
|
89
|
+
/** A term counts as searched once the search is visible to the reader or driven by the host. */
|
|
90
|
+
function highlightTermsOf(input) {
|
|
91
|
+
const searched = input.searchVisible ? input.term.trim() : "";
|
|
92
|
+
return { searched, highlight: searched === "" ? input.markTerm.trim() : searched };
|
|
93
|
+
}
|
|
94
|
+
/** The search term wins over the passage mark; only the searched page with the active hit gets an ordinal. */
|
|
95
|
+
function pageHighlightOf(pageNumber, terms, activeMatch) {
|
|
96
|
+
if (terms.highlight === "")
|
|
97
|
+
return null;
|
|
98
|
+
const isSearch = terms.searched !== "";
|
|
99
|
+
return {
|
|
100
|
+
term: terms.highlight,
|
|
101
|
+
source: !isSearch,
|
|
102
|
+
activeOrdinal: isSearch && activeMatch?.page === pageNumber ? activeMatch.ordinalOnPage : null,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Thumbnail rail, toolbar (page jump, zoom, search) and lazily rendered pages on a sand frame;
|
|
106
|
+
* `pagesOnly` keeps just the pages on the frame. */
|
|
107
|
+
export function PdfViewer({ document, searchTerm = "", initialPage = 1, onPageChange, matchIndex: controlledMatchIndex, onMatchesChange, hideSearchBar = false, markTerm = "", fill = false, pagesOnly = false, }) {
|
|
108
|
+
const pageCount = document.numPages;
|
|
109
|
+
const firstPageSize = useFirstPageSize(document);
|
|
110
|
+
const scrollerRef = useRef(null);
|
|
111
|
+
const { currentPage, commitPage } = useCurrentPage(pageCount, initialPage, onPageChange);
|
|
112
|
+
const [zoomIndex, setZoomIndex] = useState(DEFAULT_ZOOM_INDEX);
|
|
113
|
+
const [searchOpen, setSearchOpen] = useState(searchTerm !== "");
|
|
114
|
+
const [term, setTerm] = useState(searchTerm);
|
|
115
|
+
const [internalMatchIndex, setMatchIndex] = useState(0);
|
|
116
|
+
const matchIndex = controlledMatchIndex ?? internalMatchIndex;
|
|
117
|
+
const zoom = ZOOM_STEPS[zoomIndex] ?? 1;
|
|
118
|
+
const fitHeight = useScrollerContentHeight(scrollerRef, pagesOnly);
|
|
119
|
+
const pageTexts = usePageTexts(document, searchOpen && term.trim() !== "");
|
|
120
|
+
const matches = useMemo(() => (pageTexts === null || term.trim() === "" ? [] : findMatches(pageTexts, term)), [pageTexts, term]);
|
|
121
|
+
const clampedMatchIndex = Math.min(matchIndex, Math.max(0, matches.length - 1));
|
|
122
|
+
const activeMatch = matches[clampedMatchIndex];
|
|
123
|
+
const reportMatches = useEffectEvent((info) => onMatchesChange?.(info));
|
|
124
|
+
const matchCount = matches.length;
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
reportMatches({ count: matchCount, index: clampedMatchIndex });
|
|
127
|
+
}, [matchCount, clampedMatchIndex]);
|
|
128
|
+
// The opening page keeps its top in view while the layout settles, until the reader goes elsewhere.
|
|
129
|
+
const [leftPage, setLeftPage] = useState(null);
|
|
130
|
+
const goToPage = useCallback((page) => {
|
|
131
|
+
const target = clampPage(page, pageCount);
|
|
132
|
+
setLeftPage(initialPage);
|
|
133
|
+
commitPage(target);
|
|
134
|
+
pageSlotFor(scrollerRef.current, target)?.scrollIntoView({ block: "start" });
|
|
135
|
+
}, [pageCount, commitPage, initialPage]);
|
|
136
|
+
useVisiblePageTracking(scrollerRef, commitPage);
|
|
137
|
+
const activePage = activeMatch?.page;
|
|
138
|
+
// matchIndex and term are passed only so the effect refires when stepping between matches on one page or changing the term.
|
|
139
|
+
const jumpToMatch = useEffectEvent((target) => {
|
|
140
|
+
if (target.page !== undefined)
|
|
141
|
+
goToPage(target.page);
|
|
142
|
+
});
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
jumpToMatch({ page: activePage, matchIndex, term });
|
|
145
|
+
}, [activePage, matchIndex, term]);
|
|
146
|
+
const stepMatch = (direction) => {
|
|
147
|
+
if (matches.length === 0)
|
|
148
|
+
return;
|
|
149
|
+
setMatchIndex((index) => (index + direction + matches.length) % matches.length);
|
|
150
|
+
};
|
|
151
|
+
const terms = highlightTermsOf({
|
|
152
|
+
term,
|
|
153
|
+
markTerm,
|
|
154
|
+
searchVisible: searchOpen || hideSearchBar || pagesOnly,
|
|
155
|
+
});
|
|
156
|
+
const anchorPage = terms.searched === "" && initialPage > 1 && leftPage !== initialPage
|
|
157
|
+
? clampPage(initialPage, pageCount)
|
|
158
|
+
: null;
|
|
159
|
+
return (_jsxs("div", { "data-testid": "pdf-viewer", className: cn("flex h-full overflow-hidden rounded-md border border-border", fill ? "min-h-0" : "min-h-[480px]"), children: [!pagesOnly && (_jsx(PdfThumbnails, { document: document, firstPageSize: firstPageSize, currentPage: currentPage, onSelect: goToPage })), _jsxs("div", { className: "flex min-w-0 grow flex-col bg-sender-frame", children: [!pagesOnly && (_jsx(PdfViewerToolbar, { currentPage: currentPage, pageCount: pageCount, onGoToPage: goToPage, zoom: zoom, onZoomOut: () => setZoomIndex((index) => Math.max(0, index - 1)), onZoomIn: () => setZoomIndex((index) => Math.min(ZOOM_STEPS.length - 1, index + 1)), search: {
|
|
160
|
+
open: searchOpen,
|
|
161
|
+
term,
|
|
162
|
+
matchCount: matches.length,
|
|
163
|
+
matchIndex: clampedMatchIndex,
|
|
164
|
+
}, onToggleSearch: () => setSearchOpen((open) => !open), onTermChange: (next) => {
|
|
165
|
+
setTerm(next);
|
|
166
|
+
setMatchIndex(0);
|
|
167
|
+
}, onStepMatch: stepMatch, hideSearch: hideSearchBar })), _jsx("div", { ref: scrollerRef, className: "min-h-0 grow scroll-pt-5 overflow-auto p-5", children: _jsx("div", { "data-testid": "pdf-pages",
|
|
168
|
+
// w-max would size the column to the unshrunk page, so the fit-to-width measurement could never be smaller than the page.
|
|
169
|
+
className: cn("mx-auto flex flex-col gap-3", zoom > 1 ? "w-max min-w-full" : "w-full"), children: Array.from({ length: pageCount }, (_, index) => index + 1).map((pageNumber) => (_jsx(PdfPageSlot, { document: document, pageNumber: pageNumber, firstPageSize: firstPageSize, layout: {
|
|
170
|
+
variant: "viewer",
|
|
171
|
+
zoom,
|
|
172
|
+
highlight: pageHighlightOf(pageNumber, terms, activeMatch),
|
|
173
|
+
anchorTop: pageNumber === anchorPage,
|
|
174
|
+
...(fitHeight !== undefined && { fitHeight }),
|
|
175
|
+
} }, pageNumber))) }) })] })] }));
|
|
176
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type QuotedTextSplit = {
|
|
2
|
+
readonly main: string;
|
|
3
|
+
readonly quoted: string | null;
|
|
4
|
+
readonly quotedLineCount: number;
|
|
5
|
+
};
|
|
6
|
+
/** Folds everything from the first reply attribution, "Original Message" rule or trailing ">" block into `quoted`. */
|
|
7
|
+
export declare function splitQuotedText(text: string): QuotedTextSplit;
|
|
8
|
+
export type QuotedHtmlSplit = {
|
|
9
|
+
readonly main: string;
|
|
10
|
+
readonly quoted: string | null;
|
|
11
|
+
readonly quotedLineCount: number;
|
|
12
|
+
};
|
|
13
|
+
/** Cuts the first quote container and its following siblings out of the body; browser only. */
|
|
14
|
+
export declare function splitQuotedHtml(html: string): QuotedHtmlSplit;
|
|
15
|
+
export declare function hasRemoteImages(html: string): boolean;
|
|
16
|
+
export declare function plainTextOfHtml(html: string): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const ATTRIBUTION_LINE = /^(Am|On) .+(schrieb|wrote).*:\s*$/;
|
|
2
|
+
const ORIGINAL_MESSAGE_LINE = /^-{3,}\s*(Original Message|Ursprüngliche Nachricht)\s*-{3,}\s*$/i;
|
|
3
|
+
const QUOTE_MARK_LINE = /^\s*>/;
|
|
4
|
+
function startOfTrailingQuoteBlock(lines) {
|
|
5
|
+
let end = lines.length;
|
|
6
|
+
while (end > 0 && (lines[end - 1] ?? "").trim() === "")
|
|
7
|
+
end--;
|
|
8
|
+
let start = end;
|
|
9
|
+
while (start > 0 && QUOTE_MARK_LINE.test(lines[start - 1] ?? ""))
|
|
10
|
+
start--;
|
|
11
|
+
return start === end ? -1 : start;
|
|
12
|
+
}
|
|
13
|
+
function startOfQuote(lines) {
|
|
14
|
+
const marked = lines.findIndex((line) => ATTRIBUTION_LINE.test(line.trim()) || ORIGINAL_MESSAGE_LINE.test(line.trim()));
|
|
15
|
+
return marked >= 0 ? marked : startOfTrailingQuoteBlock(lines);
|
|
16
|
+
}
|
|
17
|
+
function countNonBlankLines(text) {
|
|
18
|
+
return text.split("\n").filter((line) => line.trim() !== "").length;
|
|
19
|
+
}
|
|
20
|
+
/** Folds everything from the first reply attribution, "Original Message" rule or trailing ">" block into `quoted`. */
|
|
21
|
+
export function splitQuotedText(text) {
|
|
22
|
+
const lines = text.split(/\r?\n/);
|
|
23
|
+
const start = startOfQuote(lines);
|
|
24
|
+
const main = start > 0 ? lines.slice(0, start).join("\n").trimEnd() : "";
|
|
25
|
+
// A mail that is nothing but quote stays visible as it is.
|
|
26
|
+
if (start < 0 || main === "")
|
|
27
|
+
return { main: text, quoted: null, quotedLineCount: 0 };
|
|
28
|
+
const quoted = lines.slice(start).join("\n").trimEnd();
|
|
29
|
+
return { main, quoted, quotedLineCount: countNonBlankLines(quoted) };
|
|
30
|
+
}
|
|
31
|
+
const HTML_QUOTE_SELECTOR = 'blockquote[type="cite"], .gmail_quote, .moz-cite-prefix, .yahoo_quoted, #divRplyFwdMsg, #appendonsend';
|
|
32
|
+
function parseHtmlBody(html) {
|
|
33
|
+
if (typeof DOMParser === "undefined")
|
|
34
|
+
return null;
|
|
35
|
+
return new DOMParser().parseFromString(html, "text/html").body;
|
|
36
|
+
}
|
|
37
|
+
function isBlankTail(node) {
|
|
38
|
+
return (node.nodeName === "BR" || (node.nodeName === "#text" && (node.textContent ?? "").trim() === ""));
|
|
39
|
+
}
|
|
40
|
+
// Gmail puts a <br> between the reply and its quote; once the quote is folded away it
|
|
41
|
+
// would only leave an empty line under the signature.
|
|
42
|
+
function dropTrailingBlanks(body) {
|
|
43
|
+
for (let node = body.lastChild; node !== null && isBlankTail(node); node = body.lastChild) {
|
|
44
|
+
node.remove();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Cuts the first quote container and its following siblings out of the body; browser only. */
|
|
48
|
+
export function splitQuotedHtml(html) {
|
|
49
|
+
const body = parseHtmlBody(html);
|
|
50
|
+
const marker = body?.querySelector(HTML_QUOTE_SELECTOR) ?? null;
|
|
51
|
+
if (body === null || marker === null)
|
|
52
|
+
return { main: html, quoted: null, quotedLineCount: 0 };
|
|
53
|
+
const quotedNodes = [];
|
|
54
|
+
for (let node = marker; node !== null; node = node.nextElementSibling) {
|
|
55
|
+
quotedNodes.push(node);
|
|
56
|
+
}
|
|
57
|
+
const quoted = quotedNodes.map((node) => node.outerHTML).join("");
|
|
58
|
+
const quotedText = quotedNodes.map((node) => node.textContent ?? "").join("\n");
|
|
59
|
+
for (const node of quotedNodes)
|
|
60
|
+
node.remove();
|
|
61
|
+
dropTrailingBlanks(body);
|
|
62
|
+
return {
|
|
63
|
+
main: body.innerHTML,
|
|
64
|
+
quoted,
|
|
65
|
+
quotedLineCount: Math.max(1, countNonBlankLines(quotedText)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function hasRemoteImages(html) {
|
|
69
|
+
const body = parseHtmlBody(html);
|
|
70
|
+
if (body === null)
|
|
71
|
+
return false;
|
|
72
|
+
return Array.from(body.querySelectorAll("img[src]")).some((image) => /^https?:/i.test(image.getAttribute("src") ?? ""));
|
|
73
|
+
}
|
|
74
|
+
export function plainTextOfHtml(html) {
|
|
75
|
+
return parseHtmlBody(html)?.textContent ?? "";
|
|
76
|
+
}
|
|
@@ -20,5 +20,7 @@ export const TONE_PILL = {
|
|
|
20
20
|
* (e.g. operational→ok, investigating→warn) and passes the translated
|
|
21
21
|
* label as children. */
|
|
22
22
|
export function StatusBadge({ tone, children, className, testId, }) {
|
|
23
|
-
return (_jsxs("span", { "data-testid": testId, className: cn(
|
|
23
|
+
return (_jsxs("span", { "data-testid": testId, className: cn(
|
|
24
|
+
// Px on phones: an app may shrink its root font for desktop density, the phone reading size stays.
|
|
25
|
+
"inline-flex h-5 items-center gap-1.5 whitespace-nowrap rounded-full px-2 text-xs font-medium max-md:h-[20px] max-md:text-[12px]", TONE_PILL[tone], className), children: [_jsx("span", { "aria-hidden": "true", "data-status-dot": true, className: "size-1.5 shrink-0 rounded-full bg-current" }), children] }));
|
|
24
26
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/** How many steps to show when the list must fold; undefined when every step fits.
|
|
3
|
+
* `minimum` steps always show, even when they alone overflow. */
|
|
4
|
+
export declare function stepsThatFit(input: {
|
|
5
|
+
readonly rowHeights: readonly number[];
|
|
6
|
+
readonly availableHeight: number;
|
|
7
|
+
readonly moreRowHeight: number;
|
|
8
|
+
readonly minimum: number;
|
|
9
|
+
}): number | undefined;
|
|
10
|
+
/** Folds a filling list only when its steps overflow the height it got. Every row is measured once
|
|
11
|
+
* while shown; a new step shows the whole list again for one layout pass to get its height. */
|
|
12
|
+
export declare function useFitCollapse(enabled: boolean, stepIds: readonly string[], minimum: number): {
|
|
13
|
+
readonly listRef: RefObject<HTMLOListElement | null>;
|
|
14
|
+
readonly shownCount: number | undefined;
|
|
15
|
+
};
|
|
16
|
+
/** Where a StepList folds: after `collapsedAfter`, or with `foldsOnOverflow` only where its steps overflow. */
|
|
17
|
+
export declare function useStepFold(input: {
|
|
18
|
+
readonly stepIds: readonly string[];
|
|
19
|
+
readonly collapsedAfter: number | undefined;
|
|
20
|
+
readonly foldsOnOverflow: boolean;
|
|
21
|
+
readonly expanded: boolean;
|
|
22
|
+
}): {
|
|
23
|
+
readonly listRef: RefObject<HTMLOListElement | null>;
|
|
24
|
+
readonly foldAfter: number | undefined;
|
|
25
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
// Until the "more" row was on screen once, its height is guessed from one text line plus padding.
|
|
3
|
+
const FALLBACK_MORE_ROW_HEIGHT = 44;
|
|
4
|
+
/** How many steps to show when the list must fold; undefined when every step fits.
|
|
5
|
+
* `minimum` steps always show, even when they alone overflow. */
|
|
6
|
+
export function stepsThatFit(input) {
|
|
7
|
+
const { rowHeights, availableHeight, moreRowHeight, minimum } = input;
|
|
8
|
+
const total = rowHeights.reduce((sum, height) => sum + height, 0);
|
|
9
|
+
if (total <= availableHeight)
|
|
10
|
+
return undefined;
|
|
11
|
+
let used = moreRowHeight;
|
|
12
|
+
let fitting = 0;
|
|
13
|
+
for (const height of rowHeights) {
|
|
14
|
+
if (used + height > availableHeight)
|
|
15
|
+
break;
|
|
16
|
+
used += height;
|
|
17
|
+
fitting += 1;
|
|
18
|
+
}
|
|
19
|
+
const shown = Math.max(minimum, fitting);
|
|
20
|
+
return shown >= rowHeights.length ? undefined : shown;
|
|
21
|
+
}
|
|
22
|
+
/** Folds a filling list only when its steps overflow the height it got. Every row is measured once
|
|
23
|
+
* while shown; a new step shows the whole list again for one layout pass to get its height. */
|
|
24
|
+
export function useFitCollapse(enabled, stepIds, minimum) {
|
|
25
|
+
const listRef = useRef(null);
|
|
26
|
+
const rowHeights = useRef(new Map());
|
|
27
|
+
const moreRowHeight = useRef(FALLBACK_MORE_ROW_HEIGHT);
|
|
28
|
+
const [availableHeight, setAvailableHeight] = useState(0);
|
|
29
|
+
const [shownCount, setShownCount] = useState(undefined);
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
const list = listRef.current;
|
|
32
|
+
// skip: a fixed fold, or no layout to measure (server render, test DOM without ResizeObserver)
|
|
33
|
+
if (!enabled || list === null || typeof ResizeObserver === "undefined")
|
|
34
|
+
return undefined;
|
|
35
|
+
const observer = new ResizeObserver(() => setAvailableHeight(list.clientHeight));
|
|
36
|
+
observer.observe(list);
|
|
37
|
+
setAvailableHeight(list.clientHeight);
|
|
38
|
+
return () => observer.disconnect();
|
|
39
|
+
}, [enabled]);
|
|
40
|
+
const idsKey = stepIds.join("\n");
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
const list = listRef.current;
|
|
43
|
+
// skip: a fixed fold measures nothing
|
|
44
|
+
if (!enabled || list === null)
|
|
45
|
+
return;
|
|
46
|
+
// The ids come back out of idsKey, so a new array with the same steps does not re-run this effect.
|
|
47
|
+
const ids = idsKey === "" ? [] : idsKey.split("\n");
|
|
48
|
+
const rows = Array.from(list.children);
|
|
49
|
+
const shown = shownCount ?? ids.length;
|
|
50
|
+
ids.slice(0, shown).forEach((id, index) => {
|
|
51
|
+
const row = rows[index];
|
|
52
|
+
if (row instanceof HTMLElement)
|
|
53
|
+
rowHeights.current.set(id, row.offsetHeight);
|
|
54
|
+
});
|
|
55
|
+
const moreRow = rows[shown];
|
|
56
|
+
if (shown < ids.length && moreRow instanceof HTMLElement && moreRow.offsetHeight > 0) {
|
|
57
|
+
moreRowHeight.current = moreRow.offsetHeight;
|
|
58
|
+
}
|
|
59
|
+
const heights = ids.map((id) => rowHeights.current.get(id));
|
|
60
|
+
if (heights.some((height) => height === undefined)) {
|
|
61
|
+
setShownCount(undefined);
|
|
62
|
+
// skip: an unmeasured step shows the whole list for one pass, the next pass folds it
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setShownCount(stepsThatFit({
|
|
66
|
+
rowHeights: heights.map((height) => height ?? 0),
|
|
67
|
+
availableHeight,
|
|
68
|
+
moreRowHeight: moreRowHeight.current,
|
|
69
|
+
minimum,
|
|
70
|
+
}));
|
|
71
|
+
}, [enabled, idsKey, availableHeight, minimum, shownCount]);
|
|
72
|
+
return { listRef, shownCount: enabled ? shownCount : undefined };
|
|
73
|
+
}
|
|
74
|
+
/** Where a StepList folds: after `collapsedAfter`, or with `foldsOnOverflow` only where its steps overflow. */
|
|
75
|
+
export function useStepFold(input) {
|
|
76
|
+
const fitsHeight = input.foldsOnOverflow && input.collapsedAfter !== undefined;
|
|
77
|
+
const fit = useFitCollapse(fitsHeight && !input.expanded, input.stepIds, input.collapsedAfter ?? 0);
|
|
78
|
+
return { listRef: fit.listRef, foldAfter: fitsHeight ? fit.shownCount : input.collapsedAfter };
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type StepStatus = "done" | "open" | "locked" | "running" | "rejected" | "failed";
|
|
3
|
+
export type StepAction = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly onClick: () => void;
|
|
7
|
+
readonly variant?: "primary" | "secondary" | "ghost";
|
|
8
|
+
readonly disabled?: boolean;
|
|
9
|
+
readonly pending?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type StepTag = {
|
|
12
|
+
readonly label: string;
|
|
13
|
+
readonly tone?: "accent" | "muted" | "warn" | "ok" | "bad";
|
|
14
|
+
/** A note about the step's history (e.g. just changed) reads after what it waits for. */
|
|
15
|
+
readonly afterWaiting?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type StepListItem = {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly description?: string;
|
|
21
|
+
readonly status: StepStatus;
|
|
22
|
+
/** Shown for "locked" as muted tag "Wartet auf: ..." and as the icon's accessible name. */
|
|
23
|
+
readonly lockedReason?: string;
|
|
24
|
+
readonly tags?: readonly StepTag[];
|
|
25
|
+
readonly meta?: string;
|
|
26
|
+
readonly link?: {
|
|
27
|
+
readonly label: string;
|
|
28
|
+
readonly href?: string;
|
|
29
|
+
readonly onClick?: () => void;
|
|
30
|
+
/** "below" puts an action that changes the step (e.g. taking a rejection back) under its text; default is the trailing link to what the step made. */
|
|
31
|
+
readonly placement?: "trailing" | "below";
|
|
32
|
+
};
|
|
33
|
+
/** Where the step comes from, e.g. "Quelle: Seite 3, § 5" (caller-localized); each renders as a link under the description. */
|
|
34
|
+
readonly sources?: readonly StepSource[];
|
|
35
|
+
/** Marks the step the reader is looking at (warm background). */
|
|
36
|
+
readonly highlighted?: boolean;
|
|
37
|
+
/** Rendered only while status is "open". */
|
|
38
|
+
readonly actions?: readonly StepAction[];
|
|
39
|
+
};
|
|
40
|
+
export type StepSource = {
|
|
41
|
+
readonly label: string;
|
|
42
|
+
readonly onClick: () => void;
|
|
43
|
+
};
|
|
44
|
+
export declare function StepActionButton({ action }: {
|
|
45
|
+
readonly action: StepAction;
|
|
46
|
+
}): ReactNode;
|
|
47
|
+
export declare function StepRow({ step, phoneCard, }: {
|
|
48
|
+
readonly step: StepListItem;
|
|
49
|
+
readonly phoneCard?: boolean;
|
|
50
|
+
}): ReactNode;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertTriangle, Check, Loader2, Lock, X } from "lucide-react";
|
|
3
|
+
import { usePrimitives, useTranslation } from "../../index.js";
|
|
4
|
+
import { cn } from "../lib/cn.js";
|
|
5
|
+
import { StatusBadge } from "./status-badge.js";
|
|
6
|
+
const STATUS_LABEL_KEY = {
|
|
7
|
+
done: "kumiko.widget.step-list.statusDone",
|
|
8
|
+
open: "kumiko.widget.step-list.statusOpen",
|
|
9
|
+
locked: "kumiko.widget.step-list.statusLocked",
|
|
10
|
+
running: "kumiko.widget.step-list.statusRunning",
|
|
11
|
+
rejected: "kumiko.widget.step-list.statusRejected",
|
|
12
|
+
failed: "kumiko.widget.step-list.statusFailed",
|
|
13
|
+
};
|
|
14
|
+
const ICON_BOX = "flex size-5 max-md:size-[20px] shrink-0 items-center justify-center rounded-full";
|
|
15
|
+
function StatusGlyph({ status }) {
|
|
16
|
+
switch (status) {
|
|
17
|
+
case "done":
|
|
18
|
+
return _jsx(Check, { "aria-hidden": "true", className: "size-3", strokeWidth: 2.5 });
|
|
19
|
+
case "locked":
|
|
20
|
+
return _jsx(Lock, { "aria-hidden": "true", className: "size-3.5" });
|
|
21
|
+
case "running":
|
|
22
|
+
return _jsx(Loader2, { "aria-hidden": "true", className: "size-3.5 animate-spin" });
|
|
23
|
+
case "rejected":
|
|
24
|
+
return _jsx(X, { "aria-hidden": "true", className: "size-3", strokeWidth: 2 });
|
|
25
|
+
case "failed":
|
|
26
|
+
return _jsx(AlertTriangle, { "aria-hidden": "true", className: "size-3.5" });
|
|
27
|
+
case "open":
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const STATUS_ICON_CLASS = {
|
|
32
|
+
done: "bg-status-ok text-background",
|
|
33
|
+
open: "box-border border-[1.5px] border-primary",
|
|
34
|
+
locked: "text-muted-foreground",
|
|
35
|
+
running: "text-primary",
|
|
36
|
+
rejected: "bg-border-row text-foreground-secondary",
|
|
37
|
+
failed: "text-status-bad",
|
|
38
|
+
};
|
|
39
|
+
function StatusIcon({ step }) {
|
|
40
|
+
const t = useTranslation();
|
|
41
|
+
const label = step.status === "locked" && step.lockedReason !== undefined
|
|
42
|
+
? t("kumiko.widget.step-list.waitingFor", { reason: step.lockedReason })
|
|
43
|
+
: t(STATUS_LABEL_KEY[step.status]);
|
|
44
|
+
return (_jsx("span", { role: "img", "aria-label": label, "data-status": step.status, className: cn(ICON_BOX, STATUS_ICON_CLASS[step.status]), children: _jsx(StatusGlyph, { status: step.status }) }));
|
|
45
|
+
}
|
|
46
|
+
function tagTone(tone) {
|
|
47
|
+
return tone ?? "muted";
|
|
48
|
+
}
|
|
49
|
+
function StepLink({ link }) {
|
|
50
|
+
const { Link, Button } = usePrimitives();
|
|
51
|
+
if (link.href !== undefined) {
|
|
52
|
+
return (_jsx(Link, { href: link.href, onPress: link.onClick, className: "shrink-0 text-[13px] font-medium underline underline-offset-2", children: link.label }));
|
|
53
|
+
}
|
|
54
|
+
return (_jsx(Button, { variant: "link", size: "sm", onClick: link.onClick, className: "shrink-0 text-[13px]", children: link.label }));
|
|
55
|
+
}
|
|
56
|
+
function StepBelowLink({ link }) {
|
|
57
|
+
const { Button } = usePrimitives();
|
|
58
|
+
return (_jsx(Button, { variant: "link", size: "sm", onClick: link.onClick, className: "h-auto self-start p-0 text-[13px] font-medium", children: link.label }));
|
|
59
|
+
}
|
|
60
|
+
export function StepActionButton({ action }) {
|
|
61
|
+
const { Button } = usePrimitives();
|
|
62
|
+
return (_jsx(Button, { size: "sm", variant: action.variant ?? "secondary", disabled: action.disabled, loading: action.pending, onClick: action.onClick, testId: `step-action-${action.id}`, className: "max-md:text-[14px]", children: action.label }));
|
|
63
|
+
}
|
|
64
|
+
// A long reason ("Wartet auf: Whg. 3, Stellplatz 7, …") is cut at the column edge instead of running out of it.
|
|
65
|
+
function StepTagBadge({ tone, label, className, }) {
|
|
66
|
+
return (_jsx("span", { className: "flex min-w-0 max-w-full", title: label, children: _jsx(StatusBadge, { tone: tone, className: cn("min-w-0 max-w-full", className), children: _jsx("span", { className: "truncate", children: label }) }) }));
|
|
67
|
+
}
|
|
68
|
+
// Sources and tags share one line: a source link and the step it waits for read as one fact.
|
|
69
|
+
// The phone card reads the waiting reason as a plain second line, not as a pill.
|
|
70
|
+
const PHONE_WAITING_TEXT_CLASS = "max-md:h-auto max-md:rounded-none max-md:bg-transparent max-md:px-0 max-md:text-[13px] max-md:font-normal max-md:text-foreground-secondary max-md:[&>[data-status-dot]]:hidden";
|
|
71
|
+
function StepSourcesAndTags({ step, phoneCard, }) {
|
|
72
|
+
const t = useTranslation();
|
|
73
|
+
const tags = step.tags ?? [];
|
|
74
|
+
const sources = step.sources ?? [];
|
|
75
|
+
const waiting = step.status === "locked" && step.lockedReason !== undefined;
|
|
76
|
+
if (tags.length === 0 && sources.length === 0 && !waiting)
|
|
77
|
+
return null;
|
|
78
|
+
return (_jsxs("div", { className: "flex flex-wrap items-center gap-x-2.5 gap-y-1.5 text-[13px]", children: [_jsx(StepSources, { step: step }), tags
|
|
79
|
+
.filter((tag) => tag.afterWaiting !== true)
|
|
80
|
+
.map((tag) => (_jsx(StepTagBadge, { tone: tagTone(tag.tone), label: tag.label }, tag.label))), waiting && (_jsx(StepTagBadge, { tone: "muted", label: t("kumiko.widget.step-list.waitingFor", { reason: step.lockedReason ?? "" }), ...(phoneCard && { className: PHONE_WAITING_TEXT_CLASS }) })), tags
|
|
81
|
+
.filter((tag) => tag.afterWaiting === true)
|
|
82
|
+
.map((tag) => (_jsx(StepTagBadge, { tone: tagTone(tag.tone), label: tag.label }, tag.label)))] }));
|
|
83
|
+
}
|
|
84
|
+
function StepSources({ step }) {
|
|
85
|
+
const { Button } = usePrimitives();
|
|
86
|
+
return (_jsx(_Fragment, { children: (step.sources ?? []).map((source) => (_jsx(Button, { variant: "link", size: "sm", onClick: source.onClick, className: "h-auto p-0 text-[13px] underline underline-offset-2", testId: `step-${step.id}-source`, children: source.label }, source.label))) }));
|
|
87
|
+
}
|
|
88
|
+
function StepActions({ step }) {
|
|
89
|
+
const actions = step.status === "open" ? (step.actions ?? []) : [];
|
|
90
|
+
if (actions.length === 0)
|
|
91
|
+
return null;
|
|
92
|
+
return (_jsx("div", { className: "flex gap-2 pt-0.5", children: actions.map((action) => (_jsx(StepActionButton, { action: action }, action.id))) }));
|
|
93
|
+
}
|
|
94
|
+
export function StepRow({ step, phoneCard = false, }) {
|
|
95
|
+
const rejected = step.status === "rejected";
|
|
96
|
+
return (_jsxs("li", { "data-testid": `step-${step.id}`, className: cn("flex gap-2.5 border-b border-border-row px-4 py-3", step.status === "open" && "bg-card", step.highlighted === true && "bg-status-warn-surface"), ...(step.highlighted === true && { "aria-current": "step" }), children: [_jsx(StatusIcon, { step: step }), _jsxs("div", { className: "flex min-w-0 grow flex-col gap-1", children: [_jsx("span", { className: cn("font-medium", rejected && "text-muted-foreground line-through"), "data-testid": `step-${step.id}-title`, children: step.title }), step.description !== undefined && (_jsx("span", { className: "text-[13px] text-foreground-secondary", children: step.description })), _jsx(StepSourcesAndTags, { step: step, phoneCard: phoneCard }), step.meta !== undefined && (_jsx("span", { className: "text-[13px] text-muted-foreground", children: step.meta })), step.link?.placement === "below" && _jsx(StepBelowLink, { link: step.link }), _jsx(StepActions, { step: step })] }), step.link !== undefined && step.link.placement !== "below" && _jsx(StepLink, { link: step.link })] }));
|
|
97
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type StatusBadgeTone } from "./status-badge.tsx";
|
|
3
|
+
import { type StepAction, type StepListItem } from "./step-list-row.tsx";
|
|
4
|
+
export type { StepAction, StepListItem, StepSource, StepStatus, StepTag, } from "./step-list-row.tsx";
|
|
5
|
+
export type StepListProps = {
|
|
6
|
+
readonly title: string;
|
|
7
|
+
/** Second line under the title, e.g. who completed the list and when. */
|
|
8
|
+
readonly subtitle?: string;
|
|
9
|
+
/** Badge next to the title, e.g. "Erledigt" for a finished list. */
|
|
10
|
+
readonly status?: {
|
|
11
|
+
readonly label: string;
|
|
12
|
+
readonly tone: StatusBadgeTone;
|
|
13
|
+
};
|
|
14
|
+
readonly steps: readonly StepListItem[];
|
|
15
|
+
/** Footer row: a ghost action for the whole list next to the primary next-step action. */
|
|
16
|
+
readonly footerActions?: readonly StepAction[];
|
|
17
|
+
/** Show only the first n steps plus "und k weitere Schritte" (expands on click). */
|
|
18
|
+
readonly collapsedAfter?: number;
|
|
19
|
+
/** "always" (default) folds after `collapsedAfter`; "overflow" folds a `fill` list only when its steps do not fit its height, then shows as many as fit but at least `collapsedAfter`. */
|
|
20
|
+
readonly collapseWhen?: "always" | "overflow";
|
|
21
|
+
/** "ai" (default) = AiSurface background, "plain" = no background. */
|
|
22
|
+
readonly surface?: "ai" | "plain";
|
|
23
|
+
/** Stretch to the container height: steps scroll in the middle, the footer stays pinned at the bottom. */
|
|
24
|
+
readonly fill?: boolean;
|
|
25
|
+
/** "full" (default) = "x von y erledigt" plus bar, "count" = only the count, "none" = neither, e.g. when `status` already says the list is done. */
|
|
26
|
+
readonly progress?: "full" | "count" | "none";
|
|
27
|
+
readonly emptyContent?: ReactNode;
|
|
28
|
+
/** On a phone the list reads as a card: the header sits inside the surface and the steps in a framed white box. */
|
|
29
|
+
readonly phoneCard?: boolean;
|
|
30
|
+
readonly testId?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Ordered plan of steps with status icons, progress header and per-step actions. */
|
|
33
|
+
export declare function StepList({ title, subtitle, status, steps, footerActions, collapsedAfter, collapseWhen, surface, fill, progress, emptyContent, phoneCard, testId, }: StepListProps): ReactNode;
|