@devaccel-labs/app-comments-toolbar 1.0.0 → 1.3.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 (220) hide show
  1. package/README.md +152 -18
  2. package/dist/react.js +516 -61
  3. package/dist/server.js +342 -14
  4. package/dist/types/capture/api.d.ts +30 -0
  5. package/dist/types/capture/editor.d.ts +10 -0
  6. package/dist/types/capture/ignore.d.ts +19 -0
  7. package/dist/types/capture/index.d.ts +1 -0
  8. package/dist/types/capture/picker.d.ts +9 -0
  9. package/dist/types/capture/picture.d.ts +29 -0
  10. package/dist/types/capture/surface.d.ts +39 -0
  11. package/dist/types/core/index.d.ts +2 -2
  12. package/dist/types/core/resolve.d.ts +2 -1
  13. package/dist/types/core/types.d.ts +11 -0
  14. package/dist/types/debug-context.d.ts +7 -0
  15. package/dist/types/dictation.d.ts +9 -0
  16. package/dist/types/embed/controller.d.ts +61 -0
  17. package/dist/types/embed/index.d.ts +1 -0
  18. package/dist/types/embed/options.d.ts +35 -0
  19. package/dist/types/help/index.d.ts +1 -0
  20. package/dist/types/help/panel-index.d.ts +1 -0
  21. package/dist/types/help/panel-styles.d.ts +1 -0
  22. package/dist/types/help/panel.d.ts +4 -0
  23. package/dist/types/help/pill-styles.d.ts +11 -0
  24. package/dist/types/help/pill.d.ts +44 -0
  25. package/dist/types/help/react.d.ts +12 -0
  26. package/dist/types/help/requests.d.ts +2 -0
  27. package/dist/types/help/types.d.ts +119 -0
  28. package/dist/types/help/wire.d.ts +61 -0
  29. package/dist/types/native-wire.d.ts +63 -0
  30. package/dist/types/native.d.ts +43 -0
  31. package/dist/types/react.d.ts +8 -1
  32. package/dist/types/replay.d.ts +6 -0
  33. package/dist/types/runtime/api.d.ts +250 -0
  34. package/dist/types/runtime/attachment-model.d.ts +16 -0
  35. package/dist/types/runtime/attachments.d.ts +43 -7
  36. package/dist/types/runtime/boot.d.ts +39 -0
  37. package/dist/types/runtime/browser-label.d.ts +5 -0
  38. package/dist/types/runtime/build-id.d.ts +7 -0
  39. package/dist/types/runtime/capture-ui.d.ts +45 -21
  40. package/dist/types/runtime/clarity-model.d.ts +260 -0
  41. package/dist/types/runtime/clarity-ui.d.ts +62 -0
  42. package/dist/types/runtime/client.d.ts +6 -197
  43. package/dist/types/runtime/composer-size.d.ts +30 -0
  44. package/dist/types/runtime/dashboard.d.ts +17 -2
  45. package/dist/types/runtime/debug-context-core.d.ts +88 -0
  46. package/dist/types/runtime/debug-context-host.d.ts +39 -0
  47. package/dist/types/runtime/debug-context-model.d.ts +352 -0
  48. package/dist/types/runtime/debug-context-redact.d.ts +48 -0
  49. package/dist/types/runtime/debug-context.d.ts +36 -0
  50. package/dist/types/runtime/details-model.d.ts +7 -0
  51. package/dist/types/runtime/details.d.ts +7 -5
  52. package/dist/types/runtime/dictation-engine.d.ts +98 -0
  53. package/dist/types/runtime/dictation-model.d.ts +28 -0
  54. package/dist/types/runtime/dictation-ui.d.ts +56 -0
  55. package/dist/types/runtime/dictation.d.ts +66 -0
  56. package/dist/types/runtime/draft-dock.d.ts +32 -0
  57. package/dist/types/runtime/draft-model.d.ts +104 -0
  58. package/dist/types/runtime/draft-store.d.ts +15 -0
  59. package/dist/types/runtime/edits.d.ts +1 -1
  60. package/dist/types/runtime/font.d.ts +16 -0
  61. package/dist/types/runtime/format.d.ts +30 -1
  62. package/dist/types/runtime/host-watch.d.ts +20 -0
  63. package/dist/types/runtime/icons.d.ts +16 -2
  64. package/dist/types/runtime/index.d.ts +3 -1
  65. package/dist/types/runtime/ink.d.ts +8 -0
  66. package/dist/types/runtime/kind-model.d.ts +14 -0
  67. package/dist/types/runtime/live-model.d.ts +25 -0
  68. package/dist/types/runtime/loader.d.ts +5 -11
  69. package/dist/types/runtime/markup-editor.d.ts +54 -0
  70. package/dist/types/runtime/markup-model.d.ts +126 -0
  71. package/dist/types/runtime/markup.d.ts +69 -0
  72. package/dist/types/runtime/mention-parse.d.ts +18 -0
  73. package/dist/types/runtime/mentions.d.ts +4 -4
  74. package/dist/types/runtime/page-background.d.ts +9 -0
  75. package/dist/types/runtime/page-image.d.ts +123 -0
  76. package/dist/types/runtime/placement.d.ts +6 -3
  77. package/dist/types/runtime/record.d.ts +18 -2
  78. package/dist/types/runtime/related.d.ts +1 -1
  79. package/dist/types/runtime/replay-model.d.ts +80 -0
  80. package/dist/types/runtime/replay.d.ts +5 -38
  81. package/dist/types/runtime/runtime.d.ts +6 -0
  82. package/dist/types/runtime/screen.d.ts +47 -0
  83. package/dist/types/runtime/screenshot.d.ts +60 -6
  84. package/dist/types/runtime/session-source.d.ts +45 -0
  85. package/dist/types/runtime/session.d.ts +20 -18
  86. package/dist/types/runtime/shield.d.ts +9 -0
  87. package/dist/types/runtime/shot.d.ts +45 -0
  88. package/dist/types/runtime/sketch.d.ts +26 -0
  89. package/dist/types/runtime/styles.d.ts +1 -1
  90. package/dist/types/runtime/sync.d.ts +1 -0
  91. package/dist/types/runtime/thread-model.d.ts +18 -0
  92. package/dist/types/runtime/ticket-form-model.d.ts +57 -0
  93. package/dist/types/runtime/ticket-form.d.ts +9 -0
  94. package/dist/types/runtime/toolbar.d.ts +37 -1
  95. package/dist/types/runtime/ui-scale.d.ts +17 -0
  96. package/dist/types/runtime/update.d.ts +37 -0
  97. package/dist/types/runtime/use-debug-context.d.ts +27 -0
  98. package/dist/types/server/index.d.ts +22 -0
  99. package/dist/types/server/support.d.ts +20 -0
  100. package/dist/types/server.d.ts +2 -0
  101. package/dist/types/vite/plugin.d.ts +15 -0
  102. package/dist/vite.js +121 -41
  103. package/package.json +26 -13
  104. package/src/capture/api.ts +128 -0
  105. package/src/capture/editor.tsx +178 -0
  106. package/src/capture/ignore.ts +38 -0
  107. package/src/capture/index.ts +27 -0
  108. package/src/capture/picker.tsx +171 -0
  109. package/src/capture/picture.ts +90 -0
  110. package/src/capture/surface.tsx +185 -0
  111. package/src/compiler/annotate.ts +202 -0
  112. package/src/compiler/babel.d.ts +11 -0
  113. package/src/compiler/enabled.ts +55 -0
  114. package/src/compiler/index.ts +2 -0
  115. package/src/core/index.ts +8 -0
  116. package/src/core/resolve.ts +307 -0
  117. package/src/core/types.ts +58 -0
  118. package/src/debug-context.ts +47 -0
  119. package/src/dictation.ts +17 -0
  120. package/src/embed/controller.ts +215 -0
  121. package/src/embed/index.ts +68 -0
  122. package/src/embed/options.ts +100 -0
  123. package/src/help/index.ts +38 -0
  124. package/src/help/panel-index.ts +17 -0
  125. package/src/help/panel-styles.ts +123 -0
  126. package/src/help/panel.ts +840 -0
  127. package/src/help/pill-styles.ts +75 -0
  128. package/src/help/pill.ts +338 -0
  129. package/src/help/react.tsx +143 -0
  130. package/src/help/requests.ts +111 -0
  131. package/src/help/types.ts +124 -0
  132. package/src/help/wire.ts +55 -0
  133. package/src/native-wire.ts +124 -0
  134. package/src/native.ts +282 -0
  135. package/src/react.ts +27 -0
  136. package/src/replay.ts +13 -0
  137. package/src/runtime/api.ts +531 -0
  138. package/src/runtime/attachment-model.ts +42 -0
  139. package/src/runtime/attachments.tsx +1260 -0
  140. package/src/runtime/boot.ts +95 -0
  141. package/src/runtime/browser-label.ts +31 -0
  142. package/src/runtime/build-id.ts +10 -0
  143. package/src/runtime/capture-ui.tsx +306 -0
  144. package/src/runtime/capture.ts +508 -0
  145. package/src/runtime/clarity-model.ts +634 -0
  146. package/src/runtime/clarity-ui.tsx +454 -0
  147. package/src/runtime/client.ts +151 -0
  148. package/src/runtime/composer-size.tsx +146 -0
  149. package/src/runtime/dashboard.tsx +1130 -0
  150. package/src/runtime/debug-context-core.ts +681 -0
  151. package/src/runtime/debug-context-host.ts +56 -0
  152. package/src/runtime/debug-context-model.ts +1319 -0
  153. package/src/runtime/debug-context-redact.ts +259 -0
  154. package/src/runtime/debug-context.ts +613 -0
  155. package/src/runtime/details-model.ts +30 -0
  156. package/src/runtime/details.tsx +395 -0
  157. package/src/runtime/dictation-engine.ts +616 -0
  158. package/src/runtime/dictation-model.ts +79 -0
  159. package/src/runtime/dictation-ui.tsx +363 -0
  160. package/src/runtime/dictation.ts +271 -0
  161. package/src/runtime/dock.ts +108 -0
  162. package/src/runtime/draft-dock.tsx +124 -0
  163. package/src/runtime/draft-model.ts +251 -0
  164. package/src/runtime/draft-store.ts +149 -0
  165. package/src/runtime/edits.tsx +165 -0
  166. package/src/runtime/font.ts +42 -0
  167. package/src/runtime/format.ts +129 -0
  168. package/src/runtime/freshness.ts +23 -0
  169. package/src/runtime/handoff.ts +76 -0
  170. package/src/runtime/host-watch.ts +64 -0
  171. package/src/runtime/icons.tsx +295 -0
  172. package/src/runtime/idle.ts +20 -0
  173. package/src/runtime/index.ts +11 -0
  174. package/src/runtime/ink.ts +6 -0
  175. package/src/runtime/kind-model.ts +20 -0
  176. package/src/runtime/live-model.ts +32 -0
  177. package/src/runtime/loader.tsx +87 -0
  178. package/src/runtime/markup-editor.tsx +1333 -0
  179. package/src/runtime/markup-model.ts +485 -0
  180. package/src/runtime/markup.ts +382 -0
  181. package/src/runtime/members.ts +58 -0
  182. package/src/runtime/mention-parse.ts +56 -0
  183. package/src/runtime/mentions.tsx +205 -0
  184. package/src/runtime/page-background.ts +51 -0
  185. package/src/runtime/page-image.ts +1592 -0
  186. package/src/runtime/placement.ts +336 -0
  187. package/src/runtime/record.ts +402 -0
  188. package/src/runtime/redact.ts +30 -0
  189. package/src/runtime/related.ts +34 -0
  190. package/src/runtime/render-page.ts +2 -0
  191. package/src/runtime/replay-model.ts +232 -0
  192. package/src/runtime/replay.ts +173 -0
  193. package/src/runtime/runtime-version.ts +7 -0
  194. package/src/runtime/runtime.tsx +51 -0
  195. package/src/runtime/screen.ts +182 -0
  196. package/src/runtime/screenshot.ts +260 -0
  197. package/src/runtime/session-source.ts +112 -0
  198. package/src/runtime/session.ts +108 -0
  199. package/src/runtime/shield.ts +34 -0
  200. package/src/runtime/shot.tsx +422 -0
  201. package/src/runtime/sketch.ts +139 -0
  202. package/src/runtime/styles.ts +1541 -0
  203. package/src/runtime/sync.ts +300 -0
  204. package/src/runtime/thread-model.ts +71 -0
  205. package/src/runtime/ticket-form-model.ts +128 -0
  206. package/src/runtime/ticket-form.tsx +342 -0
  207. package/src/runtime/toolbar.tsx +4427 -0
  208. package/src/runtime/ui-scale.ts +75 -0
  209. package/src/runtime/update.ts +98 -0
  210. package/src/runtime/use-debug-context.ts +81 -0
  211. package/src/server/index.ts +133 -0
  212. package/src/server/support.ts +499 -0
  213. package/src/server.ts +4 -0
  214. package/src/vite/plugin.ts +102 -0
  215. package/src/vite.ts +1 -0
  216. package/dist/chunks/chunk-CSKXLF33.js +0 -153
  217. package/dist/chunks/chunk-HUM5FQII.js +0 -160
  218. package/dist/chunks/render-page-76MLIT6M.js +0 -1421
  219. package/dist/chunks/runtime-JX75TKER.js +0 -9267
  220. package/dist/chunks/screenshot-66ARTBGR.js +0 -12
@@ -0,0 +1,395 @@
1
+ import { useState, type KeyboardEvent as ReactKeyboardEvent } from "react";
2
+ import type { Details, FieldDef, FieldValue, Settings, Thread } from "./client.js";
3
+ import * as Icon from "./icons.js";
4
+
5
+ import { detailsEnabled } from "./details-model.js";
6
+ import { REPORT_KINDS, type ReportKind } from "./kind-model.js";
7
+
8
+ export { detailsEnabled, detailsPayload, hasFieldValues, noDetails } from "./details-model.js";
9
+
10
+ function fieldId(label: string, taken: FieldDef[]) {
11
+ const base =
12
+ label
13
+ .toLowerCase()
14
+ .replace(/[^a-z0-9]+/g, "-")
15
+ .replace(/^-+|-+$/g, "")
16
+ .slice(0, 32) || "field";
17
+ let id = base;
18
+ for (let n = 2; taken.some((field) => field.id === id); n += 1) id = `${base}-${n}`;
19
+ return id;
20
+ }
21
+
22
+ export function DetailsInput({
23
+ settings,
24
+ value,
25
+ onChange,
26
+ onKeyDown,
27
+ }: {
28
+ settings: Settings | null;
29
+ value: Details;
30
+ onChange: (next: Details) => void;
31
+ onKeyDown?: (event: ReactKeyboardEvent<HTMLTextAreaElement>) => void;
32
+ }) {
33
+ if (!settings || !detailsEnabled(settings)) return null;
34
+ const roles = settings.roles.enabled ? settings.roles.options : [];
35
+ const fields = settings.fields.enabled ? settings.fields.items : [];
36
+ return (
37
+ <div className="cs-details-input" data-cs-ui="details-input">
38
+ {fields.map((field) => (
39
+ <label key={field.id} className="cs-detail-field">
40
+ <span>{field.label}</span>
41
+ <textarea
42
+ data-cs-ui={`field-${field.id}`}
43
+ rows={1}
44
+ maxLength={4000}
45
+ value={value.fields[field.id] ?? ""}
46
+ onChange={(event) =>
47
+ onChange({ ...value, fields: { ...value.fields, [field.id]: event.target.value } })
48
+ }
49
+ onKeyDown={onKeyDown}
50
+ />
51
+ </label>
52
+ ))}
53
+ {roles.length ? (
54
+ <div className="cs-roles" role="radiogroup" aria-label="Role">
55
+ <span className="cs-roles-label">Role</span>
56
+ {roles.map((role) => (
57
+ <button
58
+ key={role}
59
+ type="button"
60
+ role="radio"
61
+ data-cs-ui="role-option"
62
+ aria-checked={value.role === role}
63
+ className={value.role === role ? "cs-chip is-on" : "cs-chip"}
64
+ onClick={() => onChange({ ...value, role: value.role === role ? null : role })}
65
+ >
66
+ {role}
67
+ </button>
68
+ ))}
69
+ </div>
70
+ ) : null}
71
+ </div>
72
+ );
73
+ }
74
+
75
+ /** A new comment's kind, if the person wants to say; pressing the chosen one again leaves it to the service. */
76
+ export function KindInput({
77
+ value,
78
+ onChange,
79
+ }: {
80
+ value: ReportKind | null;
81
+ onChange: (next: ReportKind | null) => void;
82
+ }) {
83
+ return (
84
+ <div
85
+ className="cs-roles cs-kind-input"
86
+ role="radiogroup"
87
+ aria-label="Kind"
88
+ data-cs-ui="kind-input"
89
+ >
90
+ <span className="cs-roles-label">Kind</span>
91
+ {REPORT_KINDS.map(({ kind, label }) => (
92
+ <button
93
+ key={kind}
94
+ type="button"
95
+ role="radio"
96
+ data-cs-ui={`kind-${kind}`}
97
+ aria-checked={value === kind}
98
+ className={value === kind ? "cs-chip is-on" : "cs-chip"}
99
+ onClick={() => onChange(value === kind ? null : kind)}
100
+ >
101
+ {label}
102
+ </button>
103
+ ))}
104
+ </div>
105
+ );
106
+ }
107
+
108
+ export function RoleBadge({ role }: { role: string | null }) {
109
+ return role ? (
110
+ <span className="cs-role" data-cs-ui="role">
111
+ {role}
112
+ </span>
113
+ ) : null;
114
+ }
115
+
116
+ /** "Ticket I00012 · In progress": the team turned this comment into a support ticket. */
117
+ export function TicketBadge({
118
+ ticket,
119
+ }: {
120
+ ticket?: { number: string; status: string; label: string };
121
+ }) {
122
+ return ticket ? (
123
+ <span
124
+ className={ticket.status === "closed" ? "cs-ticket is-closed" : "cs-ticket"}
125
+ data-cs-ui="ticket"
126
+ title={`Support ticket ${ticket.number}: ${ticket.label}`}
127
+ >
128
+ Ticket {ticket.number} · {ticket.label}
129
+ </span>
130
+ ) : null;
131
+ }
132
+
133
+ export function FieldValues({ fields, clamp = false }: { fields: FieldValue[]; clamp?: boolean }) {
134
+ if (!fields.length) return null;
135
+ return (
136
+ <dl className={clamp ? "cs-detail-list is-clamped" : "cs-detail-list"} data-cs-ui="fields">
137
+ {fields.map((field) => (
138
+ <div key={field.id}>
139
+ <dt>{field.label}</dt>
140
+ <dd>{field.value}</dd>
141
+ </div>
142
+ ))}
143
+ </dl>
144
+ );
145
+ }
146
+
147
+ /** Inline editor for a posted comment's role and fields. Values for fields that were since removed are kept by the server. */
148
+ export function DetailsEditor({
149
+ settings,
150
+ thread,
151
+ onSave,
152
+ onClose,
153
+ }: {
154
+ settings: Settings;
155
+ thread: Thread;
156
+ onSave: (patch: Partial<Details>) => Promise<void>;
157
+ onClose: () => void;
158
+ }) {
159
+ const [value, setValue] = useState<Details>(() => ({
160
+ role: thread.role,
161
+ fields: Object.fromEntries(thread.fields.map((field) => [field.id, field.value])),
162
+ }));
163
+ const [busy, setBusy] = useState(false);
164
+ return (
165
+ <form
166
+ className="cs-details-edit"
167
+ data-cs-ui="details-editor"
168
+ onSubmit={(event) => {
169
+ event.preventDefault();
170
+ const patch: Partial<Details> = {};
171
+ if (settings.roles.enabled && value.role !== thread.role) patch.role = value.role;
172
+ if (settings.fields.enabled) {
173
+ patch.fields = Object.fromEntries(
174
+ settings.fields.items.map((field) => [field.id, value.fields[field.id] ?? ""]),
175
+ );
176
+ }
177
+ setBusy(true);
178
+ onSave(patch)
179
+ .then(onClose)
180
+ .finally(() => setBusy(false));
181
+ }}
182
+ >
183
+ <DetailsInput settings={settings} value={value} onChange={setValue} />
184
+ <div className="cs-row-end">
185
+ <button className="cs-button" type="button" onClick={onClose}>
186
+ Cancel
187
+ </button>
188
+ <button
189
+ className="cs-button is-primary"
190
+ data-cs-ui="details-save"
191
+ type="submit"
192
+ disabled={busy}
193
+ >
194
+ Save
195
+ </button>
196
+ </div>
197
+ </form>
198
+ );
199
+ }
200
+
201
+ function AddRow({
202
+ label,
203
+ hook,
204
+ onAdd,
205
+ }: {
206
+ label: string;
207
+ hook: string;
208
+ onAdd: (text: string) => void;
209
+ }) {
210
+ const [text, setText] = useState("");
211
+ return (
212
+ <form
213
+ className="cs-add-row"
214
+ onSubmit={(event) => {
215
+ event.preventDefault();
216
+ const next = text.trim().replace(/\s+/g, " ");
217
+ if (!next) return;
218
+ onAdd(next);
219
+ setText("");
220
+ }}
221
+ >
222
+ <input
223
+ data-cs-ui={hook}
224
+ aria-label={label}
225
+ placeholder={label}
226
+ value={text}
227
+ maxLength={60}
228
+ onChange={(event) => setText(event.target.value)}
229
+ />
230
+ <button className="cs-icon-button" type="submit" aria-label={label} disabled={!text.trim()}>
231
+ <Icon.Check />
232
+ </button>
233
+ </form>
234
+ );
235
+ }
236
+
237
+ /** Shared per environment: anyone signed in can change it, and existing comments keep their values. */
238
+ export function SettingsPanel({
239
+ settings,
240
+ onChange,
241
+ onBack,
242
+ error,
243
+ }: {
244
+ settings: Settings | null;
245
+ onChange: (next: Settings) => void;
246
+ /** Without a back button the panel renders inline, e.g. inside the dashboard. */
247
+ onBack?: () => void;
248
+ error: string;
249
+ }) {
250
+ return (
251
+ <section
252
+ className={onBack ? "cs-card cs-menu cs-settings cs-hit" : "cs-settings is-inline"}
253
+ data-cs-ui="settings"
254
+ aria-label="Comment fields"
255
+ >
256
+ <header className="cs-settings-head">
257
+ {onBack ? (
258
+ <button className="cs-icon-button" type="button" aria-label="Back" onClick={onBack}>
259
+ <Icon.Back />
260
+ </button>
261
+ ) : null}
262
+ <h2>Comment fields</h2>
263
+ </header>
264
+ {!settings ? (
265
+ <p className="cs-hint">Loading…</p>
266
+ ) : (
267
+ <>
268
+ <button
269
+ className="cs-item"
270
+ data-cs-ui="roles-toggle"
271
+ type="button"
272
+ role="switch"
273
+ aria-checked={settings.roles.enabled}
274
+ onClick={() =>
275
+ onChange({
276
+ ...settings,
277
+ roles: { ...settings.roles, enabled: !settings.roles.enabled },
278
+ })
279
+ }
280
+ >
281
+ <span>Role</span>
282
+ <span className={settings.roles.enabled ? "cs-switch is-on" : "cs-switch"} />
283
+ </button>
284
+ {settings.roles.enabled ? (
285
+ <div className="cs-settings-body">
286
+ {settings.roles.options.length ? (
287
+ <div className="cs-chips">
288
+ {settings.roles.options.map((role) => (
289
+ <span key={role} className="cs-chip is-static" data-cs-ui="role-chip">
290
+ {role}
291
+ <button
292
+ type="button"
293
+ aria-label={`Remove ${role}`}
294
+ onClick={() =>
295
+ onChange({
296
+ ...settings,
297
+ roles: {
298
+ ...settings.roles,
299
+ options: settings.roles.options.filter((item) => item !== role),
300
+ },
301
+ })
302
+ }
303
+ >
304
+ <Icon.Close />
305
+ </button>
306
+ </span>
307
+ ))}
308
+ </div>
309
+ ) : null}
310
+ <AddRow
311
+ label="Add a role"
312
+ hook="role-add"
313
+ onAdd={(role) => {
314
+ if (
315
+ settings.roles.options.some((item) => item.toLowerCase() === role.toLowerCase())
316
+ )
317
+ return;
318
+ onChange({
319
+ ...settings,
320
+ roles: {
321
+ ...settings.roles,
322
+ options: [...settings.roles.options, role.slice(0, 40)],
323
+ },
324
+ });
325
+ }}
326
+ />
327
+ </div>
328
+ ) : null}
329
+ <div className="cs-sep" />
330
+ <button
331
+ className="cs-item"
332
+ data-cs-ui="fields-toggle"
333
+ type="button"
334
+ role="switch"
335
+ aria-checked={settings.fields.enabled}
336
+ onClick={() =>
337
+ onChange({
338
+ ...settings,
339
+ fields: { ...settings.fields, enabled: !settings.fields.enabled },
340
+ })
341
+ }
342
+ >
343
+ <span>Custom fields</span>
344
+ <span className={settings.fields.enabled ? "cs-switch is-on" : "cs-switch"} />
345
+ </button>
346
+ {settings.fields.enabled ? (
347
+ <div className="cs-settings-body">
348
+ {settings.fields.items.map((field) => (
349
+ <div key={field.id} className="cs-field-row" data-cs-ui="field-def">
350
+ <span>{field.label}</span>
351
+ <button
352
+ className="cs-icon-button"
353
+ type="button"
354
+ aria-label={`Remove ${field.label}`}
355
+ onClick={() =>
356
+ onChange({
357
+ ...settings,
358
+ fields: {
359
+ ...settings.fields,
360
+ items: settings.fields.items.filter((item) => item.id !== field.id),
361
+ },
362
+ })
363
+ }
364
+ >
365
+ <Icon.Close />
366
+ </button>
367
+ </div>
368
+ ))}
369
+ <AddRow
370
+ label="Add a field"
371
+ hook="field-add"
372
+ onAdd={(label) =>
373
+ onChange({
374
+ ...settings,
375
+ fields: {
376
+ ...settings.fields,
377
+ items: [
378
+ ...settings.fields.items,
379
+ { id: fieldId(label, settings.fields.items), label },
380
+ ],
381
+ },
382
+ })
383
+ }
384
+ />
385
+ </div>
386
+ ) : null}
387
+ {error ? <p className="cs-error cs-pad">{error}</p> : null}
388
+ <p className="cs-hint">
389
+ Shared with everyone here. Turning off or removing only affects new comments.
390
+ </p>
391
+ </>
392
+ )}
393
+ </section>
394
+ );
395
+ }