@widgetic/creator 0.3.80 → 0.3.81

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.
@@ -3619,6 +3619,38 @@
3619
3619
  });
3620
3620
  }
3621
3621
 
3622
+ /** Widget id baked into a CDN path, when the path has one. */
3623
+ function widgetIdFromJsPath(jsPath: string | null | undefined): string | null {
3624
+ if (!jsPath) return null;
3625
+ return (jsPath.match(/\/widgets\/([^/]+)\//i) || [])[1] || null;
3626
+ }
3627
+
3628
+ /** Turn a stored js/html path into the HTML file the iframe can load. */
3629
+ function htmlUrlFromJsPath(jsPath: string): string {
3630
+ const cdnBase = publishedCdnBase();
3631
+ const trimmed = jsPath.replace(/\/+$/, '');
3632
+ let resolved = trimmed
3633
+ .replace(/\/widget\.js$/i, '/widget.html')
3634
+ .replace(/\.js$/i, '.html');
3635
+ if (!/\.html$/i.test(resolved)) {
3636
+ resolved = `${resolved}/widget.html`;
3637
+ }
3638
+ if (resolved.startsWith('/')) {
3639
+ resolved = `${cdnBase}${resolved}`;
3640
+ }
3641
+ return resolved;
3642
+ }
3643
+
3644
+ /**
3645
+ * A preset copy keeps the source file so the preview can load, but that path
3646
+ * names the source widget. It is not this widget's version history.
3647
+ */
3648
+ function borrowedPresetArtifactUrl(widgetId: string, jsPath: string | null | undefined): string | null {
3649
+ const ownerId = widgetIdFromJsPath(jsPath);
3650
+ if (!jsPath || !ownerId || ownerId === widgetId) return null;
3651
+ return htmlUrlFromJsPath(jsPath);
3652
+ }
3653
+
3622
3654
  /** Resolve published artifact URL — CDN path by live version; js_path only when it matches that version. */
3623
3655
  function resolvePublishedWidgetUrl(
3624
3656
  widgetId: string,
@@ -3631,19 +3663,14 @@
3631
3663
  const versionedUrl = `${cdnBase}/widgets/${widgetId}/v${version}/widget.html`;
3632
3664
 
3633
3665
  if (jsPath) {
3634
- const trimmed = jsPath.replace(/\/+$/, '');
3635
- let resolved = trimmed
3636
- .replace(/\/widget\.js$/i, '/widget.html')
3637
- .replace(/\.js$/i, '.html');
3638
- if (!/\.html$/i.test(resolved)) {
3639
- resolved = `${resolved}/widget.html`;
3640
- }
3641
- if (resolved.startsWith('/')) {
3642
- resolved = `${cdnBase}${resolved}`;
3643
- }
3666
+ const resolved = htmlUrlFromJsPath(jsPath);
3667
+ const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
3668
+ // The copy has no artifact of its own. Load the source file instead of
3669
+ // inventing /widgets/{newId}/vN/, which 404s on the bucket.
3670
+ if (borrowed) return borrowed;
3644
3671
  const jsPathVersionMatch = jsPath.match(/\/v(\d+)(?:\/|$)/);
3645
3672
  const jsPathVersion = jsPathVersionMatch ? parseInt(jsPathVersionMatch[1], 10) : null;
3646
- const jsPathWidgetId = (resolved.match(/\/widgets\/([^/]+)\//i) || [])[1] || null;
3673
+ const jsPathWidgetId = widgetIdFromJsPath(resolved);
3647
3674
  const pointsAtOtherWidget = !!(jsPathWidgetId && jsPathWidgetId !== widgetId);
3648
3675
  // Only reuse js_path when it already points at this widget + this version.
3649
3676
  // `/widgets/` alone used to win and keep Edit on the previous CDN version after publish.
@@ -7427,6 +7454,19 @@
7427
7454
  if (!widget) return { kind: 'draft' };
7428
7455
  const jsPath = ((widget as { jsPath?: string | null; js_path?: string | null }).jsPath
7429
7456
  ?? (widget as { js_path?: string | null }).js_path) as string | null;
7457
+ const widgetId = (widget as { id?: string }).id || '';
7458
+ // A preset copy stores the source widget's file. That /vN/ is the source's
7459
+ // history, not a version of this account's widget. Chat starts empty; so do versions.
7460
+ if (borrowedPresetArtifactUrl(widgetId, jsPath)) {
7461
+ if (isWidgetPublishedSummary(widget)) {
7462
+ return {
7463
+ kind: 'published',
7464
+ version: Number((widget as { version?: number }).version),
7465
+ jsPath,
7466
+ };
7467
+ }
7468
+ return { kind: 'draft' };
7469
+ }
7430
7470
  // Only trust an explicit CDN/version path — a bare/non-version js_path must NOT
7431
7471
  // mark the widget as published (that stuck Publish on "No new version to publish").
7432
7472
  if (jsPath) {
@@ -11444,9 +11484,13 @@ Requirements:
11444
11484
  }
11445
11485
  }
11446
11486
  const widget = getWidgetById(widgetId);
11487
+ const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null; js_path?: string | null } | undefined)?.jsPath
11488
+ ?? (widget as { js_path?: string | null } | undefined)?.js_path
11489
+ ?? null;
11490
+ const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
11491
+ if (borrowed && source !== 'preview') return borrowed;
11447
11492
  const version = ps.lastPublishedVersion ?? resolvePublishedVersionFromWidget(widget);
11448
11493
  if (version == null) return null;
11449
- const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null } | undefined)?.jsPath ?? null;
11450
11494
  return resolvePublishedWidgetUrl(widgetId, version, jsPath);
11451
11495
  }
11452
11496
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.3.80",
3
+ "version": "0.3.81",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "@sveltejs/kit": "^2.20.0",