@buffcore/app-shell 0.8.43 → 0.8.45
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/prototype/home-app.js +28 -2
- package/dist/prototype/home-challenge.d.ts +3 -0
- package/dist/prototype/home-challenge.js +13 -0
- package/dist/prototype/home-discovery.d.ts +3 -0
- package/dist/prototype/home-discovery.js +27 -1
- package/dist/prototype/home-part.d.ts +49 -0
- package/dist/prototype/home-part.js +100 -0
- package/dist/prototype/home-show.d.ts +17 -0
- package/dist/prototype/home-show.js +49 -0
- package/package.json +9 -9
|
@@ -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,6 @@
|
|
|
1
1
|
import { prototypeNavigation, prototypeStudioOrigin } from './home-bridge.js';
|
|
2
|
+
import { partAnswer, partAt, prototypePartAsk } from './home-part.js';
|
|
3
|
+
import { prototypeShow } from './home-show.js';
|
|
2
4
|
/** Strict, small request schema; no actions or credentials, only an echoed document challenge. */
|
|
3
5
|
export function prototypeChallenge(event, expected) {
|
|
4
6
|
if (event.origin === 'null' ||
|
|
@@ -68,6 +70,17 @@ export function prototypeInbox() {
|
|
|
68
70
|
next.counter = 0;
|
|
69
71
|
next.reply?.(nonce);
|
|
70
72
|
};
|
|
73
|
+
channel.port1.onmessage = (event) => {
|
|
74
|
+
const ask = prototypePartAsk(event.data, next);
|
|
75
|
+
if (ask && next.nonce) {
|
|
76
|
+
const expected = { navigation: next.navigation, nonce: next.nonce };
|
|
77
|
+
next.port.postMessage(partAnswer(expected, ask, partAt(ask.x, ask.y)));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const choice = prototypeShow(event.data, next);
|
|
81
|
+
if (choice)
|
|
82
|
+
next.show?.(choice);
|
|
83
|
+
};
|
|
71
84
|
window.addEventListener('message', receive);
|
|
72
85
|
window.addEventListener('pagehide', next.close);
|
|
73
86
|
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,49 @@
|
|
|
1
|
+
export type PrototypePartAsk = {
|
|
2
|
+
ask: number;
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export type PrototypePart = {
|
|
7
|
+
name?: string;
|
|
8
|
+
box: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
w: number;
|
|
12
|
+
h: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type Point = {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* How far the page and its tallest scroller (the box a screen's content scrolls in) are scrolled,
|
|
21
|
+
* so a picture of this screen can be scrolled the same way. The studio's picture finds the scroller
|
|
22
|
+
* by the same rule.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scrolled(page?: Document): {
|
|
25
|
+
page: Point;
|
|
26
|
+
inner: Point;
|
|
27
|
+
};
|
|
28
|
+
/** A name is one short line: a label longer than this is not a part's name. */
|
|
29
|
+
export declare const PART_NAME = 80;
|
|
30
|
+
/**
|
|
31
|
+
* One part ask, read strictly: it arrives only on this document's private port (the studio's end
|
|
32
|
+
* of the hello), names the current navigation and document nonce, and carries an ask number and a
|
|
33
|
+
* point in the page. It grants nothing: the app only reads which element is drawn there.
|
|
34
|
+
*/
|
|
35
|
+
export declare function prototypePartAsk(data: unknown, expected: {
|
|
36
|
+
navigation: string;
|
|
37
|
+
nonce?: string;
|
|
38
|
+
}): PrototypePartAsk | undefined;
|
|
39
|
+
/** The nearest element at the point with a name, with its box; the element itself without one. */
|
|
40
|
+
export declare function partAt(x: number, y: number, page?: Document): PrototypePart | undefined;
|
|
41
|
+
/** The answer to one ask: the ask's number, the part's name and box, and how far it is scrolled. */
|
|
42
|
+
export declare function partAnswer(expected: {
|
|
43
|
+
navigation: string;
|
|
44
|
+
nonce: string;
|
|
45
|
+
}, ask: PrototypePartAsk, part: PrototypePart | undefined, scroll?: {
|
|
46
|
+
page: Point;
|
|
47
|
+
inner: Point;
|
|
48
|
+
}): string;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The studio's marking asks which part of the app is at a point, to name a comment ("Comment on
|
|
2
|
+
// Price"). Development only, like the rest of the prototype home. The answer carries the part's
|
|
3
|
+
// name (its accessible label or test id), its box and the scroll, never the app's data.
|
|
4
|
+
/**
|
|
5
|
+
* How far the page and its tallest scroller (the box a screen's content scrolls in) are scrolled,
|
|
6
|
+
* so a picture of this screen can be scrolled the same way. The studio's picture finds the scroller
|
|
7
|
+
* by the same rule.
|
|
8
|
+
*/
|
|
9
|
+
export function scrolled(page = document) {
|
|
10
|
+
const view = page.defaultView;
|
|
11
|
+
let inner;
|
|
12
|
+
let most = 0;
|
|
13
|
+
const all = page.body?.querySelectorAll('*') ?? [];
|
|
14
|
+
for (let i = 0; i < all.length && i < 20_000; i++) {
|
|
15
|
+
const el = all[i];
|
|
16
|
+
const room = el.scrollHeight - el.clientHeight;
|
|
17
|
+
if (room > most && /auto|scroll|overlay/.test(view?.getComputedStyle(el).overflowY ?? '')) {
|
|
18
|
+
most = room;
|
|
19
|
+
inner = el;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const whole = (value = 0) => Math.max(0, Math.round(value));
|
|
23
|
+
return {
|
|
24
|
+
page: { x: whole(view?.scrollX), y: whole(view?.scrollY) },
|
|
25
|
+
inner: { x: whole(inner?.scrollLeft), y: whole(inner?.scrollTop) },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const allowed = new Set(['type', 'version', 'navigation', 'document', 'ask', 'x', 'y']);
|
|
29
|
+
/** A name is one short line: a label longer than this is not a part's name. */
|
|
30
|
+
export const PART_NAME = 80;
|
|
31
|
+
const coordinate = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100_000;
|
|
32
|
+
/**
|
|
33
|
+
* One part ask, read strictly: it arrives only on this document's private port (the studio's end
|
|
34
|
+
* of the hello), names the current navigation and document nonce, and carries an ask number and a
|
|
35
|
+
* point in the page. It grants nothing: the app only reads which element is drawn there.
|
|
36
|
+
*/
|
|
37
|
+
export function prototypePartAsk(data, expected) {
|
|
38
|
+
if (typeof data !== 'string' || data.length > 512 || !expected.nonce)
|
|
39
|
+
return;
|
|
40
|
+
let value;
|
|
41
|
+
try {
|
|
42
|
+
value = JSON.parse(data);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!value ||
|
|
48
|
+
typeof value !== 'object' ||
|
|
49
|
+
Array.isArray(value) ||
|
|
50
|
+
Object.keys(value).some((key) => !allowed.has(key)) ||
|
|
51
|
+
value.type !== 'ape:prototype:part' ||
|
|
52
|
+
value.version !== 2 ||
|
|
53
|
+
value.navigation !== expected.navigation ||
|
|
54
|
+
value.document !== expected.nonce)
|
|
55
|
+
return;
|
|
56
|
+
const { ask, x, y } = value;
|
|
57
|
+
if (typeof ask !== 'number' || !Number.isInteger(ask) || ask < 1 || ask > 1_000_000)
|
|
58
|
+
return;
|
|
59
|
+
if (!coordinate(x) || !coordinate(y))
|
|
60
|
+
return;
|
|
61
|
+
return { ask, x, y };
|
|
62
|
+
}
|
|
63
|
+
/** The part's own name: its accessible label, else its test id in words; else none. */
|
|
64
|
+
function nameOf(element) {
|
|
65
|
+
const label = element.getAttribute('aria-label') ?? '';
|
|
66
|
+
const id = element.getAttribute('data-testid') ?? '';
|
|
67
|
+
const words = (label || id.replace(/[-_.]+/g, ' ')).replace(/\s+/g, ' ').trim();
|
|
68
|
+
return words && words.length <= PART_NAME ? words : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** The nearest element at the point with a name, with its box; the element itself without one. */
|
|
71
|
+
export function partAt(x, y, page = document) {
|
|
72
|
+
const hit = page.elementFromPoint(x, y);
|
|
73
|
+
if (!hit)
|
|
74
|
+
return;
|
|
75
|
+
let named = hit;
|
|
76
|
+
for (let depth = 0; named && depth < 12; depth++, named = named.parentElement) {
|
|
77
|
+
const name = nameOf(named);
|
|
78
|
+
if (name)
|
|
79
|
+
return { name, box: boxOf(named) };
|
|
80
|
+
}
|
|
81
|
+
return { box: boxOf(hit) };
|
|
82
|
+
}
|
|
83
|
+
function boxOf(element) {
|
|
84
|
+
const r = element.getBoundingClientRect();
|
|
85
|
+
const round = (value) => Math.max(0, Math.round(value));
|
|
86
|
+
return { x: round(r.left), y: round(r.top), w: round(r.width), h: round(r.height) };
|
|
87
|
+
}
|
|
88
|
+
/** The answer to one ask: the ask's number, the part's name and box, and how far it is scrolled. */
|
|
89
|
+
export function partAnswer(expected, ask, part, scroll = scrolled()) {
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
type: 'ape:prototype:spot',
|
|
92
|
+
version: 2,
|
|
93
|
+
navigation: expected.navigation,
|
|
94
|
+
document: expected.nonce,
|
|
95
|
+
ask: ask.ask,
|
|
96
|
+
...(part?.name ? { name: part.name } : {}),
|
|
97
|
+
box: part?.box ?? { x: Math.round(ask.x), y: Math.round(ask.y), w: 0, h: 0 },
|
|
98
|
+
scroll,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.8.45",
|
|
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.
|
|
37
|
-
"@buffcore/
|
|
38
|
-
"@buffcore/
|
|
39
|
-
"@buffcore/
|
|
40
|
-
"@buffcore/
|
|
41
|
-
"@buffcore/
|
|
36
|
+
"@buffcore/config": "0.8.45",
|
|
37
|
+
"@buffcore/tokens": "0.8.45",
|
|
38
|
+
"@buffcore/i18n": "0.8.45",
|
|
39
|
+
"@buffcore/contracts": "0.8.45",
|
|
40
|
+
"@buffcore/sdk": "0.8.45",
|
|
41
|
+
"@buffcore/ui": "0.8.45"
|
|
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/server": "0.8.
|
|
120
|
-
"@buffcore/modules": "0.8.
|
|
119
|
+
"@buffcore/server": "0.8.45",
|
|
120
|
+
"@buffcore/modules": "0.8.45"
|
|
121
121
|
},
|
|
122
122
|
"scripts": {
|
|
123
123
|
"build": "node ../../scripts/build-package.mjs",
|