dynim-core 1.0.6 → 1.0.9
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.
|
@@ -8,6 +8,8 @@ export interface BuilderConfig {
|
|
|
8
8
|
logo?: string;
|
|
9
9
|
onExit?: () => void;
|
|
10
10
|
onEnter?: () => void;
|
|
11
|
+
/** Called at the very start of exit, before any async work */
|
|
12
|
+
onExitStart?: () => void;
|
|
11
13
|
chatConfig?: WidgetConfig;
|
|
12
14
|
contentRoot?: HTMLElement;
|
|
13
15
|
pageId?: string;
|
|
@@ -23,6 +25,8 @@ export interface BuilderConfig {
|
|
|
23
25
|
}>;
|
|
24
26
|
/** External CodeClient to use (shares state with parent) - if not provided, creates its own */
|
|
25
27
|
codeClient?: CodeClient;
|
|
28
|
+
/** Function to load a bundle URL (typically bundleManager.load) */
|
|
29
|
+
loadBundle?: (bundleUrl: string) => Promise<void>;
|
|
26
30
|
}
|
|
27
31
|
export interface Builder {
|
|
28
32
|
enter: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/builder/builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAQxE,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,YAAY,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AClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,cAAc,EAAE,MAAM,OAAO,CAAC;IAC9B,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,MAAM,GAAE,aAAkB,GAAG,OAAO,CAyejE;;;;AAMD,wBAAyC"}
|
package/dist/builder/builder.js
CHANGED
|
@@ -15,7 +15,7 @@ import { createCodeClient } from './code-client';
|
|
|
15
15
|
import { createBuilderClient } from './builder-client';
|
|
16
16
|
import { buildElementIdentifier, getRelevantStyles } from './element-utils';
|
|
17
17
|
export function createBuilder(config = {}) {
|
|
18
|
-
const { logo = 'Builder', onExit, onEnter, chatConfig = {}, contentRoot = document.body, pageId = window.location.pathname, apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession, codeClient: externalCodeClient } = config;
|
|
18
|
+
const { logo = 'Builder', onExit, onEnter, onExitStart, chatConfig = {}, contentRoot = document.body, pageId = window.location.pathname, apiBase = 'http://localhost:8080', sessionToken, refreshToken, getSession, codeClient: externalCodeClient, loadBundle } = config;
|
|
19
19
|
let isActive = false;
|
|
20
20
|
let chatWidget = null;
|
|
21
21
|
let state = null;
|
|
@@ -44,7 +44,7 @@ export function createBuilder(config = {}) {
|
|
|
44
44
|
</svg>
|
|
45
45
|
Preview
|
|
46
46
|
</button>
|
|
47
|
-
<button class="builder-bar__btn builder-bar__btn--save">
|
|
47
|
+
<button class="builder-bar__btn builder-bar__btn--save" disabled>
|
|
48
48
|
<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
|
|
49
49
|
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/>
|
|
50
50
|
</svg>
|
|
@@ -62,6 +62,8 @@ export function createBuilder(config = {}) {
|
|
|
62
62
|
let builderClient = null;
|
|
63
63
|
// Track unsubscribe function for external client
|
|
64
64
|
let unsubscribeFromClient = null;
|
|
65
|
+
// Track unsubscribe function for bundleReady state
|
|
66
|
+
let unsubscribeCodeClient = null;
|
|
65
67
|
function initCodeClient(stateRef) {
|
|
66
68
|
// Handler for message updates (used by both internal and external client)
|
|
67
69
|
const handleMessageUpdate = (message) => {
|
|
@@ -247,6 +249,16 @@ export function createBuilder(config = {}) {
|
|
|
247
249
|
});
|
|
248
250
|
initCodeClient(state);
|
|
249
251
|
initBuilderClient();
|
|
252
|
+
// Subscribe to code client to track bundleReady state
|
|
253
|
+
if (client) {
|
|
254
|
+
unsubscribeCodeClient = client.onMessage((message) => {
|
|
255
|
+
const saveBtn = root.querySelector('.builder-bar__btn--save');
|
|
256
|
+
if (saveBtn) {
|
|
257
|
+
// Enable when bundleReady (changes exist to save)
|
|
258
|
+
saveBtn.disabled = !message.bundleReady;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
250
262
|
// Pre-warm the cache for faster chat responses (projectId comes from JWT)
|
|
251
263
|
if (client) {
|
|
252
264
|
client.warmCache();
|
|
@@ -294,6 +306,9 @@ export function createBuilder(config = {}) {
|
|
|
294
306
|
freezeOverlay = null;
|
|
295
307
|
editorState = null;
|
|
296
308
|
treeState = null;
|
|
309
|
+
// Cleanup bundleReady subscription
|
|
310
|
+
unsubscribeCodeClient?.();
|
|
311
|
+
unsubscribeCodeClient = null;
|
|
297
312
|
if (chatWidget) {
|
|
298
313
|
chatWidget.close();
|
|
299
314
|
chatWidget.root.style.display = 'none';
|
|
@@ -304,7 +319,32 @@ export function createBuilder(config = {}) {
|
|
|
304
319
|
if (!isActive)
|
|
305
320
|
return;
|
|
306
321
|
isActive = false;
|
|
307
|
-
// Notify
|
|
322
|
+
// Notify IMMEDIATELY before any async work
|
|
323
|
+
// This allows BuilderProvider to set isExitingRef before streaming events can interfere
|
|
324
|
+
onExitStart?.();
|
|
325
|
+
// Step 1: Abandon temp edits on server
|
|
326
|
+
if (client) {
|
|
327
|
+
try {
|
|
328
|
+
await client.abandonCode();
|
|
329
|
+
console.log('[Builder] Temp edits abandoned');
|
|
330
|
+
// Step 2: Load permanent bundle (now that temp edits are gone)
|
|
331
|
+
if (loadBundle) {
|
|
332
|
+
const savedBundleUrl = `${apiBase}/api/code/bundle`;
|
|
333
|
+
console.log('[Builder] Loading permanent bundle:', savedBundleUrl);
|
|
334
|
+
try {
|
|
335
|
+
await loadBundle(savedBundleUrl);
|
|
336
|
+
console.log('[Builder] Permanent bundle loaded');
|
|
337
|
+
}
|
|
338
|
+
catch (bundleError) {
|
|
339
|
+
console.error('[Builder] Failed to load permanent bundle:', bundleError);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
console.error('[Builder] Exit/abandon failed:', error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// Step 3: Notify server (optional additional cleanup)
|
|
308
348
|
if (builderClient) {
|
|
309
349
|
try {
|
|
310
350
|
await builderClient.exit(pageId, true);
|
|
@@ -314,6 +354,7 @@ export function createBuilder(config = {}) {
|
|
|
314
354
|
console.error('[Builder] Exit notification failed:', error);
|
|
315
355
|
}
|
|
316
356
|
}
|
|
357
|
+
// Step 4: Cleanup UI
|
|
317
358
|
cleanup();
|
|
318
359
|
}
|
|
319
360
|
async function handlePreview() {
|
|
@@ -341,22 +382,23 @@ export function createBuilder(config = {}) {
|
|
|
341
382
|
try {
|
|
342
383
|
console.log('[Builder] Saving code edits...');
|
|
343
384
|
await client.saveCode();
|
|
344
|
-
console.log('[Builder] Save complete');
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
385
|
+
console.log('[Builder] Save complete - exiting builder');
|
|
386
|
+
// After save, the current bundle IS the permanent state
|
|
387
|
+
// Skip abandon/reload and just cleanup UI
|
|
388
|
+
if (!isActive)
|
|
389
|
+
return;
|
|
390
|
+
isActive = false;
|
|
391
|
+
// Notify server of exit (no discard since we saved)
|
|
392
|
+
if (builderClient) {
|
|
393
|
+
try {
|
|
394
|
+
await builderClient.exit(pageId, false);
|
|
395
|
+
console.log('[Builder] Exit notification sent');
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
console.error('[Builder] Exit notification failed:', error);
|
|
399
|
+
}
|
|
359
400
|
}
|
|
401
|
+
cleanup();
|
|
360
402
|
}
|
|
361
403
|
catch (error) {
|
|
362
404
|
console.error('[Builder] Save failed:', error);
|