ember-nativescript 0.2.0 → 0.3.0

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.
Files changed (49) hide show
  1. package/README.md +6 -1
  2. package/dist/components/RouteError.d.ts +8 -0
  3. package/dist/components/RouteError.d.ts.map +1 -0
  4. package/dist/components/RouteError.js +13 -0
  5. package/dist/components/RouteError.js.map +1 -0
  6. package/dist/src/application-entry.d.ts +4 -0
  7. package/dist/src/application-entry.d.ts.map +1 -0
  8. package/dist/src/application-entry.js +4 -0
  9. package/dist/src/application-testing.d.ts +19 -0
  10. package/dist/src/application-testing.d.ts.map +1 -0
  11. package/dist/src/application-testing.js +32 -0
  12. package/dist/src/application-testing.js.map +1 -0
  13. package/dist/src/application.d.ts +45 -0
  14. package/dist/src/application.d.ts.map +1 -0
  15. package/dist/src/application.js +136 -0
  16. package/dist/src/application.js.map +1 -0
  17. package/dist/src/nativescript-application.d.ts +8 -0
  18. package/dist/src/nativescript-application.d.ts.map +1 -0
  19. package/dist/src/nativescript-application.js +23 -0
  20. package/dist/src/nativescript-application.js.map +1 -0
  21. package/dist/src/testing.d.ts +2 -0
  22. package/dist/src/testing.d.ts.map +1 -1
  23. package/dist/src/testing.js +7 -2
  24. package/dist/src/testing.js.map +1 -1
  25. package/dist/src/web-adapter.d.ts +1 -1
  26. package/dist/src/web-adapter.d.ts.map +1 -1
  27. package/dist/src/web-adapter.js +6 -43
  28. package/dist/src/web-adapter.js.map +1 -1
  29. package/dist/src/web-app.d.ts +6 -0
  30. package/dist/src/web-app.d.ts.map +1 -1
  31. package/dist/src/web-app.js +26 -18
  32. package/dist/src/web-app.js.map +1 -1
  33. package/dist/src/web-application.d.ts +10 -0
  34. package/dist/src/web-application.d.ts.map +1 -0
  35. package/dist/src/web-application.js +37 -0
  36. package/dist/src/web-application.js.map +1 -0
  37. package/dist/src/web-host.d.ts +9 -2
  38. package/dist/src/web-host.d.ts.map +1 -1
  39. package/dist/src/web-host.js +10 -3
  40. package/dist/src/web-host.js.map +1 -1
  41. package/dist/src/web-list.d.ts +18 -0
  42. package/dist/src/web-list.d.ts.map +1 -0
  43. package/dist/src/web-list.js +224 -0
  44. package/dist/src/web-list.js.map +1 -0
  45. package/dist/src/web-styles.d.ts +1 -1
  46. package/dist/src/web-styles.d.ts.map +1 -1
  47. package/dist/src/web-styles.js +6 -3
  48. package/dist/src/web-styles.js.map +1 -1
  49. package/package.json +11 -2
package/README.md CHANGED
@@ -28,11 +28,16 @@ export default class Home extends Component<{ Args: { nav: Navigator } }> {
28
28
 
29
29
  **Docs:** https://betocantu93.github.io/ember-nativescript/
30
30
 
31
- **Status:** early (0.2). Everything below is tested in Node against an in-memory toolkit, typechecked against
31
+ **Status:** early (0.3). Everything below is tested in Node against an in-memory toolkit, typechecked against
32
32
  @nativescript/core, and bundles for both platforms with @nativescript/vite. On iOS it runs: the demo on the simulator,
33
33
  and Pace (`run/`: MapKit, the GPS, animations, navigation) on an iPhone. Android hasn't run yet, nor a release build;
34
34
  see [Proven and unverified](#proven-and-unverified).
35
35
 
36
+ **Screens or routes, your choice:** open screens with a navigator (`createNativeApp`, as in NativeScript-Vue), or
37
+ boot a full Ember Application with its router, routes and `model()` hooks (`createNativeApplication` from
38
+ `ember-nativescript/application`, opt-in and experimental), and each route is a native screen. Same views, same back,
39
+ same tests. See [Two ways](https://betocantu93.github.io/ember-nativescript/guide/two-ways).
40
+
36
41
  **In a browser, too (experimental):** the same screens on HTML elements, each at its own URL, with the browser's back
37
42
  button as back: `npm run web` in an app from the template. For links, demos and previews; native code needs a
38
43
  `__WEB__` branch. See [In a browser](https://betocantu93.github.io/ember-nativescript/guide/web).
@@ -0,0 +1,8 @@
1
+ import type { TOC } from '@ember/component/template-only';
2
+ declare const RouteError: TOC<{
3
+ Args: {
4
+ message: string;
5
+ };
6
+ }>;
7
+ export default RouteError;
8
+ //# sourceMappingURL=RouteError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouteError.d.ts","sourceRoot":"","sources":["../../components/RouteError.gts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAE1D,QAAA,MAAM,UAAU,EAAE,GAAG,CAAC;IAAE,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAKxC,CAAC;AAEZ,eAAe,UAAU,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { setComponentTemplate } from "@ember/component";
2
+ import { createTemplateFactory } from "@ember/template-factory";
3
+ import templateOnly from "@ember/component/template-only";
4
+ // components/RouteError.gts
5
+ var RouteError = setComponentTemplate(createTemplateFactory({
6
+ "id": null,
7
+ "block": "[[[10,\"actionBar\"],[14,\"title\",\"Error\"],[12],[13],[10,\"stackLayout\"],[14,\"padding\",\"16\"],[12],[10,\"label\"],[14,1,\"ember-nativescript-error\"],[14,\"textWrap\",\"true\"],[14,\"color\",\"#c62828\"],[15,\"text\",[30,1]],[12],[13],[13]],[\"@message\"],[]]",
8
+ "moduleName": "(unknown template module)",
9
+ "isStrictMode": true
10
+ }), templateOnly());
11
+ export { RouteError as default };
12
+
13
+ //# sourceMappingURL=RouteError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouteError.js","names":["RouteError"],"sources":["../../components/RouteError.gts"],"sourcesContent":["// What a route shows when it can't show its own screen, in the full Ember Application: the reason, on the screen and\n// in the console, instead of a crash.\nimport type { TOC } from '@ember/component/template-only';\n\nconst RouteError: TOC<{ Args: { message: string } }> = <template>\n <actionBar title='Error' />\n <stackLayout padding='16'>\n <label id='ember-nativescript-error' textWrap='true' color='#c62828' text={{@message}} />\n </stackLayout>\n</template>;\n\nexport default RouteError;\n"],"mappings":";;;;AAIA,IAAMA,a;;;;;AAKI,CAAA,GAAA,aAAA,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { type RoutedApp, type StartApplicationOptions, startRoutedApp } from './application.js';
2
+ export { createNativeApplication } from './nativescript-application.js';
3
+ export { createWebApplication, type WebApplicationOptions } from './web-application.js';
4
+ //# sourceMappingURL=application-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-entry.d.ts","sourceRoot":"","sources":["../../src/application-entry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,uBAAuB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { startRoutedApp } from "./application.js";
2
+ import { createNativeApplication } from "./nativescript-application.js";
3
+ import { createWebApplication } from "./web-application.js";
4
+ export { createNativeApplication, createWebApplication, startRoutedApp };
@@ -0,0 +1,19 @@
1
+ import type ApplicationInstance from '@ember/application/instance';
2
+ import type RouterService from '@ember/routing/router-service';
3
+ import { type StartApplicationOptions } from './application.js';
4
+ import { type TestApp } from './testing.js';
5
+ export interface ApplicationTestOptions extends StartApplicationOptions {
6
+ platform?: 'ios' | 'android';
7
+ }
8
+ export interface ApplicationTestApp extends Omit<TestApp, 'owner'> {
9
+ owner: ApplicationInstance;
10
+ router: RouterService;
11
+ /** The URLs of the screens in the stack, from the first to the one on top. */
12
+ readonly urls: string[];
13
+ /** Transitions to a URL or a route, as `router.transitionTo` does, and waits for its screen. */
14
+ visit(...args: Parameters<RouterService['transitionTo']>): Promise<void>;
15
+ destroy(): void;
16
+ }
17
+ /** Boots the Application at its first URL on fake views, as createNativeApplication does on a phone. */
18
+ export declare function startApplication(options?: ApplicationTestOptions): Promise<ApplicationTestApp>;
19
+ //# sourceMappingURL=application-testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-testing.d.ts","sourceRoot":"","sources":["../../src/application-testing.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,mBAAmB,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAkB,KAAK,uBAAuB,EAAkB,MAAM,kBAAkB,CAAC;AAIhG,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACrE,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;IAChE,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,gGAAgG;IAChG,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wGAAwG;AACxG,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwBxG"}
@@ -0,0 +1,32 @@
1
+ import { startRoutedApp } from "./application.js";
2
+ import { FakeAdapter, FakeFrame } from "./fake-adapter.js";
3
+ import { createDocument } from "./render.js";
4
+ import { testApp } from "./testing.js";
5
+ // src/application-testing.ts
6
+ /** Boots the Application at its first URL on fake views, as createNativeApplication does on a phone. */
7
+ async function startApplication(options = {}) {
8
+ const document = createDocument(new FakeAdapter(options.platform ?? "ios"));
9
+ const frame = new FakeFrame();
10
+ const routed = await startRoutedApp(document, frame, options);
11
+ const helpers = testApp(routed.instance, routed.navigator, frame);
12
+ await helpers.settled();
13
+ const app = helpers;
14
+ Object.defineProperty(app, "urls", { get: () => routed.urls });
15
+ return Object.assign(app, {
16
+ owner: routed.instance,
17
+ router: routed.router,
18
+ async visit(...args) {
19
+ await routed.router.transitionTo(...args);
20
+ await helpers.settled();
21
+ },
22
+ async back() {
23
+ frame.back();
24
+ await routed.routed();
25
+ await helpers.settled();
26
+ },
27
+ destroy: routed.destroy
28
+ });
29
+ }
30
+ export { startApplication };
31
+
32
+ //# sourceMappingURL=application-testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-testing.js","names":["startRoutedApp","FakeAdapter","FakeFrame","createDocument","testApp","startApplication","options","document","platform","frame","routed","helpers","instance","navigator","settled","app","Object","defineProperty","get","urls","assign","owner","router","visit","args","transitionTo","back","destroy"],"sources":["../../src/application-testing.ts"],"sourcesContent":["// Tests for an app on the full Ember Application, in Node: the router, routes and model hooks run as in the app, and\n// each route's screen renders into the fake views and Frame that startApp uses.\n//\n// const app = await startApplication({ modules: import.meta.glob('../src/{router.ts,routes,templates}/**', { eager: true }) });\n// await app.visit('/rides/42');\n// expect(app.find('.title').text).toBe('Ride 42');\n// await app.back();\n// expect(app.router.currentURL).toBe('/');\n\nimport type ApplicationInstance from '@ember/application/instance';\nimport type RouterService from '@ember/routing/router-service';\n\nimport { type RoutedApp, type StartApplicationOptions, startRoutedApp } from './application.ts';\nimport { FakeAdapter, FakeFrame } from './fake-adapter.ts';\nimport type { NativeOwner } from './owner.ts';\nimport { createDocument } from './render.ts';\nimport { type TestApp, testApp } from './testing.ts';\n\nexport interface ApplicationTestOptions extends StartApplicationOptions {\n platform?: 'ios' | 'android';\n}\n\nexport interface ApplicationTestApp extends Omit<TestApp, 'owner'> {\n owner: ApplicationInstance;\n router: RouterService;\n /** The URLs of the screens in the stack, from the first to the one on top. */\n readonly urls: string[];\n /** Transitions to a URL or a route, as `router.transitionTo` does, and waits for its screen. */\n visit(...args: Parameters<RouterService['transitionTo']>): Promise<void>;\n destroy(): void;\n}\n\n/** Boots the Application at its first URL on fake views, as createNativeApplication does on a phone. */\nexport async function startApplication(options: ApplicationTestOptions = {}): Promise<ApplicationTestApp> {\n const document = createDocument(new FakeAdapter(options.platform ?? 'ios'));\n const frame = new FakeFrame();\n const routed: RoutedApp = await startRoutedApp(document, frame, options);\n const helpers = testApp(routed.instance as unknown as NativeOwner, routed.navigator, frame);\n await helpers.settled();\n\n const app = helpers as unknown as ApplicationTestApp;\n Object.defineProperty(app, 'urls', { get: () => routed.urls });\n return Object.assign(app, {\n owner: routed.instance,\n router: routed.router,\n async visit(...args: Parameters<RouterService['transitionTo']>) {\n await routed.router.transitionTo(...args);\n await helpers.settled();\n },\n // The system's back: the page leaves, then the router follows it.\n async back() {\n frame.back();\n await routed.routed();\n await helpers.settled();\n },\n destroy: routed.destroy,\n });\n}\n"],"mappings":";;;;;;AAiCA,eAAsBK,iBAAiBC,UAAkC,CAAC,GAAgC;CACxG,MAAMC,WAAWJ,eAAe,IAAIF,YAAYK,QAAQE,YAAY,KAAK,CAAC;CAC1E,MAAMC,QAAQ,IAAIP,UAAU;CAC5B,MAAMQ,SAAoB,MAAMV,eAAeO,UAAUE,OAAOH,OAAO;CACvE,MAAMK,UAAUP,QAAQM,OAAOE,UAAoCF,OAAOG,WAAWJ,KAAK;CAC1F,MAAME,QAAQG,QAAQ;CAEtB,MAAMC,MAAMJ;CACZK,OAAOC,eAAeF,KAAK,QAAQ,EAAEG,WAAWR,OAAOS,KAAK,CAAC;CAC7D,OAAOH,OAAOI,OAAOL,KAAK;EACxBM,OAAOX,OAAOE;EACdU,QAAQZ,OAAOY;EACf,MAAMC,MAAM,GAAGC,MAAiD;GAC9D,MAAMd,OAAOY,OAAOG,aAAa,GAAGD,IAAI;GACxC,MAAMb,QAAQG,QAAQ;EACxB;EAEA,MAAMY,OAAO;GACXjB,MAAMiB,KAAK;GACX,MAAMhB,OAAOA,OAAO;GACpB,MAAMC,QAAQG,QAAQ;EACxB;EACAa,SAASjB,OAAOiB;CAClB,CAAC;AACH"}
@@ -0,0 +1,45 @@
1
+ import Application from '@ember/application';
2
+ import type ApplicationInstance from '@ember/application/instance';
3
+ import type RouterService from '@ember/routing/router-service';
4
+ import type { NativeDocument } from './dom.js';
5
+ import { type FrameHost, Navigator } from './navigator.js';
6
+ export interface StartApplicationOptions {
7
+ /**
8
+ * The modules Ember's resolver looks in, from `import.meta.glob`: `./router.ts`, `./routes/`, `./templates/`,
9
+ * `./controllers/`, `./services/`. Optional when `Application` already has its `modules`.
10
+ */
11
+ modules?: Record<string, unknown>;
12
+ /** An Application subclass to boot, for its initializers. Defaults to Ember's Application. */
13
+ Application?: typeof Application;
14
+ /** The URL the app starts at. Defaults to `/`. */
15
+ url?: string;
16
+ /**
17
+ * The screen under a deep link: when `url` is another, the app shows this one first and the URL's screen over it,
18
+ * so back from a link goes home, as a native app's does. Defaults to `/`; `null` shows the URL's screen alone.
19
+ */
20
+ home?: string | null;
21
+ }
22
+ interface InternalOptions extends StartApplicationOptions {
23
+ /** Runs once the router is there, before the first screen shows (the web host reads URLs from it). */
24
+ onBoot?: (router: RouterService) => void;
25
+ }
26
+ export interface RoutedApp {
27
+ app: Application;
28
+ instance: ApplicationInstance;
29
+ router: RouterService;
30
+ /** The `navigator` service: `back()`, `showModal()`, and `navigate()` for a screen that isn't a route. */
31
+ navigator: Navigator;
32
+ /** The URLs of the screens in the stack, from the first to the one on top. */
33
+ readonly urls: string[];
34
+ /** Resolves once the router has followed a back to the screen now on top. */
35
+ routed(): Promise<void>;
36
+ destroy(): void;
37
+ }
38
+ /**
39
+ * Boots an Ember Application, shows the route at `url` as the first screen, and pushes a screen for each route the
40
+ * router goes to after. The platform's entry (`createNativeApplication`, or `startApplication` in tests) passes the
41
+ * document and the Frame.
42
+ */
43
+ export declare function startRoutedApp(document: NativeDocument, host: FrameHost, options?: InternalOptions): Promise<RoutedApp>;
44
+ export {};
45
+ //# sourceMappingURL=application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/application.ts"],"names":[],"mappings":"AAuBA,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,mBAAmB,MAAM,6BAA6B,CAAC;AAEnE,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAI/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,8FAA8F;IAC9F,WAAW,CAAC,EAAE,OAAO,WAAW,CAAC;IACjC,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,UAAU,eAAgB,SAAQ,uBAAuB;IACvD,sGAAsG;IACtG,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,WAAW,CAAC;IACjB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,MAAM,EAAE,aAAa,CAAC;IACtB,0GAA0G;IAC1G,SAAS,EAAE,SAAS,CAAC;IACrB,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,6EAA6E;IAC7E,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,OAAO,IAAI,IAAI,CAAC;CACjB;AAeD;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,SAAS,EACf,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,SAAS,CAAC,CAmDpB"}
@@ -0,0 +1,136 @@
1
+ import Application from "@ember/application";
2
+ import RouteError from "../components/RouteError.js";
3
+ import { Navigator } from "./navigator.js";
4
+ // src/application.ts
5
+ /**
6
+ * Boots an Ember Application, shows the route at `url` as the first screen, and pushes a screen for each route the
7
+ * router goes to after. The platform's entry (`createNativeApplication`, or `startApplication` in tests) passes the
8
+ * document and the Frame.
9
+ */
10
+ async function startRoutedApp(document, host, options = {}) {
11
+ const Base = options.Application ?? Application;
12
+ const modules = options.modules;
13
+ const app = (modules ? class extends Base {
14
+ modules = modules;
15
+ } : Base).create({ autoboot: false });
16
+ const url = options.url ?? "/";
17
+ const home = options.home === void 0 ? "/" : options.home;
18
+ const first = home !== null && home !== url ? home : url;
19
+ const instance = await app.visit(first, {
20
+ isBrowser: false,
21
+ shouldRender: false,
22
+ location: "none"
23
+ });
24
+ const navigator = new Navigator(document, host, instance);
25
+ instance.register("service:navigator", navigator, { instantiate: false });
26
+ const router = instance.lookup("service:router");
27
+ options.onBoot?.(router);
28
+ const screens = new RouteScreens(instance, router, navigator);
29
+ screens.show(false);
30
+ router.on("routeDidChange", screens.onRouteDidChange);
31
+ if (first !== url) {
32
+ screens.animate = false;
33
+ try {
34
+ await router.transitionTo(url);
35
+ } finally {
36
+ screens.animate = true;
37
+ }
38
+ }
39
+ return {
40
+ app,
41
+ instance,
42
+ router,
43
+ navigator,
44
+ get urls() {
45
+ return screens.urls;
46
+ },
47
+ routed: () => screens.routed(),
48
+ destroy() {
49
+ router.off("routeDidChange", screens.onRouteDidChange);
50
+ navigator.destroy();
51
+ instance.destroy();
52
+ app.destroy();
53
+ }
54
+ };
55
+ }
56
+ var RouteScreens = class {
57
+ #entries = [];
58
+ /** Whether the next screens slide in. */
59
+ animate = true;
60
+ #back;
61
+ constructor(instance, router, navigator) {
62
+ this.instance = instance;
63
+ this.router = router;
64
+ this.navigator = navigator;
65
+ }
66
+ get urls() {
67
+ return this.#entries.map((entry) => entry.url);
68
+ }
69
+ async routed() {
70
+ if (this.#back) await Promise.resolve(this.#back).catch(() => void 0);
71
+ }
72
+ onRouteDidChange = (transition) => {
73
+ if (transition === this.#back) {
74
+ this.#back = void 0;
75
+ return;
76
+ }
77
+ const to = transition.to;
78
+ if (!to || isSubstate(to.name)) return;
79
+ const top = this.#entries.at(-1);
80
+ if (top && top.route === to.name && top.params === JSON.stringify(to.params)) {
81
+ top.url = this.router.currentURL ?? top.url;
82
+ return;
83
+ }
84
+ this.show(this.animate);
85
+ };
86
+ /** Pushes a screen for the route the router is on. */
87
+ show(animated) {
88
+ const name = this.router.currentRouteName;
89
+ if (!name) return;
90
+ const route = this.instance.lookup(`route:${name}`);
91
+ const templateName = route?.templateName ?? name.replace(/\./g, "/");
92
+ const template = this.instance.lookup(`template:${templateName}`);
93
+ let root;
94
+ if (template) root = this.navigator.navigate(template, {
95
+ name,
96
+ animated,
97
+ args: {
98
+ model: route?.modelFor(name),
99
+ controller: route?.controller
100
+ }
101
+ });
102
+ else {
103
+ const message = `[ember-nativescript] The route '${name}' has no template to show: add templates/${templateName}.gts.`;
104
+ console.error(message);
105
+ root = this.navigator.navigate(RouteError, {
106
+ name,
107
+ animated,
108
+ args: { message }
109
+ });
110
+ }
111
+ const entry = {
112
+ url: this.router.currentURL ?? "/",
113
+ route: name,
114
+ params: JSON.stringify(this.router.currentRoute?.params ?? {}),
115
+ root
116
+ };
117
+ root.element.addEventListener("navigatedFrom", (data) => {
118
+ if (data.isBackNavigation) this.#left(entry);
119
+ });
120
+ this.#entries.push(entry);
121
+ }
122
+ #left(entry) {
123
+ const index = this.#entries.indexOf(entry);
124
+ if (index === -1) return;
125
+ this.#entries.splice(index, 1);
126
+ const top = this.#entries.at(-1);
127
+ if (!top || top.url === this.router.currentURL) return;
128
+ const back = this.router.transitionTo(top.url);
129
+ this.#back = back;
130
+ back.catch(() => void 0);
131
+ }
132
+ };
133
+ var isSubstate = (name) => /(^|[._])loading$/.test(name);
134
+ export { startRoutedApp };
135
+
136
+ //# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","names":["Application","RouteError","Navigator","startRoutedApp","document","host","options","Base","modules","App","app","create","autoboot","url","home","undefined","first","instance","visit","isBrowser","shouldRender","location","navigator","register","instantiate","router","lookup","onBoot","screens","RouteScreens","show","on","onRouteDidChange","animate","transitionTo","urls","routed","destroy","off","back","constructor","map","entry","Promise","resolve","catch","transition","to","isSubstate","name","top","at","route","params","JSON","stringify","currentURL","animated","currentRouteName","templateName","replace","template","root","navigate","args","model","modelFor","controller","message","console","error","currentRoute","element","addEventListener","data","isBackNavigation","push","index","indexOf","splice","test"],"sources":["../../src/application.ts"],"sourcesContent":["// Opt-in: a full Ember Application on native views, with Ember's router deciding where the app is and each route\n// shown as a screen of its own.\n//\n// What a phone does doesn't change: each screen is a page in NativeScript's Frame, pushed with its animation, and\n// the system's back (Android's button, iOS's swipe) pops it. What changes is who says where to go: the router, with\n// `router.transitionTo('rides.ride', 42)`, routes, `model()` hooks, controllers and the router service, as in any\n// Ember app.\n//\n// How the two fit:\n//\n// - The Application boots as FastBoot boots one, outside a browser and without rendering (`shouldRender: false`), so\n// the router runs and Ember's renderer doesn't. Each route's template is rendered here, with Ember's public\n// `renderComponent`, into a page of its own.\n// - A transition that lands on a route pushes a page with that route's template, given `@model` and `@controller`.\n// The model is the one the route had then, and stays: the screens under the top one keep what they showed, as a\n// native app's do, however the router moves on. So the same route twice (a profile from a profile) is two pages.\n// - A page that leaves by a back (the system's, or `navigator.back()`) takes the router back to the URL of the page\n// now on top, without rendering it again: it's still there.\n// - The router's location is `none`: on a phone there's no URL bar. `router.currentURL` still says where the app is.\n//\n// Only the leaf route's template is shown: the application template and those of parent routes, with their\n// {{outlet}}, aren't (yet). A parent's model is there with `modelFor` in the leaf's route.\n\nimport Application from '@ember/application';\nimport type ApplicationInstance from '@ember/application/instance';\nimport type Route from '@ember/routing/route';\nimport type RouterService from '@ember/routing/router-service';\nimport type Transition from '@ember/routing/transition';\n\nimport RouteError from '../components/RouteError.gts';\nimport type { NativeDocument } from './dom.ts';\nimport { type FrameHost, Navigator } from './navigator.ts';\nimport type { NativeRoot } from './render.ts';\n\nexport interface StartApplicationOptions {\n /**\n * The modules Ember's resolver looks in, from `import.meta.glob`: `./router.ts`, `./routes/`, `./templates/`,\n * `./controllers/`, `./services/`. Optional when `Application` already has its `modules`.\n */\n modules?: Record<string, unknown>;\n /** An Application subclass to boot, for its initializers. Defaults to Ember's Application. */\n Application?: typeof Application;\n /** The URL the app starts at. Defaults to `/`. */\n url?: string;\n /**\n * The screen under a deep link: when `url` is another, the app shows this one first and the URL's screen over it,\n * so back from a link goes home, as a native app's does. Defaults to `/`; `null` shows the URL's screen alone.\n */\n home?: string | null;\n}\n\ninterface InternalOptions extends StartApplicationOptions {\n /** Runs once the router is there, before the first screen shows (the web host reads URLs from it). */\n onBoot?: (router: RouterService) => void;\n}\n\nexport interface RoutedApp {\n app: Application;\n instance: ApplicationInstance;\n router: RouterService;\n /** The `navigator` service: `back()`, `showModal()`, and `navigate()` for a screen that isn't a route. */\n navigator: Navigator;\n /** The URLs of the screens in the stack, from the first to the one on top. */\n readonly urls: string[];\n /** Resolves once the router has followed a back to the screen now on top. */\n routed(): Promise<void>;\n destroy(): void;\n}\n\ninterface Entry {\n url: string;\n route: string;\n params: string;\n root: NativeRoot;\n}\n\ninterface NavigatedData {\n isBackNavigation?: boolean;\n}\n\ntype BootOptions = Parameters<Application['visit']>[1];\n\n/**\n * Boots an Ember Application, shows the route at `url` as the first screen, and pushes a screen for each route the\n * router goes to after. The platform's entry (`createNativeApplication`, or `startApplication` in tests) passes the\n * document and the Frame.\n */\nexport async function startRoutedApp(\n document: NativeDocument,\n host: FrameHost,\n options: InternalOptions = {},\n): Promise<RoutedApp> {\n const Base = options.Application ?? Application;\n const modules = options.modules;\n const App = modules\n ? class extends Base {\n modules = modules;\n }\n : Base;\n const app = App.create({ autoboot: false });\n const url = options.url ?? '/';\n const home = options.home === undefined ? '/' : options.home;\n const first = home !== null && home !== url ? home : url;\n const instance = (await app.visit(first, {\n isBrowser: false,\n shouldRender: false,\n location: 'none',\n } as BootOptions)) as ApplicationInstance;\n\n const navigator = new Navigator(document, host, instance);\n instance.register('service:navigator', navigator, { instantiate: false });\n const router = instance.lookup('service:router') as RouterService;\n options.onBoot?.(router);\n const screens = new RouteScreens(instance, router, navigator);\n screens.show(false);\n router.on('routeDidChange', screens.onRouteDidChange);\n if (first !== url) {\n // The deep link, over the home screen, without an animation: it's where the app opens.\n screens.animate = false;\n try {\n await router.transitionTo(url);\n } finally {\n screens.animate = true;\n }\n }\n\n return {\n app,\n instance,\n router,\n navigator,\n get urls() {\n return screens.urls;\n },\n routed: () => screens.routed(),\n destroy() {\n router.off('routeDidChange', screens.onRouteDidChange);\n navigator.destroy();\n instance.destroy();\n app.destroy();\n },\n };\n}\n\nclass RouteScreens {\n readonly #entries: Entry[] = [];\n /** Whether the next screens slide in. */\n animate = true;\n // The transition that takes the router back after a page left: the page it lands on is already shown.\n #back: Transition | undefined;\n\n constructor(\n readonly instance: ApplicationInstance,\n readonly router: RouterService,\n readonly navigator: Navigator,\n ) {}\n\n get urls(): string[] {\n return this.#entries.map((entry) => entry.url);\n }\n\n async routed(): Promise<void> {\n if (this.#back) await Promise.resolve(this.#back).catch(() => undefined);\n }\n\n onRouteDidChange = (transition: Transition): void => {\n if (transition === this.#back) {\n this.#back = undefined;\n return;\n }\n const to = transition.to;\n if (!to || isSubstate(to.name)) return;\n const top = this.#entries.at(-1);\n // Only the query params changed: same screen, a new URL.\n if (top && top.route === to.name && top.params === JSON.stringify(to.params)) {\n top.url = this.router.currentURL ?? top.url;\n return;\n }\n this.show(this.animate);\n };\n\n /** Pushes a screen for the route the router is on. */\n show(animated: boolean): void {\n const name = this.router.currentRouteName;\n if (!name) return;\n const route = this.instance.lookup(`route:${name}`) as Route | undefined;\n const templateName = route?.templateName ?? name.replace(/\\./g, '/');\n const template = this.instance.lookup(`template:${templateName}`) as object | undefined;\n let root: NativeRoot;\n if (template) {\n root = this.navigator.navigate(template, {\n name,\n animated,\n args: { model: route?.modelFor(name), controller: route?.controller },\n });\n } else {\n // A screen that says what's wrong, rather than an error thrown from the router's event, which would end the app.\n const message = `[ember-nativescript] The route '${name}' has no template to show: add templates/${templateName}.gts.`;\n console.error(message);\n root = this.navigator.navigate(RouteError, { name, animated, args: { message } });\n }\n const entry: Entry = {\n url: this.router.currentURL ?? '/',\n route: name,\n params: JSON.stringify(this.router.currentRoute?.params ?? {}),\n root,\n };\n root.element.addEventListener('navigatedFrom', (data: unknown) => {\n if ((data as NavigatedData).isBackNavigation) this.#left(entry);\n });\n this.#entries.push(entry);\n }\n\n // A page left by a back: the router goes back to the URL of the page now on top.\n #left(entry: Entry): void {\n const index = this.#entries.indexOf(entry);\n if (index === -1) return;\n this.#entries.splice(index, 1);\n const top = this.#entries.at(-1);\n if (!top || top.url === this.router.currentURL) return;\n const back = this.router.transitionTo(top.url);\n this.#back = back;\n // A back the app redirects elsewhere (a guard in beforeModel) is a new screen: onRouteDidChange shows it.\n back.catch(() => undefined);\n }\n}\n\nconst isSubstate = (name: string): boolean => /(^|[._])loading$/.test(name);\n"],"mappings":";;;;;;;;;AAuFA,eAAsBG,eACpBC,UACAC,MACAC,UAA2B,CAAC,GACR;CACpB,MAAMC,OAAOD,QAAQN,eAAeA;CACpC,MAAMQ,UAAUF,QAAQE;CAMxB,MAAME,OALMF,UACR,cAAcD,KAAK;EACjBC,UAAUA;CACZ,IACAD,KAAAA,CACYI,OAAO,EAAEC,UAAU,MAAM,CAAC;CAC1C,MAAMC,MAAMP,QAAQO,OAAO;CAC3B,MAAMC,OAAOR,QAAQQ,SAASC,KAAAA,IAAY,MAAMT,QAAQQ;CACxD,MAAME,QAAQF,SAAS,QAAQA,SAASD,MAAMC,OAAOD;CACrD,MAAMI,WAAY,MAAMP,IAAIQ,MAAMF,OAAO;EACvCG,WAAW;EACXC,cAAc;EACdC,UAAU;CACZ,CAAgB;CAEhB,MAAMC,YAAY,IAAIpB,UAAUE,UAAUC,MAAMY,QAAQ;CACxDA,SAASM,SAAS,qBAAqBD,WAAW,EAAEE,aAAa,MAAM,CAAC;CACxE,MAAMC,SAASR,SAASS,OAAO,gBAAgB;CAC/CpB,QAAQqB,SAASF,MAAM;CACvB,MAAMG,UAAU,IAAIC,aAAaZ,UAAUQ,Q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AagB,IAAIrC,GAAG;EAC7C,KAAK,QAAQ0B;EAEbA,KAAKM,YAAY9B,KAAAA,CAAS;CAC5B;AACF;AAEA,IAAMiC,cAAcC,SAA0B,mBAAmB+B,KAAK/B,IAAI"}
@@ -0,0 +1,8 @@
1
+ import { type RoutedApp, type StartApplicationOptions } from './application.js';
2
+ /**
3
+ * Runs NativeScript with a Frame, boots the Ember Application, and shows the route at `url` in the Frame. Resolves
4
+ * once the first screen is on its way. NativeScript needs `Application.run` right away, so the Frame comes up empty
5
+ * for the moment the boot takes (under the splash screen), and a Frame queues the first page until it's loaded.
6
+ */
7
+ export declare function createNativeApplication(options?: StartApplicationOptions): Promise<RoutedApp>;
8
+ //# sourceMappingURL=nativescript-application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativescript-application.d.ts","sourceRoot":"","sources":["../../src/nativescript-application.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,uBAAuB,EAAkB,MAAM,kBAAkB,CAAC;AAMhG;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,SAAS,CAAC,CAQjG"}
@@ -0,0 +1,23 @@
1
+ import { Application, Frame } from "@nativescript/core";
2
+ import { startRoutedApp } from "./application.js";
3
+ import { FrameNavigationHost } from "./frame-host.js";
4
+ import { NativeScriptAdapter } from "./nativescript-adapter.js";
5
+ import { createDocument } from "./render.js";
6
+ // src/nativescript-application.ts
7
+ /**
8
+ * Runs NativeScript with a Frame, boots the Ember Application, and shows the route at `url` in the Frame. Resolves
9
+ * once the first screen is on its way. NativeScript needs `Application.run` right away, so the Frame comes up empty
10
+ * for the moment the boot takes (under the splash screen), and a Frame queues the first page until it's loaded.
11
+ */
12
+ function createNativeApplication(options = {}) {
13
+ const document = createDocument(new NativeScriptAdapter());
14
+ const frame = new Frame();
15
+ Application.run({ create: () => frame });
16
+ return startRoutedApp(document, new FrameNavigationHost(frame), options).catch((error) => {
17
+ console.error("[ember-nativescript] The Ember Application failed to boot:", error);
18
+ throw error;
19
+ });
20
+ }
21
+ export { createNativeApplication };
22
+
23
+ //# sourceMappingURL=nativescript-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativescript-application.js","names":["Application","Frame","startRoutedApp","FrameNavigationHost","NativeScriptAdapter","createDocument","createNativeApplication","options","document","frame","run","create","catch","error","console"],"sources":["../../src/nativescript-application.ts"],"sourcesContent":["// Opt-in: starts a full Ember Application on NativeScript, with Ember's router choosing the screens (see\n// application.ts). The default, createNativeApp, stays as it is: a thin owner and the navigator.\n//\n// // src/app.ts\n// import { createNativeApplication } from 'ember-nativescript/application';\n// createNativeApplication({\n// modules: import.meta.glob('./{router.ts,routes,controllers,services,templates}/**', { eager: true }),\n// });\n\nimport { Application, Frame } from '@nativescript/core';\n\nimport { type RoutedApp, type StartApplicationOptions, startRoutedApp } from './application.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport { NativeScriptAdapter } from './nativescript-adapter.ts';\nimport type { FrameHost } from './navigator.ts';\nimport { createDocument } from './render.ts';\n\n/**\n * Runs NativeScript with a Frame, boots the Ember Application, and shows the route at `url` in the Frame. Resolves\n * once the first screen is on its way. NativeScript needs `Application.run` right away, so the Frame comes up empty\n * for the moment the boot takes (under the splash screen), and a Frame queues the first page until it's loaded.\n */\nexport function createNativeApplication(options: StartApplicationOptions = {}): Promise<RoutedApp> {\n const document = createDocument(new NativeScriptAdapter());\n const frame = new Frame();\n Application.run({ create: () => frame });\n return startRoutedApp(document, new FrameNavigationHost(frame) as FrameHost, options).catch((error: unknown) => {\n console.error('[ember-nativescript] The Ember Application failed to boot:', error);\n throw error;\n });\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAgBM,wBAAwBC,UAAmC,CAAC,GAAuB;CACjG,MAAMC,WAAWH,eAAe,IAAID,oBAAoB,CAAC;CACzD,MAAMK,QAAQ,IAAIR,MAAM;CACxBD,YAAYU,IAAI,EAAEC,cAAcF,MAAM,CAAC;CACvC,OAAOP,eAAeM,UAAU,IAAIL,oBAAoBM,KAAK,GAAgBF,OAAO,CAAC,CAACK,OAAOC,UAAmB;EAC9GC,QAAQD,MAAM,8DAA8DA,KAAK;EACjF,MAAMA;CACR,CAAC;AACH"}
@@ -35,4 +35,6 @@ export interface TestApp {
35
35
  }
36
36
  /** Starts the app on its first screen, as createNativeApp does on a phone, and waits for it to render. */
37
37
  export declare function startApp(main: object, options?: StartAppOptions): Promise<TestApp>;
38
+ /** The helpers of a TestApp, for an app already started on a fake Frame. */
39
+ export declare function testApp(owner: NativeOwner, nav: Navigator, frame: FakeFrame): TestApp;
38
40
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing.ts"],"names":[],"mappings":"AAYA,OAAO,EAAe,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAG5F,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvF,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B;AAED,qFAAqF;AACrF,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvC,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,WAAW,CAAC;IACnB,GAAG,EAAE,SAAS,CAAC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E,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,kDAAkD;IAClD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAC5B,uGAAuG;IACvG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAQD,0GAA0G;AAC1G,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,CAU5F;AAED,4EAA4E;AAC5E,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CA6CrF"}
@@ -25,6 +25,12 @@ async function startApp(main, options = {}) {
25
25
  name: "main",
26
26
  animated: false
27
27
  });
28
+ const app = testApp(owner, nav, frame);
29
+ await app.settled();
30
+ return app;
31
+ }
32
+ /** The helpers of a TestApp, for an app already started on a fake Frame. */
33
+ function testApp(owner, nav, frame) {
28
34
  const view = (target) => typeof target === "string" ? app.find(target) : target;
29
35
  const settled = async () => {
30
36
  await renderSettled();
@@ -66,9 +72,8 @@ async function startApp(main, options = {}) {
66
72
  service: (name) => owner.lookup(`service:${name}`),
67
73
  settled
68
74
  };
69
- await settled();
70
75
  return app;
71
76
  }
72
- export { FAKE_TAGS, FAKE_UNLOADED_TAGS, FakeFrame, FakeView, startApp };
77
+ export { FAKE_TAGS, FAKE_UNLOADED_TAGS, FakeFrame, FakeView, startApp, testApp };
73
78
 
74
79
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","names":["renderSettled","FakeAdapter","FakeFrame","Navigator","createOwner","createDocument","matches","selector","view","startsWith","props","get","slice","split","includes","tag","startApp","main","options","document","platform","owner","services","modules","frame","nav","register","instantiate","navigate","args","name","animated","target","app","find","settled","list","top","findAll","each","undefined","layout","page","found","Error","toXML","fire","event","data","notify","tap","tapRow","index","String","type","text","back","service","lookup"],"sources":["../../src/testing.ts"],"sourcesContent":["// Tests for an app, in Node and without a phone: the app's screens render into fake views that keep their properties,\n// children and listeners, and a fake Frame that navigates as NativeScript's does.\n//\n// const app = await startApp(Home, { services: { session: Session } });\n// await app.type('#name', 'Ada');\n// await app.tap('.save');\n// expect(app.find('.greeting').text).toBe('Hello, Ada');\n//\n// Run them with Vitest and `emberTestConfig()` from 'ember-nativescript/vitest', which stands a stub in for\n// @nativescript/core. Native code (animations, the GPS, a plugin's view) doesn't run here: stub it with vi.mock.\nimport { renderSettled } from '@ember/renderer';\n\nimport { FakeAdapter, FakeFrame, type FakeView } from './fake-adapter.ts';\nimport { Navigator } from './navigator.ts';\nimport { createOwner, type Modules, type NativeOwner, type ServiceEntry } from './owner.ts';\nimport { createDocument } from './render.ts';\n\nexport { FAKE_TAGS, FAKE_UNLOADED_TAGS, FakeFrame, FakeView } from './fake-adapter.ts';\n\nexport interface StartAppOptions {\n args?: Record<string, unknown>;\n services?: Record<string, ServiceEntry>;\n modules?: Modules;\n platform?: 'ios' | 'android';\n}\n\n/** A view, or a selector for one on the current screen: `#id`, `.class` or a tag. */\nexport type Target = FakeView | string;\n\nexport interface TestApp {\n owner: NativeOwner;\n nav: Navigator;\n frame: FakeFrame;\n /** The page on screen. */\n readonly page: FakeView;\n /** The first view on the current screen that matches; throws, printing the screen, when none does. */\n find(selector: string): FakeView;\n findAll(selector: string): FakeView[];\n /** Fires `tap` and waits for Ember to re-render. */\n tap(target: Target): Promise<void>;\n /** Taps the row at `index` of a NativeList, as a finger on that cell does. */\n tapRow(target: Target, index: number): Promise<void>;\n /** Types into a TextField or TextView: sets `text`, fires `textChange`, and waits. */\n type(target: Target, text: string): Promise<void>;\n /** Fires any event with its data, as NativeScript would, and waits. */\n fire(target: Target, event: string, data?: Record<string, unknown>): Promise<void>;\n /** The back button on Android, a swipe on iOS. */\n back(): Promise<void>;\n service<T>(name: string): T;\n /** Waits for Ember to re-render, then lays out the screen's lists, as the phone's next frame would. */\n settled(): Promise<void>;\n}\n\nconst matches = (selector: string) => (view: FakeView) => {\n if (selector.startsWith('#')) return view.props.get('id') === selector.slice(1);\n if (selector.startsWith('.')) return (view.props.get('class') ?? '').split(/\\s+/).includes(selector.slice(1));\n return view.tag === selector;\n};\n\n/** Starts the app on its first screen, as createNativeApp does on a phone, and waits for it to render. */\nexport async function startApp(main: object, options: StartAppOptions = {}): Promise<TestApp> {\n const document = createDocument(new FakeAdapter(options.platform ?? 'ios'));\n const owner = createOwner({ services: options.services, modules: options.modules });\n const frame = new FakeFrame();\n const nav = new Navigator(document, frame, owner);\n owner.register('service:navigator', nav, { instantiate: false });\n nav.navigate(main, { args: options.args, name: 'main', animated: false });\n\n const view = (target: Target): FakeView => (typeof target === 'string' ? app.find(target) : target);\n // The lists show the rows that fit (ten), as ListView does once laid out: their cells are then on the screen.\n const settled = async (): Promise<void> => {\n await renderSettled();\n for (const list of frame.top.findAll((each) => each.list !== undefined)) list.list!.layout();\n await renderSettled();\n };\n\n const app: TestApp = {\n owner,\n nav,\n frame,\n get page() {\n return frame.top;\n },\n find(selector) {\n const found = frame.top.find(matches(selector));\n if (!found) throw new Error(`Nothing matches ${selector} on\\n${frame.top.toXML()}`);\n return found;\n },\n findAll: (selector) => frame.top.findAll(matches(selector)),\n async fire(target, event, data = {}) {\n view(target).notify(event, data);\n await settled();\n },\n tap: (target) => app.fire(target, 'tap'),\n async tapRow(target, index) {\n const list = view(target).list;\n if (!list) throw new Error(`${String(target)} is not a NativeList`);\n list.tap(index);\n await settled();\n },\n async type(target, text) {\n view(target).type(text);\n await settled();\n },\n async back() {\n frame.back();\n await settled();\n },\n service: <T>(name: string) => owner.lookup(`service:${name}`) as T,\n settled,\n };\n await settled();\n return app;\n}\n"],"mappings":";;;;;;;AAqDA,IAAMM,WAAWC,cAAsBC,SAAmB;CACxD,IAAID,SAASE,WAAW,GAAG,GAAG,OAAOD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ACT;EACAL,UAAU/B,aAAaiB,MAAMa,IAAIC,QAAQhC,QAAQC,QAAQ,CAAC;EAC1D,MAAMuC,KAAKd,QAAQe,OAAOC,OAAO,CAAC,GAAG;GACnCxC,KAAKwB,MAAM,CAAC,CAACiB,OAAOF,OAAOC,IAAI;GAC/B,MAAMb,QAAQ;EAChB;EACAe,MAAMlB,WAAWC,IAAIa,KAAKd,QAAQ,KAAK;EACvC,MAAMmB,OAAOnB,QAAQoB,OAAO;GAC1B,MAAMhB,OAAO5B,KAAKwB,MAAM,CAAC,CAACI;GAC1B,IAAI,CAACA,MAAM,MAAM,IAAIQ,MAAM,GAAGS,OAAOrB,MAAM,EAAC,qBAAsB;GAClEI,KAAKc,IAAIE,KAAK;GACd,MAAMjB,QAAQ;EAChB;EACA,MAAMmB,KAAKtB,QAAQuB,MAAM;GACvB/C,KAAKwB,MAAM,CAAC,CAACsB,KAAKC,IAAI;GACtB,MAAMpB,QAAQ;EAChB;EACA,MAAMqB,OAAO;GACXhC,MAAMgC,KAAK;GACX,MAAMrB,QAAQ;EAChB;EACAsB,UAAa3B,SAAiBT,MAAMqC,OAAO,WAAW5B,MAAM;EAC5DK;CACF;CACA,MAAMA,QAAQ;CACd,OAAOF;AACT"}
1
+ {"version":3,"file":"testing.js","names":["renderSettled","FakeAdapter","FakeFrame","Navigator","createOwner","createDocument","matches","selector","view","startsWith","props","get","slice","split","includes","tag","startApp","main","options","document","platform","owner","services","modules","frame","nav","register","instantiate","navigate","args","name","animated","app","testApp","settled","target","find","list","top","findAll","each","undefined","layout","page","found","Error","toXML","fire","event","data","notify","tap","tapRow","index","String","type","text","back","service","lookup"],"sources":["../../src/testing.ts"],"sourcesContent":["// Tests for an app, in Node and without a phone: the app's screens render into fake views that keep their properties,\n// children and listeners, and a fake Frame that navigates as NativeScript's does.\n//\n// const app = await startApp(Home, { services: { session: Session } });\n// await app.type('#name', 'Ada');\n// await app.tap('.save');\n// expect(app.find('.greeting').text).toBe('Hello, Ada');\n//\n// Run them with Vitest and `emberTestConfig()` from 'ember-nativescript/vitest', which stands a stub in for\n// @nativescript/core. Native code (animations, the GPS, a plugin's view) doesn't run here: stub it with vi.mock.\nimport { renderSettled } from '@ember/renderer';\n\nimport { FakeAdapter, FakeFrame, type FakeView } from './fake-adapter.ts';\nimport { Navigator } from './navigator.ts';\nimport { createOwner, type Modules, type NativeOwner, type ServiceEntry } from './owner.ts';\nimport { createDocument } from './render.ts';\n\nexport { FAKE_TAGS, FAKE_UNLOADED_TAGS, FakeFrame, FakeView } from './fake-adapter.ts';\n\nexport interface StartAppOptions {\n args?: Record<string, unknown>;\n services?: Record<string, ServiceEntry>;\n modules?: Modules;\n platform?: 'ios' | 'android';\n}\n\n/** A view, or a selector for one on the current screen: `#id`, `.class` or a tag. */\nexport type Target = FakeView | string;\n\nexport interface TestApp {\n owner: NativeOwner;\n nav: Navigator;\n frame: FakeFrame;\n /** The page on screen. */\n readonly page: FakeView;\n /** The first view on the current screen that matches; throws, printing the screen, when none does. */\n find(selector: string): FakeView;\n findAll(selector: string): FakeView[];\n /** Fires `tap` and waits for Ember to re-render. */\n tap(target: Target): Promise<void>;\n /** Taps the row at `index` of a NativeList, as a finger on that cell does. */\n tapRow(target: Target, index: number): Promise<void>;\n /** Types into a TextField or TextView: sets `text`, fires `textChange`, and waits. */\n type(target: Target, text: string): Promise<void>;\n /** Fires any event with its data, as NativeScript would, and waits. */\n fire(target: Target, event: string, data?: Record<string, unknown>): Promise<void>;\n /** The back button on Android, a swipe on iOS. */\n back(): Promise<void>;\n service<T>(name: string): T;\n /** Waits for Ember to re-render, then lays out the screen's lists, as the phone's next frame would. */\n settled(): Promise<void>;\n}\n\nconst matches = (selector: string) => (view: FakeView) => {\n if (selector.startsWith('#')) return view.props.get('id') === selector.slice(1);\n if (selector.startsWith('.')) return (view.props.get('class') ?? '').split(/\\s+/).includes(selector.slice(1));\n return view.tag === selector;\n};\n\n/** Starts the app on its first screen, as createNativeApp does on a phone, and waits for it to render. */\nexport async function startApp(main: object, options: StartAppOptions = {}): Promise<TestApp> {\n const document = createDocument(new FakeAdapter(options.platform ?? 'ios'));\n const owner = createOwner({ services: options.services, modules: options.modules });\n const frame = new FakeFrame();\n const nav = new Navigator(document, frame, owner);\n owner.register('service:navigator', nav, { instantiate: false });\n nav.navigate(main, { args: options.args, name: 'main', animated: false });\n const app = testApp(owner, nav, frame);\n await app.settled();\n return app;\n}\n\n/** The helpers of a TestApp, for an app already started on a fake Frame. */\nexport function testApp(owner: NativeOwner, nav: Navigator, frame: FakeFrame): TestApp {\n const view = (target: Target): FakeView => (typeof target === 'string' ? app.find(target) : target);\n // The lists show the rows that fit (ten), as ListView does once laid out: their cells are then on the screen.\n const settled = async (): Promise<void> => {\n await renderSettled();\n for (const list of frame.top.findAll((each) => each.list !== undefined)) list.list!.layout();\n await renderSettled();\n };\n\n const app: TestApp = {\n owner,\n nav,\n frame,\n get page() {\n return frame.top;\n },\n find(selector) {\n const found = frame.top.find(matches(selector));\n if (!found) throw new Error(`Nothing matches ${selector} on\\n${frame.top.toXML()}`);\n return found;\n },\n findAll: (selector) => frame.top.findAll(matches(selector)),\n async fire(target, event, data = {}) {\n view(target).notify(event, data);\n await settled();\n },\n tap: (target) => app.fire(target, 'tap'),\n async tapRow(target, index) {\n const list = view(target).list;\n if (!list) throw new Error(`${String(target)} is not a NativeList`);\n list.tap(index);\n await settled();\n },\n async type(target, text) {\n view(target).type(text);\n await settled();\n },\n async back() {\n frame.back();\n await settled();\n },\n service: <T>(name: string) => owner.lookup(`service:${name}`) as T,\n settled,\n };\n return app;\n}\n"],"mappings":";;;;;;;AAqDA,IAAMM,WAAWC,cAAsBC,SAAmB;CACxD,IAAID,SAASE,WAAW,GAAG,GAAG,OAAOD,KAAKE,MAAMC,IAAI,IAAI,MAAMJ,SAASK,MAAM,CAAC;CAC9E,IAAIL,SAASE,WAAW,GAAG,GAAG,QAAQD,KAAKE,MAAMC,IAAI,OAAO,KAAK,GAAA,CAAIE,MAAM,KAAK,CAA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AaiB,MAAMc,IAAIC,QAAQjC,QAAQC,QAAQ,CAAC;EAC1D,MAAMwC,KAAKZ,QAAQa,OAAOC,OAAO,CAAC,GAAG;GACnCzC,KAAK2B,MAAM,CAAC,CAACe,OAAOF,OAAOC,IAAI;GAC/B,MAAMf,QAAQ;EAChB;EACAiB,MAAMhB,WAAWH,IAAIe,KAAKZ,QAAQ,KAAK;EACvC,MAAMiB,OAAOjB,QAAQkB,OAAO;GAC1B,MAAMhB,OAAO7B,KAAK2B,MAAM,CAAC,CAACE;GAC1B,IAAI,CAACA,MAAM,MAAM,IAAIQ,MAAM,GAAGS,OAAOnB,MAAM,EAAC,qBAAsB;GAClEE,KAAKc,IAAIE,KAAK;GACd,MAAMnB,QAAQ;EAChB;EACA,MAAMqB,KAAKpB,QAAQqB,MAAM;GACvBhD,KAAK2B,MAAM,CAAC,CAACoB,KAAKC,IAAI;GACtB,MAAMtB,QAAQ;EAChB;EACA,MAAMuB,OAAO;GACXjC,MAAMiC,KAAK;GACX,MAAMvB,QAAQ;EAChB;EACAwB,UAAa5B,SAAiBT,MAAMsC,OAAO,WAAW7B,MAAM;EAC5DI;CACF;CACA,OAAOF;AACT"}
@@ -25,7 +25,7 @@ export declare class WebAdapter implements NativeAdapter<View> {
25
25
  on(view: View, event: string, listener: Listener): void;
26
26
  off(view: View, event: string, listener: Listener): void;
27
27
  frameHost(view: View): FrameHost<View> | null;
28
- bindList(view: View, cell: (container: View, index: number) => void, _options?: ListOptions): ListBinding | null;
28
+ bindList(view: View, cell: (container: View, index: number) => void, options?: ListOptions): ListBinding | null;
29
29
  }
30
30
  export {};
31
31
  //# sourceMappingURL=web-adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-adapter.d.ts","sourceRoot":"","sources":["../../src/web-adapter.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,KAAK,EA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IAAI,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,EAAE,OAAO,GAAE,WAAgB,GAAG,WAAW,GAAG,IAAI;CAOpH"}
@@ -1,4 +1,5 @@
1
1
  import { WebFrameHost } from "./web-host.js";
2
+ import { WebList } from "./web-list.js";
2
3
  // src/web-adapter.ts
3
4
  var STATES = /* @__PURE__ */ new WeakMap();
4
5
  var state = (view) => {
@@ -597,50 +598,12 @@ var WebAdapter = class {
597
598
  frameHost(view) {
598
599
  return state(view).tag === "frame" ? new WebFrameHost(view) : null;
599
600
  }
600
- bindList(view, cell, _options) {
601
+ bindList(view, cell, options = {}) {
601
602
  if (state(view).tag !== "listView") return null;
602
- const PAGE = 40;
603
- let count = 0;
604
- let shown = 0;
605
- let lastAsked = -1;
606
- const makeCell = (index) => {
607
- const container = this.createView("stackLayout");
608
- container.classList.add("ns-listView-cell");
609
- container.setAttribute("role", "listitem");
610
- container.addEventListener("click", (click) => {
611
- if (click.target.closest("button, input, select, textarea, a") !== null) return;
612
- emit(view, "itemTap", { index: [...view.children].indexOf(container) });
613
- });
614
- view.append(container);
615
- cell(container, index);
616
- };
617
- const fill = () => {
618
- const target = Math.min(count, Math.max(shown + PAGE, PAGE));
619
- [...view.children].forEach((container, index) => index < count && cell(container, index));
620
- for (let index = shown; index < target; index++) makeCell(index);
621
- shown = Math.max(shown, target);
622
- };
623
- const nearEnd = () => {
624
- if (view.scrollTop + view.clientHeight < view.scrollHeight - 400) return;
625
- if (shown < count) fill();
626
- else if (count > 0 && lastAsked !== count) {
627
- lastAsked = count;
628
- emit(view, "loadMoreItems");
629
- }
630
- };
631
- view.addEventListener("scroll", nearEnd, { passive: true });
632
- return {
633
- setCount(next) {
634
- count = next;
635
- while (view.children.length > count) view.lastElementChild.remove();
636
- shown = Math.min(shown, count);
637
- fill();
638
- requestAnimationFrame(nearEnd);
639
- },
640
- release() {
641
- view.removeEventListener("scroll", nearEnd);
642
- }
643
- };
603
+ return new WebList(view, cell, options, {
604
+ createCell: () => this.createView("stackLayout"),
605
+ emit: (name, data) => emit(view, name, data)
606
+ });
644
607
  }
645
608
  };
646
609
  var kebab = (name) => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);