@widgetic/creator 0.4.42 → 0.4.43
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/CreatorApp.svelte +419 -34
- package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
- package/dist/components/EmbeddedSketchViewportShell.svelte +49 -0
- package/dist/components/EmbeddedSketchViewportShell.svelte.d.ts +13 -0
- package/dist/components/WidgetDetails.svelte +23 -10
- package/dist/components/WidgetDetails.svelte.d.ts +4 -0
- package/dist/embeddedSketchLayout.d.ts +9 -0
- package/dist/embeddedSketchLayout.js +17 -0
- package/dist/i18n/language.d.ts +8 -7
- package/dist/i18n/messages.d.ts +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/sketchBoardVisibility.d.ts +17 -0
- package/dist/sketchBoardVisibility.js +22 -0
- package/dist/sketchChatDraftPrefill.d.ts +25 -0
- package/dist/sketchChatDraftPrefill.js +82 -0
- package/dist/utils/codegenStatusTails.d.ts +23 -0
- package/dist/utils/codegenStatusTails.js +77 -0
- package/package.json +1 -1
package/dist/CreatorApp.svelte
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* COMPONENTS IMPORTS from WIDGETIC DS
|
|
9
9
|
*/
|
|
10
10
|
import { Button, DropdownMenu, PasswordInput, showToast, Dialog, GenerateLoader, Portal } from '@widgetic/design-system/components';
|
|
11
|
+
import type { EmbeddedSketchMobileTab } from './embeddedSketchLayout.js';
|
|
12
|
+
import EmbeddedSketchViewportShell from './components/EmbeddedSketchViewportShell.svelte';
|
|
11
13
|
import { LogoWidgeticType } from '@widgetic/design-system/icons';
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -39,6 +41,11 @@
|
|
|
39
41
|
import type { SelectedWidgetElementReference } from './utils/widgetElementSelector.js';
|
|
40
42
|
import BrandKitPanel from './components/BrandKitPanel.svelte';
|
|
41
43
|
import { brandKitForRequest } from './generation/brandKitForRequest.js';
|
|
44
|
+
import {
|
|
45
|
+
shouldHideSketchOnBoard,
|
|
46
|
+
sketchCanvasJsonWithinPersistLimit,
|
|
47
|
+
widgetPanelIndicatesBuiltArtifact,
|
|
48
|
+
} from './sketchBoardVisibility.js';
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
51
|
* Idempotency middleware (Phase 2 hardening): the gateway rejects
|
|
@@ -202,6 +209,18 @@
|
|
|
202
209
|
type VersionRating
|
|
203
210
|
} from './utils/versionRatings.js';
|
|
204
211
|
import { generationVersionAndDocumentFields } from './utils/generationRequestFields.js';
|
|
212
|
+
import {
|
|
213
|
+
readGenerationStreamTail,
|
|
214
|
+
readPlanFromMetadata,
|
|
215
|
+
readThinkingTail,
|
|
216
|
+
type GenerationPlanWire,
|
|
217
|
+
} from './utils/codegenStatusTails.js';
|
|
218
|
+
import {
|
|
219
|
+
countDrawnCanvasObjectsInJson,
|
|
220
|
+
decideSketchDraftPrefill,
|
|
221
|
+
resolveSketchGenerateCodePrompt,
|
|
222
|
+
shouldScanBoardForSketchPrefill,
|
|
223
|
+
} from './sketchChatDraftPrefill.js';
|
|
205
224
|
import {
|
|
206
225
|
generationRefusalText,
|
|
207
226
|
headCommitForComparison,
|
|
@@ -1506,6 +1525,8 @@
|
|
|
1506
1525
|
const publishRevealTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
1507
1526
|
/** Last slice of the model stream, per widget. Painted with the status throttle, not per token. */
|
|
1508
1527
|
let generationStreamByWidgetId: Record<string, string> = {};
|
|
1528
|
+
let generationThinkingByWidgetId: Record<string, string> = {};
|
|
1529
|
+
let generationPlanByWidgetId: Record<string, GenerationPlanWire> = {};
|
|
1509
1530
|
function isAnyWidgetGenerating(): boolean {
|
|
1510
1531
|
return isGeneratingCode || Object.keys(generatingWidgetIds).some((id) => generatingWidgetIds[id]);
|
|
1511
1532
|
}
|
|
@@ -1601,6 +1622,40 @@
|
|
|
1601
1622
|
/** Fabric JSON of the board, kept so the first checkpoint can put the sketch back. */
|
|
1602
1623
|
const draftConvertSketchJson = new Map<string, string>();
|
|
1603
1624
|
const sketchSnapshotsByWidgetId = new Map<string, string>();
|
|
1625
|
+
|
|
1626
|
+
function widgetBuiltForSketchHiding(widgetId: string): boolean {
|
|
1627
|
+
if (isDraftConvertId(widgetId)) return false;
|
|
1628
|
+
return widgetPanelIndicatesBuiltArtifact(getPanelState(widgetId));
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
function rememberSketchSnapshotForWidget(widgetId: string, json: string | null | undefined): void {
|
|
1632
|
+
if (!widgetId || !sketchCanvasJsonWithinPersistLimit(json)) return;
|
|
1633
|
+
if (!sketchSnapshotsByWidgetId.has(widgetId)) {
|
|
1634
|
+
sketchSnapshotsByWidgetId.set(widgetId, json);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/** Simple canvas: stash the sketch for restore, then show only the widget shape on the board. */
|
|
1639
|
+
function hideSketchOnBoardForWidget(widgetId: string): void {
|
|
1640
|
+
if (!shouldHideSketchOnBoard({
|
|
1641
|
+
embedded,
|
|
1642
|
+
advancedFeatures: canvasAdvancedFeatures,
|
|
1643
|
+
isDraftConvertId: isDraftConvertId(widgetId),
|
|
1644
|
+
widgetHasBuiltArtifact: widgetBuiltForSketchHiding(widgetId),
|
|
1645
|
+
})) return;
|
|
1646
|
+
if (!canvasRef) return;
|
|
1647
|
+
const board = canvasRef.saveCanvas?.() ?? null;
|
|
1648
|
+
rememberSketchSnapshotForWidget(widgetId, board);
|
|
1649
|
+
const pruner = canvasRef as typeof canvasRef & {
|
|
1650
|
+
removeSketchObjectsKeepingWidget?: (id: string) => number;
|
|
1651
|
+
};
|
|
1652
|
+
const removed = pruner.removeSketchObjectsKeepingWidget?.(widgetId) ?? 0;
|
|
1653
|
+
if (removed > 0) {
|
|
1654
|
+
canvasRef.saveNow?.();
|
|
1655
|
+
syncWidgetShapeLivePreviews();
|
|
1656
|
+
console.log('[CreatorApp] Sketch hidden on board after build', widgetId.substring(0, 8), removed);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1604
1659
|
/** True while a draft conversion is being finalized (widget creation + shape replace). */
|
|
1605
1660
|
const finalizingDraftConversions = new Set<string>();
|
|
1606
1661
|
/** Keep Widget Details on this convert/draft widget until the user closes the panel. */
|
|
@@ -1644,6 +1699,16 @@
|
|
|
1644
1699
|
let promptLoadedForWidgetId: string | null = null;
|
|
1645
1700
|
/** Skip draft→prompt sync while restoring chat draft (avoids clearing promptImages). */
|
|
1646
1701
|
let suppressChatDraftSync = false;
|
|
1702
|
+
/** Sketch prefill: applied once per sketch session until the canvas clears or the user edits the draft. */
|
|
1703
|
+
let sketchPrefillApplied = false;
|
|
1704
|
+
/** Visitor-drawn shapes only (widget shapes on the board do not count). */
|
|
1705
|
+
let lastDrawnObjectCount = 0;
|
|
1706
|
+
/** Set when a prefill apply was decided before the panel Chat exposed setDraftText. */
|
|
1707
|
+
let pendingSketchGeneratePrefill = false;
|
|
1708
|
+
/** The one pending look at the board after the canvas went dirty (see `scheduleSketchPrefillFromCanvasDirty`). */
|
|
1709
|
+
let sketchPrefillDirtyTimer: ReturnType<typeof setTimeout> | null = null;
|
|
1710
|
+
/** A short delay: it coalesces a burst of dirty events into one look, and is still well ahead of the debounced autosave. */
|
|
1711
|
+
const SKETCH_PREFILL_DIRTY_DELAY_MS = 120;
|
|
1647
1712
|
|
|
1648
1713
|
// Current active conversation ID for the selected widget's chat.
|
|
1649
1714
|
// Populated via Chat's onConversationChange callback and passed to generateCode()
|
|
@@ -1917,12 +1982,21 @@
|
|
|
1917
1982
|
// picking up the line on the canvas instead of the widget.
|
|
1918
1983
|
if (!widgetAlreadyBuilt && embedded && !canvasAdvancedFeatures && sketchCanvas?.captureCanvasSketch) {
|
|
1919
1984
|
try {
|
|
1985
|
+
const sketchJsonBeforeSend = sketchCanvas.saveCanvas?.() ?? '';
|
|
1986
|
+
rememberSketchSnapshotForWidget(widgetId, sketchJsonBeforeSend);
|
|
1920
1987
|
const canvasSketch = await sketchCanvas.captureCanvasSketch();
|
|
1921
1988
|
if (canvasSketch?.startsWith('data:image/')) {
|
|
1922
1989
|
if (isDraftConvertId(widgetId)) {
|
|
1923
1990
|
draftConvertScreenshots.set(widgetId, canvasSketch);
|
|
1924
|
-
|
|
1925
|
-
|
|
1991
|
+
if (sketchJsonBeforeSend) draftConvertSketchJson.set(widgetId, sketchJsonBeforeSend);
|
|
1992
|
+
} else if (sketchCanvas.absorbCanvasSketchIntoWidget) {
|
|
1993
|
+
try {
|
|
1994
|
+
await sketchCanvas.absorbCanvasSketchIntoWidget(widgetId, canvasSketch);
|
|
1995
|
+
sketchCanvas.saveNow?.();
|
|
1996
|
+
syncWidgetShapeLivePreviews();
|
|
1997
|
+
} catch (absorbErr) {
|
|
1998
|
+
console.warn('[Chat→Sketch] Could not absorb sketch into widget shape', absorbErr);
|
|
1999
|
+
}
|
|
1926
2000
|
}
|
|
1927
2001
|
const alreadyHasImage = (attachments || []).some((attachment) =>
|
|
1928
2002
|
attachment.fileType?.startsWith('image/')
|
|
@@ -2167,7 +2241,7 @@
|
|
|
2167
2241
|
return /(?:Commit:?\s+|Code saved\s*\()[a-f0-9]{7,40}/i.test(String(content || ''));
|
|
2168
2242
|
}
|
|
2169
2243
|
|
|
2170
|
-
/** Retry failed codegen without duplicating the user bubble. A successful prompt forks a new message so each version
|
|
2244
|
+
/** Retry failed codegen without duplicating the user bubble. A successful prompt forks a new message so each version has its own turn. */
|
|
2171
2245
|
async function handleChatRetryMessage(content: string, sourceWidgetId?: string) {
|
|
2172
2246
|
const widgetId = sourceWidgetId ?? selectedWidgetId;
|
|
2173
2247
|
if (!widgetId) return;
|
|
@@ -2186,7 +2260,7 @@
|
|
|
2186
2260
|
const draftImageUrls = panelChat?.getAttachmentDataUrls?.() ?? [];
|
|
2187
2261
|
|
|
2188
2262
|
// A prompt that already has a commit must not reuse that bubble: Version N and
|
|
2189
|
-
// Version N+1 would share one message, and
|
|
2263
|
+
// Version N+1 would share one message, and the older version would have no turn of its own.
|
|
2190
2264
|
// The pictures of that sentence go with the retry, including when an earlier
|
|
2191
2265
|
// copy of the same sentence is the one that still has them.
|
|
2192
2266
|
let forkUserMessage = false;
|
|
@@ -2440,6 +2514,115 @@
|
|
|
2440
2514
|
}
|
|
2441
2515
|
}
|
|
2442
2516
|
|
|
2517
|
+
function sketchPrefillTargetWidgetId(widgetId?: string | null): string | null {
|
|
2518
|
+
return (
|
|
2519
|
+
widgetId ??
|
|
2520
|
+
focusedPanelWidgetId ??
|
|
2521
|
+
(canvasPrimaryWidgetId && !isDraftConvertId(canvasPrimaryWidgetId) ? canvasPrimaryWidgetId : null) ??
|
|
2522
|
+
(embedded && !canvasAdvancedFeatures ? CANVAS_SKETCH_DRAFT_ID : null) ??
|
|
2523
|
+
selectedWidgetId ??
|
|
2524
|
+
null
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
function sketchPrefillWidgetBuilt(targetWidgetId: string): boolean {
|
|
2529
|
+
if (!isDraftConvertId(targetWidgetId) && targetWidgetId === canvasPrimaryWidgetId) {
|
|
2530
|
+
return primaryWidgetHasGeneratedCode();
|
|
2531
|
+
}
|
|
2532
|
+
if (isDraftConvertId(targetWidgetId)) return false;
|
|
2533
|
+
const panel = getPanelState(targetWidgetId);
|
|
2534
|
+
return !!(panel.lastCommitId || panel.hasGeneratedCode || panel.lastPublishedVersion != null);
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
/** Convert-to-widget owns the draft with CONVERT_PROMPT — never compete with generate-code prefill. */
|
|
2538
|
+
function sketchConvertDraftActive(targetWidgetId: string): boolean {
|
|
2539
|
+
if (promptLoadedForWidgetId === targetWidgetId && pendingChatDraftText === CONVERT_PROMPT) return true;
|
|
2540
|
+
if (codeGenerationPrompt === CONVERT_PROMPT && focusedPanelWidgetId === targetWidgetId) return true;
|
|
2541
|
+
return false;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
function noteDrawnObjectCount(drawnObjectCount: number) {
|
|
2545
|
+
if (lastDrawnObjectCount === 0 && drawnObjectCount > 0) {
|
|
2546
|
+
sketchPrefillApplied = false;
|
|
2547
|
+
}
|
|
2548
|
+
lastDrawnObjectCount = drawnObjectCount;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* Faster than waiting for the debounced autosave, for ONE moment only: the first drawn object. A short coalescing timer (one look per
|
|
2553
|
+
* burst of dirty events, never one per event) reads the serialized board (the canvas has no "drawn objects only" count yet), and only
|
|
2554
|
+
* while no drawing is known and the widget is not built (`shouldScanBoardForSketchPrefill`), so drawing or dragging on a busy board
|
|
2555
|
+
* never costs a serialization per event. The autosave stays the source of truth for everything after (a cleared board, a typed draft).
|
|
2556
|
+
*/
|
|
2557
|
+
function scheduleSketchPrefillFromCanvasDirty() {
|
|
2558
|
+
if (!embedded || canvasAdvancedFeatures || !canvasRef?.saveCanvas) return;
|
|
2559
|
+
if (sketchPrefillDirtyTimer != null) return;
|
|
2560
|
+
if (!shouldScanBoardForSketchPrefill({ lastDrawnObjectCount, widgetBuilt: sketchPrefillWidgetBuiltNow() })) return;
|
|
2561
|
+
sketchPrefillDirtyTimer = setTimeout(() => {
|
|
2562
|
+
sketchPrefillDirtyTimer = null;
|
|
2563
|
+
try {
|
|
2564
|
+
if (!shouldScanBoardForSketchPrefill({ lastDrawnObjectCount, widgetBuilt: sketchPrefillWidgetBuiltNow() })) return;
|
|
2565
|
+
const json = canvasRef?.saveCanvas?.();
|
|
2566
|
+
const drawn = countDrawnCanvasObjectsInJson(json);
|
|
2567
|
+
if (drawn === lastDrawnObjectCount) return;
|
|
2568
|
+
noteDrawnObjectCount(drawn);
|
|
2569
|
+
maybeSyncSketchGeneratePrefill();
|
|
2570
|
+
} catch (error) {
|
|
2571
|
+
console.warn('[CreatorApp] Sketch prefill dirty check failed', error);
|
|
2572
|
+
}
|
|
2573
|
+
}, SKETCH_PREFILL_DIRTY_DELAY_MS);
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
/** True once the widget the prefill would be for has generated code (the prefill never applies after that). */
|
|
2577
|
+
function sketchPrefillWidgetBuiltNow(): boolean {
|
|
2578
|
+
const targetWidgetId = sketchPrefillTargetWidgetId();
|
|
2579
|
+
return targetWidgetId ? sketchPrefillWidgetBuilt(targetWidgetId) : false;
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
function maybeSyncSketchGeneratePrefill(widgetId?: string | null) {
|
|
2583
|
+
if (!embedded || canvasAdvancedFeatures) return;
|
|
2584
|
+
const targetWidgetId = sketchPrefillTargetWidgetId(widgetId);
|
|
2585
|
+
if (!targetWidgetId) return;
|
|
2586
|
+
if (sketchConvertDraftActive(targetWidgetId)) {
|
|
2587
|
+
pendingSketchGeneratePrefill = false;
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
const widgetBuilt = sketchPrefillWidgetBuilt(targetWidgetId);
|
|
2591
|
+
const prefillMessage = resolveSketchGenerateCodePrompt(locale, chatMessages);
|
|
2592
|
+
const chat = getChatMethodsForWidget(targetWidgetId);
|
|
2593
|
+
const draft = chat?.getDraftText?.() ?? '';
|
|
2594
|
+
const action = decideSketchDraftPrefill({
|
|
2595
|
+
drawnObjectCount: lastDrawnObjectCount,
|
|
2596
|
+
widgetBuilt,
|
|
2597
|
+
draft,
|
|
2598
|
+
prefillMessage,
|
|
2599
|
+
prefillAppliedForSketch: sketchPrefillApplied,
|
|
2600
|
+
});
|
|
2601
|
+
if (action === 'none') {
|
|
2602
|
+
if (pendingSketchGeneratePrefill && (widgetBuilt || lastDrawnObjectCount <= 0)) {
|
|
2603
|
+
pendingSketchGeneratePrefill = false;
|
|
2604
|
+
}
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
if (!chat?.getDraftText || !chat.setDraftText) {
|
|
2608
|
+
if (action === 'apply') pendingSketchGeneratePrefill = true;
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
pendingSketchGeneratePrefill = false;
|
|
2612
|
+
suppressChatDraftSync = true;
|
|
2613
|
+
try {
|
|
2614
|
+
if (action === 'apply') {
|
|
2615
|
+
chat.setDraftText(prefillMessage);
|
|
2616
|
+
sketchPrefillApplied = true;
|
|
2617
|
+
} else if (action === 'clear') {
|
|
2618
|
+
chat.setDraftText('');
|
|
2619
|
+
sketchPrefillApplied = false;
|
|
2620
|
+
}
|
|
2621
|
+
} finally {
|
|
2622
|
+
suppressChatDraftSync = false;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2443
2626
|
function handleChatDraftChange(sourceWidgetId?: string) {
|
|
2444
2627
|
const widgetId = sourceWidgetId ?? selectedWidgetId;
|
|
2445
2628
|
if (suppressChatDraftSync || !widgetId) return;
|
|
@@ -6138,6 +6321,9 @@
|
|
|
6138
6321
|
|
|
6139
6322
|
// debugMode — current ON/OFF state. User can still toggle when the UI is available.
|
|
6140
6323
|
let debugMode = debugModeAvailable;
|
|
6324
|
+
/** Mobile embedded sketch: Canvas | Chat tabs (both panes stay mounted; CSS hides the inactive one). */
|
|
6325
|
+
let embeddedSketchMobileTab: EmbeddedSketchMobileTab = 'canvas';
|
|
6326
|
+
$: embeddedSketchShell = embedded && !canvasAdvancedFeatures;
|
|
6141
6327
|
if (debugModeAvailable && typeof window !== 'undefined') {
|
|
6142
6328
|
try {
|
|
6143
6329
|
const storedDebugMode = creatorStorage.getItem('widgetic:site-debug-on');
|
|
@@ -6359,6 +6545,45 @@
|
|
|
6359
6545
|
*/
|
|
6360
6546
|
let singleWidgetChromeReady = false;
|
|
6361
6547
|
|
|
6548
|
+
/**
|
|
6549
|
+
* Lets the bottom bars appear once the canvas component is up and the canvas has been read.
|
|
6550
|
+
* `handleCanvasReady` does it for a canvas whose id was already known when the canvas component came up.
|
|
6551
|
+
* A canvas whose id is resolved afterwards (the person's latest canvas, the one remembered from the last
|
|
6552
|
+
* visit, or the blank one made for a person who has none) is read or made by other code, so that ends here
|
|
6553
|
+
* too: without it neither bar ever appeared on such a canvas, and the person had no tools and no selector.
|
|
6554
|
+
*/
|
|
6555
|
+
function releaseSingleWidgetChrome(): void {
|
|
6556
|
+
if (singleWidgetChromeReady || !canvasComponentReady || !isCanvasStateLoaded) return;
|
|
6557
|
+
singleWidgetChromeReady = true;
|
|
6558
|
+
console.log('[CreatorApp] Bottom bars released after the canvas was read', { canvasId, primaryId: canvasPrimaryWidgetId });
|
|
6559
|
+
}
|
|
6560
|
+
|
|
6561
|
+
// Whichever code made the canvas known, a canvas that is up, read, and has its primary widget gets its bar.
|
|
6562
|
+
$: if (!singleWidgetChromeReady && canvasComponentReady && isCanvasStateLoaded && !!(canvasPrimaryWidgetId || '').trim()) {
|
|
6563
|
+
releaseSingleWidgetChrome();
|
|
6564
|
+
}
|
|
6565
|
+
|
|
6566
|
+
/**
|
|
6567
|
+
* A net under all of the above: no way of loading a canvas may leave the person without bars for good.
|
|
6568
|
+
* Once the canvas is up and read, the bars come at the latest after this wait, even if none of the places that
|
|
6569
|
+
* release them ran. The person may then see the drawing tools first and the selector a moment later, as every
|
|
6570
|
+
* version before the bars waited for the widget showed them.
|
|
6571
|
+
*/
|
|
6572
|
+
const SINGLE_WIDGET_CHROME_FAILSAFE_MS = 2500;
|
|
6573
|
+
let singleWidgetChromeFailsafeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
6574
|
+
|
|
6575
|
+
function armSingleWidgetChromeFailsafe(): void {
|
|
6576
|
+
if (singleWidgetChromeFailsafeTimer) return;
|
|
6577
|
+
singleWidgetChromeFailsafeTimer = setTimeout(() => {
|
|
6578
|
+
singleWidgetChromeFailsafeTimer = null;
|
|
6579
|
+
if (singleWidgetChromeReady) return;
|
|
6580
|
+
console.warn('[CreatorApp] Bottom bars released by the failsafe: no step of loading the canvas released them');
|
|
6581
|
+
releaseSingleWidgetChrome();
|
|
6582
|
+
}, SINGLE_WIDGET_CHROME_FAILSAFE_MS);
|
|
6583
|
+
}
|
|
6584
|
+
|
|
6585
|
+
$: if (!singleWidgetChromeReady && canvasComponentReady && isCanvasStateLoaded) armSingleWidgetChromeFailsafe();
|
|
6586
|
+
|
|
6362
6587
|
function primaryWidgetHasGeneratedCode(): boolean {
|
|
6363
6588
|
if (!canvasPrimaryWidgetId || isDraftConvertId(canvasPrimaryWidgetId)) return false;
|
|
6364
6589
|
const panel = getPanelState(canvasPrimaryWidgetId);
|
|
@@ -7021,6 +7246,9 @@
|
|
|
7021
7246
|
followedGenerationWidgetIds.add(widgetId);
|
|
7022
7247
|
generationOperationByWidgetId.set(widgetId, operationId);
|
|
7023
7248
|
generatingWidgetIds = { ...generatingWidgetIds, [widgetId]: true };
|
|
7249
|
+
clearGenerationStream(widgetId);
|
|
7250
|
+
clearGenerationThinking(widgetId);
|
|
7251
|
+
clearGenerationPlan(widgetId);
|
|
7024
7252
|
noteCodegenActive(true);
|
|
7025
7253
|
let endedOperation: OperationSnapshot | null = null;
|
|
7026
7254
|
try {
|
|
@@ -7593,6 +7821,7 @@
|
|
|
7593
7821
|
setTimeout(() => applyPrimarySelectionOnCanvas(primaryId), 80);
|
|
7594
7822
|
});
|
|
7595
7823
|
}
|
|
7824
|
+
releaseSingleWidgetChrome();
|
|
7596
7825
|
return;
|
|
7597
7826
|
}
|
|
7598
7827
|
}
|
|
@@ -7619,6 +7848,7 @@
|
|
|
7619
7848
|
setTimeout(() => applyPrimarySelectionOnCanvas(primaryId), 80);
|
|
7620
7849
|
});
|
|
7621
7850
|
}
|
|
7851
|
+
releaseSingleWidgetChrome();
|
|
7622
7852
|
} catch (error) {
|
|
7623
7853
|
console.error('Widget Creator: Load canvases error:', error);
|
|
7624
7854
|
const defaultError = $t('creator.canvas.failedToLoadCanvases');
|
|
@@ -8032,6 +8262,8 @@
|
|
|
8032
8262
|
canvasRef?.onClearAllObjects();
|
|
8033
8263
|
lastSavedCanvasObjectCount = 0;
|
|
8034
8264
|
markCanvasStateLoaded();
|
|
8265
|
+
// The canvas is empty: no widget to wait for.
|
|
8266
|
+
releaseSingleWidgetChrome();
|
|
8035
8267
|
// console.log('[WidgetCreator] New canvas ready:', createdId);
|
|
8036
8268
|
return createdId;
|
|
8037
8269
|
}
|
|
@@ -8071,6 +8303,8 @@
|
|
|
8071
8303
|
} finally {
|
|
8072
8304
|
markCanvasStateLoaded();
|
|
8073
8305
|
isLoadingWidgets = false;
|
|
8306
|
+
// A blank canvas has no widget to wait for: the person gets the drawing tools.
|
|
8307
|
+
releaseSingleWidgetChrome();
|
|
8074
8308
|
}
|
|
8075
8309
|
})();
|
|
8076
8310
|
return blankCanvasEnsurePromise;
|
|
@@ -8081,6 +8315,7 @@
|
|
|
8081
8315
|
// console.log('[CreatorApp] bootstrapEmbeddedNewWidget already ran — skip');
|
|
8082
8316
|
isLoadingWidgets = false;
|
|
8083
8317
|
markCanvasStateLoaded();
|
|
8318
|
+
releaseSingleWidgetChrome();
|
|
8084
8319
|
return;
|
|
8085
8320
|
}
|
|
8086
8321
|
didForceCreateNewWidget = true;
|
|
@@ -8102,6 +8337,8 @@
|
|
|
8102
8337
|
lastSavedCanvasObjectCount = 0;
|
|
8103
8338
|
markCanvasStateLoaded();
|
|
8104
8339
|
isLoadingWidgets = false;
|
|
8340
|
+
// A new widget starts on an empty canvas: nothing to wait for, so the drawing tools come at once.
|
|
8341
|
+
releaseSingleWidgetChrome();
|
|
8105
8342
|
setTimeout(() => {
|
|
8106
8343
|
ignoreIncomingCanvasLoads = false;
|
|
8107
8344
|
// console.log('[CreatorApp] New-widget canvas lock released');
|
|
@@ -10332,6 +10569,9 @@
|
|
|
10332
10569
|
chatMethods = methods;
|
|
10333
10570
|
restoreChatDraftFromStorage();
|
|
10334
10571
|
}
|
|
10572
|
+
if (pendingSketchGeneratePrefill || (embedded && !canvasAdvancedFeatures)) {
|
|
10573
|
+
maybeSyncSketchGeneratePrefill(ownerWidgetId);
|
|
10574
|
+
}
|
|
10335
10575
|
// console.log('[Chat] Chat ready for widget', ownerWidgetId?.substring(0, 8), 'methods exposed');
|
|
10336
10576
|
|
|
10337
10577
|
// A console helper of Widgetic's own pages; a partner's page gets no globals from the creator.
|
|
@@ -11221,6 +11461,9 @@ Requirements:
|
|
|
11221
11461
|
generationOperationByWidgetId.delete(generationWidgetId);
|
|
11222
11462
|
|
|
11223
11463
|
generatingWidgetIds = { ...generatingWidgetIds, [generationWidgetId]: true };
|
|
11464
|
+
clearGenerationStream(generationWidgetId);
|
|
11465
|
+
clearGenerationThinking(generationWidgetId);
|
|
11466
|
+
clearGenerationPlan(generationWidgetId);
|
|
11224
11467
|
// The preview address does not change between builds. Without this, the next build
|
|
11225
11468
|
// is treated as the one already on the shape, and the shape keeps the previous document.
|
|
11226
11469
|
lastRunningPreviewKey = '';
|
|
@@ -11476,6 +11719,10 @@ Requirements:
|
|
|
11476
11719
|
});
|
|
11477
11720
|
// Stopped, or replaced, while the request was being prepared: no job is started for a run nobody waits for
|
|
11478
11721
|
if (signal.aborted) return;
|
|
11722
|
+
// PLAN UI (metadata.plan): do not send `clientCapabilities` here yet. Shopify/editor-session
|
|
11723
|
+
// `POST /agent/code/generate` rejects any body key outside `EDITOR_SESSION_CREATOR_WRITABLE_FIELDS.codeGenerate`
|
|
11724
|
+
// (`editorSessionSurfaces.ts`); `clientCapabilities` is not on that list until the gateway owner adds it.
|
|
11725
|
+
// Once it is listed and plan policy is switched on, add e.g. `clientCapabilities: { plan: true }` beside the fields below.
|
|
11479
11726
|
// The generated client types this call as void and drops the 202 body.
|
|
11480
11727
|
// Read the raw JSON so operationId and the intent-gate payload survive.
|
|
11481
11728
|
const accepted = await agentClient.generateCodeRaw({
|
|
@@ -12073,6 +12320,10 @@ Requirements:
|
|
|
12073
12320
|
);
|
|
12074
12321
|
}
|
|
12075
12322
|
|
|
12323
|
+
if (generationWidgetId && completedCommitSha) {
|
|
12324
|
+
hideSketchOnBoardForWidget(generationWidgetId);
|
|
12325
|
+
}
|
|
12326
|
+
|
|
12076
12327
|
if (isFocusedPanel) {
|
|
12077
12328
|
liveDesignValues = {};
|
|
12078
12329
|
liveContentValues = {};
|
|
@@ -12946,6 +13197,14 @@ Requirements:
|
|
|
12946
13197
|
mountUploadAbortController?.abort();
|
|
12947
13198
|
mountUploadAbortController = null;
|
|
12948
13199
|
clearCanvasLoadFailsafe();
|
|
13200
|
+
if (singleWidgetChromeFailsafeTimer) {
|
|
13201
|
+
clearTimeout(singleWidgetChromeFailsafeTimer);
|
|
13202
|
+
singleWidgetChromeFailsafeTimer = null;
|
|
13203
|
+
}
|
|
13204
|
+
if (sketchPrefillDirtyTimer != null) {
|
|
13205
|
+
clearTimeout(sketchPrefillDirtyTimer);
|
|
13206
|
+
sketchPrefillDirtyTimer = null;
|
|
13207
|
+
}
|
|
12949
13208
|
if (tokenCheckInterval) clearInterval(tokenCheckInterval);
|
|
12950
13209
|
if (tokenDisplayInterval) clearInterval(tokenDisplayInterval);
|
|
12951
13210
|
if (hydrationSafetyTimeout) clearTimeout(hydrationSafetyTimeout);
|
|
@@ -13341,11 +13600,16 @@ Requirements:
|
|
|
13341
13600
|
// reaches the API from the watchdog. Ordinary progress does not.
|
|
13342
13601
|
}
|
|
13343
13602
|
|
|
13344
|
-
function
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
|
|
13348
|
-
|
|
13603
|
+
function readCodegenStreamTailFromOp(op: OperationStatus): string {
|
|
13604
|
+
return readGenerationStreamTail(op.metadata as Record<string, unknown> | undefined);
|
|
13605
|
+
}
|
|
13606
|
+
|
|
13607
|
+
function readCodegenThinkingTailFromOp(op: OperationStatus): string {
|
|
13608
|
+
return readThinkingTail(op.metadata as Record<string, unknown> | undefined);
|
|
13609
|
+
}
|
|
13610
|
+
|
|
13611
|
+
function readCodegenPlanFromOp(op: OperationStatus): GenerationPlanWire | null | undefined {
|
|
13612
|
+
return readPlanFromMetadata(op.metadata as Record<string, unknown> | undefined);
|
|
13349
13613
|
}
|
|
13350
13614
|
|
|
13351
13615
|
function holdPublishForGeneration(widgetId: string): void {
|
|
@@ -13392,6 +13656,7 @@ Requirements:
|
|
|
13392
13656
|
}
|
|
13393
13657
|
delete codegenStatusPendingLine[widgetId];
|
|
13394
13658
|
delete codegenStreamPending[widgetId];
|
|
13659
|
+
delete codegenThinkingPending[widgetId];
|
|
13395
13660
|
if (codegenChatStatusTimers[widgetId]) {
|
|
13396
13661
|
clearTimeout(codegenChatStatusTimers[widgetId]);
|
|
13397
13662
|
delete codegenChatStatusTimers[widgetId];
|
|
@@ -13434,10 +13699,20 @@ Requirements:
|
|
|
13434
13699
|
const status = String(op.status || '').toLowerCase();
|
|
13435
13700
|
if (status === 'completed' || status === 'failed' || status === 'cancelled') {
|
|
13436
13701
|
delete codegenStreamPending[widgetId];
|
|
13702
|
+
delete codegenThinkingPending[widgetId];
|
|
13703
|
+
delete codegenPlanPending[widgetId];
|
|
13437
13704
|
clearGenerationStream(widgetId);
|
|
13705
|
+
clearGenerationThinking(widgetId);
|
|
13706
|
+
clearGenerationPlan(widgetId);
|
|
13438
13707
|
scheduleCodegenStatusPush(widgetId, line);
|
|
13439
13708
|
} else {
|
|
13440
|
-
scheduleCodegenStatusPush(
|
|
13709
|
+
scheduleCodegenStatusPush(
|
|
13710
|
+
widgetId,
|
|
13711
|
+
line,
|
|
13712
|
+
readCodegenStreamTailFromOp(op),
|
|
13713
|
+
readCodegenThinkingTailFromOp(op),
|
|
13714
|
+
readCodegenPlanFromOp(op),
|
|
13715
|
+
);
|
|
13441
13716
|
}
|
|
13442
13717
|
}
|
|
13443
13718
|
scheduleCodegenChatStatusPush(widgetId, line);
|
|
@@ -13447,6 +13722,9 @@ Requirements:
|
|
|
13447
13722
|
const codegenStatusTimers: Record<string, ReturnType<typeof setTimeout>> = {};
|
|
13448
13723
|
const codegenStatusPendingLine: Record<string, string> = {};
|
|
13449
13724
|
const codegenStreamPending: Record<string, string> = {};
|
|
13725
|
+
const codegenThinkingPending: Record<string, string> = {};
|
|
13726
|
+
type CodegenPlanPending = { kind: 'clear' } | { kind: 'set'; plan: GenerationPlanWire };
|
|
13727
|
+
const codegenPlanPending: Record<string, CodegenPlanPending> = {};
|
|
13450
13728
|
const codegenChatStatusTimers: Record<string, ReturnType<typeof setTimeout>> = {};
|
|
13451
13729
|
const codegenChatStatusPendingLine: Record<string, string> = {};
|
|
13452
13730
|
|
|
@@ -13457,21 +13735,56 @@ Requirements:
|
|
|
13457
13735
|
generationStreamByWidgetId = next;
|
|
13458
13736
|
}
|
|
13459
13737
|
|
|
13738
|
+
function clearGenerationThinking(widgetId: string): void {
|
|
13739
|
+
if (!generationThinkingByWidgetId[widgetId]) return;
|
|
13740
|
+
const next = { ...generationThinkingByWidgetId };
|
|
13741
|
+
delete next[widgetId];
|
|
13742
|
+
generationThinkingByWidgetId = next;
|
|
13743
|
+
}
|
|
13744
|
+
|
|
13745
|
+
function clearGenerationPlan(widgetId: string): void {
|
|
13746
|
+
if (!generationPlanByWidgetId[widgetId]) return;
|
|
13747
|
+
const next = { ...generationPlanByWidgetId };
|
|
13748
|
+
delete next[widgetId];
|
|
13749
|
+
generationPlanByWidgetId = next;
|
|
13750
|
+
}
|
|
13751
|
+
|
|
13460
13752
|
/** At most one panel status write per widget per interval; trailing line always lands. */
|
|
13461
|
-
function scheduleCodegenStatusPush(
|
|
13753
|
+
function scheduleCodegenStatusPush(
|
|
13754
|
+
widgetId: string,
|
|
13755
|
+
line: string,
|
|
13756
|
+
streamTail = '',
|
|
13757
|
+
thinkingTail = '',
|
|
13758
|
+
plan?: GenerationPlanWire | null,
|
|
13759
|
+
): void {
|
|
13462
13760
|
codegenStatusPendingLine[widgetId] = line;
|
|
13463
13761
|
if (streamTail) codegenStreamPending[widgetId] = streamTail;
|
|
13762
|
+
if (thinkingTail) codegenThinkingPending[widgetId] = thinkingTail;
|
|
13763
|
+
if (plan !== undefined) {
|
|
13764
|
+
codegenPlanPending[widgetId] = plan === null ? { kind: 'clear' } : { kind: 'set', plan };
|
|
13765
|
+
}
|
|
13464
13766
|
if (codegenStatusTimers[widgetId]) return;
|
|
13465
13767
|
codegenStatusTimers[widgetId] = setTimeout(() => {
|
|
13466
13768
|
delete codegenStatusTimers[widgetId];
|
|
13467
13769
|
const pending = codegenStatusPendingLine[widgetId];
|
|
13468
13770
|
const pendingTail = codegenStreamPending[widgetId];
|
|
13771
|
+
const pendingThinking = codegenThinkingPending[widgetId];
|
|
13772
|
+
const pendingPlan = codegenPlanPending[widgetId];
|
|
13469
13773
|
delete codegenStatusPendingLine[widgetId];
|
|
13470
13774
|
delete codegenStreamPending[widgetId];
|
|
13775
|
+
delete codegenThinkingPending[widgetId];
|
|
13776
|
+
delete codegenPlanPending[widgetId];
|
|
13471
13777
|
if (pending && !previewReadyAnnouncedByWidgetId[widgetId]) patchCodegenUiState(widgetId, { generateCodeStatus: pending });
|
|
13472
13778
|
if (pendingTail && pendingTail !== generationStreamByWidgetId[widgetId]) {
|
|
13473
13779
|
generationStreamByWidgetId = { ...generationStreamByWidgetId, [widgetId]: pendingTail };
|
|
13474
13780
|
}
|
|
13781
|
+
if (pendingThinking && pendingThinking !== generationThinkingByWidgetId[widgetId]) {
|
|
13782
|
+
generationThinkingByWidgetId = { ...generationThinkingByWidgetId, [widgetId]: pendingThinking };
|
|
13783
|
+
}
|
|
13784
|
+
if (pendingPlan?.kind === 'clear') clearGenerationPlan(widgetId);
|
|
13785
|
+
else if (pendingPlan?.kind === 'set') {
|
|
13786
|
+
generationPlanByWidgetId = { ...generationPlanByWidgetId, [widgetId]: pendingPlan.plan };
|
|
13787
|
+
}
|
|
13475
13788
|
}, CODEGEN_STATUS_THROTTLE_MS);
|
|
13476
13789
|
}
|
|
13477
13790
|
|
|
@@ -13698,6 +14011,14 @@ Requirements:
|
|
|
13698
14011
|
let widgetPanelSnapshots: Record<string, WidgetPanelSnapshot> = {};
|
|
13699
14012
|
/** Bumped on every panel snapshot write so {#each} panels re-read display state. */
|
|
13700
14013
|
let panelDisplayRevision = 0;
|
|
14014
|
+
/** Mirrors WidgetDetails `showRuntimeConsole` for the docked chat header icon. */
|
|
14015
|
+
let panelConsoleOpenByWidgetId: Record<string, boolean> = {};
|
|
14016
|
+
|
|
14017
|
+
function toggleDockedChatConsole(panelWidgetId: string, panelInstanceKey: string) {
|
|
14018
|
+
widgetDetailsRefs[panelInstanceKey]?.toggleRuntimeConsole?.();
|
|
14019
|
+
const open = widgetDetailsRefs[panelInstanceKey]?.isRuntimeConsoleOpen?.() ?? false;
|
|
14020
|
+
panelConsoleOpenByWidgetId = { ...panelConsoleOpenByWidgetId, [panelWidgetId]: open };
|
|
14021
|
+
}
|
|
13701
14022
|
/** Bumped on rename so shape chrome / host title re-read widget names. */
|
|
13702
14023
|
let widgetNamesRevision = 0;
|
|
13703
14024
|
const schemaLoadInFlight = new Set<string>();
|
|
@@ -14249,6 +14570,16 @@ Requirements:
|
|
|
14249
14570
|
if (current && current !== liveId && current !== 'live') return;
|
|
14250
14571
|
const versionId = `v:${newestDraft}`;
|
|
14251
14572
|
selectVersionInDropdowns(widgetId, versionId);
|
|
14573
|
+
const draftRecord = getShapePublishHistory(widgetId).find((row) => Number(row.version) === newestDraft);
|
|
14574
|
+
const draftCommit = draftRecord?.commitSha ?? draftRecord?.commit_sha ?? null;
|
|
14575
|
+
if (!draftCommit) {
|
|
14576
|
+
// A version row with no commit has no build. Asking /preview for it is a 404.
|
|
14577
|
+
console.log('[VersionPreview] Newest draft has no build yet', {
|
|
14578
|
+
widgetId: widgetId.substring(0, 8),
|
|
14579
|
+
versionId,
|
|
14580
|
+
});
|
|
14581
|
+
return;
|
|
14582
|
+
}
|
|
14252
14583
|
shapePreviewSourceByWidgetId = {
|
|
14253
14584
|
...shapePreviewSourceByWidgetId,
|
|
14254
14585
|
[widgetId]: versionId,
|
|
@@ -14762,7 +15093,6 @@ Requirements:
|
|
|
14762
15093
|
let versionLabelsByWidgetId: Record<string, Record<string, string>> = {};
|
|
14763
15094
|
let versionPromptLabelsByWidgetId: Record<string, Record<string, string>> = {};
|
|
14764
15095
|
let versionTimelineByWidgetId: Record<string, Array<{ version: number; sha: string; prompt: string }>> = {};
|
|
14765
|
-
let viewingVersionByWidgetId: Record<string, number | null> = {};
|
|
14766
15096
|
const emptyVersionLabels: Record<string, string> = {};
|
|
14767
15097
|
const emptyVersionTimeline: Array<{ version: number; sha: string; prompt: string }> = [];
|
|
14768
15098
|
$: {
|
|
@@ -14776,13 +15106,11 @@ Requirements:
|
|
|
14776
15106
|
const nextLabels: Record<string, Record<string, string>> = {};
|
|
14777
15107
|
const nextPrompts: Record<string, Record<string, string>> = {};
|
|
14778
15108
|
const nextTimeline: Record<string, Array<{ version: number; sha: string; prompt: string }>> = {};
|
|
14779
|
-
const nextViewing: Record<string, number | null> = {};
|
|
14780
15109
|
for (const widgetId of openWidgetPanelIds) {
|
|
14781
15110
|
nextHeads[widgetId] = resolveViewingCommitShaForPanel(widgetId);
|
|
14782
15111
|
nextLabels[widgetId] = buildVersionLabelsForPanel(widgetId);
|
|
14783
15112
|
nextPrompts[widgetId] = buildVersionPromptLabelsForPanel(widgetId);
|
|
14784
15113
|
nextTimeline[widgetId] = buildVersionTimelineForPanel(widgetId);
|
|
14785
|
-
nextViewing[widgetId] = viewingVersionNumberForPanel(widgetId);
|
|
14786
15114
|
}
|
|
14787
15115
|
// A new object with the same contents still counts as a change and makes the
|
|
14788
15116
|
// chat rebuild every turn. That rebuild was running again on each progress tick.
|
|
@@ -14790,7 +15118,6 @@ Requirements:
|
|
|
14790
15118
|
if (JSON.stringify(versionLabelsByWidgetId) !== JSON.stringify(nextLabels)) versionLabelsByWidgetId = nextLabels;
|
|
14791
15119
|
if (JSON.stringify(versionPromptLabelsByWidgetId) !== JSON.stringify(nextPrompts)) versionPromptLabelsByWidgetId = nextPrompts;
|
|
14792
15120
|
if (JSON.stringify(versionTimelineByWidgetId) !== JSON.stringify(nextTimeline)) versionTimelineByWidgetId = nextTimeline;
|
|
14793
|
-
if (JSON.stringify(viewingVersionByWidgetId) !== JSON.stringify(nextViewing)) viewingVersionByWidgetId = nextViewing;
|
|
14794
15121
|
}
|
|
14795
15122
|
|
|
14796
15123
|
/** Commit shas are keyed on 7 chars — that is what the chat summaries carry. */
|
|
@@ -14855,13 +15182,6 @@ Requirements:
|
|
|
14855
15182
|
return labels;
|
|
14856
15183
|
}
|
|
14857
15184
|
|
|
14858
|
-
function viewingVersionNumberForPanel(widgetId: string): number | null {
|
|
14859
|
-
const selected = resolveWidgetShapeVersionSelectedId(widgetId);
|
|
14860
|
-
if (!selected?.startsWith('v:')) return null;
|
|
14861
|
-
const version = parseInt(selected.slice(2), 10);
|
|
14862
|
-
return Number.isFinite(version) ? version : null;
|
|
14863
|
-
}
|
|
14864
|
-
|
|
14865
15185
|
function syncWidgetShapeLivePreviews(): void {
|
|
14866
15186
|
// This runs once per canvas frame while a shape moves. A call limit here
|
|
14867
15187
|
// left the live iframe behind the shape.
|
|
@@ -16195,6 +16515,7 @@ Requirements:
|
|
|
16195
16515
|
*/
|
|
16196
16516
|
function notifyPublishComplete(publishedWidgetId: string, publishedVersion: number | undefined): void {
|
|
16197
16517
|
if (!embedded || !onPublishComplete) return;
|
|
16518
|
+
hideSketchOnBoardForWidget(publishedWidgetId);
|
|
16198
16519
|
void (async () => {
|
|
16199
16520
|
await Promise.race([
|
|
16200
16521
|
handleRefreshScreenshot(publishedWidgetId, { quiet: true }).catch((error) => {
|
|
@@ -17586,7 +17907,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17586
17907
|
|
|
17587
17908
|
/** Simple canvas: one chat, always. The draft id stands in until the first Send creates the widget. */
|
|
17588
17909
|
async function ensureSimpleCanvasChat(): Promise<void> {
|
|
17589
|
-
if (!embedded || canvasAdvancedFeatures || !canvasComponentReady) return;
|
|
17910
|
+
if (!embedded || canvasAdvancedFeatures || !canvasComponentReady || !hasValidToken || !conversationsClient) return;
|
|
17590
17911
|
if (finalizingDraftConversions.size > 0) return;
|
|
17591
17912
|
const primaryId = (canvasPrimaryWidgetId || '').trim();
|
|
17592
17913
|
// The canvas JSON is loaded before the primary widget is known. Opening the draft chat in that gap
|
|
@@ -17610,7 +17931,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17610
17931
|
}
|
|
17611
17932
|
}
|
|
17612
17933
|
|
|
17613
|
-
$: if (
|
|
17934
|
+
$: if (
|
|
17935
|
+
hasValidToken &&
|
|
17936
|
+
embedded &&
|
|
17937
|
+
!canvasAdvancedFeatures &&
|
|
17938
|
+
canvasComponentReady &&
|
|
17939
|
+
isCanvasStateLoaded &&
|
|
17940
|
+
(singleWidgetChromeReady || !!(canvasPrimaryWidgetId || '').trim())
|
|
17941
|
+
) {
|
|
17614
17942
|
void ensureSimpleCanvasChat();
|
|
17615
17943
|
}
|
|
17616
17944
|
|
|
@@ -18073,6 +18401,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18073
18401
|
|
|
18074
18402
|
lastSavedCanvasObjectCount = objectCount;
|
|
18075
18403
|
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, String(objectCount)); } catch {}
|
|
18404
|
+
noteDrawnObjectCount(countDrawnCanvasObjectsInJson(json));
|
|
18405
|
+
maybeSyncSketchGeneratePrefill();
|
|
18076
18406
|
emitCreatorSaveState(false);
|
|
18077
18407
|
|
|
18078
18408
|
// Save to durable L1 fallback (always, even with 0 objects for legitimate clears)
|
|
@@ -18253,6 +18583,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18253
18583
|
promptLoadedForWidgetId = draftId;
|
|
18254
18584
|
pendingChatDraftText = CONVERT_PROMPT;
|
|
18255
18585
|
chatDraftRestoredForWidgetId = null;
|
|
18586
|
+
pendingSketchGeneratePrefill = false;
|
|
18587
|
+
sketchPrefillApplied = true;
|
|
18256
18588
|
savePromptForWidget(draftId);
|
|
18257
18589
|
const panelChat = getChatMethodsForWidget(draftId);
|
|
18258
18590
|
if (panelChat) {
|
|
@@ -18516,10 +18848,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18516
18848
|
promptLoadedForWidgetId = widgetId;
|
|
18517
18849
|
pendingChatDraftText = '';
|
|
18518
18850
|
|
|
18851
|
+
// No "Widget created" toast: the chat already shows the build starting, so the person sees it there.
|
|
18519
18852
|
authStatus = 'Widget created from design.';
|
|
18520
|
-
showToast('success', $t('creator.widget.widgetCreated'), {
|
|
18521
|
-
description: $t('creator.codegen.isReadyGenerationStarted', { name: newWidget.name || widgetName })
|
|
18522
|
-
});
|
|
18523
18853
|
return widgetId;
|
|
18524
18854
|
} catch (error) {
|
|
18525
18855
|
console.error('[WidgetCreator] finalizeDraftConversion error:', error);
|
|
@@ -18544,6 +18874,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18544
18874
|
*/
|
|
18545
18875
|
async function lockSimpleCanvasToOneWidget(primaryId: string | null): Promise<void> {
|
|
18546
18876
|
if (!embedded || multipleWidgetsAllowed || !canvasRef || !primaryId) return;
|
|
18877
|
+
if (widgetBuiltForSketchHiding(primaryId)) {
|
|
18878
|
+
hideSketchOnBoardForWidget(primaryId);
|
|
18879
|
+
}
|
|
18547
18880
|
const removed = canvasRef.keepOnlyWidgetShape?.(primaryId) ?? 0;
|
|
18548
18881
|
const linked = canvasRef.getLinkedWidgetIds?.() ?? new Set<string>();
|
|
18549
18882
|
let placed = false;
|
|
@@ -19231,7 +19564,29 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
19231
19564
|
|
|
19232
19565
|
|
|
19233
19566
|
<!-- Widgetic Canvas Editor - Full width background (lazy-loaded) -->
|
|
19234
|
-
<div
|
|
19567
|
+
<div
|
|
19568
|
+
class="wc-canvas-area flex-1 min-h-0 min-w-0 relative {embeddedSketchShell
|
|
19569
|
+
? 'flex flex-col lg:pe-[450px] max-lg:pe-0'
|
|
19570
|
+
: embedded && !canvasAdvancedFeatures
|
|
19571
|
+
? 'pe-[450px]'
|
|
19572
|
+
: ''}"
|
|
19573
|
+
>
|
|
19574
|
+
<EmbeddedSketchViewportShell
|
|
19575
|
+
{embedded}
|
|
19576
|
+
sketchShell={embeddedSketchShell}
|
|
19577
|
+
bind:mobileTab={embeddedSketchMobileTab}
|
|
19578
|
+
tabCanvasLabel={$t('creator.embedded.tabCanvas')}
|
|
19579
|
+
tabChatLabel={$t('creator.livePreviews.chat')}
|
|
19580
|
+
>
|
|
19581
|
+
{#snippet children()}
|
|
19582
|
+
<div
|
|
19583
|
+
class="embedded-sketch-canvas-stage flex-1 min-h-0 relative min-w-0 {embeddedSketchShell
|
|
19584
|
+
? 'max-lg:shrink-0 max-lg:basis-[58%] max-lg:min-h-0 max-md:absolute max-md:inset-0 max-md:z-0 max-md:basis-auto'
|
|
19585
|
+
: ''} {embeddedSketchShell && embeddedSketchMobileTab !== 'canvas'
|
|
19586
|
+
? 'max-md:pointer-events-none max-md:opacity-0 max-md:[visibility:hidden]'
|
|
19587
|
+
: ''}"
|
|
19588
|
+
aria-hidden={embeddedSketchShell && embeddedSketchMobileTab !== 'canvas' ? 'true' : undefined}
|
|
19589
|
+
>
|
|
19235
19590
|
<!-- Embedded: Debug toggle lives in site AppHeader (avoids overlapping Props Panel). -->
|
|
19236
19591
|
{#if canvasApiLoadError || canvasShapesMissingWarning}
|
|
19237
19592
|
<div class="canvas-state-warning-ct absolute top-3 left-1/2 -translate-x-1/2 z-30 max-w-lg w-[calc(100%-2rem)] pointer-events-auto">
|
|
@@ -19281,7 +19636,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
19281
19636
|
onConvertToWidget={handleConvertToWidget}
|
|
19282
19637
|
onRecognizeStroke={handleRecognizeStroke}
|
|
19283
19638
|
onWidgetImageClick={handleWidgetImageClick}
|
|
19284
|
-
onCanvasDirty={() =>
|
|
19639
|
+
onCanvasDirty={() => {
|
|
19640
|
+
emitCreatorSaveState(true);
|
|
19641
|
+
scheduleSketchPrefillFromCanvasDirty();
|
|
19642
|
+
}}
|
|
19285
19643
|
onWidgetShapeDuplicated={handleWidgetShapeDuplicated}
|
|
19286
19644
|
onWidgetShapeDeleting={handleWidgetShapeDeleting}
|
|
19287
19645
|
onWidgetRename={handleWidgetRename}
|
|
@@ -19338,7 +19696,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
19338
19696
|
</div>
|
|
19339
19697
|
|
|
19340
19698
|
<!-- FLOATING PANELS OVERLAY (pointer-events-none container, each panel is pointer-events-auto) -->
|
|
19341
|
-
<div
|
|
19699
|
+
<div
|
|
19700
|
+
class="floating-panels-overlay z-2003 pointer-events-none {embeddedSketchShell
|
|
19701
|
+
? 'max-lg:relative max-lg:inset-auto max-lg:flex max-lg:flex-1 max-lg:min-h-0 max-lg:basis-[42%] max-lg:shrink-0 max-lg:w-full max-md:absolute max-md:inset-0 max-md:z-[1] max-md:basis-auto lg:absolute lg:inset-0'
|
|
19702
|
+
: 'absolute inset-0'} {embeddedSketchShell && embeddedSketchMobileTab !== 'chat'
|
|
19703
|
+
? 'max-md:pointer-events-none max-md:opacity-0 max-md:[visibility:hidden]'
|
|
19704
|
+
: ''}"
|
|
19705
|
+
aria-hidden={embeddedSketchShell && embeddedSketchMobileTab !== 'chat' ? 'true' : undefined}
|
|
19706
|
+
>
|
|
19342
19707
|
|
|
19343
19708
|
<!-- W3: live iframe + drag bar on WidgetShapes (iframe interactive; body drag locked) -->
|
|
19344
19709
|
<WidgetShapeLivePreviews
|
|
@@ -20194,7 +20559,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20194
20559
|
{/if}
|
|
20195
20560
|
</svelte:fragment>
|
|
20196
20561
|
<svelte:fragment slot="code-generation-models">
|
|
20562
|
+
<!-- The debug model list stays inside `{#if debugMode}`: the i18n source guard reads that test to leave debug words in English. -->
|
|
20197
20563
|
{#if debugMode}
|
|
20564
|
+
{#if !(!canvasAdvancedFeatures && embedded)}
|
|
20198
20565
|
<div class="generation-chat-sticky-header shrink-0 z-20 bg-white border-b border-gray-200">
|
|
20199
20566
|
<!-- svelte-ignore a11y_label_has_associated_control -->
|
|
20200
20567
|
<div class="generation-models-header flex items-center justify-end gap-2 px-2 py-1.5 bg-gray-50">
|
|
@@ -20217,6 +20584,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20217
20584
|
</div>
|
|
20218
20585
|
</div>
|
|
20219
20586
|
{/if}
|
|
20587
|
+
{/if}
|
|
20220
20588
|
</svelte:fragment>
|
|
20221
20589
|
|
|
20222
20590
|
<svelte:fragment slot="code-generation-status">
|
|
@@ -20374,7 +20742,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20374
20742
|
bind:language={widgetLanguage}
|
|
20375
20743
|
/>
|
|
20376
20744
|
{/snippet}
|
|
20377
|
-
|
|
20745
|
+
<!-- Svelte 5: `{@const}` must be the direct child of a block; this wrapper exists only for dockedChatPanel and composerModelOptions. -->
|
|
20746
|
+
{#if true}
|
|
20747
|
+
{@const dockedChatPanel = embedded && !canvasAdvancedFeatures}
|
|
20748
|
+
{@const composerModelOptions = debugMode
|
|
20749
|
+
? availableModels.map((model) => ({ id: model.id, label: model.name }))
|
|
20750
|
+
: []}
|
|
20751
|
+
<Chat class="code-generation-chat h-full w-full max-w-full rounded-none border-0"
|
|
20378
20752
|
locale={locale}
|
|
20379
20753
|
messages={chatMessages}
|
|
20380
20754
|
storedLineLabel={(line) => conversationLineLabel(line, $t)}
|
|
@@ -20385,7 +20759,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20385
20759
|
onMessagesResize={(deltaPx) => handleChatMessagesResize(panelWidgetId, deltaPx)}
|
|
20386
20760
|
showLogs={debugMode}
|
|
20387
20761
|
showHeader={false}
|
|
20762
|
+
showPanelHeader={dockedChatPanel}
|
|
20763
|
+
showConsoleControl={dockedChatPanel && debugMode}
|
|
20764
|
+
consoleOpen={!!panelConsoleOpenByWidgetId[panelWidgetId]}
|
|
20765
|
+
onToggleConsole={dockedChatPanel && debugMode ? () => toggleDockedChatConsole(panelWidgetId, panelInstanceKey) : undefined}
|
|
20388
20766
|
showDescriptionHeader={false}
|
|
20767
|
+
composerModels={composerModelOptions}
|
|
20768
|
+
selectedComposerModelId={selectedModelId}
|
|
20769
|
+
onSelectComposerModel={handleModelSelect}
|
|
20389
20770
|
context={{
|
|
20390
20771
|
id: panelWidgetId,
|
|
20391
20772
|
type: ContextType.FRAME,
|
|
@@ -20394,7 +20775,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20394
20775
|
}}
|
|
20395
20776
|
config={{
|
|
20396
20777
|
features: {
|
|
20397
|
-
screenshot:
|
|
20778
|
+
screenshot: false,
|
|
20398
20779
|
screenRecording: false,
|
|
20399
20780
|
voiceTranscription: false,
|
|
20400
20781
|
fileUpload: true,
|
|
@@ -20412,7 +20793,6 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20412
20793
|
versionLabelByCommitSha={versionLabelsByWidgetId[panelWidgetId] ?? emptyVersionLabels}
|
|
20413
20794
|
versionLabelByPrompt={versionPromptLabelsByWidgetId[panelWidgetId] ?? emptyVersionLabels}
|
|
20414
20795
|
versionTimeline={versionTimelineByWidgetId[panelWidgetId] ?? emptyVersionTimeline}
|
|
20415
|
-
viewingVersion={viewingVersionByWidgetId[panelWidgetId] ?? null}
|
|
20416
20796
|
showSelector={false}
|
|
20417
20797
|
isSelectorActive={!!selectorEnabledByWidgetId[panelWidgetId]}
|
|
20418
20798
|
selectedElements={selectedElementsByWidgetId[panelWidgetId] ?? []}
|
|
@@ -20423,7 +20803,6 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20423
20803
|
onRetryMessage={(content) => handleChatRetryMessage(content, panelWidgetId)}
|
|
20424
20804
|
onUpgradePlans={openUpgradePlans}
|
|
20425
20805
|
onUploadChatFile={handleChatUploadFile}
|
|
20426
|
-
onTakeScreenshot={() => handleChatScreenshot(panelWidgetId)}
|
|
20427
20806
|
isCompleted={!!conversationCompletedByWidgetId[panelWidgetId]}
|
|
20428
20807
|
onCompletionToggle={(detail) => handleChatCompletionToggle(panelWidgetId, detail)}
|
|
20429
20808
|
onLoadConversations={handleLoadConversations}
|
|
@@ -20444,6 +20823,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20444
20823
|
onConversationChange={(conversationId) => handleChatConversationChange(conversationId, panelWidgetId)}
|
|
20445
20824
|
isGenerating={!!generatingWidgetIds[panelWidgetId] && !previewUnblockedByWidgetId[panelWidgetId]}
|
|
20446
20825
|
generationStream={generationStreamByWidgetId[panelWidgetId] || ''}
|
|
20826
|
+
generationThinking={generationThinkingByWidgetId[panelWidgetId] || ''}
|
|
20827
|
+
generationPlan={generationPlanByWidgetId[panelWidgetId] ?? null}
|
|
20447
20828
|
onStopGeneration={() => {
|
|
20448
20829
|
if (!isPanelFocused) focusWidgetPanel(panelWidgetId);
|
|
20449
20830
|
// Stop belongs to the panel it was pressed in: the other panels' generations go on
|
|
@@ -20453,6 +20834,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20453
20834
|
// console.log('[Chat] Stats update:', { messageCount, firstMessage });
|
|
20454
20835
|
}}
|
|
20455
20836
|
/>
|
|
20837
|
+
{/if}
|
|
20456
20838
|
</div>
|
|
20457
20839
|
{/key}
|
|
20458
20840
|
|
|
@@ -20882,6 +21264,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
20882
21264
|
{/if}
|
|
20883
21265
|
|
|
20884
21266
|
</div> <!-- end of floating-panels-overlay -->
|
|
21267
|
+
{/snippet}
|
|
21268
|
+
</EmbeddedSketchViewportShell>
|
|
21269
|
+
</div> <!-- end of wc-canvas-area -->
|
|
20885
21270
|
{/if} <!-- end of logged in section (canvas + main panel) -->
|
|
20886
21271
|
</div> <!-- end of widget-creator-root-page-ct -->
|
|
20887
21272
|
|