@widgetic/editor 4.1.18 → 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/WidgetPreview.svelte +77 -14
- 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 +223 -30
- 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/BrowserInputController.svelte +184 -21
- package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
- package/dist/components/ic/CheckboxInputController.svelte +11 -0
- package/dist/components/ic/ColorPickerInputController.svelte +2 -1
- package/dist/components/ic/DatePickerInputController.svelte +5 -3
- package/dist/components/ic/FontInputController.svelte +9 -4
- package/dist/components/ic/InputControllerHeader.svelte +4 -3
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +13 -0
- package/dist/components/ic/NumberControls.svelte +140 -17
- package/dist/components/ic/RadioGroupInputController.svelte +11 -0
- package/dist/components/ic/RangeCalendarInputController.svelte +38 -13
- package/dist/components/ic/TextAreaInputController.svelte +593 -321
- package/dist/components/ic/TextAreaPreviewInputController.svelte +46 -58
- package/dist/components/ic/VectorInputController.svelte +0 -1
- 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/EditorFileBrowserOverlay.svelte +48 -6
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +4 -1
- 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/fileBrowserOverlayEscape.d.ts +29 -0
- package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
- 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 +38 -2
- 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/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,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;
|
|
@@ -9,10 +9,14 @@
|
|
|
9
9
|
<svelte:options runes={false} />
|
|
10
10
|
|
|
11
11
|
<script lang="ts">
|
|
12
|
-
import {
|
|
13
|
-
import { toast, CopyableHeader } from '@widgetic/design-system/components';
|
|
12
|
+
import { createEventDispatcher } from 'svelte';
|
|
13
|
+
import { toast, CopyableHeader, Button } from '@widgetic/design-system/components';
|
|
14
14
|
import PropsEditor from './PropsEditor.svelte';
|
|
15
15
|
import { useEditorLanguage } from '../../i18n/language';
|
|
16
|
+
import { parseCompositionEmbedCode } from '../../embed/parseCompositionEmbedCode.js';
|
|
17
|
+
import EmbedAssistantPanel from './EmbedAssistantPanel.svelte';
|
|
18
|
+
import type { EmbedAssistantWireConfig } from '../../embedAssistant/types.js';
|
|
19
|
+
import { schedulePropertyHighlights } from '../../embedAssistant/highlightTiming.js';
|
|
16
20
|
|
|
17
21
|
/** Component configuration — existing public props and methods are preserved. */
|
|
18
22
|
let className = '';
|
|
@@ -20,6 +24,8 @@
|
|
|
20
24
|
export let style = '';
|
|
21
25
|
/** The title of the code box. Without one, the editor's own word in the language of the page. */
|
|
22
26
|
export let embedHeaderText: string | undefined = undefined;
|
|
27
|
+
/** Where the "Learn more" link under the code box leads: the end-user guide "How does Embed work?". */
|
|
28
|
+
export let embedHelpUrl = 'https://docs.superhuman.com/@andu/embed';
|
|
23
29
|
export let embedCode = '';
|
|
24
30
|
export let height = 720;
|
|
25
31
|
export let embedSchema: any;
|
|
@@ -33,16 +39,47 @@
|
|
|
33
39
|
export let saveDirty = false;
|
|
34
40
|
/** True while a save request is in flight. */
|
|
35
41
|
export let saveSaving = false;
|
|
42
|
+
/**
|
|
43
|
+
* Where the open values came from (`saved`, `widget_default`, or `none`). When `widget_default`, shows the reuse hint until the user edits.
|
|
44
|
+
*/
|
|
45
|
+
export let settingsSource: 'saved' | 'widget_default' | 'none' | undefined = undefined;
|
|
46
|
+
/** Schema defaults used by the Reset action when settings came from widget defaults. */
|
|
47
|
+
export let schemaDefaults: Record<string, unknown> = {};
|
|
48
|
+
/** Autosave status line from the host (`Saving…`, `Saved`, or a retry message). */
|
|
49
|
+
export let embedAutosaveStatus = '';
|
|
50
|
+
/**
|
|
51
|
+
* Optional embed assistant wiring from the host. When omitted, no assistant tab is shown.
|
|
52
|
+
*/
|
|
53
|
+
export let assistant: EmbedAssistantWireConfig | undefined = undefined;
|
|
54
|
+
|
|
55
|
+
const dispatch = createEventDispatcher<{
|
|
56
|
+
propertyChange: { propertyId?: string; value?: unknown; opacity?: number };
|
|
57
|
+
save: void;
|
|
58
|
+
settingsPasted: { settings: Record<string, unknown> };
|
|
59
|
+
settingsReset: { settings: Record<string, unknown> };
|
|
60
|
+
}>();
|
|
36
61
|
|
|
37
62
|
// The words of the editor in the language of the page: the editor above this one chose it (see `provideEditorLanguage`).
|
|
38
63
|
const { t } = useEditorLanguage();
|
|
39
64
|
|
|
40
|
-
let loading =
|
|
65
|
+
let loading = false;
|
|
41
66
|
let wrapperElement = null;
|
|
42
|
-
let internalPropsEditorRef
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
let internalPropsEditorRef: {
|
|
68
|
+
updateDesignValue?: (id: string, value: unknown) => void;
|
|
69
|
+
setPosition?: (left: number, top: number) => void;
|
|
70
|
+
getPosition?: () => { left: number; top: number };
|
|
71
|
+
} | null = null;
|
|
72
|
+
let pasteStatusKind: '' | 'invalid' | 'applied' | 'clipboard_blocked' = '';
|
|
73
|
+
let pasteIgnoredLabels: string[] = [];
|
|
74
|
+
let codePasteSurface: HTMLTextAreaElement | null = null;
|
|
75
|
+
let widgetDefaultHintVisible = false;
|
|
76
|
+
$: widgetDefaultHintVisible = settingsSource === 'widget_default';
|
|
77
|
+
let currentEmbedSettings: Record<string, unknown> = {};
|
|
78
|
+
$: currentEmbedSettings = { ...initialValues };
|
|
79
|
+
let flashPropertyIds: string[] = [];
|
|
80
|
+
let clearHighlightDisposer: (() => void) | null = null;
|
|
81
|
+
|
|
82
|
+
$: assistantEnabled = Boolean(assistant?.enabled && assistant?.streamUrl);
|
|
46
83
|
|
|
47
84
|
/** Guard: one toast at a time for copy actions. */
|
|
48
85
|
let isToastVisible = false;
|
|
@@ -65,6 +102,101 @@
|
|
|
65
102
|
});
|
|
66
103
|
}
|
|
67
104
|
|
|
105
|
+
function clearPasteStatus() {
|
|
106
|
+
pasteStatusKind = '';
|
|
107
|
+
pasteIgnoredLabels = [];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function applySettingsToEditor(settings: Record<string, unknown>) {
|
|
111
|
+
for (const [propertyId, value] of Object.entries(settings)) {
|
|
112
|
+
internalPropsEditorRef?.updateDesignValue?.(propertyId, value);
|
|
113
|
+
currentEmbedSettings = { ...currentEmbedSettings, [propertyId]: value };
|
|
114
|
+
dispatch('propertyChange', { propertyId, value });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function handleAssistantOptionsSet(
|
|
119
|
+
event: CustomEvent<{ options: Record<string, unknown>; changedIds: string[] }>,
|
|
120
|
+
) {
|
|
121
|
+
applySettingsToEditor(event.detail.options);
|
|
122
|
+
clearHighlightDisposer?.();
|
|
123
|
+
clearHighlightDisposer = schedulePropertyHighlights(
|
|
124
|
+
event.detail.changedIds,
|
|
125
|
+
(ids) => {
|
|
126
|
+
flashPropertyIds = ids;
|
|
127
|
+
},
|
|
128
|
+
() => {
|
|
129
|
+
flashPropertyIds = [];
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function triggerCopyEmbedCode() {
|
|
135
|
+
showCopyToast('success', $t('editor.embed.copied'), {
|
|
136
|
+
description: $t('editor.embed.copiedHint')
|
|
137
|
+
});
|
|
138
|
+
void navigator.clipboard.writeText(embedCode).catch(() => {
|
|
139
|
+
showCopyToast('error', $t('editor.embed.copyFailed'), {
|
|
140
|
+
description: $t('editor.embed.copyFailedHint')
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function handlePastedText(text: string) {
|
|
146
|
+
const parsed = parseCompositionEmbedCode(text);
|
|
147
|
+
if (!parsed.ok) {
|
|
148
|
+
pasteStatusKind = 'invalid';
|
|
149
|
+
pasteIgnoredLabels = [];
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
applySettingsToEditor(parsed.settings);
|
|
153
|
+
dispatch('settingsPasted', { settings: parsed.settings });
|
|
154
|
+
pasteStatusKind = 'applied';
|
|
155
|
+
pasteIgnoredLabels = parsed.ignored;
|
|
156
|
+
widgetDefaultHintVisible = false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function handlePasteEmbedCodeClick() {
|
|
160
|
+
try {
|
|
161
|
+
const text = await navigator.clipboard.readText();
|
|
162
|
+
handlePastedText(text);
|
|
163
|
+
} catch {
|
|
164
|
+
pasteStatusKind = 'clipboard_blocked';
|
|
165
|
+
pasteIgnoredLabels = [];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function handleCodePaste(event: ClipboardEvent) {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
handlePastedText(event.clipboardData?.getData('text/plain') ?? '');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function blockTyping(event: Event) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function handlePropertyChanged(
|
|
179
|
+
event: CustomEvent<{ propertyId?: string; value?: unknown; opacity?: number }>
|
|
180
|
+
) {
|
|
181
|
+
clearPasteStatus();
|
|
182
|
+
widgetDefaultHintVisible = false;
|
|
183
|
+
if (event.detail?.propertyId !== undefined) {
|
|
184
|
+
currentEmbedSettings = {
|
|
185
|
+
...currentEmbedSettings,
|
|
186
|
+
[event.detail.propertyId]: event.detail.value
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
dispatch('propertyChange', event.detail ?? {});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function handleResetWidgetDefaults() {
|
|
193
|
+
const resetValues = { ...schemaDefaults };
|
|
194
|
+
applySettingsToEditor(resetValues);
|
|
195
|
+
dispatch('settingsReset', { settings: resetValues });
|
|
196
|
+
widgetDefaultHintVisible = false;
|
|
197
|
+
clearPasteStatus();
|
|
198
|
+
}
|
|
199
|
+
|
|
68
200
|
/** Public: update a design value in the internal PropsEditor (external dimension sync). */
|
|
69
201
|
export function updateValue(propertyId: string, value: any) {
|
|
70
202
|
internalPropsEditorRef?.updateDesignValue?.(propertyId, value);
|
|
@@ -83,10 +215,11 @@
|
|
|
83
215
|
|
|
84
216
|
<div
|
|
85
217
|
bind:this={wrapperElement}
|
|
86
|
-
class={standalone
|
|
218
|
+
class="{standalone
|
|
87
219
|
? 'embed-editor-standalone-wrapper bg-inverse flex min-h-screen w-full items-center justify-center p-4 widgetic-colors widgetic-radius'
|
|
88
|
-
: 'embed-editor-inline-wrapper absolute h-full
|
|
220
|
+
: 'embed-editor-inline-wrapper absolute h-full max-h-full'} {assistantEnabled ? 'flex' : ''} {standalone ? '' : assistantEnabled ? 'w-auto' : 'w-editor-panel'}"
|
|
89
221
|
>
|
|
222
|
+
<div class="{assistantEnabled ? 'relative h-full min-w-0' : 'h-full w-full'} {assistantEnabled && !standalone ? 'w-[450px]' : 'w-full'}">
|
|
90
223
|
<PropsEditor
|
|
91
224
|
bind:this={internalPropsEditorRef}
|
|
92
225
|
class="embed-editor-container {className}"
|
|
@@ -99,8 +232,10 @@
|
|
|
99
232
|
: 'auto'}
|
|
100
233
|
positionTarget={standalone ? null : wrapperElement}
|
|
101
234
|
designSchema={embedCode ? embedSchema : null}
|
|
235
|
+
scrollAreaBottomPaddingClass="pb-4"
|
|
102
236
|
contentSchema={null}
|
|
103
237
|
initialDesignValues={initialValues}
|
|
238
|
+
{flashPropertyIds}
|
|
104
239
|
defaultOpen={true}
|
|
105
240
|
showDragHandle={!loading && !!embedCode}
|
|
106
241
|
{showSaveButton}
|
|
@@ -110,21 +245,39 @@
|
|
|
110
245
|
showSchemaError={false}
|
|
111
246
|
on:save
|
|
112
247
|
on:propertyChange
|
|
248
|
+
={handlePropertyChanged}
|
|
113
249
|
>
|
|
114
250
|
{#snippet headerContent()}
|
|
115
|
-
<!-- The title sits where the tabs of the props editor sit: its text starts at the same height (the 32 row is 30 under the grip row, as the 36 tab bar is 28), and the code card is 16 under it, as the first card is under the tabs. No padding below: the 16 gap to the first accordion belongs to the list under it (PropsEditor). -->
|
|
116
251
|
<section
|
|
117
|
-
class="embed-editor-code-header flex flex-col px-6 pt-
|
|
252
|
+
class="embed-editor-code-header flex flex-col px-6 pt-2 pb-0"
|
|
118
253
|
aria-label={$t('editor.embed.headerArea')}
|
|
119
254
|
aria-busy={loading}
|
|
120
255
|
>
|
|
256
|
+
<!-- The lines above the code only exist while they have something to say, and carry their own spacing: the section's
|
|
257
|
+
own classes stay the ones Figma pins (the title starts 8 under the grip row), whatever is stacked in it. -->
|
|
258
|
+
{#if widgetDefaultHintVisible || embedAutosaveStatus}
|
|
259
|
+
<div class="flex flex-col gap-1 pb-2">
|
|
260
|
+
{#if widgetDefaultHintVisible}
|
|
261
|
+
<div class="flex items-center justify-between gap-2 text-caption text-muted-foreground">
|
|
262
|
+
<span>{$t('editor.embed.widgetDefaultsBanner')}</span>
|
|
263
|
+
<Button variant="ghost" size="sm" onclick={handleResetWidgetDefaults}
|
|
264
|
+
>{$t('editor.embed.widgetDefaultsReset')}</Button
|
|
265
|
+
>
|
|
266
|
+
</div>
|
|
267
|
+
{/if}
|
|
268
|
+
{#if embedAutosaveStatus}
|
|
269
|
+
<p class="text-caption text-muted-foreground" aria-live="polite">{embedAutosaveStatus}</p>
|
|
270
|
+
{/if}
|
|
271
|
+
</div>
|
|
272
|
+
{/if}
|
|
121
273
|
<CopyableHeader
|
|
274
|
+
titleToContentGapClass="gap-2"
|
|
122
275
|
headerText={embedHeaderText ?? $t('editor.embed.codeHeader')}
|
|
123
276
|
content={embedCode}
|
|
124
277
|
helpPrompt={$t('editor.embed.helpPrompt')}
|
|
125
278
|
helpText={$t('editor.embed.learnMore')}
|
|
126
279
|
helpLinkAria={$t('editor.embed.helpLinkAria')}
|
|
127
|
-
helpUrl=
|
|
280
|
+
helpUrl={embedHelpUrl}
|
|
128
281
|
{loading}
|
|
129
282
|
errorTitle={!loading && !embedCode ? $t('editor.embed.noCode') : ''}
|
|
130
283
|
errorDetail={!loading && !embedCode
|
|
@@ -148,10 +301,63 @@
|
|
|
148
301
|
});
|
|
149
302
|
}}
|
|
150
303
|
/>
|
|
151
|
-
|
|
152
|
-
<
|
|
153
|
-
|
|
304
|
+
<div class="flex flex-col gap-2 pt-2">
|
|
305
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
306
|
+
<Button variant="secondary" size="sm" onclick={handlePasteEmbedCodeClick}
|
|
307
|
+
>{$t('editor.embed.pasteButton')}</Button
|
|
308
|
+
>
|
|
309
|
+
</div>
|
|
310
|
+
<!-- Paste-only surface: shows the snippet but accepts paste and Cmd/Ctrl+V only. -->
|
|
311
|
+
<textarea
|
|
312
|
+
bind:this={codePasteSurface}
|
|
313
|
+
class="embed-code-paste-surface text-code text-foreground bg-accent border-border max-h-[3lh] min-h-[3lh] w-full cursor-text resize-none rounded-xl border p-3 [overflow-wrap:anywhere] break-all"
|
|
314
|
+
readonly
|
|
315
|
+
value={embedCode}
|
|
316
|
+
aria-label={$t('editor.embed.pasteAreaAria')}
|
|
317
|
+
on:paste={handleCodePaste}
|
|
318
|
+
on:beforeinput={blockTyping}
|
|
319
|
+
on:drop|preventDefault
|
|
320
|
+
on:cut|preventDefault
|
|
321
|
+
on:input={blockTyping}
|
|
322
|
+
></textarea>
|
|
323
|
+
{#if pasteStatusKind === 'invalid'}
|
|
324
|
+
<p class="text-caption text-foreground" role="status" aria-live="polite">
|
|
325
|
+
{$t('editor.embed.pasteInvalid')}
|
|
326
|
+
</p>
|
|
327
|
+
{:else if pasteStatusKind === 'applied'}
|
|
328
|
+
<p class="text-caption text-foreground" role="status" aria-live="polite">
|
|
329
|
+
{$t('editor.embed.pasteApplied')}{#if pasteIgnoredLabels.length > 0}{$t('editor.embed.pasteNotApplied', {
|
|
330
|
+
labels: pasteIgnoredLabels.join(', ')
|
|
331
|
+
})}{/if}
|
|
332
|
+
</p>
|
|
333
|
+
{:else if pasteStatusKind === 'clipboard_blocked'}
|
|
334
|
+
<p class="text-caption text-foreground" role="status" aria-live="polite">
|
|
335
|
+
{$t('editor.embed.pasteClipboardBlocked')}
|
|
336
|
+
</p>
|
|
337
|
+
{/if}
|
|
338
|
+
{#if !embedCode}
|
|
339
|
+
<span class="sr-only">{$t('editor.embed.loading')}</span>
|
|
340
|
+
{/if}
|
|
341
|
+
</div>
|
|
154
342
|
</section>
|
|
155
343
|
{/snippet}
|
|
156
344
|
</PropsEditor>
|
|
345
|
+
</div>
|
|
346
|
+
{#if assistantEnabled && assistant}
|
|
347
|
+
<div class="relative h-full shrink-0">
|
|
348
|
+
<EmbedAssistantPanel
|
|
349
|
+
{assistant}
|
|
350
|
+
currentSettings={currentEmbedSettings}
|
|
351
|
+
on:optionsSet={handleAssistantOptionsSet}
|
|
352
|
+
on:copyEmbedCode={triggerCopyEmbedCode}
|
|
353
|
+
/>
|
|
354
|
+
</div>
|
|
355
|
+
{/if}
|
|
157
356
|
</div>
|
|
357
|
+
|
|
358
|
+
<style>
|
|
359
|
+
/* Copy stays on CopyableHeader; the paste-only field is the visible code card. */
|
|
360
|
+
.embed-editor-code-header :global(.embed-code-surface) {
|
|
361
|
+
display: none;
|
|
362
|
+
}
|
|
363
|
+
</style>
|