hadars 0.1.18 → 0.1.19
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 +146 -19
- package/dist/slim-react/index.js +147 -20
- 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/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")
|
|
@@ -67,6 +67,7 @@ module.exports = __toCommonJS(slim_react_exports);
|
|
|
67
67
|
|
|
68
68
|
// src/slim-react/types.ts
|
|
69
69
|
var SLIM_ELEMENT = Symbol.for("react.element");
|
|
70
|
+
var REACT19_ELEMENT = Symbol.for("react.transitional.element");
|
|
70
71
|
var FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
71
72
|
var SUSPENSE_TYPE = Symbol.for("react.suspense");
|
|
72
73
|
|
|
@@ -277,7 +278,7 @@ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
277
278
|
"wbr"
|
|
278
279
|
]);
|
|
279
280
|
function escapeHtml(str) {
|
|
280
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
281
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
281
282
|
}
|
|
282
283
|
function escapeAttr(str) {
|
|
283
284
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
@@ -422,7 +423,7 @@ var SVG_ATTR_MAP = {
|
|
|
422
423
|
function renderAttributes(props, isSvg) {
|
|
423
424
|
let attrs = "";
|
|
424
425
|
for (const [key, value] of Object.entries(props)) {
|
|
425
|
-
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML")
|
|
426
|
+
if (key === "children" || key === "key" || key === "ref" || key === "dangerouslySetInnerHTML" || key === "suppressHydrationWarning" || key === "suppressContentEditableWarning")
|
|
426
427
|
continue;
|
|
427
428
|
if (key.startsWith("on") && key.length > 2 && key[2] === key[2].toUpperCase())
|
|
428
429
|
continue;
|
|
@@ -430,12 +431,16 @@ function renderAttributes(props, isSvg) {
|
|
|
430
431
|
if (isSvg && key in SVG_ATTR_MAP) {
|
|
431
432
|
attrName = SVG_ATTR_MAP[key];
|
|
432
433
|
} else {
|
|
433
|
-
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key;
|
|
434
|
+
attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
|
|
434
435
|
}
|
|
435
|
-
if (value === false || value == null)
|
|
436
|
+
if (value === false || value == null) {
|
|
437
|
+
if (value === false && (attrName.startsWith("aria-") || attrName.startsWith("data-"))) {
|
|
438
|
+
attrs += ` ${attrName}="false"`;
|
|
439
|
+
}
|
|
436
440
|
continue;
|
|
441
|
+
}
|
|
437
442
|
if (value === true) {
|
|
438
|
-
attrs += ` ${attrName}`;
|
|
443
|
+
attrs += ` ${attrName}=""`;
|
|
439
444
|
continue;
|
|
440
445
|
}
|
|
441
446
|
if (key === "style" && typeof value === "object") {
|
|
@@ -448,23 +453,30 @@ function renderAttributes(props, isSvg) {
|
|
|
448
453
|
}
|
|
449
454
|
var BufferWriter = class {
|
|
450
455
|
chunks = [];
|
|
456
|
+
lastWasText = false;
|
|
451
457
|
write(chunk) {
|
|
452
458
|
this.chunks.push(chunk);
|
|
459
|
+
this.lastWasText = false;
|
|
460
|
+
}
|
|
461
|
+
text(s2) {
|
|
462
|
+
this.chunks.push(s2);
|
|
463
|
+
this.lastWasText = true;
|
|
453
464
|
}
|
|
454
465
|
flush(target) {
|
|
455
466
|
for (const c of this.chunks)
|
|
456
467
|
target.write(c);
|
|
468
|
+
target.lastWasText = this.lastWasText;
|
|
457
469
|
}
|
|
458
470
|
};
|
|
459
471
|
function renderNode(node, writer, isSvg = false) {
|
|
460
472
|
if (node == null || typeof node === "boolean")
|
|
461
473
|
return;
|
|
462
474
|
if (typeof node === "string") {
|
|
463
|
-
writer.
|
|
475
|
+
writer.text(escapeHtml(node));
|
|
464
476
|
return;
|
|
465
477
|
}
|
|
466
478
|
if (typeof node === "number") {
|
|
467
|
-
writer.
|
|
479
|
+
writer.text(String(node));
|
|
468
480
|
return;
|
|
469
481
|
}
|
|
470
482
|
if (Array.isArray(node)) {
|
|
@@ -477,7 +489,10 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
477
489
|
isSvg
|
|
478
490
|
);
|
|
479
491
|
}
|
|
480
|
-
if (typeof node === "object" && node !== null && "$$typeof" in node
|
|
492
|
+
if (typeof node === "object" && node !== null && "$$typeof" in node) {
|
|
493
|
+
const elType = node["$$typeof"];
|
|
494
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
495
|
+
return;
|
|
481
496
|
const element = node;
|
|
482
497
|
const { type, props } = element;
|
|
483
498
|
if (type === FRAGMENT_TYPE) {
|
|
@@ -489,16 +504,79 @@ function renderNode(node, writer, isSvg = false) {
|
|
|
489
504
|
if (typeof type === "function") {
|
|
490
505
|
return renderComponent(type, props, writer, isSvg);
|
|
491
506
|
}
|
|
507
|
+
if (typeof type === "object" && type !== null) {
|
|
508
|
+
return renderComponent(type, props, writer, isSvg);
|
|
509
|
+
}
|
|
492
510
|
if (typeof type === "string") {
|
|
493
511
|
return renderHostElement(type, props, writer, isSvg);
|
|
494
512
|
}
|
|
495
513
|
}
|
|
496
514
|
}
|
|
515
|
+
function markSelectedOptionsMulti(children, selectedValues) {
|
|
516
|
+
if (children == null || typeof children === "boolean")
|
|
517
|
+
return children;
|
|
518
|
+
if (typeof children === "string" || typeof children === "number")
|
|
519
|
+
return children;
|
|
520
|
+
if (Array.isArray(children)) {
|
|
521
|
+
return children.map((c) => markSelectedOptionsMulti(c, selectedValues));
|
|
522
|
+
}
|
|
523
|
+
if (typeof children === "object" && "$$typeof" in children) {
|
|
524
|
+
const elType = children["$$typeof"];
|
|
525
|
+
if (elType !== SLIM_ELEMENT && elType !== REACT19_ELEMENT)
|
|
526
|
+
return children;
|
|
527
|
+
const el = children;
|
|
528
|
+
if (el.type === "option") {
|
|
529
|
+
const optValue = el.props.value !== void 0 ? el.props.value : el.props.children;
|
|
530
|
+
const isSelected = selectedValues.has(String(optValue));
|
|
531
|
+
return { ...el, props: { ...el.props, selected: isSelected || void 0 } };
|
|
532
|
+
}
|
|
533
|
+
if (el.type === "optgroup" || el.type === FRAGMENT_TYPE) {
|
|
534
|
+
const newChildren = markSelectedOptionsMulti(el.props.children, selectedValues);
|
|
535
|
+
return { ...el, props: { ...el.props, children: newChildren } };
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return children;
|
|
539
|
+
}
|
|
497
540
|
function renderHostElement(tag, props, writer, isSvg) {
|
|
498
541
|
const enteringSvg = tag === "svg";
|
|
499
542
|
const childSvg = isSvg || enteringSvg;
|
|
500
|
-
|
|
501
|
-
|
|
543
|
+
if (tag === "textarea") {
|
|
544
|
+
const textContent = props.value ?? props.defaultValue ?? props.children ?? "";
|
|
545
|
+
const filteredProps = {};
|
|
546
|
+
for (const k of Object.keys(props)) {
|
|
547
|
+
if (k !== "value" && k !== "defaultValue" && k !== "children")
|
|
548
|
+
filteredProps[k] = props[k];
|
|
549
|
+
}
|
|
550
|
+
writer.write(`<textarea${renderAttributes(filteredProps, false)}>`);
|
|
551
|
+
writer.text(escapeHtml(String(textContent)));
|
|
552
|
+
writer.write("</textarea>");
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (tag === "select") {
|
|
556
|
+
const selectedValue = props.value ?? props.defaultValue;
|
|
557
|
+
const filteredProps = {};
|
|
558
|
+
for (const k of Object.keys(props)) {
|
|
559
|
+
if (k !== "value" && k !== "defaultValue")
|
|
560
|
+
filteredProps[k] = props[k];
|
|
561
|
+
}
|
|
562
|
+
writer.write(`<select${renderAttributes(filteredProps, false)}>`);
|
|
563
|
+
const selectedSet = selectedValue == null ? null : Array.isArray(selectedValue) ? new Set(selectedValue.map(String)) : /* @__PURE__ */ new Set([String(selectedValue)]);
|
|
564
|
+
const patchedChildren = selectedSet != null ? markSelectedOptionsMulti(props.children, selectedSet) : props.children;
|
|
565
|
+
const inner2 = renderChildren(patchedChildren, writer, false);
|
|
566
|
+
if (inner2 && typeof inner2.then === "function") {
|
|
567
|
+
return inner2.then(() => {
|
|
568
|
+
writer.write("</select>");
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
writer.write("</select>");
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
writer.write(`<${tag}${renderAttributes(props, childSvg)}`);
|
|
575
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
576
|
+
writer.write("/>");
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
writer.write(">");
|
|
502
580
|
const childContext = tag === "foreignObject" ? false : childSvg;
|
|
503
581
|
let inner = void 0;
|
|
504
582
|
if (props.dangerouslySetInnerHTML) {
|
|
@@ -508,17 +586,17 @@ function renderHostElement(tag, props, writer, isSvg) {
|
|
|
508
586
|
}
|
|
509
587
|
if (inner && typeof inner.then === "function") {
|
|
510
588
|
return inner.then(() => {
|
|
511
|
-
|
|
512
|
-
writer.write(`</${tag}>`);
|
|
589
|
+
writer.write(`</${tag}>`);
|
|
513
590
|
});
|
|
514
591
|
}
|
|
515
|
-
|
|
516
|
-
writer.write(`</${tag}>`);
|
|
592
|
+
writer.write(`</${tag}>`);
|
|
517
593
|
}
|
|
518
594
|
var REACT_MEMO = Symbol.for("react.memo");
|
|
519
595
|
var REACT_FORWARD_REF = Symbol.for("react.forward_ref");
|
|
520
596
|
var REACT_PROVIDER = Symbol.for("react.provider");
|
|
521
597
|
var REACT_CONTEXT = Symbol.for("react.context");
|
|
598
|
+
var REACT_CONSUMER = Symbol.for("react.consumer");
|
|
599
|
+
var REACT_LAZY = Symbol.for("react.lazy");
|
|
522
600
|
function renderComponent(type, props, writer, isSvg) {
|
|
523
601
|
const typeOf = type?.$$typeof;
|
|
524
602
|
if (typeOf === REACT_MEMO) {
|
|
@@ -531,6 +609,24 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
531
609
|
if (typeOf === REACT_FORWARD_REF) {
|
|
532
610
|
return renderComponent(type.render, props, writer, isSvg);
|
|
533
611
|
}
|
|
612
|
+
if (typeOf === REACT_LAZY) {
|
|
613
|
+
const resolved = type._init(type._payload);
|
|
614
|
+
const LazyComp = resolved?.default ?? resolved;
|
|
615
|
+
return renderComponent(LazyComp, props, writer, isSvg);
|
|
616
|
+
}
|
|
617
|
+
if (typeOf === REACT_CONSUMER) {
|
|
618
|
+
const ctx2 = type._context;
|
|
619
|
+
const value = ctx2?._currentValue;
|
|
620
|
+
const result2 = typeof props.children === "function" ? props.children(value) : null;
|
|
621
|
+
const savedScope2 = pushComponentScope();
|
|
622
|
+
const finish2 = () => popComponentScope(savedScope2);
|
|
623
|
+
const r2 = renderNode(result2, writer, isSvg);
|
|
624
|
+
if (r2 && typeof r2.then === "function") {
|
|
625
|
+
return r2.then(finish2);
|
|
626
|
+
}
|
|
627
|
+
finish2();
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
534
630
|
const isProvider = "_context" in type || typeOf === REACT_PROVIDER || typeOf === REACT_CONTEXT && "value" in props;
|
|
535
631
|
let prevCtxValue;
|
|
536
632
|
let ctx;
|
|
@@ -540,10 +636,27 @@ function renderComponent(type, props, writer, isSvg) {
|
|
|
540
636
|
ctx._currentValue = props.value;
|
|
541
637
|
}
|
|
542
638
|
const savedScope = pushComponentScope();
|
|
639
|
+
if (isProvider && typeof type !== "function") {
|
|
640
|
+
const finish2 = () => {
|
|
641
|
+
popComponentScope(savedScope);
|
|
642
|
+
ctx._currentValue = prevCtxValue;
|
|
643
|
+
};
|
|
644
|
+
const r2 = renderChildren(props.children, writer, isSvg);
|
|
645
|
+
if (r2 && typeof r2.then === "function") {
|
|
646
|
+
return r2.then(finish2);
|
|
647
|
+
}
|
|
648
|
+
finish2();
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
543
651
|
let result;
|
|
544
652
|
try {
|
|
545
653
|
if (type.prototype && typeof type.prototype.render === "function") {
|
|
546
654
|
const instance = new type(props);
|
|
655
|
+
if (typeof type.getDerivedStateFromProps === "function") {
|
|
656
|
+
const derived = type.getDerivedStateFromProps(props, instance.state ?? {});
|
|
657
|
+
if (derived != null)
|
|
658
|
+
instance.state = { ...instance.state ?? {}, ...derived };
|
|
659
|
+
}
|
|
547
660
|
result = instance.render();
|
|
548
661
|
} else {
|
|
549
662
|
result = type(props);
|
|
@@ -580,7 +693,7 @@ function isTextLike(node) {
|
|
|
580
693
|
function renderChildArray(children, writer, isSvg) {
|
|
581
694
|
const totalChildren = children.length;
|
|
582
695
|
for (let i = 0; i < totalChildren; i++) {
|
|
583
|
-
if (
|
|
696
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
584
697
|
writer.write("<!-- -->");
|
|
585
698
|
}
|
|
586
699
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -597,7 +710,7 @@ function renderChildArray(children, writer, isSvg) {
|
|
|
597
710
|
function renderChildArrayFrom(children, startIndex, writer, isSvg) {
|
|
598
711
|
const totalChildren = children.length;
|
|
599
712
|
for (let i = startIndex; i < totalChildren; i++) {
|
|
600
|
-
if (
|
|
713
|
+
if (isTextLike(children[i]) && writer.lastWasText) {
|
|
601
714
|
writer.write("<!-- -->");
|
|
602
715
|
}
|
|
603
716
|
const savedTree = pushTreeContext(totalChildren, i);
|
|
@@ -660,8 +773,14 @@ function renderToStream(element) {
|
|
|
660
773
|
async start(controller) {
|
|
661
774
|
resetRenderState();
|
|
662
775
|
const writer = {
|
|
776
|
+
lastWasText: false,
|
|
663
777
|
write(chunk) {
|
|
664
778
|
controller.enqueue(encoder.encode(chunk));
|
|
779
|
+
this.lastWasText = false;
|
|
780
|
+
},
|
|
781
|
+
text(s2) {
|
|
782
|
+
controller.enqueue(encoder.encode(s2));
|
|
783
|
+
this.lastWasText = true;
|
|
665
784
|
}
|
|
666
785
|
};
|
|
667
786
|
try {
|
|
@@ -679,9 +798,17 @@ async function renderToString(element) {
|
|
|
679
798
|
for (let attempt = 0; attempt < MAX_SUSPENSE_RETRIES; attempt++) {
|
|
680
799
|
resetRenderState();
|
|
681
800
|
const chunks = [];
|
|
682
|
-
const writer = {
|
|
683
|
-
|
|
684
|
-
|
|
801
|
+
const writer = {
|
|
802
|
+
lastWasText: false,
|
|
803
|
+
write(c) {
|
|
804
|
+
chunks.push(c);
|
|
805
|
+
this.lastWasText = false;
|
|
806
|
+
},
|
|
807
|
+
text(s2) {
|
|
808
|
+
chunks.push(s2);
|
|
809
|
+
this.lastWasText = true;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
685
812
|
try {
|
|
686
813
|
const r = renderNode(element, writer);
|
|
687
814
|
if (r && typeof r.then === "function")
|