@phreshos/react 0.1.35 → 0.1.37

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.
@@ -52,7 +52,7 @@ function viewportState(desktop) {
52
52
  const publish = () => { const state = complete(); if (state)
53
53
  subscriber(state); };
54
54
  const stopResize = desktop.viewport.subscribe("resize", size => { latest = { ...latest, size }; publish(); });
55
- const stopMove = desktop.viewport.subscribe("move", offset => { latest = { ...latest, offset }; publish(); });
55
+ const stopMove = desktop.viewport.subscribe("move", move => { latest = { ...latest, offset: move.offset }; publish(); });
56
56
  return () => { stopResize(); stopMove(); };
57
57
  });
58
58
  }
package/dist/main.d.ts CHANGED
@@ -10,6 +10,7 @@ export { default as useEndpointState, type EndpointState } from "./use-endpoint-
10
10
  export { default as useServiceState, type ServiceState } from "./use-service-state.js";
11
11
  export { default as useWindowState } from "./use-window-state.js";
12
12
  export { default as usePresentationState } from "./use-presentation-state.js";
13
+ export { default as usePlaneState, type PlaneState } from "./use-plane-state.js";
13
14
  export { default as useClientMemory } from "./use-client-memory.js";
14
15
  export { default as useProgramStore } from "./use-program-store.js";
15
16
  export { default as useSubscribeAsks, type AskSubscribable } from "./use-subscribe-asks.js";
package/dist/main.js CHANGED
@@ -10,6 +10,7 @@ export { default as useEndpointState } from "./use-endpoint-state.js";
10
10
  export { default as useServiceState } from "./use-service-state.js";
11
11
  export { default as useWindowState } from "./use-window-state.js";
12
12
  export { default as usePresentationState } from "./use-presentation-state.js";
13
+ export { default as usePlaneState } from "./use-plane-state.js";
13
14
  export { default as useClientMemory } from "./use-client-memory.js";
14
15
  export { default as useProgramStore } from "./use-program-store.js";
15
16
  export { default as useSubscribeAsks } from "./use-subscribe-asks.js";
@@ -0,0 +1,7 @@
1
+ import type { DesktopPlaneSource, DesktopSize } from "@phreshos/core";
2
+ /** The plane of standard Windows one Desktop shows a view of. */
3
+ export type PlaneState = Readonly<{
4
+ size: DesktopSize;
5
+ }>;
6
+ /** Explicitly reads and follows the Desktop's plane while mounted: its size, which changes with the Desktop's. */
7
+ export default function usePlaneState(plane: DesktopPlaneSource): PlaneState | undefined;
@@ -0,0 +1,7 @@
1
+ import { useMemo, useSyncExternalStore } from "react";
2
+ import LiveState from "./live-state.js";
3
+ /** Explicitly reads and follows the Desktop's plane while mounted: its size, which changes with the Desktop's. */
4
+ export default function usePlaneState(plane) {
5
+ const state = useMemo(() => new LiveState(async () => ({ size: await plane.size() }), reduce => plane.subscribe("resize", size => reduce(current => ({ ...current, size })))), [plane]);
6
+ return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
7
+ }
@@ -3,15 +3,16 @@ import LiveState, { combineCleanups } from "./live-state.js";
3
3
  /** Explicitly reads and follows how the executing Client is drawn on its Desktop while mounted. */
4
4
  export default function usePresentationState(presentation) {
5
5
  const state = useMemo(() => new LiveState(async () => {
6
- const [layer, position, size, front, interactive, surface] = await Promise.all([
6
+ const [layer, anchor, position, size, front, interactive, surface] = await Promise.all([
7
7
  presentation.layer(),
8
+ presentation.anchor(),
8
9
  presentation.position(),
9
10
  presentation.size(),
10
11
  presentation.front(),
11
12
  presentation.interactive(),
12
13
  presentation.surface()
13
14
  ]);
14
- return { layer, position, size, front, interactive, surface };
15
- }, reduce => combineCleanups(presentation.subscribe("move", position => reduce(current => ({ ...current, position }))), presentation.subscribe("resize", size => reduce(current => ({ ...current, size }))), presentation.subscribe("front", front => reduce(current => ({ ...current, front }))), presentation.subscribe("changeInteractive", interactive => reduce(current => ({ ...current, interactive }))), presentation.subscribe("changeSurface", surface => reduce(current => ({ ...current, surface }))))), [presentation]);
15
+ return { layer, anchor, position, size, front, interactive, surface };
16
+ }, reduce => combineCleanups(presentation.subscribe("move", position => reduce(current => ({ ...current, position }))), presentation.subscribe("resize", size => reduce(current => ({ ...current, size }))), presentation.subscribe("front", front => reduce(current => ({ ...current, front }))), presentation.subscribe("changeInteractive", interactive => reduce(current => ({ ...current, interactive }))), presentation.subscribe("changeSurface", surface => reduce(current => ({ ...current, surface }))), presentation.subscribe("changeAnchor", anchor => reduce(current => ({ ...current, anchor }))))), [presentation]);
16
17
  return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/react",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "Runtime-neutral React adapters for PhreshOS contracts.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -46,11 +46,11 @@
46
46
  "prepack": "node --run build"
47
47
  },
48
48
  "peerDependencies": {
49
- "@phreshos/core": "^0.1.67",
49
+ "@phreshos/core": "^0.1.69",
50
50
  "react": "^19.2.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@phreshos/core": "^0.1.67",
53
+ "@phreshos/core": "^0.1.69",
54
54
  "@testing-library/dom": "^10.4.1",
55
55
  "@testing-library/react": "^16.3.0",
56
56
  "@types/react": "^19.2.18",