@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.
- package/README.md +152 -18
- package/dist/react.js +516 -61
- package/dist/server.js +342 -14
- package/dist/types/capture/api.d.ts +30 -0
- package/dist/types/capture/editor.d.ts +10 -0
- package/dist/types/capture/ignore.d.ts +19 -0
- package/dist/types/capture/index.d.ts +1 -0
- package/dist/types/capture/picker.d.ts +9 -0
- package/dist/types/capture/picture.d.ts +29 -0
- package/dist/types/capture/surface.d.ts +39 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/resolve.d.ts +2 -1
- package/dist/types/core/types.d.ts +11 -0
- package/dist/types/debug-context.d.ts +7 -0
- package/dist/types/dictation.d.ts +9 -0
- package/dist/types/embed/controller.d.ts +61 -0
- package/dist/types/embed/index.d.ts +1 -0
- package/dist/types/embed/options.d.ts +35 -0
- package/dist/types/help/index.d.ts +1 -0
- package/dist/types/help/panel-index.d.ts +1 -0
- package/dist/types/help/panel-styles.d.ts +1 -0
- package/dist/types/help/panel.d.ts +4 -0
- package/dist/types/help/pill-styles.d.ts +11 -0
- package/dist/types/help/pill.d.ts +44 -0
- package/dist/types/help/react.d.ts +12 -0
- package/dist/types/help/requests.d.ts +2 -0
- package/dist/types/help/types.d.ts +119 -0
- package/dist/types/help/wire.d.ts +61 -0
- package/dist/types/native-wire.d.ts +63 -0
- package/dist/types/native.d.ts +43 -0
- package/dist/types/react.d.ts +8 -1
- package/dist/types/replay.d.ts +6 -0
- package/dist/types/runtime/api.d.ts +250 -0
- package/dist/types/runtime/attachment-model.d.ts +16 -0
- package/dist/types/runtime/attachments.d.ts +43 -7
- package/dist/types/runtime/boot.d.ts +39 -0
- package/dist/types/runtime/browser-label.d.ts +5 -0
- package/dist/types/runtime/build-id.d.ts +7 -0
- package/dist/types/runtime/capture-ui.d.ts +45 -21
- package/dist/types/runtime/clarity-model.d.ts +260 -0
- package/dist/types/runtime/clarity-ui.d.ts +62 -0
- package/dist/types/runtime/client.d.ts +6 -197
- package/dist/types/runtime/composer-size.d.ts +30 -0
- package/dist/types/runtime/dashboard.d.ts +17 -2
- package/dist/types/runtime/debug-context-core.d.ts +88 -0
- package/dist/types/runtime/debug-context-host.d.ts +39 -0
- package/dist/types/runtime/debug-context-model.d.ts +352 -0
- package/dist/types/runtime/debug-context-redact.d.ts +48 -0
- package/dist/types/runtime/debug-context.d.ts +36 -0
- package/dist/types/runtime/details-model.d.ts +7 -0
- package/dist/types/runtime/details.d.ts +7 -5
- package/dist/types/runtime/dictation-engine.d.ts +98 -0
- package/dist/types/runtime/dictation-model.d.ts +28 -0
- package/dist/types/runtime/dictation-ui.d.ts +56 -0
- package/dist/types/runtime/dictation.d.ts +66 -0
- package/dist/types/runtime/draft-dock.d.ts +32 -0
- package/dist/types/runtime/draft-model.d.ts +104 -0
- package/dist/types/runtime/draft-store.d.ts +15 -0
- package/dist/types/runtime/edits.d.ts +1 -1
- package/dist/types/runtime/font.d.ts +16 -0
- package/dist/types/runtime/format.d.ts +30 -1
- package/dist/types/runtime/host-watch.d.ts +20 -0
- package/dist/types/runtime/icons.d.ts +16 -2
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/ink.d.ts +8 -0
- package/dist/types/runtime/kind-model.d.ts +14 -0
- package/dist/types/runtime/live-model.d.ts +25 -0
- package/dist/types/runtime/loader.d.ts +5 -11
- package/dist/types/runtime/markup-editor.d.ts +54 -0
- package/dist/types/runtime/markup-model.d.ts +126 -0
- package/dist/types/runtime/markup.d.ts +69 -0
- package/dist/types/runtime/mention-parse.d.ts +18 -0
- package/dist/types/runtime/mentions.d.ts +4 -4
- package/dist/types/runtime/page-background.d.ts +9 -0
- package/dist/types/runtime/page-image.d.ts +123 -0
- package/dist/types/runtime/placement.d.ts +6 -3
- package/dist/types/runtime/record.d.ts +18 -2
- package/dist/types/runtime/related.d.ts +1 -1
- package/dist/types/runtime/replay-model.d.ts +80 -0
- package/dist/types/runtime/replay.d.ts +5 -38
- package/dist/types/runtime/runtime.d.ts +6 -0
- package/dist/types/runtime/screen.d.ts +47 -0
- package/dist/types/runtime/screenshot.d.ts +60 -6
- package/dist/types/runtime/session-source.d.ts +45 -0
- package/dist/types/runtime/session.d.ts +20 -18
- package/dist/types/runtime/shield.d.ts +9 -0
- package/dist/types/runtime/shot.d.ts +45 -0
- package/dist/types/runtime/sketch.d.ts +26 -0
- package/dist/types/runtime/styles.d.ts +1 -1
- package/dist/types/runtime/sync.d.ts +1 -0
- package/dist/types/runtime/thread-model.d.ts +18 -0
- package/dist/types/runtime/ticket-form-model.d.ts +57 -0
- package/dist/types/runtime/ticket-form.d.ts +9 -0
- package/dist/types/runtime/toolbar.d.ts +37 -1
- package/dist/types/runtime/ui-scale.d.ts +17 -0
- package/dist/types/runtime/update.d.ts +37 -0
- package/dist/types/runtime/use-debug-context.d.ts +27 -0
- package/dist/types/server/index.d.ts +22 -0
- package/dist/types/server/support.d.ts +20 -0
- package/dist/types/server.d.ts +2 -0
- package/dist/types/vite/plugin.d.ts +15 -0
- package/dist/vite.js +121 -41
- package/package.json +26 -13
- package/src/capture/api.ts +128 -0
- package/src/capture/editor.tsx +178 -0
- package/src/capture/ignore.ts +38 -0
- package/src/capture/index.ts +27 -0
- package/src/capture/picker.tsx +171 -0
- package/src/capture/picture.ts +90 -0
- package/src/capture/surface.tsx +185 -0
- package/src/compiler/annotate.ts +202 -0
- package/src/compiler/babel.d.ts +11 -0
- package/src/compiler/enabled.ts +55 -0
- package/src/compiler/index.ts +2 -0
- package/src/core/index.ts +8 -0
- package/src/core/resolve.ts +307 -0
- package/src/core/types.ts +58 -0
- package/src/debug-context.ts +47 -0
- package/src/dictation.ts +17 -0
- package/src/embed/controller.ts +215 -0
- package/src/embed/index.ts +68 -0
- package/src/embed/options.ts +100 -0
- package/src/help/index.ts +38 -0
- package/src/help/panel-index.ts +17 -0
- package/src/help/panel-styles.ts +123 -0
- package/src/help/panel.ts +840 -0
- package/src/help/pill-styles.ts +75 -0
- package/src/help/pill.ts +338 -0
- package/src/help/react.tsx +143 -0
- package/src/help/requests.ts +111 -0
- package/src/help/types.ts +124 -0
- package/src/help/wire.ts +55 -0
- package/src/native-wire.ts +124 -0
- package/src/native.ts +282 -0
- package/src/react.ts +27 -0
- package/src/replay.ts +13 -0
- package/src/runtime/api.ts +531 -0
- package/src/runtime/attachment-model.ts +42 -0
- package/src/runtime/attachments.tsx +1260 -0
- package/src/runtime/boot.ts +95 -0
- package/src/runtime/browser-label.ts +31 -0
- package/src/runtime/build-id.ts +10 -0
- package/src/runtime/capture-ui.tsx +306 -0
- package/src/runtime/capture.ts +508 -0
- package/src/runtime/clarity-model.ts +634 -0
- package/src/runtime/clarity-ui.tsx +454 -0
- package/src/runtime/client.ts +151 -0
- package/src/runtime/composer-size.tsx +146 -0
- package/src/runtime/dashboard.tsx +1130 -0
- package/src/runtime/debug-context-core.ts +681 -0
- package/src/runtime/debug-context-host.ts +56 -0
- package/src/runtime/debug-context-model.ts +1319 -0
- package/src/runtime/debug-context-redact.ts +259 -0
- package/src/runtime/debug-context.ts +613 -0
- package/src/runtime/details-model.ts +30 -0
- package/src/runtime/details.tsx +395 -0
- package/src/runtime/dictation-engine.ts +616 -0
- package/src/runtime/dictation-model.ts +79 -0
- package/src/runtime/dictation-ui.tsx +363 -0
- package/src/runtime/dictation.ts +271 -0
- package/src/runtime/dock.ts +108 -0
- package/src/runtime/draft-dock.tsx +124 -0
- package/src/runtime/draft-model.ts +251 -0
- package/src/runtime/draft-store.ts +149 -0
- package/src/runtime/edits.tsx +165 -0
- package/src/runtime/font.ts +42 -0
- package/src/runtime/format.ts +129 -0
- package/src/runtime/freshness.ts +23 -0
- package/src/runtime/handoff.ts +76 -0
- package/src/runtime/host-watch.ts +64 -0
- package/src/runtime/icons.tsx +295 -0
- package/src/runtime/idle.ts +20 -0
- package/src/runtime/index.ts +11 -0
- package/src/runtime/ink.ts +6 -0
- package/src/runtime/kind-model.ts +20 -0
- package/src/runtime/live-model.ts +32 -0
- package/src/runtime/loader.tsx +87 -0
- package/src/runtime/markup-editor.tsx +1333 -0
- package/src/runtime/markup-model.ts +485 -0
- package/src/runtime/markup.ts +382 -0
- package/src/runtime/members.ts +58 -0
- package/src/runtime/mention-parse.ts +56 -0
- package/src/runtime/mentions.tsx +205 -0
- package/src/runtime/page-background.ts +51 -0
- package/src/runtime/page-image.ts +1592 -0
- package/src/runtime/placement.ts +336 -0
- package/src/runtime/record.ts +402 -0
- package/src/runtime/redact.ts +30 -0
- package/src/runtime/related.ts +34 -0
- package/src/runtime/render-page.ts +2 -0
- package/src/runtime/replay-model.ts +232 -0
- package/src/runtime/replay.ts +173 -0
- package/src/runtime/runtime-version.ts +7 -0
- package/src/runtime/runtime.tsx +51 -0
- package/src/runtime/screen.ts +182 -0
- package/src/runtime/screenshot.ts +260 -0
- package/src/runtime/session-source.ts +112 -0
- package/src/runtime/session.ts +108 -0
- package/src/runtime/shield.ts +34 -0
- package/src/runtime/shot.tsx +422 -0
- package/src/runtime/sketch.ts +139 -0
- package/src/runtime/styles.ts +1541 -0
- package/src/runtime/sync.ts +300 -0
- package/src/runtime/thread-model.ts +71 -0
- package/src/runtime/ticket-form-model.ts +128 -0
- package/src/runtime/ticket-form.tsx +342 -0
- package/src/runtime/toolbar.tsx +4427 -0
- package/src/runtime/ui-scale.ts +75 -0
- package/src/runtime/update.ts +98 -0
- package/src/runtime/use-debug-context.ts +81 -0
- package/src/server/index.ts +133 -0
- package/src/server/support.ts +499 -0
- package/src/server.ts +4 -0
- package/src/vite/plugin.ts +102 -0
- package/src/vite.ts +1 -0
- package/dist/chunks/chunk-CSKXLF33.js +0 -153
- package/dist/chunks/chunk-HUM5FQII.js +0 -160
- package/dist/chunks/render-page-76MLIT6M.js +0 -1421
- package/dist/chunks/runtime-JX75TKER.js +0 -9267
- package/dist/chunks/screenshot-66ARTBGR.js +0 -12
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { type KeyboardEvent as ReactKeyboardEvent, type ReactNode, useId, useState } from "react";
|
|
2
|
+
import * as Icon from "./icons.js";
|
|
3
|
+
import {
|
|
4
|
+
CHIP_OPTIONS_MAX,
|
|
5
|
+
ticketFieldOptions,
|
|
6
|
+
ticketFieldVisibility,
|
|
7
|
+
ticketValueFilled,
|
|
8
|
+
type TicketForm,
|
|
9
|
+
type TicketFormField,
|
|
10
|
+
type TicketValue,
|
|
11
|
+
type TicketValues,
|
|
12
|
+
} from "./ticket-form-model.js";
|
|
13
|
+
|
|
14
|
+
export * from "./ticket-form-model.js";
|
|
15
|
+
|
|
16
|
+
export function TicketFormInput({
|
|
17
|
+
form,
|
|
18
|
+
values,
|
|
19
|
+
onChange,
|
|
20
|
+
onKeyDown,
|
|
21
|
+
}: {
|
|
22
|
+
form: TicketForm;
|
|
23
|
+
values: TicketValues;
|
|
24
|
+
onChange: (next: TicketValues) => void;
|
|
25
|
+
onKeyDown?: (event: ReactKeyboardEvent<HTMLTextAreaElement>) => void;
|
|
26
|
+
}) {
|
|
27
|
+
const visible = ticketFieldVisibility(form, values);
|
|
28
|
+
const set = (key: string, value: TicketValue | undefined) => {
|
|
29
|
+
const next: Record<string, TicketValue> = { ...values };
|
|
30
|
+
if (value === undefined || !ticketValueFilled(value)) delete next[key];
|
|
31
|
+
else next[key] = value;
|
|
32
|
+
onChange(next);
|
|
33
|
+
};
|
|
34
|
+
return (
|
|
35
|
+
<div className="cs-details-input cs-ticket-form" data-cs-ui="ticket-form">
|
|
36
|
+
{form.fields
|
|
37
|
+
.filter((field) => visible.get(field.key) !== false)
|
|
38
|
+
.map((field) => (
|
|
39
|
+
<TicketField
|
|
40
|
+
key={field.key}
|
|
41
|
+
field={field}
|
|
42
|
+
options={ticketFieldOptions(field, values)}
|
|
43
|
+
value={values[field.key]}
|
|
44
|
+
onChange={(value) => set(field.key, value)}
|
|
45
|
+
onKeyDown={onKeyDown}
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function TicketField({
|
|
53
|
+
field,
|
|
54
|
+
options,
|
|
55
|
+
value,
|
|
56
|
+
onChange,
|
|
57
|
+
onKeyDown,
|
|
58
|
+
}: {
|
|
59
|
+
field: TicketFormField;
|
|
60
|
+
options: readonly { readonly value: string; readonly label: string }[];
|
|
61
|
+
value: TicketValue | undefined;
|
|
62
|
+
onChange: (value: TicketValue | undefined) => void;
|
|
63
|
+
onKeyDown?: (event: ReactKeyboardEvent<HTMLTextAreaElement>) => void;
|
|
64
|
+
}) {
|
|
65
|
+
const label = (
|
|
66
|
+
<span>
|
|
67
|
+
{field.label}
|
|
68
|
+
{field.required ? <b aria-hidden="true"> *</b> : null}
|
|
69
|
+
</span>
|
|
70
|
+
);
|
|
71
|
+
const hint = field.helpText ? <small>{field.helpText}</small> : null;
|
|
72
|
+
const cs = `ticket-${field.key}`;
|
|
73
|
+
|
|
74
|
+
if (field.kind === "select_single" || field.kind === "select_multi") {
|
|
75
|
+
const multi = field.kind === "select_multi";
|
|
76
|
+
const chosen = multi
|
|
77
|
+
? Array.isArray(value)
|
|
78
|
+
? (value as readonly string[])
|
|
79
|
+
: []
|
|
80
|
+
: typeof value === "string"
|
|
81
|
+
? [value]
|
|
82
|
+
: [];
|
|
83
|
+
if (!multi && options.length > CHIP_OPTIONS_MAX) {
|
|
84
|
+
return (
|
|
85
|
+
<TicketSelect
|
|
86
|
+
cs={cs}
|
|
87
|
+
label={label}
|
|
88
|
+
hint={hint}
|
|
89
|
+
value={chosen[0] ?? ""}
|
|
90
|
+
required={field.required}
|
|
91
|
+
options={options}
|
|
92
|
+
onChange={(next) => onChange(next || undefined)}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
className="cs-roles"
|
|
99
|
+
role={multi ? "group" : "radiogroup"}
|
|
100
|
+
aria-label={field.label}
|
|
101
|
+
data-cs-ui={cs}
|
|
102
|
+
>
|
|
103
|
+
<span className="cs-roles-label">
|
|
104
|
+
{field.label}
|
|
105
|
+
{field.required ? " *" : ""}
|
|
106
|
+
</span>
|
|
107
|
+
{options.map((option) => {
|
|
108
|
+
const on = chosen.includes(option.value);
|
|
109
|
+
return (
|
|
110
|
+
<button
|
|
111
|
+
key={option.value}
|
|
112
|
+
type="button"
|
|
113
|
+
role={multi ? "checkbox" : "radio"}
|
|
114
|
+
aria-checked={on}
|
|
115
|
+
className={on ? "cs-chip is-on" : "cs-chip"}
|
|
116
|
+
onClick={() =>
|
|
117
|
+
onChange(
|
|
118
|
+
multi
|
|
119
|
+
? on
|
|
120
|
+
? chosen.filter((entry) => entry !== option.value)
|
|
121
|
+
: [...chosen, option.value]
|
|
122
|
+
: on
|
|
123
|
+
? undefined
|
|
124
|
+
: option.value,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
{option.label}
|
|
129
|
+
</button>
|
|
130
|
+
);
|
|
131
|
+
})}
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (field.kind === "checkbox") {
|
|
137
|
+
return (
|
|
138
|
+
<label className="cs-detail-field cs-ticket-check">
|
|
139
|
+
<input
|
|
140
|
+
type="checkbox"
|
|
141
|
+
data-cs-ui={cs}
|
|
142
|
+
checked={value === true}
|
|
143
|
+
onChange={(event) => onChange(event.target.checked ? true : undefined)}
|
|
144
|
+
/>
|
|
145
|
+
{label}
|
|
146
|
+
</label>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (field.kind === "long_text") {
|
|
151
|
+
return (
|
|
152
|
+
<label className="cs-detail-field">
|
|
153
|
+
{label}
|
|
154
|
+
<textarea
|
|
155
|
+
data-cs-ui={cs}
|
|
156
|
+
rows={2}
|
|
157
|
+
maxLength={10_000}
|
|
158
|
+
required={field.required}
|
|
159
|
+
value={typeof value === "string" ? value : ""}
|
|
160
|
+
onChange={(event) => onChange(event.target.value)}
|
|
161
|
+
onKeyDown={onKeyDown}
|
|
162
|
+
/>
|
|
163
|
+
{hint}
|
|
164
|
+
</label>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (field.kind === "number" || field.kind === "rating") {
|
|
169
|
+
const max = field.kind === "rating" ? (field.scale ?? 5) : field.max;
|
|
170
|
+
const min = field.kind === "rating" ? 1 : field.min;
|
|
171
|
+
return (
|
|
172
|
+
<label className="cs-detail-field">
|
|
173
|
+
{label}
|
|
174
|
+
<input
|
|
175
|
+
type="number"
|
|
176
|
+
data-cs-ui={cs}
|
|
177
|
+
min={min}
|
|
178
|
+
max={max}
|
|
179
|
+
required={field.required}
|
|
180
|
+
value={typeof value === "number" ? value : ""}
|
|
181
|
+
onChange={(event) =>
|
|
182
|
+
onChange(event.target.value === "" ? undefined : Number(event.target.value))
|
|
183
|
+
}
|
|
184
|
+
/>
|
|
185
|
+
{hint}
|
|
186
|
+
</label>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const inputType =
|
|
191
|
+
field.kind === "email"
|
|
192
|
+
? "email"
|
|
193
|
+
: field.kind === "phone"
|
|
194
|
+
? "tel"
|
|
195
|
+
: field.kind === "url"
|
|
196
|
+
? "url"
|
|
197
|
+
: field.kind === "date"
|
|
198
|
+
? "date"
|
|
199
|
+
: field.kind === "datetime"
|
|
200
|
+
? "datetime-local"
|
|
201
|
+
: "text";
|
|
202
|
+
return (
|
|
203
|
+
<label className="cs-detail-field">
|
|
204
|
+
{label}
|
|
205
|
+
<input
|
|
206
|
+
type={inputType}
|
|
207
|
+
data-cs-ui={cs}
|
|
208
|
+
maxLength={field.kind === "short_text" ? 500 : undefined}
|
|
209
|
+
required={field.required}
|
|
210
|
+
value={typeof value === "string" ? value : ""}
|
|
211
|
+
onChange={(event) => onChange(event.target.value)}
|
|
212
|
+
/>
|
|
213
|
+
{hint}
|
|
214
|
+
</label>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* One of a long list, in a list the toolbar draws: a native select opens the system's own menu, which looks
|
|
220
|
+
* different on every system and in every browser.
|
|
221
|
+
*/
|
|
222
|
+
function TicketSelect({
|
|
223
|
+
cs,
|
|
224
|
+
label,
|
|
225
|
+
hint,
|
|
226
|
+
value,
|
|
227
|
+
required,
|
|
228
|
+
options,
|
|
229
|
+
onChange,
|
|
230
|
+
}: {
|
|
231
|
+
cs: string;
|
|
232
|
+
label: ReactNode;
|
|
233
|
+
hint: ReactNode;
|
|
234
|
+
value: string;
|
|
235
|
+
required: boolean;
|
|
236
|
+
options: readonly { readonly value: string; readonly label: string }[];
|
|
237
|
+
onChange: (value: string) => void;
|
|
238
|
+
}) {
|
|
239
|
+
const id = useId();
|
|
240
|
+
const [open, setOpen] = useState(false);
|
|
241
|
+
const [active, setActive] = useState(0);
|
|
242
|
+
const choices = [{ value: "", label: "Choose…" }, ...options];
|
|
243
|
+
const current = Math.max(
|
|
244
|
+
0,
|
|
245
|
+
choices.findIndex((choice) => choice.value === value),
|
|
246
|
+
);
|
|
247
|
+
const show = () => {
|
|
248
|
+
setActive(current);
|
|
249
|
+
setOpen(true);
|
|
250
|
+
};
|
|
251
|
+
const pick = (index: number) => {
|
|
252
|
+
onChange(choices[index]?.value ?? "");
|
|
253
|
+
setOpen(false);
|
|
254
|
+
};
|
|
255
|
+
const onKeyDown = (event: ReactKeyboardEvent<HTMLButtonElement>) => {
|
|
256
|
+
const last = choices.length - 1;
|
|
257
|
+
const moveTo = (index: number) => {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
if (open) setActive(Math.min(last, Math.max(0, index)));
|
|
260
|
+
else show();
|
|
261
|
+
};
|
|
262
|
+
switch (event.key) {
|
|
263
|
+
case "ArrowDown":
|
|
264
|
+
return moveTo(active + 1);
|
|
265
|
+
case "ArrowUp":
|
|
266
|
+
return moveTo(active - 1);
|
|
267
|
+
case "Home":
|
|
268
|
+
return open ? moveTo(0) : undefined;
|
|
269
|
+
case "End":
|
|
270
|
+
return open ? moveTo(last) : undefined;
|
|
271
|
+
case "Enter":
|
|
272
|
+
case " ":
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
if (open) pick(active);
|
|
275
|
+
else show();
|
|
276
|
+
return;
|
|
277
|
+
case "Escape":
|
|
278
|
+
if (!open) return;
|
|
279
|
+
// The toolbar's own Escape (closing the composer) skips a key a control has handled.
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
setOpen(false);
|
|
282
|
+
return;
|
|
283
|
+
case "Tab":
|
|
284
|
+
setOpen(false);
|
|
285
|
+
return;
|
|
286
|
+
default:
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
className="cs-detail-field cs-select"
|
|
293
|
+
onBlur={(event) => {
|
|
294
|
+
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setOpen(false);
|
|
295
|
+
}}
|
|
296
|
+
>
|
|
297
|
+
<span id={`${id}-label`}>{label}</span>
|
|
298
|
+
<button
|
|
299
|
+
type="button"
|
|
300
|
+
role="combobox"
|
|
301
|
+
className={value ? "cs-select-button" : "cs-select-button is-empty"}
|
|
302
|
+
data-cs-ui={cs}
|
|
303
|
+
aria-labelledby={`${id}-label`}
|
|
304
|
+
aria-haspopup="listbox"
|
|
305
|
+
aria-expanded={open}
|
|
306
|
+
aria-controls={`${id}-list`}
|
|
307
|
+
aria-activedescendant={open ? `${id}-${active}` : undefined}
|
|
308
|
+
aria-required={required || undefined}
|
|
309
|
+
onClick={() => (open ? setOpen(false) : show())}
|
|
310
|
+
onKeyDown={onKeyDown}
|
|
311
|
+
>
|
|
312
|
+
{choices[current]?.label}
|
|
313
|
+
<Icon.ChevronDown />
|
|
314
|
+
</button>
|
|
315
|
+
{open ? (
|
|
316
|
+
<div
|
|
317
|
+
className="cs-select-list"
|
|
318
|
+
role="listbox"
|
|
319
|
+
id={`${id}-list`}
|
|
320
|
+
aria-labelledby={`${id}-label`}
|
|
321
|
+
>
|
|
322
|
+
{choices.map((choice, index) => (
|
|
323
|
+
<div
|
|
324
|
+
key={choice.value}
|
|
325
|
+
id={`${id}-${index}`}
|
|
326
|
+
role="option"
|
|
327
|
+
aria-selected={index === current}
|
|
328
|
+
className={index === active ? "cs-select-option is-active" : "cs-select-option"}
|
|
329
|
+
onMouseEnter={() => setActive(index)}
|
|
330
|
+
// The button keeps focus, so the list stays open until the choice is made.
|
|
331
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
332
|
+
onClick={() => pick(index)}
|
|
333
|
+
>
|
|
334
|
+
{choice.label}
|
|
335
|
+
</div>
|
|
336
|
+
))}
|
|
337
|
+
</div>
|
|
338
|
+
) : null}
|
|
339
|
+
{hint}
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
}
|