ember-nativescript 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -26,26 +26,28 @@ export default class Home extends Component<{ Args: { nav: Navigator } }> {
26
26
  }
27
27
  ```
28
28
 
29
- **Status:** everything below is tested in Node against an in-memory toolkit, typechecked against @nativescript/core,
30
- and bundles for both platforms with @nativescript/vite. **Nothing has run on a device or simulator yet**; see
31
- [Proven and unverified](#proven-and-unverified).
29
+ **Status:** early (0.1). Everything below is tested in Node against an in-memory toolkit, typechecked against
30
+ @nativescript/core, and bundles for both platforms with @nativescript/vite. On iOS it runs: the demo on the simulator,
31
+ and Pace (`run/`: MapKit, the GPS, animations, navigation) on an iPhone. Android hasn't run yet, nor a release build;
32
+ see [Proven and unverified](#proven-and-unverified).
32
33
 
33
34
  ## Start an app
34
35
 
35
- `template/` is an app with a screen, a second one, a service and Glint set up. Until it is published on its own, copy
36
- it, then add the native resources every NativeScript app has:
37
-
38
36
  ```bash
39
- cp -r template my-app && cd my-app && pnpm install
37
+ ns create my-app --template ember-nativescript-template
40
38
  ```
41
39
 
42
40
  ```bash
43
- ns create resources --template @nativescript/template-blank-ts && cp -r resources/App_Resources . && rm -rf resources
41
+ cd my-app && ns run ios
44
42
  ```
45
43
 
46
- ```bash
47
- pnpm ios
48
- ```
44
+ The template is a small to-do app: three screens as .gts components, a recycling list, a service kept with
45
+ ApplicationSettings, Glint, and tests that run in Node (`npm test`). `ns create` gives it the app id you pass with
46
+ `--appid` and NativeScript's default App_Resources. Don't name the app's folder `app`: NativeScript names the iOS binary
47
+ after it, and the app's JavaScript goes in an `app` folder inside the bundle, so Xcode fails with "Multiple commands
48
+ produce …/app.app/app".
49
+
50
+ An app is a first screen and its services:
49
51
 
50
52
  ```ts
51
53
  // src/app.ts
@@ -56,6 +58,18 @@ import Session from './services/session.ts';
56
58
  createNativeApp({ main: Home, services: { session: Session } });
57
59
  ```
58
60
 
61
+ ```ts
62
+ // vite.config.mts
63
+ import { defineConfig } from 'vite';
64
+ import { emberConfig } from 'ember-nativescript/vite';
65
+
66
+ export default defineConfig(({ mode }) => emberConfig({ mode }));
67
+ ```
68
+
69
+ `emberConfig` is NativeScript's TypeScript config with vite-plugin-ember-gts, and keeps Ember out of the vendor bundle
70
+ that `ns run` (HMR) pre-bundles with esbuild: ember-source has no root entry, and `@ember/*` and `@glimmer/*` only
71
+ resolve through the plugin, so Ember and the packages that build on it are served module by module instead.
72
+
59
73
  `createNativeApp` makes an owner, a NativeScript `Frame` and a `Navigator`, registers the navigator as the
60
74
  `navigator` service, and shows `main` as the first screen. Services are singletons looked up lazily, as in an Ember
61
75
  app; `modules` takes an `import.meta.glob('./services/**/*.ts', { eager: true })` instead.
@@ -117,8 +131,10 @@ fadeIn = (view: StackLayout) => {
117
131
  };
118
132
  ```
119
133
 
120
- For animations, focus, scrolling to a position, a plugin's API. If the function returns another one, that runs when
121
- the element goes away.
134
+ For animations, focus, scrolling to a position, a plugin's API. The function runs once the native view exists: on a
135
+ page that is still being navigated to, that's at the view's `loaded`, so core's animations don't read an undefined
136
+ `nativeView`. If it returns another function, that runs when the element goes away. If it throws, the error is logged
137
+ and the rest of the template still renders, its `{{on}}` handlers included.
122
138
 
123
139
  ### Platforms
124
140
 
@@ -221,6 +237,39 @@ anything per item belongs on the item. `components/Contacts.gts` is a thousand c
221
237
  `components/Feed.gts` an endless feed of day headers and posts; `tests/list.test.ts` scrolls them through a fake list
222
238
  that recycles the way ListView does.
223
239
 
240
+ ## Tests without a phone
241
+
242
+ An app's screens run in Node: they render into fake views that keep their properties, children and listeners, in a
243
+ fake Frame that navigates as NativeScript's does.
244
+
245
+ ```ts
246
+ import { startApp } from 'ember-nativescript/testing';
247
+
248
+ const app = await startApp(Home, { services: { todos: Todos } });
249
+ await app.type('#draft', 'Buy milk');
250
+ await app.tap('#add');
251
+ expect(app.findAll('.todo-title')[0]!.text).toBe('Buy milk');
252
+
253
+ await app.tapRow('#list', 0);
254
+ expect(app.find('#title').text).toBe('Buy milk');
255
+ await app.back();
256
+ ```
257
+
258
+ ```ts
259
+ // vitest.config.mts
260
+ import { defineConfig } from 'vitest/config';
261
+ import { emberTestConfig } from 'ember-nativescript/vitest';
262
+
263
+ export default defineConfig(emberTestConfig());
264
+ ```
265
+
266
+ - `find` and `findAll` take `#id`, `.class` or a tag; a miss throws with the screen printed as XML (`app.page.toXML()`).
267
+ - `tap`, `type`, `fire`, `tapRow` and `back` wait for Ember to re-render, then lay out the screen's lists as the
268
+ phone's next frame would, so the rows that fit are on screen.
269
+ - `emberTestConfig` compiles .gts and decorators, and stands a stub in for @nativescript/core: its views, `isIOS`,
270
+ `Application`, and an in-memory `ApplicationSettings`. Native code (animations, the GPS, a plugin's view) doesn't run
271
+ in Node; stub it with `vi.mock`. `{{nativeView}}` callbacks get the fake view.
272
+
224
273
  ## Compared with NativeScript-Vue
225
274
 
226
275
  From NativeScript-Vue 3's features as commonly documented; not re-checked against its current documentation.
@@ -236,9 +285,9 @@ From NativeScript-Vue 3's features as commonly documented; not re-checked agains
236
285
  | Platform blocks | `<ios>`, `<android>`, `ios:` attributes | `<IOS>`, `<Android>`, `ios:` attributes |
237
286
  | Recycling list, several row kinds | `<ListView>` with `v-template` and `if` | `NativeList` with `@rows` and `@rowKind` |
238
287
  | Dependency injection | `provide`/`inject`, plugins | services and `@service`, as in any Ember app |
239
- | Tests without a device | — | a fake toolkit that runs in Node and prints the tree as XML |
288
+ | Tests without a device | — | `startApp` in Node: tap, type, navigate, lists; the tree as XML |
240
289
  | HMR that keeps state | yes | no |
241
- | Runs on devices, community, plugins | years of it | not run on a device yet |
290
+ | Runs on devices, community, plugins | years of it | runs on an iPhone; Android and community plugins untried |
242
291
 
243
292
  ## Layout
244
293
 
@@ -257,12 +306,15 @@ From NativeScript-Vue 3's features as commonly documented; not re-checked agains
257
306
  bind.ts, native-view.ts the {{bind}} and {{nativeView}} modifiers
258
307
  modifier.ts a modifier from a function, on Ember's public modifier manager API
259
308
  fake-adapter.ts in-memory views and frame for tests in Node; prints the tree as XML
309
+ testing.ts startApp(): an app on the fake views, with tap, type, back and lists laid out
310
+ testing-core.ts, vitest.ts the @nativescript/core stub, and the Vitest config that uses it
260
311
  nativescript-adapter.ts the real adapter on @nativescript/core (typechecked, not run here)
261
312
  types/glint.d.ts Glint types for native tags, attributes and events
262
313
  components/ NativeList, NativeFrame, Platform (the package); the rest are the demo's screens
263
- template/ a starter app
314
+ template/ the starter app published as ember-nativescript-template (its tests run in pnpm test)
264
315
  tests/ vitest against the fake adapter; tests/types is checked by Glint
265
- app/ the demo on @nativescript/vite, booting components/Home.gts
316
+ demo/ the demo on @nativescript/vite, booting components/Home.gts
317
+ run/ Pace, a running app: MapKit, GPS, haptics and animations from JavaScript (see run/README.md)
266
318
  ```
267
319
 
268
320
  ## Develop
@@ -290,8 +342,23 @@ listeners behind. They run in Node with no `window` or `document` global, which
290
342
  `pnpm typecheck` runs Glint, including `tests/types/elements.gts`, which checks what the native types accept and
291
343
  refuse. `pnpm build` writes `dist/` (JavaScript, declarations, the Glint types).
292
344
 
293
- `pnpm build:android` and `pnpm build:ios` bundle the demo app in `app/`. Running it needs the platform SDKs and the
294
- native resources, as in [Start an app](#start-an-app).
345
+ `pnpm test` also runs the template's tests against this source, and `pnpm typecheck` checks the template, so a
346
+ change that breaks a new app fails here.
347
+
348
+ To publish a version, raise `version` in both package.json files (the root and `template/`, whose `ember-nativescript`
349
+ range follows it), add it to CHANGELOG.md, then publish the package before the template, which depends on it:
350
+
351
+ ```bash
352
+ npm publish
353
+ ```
354
+
355
+ ```bash
356
+ cd template && npm publish
357
+ ```
358
+
359
+ `pnpm build:android` and `pnpm build:ios` bundle the demo app in `demo/`, `pnpm build:run:android` and
360
+ `pnpm build:run:ios` the running app in `run/`. Running them needs the platform SDKs; `demo/` also needs the native
361
+ resources, as in [Start an app](#start-an-app).
295
362
 
296
363
  ## What Glimmer needs from the DOM
297
364
 
@@ -327,7 +394,6 @@ a device, so the shim's element class stands in for it.
327
394
  adapter and silently keep the last one on a device.
328
395
  - HMR keeps no state, and there is no error overlay on the device.
329
396
  - CSS is NativeScript's subset; styles are NativeScript's, not a web app's.
330
- - The template isn't published as a package, so `ns create --template` can't fetch it yet.
331
397
 
332
398
  ## Proven and unverified
333
399
 
@@ -336,19 +402,21 @@ components compile with vite-plugin-ember-gts for the tests, the package and the
336
402
  with @nativescript/vite produces Android and iOS bundles; the packed tarball installed into a clean copy of the
337
403
  template builds for both platforms and passes Glint, which catches wrong attributes there.
338
404
 
339
- Not verified (no Android SDK, emulator, KVM or Xcode in this container):
340
-
341
- - Anything on a device or simulator: that the bundle boots, that Ember's runloop and microtasks behave on V8/JSC under
342
- NativeScript, that `Frame.navigate` inside `Application.run`'s `create` shows the first page.
343
- - The NativeScript adapter at runtime. It typechecks against @nativescript/core 9.1.4, but string conversion of every
344
- static property, assigning a CSS string to `style`, `insertChild` order on each layout, and the slot setters
345
- (`actionItems` rebuilt through `addItem`/`removeItem`, `spans` spliced) are assumed from how NativeScript's XML
346
- builder does it.
347
- - Navigation and modals on a device: the tests drive a fake Frame that fires `navigatedTo` and `navigatedFrom` as
348
- NativeScript's source does; that the real Frame fires them in that order on both platforms, that a Frame inside a
349
- TabView shows its first page, and that `closeCallback` fires once on a swipe-down dismissal, is unverified.
350
- - `NativeList` on a device: that `itemLoading` hands over the template's StackLayout, that `itemTemplateSelector` gets
351
- the index as NativeScript's source says, that a cell updated in the event is measured with its new content, and how
352
- scrolling a thousand rows feels.
405
+ Run on a device: Pace (`run/`) on an iPhone, under `ns run ios` with HMR: its home screen with Core Animation, taps,
406
+ navigation with a transition to the run screen, and MapKit drawing a route; an error in a `{{nativeView}}` callback
407
+ reaching the terminal while the screen keeps working. `ns create --template` with the packed template, then its tests
408
+ and both bundles, on Linux with the NativeScript CLI 9.1.2.
409
+
410
+ Not verified:
411
+
412
+ - Android: neither the demo nor Pace has run on an emulator or a device.
413
+ - A release build (`ns build --release`), and startup time and binary size on a device.
414
+ - Modals on a device, including `closeCallback` firing once on a swipe-down dismissal, and a Frame inside a TabView
415
+ showing its first page.
416
+ - The NativeScript adapter's less common paths: assigning a CSS string to `style`, the slot setters (`actionItems`
417
+ rebuilt through `addItem`/`removeItem`, `spans` spliced), and `insertChild` order on every layout.
418
+ - `NativeList` with a thousand rows on a device: that a cell updated in `itemLoading` is measured with its new
419
+ content, and how scrolling feels.
353
420
  - `{{bind}}` on a device: that setting `text` only when it differs keeps the cursor where it is while typing.
354
- - Performance: startup, bundle size on device.
421
+ - On the iPhone, still: the GPS in Pace, the countdown since `{{nativeView}}` waits for `loaded`, haptics, and the
422
+ template app itself.
@@ -1,6 +1,8 @@
1
1
  import type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.js';
2
2
  import type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.js';
3
3
  export declare const FAKE_TAGS: Set<string>;
4
+ /** Tags whose views start without a native view, like those on a page still being navigated to, until `loaded`. */
5
+ export declare const FAKE_UNLOADED_TAGS: Set<string>;
4
6
  export declare class FakeView {
5
7
  readonly tag: string;
6
8
  /** Properties as strings, for toXML() and assertions. */
@@ -16,6 +18,8 @@ export declare class FakeView {
16
18
  list?: FakeList;
17
19
  /** For a frame: its pages and modals. */
18
20
  frame?: FakeFrame;
21
+ /** Whether its native view exists; see FAKE_UNLOADED_TAGS. `notify('loaded')` sets it. */
22
+ isLoaded: boolean;
19
23
  constructor(tag: string);
20
24
  get content(): FakeView | undefined;
21
25
  get text(): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"fake-adapter.d.ts","sourceRoot":"","sources":["../../src/fake-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAuD/E,eAAO,MA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E,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAM3D,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI5D,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI;IAKrD,QAAQ,CACN,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,EAClD,OAAO,CAAC,EAAE,WAAW,GACpB,WAAW,GAAG,IAAI;CAUtB"}
@@ -63,6 +63,8 @@ var FAKE_TAGS = /* @__PURE__ */ new Set([
63
63
  ...CONTENT_VIEWS,
64
64
  ...LEAF_VIEWS
65
65
  ]);
66
+ /** Tags whose views start without a native view, like those on a page still being navigated to, until `loaded`. */
67
+ var FAKE_UNLOADED_TAGS = /* @__PURE__ */ new Set();
66
68
  var FakeView = class {
67
69
  tag;
68
70
  /** Properties as strings, for toXML() and assertions. */
@@ -78,8 +80,11 @@ var FakeView = class {
78
80
  list;
79
81
  /** For a frame: its pages and modals. */
80
82
  frame;
83
+ /** Whether its native view exists; see FAKE_UNLOADED_TAGS. `notify('loaded')` sets it. */
84
+ isLoaded;
81
85
  constructor(tag) {
82
86
  this.tag = tag;
87
+ this.isLoaded = !FAKE_UNLOADED_TAGS.has(tag);
83
88
  }
84
89
  get content() {
85
90
  return CONTENT_VIEWS.has(this.tag) ? this.children[0] : void 0;
@@ -89,6 +94,7 @@ var FakeView = class {
89
94
  }
90
95
  /** Fires an event the way NativeScript's View.notify does, with { eventName, object }. */
91
96
  notify(eventName, extra = {}) {
97
+ if (eventName === "loaded") this.isLoaded = true;
92
98
  for (const listener of [...this.listeners.get(eventName) ?? []]) listener({
93
99
  eventName,
94
100
  object: this,
@@ -341,8 +347,11 @@ var FakeAdapter = class {
341
347
  const current = parent.slots.get(property);
342
348
  if (current && !Array.isArray(current)) current.parent = null;
343
349
  if (!child) {
344
- parent.slots.delete(property);
345
- return;
350
+ if (parent.tag === "page" && property === "actionBar") child = new FakeView("actionBar");
351
+ else {
352
+ parent.slots.delete(property);
353
+ return;
354
+ }
346
355
  }
347
356
  if (child.parent) throw new Error(`<${child.tag}> already has a parent`);
348
357
  child.parent = parent;
@@ -386,6 +395,6 @@ var FakeAdapter = class {
386
395
  };
387
396
  }
388
397
  };
389
- export { FAKE_TAGS, FakeAdapter, FakeFrame, FakeList, FakeView };
398
+ export { FAKE_TAGS, FAKE_UNLOADED_TAGS, FakeAdapter, FakeFrame, FakeList, FakeView };
390
399
 
391
400
  //# sourceMappingURL=fake-adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fake-adapter.js","names":[],"sources":["../../src/fake-adapter.ts"],"sourcesContent":["// An in-memory stand-in for NativeScript's views, for tests in Node: the same tags, a parent/children\n// tree, `content` for single-child views, properties and listeners. `toXML()` prints the tree the way a\n// NativeScript XML page would describe it.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\n\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'flexboxLayout',\n 'gridLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\nconst CONTENT_VIEWS = new Set(['page', 'scrollView', 'contentView']);\nconst TEXT_VIEWS = new Set(['label', 'button', 'textField', 'textView', 'span']);\n// A listView's children are the cells it shows, which only the list itself puts there. The rest hold no child views,\n// though some take children into properties (see elements.ts).\nconst LEAF_VIEWS = new Set([\n ...TEXT_VIEWS,\n 'frame',\n 'image',\n 'switch',\n 'slider',\n 'activityIndicator',\n 'listView',\n 'actionBar',\n 'actionItem',\n 'navigationButton',\n 'datePicker',\n 'timePicker',\n 'listPicker',\n 'progress',\n 'searchBar',\n 'segmentedBar',\n 'segmentedBarItem',\n 'tabView',\n 'tabViewItem',\n 'webView',\n 'htmlView',\n 'placeholder',\n 'formattedString',\n]);\n// Names that aren't properties of a NativeScript view: what a layout or a stylesheet sets, and `element`, which\n// renderComponent probes (`'element' in into`) to tell a cursor from an element. Fake views have every other property.\nconst NOT_PROPERTIES = new Set([\n 'class',\n 'style',\n 'row',\n 'col',\n 'rowSpan',\n 'colSpan',\n 'dock',\n 'left',\n 'top',\n 'order',\n 'element',\n]);\nexport const FAKE_TAGS = new Set([...LAYOUTS, ...CONTENT_VIEWS, ...LEAF_VIEWS]);\n\nexport class FakeView {\n /** Properties as strings, for toXML() and assertions. */\n readonly props = new Map<string, string>();\n /** Properties as they were set. */\n readonly values = new Map<string, unknown>();\n readonly children: FakeView[] = [];\n readonly listeners = new Map<string, Set<Listener>>();\n /** Children that went into a property (a page's actionBar, an ActionBar's actionItems). */\n readonly slots = new Map<string, FakeView | FakeView[]>();\n parent: FakeView | null = null;\n /** For a listView bound to rows: what scrolling and layout do to it. */\n list?: FakeList;\n /** For a frame: its pages and modals. */\n frame?: FakeFrame;\n\n constructor(readonly tag: string) {}\n\n get content(): FakeView | undefined {\n return CONTENT_VIEWS.has(this.tag) ? this.children[0] : undefined;\n }\n\n get text(): string | undefined {\n return this.props.get('text');\n }\n\n /** Fires an event the way NativeScript's View.notify does, with { eventName, object }. */\n notify(eventName: string, extra: Record<string, unknown> = {}): void {\n for (const listener of [...(this.listeners.get(eventName) ?? [])]) {\n listener({ eventName, object: this, ...extra });\n }\n }\n\n /** What a user typing does to a TextField: set `text`, then fire `textChange`. */\n type(value: string): void {\n const old = this.props.get('text');\n this.props.set('text', value);\n this.values.set('text', value);\n this.notify('textChange', { propertyName: 'text', value, oldValue: old });\n }\n\n /** A slot's content: one view, a list, or nothing. */\n slot(property: string): FakeView | FakeView[] | undefined {\n return this.slots.get(property);\n }\n\n /** Every view under this one, in slots first and then children. */\n get descendants(): FakeView[] {\n const slotted = [...this.slots.values()].flat();\n return [...slotted, ...this.children];\n }\n\n get listenerCount(): number {\n let count = 0;\n for (const set of this.listeners.values()) count += set.size;\n for (const child of this.descendants) count += child.listenerCount;\n return count;\n }\n\n find(predicate: (view: FakeView) => boolean): FakeView | undefined {\n if (predicate(this)) return this;\n for (const child of this.descendants) {\n const found = child.find(predicate);\n if (found) return found;\n }\n return undefined;\n }\n\n findAll(predicate: (view: FakeView) => boolean, into: FakeView[] = []): FakeView[] {\n if (predicate(this)) into.push(this);\n for (const child of this.descendants) child.findAll(predicate, into);\n return into;\n }\n\n byId(id: string): FakeView {\n const found = this.find((view) => view.props.get('id') === id);\n if (!found) throw new Error(`No view with id ${id} in\\n${this.toXML()}`);\n return found;\n }\n\n // Slots print the way NativeScript's XML writes a property set to views: <page.actionBar>…</page.actionBar>.\n toXML(indent = ''): string {\n const props = [...this.props].map(([name, value]) => ` ${name}=\"${value}\"`).join('');\n const slots = [...this.slots].map(([property, content]) => {\n const views = [content].flat();\n const inner = views.map((view) => view.toXML(`${indent} `)).join('\\n');\n return `${indent} <${this.tag}.${property}>\\n${inner}\\n${indent} </${this.tag}.${property}>`;\n });\n const inner = [...slots, ...this.children.map((child) => child.toXML(`${indent} `))];\n if (!inner.length) return `${indent}<${this.tag}${props} />`;\n return `${indent}<${this.tag}${props}>\\n${inner.join('\\n')}\\n${indent}</${this.tag}>`;\n }\n}\n\n/**\n * What a ListView does with its cells, in memory: it shows `visible` rows from `first`, keeps a container per row on\n * screen, and puts the containers of rows that scroll away in a pool to show the next ones. As on a device, it asks\n * for cells on a layout pass, not when the row count changes.\n */\nexport class FakeList {\n count = 0;\n first = 0;\n /** How many times the list asked for a cell. */\n loads = 0;\n /** How many times the list fired loadMoreItems. */\n loadMores = 0;\n released = false;\n readonly #shown = new Map<number, FakeView>();\n readonly #pools = new Map<string, FakeView[]>();\n readonly #kinds = new WeakMap<FakeView, string>();\n #stale = false;\n\n constructor(\n readonly view: FakeView,\n readonly adapter: FakeAdapter,\n readonly cell: (container: FakeView, index: number) => void,\n readonly options: ListOptions = {},\n public visible = 10,\n ) {}\n\n setCount(count: number): void {\n this.count = count;\n this.#stale = true;\n }\n\n /** Scrolls so that row `first` is at the top, and lays out. */\n scrollTo(first: number): void {\n this.first = first;\n this.layout();\n }\n\n /** The kind of a container: the template it was made from. */\n kindOf(container: FakeView): string | undefined {\n return this.#kinds.get(container);\n }\n\n #kindAt(index: number): string {\n return this.options.kindOf?.(index) ?? 'default';\n }\n\n #pool(kind: string): FakeView[] {\n let pool = this.#pools.get(kind);\n if (!pool) this.#pools.set(kind, (pool = []));\n return pool;\n }\n\n #release(index: number, container: FakeView): void {\n this.#shown.delete(index);\n this.#pool(this.#kinds.get(container)!).push(container);\n }\n\n /**\n * The platform's layout pass: rows that left the screen give their containers back to the pool of their kind, rows\n * that came on get one of their kind (from the pool first), and after a change of rows every row on screen is asked\n * for again, as ListView.refresh() does. Loading the last row fires loadMoreItems, as ListView does on both platforms.\n */\n layout(): void {\n if (this.released) return;\n\n const end = Math.min(this.first + this.visible, this.count);\n\n for (const [index, container] of this.#shown) {\n const gone = index < this.first || index >= end;\n // After a refresh, a row whose kind changed needs a cell of its new kind.\n if (gone || (this.#stale && this.#kinds.get(container) !== this.#kindAt(index))) this.#release(index, container);\n }\n\n let loadedLast = false;\n\n for (let index = this.first; index < end; index++) {\n let container = this.#shown.get(index);\n\n if (!container) {\n const kind = this.#kindAt(index);\n container = this.#pool(kind).pop();\n if (!container) {\n container = this.adapter.createView('stackLayout')!;\n this.#kinds.set(container, kind);\n }\n this.#shown.set(index, container);\n } else if (!this.#stale) {\n continue;\n }\n\n this.loads++;\n this.cell(container, index);\n if (index === this.count - 1) loadedLast = true;\n }\n\n this.#stale = false;\n\n for (const child of this.view.children) child.parent = null;\n const shown = [...this.#shown].sort(([a], [b]) => a - b).map(([, container]) => container);\n this.view.children.splice(0, this.view.children.length, ...shown);\n for (const child of shown) child.parent = this.view;\n\n if (loadedLast) {\n this.loadMores++;\n this.view.notify('loadMoreItems');\n }\n }\n\n /** What a tap on the row at an index does: the list fires itemTap with that index and the cell. */\n tap(index: number): void {\n this.view.notify('itemTap', { index, view: this.#shown.get(index) });\n }\n\n /** Every container the list has made, on screen or in the pools. */\n get containers(): FakeView[] {\n return [...this.#shown.values(), ...[...this.#pools.values()].flat()];\n }\n}\n\n/**\n * NativeScript's Frame, in memory: a stack of pages that fire `navigatedFrom` and `navigatedTo` with\n * `isBackNavigation` as the real one does, honouring clearHistory and backstackVisible, plus modals over the top page.\n */\nexport class FakeFrame implements FrameHost<FakeView> {\n readonly stack: FakeView[] = [];\n readonly shown: Array<{ page: FakeView } & ShowOptions> = [];\n readonly modals: Array<{ view: FakeView } & ModalHostOptions> = [];\n // The page on screen stays out of the back stack once another is shown when it was shown with backstackVisible: false.\n readonly #hidden = new WeakSet<FakeView>();\n\n get top(): FakeView {\n return this.stack.at(-1)!;\n }\n\n show(page: FakeView, options: ShowOptions): void {\n const previous = this.stack.at(-1);\n this.shown.push({ page, ...options });\n previous?.notify('navigatedFrom', { isBackNavigation: false });\n if (options.clearHistory) this.stack.length = 0;\n else if (previous && this.#hidden.has(previous)) this.stack.pop();\n if (!options.backstackVisible) this.#hidden.add(page);\n this.stack.push(page);\n page.notify('navigatedTo', { isBackNavigation: false });\n }\n\n /** What Frame.goBack() does, and what Android's back button and iOS's swipe do. */\n back(): void {\n if (this.stack.length < 2) return;\n const page = this.stack.pop()!;\n page.notify('navigatedFrom', { isBackNavigation: true });\n this.top.notify('navigatedTo', { isBackNavigation: true });\n }\n\n showModal(view: FakeView, options: ModalHostOptions): void {\n this.modals.push({ view, ...options });\n }\n\n closeModal(view: FakeView, result: unknown): void {\n const index = this.modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.modals.splice(index, 1);\n modal!.onClose(result);\n }\n\n /** What a swipe down on iOS or the back button on Android does to a modal: it closes with no result. */\n dismissModal(): void {\n const modal = this.modals.pop();\n modal?.onClose();\n }\n}\n\nexport class FakeAdapter implements NativeAdapter<FakeView> {\n /** Every view the adapter made, to check that destroyed screens let go of theirs. */\n readonly created: FakeView[] = [];\n\n constructor(readonly platform: 'ios' | 'android' = 'ios') {}\n\n createView(tag: string): FakeView | null {\n if (!FAKE_TAGS.has(tag)) return null;\n const view = new FakeView(tag);\n this.created.push(view);\n return view;\n }\n\n setProperty(view: FakeView, name: string, value: unknown): void {\n if (value === null || value === undefined) {\n view.props.delete(name);\n view.values.delete(name);\n } else {\n view.props.set(name, value instanceof Date ? value.toISOString() : String(value));\n view.values.set(name, value);\n }\n }\n\n hasProperty(_view: FakeView, name: string): boolean {\n return !NOT_PROPERTIES.has(name);\n }\n\n takesText(view: FakeView): boolean {\n return TEXT_VIEWS.has(view.tag);\n }\n\n insertChild(parent: FakeView, child: FakeView, index: number): void {\n if (LEAF_VIEWS.has(parent.tag)) throw new Error(`<${parent.tag}> can't hold views`);\n if (CONTENT_VIEWS.has(parent.tag) && parent.children.length) {\n throw new Error(`<${parent.tag}> holds one view; it already has <${parent.children[0]!.tag}>`);\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.children.splice(index, 0, child);\n }\n\n removeChild(parent: FakeView, child: FakeView): void {\n const index = parent.children.indexOf(child);\n if (index === -1) throw new Error(`<${child.tag}> is not a child of <${parent.tag}>`);\n parent.children.splice(index, 1);\n child.parent = null;\n }\n\n setSlot(parent: FakeView, property: string, child: FakeView | null): void {\n const current = parent.slots.get(property);\n if (current && !Array.isArray(current)) current.parent = null;\n if (!child) {\n parent.slots.delete(property);\n return;\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.slots.set(property, child);\n }\n\n insertInSlot(parent: FakeView, property: string, child: FakeView, index: number): void {\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n const list = (parent.slots.get(property) as FakeView[] | undefined) ?? [];\n list.splice(index, 0, child);\n parent.slots.set(property, list);\n child.parent = parent;\n }\n\n removeFromSlot(parent: FakeView, property: string, child: FakeView): void {\n const list = parent.slots.get(property) as FakeView[] | undefined;\n const index = list?.indexOf(child) ?? -1;\n if (index === -1) throw new Error(`<${child.tag}> is not in <${parent.tag}>.${property}`);\n list!.splice(index, 1);\n if (!list!.length) parent.slots.delete(property);\n child.parent = null;\n }\n\n on(view: FakeView, event: string, listener: Listener): void {\n let set = view.listeners.get(event);\n if (!set) view.listeners.set(event, (set = new Set()));\n set.add(listener);\n }\n\n off(view: FakeView, event: string, listener: Listener): void {\n view.listeners.get(event)?.delete(listener);\n }\n\n frameHost(view: FakeView): FrameHost<FakeView> | null {\n if (view.tag !== 'frame') return null;\n return (view.frame ??= new FakeFrame());\n }\n\n bindList(\n view: FakeView,\n cell: (container: FakeView, index: number) => void,\n options?: ListOptions,\n ): ListBinding | null {\n if (view.tag !== 'listView') return null;\n const list = (view.list = new FakeList(view, this, cell, options));\n return {\n setCount: (count) => list.setCount(count),\n release: () => {\n list.released = true;\n },\n };\n }\n}\n"],"mappings":";AAOA,IAAM,0BAAU,IAAI,IAAI;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAM,gCAAgB,IAAI,IAAI;CAAC;CAAQ;CAAc;AAAa,CAAC;AACnE,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAS;CAAU;CAAa;CAAY;AAAM,CAAC;AAG/E,IAAM,6BAAa,IAAI,IAAI;CACzB,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,IAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAa,4BAAY,IAAI,IAAI;CAAC,GAAG;CAAS,GAAG;CAAe,GAAG;AAAU,CAAC;AAE9E,IAAa,WAAb,MAAsB;CAeC;;CAbZ,wBAAQ,IAAI,IAAoB;;CAEhC,yBAAS,IAAI,IAAqB;CAClC,WAAuB,CAAC;CACxB,4BAAY,IAA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F;AACF"}
1
+ {"version":3,"file":"fake-adapter.js","names":[],"sources":["../../src/fake-adapter.ts"],"sourcesContent":["// An in-memory stand-in for NativeScript's views, for tests in Node: the same tags, a parent/children\n// tree, `content` for single-child views, properties and listeners. `toXML()` prints the tree the way a\n// NativeScript XML page would describe it.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\n\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'flexboxLayout',\n 'gridLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\nconst CONTENT_VIEWS = new Set(['page', 'scrollView', 'contentView']);\nconst TEXT_VIEWS = new Set(['label', 'button', 'textField', 'textView', 'span']);\n// A listView's children are the cells it shows, which only the list itself puts there. The rest hold no child views,\n// though some take children into properties (see elements.ts).\nconst LEAF_VIEWS = new Set([\n ...TEXT_VIEWS,\n 'frame',\n 'image',\n 'switch',\n 'slider',\n 'activityIndicator',\n 'listView',\n 'actionBar',\n 'actionItem',\n 'navigationButton',\n 'datePicker',\n 'timePicker',\n 'listPicker',\n 'progress',\n 'searchBar',\n 'segmentedBar',\n 'segmentedBarItem',\n 'tabView',\n 'tabViewItem',\n 'webView',\n 'htmlView',\n 'placeholder',\n 'formattedString',\n]);\n// Names that aren't properties of a NativeScript view: what a layout or a stylesheet sets, and `element`, which\n// renderComponent probes (`'element' in into`) to tell a cursor from an element. Fake views have every other property.\nconst NOT_PROPERTIES = new Set([\n 'class',\n 'style',\n 'row',\n 'col',\n 'rowSpan',\n 'colSpan',\n 'dock',\n 'left',\n 'top',\n 'order',\n 'element',\n]);\nexport const FAKE_TAGS = new Set([...LAYOUTS, ...CONTENT_VIEWS, ...LEAF_VIEWS]);\n/** Tags whose views start without a native view, like those on a page still being navigated to, until `loaded`. */\nexport const FAKE_UNLOADED_TAGS = new Set<string>();\n\nexport class FakeView {\n /** Properties as strings, for toXML() and assertions. */\n readonly props = new Map<string, string>();\n /** Properties as they were set. */\n readonly values = new Map<string, unknown>();\n readonly children: FakeView[] = [];\n readonly listeners = new Map<string, Set<Listener>>();\n /** Children that went into a property (a page's actionBar, an ActionBar's actionItems). */\n readonly slots = new Map<string, FakeView | FakeView[]>();\n parent: FakeView | null = null;\n /** For a listView bound to rows: what scrolling and layout do to it. */\n list?: FakeList;\n /** For a frame: its pages and modals. */\n frame?: FakeFrame;\n\n /** Whether its native view exists; see FAKE_UNLOADED_TAGS. `notify('loaded')` sets it. */\n isLoaded: boolean;\n\n constructor(readonly tag: string) {\n this.isLoaded = !FAKE_UNLOADED_TAGS.has(tag);\n }\n\n get content(): FakeView | undefined {\n return CONTENT_VIEWS.has(this.tag) ? this.children[0] : undefined;\n }\n\n get text(): string | undefined {\n return this.props.get('text');\n }\n\n /** Fires an event the way NativeScript's View.notify does, with { eventName, object }. */\n notify(eventName: string, extra: Record<string, unknown> = {}): void {\n if (eventName === 'loaded') this.isLoaded = true;\n for (const listener of [...(this.listeners.get(eventName) ?? [])]) {\n listener({ eventName, object: this, ...extra });\n }\n }\n\n /** What a user typing does to a TextField: set `text`, then fire `textChange`. */\n type(value: string): void {\n const old = this.props.get('text');\n this.props.set('text', value);\n this.values.set('text', value);\n this.notify('textChange', { propertyName: 'text', value, oldValue: old });\n }\n\n /** A slot's content: one view, a list, or nothing. */\n slot(property: string): FakeView | FakeView[] | undefined {\n return this.slots.get(property);\n }\n\n /** Every view under this one, in slots first and then children. */\n get descendants(): FakeView[] {\n const slotted = [...this.slots.values()].flat();\n return [...slotted, ...this.children];\n }\n\n get listenerCount(): number {\n let count = 0;\n for (const set of this.listeners.values()) count += set.size;\n for (const child of this.descendants) count += child.listenerCount;\n return count;\n }\n\n find(predicate: (view: FakeView) => boolean): FakeView | undefined {\n if (predicate(this)) return this;\n for (const child of this.descendants) {\n const found = child.find(predicate);\n if (found) return found;\n }\n return undefined;\n }\n\n findAll(predicate: (view: FakeView) => boolean, into: FakeView[] = []): FakeView[] {\n if (predicate(this)) into.push(this);\n for (const child of this.descendants) child.findAll(predicate, into);\n return into;\n }\n\n byId(id: string): FakeView {\n const found = this.find((view) => view.props.get('id') === id);\n if (!found) throw new Error(`No view with id ${id} in\\n${this.toXML()}`);\n return found;\n }\n\n // Slots print the way NativeScript's XML writes a property set to views: <page.actionBar>…</page.actionBar>.\n toXML(indent = ''): string {\n const props = [...this.props].map(([name, value]) => ` ${name}=\"${value}\"`).join('');\n const slots = [...this.slots].map(([property, content]) => {\n const views = [content].flat();\n const inner = views.map((view) => view.toXML(`${indent} `)).join('\\n');\n return `${indent} <${this.tag}.${property}>\\n${inner}\\n${indent} </${this.tag}.${property}>`;\n });\n const inner = [...slots, ...this.children.map((child) => child.toXML(`${indent} `))];\n if (!inner.length) return `${indent}<${this.tag}${props} />`;\n return `${indent}<${this.tag}${props}>\\n${inner.join('\\n')}\\n${indent}</${this.tag}>`;\n }\n}\n\n/**\n * What a ListView does with its cells, in memory: it shows `visible` rows from `first`, keeps a container per row on\n * screen, and puts the containers of rows that scroll away in a pool to show the next ones. As on a device, it asks\n * for cells on a layout pass, not when the row count changes.\n */\nexport class FakeList {\n count = 0;\n first = 0;\n /** How many times the list asked for a cell. */\n loads = 0;\n /** How many times the list fired loadMoreItems. */\n loadMores = 0;\n released = false;\n readonly #shown = new Map<number, FakeView>();\n readonly #pools = new Map<string, FakeView[]>();\n readonly #kinds = new WeakMap<FakeView, string>();\n #stale = false;\n\n constructor(\n readonly view: FakeView,\n readonly adapter: FakeAdapter,\n readonly cell: (container: FakeView, index: number) => void,\n readonly options: ListOptions = {},\n public visible = 10,\n ) {}\n\n setCount(count: number): void {\n this.count = count;\n this.#stale = true;\n }\n\n /** Scrolls so that row `first` is at the top, and lays out. */\n scrollTo(first: number): void {\n this.first = first;\n this.layout();\n }\n\n /** The kind of a container: the template it was made from. */\n kindOf(container: FakeView): string | undefined {\n return this.#kinds.get(container);\n }\n\n #kindAt(index: number): string {\n return this.options.kindOf?.(index) ?? 'default';\n }\n\n #pool(kind: string): FakeView[] {\n let pool = this.#pools.get(kind);\n if (!pool) this.#pools.set(kind, (pool = []));\n return pool;\n }\n\n #release(index: number, container: FakeView): void {\n this.#shown.delete(index);\n this.#pool(this.#kinds.get(container)!).push(container);\n }\n\n /**\n * The platform's layout pass: rows that left the screen give their containers back to the pool of their kind, rows\n * that came on get one of their kind (from the pool first), and after a change of rows every row on screen is asked\n * for again, as ListView.refresh() does. Loading the last row fires loadMoreItems, as ListView does on both platforms.\n */\n layout(): void {\n if (this.released) return;\n\n const end = Math.min(this.first + this.visible, this.count);\n\n for (const [index, container] of this.#shown) {\n const gone = index < this.first || index >= end;\n // After a refresh, a row whose kind changed needs a cell of its new kind.\n if (gone || (this.#stale && this.#kinds.get(container) !== this.#kindAt(index))) this.#release(index, container);\n }\n\n let loadedLast = false;\n\n for (let index = this.first; index < end; index++) {\n let container = this.#shown.get(index);\n\n if (!container) {\n const kind = this.#kindAt(index);\n container = this.#pool(kind).pop();\n if (!container) {\n container = this.adapter.createView('stackLayout')!;\n this.#kinds.set(container, kind);\n }\n this.#shown.set(index, container);\n } else if (!this.#stale) {\n continue;\n }\n\n this.loads++;\n this.cell(container, index);\n if (index === this.count - 1) loadedLast = true;\n }\n\n this.#stale = false;\n\n for (const child of this.view.children) child.parent = null;\n const shown = [...this.#shown].sort(([a], [b]) => a - b).map(([, container]) => container);\n this.view.children.splice(0, this.view.children.length, ...shown);\n for (const child of shown) child.parent = this.view;\n\n if (loadedLast) {\n this.loadMores++;\n this.view.notify('loadMoreItems');\n }\n }\n\n /** What a tap on the row at an index does: the list fires itemTap with that index and the cell. */\n tap(index: number): void {\n this.view.notify('itemTap', { index, view: this.#shown.get(index) });\n }\n\n /** Every container the list has made, on screen or in the pools. */\n get containers(): FakeView[] {\n return [...this.#shown.values(), ...[...this.#pools.values()].flat()];\n }\n}\n\n/**\n * NativeScript's Frame, in memory: a stack of pages that fire `navigatedFrom` and `navigatedTo` with\n * `isBackNavigation` as the real one does, honouring clearHistory and backstackVisible, plus modals over the top page.\n */\nexport class FakeFrame implements FrameHost<FakeView> {\n readonly stack: FakeView[] = [];\n readonly shown: Array<{ page: FakeView } & ShowOptions> = [];\n readonly modals: Array<{ view: FakeView } & ModalHostOptions> = [];\n // The page on screen stays out of the back stack once another is shown when it was shown with backstackVisible: false.\n readonly #hidden = new WeakSet<FakeView>();\n\n get top(): FakeView {\n return this.stack.at(-1)!;\n }\n\n show(page: FakeView, options: ShowOptions): void {\n const previous = this.stack.at(-1);\n this.shown.push({ page, ...options });\n previous?.notify('navigatedFrom', { isBackNavigation: false });\n if (options.clearHistory) this.stack.length = 0;\n else if (previous && this.#hidden.has(previous)) this.stack.pop();\n if (!options.backstackVisible) this.#hidden.add(page);\n this.stack.push(page);\n page.notify('navigatedTo', { isBackNavigation: false });\n }\n\n /** What Frame.goBack() does, and what Android's back button and iOS's swipe do. */\n back(): void {\n if (this.stack.length < 2) return;\n const page = this.stack.pop()!;\n page.notify('navigatedFrom', { isBackNavigation: true });\n this.top.notify('navigatedTo', { isBackNavigation: true });\n }\n\n showModal(view: FakeView, options: ModalHostOptions): void {\n this.modals.push({ view, ...options });\n }\n\n closeModal(view: FakeView, result: unknown): void {\n const index = this.modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.modals.splice(index, 1);\n modal!.onClose(result);\n }\n\n /** What a swipe down on iOS or the back button on Android does to a modal: it closes with no result. */\n dismissModal(): void {\n const modal = this.modals.pop();\n modal?.onClose();\n }\n}\n\nexport class FakeAdapter implements NativeAdapter<FakeView> {\n /** Every view the adapter made, to check that destroyed screens let go of theirs. */\n readonly created: FakeView[] = [];\n\n constructor(readonly platform: 'ios' | 'android' = 'ios') {}\n\n createView(tag: string): FakeView | null {\n if (!FAKE_TAGS.has(tag)) return null;\n const view = new FakeView(tag);\n this.created.push(view);\n return view;\n }\n\n setProperty(view: FakeView, name: string, value: unknown): void {\n if (value === null || value === undefined) {\n view.props.delete(name);\n view.values.delete(name);\n } else {\n view.props.set(name, value instanceof Date ? value.toISOString() : String(value));\n view.values.set(name, value);\n }\n }\n\n hasProperty(_view: FakeView, name: string): boolean {\n return !NOT_PROPERTIES.has(name);\n }\n\n takesText(view: FakeView): boolean {\n return TEXT_VIEWS.has(view.tag);\n }\n\n insertChild(parent: FakeView, child: FakeView, index: number): void {\n if (LEAF_VIEWS.has(parent.tag)) throw new Error(`<${parent.tag}> can't hold views`);\n if (CONTENT_VIEWS.has(parent.tag) && parent.children.length) {\n throw new Error(`<${parent.tag}> holds one view; it already has <${parent.children[0]!.tag}>`);\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.children.splice(index, 0, child);\n }\n\n removeChild(parent: FakeView, child: FakeView): void {\n const index = parent.children.indexOf(child);\n if (index === -1) throw new Error(`<${child.tag}> is not a child of <${parent.tag}>`);\n parent.children.splice(index, 1);\n child.parent = null;\n }\n\n setSlot(parent: FakeView, property: string, child: FakeView | null): void {\n const current = parent.slots.get(property);\n if (current && !Array.isArray(current)) current.parent = null;\n if (!child) {\n // Like NativeScript's Page, which throws on a null ActionBar: the adapter has to put back a blank one.\n if (parent.tag === 'page' && property === 'actionBar') child = new FakeView('actionBar');\n else {\n parent.slots.delete(property);\n return;\n }\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.slots.set(property, child);\n }\n\n insertInSlot(parent: FakeView, property: string, child: FakeView, index: number): void {\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n const list = (parent.slots.get(property) as FakeView[] | undefined) ?? [];\n list.splice(index, 0, child);\n parent.slots.set(property, list);\n child.parent = parent;\n }\n\n removeFromSlot(parent: FakeView, property: string, child: FakeView): void {\n const list = parent.slots.get(property) as FakeView[] | undefined;\n const index = list?.indexOf(child) ?? -1;\n if (index === -1) throw new Error(`<${child.tag}> is not in <${parent.tag}>.${property}`);\n list!.splice(index, 1);\n if (!list!.length) parent.slots.delete(property);\n child.parent = null;\n }\n\n on(view: FakeView, event: string, listener: Listener): void {\n let set = view.listeners.get(event);\n if (!set) view.listeners.set(event, (set = new Set()));\n set.add(listener);\n }\n\n off(view: FakeView, event: string, listener: Listener): void {\n view.listeners.get(event)?.delete(listener);\n }\n\n frameHost(view: FakeView): FrameHost<FakeView> | null {\n if (view.tag !== 'frame') return null;\n return (view.frame ??= new FakeFrame());\n }\n\n bindList(\n view: FakeView,\n cell: (container: FakeView, index: number) => void,\n options?: ListOptions,\n ): ListBinding | null {\n if (view.tag !== 'listView') return null;\n const list = (view.list = new FakeList(view, this, cell, options));\n return {\n setCount: (count) => list.setCount(count),\n release: () => {\n list.released = true;\n },\n };\n }\n}\n"],"mappings":";AAOA,IAAM,0BAAU,IAAI,IAAI;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAM,gCAAgB,IAAI,IAAI;CAAC;CAAQ;CAAc;AAAa,CAAC;AACnE,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAS;CAAU;CAAa;CAAY;AAAM,CAAC;AAG/E,IAAM,6BAAa,IAAI,IAAI;CACzB,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,IAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAa,4BAAY,IAAI,IAAI;CAAC,GAAG;CAAS,GAAG;CAAe,GAAG;AAAU,CAAC;;AAE9E,IAAa,qCAAqB,IAAI,IAAY;AAElD,IAAa,WAAb,MAAsB;CAkBC;;CAhBZ,wBAAQ,IAAI,IAAoB;;CAEhC,yBAAS,IAAI,IAAqB;CAClC,WAAuB,CAAC;CACxB,4BAAY,IAAI,IAA2B;;CAE3C,wBAAQ,IAAI,IAAmC;CACxD,SAA0B;;CAE1B;;CAEA;;CAGA;CAEA,YAAq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AAO;GACL,WAAW,UAAU,KAAK,SAAS,KAAK;GACxC,eAAe;IACb,KAAK,WAAW;GAClB;EACF;CACF;AACF"}
@@ -1,10 +1,11 @@
1
1
  import type { ModifierLike } from '@glint/template';
2
+ import type { View as NSView } from '@nativescript/core';
2
3
  export declare const nativeView: abstract new <El extends Element = Element>() => InstanceType<ModifierLike<{
3
4
  Element: El;
4
5
  Args: {
5
6
  Positional: [callback: (view: El extends {
6
7
  view: infer View;
7
- } ? View : unknown) => void | (() => void)];
8
+ } ? View : NSView) => void | (() => void)];
8
9
  };
9
10
  }>>;
10
11
  //# sourceMappingURL=native-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native-view.d.ts","sourceRoot":"","sources":["../../src/native-view.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUpD,eAAO,MAAM,UAAU,EAAoC,QAAQ,MACjE,EAAE,SAAS,OAAO,GAAG,OAAO,OACvB,YAAY,CACjB,YAAY,CAAC;IACX,OAAO,EAAE,EAAE,CAAC;IACZ,IAAI,EAAE;QAAE,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS;YAAE,IAAI,EAAE,MAAM,IAAI,CAAA;SAAE,GAAG,IAAI,GAAG,OAAO,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;KAAE,CAAC;CACnH,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"native-view.d.ts","sourceRoot":"","sources":["../../src/native-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA+BzD,eAAO,MAAM,UAAU,EAAoC,QAAQ,MACjE,EAAE,SAAS,OAAO,GAAG,OAAO,OACvB,YAAY,CACjB,YAAY,CAAC;IACX,OAAO,EAAE,EAAE,CAAC;IAEZ,IAAI,EAAE;QAAE,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS;YAAE,IAAI,EAAE,MAAM,IAAI,CAAA;SAAE,GAAG,IAAI,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;KAAE,CAAC;CAClH,CAAC,CACH,CAAC"}
@@ -1,7 +1,27 @@
1
1
  import { modifier } from "./modifier.js";
2
+ // src/native-view.ts
3
+ function run(callback, view) {
4
+ try {
5
+ return callback(view);
6
+ } catch (error) {
7
+ console.error("{{nativeView}} callback failed:", error instanceof Error ? error.stack ?? error.message : error);
8
+ return;
9
+ }
10
+ }
2
11
  var nativeView = modifier((element, [callback]) => {
3
12
  const view = element.view;
4
- return view === void 0 ? void 0 : callback(view);
13
+ if (view === void 0) return void 0;
14
+ if (view.isLoaded !== false) return run(callback, view);
15
+ let cleanup;
16
+ const loaded = () => {
17
+ element.removeEventListener("loaded", loaded);
18
+ cleanup = run(callback, view);
19
+ };
20
+ element.addEventListener("loaded", loaded);
21
+ return () => {
22
+ element.removeEventListener("loaded", loaded);
23
+ cleanup?.();
24
+ };
5
25
  });
6
26
  export { nativeView };
7
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"native-view.js","names":["modifier","nativeViewModifier","element","callback","view","undefined","nativeView"],"sources":["../../src/native-view.ts"],"sourcesContent":["// Hands the native view to a function once the element is in the tree, for what templates don't cover: animations,\n// focus, scrolling to a position, a plugin's API.\n//\n// <stackLayout {{nativeView this.fadeIn}} />\n//\n// fadeIn = (view: StackLayout) => { view.opacity = 0; view.animate({ opacity: 1, duration: 300 }); };\n//\n// If the function returns another one, that runs when the element goes away.\nimport type { ModifierLike } from '@glint/template';\n\nimport type { NativeElement } from './dom.ts';\nimport { modifier } from './modifier.ts';\n\nconst nativeViewModifier = modifier<[(view: unknown) => void | (() => void)]>((element, [callback]) => {\n const view = (element as unknown as NativeElement).view;\n return view === undefined ? undefined : callback(view);\n});\n\nexport const nativeView = nativeViewModifier as unknown as abstract new <\n El extends Element = Element,\n>() => InstanceType<\n ModifierLike<{\n Element: El;\n Args: { Positional: [callback: (view: El extends { view: infer View } ? View : unknown) => void | (() => void)] };\n }>\n>;\n"],"mappings":";AAkBA,IAAaM,aALcN,UAAoDE,SAAS,CAACC,cAAc;CACrG,MAAMC,OAAQF,QAAqCE;CACnD,OAAOA,SAASC,KAAAA,IAAYA,KAAAA,IAAYF,SAASC,IAAI;AACvD,CAE0BH"}
1
+ {"version":3,"file":"native-view.js","names":["modifier","run","callback","view","error","console","Error","stack","message","undefined","nativeViewModifier","element","isLoaded","cleanup","loaded","removeEventListener","addEventListener","nativeView"],"sources":["../../src/native-view.ts"],"sourcesContent":["// Hands the view to a function once its native view exists, for what templates don't cover: animations, focus,\n// scrolling to a position, a plugin's API. A view on a page that is still being navigated to has no native view yet\n// (core's animations would read `nativeView.layer` from undefined), so the function waits for the view's `loaded`.\n//\n// <stackLayout {{nativeView this.fadeIn}} />\n//\n// fadeIn = (view: StackLayout) => { view.opacity = 0; view.animate({ opacity: 1, duration: 300 }); };\n//\n// If the function returns another one, that runs when the element goes away. If the function throws, the error is\n// logged and the render goes on: otherwise the modifiers after it, such as a button's {{on 'tap'}}, never install.\nimport type { ModifierLike } from '@glint/template';\nimport type { View as NSView } from '@nativescript/core';\n\nimport type { NativeElement } from './dom.ts';\nimport { modifier } from './modifier.ts';\n\nfunction run(callback: (view: unknown) => void | (() => void), view: unknown): void | (() => void) {\n try {\n return callback(view);\n } catch (error) {\n console.error('{{nativeView}} callback failed:', error instanceof Error ? (error.stack ?? error.message) : error);\n return undefined;\n }\n}\n\nconst nativeViewModifier = modifier<[(view: unknown) => void | (() => void)]>((element, [callback]) => {\n const view = (element as unknown as NativeElement).view;\n if (view === undefined) return undefined;\n if ((view as { isLoaded?: boolean }).isLoaded !== false) return run(callback, view);\n\n let cleanup: void | (() => void);\n const loaded = (): void => {\n element.removeEventListener('loaded', loaded);\n cleanup = run(callback, view);\n };\n element.addEventListener('loaded', loaded);\n return () => {\n element.removeEventListener('loaded', loaded);\n cleanup?.();\n };\n});\n\nexport const nativeView = nativeViewModifier as unknown as abstract new <\n El extends Element = Element,\n>() => InstanceType<\n ModifierLike<{\n Element: El;\n // Tags HTML also has (label, button…) keep HTML's element type: their view is typed as NativeScript's View.\n Args: { Positional: [callback: (view: El extends { view: infer View } ? View : NSView) => void | (() => void)] };\n }>\n>;\n"],"mappings":";;AAgBA,SAASC,IAAIC,UAAkDC,MAAoC;CACjG,IAAI;EACF,OAAOD,SAASC,IAAI;CACtB,SAASC,OAAO;EACdC,QAAQD,MAAM,mCAAmCA,iBAAiBE,QAASF,MAAMG,SAASH,MAAMI,UAAWJ,KAAK;EAChH;CACF;AACF;AAmBA,IAAaa,aAjBcjB,UAAoDW,SAAS,CAACT,cAAc;CACrG,MAAMC,OAAQQ,QAAqCR;CACnD,IAAIA,SAASM,KAAAA,GAAW,OAAOA,KAAAA;CAC/B,IAAKN,KAAgCS,aAAa,OAAO,OAAOX,IAAIC,UAAUC,IAAI;CAElF,IAAIU;CACJ,MAAMC,eAAqB;EACzBH,QAAQI,oBAAoB,UAAUD,MAAM;EAC5CD,UAAUZ,IAAIC,UAAUC,IAAI;CAC9B;CACAQ,QAAQK,iBAAiB,UAAUF,MAAM;CACzC,aAAa;EACXH,QAAQI,oBAAoB,UAAUD,MAAM;EAC5CD,UAAU;CACZ;AACF,CAE0BH"}
@@ -1 +1 @@
1
- {"version":3,"file":"nativescript-adapter.d.ts","sourceRoot":"","sources":["../../src/nativescript-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAyCL,KAAK,QAAQ,EAGd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA8CtE;;;;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AAK,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI;IAYzE,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAItF,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IA8BzE,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI3D,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAO5D,QAAQ,CACN,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,EAClD,OAAO,GAAE,WAAgB,GACxB,WAAW,GAAG,IAAI;CA2BtB"}
@@ -96,6 +96,10 @@ var NativeScriptAdapter = class {
96
96
  else if (parent.content === child) parent.content = null;
97
97
  }
98
98
  setSlot(parent, property, child) {
99
+ if (!child && parent instanceof Page && property === "actionBar") {
100
+ parent.actionBar = new ActionBar();
101
+ return;
102
+ }
99
103
  const bag = parent;
100
104
  if (child || bag[property]) bag[property] = child ?? null;
101
105
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nativescript-adapter.js","names":["AbsoluteLayout","ActionBar","ActionItem","ActivityIndicator","Button","ContentView","DatePicker","DockLayout","FlexboxLayout","FormattedString","Frame","GridLayout","HtmlView","Image","isIOS","Label","LayoutBase","ListPicker","ListView","NavigationButton","ObservableArray","Page","Placeholder","Progress","RootLayout","ScrollView","SearchBar","SegmentedBar","SegmentedBarItem","Slider","Span","StackLayout","Switch","TabView","TabViewItem","TextField","TextView","TimePicker","WebView","WrapLayout","defineElement","VIEWS","Map","Object","entries","absoluteLayout","actionBar","actionItem","activityIndicator","button","contentView","datePicker","dockLayout","flexboxLayout","formattedString","frame","gridLayout","htmlView","image","label","listPicker","listView","navigationButton","page","placeholder","progress","rootLayout","scrollView","searchBar","segmentedBar","segmentedBarItem","slider","span","stackLayout","switch","tabView","tabViewItem","textField","textView","timePicker","webView","wrapLayout","registerElement","tag","create","definition","set","takesText","view","ATTACHED","row","value","setRow","Number","col","setColumn","rowSpan","setRowSpan","colSpan","setColumnSpan","dock","setDock","left","setLeft","top","setTop","order","setOrder","flexGrow","setFlexGrow","flexShrink","setFlexShrink","NativeScriptAdapter","platform","createView","get","setProperty","name","className","String","style","includes","path","split","last","pop","target","key","undefined","hasProperty","replace","insertChild","parent","child","index","content","Error","typeName","removeChild","setSlot","property","bag","insertInSlot","items","splice","removeFromSlot","indexOf","change","actionItems","getItems","next","item","removeItem","addItem","current","length","on","event","listener","off","bindList","cell","options","onItemLoading","data","args","kinds","kindOf","itemTemplates","map","itemTemplateSelector","_item","itemTemplate","itemLoadingEvent","setCount","count","getItem","refresh","release"],"sources":["../../src/nativescript-adapter.ts"],"sourcesContent":["// The adapter that drives NativeScript's views on a device. Not run in this repository's tests (they need iOS or\n// Android); `pnpm typecheck` checks it against @nativescript/core's types.\n//\n// Static attributes arrive as strings, as they would from NativeScript's XML, and are assigned the same way;\n// dynamic ones arrive as their values (an array, a Date, an ImageSource) and are assigned as they are.\n// Strings: NativeScript's properties convert them themselves (`isEnabled=\"false\"`, `columns=\"*, auto\"` on a\n// GridLayout), attached layout properties such as `col` go through their layout's setter, `class` sets className\n// and `style` sets inline CSS. A dotted name sets a nested property (`ios.position` on an ActionItem).\n\nimport {\n AbsoluteLayout,\n ActionBar,\n ActionItem,\n ActivityIndicator,\n Button,\n ContentView,\n DatePicker,\n DockLayout,\n FlexboxLayout,\n FormattedString,\n Frame,\n GridLayout,\n HtmlView,\n Image,\n isIOS,\n type ItemEventData,\n Label,\n LayoutBase,\n ListPicker,\n ListView,\n NavigationButton,\n ObservableArray,\n Page,\n Placeholder,\n Progress,\n RootLayout,\n ScrollView,\n SearchBar,\n SegmentedBar,\n SegmentedBarItem,\n Slider,\n Span,\n StackLayout,\n Switch,\n TabView,\n TabViewItem,\n TextField,\n TextView,\n TimePicker,\n View,\n type ViewBase,\n WebView,\n WrapLayout,\n} from '@nativescript/core';\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport { defineElement, type ElementDefinition } from './elements.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport type { FrameHost } from './navigator.ts';\n\nconst VIEWS = new Map<string, () => ViewBase>(\n Object.entries({\n absoluteLayout: () => new AbsoluteLayout(),\n actionBar: () => new ActionBar(),\n actionItem: () => new ActionItem(),\n activityIndicator: () => new ActivityIndicator(),\n button: () => new Button(),\n contentView: () => new ContentView(),\n datePicker: () => new DatePicker(),\n dockLayout: () => new DockLayout(),\n flexboxLayout: () => new FlexboxLayout(),\n formattedString: () => new FormattedString(),\n frame: () => new Frame(),\n gridLayout: () => new GridLayout(),\n htmlView: () => new HtmlView(),\n image: () => new Image(),\n label: () => new Label(),\n listPicker: () => new ListPicker(),\n listView: () => new ListView(),\n navigationButton: () => new NavigationButton(),\n page: () => new Page(),\n placeholder: () => new Placeholder(),\n progress: () => new Progress(),\n rootLayout: () => new RootLayout(),\n scrollView: () => new ScrollView(),\n searchBar: () => new SearchBar(),\n segmentedBar: () => new SegmentedBar(),\n segmentedBarItem: () => new SegmentedBarItem(),\n slider: () => new Slider(),\n span: () => new Span(),\n stackLayout: () => new StackLayout(),\n switch: () => new Switch(),\n tabView: () => new TabView(),\n tabViewItem: () => new TabViewItem(),\n textField: () => new TextField(),\n textView: () => new TextView(),\n timePicker: () => new TimePicker(),\n webView: () => new WebView(),\n wrapLayout: () => new WrapLayout(),\n }),\n);\n\n/**\n * Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:\n * { property: 'items', list: true } })`. The definition says which children go into properties rather than being\n * child views (see elements.ts); leave it out for a view that lays out its children or has none.\n */\nexport function registerElement(tag: string, create: () => ViewBase, definition?: ElementDefinition): void {\n VIEWS.set(tag, create);\n if (definition) defineElement(tag, definition);\n}\n\n// Views whose text children become their `text` property.\nconst takesText = (view: ViewBase): boolean =>\n view instanceof Label ||\n view instanceof Button ||\n view instanceof TextField ||\n view instanceof TextView ||\n view instanceof Span;\n\n// Properties a view's parent layout reads, written on the child: GridLayout's row/col, DockLayout's dock,\n// AbsoluteLayout's left/top, FlexboxLayout's order/flexGrow…\nconst ATTACHED: Record<string, (view: View, value: string) => void> = {\n row: (view, value) => GridLayout.setRow(view, Number(value)),\n col: (view, value) => GridLayout.setColumn(view, Number(value)),\n rowSpan: (view, value) => GridLayout.setRowSpan(view, Number(value)),\n colSpan: (view, value) => GridLayout.setColumnSpan(view, Number(value)),\n dock: (view, value) => DockLayout.setDock(view, value as never),\n left: (view, value) => AbsoluteLayout.setLeft(view, Number(value)),\n top: (view, value) => AbsoluteLayout.setTop(view, Number(value)),\n order: (view, value) => FlexboxLayout.setOrder(view, Number(value)),\n flexGrow: (view, value) => FlexboxLayout.setFlexGrow(view, Number(value)),\n flexShrink: (view, value) => FlexboxLayout.setFlexShrink(view, Number(value)),\n};\n\ntype Bag = Record<string, unknown>;\n\nexport class NativeScriptAdapter implements NativeAdapter<ViewBase> {\n readonly platform = isIOS ? ('ios' as const) : ('android' as const);\n\n createView(tag: string): ViewBase | null {\n return VIEWS.get(tag)?.() ?? null;\n }\n\n setProperty(view: ViewBase, name: string, value: unknown): void {\n if (name === 'class') {\n view.className = value === null ? '' : String(value);\n } else if (name === 'style') {\n // NativeScript parses an inline CSS string assigned to `style`, as XML's style=\"…\" does.\n (view as unknown as { style: unknown }).style = value ?? '';\n } else if (ATTACHED[name]) {\n if (value !== null) ATTACHED[name](view as View, String(value));\n } else if (name.includes('.')) {\n const path = name.split('.');\n const last = path.pop()!;\n let target = view as unknown as Bag;\n for (const key of path) target = (target[key] ??= {}) as Bag;\n target[last] = value === null ? undefined : value;\n } else {\n // Unset goes back to the property's default.\n (view as unknown as Bag)[name] = value === null ? undefined : value;\n }\n }\n\n // NativeScript defines its properties as accessors on each view class, so `in` finds them (`items` on a\n // ListPicker, `date` on a DatePicker). Layout properties such as `col` aren't, and stay strings.\n hasProperty(view: ViewBase, name: string): boolean {\n return name.replace(/^(ios|android):/, '') in view;\n }\n\n takesText(view: ViewBase): boolean {\n return takesText(view);\n }\n\n insertChild(parent: ViewBase, child: ViewBase, index: number): void {\n if (parent instanceof LayoutBase) {\n parent.insertChild(child as View, index);\n } else if (parent instanceof ContentView || parent instanceof Page || parent instanceof ScrollView) {\n parent.content = child as View;\n } else {\n throw new Error(`[ember-nativescript] <${parent.typeName}> can't hold views.`);\n }\n }\n\n removeChild(parent: ViewBase, child: ViewBase): void {\n if (parent instanceof LayoutBase) {\n parent.removeChild(child as View);\n } else if ((parent as ContentView).content === child) {\n (parent as ContentView).content = null as unknown as View;\n }\n }\n\n setSlot(parent: ViewBase, property: string, child: ViewBase | null): void {\n const bag = parent as unknown as Bag;\n if (child || bag[property]) bag[property] = child ?? null;\n }\n\n // NativeScript's list properties are set three ways: an ActionBar's actionItems through addItem and removeItem, a\n // FormattedString's spans as an ObservableArray it watches, and a SegmentedBar's or TabView's items by assigning a new\n // array, which its property handler compares with the old one.\n insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void {\n this.#updateList(parent, property, (items) => items.splice(index, 0, child));\n }\n\n removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void {\n this.#updateList(parent, property, (items) => {\n const index = items.indexOf(child);\n if (index !== -1) items.splice(index, 1);\n });\n }\n\n #updateList(parent: ViewBase, property: string, change: (items: ViewBase[]) => void): void {\n if (parent instanceof ActionBar && property === 'actionItems') {\n const items = parent.actionItems.getItems();\n const next = [...items];\n change(next);\n for (const item of items) parent.actionItems.removeItem(item);\n for (const item of next) parent.actionItems.addItem(item as ActionItem);\n return;\n }\n\n const current = (parent as unknown as Bag)[property];\n if (current instanceof ObservableArray) {\n const next = [...current] as ViewBase[];\n change(next);\n current.splice(0, current.length, ...next);\n return;\n }\n\n const next = [...((current as ViewBase[] | undefined) ?? [])];\n change(next);\n (parent as unknown as Bag)[property] = next;\n }\n\n on(view: ViewBase, event: string, listener: Listener): void {\n view.on(event, listener);\n }\n\n off(view: ViewBase, event: string, listener: Listener): void {\n view.off(event, listener);\n }\n\n // Each cell is an empty StackLayout from the item template; ember-native renders the row into it. `items` is only a\n // count (an ItemsSource whose items are their indexes): the rows read their item from Ember's state, not from\n // NativeScript's binding context.\n bindList(\n view: ViewBase,\n cell: (container: ViewBase, index: number) => void,\n options: ListOptions = {},\n ): ListBinding | null {\n if (!(view instanceof ListView)) return null;\n\n const onItemLoading = (data: unknown) => {\n const args = data as ItemEventData;\n cell(args.view, args.index);\n };\n const { kinds, kindOf } = options;\n if (kinds && kindOf) {\n // One template per kind: the list keeps a pool of cells per kind, and reuses a cell only for its kind.\n view.itemTemplates = kinds.map((key) => ({ key, createView: () => new StackLayout() }));\n view.itemTemplateSelector = (_item: unknown, index: number) => kindOf(index);\n } else {\n view.itemTemplate = () => new StackLayout();\n }\n view.on(ListView.itemLoadingEvent, onItemLoading);\n\n return {\n setCount(count) {\n view.items = { length: count, getItem: (index: number) => index };\n view.refresh();\n },\n release() {\n view.off(ListView.itemLoadingEvent, onItemLoading);\n },\n };\n }\n}\n"],"mappings":";;;AA4DA,IAAMyC,QAAQ,IAAIC,IAChBC,OAAOC,QAAQ;CACbC,sBAAsB,IAAI7C,eAAe;CACzC8C,iBAAiB,IAAI7C,UAAU;CAC/B8C,kBAAkB,IAAI7C,WAAW;CACjC8C,yBAAyB,IAAI7C,kBAAkB;CAC/C8C,cAAc,IAAI7C,OAAO;CACzB8C,mBAAmB,IAAI7C,YAAY;CACnC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,qBAAqB,IAAI7C,cAAc;CACvC8C,uBAAuB,IAAI7C,gBAAgB;CAC3C8C,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;IACdvF,KAAKuD,QAAQ;KAAEY,QAAQoB;KAAOC,UAAU1C,UAAkBA;IAAM;IAChE9C,KAAKyF,QAAQ;GACf;GACAC,UAAU;IACR1F,KAAKuE,IAAI7I,SAAS2J,kBAAkBV,aAAa;GACnD;EACF;CACF;AACF"}
1
+ {"version":3,"file":"nativescript-adapter.js","names":["AbsoluteLayout","ActionBar","ActionItem","ActivityIndicator","Button","ContentView","DatePicker","DockLayout","FlexboxLayout","FormattedString","Frame","GridLayout","HtmlView","Image","isIOS","Label","LayoutBase","ListPicker","ListView","NavigationButton","ObservableArray","Page","Placeholder","Progress","RootLayout","ScrollView","SearchBar","SegmentedBar","SegmentedBarItem","Slider","Span","StackLayout","Switch","TabView","TabViewItem","TextField","TextView","TimePicker","WebView","WrapLayout","defineElement","VIEWS","Map","Object","entries","absoluteLayout","actionBar","actionItem","activityIndicator","button","contentView","datePicker","dockLayout","flexboxLayout","formattedString","frame","gridLayout","htmlView","image","label","listPicker","listView","navigationButton","page","placeholder","progress","rootLayout","scrollView","searchBar","segmentedBar","segmentedBarItem","slider","span","stackLayout","switch","tabView","tabViewItem","textField","textView","timePicker","webView","wrapLayout","registerElement","tag","create","definition","set","takesText","view","ATTACHED","row","value","setRow","Number","col","setColumn","rowSpan","setRowSpan","colSpan","setColumnSpan","dock","setDock","left","setLeft","top","setTop","order","setOrder","flexGrow","setFlexGrow","flexShrink","setFlexShrink","NativeScriptAdapter","platform","createView","get","setProperty","name","className","String","style","includes","path","split","last","pop","target","key","undefined","hasProperty","replace","insertChild","parent","child","index","content","Error","typeName","removeChild","setSlot","property","bag","insertInSlot","items","splice","removeFromSlot","indexOf","change","actionItems","getItems","next","item","removeItem","addItem","current","length","on","event","listener","off","bindList","cell","options","onItemLoading","data","args","kinds","kindOf","itemTemplates","map","itemTemplateSelector","_item","itemTemplate","itemLoadingEvent","setCount","count","getItem","refresh","release"],"sources":["../../src/nativescript-adapter.ts"],"sourcesContent":["// The adapter that drives NativeScript's views on a device. Not run in this repository's tests (they need iOS or\n// Android); `pnpm typecheck` checks it against @nativescript/core's types.\n//\n// Static attributes arrive as strings, as they would from NativeScript's XML, and are assigned the same way;\n// dynamic ones arrive as their values (an array, a Date, an ImageSource) and are assigned as they are.\n// Strings: NativeScript's properties convert them themselves (`isEnabled=\"false\"`, `columns=\"*, auto\"` on a\n// GridLayout), attached layout properties such as `col` go through their layout's setter, `class` sets className\n// and `style` sets inline CSS. A dotted name sets a nested property (`ios.position` on an ActionItem).\n\nimport {\n AbsoluteLayout,\n ActionBar,\n ActionItem,\n ActivityIndicator,\n Button,\n ContentView,\n DatePicker,\n DockLayout,\n FlexboxLayout,\n FormattedString,\n Frame,\n GridLayout,\n HtmlView,\n Image,\n isIOS,\n type ItemEventData,\n Label,\n LayoutBase,\n ListPicker,\n ListView,\n NavigationButton,\n ObservableArray,\n Page,\n Placeholder,\n Progress,\n RootLayout,\n ScrollView,\n SearchBar,\n SegmentedBar,\n SegmentedBarItem,\n Slider,\n Span,\n StackLayout,\n Switch,\n TabView,\n TabViewItem,\n TextField,\n TextView,\n TimePicker,\n View,\n type ViewBase,\n WebView,\n WrapLayout,\n} from '@nativescript/core';\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport { defineElement, type ElementDefinition } from './elements.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport type { FrameHost } from './navigator.ts';\n\nconst VIEWS = new Map<string, () => ViewBase>(\n Object.entries({\n absoluteLayout: () => new AbsoluteLayout(),\n actionBar: () => new ActionBar(),\n actionItem: () => new ActionItem(),\n activityIndicator: () => new ActivityIndicator(),\n button: () => new Button(),\n contentView: () => new ContentView(),\n datePicker: () => new DatePicker(),\n dockLayout: () => new DockLayout(),\n flexboxLayout: () => new FlexboxLayout(),\n formattedString: () => new FormattedString(),\n frame: () => new Frame(),\n gridLayout: () => new GridLayout(),\n htmlView: () => new HtmlView(),\n image: () => new Image(),\n label: () => new Label(),\n listPicker: () => new ListPicker(),\n listView: () => new ListView(),\n navigationButton: () => new NavigationButton(),\n page: () => new Page(),\n placeholder: () => new Placeholder(),\n progress: () => new Progress(),\n rootLayout: () => new RootLayout(),\n scrollView: () => new ScrollView(),\n searchBar: () => new SearchBar(),\n segmentedBar: () => new SegmentedBar(),\n segmentedBarItem: () => new SegmentedBarItem(),\n slider: () => new Slider(),\n span: () => new Span(),\n stackLayout: () => new StackLayout(),\n switch: () => new Switch(),\n tabView: () => new TabView(),\n tabViewItem: () => new TabViewItem(),\n textField: () => new TextField(),\n textView: () => new TextView(),\n timePicker: () => new TimePicker(),\n webView: () => new WebView(),\n wrapLayout: () => new WrapLayout(),\n }),\n);\n\n/**\n * Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:\n * { property: 'items', list: true } })`. The definition says which children go into properties rather than being\n * child views (see elements.ts); leave it out for a view that lays out its children or has none.\n */\nexport function registerElement(tag: string, create: () => ViewBase, definition?: ElementDefinition): void {\n VIEWS.set(tag, create);\n if (definition) defineElement(tag, definition);\n}\n\n// Views whose text children become their `text` property.\nconst takesText = (view: ViewBase): boolean =>\n view instanceof Label ||\n view instanceof Button ||\n view instanceof TextField ||\n view instanceof TextView ||\n view instanceof Span;\n\n// Properties a view's parent layout reads, written on the child: GridLayout's row/col, DockLayout's dock,\n// AbsoluteLayout's left/top, FlexboxLayout's order/flexGrow…\nconst ATTACHED: Record<string, (view: View, value: string) => void> = {\n row: (view, value) => GridLayout.setRow(view, Number(value)),\n col: (view, value) => GridLayout.setColumn(view, Number(value)),\n rowSpan: (view, value) => GridLayout.setRowSpan(view, Number(value)),\n colSpan: (view, value) => GridLayout.setColumnSpan(view, Number(value)),\n dock: (view, value) => DockLayout.setDock(view, value as never),\n left: (view, value) => AbsoluteLayout.setLeft(view, Number(value)),\n top: (view, value) => AbsoluteLayout.setTop(view, Number(value)),\n order: (view, value) => FlexboxLayout.setOrder(view, Number(value)),\n flexGrow: (view, value) => FlexboxLayout.setFlexGrow(view, Number(value)),\n flexShrink: (view, value) => FlexboxLayout.setFlexShrink(view, Number(value)),\n};\n\ntype Bag = Record<string, unknown>;\n\nexport class NativeScriptAdapter implements NativeAdapter<ViewBase> {\n readonly platform = isIOS ? ('ios' as const) : ('android' as const);\n\n createView(tag: string): ViewBase | null {\n return VIEWS.get(tag)?.() ?? null;\n }\n\n setProperty(view: ViewBase, name: string, value: unknown): void {\n if (name === 'class') {\n view.className = value === null ? '' : String(value);\n } else if (name === 'style') {\n // NativeScript parses an inline CSS string assigned to `style`, as XML's style=\"…\" does.\n (view as unknown as { style: unknown }).style = value ?? '';\n } else if (ATTACHED[name]) {\n if (value !== null) ATTACHED[name](view as View, String(value));\n } else if (name.includes('.')) {\n const path = name.split('.');\n const last = path.pop()!;\n let target = view as unknown as Bag;\n for (const key of path) target = (target[key] ??= {}) as Bag;\n target[last] = value === null ? undefined : value;\n } else {\n // Unset goes back to the property's default.\n (view as unknown as Bag)[name] = value === null ? undefined : value;\n }\n }\n\n // NativeScript defines its properties as accessors on each view class, so `in` finds them (`items` on a\n // ListPicker, `date` on a DatePicker). Layout properties such as `col` aren't, and stay strings.\n hasProperty(view: ViewBase, name: string): boolean {\n return name.replace(/^(ios|android):/, '') in view;\n }\n\n takesText(view: ViewBase): boolean {\n return takesText(view);\n }\n\n insertChild(parent: ViewBase, child: ViewBase, index: number): void {\n if (parent instanceof LayoutBase) {\n parent.insertChild(child as View, index);\n } else if (parent instanceof ContentView || parent instanceof Page || parent instanceof ScrollView) {\n parent.content = child as View;\n } else {\n throw new Error(`[ember-nativescript] <${parent.typeName}> can't hold views.`);\n }\n }\n\n removeChild(parent: ViewBase, child: ViewBase): void {\n if (parent instanceof LayoutBase) {\n parent.removeChild(child as View);\n } else if ((parent as ContentView).content === child) {\n (parent as ContentView).content = null as unknown as View;\n }\n }\n\n // A page always has an ActionBar (setting it to null throws): taking ours out puts back a blank one, as a page\n // that never had one shows.\n setSlot(parent: ViewBase, property: string, child: ViewBase | null): void {\n if (!child && parent instanceof Page && property === 'actionBar') {\n parent.actionBar = new ActionBar();\n return;\n }\n const bag = parent as unknown as Bag;\n if (child || bag[property]) bag[property] = child ?? null;\n }\n\n // NativeScript's list properties are set three ways: an ActionBar's actionItems through addItem and removeItem, a\n // FormattedString's spans as an ObservableArray it watches, and a SegmentedBar's or TabView's items by assigning a new\n // array, which its property handler compares with the old one.\n insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void {\n this.#updateList(parent, property, (items) => items.splice(index, 0, child));\n }\n\n removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void {\n this.#updateList(parent, property, (items) => {\n const index = items.indexOf(child);\n if (index !== -1) items.splice(index, 1);\n });\n }\n\n #updateList(parent: ViewBase, property: string, change: (items: ViewBase[]) => void): void {\n if (parent instanceof ActionBar && property === 'actionItems') {\n const items = parent.actionItems.getItems();\n const next = [...items];\n change(next);\n for (const item of items) parent.actionItems.removeItem(item);\n for (const item of next) parent.actionItems.addItem(item as ActionItem);\n return;\n }\n\n const current = (parent as unknown as Bag)[property];\n if (current instanceof ObservableArray) {\n const next = [...current] as ViewBase[];\n change(next);\n current.splice(0, current.length, ...next);\n return;\n }\n\n const next = [...((current as ViewBase[] | undefined) ?? [])];\n change(next);\n (parent as unknown as Bag)[property] = next;\n }\n\n on(view: ViewBase, event: string, listener: Listener): void {\n view.on(event, listener);\n }\n\n off(view: ViewBase, event: string, listener: Listener): void {\n view.off(event, listener);\n }\n\n // Each cell is an empty StackLayout from the item template; ember-native renders the row into it. `items` is only a\n // count (an ItemsSource whose items are their indexes): the rows read their item from Ember's state, not from\n // NativeScript's binding context.\n bindList(\n view: ViewBase,\n cell: (container: ViewBase, index: number) => void,\n options: ListOptions = {},\n ): ListBinding | null {\n if (!(view instanceof ListView)) return null;\n\n const onItemLoading = (data: unknown) => {\n const args = data as ItemEventData;\n cell(args.view, args.index);\n };\n const { kinds, kindOf } = options;\n if (kinds && kindOf) {\n // One template per kind: the list keeps a pool of cells per kind, and reuses a cell only for its kind.\n view.itemTemplates = kinds.map((key) => ({ key, createView: () => new StackLayout() }));\n view.itemTemplateSelector = (_item: unknown, index: number) => kindOf(index);\n } else {\n view.itemTemplate = () => new StackLayout();\n }\n view.on(ListView.itemLoadingEvent, onItemLoading);\n\n return {\n setCount(count) {\n view.items = { length: count, getItem: (index: number) => index };\n view.refresh();\n },\n release() {\n view.off(ListView.itemLoadingEvent, onItemLoading);\n },\n };\n }\n}\n"],"mappings":";;;AA4DA,IAAMyC,QAAQ,IAAIC,IAChBC,OAAOC,QAAQ;CACbC,sBAAsB,IAAI7C,eAAe;CACzC8C,iBAAiB,IAAI7C,UAAU;CAC/B8C,kBAAkB,IAAI7C,WAAW;CACjC8C,yBAAyB,IAAI7C,kBAAkB;CAC/C8C,cAAc,IAAI7C,OAAO;CACzB8C,mBAAmB,IAAI7C,YAAY;CACnC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,qBAAqB,IAAI7C,cAAc;CACvC8C,uBAAuB,IAAI7C,gBAAgB;CAC3C8C,aAAa,IAAI7C,MAAM;CACvB8C,kBAAkB,IAAI7C,WAAW;CACjC8C,gBAAgB,IAAI7C,SAAS;CAC7B8C,aAAa,IAAI7C,MAAM;CACvB8C,aAAa,IAAI5C,MAAM;CACvB6C,kBAAkB,IAAI3C,WAAW;CACjC4C,gBAAgB,IAAI3C,SAAS;CAC7B4C,wBAAwB,IAAI3C,iBAAiB;CAC7C4C,YAAY,IAAI1C,KAAK;CACrB2C,mBAAmB,IAAI1C,YAAY;CACnC2C,gBAAgB,IAAI1C,SAAS;CAC7B2C,kBAAkB,IAAI1C,WAAW;CACjC2C,kBAAkB,IAAI1C,WAAW;CACjC2C,iBAAiB,IAAI1C,UAAU;CAC/B2C,oBAAoB,IAAI1C,aAAa;CACrC2C,wBAAwB,IAAI1C,iBAAiB;CAC7C2C,cAAc,IAAI1C,OAAO;CACzB2C,YAAY,IAAI1C,KAAK;CACrB2C,mBAAmB,IAAI1C,YAAY;CACnC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