@optiaxiom/proteus 0.3.0 → 1.1.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/dist/esm/_virtual/_openai-shim-script.js +3 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChart.css.ts.vanilla-DNE5j3uT.css → ProteusChart.css.ts.vanilla-yGx8JdKz.css} +2 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChartTooltipContent.css.ts.vanilla-DM8u1icS.css → ProteusChartTooltipContent.css.ts.vanilla-HapBe2oo.css} +2 -2
- package/dist/esm/assets/src/proteus-document/{ProteusDocumentShell.css.ts.vanilla-DjZJuQ2A.css → ProteusDocumentShell.css.ts.vanilla-BPytQ9pT.css} +2 -2
- package/dist/esm/assets/src/proteus-image-carousel/{ProteusImageCarousel.css.ts.vanilla-CIwMJ4Cg.css → ProteusImageCarousel.css.ts.vanilla-DnlXoyv1.css} +2 -2
- package/dist/esm/assets/src/proteus-question/{ProteusQuestion.css.ts.vanilla-DiCe_bxf.css → ProteusQuestion.css.ts.vanilla-CpDgoW0l.css} +2 -2
- package/dist/esm/hooks/useEffectEvent.js +11 -10
- package/dist/esm/hooks/useObserveValue.js +24 -30
- package/dist/esm/icons/IconAngleLeft.js +13 -19
- package/dist/esm/icons/IconAngleRight.js +13 -19
- package/dist/esm/icons/IconX.js +10 -18
- package/dist/esm/icons/withIcon.js +17 -28
- package/dist/esm/index.js +22 -17
- package/dist/esm/proteus-action/ProteusAction.js +44 -39
- package/dist/esm/proteus-bridge/ProteusBridge.js +71 -85
- package/dist/esm/proteus-card-link/ProteusCardLink.js +24 -37
- package/dist/esm/proteus-chart/ProteusChart-css.js +14 -5
- package/dist/esm/proteus-chart/ProteusChart.js +86 -84
- package/dist/esm/proteus-chart/ProteusChartContext.js +3 -3
- package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +23 -6
- package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +52 -66
- package/dist/esm/proteus-data-table/ProteusDataTable.js +28 -29
- package/dist/esm/proteus-date-input/ProteusDateInput.js +23 -0
- package/dist/esm/proteus-document/ProteusDocumentContext.js +4 -3
- package/dist/esm/proteus-document/ProteusDocumentPathContext.js +6 -5
- package/dist/esm/proteus-document/ProteusDocumentRenderer.js +25 -33
- package/dist/esm/proteus-document/ProteusDocumentShell-css.js +32 -6
- package/dist/esm/proteus-document/ProteusDocumentShell.js +226 -219
- package/dist/esm/proteus-document/getProteusValue.js +28 -42
- package/dist/esm/proteus-document/resolveProteusProp.js +31 -49
- package/dist/esm/proteus-document/resolveProteusValue.js +73 -136
- package/dist/esm/proteus-document/schemas.js +42 -45
- package/dist/esm/proteus-document/useResolveProteusValues.js +10 -16
- package/dist/esm/proteus-element/ProteusElement.js +114 -180
- package/dist/esm/proteus-federated/ProteusFederated.js +51 -52
- package/dist/esm/proteus-file-icon/ProteusFileIcon.js +29 -38
- package/dist/esm/proteus-file-upload/ProteusFileUpload.js +107 -133
- package/dist/esm/proteus-image/ProteusImage.js +99 -106
- package/dist/esm/proteus-image/downloadFile.js +3 -2
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel-css.js +49 -11
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel.js +151 -163
- package/dist/esm/proteus-input/ProteusInput.js +19 -27
- package/dist/esm/proteus-length/ProteusLength.js +10 -0
- package/dist/esm/proteus-map/ProteusMap.js +18 -31
- package/dist/esm/proteus-map-index/ProteusMapIndex.js +11 -0
- package/dist/esm/proteus-pill-menu/ProteusPillMenu.js +65 -0
- package/dist/esm/proteus-pill-menu/useInputValueChangeInteraction.js +36 -0
- package/dist/esm/proteus-question/ProteusQuestion-css.js +40 -8
- package/dist/esm/proteus-question/ProteusQuestion.js +324 -400
- package/dist/esm/proteus-select/ProteusSelect.js +25 -40
- package/dist/esm/proteus-show/ProteusShow.js +10 -18
- package/dist/esm/proteus-switch/ProteusSwitch.js +33 -36
- package/dist/esm/proteus-textarea/ProteusTextarea.js +18 -27
- package/dist/esm/proteus-value/ProteusValue.js +4 -4
- package/dist/esm/schema/public-schema.js +4537 -0
- package/dist/esm/schema/runtime-schema.js +4460 -0
- package/dist/esm/spec.js +5 -1
- package/dist/esm/use-proteus-value/useProteusValue.js +8 -12
- package/dist/index.d.ts +516 -347
- package/dist/spec.d.ts +5 -9952
- package/package.json +5 -5
- package/dist/esm/icons/IconCalendar.js +0 -20
- package/dist/esm/schema/public-schema.json.js +0 -9041
- package/dist/esm/schema/runtime-schema.json.js +0 -8974
|
@@ -1,405 +1,329 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
2
|
+
import { useProteusDocumentContext } from "../proteus-document/ProteusDocumentContext.js";
|
|
3
|
+
import { IconAngleLeft } from "../icons/IconAngleLeft.js";
|
|
4
|
+
import { IconAngleRight } from "../icons/IconAngleRight.js";
|
|
5
|
+
import { IconX } from "../icons/IconX.js";
|
|
6
|
+
import { addon, choice, choiceGroup, question } from "./ProteusQuestion-css.js";
|
|
7
|
+
import { Box, Button, Checkbox, Group, Text } from "@optiaxiom/react";
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { InlineInput } from "@optiaxiom/react/unstable";
|
|
11
|
+
import { IconArrowRight, IconPen } from "@optiaxiom/icons";
|
|
12
|
+
import * as RovingFocus from "@radix-ui/react-roving-focus";
|
|
13
|
+
//#region src/proteus-question/ProteusQuestion.tsx
|
|
14
14
|
function ProteusQuestion({ questions }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
},
|
|
327
|
-
ref: otherInputRef,
|
|
328
|
-
value: otherValue ?? ""
|
|
329
|
-
}
|
|
330
|
-
)
|
|
331
|
-
}
|
|
332
|
-
) }),
|
|
333
|
-
type === "single_select" && /* @__PURE__ */ jsx(
|
|
334
|
-
Button,
|
|
335
|
-
{
|
|
336
|
-
appearance: otherValue ? "primary-opal" : "default",
|
|
337
|
-
"aria-label": otherValue && (isLast ? "Submit" : "Next"),
|
|
338
|
-
icon: otherValue && /* @__PURE__ */ jsx(IconArrowRight, {}),
|
|
339
|
-
ml: "auto",
|
|
340
|
-
onClick: (event) => {
|
|
341
|
-
event.preventDefault();
|
|
342
|
-
if (otherValue) {
|
|
343
|
-
onSubmit();
|
|
344
|
-
} else {
|
|
345
|
-
onSkip();
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
children: !otherValue && "Skip"
|
|
349
|
-
}
|
|
350
|
-
)
|
|
351
|
-
] })
|
|
352
|
-
},
|
|
353
|
-
"other"
|
|
354
|
-
)
|
|
355
|
-
]
|
|
356
|
-
}
|
|
357
|
-
) })
|
|
358
|
-
] }),
|
|
359
|
-
type === "multi_select" && /* @__PURE__ */ jsxs(
|
|
360
|
-
Group,
|
|
361
|
-
{
|
|
362
|
-
borderColor: "border.secondary",
|
|
363
|
-
borderT: "1",
|
|
364
|
-
gap: "8",
|
|
365
|
-
pt: "16",
|
|
366
|
-
px: "16",
|
|
367
|
-
children: [
|
|
368
|
-
/* @__PURE__ */ jsxs(Text, { children: [
|
|
369
|
-
value?.length || 0,
|
|
370
|
-
" selected"
|
|
371
|
-
] }),
|
|
372
|
-
/* @__PURE__ */ jsx(
|
|
373
|
-
Button,
|
|
374
|
-
{
|
|
375
|
-
ml: "auto",
|
|
376
|
-
onClick: (event) => {
|
|
377
|
-
event.preventDefault();
|
|
378
|
-
onSkip();
|
|
379
|
-
},
|
|
380
|
-
children: "Skip"
|
|
381
|
-
}
|
|
382
|
-
),
|
|
383
|
-
/* @__PURE__ */ jsx(
|
|
384
|
-
Button,
|
|
385
|
-
{
|
|
386
|
-
appearance: valid ? "primary-opal" : "default",
|
|
387
|
-
"aria-label": isLast ? "Submit" : "Next",
|
|
388
|
-
disabled: !valid,
|
|
389
|
-
icon: /* @__PURE__ */ jsx(IconArrowRight, {}),
|
|
390
|
-
onClick: (event) => {
|
|
391
|
-
event.preventDefault();
|
|
392
|
-
onSubmit();
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
)
|
|
396
|
-
]
|
|
397
|
-
}
|
|
398
|
-
)
|
|
399
|
-
]
|
|
400
|
-
}
|
|
401
|
-
);
|
|
15
|
+
const { onEvent, onTrack } = useProteusDocumentContext("@optiaxiom/proteus/ProteusQuestion");
|
|
16
|
+
const [answers, setAnswers] = useState([]);
|
|
17
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
18
|
+
const value = answers[currentIndex];
|
|
19
|
+
const valid = Array.isArray(value) && value.length > 0 && value.every(Boolean);
|
|
20
|
+
const goBack = useCallback(() => {
|
|
21
|
+
onTrack?.("Ask User Question Back", {
|
|
22
|
+
fromIndex: String(currentIndex),
|
|
23
|
+
toIndex: String(currentIndex - 1)
|
|
24
|
+
});
|
|
25
|
+
setCurrentIndex((i) => i - 1);
|
|
26
|
+
}, [currentIndex, onTrack]);
|
|
27
|
+
const onDismiss = useCallback(() => {
|
|
28
|
+
onTrack?.("Ask User Question Dismissed", { questionIndex: String(currentIndex) });
|
|
29
|
+
onEvent({ message: "[User declined to answer the question]" });
|
|
30
|
+
}, [
|
|
31
|
+
currentIndex,
|
|
32
|
+
onEvent,
|
|
33
|
+
onTrack
|
|
34
|
+
]);
|
|
35
|
+
const questionRef = useRef(null);
|
|
36
|
+
const lastIndexRef = useRef(currentIndex);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (lastIndexRef.current !== currentIndex) {
|
|
39
|
+
questionRef.current?.animate([{
|
|
40
|
+
opacity: 0,
|
|
41
|
+
translate: currentIndex > lastIndexRef.current ? "8px" : "-8px"
|
|
42
|
+
}, {
|
|
43
|
+
opacity: 1,
|
|
44
|
+
translate: "0px"
|
|
45
|
+
}], { duration: 150 });
|
|
46
|
+
lastIndexRef.current = currentIndex;
|
|
47
|
+
}
|
|
48
|
+
(questionRef.current?.querySelector("[data-selected]") ?? questionRef.current?.querySelector("[tabindex]"))?.focus();
|
|
49
|
+
}, [currentIndex]);
|
|
50
|
+
const otherInputRef = useRef(null);
|
|
51
|
+
const otherItemRef = useRef(null);
|
|
52
|
+
if (currentIndex >= questions.length) return null;
|
|
53
|
+
const { options, question: question$1, type } = questions[currentIndex];
|
|
54
|
+
const isLast = currentIndex === questions.length - 1;
|
|
55
|
+
const otherValue = value?.find((v) => !options.includes(v));
|
|
56
|
+
const otherChecked = otherValue !== void 0;
|
|
57
|
+
const onComplete = () => {
|
|
58
|
+
const answeredCount = answers.filter((answer) => Array.isArray(answer) && answer.length > 0).length;
|
|
59
|
+
onTrack?.("Ask User Question Submitted", {
|
|
60
|
+
answeredCount: String(answeredCount),
|
|
61
|
+
skippedCount: String(questions.length - answeredCount),
|
|
62
|
+
totalQuestions: String(questions.length)
|
|
63
|
+
});
|
|
64
|
+
return onEvent({ message: answers.map((value, index) => `Q: ${questions[index].question}\nA: ${value || "[Not specified]"}`).join("\n\n") });
|
|
65
|
+
};
|
|
66
|
+
const onValueChange = (value) => {
|
|
67
|
+
answers[currentIndex] = value;
|
|
68
|
+
setAnswers([...answers]);
|
|
69
|
+
};
|
|
70
|
+
const onSkip = () => {
|
|
71
|
+
onTrack?.("Ask User Question Skipped", { questionIndex: String(currentIndex) });
|
|
72
|
+
answers[currentIndex] = null;
|
|
73
|
+
setAnswers([...answers]);
|
|
74
|
+
if (isLast) onComplete();
|
|
75
|
+
else setCurrentIndex((i) => i + 1);
|
|
76
|
+
};
|
|
77
|
+
const onSubmit = () => {
|
|
78
|
+
const currentValue = answers[currentIndex];
|
|
79
|
+
if (currentValue) {
|
|
80
|
+
const firstIndex = options.indexOf(currentValue[0]);
|
|
81
|
+
onTrack?.("Ask User Question Option Selected", {
|
|
82
|
+
isCustomText: String(currentValue.some((v) => !options.includes(v))),
|
|
83
|
+
optionIndex: String(firstIndex),
|
|
84
|
+
questionIndex: String(currentIndex)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (isLast) onComplete();
|
|
88
|
+
else setCurrentIndex((i) => i + 1);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ jsxs(Group, {
|
|
91
|
+
onKeyDown: (event) => {
|
|
92
|
+
if (event.key === "Escape") {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
if (type === "multi_select" && valid) onValueChange(null);
|
|
95
|
+
else onSkip();
|
|
96
|
+
}
|
|
97
|
+
if ((event.key === "ArrowLeft" || event.key === "ArrowRight") && !(event.target instanceof HTMLInputElement) && !event.target.isContentEditable) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
if (event.key === "ArrowLeft" && currentIndex > 0) goBack();
|
|
100
|
+
else if (event.key === "ArrowRight" && !isLast) setCurrentIndex((i) => i + 1);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
tabIndex: -1,
|
|
104
|
+
...question(),
|
|
105
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
106
|
+
flexDirection: "column",
|
|
107
|
+
gap: "16",
|
|
108
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
109
|
+
pl: "16",
|
|
110
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
111
|
+
flex: "1",
|
|
112
|
+
fontWeight: "500",
|
|
113
|
+
children: question$1
|
|
114
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
115
|
+
gap: "6",
|
|
116
|
+
children: [questions.length > 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
117
|
+
/* @__PURE__ */ jsx(Button, {
|
|
118
|
+
appearance: "subtle",
|
|
119
|
+
"aria-label": "Previous",
|
|
120
|
+
disabled: currentIndex === 0,
|
|
121
|
+
icon: /* @__PURE__ */ jsx(IconAngleLeft, {}),
|
|
122
|
+
onClick: (event) => {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
goBack();
|
|
125
|
+
},
|
|
126
|
+
size: "sm"
|
|
127
|
+
}),
|
|
128
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
129
|
+
color: "fg.tertiary",
|
|
130
|
+
fontSize: "sm",
|
|
131
|
+
children: [
|
|
132
|
+
currentIndex + 1,
|
|
133
|
+
" of ",
|
|
134
|
+
questions.length
|
|
135
|
+
]
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ jsx(Button, {
|
|
138
|
+
appearance: "subtle",
|
|
139
|
+
"aria-label": "Next",
|
|
140
|
+
disabled: isLast,
|
|
141
|
+
icon: /* @__PURE__ */ jsx(IconAngleRight, {}),
|
|
142
|
+
onClick: (event) => {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
setCurrentIndex((i) => i + 1);
|
|
145
|
+
},
|
|
146
|
+
size: "sm"
|
|
147
|
+
})
|
|
148
|
+
] }), /* @__PURE__ */ jsx(Button, {
|
|
149
|
+
appearance: "subtle",
|
|
150
|
+
"aria-label": "Dismiss",
|
|
151
|
+
icon: /* @__PURE__ */ jsx(IconX, {}),
|
|
152
|
+
onClick: (event) => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
onDismiss();
|
|
155
|
+
},
|
|
156
|
+
size: "sm"
|
|
157
|
+
})]
|
|
158
|
+
})]
|
|
159
|
+
}), /* @__PURE__ */ jsx(RovingFocus.Root, {
|
|
160
|
+
asChild: true,
|
|
161
|
+
loop: true,
|
|
162
|
+
orientation: "vertical",
|
|
163
|
+
ref: questionRef,
|
|
164
|
+
children: /* @__PURE__ */ jsxs(Group, {
|
|
165
|
+
role: type === "single_select" ? "radiogroup" : "listbox",
|
|
166
|
+
...choiceGroup(),
|
|
167
|
+
children: [options.map((option, index) => {
|
|
168
|
+
const checked = type === "single_select" ? value?.[0] === option : value?.includes(option);
|
|
169
|
+
const disabled = type === "single_select" && otherChecked && !!otherValue;
|
|
170
|
+
return /* @__PURE__ */ jsx(RovingFocus.Item, {
|
|
171
|
+
asChild: true,
|
|
172
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
173
|
+
"aria-checked": type === "single_select" ? checked : void 0,
|
|
174
|
+
"data-disabled": disabled ? "" : void 0,
|
|
175
|
+
"data-selected": checked && type === "single_select" ? "" : void 0,
|
|
176
|
+
onClick: () => {
|
|
177
|
+
if (type === "single_select") {
|
|
178
|
+
onValueChange([option]);
|
|
179
|
+
onSubmit();
|
|
180
|
+
} else {
|
|
181
|
+
const current = value ?? [];
|
|
182
|
+
onValueChange(checked ? current.filter((v) => v !== option) : [...current, option]);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
onFocus: () => {
|
|
186
|
+
if (type === "single_select") onValueChange([option]);
|
|
187
|
+
},
|
|
188
|
+
onKeyDown: (event) => {
|
|
189
|
+
if (type === "single_select" && event.key === "Enter") {
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
onSubmit();
|
|
192
|
+
} else if (type === "multi_select" && (event.key === "Enter" || event.key === " ")) {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
const current = value ?? [];
|
|
195
|
+
onValueChange(checked ? current.filter((v) => v !== option) : [...current, option]);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
role: type === "single_select" ? "radio" : "option",
|
|
199
|
+
tabIndex: 0,
|
|
200
|
+
...choice({ cursor: "pointer" }),
|
|
201
|
+
children: /* @__PURE__ */ jsxs(Group, {
|
|
202
|
+
gap: "12",
|
|
203
|
+
children: [
|
|
204
|
+
type === "single_select" ? /* @__PURE__ */ jsx(Box, {
|
|
205
|
+
...addon(),
|
|
206
|
+
children: index + 1
|
|
207
|
+
}) : /* @__PURE__ */ jsx(Checkbox, {
|
|
208
|
+
checked,
|
|
209
|
+
hidden: true,
|
|
210
|
+
pointerEvents: "none",
|
|
211
|
+
tabIndex: -1
|
|
212
|
+
}),
|
|
213
|
+
/* @__PURE__ */ jsx(Group, {
|
|
214
|
+
flex: "1",
|
|
215
|
+
flexDirection: "column",
|
|
216
|
+
gap: "2",
|
|
217
|
+
children: /* @__PURE__ */ jsx(Text, { children: option })
|
|
218
|
+
}),
|
|
219
|
+
type === "single_select" && checked && /* @__PURE__ */ jsx(Box, {
|
|
220
|
+
asChild: true,
|
|
221
|
+
color: "fg.tertiary",
|
|
222
|
+
h: "24",
|
|
223
|
+
ml: "auto",
|
|
224
|
+
w: "24",
|
|
225
|
+
children: /* @__PURE__ */ jsx(IconArrowRight, {})
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
}, option);
|
|
231
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
232
|
+
"aria-label": "Something else",
|
|
233
|
+
"data-selected": otherChecked ? "" : void 0,
|
|
234
|
+
role: "group",
|
|
235
|
+
...choice({ cursor: "text" }),
|
|
236
|
+
children: /* @__PURE__ */ jsxs(Group, {
|
|
237
|
+
gap: "12",
|
|
238
|
+
children: [
|
|
239
|
+
type === "single_select" ? /* @__PURE__ */ jsx(Box, {
|
|
240
|
+
...addon({ cursor: "pointer" }),
|
|
241
|
+
children: /* @__PURE__ */ jsx(IconPen, {})
|
|
242
|
+
}) : /* @__PURE__ */ jsx(Checkbox, {
|
|
243
|
+
checked: otherChecked,
|
|
244
|
+
hidden: true,
|
|
245
|
+
pointerEvents: "none",
|
|
246
|
+
tabIndex: -1
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ jsx(RovingFocus.Item, {
|
|
249
|
+
asChild: true,
|
|
250
|
+
children: /* @__PURE__ */ jsx(Group, {
|
|
251
|
+
flex: "1",
|
|
252
|
+
flexDirection: "column",
|
|
253
|
+
gap: "2",
|
|
254
|
+
onFocus: () => {
|
|
255
|
+
if (type === "single_select" && !otherValue) onValueChange([""]);
|
|
256
|
+
otherInputRef.current?.focus();
|
|
257
|
+
},
|
|
258
|
+
ref: otherItemRef,
|
|
259
|
+
children: /* @__PURE__ */ jsx(InlineInput, {
|
|
260
|
+
label: "Something else",
|
|
261
|
+
onKeyDown: (event) => {
|
|
262
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
otherItemRef.current?.focus();
|
|
265
|
+
otherItemRef.current?.dispatchEvent(new KeyboardEvent("keydown", {
|
|
266
|
+
bubbles: true,
|
|
267
|
+
key: event.key
|
|
268
|
+
}));
|
|
269
|
+
} else if (event.key === "Enter") onSubmit();
|
|
270
|
+
},
|
|
271
|
+
onValueChange: (text) => {
|
|
272
|
+
if (type === "single_select") onValueChange([text]);
|
|
273
|
+
else onValueChange([...(value ?? []).filter((v) => options.includes(v)), ...text ? [text] : []]);
|
|
274
|
+
},
|
|
275
|
+
ref: otherInputRef,
|
|
276
|
+
value: otherValue ?? ""
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
}),
|
|
280
|
+
type === "single_select" && /* @__PURE__ */ jsx(Button, {
|
|
281
|
+
appearance: otherValue ? "primary-opal" : "default",
|
|
282
|
+
"aria-label": otherValue && (isLast ? "Submit" : "Next"),
|
|
283
|
+
icon: otherValue && /* @__PURE__ */ jsx(IconArrowRight, {}),
|
|
284
|
+
ml: "auto",
|
|
285
|
+
onClick: (event) => {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
if (otherValue) onSubmit();
|
|
288
|
+
else onSkip();
|
|
289
|
+
},
|
|
290
|
+
children: !otherValue && "Skip"
|
|
291
|
+
})
|
|
292
|
+
]
|
|
293
|
+
})
|
|
294
|
+
}, "other")]
|
|
295
|
+
})
|
|
296
|
+
})]
|
|
297
|
+
}), type === "multi_select" && /* @__PURE__ */ jsxs(Group, {
|
|
298
|
+
borderColor: "border.secondary",
|
|
299
|
+
borderT: "1",
|
|
300
|
+
gap: "8",
|
|
301
|
+
pt: "16",
|
|
302
|
+
px: "16",
|
|
303
|
+
children: [
|
|
304
|
+
/* @__PURE__ */ jsxs(Text, { children: [value?.length || 0, " selected"] }),
|
|
305
|
+
/* @__PURE__ */ jsx(Button, {
|
|
306
|
+
ml: "auto",
|
|
307
|
+
onClick: (event) => {
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
onSkip();
|
|
310
|
+
},
|
|
311
|
+
children: "Skip"
|
|
312
|
+
}),
|
|
313
|
+
/* @__PURE__ */ jsx(Button, {
|
|
314
|
+
appearance: valid ? "primary-opal" : "default",
|
|
315
|
+
"aria-label": isLast ? "Submit" : "Next",
|
|
316
|
+
disabled: !valid,
|
|
317
|
+
icon: /* @__PURE__ */ jsx(IconArrowRight, {}),
|
|
318
|
+
onClick: (event) => {
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
onSubmit();
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
]
|
|
324
|
+
})]
|
|
325
|
+
});
|
|
402
326
|
}
|
|
403
327
|
ProteusQuestion.displayName = "@optiaxiom/proteus/ProteusQuestion";
|
|
404
|
-
|
|
328
|
+
//#endregion
|
|
405
329
|
export { ProteusQuestion };
|