dynim-core 1.0.10 → 1.0.11

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.
@@ -32,6 +32,10 @@ export interface Builder {
32
32
  enter: () => void;
33
33
  exit: () => void;
34
34
  isActive: () => boolean;
35
+ isPreviewMode: () => boolean;
36
+ togglePreview: () => void;
37
+ enterPreviewMode: () => void;
38
+ exitPreviewMode: () => void;
35
39
  getEditorState: () => unknown;
36
40
  getTreeState: () => unknown;
37
41
  destroy: () => 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,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,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;IACxB,mEAAmE;IACnE,UAAU,CAAC,EAAE,CAAC,S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C;IACxB,mEAAmE;IACnE,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,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,CA0kBjE;;;;AAMD,wBAAyC"}
@@ -17,6 +17,7 @@ import { buildElementIdentifier, getRelevantStyles } from './element-utils';
17
17
  export function createBuilder(config = {}) {
18
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
+ let isPreviewMode = false;
20
21
  let chatWidget = null;
21
22
  let state = null;
22
23
  let client = null;
@@ -37,6 +38,12 @@ export function createBuilder(config = {}) {
37
38
  <span>${logo}</span>
38
39
  </div>
39
40
  <div class="builder-bar__divider"></div>
41
+ <span class="builder-bar__preview-badge" style="display: none;">
42
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
43
+ <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>
44
+ </svg>
45
+ PREVIEWING
46
+ </span>
40
47
  <div class="builder-bar__actions">
41
48
  <button class="builder-bar__btn builder-bar__btn--preview">
42
49
  <svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
@@ -318,6 +325,11 @@ export function createBuilder(config = {}) {
318
325
  async function exit() {
319
326
  if (!isActive)
320
327
  return;
328
+ // Exit preview mode first if active
329
+ if (isPreviewMode) {
330
+ isPreviewMode = false;
331
+ updateBarForPreviewMode(false);
332
+ }
321
333
  isActive = false;
322
334
  // Notify IMMEDIATELY before any async work
323
335
  // This allows BuilderProvider to set isExitingRef before streaming events can interfere
@@ -404,6 +416,71 @@ export function createBuilder(config = {}) {
404
416
  console.error('[Builder] Save failed:', error);
405
417
  }
406
418
  }
419
+ function updateBarForPreviewMode(isPreviewing) {
420
+ const previewBtn = root.querySelector('.builder-bar__btn--preview');
421
+ const previewBadge = root.querySelector('.builder-bar__preview-badge');
422
+ if (previewBtn) {
423
+ // Update button text while preserving the icon
424
+ const textNode = Array.from(previewBtn.childNodes).find(node => node.nodeType === Node.TEXT_NODE);
425
+ if (textNode) {
426
+ textNode.textContent = isPreviewing ? 'Edit' : 'Preview';
427
+ }
428
+ else {
429
+ // Fallback: append text if no text node found
430
+ previewBtn.appendChild(document.createTextNode(isPreviewing ? 'Edit' : 'Preview'));
431
+ }
432
+ }
433
+ if (previewBadge) {
434
+ previewBadge.style.display = isPreviewing ? 'flex' : 'none';
435
+ }
436
+ // Add/remove preview mode class for styling
437
+ root.classList.toggle('builder-bar--preview-mode', isPreviewing);
438
+ }
439
+ function enterPreviewMode() {
440
+ if (!isActive || isPreviewMode)
441
+ return;
442
+ isPreviewMode = true;
443
+ console.log('[Builder] Entering preview mode');
444
+ // Hide editing UI
445
+ freezeOverlay?.unmount();
446
+ overlays?.hideAll();
447
+ interactionEngine?.detach();
448
+ aiPromptPopover?.unmount();
449
+ // Hide chat
450
+ chatWidget?.close();
451
+ if (chatWidget?.root) {
452
+ chatWidget.root.style.display = 'none';
453
+ }
454
+ // Clear any selection
455
+ editorState?.clearSelection();
456
+ // Update bar UI
457
+ updateBarForPreviewMode(true);
458
+ }
459
+ function exitPreviewMode() {
460
+ if (!isActive || !isPreviewMode)
461
+ return;
462
+ isPreviewMode = false;
463
+ console.log('[Builder] Exiting preview mode');
464
+ // Restore editing UI
465
+ freezeOverlay?.mount();
466
+ overlays?.mount();
467
+ interactionEngine?.attach();
468
+ aiPromptPopover?.mount();
469
+ // Show chat
470
+ if (chatWidget?.root) {
471
+ chatWidget.root.style.display = '';
472
+ }
473
+ // Update bar UI
474
+ updateBarForPreviewMode(false);
475
+ }
476
+ function togglePreview() {
477
+ if (isPreviewMode) {
478
+ exitPreviewMode();
479
+ }
480
+ else {
481
+ enterPreviewMode();
482
+ }
483
+ }
407
484
  root.addEventListener('click', (e) => {
408
485
  const target = e.target;
409
486
  if (target.closest('.builder-bar__btn--exit')) {
@@ -413,7 +490,7 @@ export function createBuilder(config = {}) {
413
490
  }
414
491
  if (target.closest('.builder-bar__btn--preview')) {
415
492
  e.stopPropagation();
416
- handlePreview();
493
+ togglePreview();
417
494
  return;
418
495
  }
419
496
  if (target.closest('.builder-bar__btn--save')) {
@@ -435,6 +512,10 @@ export function createBuilder(config = {}) {
435
512
  enter,
436
513
  exit,
437
514
  isActive: () => isActive,
515
+ isPreviewMode: () => isPreviewMode,
516
+ togglePreview,
517
+ enterPreviewMode,
518
+ exitPreviewMode,
438
519
  getEditorState: () => editorState?.getState(),
439
520
  getTreeState: () => treeState?.getState(),
440
521
  destroy: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynim-core",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -70,6 +70,32 @@
70
70
  margin: 0 4px;
71
71
  }
72
72
 
73
+ /* Preview badge */
74
+ .builder-bar__preview-badge {
75
+ display: flex;
76
+ align-items: center;
77
+ gap: 6px;
78
+ padding: 4px 12px;
79
+ background: #3b82f6;
80
+ color: white;
81
+ border-radius: 4px;
82
+ font-size: 12px;
83
+ font-weight: 600;
84
+ text-transform: uppercase;
85
+ letter-spacing: 0.5px;
86
+ }
87
+
88
+ .builder-bar__preview-badge svg {
89
+ width: 14px;
90
+ height: 14px;
91
+ }
92
+
93
+ /* Preview mode bar styling */
94
+ .builder-bar--preview-mode .builder-bar {
95
+ background: linear-gradient(to right, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
96
+ border-bottom: 2px solid #3b82f6;
97
+ }
98
+
73
99
  /* Actions section */
74
100
  .builder-bar__actions {
75
101
  display: flex;