marko 5.22.3 → 5.22.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core-tags/core/await/index.marko +6 -6
- package/dist/runtime/components/entry/index-browser.js +4 -0
- package/dist/runtime/components/entry/index.js +4 -0
- package/index.d.ts +314 -0
- package/package.json +4 -3
- package/src/core-tags/core/await/index.marko +6 -6
- package/src/runtime/components/entry/index-browser.js +4 -0
- package/src/runtime/components/entry/index.js +4 -0
@@ -1,13 +1,13 @@
|
|
1
1
|
/**
|
2
2
|
* @template T
|
3
3
|
* @typedef {{
|
4
|
-
* value?: T;
|
5
|
-
* then?: Marko.Body<[Awaited<T>], void
|
6
|
-
* catch?: Marko.Body<[unknown], void
|
7
|
-
* placeholder?: Marko.Body<[], void
|
8
|
-
* client-reorder?: boolean;
|
4
|
+
* value?: readonly [T];
|
5
|
+
* then?: { renderBody: Marko.Body<[Awaited<T>], void> };
|
6
|
+
* catch?: { renderBody: Marko.Body<[unknown], void> };
|
7
|
+
* placeholder?: { renderBody: Marko.Body<[], void> };
|
8
|
+
* "client-reorder"?: boolean;
|
9
9
|
* name?: string;
|
10
10
|
* timeout?: number;
|
11
|
-
* show-after?: string;
|
11
|
+
* "show-after"?: string;
|
12
12
|
* }} Input
|
13
13
|
*/
|
@@ -270,4 +270,8 @@ exports.writeInitComponentsCode = writeInitComponentsCode;
|
|
270
270
|
*/
|
271
271
|
exports.getRenderedComponents = function (out) {
|
272
272
|
return warp10.stringifyPrepare(getInitComponentsDataFromOut(out));
|
273
|
+
};
|
274
|
+
|
275
|
+
globalThis.Marko = {
|
276
|
+
Component: function () {}
|
273
277
|
};
|
package/index.d.ts
ADDED
@@ -0,0 +1,314 @@
|
|
1
|
+
declare module "*.marko" {
|
2
|
+
const template: Marko.Template;
|
3
|
+
export default template;
|
4
|
+
}
|
5
|
+
|
6
|
+
declare namespace NodeJS {
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
8
|
+
interface ReadableStream {}
|
9
|
+
}
|
10
|
+
|
11
|
+
declare namespace Marko {
|
12
|
+
/** A mutable global object for the current render. */
|
13
|
+
export interface Global {
|
14
|
+
serializedGlobals?: Record<string, boolean>;
|
15
|
+
[attr: PropertyKey]: unknown;
|
16
|
+
}
|
17
|
+
|
18
|
+
export type TemplateInput<Input = { [attr: PropertyKey]: any }> = Input & {
|
19
|
+
$global?: Global;
|
20
|
+
};
|
21
|
+
|
22
|
+
export interface Out<Component extends Marko.Component = Marko.Component>
|
23
|
+
extends PromiseLike<RenderResult<Component>> {
|
24
|
+
/** The underlying ReadableStream Marko is writing into. */
|
25
|
+
stream: unknown;
|
26
|
+
/** A mutable global object for the current render. */
|
27
|
+
global: Global;
|
28
|
+
/** Disable all async rendering. Will error if something beings async. */
|
29
|
+
sync(): void;
|
30
|
+
/** Returns true if async rendering is disabled. */
|
31
|
+
isSync(): boolean;
|
32
|
+
/** Write unescaped text at the current stream position. */
|
33
|
+
write(val: string | void): this;
|
34
|
+
/** Write javascript content to be merged with the scripts Marko sends out on the next flush. */
|
35
|
+
script(val: string | void): this;
|
36
|
+
/** Returns the currently rendered html content. */
|
37
|
+
toString(): string;
|
38
|
+
/** Starts a new async/forked stream. */
|
39
|
+
beginAsync(options?: {
|
40
|
+
name?: string;
|
41
|
+
timeout?: number;
|
42
|
+
last?: boolean;
|
43
|
+
}): Out;
|
44
|
+
/** Marks the current stream as complete (async streams may still be executing). */
|
45
|
+
end(val?: string | void): this;
|
46
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
47
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
48
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
49
|
+
prependListener(
|
50
|
+
eventName: PropertyKey,
|
51
|
+
listener: (...args: any[]) => any
|
52
|
+
): this;
|
53
|
+
removeListener(
|
54
|
+
eventName: PropertyKey,
|
55
|
+
listener: (...args: any[]) => any
|
56
|
+
): this;
|
57
|
+
/** Register a callback executed when the last async out has completed. */
|
58
|
+
onLast(listener: (next: () => void) => unknown): this;
|
59
|
+
/** Pipe Marko's stream to another stream. */
|
60
|
+
pipe(stream: unknown): this;
|
61
|
+
/** Emits an error on the stream. */
|
62
|
+
error(e: Error): this;
|
63
|
+
/** Schedules a Marko to flush buffered html to the underlying stream. */
|
64
|
+
flush(): this;
|
65
|
+
/** Creates a detached out stream (used for out of order flushing). */
|
66
|
+
createOut(): Out;
|
67
|
+
/** Write escaped text at the current stream position. */
|
68
|
+
text(val: string | void): void;
|
69
|
+
}
|
70
|
+
|
71
|
+
/** Body content created from by a component, typically held in an object with a renderBody property. */
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
73
|
+
export interface Body<
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
75
|
+
in Params extends readonly any[] = [],
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
77
|
+
out Return = void
|
78
|
+
> {}
|
79
|
+
|
80
|
+
/** Valid data types which can be passed in as a <${dynamic}/> tag name. */
|
81
|
+
export type Renderable =
|
82
|
+
| { renderBody: Body<any, any> | Template | string }
|
83
|
+
| Body<any, any>
|
84
|
+
| Template
|
85
|
+
| string;
|
86
|
+
|
87
|
+
/** Extract the return tag type from a renderBody. */
|
88
|
+
export type BodyReturnType<B> = B extends Body<any, infer Return>
|
89
|
+
? Return
|
90
|
+
: never;
|
91
|
+
|
92
|
+
/** Extract the tag parameter types received by a renderBody. */
|
93
|
+
export type BodyParameters<B> = B extends Body<infer Params, any>
|
94
|
+
? Params
|
95
|
+
: never;
|
96
|
+
|
97
|
+
export class Component<
|
98
|
+
Input extends Record<PropertyKey, any> = Record<PropertyKey, any>,
|
99
|
+
State extends undefined | null | Record<PropertyKey, any> =
|
100
|
+
| undefined
|
101
|
+
| null
|
102
|
+
| Record<PropertyKey, any>
|
103
|
+
> implements Emitter
|
104
|
+
{
|
105
|
+
/** A unique id for this instance. */
|
106
|
+
public readonly id: string;
|
107
|
+
/** The top level element rendered by this instance. */
|
108
|
+
public readonly el: Element | void;
|
109
|
+
/** The attributes passed to this instance. */
|
110
|
+
public readonly input: Input;
|
111
|
+
/** @deprecated */
|
112
|
+
public readonly els: Element[];
|
113
|
+
/** Mutable state that when changed causes a rerender. */
|
114
|
+
abstract state: State;
|
115
|
+
|
116
|
+
/** Returns the amount of event handlers listening to a specific event. */
|
117
|
+
listenerCount(eventName: PropertyKey): number;
|
118
|
+
/**
|
119
|
+
* Used to wrap an existing event emitted and ensure that all events are
|
120
|
+
* cleaned up once this component is destroyed
|
121
|
+
* */
|
122
|
+
subscribeTo(
|
123
|
+
emitter: unknown
|
124
|
+
): Omit<Emitter, "listenerCount" | "prependListener" | "emit">;
|
125
|
+
/** Emits an event on the component instance. */
|
126
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
127
|
+
/** Listen to an event on the component instance. */
|
128
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
129
|
+
/** Listen to an event on the component instance once. */
|
130
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
131
|
+
/** Listen to an event on the component instance before all other listeners. */
|
132
|
+
prependListener(
|
133
|
+
eventName: PropertyKey,
|
134
|
+
listener: (...args: any[]) => any
|
135
|
+
): this;
|
136
|
+
/** Remove a listener from the component instance. */
|
137
|
+
removeListener(
|
138
|
+
eventName: PropertyKey,
|
139
|
+
listener: (...args: any[]) => any
|
140
|
+
): this;
|
141
|
+
/** Remove all listeners from the component instance. */
|
142
|
+
removeAllListeners(eventName?: PropertyKey): this;
|
143
|
+
/** Removes the component instance from the DOM and cleans up all active event handlers including all children. */
|
144
|
+
destroy(): void;
|
145
|
+
/** Schedule an update (similar to if a state had been changed). */
|
146
|
+
forceUpdate(): void;
|
147
|
+
/** Generates a unique id derived from the current unique instance id (similar to :scoped in the template). */
|
148
|
+
elId(key?: string, index?: number): string;
|
149
|
+
/** @alias elId */
|
150
|
+
getElId(key?: string, index?: number): string;
|
151
|
+
/** Gets an element reference by its `key` attribute in the template. */
|
152
|
+
getEl<T extends Element | void = Element | void>(
|
153
|
+
key?: string,
|
154
|
+
index?: number
|
155
|
+
): T;
|
156
|
+
/** Gets all element references by their `key` attribute in the template. */
|
157
|
+
getEls<T extends Element[] = Element[]>(key: string): T;
|
158
|
+
/** Gets a component reference by its `key` attribute in the template. */
|
159
|
+
getComponent<T extends Component | void = Component | void>(
|
160
|
+
key: string,
|
161
|
+
index?: number
|
162
|
+
): T;
|
163
|
+
/** Gets all component references by their `key` attribute in the template. */
|
164
|
+
getComponents<T extends Component[] = Component[]>(key: string): T;
|
165
|
+
/** True if this instance has been removed from the dom. */
|
166
|
+
/** True if this instance is scheduled to rerender. */
|
167
|
+
isDestroyed(): boolean;
|
168
|
+
/** Replace the entire state object with a new one, removing old properties. */
|
169
|
+
replaceState(state: this["state"]): void;
|
170
|
+
/**
|
171
|
+
* Update a property on this.state (should prefer mutating this.state directly).
|
172
|
+
* When passed an object as the first argument, it will be merged into the state.
|
173
|
+
*/
|
174
|
+
setState<Key extends PropertyKey>(
|
175
|
+
name: Key & keyof this["state"],
|
176
|
+
value: (this["state"] & Record<PropertyKey, unknown>)[Key]
|
177
|
+
): void;
|
178
|
+
setState(value: Partial<this["state"]>): void;
|
179
|
+
|
180
|
+
/** Schedules an update related to a specific state property and optionally updates the value. */
|
181
|
+
setStateDirty<Key extends PropertyKey>(
|
182
|
+
name: Key & keyof this["state"],
|
183
|
+
value?: (this["state"] & Record<PropertyKey, unknown>)[Key]
|
184
|
+
): void;
|
185
|
+
/** Synchronously flush any scheduled updates. */
|
186
|
+
update(): void;
|
187
|
+
/** Appends the dom for the current instance to a parent DOM element. */
|
188
|
+
appendTo(target: ParentNode): this;
|
189
|
+
/** Inserts the dom for the current instance after a sibling DOM element. */
|
190
|
+
insertAfter(target: ChildNode): this;
|
191
|
+
/** Inserts the dom for the current instance before a sibling DOM element. */
|
192
|
+
insertBefore(target: ChildNode): this;
|
193
|
+
/** Prepends the dom for the current instance to a parent DOM element. */
|
194
|
+
prependTo(target: ParentNode): this;
|
195
|
+
/** Replaces an existing DOM element with the dom for the current instance. */
|
196
|
+
replace(target: ChildNode): this;
|
197
|
+
/** Replaces the children of an existing DOM element with the dom for the current instance. */
|
198
|
+
replaceChildrenOf(target: ParentNode): this;
|
199
|
+
/** Called when the component is firsted created. */
|
200
|
+
onCreate?(input: this["input"], out: Marko.Out): void;
|
201
|
+
/** Called every time the component receives input from it's parent. */
|
202
|
+
onInput?(input: this["input"], out: Marko.Out): void | this["input"];
|
203
|
+
/** Called after a component has successfully rendered, but before it's update has been applied to the dom. */
|
204
|
+
onRender?(out: Marko.Out): void;
|
205
|
+
/** Called after the first time the component renders and is attached to the dom. */
|
206
|
+
onMount?(): void;
|
207
|
+
/** Called when a components render has been applied to the DOM (excluding when it is initially mounted). */
|
208
|
+
onUpdate?(): void;
|
209
|
+
/** Called when a component is destroyed and removed from the dom. */
|
210
|
+
onDestroy?(): void;
|
211
|
+
}
|
212
|
+
|
213
|
+
/** The top level api for a Marko Template. */
|
214
|
+
export abstract class Template {
|
215
|
+
/** Creates a Marko compatible output stream. */
|
216
|
+
createOut(): Out;
|
217
|
+
|
218
|
+
/**
|
219
|
+
* The folowing types are processed up by the @marko/language-tools
|
220
|
+
* and inlined into the compiled template.
|
221
|
+
*
|
222
|
+
* This is done to support generics on each of these methods
|
223
|
+
* until TypeScript supports higher kinded types.
|
224
|
+
*
|
225
|
+
* https://github.com/microsoft/TypeScript/issues/1213
|
226
|
+
*/
|
227
|
+
|
228
|
+
/** @marko-overload-start */
|
229
|
+
/** Asynchronously render the template. */
|
230
|
+
abstract render(
|
231
|
+
input: Marko.TemplateInput,
|
232
|
+
stream?: {
|
233
|
+
write: (chunk: string) => void;
|
234
|
+
end: (chunk?: string) => void;
|
235
|
+
}
|
236
|
+
): Marko.Out<Marko.Component>;
|
237
|
+
|
238
|
+
/** Synchronously render the template. */
|
239
|
+
abstract renderSync(
|
240
|
+
input: Marko.TemplateInput
|
241
|
+
): Marko.RenderResult<Marko.Component>;
|
242
|
+
|
243
|
+
/** Synchronously render a template to a string. */
|
244
|
+
abstract renderToString(input: Marko.TemplateInput): string;
|
245
|
+
|
246
|
+
/** Render a template and return a stream.Readable in nodejs or a ReadableStream in a web worker environment. */
|
247
|
+
abstract stream(
|
248
|
+
input: Marko.TemplateInput
|
249
|
+
): ReadableStream<string> & NodeJS.ReadableStream;
|
250
|
+
/** @marko-overload-end */
|
251
|
+
}
|
252
|
+
|
253
|
+
export interface RenderResult<
|
254
|
+
out Component extends Marko.Component = Marko.Component
|
255
|
+
> {
|
256
|
+
/** Returns the component created as a result of rendering the template. */
|
257
|
+
getComponent(): Component;
|
258
|
+
getComponents(selector?: any): any;
|
259
|
+
/** Triggers the mount lifecycle of a component without necessarily attaching it to the DOM. */
|
260
|
+
afterInsert(host?: any): this;
|
261
|
+
/** Gets the DOM node rendered by a template. */
|
262
|
+
getNode(host?: any): Node;
|
263
|
+
/** Gets the HTML output of the rendered template. */
|
264
|
+
toString(): string;
|
265
|
+
/** Appends the dom of the rendered template to a parent DOM element. */
|
266
|
+
appendTo(target: ParentNode): this;
|
267
|
+
/** Inserts the dom of the rendered template after a sibling DOM element. */
|
268
|
+
insertAfter(target: ChildNode): this;
|
269
|
+
/** Inserts the dom of the rendered template before a sibling DOM element. */
|
270
|
+
insertBefore(target: ChildNode): this;
|
271
|
+
/** Prepends the dom of the rendered template to a parent DOM element. */
|
272
|
+
prependTo(target: ParentNode): this;
|
273
|
+
/** Replaces an existing DOM element with the dom of the rendered template. */
|
274
|
+
replace(target: ChildNode): this;
|
275
|
+
/** Replaces the children of an existing DOM element with the dom of the rendered template. */
|
276
|
+
replaceChildrenOf(target: ParentNode): this;
|
277
|
+
out: Out<Component>;
|
278
|
+
/** @deprecated */
|
279
|
+
document: any;
|
280
|
+
/** @deprecated */
|
281
|
+
getOutput(): string;
|
282
|
+
/** @deprecated */
|
283
|
+
html: string;
|
284
|
+
/** @deprecated */
|
285
|
+
context: Out<Component>;
|
286
|
+
}
|
287
|
+
|
288
|
+
export interface Emitter {
|
289
|
+
listenerCount(eventName: PropertyKey): number;
|
290
|
+
emit(eventName: PropertyKey, ...args: any[]): boolean;
|
291
|
+
on(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
292
|
+
once(eventName: PropertyKey, listener: (...args: any[]) => any): this;
|
293
|
+
prependListener(
|
294
|
+
eventName: PropertyKey,
|
295
|
+
listener: (...args: any[]) => any
|
296
|
+
): this;
|
297
|
+
removeListener(
|
298
|
+
eventName: PropertyKey,
|
299
|
+
listener: (...args: any[]) => any
|
300
|
+
): this;
|
301
|
+
removeAllListeners(eventName?: PropertyKey): this;
|
302
|
+
}
|
303
|
+
|
304
|
+
export type Repeated<T> = [T, T, ...T[]];
|
305
|
+
export type Repeatable<T> = T | Repeated<T>;
|
306
|
+
export type MaybeRepeatable<T> = undefined | Repeatable<T>;
|
307
|
+
|
308
|
+
export interface NativeTags {
|
309
|
+
[name: string]: {
|
310
|
+
input: Record<string, unknown>;
|
311
|
+
return: unknown;
|
312
|
+
};
|
313
|
+
}
|
314
|
+
}
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "marko",
|
3
|
-
"version": "5.22.
|
3
|
+
"version": "5.22.5",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
|
6
6
|
"dependencies": {
|
7
|
-
"@marko/compiler": "^5.23.
|
8
|
-
"@marko/translator-default": "^5.22.
|
7
|
+
"@marko/compiler": "^5.23.5",
|
8
|
+
"@marko/translator-default": "^5.22.5",
|
9
9
|
"app-module-path": "^2.2.0",
|
10
10
|
"argly": "^1.2.0",
|
11
11
|
"browser-refresh-client": "1.1.4",
|
@@ -68,6 +68,7 @@
|
|
68
68
|
"components-browser.marko",
|
69
69
|
"components.js",
|
70
70
|
"env.js",
|
71
|
+
"index.d.ts",
|
71
72
|
"index-browser.marko",
|
72
73
|
"index.js",
|
73
74
|
"node-require.js"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
/**
|
2
2
|
* @template T
|
3
3
|
* @typedef {{
|
4
|
-
* value?: T;
|
5
|
-
* then?: Marko.Body<[Awaited<T>], void
|
6
|
-
* catch?: Marko.Body<[unknown], void
|
7
|
-
* placeholder?: Marko.Body<[], void
|
8
|
-
* client-reorder?: boolean;
|
4
|
+
* value?: readonly [T];
|
5
|
+
* then?: { renderBody: Marko.Body<[Awaited<T>], void> };
|
6
|
+
* catch?: { renderBody: Marko.Body<[unknown], void> };
|
7
|
+
* placeholder?: { renderBody: Marko.Body<[], void> };
|
8
|
+
* "client-reorder"?: boolean;
|
9
9
|
* name?: string;
|
10
10
|
* timeout?: number;
|
11
|
-
* show-after?: string;
|
11
|
+
* "show-after"?: string;
|
12
12
|
* }} Input
|
13
13
|
*/
|