@widgetic/creator 0.4.2 → 0.4.4

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.
@@ -22,6 +22,7 @@ declare const CreatorApp: $$__sveltets_2_IsomorphicComponent<{
22
22
  initialCompositionId?: CreatorAppProps["initialCompositionId"];
23
23
  initialStep?: CreatorAppProps["initialStep"];
24
24
  forceCreateNewWidget?: CreatorAppProps["forceCreateNewWidget"];
25
+ initialSketchName?: CreatorAppProps["initialSketchName"];
25
26
  apiUrl?: CreatorAppProps["apiUrl"];
26
27
  widgetBuilderUrl?: CreatorAppProps["widgetBuilderUrl"];
27
28
  initialDebugMode?: CreatorAppProps["initialDebugMode"];
@@ -43,7 +44,10 @@ declare const CreatorApp: $$__sveltets_2_IsomorphicComponent<{
43
44
  onCanvasUnavailable?: CreatorAppProps["onCanvasUnavailable"];
44
45
  onCanvasChanged?: CreatorAppProps["onCanvasChanged"];
45
46
  onReady?: CreatorAppProps["onReady"];
46
- /** The page's own media library for the editor's file pickers (see `CreatorAppProps.mediaLibrary`). */ mediaLibrary?: CreatorAppProps["mediaLibrary"];
47
+ /** Partner library for chat/canvas uploads (see `CreatorAppProps.mediaLibrary`). */ mediaLibrary?: CreatorAppProps["mediaLibrary"];
48
+ /** Optional override for PropsEditor file fields (`purpose: 'field'`). */ mediaLibraryForFields?: CreatorAppProps["mediaLibraryForFields"];
49
+ /** Opens the partner's file picker instead of the built-in File Browser (see `CreatorAppProps.pickFile`). */ pickFile?: CreatorAppProps["pickFile"];
50
+ /** Resolves the url stored with a picked file (see `CreatorAppProps.storeFileUrl`). */ storeFileUrl?: CreatorAppProps["storeFileUrl"];
47
51
  /**
48
52
  * The language of everything the creator shows (see `CreatorAppProps.locale` and `CreatorAppProps.messages`). The one flat
49
53
  * `messages` object is split between the creator's own words and the parts it draws: the editor (with its file
@@ -100,7 +100,6 @@
100
100
  </script>
101
101
 
102
102
  <div class="design-quick-edit flex flex-col gap-2 overflow-visible rounded-lg border border-gray-200 bg-white p-3 shadow-sm">
103
- <p class="text-xs leading-relaxed text-gray-600">{spec.summary}</p>
104
103
  {#if detached}
105
104
  <p class="text-[10px] leading-relaxed text-gray-400">
106
105
  {$t('creator.designEdit.shownAsAppliedTheseControls')}
@@ -94,7 +94,7 @@
94
94
  </script>
95
95
 
96
96
  <div
97
- class="version-dropdown-row flex items-center justify-between gap-2 rounded px-2 py-1.5 w-full text-[10px] cursor-pointer {selected ? 'bg-emerald-50 text-emerald-800' : 'text-gray-700 hover:bg-gray-50'}"
97
+ class="version-dropdown-row flex items-center justify-between gap-2 rounded px-2 py-1.5 w-full text-[10px] cursor-pointer {selected ? 'bg-emerald-200 text-emerald-950' : 'text-gray-700 hover:bg-emerald-100'}"
98
98
  role="option"
99
99
  aria-selected={selected}
100
100
  tabindex="0"
@@ -561,12 +561,27 @@
561
561
  }
562
562
  }
563
563
 
564
+ /** Panel preview column is off; the canvas shape holds the live iframe. */
565
+ function detailsPreviewIsMounted(): boolean {
566
+ return SHOW_PANEL_PREVIEW_COLUMN;
567
+ }
568
+
564
569
  function applyPreviewUrlToIframe(
565
570
  url: string | null,
566
571
  cacheBuster?: number,
567
572
  opts: { forceReload?: boolean; skipHydration?: boolean } = {}
568
573
  ) {
569
574
  if (!url) return;
575
+ // Same-origin dev proxy (/__widget_builder__) runs the widget on this page's thread.
576
+ // The shape overlay uses the public Worker URL. Do not boot a second document here.
577
+ if (!detailsPreviewIsMounted()) {
578
+ const fetchUrl = toPreviewFetchUrl(url);
579
+ dynamicWorkerPreviewUrl = fetchUrl;
580
+ directPreviewUrl = toPreviewDisplayUrl(fetchUrl);
581
+ previewLoading = false;
582
+ previewHydrating = false;
583
+ return;
584
+ }
570
585
 
571
586
  const fetchUrl = toPreviewFetchUrl(url);
572
587
  const nextBase = normalizePreviewBaseUrl(fetchUrl);
@@ -688,6 +703,10 @@
688
703
 
689
704
  /** Force iframe remount + cache-bust after Worker rebuild (avoids stale cached document). */
690
705
  async function forceReloadPreviewIframe(url: string): Promise<void> {
706
+ if (!detailsPreviewIsMounted()) {
707
+ applyPreviewUrlToIframe(url, undefined, { forceReload: true });
708
+ return;
709
+ }
691
710
  const fetchUrl = toPreviewFetchUrl(url);
692
711
  previewError = null;
693
712
  previewLoading = true;
@@ -2445,6 +2464,7 @@
2445
2464
  }
2446
2465
 
2447
2466
  function setupPreviewFallbackTimeout(): void {
2467
+ if (!detailsPreviewIsMounted()) return;
2448
2468
  if (previewFallbackHandle) { clearTimeout(previewFallbackHandle); previewFallbackHandle = null; }
2449
2469
  if (previewHealthCheckHandle) { clearInterval(previewHealthCheckHandle); previewHealthCheckHandle = null; }
2450
2470
  previewFallbackHandle = setTimeout(() => {
@@ -2467,7 +2487,7 @@
2467
2487
  previewHealthCheckHandle = setInterval(() => {
2468
2488
  if (!previewLoading && !previewHydrating) { clearPreviewHealthCheck(); return; }
2469
2489
  try {
2470
- const iframe = previewIframe ?? (getCreatorShadowRoot(contentContainerEl) ?? document).querySelector('iframe[title="Widget preview"]') as HTMLIFrameElement;
2490
+ const iframe = previewIframe;
2471
2491
  if (!iframe || !iframeSrc) return;
2472
2492
  if (!previewFullUrlsMatch(iframeSrc, iframe.src)) return;
2473
2493
  if (iframe.contentWindow) {
@@ -3254,9 +3274,10 @@
3254
3274
  lastWsPreviewSignature = signature;
3255
3275
 
3256
3276
  if (isGeneratingCode) {
3277
+ // Leave the URLs unset. The preview template uses them as the iframe src
3278
+ // when iframeSrc is still empty, so a new widget would boot the same-origin
3279
+ // Worker document on this page's thread while the status still says "Saving…".
3257
3280
  pendingWorkerPreviewFromWs = { workerUrl, buildTimeMs, eventTimestamp };
3258
- dynamicWorkerPreviewUrl = fetchUrl;
3259
- directPreviewUrl = toWorkerPreviewDisplayUrl(fetchUrl);
3260
3281
  console.log('[WidgetDetails] Defer Worker iframe remount until codegen finishes');
3261
3282
  return;
3262
3283
  }
@@ -3281,8 +3302,10 @@
3281
3302
  dispatch('widgetReady', { widgetId: selectedWidgetId });
3282
3303
  }
3283
3304
 
3284
- // Worker preview ready via WebSocket event (after codegen / Worker build)
3285
- $: if ($dynamicWorkerPreviewStatus.widgetId === selectedWidgetId && $dynamicWorkerPreviewStatus.previewUrl) {
3305
+ // Worker preview ready via WebSocket event (after codegen / Worker build).
3306
+ // The details iframe is not mounted. Subscribing still ran the reload on
3307
+ // this page's thread at the same moment the canvas tab stopped answering.
3308
+ $: if (detailsPreviewIsMounted() && $dynamicWorkerPreviewStatus.widgetId === selectedWidgetId && $dynamicWorkerPreviewStatus.previewUrl) {
3286
3309
  void applyWorkerPreviewFromEvent(
3287
3310
  $dynamicWorkerPreviewStatus.previewUrl,
3288
3311
  $dynamicWorkerPreviewStatus.buildTimeMs,
@@ -3302,17 +3325,34 @@
3302
3325
  void processQueuedActions();
3303
3326
  }
3304
3327
 
3305
- // Sync key state back to parent so reactive blocks (isGenerateDisabled, etc.) stay correct
3306
- $: dispatch('stateSync', {
3307
- widgetId: selectedWidgetId,
3308
- directPreviewUrl,
3309
- iframeSrc,
3310
- previewLoading,
3311
- showPreviewModal,
3312
- showWidgetDetails,
3313
- inlinePanelView,
3314
- hasAutoOpenedPreview,
3315
- });
3328
+ // Sync key state back to parent so reactive blocks (isGenerateDisabled, etc.) stay correct.
3329
+ // Dispatch only when the payload changes — an identical dispatch re-renders the whole canvas page.
3330
+ let lastStateSyncKey = '';
3331
+ $: {
3332
+ const stateSyncKey = [
3333
+ selectedWidgetId ?? '',
3334
+ directPreviewUrl ?? '',
3335
+ iframeSrc ?? '',
3336
+ previewLoading ? '1' : '0',
3337
+ showPreviewModal ? '1' : '0',
3338
+ showWidgetDetails ? '1' : '0',
3339
+ inlinePanelView ?? '',
3340
+ hasAutoOpenedPreview ? '1' : '0',
3341
+ ].join('\n');
3342
+ if (stateSyncKey !== lastStateSyncKey) {
3343
+ lastStateSyncKey = stateSyncKey;
3344
+ dispatch('stateSync', {
3345
+ widgetId: selectedWidgetId,
3346
+ directPreviewUrl,
3347
+ iframeSrc,
3348
+ previewLoading,
3349
+ showPreviewModal,
3350
+ showWidgetDetails,
3351
+ inlinePanelView,
3352
+ hasAutoOpenedPreview,
3353
+ });
3354
+ }
3355
+ }
3316
3356
 
3317
3357
  // ═══════════════════════════════════════════════════════════════════════
3318
3358
  // LIFECYCLE
@@ -209,31 +209,36 @@
209
209
  * showing the version from before the generation.
210
210
  */
211
211
  const RELOAD_COALESCE_MS = 1200;
212
+ // Completion, history alignment and the unpublished-head pass all ask for a
213
+ // reload of the same Worker document. A second one in this window only flashes.
214
+ const RELOAD_QUIET_MS = 3000;
212
215
  let lastReloadAtByWidgetId: Record<string, number> = {};
213
216
  const coalescedReloadTimers = new Map<string, ReturnType<typeof setTimeout>>();
214
217
 
215
- export function requestReload(widgetId: string): void {
218
+ export function requestReload(widgetId: string, options?: { immediate?: boolean }): void {
216
219
  const now = Date.now();
217
220
  const sinceLast = now - (lastReloadAtByWidgetId[widgetId] || 0);
218
221
  // A second call inside the window used to be dropped when a timer already
219
222
  // existed, so the codegen reload (the one that matches the new commit)
220
223
  // never ran and the shape kept the previous build. Replace the timer so
221
224
  // the later request wins. While generating, wait and try again.
222
- if (isGenerating || sinceLast < RELOAD_COALESCE_MS) {
225
+ // `immediate` is the call after the run flag has been cleared: the prop can
226
+ // still say generating for this turn, and waiting here left the old document up.
227
+ if (isGenerating) {
223
228
  const existing = coalescedReloadTimers.get(widgetId);
224
229
  if (existing) clearTimeout(existing);
225
- const wait = isGenerating
226
- ? RELOAD_COALESCE_MS
227
- : Math.max(0, RELOAD_COALESCE_MS - sinceLast);
228
230
  coalescedReloadTimers.set(
229
231
  widgetId,
230
232
  setTimeout(() => {
231
233
  coalescedReloadTimers.delete(widgetId);
232
234
  requestReload(widgetId);
233
- }, wait),
235
+ }, RELOAD_COALESCE_MS),
234
236
  );
235
237
  return;
236
238
  }
239
+ if (!options?.immediate && sinceLast < RELOAD_QUIET_MS) {
240
+ return;
241
+ }
237
242
  const coalesced = coalescedReloadTimers.get(widgetId);
238
243
  if (coalesced) {
239
244
  clearTimeout(coalesced);
@@ -291,16 +296,32 @@
291
296
  const nextLoaded = { ...iframeLoadedByWidgetId };
292
297
  for (const rect of getRects() || []) {
293
298
  if (!rect?.widgetId) continue;
294
- const src = resolveUrl(rect.widgetId) || '';
299
+ const resolvedSrc = resolveUrl(rect.widgetId) || '';
295
300
  const previewState = resolvePreviewState?.(rect.widgetId);
296
- if (!src && !previewState?.loading && !previewState?.error) continue;
297
301
  const prev = overlays.find((o) => o.widgetId === rect.widgetId);
302
+ // Keep the frame that is already up. Swapping its address when the Worker
303
+ // finishes reloads the document while the status still says "Saving…".
304
+ const src = isGenerating && prev?.src ? prev.src : resolvedSrc;
305
+ if (!src && !previewState?.loading && !previewState?.error) continue;
306
+ if (isGenerating && !prev?.src && !previewState?.url) continue;
298
307
  if (!prev || prev.src !== src) {
299
308
  cancelPendingRefresh(rect.widgetId);
300
309
  nextLoaded[rect.widgetId] = false;
301
310
  }
302
311
  next.push({ ...rect, src });
303
312
  }
313
+ const unchanged = next.length === overlays.length && next.every((overlay, index) => {
314
+ const current = overlays[index];
315
+ return current
316
+ && current.widgetId === overlay.widgetId
317
+ && current.src === overlay.src
318
+ && current.left === overlay.left
319
+ && current.top === overlay.top
320
+ && current.width === overlay.width
321
+ && current.height === overlay.height
322
+ && current.hovered === overlay.hovered;
323
+ });
324
+ if (unchanged) return;
304
325
  iframeLoadedByWidgetId = nextLoaded;
305
326
  // Drop refresh intents for shapes that left the canvas — their iframes
306
327
  // will never fire the load event the capture is waiting on.
@@ -94,7 +94,9 @@ interface Props {
94
94
  isGenerating?: boolean;
95
95
  }
96
96
  declare const WidgetShapeLivePreviews: import("svelte").Component<Props, {
97
- requestReload: (widgetId: string) => void;
97
+ requestReload: (widgetId: string, options?: {
98
+ immediate?: boolean;
99
+ }) => void;
98
100
  cancelReloads: (widgetId?: string) => void;
99
101
  setSelectedVersion: (widgetId: string, versionId: string | null) => void;
100
102
  sync: () => void;
@@ -71,10 +71,32 @@ export interface CreatorAppProps {
71
71
  /**
72
72
  * The page's own media library for the file pickers of the editor (the image, video and file settings of a widget):
73
73
  * their files are listed, uploaded, renamed and deleted through these functions instead of the visitor's Widgetic
74
- * uploads. Dropping an image on the canvas and the chat's attachments are not covered: they keep using Widgetic's
75
- * storage.
74
+ * uploads. When `upload` is given, chat attachments and prompt/canvas image drops call it once per file with
75
+ * `{ file, purpose: 'chat' | 'canvas', onProgress?, signal? }` (file fields use `purpose: 'field'`). The transfer
76
+ * has no time limit of ours: it ends when your promise settles or when `signal` aborts. On failure or an invalid
77
+ * result the upload is reported to the visitor and Widgetic's storage is not used.
76
78
  */
77
79
  mediaLibrary?: MediaLibraryProvider;
80
+ /** File pickers in widget settings; when set, overrides `mediaLibrary` there only (chat/canvas still use `mediaLibrary`). */
81
+ mediaLibraryForFields?: MediaLibraryProvider;
82
+ /** Opens the partner's file picker instead of the built-in File Browser in widget settings fields. */
83
+ pickFile?: (request: {
84
+ accept: string[];
85
+ multiple: boolean;
86
+ signal: AbortSignal;
87
+ }) => Promise<Array<{
88
+ id: string;
89
+ name: string;
90
+ url: string;
91
+ mimeType?: string;
92
+ }>>;
93
+ /** Resolves the url stored with a picked file (`mediaLibrary.urlResolver`). */
94
+ storeFileUrl?: (file: {
95
+ id: string;
96
+ name: string;
97
+ url: string;
98
+ mimeType?: string;
99
+ }) => Promise<string>;
78
100
  /**
79
101
  * The language of the creator: a BCP 47 tag (`"de"`, `"pt-BR"`) that sets the plural rules and how numbers, dates and
80
102
  * lists are written. English when left out or when this browser does not know the tag. Set again while the creator
@@ -109,11 +131,13 @@ export interface CreatorAppProps {
109
131
  * restoring the last project canvas / selected widget.
110
132
  */
111
133
  forceCreateNewWidget?: boolean;
134
+ /** Name the project list already chose, shown before this canvas is saved. */
135
+ initialSketchName?: string | null;
112
136
  /** When true, hides auth screen + top bar; syncs session from site localStorage */
113
137
  embedded?: boolean;
114
138
  /**
115
139
  * API gateway origin for embedded hosts (e.g. site `PUBLIC_API_URL`).
116
- * Without this, production creator dist falls back to SDK default `dev-api.widgetic.com`.
140
+ * Without this, the creator falls back to the SDK default, `https://api.widgetic.com/v1` (the production API).
117
141
  */
118
142
  apiUrl?: string | null;
119
143
  /**