@ciridae/ui 1.2.2 → 1.4.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.
Files changed (64) hide show
  1. package/README.md +2 -2
  2. package/dist/components/app-frame.js +4 -4
  3. package/dist/components/button.d.ts +0 -11
  4. package/dist/components/button.js +1 -26
  5. package/dist/components/color-theme.d.ts +3 -12
  6. package/dist/components/color-theme.js +2 -29
  7. package/dist/components/dropzone.d.ts +0 -4
  8. package/dist/components/dropzone.js +4 -9
  9. package/dist/components/feedback-sheet.d.ts +1 -16
  10. package/dist/components/feedback-sheet.js +7 -144
  11. package/dist/components/hotkeys.d.ts +1 -11
  12. package/dist/components/hotkeys.js +3 -44
  13. package/dist/components/keyboard-shortcuts.d.ts +0 -2
  14. package/dist/components/keyboard-shortcuts.js +2 -46
  15. package/dist/components/locale.d.ts +11 -42
  16. package/dist/components/locale.js +12 -48
  17. package/dist/components/log-list.d.ts +0 -2
  18. package/dist/components/log-list.js +0 -22
  19. package/dist/components/profile-dialog.d.ts +10 -0
  20. package/dist/components/profile-dialog.js +46 -0
  21. package/dist/components/record.d.ts +0 -23
  22. package/dist/components/record.js +2 -80
  23. package/dist/components/select.d.ts +7 -0
  24. package/dist/components/select.js +21 -2
  25. package/dist/components/sidebar.d.ts +0 -1
  26. package/dist/components/sidebar.js +0 -10
  27. package/dist/components/tabs.d.ts +0 -3
  28. package/dist/components/tabs.js +0 -4
  29. package/dist/feedback/contract.d.ts +1 -25
  30. package/dist/feedback/contract.js +2 -6
  31. package/dist/feedback/operator-controller.d.ts +3 -10
  32. package/dist/feedback/operator-controller.js +1 -28
  33. package/dist/preset.d.ts +0 -6
  34. package/dist/preset.js +0 -5
  35. package/dist/styled-system/styles.css +20 -82
  36. package/dist/theme/options.d.ts +1 -19
  37. package/dist/theme/options.js +0 -1
  38. package/dist/theme/tokens.d.ts +1 -8
  39. package/dist/theme/tokens.js +1 -17
  40. package/package.json +5 -49
  41. package/dist/components/profile-header.d.ts +0 -15
  42. package/dist/components/profile-header.js +0 -40
  43. package/dist/components/recent-items.d.ts +0 -28
  44. package/dist/components/recent-items.js +0 -63
  45. package/dist/components/theme-customizer.d.ts +0 -50
  46. package/dist/components/theme-customizer.js +0 -84
  47. package/dist/components/theme-toggle.d.ts +0 -3
  48. package/dist/components/theme-toggle.js +0 -65
  49. package/dist/feedback/comment-types.d.ts +0 -17
  50. package/dist/feedback/comment-types.js +0 -1
  51. package/dist/feedback/feedback-cache.d.ts +0 -6
  52. package/dist/feedback/feedback-cache.js +0 -58
  53. package/dist/feedback/feedback-center-model.d.ts +0 -8
  54. package/dist/feedback/feedback-center-model.js +0 -37
  55. package/dist/feedback/feedback-composer-types.d.ts +0 -11
  56. package/dist/feedback/feedback-composer-types.js +0 -1
  57. package/dist/feedback/feedback-controller.d.ts +0 -56
  58. package/dist/feedback/feedback-controller.js +0 -181
  59. package/dist/feedback/feedback-tracking-types.d.ts +0 -14
  60. package/dist/feedback/feedback-tracking-types.js +0 -1
  61. package/dist/feedback/submit-feedback-with-attachments.d.ts +0 -10
  62. package/dist/feedback/submit-feedback-with-attachments.js +0 -10
  63. package/dist/theme/index.d.ts +0 -3
  64. package/dist/theme/index.js +0 -7
@@ -1,40 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /*
3
- * The head of a person's or an agent's page: a large avatar, the name, their title and team,
4
- * their email with a copy control, a line on what they do, and actions at the end. The actions
5
- * drop under the name once the header is narrow.
6
- */
7
- import { css, cx } from "#primitives/css";
8
- import { CopyableText } from "./copyable-id.js";
9
- import { Avatar } from "./data-display.js";
10
- import { useCiridaeLocale } from "./locale.js";
11
- const header = css({ containerType: "inline-size" });
12
- const grid = css({
13
- display: "grid",
14
- gridTemplateColumns: "auto minmax(0, 1fr) auto",
15
- alignItems: "start",
16
- columnGap: "layout.contentGap",
17
- rowGap: "layout.controlGap",
18
- paddingInline: "layout.tightGap",
19
- "@container (max-width: 480px)": {
20
- gridTemplateColumns: "auto minmax(0, 1fr)",
21
- "& > [data-actions]": { gridColumn: "1 / -1" },
22
- },
23
- });
24
- const text = css({ display: "grid", gap: "layout.tightGap", minWidth: "0" });
25
- const nameStyle = css({
26
- margin: "none",
27
- fontSize: "heading.page",
28
- fontWeight: "medium",
29
- letterSpacing: "compact",
30
- lineHeight: "tight",
31
- overflowWrap: "anywhere",
32
- });
33
- const muted = css({ color: "fg.muted", fontSize: "caption", fontWeight: "medium" });
34
- const descriptionStyle = css({ margin: "none", color: "fg.secondary", fontSize: "body" });
35
- const actionsStyle = css({ display: "flex", flexWrap: "wrap", gap: "layout.controlGap" });
36
- export function ProfileHeader({ name, kind = "user", src, title, team, email, description, actions, className, ...props }) {
37
- const { labels } = useCiridaeLocale();
38
- const meta = [title, team].filter(Boolean).join(" · ");
39
- return (_jsx("header", { ...props, className: cx(header, className), "data-ciridae-ui": "", children: _jsxs("div", { className: grid, children: [_jsx(Avatar, { label: name, kind: kind, src: src, size: "large", "aria-hidden": "true" }), _jsxs("div", { className: text, children: [_jsx("h2", { className: nameStyle, children: name }), meta && _jsx("span", { className: muted, children: meta }), email && (_jsx("span", { className: muted, children: _jsx(CopyableText, { text: email, label: labels.profileHeader.email }) })), description && _jsx("p", { className: descriptionStyle, children: description })] }), actions && (_jsx("div", { className: actionsStyle, "data-actions": "", children: actions }))] }) }));
40
- }
@@ -1,28 +0,0 @@
1
- type RecentItemsStorage<Item> = {
2
- storageKey?: undefined;
3
- parseItem?: undefined;
4
- } | {
5
- /** Keeps both lists in `localStorage` as `{ recent, pinned }`. */
6
- storageKey: string;
7
- /** Reads one stored entry back, or null to drop it, such as a record that is gone. */
8
- parseItem: (stored: unknown) => Item | null;
9
- };
10
- export type UseRecentItemsOptions<Item> = RecentItemsStorage<Item> & {
11
- /** What makes two items the same, such as a record's route. */
12
- getId: (item: Item) => string;
13
- /** The open item; it joins Recent unless it is pinned or already listed. */
14
- current?: Item | null;
15
- /** Recent's length; 10 by default. */
16
- limit?: number;
17
- /** Recent while nothing is stored. */
18
- seed?: readonly Item[];
19
- };
20
- export declare function useRecentItems<Item>({ getId, current, limit, seed, storageKey, parseItem, }: UseRecentItemsOptions<Item>): {
21
- recent: readonly Item[];
22
- pinned: readonly Item[];
23
- isPinned: (item: Item) => boolean;
24
- pin: (item: Item) => void;
25
- unpin: (item: Item) => void;
26
- togglePin: (item: Item) => void;
27
- };
28
- export {};
@@ -1,63 +0,0 @@
1
- /*
2
- * The items a person opened lately and the ones they pinned, for a sidebar's Pinned and Recent
3
- * sections. An item joins Recent at the top the first time it opens; one already listed keeps its
4
- * place, so reopening never reshuffles the list under the pointer. Pinning moves an item out of
5
- * Recent to the end of Pinned; unpinning puts it back in Recent. Recent holds `limit` items.
6
- */
7
- import { useCallback, useEffect, useState } from "react";
8
- const DEFAULT_LIMIT = 10;
9
- function readStored(storageKey, parseItem) {
10
- try {
11
- const text = globalThis.localStorage?.getItem(storageKey);
12
- if (!text)
13
- return null;
14
- const stored = JSON.parse(text);
15
- if (typeof stored !== "object" || stored === null)
16
- return null;
17
- const list = (value) => Array.isArray(value) ? value.flatMap((entry) => parseItem(entry) ?? []) : [];
18
- return {
19
- recent: "recent" in stored ? list(stored.recent) : [],
20
- pinned: "pinned" in stored ? list(stored.pinned) : [],
21
- };
22
- }
23
- catch {
24
- // Unreadable storage starts from the seed.
25
- return null;
26
- }
27
- }
28
- export function useRecentItems({ getId, current, limit = DEFAULT_LIMIT, seed = [], storageKey, parseItem, }) {
29
- const [state, setState] = useState(() => {
30
- const stored = storageKey && parseItem ? readStored(storageKey, parseItem) : null;
31
- return stored ?? { recent: seed.slice(0, limit), pinned: [] };
32
- });
33
- const listed = useCallback((items, item) => items.some((other) => getId(other) === getId(item)), [getId]);
34
- const without = useCallback((items, item) => items.filter((other) => getId(other) !== getId(item)), [getId]);
35
- const withRecent = useCallback((items, item) => listed(items, item) ? items : [item, ...items].slice(0, limit), [listed, limit]);
36
- useEffect(() => {
37
- if (!current)
38
- return;
39
- setState((previous) => listed(previous.pinned, current) || listed(previous.recent, current)
40
- ? previous
41
- : { ...previous, recent: withRecent(previous.recent, current) });
42
- }, [current, listed, withRecent]);
43
- useEffect(() => {
44
- if (!storageKey)
45
- return;
46
- try {
47
- globalThis.localStorage?.setItem(storageKey, JSON.stringify(state));
48
- }
49
- catch {
50
- // Storage is a convenience; the lists still work for this visit.
51
- }
52
- }, [state, storageKey]);
53
- const pin = useCallback((item) => setState(({ recent, pinned }) => listed(pinned, item)
54
- ? { recent, pinned }
55
- : { pinned: [...pinned, item], recent: without(recent, item) }), [listed, without]);
56
- const unpin = useCallback((item) => setState(({ recent, pinned }) => ({
57
- pinned: without(pinned, item),
58
- recent: withRecent(recent, item),
59
- })), [without, withRecent]);
60
- const isPinned = (item) => listed(state.pinned, item);
61
- const togglePin = (item) => (isPinned(item) ? unpin(item) : pin(item));
62
- return { recent: state.recent, pinned: state.pinned, isPinned, pin, unpin, togglePin };
63
- }
@@ -1,50 +0,0 @@
1
- import { type ComponentProps } from "react";
2
- import { type CiridaeLabels } from "./locale.js";
3
- import type { CiridaeTheme } from "../theme/options.js";
4
- /** A face the app offers: its id, its name in the menu and its CSS family. */
5
- export type ThemeFontOption = {
6
- id: string;
7
- label: string;
8
- family: string;
9
- };
10
- export type ThemeFontOptions = {
11
- /** Heading faces; the body faces when left out. */
12
- display?: readonly ThemeFontOption[];
13
- sans: readonly ThemeFontOption[];
14
- mono: readonly ThemeFontOption[];
15
- };
16
- export type ThemeCustomization = {
17
- displayFont: string;
18
- sansFont: string;
19
- monoFont: string;
20
- };
21
- /** The font families `ThemeProvider` (and `createCiridaePreset`) take for `value`. */
22
- export declare function themeCustomizationTheme(value: ThemeCustomization, fonts: ThemeFontOptions): Pick<CiridaeTheme, "fonts">;
23
- /** A stored customization read back field by field, taking `fallback`'s for any it lacks. */
24
- export declare function parseThemeCustomization(stored: unknown, fallback: ThemeCustomization, fonts: ThemeFontOptions): ThemeCustomization;
25
- export type UseThemeCustomizationOptions<Value extends ThemeCustomization> = {
26
- defaultValue: Value;
27
- fonts: ThemeFontOptions;
28
- /** Keeps the value in `localStorage`, as JSON, under this key. */
29
- persistKey?: string;
30
- /** Reads the stored JSON back; `parseThemeCustomization` covers a plain customization. */
31
- parse: (stored: unknown) => Value;
32
- };
33
- /**
34
- * A customization the app holds at its root: the value, a setter, and the `fonts` to pass
35
- * `ThemeProvider`. With `persistKey` it survives reloads; anything the app keeps beside
36
- * the theme in `Value`, such as a brand name, is stored with it.
37
- */
38
- export declare function useThemeCustomization<Value extends ThemeCustomization>({ defaultValue, fonts, persistKey, parse, }: UseThemeCustomizationOptions<Value>): {
39
- value: Value;
40
- setValue: import("react").Dispatch<import("react").SetStateAction<Value>>;
41
- reset: () => void;
42
- theme: Pick<CiridaeTheme, "fonts">;
43
- };
44
- export type ThemeCustomizerProps<Value extends ThemeCustomization> = Omit<ComponentProps<"div">, "children" | "onChange"> & {
45
- value: Value;
46
- onValueChange: (value: Value) => void;
47
- fonts: ThemeFontOptions;
48
- labels?: Partial<CiridaeLabels["themeCustomizer"]>;
49
- };
50
- export declare function ThemeCustomizer<Value extends ThemeCustomization>({ value, onValueChange, fonts, labels: ownLabels, className, ...props }: ThemeCustomizerProps<Value>): import("react").JSX.Element;
@@ -1,84 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /*
3
- * The Appearance controls: the color theme (System, Light, Dark) and the display, body and mono
4
- * faces from fonts the app offers. The faces are the caller's `value`, which it hands to
5
- * `ThemeProvider` (`useThemeCustomization` keeps one in `localStorage` and builds that prop); the
6
- * color theme is `ThemeProvider`'s own, so it is read and set through `useColorTheme`.
7
- */
8
- import { useCallback, useEffect, useState } from "react";
9
- import { css, cx } from "#primitives/css";
10
- import { useColorTheme } from "./color-theme.js";
11
- import { DrawerField, DrawerFieldRow } from "./drawer.js";
12
- import { SegmentedControl, SegmentedOption } from "./form-layout.js";
13
- import { useCiridaeLocale } from "./locale.js";
14
- import { Select } from "./select.js";
15
- function fontFamily(options, id) {
16
- return options.find((option) => option.id === id)?.family;
17
- }
18
- /** The font families `ThemeProvider` (and `createCiridaePreset`) take for `value`. */
19
- export function themeCustomizationTheme(value, fonts) {
20
- return {
21
- fonts: {
22
- display: fontFamily(fonts.display ?? fonts.sans, value.displayFont),
23
- sans: fontFamily(fonts.sans, value.sansFont),
24
- mono: fontFamily(fonts.mono, value.monoFont),
25
- },
26
- };
27
- }
28
- /** A stored customization read back field by field, taking `fallback`'s for any it lacks. */
29
- export function parseThemeCustomization(stored, fallback, fonts) {
30
- if (typeof stored !== "object" || stored === null)
31
- return fallback;
32
- const fontId = (options, value, otherwise) => options.find((option) => option.id === value)?.id ?? otherwise;
33
- return {
34
- displayFont: fontId(fonts.display ?? fonts.sans, "displayFont" in stored ? stored.displayFont : undefined, fallback.displayFont),
35
- sansFont: fontId(fonts.sans, "sansFont" in stored ? stored.sansFont : undefined, fallback.sansFont),
36
- monoFont: fontId(fonts.mono, "monoFont" in stored ? stored.monoFont : undefined, fallback.monoFont),
37
- };
38
- }
39
- /**
40
- * A customization the app holds at its root: the value, a setter, and the `fonts` to pass
41
- * `ThemeProvider`. With `persistKey` it survives reloads; anything the app keeps beside
42
- * the theme in `Value`, such as a brand name, is stored with it.
43
- */
44
- export function useThemeCustomization({ defaultValue, fonts, persistKey, parse, }) {
45
- const [value, setValue] = useState(() => {
46
- if (!persistKey)
47
- return defaultValue;
48
- try {
49
- const text = globalThis.localStorage?.getItem(persistKey);
50
- return text ? parse(JSON.parse(text)) : defaultValue;
51
- }
52
- catch {
53
- return defaultValue;
54
- }
55
- });
56
- useEffect(() => {
57
- if (!persistKey)
58
- return;
59
- try {
60
- globalThis.localStorage?.setItem(persistKey, JSON.stringify(value));
61
- }
62
- catch {
63
- // The reader loses persistence across reloads, not the look they chose.
64
- }
65
- }, [persistKey, value]);
66
- const reset = useCallback(() => setValue(defaultValue), [defaultValue]);
67
- return { value, setValue, reset, theme: themeCustomizationTheme(value, fonts) };
68
- }
69
- const root = css({ display: "flex", flexDirection: "column", gap: "layout.clusterGap" });
70
- export function ThemeCustomizer({ value, onValueChange, fonts, labels: ownLabels, className, ...props }) {
71
- const { labels: localeLabels } = useCiridaeLocale();
72
- const labels = { ...localeLabels.themeCustomizer, ...ownLabels };
73
- const { preference, setPreference } = useColorTheme();
74
- const colorThemes = [
75
- { value: "system", label: labels.system },
76
- { value: "light", label: labels.light },
77
- { value: "dark", label: labels.dark },
78
- ];
79
- const fontSelect = (label, options, selected, pick) => (_jsx(DrawerField, { label: label, children: _jsx(Select, { label: label, size: "medium", options: options.map((option) => ({ value: option.id, label: option.label })), value: selected, onValueChange: (id) => {
80
- if (id !== null && options.some((option) => option.id === id))
81
- pick(id);
82
- } }) }));
83
- return (_jsxs("div", { ...props, className: cx(root, className), "data-ciridae-ui": "", children: [_jsx(DrawerField, { label: labels.colorTheme, children: _jsx(SegmentedControl, { "aria-label": labels.colorTheme, children: colorThemes.map((option) => (_jsx(SegmentedOption, { selected: option.value === preference, onClick: () => setPreference(option.value), children: option.label }, option.value))) }) }), _jsxs(DrawerFieldRow, { children: [fontSelect(labels.displayFont, fonts.display ?? fonts.sans, value.displayFont, (id) => onValueChange({ ...value, displayFont: id })), fontSelect(labels.sansFont, fonts.sans, value.sansFont, (id) => onValueChange({ ...value, sansFont: id }))] }), _jsx(DrawerFieldRow, { children: fontSelect(labels.monoFont, fonts.mono, value.monoFont, (id) => onValueChange({ ...value, monoFont: id })) })] }));
84
- }
@@ -1,3 +0,0 @@
1
- export declare function ThemeToggle({ className }: {
2
- className?: string;
3
- }): import("react").JSX.Element;
@@ -1,65 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { CircleHalfIcon, MoonIcon, SunIcon } from "@phosphor-icons/react";
3
- import { css, cx } from "#primitives/css";
4
- import { useColorTheme } from "./color-theme.js";
5
- import { faceEdge } from "./gradient-edge.js";
6
- import { icon } from "./icon.js";
7
- import { useCiridaeLocale } from "./locale.js";
8
- const track = css({
9
- display: "inline-flex",
10
- alignItems: "center",
11
- gap: "control.trackInset",
12
- padding: "control.trackInset",
13
- // The design lays the track's edge over its inset, and rounds it to its options' corners.
14
- border: "0",
15
- borderRadius: "[calc(token(radii.inset) + token(spacing.control.trackInset))]",
16
- background: "[token(gradients.panel)]",
17
- });
18
- const option = css({
19
- display: "inline-grid",
20
- placeItems: "center",
21
- width: "control.small",
22
- height: "[calc(token(sizes.control.small) - 2 * token(spacing.control.trackInset))]",
23
- padding: "none",
24
- border: "0",
25
- borderRadius: "inset",
26
- background: "transparent",
27
- color: "fg.secondary",
28
- cursor: "pointer",
29
- transitionProperty: "[background, color]",
30
- transitionDuration: "fast",
31
- _hover: { color: "fg.primary" },
32
- _focusVisible: { focusRing: "outer" },
33
- _before: { display: "none", background: "[token(gradients.border.raised)]" },
34
- "&[aria-pressed=true]": {
35
- background: "[token(gradients.raised)]",
36
- color: "fg.primary",
37
- _before: { display: "block" },
38
- },
39
- });
40
- export function ThemeToggle({ className }) {
41
- const { preference, setPreference } = useColorTheme();
42
- const { labels } = useCiridaeLocale();
43
- // The track takes the quieter toolbar edge, as the filter and slicer bars do: with the raised
44
- // edge it matched the pressed option's own ring 2px inside it, and the pair read as one thick
45
- // double border rather than a selected option in a track.
46
- const trackEdge = faceEdge("toolbar");
47
- const choices = [
48
- {
49
- value: "light",
50
- label: labels.themeCustomizer.light,
51
- glyph: _jsx(SunIcon, { className: icon({ size: "small" }) }),
52
- },
53
- {
54
- value: "dark",
55
- label: labels.themeCustomizer.dark,
56
- glyph: _jsx(MoonIcon, { className: icon({ size: "small" }) }),
57
- },
58
- {
59
- value: "system",
60
- label: labels.themeCustomizer.system,
61
- glyph: _jsx(CircleHalfIcon, { className: icon({ size: "small" }) }),
62
- },
63
- ];
64
- return (_jsx("div", { role: "group", "aria-label": labels.themeCustomizer.colorTheme, className: cx(track, trackEdge.className, className), "data-ciridae-ui": "", "data-edge": trackEdge["data-edge"], children: choices.map((choice) => (_jsx("button", { type: "button", "aria-label": choice.label, "aria-pressed": preference === choice.value, className: option, "data-ciridae-ui": "", "data-edge": "gradient", onClick: () => setPreference(choice.value), children: choice.glyph }, choice.value))) }));
65
- }
@@ -1,17 +0,0 @@
1
- type CommentAuthor = {
2
- avatarUrl?: string;
3
- email?: string;
4
- id: string;
5
- name: string;
6
- };
7
- type CommentStatus = "sent" | "sending" | "failed";
8
- /** A feedback thread message in the shape a comment list renders. */
9
- type CommentItemData = {
10
- author: CommentAuthor;
11
- body: string;
12
- createdAt: string;
13
- id: string;
14
- status?: CommentStatus;
15
- updatedAt?: string;
16
- };
17
- export type { CommentAuthor, CommentItemData, CommentStatus };
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { FeedbackItem, FeedbackMessage } from "./contract.js";
2
- import type { QueryClient } from "@tanstack/react-query";
3
- declare function cacheCreatedFeedbackItem(queryClient: QueryClient, queryRoot: readonly string[], item: FeedbackItem): Promise<void>;
4
- declare function refreshFeedbackItem(queryClient: QueryClient, queryRoot: readonly string[], item: FeedbackItem): Promise<void>;
5
- declare function appendFeedbackMessage(queryClient: QueryClient, queryRoot: readonly string[], feedbackId: string, message: FeedbackMessage): Promise<void>;
6
- export { appendFeedbackMessage, cacheCreatedFeedbackItem, refreshFeedbackItem };
@@ -1,58 +0,0 @@
1
- async function cacheCreatedFeedbackItem(queryClient, queryRoot, item) {
2
- const itemsKey = [...queryRoot, "items"];
3
- await queryClient.cancelQueries({ queryKey: itemsKey, exact: true });
4
- queryClient.setQueryData(itemsKey, (summaries = []) => [
5
- item,
6
- ...summaries.filter((summary) => summary.id !== item.id),
7
- ]);
8
- return queryClient.invalidateQueries({ queryKey: itemsKey, exact: true });
9
- }
10
- async function refreshFeedbackItem(queryClient, queryRoot, item) {
11
- const itemKey = [...queryRoot, "item", item.id];
12
- const itemsKey = [...queryRoot, "items"];
13
- await Promise.all([
14
- queryClient.cancelQueries({ queryKey: itemKey, exact: true }),
15
- queryClient.cancelQueries({ queryKey: itemsKey, exact: true }),
16
- ]);
17
- queryClient.setQueryData(itemKey, (cached) => cached
18
- ? {
19
- ...item,
20
- messages: mergeFeedbackMessages(item.messages, cached.messages),
21
- }
22
- : item);
23
- queryClient.setQueryData(itemsKey, (summaries) => summaries?.map((summary) => (summary.id === item.id ? item : summary)));
24
- return queryClient.invalidateQueries({ queryKey: itemsKey, exact: true });
25
- }
26
- async function appendFeedbackMessage(queryClient, queryRoot, feedbackId, message) {
27
- const itemKey = [...queryRoot, "item", feedbackId];
28
- await queryClient.cancelQueries({ queryKey: itemKey, exact: true });
29
- let updated = false;
30
- queryClient.setQueryData(itemKey, (item) => {
31
- if (!item)
32
- return item;
33
- updated = true;
34
- if (item.messages.some((existing) => existing.id === message.id))
35
- return item;
36
- return {
37
- ...item,
38
- messages: [...item.messages, message],
39
- updatedAt: message.createdAt,
40
- updatedAt_epoch_milliseconds: message.createdAt_epoch_milliseconds,
41
- };
42
- });
43
- const invalidations = [
44
- queryClient.invalidateQueries({ queryKey: [...queryRoot, "items"], exact: true }),
45
- ];
46
- if (!updated) {
47
- invalidations.push(queryClient.invalidateQueries({ queryKey: itemKey, exact: true }));
48
- }
49
- await Promise.all(invalidations);
50
- }
51
- function mergeFeedbackMessages(serverMessages, cachedMessages) {
52
- const serverMessageIds = new Set(serverMessages.map((message) => message.id));
53
- return [
54
- ...serverMessages,
55
- ...cachedMessages.filter((message) => !serverMessageIds.has(message.id)),
56
- ];
57
- }
58
- export { appendFeedbackMessage, cacheCreatedFeedbackItem, refreshFeedbackItem };
@@ -1,8 +0,0 @@
1
- import type { CommentItemData } from "./comment-types.js";
2
- import type { FeedbackItem, FeedbackMessage, FeedbackSummary } from "./contract.js";
3
- import type { UserFeedbackItem } from "./feedback-tracking-types.js";
4
- declare function toPresentationItem(item: FeedbackSummary): UserFeedbackItem;
5
- declare function toCommentsByFeedbackId(feedbackId: string | undefined, messages: FeedbackMessage[]): Record<string, CommentItemData[]>;
6
- declare function canReply(feedbackId: string, summaries: FeedbackSummary[], detail: FeedbackItem | undefined): boolean;
7
- declare function requireSelectedId(selectedId: string | undefined): string;
8
- export { canReply, requireSelectedId, toCommentsByFeedbackId, toPresentationItem };
@@ -1,37 +0,0 @@
1
- function toPresentationItem(item) {
2
- return {
3
- affectedScope: item.affectedScope,
4
- description: item.description,
5
- id: item.id,
6
- status: item.status,
7
- subject: item.subject,
8
- submittedAt: item.createdAt,
9
- type: item.type,
10
- updatedAt: item.updatedAt,
11
- urgency: item.urgency,
12
- };
13
- }
14
- function toCommentsByFeedbackId(feedbackId, messages) {
15
- if (!feedbackId)
16
- return {};
17
- return {
18
- [feedbackId]: messages.map((message) => ({
19
- author: { id: message.author.role, name: message.author.name },
20
- body: message.body,
21
- createdAt: message.createdAt,
22
- id: message.id,
23
- updatedAt: message.editedAt ?? undefined,
24
- })),
25
- };
26
- }
27
- function canReply(feedbackId, summaries, detail) {
28
- if (detail?.id === feedbackId)
29
- return detail.canReply;
30
- return summaries.find((item) => item.id === feedbackId)?.canReply ?? false;
31
- }
32
- function requireSelectedId(selectedId) {
33
- if (!selectedId)
34
- throw new Error("Feedback selection is required.");
35
- return selectedId;
36
- }
37
- export { canReply, requireSelectedId, toCommentsByFeedbackId, toPresentationItem };
@@ -1,11 +0,0 @@
1
- import type { FeedbackAffectedScope, FeedbackType, FeedbackUrgency } from "./contract.js";
2
- /** What a feedback composer submits: the create request's fields plus the files to attach. */
3
- type FeedbackSubmitValues = {
4
- affectedScope: FeedbackAffectedScope;
5
- attachments: File[];
6
- description: string;
7
- subject: string;
8
- type: FeedbackType;
9
- urgency: FeedbackUrgency;
10
- };
11
- export type { FeedbackSubmitValues };
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- import { type FeedbackClientConfig } from "./client.js";
2
- import type { CommentItemData } from "./comment-types.js";
3
- import type { FeedbackItem, FeedbackSummary, FeedbackUpdateInput } from "./contract.js";
4
- import type { FeedbackSubmitValues } from "./feedback-composer-types.js";
5
- type FeedbackControllerConfig = FeedbackClientConfig & {
6
- cacheScope: string;
7
- };
8
- type FeedbackControllerOptions = {
9
- active: boolean;
10
- config: FeedbackControllerConfig;
11
- onFeedbackCreated?: (item: FeedbackItem) => void;
12
- };
13
- declare function useFeedbackController({ active, config, onFeedbackCreated }: FeedbackControllerOptions): {
14
- createMutation: import("@tanstack/react-query").UseMutationResult<FeedbackItem, Error, {
15
- queryRoot: readonly string[];
16
- values: FeedbackSubmitValues;
17
- }, unknown>;
18
- messageMutation: import("@tanstack/react-query").UseMutationResult<import("./contract.js").FeedbackMessage, Error, {
19
- body: string;
20
- feedbackId: string;
21
- queryRoot: readonly string[];
22
- }, void>;
23
- messageStates: Record<string, FeedbackMessageMutationState>;
24
- updateMutation: import("@tanstack/react-query").UseMutationResult<FeedbackItem, Error, {
25
- feedbackId: string;
26
- input: FeedbackUpdateInput;
27
- queryRoot: readonly string[];
28
- }, unknown>;
29
- withdrawMutation: import("@tanstack/react-query").UseMutationResult<FeedbackItem, Error, {
30
- feedbackId: string;
31
- queryRoot: readonly string[];
32
- }, unknown>;
33
- uploadStatus: string | undefined;
34
- getAttachmentUrl: (feedbackId: string, attachmentId: string) => Promise<string>;
35
- comments: Record<string, CommentItemData[]>;
36
- createFeedback: (values: FeedbackSubmitValues) => Promise<FeedbackItem>;
37
- createMessage: (feedbackId: string, body: string) => Promise<import("./contract.js").FeedbackMessage>;
38
- detailQuery: import("@tanstack/react-query").UseQueryResult<NoInfer<FeedbackItem>, Error>;
39
- items: import("./feedback-tracking-types.js").UserFeedbackItem[];
40
- itemsQuery: import("@tanstack/react-query").UseQueryResult<NoInfer<FeedbackSummary[]>, Error>;
41
- isMessageSubmitting: boolean;
42
- messageError: Error | null;
43
- selectedDetail: NoInfer<FeedbackItem> | undefined;
44
- selectedId: string | undefined;
45
- selectedSummary: FeedbackSummary | undefined;
46
- selectionScope: string;
47
- setSelectedId: (feedbackId: string | undefined) => void;
48
- summaries: FeedbackSummary[];
49
- updateFeedback: (feedbackId: string, input: FeedbackUpdateInput) => Promise<FeedbackItem>;
50
- withdrawFeedback: (feedbackId: string) => Promise<FeedbackItem>;
51
- };
52
- type FeedbackMessageMutationState = {
53
- error?: Error;
54
- isPending: boolean;
55
- };
56
- export { type FeedbackControllerConfig, useFeedbackController };