@widgetic/creator 0.4.16 → 0.4.18
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
CHANGED
|
@@ -855,7 +855,7 @@
|
|
|
855
855
|
let widgetDetailsOpenTargetId: string | null = null;
|
|
856
856
|
|
|
857
857
|
// Lightweight static imports from canvas (excludes Canvas.svelte — 10K+ lines)
|
|
858
|
-
import { Tooltip } from '@widgetic/canvas/components';
|
|
858
|
+
import { Tooltip, CanvasBoardPlaceholder } from '@widgetic/canvas/components';
|
|
859
859
|
// WidgetConversionPayload lives on the canvas root export (re-exported from
|
|
860
860
|
// ./canvas); the components barrel only carries the input controls. Type-only
|
|
861
861
|
// import, so the 10K-line Canvas.svelte still never loads.
|
|
@@ -881,6 +881,15 @@
|
|
|
881
881
|
type DesignIntentClassification
|
|
882
882
|
} from './utils/designIntentTelemetry';
|
|
883
883
|
|
|
884
|
+
/** Open-time marks (DevTools Performance panel, or `performance.getEntriesByType('mark')`). */
|
|
885
|
+
function markCanvasOpenStep(stepName: string): void {
|
|
886
|
+
try {
|
|
887
|
+
performance.mark(stepName);
|
|
888
|
+
} catch {
|
|
889
|
+
// Marks are diagnostics only.
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
884
893
|
// Eagerly initiate canvas chunk fetching at script evaluation (parallel with DOM parsing)
|
|
885
894
|
const canvasModulePromise = typeof window !== 'undefined' ? import('@widgetic/canvas') : null;
|
|
886
895
|
|
|
@@ -944,6 +953,7 @@
|
|
|
944
953
|
mountUploadAbortController = new AbortController();
|
|
945
954
|
if (canvasModulePromise) {
|
|
946
955
|
const canvasModule = await canvasModulePromise;
|
|
956
|
+
markCanvasOpenStep('creator:canvas-module-loaded');
|
|
947
957
|
// Installed before the canvas mounts so the first save already externalizes
|
|
948
958
|
installCanvasThumbnailStore(canvasModule);
|
|
949
959
|
// The canvas keeps the visitor's saved colors where the creator keeps its own memory: the browser's
|
|
@@ -1009,6 +1019,8 @@
|
|
|
1009
1019
|
import {
|
|
1010
1020
|
saveCanvasState,
|
|
1011
1021
|
readCanvasState,
|
|
1022
|
+
saveCanvasWidgetList,
|
|
1023
|
+
readCanvasWidgetList,
|
|
1012
1024
|
saveActiveGeneration,
|
|
1013
1025
|
readActiveGeneration,
|
|
1014
1026
|
clearActiveGeneration,
|
|
@@ -4979,15 +4991,42 @@
|
|
|
4979
4991
|
}
|
|
4980
4992
|
}
|
|
4981
4993
|
|
|
4994
|
+
/**
|
|
4995
|
+
* The generated widget reads its slides from `contentItems`. On Create, the
|
|
4996
|
+
* composition overlay is skipped, and the canvas shape is a second iframe
|
|
4997
|
+
* that never received those items — so the preview stayed on "No content".
|
|
4998
|
+
*/
|
|
4999
|
+
function postContentItemsToPreviewFrames(widgetId: string): void {
|
|
5000
|
+
if (!widgetId) return;
|
|
5001
|
+
const ps = getPanelDisplayState(widgetId);
|
|
5002
|
+
let items = ps.liveContentItems || [];
|
|
5003
|
+
if (items.length === 0) {
|
|
5004
|
+
const schema = ps.compositionContentSchema;
|
|
5005
|
+
const schemaItems = schema?.contentItems ?? schema?.data?.contentItems;
|
|
5006
|
+
if (Array.isArray(schemaItems) && schemaItems.length > 0) {
|
|
5007
|
+
items = schemaItems;
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
if (!Array.isArray(items) || items.length === 0) return;
|
|
5011
|
+
const message = {
|
|
5012
|
+
type: 'widgetic:update',
|
|
5013
|
+
contentItems: flattenContentItemsForPreview(items),
|
|
5014
|
+
};
|
|
5015
|
+
getWidgetDetailsRef(widgetId)?.sendMessageToPreview(message);
|
|
5016
|
+
resolveLiveWidgetShapeIframe(widgetId)?.contentWindow?.postMessage(message, '*');
|
|
5017
|
+
}
|
|
5018
|
+
|
|
4982
5019
|
/** Push composition overlay to a specific panel preview iframe. */
|
|
4983
5020
|
function applyPanelCompositionToPreview(widgetId: string): void {
|
|
4984
5021
|
const panelRef = getWidgetDetailsRef(widgetId);
|
|
4985
|
-
if (!panelRef) return;
|
|
4986
5022
|
const step = widgetId === focusedPanelWidgetId ? widgetDetailsStep : 'create';
|
|
4987
5023
|
if (step === 'create') {
|
|
4988
|
-
//
|
|
5024
|
+
// Create shows the generated defaults, not a saved composition.
|
|
5025
|
+
// The slides still have to reach both preview iframes.
|
|
5026
|
+
postContentItemsToPreviewFrames(widgetId);
|
|
4989
5027
|
return;
|
|
4990
5028
|
}
|
|
5029
|
+
if (!panelRef) return;
|
|
4991
5030
|
const ps = getPanelDisplayState(widgetId);
|
|
4992
5031
|
if (Object.keys(ps.liveDesignValues).length > 0) {
|
|
4993
5032
|
panelRef.sendMessageToPreview({ type: 'widgetic:update', design: flattenDesignValuesForPreview(ps.liveDesignValues as Record<string, unknown>) });
|
|
@@ -4996,10 +5035,12 @@
|
|
|
4996
5035
|
panelRef.sendMessageToPreview({ type: 'widgetic:update', content: ps.liveContentValues });
|
|
4997
5036
|
}
|
|
4998
5037
|
if (ps.liveContentItems.length > 0) {
|
|
4999
|
-
|
|
5038
|
+
const contentItemsMessage = {
|
|
5000
5039
|
type: 'widgetic:update',
|
|
5001
5040
|
contentItems: flattenContentItemsForPreview(ps.liveContentItems),
|
|
5002
|
-
}
|
|
5041
|
+
};
|
|
5042
|
+
panelRef.sendMessageToPreview(contentItemsMessage);
|
|
5043
|
+
resolveLiveWidgetShapeIframe(widgetId)?.contentWindow?.postMessage(contentItemsMessage, '*');
|
|
5003
5044
|
}
|
|
5004
5045
|
}
|
|
5005
5046
|
|
|
@@ -5835,6 +5876,7 @@
|
|
|
5835
5876
|
id: targetCanvasId,
|
|
5836
5877
|
updateCanvasRequest: { primaryWidgetId: widgetId }
|
|
5837
5878
|
});
|
|
5879
|
+
canvasRecordReads.delete(targetCanvasId);
|
|
5838
5880
|
} catch (err) {
|
|
5839
5881
|
console.warn('[CreatorApp] Failed to save primary_widget_id:', err);
|
|
5840
5882
|
}
|
|
@@ -6487,7 +6529,7 @@
|
|
|
6487
6529
|
try {
|
|
6488
6530
|
const { [widgetId]: _resolved, ...restResolved } = shapeHistoryResolvedByWidgetId;
|
|
6489
6531
|
shapeHistoryResolvedByWidgetId = restResolved;
|
|
6490
|
-
await loadPublishHistoryForPanel(widgetId, { silent: true });
|
|
6532
|
+
await loadPublishHistoryForPanel(widgetId, { silent: true, fresh: true });
|
|
6491
6533
|
void loadWidgetSchemas(widgetId, { force: true });
|
|
6492
6534
|
|
|
6493
6535
|
const panelRef = getWidgetDetailsRef(widgetId);
|
|
@@ -6613,6 +6655,47 @@
|
|
|
6613
6655
|
]);
|
|
6614
6656
|
}
|
|
6615
6657
|
|
|
6658
|
+
/**
|
|
6659
|
+
* One read of a canvas record per open. The JSON load and the primary-widget lookups run from two start paths
|
|
6660
|
+
* (loadCurrentCanvas and handleCanvasReady); each used to read the canvas again. A read is shared for
|
|
6661
|
+
* CANVAS_RECORD_SHARE_MS, then the next caller reads fresh.
|
|
6662
|
+
*/
|
|
6663
|
+
const CANVAS_RECORD_SHARE_MS = 15000;
|
|
6664
|
+
type CanvasRecordRead = { status: number; record: Record<string, any> | null };
|
|
6665
|
+
const canvasRecordReads = new Map<string, { startedAt: number; read: Promise<CanvasRecordRead> }>();
|
|
6666
|
+
|
|
6667
|
+
function forgetCanvasRecordReads(): void {
|
|
6668
|
+
canvasRecordReads.clear();
|
|
6669
|
+
}
|
|
6670
|
+
|
|
6671
|
+
function readCanvasRecord(targetCanvasId: string, options: { fresh?: boolean } = {}): Promise<CanvasRecordRead> {
|
|
6672
|
+
const shared = canvasRecordReads.get(targetCanvasId);
|
|
6673
|
+
if (!options.fresh && shared && Date.now() - shared.startedAt < CANVAS_RECORD_SHARE_MS) return shared.read;
|
|
6674
|
+
const read = (async (): Promise<CanvasRecordRead> => {
|
|
6675
|
+
if (!canvasesClient) throw new Error('Canvases API client is not configured');
|
|
6676
|
+
const response = await withCanvasApiTimeout(canvasesClient.getCanvasRaw({ id: targetCanvasId }), 'getCanvas');
|
|
6677
|
+
// A 304 has no body; the caller keeps what it already painted.
|
|
6678
|
+
if (response.raw.status === 304) return { status: 304, record: null };
|
|
6679
|
+
const body = await response.raw.json();
|
|
6680
|
+
const record = (body?.data || body) ?? null;
|
|
6681
|
+
announceCanvasName(targetCanvasId, record);
|
|
6682
|
+
return { status: response.raw.status, record };
|
|
6683
|
+
})();
|
|
6684
|
+
canvasRecordReads.set(targetCanvasId, { startedAt: Date.now(), read });
|
|
6685
|
+
// A failed read is not shared: the next caller asks again.
|
|
6686
|
+
read.catch(() => {
|
|
6687
|
+
if (canvasRecordReads.get(targetCanvasId)?.read === read) canvasRecordReads.delete(targetCanvasId);
|
|
6688
|
+
});
|
|
6689
|
+
return read;
|
|
6690
|
+
}
|
|
6691
|
+
|
|
6692
|
+
/** The site header shows the canvas name; it reads it from here instead of asking the API again. */
|
|
6693
|
+
function announceCanvasName(targetCanvasId: string, record: Record<string, any> | null): void {
|
|
6694
|
+
const name = String(record?.persistenceKey || record?.persistence_key || '').trim();
|
|
6695
|
+
if (!name) return;
|
|
6696
|
+
announceToSite('widgetic:creator-canvas-name', { canvasId: targetCanvasId, name });
|
|
6697
|
+
}
|
|
6698
|
+
|
|
6616
6699
|
function clearCanvasHydrateRetry() {
|
|
6617
6700
|
if (canvasHydrateRetryTimer) {
|
|
6618
6701
|
clearTimeout(canvasHydrateRetryTimer);
|
|
@@ -6949,8 +7032,8 @@
|
|
|
6949
7032
|
|
|
6950
7033
|
// Reload canvas shapes first, then widget metadata for the new canvas
|
|
6951
7034
|
try {
|
|
6952
|
-
|
|
6953
|
-
|
|
7035
|
+
forgetWidgetListRead();
|
|
7036
|
+
forgetCanvasRecordReads();
|
|
6954
7037
|
const { widgetIds: widgetIdsOnCanvas } = await tryLoadCanvasState();
|
|
6955
7038
|
await syncWidgetsWithCanvas(widgetIdsOnCanvas);
|
|
6956
7039
|
} catch (err) {
|
|
@@ -7430,9 +7513,19 @@
|
|
|
7430
7513
|
deleteCanvasTarget = null;
|
|
7431
7514
|
}
|
|
7432
7515
|
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7516
|
+
/**
|
|
7517
|
+
* The widget list read for the open canvas. Both start paths (loadCurrentCanvas and handleCanvasReady) need it;
|
|
7518
|
+
* they wait on this one read. A refresh, a retry or another canvas forgets it and reads again.
|
|
7519
|
+
*/
|
|
7520
|
+
let widgetListReadCanvasId: string | null = null;
|
|
7521
|
+
let widgetListRead: Promise<boolean> | null = null;
|
|
7522
|
+
|
|
7523
|
+
function forgetWidgetListRead(): void {
|
|
7524
|
+
widgetListReadCanvasId = null;
|
|
7525
|
+
widgetListRead = null;
|
|
7526
|
+
}
|
|
7527
|
+
|
|
7528
|
+
async function loadWidgetsForCanvas(): Promise<void> {
|
|
7436
7529
|
// if no canvas id, return
|
|
7437
7530
|
if (!canvasId) {
|
|
7438
7531
|
// console.log('Widget Creator: loadWidgetsForCanvas: No canvas id, returning');
|
|
@@ -7442,13 +7535,23 @@
|
|
|
7442
7535
|
isLoadingWidgets = false;
|
|
7443
7536
|
return;
|
|
7444
7537
|
}
|
|
7538
|
+
if (widgetListRead && widgetListReadCanvasId === canvasId) {
|
|
7539
|
+
await widgetListRead;
|
|
7540
|
+
return;
|
|
7541
|
+
}
|
|
7542
|
+
const listCanvasId = canvasId;
|
|
7543
|
+
const read = readAndApplyWidgetList(listCanvasId);
|
|
7544
|
+
widgetListReadCanvasId = listCanvasId;
|
|
7545
|
+
widgetListRead = read;
|
|
7546
|
+
const loaded = await read;
|
|
7547
|
+
// A failed read is not kept, so the next caller asks again.
|
|
7548
|
+
if (!loaded && widgetListRead === read) forgetWidgetListRead();
|
|
7549
|
+
}
|
|
7445
7550
|
|
|
7446
|
-
|
|
7447
|
-
// console.log('Widget Creator: loadWidgetsForCanvas:',
|
|
7551
|
+
async function readAndApplyWidgetList(listCanvasId: string): Promise<boolean> {
|
|
7552
|
+
// console.log('Widget Creator: loadWidgetsForCanvas:', listCanvasId);
|
|
7553
|
+
let networkListSettled = false;
|
|
7448
7554
|
try {
|
|
7449
|
-
if (isLoadingWidgetsOnce && lastWidgetsCanvasId === canvasId) return;
|
|
7450
|
-
isLoadingWidgetsOnce = true;
|
|
7451
|
-
lastWidgetsCanvasId = canvasId;
|
|
7452
7555
|
isLoadingWidgets = true;
|
|
7453
7556
|
widgetsError = null;
|
|
7454
7557
|
if (!$userSession?.jwt) {
|
|
@@ -7459,7 +7562,13 @@
|
|
|
7459
7562
|
// which the generated model drops. A refused request or an error answer
|
|
7460
7563
|
// is thrown (see readWidgetList), so the catch below shows it and
|
|
7461
7564
|
// saysCanvasIsMissing can read a 404 in partner mode.
|
|
7462
|
-
|
|
7565
|
+
// The request starts first; the cached list is read beside it and shown only until it answers.
|
|
7566
|
+
const networkListPromise = readWidgetList(listCanvasId);
|
|
7567
|
+
void showCachedWidgetList(listCanvasId, () => networkListSettled);
|
|
7568
|
+
const fetched = await networkListPromise;
|
|
7569
|
+
networkListSettled = true;
|
|
7570
|
+
markCanvasOpenStep('creator:widget-list-ready');
|
|
7571
|
+
saveCanvasWidgetList(listCanvasId, fetched);
|
|
7463
7572
|
|
|
7464
7573
|
const previousById = new Map(
|
|
7465
7574
|
widgets.filter((w) => w.id).map((w) => [w.id as string, w]),
|
|
@@ -7537,6 +7646,7 @@
|
|
|
7537
7646
|
selectedWidgetId = null;
|
|
7538
7647
|
saveSelectedWidgetId(null); // Clear localStorage if no widgets
|
|
7539
7648
|
}
|
|
7649
|
+
return true;
|
|
7540
7650
|
} catch (error) {
|
|
7541
7651
|
console.error('Widget Creator: Failed to load widgets for canvas:', error);
|
|
7542
7652
|
const defaultError = $t('creator.widget.failedToLoadWidgets');
|
|
@@ -7552,9 +7662,34 @@
|
|
|
7552
7662
|
duration: 5000
|
|
7553
7663
|
});
|
|
7554
7664
|
}
|
|
7665
|
+
return false;
|
|
7555
7666
|
} finally {
|
|
7667
|
+
networkListSettled = true;
|
|
7556
7668
|
isLoadingWidgets = false;
|
|
7557
|
-
|
|
7669
|
+
}
|
|
7670
|
+
}
|
|
7671
|
+
|
|
7672
|
+
/**
|
|
7673
|
+
* Second open of a canvas: show the widget list saved last time, so names and
|
|
7674
|
+
* thumbnails on the board do not wait for the network. Needs enableLocalCache.
|
|
7675
|
+
*/
|
|
7676
|
+
async function showCachedWidgetList(listCanvasId: string, hasNetworkSettled: () => boolean): Promise<void> {
|
|
7677
|
+
if (!isLocalCacheEnabled()) return;
|
|
7678
|
+
try {
|
|
7679
|
+
const cachedList = (await readCanvasWidgetList(listCanvasId)) as WidgetSummary[] | null;
|
|
7680
|
+
if (!cachedList?.length || hasNetworkSettled() || canvasId !== listCanvasId) return;
|
|
7681
|
+
// Something already put widgets of this canvas on screen; the network list will replace them.
|
|
7682
|
+
const alreadyShowsThisCanvas = widgets.some(
|
|
7683
|
+
(widget) => widgetCanvasIdOf(widget as { canvasId?: string | null; canvas_id?: string | null }) === listCanvasId,
|
|
7684
|
+
);
|
|
7685
|
+
if (alreadyShowsThisCanvas) return;
|
|
7686
|
+
widgets = sortWidgetSummaries(cachedList);
|
|
7687
|
+
markCanvasOpenStep('creator:widget-list-from-cache');
|
|
7688
|
+
widgetNamesRevision += 1;
|
|
7689
|
+
backfillWidgetShapeMetadata();
|
|
7690
|
+
syncWidgetShapeLivePreviews();
|
|
7691
|
+
} catch (error) {
|
|
7692
|
+
console.warn('[WidgetCreator] Cached widget list could not be read:', error);
|
|
7558
7693
|
}
|
|
7559
7694
|
}
|
|
7560
7695
|
|
|
@@ -7786,6 +7921,25 @@
|
|
|
7786
7921
|
|
|
7787
7922
|
if (missingIds.length === 0) return;
|
|
7788
7923
|
|
|
7924
|
+
// Both start paths reach here together once the shared widget list arrives; the same ids are fetched once.
|
|
7925
|
+
const mergeKey = `${resolveHostCanvasId() ?? ''}:${[...missingIds].sort().join(',')}`;
|
|
7926
|
+
if (linkedWidgetsMerge?.key === mergeKey) {
|
|
7927
|
+
await linkedWidgetsMerge.done;
|
|
7928
|
+
return;
|
|
7929
|
+
}
|
|
7930
|
+
const done = fetchAndMergeLinkedWidgets(missingIds);
|
|
7931
|
+
linkedWidgetsMerge = { key: mergeKey, done };
|
|
7932
|
+
try {
|
|
7933
|
+
await done;
|
|
7934
|
+
} finally {
|
|
7935
|
+
if (linkedWidgetsMerge?.done === done) linkedWidgetsMerge = null;
|
|
7936
|
+
}
|
|
7937
|
+
}
|
|
7938
|
+
|
|
7939
|
+
let linkedWidgetsMerge: { key: string; done: Promise<void> } | null = null;
|
|
7940
|
+
|
|
7941
|
+
async function fetchAndMergeLinkedWidgets(missingIds: string[]): Promise<void> {
|
|
7942
|
+
if (!widgetsClient) return;
|
|
7789
7943
|
// Scope merge to THIS canvas: a shape can linger on several canvases (legacy canvas
|
|
7790
7944
|
// duplication), but a widget belongs to exactly one. Merging foreign widgets is what
|
|
7791
7945
|
// made another canvas's widgets show up in this canvas's list/picker.
|
|
@@ -7986,10 +8140,10 @@
|
|
|
7986
8140
|
async function readPrimaryWidgetIdForCanvas(targetCanvasId: string): Promise<string | null> {
|
|
7987
8141
|
if (!canvasesClient || !targetCanvasId?.trim()) return null;
|
|
7988
8142
|
try {
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
(
|
|
7992
|
-
|
|
8143
|
+
const canvasRead = await readCanvasRecord(targetCanvasId);
|
|
8144
|
+
// 304: nothing new about this canvas; keep the primary already known.
|
|
8145
|
+
if (!canvasRead.record) return canvasPrimaryWidgetId || null;
|
|
8146
|
+
const record = canvasRead.record;
|
|
7993
8147
|
const raw =
|
|
7994
8148
|
(record as { primaryWidgetId?: unknown })?.primaryWidgetId ??
|
|
7995
8149
|
(record as { primary_widget_id?: unknown })?.primary_widget_id ??
|
|
@@ -8219,13 +8373,14 @@
|
|
|
8219
8373
|
|
|
8220
8374
|
function handleRefreshWidgets() {
|
|
8221
8375
|
// console.log('Widget Creator: Refresh widgets clicked');
|
|
8222
|
-
|
|
8223
|
-
isLoadingWidgetsOnce = false;
|
|
8376
|
+
forgetWidgetListRead();
|
|
8224
8377
|
void syncWidgetsWithCanvas();
|
|
8225
8378
|
}
|
|
8226
8379
|
|
|
8227
8380
|
function retryLoadCanvas() {
|
|
8228
8381
|
console.log('Widget Creator: Retry loading canvas');
|
|
8382
|
+
forgetWidgetListRead();
|
|
8383
|
+
forgetCanvasRecordReads();
|
|
8229
8384
|
isLoadingCanvasOnce = false;
|
|
8230
8385
|
isCanvasStateLoaded = false;
|
|
8231
8386
|
canvasHydrateRetryCount = 0;
|
|
@@ -10777,7 +10932,7 @@ Requirements:
|
|
|
10777
10932
|
// Start the history request on this turn, before any timer. A stall in
|
|
10778
10933
|
// the timer then still shows up in the API log as this request.
|
|
10779
10934
|
if (generationWidgetId) {
|
|
10780
|
-
void loadPublishHistoryForPanel(generationWidgetId, { silent: true });
|
|
10935
|
+
void loadPublishHistoryForPanel(generationWidgetId, { silent: true, fresh: true });
|
|
10781
10936
|
}
|
|
10782
10937
|
setTimeout(() => {
|
|
10783
10938
|
setTimeout(() => {
|
|
@@ -10851,7 +11006,7 @@ Requirements:
|
|
|
10851
11006
|
const alignWidgetId = generationWidgetId;
|
|
10852
11007
|
const alignCommitSha = completedCommitSha;
|
|
10853
11008
|
const alignGeneratedVersion = (attempt: number) => {
|
|
10854
|
-
void loadPublishHistoryForPanel(alignWidgetId, { silent: true }).then(() => {
|
|
11009
|
+
void loadPublishHistoryForPanel(alignWidgetId, { silent: true, fresh: true }).then(() => {
|
|
10855
11010
|
// The refetch is authoritative, but a snapshot that raced the
|
|
10856
11011
|
// row's title (or an API row still missing it) gets the
|
|
10857
11012
|
// operation's label — the guard inside keeps a user rename.
|
|
@@ -11437,7 +11592,7 @@ Requirements:
|
|
|
11437
11592
|
// Creator always opens on the step the user/URL requested.
|
|
11438
11593
|
}
|
|
11439
11594
|
|
|
11440
|
-
void loadPublishHistoryForPanel(widgetId, { silent: true });
|
|
11595
|
+
void loadPublishHistoryForPanel(widgetId, { silent: true, fresh: true });
|
|
11441
11596
|
}
|
|
11442
11597
|
|
|
11443
11598
|
/**
|
|
@@ -11600,7 +11755,7 @@ Requirements:
|
|
|
11600
11755
|
publishedPanelRef?.invalidatePublishedArtifactCache?.();
|
|
11601
11756
|
await publishedPanelRef?.refreshPreview({ withRetry: true });
|
|
11602
11757
|
scheduleListThumbnailCapture(capturedWidgetId);
|
|
11603
|
-
await loadPublishHistory();
|
|
11758
|
+
await loadPublishHistory({ fresh: true });
|
|
11604
11759
|
void refreshTrialCounter();
|
|
11605
11760
|
} catch (previewErr) {
|
|
11606
11761
|
// The version is already live. A preview reload must not be reported as a failed publish.
|
|
@@ -11658,6 +11813,23 @@ Requirements:
|
|
|
11658
11813
|
|
|
11659
11814
|
let lastHarnessChatLine = '';
|
|
11660
11815
|
|
|
11816
|
+
// The canvas shape iframe loads on its own. When it says it is listening,
|
|
11817
|
+
// hand it the slide list. A message sent before that is dropped.
|
|
11818
|
+
onMount(() => {
|
|
11819
|
+
const onShapeWidgetReady = (event: MessageEvent) => {
|
|
11820
|
+
if (event.data?.type !== 'widgetic:ready') return;
|
|
11821
|
+
const searchRoot = getCreatorShadowRoot(creatorRootEl) ?? document;
|
|
11822
|
+
const frames = searchRoot.querySelectorAll('iframe.widget-shape-live-preview-iframe');
|
|
11823
|
+
for (const frame of frames) {
|
|
11824
|
+
if (!(frame instanceof HTMLIFrameElement) || event.source !== frame.contentWindow) continue;
|
|
11825
|
+
const widgetId = frame.dataset.widgetId;
|
|
11826
|
+
if (widgetId) postContentItemsToPreviewFrames(widgetId);
|
|
11827
|
+
}
|
|
11828
|
+
};
|
|
11829
|
+
window.addEventListener('message', onShapeWidgetReady);
|
|
11830
|
+
return () => window.removeEventListener('message', onShapeWidgetReady);
|
|
11831
|
+
});
|
|
11832
|
+
|
|
11661
11833
|
// Restore session on mount with expiration check
|
|
11662
11834
|
onMount(() => {
|
|
11663
11835
|
const googleFontsKey =
|
|
@@ -15008,11 +15180,38 @@ $: if ($dynamicWorkerPreviewStatus.widgetId && $dynamicWorkerPreviewStatus.previ
|
|
|
15008
15180
|
|
|
15009
15181
|
// ===================== Publish History =====================
|
|
15010
15182
|
|
|
15183
|
+
/**
|
|
15184
|
+
* Selection, the panel and the shape badge all ask for the same widget's history while the page opens; a caller that
|
|
15185
|
+
* comes while a read is running waits on it. After a publish or a generation, callers pass `fresh` to read again.
|
|
15186
|
+
*/
|
|
15187
|
+
const publishHistoryReadsInFlight = new Map<string, Promise<void>>();
|
|
15188
|
+
|
|
15011
15189
|
/**
|
|
15012
15190
|
* Loads publish history for a widget panel (background-safe).
|
|
15013
15191
|
*/
|
|
15014
|
-
async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean } = {}) {
|
|
15192
|
+
async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean; fresh?: boolean } = {}) {
|
|
15015
15193
|
if (!widgetId || !$userSession?.jwt) return;
|
|
15194
|
+
const showsLoading = !opts.silent && widgetId === selectedWidgetId;
|
|
15195
|
+
const inFlight = opts.fresh ? undefined : publishHistoryReadsInFlight.get(widgetId);
|
|
15196
|
+
if (inFlight) {
|
|
15197
|
+
if (showsLoading) isLoadingHistory = true;
|
|
15198
|
+
try {
|
|
15199
|
+
await inFlight;
|
|
15200
|
+
} finally {
|
|
15201
|
+
if (showsLoading) isLoadingHistory = false;
|
|
15202
|
+
}
|
|
15203
|
+
return;
|
|
15204
|
+
}
|
|
15205
|
+
const read = readPublishHistoryForPanel(widgetId, opts);
|
|
15206
|
+
publishHistoryReadsInFlight.set(widgetId, read);
|
|
15207
|
+
try {
|
|
15208
|
+
await read;
|
|
15209
|
+
} finally {
|
|
15210
|
+
if (publishHistoryReadsInFlight.get(widgetId) === read) publishHistoryReadsInFlight.delete(widgetId);
|
|
15211
|
+
}
|
|
15212
|
+
}
|
|
15213
|
+
|
|
15214
|
+
async function readPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean } = {}) {
|
|
15016
15215
|
|
|
15017
15216
|
if (!opts.silent && widgetId === selectedWidgetId) {
|
|
15018
15217
|
isLoadingHistory = true;
|
|
@@ -15078,7 +15277,7 @@ async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boo
|
|
|
15078
15277
|
* Loads publish history for the selected widget from the API.
|
|
15079
15278
|
* Called when the user expands the history panel, or silently on widget select.
|
|
15080
15279
|
*/
|
|
15081
|
-
async function loadPublishHistory(opts: { silent?: boolean } = {}) {
|
|
15280
|
+
async function loadPublishHistory(opts: { silent?: boolean; fresh?: boolean } = {}) {
|
|
15082
15281
|
if (!selectedWidgetId || !$userSession?.jwt) return;
|
|
15083
15282
|
await loadPublishHistoryForPanel(selectedWidgetId, opts);
|
|
15084
15283
|
}
|
|
@@ -15244,7 +15443,7 @@ function togglePublishHistory(triggerEl?: HTMLElement | null) {
|
|
|
15244
15443
|
|
|
15245
15444
|
/** Refresh history after a new publish */
|
|
15246
15445
|
$: if (lastPublishedVersion !== null && isHistoryOpen) {
|
|
15247
|
-
loadPublishHistory();
|
|
15446
|
+
loadPublishHistory({ fresh: true });
|
|
15248
15447
|
}
|
|
15249
15448
|
|
|
15250
15449
|
|
|
@@ -16094,13 +16293,29 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16094
16293
|
return !!getWidgetById(widgetId);
|
|
16095
16294
|
}
|
|
16096
16295
|
|
|
16296
|
+
/**
|
|
16297
|
+
* The canvas calls onReady from its own mount, before `bind:this` has filled canvasRef.
|
|
16298
|
+
* Loading then would be skipped and wait for the retry timer (~0.9s), so wait for the ref.
|
|
16299
|
+
*/
|
|
16300
|
+
async function waitForCanvasRef(): Promise<boolean> {
|
|
16301
|
+
if (canvasRef) return true;
|
|
16302
|
+
await tick();
|
|
16303
|
+
for (let frame = 0; frame < 3 && !canvasRef; frame++) {
|
|
16304
|
+
await new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
|
|
16305
|
+
}
|
|
16306
|
+
if (!canvasRef) console.warn('[WidgetCreator] Canvas ready, but its ref is still empty');
|
|
16307
|
+
return !!canvasRef;
|
|
16308
|
+
}
|
|
16309
|
+
|
|
16097
16310
|
/**
|
|
16098
16311
|
* Called when WidgeticCanvas is initialized and ready.
|
|
16099
16312
|
* Marks the canvas as ready; actual state loading happens in loadCanvasState()
|
|
16100
16313
|
* which is called after loadCurrentCanvas() resolves canvasId.
|
|
16101
16314
|
*/
|
|
16102
16315
|
async function handleCanvasReady() {
|
|
16316
|
+
markCanvasOpenStep('creator:canvas-ready');
|
|
16103
16317
|
// console.log('[WidgetCreator] Canvas component ready');
|
|
16318
|
+
await waitForCanvasRef();
|
|
16104
16319
|
canvasComponentReady = true;
|
|
16105
16320
|
if (ignoreIncomingCanvasLoads) {
|
|
16106
16321
|
// console.log('[WidgetCreator] Canvas ready — skipping JSON hydrate (new widget)');
|
|
@@ -16155,6 +16370,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16155
16370
|
canvasLoadFailsafeArmedForId = null;
|
|
16156
16371
|
}
|
|
16157
16372
|
function markCanvasStateLoaded() {
|
|
16373
|
+
if (!isCanvasStateLoaded) markCanvasOpenStep('creator:canvas-state-loaded');
|
|
16158
16374
|
isCanvasStateLoaded = true;
|
|
16159
16375
|
canvasHydrateRetryCount = 0;
|
|
16160
16376
|
clearCanvasHydrateRetry();
|
|
@@ -16233,6 +16449,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16233
16449
|
localCachedJson = (await readCanvasState(canvasId)) ?? (() => {
|
|
16234
16450
|
try { return creatorStorage.getItem(getCanvasStorageKey()); } catch { return null; }
|
|
16235
16451
|
})();
|
|
16452
|
+
markCanvasOpenStep(localCachedJson ? 'creator:canvas-cache-hit' : 'creator:canvas-cache-miss');
|
|
16236
16453
|
if (localCachedJson && canvasRef) {
|
|
16237
16454
|
const parsed = JSON.parse(localCachedJson);
|
|
16238
16455
|
const objects = parsed?.canvas?.objects ?? parsed?.objects ?? [];
|
|
@@ -16262,13 +16479,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16262
16479
|
// Another read has already found out there is no such canvas for this visitor.
|
|
16263
16480
|
if (canvasUnavailable) return emptyResult;
|
|
16264
16481
|
try {
|
|
16265
|
-
|
|
16266
|
-
|
|
16267
|
-
'getCanvas',
|
|
16268
|
-
);
|
|
16482
|
+
// The first attempt joins the read a primary-widget lookup may already have started.
|
|
16483
|
+
const canvasRead = await readCanvasRecord(canvasId, { fresh: attempt > 0 });
|
|
16269
16484
|
// A 304 has no body. Parsing it throws, the loader treats that as a
|
|
16270
16485
|
// failed read, and the page asks for the same canvas again.
|
|
16271
|
-
if (
|
|
16486
|
+
if (canvasRead.status === 304) {
|
|
16272
16487
|
markCanvasStateLoaded();
|
|
16273
16488
|
let cachedIds: string[] = [];
|
|
16274
16489
|
if (localCachedJson) {
|
|
@@ -16280,8 +16495,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16280
16495
|
}
|
|
16281
16496
|
return { loaded: true, widgetIds: cachedIds };
|
|
16282
16497
|
}
|
|
16283
|
-
|
|
16284
|
-
const canvasRecord =
|
|
16498
|
+
markCanvasOpenStep('creator:canvas-json-fetched');
|
|
16499
|
+
const canvasRecord = canvasRead.record;
|
|
16285
16500
|
if (loadEpoch !== canvasLoadEpoch || ignoreIncomingCanvasLoads) {
|
|
16286
16501
|
console.log('[CanvasDebug] Ignoring stale getCanvas result', { loadEpoch, canvasLoadEpoch });
|
|
16287
16502
|
return emptyResult;
|
|
@@ -16569,6 +16784,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16569
16784
|
canvasContent: parsedCanvas ?? JSON.parse(json)
|
|
16570
16785
|
}
|
|
16571
16786
|
});
|
|
16787
|
+
canvasRecordReads.delete(canvasId);
|
|
16572
16788
|
if (currentSeq < lastResolvedAutosaveSequence) {
|
|
16573
16789
|
// console.log(
|
|
16574
16790
|
// `[CanvasDebug] Dropped out-of-order autosave response (${currentSeq} < ${lastResolvedAutosaveSequence})`
|
|
@@ -17667,6 +17883,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17667
17883
|
suspendAutosave={suspendCanvasAutosave}
|
|
17668
17884
|
isExternalDataLoading={!isCanvasStateLoaded}
|
|
17669
17885
|
/>
|
|
17886
|
+
{:else}
|
|
17887
|
+
<!-- Empty board while the canvas code downloads; the canvas mounts over the same surface. -->
|
|
17888
|
+
<CanvasBoardPlaceholder class="wc-canvas-placeholder" {locale} messages={canvasMessages} />
|
|
17670
17889
|
{/if}
|
|
17671
17890
|
</div>
|
|
17672
17891
|
|
|
@@ -12,6 +12,8 @@ export declare function readAllWidgetDrafts(): Promise<Record<string, WidgetDraf
|
|
|
12
12
|
export declare function copyWidgetDraft(sourceWidgetId: string, targetWidgetId: string): Promise<void>;
|
|
13
13
|
export declare function saveCanvasState(canvasId: string | null, json: string): void;
|
|
14
14
|
export declare function readCanvasState(canvasId: string | null): Promise<string | null>;
|
|
15
|
+
export declare function saveCanvasWidgetList(canvasId: string, widgetList: unknown[]): void;
|
|
16
|
+
export declare function readCanvasWidgetList(canvasId: string): Promise<unknown[] | null>;
|
|
15
17
|
/** False before an owner is known — nothing can be persisted yet. */
|
|
16
18
|
export declare function canPersistShapeThumbnails(): boolean;
|
|
17
19
|
export declare function saveShapeThumbnail(ref: string, dataUrl: string): void;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { deleteEntity, getCacheOwner, readAllEntitiesForKind, readEntity, writeEntity } from '@widgetic/cache-layer';
|
|
11
11
|
const DRAFT_KIND = 'creatorDrafts';
|
|
12
12
|
const CANVAS_KIND = 'creatorCanvasState';
|
|
13
|
+
const CANVAS_WIDGETS_KIND = 'creatorCanvasWidgets';
|
|
13
14
|
const GENERATION_KIND = 'creatorActiveGeneration';
|
|
14
15
|
const SHAPE_THUMBNAIL_KIND = 'creatorShapeThumbnails';
|
|
15
16
|
function ownerIdOrNull() {
|
|
@@ -70,6 +71,26 @@ export async function readCanvasState(canvasId) {
|
|
|
70
71
|
const record = await readEntity(ownerId, CANVAS_KIND, canvasId ?? 'default');
|
|
71
72
|
return record?.json ?? null;
|
|
72
73
|
}
|
|
74
|
+
// ─── Canvas widget list ──────────────────────────────────────────
|
|
75
|
+
//
|
|
76
|
+
// The last widget list read for a canvas. A second open shows it before the
|
|
77
|
+
// network answers; the network list then replaces it.
|
|
78
|
+
export function saveCanvasWidgetList(canvasId, widgetList) {
|
|
79
|
+
const ownerId = ownerIdOrNull();
|
|
80
|
+
if (!ownerId || !canvasId)
|
|
81
|
+
return;
|
|
82
|
+
// Wrapped in an object: readEntity only hands back object payloads.
|
|
83
|
+
void writeEntity(ownerId, CANVAS_WIDGETS_KIND, canvasId, { widgets: widgetList }).catch((error) => {
|
|
84
|
+
console.warn('[creatorDraftStorage] Failed to persist the canvas widget list:', error);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export async function readCanvasWidgetList(canvasId) {
|
|
88
|
+
const ownerId = ownerIdOrNull();
|
|
89
|
+
if (!ownerId || !canvasId)
|
|
90
|
+
return null;
|
|
91
|
+
const record = await readEntity(ownerId, CANVAS_WIDGETS_KIND, canvasId);
|
|
92
|
+
return Array.isArray(record?.widgets) ? record.widgets : null;
|
|
93
|
+
}
|
|
73
94
|
// ─── Widget shape thumbnails ─────────────────────────────────────
|
|
74
95
|
//
|
|
75
96
|
// Widget screenshots used to be serialized inline in the canvas JSON, which
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/creator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@sveltejs/kit": "^2.20.0",
|
|
8
8
|
"@widgetic/api-sdk": "^1.0.23",
|
|
9
9
|
"@widgetic/cache-layer": "^0.1.2",
|
|
10
|
-
"@widgetic/canvas": "^0.5.
|
|
10
|
+
"@widgetic/canvas": "^0.5.27",
|
|
11
11
|
"@widgetic/chat": "^0.1.17",
|
|
12
12
|
"@widgetic/design-system": "^0.5.15",
|
|
13
13
|
"@widgetic/editor": "^4.0.10",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@types/node": "26.4.0",
|
|
75
75
|
"@widgetic/api-sdk": "^1.0.23",
|
|
76
76
|
"@widgetic/cache-layer": "^0.1.2",
|
|
77
|
-
"@widgetic/canvas": "^0.5.
|
|
77
|
+
"@widgetic/canvas": "^0.5.27",
|
|
78
78
|
"@widgetic/chat": "^0.1.17",
|
|
79
79
|
"@widgetic/design-system": "^0.5.15",
|
|
80
80
|
"@widgetic/dev-tools": "^0.3.0",
|