196 lines
5.9 KiB
TypeScript
196 lines
5.9 KiB
TypeScript
// Metro module 5029 (f5030).
|
|
import Module38 from "../../_bundle/Module38";
|
|
import { clone } from "../../_bundle/Module12";
|
|
function $mk104094($env) {
|
|
return (a0) => {
|
|
const r1 = $env;
|
|
return a0.type === r1[3].GUILD ? [a0] : a0.children == null ? [] : a0.children.map($mk104094(r1)).flat();
|
|
};
|
|
}
|
|
let env3035 = {};
|
|
const c3035_3 = {
|
|
ROOT: "root",
|
|
FOLDER: "folder",
|
|
GUILD: "guild"
|
|
};
|
|
export { c3035_3 as GuildsNodeType };
|
|
export class GuildsTree {
|
|
root = {
|
|
type: c3035_3.ROOT,
|
|
children: []
|
|
};
|
|
nodes = {};
|
|
version = 0;
|
|
getSnapshot() {
|
|
const nodes2 = {};
|
|
const nodes = this.nodes;
|
|
for (const key in nodes) {
|
|
const r10 = this.nodes[key];
|
|
nodes2[key] = {
|
|
...r10,
|
|
children: void 0,
|
|
childrenIds: r10.children.map((item) => item.id)
|
|
};
|
|
}
|
|
return {
|
|
rootChildrenIds: this.root.children.map((item) => item.id),
|
|
nodes: nodes2
|
|
};
|
|
}
|
|
loadSnapshot(a0) {
|
|
this.nodes = a0.nodes;
|
|
const nodes = this.nodes;
|
|
for (const key in nodes) {
|
|
const r15 = this.nodes[key];
|
|
if ("childrenIds" in r15) {
|
|
r15.children = r15.childrenIds.map((childrenId) => this.nodes[childrenId]);
|
|
delete r15["childrenIds"];
|
|
}
|
|
}
|
|
this.root.children = a0.rootChildrenIds.map((rootChildrenId) => this.nodes[rootChildrenId]);
|
|
this.version = this.version + 1;
|
|
}
|
|
moveNextTo(a0, a1, r10 = false) {
|
|
this._pluckNode(a0);
|
|
const r29 = a1.parentId != null ? this.nodes[a1.parentId] : this.root;
|
|
const r32 = r29.children.indexOf(a1);
|
|
const type = a0.type;
|
|
Module38(!(type === c3035_3.FOLDER && r29.type === c3035_3.FOLDER), `[GUILDS TREE] Tried moving a folder (${a0.id}) inside of another folder (${r29.id})`);
|
|
Module38(r32 >= 0, `[GUILDS TREE] target node (${a1.id}) did not exist within its specified parent (${a1.parentId})`);
|
|
const r0 = r10 ? 1 : 0;
|
|
r29.children = [...r29.children];
|
|
r29.children.splice(r32 + r0, 0, a0);
|
|
a0.parentId = r29.id;
|
|
this.version = this.version + 1;
|
|
return this;
|
|
}
|
|
moveInto(a0, a1, r6 = true) {
|
|
this._pluckNode(a0);
|
|
const r8 = r6 ? a1.children.length : 0;
|
|
a1.children = [...a1.children];
|
|
a1.children.splice(r8, 0, a0);
|
|
a0.parentId = a1.id;
|
|
this.version = this.version + 1;
|
|
return this;
|
|
}
|
|
addNode(a0, r6 = this.root, r5 = true) {
|
|
Module38(a0.type !== c3035_3.ROOT, "[GUILDS TREE] Tried adding another root node into the tree");
|
|
Module38(a0.id != null, "[GUILDS TREE] Tried adding a node without an id");
|
|
Module38(this.nodes[a0.id] == null, `[GUILDS TREE] Tried adding a node that already exists (${a0.id})`);
|
|
this.nodes[a0.id] = a0;
|
|
this.version = this.version + 1;
|
|
return this.moveInto(a0, r6, r5);
|
|
}
|
|
removeNode(a0) {
|
|
Module38(a0 !== this.root, "[GUILDS TREE] Tried removing the root node from the tree");
|
|
Module38(a0.id != null, "[GUILDS TREE] Tried removing a node without an id");
|
|
this._pluckNode(a0);
|
|
a0.parentId = void 0;
|
|
delete this.nodes[a0.id];
|
|
this.version = this.version + 1;
|
|
return this;
|
|
}
|
|
replaceNode(a0, a1) {
|
|
Module38(a0.id != null, "[GUILDS TREE] Tried replacing a node without an id");
|
|
Module38(a1.id != null, "[GUILDS TREE] Tried replacing a node with one that does not have an id");
|
|
const r32 = a0.parentId != null ? this.nodes[a0.parentId] : this.root;
|
|
const r36 = r32.children.indexOf(a0);
|
|
Module38(r36 >= 0, `[GUILDS TREE] existing node (${a0.id}) did not exist within its specified parent (${a0.parentId})`);
|
|
r32.children = [...r32.children];
|
|
r32.children.splice(r36, 1, a1);
|
|
a1.parentId = r32.id;
|
|
a0.parentId = void 0;
|
|
delete this.nodes[a0.id];
|
|
this.nodes[a1.id] = a1;
|
|
this.version = this.version + 1;
|
|
return this;
|
|
}
|
|
cloneNode(a0) {
|
|
return clone(a0);
|
|
}
|
|
convertToFolder(a0) {
|
|
let node;
|
|
let id = Math.floor(4294967296 * Math.random());
|
|
if (this.getNode(id) != null) {
|
|
do {
|
|
const r19 = Math.floor(4294967296 * Math.random());
|
|
node = this.getNode(r19);
|
|
id = r19;
|
|
} while (node != null);
|
|
}
|
|
const r26 = {
|
|
type: c3035_3.FOLDER,
|
|
id,
|
|
expanded: false,
|
|
children: []
|
|
};
|
|
this.replaceNode(a0, r26);
|
|
this.removeNode(a0);
|
|
this.addNode(a0, r26, false);
|
|
this.version = this.version + 1;
|
|
return r26;
|
|
}
|
|
allNodes() {
|
|
return Object.values(this.nodes);
|
|
}
|
|
getNode(a0) {
|
|
return this.nodes[a0];
|
|
}
|
|
getRoots() {
|
|
return this.root.children;
|
|
}
|
|
get size() {
|
|
return this.allNodes().length;
|
|
}
|
|
sortedGuildNodes() {
|
|
const r1 = env3035;
|
|
const root = this.root;
|
|
return root.type === c3035_3.GUILD ? [root] : root.children == null ? [] : root.children.map($mk104094(r1)).flat();
|
|
}
|
|
_pluckNode(a0) {
|
|
const r22 = a0.parentId != null ? this.nodes[a0.parentId] : this.root;
|
|
Module38(r22 != null, `[GUILDS TREE] source node (${a0.id}) had a parent id (${a0.parentId}) which doesn't exist in the tree`);
|
|
const children = r22.children;
|
|
Module38(children != null, `[GUILDS TREE] source node (${a0.id}) had a parent id (${a0.parentId}) which contains no children`);
|
|
r22.children = children.filter((item) => item !== a0);
|
|
a0.parentId = void 0;
|
|
this.version = this.version + 1;
|
|
}
|
|
}
|
|
export function createGuildNode(a0, a1) {
|
|
return {
|
|
type: c3035_3.GUILD,
|
|
id: a0,
|
|
parentId: a1,
|
|
children: [],
|
|
unavailable: false
|
|
};
|
|
}
|
|
export function createFolderNode(a0, a1, a2) {
|
|
let folderName = a0.folderName;
|
|
if (folderName == null) {
|
|
folderName = void 0;
|
|
}
|
|
let folderColor = a0.folderColor;
|
|
if (folderColor == null) {
|
|
folderColor = void 0;
|
|
}
|
|
let expanded2 = a2;
|
|
if (a2 == null) {
|
|
let expanded = a0.expanded;
|
|
if (expanded == null) {
|
|
expanded = false;
|
|
}
|
|
expanded2 = expanded;
|
|
}
|
|
return {
|
|
type: c3035_3.FOLDER,
|
|
id: a0.folderId,
|
|
parentId: a1,
|
|
name: folderName,
|
|
color: folderColor,
|
|
expanded: expanded2,
|
|
children: []
|
|
};
|
|
}
|