@panyam/tsappkit 0.7.4 → 0.7.5

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.
package/dist/index.d.mts CHANGED
@@ -760,6 +760,45 @@ declare class MobileBottomDrawer extends BaseComponent implements LCMComponent {
760
760
  getContentContainer(): HTMLElement;
761
761
  }
762
762
 
763
+ /**
764
+ * The views a presenter drives through one typed view interface, its "port"
765
+ * (docs/PRESENTER_CONTRACT_THESIS.md, Principle 3). A presenter keeps one Port
766
+ * per interface it talks to, so one presenter can drive several islands on a
767
+ * page without an EventBus or a store between them:
768
+ *
769
+ * readonly tools = new Port<ToolsView>((v) => v.setToolState(this.state));
770
+ * select(t: Tool) { this.state = ...; this.tools.each((v) => v.setToolState(this.state)); }
771
+ *
772
+ * Islands mount at different times (a `visible` one may mount long after the
773
+ * page started), so a view attached late has missed every command sent so far.
774
+ * The replay passed to the constructor runs on each view as it attaches and
775
+ * should send the presenter's current state, which is how a late view catches
776
+ * up. A port takes any number of views, including none: commands to an empty
777
+ * port go nowhere.
778
+ */
779
+ declare class Port<V> {
780
+ private readonly replay?;
781
+ private readonly views;
782
+ /** @param replay runs on each view as it attaches, to bring it up to date. */
783
+ constructor(replay?: ((view: V) => void) | undefined);
784
+ /**
785
+ * Adds a view, runs the replay on it, and returns the function that removes
786
+ * it again. An island attaches when it activates and detaches when it
787
+ * deactivates (tsappkit-solid's useView does both). Attaching the same view
788
+ * twice keeps one copy, and calling the returned function more than once is
789
+ * harmless.
790
+ */
791
+ attach(view: V): () => void;
792
+ /**
793
+ * Sends a command to every view attached when it's called, in the order they
794
+ * attached. A view may detach (or attach another) from inside the command.
795
+ * A view that throws stops the command reaching the views after it.
796
+ */
797
+ each(send: (view: V) => void): void;
798
+ /** How many views are attached. */
799
+ get size(): number;
800
+ }
801
+
763
802
  /**
764
803
  * When an island mounts: its `load` in the page spec (goapplib's
765
804
  * page.Island.Load), read and waited for. Every strategy mounts once; an
@@ -1098,4 +1137,4 @@ declare class KeyboardShortcutManager {
1098
1137
  getCurrentArgs(): string;
1099
1138
  }
1100
1139
 
1101
- export { BaseComponent, BasePage, type Component, type ComponentEventType, ComponentEventTypes, type ComponentLifecycleEvent, EventBus, type EventHandler, type EventSubscriber, type IslandFactory, IslandOverlay, IslandPage, type IslandSpec, KeyboardShortcutManager, KeyboardState, type LCMComponent, type LCMComponentConfig, type LCMComponentEvent, type LazyIsland, LifecycleController, type LifecycleEventType, LifecycleEventTypes, type LoadEnv, type LoadStrategy, MobileBottomDrawer, Modal, type MountOptions, type PageSpec, type Registry, SPEC_ELEMENT_ID, type ShortcutConfig, type ShortcutManagerConfig, type SpecExtension, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, lazy, mountIslands, parseLoad, readSpec, scheduleMount, shouldIgnoreShortcut };
1140
+ export { BaseComponent, BasePage, type Component, type ComponentEventType, ComponentEventTypes, type ComponentLifecycleEvent, EventBus, type EventHandler, type EventSubscriber, type IslandFactory, IslandOverlay, IslandPage, type IslandSpec, KeyboardShortcutManager, KeyboardState, type LCMComponent, type LCMComponentConfig, type LCMComponentEvent, type LazyIsland, LifecycleController, type LifecycleEventType, LifecycleEventTypes, type LoadEnv, type LoadStrategy, MobileBottomDrawer, Modal, type MountOptions, type PageSpec, Port, type Registry, SPEC_ELEMENT_ID, type ShortcutConfig, type ShortcutManagerConfig, type SpecExtension, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, lazy, mountIslands, parseLoad, readSpec, scheduleMount, shouldIgnoreShortcut };
package/dist/index.d.ts CHANGED
@@ -760,6 +760,45 @@ declare class MobileBottomDrawer extends BaseComponent implements LCMComponent {
760
760
  getContentContainer(): HTMLElement;
761
761
  }
762
762
 
763
+ /**
764
+ * The views a presenter drives through one typed view interface, its "port"
765
+ * (docs/PRESENTER_CONTRACT_THESIS.md, Principle 3). A presenter keeps one Port
766
+ * per interface it talks to, so one presenter can drive several islands on a
767
+ * page without an EventBus or a store between them:
768
+ *
769
+ * readonly tools = new Port<ToolsView>((v) => v.setToolState(this.state));
770
+ * select(t: Tool) { this.state = ...; this.tools.each((v) => v.setToolState(this.state)); }
771
+ *
772
+ * Islands mount at different times (a `visible` one may mount long after the
773
+ * page started), so a view attached late has missed every command sent so far.
774
+ * The replay passed to the constructor runs on each view as it attaches and
775
+ * should send the presenter's current state, which is how a late view catches
776
+ * up. A port takes any number of views, including none: commands to an empty
777
+ * port go nowhere.
778
+ */
779
+ declare class Port<V> {
780
+ private readonly replay?;
781
+ private readonly views;
782
+ /** @param replay runs on each view as it attaches, to bring it up to date. */
783
+ constructor(replay?: ((view: V) => void) | undefined);
784
+ /**
785
+ * Adds a view, runs the replay on it, and returns the function that removes
786
+ * it again. An island attaches when it activates and detaches when it
787
+ * deactivates (tsappkit-solid's useView does both). Attaching the same view
788
+ * twice keeps one copy, and calling the returned function more than once is
789
+ * harmless.
790
+ */
791
+ attach(view: V): () => void;
792
+ /**
793
+ * Sends a command to every view attached when it's called, in the order they
794
+ * attached. A view may detach (or attach another) from inside the command.
795
+ * A view that throws stops the command reaching the views after it.
796
+ */
797
+ each(send: (view: V) => void): void;
798
+ /** How many views are attached. */
799
+ get size(): number;
800
+ }
801
+
763
802
  /**
764
803
  * When an island mounts: its `load` in the page spec (goapplib's
765
804
  * page.Island.Load), read and waited for. Every strategy mounts once; an
@@ -1098,4 +1137,4 @@ declare class KeyboardShortcutManager {
1098
1137
  getCurrentArgs(): string;
1099
1138
  }
1100
1139
 
1101
- export { BaseComponent, BasePage, type Component, type ComponentEventType, ComponentEventTypes, type ComponentLifecycleEvent, EventBus, type EventHandler, type EventSubscriber, type IslandFactory, IslandOverlay, IslandPage, type IslandSpec, KeyboardShortcutManager, KeyboardState, type LCMComponent, type LCMComponentConfig, type LCMComponentEvent, type LazyIsland, LifecycleController, type LifecycleEventType, LifecycleEventTypes, type LoadEnv, type LoadStrategy, MobileBottomDrawer, Modal, type MountOptions, type PageSpec, type Registry, SPEC_ELEMENT_ID, type ShortcutConfig, type ShortcutManagerConfig, type SpecExtension, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, lazy, mountIslands, parseLoad, readSpec, scheduleMount, shouldIgnoreShortcut };
1140
+ export { BaseComponent, BasePage, type Component, type ComponentEventType, ComponentEventTypes, type ComponentLifecycleEvent, EventBus, type EventHandler, type EventSubscriber, type IslandFactory, IslandOverlay, IslandPage, type IslandSpec, KeyboardShortcutManager, KeyboardState, type LCMComponent, type LCMComponentConfig, type LCMComponentEvent, type LazyIsland, LifecycleController, type LifecycleEventType, LifecycleEventTypes, type LoadEnv, type LoadStrategy, MobileBottomDrawer, Modal, type MountOptions, type PageSpec, Port, type Registry, SPEC_ELEMENT_ID, type ShortcutConfig, type ShortcutManagerConfig, type SpecExtension, SplashScreen, TemplateLoader, ThemeManager, ToastManager, hasModifierKeys, isInInputContext, lazy, mountIslands, parseLoad, readSpec, scheduleMount, shouldIgnoreShortcut };
package/dist/index.js CHANGED
@@ -1373,6 +1373,41 @@ var MobileBottomDrawer = class extends BaseComponent {
1373
1373
  }
1374
1374
  };
1375
1375
 
1376
+ // src/Port.ts
1377
+ var Port = class {
1378
+ /** @param replay runs on each view as it attaches, to bring it up to date. */
1379
+ constructor(replay) {
1380
+ this.replay = replay;
1381
+ this.views = /* @__PURE__ */ new Set();
1382
+ }
1383
+ /**
1384
+ * Adds a view, runs the replay on it, and returns the function that removes
1385
+ * it again. An island attaches when it activates and detaches when it
1386
+ * deactivates (tsappkit-solid's useView does both). Attaching the same view
1387
+ * twice keeps one copy, and calling the returned function more than once is
1388
+ * harmless.
1389
+ */
1390
+ attach(view) {
1391
+ this.views.add(view);
1392
+ this.replay?.(view);
1393
+ return () => {
1394
+ this.views.delete(view);
1395
+ };
1396
+ }
1397
+ /**
1398
+ * Sends a command to every view attached when it's called, in the order they
1399
+ * attached. A view may detach (or attach another) from inside the command.
1400
+ * A view that throws stops the command reaching the views after it.
1401
+ */
1402
+ each(send) {
1403
+ for (const view of [...this.views]) send(view);
1404
+ }
1405
+ /** How many views are attached. */
1406
+ get size() {
1407
+ return this.views.size;
1408
+ }
1409
+ };
1410
+
1376
1411
  // src/page/load.ts
1377
1412
  function parseLoad(load) {
1378
1413
  switch (load ?? "") {
@@ -1993,6 +2028,7 @@ exports.LifecycleController = LifecycleController;
1993
2028
  exports.LifecycleEventTypes = LifecycleEventTypes;
1994
2029
  exports.MobileBottomDrawer = MobileBottomDrawer;
1995
2030
  exports.Modal = Modal;
2031
+ exports.Port = Port;
1996
2032
  exports.SPEC_ELEMENT_ID = SPEC_ELEMENT_ID;
1997
2033
  exports.SplashScreen = SplashScreen;
1998
2034
  exports.TemplateLoader = TemplateLoader;