hadars 0.1.18 → 0.1.20
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/{chunk-TGSIYGY2.js → chunk-OS3V4CPN.js} +2 -0
- package/dist/cli.js +140 -19
- package/dist/slim-react/index.cjs +153 -23
- package/dist/slim-react/index.d.ts +2 -1
- package/dist/slim-react/index.js +152 -23
- package/dist/slim-react/jsx-runtime.cjs +1 -0
- package/dist/slim-react/jsx-runtime.js +1 -1
- package/dist/ssr-render-worker.js +140 -19
- package/package.json +2 -2
- package/src/slim-react/index.ts +8 -2
- package/src/slim-react/render.ts +204 -27
- package/src/slim-react/types.ts +9 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/slim-react/types.ts
|
|
2
2
|
var SLIM_ELEMENT = Symbol.for("react.element");
|
|
3
|
+
var REACT19_ELEMENT = Symbol.for("react.transitional.element");
|
|
3
4
|
var FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
4
5
|
var SUSPENSE_TYPE = Symbol.for("react.suspense");
|
|
5
6
|
|
|
@@ -32,6 +33,7 @@ function createElement(type, props, ...children) {
|
|
|
32
33
|
|
|
33
34
|
export {
|
|
34
35
|
SLIM_ELEMENT,
|
|
36
|
+
REACT19_ELEMENT,
|
|
35
37
|
FRAGMENT_TYPE,
|
|
36
38
|
SUSPENSE_TYPE,
|
|
37
39
|
Fragment,
|
package/dist/cli.js
CHANGED
|
@@ -136,6 +136,7 @@ var upgradeHandler = (options) => {
|
|
|
136
136
|
|
|
137
137
|
// src/slim-react/types.ts
|
|
138
138
|
var SLIM_ELEMENT = Symbol.for("react.element");
|
|
139
|
+
var REACT19_ELEMENT = Symbol.for("react.transitional.element");
|
|
139
140
|
var FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
140
141
|
var SUSPENSE_TYPE = Symbol.for("react.suspense");
|
|
141
142
|
|
|
@@ -233,7 +234,7 @@ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
233
234
|
"wbr"
|
|
234
235
|
]);
|
|
235
236
|
function escapeHtml(str) {
|
|
236
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
237
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
237
238
|
}
|
|
238
239
|
function escapeAttr(str) {
|
|
239
240
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
@@ -378,7 +379,7 @@ var SVG_ATTR_MAP = {
|
|
|
378
379
|
function renderAttributes(props, isSvg) {
|
|
379
380
|
let attrs = "";
|
|
380
381
|
for (const [key, value] of Object.entries(props)) {
|
|
381
|
-
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML")
|
|
382
|
+
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML" || key === "suppressHydrationWarning" || key === "suppressContentEditableWarning")
|
|
382
383
|
continue;
|
|
383
384
|
if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase())
|
|
384
385
|
continue;
|
|
@@ -386,12 +387,16 @@ function renderAttributes(props, isSvg) {
|
|
|
386
387
|
if (isSvg && key in SVG_ATTR_MAP) {
|
|
387
388
|
attrName = SVG_ATTR_MAP[key];
|
|
388
389
|
} else {
|
|
389
|
-
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key;
|
|
390
|
+
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
|
|
390
391
|
}
|
|
391
|
-
if (value === false || value == null)
|
|
392
|
+
if (value === false || value == null) {
|
|
393
|
+
if (value === false && (attrName.startsWith("aria-") || attrName.startsWith("data-"))) {
|
|
394
|
+
attrs += ` ${attrName}="false"`;
|
|
395
|
+
}
|
|
392
396
|
continue;
|
|
397
|
+
}
|
|
393
398
|
if (value === true) {
|
|
394
|
-
attrs += ` ${attrName}`;
|
|
399
|
+
attrs += ` ${attrName}=""`;
|
|
395
400
|
continue;
|
|
396
401
|
}
|
|
397
402
|
if (key === "style" && typeof value === "object") {
|
|
@@ -404,23 +409,30 @@ function renderAttributes(props, isSvg) {
|
|
|
404
409
|
}
|
|
405
410
|
var BufferWriter = class {
|
|
406
411
|
chunks = [];
|
|
412
|
+
lastWasText = false;
|
|
407
413
|
write(chunk) {
|
|
408
414
|
this.chunks.push(chunk);
|
|
415
|
+
this.lastWasText = false;
|
|
416
|
+
}
|
|
417
|
+
text(s2) {
|
|
418
|
+
this.chunks.push(s2);
|
|
419
|
+
this.lastWasText = true;
|
|
409
420
|
}
|
|
410
421
|
flush(target) {
|
|
411
422
|
for (const c of this.chunks)
|
|
412
423
|
target.write(c);
|
|
424
|
+
target.lastWasText = this.lastWasText;
|
|
413
425
|
}
|
|
414
426
|
};
|
|
415
427
|
function renderNode(node, writer, isSvg = false) {
|
|
416
428
|
if (node == null || typeof node === "boolean")
|
|
417
429
|
return;
|
|
418
430
|
if (typeof node === "string") {
|
|
419
|
-
writer.
|
|
431
|
+
writer.text(escapeHtml(node));
|
|
420
432
|
return;
|
|
421
433
|
}
|
|
422
434
|
if (typeof node === "number") {
|
|
423
|
-
writer.
|
|
435
|
+
writer.text(String(node));
|
|
424
436
|
return;
|
|
425
437
|
}
|
|
426
438
|
if (Array.isArray(node)) {
|
|
@@ -433,7 +445,10 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
433
445
|
isSvg
|
|
434
446
|
);
|
|
435
447
|
}
|
|
436
|
-
if (typeof node === "object" && node !== null && "$$typeof" in node
|
|
448
|
+
if (typeof node === "object" && node !== null && "$$typeof" in node) {
|
|
449
|
+
const elType = node["$$typeof"];
|
|
450
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
451
|
+
return;
|
|
437
452
|
const element = node;
|
|
438
453
|
const { type, props } = element;
|
|
439
454
|
if (type === FRAGMENT_TYPE) {
|
|
@@ -445,16 +460,79 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
445
460
|
if (typeof type === "function") {
|
|
446
461
|
return renderComponent(type, props, writer, isSvg);
|
|
447
462
|
}
|
|
463
|
+
if (typeof type === "object" && type !== null) {
|
|
464
|
+
return renderComponent(type, props, writer, isSvg);
|
|
465
|
+
}
|
|
448
466
|
if (typeof type === "string") {
|
|
449
467
|
return renderHostElement(type, props, writer, isSvg);
|
|
450
468
|
}
|
|
451
469
|
}
|
|
452
470
|
}
|
|
471
|
+
function markSelectedOptionsMulti(children, selectedValues) {
|
|
472
|
+
if (children == null || typeof children === "boolean")
|
|
473
|
+
return children;
|
|
474
|
+
if (typeof children === "string" || typeof children === "number")
|
|
475
|
+
return children;
|
|
476
|
+
if (Array.isArray(children)) {
|
|
477
|
+
return children.map((c) => markSelectedOptionsMulti(c, selectedValues));
|
|
478
|
+
}
|
|
479
|
+
if (typeof children === "object" && "$$typeof" in children) {
|
|
480
|
+
const elType = children["$$typeof"];
|
|
481
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
482
|
+
return children;
|
|
483
|
+
const el = children;
|
|
484
|
+
if (el.type === "option") {
|
|
485
|
+
const optValue = el.props.value !== void 0 ? el.props.value : el.props.children;
|
|
486
|
+
const isSelected = selectedValues.has(String(optValue));
|
|
487
|
+
return { ...el, props: { ...el.props, selected: isSelected || void 0 } };
|
|
488
|
+
}
|
|
489
|
+
if (el.type === "optgroup" || el.type === FRAGMENT_TYPE) {
|
|
490
|
+
const newChildren = markSelectedOptionsMulti(el.props.children, selectedValues);
|
|
491
|
+
return { ...el, props: { ...el.props, children: newChildren } };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return children;
|
|
495
|
+
}
|
|
453
496
|
function renderHostElement(tag, props, writer, isSvg) {
|
|
454
497
|
const enteringSvg = tag === "svg";
|
|
455
498
|
const childSvg = isSvg || enteringSvg;
|
|
456
|
-
|
|
457
|
-
|
|
499
|
+
if (tag === "textarea") {
|
|
500
|
+
const textContent = props.value ?? props.defaultValue ?? props.children ?? "";
|
|
501
|
+
const filteredProps = {};
|
|
502
|
+
for (const k of Object.keys(props)) {
|
|
503
|
+
if (k !== "value" && k !== "defaultValue" && k !== "children")
|
|
504
|
+
filteredProps[k] = props[k];
|
|
505
|
+
}
|
|
506
|
+
writer.write(`<textarea${renderAttributes(filteredProps, false)}>`);
|
|
507
|
+
writer.text(escapeHtml(String(textContent)));
|
|
508
|
+
writer.write("</textarea>");
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (tag === "select") {
|
|
512
|
+
const selectedValue = props.value ?? props.defaultValue;
|
|
513
|
+
const filteredProps = {};
|
|
514
|
+
for (const k of Object.keys(props)) {
|
|
515
|
+
if (k !== "value" && k !== "defaultValue")
|
|
516
|
+
filteredProps[k] = props[k];
|
|
517
|
+
}
|
|
518
|
+
writer.write(`<select${renderAttributes(filteredProps, false)}>`);
|
|
519
|
+
const selectedSet = selectedValue == null ? null : Array.isArray(selectedValue) ? new Set(selectedValue.map(String)) : /* @__PURE__ */ new Set([String(selectedValue)]);
|
|
520
|
+
const patchedChildren = selectedSet != null ? markSelectedOptionsMulti(props.children, selectedSet) : props.children;
|
|
521
|
+
const inner2 = renderChildren(patchedChildren, writer, false);
|
|
522
|
+
if (inner2 && typeof inner2.then === "function") {
|
|
523
|
+
return inner2.then(() => {
|
|
524
|
+
writer.write("</select>");
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
writer.write("</select>");
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
writer.write(`<${tag}${renderAttributes(props, childSvg)}`);
|
|
531
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
532
|
+
writer.write("/>");
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
writer.write(">");
|
|
458
536
|
const childContext = tag === "foreignObject" ? false : childSvg;
|
|
459
537
|
let inner = void 0;
|
|
460
538
|
if (props.dangerouslySetInnerHTML) {
|
|
@@ -464,17 +542,17 @@ function renderHostElement(tag, props, writer, isSvg) {
|
|
|
464
542
|
}
|
|
465
543
|
if (inner && typeof inner.then === "function") {
|
|
466
544
|
return inner.then(() => {
|
|
467
|
-
|
|
468
|
-
writer.write(`</${tag}>`);
|
|
545
|
+
writer.write(`</${tag}>`);
|
|
469
546
|
});
|
|
470
547
|
}
|
|
471
|
-
|
|
472
|
-
writer.write(`</${tag}>`);
|
|
548
|
+
writer.write(`</${tag}>`);
|
|
473
549
|
}
|
|
474
550
|
var REACT_MEMO = Symbol.for("react.memo");
|
|
475
551
|
var REACT_FORWARD_REF = Symbol.for("react.forward_ref");
|
|
476
552
|
var REACT_PROVIDER = Symbol.for("react.provider");
|
|
477
553
|
var REACT_CONTEXT = Symbol.for("react.context");
|
|
554
|
+
var REACT_CONSUMER = Symbol.for("react.consumer");
|
|
555
|
+
var REACT_LAZY = Symbol.for("react.lazy");
|
|
478
556
|
function renderComponent(type, props, writer, isSvg) {
|
|
479
557
|
const typeOf = type?.$$typeof;
|
|
480
558
|
if (typeOf === REACT_MEMO) {
|
|
@@ -487,6 +565,24 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
487
565
|
if (typeOf === REACT_FORWARD_REF) {
|
|
488
566
|
return renderComponent(type.render, props, writer, isSvg);
|
|
489
567
|
}
|
|
568
|
+
if (typeOf === REACT_LAZY) {
|
|
569
|
+
const resolved = type._init(type._payload);
|
|
570
|
+
const LazyComp = resolved?.default ?? resolved;
|
|
571
|
+
return renderComponent(LazyComp, props, writer, isSvg);
|
|
572
|
+
}
|
|
573
|
+
if (typeOf === REACT_CONSUMER) {
|
|
574
|
+
const ctx2 = type._context;
|
|
575
|
+
const value = ctx2?._currentValue;
|
|
576
|
+
const result2 = typeof props.children === "function" ? props.children(value) : null;
|
|
577
|
+
const savedScope2 = pushComponentScope();
|
|
578
|
+
const finish2 = () => popComponentScope(savedScope2);
|
|
579
|
+
const r2 = renderNode(result2, writer, isSvg);
|
|
580
|
+
if (r2 && typeof r2.then === "function") {
|
|
581
|
+
return r2.then(finish2);
|
|
582
|
+
}
|
|
583
|
+
finish2();
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
490
586
|
const isProvider = "_context" in type || typeOf === REACT_PROVIDER || typeOf === REACT_CONTEXT && "value" in props;
|
|
491
587
|
let prevCtxValue;
|
|
492
588
|
let ctx;
|
|
@@ -496,10 +592,27 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
496
592
|
ctx._currentValue = props.value;
|
|
497
593
|
}
|
|
498
594
|
const savedScope = pushComponentScope();
|
|
595
|
+
if (isProvider && typeof type !== "function") {
|
|
596
|
+
const finish2 = () => {
|
|
597
|
+
popComponentScope(savedScope);
|
|
598
|
+
ctx._currentValue = prevCtxValue;
|
|
599
|
+
};
|
|
600
|
+
const r2 = renderChildren(props.children, writer, isSvg);
|
|
601
|
+
if (r2 && typeof r2.then === "function") {
|
|
602
|
+
return r2.then(finish2);
|
|
603
|
+
}
|
|
604
|
+
finish2();
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
499
607
|
let result;
|
|
500
608
|
try {
|
|
501
609
|
if (type.prototype && typeof type.prototype.render === "function") {
|
|
502
610
|
const instance = new type(props);
|
|
611
|
+
if (typeof type.getDerivedStateFromProps === "function") {
|
|
612
|
+
const derived = type.getDerivedStateFromProps(props, instance.state ?? {});
|
|
613
|
+
if (derived != null)
|
|
614
|
+
instance.state = { ...instance.state ?? {}, ...derived };
|
|
615
|
+
}
|
|
503
616
|
result = instance.render();
|
|
504
617
|
} else {
|
|
505
618
|
result = type(props);
|
|
@@ -536,7 +649,7 @@ function isTextLike(node) {
|
|
|
536
649
|
function renderChildArray(children, writer, isSvg) {
|
|
537
650
|
const totalChildren = children.length;
|
|
538
651
|
for (let i = 0; i < totalChildren; i++) {
|
|
539
|
-
if (
|
|
652
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
540
653
|
writer.write("<!-- -->");
|
|
541
654
|
}
|
|
542
655
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -553,7 +666,7 @@ function renderChildArray(children, writer, isSvg) {
|
|
|
553
666
|
function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
554
667
|
const totalChildren = children.length;
|
|
555
668
|
for (let i = startIndex; i < totalChildren; i++) {
|
|
556
|
-
if (
|
|
669
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
557
670
|
writer.write("<!-- -->");
|
|
558
671
|
}
|
|
559
672
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -614,9 +727,17 @@ async function renderToString(element) {
|
|
|
614
727
|
for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
|
|
615
728
|
resetRenderState();
|
|
616
729
|
const chunks = [];
|
|
617
|
-
const writer = {
|
|
618
|
-
|
|
619
|
-
|
|
730
|
+
const writer = {
|
|
731
|
+
lastWasText: false,
|
|
732
|
+
write(c) {
|
|
733
|
+
chunks.push(c);
|
|
734
|
+
this.lastWasText = false;
|
|
735
|
+
},
|
|
736
|
+
text(s2) {
|
|
737
|
+
chunks.push(s2);
|
|
738
|
+
this.lastWasText = true;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
620
741
|
try {
|
|
621
742
|
const r = renderNode(element, writer);
|
|
622
743
|
if (r && typeof r.then === "function")
|
|
@@ -61,12 +61,14 @@ __export(slim_react_exports, {
|
|
|
61
61
|
useRef: () => useRef,
|
|
62
62
|
useState: () => useState,
|
|
63
63
|
useSyncExternalStore: () => useSyncExternalStore,
|
|
64
|
-
useTransition: () => useTransition
|
|
64
|
+
useTransition: () => useTransition,
|
|
65
|
+
version: () => version
|
|
65
66
|
});
|
|
66
67
|
module.exports = __toCommonJS(slim_react_exports);
|
|
67
68
|
|
|
68
69
|
// src/slim-react/types.ts
|
|
69
70
|
var SLIM_ELEMENT = Symbol.for("react.element");
|
|
71
|
+
var REACT19_ELEMENT = Symbol.for("react.transitional.element");
|
|
70
72
|
var FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
71
73
|
var SUSPENSE_TYPE = Symbol.for("react.suspense");
|
|
72
74
|
|
|
@@ -277,7 +279,7 @@ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
277
279
|
"wbr"
|
|
278
280
|
]);
|
|
279
281
|
function escapeHtml(str) {
|
|
280
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
282
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
281
283
|
}
|
|
282
284
|
function escapeAttr(str) {
|
|
283
285
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
@@ -422,7 +424,7 @@ var SVG_ATTR_MAP = {
|
|
|
422
424
|
function renderAttributes(props, isSvg) {
|
|
423
425
|
let attrs = "";
|
|
424
426
|
for (const [key, value] of Object.entries(props)) {
|
|
425
|
-
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML")
|
|
427
|
+
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML" || key === "suppressHydrationWarning" || key === "suppressContentEditableWarning")
|
|
426
428
|
continue;
|
|
427
429
|
if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase())
|
|
428
430
|
continue;
|
|
@@ -430,12 +432,16 @@ function renderAttributes(props, isSvg) {
|
|
|
430
432
|
if (isSvg && key in SVG_ATTR_MAP) {
|
|
431
433
|
attrName = SVG_ATTR_MAP[key];
|
|
432
434
|
} else {
|
|
433
|
-
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key;
|
|
435
|
+
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
|
|
434
436
|
}
|
|
435
|
-
if (value === false || value == null)
|
|
437
|
+
if (value === false || value == null) {
|
|
438
|
+
if (value === false && (attrName.startsWith("aria-") || attrName.startsWith("data-"))) {
|
|
439
|
+
attrs += ` ${attrName}="false"`;
|
|
440
|
+
}
|
|
436
441
|
continue;
|
|
442
|
+
}
|
|
437
443
|
if (value === true) {
|
|
438
|
-
attrs += ` ${attrName}`;
|
|
444
|
+
attrs += ` ${attrName}=""`;
|
|
439
445
|
continue;
|
|
440
446
|
}
|
|
441
447
|
if (key === "style" && typeof value === "object") {
|
|
@@ -448,23 +454,30 @@ function renderAttributes(props, isSvg) {
|
|
|
448
454
|
}
|
|
449
455
|
var BufferWriter = class {
|
|
450
456
|
chunks = [];
|
|
457
|
+
lastWasText = false;
|
|
451
458
|
write(chunk) {
|
|
452
459
|
this.chunks.push(chunk);
|
|
460
|
+
this.lastWasText = false;
|
|
461
|
+
}
|
|
462
|
+
text(s2) {
|
|
463
|
+
this.chunks.push(s2);
|
|
464
|
+
this.lastWasText = true;
|
|
453
465
|
}
|
|
454
466
|
flush(target) {
|
|
455
467
|
for (const c of this.chunks)
|
|
456
468
|
target.write(c);
|
|
469
|
+
target.lastWasText = this.lastWasText;
|
|
457
470
|
}
|
|
458
471
|
};
|
|
459
472
|
function renderNode(node, writer, isSvg = false) {
|
|
460
473
|
if (node == null || typeof node === "boolean")
|
|
461
474
|
return;
|
|
462
475
|
if (typeof node === "string") {
|
|
463
|
-
writer.
|
|
476
|
+
writer.text(escapeHtml(node));
|
|
464
477
|
return;
|
|
465
478
|
}
|
|
466
479
|
if (typeof node === "number") {
|
|
467
|
-
writer.
|
|
480
|
+
writer.text(String(node));
|
|
468
481
|
return;
|
|
469
482
|
}
|
|
470
483
|
if (Array.isArray(node)) {
|
|
@@ -477,7 +490,10 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
477
490
|
isSvg
|
|
478
491
|
);
|
|
479
492
|
}
|
|
480
|
-
if (typeof node === "object" && node !== null && "$$typeof" in node
|
|
493
|
+
if (typeof node === "object" && node !== null && "$$typeof" in node) {
|
|
494
|
+
const elType = node["$$typeof"];
|
|
495
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
496
|
+
return;
|
|
481
497
|
const element = node;
|
|
482
498
|
const { type, props } = element;
|
|
483
499
|
if (type === FRAGMENT_TYPE) {
|
|
@@ -489,16 +505,79 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
489
505
|
if (typeof type === "function") {
|
|
490
506
|
return renderComponent(type, props, writer, isSvg);
|
|
491
507
|
}
|
|
508
|
+
if (typeof type === "object" && type !== null) {
|
|
509
|
+
return renderComponent(type, props, writer, isSvg);
|
|
510
|
+
}
|
|
492
511
|
if (typeof type === "string") {
|
|
493
512
|
return renderHostElement(type, props, writer, isSvg);
|
|
494
513
|
}
|
|
495
514
|
}
|
|
496
515
|
}
|
|
516
|
+
function markSelectedOptionsMulti(children, selectedValues) {
|
|
517
|
+
if (children == null || typeof children === "boolean")
|
|
518
|
+
return children;
|
|
519
|
+
if (typeof children === "string" || typeof children === "number")
|
|
520
|
+
return children;
|
|
521
|
+
if (Array.isArray(children)) {
|
|
522
|
+
return children.map((c) => markSelectedOptionsMulti(c, selectedValues));
|
|
523
|
+
}
|
|
524
|
+
if (typeof children === "object" && "$$typeof" in children) {
|
|
525
|
+
const elType = children["$$typeof"];
|
|
526
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
527
|
+
return children;
|
|
528
|
+
const el = children;
|
|
529
|
+
if (el.type === "option") {
|
|
530
|
+
const optValue = el.props.value !== void 0 ? el.props.value : el.props.children;
|
|
531
|
+
const isSelected = selectedValues.has(String(optValue));
|
|
532
|
+
return { ...el, props: { ...el.props, selected: isSelected || void 0 } };
|
|
533
|
+
}
|
|
534
|
+
if (el.type === "optgroup" || el.type === FRAGMENT_TYPE) {
|
|
535
|
+
const newChildren = markSelectedOptionsMulti(el.props.children, selectedValues);
|
|
536
|
+
return { ...el, props: { ...el.props, children: newChildren } };
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return children;
|
|
540
|
+
}
|
|
497
541
|
function renderHostElement(tag, props, writer, isSvg) {
|
|
498
542
|
const enteringSvg = tag === "svg";
|
|
499
543
|
const childSvg = isSvg || enteringSvg;
|
|
500
|
-
|
|
501
|
-
|
|
544
|
+
if (tag === "textarea") {
|
|
545
|
+
const textContent = props.value ?? props.defaultValue ?? props.children ?? "";
|
|
546
|
+
const filteredProps = {};
|
|
547
|
+
for (const k of Object.keys(props)) {
|
|
548
|
+
if (k !== "value" && k !== "defaultValue" && k !== "children")
|
|
549
|
+
filteredProps[k] = props[k];
|
|
550
|
+
}
|
|
551
|
+
writer.write(`<textarea${renderAttributes(filteredProps, false)}>`);
|
|
552
|
+
writer.text(escapeHtml(String(textContent)));
|
|
553
|
+
writer.write("</textarea>");
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (tag === "select") {
|
|
557
|
+
const selectedValue = props.value ?? props.defaultValue;
|
|
558
|
+
const filteredProps = {};
|
|
559
|
+
for (const k of Object.keys(props)) {
|
|
560
|
+
if (k !== "value" && k !== "defaultValue")
|
|
561
|
+
filteredProps[k] = props[k];
|
|
562
|
+
}
|
|
563
|
+
writer.write(`<select${renderAttributes(filteredProps, false)}>`);
|
|
564
|
+
const selectedSet = selectedValue == null ? null : Array.isArray(selectedValue) ? new Set(selectedValue.map(String)) : /* @__PURE__ */ new Set([String(selectedValue)]);
|
|
565
|
+
const patchedChildren = selectedSet != null ? markSelectedOptionsMulti(props.children, selectedSet) : props.children;
|
|
566
|
+
const inner2 = renderChildren(patchedChildren, writer, false);
|
|
567
|
+
if (inner2 && typeof inner2.then === "function") {
|
|
568
|
+
return inner2.then(() => {
|
|
569
|
+
writer.write("</select>");
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
writer.write("</select>");
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
writer.write(`<${tag}${renderAttributes(props, childSvg)}`);
|
|
576
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
577
|
+
writer.write("/>");
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
writer.write(">");
|
|
502
581
|
const childContext = tag === "foreignObject" ? false : childSvg;
|
|
503
582
|
let inner = void 0;
|
|
504
583
|
if (props.dangerouslySetInnerHTML) {
|
|
@@ -508,17 +587,17 @@ function renderHostElement(tag, props, writer, isSvg) {
|
|
|
508
587
|
}
|
|
509
588
|
if (inner && typeof inner.then === "function") {
|
|
510
589
|
return inner.then(() => {
|
|
511
|
-
|
|
512
|
-
writer.write(`</${tag}>`);
|
|
590
|
+
writer.write(`</${tag}>`);
|
|
513
591
|
});
|
|
514
592
|
}
|
|
515
|
-
|
|
516
|
-
writer.write(`</${tag}>`);
|
|
593
|
+
writer.write(`</${tag}>`);
|
|
517
594
|
}
|
|
518
595
|
var REACT_MEMO = Symbol.for("react.memo");
|
|
519
596
|
var REACT_FORWARD_REF = Symbol.for("react.forward_ref");
|
|
520
597
|
var REACT_PROVIDER = Symbol.for("react.provider");
|
|
521
598
|
var REACT_CONTEXT = Symbol.for("react.context");
|
|
599
|
+
var REACT_CONSUMER = Symbol.for("react.consumer");
|
|
600
|
+
var REACT_LAZY = Symbol.for("react.lazy");
|
|
522
601
|
function renderComponent(type, props, writer, isSvg) {
|
|
523
602
|
const typeOf = type?.$$typeof;
|
|
524
603
|
if (typeOf === REACT_MEMO) {
|
|
@@ -531,6 +610,24 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
531
610
|
if (typeOf === REACT_FORWARD_REF) {
|
|
532
611
|
return renderComponent(type.render, props, writer, isSvg);
|
|
533
612
|
}
|
|
613
|
+
if (typeOf === REACT_LAZY) {
|
|
614
|
+
const resolved = type._init(type._payload);
|
|
615
|
+
const LazyComp = resolved?.default ?? resolved;
|
|
616
|
+
return renderComponent(LazyComp, props, writer, isSvg);
|
|
617
|
+
}
|
|
618
|
+
if (typeOf === REACT_CONSUMER) {
|
|
619
|
+
const ctx2 = type._context;
|
|
620
|
+
const value = ctx2?._currentValue;
|
|
621
|
+
const result2 = typeof props.children === "function" ? props.children(value) : null;
|
|
622
|
+
const savedScope2 = pushComponentScope();
|
|
623
|
+
const finish2 = () => popComponentScope(savedScope2);
|
|
624
|
+
const r2 = renderNode(result2, writer, isSvg);
|
|
625
|
+
if (r2 && typeof r2.then === "function") {
|
|
626
|
+
return r2.then(finish2);
|
|
627
|
+
}
|
|
628
|
+
finish2();
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
534
631
|
const isProvider = "_context" in type || typeOf === REACT_PROVIDER || typeOf === REACT_CONTEXT && "value" in props;
|
|
535
632
|
let prevCtxValue;
|
|
536
633
|
let ctx;
|
|
@@ -540,10 +637,27 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
540
637
|
ctx._currentValue = props.value;
|
|
541
638
|
}
|
|
542
639
|
const savedScope = pushComponentScope();
|
|
640
|
+
if (isProvider && typeof type !== "function") {
|
|
641
|
+
const finish2 = () => {
|
|
642
|
+
popComponentScope(savedScope);
|
|
643
|
+
ctx._currentValue = prevCtxValue;
|
|
644
|
+
};
|
|
645
|
+
const r2 = renderChildren(props.children, writer, isSvg);
|
|
646
|
+
if (r2 && typeof r2.then === "function") {
|
|
647
|
+
return r2.then(finish2);
|
|
648
|
+
}
|
|
649
|
+
finish2();
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
543
652
|
let result;
|
|
544
653
|
try {
|
|
545
654
|
if (type.prototype && typeof type.prototype.render === "function") {
|
|
546
655
|
const instance = new type(props);
|
|
656
|
+
if (typeof type.getDerivedStateFromProps === "function") {
|
|
657
|
+
const derived = type.getDerivedStateFromProps(props, instance.state ?? {});
|
|
658
|
+
if (derived != null)
|
|
659
|
+
instance.state = { ...instance.state ?? {}, ...derived };
|
|
660
|
+
}
|
|
547
661
|
result = instance.render();
|
|
548
662
|
} else {
|
|
549
663
|
result = type(props);
|
|
@@ -580,7 +694,7 @@ function isTextLike(node) {
|
|
|
580
694
|
function renderChildArray(children, writer, isSvg) {
|
|
581
695
|
const totalChildren = children.length;
|
|
582
696
|
for (let i = 0; i < totalChildren; i++) {
|
|
583
|
-
if (
|
|
697
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
584
698
|
writer.write("<!-- -->");
|
|
585
699
|
}
|
|
586
700
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -597,7 +711,7 @@ function renderChildArray(children, writer, isSvg) {
|
|
|
597
711
|
function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
598
712
|
const totalChildren = children.length;
|
|
599
713
|
for (let i = startIndex; i < totalChildren; i++) {
|
|
600
|
-
if (
|
|
714
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
601
715
|
writer.write("<!-- -->");
|
|
602
716
|
}
|
|
603
717
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -660,8 +774,14 @@ function renderToStream(element) {
|
|
|
660
774
|
async start(controller) {
|
|
661
775
|
resetRenderState();
|
|
662
776
|
const writer = {
|
|
777
|
+
lastWasText: false,
|
|
663
778
|
write(chunk) {
|
|
664
779
|
controller.enqueue(encoder.encode(chunk));
|
|
780
|
+
this.lastWasText = false;
|
|
781
|
+
},
|
|
782
|
+
text(s2) {
|
|
783
|
+
controller.enqueue(encoder.encode(s2));
|
|
784
|
+
this.lastWasText = true;
|
|
665
785
|
}
|
|
666
786
|
};
|
|
667
787
|
try {
|
|
@@ -679,9 +799,17 @@ async function renderToString(element) {
|
|
|
679
799
|
for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
|
|
680
800
|
resetRenderState();
|
|
681
801
|
const chunks = [];
|
|
682
|
-
const writer = {
|
|
683
|
-
|
|
684
|
-
|
|
802
|
+
const writer = {
|
|
803
|
+
lastWasText: false,
|
|
804
|
+
write(c) {
|
|
805
|
+
chunks.push(c);
|
|
806
|
+
this.lastWasText = false;
|
|
807
|
+
},
|
|
808
|
+
text(s2) {
|
|
809
|
+
chunks.push(s2);
|
|
810
|
+
this.lastWasText = true;
|
|
811
|
+
}
|
|
812
|
+
};
|
|
685
813
|
try {
|
|
686
814
|
const r = renderNode(element, writer);
|
|
687
815
|
if (r && typeof r.then === "function")
|
|
@@ -783,6 +911,7 @@ var Component = class {
|
|
|
783
911
|
};
|
|
784
912
|
var PureComponent = class extends Component {
|
|
785
913
|
};
|
|
914
|
+
var version = "19.1.1";
|
|
786
915
|
var React = {
|
|
787
916
|
// Hooks
|
|
788
917
|
useState,
|
|
@@ -824,8 +953,8 @@ var React = {
|
|
|
824
953
|
renderToStream,
|
|
825
954
|
renderToString,
|
|
826
955
|
renderToReadableStream: renderToStream,
|
|
827
|
-
// Version
|
|
828
|
-
version
|
|
956
|
+
// Version
|
|
957
|
+
version
|
|
829
958
|
};
|
|
830
959
|
var slim_react_default = React;
|
|
831
960
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -870,5 +999,6 @@ var slim_react_default = React;
|
|
|
870
999
|
useRef,
|
|
871
1000
|
useState,
|
|
872
1001
|
useSyncExternalStore,
|
|
873
|
-
useTransition
|
|
1002
|
+
useTransition,
|
|
1003
|
+
version
|
|
874
1004
|
});
|
|
@@ -132,6 +132,7 @@ declare class Component<P = {}, S = {}> {
|
|
|
132
132
|
}
|
|
133
133
|
declare class PureComponent<P = {}, S = {}> extends Component<P, S> {
|
|
134
134
|
}
|
|
135
|
+
declare const version = "19.1.1";
|
|
135
136
|
declare const React: {
|
|
136
137
|
useState: typeof useState;
|
|
137
138
|
useReducer: typeof useReducer;
|
|
@@ -177,4 +178,4 @@ declare const React: {
|
|
|
177
178
|
version: string;
|
|
178
179
|
};
|
|
179
180
|
|
|
180
|
-
export { Children, Component, Context, PureComponent, SlimElement, SlimNode, Suspense, cloneElement, createContext, createElement, React as default, forwardRef, isValidElement, lazy, memo, renderToStream as renderToReadableStream, renderToStream, renderToString, startTransition, use, useActionState, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useFormStatus, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
|
181
|
+
export { Children, Component, Context, PureComponent, SlimElement, SlimNode, Suspense, cloneElement, createContext, createElement, React as default, forwardRef, isValidElement, lazy, memo, renderToStream as renderToReadableStream, renderToStream, renderToString, startTransition, use, useActionState, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useFormStatus, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition, version };
|