@widgetic/design-system 0.5.42 → 0.5.44

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 (31) hide show
  1. package/README.md +55 -3
  2. package/dist/components/chat/Composer.svelte +68 -17
  3. package/dist/components/chat/Composer.svelte.d.ts +22 -2
  4. package/dist/components/chat/ComposerNotice.svelte +56 -0
  5. package/dist/components/chat/ComposerNotice.svelte.d.ts +14 -0
  6. package/dist/components/chat/Message.svelte +50 -41
  7. package/dist/components/chat/MessageRatingActions.svelte +50 -3
  8. package/dist/components/chat/MessageRatingActions.svelte.d.ts +8 -0
  9. package/dist/components/chat/PlanCard.svelte +39 -8
  10. package/dist/components/chat/ScrollToBottom.svelte +13 -2
  11. package/dist/components/chat/ScrollToBottom.svelte.d.ts +1 -0
  12. package/dist/components/chat/composerLogic.d.ts +6 -0
  13. package/dist/components/chat/composerLogic.js +11 -0
  14. package/dist/components/chat/index.d.ts +1 -0
  15. package/dist/components/chat/index.js +2 -0
  16. package/dist/components/chat/planCardLogic.d.ts +24 -0
  17. package/dist/components/chat/planCardLogic.js +20 -0
  18. package/dist/components/index.d.ts +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +10 -0
  21. package/dist/inline-completion/hintMemory.js +1 -0
  22. package/dist/inline-completion/inlineCompletionAction.js +1 -0
  23. package/dist/prompt-references/ReferenceMenu.svelte +72 -72
  24. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +2 -2
  25. package/dist/prompt-references/promptReferences.js +15 -2
  26. package/dist/prompt-references/referenceMenuPlacement.d.ts +2 -16
  27. package/dist/prompt-references/referenceMenuPlacement.js +2 -25
  28. package/dist/prompt-references/referenceTypes.d.ts +5 -0
  29. package/dist/styles/tokens.css +26 -1
  30. package/dist/textarea-overlay/textareaOverlay.js +4 -1
  31. package/package.json +1 -1
@@ -8,6 +8,8 @@ export type MessageRatingActionsMessages = {
8
8
  rateGroup: string;
9
9
  rateUp: string;
10
10
  rateDown: string;
11
+ /** The name of the "i" button at the far end of the row (its tooltip and what a screen reader says). */
12
+ details: string;
11
13
  };
12
14
  export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
13
15
  ref?: HTMLDivElement | null;
@@ -20,6 +22,12 @@ export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
20
22
  onCopy?: () => void | Promise<void>;
21
23
  onRegenerate?: () => void;
22
24
  onRate?: (messageId: string, pressed: VersionThumb) => void;
25
+ /**
26
+ * Draws an "i" button at the far end of the row (away from the buttons that act on the message: it is for support, not for the
27
+ * person's own use). Pressing it calls this; what it opens (the page's dialog with a Support ID) is the page's. Without it no
28
+ * "i" is drawn. Like the rest of the row it is drawn only when the row has something else to show.
29
+ */
30
+ onDetails?: () => void;
23
31
  };
24
32
  declare const MessageRatingActions: import("svelte").Component<MessageRatingActionsProps, {}, "ref">;
25
33
  type MessageRatingActions = ReturnType<typeof MessageRatingActions>;
@@ -20,6 +20,7 @@
20
20
  import { TextFlip } from '../ui/text-flip';
21
21
  import { cn } from '../../utils.js';
22
22
  import { prefersReducedMotion } from '../../utils/reducedMotion.js';
23
+ import { shouldOpenCollapsedPlanCard } from './planCardLogic.js';
23
24
 
24
25
  export type PlanTask = {
25
26
  id: string;
@@ -112,6 +113,7 @@
112
113
  headerIcon,
113
114
  primaryAction,
114
115
  secondaryAction,
116
+ onclick: onclickProp = undefined,
115
117
  ...restProps
116
118
  }: Props = $props();
117
119
 
@@ -145,6 +147,28 @@
145
147
  : messages.showMoreTasks.replace('{count}', String(hiddenCount))
146
148
  );
147
149
 
150
+ // A collapsed card (tasks still folded away) is a surface that opens: the whole of it answers the pointer like a chip does (grey on hover),
151
+ // and a press on it, outside its buttons and links, shows the rest of the tasks, as the toggle at the end of the list does.
152
+ const opensOnPress = $derived(!planning && hiddenCount > 0 && !expanded);
153
+
154
+ function handleCardClick(event: Parameters<NonNullable<Props['onclick']>>[0]): void {
155
+ try {
156
+ // The page's own handler goes first, and may answer the press itself (`preventDefault`)
157
+ onclickProp?.(event);
158
+ const shouldOpen = shouldOpenCollapsedPlanCard({
159
+ collapsed: opensOnPress,
160
+ defaultPrevented: event.defaultPrevented,
161
+ pressedElement: event.target instanceof Element ? event.target : null,
162
+ selectedText: window.getSelection()?.toString() ?? ''
163
+ });
164
+ if (!shouldOpen) return;
165
+ // console.debug('[PlanCard] the collapsed card was pressed: its folded tasks are shown');
166
+ expanded = true;
167
+ } catch (error) {
168
+ console.error('[PlanCard] could not open the collapsed card:', error);
169
+ }
170
+ }
171
+
148
172
  // The three screens of the responsive view, in the order of the plan: small to large. A screen without text is left out.
149
173
  const responsiveRows = $derived(
150
174
  responsive
@@ -243,14 +267,18 @@
243
267
  </div>
244
268
  {/snippet}
245
269
 
270
+ <!-- The press on the card is a pointer shortcut: a keyboard and a screen reader have the toggle at the end of the list, a button -->
246
271
  <div
247
272
  bind:this={ref}
248
273
  class={cn(
249
- 'rounded-card border-border bg-background flex w-full max-w-full flex-col border p-4',
274
+ 'rounded-card border-border bg-background duration-fast flex w-full max-w-full flex-col border p-4 transition-colors',
275
+ opensOnPress && 'hover:bg-accent cursor-pointer',
250
276
  className
251
277
  )}
252
278
  data-plan-state={planning ? 'planning' : 'ready'}
279
+ data-plan-collapsed={opensOnPress ? true : undefined}
253
280
  aria-busy={planning ? true : undefined}
281
+ onclick={handleCardClick}
254
282
  {...restProps}
255
283
  >
256
284
  <header class="flex min-w-0 items-center gap-2">
@@ -311,6 +339,16 @@
311
339
 
312
340
  {#if hiddenCount > 0}
313
341
  <Collapsible.Root bind:open={expanded}>
342
+ <!-- The tasks that were hidden come first, so that opening them lists them right after the ones that were already
343
+ visible; the toggle stays the last thing of the list, whether it says "Show more" or "Show fewer". -->
344
+ <Collapsible.Content
345
+ class="flex flex-col overflow-hidden motion-reduce:transition-none"
346
+ data-testid="plan-card-hidden-tasks"
347
+ >
348
+ {#each hiddenTasks as task (task.id)}
349
+ {@render taskRow(task)}
350
+ {/each}
351
+ </Collapsible.Content>
314
352
  <Collapsible.Trigger
315
353
  class="text-label text-foreground duration-fast hover:bg-accent focus-visible:ring-ring focus-visible:ring-offset-background mt-1 inline-flex h-8 items-center gap-1 rounded-lg px-2 transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden"
316
354
  >
@@ -323,13 +361,6 @@
323
361
  aria-hidden="true"
324
362
  />
325
363
  </Collapsible.Trigger>
326
- <Collapsible.Content
327
- class="flex flex-col overflow-hidden motion-reduce:transition-none"
328
- >
329
- {#each hiddenTasks as task (task.id)}
330
- {@render taskRow(task)}
331
- {/each}
332
- </Collapsible.Content>
333
364
  </Collapsible.Root>
334
365
  {/if}
335
366
  </div>
@@ -1,5 +1,12 @@
1
1
  <!--
2
2
  Figma: Scroll to Bottom (component set 69:79, node 69:79)
3
+
4
+ The arrow slides up from the bottom edge while it fades in, and slides back down while it fades out (owner, 21 Nov 2026: it
5
+ "appears with a slide ... in a fading, and then when it goes back out, it goes back to the bottom, it will slide down and the
6
+ same fading"). It stays in the page the whole time and is only moved and faded, so the list around it never changes size when
7
+ it comes or goes, and a change of mind half way (the person scrolls back down while it is still arriving) turns it around from
8
+ where it is. While it is away it is out of the tab order and out of the accessibility tree (`inert`). People who ask for less
9
+ motion get no slide and no fade.
3
10
  -->
4
11
  <script lang="ts" module>
5
12
  import type { HTMLAttributes } from 'svelte/elements';
@@ -7,6 +14,7 @@
7
14
  export type ScrollToBottomProps = HTMLAttributes<HTMLButtonElement> & {
8
15
  ref?: HTMLButtonElement | null;
9
16
  class?: string;
17
+ /** Whether the arrow is shown. It slides and fades in when this becomes true, and slides and fades out when it becomes false. */
10
18
  visible?: boolean;
11
19
  label?: string;
12
20
  onScroll?: () => void;
@@ -30,10 +38,13 @@
30
38
 
31
39
  <div
32
40
  class={cn(
33
- 'duration-base pointer-events-none transition-opacity',
34
- visible ? 'opacity-100' : 'opacity-0',
41
+ 'duration-base ease-out pointer-events-none transition-[opacity,translate,visibility] motion-reduce:transition-none',
42
+ visible ? 'visible translate-y-0 opacity-100' : 'invisible translate-y-2 opacity-0',
35
43
  className
36
44
  )}
45
+ inert={!visible}
46
+ data-testid="scroll-to-bottom"
47
+ data-visible={visible ? 'true' : 'false'}
37
48
  >
38
49
  <IconButton
39
50
  bind:ref
@@ -2,6 +2,7 @@ import type { HTMLAttributes } from 'svelte/elements';
2
2
  export type ScrollToBottomProps = HTMLAttributes<HTMLButtonElement> & {
3
3
  ref?: HTMLButtonElement | null;
4
4
  class?: string;
5
+ /** Whether the arrow is shown. It slides and fades in when this becomes true, and slides and fades out when it becomes false. */
5
6
  visible?: boolean;
6
7
  label?: string;
7
8
  onScroll?: () => void;
@@ -22,6 +22,12 @@ export type CanSendTextOptions = {
22
22
  };
23
23
  /** Whether the primary send action is allowed (not stop — use `busy` on the component for that). */
24
24
  export declare function canSendText(text: string, options?: CanSendTextOptions): boolean;
25
+ /**
26
+ * The words the box shows in place of what is typed while the pointer (or the keyboard) rests on a suggestion somewhere else on the
27
+ * page: the text trimmed, or `null` when there is nothing to show (blank, or not text at all), so a page can hand over whatever it
28
+ * holds without checking it first.
29
+ */
30
+ export declare function previewTextOf(value: unknown): string | null;
25
31
  /** What the primary control of the composer does at this moment. */
26
32
  export type ComposerPrimaryAction = 'send' | 'queue' | 'stop' | 'confirmEdit';
27
33
  export type ComposerPrimaryState = {
@@ -40,6 +40,17 @@ export function canSendText(text, options = {}) {
40
40
  return false;
41
41
  return true;
42
42
  }
43
+ /**
44
+ * The words the box shows in place of what is typed while the pointer (or the keyboard) rests on a suggestion somewhere else on the
45
+ * page: the text trimmed, or `null` when there is nothing to show (blank, or not text at all), so a page can hand over whatever it
46
+ * holds without checking it first.
47
+ */
48
+ export function previewTextOf(value) {
49
+ if (typeof value !== 'string')
50
+ return null;
51
+ const trimmed = value.trim();
52
+ return trimmed === '' ? null : trimmed;
53
+ }
43
54
  /** Whether the text can be queued or saved as an edit: something is written (a queued message is never empty) and it fits. */
44
55
  export function isQueueableText(text, maxLength) {
45
56
  const trimmed = text.trim();
@@ -10,6 +10,7 @@ export { default as ActivityRow, type ActivityRowProps, type ActivityRowStatus }
10
10
  export { default as OptionRow, type OptionRowProps, type OptionRowSelectionMode } from './OptionRow.svelte';
11
11
  export { default as TaskRow, type TaskRowProps, type TaskRowStatus } from './TaskRow.svelte';
12
12
  export { default as ScrollToBottom, type ScrollToBottomProps } from './ScrollToBottom.svelte';
13
+ export { default as ComposerNotice, type ComposerNoticeProps } from './ComposerNotice.svelte';
13
14
  export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, type ComposerPrimaryAction, type ComposerPrimaryState } from './composerLogic.js';
14
15
  export { default as ChatHeader } from './ChatHeader.svelte';
15
16
  export type { ChatHeaderLayout, ChatHeaderMessages } from './ChatHeader.svelte';
@@ -18,6 +18,8 @@ export { default as ActivityRow } from './ActivityRow.svelte';
18
18
  export { default as OptionRow } from './OptionRow.svelte';
19
19
  export { default as TaskRow } from './TaskRow.svelte';
20
20
  export { default as ScrollToBottom } from './ScrollToBottom.svelte';
21
+ // The tinted notice above the message box that stays while it is true (out of AI credits), with an optional button under the words.
22
+ export { default as ComposerNotice } from './ComposerNotice.svelte';
21
23
  export { canSendText, clampTextareaHeight, COMPOSER_TEXTAREA_MAX_HEIGHT_PX, COMPOSER_TEXTAREA_MIN_HEIGHT_PX, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown } from './composerLogic.js';
22
24
  // [C2 exports]
23
25
  export { default as ChatHeader } from './ChatHeader.svelte';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Whether a press on a plan card is the press that opens it.
3
+ *
4
+ * A collapsed card (it has tasks folded away behind its toggle) is a surface that opens: a press anywhere on it shows the rest of the
5
+ * tasks, as the toggle at the end of the list does. Three presses are not that one:
6
+ * - one a handler of the page already answered (it called `preventDefault`);
7
+ * - one on a button or a link of the card (it does its own work, and the toggle, which is a button, must not be counted twice);
8
+ * - the end of a drag over the text of the card (the person was selecting words, not pressing the card).
9
+ */
10
+ /** What counts as a control of its own inside the card: a press on one of these (or on something inside one) is theirs. */
11
+ export declare const PLAN_CARD_CONTROLS_SELECTOR = "button, a, [role=\"button\"]";
12
+ export type PlanCardPress = {
13
+ /** The card is collapsed: it has tasks folded away, it is not being planned and it is not open. */
14
+ collapsed: boolean;
15
+ /** A handler of the page already answered the press. */
16
+ defaultPrevented: boolean;
17
+ /** What was pressed, or `null` when it is no element. */
18
+ pressedElement: {
19
+ closest(selectors: string): unknown;
20
+ } | null;
21
+ /** The text the person has selected on the page ('' for none). */
22
+ selectedText: string;
23
+ };
24
+ export declare function shouldOpenCollapsedPlanCard(press: PlanCardPress): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Whether a press on a plan card is the press that opens it.
3
+ *
4
+ * A collapsed card (it has tasks folded away behind its toggle) is a surface that opens: a press anywhere on it shows the rest of the
5
+ * tasks, as the toggle at the end of the list does. Three presses are not that one:
6
+ * - one a handler of the page already answered (it called `preventDefault`);
7
+ * - one on a button or a link of the card (it does its own work, and the toggle, which is a button, must not be counted twice);
8
+ * - the end of a drag over the text of the card (the person was selecting words, not pressing the card).
9
+ */
10
+ /** What counts as a control of its own inside the card: a press on one of these (or on something inside one) is theirs. */
11
+ export const PLAN_CARD_CONTROLS_SELECTOR = 'button, a, [role="button"]';
12
+ export function shouldOpenCollapsedPlanCard(press) {
13
+ if (!press.collapsed || press.defaultPrevented)
14
+ return false;
15
+ if (press.pressedElement?.closest(PLAN_CARD_CONTROLS_SELECTOR))
16
+ return false;
17
+ if (press.selectedText !== '')
18
+ return false;
19
+ return true;
20
+ }
@@ -5,7 +5,7 @@ export { default as GenerateLoader } from './GenerateLoader.svelte';
5
5
  export { default as PasswordInput } from './PasswordInput.svelte';
6
6
  export { default as ThumbHashImage } from './ThumbHashImage.svelte';
7
7
  export { default as WScrollArea } from './WScrollArea.svelte';
8
- export { Composer, type ComposerCompletion, type ComposerEditing, type ComposerMessages, type ComposerProps, type ComposerReferenceMessages, type ComposerReferences, type ComposerSendOptions, assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles, type CollectedReference, type ReferenceHoverEvent, type ReferenceItem, QueueCard, type QueueCardItem, type QueueCardMessages, type QueueCardProps, queueRowMode, type QueueRowMode, Message, type MessageMessages, type MessageProps, type MessageRole, ChatAlertCard, type ChatAlertCardProps, ActivityRow, type ActivityRowProps, type ActivityRowStatus, OptionRow, type OptionRowProps, type OptionRowSelectionMode, TaskRow, type TaskRowProps, type TaskRowStatus, ScrollToBottom, type ScrollToBottomProps, canSendText, clampTextareaHeight, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, type ComposerPrimaryAction, type ComposerPrimaryState, ChatHeader, PlanCard, QuestionCard, QuestionCardSummary, type QuestionCardSummaryMessages, areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption, type QuestionSummaryItem, SuggestionCard, MessageRatingActions, MessageCheckpointRow, shouldShowConsoleButton, shouldShowPinButton, shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, type VersionThumb, selectedModelLabel, shouldShowComposerModelMenu, type ComposerModelOption } from './chat';
8
+ export { Composer, type ComposerCompletion, type ComposerEditing, type ComposerMessages, type ComposerProps, type ComposerReferenceMessages, type ComposerReferences, type ComposerSendOptions, assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles, type CollectedReference, type ReferenceHoverEvent, type ReferenceItem, QueueCard, type QueueCardItem, type QueueCardMessages, type QueueCardProps, queueRowMode, type QueueRowMode, Message, type MessageMessages, type MessageProps, type MessageRole, ChatAlertCard, type ChatAlertCardProps, ActivityRow, type ActivityRowProps, type ActivityRowStatus, OptionRow, type OptionRowProps, type OptionRowSelectionMode, TaskRow, type TaskRowProps, type TaskRowStatus, ScrollToBottom, type ScrollToBottomProps, ComposerNotice, type ComposerNoticeProps, canSendText, clampTextareaHeight, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, type ComposerPrimaryAction, type ComposerPrimaryState, ChatHeader, PlanCard, QuestionCard, QuestionCardSummary, type QuestionCardSummaryMessages, areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption, type QuestionSummaryItem, SuggestionCard, MessageRatingActions, MessageCheckpointRow, shouldShowConsoleButton, shouldShowPinButton, shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, type VersionThumb, selectedModelLabel, shouldShowComposerModelMenu, type ComposerModelOption } from './chat';
9
9
  export { ColorPicker, type ColorPickerMessages, type ColorPickerProps, normalizeHex, hexToHsv, hsvToHex, type Hsv } from './color-picker';
10
10
  export { CreatorBar, CanvasBoardStatusChip, type CanvasBoardStatusChipVariant } from './creator';
11
11
  export { default as DebugGrid } from './debug-grid/DebugGrid.svelte';
@@ -6,7 +6,7 @@ export { default as GenerateLoader } from './GenerateLoader.svelte';
6
6
  export { default as PasswordInput } from './PasswordInput.svelte';
7
7
  export { default as ThumbHashImage } from './ThumbHashImage.svelte';
8
8
  export { default as WScrollArea } from './WScrollArea.svelte';
9
- export { Composer, assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles, QueueCard, queueRowMode, Message, ChatAlertCard, ActivityRow, OptionRow, TaskRow, ScrollToBottom, canSendText, clampTextareaHeight, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, ChatHeader, PlanCard, QuestionCard, QuestionCardSummary, areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption, SuggestionCard, MessageRatingActions, MessageCheckpointRow, shouldShowConsoleButton, shouldShowPinButton, shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, selectedModelLabel, shouldShowComposerModelMenu } from './chat';
9
+ export { Composer, assignReferenceLabel, genericLabelNumber, isValidReferenceLabel, referenceOccurrences, removeTokensOfLabel, unbadgeTokensWithoutFiles, QueueCard, queueRowMode, Message, ChatAlertCard, ActivityRow, OptionRow, TaskRow, ScrollToBottom, ComposerNotice, canSendText, clampTextareaHeight, composerPrimaryAction, enterKeyAction, isQueueableText, shouldSendOnKeyDown, ChatHeader, PlanCard, QuestionCard, QuestionCardSummary, areAllQuestionsSkipped, canAdvanceQuestion, canStepBack, canStepForward, canSubmitQuestion, collectQuestionSelections, formatQuestionStep, isFirstQuestion, isLastQuestion, isQuestionSkipped, moveFocusedIndex, optionItemRole, primaryQuestionLabel, questionCardTitle, selectionRole, showsQuestionPager, stepQuestionIndex, toggleOption, SuggestionCard, MessageRatingActions, MessageCheckpointRow, shouldShowConsoleButton, shouldShowPinButton, shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, selectedModelLabel, shouldShowComposerModelMenu } from './chat';
10
10
  export { ColorPicker, normalizeHex, hexToHsv, hsvToHex } from './color-picker';
11
11
  export { CreatorBar, CanvasBoardStatusChip } from './creator';
12
12
  export { default as DebugGrid } from './debug-grid/DebugGrid.svelte';
@@ -12,15 +12,25 @@
12
12
  // alignment inside a menu of a right to left screen.
13
13
  const textDirection = useTextDirection();
14
14
 
15
+ // The sub-menu hangs from its row: the top of its first entry is level with the row that opened it. The library centres a
16
+ // floating element on its anchor unless told otherwise, so a sub-menu of three entries sat a third of its height above the
17
+ // row and did not look as if it came out of it. The offset is the 1px border plus the 4px padding (`border p-1` below) that
18
+ // stand between the top edge of the box and its first entry.
19
+ const SUB_MENU_ALIGN_OFFSET_PX = -5;
20
+
15
21
  let {
16
22
  ref = $bindable(null),
17
23
  class: className,
24
+ align = "start",
25
+ alignOffset = SUB_MENU_ALIGN_OFFSET_PX,
18
26
  ...restProps
19
27
  }: DropdownMenuSubContentProps = $props();
20
28
  </script>
21
29
 
22
30
  <DropdownMenuPrimitive.SubContent
23
31
  bind:ref
32
+ {align}
33
+ {alignOffset}
24
34
  dir={$textDirection}
25
35
  class={cn(
26
36
  // floating-motion: the sub-menu slides in like the menu it opens from (it had no motion before)
@@ -3,6 +3,7 @@ export const COMPLETION_HINT_STORAGE_KEY = 'widgetic:completion-hint-learned:v1'
3
3
  /** What is stored once a suggestion was taken. */
4
4
  const LEARNED_VALUE = '1';
5
5
  const defaultLog = (message, detail) => {
6
+ // Kept on: this is the documented default of the `log` option (a test pins it), and it writes at debug level only.
6
7
  console.debug('[inline-completion]', message, detail ?? '');
7
8
  };
8
9
  /** The page's own storage, or null when there is none (a server render) or the browser refuses to hand it out (it throws). */
@@ -8,6 +8,7 @@ export const GHOST_OVERLAY_OWNER = 'ghost';
8
8
  /** The ghost's colour: the muted text colour of the design system. A host may pass its own classes. */
9
9
  export const DEFAULT_GHOST_CLASS = 'text-muted-foreground';
10
10
  const defaultLog = (message, detail) => {
11
+ // Kept on: this is the documented default of the `log` option (the same line as the hint memory's), and it writes at debug level only.
11
12
  console.debug('[inline-completion]', message, detail ?? '');
12
13
  };
13
14
  /** Text for assistive technology only: out of sight, still read. */
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
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.
3
+ * The `#` menu: the files a person may refer to, each row with its small thumbnail and the file's name, and nothing else (the
4
+ * thumbnail IS the preview: no larger card opens beside the list). It can also show a larger preview alone, over a badge the pointer
5
+ * is on.
5
6
  *
6
7
  * 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
8
  * hovered. The focus never leaves the text box (this is a combobox popup: the action sets `aria-activedescendant` on the box), so the
@@ -12,12 +13,7 @@
12
13
  * Where the top layer is not available they are `fixed` with a high z-index instead.
13
14
  */
14
15
  import { FILE_GLYPH_PATHS } from './referenceBadge.js';
15
- import {
16
- placeMenu,
17
- placePreview,
18
- type Box,
19
- type MenuDirection
20
- } from './referenceMenuPlacement.js';
16
+ import { placeMenu, type Box, type MenuDirection } from './referenceMenuPlacement.js';
21
17
  import type { ReferenceItem } from './referenceTypes.js';
22
18
 
23
19
  type Props = {
@@ -27,9 +23,9 @@
27
23
  activeIndex: number;
28
24
  /** The `#` the list hangs from, in viewport pixels. */
29
25
  anchor: Box | null;
30
- /** The file the preview shows (the highlighted row's, or the badge the pointer is on). */
26
+ /** The file the preview shows: the badge the pointer is on. Never a row of the list, which carries its own small picture. */
31
27
  previewItem: ReferenceItem | null;
32
- /** What the preview hangs from when there is no list: the badge, in viewport pixels. */
28
+ /** What the preview hangs from: the badge, in viewport pixels. Without it there is no preview. */
33
29
  previewAnchor: Box | null;
34
30
  /** The id of the list, for the box's `aria-controls`. The rows are `{menuId}-option-{index}`. */
35
31
  menuId: string;
@@ -71,15 +67,15 @@
71
67
  let previewPosition = $state<{ left: number; top: number } | null>(null);
72
68
  /**
73
69
  * 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.
70
+ * rectangles of the text box (or of the badge) and of the page (the placement code picks the side there is room on), so a
71
+ * left-to-right and a right-to-left page put them alike.
76
72
  */
77
73
  const listOffsetStyle = $derived(
78
74
  // rtl-ok: measured from the left edge of the page, at a place the placement code chose
79
75
  `left: ${listBox?.left ?? 0}px;`
80
76
  );
81
77
  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
78
+ // rtl-ok: measured from the left edge of the page, at a place the placement code chose over the badge
83
79
  `left: ${previewPosition?.left ?? 0}px;`
84
80
  );
85
81
  /** The window's size, kept by Svelte: a resize or a zoom places both again. */
@@ -94,10 +90,10 @@
94
90
  function reportProblemOnce(error: unknown): void {
95
91
  if (reportedProblem) return;
96
92
  reportedProblem = true;
97
- console.debug(
98
- '[prompt-references] could not place the menu',
99
- error instanceof Error ? error.message : error
100
- );
93
+ // console.debug(
94
+ // '[prompt-references] could not place the menu',
95
+ // error instanceof Error ? error.message : error
96
+ // );
101
97
  }
102
98
 
103
99
  /** The space the page can show, in the same pixels as the anchors: the visual viewport when there is one (a keyboard shrinks it). */
@@ -161,37 +157,21 @@
161
157
  }
162
158
  });
163
159
 
164
- // The preview: beside the list when there is one, otherwise above (or below) the badge it belongs to.
160
+ // The preview: above (or below) the badge it belongs to. The list has no card of its own beside it (its rows carry a small picture).
165
161
  $effect(() => {
166
162
  void windowWidth;
167
163
  void windowHeight;
168
164
  const element = previewElement;
169
165
  const shown = previewItem;
170
- if (!element || !shown) {
166
+ const hangFrom = previewAnchor;
167
+ if (!element || !shown || !hangFrom) {
171
168
  previewPosition = null;
172
169
  return;
173
170
  }
174
171
  try {
175
172
  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
- }
173
+ const placed = placeMenu({ anchor: hangFrom, menu: size, viewport: viewportSize(), direction });
174
+ previewPosition = { left: placed.left, top: placed.top };
195
175
  } catch (error) {
196
176
  reportProblemOnce(error);
197
177
  }
@@ -215,6 +195,11 @@
215
195
  failedPictures[url] = true;
216
196
  }
217
197
 
198
+ /** What the pointer shows when it rests on a row: the whole name (a long one is cut short), and the size when the host knows it. */
199
+ function rowTitle(item: ReferenceItem): string {
200
+ return item.sizeLabel ? `${item.fileName} · ${item.sizeLabel}` : item.fileName;
201
+ }
202
+
218
203
  /** A move over a row highlights it, unless the pointer has not really moved (the rows scrolled under it). */
219
204
  function handleRowPointerMove(event: MouseEvent, index: number): void {
220
205
  if (event.clientX === lastPointerPosition.x && event.clientY === lastPointerPosition.y) return;
@@ -282,6 +267,7 @@
282
267
  id="{menuId}-option-{index}"
283
268
  role="option"
284
269
  aria-selected={index === activeIndex}
270
+ aria-label={item.fileName}
285
271
  data-prompt-reference-option={index}
286
272
  data-label={item.label}
287
273
  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"
@@ -289,56 +275,70 @@
289
275
  onclick={() => onChoose(item)}
290
276
  >
291
277
  {@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>
278
+ <!-- The name and nothing else. It may take a second line before it is cut with an ellipsis: files from a camera or an
279
+ export often share a long beginning and differ at the end, so one line cut at the end would show two rows alike. -->
280
+ <span
281
+ class="line-clamp-2 min-w-0 flex-1 [overflow-wrap:anywhere]"
282
+ data-prompt-reference-name
283
+ title={rowTitle(item)}>{item.fileName}</span
284
+ >
298
285
  <span class="text-muted-foreground text-xs tabular-nums">{item.number}</span>
299
286
  </div>
300
287
  {/each}
301
288
  </div>
302
289
  {/if}
303
290
 
304
- {#if previewItem}
291
+ {#if previewItem && previewAnchor}
292
+ <!-- Over a badge the pointer is on. A row of the list never gets one: its small picture is the preview. -->
305
293
  <div
306
294
  bind:this={previewElement}
307
295
  use:showInTopLayer
308
296
  popover="manual"
309
297
  aria-hidden="true"
310
298
  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"
299
+ class="border-border bg-popover text-popover-foreground pointer-events-none fixed inset-auto z-[1100] m-0 box-content flex flex-col gap-1 overflow-hidden rounded-xl border p-1 {previewItem.excerpt
300
+ ? 'w-64'
301
+ : 'w-40'}"
312
302
  style={previewOffsetStyle}
313
303
  style:top="{previewPosition?.top ?? 0}px"
314
304
  style:visibility={previewPosition ? 'visible' : 'hidden'}
315
305
  >
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>
306
+ {#if previewItem.excerpt}
307
+ <!-- A text: what it says, from its beginning, cut short with an ellipsis (a long text is far more than the card can hold).
308
+ The padding sits on the wrapper: a clamped box with padding of its own lets a tenth line show through the padding. -->
309
+ <div class="bg-background w-full overflow-hidden rounded-lg p-2">
310
+ <p
311
+ class="text-muted-foreground line-clamp-9 w-full text-xs leading-4 break-words whitespace-pre-wrap"
312
+ data-prompt-reference-excerpt>{previewItem.excerpt}</p>
313
+ </div>
314
+ {:else}
315
+ <div class="bg-background flex size-40 items-center justify-center overflow-hidden rounded-lg">
316
+ {#if previewItem.previewUrl && !failedPictures[previewItem.previewUrl]}
317
+ <img
318
+ src={previewItem.previewUrl}
319
+ alt=""
320
+ draggable="false"
321
+ class="size-full object-contain"
322
+ onerror={() => markPictureFailed(previewItem?.previewUrl ?? '')}
323
+ />
324
+ {:else}
325
+ <svg
326
+ viewBox="0 0 24 24"
327
+ fill="none"
328
+ stroke="currentColor"
329
+ stroke-width="1.5"
330
+ stroke-linecap="round"
331
+ stroke-linejoin="round"
332
+ aria-hidden="true"
333
+ class="text-muted-foreground size-10"
334
+ >
335
+ {#each FILE_GLYPH_PATHS as pathData (pathData)}
336
+ <path d={pathData} />
337
+ {/each}
338
+ </svg>
339
+ {/if}
340
+ </div>
341
+ {/if}
342
342
  <span class="truncate px-1 text-xs">{previewItem.fileName}</span>
343
343
  </div>
344
344
  {/if}
@@ -7,9 +7,9 @@ type Props = {
7
7
  activeIndex: number;
8
8
  /** The `#` the list hangs from, in viewport pixels. */
9
9
  anchor: Box | null;
10
- /** The file the preview shows (the highlighted row's, or the badge the pointer is on). */
10
+ /** The file the preview shows: the badge the pointer is on. Never a row of the list, which carries its own small picture. */
11
11
  previewItem: ReferenceItem | null;
12
- /** What the preview hangs from when there is no list: the badge, in viewport pixels. */
12
+ /** What the preview hangs from: the badge, in viewport pixels. Without it there is no preview. */
13
13
  previewAnchor: Box | null;
14
14
  /** The id of the list, for the box's `aria-controls`. The rows are `{menuId}-option-{index}`. */
15
15
  menuId: string;
@@ -82,6 +82,7 @@ export function promptReferences(field, initialParams) {
82
82
  const reportedKinds = new Set();
83
83
  function log(message, detail) {
84
84
  try {
85
+ // Kept on: the console at debug level is the documented default of the `logger` option.
85
86
  if (params.logger)
86
87
  params.logger(message, detail);
87
88
  else
@@ -196,8 +197,15 @@ export function promptReferences(field, initialParams) {
196
197
  const selection = currentSelection();
197
198
  const decorations = [];
198
199
  let badgeCount = 0;
200
+ const tokens = badgesFellBack ? [] : readTokens();
201
+ // The badge under the pointer can be gone with no pointer move (the message was sent, or the text cleared, while the pointer rested
202
+ // on it): its preview goes with it, instead of hanging over the box until the pointer moves.
203
+ const hoveredBadgeIsGone = badgeHover !== null &&
204
+ !tokens.some((token) => itemOfToken(token)?.label.toLowerCase() === hoveredLabel());
205
+ if (hoveredBadgeIsGone)
206
+ badgeHover = null;
199
207
  if (!badgesFellBack) {
200
- for (const token of readTokens()) {
208
+ for (const token of tokens) {
201
209
  const item = itemOfToken(token);
202
210
  if (!item)
203
211
  continue;
@@ -230,6 +238,10 @@ export function promptReferences(field, initialParams) {
230
238
  });
231
239
  }
232
240
  overlay.setDecorations(decorations);
241
+ if (hoveredBadgeIsGone) {
242
+ syncMenuView();
243
+ tellHover(null, 'badge');
244
+ }
233
245
  if (badgeCount > 0 && !layoutCheckQueued) {
234
246
  layoutCheckQueued = true;
235
247
  // After the layer's own paint, which is queued first.
@@ -383,12 +395,13 @@ export function promptReferences(field, initialParams) {
383
395
  const host = ensureMenuHost();
384
396
  const base = { menuLabel: params.messages.menuLabel, direction: fieldDirection() };
385
397
  if (openMenu) {
398
+ // The list alone: each row has its own small picture, so no larger card opens beside it for the highlighted row.
386
399
  host.update({
387
400
  ...base,
388
401
  items: openMenu.matches,
389
402
  activeIndex: openMenu.activeIndex,
390
403
  anchor: measureAnchor(),
391
- previewItem: openMenu.matches[openMenu.activeIndex] ?? null,
404
+ previewItem: null,
392
405
  previewAnchor: null
393
406
  });
394
407
  }