@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,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";