reptree 0.8.1 → 0.9.0
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/index.cjs +3 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.js +3 -63
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -505,7 +505,7 @@ function bindVertex(tree, id, schemaOrOptions) {
|
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
// src/Vertex.ts
|
|
508
|
-
var Vertex = class
|
|
508
|
+
var Vertex = class {
|
|
509
509
|
constructor(tree, state) {
|
|
510
510
|
this.state = state;
|
|
511
511
|
this._tree = tree;
|
|
@@ -583,19 +583,11 @@ var Vertex = class _Vertex {
|
|
|
583
583
|
}
|
|
584
584
|
/** Creates a new child vertex of this vertex. */
|
|
585
585
|
newChild(props) {
|
|
586
|
-
|
|
587
|
-
throw new Error("Passing children inside props is not supported at the moment");
|
|
588
|
-
}
|
|
589
|
-
const normalized = _Vertex.normalizePropsForCreation(props);
|
|
590
|
-
return this.tree.newVertex(this.id, normalized);
|
|
586
|
+
return this.tree.newVertex(this.id, props);
|
|
591
587
|
}
|
|
592
588
|
/** Creates a new named child vertex of this vertex. */
|
|
593
589
|
newNamedChild(name, props) {
|
|
594
|
-
|
|
595
|
-
throw new Error("Passing children inside props is not supported at the moment");
|
|
596
|
-
}
|
|
597
|
-
const normalized = _Vertex.normalizePropsForCreation(props);
|
|
598
|
-
return this.tree.newNamedVertex(this.id, name, normalized);
|
|
590
|
+
return this.tree.newNamedVertex(this.id, name, props);
|
|
599
591
|
}
|
|
600
592
|
/** Sets a property on this vertex. */
|
|
601
593
|
setProperty(key, value) {
|
|
@@ -676,58 +668,6 @@ var Vertex = class _Vertex {
|
|
|
676
668
|
bind(schemaOrOptions) {
|
|
677
669
|
return bindVertex(this.tree, this.id, schemaOrOptions);
|
|
678
670
|
}
|
|
679
|
-
/**
|
|
680
|
-
* Normalizes an input props object for vertex creation:
|
|
681
|
-
* - Filters unsupported field types with a console warning
|
|
682
|
-
* - When a name param is provided to newNamedChild, ignores conflicting name in props
|
|
683
|
-
*/
|
|
684
|
-
static normalizePropsForCreation(props) {
|
|
685
|
-
if (!props) return null;
|
|
686
|
-
const input = props;
|
|
687
|
-
const out = {};
|
|
688
|
-
const skipped = [];
|
|
689
|
-
const isJsonValue2 = (v) => {
|
|
690
|
-
if (v === null) return true;
|
|
691
|
-
const t = typeof v;
|
|
692
|
-
if (t === "string" || t === "number" || t === "boolean") return true;
|
|
693
|
-
if (Array.isArray(v)) return v.every(isJsonValue2);
|
|
694
|
-
if (t === "object") {
|
|
695
|
-
const proto = Object.getPrototypeOf(v);
|
|
696
|
-
if (proto !== Object.prototype && proto !== null) return false;
|
|
697
|
-
for (const val of Object.values(v)) {
|
|
698
|
-
if (!isJsonValue2(val)) return false;
|
|
699
|
-
}
|
|
700
|
-
return true;
|
|
701
|
-
}
|
|
702
|
-
return false;
|
|
703
|
-
};
|
|
704
|
-
for (const [rawKey, rawValue] of Object.entries(input)) {
|
|
705
|
-
if (rawValue === void 0) {
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
if (rawKey === "children") continue;
|
|
709
|
-
let key = rawKey;
|
|
710
|
-
let value = rawValue;
|
|
711
|
-
if (key === "_c") {
|
|
712
|
-
if (value instanceof Date) {
|
|
713
|
-
value = value.toISOString();
|
|
714
|
-
} else if (typeof value === "string") {
|
|
715
|
-
} else {
|
|
716
|
-
skipped.push(rawKey);
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if (!isJsonValue2(value)) {
|
|
721
|
-
skipped.push(rawKey);
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
out[key] = value;
|
|
725
|
-
}
|
|
726
|
-
if (skipped.length > 0) {
|
|
727
|
-
throw new Error(`Unsupported property types for keys: ${skipped.join(", ")}`);
|
|
728
|
-
}
|
|
729
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
730
|
-
}
|
|
731
671
|
};
|
|
732
672
|
|
|
733
673
|
// src/StateVector.ts
|