@widgetic/creator 0.4.47 → 0.4.49

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.
@@ -84,7 +84,6 @@ export const CREATOR_MESSAGES = {
84
84
  'creator.general.keepInDatabase': 'Keep in Database',
85
85
  'creator.general.deleteFromDatabase': 'Delete from Database',
86
86
  'creator.general.checkingWhatWillBeDeleted': 'Checking what will be deleted…',
87
- 'creator.general.describeWhatYouWant': 'Describe what you want...',
88
87
  // The visitor's session: ended, expired, sign-in needed.
89
88
  'creator.session.endedStartAgain': 'This session is no longer active. Please start again from the page.',
90
89
  'creator.session.canvasCannotOpen': 'This canvas cannot be opened. Please start again from the page.',
@@ -103,7 +102,6 @@ export const CREATOR_MESSAGES = {
103
102
  'creator.widget.notFound': 'Widget not found',
104
103
  'creator.widget.fallbackName': 'Widget',
105
104
  'creator.widget.untitledName': 'Untitled widget',
106
- 'creator.widget.noWidgetSelected': 'No widget selected.',
107
105
  'creator.widget.shapeRemoved': 'Shape removed',
108
106
  'creator.widget.widgetKeptInDatabase': 'Widget kept in database',
109
107
  'creator.widget.widgetDeletedFromDatabase': 'Widget deleted from database',
@@ -156,6 +154,7 @@ export const CREATOR_MESSAGES = {
156
154
  'creator.canvas.canvasSaved': 'Canvas saved',
157
155
  'creator.canvas.sketchRestored': 'Sketch restored',
158
156
  'creator.canvas.canvasSaveFailed': 'Canvas save failed',
157
+ 'creator.canvas.autosaveFailedWillRetry': 'Your latest changes are not saved yet. We will keep trying: leave this page open until it is saved.',
159
158
  'creator.canvas.canvasSavedLocally': 'Canvas saved locally',
160
159
  'creator.canvas.noCanvasIdYet': 'No canvas id yet.',
161
160
  'creator.canvas.canvasUnavailable': 'Canvas unavailable',
@@ -163,13 +162,9 @@ export const CREATOR_MESSAGES = {
163
162
  'creator.canvas.shapeDataMayBeMissing': 'Shape data may be missing from the saved canvas (failed autosave or API quota). Widgets still work from the list — click Restore shapes to re-add placeholders on the canvas.',
164
163
  'creator.canvas.deleteCanvas': 'Delete Canvas',
165
164
  'creator.embedded.tabCanvas': 'Canvas',
166
- 'creator.sketch.boardReady': 'Your widget is ready',
167
- 'creator.sketch.boardGenerating': 'Generating your widget…',
168
- 'creator.sketch.boardFailed': 'Could not generate your widget',
169
- /** The button inside the failed chip: runs the last prompt again. */
170
- 'creator.sketch.boardFailedRetry': 'Try again',
171
165
  'creator.sketch.customize': 'Customize',
172
166
  'creator.sketch.publishedJustNow': 'Published just now',
167
+ 'creator.sketch.publishNeedsWidget': 'Send a message first so your widget gets built, then publish it.',
173
168
  // The chat tab reuses `creator.livePreviews.chat` ("Chat"): the catalog holds one key per wording.
174
169
  // Compositions: creating, saving, renaming, deleting, the Edit step.
175
170
  'creator.composition.compositionCreated': 'Composition "{name}" created',
@@ -185,9 +180,7 @@ export const CREATOR_MESSAGES = {
185
180
  'creator.composition.deleteThisComposition': 'Delete this composition?',
186
181
  'creator.composition.webComponentFormatRequiresA': 'Web Component format requires a composition. Select a composition first — falling back to iframe for direct widget URL.',
187
182
  'creator.composition.compositionUrl': 'Composition URL',
188
- // Code generation, repositories and the confirm dialog.
189
- 'creator.codegen.referenceImages': 'Reference Images ({count})',
190
- 'creator.codegen.referenceNumber': 'Reference {number}',
183
+ // Code generation and repositories.
191
184
  'creator.codegen.missingReferenceImage': 'Missing reference image',
192
185
  'creator.codegen.unreadableAttachmentsTitle': 'Some attached files were not used',
193
186
  'creator.codegen.unreadableAttachments': 'The builder reads images, CSV files and Markdown or text files. It did not read: {names}. Paste the text into your message instead.',
@@ -263,12 +256,6 @@ export const CREATOR_MESSAGES = {
263
256
  'creator.codegen.generateCodeFirstToCustomize': 'Generate code first to customize colors, text, and content.',
264
257
  'creator.codegen.noWidgetCodeYet': 'No widget code yet',
265
258
  'creator.codegen.goToStep1Create': 'Go to Step 1 (Create) to generate widget code first.',
266
- 'creator.codegen.confirmCodeGeneration': 'Confirm Code Generation',
267
- 'creator.codegen.reviewThePromptAndReference': 'Review the prompt and reference image before starting generation.',
268
- 'creator.codegen.describeTheWidgetYouWant': 'Describe the widget you want. You can attach a screenshot first if you have a design.',
269
- 'creator.codegen.prompt': 'Prompt',
270
- 'creator.codegen.editPromptFirst': 'Edit Prompt First',
271
- 'creator.codegen.generateNow': '🚀 Generate Now',
272
259
  // The preview and its banners.
273
260
  'creator.preview.newerThanLive': 'Newer than Live v{version}',
274
261
  'creator.preview.mayShowLive': 'Preview may show Live v{version} while HEAD is broken.',
@@ -318,7 +305,6 @@ export const CREATOR_MESSAGES = {
318
305
  'creator.publish.publishIsRunningInAnother': 'Publish is running in another browser tab.',
319
306
  'creator.publish.thisVersionIsAlreadyPublished': 'This version is already published.',
320
307
  'creator.publish.thisDraftHasNoRecorded': 'This draft has no recorded commit to publish.',
321
- 'creator.publish.generateWidgetCodeBeforePublishing': 'Generate widget code before publishing.',
322
308
  'creator.publish.publishWidget': 'Publish Widget',
323
309
  /** The name of the publish button the page shows (it hears it from the creator) when the widget has changes that are not live. */
324
310
  'creator.publish.publishChanges': 'Publish changes',
@@ -0,0 +1,9 @@
1
+ export type PublishCodeSnapshot = {
2
+ hasGeneratedCode: boolean;
3
+ lastPublishedVersion: number | null;
4
+ lastCommitId: string | null;
5
+ };
6
+ /** True when the panel has no generated version/commit to publish yet (fresh or sketch-only). */
7
+ export declare function panelLacksGeneratedVersion(snapshot: PublishCodeSnapshot): boolean;
8
+ /** Publish stays clickable; this is when a click should nudge Send instead of running publish. */
9
+ export declare function shouldNudgeSendBeforePublish(snapshot: PublishCodeSnapshot): boolean;
@@ -0,0 +1,10 @@
1
+ /** True when the panel has no generated version/commit to publish yet (fresh or sketch-only). */
2
+ export function panelLacksGeneratedVersion(snapshot) {
3
+ return !(snapshot.hasGeneratedCode
4
+ || snapshot.lastPublishedVersion !== null
5
+ || !!snapshot.lastCommitId);
6
+ }
7
+ /** Publish stays clickable; this is when a click should nudge Send instead of running publish. */
8
+ export function shouldNudgeSendBeforePublish(snapshot) {
9
+ return panelLacksGeneratedVersion(snapshot);
10
+ }
@@ -7,6 +7,11 @@ export type PanelCodegenFlags = {
7
7
  export declare function isSketchGenerationFailed(panelState: PanelCodegenFlags, widget: Record<string, unknown> | null | undefined): boolean;
8
8
  /** Figma ready frame: caption "Saved 2m ago" from widget `updatedAt`. */
9
9
  export declare function sketchSavedStatusLabel(savedWord: string, updatedAt: unknown, nowMs?: number): string;
10
+ /**
11
+ * The bar of the Figma frames carries Publish in every state except while the widget is being built (526:2466) and after a
12
+ * failed build (526:2984). A canvas that has no widget yet (the Empty frame) shows it too, as the way of learning that
13
+ * Send comes first: a bar with no Publish at all on a new canvas read as "Publish is missing".
14
+ */
10
15
  export declare function sketchBarShowsPublish(input: {
11
16
  embedded: boolean;
12
17
  widgetId: string | null;
@@ -28,13 +28,16 @@ export function sketchSavedStatusLabel(savedWord, updatedAt, nowMs = Date.now())
28
28
  return `${savedWord} ${diffH}h ago`;
29
29
  return savedWord;
30
30
  }
31
+ /**
32
+ * The bar of the Figma frames carries Publish in every state except while the widget is being built (526:2466) and after a
33
+ * failed build (526:2984). A canvas that has no widget yet (the Empty frame) shows it too, as the way of learning that
34
+ * Send comes first: a bar with no Publish at all on a new canvas read as "Publish is missing".
35
+ */
31
36
  export function sketchBarShowsPublish(input) {
32
- return (input.embedded &&
33
- !!input.widgetId &&
34
- input.hasGeneratedCode &&
35
- !input.showsLive &&
36
- !input.generating &&
37
- !input.failed);
37
+ void input.widgetId;
38
+ void input.hasGeneratedCode;
39
+ void input.showsLive;
40
+ return input.embedded && !input.generating && !input.failed;
38
41
  }
39
42
  export function sketchBarShowsCustomize(input) {
40
43
  return (input.embedded &&
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Two decisions the creator makes when it saves the canvas, kept out of `CreatorApp.svelte` so that they can be tested.
3
+ *
4
+ * - **Is an empty canvas written over a canvas that had shapes?** A save that sends no shapes over a server copy that had
5
+ * some is how a canvas is wiped, by a snapshot that looks empty for the wrong reason (the board was not loaded, the page
6
+ * is being torn down). It is refused, unless the canvas itself reported a change since the last save got past this
7
+ * guard: a person who selected everything and pressed Delete emptied the board on purpose, and a server that kept the
8
+ * old shapes would show them again at the next visit.
9
+ * - **Does the request ask the browser to keep it alive?** A page that is going away (the tab closes, a reload) drops a
10
+ * request that is still on its way, and the last changes are lost. `keepalive` lets the browser finish it, for bodies of
11
+ * up to 64 KB.
12
+ */
13
+ /** What the guard against an empty canvas is told about the save. */
14
+ export interface EmptyCanvasGuardInput {
15
+ /** How many shapes the canvas to save has. */
16
+ shapesToSave: number;
17
+ /** How many shapes the last save that got past the guard had. */
18
+ shapesSavedBefore: number;
19
+ /** The save is the one made when the canvas component is torn down (a hot reload, a navigation): its snapshot is never trusted when it is empty. */
20
+ isUnmountSave: boolean;
21
+ /** The canvas reported a change since the last save got past the guard. */
22
+ changedSinceLastSave: boolean;
23
+ }
24
+ /**
25
+ * True when the save must be refused: it would put an empty canvas over one that had shapes, and nothing says the person did it.
26
+ * An empty canvas over an empty one, and over one that had a single shape (the last one was deleted), is always allowed.
27
+ */
28
+ export declare function refusesEmptyCanvas(input: EmptyCanvasGuardInput): boolean;
29
+ /** The most a request that outlives its page may carry, in bytes. The browser's limit is 64 KB for the body and the headers together. */
30
+ export declare const KEEPALIVE_BODY_LIMIT_BYTES = 60000;
31
+ /** Whether the text can go in a request that outlives its page. */
32
+ export declare function fitsKeepaliveRequest(text: string): boolean;
33
+ /** What the page tells about itself: whether it is being torn down, and what the document says about being seen. */
34
+ export interface PageState {
35
+ isUnmountSave: boolean;
36
+ /**
37
+ * The canvas says the page is going away (`pagehide`). It cannot be read from `visibilityState`: the browser sends `pagehide`
38
+ * while the document still says `visible` (`hidden` comes a moment later), so a save made in that moment would not be kept
39
+ * alive and would go with the page: that is how a text typed a second before a reload was lost.
40
+ */
41
+ pageIsLeaving?: boolean;
42
+ visibilityState: string | null | undefined;
43
+ }
44
+ /**
45
+ * The extra options of the save request: `{ keepalive: true }` when the page is going away or is hidden and the canvas fits,
46
+ * nothing otherwise (a request that is not kept alive can carry any size).
47
+ */
48
+ export declare function requestInitForSave(json: string, page: PageState): {
49
+ keepalive: true;
50
+ } | undefined;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Two decisions the creator makes when it saves the canvas, kept out of `CreatorApp.svelte` so that they can be tested.
3
+ *
4
+ * - **Is an empty canvas written over a canvas that had shapes?** A save that sends no shapes over a server copy that had
5
+ * some is how a canvas is wiped, by a snapshot that looks empty for the wrong reason (the board was not loaded, the page
6
+ * is being torn down). It is refused, unless the canvas itself reported a change since the last save got past this
7
+ * guard: a person who selected everything and pressed Delete emptied the board on purpose, and a server that kept the
8
+ * old shapes would show them again at the next visit.
9
+ * - **Does the request ask the browser to keep it alive?** A page that is going away (the tab closes, a reload) drops a
10
+ * request that is still on its way, and the last changes are lost. `keepalive` lets the browser finish it, for bodies of
11
+ * up to 64 KB.
12
+ */
13
+ /**
14
+ * True when the save must be refused: it would put an empty canvas over one that had shapes, and nothing says the person did it.
15
+ * An empty canvas over an empty one, and over one that had a single shape (the last one was deleted), is always allowed.
16
+ */
17
+ export function refusesEmptyCanvas(input) {
18
+ if (input.shapesToSave !== 0 || input.shapesSavedBefore <= 0)
19
+ return false;
20
+ if (input.isUnmountSave)
21
+ return true;
22
+ return input.shapesSavedBefore > 1 && !input.changedSinceLastSave;
23
+ }
24
+ /** The most a request that outlives its page may carry, in bytes. The browser's limit is 64 KB for the body and the headers together. */
25
+ export const KEEPALIVE_BODY_LIMIT_BYTES = 60_000;
26
+ /** Whether the text can go in a request that outlives its page. */
27
+ export function fitsKeepaliveRequest(text) {
28
+ try {
29
+ return new TextEncoder().encode(text).length <= KEEPALIVE_BODY_LIMIT_BYTES;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ /**
36
+ * The extra options of the save request: `{ keepalive: true }` when the page is going away or is hidden and the canvas fits,
37
+ * nothing otherwise (a request that is not kept alive can carry any size).
38
+ */
39
+ export function requestInitForSave(json, page) {
40
+ const leaving = page.isUnmountSave || page.pageIsLeaving === true || page.visibilityState === 'hidden';
41
+ return leaving && fitsKeepaliveRequest(json) ? { keepalive: true } : undefined;
42
+ }
@@ -29,7 +29,11 @@ export function streamOperationUpdates(operationId, options) {
29
29
  }
30
30
  deferredFrame = null;
31
31
  try {
32
- reader?.cancel();
32
+ // `cancel()` answers with a promise that rejects with the AbortError of a stream the caller has aborted (a press
33
+ // of Stop): left alone, that rejection reaches the console as an uncaught error.
34
+ void reader?.cancel().catch(() => {
35
+ /* the stream is closed either way */
36
+ });
33
37
  }
34
38
  catch {
35
39
  /* noop */
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@widgetic/creator",
3
- "version": "0.4.47",
3
+ "version": "0.4.49",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "peerDependencies": {
7
7
  "@sveltejs/kit": "^2.20.0",
8
8
  "@widgetic/api-sdk": "^2.0.0",
9
9
  "@widgetic/cache-layer": "^0.1.2",
10
- "@widgetic/canvas": "^0.5.36",
11
- "@widgetic/chat": "^0.1.36",
12
- "@widgetic/design-system": "^0.5.32",
10
+ "@widgetic/canvas": "^0.5.39",
11
+ "@widgetic/chat": "^0.1.38",
12
+ "@widgetic/design-system": "^0.5.34",
13
13
  "@widgetic/editor": "^4.1.3",
14
14
  "@widgetic/file-browser": "^0.5.25",
15
15
  "svelte": "^5.25.0"
@@ -74,9 +74,9 @@
74
74
  "@types/node": "26.4.0",
75
75
  "@widgetic/api-sdk": "^2.0.0",
76
76
  "@widgetic/cache-layer": "^0.1.2",
77
- "@widgetic/canvas": "^0.5.36",
78
- "@widgetic/chat": "^0.1.36",
79
- "@widgetic/design-system": "^0.5.32",
77
+ "@widgetic/canvas": "^0.5.39",
78
+ "@widgetic/chat": "^0.1.38",
79
+ "@widgetic/design-system": "^0.5.34",
80
80
  "@widgetic/dev-tools": "^0.3.0",
81
81
  "@widgetic/editor": "^4.1.3",
82
82
  "@widgetic/file-browser": "^0.5.25",