@widgetic/creator 0.4.29 → 0.4.30

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.
@@ -1780,7 +1780,13 @@
1780
1780
  captureCanvasSketch?: () => Promise<string>;
1781
1781
  absorbCanvasSketchIntoWidget?: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
1782
1782
  }) | null;
1783
- if (embedded && !canvasAdvancedFeatures && sketchCanvas?.captureCanvasSketch) {
1783
+ const sketchPanel = getPanelState(widgetId);
1784
+ const widgetAlreadyBuilt = !isDraftConvertId(widgetId) && !!(
1785
+ sketchPanel.lastCommitId || sketchPanel.hasGeneratedCode || sketchPanel.lastPublishedVersion != null
1786
+ );
1787
+ // The board sketch belongs on the first prompt only. A later message was
1788
+ // picking up the line on the canvas instead of the widget.
1789
+ if (!widgetAlreadyBuilt && embedded && !canvasAdvancedFeatures && sketchCanvas?.captureCanvasSketch) {
1784
1790
  try {
1785
1791
  const canvasSketch = await sketchCanvas.captureCanvasSketch();
1786
1792
  if (canvasSketch?.startsWith('data:image/')) {
@@ -2127,6 +2133,7 @@
2127
2133
  const retryImageAttachments = retryFileAttachments.filter((attachment) => {
2128
2134
  const type = String(attachment.file_type || '');
2129
2135
  const name = String(attachment.file_name || '');
2136
+ if (/design-screenshot|attached-sketch/i.test(name)) return false;
2130
2137
  return type.startsWith('image/') || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(name) || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(attachment.url);
2131
2138
  });
2132
2139
  const retryUploadIds = [
@@ -4796,6 +4803,35 @@
4796
4803
  'enforce'
4797
4804
  ) as 'off' | 'shadow' | 'enforce';
4798
4805
 
4806
+ /** Same-origin previews: set the CSS variables directly, so a color shows while the field is still focused. */
4807
+ function paintDesignVarsOnPreview(widgetId: string, design: Record<string, unknown>): void {
4808
+ const frames = [
4809
+ getWidgetDetailsRef(widgetId)?.getPreviewIframe?.() ?? null,
4810
+ resolveLiveWidgetShapeIframe(widgetId)
4811
+ ];
4812
+ for (const frame of frames) {
4813
+ const doc = frame?.contentDocument;
4814
+ if (!doc) continue;
4815
+ const roots = [
4816
+ doc.documentElement,
4817
+ doc.body,
4818
+ doc.querySelector('.widget-root'),
4819
+ doc.querySelector('#widget-root'),
4820
+ doc.querySelector('[data-widget-root]')
4821
+ ].filter((node, index, list): node is HTMLElement => node instanceof HTMLElement && list.indexOf(node) === index);
4822
+ for (const [key, value] of Object.entries(design)) {
4823
+ if (!key || value == null) continue;
4824
+ for (const root of roots) {
4825
+ try {
4826
+ root.style.setProperty('--' + key, String(value));
4827
+ } catch (error) {
4828
+ console.warn('[CreatorApp] Could not paint a design variable on the preview', key, error);
4829
+ }
4830
+ }
4831
+ }
4832
+ }
4833
+ }
4834
+
4799
4835
  /** Apply design values to the live preview + persist, mirroring the editor path. */
4800
4836
  let designEditsByWidgetId: Record<string, Record<string, unknown>> = {};
4801
4837
 
@@ -4818,6 +4854,7 @@
4818
4854
  };
4819
4855
  getWidgetDetailsRef(widgetId)?.sendMessageToPreview(designMessage);
4820
4856
  resolveLiveWidgetShapeIframe(widgetId)?.contentWindow?.postMessage(designMessage, '*');
4857
+ paintDesignVarsOnPreview(widgetId, designMessage.design);
4821
4858
  compositionDirty = true;
4822
4859
  if (widgetId === focusedPanelWidgetId) {
4823
4860
  syncFocusedPanelEditorSnapshot();
@@ -8709,9 +8746,18 @@
8709
8746
  await getWidgetDetailsRef(selectedWidgetId)?.loadWidget(selectedWidgetId);
8710
8747
  }
8711
8748
 
8712
- // Auto-create repository if widget has none (silently, in background)
8749
+ // A repo is created when the widget is actually started (a prompt is typed, or Send).
8750
+ // Opening a sketch must not create one — that used to make a repo for every untouched widget.
8713
8751
  if (widget?.id && !normalizeRepositoryId(widget)) {
8714
8752
  const capturedId = widget.id;
8753
+ const panel = getPanelState(capturedId);
8754
+ const started = !!(
8755
+ panel.lastCommitId
8756
+ || panel.lastPublishedVersion != null
8757
+ || panel.hasGeneratedCode
8758
+ || (conversationsByWidgetId[capturedId]?.length ?? 0) > 0
8759
+ );
8760
+ if (started) {
8715
8761
  repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [capturedId]: 'pending' };
8716
8762
  ensureWidgetRepository(widget, { silent: true }).then((repoId) => {
8717
8763
  if (repoId) {
@@ -8732,8 +8778,10 @@
8732
8778
  repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [capturedId]: 'failed' };
8733
8779
  console.warn('[WidgetCreator] Auto-repo creation failed:', err);
8734
8780
  });
8781
+ }
8735
8782
  } else if (widget?.id && normalizeRepositoryId(widget)) {
8736
8783
  repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [widget.id]: 'ready' };
8784
+ void prewarmWidgetCodegenOnTyping(widget.id);
8737
8785
  }
8738
8786
 
8739
8787
  if (
@@ -65,8 +65,9 @@
65
65
  let { spec, liveValues, knownPropertyIds, detached = false, onChange }: Props = $props();
66
66
 
67
67
  let values = $state<Record<string, unknown>>({});
68
- let editingPropertyId = '';
69
- let editingValue: unknown = undefined;
68
+ let editingPropertyId = $state('');
69
+ let editingValue = $state<unknown>(undefined);
70
+ let previewTimer: ReturnType<typeof setTimeout> | null = null;
70
71
 
71
72
  // A drag in the PropsEditor moves the card. While this card's own field is
72
73
  // focused, keep what the user is typing — reseeding from the host used to
@@ -84,19 +85,25 @@
84
85
  onChange(property.id, value);
85
86
  }
86
87
 
87
- /** Native input listener. A controlled `value` was only flushing the color when the field blurred. */
88
- function applyAsTyped(node: HTMLInputElement, initial: DesignControlProperty) {
89
- let property = initial;
90
- const onType = () => commit(property, node.value.trim());
91
- node.addEventListener('input', onType);
92
- return {
93
- update(next: DesignControlProperty) {
94
- property = next;
95
- },
96
- destroy() {
97
- node.removeEventListener('input', onType);
98
- }
99
- };
88
+ /** Text fields send every key. Color fields wait until the hex is complete. */
89
+ function commitText(property: DesignControlProperty, raw: string) {
90
+ editingPropertyId = property.id;
91
+ editingValue = raw;
92
+ values = { ...values, [property.id]: raw };
93
+ onChange(property.id, raw);
94
+ }
95
+
96
+ /** The preview updates on each key. The composition save is debounced by the host. */
97
+ function commitWhileTyping(property: DesignControlProperty, raw: string) {
98
+ const trimmed = raw.trim();
99
+ editingPropertyId = property.id;
100
+ editingValue = trimmed;
101
+ values = { ...values, [property.id]: trimmed };
102
+ const colorReady = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(trimmed);
103
+ if (!colorReady && trimmed !== '') return;
104
+ if (previewTimer) clearTimeout(previewTimer);
105
+ previewTimer = null;
106
+ onChange(property.id, trimmed);
100
107
  }
101
108
 
102
109
  function currentValue(property: DesignControlProperty): unknown {
@@ -126,6 +133,7 @@
126
133
  {/if}
127
134
  {#each spec.properties as property (property.id)}
128
135
  {@const type = String(property.controllerType ?? '').toLowerCase()}
136
+ {@const isColor = type.includes('color') || type.includes('colour')}
129
137
  {@const available = isQuickEditPropertyAvailable(property.id, knownPropertyIds)}
130
138
  {@const editable = !detached && available}
131
139
  <div class="flex items-center justify-between gap-3">
@@ -140,7 +148,7 @@
140
148
  <span class="text-xs tabular-nums text-gray-500">{asString(property)}</span>
141
149
  {:else if !available}
142
150
  <span class="text-[10px] italic text-gray-400">{$t('creator.designEdit.notAvailableInThisWidget')}</span>
143
- {:else if type === 'colorpicker'}
151
+ {:else if isColor}
144
152
  <div class="flex items-center gap-2">
145
153
  <input
146
154
  id={`design-quick-${property.id}`}
@@ -148,7 +156,7 @@
148
156
  tabindex="-1"
149
157
  class="design-quick-color h-6 w-8 shrink-0 cursor-pointer rounded border border-gray-300 bg-white p-0 outline-none"
150
158
  value={/^#[0-9a-fA-F]{6}$/.test(asString(property)) ? asString(property) : '#000000'}
151
- use:applyAsTyped={property}
159
+ oninput={(event) => commitWhileTyping(property, (event.currentTarget as HTMLInputElement).value)}
152
160
  />
153
161
  <input
154
162
  type="text"
@@ -156,7 +164,7 @@
156
164
  tabindex="-1"
157
165
  class="design-quick-hex w-24 rounded border border-gray-300 px-1.5 py-1 text-xs font-mono text-gray-700 outline-none"
158
166
  value={asString(property)}
159
- use:applyAsTyped={property}
167
+ oninput={(event) => commitWhileTyping(property, (event.currentTarget as HTMLInputElement).value)}
160
168
  />
161
169
  </div>
162
170
  {:else if type === 'slider' && property.min !== undefined && property.max !== undefined}
@@ -219,7 +227,7 @@
219
227
  dir={asString(property) ? dirForUserText($textDirection) : undefined}
220
228
  class="w-40 rounded border border-gray-300 px-1.5 py-1 text-xs text-gray-700"
221
229
  value={asString(property)}
222
- onchange={(e) => commit(property, (e.currentTarget as HTMLInputElement).value)}
230
+ oninput={(e) => commitText(property, (e.currentTarget as HTMLInputElement).value)}
223
231
  />
224
232
  {/if}
225
233
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.4.29",
3
+ "version": "0.4.30",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "peerDependencies": {