dynim-core 1.0.6 → 1.0.7

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.
@@ -23,6 +23,8 @@ export interface BuilderConfig {
23
23
  }>;
24
24
  /** External CodeClient to use (shares state with parent) - if not provided, creates its own */
25
25
  codeClient?: CodeClient;
26
+ /** Function to load a bundle URL (typically bundleManager.load) */
27
+ loadBundle?: (bundleUrl: string) => Promise<void>;
26
28
  }
27
29
  export interface Builder {
28
30
  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,CAAC,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,+FAA+F;IAC/F,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,Q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AE,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,CAoejE;;;;AAMD,wBAAyC"}
@@ -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, 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,29 @@ export function createBuilder(config = {}) {
304
319
  if (!isActive)
305
320
  return;
306
321
  isActive = false;
307
- // Notify server of exit
322
+ // Step 1: Abandon temp edits on server
323
+ if (client) {
324
+ try {
325
+ await client.abandonCode();
326
+ console.log('[Builder] Temp edits abandoned');
327
+ // Step 2: Load permanent bundle (now that temp edits are gone)
328
+ if (loadBundle) {
329
+ const savedBundleUrl = `${apiBase}/api/code/bundle`;
330
+ console.log('[Builder] Loading permanent bundle:', savedBundleUrl);
331
+ try {
332
+ await loadBundle(savedBundleUrl);
333
+ console.log('[Builder] Permanent bundle loaded');
334
+ }
335
+ catch (bundleError) {
336
+ console.error('[Builder] Failed to load permanent bundle:', bundleError);
337
+ }
338
+ }
339
+ }
340
+ catch (error) {
341
+ console.error('[Builder] Exit/abandon failed:', error);
342
+ }
343
+ }
344
+ // Step 3: Notify server (optional additional cleanup)
308
345
  if (builderClient) {
309
346
  try {
310
347
  await builderClient.exit(pageId, true);
@@ -314,6 +351,7 @@ export function createBuilder(config = {}) {
314
351
  console.error('[Builder] Exit notification failed:', error);
315
352
  }
316
353
  }
354
+ // Step 4: Cleanup UI
317
355
  cleanup();
318
356
  }
319
357
  async function handlePreview() {
@@ -341,22 +379,23 @@ export function createBuilder(config = {}) {
341
379
  try {
342
380
  console.log('[Builder] Saving code edits...');
343
381
  await client.saveCode();
344
- console.log('[Builder] Save complete');
345
- // Visual feedback - briefly show saved state
346
- const saveBtn = root.querySelector('.builder-bar__btn--save');
347
- if (saveBtn) {
348
- saveBtn.classList.add('builder-bar__btn--saved');
349
- saveBtn.textContent = 'Saved!';
350
- setTimeout(() => {
351
- saveBtn.classList.remove('builder-bar__btn--saved');
352
- saveBtn.innerHTML = `
353
- <svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
354
- <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/>
355
- </svg>
356
- Save
357
- `;
358
- }, 2000);
382
+ console.log('[Builder] Save complete - exiting builder');
383
+ // After save, the current bundle IS the permanent state
384
+ // Skip abandon/reload and just cleanup UI
385
+ if (!isActive)
386
+ return;
387
+ isActive = false;
388
+ // Notify server of exit (no discard since we saved)
389
+ if (builderClient) {
390
+ try {
391
+ await builderClient.exit(pageId, false);
392
+ console.log('[Builder] Exit notification sent');
393
+ }
394
+ catch (error) {
395
+ console.error('[Builder] Exit notification failed:', error);
396
+ }
359
397
  }
398
+ cleanup();
360
399
  }
361
400
  catch (error) {
362
401
  console.error('[Builder] Save failed:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynim-core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",