@ciridae/ui 1.3.0 → 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 (60) 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 +3 -42
  16. package/dist/components/locale.js +3 -48
  17. package/dist/components/log-list.d.ts +0 -2
  18. package/dist/components/log-list.js +0 -22
  19. package/dist/components/record.d.ts +0 -23
  20. package/dist/components/record.js +2 -80
  21. package/dist/components/sidebar.d.ts +0 -1
  22. package/dist/components/sidebar.js +0 -10
  23. package/dist/components/tabs.d.ts +0 -3
  24. package/dist/components/tabs.js +0 -4
  25. package/dist/feedback/contract.d.ts +1 -25
  26. package/dist/feedback/contract.js +2 -6
  27. package/dist/feedback/operator-controller.d.ts +3 -10
  28. package/dist/feedback/operator-controller.js +1 -28
  29. package/dist/preset.d.ts +0 -6
  30. package/dist/preset.js +0 -5
  31. package/dist/styled-system/styles.css +20 -82
  32. package/dist/theme/options.d.ts +1 -19
  33. package/dist/theme/options.js +0 -1
  34. package/dist/theme/tokens.d.ts +1 -8
  35. package/dist/theme/tokens.js +1 -17
  36. package/package.json +1 -49
  37. package/dist/components/profile-header.d.ts +0 -15
  38. package/dist/components/profile-header.js +0 -40
  39. package/dist/components/recent-items.d.ts +0 -28
  40. package/dist/components/recent-items.js +0 -63
  41. package/dist/components/theme-customizer.d.ts +0 -50
  42. package/dist/components/theme-customizer.js +0 -84
  43. package/dist/components/theme-toggle.d.ts +0 -3
  44. package/dist/components/theme-toggle.js +0 -65
  45. package/dist/feedback/comment-types.d.ts +0 -17
  46. package/dist/feedback/comment-types.js +0 -1
  47. package/dist/feedback/feedback-cache.d.ts +0 -6
  48. package/dist/feedback/feedback-cache.js +0 -58
  49. package/dist/feedback/feedback-center-model.d.ts +0 -8
  50. package/dist/feedback/feedback-center-model.js +0 -37
  51. package/dist/feedback/feedback-composer-types.d.ts +0 -11
  52. package/dist/feedback/feedback-composer-types.js +0 -1
  53. package/dist/feedback/feedback-controller.d.ts +0 -56
  54. package/dist/feedback/feedback-controller.js +0 -181
  55. package/dist/feedback/feedback-tracking-types.d.ts +0 -14
  56. package/dist/feedback/feedback-tracking-types.js +0 -1
  57. package/dist/feedback/submit-feedback-with-attachments.d.ts +0 -10
  58. package/dist/feedback/submit-feedback-with-attachments.js +0 -10
  59. package/dist/theme/index.d.ts +0 -3
  60. package/dist/theme/index.js +0 -7
@@ -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 };
@@ -1,181 +0,0 @@
1
- import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
- import * as React from "react";
3
- import { createFeedbackClient } from "./client.js";
4
- import { appendFeedbackMessage, cacheCreatedFeedbackItem, refreshFeedbackItem, } from "./feedback-cache.js";
5
- import { canReply, requireSelectedId, toCommentsByFeedbackId, toPresentationItem, } from "./feedback-center-model.js";
6
- import { requireConfig } from "./require-config.js";
7
- import { submitFeedbackWithAttachments } from "./submit-feedback-with-attachments.js";
8
- function useFeedbackController({ active, config, onFeedbackCreated }) {
9
- const client = useFeedbackClient(config);
10
- const normalizedCacheScope = requireConfig(config.cacheScope, "cacheScope");
11
- const queryClient = useQueryClient();
12
- const queryRoot = React.useMemo(() => ["feedback", client.baseUrl, normalizedCacheScope], [client.baseUrl, normalizedCacheScope]);
13
- const selectionScope = JSON.stringify([client.baseUrl, normalizedCacheScope]);
14
- const [selection, setSelection] = React.useState({ scope: selectionScope });
15
- React.useEffect(() => {
16
- setSelection((current) => current.scope === selectionScope ? current : { scope: selectionScope });
17
- }, [selectionScope]);
18
- const selectedId = selection.scope === selectionScope ? selection.feedbackId : undefined;
19
- const { detailQuery, itemsQuery } = useFeedbackQueries(client, queryRoot, active, selectedId);
20
- const mutations = useFeedbackMutations({ client, onFeedbackCreated, queryClient });
21
- const summaries = itemsQuery.data ?? [];
22
- const selectedSummary = summaries.find((item) => item.id === selectedId);
23
- const selectedDetail = detailQuery.data?.id === selectedId ? detailQuery.data : undefined;
24
- const comments = selectedDetail
25
- ? toCommentsByFeedbackId(selectedDetail.id, selectedDetail.messages)
26
- : {};
27
- const createFeedback = (values) => mutations.createMutation.mutateAsync({ queryRoot, values });
28
- const createMessage = (feedbackId, body) => mutations.messageMutation.mutateAsync({ body, feedbackId, queryRoot });
29
- const messageState = getMessageState(mutations.messageStates, queryRoot, selectedId);
30
- const isMessageSubmitting = messageState?.isPending ?? false;
31
- const messageError = getMessageError(messageState, selectedId, summaries, detailQuery.data);
32
- const updateFeedback = (feedbackId, input) => mutations.updateMutation.mutateAsync({ feedbackId, input, queryRoot });
33
- const withdrawFeedback = (feedbackId) => mutations.withdrawMutation.mutateAsync({ feedbackId, queryRoot });
34
- const setSelectedId = (feedbackId) => setSelection({ feedbackId, scope: selectionScope });
35
- return {
36
- getAttachmentUrl: (feedbackId, attachmentId) => client.getAttachmentUrl(feedbackId, attachmentId),
37
- comments,
38
- createFeedback,
39
- createMessage,
40
- detailQuery,
41
- items: summaries.map(toPresentationItem),
42
- itemsQuery,
43
- isMessageSubmitting,
44
- messageError,
45
- selectedDetail,
46
- selectedId,
47
- selectedSummary,
48
- selectionScope,
49
- setSelectedId,
50
- summaries,
51
- updateFeedback,
52
- withdrawFeedback,
53
- ...mutations,
54
- };
55
- }
56
- function useFeedbackClient({ baseUrl, getBearerToken }) {
57
- return React.useMemo(() => createFeedbackClient({ baseUrl, getBearerToken }), [baseUrl, getBearerToken]);
58
- }
59
- function useFeedbackQueries(client, queryRoot, active, selectedId) {
60
- const itemsQuery = useQuery({
61
- queryKey: [...queryRoot, "items"],
62
- queryFn: ({ signal }) => client.list({ signal }),
63
- enabled: active,
64
- retry: false,
65
- });
66
- const detailQuery = useQuery({
67
- queryKey: [...queryRoot, "item", selectedId],
68
- queryFn: ({ signal }) => client.get(requireSelectedId(selectedId), { signal }),
69
- enabled: active && selectedId !== undefined,
70
- retry: false,
71
- });
72
- return { detailQuery, itemsQuery };
73
- }
74
- function useFeedbackMutations({ client, onFeedbackCreated, queryClient, }) {
75
- const [uploadStatus, setUploadStatus] = React.useState();
76
- const pendingCreate = React.useRef(undefined);
77
- const { messageMutation, messageStates } = useFeedbackMessageMutation(client, queryClient);
78
- const createMutation = useMutation({
79
- mutationFn: ({ queryRoot, values, }) => {
80
- const input = {
81
- affectedScope: values.affectedScope,
82
- description: values.description,
83
- subject: values.subject,
84
- type: values.type,
85
- urgency: values.urgency,
86
- };
87
- const fingerprint = JSON.stringify([queryRoot, input]);
88
- const idempotencyKey = pendingCreate.current?.fingerprint === fingerprint
89
- ? pendingCreate.current.idempotencyKey
90
- : crypto.randomUUID();
91
- pendingCreate.current = { fingerprint, idempotencyKey };
92
- return submitFeedbackWithAttachments({
93
- client,
94
- input,
95
- idempotencyKey,
96
- files: values.attachments,
97
- onStatus: setUploadStatus,
98
- });
99
- },
100
- onSuccess: (item, { queryRoot }) => {
101
- pendingCreate.current = undefined;
102
- void cacheCreatedFeedbackItem(queryClient, queryRoot, item).catch(() => undefined);
103
- notifyFeedbackCreated(onFeedbackCreated, item);
104
- },
105
- });
106
- const updateMutation = useMutation({
107
- mutationFn: ({ feedbackId, input, }) => client.update(feedbackId, input),
108
- onSuccess: (item, input) => {
109
- void refreshFeedbackItem(queryClient, input.queryRoot, item).catch(() => undefined);
110
- },
111
- });
112
- const withdrawMutation = useMutation({
113
- mutationFn: ({ feedbackId }) => client.withdraw(feedbackId),
114
- onSuccess: (item, input) => {
115
- void refreshFeedbackItem(queryClient, input.queryRoot, item).catch(() => undefined);
116
- },
117
- });
118
- return {
119
- createMutation,
120
- messageMutation,
121
- messageStates,
122
- updateMutation,
123
- withdrawMutation,
124
- uploadStatus,
125
- };
126
- }
127
- function useFeedbackMessageMutation(client, queryClient) {
128
- const [messageStates, setMessageStates] = React.useState({});
129
- const messageMutation = useMutation({
130
- mutationFn: ({ body, feedbackId, }) => client.createMessage(feedbackId, body),
131
- onMutate: (input) => {
132
- setMessageStates((current) => ({
133
- ...current,
134
- [messageErrorKey(input.queryRoot, input.feedbackId)]: { isPending: true },
135
- }));
136
- },
137
- onError: (error, input) => {
138
- setMessageStates((current) => ({
139
- ...current,
140
- [messageErrorKey(input.queryRoot, input.feedbackId)]: {
141
- error,
142
- isPending: false,
143
- },
144
- }));
145
- },
146
- onSuccess: (message, input) => {
147
- setMessageStates((current) => {
148
- const key = messageErrorKey(input.queryRoot, input.feedbackId);
149
- if (current[key] === undefined)
150
- return current;
151
- const next = { ...current };
152
- delete next[key];
153
- return next;
154
- });
155
- void appendFeedbackMessage(queryClient, input.queryRoot, input.feedbackId, message).catch(() => undefined);
156
- },
157
- });
158
- return { messageMutation, messageStates };
159
- }
160
- function messageErrorKey(queryRoot, feedbackId) {
161
- return JSON.stringify([...queryRoot, "message", feedbackId]);
162
- }
163
- function getMessageState(messageStates, queryRoot, selectedId) {
164
- return selectedId === undefined
165
- ? undefined
166
- : messageStates[messageErrorKey(queryRoot, selectedId)];
167
- }
168
- function getMessageError(messageState, selectedId, summaries, detail) {
169
- return selectedId !== undefined && canReply(selectedId, summaries, detail)
170
- ? (messageState?.error ?? null)
171
- : null;
172
- }
173
- function notifyFeedbackCreated(onFeedbackCreated, item) {
174
- try {
175
- void Promise.resolve(onFeedbackCreated?.(item)).catch(() => undefined);
176
- }
177
- catch {
178
- // A consumer observer cannot turn a durable create into a failed retry.
179
- }
180
- }
181
- export { useFeedbackController };
@@ -1,14 +0,0 @@
1
- import type { FeedbackAffectedScope, FeedbackStatus, FeedbackType, FeedbackUrgency } from "./contract.js";
2
- /** A submitted feedback item in the shape a reporter's tracking list renders. */
3
- type UserFeedbackItem = {
4
- affectedScope?: FeedbackAffectedScope;
5
- description: string;
6
- id: string;
7
- status: FeedbackStatus;
8
- subject: string;
9
- submittedAt: string;
10
- type: FeedbackType;
11
- updatedAt?: string;
12
- urgency?: FeedbackUrgency;
13
- };
14
- export type { UserFeedbackItem };
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import { type FeedbackClient } from "./client.js";
2
- import type { FeedbackCreateInput } from "./contract.js";
3
- declare function submitFeedbackWithAttachments({ client, input, idempotencyKey, files, onStatus, }: {
4
- client: FeedbackClient;
5
- input: FeedbackCreateInput;
6
- idempotencyKey: string;
7
- files: File[];
8
- onStatus: (status: string | undefined) => void;
9
- }): Promise<import("./contract.js").FeedbackItem>;
10
- export { submitFeedbackWithAttachments };
@@ -1,10 +0,0 @@
1
- async function submitFeedbackWithAttachments({ client, input, idempotencyKey, files, onStatus, }) {
2
- onStatus(files.length ? "Saving feedback and attachments…" : "Saving feedback…");
3
- try {
4
- return await client.create(input, { idempotencyKey, files });
5
- }
6
- finally {
7
- onStatus(undefined);
8
- }
9
- }
10
- export { submitFeedbackWithAttachments };
@@ -1,3 +0,0 @@
1
- export { breakpointQuery, breakpoints, type Breakpoint } from "./breakpoints.js";
2
- export { defaultTheme, type Brand, type CiridaeTheme, type ColorTheme } from "./options.js";
3
- export { deriveThemeTokens, type ThemeTokens } from "./tokens.js";
@@ -1,7 +0,0 @@
1
- /*
2
- * The theme at runtime: the breakpoints, the brand and theme options, and the token values the
3
- * preset is built from.
4
- */
5
- export { breakpointQuery, breakpoints } from "./breakpoints.js";
6
- export { defaultTheme } from "./options.js";
7
- export { deriveThemeTokens } from "./tokens.js";