ember-nativescript 0.1.0 → 0.2.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/README.md +111 -35
- package/dist/components/Platform.d.ts +7 -0
- package/dist/components/Platform.d.ts.map +1 -1
- package/dist/components/Platform.js +9 -2
- package/dist/components/Platform.js.map +1 -1
- package/dist/src/adapter.d.ts +3 -2
- package/dist/src/adapter.d.ts.map +1 -1
- package/dist/src/dom.js +1 -1
- package/dist/src/dom.js.map +1 -1
- package/dist/src/fake-adapter.d.ts +4 -0
- package/dist/src/fake-adapter.d.ts.map +1 -1
- package/dist/src/fake-adapter.js +12 -3
- package/dist/src/fake-adapter.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/native-view.d.ts +2 -1
- package/dist/src/native-view.d.ts.map +1 -1
- package/dist/src/native-view.js +21 -1
- package/dist/src/native-view.js.map +1 -1
- package/dist/src/nativescript-adapter.d.ts.map +1 -1
- package/dist/src/nativescript-adapter.js +4 -0
- package/dist/src/nativescript-adapter.js.map +1 -1
- package/dist/src/navigator.d.ts +6 -0
- package/dist/src/navigator.d.ts.map +1 -1
- package/dist/src/navigator.js +6 -1
- package/dist/src/navigator.js.map +1 -1
- package/dist/src/platform.d.ts +4 -2
- package/dist/src/platform.d.ts.map +1 -1
- package/dist/src/platform.js +2 -1
- package/dist/src/platform.js.map +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js.map +1 -1
- 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-web.d.ts +5 -0
- package/dist/src/vite-web.d.ts.map +1 -0
- package/dist/src/vite-web.js +41 -0
- package/dist/src/vite-web.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 +17 -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 +24 -0
- package/dist/src/vitest.js.map +1 -0
- package/dist/src/web-adapter.d.ts +31 -0
- package/dist/src/web-adapter.d.ts.map +1 -0
- package/dist/src/web-adapter.js +701 -0
- package/dist/src/web-adapter.js.map +1 -0
- package/dist/src/web-app.d.ts +23 -0
- package/dist/src/web-app.d.ts.map +1 -0
- package/dist/src/web-app.js +53 -0
- package/dist/src/web-app.js.map +1 -0
- package/dist/src/web-core.d.ts +56 -0
- package/dist/src/web-core.d.ts.map +1 -0
- package/dist/src/web-core.js +84 -0
- package/dist/src/web-core.js.map +1 -0
- package/dist/src/web-css.d.ts +7 -0
- package/dist/src/web-css.d.ts.map +1 -0
- package/dist/src/web-css.js +118 -0
- package/dist/src/web-css.js.map +1 -0
- package/dist/src/web-host.d.ts +18 -0
- package/dist/src/web-host.d.ts.map +1 -0
- package/dist/src/web-host.js +165 -0
- package/dist/src/web-host.js.map +1 -0
- package/dist/src/web-router.d.ts +51 -0
- package/dist/src/web-router.d.ts.map +1 -0
- package/dist/src/web-router.js +83 -0
- package/dist/src/web-router.js.map +1 -0
- package/dist/src/web-styles.d.ts +4 -0
- package/dist/src/web-styles.d.ts.map +1 -0
- package/dist/src/web-styles.js +157 -0
- package/dist/src/web-styles.js.map +1 -0
- package/dist/src/web.d.ts +7 -0
- package/dist/src/web.d.ts.map +1 -0
- package/dist/src/web.js +7 -0
- package/dist/types/glint.d.ts +6 -1
- package/package.json +58 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-adapter.js","names":[],"sources":["../../src/fake-adapter.ts"],"sourcesContent":["// An in-memory stand-in for NativeScript's views, for tests in Node: the same tags, a parent/children\n// tree, `content` for single-child views, properties and listeners. `toXML()` prints the tree the way a\n// NativeScript XML page would describe it.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\n\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'flexboxLayout',\n 'gridLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\nconst CONTENT_VIEWS = new Set(['page', 'scrollView', 'contentView']);\nconst TEXT_VIEWS = new Set(['label', 'button', 'textField', 'textView', 'span']);\n// A listView's children are the cells it shows, which only the list itself puts there. The rest hold no child views,\n// though some take children into properties (see elements.ts).\nconst LEAF_VIEWS = new Set([\n ...TEXT_VIEWS,\n 'frame',\n 'image',\n 'switch',\n 'slider',\n 'activityIndicator',\n 'listView',\n 'actionBar',\n 'actionItem',\n 'navigationButton',\n 'datePicker',\n 'timePicker',\n 'listPicker',\n 'progress',\n 'searchBar',\n 'segmentedBar',\n 'segmentedBarItem',\n 'tabView',\n 'tabViewItem',\n 'webView',\n 'htmlView',\n 'placeholder',\n 'formattedString',\n]);\n// Names that aren't properties of a NativeScript view: what a layout or a stylesheet sets, and `element`, which\n// renderComponent probes (`'element' in into`) to tell a cursor from an element. Fake views have every other property.\nconst NOT_PROPERTIES = new Set([\n 'class',\n 'style',\n 'row',\n 'col',\n 'rowSpan',\n 'colSpan',\n 'dock',\n 'left',\n 'top',\n 'order',\n 'element',\n]);\nexport const FAKE_TAGS = new Set([...LAYOUTS, ...CONTENT_VIEWS, ...LEAF_VIEWS]);\n\nexport class FakeView {\n /** Properties as strings, for toXML() and assertions. */\n readonly props = new Map<string, string>();\n /** Properties as they were set. */\n readonly values = new Map<string, unknown>();\n readonly children: FakeView[] = [];\n readonly listeners = new Map<string, Set<Listener>>();\n /** Children that went into a property (a page's actionBar, an ActionBar's actionItems). */\n readonly slots = new Map<string, FakeView | FakeView[]>();\n parent: FakeView | null = null;\n /** For a listView bound to rows: what scrolling and layout do to it. */\n list?: FakeList;\n /** For a frame: its pages and modals. */\n frame?: FakeFrame;\n\n constructor(readonly tag: string) {}\n\n get content(): FakeView | undefined {\n return CONTENT_VIEWS.has(this.tag) ? this.children[0] : undefined;\n }\n\n get text(): string | undefined {\n return this.props.get('text');\n }\n\n /** Fires an event the way NativeScript's View.notify does, with { eventName, object }. */\n notify(eventName: string, extra: Record<string, unknown> = {}): void {\n for (const listener of [...(this.listeners.get(eventName) ?? [])]) {\n listener({ eventName, object: this, ...extra });\n }\n }\n\n /** What a user typing does to a TextField: set `text`, then fire `textChange`. */\n type(value: string): void {\n const old = this.props.get('text');\n this.props.set('text', value);\n this.values.set('text', value);\n this.notify('textChange', { propertyName: 'text', value, oldValue: old });\n }\n\n /** A slot's content: one view, a list, or nothing. */\n slot(property: string): FakeView | FakeView[] | undefined {\n return this.slots.get(property);\n }\n\n /** Every view under this one, in slots first and then children. */\n get descendants(): FakeView[] {\n const slotted = [...this.slots.values()].flat();\n return [...slotted, ...this.children];\n }\n\n get listenerCount(): number {\n let count = 0;\n for (const set of this.listeners.values()) count += set.size;\n for (const child of this.descendants) count += child.listenerCount;\n return count;\n }\n\n find(predicate: (view: FakeView) => boolean): FakeView | undefined {\n if (predicate(this)) return this;\n for (const child of this.descendants) {\n const found = child.find(predicate);\n if (found) return found;\n }\n return undefined;\n }\n\n findAll(predicate: (view: FakeView) => boolean, into: FakeView[] = []): FakeView[] {\n if (predicate(this)) into.push(this);\n for (const child of this.descendants) child.findAll(predicate, into);\n return into;\n }\n\n byId(id: string): FakeView {\n const found = this.find((view) => view.props.get('id') === id);\n if (!found) throw new Error(`No view with id ${id} in\\n${this.toXML()}`);\n return found;\n }\n\n // Slots print the way NativeScript's XML writes a property set to views: <page.actionBar>…</page.actionBar>.\n toXML(indent = ''): string {\n const props = [...this.props].map(([name, value]) => ` ${name}=\"${value}\"`).join('');\n const slots = [...this.slots].map(([property, content]) => {\n const views = [content].flat();\n const inner = views.map((view) => view.toXML(`${indent} `)).join('\\n');\n return `${indent} <${this.tag}.${property}>\\n${inner}\\n${indent} </${this.tag}.${property}>`;\n });\n const inner = [...slots, ...this.children.map((child) => child.toXML(`${indent} `))];\n if (!inner.length) return `${indent}<${this.tag}${props} />`;\n return `${indent}<${this.tag}${props}>\\n${inner.join('\\n')}\\n${indent}</${this.tag}>`;\n }\n}\n\n/**\n * What a ListView does with its cells, in memory: it shows `visible` rows from `first`, keeps a container per row on\n * screen, and puts the containers of rows that scroll away in a pool to show the next ones. As on a device, it asks\n * for cells on a layout pass, not when the row count changes.\n */\nexport class FakeList {\n count = 0;\n first = 0;\n /** How many times the list asked for a cell. */\n loads = 0;\n /** How many times the list fired loadMoreItems. */\n loadMores = 0;\n released = false;\n readonly #shown = new Map<number, FakeView>();\n readonly #pools = new Map<string, FakeView[]>();\n readonly #kinds = new WeakMap<FakeView, string>();\n #stale = false;\n\n constructor(\n readonly view: FakeView,\n readonly adapter: FakeAdapter,\n readonly cell: (container: FakeView, index: number) => void,\n readonly options: ListOptions = {},\n public visible = 10,\n ) {}\n\n setCount(count: number): void {\n this.count = count;\n this.#stale = true;\n }\n\n /** Scrolls so that row `first` is at the top, and lays out. */\n scrollTo(first: number): void {\n this.first = first;\n this.layout();\n }\n\n /** The kind of a container: the template it was made from. */\n kindOf(container: FakeView): string | undefined {\n return this.#kinds.get(container);\n }\n\n #kindAt(index: number): string {\n return this.options.kindOf?.(index) ?? 'default';\n }\n\n #pool(kind: string): FakeView[] {\n let pool = this.#pools.get(kind);\n if (!pool) this.#pools.set(kind, (pool = []));\n return pool;\n }\n\n #release(index: number, container: FakeView): void {\n this.#shown.delete(index);\n this.#pool(this.#kinds.get(container)!).push(container);\n }\n\n /**\n * The platform's layout pass: rows that left the screen give their containers back to the pool of their kind, rows\n * that came on get one of their kind (from the pool first), and after a change of rows every row on screen is asked\n * for again, as ListView.refresh() does. Loading the last row fires loadMoreItems, as ListView does on both platforms.\n */\n layout(): void {\n if (this.released) return;\n\n const end = Math.min(this.first + this.visible, this.count);\n\n for (const [index, container] of this.#shown) {\n const gone = index < this.first || index >= end;\n // After a refresh, a row whose kind changed needs a cell of its new kind.\n if (gone || (this.#stale && this.#kinds.get(container) !== this.#kindAt(index))) this.#release(index, container);\n }\n\n let loadedLast = false;\n\n for (let index = this.first; index < end; index++) {\n let container = this.#shown.get(index);\n\n if (!container) {\n const kind = this.#kindAt(index);\n container = this.#pool(kind).pop();\n if (!container) {\n container = this.adapter.createView('stackLayout')!;\n this.#kinds.set(container, kind);\n }\n this.#shown.set(index, container);\n } else if (!this.#stale) {\n continue;\n }\n\n this.loads++;\n this.cell(container, index);\n if (index === this.count - 1) loadedLast = true;\n }\n\n this.#stale = false;\n\n for (const child of this.view.children) child.parent = null;\n const shown = [...this.#shown].sort(([a], [b]) => a - b).map(([, container]) => container);\n this.view.children.splice(0, this.view.children.length, ...shown);\n for (const child of shown) child.parent = this.view;\n\n if (loadedLast) {\n this.loadMores++;\n this.view.notify('loadMoreItems');\n }\n }\n\n /** What a tap on the row at an index does: the list fires itemTap with that index and the cell. */\n tap(index: number): void {\n this.view.notify('itemTap', { index, view: this.#shown.get(index) });\n }\n\n /** Every container the list has made, on screen or in the pools. */\n get containers(): FakeView[] {\n return [...this.#shown.values(), ...[...this.#pools.values()].flat()];\n }\n}\n\n/**\n * NativeScript's Frame, in memory: a stack of pages that fire `navigatedFrom` and `navigatedTo` with\n * `isBackNavigation` as the real one does, honouring clearHistory and backstackVisible, plus modals over the top page.\n */\nexport class FakeFrame implements FrameHost<FakeView> {\n readonly stack: FakeView[] = [];\n readonly shown: Array<{ page: FakeView } & ShowOptions> = [];\n readonly modals: Array<{ view: FakeView } & ModalHostOptions> = [];\n // The page on screen stays out of the back stack once another is shown when it was shown with backstackVisible: false.\n readonly #hidden = new WeakSet<FakeView>();\n\n get top(): FakeView {\n return this.stack.at(-1)!;\n }\n\n show(page: FakeView, options: ShowOptions): void {\n const previous = this.stack.at(-1);\n this.shown.push({ page, ...options });\n previous?.notify('navigatedFrom', { isBackNavigation: false });\n if (options.clearHistory) this.stack.length = 0;\n else if (previous && this.#hidden.has(previous)) this.stack.pop();\n if (!options.backstackVisible) this.#hidden.add(page);\n this.stack.push(page);\n page.notify('navigatedTo', { isBackNavigation: false });\n }\n\n /** What Frame.goBack() does, and what Android's back button and iOS's swipe do. */\n back(): void {\n if (this.stack.length < 2) return;\n const page = this.stack.pop()!;\n page.notify('navigatedFrom', { isBackNavigation: true });\n this.top.notify('navigatedTo', { isBackNavigation: true });\n }\n\n showModal(view: FakeView, options: ModalHostOptions): void {\n this.modals.push({ view, ...options });\n }\n\n closeModal(view: FakeView, result: unknown): void {\n const index = this.modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.modals.splice(index, 1);\n modal!.onClose(result);\n }\n\n /** What a swipe down on iOS or the back button on Android does to a modal: it closes with no result. */\n dismissModal(): void {\n const modal = this.modals.pop();\n modal?.onClose();\n }\n}\n\nexport class FakeAdapter implements NativeAdapter<FakeView> {\n /** Every view the adapter made, to check that destroyed screens let go of theirs. */\n readonly created: FakeView[] = [];\n\n constructor(readonly platform: 'ios' | 'android' = 'ios') {}\n\n createView(tag: string): FakeView | null {\n if (!FAKE_TAGS.has(tag)) return null;\n const view = new FakeView(tag);\n this.created.push(view);\n return view;\n }\n\n setProperty(view: FakeView, name: string, value: unknown): void {\n if (value === null || value === undefined) {\n view.props.delete(name);\n view.values.delete(name);\n } else {\n view.props.set(name, value instanceof Date ? value.toISOString() : String(value));\n view.values.set(name, value);\n }\n }\n\n hasProperty(_view: FakeView, name: string): boolean {\n return !NOT_PROPERTIES.has(name);\n }\n\n takesText(view: FakeView): boolean {\n return TEXT_VIEWS.has(view.tag);\n }\n\n insertChild(parent: FakeView, child: FakeView, index: number): void {\n if (LEAF_VIEWS.has(parent.tag)) throw new Error(`<${parent.tag}> can't hold views`);\n if (CONTENT_VIEWS.has(parent.tag) && parent.children.length) {\n throw new Error(`<${parent.tag}> holds one view; it already has <${parent.children[0]!.tag}>`);\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.children.splice(index, 0, child);\n }\n\n removeChild(parent: FakeView, child: FakeView): void {\n const index = parent.children.indexOf(child);\n if (index === -1) throw new Error(`<${child.tag}> is not a child of <${parent.tag}>`);\n parent.children.splice(index, 1);\n child.parent = null;\n }\n\n setSlot(parent: FakeView, property: string, child: FakeView | null): void {\n const current = parent.slots.get(property);\n if (current && !Array.isArray(current)) current.parent = null;\n if (!child) {\n parent.slots.delete(property);\n return;\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.slots.set(property, child);\n }\n\n insertInSlot(parent: FakeView, property: string, child: FakeView, index: number): void {\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n const list = (parent.slots.get(property) as FakeView[] | undefined) ?? [];\n list.splice(index, 0, child);\n parent.slots.set(property, list);\n child.parent = parent;\n }\n\n removeFromSlot(parent: FakeView, property: string, child: FakeView): void {\n const list = parent.slots.get(property) as FakeView[] | undefined;\n const index = list?.indexOf(child) ?? -1;\n if (index === -1) throw new Error(`<${child.tag}> is not in <${parent.tag}>.${property}`);\n list!.splice(index, 1);\n if (!list!.length) parent.slots.delete(property);\n child.parent = null;\n }\n\n on(view: FakeView, event: string, listener: Listener): void {\n let set = view.listeners.get(event);\n if (!set) view.listeners.set(event, (set = new Set()));\n set.add(listener);\n }\n\n off(view: FakeView, event: string, listener: Listener): void {\n view.listeners.get(event)?.delete(listener);\n }\n\n frameHost(view: FakeView): FrameHost<FakeView> | null {\n if (view.tag !== 'frame') return null;\n return (view.frame ??= new FakeFrame());\n }\n\n bindList(\n view: FakeView,\n cell: (container: FakeView, index: number) => void,\n options?: ListOptions,\n ): ListBinding | null {\n if (view.tag !== 'listView') return null;\n const list = (view.list = new FakeList(view, this, cell, options));\n return {\n setCount: (count) => list.setCount(count),\n release: () => {\n list.released = true;\n },\n };\n }\n}\n"],"mappings":";AAOA,IAAM,0BAAU,IAAI,IAAI;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAM,gCAAgB,IAAI,IAAI;CAAC;CAAQ;CAAc;AAAa,CAAC;AACnE,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAS;CAAU;CAAa;CAAY;AAAM,CAAC;AAG/E,IAAM,6BAAa,IAAI,IAAI;CACzB,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,IAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAa,4BAAY,IAAI,IAAI;CAAC,GAAG;CAAS,GAAG;CAAe,GAAG;AAAU,CAAC;AAE9E,IAAa,WAAb,MAAsB;CAeC;;CAbZ,wBAAQ,IAAI,IAAoB;;CAEhC,yBAAS,IAAI,IAAqB;CAClC,WAAuB,CAAC;CACxB,4BAAY,IAAI,IAA2B;;CAE3C,wBAAQ,IAAI,IAAmC;CACxD,SAA0B;;CAE1B;;CAEA;CAEA,YAAqB,KAAa;EAAb,KAAA,MAAA;CAAc;CAEnC,IAAI,UAAgC;EAClC,OAAO,cAAc,IAAI,KAAK,GAAG,IAAI,KAAK,SAAS,KAAK,KAAA;CAC1D;CAEA,IAAI,OAA2B;EAC7B,OAAO,KAAK,MAAM,IAAI,MAAM;CAC9B;;CAGA,OAAO,WAAmB,QAAiC,CAAC,GAAS;EACnE,KAAK,MAAM,YAAY,CAAC,GAAI,KAAK,UAAU,IAAI,SAAS,KAAK,CAAC,CAAE,GAC9D,SAAS;GAAE;GAAW,QAAQ;GAAM,GAAG;E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ACtC,IAAI,UAAU,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,eAAe,OAAO,IAAI,IAAI,UAAU;EACxF,KAAM,OAAO,OAAO,CAAC;EACrB,IAAI,CAAC,KAAM,QAAQ,OAAO,MAAM,OAAO,QAAQ;EAC/C,MAAM,SAAS;CACjB;CAEA,GAAG,MAAgB,OAAe,UAA0B;EAC1D,IAAI,MAAM,KAAK,UAAU,IAAI,KAAK;EAClC,IAAI,CAAC,KAAK,KAAK,UAAU,IAAI,OAAQ,sBAAM,IAAI,IAAI,CAAE;EACrD,IAAI,IAAI,QAAQ;CAClB;CAEA,IAAI,MAAgB,OAAe,UAA0B;EAC3D,KAAK,UAAU,IAAI,KAAK,CAAC,EAAE,OAAO,QAAQ;CAC5C;CAEA,UAAU,MAA4C;EACpD,IAAI,KAAK,QAAQ,SAAS,OAAO;EACjC,OAAQ,KAAK,UAAU,IAAI,UAAU;CACvC;CAEA,SACE,MACA,MACA,SACoB;EACpB,IAAI,KAAK,QAAQ,YAAY,OAAO;EACpC,MAAM,OAAQ,KAAK,OAAO,IAAI,SAAS,MAAM,MAAM,MAAM,OAAO;EAChE,OAAO;GACL,WAAW,UAAU,KAAK,SAAS,KAAK;GACxC,eAAe;IACb,KAAK,WAAW;GAClB;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"fake-adapter.js","names":[],"sources":["../../src/fake-adapter.ts"],"sourcesContent":["// An in-memory stand-in for NativeScript's views, for tests in Node: the same tags, a parent/children\n// tree, `content` for single-child views, properties and listeners. `toXML()` prints the tree the way a\n// NativeScript XML page would describe it.\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport type { FrameHost, ModalHostOptions, ShowOptions } from './navigator.ts';\n\nconst LAYOUTS = new Set([\n 'stackLayout',\n 'flexboxLayout',\n 'gridLayout',\n 'wrapLayout',\n 'absoluteLayout',\n 'dockLayout',\n 'rootLayout',\n]);\nconst CONTENT_VIEWS = new Set(['page', 'scrollView', 'contentView']);\nconst TEXT_VIEWS = new Set(['label', 'button', 'textField', 'textView', 'span']);\n// A listView's children are the cells it shows, which only the list itself puts there. The rest hold no child views,\n// though some take children into properties (see elements.ts).\nconst LEAF_VIEWS = new Set([\n ...TEXT_VIEWS,\n 'frame',\n 'image',\n 'switch',\n 'slider',\n 'activityIndicator',\n 'listView',\n 'actionBar',\n 'actionItem',\n 'navigationButton',\n 'datePicker',\n 'timePicker',\n 'listPicker',\n 'progress',\n 'searchBar',\n 'segmentedBar',\n 'segmentedBarItem',\n 'tabView',\n 'tabViewItem',\n 'webView',\n 'htmlView',\n 'placeholder',\n 'formattedString',\n]);\n// Names that aren't properties of a NativeScript view: what a layout or a stylesheet sets, and `element`, which\n// renderComponent probes (`'element' in into`) to tell a cursor from an element. Fake views have every other property.\nconst NOT_PROPERTIES = new Set([\n 'class',\n 'style',\n 'row',\n 'col',\n 'rowSpan',\n 'colSpan',\n 'dock',\n 'left',\n 'top',\n 'order',\n 'element',\n]);\nexport const FAKE_TAGS = new Set([...LAYOUTS, ...CONTENT_VIEWS, ...LEAF_VIEWS]);\n/** Tags whose views start without a native view, like those on a page still being navigated to, until `loaded`. */\nexport const FAKE_UNLOADED_TAGS = new Set<string>();\n\nexport class FakeView {\n /** Properties as strings, for toXML() and assertions. */\n readonly props = new Map<string, string>();\n /** Properties as they were set. */\n readonly values = new Map<string, unknown>();\n readonly children: FakeView[] = [];\n readonly listeners = new Map<string, Set<Listener>>();\n /** Children that went into a property (a page's actionBar, an ActionBar's actionItems). */\n readonly slots = new Map<string, FakeView | FakeView[]>();\n parent: FakeView | null = null;\n /** For a listView bound to rows: what scrolling and layout do to it. */\n list?: FakeList;\n /** For a frame: its pages and modals. */\n frame?: FakeFrame;\n\n /** Whether its native view exists; see FAKE_UNLOADED_TAGS. `notify('loaded')` sets it. */\n isLoaded: boolean;\n\n constructor(readonly tag: string) {\n this.isLoaded = !FAKE_UNLOADED_TAGS.has(tag);\n }\n\n get content(): FakeView | undefined {\n return CONTENT_VIEWS.has(this.tag) ? this.children[0] : undefined;\n }\n\n get text(): string | undefined {\n return this.props.get('text');\n }\n\n /** Fires an event the way NativeScript's View.notify does, with { eventName, object }. */\n notify(eventName: string, extra: Record<string, unknown> = {}): void {\n if (eventName === 'loaded') this.isLoaded = true;\n for (const listener of [...(this.listeners.get(eventName) ?? [])]) {\n listener({ eventName, object: this, ...extra });\n }\n }\n\n /** What a user typing does to a TextField: set `text`, then fire `textChange`. */\n type(value: string): void {\n const old = this.props.get('text');\n this.props.set('text', value);\n this.values.set('text', value);\n this.notify('textChange', { propertyName: 'text', value, oldValue: old });\n }\n\n /** A slot's content: one view, a list, or nothing. */\n slot(property: string): FakeView | FakeView[] | undefined {\n return this.slots.get(property);\n }\n\n /** Every view under this one, in slots first and then children. */\n get descendants(): FakeView[] {\n const slotted = [...this.slots.values()].flat();\n return [...slotted, ...this.children];\n }\n\n get listenerCount(): number {\n let count = 0;\n for (const set of this.listeners.values()) count += set.size;\n for (const child of this.descendants) count += child.listenerCount;\n return count;\n }\n\n find(predicate: (view: FakeView) => boolean): FakeView | undefined {\n if (predicate(this)) return this;\n for (const child of this.descendants) {\n const found = child.find(predicate);\n if (found) return found;\n }\n return undefined;\n }\n\n findAll(predicate: (view: FakeView) => boolean, into: FakeView[] = []): FakeView[] {\n if (predicate(this)) into.push(this);\n for (const child of this.descendants) child.findAll(predicate, into);\n return into;\n }\n\n byId(id: string): FakeView {\n const found = this.find((view) => view.props.get('id') === id);\n if (!found) throw new Error(`No view with id ${id} in\\n${this.toXML()}`);\n return found;\n }\n\n // Slots print the way NativeScript's XML writes a property set to views: <page.actionBar>…</page.actionBar>.\n toXML(indent = ''): string {\n const props = [...this.props].map(([name, value]) => ` ${name}=\"${value}\"`).join('');\n const slots = [...this.slots].map(([property, content]) => {\n const views = [content].flat();\n const inner = views.map((view) => view.toXML(`${indent} `)).join('\\n');\n return `${indent} <${this.tag}.${property}>\\n${inner}\\n${indent} </${this.tag}.${property}>`;\n });\n const inner = [...slots, ...this.children.map((child) => child.toXML(`${indent} `))];\n if (!inner.length) return `${indent}<${this.tag}${props} />`;\n return `${indent}<${this.tag}${props}>\\n${inner.join('\\n')}\\n${indent}</${this.tag}>`;\n }\n}\n\n/**\n * What a ListView does with its cells, in memory: it shows `visible` rows from `first`, keeps a container per row on\n * screen, and puts the containers of rows that scroll away in a pool to show the next ones. As on a device, it asks\n * for cells on a layout pass, not when the row count changes.\n */\nexport class FakeList {\n count = 0;\n first = 0;\n /** How many times the list asked for a cell. */\n loads = 0;\n /** How many times the list fired loadMoreItems. */\n loadMores = 0;\n released = false;\n readonly #shown = new Map<number, FakeView>();\n readonly #pools = new Map<string, FakeView[]>();\n readonly #kinds = new WeakMap<FakeView, string>();\n #stale = false;\n\n constructor(\n readonly view: FakeView,\n readonly adapter: FakeAdapter,\n readonly cell: (container: FakeView, index: number) => void,\n readonly options: ListOptions = {},\n public visible = 10,\n ) {}\n\n setCount(count: number): void {\n this.count = count;\n this.#stale = true;\n }\n\n /** Scrolls so that row `first` is at the top, and lays out. */\n scrollTo(first: number): void {\n this.first = first;\n this.layout();\n }\n\n /** The kind of a container: the template it was made from. */\n kindOf(container: FakeView): string | undefined {\n return this.#kinds.get(container);\n }\n\n #kindAt(index: number): string {\n return this.options.kindOf?.(index) ?? 'default';\n }\n\n #pool(kind: string): FakeView[] {\n let pool = this.#pools.get(kind);\n if (!pool) this.#pools.set(kind, (pool = []));\n return pool;\n }\n\n #release(index: number, container: FakeView): void {\n this.#shown.delete(index);\n this.#pool(this.#kinds.get(container)!).push(container);\n }\n\n /**\n * The platform's layout pass: rows that left the screen give their containers back to the pool of their kind, rows\n * that came on get one of their kind (from the pool first), and after a change of rows every row on screen is asked\n * for again, as ListView.refresh() does. Loading the last row fires loadMoreItems, as ListView does on both platforms.\n */\n layout(): void {\n if (this.released) return;\n\n const end = Math.min(this.first + this.visible, this.count);\n\n for (const [index, container] of this.#shown) {\n const gone = index < this.first || index >= end;\n // After a refresh, a row whose kind changed needs a cell of its new kind.\n if (gone || (this.#stale && this.#kinds.get(container) !== this.#kindAt(index))) this.#release(index, container);\n }\n\n let loadedLast = false;\n\n for (let index = this.first; index < end; index++) {\n let container = this.#shown.get(index);\n\n if (!container) {\n const kind = this.#kindAt(index);\n container = this.#pool(kind).pop();\n if (!container) {\n container = this.adapter.createView('stackLayout')!;\n this.#kinds.set(container, kind);\n }\n this.#shown.set(index, container);\n } else if (!this.#stale) {\n continue;\n }\n\n this.loads++;\n this.cell(container, index);\n if (index === this.count - 1) loadedLast = true;\n }\n\n this.#stale = false;\n\n for (const child of this.view.children) child.parent = null;\n const shown = [...this.#shown].sort(([a], [b]) => a - b).map(([, container]) => container);\n this.view.children.splice(0, this.view.children.length, ...shown);\n for (const child of shown) child.parent = this.view;\n\n if (loadedLast) {\n this.loadMores++;\n this.view.notify('loadMoreItems');\n }\n }\n\n /** What a tap on the row at an index does: the list fires itemTap with that index and the cell. */\n tap(index: number): void {\n this.view.notify('itemTap', { index, view: this.#shown.get(index) });\n }\n\n /** Every container the list has made, on screen or in the pools. */\n get containers(): FakeView[] {\n return [...this.#shown.values(), ...[...this.#pools.values()].flat()];\n }\n}\n\n/**\n * NativeScript's Frame, in memory: a stack of pages that fire `navigatedFrom` and `navigatedTo` with\n * `isBackNavigation` as the real one does, honouring clearHistory and backstackVisible, plus modals over the top page.\n */\nexport class FakeFrame implements FrameHost<FakeView> {\n readonly stack: FakeView[] = [];\n readonly shown: Array<{ page: FakeView } & ShowOptions> = [];\n readonly modals: Array<{ view: FakeView } & ModalHostOptions> = [];\n // The page on screen stays out of the back stack once another is shown when it was shown with backstackVisible: false.\n readonly #hidden = new WeakSet<FakeView>();\n\n get top(): FakeView {\n return this.stack.at(-1)!;\n }\n\n show(page: FakeView, options: ShowOptions): void {\n const previous = this.stack.at(-1);\n this.shown.push({ page, ...options });\n previous?.notify('navigatedFrom', { isBackNavigation: false });\n if (options.clearHistory) this.stack.length = 0;\n else if (previous && this.#hidden.has(previous)) this.stack.pop();\n if (!options.backstackVisible) this.#hidden.add(page);\n this.stack.push(page);\n page.notify('navigatedTo', { isBackNavigation: false });\n }\n\n /** What Frame.goBack() does, and what Android's back button and iOS's swipe do. */\n back(): void {\n if (this.stack.length < 2) return;\n const page = this.stack.pop()!;\n page.notify('navigatedFrom', { isBackNavigation: true });\n this.top.notify('navigatedTo', { isBackNavigation: true });\n }\n\n showModal(view: FakeView, options: ModalHostOptions): void {\n this.modals.push({ view, ...options });\n }\n\n closeModal(view: FakeView, result: unknown): void {\n const index = this.modals.findIndex((modal) => modal.view === view);\n if (index === -1) return;\n const [modal] = this.modals.splice(index, 1);\n modal!.onClose(result);\n }\n\n /** What a swipe down on iOS or the back button on Android does to a modal: it closes with no result. */\n dismissModal(): void {\n const modal = this.modals.pop();\n modal?.onClose();\n }\n}\n\nexport class FakeAdapter implements NativeAdapter<FakeView> {\n /** Every view the adapter made, to check that destroyed screens let go of theirs. */\n readonly created: FakeView[] = [];\n\n constructor(readonly platform: 'ios' | 'android' = 'ios') {}\n\n createView(tag: string): FakeView | null {\n if (!FAKE_TAGS.has(tag)) return null;\n const view = new FakeView(tag);\n this.created.push(view);\n return view;\n }\n\n setProperty(view: FakeView, name: string, value: unknown): void {\n if (value === null || value === undefined) {\n view.props.delete(name);\n view.values.delete(name);\n } else {\n view.props.set(name, value instanceof Date ? value.toISOString() : String(value));\n view.values.set(name, value);\n }\n }\n\n hasProperty(_view: FakeView, name: string): boolean {\n return !NOT_PROPERTIES.has(name);\n }\n\n takesText(view: FakeView): boolean {\n return TEXT_VIEWS.has(view.tag);\n }\n\n insertChild(parent: FakeView, child: FakeView, index: number): void {\n if (LEAF_VIEWS.has(parent.tag)) throw new Error(`<${parent.tag}> can't hold views`);\n if (CONTENT_VIEWS.has(parent.tag) && parent.children.length) {\n throw new Error(`<${parent.tag}> holds one view; it already has <${parent.children[0]!.tag}>`);\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.children.splice(index, 0, child);\n }\n\n removeChild(parent: FakeView, child: FakeView): void {\n const index = parent.children.indexOf(child);\n if (index === -1) throw new Error(`<${child.tag}> is not a child of <${parent.tag}>`);\n parent.children.splice(index, 1);\n child.parent = null;\n }\n\n setSlot(parent: FakeView, property: string, child: FakeView | null): void {\n const current = parent.slots.get(property);\n if (current && !Array.isArray(current)) current.parent = null;\n if (!child) {\n // Like NativeScript's Page, which throws on a null ActionBar: the adapter has to put back a blank one.\n if (parent.tag === 'page' && property === 'actionBar') child = new FakeView('actionBar');\n else {\n parent.slots.delete(property);\n return;\n }\n }\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n child.parent = parent;\n parent.slots.set(property, child);\n }\n\n insertInSlot(parent: FakeView, property: string, child: FakeView, index: number): void {\n if (child.parent) throw new Error(`<${child.tag}> already has a parent`);\n const list = (parent.slots.get(property) as FakeView[] | undefined) ?? [];\n list.splice(index, 0, child);\n parent.slots.set(property, list);\n child.parent = parent;\n }\n\n removeFromSlot(parent: FakeView, property: string, child: FakeView): void {\n const list = parent.slots.get(property) as FakeView[] | undefined;\n const index = list?.indexOf(child) ?? -1;\n if (index === -1) throw new Error(`<${child.tag}> is not in <${parent.tag}>.${property}`);\n list!.splice(index, 1);\n if (!list!.length) parent.slots.delete(property);\n child.parent = null;\n }\n\n on(view: FakeView, event: string, listener: Listener): void {\n let set = view.listeners.get(event);\n if (!set) view.listeners.set(event, (set = new Set()));\n set.add(listener);\n }\n\n off(view: FakeView, event: string, listener: Listener): void {\n view.listeners.get(event)?.delete(listener);\n }\n\n frameHost(view: FakeView): FrameHost<FakeView> | null {\n if (view.tag !== 'frame') return null;\n return (view.frame ??= new FakeFrame());\n }\n\n bindList(\n view: FakeView,\n cell: (container: FakeView, index: number) => void,\n options?: ListOptions,\n ): ListBinding | null {\n if (view.tag !== 'listView') return null;\n const list = (view.list = new FakeList(view, this, cell, options));\n return {\n setCount: (count) => list.setCount(count),\n release: () => {\n list.released = true;\n },\n };\n }\n}\n"],"m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EACxE,MAAM,OAAO,OAAO,MAAM,IAAI,QAAQ;EACtC,MAAM,QAAQ,MAAM,QAAQ,KAAK,KAAK;EACtC,IAAI,UAAU,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,eAAe,OAAO,IAAI,IAAI,UAAU;EACxF,KAAM,OAAO,OAAO,CAAC;EACrB,IAAI,CAAC,KAAM,QAAQ,OAAO,MAAM,OAAO,QAAQ;EAC/C,MAAM,SAAS;CACjB;CAEA,GAAG,MAAgB,OAAe,UAA0B;EAC1D,IAAI,MAAM,KAAK,UAAU,IAAI,KAAK;EAClC,IAAI,CAAC,KAAK,KAAK,UAAU,IAAI,OAAQ,sBAAM,IAAI,IAAI,CAAE;EACrD,IAAI,IAAI,QAAQ;CAClB;CAEA,IAAI,MAAgB,OAAe,UAA0B;EAC3D,KAAK,UAAU,IAAI,KAAK,CAAC,EAAE,OAAO,QAAQ;CAC5C;CAEA,UAAU,MAA4C;EACpD,IAAI,KAAK,QAAQ,SAAS,OAAO;EACjC,OAAQ,KAAK,UAAU,IAAI,UAAU;CACvC;CAEA,SACE,MACA,MACA,SACoB;EACpB,IAAI,KAAK,QAAQ,YAAY,OAAO;EACpC,MAAM,OAAQ,KAAK,OAAO,IAAI,SAAS,MAAM,MAAM,MAAM,OAAO;EAChE,OAAO;GACL,WAAW,UAAU,KAAK,SAAS,KAAK;GACxC,eAAe;IACb,KAAK,WAAW;GAClB;EACF;CACF;AACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ export { type FrameHost, type ModalOptions, type NavigateOptions, Navigator, typ
|
|
|
7
7
|
export { createNativeApp, FrameNavigationHost, type NativeApp, type NativeAppOptions } from './nativescript-app.js';
|
|
8
8
|
export { NativeScriptAdapter, registerElement } from './nativescript-adapter.js';
|
|
9
9
|
export { createOwner, type CreateOwnerOptions, type NativeOwner, type ServiceEntry } from './owner.js';
|
|
10
|
-
export { isAndroid, isIOS, platform } from './platform.js';
|
|
10
|
+
export { isAndroid, isIOS, isWeb, platform, type Platform } from './platform.js';
|
|
11
11
|
export { createDocument, type NativeRoot, renderNative } from './render.js';
|
|
12
12
|
export { bind } from './bind.js';
|
|
13
13
|
export { nativeView } from './native-view.js';
|
|
14
14
|
export { default as NativeFrame } from '../components/NativeFrame.js';
|
|
15
15
|
export { default as NativeList } from '../components/NativeList.js';
|
|
16
|
-
export { Android, IOS } from '../components/Platform.js';
|
|
16
|
+
export { Android, IOS, Web } from '../components/Platform.js';
|
|
17
17
|
export type { NativeAttributes, NativeElementFor, NativeElementTagNameMap, NativeEvent } from '../types/glint.js';
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACtH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,WAAW,E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AE,OAAO,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -6,12 +6,12 @@ import { Navigator } from "./navigator.js";
|
|
|
6
6
|
import { createNativeApp } from "./nativescript-app.js";
|
|
7
7
|
import { NativeScriptAdapter, registerElement } from "./nativescript-adapter.js";
|
|
8
8
|
import { createOwner } from "./owner.js";
|
|
9
|
-
import { isAndroid, isIOS, platform } from "./platform.js";
|
|
9
|
+
import { isAndroid, isIOS, isWeb, platform } from "./platform.js";
|
|
10
10
|
import { FrameNavigationHost } from "./frame-host.js";
|
|
11
11
|
import { createDocument, renderNative } from "./render.js";
|
|
12
12
|
import { bind } from "./bind.js";
|
|
13
13
|
import { nativeView } from "./native-view.js";
|
|
14
14
|
import NativeFrame from "../components/NativeFrame.js";
|
|
15
15
|
import NativeList from "../components/NativeList.js";
|
|
16
|
-
import { Android, IOS } from "../components/Platform.js";
|
|
17
|
-
export { Android, FrameNavigationHost, IOS, NativeDocument, NativeElement, NativeFrame, NativeList, NativeScriptAdapter, Navigator, bind, bindListRows, createDocument, createNativeApp, createOwner, defineElement, isAndroid, isIOS, modifier, nativeView, platform, registerElement, renderNative };
|
|
16
|
+
import { Android, IOS, Web } from "../components/Platform.js";
|
|
17
|
+
export { Android, FrameNavigationHost, IOS, NativeDocument, NativeElement, NativeFrame, NativeList, NativeScriptAdapter, Navigator, Web, bind, bindListRows, createDocument, createNativeApp, createOwner, defineElement, isAndroid, isIOS, isWeb, modifier, nativeView, platform, registerElement, renderNative };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ModifierLike } from '@glint/template';
|
|
2
|
+
import type { View as NSView } from '@nativescript/core';
|
|
2
3
|
export declare const nativeView: abstract new <El extends Element = Element>() => InstanceType<ModifierLike<{
|
|
3
4
|
Element: El;
|
|
4
5
|
Args: {
|
|
5
6
|
Positional: [callback: (view: El extends {
|
|
6
7
|
view: infer View;
|
|
7
|
-
} ? View :
|
|
8
|
+
} ? View : NSView) => void | (() => void)];
|
|
8
9
|
};
|
|
9
10
|
}>>;
|
|
10
11
|
//# sourceMappingURL=native-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-view.d.ts","sourceRoot":"","sources":["../../src/native-view.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-view.d.ts","sourceRoot":"","sources":["../../src/native-view.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA+BzD,eAAO,MAAM,UAAU,EAAoC,QAAQ,MACjE,EAAE,SAAS,OAAO,GAAG,OAAO,OACvB,YAAY,CACjB,YAAY,CAAC;IACX,OAAO,EAAE,EAAE,CAAC;IAEZ,IAAI,EAAE;QAAE,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS;YAAE,IAAI,EAAE,MAAM,IAAI,CAAA;SAAE,GAAG,IAAI,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;KAAE,CAAC;CAClH,CAAC,CACH,CAAC"}
|
package/dist/src/native-view.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { modifier } from "./modifier.js";
|
|
2
|
+
// src/native-view.ts
|
|
3
|
+
function run(callback, view) {
|
|
4
|
+
try {
|
|
5
|
+
return callback(view);
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.error("{{nativeView}} callback failed:", error instanceof Error ? error.stack ?? error.message : error);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
2
11
|
var nativeView = modifier((element, [callback]) => {
|
|
3
12
|
const view = element.view;
|
|
4
|
-
|
|
13
|
+
if (view === void 0) return void 0;
|
|
14
|
+
if (view.isLoaded !== false) return run(callback, view);
|
|
15
|
+
let cleanup;
|
|
16
|
+
const loaded = () => {
|
|
17
|
+
element.removeEventListener("loaded", loaded);
|
|
18
|
+
cleanup = run(callback, view);
|
|
19
|
+
};
|
|
20
|
+
element.addEventListener("loaded", loaded);
|
|
21
|
+
return () => {
|
|
22
|
+
element.removeEventListener("loaded", loaded);
|
|
23
|
+
cleanup?.();
|
|
24
|
+
};
|
|
5
25
|
});
|
|
6
26
|
export { nativeView };
|
|
7
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-view.js","names":["modifier","nativeViewModifier","element","
|
|
1
|
+
{"version":3,"file":"native-view.js","names":["modifier","run","callback","view","error","console","Error","stack","message","undefined","nativeViewModifier","element","isLoaded","cleanup","loaded","removeEventListener","addEventListener","nativeView"],"sources":["../../src/native-view.ts"],"sourcesContent":["// Hands the view to a function once its native view exists, for what templates don't cover: animations, focus,\n// scrolling to a position, a plugin's API. A view on a page that is still being navigated to has no native view yet\n// (core's animations would read `nativeView.layer` from undefined), so the function waits for the view's `loaded`.\n//\n// <stackLayout {{nativeView this.fadeIn}} />\n//\n// fadeIn = (view: StackLayout) => { view.opacity = 0; view.animate({ opacity: 1, duration: 300 }); };\n//\n// If the function returns another one, that runs when the element goes away. If the function throws, the error is\n// logged and the render goes on: otherwise the modifiers after it, such as a button's {{on 'tap'}}, never install.\nimport type { ModifierLike } from '@glint/template';\nimport type { View as NSView } from '@nativescript/core';\n\nimport type { NativeElement } from './dom.ts';\nimport { modifier } from './modifier.ts';\n\nfunction run(callback: (view: unknown) => void | (() => void), view: unknown): void | (() => void) {\n try {\n return callback(view);\n } catch (error) {\n console.error('{{nativeView}} callback failed:', error instanceof Error ? (error.stack ?? error.message) : error);\n return undefined;\n }\n}\n\nconst nativeViewModifier = modifier<[(view: unknown) => void | (() => void)]>((element, [callback]) => {\n const view = (element as unknown as NativeElement).view;\n if (view === undefined) return undefined;\n if ((view as { isLoaded?: boolean }).isLoaded !== false) return run(callback, view);\n\n let cleanup: void | (() => void);\n const loaded = (): void => {\n element.removeEventListener('loaded', loaded);\n cleanup = run(callback, view);\n };\n element.addEventListener('loaded', loaded);\n return () => {\n element.removeEventListener('loaded', loaded);\n cleanup?.();\n };\n});\n\nexport const nativeView = nativeViewModifier as unknown as abstract new <\n El extends Element = Element,\n>() => InstanceType<\n ModifierLike<{\n Element: El;\n // Tags HTML also has (label, button…) keep HTML's element type: their view is typed as NativeScript's View.\n Args: { Positional: [callback: (view: El extends { view: infer View } ? View : NSView) => void | (() => void)] };\n }>\n>;\n"],"mappings":";;AAgBA,SAASC,IAAIC,UAAkDC,MAAoC;CACjG,IAAI;EACF,OAAOD,SAASC,IAAI;CACtB,SAASC,OAAO;EACdC,QAAQD,MAAM,mCAAmCA,iBAAiBE,QAASF,MAAMG,SAASH,MAAMI,UAAWJ,KAAK;EAChH;CACF;AACF;AAmBA,IAAaa,aAjBcjB,UAAoDW,SAAS,CAACT,cAAc;CACrG,MAAMC,OAAQQ,QAAqCR;CACnD,IAAIA,SAASM,KAAAA,GAAW,OAAOA,KAAAA;CAC/B,IAAKN,KAAgCS,aAAa,OAAO,OAAOX,IAAIC,UAAUC,IAAI;CAElF,IAAIU;CACJ,MAAMC,eAAqB;EACzBH,QAAQI,oBAAoB,UAAUD,MAAM;EAC5CD,UAAUZ,IAAIC,UAAUC,IAAI;CAC9B;CACAQ,QAAQK,iBAAiB,UAAUF,MAAM;CACzC,aAAa;EACXH,QAAQI,oBAAoB,UAAUD,MAAM;EAC5CD,UAAU;CACZ;AACF,CAE0BH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativescript-adapter.d.ts","sourceRoot":"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,QAAQ,GAAG,IAAI;IAO5D,QAAQ,CACN,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,EAClD,OAAO,GAAE,WAAgB,GACxB,WAAW,GAAG,IAAI;CA2BtB"}
|
|
@@ -96,6 +96,10 @@ var NativeScriptAdapter = class {
|
|
|
96
96
|
else if (parent.content === child) parent.content = null;
|
|
97
97
|
}
|
|
98
98
|
setSlot(parent, property, child) {
|
|
99
|
+
if (!child && parent instanceof Page && property === "actionBar") {
|
|
100
|
+
parent.actionBar = new ActionBar();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
99
103
|
const bag = parent;
|
|
100
104
|
if (child || bag[property]) bag[property] = child ?? null;
|
|
101
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativescript-adapter.js","names":["AbsoluteLayout","ActionBar","ActionItem","ActivityIndicator","Button","ContentView","DatePicker","DockLayout","FlexboxLayout","FormattedString","Frame","GridLayout","HtmlView","Image","isIOS","Label","LayoutBase","ListPicker","ListView","NavigationButton","ObservableArray","Page","Placeholder","Progress","RootLayout","ScrollView","SearchBar","SegmentedBar","SegmentedBarItem","Slider","Span","StackLayout","Switch","TabView","TabViewItem","TextField","TextView","TimePicker","WebView","WrapLayout","defineElement","VIEWS","Map","Object","entries","absoluteLayout","actionBar","actionItem","activityIndicator","button","contentView","datePicker","dockLayout","flexboxLayout","formattedString","frame","gridLayout","htmlView","image","label","listPicker","listView","navigationButton","page","placeholder","progress","rootLayout","scrollView","searchBar","segmentedBar","segmentedBarItem","slider","span","stackLayout","switch","tabView","tabViewItem","textField","textView","timePicker","webView","wrapLayout","registerElement","tag","create","definition","set","takesText","view","ATTACHED","row","value","setRow","Number","col","setColumn","rowSpan","setRowSpan","colSpan","setColumnSpan","dock","setDock","left","setLeft","top","setTop","order","setOrder","flexGrow","setFlexGrow","flexShrink","setFlexShrink","NativeScriptAdapter","platform","createView","get","setProperty","name","className","String","style","includes","path","split","last","pop","target","key","undefined","hasProperty","replace","insertChild","parent","child","index","content","Error","typeName","removeChild","setSlot","property","bag","insertInSlot","items","splice","removeFromSlot","indexOf","change","actionItems","getItems","next","item","removeItem","addItem","current","length","on","event","listener","off","bindList","cell","options","onItemLoading","data","args","kinds","kindOf","itemTemplates","map","itemTemplateSelector","_item","itemTemplate","itemLoadingEvent","setCount","count","getItem","refresh","release"],"sources":["../../src/nativescript-adapter.ts"],"sourcesContent":["// The adapter that drives NativeScript's views on a device. Not run in this repository's tests (they need iOS or\n// Android); `pnpm typecheck` checks it against @nativescript/core's types.\n//\n// Static attributes arrive as strings, as they would from NativeScript's XML, and are assigned the same way;\n// dynamic ones arrive as their values (an array, a Date, an ImageSource) and are assigned as they are.\n// Strings: NativeScript's properties convert them themselves (`isEnabled=\"false\"`, `columns=\"*, auto\"` on a\n// GridLayout), attached layout properties such as `col` go through their layout's setter, `class` sets className\n// and `style` sets inline CSS. A dotted name sets a nested property (`ios.position` on an ActionItem).\n\nimport {\n AbsoluteLayout,\n ActionBar,\n ActionItem,\n ActivityIndicator,\n Button,\n ContentView,\n DatePicker,\n DockLayout,\n FlexboxLayout,\n FormattedString,\n Frame,\n GridLayout,\n HtmlView,\n Image,\n isIOS,\n type ItemEventData,\n Label,\n LayoutBase,\n ListPicker,\n ListView,\n NavigationButton,\n ObservableArray,\n Page,\n Placeholder,\n Progress,\n RootLayout,\n ScrollView,\n SearchBar,\n SegmentedBar,\n SegmentedBarItem,\n Slider,\n Span,\n StackLayout,\n Switch,\n TabView,\n TabViewItem,\n TextField,\n TextView,\n TimePicker,\n View,\n type ViewBase,\n WebView,\n WrapLayout,\n} from '@nativescript/core';\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport { defineElement, type ElementDefinition } from './elements.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport type { FrameHost } from './navigator.ts';\n\nconst VIEWS = new Map<string, () => ViewBase>(\n Object.entries({\n absoluteLayout: () => new AbsoluteLayout(),\n actionBar: () => new ActionBar(),\n actionItem: () => new ActionItem(),\n activityIndicator: () => new ActivityIndicator(),\n button: () => new Button(),\n contentView: () => new ContentView(),\n datePicker: () => new DatePicker(),\n dockLayout: () => new DockLayout(),\n flexboxLayout: () => new FlexboxLayout(),\n formattedString: () => new FormattedString(),\n frame: () => new Frame(),\n gridLayout: () => new GridLayout(),\n htmlView: () => new HtmlView(),\n image: () => new Image(),\n label: () => new Label(),\n listPicker: () => new ListPicker(),\n listView: () => new ListView(),\n navigationButton: () => new NavigationButton(),\n page: () => new Page(),\n placeholder: () => new Placeholder(),\n progress: () => new Progress(),\n rootLayout: () => new RootLayout(),\n scrollView: () => new ScrollView(),\n searchBar: () => new SearchBar(),\n segmentedBar: () => new SegmentedBar(),\n segmentedBarItem: () => new SegmentedBarItem(),\n slider: () => new Slider(),\n span: () => new Span(),\n stackLayout: () => new StackLayout(),\n switch: () => new Switch(),\n tabView: () => new TabView(),\n tabViewItem: () => new TabViewItem(),\n textField: () => new TextField(),\n textView: () => new TextView(),\n timePicker: () => new TimePicker(),\n webView: () => new WebView(),\n wrapLayout: () => new WrapLayout(),\n }),\n);\n\n/**\n * Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:\n * { property: 'items', list: true } })`. The definition says which children go into properties rather than being\n * child views (see elements.ts); leave it out for a view that lays out its children or has none.\n */\nexport function registerElement(tag: string, create: () => ViewBase, definition?: ElementDefinition): void {\n VIEWS.set(tag, create);\n if (definition) defineElement(tag, definition);\n}\n\n// Views whose text children become their `text` property.\nconst takesText = (view: ViewBase): boolean =>\n view instanceof Label ||\n view instanceof Button ||\n view instanceof TextField ||\n view instanceof TextView ||\n view instanceof Span;\n\n// Properties a view's parent layout reads, written on the child: GridLayout's row/col, DockLayout's dock,\n// AbsoluteLayout's left/top, FlexboxLayout's order/flexGrow…\nconst ATTACHED: Record<string, (view: View, value: string) => void> = {\n row: (view, value) => GridLayout.setRow(view, Number(value)),\n col: (view, value) => GridLayout.setColumn(view, Number(value)),\n rowSpan: (view, value) => GridLayout.setRowSpan(view, Number(value)),\n colSpan: (view, value) => GridLayout.setColumnSpan(view, Number(value)),\n dock: (view, value) => DockLayout.setDock(view, value as never),\n left: (view, value) => AbsoluteLayout.setLeft(view, Number(value)),\n top: (view, value) => AbsoluteLayout.setTop(view, Number(value)),\n order: (view, value) => FlexboxLayout.setOrder(view, Number(value)),\n flexGrow: (view, value) => FlexboxLayout.setFlexGrow(view, Number(value)),\n flexShrink: (view, value) => FlexboxLayout.setFlexShrink(view, Number(value)),\n};\n\ntype Bag = Record<string, unknown>;\n\nexport class NativeScriptAdapter implements NativeAdapter<ViewBase> {\n readonly platform = isIOS ? ('ios' as const) : ('android' as const);\n\n createView(tag: string): ViewBase | null {\n return VIEWS.get(tag)?.() ?? null;\n }\n\n setProperty(view: ViewBase, name: string, value: unknown): void {\n if (name === 'class') {\n view.className = value === null ? '' : String(value);\n } else if (name === 'style') {\n // NativeScript parses an inline CSS string assigned to `style`, as XML's style=\"…\" does.\n (view as unknown as { style: unknown }).style = value ?? '';\n } else if (ATTACHED[name]) {\n if (value !== null) ATTACHED[name](view as View, String(value));\n } else if (name.includes('.')) {\n const path = name.split('.');\n const last = path.pop()!;\n let target = view as unknown as Bag;\n for (const key of path) target = (target[key] ??= {}) as Bag;\n target[last] = value === null ? undefined : value;\n } else {\n // Unset goes back to the property's default.\n (view as unknown as Bag)[name] = value === null ? undefined : value;\n }\n }\n\n // NativeScript defines its properties as accessors on each view class, so `in` finds them (`items` on a\n // ListPicker, `date` on a DatePicker). Layout properties such as `col` aren't, and stay strings.\n hasProperty(view: ViewBase, name: string): boolean {\n return name.replace(/^(ios|android):/, '') in view;\n }\n\n takesText(view: ViewBase): boolean {\n return takesText(view);\n }\n\n insertChild(parent: ViewBase, child: ViewBase, index: number): void {\n if (parent instanceof LayoutBase) {\n parent.insertChild(child as View, index);\n } else if (parent instanceof ContentView || parent instanceof Page || parent instanceof ScrollView) {\n parent.content = child as View;\n } else {\n throw new Error(`[ember-nativescript] <${parent.typeName}> can't hold views.`);\n }\n }\n\n removeChild(parent: ViewBase, child: ViewBase): void {\n if (parent instanceof LayoutBase) {\n parent.removeChild(child as View);\n } else if ((parent as ContentView).content === child) {\n (parent as ContentView).content = null as unknown as View;\n }\n }\n\n setSlot(parent: ViewBase, property: string, child: ViewBase | null): void {\n const bag = parent as unknown as Bag;\n if (child || bag[property]) bag[property] = child ?? null;\n }\n\n // NativeScript's list properties are set three ways: an ActionBar's actionItems through addItem and removeItem, a\n // FormattedString's spans as an ObservableArray it watches, and a SegmentedBar's or TabView's items by assigning a new\n // array, which its property handler compares with the old one.\n insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void {\n this.#updateList(parent, property, (items) => items.splice(index, 0, child));\n }\n\n removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void {\n this.#updateList(parent, property, (items) => {\n const index = items.indexOf(child);\n if (index !== -1) items.splice(index, 1);\n });\n }\n\n #updateList(parent: ViewBase, property: string, change: (items: ViewBase[]) => void): void {\n if (parent instanceof ActionBar && property === 'actionItems') {\n const items = parent.actionItems.getItems();\n const next = [...items];\n change(next);\n for (const item of items) parent.actionItems.removeItem(item);\n for (const item of next) parent.actionItems.addItem(item as ActionItem);\n return;\n }\n\n const current = (parent as unknown as Bag)[property];\n if (current instanceof ObservableArray) {\n const next = [...current] as ViewBase[];\n change(next);\n current.splice(0, current.length, ...next);\n return;\n }\n\n const next = [...((current as ViewBase[] | undefined) ?? [])];\n change(next);\n (parent as unknown as Bag)[property] = next;\n }\n\n on(view: ViewBase, event: string, listener: Listener): void {\n view.on(event, listener);\n }\n\n off(view: ViewBase, event: string, listener: Listener): void {\n view.off(event, listener);\n }\n\n // Each cell is an empty StackLayout from the item template; ember-native renders the row into it. `items` is only a\n // count (an ItemsSource whose items are their indexes): the rows read their item from Ember's state, not from\n // NativeScript's binding context.\n bindList(\n view: ViewBase,\n cell: (container: ViewBase, index: number) => void,\n options: ListOptions = {},\n ): ListBinding | null {\n if (!(view instanceof ListView)) return null;\n\n const onItemLoading = (data: unknown) => {\n const args = data as ItemEventData;\n cell(args.view, args.index);\n };\n const { kinds, kindOf } = options;\n if (kinds && kindOf) {\n // One template per kind: the list keeps a pool of cells per kind, and reuses a cell only for its kind.\n view.itemTemplates = kinds.map((key) => ({ key, createView: () => new StackLayout() }));\n view.itemTemplateSelector = (_item: unknown, index: number) => kindOf(index);\n } else {\n view.itemTemplate = () => new StackLayout();\n }\n view.on(ListView.itemLoadingEvent, onItemLoading);\n\n return {\n setCount(count) {\n view.items = { length: count, getItem: (index: number) => index };\n view.refresh();\n },\n release() {\n view.off(ListView.itemLoadingEvent, onItemLoading);\n },\n };\n }\n}\n"],"mappings":";;;AA4DA,IAAMyC,QAAQ,IAAIC,IAChBC,OAAOC,QAAQ;CACbC,sBAAsB,IAAI7C,eAAe;CACzC8C,iBAAiB,IAAI7C,UAAU;CAC/B8C,kBAAkB,IAAI7C,WAAW;CACjC8C,yBAAyB,IAAI7C,kBAAkB;CAC/C8C,cAAc,IAAI7C,OAAO;CACzB8C,mBAAmB,IAAI7C,YAAY;CACnC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,qBAAqB,IAAI7C,cAAc;CACvC8C,uBAAuB,IAAI7C,gBAAgB;CAC3C8C,aAAa,IAAI7C,MAAM;CACvB8C,kBAAkB,IAAI7C,WAAW;CACjC8C,gBAAgB,IAAI7C,SAAS;CAC7B8C,aAAa,IAAI7C,MAAM;CACvB8C,aAAa,IAAI5C,MAAM;CACvB6C,kBAAkB,IAAI3C,WAAW;CACjC4C,gBAAgB,IAAI3C,SAAS;CAC7B4C,wBAAwB,IAAI3C,iBAAiB;CAC7C4C,YAAY,IAAI1C,KAAK;CACrB2C,mBAAmB,IAAI1C,YAAY;CACnC2C,gBAAgB,IAAI1C,SAAS;CAC7B2C,kBAAkB,IAAI1C,WAA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AQV,OAAO,GAAGU,QAAQC,QAAQ,GAAGL,IAAI;GACzC;EACF;EAEA,MAAMA,OAAO,CAAC,GAAKI,WAAsC,CAAA,CAAG;EAC5DP,OAAOG,IAAI;EACVlB,OAA0BQ,YAAYU;CACzC;CAEAM,GAAGpE,MAAgBqE,OAAeC,UAA0B;EAC1DtE,KAAKoE,GAAGC,OAAOC,QAAQ;CACzB;CAEAC,IAAIvE,MAAgBqE,OAAeC,UAA0B;EAC3DtE,KAAKuE,IAAIF,OAAOC,QAAQ;CAC1B;CAKAE,SACExE,MACAyE,MACAC,UAAuB,CAAC,GACJ;EACpB,IAAI,EAAE1E,gBAAgBtE,WAAW,OAAO;EAExC,MAAMiJ,iBAAiBC,SAAkB;GACvC,MAAMC,OAAOD;GACbH,KAAKI,KAAK7E,MAAM6E,KAAK/B,KAAK;EAC5B;EACA,MAAM,EAAEgC,OAAOC,WAAWL;EAC1B,IAAII,SAASC,QAAQ;GAEnB/E,KAAKgF,gBAAgBF,MAAMG,KAAK1C,SAAS;IAAEA;IAAKb,kBAAkB,IAAInF,YAAY;GAAE,EAAE;GACtFyD,KAAKkF,wBAAwBC,OAAgBrC,UAAkBiC,OAAOjC,KAAK;EAC7E,OACE9C,KAAKoF,qBAAqB,IAAI7I,YAAY;EAE5CyD,KAAKoE,GAAG1I,SAAS2J,kBAAkBV,aAAa;EAEhD,OAAO;GACLW,SAASC,OAAO;IACdvF,KAAKuD,QAAQ;KAAEY,QAAQoB;KAAOC,UAAU1C,UAAkBA;IAAM;IAChE9C,KAAKyF,QAAQ;GACf;GACAC,UAAU;IACR1F,KAAKuE,IAAI7I,SAAS2J,kBAAkBV,aAAa;GACnD;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"nativescript-adapter.js","names":["AbsoluteLayout","ActionBar","ActionItem","ActivityIndicator","Button","ContentView","DatePicker","DockLayout","FlexboxLayout","FormattedString","Frame","GridLayout","HtmlView","Image","isIOS","Label","LayoutBase","ListPicker","ListView","NavigationButton","ObservableArray","Page","Placeholder","Progress","RootLayout","ScrollView","SearchBar","SegmentedBar","SegmentedBarItem","Slider","Span","StackLayout","Switch","TabView","TabViewItem","TextField","TextView","TimePicker","WebView","WrapLayout","defineElement","VIEWS","Map","Object","entries","absoluteLayout","actionBar","actionItem","activityIndicator","button","contentView","datePicker","dockLayout","flexboxLayout","formattedString","frame","gridLayout","htmlView","image","label","listPicker","listView","navigationButton","page","placeholder","progress","rootLayout","scrollView","searchBar","segmentedBar","segmentedBarItem","slider","span","stackLayout","switch","tabView","tabViewItem","textField","textView","timePicker","webView","wrapLayout","registerElement","tag","create","definition","set","takesText","view","ATTACHED","row","value","setRow","Number","col","setColumn","rowSpan","setRowSpan","colSpan","setColumnSpan","dock","setDock","left","setLeft","top","setTop","order","setOrder","flexGrow","setFlexGrow","flexShrink","setFlexShrink","NativeScriptAdapter","platform","createView","get","setProperty","name","className","String","style","includes","path","split","last","pop","target","key","undefined","hasProperty","replace","insertChild","parent","child","index","content","Error","typeName","removeChild","setSlot","property","bag","insertInSlot","items","splice","removeFromSlot","indexOf","change","actionItems","getItems","next","item","removeItem","addItem","current","length","on","event","listener","off","bindList","cell","options","onItemLoading","data","args","kinds","kindOf","itemTemplates","map","itemTemplateSelector","_item","itemTemplate","itemLoadingEvent","setCount","count","getItem","refresh","release"],"sources":["../../src/nativescript-adapter.ts"],"sourcesContent":["// The adapter that drives NativeScript's views on a device. Not run in this repository's tests (they need iOS or\n// Android); `pnpm typecheck` checks it against @nativescript/core's types.\n//\n// Static attributes arrive as strings, as they would from NativeScript's XML, and are assigned the same way;\n// dynamic ones arrive as their values (an array, a Date, an ImageSource) and are assigned as they are.\n// Strings: NativeScript's properties convert them themselves (`isEnabled=\"false\"`, `columns=\"*, auto\"` on a\n// GridLayout), attached layout properties such as `col` go through their layout's setter, `class` sets className\n// and `style` sets inline CSS. A dotted name sets a nested property (`ios.position` on an ActionItem).\n\nimport {\n AbsoluteLayout,\n ActionBar,\n ActionItem,\n ActivityIndicator,\n Button,\n ContentView,\n DatePicker,\n DockLayout,\n FlexboxLayout,\n FormattedString,\n Frame,\n GridLayout,\n HtmlView,\n Image,\n isIOS,\n type ItemEventData,\n Label,\n LayoutBase,\n ListPicker,\n ListView,\n NavigationButton,\n ObservableArray,\n Page,\n Placeholder,\n Progress,\n RootLayout,\n ScrollView,\n SearchBar,\n SegmentedBar,\n SegmentedBarItem,\n Slider,\n Span,\n StackLayout,\n Switch,\n TabView,\n TabViewItem,\n TextField,\n TextView,\n TimePicker,\n View,\n type ViewBase,\n WebView,\n WrapLayout,\n} from '@nativescript/core';\n\nimport type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.ts';\nimport { defineElement, type ElementDefinition } from './elements.ts';\nimport { FrameNavigationHost } from './frame-host.ts';\nimport type { FrameHost } from './navigator.ts';\n\nconst VIEWS = new Map<string, () => ViewBase>(\n Object.entries({\n absoluteLayout: () => new AbsoluteLayout(),\n actionBar: () => new ActionBar(),\n actionItem: () => new ActionItem(),\n activityIndicator: () => new ActivityIndicator(),\n button: () => new Button(),\n contentView: () => new ContentView(),\n datePicker: () => new DatePicker(),\n dockLayout: () => new DockLayout(),\n flexboxLayout: () => new FlexboxLayout(),\n formattedString: () => new FormattedString(),\n frame: () => new Frame(),\n gridLayout: () => new GridLayout(),\n htmlView: () => new HtmlView(),\n image: () => new Image(),\n label: () => new Label(),\n listPicker: () => new ListPicker(),\n listView: () => new ListView(),\n navigationButton: () => new NavigationButton(),\n page: () => new Page(),\n placeholder: () => new Placeholder(),\n progress: () => new Progress(),\n rootLayout: () => new RootLayout(),\n scrollView: () => new ScrollView(),\n searchBar: () => new SearchBar(),\n segmentedBar: () => new SegmentedBar(),\n segmentedBarItem: () => new SegmentedBarItem(),\n slider: () => new Slider(),\n span: () => new Span(),\n stackLayout: () => new StackLayout(),\n switch: () => new Switch(),\n tabView: () => new TabView(),\n tabViewItem: () => new TabViewItem(),\n textField: () => new TextField(),\n textView: () => new TextView(),\n timePicker: () => new TimePicker(),\n webView: () => new WebView(),\n wrapLayout: () => new WrapLayout(),\n }),\n);\n\n/**\n * Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:\n * { property: 'items', list: true } })`. The definition says which children go into properties rather than being\n * child views (see elements.ts); leave it out for a view that lays out its children or has none.\n */\nexport function registerElement(tag: string, create: () => ViewBase, definition?: ElementDefinition): void {\n VIEWS.set(tag, create);\n if (definition) defineElement(tag, definition);\n}\n\n// Views whose text children become their `text` property.\nconst takesText = (view: ViewBase): boolean =>\n view instanceof Label ||\n view instanceof Button ||\n view instanceof TextField ||\n view instanceof TextView ||\n view instanceof Span;\n\n// Properties a view's parent layout reads, written on the child: GridLayout's row/col, DockLayout's dock,\n// AbsoluteLayout's left/top, FlexboxLayout's order/flexGrow…\nconst ATTACHED: Record<string, (view: View, value: string) => void> = {\n row: (view, value) => GridLayout.setRow(view, Number(value)),\n col: (view, value) => GridLayout.setColumn(view, Number(value)),\n rowSpan: (view, value) => GridLayout.setRowSpan(view, Number(value)),\n colSpan: (view, value) => GridLayout.setColumnSpan(view, Number(value)),\n dock: (view, value) => DockLayout.setDock(view, value as never),\n left: (view, value) => AbsoluteLayout.setLeft(view, Number(value)),\n top: (view, value) => AbsoluteLayout.setTop(view, Number(value)),\n order: (view, value) => FlexboxLayout.setOrder(view, Number(value)),\n flexGrow: (view, value) => FlexboxLayout.setFlexGrow(view, Number(value)),\n flexShrink: (view, value) => FlexboxLayout.setFlexShrink(view, Number(value)),\n};\n\ntype Bag = Record<string, unknown>;\n\nexport class NativeScriptAdapter implements NativeAdapter<ViewBase> {\n readonly platform = isIOS ? ('ios' as const) : ('android' as const);\n\n createView(tag: string): ViewBase | null {\n return VIEWS.get(tag)?.() ?? null;\n }\n\n setProperty(view: ViewBase, name: string, value: unknown): void {\n if (name === 'class') {\n view.className = value === null ? '' : String(value);\n } else if (name === 'style') {\n // NativeScript parses an inline CSS string assigned to `style`, as XML's style=\"…\" does.\n (view as unknown as { style: unknown }).style = value ?? '';\n } else if (ATTACHED[name]) {\n if (value !== null) ATTACHED[name](view as View, String(value));\n } else if (name.includes('.')) {\n const path = name.split('.');\n const last = path.pop()!;\n let target = view as unknown as Bag;\n for (const key of path) target = (target[key] ??= {}) as Bag;\n target[last] = value === null ? undefined : value;\n } else {\n // Unset goes back to the property's default.\n (view as unknown as Bag)[name] = value === null ? undefined : value;\n }\n }\n\n // NativeScript defines its properties as accessors on each view class, so `in` finds them (`items` on a\n // ListPicker, `date` on a DatePicker). Layout properties such as `col` aren't, and stay strings.\n hasProperty(view: ViewBase, name: string): boolean {\n return name.replace(/^(ios|android):/, '') in view;\n }\n\n takesText(view: ViewBase): boolean {\n return takesText(view);\n }\n\n insertChild(parent: ViewBase, child: ViewBase, index: number): void {\n if (parent instanceof LayoutBase) {\n parent.insertChild(child as View, index);\n } else if (parent instanceof ContentView || parent instanceof Page || parent instanceof ScrollView) {\n parent.content = child as View;\n } else {\n throw new Error(`[ember-nativescript] <${parent.typeName}> can't hold views.`);\n }\n }\n\n removeChild(parent: ViewBase, child: ViewBase): void {\n if (parent instanceof LayoutBase) {\n parent.removeChild(child as View);\n } else if ((parent as ContentView).content === child) {\n (parent as ContentView).content = null as unknown as View;\n }\n }\n\n // A page always has an ActionBar (setting it to null throws): taking ours out puts back a blank one, as a page\n // that never had one shows.\n setSlot(parent: ViewBase, property: string, child: ViewBase | null): void {\n if (!child && parent instanceof Page && property === 'actionBar') {\n parent.actionBar = new ActionBar();\n return;\n }\n const bag = parent as unknown as Bag;\n if (child || bag[property]) bag[property] = child ?? null;\n }\n\n // NativeScript's list properties are set three ways: an ActionBar's actionItems through addItem and removeItem, a\n // FormattedString's spans as an ObservableArray it watches, and a SegmentedBar's or TabView's items by assigning a new\n // array, which its property handler compares with the old one.\n insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void {\n this.#updateList(parent, property, (items) => items.splice(index, 0, child));\n }\n\n removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void {\n this.#updateList(parent, property, (items) => {\n const index = items.indexOf(child);\n if (index !== -1) items.splice(index, 1);\n });\n }\n\n #updateList(parent: ViewBase, property: string, change: (items: ViewBase[]) => void): void {\n if (parent instanceof ActionBar && property === 'actionItems') {\n const items = parent.actionItems.getItems();\n const next = [...items];\n change(next);\n for (const item of items) parent.actionItems.removeItem(item);\n for (const item of next) parent.actionItems.addItem(item as ActionItem);\n return;\n }\n\n const current = (parent as unknown as Bag)[property];\n if (current instanceof ObservableArray) {\n const next = [...current] as ViewBase[];\n change(next);\n current.splice(0, current.length, ...next);\n return;\n }\n\n const next = [...((current as ViewBase[] | undefined) ?? [])];\n change(next);\n (parent as unknown as Bag)[property] = next;\n }\n\n on(view: ViewBase, event: string, listener: Listener): void {\n view.on(event, listener);\n }\n\n off(view: ViewBase, event: string, listener: Listener): void {\n view.off(event, listener);\n }\n\n // Each cell is an empty StackLayout from the item template; ember-native renders the row into it. `items` is only a\n // count (an ItemsSource whose items are their indexes): the rows read their item from Ember's state, not from\n // NativeScript's binding context.\n bindList(\n view: ViewBase,\n cell: (container: ViewBase, index: number) => void,\n options: ListOptions = {},\n ): ListBinding | null {\n if (!(view instanceof ListView)) return null;\n\n const onItemLoading = (data: unknown) => {\n const args = data as ItemEventData;\n cell(args.view, args.index);\n };\n const { kinds, kindOf } = options;\n if (kinds && kindOf) {\n // One template per kind: the list keeps a pool of cells per kind, and reuses a cell only for its kind.\n view.itemTemplates = kinds.map((key) => ({ key, createView: () => new StackLayout() }));\n view.itemTemplateSelector = (_item: unknown, index: number) => kindOf(index);\n } else {\n view.itemTemplate = () => new StackLayout();\n }\n view.on(ListView.itemLoadingEvent, onItemLoading);\n\n return {\n setCount(count) {\n view.items = { length: count, getItem: (index: number) => index };\n view.refresh();\n },\n release() {\n view.off(ListView.itemLoadingEvent, onItemLoading);\n },\n };\n }\n}\n"],"mappings":";;;AA4DA,IAAMyC,QAAQ,IAAIC,IAChBC,OAAOC,QAAQ;CACbC,sBAAsB,IAAI7C,eAAe;CACzC8C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AAKI,KAAK7E,MAAM6E,KAAK/B,KAAK;EAC5B;EACA,MAAM,EAAEgC,OAAOC,WAAWL;EAC1B,IAAII,SAASC,QAAQ;GAEnB/E,KAAKgF,gBAAgBF,MAAMG,KAAK1C,SAAS;IAAEA;IAAKb,kBAAkB,IAAInF,YAAY;GAAE,EAAE;GACtFyD,KAAKkF,wBAAwBC,OAAgBrC,UAAkBiC,OAAOjC,KAAK;EAC7E,OACE9C,KAAKoF,qBAAqB,IAAI7I,YAAY;EAE5CyD,KAAKoE,GAAG1I,SAAS2J,kBAAkBV,aAAa;EAEhD,OAAO;GACLW,SAASC,OAAO;IACdvF,KAAKuD,QAAQ;KAAEY,QAAQoB;KAAOC,UAAU1C,UAAkBA;IAAM;IAChE9C,KAAKyF,QAAQ;GACf;GACAC,UAAU;IACR1F,KAAKuE,IAAI7I,SAAS2J,kBAAkBV,aAAa;GACnD;EACF;CACF;AACF"}
|
package/dist/src/navigator.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import type { NativeDocument } from './dom.js';
|
|
|
2
2
|
import { type NativeRoot } from './render.js';
|
|
3
3
|
export interface ShowOptions {
|
|
4
4
|
animated: boolean;
|
|
5
|
+
/** The screen being shown, for a host that names it (the web host's URL). Native hosts ignore it. */
|
|
6
|
+
screen?: {
|
|
7
|
+
component: object;
|
|
8
|
+
args?: Record<string, unknown>;
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
5
11
|
/** Passed to the host as is: a NativeScript NavigationTransition. */
|
|
6
12
|
transition?: unknown;
|
|
7
13
|
clearHistory: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigator.d.ts","sourceRoot":"","sources":["../../src/navigator.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,aAAa,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,OAAO,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AAS,IAAI,OAAO,CAEvB;IAED,QAAQ,GAAI,WAAW,MAAM,EAAE,UAAS,eAAoB,KAAG,UAAU,CAuCvE;IAEF,0EAA0E;IAC1E,IAAI,QAAO,IAAI,CAEb;IAEF,SAAS,GAAI,MAAM,GAAG,OAAO,EAAE,WAAW,MAAM,EAAE,UAAS,YAAiB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgCxG;IAEF,6EAA6E;IAC7E,UAAU,GAAI,SAAS,OAAO,KAAG,IAAI,CAEnC;IAEF,0GAA0G;IAC1G,OAAO,QAAO,IAAI,CAIhB;CAkBH"}
|
package/dist/src/navigator.js
CHANGED
|
@@ -68,7 +68,12 @@ var Navigator = class {
|
|
|
68
68
|
animated: options.animated ?? this.#stack.length + this.#dropped.length > 1,
|
|
69
69
|
transition: options.transition,
|
|
70
70
|
clearHistory: options.clearHistory ?? false,
|
|
71
|
-
backstackVisible: screen.backstackVisible
|
|
71
|
+
backstackVisible: screen.backstackVisible,
|
|
72
|
+
screen: {
|
|
73
|
+
component,
|
|
74
|
+
args: options.args,
|
|
75
|
+
name: screen.name
|
|
76
|
+
}
|
|
72
77
|
});
|
|
73
78
|
return root;
|
|
74
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigator.js","names":["tracked","renderNative","g","i","Navigator","prototype","depth","current","modals","constructor","document","host","owner","canGoBack","navigate","component","options","root","args","nav","onNavigatedTo","onNavigatedFrom","data","isBackNavigation","screen","name","backstackVisible","release","element","removeEventListener","destroy","previous","at","clearHistory","push","splice","pop","addEventListener","show","view","animated","length","transition","back","showModal","Promise","resolve","open","closeModal","result","onClose","indexOf","fullscreen","stretched","close","reverse","index"],"sources":["../../src/navigator.ts"],"sourcesContent":["// Screens and modals, the way NativeScript-Vue's navigateTo, navigateBack, showModal and closeModal work.\n//\n// Each screen is a component rendered into its own <page>, shown through the host (NativeScript's Frame on a\n// device, an array in tests). The page's own events keep the stack honest: a page leaves with `navigatedFrom` and\n// `isBackNavigation`, whether the back came from here, from Android's back button or from iOS's swipe, and that is\n// when its render is destroyed. Pages the Frame drops without a back (clearHistory, backstackVisible: false) are\n// destroyed once the next page has arrived (`navigatedTo`).\n//\n// A modal is a component rendered into a view of its own and shown over the current page. It gets `@closeModal`;\n// showModal() resolves with what it passes, or with undefined when the user dismisses it.\n\nimport { tracked } from '@glimmer/tracking';\n\nimport type { NativeDocument } from './dom.ts';\nimport { type NativeRoot, renderNative } from './render.ts';\n\nexport interface ShowOptions {\n animated: boolean;\n /** Passed to the host as is: a NativeScript NavigationTransition. */\n transition?: unknown;\n clearHistory: boolean;\n backstackVisible: boolean;\n}\n\nexport interface ModalHostOptions {\n fullscreen: boolean;\n animated: boolean;\n stretched: boolean;\n /** The host calls this once the modal is gone, with the result it was closed with (none when dismissed). */\n onClose: (result?: unknown) => void;\n}\n\nexport interface FrameHost<View = unknown> {\n show(page: View, options: ShowOptions): void;\n back(): void;\n showModal(view: View, options: ModalHostOptions): void;\n closeModal(view: View, result: unknown): void;\n}\n\nexport interface NavigateOptions {\n args?: Record<string, unknown>;\n /** A name for the screen, for `navigator.current` and tests. */\n name?: string;\n /** Animates the change of page. Defaults to true except for the first screen. */\n animated?: boolean;\n transition?: unknown;\n /** Drops every screen before this one: there is nothing to go back to. */\n clearHistory?: boolean;\n /** False to leave this screen out of the back stack once the next one is shown (a splash, a login). */\n backstackVisible?: boolean;\n}\n\nexport interface ModalOptions {\n args?: Record<string, unknown>;\n fullscreen?: boolean;\n animated?: boolean;\n stretched?: boolean;\n /** The tag of the view the modal renders into. */\n root?: string;\n}\n\ninterface Screen {\n name: string;\n root: NativeRoot;\n backstackVisible: boolean;\n /** Stops listening to the page and destroys the render. */\n release(): void;\n}\n\ninterface NavigatedData {\n isBackNavigation?: boolean;\n}\n\nexport class Navigator {\n /** How many screens are in the stack. */\n @tracked depth = 0;\n /** The name of the screen on top. */\n @tracked current: string | undefined;\n /** How many modals are open. */\n @tracked modals = 0;\n readonly #stack: Screen[] = [];\n readonly #closers: Array<(result?: unknown) => void> = [];\n // Screens the Frame dropped without a back, destroyed when the next page has arrived.\n #dropped: Screen[] = [];\n\n constructor(\n readonly document: NativeDocument,\n readonly host: FrameHost,\n readonly owner: object = {},\n ) {}\n\n get canGoBack(): boolean {\n return this.depth > 1;\n }\n\n navigate = (component: object, options: NavigateOptions = {}): NativeRoot => {\n const root = renderNative(component, {\n document: this.document,\n root: 'page',\n owner: this.owner,\n args: { ...options.args, nav: this },\n });\n const onNavigatedTo = (): void => this.#destroyDropped();\n const onNavigatedFrom = (data: unknown): void => {\n if ((data as NavigatedData).isBackNavigation) this.#popped(screen);\n };\n const screen: Screen = {\n name: options.name ?? 'screen',\n root,\n backstackVisible: options.backstackVisible ?? true,\n release() {\n root.element.removeEventListener('navigatedTo', onNavigatedTo);\n root.element.removeEventListener('navigatedFrom', onNavigatedFrom);\n root.destroy();\n },\n };\n const previous = this.#stack.at(-1);\n\n if (options.clearHistory) this.#dropped.push(...this.#stack.splice(0));\n else if (previous && !previous.backstackVisible) this.#dropped.push(this.#stack.pop()!);\n\n root.element.addEventListener('navigatedTo', onNavigatedTo);\n root.element.addEventListener('navigatedFrom', onNavigatedFrom);\n\n this.#stack.push(screen);\n this.#changed();\n this.host.show(root.view, {\n animated: options.animated ?? this.#stack.length + this.#dropped.length > 1,\n transition: options.transition,\n clearHistory: options.clearHistory ?? false,\n backstackVisible: screen.backstackVisible,\n });\n return root;\n };\n\n /** Goes back a screen. The screen is destroyed when its page has left. */\n back = (): void => {\n if (this.#stack.length > 1) this.host.back();\n };\n\n showModal = <Result = unknown>(component: object, options: ModalOptions = {}): Promise<Result | undefined> => {\n return new Promise((resolve) => {\n let open = true;\n let root: NativeRoot | undefined;\n\n const closeModal = (result?: unknown): void => {\n if (open && root) this.host.closeModal(root.view, result);\n };\n const onClose = (result?: unknown): void => {\n if (!open) return;\n open = false;\n this.#closers.splice(this.#closers.indexOf(closeModal), 1);\n this.modals = this.#closers.length;\n root?.destroy();\n resolve(result as Result | undefined);\n };\n\n root = renderNative(component, {\n document: this.document,\n root: options.root ?? 'contentView',\n owner: this.owner,\n args: { ...options.args, nav: this, closeModal },\n });\n this.#closers.push(closeModal);\n this.modals = this.#closers.length;\n this.host.showModal(root.view, {\n fullscreen: options.fullscreen ?? false,\n animated: options.animated ?? true,\n stretched: options.stretched ?? false,\n onClose,\n });\n });\n };\n\n /** Closes the modal on top with a result, as its own `@closeModal` would. */\n closeModal = (result?: unknown): void => {\n this.#closers.at(-1)?.(result);\n };\n\n /** Destroys every screen, and closes open modals with no result. For a frame that goes away (a tab's). */\n destroy = (): void => {\n for (const screen of [...this.#stack.splice(0), ...this.#dropped.splice(0)]) screen.release();\n this.#changed();\n for (const close of [...this.#closers].reverse()) close();\n };\n\n #popped(screen: Screen): void {\n const index = this.#stack.indexOf(screen);\n if (index === -1) return;\n this.#stack.splice(index, 1);\n this.#changed();\n screen.release();\n }\n\n #changed(): void {\n this.depth = this.#stack.length;\n this.current = this.#stack.at(-1)?.name;\n }\n\n #destroyDropped(): void {\n for (const screen of this.#dropped.splice(0)) screen.release();\n }\n}\n"],"mappings":";;;;AAyEA,IAAaI,YAAb,MAAuB;CAAA;EAAAF,gBAAA,KAAAG,WAAA,SAAA,CAEpBL,OAAO,GAAA,WAAA;GAAA,OAAS;EAAC,CAAA;CAAA;CAAA,UAAAG,4BAAA,MAAA,OAAA,GAAA,KAAA;;CADlB;EAAAD,gBAAA,KAAAG,WAAA,WAAA,CAGCL,OAAO,CAAA;CAAA;CAAA,YAAAG,4BAAA,MAAA,SAAA,GAAA,KAAA;;CADR;EAAAD,gBAAA,KAAAG,WAAA,UAAA,CAGCL,OAAO,GAAA,WAAA;GAAA,OAAU;EAAC,CAAA;CAAA;CAAA,WAAAG,4BAAA,MAAA,QAAA,GAAA,KAAA;;CACV,SAAmB,CAAA;CACnB,WAA8C,CAAA;CAEvD,WAAqB,CAAA;CAErBM,YACWC,UACAC,MACAC,QAAgB,CAAC,GAC1B;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QAAQ,CAAC,CAACC,QAAQ,GAAGD,MAAM;CAC1D;CAEA,QAAQ9B,QAAsB;EAC5B,MAAMgC,QAAQ,KAAK,OAAOL,QAAQ3B,MAAM;EACxC,IAAIgC,UAAU,IAAI;EAClB,KAAK,OAAOrB,OAAOqB,OAAO,CAAC;EAC3B,KAAK,SAAS;EACdhC,OAAOG,QAAQ;CACjB;CAEA,WAAiB;EACf,KAAKrB,QAAQ,KAAK,OAAOmC;EACzB,KAAKlC,UAAU,KAAK,OAAOyB,GAAG,EAAE,CAAC,EAAEP;CACrC;CAEA,kBAAwB;EACtB,KAAK,MAAMD,UAAU,KAAK,SAASW,OAAO,CAAC,GAAGX,OAAOG,QAAQ;CAC/D;AACF"}
|
|
1
|
+
{"version":3,"file":"navigator.js","names":["tracked","renderNative","g","i","Navigator","prototype","depth","current","modals","constructor","document","host","owner","canGoBack","navigate","component","options","root","args","nav","onNavigatedTo","onNavigatedFrom","data","isBackNavigation","screen","name","backstackVisible","release","element","removeEventListener","destroy","previous","at","clearHistory","push","splice","pop","addEventListener","show","view","animated","length","transition","back","showModal","Promise","resolve","open","closeModal","result","onClose","indexOf","fullscreen","stretched","close","reverse","index"],"sources":["../../src/navigator.ts"],"sourcesContent":["// Screens and modals, the way NativeScript-Vue's navigateTo, navigateBack, showModal and closeModal work.\n//\n// Each screen is a component rendered into its own <page>, shown through the host (NativeScript's Frame on a\n// device, an array in tests). The page's own events keep the stack honest: a page leaves with `navigatedFrom` and\n// `isBackNavigation`, whether the back came from here, from Android's back button or from iOS's swipe, and that is\n// when its render is destroyed. Pages the Frame drops without a back (clearHistory, backstackVisible: false) are\n// destroyed once the next page has arrived (`navigatedTo`).\n//\n// A modal is a component rendered into a view of its own and shown over the current page. It gets `@closeModal`;\n// showModal() resolves with what it passes, or with undefined when the user dismisses it.\n\nimport { tracked } from '@glimmer/tracking';\n\nimport type { NativeDocument } from './dom.ts';\nimport { type NativeRoot, renderNative } from './render.ts';\n\nexport interface ShowOptions {\n animated: boolean;\n /** The screen being shown, for a host that names it (the web host's URL). Native hosts ignore it. */\n screen?: { component: object; args?: Record<string, unknown>; name: string };\n /** Passed to the host as is: a NativeScript NavigationTransition. */\n transition?: unknown;\n clearHistory: boolean;\n backstackVisible: boolean;\n}\n\nexport interface ModalHostOptions {\n fullscreen: boolean;\n animated: boolean;\n stretched: boolean;\n /** The host calls this once the modal is gone, with the result it was closed with (none when dismissed). */\n onClose: (result?: unknown) => void;\n}\n\nexport interface FrameHost<View = unknown> {\n show(page: View, options: ShowOptions): void;\n back(): void;\n showModal(view: View, options: ModalHostOptions): void;\n closeModal(view: View, result: unknown): void;\n}\n\nexport interface NavigateOptions {\n args?: Record<string, unknown>;\n /** A name for the screen, for `navigator.current` and tests. */\n name?: string;\n /** Animates the change of page. Defaults to true except for the first screen. */\n animated?: boolean;\n transition?: unknown;\n /** Drops every screen before this one: there is nothing to go back to. */\n clearHistory?: boolean;\n /** False to leave this screen out of the back stack once the next one is shown (a splash, a login). */\n backstackVisible?: boolean;\n}\n\nexport interface ModalOptions {\n args?: Record<string, unknown>;\n fullscreen?: boolean;\n animated?: boolean;\n stretched?: boolean;\n /** The tag of the view the modal renders into. */\n root?: string;\n}\n\ninterface Screen {\n name: string;\n root: NativeRoot;\n backstackVisible: boolean;\n /** Stops listening to the page and destroys the render. */\n release(): void;\n}\n\ninterface NavigatedData {\n isBackNavigation?: boolean;\n}\n\nexport class Navigator {\n /** How many screens are in the stack. */\n @tracked depth = 0;\n /** The name of the screen on top. */\n @tracked current: string | undefined;\n /** How many modals are open. */\n @tracked modals = 0;\n readonly #stack: Screen[] = [];\n readonly #closers: Array<(result?: unknown) => void> = [];\n // Screens the Frame dropped without a back, destroyed when the next page has arrived.\n #dropped: Screen[] = [];\n\n constructor(\n readonly document: NativeDocument,\n readonly host: FrameHost,\n readonly owner: object = {},\n ) {}\n\n get canGoBack(): boolean {\n return this.depth > 1;\n }\n\n navigate = (component: object, options: NavigateOptions = {}): NativeRoot => {\n const root = renderNative(component, {\n document: this.document,\n root: 'page',\n owner: this.owner,\n args: { ...options.args, nav: this },\n });\n const onNavigatedTo = (): void => this.#destroyDropped();\n const onNavigatedFrom = (data: unknown): void => {\n if ((data as NavigatedData).isBackNavigation) this.#popped(screen);\n };\n const screen: Screen = {\n name: options.name ?? 'screen',\n root,\n backstackVisible: options.backstackVisible ?? true,\n release() {\n root.element.removeEventListener('navigatedTo', onNavigatedTo);\n root.element.removeEventListener('navigatedFrom', onNavigatedFrom);\n root.destroy();\n },\n };\n const previous = this.#stack.at(-1);\n\n if (options.clearHistory) this.#dropped.push(...this.#stack.splice(0));\n else if (previous && !previous.backstackVisible) this.#dropped.push(this.#stack.pop()!);\n\n root.element.addEventListener('navigatedTo', onNavigatedTo);\n root.element.addEventListener('navigatedFrom', onNavigatedFrom);\n\n this.#stack.push(screen);\n this.#changed();\n this.host.show(root.view, {\n animated: options.animated ?? this.#stack.length + this.#dropped.length > 1,\n transition: options.transition,\n clearHistory: options.clearHistory ?? false,\n backstackVisible: screen.backstackVisible,\n screen: { component, args: options.args, name: screen.name },\n });\n return root;\n };\n\n /** Goes back a screen. The screen is destroyed when its page has left. */\n back = (): void => {\n if (this.#stack.length > 1) this.host.back();\n };\n\n showModal = <Result = unknown>(component: object, options: ModalOptions = {}): Promise<Result | undefined> => {\n return new Promise((resolve) => {\n let open = true;\n let root: NativeRoot | undefined;\n\n const closeModal = (result?: unknown): void => {\n if (open && root) this.host.closeModal(root.view, result);\n };\n const onClose = (result?: unknown): void => {\n if (!open) return;\n open = false;\n this.#closers.splice(this.#closers.indexOf(closeModal), 1);\n this.modals = this.#closers.length;\n root?.destroy();\n resolve(result as Result | undefined);\n };\n\n root = renderNative(component, {\n document: this.document,\n root: options.root ?? 'contentView',\n owner: this.owner,\n args: { ...options.args, nav: this, closeModal },\n });\n this.#closers.push(closeModal);\n this.modals = this.#closers.length;\n this.host.showModal(root.view, {\n fullscreen: options.fullscreen ?? false,\n animated: options.animated ?? true,\n stretched: options.stretched ?? false,\n onClose,\n });\n });\n };\n\n /** Closes the modal on top with a result, as its own `@closeModal` would. */\n closeModal = (result?: unknown): void => {\n this.#closers.at(-1)?.(result);\n };\n\n /** Destroys every screen, and closes open modals with no result. For a frame that goes away (a tab's). */\n destroy = (): void => {\n for (const screen of [...this.#stack.splice(0), ...this.#dropped.splice(0)]) screen.release();\n this.#changed();\n for (const close of [...this.#closers].reverse()) close();\n };\n\n #popped(screen: Screen): void {\n const index = this.#stack.indexOf(screen);\n if (index === -1) return;\n this.#stack.splice(index, 1);\n this.#changed();\n screen.release();\n }\n\n #changed(): void {\n this.depth = this.#stack.length;\n this.current = this.#stack.at(-1)?.name;\n }\n\n #destroyDropped(): void {\n for (const screen of this.#dropped.splice(0)) screen.release();\n }\n}\n"],"mappings":";;;;AA2EA,IAAaI,YAAb,MAAuB;CAAA;EAAAF,gBAAA,KAAAG,WAAA,SAAA,CAEpBL,OAAO,GAAA,WAAA;GAAA,OAAS;EAAC,CAAA;CAAA;CAAA,UAAAG,4BAAA,MAAA,OAAA,GAAA,KAAA;;CADlB;EAAAD,gBAAA,KAAAG,WAAA,WAAA,CAGCL,OAAO,CAAA;CAAA;CAAA,YAAAG,4BAAA,MAAA,SAAA,GAAA,KAAA;;CADR;EAAAD,gBAAA,KAAAG,WAAA,UAAA,CAGCL,OAAO,GAAA,WAAA;GAAA,OAAU;EAAC,CAAA;CAAA;CAAA,WAAAG,4BAAA,MAAA,QAAA,GAAA,KAAA;;CACV,SAAmB,CAAA;CACnB,WAA8C,CAAA;CAEvD,WAAqB,CAAA;CAErBM,YACWC,UACAC,MACAC,QAAgB,CAAC,GAC1B;EAAA,KAHSF,WAAAA;EAAwB,KACxBC,OAAAA;EAAe,KACfC,QAAAA;CACR;CAEH,IAAIC,YAAqB;EACvB,OAAO,KAAKP,QAAQ;CACtB;CAEAQ,YAAYC,WAAmBC,UAA2B,CAAC,MAAkB;EAC3E,MAAMC,OAAOhB,aAAac,WAAW;GACnCL,UAAU,KAAKA;GACf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,KAAK,OAAOrB,OAAOqB,OAAO,CAAC;EAC3B,KAAK,SAAS;EACdhC,OAAOG,QAAQ;CACjB;CAEA,WAAiB;EACf,KAAKrB,QAAQ,KAAK,OAAOmC;EACzB,KAAKlC,UAAU,KAAK,OAAOyB,GAAG,EAAE,CAAC,EAAEP;CACrC;CAEA,kBAAwB;EACtB,KAAK,MAAMD,UAAU,KAAK,SAASW,OAAO,CAAC,GAAGX,OAAOG,QAAQ;CAC/D;AACF"}
|
package/dist/src/platform.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare
|
|
1
|
+
export type Platform = 'ios' | 'android' | 'web';
|
|
2
|
+
export declare function setPlatform(platform: Platform | undefined): void;
|
|
3
|
+
export declare const platform: () => Platform | undefined;
|
|
3
4
|
export declare const isIOS: () => boolean;
|
|
4
5
|
export declare const isAndroid: () => boolean;
|
|
6
|
+
export declare const isWeb: () => boolean;
|
|
5
7
|
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAAC;AAIjD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAEhE;AAED,eAAO,MAAM,QAAQ,QAAO,QAAQ,GAAG,SAAoB,CAAC;AAC5D,eAAO,MAAM,KAAK,QAAO,OAA4B,CAAC;AACtD,eAAO,MAAM,SAAS,QAAO,OAAgC,CAAC;AAC9D,eAAO,MAAM,KAAK,QAAO,OAA4B,CAAC"}
|
package/dist/src/platform.js
CHANGED
|
@@ -6,6 +6,7 @@ function setPlatform(platform) {
|
|
|
6
6
|
var platform = () => current;
|
|
7
7
|
var isIOS = () => current === "ios";
|
|
8
8
|
var isAndroid = () => current === "android";
|
|
9
|
-
|
|
9
|
+
var isWeb = () => current === "web";
|
|
10
|
+
export { isAndroid, isIOS, isWeb, platform, setPlatform };
|
|
10
11
|
|
|
11
12
|
//# sourceMappingURL=platform.js.map
|
package/dist/src/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","names":[],"sources":["../../src/platform.ts"],"sourcesContent":["// Which platform the app runs on, for templates: {{#if (isIOS)}}…{{/if}}. Set from the adapter when a document is\n// created, which happens once, before anything renders.\
|
|
1
|
+
{"version":3,"file":"platform.js","names":[],"sources":["../../src/platform.ts"],"sourcesContent":["// Which platform the app runs on, for templates: {{#if (isIOS)}}…{{/if}}. Set from the adapter when a document is\n// created, which happens once, before anything renders. `web` is the browser, through the web adapter.\nexport type Platform = 'ios' | 'android' | 'web';\n\nlet current: Platform | undefined;\n\nexport function setPlatform(platform: Platform | undefined): void {\n current = platform;\n}\n\nexport const platform = (): Platform | undefined => current;\nexport const isIOS = (): boolean => current === 'ios';\nexport const isAndroid = (): boolean => current === 'android';\nexport const isWeb = (): boolean => current === 'web';\n"],"mappings":";AAIA,IAAI;AAEJ,SAAgB,YAAY,UAAsC;CAChE,UAAU;AACZ;AAEA,IAAa,iBAAuC;AACpD,IAAa,cAAuB,YAAY;AAChD,IAAa,kBAA2B,YAAY;AACpD,IAAa,cAAuB,YAAY"}
|
package/dist/src/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AASzD,MAAM,WAAW,UAAU,CAAC,IAAI,GAAG,OAAO;IACxC,4DAA4D;IAC5D,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,cAAc,CAAC;IACzB,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,CAGrE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAC/B,SAAS,EAAE,MAAM,EACjB,EAAE,QAAQ,EAAE,IAAa,EAAE,IAAI,EAAE,KAAU,EAAE,EAAE,mBAAmB,GACjE,UAAU,CAAC,IAAI,CAAC,CAgBlB"}
|
package/dist/src/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":["renderComponent","NativeDocument","NativeElement","setPlatform","globals","globalThis","Element","createDocument","adapter","platform","renderNative","component","document","root","args","owner","element","createElement","view","Error","result","into","env","isInteractive","hasDOM","destroy"],"sources":["../../src/render.ts"],"sourcesContent":["// Renders Ember components into native views with Ember's public `renderComponent`, which takes the\n// document to build with (`env.document`). Nothing private from Ember is used here.\n\nimport { renderComponent } from '@ember/renderer';\n\nimport type { NativeAdapter } from './adapter.ts';\nimport { NativeDocument, NativeElement } from './dom.ts';\nimport { setPlatform } from './platform.ts';\n\n// `renderComponent` checks `into instanceof Element` before clearing its target. Neither Node nor\n// NativeScript has a global Element, so the shim's element class stands in for it.\nconst globals = globalThis as { Element?: unknown };\nglobals.Element ??= NativeElement;\n\nexport interface NativeRoot<View = unknown> {\n /** The root element; its view is what the toolkit shows. */\n element: NativeElement;\n view: View;\n destroy(): void;\n}\n\nexport interface RenderNativeOptions {\n document: NativeDocument;\n /** The tag of the root view the component renders into, such as `page` or `stackLayout`. */\n root?: string;\n args?: Record<string, unknown>;\n owner?: object;\n}\n\nexport function createDocument(adapter: NativeAdapter): NativeDocument {\n setPlatform(adapter.platform);\n return new NativeDocument(adapter);\n}\n\nexport function renderNative<View>(\n component: object,\n { document, root = 'page', args, owner = {} }: RenderNativeOptions,\n): NativeRoot<View> {\n const element = document.createElement(root);\n if (!element.view) throw new Error(`[ember-nativescript] <${root}> has no view, so it can't be a root.`);\n\n const result = renderComponent(component, {\n into: element as unknown as Element,\n owner,\n args,\n env: { document: document as unknown as Document, isInteractive: true, hasDOM: true } as never,\n });\n\n return {\n element,\n view: element.view as View,\n destroy: () => result.destroy(),\n };\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"render.js","names":["renderComponent","NativeDocument","NativeElement","setPlatform","globals","globalThis","Element","createDocument","adapter","platform","renderNative","component","document","root","args","owner","element","createElement","view","Error","result","into","env","isInteractive","hasDOM","destroy"],"sources":["../../src/render.ts"],"sourcesContent":["// Renders Ember components into native views with Ember's public `renderComponent`, which takes the\n// document to build with (`env.document`). Nothing private from Ember is used here.\n\nimport { renderComponent } from '@ember/renderer';\n\nimport type { NativeAdapter } from './adapter.ts';\nimport { NativeDocument, NativeElement } from './dom.ts';\nimport { setPlatform } from './platform.ts';\n\n// `renderComponent` checks `into instanceof Element` before clearing its target. Neither Node nor\n// NativeScript has a global Element, so the shim's element class stands in for it. A browser has one: there the check\n// fails, and renderComponent only skips clearing the target, which is a new element anyway.\nconst globals = globalThis as { Element?: unknown };\nglobals.Element ??= NativeElement;\n\nexport interface NativeRoot<View = unknown> {\n /** The root element; its view is what the toolkit shows. */\n element: NativeElement;\n view: View;\n destroy(): void;\n}\n\nexport interface RenderNativeOptions {\n document: NativeDocument;\n /** The tag of the root view the component renders into, such as `page` or `stackLayout`. */\n root?: string;\n args?: Record<string, unknown>;\n owner?: object;\n}\n\nexport function createDocument(adapter: NativeAdapter): NativeDocument {\n setPlatform(adapter.platform);\n return new NativeDocument(adapter);\n}\n\nexport function renderNative<View>(\n component: object,\n { document, root = 'page', args, owner = {} }: RenderNativeOptions,\n): NativeRoot<View> {\n const element = document.createElement(root);\n if (!element.view) throw new Error(`[ember-nativescript] <${root}> has no view, so it can't be a root.`);\n\n const result = renderComponent(component, {\n into: element as unknown as Element,\n owner,\n args,\n env: { document: document as unknown as Document, isInteractive: true, hasDOM: true } as never,\n });\n\n return {\n element,\n view: element.view as View,\n destroy: () => result.destroy(),\n };\n}\n"],"mappings":";;;;AAYA,IAAMI,UAAUC;AAChBD,QAAQE,YAAYJ;AAiBpB,SAAgBK,eAAeC,SAAwC;CACrEL,YAAYK,QAAQC,QAAQ;CAC5B,OAAO,IAAIR,eAAeO,OAAO;AACnC;AAEA,SAAgBE,aACdC,WACA,EAAEC,UAAUC,OAAO,QAAQC,MAAMC,QAAQ,CAAC,KACxB;CAClB,MAAMC,UAAUJ,SAASK,cAAcJ,IAAI;CAC3C,IAAI,CAACG,QAAQE,MAAM,MAAM,IAAIC,MAAM,yBAAyBN,KAAI,sCAAuC;CAEvG,MAAMO,SAASpB,gBAAgBW,WAAW;EACxCU,MAAML;EACND;EACAD;EACAQ,KAAK;GAAYV;GAAiCW,eAAe;GAAMC,QAAQ;EAAK;CACtF,CAAC;CAED,OAAO;EACLR;EACAE,MAAMF,QAAQE;EACdO,eAAeL,OAAOK,QAAQ;CAChC;AACF"}
|