@widgetic/editor 4.1.12 → 4.1.14

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.
@@ -46,6 +46,8 @@
46
46
  import { shareTextDirection, type TextDirection } from '@widgetic/design-system/components/textDirection';
47
47
  import { leftOnThisScreen } from '../../utils/dockPlacement';
48
48
  import { provideEditorLanguage } from '../../i18n/language.js';
49
+ import { provideEditorKnowledgeDocuments } from '../../knowledgeDocumentsContext.js';
50
+ import { createKnowledgeDocumentsClient } from '../../composition/knowledgeDocuments.js';
49
51
  import type { PartnerPickFileFn } from '../../pickFileContext.js';
50
52
  import type { StoreFileUrlFn } from '../../fileStorageUrlContext.js';
51
53
  import PropsEditor from './PropsEditor.svelte';
@@ -177,6 +179,12 @@
177
179
  apiBasePath,
178
180
  getAccessToken: (reason, refusedToken) => getAccessToken(reason, refusedToken)
179
181
  });
182
+
183
+ // The Documents panel of AI Answers sits deep inside the settings editor and is drawn from a schema, so the calls that list,
184
+ // add and remove the documents of THIS composition reach it through a context instead of through props. They go through the
185
+ // same client as the saves, so they ask for a new token the same way when one is refused.
186
+ const knowledgeDocuments = createKnowledgeDocumentsClient(api, compositionId);
187
+ provideEditorKnowledgeDocuments(() => knowledgeDocuments);
180
188
  const controller = new CompositionEditorController({
181
189
  compositionId,
182
190
  api,
@@ -68,6 +68,7 @@
68
68
  TimeInputController,
69
69
  RoundedCornersInputController,
70
70
  TagsInputController,
71
+ KnowledgeDocumentsInputController,
71
72
  DateFieldInputController
72
73
  } from '../ic';
73
74
  import type { InputControllerConfig } from '../ic';
@@ -1094,6 +1095,7 @@
1094
1095
  case 'time': return TimeInputController;
1095
1096
  case 'roundedcorners': return RoundedCornersInputController;
1096
1097
  case 'tags': return TagsInputController;
1098
+ case 'knowledgedocuments': return KnowledgeDocumentsInputController;
1097
1099
  default: return TextInputController;
1098
1100
  }
1099
1101
  }
@@ -1194,6 +1196,9 @@
1194
1196
  case TagsInputController: return { kind: 'tags', props: {
1195
1197
  label: props.label, value: props.value, onChange: props.onChange, config: props.config,
1196
1198
  helpText: props.helpText, onFocus: props.onFocus } };
1199
+ // The documents of AI Answers hold no value of the widget: the panel takes nothing but the focus hook.
1200
+ case KnowledgeDocumentsInputController: return { kind: 'knowledgedocuments', props: {
1201
+ onFocus: props.onFocus } };
1197
1202
  default: return null;
1198
1203
  }
1199
1204
  }
@@ -2300,7 +2305,9 @@
2300
2305
 
2301
2306
  {#if isVisible}
2302
2307
  {@const isFontIc = property.inputController.type.toLowerCase() === 'font'}
2303
- <div class="ictrl input-controller flex {isFontIc ? 'font-ic-host flex-col items-stretch' : 'items-center justify-between'} w-full p-0 browser-input-wrapper"
2308
+ <!-- A panel (the documents of AI Answers) is a list and a form: it gets the whole width under its header. -->
2309
+ {@const isPanelIc = property.inputController.type.toLowerCase() === 'knowledgedocuments'}
2310
+ <div class="ictrl input-controller flex {isFontIc ? 'font-ic-host flex-col items-stretch' : isPanelIc ? 'panel-ic-host flex-col items-stretch gap-1' : 'items-center justify-between'} w-full p-0 browser-input-wrapper"
2304
2311
  class:double-height={isFontIc}
2305
2312
  >
2306
2313
  {#if !isFontIc && InputComponent !== BrowserInputController}
@@ -2317,7 +2324,7 @@
2317
2324
  </div>
2318
2325
  {/if}
2319
2326
 
2320
- <div class="ic-input-ct {isFontIc ? 'w-full' : 'shrink-0'}" style={isFontIc ? '' : 'width: 185px;'}>
2327
+ <div class="ic-input-ct {isFontIc || isPanelIc ? 'w-full' : 'shrink-0'}" style={isFontIc || isPanelIc ? '' : 'width: 185px;'}>
2321
2328
  <InputControllerRenderer
2322
2329
  controller={describeInputController(InputComponent, { ...props, header })}
2323
2330
  />
@@ -2398,7 +2405,8 @@
2398
2405
 
2399
2406
  {#if isVisible && InputComponent}
2400
2407
  {@const isFontIc = (property.inputController?.type || '').toLowerCase() === 'font'}
2401
- <div class="ictrl input-controller flex {isFontIc ? 'font-ic-host flex-col items-stretch' : 'items-center justify-between'} w-full p-0 browser-input-wrapper"
2408
+ {@const isPanelIc = (property.inputController?.type || '').toLowerCase() === 'knowledgedocuments'}
2409
+ <div class="ictrl input-controller flex {isFontIc ? 'font-ic-host flex-col items-stretch' : isPanelIc ? 'panel-ic-host flex-col items-stretch gap-1' : 'items-center justify-between'} w-full p-0 browser-input-wrapper"
2402
2410
  class:double-height={isFontIc}
2403
2411
  >
2404
2412
  {#if !isFontIc && InputComponent !== BrowserInputController}
@@ -2415,7 +2423,7 @@
2415
2423
  </div>
2416
2424
  {/if}
2417
2425
 
2418
- <div class="ic-input-ct {isFontIc ? 'w-full' : 'shrink-0'}" style={isFontIc ? '' : 'width: 185px;'}>
2426
+ <div class="ic-input-ct {isFontIc || isPanelIc ? 'w-full' : 'shrink-0'}" style={isFontIc || isPanelIc ? '' : 'width: 185px;'}>
2419
2427
  <InputControllerRenderer
2420
2428
  controller={describeInputController(InputComponent, { ...props, header })}
2421
2429
  />
@@ -3048,15 +3056,20 @@
3048
3056
 
3049
3057
  /* FontIC is two stacked 185px rows with its own labels. Do not squeeze
3050
3058
  the whole controller into the single 185px color column (that hid labels). */
3051
- :global(.input-controller.font-ic-host) {
3059
+ :global(.input-controller.font-ic-host),
3060
+ :global(.input-controller.panel-ic-host) {
3052
3061
  display: flex !important;
3053
3062
  flex-direction: column !important;
3054
3063
  align-items: stretch !important;
3055
3064
  justify-content: flex-start !important;
3056
3065
  }
3057
3066
 
3067
+ /* A panel (the documents of AI Answers) is a list and a form, not one control: its header, then the panel itself,
3068
+ both over the whole width. Unlike FontIC it grows with what is in it. */
3058
3069
  :global(.input-controller.font-ic-host > div:first-child),
3059
- :global(.input-controller.font-ic-host > div:last-child) {
3070
+ :global(.input-controller.font-ic-host > div:last-child),
3071
+ :global(.input-controller.panel-ic-host > div:first-child),
3072
+ :global(.input-controller.panel-ic-host > div:last-child) {
3060
3073
  width: 100% !important;
3061
3074
  max-width: 100% !important;
3062
3075
  flex: none !important;
@@ -800,6 +800,12 @@
800
800
  */
801
801
  function handleFontSelect(font: FontItem | RecentFont) {
802
802
  if (onChange) {
803
+ // The family has to reach the card even when the weight catalog fails.
804
+ onChange({
805
+ family: font.family,
806
+ weight: 'Regular',
807
+ category: font.category
808
+ });
803
809
  // Reset weight to Regular or first available weight
804
810
  fetchFontWeights(font.family).then(async () => {
805
811
  const newWeight = availableWeights.includes('Regular') ?
@@ -828,6 +834,8 @@
828
834
  // console.log('✅ [FontInput] Font selected:', {
829
835
  // font: fontValue
830
836
  // });
837
+ }).catch((error) => {
838
+ console.error('[FontInput] Weight lookup failed after the family was applied:', error);
831
839
  });
832
840
  }
833
841
  }
@@ -1414,6 +1422,15 @@
1414
1422
  * Fetches and processes font weights from Google Fonts API
1415
1423
  * or from fonts.json for custom fonts
1416
1424
  */
1425
+ function keepWeightIfListed() {
1426
+ const currentName = selectedWeight.startsWith(`${controllerId}-`)
1427
+ ? selectedWeight.slice(controllerId.length + 1)
1428
+ : '';
1429
+ if (!availableWeights.includes(currentName)) {
1430
+ selectedWeight = `${controllerId}-${availableWeights.includes('Regular') ? 'Regular' : availableWeights[0]}`;
1431
+ }
1432
+ }
1433
+
1417
1434
  async function fetchFontWeights(fontFamily: string) {
1418
1435
  try {
1419
1436
  // Wait for FontManager init — reactive weight fetch can race ahead of onMount.
@@ -1480,12 +1497,12 @@
1480
1497
  fontCatalogFallbackWarned = true;
1481
1498
  console.warn('[FontInput] Using default weights (Google catalog not loaded). Later fonts will use the same fallback silently.');
1482
1499
  }
1483
- availableWeights = ['Regular', 'Bold'];
1484
- selectedWeight = `${controllerId}-Regular`;
1500
+ availableWeights = ['Regular', 'Italic', 'Bold', 'Bold Italic'];
1501
+ keepWeightIfListed();
1485
1502
  } catch (error) {
1486
1503
  console.error('Error fetching font weights:', error);
1487
- availableWeights = ['Regular'];
1488
- selectedWeight = `${controllerId}-Regular`;
1504
+ availableWeights = ['Regular', 'Italic', 'Bold', 'Bold Italic'];
1505
+ keepWeightIfListed();
1489
1506
  }
1490
1507
  }
1491
1508
 
@@ -1814,8 +1831,10 @@
1814
1831
  collisionPadding={12}
1815
1832
  side={familyPopoverSide}
1816
1833
  sideOffset={4}
1834
+ tabindex={-1}
1835
+ onOpenAutoFocus={(event) => event.preventDefault()}
1817
1836
  portalProps={{ to: fontPickerPortalHost }}
1818
- class="font-input-popover !p-0 widgetic-colors widgetic-radius rounded-medium modal-shadow border border-grey2"
1837
+ class="font-input-popover !p-0 widgetic-colors widgetic-radius rounded-medium modal-shadow border border-grey2 outline-none"
1819
1838
  style={familyPopoverStyle}
1820
1839
  >
1821
1840
  <div class="flex flex-col h-full min-h-0 font-popover-content">
@@ -2020,15 +2039,21 @@
2020
2039
  </span>
2021
2040
  <IconCaretDownFilled class="w-5 h-5 shrink-0 text-grey5 group-hover:text-grey7" />
2022
2041
  </Popover.Trigger>
2023
- <Popover.Content class="font-input-popover p-0 w-[150px]" portalProps={{ to: fontPickerPortalHost }}>
2042
+ <Popover.Content
2043
+ class="font-input-popover p-0 w-[150px] outline-none"
2044
+ tabindex={-1}
2045
+ onOpenAutoFocus={(event) => event.preventDefault()}
2046
+ portalProps={{ to: fontPickerPortalHost }}
2047
+ >
2024
2048
  <Command.Root>
2025
2049
  <Command.List aria-label={$t('editor.font.weightList')}>
2026
2050
  <Command.Group>
2027
2051
  {#each availableWeights as weight}
2028
2052
  <Command.Item
2029
2053
  value={weight}
2054
+ tabindex={-1}
2030
2055
  onSelect={() => handleWeightSelect(weight)}
2031
- class="px-2 py-2"
2056
+ class="px-2 py-2 outline-none"
2032
2057
  >
2033
2058
  <Check
2034
2059
  class="me-1 h-4 w-4 {displayWeight === weight ? 'opacity-100' : 'opacity-0'}"
@@ -2119,14 +2144,12 @@
2119
2144
  .font-family-input-ct :global(button:focus-visible),
2120
2145
  .font-weight-input-ct :global(button:focus),
2121
2146
  .font-weight-input-ct :global(button:focus-visible),
2122
- :global(.font-input-popover button:focus),
2123
- :global(.font-input-popover button:focus-visible),
2124
- :global(.font-list-row:focus),
2125
- :global(.font-list-row:focus-visible),
2126
- :global(.font-input-popover [data-item]:focus),
2127
- :global(.font-input-popover [data-item]:focus-visible) {
2128
- outline: none;
2129
- box-shadow: none;
2147
+ :global(.font-input-popover:focus),
2148
+ :global(.font-input-popover:focus-visible),
2149
+ :global(.font-input-popover *:focus),
2150
+ :global(.font-input-popover *:focus-visible) {
2151
+ outline: none !important;
2152
+ outline-offset: 0 !important;
2130
2153
  }
2131
2154
 
2132
2155
  /* Clamp to the viewport so the Fonts header and list stay on screen */
@@ -7,7 +7,8 @@
7
7
  SwitchInputController, ColorPickerInputController, CheckboxInputController,
8
8
  RadioGroupInputController, FontInputController, PositionInputController,
9
9
  BrowserInputController, FixedPositionInputController, VectorInputController,
10
- AngleInputController, TimeInputController, RoundedCornersInputController, TagsInputController
10
+ AngleInputController, TimeInputController, RoundedCornersInputController, TagsInputController,
11
+ KnowledgeDocumentsInputController
11
12
  } from './index';
12
13
 
13
14
  type ControllerComponents = {
@@ -33,6 +34,7 @@
33
34
  time: typeof TimeInputController;
34
35
  roundedcorners: typeof RoundedCornersInputController;
35
36
  tags: typeof TagsInputController;
37
+ knowledgedocuments: typeof KnowledgeDocumentsInputController;
36
38
  };
37
39
 
38
40
  // Each branch preserves the relationship between a controller and its props.
@@ -94,5 +96,7 @@
94
96
  <RoundedCornersInputController {...controller.props} />
95
97
  {:else if controller?.kind === 'tags'}
96
98
  <TagsInputController {...controller.props} />
99
+ {:else if controller?.kind === 'knowledgedocuments'}
100
+ <KnowledgeDocumentsInputController {...controller.props} />
97
101
  {/if}
98
102
  </div>
@@ -1,5 +1,5 @@
1
1
  import type { ComponentProps } from 'svelte';
2
- import { TextInputController, TextAreaPreviewInputController, NumberInputController, SliderInputController, SliderRangeInputController, DropdownInputController, DatePickerInputController, DateFieldInputController, RangeCalendarInputController, SwitchInputController, ColorPickerInputController, CheckboxInputController, RadioGroupInputController, FontInputController, PositionInputController, BrowserInputController, FixedPositionInputController, VectorInputController, AngleInputController, TimeInputController, RoundedCornersInputController, TagsInputController } from './index';
2
+ import { TextInputController, TextAreaPreviewInputController, NumberInputController, SliderInputController, SliderRangeInputController, DropdownInputController, DatePickerInputController, DateFieldInputController, RangeCalendarInputController, SwitchInputController, ColorPickerInputController, CheckboxInputController, RadioGroupInputController, FontInputController, PositionInputController, BrowserInputController, FixedPositionInputController, VectorInputController, AngleInputController, TimeInputController, RoundedCornersInputController, TagsInputController, KnowledgeDocumentsInputController } from './index';
3
3
  type ControllerComponents = {
4
4
  textinput: typeof TextInputController;
5
5
  textarea: typeof TextAreaPreviewInputController;
@@ -23,6 +23,7 @@ type ControllerComponents = {
23
23
  time: typeof TimeInputController;
24
24
  roundedcorners: typeof RoundedCornersInputController;
25
25
  tags: typeof TagsInputController;
26
+ knowledgedocuments: typeof KnowledgeDocumentsInputController;
26
27
  };
27
28
  export type ControllerDescriptor = {
28
29
  [Kind in keyof ControllerComponents]: {
@@ -0,0 +1,364 @@
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 } from '@widgetic/design-system/components';
35
+ import { FileText, LoaderCircle, Trash2, TriangleAlert } from '@widgetic/design-system/icons';
36
+ import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
37
+ import AddNew from '../icons/addnew.svelte';
38
+ import KnowledgeTextForm from './KnowledgeTextForm.svelte';
39
+ import { useEditorLanguage } from '../../i18n/language';
40
+ import { useEditorKnowledgeDocuments } from '../../knowledgeDocumentsContext';
41
+ import {
42
+ KnowledgeDocumentsPanel,
43
+ type PanelMessage
44
+ } from '../../composition/knowledgeDocumentsPanel';
45
+ import { KNOWLEDGE_FILE_ACCEPT } from '../../composition/knowledgeDocuments';
46
+
47
+ let { onFocus = () => {}, panel: suppliedPanel = undefined }: KnowledgeDocumentsInputControllerProps =
48
+ $props();
49
+
50
+ // 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
51
+ // typed, so on a right to left screen it is read by its own first letter).
52
+ const { t, locale } = useEditorLanguage();
53
+ const textDirection = useTextDirection();
54
+
55
+ // The calls for the composition being edited. `undefined` outside a composition editor: the panel then says so.
56
+ const getKnowledgeClient = useEditorKnowledgeDocuments();
57
+
58
+ // The panel is made once, when this control is made, from the client of that moment: a control belongs to one composition.
59
+ // svelte-ignore state_referenced_locally
60
+ const panel = suppliedPanel ?? new KnowledgeDocumentsPanel({ client: getKnowledgeClient() });
61
+
62
+ let fileChooser: HTMLInputElement | undefined = $state();
63
+ let pasteButton: HTMLButtonElement | null = $state(null);
64
+ let noticesElement: HTMLElement | undefined = $state();
65
+ let pasteFormOpen = $state(false);
66
+ // How many drag events of files have entered the panel and not left it yet (enter and leave fire for every child).
67
+ let draggingFilesDepth = $state(0);
68
+
69
+ onMount(() => {
70
+ void panel.start();
71
+ });
72
+
73
+ onDestroy(() => {
74
+ panel.destroy();
75
+ });
76
+
77
+ /** True while the panel is sending a file or removing a document: nothing else can be started meanwhile. */
78
+ const isBusy = $derived($panel.sending !== null || $panel.removing.length > 0);
79
+
80
+ // The problems, as the list the panel holds: the very same list until the panel puts new ones in its place, so what follows
81
+ // runs for new problems and not at every change of the panel (a look at the list every few seconds, for one).
82
+ const notices = $derived($panel.notices);
83
+
84
+ // New problems are brought into view, if the list is long enough to have put them out of sight (a document that could not
85
+ // be removed is reported below the list while the person is looking at a button in it).
86
+ $effect(() => {
87
+ if (notices.length > 0) noticesElement?.scrollIntoView?.({ block: 'nearest' });
88
+ });
89
+
90
+ /** True when the knowledge base cannot take one more document. */
91
+ const isFull = $derived(
92
+ $panel.totals !== null &&
93
+ $panel.totals.maxDocuments !== null &&
94
+ $panel.documents.length >= $panel.totals.maxDocuments
95
+ );
96
+
97
+ const canAdd = $derived($panel.phase === 'ready' && !isBusy && !isFull);
98
+
99
+ /** A number the way the page's language writes it ("12,000" or "12 000"). */
100
+ function formatNumber(value: number): string {
101
+ try {
102
+ return new Intl.NumberFormat($locale).format(value);
103
+ } catch (error) {
104
+ // A language tag the browser does not know: write the number plainly rather than show nothing.
105
+ console.warn('[KnowledgeDocuments] The number could not be written in the language of the page:', error);
106
+ return String(value);
107
+ }
108
+ }
109
+
110
+ /** A message as a sentence: what the API itself said when the editor has no words for it, else the catalog's. */
111
+ function sentenceOf(message: PanelMessage): string {
112
+ return message.verbatim ?? $t(message.messageKey, message.messageValues);
113
+ }
114
+
115
+ function openFileChooser(): void {
116
+ if (!canAdd) return;
117
+ fileChooser?.click();
118
+ }
119
+
120
+ function handleFilesChosen(event: Event): void {
121
+ const chooser = event.currentTarget as HTMLInputElement;
122
+ const files = Array.from(chooser.files ?? []);
123
+ // Cleared, so choosing the same file again (after fixing it, say) is heard as a change.
124
+ chooser.value = '';
125
+ if (files.length > 0) void panel.addFiles(files);
126
+ }
127
+
128
+ function openPasteForm(): void {
129
+ if (!canAdd) return;
130
+ panel.dismissNotices();
131
+ pasteFormOpen = true;
132
+ }
133
+
134
+ function closePasteForm(): void {
135
+ pasteFormOpen = false;
136
+ // The form is gone, and with it the focus: it goes back to the button that opened the form.
137
+ pasteButton?.focus();
138
+ }
139
+
140
+ // --- dropping files on the panel -------------------------------------------------------------------
141
+
142
+ /** True for a drag that carries files (not a piece of text or a link dragged from the page). */
143
+ function carriesFiles(event: DragEvent): boolean {
144
+ return Array.from(event.dataTransfer?.types ?? []).includes('Files');
145
+ }
146
+
147
+ function handleDragEnter(event: DragEvent): void {
148
+ if (!canAdd || !carriesFiles(event)) return;
149
+ event.preventDefault();
150
+ draggingFilesDepth += 1;
151
+ }
152
+
153
+ function handleDragOver(event: DragEvent): void {
154
+ if (!canAdd || !carriesFiles(event)) return;
155
+ // Without this the browser would not allow a drop here.
156
+ event.preventDefault();
157
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
158
+ }
159
+
160
+ function handleDragLeave(event: DragEvent): void {
161
+ if (!carriesFiles(event)) return;
162
+ draggingFilesDepth = Math.max(0, draggingFilesDepth - 1);
163
+ }
164
+
165
+ function handleDrop(event: DragEvent): void {
166
+ if (!carriesFiles(event)) return;
167
+ // Always taken in: a file dropped on the page itself would make the browser open it and leave the editor.
168
+ event.preventDefault();
169
+ draggingFilesDepth = 0;
170
+ if (!canAdd) return;
171
+ const files = Array.from(event.dataTransfer?.files ?? []);
172
+ if (files.length > 0) void panel.addFiles(files);
173
+ }
174
+ </script>
175
+
176
+ <!--
177
+ The drag handlers are a convenience on top of the "Add files" button, which does the same for the keyboard and for a screen
178
+ reader, so the panel itself is not made a control.
179
+ -->
180
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
181
+ <div
182
+ class="widgetic-colors flex w-full flex-col gap-3 rounded-large {draggingFilesDepth > 0
183
+ ? 'outline-2 outline-dashed outline-forest-green outline-offset-4'
184
+ : ''}"
185
+ data-knowledge-documents
186
+ onfocusin={() => onFocus()}
187
+ ondragenter={handleDragEnter}
188
+ ondragover={handleDragOver}
189
+ ondragleave={handleDragLeave}
190
+ ondrop={handleDrop}
191
+ >
192
+ {#if $panel.phase === 'unavailable'}
193
+ <p class="subtext text-grey5">{$t('editor.knowledge.unavailable')}</p>
194
+ {:else if $panel.phase === 'loading'}
195
+ <p class="subtext flex items-center gap-2 text-grey5" role="status">
196
+ <LoaderCircle class="h-4 w-4 shrink-0 animate-spin" aria-hidden="true" />
197
+ <span>{$t('editor.knowledge.loading')}</span>
198
+ </p>
199
+ {:else if $panel.phase === 'failed'}
200
+ <div class="flex flex-col items-start gap-2" role="alert">
201
+ <p class="subtext flex gap-2 text-error">
202
+ <TriangleAlert class="mt-[2px] h-4 w-4 shrink-0" aria-hidden="true" />
203
+ <span>{$panel.loadFailure ? sentenceOf($panel.loadFailure) : $t('editor.knowledgeError.generic')}</span>
204
+ </p>
205
+ <Button variant="outline" size="sm" onclick={() => void panel.retry()}>
206
+ {$t('editor.knowledge.retry')}
207
+ </Button>
208
+ </div>
209
+ {:else}
210
+ {#if $panel.documents.length === 0}
211
+ <p class="subtext text-grey5">{$t('editor.knowledge.empty')}</p>
212
+ {:else}
213
+ <ul class="flex flex-col gap-2" aria-label={$t('editor.knowledge.listLabel')}>
214
+ {#each $panel.documents as document (document.id)}
215
+ <li
216
+ class="flex min-h-[48px] items-center gap-3 rounded-large border border-grey2 bg-grey1 py-2 ps-4 pe-2"
217
+ >
218
+ <FileText class="h-5 w-5 shrink-0 text-grey5" aria-hidden="true" />
219
+ <div class="min-w-0 flex-1">
220
+ <p class="subtext truncate text-grey7" dir={dirForUserText($textDirection)}>
221
+ {document.title}
222
+ </p>
223
+ <p class="caption text-grey5">
224
+ {#if document.status === 'ready'}
225
+ {$t('editor.knowledge.characters', { count: document.charCount })}
226
+ {:else}
227
+ {$t('editor.knowledge.processing')}
228
+ {/if}
229
+ </p>
230
+ </div>
231
+
232
+ {#if $panel.removing.includes(document.id)}
233
+ <span class="caption px-2 text-grey5" role="status">{$t('editor.knowledge.removing')}</span>
234
+ {:else if $panel.confirmingRemoval === document.id}
235
+ <div class="flex shrink-0 items-center gap-1">
236
+ <Button
237
+ variant="ghost"
238
+ size="sm"
239
+ class="text-error hover:text-error-dark"
240
+ aria-label={$t('editor.knowledge.removeLabel', { title: document.title })}
241
+ onclick={() => void panel.confirmRemoval(document.id)}
242
+ >
243
+ {$t('editor.knowledge.removeConfirm')}
244
+ </Button>
245
+ <Button variant="ghost" size="sm" class="text-grey5" onclick={() => panel.cancelRemoval()}>
246
+ {$t('editor.knowledge.keep')}
247
+ </Button>
248
+ </div>
249
+ {:else}
250
+ <Button
251
+ variant="ghost"
252
+ size="icon"
253
+ class="h-8 w-8 shrink-0 text-grey5 hover:text-error"
254
+ aria-label={$t('editor.knowledge.removeLabel', { title: document.title })}
255
+ disabled={isBusy}
256
+ onclick={() => panel.askToRemove(document.id)}
257
+ >
258
+ <Trash2 class="h-4 w-4" aria-hidden="true" />
259
+ </Button>
260
+ {/if}
261
+ </li>
262
+ {/each}
263
+ </ul>
264
+ {/if}
265
+
266
+ {#if $panel.sending}
267
+ <p class="subtext flex items-center gap-2 text-grey7" role="status">
268
+ <LoaderCircle class="h-4 w-4 shrink-0 animate-spin" aria-hidden="true" />
269
+ <span class="truncate" dir={dirForUserText($textDirection)}>
270
+ {#if $panel.sending.count > 1}
271
+ {$t('editor.knowledge.sendingOf', {
272
+ name: $panel.sending.name,
273
+ position: $panel.sending.position,
274
+ count: $panel.sending.count
275
+ })}
276
+ {:else}
277
+ {$t('editor.knowledge.sending', { name: $panel.sending.name })}
278
+ {/if}
279
+ </span>
280
+ </p>
281
+ {/if}
282
+
283
+ <!-- Below the list, next to the buttons that were pressed: at the top of a long list it would be out of sight. -->
284
+ {#if $panel.notices.length > 0}
285
+ <div
286
+ bind:this={noticesElement}
287
+ class="flex flex-col gap-1 rounded-medium border border-error bg-white px-3 py-2"
288
+ role="alert"
289
+ >
290
+ {#each $panel.notices as notice (notice.id)}
291
+ <p class="subtext flex gap-2 text-error">
292
+ <TriangleAlert class="mt-[2px] h-4 w-4 shrink-0" aria-hidden="true" />
293
+ <span>{sentenceOf(notice.message)}</span>
294
+ </p>
295
+ {/each}
296
+ <Button variant="ghost" size="sm" class="self-end text-grey5" onclick={() => panel.dismissNotices()}>
297
+ {$t('editor.knowledge.dismiss')}
298
+ </Button>
299
+ </div>
300
+ {/if}
301
+
302
+ {#if isFull}
303
+ <p class="subtext text-grey5">{$t('editor.knowledgeError.limitDocuments')}</p>
304
+ {/if}
305
+
306
+ <div class="flex flex-col gap-2">
307
+ <div class="flex items-center gap-2">
308
+ <Button
309
+ variant="ghost"
310
+ class="group h-13 min-w-0 flex-1 rounded-medium border-2 border-grey2 bg-grey1 hover:bg-grey2 active:scale-[0.98]"
311
+ disabled={!canAdd}
312
+ onclick={openFileChooser}
313
+ >
314
+ <AddNew class="h-5 w-5 text-grey5" />
315
+ <span class="body-medium truncate text-grey7 group-hover:underline">{$t('editor.knowledge.addFiles')}</span>
316
+ </Button>
317
+ <Button
318
+ bind:ref={pasteButton}
319
+ variant="ghost"
320
+ class="h-13 shrink-0 rounded-medium border-2 border-grey2 bg-grey1 hover:bg-grey2 active:scale-[0.98]"
321
+ disabled={!canAdd}
322
+ aria-expanded={pasteFormOpen}
323
+ onclick={openPasteForm}
324
+ >
325
+ <span class="body-medium text-grey7">{$t('editor.knowledge.addText')}</span>
326
+ </Button>
327
+ </div>
328
+ <p class="caption text-grey5">{$t('editor.knowledge.dropHint')}</p>
329
+ </div>
330
+
331
+ <!-- Hidden: the "Add files" button opens it, and the keyboard reaches that button. -->
332
+ <input
333
+ bind:this={fileChooser}
334
+ type="file"
335
+ multiple
336
+ accept={KNOWLEDGE_FILE_ACCEPT}
337
+ class="hidden"
338
+ tabindex="-1"
339
+ aria-hidden="true"
340
+ onchange={handleFilesChosen}
341
+ />
342
+
343
+ {#if pasteFormOpen}
344
+ <KnowledgeTextForm busy={isBusy} onAdd={(input) => panel.addText(input)} onClose={closePasteForm} />
345
+ {/if}
346
+
347
+ {#if $panel.totals && $panel.totals.maxDocuments !== null && $panel.totals.maxTotalChars !== null}
348
+ <p class="caption flex flex-wrap gap-x-4 text-grey5">
349
+ <span>
350
+ {$t('editor.knowledge.documentsUsed', {
351
+ documents: formatNumber($panel.totals.documents),
352
+ maxDocuments: formatNumber($panel.totals.maxDocuments)
353
+ })}
354
+ </span>
355
+ <span>
356
+ {$t('editor.knowledge.textUsed', {
357
+ characters: formatNumber($panel.totals.characters),
358
+ maxCharacters: formatNumber($panel.totals.maxTotalChars)
359
+ })}
360
+ </span>
361
+ </p>
362
+ {/if}
363
+ {/if}
364
+ </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;