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.js CHANGED
@@ -317,7 +317,7 @@ var TreeState = class {
317
317
  const vertex = this.getVertex(vertexId);
318
318
  if (vertex) {
319
319
  for (const prop of vertex.getAllProperties()) {
320
- if (prop.key === "_n") {
320
+ if (prop.key === "name") {
321
321
  vertexName = prop.value;
322
322
  }
323
323
  const propPrefix = indent + (isLast ? " " : "\u2502 ") + "\u2022 ";
@@ -330,8 +330,8 @@ var TreeState = class {
330
330
  const sortedChildren = [...children].sort((a, b) => {
331
331
  const vertexA = this.getVertex(a);
332
332
  const vertexB = this.getVertex(b);
333
- const nameA = vertexA?.getProperty("_n");
334
- const nameB = vertexB?.getProperty("_n");
333
+ const nameA = vertexA?.getProperty("name");
334
+ const nameB = vertexB?.getProperty("name");
335
335
  if (nameA && nameB) {
336
336
  return nameA.localeCompare(nameB);
337
337
  }
@@ -355,30 +355,10 @@ function uuid() {
355
355
  }
356
356
 
357
357
  // src/reactive.ts
358
- var defaultAliases = [
359
- { publicKey: "name", internalKey: "_n" },
360
- {
361
- publicKey: "createdAt",
362
- internalKey: "_c",
363
- toPublic: (v) => typeof v === "string" ? new Date(v) : v,
364
- toInternal: (v) => v instanceof Date ? v.toISOString() : v
365
- }
366
- ];
367
- function buildAliasMaps(aliases) {
368
- const publicToInternal = /* @__PURE__ */ new Map();
369
- const internalToPublic = /* @__PURE__ */ new Map();
370
- for (const rule of aliases) {
371
- publicToInternal.set(rule.publicKey, rule);
372
- internalToPublic.set(rule.internalKey, rule);
373
- }
374
- return { publicToInternal, internalToPublic };
375
- }
376
358
  function bindVertex(tree, id, schemaOrOptions) {
377
- const isOptions = typeof schemaOrOptions === "object" && schemaOrOptions !== null && (Object.prototype.hasOwnProperty.call(schemaOrOptions, "aliases") || Object.prototype.hasOwnProperty.call(schemaOrOptions, "includeInternalKeys") || Object.prototype.hasOwnProperty.call(schemaOrOptions, "schema"));
359
+ const isOptions = typeof schemaOrOptions === "object" && schemaOrOptions !== null && (Object.prototype.hasOwnProperty.call(schemaOrOptions, "includeInternalKeys") || Object.prototype.hasOwnProperty.call(schemaOrOptions, "schema"));
378
360
  const options = isOptions ? schemaOrOptions : { schema: schemaOrOptions };
379
361
  const schema = options.schema;
380
- const aliases = options.aliases ?? defaultAliases;
381
- const { publicToInternal } = buildAliasMaps(aliases);
382
362
  const obj = {};
383
363
  Object.defineProperties(obj, {
384
364
  $vertex: { get: () => tree.getVertex(id), enumerable: false, configurable: true },
@@ -415,19 +395,14 @@ function bindVertex(tree, id, schemaOrOptions) {
415
395
  const transientProxy = new Proxy({}, {
416
396
  set(_, prop, value) {
417
397
  if (typeof prop === "string") {
418
- const rule = publicToInternal.get(prop);
419
- const internalKey = rule?.internalKey ?? prop;
420
- const internalValue = rule?.toInternal ? rule.toInternal(value) : value;
421
- tree.setTransientVertexProperty(id, internalKey, internalValue);
398
+ tree.setTransientVertexProperty(id, prop, value);
422
399
  }
423
400
  return true;
424
401
  },
425
402
  get(_, prop) {
426
403
  if (typeof prop !== "string") return void 0;
427
- const rule = publicToInternal.get(prop);
428
- const internalKey = rule?.internalKey ?? prop;
429
- const rawValue = tree.getVertexProperty(id, internalKey, true);
430
- return rule?.toPublic ? rule.toPublic(rawValue) : rawValue;
404
+ const rawValue = tree.getVertexProperty(id, prop, true);
405
+ return rawValue;
431
406
  }
432
407
  });
433
408
  fn(transientProxy);
@@ -457,10 +432,8 @@ function bindVertex(tree, id, schemaOrOptions) {
457
432
  if (prop in target) {
458
433
  return Reflect.get(target, prop, receiver);
459
434
  }
460
- const rule = publicToInternal.get(prop);
461
- const internalKey = rule?.internalKey ?? prop;
462
- const rawValue = tree.getVertexProperty(id, internalKey, true);
463
- return rule?.toPublic ? rule.toPublic(rawValue) : rawValue;
435
+ const rawValue = tree.getVertexProperty(id, prop, true);
436
+ return rawValue;
464
437
  },
465
438
  set(target, prop, value) {
466
439
  if (typeof prop !== "string") {
@@ -474,19 +447,14 @@ function bindVertex(tree, id, schemaOrOptions) {
474
447
  value = res.data;
475
448
  }
476
449
  }
477
- const rule = publicToInternal.get(prop);
478
- const internalKey = rule?.internalKey ?? prop;
479
- const internalValue = rule?.toInternal ? rule.toInternal(value) : value;
480
- tree.setVertexProperty(id, internalKey, internalValue);
450
+ tree.setVertexProperty(id, prop, value);
481
451
  return true;
482
452
  },
483
453
  deleteProperty(_target, prop) {
484
454
  if (typeof prop !== "string") {
485
455
  return true;
486
456
  }
487
- const rule = publicToInternal.get(prop);
488
- const internalKey = rule?.internalKey ?? prop;
489
- tree.setVertexProperty(id, internalKey, void 0);
457
+ tree.setVertexProperty(id, prop, void 0);
490
458
  return true;
491
459
  }
492
460
  });
@@ -503,10 +471,10 @@ var Vertex = class _Vertex {
503
471
  return this.state.id;
504
472
  }
505
473
  get name() {
506
- return this.getProperty("_n");
474
+ return this.getProperty("name");
507
475
  }
508
476
  set name(name) {
509
- this.tree.setVertexProperty(this.id, "_n", name);
477
+ this.tree.setVertexProperty(this.id, "name", name);
510
478
  }
511
479
  get createdAt() {
512
480
  const createdAt = this.getProperty("_c");
@@ -626,7 +594,6 @@ var Vertex = class _Vertex {
626
594
  }
627
595
  /**
628
596
  * Normalizes an input props object for vertex creation:
629
- * - Aliases name -> _n, createdAt -> _c (Date -> ISO string)
630
597
  * - Filters unsupported field types with a console warning
631
598
  * - When a name param is provided to newNamedChild, ignores conflicting name in props
632
599
  */
@@ -641,14 +608,9 @@ var Vertex = class _Vertex {
641
608
  }
642
609
  if (rawKey === "children") continue;
643
610
  let key = rawKey;
644
- if (rawKey === "name") {
645
- if (explicitName !== void 0) {
646
- console.warn('newNamedChild: "name" in props is ignored because a name argument was provided');
647
- continue;
648
- }
649
- key = "_n";
650
- } else if (rawKey === "createdAt") {
651
- key = "_c";
611
+ if (rawKey === "name" && explicitName !== void 0) {
612
+ console.warn('newNamedChild: "name" in props is ignored because a name argument was provided');
613
+ continue;
652
614
  }
653
615
  let value = rawValue;
654
616
  if (key === "_c") {
@@ -1016,7 +978,7 @@ var _RepTree = class _RepTree {
1016
978
  if (typedProps) {
1017
979
  this.setVertexProperties(vertexId, typedProps);
1018
980
  }
1019
- this.setVertexProperty(vertexId, "_n", name);
981
+ this.setVertexProperty(vertexId, "name", name);
1020
982
  const vertex = this.state.getVertex(vertexId);
1021
983
  if (!vertex) {
1022
984
  throw new Error("Failed to create named vertex");
@@ -1090,7 +1052,7 @@ var _RepTree = class _RepTree {
1090
1052
  const targetName = path[0];
1091
1053
  const children = this.getChildren(vertex.id);
1092
1054
  for (const child of children) {
1093
- if (child.getProperty("_n") === targetName) {
1055
+ if (child.getProperty("name") === targetName) {
1094
1056
  return this.getVertexByPathArray(child, path.slice(1));
1095
1057
  }
1096
1058
  }
@@ -1477,7 +1439,6 @@ export {
1477
1439
  Vertex,
1478
1440
  VertexState,
1479
1441
  bindVertex,
1480
- defaultAliases,
1481
1442
  isAnyPropertyOp,
1482
1443
  isMoveVertexOp,
1483
1444
  newMoveVertexOp,