ember-nativescript 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +353 -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 +113 -0
- package/dist/src/fake-adapter.d.ts.map +1 -0
- package/dist/src/fake-adapter.js +391 -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 +10 -0
- package/dist/src/native-view.d.ts.map +1 -0
- package/dist/src/native-view.js +8 -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 +168 -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/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 +72 -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,354 @@
|
|
|
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:** 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).
|
|
32
|
+
|
|
33
|
+
## Start an app
|
|
34
|
+
|
|
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
|
+
```bash
|
|
39
|
+
cp -r template my-app && cd my-app && pnpm install
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
ns create resources --template @nativescript/template-blank-ts && cp -r resources/App_Resources . && rm -rf resources
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm ios
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// src/app.ts
|
|
52
|
+
import { createNativeApp } from 'ember-nativescript';
|
|
53
|
+
import Home from './components/Home.gts';
|
|
54
|
+
import Session from './services/session.ts';
|
|
55
|
+
|
|
56
|
+
createNativeApp({ main: Home, services: { session: Session } });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`createNativeApp` makes an owner, a NativeScript `Frame` and a `Navigator`, registers the navigator as the
|
|
60
|
+
`navigator` service, and shows `main` as the first screen. Services are singletons looked up lazily, as in an Ember
|
|
61
|
+
app; `modules` takes an `import.meta.glob('./services/**/*.ts', { eager: true })` instead.
|
|
62
|
+
|
|
63
|
+
## Templates
|
|
64
|
+
|
|
65
|
+
### Elements and properties
|
|
66
|
+
|
|
67
|
+
Every NativeScript core view is a tag: `stackLayout`, `gridLayout`, `flexboxLayout`, `label`, `textField`, `image`,
|
|
68
|
+
`listView`, `datePicker`, `webView`, `tabView`… A dynamic value reaches the view as it is: `items={{this.colors}}`
|
|
69
|
+
gives a ListPicker the array, `date={{this.when}}` a DatePicker the `Date`. A static attribute is a string, as
|
|
70
|
+
NativeScript's XML gives it, and the property converts it: `isEnabled='false'`, `columns='*, auto'`, `color='red'`.
|
|
71
|
+
Dotted names set a nested property (`ios.position='right'`).
|
|
72
|
+
|
|
73
|
+
### Types for every tag (Glint)
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// src/types.d.ts
|
|
77
|
+
import 'ember-nativescript/glint';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Attributes are typed from @nativescript/core's own classes, so the checker knows every settable property of every
|
|
81
|
+
view, and what a static string may say:
|
|
82
|
+
|
|
83
|
+
```gts
|
|
84
|
+
<listPicker items={{1}} /> {{! error: any[] | ItemsSource expected }}
|
|
85
|
+
<button isEnabled='maybe' /> {{! error: boolean | 'true' | 'false' expected }}
|
|
86
|
+
<stackLayout notAProperty='x' /> {{! error: not a property of StackLayout }}
|
|
87
|
+
<button {{on 'tap' this.onTap}} /> {{! onTap gets TapGestureEventData & { currentTarget } }}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Events are typed with their real data (`textChange` has a string `value`, `swipe` a `direction`, `itemTap` an
|
|
91
|
+
`index`), and `event.currentTarget` is the element, at runtime too. `{{bind}}` checks the field exists, and
|
|
92
|
+
`{{nativeView}}` hands over the view typed by tag. A plugin's view is added with
|
|
93
|
+
`declare module 'ember-nativescript/glint' { interface NativeElementTagNameMap { pager: Pager } }`.
|
|
94
|
+
|
|
95
|
+
### Two-way binding
|
|
96
|
+
|
|
97
|
+
```gts
|
|
98
|
+
<textField {{bind this 'name'}} />
|
|
99
|
+
<switch {{bind this.settings 'notifications'}} />
|
|
100
|
+
<slider {{bind this 'volume'}} />
|
|
101
|
+
<datePicker {{bind this 'when'}} />
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Like `v-model`: the view follows the tracked field, and the field follows the user (`textChange`, `checkedChange`,
|
|
105
|
+
`valueChange`…). `property=` picks another property.
|
|
106
|
+
|
|
107
|
+
### The native view
|
|
108
|
+
|
|
109
|
+
```gts
|
|
110
|
+
<stackLayout {{nativeView this.fadeIn}} />
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
fadeIn = (view: StackLayout) => {
|
|
115
|
+
view.opacity = 0;
|
|
116
|
+
view.animate({ opacity: 1, duration: 300 });
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
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.
|
|
122
|
+
|
|
123
|
+
### Platforms
|
|
124
|
+
|
|
125
|
+
`ios:text='Tap'` and `android:text='Press'` set a property on one platform only. `<IOS>…</IOS>` and
|
|
126
|
+
`<Android>…</Android>` render their block on one platform only. In code, `isIOS()`, `isAndroid()` and `platform()`.
|
|
127
|
+
|
|
128
|
+
### Children that go into a property
|
|
129
|
+
|
|
130
|
+
Some NativeScript views take children as properties rather than as child views. ember-nativescript does what
|
|
131
|
+
NativeScript's XML builder does:
|
|
132
|
+
|
|
133
|
+
```gts
|
|
134
|
+
<actionBar title='Contacts'>
|
|
135
|
+
<navigationButton text='Back' {{on 'tap' @nav.back}} />
|
|
136
|
+
{{#if this.editing}}<actionItem text='Done' ios.position='right' {{on 'tap' this.done}} />{{/if}}
|
|
137
|
+
</actionBar>
|
|
138
|
+
<label>
|
|
139
|
+
<formattedString><span text='Bold ' fontWeight='bold' /><span text={{this.rest}} /></formattedString>
|
|
140
|
+
</label>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| Child | Goes into |
|
|
144
|
+
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
145
|
+
| `actionBar` in `page` | `page.actionBar` |
|
|
146
|
+
| `navigationButton` in `actionBar` | `actionBar.navigationButton` |
|
|
147
|
+
| `actionItem` in `actionBar` | `actionBar.actionItems`, in template order (`{{#if}}` and `{{#each}}` keep it) |
|
|
148
|
+
| a view in `actionItem` | `actionItem.actionView` |
|
|
149
|
+
| `formattedString` in `label`, `button`, `textField`, `textView` | `formattedText` |
|
|
150
|
+
| `span` in `formattedString` | `spans` |
|
|
151
|
+
| `segmentedBarItem` in `segmentedBar`, `tabViewItem` in `tabView` | `items` |
|
|
152
|
+
| a view in `tabViewItem` | `tabViewItem.view` |
|
|
153
|
+
|
|
154
|
+
A plugin's view is registered with the same rules:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { registerElement } from 'ember-nativescript';
|
|
158
|
+
registerElement('pager', () => new Pager(), { childSlot: { property: 'items', list: true } });
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Screens and modals
|
|
162
|
+
|
|
163
|
+
Every screen gets the navigator as `@nav`; any component can also inject it with `@service navigator`.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
nav.navigate(Details, { args: { id: 7 }, name: 'details' }); // push
|
|
167
|
+
nav.navigate(Inbox, { clearHistory: true }); // after login: nothing to go back to
|
|
168
|
+
nav.navigate(Splash, { backstackVisible: false }); // skipped by back
|
|
169
|
+
nav.back();
|
|
170
|
+
const name = await nav.showModal<string>(Rename, { args: { name } }); // undefined when dismissed
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- Options are NativeScript's: `animated`, `transition`, `clearHistory`, `backstackVisible`; modals take
|
|
174
|
+
`fullscreen`, `animated`, `stretched`.
|
|
175
|
+
- A screen is destroyed when its page leaves the Frame going back (`navigatedFrom` with `isBackNavigation`),
|
|
176
|
+
whatever started the back: `nav.back()`, Android's back button or iOS's swipe. Screens the Frame drops without a
|
|
177
|
+
back (`clearHistory`, `backstackVisible: false`) are destroyed once the next page has arrived.
|
|
178
|
+
- A modal gets `@closeModal`; `showModal` resolves with what it is called with, or `undefined` when the user
|
|
179
|
+
dismisses it. Its render is destroyed when it closes.
|
|
180
|
+
- `nav.depth`, `nav.current` (the screen's name) and `nav.modals` are tracked.
|
|
181
|
+
|
|
182
|
+
### A frame per tab
|
|
183
|
+
|
|
184
|
+
```gts
|
|
185
|
+
<tabView>
|
|
186
|
+
<tabViewItem title='Feed'><NativeFrame @main={{Feed}} /></tabViewItem>
|
|
187
|
+
<tabViewItem title='Contacts'><NativeFrame @main={{Contacts}} /></tabViewItem>
|
|
188
|
+
</tabView>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Each `NativeFrame` has a navigator of its own, given to its screens as `@nav`, so each tab keeps its own history.
|
|
192
|
+
Destroying the frame destroys its screens.
|
|
193
|
+
|
|
194
|
+
## Long lists
|
|
195
|
+
|
|
196
|
+
`{{#each}}` builds a view for every row, which is fine for a screenful and not for a thousand. NativeScript's
|
|
197
|
+
`ListView` keeps only the cells on screen: when one scrolls away, the list hands its container back to show another
|
|
198
|
+
row, and asks for it in an `itemLoading` event right before measuring it. `NativeList` drives that from Ember:
|
|
199
|
+
|
|
200
|
+
```gts
|
|
201
|
+
<NativeList @items={{this.contacts}} @row={{ContactRow}} @onItemTap={{this.open}} @onLoadMore={{this.fetchMore}} />
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- Each cell is a render root of its own: `@row` is rendered once into the container the list made, with `@item` and
|
|
205
|
+
`@index` read from tracked state.
|
|
206
|
+
- When the list recycles the container, only that state changes, and Glimmer updates the cell in place inside a run
|
|
207
|
+
loop, so it is done before the list measures it. No views are made while scrolling.
|
|
208
|
+
- `@items` changing (a new array, or a tracked array whose items change) sets the row count and refreshes the list.
|
|
209
|
+
- `@onItemTap` gets the item and its index; `@onLoadMore` fires when the last row is shown.
|
|
210
|
+
- Destroying the list destroys every cell's render and its listeners.
|
|
211
|
+
|
|
212
|
+
Rows of several kinds take one component per kind and a function that picks it; they map to ListView's
|
|
213
|
+
`itemTemplates` and `itemTemplateSelector`, so a cell is only reused for a row of its kind:
|
|
214
|
+
|
|
215
|
+
```gts
|
|
216
|
+
<NativeList @items={{this.entries}} @rows={{hash header=DayHeader post=PostRow}} @rowKind={{this.kindOf}} />
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The row shouldn't keep state about its item, since the same row object shows other items as cells are recycled:
|
|
220
|
+
anything per item belongs on the item. `components/Contacts.gts` is a thousand contacts with a star each and
|
|
221
|
+
`components/Feed.gts` an endless feed of day headers and posts; `tests/list.test.ts` scrolls them through a fake list
|
|
222
|
+
that recycles the way ListView does.
|
|
223
|
+
|
|
224
|
+
## Compared with NativeScript-Vue
|
|
225
|
+
|
|
226
|
+
From NativeScript-Vue 3's features as commonly documented; not re-checked against its current documentation.
|
|
227
|
+
|
|
228
|
+
| | NativeScript-Vue 3 | ember-nativescript |
|
|
229
|
+
| ----------------------------------- | --------------------------------------- | -------------------------------------------------------------------- |
|
|
230
|
+
| Core views, ActionBar, spans, tabs | yes | yes |
|
|
231
|
+
| Plugin views | `registerElement` | `registerElement`, plus a Glint type in one line |
|
|
232
|
+
| Template type checking | Volar | Glint: every attribute typed from @nativescript/core, and event data |
|
|
233
|
+
| Navigation, modals with a result | `$navigateTo`, `$showModal` | `nav.navigate`, `nav.showModal`, kept in sync with the system back |
|
|
234
|
+
| A frame per tab | `<Frame>` | `<NativeFrame>` |
|
|
235
|
+
| Two-way binding | `v-model` | `{{bind}}`, with the field checked by Glint |
|
|
236
|
+
| Platform blocks | `<ios>`, `<android>`, `ios:` attributes | `<IOS>`, `<Android>`, `ios:` attributes |
|
|
237
|
+
| Recycling list, several row kinds | `<ListView>` with `v-template` and `if` | `NativeList` with `@rows` and `@rowKind` |
|
|
238
|
+
| 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 |
|
|
240
|
+
| HMR that keeps state | yes | no |
|
|
241
|
+
| Runs on devices, community, plugins | years of it | not run on a device yet |
|
|
242
|
+
|
|
243
|
+
## Layout
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
src/
|
|
247
|
+
adapter.ts the interface a toolkit implements (create a view, set a property, fill a slot, listen…)
|
|
248
|
+
dom.ts the DOM Glimmer needs, mirrored onto views through an adapter
|
|
249
|
+
elements.ts which children go into a property of their parent (page.actionBar, label.formattedText)
|
|
250
|
+
render.ts renderNative(): renderComponent into a root view
|
|
251
|
+
navigator.ts screens and modals, the way NativeScript-Vue's navigateTo and showModal work
|
|
252
|
+
frame-host.ts a NativeScript Frame as the navigator's host
|
|
253
|
+
owner.ts an owner for @service and getOwner, without @ember/application
|
|
254
|
+
platform.ts isIOS(), isAndroid()
|
|
255
|
+
nativescript-app.ts createNativeApp(): owner, Frame, navigator service, first screen
|
|
256
|
+
list.ts rows for a ListView: one render per cell, updated in place when the cell is recycled
|
|
257
|
+
bind.ts, native-view.ts the {{bind}} and {{nativeView}} modifiers
|
|
258
|
+
modifier.ts a modifier from a function, on Ember's public modifier manager API
|
|
259
|
+
fake-adapter.ts in-memory views and frame for tests in Node; prints the tree as XML
|
|
260
|
+
nativescript-adapter.ts the real adapter on @nativescript/core (typechecked, not run here)
|
|
261
|
+
types/glint.d.ts Glint types for native tags, attributes and events
|
|
262
|
+
components/ NativeList, NativeFrame, Platform (the package); the rest are the demo's screens
|
|
263
|
+
template/ a starter app
|
|
264
|
+
tests/ vitest against the fake adapter; tests/types is checked by Glint
|
|
265
|
+
app/ the demo on @nativescript/vite, booting components/Home.gts
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Develop
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
pnpm install
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
pnpm test
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
pnpm typecheck
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
pnpm build
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
The tests render the .gts components (compiled by vite-plugin-ember-gts) into the fake adapter and assert the
|
|
287
|
+
native tree itself: the XML it would be in a NativeScript page, taps and typing through native-style events, slots,
|
|
288
|
+
navigation with the system back, modals, lists recycling, and that destroying a render leaves no views and no
|
|
289
|
+
listeners behind. They run in Node with no `window` or `document` global, which is also the situation on a device.
|
|
290
|
+
`pnpm typecheck` runs Glint, including `tests/types/elements.gts`, which checks what the native types accept and
|
|
291
|
+
refuse. `pnpm build` writes `dist/` (JavaScript, declarations, the Glint types).
|
|
292
|
+
|
|
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).
|
|
295
|
+
|
|
296
|
+
## What Glimmer needs from the DOM
|
|
297
|
+
|
|
298
|
+
Recorded by `tests/dom-usage.test.ts` while the components render, update, navigate and are destroyed:
|
|
299
|
+
|
|
300
|
+
- `document.createElement`, `createTextNode`, `createComment`
|
|
301
|
+
- `insertBefore`, `removeChild` (on elements and fragments)
|
|
302
|
+
- `setAttribute` (and `removeAttribute` when an attribute goes away)
|
|
303
|
+
- `addEventListener`, `removeEventListener` (from `{{on}}`)
|
|
304
|
+
- `nodeValue =` on text nodes, for dynamic text
|
|
305
|
+
- `innerHTML = ''` on the root, once, from `renderComponent`
|
|
306
|
+
- `tagName`, `id`, `classList`, read by the development build of `{{on}}` for its error messages
|
|
307
|
+
- the tree fields: `parentNode`, `firstChild`, `lastChild`, `nextSibling`, `previousSibling`, `nodeType`,
|
|
308
|
+
`namespaceURI`
|
|
309
|
+
|
|
310
|
+
A dynamic attribute is set as a property when the element has one of that name (`'id' in element`), so every getter on
|
|
311
|
+
the shim's element needs a setter. `renderComponent` checks `into instanceof Element`; there is no global `Element` on
|
|
312
|
+
a device, so the shim's element class stands in for it.
|
|
313
|
+
|
|
314
|
+
## Known gaps
|
|
315
|
+
|
|
316
|
+
- Text outside a text view (between two buttons) has nowhere to go. It is dropped and recorded in
|
|
317
|
+
`document.droppedText`; a lint rule could catch it at build time.
|
|
318
|
+
- Triple-curlies and `htmlSafe` HTML, SVG and MathML fail loudly: there is no HTML to parse. A view inside an element
|
|
319
|
+
that has no view (a `<div>` around a `<label>`) too.
|
|
320
|
+
- Glint types: a static attribute is accepted as any string where the property is a string or a color; `scroll`,
|
|
321
|
+
`submit`, `focus` and `blur` keep HTML's event types; `label`, `button`, `span`, `progress` and `frame` are typed
|
|
322
|
+
as HTML elements for modifiers (their attributes are NativeScript's).
|
|
323
|
+
- Lists: pull to refresh, sections with sticky headers and `CollectionView` aren't wrapped (they are plugins, which
|
|
324
|
+
`registerElement` reaches). Cells the list drops without reusing (Android does when the list is replaced) keep their
|
|
325
|
+
render until the list is destroyed.
|
|
326
|
+
- `ScrollView`/`Page` hold one child; the adapter replaces `content`. Several children there are an error in the fake
|
|
327
|
+
adapter and silently keep the last one on a device.
|
|
328
|
+
- HMR keeps no state, and there is no error overlay on the device.
|
|
329
|
+
- 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
|
+
|
|
332
|
+
## Proven and unverified
|
|
333
|
+
|
|
334
|
+
Proven here: Ember 7.4 and Glimmer render, update and tear down a non-DOM tree through public API only; .gts
|
|
335
|
+
components compile with vite-plugin-ember-gts for the tests, the package and the NativeScript bundle; `vite build`
|
|
336
|
+
with @nativescript/vite produces Android and iOS bundles; the packed tarball installed into a clean copy of the
|
|
337
|
+
template builds for both platforms and passes Glint, which catches wrong attributes there.
|
|
338
|
+
|
|
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.
|
|
353
|
+
- `{{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.
|
|
@@ -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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isAndroid, isIOS } from "../src/platform.js";
|
|
2
|
+
import { setComponentTemplate } from "@ember/component";
|
|
3
|
+
import { createTemplateFactory } from "@ember/template-factory";
|
|
4
|
+
import templateOnly from "@ember/component/template-only";
|
|
5
|
+
// components/Platform.gts
|
|
6
|
+
var IOS = setComponentTemplate(createTemplateFactory({
|
|
7
|
+
"id": null,
|
|
8
|
+
"block": "[[[41,[28,[32,0],null,null],[[[18,1,null]],[]],null]],[\"&default\"],[\"if\",\"yield\"]]",
|
|
9
|
+
"moduleName": "(unknown template module)",
|
|
10
|
+
"scope": () => ({ isIOS }),
|
|
11
|
+
"isStrictMode": true
|
|
12
|
+
}), templateOnly());
|
|
13
|
+
var Android = setComponentTemplate(createTemplateFactory({
|
|
14
|
+
"id": null,
|
|
15
|
+
"block": "[[[41,[28,[32,0],null,null],[[[18,1,null]],[]],null]],[\"&default\"],[\"if\",\"yield\"]]",
|
|
16
|
+
"moduleName": "(unknown template module)",
|
|
17
|
+
"scope": () => ({ isAndroid }),
|
|
18
|
+
"isStrictMode": true
|
|
19
|
+
}), templateOnly());
|
|
20
|
+
export { Android, IOS };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=Platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.js","names":["isAndroid","isIOS","setComponentTemplate","createTemplateFactory","templateOnly","IOS","Android"],"sources":["../../components/Platform.gts"],"sourcesContent":["// What only one platform shows, like NativeScript-Vue's <ios> and <android> blocks:\n//\n// <IOS><label text='Swipe down to close' /></IOS>\n// <Android><button text='Close' {{on 'tap' @closeModal}} /></Android>\nimport type { TOC } from '@ember/component/template-only';\n\nimport { isAndroid, isIOS } from '../src/platform.ts';\n\ninterface Signature {\n Blocks: { default: [] };\n}\n\nexport const IOS = <template>{{#if (isIOS)}}{{yield}}{{/if}}</template> satisfies TOC<Signature>;\nexport const Android = <template>{{#if (isAndroid)}}{{yield}}{{/if}}</template> satisfies TOC<Signature>;\n"],"mappings":";;;;;AAYA,IAAaK,MAAAH,qBAAAC,sBAAA;CAAA,MAAA;CAAA,SAAA;CAAA,cAAA;CAAA,gBAAA,EAAAF,MAAA;CAAA,gBAAA;AAAA,CAAA,GAAAG,aAAA,CAAA;AACb,IAAaE,UAAAJ,qBAAAC,sBAAA;CAAA,MAAA;CAAA,SAAA;CAAA,cAAA;CAAA,gBAAA,EAAAH,UAAA;CAAA,gBAAA;AAAA,CAAA,GAAAI,aAAA,CAAA"}
|