ember-nativescript 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +421 -2
- package/dist/components/NativeFrame.d.ts +28 -0
- package/dist/components/NativeFrame.d.ts.map +1 -0
- package/dist/components/NativeFrame.js +39 -0
- package/dist/components/NativeFrame.js.map +1 -0
- package/dist/components/NativeList.d.ts +32 -0
- package/dist/components/NativeList.d.ts.map +1 -0
- package/dist/components/NativeList.js +44 -0
- package/dist/components/NativeList.js.map +1 -0
- package/dist/components/Platform.d.ts +21 -0
- package/dist/components/Platform.d.ts.map +1 -0
- package/dist/components/Platform.js +22 -0
- package/dist/components/Platform.js.map +1 -0
- package/dist/src/adapter.d.ts +51 -0
- package/dist/src/adapter.d.ts.map +1 -0
- package/dist/src/bind.d.ts +12 -0
- package/dist/src/bind.d.ts.map +1 -0
- package/dist/src/bind.js +32 -0
- package/dist/src/bind.js.map +1 -0
- package/dist/src/dom.d.ts +104 -0
- package/dist/src/dom.d.ts.map +1 -0
- package/dist/src/dom.js +329 -0
- package/dist/src/dom.js.map +1 -0
- package/dist/src/elements.d.ts +17 -0
- package/dist/src/elements.d.ts.map +1 -0
- package/dist/src/elements.js +52 -0
- package/dist/src/elements.js.map +1 -0
- package/dist/src/fake-adapter.d.ts +117 -0
- package/dist/src/fake-adapter.d.ts.map +1 -0
- package/dist/src/fake-adapter.js +400 -0
- package/dist/src/fake-adapter.js.map +1 -0
- package/dist/src/frame-host.d.ts +12 -0
- package/dist/src/frame-host.d.ts.map +1 -0
- package/dist/src/frame-host.js +34 -0
- package/dist/src/frame-host.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/list.d.ts +21 -0
- package/dist/src/list.d.ts.map +1 -0
- package/dist/src/list.js +96 -0
- package/dist/src/list.js.map +1 -0
- package/dist/src/modifier.d.ts +11 -0
- package/dist/src/modifier.d.ts.map +1 -0
- package/dist/src/modifier.js +27 -0
- package/dist/src/modifier.js.map +1 -0
- package/dist/src/native-view.d.ts +11 -0
- package/dist/src/native-view.d.ts.map +1 -0
- package/dist/src/native-view.js +28 -0
- package/dist/src/native-view.js.map +1 -0
- package/dist/src/nativescript-adapter.d.ts +26 -0
- package/dist/src/nativescript-adapter.d.ts.map +1 -0
- package/dist/src/nativescript-adapter.js +172 -0
- package/dist/src/nativescript-adapter.js.map +1 -0
- package/dist/src/nativescript-app.d.ts +18 -0
- package/dist/src/nativescript-app.d.ts.map +1 -0
- package/dist/src/nativescript-app.js +32 -0
- package/dist/src/nativescript-app.js.map +1 -0
- package/dist/src/navigator.d.ts +65 -0
- package/dist/src/navigator.d.ts.map +1 -0
- package/dist/src/navigator.js +141 -0
- package/dist/src/navigator.js.map +1 -0
- package/dist/src/owner.d.ts +39 -0
- package/dist/src/owner.d.ts.map +1 -0
- package/dist/src/owner.js +185 -0
- package/dist/src/owner.js.map +1 -0
- package/dist/src/platform.d.ts +5 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +11 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/render.d.ts +18 -0
- package/dist/src/render.d.ts.map +1 -0
- package/dist/src/render.js +32 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/testing-core.d.ts +147 -0
- package/dist/src/testing-core.d.ts.map +1 -0
- package/dist/src/testing-core.js +110 -0
- package/dist/src/testing-core.js.map +1 -0
- package/dist/src/testing.d.ts +38 -0
- package/dist/src/testing.d.ts.map +1 -0
- package/dist/src/testing.js +74 -0
- package/dist/src/testing.js.map +1 -0
- package/dist/src/vendor-excludes.d.ts +6 -0
- package/dist/src/vendor-excludes.d.ts.map +1 -0
- package/dist/src/vendor-excludes.js +38 -0
- package/dist/src/vendor-excludes.js.map +1 -0
- package/dist/src/vite.d.ts +10 -0
- package/dist/src/vite.d.ts.map +1 -0
- package/dist/src/vite.js +14 -0
- package/dist/src/vite.js.map +1 -0
- package/dist/src/vitest.d.ts +5 -0
- package/dist/src/vitest.d.ts.map +1 -0
- package/dist/src/vitest.js +23 -0
- package/dist/src/vitest.js.map +1 -0
- package/dist/types/glint.d.ts +164 -0
- package/dist/vendor/runtime--fcdnjmJ.js +43 -0
- package/dist/vendor/runtime--fcdnjmJ.js.map +1 -0
- package/package.json +105 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 betocantu93
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,422 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ember-nativescript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ember components that render real native views on iOS and Android, through NativeScript, the way NativeScript-Vue
|
|
4
|
+
and React NativeScript do. No WebView: Ember 7.4's public `renderComponent` takes the document to build with, so a
|
|
5
|
+
small DOM whose elements are NativeScript views is enough for Glimmer to build, update and tear down a native tree.
|
|
6
|
+
|
|
7
|
+
```gts
|
|
8
|
+
import Component from '@glimmer/component';
|
|
9
|
+
import { tracked } from '@glimmer/tracking';
|
|
10
|
+
import { on } from '@ember/modifier';
|
|
11
|
+
import { bind, type Navigator } from 'ember-nativescript';
|
|
12
|
+
|
|
13
|
+
export default class Home extends Component<{ Args: { nav: Navigator } }> {
|
|
14
|
+
@tracked name = 'Ember';
|
|
15
|
+
|
|
16
|
+
about = () => this.args.nav.navigate(About, { args: { name: this.name } });
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<actionBar title='Hello' />
|
|
20
|
+
<stackLayout padding='16'>
|
|
21
|
+
<label text='Hello, {{this.name}}' class='title' />
|
|
22
|
+
<textField hint='Your name' {{bind this 'name'}} />
|
|
23
|
+
<button {{on 'tap' this.about}}>About</button>
|
|
24
|
+
</stackLayout>
|
|
25
|
+
</template>
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
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).
|
|
33
|
+
|
|
34
|
+
## Start an app
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
ns create my-app --template ember-nativescript-template
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
cd my-app && ns run ios
|
|
42
|
+
```
|
|
43
|
+
|
|
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:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// src/app.ts
|
|
54
|
+
import { createNativeApp } from 'ember-nativescript';
|
|
55
|
+
import Home from './components/Home.gts';
|
|
56
|
+
import Session from './services/session.ts';
|
|
57
|
+
|
|
58
|
+
createNativeApp({ main: Home, services: { session: Session } });
|
|
59
|
+
```
|
|
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
|
+
|
|
73
|
+
`createNativeApp` makes an owner, a NativeScript `Frame` and a `Navigator`, registers the navigator as the
|
|
74
|
+
`navigator` service, and shows `main` as the first screen. Services are singletons looked up lazily, as in an Ember
|
|
75
|
+
app; `modules` takes an `import.meta.glob('./services/**/*.ts', { eager: true })` instead.
|
|
76
|
+
|
|
77
|
+
## Templates
|
|
78
|
+
|
|
79
|
+
### Elements and properties
|
|
80
|
+
|
|
81
|
+
Every NativeScript core view is a tag: `stackLayout`, `gridLayout`, `flexboxLayout`, `label`, `textField`, `image`,
|
|
82
|
+
`listView`, `datePicker`, `webView`, `tabView`… A dynamic value reaches the view as it is: `items={{this.colors}}`
|
|
83
|
+
gives a ListPicker the array, `date={{this.when}}` a DatePicker the `Date`. A static attribute is a string, as
|
|
84
|
+
NativeScript's XML gives it, and the property converts it: `isEnabled='false'`, `columns='*, auto'`, `color='red'`.
|
|
85
|
+
Dotted names set a nested property (`ios.position='right'`).
|
|
86
|
+
|
|
87
|
+
### Types for every tag (Glint)
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// src/types.d.ts
|
|
91
|
+
import 'ember-nativescript/glint';
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Attributes are typed from @nativescript/core's own classes, so the checker knows every settable property of every
|
|
95
|
+
view, and what a static string may say:
|
|
96
|
+
|
|
97
|
+
```gts
|
|
98
|
+
<listPicker items={{1}} /> {{! error: any[] | ItemsSource expected }}
|
|
99
|
+
<button isEnabled='maybe' /> {{! error: boolean | 'true' | 'false' expected }}
|
|
100
|
+
<stackLayout notAProperty='x' /> {{! error: not a property of StackLayout }}
|
|
101
|
+
<button {{on 'tap' this.onTap}} /> {{! onTap gets TapGestureEventData & { currentTarget } }}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Events are typed with their real data (`textChange` has a string `value`, `swipe` a `direction`, `itemTap` an
|
|
105
|
+
`index`), and `event.currentTarget` is the element, at runtime too. `{{bind}}` checks the field exists, and
|
|
106
|
+
`{{nativeView}}` hands over the view typed by tag. A plugin's view is added with
|
|
107
|
+
`declare module 'ember-nativescript/glint' { interface NativeElementTagNameMap { pager: Pager } }`.
|
|
108
|
+
|
|
109
|
+
### Two-way binding
|
|
110
|
+
|
|
111
|
+
```gts
|
|
112
|
+
<textField {{bind this 'name'}} />
|
|
113
|
+
<switch {{bind this.settings 'notifications'}} />
|
|
114
|
+
<slider {{bind this 'volume'}} />
|
|
115
|
+
<datePicker {{bind this 'when'}} />
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Like `v-model`: the view follows the tracked field, and the field follows the user (`textChange`, `checkedChange`,
|
|
119
|
+
`valueChange`…). `property=` picks another property.
|
|
120
|
+
|
|
121
|
+
### The native view
|
|
122
|
+
|
|
123
|
+
```gts
|
|
124
|
+
<stackLayout {{nativeView this.fadeIn}} />
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
fadeIn = (view: StackLayout) => {
|
|
129
|
+
view.opacity = 0;
|
|
130
|
+
view.animate({ opacity: 1, duration: 300 });
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
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.
|
|
138
|
+
|
|
139
|
+
### Platforms
|
|
140
|
+
|
|
141
|
+
`ios:text='Tap'` and `android:text='Press'` set a property on one platform only. `<IOS>…</IOS>` and
|
|
142
|
+
`<Android>…</Android>` render their block on one platform only. In code, `isIOS()`, `isAndroid()` and `platform()`.
|
|
143
|
+
|
|
144
|
+
### Children that go into a property
|
|
145
|
+
|
|
146
|
+
Some NativeScript views take children as properties rather than as child views. ember-nativescript does what
|
|
147
|
+
NativeScript's XML builder does:
|
|
148
|
+
|
|
149
|
+
```gts
|
|
150
|
+
<actionBar title='Contacts'>
|
|
151
|
+
<navigationButton text='Back' {{on 'tap' @nav.back}} />
|
|
152
|
+
{{#if this.editing}}<actionItem text='Done' ios.position='right' {{on 'tap' this.done}} />{{/if}}
|
|
153
|
+
</actionBar>
|
|
154
|
+
<label>
|
|
155
|
+
<formattedString><span text='Bold ' fontWeight='bold' /><span text={{this.rest}} /></formattedString>
|
|
156
|
+
</label>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Child | Goes into |
|
|
160
|
+
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
161
|
+
| `actionBar` in `page` | `page.actionBar` |
|
|
162
|
+
| `navigationButton` in `actionBar` | `actionBar.navigationButton` |
|
|
163
|
+
| `actionItem` in `actionBar` | `actionBar.actionItems`, in template order (`{{#if}}` and `{{#each}}` keep it) |
|
|
164
|
+
| a view in `actionItem` | `actionItem.actionView` |
|
|
165
|
+
| `formattedString` in `label`, `button`, `textField`, `textView` | `formattedText` |
|
|
166
|
+
| `span` in `formattedString` | `spans` |
|
|
167
|
+
| `segmentedBarItem` in `segmentedBar`, `tabViewItem` in `tabView` | `items` |
|
|
168
|
+
| a view in `tabViewItem` | `tabViewItem.view` |
|
|
169
|
+
|
|
170
|
+
A plugin's view is registered with the same rules:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { registerElement } from 'ember-nativescript';
|
|
174
|
+
registerElement('pager', () => new Pager(), { childSlot: { property: 'items', list: true } });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Screens and modals
|
|
178
|
+
|
|
179
|
+
Every screen gets the navigator as `@nav`; any component can also inject it with `@service navigator`.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
nav.navigate(Details, { args: { id: 7 }, name: 'details' }); // push
|
|
183
|
+
nav.navigate(Inbox, { clearHistory: true }); // after login: nothing to go back to
|
|
184
|
+
nav.navigate(Splash, { backstackVisible: false }); // skipped by back
|
|
185
|
+
nav.back();
|
|
186
|
+
const name = await nav.showModal<string>(Rename, { args: { name } }); // undefined when dismissed
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- Options are NativeScript's: `animated`, `transition`, `clearHistory`, `backstackVisible`; modals take
|
|
190
|
+
`fullscreen`, `animated`, `stretched`.
|
|
191
|
+
- A screen is destroyed when its page leaves the Frame going back (`navigatedFrom` with `isBackNavigation`),
|
|
192
|
+
whatever started the back: `nav.back()`, Android's back button or iOS's swipe. Screens the Frame drops without a
|
|
193
|
+
back (`clearHistory`, `backstackVisible: false`) are destroyed once the next page has arrived.
|
|
194
|
+
- A modal gets `@closeModal`; `showModal` resolves with what it is called with, or `undefined` when the user
|
|
195
|
+
dismisses it. Its render is destroyed when it closes.
|
|
196
|
+
- `nav.depth`, `nav.current` (the screen's name) and `nav.modals` are tracked.
|
|
197
|
+
|
|
198
|
+
### A frame per tab
|
|
199
|
+
|
|
200
|
+
```gts
|
|
201
|
+
<tabView>
|
|
202
|
+
<tabViewItem title='Feed'><NativeFrame @main={{Feed}} /></tabViewItem>
|
|
203
|
+
<tabViewItem title='Contacts'><NativeFrame @main={{Contacts}} /></tabViewItem>
|
|
204
|
+
</tabView>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Each `NativeFrame` has a navigator of its own, given to its screens as `@nav`, so each tab keeps its own history.
|
|
208
|
+
Destroying the frame destroys its screens.
|
|
209
|
+
|
|
210
|
+
## Long lists
|
|
211
|
+
|
|
212
|
+
`{{#each}}` builds a view for every row, which is fine for a screenful and not for a thousand. NativeScript's
|
|
213
|
+
`ListView` keeps only the cells on screen: when one scrolls away, the list hands its container back to show another
|
|
214
|
+
row, and asks for it in an `itemLoading` event right before measuring it. `NativeList` drives that from Ember:
|
|
215
|
+
|
|
216
|
+
```gts
|
|
217
|
+
<NativeList @items={{this.contacts}} @row={{ContactRow}} @onItemTap={{this.open}} @onLoadMore={{this.fetchMore}} />
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
- Each cell is a render root of its own: `@row` is rendered once into the container the list made, with `@item` and
|
|
221
|
+
`@index` read from tracked state.
|
|
222
|
+
- When the list recycles the container, only that state changes, and Glimmer updates the cell in place inside a run
|
|
223
|
+
loop, so it is done before the list measures it. No views are made while scrolling.
|
|
224
|
+
- `@items` changing (a new array, or a tracked array whose items change) sets the row count and refreshes the list.
|
|
225
|
+
- `@onItemTap` gets the item and its index; `@onLoadMore` fires when the last row is shown.
|
|
226
|
+
- Destroying the list destroys every cell's render and its listeners.
|
|
227
|
+
|
|
228
|
+
Rows of several kinds take one component per kind and a function that picks it; they map to ListView's
|
|
229
|
+
`itemTemplates` and `itemTemplateSelector`, so a cell is only reused for a row of its kind:
|
|
230
|
+
|
|
231
|
+
```gts
|
|
232
|
+
<NativeList @items={{this.entries}} @rows={{hash header=DayHeader post=PostRow}} @rowKind={{this.kindOf}} />
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The row shouldn't keep state about its item, since the same row object shows other items as cells are recycled:
|
|
236
|
+
anything per item belongs on the item. `components/Contacts.gts` is a thousand contacts with a star each and
|
|
237
|
+
`components/Feed.gts` an endless feed of day headers and posts; `tests/list.test.ts` scrolls them through a fake list
|
|
238
|
+
that recycles the way ListView does.
|
|
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
|
+
|
|
273
|
+
## Compared with NativeScript-Vue
|
|
274
|
+
|
|
275
|
+
From NativeScript-Vue 3's features as commonly documented; not re-checked against its current documentation.
|
|
276
|
+
|
|
277
|
+
| | NativeScript-Vue 3 | ember-nativescript |
|
|
278
|
+
| ----------------------------------- | --------------------------------------- | -------------------------------------------------------------------- |
|
|
279
|
+
| Core views, ActionBar, spans, tabs | yes | yes |
|
|
280
|
+
| Plugin views | `registerElement` | `registerElement`, plus a Glint type in one line |
|
|
281
|
+
| Template type checking | Volar | Glint: every attribute typed from @nativescript/core, and event data |
|
|
282
|
+
| Navigation, modals with a result | `$navigateTo`, `$showModal` | `nav.navigate`, `nav.showModal`, kept in sync with the system back |
|
|
283
|
+
| A frame per tab | `<Frame>` | `<NativeFrame>` |
|
|
284
|
+
| Two-way binding | `v-model` | `{{bind}}`, with the field checked by Glint |
|
|
285
|
+
| Platform blocks | `<ios>`, `<android>`, `ios:` attributes | `<IOS>`, `<Android>`, `ios:` attributes |
|
|
286
|
+
| Recycling list, several row kinds | `<ListView>` with `v-template` and `if` | `NativeList` with `@rows` and `@rowKind` |
|
|
287
|
+
| Dependency injection | `provide`/`inject`, plugins | services and `@service`, as in any Ember app |
|
|
288
|
+
| Tests without a device | — | `startApp` in Node: tap, type, navigate, lists; the tree as XML |
|
|
289
|
+
| HMR that keeps state | yes | no |
|
|
290
|
+
| Runs on devices, community, plugins | years of it | runs on an iPhone; Android and community plugins untried |
|
|
291
|
+
|
|
292
|
+
## Layout
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
src/
|
|
296
|
+
adapter.ts the interface a toolkit implements (create a view, set a property, fill a slot, listen…)
|
|
297
|
+
dom.ts the DOM Glimmer needs, mirrored onto views through an adapter
|
|
298
|
+
elements.ts which children go into a property of their parent (page.actionBar, label.formattedText)
|
|
299
|
+
render.ts renderNative(): renderComponent into a root view
|
|
300
|
+
navigator.ts screens and modals, the way NativeScript-Vue's navigateTo and showModal work
|
|
301
|
+
frame-host.ts a NativeScript Frame as the navigator's host
|
|
302
|
+
owner.ts an owner for @service and getOwner, without @ember/application
|
|
303
|
+
platform.ts isIOS(), isAndroid()
|
|
304
|
+
nativescript-app.ts createNativeApp(): owner, Frame, navigator service, first screen
|
|
305
|
+
list.ts rows for a ListView: one render per cell, updated in place when the cell is recycled
|
|
306
|
+
bind.ts, native-view.ts the {{bind}} and {{nativeView}} modifiers
|
|
307
|
+
modifier.ts a modifier from a function, on Ember's public modifier manager API
|
|
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
|
|
311
|
+
nativescript-adapter.ts the real adapter on @nativescript/core (typechecked, not run here)
|
|
312
|
+
types/glint.d.ts Glint types for native tags, attributes and events
|
|
313
|
+
components/ NativeList, NativeFrame, Platform (the package); the rest are the demo's screens
|
|
314
|
+
template/ the starter app published as ember-nativescript-template (its tests run in pnpm test)
|
|
315
|
+
tests/ vitest against the fake adapter; tests/types is checked by Glint
|
|
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)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Develop
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
pnpm install
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
pnpm test
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
pnpm typecheck
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
pnpm build
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The tests render the .gts components (compiled by vite-plugin-ember-gts) into the fake adapter and assert the
|
|
339
|
+
native tree itself: the XML it would be in a NativeScript page, taps and typing through native-style events, slots,
|
|
340
|
+
navigation with the system back, modals, lists recycling, and that destroying a render leaves no views and no
|
|
341
|
+
listeners behind. They run in Node with no `window` or `document` global, which is also the situation on a device.
|
|
342
|
+
`pnpm typecheck` runs Glint, including `tests/types/elements.gts`, which checks what the native types accept and
|
|
343
|
+
refuse. `pnpm build` writes `dist/` (JavaScript, declarations, the Glint types).
|
|
344
|
+
|
|
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).
|
|
362
|
+
|
|
363
|
+
## What Glimmer needs from the DOM
|
|
364
|
+
|
|
365
|
+
Recorded by `tests/dom-usage.test.ts` while the components render, update, navigate and are destroyed:
|
|
366
|
+
|
|
367
|
+
- `document.createElement`, `createTextNode`, `createComment`
|
|
368
|
+
- `insertBefore`, `removeChild` (on elements and fragments)
|
|
369
|
+
- `setAttribute` (and `removeAttribute` when an attribute goes away)
|
|
370
|
+
- `addEventListener`, `removeEventListener` (from `{{on}}`)
|
|
371
|
+
- `nodeValue =` on text nodes, for dynamic text
|
|
372
|
+
- `innerHTML = ''` on the root, once, from `renderComponent`
|
|
373
|
+
- `tagName`, `id`, `classList`, read by the development build of `{{on}}` for its error messages
|
|
374
|
+
- the tree fields: `parentNode`, `firstChild`, `lastChild`, `nextSibling`, `previousSibling`, `nodeType`,
|
|
375
|
+
`namespaceURI`
|
|
376
|
+
|
|
377
|
+
A dynamic attribute is set as a property when the element has one of that name (`'id' in element`), so every getter on
|
|
378
|
+
the shim's element needs a setter. `renderComponent` checks `into instanceof Element`; there is no global `Element` on
|
|
379
|
+
a device, so the shim's element class stands in for it.
|
|
380
|
+
|
|
381
|
+
## Known gaps
|
|
382
|
+
|
|
383
|
+
- Text outside a text view (between two buttons) has nowhere to go. It is dropped and recorded in
|
|
384
|
+
`document.droppedText`; a lint rule could catch it at build time.
|
|
385
|
+
- Triple-curlies and `htmlSafe` HTML, SVG and MathML fail loudly: there is no HTML to parse. A view inside an element
|
|
386
|
+
that has no view (a `<div>` around a `<label>`) too.
|
|
387
|
+
- Glint types: a static attribute is accepted as any string where the property is a string or a color; `scroll`,
|
|
388
|
+
`submit`, `focus` and `blur` keep HTML's event types; `label`, `button`, `span`, `progress` and `frame` are typed
|
|
389
|
+
as HTML elements for modifiers (their attributes are NativeScript's).
|
|
390
|
+
- Lists: pull to refresh, sections with sticky headers and `CollectionView` aren't wrapped (they are plugins, which
|
|
391
|
+
`registerElement` reaches). Cells the list drops without reusing (Android does when the list is replaced) keep their
|
|
392
|
+
render until the list is destroyed.
|
|
393
|
+
- `ScrollView`/`Page` hold one child; the adapter replaces `content`. Several children there are an error in the fake
|
|
394
|
+
adapter and silently keep the last one on a device.
|
|
395
|
+
- HMR keeps no state, and there is no error overlay on the device.
|
|
396
|
+
- CSS is NativeScript's subset; styles are NativeScript's, not a web app's.
|
|
397
|
+
|
|
398
|
+
## Proven and unverified
|
|
399
|
+
|
|
400
|
+
Proven here: Ember 7.4 and Glimmer render, update and tear down a non-DOM tree through public API only; .gts
|
|
401
|
+
components compile with vite-plugin-ember-gts for the tests, the package and the NativeScript bundle; `vite build`
|
|
402
|
+
with @nativescript/vite produces Android and iOS bundles; the packed tarball installed into a clean copy of the
|
|
403
|
+
template builds for both platforms and passes Glint, which catches wrong attributes there.
|
|
404
|
+
|
|
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.
|
|
420
|
+
- `{{bind}}` on a device: that setting `text` only when it differs keeps the cursor where it is while typing.
|
|
421
|
+
- On the iPhone, still: the GPS in Pace, the countdown since `{{nativeView}}` waits for `loaded`, haptics, and the
|
|
422
|
+
template app itself.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type { Frame } from '@nativescript/core';
|
|
3
|
+
import { Navigator } from '../src/navigator.js';
|
|
4
|
+
import type { NativeElementFor } from '../types/glint.js';
|
|
5
|
+
interface Signature {
|
|
6
|
+
Args: {
|
|
7
|
+
main: object;
|
|
8
|
+
args?: Record<string, unknown>;
|
|
9
|
+
/** The first screen's name, for `navigator.current`. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Gets this frame's navigator, to move between its screens from outside them. */
|
|
12
|
+
onNavigator?: (navigator: Navigator) => void;
|
|
13
|
+
};
|
|
14
|
+
Element: NativeElementFor<'frame', Frame>;
|
|
15
|
+
}
|
|
16
|
+
export default class NativeFrame extends Component<Signature> {
|
|
17
|
+
navigator?: Navigator;
|
|
18
|
+
constructor(owner: object, args: Signature['Args']);
|
|
19
|
+
start: import("@glint/template").ModifierLike<{
|
|
20
|
+
Element: Element;
|
|
21
|
+
Args: {
|
|
22
|
+
Positional: [];
|
|
23
|
+
Named: Record<string, never>;
|
|
24
|
+
};
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=NativeFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeFrame.d.ts","sourceRoot":"","sources":["../../components/NativeFrame.gts"],"names":[],"mappings":"AAUA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAG3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,UAAU,SAAS;IACjB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,wDAAwD;QACxD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,kFAAkF;QAClF,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;KAC9C,CAAC;IACF,OAAO,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAC3C;AAED,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAAS,CAAC,SAAS,CAAC;IAC3D,SAAS,CAAC,EAAE,SAAS,CAAC;gBAEV,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC;IAKlD,KAAK;;;;;;OASF;CAGJ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Component from "@glimmer/component";
|
|
2
|
+
import { registerDestructor } from "@ember/destroyable";
|
|
3
|
+
import { getOwner } from "@ember/owner";
|
|
4
|
+
import { modifier } from "../src/modifier.js";
|
|
5
|
+
import { Navigator } from "../src/navigator.js";
|
|
6
|
+
import { setComponentTemplate } from "@ember/component";
|
|
7
|
+
import { createTemplateFactory } from "@ember/template-factory";
|
|
8
|
+
// components/NativeFrame.gts
|
|
9
|
+
var NativeFrame = class extends Component {
|
|
10
|
+
navigator;
|
|
11
|
+
constructor(owner, args) {
|
|
12
|
+
super(owner, args);
|
|
13
|
+
registerDestructor(this, () => this.navigator?.destroy());
|
|
14
|
+
}
|
|
15
|
+
start = modifier((element) => {
|
|
16
|
+
if (this.navigator) return;
|
|
17
|
+
const native = element;
|
|
18
|
+
const host = native.view === void 0 ? null : native.ownerDocument.adapter.frameHost?.(native.view);
|
|
19
|
+
if (!host) throw new Error(`[ember-nativescript] <${native.localName}> isn't a frame, so it can't show screens.`);
|
|
20
|
+
const navigator = this.navigator = new Navigator(native.ownerDocument, host, getOwner(this) ?? {});
|
|
21
|
+
navigator.navigate(this.args.main, {
|
|
22
|
+
args: this.args.args,
|
|
23
|
+
name: this.args.name ?? "main",
|
|
24
|
+
animated: false
|
|
25
|
+
});
|
|
26
|
+
this.args.onNavigator?.(navigator);
|
|
27
|
+
});
|
|
28
|
+
static {
|
|
29
|
+
setComponentTemplate(createTemplateFactory({
|
|
30
|
+
"id": null,
|
|
31
|
+
"block": "[[[11,\"frame\"],[17,1],[4,[30,0,[\"start\"]],null,null],[12],[13]],[\"&attrs\"],[]]",
|
|
32
|
+
"moduleName": "(unknown template module)",
|
|
33
|
+
"isStrictMode": true
|
|
34
|
+
}), this);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export { NativeFrame as default };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=NativeFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeFrame.js","names":["Component","registerDestructor","getOwner","modifier","Navigator","setComponentTemplate","createTemplateFactory","NativeFrame","navigator","constructor","owner","args","destroy","start","element","native","host","view","undefined","ownerDocument","adapter","frameHost","Error","localName","navigate","main","name","animated","onNavigator"],"sources":["../../components/NativeFrame.gts"],"sourcesContent":["// A frame of its own inside a screen: each tab of a TabView keeps its own stack of screens, as with NativeScript-Vue's\n// <Frame> in a tab.\n//\n// <tabView>\n// <tabViewItem title='Feed'><NativeFrame @main={{Feed}} /></tabViewItem>\n// <tabViewItem title='Contacts'><NativeFrame @main={{Contacts}} /></tabViewItem>\n// </tabView>\n//\n// Screens in it get this frame's navigator as @nav; `@service navigator` stays the app's. Destroying the frame\n// destroys its screens.\nimport Component from '@glimmer/component';\nimport { registerDestructor } from '@ember/destroyable';\nimport { getOwner } from '@ember/owner';\nimport type { Frame } from '@nativescript/core';\n\nimport type { NativeElement } from '../src/dom.ts';\nimport { modifier } from '../src/modifier.ts';\nimport { Navigator } from '../src/navigator.ts';\nimport type { NativeElementFor } from '../types/glint.d.ts';\n\ninterface Signature {\n Args: {\n main: object;\n args?: Record<string, unknown>;\n /** The first screen's name, for `navigator.current`. */\n name?: string;\n /** Gets this frame's navigator, to move between its screens from outside them. */\n onNavigator?: (navigator: Navigator) => void;\n };\n Element: NativeElementFor<'frame', Frame>;\n}\n\nexport default class NativeFrame extends Component<Signature> {\n navigator?: Navigator;\n\n constructor(owner: object, args: Signature['Args']) {\n super(owner as never, args);\n registerDestructor(this, () => this.navigator?.destroy());\n }\n\n start = modifier<[]>((element) => {\n if (this.navigator) return;\n const native = element as unknown as NativeElement;\n const host = native.view === undefined ? null : native.ownerDocument.adapter.frameHost?.(native.view);\n if (!host) throw new Error(`[ember-nativescript] <${native.localName}> isn't a frame, so it can't show screens.`);\n\n const navigator = (this.navigator = new Navigator(native.ownerDocument, host, getOwner(this) ?? {}));\n navigator.navigate(this.args.main, { args: this.args.args, name: this.args.name ?? 'main', animated: false });\n this.args.onNavigator?.(navigator);\n });\n\n <template><frame ...attributes {{this.start}} /></template>\n}\n"],"mappings":";;;;;;;;AAgCA,IAAqBO,cAArB,cAAyCP,UAAU;CACjDQ;CAEAC,YAAYC,OAAeC,MAAyB;EAClD,MAAMD,OAAgBC,IAAA;EACtBV,mBAAmB,YAAY,KAAKO,WAAWI,QAAA,CAAA;CACjD;CAEAC,QAAQV,UAAcW,YAAA;EACpB,IAAI,KAAKN,WAAW;EACpB,MAAMO,SAASD;EACf,MAAME,OAAOD,OAAOE,SAASC,KAAAA,IAAY,OAAOH,OAAOI,cAAcC,QAAQC,YAAYN,OAAOE,IAAI;EACpG,IAAI,CAACD,MAAM,MAAM,IAAIM,MAAM,yBAAyBP,OAAOQ,UAAS,2CAA4C;EAEhH,MAAMf,YAAa,KAAKA,YAAY,IAAIJ,UAAUW,OAAOI,eAAeH,MAAMd,SAAS,IAAI,KAAK,CAAC,CAAA;EACjGM,UAAUgB,SAAS,KAAKb,KAAKc,MAAM;GAAEd,MAAM,KAAKA,KAAKA;GAAMe,MAAM,KAAKf,KAAKe,QAAQ;GAAQC,UAAU;EAAM,CAAA;EAC3G,KAAKhB,KAAKiB,cAAcpB,SAAA;CAC1B,CAAA;CAEA;EAAAH,qBAAAC,sBAAA;GAAA,MAAA;GAAA,SAAA;GAAA,cAAA;GAAA,gBAAA;EAAA,CAAA,GAAgD,IAAW;CAAD;AAC5D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import type { ItemEventData, ListView } from '@nativescript/core';
|
|
3
|
+
import { type ListRows } from '../src/list.js';
|
|
4
|
+
import type { NativeElementFor } from '../types/glint.js';
|
|
5
|
+
interface Signature<Item> {
|
|
6
|
+
Args: {
|
|
7
|
+
items: readonly Item[];
|
|
8
|
+
row?: object;
|
|
9
|
+
rows?: Record<string, object>;
|
|
10
|
+
rowKind?: (item: Item, index: number) => string;
|
|
11
|
+
/** A tap on a row, outside any button in it. */
|
|
12
|
+
onItemTap?: (item: Item, index: number) => void;
|
|
13
|
+
/** The last row was shown: time to fetch more. */
|
|
14
|
+
onLoadMore?: () => void;
|
|
15
|
+
};
|
|
16
|
+
Element: NativeElementFor<'listView', ListView>;
|
|
17
|
+
}
|
|
18
|
+
export default class NativeList<Item = unknown> extends Component<Signature<Item>> {
|
|
19
|
+
rows?: ListRows;
|
|
20
|
+
constructor(owner: object, args: Signature<Item>['Args']);
|
|
21
|
+
showItems: import("@glint/template").ModifierLike<{
|
|
22
|
+
Element: Element;
|
|
23
|
+
Args: {
|
|
24
|
+
Positional: [readonly Item[]];
|
|
25
|
+
Named: Record<string, never>;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
itemTap: (event: ItemEventData) => void;
|
|
29
|
+
loadMore: () => void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=NativeList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeList.d.ts","sourceRoot":"","sources":["../../components/NativeList.gts"],"names":[],"mappings":"AAYA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAI3C,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAGlE,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,UAAU,SAAS,CAAC,IAAI;IACtB,IAAI,EAAE;QACJ,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;QACvB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;QAChD,gDAAgD;QAChD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QAChD,kDAAkD;QAClD,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;KACzB,CAAC;IACF,OAAO,EAAE,gBAAgB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;CACjD;AAED,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,IAAI,GAAG,OAAO,CAAE,SAAQ,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAChF,IAAI,CAAC,EAAE,QAAQ,CAAC;gBAEJ,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAOxD,SAAS;;;;;;OASN;IAEH,OAAO,GAAI,OAAO,aAAa,KAAG,IAAI,CAEpC;IAEF,QAAQ,QAAO,IAAI,CAEjB;CAUH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Component from "@glimmer/component";
|
|
2
|
+
import { registerDestructor } from "@ember/destroyable";
|
|
3
|
+
import { on } from "@ember/modifier";
|
|
4
|
+
import { getOwner } from "@ember/owner";
|
|
5
|
+
import { bindListRows } from "../src/list.js";
|
|
6
|
+
import { modifier } from "../src/modifier.js";
|
|
7
|
+
import { setComponentTemplate } from "@ember/component";
|
|
8
|
+
import { createTemplateFactory } from "@ember/template-factory";
|
|
9
|
+
// components/NativeList.gts
|
|
10
|
+
var NativeList = class extends Component {
|
|
11
|
+
rows;
|
|
12
|
+
constructor(owner, args) {
|
|
13
|
+
super(owner, args);
|
|
14
|
+
registerDestructor(this, () => this.rows?.destroy());
|
|
15
|
+
}
|
|
16
|
+
showItems = modifier((element, [items]) => {
|
|
17
|
+
const all = Array.from(items);
|
|
18
|
+
this.rows ??= bindListRows(element, {
|
|
19
|
+
owner: getOwner(this) ?? {},
|
|
20
|
+
row: this.args.row,
|
|
21
|
+
rows: this.args.rows,
|
|
22
|
+
kindOf: this.args.rowKind
|
|
23
|
+
});
|
|
24
|
+
this.rows.update(all);
|
|
25
|
+
});
|
|
26
|
+
itemTap = (event) => {
|
|
27
|
+
this.args.onItemTap?.(this.rows?.itemAt(event.index), event.index);
|
|
28
|
+
};
|
|
29
|
+
loadMore = () => {
|
|
30
|
+
this.args.onLoadMore?.();
|
|
31
|
+
};
|
|
32
|
+
static {
|
|
33
|
+
setComponentTemplate(createTemplateFactory({
|
|
34
|
+
"id": null,
|
|
35
|
+
"block": "[[[11,\"listView\"],[17,1],[4,[30,0,[\"showItems\"]],[[30,2]],null],[4,[32,0],[\"itemTap\",[30,0,[\"itemTap\"]]],null],[4,[32,0],[\"loadMoreItems\",[30,0,[\"loadMore\"]]],null],[12],[13]],[\"&attrs\",\"@items\"],[]]",
|
|
36
|
+
"moduleName": "(unknown template module)",
|
|
37
|
+
"scope": () => ({ on }),
|
|
38
|
+
"isStrictMode": true
|
|
39
|
+
}), this);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export { NativeList as default };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=NativeList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeList.js","names":["Component","registerDestructor","on","getOwner","bindListRows","modifier","setComponentTemplate","createTemplateFactory","NativeList","rows","constructor","owner","args","destroy","showItems","element","items","all","Array","from","row","kindOf","rowKind","update","itemTap","event","onItemTap","itemAt","index","loadMore","onLoadMore"],"sources":["../../components/NativeList.gts"],"sourcesContent":["// A long list on NativeScript's ListView, which keeps only the rows on screen and recycles them as you scroll.\n// `@row` is the component for one row; it gets `@item` and `@index`.\n//\n// <NativeList @items={{this.todos}} @row={{TodoRow}} @onItemTap={{this.open}} @onLoadMore={{this.more}} />\n//\n// Rows of several kinds (a header, then its contacts) take one component per kind and a function that picks it:\n//\n// <NativeList @items={{this.entries}} @rows={{hash header=Header contact=ContactRow}} @rowKind={{this.kindOf}} />\n//\n// The list keeps cells by kind and reuses a cell only for a row of the same kind, as ListView's itemTemplates do.\n// A row is rendered once per cell and updated in place when the cell is recycled, so it shouldn't keep state of its\n// own about its item: anything per item belongs on the item. For a short list, {{#each}} inside a scrollView is simpler.\nimport Component from '@glimmer/component';\nimport { registerDestructor } from '@ember/destroyable';\nimport { on } from '@ember/modifier';\nimport { getOwner } from '@ember/owner';\nimport type { ItemEventData, ListView } from '@nativescript/core';\n\nimport type { NativeElement } from '../src/dom.ts';\nimport { bindListRows, type ListRows } from '../src/list.ts';\nimport { modifier } from '../src/modifier.ts';\nimport type { NativeElementFor } from '../types/glint.d.ts';\n\ninterface Signature<Item> {\n Args: {\n items: readonly Item[];\n row?: object;\n rows?: Record<string, object>;\n rowKind?: (item: Item, index: number) => string;\n /** A tap on a row, outside any button in it. */\n onItemTap?: (item: Item, index: number) => void;\n /** The last row was shown: time to fetch more. */\n onLoadMore?: () => void;\n };\n Element: NativeElementFor<'listView', ListView>;\n}\n\nexport default class NativeList<Item = unknown> extends Component<Signature<Item>> {\n rows?: ListRows;\n\n constructor(owner: object, args: Signature<Item>['Args']) {\n super(owner as never, args);\n registerDestructor(this, () => this.rows?.destroy());\n }\n\n // Runs when the list view is inserted and again when @items changes: copying the items reads all of them, so\n // replacing one of a tracked array's items counts as a change too.\n showItems = modifier<[readonly Item[]]>((element, [items]) => {\n const all = Array.from(items);\n this.rows ??= bindListRows(element as unknown as NativeElement, {\n owner: getOwner(this) ?? {},\n row: this.args.row,\n rows: this.args.rows,\n kindOf: this.args.rowKind as ((item: unknown, index: number) => string) | undefined,\n });\n this.rows.update(all);\n });\n\n itemTap = (event: ItemEventData): void => {\n this.args.onItemTap?.(this.rows?.itemAt(event.index) as Item, event.index);\n };\n\n loadMore = (): void => {\n this.args.onLoadMore?.();\n };\n\n <template>\n <listView\n ...attributes\n {{this.showItems @items}}\n {{on 'itemTap' this.itemTap}}\n {{on 'loadMoreItems' this.loadMore}}\n />\n </template>\n}\n"],"mappings":";;;;;;;;;AAqCA,IAAqBQ,aAArB,cAAwDR,UAAoB;CAC1ES;CAEAC,YAAYC,OAAeC,MAA+B;EACxD,MAAMD,OAAgBC,IAAA;EACtBX,mBAAmB,YAAY,KAAKQ,MAAMI,QAAA,CAAA;CAC5C;CAIAC,YAAYT,UAA6BU,SAAS,CAACC,WAAM;EACvD,MAAMC,MAAMC,MAAMC,KAAKH,KAAA;EACvB,KAAKP,SAASL,aAAaW,SAAqC;GAC9DJ,OAAOR,SAAS,IAAI,KAAK,CAAC;GAC1BiB,KAAK,KAAKR,KAAKQ;GACfX,MAAM,KAAKG,KAAKH;GAChBY,QAAQ,KAAKT,KAAKU;EACpB,CAAA;EACA,KAAKb,KAAKc,OAAON,GAAA;CACnB,CAAA;CAEAO,WAAWC,UAA2B;EACpC,KAAKb,KAAKc,YAAY,KAAKjB,MAAMkB,OAAOF,MAAMG,KAAK,GAAWH,MAAMG,KAAK;CAC3E;CAEAC,iBAAmB;EACjB,KAAKjB,KAAKkB,aAAU;CACtB;CAEA;EAAAxB,qBAAAC,sBAAA;GAAA,MAAA;GAAA,SAAA;GAAA,cAAA;GAAA,gBAAA,EAAAL,GAAA;GAAA,gBAAA;EAAA,CAAA,GAOA,IAAW;CAAD;AACZ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Signature {
|
|
2
|
+
Blocks: {
|
|
3
|
+
default: [];
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export declare const IOS: import("@ember/component/template-only").TemplateOnlyComponent<never> & (abstract new () => import("@glint/template/-private/integration").InvokableInstance<() => import("@glint/template/-private/integration").ComponentReturn<import("@glint/template/-private/integration").FlattenBlockParams<{
|
|
7
|
+
default: {
|
|
8
|
+
Params: {
|
|
9
|
+
Positional: [];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}>, unknown>> & import("@glint/template/-private/integration").HasContext<import("@glint/ember-tsc/types").ComponentContext<null, Signature>>);
|
|
13
|
+
export declare const Android: import("@ember/component/template-only").TemplateOnlyComponent<never> & (abstract new () => import("@glint/template/-private/integration").InvokableInstance<() => import("@glint/template/-private/integration").ComponentReturn<import("@glint/template/-private/integration").FlattenBlockParams<{
|
|
14
|
+
default: {
|
|
15
|
+
Params: {
|
|
16
|
+
Positional: [];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}>, unknown>> & import("@glint/template/-private/integration").HasContext<import("@glint/ember-tsc/types").ComponentContext<null, Signature>>);
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../components/Platform.gts"],"names":[],"mappings":"AAQA,UAAU,SAAS;IACjB,MAAM,EAAE;QAAE,OAAO,EAAE,EAAE,CAAA;KAAE,CAAC;CACzB;AAED,eAAO,MAAM,GAAG;;;;;;8IAAgF,CAAC;AACjG,eAAO,MAAM,OAAO;;;;;;8IAAoF,CAAC"}
|