@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
118 lines • 6.11 kB
JavaScript
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _ExecutionList_instances, _ExecutionList_list, _ExecutionList_transformToExpandableList, _ExecutionList_getParentNodes;
export class IndexChange {
constructor(oldIndex, newIndex) {
this.oldIndex = oldIndex;
this.newIndex = newIndex;
}
}
export class LevelChange extends IndexChange {
constructor(oldIndex, newIndex, parent) {
super(oldIndex, newIndex);
this.parent = parent;
}
}
export class ExecutionList {
constructor(list) {
_ExecutionList_instances.add(this);
_ExecutionList_list.set(this, void 0);
__classPrivateFieldSet(this, _ExecutionList_list, list, "f");
const exList = {
executionList: [],
isCollapsed: false,
};
__classPrivateFieldGet(this, _ExecutionList_instances, "m", _ExecutionList_transformToExpandableList).call(this, 0, -1, exList);
this.expandableList = exList.executionList;
}
order(list) {
let result = [];
for (const row of list || this.expandableList) {
result.push(row);
if (row.executionList && !row.isCollapsed) {
result = result.concat(this.order(row.executionList));
}
}
return result;
}
findExecution(index, current = { index: 0 }, list) {
const l = list || this.expandableList;
for (let i = 0; i < l.length; i++) {
const ex = l[i];
if (current.index === index) {
return ex;
}
current.index++;
if (ex.executionList) {
const found = this.findExecution(index, current, ex.executionList);
if (found) {
return found;
}
}
}
return undefined;
}
getChange(changed, order) {
var _a;
const currentOrder = this.order();
const newLocIndex = order.findIndex((id) => id === changed.id);
const oldLocIndex = currentOrder.findIndex((ex) => ex.id === changed.id);
const oldLocation = currentOrder[oldLocIndex];
const newLocation = currentOrder[newLocIndex];
const currentParent = __classPrivateFieldGet(this, _ExecutionList_instances, "m", _ExecutionList_getParentNodes).call(this, oldLocation.level, oldLocIndex);
const parent = __classPrivateFieldGet(this, _ExecutionList_instances, "m", _ExecutionList_getParentNodes).call(this, newLocation.level, newLocIndex);
if ((currentParent === null || currentParent === void 0 ? void 0 : currentParent.id) !== (parent === null || parent === void 0 ? void 0 : parent.id)) {
if (newLocation.level > 0) {
return new LevelChange(((_a = parent === null || parent === void 0 ? void 0 : parent.executionList) === null || _a === void 0 ? void 0 : _a.length) || 0, newLocation.index, parent);
}
return new LevelChange(this.expandableList.length, newLocation.index);
}
return new IndexChange(oldLocation.index, newLocation.index);
}
clone() {
const newList = new ExecutionList([]);
__classPrivateFieldSet(newList, _ExecutionList_list, __classPrivateFieldGet(this, _ExecutionList_list, "f"), "f");
newList.expandableList = this.expandableList;
return newList;
}
}
_ExecutionList_list = new WeakMap(), _ExecutionList_instances = new WeakSet(), _ExecutionList_transformToExpandableList = function _ExecutionList_transformToExpandableList(currentIndex, currentLevel, execution) {
var _a, _b, _c;
for (let index = currentIndex; index < __classPrivateFieldGet(this, _ExecutionList_list, "f").length; index++) {
const ex = __classPrivateFieldGet(this, _ExecutionList_list, "f")[index];
const level = ex.level || 0;
if (level <= currentLevel) {
return index - 1;
}
const nextRowLevel = ((_a = __classPrivateFieldGet(this, _ExecutionList_list, "f")[index + 1]) === null || _a === void 0 ? void 0 : _a.level) || 0;
const hasChild = level < nextRowLevel;
if (hasChild) {
const subLevel = { ...ex, executionList: [], isCollapsed: false };
index = __classPrivateFieldGet(this, _ExecutionList_instances, "m", _ExecutionList_transformToExpandableList).call(this, index + 1, level, subLevel);
(_b = execution.executionList) === null || _b === void 0 ? void 0 : _b.push(subLevel);
}
else {
(_c = execution.executionList) === null || _c === void 0 ? void 0 : _c.push(ex);
}
}
return __classPrivateFieldGet(this, _ExecutionList_list, "f").length;
}, _ExecutionList_getParentNodes = function _ExecutionList_getParentNodes(level, index) {
let parent = undefined;
for (let i = 0; i < index; i++) {
const ex = __classPrivateFieldGet(this, _ExecutionList_list, "f")[i];
if (level - 1 === ex.level) {
parent = ex;
}
}
return parent;
};
//# sourceMappingURL=execution-model.js.map