@widgetic/design-system 0.5.40 → 0.5.42
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 +73 -0
- package/dist/components/ContentRefreshOverlay.svelte +103 -0
- package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
- package/dist/components/EmptyState.svelte +6 -2
- package/dist/components/chat/Composer.svelte +380 -19
- package/dist/components/chat/Composer.svelte.d.ts +88 -1
- package/dist/components/chat/PlanCard.svelte +218 -88
- package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
- package/dist/components/chat/QuestionCard.svelte +180 -70
- package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
- package/dist/components/chat/QuestionCardSummary.svelte +96 -0
- package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
- package/dist/components/chat/QueueCard.svelte +185 -0
- package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
- package/dist/components/chat/composerLogic.d.ts +31 -0
- package/dist/components/chat/composerLogic.js +37 -0
- package/dist/components/chat/composerReferences.d.ts +28 -0
- package/dist/components/chat/composerReferences.js +23 -0
- package/dist/components/chat/index.d.ts +8 -3
- package/dist/components/chat/index.js +10 -2
- package/dist/components/chat/questionCardLogic.d.ts +40 -3
- package/dist/components/chat/questionCardLogic.js +54 -3
- package/dist/components/chat/queueCardLogic.d.ts +7 -0
- package/dist/components/chat/queueCardLogic.js +5 -0
- package/dist/components/creator/CreatorBar.svelte +54 -1
- package/dist/components/creator/CreatorBar.svelte.d.ts +5 -0
- package/dist/components/creator/index.d.ts +1 -2
- package/dist/components/creator/index.js +2 -0
- package/dist/components/index.d.ts +8 -7
- package/dist/components/index.js +8 -6
- package/dist/components/modals/BaseModal.svelte +23 -4
- package/dist/components/modals/BaseModal.svelte.d.ts +5 -0
- package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
- package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
- package/dist/components/search-input/SearchInput.svelte +317 -14
- package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
- package/dist/components/search-input/index.d.ts +1 -0
- package/dist/components/search-input/index.js +1 -0
- package/dist/components/search-input/index2.d.ts +4 -0
- package/dist/components/search-input/recentSearches.d.ts +16 -0
- package/dist/components/search-input/recentSearches.js +141 -0
- package/dist/components/shell/NavRow.svelte +53 -10
- package/dist/components/shell/NavRow.svelte.d.ts +23 -2
- package/dist/components/shell/NotificationRow.svelte +3 -2
- package/dist/components/shell/ProfileRow.svelte +6 -4
- package/dist/components/shell/ProfileRow.svelte.d.ts +2 -2
- package/dist/components/shell/SettingsDialog.svelte +23 -1
- package/dist/components/shell/WidgetRow.svelte +4 -3
- package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
- package/dist/components/toast/ToasterModal.svelte +8 -3
- package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
- package/dist/components/ui/accordion/accordion-trigger.svelte +19 -0
- package/dist/components/ui/button/button.svelte +4 -2
- package/dist/components/ui/chip/chip.svelte +39 -1
- package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
- package/dist/components/ui/chip/chipProgress.d.ts +14 -0
- package/dist/components/ui/chip/chipProgress.js +21 -0
- package/dist/components/ui/dialog/dialog-content.svelte +24 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +2 -1
- package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +2 -1
- package/dist/components/ui/hover-card/hover-card-content.svelte +2 -1
- package/dist/components/ui/icon-button/icon-button.svelte +2 -0
- package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
- package/dist/components/ui/number-controls/index.d.ts +2 -0
- package/dist/components/ui/number-controls/index.js +2 -0
- package/dist/components/ui/number-controls/number-controls.svelte +530 -0
- package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
- package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
- package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
- package/dist/components/ui/popover/popover-content.svelte +2 -1
- package/dist/components/ui/select/select-content.svelte +2 -1
- package/dist/components/ui/text-flip/index.d.ts +1 -0
- package/dist/components/ui/text-flip/index.js +1 -0
- package/dist/components/ui/text-flip/text-flip.svelte +103 -0
- package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
- package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
- package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/inline-completion/completionAnswer.d.ts +11 -0
- package/dist/inline-completion/completionAnswer.js +49 -0
- package/dist/inline-completion/completionCache.d.ts +24 -0
- package/dist/inline-completion/completionCache.js +47 -0
- package/dist/inline-completion/completionController.d.ts +61 -0
- package/dist/inline-completion/completionController.js +280 -0
- package/dist/inline-completion/completionKeys.d.ts +21 -0
- package/dist/inline-completion/completionKeys.js +19 -0
- package/dist/inline-completion/completionText.d.ts +53 -0
- package/dist/inline-completion/completionText.js +79 -0
- package/dist/inline-completion/completionTypes.d.ts +71 -0
- package/dist/inline-completion/completionTypes.js +5 -0
- package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
- package/dist/inline-completion/gatewayCompletion.js +77 -0
- package/dist/inline-completion/ghostTap.d.ts +19 -0
- package/dist/inline-completion/ghostTap.js +20 -0
- package/dist/inline-completion/hintMemory.d.ts +43 -0
- package/dist/inline-completion/hintMemory.js +90 -0
- package/dist/inline-completion/httpSource.d.ts +40 -0
- package/dist/inline-completion/httpSource.js +149 -0
- package/dist/inline-completion/index.d.ts +30 -0
- package/dist/inline-completion/index.js +20 -0
- package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
- package/dist/inline-completion/inlineCompletionAction.js +310 -0
- package/dist/inline-completion/outcomeReporter.d.ts +49 -0
- package/dist/inline-completion/outcomeReporter.js +139 -0
- package/dist/inline-completion/promiseLike.d.ts +9 -0
- package/dist/inline-completion/promiseLike.js +9 -0
- package/dist/prompt-references/ReferenceMenu.svelte +344 -0
- package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
- package/dist/prompt-references/index.d.ts +27 -0
- package/dist/prompt-references/index.js +20 -0
- package/dist/prompt-references/neutralizingSource.d.ts +21 -0
- package/dist/prompt-references/neutralizingSource.js +29 -0
- package/dist/prompt-references/promptReferences.d.ts +28 -0
- package/dist/prompt-references/promptReferences.js +766 -0
- package/dist/prompt-references/referenceBadge.d.ts +61 -0
- package/dist/prompt-references/referenceBadge.js +82 -0
- package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
- package/dist/prompt-references/referenceBadgePainter.js +106 -0
- package/dist/prompt-references/referenceEditing.d.ts +60 -0
- package/dist/prompt-references/referenceEditing.js +135 -0
- package/dist/prompt-references/referenceLabels.d.ts +56 -0
- package/dist/prompt-references/referenceLabels.js +215 -0
- package/dist/prompt-references/referenceMeasure.d.ts +12 -0
- package/dist/prompt-references/referenceMeasure.js +63 -0
- package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
- package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
- package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
- package/dist/prompt-references/referenceMenuKeys.js +49 -0
- package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
- package/dist/prompt-references/referenceMenuPlacement.js +66 -0
- package/dist/prompt-references/referenceTokens.d.ts +175 -0
- package/dist/prompt-references/referenceTokens.js +332 -0
- package/dist/prompt-references/referenceTrigger.d.ts +52 -0
- package/dist/prompt-references/referenceTrigger.js +100 -0
- package/dist/prompt-references/referenceTypes.d.ts +38 -0
- package/dist/prompt-references/referenceTypes.js +4 -0
- package/dist/prompt-references/sentReferences.d.ts +50 -0
- package/dist/prompt-references/sentReferences.js +122 -0
- package/dist/styles/tokens.css +126 -1
- package/dist/textarea-overlay/index.d.ts +9 -0
- package/dist/textarea-overlay/index.js +7 -0
- package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
- package/dist/textarea-overlay/mirrorSegments.js +47 -0
- package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
- package/dist/textarea-overlay/mirrorSizing.js +40 -0
- package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
- package/dist/textarea-overlay/textareaOverlay.js +277 -0
- package/dist/utils/modalEnterKey.d.ts +139 -0
- package/dist/utils/modalEnterKey.js +276 -0
- package/dist/utils/modalFocusTrap.d.ts +7 -0
- package/dist/utils/modalFocusTrap.js +22 -0
- package/dist/utils/overlayMotion.d.ts +10 -0
- package/dist/utils/overlayMotion.js +12 -3
- package/dist/utils/reducedMotion.d.ts +9 -0
- package/dist/utils/reducedMotion.js +13 -0
- package/dist/utils/revealOpeningSection.d.ts +51 -0
- package/dist/utils/revealOpeningSection.js +109 -0
- package/package.json +16 -1
- package/dist/components/ui/number-stepper/index.d.ts +0 -3
- package/dist/components/ui/number-stepper/index.js +0 -3
- package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
- package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
- package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
- package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The card of the messages that wait for the agent. It has no Figma frame yet: it is modeled on the queue Cursor draws above its
|
|
3
|
+
input, the product owner's reference (16 Nov 2026), and built from the parts the suggestion card uses (card surface, border,
|
|
4
|
+
row type). It sits above the composer, the newest message at the bottom. A row says what was written, on one line, and on hover
|
|
5
|
+
or keyboard focus what can be done with it: send it now (which interrupts the agent), edit it, delete it. While one message is
|
|
6
|
+
edited its row says so and the others hold still.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts" module>
|
|
9
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
10
|
+
|
|
11
|
+
export type QueueCardItem = {
|
|
12
|
+
id: string;
|
|
13
|
+
/** What was written. One line is shown; the whole text is the tooltip of the row. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** How many files go with the message (none when 0 or left out). */
|
|
16
|
+
attachmentCount?: number;
|
|
17
|
+
/** The words for those files ("2 files"): the tooltip and the label of the mark. */
|
|
18
|
+
attachmentLabel?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type QueueCardMessages = {
|
|
22
|
+
/** The button that interrupts the agent and sends this message. */
|
|
23
|
+
sendNow: string;
|
|
24
|
+
/** The label of the pencil. */
|
|
25
|
+
edit: string;
|
|
26
|
+
/** The label of the bin. */
|
|
27
|
+
delete: string;
|
|
28
|
+
/** Said on the row of the message that is being edited. */
|
|
29
|
+
editing: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type QueueCardProps = Omit<HTMLAttributes<HTMLElement>, 'title'> & {
|
|
33
|
+
ref?: HTMLElement | null;
|
|
34
|
+
class?: string;
|
|
35
|
+
/** The header ("2 Queued"): it names the list for screen readers as well. */
|
|
36
|
+
title: string;
|
|
37
|
+
/** What else is true of the queue, at the end of the header ("Paused"). */
|
|
38
|
+
status?: string;
|
|
39
|
+
/** The messages, the oldest first: the newest is at the bottom. A queue with none draws nothing. */
|
|
40
|
+
items: QueueCardItem[];
|
|
41
|
+
/** The message that is being edited, if one is: its row says so, and the others have no buttons. */
|
|
42
|
+
editingId?: string | null;
|
|
43
|
+
messages?: Partial<QueueCardMessages>;
|
|
44
|
+
/** A button is drawn only when its handler is given: a host that cannot interrupt its agent gives no `onSendNow`. */
|
|
45
|
+
onSendNow?: (id: string) => void;
|
|
46
|
+
onEdit?: (id: string) => void;
|
|
47
|
+
onDelete?: (id: string) => void;
|
|
48
|
+
};
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import IconCircle from '@tabler/icons-svelte/icons/circle';
|
|
53
|
+
import IconPaperclip from '@tabler/icons-svelte/icons/paperclip';
|
|
54
|
+
import IconPencil from '@tabler/icons-svelte/icons/pencil';
|
|
55
|
+
import IconTrash from '@tabler/icons-svelte/icons/trash';
|
|
56
|
+
import { cn } from '../../utils.js';
|
|
57
|
+
import { Button } from '../ui/button/index.js';
|
|
58
|
+
import { IconButton } from '../ui/icon-button/index.js';
|
|
59
|
+
import { queueRowMode } from './queueCardLogic.js';
|
|
60
|
+
|
|
61
|
+
const defaultMessages: QueueCardMessages = {
|
|
62
|
+
sendNow: 'Send now',
|
|
63
|
+
edit: 'Edit',
|
|
64
|
+
delete: 'Delete',
|
|
65
|
+
editing: 'Editing'
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let {
|
|
69
|
+
ref = $bindable(null),
|
|
70
|
+
class: className,
|
|
71
|
+
title,
|
|
72
|
+
status = '',
|
|
73
|
+
items,
|
|
74
|
+
editingId = null,
|
|
75
|
+
messages: messagesProp,
|
|
76
|
+
onSendNow,
|
|
77
|
+
onEdit,
|
|
78
|
+
onDelete,
|
|
79
|
+
...restProps
|
|
80
|
+
}: QueueCardProps = $props();
|
|
81
|
+
|
|
82
|
+
const messages = $derived({ ...defaultMessages, ...messagesProp });
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
{#if items.length > 0}
|
|
86
|
+
<section
|
|
87
|
+
bind:this={ref}
|
|
88
|
+
class={cn(
|
|
89
|
+
'rounded-card border-border bg-card flex w-full max-w-full flex-col overflow-hidden border',
|
|
90
|
+
className
|
|
91
|
+
)}
|
|
92
|
+
aria-label={title}
|
|
93
|
+
data-testid="queue-card"
|
|
94
|
+
{...restProps}
|
|
95
|
+
>
|
|
96
|
+
<header
|
|
97
|
+
class="text-label-small text-muted-foreground flex items-center justify-between gap-2 px-3 pt-2 pb-1"
|
|
98
|
+
>
|
|
99
|
+
<span class="font-medium">{title}</span>
|
|
100
|
+
{#if status}
|
|
101
|
+
<span class="text-caption" data-testid="queue-card-status">{status}</span>
|
|
102
|
+
{/if}
|
|
103
|
+
</header>
|
|
104
|
+
<!-- A long queue scrolls inside the card instead of pushing the conversation away -->
|
|
105
|
+
<ul class="flex max-h-48 flex-col overflow-y-auto pb-1">
|
|
106
|
+
{#each items as item (item.id)}
|
|
107
|
+
{@const mode = queueRowMode(item.id, editingId)}
|
|
108
|
+
<li
|
|
109
|
+
class={cn(
|
|
110
|
+
'group duration-fast flex min-h-9 shrink-0 items-center gap-2 px-3 py-1 transition-colors',
|
|
111
|
+
mode === 'idle' && 'hover:bg-accent focus-within:bg-accent',
|
|
112
|
+
mode === 'editing' && 'bg-accent'
|
|
113
|
+
)}
|
|
114
|
+
data-testid="queue-card-row"
|
|
115
|
+
data-mode={mode}
|
|
116
|
+
>
|
|
117
|
+
<IconCircle class="text-muted-foreground size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
118
|
+
<span class="text-body text-foreground min-w-0 flex-1 truncate" title={item.text}
|
|
119
|
+
>{item.text}</span
|
|
120
|
+
>
|
|
121
|
+
{#if item.attachmentCount}
|
|
122
|
+
<span
|
|
123
|
+
class="text-caption text-muted-foreground inline-flex shrink-0 items-center gap-1"
|
|
124
|
+
title={item.attachmentLabel}
|
|
125
|
+
aria-label={item.attachmentLabel}
|
|
126
|
+
data-testid="queue-card-attachments"
|
|
127
|
+
>
|
|
128
|
+
<IconPaperclip class="size-3.5 stroke-2" aria-hidden="true" />
|
|
129
|
+
{item.attachmentCount}
|
|
130
|
+
</span>
|
|
131
|
+
{/if}
|
|
132
|
+
{#if mode === 'editing'}
|
|
133
|
+
<span
|
|
134
|
+
class="text-caption text-muted-foreground shrink-0"
|
|
135
|
+
data-testid="queue-card-editing"
|
|
136
|
+
>
|
|
137
|
+
{messages.editing}
|
|
138
|
+
</span>
|
|
139
|
+
{:else if mode === 'idle' && (onSendNow || onEdit || onDelete)}
|
|
140
|
+
<!--
|
|
141
|
+
Shown on hover and on keyboard focus (and always where there is no hover, a touch screen). They take no room until
|
|
142
|
+
then, so the text has the whole row while nothing is pointed at; the width opens, it is not covered (the accent
|
|
143
|
+
token is a faint tint, so nothing drawn over the text would hide it).
|
|
144
|
+
-->
|
|
145
|
+
<div
|
|
146
|
+
class="duration-fast flex max-w-0 shrink-0 items-center gap-0.5 overflow-hidden opacity-0 transition-[max-width,opacity] group-focus-within:max-w-56 group-focus-within:opacity-100 group-hover:max-w-56 group-hover:opacity-100 [@media(hover:none)]:max-w-none [@media(hover:none)]:opacity-100"
|
|
147
|
+
data-testid="queue-card-actions"
|
|
148
|
+
>
|
|
149
|
+
{#if onSendNow}
|
|
150
|
+
<Button
|
|
151
|
+
variant="ghost"
|
|
152
|
+
size="sm"
|
|
153
|
+
data-testid="queue-card-send-now"
|
|
154
|
+
onclick={() => onSendNow?.(item.id)}
|
|
155
|
+
>
|
|
156
|
+
{messages.sendNow}
|
|
157
|
+
</Button>
|
|
158
|
+
{/if}
|
|
159
|
+
{#if onEdit}
|
|
160
|
+
<IconButton
|
|
161
|
+
size="sm"
|
|
162
|
+
label={messages.edit}
|
|
163
|
+
data-testid="queue-card-edit"
|
|
164
|
+
onclick={() => onEdit?.(item.id)}
|
|
165
|
+
>
|
|
166
|
+
<IconPencil class="size-4 stroke-2" aria-hidden="true" />
|
|
167
|
+
</IconButton>
|
|
168
|
+
{/if}
|
|
169
|
+
{#if onDelete}
|
|
170
|
+
<IconButton
|
|
171
|
+
size="sm"
|
|
172
|
+
label={messages.delete}
|
|
173
|
+
data-testid="queue-card-delete"
|
|
174
|
+
onclick={() => onDelete?.(item.id)}
|
|
175
|
+
>
|
|
176
|
+
<IconTrash class="size-4 stroke-2" aria-hidden="true" />
|
|
177
|
+
</IconButton>
|
|
178
|
+
{/if}
|
|
179
|
+
</div>
|
|
180
|
+
{/if}
|
|
181
|
+
</li>
|
|
182
|
+
{/each}
|
|
183
|
+
</ul>
|
|
184
|
+
</section>
|
|
185
|
+
{/if}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
export type QueueCardItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
/** What was written. One line is shown; the whole text is the tooltip of the row. */
|
|
5
|
+
text: string;
|
|
6
|
+
/** How many files go with the message (none when 0 or left out). */
|
|
7
|
+
attachmentCount?: number;
|
|
8
|
+
/** The words for those files ("2 files"): the tooltip and the label of the mark. */
|
|
9
|
+
attachmentLabel?: string;
|
|
10
|
+
};
|
|
11
|
+
export type QueueCardMessages = {
|
|
12
|
+
/** The button that interrupts the agent and sends this message. */
|
|
13
|
+
sendNow: string;
|
|
14
|
+
/** The label of the pencil. */
|
|
15
|
+
edit: string;
|
|
16
|
+
/** The label of the bin. */
|
|
17
|
+
delete: string;
|
|
18
|
+
/** Said on the row of the message that is being edited. */
|
|
19
|
+
editing: string;
|
|
20
|
+
};
|
|
21
|
+
export type QueueCardProps = Omit<HTMLAttributes<HTMLElement>, 'title'> & {
|
|
22
|
+
ref?: HTMLElement | null;
|
|
23
|
+
class?: string;
|
|
24
|
+
/** The header ("2 Queued"): it names the list for screen readers as well. */
|
|
25
|
+
title: string;
|
|
26
|
+
/** What else is true of the queue, at the end of the header ("Paused"). */
|
|
27
|
+
status?: string;
|
|
28
|
+
/** The messages, the oldest first: the newest is at the bottom. A queue with none draws nothing. */
|
|
29
|
+
items: QueueCardItem[];
|
|
30
|
+
/** The message that is being edited, if one is: its row says so, and the others have no buttons. */
|
|
31
|
+
editingId?: string | null;
|
|
32
|
+
messages?: Partial<QueueCardMessages>;
|
|
33
|
+
/** A button is drawn only when its handler is given: a host that cannot interrupt its agent gives no `onSendNow`. */
|
|
34
|
+
onSendNow?: (id: string) => void;
|
|
35
|
+
onEdit?: (id: string) => void;
|
|
36
|
+
onDelete?: (id: string) => void;
|
|
37
|
+
};
|
|
38
|
+
declare const QueueCard: import("svelte").Component<QueueCardProps, {}, "ref">;
|
|
39
|
+
type QueueCard = ReturnType<typeof QueueCard>;
|
|
40
|
+
export default QueueCard;
|
|
@@ -7,6 +7,13 @@ export declare const COMPOSER_TEXTAREA_MIN_HEIGHT_PX = 44;
|
|
|
7
7
|
export declare function shouldSendOnKeyDown(key: string, shiftKey: boolean, isComposing: boolean): boolean;
|
|
8
8
|
/** Clamp measured scroll height between min and max for autosize. */
|
|
9
9
|
export declare function clampTextareaHeight(scrollHeight: number, minHeight?: number, maxHeight?: number): number;
|
|
10
|
+
/** How many characters of the typed text a screen reader hears before a suggestion: enough for the last words. */
|
|
11
|
+
export declare const COMPLETION_ANNOUNCE_TAIL_CHARACTERS = 48;
|
|
12
|
+
/**
|
|
13
|
+
* What a screen reader says when a suggestion shows after the caret: the last words typed with the suggestion after them (so
|
|
14
|
+
* "build a v" and "ideo player" are heard as "build a video player"), then what the person does to take it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function completionAnnouncement(typedText: string, suggestion: string, hint: string): string;
|
|
10
17
|
export type CanSendTextOptions = {
|
|
11
18
|
disabled?: boolean;
|
|
12
19
|
/** When true, empty trimmed text still cannot send (attachments handled by the component). */
|
|
@@ -15,3 +22,27 @@ export type CanSendTextOptions = {
|
|
|
15
22
|
};
|
|
16
23
|
/** Whether the primary send action is allowed (not stop — use `busy` on the component for that). */
|
|
17
24
|
export declare function canSendText(text: string, options?: CanSendTextOptions): boolean;
|
|
25
|
+
/** What the primary control of the composer does at this moment. */
|
|
26
|
+
export type ComposerPrimaryAction = 'send' | 'queue' | 'stop' | 'confirmEdit';
|
|
27
|
+
export type ComposerPrimaryState = {
|
|
28
|
+
/** An agent is working on the last message. */
|
|
29
|
+
busy: boolean;
|
|
30
|
+
/** The composer holds a queued message that is being edited. */
|
|
31
|
+
editing: boolean;
|
|
32
|
+
/** The host takes a message sent while it is busy (`onQueue`). Without it a busy composer can only stop. */
|
|
33
|
+
canQueue: boolean;
|
|
34
|
+
/** The text is not empty once trimmed and fits the limit: what a queued or an edited message needs. */
|
|
35
|
+
hasQueueableText: boolean;
|
|
36
|
+
};
|
|
37
|
+
/** Whether the text can be queued or saved as an edit: something is written (a queued message is never empty) and it fits. */
|
|
38
|
+
export declare function isQueueableText(text: string, maxLength?: number): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* What the primary control does: it saves an edit while a queued message is edited, queues what is typed while an agent works
|
|
41
|
+
* (when the host takes a queue), stops the agent when nothing is typed, and sends otherwise.
|
|
42
|
+
*/
|
|
43
|
+
export declare function composerPrimaryAction(state: ComposerPrimaryState): ComposerPrimaryAction;
|
|
44
|
+
/**
|
|
45
|
+
* What the Enter key does, given what the primary control would do. When the host takes a queue, Enter on an empty text while
|
|
46
|
+
* an agent works does nothing: Stop is a button to press, not a key to hit by accident. Without a queue it stops, as it always did.
|
|
47
|
+
*/
|
|
48
|
+
export declare function enterKeyAction(action: ComposerPrimaryAction, canQueue: boolean): ComposerPrimaryAction | 'none';
|
|
@@ -17,6 +17,18 @@ export function shouldSendOnKeyDown(key, shiftKey, isComposing) {
|
|
|
17
17
|
export function clampTextareaHeight(scrollHeight, minHeight = COMPOSER_TEXTAREA_MIN_HEIGHT_PX, maxHeight = COMPOSER_TEXTAREA_MAX_HEIGHT_PX) {
|
|
18
18
|
return Math.min(Math.max(scrollHeight, minHeight), maxHeight);
|
|
19
19
|
}
|
|
20
|
+
/** How many characters of the typed text a screen reader hears before a suggestion: enough for the last words. */
|
|
21
|
+
export const COMPLETION_ANNOUNCE_TAIL_CHARACTERS = 48;
|
|
22
|
+
/**
|
|
23
|
+
* What a screen reader says when a suggestion shows after the caret: the last words typed with the suggestion after them (so
|
|
24
|
+
* "build a v" and "ideo player" are heard as "build a video player"), then what the person does to take it.
|
|
25
|
+
*/
|
|
26
|
+
export function completionAnnouncement(typedText, suggestion, hint) {
|
|
27
|
+
const tail = typedText.slice(-COMPLETION_ANNOUNCE_TAIL_CHARACTERS);
|
|
28
|
+
// A cut that lands inside a word would be heard as a word nobody wrote: the half word goes.
|
|
29
|
+
const lastWords = tail.length < typedText.length ? tail.replace(/^\S+\s+/, '') : tail;
|
|
30
|
+
return `${lastWords}${suggestion}. ${hint}`;
|
|
31
|
+
}
|
|
20
32
|
/** Whether the primary send action is allowed (not stop — use `busy` on the component for that). */
|
|
21
33
|
export function canSendText(text, options = {}) {
|
|
22
34
|
if (options.disabled)
|
|
@@ -28,3 +40,28 @@ export function canSendText(text, options = {}) {
|
|
|
28
40
|
return false;
|
|
29
41
|
return true;
|
|
30
42
|
}
|
|
43
|
+
/** Whether the text can be queued or saved as an edit: something is written (a queued message is never empty) and it fits. */
|
|
44
|
+
export function isQueueableText(text, maxLength) {
|
|
45
|
+
const trimmed = text.trim();
|
|
46
|
+
if (trimmed.length === 0)
|
|
47
|
+
return false;
|
|
48
|
+
return maxLength == null || trimmed.length <= maxLength;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What the primary control does: it saves an edit while a queued message is edited, queues what is typed while an agent works
|
|
52
|
+
* (when the host takes a queue), stops the agent when nothing is typed, and sends otherwise.
|
|
53
|
+
*/
|
|
54
|
+
export function composerPrimaryAction(state) {
|
|
55
|
+
if (state.editing)
|
|
56
|
+
return 'confirmEdit';
|
|
57
|
+
if (state.busy)
|
|
58
|
+
return state.canQueue && state.hasQueueableText ? 'queue' : 'stop';
|
|
59
|
+
return 'send';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What the Enter key does, given what the primary control would do. When the host takes a queue, Enter on an empty text while
|
|
63
|
+
* an agent works does nothing: Stop is a button to press, not a key to hit by accident. Without a queue it stops, as it always did.
|
|
64
|
+
*/
|
|
65
|
+
export function enterKeyAction(action, canQueue) {
|
|
66
|
+
return action === 'stop' && canQueue ? 'none' : action;
|
|
67
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the composer does for the files a message may refer to (`#hero_banner`), kept apart from the component so Node can test it:
|
|
3
|
+
* the text a send carries, the references that text makes, the text a suggestion service is allowed to see, and when the composer
|
|
4
|
+
* shows its "type # to reference a file" line. The model of a reference itself lives in `src/lib/prompt-references`.
|
|
5
|
+
*/
|
|
6
|
+
import { type CollectedReference } from '../../prompt-references/referenceTokens.ts';
|
|
7
|
+
/** A file, as far as a send is concerned: what the host knows it by, and the word the person uses for it. */
|
|
8
|
+
export interface ComposerReferenceTarget {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The text a message carries: the box's text with the room each badge reserves taken out ("fix #logo now" is "fix #logo now").
|
|
14
|
+
* A box that does not offer references sends its text as it is.
|
|
15
|
+
*/
|
|
16
|
+
export declare function messageText(value: string, referencesOn: boolean): string;
|
|
17
|
+
export interface ReferencesOfMessageOptions {
|
|
18
|
+
/** The most references a message may carry (the request's own cap). Default: no cap. */
|
|
19
|
+
max?: number;
|
|
20
|
+
/** The character that starts a reference. Default `#`. */
|
|
21
|
+
triggerCharacter?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The references a message makes: each attached file the text names (a badge, or a `#label` typed by hand), once per file, in order.
|
|
25
|
+
* It reads the box's own text, rooms and all: two badges that touch are two references there, and one word once the rooms are gone.
|
|
26
|
+
*/
|
|
27
|
+
export declare function referencesOfMessage(value: string, targets: readonly ComposerReferenceTarget[], options?: ReferencesOfMessageOptions): CollectedReference[];
|
|
28
|
+
export { neutralizingSource, type NeutralizingSettings } from '../../prompt-references/neutralizingSource.ts';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the composer does for the files a message may refer to (`#hero_banner`), kept apart from the component so Node can test it:
|
|
3
|
+
* the text a send carries, the references that text makes, the text a suggestion service is allowed to see, and when the composer
|
|
4
|
+
* shows its "type # to reference a file" line. The model of a reference itself lives in `src/lib/prompt-references`.
|
|
5
|
+
*/
|
|
6
|
+
import { collectReferences, normalizeForSend } from "../../prompt-references/referenceTokens.js";
|
|
7
|
+
/**
|
|
8
|
+
* The text a message carries: the box's text with the room each badge reserves taken out ("fix #logo now" is "fix #logo now").
|
|
9
|
+
* A box that does not offer references sends its text as it is.
|
|
10
|
+
*/
|
|
11
|
+
export function messageText(value, referencesOn) {
|
|
12
|
+
return referencesOn ? normalizeForSend(value) : value;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The references a message makes: each attached file the text names (a badge, or a `#label` typed by hand), once per file, in order.
|
|
16
|
+
* It reads the box's own text, rooms and all: two badges that touch are two references there, and one word once the rooms are gone.
|
|
17
|
+
*/
|
|
18
|
+
export function referencesOfMessage(value, targets, options = {}) {
|
|
19
|
+
return collectReferences(value, targets.map(({ id, label }) => ({ id, label })), { max: options.max, triggerCharacter: options.triggerCharacter });
|
|
20
|
+
}
|
|
21
|
+
// The guard in front of a suggestion source (`neutralizingSource`) lives with the model of a reference, so a host with a box of its
|
|
22
|
+
// own can use it too; it is passed on from here for the Composer and for what already imports it from this file.
|
|
23
|
+
export { neutralizingSource } from "../../prompt-references/neutralizingSource.js";
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
export { Chip } from '../ui/chip';
|
|
2
2
|
export { IconButton } from '../ui/icon-button';
|
|
3
|
-
export { default as Composer, type ComposerMessages, type ComposerProps } from './Composer.svelte';
|
|
3
|
+
export { default as Composer, type ComposerCompletion, type ComposerEditing, type ComposerMessages, type ComposerProps, type ComposerReferenceMessages, type ComposerReferences, type ComposerSendOptions } from './Composer.svelte';
|
|
4
|
+
export { assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles, type CollectedReference, type ReferenceHoverEvent, type ReferenceItem } from '../../prompt-references/index.js';
|
|
5
|
+
export { default as QueueCard, type QueueCardItem, type QueueCardMessages, type QueueCardProps } from './QueueCard.svelte';
|
|
6
|
+
export { queueRowMode, type QueueRowMode } from './queueCardLogic.js';
|
|
4
7
|
export { default as Message, type MessageMessages, type MessageProps, type MessageRole } from './Message.svelte';
|
|
5
8
|
export { default as ChatAlertCard, type ChatAlertCardProps } from './ChatAlertCard.svelte';
|
|
6
9
|
export { default as ActivityRow, type ActivityRowProps, type ActivityRowStatus } from './ActivityRow.svelte';
|
|
7
10
|
export { default as OptionRow, type OptionRowProps, type OptionRowSelectionMode } from './OptionRow.svelte';
|
|
8
11
|
export { default as TaskRow, type TaskRowProps, type TaskRowStatus } from './TaskRow.svelte';
|
|
9
12
|
export { default as ScrollToBottom, type ScrollToBottomProps } from './ScrollToBottom.svelte';
|
|
10
|
-
export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, shouldSendOnKeyDown } from './composerLogic.js';
|
|
13
|
+
export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, type ComposerPrimaryAction, type ComposerPrimaryState } from './composerLogic.js';
|
|
11
14
|
export { default as ChatHeader } from './ChatHeader.svelte';
|
|
12
15
|
export type { ChatHeaderLayout, ChatHeaderMessages } from './ChatHeader.svelte';
|
|
13
16
|
export { default as PlanCard } from './PlanCard.svelte';
|
|
14
17
|
export type { PlanCardMessages, PlanTask } from './PlanCard.svelte';
|
|
15
18
|
export { default as QuestionCard } from './QuestionCard.svelte';
|
|
16
19
|
export type { QuestionCardMessages, QuestionItem, QuestionOption } from './QuestionCard.svelte';
|
|
17
|
-
export {
|
|
20
|
+
export { default as QuestionCardSummary, type QuestionCardSummaryMessages } from './QuestionCardSummary.svelte';
|
|
21
|
+
export { areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption, type QuestionSummaryItem } from './questionCardLogic.js';
|
|
22
|
+
export type { QuestionStepDirection } from './questionCardLogic.js';
|
|
18
23
|
export { default as SuggestionCard } from './SuggestionCard.svelte';
|
|
19
24
|
export type { SuggestionCardMessages } from './SuggestionCard.svelte';
|
|
20
25
|
export { default as MessageRatingActions } from './MessageRatingActions.svelte';
|
|
@@ -5,6 +5,12 @@ export { Chip } from '../ui/chip';
|
|
|
5
5
|
// The chat's composer draws its attach "+" with the same icon button (the chat imports only this barrel).
|
|
6
6
|
export { IconButton } from '../ui/icon-button';
|
|
7
7
|
export { default as Composer } from './Composer.svelte';
|
|
8
|
+
// What a host that offers its attached files to a message (`#hero_banner`) needs besides the composer: the label a file gets, the
|
|
9
|
+
// text once a file leaves, and the shapes of the list the composer takes. Re-exported here because the chat imports only this barrel.
|
|
10
|
+
export { assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles } from '../../prompt-references/index.js';
|
|
11
|
+
// The card of the messages that wait for the agent, above the composer (and what its rows are).
|
|
12
|
+
export { default as QueueCard } from './QueueCard.svelte';
|
|
13
|
+
export { queueRowMode } from './queueCardLogic.js';
|
|
8
14
|
export { default as Message } from './Message.svelte';
|
|
9
15
|
// The card a failed reply is shown in (Figma Alert 526:3205), with its "Try again" button.
|
|
10
16
|
export { default as ChatAlertCard } from './ChatAlertCard.svelte';
|
|
@@ -12,12 +18,14 @@ export { default as ActivityRow } from './ActivityRow.svelte';
|
|
|
12
18
|
export { default as OptionRow } from './OptionRow.svelte';
|
|
13
19
|
export { default as TaskRow } from './TaskRow.svelte';
|
|
14
20
|
export { default as ScrollToBottom } from './ScrollToBottom.svelte';
|
|
15
|
-
export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, shouldSendOnKeyDown } from './composerLogic.js';
|
|
21
|
+
export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown } from './composerLogic.js';
|
|
16
22
|
// [C2 exports]
|
|
17
23
|
export { default as ChatHeader } from './ChatHeader.svelte';
|
|
18
24
|
export { default as PlanCard } from './PlanCard.svelte';
|
|
19
25
|
export { default as QuestionCard } from './QuestionCard.svelte';
|
|
20
|
-
|
|
26
|
+
// The Question Card once it is closed: what was answered, and "Skipped" for a question that was left to the agent.
|
|
27
|
+
export { default as QuestionCardSummary } from './QuestionCardSummary.svelte';
|
|
28
|
+
export { areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption } from './questionCardLogic.js';
|
|
21
29
|
export { default as SuggestionCard } from './SuggestionCard.svelte';
|
|
22
30
|
export { default as MessageRatingActions } from './MessageRatingActions.svelte';
|
|
23
31
|
export { default as MessageCheckpointRow } from './MessageCheckpointRow.svelte';
|
|
@@ -1,11 +1,48 @@
|
|
|
1
|
-
/** Pure selection and keyboard helpers for QuestionCard. */
|
|
2
|
-
|
|
1
|
+
/** Pure selection and keyboard helpers for QuestionCard and QuestionCardSummary. */
|
|
2
|
+
/**
|
|
3
|
+
* The picks after the person presses an option. With several choices allowed (`multiple`) the option is added or taken off. With one,
|
|
4
|
+
* the option replaces the pick; and when the person may leave a question unanswered (`allowClear`, a card whose Next skips) pressing
|
|
5
|
+
* the option that is picked takes it off, so a pick made by mistake can be undone and the question skipped.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toggleOption(selected: readonly string[], optionId: string, multiple: boolean, allowClear?: boolean): string[];
|
|
3
8
|
export declare function moveFocusedIndex(current: number, direction: 'up' | 'down', count: number): number;
|
|
4
9
|
export declare function canSubmitQuestion(selected: readonly string[]): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether Next / Submit can be pressed on the question on show. It needs a pick, unless Next skips (`nextSkips`): then it can always
|
|
12
|
+
* be pressed, and with nothing picked it leaves the question skipped, which is how the agent is told to decide that one itself.
|
|
13
|
+
*/
|
|
14
|
+
export declare function canAdvanceQuestion(selected: readonly string[], nextSkips: boolean): boolean;
|
|
5
15
|
export declare function selectionRole(multiple: boolean): 'radiogroup' | 'group';
|
|
6
16
|
export declare function optionItemRole(multiple: boolean): 'radio' | 'checkbox';
|
|
7
|
-
/** Format the step
|
|
17
|
+
/** Format the step the pager shows between its arrows, such as "1 of 4" (1-based `current`). */
|
|
8
18
|
export declare function formatQuestionStep(template: string, current: number, total: number): string;
|
|
9
19
|
export declare function isFirstQuestion(index: number): boolean;
|
|
10
20
|
export declare function isLastQuestion(index: number, total: number): boolean;
|
|
11
21
|
export declare function primaryQuestionLabel(isLast: boolean, nextLabel: string, submitLabel: string): string;
|
|
22
|
+
/** Which way an arrow of the pager steps: `back` to the question before, `forward` to the one after. */
|
|
23
|
+
export type QuestionStepDirection = 'back' | 'forward';
|
|
24
|
+
/** The arrow that goes back is on from the second question. */
|
|
25
|
+
export declare function canStepBack(index: number): boolean;
|
|
26
|
+
/** The arrow that goes on is on until the last question. */
|
|
27
|
+
export declare function canStepForward(index: number, total: number): boolean;
|
|
28
|
+
/** The question an arrow leads to. It never leaves the questions: at an end the index stays. */
|
|
29
|
+
export declare function stepQuestionIndex(index: number, direction: QuestionStepDirection, total: number): number;
|
|
30
|
+
/** The pager shows with more than one question: with one there is nowhere to step to. */
|
|
31
|
+
export declare function showsQuestionPager(total: number): boolean;
|
|
32
|
+
/** The small title on top of the card: the plural for a few questions, the singular for one. */
|
|
33
|
+
export declare function questionCardTitle(total: number, singular: string, plural: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* The picks of every question, in order of the questions: `currentSelection` stands for the question on show
|
|
36
|
+
* (its pick is not stored until the person leaves it), the others come from `selectionsByIndex`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function collectQuestionSelections(total: number, selectionsByIndex: Readonly<Record<number, readonly string[]>>, currentIndex: number, currentSelection: readonly string[]): string[][];
|
|
39
|
+
/** One question of a card that is closed, as the summary shows it: the question and the words of what was picked. */
|
|
40
|
+
export type QuestionSummaryItem = {
|
|
41
|
+
question: string;
|
|
42
|
+
/** The labels of the options that were picked; empty when the question was skipped. */
|
|
43
|
+
answers: string[];
|
|
44
|
+
};
|
|
45
|
+
/** A question is skipped when nothing was picked for it. */
|
|
46
|
+
export declare function isQuestionSkipped(answers: readonly string[]): boolean;
|
|
47
|
+
/** Whether every question of the card was skipped (a card with no questions is not "skipped": there was nothing to skip). */
|
|
48
|
+
export declare function areAllQuestionsSkipped(items: readonly QuestionSummaryItem[]): boolean;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
/** Pure selection and keyboard helpers for QuestionCard. */
|
|
2
|
-
|
|
1
|
+
/** Pure selection and keyboard helpers for QuestionCard and QuestionCardSummary. */
|
|
2
|
+
/**
|
|
3
|
+
* The picks after the person presses an option. With several choices allowed (`multiple`) the option is added or taken off. With one,
|
|
4
|
+
* the option replaces the pick; and when the person may leave a question unanswered (`allowClear`, a card whose Next skips) pressing
|
|
5
|
+
* the option that is picked takes it off, so a pick made by mistake can be undone and the question skipped.
|
|
6
|
+
*/
|
|
7
|
+
export function toggleOption(selected, optionId, multiple, allowClear = false) {
|
|
3
8
|
if (multiple) {
|
|
4
9
|
return selected.includes(optionId)
|
|
5
10
|
? selected.filter((id) => id !== optionId)
|
|
6
11
|
: [...selected, optionId];
|
|
7
12
|
}
|
|
13
|
+
if (allowClear && selected.includes(optionId))
|
|
14
|
+
return [];
|
|
8
15
|
return [optionId];
|
|
9
16
|
}
|
|
10
17
|
export function moveFocusedIndex(current, direction, count) {
|
|
@@ -18,13 +25,20 @@ export function moveFocusedIndex(current, direction, count) {
|
|
|
18
25
|
export function canSubmitQuestion(selected) {
|
|
19
26
|
return selected.length > 0;
|
|
20
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether Next / Submit can be pressed on the question on show. It needs a pick, unless Next skips (`nextSkips`): then it can always
|
|
30
|
+
* be pressed, and with nothing picked it leaves the question skipped, which is how the agent is told to decide that one itself.
|
|
31
|
+
*/
|
|
32
|
+
export function canAdvanceQuestion(selected, nextSkips) {
|
|
33
|
+
return nextSkips || canSubmitQuestion(selected);
|
|
34
|
+
}
|
|
21
35
|
export function selectionRole(multiple) {
|
|
22
36
|
return multiple ? 'group' : 'radiogroup';
|
|
23
37
|
}
|
|
24
38
|
export function optionItemRole(multiple) {
|
|
25
39
|
return multiple ? 'checkbox' : 'radio';
|
|
26
40
|
}
|
|
27
|
-
/** Format the step
|
|
41
|
+
/** Format the step the pager shows between its arrows, such as "1 of 4" (1-based `current`). */
|
|
28
42
|
export function formatQuestionStep(template, current, total) {
|
|
29
43
|
return template.replace('{current}', String(current)).replace('{total}', String(total));
|
|
30
44
|
}
|
|
@@ -37,3 +51,40 @@ export function isLastQuestion(index, total) {
|
|
|
37
51
|
export function primaryQuestionLabel(isLast, nextLabel, submitLabel) {
|
|
38
52
|
return isLast ? submitLabel : nextLabel;
|
|
39
53
|
}
|
|
54
|
+
/** The arrow that goes back is on from the second question. */
|
|
55
|
+
export function canStepBack(index) {
|
|
56
|
+
return !isFirstQuestion(index);
|
|
57
|
+
}
|
|
58
|
+
/** The arrow that goes on is on until the last question. */
|
|
59
|
+
export function canStepForward(index, total) {
|
|
60
|
+
return !isLastQuestion(index, total);
|
|
61
|
+
}
|
|
62
|
+
/** The question an arrow leads to. It never leaves the questions: at an end the index stays. */
|
|
63
|
+
export function stepQuestionIndex(index, direction, total) {
|
|
64
|
+
if (direction === 'back')
|
|
65
|
+
return canStepBack(index) ? index - 1 : index;
|
|
66
|
+
return canStepForward(index, total) ? index + 1 : index;
|
|
67
|
+
}
|
|
68
|
+
/** The pager shows with more than one question: with one there is nowhere to step to. */
|
|
69
|
+
export function showsQuestionPager(total) {
|
|
70
|
+
return total > 1;
|
|
71
|
+
}
|
|
72
|
+
/** The small title on top of the card: the plural for a few questions, the singular for one. */
|
|
73
|
+
export function questionCardTitle(total, singular, plural) {
|
|
74
|
+
return total > 1 ? plural : singular;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The picks of every question, in order of the questions: `currentSelection` stands for the question on show
|
|
78
|
+
* (its pick is not stored until the person leaves it), the others come from `selectionsByIndex`.
|
|
79
|
+
*/
|
|
80
|
+
export function collectQuestionSelections(total, selectionsByIndex, currentIndex, currentSelection) {
|
|
81
|
+
return Array.from({ length: Math.max(total, 1) }, (_, index) => index === currentIndex ? [...currentSelection] : [...(selectionsByIndex[index] ?? [])]);
|
|
82
|
+
}
|
|
83
|
+
/** A question is skipped when nothing was picked for it. */
|
|
84
|
+
export function isQuestionSkipped(answers) {
|
|
85
|
+
return answers.length === 0;
|
|
86
|
+
}
|
|
87
|
+
/** Whether every question of the card was skipped (a card with no questions is not "skipped": there was nothing to skip). */
|
|
88
|
+
export function areAllQuestionsSkipped(items) {
|
|
89
|
+
return items.length > 0 && items.every((item) => isQuestionSkipped(item.answers));
|
|
90
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a row of the queue card is: `idle` (nothing happens to it: it shows its buttons on hover and focus), `editing` (it is the
|
|
3
|
+
* message in the composer: it says so and has no buttons) or `held` (another message is being edited, so this one has no
|
|
4
|
+
* buttons until that is saved or dropped: one edit at a time).
|
|
5
|
+
*/
|
|
6
|
+
export type QueueRowMode = 'idle' | 'editing' | 'held';
|
|
7
|
+
export declare function queueRowMode(itemId: string, editingId: string | null | undefined): QueueRowMode;
|