wyreframe 0.2.2 → 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.
@@ -48,6 +48,14 @@ module DomBindings = {
48
48
  // Render Options
49
49
  // ============================================================================
50
50
 
51
+ /**
52
+ * Scene change callback type.
53
+ * Called when navigating between scenes.
54
+ * @param fromScene The scene ID navigating from (None if initial)
55
+ * @param toScene The scene ID navigating to
56
+ */
57
+ type onSceneChangeCallback = (option<string>, string) => unit
58
+
51
59
  /**
52
60
  * Configuration for the rendering process.
53
61
  */
@@ -56,6 +64,7 @@ type renderOptions = {
56
64
  interactive: bool,
57
65
  injectStyles: bool,
58
66
  containerClass: option<string>,
67
+ onSceneChange: option<onSceneChangeCallback>,
59
68
  }
60
69
 
61
70
  /**
@@ -66,6 +75,7 @@ let defaultOptions: renderOptions = {
66
75
  interactive: true,
67
76
  injectStyles: true,
68
77
  containerClass: None,
78
+ onSceneChange: None,
69
79
  }
70
80
 
71
81
  // ============================================================================
@@ -418,14 +428,27 @@ let renderScene = (scene: scene, ~onAction: option<actionHandler>=?): DomBinding
418
428
  // Scene Manager Implementation
419
429
  // ============================================================================
420
430
 
421
- let createSceneManager = (scenes: Map.t<string, DomBindings.element>): sceneManager => {
431
+ let createSceneManager = (
432
+ scenes: Map.t<string, DomBindings.element>,
433
+ ~onSceneChange: option<onSceneChangeCallback>=?,
434
+ ): sceneManager => {
422
435
  let currentScene = ref(None)
423
436
  let historyStack: ref<array<string>> = ref([])
424
437
  let forwardStack: ref<array<string>> = ref([])
425
438
 
439
+ // Helper to call onSceneChange callback if provided
440
+ let notifySceneChange = (fromScene: option<string>, toScene: string): unit => {
441
+ switch onSceneChange {
442
+ | Some(callback) => callback(fromScene, toScene)
443
+ | None => ()
444
+ }
445
+ }
446
+
426
447
  // Internal function to switch scenes without affecting history
427
- let switchToScene = (id: string): unit => {
428
- switch currentScene.contents {
448
+ let switchToScene = (id: string, ~notify: bool=true): unit => {
449
+ let previousScene = currentScene.contents
450
+
451
+ switch previousScene {
429
452
  | Some(currentId) => {
430
453
  switch scenes->Map.get(currentId) {
431
454
  | Some(el) => el->DomBindings.classList->DomBindings.remove("active")
@@ -439,6 +462,13 @@ let createSceneManager = (scenes: Map.t<string, DomBindings.element>): sceneMana
439
462
  | Some(el) => {
440
463
  el->DomBindings.classList->DomBindings.add("active")
441
464
  currentScene := Some(id)
465
+ // Notify callback if enabled and scene actually changed
466
+ if notify {
467
+ switch previousScene {
468
+ | Some(prevId) if prevId == id => () // Same scene, no notification
469
+ | _ => notifySceneChange(previousScene, id)
470
+ }
471
+ }
442
472
  }
443
473
  | None => ()
444
474
  }
@@ -634,7 +664,7 @@ let render = (ast: ast, options: option<renderOptions>): renderResult => {
634
664
  sceneMap->Map.set(scene.id, sceneEl)
635
665
  })
636
666
 
637
- let manager = createSceneManager(sceneMap)
667
+ let manager = createSceneManager(sceneMap, ~onSceneChange=?opts.onSceneChange)
638
668
 
639
669
  // Now that sceneManager is created, set the refs
640
670
  gotoRef := Some(manager.goto)