@widgetic/creator 0.4.36 → 0.4.37

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.
@@ -37,7 +37,7 @@
37
37
  import { widgetBuilderRequestInit } from './utils/widgetBuilderRequest.js';
38
38
  import { gzipRequestBodyMiddleware } from './utils/gzipRequestMiddleware.js';
39
39
  import type { SelectedWidgetElementReference } from './utils/widgetElementSelector.js';
40
- import GenerationOptionsPanel from './components/GenerationOptionsPanel.svelte';
40
+ import BrandKitPanel from './components/BrandKitPanel.svelte';
41
41
  import { brandKitForRequest } from './generation/brandKitForRequest.js';
42
42
 
43
43
  /**
@@ -149,6 +149,7 @@
149
149
 
150
150
  import {
151
151
  normalizeErrorMessage,
152
+ codegenFailureChatLine,
152
153
  toErrorMessage,
153
154
  deriveApiErrorMessage,
154
155
  extractDetailsMessage,
@@ -1516,6 +1517,13 @@
1516
1517
  let widgetLanguage: 'svelte' | 'react' = 'react';
1517
1518
  let librariesEnabled = false;
1518
1519
  let generationLibraries: string[] = [];
1520
+ let brandKitEnabled = false;
1521
+ let brandPrimary = '#314F2F';
1522
+ let brandSecondary = '#7BA668';
1523
+ let brandTitle = '#0F2010';
1524
+ let brandSub = '#5C6B58';
1525
+ let brandFonts: string[] = ['Inter'];
1526
+ let fontUploads: { name: string; content: string; encoding: string }[] = [];
1519
1527
  let libraryGitUrl = '';
1520
1528
  let libraryFileName = '';
1521
1529
  let libraryUploads: { name: string; content: string; encoding: string }[] = [];
@@ -1725,6 +1733,15 @@
1725
1733
  panelDisplayRevision += 1;
1726
1734
  }
1727
1735
 
1736
+ function handleUpdateWidgetElementNote(widgetId: string, elementId: string, note: string): void {
1737
+ if (!widgetId || !elementId) return;
1738
+ const existing = selectedElementsByWidgetId[widgetId] ?? [];
1739
+ selectedElementsByWidgetId = {
1740
+ ...selectedElementsByWidgetId,
1741
+ [widgetId]: existing.map((item) => (item.id === elementId ? { ...item, note } : item)),
1742
+ };
1743
+ }
1744
+
1728
1745
  function handleClearWidgetSelectedElements(widgetId: string): void {
1729
1746
  if (!widgetId) return;
1730
1747
  const { [widgetId]: _cleared, ...rest } = selectedElementsByWidgetId;
@@ -2005,9 +2022,7 @@
2005
2022
 
2006
2023
  function pushCodegenFailureToChat(widgetId: string, errorText: string) {
2007
2024
  const panelChat = getChatMethodsForWidget(widgetId);
2008
- const content = /^Code generation failed/i.test(errorText)
2009
- ? errorText
2010
- : `Code generation failed: ${errorText}`;
2025
+ const content = codegenFailureChatLine(errorText);
2011
2026
  panelChat?.addAssistantMessage?.(content);
2012
2027
  // console.log('[Chat] Codegen failure bubble:', content.slice(0, 160));
2013
2028
  }
@@ -3480,6 +3495,9 @@
3480
3495
  }
3481
3496
  }
3482
3497
 
3498
+ /** One restore at a time. A second click while GitLab is still answering used to be told a generation was running. */
3499
+ let _restoreCheckpointInFlight = false;
3500
+
3483
3501
  /** Restore conversation to a checkpoint message via backend (deletes messages + git rollback) */
3484
3502
  async function handleRestoreCheckpoint(
3485
3503
  conversationId: string,
@@ -3489,6 +3507,14 @@
3489
3507
  // The widget whose code the restore puts back, as the panel looks at it when the request is made (the person may look at
3490
3508
  // another panel while it runs).
3491
3509
  const widgetIdAtRestore = restoreWidgetId || focusedPanelWidgetId || selectedWidgetId || null;
3510
+ if (_restoreCheckpointInFlight) {
3511
+ showToast('warning', $t('creator.version.failedToRestoreCheckpoint'), {
3512
+ description: $t('creator.version.restoreAlreadyRunning'),
3513
+ duration: 6000,
3514
+ });
3515
+ return null;
3516
+ }
3517
+ _restoreCheckpointInFlight = true;
3492
3518
  try {
3493
3519
  if (!messagesClient) {
3494
3520
  console.warn('[Chat→Backend] messagesClient not initialized');
@@ -3538,6 +3564,7 @@
3538
3564
  // Version 1 is the board before a generation replaced the drawing.
3539
3565
  // Later versions put that generation's code back on the shape.
3540
3566
  const restoreSketch = !targetCommit || restoredVersion === 1;
3567
+ sketchToolbarAfterRestore = restoreSketch;
3541
3568
  if (panelWidgetId && restoreSketch) {
3542
3569
  const sketchFromWidget = (getWidgetById(panelWidgetId) as { content?: { sketchCanvasJson?: string } } | null)?.content?.sketchCanvasJson;
3543
3570
  const sketch = sketchSnapshotsByWidgetId.get(panelWidgetId) || sketchFromWidget;
@@ -3634,6 +3661,15 @@
3634
3661
  _isRestoringCheckpoint = false;
3635
3662
  };
3636
3663
  void scheduleBuildRetry();
3664
+ } else if (gitRollback && gitRollback.success === false) {
3665
+ const rollbackError = String(gitRollback.error || '').trim();
3666
+ const gitlabLimited = /429|too many requests|rate limit/i.test(rollbackError);
3667
+ console.warn('[Restore] The code was not rolled back', { widgetId: panelWidgetId, rollbackError });
3668
+ showToast('warning', gitlabLimited ? $t('creator.general.rateLimited') : $t('creator.version.failedToRestoreCheckpoint'), {
3669
+ description: rollbackError || $t('creator.version.codeWasNotRolledBack'),
3670
+ duration: 9000,
3671
+ });
3672
+ return null;
3637
3673
  } else {
3638
3674
  console.warn('[Chat→Backend] Git rollback not detected in response, refreshing preview anyway...');
3639
3675
  showToast('warning', $t('creator.version.restoreCompletedWithWarnings'), {
@@ -3668,6 +3704,8 @@
3668
3704
  description: error instanceof Error ? error.message : $t('creator.general.unknownError'),
3669
3705
  });
3670
3706
  return null;
3707
+ } finally {
3708
+ _restoreCheckpointInFlight = false;
3671
3709
  }
3672
3710
  }
3673
3711
 
@@ -3760,6 +3798,9 @@
3760
3798
  if (!selectedId?.startsWith('v:')) return null;
3761
3799
  const version = Number(selectedId.slice(2));
3762
3800
  if (!Number.isFinite(version)) return null;
3801
+ // Restore already put this version on the board. Its commit is a new sha, so it does not match the history row.
3802
+ // Asking GitLab to roll back again only reads the trees and can 429.
3803
+ if (restoredViewingVersionByWidgetId[widgetId] === version) return null;
3763
3804
  const record = getShapePublishHistory(widgetId).find((row) => Number(row.version) === version);
3764
3805
  const sha = String(record?.commitSha ?? record?.commit_sha ?? '').trim();
3765
3806
  if (!/^[0-9a-f]{7,40}$/i.test(sha)) return null;
@@ -6030,6 +6071,7 @@
6030
6071
  function toggleDebugMode() {
6031
6072
  if (!debugModeAvailable) return;
6032
6073
  debugMode = !debugMode;
6074
+ if (!debugMode) brandKitEnabled = false;
6033
6075
  try {
6034
6076
  creatorStorage.setItem('widgetic:site-debug-on', debugMode ? '1' : '0');
6035
6077
  } catch (err) {
@@ -6050,7 +6092,26 @@
6050
6092
  let canvasWireframeMode = true;
6051
6093
  /** Extra canvas chrome — default off. Not tied to debugMode. */
6052
6094
  let canvasAdvancedFeatures = !!initialAdvancedFeatures;
6095
+ /**
6096
+ * More than one widget on this canvas. There is no env switch for it.
6097
+ * The Advanced button turns it on and off with the rest of the advanced chrome.
6098
+ */
6099
+ let multipleWidgetsAllowed = !!initialAdvancedFeatures;
6053
6100
  let canvasPrimaryWidgetId: string | null = null;
6101
+ /** Restore Checkpoint back to the sketch brings the drawing tools back until the next generation. */
6102
+ let sketchToolbarAfterRestore = false;
6103
+
6104
+ function primaryWidgetHasGeneratedCode(): boolean {
6105
+ if (!canvasPrimaryWidgetId || isDraftConvertId(canvasPrimaryWidgetId)) return false;
6106
+ const panel = getPanelState(canvasPrimaryWidgetId);
6107
+ return !!(panel.hasGeneratedCode || panel.lastCommitId || panel.lastPublishedVersion != null);
6108
+ }
6109
+
6110
+ $: showDrawingTools = sketchToolbarAfterRestore || !(
6111
+ panelDisplayRevision >= 0
6112
+ && !!canvasPrimaryWidgetId
6113
+ && primaryWidgetHasGeneratedCode()
6114
+ );
6054
6115
 
6055
6116
  function emitCreatorWireframeChanged() {
6056
6117
  announceToSite(CREATOR_WIREFRAME_CHANGED_EVENT, { wireframeMode: canvasWireframeMode });
@@ -6068,6 +6129,7 @@
6068
6129
 
6069
6130
  function handleHostToggleAdvancedEvent() {
6070
6131
  canvasAdvancedFeatures = !canvasAdvancedFeatures;
6132
+ multipleWidgetsAllowed = canvasAdvancedFeatures;
6071
6133
  emitCreatorAdvancedChanged();
6072
6134
  console.log('[CreatorApp] Advanced', canvasAdvancedFeatures ? 'ON' : 'OFF',
6073
6135
  '— composition steps', canvasAdvancedFeatures ? 'visible' : 'hidden');
@@ -6101,6 +6163,10 @@
6101
6163
  }
6102
6164
 
6103
6165
  async function handleHostDuplicateWidgetEvent(): Promise<void> {
6166
+ if (simpleCanvasHasItsWidget()) {
6167
+ showToast('info', $t('creator.widget.oneWidgetAlready'));
6168
+ return;
6169
+ }
6104
6170
  const widgetId = canvasPrimaryWidgetId || resolveHostTargetWidgetId();
6105
6171
  if (!widgetId || isDraftConvertId(widgetId)) {
6106
6172
  showToast('warning', $t('creator.widget.selectAWidgetFirst'), {
@@ -8130,7 +8196,13 @@
8130
8196
  }
8131
8197
 
8132
8198
  const linked = canvasRef.getLinkedWidgetIds?.() ?? new Set<string>();
8133
- const missing = sortWidgetSummaries(widgets.filter((w) => w.id && !linked.has(w.id))).reverse();
8199
+ let missing = sortWidgetSummaries(widgets.filter((w) => w.id && !linked.has(w.id))).reverse();
8200
+ if (embedded && !multipleWidgetsAllowed) {
8201
+ const primaryId = (canvasPrimaryWidgetId || '').trim();
8202
+ missing = primaryId
8203
+ ? missing.filter((widget) => widget.id === primaryId)
8204
+ : [];
8205
+ }
8134
8206
  if (missing.length === 0) return 0;
8135
8207
 
8136
8208
  // console.log('[CanvasDebug] Restoring', missing.length, 'widget shapes from canvas_id list');
@@ -9297,6 +9369,10 @@
9297
9369
 
9298
9370
 
9299
9371
  async function createNewWidgetRecord() {
9372
+ if (simpleCanvasHasItsWidget()) {
9373
+ showToast('info', $t('creator.widget.oneWidgetAlready'));
9374
+ return;
9375
+ }
9300
9376
  if (!$userSession.user || !hasValidToken) {
9301
9377
  authStatus = 'Please login first.';
9302
9378
  return;
@@ -10797,6 +10873,9 @@ Requirements:
10797
10873
  generationOperationByWidgetId.delete(generationWidgetId);
10798
10874
 
10799
10875
  generatingWidgetIds = { ...generatingWidgetIds, [generationWidgetId]: true };
10876
+ // The preview address does not change between builds. Without this, the next build
10877
+ // is treated as the one already on the shape, and the shape keeps the previous document.
10878
+ lastRunningPreviewKey = '';
10800
10879
  if (previewUnblockedByWidgetId[generationWidgetId]) {
10801
10880
  const { [generationWidgetId]: _dropPreview, ...restPreview } = previewUnblockedByWidgetId;
10802
10881
  previewUnblockedByWidgetId = restPreview;
@@ -10807,11 +10886,8 @@ Requirements:
10807
10886
  cancelQuietScreenshots();
10808
10887
  cancelIdleThumbnailPersist();
10809
10888
  widgetShapeLivePreviewsRef?.cancelReloads?.();
10810
- if (options.fromChat) {
10811
- console.log('[Chat→Preview] Reloading preview iframe on send', generationWidgetId.substring(0, 8));
10812
- widgetShapeLivePreviewsRef?.requestReload?.(generationWidgetId, { immediate: true });
10813
- void getWidgetDetailsRef(generationWidgetId)?.refreshPreview?.();
10814
- }
10889
+ // The preview stays on the current widget until a build actually lands.
10890
+ // Reloading here only flashed the same frame at the moment of Send.
10815
10891
  holdPublishForGeneration(generationWidgetId);
10816
10892
  if (restoredViewingVersionByWidgetId[generationWidgetId] != null) {
10817
10893
  const { [generationWidgetId]: _droppedRestore, ...restRestored } = restoredViewingVersionByWidgetId;
@@ -11079,6 +11155,15 @@ Requirements:
11079
11155
  debugMode,
11080
11156
  libraries: generationLibraries,
11081
11157
  libraryUploads,
11158
+ brandKitEnabled,
11159
+ colors: {
11160
+ primary: brandPrimary,
11161
+ secondary: brandSecondary,
11162
+ title: brandTitle,
11163
+ sub: brandSub,
11164
+ },
11165
+ fonts: brandFonts,
11166
+ fontUploads,
11082
11167
  }),
11083
11168
  ...(options.selectedElements && options.selectedElements.length > 0
11084
11169
  ? {
@@ -11087,7 +11172,9 @@ Requirements:
11087
11172
  selector: el.selector,
11088
11173
  idAttr: el.idAttr,
11089
11174
  classList: el.classList,
11090
- textSnippet: el.textSnippet,
11175
+ textSnippet: [el.textSnippet, el.note?.trim() ? `Note: ${el.note.trim()}` : '']
11176
+ .filter(Boolean)
11177
+ .join(' — ') || undefined,
11091
11178
  dataContent: el.dataContent,
11092
11179
  parentTag: el.parentTag,
11093
11180
  outerHtmlSnippet: el.outerHtmlSnippet,
@@ -11329,7 +11416,8 @@ Requirements:
11329
11416
  });
11330
11417
  clearActiveOperationId(generationWidgetId);
11331
11418
 
11332
- const isServiceError = errorMsg.includes('temporarily unavailable') ||
11419
+ const isGitlabLimit = /gitlab rate limit|gitlab refused the (save|rollback)|last status code:\s*429/i.test(errorMsg);
11420
+ const isServiceError = isGitlabLimit || errorMsg.includes('temporarily unavailable') ||
11333
11421
  errorMsg.includes('Our team has been notified') ||
11334
11422
  errorMsg.includes('Too many generation requests');
11335
11423
  const isSvelteSyntaxError = errorMsg.includes('Svelte') ||
@@ -11348,7 +11436,7 @@ Requirements:
11348
11436
  ? $t('creator.codegen.aiGeneratedInvalidSvelteSyntax')
11349
11437
  : errorMsg;
11350
11438
 
11351
- showToast('error', isServiceError ? $t('creator.general.serviceTemporarilyUnavailable') : $t('creator.status.failed'), {
11439
+ showToast('error', isGitlabLimit ? $t('creator.general.rateLimited') : isServiceError ? $t('creator.general.serviceTemporarilyUnavailable') : $t('creator.status.failed'), {
11352
11440
  description: toastDescription,
11353
11441
  duration: isServiceError ? 10000 : 8000
11354
11442
  });
@@ -11594,6 +11682,7 @@ Requirements:
11594
11682
  const shownFailure = [completedPreviewBuildErr, !completedCommitSha ? unsavedText : null]
11595
11683
  .filter((part): part is string => !!part)
11596
11684
  .join('\n');
11685
+ sketchToolbarAfterRestore = false;
11597
11686
  patchCodegenUiState(generationWidgetId, {
11598
11687
  hasGeneratedCode: true,
11599
11688
  ...(completedCommitSha ? { lastCommitId: completedCommitSha } : {}),
@@ -11925,13 +12014,8 @@ Requirements:
11925
12014
  // Update global flag: true only if the CURRENT widget is still generating
11926
12015
  isGeneratingCode = !!(focusedPanelWidgetId && generatingWidgetIds[focusedPanelWidgetId]);
11927
12016
  setCrossTabGenerating(false, generationWidgetId);
11928
- // A finished run already loads the new preview. Reloading here as well
11929
- // flashed the shape a second time. A failed run still needs the one reload.
11930
- if (getPanelState(generationWidgetId).lastGenerationFailed) {
11931
- void tick().then(() => {
11932
- widgetShapeLivePreviewsRef?.requestReload?.(generationWidgetId, { immediate: true });
11933
- });
11934
- }
12017
+ // A finished run already loads the new preview when the worker build lands.
12018
+ // A failed run kept the previous frame, so reloading it only flashes the same picture.
11935
12019
  // The API refused this run and the widget is free of it now: follow the person's own generation, or catch up with the
11936
12020
  // newer code that was saved. (Not awaited: a followed run can take minutes, and the queue behind this one must not wait.)
11937
12021
  if (afterRefusal) {
@@ -12308,6 +12392,7 @@ Requirements:
12308
12392
  codeGenerationStatus,
12309
12393
  agentHarnessOutput,
12310
12394
  dynamicWorkerPreviewStatus,
12395
+ deferredVersionRecorded,
12311
12396
  setAuthToken as setWsAuthToken,
12312
12397
  setWebsocketApiUrl,
12313
12398
  resetRealtimeState
@@ -14004,10 +14089,9 @@ Requirements:
14004
14089
  const ps = getPanelDisplayState(widgetId);
14005
14090
  const liveVersion =
14006
14091
  ps.lastPublishedVersion ?? resolvePublishedVersionFromWidget(getWidgetById(widgetId));
14007
- // Newest first. Versions are one ascending sequence, so the number orders
14008
- // them correctly on its own; sorting by time is a stable tiebreak.
14092
+ // Oldest first, same as the chat: the first version is the top row, the latest is the bottom.
14009
14093
  const history = [...getShapePublishHistory(widgetId)].sort(
14010
- (a, b) => Number(b.version) - Number(a.version),
14094
+ (a, b) => Number(a.version) - Number(b.version),
14011
14095
  );
14012
14096
  const options: Array<{
14013
14097
  id: string;
@@ -14143,6 +14227,8 @@ Requirements:
14143
14227
  // draft/restore look like the last publish even when git had moved.
14144
14228
  if (versionId.startsWith('v:')) {
14145
14229
  const version = Number(versionId.slice(2));
14230
+ // Leaving the sketch. The drawing tools stay only while version 1 is the board.
14231
+ if (version !== 1) sketchToolbarAfterRestore = false;
14146
14232
  const record = getShapePublishHistory(widgetId).find((row) => Number(row.version) === version);
14147
14233
  const isPublished = !!(record?.publishedAt ?? record?.published_at);
14148
14234
  const newestDraft = getNewestDraftVersionId(widgetId);
@@ -15938,6 +16024,30 @@ $: if ($dynamicWorkerPreviewStatus.widgetId && $dynamicWorkerPreviewStatus.previ
15938
16024
  }
15939
16025
  }
15940
16026
 
16027
+ // A 429 left the preview up and the version menu empty. When GitLab accepts the same commit, the version lands here.
16028
+ let lastDeferredVersionEventKey: string | null = null;
16029
+ $: if ($deferredVersionRecorded.widgetId && $deferredVersionRecorded.commitId) {
16030
+ const deferredWidgetId = $deferredVersionRecorded.widgetId;
16031
+ const deferredCommitId = $deferredVersionRecorded.commitId;
16032
+ const deferredEventKey = `${deferredWidgetId}:${deferredCommitId}:${$deferredVersionRecorded.timestamp ?? ''}`;
16033
+ if (deferredEventKey !== lastDeferredVersionEventKey) {
16034
+ lastDeferredVersionEventKey = deferredEventKey;
16035
+ const deferredVersion = $deferredVersionRecorded.version;
16036
+ const deferredTitle = $deferredVersionRecorded.commitTitle;
16037
+ setTimeout(() => {
16038
+ console.log('[CreatorApp] Version recorded after GitLab accepted the save', deferredWidgetId.substring(0, 8), deferredVersion);
16039
+ patchCodegenUiState(deferredWidgetId, {
16040
+ lastCommitId: deferredCommitId,
16041
+ lastGenerationFailed: false,
16042
+ lastGenerationError: null,
16043
+ generateCodeStatus: deferredVersion ? `Version ${deferredVersion} saved` : 'Version saved',
16044
+ });
16045
+ stampCodegenTitleIntoPanelHistory(deferredWidgetId, deferredCommitId, deferredTitle);
16046
+ void loadPublishHistoryForPanel(deferredWidgetId, { silent: true, fresh: true });
16047
+ }, 0);
16048
+ }
16049
+ }
16050
+
15941
16051
  // ===================== Publish History =====================
15942
16052
 
15943
16053
  /**
@@ -17163,6 +17273,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
17163
17273
  ? widgetIdsOnCanvas
17164
17274
  : [...(canvasRef?.getLinkedWidgetIds?.() ?? [])];
17165
17275
  const primaryId = await hydrateCanvasPrimaryWidget(linkedIds);
17276
+ await lockSimpleCanvasToOneWidget(primaryId);
17166
17277
  applyPrimarySelectionOnCanvas(primaryId);
17167
17278
  requestAnimationFrame(() => {
17168
17279
  setTimeout(() => applyPrimarySelectionOnCanvas(primaryId), 80);
@@ -17653,6 +17764,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
17653
17764
  showToast('error', $t('creator.session.pleaseLoginFirst'));
17654
17765
  return;
17655
17766
  }
17767
+ if (simpleCanvasHasItsWidget()) {
17768
+ showToast('info', $t('creator.widget.oneWidgetAlready'));
17769
+ return;
17770
+ }
17656
17771
  if (isWidgetOperationInProgress) {
17657
17772
  console.warn('[WidgetCreator] Another widget operation in progress, skipping convert');
17658
17773
  showToast('warning', $t('creator.general.pleaseWaitForTheCurrent'));
@@ -17782,6 +17897,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
17782
17897
  */
17783
17898
  async function finalizeDraftConversion(draftId: string, prompt: string, extraImageUrls: string[] = []): Promise<string | null> {
17784
17899
  if (!draftId.startsWith(DRAFT_CONVERT_ID_PREFIX)) return null;
17900
+ if (simpleCanvasHasItsWidget()) {
17901
+ showToast('info', $t('creator.widget.oneWidgetAlready'));
17902
+ console.warn('[CreatorApp] Simple canvas already has a widget — not creating another');
17903
+ return null;
17904
+ }
17785
17905
  if (finalizingDraftConversions.has(draftId)) return null;
17786
17906
  finalizingDraftConversions.add(draftId);
17787
17907
  // Keep Widget Details open while the canvas sketch is replaced (selection
@@ -18012,6 +18132,35 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
18012
18132
  }
18013
18133
  }
18014
18134
 
18135
+ /** Advanced off: the canvas already has its one widget, so another must not be created. */
18136
+ function simpleCanvasHasItsWidget(): boolean {
18137
+ if (!embedded || multipleWidgetsAllowed) return false;
18138
+ const primaryId = (canvasPrimaryWidgetId || '').trim();
18139
+ return !!primaryId && !isDraftConvertId(primaryId);
18140
+ }
18141
+
18142
+ /**
18143
+ * Simple canvas: leave the primary widget's shape, drop the others, and place
18144
+ * the primary when the board is still showing a different widget.
18145
+ */
18146
+ async function lockSimpleCanvasToOneWidget(primaryId: string | null): Promise<void> {
18147
+ if (!embedded || multipleWidgetsAllowed || !canvasRef || !primaryId) return;
18148
+ const removed = canvasRef.keepOnlyWidgetShape?.(primaryId) ?? 0;
18149
+ const linked = canvasRef.getLinkedWidgetIds?.() ?? new Set<string>();
18150
+ let placed = false;
18151
+ if (!linked.has(primaryId)) {
18152
+ const widget = getWidgetById(primaryId) as { name?: string; thumbnailUrl?: string | null; thumbnail_url?: string | null } | null;
18153
+ const preview = widget?.thumbnailUrl ?? widget?.thumbnail_url ?? null;
18154
+ canvasRef.addWidgetShape?.(primaryId, widget?.name, 0, 1, preview);
18155
+ placed = true;
18156
+ console.log('[CreatorApp] Simple canvas placed the one widget', primaryId.slice(0, 8));
18157
+ }
18158
+ if (removed > 0 || placed) {
18159
+ canvasRef.saveNow?.();
18160
+ syncWidgetShapeLivePreviews();
18161
+ }
18162
+ }
18163
+
18015
18164
  /** Draft panel id helper — true when the id is a synthetic convert draft. */
18016
18165
  function isDraftConvertId(widgetId: string | null | undefined): boolean {
18017
18166
  return !!widgetId && widgetId.startsWith(DRAFT_CONVERT_ID_PREFIX);
@@ -18741,6 +18890,25 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
18741
18890
  void captureListThumbnail(widgetId, true);
18742
18891
  }}
18743
18892
  onSetPrimaryWidget={handleSetPrimaryWidget}
18893
+ showElementSelector={!!canvasPrimaryWidgetId && !isDraftConvertId(canvasPrimaryWidgetId)}
18894
+ showDrawingTools={showDrawingTools}
18895
+ elementSelectorActive={!!(canvasPrimaryWidgetId && selectorEnabledByWidgetId[canvasPrimaryWidgetId])}
18896
+ selectorGuide={{
18897
+ click: $t('creator.elementSelector.clickPartToReference'),
18898
+ parentChild: $t('creator.elementSelector.parentChild'),
18899
+ hold: $t('creator.elementSelector.hold'),
18900
+ cmd: $t('creator.elementSelector.cmdCtrl'),
18901
+ interact: $t('creator.elementSelector.toInteract'),
18902
+ esc: $t('creator.elementSelector.esc'),
18903
+ done: $t('creator.elementSelector.done'),
18904
+ }}
18905
+ onToggleElementSelector={() => {
18906
+ if (!canvasPrimaryWidgetId || isDraftConvertId(canvasPrimaryWidgetId)) return;
18907
+ handleToggleWidgetSelector(
18908
+ canvasPrimaryWidgetId,
18909
+ !selectorEnabledByWidgetId[canvasPrimaryWidgetId],
18910
+ );
18911
+ }}
18744
18912
  onAfterRender={syncWidgetShapeLivePreviews}
18745
18913
  getWidgetName={getWidgetNameById}
18746
18914
  widgetNameRevision={widgetNamesRevision}
@@ -18820,9 +18988,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
18820
18988
  isGenerating={isAnyWidgetGenerating()}
18821
18989
  onLiveFrameShown={noteShapePreviewShown}
18822
18990
  resolveSelectorEnabled={(widgetId) => !!selectorEnabledByWidgetId[widgetId]}
18991
+ showUnderShapeSelectorHint={false}
18823
18992
  resolveSelectedElements={(widgetId) => selectedElementsByWidgetId[widgetId] ?? []}
18824
18993
  onSelectWidgetElement={(widgetId, element) => handleSelectWidgetElement(widgetId, element)}
18825
18994
  onRemoveWidgetElement={(widgetId, elementId) => handleRemoveWidgetElement(widgetId, elementId)}
18995
+ onUpdateWidgetElementNote={(widgetId, elementId, note) => handleUpdateWidgetElementNote(widgetId, elementId, note)}
18826
18996
  onCloseWidgetSelector={(widgetId) => {
18827
18997
  handleToggleWidgetSelector(widgetId, false);
18828
18998
  canvasRef?.setWidgetShapeBodyDragAllowed?.(widgetId, false);
@@ -19536,7 +19706,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19536
19706
  runPublishForPanel(panelWidgetId, Number(viewingVersion));
19537
19707
  }}
19538
19708
  disabled={!canPublishDraftVersionForPanel(panelWidgetId, viewingVersion) || getPublishGateForPanel(panelWidgetId, Number(viewingVersion)).disabled}
19539
- title={$t('creator.common.buildThisDraftVersionAnd')}
19709
+ title={$t('creator.livePreviews.publishThisDraft')}
19540
19710
  class="wc-version-publish-btn shrink-0 inline-flex items-center justify-center min-w-[4.75rem] w-[4.75rem] text-[10px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded border border-emerald-600 bg-emerald-600 text-white hover:bg-emerald-700 disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer"
19541
19711
  >
19542
19712
  {isPublishing && publishingWidgetId === panelWidgetId ? '...' : $t('creator.common.publish')}
@@ -19582,7 +19752,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19582
19752
  class="wc-version-history-scroll flex flex-col gap-1 overflow-x-hidden {hasChatScroll ? 'overflow-y-auto' : 'overflow-y-visible'}"
19583
19753
  style="{hasChatScroll ? 'max-height: 185px; margin-inline-end: -4px; padding-inline-end: 4px;' : 'max-height: none;'} scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.2) transparent;"
19584
19754
  >
19585
- {#each ps.publishHistory as record (record.id)}
19755
+ {#each [...ps.publishHistory].sort((a, b) => Number(a.version) - Number(b.version)) as record (record.id)}
19586
19756
  {@const rowVersion = Number(record.version)}
19587
19757
  {@const rowIsDraft = !(record.publishedAt ?? record.published_at)}
19588
19758
  {@const rowIsViewing = rowVersion === Number(viewingVersion)}
@@ -19781,9 +19951,17 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19781
19951
  />
19782
19952
  {/snippet}
19783
19953
  {#snippet generationOptionChecks()}
19784
- <GenerationOptionsPanel
19954
+ <BrandKitPanel
19785
19955
  part="checks"
19786
19956
  showPresetLibraries={debugMode}
19957
+ showBrandKit={debugMode}
19958
+ bind:brandKitEnabled
19959
+ bind:primary={brandPrimary}
19960
+ bind:secondary={brandSecondary}
19961
+ bind:title={brandTitle}
19962
+ bind:sub={brandSub}
19963
+ bind:fonts={brandFonts}
19964
+ bind:fontUploads
19787
19965
  bind:librariesEnabled
19788
19966
  bind:libraries={generationLibraries}
19789
19967
  bind:libraryGitUrl
@@ -19833,7 +20011,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
19833
20011
  versionLabelByPrompt={versionPromptLabelsByWidgetId[panelWidgetId] ?? emptyVersionLabels}
19834
20012
  versionTimeline={versionTimelineByWidgetId[panelWidgetId] ?? emptyVersionTimeline}
19835
20013
  viewingVersion={viewingVersionByWidgetId[panelWidgetId] ?? null}
19836
- showSelector={!isDraftConvertId(panelWidgetId)}
20014
+ showSelector={false}
19837
20015
  isSelectorActive={!!selectorEnabledByWidgetId[panelWidgetId]}
19838
20016
  selectedElements={selectedElementsByWidgetId[panelWidgetId] ?? []}
19839
20017
  onToggleSelector={(active) => handleToggleWidgetSelector(panelWidgetId, active)}