@widgetic/creator 0.3.75 → 0.3.76

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.
@@ -8903,6 +8903,112 @@ Requirements:
8903
8903
  return logs;
8904
8904
  }
8905
8905
 
8906
+ function languageStorageKey(widgetId: string): string {
8907
+ return `widgetic-widget-language:${widgetId}`;
8908
+ }
8909
+
8910
+ function generationOptionsStorageKey(widgetId: string): string {
8911
+ return `widgetic-generation-options:${widgetId}`;
8912
+ }
8913
+
8914
+ type RememberedGenerationOptions = {
8915
+ language: 'svelte' | 'react';
8916
+ librariesEnabled: boolean;
8917
+ libraries: string[];
8918
+ brandKitEnabled: boolean;
8919
+ primary: string;
8920
+ secondary: string;
8921
+ title: string;
8922
+ sub: string;
8923
+ fonts: string[];
8924
+ libraryUploads: { name: string; content: string; encoding: string }[];
8925
+ fontUploads: { name: string; content: string; encoding: string }[];
8926
+ };
8927
+
8928
+ let generationOptionsMemory: Record<string, RememberedGenerationOptions> = {};
8929
+
8930
+ function currentGenerationOptions(): RememberedGenerationOptions {
8931
+ return {
8932
+ language: widgetLanguage === 'react' ? 'react' : 'svelte',
8933
+ librariesEnabled,
8934
+ libraries: [...brandKitLibraries],
8935
+ brandKitEnabled,
8936
+ primary: brandPrimary,
8937
+ secondary: brandSecondary,
8938
+ title: brandTitle,
8939
+ sub: brandSub,
8940
+ fonts: [...brandFonts],
8941
+ libraryUploads: libraryUploads.map((file) => ({ ...file })),
8942
+ fontUploads: fontUploads.map((file) => ({ ...file })),
8943
+ };
8944
+ }
8945
+
8946
+ function rememberGenerationOptions(widgetId: string): void {
8947
+ if (!widgetId) return;
8948
+ const options = currentGenerationOptions();
8949
+ generationOptionsMemory = { ...generationOptionsMemory, [widgetId]: options };
8950
+ try {
8951
+ localStorage.setItem(languageStorageKey(widgetId), options.language);
8952
+ localStorage.setItem(generationOptionsStorageKey(widgetId), JSON.stringify({
8953
+ language: options.language,
8954
+ librariesEnabled: options.librariesEnabled,
8955
+ libraries: options.libraries,
8956
+ brandKitEnabled: options.brandKitEnabled,
8957
+ primary: options.primary,
8958
+ secondary: options.secondary,
8959
+ title: options.title,
8960
+ sub: options.sub,
8961
+ fonts: options.fonts,
8962
+ }));
8963
+ } catch (error) {
8964
+ console.warn('[WidgetCreator] Could not store generation options', error);
8965
+ }
8966
+ }
8967
+
8968
+ function restoreGenerationOptions(widgetId: string): void {
8969
+ const inMemory = generationOptionsMemory[widgetId];
8970
+ let stored: Partial<RememberedGenerationOptions> | null = null;
8971
+ if (!inMemory) {
8972
+ try {
8973
+ const raw = localStorage.getItem(generationOptionsStorageKey(widgetId));
8974
+ stored = raw ? JSON.parse(raw) : null;
8975
+ } catch (error) {
8976
+ console.warn('[WidgetCreator] Could not read generation options', error);
8977
+ }
8978
+ }
8979
+ const options = inMemory || stored;
8980
+ widgetLanguage = options?.language === 'react' ? 'react' : 'svelte';
8981
+ librariesEnabled = !!options?.librariesEnabled;
8982
+ brandKitLibraries = Array.isArray(options?.libraries) ? [...options.libraries] : [];
8983
+ brandKitEnabled = !!options?.brandKitEnabled;
8984
+ brandPrimary = options?.primary || '#314F2F';
8985
+ brandSecondary = options?.secondary || '#7BA668';
8986
+ brandTitle = options?.title || '#0F2010';
8987
+ brandSub = options?.sub || '#5C6B58';
8988
+ brandFonts = Array.isArray(options?.fonts) && options.fonts.length > 0 ? [...options.fonts] : ['Inter'];
8989
+ libraryUploads = inMemory?.libraryUploads ? inMemory.libraryUploads.map((file) => ({ ...file })) : [];
8990
+ fontUploads = inMemory?.fontUploads ? inMemory.fontUploads.map((file) => ({ ...file })) : [];
8991
+ }
8992
+
8993
+ function languageForGeneration(widgetId: string): 'svelte' | 'react' {
8994
+ const panel = getPanelState(widgetId);
8995
+ const hasCode = !!(panel.lastCommitId || panel.lastPublishedVersion != null);
8996
+ let language: 'svelte' | 'react' = widgetLanguage === 'react' ? 'react' : 'svelte';
8997
+ if (hasCode) {
8998
+ try {
8999
+ const saved = localStorage.getItem(languageStorageKey(widgetId));
9000
+ language = saved === 'react' ? 'react' : 'svelte';
9001
+ } catch (error) {
9002
+ console.warn('[WidgetCreator] Could not read widget language', error);
9003
+ }
9004
+ }
9005
+ widgetLanguage = language;
9006
+ rememberGenerationOptions(widgetId);
9007
+ return language;
9008
+ }
9009
+
9010
+ $: if (focusedPanelWidgetId) rememberGenerationOptions(focusedPanelWidgetId);
9011
+
8906
9012
  async function performCodeGeneration(
8907
9013
  prompt: string,
8908
9014
  options: {
@@ -9191,6 +9297,7 @@ Requirements:
9191
9297
  compileFixOnly: options.compileFixOnly === true,
9192
9298
  skipIntentGate: options.skipIntentGate === true,
9193
9299
  chipIntent: options.chipIntent,
9300
+ language: languageForGeneration(generationWidgetId),
9194
9301
  brandKit: brandKitForRequest(),
9195
9302
  } as GenerateCodeRequest
9196
9303
  });
@@ -12042,9 +12149,11 @@ Requirements:
12042
12149
  notifyHostWidgetName(getWidgetById(widgetId) ?? selectedWidget);
12043
12150
  return;
12044
12151
  }
12152
+ if (focusedPanelWidgetId) rememberGenerationOptions(focusedPanelWidgetId);
12045
12153
  captureFocusedPanelSnapshot();
12046
12154
  ensurePanelState(widgetId);
12047
12155
  focusedPanelWidgetId = widgetId;
12156
+ restoreGenerationOptions(widgetId);
12048
12157
  raiseWidgetDetailsPanelToFront(widgetId);
12049
12158
  isHistoryOpen = false;
12050
12159
  const widget = getWidgetById(widgetId);
@@ -16869,6 +16978,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
16869
16978
  bind:sub={brandSub}
16870
16979
  bind:fonts={brandFonts}
16871
16980
  showLanguage={debugMode}
16981
+ languageLocked={!!(generatingWidgetIds[panelWidgetId] || ps.lastCommitId || ps.lastPublishedVersion != null)}
16872
16982
  bind:language={widgetLanguage}
16873
16983
  />
16874
16984
  {/snippet}
@@ -31,6 +31,7 @@
31
31
  fontUploads?: { name: string; content: string; encoding: string }[];
32
32
  showLanguage?: boolean;
33
33
  language?: string;
34
+ languageLocked?: boolean;
34
35
  }
35
36
 
36
37
  const maxFonts = 3;
@@ -55,6 +56,7 @@
55
56
  fontUploads = $bindable([] as { name: string; content: string; encoding: string }[]),
56
57
  showLanguage = false,
57
58
  language = $bindable('svelte'),
59
+ languageLocked = false,
58
60
  }: Props = $props();
59
61
 
60
62
  const libraryChoices = [
@@ -281,6 +283,16 @@
281
283
  <div class="generation-libraries-row flex w-full flex-col gap-2">
282
284
  <div class="generation-libraries-checks flex flex-nowrap items-center gap-1">
283
285
  {#if showLanguage}
286
+ {#if languageLocked}
287
+ <HoverTooltip class="inline-flex shrink-0" text="Language is fixed after the first generation">
288
+ <span
289
+ class="generation-language-select flex h-10 w-[4.75rem] shrink-0 cursor-default items-center justify-between gap-0.5 rounded-lg border border-gray-300 bg-white px-1.5 text-sm text-gray-900 opacity-60"
290
+ aria-disabled="true"
291
+ >
292
+ <span class="truncate">{language === 'react' ? 'React' : 'Svelte'}</span>
293
+ </span>
294
+ </HoverTooltip>
295
+ {:else}
284
296
  <HoverTooltip class="inline-flex shrink-0" text="Select language">
285
297
  <DropdownMenu.Root>
286
298
  <DropdownMenu.Trigger
@@ -303,6 +315,7 @@
303
315
  </DropdownMenu.Content>
304
316
  </DropdownMenu.Root>
305
317
  </HoverTooltip>
318
+ {/if}
306
319
  {/if}
307
320
  <label class="generation-option-toggle flex h-10 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border px-2 text-sm {librariesEnabled ? 'border-[#314F2F] bg-[#314F2F] text-white' : 'border-gray-300 bg-white text-gray-800'}">
308
321
  <input class="generation-option-check cursor-pointer" type="checkbox" checked={librariesEnabled} onchange={onLibrariesChange} />
@@ -26,6 +26,7 @@ interface Props {
26
26
  }[];
27
27
  showLanguage?: boolean;
28
28
  language?: string;
29
+ languageLocked?: boolean;
29
30
  }
30
31
  declare const BrandKitPanel: import("svelte").Component<Props, {}, "brandKitEnabled" | "librariesEnabled" | "primary" | "secondary" | "title" | "sub" | "fonts" | "libraries" | "libraryGitUrl" | "libraryFileName" | "libraryUploads" | "fontUploads" | "language">;
31
32
  type BrandKitPanel = ReturnType<typeof BrandKitPanel>;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.3.75",
3
+ "version": "0.3.76",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "@sveltejs/kit": "^2.20.0",
7
- "@widgetic/api-sdk": "^1.0.22",
7
+ "@widgetic/api-sdk": "^1.0.23",
8
8
  "@widgetic/cache-layer": "^0.1.2",
9
9
  "@widgetic/canvas": "^0.5.15",
10
10
  "@widgetic/chat": "^0.1.17",
@@ -68,7 +68,7 @@
68
68
  "@tailwindcss/postcss": "^4.1.4",
69
69
  "@tailwindcss/typography": "^0.5.15",
70
70
  "@types/node": "26.4.0",
71
- "@widgetic/api-sdk": "^1.0.22",
71
+ "@widgetic/api-sdk": "^1.0.23",
72
72
  "@widgetic/cache-layer": "^0.1.2",
73
73
  "@widgetic/canvas": "^0.5.15",
74
74
  "@widgetic/chat": "^0.1.17",