@widgetic/chat 0.1.31 → 0.1.33

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.
@@ -635,7 +635,12 @@
635
635
  });
636
636
 
637
637
  // chatLog('[Chat] Sending message:', content.substring(0, 60));
638
- const submittedContent = content;
638
+ const noteLines = (selectedElements ?? [])
639
+ .map((element) => element.note?.trim())
640
+ .filter((note): note is string => !!note);
641
+ const submittedContent = content.trim()
642
+ ? content
643
+ : noteLines.join('\n');
639
644
  const submittedAttachments = normalizedAttachments;
640
645
  const submittedSelectedElements =
641
646
  selectedElements && selectedElements.length > 0 ? [...selectedElements] : undefined;
@@ -1773,7 +1778,7 @@
1773
1778
  let lastGenerationOptionsHeight = 0;
1774
1779
  let generationOptionsHeightReady = false;
1775
1780
 
1776
- // Brand kit / libraries sit in the footer. Grow the host by that height so
1781
+ // The generation options (language, libraries) sit in the footer. Grow the host by that height so
1777
1782
  // the messages area stays put and the input moves down inside the scroller.
1778
1783
  $effect(() => {
1779
1784
  const el = generationOptionsEl;
@@ -1977,7 +1982,12 @@
1977
1982
  <span class="rounded bg-[#7BA668]/15 px-1 py-0.5 font-mono text-[11px] font-medium text-[#3C632C]">
1978
1983
  &lt;{item.tagName}{item.idAttr ? `#${item.idAttr}` : ''}&gt;
1979
1984
  </span>
1980
- {#if item.textSnippet}
1985
+ {#if item.note?.trim()}
1986
+ <span class="text-gray-400">·</span>
1987
+ <span class="max-w-[220px] truncate text-[11px] text-[#3C632C]" title={item.note}>
1988
+ {item.note.trim()}
1989
+ </span>
1990
+ {:else if item.textSnippet}
1981
1991
  <span class="text-gray-400">·</span>
1982
1992
  <span class="max-w-[180px] truncate text-[11px] text-gray-600">
1983
1993
  {item.textSnippet}
@@ -2081,6 +2091,7 @@
2081
2091
  onFilesDropped={(files) => {
2082
2092
  void addFilesAsAttachments(files);
2083
2093
  }}
2094
+ canSendWithoutText={(selectedElements ?? []).some((element) => !!element.note?.trim())}
2084
2095
  />
2085
2096
  </div>
2086
2097
 
@@ -29,6 +29,8 @@
29
29
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
30
30
  /** OS file drag-and-drop onto the input area (not attachment reorder). */
31
31
  onFilesDropped?: (files: File[]) => void;
32
+ /** A selected part already carries a note, so Send works with an empty box. */
33
+ canSendWithoutText?: boolean;
32
34
  /** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
33
35
  placeholder?: string;
34
36
  class?: string;
@@ -48,6 +50,7 @@
48
50
  onInputChange,
49
51
  onAttachmentsChange,
50
52
  onFilesDropped,
53
+ canSendWithoutText = false,
51
54
  placeholder,
52
55
  class: className = '',
53
56
  style = '',
@@ -107,8 +110,12 @@
107
110
  // chatLog('ChatInput destroyed for value:', value);
108
111
  });
109
112
 
113
+ function hasSomethingToSend(): boolean {
114
+ return value.trim().length > 0 || attachments.length > 0 || canSendWithoutText;
115
+ }
116
+
110
117
  function handleSubmit() {
111
- if (!value.trim() && attachments.length === 0) return;
118
+ if (!hasSomethingToSend()) return;
112
119
  if (isSending) return;
113
120
 
114
121
  onSend(value.trim(), attachments.length > 0 ? attachments : undefined);
@@ -339,8 +346,8 @@
339
346
  class:hover:bg-blue-700={!isGenerating}
340
347
  class:bg-red-600={isGenerating}
341
348
  class:hover:bg-red-700={isGenerating}
342
- class:bg-gray-300={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
343
- class:cursor-not-allowed={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
349
+ class:bg-gray-300={!isGenerating && (!hasSomethingToSend() || isSending)}
350
+ class:cursor-not-allowed={!isGenerating && (!hasSomethingToSend() || isSending)}
344
351
  onclick={() => {
345
352
  if (isGenerating) {
346
353
  onStop?.();
@@ -348,7 +355,7 @@
348
355
  }
349
356
  handleSubmit();
350
357
  }}
351
- disabled={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
358
+ disabled={!isGenerating && (!hasSomethingToSend() || isSending)}
352
359
  aria-label={sendLabel}
353
360
  title={sendLabel}
354
361
  >
@@ -17,6 +17,8 @@ interface Props {
17
17
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
18
18
  /** OS file drag-and-drop onto the input area (not attachment reorder). */
19
19
  onFilesDropped?: (files: File[]) => void;
20
+ /** A selected part already carries a note, so Send works with an empty box. */
21
+ canSendWithoutText?: boolean;
20
22
  /** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
21
23
  placeholder?: string;
22
24
  class?: string;
@@ -909,11 +909,11 @@
909
909
  // Local state
910
910
  let messagesContainer: HTMLElement;
911
911
  let autoScroll = $state(true);
912
- /** Model text kept after the preview is up, so thinking and code stay in the thread. */
912
+ /** Model text shown while code is streaming. Cleared when the generation finishes. */
913
913
  let keptGenerationText = $state('');
914
914
  let shownGenerationCount = $state(0);
915
915
  let thinkingShownCount = $state(0);
916
- /** The thinking line stays after the preview, until the next send. */
916
+ /** The thinking line is up only while a generation is running. */
917
917
  let thinkingHold = $state(false);
918
918
  let generationWasRunning = false;
919
919
  // The first paint is shorter than the loaded page. Scrolling then, or treating
@@ -942,6 +942,12 @@
942
942
  thinkingShownCount = 0;
943
943
  thinkingHold = true;
944
944
  }
945
+ if (!isGenerating && generationWasRunning) {
946
+ keptGenerationText = '';
947
+ shownGenerationCount = 0;
948
+ thinkingShownCount = 0;
949
+ thinkingHold = false;
950
+ }
945
951
  generationWasRunning = isGenerating;
946
952
  if (messages.length === 0 && !isGenerating) {
947
953
  keptGenerationText = '';
@@ -1538,6 +1544,7 @@
1538
1544
  {/if}
1539
1545
  {#if showCommitMetaOnUserTurn(turn)}
1540
1546
  {@const commitTitle = getTurnCommitTitle(turn)}
1547
+ {@const versionLabel = getTurnVersionLabel(turn)}
1541
1548
  {#if showCommitMeta && commitTitle}
1542
1549
  <div class="wc-user-commit-title-row flex w-full min-w-0 mt-1">
1543
1550
  <span class="wc-user-commit-title text-xs text-gray-600" title={commitTitle}>
@@ -1547,9 +1554,10 @@
1547
1554
  {/if}
1548
1555
  <div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
1549
1556
  <div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
1550
- {#if getTurnVersionLabel(turn)}
1557
+ <!-- Version 1 is the sketch turn. The words read as a second message, so they stay off. Restore stays. -->
1558
+ {#if versionLabel && versionNumberFromLabel(versionLabel) !== 1}
1551
1559
  <span class="wc-user-version-label text-xs text-gray-500">
1552
- {versionLabelText(getTurnVersionLabel(turn), $t)}
1560
+ {versionLabelText(versionLabel, $t)}
1553
1561
  </span>
1554
1562
  {/if}
1555
1563
  {#if showCommitMeta && getTurnCommitShort(turn)}
@@ -1559,7 +1567,7 @@
1559
1567
  {/if}
1560
1568
  </div>
1561
1569
  {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
1562
- {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply))}
1570
+ {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(versionLabel) !== 1)}
1563
1571
  <button
1564
1572
  class="restore-checkpoint-btn shrink-0"
1565
1573
  disabled={restoreIsCurrentHead}
@@ -28,6 +28,8 @@ export interface SelectedElementChatReference {
28
28
  height: number;
29
29
  };
30
30
  label: string;
31
+ /** A note typed on the preview, sent with this part. */
32
+ note?: string;
31
33
  }
32
34
  /**
33
35
  * Input for creating attachments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",