@widgetic/creator 0.3.80 → 0.4.0
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.
- package/README.md +157 -0
- package/dist/CreatorApp.svelte +1159 -624
- package/dist/CreatorApp.svelte.d.ts +22 -0
- package/dist/components/BrandKitPanel.svelte +48 -40
- package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
- package/dist/components/DesignQuickEdit.svelte +13 -4
- package/dist/components/EditableName.svelte +13 -8
- package/dist/components/EditableName.svelte.d.ts +2 -2
- package/dist/components/FileUrlSourceControl.svelte +21 -8
- package/dist/components/HoverTooltip.svelte +1 -1
- package/dist/components/SelectorDropdown.svelte +19 -15
- package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
- package/dist/components/VersionDropdownRow.svelte +14 -11
- package/dist/components/WidgetDetails.svelte +118 -92
- package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
- package/dist/creator-types.d.ts +96 -0
- package/dist/host/creatorHost.d.ts +176 -0
- package/dist/host/creatorHost.js +242 -0
- package/dist/host/limitRefusal.d.ts +64 -0
- package/dist/host/limitRefusal.js +109 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/labels.d.ts +14 -0
- package/dist/i18n/labels.js +39 -0
- package/dist/i18n/language.d.ts +559 -0
- package/dist/i18n/language.js +47 -0
- package/dist/i18n/languageKit.d.ts +52 -0
- package/dist/i18n/languageKit.js +45 -0
- package/dist/i18n/messages.d.ts +526 -0
- package/dist/i18n/messages.js +548 -0
- package/dist/i18n/slots.d.ts +22 -0
- package/dist/i18n/slots.js +42 -0
- package/dist/i18n/statusText.d.ts +22 -0
- package/dist/i18n/statusText.js +223 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/stores/userSession.d.ts +8 -1
- package/dist/stores/userSession.js +18 -25
- package/dist/stores/websocketStore.d.ts +6 -0
- package/dist/stores/websocketStore.js +39 -4
- package/dist/utils/designIntentTelemetry.d.ts +8 -0
- package/dist/utils/designIntentTelemetry.js +52 -34
- package/dist/utils/directionPlacement.d.ts +51 -0
- package/dist/utils/directionPlacement.js +55 -0
- package/dist/utils/embedCode.d.ts +0 -1
- package/dist/utils/embedCode.js +0 -4
- package/dist/utils/nativeScrollbarPadding.js +1 -1
- package/dist/utils/pickedFile.d.ts +15 -0
- package/dist/utils/pickedFile.js +21 -0
- package/dist/utils/widgeticChatUpload.d.ts +9 -0
- package/dist/utils/widgeticChatUpload.js +24 -2
- package/package.json +5 -3
- package/dist/retiredSurface.test.d.ts +0 -1
- package/dist/retiredSurface.test.js +0 -113
- package/dist/utils/designIntentResolver.test.d.ts +0 -1
- package/dist/utils/designIntentResolver.test.js +0 -246
- package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
- package/dist/utils/designIntentTelemetry.test.js +0 -385
- package/dist/utils/designQuickEditValues.test.d.ts +0 -1
- package/dist/utils/designQuickEditValues.test.js +0 -100
- package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
- package/dist/utils/widgeticChatUpload.test.js +0 -257
package/dist/CreatorApp.svelte
CHANGED
|
@@ -62,6 +62,88 @@
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
/** The bearer token a request carries, or null. */
|
|
66
|
+
function bearerTokenOf(headersInit: HeadersInit | undefined): string | null {
|
|
67
|
+
const value = new Headers(headersInit).get('Authorization');
|
|
68
|
+
return value ? value.replace(/^Bearer\s+/i, '') : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The API's code for a refusal (`EDITOR_SESSION_REVOKED`, `EDITOR_SESSION_EXPIRED` ...), when its answer has one. */
|
|
72
|
+
async function refusalCodeOf(response: Response): Promise<string | undefined> {
|
|
73
|
+
try {
|
|
74
|
+
const body = await response.clone().json();
|
|
75
|
+
const code = body?.error?.code ?? body?.code;
|
|
76
|
+
return typeof code === 'string' && code ? code : undefined;
|
|
77
|
+
} catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Partner mode: when the API turns a token down (401), ask the page for a replacement and send the request once
|
|
84
|
+
* more. The page is asked once per burst of refusals (it is told which token was refused). When the page can only
|
|
85
|
+
* give back the very token the API refused (a session that was revoked), the session is over: the page is told, and
|
|
86
|
+
* neither the page nor the API is asked anything more with that token.
|
|
87
|
+
*/
|
|
88
|
+
const retriedAfterTokenRefresh = new WeakSet<object>();
|
|
89
|
+
/** The token the API refused and the page had no other to give instead. */
|
|
90
|
+
let tokenWithoutReplacement: string | null = null;
|
|
91
|
+
const hostTokenRefreshMiddleware: Middleware = {
|
|
92
|
+
pre: async (context) => {
|
|
93
|
+
// Sent again, it would only be refused again.
|
|
94
|
+
if (tokenWithoutReplacement && bearerTokenOf(context.init.headers) === tokenWithoutReplacement) {
|
|
95
|
+
throw new Error(partnerSessionEndedText());
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
post: async (context) => {
|
|
99
|
+
if (context.response.status !== 401 || retriedAfterTokenRefresh.has(context.init)) return;
|
|
100
|
+
const refusedToken = bearerTokenOf(context.init.headers);
|
|
101
|
+
// The page was already asked about this very token and had nothing else to give.
|
|
102
|
+
if (refusedToken && refusedToken === tokenWithoutReplacement) return;
|
|
103
|
+
const replacement = await adoptHostToken('expired', refusedToken ?? undefined);
|
|
104
|
+
if (!replacement) return;
|
|
105
|
+
if (replacement === refusedToken) {
|
|
106
|
+
tokenWithoutReplacement = refusedToken;
|
|
107
|
+
endHostSession('The API refused the session token and the page has no other to give.', await refusalCodeOf(context.response));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const headers = new Headers(context.init.headers);
|
|
111
|
+
headers.set('Authorization', `Bearer ${replacement}`);
|
|
112
|
+
const retryInit: RequestInit = { ...context.init, headers };
|
|
113
|
+
retriedAfterTokenRefresh.add(retryInit);
|
|
114
|
+
return context.fetch(context.url, retryInit);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Partner mode: the page is told when the API refuses something because the visitor reached a limit (the wallet is
|
|
120
|
+
* empty, the plan does not include it, the storage is full, the customer's budget is used up), once per limit and not
|
|
121
|
+
* once per refused request. What counts as a limit is decided in `host/limitRefusal.ts`. The creator keeps showing the
|
|
122
|
+
* visitor its own neutral message; this is for the partner's page to show whatever it has for it.
|
|
123
|
+
*/
|
|
124
|
+
const limitReporter = createLimitReporter({ report: reportLimitReached });
|
|
125
|
+
const limitReachedMiddleware: Middleware = {
|
|
126
|
+
post: async (context) => {
|
|
127
|
+
const status = context.response.status;
|
|
128
|
+
// Only the few statuses a limit comes with are read: every other answer is left alone.
|
|
129
|
+
if (!answerMayBeALimit(status)) return;
|
|
130
|
+
let body: unknown;
|
|
131
|
+
try {
|
|
132
|
+
body = await context.response.clone().json();
|
|
133
|
+
} catch {
|
|
134
|
+
// An answer that is not JSON did not come from the gateway's error handler, so it is no limit of ours.
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let where: string | undefined;
|
|
138
|
+
try {
|
|
139
|
+
where = `${context.init.method ?? 'GET'} ${new URL(context.url, 'http://localhost').pathname}`;
|
|
140
|
+
} catch {
|
|
141
|
+
where = undefined;
|
|
142
|
+
}
|
|
143
|
+
limitReporter.noteAnswer(status, body, where);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
65
147
|
import {
|
|
66
148
|
normalizeErrorMessage,
|
|
67
149
|
toErrorMessage,
|
|
@@ -74,13 +156,17 @@
|
|
|
74
156
|
sanitizePreviewBuildError,
|
|
75
157
|
isInfrastructurePreviewError
|
|
76
158
|
} from './pageHelpers.js';
|
|
77
|
-
import {
|
|
159
|
+
import {
|
|
160
|
+
ChatUploadRefusedError,
|
|
161
|
+
shouldUseTusForChatUpload,
|
|
162
|
+
uploadChatFileToWidgeticApi
|
|
163
|
+
} from './utils/widgeticChatUpload.js';
|
|
78
164
|
import { persistWidgetThumbnail } from './utils/persistWidgetThumbnail.js';
|
|
79
165
|
import { nativeScrollbarPadding } from './utils/nativeScrollbarPadding.js';
|
|
80
166
|
import { pinScrollToBottom } from './utils/pinScrollToBottom.js';
|
|
81
167
|
import { installFreezeWatchdog, measureSync } from './utils/freezeWatchdog.js';
|
|
82
168
|
import { streamOperationUpdates } from './utils/operationStream.js';
|
|
83
|
-
import { generateEmbedCode, EMBED_FORMATS,
|
|
169
|
+
import { generateEmbedCode, EMBED_FORMATS, type EmbedFormat } from './utils/embedCode.js';
|
|
84
170
|
|
|
85
171
|
function openEmbedTestPage(href: string) {
|
|
86
172
|
if (typeof window === 'undefined') return;
|
|
@@ -91,6 +177,32 @@
|
|
|
91
177
|
import { syncSessionFromSiteAuth } from './syncSiteAuth.js';
|
|
92
178
|
import { setEnableLocalCache, isLocalCacheEnabled } from './localCacheGate.js';
|
|
93
179
|
import type { CreatorAppProps } from './creator-types.js';
|
|
180
|
+
import { shareTextDirection, type TextDirection } from '@widgetic/design-system/components/textDirection';
|
|
181
|
+
import { listAlignedToEnd } from './utils/directionPlacement.js';
|
|
182
|
+
import { conversationLineLabel, embedFormatLabel, errorLabel, provideCreatorLanguage, sentenceParts, splitCreatorMessages, statusLabel, versionDateText } from './i18n/index.js';
|
|
183
|
+
import {
|
|
184
|
+
creatorStorage,
|
|
185
|
+
creatorSessionStorage,
|
|
186
|
+
HOST_VISITOR,
|
|
187
|
+
enterPartnerMode,
|
|
188
|
+
leavePartnerMode,
|
|
189
|
+
isPartnerMode,
|
|
190
|
+
setHostHandlers,
|
|
191
|
+
mayUseAddressBar,
|
|
192
|
+
mayShowAccountBilling,
|
|
193
|
+
mayListenToSiteEvents,
|
|
194
|
+
announceToSite,
|
|
195
|
+
eventIsFromCreator,
|
|
196
|
+
eventPathMatches,
|
|
197
|
+
createDragFeedback,
|
|
198
|
+
getCreatorShadowRoot,
|
|
199
|
+
messageIsFromCreatorFrame,
|
|
200
|
+
reloadThePage,
|
|
201
|
+
reportSessionEnded,
|
|
202
|
+
reportLimitReached,
|
|
203
|
+
reportCanvasUnavailable
|
|
204
|
+
} from './host/creatorHost.js';
|
|
205
|
+
import { answerMayBeALimit, createLimitReporter, responseIsALimit } from './host/limitRefusal.js';
|
|
94
206
|
|
|
95
207
|
function resolveCreatorWorkflowStep(
|
|
96
208
|
step?: CreatorAppProps['initialStep'] | 'create' | 'edit' | 'embed' | null
|
|
@@ -125,6 +237,90 @@
|
|
|
125
237
|
export const onBack: CreatorAppProps['onBack'] = undefined;
|
|
126
238
|
export let onWidgetRenamed: CreatorAppProps['onWidgetRenamed'] = undefined;
|
|
127
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Partner mode (see `CreatorAppProps.getAccessToken`): the page hands over the token and keeps the storage, the
|
|
242
|
+
* address bar and the navigation for itself. Decided once, when the creator starts.
|
|
243
|
+
*/
|
|
244
|
+
export let getAccessToken: CreatorAppProps['getAccessToken'] = undefined;
|
|
245
|
+
export let onSessionEnded: CreatorAppProps['onSessionEnded'] = undefined;
|
|
246
|
+
export let onReloadRequested: CreatorAppProps['onReloadRequested'] = undefined;
|
|
247
|
+
export let onLimitReached: CreatorAppProps['onLimitReached'] = undefined;
|
|
248
|
+
export let onCanvasUnavailable: CreatorAppProps['onCanvasUnavailable'] = undefined;
|
|
249
|
+
export let onCanvasChanged: CreatorAppProps['onCanvasChanged'] = undefined;
|
|
250
|
+
export let onReady: CreatorAppProps['onReady'] = undefined;
|
|
251
|
+
/** The page's own media library for the editor's file pickers (see `CreatorAppProps.mediaLibrary`). */
|
|
252
|
+
export let mediaLibrary: CreatorAppProps['mediaLibrary'] = undefined;
|
|
253
|
+
/**
|
|
254
|
+
* The language of everything the creator shows (see `CreatorAppProps.locale` and `CreatorAppProps.messages`). The one flat
|
|
255
|
+
* `messages` object is split between the creator's own words and the parts it draws: the editor (with its file
|
|
256
|
+
* browser), the chat and the canvas each have a catalog of their own.
|
|
257
|
+
*/
|
|
258
|
+
export let locale: CreatorAppProps['locale'] = null;
|
|
259
|
+
export let messages: CreatorAppProps['messages'] = null;
|
|
260
|
+
const firstLanguageSlices = splitCreatorMessages(messages);
|
|
261
|
+
const language = provideCreatorLanguage({ locale, messages: firstLanguageSlices.creator });
|
|
262
|
+
const editorLanguage = provideEditorLanguage({ locale, messages: firstLanguageSlices.editor });
|
|
263
|
+
// `languageTag` is the language the words are in ('en' unless the page asked for another one); dates are written in it.
|
|
264
|
+
const { t, locale: languageTag } = language;
|
|
265
|
+
/**
|
|
266
|
+
* The direction of the creator's screen (see `CreatorAppProps.dir`). Every part below (the chat, the canvas, the editor with
|
|
267
|
+
* its File Browser and rich text editor) reads it from Svelte's context and follows when the page changes `dir`;
|
|
268
|
+
* `textDirection` is the answer, for the creator's own decisions (where a pop-up opens from, which way a divider drags).
|
|
269
|
+
*/
|
|
270
|
+
export let dir: CreatorAppProps['dir'] = undefined;
|
|
271
|
+
const givenDirection = writable<TextDirection | undefined>(dir);
|
|
272
|
+
const textDirection = shareTextDirection(givenDirection);
|
|
273
|
+
$: givenDirection.set(dir);
|
|
274
|
+
// The page may change the language while the creator is open.
|
|
275
|
+
$: languageSlices = splitCreatorMessages(messages);
|
|
276
|
+
$: language.update({ locale, messages: languageSlices.creator });
|
|
277
|
+
$: editorLanguage.update({ locale, messages: languageSlices.editor });
|
|
278
|
+
$: chatMessages = languageSlices.chat;
|
|
279
|
+
$: canvasMessages = languageSlices.canvas;
|
|
280
|
+
/** The creator's own area of the page (see `eventIsFromCreator`). */
|
|
281
|
+
let creatorRootEl: HTMLElement | null = null;
|
|
282
|
+
const partnerMode = typeof getAccessToken === 'function';
|
|
283
|
+
if (partnerMode) {
|
|
284
|
+
// A creator in a partner's page is always the embedded kind: no sign-in screen, no top bar.
|
|
285
|
+
embedded = true;
|
|
286
|
+
// Before anything below can ask the storage for a sign-in: in partner mode the storage is memory.
|
|
287
|
+
enterPartnerMode({ onSessionEnded, onReloadRequested, onLimitReached, onCanvasUnavailable });
|
|
288
|
+
}
|
|
289
|
+
// The page may hand over new functions while the creator runs.
|
|
290
|
+
$: if (partnerMode) setHostHandlers({ onSessionEnded, onReloadRequested, onLimitReached, onCanvasUnavailable });
|
|
291
|
+
// The page is told which canvas is open whenever that changes (the creator opens one, or makes a new one), so a
|
|
292
|
+
// partner's page can keep the id: the creator leaves the address bar and the storage alone.
|
|
293
|
+
let lastReportedCanvasId: string | null = null;
|
|
294
|
+
$: if (canvasId && canvasId !== lastReportedCanvasId) {
|
|
295
|
+
lastReportedCanvasId = canvasId;
|
|
296
|
+
try {
|
|
297
|
+
onCanvasChanged?.({ canvasId });
|
|
298
|
+
} catch (error) {
|
|
299
|
+
console.error(`[CreatorApp] The page's onCanvasChanged handler threw:`, error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// The page is told once, when the first canvas has loaded (see `markCanvasStateLoaded`), that the creator is ready.
|
|
303
|
+
let readyAnnounced = false;
|
|
304
|
+
function announceReadyOnce(): void {
|
|
305
|
+
if (readyAnnounced) return;
|
|
306
|
+
// A creator that has no canvas to show (the page named one the visitor cannot open) or no session is not ready:
|
|
307
|
+
// the page was told what is wrong instead.
|
|
308
|
+
if (canvasUnavailable || hostSessionEnded) return;
|
|
309
|
+
readyAnnounced = true;
|
|
310
|
+
try {
|
|
311
|
+
onReady?.({ canvasId: canvasId || null });
|
|
312
|
+
} catch (error) {
|
|
313
|
+
console.error(`[CreatorApp] The page's onReady handler threw:`, error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* What every API client of the creator runs its requests through. In a partner's page the limit middleware comes
|
|
318
|
+
* last, so it reads the answer to the request that was sent again with a fresh token, not the refusal before it.
|
|
319
|
+
*/
|
|
320
|
+
const clientMiddleware: Middleware[] = partnerMode
|
|
321
|
+
? [idempotencyKeyMiddleware, hostTokenRefreshMiddleware, limitReachedMiddleware]
|
|
322
|
+
: [idempotencyKeyMiddleware];
|
|
323
|
+
|
|
128
324
|
// Opt-in Dexie owner — reactive to prop changes without $effect (would force runes mode).
|
|
129
325
|
$: setEnableLocalCache(!!enableLocalCache);
|
|
130
326
|
|
|
@@ -161,13 +357,7 @@
|
|
|
161
357
|
// console.log('[CreatorApp] Notify host widget name:', widget.id, name);
|
|
162
358
|
onWidgetRenamed?.({ widgetId: widget.id, name });
|
|
163
359
|
// Also broadcast — mount props can be stale across embed remounts.
|
|
164
|
-
|
|
165
|
-
window.dispatchEvent(
|
|
166
|
-
new CustomEvent('widgetic:creator-primary-renamed', {
|
|
167
|
-
detail: { widgetId: widget.id, name },
|
|
168
|
-
}),
|
|
169
|
-
);
|
|
170
|
-
}
|
|
360
|
+
announceToSite('widgetic:creator-primary-renamed', { widgetId: widget.id, name });
|
|
171
361
|
}
|
|
172
362
|
|
|
173
363
|
/**
|
|
@@ -179,6 +369,8 @@
|
|
|
179
369
|
*/
|
|
180
370
|
function syncEmbeddedCanvasUrl(canvasIdToSync: string): void {
|
|
181
371
|
if (!embedded || !canvasIdToSync) return;
|
|
372
|
+
// A partner's address bar is the partner's: the page learns which canvas is open from the module instead.
|
|
373
|
+
if (!mayUseAddressBar()) return;
|
|
182
374
|
try {
|
|
183
375
|
const url = new URL(window.location.href);
|
|
184
376
|
url.pathname = `/canvas/${encodeURIComponent(canvasIdToSync)}`;
|
|
@@ -253,7 +445,7 @@
|
|
|
253
445
|
function handleHostRequestPublishEvent(): void {
|
|
254
446
|
const targetId = focusedPanelWidgetId || selectedWidgetId;
|
|
255
447
|
if (!targetId) {
|
|
256
|
-
showToast('error', '
|
|
448
|
+
showToast('error', $t('creator.publish.cannotPublish'), { description: $t('creator.widget.noWidgetSelected') });
|
|
257
449
|
return;
|
|
258
450
|
}
|
|
259
451
|
// console.log('[CreatorApp] Host requested publish for', targetId.substring(0, 8));
|
|
@@ -266,7 +458,9 @@
|
|
|
266
458
|
|
|
267
459
|
// Sync JWT before reactive blocks run (avoids false "No JWT" on first paint in embedded or standalone)
|
|
268
460
|
if (typeof window !== 'undefined') {
|
|
269
|
-
if (
|
|
461
|
+
if (partnerMode) {
|
|
462
|
+
// The sign-in comes from the page (adoptHostToken, below), never from the browser's storage.
|
|
463
|
+
} else if (embedded) {
|
|
270
464
|
syncSessionFromSiteAuth();
|
|
271
465
|
} else {
|
|
272
466
|
restoreSession();
|
|
@@ -304,6 +498,8 @@
|
|
|
304
498
|
}
|
|
305
499
|
|
|
306
500
|
function buildCompositionProjectFields(widgetId?: string | null): { projectId?: string } {
|
|
501
|
+
// A visitor in a partner's page has no project of the Widgetic site, and the gateway refuses the field for a session.
|
|
502
|
+
if (partnerMode) return {};
|
|
307
503
|
const resolvedProjectId = resolveCompositionProjectId(widgetId);
|
|
308
504
|
return resolvedProjectId ? { projectId: resolvedProjectId } : {};
|
|
309
505
|
}
|
|
@@ -317,7 +513,7 @@
|
|
|
317
513
|
/**
|
|
318
514
|
* WIDGETIC EDITOR — PropsEditor for design/content property editing
|
|
319
515
|
*/
|
|
320
|
-
import { PropsEditor, setFileBrowserUploadConfig, setGoogleFontsApiKey } from '@widgetic/editor';
|
|
516
|
+
import { PropsEditor, provideEditorLanguage, setFileBrowserUploadConfig, setGoogleFontsApiKey } from '@widgetic/editor';
|
|
321
517
|
|
|
322
518
|
// API root: embedded hosts pass apiUrl; standalone uses VITE_API_URL / PUBLIC_API_URL.
|
|
323
519
|
// If unset, @widgetic/api-sdk falls back to BASE_PATH = dev-api.widgetic.com (OpenAPI default).
|
|
@@ -348,7 +544,7 @@
|
|
|
348
544
|
let messagesClient: MessagesApi;
|
|
349
545
|
let compositionsClient: CompositionsApi;
|
|
350
546
|
let uploadsClient: UploadsApi;
|
|
351
|
-
let usersClient: UsersApi;
|
|
547
|
+
let usersClient: UsersApi | null = null;
|
|
352
548
|
/** Credits, and days left while the account is still on the free trial. */
|
|
353
549
|
let trialCounter: { credits: number; days: number | null; trialEnded: boolean } | null = null;
|
|
354
550
|
|
|
@@ -370,35 +566,39 @@
|
|
|
370
566
|
setWebsocketApiUrl(apiRoot ?? null);
|
|
371
567
|
|
|
372
568
|
canvasesClient = apiBasePath
|
|
373
|
-
? new CanvasesApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
374
|
-
: new CanvasesApi({ accessToken: token, middleware:
|
|
569
|
+
? new CanvasesApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
570
|
+
: new CanvasesApi({ accessToken: token, middleware: clientMiddleware });
|
|
375
571
|
widgetsClient = apiBasePath
|
|
376
|
-
? new WidgetsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
377
|
-
: new WidgetsApi({ accessToken: token, middleware:
|
|
572
|
+
? new WidgetsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
573
|
+
: new WidgetsApi({ accessToken: token, middleware: clientMiddleware });
|
|
378
574
|
componentsClient = apiBasePath
|
|
379
|
-
? new ComponentsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
380
|
-
: new ComponentsApi({ accessToken: token, middleware:
|
|
575
|
+
? new ComponentsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
576
|
+
: new ComponentsApi({ accessToken: token, middleware: clientMiddleware });
|
|
381
577
|
agentClient = apiBasePath
|
|
382
|
-
? new AgentApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
383
|
-
: new AgentApi({ accessToken: token, middleware:
|
|
578
|
+
? new AgentApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
579
|
+
: new AgentApi({ accessToken: token, middleware: clientMiddleware });
|
|
384
580
|
operationsClient = apiBasePath
|
|
385
|
-
? new OperationsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
386
|
-
: new OperationsApi({ accessToken: token, middleware:
|
|
581
|
+
? new OperationsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
582
|
+
: new OperationsApi({ accessToken: token, middleware: clientMiddleware });
|
|
387
583
|
conversationsClient = apiBasePath
|
|
388
|
-
? new ConversationsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
389
|
-
: new ConversationsApi({ accessToken: token, middleware:
|
|
584
|
+
? new ConversationsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
585
|
+
: new ConversationsApi({ accessToken: token, middleware: clientMiddleware });
|
|
390
586
|
messagesClient = apiBasePath
|
|
391
|
-
? new MessagesApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
392
|
-
: new MessagesApi({ accessToken: token, middleware:
|
|
587
|
+
? new MessagesApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
588
|
+
: new MessagesApi({ accessToken: token, middleware: clientMiddleware });
|
|
393
589
|
compositionsClient = apiBasePath
|
|
394
|
-
? new CompositionsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
395
|
-
: new CompositionsApi({ accessToken: token, middleware:
|
|
590
|
+
? new CompositionsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
591
|
+
: new CompositionsApi({ accessToken: token, middleware: clientMiddleware });
|
|
396
592
|
uploadsClient = apiBasePath
|
|
397
|
-
? new UploadsApi({ basePath: apiBasePath, accessToken: token, middleware:
|
|
398
|
-
: new UploadsApi({ accessToken: token, middleware:
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
593
|
+
? new UploadsApi({ basePath: apiBasePath, accessToken: token, middleware: clientMiddleware })
|
|
594
|
+
: new UploadsApi({ accessToken: token, middleware: clientMiddleware });
|
|
595
|
+
// The trial and credit counter is an account matter: a visitor of a partner has none, and a session may not ask for it
|
|
596
|
+
// (so there is no client for it at all, and nothing can ask by mistake).
|
|
597
|
+
usersClient = partnerMode
|
|
598
|
+
? null
|
|
599
|
+
: apiBasePath
|
|
600
|
+
? new UsersApi({ basePath: apiBasePath, accessToken: token })
|
|
601
|
+
: new UsersApi({ accessToken: token });
|
|
402
602
|
|
|
403
603
|
authenticatedClientsToken = token;
|
|
404
604
|
try {
|
|
@@ -410,9 +610,96 @@
|
|
|
410
610
|
void refreshTrialCounter();
|
|
411
611
|
}
|
|
412
612
|
|
|
613
|
+
/** Partner mode: the page could not give the creator a token the API accepts, so nothing it asks can go through. */
|
|
614
|
+
let hostSessionEnded = false;
|
|
615
|
+
/** Partner mode: how often the creator takes the token the page holds, so a renewed one reaches the API clients. */
|
|
616
|
+
const HOST_TOKEN_PUMP_MS = 20_000;
|
|
617
|
+
let hostTokenPump: ReturnType<typeof setInterval> | null = null;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Partner mode: takes the token the page holds (`'initial'`) or, when the API has just refused one, a replacement
|
|
621
|
+
* for it (`'expired'`), and makes it the one the creator calls the API with. Resolves with the token, or null when
|
|
622
|
+
* the page could not give one. A failed replacement ends the session; a later successful call revives it.
|
|
623
|
+
*/
|
|
624
|
+
async function adoptHostToken(reason: 'initial' | 'expired', refusedToken?: string): Promise<string | null> {
|
|
625
|
+
if (!partnerMode || typeof getAccessToken !== 'function') return null;
|
|
626
|
+
try {
|
|
627
|
+
const token = await getAccessToken(reason, refusedToken);
|
|
628
|
+
if (typeof token !== 'string' || token.trim() === '') {
|
|
629
|
+
throw new Error('The page did not give the creator a token');
|
|
630
|
+
}
|
|
631
|
+
// Only another token revives a session: the very token the API refused would end it again at once.
|
|
632
|
+
if (hostSessionEnded && token !== tokenWithoutReplacement) {
|
|
633
|
+
hostSessionEnded = false;
|
|
634
|
+
}
|
|
635
|
+
if (token !== $userSession.jwt || !$userSession.user) {
|
|
636
|
+
// The reactive statement on $userSession binds the API clients to the new token.
|
|
637
|
+
setSession(HOST_VISITOR, token);
|
|
638
|
+
}
|
|
639
|
+
return token;
|
|
640
|
+
} catch (error) {
|
|
641
|
+
console.warn('[CreatorApp] The page could not give the creator a token', error);
|
|
642
|
+
if (reason === 'expired') {
|
|
643
|
+
// Asked about this token and had nothing to give: it is not asked again for the same one.
|
|
644
|
+
if (refusedToken) tokenWithoutReplacement = refusedToken;
|
|
645
|
+
endHostSession(
|
|
646
|
+
error instanceof Error && error.message ? error.message : 'The session could not be renewed.',
|
|
647
|
+
'TOKEN_REFRESH_FAILED'
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** Partner mode: nothing more can be asked of the API. Tells the page (once per ending) and shows the visitor. */
|
|
655
|
+
function endHostSession(message: string, code?: string): void {
|
|
656
|
+
const alreadyEnded = hostSessionEnded;
|
|
657
|
+
hostSessionEnded = true;
|
|
658
|
+
updateTokenStatus();
|
|
659
|
+
if (alreadyEnded) return;
|
|
660
|
+
// The visitor is told in plain words whatever the cause was; the reason goes to the page, not to the visitor.
|
|
661
|
+
showToast('warning', $t('creator.session.sessionEnded'), { description: partnerSessionEndedText(), duration: 8000 });
|
|
662
|
+
reportSessionEnded({ message, code });
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/** In a partner's page there is no sign-in to offer a visitor whose session is gone, only a new one the page starts. */
|
|
666
|
+
function partnerSessionEndedText(): string {
|
|
667
|
+
return $t('creator.session.endedStartAgain');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** What to tell the visitor when their sign-in is gone: the site's wording, or the neutral one in a partner's page. */
|
|
671
|
+
function signInAgainText(siteText: string): string {
|
|
672
|
+
return partnerMode ? partnerSessionEndedText() : siteText;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Partner mode: the canvas the page named is not one this visitor can open (the API answers as if it did not exist for
|
|
677
|
+
* them). There is nothing to show or to save then, and asking again would not change the answer.
|
|
678
|
+
*/
|
|
679
|
+
let canvasUnavailable = false;
|
|
680
|
+
function partnerCanvasUnavailableText(): string {
|
|
681
|
+
return $t('creator.session.canvasCannotOpen');
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Says so once: on the creator's own screen and to the page, and stops everything that would ask for the canvas again. */
|
|
685
|
+
function declareCanvasUnavailable(unavailableCanvasId: string | null, message: string, code = 'NOT_FOUND'): void {
|
|
686
|
+
if (canvasUnavailable) return;
|
|
687
|
+
canvasUnavailable = true;
|
|
688
|
+
clearCanvasLoadFailsafe();
|
|
689
|
+
clearCanvasHydrateRetry();
|
|
690
|
+
canvasApiLoadError = partnerCanvasUnavailableText();
|
|
691
|
+
reportCanvasUnavailable({ canvasId: unavailableCanvasId, message, code });
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** Partner mode: does this error from the API say that there is no such canvas (for this visitor)? */
|
|
695
|
+
function saysCanvasIsMissing(err: unknown): boolean {
|
|
696
|
+
return partnerMode && err instanceof ResponseError && err.response?.status === 404;
|
|
697
|
+
}
|
|
698
|
+
|
|
413
699
|
/** Credits left and days left, from the same billing status the publish gate uses. */
|
|
414
700
|
async function refreshTrialCounter() {
|
|
415
|
-
|
|
701
|
+
// An account matter: a visitor of a partner has no trial and no balance of their own to show.
|
|
702
|
+
if (!usersClient || !mayShowAccountBilling()) return;
|
|
416
703
|
try {
|
|
417
704
|
const accepted = await usersClient.usersMeBillingGetRaw();
|
|
418
705
|
const body = await accepted.raw.json();
|
|
@@ -436,27 +723,27 @@
|
|
|
436
723
|
days: paidPlan || days == null || !Number.isFinite(days) ? null : Math.max(0, Math.round(days)),
|
|
437
724
|
trialEnded: !paidPlan && days === 0,
|
|
438
725
|
};
|
|
439
|
-
|
|
440
|
-
window.dispatchEvent(new CustomEvent('widgetic:trial-counter'));
|
|
441
|
-
}
|
|
726
|
+
announceToSite('widgetic:trial-counter');
|
|
442
727
|
} catch (error) {
|
|
443
728
|
console.warn('[Trial] Could not load the credit counter', error);
|
|
444
729
|
}
|
|
445
730
|
}
|
|
446
731
|
|
|
447
732
|
function applySiteSessionToCreator(): boolean {
|
|
733
|
+
// Partner mode has no site session. A refused token is replaced by the middleware that sees the refusal.
|
|
734
|
+
if (partnerMode) return hasValidToken;
|
|
448
735
|
const synced = syncSessionFromSiteAuth();
|
|
449
736
|
if (!synced) return false;
|
|
450
737
|
try {
|
|
451
|
-
const sessionStr =
|
|
738
|
+
const sessionStr = creatorStorage.getItem('session');
|
|
452
739
|
const session = sessionStr ? JSON.parse(sessionStr) : null;
|
|
453
740
|
currentUserToken =
|
|
454
741
|
session?.accessToken ||
|
|
455
742
|
session?.access_token ||
|
|
456
|
-
|
|
743
|
+
creatorStorage.getItem('jwt') ||
|
|
457
744
|
currentUserToken;
|
|
458
745
|
} catch {
|
|
459
|
-
currentUserToken =
|
|
746
|
+
currentUserToken = creatorStorage.getItem('jwt') || currentUserToken;
|
|
460
747
|
}
|
|
461
748
|
if (currentUserToken) {
|
|
462
749
|
authenticatedClientsToken = null;
|
|
@@ -582,6 +869,7 @@
|
|
|
582
869
|
import {
|
|
583
870
|
recordDesignIntentTelemetry,
|
|
584
871
|
recordDesignIntentJevOutcome,
|
|
872
|
+
installDesignIntentTelemetryConsoleHandle,
|
|
585
873
|
isJevCandidateBucket,
|
|
586
874
|
type DesignIntentClassification
|
|
587
875
|
} from './utils/designIntentTelemetry';
|
|
@@ -650,11 +938,19 @@
|
|
|
650
938
|
const canvasModule = await canvasModulePromise;
|
|
651
939
|
// Installed before the canvas mounts so the first save already externalizes
|
|
652
940
|
installCanvasThumbnailStore(canvasModule);
|
|
941
|
+
// The canvas keeps the visitor's saved colors where the creator keeps its own memory: the browser's
|
|
942
|
+
// storage, except in a partner's page, where it is memory (a partner's page is not written to).
|
|
943
|
+
canvasModule.setCanvasPreferenceStorage?.(creatorStorage);
|
|
653
944
|
WidgeticCanvas = canvasModule.Canvas;
|
|
654
945
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
946
|
+
// Widgetic's own diagnostics (a watchdog worker, long-task observers and console handles on `window`) belong
|
|
947
|
+
// to the pages Widgetic owns; a partner's page gets none of them.
|
|
948
|
+
if (!isPartnerMode()) {
|
|
949
|
+
installLongTaskFreezeReporter();
|
|
950
|
+
installFreezeWatchdog();
|
|
951
|
+
installDesignIntentTelemetryConsoleHandle();
|
|
952
|
+
console.info('[FreezeWatchdog] Freeze reports log on this page. In DevTools, pick the top frame — not a widget iframe.');
|
|
953
|
+
}
|
|
658
954
|
});
|
|
659
955
|
|
|
660
956
|
/**
|
|
@@ -701,7 +997,6 @@
|
|
|
701
997
|
/**
|
|
702
998
|
* CONSTANTS
|
|
703
999
|
*/
|
|
704
|
-
import { page as pageStore } from '$app/stores';
|
|
705
1000
|
import { maxCharsFromId } from './constants.js';
|
|
706
1001
|
import {
|
|
707
1002
|
saveCanvasState,
|
|
@@ -826,7 +1121,7 @@
|
|
|
826
1121
|
let canvasApiLoadError: string | null = null;
|
|
827
1122
|
let canvasShapesMissingWarning = false;
|
|
828
1123
|
let lastSavedCanvasObjectCount = (() => {
|
|
829
|
-
try { return parseInt(
|
|
1124
|
+
try { return parseInt(creatorSessionStorage.getItem(CANVAS_OBJ_COUNT_KEY) || '0', 10) || 0; }
|
|
830
1125
|
catch { return 0; }
|
|
831
1126
|
})();
|
|
832
1127
|
|
|
@@ -878,7 +1173,7 @@
|
|
|
878
1173
|
break;
|
|
879
1174
|
case 'keep-in-db':
|
|
880
1175
|
deleteDialogOpen = false;
|
|
881
|
-
showToast('info', '
|
|
1176
|
+
showToast('info', $t('creator.widget.shapeRemoved'), { description: $t('creator.widget.widgetKeptInDatabase') });
|
|
882
1177
|
break;
|
|
883
1178
|
case 'delete-from-db':
|
|
884
1179
|
deleteDialogOpen = false;
|
|
@@ -902,7 +1197,7 @@
|
|
|
902
1197
|
if (selectedWidgetId === widgetId) {
|
|
903
1198
|
selectedWidgetId = null;
|
|
904
1199
|
}
|
|
905
|
-
showToast('success', '
|
|
1200
|
+
showToast('success', $t('creator.widget.widgetDeletedFromDatabase'));
|
|
906
1201
|
} catch (err) {
|
|
907
1202
|
// A shape can outlive its widget row (deleted from the Projects page or
|
|
908
1203
|
// another session). The canvas only needs the shape and local entry gone,
|
|
@@ -914,13 +1209,13 @@
|
|
|
914
1209
|
if (selectedWidgetId === widgetId) {
|
|
915
1210
|
selectedWidgetId = null;
|
|
916
1211
|
}
|
|
917
|
-
showToast('info', '
|
|
918
|
-
description: '
|
|
1212
|
+
showToast('info', $t('creator.widget.widgetWasAlreadyDeleted'), {
|
|
1213
|
+
description: $t('creator.canvas.removedTheLeftoverShapeFrom'),
|
|
919
1214
|
});
|
|
920
1215
|
return;
|
|
921
1216
|
}
|
|
922
1217
|
console.error('[WidgetCreator] Failed to delete widget from DB:', err);
|
|
923
|
-
showToast('error', '
|
|
1218
|
+
showToast('error', $t('creator.widget.failedToDeleteWidgetFrom'));
|
|
924
1219
|
}
|
|
925
1220
|
}
|
|
926
1221
|
|
|
@@ -928,10 +1223,10 @@
|
|
|
928
1223
|
function saveSelectedWidgetId(widgetId: string | null) {
|
|
929
1224
|
try {
|
|
930
1225
|
if (widgetId) {
|
|
931
|
-
|
|
1226
|
+
creatorStorage.setItem(SELECTED_WIDGET_STORAGE_KEY, widgetId);
|
|
932
1227
|
// console.log('[WidgetCreator] Saved selected widget ID to localStorage:', widgetId);
|
|
933
1228
|
} else {
|
|
934
|
-
|
|
1229
|
+
creatorStorage.removeItem(SELECTED_WIDGET_STORAGE_KEY);
|
|
935
1230
|
// console.log('[WidgetCreator] Cleared selected widget ID from localStorage');
|
|
936
1231
|
}
|
|
937
1232
|
} catch (e) {
|
|
@@ -942,7 +1237,7 @@
|
|
|
942
1237
|
// Helper function to get saved widget ID from localStorage
|
|
943
1238
|
function getSavedSelectedWidgetId(): string | null {
|
|
944
1239
|
try {
|
|
945
|
-
return
|
|
1240
|
+
return creatorStorage.getItem(SELECTED_WIDGET_STORAGE_KEY);
|
|
946
1241
|
} catch (e) {
|
|
947
1242
|
console.warn('[WidgetCreator] Failed to get selected widget ID from localStorage:', e);
|
|
948
1243
|
return null;
|
|
@@ -952,9 +1247,9 @@
|
|
|
952
1247
|
function saveSelectedCanvasId(id: string | null) {
|
|
953
1248
|
try {
|
|
954
1249
|
if (id) {
|
|
955
|
-
|
|
1250
|
+
creatorStorage.setItem(SELECTED_CANVAS_STORAGE_KEY, id);
|
|
956
1251
|
} else {
|
|
957
|
-
|
|
1252
|
+
creatorStorage.removeItem(SELECTED_CANVAS_STORAGE_KEY);
|
|
958
1253
|
}
|
|
959
1254
|
} catch (e) {
|
|
960
1255
|
console.warn('[WidgetCreator] Failed to save canvas ID to localStorage:', e);
|
|
@@ -970,7 +1265,7 @@
|
|
|
970
1265
|
|
|
971
1266
|
function getSavedSelectedCanvasId(): string | null {
|
|
972
1267
|
try {
|
|
973
|
-
return
|
|
1268
|
+
return creatorStorage.getItem(SELECTED_CANVAS_STORAGE_KEY);
|
|
974
1269
|
} catch (e) {
|
|
975
1270
|
return null;
|
|
976
1271
|
}
|
|
@@ -992,15 +1287,17 @@
|
|
|
992
1287
|
return isGeneratingCode || Object.keys(generatingWidgetIds).some((id) => generatingWidgetIds[id]);
|
|
993
1288
|
}
|
|
994
1289
|
|
|
995
|
-
/**
|
|
1290
|
+
/**
|
|
1291
|
+
* Synchronous hold so a screenshot cannot postMessage after codegen has started. Kept in the component, not on
|
|
1292
|
+
* `window`: nothing else reads it, and a partner's page is not a place to leave globals.
|
|
1293
|
+
*/
|
|
1294
|
+
let codegenActiveCount = 0;
|
|
996
1295
|
function noteCodegenActive(active: boolean): void {
|
|
997
|
-
|
|
998
|
-
const holder = window as Window & { __widgeticCodegenCount?: number };
|
|
999
|
-
holder.__widgeticCodegenCount = Math.max(0, (holder.__widgeticCodegenCount || 0) + (active ? 1 : -1));
|
|
1296
|
+
codegenActiveCount = Math.max(0, codegenActiveCount + (active ? 1 : -1));
|
|
1000
1297
|
}
|
|
1001
1298
|
|
|
1002
1299
|
function codegenCaptureBlocked(): boolean {
|
|
1003
|
-
if (
|
|
1300
|
+
if (codegenActiveCount > 0) {
|
|
1004
1301
|
return true;
|
|
1005
1302
|
}
|
|
1006
1303
|
if (isAnyWidgetGenerating()) return true;
|
|
@@ -1018,6 +1315,11 @@
|
|
|
1018
1315
|
}
|
|
1019
1316
|
|
|
1020
1317
|
function openUpgradePlans() {
|
|
1318
|
+
if (partnerMode) {
|
|
1319
|
+
// A visitor of a partner has no plan of their own to upgrade: the page decides what a limit means for them.
|
|
1320
|
+
reportLimitReached({ message: 'The visitor reached a limit.', code: 'LIMIT_REACHED' });
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1021
1323
|
window.location.assign('/workspaces/personal/settings/billing');
|
|
1022
1324
|
}
|
|
1023
1325
|
let lastGenerationError: string | null = null; // Store the error message for display
|
|
@@ -1156,8 +1458,8 @@
|
|
|
1156
1458
|
return await processImageFile(imageFile);
|
|
1157
1459
|
} catch (error) {
|
|
1158
1460
|
console.error('[Chat→CodeGen] Failed to load uploaded image URL:', uploadedUrl, error);
|
|
1159
|
-
showToast('error', '
|
|
1160
|
-
description: '
|
|
1461
|
+
showToast('error', $t('creator.general.couldNotLoadUploadedImage'), {
|
|
1462
|
+
description: $t('creator.general.tryUploadingTheImageAgain'),
|
|
1161
1463
|
duration: 6000,
|
|
1162
1464
|
});
|
|
1163
1465
|
return null;
|
|
@@ -1190,21 +1492,36 @@
|
|
|
1190
1492
|
console.warn('[Chat→Upload] WebP convert skipped, using original file', error);
|
|
1191
1493
|
}
|
|
1192
1494
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1495
|
+
// A visitor's session cannot use the resumable (TUS) upload the gateway keeps for bigger files,
|
|
1496
|
+
// so say so up front instead of failing halfway (the File Browser module does the same).
|
|
1497
|
+
if (partnerMode && shouldUseTusForChatUpload(uploadFile)) {
|
|
1498
|
+
throw new Error('This file is too large to attach here (the limit is 10 MB).');
|
|
1499
|
+
}
|
|
1500
|
+
let result: Awaited<ReturnType<typeof uploadChatFileToWidgeticApi>>;
|
|
1501
|
+
try {
|
|
1502
|
+
result = await uploadChatFileToWidgeticApi(
|
|
1503
|
+
uploadFile,
|
|
1504
|
+
{
|
|
1505
|
+
apiBasePath: uploadBasePath,
|
|
1506
|
+
accessToken: authenticatedClientsToken,
|
|
1507
|
+
contextType: options?.source === 'preview-screenshot' ? 'browser-ic' : 'widget-codegen',
|
|
1508
|
+
source: options?.source || 'chat-upload',
|
|
1509
|
+
widgetId: persistWidgetId && !isDraftConvertId(persistWidgetId) ? persistWidgetId : undefined,
|
|
1510
|
+
conversationId:
|
|
1511
|
+
currentChatConversationId && !isLocalOnlyConversationId(currentChatConversationId)
|
|
1512
|
+
? currentChatConversationId
|
|
1513
|
+
: undefined,
|
|
1514
|
+
},
|
|
1515
|
+
{ onProgress: options?.onProgress },
|
|
1516
|
+
);
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
// This upload does not go through the API clients, so their middleware did not see the refusal: a full storage
|
|
1519
|
+
// allowance is a limit the page is told about, like the others (the chat still shows its own message).
|
|
1520
|
+
if (partnerMode && error instanceof ChatUploadRefusedError) {
|
|
1521
|
+
limitReporter.noteAnswer(error.status, error.body, 'POST /v1/uploads');
|
|
1522
|
+
}
|
|
1523
|
+
throw error;
|
|
1524
|
+
}
|
|
1208
1525
|
// console.log('[Chat→Upload] Stored attachment:', {
|
|
1209
1526
|
// id: result.id,
|
|
1210
1527
|
// url: result.url.slice(0, 80),
|
|
@@ -1293,10 +1610,10 @@
|
|
|
1293
1610
|
void deleteWidgetDraft(codegenWidgetId).catch(() => {
|
|
1294
1611
|
// Also drop the legacy localStorage copies if the durable clear fails.
|
|
1295
1612
|
try {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1613
|
+
creatorStorage.removeItem(PROMPT_IMAGES_STORAGE_PREFIX + codegenWidgetId);
|
|
1614
|
+
creatorStorage.removeItem(CHAT_DRAFT_STORAGE_PREFIX + codegenWidgetId);
|
|
1615
|
+
creatorStorage.removeItem(PROMPT_TEXT_STORAGE_PREFIX + codegenWidgetId);
|
|
1616
|
+
creatorStorage.removeItem(PROMPT_IMAGES_STORAGE_KEY);
|
|
1300
1617
|
} catch {
|
|
1301
1618
|
/* ignore */
|
|
1302
1619
|
}
|
|
@@ -1348,8 +1665,8 @@
|
|
|
1348
1665
|
);
|
|
1349
1666
|
if (!hasImages && !hasNonImageFiles && promptImpliesVisionReference(content)) {
|
|
1350
1667
|
const missingImageError =
|
|
1351
|
-
'
|
|
1352
|
-
showToast('warning', '
|
|
1668
|
+
$t('creator.codegen.missingImageError');
|
|
1669
|
+
showToast('warning', $t('creator.codegen.missingReferenceImage'), {
|
|
1353
1670
|
description: missingImageError,
|
|
1354
1671
|
duration: 10000,
|
|
1355
1672
|
});
|
|
@@ -1565,7 +1882,7 @@
|
|
|
1565
1882
|
// console.log('[Chat] Conversation marked', next ? 'completed' : 'active', conversationId);
|
|
1566
1883
|
} catch (error) {
|
|
1567
1884
|
console.error('[Chat] Failed to persist conversation completed:', error);
|
|
1568
|
-
showToast('error', '
|
|
1885
|
+
showToast('error', $t('creator.general.couldNotUpdateConversationStatus'));
|
|
1569
1886
|
conversationCompletedByWidgetId = { ...conversationCompletedByWidgetId, [widgetId]: !next };
|
|
1570
1887
|
}
|
|
1571
1888
|
}
|
|
@@ -1724,6 +2041,13 @@
|
|
|
1724
2041
|
if (Array.isArray(body)) return body;
|
|
1725
2042
|
if (Array.isArray(nested)) return nested;
|
|
1726
2043
|
if (Array.isArray(envelopeData)) return envelopeData;
|
|
2044
|
+
// An answer that carries error or message (the apiRequest envelope) is not an empty list:
|
|
2045
|
+
// throw it, as the loader did before the raw read, so the caller shows the message instead
|
|
2046
|
+
// of a blank list. A refused request (a 404 for a canvas that is not there) is thrown as a
|
|
2047
|
+
// ResponseError by the client itself, before this point.
|
|
2048
|
+
if (body && (body.error || body.message)) {
|
|
2049
|
+
throw new Error(String(body.message || body.error));
|
|
2050
|
+
}
|
|
1727
2051
|
return [];
|
|
1728
2052
|
}
|
|
1729
2053
|
|
|
@@ -1963,15 +2287,17 @@
|
|
|
1963
2287
|
*/
|
|
1964
2288
|
function resolveLiveWidgetShapeIframe(widgetId: string | null | undefined): HTMLIFrameElement | null {
|
|
1965
2289
|
const targetId = widgetId || focusedPanelWidgetId || selectedWidgetId;
|
|
2290
|
+
// The tree the creator is in: in a partner's page `document.querySelector` cannot see into its shadow root.
|
|
2291
|
+
const searchRoot = getCreatorShadowRoot(creatorRootEl) ?? document;
|
|
1966
2292
|
if (targetId) {
|
|
1967
|
-
const liveById =
|
|
2293
|
+
const liveById = searchRoot.querySelector(
|
|
1968
2294
|
`iframe.widget-shape-live-preview-iframe[data-widget-id="${CSS.escape(targetId)}"]`,
|
|
1969
2295
|
) as HTMLIFrameElement | null;
|
|
1970
2296
|
return liveById?.contentWindow ? liveById : null;
|
|
1971
2297
|
}
|
|
1972
2298
|
// No id known: only unambiguous when exactly one shape is mounted.
|
|
1973
2299
|
const all = Array.from(
|
|
1974
|
-
|
|
2300
|
+
searchRoot.querySelectorAll('iframe.widget-shape-live-preview-iframe'),
|
|
1975
2301
|
) as HTMLIFrameElement[];
|
|
1976
2302
|
const withWindow = all.filter((frame) => !!frame.contentWindow);
|
|
1977
2303
|
return withWindow.length === 1 ? withWindow[0] : null;
|
|
@@ -2057,14 +2383,15 @@
|
|
|
2057
2383
|
host.className = 'wc-hidden-screenshot-host';
|
|
2058
2384
|
host.setAttribute(
|
|
2059
2385
|
'style',
|
|
2060
|
-
'position:fixed;left:-10000px;top:0;width:800px;height:600px;opacity:0;pointer-events:none;z-index:-1;',
|
|
2386
|
+
'position:fixed;left:-10000px;top:0;width:800px;height:600px;opacity:0;pointer-events:none;z-index:-1;', // rtl-ok: parked far outside the screen where nobody sees it, whatever the direction
|
|
2061
2387
|
);
|
|
2062
2388
|
const iframe = document.createElement('iframe');
|
|
2063
2389
|
iframe.title = 'Hidden widget screenshot';
|
|
2064
2390
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms');
|
|
2065
2391
|
iframe.style.cssText = 'width:800px;height:600px;border:0;';
|
|
2066
2392
|
host.appendChild(iframe);
|
|
2067
|
-
|
|
2393
|
+
// In the creator's own tree: in a partner's page the creator must not put a frame in the page's <body>.
|
|
2394
|
+
(getCreatorShadowRoot(creatorRootEl) ?? document.body).appendChild(host);
|
|
2068
2395
|
|
|
2069
2396
|
try {
|
|
2070
2397
|
await new Promise<void>((resolve, reject) => {
|
|
@@ -2672,10 +2999,10 @@
|
|
|
2672
2999
|
syncWidgetShapeLivePreviews();
|
|
2673
3000
|
panelDisplayRevision += 1;
|
|
2674
3001
|
}
|
|
2675
|
-
showToast('success', undoMode ? '
|
|
3002
|
+
showToast('success', undoMode ? $t('creator.general.changeUndone') : $t('creator.version.checkpointRestored'), {
|
|
2676
3003
|
description: undoMode
|
|
2677
|
-
?
|
|
2678
|
-
:
|
|
3004
|
+
? $t('creator.codegen.codeRevertedToCommitRefreshing', { commit: formatCommitShaShort(historicalSha) })
|
|
3005
|
+
: $t('creator.codegen.widgetCodeAtCommitRefreshing', { commit: formatCommitShaShort(historicalSha) }),
|
|
2679
3006
|
duration: 6000,
|
|
2680
3007
|
});
|
|
2681
3008
|
liveDesignValues = {};
|
|
@@ -2719,8 +3046,8 @@
|
|
|
2719
3046
|
void scheduleBuildRetry();
|
|
2720
3047
|
} else {
|
|
2721
3048
|
console.warn('[Chat→Backend] Git rollback not detected in response, refreshing preview anyway...');
|
|
2722
|
-
showToast('warning', '
|
|
2723
|
-
description: '
|
|
3049
|
+
showToast('warning', $t('creator.version.restoreCompletedWithWarnings'), {
|
|
3050
|
+
description: $t('creator.codegen.gitRollbackMayNotHave'),
|
|
2724
3051
|
duration: 8000,
|
|
2725
3052
|
});
|
|
2726
3053
|
liveDesignValues = {};
|
|
@@ -2736,8 +3063,8 @@
|
|
|
2736
3063
|
return data;
|
|
2737
3064
|
} catch (error) {
|
|
2738
3065
|
console.error('[Chat→Backend] Failed to restore checkpoint:', error);
|
|
2739
|
-
showToast('error', '
|
|
2740
|
-
description: error instanceof Error ? error.message : '
|
|
3066
|
+
showToast('error', $t('creator.version.failedToRestoreCheckpoint'), {
|
|
3067
|
+
description: error instanceof Error ? error.message : $t('creator.general.unknownError'),
|
|
2741
3068
|
});
|
|
2742
3069
|
return null;
|
|
2743
3070
|
}
|
|
@@ -2813,7 +3140,8 @@
|
|
|
2813
3140
|
/** The version whose title rename is in flight, as `widgetId:version`. */
|
|
2814
3141
|
let renamingTitleFor: string | null = null;
|
|
2815
3142
|
let liveHistoryPanelTop = 0;
|
|
2816
|
-
|
|
3143
|
+
/** The edge of the publish history list that lines up with the header cluster, as style text: it is the end edge of the cluster. */
|
|
3144
|
+
let liveHistoryPanelPlacement = '';
|
|
2817
3145
|
/** True once publish history fetch completed for the current widget (or widget was never published). */
|
|
2818
3146
|
let publishHistoryResolved = false;
|
|
2819
3147
|
let publishHistoryResolvedForWidgetId: string | null = null;
|
|
@@ -3393,7 +3721,7 @@
|
|
|
3393
3721
|
contentSchema = normalizeContentSchemaFromApiResponse(contentRes);
|
|
3394
3722
|
|
|
3395
3723
|
if (!designSchema && !contentSchema) {
|
|
3396
|
-
schemaError = '
|
|
3724
|
+
schemaError = $t('creator.publish.noEditableSettingsFoundGenerate');
|
|
3397
3725
|
}
|
|
3398
3726
|
|
|
3399
3727
|
// console.log('[CompositionEditor] Schemas loaded for', widgetId.substring(0, 8), {
|
|
@@ -3402,7 +3730,7 @@
|
|
|
3402
3730
|
// });
|
|
3403
3731
|
} catch (err: any) {
|
|
3404
3732
|
console.error('[CompositionEditor] Failed to load schemas:', err);
|
|
3405
|
-
schemaError = err?.message || '
|
|
3733
|
+
schemaError = err?.message || $t('creator.general.failedToLoadEditorSettings');
|
|
3406
3734
|
}
|
|
3407
3735
|
|
|
3408
3736
|
widgetSchemaCache.set(widgetId, {
|
|
@@ -3619,6 +3947,38 @@
|
|
|
3619
3947
|
});
|
|
3620
3948
|
}
|
|
3621
3949
|
|
|
3950
|
+
/** Widget id baked into a CDN path, when the path has one. */
|
|
3951
|
+
function widgetIdFromJsPath(jsPath: string | null | undefined): string | null {
|
|
3952
|
+
if (!jsPath) return null;
|
|
3953
|
+
return (jsPath.match(/\/widgets\/([^/]+)\//i) || [])[1] || null;
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
/** Turn a stored js/html path into the HTML file the iframe can load. */
|
|
3957
|
+
function htmlUrlFromJsPath(jsPath: string): string {
|
|
3958
|
+
const cdnBase = publishedCdnBase();
|
|
3959
|
+
const trimmed = jsPath.replace(/\/+$/, '');
|
|
3960
|
+
let resolved = trimmed
|
|
3961
|
+
.replace(/\/widget\.js$/i, '/widget.html')
|
|
3962
|
+
.replace(/\.js$/i, '.html');
|
|
3963
|
+
if (!/\.html$/i.test(resolved)) {
|
|
3964
|
+
resolved = `${resolved}/widget.html`;
|
|
3965
|
+
}
|
|
3966
|
+
if (resolved.startsWith('/')) {
|
|
3967
|
+
resolved = `${cdnBase}${resolved}`;
|
|
3968
|
+
}
|
|
3969
|
+
return resolved;
|
|
3970
|
+
}
|
|
3971
|
+
|
|
3972
|
+
/**
|
|
3973
|
+
* A preset copy keeps the source file so the preview can load, but that path
|
|
3974
|
+
* names the source widget. It is not this widget's version history.
|
|
3975
|
+
*/
|
|
3976
|
+
function borrowedPresetArtifactUrl(widgetId: string, jsPath: string | null | undefined): string | null {
|
|
3977
|
+
const ownerId = widgetIdFromJsPath(jsPath);
|
|
3978
|
+
if (!jsPath || !ownerId || ownerId === widgetId) return null;
|
|
3979
|
+
return htmlUrlFromJsPath(jsPath);
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3622
3982
|
/** Resolve published artifact URL — CDN path by live version; js_path only when it matches that version. */
|
|
3623
3983
|
function resolvePublishedWidgetUrl(
|
|
3624
3984
|
widgetId: string,
|
|
@@ -3631,19 +3991,14 @@
|
|
|
3631
3991
|
const versionedUrl = `${cdnBase}/widgets/${widgetId}/v${version}/widget.html`;
|
|
3632
3992
|
|
|
3633
3993
|
if (jsPath) {
|
|
3634
|
-
const
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
if (
|
|
3639
|
-
resolved = `${resolved}/widget.html`;
|
|
3640
|
-
}
|
|
3641
|
-
if (resolved.startsWith('/')) {
|
|
3642
|
-
resolved = `${cdnBase}${resolved}`;
|
|
3643
|
-
}
|
|
3994
|
+
const resolved = htmlUrlFromJsPath(jsPath);
|
|
3995
|
+
const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
|
|
3996
|
+
// The copy has no artifact of its own. Load the source file instead of
|
|
3997
|
+
// inventing /widgets/{newId}/vN/, which 404s on the bucket.
|
|
3998
|
+
if (borrowed) return borrowed;
|
|
3644
3999
|
const jsPathVersionMatch = jsPath.match(/\/v(\d+)(?:\/|$)/);
|
|
3645
4000
|
const jsPathVersion = jsPathVersionMatch ? parseInt(jsPathVersionMatch[1], 10) : null;
|
|
3646
|
-
const jsPathWidgetId = (resolved
|
|
4001
|
+
const jsPathWidgetId = widgetIdFromJsPath(resolved);
|
|
3647
4002
|
const pointsAtOtherWidget = !!(jsPathWidgetId && jsPathWidgetId !== widgetId);
|
|
3648
4003
|
// Only reuse js_path when it already points at this widget + this version.
|
|
3649
4004
|
// `/widgets/` alone used to win and keep Edit on the previous CDN version after publish.
|
|
@@ -3901,7 +4256,7 @@
|
|
|
3901
4256
|
const label = property?.label ?? result.property;
|
|
3902
4257
|
applyDesignValuesToPreview(widgetId, { [result.property]: result.value });
|
|
3903
4258
|
const card: DesignControlRequest = {
|
|
3904
|
-
summary:
|
|
4259
|
+
summary: $t('creator.general.setTo', { label, value: String(result.value) }),
|
|
3905
4260
|
properties: [
|
|
3906
4261
|
{
|
|
3907
4262
|
id: result.property,
|
|
@@ -4355,7 +4710,7 @@
|
|
|
4355
4710
|
// Ensure the created object carries the name we used locally
|
|
4356
4711
|
if (!created.name) created.name = nameToUse;
|
|
4357
4712
|
// console.log('[Compositions] Created:', created);
|
|
4358
|
-
showToast('success',
|
|
4713
|
+
showToast('success', $t('creator.composition.compositionCreated', { name: nameToUse }));
|
|
4359
4714
|
|
|
4360
4715
|
// Select immediately so loadCompositions doesn't auto-select a different one
|
|
4361
4716
|
selectComposition(created);
|
|
@@ -4364,7 +4719,7 @@
|
|
|
4364
4719
|
await loadCompositions();
|
|
4365
4720
|
} catch (err: any) {
|
|
4366
4721
|
console.error('[Compositions] Create failed:', err);
|
|
4367
|
-
showToast('error',
|
|
4722
|
+
showToast('error', $t('creator.composition.failedToCreateComposition', { message: err.message || $t('creator.general.unknownError') }));
|
|
4368
4723
|
} finally {
|
|
4369
4724
|
compositionSaving = false;
|
|
4370
4725
|
}
|
|
@@ -4388,7 +4743,7 @@
|
|
|
4388
4743
|
});
|
|
4389
4744
|
const updated = (res as any)?.data ?? res;
|
|
4390
4745
|
// console.log('[Compositions] Updated:', updated);
|
|
4391
|
-
showToast('success', '
|
|
4746
|
+
showToast('success', $t('creator.composition.compositionSaved'));
|
|
4392
4747
|
compositionDirty = false;
|
|
4393
4748
|
// Preserve local name if the API response doesn't include it
|
|
4394
4749
|
const currentName = selectedComposition!.name;
|
|
@@ -4397,7 +4752,7 @@
|
|
|
4397
4752
|
return true;
|
|
4398
4753
|
} catch (err: any) {
|
|
4399
4754
|
console.error('[Compositions] Update failed:', err);
|
|
4400
|
-
showToast('error',
|
|
4755
|
+
showToast('error', $t('creator.general.failedToUpdate', { message: err.message || $t('creator.general.unknownError') }));
|
|
4401
4756
|
return false;
|
|
4402
4757
|
} finally {
|
|
4403
4758
|
compositionSaving = false;
|
|
@@ -4475,11 +4830,11 @@
|
|
|
4475
4830
|
id: compositionId,
|
|
4476
4831
|
updateComposition: { name: trimmed }
|
|
4477
4832
|
});
|
|
4478
|
-
showToast('success', '
|
|
4833
|
+
showToast('success', $t('creator.composition.compositionRenamed'));
|
|
4479
4834
|
await loadCompositions();
|
|
4480
4835
|
} catch (err: any) {
|
|
4481
4836
|
console.error('[Compositions] Rename failed:', err);
|
|
4482
|
-
showToast('error', '
|
|
4837
|
+
showToast('error', $t('creator.composition.failedToRenameComposition'));
|
|
4483
4838
|
} finally {
|
|
4484
4839
|
editingCompositionId = null;
|
|
4485
4840
|
}
|
|
@@ -4497,7 +4852,7 @@
|
|
|
4497
4852
|
deletingCompositionId = null;
|
|
4498
4853
|
try {
|
|
4499
4854
|
await compositionsClient.deleteComposition({ id: compositionId });
|
|
4500
|
-
showToast('success', '
|
|
4855
|
+
showToast('success', $t('creator.composition.compositionDeleted'));
|
|
4501
4856
|
if (selectedComposition?.id === compositionId) {
|
|
4502
4857
|
selectedComposition = null;
|
|
4503
4858
|
liveDesignValues = {};
|
|
@@ -4508,7 +4863,7 @@
|
|
|
4508
4863
|
await loadCompositions();
|
|
4509
4864
|
} catch (err: any) {
|
|
4510
4865
|
console.error('[Compositions] Delete failed:', err);
|
|
4511
|
-
showToast('error', '
|
|
4866
|
+
showToast('error', $t('creator.composition.failedToDeleteComposition'));
|
|
4512
4867
|
}
|
|
4513
4868
|
}
|
|
4514
4869
|
|
|
@@ -4546,7 +4901,7 @@
|
|
|
4546
4901
|
// console.log('[Embed] Saved dimensions:', embedWidth, '×', embedHeight);
|
|
4547
4902
|
} catch (err) {
|
|
4548
4903
|
console.error('[Embed] Failed to save dimensions:', err);
|
|
4549
|
-
showToast('error', '
|
|
4904
|
+
showToast('error', $t('creator.general.failedToSaveDimensions'));
|
|
4550
4905
|
} finally {
|
|
4551
4906
|
isSavingEmbedDims = false;
|
|
4552
4907
|
}
|
|
@@ -4673,10 +5028,14 @@
|
|
|
4673
5028
|
|
|
4674
5029
|
// debugMode — current ON/OFF state. User can still toggle when the UI is available.
|
|
4675
5030
|
let debugMode = debugModeAvailable;
|
|
4676
|
-
if (typeof
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
5031
|
+
if (debugModeAvailable && typeof window !== 'undefined') {
|
|
5032
|
+
try {
|
|
5033
|
+
const storedDebugMode = creatorStorage.getItem('widgetic:site-debug-on');
|
|
5034
|
+
if (storedDebugMode === '1' || storedDebugMode === 'true') debugMode = true;
|
|
5035
|
+
if (storedDebugMode === '0' || storedDebugMode === 'false') debugMode = false;
|
|
5036
|
+
} catch {
|
|
5037
|
+
/* storage unavailable (a sandboxed frame): keep the default */
|
|
5038
|
+
}
|
|
4680
5039
|
}
|
|
4681
5040
|
// console.log('[WidgetCreator] Debug from host/env', {
|
|
4682
5041
|
// hostProvidedDebug,
|
|
@@ -4851,19 +5210,14 @@
|
|
|
4851
5210
|
|
|
4852
5211
|
// Toggle debug mode
|
|
4853
5212
|
function emitCreatorDebugChanged() {
|
|
4854
|
-
|
|
4855
|
-
window.dispatchEvent(
|
|
4856
|
-
new CustomEvent(CREATOR_DEBUG_CHANGED_EVENT, {
|
|
4857
|
-
detail: { debugMode, debugModeAvailable }
|
|
4858
|
-
})
|
|
4859
|
-
);
|
|
5213
|
+
announceToSite(CREATOR_DEBUG_CHANGED_EVENT, { debugMode, debugModeAvailable });
|
|
4860
5214
|
}
|
|
4861
5215
|
|
|
4862
5216
|
function toggleDebugMode() {
|
|
4863
5217
|
if (!debugModeAvailable) return;
|
|
4864
5218
|
debugMode = !debugMode;
|
|
4865
5219
|
try {
|
|
4866
|
-
|
|
5220
|
+
creatorStorage.setItem('widgetic:site-debug-on', debugMode ? '1' : '0');
|
|
4867
5221
|
} catch (err) {
|
|
4868
5222
|
console.warn('[WidgetCreator] Could not persist debug mode', err);
|
|
4869
5223
|
}
|
|
@@ -4885,12 +5239,7 @@
|
|
|
4885
5239
|
let canvasPrimaryWidgetId: string | null = null;
|
|
4886
5240
|
|
|
4887
5241
|
function emitCreatorWireframeChanged() {
|
|
4888
|
-
|
|
4889
|
-
window.dispatchEvent(
|
|
4890
|
-
new CustomEvent(CREATOR_WIREFRAME_CHANGED_EVENT, {
|
|
4891
|
-
detail: { wireframeMode: canvasWireframeMode }
|
|
4892
|
-
})
|
|
4893
|
-
);
|
|
5242
|
+
announceToSite(CREATOR_WIREFRAME_CHANGED_EVENT, { wireframeMode: canvasWireframeMode });
|
|
4894
5243
|
}
|
|
4895
5244
|
|
|
4896
5245
|
function handleHostToggleWireframeEvent() {
|
|
@@ -4900,12 +5249,7 @@
|
|
|
4900
5249
|
}
|
|
4901
5250
|
|
|
4902
5251
|
function emitCreatorAdvancedChanged() {
|
|
4903
|
-
|
|
4904
|
-
window.dispatchEvent(
|
|
4905
|
-
new CustomEvent(CREATOR_ADVANCED_CHANGED_EVENT, {
|
|
4906
|
-
detail: { advancedFeatures: canvasAdvancedFeatures }
|
|
4907
|
-
})
|
|
4908
|
-
);
|
|
5252
|
+
announceToSite(CREATOR_ADVANCED_CHANGED_EVENT, { advancedFeatures: canvasAdvancedFeatures });
|
|
4909
5253
|
}
|
|
4910
5254
|
|
|
4911
5255
|
function handleHostToggleAdvancedEvent() {
|
|
@@ -4932,8 +5276,8 @@
|
|
|
4932
5276
|
function handleHostOpenWidgetDetailsEvent(): void {
|
|
4933
5277
|
const widgetId = resolveHostTargetWidgetId();
|
|
4934
5278
|
if (!widgetId) {
|
|
4935
|
-
showToast('warning', '
|
|
4936
|
-
description: '
|
|
5279
|
+
showToast('warning', $t('creator.widget.selectAWidgetFirst'), {
|
|
5280
|
+
description: $t('creator.canvas.clickAWidgetOnThe'),
|
|
4937
5281
|
});
|
|
4938
5282
|
return;
|
|
4939
5283
|
}
|
|
@@ -4944,8 +5288,8 @@
|
|
|
4944
5288
|
async function handleHostDuplicateWidgetEvent(): Promise<void> {
|
|
4945
5289
|
const widgetId = canvasPrimaryWidgetId || resolveHostTargetWidgetId();
|
|
4946
5290
|
if (!widgetId || isDraftConvertId(widgetId)) {
|
|
4947
|
-
showToast('warning', '
|
|
4948
|
-
description: '
|
|
5291
|
+
showToast('warning', $t('creator.widget.selectAWidgetFirst'), {
|
|
5292
|
+
description: $t('creator.widget.duplicateFromTheHeaderCopies'),
|
|
4949
5293
|
});
|
|
4950
5294
|
return;
|
|
4951
5295
|
}
|
|
@@ -4962,7 +5306,7 @@
|
|
|
4962
5306
|
async function handleHostDeleteWidgetEvent(): Promise<void> {
|
|
4963
5307
|
const widgetId = resolveHostTargetWidgetId();
|
|
4964
5308
|
if (!widgetId) {
|
|
4965
|
-
showToast('warning', '
|
|
5309
|
+
showToast('warning', $t('creator.widget.selectAWidgetFirst'));
|
|
4966
5310
|
return;
|
|
4967
5311
|
}
|
|
4968
5312
|
if (canvasRef?.selectWidgetShape?.(widgetId) && typeof canvasRef.deleteSelectedObjects === 'function') {
|
|
@@ -4977,8 +5321,8 @@
|
|
|
4977
5321
|
}
|
|
4978
5322
|
|
|
4979
5323
|
function emitCreatorSaveState(dirty: boolean): void {
|
|
4980
|
-
if (
|
|
4981
|
-
|
|
5324
|
+
if (!embedded) return;
|
|
5325
|
+
announceToSite('widgetic:creator-save-state', { dirty });
|
|
4982
5326
|
}
|
|
4983
5327
|
|
|
4984
5328
|
function handleHostSaveCanvasEvent(): void {
|
|
@@ -4986,7 +5330,7 @@
|
|
|
4986
5330
|
const json = canvasRef?.saveCanvas?.() ?? null;
|
|
4987
5331
|
if (!json) {
|
|
4988
5332
|
console.warn('[CreatorApp] Host Save ignored — saveCanvas returned null');
|
|
4989
|
-
showToast('error', '
|
|
5333
|
+
showToast('error', $t('creator.general.nothingToSave'), { description: $t('creator.canvas.canvasIsNotReadyYet') });
|
|
4990
5334
|
return;
|
|
4991
5335
|
}
|
|
4992
5336
|
void handleCanvasAutoSave(json, false, { force: true });
|
|
@@ -5135,9 +5479,7 @@
|
|
|
5135
5479
|
primaryWidgetId = items[0].id;
|
|
5136
5480
|
}
|
|
5137
5481
|
// console.log('[CreatorApp] Emit canvas widgets for header', reason, items.length, primaryWidgetId);
|
|
5138
|
-
|
|
5139
|
-
detail: { widgets: items, primaryWidgetId: primaryWidgetId || '' }
|
|
5140
|
-
}));
|
|
5482
|
+
announceToSite(CREATOR_CANVAS_WIDGETS_EVENT, { widgets: items, primaryWidgetId: primaryWidgetId || '' });
|
|
5141
5483
|
}
|
|
5142
5484
|
|
|
5143
5485
|
function handleHostRequestCanvasWidgetsEvent() {
|
|
@@ -5341,10 +5683,10 @@
|
|
|
5341
5683
|
if (!widgetId) return;
|
|
5342
5684
|
try {
|
|
5343
5685
|
if (active) {
|
|
5344
|
-
|
|
5686
|
+
creatorStorage.setItem(`crossTab_generating_${widgetId}`, String(Date.now()));
|
|
5345
5687
|
// console.log('[CrossTab] Set generating flag for widget:', widgetId);
|
|
5346
5688
|
} else {
|
|
5347
|
-
|
|
5689
|
+
creatorStorage.removeItem(`crossTab_generating_${widgetId}`);
|
|
5348
5690
|
// console.log('[CrossTab] Cleared generating flag for widget:', widgetId);
|
|
5349
5691
|
}
|
|
5350
5692
|
} catch (e) { /* localStorage unavailable */ }
|
|
@@ -5355,10 +5697,10 @@
|
|
|
5355
5697
|
if (!widgetId) return;
|
|
5356
5698
|
try {
|
|
5357
5699
|
if (active) {
|
|
5358
|
-
|
|
5700
|
+
creatorStorage.setItem(`crossTab_publishing_${widgetId}`, String(Date.now()));
|
|
5359
5701
|
// console.log('[CrossTab] Set publishing flag for widget:', widgetId);
|
|
5360
5702
|
} else {
|
|
5361
|
-
|
|
5703
|
+
creatorStorage.removeItem(`crossTab_publishing_${widgetId}`);
|
|
5362
5704
|
// console.log('[CrossTab] Cleared publishing flag for widget:', widgetId);
|
|
5363
5705
|
}
|
|
5364
5706
|
} catch (e) { /* localStorage unavailable */ }
|
|
@@ -5368,11 +5710,11 @@
|
|
|
5368
5710
|
function checkCrossTabGenerating(widgetId = selectedWidgetId): boolean {
|
|
5369
5711
|
if (!widgetId || isGeneratingCode) return false;
|
|
5370
5712
|
try {
|
|
5371
|
-
const ts =
|
|
5713
|
+
const ts = creatorStorage.getItem(`crossTab_generating_${widgetId}`);
|
|
5372
5714
|
if (!ts) return false;
|
|
5373
5715
|
const elapsed = Date.now() - Number(ts);
|
|
5374
5716
|
if (elapsed > CROSS_TAB_STALE_TIMEOUT_MS) {
|
|
5375
|
-
|
|
5717
|
+
creatorStorage.removeItem(`crossTab_generating_${widgetId}`);
|
|
5376
5718
|
return false;
|
|
5377
5719
|
}
|
|
5378
5720
|
return true;
|
|
@@ -5383,11 +5725,11 @@
|
|
|
5383
5725
|
function checkCrossTabPublishing(widgetId = selectedWidgetId): boolean {
|
|
5384
5726
|
if (!widgetId || isPublishing) return false; // If WE are publishing, ignore cross-tab flag
|
|
5385
5727
|
try {
|
|
5386
|
-
const ts =
|
|
5728
|
+
const ts = creatorStorage.getItem(`crossTab_publishing_${widgetId}`);
|
|
5387
5729
|
if (!ts) return false;
|
|
5388
5730
|
const elapsed = Date.now() - Number(ts);
|
|
5389
5731
|
if (elapsed > CROSS_TAB_STALE_TIMEOUT_MS) {
|
|
5390
|
-
|
|
5732
|
+
creatorStorage.removeItem(`crossTab_publishing_${widgetId}`);
|
|
5391
5733
|
return false;
|
|
5392
5734
|
}
|
|
5393
5735
|
return true;
|
|
@@ -5445,7 +5787,7 @@
|
|
|
5445
5787
|
const persisted = await readActiveGeneration(widgetId);
|
|
5446
5788
|
if (persisted) return persisted;
|
|
5447
5789
|
try {
|
|
5448
|
-
return
|
|
5790
|
+
return creatorStorage.getItem(`activeGeneration_${widgetId}`);
|
|
5449
5791
|
} catch (e) { return null; }
|
|
5450
5792
|
}
|
|
5451
5793
|
|
|
@@ -5502,8 +5844,8 @@
|
|
|
5502
5844
|
// console.log(`[Version] Commit restored from completed operation: ${resumeCommitSha.substring(0, 7)}`);
|
|
5503
5845
|
}
|
|
5504
5846
|
generateCodeStatus = 'Code generation completed! Auto-saving...';
|
|
5505
|
-
showToast('success', '
|
|
5506
|
-
description: '
|
|
5847
|
+
showToast('success', $t('creator.codegen.codeGenerationCompleted'), {
|
|
5848
|
+
description: $t('creator.codegen.generationFinishedWhileYouWere'),
|
|
5507
5849
|
duration: 5000
|
|
5508
5850
|
});
|
|
5509
5851
|
generateCodeStatus = 'Code generation completed! Changes saved to GitLab.';
|
|
@@ -5526,7 +5868,7 @@
|
|
|
5526
5868
|
lastGenerationFailed = true;
|
|
5527
5869
|
lastGenerationError = failedMsg;
|
|
5528
5870
|
generateCodeStatus = `❌ Code generation failed`;
|
|
5529
|
-
showToast('error', isServiceErr ? '
|
|
5871
|
+
showToast('error', isServiceErr ? $t('creator.general.serviceTemporarilyUnavailable') : $t('creator.status.failed'), {
|
|
5530
5872
|
description: failedMsg,
|
|
5531
5873
|
duration: isServiceErr ? 10000 : 6000
|
|
5532
5874
|
});
|
|
@@ -5551,8 +5893,8 @@
|
|
|
5551
5893
|
// Keep preview tab so user sees the "Generating..." overlay
|
|
5552
5894
|
widgetDetails?.setInlinePanelView('preview');
|
|
5553
5895
|
|
|
5554
|
-
showToast('info', '
|
|
5555
|
-
description: '
|
|
5896
|
+
showToast('info', $t('creator.codegen.generationInProgress'), {
|
|
5897
|
+
description: $t('creator.codegen.reconnectedToAnActiveCode'),
|
|
5556
5898
|
duration: 4000
|
|
5557
5899
|
});
|
|
5558
5900
|
|
|
@@ -5573,7 +5915,7 @@
|
|
|
5573
5915
|
lastGenerationFailed = true;
|
|
5574
5916
|
lastGenerationError = resumeError;
|
|
5575
5917
|
clearActiveOperationId();
|
|
5576
|
-
showToast('error', isResumeServiceErr ? '
|
|
5918
|
+
showToast('error', isResumeServiceErr ? $t('creator.general.serviceTemporarilyUnavailable') : $t('creator.status.failed'), {
|
|
5577
5919
|
description: resumeError,
|
|
5578
5920
|
duration: isResumeServiceErr ? 10000 : 8000
|
|
5579
5921
|
});
|
|
@@ -5585,8 +5927,8 @@
|
|
|
5585
5927
|
|
|
5586
5928
|
if (selectedWidgetId !== resumeWidgetId) {
|
|
5587
5929
|
// console.log('[GenerationResilience] Completed for widget', resumeWidgetId, 'but user switched to', selectedWidgetId);
|
|
5588
|
-
showToast('success', '
|
|
5589
|
-
description: '
|
|
5930
|
+
showToast('success', $t('creator.codegen.codeGenerationCompleted'), {
|
|
5931
|
+
description: $t('creator.codegen.generationFinishedForADifferent'),
|
|
5590
5932
|
duration: 5000
|
|
5591
5933
|
});
|
|
5592
5934
|
return;
|
|
@@ -5594,8 +5936,8 @@
|
|
|
5594
5936
|
|
|
5595
5937
|
hasChangesToSave = false;
|
|
5596
5938
|
generateCodeStatus = 'Code generation completed! Saved to GitLab.';
|
|
5597
|
-
showToast('success', '
|
|
5598
|
-
description: '
|
|
5939
|
+
showToast('success', $t('creator.codegen.codeGenerationCompleted'), {
|
|
5940
|
+
description: $t('creator.codegen.codeSavedToGitlabAnd'),
|
|
5599
5941
|
duration: 5000
|
|
5600
5942
|
});
|
|
5601
5943
|
setTimeout(async () => {
|
|
@@ -5650,6 +5992,8 @@
|
|
|
5650
5992
|
let isLoadingCanvasOnce = false;
|
|
5651
5993
|
let canvasHydrateRetryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
5652
5994
|
let canvasHydrateRetryCount = 0;
|
|
5995
|
+
/** How many reads of the canvas from the API are running (see `tryLoadCanvasState`). */
|
|
5996
|
+
let canvasRemoteReadsInFlight = 0;
|
|
5653
5997
|
const CANVAS_HYDRATE_MAX_RETRIES = 10;
|
|
5654
5998
|
const CANVAS_API_TIMEOUT_MS = 8000;
|
|
5655
5999
|
|
|
@@ -5670,7 +6014,7 @@
|
|
|
5670
6014
|
}
|
|
5671
6015
|
|
|
5672
6016
|
function scheduleCanvasHydrateRetry(reason: string) {
|
|
5673
|
-
if (isCanvasStateLoaded) return;
|
|
6017
|
+
if (isCanvasStateLoaded || canvasUnavailable) return;
|
|
5674
6018
|
if (canvasHydrateRetryCount >= CANVAS_HYDRATE_MAX_RETRIES) {
|
|
5675
6019
|
console.warn('[CanvasDebug] Exhausted canvas hydrate retries:', reason);
|
|
5676
6020
|
armCanvasLoadFailsafe(reason, canvasId || '__pending__');
|
|
@@ -5682,6 +6026,9 @@
|
|
|
5682
6026
|
clearCanvasHydrateRetry();
|
|
5683
6027
|
canvasHydrateRetryTimer = setTimeout(() => {
|
|
5684
6028
|
canvasHydrateRetryTimer = null;
|
|
6029
|
+
// Partner mode: a read that is still running will finish the load, or schedule the next try itself; a second
|
|
6030
|
+
// load beside it would only ask for the same canvas again.
|
|
6031
|
+
if (partnerMode && canvasRemoteReadsInFlight > 0) return;
|
|
5685
6032
|
isLoadingCanvasOnce = false;
|
|
5686
6033
|
void loadCurrentCanvas();
|
|
5687
6034
|
}, delayMs);
|
|
@@ -5700,6 +6047,9 @@
|
|
|
5700
6047
|
*/
|
|
5701
6048
|
function readCanvasIdFromAddressBar(): string | null {
|
|
5702
6049
|
if (typeof window === 'undefined') return null;
|
|
6050
|
+
// In a partner's page the address bar says nothing about Widgetic canvases (a partner's own `/canvas/…` route
|
|
6051
|
+
// must not be mistaken for one): the page names the canvas through the `canvasId` prop.
|
|
6052
|
+
if (!mayUseAddressBar()) return null;
|
|
5703
6053
|
try {
|
|
5704
6054
|
const pathParts = window.location.pathname.split('/');
|
|
5705
6055
|
const canvasIndex = pathParts.indexOf('canvas');
|
|
@@ -5911,7 +6261,7 @@
|
|
|
5911
6261
|
}
|
|
5912
6262
|
} catch (error) {
|
|
5913
6263
|
console.error('Widget Creator: Load canvases error:', error);
|
|
5914
|
-
const defaultError = '
|
|
6264
|
+
const defaultError = $t('creator.canvas.failedToLoadCanvases');
|
|
5915
6265
|
const message = toErrorMessage(error, defaultError);
|
|
5916
6266
|
widgetsError = message;
|
|
5917
6267
|
const savedCanvasId = routeCanvasId || getSavedSelectedCanvasId();
|
|
@@ -5934,7 +6284,7 @@
|
|
|
5934
6284
|
}
|
|
5935
6285
|
if (widgetsError && canvasHydrateRetryCount === 0) {
|
|
5936
6286
|
showToast('error', defaultError, {
|
|
5937
|
-
description:
|
|
6287
|
+
description: $t('creator.general.retryingWhenTheApiIs', { message }),
|
|
5938
6288
|
duration: 5000
|
|
5939
6289
|
});
|
|
5940
6290
|
}
|
|
@@ -6018,8 +6368,9 @@
|
|
|
6018
6368
|
|
|
6019
6369
|
/** Close canvas dropdown on outside click */
|
|
6020
6370
|
function handleCanvasDropdownOutsideClick(e: MouseEvent) {
|
|
6021
|
-
|
|
6022
|
-
|
|
6371
|
+
// The whole path is looked at, not `e.target.closest(…)`: in a shadow root the target seen from `window` is the
|
|
6372
|
+
// shadow's host element, so the dropdown would close on every click, including the one that opens it.
|
|
6373
|
+
if (!eventPathMatches(e, '.canvas-selector-group')) {
|
|
6023
6374
|
showCanvasDropdown = false;
|
|
6024
6375
|
if (canvasNameEditing) commitCanvasNameEdit();
|
|
6025
6376
|
}
|
|
@@ -6126,7 +6477,7 @@
|
|
|
6126
6477
|
selectedWidgetJsPath = null;
|
|
6127
6478
|
widgetDetailsStep = 'create';
|
|
6128
6479
|
lastSavedCanvasObjectCount = 0;
|
|
6129
|
-
try {
|
|
6480
|
+
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, '0'); } catch { /* ignore */ }
|
|
6130
6481
|
canvasRef?.onClearAllObjects();
|
|
6131
6482
|
// console.log('[CreatorApp] Blank canvas session:', reason, 'epoch', canvasLoadEpoch);
|
|
6132
6483
|
}
|
|
@@ -6432,7 +6783,7 @@
|
|
|
6432
6783
|
console.error('[WidgetCreator] Failed to delete canvas:', targetId, err);
|
|
6433
6784
|
// Keep the dialog open so the user can react; a partial failure leaves
|
|
6434
6785
|
// the canvas intact on purpose (the API refuses to orphan widgets).
|
|
6435
|
-
deleteCanvasError = '
|
|
6786
|
+
deleteCanvasError = $t('creator.canvas.couldNotDeleteThisCanvas');
|
|
6436
6787
|
return;
|
|
6437
6788
|
}
|
|
6438
6789
|
deleteCanvasTarget = null;
|
|
@@ -6444,7 +6795,7 @@
|
|
|
6444
6795
|
// if no canvas id, return
|
|
6445
6796
|
if (!canvasId) {
|
|
6446
6797
|
// console.log('Widget Creator: loadWidgetsForCanvas: No canvas id, returning');
|
|
6447
|
-
widgetsError = '
|
|
6798
|
+
widgetsError = $t('creator.canvas.noCanvasIdCannotLoad');
|
|
6448
6799
|
widgets = [];
|
|
6449
6800
|
selectedWidgetId = null;
|
|
6450
6801
|
isLoadingWidgets = false;
|
|
@@ -6464,7 +6815,9 @@
|
|
|
6464
6815
|
}
|
|
6465
6816
|
|
|
6466
6817
|
// Fetch widgets directly by canvasId. Raw JSON keeps thumbnailUrl,
|
|
6467
|
-
// which the generated model drops.
|
|
6818
|
+
// which the generated model drops. A refused request or an error answer
|
|
6819
|
+
// is thrown (see readWidgetList), so the catch below shows it and
|
|
6820
|
+
// saysCanvasIsMissing can read a 404 in partner mode.
|
|
6468
6821
|
const fetched = await readWidgetList(canvasId);
|
|
6469
6822
|
|
|
6470
6823
|
const previousById = new Map(
|
|
@@ -6545,15 +6898,19 @@
|
|
|
6545
6898
|
}
|
|
6546
6899
|
} catch (error) {
|
|
6547
6900
|
console.error('Widget Creator: Failed to load widgets for canvas:', error);
|
|
6548
|
-
const defaultError = '
|
|
6901
|
+
const defaultError = $t('creator.widget.failedToLoadWidgets');
|
|
6549
6902
|
const message = toErrorMessage(error, defaultError);
|
|
6903
|
+
// Partner mode: "no such canvas" is the answer to the canvas the page named, not a problem with the widget list.
|
|
6904
|
+
if (saysCanvasIsMissing(error)) declareCanvasUnavailable(canvasId?.trim() || null, message);
|
|
6550
6905
|
widgetsError = message;
|
|
6551
6906
|
widgets = [];
|
|
6552
6907
|
selectedWidgetId = null;
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6908
|
+
if (!canvasUnavailable) {
|
|
6909
|
+
showToast('error', defaultError, {
|
|
6910
|
+
description: message,
|
|
6911
|
+
duration: 5000
|
|
6912
|
+
});
|
|
6913
|
+
}
|
|
6557
6914
|
} finally {
|
|
6558
6915
|
isLoadingWidgets = false;
|
|
6559
6916
|
isLoadingWidgetsOnce = false;
|
|
@@ -6625,8 +6982,8 @@
|
|
|
6625
6982
|
const restored = await restoreWidgetShapesFromDb();
|
|
6626
6983
|
if (restored === 0) {
|
|
6627
6984
|
canvasShapesMissingWarning = true;
|
|
6628
|
-
showToast('error', '
|
|
6629
|
-
description: '
|
|
6985
|
+
showToast('error', $t('creator.widget.couldNotRestoreShapesYet'), {
|
|
6986
|
+
description: $t('creator.canvas.canvasMayStillBeLoading'),
|
|
6630
6987
|
duration: 6000,
|
|
6631
6988
|
});
|
|
6632
6989
|
}
|
|
@@ -6707,7 +7064,7 @@
|
|
|
6707
7064
|
refreshLinkedWidgetIds();
|
|
6708
7065
|
canvasShapesMissingWarning = false;
|
|
6709
7066
|
if (!options.silent) {
|
|
6710
|
-
showToast('success',
|
|
7067
|
+
showToast('success', $t('creator.canvas.restoredShapes', { count: actuallyRestored }), {
|
|
6711
7068
|
duration: 6000,
|
|
6712
7069
|
});
|
|
6713
7070
|
}
|
|
@@ -6877,7 +7234,7 @@
|
|
|
6877
7234
|
* a stale widget_id from the previous canvas overwrites the header/primary.
|
|
6878
7235
|
*/
|
|
6879
7236
|
function resolveEmbeddedDeepLinkWidgetId(): string | null {
|
|
6880
|
-
if (typeof window !== 'undefined') {
|
|
7237
|
+
if (typeof window !== 'undefined' && mayUseAddressBar()) {
|
|
6881
7238
|
try {
|
|
6882
7239
|
const fromUrl = new URLSearchParams(window.location.search).get('widget_id');
|
|
6883
7240
|
if (fromUrl && fromUrl.trim()) return fromUrl.trim();
|
|
@@ -6951,6 +7308,7 @@
|
|
|
6951
7308
|
/** Ensure the address bar points at the canvas we actually loaded (refresh-safe). */
|
|
6952
7309
|
function syncUrlCanvasId(canvasIdToSync: string | null): void {
|
|
6953
7310
|
if (typeof window === 'undefined' || !embedded) return;
|
|
7311
|
+
if (!mayUseAddressBar()) return;
|
|
6954
7312
|
if (!canvasIdToSync || !canvasIdToSync.trim()) return;
|
|
6955
7313
|
try {
|
|
6956
7314
|
const url = new URL(window.location.href);
|
|
@@ -6966,11 +7324,25 @@
|
|
|
6966
7324
|
}
|
|
6967
7325
|
}
|
|
6968
7326
|
|
|
7327
|
+
/** The reads of a canvas's primary widget that are running now, by canvas id. */
|
|
7328
|
+
const primaryWidgetReadsInFlight = new Map<string, Promise<string | null>>();
|
|
7329
|
+
|
|
6969
7330
|
/**
|
|
6970
7331
|
* Canvas-only embed deep-link (My widgets / canvas without widget_id):
|
|
6971
7332
|
* read canvases.primary_widget_id so Creator can open that widget panel.
|
|
6972
7333
|
*/
|
|
6973
|
-
|
|
7334
|
+
function resolvePrimaryWidgetIdForCanvas(targetCanvasId: string): Promise<string | null> {
|
|
7335
|
+
const readKey = targetCanvasId?.trim();
|
|
7336
|
+
if (!readKey || canvasUnavailable) return Promise.resolve(null);
|
|
7337
|
+
// Several parts of the start ask for this at the same moment; they share one read of the canvas.
|
|
7338
|
+
const readRunning = primaryWidgetReadsInFlight.get(readKey);
|
|
7339
|
+
if (readRunning) return readRunning;
|
|
7340
|
+
const read = readPrimaryWidgetIdForCanvas(targetCanvasId).finally(() => primaryWidgetReadsInFlight.delete(readKey));
|
|
7341
|
+
primaryWidgetReadsInFlight.set(readKey, read);
|
|
7342
|
+
return read;
|
|
7343
|
+
}
|
|
7344
|
+
|
|
7345
|
+
async function readPrimaryWidgetIdForCanvas(targetCanvasId: string): Promise<string | null> {
|
|
6974
7346
|
if (!canvasesClient || !targetCanvasId?.trim()) return null;
|
|
6975
7347
|
try {
|
|
6976
7348
|
const canvasRecord = await canvasesClient.getCanvas({ id: targetCanvasId });
|
|
@@ -7027,6 +7399,8 @@
|
|
|
7027
7399
|
targetCanvasId.substring(0, 8),
|
|
7028
7400
|
err
|
|
7029
7401
|
);
|
|
7402
|
+
// Partner mode: the first read to be told "no such canvas" says so for the whole creator.
|
|
7403
|
+
if (saysCanvasIsMissing(err)) declareCanvasUnavailable(targetCanvasId, toErrorMessage(err, 'Canvas not found'));
|
|
7030
7404
|
return null;
|
|
7031
7405
|
}
|
|
7032
7406
|
}
|
|
@@ -7427,6 +7801,19 @@
|
|
|
7427
7801
|
if (!widget) return { kind: 'draft' };
|
|
7428
7802
|
const jsPath = ((widget as { jsPath?: string | null; js_path?: string | null }).jsPath
|
|
7429
7803
|
?? (widget as { js_path?: string | null }).js_path) as string | null;
|
|
7804
|
+
const widgetId = (widget as { id?: string }).id || '';
|
|
7805
|
+
// A preset copy stores the source widget's file. That /vN/ is the source's
|
|
7806
|
+
// history, not a version of this account's widget. Chat starts empty; so do versions.
|
|
7807
|
+
if (borrowedPresetArtifactUrl(widgetId, jsPath)) {
|
|
7808
|
+
if (isWidgetPublishedSummary(widget)) {
|
|
7809
|
+
return {
|
|
7810
|
+
kind: 'published',
|
|
7811
|
+
version: Number((widget as { version?: number }).version),
|
|
7812
|
+
jsPath,
|
|
7813
|
+
};
|
|
7814
|
+
}
|
|
7815
|
+
return { kind: 'draft' };
|
|
7816
|
+
}
|
|
7430
7817
|
// Only trust an explicit CDN/version path — a bare/non-version js_path must NOT
|
|
7431
7818
|
// mark the widget as published (that stuck Publish on "No new version to publish").
|
|
7432
7819
|
if (jsPath) {
|
|
@@ -7741,11 +8128,11 @@
|
|
|
7741
8128
|
backfillWidgetShapeMetadata();
|
|
7742
8129
|
syncWidgetShapeLivePreviews();
|
|
7743
8130
|
// console.log('[WidgetRename] Successfully renamed widget:', widgetId, 'to:', newName);
|
|
7744
|
-
showToast('success',
|
|
8131
|
+
showToast('success', $t('creator.widget.widgetRenamedTo', { name: newName }));
|
|
7745
8132
|
} catch (error) {
|
|
7746
8133
|
console.error('[WidgetRename] Failed to rename widget:', error);
|
|
7747
|
-
showToast('error', '
|
|
7748
|
-
description: error instanceof Error ? error.message : '
|
|
8134
|
+
showToast('error', $t('creator.widget.failedToRenameWidget'), {
|
|
8135
|
+
description: error instanceof Error ? error.message : $t('creator.general.unknownError')
|
|
7749
8136
|
});
|
|
7750
8137
|
} finally {
|
|
7751
8138
|
isRenamingInProgress = false;
|
|
@@ -7976,8 +8363,8 @@
|
|
|
7976
8363
|
getChatMethodsForWidget(statusWidgetId)?.updateLatestCodegenStatusMessage?.(
|
|
7977
8364
|
'Generation stopped by user. You can Retry this prompt.',
|
|
7978
8365
|
);
|
|
7979
|
-
showToast('info', '
|
|
7980
|
-
description: '
|
|
8366
|
+
showToast('info', $t('creator.codegen.generationStopped'), {
|
|
8367
|
+
description: $t('creator.codegen.codeGenerationWasCancelledYou'),
|
|
7981
8368
|
duration: 3000
|
|
7982
8369
|
});
|
|
7983
8370
|
}
|
|
@@ -7992,8 +8379,8 @@
|
|
|
7992
8379
|
async function processImageFile(file: File): Promise<string | null> {
|
|
7993
8380
|
// Check file type
|
|
7994
8381
|
if (!file.type.startsWith('image/')) {
|
|
7995
|
-
showToast('error', '
|
|
7996
|
-
description: '
|
|
8382
|
+
showToast('error', $t('creator.general.invalidFileType'), {
|
|
8383
|
+
description: $t('creator.general.pleaseSelectAnImageFile'),
|
|
7997
8384
|
duration: 3000
|
|
7998
8385
|
});
|
|
7999
8386
|
return null;
|
|
@@ -8002,8 +8389,8 @@
|
|
|
8002
8389
|
// Check file size
|
|
8003
8390
|
const sizeMB = file.size / (1024 * 1024);
|
|
8004
8391
|
if (sizeMB > MAX_IMAGE_SIZE_MB) {
|
|
8005
|
-
showToast('error', '
|
|
8006
|
-
description:
|
|
8392
|
+
showToast('error', $t('creator.general.imageTooLarge'), {
|
|
8393
|
+
description: $t('creator.general.maximumImageSizeIsMb', { maxMb: MAX_IMAGE_SIZE_MB, sizeMb: sizeMB.toFixed(1) }),
|
|
8007
8394
|
duration: 3000
|
|
8008
8395
|
});
|
|
8009
8396
|
return null;
|
|
@@ -8011,8 +8398,8 @@
|
|
|
8011
8398
|
|
|
8012
8399
|
// Check max images limit
|
|
8013
8400
|
if (promptImages.length >= MAX_PROMPT_IMAGES) {
|
|
8014
|
-
showToast('error', '
|
|
8015
|
-
description:
|
|
8401
|
+
showToast('error', $t('creator.general.tooManyImages'), {
|
|
8402
|
+
description: $t('creator.general.maximumImagesAllowedRemoveAn', { max: MAX_PROMPT_IMAGES }),
|
|
8016
8403
|
duration: 3000
|
|
8017
8404
|
});
|
|
8018
8405
|
return null;
|
|
@@ -8025,8 +8412,8 @@
|
|
|
8025
8412
|
return base64;
|
|
8026
8413
|
} catch (error) {
|
|
8027
8414
|
console.error('[WidgetCreator] Error processing image:', error);
|
|
8028
|
-
showToast('error', '
|
|
8029
|
-
description: '
|
|
8415
|
+
showToast('error', $t('creator.general.failedToProcessImage'), {
|
|
8416
|
+
description: $t('creator.general.couldNotReadTheImage'),
|
|
8030
8417
|
duration: 3000
|
|
8031
8418
|
});
|
|
8032
8419
|
return null;
|
|
@@ -8071,8 +8458,8 @@
|
|
|
8071
8458
|
if (base64) {
|
|
8072
8459
|
promptImages = [...promptImages, base64];
|
|
8073
8460
|
savePromptImagesToSession();
|
|
8074
|
-
showToast('success', '
|
|
8075
|
-
description: '
|
|
8461
|
+
showToast('success', $t('creator.general.imagePasted'), {
|
|
8462
|
+
description: $t('creator.codegen.imageAddedToYourPrompt'),
|
|
8076
8463
|
duration: 2000
|
|
8077
8464
|
});
|
|
8078
8465
|
}
|
|
@@ -8286,7 +8673,8 @@
|
|
|
8286
8673
|
}
|
|
8287
8674
|
// console.log('[Chat] Chat ready for widget', ownerWidgetId?.substring(0, 8), 'methods exposed');
|
|
8288
8675
|
|
|
8289
|
-
|
|
8676
|
+
// A console helper of Widgetic's own pages; a partner's page gets no globals from the creator.
|
|
8677
|
+
if (typeof window !== 'undefined' && !partnerMode) {
|
|
8290
8678
|
(window as Window & { __widgeticAttachReferenceImage?: (url?: string) => Promise<boolean> }).__widgeticAttachReferenceImage =
|
|
8291
8679
|
attachReferenceImageFromUrl;
|
|
8292
8680
|
}
|
|
@@ -8311,7 +8699,7 @@
|
|
|
8311
8699
|
// console.log('[WidgetCreator] Images restored from durable draft:', promptImages.length);
|
|
8312
8700
|
return;
|
|
8313
8701
|
}
|
|
8314
|
-
const stored =
|
|
8702
|
+
const stored = creatorStorage.getItem(PROMPT_IMAGES_STORAGE_PREFIX + selectedWidgetId);
|
|
8315
8703
|
if (stored) {
|
|
8316
8704
|
const parsed = JSON.parse(stored);
|
|
8317
8705
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
@@ -8319,7 +8707,7 @@
|
|
|
8319
8707
|
// console.log('[WidgetCreator] Images restored from per-widget localStorage:', promptImages.length);
|
|
8320
8708
|
}
|
|
8321
8709
|
}
|
|
8322
|
-
|
|
8710
|
+
creatorStorage.removeItem(PROMPT_IMAGES_STORAGE_KEY);
|
|
8323
8711
|
} catch (error) {
|
|
8324
8712
|
console.warn('[WidgetCreator] Could not restore images from durable storage:', error);
|
|
8325
8713
|
}
|
|
@@ -8523,19 +8911,19 @@
|
|
|
8523
8911
|
if (!widgetId || isDraftConvertId(widgetId)) return;
|
|
8524
8912
|
if (codegenCaptureBlocked() || generatingWidgetIds[widgetId]) {
|
|
8525
8913
|
if (interactive) {
|
|
8526
|
-
showToast('info', '
|
|
8914
|
+
showToast('info', $t('creator.preview.imageWaitsForGeneration'), { duration: 3000 });
|
|
8527
8915
|
}
|
|
8528
8916
|
return;
|
|
8529
8917
|
}
|
|
8530
8918
|
if (interactive) {
|
|
8531
|
-
showToast('info', '
|
|
8919
|
+
showToast('info', $t('creator.preview.savingImage'), { duration: 2500 });
|
|
8532
8920
|
}
|
|
8533
8921
|
try {
|
|
8534
8922
|
const screenshot = await handleChatScreenshot(widgetId, null, false);
|
|
8535
8923
|
if (!screenshot) {
|
|
8536
8924
|
if (interactive) {
|
|
8537
|
-
showToast('error', '
|
|
8538
|
-
description: '
|
|
8925
|
+
showToast('error', $t('creator.preview.couldNotSaveImage'), {
|
|
8926
|
+
description: $t('creator.preview.imageNotReturned'),
|
|
8539
8927
|
duration: 5000,
|
|
8540
8928
|
});
|
|
8541
8929
|
}
|
|
@@ -8544,14 +8932,14 @@
|
|
|
8544
8932
|
canvasRef?.updateWidgetImage(widgetId, screenshot);
|
|
8545
8933
|
await persistWidgetListThumbnail(widgetId, screenshot);
|
|
8546
8934
|
if (interactive) {
|
|
8547
|
-
showToast('success', '
|
|
8935
|
+
showToast('success', $t('creator.preview.imageSaved'), { duration: 2000 });
|
|
8548
8936
|
} else {
|
|
8549
8937
|
console.log('[Chat→Screenshot] List thumbnail saved', widgetId.substring(0, 8));
|
|
8550
8938
|
}
|
|
8551
8939
|
} catch (error) {
|
|
8552
8940
|
console.warn('[Chat→Screenshot] List thumbnail failed', widgetId.substring(0, 8), error);
|
|
8553
8941
|
if (interactive) {
|
|
8554
|
-
showToast('error', '
|
|
8942
|
+
showToast('error', $t('creator.preview.couldNotSaveImage'), { duration: 4000 });
|
|
8555
8943
|
}
|
|
8556
8944
|
}
|
|
8557
8945
|
}
|
|
@@ -8702,13 +9090,13 @@
|
|
|
8702
9090
|
if (!iframe?.contentWindow) {
|
|
8703
9091
|
// console.log('[handleRefreshScreenshot] Preview iframe not ready — skipping capture');
|
|
8704
9092
|
if (!quiet) {
|
|
8705
|
-
showToast('error', '
|
|
9093
|
+
showToast('error', $t('creator.preview.noValidPreviewAvailable'), { description: $t('creator.codegen.generateCodeFirstToCapture'), duration: 5000 });
|
|
8706
9094
|
}
|
|
8707
9095
|
return;
|
|
8708
9096
|
}
|
|
8709
9097
|
|
|
8710
9098
|
if (!quiet) {
|
|
8711
|
-
showToast('info', '
|
|
9099
|
+
showToast('info', $t('creator.widget.capturingWidgetScreenshot'), { duration: 3000 });
|
|
8712
9100
|
}
|
|
8713
9101
|
|
|
8714
9102
|
const result = await new Promise<{ data: string | null; error: string | null }>((resolve) => {
|
|
@@ -8719,6 +9107,8 @@
|
|
|
8719
9107
|
|
|
8720
9108
|
function handler(event: MessageEvent) {
|
|
8721
9109
|
if (event.data?.type !== 'widgetic:screenshot') return;
|
|
9110
|
+
// Only the preview that was asked: in a partner's page another frame could answer in its place.
|
|
9111
|
+
if (event.source !== iframe.contentWindow) return;
|
|
8722
9112
|
clearTimeout(timeout);
|
|
8723
9113
|
window.removeEventListener('message', handler);
|
|
8724
9114
|
resolve({
|
|
@@ -8744,7 +9134,7 @@
|
|
|
8744
9134
|
}, 500);
|
|
8745
9135
|
void persistWidgetListThumbnail(widgetId, result.data);
|
|
8746
9136
|
if (!quiet) {
|
|
8747
|
-
showToast('success', '
|
|
9137
|
+
showToast('success', $t('creator.canvas.widgetPreviewUpdatedOnCanvas'), { duration: 2000 });
|
|
8748
9138
|
} else {
|
|
8749
9139
|
// console.log('[handleRefreshScreenshot] Canvas shape preview synced (quiet):', widgetId.substring(0, 8));
|
|
8750
9140
|
}
|
|
@@ -8752,13 +9142,13 @@
|
|
|
8752
9142
|
const reason = result.error || 'no image data';
|
|
8753
9143
|
console.warn('[handleRefreshScreenshot] Capture failed:', reason);
|
|
8754
9144
|
if (!quiet) {
|
|
8755
|
-
showToast('error', '
|
|
9145
|
+
showToast('error', $t('creator.general.screenshotCaptureFailed'), {
|
|
8756
9146
|
description:
|
|
8757
9147
|
reason === 'html2canvas not loaded'
|
|
8758
|
-
? '
|
|
9148
|
+
? $t('creator.codegen.previewIsMissingTheCapture')
|
|
8759
9149
|
: reason === 'timeout'
|
|
8760
|
-
? '
|
|
8761
|
-
:
|
|
9150
|
+
? $t('creator.preview.theWidgetDidNotRespond')
|
|
9151
|
+
: $t('creator.preview.captureErrorRefreshThePreview', { reason }),
|
|
8762
9152
|
duration: 6000,
|
|
8763
9153
|
});
|
|
8764
9154
|
}
|
|
@@ -8766,7 +9156,7 @@
|
|
|
8766
9156
|
} catch (err) {
|
|
8767
9157
|
console.error('[handleRefreshScreenshot] Screenshot error:', err);
|
|
8768
9158
|
if (!quiet) {
|
|
8769
|
-
showToast('error', '
|
|
9159
|
+
showToast('error', $t('creator.general.screenshotCaptureFailed'), { duration: 3000 });
|
|
8770
9160
|
}
|
|
8771
9161
|
} finally {
|
|
8772
9162
|
screenshotCaptureInFlight.delete(widgetId);
|
|
@@ -8894,9 +9284,9 @@ Requirements:
|
|
|
8894
9284
|
const promptSource = options.prompt || panelPrompt;
|
|
8895
9285
|
const trimmedPrompt = promptSource.trim();
|
|
8896
9286
|
if (trimmedPrompt.length < 10) {
|
|
8897
|
-
showToast('error', '
|
|
9287
|
+
showToast('error', $t('creator.codegen.promptTooShort'), {
|
|
8898
9288
|
description:
|
|
8899
|
-
'
|
|
9289
|
+
$t('creator.codegen.pleaseProvideAPromptWith'),
|
|
8900
9290
|
duration: 5000
|
|
8901
9291
|
});
|
|
8902
9292
|
return;
|
|
@@ -8929,8 +9319,8 @@ Requirements:
|
|
|
8929
9319
|
setCrossTabGenerating(false, codegenTargetWidgetId);
|
|
8930
9320
|
patchCodegenUiState(codegenTargetWidgetId, { generateCodeStatus: 'Mock code generation complete!' });
|
|
8931
9321
|
if (codegenTargetWidgetId === focusedPanelWidgetId) hasChangesToSave = true;
|
|
8932
|
-
showToast('success', '
|
|
8933
|
-
description: '
|
|
9322
|
+
showToast('success', $t('creator.codegen.mockCodeGenerated'), {
|
|
9323
|
+
description: $t('creator.codegen.thisIsASimulationNo'),
|
|
8934
9324
|
duration: 3000
|
|
8935
9325
|
});
|
|
8936
9326
|
}, 2000);
|
|
@@ -9004,8 +9394,8 @@ Requirements:
|
|
|
9004
9394
|
const options = currentGenerationOptions();
|
|
9005
9395
|
generationOptionsMemory = { ...generationOptionsMemory, [widgetId]: options };
|
|
9006
9396
|
try {
|
|
9007
|
-
|
|
9008
|
-
|
|
9397
|
+
creatorStorage.setItem(languageStorageKey(widgetId), options.language);
|
|
9398
|
+
creatorStorage.setItem(generationOptionsStorageKey(widgetId), JSON.stringify({
|
|
9009
9399
|
language: options.language,
|
|
9010
9400
|
librariesEnabled: options.librariesEnabled,
|
|
9011
9401
|
libraries: options.libraries,
|
|
@@ -9027,7 +9417,7 @@ Requirements:
|
|
|
9027
9417
|
|
|
9028
9418
|
function readGeneratedLanguage(widgetId: string): 'svelte' | 'react' | null {
|
|
9029
9419
|
try {
|
|
9030
|
-
const value =
|
|
9420
|
+
const value = creatorStorage.getItem(generatedLanguageStorageKey(widgetId));
|
|
9031
9421
|
return value === 'svelte' || value === 'react' ? value : null;
|
|
9032
9422
|
} catch (error) {
|
|
9033
9423
|
console.warn('[WidgetCreator] Could not read generated language', error);
|
|
@@ -9037,7 +9427,7 @@ Requirements:
|
|
|
9037
9427
|
|
|
9038
9428
|
function rememberGeneratedLanguage(widgetId: string, language: 'svelte' | 'react'): void {
|
|
9039
9429
|
try {
|
|
9040
|
-
|
|
9430
|
+
creatorStorage.setItem(generatedLanguageStorageKey(widgetId), language);
|
|
9041
9431
|
} catch (error) {
|
|
9042
9432
|
console.warn('[WidgetCreator] Could not store generated language', error);
|
|
9043
9433
|
}
|
|
@@ -9067,7 +9457,7 @@ Requirements:
|
|
|
9067
9457
|
let stored: Partial<RememberedGenerationOptions> | null = null;
|
|
9068
9458
|
if (!inMemory) {
|
|
9069
9459
|
try {
|
|
9070
|
-
const raw =
|
|
9460
|
+
const raw = creatorStorage.getItem(generationOptionsStorageKey(widgetId));
|
|
9071
9461
|
stored = raw ? JSON.parse(raw) : null;
|
|
9072
9462
|
} catch (error) {
|
|
9073
9463
|
console.warn('[WidgetCreator] Could not read generation options', error);
|
|
@@ -9144,7 +9534,8 @@ Requirements:
|
|
|
9144
9534
|
generatingWidgetIds = { ...generatingWidgetIds, [generationWidgetId]: true };
|
|
9145
9535
|
noteCodegenActive(true);
|
|
9146
9536
|
screenshotGenerationEpoch += 1;
|
|
9147
|
-
|
|
9537
|
+
// The creator's own frames: in a partner's page `document` holds the page's frames, and not these.
|
|
9538
|
+
(getCreatorShadowRoot(creatorRootEl) ?? document).querySelectorAll('iframe').forEach((frame) => {
|
|
9148
9539
|
try {
|
|
9149
9540
|
frame.contentWindow?.postMessage({ type: 'widgetic:abort-screenshot' }, '*');
|
|
9150
9541
|
} catch (err) {
|
|
@@ -9211,13 +9602,13 @@ Requirements:
|
|
|
9211
9602
|
}
|
|
9212
9603
|
} catch (repoError) {
|
|
9213
9604
|
if (repoError instanceof ResponseError && repoError.response?.status === 401) {
|
|
9214
|
-
const sessionError = '
|
|
9605
|
+
const sessionError = signInAgainText($t('creator.session.sessionExpiredSignInAgain'));
|
|
9215
9606
|
patchCodegenUiState(generationWidgetId, {
|
|
9216
9607
|
generateCodeStatus: '❌ Session expired.',
|
|
9217
9608
|
lastGenerationFailed: true,
|
|
9218
9609
|
lastGenerationError: sessionError,
|
|
9219
9610
|
});
|
|
9220
|
-
showToast('error', '
|
|
9611
|
+
showToast('error', $t('creator.session.sessionExpired'), {
|
|
9221
9612
|
description: sessionError,
|
|
9222
9613
|
duration: 5000
|
|
9223
9614
|
});
|
|
@@ -9235,8 +9626,8 @@ Requirements:
|
|
|
9235
9626
|
lastGenerationFailed: true,
|
|
9236
9627
|
lastGenerationError: missingRepoError,
|
|
9237
9628
|
});
|
|
9238
|
-
showToast('error', '
|
|
9239
|
-
description: missingRepoError,
|
|
9629
|
+
showToast('error', $t('creator.codegen.missingRepository'), {
|
|
9630
|
+
description: errorLabel(missingRepoError, $t),
|
|
9240
9631
|
duration: 5000
|
|
9241
9632
|
});
|
|
9242
9633
|
pushCodegenFailureToChat(generationWidgetId, missingRepoError);
|
|
@@ -9337,15 +9728,15 @@ Requirements:
|
|
|
9337
9728
|
// });
|
|
9338
9729
|
coderModelForRequest = visionFallback;
|
|
9339
9730
|
const visionModel = availableModels.find((m) => m.id === visionFallback);
|
|
9340
|
-
showToast('info',
|
|
9341
|
-
description: '
|
|
9731
|
+
showToast('info', $t('creator.codegen.coderVision', { model: visionModel?.name ?? visionFallback }), {
|
|
9732
|
+
description: $t('creator.codegen.visionModelNote'),
|
|
9342
9733
|
duration: 8000
|
|
9343
9734
|
});
|
|
9344
9735
|
}
|
|
9345
9736
|
} else if (promptImpliesVisionReference(prompt) && !options.forkUserMessage) {
|
|
9346
|
-
showToast('warning', '
|
|
9737
|
+
showToast('warning', $t('creator.codegen.noImageTitle'), {
|
|
9347
9738
|
description:
|
|
9348
|
-
'
|
|
9739
|
+
$t('creator.codegen.noVisionNote'),
|
|
9349
9740
|
duration: 8000,
|
|
9350
9741
|
});
|
|
9351
9742
|
}
|
|
@@ -9436,7 +9827,7 @@ Requirements:
|
|
|
9436
9827
|
|
|
9437
9828
|
showToast(
|
|
9438
9829
|
gatedAction === 'answer' ? 'info' : 'warning',
|
|
9439
|
-
gatedAction === 'answer' ? '
|
|
9830
|
+
gatedAction === 'answer' ? $t('creator.codegen.answeredWithoutGenerating') : $t('creator.codegen.noGenerationStarted'),
|
|
9440
9831
|
{
|
|
9441
9832
|
description: gatedReply.slice(0, 140),
|
|
9442
9833
|
duration: 8000,
|
|
@@ -9459,8 +9850,8 @@ Requirements:
|
|
|
9459
9850
|
lastGenerationFailed: true,
|
|
9460
9851
|
lastGenerationError: 'Authentication expired. Please login again to continue.',
|
|
9461
9852
|
});
|
|
9462
|
-
showToast('error', '
|
|
9463
|
-
description: '
|
|
9853
|
+
showToast('error', $t('creator.session.authenticationExpired'), {
|
|
9854
|
+
description: $t('creator.session.pleaseLoginAgainToContinue'),
|
|
9464
9855
|
duration: 5000
|
|
9465
9856
|
});
|
|
9466
9857
|
return;
|
|
@@ -9475,7 +9866,7 @@ Requirements:
|
|
|
9475
9866
|
lastGenerationFailed: true,
|
|
9476
9867
|
lastGenerationError: normalizedMessage,
|
|
9477
9868
|
});
|
|
9478
|
-
showToast('error', '
|
|
9869
|
+
showToast('error', $t('creator.status.failed'), {
|
|
9479
9870
|
description: normalizedMessage,
|
|
9480
9871
|
duration: 5000
|
|
9481
9872
|
});
|
|
@@ -9499,8 +9890,8 @@ Requirements:
|
|
|
9499
9890
|
lastGenerationFailed: true,
|
|
9500
9891
|
lastGenerationError: 'Cannot track code generation progress. No operation ID received from server.',
|
|
9501
9892
|
});
|
|
9502
|
-
showToast('error', '
|
|
9503
|
-
description: '
|
|
9893
|
+
showToast('error', $t('creator.general.missingOperationId'), {
|
|
9894
|
+
description: $t('creator.codegen.cannotTrackCodeGenerationProgress'),
|
|
9504
9895
|
duration: 5000
|
|
9505
9896
|
});
|
|
9506
9897
|
console.error('Widget Creator: Code generation started, but no operation ID was returned.');
|
|
@@ -9550,10 +9941,10 @@ Requirements:
|
|
|
9550
9941
|
const toastDescription = isServiceError
|
|
9551
9942
|
? errorMsg
|
|
9552
9943
|
: isSvelteSyntaxError
|
|
9553
|
-
? '
|
|
9944
|
+
? $t('creator.codegen.aiGeneratedInvalidSvelteSyntax')
|
|
9554
9945
|
: errorMsg;
|
|
9555
9946
|
|
|
9556
|
-
showToast('error', isServiceError ? '
|
|
9947
|
+
showToast('error', isServiceError ? $t('creator.general.serviceTemporarilyUnavailable') : $t('creator.status.failed'), {
|
|
9557
9948
|
description: toastDescription,
|
|
9558
9949
|
duration: isServiceError ? 10000 : 8000
|
|
9559
9950
|
});
|
|
@@ -9781,18 +10172,18 @@ Requirements:
|
|
|
9781
10172
|
`Code saved${completedCommitSha ? ` (Commit: ${completedCommitSha.substring(0, 7)})` : ''}, but preview build failed:\n${completedPreviewBuildErr}\n\nRebuilding preview…`,
|
|
9782
10173
|
true
|
|
9783
10174
|
);
|
|
9784
|
-
showToast('warning', '
|
|
10175
|
+
showToast('warning', $t('creator.codegen.codeSavedRebuildingPreview'), {
|
|
9785
10176
|
description: completedPreviewBuildErr.length > 120 ? `${completedPreviewBuildErr.slice(0, 120)}…` : completedPreviewBuildErr,
|
|
9786
10177
|
duration: 8000
|
|
9787
10178
|
});
|
|
9788
10179
|
} else {
|
|
9789
10180
|
showToast(
|
|
9790
10181
|
'success',
|
|
9791
|
-
isFocusedPanel ? '
|
|
10182
|
+
isFocusedPanel ? $t('creator.codegen.codeGenerationCompleted') : $t('creator.codegen.generationCompleted', { name: completedWidgetName }),
|
|
9792
10183
|
{
|
|
9793
10184
|
description: isFocusedPanel
|
|
9794
|
-
? '
|
|
9795
|
-
: '
|
|
10185
|
+
? $t('creator.codegen.codeSavedPreviewIsLoading')
|
|
10186
|
+
: $t('creator.general.switchToThatPanelTo'),
|
|
9796
10187
|
duration: 5000
|
|
9797
10188
|
}
|
|
9798
10189
|
);
|
|
@@ -9922,8 +10313,8 @@ Requirements:
|
|
|
9922
10313
|
patchCodegenUiState(generationWidgetId, {
|
|
9923
10314
|
generateCodeStatus: '⚠️ A code generation is already running. Please wait for it to finish.',
|
|
9924
10315
|
});
|
|
9925
|
-
showToast('warning', '
|
|
9926
|
-
description: '
|
|
10316
|
+
showToast('warning', $t('creator.codegen.generationAlreadyInProgress'), {
|
|
10317
|
+
description: $t('creator.codegen.anotherCodeGenerationIsAlready'),
|
|
9927
10318
|
duration: 5000
|
|
9928
10319
|
});
|
|
9929
10320
|
return;
|
|
@@ -9938,12 +10329,12 @@ Requirements:
|
|
|
9938
10329
|
lastGenerationFailed: true,
|
|
9939
10330
|
lastGenerationError: error.message,
|
|
9940
10331
|
});
|
|
9941
|
-
showToast('warning', '
|
|
10332
|
+
showToast('warning', $t('creator.common.thisAppNeedsARefresh'), {
|
|
9942
10333
|
description: error.message,
|
|
9943
10334
|
duration: 12000,
|
|
9944
10335
|
action: {
|
|
9945
|
-
label: '
|
|
9946
|
-
onClick: () =>
|
|
10336
|
+
label: $t('creator.common.reload'),
|
|
10337
|
+
onClick: () => reloadThePage()
|
|
9947
10338
|
}
|
|
9948
10339
|
});
|
|
9949
10340
|
return;
|
|
@@ -9951,14 +10342,28 @@ Requirements:
|
|
|
9951
10342
|
|
|
9952
10343
|
// Handle rate limiting (429) — too many API requests in the time window
|
|
9953
10344
|
if (httpStatus === 429) {
|
|
10345
|
+
// A visitor who used up the budget the partner gave them is told that, and not that the API is busy: a wait
|
|
10346
|
+
// of half a minute would not help them. (The page is told by the limit middleware.)
|
|
10347
|
+
if (partnerMode && (await responseIsALimit(error.response))) {
|
|
10348
|
+
console.warn('Widget Creator: the visitor reached their budget during code generation');
|
|
10349
|
+
const limitMessage = await deriveApiErrorMessage(error, 'Usage limit exceeded');
|
|
10350
|
+
patchCodegenUiState(generationWidgetId, {
|
|
10351
|
+
generateCodeStatus: '⚠️ Limit reached for now. Please try again later.',
|
|
10352
|
+
lastGenerationFailed: true,
|
|
10353
|
+
lastGenerationError: limitMessage,
|
|
10354
|
+
});
|
|
10355
|
+
showToast('warning', $t('creator.general.limitReached'), { description: limitMessage, duration: 8000 });
|
|
10356
|
+
pushCodegenFailureToChat(generationWidgetId, limitMessage);
|
|
10357
|
+
return;
|
|
10358
|
+
}
|
|
9954
10359
|
console.warn('Widget Creator: Rate limited (429) during code generation');
|
|
9955
10360
|
patchCodegenUiState(generationWidgetId, {
|
|
9956
10361
|
generateCodeStatus: '⚠️ Rate limited — too many requests. Wait ~30s and retry.',
|
|
9957
10362
|
lastGenerationFailed: true,
|
|
9958
10363
|
lastGenerationError: 'Too many requests, please try again later.',
|
|
9959
10364
|
});
|
|
9960
|
-
showToast('warning', '
|
|
9961
|
-
description: '
|
|
10365
|
+
showToast('warning', $t('creator.general.rateLimited'), {
|
|
10366
|
+
description: $t('creator.general.theApiRateLimitWas'),
|
|
9962
10367
|
duration: 8000
|
|
9963
10368
|
});
|
|
9964
10369
|
return;
|
|
@@ -9982,7 +10387,7 @@ Requirements:
|
|
|
9982
10387
|
lastGenerationError: message,
|
|
9983
10388
|
});
|
|
9984
10389
|
clearActiveOperationId(); // Clear persisted operationId on error
|
|
9985
|
-
showToast('error', '
|
|
10390
|
+
showToast('error', $t('creator.codegen.codeGenerationError'), { description: message, duration: 6000 });
|
|
9986
10391
|
pushCodegenFailureToChat(generationWidgetId, message);
|
|
9987
10392
|
} finally {
|
|
9988
10393
|
noteCodegenActive(false);
|
|
@@ -10234,7 +10639,7 @@ Requirements:
|
|
|
10234
10639
|
|| lastCommitId);
|
|
10235
10640
|
|
|
10236
10641
|
if (!capturedWidgetId || !capturedCanvasId || !capturedRepositoryId) {
|
|
10237
|
-
showToast('error', '
|
|
10642
|
+
showToast('error', $t('creator.publish.cannotPublish'), { description: $t('creator.canvas.widgetCanvasAndRepositoryAre') });
|
|
10238
10643
|
return;
|
|
10239
10644
|
}
|
|
10240
10645
|
|
|
@@ -10247,7 +10652,7 @@ Requirements:
|
|
|
10247
10652
|
publishingWidgetId = capturedWidgetId;
|
|
10248
10653
|
setCrossTabPublishing(true, capturedWidgetId);
|
|
10249
10654
|
|
|
10250
|
-
publishWidgetStatus = '
|
|
10655
|
+
publishWidgetStatus = $t('creator.widget.fetchingWidgetComponent');
|
|
10251
10656
|
|
|
10252
10657
|
if (!componentsClient || !agentClient) {
|
|
10253
10658
|
throw new Error('API clients are not configured');
|
|
@@ -10271,7 +10676,7 @@ Requirements:
|
|
|
10271
10676
|
// If no component exists for this widget in the canvas, create one now
|
|
10272
10677
|
// (in widget-creator, saving to git doesn't auto-create a component record)
|
|
10273
10678
|
if (!matchedComponent?.id) {
|
|
10274
|
-
publishWidgetStatus = '
|
|
10679
|
+
publishWidgetStatus = $t('creator.widget.creatingWidgetComponent');
|
|
10275
10680
|
const widgetName = getWidgetById(capturedWidgetId)?.name || 'Widget';
|
|
10276
10681
|
// console.log('[Publish] No component found — creating one for widget:', capturedWidgetId, 'name:', widgetName);
|
|
10277
10682
|
|
|
@@ -10294,7 +10699,7 @@ Requirements:
|
|
|
10294
10699
|
const componentId = matchedComponent.id;
|
|
10295
10700
|
// console.log('[Publish] Publishing component:', { componentId, capturedWidgetId, capturedCanvasId });
|
|
10296
10701
|
|
|
10297
|
-
publishWidgetStatus = '
|
|
10702
|
+
publishWidgetStatus = $t('creator.publish.publishingViaWidgetBuilder');
|
|
10298
10703
|
|
|
10299
10704
|
const publishData = await agentClient.agentWidgetBuilderPublishWidgetIdPost({
|
|
10300
10705
|
widgetId: capturedWidgetId,
|
|
@@ -10336,13 +10741,13 @@ Requirements:
|
|
|
10336
10741
|
applyPublishSuccessToWidgetState(capturedWidgetId, version, artifactUrl, commitSha, commitTitle);
|
|
10337
10742
|
|
|
10338
10743
|
if (!publishOpts.silent) {
|
|
10339
|
-
showToast('success', '
|
|
10340
|
-
description:
|
|
10744
|
+
showToast('success', $t('creator.publish.widgetPublished'), {
|
|
10745
|
+
description: $t('creator.version.versionIsNowLive', { version }),
|
|
10341
10746
|
duration: 5000
|
|
10342
10747
|
});
|
|
10343
10748
|
} else {
|
|
10344
|
-
showToast('success',
|
|
10345
|
-
description: publishOpts.fromCodegen ? '
|
|
10749
|
+
showToast('success', $t('creator.general.liveV', { version }), {
|
|
10750
|
+
description: publishOpts.fromCodegen ? $t('creator.publish.publishedAutomaticallyAfterCodeGeneration') : $t('creator.version.versionIsNowLive', { version }),
|
|
10346
10751
|
duration: 4000
|
|
10347
10752
|
});
|
|
10348
10753
|
}
|
|
@@ -10362,14 +10767,14 @@ Requirements:
|
|
|
10362
10767
|
isPublishing = false;
|
|
10363
10768
|
publishingWidgetId = null;
|
|
10364
10769
|
setCrossTabPublishing(false, capturedWidgetId);
|
|
10365
|
-
const publishErrorText = normalizeErrorMessage(err) || '
|
|
10770
|
+
const publishErrorText = normalizeErrorMessage(err) || $t('creator.general.anUnexpectedErrorOccurredPlease');
|
|
10366
10771
|
if (isPlanLimitMessage(publishErrorText) && capturedWidgetId) {
|
|
10367
10772
|
publishPlanMessageByWidgetId = {
|
|
10368
10773
|
...publishPlanMessageByWidgetId,
|
|
10369
10774
|
[capturedWidgetId]: publishErrorText,
|
|
10370
10775
|
};
|
|
10371
10776
|
} else {
|
|
10372
|
-
showToast('error', '
|
|
10777
|
+
showToast('error', $t('creator.publish.publishFailed'), {
|
|
10373
10778
|
description: publishErrorText,
|
|
10374
10779
|
duration: 8000
|
|
10375
10780
|
});
|
|
@@ -10381,7 +10786,7 @@ Requirements:
|
|
|
10381
10786
|
|
|
10382
10787
|
// ===================== Auth Automation =====================
|
|
10383
10788
|
import { userSession, setSession, clearSession, restoreSession } from './stores/userSession.js';
|
|
10384
|
-
import { get } from 'svelte/store';
|
|
10789
|
+
import { get, writable } from 'svelte/store';
|
|
10385
10790
|
|
|
10386
10791
|
|
|
10387
10792
|
// Token expiration check interval
|
|
@@ -10401,7 +10806,8 @@ Requirements:
|
|
|
10401
10806
|
agentHarnessOutput,
|
|
10402
10807
|
dynamicWorkerPreviewStatus,
|
|
10403
10808
|
setAuthToken as setWsAuthToken,
|
|
10404
|
-
setWebsocketApiUrl
|
|
10809
|
+
setWebsocketApiUrl,
|
|
10810
|
+
resetRealtimeState
|
|
10405
10811
|
} from './stores/websocketStore.js';
|
|
10406
10812
|
|
|
10407
10813
|
let lastHarnessChatLine = '';
|
|
@@ -10419,7 +10825,14 @@ Requirements:
|
|
|
10419
10825
|
console.warn('[CreatorApp] No PUBLIC_GOOGLE_FONTS_API_KEY / VITE_GOOGLE_FONTS_API_KEY — FontIC uses fallback catalog');
|
|
10420
10826
|
}
|
|
10421
10827
|
setWebsocketApiUrl(apiRoot ?? null);
|
|
10422
|
-
if (
|
|
10828
|
+
if (partnerMode) {
|
|
10829
|
+
// Take the page's token at once, and keep taking it: the page renews it before it expires, and the
|
|
10830
|
+
// clients are bound to whichever token this last adopted.
|
|
10831
|
+
void adoptHostToken('initial');
|
|
10832
|
+
hostTokenPump = setInterval(() => {
|
|
10833
|
+
void adoptHostToken('initial');
|
|
10834
|
+
}, HOST_TOKEN_PUMP_MS);
|
|
10835
|
+
} else if (embedded) {
|
|
10423
10836
|
syncSessionFromSiteAuth();
|
|
10424
10837
|
} else {
|
|
10425
10838
|
restoreSession();
|
|
@@ -10458,37 +10871,37 @@ Requirements:
|
|
|
10458
10871
|
// Prompt images are restored only after a widget is selected. Restoring the
|
|
10459
10872
|
// legacy global key here can rehydrate already-sent/deleted attachments.
|
|
10460
10873
|
try {
|
|
10461
|
-
|
|
10874
|
+
creatorStorage.removeItem(PROMPT_IMAGES_STORAGE_KEY);
|
|
10462
10875
|
} catch {
|
|
10463
10876
|
/* ignore */
|
|
10464
10877
|
}
|
|
10465
10878
|
|
|
10466
|
-
// Cross-tab operation sync: listen for localStorage changes from other tabs
|
|
10467
|
-
window.
|
|
10468
|
-
|
|
10879
|
+
// Cross-tab operation sync: listen for localStorage changes from other tabs. (Partner mode keeps its state in
|
|
10880
|
+
// memory, so there are no other tabs to hear from, and nothing on the partner's window to listen to.)
|
|
10881
|
+
if (mayListenToSiteEvents()) {
|
|
10882
|
+
window.addEventListener('storage', handleCrossTabStorageEvent);
|
|
10883
|
+
window.addEventListener('widgetic:session-extended', handleSiteSessionExtended);
|
|
10469
10884
|
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10885
|
+
// Clean up cross-tab flags when tab is closed/refreshed. The handler lives at
|
|
10886
|
+
// component scope so `onDestroy` can remove the same reference.
|
|
10887
|
+
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
10888
|
+
// Keep a component-scope binding so onDestroy can remove the listener —
|
|
10889
|
+
// the arrow itself is scoped to this onMount callback.
|
|
10890
|
+
handleBeforeUnloadRef = handleBeforeUnload;
|
|
10891
|
+
}
|
|
10476
10892
|
|
|
10477
10893
|
// Read canvas id from the route. The route path (`/canvas/<canvasId>`) is the
|
|
10478
10894
|
// AUTHORITATIVE canvas (site links, refresh, deep-links); localStorage is only a
|
|
10479
10895
|
// fallback and must never win over it.
|
|
10480
10896
|
if (!routeCanvasId) {
|
|
10481
10897
|
try {
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
setTimeout(() => {
|
|
10490
|
-
if (sub && typeof sub === 'function') sub();
|
|
10491
|
-
}, 0);
|
|
10898
|
+
// `readCanvasIdFromAddressBar()` also covers the legacy query string, so an
|
|
10899
|
+
// old bookmark `/canvas?canvas_id=…` still resolves to its canvas. (This used to be read through
|
|
10900
|
+
// SvelteKit's page store, whose first value is all that was ever used; the package no longer
|
|
10901
|
+
// depends on SvelteKit, so it works outside the Widgetic site too.)
|
|
10902
|
+
const nextCanvasId = readCanvasIdFromAddressBar();
|
|
10903
|
+
// Never clobber an already-known canvas with null.
|
|
10904
|
+
if (nextCanvasId) routeCanvasId = nextCanvasId;
|
|
10492
10905
|
} catch (e) {
|
|
10493
10906
|
console.error('Error reading canvas id from route:', e);
|
|
10494
10907
|
}
|
|
@@ -10511,6 +10924,8 @@ Requirements:
|
|
|
10511
10924
|
// The proxy injects a script that sends postMessage when SvelteKit finishes
|
|
10512
10925
|
// attaching event handlers (buttons become interactive at this point).
|
|
10513
10926
|
const handleHydrationSignal = (event: MessageEvent) => {
|
|
10927
|
+
// In a partner's page `window` also hears the page's other frames; only the creator's previews count.
|
|
10928
|
+
if (!messageIsFromCreatorFrame(event, creatorRootEl)) return;
|
|
10514
10929
|
if (event.data?.type === 'sveltekit-hydration-complete') {
|
|
10515
10930
|
// console.log('Received SvelteKit hydration complete signal from iframe');
|
|
10516
10931
|
previewHydrating = false;
|
|
@@ -10525,6 +10940,7 @@ Requirements:
|
|
|
10525
10940
|
// Listen for runtime error signals from the preview iframe.
|
|
10526
10941
|
// NOTE: WidgetDetails owns this. Do not also flip orphan CreatorApp flags here.
|
|
10527
10942
|
const handleIframeRuntimeError = (event: MessageEvent) => {
|
|
10943
|
+
if (!messageIsFromCreatorFrame(event, creatorRootEl)) return;
|
|
10528
10944
|
if (event.data?.type === 'sveltekit-runtime-error') {
|
|
10529
10945
|
console.warn(
|
|
10530
10946
|
'[CreatorApp] Preview runtime signal (handled by WidgetDetails):',
|
|
@@ -10539,6 +10955,7 @@ Requirements:
|
|
|
10539
10955
|
// an HTML page with a postMessage instead of JSON. We auto-fetch a fresh token
|
|
10540
10956
|
// and reload the iframe seamlessly.
|
|
10541
10957
|
const handleTokenExpired = async (event: MessageEvent) => {
|
|
10958
|
+
if (!messageIsFromCreatorFrame(event, creatorRootEl)) return;
|
|
10542
10959
|
if (event.data?.type === 'preview-token-expired') {
|
|
10543
10960
|
console.warn('Preview token expired — delegating refresh to WidgetDetails');
|
|
10544
10961
|
widgetDetails?.refreshPreview();
|
|
@@ -10589,10 +11006,23 @@ Requirements:
|
|
|
10589
11006
|
}
|
|
10590
11007
|
if (isPublishing) setCrossTabPublishing(false);
|
|
10591
11008
|
}
|
|
11009
|
+
// Partner mode ends with the creator: the token pump stops, and nothing the creator holds about this visitor
|
|
11010
|
+
// outlives it (the page may start the next visitor in the same tab). Last, because the cleanup above still
|
|
11011
|
+
// writes through the same storage.
|
|
11012
|
+
if (hostTokenPump) {
|
|
11013
|
+
clearInterval(hostTokenPump);
|
|
11014
|
+
hostTokenPump = null;
|
|
11015
|
+
}
|
|
11016
|
+
if (partnerMode) {
|
|
11017
|
+
clearSession();
|
|
11018
|
+
setFileBrowserUploadConfig(null);
|
|
11019
|
+
resetRealtimeState();
|
|
11020
|
+
leavePartnerMode();
|
|
11021
|
+
}
|
|
10592
11022
|
});
|
|
10593
11023
|
|
|
10594
11024
|
onMount(() => {
|
|
10595
|
-
if (typeof window === 'undefined') return;
|
|
11025
|
+
if (typeof window === 'undefined' || !mayUseAddressBar()) return;
|
|
10596
11026
|
if (new URLSearchParams(window.location.search).get('attachStairsRef') === '1') {
|
|
10597
11027
|
wantStairsReferenceAttach = true;
|
|
10598
11028
|
const url = new URL(window.location.href);
|
|
@@ -10605,18 +11035,22 @@ Requirements:
|
|
|
10605
11035
|
// Register click-outside listener for canvas dropdown
|
|
10606
11036
|
onMount(() => {
|
|
10607
11037
|
window.addEventListener('click', handleCanvasDropdownOutsideClick);
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
|
|
10616
|
-
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
11038
|
+
// The `widgetic:host-*` events are the Widgetic site's header talking to the creator; a partner's page has no
|
|
11039
|
+
// such header, and a page-wide listener there would answer to whatever the partner's own scripts dispatch.
|
|
11040
|
+
if (mayListenToSiteEvents()) {
|
|
11041
|
+
window.addEventListener(HOST_WIDGET_RENAMED_EVENT, handleHostWidgetRenamedEvent);
|
|
11042
|
+
window.addEventListener(HOST_REQUEST_PUBLISH_EVENT, handleHostRequestPublishEvent);
|
|
11043
|
+
window.addEventListener(HOST_TOGGLE_DEBUG_EVENT, handleHostToggleDebugEvent);
|
|
11044
|
+
window.addEventListener(HOST_TOGGLE_WIREFRAME_EVENT, handleHostToggleWireframeEvent);
|
|
11045
|
+
window.addEventListener(HOST_TOGGLE_ADVANCED_EVENT, handleHostToggleAdvancedEvent);
|
|
11046
|
+
window.addEventListener(HOST_OPEN_WIDGET_DETAILS_EVENT, handleHostOpenWidgetDetailsEvent);
|
|
11047
|
+
window.addEventListener(HOST_DUPLICATE_WIDGET_EVENT, handleHostDuplicateWidgetEvent);
|
|
11048
|
+
window.addEventListener(HOST_DELETE_WIDGET_EVENT, handleHostDeleteWidgetEvent);
|
|
11049
|
+
window.addEventListener(HOST_SAVE_CANVAS_EVENT, handleHostSaveCanvasEvent);
|
|
11050
|
+
window.addEventListener(HOST_SET_PRIMARY_WIDGET_EVENT, handleHostSetPrimaryWidgetEvent);
|
|
11051
|
+
window.addEventListener(HOST_REQUEST_CANVAS_WIDGETS_EVENT, handleHostRequestCanvasWidgetsEvent);
|
|
11052
|
+
window.addEventListener(HOST_MOVE_CANVAS_FOLDER_EVENT, handleHostMoveCanvasFolderEvent);
|
|
11053
|
+
}
|
|
10620
11054
|
emitCreatorDebugChanged();
|
|
10621
11055
|
emitCreatorWireframeChanged();
|
|
10622
11056
|
emitCreatorAdvancedChanged();
|
|
@@ -10627,6 +11061,8 @@ Requirements:
|
|
|
10627
11061
|
onMount(() => {
|
|
10628
11062
|
const handleEscapeCapture = (e: KeyboardEvent) => {
|
|
10629
11063
|
if (e.key !== 'Escape') return;
|
|
11064
|
+
// In a partner's page an Escape that started outside the creator is the partner's (their own dialog).
|
|
11065
|
+
if (!eventIsFromCreator(e, creatorRootEl)) return;
|
|
10630
11066
|
if (lightboxImage) {
|
|
10631
11067
|
lightboxImage = null;
|
|
10632
11068
|
e.stopImmediatePropagation();
|
|
@@ -10644,9 +11080,10 @@ Requirements:
|
|
|
10644
11080
|
onMount(() => {
|
|
10645
11081
|
const handlePasteCapture = async (e: ClipboardEvent) => {
|
|
10646
11082
|
if (!showWidgetDetails || !selectedWidgetId) return;
|
|
10647
|
-
|
|
10648
|
-
// Only intercept if paste originates from inside widget details or widgets list panels
|
|
10649
|
-
|
|
11083
|
+
if (!eventIsFromCreator(e, creatorRootEl)) return;
|
|
11084
|
+
// Only intercept if paste originates from inside widget details or widgets list panels. (The event's whole
|
|
11085
|
+
// path is looked at, not `e.target.closest(…)`: in a shadow root `target` is the shadow's host element.)
|
|
11086
|
+
const isInsidePanel = eventPathMatches(e, '.widget-details-floating-panel, .widgets-list-panel, [data-widget-details]');
|
|
10650
11087
|
if (!isInsidePanel) return;
|
|
10651
11088
|
const items = e.clipboardData?.items;
|
|
10652
11089
|
if (!items) return;
|
|
@@ -10659,7 +11096,7 @@ Requirements:
|
|
|
10659
11096
|
const base64 = await processImageFile(file);
|
|
10660
11097
|
if (base64) {
|
|
10661
11098
|
chatMethods?.addImageAttachment?.(base64, file.name || 'pasted-image.png');
|
|
10662
|
-
showToast('success', '
|
|
11099
|
+
showToast('success', $t('creator.codegen.imagePastedToPrompt'), { duration: 2000 });
|
|
10663
11100
|
}
|
|
10664
11101
|
}
|
|
10665
11102
|
return;
|
|
@@ -10689,7 +11126,7 @@ Requirements:
|
|
|
10689
11126
|
|
|
10690
11127
|
function saveCommitIdForWidget(widgetId: string, commitId: string) {
|
|
10691
11128
|
commitIdMemoryCache.set(widgetId, commitId);
|
|
10692
|
-
try {
|
|
11129
|
+
try { creatorStorage.setItem(COMMIT_ID_STORAGE_PREFIX + widgetId, commitId); } catch (e) { /* ignore */ }
|
|
10693
11130
|
}
|
|
10694
11131
|
|
|
10695
11132
|
function loadCommitIdForWidget(widgetId: string): string | null {
|
|
@@ -10697,7 +11134,7 @@ Requirements:
|
|
|
10697
11134
|
return commitIdMemoryCache.get(widgetId) ?? null;
|
|
10698
11135
|
}
|
|
10699
11136
|
try {
|
|
10700
|
-
const id =
|
|
11137
|
+
const id = creatorStorage.getItem(COMMIT_ID_STORAGE_PREFIX + widgetId);
|
|
10701
11138
|
if (id) {
|
|
10702
11139
|
commitIdMemoryCache.set(widgetId, id);
|
|
10703
11140
|
return id;
|
|
@@ -10714,15 +11151,15 @@ Requirements:
|
|
|
10714
11151
|
function savePendingPublishShaForWidget(widgetId: string, commitId: string) {
|
|
10715
11152
|
const sha = normalizeCommitSha(commitId) || commitId;
|
|
10716
11153
|
if (!widgetId || !sha) return;
|
|
10717
|
-
try {
|
|
11154
|
+
try { creatorSessionStorage.setItem(PENDING_PUBLISH_STORAGE_PREFIX + widgetId, sha); } catch (e) { /* ignore */ }
|
|
10718
11155
|
}
|
|
10719
11156
|
|
|
10720
11157
|
function loadPendingPublishShaForWidget(widgetId: string): string | null {
|
|
10721
|
-
try { return
|
|
11158
|
+
try { return creatorSessionStorage.getItem(PENDING_PUBLISH_STORAGE_PREFIX + widgetId); } catch (e) { return null; }
|
|
10722
11159
|
}
|
|
10723
11160
|
|
|
10724
11161
|
function clearPendingPublishShaForWidget(widgetId: string) {
|
|
10725
|
-
try {
|
|
11162
|
+
try { creatorSessionStorage.removeItem(PENDING_PUBLISH_STORAGE_PREFIX + widgetId); } catch (e) { /* ignore */ }
|
|
10726
11163
|
}
|
|
10727
11164
|
|
|
10728
11165
|
const COMMIT_MESSAGE_REGEX = /Commit:?\s+([a-f0-9]{7,40})/i;
|
|
@@ -10806,18 +11243,31 @@ Requirements:
|
|
|
10806
11243
|
return typeof raw === 'string' && raw.trim().length > 0 ? raw.trim() : null;
|
|
10807
11244
|
}
|
|
10808
11245
|
|
|
11246
|
+
/**
|
|
11247
|
+
* The line of a code generation that is under way, as a visitor reads it ("Generating code... (40%)"). It is one of the
|
|
11248
|
+
* creator's own lines that the status bar says in the page's language (`i18n/statusText.ts` knows both forms).
|
|
11249
|
+
*/
|
|
11250
|
+
function codegenProgressLine(pct: number | null): string {
|
|
11251
|
+
return pct != null && pct > 0 ? `Generating code... (${pct}%)` : 'Generating code...';
|
|
11252
|
+
}
|
|
11253
|
+
|
|
11254
|
+
/** The lines of debug mode, which a partner's visitor never reads: the server's own stage, or the operation's status and number. */
|
|
11255
|
+
function codegenProgressDebugLine(op: OperationStatus, stage: string | null, pct: number | null): string {
|
|
11256
|
+
if (stage) {
|
|
11257
|
+
return pct != null && pct > 0 ? `${stage} (${pct}%)` : stage;
|
|
11258
|
+
}
|
|
11259
|
+
const progressText = pct != null ? `${pct}%` : '';
|
|
11260
|
+
return progressText ? `Generating code... ${progressText}` : `Generating code (${op.status})...`;
|
|
11261
|
+
}
|
|
11262
|
+
|
|
10809
11263
|
function formatCodegenProgressStatus(op: OperationStatus): string {
|
|
10810
11264
|
const stage = getOperationStageMessage(op.metadata as Record<string, unknown> | undefined);
|
|
10811
11265
|
const pct = typeof op.progress === 'number' ? op.progress : null;
|
|
10812
11266
|
// User mode: never expose model names / provider in the status line.
|
|
10813
11267
|
if (!debugMode) {
|
|
10814
|
-
return
|
|
10815
|
-
}
|
|
10816
|
-
if (stage) {
|
|
10817
|
-
return pct != null && pct > 0 ? `${stage} (${pct}%)` : stage;
|
|
11268
|
+
return codegenProgressLine(pct);
|
|
10818
11269
|
}
|
|
10819
|
-
|
|
10820
|
-
return progressText ? `Generating code... ${progressText}` : `Generating code (${op.status})...`;
|
|
11270
|
+
return codegenProgressDebugLine(op, stage, pct);
|
|
10821
11271
|
}
|
|
10822
11272
|
|
|
10823
11273
|
function pushCodegenProgressToUi(op: OperationStatus, widgetId: string | null | undefined) {
|
|
@@ -11147,7 +11597,7 @@ Requirements:
|
|
|
11147
11597
|
let storedPrompt = DEFAULT_PROMPT;
|
|
11148
11598
|
try {
|
|
11149
11599
|
storedPrompt =
|
|
11150
|
-
|
|
11600
|
+
creatorStorage.getItem(PROMPT_TEXT_STORAGE_PREFIX + widgetId) ?? DEFAULT_PROMPT;
|
|
11151
11601
|
} catch {
|
|
11152
11602
|
/* ignore */
|
|
11153
11603
|
}
|
|
@@ -11444,9 +11894,13 @@ Requirements:
|
|
|
11444
11894
|
}
|
|
11445
11895
|
}
|
|
11446
11896
|
const widget = getWidgetById(widgetId);
|
|
11897
|
+
const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null; js_path?: string | null } | undefined)?.jsPath
|
|
11898
|
+
?? (widget as { js_path?: string | null } | undefined)?.js_path
|
|
11899
|
+
?? null;
|
|
11900
|
+
const borrowed = borrowedPresetArtifactUrl(widgetId, jsPath);
|
|
11901
|
+
if (borrowed && source !== 'preview') return borrowed;
|
|
11447
11902
|
const version = ps.lastPublishedVersion ?? resolvePublishedVersionFromWidget(widget);
|
|
11448
11903
|
if (version == null) return null;
|
|
11449
|
-
const jsPath = ps.selectedWidgetJsPath ?? (widget as { jsPath?: string | null } | undefined)?.jsPath ?? null;
|
|
11450
11904
|
return resolvePublishedWidgetUrl(widgetId, version, jsPath);
|
|
11451
11905
|
}
|
|
11452
11906
|
|
|
@@ -11685,20 +12139,19 @@ Requirements:
|
|
|
11685
12139
|
return newestDraft != null ? `v${newestDraft}` : null;
|
|
11686
12140
|
}
|
|
11687
12141
|
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
return `${month}/${day}/${d.getFullYear()} ${timePart}`;
|
|
12142
|
+
/**
|
|
12143
|
+
* The date of a version, written the way the page's language writes dates. A template that shows it passes `$languageTag`
|
|
12144
|
+
* so the row is written again when the page changes the language; the canvas, which asks for the options when it needs
|
|
12145
|
+
* them, gets whatever language is current.
|
|
12146
|
+
*/
|
|
12147
|
+
function formatPublishHistoryDate(
|
|
12148
|
+
record: {
|
|
12149
|
+
publishedAt?: string;
|
|
12150
|
+
published_at?: string;
|
|
12151
|
+
},
|
|
12152
|
+
dateLanguage: string = get(languageTag)
|
|
12153
|
+
): string {
|
|
12154
|
+
return versionDateText(new Date(record.publishedAt ?? record.published_at ?? ''), dateLanguage);
|
|
11702
12155
|
}
|
|
11703
12156
|
|
|
11704
12157
|
function resolveWidgetShapeVersionOptions(
|
|
@@ -11739,7 +12192,7 @@ Requirements:
|
|
|
11739
12192
|
const isPublished = !!(record.publishedAt ?? record.published_at);
|
|
11740
12193
|
options.push({
|
|
11741
12194
|
id: `v:${version}`,
|
|
11742
|
-
label:
|
|
12195
|
+
label: $t('creator.version.version', { version }),
|
|
11743
12196
|
shortLabel: `v${version}`,
|
|
11744
12197
|
dateLabel: formatPublishHistoryDate(record),
|
|
11745
12198
|
// Only a published version can be what visitors see.
|
|
@@ -11751,7 +12204,7 @@ Requirements:
|
|
|
11751
12204
|
if (options.length === 0 && liveVersion != null) {
|
|
11752
12205
|
options.push({
|
|
11753
12206
|
id: `v:${liveVersion}`,
|
|
11754
|
-
label:
|
|
12207
|
+
label: $t('creator.version.version', { version: liveVersion }),
|
|
11755
12208
|
shortLabel: `v${liveVersion}`,
|
|
11756
12209
|
dateLabel: '—',
|
|
11757
12210
|
isLive: true,
|
|
@@ -11986,6 +12439,7 @@ Requirements:
|
|
|
11986
12439
|
void restoredViewingVersionByWidgetId;
|
|
11987
12440
|
void dropdownVersionByWidgetId;
|
|
11988
12441
|
void panelDisplayRevision;
|
|
12442
|
+
void $t;
|
|
11989
12443
|
const nextHeads: Record<string, string | null> = {};
|
|
11990
12444
|
const nextLabels: Record<string, Record<string, string>> = {};
|
|
11991
12445
|
const nextPrompts: Record<string, Record<string, string>> = {};
|
|
@@ -12530,7 +12984,8 @@ Requirements:
|
|
|
12530
12984
|
|
|
12531
12985
|
// Widgets Panel sizing — dynamically adapts to auth panel height
|
|
12532
12986
|
const topBarHeight = 56; // h-14 (3.5rem) top bar
|
|
12533
|
-
|
|
12987
|
+
// site AppHeader when CreatorApp is embedded in /canvas; a partner's page has no such header above the creator.
|
|
12988
|
+
const embeddedSiteHeaderHeight = partnerMode ? 8 : 56;
|
|
12534
12989
|
const widgetsPanelBottomMargin = 130; // kept for details panel default sizing
|
|
12535
12990
|
$: widgetsPanelTopOffset = embedded ? embeddedSiteHeaderHeight : topBarHeight + 8;
|
|
12536
12991
|
let widgetsPanelWidth = 450;
|
|
@@ -12578,14 +13033,16 @@ Requirements:
|
|
|
12578
13033
|
widgetsPanelY = Math.round(rect.top);
|
|
12579
13034
|
}
|
|
12580
13035
|
|
|
13036
|
+
/** The drag cursor of the panel's edges and of the panel itself (on the page's <body> on the site, in the creator's own area in a partner's page). */
|
|
13037
|
+
const widgetsPanelDragFeedback = createDragFeedback();
|
|
13038
|
+
|
|
12581
13039
|
function startWidgetsPanelResize(e: MouseEvent) {
|
|
12582
13040
|
e.preventDefault();
|
|
12583
13041
|
e.stopPropagation();
|
|
12584
13042
|
isResizingWidgetsPanel = true;
|
|
12585
13043
|
widgetsResizeStartX = e.clientX;
|
|
12586
13044
|
widgetsResizeStartWidth = widgetsPanelWidth;
|
|
12587
|
-
|
|
12588
|
-
document.body.style.userSelect = 'none';
|
|
13045
|
+
widgetsPanelDragFeedback.start(creatorRootEl, 'col-resize');
|
|
12589
13046
|
document.addEventListener('mousemove', onWidgetsPanelResize);
|
|
12590
13047
|
document.addEventListener('mouseup', stopWidgetsPanelResize);
|
|
12591
13048
|
}
|
|
@@ -12599,8 +13056,7 @@ Requirements:
|
|
|
12599
13056
|
|
|
12600
13057
|
function stopWidgetsPanelResize() {
|
|
12601
13058
|
isResizingWidgetsPanel = false;
|
|
12602
|
-
|
|
12603
|
-
document.body.style.userSelect = '';
|
|
13059
|
+
widgetsPanelDragFeedback.stop();
|
|
12604
13060
|
document.removeEventListener('mousemove', onWidgetsPanelResize);
|
|
12605
13061
|
document.removeEventListener('mouseup', stopWidgetsPanelResize);
|
|
12606
13062
|
}
|
|
@@ -12614,8 +13070,7 @@ Requirements:
|
|
|
12614
13070
|
widgetsResizeStartY = e.clientY;
|
|
12615
13071
|
widgetsResizeStartWidth = widgetsPanelWidth;
|
|
12616
13072
|
widgetsResizeStartHeight = widgetsPanelHeight;
|
|
12617
|
-
|
|
12618
|
-
document.body.style.userSelect = 'none';
|
|
13073
|
+
widgetsPanelDragFeedback.start(creatorRootEl, 'nwse-resize');
|
|
12619
13074
|
document.addEventListener('mousemove', onWidgetsPanelCornerResize);
|
|
12620
13075
|
document.addEventListener('mouseup', stopWidgetsPanelCornerResize);
|
|
12621
13076
|
}
|
|
@@ -12634,8 +13089,7 @@ Requirements:
|
|
|
12634
13089
|
|
|
12635
13090
|
function stopWidgetsPanelCornerResize() {
|
|
12636
13091
|
isResizingWidgetsPanelCorner = false;
|
|
12637
|
-
|
|
12638
|
-
document.body.style.userSelect = '';
|
|
13092
|
+
widgetsPanelDragFeedback.stop();
|
|
12639
13093
|
document.removeEventListener('mousemove', onWidgetsPanelCornerResize);
|
|
12640
13094
|
document.removeEventListener('mouseup', stopWidgetsPanelCornerResize);
|
|
12641
13095
|
}
|
|
@@ -12654,7 +13108,7 @@ Requirements:
|
|
|
12654
13108
|
widgetsPanelY = y;
|
|
12655
13109
|
// Direct DOM write keeps drag smooth even if Svelte batching lags on inline style updates.
|
|
12656
13110
|
if (widgetsPanelEl) {
|
|
12657
|
-
widgetsPanelEl.style.left = `${x}px`;
|
|
13111
|
+
widgetsPanelEl.style.left = `${x}px`; // rtl-ok: the panel is put in pixels from the left edge of the screen and dragged there
|
|
12658
13112
|
widgetsPanelEl.style.top = `${y}px`;
|
|
12659
13113
|
}
|
|
12660
13114
|
}
|
|
@@ -12669,8 +13123,7 @@ Requirements:
|
|
|
12669
13123
|
widgetsPanelDragStartY = e.clientY;
|
|
12670
13124
|
widgetsPanelInitialX = widgetsPanelX;
|
|
12671
13125
|
widgetsPanelInitialY = widgetsPanelY < 0 ? widgetsPanelTopOffset : widgetsPanelY;
|
|
12672
|
-
|
|
12673
|
-
document.body.style.userSelect = 'none';
|
|
13126
|
+
widgetsPanelDragFeedback.start(creatorRootEl, 'grabbing');
|
|
12674
13127
|
document.addEventListener('pointermove', onWidgetsPanelDrag);
|
|
12675
13128
|
document.addEventListener('pointerup', stopWidgetsPanelDrag);
|
|
12676
13129
|
document.addEventListener('pointercancel', stopWidgetsPanelDrag);
|
|
@@ -12699,8 +13152,7 @@ Requirements:
|
|
|
12699
13152
|
function stopWidgetsPanelDrag(e?: PointerEvent) {
|
|
12700
13153
|
if (!isDraggingWidgetsPanel) return;
|
|
12701
13154
|
isDraggingWidgetsPanel = false;
|
|
12702
|
-
|
|
12703
|
-
document.body.style.userSelect = '';
|
|
13155
|
+
widgetsPanelDragFeedback.stop();
|
|
12704
13156
|
document.removeEventListener('pointermove', onWidgetsPanelDrag);
|
|
12705
13157
|
document.removeEventListener('pointerup', stopWidgetsPanelDrag);
|
|
12706
13158
|
document.removeEventListener('pointercancel', stopWidgetsPanelDrag);
|
|
@@ -13159,13 +13611,13 @@ Requirements:
|
|
|
13159
13611
|
const nextVersion = (ps.lastPublishedVersion ?? 0) + 1;
|
|
13160
13612
|
|
|
13161
13613
|
if (panelIsPublishing) {
|
|
13162
|
-
return { disabled: true, label: '
|
|
13614
|
+
return { disabled: true, label: $t('creator.publish.publishing'), reason: $t('creator.publish.publishingInProgress'), showDisabledHint: false };
|
|
13163
13615
|
}
|
|
13164
13616
|
if (anotherPanelIsPublishing) {
|
|
13165
13617
|
return {
|
|
13166
13618
|
disabled: true,
|
|
13167
13619
|
label: getPublishButtonLabelFallback(ps),
|
|
13168
|
-
reason: '
|
|
13620
|
+
reason: $t('creator.publish.anotherWidgetIsPublishingWait'),
|
|
13169
13621
|
showDisabledHint: true,
|
|
13170
13622
|
};
|
|
13171
13623
|
}
|
|
@@ -13173,7 +13625,7 @@ Requirements:
|
|
|
13173
13625
|
return {
|
|
13174
13626
|
disabled: true,
|
|
13175
13627
|
label: getPublishButtonLabelFallback(ps),
|
|
13176
|
-
reason: '
|
|
13628
|
+
reason: $t('creator.publish.publishIsRunningInAnother'),
|
|
13177
13629
|
showDisabledHint: true,
|
|
13178
13630
|
};
|
|
13179
13631
|
}
|
|
@@ -13181,7 +13633,7 @@ Requirements:
|
|
|
13181
13633
|
return {
|
|
13182
13634
|
disabled: true,
|
|
13183
13635
|
label: getPublishButtonLabelFallback(ps),
|
|
13184
|
-
reason: '
|
|
13636
|
+
reason: $t('creator.codegen.codeGenerationInProgressWait'),
|
|
13185
13637
|
showDisabledHint: true,
|
|
13186
13638
|
};
|
|
13187
13639
|
}
|
|
@@ -13189,7 +13641,7 @@ Requirements:
|
|
|
13189
13641
|
return {
|
|
13190
13642
|
disabled: true,
|
|
13191
13643
|
label: getPublishButtonLabelFallback(ps),
|
|
13192
|
-
reason: '
|
|
13644
|
+
reason: $t('creator.canvas.canvasIsRequiredBeforePublishing'),
|
|
13193
13645
|
showDisabledHint: true,
|
|
13194
13646
|
};
|
|
13195
13647
|
}
|
|
@@ -13197,7 +13649,7 @@ Requirements:
|
|
|
13197
13649
|
return {
|
|
13198
13650
|
disabled: true,
|
|
13199
13651
|
label: getPublishButtonLabelFallback(ps),
|
|
13200
|
-
reason: '
|
|
13652
|
+
reason: $t('creator.codegen.repositoryMissingUseRebuildCode'),
|
|
13201
13653
|
showDisabledHint: true,
|
|
13202
13654
|
};
|
|
13203
13655
|
}
|
|
@@ -13205,13 +13657,13 @@ Requirements:
|
|
|
13205
13657
|
return {
|
|
13206
13658
|
disabled: true,
|
|
13207
13659
|
label: getPublishButtonLabelFallback(ps),
|
|
13208
|
-
reason: '
|
|
13660
|
+
reason: signInAgainText($t('creator.session.signInAgainToPublish')),
|
|
13209
13661
|
showDisabledHint: true,
|
|
13210
13662
|
};
|
|
13211
13663
|
}
|
|
13212
13664
|
const previewBlockReason = getVersionPreviewPublishBlockReason(widgetId, targetVersion);
|
|
13213
13665
|
if (previewBlockReason) {
|
|
13214
|
-
return { disabled: true, label: '
|
|
13666
|
+
return { disabled: true, label: $t('creator.common.publish'), reason: errorLabel(previewBlockReason, $t), showDisabledHint: true };
|
|
13215
13667
|
}
|
|
13216
13668
|
// An explicit Draft owns its commit: HEAD being Live must not block it.
|
|
13217
13669
|
// Keep all shared auth/canvas/repository/concurrency checks above this branch.
|
|
@@ -13221,27 +13673,27 @@ Requirements:
|
|
|
13221
13673
|
);
|
|
13222
13674
|
const validVersion = targetVersion !== '' && Number.isInteger(Number(targetVersion)) && Number(targetVersion) > 0;
|
|
13223
13675
|
const reason = !validVersion || !record
|
|
13224
|
-
? '
|
|
13676
|
+
? $t('creator.version.theSelectedDraftVersionWas')
|
|
13225
13677
|
: (record.publishedAt ?? record.published_at)
|
|
13226
|
-
? '
|
|
13678
|
+
? $t('creator.publish.thisVersionIsAlreadyPublished')
|
|
13227
13679
|
: !(record.commitSha ?? record.commit_sha)
|
|
13228
|
-
? '
|
|
13680
|
+
? $t('creator.publish.thisDraftHasNoRecorded')
|
|
13229
13681
|
: null;
|
|
13230
|
-
return { disabled: !!reason, label: '
|
|
13682
|
+
return { disabled: !!reason, label: $t('creator.common.publish'), reason, showDisabledHint: !!reason };
|
|
13231
13683
|
}
|
|
13232
13684
|
|
|
13233
13685
|
if (!hasCode) {
|
|
13234
13686
|
return {
|
|
13235
13687
|
disabled: true,
|
|
13236
13688
|
label: getPublishButtonLabelFallback(ps),
|
|
13237
|
-
reason: '
|
|
13689
|
+
reason: $t('creator.publish.generateWidgetCodeBeforePublishing'),
|
|
13238
13690
|
showDisabledHint: true,
|
|
13239
13691
|
};
|
|
13240
13692
|
}
|
|
13241
13693
|
|
|
13242
13694
|
// Never published → allow Publish once code exists.
|
|
13243
13695
|
if (ps.lastPublishedVersion === null) {
|
|
13244
|
-
return { disabled: false, label: '
|
|
13696
|
+
return { disabled: false, label: $t('creator.publish.publishWidget'), reason: null, showDisabledHint: false };
|
|
13245
13697
|
}
|
|
13246
13698
|
|
|
13247
13699
|
const headSha = resolvePublishHeadCommitId(widgetId, ps);
|
|
@@ -13262,8 +13714,8 @@ Requirements:
|
|
|
13262
13714
|
if (headSha && liveSha && commitsMatch(headSha, liveSha) && !pendingPublish && !unpublishedAhead) {
|
|
13263
13715
|
return {
|
|
13264
13716
|
disabled: true,
|
|
13265
|
-
label: '
|
|
13266
|
-
reason:
|
|
13717
|
+
label: $t('creator.publish.noNewVersionToPublish'),
|
|
13718
|
+
reason: $t('creator.general.latestCommitIsAlreadyLive', { commit: formatCommitShaShort(headSha), version: ps.lastPublishedVersion }),
|
|
13267
13719
|
showDisabledHint: false,
|
|
13268
13720
|
};
|
|
13269
13721
|
}
|
|
@@ -13278,7 +13730,7 @@ Requirements:
|
|
|
13278
13730
|
// });
|
|
13279
13731
|
return {
|
|
13280
13732
|
disabled: false,
|
|
13281
|
-
label:
|
|
13733
|
+
label: $t('creator.publish.publishNewV', { version: nextVersion }),
|
|
13282
13734
|
reason: null,
|
|
13283
13735
|
showDisabledHint: false,
|
|
13284
13736
|
};
|
|
@@ -13288,7 +13740,7 @@ Requirements:
|
|
|
13288
13740
|
if (headSha && liveSha && !commitsMatch(headSha, liveSha)) {
|
|
13289
13741
|
return {
|
|
13290
13742
|
disabled: false,
|
|
13291
|
-
label:
|
|
13743
|
+
label: $t('creator.publish.publishNewV', { version: nextVersion }),
|
|
13292
13744
|
reason: null,
|
|
13293
13745
|
showDisabledHint: false,
|
|
13294
13746
|
};
|
|
@@ -13298,15 +13750,15 @@ Requirements:
|
|
|
13298
13750
|
if (!headSha) {
|
|
13299
13751
|
return {
|
|
13300
13752
|
disabled: true,
|
|
13301
|
-
label: '
|
|
13302
|
-
reason: '
|
|
13753
|
+
label: $t('creator.publish.noNewVersionToPublish'),
|
|
13754
|
+
reason: $t('creator.publish.generateOrRebuildSoWe'),
|
|
13303
13755
|
showDisabledHint: true,
|
|
13304
13756
|
};
|
|
13305
13757
|
}
|
|
13306
13758
|
|
|
13307
13759
|
return {
|
|
13308
13760
|
disabled: true,
|
|
13309
|
-
label: '
|
|
13761
|
+
label: $t('creator.publish.noNewVersionToPublish'),
|
|
13310
13762
|
reason: null,
|
|
13311
13763
|
showDisabledHint: false,
|
|
13312
13764
|
};
|
|
@@ -13397,7 +13849,7 @@ Requirements:
|
|
|
13397
13849
|
const gateBefore = getPublishGateForPanel(panelWidgetId, targetVersion ?? null);
|
|
13398
13850
|
if (gateBefore.disabled) {
|
|
13399
13851
|
if (gateBefore.reason) {
|
|
13400
|
-
showToast('info', '
|
|
13852
|
+
showToast('info', $t('creator.publish.cannotPublishYet'), { description: gateBefore.reason, duration: 5000 });
|
|
13401
13853
|
}
|
|
13402
13854
|
return;
|
|
13403
13855
|
}
|
|
@@ -13410,7 +13862,7 @@ Requirements:
|
|
|
13410
13862
|
const gateAfter = getPublishGateForPanel(panelWidgetId, targetVersion ?? null);
|
|
13411
13863
|
if (gateAfter.disabled) {
|
|
13412
13864
|
if (gateAfter.reason) {
|
|
13413
|
-
showToast('info', '
|
|
13865
|
+
showToast('info', $t('creator.publish.cannotPublishYet'), { description: gateAfter.reason, duration: 5000 });
|
|
13414
13866
|
}
|
|
13415
13867
|
return;
|
|
13416
13868
|
}
|
|
@@ -13438,7 +13890,7 @@ $: if ($widgetPublishStatus.timestamp && $widgetPublishStatus.widgetId) {
|
|
|
13438
13890
|
|
|
13439
13891
|
if (publishResult.status === 'success') {
|
|
13440
13892
|
if (isFocusedPublish) {
|
|
13441
|
-
publishWidgetStatus =
|
|
13893
|
+
publishWidgetStatus = $t('creator.publish.publishedVSuccessfully', { version: publishResult.version ?? '?' });
|
|
13442
13894
|
}
|
|
13443
13895
|
const publishedVersion = publishResult.version ?? 1;
|
|
13444
13896
|
applyPublishSuccessToWidgetState(
|
|
@@ -13449,8 +13901,8 @@ $: if ($widgetPublishStatus.timestamp && $widgetPublishStatus.widgetId) {
|
|
|
13449
13901
|
publishResult.commitTitle ?? null
|
|
13450
13902
|
);
|
|
13451
13903
|
const publishedName = getWidgetById(publishWidgetId)?.name || 'Widget';
|
|
13452
|
-
showToast('success',
|
|
13453
|
-
description:
|
|
13904
|
+
showToast('success', $t('creator.publish.published', { name: publishedName }), {
|
|
13905
|
+
description: $t('creator.embed.versionIsLiveAndReady', { version: publishResult.version ?? '' }),
|
|
13454
13906
|
duration: 6000
|
|
13455
13907
|
});
|
|
13456
13908
|
if (publishWidgetId) {
|
|
@@ -13471,8 +13923,8 @@ $: if ($widgetPublishStatus.timestamp && $widgetPublishStatus.widgetId) {
|
|
|
13471
13923
|
if (isFocusedPublish) {
|
|
13472
13924
|
publishWidgetStatus = null;
|
|
13473
13925
|
}
|
|
13474
|
-
showToast('error', '
|
|
13475
|
-
description: publishResult.message || publishResult.error?.details || '
|
|
13926
|
+
showToast('error', $t('creator.publish.widgetPublishFailed'), {
|
|
13927
|
+
description: publishResult.message || publishResult.error?.details || $t('creator.codegen.buildFailedCheckLogsFor'),
|
|
13476
13928
|
duration: 8000
|
|
13477
13929
|
});
|
|
13478
13930
|
}
|
|
@@ -13613,7 +14065,7 @@ async function loadPublishHistoryForPanel(widgetId: string, opts: { silent?: boo
|
|
|
13613
14065
|
publishHistoryResolvedForWidgetId = widgetId;
|
|
13614
14066
|
}
|
|
13615
14067
|
if (!opts.silent && widgetId === selectedWidgetId) {
|
|
13616
|
-
showToast('error', '
|
|
14068
|
+
showToast('error', $t('creator.publish.failedToLoadPublishHistory'));
|
|
13617
14069
|
}
|
|
13618
14070
|
} finally {
|
|
13619
14071
|
if (!opts.silent && widgetId === selectedWidgetId) {
|
|
@@ -13647,15 +14099,15 @@ async function setLiveVersionForWidget(widgetId: string, version: number) {
|
|
|
13647
14099
|
(row) => Number(row.version) === version,
|
|
13648
14100
|
);
|
|
13649
14101
|
if (record && !(record.publishedAt ?? record.published_at)) {
|
|
13650
|
-
showToast('info', '
|
|
13651
|
-
description: '
|
|
14102
|
+
showToast('info', $t('creator.version.thisIsADraftVersion'), {
|
|
14103
|
+
description: $t('creator.publish.pressPublishToMakeThe'),
|
|
13652
14104
|
});
|
|
13653
14105
|
return;
|
|
13654
14106
|
}
|
|
13655
14107
|
|
|
13656
14108
|
isSettingLiveVersion = version;
|
|
13657
14109
|
if (!widgetsClient) {
|
|
13658
|
-
showToast('error', '
|
|
14110
|
+
showToast('error', $t('creator.widget.widgetsApiClientIsNot'));
|
|
13659
14111
|
isSettingLiveVersion = null;
|
|
13660
14112
|
return;
|
|
13661
14113
|
}
|
|
@@ -13694,13 +14146,13 @@ async function setLiveVersionForWidget(widgetId: string, version: number) {
|
|
|
13694
14146
|
if (widgetId === selectedWidgetId || widgetId === focusedPanelWidgetId) {
|
|
13695
14147
|
revealCompositionPreview();
|
|
13696
14148
|
}
|
|
13697
|
-
showToast('success',
|
|
13698
|
-
description: '
|
|
14149
|
+
showToast('success', $t('creator.general.liveV', { version }), {
|
|
14150
|
+
description: $t('creator.version.thisVersionIsNowWhat'),
|
|
13699
14151
|
duration: 5000
|
|
13700
14152
|
});
|
|
13701
14153
|
} catch (err: any) {
|
|
13702
14154
|
console.error('[PublishHistory] set-live unexpected error:', err);
|
|
13703
|
-
showToast('error', '
|
|
14155
|
+
showToast('error', $t('creator.publish.failedToSetLiveVersion'));
|
|
13704
14156
|
} finally {
|
|
13705
14157
|
isSettingLiveVersion = null;
|
|
13706
14158
|
}
|
|
@@ -13714,7 +14166,7 @@ async function setLiveVersionForWidget(widgetId: string, version: number) {
|
|
|
13714
14166
|
async function renameVersionTitleForWidget(widgetId: string, version: number, title: string) {
|
|
13715
14167
|
if (!widgetId || !$userSession?.jwt) return;
|
|
13716
14168
|
if (!widgetsClient) {
|
|
13717
|
-
showToast('error', '
|
|
14169
|
+
showToast('error', $t('creator.widget.widgetsApiClientIsNot'));
|
|
13718
14170
|
return;
|
|
13719
14171
|
}
|
|
13720
14172
|
|
|
@@ -13747,7 +14199,7 @@ async function renameVersionTitleForWidget(widgetId: string, version: number, ti
|
|
|
13747
14199
|
record.commit_title = stored ?? null;
|
|
13748
14200
|
}
|
|
13749
14201
|
panelDisplayRevision += 1;
|
|
13750
|
-
showToast('success', stored ? '
|
|
14202
|
+
showToast('success', stored ? $t('creator.version.versionRenamed') : $t('creator.version.versionTitleCleared'));
|
|
13751
14203
|
} catch (err) {
|
|
13752
14204
|
// Roll the row back; nothing else needs reloading — the write did not land.
|
|
13753
14205
|
if (record) {
|
|
@@ -13755,8 +14207,8 @@ async function renameVersionTitleForWidget(widgetId: string, version: number, ti
|
|
|
13755
14207
|
record.commit_title = previousTitle;
|
|
13756
14208
|
}
|
|
13757
14209
|
panelDisplayRevision += 1;
|
|
13758
|
-
showToast('error', '
|
|
13759
|
-
description: err instanceof ResponseError ? '
|
|
14210
|
+
showToast('error', $t('creator.version.couldNotRenameTheVersion'), {
|
|
14211
|
+
description: err instanceof ResponseError ? $t('creator.general.theServerRefusedTheRename') : $t('creator.general.checkYourConnectionAndTry'),
|
|
13760
14212
|
});
|
|
13761
14213
|
} finally {
|
|
13762
14214
|
renamingTitleFor = null;
|
|
@@ -13782,7 +14234,9 @@ function togglePublishHistory(triggerEl?: HTMLElement | null) {
|
|
|
13782
14234
|
liveHistoryPanelTop = Math.round(rect.bottom + 4);
|
|
13783
14235
|
// Rows inset their action button 12px from the panel edge (panel p-1 4px + row px-2 8px).
|
|
13784
14236
|
// Shift right by 12px so the per-row action buttons line up under the header action button.
|
|
13785
|
-
|
|
14237
|
+
// On a right to left screen the cluster is at the other end of the header, so it is the left edge that lines up
|
|
14238
|
+
// and the list grows toward the middle of the panel.
|
|
14239
|
+
liveHistoryPanelPlacement = listAlignedToEnd($textDirection, rect, window.innerWidth, 12);
|
|
13786
14240
|
}
|
|
13787
14241
|
loadPublishHistory();
|
|
13788
14242
|
}
|
|
@@ -14001,7 +14455,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14001
14455
|
authStatus = `${defaultErrorMessage}: Unable to reach the server. Please verify the API gateway is running and try again.`;
|
|
14002
14456
|
showToast('error', defaultErrorMessage, {
|
|
14003
14457
|
description:
|
|
14004
|
-
'
|
|
14458
|
+
$t('creator.general.unableToReachTheApi'),
|
|
14005
14459
|
duration: 6000
|
|
14006
14460
|
});
|
|
14007
14461
|
return;
|
|
@@ -14023,6 +14477,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14023
14477
|
hasValidToken = false;
|
|
14024
14478
|
inlinePanelView = null;
|
|
14025
14479
|
selectedWidget = null;
|
|
14480
|
+
if (partnerMode) {
|
|
14481
|
+
// The page owns the sign-in: tell it, and stay where we are.
|
|
14482
|
+
endHostSession('The session has been signed out.', 'SIGNED_OUT');
|
|
14483
|
+
return;
|
|
14484
|
+
}
|
|
14026
14485
|
if (typeof window !== 'undefined') {
|
|
14027
14486
|
window.location.href = '/login';
|
|
14028
14487
|
}
|
|
@@ -14034,6 +14493,15 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14034
14493
|
function updateTokenStatus() {
|
|
14035
14494
|
// console.log('WidgetCreator.updateTokenStatus: currentUserToken:', currentUserToken);
|
|
14036
14495
|
|
|
14496
|
+
// Partner mode: the token is an opaque editor session token, not a JWT, so there is nothing to decode. The page
|
|
14497
|
+
// keeps it fresh (adoptHostToken); it is good until the page says the session is over.
|
|
14498
|
+
if (partnerMode) {
|
|
14499
|
+
hasValidToken = !!currentUserToken && !hostSessionEnded;
|
|
14500
|
+
tokenExpired = hostSessionEnded;
|
|
14501
|
+
tokenTimeLeft = hasValidToken ? Number.MAX_SAFE_INTEGER : 0;
|
|
14502
|
+
return;
|
|
14503
|
+
}
|
|
14504
|
+
|
|
14037
14505
|
// if the session has a jwt, decode the token and update the token status
|
|
14038
14506
|
if (currentUserToken) {
|
|
14039
14507
|
// decode the token
|
|
@@ -14096,6 +14564,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14096
14564
|
// and show a warning instead of abruptly cutting off the operation
|
|
14097
14565
|
function checkTokenExpiration() {
|
|
14098
14566
|
updateTokenStatus();
|
|
14567
|
+
// Partner mode: tokens are never "expired" by the clock here; the page renews them, and a session the page cannot
|
|
14568
|
+
// renew is reported by adoptHostToken.
|
|
14569
|
+
if (partnerMode) return hasValidToken;
|
|
14099
14570
|
if (currentUserToken) {
|
|
14100
14571
|
if (tokenExpired || tokenTimeLeft <= 0) {
|
|
14101
14572
|
const hasActiveOperations = isGeneratingCode || (showPreviewModal && previewLoading);
|
|
@@ -14325,9 +14796,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14325
14796
|
const widget = getWidgetById(widgetId);
|
|
14326
14797
|
if (!widget) {
|
|
14327
14798
|
console.warn('[WidgetCreator] Widget Image clicked but widget not found:', widgetId);
|
|
14328
|
-
showToast('warning', '
|
|
14799
|
+
showToast('warning', $t('creator.widget.unlinkedWidgetShape'), {
|
|
14329
14800
|
description:
|
|
14330
|
-
'
|
|
14801
|
+
$t('creator.canvas.thisShapePointsToA'),
|
|
14331
14802
|
duration: 8000,
|
|
14332
14803
|
});
|
|
14333
14804
|
return;
|
|
@@ -14386,20 +14857,20 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14386
14857
|
|
|
14387
14858
|
if (!widgetsClient || !hasValidToken) {
|
|
14388
14859
|
console.warn('[WidgetCreator] Cannot duplicate widget — not authenticated');
|
|
14389
|
-
showToast('error', '
|
|
14860
|
+
showToast('error', $t('creator.session.loginRequiredToDuplicateWidget'));
|
|
14390
14861
|
return;
|
|
14391
14862
|
}
|
|
14392
14863
|
|
|
14393
14864
|
if (isWidgetOperationInProgress) {
|
|
14394
14865
|
console.warn('[WidgetCreator] Another widget operation in progress, skipping duplicate');
|
|
14395
|
-
showToast('warning', '
|
|
14866
|
+
showToast('warning', $t('creator.general.pleaseWaitForTheCurrent'));
|
|
14396
14867
|
return;
|
|
14397
14868
|
}
|
|
14398
14869
|
|
|
14399
14870
|
try {
|
|
14400
14871
|
isWidgetOperationInProgress = true;
|
|
14401
14872
|
canvasRef?.markSelectedAsDuplicating();
|
|
14402
|
-
showToast('info', '
|
|
14873
|
+
showToast('info', $t('creator.widget.duplicatingWidget'), { duration: 2000 });
|
|
14403
14874
|
|
|
14404
14875
|
const response = await widgetsClient.duplicateWidget({
|
|
14405
14876
|
id: sourceWidgetId,
|
|
@@ -14409,7 +14880,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14409
14880
|
|
|
14410
14881
|
if (!newWidget?.id) {
|
|
14411
14882
|
console.error('[WidgetCreator] duplicateWidget returned no data', response);
|
|
14412
|
-
showToast('error', '
|
|
14883
|
+
showToast('error', $t('creator.widget.failedToDuplicateWidget'));
|
|
14413
14884
|
return;
|
|
14414
14885
|
}
|
|
14415
14886
|
|
|
@@ -14491,10 +14962,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14491
14962
|
await selectWidget(asWidgetSummary(newWidget), { skipPlaceShape: true });
|
|
14492
14963
|
notifyHostWidgetName(getWidgetById(canvasPrimaryWidgetId) ?? getWidgetById(sourceWidgetId));
|
|
14493
14964
|
|
|
14494
|
-
showToast('success', '
|
|
14965
|
+
showToast('success', $t('creator.widget.widgetDuplicated'), {
|
|
14495
14966
|
description: sourceHasCode
|
|
14496
|
-
?
|
|
14497
|
-
:
|
|
14967
|
+
? $t('creator.codegen.createdWithExistingCode', { name: newWidget.name })
|
|
14968
|
+
: $t('creator.general.created', { name: newWidget.name })
|
|
14498
14969
|
});
|
|
14499
14970
|
|
|
14500
14971
|
setTimeout(() => handleWidgetDataChanged(newWidget.id), 1500);
|
|
@@ -14541,8 +15012,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14541
15012
|
}, 6000);
|
|
14542
15013
|
} catch (err) {
|
|
14543
15014
|
console.error('[WidgetCreator] Failed to duplicate widget:', err);
|
|
14544
|
-
showToast('error', '
|
|
14545
|
-
description: err instanceof Error ? err.message : '
|
|
15015
|
+
showToast('error', $t('creator.widget.failedToDuplicateWidget'), {
|
|
15016
|
+
description: err instanceof Error ? err.message : $t('creator.general.unknownError')
|
|
14546
15017
|
});
|
|
14547
15018
|
} finally {
|
|
14548
15019
|
isWidgetOperationInProgress = false;
|
|
@@ -14571,7 +15042,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14571
15042
|
if (result.deleteFromDb) {
|
|
14572
15043
|
await deleteWidgetFromDb(widgetId);
|
|
14573
15044
|
} else {
|
|
14574
|
-
showToast('info', '
|
|
15045
|
+
showToast('info', $t('creator.canvas.shapeRemovedFromCanvas'), { description: $t('creator.widget.widgetKeptInDatabase2', { name: widgetName }) });
|
|
14575
15046
|
}
|
|
14576
15047
|
return true;
|
|
14577
15048
|
}
|
|
@@ -14601,11 +15072,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14601
15072
|
panelDisplayRevision += 1;
|
|
14602
15073
|
backfillWidgetShapeMetadata();
|
|
14603
15074
|
syncWidgetShapeLivePreviews();
|
|
14604
|
-
showToast('success',
|
|
15075
|
+
showToast('success', $t('creator.widget.widgetRenamedTo', { name: newName }));
|
|
14605
15076
|
} catch (error) {
|
|
14606
15077
|
console.error('[WidgetCreator] Failed to rename widget:', error);
|
|
14607
|
-
showToast('error', '
|
|
14608
|
-
description: error instanceof Error ? error.message : '
|
|
15078
|
+
showToast('error', $t('creator.widget.failedToRenameWidget'), {
|
|
15079
|
+
description: error instanceof Error ? error.message : $t('creator.general.unknownError')
|
|
14609
15080
|
});
|
|
14610
15081
|
}
|
|
14611
15082
|
}
|
|
@@ -14686,8 +15157,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14686
15157
|
canvasHydrateRetryCount = 0;
|
|
14687
15158
|
clearCanvasHydrateRetry();
|
|
14688
15159
|
clearCanvasLoadFailsafe();
|
|
15160
|
+
announceReadyOnce();
|
|
14689
15161
|
}
|
|
14690
15162
|
function armCanvasLoadFailsafe(reason: string, forCanvasId: string) {
|
|
15163
|
+
// The failsafe ends in "the canvas is loaded": not for a canvas the visitor cannot open.
|
|
15164
|
+
if (canvasUnavailable) return;
|
|
14691
15165
|
const failsafeKey = forCanvasId || '__pending__';
|
|
14692
15166
|
if (canvasLoadFailsafeArmedForId === failsafeKey && canvasLoadFailsafeTimer) return;
|
|
14693
15167
|
if (canvasLoadFailsafeTimer) clearTimeout(canvasLoadFailsafeTimer);
|
|
@@ -14702,8 +15176,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14702
15176
|
return;
|
|
14703
15177
|
}
|
|
14704
15178
|
markCanvasStateLoaded();
|
|
14705
|
-
showToast('warning', '
|
|
14706
|
-
description: '
|
|
15179
|
+
showToast('warning', $t('creator.canvas.canvasIsTakingLongerThan'), {
|
|
15180
|
+
description: $t('creator.widget.youCanKeepEditingWidgets'),
|
|
14707
15181
|
duration: 8000,
|
|
14708
15182
|
});
|
|
14709
15183
|
}, timeoutMs);
|
|
@@ -14711,6 +15185,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14711
15185
|
async function tryLoadCanvasState(): Promise<{ loaded: boolean; widgetIds: string[] }> {
|
|
14712
15186
|
const emptyResult = { loaded: false, widgetIds: [] as string[] };
|
|
14713
15187
|
const loadEpoch = canvasLoadEpoch;
|
|
15188
|
+
// Partner mode: the page's canvas is not the visitor's; asking for it again would not change the answer.
|
|
15189
|
+
if (canvasUnavailable) return emptyResult;
|
|
14714
15190
|
if (ignoreIncomingCanvasLoads) {
|
|
14715
15191
|
// console.log('[CanvasDebug] tryLoadCanvasState skipped — new widget blank canvas');
|
|
14716
15192
|
canvasRef?.onClearAllObjects();
|
|
@@ -14753,7 +15229,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14753
15229
|
let localCachedJson: string | null = null;
|
|
14754
15230
|
try {
|
|
14755
15231
|
localCachedJson = (await readCanvasState(canvasId)) ?? (() => {
|
|
14756
|
-
try { return
|
|
15232
|
+
try { return creatorStorage.getItem(getCanvasStorageKey()); } catch { return null; }
|
|
14757
15233
|
})();
|
|
14758
15234
|
if (localCachedJson && canvasRef) {
|
|
14759
15235
|
const parsed = JSON.parse(localCachedJson);
|
|
@@ -14772,10 +15248,17 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14772
15248
|
}
|
|
14773
15249
|
|
|
14774
15250
|
// ── Revalidate against remote API (single request, no artificial sleep loops) ──
|
|
15251
|
+
canvasRemoteReadsInFlight += 1;
|
|
14775
15252
|
try {
|
|
14776
15253
|
if (canvasesClient) {
|
|
14777
15254
|
let canvasContent: any = null;
|
|
14778
|
-
|
|
15255
|
+
// A canvas that comes back without content is read once more in case it was only just saved. On the site a
|
|
15256
|
+
// few more times; a partner's visitor starts from an empty canvas more often than not, and should not wait
|
|
15257
|
+
// seconds (and ask a dozen times) to be told that is what it is.
|
|
15258
|
+
const maxCanvasReadAttempts = partnerMode ? 2 : 5;
|
|
15259
|
+
for (let attempt = 0; attempt < maxCanvasReadAttempts; attempt++) {
|
|
15260
|
+
// Another read has already found out there is no such canvas for this visitor.
|
|
15261
|
+
if (canvasUnavailable) return emptyResult;
|
|
14779
15262
|
try {
|
|
14780
15263
|
const canvasResponse = await withCanvasApiTimeout(
|
|
14781
15264
|
canvasesClient.getCanvasRaw({ id: canvasId }),
|
|
@@ -14792,9 +15275,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14792
15275
|
console.log('[CanvasDebug] getCanvas returned no canvasContent, retry', attempt + 1);
|
|
14793
15276
|
} catch (getErr) {
|
|
14794
15277
|
console.warn('[CanvasDebug] getCanvas failed, retry', attempt + 1, getErr);
|
|
14795
|
-
|
|
15278
|
+
// "No such canvas" is an answer, not a hiccup: asking again would only get it again.
|
|
15279
|
+
if (saysCanvasIsMissing(getErr) || attempt >= maxCanvasReadAttempts - 1) throw getErr;
|
|
14796
15280
|
}
|
|
14797
|
-
if (attempt <
|
|
15281
|
+
if (attempt < maxCanvasReadAttempts - 1) {
|
|
14798
15282
|
await new Promise((resolve) => setTimeout(resolve, 400 * (attempt + 1)));
|
|
14799
15283
|
}
|
|
14800
15284
|
}
|
|
@@ -14833,7 +15317,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14833
15317
|
canvasShapesLoaded = true;
|
|
14834
15318
|
} catch (loadErr) {
|
|
14835
15319
|
console.warn('[WidgetCreator] canvasRef.loadCanvas failed/timed out — clearing loading overlay:', loadErr);
|
|
14836
|
-
canvasApiLoadError = toErrorMessage(loadErr, '
|
|
15320
|
+
canvasApiLoadError = toErrorMessage(loadErr, $t('creator.canvas.canvasShapesFailedToRender'));
|
|
14837
15321
|
}
|
|
14838
15322
|
if (canvasShapesLoaded) canvasApiLoadError = null;
|
|
14839
15323
|
}
|
|
@@ -14844,7 +15328,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14844
15328
|
setTimeout(() => { isLoadCooldownActive = false; }, 3000);
|
|
14845
15329
|
lastSavedCanvasObjectCount = objectCount;
|
|
14846
15330
|
setTimeout(refreshLinkedWidgetIds, 500);
|
|
14847
|
-
try {
|
|
15331
|
+
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, String(objectCount)); } catch {}
|
|
14848
15332
|
// console.log('[WidgetCreator] Canvas state validated from API (autosave cooldown 3s)');
|
|
14849
15333
|
return { loaded: true, widgetIds: widgetIdsOnCanvas };
|
|
14850
15334
|
} else {
|
|
@@ -14855,19 +15339,28 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14855
15339
|
}
|
|
14856
15340
|
} catch (err) {
|
|
14857
15341
|
console.warn('[WidgetCreator] Failed to load canvas from API:', err);
|
|
14858
|
-
const errMsg = toErrorMessage(err, '
|
|
15342
|
+
const errMsg = toErrorMessage(err, $t('creator.canvas.failedToLoadCanvasFrom'));
|
|
14859
15343
|
canvasApiLoadError = errMsg;
|
|
15344
|
+
// Partner mode: the API says the canvas does not exist for this visitor. It is not an empty canvas to start on
|
|
15345
|
+
// (the fallbacks below would call it one and say the creator is ready): the page is told, and that is the end.
|
|
15346
|
+
if (saysCanvasIsMissing(err)) {
|
|
15347
|
+
declareCanvasUnavailable(canvasId || null, errMsg);
|
|
15348
|
+
return emptyResult;
|
|
15349
|
+
}
|
|
14860
15350
|
if (/timed out|failed to fetch|network|econnrefused|503|502|load canvases/i.test(errMsg)) {
|
|
14861
15351
|
console.log('[CanvasDebug] Skip localStorage canvas fallback after API/network error');
|
|
14862
15352
|
return emptyResult;
|
|
14863
15353
|
}
|
|
14864
|
-
|
|
14865
|
-
|
|
15354
|
+
// (The hint about the Widgetic site's own database billing is for its team, not for a partner's visitor.)
|
|
15355
|
+
if (!partnerMode && /quota|limit|billing|exceeded|402|403|503/i.test(errMsg)) {
|
|
15356
|
+
showToast('error', $t('creator.canvas.canvasLoadFailedCheckSupabase'), {
|
|
14866
15357
|
description:
|
|
14867
|
-
'
|
|
15358
|
+
$t('creator.canvas.apiMayBeThrottledOr'),
|
|
14868
15359
|
duration: 10000,
|
|
14869
15360
|
});
|
|
14870
15361
|
}
|
|
15362
|
+
} finally {
|
|
15363
|
+
canvasRemoteReadsInFlight -= 1;
|
|
14871
15364
|
}
|
|
14872
15365
|
|
|
14873
15366
|
// Fallback: if SWR hasn't painted yet and API failed, try loading from localStorage
|
|
@@ -14877,7 +15370,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14877
15370
|
}
|
|
14878
15371
|
try {
|
|
14879
15372
|
const saved = (await readCanvasState(canvasId)) ?? (() => {
|
|
14880
|
-
try { return
|
|
15373
|
+
try { return creatorStorage.getItem(getCanvasStorageKey()); } catch { return null; }
|
|
14881
15374
|
})();
|
|
14882
15375
|
if (saved && canvasRef) {
|
|
14883
15376
|
let parsed: any = null;
|
|
@@ -14903,7 +15396,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14903
15396
|
setTimeout(() => { isLoadCooldownActive = false; }, 3000);
|
|
14904
15397
|
lastSavedCanvasObjectCount = objectCount;
|
|
14905
15398
|
setTimeout(refreshLinkedWidgetIds, 500);
|
|
14906
|
-
try {
|
|
15399
|
+
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, String(objectCount)); } catch {}
|
|
14907
15400
|
// console.log('[WidgetCreator] Canvas state loaded from localStorage (autosave cooldown 3s)');
|
|
14908
15401
|
return { loaded: true, widgetIds: widgetIdsOnCanvas };
|
|
14909
15402
|
} else {
|
|
@@ -14920,7 +15413,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
14920
15413
|
// Both API and localStorage returned empty — this is genuinely a new/empty canvas
|
|
14921
15414
|
markCanvasStateLoaded();
|
|
14922
15415
|
lastSavedCanvasObjectCount = 0;
|
|
14923
|
-
try {
|
|
15416
|
+
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, '0'); } catch {}
|
|
14924
15417
|
// console.log(
|
|
14925
15418
|
// `[CanvasDebug] Loading canvas ${canvasId}: NO shapes found anywhere - starting fresh`
|
|
14926
15419
|
// );
|
|
@@ -15013,8 +15506,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15013
15506
|
`[CanvasDebug] BLOCKING save: would overwrite ${lastSavedCanvasObjectCount} shapes with 0 (isUnmount=${isUnmountSave}, force=${force})`
|
|
15014
15507
|
);
|
|
15015
15508
|
if (force) {
|
|
15016
|
-
showToast('error', '
|
|
15017
|
-
description: '
|
|
15509
|
+
showToast('error', $t('creator.general.saveBlocked'), {
|
|
15510
|
+
description: $t('creator.canvas.canvasSnapshotLookedEmptyRefresh'),
|
|
15018
15511
|
});
|
|
15019
15512
|
}
|
|
15020
15513
|
return;
|
|
@@ -15024,7 +15517,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15024
15517
|
}
|
|
15025
15518
|
|
|
15026
15519
|
lastSavedCanvasObjectCount = objectCount;
|
|
15027
|
-
try {
|
|
15520
|
+
try { creatorSessionStorage.setItem(CANVAS_OBJ_COUNT_KEY, String(objectCount)); } catch {}
|
|
15028
15521
|
emitCreatorSaveState(false);
|
|
15029
15522
|
|
|
15030
15523
|
// Save to durable L1 fallback (always, even with 0 objects for legitimate clears)
|
|
@@ -15036,7 +15529,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15036
15529
|
if (!isAnyWidgetGenerating() || force || isUnmountSave) {
|
|
15037
15530
|
measureSync('canvas-autosave:localStorage-mirror', () => {
|
|
15038
15531
|
try {
|
|
15039
|
-
|
|
15532
|
+
creatorStorage.setItem(getCanvasStorageKey(), json);
|
|
15040
15533
|
} catch (err) {
|
|
15041
15534
|
console.warn('[WidgetCreator] Failed to save canvas to localStorage:', err);
|
|
15042
15535
|
}
|
|
@@ -15068,7 +15561,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15068
15561
|
}
|
|
15069
15562
|
lastResolvedAutosaveSequence = currentSeq;
|
|
15070
15563
|
if (force) {
|
|
15071
|
-
showToast('success', '
|
|
15564
|
+
showToast('success', $t('creator.canvas.canvasSaved'), { duration: 2000 });
|
|
15072
15565
|
}
|
|
15073
15566
|
// console.log(
|
|
15074
15567
|
// `[CanvasDebug] Canvas ${canvasId} saved to API: ${objectCount} shapes (seq ${currentSeq})`
|
|
@@ -15076,14 +15569,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15076
15569
|
} catch (err) {
|
|
15077
15570
|
console.warn('[WidgetCreator] Failed to save canvas to API:', err);
|
|
15078
15571
|
if (force) {
|
|
15079
|
-
showToast('error', '
|
|
15080
|
-
description: '
|
|
15572
|
+
showToast('error', $t('creator.canvas.canvasSaveFailed'), {
|
|
15573
|
+
description: $t('creator.general.keptALocalCopyCheck'),
|
|
15081
15574
|
});
|
|
15082
15575
|
}
|
|
15083
15576
|
}
|
|
15084
15577
|
} else if (force) {
|
|
15085
|
-
showToast('success', '
|
|
15086
|
-
description: canvasId ? '
|
|
15578
|
+
showToast('success', $t('creator.canvas.canvasSavedLocally'), {
|
|
15579
|
+
description: canvasId ? $t('creator.general.apiClientUnavailable') : $t('creator.canvas.noCanvasIdYet'),
|
|
15087
15580
|
duration: 2500,
|
|
15088
15581
|
});
|
|
15089
15582
|
}
|
|
@@ -15104,12 +15597,12 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15104
15597
|
// console.log('[WidgetCreator] Convert to widget (draft, v2):', payload);
|
|
15105
15598
|
|
|
15106
15599
|
if (!$userSession.user || !hasValidToken) {
|
|
15107
|
-
showToast('error', '
|
|
15600
|
+
showToast('error', $t('creator.session.pleaseLoginFirst'));
|
|
15108
15601
|
return;
|
|
15109
15602
|
}
|
|
15110
15603
|
if (isWidgetOperationInProgress) {
|
|
15111
15604
|
console.warn('[WidgetCreator] Another widget operation in progress, skipping convert');
|
|
15112
|
-
showToast('warning', '
|
|
15605
|
+
showToast('warning', $t('creator.general.pleaseWaitForTheCurrent'));
|
|
15113
15606
|
return;
|
|
15114
15607
|
}
|
|
15115
15608
|
|
|
@@ -15121,8 +15614,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15121
15614
|
payload.screenshot?.length ?? 0,
|
|
15122
15615
|
') — keeping original shapes so the sketch is not lost'
|
|
15123
15616
|
);
|
|
15124
|
-
showToast('warning', '
|
|
15125
|
-
description: '
|
|
15617
|
+
showToast('warning', $t('creator.general.screenshotCouldNotBeCaptured'), {
|
|
15618
|
+
description: $t('creator.general.fixTheSelectionZoomOut'),
|
|
15126
15619
|
duration: 10000
|
|
15127
15620
|
});
|
|
15128
15621
|
return;
|
|
@@ -15210,15 +15703,15 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15210
15703
|
}
|
|
15211
15704
|
|
|
15212
15705
|
authStatus = 'Widget draft ready — send the prompt to generate.';
|
|
15213
|
-
showToast('info', '
|
|
15214
|
-
description: '
|
|
15706
|
+
showToast('info', $t('creator.widget.widgetDraftCreated'), {
|
|
15707
|
+
description: $t('creator.codegen.editTheSketchFreelySending')
|
|
15215
15708
|
});
|
|
15216
15709
|
} catch (error) {
|
|
15217
15710
|
console.error('[WidgetCreator] Convert to widget (draft) error:', error);
|
|
15218
15711
|
draftConvertObjectIds.delete(draftId);
|
|
15219
15712
|
draftConvertScreenshots.delete(draftId);
|
|
15220
15713
|
authStatus = toErrorMessage(error, 'Failed to prepare widget draft.');
|
|
15221
|
-
showToast('error', '
|
|
15714
|
+
showToast('error', $t('creator.widget.failedToPrepareWidgetDraft'));
|
|
15222
15715
|
} finally {
|
|
15223
15716
|
isWidgetOperationInProgress = false;
|
|
15224
15717
|
setTimeout(() => {
|
|
@@ -15260,7 +15753,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15260
15753
|
// Canvas sketch snapshot is stored on the widget for future reference
|
|
15261
15754
|
content: { source: 'canvas_convert', prompt },
|
|
15262
15755
|
isDraft: true,
|
|
15263
|
-
description
|
|
15756
|
+
// (No `description`: a new widget has no such field, the API ignored it, and a partner's session is
|
|
15757
|
+
// refused for sending a field it may not write.)
|
|
15264
15758
|
...(canvasId ? { canvasId } : {}),
|
|
15265
15759
|
...embeddedWidgetProjectContext()
|
|
15266
15760
|
}
|
|
@@ -15271,13 +15765,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15271
15765
|
const createEnvelope = response as unknown as { error?: string; message?: string };
|
|
15272
15766
|
if (!response || createEnvelope.error || createEnvelope.message) {
|
|
15273
15767
|
console.error('[WidgetCreator] Widget create on first send failed:', response);
|
|
15274
|
-
showToast('error', '
|
|
15768
|
+
showToast('error', $t('creator.widget.failedToCreateWidgetFrom'));
|
|
15275
15769
|
return null;
|
|
15276
15770
|
}
|
|
15277
15771
|
|
|
15278
15772
|
const newWidget = asWidgetSummary((response as { data?: unknown }).data ?? response);
|
|
15279
15773
|
if (!newWidget?.id) {
|
|
15280
|
-
showToast('warning', '
|
|
15774
|
+
showToast('warning', $t('creator.widget.widgetCreatedButNoId'));
|
|
15281
15775
|
return null;
|
|
15282
15776
|
}
|
|
15283
15777
|
const widgetId: string = newWidget.id;
|
|
@@ -15412,13 +15906,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15412
15906
|
pendingChatDraftText = '';
|
|
15413
15907
|
|
|
15414
15908
|
authStatus = 'Widget created from design.';
|
|
15415
|
-
showToast('success', '
|
|
15416
|
-
description:
|
|
15909
|
+
showToast('success', $t('creator.widget.widgetCreated'), {
|
|
15910
|
+
description: $t('creator.codegen.isReadyGenerationStarted', { name: draftName })
|
|
15417
15911
|
});
|
|
15418
15912
|
return widgetId;
|
|
15419
15913
|
} catch (error) {
|
|
15420
15914
|
console.error('[WidgetCreator] finalizeDraftConversion error:', error);
|
|
15421
|
-
showToast('error', '
|
|
15915
|
+
showToast('error', $t('creator.widget.failedToFinalizeWidgetConversion'));
|
|
15422
15916
|
return null;
|
|
15423
15917
|
} finally {
|
|
15424
15918
|
suppressWidgetDetailsClose = false;
|
|
@@ -15512,8 +16006,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15512
16006
|
async function recreateRepositoryForWidget(widget: WidgetSummary) {
|
|
15513
16007
|
if (!$userSession.user || !hasValidToken) {
|
|
15514
16008
|
console.warn('Cannot create repository: not authenticated');
|
|
15515
|
-
showToast('error', '
|
|
15516
|
-
description: '
|
|
16009
|
+
showToast('error', $t('creator.session.authenticationRequired'), {
|
|
16010
|
+
description: $t('creator.session.pleaseLoginBeforeCreatingA'),
|
|
15517
16011
|
duration: 5000
|
|
15518
16012
|
});
|
|
15519
16013
|
return;
|
|
@@ -15526,8 +16020,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15526
16020
|
currentRepositoryId = repoId;
|
|
15527
16021
|
widgetDetails?.setCurrentRepositoryId(repoId);
|
|
15528
16022
|
}
|
|
15529
|
-
showToast('success', '
|
|
15530
|
-
description:
|
|
16023
|
+
showToast('success', $t('creator.codegen.repositoryCreated'), {
|
|
16024
|
+
description: $t('creator.codegen.repositoryIsNowLinkedTo', { id: repoId.slice(0, 8) })
|
|
15531
16025
|
});
|
|
15532
16026
|
}
|
|
15533
16027
|
}
|
|
@@ -15536,8 +16030,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15536
16030
|
const repoId = normalizeRepositoryId(widget);
|
|
15537
16031
|
if (repoId) {
|
|
15538
16032
|
// Repository exists - show info
|
|
15539
|
-
showToast('info', '
|
|
15540
|
-
description:
|
|
16033
|
+
showToast('info', $t('creator.codegen.repositoryExists'), {
|
|
16034
|
+
description: $t('creator.widget.repoIdToDeleteUse', { id: repoId.slice(0, 8) })
|
|
15541
16035
|
});
|
|
15542
16036
|
} else {
|
|
15543
16037
|
// Create repository
|
|
@@ -15575,8 +16069,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15575
16069
|
return false;
|
|
15576
16070
|
}
|
|
15577
16071
|
|
|
15578
|
-
// check if the repository belongs to the current user
|
|
15579
|
-
|
|
16072
|
+
// check if the repository belongs to the current user. In a partner's page the repository belongs to the
|
|
16073
|
+
// partner's account, never to the visitor, and the gateway has already checked that this visitor may open it
|
|
16074
|
+
// (it answers 404 otherwise), so there is no owner to compare here.
|
|
16075
|
+
const repoOwnerMatches = partnerMode || repoDetails.userId === $userSession.user?.id;
|
|
15580
16076
|
// if the repository does not belong to the current user, show a warning and return false
|
|
15581
16077
|
if (!repoOwnerMatches) {
|
|
15582
16078
|
console.warn('Repository belongs to a different user. Re-creating.', {
|
|
@@ -15585,9 +16081,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15585
16081
|
currentUser: $userSession.user?.id
|
|
15586
16082
|
});
|
|
15587
16083
|
if (!silent) {
|
|
15588
|
-
showToast('warning', '
|
|
16084
|
+
showToast('warning', $t('creator.codegen.repositoryOwnedByAnotherAccount'), {
|
|
15589
16085
|
description:
|
|
15590
|
-
'
|
|
16086
|
+
$t('creator.session.thisWidgetReferencesARepository'),
|
|
15591
16087
|
duration: 6000
|
|
15592
16088
|
});
|
|
15593
16089
|
}
|
|
@@ -15595,8 +16091,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15595
16091
|
}
|
|
15596
16092
|
|
|
15597
16093
|
if (!silent) {
|
|
15598
|
-
showToast('info', '
|
|
15599
|
-
description:
|
|
16094
|
+
showToast('info', $t('creator.codegen.repositoryFound'), {
|
|
16095
|
+
description: $t('creator.codegen.linkedToRepository', { id: repoDetails.id.slice(0, 8) })
|
|
15600
16096
|
});
|
|
15601
16097
|
}
|
|
15602
16098
|
return true;
|
|
@@ -15613,14 +16109,17 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15613
16109
|
if (retryDetails?.id) return true;
|
|
15614
16110
|
} catch (retryError) {
|
|
15615
16111
|
if (retryError instanceof ResponseError && retryError.response?.status === 401) {
|
|
15616
|
-
if (
|
|
15617
|
-
|
|
15618
|
-
|
|
15619
|
-
|
|
15620
|
-
|
|
15621
|
-
|
|
15622
|
-
|
|
15623
|
-
|
|
16112
|
+
if (partnerMode) {
|
|
16113
|
+
// The page's token was refused twice (the renewal already ran): the session is over.
|
|
16114
|
+
endHostSession('The API refused the session token.', 'SESSION_REFUSED');
|
|
16115
|
+
} else {
|
|
16116
|
+
if (!silent) {
|
|
16117
|
+
showToast('warning', $t('creator.session.sessionExpired'), {
|
|
16118
|
+
description: $t('creator.session.signInAgainThenRetry'),
|
|
16119
|
+
duration: 6000
|
|
16120
|
+
});
|
|
16121
|
+
}
|
|
16122
|
+
announceToSite('widgetic:session-needs-reauth');
|
|
15624
16123
|
}
|
|
15625
16124
|
throw retryError;
|
|
15626
16125
|
}
|
|
@@ -15633,9 +16132,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15633
16132
|
status
|
|
15634
16133
|
});
|
|
15635
16134
|
if (!silent) {
|
|
15636
|
-
showToast('warning', '
|
|
16135
|
+
showToast('warning', $t('creator.codegen.repositoryReferenceInvalid'), {
|
|
15637
16136
|
description:
|
|
15638
|
-
'
|
|
16137
|
+
$t('creator.codegen.supabaseDoesNotHaveThis'),
|
|
15639
16138
|
duration: 6000
|
|
15640
16139
|
});
|
|
15641
16140
|
}
|
|
@@ -15645,8 +16144,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15645
16144
|
|
|
15646
16145
|
console.error('Failed to verify repository', error);
|
|
15647
16146
|
if (!silent) {
|
|
15648
|
-
const message = await deriveApiErrorMessage(error, '
|
|
15649
|
-
showToast('error', '
|
|
16147
|
+
const message = await deriveApiErrorMessage(error, $t('creator.codegen.unableToVerifyRepositoryStatus'));
|
|
16148
|
+
showToast('error', $t('creator.codegen.repositoryVerificationFailed'), {
|
|
15650
16149
|
description: message,
|
|
15651
16150
|
duration: 5000
|
|
15652
16151
|
});
|
|
@@ -15675,8 +16174,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15675
16174
|
const repoId = (repoData?.id || repoData?.repoId || repoData?.repo_id || null) as string | null;
|
|
15676
16175
|
|
|
15677
16176
|
if (!repoId) {
|
|
15678
|
-
showToast('error', '
|
|
15679
|
-
description: '
|
|
16177
|
+
showToast('error', $t('creator.codegen.repositoryCreationFailed'), {
|
|
16178
|
+
description: $t('creator.codegen.couldNotDetermineRepositoryId'),
|
|
15680
16179
|
duration: 5000
|
|
15681
16180
|
});
|
|
15682
16181
|
return null;
|
|
@@ -15695,24 +16194,24 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15695
16194
|
})
|
|
15696
16195
|
.catch((err) => {
|
|
15697
16196
|
console.error('Widget Creator: Failed to persist repository ID for widget', err);
|
|
15698
|
-
showToast('warning', '
|
|
16197
|
+
showToast('warning', $t('creator.codegen.repositoryCreatedButNotPersisted'), {
|
|
15699
16198
|
description:
|
|
15700
|
-
'
|
|
16199
|
+
$t('creator.codegen.repositoryExistsButFailedTo'),
|
|
15701
16200
|
duration: 6000
|
|
15702
16201
|
});
|
|
15703
16202
|
});
|
|
15704
16203
|
|
|
15705
16204
|
if (!silent) {
|
|
15706
|
-
showToast('success', '
|
|
15707
|
-
description:
|
|
16205
|
+
showToast('success', $t('creator.codegen.repositoryCreated'), {
|
|
16206
|
+
description: $t('creator.codegen.repositoryReadyForUse', { id: repoId.slice(0, 8) })
|
|
15708
16207
|
});
|
|
15709
16208
|
}
|
|
15710
16209
|
|
|
15711
16210
|
return repoId;
|
|
15712
16211
|
} catch (error) {
|
|
15713
16212
|
console.error('Failed to create repository for widget:', error);
|
|
15714
|
-
showToast('error', '
|
|
15715
|
-
description: error?.message || '
|
|
16213
|
+
showToast('error', $t('creator.codegen.repositoryCreationFailed'), {
|
|
16214
|
+
description: error?.message || $t('creator.general.checkConsoleForDetails'),
|
|
15716
16215
|
duration: 5000
|
|
15717
16216
|
});
|
|
15718
16217
|
return null;
|
|
@@ -15805,6 +16304,21 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15805
16304
|
}
|
|
15806
16305
|
}
|
|
15807
16306
|
|
|
16307
|
+
/**
|
|
16308
|
+
* In a partner's page: a press inside the creator puts the keyboard focus in the creator, so that the keys the visitor
|
|
16309
|
+
* presses next (Delete, Ctrl+Z, the arrows ...) are the creator's and not the page's. The creator is in a shadow root
|
|
16310
|
+
* there, and a press on something that cannot take the focus itself (a panel's background, the canvas) would leave the
|
|
16311
|
+
* focus on the page's <body>, outside the shadow root, where the creator does not hear the keys. A control that can
|
|
16312
|
+
* take the focus still gets it: the browser gives it the focus after this, as the press's own default.
|
|
16313
|
+
*/
|
|
16314
|
+
function keepFocusInCreator(): void {
|
|
16315
|
+
const creatorRoot = creatorRootEl;
|
|
16316
|
+
if (!creatorRoot) return;
|
|
16317
|
+
const focusRoot = creatorRoot.getRootNode() as Document | ShadowRoot;
|
|
16318
|
+
if (focusRoot.activeElement && creatorRoot.contains(focusRoot.activeElement)) return;
|
|
16319
|
+
creatorRoot.focus({ preventScroll: true });
|
|
16320
|
+
}
|
|
16321
|
+
|
|
15808
16322
|
// Svelte action: auto-focus element when mounted (for ESC key to work in modal)
|
|
15809
16323
|
function focusOnMount(node) {
|
|
15810
16324
|
// Use requestAnimationFrame to ensure DOM is fully rendered
|
|
@@ -15817,6 +16331,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15817
16331
|
<svelte:window
|
|
15818
16332
|
onkeydown={(e) => {
|
|
15819
16333
|
if (e.key === 'Escape') {
|
|
16334
|
+
// In a partner's page an Escape that started outside the creator is the partner's (their own dialog).
|
|
16335
|
+
if (!eventIsFromCreator(e, creatorRootEl)) return;
|
|
15820
16336
|
if (showPreviewModal) { showPreviewModal = false; return; }
|
|
15821
16337
|
}
|
|
15822
16338
|
}}
|
|
@@ -15827,7 +16343,16 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15827
16343
|
}}
|
|
15828
16344
|
/>
|
|
15829
16345
|
|
|
15830
|
-
|
|
16346
|
+
<!-- Partner mode: the creator is a place the keyboard can be "in" (shortcuts are for the canvas only while the focus is inside it, see `keepFocusInCreator`); the root takes the focus programmatically (tabindex -1), it is not a tab stop. -->
|
|
16347
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
16348
|
+
<div
|
|
16349
|
+
bind:this={creatorRootEl}
|
|
16350
|
+
class="widget-creator-root-page-ct relative flex flex-col w-full h-full {partnerMode ? 'outline-none' : ''} {className}"
|
|
16351
|
+
dir={$textDirection}
|
|
16352
|
+
style={style}
|
|
16353
|
+
tabindex={partnerMode ? -1 : undefined}
|
|
16354
|
+
onpointerdowncapture={partnerMode ? keepFocusInCreator : undefined}
|
|
16355
|
+
>
|
|
15831
16356
|
|
|
15832
16357
|
<!-- AUTH SCREEN - Show when user is NOT logged in (standalone only) -->
|
|
15833
16358
|
{#if !embedded && !$userSession.user}
|
|
@@ -15911,7 +16436,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
15911
16436
|
</div>
|
|
15912
16437
|
{#if debugModeAvailable}
|
|
15913
16438
|
<span
|
|
15914
|
-
class="wc-build-info text-[10px] font-mono text-gray-400 leading-none
|
|
16439
|
+
class="wc-build-info text-[10px] font-mono text-gray-400 leading-none ps-0.5"
|
|
15915
16440
|
title="Deployed build — remove when beta ends"
|
|
15916
16441
|
>{buildLabel}</span>
|
|
15917
16442
|
{/if}
|
|
@@ -16001,18 +16526,22 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16001
16526
|
<div class="canvas-state-warning-banner rounded-lg border px-4 py-3 shadow-md text-sm
|
|
16002
16527
|
{canvasApiLoadError ? 'border-red-200 bg-red-50 text-red-900' : 'border-amber-200 bg-amber-50 text-amber-900'}">
|
|
16003
16528
|
{#if canvasApiLoadError}
|
|
16004
|
-
<p class="font-semibold">
|
|
16529
|
+
<p class="font-semibold">{canvasUnavailable ? $t('creator.canvas.canvasUnavailable') : $t('creator.canvas.canvasShapesFailedToLoad')}</p>
|
|
16005
16530
|
<p class="text-xs mt-1">{canvasApiLoadError}</p>
|
|
16531
|
+
{#if !partnerMode}
|
|
16006
16532
|
<p class="text-xs mt-1 opacity-90">If Supabase shows a billing/quota warning, upgrade or review billing — API reads may fail while the widget list still loads.</p>
|
|
16533
|
+
{/if}
|
|
16007
16534
|
{:else}
|
|
16008
|
-
<p class="font-semibold">
|
|
16009
|
-
<p class="text-xs mt-1">
|
|
16535
|
+
<p class="font-semibold">{$t('creator.canvas.appearsEmptyButWidgets', { count: widgets.length })}</p>
|
|
16536
|
+
<p class="text-xs mt-1">{$t('creator.canvas.shapeDataMayBeMissing')}</p>
|
|
16010
16537
|
{/if}
|
|
16011
16538
|
<div class="canvas-state-warning-actions flex gap-2 mt-3">
|
|
16012
|
-
|
|
16539
|
+
{#if !canvasUnavailable}
|
|
16540
|
+
<Button variant="outline" size="sm" onclick={retryLoadCanvas}>{$t('creator.general.retryLoad')}</Button>
|
|
16541
|
+
{/if}
|
|
16013
16542
|
{#if canvasShapesMissingWarning}
|
|
16014
|
-
<Button variant="default" size="sm" onclick={() => void handleRestoreShapesClick()}>
|
|
16015
|
-
<Button variant="outline" size="sm" onclick={() => { canvasShapesMissingWarning = false; }}>
|
|
16543
|
+
<Button variant="default" size="sm" onclick={() => void handleRestoreShapesClick()}>{$t('creator.widget.restoreShapes')}</Button>
|
|
16544
|
+
<Button variant="outline" size="sm" onclick={() => { canvasShapesMissingWarning = false; }}>{$t('creator.general.dismiss')}</Button>
|
|
16016
16545
|
{/if}
|
|
16017
16546
|
</div>
|
|
16018
16547
|
</div>
|
|
@@ -16021,6 +16550,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16021
16550
|
{#if WidgeticCanvas}
|
|
16022
16551
|
<svelte:component this={WidgeticCanvas}
|
|
16023
16552
|
bind:this={canvasRef}
|
|
16553
|
+
locale={locale}
|
|
16554
|
+
messages={canvasMessages}
|
|
16024
16555
|
showContainerFrame={!embedded}
|
|
16025
16556
|
widgetSelectionLayerTarget="floating-panels-overlay"
|
|
16026
16557
|
bind:wireframeMode={canvasWireframeMode}
|
|
@@ -16124,7 +16655,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16124
16655
|
<div
|
|
16125
16656
|
bind:this={widgetsPanelEl}
|
|
16126
16657
|
class="widgets-floating-panel pointer-events-auto fixed bg-white/95 backdrop-blur-sm rounded-lg shadow-lg border border-gray-300 pt-0 pb-2.5 px-2.5 flex flex-col gap-3 overflow-hidden"
|
|
16127
|
-
style="min-width: {WIDGETS_PANEL_MIN_WIDTH}px; width: {widgetsPanelWidth}px; left: {widgetsPanelX}px; top: {widgetsPanelTopPx}px; z-index: {widgetsPanelZIndex}; {isWidgetsPanelMinimized ? 'height: auto; max-height: none;' : `height: ${widgetsPanelHeight}px;`}"
|
|
16658
|
+
style="min-width: {WIDGETS_PANEL_MIN_WIDTH}px; width: {widgetsPanelWidth}px; left: {widgetsPanelX}px; /* rtl-ok: the panel is put in pixels from the left edge of the screen and dragged there */ top: {widgetsPanelTopPx}px; z-index: {widgetsPanelZIndex}; {isWidgetsPanelMinimized ? 'height: auto; max-height: none;' : `height: ${widgetsPanelHeight}px;`}"
|
|
16128
16659
|
onmousedown={raiseWidgetsPanelToFront}
|
|
16129
16660
|
>
|
|
16130
16661
|
<!-- Drag bar -->
|
|
@@ -16132,7 +16663,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16132
16663
|
class="widgets-panel-drag-bar relative flex items-center justify-between px-1 py-1.5 -mx-2.5 bg-gray-100 border-b border-gray-200 rounded-t-lg cursor-grab active:cursor-grabbing select-none shrink-0 touch-none"
|
|
16133
16664
|
onpointerdown={startWidgetsPanelDrag}
|
|
16134
16665
|
>
|
|
16135
|
-
<span class="text-xs font-semibold text-gray-500
|
|
16666
|
+
<span class="text-xs font-semibold text-gray-500 ps-2">Widgets List</span>
|
|
16136
16667
|
<div class="absolute left-1/2 -translate-x-1/2 flex items-center">
|
|
16137
16668
|
<div class="grid grid-cols-3 gap-[3px]">
|
|
16138
16669
|
<div class="w-[3px] h-[3px] rounded-full bg-gray-400"></div>
|
|
@@ -16145,7 +16676,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16145
16676
|
</div>
|
|
16146
16677
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
16147
16678
|
<button
|
|
16148
|
-
class="widgets-panel-minimize-btn flex items-center justify-center w-6 h-6 rounded hover:bg-gray-200 transition-colors
|
|
16679
|
+
class="widgets-panel-minimize-btn flex items-center justify-center w-6 h-6 rounded hover:bg-gray-200 transition-colors me-1 cursor-pointer"
|
|
16149
16680
|
title={isWidgetsPanelMinimized ? 'Expand panel' : 'Minimize panel'}
|
|
16150
16681
|
onclick={(e) => { e.stopPropagation(); isWidgetsPanelMinimized = !isWidgetsPanelMinimized; }}
|
|
16151
16682
|
onmousedown={(e) => e.stopPropagation()}
|
|
@@ -16156,9 +16687,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16156
16687
|
</button>
|
|
16157
16688
|
</div> <!-- end of widgets-panel-drag-bar -->
|
|
16158
16689
|
|
|
16159
|
-
<!-- Right-edge resize handle -->
|
|
16160
|
-
<div
|
|
16161
|
-
class="widgets-panel-resize-handle absolute top-0 right-0 w-[10px] h-full cursor-col-resize z-10 flex items-center justify-center hover:bg-blue-100/60 transition-colors"
|
|
16690
|
+
<!-- Right-edge resize handle. rtl-ok: the panel grows from its left edge on every screen, so the handle that widens it is on its right edge -->
|
|
16691
|
+
<div class="widgets-panel-resize-handle absolute top-0 right-0 w-[10px] h-full cursor-col-resize z-10 flex items-center justify-center hover:bg-blue-100/60 transition-colors"
|
|
16162
16692
|
onmousedown={startWidgetsPanelResize}
|
|
16163
16693
|
>
|
|
16164
16694
|
<svg class="w-[4px] h-6 text-gray-400" viewBox="0 0 4 24" fill="currentColor">
|
|
@@ -16233,7 +16763,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16233
16763
|
|
|
16234
16764
|
<!-- Widgets List Container -->
|
|
16235
16765
|
<div
|
|
16236
|
-
class="widgets-list-outer flex flex-col flex-1 min-h-0 border border-gray-200 rounded p-2.5
|
|
16766
|
+
class="widgets-list-outer flex flex-col flex-1 min-h-0 border border-gray-200 rounded p-2.5 pe-0 {isWidgetsPanelMinimized ? 'overflow-hidden' : ''}"
|
|
16237
16767
|
style={isWidgetsPanelMinimized ? 'max-height: 76px;' : ''}
|
|
16238
16768
|
>
|
|
16239
16769
|
|
|
@@ -16383,11 +16913,12 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16383
16913
|
|
|
16384
16914
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
16385
16915
|
{#if !isWidgetsPanelMinimized}
|
|
16386
|
-
|
|
16387
|
-
|
|
16916
|
+
<!-- rtl-ok: the bottom right corner is where the panel is resized from, on every screen -->
|
|
16917
|
+
<div class="widgets-panel-corner-resize absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize z-10 group"
|
|
16388
16918
|
onmousedown={startWidgetsPanelCornerResize}
|
|
16389
16919
|
title="Resize panel"
|
|
16390
16920
|
>
|
|
16921
|
+
<!-- rtl-ok: the grip is drawn in the bottom right corner, as the handle is -->
|
|
16391
16922
|
<svg class="w-3 h-3 absolute bottom-0.5 right-0.5 text-gray-400 group-hover:text-gray-600 transition-colors" viewBox="0 0 6 6" fill="currentColor">
|
|
16392
16923
|
<circle cx="5" cy="1" r="0.7"/>
|
|
16393
16924
|
<circle cx="3" cy="3" r="0.7"/>
|
|
@@ -16563,10 +17094,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16563
17094
|
// console.log('[WidgetCreator] Suppressed automatic build-from-repo chat message:', rebuildMsg);
|
|
16564
17095
|
} else if (isPanelFocused) {
|
|
16565
17096
|
chatMethods?.addAssistantMessage(rebuildMsg, false);
|
|
16566
|
-
showToast('success', '
|
|
17097
|
+
showToast('success', $t('creator.preview.rebuilt'), {
|
|
16567
17098
|
description: buildMs
|
|
16568
|
-
?
|
|
16569
|
-
:
|
|
17099
|
+
? $t('creator.preview.recompiledIn', { ms: buildMs, commit: shaLabel })
|
|
17100
|
+
: $t('creator.preview.commitRefreshed', { commit: shaLabel }),
|
|
16570
17101
|
duration: 6000,
|
|
16571
17102
|
});
|
|
16572
17103
|
}
|
|
@@ -16577,7 +17108,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16577
17108
|
// console.log('[WidgetCreator] Retry repository for widget:', widgetId);
|
|
16578
17109
|
const widget = getWidgetById(widgetId);
|
|
16579
17110
|
if (!widget) {
|
|
16580
|
-
showToast('error', '
|
|
17111
|
+
showToast('error', $t('creator.widget.notFound'));
|
|
16581
17112
|
return;
|
|
16582
17113
|
}
|
|
16583
17114
|
repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [widgetId]: 'pending' };
|
|
@@ -16591,8 +17122,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16591
17122
|
widgetDetails?.setCurrentRepositoryId(repoId);
|
|
16592
17123
|
}
|
|
16593
17124
|
getWidgetDetailsRef(widgetId)?.showNoCodeYetState?.();
|
|
16594
|
-
showToast('success', '
|
|
16595
|
-
description:
|
|
17125
|
+
showToast('success', $t('creator.codegen.repositoryCreated'), {
|
|
17126
|
+
description: $t('creator.status.preparingCodeGeneration')
|
|
16596
17127
|
});
|
|
16597
17128
|
|
|
16598
17129
|
// Restore prompt from localStorage or DB, then auto-generate
|
|
@@ -16601,7 +17132,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16601
17132
|
// Source 1: durable draft store / localStorage (persisted at conversion time)
|
|
16602
17133
|
const storedPromptText = await readWidgetDraft(widgetId)
|
|
16603
17134
|
.then((draft) => draft?.promptText ?? null)
|
|
16604
|
-
.catch(() =>
|
|
17135
|
+
.catch(() => creatorStorage.getItem(PROMPT_TEXT_STORAGE_PREFIX + widgetId));
|
|
16605
17136
|
if (storedPromptText && storedPromptText !== DEFAULT_PROMPT) {
|
|
16606
17137
|
loadPromptForWidget(widgetId);
|
|
16607
17138
|
hasPrompt = true;
|
|
@@ -16652,13 +17183,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16652
17183
|
}
|
|
16653
17184
|
} else {
|
|
16654
17185
|
repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [widgetId]: 'failed' };
|
|
16655
|
-
showToast('error', '
|
|
17186
|
+
showToast('error', $t('creator.codegen.failedToCreateRepository'));
|
|
16656
17187
|
}
|
|
16657
17188
|
} catch (err: any) {
|
|
16658
17189
|
repositorySetupByWidgetId = { ...repositorySetupByWidgetId, [widgetId]: 'failed' };
|
|
16659
17190
|
console.error('[WidgetCreator] Failed to retry repository:', err);
|
|
16660
|
-
showToast('error', '
|
|
16661
|
-
description: err?.message || '
|
|
17191
|
+
showToast('error', $t('creator.codegen.failedToCreateRepository'), {
|
|
17192
|
+
description: err?.message || $t('creator.general.unknownError')
|
|
16662
17193
|
});
|
|
16663
17194
|
}
|
|
16664
17195
|
}}
|
|
@@ -16721,11 +17252,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16721
17252
|
>
|
|
16722
17253
|
<svelte:fragment slot="header-meta">
|
|
16723
17254
|
{#if saveStatus === 'saving' && isPanelFocused}
|
|
16724
|
-
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-blue-100 text-blue-700 animate-pulse">
|
|
17255
|
+
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-blue-100 text-blue-700 animate-pulse">{$t('creator.general.saving')}</span>
|
|
16725
17256
|
{:else if saveStatus === 'saved' && isPanelFocused}
|
|
16726
|
-
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-green-100 text-green-700">
|
|
17257
|
+
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-green-100 text-green-700">{$t('creator.general.saved')}</span>
|
|
16727
17258
|
{:else if saveStatus === 'error' && isPanelFocused}
|
|
16728
|
-
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-red-100 text-red-700">
|
|
17259
|
+
<span class="wc-header-save-status text-[10px] px-1.5 py-0.5 rounded bg-red-100 text-red-700">{$t('creator.general.saveError')}</span>
|
|
16729
17260
|
{/if}
|
|
16730
17261
|
{#if debugMode}
|
|
16731
17262
|
<span class="wc-header-commit text-[10px] text-gray-500 whitespace-nowrap">
|
|
@@ -16775,7 +17306,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16775
17306
|
? !(viewingRecord.publishedAt ?? viewingRecord.published_at)
|
|
16776
17307
|
: false}
|
|
16777
17308
|
<div class="wc-version-history-ct relative shrink-0 flex items-center gap-0.5">
|
|
16778
|
-
<HoverTooltip text=
|
|
17309
|
+
<HoverTooltip text={$t('creator.common.switchVersion')} maxWidth={120}>
|
|
16779
17310
|
<button
|
|
16780
17311
|
type="button"
|
|
16781
17312
|
onclick={(e) => {
|
|
@@ -16798,16 +17329,16 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16798
17329
|
runPublishForPanel(panelWidgetId);
|
|
16799
17330
|
}}
|
|
16800
17331
|
disabled={isPublishDisabledForPanel(panelWidgetId) || (isPublishing && publishingWidgetId === panelWidgetId)}
|
|
16801
|
-
title={getPublishDisabledReasonForPanel(panelWidgetId) ?? '
|
|
17332
|
+
title={getPublishDisabledReasonForPanel(panelWidgetId) ?? $t('creator.publish.publishTheLatestGeneratedCode')}
|
|
16802
17333
|
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"
|
|
16803
17334
|
>
|
|
16804
|
-
{isPublishing && publishingWidgetId === panelWidgetId ? '...' : '
|
|
17335
|
+
{isPublishing && publishingWidgetId === panelWidgetId ? '...' : $t('creator.common.publish')}
|
|
16805
17336
|
</button>
|
|
16806
17337
|
{:else if viewingIsLive}
|
|
16807
17338
|
<span
|
|
16808
17339
|
class="wc-version-live-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 bg-emerald-100 text-emerald-600 opacity-80"
|
|
16809
|
-
title=
|
|
16810
|
-
>
|
|
17340
|
+
title={$t('creator.publish.liveGenerateNewCodeTo')}
|
|
17341
|
+
>{$t('creator.common.live')}</span>
|
|
16811
17342
|
{:else if viewingIsDraft}
|
|
16812
17343
|
{#if viewingIsDraft}
|
|
16813
17344
|
<button
|
|
@@ -16820,10 +17351,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16820
17351
|
runPublishForPanel(panelWidgetId, Number(viewingVersion));
|
|
16821
17352
|
}}
|
|
16822
17353
|
disabled={!canPublishDraftVersionForPanel(panelWidgetId, viewingVersion) || getPublishGateForPanel(panelWidgetId, Number(viewingVersion)).disabled}
|
|
16823
|
-
title=
|
|
17354
|
+
title={$t('creator.common.buildThisDraftVersionAnd')}
|
|
16824
17355
|
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"
|
|
16825
17356
|
>
|
|
16826
|
-
{isPublishing && publishingWidgetId === panelWidgetId ? '...' : '
|
|
17357
|
+
{isPublishing && publishingWidgetId === panelWidgetId ? '...' : $t('creator.common.publish')}
|
|
16827
17358
|
</button>
|
|
16828
17359
|
{/if}
|
|
16829
17360
|
{:else}
|
|
@@ -16837,40 +17368,40 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16837
17368
|
}
|
|
16838
17369
|
}}
|
|
16839
17370
|
disabled={isSettingLiveVersion === Number(viewingVersion)}
|
|
16840
|
-
title=
|
|
17371
|
+
title={$t('creator.publish.publishThisVersionSoVisitors')}
|
|
16841
17372
|
class="wc-version-set-live-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-300 text-emerald-700 hover:bg-emerald-100 disabled:opacity-50 disabled:cursor-not-allowed cursor-pointer"
|
|
16842
17373
|
>
|
|
16843
|
-
{isSettingLiveVersion === Number(viewingVersion) ? '...' : '
|
|
17374
|
+
{isSettingLiveVersion === Number(viewingVersion) ? '...' : $t('creator.common.setLive')}
|
|
16844
17375
|
</button>
|
|
16845
17376
|
{/if}
|
|
16846
17377
|
{#if isHistoryOpen && isPanelFocused}
|
|
16847
17378
|
<Portal target="wc-live-history-portal-{panelWidgetId}">
|
|
16848
17379
|
<button
|
|
16849
17380
|
type="button"
|
|
16850
|
-
class="wc-live-history-backdrop fixed
|
|
16851
|
-
aria-label=
|
|
17381
|
+
class="wc-live-history-backdrop fixed start-0 end-0 bottom-0 top-14 z-[9998] cursor-default bg-transparent"
|
|
17382
|
+
aria-label={$t('creator.version.closeVersionHistory')}
|
|
16852
17383
|
onclick={() => { isHistoryOpen = false; }}
|
|
16853
17384
|
></button>
|
|
16854
17385
|
{@const hasChatScroll = ps.publishHistory.length > 5}
|
|
16855
17386
|
<div
|
|
16856
17387
|
class="wc-version-history-panel rounded-md border border-emerald-200 bg-white shadow-lg p-1 z-[9999] w-max"
|
|
16857
|
-
style="position: fixed; top: {liveHistoryPanelTop}px;
|
|
17388
|
+
style="position: fixed; top: {liveHistoryPanelTop}px; {liveHistoryPanelPlacement}"
|
|
16858
17389
|
>
|
|
16859
17390
|
{#if isLoadingHistory}
|
|
16860
|
-
<p class="text-xs text-emerald-500 animate-pulse text-center py-2">
|
|
17391
|
+
<p class="text-xs text-emerald-500 animate-pulse text-center py-2">{$t('creator.general.loadingHistory')}</p>
|
|
16861
17392
|
{:else if ps.publishHistory.length === 0}
|
|
16862
|
-
<p class="text-xs text-emerald-400 text-center py-2">
|
|
17393
|
+
<p class="text-xs text-emerald-400 text-center py-2">{$t('creator.publish.noHistoryRecordsYetGenerate')}</p>
|
|
16863
17394
|
{:else}
|
|
16864
17395
|
<div
|
|
16865
17396
|
class="wc-version-history-scroll flex flex-col gap-1 overflow-x-hidden {hasChatScroll ? 'overflow-y-auto' : 'overflow-y-visible'}"
|
|
16866
|
-
style="{hasChatScroll ? 'max-height: 185px; margin-
|
|
17397
|
+
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;"
|
|
16867
17398
|
>
|
|
16868
17399
|
{#each ps.publishHistory as record (record.id)}
|
|
16869
17400
|
{@const rowVersion = Number(record.version)}
|
|
16870
17401
|
{@const rowIsDraft = !(record.publishedAt ?? record.published_at)}
|
|
16871
17402
|
{@const rowIsViewing = rowVersion === Number(viewingVersion)}
|
|
16872
17403
|
{@const rowIsLive = !rowIsDraft && rowVersion === Number(panelPublishedVersion)}
|
|
16873
|
-
{@const rowDateLabel = formatPublishHistoryDate(record)}
|
|
17404
|
+
{@const rowDateLabel = formatPublishHistoryDate(record, $languageTag)}
|
|
16874
17405
|
{@const publishGate = getPublishGateForPanel(panelWidgetId, rowVersion)} <VersionDropdownRow
|
|
16875
17406
|
versionLabel={'v' + rowVersion}
|
|
16876
17407
|
commitSha={record.commitSha ?? record.commit_sha ?? null}
|
|
@@ -16935,9 +17466,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16935
17466
|
<div class="flex items-center justify-between gap-2 min-w-0">
|
|
16936
17467
|
<div class="generate-code-status-el text-xs flex-1 min-w-0 truncate {ps.lastGenerationFailed ? 'text-red-600' : 'text-gray-500'}">
|
|
16937
17468
|
{#if ps.lastGenerationFailed}
|
|
16938
|
-
<span class="text-red-500 font-medium">
|
|
17469
|
+
<span class="text-red-500 font-medium">{$t('creator.codegen.generationFailed')}</span>
|
|
16939
17470
|
{:else}
|
|
16940
|
-
<span class="text-gray-400">
|
|
17471
|
+
<span class="text-gray-400">{$t('creator.status.label')}</span> {statusLabel(ps.generateCodeStatus, $t)}
|
|
16941
17472
|
{/if}
|
|
16942
17473
|
</div>
|
|
16943
17474
|
</div>
|
|
@@ -16951,7 +17482,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16951
17482
|
size="sm"
|
|
16952
17483
|
class="bg-red-600 hover:bg-red-700 text-white rounded-lg"
|
|
16953
17484
|
>
|
|
16954
|
-
|
|
17485
|
+
{$t('creator.general.upgrade')}
|
|
16955
17486
|
</Button>
|
|
16956
17487
|
<Button
|
|
16957
17488
|
onclick={() => {
|
|
@@ -16963,14 +17494,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16963
17494
|
size="sm"
|
|
16964
17495
|
class="border-gray-300 text-gray-600 hover:bg-gray-50 rounded-lg"
|
|
16965
17496
|
>
|
|
16966
|
-
|
|
17497
|
+
{$t('creator.general.dismiss')}
|
|
16967
17498
|
</Button>
|
|
16968
17499
|
</div>
|
|
16969
17500
|
</div>
|
|
16970
17501
|
{/if}
|
|
16971
17502
|
{#if ps.lastGenerationFailed}
|
|
16972
17503
|
<div class="p-3 bg-red-50 border border-red-200" style="border-radius: 0;">
|
|
16973
|
-
<p class="text-xs text-red-700 whitespace-pre-wrap">{ps.lastGenerationError}</p>
|
|
17504
|
+
<p class="text-xs text-red-700 whitespace-pre-wrap">{errorLabel(ps.lastGenerationError, $t)}</p>
|
|
16974
17505
|
<div class="flex gap-2 mt-3 justify-center">
|
|
16975
17506
|
{#if isPlanLimitMessage(ps.lastGenerationError)}
|
|
16976
17507
|
<Button
|
|
@@ -16979,7 +17510,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16979
17510
|
size="sm"
|
|
16980
17511
|
class="bg-red-600 hover:bg-red-700 text-white rounded-lg"
|
|
16981
17512
|
>
|
|
16982
|
-
|
|
17513
|
+
{$t('creator.general.upgrade')}
|
|
16983
17514
|
</Button>
|
|
16984
17515
|
{:else}
|
|
16985
17516
|
<Button
|
|
@@ -16994,7 +17525,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
16994
17525
|
size="sm"
|
|
16995
17526
|
class="bg-red-600 hover:bg-red-700 text-white rounded-lg"
|
|
16996
17527
|
>
|
|
16997
|
-
|
|
17528
|
+
{$t('creator.common.retry')}
|
|
16998
17529
|
</Button>
|
|
16999
17530
|
{/if}
|
|
17000
17531
|
<Button
|
|
@@ -17015,7 +17546,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17015
17546
|
size="sm"
|
|
17016
17547
|
class="border-gray-300 text-gray-600 hover:bg-gray-50 rounded-lg"
|
|
17017
17548
|
>
|
|
17018
|
-
|
|
17549
|
+
{$t('creator.general.dismiss')}
|
|
17019
17550
|
</Button>
|
|
17020
17551
|
</div>
|
|
17021
17552
|
</div>
|
|
@@ -17082,6 +17613,9 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17082
17613
|
/>
|
|
17083
17614
|
{/snippet}
|
|
17084
17615
|
<Chat class="code-generation-chat w-full h-full rounded-none border-0"
|
|
17616
|
+
locale={locale}
|
|
17617
|
+
messages={chatMessages}
|
|
17618
|
+
storedLineLabel={(line) => conversationLineLabel(line, $t)}
|
|
17085
17619
|
actionBarExtras={generationOptionChecks}
|
|
17086
17620
|
style="height: 100%; min-height: {chatUserHeight == null ? CHAT_AUTO_MIN_HEIGHT : CHAT_MIN_HEIGHT}px;"
|
|
17087
17621
|
resizeExpandsContainer={true}
|
|
@@ -17094,7 +17628,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17094
17628
|
id: panelWidgetId,
|
|
17095
17629
|
type: ContextType.FRAME,
|
|
17096
17630
|
parentId: panelWidgetId,
|
|
17097
|
-
title: panelWidget?.name || '
|
|
17631
|
+
title: panelWidget?.name || $t('creator.widget.fallbackName'),
|
|
17098
17632
|
}}
|
|
17099
17633
|
config={{
|
|
17100
17634
|
features: {
|
|
@@ -17119,6 +17653,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17119
17653
|
viewingVersion={viewingVersionByWidgetId[panelWidgetId] ?? null}
|
|
17120
17654
|
onSendMessage={(content, attachments) => handleChatSendMessage(content, attachments, panelWidgetId)}
|
|
17121
17655
|
onRetryMessage={(content) => handleChatRetryMessage(content, panelWidgetId)}
|
|
17656
|
+
onUpgradePlans={openUpgradePlans}
|
|
17122
17657
|
onUploadChatFile={handleChatUploadFile}
|
|
17123
17658
|
onTakeScreenshot={() => handleChatScreenshot(panelWidgetId)}
|
|
17124
17659
|
isCompleted={!!conversationCompletedByWidgetId[panelWidgetId]}
|
|
@@ -17164,7 +17699,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17164
17699
|
{#if panelHasUnpublishedChanges}
|
|
17165
17700
|
<div class="edit-unpublished-banner-ct mx-3 mt-2 px-2 py-1.5 rounded-md border border-amber-200 bg-amber-50 text-amber-800 text-xs flex items-center gap-2 shrink-0">
|
|
17166
17701
|
<p class="edit-unpublished-banner-text leading-snug min-w-0 flex-1 truncate">
|
|
17167
|
-
<strong class="font-semibold">
|
|
17702
|
+
<strong class="font-semibold">{$t('creator.preview.newerThanLive', { version: ps.lastPublishedVersion ?? '—' })}</strong>
|
|
17168
17703
|
{#if debugMode}
|
|
17169
17704
|
<span class="font-mono">{formatCommitShaShort(ps.lastCommitId)}</span>
|
|
17170
17705
|
ahead of
|
|
@@ -17183,7 +17718,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17183
17718
|
{#if isPublishing && publishingWidgetId === panelWidgetId}
|
|
17184
17719
|
<span>⏳</span>
|
|
17185
17720
|
{:else}
|
|
17186
|
-
<span>
|
|
17721
|
+
<span>{$t('creator.publish.retryPublish')}</span>
|
|
17187
17722
|
{/if}
|
|
17188
17723
|
</Button>
|
|
17189
17724
|
</div>
|
|
@@ -17191,8 +17726,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17191
17726
|
|
|
17192
17727
|
{#if isEditStepWithoutPublishForPanel(panelWidgetId)}
|
|
17193
17728
|
<div class="edit-not-published-banner-ct mx-3 mt-2 px-3 py-2 rounded-md border border-amber-200 bg-amber-50 text-amber-800 text-xs">
|
|
17194
|
-
<strong class="font-semibold">
|
|
17195
|
-
|
|
17729
|
+
<strong class="font-semibold">{$t('creator.publish.notPublishedYet')}</strong>
|
|
17730
|
+
{$t('creator.publish.generateOnCreatePreviewThe')}
|
|
17196
17731
|
</div>
|
|
17197
17732
|
{/if}
|
|
17198
17733
|
|
|
@@ -17203,11 +17738,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17203
17738
|
<div class="composition-builder-unavailable-header flex items-start gap-2">
|
|
17204
17739
|
<span class="text-xl shrink-0" aria-hidden="true">⚠️</span>
|
|
17205
17740
|
<div class="composition-builder-unavailable-copy min-w-0">
|
|
17206
|
-
<p class="text-sm font-semibold">
|
|
17741
|
+
<p class="text-sm font-semibold">{$t('creator.codegen.previewBuilderIsUnavailable')}</p>
|
|
17207
17742
|
<p class="text-xs mt-1 text-amber-800 leading-relaxed">
|
|
17208
|
-
|
|
17743
|
+
{$t('creator.codegen.theWidgetCodeWasSaved')}
|
|
17209
17744
|
</p>
|
|
17210
|
-
<p class="text-[11px] mt-2 text-amber-700 wrap-break-word">{getPanelPreviewCompileError(panelWidgetId)}</p>
|
|
17745
|
+
<p class="text-[11px] mt-2 text-amber-700 wrap-break-word">{errorLabel(getPanelPreviewCompileError(panelWidgetId), $t)}</p>
|
|
17211
17746
|
</div>
|
|
17212
17747
|
</div>
|
|
17213
17748
|
<Button
|
|
@@ -17219,7 +17754,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17219
17754
|
void getWidgetDetailsRef(panelWidgetId)?.triggerBuildFromRepo?.({ force: true });
|
|
17220
17755
|
}}
|
|
17221
17756
|
>
|
|
17222
|
-
|
|
17757
|
+
{$t('creator.codegen.rebuildInCreate')}
|
|
17223
17758
|
</Button>
|
|
17224
17759
|
</div>
|
|
17225
17760
|
{:else if panelHasCompileErrorState}
|
|
@@ -17227,11 +17762,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17227
17762
|
<div class="composition-compile-error-header flex items-start gap-2">
|
|
17228
17763
|
<span class="text-xl shrink-0" aria-hidden="true">⚠️</span>
|
|
17229
17764
|
<div class="composition-compile-error-copy min-w-0">
|
|
17230
|
-
<p class="text-sm font-semibold">
|
|
17765
|
+
<p class="text-sm font-semibold">{$t('creator.codegen.codeDoesNotCompile')}</p>
|
|
17231
17766
|
<p class="text-xs mt-1 text-red-800 leading-relaxed">
|
|
17232
|
-
|
|
17767
|
+
{$t('creator.composition.fixTheSyntaxErrorIn')}
|
|
17233
17768
|
</p>
|
|
17234
|
-
<p class="text-[11px] font-mono mt-2 text-red-700 wrap-break-word">{getPanelPreviewCompileError(panelWidgetId)}</p>
|
|
17769
|
+
<p class="text-[11px] font-mono mt-2 text-red-700 wrap-break-word">{errorLabel(getPanelPreviewCompileError(panelWidgetId), $t)}</p>
|
|
17235
17770
|
</div>
|
|
17236
17771
|
</div>
|
|
17237
17772
|
<Button
|
|
@@ -17239,7 +17774,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17239
17774
|
class="fix-compile-in-create-btn w-fit"
|
|
17240
17775
|
onclick={() => fixWidgetCompileError(panelWidgetId, getPanelPreviewCompileError(panelWidgetId))}
|
|
17241
17776
|
>
|
|
17242
|
-
|
|
17777
|
+
{$t('creator.general.fixInCreate')}
|
|
17243
17778
|
</Button>
|
|
17244
17779
|
</div>
|
|
17245
17780
|
{/if}
|
|
@@ -17247,13 +17782,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17247
17782
|
|
|
17248
17783
|
{#if panelHasCompileErrorState}
|
|
17249
17784
|
<div class="composition-compile-error-ct mx-3 mt-2 px-3 py-3 rounded-md border border-amber-200 bg-amber-50 text-amber-900 text-xs">
|
|
17250
|
-
<strong class="font-semibold">
|
|
17251
|
-
<span class="
|
|
17785
|
+
<strong class="font-semibold">{$t('creator.codegen.latestCodeDoesNotCompile')}</strong>
|
|
17786
|
+
<span class="ms-1">{$t('creator.preview.mayShowLive', { version: ps.lastPublishedVersion })}</span>
|
|
17252
17787
|
<button
|
|
17253
17788
|
type="button"
|
|
17254
|
-
class="
|
|
17789
|
+
class="ms-2 underline font-medium cursor-pointer"
|
|
17255
17790
|
onclick={() => fixWidgetCompileError(panelWidgetId, getPanelPreviewCompileError(panelWidgetId))}
|
|
17256
|
-
>
|
|
17791
|
+
>{$t('creator.general.fixInCreate2')}</button>
|
|
17257
17792
|
</div>
|
|
17258
17793
|
{/if}
|
|
17259
17794
|
|
|
@@ -17261,20 +17796,21 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17261
17796
|
{#if ps.compositionDesignSchema || ps.compositionContentSchema}
|
|
17262
17797
|
<div class="compositions-bar flex items-center gap-2 px-3 py-2 bg-gray-50 shrink-0 flex-nowrap">
|
|
17263
17798
|
<!-- Composition selector dropdown -->
|
|
17799
|
+
<!-- A visitor of a partner can add and rename compositions but not delete them (the gateway does not let a session do that), so the delete control is not offered. -->
|
|
17264
17800
|
<SelectorDropdown
|
|
17265
17801
|
class="compositions-selector"
|
|
17266
17802
|
items={getCompositionDropdownItemsFromList(ps.compositions)}
|
|
17267
17803
|
selectedId={ps.selectedComposition?.id || null}
|
|
17268
|
-
label=
|
|
17804
|
+
label={$t('creator.composition.compositions')}
|
|
17269
17805
|
labelPosition="inline"
|
|
17270
|
-
placeholder={ps.selectedComposition?.name || '
|
|
17271
|
-
newButtonLabel=
|
|
17806
|
+
placeholder={ps.selectedComposition?.name || $t('creator.composition.selectComposition')}
|
|
17807
|
+
newButtonLabel={$t('creator.common.new')}
|
|
17272
17808
|
accentColor="#3B82F6"
|
|
17273
17809
|
nameWidth="140px"
|
|
17274
17810
|
loading={isPanelFocused && compositionsLoading}
|
|
17275
17811
|
allowRename={!!ps.selectedComposition}
|
|
17276
17812
|
onselect={(item) => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); handleCompositionDropdownSelect(item); }}
|
|
17277
|
-
ondelete={(item) => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); handleCompositionDropdownDelete(item); }}
|
|
17813
|
+
ondelete={partnerMode ? undefined : (item) => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); handleCompositionDropdownDelete(item); }}
|
|
17278
17814
|
onnew={() => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); handleCompositionDropdownNew(); }}
|
|
17279
17815
|
onrename={(id, name) => { if (!isPanelFocused) focusWidgetPanel(panelWidgetId); handleCompositionDropdownRename(id, name); }}
|
|
17280
17816
|
/>
|
|
@@ -17303,11 +17839,11 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17303
17839
|
</svg>
|
|
17304
17840
|
{/if}
|
|
17305
17841
|
{#if compositionSaving}
|
|
17306
|
-
|
|
17842
|
+
{$t('creator.general.saving2')}
|
|
17307
17843
|
{:else if ps.selectedComposition}
|
|
17308
|
-
{ps.compositionDirty ? '
|
|
17844
|
+
{ps.compositionDirty ? $t('creator.general.save') : $t('creator.general.saved')}
|
|
17309
17845
|
{:else}
|
|
17310
|
-
|
|
17846
|
+
{$t('creator.general.save')}
|
|
17311
17847
|
{/if}
|
|
17312
17848
|
</button>
|
|
17313
17849
|
</div>
|
|
@@ -17317,10 +17853,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17317
17853
|
{#if deletingCompositionId}
|
|
17318
17854
|
<div class="compositions-delete-confirm fixed inset-0 flex items-center justify-center bg-black/30" style="z-index: 99999;">
|
|
17319
17855
|
<div class="bg-white rounded-lg shadow-lg p-4 max-w-xs text-center">
|
|
17320
|
-
<p class="text-sm text-gray-700 mb-3">
|
|
17856
|
+
<p class="text-sm text-gray-700 mb-3">{$t('creator.composition.deleteThisComposition')}</p>
|
|
17321
17857
|
<div class="flex gap-2 justify-center">
|
|
17322
|
-
<Button variant="outline" size="sm" onclick={() => deletingCompositionId = null}>
|
|
17323
|
-
<Button variant="default" size="sm" onclick={deleteComposition} class="bg-red-600 hover:bg-red-700 border-red-600">
|
|
17858
|
+
<Button variant="outline" size="sm" onclick={() => deletingCompositionId = null}>{$t('creator.general.cancel')}</Button>
|
|
17859
|
+
<Button variant="default" size="sm" onclick={deleteComposition} class="bg-red-600 hover:bg-red-700 border-red-600">{$t('creator.common.delete')}</Button>
|
|
17324
17860
|
</div>
|
|
17325
17861
|
</div>
|
|
17326
17862
|
</div>
|
|
@@ -17343,7 +17879,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17343
17879
|
}}
|
|
17344
17880
|
class="text-xs px-2 py-1 rounded bg-blue-100 text-blue-700 hover:bg-blue-200 w-fit transition-colors"
|
|
17345
17881
|
>
|
|
17346
|
-
|
|
17882
|
+
{$t('creator.common.retry')}
|
|
17347
17883
|
</button>
|
|
17348
17884
|
</div>
|
|
17349
17885
|
{:else if ps.compositionDesignSchema || ps.compositionContentSchema}
|
|
@@ -17366,6 +17902,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17366
17902
|
height="620px"
|
|
17367
17903
|
showDragHandle={false}
|
|
17368
17904
|
enableDrag={false}
|
|
17905
|
+
{mediaLibrary}
|
|
17369
17906
|
defaultTab="design"
|
|
17370
17907
|
on:propertyChange={handleEditorPropertyChange}
|
|
17371
17908
|
on:contentItemsChanged={handleEditorContentItemsChanged}
|
|
@@ -17374,8 +17911,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17374
17911
|
</div>
|
|
17375
17912
|
{:else}
|
|
17376
17913
|
<div class="flex flex-col items-center justify-center py-8 text-center">
|
|
17377
|
-
<p class="text-sm text-gray-500">
|
|
17378
|
-
<p class="text-xs text-gray-400 mt-1">
|
|
17914
|
+
<p class="text-sm text-gray-500">{$t('creator.general.noEditableSettingsAvailableYet')}</p>
|
|
17915
|
+
<p class="text-xs text-gray-400 mt-1">{$t('creator.codegen.generateCodeFirstToCustomize')}</p>
|
|
17379
17916
|
</div>
|
|
17380
17917
|
{/if}
|
|
17381
17918
|
|
|
@@ -17384,8 +17921,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17384
17921
|
{:else}
|
|
17385
17922
|
<div class="flex flex-col items-center justify-center py-12 text-center px-4">
|
|
17386
17923
|
<div class="text-3xl mb-3">🎨</div>
|
|
17387
|
-
<p class="text-sm font-medium text-gray-600">
|
|
17388
|
-
<p class="text-xs text-gray-400 mt-1">
|
|
17924
|
+
<p class="text-sm font-medium text-gray-600">{$t('creator.codegen.noWidgetCodeYet')}</p>
|
|
17925
|
+
<p class="text-xs text-gray-400 mt-1">{$t('creator.codegen.goToStep1Create')}</p>
|
|
17389
17926
|
</div>
|
|
17390
17927
|
{/if}
|
|
17391
17928
|
</div>
|
|
@@ -17401,29 +17938,29 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17401
17938
|
{#if panelWidgetId && ps.lastPublishedVersion !== null}
|
|
17402
17939
|
<div class="embed-section flex flex-col gap-4 p-3">
|
|
17403
17940
|
<div class="embed-section-header">
|
|
17404
|
-
<h3 class="text-sm font-semibold text-gray-700">
|
|
17941
|
+
<h3 class="text-sm font-semibold text-gray-700">{$t('creator.embed.embedYourWidget')}</h3>
|
|
17405
17942
|
{#if ps.lastPublishedVersion !== null}
|
|
17406
|
-
<p class="text-xs text-gray-500 mt-1">
|
|
17943
|
+
<p class="text-xs text-gray-500 mt-1">{$t('creator.embed.setDimensionsAndCopyThe')}</p>
|
|
17407
17944
|
{/if}
|
|
17408
17945
|
</div>
|
|
17409
17946
|
|
|
17410
17947
|
{#if ps.lastPublishedVersion === null}
|
|
17411
17948
|
<div class="embed-unpublished-ct flex flex-col items-center justify-center py-8 text-center px-4">
|
|
17412
17949
|
<div class="text-3xl mb-3">📦</div>
|
|
17413
|
-
<p class="text-sm font-medium text-gray-600">
|
|
17414
|
-
<p class="text-xs text-gray-400 mt-1">
|
|
17950
|
+
<p class="text-sm font-medium text-gray-600">{$t('creator.publish.widgetNotPublishedYet')}</p>
|
|
17951
|
+
<p class="text-xs text-gray-400 mt-1">{$t('creator.publish.publishYourWidgetFromThe')}</p>
|
|
17415
17952
|
</div>
|
|
17416
17953
|
{:else}
|
|
17417
17954
|
|
|
17418
17955
|
<!-- Embed Dimensions -->
|
|
17419
17956
|
<div class="embed-dimensions-ct flex flex-col gap-2">
|
|
17420
|
-
<label class="text-xs font-medium text-gray-600" for="embed-width-input">
|
|
17957
|
+
<label class="text-xs font-medium text-gray-600" for="embed-width-input">{$t('creator.general.dimensions')}</label>
|
|
17421
17958
|
<div class="embed-dimensions-row flex items-center gap-2">
|
|
17422
17959
|
<div class="embed-dim-input flex items-center gap-1">
|
|
17423
|
-
<span class="text-[10px] text-gray-400 font-medium">
|
|
17960
|
+
<span class="text-[10px] text-gray-400 font-medium">{$t('creator.general.w')}</span>
|
|
17424
17961
|
<input
|
|
17425
17962
|
id="embed-width-input"
|
|
17426
|
-
aria-label=
|
|
17963
|
+
aria-label={$t('creator.embed.embedWidth')}
|
|
17427
17964
|
type="number"
|
|
17428
17965
|
min="100"
|
|
17429
17966
|
max="4000"
|
|
@@ -17440,10 +17977,10 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17440
17977
|
</div>
|
|
17441
17978
|
<span class="text-gray-300 text-xs">×</span>
|
|
17442
17979
|
<div class="embed-dim-input flex items-center gap-1">
|
|
17443
|
-
<span class="text-[10px] text-gray-400 font-medium">
|
|
17980
|
+
<span class="text-[10px] text-gray-400 font-medium">{$t('creator.general.h')}</span>
|
|
17444
17981
|
<input
|
|
17445
17982
|
id="embed-height-input"
|
|
17446
|
-
aria-label=
|
|
17983
|
+
aria-label={$t('creator.embed.embedHeight')}
|
|
17447
17984
|
type="number"
|
|
17448
17985
|
min="50"
|
|
17449
17986
|
max="4000"
|
|
@@ -17458,14 +17995,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17458
17995
|
class="w-16 text-xs px-1.5 py-1 rounded border border-gray-300 text-center"
|
|
17459
17996
|
/>
|
|
17460
17997
|
</div>
|
|
17461
|
-
<span class="text-[10px] text-gray-400">px</span>
|
|
17998
|
+
<span class="text-[10px] text-gray-400">{$t('creator.general.px')}</span>
|
|
17462
17999
|
{#if embedDimensionsChanged && selectedComposition}
|
|
17463
18000
|
<button
|
|
17464
18001
|
type="button"
|
|
17465
|
-
class="embed-save-dims-btn
|
|
18002
|
+
class="embed-save-dims-btn ms-auto px-2.5 py-1 text-[10px] font-medium rounded border border-blue-500 text-blue-600 hover:bg-blue-50 transition-colors cursor-pointer"
|
|
17466
18003
|
onclick={saveEmbedDimensions}
|
|
17467
18004
|
>
|
|
17468
|
-
{isSavingEmbedDims ? '
|
|
18005
|
+
{isSavingEmbedDims ? $t('creator.general.saving2') : $t('creator.general.save')}
|
|
17469
18006
|
</button>
|
|
17470
18007
|
{/if}
|
|
17471
18008
|
</div>
|
|
@@ -17490,22 +18027,22 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17490
18027
|
<div class="embed-code-ct flex flex-col gap-2">
|
|
17491
18028
|
<div class="embed-code-header flex items-center justify-between">
|
|
17492
18029
|
<!-- svelte-ignore a11y_label_has_associated_control -->
|
|
17493
|
-
<label class="text-xs font-medium text-gray-600">
|
|
18030
|
+
<label class="text-xs font-medium text-gray-600">{$t('creator.embed.codeTitle', { format: embedFormatLabel(effectiveFormat, $t) })}</label>
|
|
17494
18031
|
<!-- svelte-ignore a11y_consider_explicit_label -->
|
|
17495
18032
|
<button
|
|
17496
18033
|
type="button"
|
|
17497
|
-
title=
|
|
18034
|
+
title={$t('creator.embed.copyEmbedCode')}
|
|
17498
18035
|
onclick={() => {
|
|
17499
18036
|
navigator.clipboard.writeText(effectiveEmbedCode);
|
|
17500
|
-
showToast('success', '
|
|
18037
|
+
showToast('success', $t('creator.embed.copied'), { duration: 2000 });
|
|
17501
18038
|
}}
|
|
17502
18039
|
class="embed-copy-btn flex items-center gap-1 px-2 py-0.5 text-[10px] font-medium rounded text-gray-500 hover:text-gray-700 hover:bg-gray-100 transition-colors cursor-pointer"
|
|
17503
18040
|
>
|
|
17504
18041
|
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2" ry="2" stroke-width="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" stroke-width="2"/></svg>
|
|
17505
|
-
|
|
18042
|
+
{$t('creator.general.copy')}
|
|
17506
18043
|
</button>
|
|
17507
18044
|
</div>
|
|
17508
|
-
<div class="embed-format-selector flex items-center gap-1 mb-1" role="tablist" aria-label=
|
|
18045
|
+
<div class="embed-format-selector flex items-center gap-1 mb-1" role="tablist" aria-label={$t('creator.embed.embedFormat')}>
|
|
17509
18046
|
{#each EMBED_FORMATS as fmt}
|
|
17510
18047
|
<button
|
|
17511
18048
|
type="button"
|
|
@@ -17514,13 +18051,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17514
18051
|
class="embed-format-tab px-2.5 py-1 text-[11px] font-medium rounded border transition-colors {embedFormat === fmt ? 'border-blue-500 bg-blue-50 text-blue-700' : 'border-gray-300 text-gray-600 hover:bg-gray-50'}"
|
|
17515
18052
|
onclick={() => { embedFormat = fmt; }}
|
|
17516
18053
|
>
|
|
17517
|
-
{
|
|
18054
|
+
{embedFormatLabel(fmt, $t)}
|
|
17518
18055
|
</button>
|
|
17519
18056
|
{/each}
|
|
17520
18057
|
</div>
|
|
17521
18058
|
{#if embedFormat === 'web-component' && effectiveFormat === 'iframe'}
|
|
17522
18059
|
<p class="embed-format-fallback-note text-[10px] text-amber-600 bg-amber-50 border border-amber-200 rounded px-2 py-1">
|
|
17523
|
-
|
|
18060
|
+
{$t('creator.composition.webComponentFormatRequiresA')}
|
|
17524
18061
|
</p>
|
|
17525
18062
|
{/if}
|
|
17526
18063
|
<div class="embed-code-block max-h-40 overflow-y-auto overflow-x-hidden rounded-lg scrollbar-thin">
|
|
@@ -17531,7 +18068,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17531
18068
|
<!-- Direct URL -->
|
|
17532
18069
|
<!-- svelte-ignore a11y_label_has_associated_control -->
|
|
17533
18070
|
<div class="embed-url-ct flex flex-col gap-2">
|
|
17534
|
-
<label class="text-xs font-medium text-gray-600">{selectedComposition ? '
|
|
18071
|
+
<label class="text-xs font-medium text-gray-600">{selectedComposition ? $t('creator.composition.compositionUrl') : $t('creator.widget.directWidgetUrl')}</label>
|
|
17535
18072
|
<div class="flex items-center gap-2">
|
|
17536
18073
|
<input
|
|
17537
18074
|
type="text"
|
|
@@ -17544,7 +18081,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17544
18081
|
onclick={() => openEmbedTestPage(testPageHref)}
|
|
17545
18082
|
class="px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 transition-colors whitespace-nowrap cursor-pointer"
|
|
17546
18083
|
>
|
|
17547
|
-
|
|
18084
|
+
{$t('creator.general.testPage')}
|
|
17548
18085
|
</button>
|
|
17549
18086
|
</div>
|
|
17550
18087
|
</div>
|
|
@@ -17555,8 +18092,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17555
18092
|
{:else}
|
|
17556
18093
|
<div class="flex flex-col items-center justify-center py-12 text-center px-4">
|
|
17557
18094
|
<div class="text-3xl mb-3">🔗</div>
|
|
17558
|
-
<p class="text-sm font-medium text-gray-600">
|
|
17559
|
-
<p class="text-xs text-gray-400 mt-1">
|
|
18095
|
+
<p class="text-sm font-medium text-gray-600">{$t('creator.publish.widgetNotPublishedYet')}</p>
|
|
18096
|
+
<p class="text-xs text-gray-400 mt-1">{$t('creator.publish.publishYourWidgetFromTheCreate')}</p>
|
|
17560
18097
|
</div>
|
|
17561
18098
|
{/if}
|
|
17562
18099
|
</div>
|
|
@@ -17582,12 +18119,12 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17582
18119
|
<!-- svelte-ignore a11y_img_redundant_alt -->
|
|
17583
18120
|
<img
|
|
17584
18121
|
src={lightboxImage}
|
|
17585
|
-
alt=
|
|
18122
|
+
alt={$t('creator.general.zoomedReference')}
|
|
17586
18123
|
style="max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 0.5rem; box-shadow: 0 25px 50px rgba(0,0,0,0.25);"
|
|
17587
18124
|
/>
|
|
17588
18125
|
<button
|
|
17589
18126
|
type="button"
|
|
17590
|
-
style="position: absolute; top: 1rem;
|
|
18127
|
+
style="position: absolute; top: 1rem; inset-inline-end: 1rem; width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.9); color: #374151; border-radius: 9999px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); border: none; cursor: pointer; font-size: 1.125rem; font-weight: 700;"
|
|
17591
18128
|
onclick={(e) => { e.stopPropagation(); lightboxImage = null; }}
|
|
17592
18129
|
>✕</button>
|
|
17593
18130
|
</div>
|
|
@@ -17641,15 +18178,13 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17641
18178
|
<!-- Dialog.Root (bits-ui AlertDialogRoot) exposes no class prop — styling hooks
|
|
17642
18179
|
live on Content/Header below. -->
|
|
17643
18180
|
<Dialog.Root bind:open={deleteDialogOpen} onOpenChange={(open) => { if (!open) handleDeleteDialogResponse('cancel'); }}>
|
|
17644
|
-
<Dialog.Content class="confirm-delete-dialog-content max-w-md bg-white z-9999">
|
|
18181
|
+
<Dialog.Content closeLabel={$t('creator.common.close')} class="confirm-delete-dialog-content max-w-md bg-white z-9999">
|
|
17645
18182
|
<Dialog.Header class="confirm-delete-dialog-header">
|
|
17646
|
-
<Dialog.Title>
|
|
18183
|
+
<Dialog.Title>{$t('creator.widget.deleteWidgetShape')}</Dialog.Title>
|
|
17647
18184
|
<Dialog.Description>
|
|
17648
|
-
{#
|
|
17649
|
-
|
|
17650
|
-
{
|
|
17651
|
-
Also delete the widget <strong>"{deleteDialogWidgetName}"</strong> from the database?
|
|
17652
|
-
{/if}
|
|
18185
|
+
{#each sentenceParts(deleteDialogStep === 'confirm-remove' ? 'creator.dialog.removeShape' : 'creator.dialog.alsoDeleteWidget', ['name'], $t) as part}
|
|
18186
|
+
{#if 'text' in part}{part.text}{:else}<strong>"{deleteDialogWidgetName}"</strong>{/if}
|
|
18187
|
+
{/each}
|
|
17653
18188
|
</Dialog.Description>
|
|
17654
18189
|
</Dialog.Header>
|
|
17655
18190
|
|
|
@@ -17659,23 +18194,23 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17659
18194
|
type="button"
|
|
17660
18195
|
class="px-4 py-2 text-sm rounded-lg border border-gray-300 hover:bg-gray-100 cursor-pointer"
|
|
17661
18196
|
onclick={() => handleDeleteDialogResponse('cancel')}
|
|
17662
|
-
>
|
|
18197
|
+
>{$t('creator.general.cancel')}</button>
|
|
17663
18198
|
<button
|
|
17664
18199
|
type="button"
|
|
17665
18200
|
class="px-4 py-2 text-sm rounded-lg bg-red-600 hover:bg-red-700 text-white cursor-pointer"
|
|
17666
18201
|
onclick={() => handleDeleteDialogResponse('remove-and-ask-db')}
|
|
17667
|
-
>
|
|
18202
|
+
>{$t('creator.common.delete')}</button>
|
|
17668
18203
|
{:else if ASK_DELETE_FROM_DB_CONFIRM}
|
|
17669
18204
|
<button
|
|
17670
18205
|
type="button"
|
|
17671
18206
|
class="px-4 py-2 text-sm rounded-lg border border-gray-300 hover:bg-gray-100 cursor-pointer"
|
|
17672
18207
|
onclick={() => handleDeleteDialogResponse('keep-in-db')}
|
|
17673
|
-
>
|
|
18208
|
+
>{$t('creator.general.keepInDatabase')}</button>
|
|
17674
18209
|
<button
|
|
17675
18210
|
type="button"
|
|
17676
18211
|
class="px-4 py-2 text-sm rounded-lg bg-red-600 hover:bg-red-700 text-white cursor-pointer"
|
|
17677
18212
|
onclick={() => handleDeleteDialogResponse('delete-from-db')}
|
|
17678
|
-
>
|
|
18213
|
+
>{$t('creator.general.deleteFromDatabase')}</button>
|
|
17679
18214
|
{/if}
|
|
17680
18215
|
</div>
|
|
17681
18216
|
</Dialog.Content>
|
|
@@ -17683,24 +18218,24 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17683
18218
|
|
|
17684
18219
|
<!-- Delete Canvas Confirmation Dialog -->
|
|
17685
18220
|
<Dialog.Root bind:open={showDeleteCanvasDialog} onOpenChange={(open) => { if (!open) { showDeleteCanvasDialog = false; deleteCanvasTarget = null; } }}>
|
|
17686
|
-
<Dialog.Content class="confirm-delete-canvas-dialog-content max-w-sm bg-white z-9999">
|
|
18221
|
+
<Dialog.Content closeLabel={$t('creator.common.close')} class="confirm-delete-canvas-dialog-content max-w-sm bg-white z-9999">
|
|
17687
18222
|
<Dialog.Header class="confirm-delete-canvas-dialog-header">
|
|
17688
|
-
<Dialog.Title>
|
|
18223
|
+
<Dialog.Title>{$t('creator.canvas.deleteCanvas')}</Dialog.Title>
|
|
17689
18224
|
<Dialog.Description>
|
|
17690
|
-
|
|
18225
|
+
{#each sentenceParts('creator.dialog.deleteCanvas', ['name'], $t) as part}
|
|
18226
|
+
{#if 'text' in part}{part.text}{:else}<strong>"{deleteCanvasTarget?.name || ''}"</strong>{/if}
|
|
18227
|
+
{/each}
|
|
17691
18228
|
</Dialog.Description>
|
|
17692
18229
|
</Dialog.Header>
|
|
17693
18230
|
|
|
17694
18231
|
{#if deleteCanvasPreviewLoading}
|
|
17695
18232
|
<p class="confirm-delete-canvas-preview-loading text-sm text-gray-500 pt-2">
|
|
17696
|
-
|
|
18233
|
+
{$t('creator.general.checkingWhatWillBeDeleted')}
|
|
17697
18234
|
</p>
|
|
17698
18235
|
{:else if deleteCanvasPreview && deleteCanvasPreview.widgetCount > 0}
|
|
17699
18236
|
<div class="confirm-delete-canvas-preview pt-2">
|
|
17700
18237
|
<p class="text-sm text-gray-700">
|
|
17701
|
-
|
|
17702
|
-
<strong>{deleteCanvasPreview.widgetCount}</strong>
|
|
17703
|
-
{deleteCanvasPreview.widgetCount === 1 ? 'widget' : 'widgets'} on this canvas:
|
|
18238
|
+
{$t('creator.dialog.alsoDeleteWidgets', { count: deleteCanvasPreview.widgetCount })}
|
|
17704
18239
|
</p>
|
|
17705
18240
|
<ul class="confirm-delete-canvas-preview-groups mt-2 space-y-1.5 max-h-40 overflow-y-auto scrollbar-thin text-sm">
|
|
17706
18241
|
{#each deleteCanvasPreview.groups as group}
|
|
@@ -17715,7 +18250,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17715
18250
|
</ul>
|
|
17716
18251
|
{#if deleteCanvasPreview.groups.length > 1}
|
|
17717
18252
|
<p class="confirm-delete-canvas-preview-warning text-xs text-amber-700 mt-2">
|
|
17718
|
-
|
|
18253
|
+
{$t('creator.widget.theseWidgetsBelongToMore')}
|
|
17719
18254
|
</p>
|
|
17720
18255
|
{/if}
|
|
17721
18256
|
</div>
|
|
@@ -17730,12 +18265,12 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17730
18265
|
type="button"
|
|
17731
18266
|
class="px-4 py-2 text-sm rounded-lg border border-gray-300 hover:bg-gray-100 cursor-pointer"
|
|
17732
18267
|
onclick={() => { showDeleteCanvasDialog = false; deleteCanvasTarget = null; deleteCanvasError = ''; }}
|
|
17733
|
-
>
|
|
18268
|
+
>{$t('creator.general.cancel')}</button>
|
|
17734
18269
|
<button
|
|
17735
18270
|
type="button"
|
|
17736
18271
|
class="px-4 py-2 text-sm rounded-lg bg-red-600 hover:bg-red-700 text-white cursor-pointer"
|
|
17737
18272
|
onclick={handleDeleteCanvasConfirm}
|
|
17738
|
-
>
|
|
18273
|
+
>{$t('creator.common.delete')}</button>
|
|
17739
18274
|
</div>
|
|
17740
18275
|
</Dialog.Content>
|
|
17741
18276
|
</Dialog.Root>
|
|
@@ -17748,29 +18283,29 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17748
18283
|
if (!open) confirmGenerateWidgetId = null;
|
|
17749
18284
|
}}
|
|
17750
18285
|
>
|
|
17751
|
-
<Dialog.Content class="confirm-generate-dialog-content max-w-lg bg-white z-9999">
|
|
18286
|
+
<Dialog.Content closeLabel={$t('creator.common.close')} class="confirm-generate-dialog-content max-w-lg bg-white z-9999">
|
|
17752
18287
|
<Dialog.Header class="confirm-generate-dialog-header">
|
|
17753
|
-
<Dialog.Title>
|
|
18288
|
+
<Dialog.Title>{$t('creator.codegen.confirmCodeGeneration')}</Dialog.Title>
|
|
17754
18289
|
<Dialog.Description>
|
|
17755
18290
|
{promptImages.length > 0
|
|
17756
|
-
? '
|
|
17757
|
-
: '
|
|
18291
|
+
? $t('creator.codegen.reviewThePromptAndReference')
|
|
18292
|
+
: $t('creator.codegen.describeTheWidgetYouWant')}
|
|
17758
18293
|
</Dialog.Description>
|
|
17759
18294
|
</Dialog.Header>
|
|
17760
18295
|
<div class="flex flex-col gap-3 py-3 px-1">
|
|
17761
|
-
<div class="text-xs font-medium text-gray-500 uppercase tracking-wide">
|
|
18296
|
+
<div class="text-xs font-medium text-gray-500 uppercase tracking-wide">{$t('creator.codegen.prompt')}</div>
|
|
17762
18297
|
<textarea
|
|
17763
18298
|
bind:value={codeGenerationPrompt}
|
|
17764
18299
|
class="w-full min-h-[80px] max-h-[160px] rounded-md border border-gray-300 p-2 text-sm resize-y focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent"
|
|
17765
|
-
placeholder=
|
|
18300
|
+
placeholder={$t('creator.general.describeWhatYouWant')}
|
|
17766
18301
|
></textarea>
|
|
17767
18302
|
{#if promptImages.length > 0}
|
|
17768
|
-
<div class="text-xs font-medium text-gray-500 uppercase tracking-wide">
|
|
18303
|
+
<div class="text-xs font-medium text-gray-500 uppercase tracking-wide">{$t('creator.codegen.referenceImages', { count: promptImages.length })}</div>
|
|
17769
18304
|
<div class="flex gap-2 flex-wrap">
|
|
17770
18305
|
{#each promptImages as img, i}
|
|
17771
18306
|
<div class="relative">
|
|
17772
|
-
<span class="absolute top-0.5
|
|
17773
|
-
<img src={img} alt=
|
|
18307
|
+
<span class="absolute top-0.5 start-0.5 z-10 w-4 h-4 flex items-center justify-center rounded-full bg-blue-600 text-white text-[9px] font-bold shadow">{i + 1}</span>
|
|
18308
|
+
<img src={img} alt={$t('creator.codegen.referenceNumber', { number: i + 1 })} class="w-16 h-16 rounded border border-gray-200 object-cover" />
|
|
17774
18309
|
</div>
|
|
17775
18310
|
{/each}
|
|
17776
18311
|
</div>
|
|
@@ -17781,7 +18316,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17781
18316
|
confirmGenerateDialogOpen = false;
|
|
17782
18317
|
syncPromptToChatDraft();
|
|
17783
18318
|
}}>
|
|
17784
|
-
|
|
18319
|
+
{$t('creator.codegen.editPromptFirst')}
|
|
17785
18320
|
</Button>
|
|
17786
18321
|
<Button variant="default" size="sm" onclick={() => {
|
|
17787
18322
|
const targetWidgetId = confirmGenerateWidgetId ?? selectedWidgetId ?? undefined;
|
|
@@ -17789,7 +18324,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17789
18324
|
confirmGenerateWidgetId = null;
|
|
17790
18325
|
generateCode({ widgetId: targetWidgetId });
|
|
17791
18326
|
}}>
|
|
17792
|
-
|
|
18327
|
+
{$t('creator.codegen.generateNow')}
|
|
17793
18328
|
</Button>
|
|
17794
18329
|
</div>
|
|
17795
18330
|
</Dialog.Content>
|