@marko/language-server 2.1.5 → 2.1.6
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/dist/marko.internal.d.ts +583 -0
- package/dist/marko.runtime.d.ts +408 -0
- package/package.json +1 -1
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
// This is a typescript file which defines utilities used in the output of the typescript extractor.
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Marko {
|
|
4
|
+
export interface Directives {}
|
|
5
|
+
|
|
6
|
+
// Extend the Body type to keep track of what is yielded (used for scope hoisted types).
|
|
7
|
+
export interface Body<
|
|
8
|
+
in Params extends readonly any[] = [],
|
|
9
|
+
out Return = void,
|
|
10
|
+
> {
|
|
11
|
+
(...params: Params): MarkoReturn<Return>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Do not use or you will be fired.
|
|
16
|
+
*/
|
|
17
|
+
namespace _ {
|
|
18
|
+
export const voidReturn: MarkoReturn<void>;
|
|
19
|
+
export const scope: unique symbol;
|
|
20
|
+
export const out: Marko.Out;
|
|
21
|
+
export const never: never;
|
|
22
|
+
export const any: any;
|
|
23
|
+
|
|
24
|
+
export function getGlobal<Override>(
|
|
25
|
+
override: Override,
|
|
26
|
+
): [0] extends [1 & Override] ? Marko.Global : Override;
|
|
27
|
+
|
|
28
|
+
export function attrTagNames<Tag>(
|
|
29
|
+
tag: Tag,
|
|
30
|
+
fn: (input: AttrTagNames<Marko.Input<Tag>>) => void,
|
|
31
|
+
): void;
|
|
32
|
+
export function nestedAttrTagNames<Input>(
|
|
33
|
+
input: Input,
|
|
34
|
+
fn: (input: AttrTagNames<Input>) => void,
|
|
35
|
+
): void;
|
|
36
|
+
|
|
37
|
+
export const content: DefaultBodyContentKey;
|
|
38
|
+
|
|
39
|
+
export function contentFor<Name>(
|
|
40
|
+
tag: Name,
|
|
41
|
+
): Name extends { api: infer API }
|
|
42
|
+
? API extends "tags"
|
|
43
|
+
? "content"
|
|
44
|
+
: API extends "class"
|
|
45
|
+
? "renderBody"
|
|
46
|
+
: DefaultBodyContentKey
|
|
47
|
+
: DefaultBodyContentKey;
|
|
48
|
+
|
|
49
|
+
export const Template: new <Overrides = unknown>() => {
|
|
50
|
+
[K in Exclude<
|
|
51
|
+
keyof Marko.Template,
|
|
52
|
+
keyof Overrides
|
|
53
|
+
>]: Marko.Template[K];
|
|
54
|
+
} & Overrides;
|
|
55
|
+
|
|
56
|
+
export function noop(value: any): void;
|
|
57
|
+
|
|
58
|
+
export function tuple<T extends readonly any[]>(...v: T): T;
|
|
59
|
+
|
|
60
|
+
export function interpolated(
|
|
61
|
+
strs: TemplateStringsArray,
|
|
62
|
+
...exprs: (string | number | void | null | false)[]
|
|
63
|
+
): string;
|
|
64
|
+
|
|
65
|
+
export function state<Component>(
|
|
66
|
+
component: Component,
|
|
67
|
+
): Component extends {
|
|
68
|
+
state: infer State extends object;
|
|
69
|
+
}
|
|
70
|
+
? State
|
|
71
|
+
: never;
|
|
72
|
+
|
|
73
|
+
export type ReturnWithScope<Input, Return> = ReturnAndScope<
|
|
74
|
+
Scopes<Input>,
|
|
75
|
+
Return
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
export function instance<Constructor>(
|
|
79
|
+
constructor: Constructor,
|
|
80
|
+
): Constructor extends abstract new (...args: any) => infer Instance
|
|
81
|
+
? Instance
|
|
82
|
+
: never;
|
|
83
|
+
|
|
84
|
+
export function readScopes<Rendered>(rendered: Rendered): MergeScopes<
|
|
85
|
+
{
|
|
86
|
+
[K in keyof Rendered]: Rendered[K] extends infer Value
|
|
87
|
+
? undefined extends Value
|
|
88
|
+
? Value extends { scope: infer Scope }
|
|
89
|
+
? [0] extends [1 & Scope]
|
|
90
|
+
? never
|
|
91
|
+
: Partial<Scope>
|
|
92
|
+
: never
|
|
93
|
+
: Value extends { scope: infer Scope }
|
|
94
|
+
? [0] extends [1 & Scope]
|
|
95
|
+
? never
|
|
96
|
+
: Scope
|
|
97
|
+
: never
|
|
98
|
+
: never;
|
|
99
|
+
}[keyof Rendered]
|
|
100
|
+
> &
|
|
101
|
+
Record<any, never>;
|
|
102
|
+
|
|
103
|
+
export function readScope<Value>(
|
|
104
|
+
value: Value,
|
|
105
|
+
): MergeScopes<
|
|
106
|
+
undefined extends Value
|
|
107
|
+
? Value extends { scope: infer Scope }
|
|
108
|
+
? [0] extends [1 & Scope]
|
|
109
|
+
? never
|
|
110
|
+
: Partial<Scope>
|
|
111
|
+
: never
|
|
112
|
+
: Value extends { scope: infer Scope }
|
|
113
|
+
? [0] extends [1 & Scope]
|
|
114
|
+
? never
|
|
115
|
+
: Scope
|
|
116
|
+
: never
|
|
117
|
+
> &
|
|
118
|
+
Record<any, never>;
|
|
119
|
+
|
|
120
|
+
export function mutable<Lookup>(lookup: Lookup): UnionToIntersection<
|
|
121
|
+
Lookup extends readonly (infer Item)[]
|
|
122
|
+
? Item extends
|
|
123
|
+
| readonly [infer LocalName extends string, infer Data]
|
|
124
|
+
| readonly [infer LocalName, infer SourceName, infer Data]
|
|
125
|
+
? Data extends {
|
|
126
|
+
[K in `${SourceName extends string
|
|
127
|
+
? SourceName
|
|
128
|
+
: LocalName}Change`]: (value: infer V, ...args: any[]) => any;
|
|
129
|
+
}
|
|
130
|
+
? { [K in LocalName]: V }
|
|
131
|
+
: { readonly [K in LocalName]: unknown }
|
|
132
|
+
: never
|
|
133
|
+
: never
|
|
134
|
+
>;
|
|
135
|
+
|
|
136
|
+
export function bind<
|
|
137
|
+
Owner extends Marko.Component,
|
|
138
|
+
OwnerHandlers extends ComponentEventHandlers<Owner>,
|
|
139
|
+
Handler extends
|
|
140
|
+
| keyof OwnerHandlers
|
|
141
|
+
| ((...args: any) => any)
|
|
142
|
+
| false
|
|
143
|
+
| void,
|
|
144
|
+
Args extends readonly any[],
|
|
145
|
+
>(
|
|
146
|
+
owner: Owner,
|
|
147
|
+
handler: Handler,
|
|
148
|
+
...args: Args
|
|
149
|
+
): Args extends readonly []
|
|
150
|
+
? Handler extends keyof OwnerHandlers
|
|
151
|
+
? OwnerHandlers[Handler]
|
|
152
|
+
: Handler
|
|
153
|
+
: (...args: any) => any; // If typescript ever actually supports partial application maybe we do this.
|
|
154
|
+
|
|
155
|
+
export function renderTemplate<Name extends Marko.Template<any, any>>(
|
|
156
|
+
template: Name,
|
|
157
|
+
): TemplateRenderer<Name>;
|
|
158
|
+
export function renderNativeTag<Name extends string>(
|
|
159
|
+
tag: Name,
|
|
160
|
+
): NativeTagRenderer<Name>;
|
|
161
|
+
export const missingTag: DefaultRenderer;
|
|
162
|
+
export function resolveTemplate<Template>(
|
|
163
|
+
imported: Promise<{ default: Template }>,
|
|
164
|
+
): Template;
|
|
165
|
+
export function fallbackTemplate<Tag, Template>(
|
|
166
|
+
tag: Tag,
|
|
167
|
+
fallback: Promise<{ default: Template }>,
|
|
168
|
+
): [0] extends [1 & Tag] ? Template : Tag;
|
|
169
|
+
export function input<Name>(tag: Name): Marko.Input<Name>;
|
|
170
|
+
export function renderDynamicTag<Name>(tag: Name): DynamicRenderer<Name>;
|
|
171
|
+
|
|
172
|
+
export function returnTag<
|
|
173
|
+
Input extends { value: unknown; valueChange?: (value: any) => void },
|
|
174
|
+
>(input: Input): Input;
|
|
175
|
+
|
|
176
|
+
export function forOfTag<
|
|
177
|
+
Value extends Iterable,
|
|
178
|
+
Item extends [0] extends [1 & Value]
|
|
179
|
+
? any
|
|
180
|
+
: Value extends readonly (infer Item)[] | Iterable<infer Item>
|
|
181
|
+
? Item
|
|
182
|
+
: never,
|
|
183
|
+
BodyContent extends Marko.Body<
|
|
184
|
+
[item: Item, index: number, all: Value],
|
|
185
|
+
void
|
|
186
|
+
>,
|
|
187
|
+
>(
|
|
188
|
+
input: {
|
|
189
|
+
of: Value | false | void | null;
|
|
190
|
+
by?: ((item: Item, index: number) => string) | string;
|
|
191
|
+
},
|
|
192
|
+
content: BodyContent,
|
|
193
|
+
): ReturnAndScope<BodyContentScope<BodyContent>, void>;
|
|
194
|
+
|
|
195
|
+
export function forInTag<
|
|
196
|
+
Value,
|
|
197
|
+
BodyContent extends Marko.Body<
|
|
198
|
+
[key: keyof Value, value: Value[keyof Value]],
|
|
199
|
+
void
|
|
200
|
+
>,
|
|
201
|
+
>(
|
|
202
|
+
input: {
|
|
203
|
+
in: Value | false | void | null;
|
|
204
|
+
by?: (value: Value[keyof Value], key: keyof Value) => string;
|
|
205
|
+
},
|
|
206
|
+
content: BodyContent,
|
|
207
|
+
): ReturnAndScope<BodyContentScope<BodyContent>, void>;
|
|
208
|
+
|
|
209
|
+
export function forToTag<
|
|
210
|
+
From extends void | number,
|
|
211
|
+
To extends number,
|
|
212
|
+
Step extends void | number,
|
|
213
|
+
BodyContent extends Marko.Body<[index: number], void>,
|
|
214
|
+
>(
|
|
215
|
+
input: {
|
|
216
|
+
from?: From;
|
|
217
|
+
to: To;
|
|
218
|
+
step?: Step;
|
|
219
|
+
by?: (index: number) => string;
|
|
220
|
+
},
|
|
221
|
+
content: BodyContent,
|
|
222
|
+
): ReturnAndScope<BodyContentScope<BodyContent>, void>;
|
|
223
|
+
|
|
224
|
+
export function forTag<BodyContent extends AnyMarkoBody>(
|
|
225
|
+
input: (
|
|
226
|
+
| {
|
|
227
|
+
from?: number;
|
|
228
|
+
to: number;
|
|
229
|
+
step?: number;
|
|
230
|
+
}
|
|
231
|
+
| {
|
|
232
|
+
in: object | false | void | null;
|
|
233
|
+
}
|
|
234
|
+
| {
|
|
235
|
+
of: Iterable<unknown> | readonly unknown[] | false | void | null;
|
|
236
|
+
}
|
|
237
|
+
) & { by?: (...args: unknown[]) => string },
|
|
238
|
+
content: BodyContent,
|
|
239
|
+
): ReturnAndScope<BodyContentScope<BodyContent>, void>;
|
|
240
|
+
|
|
241
|
+
export function forOfAttrTag<
|
|
242
|
+
Value extends Iterable,
|
|
243
|
+
Item extends [0] extends [1 & Value]
|
|
244
|
+
? any
|
|
245
|
+
: Value extends readonly (infer Item)[] | Iterable<infer Item>
|
|
246
|
+
? Item
|
|
247
|
+
: never,
|
|
248
|
+
const Return,
|
|
249
|
+
>(
|
|
250
|
+
input: {
|
|
251
|
+
of: Value | false | void | null;
|
|
252
|
+
},
|
|
253
|
+
content: (value: Item, index: number, all: Value) => Return,
|
|
254
|
+
): {
|
|
255
|
+
[Key in keyof Return]: Return[Key] extends
|
|
256
|
+
| readonly (infer Item)[]
|
|
257
|
+
| (infer Item extends Record<PropertyKey, any>)
|
|
258
|
+
? AttrTagByListSize<Value, Item>
|
|
259
|
+
: never;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export function forInAttrTag<Value extends object, const Return>(
|
|
263
|
+
input: {
|
|
264
|
+
in: Value | false | void | null;
|
|
265
|
+
},
|
|
266
|
+
content: (key: keyof Value, value: Value[keyof Value]) => Return,
|
|
267
|
+
): {
|
|
268
|
+
[Key in keyof Return]: Return[Key] extends
|
|
269
|
+
| readonly (infer Item)[]
|
|
270
|
+
| (infer Item extends Record<PropertyKey, any>)
|
|
271
|
+
? AttrTagByObjectSize<Value, Item>
|
|
272
|
+
: never;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
export function forToAttrTag<
|
|
276
|
+
From extends void | number,
|
|
277
|
+
To extends number,
|
|
278
|
+
Step extends void | number,
|
|
279
|
+
const Return,
|
|
280
|
+
>(
|
|
281
|
+
input: {
|
|
282
|
+
from?: From;
|
|
283
|
+
to: To;
|
|
284
|
+
step?: Step;
|
|
285
|
+
},
|
|
286
|
+
content: (index: number) => Return,
|
|
287
|
+
): {
|
|
288
|
+
[Key in keyof Return]: Return[Key] extends
|
|
289
|
+
| readonly (infer Item)[]
|
|
290
|
+
| (infer Item extends Record<PropertyKey, any>)
|
|
291
|
+
? number extends From | To | Step
|
|
292
|
+
? undefined | Marko.AttrTag<Item>
|
|
293
|
+
: Step extends 0
|
|
294
|
+
? never
|
|
295
|
+
: [To] extends [From extends void ? 0 : From]
|
|
296
|
+
? undefined
|
|
297
|
+
: Marko.AttrTag<Item>
|
|
298
|
+
: never;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export function forAttrTag<const Return>(
|
|
302
|
+
input:
|
|
303
|
+
| {
|
|
304
|
+
of: Iterable<unknown> | readonly unknown[] | false | void | null;
|
|
305
|
+
}
|
|
306
|
+
| {
|
|
307
|
+
in: object;
|
|
308
|
+
}
|
|
309
|
+
| {
|
|
310
|
+
from?: number;
|
|
311
|
+
to: number;
|
|
312
|
+
step?: number;
|
|
313
|
+
},
|
|
314
|
+
content: (...args: unknown[]) => Return,
|
|
315
|
+
): {
|
|
316
|
+
[Key in keyof Return]: Return[Key] extends
|
|
317
|
+
| readonly (infer Item)[]
|
|
318
|
+
| (infer Item extends Record<PropertyKey, any>)
|
|
319
|
+
? undefined | Marko.AttrTag<Item>
|
|
320
|
+
: never;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export function mergeAttrTags<Attrs extends readonly any[]>(
|
|
324
|
+
...attrs: Attrs
|
|
325
|
+
): MergeAttrTags<Attrs>;
|
|
326
|
+
export function attrTag<AttrTag>(attrTags: AttrTag[]): AttrTag;
|
|
327
|
+
export function attrTagFor<Tag, Path extends readonly string[]>(
|
|
328
|
+
tag: Tag,
|
|
329
|
+
...path: Path
|
|
330
|
+
): <
|
|
331
|
+
AttrTag extends [0] extends [1 & Tag]
|
|
332
|
+
? Marko.AttrTag<unknown>
|
|
333
|
+
: Marko.Input<Tag> extends infer Input
|
|
334
|
+
? [0] extends [1 & Input]
|
|
335
|
+
? Marko.AttrTag<unknown>
|
|
336
|
+
: AttrTagValue<Marko.Input<Tag>, Path>
|
|
337
|
+
: Marko.AttrTag<unknown>,
|
|
338
|
+
>(
|
|
339
|
+
attrTags: AttrTag[],
|
|
340
|
+
) => AttrTag extends Marko.AttrTag<infer Input>
|
|
341
|
+
? Marko.AttrTag<Input>
|
|
342
|
+
: any;
|
|
343
|
+
|
|
344
|
+
// TODO: this could be improved.
|
|
345
|
+
// currently falls back to DefaultRenderer too eagerly.
|
|
346
|
+
export type DynamicRenderer<Name> = [0] extends [1 & Name]
|
|
347
|
+
? DefaultRenderer
|
|
348
|
+
: [Name] extends [Marko.Template<any, any>]
|
|
349
|
+
? TemplateRenderer<Name>
|
|
350
|
+
: [Name] extends [string]
|
|
351
|
+
? NativeTagRenderer<Name>
|
|
352
|
+
: [Name] extends [AnyMarkoBody]
|
|
353
|
+
? BodyRenderer<Name>
|
|
354
|
+
: [Name] extends [
|
|
355
|
+
{
|
|
356
|
+
[BodyContentKey in DefaultBodyContentKey]?: infer BodyValue extends
|
|
357
|
+
AnyMarkoBody;
|
|
358
|
+
},
|
|
359
|
+
]
|
|
360
|
+
? BodyRenderer<BodyValue>
|
|
361
|
+
: DefaultRenderer;
|
|
362
|
+
|
|
363
|
+
export type TemplateRenderer<Template> = Template extends {
|
|
364
|
+
_: infer Renderer;
|
|
365
|
+
}
|
|
366
|
+
? Renderer
|
|
367
|
+
: Template extends Marko.Template<infer Input, infer Return>
|
|
368
|
+
? BaseRenderer<Input, Return>
|
|
369
|
+
: never;
|
|
370
|
+
|
|
371
|
+
export interface NativeTagRenderer<Name extends string> {
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
373
|
+
(): () => <__marko_internal_input extends unknown>(
|
|
374
|
+
input: Marko.Directives &
|
|
375
|
+
Marko.NativeTags[Name]["input"] &
|
|
376
|
+
Relate<
|
|
377
|
+
__marko_internal_input,
|
|
378
|
+
Marko.Directives & Marko.NativeTags[Name]["input"]
|
|
379
|
+
>,
|
|
380
|
+
) => ReturnAndScope<
|
|
381
|
+
Scopes<__marko_internal_input>,
|
|
382
|
+
Marko.NativeTags[Name]["return"]
|
|
383
|
+
>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface BodyRenderer<Body extends AnyMarkoBody> {
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
388
|
+
(): () => <__marko_internal_input extends unknown>(
|
|
389
|
+
...args: BodyParamsWithDefault<Body> &
|
|
390
|
+
Relate<__marko_internal_input, BodyParamsWithDefault<Body>>
|
|
391
|
+
) => ReturnAndScope<
|
|
392
|
+
Scopes<__marko_internal_input>,
|
|
393
|
+
BodyReturnType<Body>
|
|
394
|
+
>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface BaseRenderer<Input, Return = void> {
|
|
398
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
399
|
+
(): () => <__marko_input_with_scope extends unknown>(
|
|
400
|
+
input: Marko.Directives &
|
|
401
|
+
Input &
|
|
402
|
+
Relate<__marko_input_with_scope, Marko.Directives & Input>,
|
|
403
|
+
) => ReturnAndScope<Scopes<__marko_input_with_scope>, Return>;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface DefaultRenderer {
|
|
407
|
+
(): () => <Input>(input: Input) => ReturnAndScope<Scopes<Input>, void>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export type Relate<A, B> = B extends A ? A : B;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
declare abstract class MarkoReturn<Return> {
|
|
416
|
+
return: Return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type AnyMarkoBody = Marko.Body<any, any>;
|
|
420
|
+
|
|
421
|
+
type BodyContentScope<BodyContent> = BodyContent extends (...params: any) => {
|
|
422
|
+
[Marko._.scope]: infer Scope;
|
|
423
|
+
}
|
|
424
|
+
? Scope
|
|
425
|
+
: never;
|
|
426
|
+
|
|
427
|
+
type ReturnAndScope<Scope, Return> = {
|
|
428
|
+
return: Return;
|
|
429
|
+
scope: Scope;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
type BodyParamsWithDefault<Body extends AnyMarkoBody> =
|
|
433
|
+
Body extends Marko.Body<infer Params, any>
|
|
434
|
+
? Params extends []
|
|
435
|
+
? [input?: Record<string, never>]
|
|
436
|
+
: Params
|
|
437
|
+
: never;
|
|
438
|
+
|
|
439
|
+
type Scopes<Input> = [0] extends [1 & Input]
|
|
440
|
+
? never
|
|
441
|
+
: MergeScopes<FlatScopes<Input>>;
|
|
442
|
+
|
|
443
|
+
type ComponentEventHandlers<Component extends Marko.Component> = {
|
|
444
|
+
[K in Exclude<
|
|
445
|
+
keyof Component,
|
|
446
|
+
Exclude<
|
|
447
|
+
keyof Marko.Component,
|
|
448
|
+
"emit" | "setState" | "setStateDirty" | "forceUpdate"
|
|
449
|
+
>
|
|
450
|
+
>]: Component[K] extends (...args: any) => any ? Component[K] : never;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
type FlatScopes<Input> = [0] extends [1 & Input]
|
|
454
|
+
? never
|
|
455
|
+
:
|
|
456
|
+
| (Input[("content" | "renderBody") & keyof Input] extends infer Prop
|
|
457
|
+
? Prop extends (...args: any[]) => { [Marko._.scope]: infer Scope }
|
|
458
|
+
? Scope
|
|
459
|
+
: never
|
|
460
|
+
: never)
|
|
461
|
+
| (Input[string & keyof Input] extends infer Prop
|
|
462
|
+
? Prop extends { [Symbol.iterator]: any }
|
|
463
|
+
? Prop extends readonly any[]
|
|
464
|
+
? never
|
|
465
|
+
: FlatScopes<Prop>
|
|
466
|
+
: never
|
|
467
|
+
: never);
|
|
468
|
+
|
|
469
|
+
type MergeScopes<Scopes> = {
|
|
470
|
+
[K in Scopes extends Scopes ? keyof Scopes : never]: Scopes extends Scopes
|
|
471
|
+
? Scopes[K & keyof Scopes]
|
|
472
|
+
: never;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
type MergeOptionalScopes<Scopes> = {
|
|
476
|
+
[K in Scopes extends Scopes ? keyof Scopes : never]: Scopes extends Scopes
|
|
477
|
+
? K extends keyof Scopes
|
|
478
|
+
? Scopes[K]
|
|
479
|
+
: undefined
|
|
480
|
+
: never;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
type MergeAttrTags<Attrs extends readonly any[]> = Attrs extends readonly [
|
|
484
|
+
infer A,
|
|
485
|
+
infer B,
|
|
486
|
+
...infer Rest,
|
|
487
|
+
]
|
|
488
|
+
? MergeAttrTags<[MergeAttrTag<A, B>, ...Rest]>
|
|
489
|
+
: Attrs extends readonly [infer A]
|
|
490
|
+
? A
|
|
491
|
+
: never;
|
|
492
|
+
|
|
493
|
+
type MergeAttrTag<A, B> = {
|
|
494
|
+
[K in keyof A | keyof B]: K extends keyof A
|
|
495
|
+
? K extends keyof B
|
|
496
|
+
? MergeAttrTagValue<A[K], B[K]>
|
|
497
|
+
: A[K]
|
|
498
|
+
: K extends keyof B
|
|
499
|
+
? B[K]
|
|
500
|
+
: never;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
type MergeAttrTagValue<A, B> = A extends readonly (infer AType)[]
|
|
504
|
+
? B extends readonly (infer BType)[]
|
|
505
|
+
? AType | BType
|
|
506
|
+
: B extends void
|
|
507
|
+
? A
|
|
508
|
+
: AType | B
|
|
509
|
+
: A extends void
|
|
510
|
+
? B
|
|
511
|
+
: B extends void
|
|
512
|
+
? A
|
|
513
|
+
: A | B;
|
|
514
|
+
|
|
515
|
+
type AttrTagByListSize<T, Item> = T extends
|
|
516
|
+
| readonly [any, ...any[]]
|
|
517
|
+
| readonly [...any[], any]
|
|
518
|
+
? Marko.AttrTag<Item>
|
|
519
|
+
: T extends readonly []
|
|
520
|
+
? undefined
|
|
521
|
+
: undefined | Marko.AttrTag<Item>;
|
|
522
|
+
|
|
523
|
+
type AttrTagByObjectSize<
|
|
524
|
+
Value,
|
|
525
|
+
Item,
|
|
526
|
+
Keys = RecordKeys<Value>,
|
|
527
|
+
KnownKeys = KnownRecordKeys<Value>,
|
|
528
|
+
> = CheckNever<
|
|
529
|
+
Keys,
|
|
530
|
+
undefined,
|
|
531
|
+
CheckNever<KnownKeys, Marko.AttrTag<Item>, undefined | Marko.AttrTag<Item>>
|
|
532
|
+
>;
|
|
533
|
+
|
|
534
|
+
type AttrTagValue<Input, Path extends readonly string[]> = Path extends [
|
|
535
|
+
infer Prop extends keyof Input,
|
|
536
|
+
...infer Rest extends readonly string[],
|
|
537
|
+
]
|
|
538
|
+
? Input[Prop] & Marko.AttrTag<unknown> extends infer Value
|
|
539
|
+
? Rest extends readonly []
|
|
540
|
+
? Value
|
|
541
|
+
: AttrTagValue<Value, Rest>
|
|
542
|
+
: Marko.AttrTag<unknown>
|
|
543
|
+
: Marko.AttrTag<unknown>;
|
|
544
|
+
|
|
545
|
+
type AttrTagNames<Input> = Record<string, never> &
|
|
546
|
+
(Input extends infer Input extends {}
|
|
547
|
+
? {
|
|
548
|
+
[Key in keyof Input & string as `@${Input[Key] extends infer Value
|
|
549
|
+
? Value extends Marko.AttrTag<any>
|
|
550
|
+
? Key
|
|
551
|
+
: never
|
|
552
|
+
: never}`]: Input[Key];
|
|
553
|
+
}
|
|
554
|
+
: never);
|
|
555
|
+
|
|
556
|
+
type RecordKeys<T> = keyof {
|
|
557
|
+
[K in keyof T as CheckNever<T[K], never, K>]: 0;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
type KnownRecordKeys<T> = keyof {
|
|
561
|
+
[Key in keyof T as string extends Key
|
|
562
|
+
? never
|
|
563
|
+
: number extends Key
|
|
564
|
+
? never
|
|
565
|
+
: symbol extends Key
|
|
566
|
+
? never
|
|
567
|
+
: CheckNever<T[Key], never, Key>]: 0;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
type CheckNever<T, If, Else> = [T] extends [never] ? If : Else;
|
|
571
|
+
|
|
572
|
+
type UnionToIntersection<T> = (T extends any ? (_: T) => any : never) extends (
|
|
573
|
+
_: infer U,
|
|
574
|
+
) => any
|
|
575
|
+
? U
|
|
576
|
+
: never;
|
|
577
|
+
|
|
578
|
+
type DefaultBodyContentKey = keyof Exclude<
|
|
579
|
+
Marko.Renderable,
|
|
580
|
+
Marko.Template<any, any> | Marko.Body<any, any> | string
|
|
581
|
+
>;
|
|
582
|
+
|
|
583
|
+
export {};
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import "./tags-html";
|
|
2
|
+
|
|
3
|
+
declare module "*.marko" {
|
|
4
|
+
const template: Marko.Template;
|
|
5
|
+
export default template;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
namespace NodeJS {
|
|
10
|
+
interface ReadableStream {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace Marko {
|
|
14
|
+
/** A mutable global object for the current render. */
|
|
15
|
+
export interface Global {
|
|
16
|
+
[x: PropertyKey]: unknown;
|
|
17
|
+
/** An AbortSignal instance that, when aborted, stops further streamed content. */
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
/** A CSP Nonce to add to each script output from Marko. */
|
|
20
|
+
cspNonce?: string;
|
|
21
|
+
/** Used for rendering multiple Marko templates in a single hydrated page. */
|
|
22
|
+
renderId?: string;
|
|
23
|
+
/** Used to uniquely identify a instance of a Marko runtime. */
|
|
24
|
+
runtimeId?: string;
|
|
25
|
+
/** A list of globals that should be serialized to the browser. */
|
|
26
|
+
serializedGlobals?: Record<string, boolean>;
|
|
27
|
+
/** @deprecated prefer `renderId` */
|
|
28
|
+
widgetIdPrefix?: string;
|
|
29
|
+
/** @deprecated prefer `renderId` */
|
|
30
|
+
componentIdPrefix?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type TemplateInput<Input> = Input & {
|
|
34
|
+
$global?: Global;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The result of calling `template.render`. */
|
|
38
|
+
export type RenderedTemplate<Component = unknown> = Promise<
|
|
39
|
+
Component extends Marko.Component ? RenderResult<Component> : string
|
|
40
|
+
> &
|
|
41
|
+
AsyncIterable<string> & {
|
|
42
|
+
toReadable(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
43
|
+
pipe(stream: {
|
|
44
|
+
write(chunk: string): unknown;
|
|
45
|
+
end(): unknown;
|
|
46
|
+
flush?(): void;
|
|
47
|
+
}): void;
|
|
48
|
+
toString(): string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The result of calling `template.mount`. */
|
|
52
|
+
export type MountedTemplate<Input = unknown, Return = unknown> = {
|
|
53
|
+
get value(): Return extends { value: infer Value } ? Value : void;
|
|
54
|
+
set value(
|
|
55
|
+
next: Return extends { valueChange?(next: infer Next): any }
|
|
56
|
+
? Next
|
|
57
|
+
: never,
|
|
58
|
+
);
|
|
59
|
+
update(input: Marko.TemplateInput<Input>): void;
|
|
60
|
+
destroy(): void;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export interface Out<Component = unknown>
|
|
64
|
+
extends Marko.RenderedTemplate<Component> {
|
|
65
|
+
/** The underlying ReadableStream Marko is writing into. */
|
|
66
|
+
stream: unknown;
|
|
67
|
+
/** A mutable global object for the current render. */
|
|
68
|
+
global: Global;
|
|
69
|
+
/** Disable all async rendering. Will error if something beings async. */
|
|
70
|
+
sync(): void;
|
|
71
|
+
/** Returns true if async rendering is disabled. */
|
|
72
|
+
isSync(): boolean;
|
|
73
|
+
/** Write unescaped text at the current stream position. */
|
|
74
|
+
write(val: string | void): this;
|
|
75
|
+
/** Write javascript content to be merged with the scripts Marko sends out on the next flush. */
|
|
76
|
+
script(val: string | void): this;
|
|
77
|
+
/** Starts a new async/forked stream. */
|
|
78
|
+
beginAsync(options?: {
|
|
79
|
+
name?: string;
|
|
80
|
+
timeout?: number;
|
|
81
|
+
last?: boolean;
|
|
82
|
+
}): Out;
|
|
83
|
+
/** Marks the current stream as complete (async streams may still be executing). */
|
|
84
|
+
end(val?: string | void): this;
|
|
85
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
|
86
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
87
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
88
|
+
prependListener(
|
|
89
|
+
eventName: PropertyKey,
|
|
90
|
+
listener: (...args: any[]) => any,
|
|
91
|
+
): this;
|
|
92
|
+
removeListener(
|
|
93
|
+
eventName: PropertyKey,
|
|
94
|
+
listener: (...args: any[]) => any,
|
|
95
|
+
): this;
|
|
96
|
+
/** Register a callback executed when the last async out has completed. */
|
|
97
|
+
onLast(listener: (next: () => void) => unknown): this;
|
|
98
|
+
/** Emits an error on the stream. */
|
|
99
|
+
error(e: Error): this;
|
|
100
|
+
/** Schedules a Marko to flush buffered html to the underlying stream. */
|
|
101
|
+
flush(): this;
|
|
102
|
+
/** Creates a detached out stream (used for out of order flushing). */
|
|
103
|
+
createOut(): Out;
|
|
104
|
+
/** Write escaped text at the current stream position. */
|
|
105
|
+
text(val: string | void): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Body content created from by a component, typically held in an object with a renderBody property. */
|
|
109
|
+
|
|
110
|
+
export interface Body<
|
|
111
|
+
in Params extends readonly any[] = [],
|
|
112
|
+
out Return = void,
|
|
113
|
+
> {}
|
|
114
|
+
|
|
115
|
+
/** Valid data types which can be passed in as a <${dynamic}/> tag name. */
|
|
116
|
+
export type Renderable =
|
|
117
|
+
| { renderBody: Body<any, any> | Template | string }
|
|
118
|
+
| Body<any, any>
|
|
119
|
+
| Template
|
|
120
|
+
| string;
|
|
121
|
+
|
|
122
|
+
/** Extract the return tag type from a renderBody. */
|
|
123
|
+
export type BodyReturnType<B> =
|
|
124
|
+
B extends Body<any, infer Return> ? Return : never;
|
|
125
|
+
|
|
126
|
+
/** Extract the tag parameter types received by a renderBody. */
|
|
127
|
+
export type BodyParameters<B> =
|
|
128
|
+
B extends Body<infer Params, any> ? Params : never;
|
|
129
|
+
|
|
130
|
+
export class Component<Input = unknown, State = unknown>
|
|
131
|
+
implements Emitter
|
|
132
|
+
{
|
|
133
|
+
/** A unique id for this instance. */
|
|
134
|
+
public readonly id: string;
|
|
135
|
+
/** The top level element rendered by this instance. */
|
|
136
|
+
public readonly el: Element | void;
|
|
137
|
+
/** The attributes passed to this instance. */
|
|
138
|
+
public readonly input: Input;
|
|
139
|
+
/** @deprecated */
|
|
140
|
+
public readonly els: Element[];
|
|
141
|
+
/** Mutable state that when changed causes a rerender. */
|
|
142
|
+
state: State;
|
|
143
|
+
|
|
144
|
+
/** Returns the amount of event handlers listening to a specific event. */
|
|
145
|
+
listenerCount(eventName: PropertyKey): number;
|
|
146
|
+
/**
|
|
147
|
+
* Used to wrap an existing event emitted and ensure that all events are
|
|
148
|
+
* cleaned up once this component is destroyed
|
|
149
|
+
* */
|
|
150
|
+
subscribeTo(
|
|
151
|
+
emitter: unknown,
|
|
152
|
+
): Omit<Emitter, "listenerCount" | "prependListener" | "emit">;
|
|
153
|
+
/** Emits an event on the component instance. */
|
|
154
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
|
155
|
+
/** Listen to an event on the component instance. */
|
|
156
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
157
|
+
/** Listen to an event on the component instance once. */
|
|
158
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
159
|
+
/** Listen to an event on the component instance before all other listeners. */
|
|
160
|
+
prependListener(
|
|
161
|
+
eventName: PropertyKey,
|
|
162
|
+
listener: (...args: any[]) => any,
|
|
163
|
+
): this;
|
|
164
|
+
/** Remove a listener from the component instance. */
|
|
165
|
+
removeListener(
|
|
166
|
+
eventName: PropertyKey,
|
|
167
|
+
listener: (...args: any[]) => any,
|
|
168
|
+
): this;
|
|
169
|
+
/** Remove all listeners from the component instance. */
|
|
170
|
+
removeAllListeners(eventName?: PropertyKey): this;
|
|
171
|
+
/** Removes the component instance from the DOM and cleans up all active event handlers including all children. */
|
|
172
|
+
destroy(): void;
|
|
173
|
+
/** Schedule an update (similar to if a state had been changed). */
|
|
174
|
+
forceUpdate(): void;
|
|
175
|
+
/** Generates a unique id derived from the current unique instance id (similar to :scoped in the template). */
|
|
176
|
+
elId(key?: string, index?: number): string;
|
|
177
|
+
/** @alias elId */
|
|
178
|
+
getElId(key?: string, index?: number): string;
|
|
179
|
+
/** Gets an element reference by its `key` attribute in the template. */
|
|
180
|
+
getEl<T extends Element | void = Element | void>(
|
|
181
|
+
key?: string,
|
|
182
|
+
index?: number,
|
|
183
|
+
): T;
|
|
184
|
+
/** Gets all element references by their `key` attribute in the template. */
|
|
185
|
+
getEls<T extends Element[] = Element[]>(key: string): T;
|
|
186
|
+
/** Gets a component reference by its `key` attribute in the template. */
|
|
187
|
+
getComponent<T extends Component | void = Component | void>(
|
|
188
|
+
key: string,
|
|
189
|
+
index?: number,
|
|
190
|
+
): T;
|
|
191
|
+
/** Gets all component references by their `key` attribute in the template. */
|
|
192
|
+
getComponents<T extends Component[] = Component[]>(key: string): T;
|
|
193
|
+
/** True if this instance has been removed from the dom. */
|
|
194
|
+
/** True if this instance is scheduled to rerender. */
|
|
195
|
+
isDestroyed(): boolean;
|
|
196
|
+
/** Replace the entire state object with a new one, removing old properties. */
|
|
197
|
+
replaceState(state: this["state"]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Update a property on this.state (should prefer mutating this.state directly).
|
|
200
|
+
* When passed an object as the first argument, it will be merged into the state.
|
|
201
|
+
*/
|
|
202
|
+
setState<Key extends PropertyKey>(
|
|
203
|
+
name: Key & keyof this["state"],
|
|
204
|
+
value: (this["state"] & Record<PropertyKey, unknown>)[Key],
|
|
205
|
+
): void;
|
|
206
|
+
setState(value: Partial<this["state"]>): void;
|
|
207
|
+
|
|
208
|
+
/** Schedules an update related to a specific state property and optionally updates the value. */
|
|
209
|
+
setStateDirty<Key extends PropertyKey>(
|
|
210
|
+
name: Key & keyof this["state"],
|
|
211
|
+
value?: (this["state"] & Record<PropertyKey, unknown>)[Key],
|
|
212
|
+
): void;
|
|
213
|
+
/** Synchronously flush any scheduled updates. */
|
|
214
|
+
update(): void;
|
|
215
|
+
/** Appends the dom for the current instance to a parent DOM element. */
|
|
216
|
+
appendTo(target: ParentNode): this;
|
|
217
|
+
/** Inserts the dom for the current instance after a sibling DOM element. */
|
|
218
|
+
insertAfter(target: ChildNode): this;
|
|
219
|
+
/** Inserts the dom for the current instance before a sibling DOM element. */
|
|
220
|
+
insertBefore(target: ChildNode): this;
|
|
221
|
+
/** Prepends the dom for the current instance to a parent DOM element. */
|
|
222
|
+
prependTo(target: ParentNode): this;
|
|
223
|
+
/** Replaces an existing DOM element with the dom for the current instance. */
|
|
224
|
+
replace(target: ChildNode): this;
|
|
225
|
+
/** Replaces the children of an existing DOM element with the dom for the current instance. */
|
|
226
|
+
replaceChildrenOf(target: ParentNode): this;
|
|
227
|
+
// /** Called when the component is firsted created. */
|
|
228
|
+
// onCreate?(input: this["input"], out: Marko.Out): void;
|
|
229
|
+
// /** Called every time the component receives input from it's parent. */
|
|
230
|
+
// onInput?(input: this["input"], out: Marko.Out): void | this["input"];
|
|
231
|
+
// /** Called after a component has successfully rendered, but before it's update has been applied to the dom. */
|
|
232
|
+
// onRender?(out: Marko.Out): void;
|
|
233
|
+
// /** Called after the first time the component renders and is attached to the dom. */
|
|
234
|
+
// onMount?(): void;
|
|
235
|
+
// /** Called when a components render has been applied to the DOM (excluding when it is initially mounted). */
|
|
236
|
+
// onUpdate?(): void;
|
|
237
|
+
// /** Called when a component is destroyed and removed from the dom. */
|
|
238
|
+
// onDestroy?(): void;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The top level api for a Marko Template. */
|
|
242
|
+
export abstract class Template<Input = unknown, Return = unknown> {
|
|
243
|
+
/** Creates a Marko compatible output stream. */
|
|
244
|
+
createOut(): Out;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The folowing types are processed up by the @marko/language-tools
|
|
248
|
+
* and inlined into the compiled template.
|
|
249
|
+
*
|
|
250
|
+
* This is done to support generics on each of these methods
|
|
251
|
+
* until TypeScript supports higher kinded types.
|
|
252
|
+
*
|
|
253
|
+
* https://github.com/microsoft/TypeScript/issues/1213
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
/** @marko-overload-start */
|
|
257
|
+
/** Asynchronously render the template. */
|
|
258
|
+
abstract render(
|
|
259
|
+
input: Marko.TemplateInput<Input>,
|
|
260
|
+
stream?: {
|
|
261
|
+
write: (chunk: string) => void;
|
|
262
|
+
end: (chunk?: string) => void;
|
|
263
|
+
},
|
|
264
|
+
): Marko.Out<Marko.Component>;
|
|
265
|
+
|
|
266
|
+
/** Asynchronously render the template in buffered mode. */
|
|
267
|
+
abstract render(
|
|
268
|
+
input: Marko.TemplateInput<Input>,
|
|
269
|
+
cb?: (
|
|
270
|
+
err: Error | null,
|
|
271
|
+
result: Marko.RenderResult<Marko.Component>,
|
|
272
|
+
) => void,
|
|
273
|
+
): Marko.Out<Marko.Component>;
|
|
274
|
+
|
|
275
|
+
/** Synchronously render the template. */
|
|
276
|
+
abstract renderSync(
|
|
277
|
+
input: Marko.TemplateInput<Input>,
|
|
278
|
+
): Marko.RenderResult<Marko.Component>;
|
|
279
|
+
|
|
280
|
+
/** Synchronously render a template to a string. */
|
|
281
|
+
abstract renderToString(input: Marko.TemplateInput<Input>): string;
|
|
282
|
+
|
|
283
|
+
/** Render a template and return a stream.Readable in nodejs or a ReadableStream in a web worker environment. */
|
|
284
|
+
abstract stream(
|
|
285
|
+
input: Marko.TemplateInput<Input>,
|
|
286
|
+
): ReadableStream<string> & NodeJS.ReadableStream;
|
|
287
|
+
|
|
288
|
+
/** Render and attach the template to a DOM node. */
|
|
289
|
+
abstract mount(
|
|
290
|
+
input: Marko.TemplateInput<Input>,
|
|
291
|
+
reference: Node,
|
|
292
|
+
position?: "afterbegin" | "afterend" | "beforebegin" | "beforeend",
|
|
293
|
+
): Marko.MountedTemplate<typeof input>;
|
|
294
|
+
/** @marko-overload-end */
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface RenderResult<
|
|
298
|
+
out Component extends Marko.Component = Marko.Component,
|
|
299
|
+
> {
|
|
300
|
+
/** Returns the component created as a result of rendering the template. */
|
|
301
|
+
getComponent(): Component;
|
|
302
|
+
getComponents(selector?: any): any;
|
|
303
|
+
/** Triggers the mount lifecycle of a component without necessarily attaching it to the DOM. */
|
|
304
|
+
afterInsert(host?: any): this;
|
|
305
|
+
/** Gets the DOM node rendered by a template. */
|
|
306
|
+
getNode(host?: any): Node;
|
|
307
|
+
/** Gets the HTML output of the rendered template. */
|
|
308
|
+
toString(): string;
|
|
309
|
+
/** Appends the dom of the rendered template to a parent DOM element. */
|
|
310
|
+
appendTo(target: ParentNode): this;
|
|
311
|
+
/** Inserts the dom of the rendered template after a sibling DOM element. */
|
|
312
|
+
insertAfter(target: ChildNode): this;
|
|
313
|
+
/** Inserts the dom of the rendered template before a sibling DOM element. */
|
|
314
|
+
insertBefore(target: ChildNode): this;
|
|
315
|
+
/** Prepends the dom of the rendered template to a parent DOM element. */
|
|
316
|
+
prependTo(target: ParentNode): this;
|
|
317
|
+
/** Replaces an existing DOM element with the dom of the rendered template. */
|
|
318
|
+
replace(target: ChildNode): this;
|
|
319
|
+
/** Replaces the children of an existing DOM element with the dom of the rendered template. */
|
|
320
|
+
replaceChildrenOf(target: ParentNode): this;
|
|
321
|
+
out: Out<Component>;
|
|
322
|
+
/** @deprecated */
|
|
323
|
+
document: any;
|
|
324
|
+
/** @deprecated */
|
|
325
|
+
getOutput(): string;
|
|
326
|
+
/** @deprecated */
|
|
327
|
+
html: string;
|
|
328
|
+
/** @deprecated */
|
|
329
|
+
context: Out<Component>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface Emitter {
|
|
333
|
+
listenerCount(eventName: PropertyKey): number;
|
|
334
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
|
335
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
336
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
|
337
|
+
prependListener(
|
|
338
|
+
eventName: PropertyKey,
|
|
339
|
+
listener: (...args: any[]) => any,
|
|
340
|
+
): this;
|
|
341
|
+
removeListener(
|
|
342
|
+
eventName: PropertyKey,
|
|
343
|
+
listener: (...args: any[]) => any,
|
|
344
|
+
): this;
|
|
345
|
+
removeAllListeners(eventName?: PropertyKey): this;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export type AttrTag<T> = T & {
|
|
349
|
+
[Symbol.iterator](): Iterator<T>;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export interface NativeTag<
|
|
353
|
+
Input extends Record<string, any>,
|
|
354
|
+
Return extends Element,
|
|
355
|
+
> {
|
|
356
|
+
input: Input;
|
|
357
|
+
return: { value: () => Return };
|
|
358
|
+
}
|
|
359
|
+
export interface NativeTags {
|
|
360
|
+
[name: string]: NativeTag<Record<string, any>, Element>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export type Input<Name> = 0 extends 1 & Name
|
|
364
|
+
? any
|
|
365
|
+
: Name extends string
|
|
366
|
+
? Name extends keyof NativeTags
|
|
367
|
+
? NativeTags[Name]["input"]
|
|
368
|
+
: Record<string, unknown>
|
|
369
|
+
: Name extends
|
|
370
|
+
| Template<infer Input, any>
|
|
371
|
+
| { _(): () => (input: infer Input) => any }
|
|
372
|
+
? Input
|
|
373
|
+
: Name extends Body<infer Args, any>
|
|
374
|
+
? Args extends {
|
|
375
|
+
length: infer Length;
|
|
376
|
+
}
|
|
377
|
+
? number extends Length
|
|
378
|
+
? Args[0] | undefined
|
|
379
|
+
: 0 extends Length
|
|
380
|
+
? undefined
|
|
381
|
+
: Args[0]
|
|
382
|
+
: never
|
|
383
|
+
: never;
|
|
384
|
+
|
|
385
|
+
export type Return<Name> = 0 extends 1 & Name
|
|
386
|
+
? any
|
|
387
|
+
: Name extends string
|
|
388
|
+
? Name extends keyof NativeTags
|
|
389
|
+
? NativeTags[Name]["return"]
|
|
390
|
+
: () => Element
|
|
391
|
+
: Name extends
|
|
392
|
+
| { _(): () => (input: any) => { return: infer Return } }
|
|
393
|
+
| Template<any, infer Return>
|
|
394
|
+
| Body<any, infer Return>
|
|
395
|
+
? Return
|
|
396
|
+
: never;
|
|
397
|
+
|
|
398
|
+
/** @deprecated @see {@link Marko.AttrTag} */
|
|
399
|
+
export type RepeatableAttrTag<T> = AttrTag<T>;
|
|
400
|
+
|
|
401
|
+
/** @deprecated @see {@link Marko.Input} */
|
|
402
|
+
export type NativeTagInput<Name extends keyof NativeTags> =
|
|
403
|
+
NativeTags[Name]["input"];
|
|
404
|
+
/** @deprecated @see {@link Marko.Return} */
|
|
405
|
+
export type NativeTagReturn<Name extends keyof NativeTags> =
|
|
406
|
+
NativeTags[Name]["return"];
|
|
407
|
+
}
|
|
408
|
+
}
|