@buffcore/app-shell 0.8.45 → 0.8.47

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,4 +25,4 @@ export interface SceneProps {
25
25
  * The component for the app's `/_scene` route. Development only: the route loads it behind
26
26
  * `__DEV__`, so production builds leave it and the sample data out.
27
27
  */
28
- export declare function createScene({ scenes, views, catalogs, extensions }: SceneOptions): (props: SceneProps) => import("react").JSX.Element | null;
28
+ export declare function createScene({ scenes, views, catalogs, extensions }: SceneOptions): (props: SceneProps) => import("react").JSX.Element;
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { SCENE_LOOK_ATTR, SCENE_LOOK_CHANGE, SCENE_LOOK_REUSABLE, } from '@buffcore/contracts/prototype';
2
3
  import { createI18n, isRtl } from '@buffcore/i18n';
3
4
  import { I18nProvider } from '@buffcore/i18n/react';
4
5
  import { DirectionProvider } from '@buffcore/ui';
@@ -28,7 +29,7 @@ export function createScene({ scenes, views, catalogs = [], extensions = [] }) {
28
29
  const names = missing.map((s) => `"${s.key}" (${s.view})`).join(', ');
29
30
  throw new Error(`No app view for the scenes ${names}: add them to createScene's views.`);
30
31
  }
31
- return function Scene(props) {
32
+ function SceneLook({ props, search }) {
32
33
  const { scene: key, theme, mode = 'light', locale = 'en', scale: asked } = props;
33
34
  const [themeReady, setThemeReady] = useState(false);
34
35
  const translator = useMemo(() => createI18n({ catalogs: [shellCatalog, ...strings], pseudo: true, locale }), [locale]);
@@ -37,6 +38,7 @@ export function createScene({ scenes, views, catalogs = [], extensions = [] }) {
37
38
  const name = themeName(look.key, resolveThemeMode(mode, look.modes));
38
39
  const dir = isRtl(locale) ? 'rtl' : 'ltr';
39
40
  const found = key ? own.find((s) => s.key === key) : preview;
41
+ const View = found && views[found.view];
40
42
  // The scale the URL asks for, else the scene's own, else 1.
41
43
  const scale = Number(asked) > 0 ? Number(asked) : (found?.scale ?? 1);
42
44
  // Apply the theme before mounting the view, and before paint on later switches.
@@ -52,13 +54,50 @@ export function createScene({ scenes, views, catalogs = [], extensions = [] }) {
52
54
  document.documentElement.lang = locale;
53
55
  document.documentElement.dir = dir;
54
56
  }, [locale, dir]);
55
- if (!found)
57
+ useLayoutEffect(() => {
58
+ if (!themeReady || Platform.OS !== 'web')
59
+ return;
60
+ const html = document.documentElement;
61
+ html.setAttribute(SCENE_LOOK_ATTR, search ?? window.location.search);
62
+ // Any view can move in place: the snapshot checks each scene against a fresh load.
63
+ html.setAttribute(SCENE_LOOK_REUSABLE, '');
64
+ return () => {
65
+ html.removeAttribute(SCENE_LOOK_ATTR);
66
+ html.removeAttribute(SCENE_LOOK_REUSABLE);
67
+ };
68
+ }, [themeReady, search]);
69
+ if (!found || !View)
56
70
  throw new Error(key
57
71
  ? `No app scene "${key}" in prototype/scenes.ts.`
58
72
  : 'No app scene to preview in prototype/scenes.ts.');
59
73
  if (!themeReady)
60
74
  return null;
61
- const View = views[found.view];
62
75
  return (_jsx(I18nProvider, { translator: translator, children: _jsx(DirectionProvider, { dir: dir, children: _jsx(View, { ...found.props }) }) }));
76
+ }
77
+ return function Scene(props) {
78
+ // The router supplies the initial props (also on native). A browser snapshot moves the URL
79
+ // directly so the router and the rest of the app stay mounted.
80
+ const [search, setSearch] = useState();
81
+ useLayoutEffect(() => {
82
+ if (Platform.OS !== 'web')
83
+ return;
84
+ const read = () => {
85
+ window.scrollTo({ top: 0, left: 0, behavior: 'instant' });
86
+ setSearch(window.location.search);
87
+ };
88
+ window.addEventListener(SCENE_LOOK_CHANGE, read);
89
+ return () => window.removeEventListener(SCENE_LOOK_CHANGE, read);
90
+ }, []);
91
+ return (_jsx(SceneLook, { props: search === undefined ? props : urlProps(search), search: search }, search));
92
+ };
93
+ }
94
+ function urlProps(search) {
95
+ const params = new URLSearchParams(search);
96
+ return {
97
+ scene: params.get('key') ?? undefined,
98
+ theme: params.get('theme') ?? undefined,
99
+ mode: params.get('mode') ?? undefined,
100
+ locale: params.get('locale') ?? undefined,
101
+ scale: params.get('scale') ?? undefined,
63
102
  };
64
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buffcore/app-shell",
3
- "version": "0.8.45",
3
+ "version": "0.8.47",
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.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"
36
+ "@buffcore/ui": "0.8.47",
37
+ "@buffcore/tokens": "0.8.47",
38
+ "@buffcore/contracts": "0.8.47",
39
+ "@buffcore/i18n": "0.8.47",
40
+ "@buffcore/config": "0.8.47",
41
+ "@buffcore/sdk": "0.8.47"
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.45",
120
- "@buffcore/modules": "0.8.45"
119
+ "@buffcore/modules": "0.8.47",
120
+ "@buffcore/server": "0.8.47"
121
121
  },
122
122
  "scripts": {
123
123
  "build": "node ../../scripts/build-package.mjs",