@hkdigital/lib-sveltekit 0.1.20 → 0.1.21

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.
@@ -25,6 +25,13 @@ export class PresenterState {
25
25
  busy: boolean;
26
26
  /** @type {string} */
27
27
  currentSlideName: string;
28
+ /**
29
+ * Returns a simplified presenter reference with essential methods
30
+ * for slide components to use
31
+ *
32
+ * @returns {PresenterRef} A reference object with presenter methods
33
+ */
34
+ getPresenterRef(): PresenterRef;
28
35
  /**
29
36
  * Mark the slide as loaded, which triggers transitions to begin
30
37
  */
@@ -80,4 +87,14 @@ export type LoadController = {
80
87
  */
81
88
  cancel: () => void;
82
89
  };
90
+ export type PresenterRef = {
91
+ /**
92
+ * - Navigate to a slide by name
93
+ */
94
+ gotoSlide: (name: string) => void;
95
+ /**
96
+ * - Get the current slide name
97
+ */
98
+ getCurrentSlideName: () => string;
99
+ };
83
100
  import { HkPromise } from '../../classes/promise/index.js';
@@ -26,6 +26,12 @@ import { HkPromise } from '../../classes/promise/index.js';
26
26
  * @property {() => void} cancel - Function to return to the previous slide
27
27
  */
28
28
 
29
+ /**
30
+ * @typedef {Object} PresenterRef
31
+ * @property {(name: string) => void} gotoSlide - Navigate to a slide by name
32
+ * @property {() => string} getCurrentSlideName - Get the current slide name
33
+ */
34
+
29
35
  /* -------------------------------------------------------------- Constants */
30
36
 
31
37
  const Z_BACK = 0;
@@ -96,6 +102,19 @@ export class PresenterState {
96
102
  this.#setupLoadingTransitions();
97
103
  }
98
104
 
105
+ /**
106
+ * Returns a simplified presenter reference with essential methods
107
+ * for slide components to use
108
+ *
109
+ * @returns {PresenterRef} A reference object with presenter methods
110
+ */
111
+ getPresenterRef() {
112
+ return {
113
+ gotoSlide: (name) => this.gotoSlide(name),
114
+ getCurrentSlideName: () => this.currentSlideName
115
+ };
116
+ }
117
+
99
118
  /**
100
119
  * Set up reactivity for stage transitions between the before/after states
101
120
  * This handles the animation timing for both layers
@@ -358,27 +377,31 @@ export class PresenterState {
358
377
 
359
378
  // Add controller function to slide props if it has a component
360
379
  if (slide.data?.component) {
380
+ // Get a presenter reference to pass to the slide
381
+ const presenterRef = this.getPresenterRef();
382
+
361
383
  // Create a copy of the slide to avoid mutating the original
362
- const slideWithController = {
384
+ const slideWithExtras = {
363
385
  ...slide,
364
386
  data: {
365
387
  ...slide.data,
366
388
  props: {
367
389
  ...(slide.data.props || {}),
368
- getLoadingController: () => this.getLoadingController()
390
+ getLoadingController: () => this.getLoadingController(),
391
+ presenter: presenterRef // Add presenter reference to props
369
392
  }
370
393
  }
371
394
  };
372
395
 
373
- // Add next slide to next layer with controller included
374
- this.#updateSlide(this.nextLayerLabel, slideWithController);
396
+ // Add next slide to next layer with controller and presenter included
397
+ this.#updateSlide(this.nextLayerLabel, slideWithExtras);
375
398
 
376
399
  // If a timeout is configured, automatically finish loading after delay
377
400
  if (this.loadingTimeout > 0) {
378
401
  setTimeout(() => {
379
402
  // Only auto-finish if the controller wasn't requested
380
403
  if (!this.controllerRequested && this.isSlideLoading) {
381
- // console.log(
404
+ // console.debug(
382
405
  // `Slide '${slide.name}' didn't request loading controller, auto-finishing.`
383
406
  // );
384
407
  this.finishSlideLoading();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"