@widgetic/design-system 0.5.40 → 0.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +73 -0
  2. package/dist/components/ContentRefreshOverlay.svelte +103 -0
  3. package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
  4. package/dist/components/chat/Composer.svelte +380 -19
  5. package/dist/components/chat/Composer.svelte.d.ts +88 -1
  6. package/dist/components/chat/PlanCard.svelte +218 -88
  7. package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
  8. package/dist/components/chat/QuestionCard.svelte +180 -70
  9. package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
  10. package/dist/components/chat/QuestionCardSummary.svelte +96 -0
  11. package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
  12. package/dist/components/chat/QueueCard.svelte +185 -0
  13. package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
  14. package/dist/components/chat/composerLogic.d.ts +31 -0
  15. package/dist/components/chat/composerLogic.js +37 -0
  16. package/dist/components/chat/composerReferences.d.ts +28 -0
  17. package/dist/components/chat/composerReferences.js +23 -0
  18. package/dist/components/chat/index.d.ts +8 -3
  19. package/dist/components/chat/index.js +10 -2
  20. package/dist/components/chat/questionCardLogic.d.ts +40 -3
  21. package/dist/components/chat/questionCardLogic.js +54 -3
  22. package/dist/components/chat/queueCardLogic.d.ts +7 -0
  23. package/dist/components/chat/queueCardLogic.js +5 -0
  24. package/dist/components/creator/index.d.ts +1 -2
  25. package/dist/components/creator/index.js +2 -0
  26. package/dist/components/index.d.ts +8 -7
  27. package/dist/components/index.js +8 -6
  28. package/dist/components/modals/BaseModal.svelte +14 -4
  29. package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
  30. package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
  31. package/dist/components/search-input/SearchInput.svelte +282 -14
  32. package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
  33. package/dist/components/search-input/index.d.ts +1 -0
  34. package/dist/components/search-input/index.js +1 -0
  35. package/dist/components/search-input/index2.d.ts +4 -0
  36. package/dist/components/search-input/recentSearches.d.ts +12 -0
  37. package/dist/components/search-input/recentSearches.js +124 -0
  38. package/dist/components/toast/ToasterModal.svelte +8 -3
  39. package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
  40. package/dist/components/ui/chip/chip.svelte +39 -1
  41. package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
  42. package/dist/components/ui/chip/chipProgress.d.ts +14 -0
  43. package/dist/components/ui/chip/chipProgress.js +21 -0
  44. package/dist/components/ui/icon-button/icon-button.svelte +2 -0
  45. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
  46. package/dist/components/ui/number-controls/index.d.ts +2 -0
  47. package/dist/components/ui/number-controls/index.js +2 -0
  48. package/dist/components/ui/number-controls/number-controls.svelte +530 -0
  49. package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
  50. package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
  51. package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
  52. package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
  53. package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
  54. package/dist/components/ui/text-flip/index.d.ts +1 -0
  55. package/dist/components/ui/text-flip/index.js +1 -0
  56. package/dist/components/ui/text-flip/text-flip.svelte +103 -0
  57. package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
  58. package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
  59. package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
  60. package/dist/inline-completion/completionAnswer.d.ts +11 -0
  61. package/dist/inline-completion/completionAnswer.js +49 -0
  62. package/dist/inline-completion/completionCache.d.ts +24 -0
  63. package/dist/inline-completion/completionCache.js +47 -0
  64. package/dist/inline-completion/completionController.d.ts +61 -0
  65. package/dist/inline-completion/completionController.js +280 -0
  66. package/dist/inline-completion/completionKeys.d.ts +21 -0
  67. package/dist/inline-completion/completionKeys.js +19 -0
  68. package/dist/inline-completion/completionText.d.ts +53 -0
  69. package/dist/inline-completion/completionText.js +79 -0
  70. package/dist/inline-completion/completionTypes.d.ts +71 -0
  71. package/dist/inline-completion/completionTypes.js +5 -0
  72. package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
  73. package/dist/inline-completion/gatewayCompletion.js +77 -0
  74. package/dist/inline-completion/ghostTap.d.ts +19 -0
  75. package/dist/inline-completion/ghostTap.js +20 -0
  76. package/dist/inline-completion/hintMemory.d.ts +43 -0
  77. package/dist/inline-completion/hintMemory.js +90 -0
  78. package/dist/inline-completion/httpSource.d.ts +40 -0
  79. package/dist/inline-completion/httpSource.js +149 -0
  80. package/dist/inline-completion/index.d.ts +30 -0
  81. package/dist/inline-completion/index.js +20 -0
  82. package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
  83. package/dist/inline-completion/inlineCompletionAction.js +310 -0
  84. package/dist/inline-completion/outcomeReporter.d.ts +49 -0
  85. package/dist/inline-completion/outcomeReporter.js +139 -0
  86. package/dist/inline-completion/promiseLike.d.ts +9 -0
  87. package/dist/inline-completion/promiseLike.js +9 -0
  88. package/dist/prompt-references/ReferenceMenu.svelte +344 -0
  89. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
  90. package/dist/prompt-references/index.d.ts +27 -0
  91. package/dist/prompt-references/index.js +20 -0
  92. package/dist/prompt-references/neutralizingSource.d.ts +21 -0
  93. package/dist/prompt-references/neutralizingSource.js +29 -0
  94. package/dist/prompt-references/promptReferences.d.ts +28 -0
  95. package/dist/prompt-references/promptReferences.js +766 -0
  96. package/dist/prompt-references/referenceBadge.d.ts +61 -0
  97. package/dist/prompt-references/referenceBadge.js +82 -0
  98. package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
  99. package/dist/prompt-references/referenceBadgePainter.js +106 -0
  100. package/dist/prompt-references/referenceEditing.d.ts +60 -0
  101. package/dist/prompt-references/referenceEditing.js +135 -0
  102. package/dist/prompt-references/referenceLabels.d.ts +56 -0
  103. package/dist/prompt-references/referenceLabels.js +215 -0
  104. package/dist/prompt-references/referenceMeasure.d.ts +12 -0
  105. package/dist/prompt-references/referenceMeasure.js +63 -0
  106. package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
  107. package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
  108. package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
  109. package/dist/prompt-references/referenceMenuKeys.js +49 -0
  110. package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
  111. package/dist/prompt-references/referenceMenuPlacement.js +66 -0
  112. package/dist/prompt-references/referenceTokens.d.ts +175 -0
  113. package/dist/prompt-references/referenceTokens.js +332 -0
  114. package/dist/prompt-references/referenceTrigger.d.ts +52 -0
  115. package/dist/prompt-references/referenceTrigger.js +100 -0
  116. package/dist/prompt-references/referenceTypes.d.ts +38 -0
  117. package/dist/prompt-references/referenceTypes.js +4 -0
  118. package/dist/prompt-references/sentReferences.d.ts +50 -0
  119. package/dist/prompt-references/sentReferences.js +122 -0
  120. package/dist/styles/tokens.css +58 -0
  121. package/dist/textarea-overlay/index.d.ts +9 -0
  122. package/dist/textarea-overlay/index.js +7 -0
  123. package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
  124. package/dist/textarea-overlay/mirrorSegments.js +47 -0
  125. package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
  126. package/dist/textarea-overlay/mirrorSizing.js +40 -0
  127. package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
  128. package/dist/textarea-overlay/textareaOverlay.js +277 -0
  129. package/dist/utils/overlayMotion.d.ts +1 -0
  130. package/dist/utils/overlayMotion.js +3 -3
  131. package/dist/utils/reducedMotion.d.ts +9 -0
  132. package/dist/utils/reducedMotion.js +13 -0
  133. package/package.json +16 -1
  134. package/dist/components/ui/number-stepper/index.d.ts +0 -3
  135. package/dist/components/ui/number-stepper/index.js +0 -3
  136. package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
  137. package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
  138. package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
  139. package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
@@ -0,0 +1,344 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The `#` menu: the files a person may refer to, each with its thumbnail, label, file name and size, and a larger preview of the
4
+ * highlighted one. It can also show the preview alone, over a badge the pointer is on.
5
+ *
6
+ * It does not own any state: the action (`promptReferences`) tells it what to show and where, and hears back which row was chosen or
7
+ * hovered. The focus never leaves the text box (this is a combobox popup: the action sets `aria-activedescendant` on the box), so the
8
+ * rows take no focus and a press on them is kept from moving it.
9
+ *
10
+ * Both the list and the preview are placed in the TOP LAYER (`popover="manual"`): they are not cut off by an `overflow-hidden` card,
11
+ * are not under a modal's z-index, and stay inside the page's own subtree (a dialog's outside-click guard sees them as inside).
12
+ * Where the top layer is not available they are `fixed` with a high z-index instead.
13
+ */
14
+ import { FILE_GLYPH_PATHS } from './referenceBadge.js';
15
+ import {
16
+ placeMenu,
17
+ placePreview,
18
+ type Box,
19
+ type MenuDirection
20
+ } from './referenceMenuPlacement.js';
21
+ import type { ReferenceItem } from './referenceTypes.js';
22
+
23
+ type Props = {
24
+ /** The rows, best first. Empty: no list (the preview may still show, over a badge). */
25
+ items: readonly ReferenceItem[];
26
+ /** The highlighted row, -1 for none. */
27
+ activeIndex: number;
28
+ /** The `#` the list hangs from, in viewport pixels. */
29
+ anchor: Box | null;
30
+ /** The file the preview shows (the highlighted row's, or the badge the pointer is on). */
31
+ previewItem: ReferenceItem | null;
32
+ /** What the preview hangs from when there is no list: the badge, in viewport pixels. */
33
+ previewAnchor: Box | null;
34
+ /** The id of the list, for the box's `aria-controls`. The rows are `{menuId}-option-{index}`. */
35
+ menuId: string;
36
+ /** What a screen reader calls the list. */
37
+ menuLabel: string;
38
+ direction: MenuDirection;
39
+ /** A row was pressed. */
40
+ onChoose: (item: ReferenceItem) => void;
41
+ /** The pointer moved onto another row. */
42
+ onActiveChange: (index: number) => void;
43
+ };
44
+
45
+ let {
46
+ items,
47
+ activeIndex,
48
+ anchor,
49
+ previewItem,
50
+ previewAnchor,
51
+ menuId,
52
+ menuLabel,
53
+ direction,
54
+ onChoose,
55
+ onActiveChange
56
+ }: Props = $props();
57
+
58
+ /** About seven rows: the list scrolls beyond it. */
59
+ const LIST_MAX_HEIGHT_PX = 296;
60
+
61
+ let listElement = $state<HTMLElement | null>(null);
62
+ let previewElement = $state<HTMLElement | null>(null);
63
+ /** Where the list went, in viewport pixels, once it was measured. */
64
+ let listBox = $state<{
65
+ left: number;
66
+ top: number;
67
+ width: number;
68
+ height: number;
69
+ maxHeight: number;
70
+ } | null>(null);
71
+ let previewPosition = $state<{ left: number; top: number } | null>(null);
72
+ /**
73
+ * The distance of the list and of the picture from the left edge of the page. Both are put by pixel at a place measured from the
74
+ * rectangles of the text box and of the page (the placement code picks the side the text box leaves room on), so a left-to-right
75
+ * and a right-to-left page put them alike.
76
+ */
77
+ const listOffsetStyle = $derived(
78
+ // rtl-ok: measured from the left edge of the page, at a place the placement code chose
79
+ `left: ${listBox?.left ?? 0}px;`
80
+ );
81
+ const previewOffsetStyle = $derived(
82
+ // rtl-ok: measured from the left edge of the page, at a place the placement code chose next to the list
83
+ `left: ${previewPosition?.left ?? 0}px;`
84
+ );
85
+ /** The window's size, kept by Svelte: a resize or a zoom places both again. */
86
+ let windowWidth = $state(0);
87
+ let windowHeight = $state(0);
88
+ /** Pictures that did not load: their glyph is shown instead. */
89
+ let failedPictures = $state<Record<string, boolean>>({});
90
+ /** Where the pointer was at its last move: a layout change under a still pointer raises a move with the same place, which is not one. */
91
+ let lastPointerPosition = { x: -1, y: -1 };
92
+
93
+ let reportedProblem = false;
94
+ function reportProblemOnce(error: unknown): void {
95
+ if (reportedProblem) return;
96
+ reportedProblem = true;
97
+ console.debug(
98
+ '[prompt-references] could not place the menu',
99
+ error instanceof Error ? error.message : error
100
+ );
101
+ }
102
+
103
+ /** The space the page can show, in the same pixels as the anchors: the visual viewport when there is one (a keyboard shrinks it). */
104
+ function viewportSize(): { width: number; height: number } {
105
+ const visual = window.visualViewport;
106
+ return {
107
+ width: visual?.width ?? window.innerWidth,
108
+ height: visual?.height ?? window.innerHeight
109
+ };
110
+ }
111
+
112
+ /** Shows an element in the top layer, and takes it out again when it goes. */
113
+ function showInTopLayer(node: HTMLElement) {
114
+ try {
115
+ node.showPopover?.();
116
+ } catch {
117
+ // Not in the document yet, or already open: nothing to do.
118
+ }
119
+ return {
120
+ destroy() {
121
+ try {
122
+ if (node.matches(':popover-open')) node.hidePopover();
123
+ } catch {
124
+ // No top layer here.
125
+ }
126
+ }
127
+ };
128
+ }
129
+
130
+ // The list: measured at its natural size, then put above or below the `#`, inside the viewport.
131
+ $effect(() => {
132
+ void windowWidth;
133
+ void windowHeight;
134
+ void items.length;
135
+ const element = listElement;
136
+ const hangFrom = anchor;
137
+ if (!element || !hangFrom) {
138
+ listBox = null;
139
+ return;
140
+ }
141
+ try {
142
+ const width = element.offsetWidth;
143
+ // The content's height plus the borders; the scrollHeight is the content's even while the list is cut short.
144
+ const height = element.scrollHeight + (element.offsetHeight - element.clientHeight);
145
+ const placed = placeMenu({
146
+ anchor: hangFrom,
147
+ menu: { width, height },
148
+ viewport: viewportSize(),
149
+ direction,
150
+ preferredMaxHeight: LIST_MAX_HEIGHT_PX
151
+ });
152
+ listBox = {
153
+ left: placed.left,
154
+ top: placed.top,
155
+ width,
156
+ height: Math.min(height, placed.maxHeight),
157
+ maxHeight: placed.maxHeight
158
+ };
159
+ } catch (error) {
160
+ reportProblemOnce(error);
161
+ }
162
+ });
163
+
164
+ // The preview: beside the list when there is one, otherwise above (or below) the badge it belongs to.
165
+ $effect(() => {
166
+ void windowWidth;
167
+ void windowHeight;
168
+ const element = previewElement;
169
+ const shown = previewItem;
170
+ if (!element || !shown) {
171
+ previewPosition = null;
172
+ return;
173
+ }
174
+ try {
175
+ const size = { width: element.offsetWidth, height: element.offsetHeight };
176
+ const viewport = viewportSize();
177
+ if (items.length > 0 && listBox) {
178
+ previewPosition = placePreview({
179
+ beside: {
180
+ left: listBox.left,
181
+ top: listBox.top,
182
+ right: listBox.left + listBox.width,
183
+ bottom: listBox.top + listBox.height
184
+ },
185
+ preview: size,
186
+ viewport,
187
+ direction
188
+ });
189
+ } else if (previewAnchor) {
190
+ const placed = placeMenu({ anchor: previewAnchor, menu: size, viewport, direction });
191
+ previewPosition = { left: placed.left, top: placed.top };
192
+ } else {
193
+ previewPosition = null;
194
+ }
195
+ } catch (error) {
196
+ reportProblemOnce(error);
197
+ }
198
+ });
199
+
200
+ // The highlighted row stays in view when the arrows move it.
201
+ $effect(() => {
202
+ const element = listElement;
203
+ const index = activeIndex;
204
+ if (!element || index < 0) return;
205
+ const row = element.querySelector<HTMLElement>(`[data-prompt-reference-option="${index}"]`);
206
+ if (!row) return;
207
+ const rowTop = row.offsetTop;
208
+ const rowBottom = rowTop + row.offsetHeight;
209
+ if (rowTop < element.scrollTop) element.scrollTop = Math.max(0, rowTop - 4);
210
+ else if (rowBottom > element.scrollTop + element.clientHeight)
211
+ element.scrollTop = rowBottom - element.clientHeight + 4;
212
+ });
213
+
214
+ function markPictureFailed(url: string): void {
215
+ failedPictures[url] = true;
216
+ }
217
+
218
+ /** A move over a row highlights it, unless the pointer has not really moved (the rows scrolled under it). */
219
+ function handleRowPointerMove(event: MouseEvent, index: number): void {
220
+ if (event.clientX === lastPointerPosition.x && event.clientY === lastPointerPosition.y) return;
221
+ lastPointerPosition = { x: event.clientX, y: event.clientY };
222
+ if (index !== activeIndex) onActiveChange(index);
223
+ }
224
+ </script>
225
+
226
+ <svelte:window bind:innerWidth={windowWidth} bind:innerHeight={windowHeight} />
227
+
228
+ {#snippet picture(item: ReferenceItem, sizeClass: string, glyphClass: string)}
229
+ {#if item.previewUrl && !failedPictures[item.previewUrl]}
230
+ <img
231
+ src={item.previewUrl}
232
+ alt=""
233
+ draggable="false"
234
+ class="{sizeClass} bg-background shrink-0 object-cover"
235
+ onerror={() => markPictureFailed(item.previewUrl ?? '')}
236
+ />
237
+ {:else}
238
+ <span
239
+ class="{sizeClass} bg-background text-muted-foreground flex shrink-0 items-center justify-center"
240
+ >
241
+ <svg
242
+ viewBox="0 0 24 24"
243
+ fill="none"
244
+ stroke="currentColor"
245
+ stroke-width="2"
246
+ stroke-linecap="round"
247
+ stroke-linejoin="round"
248
+ aria-hidden="true"
249
+ class={glyphClass}
250
+ >
251
+ {#each FILE_GLYPH_PATHS as pathData (pathData)}
252
+ <path d={pathData} />
253
+ {/each}
254
+ </svg>
255
+ </span>
256
+ {/if}
257
+ {/snippet}
258
+
259
+ {#if items.length > 0}
260
+ <!-- The focus stays in the text box, so the list takes none: a press on it is kept from moving it. -->
261
+ <!-- svelte-ignore a11y_interactive_supports_focus -->
262
+ <div
263
+ bind:this={listElement}
264
+ use:showInTopLayer
265
+ id={menuId}
266
+ role="listbox"
267
+ aria-label={menuLabel}
268
+ popover="manual"
269
+ data-prompt-reference-menu
270
+ class="border-border bg-popover text-popover-foreground pointer-events-auto fixed inset-auto z-[1100] m-0 flex w-72 max-w-[calc(100vw-1rem)] flex-col gap-0.5 overflow-y-auto overscroll-contain rounded-xl border p-1"
271
+ style={listOffsetStyle}
272
+ style:top="{listBox?.top ?? 0}px"
273
+ style:max-height="{listBox?.maxHeight ?? LIST_MAX_HEIGHT_PX}px"
274
+ style:visibility={listBox ? 'visible' : 'hidden'}
275
+ onmousedown={(event) => event.preventDefault()}
276
+ >
277
+ {#each items as item, index (item.id)}
278
+ <!-- The box handles the keys (a combobox popup); the rows are for the pointer. -->
279
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
280
+ <!-- svelte-ignore a11y_interactive_supports_focus -->
281
+ <div
282
+ id="{menuId}-option-{index}"
283
+ role="option"
284
+ aria-selected={index === activeIndex}
285
+ data-prompt-reference-option={index}
286
+ data-label={item.label}
287
+ class="aria-selected:bg-accent aria-selected:text-accent-foreground flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-sm"
288
+ onmousemove={(event) => handleRowPointerMove(event, index)}
289
+ onclick={() => onChoose(item)}
290
+ >
291
+ {@render picture(item, 'size-8 rounded-lg', 'size-4')}
292
+ <span class="flex min-w-0 flex-1 flex-col">
293
+ <span class="truncate font-medium">#{item.label}</span>
294
+ <span class="text-muted-foreground truncate text-xs">
295
+ {item.fileName}{item.sizeLabel ? ` · ${item.sizeLabel}` : ''}
296
+ </span>
297
+ </span>
298
+ <span class="text-muted-foreground text-xs tabular-nums">{item.number}</span>
299
+ </div>
300
+ {/each}
301
+ </div>
302
+ {/if}
303
+
304
+ {#if previewItem}
305
+ <div
306
+ bind:this={previewElement}
307
+ use:showInTopLayer
308
+ popover="manual"
309
+ aria-hidden="true"
310
+ data-prompt-reference-preview
311
+ class="border-border bg-popover text-popover-foreground pointer-events-none fixed inset-auto z-[1100] m-0 box-content flex w-40 flex-col gap-1 overflow-hidden rounded-xl border p-1"
312
+ style={previewOffsetStyle}
313
+ style:top="{previewPosition?.top ?? 0}px"
314
+ style:visibility={previewPosition ? 'visible' : 'hidden'}
315
+ >
316
+ <div class="bg-background flex size-40 items-center justify-center overflow-hidden rounded-lg">
317
+ {#if previewItem.previewUrl && !failedPictures[previewItem.previewUrl]}
318
+ <img
319
+ src={previewItem.previewUrl}
320
+ alt=""
321
+ draggable="false"
322
+ class="size-full object-contain"
323
+ onerror={() => markPictureFailed(previewItem?.previewUrl ?? '')}
324
+ />
325
+ {:else}
326
+ <svg
327
+ viewBox="0 0 24 24"
328
+ fill="none"
329
+ stroke="currentColor"
330
+ stroke-width="1.5"
331
+ stroke-linecap="round"
332
+ stroke-linejoin="round"
333
+ aria-hidden="true"
334
+ class="text-muted-foreground size-10"
335
+ >
336
+ {#each FILE_GLYPH_PATHS as pathData (pathData)}
337
+ <path d={pathData} />
338
+ {/each}
339
+ </svg>
340
+ {/if}
341
+ </div>
342
+ <span class="truncate px-1 text-xs">{previewItem.fileName}</span>
343
+ </div>
344
+ {/if}
@@ -0,0 +1,26 @@
1
+ import { type Box, type MenuDirection } from './referenceMenuPlacement.ts';
2
+ import type { ReferenceItem } from './referenceTypes.ts';
3
+ type Props = {
4
+ /** The rows, best first. Empty: no list (the preview may still show, over a badge). */
5
+ items: readonly ReferenceItem[];
6
+ /** The highlighted row, -1 for none. */
7
+ activeIndex: number;
8
+ /** The `#` the list hangs from, in viewport pixels. */
9
+ anchor: Box | null;
10
+ /** The file the preview shows (the highlighted row's, or the badge the pointer is on). */
11
+ previewItem: ReferenceItem | null;
12
+ /** What the preview hangs from when there is no list: the badge, in viewport pixels. */
13
+ previewAnchor: Box | null;
14
+ /** The id of the list, for the box's `aria-controls`. The rows are `{menuId}-option-{index}`. */
15
+ menuId: string;
16
+ /** What a screen reader calls the list. */
17
+ menuLabel: string;
18
+ direction: MenuDirection;
19
+ /** A row was pressed. */
20
+ onChoose: (item: ReferenceItem) => void;
21
+ /** The pointer moved onto another row. */
22
+ onActiveChange: (index: number) => void;
23
+ };
24
+ declare const ReferenceMenu: import("svelte").Component<Props, {}, "">;
25
+ type ReferenceMenu = ReturnType<typeof ReferenceMenu>;
26
+ export default ReferenceMenu;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@widgetic/design-system/prompt-references` — references to attached files inside a prompt box: type `#` after a space, pick a file,
3
+ * and a badge (thumbnail, name, X) stands in the text. The box stays the native textarea; the badge is painted on the field's mirror
4
+ * layer (`@widgetic/design-system/textarea-overlay`) over room the text reserves for it.
5
+ *
6
+ * The model in this folder is pure (no DOM): the label of a file, the text of a reference, when the menu opens and which references a
7
+ * message makes. On top of it, `promptReferences` is the action (`use:promptReferences`) that opens the `#` menu, edits the field and
8
+ * paints the badges, and `REFERENCE_BADGE_CLASSES` and its siblings are the badge's look, shared with a badge drawn elsewhere. A SENT
9
+ * message draws the same badge (without the X): `segmentSentText` finds which of its words name which of its files (from the text
10
+ * and the file names alone), and `SENT_BADGE_CLASSES` with `sentBadgeWidth` are the pill and its width.
11
+ * A box that also has ghost text (`@widgetic/design-system/inline-completion`) puts `neutralizingSource` in front of its source, so a
12
+ * label, which is made from a file's name, never reaches a suggestion service.
13
+ */
14
+ export { DEFAULT_GENERIC_LABEL_WORD, MAX_REFERENCE_LABEL_LENGTH, REFERENCE_LABEL_CHARACTER, REFERENCE_LABEL_PATTERN, assignReferenceLabel, countCharacters, genericLabelNumber, isGenericFileName, isValidReferenceLabel, labelFromFileName, stripFileExtension, truncateToCharacters } from './referenceLabels.ts';
15
+ export type { AssignReferenceLabelOptions } from './referenceLabels.ts';
16
+ export { BADGE_ROOM_PIXELS, DEFAULT_TOKEN_ROOM, DEFAULT_TRIGGER_CHARACTER, FIGURE_SPACE, MAX_ROOM_SPACES, buildToken, canStartReferenceAt, collectReferences, findReferenceWords, isRegularWhitespace, neutralizeReferences, normalizeForSend, parseTokens, planTokenInsertion, referenceOccurrences, removalRangeOf, removeToken, removeTokensOfLabel, roomForFigureSpaceWidth, snapSelection, triggerCharacterOf, unbadgeTokensWithoutFiles } from './referenceTokens.ts';
17
+ export type { CollectedReference, CollectReferencesOptions, NeutralizeOptions, ReferenceAttachment, ReferenceToken, ReferenceWord, SnapOptions, TextSelection, TokenInsertionPlan, TokenReadingOptions, TokenRoom } from './referenceTokens.ts';
18
+ export { findReferenceTrigger, matchReferenceItems, resolveReferenceMenu } from './referenceTrigger.ts';
19
+ export type { ReferenceMenuCandidate, ReferenceMenuState, ReferenceTrigger, ResolveReferenceMenuOptions } from './referenceTrigger.ts';
20
+ export { neutralizingSource } from './neutralizingSource.ts';
21
+ export type { NeutralizingSettings } from './neutralizingSource.ts';
22
+ export { promptReferences } from './promptReferences.ts';
23
+ export type { PromptReferencesAction, PromptReferencesParams } from './promptReferences.ts';
24
+ export type { PromptReferencesLogger, ReferenceHoverEvent, ReferenceItem, ReferenceMenuStatus, ReferenceMessages } from './referenceTypes.ts';
25
+ export { BADGE_REMOVE_INSET_PX, BADGE_REMOVE_SIZE_PX, BADGE_THUMBNAIL_INSET_PX, BADGE_THUMBNAIL_SIZE_PX, CLOSE_GLYPH_PATHS, FILE_GLYPH_PATHS, REFERENCE_BADGE_CLASSES, REFERENCE_BADGE_GLYPH_CLASSES, REFERENCE_BADGE_REMOVE_CLASSES, REFERENCE_BADGE_SELECTED_CLASSES, REFERENCE_BADGE_THUMBNAIL_CLASSES, SENT_BADGE_CLASSES, SENT_BADGE_LABEL_CLASSES, SENT_BADGE_LEADING_PX, SENT_BADGE_THUMBNAIL_CLASSES, SENT_BADGE_TRAILING_PX, removeLabelFor, sentBadgeWidth } from './referenceBadge.ts';
26
+ export { DEFAULT_MAX_SENT_BADGES, hasSentBadges, labelsOfSentAttachments, segmentSentText } from './sentReferences.ts';
27
+ export type { SegmentSentTextOptions, SentAttachment, SentBadgeSegment, SentSegment, SentTextSegment } from './sentReferences.ts';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `@widgetic/design-system/prompt-references` — references to attached files inside a prompt box: type `#` after a space, pick a file,
3
+ * and a badge (thumbnail, name, X) stands in the text. The box stays the native textarea; the badge is painted on the field's mirror
4
+ * layer (`@widgetic/design-system/textarea-overlay`) over room the text reserves for it.
5
+ *
6
+ * The model in this folder is pure (no DOM): the label of a file, the text of a reference, when the menu opens and which references a
7
+ * message makes. On top of it, `promptReferences` is the action (`use:promptReferences`) that opens the `#` menu, edits the field and
8
+ * paints the badges, and `REFERENCE_BADGE_CLASSES` and its siblings are the badge's look, shared with a badge drawn elsewhere. A SENT
9
+ * message draws the same badge (without the X): `segmentSentText` finds which of its words name which of its files (from the text
10
+ * and the file names alone), and `SENT_BADGE_CLASSES` with `sentBadgeWidth` are the pill and its width.
11
+ * A box that also has ghost text (`@widgetic/design-system/inline-completion`) puts `neutralizingSource` in front of its source, so a
12
+ * label, which is made from a file's name, never reaches a suggestion service.
13
+ */
14
+ export { DEFAULT_GENERIC_LABEL_WORD, MAX_REFERENCE_LABEL_LENGTH, REFERENCE_LABEL_CHARACTER, REFERENCE_LABEL_PATTERN, assignReferenceLabel, countCharacters, genericLabelNumber, isGenericFileName, isValidReferenceLabel, labelFromFileName, stripFileExtension, truncateToCharacters } from "./referenceLabels.js";
15
+ export { BADGE_ROOM_PIXELS, DEFAULT_TOKEN_ROOM, DEFAULT_TRIGGER_CHARACTER, FIGURE_SPACE, MAX_ROOM_SPACES, buildToken, canStartReferenceAt, collectReferences, findReferenceWords, isRegularWhitespace, neutralizeReferences, normalizeForSend, parseTokens, planTokenInsertion, referenceOccurrences, removalRangeOf, removeToken, removeTokensOfLabel, roomForFigureSpaceWidth, snapSelection, triggerCharacterOf, unbadgeTokensWithoutFiles } from "./referenceTokens.js";
16
+ export { findReferenceTrigger, matchReferenceItems, resolveReferenceMenu } from "./referenceTrigger.js";
17
+ export { neutralizingSource } from "./neutralizingSource.js";
18
+ export { promptReferences } from "./promptReferences.js";
19
+ export { BADGE_REMOVE_INSET_PX, BADGE_REMOVE_SIZE_PX, BADGE_THUMBNAIL_INSET_PX, BADGE_THUMBNAIL_SIZE_PX, CLOSE_GLYPH_PATHS, FILE_GLYPH_PATHS, REFERENCE_BADGE_CLASSES, REFERENCE_BADGE_GLYPH_CLASSES, REFERENCE_BADGE_REMOVE_CLASSES, REFERENCE_BADGE_SELECTED_CLASSES, REFERENCE_BADGE_THUMBNAIL_CLASSES, SENT_BADGE_CLASSES, SENT_BADGE_LABEL_CLASSES, SENT_BADGE_LEADING_PX, SENT_BADGE_THUMBNAIL_CLASSES, SENT_BADGE_TRAILING_PX, removeLabelFor, sentBadgeWidth } from "./referenceBadge.js";
20
+ export { DEFAULT_MAX_SENT_BADGES, hasSentBadges, labelsOfSentAttachments, segmentSentText } from "./sentReferences.js";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A suggestion source that never sees the name of an attached file. A label is made from a file's name (`hero-banner-final.png` is
3
+ * `#hero_banner_final`), so a text with a reference in it must not reach a service as it is: every reference is the neutral word
4
+ * `#file` by the time the source gets the text. It is here, with the model of a reference, so a box with its own `<textarea>` (a
5
+ * host that does not use the design system's Composer) puts the same guard in front of the same engine as the Composer does.
6
+ */
7
+ import type { InlineCompletionSource } from '../inline-completion/completionTypes.ts';
8
+ /** What `neutralizingSource` asks for each time a suggestion is wanted: the labels of the files attached now. */
9
+ export interface NeutralizingSettings {
10
+ labels: Iterable<string>;
11
+ triggerCharacter?: string;
12
+ }
13
+ /**
14
+ * A suggestion source that never sees a file's name: every reference in the text (a badge, and a hand-typed `#label` naming an
15
+ * attached file) is the neutral word `#file` by the time the source gets the text, and the rooms of the badges are gone. The box
16
+ * itself still holds, and the suggestion is still laid after, the text as it is.
17
+ *
18
+ * The settings are read for each request, so the one wrapper made for a source stays the same object while files come and go (a new
19
+ * source would start the box's suggestions over). Without a source there is nothing to wrap: `null`.
20
+ */
21
+ export declare function neutralizingSource(source: InlineCompletionSource | null | undefined, readSettings: () => NeutralizingSettings): InlineCompletionSource | null;
@@ -0,0 +1,29 @@
1
+ import { neutralizeReferences } from "./referenceTokens.js";
2
+ /**
3
+ * A suggestion source that never sees a file's name: every reference in the text (a badge, and a hand-typed `#label` naming an
4
+ * attached file) is the neutral word `#file` by the time the source gets the text, and the rooms of the badges are gone. The box
5
+ * itself still holds, and the suggestion is still laid after, the text as it is.
6
+ *
7
+ * The settings are read for each request, so the one wrapper made for a source stays the same object while files come and go (a new
8
+ * source would start the box's suggestions over). Without a source there is nothing to wrap: `null`.
9
+ */
10
+ export function neutralizingSource(source, readSettings) {
11
+ if (!source)
12
+ return null;
13
+ return {
14
+ suggest(request) {
15
+ let text;
16
+ try {
17
+ const { labels, triggerCharacter } = readSettings();
18
+ text = neutralizeReferences(request.text, { knownLabels: labels, triggerCharacter });
19
+ }
20
+ catch (error) {
21
+ // A text that cannot be made neutral does not reach the service as it is (a file's name is the person's own): the answer
22
+ // is "nothing to show", and the box goes on without a suggestion.
23
+ console.warn('[composer] could not neutralize the references of the text, no suggestion asked:', error);
24
+ return Promise.resolve([]);
25
+ }
26
+ return source.suggest({ ...request, text });
27
+ }
28
+ };
29
+ }
@@ -0,0 +1,28 @@
1
+ import type { PromptReferencesLogger, ReferenceHoverEvent, ReferenceItem, ReferenceMenuStatus, ReferenceMessages } from './referenceTypes.ts';
2
+ /** What the host gives the action. Every field may change over time: `update` reads the new ones. */
3
+ export interface PromptReferencesParams {
4
+ /** The files that can be referenced, in tray order. Files without a label are not in it. */
5
+ items: readonly ReferenceItem[];
6
+ /** The words the action shows or speaks. */
7
+ messages: ReferenceMessages;
8
+ /**
9
+ * The text the page holds in the box. It is there so a text the page changes by itself (the box clears after a send, a draft is
10
+ * restored) repaints the badges: the page's own assignments raise no event.
11
+ */
12
+ value: string;
13
+ /** The character that starts a reference. Default `#`. */
14
+ triggerCharacter?: string;
15
+ /** False while the box is switched off (a send is under way): the menu stays closed. Badges still show. Default true. */
16
+ enabled?: boolean;
17
+ /** The pointer is on a badge, or the keys are on a menu row (the tray shows the same file); `label: null` when it left. */
18
+ onHover?: (event: ReferenceHoverEvent) => void;
19
+ /** The menu opened or closed (the ghost text of the same box must go while it is open). */
20
+ onMenuChange?: (status: ReferenceMenuStatus) => void;
21
+ /** Where debug lines go (one per transition, never one per key). Default: the console, at debug level. */
22
+ logger?: PromptReferencesLogger;
23
+ }
24
+ export interface PromptReferencesAction {
25
+ update(params: PromptReferencesParams): void;
26
+ destroy(): void;
27
+ }
28
+ export declare function promptReferences(field: HTMLTextAreaElement, initialParams: PromptReferencesParams): PromptReferencesAction;