vaderjs 2.3.5 → 2.3.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/config/index.ts +4 -1
- package/index.ts +66 -41
- package/main.js +7 -1
- package/package.json +1 -1
- package/plugins/index.ts +10 -1
package/config/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
type Config = {
|
|
1
|
+
export type Config = {
|
|
2
2
|
port: number,
|
|
3
3
|
host?: string,
|
|
4
|
+
plugin_config?: {
|
|
5
|
+
[key: string]: any
|
|
6
|
+
},
|
|
4
7
|
plugins?: any[],
|
|
5
8
|
generateTypes?: boolean,
|
|
6
9
|
host_provider?: 'vercel' | 'netlify' | 'aws' | 'gcp' | 'azure' | 'heroku' | 'custom' | 'apache' | 'none',
|
package/index.ts
CHANGED
|
@@ -346,29 +346,38 @@ function performUnitOfWork(fiber: Fiber): Fiber | null {
|
|
|
346
346
|
* Updates a function component fiber.
|
|
347
347
|
* @param {Fiber} fiber - The function component fiber to update.
|
|
348
348
|
*/
|
|
349
|
-
|
|
349
|
+
function updateFunctionComponent(fiber: Fiber) {
|
|
350
350
|
wipFiber = fiber;
|
|
351
351
|
hookIndex = 0;
|
|
352
352
|
fiber.hooks = fiber.alternate?.hooks || [];
|
|
353
353
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const children = [(fiber.type as Function)(fiber.props)]
|
|
357
|
-
.flat()
|
|
358
|
-
.filter(child => child != null && typeof child !== 'boolean')
|
|
359
|
-
.map(child => typeof child === 'object' ? child : createTextElement(child));
|
|
354
|
+
const rawChildren = (fiber.type as Function)(fiber.props);
|
|
355
|
+
const children = normalizeChildren(rawChildren, fiber);
|
|
360
356
|
|
|
361
357
|
reconcileChildren(fiber, children);
|
|
362
358
|
}
|
|
359
|
+
function normalizeChildren(children: any, parentFiber: Fiber): VNode[] {
|
|
360
|
+
if (!children) return [];
|
|
361
|
+
let arr = Array.isArray(children) ? children : [children];
|
|
362
|
+
|
|
363
|
+
return arr.flatMap((child, index) => {
|
|
364
|
+
if (child == null || typeof child === "boolean") return [];
|
|
365
|
+
if (typeof child === "string" || typeof child === "number") return [createTextElement(String(child))];
|
|
366
|
+
|
|
367
|
+
// Ensure every child has a stable key
|
|
368
|
+
const key = child.key ?? child.props?.id ?? `${parentFiber.key ?? "root"}-${index}`;
|
|
369
|
+
return [{ ...child, key }];
|
|
370
|
+
});
|
|
371
|
+
}
|
|
363
372
|
/**
|
|
364
373
|
* Updates a host component fiber (DOM element).
|
|
365
374
|
* @param {Fiber} fiber - The host component fiber to update.
|
|
366
375
|
*/
|
|
367
376
|
function updateHostComponent(fiber: Fiber): void {
|
|
368
|
-
if (!fiber.dom)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
reconcileChildren(fiber,
|
|
377
|
+
if (!fiber.dom) fiber.dom = createDom(fiber);
|
|
378
|
+
|
|
379
|
+
const children = normalizeChildren(fiber.props.children, fiber);
|
|
380
|
+
reconcileChildren(fiber, children);
|
|
372
381
|
}
|
|
373
382
|
|
|
374
383
|
/**
|
|
@@ -376,12 +385,11 @@ function updateHostComponent(fiber: Fiber): void {
|
|
|
376
385
|
* @param {Fiber} wipFiber - The work-in-progress fiber.
|
|
377
386
|
* @param {VNode[]} elements - The new child elements.
|
|
378
387
|
*/
|
|
379
|
-
|
|
388
|
+
function reconcileChildren(wipFiber: Fiber, elements: VNode[]) {
|
|
380
389
|
let index = 0;
|
|
381
390
|
let oldFiber = wipFiber.alternate?.child;
|
|
382
391
|
let prevSibling: Fiber | null = null;
|
|
383
|
-
|
|
384
|
-
// Create map of existing fibers by key
|
|
392
|
+
|
|
385
393
|
const existingFibers = new Map<string | number | null, Fiber>();
|
|
386
394
|
while (oldFiber) {
|
|
387
395
|
const key = oldFiber.key ?? index;
|
|
@@ -393,23 +401,21 @@ function updateHostComponent(fiber: Fiber): void {
|
|
|
393
401
|
index = 0;
|
|
394
402
|
for (; index < elements.length; index++) {
|
|
395
403
|
const element = elements[index];
|
|
396
|
-
const key = element
|
|
404
|
+
const key = element.key ?? index;
|
|
397
405
|
const oldFiber = existingFibers.get(key);
|
|
398
|
-
|
|
406
|
+
|
|
399
407
|
const sameType = oldFiber && element && element.type === oldFiber.type;
|
|
400
408
|
let newFiber: Fiber | null = null;
|
|
401
409
|
|
|
402
410
|
if (sameType) {
|
|
403
|
-
// Reuse
|
|
411
|
+
// Reuse old fiber for same type + key
|
|
404
412
|
newFiber = {
|
|
405
|
-
|
|
413
|
+
...oldFiber,
|
|
406
414
|
props: element.props,
|
|
407
|
-
dom: oldFiber.dom,
|
|
408
415
|
parent: wipFiber,
|
|
409
416
|
alternate: oldFiber,
|
|
410
417
|
effectTag: "UPDATE",
|
|
411
|
-
|
|
412
|
-
key
|
|
418
|
+
_needsUpdate: false,
|
|
413
419
|
};
|
|
414
420
|
existingFibers.delete(key);
|
|
415
421
|
} else if (element) {
|
|
@@ -421,7 +427,8 @@ function updateHostComponent(fiber: Fiber): void {
|
|
|
421
427
|
parent: wipFiber,
|
|
422
428
|
alternate: null,
|
|
423
429
|
effectTag: "PLACEMENT",
|
|
424
|
-
key
|
|
430
|
+
key,
|
|
431
|
+
_needsUpdate: true,
|
|
425
432
|
};
|
|
426
433
|
}
|
|
427
434
|
|
|
@@ -436,9 +443,7 @@ function updateHostComponent(fiber: Fiber): void {
|
|
|
436
443
|
prevSibling.sibling = newFiber;
|
|
437
444
|
}
|
|
438
445
|
|
|
439
|
-
if (newFiber)
|
|
440
|
-
prevSibling = newFiber;
|
|
441
|
-
}
|
|
446
|
+
if (newFiber) prevSibling = newFiber;
|
|
442
447
|
}
|
|
443
448
|
|
|
444
449
|
// Mark remaining old fibers for deletion
|
|
@@ -455,23 +460,17 @@ function updateHostComponent(fiber: Fiber): void {
|
|
|
455
460
|
* @param {...any} children - The element's children.
|
|
456
461
|
* @returns {VNode} The created virtual DOM element.
|
|
457
462
|
*/
|
|
458
|
-
export function createElement(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
)
|
|
463
|
+
export function createElement(type: string | Function, props?: any, ...children: any[]): VNode {
|
|
464
|
+
const rawChildren = children.flat().filter(c => c != null && typeof c !== "boolean");
|
|
465
|
+
const normalizedChildren = rawChildren.map((child, i) => {
|
|
466
|
+
if (typeof child === "object") return child;
|
|
467
|
+
return createTextElement(String(child));
|
|
468
|
+
});
|
|
469
|
+
|
|
463
470
|
return {
|
|
464
471
|
type,
|
|
465
|
-
props: {
|
|
466
|
-
|
|
467
|
-
children: children
|
|
468
|
-
.flat()
|
|
469
|
-
.filter(child => child != null && typeof child !== "boolean")
|
|
470
|
-
.map(child =>
|
|
471
|
-
typeof child === "object" ? child : createTextElement(child)
|
|
472
|
-
),
|
|
473
|
-
},
|
|
474
|
-
key: props?.key ?? null,
|
|
472
|
+
props: { ...props, children: normalizedChildren },
|
|
473
|
+
key: props?.key ?? props?.id ?? null,
|
|
475
474
|
};
|
|
476
475
|
}
|
|
477
476
|
|
|
@@ -598,10 +597,36 @@ export function Switch({ children }: { children: VNode[] }): VNode | null {
|
|
|
598
597
|
export function Match({ when, children }: { when: boolean, children: VNode[] }): VNode | null {
|
|
599
598
|
return when ? children : null;
|
|
600
599
|
}
|
|
601
|
-
|
|
600
|
+
/**
|
|
601
|
+
* Wraps a functional component into a VNode for Vader.js rendering.
|
|
602
|
+
* @param {Function} fn - The function component to wrap.
|
|
603
|
+
* @returns {Function} A function that creates a VNode when called with props.
|
|
604
|
+
*/
|
|
605
|
+
export function component<P extends object>(
|
|
606
|
+
fn: (props: P) => VNode | VNode[]
|
|
607
|
+
): (props: P & { key?: string | number }) => VNode {
|
|
608
|
+
return (props: P & { key?: string | number }) => {
|
|
609
|
+
return createElement(fn, props);
|
|
610
|
+
};
|
|
611
|
+
}
|
|
602
612
|
export function Show({ when, children }: { when: boolean, children: VNode[] }): VNode | null {
|
|
603
613
|
return when ? children : null;
|
|
604
614
|
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* For TypeScript to recognize your JSX factory,
|
|
618
|
+
* you often need the global namespace declaration as well:
|
|
619
|
+
*/
|
|
620
|
+
declare global {
|
|
621
|
+
namespace JSX {
|
|
622
|
+
interface IntrinsicElements {
|
|
623
|
+
[elemName: string]: any;
|
|
624
|
+
}
|
|
625
|
+
interface Element {
|
|
626
|
+
[key: string]: any;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
605
630
|
|
|
606
631
|
/**
|
|
607
632
|
* A React-like useRef hook for mutable references.
|
package/main.js
CHANGED
|
@@ -75,7 +75,13 @@ const vaderAPI = {
|
|
|
75
75
|
await p.exited;
|
|
76
76
|
},
|
|
77
77
|
injectHTML: (content) => htmlInjections.push(content),
|
|
78
|
-
log:
|
|
78
|
+
log: {
|
|
79
|
+
warn: (msg) => logger.warn(msg),
|
|
80
|
+
info: (msg) => logger.info(msg),
|
|
81
|
+
error: (msg) => logger.error(msg),
|
|
82
|
+
success: (msg) => logger.success(msg),
|
|
83
|
+
step: (msg) => logger.step(msg)
|
|
84
|
+
},
|
|
79
85
|
getProjectRoot: () => PROJECT_ROOT,
|
|
80
86
|
getDistDir: () => DIST_DIR,
|
|
81
87
|
getPublicDir: () => PUBLIC_DIR,
|
package/package.json
CHANGED
package/plugins/index.ts
CHANGED
|
@@ -9,7 +9,13 @@ export interface VaderAPI {
|
|
|
9
9
|
injectHTML(content: string): void;
|
|
10
10
|
|
|
11
11
|
/** Log a message prefixed with [Vader Plugin] */
|
|
12
|
-
log
|
|
12
|
+
log : {
|
|
13
|
+
warn: (msg: any) => void,
|
|
14
|
+
info: (msg: any) => void,
|
|
15
|
+
error: (msg: any) => void,
|
|
16
|
+
success: (msg: any) => void,
|
|
17
|
+
step: (msg: any) => void
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
/** Get absolute path to the project root */
|
|
15
21
|
getProjectRoot(): string;
|
|
@@ -33,6 +39,9 @@ export type PluginHookName =
|
|
|
33
39
|
|
|
34
40
|
/** Interface for a single plugin */
|
|
35
41
|
export interface VaderPlugin {
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
version: string;
|
|
36
45
|
/** Called before build starts */
|
|
37
46
|
onBuildStart?(api: VaderAPI): Promise<void> | void;
|
|
38
47
|
|