@widgetic/editor 4.1.17 → 4.1.19
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.
- package/dist/components/PreviewChromeControls.svelte +2 -2
- package/dist/components/WidgetPreview.svelte +79 -16
- package/dist/components/editors/CompositionEditorApp.svelte +71 -35
- package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
- package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
- package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
- package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
- package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
- package/dist/components/editors/EmbedEditor.svelte +221 -15
- package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
- package/dist/components/editors/PropsEditor.svelte +326 -37
- package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
- package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
- package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
- package/dist/components/ic/AngleInputController.svelte +9 -5
- package/dist/components/ic/BrowserInputController.svelte +208 -132
- package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
- package/dist/components/ic/CheckboxInputController.svelte +11 -0
- package/dist/components/ic/ColorPickerInputController.svelte +122 -49
- package/dist/components/ic/DatePickerInputController.svelte +23 -13
- package/dist/components/ic/FixedPositionInputController.svelte +1 -1
- package/dist/components/ic/FontInputController.svelte +48 -47
- package/dist/components/ic/InputControllerHeader.svelte +5 -4
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +20 -7
- package/dist/components/ic/NumberControls.svelte +163 -35
- package/dist/components/ic/PositionInputController.svelte +24 -15
- package/dist/components/ic/RadioGroupInputController.svelte +11 -0
- package/dist/components/ic/RangeCalendarInputController.svelte +73 -28
- package/dist/components/ic/RoundedCornersInputController.svelte +2 -2
- package/dist/components/ic/SliderInputController.svelte +11 -4
- package/dist/components/ic/TextAreaInputController.svelte +620 -327
- package/dist/components/ic/TextAreaPreviewInputController.svelte +53 -64
- package/dist/components/ic/TextInputController.svelte +15 -2
- package/dist/components/ic/TimeInputController.svelte +1 -1
- package/dist/components/ic/VectorInputController.svelte +152 -20
- package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
- package/dist/components/ic/numberControlsValueArea.js +51 -0
- package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
- package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
- package/dist/components/ic/shared/DropdownChevron.svelte +2 -2
- package/dist/components/ic/shared/DropdownChevron.svelte.d.ts +1 -1
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +174 -0
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +30 -0
- package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
- package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
- package/dist/components/ic/shared/ItemGrid.svelte +2 -2
- package/dist/components/ic/shared/RecentItemsSection.svelte +6 -6
- package/dist/components/ic/shared/editableFieldClasses.d.ts +15 -0
- package/dist/components/ic/shared/editableFieldClasses.js +15 -0
- package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
- package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
- package/dist/components/ic/shared/index.d.ts +1 -0
- package/dist/components/ic/shared/index.js +1 -0
- package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +41 -9
- package/dist/composition/compositionApi.d.ts +16 -0
- package/dist/composition/compositionApi.js +16 -1
- package/dist/composition/compositionEditorController.d.ts +46 -0
- package/dist/composition/compositionEditorController.js +277 -5
- package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
- package/dist/composition/compositionEditorSchemaCache.js +82 -0
- package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
- package/dist/contentBulkDrop/applyContentPlan.js +55 -0
- package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
- package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
- package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
- package/dist/contentBulkDrop/dragIntent.js +24 -0
- package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
- package/dist/contentBulkDrop/filterDropFiles.js +21 -0
- package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
- package/dist/contentBulkDrop/formatFileSize.js +13 -0
- package/dist/contentBulkDrop/types.d.ts +34 -0
- package/dist/contentBulkDrop/types.js +1 -0
- package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
- package/dist/contentBulkDrop/uploadQueue.js +114 -0
- package/dist/drafts/compositionDraft.d.ts +65 -0
- package/dist/drafts/compositionDraft.js +136 -0
- package/dist/drafts/compositionEditorViewState.d.ts +9 -0
- package/dist/drafts/compositionEditorViewState.js +33 -0
- package/dist/drafts/draftJournal.d.ts +59 -0
- package/dist/drafts/draftJournal.js +261 -0
- package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
- package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
- package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
- package/dist/embed/parseCompositionEmbedCode.js +376 -0
- package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
- package/dist/embedAssistant/embedAssistantEvents.js +39 -0
- package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
- package/dist/embedAssistant/embedAssistantStream.js +125 -0
- package/dist/embedAssistant/highlightTiming.d.ts +1 -0
- package/dist/embedAssistant/highlightTiming.js +6 -0
- package/dist/embedAssistant/types.d.ts +27 -0
- package/dist/embedAssistant/types.js +1 -0
- package/dist/i18n/labels.js +8 -4
- package/dist/i18n/language.d.ts +297 -3
- package/dist/i18n/messages.d.ts +38 -1
- package/dist/i18n/messages.js +40 -1
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/utils/FontManager.d.ts +2 -0
- package/dist/utils/FontManager.js +16 -1
- package/dist/utils/angleMath.d.ts +2 -0
- package/dist/utils/angleMath.js +6 -0
- package/dist/utils/isEditableEventTarget.d.ts +5 -0
- package/dist/utils/isEditableEventTarget.js +25 -0
- package/dist/utils/linkUrlValidation.d.ts +17 -0
- package/dist/utils/linkUrlValidation.js +120 -0
- package/dist/utils/mediaFileValue.d.ts +12 -0
- package/dist/utils/mediaFileValue.js +24 -0
- package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
- package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
- package/package.json +6 -6
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
<svelte:options runes={false} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
|
5
|
+
import { Button } from '@widgetic/design-system/components';
|
|
6
|
+
import type { MediaLibraryProvider } from '@widgetic/file-browser';
|
|
7
|
+
import { filesFromDataTransfer } from '../../contentBulkDrop/filterDropFiles.js';
|
|
8
|
+
import { shouldStartBulkContentDrop } from '../../contentBulkDrop/dragIntent.js';
|
|
9
|
+
import {
|
|
10
|
+
createUploadQueue,
|
|
11
|
+
type BulkDropUploadQueue,
|
|
12
|
+
type UploadQueueEntry,
|
|
13
|
+
type UploadQueueSnapshot
|
|
14
|
+
} from '../../contentBulkDrop/uploadQueue.js';
|
|
15
|
+
import {
|
|
16
|
+
formatBulkDropSummary,
|
|
17
|
+
formatBulkUploadFailureMessage
|
|
18
|
+
} from '../../contentBulkDrop/bulkDropSummary.js';
|
|
19
|
+
import { formatFileSize } from '../../contentBulkDrop/formatFileSize.js';
|
|
20
|
+
import type { ContentFromFilesPlan } from '../../contentBulkDrop/types.js';
|
|
21
|
+
import { useEditorLanguage } from '../../i18n/language.js';
|
|
22
|
+
|
|
23
|
+
export let enabled = true;
|
|
24
|
+
export let mediaLibrary: MediaLibraryProvider | undefined = undefined;
|
|
25
|
+
export let requestPlan: ((files: Array<{ name: string; mimeType: string; sizeBytes?: number; mediaId: string }>) => Promise<ContentFromFilesPlan>) | undefined = undefined;
|
|
26
|
+
|
|
27
|
+
const { t } = useEditorLanguage();
|
|
28
|
+
|
|
29
|
+
const dispatch = createEventDispatcher<{
|
|
30
|
+
planReady: { plan: ContentFromFilesPlan; mediaIds: Map<string, import('@widgetic/file-browser').MediaLibraryFile> };
|
|
31
|
+
uploadActivity: { active: boolean };
|
|
32
|
+
}>();
|
|
33
|
+
|
|
34
|
+
let dragDepth = 0;
|
|
35
|
+
let dragActive = false;
|
|
36
|
+
let queue: BulkDropUploadQueue | null = null;
|
|
37
|
+
let snapshot: UploadQueueSnapshot = { entries: [], activeCount: 0, allFinished: false, failures: [] };
|
|
38
|
+
let summaryMessage = '';
|
|
39
|
+
let failureMessage = '';
|
|
40
|
+
let dismissSummary = false;
|
|
41
|
+
let planning = false;
|
|
42
|
+
let leaveWarningInstalled = false;
|
|
43
|
+
|
|
44
|
+
$: uploadingPanelVisible = snapshot.entries.length > 0 && (!snapshot.allFinished || planning);
|
|
45
|
+
$: overallProgress = computeOverallProgress(snapshot);
|
|
46
|
+
|
|
47
|
+
function computeOverallProgress(next: UploadQueueSnapshot): number {
|
|
48
|
+
if (next.entries.length === 0) return 0;
|
|
49
|
+
let total = 0;
|
|
50
|
+
for (const entry of next.entries) {
|
|
51
|
+
if (entry.state.status === 'done') total += 100;
|
|
52
|
+
else if (entry.state.status === 'uploading') total += entry.state.progress;
|
|
53
|
+
}
|
|
54
|
+
return Math.round(total / next.entries.length);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function rowProgress(entry: UploadQueueEntry): number {
|
|
58
|
+
if (entry.state.status === 'done') return 100;
|
|
59
|
+
if (entry.state.status === 'uploading') return Math.max(0, Math.min(100, entry.state.progress));
|
|
60
|
+
if (entry.state.status === 'error' && entry.state.reason === 'upload_failed') return 20;
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function rowProgressBarClass(entry: UploadQueueEntry): string {
|
|
65
|
+
if (entry.state.status === 'error' && entry.state.reason === 'upload_failed') {
|
|
66
|
+
return 'bg-destructive';
|
|
67
|
+
}
|
|
68
|
+
return 'bg-foreground';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onDragEnter(event: DragEvent) {
|
|
72
|
+
if (!enabled || !shouldStartBulkContentDrop(event)) return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
dragDepth += 1;
|
|
75
|
+
dragActive = true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onDragLeave(event: DragEvent) {
|
|
79
|
+
if (!enabled) return;
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
dragDepth = Math.max(0, dragDepth - 1);
|
|
82
|
+
if (dragDepth === 0) dragActive = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function onDragOver(event: DragEvent) {
|
|
86
|
+
if (!enabled || !shouldStartBulkContentDrop(event)) return;
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function onDrop(event: DragEvent) {
|
|
91
|
+
if (!enabled || !mediaLibrary || !requestPlan || !shouldStartBulkContentDrop(event)) return;
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
dragDepth = 0;
|
|
94
|
+
dragActive = false;
|
|
95
|
+
const files = filesFromDataTransfer(event.dataTransfer);
|
|
96
|
+
if (files.length === 0) return;
|
|
97
|
+
dismissSummary = false;
|
|
98
|
+
summaryMessage = '';
|
|
99
|
+
failureMessage = '';
|
|
100
|
+
queue?.reset();
|
|
101
|
+
queue = createUploadQueue(mediaLibrary);
|
|
102
|
+
queue.subscribe((next) => {
|
|
103
|
+
snapshot = next;
|
|
104
|
+
dispatch('uploadActivity', { active: queue?.hasActiveUploads() ?? false });
|
|
105
|
+
if (next.allFinished) void finishUploads();
|
|
106
|
+
});
|
|
107
|
+
queue.enqueue(files);
|
|
108
|
+
installLeaveWarning();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function finishUploads() {
|
|
112
|
+
if (!queue || !requestPlan || planning) return;
|
|
113
|
+
if (snapshot.failures.length > 0) {
|
|
114
|
+
failureMessage = formatBulkUploadFailureMessage($t, snapshot.failures.length);
|
|
115
|
+
}
|
|
116
|
+
const uploads = queue.successfulUploads();
|
|
117
|
+
if (uploads.length === 0) return;
|
|
118
|
+
planning = true;
|
|
119
|
+
try {
|
|
120
|
+
const mediaIds = new Map<string, import('@widgetic/file-browser').MediaLibraryFile>();
|
|
121
|
+
const body = uploads.map((entry) => {
|
|
122
|
+
mediaIds.set(entry.file.id, entry.file);
|
|
123
|
+
return {
|
|
124
|
+
name: entry.sourceName,
|
|
125
|
+
mimeType: entry.file.mimeType ?? 'application/octet-stream',
|
|
126
|
+
sizeBytes: entry.file.size,
|
|
127
|
+
mediaId: entry.file.id
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
const plan = await requestPlan(body);
|
|
131
|
+
summaryMessage = formatBulkDropSummary($t, plan.summary.added, plan.summary.libraryOnly);
|
|
132
|
+
dispatch('planReady', { plan, mediaIds });
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.warn('[ContentTabBulkDrop] Could not plan content from files:', error);
|
|
135
|
+
failureMessage = formatBulkUploadFailureMessage($t, uploads.length);
|
|
136
|
+
} finally {
|
|
137
|
+
planning = false;
|
|
138
|
+
removeLeaveWarning();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function retryFailedUploads() {
|
|
143
|
+
queue?.retryFailures();
|
|
144
|
+
failureMessage = '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function retryOne(localId: string) {
|
|
148
|
+
queue?.retry(localId);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function beforeUnload(event: BeforeUnloadEvent) {
|
|
152
|
+
if (queue?.hasActiveUploads()) {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
event.returnValue = '';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function installLeaveWarning() {
|
|
159
|
+
if (leaveWarningInstalled || typeof window === 'undefined') return;
|
|
160
|
+
window.addEventListener('beforeunload', beforeUnload);
|
|
161
|
+
leaveWarningInstalled = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function removeLeaveWarning() {
|
|
165
|
+
if (!leaveWarningInstalled || typeof window === 'undefined') return;
|
|
166
|
+
window.removeEventListener('beforeunload', beforeUnload);
|
|
167
|
+
leaveWarningInstalled = false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
onDestroy(() => {
|
|
171
|
+
removeLeaveWarning();
|
|
172
|
+
queue?.reset();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
onMount(() => () => removeLeaveWarning());
|
|
176
|
+
</script>
|
|
177
|
+
|
|
178
|
+
<div
|
|
179
|
+
class="content-bulk-drop-host pointer-events-none absolute inset-0 z-20"
|
|
180
|
+
class:pointer-events-auto={enabled}
|
|
181
|
+
role="presentation"
|
|
182
|
+
on:dragenter={onDragEnter}
|
|
183
|
+
on:dragleave={onDragLeave}
|
|
184
|
+
on:dragover={onDragOver}
|
|
185
|
+
on:drop={onDrop}
|
|
186
|
+
>
|
|
187
|
+
{#if dragActive && !uploadingPanelVisible}
|
|
188
|
+
<div
|
|
189
|
+
class="pointer-events-none absolute inset-3 flex items-center justify-center rounded-xl border-2 border-dashed border-primary bg-primary/5"
|
|
190
|
+
>
|
|
191
|
+
<p class="text-body-medium text-primary">{$t('editor.contentBulkDrop.dragOver')}</p>
|
|
192
|
+
</div>
|
|
193
|
+
{/if}
|
|
194
|
+
|
|
195
|
+
{#if uploadingPanelVisible}
|
|
196
|
+
<div
|
|
197
|
+
class="pointer-events-auto absolute inset-x-0 top-0 flex max-h-full flex-col gap-3 overflow-y-auto bg-popover/95 px-6 pb-4 pt-2 backdrop-blur-sm"
|
|
198
|
+
>
|
|
199
|
+
<p class="text-body-medium text-foreground">
|
|
200
|
+
{$t('editor.contentBulkDrop.uploadingHeader', { n: String(snapshot.entries.length) })}
|
|
201
|
+
</p>
|
|
202
|
+
<div class="flex flex-col gap-3">
|
|
203
|
+
{#each snapshot.entries as entry (entry.localId)}
|
|
204
|
+
<div class="flex flex-col gap-1.5">
|
|
205
|
+
<div class="flex h-5 items-center justify-between gap-2">
|
|
206
|
+
<span class="text-body truncate text-foreground">{entry.source.name}</span>
|
|
207
|
+
<span class="text-caption shrink-0 text-muted-foreground"
|
|
208
|
+
>{formatFileSize(entry.source.size)}</span
|
|
209
|
+
>
|
|
210
|
+
</div>
|
|
211
|
+
{#if entry.state.status === 'error' && entry.state.reason === 'too_large'}
|
|
212
|
+
<p class="text-caption text-muted-foreground">{$t('editor.contentBulkDrop.tooLarge')}</p>
|
|
213
|
+
{:else if entry.state.status !== 'error' || entry.state.reason === 'upload_failed'}
|
|
214
|
+
<div class="h-1 w-full overflow-hidden rounded-sm bg-muted">
|
|
215
|
+
<div
|
|
216
|
+
class="h-full rounded-sm transition-[width] duration-fast {rowProgressBarClass(entry)}"
|
|
217
|
+
style="width: {rowProgress(entry)}%"
|
|
218
|
+
></div>
|
|
219
|
+
</div>
|
|
220
|
+
{/if}
|
|
221
|
+
{#if entry.state.status === 'error' && entry.state.reason === 'upload_failed'}
|
|
222
|
+
<div class="flex items-center gap-2 text-caption">
|
|
223
|
+
<span class="text-destructive">{$t('editor.contentBulkDrop.uploadFailed')}</span>
|
|
224
|
+
{#if entry.state.canRetry}
|
|
225
|
+
<Button variant="ghost" size="sm" class="h-auto px-1 py-0" onclick={() => retryOne(entry.localId)}>
|
|
226
|
+
{$t('editor.app.retry')}
|
|
227
|
+
</Button>
|
|
228
|
+
{/if}
|
|
229
|
+
</div>
|
|
230
|
+
{/if}
|
|
231
|
+
</div>
|
|
232
|
+
{/each}
|
|
233
|
+
</div>
|
|
234
|
+
<div class="h-1.5 w-full overflow-hidden rounded-sm bg-muted">
|
|
235
|
+
<div
|
|
236
|
+
class="h-full rounded-sm bg-foreground transition-[width] duration-fast"
|
|
237
|
+
style="width: {overallProgress}%"
|
|
238
|
+
></div>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
{/if}
|
|
242
|
+
|
|
243
|
+
{#if !dismissSummary && summaryMessage}
|
|
244
|
+
<div
|
|
245
|
+
class="pointer-events-auto absolute inset-x-4 bottom-20 rounded-xl border border-border bg-accent/60 px-3 py-3"
|
|
246
|
+
role="status"
|
|
247
|
+
>
|
|
248
|
+
<div class="flex items-start justify-between gap-3">
|
|
249
|
+
<span class="text-body-medium text-foreground">{summaryMessage}</span>
|
|
250
|
+
<Button variant="ghost" size="sm" onclick={() => (dismissSummary = true)}>
|
|
251
|
+
{$t('editor.contentBulkDrop.dismiss')}
|
|
252
|
+
</Button>
|
|
253
|
+
</div>
|
|
254
|
+
</div>
|
|
255
|
+
{/if}
|
|
256
|
+
|
|
257
|
+
{#if failureMessage}
|
|
258
|
+
<div
|
|
259
|
+
class="pointer-events-auto absolute inset-x-4 bottom-4 rounded-lg border border-destructive/40 bg-popover px-3 py-2 shadow-md"
|
|
260
|
+
role="status"
|
|
261
|
+
>
|
|
262
|
+
<div class="flex items-center justify-between gap-3">
|
|
263
|
+
<span class="text-body text-foreground">{failureMessage}</span>
|
|
264
|
+
<Button variant="outline" size="sm" onclick={retryFailedUploads}>{$t('editor.app.retry')}</Button>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
{/if}
|
|
268
|
+
</div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MediaLibraryProvider } from '@widgetic/file-browser';
|
|
2
|
+
import type { ContentFromFilesPlan } from '../../contentBulkDrop/types.js';
|
|
3
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
4
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
|
+
$$bindings?: Bindings;
|
|
6
|
+
} & Exports;
|
|
7
|
+
(internal: unknown, props: Props & {
|
|
8
|
+
$$events?: Events;
|
|
9
|
+
$$slots?: Slots;
|
|
10
|
+
}): Exports & {
|
|
11
|
+
$set?: any;
|
|
12
|
+
$on?: any;
|
|
13
|
+
};
|
|
14
|
+
z_$$bindings?: Bindings;
|
|
15
|
+
}
|
|
16
|
+
declare const ContentTabBulkDrop: $$__sveltets_2_IsomorphicComponent<{
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
mediaLibrary?: MediaLibraryProvider | undefined;
|
|
19
|
+
requestPlan?: ((files: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
sizeBytes?: number;
|
|
23
|
+
mediaId: string;
|
|
24
|
+
}>) => Promise<ContentFromFilesPlan>) | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
planReady: CustomEvent<{
|
|
27
|
+
plan: ContentFromFilesPlan;
|
|
28
|
+
mediaIds: Map<string, import("@widgetic/file-browser").MediaLibraryFile>;
|
|
29
|
+
}>;
|
|
30
|
+
uploadActivity: CustomEvent<{
|
|
31
|
+
active: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
} & {
|
|
34
|
+
[evt: string]: CustomEvent<any>;
|
|
35
|
+
}, {}, {}, string>;
|
|
36
|
+
type ContentTabBulkDrop = InstanceType<typeof ContentTabBulkDrop>;
|
|
37
|
+
export default ContentTabBulkDrop;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Embed configuration assistant: collapsible side panel for natural-language embed settings.
|
|
3
|
+
-->
|
|
4
|
+
<svelte:options runes={false} />
|
|
5
|
+
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
|
8
|
+
import { Button } from '@widgetic/design-system/components';
|
|
9
|
+
import { useEditorLanguage } from '../../i18n/language.js';
|
|
10
|
+
import type { EmbedAssistantWireConfig } from '../../embedAssistant/types.js';
|
|
11
|
+
import {
|
|
12
|
+
buildAssistantHistory,
|
|
13
|
+
emptyEmbedAssistantUiState,
|
|
14
|
+
reduceEmbedAssistantUiState,
|
|
15
|
+
type EmbedAssistantUiState,
|
|
16
|
+
} from '../../embedAssistant/embedAssistantEvents.js';
|
|
17
|
+
import {
|
|
18
|
+
EMBED_ASSISTANT_STREAM_MESSAGES,
|
|
19
|
+
parseEmbedAssistantSseStream,
|
|
20
|
+
} from '../../embedAssistant/embedAssistantStream.js';
|
|
21
|
+
|
|
22
|
+
const SESSION_OPEN_KEY = 'embed_assistant_panel_open';
|
|
23
|
+
const SESSION_WIDTH_KEY = 'embed_assistant_panel_width';
|
|
24
|
+
const DEFAULT_PANEL_WIDTH = 320;
|
|
25
|
+
|
|
26
|
+
export let assistant: EmbedAssistantWireConfig;
|
|
27
|
+
export let currentSettings: Record<string, unknown> = {};
|
|
28
|
+
export let panelWidth = DEFAULT_PANEL_WIDTH;
|
|
29
|
+
|
|
30
|
+
const dispatch = createEventDispatcher<{
|
|
31
|
+
optionsSet: { options: Record<string, unknown>; changedIds: string[] };
|
|
32
|
+
copyEmbedCode: void;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
const { t } = useEditorLanguage();
|
|
36
|
+
|
|
37
|
+
let collapsed = true;
|
|
38
|
+
let draft = '';
|
|
39
|
+
let ui: EmbedAssistantUiState = { ...emptyEmbedAssistantUiState };
|
|
40
|
+
let selectedOptionIds: string[] = [];
|
|
41
|
+
let resizeStartX = 0;
|
|
42
|
+
let resizeStartWidth = DEFAULT_PANEL_WIDTH;
|
|
43
|
+
let isResizing = false;
|
|
44
|
+
let streamAbort: AbortController | null = null;
|
|
45
|
+
|
|
46
|
+
const welcomeChips = [
|
|
47
|
+
{ labelKey: 'editor.embedAssistant.chipOverlayExitIntent', messageKey: 'editor.embedAssistant.chipOverlayExitIntent' },
|
|
48
|
+
{ labelKey: 'editor.embedAssistant.chipCenteredFiveTimes', messageKey: 'editor.embedAssistant.chipCenteredFiveTimes' },
|
|
49
|
+
{ labelKey: 'editor.embedAssistant.chipHideOnMobile', messageKey: 'editor.embedAssistant.chipHideOnMobile' },
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
onMount(() => {
|
|
53
|
+
try {
|
|
54
|
+
collapsed = sessionStorage.getItem(SESSION_OPEN_KEY) !== 'open';
|
|
55
|
+
const storedWidth = Number(sessionStorage.getItem(SESSION_WIDTH_KEY));
|
|
56
|
+
if (Number.isFinite(storedWidth) && storedWidth >= 280 && storedWidth <= 480) {
|
|
57
|
+
panelWidth = storedWidth;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
/* ignore */
|
|
61
|
+
}
|
|
62
|
+
if (assistant.initialTranscript?.length) {
|
|
63
|
+
ui = { ...ui, messages: [...assistant.initialTranscript] };
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function persistOpenState(): void {
|
|
68
|
+
try {
|
|
69
|
+
sessionStorage.setItem(SESSION_OPEN_KEY, collapsed ? 'closed' : 'open');
|
|
70
|
+
sessionStorage.setItem(SESSION_WIDTH_KEY, String(panelWidth));
|
|
71
|
+
} catch {
|
|
72
|
+
/* ignore */
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function notifyTranscript(): void {
|
|
77
|
+
assistant.onTranscriptChange?.(ui.messages);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function authHeaders(): Promise<Record<string, string>> {
|
|
81
|
+
const headers = assistant.getAuthHeaders;
|
|
82
|
+
return typeof headers === 'function' ? headers() : headers;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function sendMessage(
|
|
86
|
+
text: string,
|
|
87
|
+
answer?: { cardId: string; selectedOptionIds: string[] },
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
if (!text.trim() || ui.isStreaming) return;
|
|
90
|
+
streamAbort?.abort();
|
|
91
|
+
streamAbort = new AbortController();
|
|
92
|
+
ui = reduceEmbedAssistantUiState(ui, { type: 'user_message', id: crypto.randomUUID(), text });
|
|
93
|
+
ui = reduceEmbedAssistantUiState(ui, { type: 'streaming', value: true });
|
|
94
|
+
notifyTranscript();
|
|
95
|
+
try {
|
|
96
|
+
const response = await fetch(assistant.streamUrl, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json', ...(await authHeaders()) },
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
message: text,
|
|
101
|
+
history: buildAssistantHistory(ui.messages.slice(0, -1)),
|
|
102
|
+
currentSettings,
|
|
103
|
+
...(answer ? { answerToQuestion: answer } : {}),
|
|
104
|
+
}),
|
|
105
|
+
signal: streamAbort.signal,
|
|
106
|
+
});
|
|
107
|
+
for await (const event of parseEmbedAssistantSseStream(response, streamAbort.signal)) {
|
|
108
|
+
if (event.type === 'options_set') {
|
|
109
|
+
dispatch('optionsSet', {
|
|
110
|
+
options: event.payload.options,
|
|
111
|
+
changedIds: event.payload.changedIds,
|
|
112
|
+
});
|
|
113
|
+
} else if (event.type === 'streaming') {
|
|
114
|
+
ui = reduceEmbedAssistantUiState(ui, event);
|
|
115
|
+
} else if (event.type === 'done') {
|
|
116
|
+
ui = reduceEmbedAssistantUiState(ui, event);
|
|
117
|
+
} else if (event.type === 'error') {
|
|
118
|
+
ui = reduceEmbedAssistantUiState(ui, event);
|
|
119
|
+
} else {
|
|
120
|
+
ui = reduceEmbedAssistantUiState(ui, event);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (ui.isStreaming) {
|
|
124
|
+
ui = reduceEmbedAssistantUiState(ui, { type: 'streaming', value: false });
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error instanceof DOMException && error.name === 'AbortError') return;
|
|
128
|
+
ui = reduceEmbedAssistantUiState(ui, {
|
|
129
|
+
type: 'error',
|
|
130
|
+
message: EMBED_ASSISTANT_STREAM_MESSAGES.generic,
|
|
131
|
+
});
|
|
132
|
+
ui = reduceEmbedAssistantUiState(ui, { type: 'streaming', value: false });
|
|
133
|
+
}
|
|
134
|
+
notifyTranscript();
|
|
135
|
+
draft = '';
|
|
136
|
+
selectedOptionIds = [];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function toggleCollapsed(): void {
|
|
140
|
+
collapsed = !collapsed;
|
|
141
|
+
persistOpenState();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function newChat(): void {
|
|
145
|
+
streamAbort?.abort();
|
|
146
|
+
ui = reduceEmbedAssistantUiState(ui, { type: 'reset' });
|
|
147
|
+
notifyTranscript();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function submitQuestionAnswer(): void {
|
|
151
|
+
if (!ui.pendingQuestion || selectedOptionIds.length === 0) return;
|
|
152
|
+
const labels = ui.pendingQuestion.options
|
|
153
|
+
.filter((option) => selectedOptionIds.includes(option.id))
|
|
154
|
+
.map((option) => option.label)
|
|
155
|
+
.join(', ');
|
|
156
|
+
void sendMessage(labels, {
|
|
157
|
+
cardId: ui.pendingQuestion.cardId,
|
|
158
|
+
selectedOptionIds,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function startResize(event: PointerEvent): void {
|
|
163
|
+
isResizing = true;
|
|
164
|
+
resizeStartX = event.clientX;
|
|
165
|
+
resizeStartWidth = panelWidth;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function onResizeMove(event: PointerEvent): void {
|
|
169
|
+
if (!isResizing) return;
|
|
170
|
+
const delta = resizeStartX - event.clientX;
|
|
171
|
+
panelWidth = Math.min(480, Math.max(280, resizeStartWidth + delta));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function endResize(): void {
|
|
175
|
+
if (!isResizing) return;
|
|
176
|
+
isResizing = false;
|
|
177
|
+
persistOpenState();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onDestroy(() => {
|
|
181
|
+
streamAbort?.abort();
|
|
182
|
+
endResize();
|
|
183
|
+
});
|
|
184
|
+
</script>
|
|
185
|
+
|
|
186
|
+
<svelte:window on:pointermove={onResizeMove} on:pointerup={endResize} />
|
|
187
|
+
|
|
188
|
+
{#if collapsed}
|
|
189
|
+
<button
|
|
190
|
+
type="button"
|
|
191
|
+
class="embed-assistant-tab bg-background text-caption text-foreground hover:bg-accent border-border absolute end-0 top-1/2 z-20 flex -translate-y-1/2 cursor-pointer flex-col items-center gap-1 rounded-s-[12px] border border-e-0 px-2 py-4 shadow-sm [writing-mode:vertical-rl]"
|
|
192
|
+
on:click={toggleCollapsed}
|
|
193
|
+
aria-expanded="false"
|
|
194
|
+
aria-label={$t('editor.embedAssistant.tabLabel')}
|
|
195
|
+
>
|
|
196
|
+
{$t('editor.embedAssistant.tabLabel')}
|
|
197
|
+
</button>
|
|
198
|
+
{:else}
|
|
199
|
+
<aside
|
|
200
|
+
class="embed-assistant-panel bg-background border-border flex h-full shrink-0 flex-col border-s shadow-sm"
|
|
201
|
+
style="width: {panelWidth}px"
|
|
202
|
+
aria-label={$t('editor.embedAssistant.title')}
|
|
203
|
+
>
|
|
204
|
+
<div
|
|
205
|
+
class="embed-assistant-resize-handle absolute start-0 top-0 h-full w-1 cursor-col-resize"
|
|
206
|
+
role="separator"
|
|
207
|
+
aria-orientation="vertical"
|
|
208
|
+
on:pointerdown={startResize}
|
|
209
|
+
></div>
|
|
210
|
+
<header class="border-border flex items-center justify-between gap-2 border-b px-4 py-3">
|
|
211
|
+
<h2 class="text-body font-medium text-foreground">{$t('editor.embedAssistant.title')}</h2>
|
|
212
|
+
<div class="flex items-center gap-2">
|
|
213
|
+
<Button variant="ghost" size="sm" onclick={newChat}>{$t('editor.embedAssistant.newChat')}</Button>
|
|
214
|
+
<Button variant="ghost" size="sm" onclick={toggleCollapsed}>{$t('editor.embedAssistant.collapse')}</Button>
|
|
215
|
+
</div>
|
|
216
|
+
</header>
|
|
217
|
+
<div class="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-3">
|
|
218
|
+
{#if ui.messages.length === 0}
|
|
219
|
+
<p class="text-body text-muted-foreground text-center">{$t('editor.embedAssistant.welcome')}</p>
|
|
220
|
+
<div class="flex flex-wrap justify-center gap-2">
|
|
221
|
+
{#each welcomeChips as chip (chip.labelKey)}
|
|
222
|
+
<Button
|
|
223
|
+
variant="secondary"
|
|
224
|
+
size="sm"
|
|
225
|
+
onclick={() => sendMessage($t(chip.messageKey))}
|
|
226
|
+
>
|
|
227
|
+
{$t(chip.labelKey)}
|
|
228
|
+
</Button>
|
|
229
|
+
{/each}
|
|
230
|
+
</div>
|
|
231
|
+
{/if}
|
|
232
|
+
{#each ui.messages as message (message.id)}
|
|
233
|
+
<div
|
|
234
|
+
class="text-body {message.role === 'user'
|
|
235
|
+
? 'text-foreground'
|
|
236
|
+
: 'text-muted-foreground'}"
|
|
237
|
+
>
|
|
238
|
+
{message.text}
|
|
239
|
+
</div>
|
|
240
|
+
{/each}
|
|
241
|
+
{#if ui.isStreaming}
|
|
242
|
+
<p class="text-caption text-muted-foreground" aria-live="polite">{$t('editor.embedAssistant.working')}</p>
|
|
243
|
+
{/if}
|
|
244
|
+
{#if ui.pendingQuestion}
|
|
245
|
+
<div class="border-border rounded-xl border bg-accent/30 p-3">
|
|
246
|
+
<p class="text-body text-foreground mb-2">{ui.pendingQuestion.question}</p>
|
|
247
|
+
<div class="flex flex-col gap-2">
|
|
248
|
+
{#each ui.pendingQuestion.options as option (option.id)}
|
|
249
|
+
<label class="flex cursor-pointer items-center gap-2">
|
|
250
|
+
<input
|
|
251
|
+
type={ui.pendingQuestion.allowMultiple ? 'checkbox' : 'radio'}
|
|
252
|
+
name="embed-assistant-question"
|
|
253
|
+
value={option.id}
|
|
254
|
+
checked={selectedOptionIds.includes(option.id)}
|
|
255
|
+
on:change={() => {
|
|
256
|
+
if (ui.pendingQuestion?.allowMultiple) {
|
|
257
|
+
selectedOptionIds = selectedOptionIds.includes(option.id)
|
|
258
|
+
? selectedOptionIds.filter((id) => id !== option.id)
|
|
259
|
+
: [...selectedOptionIds, option.id];
|
|
260
|
+
} else {
|
|
261
|
+
selectedOptionIds = [option.id];
|
|
262
|
+
}
|
|
263
|
+
}}
|
|
264
|
+
/>
|
|
265
|
+
<span class="text-body text-foreground">{option.label}</span>
|
|
266
|
+
</label>
|
|
267
|
+
{/each}
|
|
268
|
+
</div>
|
|
269
|
+
<Button class="mt-3" size="sm" onclick={submitQuestionAnswer}>
|
|
270
|
+
{$t('editor.embedAssistant.continue')}
|
|
271
|
+
</Button>
|
|
272
|
+
</div>
|
|
273
|
+
{/if}
|
|
274
|
+
{#if ui.lastError}
|
|
275
|
+
<p class="text-caption text-destructive" role="alert">{ui.lastError}</p>
|
|
276
|
+
{/if}
|
|
277
|
+
</div>
|
|
278
|
+
<footer class="border-border border-t px-4 py-3">
|
|
279
|
+
{#if ui.showCopyPrimary}
|
|
280
|
+
<Button class="mb-2 w-full" onclick={() => dispatch('copyEmbedCode')}>
|
|
281
|
+
{$t('editor.embedAssistant.copyEmbedCode')}
|
|
282
|
+
</Button>
|
|
283
|
+
{/if}
|
|
284
|
+
<div class="flex gap-2">
|
|
285
|
+
<input
|
|
286
|
+
class="text-body text-foreground bg-accent border-border min-w-0 flex-1 rounded-lg border px-3 py-2"
|
|
287
|
+
placeholder={$t('editor.embedAssistant.composerPlaceholder')}
|
|
288
|
+
bind:value={draft}
|
|
289
|
+
disabled={ui.isStreaming}
|
|
290
|
+
on:keydown={(event) => {
|
|
291
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
292
|
+
event.preventDefault();
|
|
293
|
+
void sendMessage(draft);
|
|
294
|
+
}
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
<Button size="sm" disabled={ui.isStreaming || !draft.trim()} onclick={() => sendMessage(draft)}>
|
|
298
|
+
{$t('editor.embedAssistant.send')}
|
|
299
|
+
</Button>
|
|
300
|
+
</div>
|
|
301
|
+
</footer>
|
|
302
|
+
</aside>
|
|
303
|
+
{/if}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EmbedAssistantWireConfig } from '../../embedAssistant/types.js';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const EmbedAssistantPanel: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
assistant: EmbedAssistantWireConfig;
|
|
17
|
+
currentSettings?: Record<string, unknown>;
|
|
18
|
+
panelWidth?: number;
|
|
19
|
+
}, {
|
|
20
|
+
optionsSet: CustomEvent<{
|
|
21
|
+
options: Record<string, unknown>;
|
|
22
|
+
changedIds: string[];
|
|
23
|
+
}>;
|
|
24
|
+
copyEmbedCode: CustomEvent<void>;
|
|
25
|
+
} & {
|
|
26
|
+
[evt: string]: CustomEvent<any>;
|
|
27
|
+
}, {}, {}, string>;
|
|
28
|
+
type EmbedAssistantPanel = InstanceType<typeof EmbedAssistantPanel>;
|
|
29
|
+
export default EmbedAssistantPanel;
|