@buffcore/app-shell 0.8.42 → 0.8.44

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.
@@ -12,8 +12,8 @@ import { useT } from '@buffcore/i18n/react';
12
12
  import { Button, Text } from '@buffcore/ui';
13
13
  import { useRef, useState } from 'react';
14
14
  import { Platform, useWindowDimensions, View } from 'react-native';
15
- import { prototypeNavigation, studioPreview } from './home-bridge.js';
16
- import { usePrototypeReady } from './home-discovery.js';
15
+ import { previewSeed, prototypeNavigation, studioPreview } from './home-bridge.js';
16
+ import { usePrototypePlayer, usePrototypeReady } from './home-discovery.js';
17
17
  import { applyStep, journeyLook, replayJourney } from './home-journey.js';
18
18
  import { HomePanel } from './home-panel.js';
19
19
  import { EmbeddedPlayer } from './home-player.js';
@@ -85,6 +85,32 @@ export function PrototypeHome({ product, locales, states, previewStates, journey
85
85
  setPlay({ key: journey.key, step });
86
86
  onLook(journeyLook(baseLook.current, journey, step));
87
87
  };
88
+ // The studio's preview player: a step or a data choice, shown at once without a reload.
89
+ // A data choice and another journey both start from the look before any journey changed it.
90
+ const resting = useRef(look);
91
+ if (!play)
92
+ resting.current = look;
93
+ const showLook = (next) => {
94
+ if (next.mode !== look.mode || next.locale !== look.locale || next.scale !== look.scale)
95
+ onLook(next);
96
+ };
97
+ usePrototypePlayer(parentPlayer, (choice) => {
98
+ if (!('journey' in choice)) {
99
+ const seeded = 'data' in choice && previewSeed(states, previewStates, choice.data);
100
+ restart(seeded || start);
101
+ return showLook(resting.current);
102
+ }
103
+ const journey = journeys.find((candidate) => candidate.key === choice.journey);
104
+ if (!journey)
105
+ return;
106
+ const step = choice.step < journey.steps.length ? choice.step : 0;
107
+ if (play?.key !== journey.key)
108
+ baseLook.current = resting.current;
109
+ setStarted(journey.base);
110
+ setPage(replayJourney(seed(journey.base), journey, step, reduce));
111
+ setPlay({ key: journey.key, step });
112
+ showLook(journeyLook(baseLook.current, journey, step));
113
+ });
88
114
  const takeOver = () => {
89
115
  setPlay(null);
90
116
  setDrawer(false);
@@ -1,3 +1,4 @@
1
+ import { type PrototypeShow } from './home-show.ts';
1
2
  /** Strict, small request schema; no actions or credentials, only an echoed document challenge. */
2
3
  export declare function prototypeChallenge(event: MessageEvent, expected: {
3
4
  origin: string;
@@ -14,6 +15,8 @@ export type PrototypeInbox = {
14
15
  nonce?: string;
15
16
  counter: number;
16
17
  reply?: (nonce: string) => void;
18
+ /** The studio's preview player: what to show, read from this document's private port only. */
19
+ show?: (choice: PrototypeShow) => void;
17
20
  close: () => void;
18
21
  };
19
22
  /** Private module memory only; a hello transfers a port owned by this document, never stored on Window or in storage. */
@@ -1,4 +1,5 @@
1
1
  import { prototypeNavigation, prototypeStudioOrigin } from './home-bridge.js';
2
+ import { prototypeShow } from './home-show.js';
2
3
  /** Strict, small request schema; no actions or credentials, only an echoed document challenge. */
3
4
  export function prototypeChallenge(event, expected) {
4
5
  if (event.origin === 'null' ||
@@ -68,6 +69,11 @@ export function prototypeInbox() {
68
69
  next.counter = 0;
69
70
  next.reply?.(nonce);
70
71
  };
72
+ channel.port1.onmessage = (event) => {
73
+ const choice = prototypeShow(event.data, next);
74
+ if (choice)
75
+ next.show?.(choice);
76
+ };
71
77
  window.addEventListener('message', receive);
72
78
  window.addEventListener('pagehide', next.close);
73
79
  inbox = next;
@@ -1,4 +1,5 @@
1
1
  import type { T } from '@buffcore/i18n';
2
+ import type { PrototypeShow } from './home-show.ts';
2
3
  import type { PrototypeHomeState, PrototypePlay, PrototypePreviewData } from './home-types.ts';
3
4
  /** The current hello's port carries only public discovery and liveness; it grants no action. */
4
5
  export declare function usePrototypeReady<State extends string>(embedded: boolean, journeys: readonly {
@@ -9,3 +10,5 @@ export declare function usePrototypeReady<State extends string>(embedded: boolea
9
10
  caption: string;
10
11
  }[];
11
12
  }[], t: T, preview?: Partial<Record<PrototypePreviewData, State>>, states?: readonly PrototypeHomeState<State>[], play?: PrototypePlay | null): void;
13
+ /** While the studio's preview drives the player, take its show messages on the private port. */
14
+ export declare function usePrototypePlayer(enabled: boolean, onShow: (choice: PrototypeShow) => void): void;
@@ -1,4 +1,4 @@
1
- import { useLayoutEffect } from 'react';
1
+ import { useEffect, useLayoutEffect, useRef } from 'react';
2
2
  import { Platform } from 'react-native';
3
3
  import { previewData, previewSeed, readyMessage } from './home-bridge.js';
4
4
  import { prototypeInbox } from './home-challenge.js';
@@ -24,6 +24,14 @@ export function usePrototypeReady(embedded, journeys, t, preview, states, play)
24
24
  if (inbox.nonce !== nonce)
25
25
  return;
26
26
  stop();
27
+ // In the studio's preview, first say this home plays the studio's show messages.
28
+ if (preview)
29
+ inbox.port.postMessage(JSON.stringify({
30
+ type: 'ape:prototype:player',
31
+ version: 2,
32
+ navigation: inbox.navigation,
33
+ document: nonce,
34
+ }));
27
35
  inbox.port.postMessage(message);
28
36
  stop = watchPrototypeHeartbeat(inbox, nonce);
29
37
  };
@@ -37,3 +45,21 @@ export function usePrototypeReady(embedded, journeys, t, preview, states, play)
37
45
  };
38
46
  }, [embedded, journeys, t, preview, states, play]);
39
47
  }
48
+ /** While the studio's preview drives the player, take its show messages on the private port. */
49
+ export function usePrototypePlayer(enabled, onShow) {
50
+ const latest = useRef(onShow);
51
+ latest.current = onShow;
52
+ useEffect(() => {
53
+ if (Platform.OS !== 'web' || !enabled)
54
+ return;
55
+ const inbox = prototypeInbox();
56
+ if (!inbox)
57
+ return;
58
+ const show = (choice) => latest.current(choice);
59
+ inbox.show = show;
60
+ return () => {
61
+ if (inbox.show === show)
62
+ inbox.show = undefined;
63
+ };
64
+ }, [enabled]);
65
+ }
@@ -0,0 +1,17 @@
1
+ import type { PrototypePreviewData } from './home-types.ts';
2
+ export type PrototypeShow = {
3
+ journey: string;
4
+ step: number;
5
+ } | {
6
+ data: PrototypePreviewData;
7
+ } | Record<string, never>;
8
+ /**
9
+ * One show message, read strictly: it arrives only on this document's private port (the studio's
10
+ * end of the hello), names the current navigation and document nonce, and carries a journey key
11
+ * with a step, or a preview data state, or neither (the app as it starts). It grants no action:
12
+ * the app only replays its own journeys and seeds, as its panel already does.
13
+ */
14
+ export declare function prototypeShow(data: unknown, expected: {
15
+ navigation: string;
16
+ nonce?: string;
17
+ }): PrototypeShow | undefined;
@@ -0,0 +1,49 @@
1
+ // The studio's preview tells the running app which journey step, or which sample data, to show,
2
+ // so a step never reloads the app. Development only, like the rest of the prototype home.
3
+ import { previewData } from './home-bridge.js';
4
+ const keys = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/;
5
+ const allowed = new Set(['type', 'version', 'navigation', 'document', 'journey', 'step', 'data']);
6
+ /**
7
+ * One show message, read strictly: it arrives only on this document's private port (the studio's
8
+ * end of the hello), names the current navigation and document nonce, and carries a journey key
9
+ * with a step, or a preview data state, or neither (the app as it starts). It grants no action:
10
+ * the app only replays its own journeys and seeds, as its panel already does.
11
+ */
12
+ export function prototypeShow(data, expected) {
13
+ if (typeof data !== 'string' || data.length > 512 || !expected.nonce)
14
+ return;
15
+ let value;
16
+ try {
17
+ value = JSON.parse(data);
18
+ }
19
+ catch {
20
+ return;
21
+ }
22
+ if (!value ||
23
+ typeof value !== 'object' ||
24
+ Array.isArray(value) ||
25
+ Object.keys(value).some((key) => !allowed.has(key)) ||
26
+ value.type !== 'ape:prototype:show' ||
27
+ value.version !== 2 ||
28
+ value.navigation !== expected.navigation ||
29
+ value.document !== expected.nonce)
30
+ return;
31
+ const { journey, step, data: seed } = value;
32
+ if (journey !== undefined) {
33
+ if (typeof journey !== 'string' ||
34
+ !keys.test(journey) ||
35
+ typeof step !== 'number' ||
36
+ !Number.isInteger(step) ||
37
+ step < 0 ||
38
+ step > 999 ||
39
+ seed !== undefined)
40
+ return;
41
+ return { journey, step };
42
+ }
43
+ if (step !== undefined)
44
+ return;
45
+ if (seed === undefined)
46
+ return {};
47
+ const choice = previewData.find((entry) => entry === seed);
48
+ return choice ? { data: choice } : undefined;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buffcore/app-shell",
3
- "version": "0.8.42",
3
+ "version": "0.8.44",
4
4
  "description": "The Expo app shell for a BuffCore product: sign-in, settings, themes, live sessions and push.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "BuffApe",
@@ -33,12 +33,12 @@
33
33
  "dependencies": {
34
34
  "@noble/hashes": "2.4.0",
35
35
  "firebase": "12.19.0",
36
- "@buffcore/config": "0.8.42",
37
- "@buffcore/contracts": "0.8.42",
38
- "@buffcore/i18n": "0.8.42",
39
- "@buffcore/tokens": "0.8.42",
40
- "@buffcore/sdk": "0.8.42",
41
- "@buffcore/ui": "0.8.42"
36
+ "@buffcore/config": "0.8.44",
37
+ "@buffcore/contracts": "0.8.44",
38
+ "@buffcore/i18n": "0.8.44",
39
+ "@buffcore/sdk": "0.8.44",
40
+ "@buffcore/ui": "0.8.44",
41
+ "@buffcore/tokens": "0.8.44"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@react-native-firebase/app": ">=26",
@@ -116,8 +116,8 @@
116
116
  "react-native-web": "0.21.4",
117
117
  "react-native-webview": "13.16.1",
118
118
  "zod": "4.6.5",
119
- "@buffcore/modules": "0.8.42",
120
- "@buffcore/server": "0.8.42"
119
+ "@buffcore/modules": "0.8.44",
120
+ "@buffcore/server": "0.8.44"
121
121
  },
122
122
  "scripts": {
123
123
  "build": "node ../../scripts/build-package.mjs",