alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
56 lines (54 loc) • 1.53 kB
JavaScript
import "../../chunks/chunk-U5RRZUYZ.js";
// src/core/pages/Tree.ts
import { Cursor, SourceType } from "./Cursor.js";
import { Target } from "./Target.js";
var Tree = class {
constructor() {
this.children = this.children.bind(this);
this.parents = this.parents.bind(this);
}
narrowData(narrow) {
return narrow && (Cursor.isCursor(narrow) ? narrow[Cursor.Data] : { target: narrow[Target.Data] });
}
find(sourceType, narrow, depth) {
return new Cursor.Find({
...this.narrowData(narrow),
source: { type: sourceType, depth }
});
}
get(sourceType, narrow) {
return new Cursor.Get({
...this.narrowData(narrow),
first: true,
source: { type: sourceType }
});
}
children(narrow, depth) {
;
[narrow, depth] = typeof narrow === "number" ? [void 0, narrow] : [narrow, depth || 1];
return this.find(SourceType.Children, narrow, depth);
}
parents(narrow, depth) {
;
[narrow, depth] = typeof narrow === "number" ? [void 0, narrow] : [narrow, depth];
return this.find(SourceType.Parents, narrow, depth);
}
previous = (narrow) => {
return this.get(SourceType.Previous, narrow);
};
next = (narrow) => {
return this.get(SourceType.Next, narrow);
};
parent = (narrow) => {
return this.get(SourceType.Parent, narrow);
};
siblings = (narrow) => {
return this.find(SourceType.Siblings, narrow);
};
translations = (includeSelf = false) => {
return this.find(SourceType.Translations);
};
};
export {
Tree
};