@widgetic/editor 4.1.13 → 4.1.15

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 (89) hide show
  1. package/dist/components/PreviewChromeControls.svelte +15 -21
  2. package/dist/components/WidgetPreview.svelte +136 -105
  3. package/dist/components/color-select/ColorSelect.svelte +203 -224
  4. package/dist/components/color-select/constants.d.ts +4 -2
  5. package/dist/components/color-select/constants.js +4 -2
  6. package/dist/components/color-select/render.js +10 -9
  7. package/dist/components/editors/CompositionEditorApp.svelte +55 -40
  8. package/dist/components/editors/EditLeaseNotice.svelte +44 -33
  9. package/dist/components/editors/EmbedEditor.svelte +133 -259
  10. package/dist/components/editors/PropsEditor.svelte +426 -1333
  11. package/dist/components/editors/props-editor.css +5 -68
  12. package/dist/components/ic/AngleInputController.svelte +202 -277
  13. package/dist/components/ic/BrowserInputController.svelte +813 -803
  14. package/dist/components/ic/CheckboxInputController.svelte +92 -169
  15. package/dist/components/ic/CheckboxInputController.svelte.d.ts +2 -8
  16. package/dist/components/ic/ColorPickerInputController.svelte +1589 -1587
  17. package/dist/components/ic/ColorPickerInputController.svelte.d.ts +3 -3
  18. package/dist/components/ic/DateFieldInputController.svelte +455 -465
  19. package/dist/components/ic/DatePickerInputController.svelte +355 -368
  20. package/dist/components/ic/DatePickerInputController.svelte.d.ts +1 -1
  21. package/dist/components/ic/DropdownInputController.svelte +130 -200
  22. package/dist/components/ic/FixedPositionInputController.svelte +255 -276
  23. package/dist/components/ic/FixedPositionInputController.svelte.d.ts +5 -1
  24. package/dist/components/ic/FontInputController.svelte +2110 -2231
  25. package/dist/components/ic/FontInputController.svelte.d.ts +11 -11
  26. package/dist/components/ic/InputControllerHeader.svelte +141 -147
  27. package/dist/components/ic/InputControllerRenderer.svelte +5 -1
  28. package/dist/components/ic/InputControllerRenderer.svelte.d.ts +2 -1
  29. package/dist/components/ic/InputControllerRow.svelte +74 -0
  30. package/dist/components/ic/InputControllerRow.svelte.d.ts +14 -0
  31. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +401 -0
  32. package/dist/components/ic/KnowledgeDocumentsInputController.svelte.d.ts +11 -0
  33. package/dist/components/ic/KnowledgeTextForm.svelte +109 -0
  34. package/dist/components/ic/KnowledgeTextForm.svelte.d.ts +15 -0
  35. package/dist/components/ic/NumberControls.svelte +303 -269
  36. package/dist/components/ic/NumberControls.svelte.d.ts +4 -1
  37. package/dist/components/ic/NumberInputController.svelte +361 -301
  38. package/dist/components/ic/NumberInputController.svelte.d.ts +2 -0
  39. package/dist/components/ic/PositionInputController.svelte +253 -176
  40. package/dist/components/ic/PositionInputController.svelte.d.ts +2 -0
  41. package/dist/components/ic/RadioGroupInputController.svelte +71 -137
  42. package/dist/components/ic/RadioGroupInputController.svelte.d.ts +2 -8
  43. package/dist/components/ic/RangeCalendarInputController.svelte +233 -270
  44. package/dist/components/ic/RangeCalendarInputController.svelte.d.ts +2 -2
  45. package/dist/components/ic/RoundedCornersInputController.svelte +412 -435
  46. package/dist/components/ic/RoundedCornersInputController.svelte.d.ts +2 -0
  47. package/dist/components/ic/SliderInputController.svelte +263 -332
  48. package/dist/components/ic/SliderInputController.svelte.d.ts +1 -1
  49. package/dist/components/ic/SliderRangeInputController.svelte +140 -144
  50. package/dist/components/ic/SliderRangeInputController.svelte.d.ts +3 -3
  51. package/dist/components/ic/SwitchInputController.svelte +47 -109
  52. package/dist/components/ic/TagsInputController.svelte +95 -110
  53. package/dist/components/ic/TextAreaInputController.svelte +1794 -1935
  54. package/dist/components/ic/TextAreaPreviewInputController.svelte +436 -438
  55. package/dist/components/ic/TextAreaPreviewInputController.svelte.d.ts +2 -2
  56. package/dist/components/ic/TextInputController.svelte +65 -75
  57. package/dist/components/ic/TextInputController.svelte.d.ts +2 -0
  58. package/dist/components/ic/TimeInputController.svelte +433 -431
  59. package/dist/components/ic/VectorInputController.svelte +1833 -1831
  60. package/dist/components/ic/VectorInputController.svelte.d.ts +10 -10
  61. package/dist/components/ic/index.d.ts +2 -0
  62. package/dist/components/ic/index.js +2 -0
  63. package/dist/components/ic/shared/CategoryTabs.svelte +28 -35
  64. package/dist/components/ic/shared/ItemGrid.svelte +145 -179
  65. package/dist/components/ic/shared/RecentItemsSection.svelte +208 -271
  66. package/dist/components/ic/shared/RecentItemsSection.svelte.d.ts +1 -1
  67. package/dist/components/ui/arrows/OpacitySliderArrows.svelte +23 -38
  68. package/dist/components/ui/arrows/OpacitySliderArrows.svelte.d.ts +1 -4
  69. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +45 -0
  70. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte.d.ts +26 -0
  71. package/dist/components/ui/checkerboard-background/CheckerboardBackground.svelte +20 -12
  72. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte +39 -0
  73. package/dist/components/ui/shadow-picker-host/ShadowPickerHost.svelte.d.ts +10 -0
  74. package/dist/composition/compositionApi.d.ts +21 -1
  75. package/dist/composition/compositionApi.js +64 -5
  76. package/dist/composition/knowledgeDocuments.d.ts +90 -0
  77. package/dist/composition/knowledgeDocuments.js +94 -0
  78. package/dist/composition/knowledgeDocumentsPanel.d.ts +152 -0
  79. package/dist/composition/knowledgeDocumentsPanel.js +443 -0
  80. package/dist/i18n/language.d.ts +86 -36
  81. package/dist/i18n/messages.d.ts +97 -34
  82. package/dist/i18n/messages.js +104 -34
  83. package/dist/i18n/translate.d.ts +1 -1
  84. package/dist/index.d.ts +1 -0
  85. package/dist/knowledgeDocumentsContext.d.ts +10 -0
  86. package/dist/knowledgeDocumentsContext.js +31 -0
  87. package/dist/utils.d.ts +7 -0
  88. package/dist/utils.js +26 -2
  89. package/package.json +4 -4
@@ -0,0 +1,401 @@
1
+ <!--
2
+ * KnowledgeDocumentsInputController
3
+ *
4
+ * The Documents panel of AI Answers: where the owner of a widget gives its AI the documents the answers are written from.
5
+ * It holds no value of the widget. Its documents live on the Widgetic API, next to the composition, and are listed, added
6
+ * and removed through the calls the composition editor hands down (see knowledgeDocumentsContext.ts).
7
+ *
8
+ * What the owner can do:
9
+ * - add files (a text, Markdown or CSV file, or a picture of a page; not a PDF yet), by choosing them or dropping them on the panel
10
+ * - paste text, with a title of their own
11
+ * - remove a document (two presses, so a slip does not lose one)
12
+ *
13
+ * What happens behind it (loading, sending one file after the other, the sentences for what can go wrong) is in
14
+ * knowledgeDocumentsPanel.ts, which can be tested without a screen; this file only draws its state.
15
+ *
16
+ * The header ("Documents" and its help) is drawn by the settings editor, like the header of every other control, and this
17
+ * control is given the full width of the column instead of the narrow one the others have.
18
+ -->
19
+
20
+ <script module lang="ts">
21
+ import type { KnowledgeDocumentsPanel as KnowledgeDocumentsPanelType } from '../../composition/knowledgeDocumentsPanel';
22
+
23
+ /** Declared props contract: what the settings editor hands to every control that is drawn from a schema. */
24
+ export interface KnowledgeDocumentsInputControllerProps {
25
+ /** Called when something inside the panel takes the focus, like every control's `onFocus`. */
26
+ onFocus?: () => void;
27
+ /** A panel made elsewhere (a test hands one in). Without it the control makes its own from the editor's client. */
28
+ panel?: KnowledgeDocumentsPanelType;
29
+ }
30
+ </script>
31
+
32
+ <script lang="ts">
33
+ import { onDestroy, onMount } from 'svelte';
34
+ import { Button, IconButton } from '@widgetic/design-system/components';
35
+ import {
36
+ IconAlertTriangle,
37
+ IconFileText,
38
+ IconLoader2,
39
+ IconPlus,
40
+ IconTrash
41
+ } from '@widgetic/design-system/icons';
42
+ import {
43
+ dirForUserText,
44
+ useTextDirection
45
+ } from '@widgetic/design-system/components/textDirection';
46
+ import KnowledgeTextForm from './KnowledgeTextForm.svelte';
47
+ import { useEditorLanguage } from '../../i18n/language';
48
+ import { useEditorKnowledgeDocuments } from '../../knowledgeDocumentsContext';
49
+ import {
50
+ KnowledgeDocumentsPanel,
51
+ type PanelMessage
52
+ } from '../../composition/knowledgeDocumentsPanel';
53
+ import { KNOWLEDGE_FILE_ACCEPT } from '../../composition/knowledgeDocuments';
54
+
55
+ let {
56
+ onFocus = () => {},
57
+ panel: suppliedPanel = undefined
58
+ }: KnowledgeDocumentsInputControllerProps = $props();
59
+
60
+ // The words of the editor in the language of the page, and the way the screen is read (a document's title is what a person
61
+ // typed, so on a right to left screen it is read by its own first letter).
62
+ const { t, locale } = useEditorLanguage();
63
+ const textDirection = useTextDirection();
64
+
65
+ // The calls for the composition being edited. `undefined` outside a composition editor: the panel then says so.
66
+ const getKnowledgeClient = useEditorKnowledgeDocuments();
67
+
68
+ // The panel is made once, when this control is made, from the client of that moment: a control belongs to one composition.
69
+ // svelte-ignore state_referenced_locally
70
+ const panel = suppliedPanel ?? new KnowledgeDocumentsPanel({ client: getKnowledgeClient() });
71
+
72
+ let fileChooser: HTMLInputElement | undefined = $state();
73
+ let pasteButton: HTMLButtonElement | null = $state(null);
74
+ let noticesElement: HTMLElement | undefined = $state();
75
+ let pasteFormOpen = $state(false);
76
+ // How many drag events of files have entered the panel and not left it yet (enter and leave fire for every child).
77
+ let draggingFilesDepth = $state(0);
78
+
79
+ onMount(() => {
80
+ void panel.start();
81
+ });
82
+
83
+ onDestroy(() => {
84
+ panel.destroy();
85
+ });
86
+
87
+ /** True while the panel is sending a file or removing a document: nothing else can be started meanwhile. */
88
+ const isBusy = $derived($panel.sending !== null || $panel.removing.length > 0);
89
+
90
+ // The problems, as the list the panel holds: the very same list until the panel puts new ones in its place, so what follows
91
+ // runs for new problems and not at every change of the panel (a look at the list every few seconds, for one).
92
+ const notices = $derived($panel.notices);
93
+
94
+ // New problems are brought into view, if the list is long enough to have put them out of sight (a document that could not
95
+ // be removed is reported below the list while the person is looking at a button in it).
96
+ $effect(() => {
97
+ if (notices.length > 0) noticesElement?.scrollIntoView?.({ block: 'nearest' });
98
+ });
99
+
100
+ /** True when the knowledge base cannot take one more document. */
101
+ const isFull = $derived(
102
+ $panel.totals !== null &&
103
+ $panel.totals.maxDocuments !== null &&
104
+ $panel.documents.length >= $panel.totals.maxDocuments
105
+ );
106
+
107
+ const canAdd = $derived($panel.phase === 'ready' && !isBusy && !isFull);
108
+
109
+ /** A number the way the page's language writes it ("12,000" or "12 000"). */
110
+ function formatNumber(value: number): string {
111
+ try {
112
+ return new Intl.NumberFormat($locale).format(value);
113
+ } catch (error) {
114
+ // A language tag the browser does not know: write the number plainly rather than show nothing.
115
+ console.warn(
116
+ '[KnowledgeDocuments] The number could not be written in the language of the page:',
117
+ error
118
+ );
119
+ return String(value);
120
+ }
121
+ }
122
+
123
+ /** A message as a sentence: what the API itself said when the editor has no words for it, else the catalog's. */
124
+ function sentenceOf(message: PanelMessage): string {
125
+ return message.verbatim ?? $t(message.messageKey, message.messageValues);
126
+ }
127
+
128
+ function openFileChooser(): void {
129
+ if (!canAdd) return;
130
+ fileChooser?.click();
131
+ }
132
+
133
+ function handleFilesChosen(event: Event): void {
134
+ const chooser = event.currentTarget as HTMLInputElement;
135
+ const files = Array.from(chooser.files ?? []);
136
+ // Cleared, so choosing the same file again (after fixing it, say) is heard as a change.
137
+ chooser.value = '';
138
+ if (files.length > 0) void panel.addFiles(files);
139
+ }
140
+
141
+ function openPasteForm(): void {
142
+ if (!canAdd) return;
143
+ panel.dismissNotices();
144
+ pasteFormOpen = true;
145
+ }
146
+
147
+ function closePasteForm(): void {
148
+ pasteFormOpen = false;
149
+ // The form is gone, and with it the focus: it goes back to the button that opened the form.
150
+ pasteButton?.focus();
151
+ }
152
+
153
+ // --- dropping files on the panel -------------------------------------------------------------------
154
+
155
+ /** True for a drag that carries files (not a piece of text or a link dragged from the page). */
156
+ function carriesFiles(event: DragEvent): boolean {
157
+ return Array.from(event.dataTransfer?.types ?? []).includes('Files');
158
+ }
159
+
160
+ function handleDragEnter(event: DragEvent): void {
161
+ if (!canAdd || !carriesFiles(event)) return;
162
+ event.preventDefault();
163
+ draggingFilesDepth += 1;
164
+ }
165
+
166
+ function handleDragOver(event: DragEvent): void {
167
+ if (!canAdd || !carriesFiles(event)) return;
168
+ // Without this the browser would not allow a drop here.
169
+ event.preventDefault();
170
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
171
+ }
172
+
173
+ function handleDragLeave(event: DragEvent): void {
174
+ if (!carriesFiles(event)) return;
175
+ draggingFilesDepth = Math.max(0, draggingFilesDepth - 1);
176
+ }
177
+
178
+ function handleDrop(event: DragEvent): void {
179
+ if (!carriesFiles(event)) return;
180
+ // Always taken in: a file dropped on the page itself would make the browser open it and leave the editor.
181
+ event.preventDefault();
182
+ draggingFilesDepth = 0;
183
+ if (!canAdd) return;
184
+ const files = Array.from(event.dataTransfer?.files ?? []);
185
+ if (files.length > 0) void panel.addFiles(files);
186
+ }
187
+ </script>
188
+
189
+ <!--
190
+ The drag handlers are a convenience on top of the "Add files" button, which does the same for the keyboard and for a screen
191
+ reader, so the panel itself is not made a control.
192
+ -->
193
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
194
+ <div
195
+ class="flex w-full flex-col gap-3 rounded-xl {draggingFilesDepth > 0
196
+ ? 'outline-2 outline-dashed outline-brand outline-offset-4'
197
+ : ''}"
198
+ data-knowledge-documents
199
+ onfocusin={() => onFocus()}
200
+ ondragenter={handleDragEnter}
201
+ ondragover={handleDragOver}
202
+ ondragleave={handleDragLeave}
203
+ ondrop={handleDrop}
204
+ >
205
+ {#if $panel.phase === 'unavailable'}
206
+ <p class="text-body text-muted-foreground">{$t('editor.knowledge.unavailable')}</p>
207
+ {:else if $panel.phase === 'loading'}
208
+ <p class="text-body flex items-center gap-2 text-muted-foreground" role="status">
209
+ <IconLoader2 class="size-4 shrink-0 animate-spin stroke-[1.333]" aria-hidden="true" />
210
+ <span>{$t('editor.knowledge.loading')}</span>
211
+ </p>
212
+ {:else if $panel.phase === 'failed'}
213
+ <div
214
+ class="flex flex-col items-start gap-2 rounded-xl border border-destructive/30 bg-destructive/5 p-3"
215
+ role="alert"
216
+ >
217
+ <p class="text-body flex gap-2 text-destructive">
218
+ <IconAlertTriangle class="mt-0.5 size-4 shrink-0 stroke-[1.333]" aria-hidden="true" />
219
+ <span
220
+ >{$panel.loadFailure
221
+ ? sentenceOf($panel.loadFailure)
222
+ : $t('editor.knowledgeError.generic')}</span
223
+ >
224
+ </p>
225
+ <Button variant="outline" size="sm" onclick={() => void panel.retry()}>
226
+ {$t('editor.knowledge.retry')}
227
+ </Button>
228
+ </div>
229
+ {:else}
230
+ {#if $panel.documents.length === 0}
231
+ <p class="text-body text-muted-foreground">{$t('editor.knowledge.empty')}</p>
232
+ {:else}
233
+ <ul class="flex flex-col gap-2" aria-label={$t('editor.knowledge.listLabel')}>
234
+ {#each $panel.documents as document (document.id)}
235
+ <li
236
+ class="flex min-h-12 items-center gap-3 rounded-xl border border-border bg-accent py-2 ps-4 pe-2"
237
+ >
238
+ <IconFileText
239
+ class="size-4 shrink-0 stroke-[1.333] text-muted-foreground"
240
+ aria-hidden="true"
241
+ />
242
+ <div class="min-w-0 flex-1">
243
+ <p
244
+ class="text-body-medium truncate text-foreground"
245
+ dir={dirForUserText($textDirection)}
246
+ >
247
+ {document.title}
248
+ </p>
249
+ <p class="text-caption text-muted-foreground">
250
+ {#if document.status === 'ready'}
251
+ {$t('editor.knowledge.characters', { count: document.charCount })}
252
+ {:else}
253
+ {$t('editor.knowledge.processing')}
254
+ {/if}
255
+ </p>
256
+ </div>
257
+
258
+ {#if $panel.removing.includes(document.id)}
259
+ <span class="text-caption px-2 text-muted-foreground" role="status">
260
+ {$t('editor.knowledge.removing')}
261
+ </span>
262
+ {:else if $panel.confirmingRemoval === document.id}
263
+ <div class="flex shrink-0 items-center gap-1">
264
+ <Button
265
+ variant="ghost"
266
+ size="sm"
267
+ class="text-destructive hover:text-destructive"
268
+ aria-label={$t('editor.knowledge.removeLabel', { title: document.title })}
269
+ onclick={() => void panel.confirmRemoval(document.id)}
270
+ >
271
+ {$t('editor.knowledge.removeConfirm')}
272
+ </Button>
273
+ <Button variant="ghost" size="sm" onclick={() => panel.cancelRemoval()}>
274
+ {$t('editor.knowledge.keep')}
275
+ </Button>
276
+ </div>
277
+ {:else}
278
+ <IconButton
279
+ variant="ghost"
280
+ size="sm"
281
+ class="shrink-0 text-muted-foreground hover:text-destructive"
282
+ label={$t('editor.knowledge.removeLabel', { title: document.title })}
283
+ disabled={isBusy}
284
+ onclick={() => panel.askToRemove(document.id)}
285
+ >
286
+ <IconTrash class="size-4 stroke-[1.333]" aria-hidden="true" />
287
+ </IconButton>
288
+ {/if}
289
+ </li>
290
+ {/each}
291
+ </ul>
292
+ {/if}
293
+
294
+ {#if $panel.sending}
295
+ <p class="text-body flex items-center gap-2 text-foreground" role="status">
296
+ <IconLoader2 class="size-4 shrink-0 animate-spin stroke-[1.333]" aria-hidden="true" />
297
+ <span class="truncate" dir={dirForUserText($textDirection)}>
298
+ {#if $panel.sending.count > 1}
299
+ {$t('editor.knowledge.sendingOf', {
300
+ name: $panel.sending.name,
301
+ position: $panel.sending.position,
302
+ count: $panel.sending.count
303
+ })}
304
+ {:else}
305
+ {$t('editor.knowledge.sending', { name: $panel.sending.name })}
306
+ {/if}
307
+ </span>
308
+ </p>
309
+ {/if}
310
+
311
+ <!-- Below the list, next to the buttons that were pressed: at the top of a long list it would be out of sight. -->
312
+ {#if $panel.notices.length > 0}
313
+ <div
314
+ bind:this={noticesElement}
315
+ class="flex flex-col gap-2 rounded-xl border border-destructive/30 bg-destructive/5 px-3 py-2"
316
+ role="alert"
317
+ >
318
+ {#each $panel.notices as notice (notice.id)}
319
+ <p class="text-body flex gap-2 text-destructive">
320
+ <IconAlertTriangle class="mt-0.5 size-4 shrink-0 stroke-[1.333]" aria-hidden="true" />
321
+ <span>{sentenceOf(notice.message)}</span>
322
+ </p>
323
+ {/each}
324
+ <Button variant="ghost" size="sm" class="self-end" onclick={() => panel.dismissNotices()}>
325
+ {$t('editor.knowledge.dismiss')}
326
+ </Button>
327
+ </div>
328
+ {/if}
329
+
330
+ {#if isFull}
331
+ <p class="text-body text-muted-foreground">{$t('editor.knowledgeError.limitDocuments')}</p>
332
+ {/if}
333
+
334
+ <div class="flex flex-col gap-2">
335
+ <div class="flex items-center gap-2">
336
+ <Button
337
+ variant="outline"
338
+ class="group h-9 min-w-0 flex-1 gap-2 press-feedback"
339
+ disabled={!canAdd}
340
+ onclick={openFileChooser}
341
+ >
342
+ <IconPlus
343
+ class="size-4 shrink-0 stroke-[1.333] text-muted-foreground"
344
+ aria-hidden="true"
345
+ />
346
+ <span class="text-body-medium truncate text-foreground group-hover:underline">
347
+ {$t('editor.knowledge.addFiles')}
348
+ </span>
349
+ </Button>
350
+ <Button
351
+ bind:ref={pasteButton}
352
+ variant="outline"
353
+ class="h-9 shrink-0 press-feedback"
354
+ disabled={!canAdd}
355
+ aria-expanded={pasteFormOpen}
356
+ onclick={openPasteForm}
357
+ >
358
+ <span class="text-body-medium text-foreground">{$t('editor.knowledge.addText')}</span>
359
+ </Button>
360
+ </div>
361
+ <p class="text-caption text-muted-foreground">{$t('editor.knowledge.dropHint')}</p>
362
+ </div>
363
+
364
+ <!-- Hidden: the "Add files" button opens it, and the keyboard reaches that button. -->
365
+ <input
366
+ bind:this={fileChooser}
367
+ type="file"
368
+ multiple
369
+ accept={KNOWLEDGE_FILE_ACCEPT}
370
+ class="hidden"
371
+ tabindex="-1"
372
+ aria-hidden="true"
373
+ onchange={handleFilesChosen}
374
+ />
375
+
376
+ {#if pasteFormOpen}
377
+ <KnowledgeTextForm
378
+ busy={isBusy}
379
+ onAdd={(input) => panel.addText(input)}
380
+ onClose={closePasteForm}
381
+ />
382
+ {/if}
383
+
384
+ {#if $panel.totals && $panel.totals.maxDocuments !== null && $panel.totals.maxTotalChars !== null}
385
+ <p class="text-caption flex flex-wrap gap-x-4 text-muted-foreground">
386
+ <span>
387
+ {$t('editor.knowledge.documentsUsed', {
388
+ documents: formatNumber($panel.totals.documents),
389
+ maxDocuments: formatNumber($panel.totals.maxDocuments)
390
+ })}
391
+ </span>
392
+ <span>
393
+ {$t('editor.knowledge.textUsed', {
394
+ characters: formatNumber($panel.totals.characters),
395
+ maxCharacters: formatNumber($panel.totals.maxTotalChars)
396
+ })}
397
+ </span>
398
+ </p>
399
+ {/if}
400
+ {/if}
401
+ </div>
@@ -0,0 +1,11 @@
1
+ import type { KnowledgeDocumentsPanel as KnowledgeDocumentsPanelType } from '../../composition/knowledgeDocumentsPanel';
2
+ /** Declared props contract: what the settings editor hands to every control that is drawn from a schema. */
3
+ export interface KnowledgeDocumentsInputControllerProps {
4
+ /** Called when something inside the panel takes the focus, like every control's `onFocus`. */
5
+ onFocus?: () => void;
6
+ /** A panel made elsewhere (a test hands one in). Without it the control makes its own from the editor's client. */
7
+ panel?: KnowledgeDocumentsPanelType;
8
+ }
9
+ declare const KnowledgeDocumentsInputController: import("svelte").Component<KnowledgeDocumentsInputControllerProps, {}, "">;
10
+ type KnowledgeDocumentsInputController = ReturnType<typeof KnowledgeDocumentsInputController>;
11
+ export default KnowledgeDocumentsInputController;
@@ -0,0 +1,109 @@
1
+ <!--
2
+ * KnowledgeTextForm
3
+ *
4
+ * The form of the Documents panel (AI Answers) that adds a document made of text a person typed or pasted: a title and the
5
+ * text. It is on the screen only while the person is writing; closing it, by cancelling or by adding the document, throws
6
+ * away what was written, and a document the API refuses keeps the form open with everything in it so it can be fixed.
7
+ *
8
+ * The form sends nothing itself: it hands the title and the text to `onAdd` (the panel's `addText`), which answers `true`
9
+ * when the document was added. What the panel says about a refusal is on the screen in the panel, below its list, not here.
10
+ -->
11
+
12
+ <script module lang="ts">
13
+ /** Declared props contract of the form. */
14
+ export interface KnowledgeTextFormProps {
15
+ /** True while the panel is sending or removing something: nothing can be added meanwhile. */
16
+ busy?: boolean;
17
+ /** Adds the document. Resolves `true` when it was added (the form then closes) and `false` when it was not. */
18
+ onAdd: (input: { title: string; text: string }) => Promise<boolean>;
19
+ /** Takes the form off the screen: the person cancelled, or the document was added. */
20
+ onClose: () => void;
21
+ }
22
+ </script>
23
+
24
+ <script lang="ts">
25
+ import { onMount } from 'svelte';
26
+ import { Button, Input, Textarea } from '@widgetic/design-system/components';
27
+ import {
28
+ dirForUserText,
29
+ useTextDirection
30
+ } from '@widgetic/design-system/components/textDirection';
31
+ import { useEditorLanguage } from '../../i18n/language';
32
+ import { KNOWLEDGE_TITLE_MAX_LENGTH } from '../../composition/knowledgeDocuments';
33
+
34
+ let { busy = false, onAdd, onClose }: KnowledgeTextFormProps = $props();
35
+
36
+ // The words of the editor in the language of the page, and the way the screen is read (what a person typed is read by its
37
+ // own first letter on a right to left screen).
38
+ const { t } = useEditorLanguage();
39
+ const textDirection = useTextDirection();
40
+
41
+ // Ids that stay unique when the panel is on the screen twice.
42
+ const uniqueId = $props.id();
43
+ const titleFieldId = `${uniqueId}-title`;
44
+ const textFieldId = `${uniqueId}-text`;
45
+
46
+ let titleField: HTMLInputElement | null = $state(null);
47
+ let title = $state('');
48
+ let text = $state('');
49
+
50
+ /** Both boxes need words, and nothing else may be going on: the same two things the panel would turn the person back for. */
51
+ const canAdd = $derived(!busy && title.trim() !== '' && text.trim() !== '');
52
+
53
+ // The form was opened by a button: the person goes on typing where the form begins, without searching for it.
54
+ onMount(() => {
55
+ titleField?.focus();
56
+ });
57
+
58
+ async function handleSubmit(event: SubmitEvent): Promise<void> {
59
+ event.preventDefault();
60
+ if (!canAdd) return;
61
+ try {
62
+ const wasAdded = await onAdd({ title, text });
63
+ if (wasAdded) onClose();
64
+ } catch (error) {
65
+ // The panel answers `false` for what it could not do; this is something it did not expect. The form stays as it is.
66
+ console.warn('[KnowledgeDocuments] The text could not be added:', error);
67
+ }
68
+ }
69
+ </script>
70
+
71
+ <form
72
+ class="flex flex-col gap-3 rounded-xl border border-border bg-accent p-3"
73
+ onsubmit={handleSubmit}
74
+ >
75
+ <label class="text-label-small text-muted-foreground" for={titleFieldId}>
76
+ {$t('editor.knowledge.titleLabel')}
77
+ </label>
78
+ <Input
79
+ id={titleFieldId}
80
+ bind:ref={titleField}
81
+ bind:value={title}
82
+ maxlength={KNOWLEDGE_TITLE_MAX_LENGTH}
83
+ autocomplete="off"
84
+ placeholder={$t('editor.knowledge.titlePlaceholder')}
85
+ dir={title ? dirForUserText($textDirection) : undefined}
86
+ disabled={busy}
87
+ class="h-9"
88
+ />
89
+ <label class="text-label-small text-muted-foreground" for={textFieldId}>
90
+ {$t('editor.knowledge.textLabel')}
91
+ </label>
92
+ <Textarea
93
+ id={textFieldId}
94
+ bind:value={text}
95
+ rows={6}
96
+ placeholder={$t('editor.knowledge.textPlaceholder')}
97
+ dir={text ? dirForUserText($textDirection) : undefined}
98
+ disabled={busy}
99
+ class="min-h-[9rem] resize-y"
100
+ />
101
+ <div class="flex justify-end gap-2">
102
+ <Button type="button" variant="ghost" size="sm" onclick={onClose}>
103
+ {$t('editor.knowledge.cancel')}
104
+ </Button>
105
+ <Button type="submit" size="sm" disabled={!canAdd}>
106
+ {$t('editor.knowledge.addDocument')}
107
+ </Button>
108
+ </div>
109
+ </form>
@@ -0,0 +1,15 @@
1
+ /** Declared props contract of the form. */
2
+ export interface KnowledgeTextFormProps {
3
+ /** True while the panel is sending or removing something: nothing can be added meanwhile. */
4
+ busy?: boolean;
5
+ /** Adds the document. Resolves `true` when it was added (the form then closes) and `false` when it was not. */
6
+ onAdd: (input: {
7
+ title: string;
8
+ text: string;
9
+ }) => Promise<boolean>;
10
+ /** Takes the form off the screen: the person cancelled, or the document was added. */
11
+ onClose: () => void;
12
+ }
13
+ declare const KnowledgeTextForm: import("svelte").Component<KnowledgeTextFormProps, {}, "">;
14
+ type KnowledgeTextForm = ReturnType<typeof KnowledgeTextForm>;
15
+ export default KnowledgeTextForm;