@widgetic/creator 0.3.78 → 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.
@@ -1709,29 +1709,32 @@
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
+ /**
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
+
1712
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
- // The canvas list already carries thumbnail_url. Do not use
1719
- // POST /widgets/batch: that route is the public embed gate and
1720
- // drops the row when the trial has ended, so the sketch never paints.
1721
1736
  const canvasForWidget = widget?.canvasId || widget?.canvas_id || canvasId;
1722
- const res = await widgetsClient.getWidgets(
1723
- canvasForWidget ? { canvasId: canvasForWidget } : {},
1724
- );
1725
- const envelope = res as { data?: unknown };
1726
- const envelopeData = envelope?.data;
1727
- const nested = (envelopeData as { data?: unknown } | undefined)?.data;
1728
- const list = Array.isArray(res)
1729
- ? (res as any[])
1730
- : Array.isArray(nested)
1731
- ? (nested as any[])
1732
- : Array.isArray(envelopeData)
1733
- ? (envelopeData as any[])
1734
- : [];
1737
+ const list = await readWidgetList(canvasForWidget);
1735
1738
  const fetched = list.find((row) => row?.id === widgetId);
1736
1739
  return fetched?.thumbnailUrl ?? fetched?.thumbnail_url ?? null;
1737
1740
  } catch (error) {
@@ -6460,34 +6463,9 @@
6460
6463
  console.warn('WidgetCreator.loadWidgetsForCanvas: missing JWT before calling widgets API');
6461
6464
  }
6462
6465
 
6463
- // Fetch widgets directly by canvasId
6464
- const res = await widgetsClient.getWidgets({ canvasId: canvasId ?? undefined });
6465
-
6466
- // normalize error shape from apiRequest
6467
- const envelope = res as unknown as {
6468
- error?: string;
6469
- message?: string;
6470
- data?: unknown;
6471
- };
6472
- if (envelope && (envelope.error || envelope.message)) {
6473
- // console.error('Widget Creator: loadWidgetsForCanvas: response not ok:', res);
6474
- widgets = [];
6475
- selectedWidgetId = null;
6476
- isLoadingWidgets = false;
6477
- widgetsError = envelope.message || envelope.error || 'Failed to load widgets';
6478
- throw new Error(widgetsError);
6479
- }
6480
-
6481
- // if the response is ok, parse the data (bare list, {data: list} or {data: {data: list}})
6482
- const envelopeData = envelope?.data;
6483
- const envelopeNestedData = (envelopeData as { data?: unknown } | undefined)?.data;
6484
- const fetched = Array.isArray(res)
6485
- ? (res as unknown as WidgetSummary[])
6486
- : Array.isArray(envelopeNestedData)
6487
- ? (envelopeNestedData as unknown as WidgetSummary[])
6488
- : Array.isArray(envelopeData)
6489
- ? (envelopeData as unknown as WidgetSummary[])
6490
- : [];
6466
+ // Fetch widgets directly by canvasId. Raw JSON keeps thumbnailUrl,
6467
+ // which the generated model drops.
6468
+ const fetched = await readWidgetList(canvasId);
6491
6469
 
6492
6470
  const previousById = new Map(
6493
6471
  widgets.filter((w) => w.id).map((w) => [w.id as string, w]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.3.78",
3
+ "version": "0.3.79",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "@sveltejs/kit": "^2.20.0",