@widgetic/creator 0.3.79 → 0.3.81
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 +121 -13
- package/package.json +1 -1
package/dist/CreatorApp.svelte
CHANGED
|
@@ -3619,6 +3619,38 @@
|
|
|
3619
3619
|
});
|
|
3620
3620
|
}
|
|
3621
3621
|
|
|
3622
|
+
/** Widget id baked into a CDN path, when the path has one. */
|
|
3623
|
+
function widgetIdFromJsPath(jsPath: string | null | undefined): string | null {
|
|
3624
|
+
if (!jsPath) return null;
|
|
3625
|
+
return (jsPath.match(/\/widgets\/([^/]+)\//i) || [])[1] || null;
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
/** Turn a stored js/html path into the HTML file the iframe can load. */
|
|
3629
|
+
function htmlUrlFromJsPath(jsPath: string): string {
|
|
3630
|
+
const cdnBase = publishedCdnBase();
|
|
3631
|
+
const trimmed = jsPath.replace(/\/+$/, '');
|
|
3632
|
+
let resolved = trimmed
|
|
3633
|
+
.replace(/\/widget\.js$/i, '/widget.html')
|
|
3634
|
+
.replace(/\.js$/i, '.html');
|
|
3635
|
+
if (!/\.html$/i.test(resolved)) {
|
|
3636
|
+
resolved = `${resolved}/widget.html`;
|
|
3637
|
+
}
|
|
3638
|
+
if (resolved.startsWith('/')) {
|
|
3639
|
+
resolved = `${cdnBase}${resolved}`;
|
|
3640
|
+
}
|
|
3641
|
+
return resolved;
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
/**
|
|
3645
|
+
* A preset copy keeps the source file so the preview can load, but that path
|
|
3646
|
+
* names the source widget. It is not this widget's version history.
|
|
3647
|
+
*/
|
|
3648
|
+
function borrowedPresetArtifactUrl(widgetId: string, jsPath: string | null | undefined): string | null {
|
|
3649
|
+
const ownerId = widgetIdFromJsPath(jsPath);
|
|
3650
|
+
if (!jsPath || !ownerId || ownerId === widgetId) return null;
|
|
3651
|
+
return htmlUrlFromJsPath(jsPath);
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3622
3654
|
/** Resolve published artifact URL — CDN path by live version; js_path only when it matches that version. */
|
|
3623
3655
|
function resolvePublishedWidgetUrl(
|
|
3624
3656
|
widgetId: string,
|
|
@@ -3631,19 +3663,14 @@
|
|
|
3631
3663
|
const versionedUrl = `${cdnBase}/widgets/${widgetId}/v${version}/widget.html`;
|
|
3632
3664
|
|
|
3633
3665
|
if (jsPath) {
|
|
3634
|
-
const
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
if (
|
|
3639
|
-
resolved = `${resolved}/widget.html`;
|
|
3640
|
-
}
|
|
3641
|
-
if (resolved.startsWith('/')) {
|
|
3642
|
-
resolved = `${cdnBase}${resolved}`;
|
|
3643
|
-
}
|
|
3666
|
+
const resolved = htmlUrlFromJsPath(jsPath);
|
|
3667
|
+
const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
|
|
3668
|
+
// The copy has no artifact of its own. Load the source file instead of
|
|
3669
|
+
// inventing /widgets/{newId}/vN/, which 404s on the bucket.
|
|
3670
|
+
if (borrowed) return borrowed;
|
|
3644
3671
|
const jsPathVersionMatch = jsPath.match(/\/v(\d+)(?:\/|$)/);
|
|
3645
3672
|
const jsPathVersion = jsPathVersionMatch ? parseInt(jsPathVersionMatch[1], 10) : null;
|
|
3646
|
-
const jsPathWidgetId = (resolved
|
|
3673
|
+
const jsPathWidgetId = widgetIdFromJsPath(resolved);
|
|
3647
3674
|
const pointsAtOtherWidget = !!(jsPathWidgetId && jsPathWidgetId !== widgetId);
|
|
3648
3675
|
// Only reuse js_path when it already points at this widget + this version.
|
|
3649
3676
|
// `/widgets/` alone used to win and keep Edit on the previous CDN version after publish.
|
|
@@ -7427,6 +7454,19 @@
|
|
|
7427
7454
|
if (!widget) return { kind: 'draft' };
|
|
7428
7455
|
const jsPath = ((widget as { jsPath?: string | null; js_path?: string | null }).jsPath
|
|
7429
7456
|
?? (widget as { js_path?: string | null }).js_path) as string | null;
|
|
7457
|
+
const widgetId = (widget as { id?: string }).id || '';
|
|
7458
|
+
// A preset copy stores the source widget's file. That /vN/ is the source's
|
|
7459
|
+
// history, not a version of this account's widget. Chat starts empty; so do versions.
|
|
7460
|
+
if (borrowedPresetArtifactUrl(widgetId, jsPath)) {
|
|
7461
|
+
if (isWidgetPublishedSummary(widget)) {
|
|
7462
|
+
return {
|
|
7463
|
+
kind: 'published',
|
|
7464
|
+
version: Number((widget as { version?: number }).version),
|
|
7465
|
+
jsPath,
|
|
7466
|
+
};
|
|
7467
|
+
}
|
|
7468
|
+
return { kind: 'draft' };
|
|
7469
|
+
}
|
|
7430
7470
|
// Only trust an explicit CDN/version path — a bare/non-version js_path must NOT
|
|
7431
7471
|
// mark the widget as published (that stuck Publish on "No new version to publish").
|
|
7432
7472
|
if (jsPath) {
|
|
@@ -8514,6 +8554,67 @@
|
|
|
8514
8554
|
}, IDLE_THUMBNAIL_DELAY_MS);
|
|
8515
8555
|
idleThumbnailTimers.set(widgetId, timer);
|
|
8516
8556
|
}
|
|
8557
|
+
/**
|
|
8558
|
+
* Screenshot of whatever the preview is showing now, stored as the list thumbnail.
|
|
8559
|
+
* A published CDN file often has no capture script, so the Worker preview is the fallback.
|
|
8560
|
+
* That fallback still uses the main thread, so publish schedules it after the click returns.
|
|
8561
|
+
*/
|
|
8562
|
+
async function captureListThumbnail(widgetId: string, interactive: boolean): Promise<void> {
|
|
8563
|
+
if (!widgetId || isDraftConvertId(widgetId)) return;
|
|
8564
|
+
if (codegenCaptureBlocked() || generatingWidgetIds[widgetId]) {
|
|
8565
|
+
if (interactive) {
|
|
8566
|
+
showToast('info', 'Preview image waits until generation finishes', { duration: 3000 });
|
|
8567
|
+
}
|
|
8568
|
+
return;
|
|
8569
|
+
}
|
|
8570
|
+
if (interactive) {
|
|
8571
|
+
showToast('info', 'Saving preview image...', { duration: 2500 });
|
|
8572
|
+
}
|
|
8573
|
+
try {
|
|
8574
|
+
const screenshot = await handleChatScreenshot(widgetId, null, false);
|
|
8575
|
+
if (!screenshot) {
|
|
8576
|
+
if (interactive) {
|
|
8577
|
+
showToast('error', 'Could not save the preview image', {
|
|
8578
|
+
description: 'The preview did not return an image. Refresh it, then try again.',
|
|
8579
|
+
duration: 5000,
|
|
8580
|
+
});
|
|
8581
|
+
}
|
|
8582
|
+
return;
|
|
8583
|
+
}
|
|
8584
|
+
canvasRef?.updateWidgetImage(widgetId, screenshot);
|
|
8585
|
+
await persistWidgetListThumbnail(widgetId, screenshot);
|
|
8586
|
+
if (interactive) {
|
|
8587
|
+
showToast('success', 'Preview image saved', { duration: 2000 });
|
|
8588
|
+
} else {
|
|
8589
|
+
console.log('[Chat→Screenshot] List thumbnail saved', widgetId.substring(0, 8));
|
|
8590
|
+
}
|
|
8591
|
+
} catch (error) {
|
|
8592
|
+
console.warn('[Chat→Screenshot] List thumbnail failed', widgetId.substring(0, 8), error);
|
|
8593
|
+
if (interactive) {
|
|
8594
|
+
showToast('error', 'Could not save the preview image', { duration: 4000 });
|
|
8595
|
+
}
|
|
8596
|
+
}
|
|
8597
|
+
}
|
|
8598
|
+
|
|
8599
|
+
const listThumbnailTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
8600
|
+
function scheduleListThumbnailCapture(widgetId: string): void {
|
|
8601
|
+
if (!widgetId) return;
|
|
8602
|
+
const existing = listThumbnailTimers.get(widgetId);
|
|
8603
|
+
if (existing) clearTimeout(existing);
|
|
8604
|
+
const timer = setTimeout(() => {
|
|
8605
|
+
listThumbnailTimers.delete(widgetId);
|
|
8606
|
+
const run = () => {
|
|
8607
|
+
void captureListThumbnail(widgetId, false);
|
|
8608
|
+
};
|
|
8609
|
+
if (typeof requestIdleCallback === 'function') {
|
|
8610
|
+
requestIdleCallback(() => run(), { timeout: 8000 });
|
|
8611
|
+
} else {
|
|
8612
|
+
run();
|
|
8613
|
+
}
|
|
8614
|
+
}, 8000);
|
|
8615
|
+
listThumbnailTimers.set(widgetId, timer);
|
|
8616
|
+
}
|
|
8617
|
+
|
|
8517
8618
|
async function persistIdleWidgetThumbnail(widgetId: string): Promise<void> {
|
|
8518
8619
|
if (codegenCaptureBlocked() || generatingWidgetIds[widgetId]) return;
|
|
8519
8620
|
const iframe = resolveLiveWidgetShapeIframe(widgetId);
|
|
@@ -10290,6 +10391,7 @@ Requirements:
|
|
|
10290
10391
|
console.log('[Publish] Refreshing preview after publish (step:', widgetDetailsStep, ')');
|
|
10291
10392
|
publishedPanelRef?.invalidatePublishedArtifactCache?.();
|
|
10292
10393
|
await publishedPanelRef?.refreshPreview({ withRetry: true });
|
|
10394
|
+
scheduleListThumbnailCapture(capturedWidgetId);
|
|
10293
10395
|
|
|
10294
10396
|
await loadPublishHistory();
|
|
10295
10397
|
void refreshTrialCounter();
|
|
@@ -11382,9 +11484,13 @@ Requirements:
|
|
|
11382
11484
|
}
|
|
11383
11485
|
}
|
|
11384
11486
|
const widget = getWidgetById(widgetId);
|
|
11487
|
+
const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null; js_path?: string | null } | undefined)?.jsPath
|
|
11488
|
+
?? (widget as { js_path?: string | null } | undefined)?.js_path
|
|
11489
|
+
?? null;
|
|
11490
|
+
const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
|
|
11491
|
+
if (borrowed && source !== 'preview') return borrowed;
|
|
11385
11492
|
const version = ps.lastPublishedVersion ?? resolvePublishedVersionFromWidget(widget);
|
|
11386
11493
|
if (version == null) return null;
|
|
11387
|
-
const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null } | undefined)?.jsPath ?? null;
|
|
11388
11494
|
return resolvePublishedWidgetUrl(widgetId, version, jsPath);
|
|
11389
11495
|
}
|
|
11390
11496
|
|
|
@@ -15979,7 +16085,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15979
16085
|
onWidgetShapeDuplicated={handleWidgetShapeDuplicated}
|
|
15980
16086
|
onWidgetShapeDeleting={handleWidgetShapeDeleting}
|
|
15981
16087
|
onWidgetRename={handleWidgetRename}
|
|
15982
|
-
onRefreshScreenshot={
|
|
16088
|
+
onRefreshScreenshot={(widgetId) => {
|
|
16089
|
+
void captureListThumbnail(widgetId, true);
|
|
16090
|
+
}}
|
|
15983
16091
|
onSetPrimaryWidget={handleSetPrimaryWidget}
|
|
15984
16092
|
onAfterRender={syncWidgetShapeLivePreviews}
|
|
15985
16093
|
getWidgetName={getWidgetNameById}
|