@widgetic/creator 0.4.17 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CreatorApp.svelte +118 -13
- package/package.json +3 -3
package/dist/CreatorApp.svelte
CHANGED
|
@@ -4991,15 +4991,42 @@
|
|
|
4991
4991
|
}
|
|
4992
4992
|
}
|
|
4993
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
|
+
|
|
4994
5019
|
/** Push composition overlay to a specific panel preview iframe. */
|
|
4995
5020
|
function applyPanelCompositionToPreview(widgetId: string): void {
|
|
4996
5021
|
const panelRef = getWidgetDetailsRef(widgetId);
|
|
4997
|
-
if (!panelRef) return;
|
|
4998
5022
|
const step = widgetId === focusedPanelWidgetId ? widgetDetailsStep : 'create';
|
|
4999
5023
|
if (step === 'create') {
|
|
5000
|
-
//
|
|
5024
|
+
// Create shows the generated defaults, not a saved composition.
|
|
5025
|
+
// The slides still have to reach both preview iframes.
|
|
5026
|
+
postContentItemsToPreviewFrames(widgetId);
|
|
5001
5027
|
return;
|
|
5002
5028
|
}
|
|
5029
|
+
if (!panelRef) return;
|
|
5003
5030
|
const ps = getPanelDisplayState(widgetId);
|
|
5004
5031
|
if (Object.keys(ps.liveDesignValues).length > 0) {
|
|
5005
5032
|
panelRef.sendMessageToPreview({ type: 'widgetic:update', design: flattenDesignValuesForPreview(ps.liveDesignValues as Record<string, unknown>) });
|
|
@@ -5008,10 +5035,12 @@
|
|
|
5008
5035
|
panelRef.sendMessageToPreview({ type: 'widgetic:update', content: ps.liveContentValues });
|
|
5009
5036
|
}
|
|
5010
5037
|
if (ps.liveContentItems.length > 0) {
|
|
5011
|
-
|
|
5038
|
+
const contentItemsMessage = {
|
|
5012
5039
|
type: 'widgetic:update',
|
|
5013
5040
|
contentItems: flattenContentItemsForPreview(ps.liveContentItems),
|
|
5014
|
-
}
|
|
5041
|
+
};
|
|
5042
|
+
panelRef.sendMessageToPreview(contentItemsMessage);
|
|
5043
|
+
resolveLiveWidgetShapeIframe(widgetId)?.contentWindow?.postMessage(contentItemsMessage, '*');
|
|
5015
5044
|
}
|
|
5016
5045
|
}
|
|
5017
5046
|
|
|
@@ -6500,7 +6529,7 @@
|
|
|
6500
6529
|
try {
|
|
6501
6530
|
const { [widgetId]: _resolved, ...restResolved } = shapeHistoryResolvedByWidgetId;
|
|
6502
6531
|
shapeHistoryResolvedByWidgetId = restResolved;
|
|
6503
|
-
await loadPublishHistoryForPanel(widgetId, { silent: true });
|
|
6532
|
+
await loadPublishHistoryForPanel(widgetId, { silent: true, fresh: true });
|
|
6504
6533
|
void loadWidgetSchemas(widgetId, { force: true });
|
|
6505
6534
|
|
|
6506
6535
|
const panelRef = getWidgetDetailsRef(widgetId);
|
|
@@ -6660,6 +6689,17 @@
|
|
|
6660
6689
|
return read;
|
|
6661
6690
|
}
|
|
6662
6691
|
|
|
6692
|
+
/**
|
|
6693
|
+
* A new canvas row is written once, with no content, so its update time is its creation time. Rows without both
|
|
6694
|
+
* times are not judged here (the caller keeps retrying, as before).
|
|
6695
|
+
*/
|
|
6696
|
+
function canvasRecordWasNeverSaved(record: Record<string, any> | null): boolean {
|
|
6697
|
+
const createdAt = Date.parse(record?.createdAt ?? record?.created_at ?? '');
|
|
6698
|
+
const updatedAt = Date.parse(record?.updatedAt ?? record?.updated_at ?? '');
|
|
6699
|
+
if (Number.isNaN(createdAt) || Number.isNaN(updatedAt)) return false;
|
|
6700
|
+
return updatedAt - createdAt < 1000;
|
|
6701
|
+
}
|
|
6702
|
+
|
|
6663
6703
|
/** The site header shows the canvas name; it reads it from here instead of asking the API again. */
|
|
6664
6704
|
function announceCanvasName(targetCanvasId: string, record: Record<string, any> | null): void {
|
|
6665
6705
|
const name = String(record?.persistenceKey || record?.persistence_key || '').trim();
|
|
@@ -7892,6 +7932,25 @@
|
|
|
7892
7932
|
|
|
7893
7933
|
if (missingIds.length === 0) return;
|
|
7894
7934
|
|
|
7935
|
+
// Both start paths reach here together once the shared widget list arrives; the same ids are fetched once.
|
|
7936
|
+
const mergeKey = `${resolveHostCanvasId() ?? ''}:${[...missingIds].sort().join(',')}`;
|
|
7937
|
+
if (linkedWidgetsMerge?.key === mergeKey) {
|
|
7938
|
+
await linkedWidgetsMerge.done;
|
|
7939
|
+
return;
|
|
7940
|
+
}
|
|
7941
|
+
const done = fetchAndMergeLinkedWidgets(missingIds);
|
|
7942
|
+
linkedWidgetsMerge = { key: mergeKey, done };
|
|
7943
|
+
try {
|
|
7944
|
+
await done;
|
|
7945
|
+
} finally {
|
|
7946
|
+
if (linkedWidgetsMerge?.done === done) linkedWidgetsMerge = null;
|
|
7947
|
+
}
|
|
7948
|
+
}
|
|
7949
|
+
|
|
7950
|
+
let linkedWidgetsMerge: { key: string; done: Promise<void> } | null = null;
|
|
7951
|
+
|
|
7952
|
+
async function fetchAndMergeLinkedWidgets(missingIds: string[]): Promise<void> {
|
|
7953
|
+
if (!widgetsClient) return;
|
|
7895
7954
|
// Scope merge to THIS canvas: a shape can linger on several canvases (legacy canvas
|
|
7896
7955
|
// duplication), but a widget belongs to exactly one. Merging foreign widgets is what
|
|
7897
7956
|
// made another canvas's widgets show up in this canvas's list/picker.
|
|
@@ -10884,7 +10943,7 @@ Requirements:
|
|
|
10884
10943
|
// Start the history request on this turn, before any timer. A stall in
|
|
10885
10944
|
// the timer then still shows up in the API log as this request.
|
|
10886
10945
|
if (generationWidgetId) {
|
|
10887
|
-
void loadPublishHistoryForPanel(generationWidgetId, { silent: true });
|
|
10946
|
+
void loadPublishHistoryForPanel(generationWidgetId, { silent: true, fresh: true });
|
|
10888
10947
|
}
|
|
10889
10948
|
setTimeout(() => {
|
|
10890
10949
|
setTimeout(() => {
|
|
@@ -10958,7 +11017,7 @@ Requirements:
|
|
|
10958
11017
|
const alignWidgetId = generationWidgetId;
|
|
10959
11018
|
const alignCommitSha = completedCommitSha;
|
|
10960
11019
|
const alignGeneratedVersion = (attempt: number) => {
|
|
10961
|
-
void loadPublishHistoryForPanel(alignWidgetId, { silent: true }).then(() => {
|
|
11020
|
+
void loadPublishHistoryForPanel(alignWidgetId, { silent: true, fresh: true }).then(() => {
|
|
10962
11021
|
// The refetch is authoritative, but a snapshot that raced the
|
|
10963
11022
|
// row's title (or an API row still missing it) gets the
|
|
10964
11023
|
// operation's label — the guard inside keeps a user rename.
|
|
@@ -11544,7 +11603,7 @@ Requirements:
|
|
|
11544
11603
|
// Creator always opens on the step the user/URL requested.
|
|
11545
11604
|
}
|
|
11546
11605
|
|
|
11547
|
-
void loadPublishHistoryForPanel(widgetId, { silent: true });
|
|
11606
|
+
void loadPublishHistoryForPanel(widgetId, { silent: true, fresh: true });
|
|
11548
11607
|
}
|
|
11549
11608
|
|
|
11550
11609
|
/**
|
|
@@ -11707,7 +11766,7 @@ Requirements:
|
|
|
11707
11766
|
publishedPanelRef?.invalidatePublishedArtifactCache?.();
|
|
11708
11767
|
await publishedPanelRef?.refreshPreview({ withRetry: true });
|
|
11709
11768
|
scheduleListThumbnailCapture(capturedWidgetId);
|
|
11710
|
-
await loadPublishHistory();
|
|
11769
|
+
await loadPublishHistory({ fresh: true });
|
|
11711
11770
|
void refreshTrialCounter();
|
|
11712
11771
|
} catch (previewErr) {
|
|
11713
11772
|
// The version is already live. A preview reload must not be reported as a failed publish.
|
|
@@ -11765,6 +11824,23 @@ Requirements:
|
|
|
11765
11824
|
|
|
11766
11825
|
let lastHarnessChatLine = '';
|
|
11767
11826
|
|
|
11827
|
+
// The canvas shape iframe loads on its own. When it says it is listening,
|
|
11828
|
+
// hand it the slide list. A message sent before that is dropped.
|
|
11829
|
+
onMount(() => {
|
|
11830
|
+
const onShapeWidgetReady = (event: MessageEvent) => {
|
|
11831
|
+
if (event.data?.type !== 'widgetic:ready') return;
|
|
11832
|
+
const searchRoot = getCreatorShadowRoot(creatorRootEl) ?? document;
|
|
11833
|
+
const frames = searchRoot.querySelectorAll('iframe.widget-shape-live-preview-iframe');
|
|
11834
|
+
for (const frame of frames) {
|
|
11835
|
+
if (!(frame instanceof HTMLIFrameElement) || event.source !== frame.contentWindow) continue;
|
|
11836
|
+
const widgetId = frame.dataset.widgetId;
|
|
11837
|
+
if (widgetId) postContentItemsToPreviewFrames(widgetId);
|
|
11838
|
+
}
|
|
11839
|
+
};
|
|
11840
|
+
window.addEventListener('message', onShapeWidgetReady);
|
|
11841
|
+
return () => window.removeEventListener('message', onShapeWidgetReady);
|
|
11842
|
+
});
|
|
11843
|
+
|
|
11768
11844
|
// Restore session on mount with expiration check
|
|
11769
11845
|
onMount(() => {
|
|
11770
11846
|
const googleFontsKey =
|
|
@@ -15115,11 +15191,38 @@ $: if ($dynamicWorkerPreviewStatus.widgetId && $dynamicWorkerPreviewStatus.previ
|
|
|
15115
15191
|
|
|
15116
15192
|
// ===================== Publish History =====================
|
|
15117
15193
|
|
|
15194
|
+
/**
|
|
15195
|
+
* Selection, the panel and the shape badge all ask for the same widget's history while the page opens; a caller that
|
|
15196
|
+
* comes while a read is running waits on it. After a publish or a generation, callers pass `fresh` to read again.
|
|
15197
|
+
*/
|
|
15198
|
+
const publishHistoryReadsInFlight = new Map<string, Promise<void>>();
|
|
15199
|
+
|
|
15118
15200
|
/**
|
|
15119
15201
|
* Loads publish history for a widget panel (background-safe).
|
|
15120
15202
|
*/
|
|
15121
|
-
async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean } = {}) {
|
|
15203
|
+
async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean; fresh?: boolean } = {}) {
|
|
15122
15204
|
if (!widgetId || !$userSession?.jwt) return;
|
|
15205
|
+
const showsLoading = !opts.silent && widgetId === selectedWidgetId;
|
|
15206
|
+
const inFlight = opts.fresh ? undefined : publishHistoryReadsInFlight.get(widgetId);
|
|
15207
|
+
if (inFlight) {
|
|
15208
|
+
if (showsLoading) isLoadingHistory = true;
|
|
15209
|
+
try {
|
|
15210
|
+
await inFlight;
|
|
15211
|
+
} finally {
|
|
15212
|
+
if (showsLoading) isLoadingHistory = false;
|
|
15213
|
+
}
|
|
15214
|
+
return;
|
|
15215
|
+
}
|
|
15216
|
+
const read = readPublishHistoryForPanel(widgetId, opts);
|
|
15217
|
+
publishHistoryReadsInFlight.set(widgetId, read);
|
|
15218
|
+
try {
|
|
15219
|
+
await read;
|
|
15220
|
+
} finally {
|
|
15221
|
+
if (publishHistoryReadsInFlight.get(widgetId) === read) publishHistoryReadsInFlight.delete(widgetId);
|
|
15222
|
+
}
|
|
15223
|
+
}
|
|
15224
|
+
|
|
15225
|
+
async function readPublishHistoryForPanel(widgetId: string, opts: { silent?: boolean } = {}) {
|
|
15123
15226
|
|
|
15124
15227
|
if (!opts.silent && widgetId === selectedWidgetId) {
|
|
15125
15228
|
isLoadingHistory = true;
|
|
@@ -15185,7 +15288,7 @@ async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boo
|
|
|
15185
15288
|
* Loads publish history for the selected widget from the API.
|
|
15186
15289
|
* Called when the user expands the history panel, or silently on widget select.
|
|
15187
15290
|
*/
|
|
15188
|
-
async function loadPublishHistory(opts: { silent?: boolean } = {}) {
|
|
15291
|
+
async function loadPublishHistory(opts: { silent?: boolean; fresh?: boolean } = {}) {
|
|
15189
15292
|
if (!selectedWidgetId || !$userSession?.jwt) return;
|
|
15190
15293
|
await loadPublishHistoryForPanel(selectedWidgetId, opts);
|
|
15191
15294
|
}
|
|
@@ -15351,7 +15454,7 @@ function togglePublishHistory(triggerEl?: HTMLElement | null) {
|
|
|
15351
15454
|
|
|
15352
15455
|
/** Refresh history after a new publish */
|
|
15353
15456
|
$: if (lastPublishedVersion !== null && isHistoryOpen) {
|
|
15354
|
-
loadPublishHistory();
|
|
15457
|
+
loadPublishHistory({ fresh: true });
|
|
15355
15458
|
}
|
|
15356
15459
|
|
|
15357
15460
|
|
|
@@ -16411,6 +16514,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16411
16514
|
}
|
|
16412
16515
|
canvasContent = canvasRecord?.canvasContent ?? canvasRecord?.canvas_content ?? null;
|
|
16413
16516
|
if (canvasContent) break;
|
|
16517
|
+
// A canvas that was never saved is empty for certain; waiting for content would take seconds.
|
|
16518
|
+
if (canvasRecordWasNeverSaved(canvasRecord)) break;
|
|
16414
16519
|
console.log('[CanvasDebug] getCanvas returned no canvasContent, retry', attempt + 1);
|
|
16415
16520
|
} catch (getErr) {
|
|
16416
16521
|
console.warn('[CanvasDebug] getCanvas failed, retry', attempt + 1, getErr);
|
|
@@ -17785,7 +17890,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17785
17890
|
}
|
|
17786
17891
|
widgetDetails?.closeWidgetDetails();
|
|
17787
17892
|
}}
|
|
17788
|
-
panZoomPosition="
|
|
17893
|
+
panZoomPosition="TL"
|
|
17789
17894
|
showSaveButton={true}
|
|
17790
17895
|
autosaveDelayMs={import.meta.env.DEV ? 15000 : 5000}
|
|
17791
17896
|
suspendAutosave={suspendCanvasAutosave}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/creator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
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",
|