reptree 0.5.0 → 0.6.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 +18 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -10
- package/dist/index.d.ts +1 -10
- package/dist/index.js +18 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,6 @@ __export(index_exports, {
|
|
|
26
26
|
Vertex: () => Vertex,
|
|
27
27
|
VertexState: () => VertexState,
|
|
28
28
|
bindVertex: () => bindVertex,
|
|
29
|
-
defaultAliases: () => defaultAliases,
|
|
30
29
|
isAnyPropertyOp: () => isAnyPropertyOp,
|
|
31
30
|
isMoveVertexOp: () => isMoveVertexOp,
|
|
32
31
|
newMoveVertexOp: () => newMoveVertexOp,
|
|
@@ -355,7 +354,7 @@ var TreeState = class {
|
|
|
355
354
|
const vertex = this.getVertex(vertexId);
|
|
356
355
|
if (vertex) {
|
|
357
356
|
for (const prop of vertex.getAllProperties()) {
|
|
358
|
-
if (prop.key === "
|
|
357
|
+
if (prop.key === "name") {
|
|
359
358
|
vertexName = prop.value;
|
|
360
359
|
}
|
|
361
360
|
const propPrefix = indent + (isLast ? " " : "\u2502 ") + "\u2022 ";
|
|
@@ -368,8 +367,8 @@ var TreeState = class {
|
|
|
368
367
|
const sortedChildren = [...children].sort((a, b) => {
|
|
369
368
|
const vertexA = this.getVertex(a);
|
|
370
369
|
const vertexB = this.getVertex(b);
|
|
371
|
-
const nameA = vertexA?.getProperty("
|
|
372
|
-
const nameB = vertexB?.getProperty("
|
|
370
|
+
const nameA = vertexA?.getProperty("name");
|
|
371
|
+
const nameB = vertexB?.getProperty("name");
|
|
373
372
|
if (nameA && nameB) {
|
|
374
373
|
return nameA.localeCompare(nameB);
|
|
375
374
|
}
|
|
@@ -393,30 +392,10 @@ function uuid() {
|
|
|
393
392
|
}
|
|
394
393
|
|
|
395
394
|
// src/reactive.ts
|
|
396
|
-
var defaultAliases = [
|
|
397
|
-
{ publicKey: "name", internalKey: "_n" },
|
|
398
|
-
{
|
|
399
|
-
publicKey: "createdAt",
|
|
400
|
-
internalKey: "_c",
|
|
401
|
-
toPublic: (v) => typeof v === "string" ? new Date(v) : v,
|
|
402
|
-
toInternal: (v) => v instanceof Date ? v.toISOString() : v
|
|
403
|
-
}
|
|
404
|
-
];
|
|
405
|
-
function buildAliasMaps(aliases) {
|
|
406
|
-
const publicToInternal = /* @__PURE__ */ new Map();
|
|
407
|
-
const internalToPublic = /* @__PURE__ */ new Map();
|
|
408
|
-
for (const rule of aliases) {
|
|
409
|
-
publicToInternal.set(rule.publicKey, rule);
|
|
410
|
-
internalToPublic.set(rule.internalKey, rule);
|
|
411
|
-
}
|
|
412
|
-
return { publicToInternal, internalToPublic };
|
|
413
|
-
}
|
|
414
395
|
function bindVertex(tree, id, schemaOrOptions) {
|
|
415
|
-
const isOptions = typeof schemaOrOptions === "object" && schemaOrOptions !== null && (Object.prototype.hasOwnProperty.call(schemaOrOptions, "
|
|
396
|
+
const isOptions = typeof schemaOrOptions === "object" && schemaOrOptions !== null && (Object.prototype.hasOwnProperty.call(schemaOrOptions, "includeInternalKeys") || Object.prototype.hasOwnProperty.call(schemaOrOptions, "schema"));
|
|
416
397
|
const options = isOptions ? schemaOrOptions : { schema: schemaOrOptions };
|
|
417
398
|
const schema = options.schema;
|
|
418
|
-
const aliases = options.aliases ?? defaultAliases;
|
|
419
|
-
const { publicToInternal } = buildAliasMaps(aliases);
|
|
420
399
|
const obj = {};
|
|
421
400
|
Object.defineProperties(obj, {
|
|
422
401
|
$vertex: { get: () => tree.getVertex(id), enumerable: false, configurable: true },
|
|
@@ -453,19 +432,14 @@ function bindVertex(tree, id, schemaOrOptions) {
|
|
|
453
432
|
const transientProxy = new Proxy({}, {
|
|
454
433
|
set(_, prop, value) {
|
|
455
434
|
if (typeof prop === "string") {
|
|
456
|
-
|
|
457
|
-
const internalKey = rule?.internalKey ?? prop;
|
|
458
|
-
const internalValue = rule?.toInternal ? rule.toInternal(value) : value;
|
|
459
|
-
tree.setTransientVertexProperty(id, internalKey, internalValue);
|
|
435
|
+
tree.setTransientVertexProperty(id, prop, value);
|
|
460
436
|
}
|
|
461
437
|
return true;
|
|
462
438
|
},
|
|
463
439
|
get(_, prop) {
|
|
464
440
|
if (typeof prop !== "string") return void 0;
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
const rawValue = tree.getVertexProperty(id, internalKey, true);
|
|
468
|
-
return rule?.toPublic ? rule.toPublic(rawValue) : rawValue;
|
|
441
|
+
const rawValue = tree.getVertexProperty(id, prop, true);
|
|
442
|
+
return rawValue;
|
|
469
443
|
}
|
|
470
444
|
});
|
|
471
445
|
fn(transientProxy);
|
|
@@ -495,10 +469,8 @@ function bindVertex(tree, id, schemaOrOptions) {
|
|
|
495
469
|
if (prop in target) {
|
|
496
470
|
return Reflect.get(target, prop, receiver);
|
|
497
471
|
}
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
const rawValue = tree.getVertexProperty(id, internalKey, true);
|
|
501
|
-
return rule?.toPublic ? rule.toPublic(rawValue) : rawValue;
|
|
472
|
+
const rawValue = tree.getVertexProperty(id, prop, true);
|
|
473
|
+
return rawValue;
|
|
502
474
|
},
|
|
503
475
|
set(target, prop, value) {
|
|
504
476
|
if (typeof prop !== "string") {
|
|
@@ -512,19 +484,14 @@ function bindVertex(tree, id, schemaOrOptions) {
|
|
|
512
484
|
value = res.data;
|
|
513
485
|
}
|
|
514
486
|
}
|
|
515
|
-
|
|
516
|
-
const internalKey = rule?.internalKey ?? prop;
|
|
517
|
-
const internalValue = rule?.toInternal ? rule.toInternal(value) : value;
|
|
518
|
-
tree.setVertexProperty(id, internalKey, internalValue);
|
|
487
|
+
tree.setVertexProperty(id, prop, value);
|
|
519
488
|
return true;
|
|
520
489
|
},
|
|
521
490
|
deleteProperty(_target, prop) {
|
|
522
491
|
if (typeof prop !== "string") {
|
|
523
492
|
return true;
|
|
524
493
|
}
|
|
525
|
-
|
|
526
|
-
const internalKey = rule?.internalKey ?? prop;
|
|
527
|
-
tree.setVertexProperty(id, internalKey, void 0);
|
|
494
|
+
tree.setVertexProperty(id, prop, void 0);
|
|
528
495
|
return true;
|
|
529
496
|
}
|
|
530
497
|
});
|
|
@@ -541,10 +508,10 @@ var Vertex = class _Vertex {
|
|
|
541
508
|
return this.state.id;
|
|
542
509
|
}
|
|
543
510
|
get name() {
|
|
544
|
-
return this.getProperty("
|
|
511
|
+
return this.getProperty("name");
|
|
545
512
|
}
|
|
546
513
|
set name(name) {
|
|
547
|
-
this.tree.setVertexProperty(this.id, "
|
|
514
|
+
this.tree.setVertexProperty(this.id, "name", name);
|
|
548
515
|
}
|
|
549
516
|
get createdAt() {
|
|
550
517
|
const createdAt = this.getProperty("_c");
|
|
@@ -664,7 +631,6 @@ var Vertex = class _Vertex {
|
|
|
664
631
|
}
|
|
665
632
|
/**
|
|
666
633
|
* Normalizes an input props object for vertex creation:
|
|
667
|
-
* - Aliases name -> _n, createdAt -> _c (Date -> ISO string)
|
|
668
634
|
* - Filters unsupported field types with a console warning
|
|
669
635
|
* - When a name param is provided to newNamedChild, ignores conflicting name in props
|
|
670
636
|
*/
|
|
@@ -679,14 +645,9 @@ var Vertex = class _Vertex {
|
|
|
679
645
|
}
|
|
680
646
|
if (rawKey === "children") continue;
|
|
681
647
|
let key = rawKey;
|
|
682
|
-
if (rawKey === "name") {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
key = "_n";
|
|
688
|
-
} else if (rawKey === "createdAt") {
|
|
689
|
-
key = "_c";
|
|
648
|
+
if (rawKey === "name" && explicitName !== void 0) {
|
|
649
|
+
console.warn('newNamedChild: "name" in props is ignored because a name argument was provided');
|
|
650
|
+
continue;
|
|
690
651
|
}
|
|
691
652
|
let value = rawValue;
|
|
692
653
|
if (key === "_c") {
|
|
@@ -1054,7 +1015,7 @@ var _RepTree = class _RepTree {
|
|
|
1054
1015
|
if (typedProps) {
|
|
1055
1016
|
this.setVertexProperties(vertexId, typedProps);
|
|
1056
1017
|
}
|
|
1057
|
-
this.setVertexProperty(vertexId, "
|
|
1018
|
+
this.setVertexProperty(vertexId, "name", name);
|
|
1058
1019
|
const vertex = this.state.getVertex(vertexId);
|
|
1059
1020
|
if (!vertex) {
|
|
1060
1021
|
throw new Error("Failed to create named vertex");
|
|
@@ -1128,7 +1089,7 @@ var _RepTree = class _RepTree {
|
|
|
1128
1089
|
const targetName = path[0];
|
|
1129
1090
|
const children = this.getChildren(vertex.id);
|
|
1130
1091
|
for (const child of children) {
|
|
1131
|
-
if (child.getProperty("
|
|
1092
|
+
if (child.getProperty("name") === targetName) {
|
|
1132
1093
|
return this.getVertexByPathArray(child, path.slice(1));
|
|
1133
1094
|
}
|
|
1134
1095
|
}
|
|
@@ -1516,7 +1477,6 @@ var RepTree = _RepTree;
|
|
|
1516
1477
|
Vertex,
|
|
1517
1478
|
VertexState,
|
|
1518
1479
|
bindVertex,
|
|
1519
|
-
defaultAliases,
|
|
1520
1480
|
isAnyPropertyOp,
|
|
1521
1481
|
isMoveVertexOp,
|
|
1522
1482
|
newMoveVertexOp,
|