-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
231 lines (206 loc) · 4.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import { AbsoluteLayout, Frame, ListView, ViewBase } from "@nativescript/core";
import {
Document,
Element,
ExtractEventNames,
HTMLElement,
HTMLElementTagNameMap,
ItemTemplate,
NSComponentsMap,
NSComponentsWithTypeOfMap,
DOMEvent,
NSCustomComponentsMap,
} from "dominative";
import {
Component as VueComponent,
ComponentPublicInstance,
DefineComponent,
} from "vue";
export type Filter<
Set,
Needle extends string
> = Set extends `${Needle}${infer _X}` ? never : Set;
export type MapNativeViewEvents<T, C> = {
[K in T as `on${Capitalize<K>}`]: (event: DOMEvent<C>) => void;
};
type NSComponentEventsMap = {
[K in keyof NSComponentsMap]: MapNativeViewEvents<
HTMLElementTagNameMap[K]["eventNames"],
HTMLElementTagNameMap[K]
>;
} & {
[K in keyof NSCustomComponentsMap]: MapNativeViewEvents<
NSCustomComponentsMap[K]["eventNames"],
NSCustomComponentsMap[K]
>;
};
export type IgnoredKeys =
| "cssType"
| "requestLayout"
| "layoutNativeView"
| "goBack"
| "replacePage"
| "firstElementChild"
| "lastElementChild"
| "children"
| "childNodes"
| "append"
| "insertBefore"
| "replaceChild"
| "appendChild"
| "textContent"
| "removeChild"
| "childElementCount"
| "innerHTML"
| "outerHTML"
| "insertBefore"
| "setAttribute"
| "getAttribute"
| "removeAttribute"
| "removeAttributeNS"
| "setAttributeNS"
| "namespaceURI"
| "dispatchEvent"
| "getAttributeNS"
| "localName"
| "nodeName"
| "tagName"
| "attributes"
| "hasChildNodes"
| "firstChild"
| "lastChild"
| "replaceWith"
| "cloneNode"
| "remove"
| "parentNode"
| "height"
| "width"
| "appendData";
export type PickedNSComponentKeys<T> = Omit<
T,
Filter<
keyof T,
| "_"
| "set"
| "get"
| "has"
| "change"
| "each"
| "can"
| "create"
| "send"
| "perform"
| "go"
| "on"
>
>;
type OverrideProperties = {
style: any;
height: string | number;
width: string | number;
};
export type DefineNSComponent<T, E> = DefineComponent<
Partial<
Omit<
T,
| keyof ComponentPublicInstance
| IgnoredKeys
| keyof OverrideProperties
| keyof PickedNSComponentKeys<T>
> &
E
>
>;
declare global {
var document: Document;
}
declare module "@vue/runtime-core" {
type NSDefaultComponents = {
[K in keyof HTMLElementTagNameMap]: DefineNSComponent<
HTMLElementTagNameMap[K],
NSComponentEventsMap[K]
> &
OverrideProperties;
};
export interface GlobalComponents extends NSDefaultComponents {}
}
declare module "dominative" {
interface NSCustomComponentsMap {
"v-list": ExtendWithCustomEventHandlers<
typeof ListView,
ListView & {
itemTemplateSelector: string;
wrapper: VueComponent;
}
>;
"v-template": ItemTemplate & {
prop: string;
};
}
}
declare module "@dominative/vue" {
import { App, Component, ComponentPublicInstance, Plugin } from "vue";
type Data = Record<String, unknown>;
/**
* Creates an application instance.
*
Example:
```js
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
app.$run(document.createElement("ContentView"));
* ```
*/
export function createApp(
rootComponent: Component,
props?: Data
): App<Element> & {
/**
* Renders the application instance.
*/
$render(container?: HTMLElement): ComponentPublicInstance;
/**
* Start the app as main entry
*
* **NOTE:** This method won't return! Codes below this function call
* are not likely to run.
*/
$run(container?: HTMLElement): void;
};
/**
* Registers a plugin to be used across app instances. It is recommended
* to use this method instead of `app.use` so that different screens &
* layouts will share plugins.
*
* Example:
*
* ```js
import {createApp, addGlobalPlugin} from '@dominative/vue';
import App from './App.vue';
import {createPinia} from "pinia";
const pinia = createPinia()
addGlobalPlugin(pinia)
const app = createApp(App);
app.$run();
```
*/
export function addGlobalPlugin(plugin: Plugin, ...options: any[]);
/**
* Creates an app instance from a Vue component and
* returns the NativeScript View.
*/
export function createNativeView<T = HTMLElement<ViewBase>>(
rootComponent: Component,
props?: Data,
container?: element
): T;
export function installNavigation(app: App<Element>);
type NavigationOptions = {
props: any;
frame: Frame;
target: HTMLElement;
};
export function $navigateTo(target: VueComponent, options: NavigationOptions);
export function $navigateBack(options: NavigationOptions);
}