ember-nativescript 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +421 -2
- package/dist/components/NativeFrame.d.ts +28 -0
- package/dist/components/NativeFrame.d.ts.map +1 -0
- package/dist/components/NativeFrame.js +39 -0
- package/dist/components/NativeFrame.js.map +1 -0
- package/dist/components/NativeList.d.ts +32 -0
- package/dist/components/NativeList.d.ts.map +1 -0
- package/dist/components/NativeList.js +44 -0
- package/dist/components/NativeList.js.map +1 -0
- package/dist/components/Platform.d.ts +21 -0
- package/dist/components/Platform.d.ts.map +1 -0
- package/dist/components/Platform.js +22 -0
- package/dist/components/Platform.js.map +1 -0
- package/dist/src/adapter.d.ts +51 -0
- package/dist/src/adapter.d.ts.map +1 -0
- package/dist/src/bind.d.ts +12 -0
- package/dist/src/bind.d.ts.map +1 -0
- package/dist/src/bind.js +32 -0
- package/dist/src/bind.js.map +1 -0
- package/dist/src/dom.d.ts +104 -0
- package/dist/src/dom.d.ts.map +1 -0
- package/dist/src/dom.js +329 -0
- package/dist/src/dom.js.map +1 -0
- package/dist/src/elements.d.ts +17 -0
- package/dist/src/elements.d.ts.map +1 -0
- package/dist/src/elements.js +52 -0
- package/dist/src/elements.js.map +1 -0
- package/dist/src/fake-adapter.d.ts +117 -0
- package/dist/src/fake-adapter.d.ts.map +1 -0
- package/dist/src/fake-adapter.js +400 -0
- package/dist/src/fake-adapter.js.map +1 -0
- package/dist/src/frame-host.d.ts +12 -0
- package/dist/src/frame-host.d.ts.map +1 -0
- package/dist/src/frame-host.js +34 -0
- package/dist/src/frame-host.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/list.d.ts +21 -0
- package/dist/src/list.d.ts.map +1 -0
- package/dist/src/list.js +96 -0
- package/dist/src/list.js.map +1 -0
- package/dist/src/modifier.d.ts +11 -0
- package/dist/src/modifier.d.ts.map +1 -0
- package/dist/src/modifier.js +27 -0
- package/dist/src/modifier.js.map +1 -0
- package/dist/src/native-view.d.ts +11 -0
- package/dist/src/native-view.d.ts.map +1 -0
- package/dist/src/native-view.js +28 -0
- package/dist/src/native-view.js.map +1 -0
- package/dist/src/nativescript-adapter.d.ts +26 -0
- package/dist/src/nativescript-adapter.d.ts.map +1 -0
- package/dist/src/nativescript-adapter.js +172 -0
- package/dist/src/nativescript-adapter.js.map +1 -0
- package/dist/src/nativescript-app.d.ts +18 -0
- package/dist/src/nativescript-app.d.ts.map +1 -0
- package/dist/src/nativescript-app.js +32 -0
- package/dist/src/nativescript-app.js.map +1 -0
- package/dist/src/navigator.d.ts +65 -0
- package/dist/src/navigator.d.ts.map +1 -0
- package/dist/src/navigator.js +141 -0
- package/dist/src/navigator.js.map +1 -0
- package/dist/src/owner.d.ts +39 -0
- package/dist/src/owner.d.ts.map +1 -0
- package/dist/src/owner.js +185 -0
- package/dist/src/owner.js.map +1 -0
- package/dist/src/platform.d.ts +5 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +11 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/render.d.ts +18 -0
- package/dist/src/render.d.ts.map +1 -0
- package/dist/src/render.js +32 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/testing-core.d.ts +147 -0
- package/dist/src/testing-core.d.ts.map +1 -0
- package/dist/src/testing-core.js +110 -0
- package/dist/src/testing-core.js.map +1 -0
- package/dist/src/testing.d.ts +38 -0
- package/dist/src/testing.d.ts.map +1 -0
- package/dist/src/testing.js +74 -0
- package/dist/src/testing.js.map +1 -0
- package/dist/src/vendor-excludes.d.ts +6 -0
- package/dist/src/vendor-excludes.d.ts.map +1 -0
- package/dist/src/vendor-excludes.js +38 -0
- package/dist/src/vendor-excludes.js.map +1 -0
- package/dist/src/vite.d.ts +10 -0
- package/dist/src/vite.d.ts.map +1 -0
- package/dist/src/vite.js +14 -0
- package/dist/src/vite.js.map +1 -0
- package/dist/src/vitest.d.ts +5 -0
- package/dist/src/vitest.d.ts.map +1 -0
- package/dist/src/vitest.js +23 -0
- package/dist/src/vitest.js.map +1 -0
- package/dist/types/glint.d.ts +164 -0
- package/dist/vendor/runtime--fcdnjmJ.js +43 -0
- package/dist/vendor/runtime--fcdnjmJ.js.map +1 -0
- package/package.json +105 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Frame, View } from '@nativescript/core';
|
|
2
|
+
import type { FrameHost } from './navigator.js';
|
|
3
|
+
/** Shows pages in a NativeScript Frame and modals over its current page. */
|
|
4
|
+
export declare class FrameNavigationHost implements FrameHost<View> {
|
|
5
|
+
readonly frame: Frame;
|
|
6
|
+
constructor(frame: Frame);
|
|
7
|
+
show(page: View, options: Parameters<FrameHost['show']>[1]): void;
|
|
8
|
+
back(): void;
|
|
9
|
+
showModal(view: View, options: Parameters<FrameHost['showModal']>[1]): void;
|
|
10
|
+
closeModal(view: View, result: unknown): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=frame-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-host.d.ts","sourceRoot":"","sources":["../../src/frame-host.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAA8B,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,4EAA4E;AAC5E,qBAAa,mBAAoB,YAAW,SAAS,CAAC,IAAI,CAAC;IAC7C,QAAQ,CAAC,KAAK,EAAE,KAAK;gBAAZ,KAAK,EAAE,KAAK;IAEjC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAUjE,IAAI,IAAI,IAAI;IAIZ,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAW3E,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;CAG9C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/frame-host.ts
|
|
2
|
+
/** Shows pages in a NativeScript Frame and modals over its current page. */
|
|
3
|
+
var FrameNavigationHost = class {
|
|
4
|
+
constructor(frame) {
|
|
5
|
+
this.frame = frame;
|
|
6
|
+
}
|
|
7
|
+
show(page, options) {
|
|
8
|
+
this.frame.navigate({
|
|
9
|
+
create: () => page,
|
|
10
|
+
animated: options.animated,
|
|
11
|
+
transition: options.transition,
|
|
12
|
+
clearHistory: options.clearHistory,
|
|
13
|
+
backstackVisible: options.backstackVisible
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
back() {
|
|
17
|
+
this.frame.goBack();
|
|
18
|
+
}
|
|
19
|
+
showModal(view, options) {
|
|
20
|
+
(this.frame.currentPage ?? this.frame).showModal(view, {
|
|
21
|
+
context: null,
|
|
22
|
+
closeCallback: (result) => options.onClose(result),
|
|
23
|
+
fullscreen: options.fullscreen,
|
|
24
|
+
animated: options.animated,
|
|
25
|
+
stretched: options.stretched
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
closeModal(view, result) {
|
|
29
|
+
view.closeModal(result);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export { FrameNavigationHost };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=frame-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-host.js","names":["FrameNavigationHost","constructor","frame","show","page","options","navigate","create","animated","transition","clearHistory","backstackVisible","back","goBack","showModal","view","parent","currentPage","context","closeCallback","result","onClose","fullscreen","stretched","closeModal"],"sources":["../../src/frame-host.ts"],"sourcesContent":["// Shows screens in a NativeScript Frame, and modals over its current page.\nimport type { Frame, NavigationTransition, Page, View } from '@nativescript/core';\n\nimport type { FrameHost } from './navigator.ts';\n\n/** Shows pages in a NativeScript Frame and modals over its current page. */\nexport class FrameNavigationHost implements FrameHost<View> {\n constructor(readonly frame: Frame) {}\n\n show(page: View, options: Parameters<FrameHost['show']>[1]): void {\n this.frame.navigate({\n create: () => page,\n animated: options.animated,\n transition: options.transition as NavigationTransition | undefined,\n clearHistory: options.clearHistory,\n backstackVisible: options.backstackVisible,\n });\n }\n\n back(): void {\n this.frame.goBack();\n }\n\n showModal(view: View, options: Parameters<FrameHost['showModal']>[1]): void {\n const parent: Page | View = this.frame.currentPage ?? this.frame;\n parent.showModal(view, {\n context: null,\n closeCallback: (result?: unknown) => options.onClose(result),\n fullscreen: options.fullscreen,\n animated: options.animated,\n stretched: options.stretched,\n });\n }\n\n closeModal(view: View, result: unknown): void {\n view.closeModal(result);\n }\n}\n"],"mappings":";;AAMA,IAAaA,sBAAb,MAA4D;CAC1DC,YAAqBC,OAAc;EAAA,KAAdA,QAAAA;CAAe;CAEpCC,KAAKC,MAAYC,SAAiD;EAChE,KAAKH,MAAMI,SAAS;GAClBC,cAAcH;GACdI,UAAUH,QAAQG;GAClBC,YAAYJ,QAAQI;GACpBC,cAAcL,QAAQK;GACtBC,kBAAkBN,QAAQM;EAC5B,CAAC;CACH;CAEAC,OAAa;EACX,KAAKV,MAAMW,OAAO;CACpB;CAEAC,UAAUC,MAAYV,SAAsD;EAE1EW,CAD4B,KAAKd,MAAMe,eAAe,KAAKf,MAAAA,CACpDY,UAAUC,MAAM;GACrBG,SAAS;GACTC,gBAAgBC,WAAqBf,QAAQgB,QAAQD,MAAM;GAC3DE,YAAYjB,QAAQiB;GACpBd,UAAUH,QAAQG;GAClBe,WAAWlB,QAAQkB;EACrB,CAAC;CACH;CAEAC,WAAWT,MAAYK,QAAuB;EAC5CL,KAAKS,WAAWJ,MAAM;CACxB;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.js';
|
|
2
|
+
export { NativeDocument, NativeElement } from './dom.js';
|
|
3
|
+
export { defineElement, type ElementDefinition, type Slot } from './elements.js';
|
|
4
|
+
export { bindListRows, type ListRows } from './list.js';
|
|
5
|
+
export { modifier } from './modifier.js';
|
|
6
|
+
export { type FrameHost, type ModalOptions, type NavigateOptions, Navigator, type ShowOptions } from './navigator.js';
|
|
7
|
+
export { createNativeApp, FrameNavigationHost, type NativeApp, type NativeAppOptions } from './nativescript-app.js';
|
|
8
|
+
export { NativeScriptAdapter, registerElement } from './nativescript-adapter.js';
|
|
9
|
+
export { createOwner, type CreateOwnerOptions, type NativeOwner, type ServiceEntry } from './owner.js';
|
|
10
|
+
export { isAndroid, isIOS, platform } from './platform.js';
|
|
11
|
+
export { createDocument, type NativeRoot, renderNative } from './render.js';
|
|
12
|
+
export { bind } from './bind.js';
|
|
13
|
+
export { nativeView } from './native-view.js';
|
|
14
|
+
export { default as NativeFrame } from '../components/NativeFrame.js';
|
|
15
|
+
export { default as NativeList } from '../components/NativeList.js';
|
|
16
|
+
export { Android, IOS } from '../components/Platform.js';
|
|
17
|
+
export type { NativeAttributes, NativeElementFor, NativeElementTagNameMap, NativeEvent } from '../types/glint.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,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,MAAM,4BAA4B,CAAC;AAC1D,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NativeDocument, NativeElement } from "./dom.js";
|
|
2
|
+
import { defineElement } from "./elements.js";
|
|
3
|
+
import { bindListRows } from "./list.js";
|
|
4
|
+
import { modifier } from "./modifier.js";
|
|
5
|
+
import { Navigator } from "./navigator.js";
|
|
6
|
+
import { createNativeApp } from "./nativescript-app.js";
|
|
7
|
+
import { NativeScriptAdapter, registerElement } from "./nativescript-adapter.js";
|
|
8
|
+
import { createOwner } from "./owner.js";
|
|
9
|
+
import { isAndroid, isIOS, platform } from "./platform.js";
|
|
10
|
+
import { FrameNavigationHost } from "./frame-host.js";
|
|
11
|
+
import { createDocument, renderNative } from "./render.js";
|
|
12
|
+
import { bind } from "./bind.js";
|
|
13
|
+
import { nativeView } from "./native-view.js";
|
|
14
|
+
import NativeFrame from "../components/NativeFrame.js";
|
|
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 };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NativeElement } from './dom.js';
|
|
2
|
+
export interface ListRows {
|
|
3
|
+
/** The items to show. The list re-asks for the cells it shows. */
|
|
4
|
+
update(items: readonly unknown[]): void;
|
|
5
|
+
/** The item at an index, for events that report one (itemTap). */
|
|
6
|
+
itemAt(index: number): unknown;
|
|
7
|
+
/** Destroys every cell's render and stops listening to the list. */
|
|
8
|
+
destroy(): void;
|
|
9
|
+
/** How many cells were rendered, which stays at about a screenful however long the list is. */
|
|
10
|
+
readonly cellCount: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ListRowOptions {
|
|
13
|
+
owner: object;
|
|
14
|
+
/** The component for every row. */
|
|
15
|
+
row?: object;
|
|
16
|
+
/** Components by kind of row, with `kindOf` to pick one per item: a header and its contacts. */
|
|
17
|
+
rows?: Record<string, object>;
|
|
18
|
+
kindOf?: (item: unknown, index: number) => string;
|
|
19
|
+
}
|
|
20
|
+
export declare function bindListRows(element: NativeElement, options: ListRowOptions): ListRows;
|
|
21
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/list.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAe9C,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,MAAM,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,CAAC;IACxC,kEAAkE;IAClE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,oEAAoE;IACpE,OAAO,IAAI,IAAI,CAAC;IAChB,+FAA+F;IAC/F,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACnD;AAID,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CA+EtF"}
|
package/dist/src/list.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { renderComponent } from "@ember/renderer";
|
|
2
|
+
import { run } from "@ember/runloop";
|
|
3
|
+
import { tracked } from "@glimmer/tracking";
|
|
4
|
+
import { b as decorateFieldV2, i as initializeDeferredDecorator } from "../vendor/runtime--fcdnjmJ.js";
|
|
5
|
+
// src/list.ts
|
|
6
|
+
var Row = class {
|
|
7
|
+
static {
|
|
8
|
+
decorateFieldV2(this.prototype, "item", [tracked]);
|
|
9
|
+
}
|
|
10
|
+
#item = (initializeDeferredDecorator(this, "item"), void 0);
|
|
11
|
+
static {
|
|
12
|
+
decorateFieldV2(this.prototype, "index", [tracked], function() {
|
|
13
|
+
return 0;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
#index = (initializeDeferredDecorator(this, "index"), void 0);
|
|
17
|
+
};
|
|
18
|
+
var ONE_KIND = "row";
|
|
19
|
+
function bindListRows(element, options) {
|
|
20
|
+
const document = element.ownerDocument;
|
|
21
|
+
const cells = /* @__PURE__ */ new Map();
|
|
22
|
+
const { owner, kindOf } = options;
|
|
23
|
+
const components = options.rows ?? (options.row ? { [ONE_KIND]: options.row } : {});
|
|
24
|
+
const kinds = Object.keys(components);
|
|
25
|
+
let items = [];
|
|
26
|
+
if (kinds.length === 0) throw new Error("[ember-nativescript] A list needs @row, or @rows and @rowKind.");
|
|
27
|
+
if (options.rows && !kindOf) throw new Error("[ember-nativescript] A list with @rows needs @rowKind to pick one per item.");
|
|
28
|
+
const kindAt = (index) => kindOf ? kindOf(items[index], index) : ONE_KIND;
|
|
29
|
+
const render = (container, index, kind) => {
|
|
30
|
+
const component = components[kind];
|
|
31
|
+
if (!component) throw new Error(`[ember-nativescript] @rowKind returned '${kind}', which isn't one of @rows.`);
|
|
32
|
+
const state = new Row();
|
|
33
|
+
state.item = items[index];
|
|
34
|
+
state.index = index;
|
|
35
|
+
const result = renderComponent(component, {
|
|
36
|
+
into: document.adopt(container),
|
|
37
|
+
owner,
|
|
38
|
+
args: {
|
|
39
|
+
get item() {
|
|
40
|
+
return state.item;
|
|
41
|
+
},
|
|
42
|
+
get index() {
|
|
43
|
+
return state.index;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
env: {
|
|
47
|
+
document,
|
|
48
|
+
isInteractive: true,
|
|
49
|
+
hasDOM: true
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
cells.set(container, {
|
|
53
|
+
kind,
|
|
54
|
+
row: state,
|
|
55
|
+
result
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const showRow = (container, index) => {
|
|
59
|
+
run(() => {
|
|
60
|
+
const kind = kindAt(index);
|
|
61
|
+
const cell = cells.get(container);
|
|
62
|
+
if (cell?.kind === kind) {
|
|
63
|
+
cell.row.item = items[index];
|
|
64
|
+
cell.row.index = index;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (cell) cell.result.destroy();
|
|
68
|
+
render(container, index, kind);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const binding = element.view ? document.adapter.bindList?.(element.view, showRow, kindOf ? {
|
|
72
|
+
kinds,
|
|
73
|
+
kindOf: kindAt
|
|
74
|
+
} : {}) : null;
|
|
75
|
+
if (!binding) throw new Error(`[ember-nativescript] <${element.localName}> isn't a list view, so it can't show rows.`);
|
|
76
|
+
return {
|
|
77
|
+
update(next) {
|
|
78
|
+
items = next;
|
|
79
|
+
binding.setCount(next.length);
|
|
80
|
+
},
|
|
81
|
+
itemAt(index) {
|
|
82
|
+
return items[index];
|
|
83
|
+
},
|
|
84
|
+
destroy() {
|
|
85
|
+
binding.release();
|
|
86
|
+
for (const cell of cells.values()) cell.result.destroy();
|
|
87
|
+
cells.clear();
|
|
88
|
+
},
|
|
89
|
+
get cellCount() {
|
|
90
|
+
return cells.size;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export { bindListRows };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","names":["renderComponent","run","tracked","g","i","Row","prototype","item","index","ONE_KIND","bindListRows","element","options","document","ownerDocument","cells","Map","owner","kindOf","components","rows","row","kinds","Object","keys","items","length","Error","kindAt","render","container","kind","component","state","result","into","adopt","args","env","isInteractive","hasDOM","set","showRow","cell","get","destroy","binding","view","adapter","bindList","localName","update","next","setCount","itemAt","release","values","clear","cellCount","size"],"sources":["../../src/list.ts"],"sourcesContent":["// Lists that recycle their cells (NativeScript's ListView), rendered with Ember.\n//\n// A ListView keeps only the cells on screen, and hands a cell that scrolled away back to show another row. Glimmer's\n// {{#each}} can't drive that: it owns every row it renders. So each cell is a render root of its own: the row\n// component is rendered once into a cell's container, with `@item` and `@index` read from tracked state, and when the\n// list recycles that container only that state changes. Glimmer then updates the cell in place, inside a run loop so\n// it's done before the list measures the cell.\n\nimport { renderComponent } from '@ember/renderer';\nimport { run } from '@ember/runloop';\nimport { tracked } from '@glimmer/tracking';\n\nimport type { NativeElement } from './dom.ts';\n\nclass Row {\n @tracked item: unknown;\n @tracked index = 0;\n}\n\ntype RenderResult = ReturnType<typeof renderComponent>;\n\ninterface Cell {\n kind: string;\n row: Row;\n result: RenderResult;\n}\n\nexport interface ListRows {\n /** The items to show. The list re-asks for the cells it shows. */\n update(items: readonly unknown[]): void;\n /** The item at an index, for events that report one (itemTap). */\n itemAt(index: number): unknown;\n /** Destroys every cell's render and stops listening to the list. */\n destroy(): void;\n /** How many cells were rendered, which stays at about a screenful however long the list is. */\n readonly cellCount: number;\n}\n\nexport interface ListRowOptions {\n owner: object;\n /** The component for every row. */\n row?: object;\n /** Components by kind of row, with `kindOf` to pick one per item: a header and its contacts. */\n rows?: Record<string, object>;\n kindOf?: (item: unknown, index: number) => string;\n}\n\nconst ONE_KIND = 'row';\n\nexport function bindListRows(element: NativeElement, options: ListRowOptions): ListRows {\n const document = element.ownerDocument;\n const cells = new Map<unknown, Cell>();\n const { owner, kindOf } = options;\n const components: Record<string, object> = options.rows ?? (options.row ? { [ONE_KIND]: options.row } : {});\n const kinds = Object.keys(components);\n let items: readonly unknown[] = [];\n\n if (kinds.length === 0) throw new Error('[ember-nativescript] A list needs @row, or @rows and @rowKind.');\n if (options.rows && !kindOf)\n throw new Error('[ember-nativescript] A list with @rows needs @rowKind to pick one per item.');\n\n const kindAt = (index: number): string => (kindOf ? kindOf(items[index], index) : ONE_KIND);\n\n const render = (container: unknown, index: number, kind: string): void => {\n const component = components[kind];\n if (!component) throw new Error(`[ember-nativescript] @rowKind returned '${kind}', which isn't one of @rows.`);\n const state = new Row();\n state.item = items[index];\n state.index = index;\n const result = renderComponent(component, {\n into: document.adopt(container) as unknown as Element,\n owner,\n // Getters, so the row reads the state each time and updates when it changes.\n args: {\n get item() {\n return state.item;\n },\n get index() {\n return state.index;\n },\n },\n env: { document: document as unknown as Document, isInteractive: true, hasDOM: true } as never,\n });\n cells.set(container, { kind, row: state, result });\n };\n\n const showRow = (container: unknown, index: number): void => {\n run(() => {\n const kind = kindAt(index);\n const cell = cells.get(container);\n\n if (cell?.kind === kind) {\n cell.row.item = items[index];\n cell.row.index = index;\n return;\n }\n\n // The list keeps cells by kind, so this only happens if a platform hands over a cell of another kind.\n if (cell) cell.result.destroy();\n render(container, index, kind);\n });\n };\n\n const binding = element.view\n ? document.adapter.bindList?.(element.view, showRow, kindOf ? { kinds, kindOf: kindAt } : {})\n : null;\n\n if (!binding) {\n throw new Error(`[ember-nativescript] <${element.localName}> isn't a list view, so it can't show rows.`);\n }\n\n return {\n update(next) {\n items = next;\n binding.setCount(next.length);\n },\n itemAt(index) {\n return items[index];\n },\n destroy() {\n binding.release();\n for (const cell of cells.values()) cell.result.destroy();\n cells.clear();\n },\n get cellCount() {\n return cells.size;\n },\n };\n}\n"],"mappings":";;;;;AAcA,IAAMK,MAAN,MAAU;CAAA;EAAAF,gBAAA,KAAAG,WAAA,QAAA,CACPJ,OAAO,CAAA;CAAA;CAAA,SAAAE,4BAAA,MAAA,MAAA,GAAA,KAAA;CAAA;EAAAD,gBAAA,KAAAG,WAAA,SAAA,CACPJ,OAAO,GAAA,WAAA;GAAA,OAAS;EAAC,CAAA;CAAA;CAAA,UAAAE,4BAAA,MAAA,OAAA,GAAA,KAAA;AACpB;AA8BA,IAAMK,WAAW;AAEjB,SAAgBC,aAAaC,SAAwBC,SAAmC;CACtF,MAAMC,WAAWF,QAAQG;CACzB,MAAMC,wBAAQ,IAAIC,IAAmB;CACrC,MAAM,EAAEC,OAAOC,WAAWN;CAC1B,MAAMO,aAAqCP,QAAQQ,SAASR,QAAQS,MAAM,GAAGZ,WAAWG,QAAQS,IAAI,IAAI,CAAC;CACzG,MAAMC,QAAQC,O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,QAAQoC,MAAML,SAASxB,SAAS;EAAEI;EAAOJ,QAAQU;CAAO,IAAI,CAAC,CAAC,IAC1F;CAEJ,IAAI,CAACkB,SACH,MAAM,IAAInB,MAAM,yBAAyBhB,QAAQuC,UAAS,4CAA6C;CAGzG,OAAO;EACLC,OAAOC,MAAM;GACX3B,QAAQ2B;GACRN,QAAQO,SAASD,KAAK1B,MAAM;EAC9B;EACA4B,OAAO9C,OAAO;GACZ,OAAOiB,MAAMjB;EACf;EACAqC,UAAU;GACRC,QAAQS,QAAQ;GAChB,KAAK,MAAMZ,QAAQ5B,MAAMyC,OAAO,GAAGb,KAAKT,OAAOW,QAAQ;GACvD9B,MAAM0C,MAAM;EACd;EACA,IAAIC,YAAY;GACd,OAAO3C,MAAM4C;EACf;CACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModifierLike } from '@glint/template';
|
|
2
|
+
type Cleanup = void | (() => void);
|
|
3
|
+
export declare function modifier<Positional extends unknown[], Named extends object = Record<string, never>>(run: (element: Element, positional: Positional, named: Named) => Cleanup): ModifierLike<{
|
|
4
|
+
Element: Element;
|
|
5
|
+
Args: {
|
|
6
|
+
Positional: Positional;
|
|
7
|
+
Named: Named;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=modifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifier.d.ts","sourceRoot":"","sources":["../../src/modifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,KAAK,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAYnC,wBAAgB,QAAQ,CAAC,UAAU,SAAS,OAAO,EAAE,EAAE,KAAK,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACjG,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,GACvE,YAAY,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAA;CAAE,CAAC,CAsBpF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { capabilities, setModifierManager } from "@ember/modifier";
|
|
2
|
+
// src/modifier.ts
|
|
3
|
+
function modifier(run) {
|
|
4
|
+
const call = (state, args) => {
|
|
5
|
+
state.cleanup?.();
|
|
6
|
+
state.cleanup = run(state.element, args.positional, { ...args.named });
|
|
7
|
+
};
|
|
8
|
+
return setModifierManager(() => ({
|
|
9
|
+
capabilities: capabilities("3.22"),
|
|
10
|
+
createModifier: () => ({
|
|
11
|
+
element: null,
|
|
12
|
+
cleanup: void 0
|
|
13
|
+
}),
|
|
14
|
+
installModifier(state, element, args) {
|
|
15
|
+
state.element = element;
|
|
16
|
+
call(state, args);
|
|
17
|
+
},
|
|
18
|
+
updateModifier: call,
|
|
19
|
+
destroyModifier(state) {
|
|
20
|
+
state.cleanup?.();
|
|
21
|
+
state.cleanup = void 0;
|
|
22
|
+
}
|
|
23
|
+
}), {});
|
|
24
|
+
}
|
|
25
|
+
export { modifier };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=modifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifier.js","names":["capabilities","setModifierManager","modifier","run","call","state","args","cleanup","element","positional","named","createModifier","undefined","installModifier","updateModifier","destroyModifier"],"sources":["../../src/modifier.ts"],"sourcesContent":["// A modifier from a function, through Ember's public modifier manager API, without depending on ember-modifier.\n// The function runs when the element is inserted and again whenever tracked state it read changes. If it returns a\n// function, that runs before the next run and when the element is destroyed.\nimport { capabilities, setModifierManager } from '@ember/modifier';\nimport type { ModifierLike } from '@glint/template';\n\ntype Cleanup = void | (() => void);\n\ninterface State {\n element: Element | null;\n cleanup: Cleanup;\n}\n\ninterface Args {\n positional: unknown[];\n named: Record<string, unknown>;\n}\n\nexport function modifier<Positional extends unknown[], Named extends object = Record<string, never>>(\n run: (element: Element, positional: Positional, named: Named) => Cleanup,\n): ModifierLike<{ Element: Element; Args: { Positional: Positional; Named: Named } }> {\n const call = (state: State, args: Args): void => {\n state.cleanup?.();\n state.cleanup = run(state.element!, args.positional as Positional, { ...args.named } as Named);\n };\n\n return setModifierManager(\n () => ({\n capabilities: capabilities('3.22'),\n createModifier: (): State => ({ element: null, cleanup: undefined }),\n installModifier(state: State, element: Element, args: Args) {\n state.element = element;\n call(state, args);\n },\n updateModifier: call,\n destroyModifier(state: State) {\n state.cleanup?.();\n state.cleanup = undefined;\n },\n }),\n {},\n ) as never;\n}\n"],"mappings":";;AAkBA,SAAgBE,SACdC,KACoF;CACpF,MAAMC,QAAQC,OAAcC,SAAqB;EAC/CD,MAAME,UAAU;EAChBF,MAAME,UAAUJ,IAAIE,MAAMG,SAAUF,KAAKG,YAA0B,EAAE,GAAGH,KAAKI,MAAM,CAAU;CAC/F;CAEA,OAAOT,0BACE;EACLD,cAAcA,aAAa,MAAM;EACjCW,uBAA8B;GAAEH,SAAS;GAAMD,SAASK,KAAAA;EAAU;EAClEC,gBAAgBR,OAAcG,SAAkBF,MAAY;GAC1DD,MAAMG,UAAUA;GAChBJ,KAAKC,OAAOC,IAAI;EAClB;EACAQ,gBAAgBV;EAChBW,gBAAgBV,OAAc;GAC5BA,MAAME,UAAU;GAChBF,MAAME,UAAUK,KAAAA;EAClB;CACF,IACA,CAAC,CACH;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModifierLike } from '@glint/template';
|
|
2
|
+
import type { View as NSView } from '@nativescript/core';
|
|
3
|
+
export declare const nativeView: abstract new <El extends Element = Element>() => InstanceType<ModifierLike<{
|
|
4
|
+
Element: El;
|
|
5
|
+
Args: {
|
|
6
|
+
Positional: [callback: (view: El extends {
|
|
7
|
+
view: infer View;
|
|
8
|
+
} ? View : NSView) => void | (() => void)];
|
|
9
|
+
};
|
|
10
|
+
}>>;
|
|
11
|
+
//# sourceMappingURL=native-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
11
|
+
var nativeView = modifier((element, [callback]) => {
|
|
12
|
+
const view = element.view;
|
|
13
|
+
if (view === void 0) return void 0;
|
|
14
|
+
if (view.isLoaded !== false) return run(callback, view);
|
|
15
|
+
let cleanup;
|
|
16
|
+
const loaded = () => {
|
|
17
|
+
element.removeEventListener("loaded", loaded);
|
|
18
|
+
cleanup = run(callback, view);
|
|
19
|
+
};
|
|
20
|
+
element.addEventListener("loaded", loaded);
|
|
21
|
+
return () => {
|
|
22
|
+
element.removeEventListener("loaded", loaded);
|
|
23
|
+
cleanup?.();
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
export { nativeView };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=native-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ViewBase } from '@nativescript/core';
|
|
2
|
+
import type { ListBinding, Listener, ListOptions, NativeAdapter } from './adapter.js';
|
|
3
|
+
import { type ElementDefinition } from './elements.js';
|
|
4
|
+
/**
|
|
5
|
+
* Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:
|
|
6
|
+
* { property: 'items', list: true } })`. The definition says which children go into properties rather than being
|
|
7
|
+
* child views (see elements.ts); leave it out for a view that lays out its children or has none.
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerElement(tag: string, create: () => ViewBase, definition?: ElementDefinition): void;
|
|
10
|
+
export declare class NativeScriptAdapter implements NativeAdapter<ViewBase> {
|
|
11
|
+
#private;
|
|
12
|
+
readonly platform: "ios" | "android";
|
|
13
|
+
createView(tag: string): ViewBase | null;
|
|
14
|
+
setProperty(view: ViewBase, name: string, value: unknown): void;
|
|
15
|
+
hasProperty(view: ViewBase, name: string): boolean;
|
|
16
|
+
takesText(view: ViewBase): boolean;
|
|
17
|
+
insertChild(parent: ViewBase, child: ViewBase, index: number): void;
|
|
18
|
+
removeChild(parent: ViewBase, child: ViewBase): void;
|
|
19
|
+
setSlot(parent: ViewBase, property: string, child: ViewBase | null): void;
|
|
20
|
+
insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void;
|
|
21
|
+
removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void;
|
|
22
|
+
on(view: ViewBase, event: string, listener: Listener): void;
|
|
23
|
+
off(view: ViewBase, event: string, listener: Listener): void;
|
|
24
|
+
bindList(view: ViewBase, cell: (container: ViewBase, index: number) => void, options?: ListOptions): ListBinding | null;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=nativescript-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativescript-adapter.d.ts","sourceRoot":"","sources":["../../src/nativescript-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAyCL,KAAK,QAAQ,EAGd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA8CtE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,EAAE,UAAU,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAGzG;AA2BD,qBAAa,mBAAoB,YAAW,aAAa,CAAC,QAAQ,CA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,0 +1,172 @@
|
|
|
1
|
+
import { AbsoluteLayout, ActionBar, ActionItem, ActivityIndicator, Button, ContentView, DatePicker, DockLayout, FlexboxLayout, FormattedString, Frame, GridLayout, HtmlView, Image, 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, isIOS } from "@nativescript/core";
|
|
2
|
+
import { defineElement } from "./elements.js";
|
|
3
|
+
// src/nativescript-adapter.ts
|
|
4
|
+
var VIEWS = new Map(Object.entries({
|
|
5
|
+
absoluteLayout: () => new AbsoluteLayout(),
|
|
6
|
+
actionBar: () => new ActionBar(),
|
|
7
|
+
actionItem: () => new ActionItem(),
|
|
8
|
+
activityIndicator: () => new ActivityIndicator(),
|
|
9
|
+
button: () => new Button(),
|
|
10
|
+
contentView: () => new ContentView(),
|
|
11
|
+
datePicker: () => new DatePicker(),
|
|
12
|
+
dockLayout: () => new DockLayout(),
|
|
13
|
+
flexboxLayout: () => new FlexboxLayout(),
|
|
14
|
+
formattedString: () => new FormattedString(),
|
|
15
|
+
frame: () => new Frame(),
|
|
16
|
+
gridLayout: () => new GridLayout(),
|
|
17
|
+
htmlView: () => new HtmlView(),
|
|
18
|
+
image: () => new Image(),
|
|
19
|
+
label: () => new Label(),
|
|
20
|
+
listPicker: () => new ListPicker(),
|
|
21
|
+
listView: () => new ListView(),
|
|
22
|
+
navigationButton: () => new NavigationButton(),
|
|
23
|
+
page: () => new Page(),
|
|
24
|
+
placeholder: () => new Placeholder(),
|
|
25
|
+
progress: () => new Progress(),
|
|
26
|
+
rootLayout: () => new RootLayout(),
|
|
27
|
+
scrollView: () => new ScrollView(),
|
|
28
|
+
searchBar: () => new SearchBar(),
|
|
29
|
+
segmentedBar: () => new SegmentedBar(),
|
|
30
|
+
segmentedBarItem: () => new SegmentedBarItem(),
|
|
31
|
+
slider: () => new Slider(),
|
|
32
|
+
span: () => new Span(),
|
|
33
|
+
stackLayout: () => new StackLayout(),
|
|
34
|
+
switch: () => new Switch(),
|
|
35
|
+
tabView: () => new TabView(),
|
|
36
|
+
tabViewItem: () => new TabViewItem(),
|
|
37
|
+
textField: () => new TextField(),
|
|
38
|
+
textView: () => new TextView(),
|
|
39
|
+
timePicker: () => new TimePicker(),
|
|
40
|
+
webView: () => new WebView(),
|
|
41
|
+
wrapLayout: () => new WrapLayout()
|
|
42
|
+
}));
|
|
43
|
+
/**
|
|
44
|
+
* Makes a tag available in templates, for a plugin's view: `registerElement('pager', () => new Pager(), { childSlot:
|
|
45
|
+
* { property: 'items', list: true } })`. The definition says which children go into properties rather than being
|
|
46
|
+
* child views (see elements.ts); leave it out for a view that lays out its children or has none.
|
|
47
|
+
*/
|
|
48
|
+
function registerElement(tag, create, definition) {
|
|
49
|
+
VIEWS.set(tag, create);
|
|
50
|
+
if (definition) defineElement(tag, definition);
|
|
51
|
+
}
|
|
52
|
+
var takesText = (view) => view instanceof Label || view instanceof Button || view instanceof TextField || view instanceof TextView || view instanceof Span;
|
|
53
|
+
var ATTACHED = {
|
|
54
|
+
row: (view, value) => GridLayout.setRow(view, Number(value)),
|
|
55
|
+
col: (view, value) => GridLayout.setColumn(view, Number(value)),
|
|
56
|
+
rowSpan: (view, value) => GridLayout.setRowSpan(view, Number(value)),
|
|
57
|
+
colSpan: (view, value) => GridLayout.setColumnSpan(view, Number(value)),
|
|
58
|
+
dock: (view, value) => DockLayout.setDock(view, value),
|
|
59
|
+
left: (view, value) => AbsoluteLayout.setLeft(view, Number(value)),
|
|
60
|
+
top: (view, value) => AbsoluteLayout.setTop(view, Number(value)),
|
|
61
|
+
order: (view, value) => FlexboxLayout.setOrder(view, Number(value)),
|
|
62
|
+
flexGrow: (view, value) => FlexboxLayout.setFlexGrow(view, Number(value)),
|
|
63
|
+
flexShrink: (view, value) => FlexboxLayout.setFlexShrink(view, Number(value))
|
|
64
|
+
};
|
|
65
|
+
var NativeScriptAdapter = class {
|
|
66
|
+
platform = isIOS ? "ios" : "android";
|
|
67
|
+
createView(tag) {
|
|
68
|
+
return VIEWS.get(tag)?.() ?? null;
|
|
69
|
+
}
|
|
70
|
+
setProperty(view, name, value) {
|
|
71
|
+
if (name === "class") view.className = value === null ? "" : String(value);
|
|
72
|
+
else if (name === "style") view.style = value ?? "";
|
|
73
|
+
else if (ATTACHED[name]) {
|
|
74
|
+
if (value !== null) ATTACHED[name](view, String(value));
|
|
75
|
+
} else if (name.includes(".")) {
|
|
76
|
+
const path = name.split(".");
|
|
77
|
+
const last = path.pop();
|
|
78
|
+
let target = view;
|
|
79
|
+
for (const key of path) target = target[key] ??= {};
|
|
80
|
+
target[last] = value === null ? void 0 : value;
|
|
81
|
+
} else view[name] = value === null ? void 0 : value;
|
|
82
|
+
}
|
|
83
|
+
hasProperty(view, name) {
|
|
84
|
+
return name.replace(/^(ios|android):/, "") in view;
|
|
85
|
+
}
|
|
86
|
+
takesText(view) {
|
|
87
|
+
return takesText(view);
|
|
88
|
+
}
|
|
89
|
+
insertChild(parent, child, index) {
|
|
90
|
+
if (parent instanceof LayoutBase) parent.insertChild(child, index);
|
|
91
|
+
else if (parent instanceof ContentView || parent instanceof Page || parent instanceof ScrollView) parent.content = child;
|
|
92
|
+
else throw new Error(`[ember-nativescript] <${parent.typeName}> can't hold views.`);
|
|
93
|
+
}
|
|
94
|
+
removeChild(parent, child) {
|
|
95
|
+
if (parent instanceof LayoutBase) parent.removeChild(child);
|
|
96
|
+
else if (parent.content === child) parent.content = null;
|
|
97
|
+
}
|
|
98
|
+
setSlot(parent, property, child) {
|
|
99
|
+
if (!child && parent instanceof Page && property === "actionBar") {
|
|
100
|
+
parent.actionBar = new ActionBar();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const bag = parent;
|
|
104
|
+
if (child || bag[property]) bag[property] = child ?? null;
|
|
105
|
+
}
|
|
106
|
+
insertInSlot(parent, property, child, index) {
|
|
107
|
+
this.#updateList(parent, property, (items) => items.splice(index, 0, child));
|
|
108
|
+
}
|
|
109
|
+
removeFromSlot(parent, property, child) {
|
|
110
|
+
this.#updateList(parent, property, (items) => {
|
|
111
|
+
const index = items.indexOf(child);
|
|
112
|
+
if (index !== -1) items.splice(index, 1);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
#updateList(parent, property, change) {
|
|
116
|
+
if (parent instanceof ActionBar && property === "actionItems") {
|
|
117
|
+
const items = parent.actionItems.getItems();
|
|
118
|
+
const next = [...items];
|
|
119
|
+
change(next);
|
|
120
|
+
for (const item of items) parent.actionItems.removeItem(item);
|
|
121
|
+
for (const item of next) parent.actionItems.addItem(item);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const current = parent[property];
|
|
125
|
+
if (current instanceof ObservableArray) {
|
|
126
|
+
const next = [...current];
|
|
127
|
+
change(next);
|
|
128
|
+
current.splice(0, current.length, ...next);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const next = [...current ?? []];
|
|
132
|
+
change(next);
|
|
133
|
+
parent[property] = next;
|
|
134
|
+
}
|
|
135
|
+
on(view, event, listener) {
|
|
136
|
+
view.on(event, listener);
|
|
137
|
+
}
|
|
138
|
+
off(view, event, listener) {
|
|
139
|
+
view.off(event, listener);
|
|
140
|
+
}
|
|
141
|
+
bindList(view, cell, options = {}) {
|
|
142
|
+
if (!(view instanceof ListView)) return null;
|
|
143
|
+
const onItemLoading = (data) => {
|
|
144
|
+
const args = data;
|
|
145
|
+
cell(args.view, args.index);
|
|
146
|
+
};
|
|
147
|
+
const { kinds, kindOf } = options;
|
|
148
|
+
if (kinds && kindOf) {
|
|
149
|
+
view.itemTemplates = kinds.map((key) => ({
|
|
150
|
+
key,
|
|
151
|
+
createView: () => new StackLayout()
|
|
152
|
+
}));
|
|
153
|
+
view.itemTemplateSelector = (_item, index) => kindOf(index);
|
|
154
|
+
} else view.itemTemplate = () => new StackLayout();
|
|
155
|
+
view.on(ListView.itemLoadingEvent, onItemLoading);
|
|
156
|
+
return {
|
|
157
|
+
setCount(count) {
|
|
158
|
+
view.items = {
|
|
159
|
+
length: count,
|
|
160
|
+
getItem: (index) => index
|
|
161
|
+
};
|
|
162
|
+
view.refresh();
|
|
163
|
+
},
|
|
164
|
+
release() {
|
|
165
|
+
view.off(ListView.itemLoadingEvent, onItemLoading);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
export { NativeScriptAdapter, registerElement };
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=nativescript-adapter.js.map
|
|
@@ -0,0 +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 // A page always has an ActionBar (setting it to null throws): taking ours out puts back a blank one, as a page\n // that never had one shows.\n setSlot(parent: ViewBase, property: string, child: ViewBase | null): void {\n if (!child && parent instanceof Page && property === 'actionBar') {\n parent.actionBar = new ActionBar();\n return;\n }\n const bag = parent as unknown as Bag;\n if (child || bag[property]) bag[property] = child ?? null;\n }\n\n // NativeScript's list properties are set three ways: an ActionBar's actionItems through addItem and removeItem, a\n // FormattedString's spans as an ObservableArray it watches, and a SegmentedBar's or TabView's items by assigning a new\n // array, which its property handler compares with the old one.\n insertInSlot(parent: ViewBase, property: string, child: ViewBase, index: number): void {\n this.#updateList(parent, property, (items) => items.splice(index, 0, child));\n }\n\n removeFromSlot(parent: ViewBase, property: string, child: ViewBase): void {\n this.#updateList(parent, property, (items) => {\n const index = items.indexOf(child);\n if (index !== -1) items.splice(index, 1);\n });\n }\n\n #updateList(parent: ViewBase, property: string, change: (items: ViewBase[]) => void): void {\n if (parent instanceof ActionBar && property === 'actionItems') {\n const items = parent.actionItems.getItems();\n const next = [...items];\n change(next);\n for (const item of items) parent.actionItems.removeItem(item);\n for (const item of next) parent.actionItems.addItem(item as ActionItem);\n return;\n }\n\n const current = (parent as unknown as Bag)[property];\n if (current instanceof ObservableArray) {\n const next = [...current] as ViewBase[];\n change(next);\n current.splice(0, current.length, ...next);\n return;\n }\n\n const next = [...((current as ViewBase[] | undefined) ?? [])];\n change(next);\n (parent as unknown as Bag)[property] = next;\n }\n\n on(view: ViewBase, event: string, listener: Listener): void {\n view.on(event, listener);\n }\n\n off(view: ViewBase, event: string, listener: Listener): void {\n view.off(event, listener);\n }\n\n // Each cell is an empty StackLayout from the item template; ember-native renders the row into it. `items` is only a\n // count (an ItemsSource whose items are their indexes): the rows read their item from Ember's state, not from\n // NativeScript's binding context.\n bindList(\n view: ViewBase,\n cell: (container: ViewBase, index: number) => void,\n options: ListOptions = {},\n ): ListBinding | null {\n if (!(view instanceof ListView)) return null;\n\n const onItemLoading = (data: unknown) => {\n const args = data as ItemEventData;\n cell(args.view, args.index);\n };\n const { kinds, kindOf } = options;\n if (kinds && kindOf) {\n // One template per kind: the list keeps a pool of cells per kind, and reuses a cell only for its kind.\n view.itemTemplates = kinds.map((key) => ({ key, createView: () => new StackLayout() }));\n view.itemTemplateSelector = (_item: unknown, index: number) => kindOf(index);\n } else {\n view.itemTemplate = () => new StackLayout();\n }\n view.on(ListView.itemLoadingEvent, onItemLoading);\n\n return {\n setCount(count) {\n view.items = { length: count, getItem: (index: number) => index };\n view.refresh();\n },\n release() {\n view.off(ListView.itemLoadingEvent, onItemLoading);\n },\n };\n }\n}\n"],"mappings":";;;AA4DA,IAAMyC,QAAQ,IAAIC,IAChBC,OAAOC,QAAQ;CACbC,sBAAsB,IAAI7C,eAAe;CACzC8C,iBAAiB,IAAI7C,UAAU;CAC/B8C,kBAAkB,IAAI7C,WAAW;CACjC8C,yBAAyB,IAAI7C,kBAAkB;CAC/C8C,cAAc,IAAI7C,OAAO;CACzB8C,mBAAmB,IAAI7C,YAAY;CACnC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,kBAAkB,IAAI7C,WAAW;CACjC8C,qBAAqB,IAAI7C,cAAc;CACvC8C,uBAAuB,IAAI7C,gBAAgB;CAC3C8C,aAAa,IAAI7C,MAAM;CACvB8C,kBAAkB,IAAI7C,WAAW;CACjC8C,gBAAgB,IAAI7C,SAAS;CAC7B8C,aAAa,IAAI7C,MAAM;CACvB8C,aAAa,IAAI5C,MAAM;CACvB6C,kBAAkB,IAAI3C,WAAW;CACjC4C,gBAAgB,IAAI3C,SAAS;CAC7B4C,wBAAwB,IAAI3C,iBAAiB;CAC7C4C,YAAY,IAAI1C,KAAK;CACrB2C,mBAAmB,IAAI1C,YAAY;CACnC2C,gBAAgB,IAAI1C,SAAS;CAC7B2C,kBAAkB,IAAI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js';
|
|
2
|
+
import { FrameNavigationHost } from './frame-host.js';
|
|
3
|
+
import { Navigator } from './navigator.js';
|
|
4
|
+
export interface NativeAppOptions {
|
|
5
|
+
/** The first screen. */
|
|
6
|
+
main: object;
|
|
7
|
+
args?: Record<string, unknown>;
|
|
8
|
+
/** Services by name, or a module glob of ./services. */
|
|
9
|
+
services?: Record<string, ServiceEntry>;
|
|
10
|
+
modules?: Modules;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeApp {
|
|
13
|
+
owner: NativeOwner;
|
|
14
|
+
navigator: Navigator;
|
|
15
|
+
}
|
|
16
|
+
export { FrameNavigationHost };
|
|
17
|
+
export declare function createNativeApp(options: NativeAppOptions): NativeApp;
|
|
18
|
+
//# sourceMappingURL=nativescript-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativescript-app.d.ts","sourceRoot":"","sources":["../../src/nativescript-app.ts"],"names":[],"mappings":"AAQA,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAgBpE"}
|