@widgetic/creator 0.3.77 → 0.3.79

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.
@@ -1700,7 +1700,7 @@
1700
1700
  if (url) return url;
1701
1701
  // The canvas widget list is slim and often omits the thumbnail, so ask the
1702
1702
  // API for this one widget rather than leaving the shape blank.
1703
- if (widget) return await fetchWidgetThumbnailUrl(widgetId);
1703
+ if (widget) return await fetchWidgetThumbnailUrl(widgetId, widget);
1704
1704
  await new Promise((resolve) => setTimeout(resolve, 500));
1705
1705
  }
1706
1706
  return null;
@@ -1709,16 +1709,33 @@
1709
1709
  /** One-widget lookup for the persisted thumbnail, cached per widget. */
1710
1710
  const thumbnailUrlRequests = new Map<string, Promise<string | null>>();
1711
1711
 
1712
- function fetchWidgetThumbnailUrl(widgetId: string): Promise<string | null> {
1712
+ /**
1713
+ * The generated widget model drops thumbnailUrl. Read the list as JSON so
1714
+ * the canvas shape still receives the saved image.
1715
+ */
1716
+ async function readWidgetList(canvasIdForList?: string | null): Promise<any[]> {
1717
+ if (!widgetsClient || typeof (widgetsClient as any).getWidgetsRaw !== 'function') return [];
1718
+ const response = await (widgetsClient as any).getWidgetsRaw(
1719
+ canvasIdForList ? { canvasId: canvasIdForList } : {},
1720
+ );
1721
+ const body = await response.raw.json();
1722
+ const envelopeData = body?.data;
1723
+ const nested = envelopeData?.data;
1724
+ if (Array.isArray(body)) return body;
1725
+ if (Array.isArray(nested)) return nested;
1726
+ if (Array.isArray(envelopeData)) return envelopeData;
1727
+ return [];
1728
+ }
1729
+
1730
+ function fetchWidgetThumbnailUrl(widgetId: string, widget?: any): Promise<string | null> {
1713
1731
  const pending = thumbnailUrlRequests.get(widgetId);
1714
1732
  if (pending) return pending;
1715
1733
  const request = (async () => {
1716
1734
  if (!widgetsClient) return null;
1717
1735
  try {
1718
- const response = (await widgetsClient.getWidgetsBatch({
1719
- getWidgetsBatchRequest: { widgetIds: [widgetId] }
1720
- })) as { widgets?: any[]; data?: { widgets?: any[] } };
1721
- const fetched = (response?.widgets ?? response?.data?.widgets ?? [])[0];
1736
+ const canvasForWidget = widget?.canvasId || widget?.canvas_id || canvasId;
1737
+ const list = await readWidgetList(canvasForWidget);
1738
+ const fetched = list.find((row) => row?.id === widgetId);
1722
1739
  return fetched?.thumbnailUrl ?? fetched?.thumbnail_url ?? null;
1723
1740
  } catch (error) {
1724
1741
  console.warn('[CreatorApp] thumbnail lookup failed', widgetId.slice(0, 8), error);
@@ -6446,34 +6463,9 @@
6446
6463
  console.warn('WidgetCreator.loadWidgetsForCanvas: missing JWT before calling widgets API');
6447
6464
  }
6448
6465
 
6449
- // Fetch widgets directly by canvasId
6450
- const res = await widgetsClient.getWidgets({ canvasId: canvasId ?? undefined });
6451
-
6452
- // normalize error shape from apiRequest
6453
- const envelope = res as unknown as {
6454
- error?: string;
6455
- message?: string;
6456
- data?: unknown;
6457
- };
6458
- if (envelope && (envelope.error || envelope.message)) {
6459
- // console.error('Widget Creator: loadWidgetsForCanvas: response not ok:', res);
6460
- widgets = [];
6461
- selectedWidgetId = null;
6462
- isLoadingWidgets = false;
6463
- widgetsError = envelope.message || envelope.error || 'Failed to load widgets';
6464
- throw new Error(widgetsError);
6465
- }
6466
-
6467
- // if the response is ok, parse the data (bare list, {data: list} or {data: {data: list}})
6468
- const envelopeData = envelope?.data;
6469
- const envelopeNestedData = (envelopeData as { data?: unknown } | undefined)?.data;
6470
- const fetched = Array.isArray(res)
6471
- ? (res as unknown as WidgetSummary[])
6472
- : Array.isArray(envelopeNestedData)
6473
- ? (envelopeNestedData as unknown as WidgetSummary[])
6474
- : Array.isArray(envelopeData)
6475
- ? (envelopeData as unknown as WidgetSummary[])
6476
- : [];
6466
+ // Fetch widgets directly by canvasId. Raw JSON keeps thumbnailUrl,
6467
+ // which the generated model drops.
6468
+ const fetched = await readWidgetList(canvasId);
6477
6469
 
6478
6470
  const previousById = new Map(
6479
6471
  widgets.filter((w) => w.id).map((w) => [w.id as string, w]),
@@ -12036,9 +12028,13 @@ Requirements:
12036
12028
  }
12037
12029
  const linkedIds = canvasRef?.getLinkedWidgetIds?.() ?? new Set<string>();
12038
12030
  for (const widgetId of linkedIds) {
12039
- if (!liveWidgetIds.has(widgetId)) {
12031
+ const hasLivePreview = liveWidgetIds.has(widgetId);
12032
+ if (!hasLivePreview) {
12040
12033
  canvasRef?.setWidgetShapeLivePreviewHiddenImage?.(widgetId, false);
12041
12034
  }
12035
+ // The drag bar exists only over a live iframe. A sketch or a
12036
+ // failed generation has no iframe, so the shape itself must move.
12037
+ canvasRef?.setWidgetShapeBodyDragAllowed?.(widgetId, !hasLivePreview);
12042
12038
  }
12043
12039
  } catch (err) {
12044
12040
  console.warn('[CreatorApp] WidgetShape live preview sync failed', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.3.77",
3
+ "version": "0.3.79",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "@sveltejs/kit": "^2.20.0",