![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /proc/self/root/var/www/html/libs/absol-form/js/core/ |
Upload File : |
function FNode() { /** * @type {FNode} */ this.parent = null; /** * @type {Array<FNode>} */ this.children = []; } FNode.prototype.onDetach = function () {/* NOOP */ }; FNode.prototype.onDetached = function () {/* NOOP */ }; FNode.prototype.onAttach = function () {/* NOOP */ }; FNode.prototype.onAttached = function () {/* NOOP */ }; /** * @param {FNode} child * @param {Number} index */ FNode.prototype.onRemoveChild = function (child, index) { } /** * @param {FNode} child * @param {Number} index */ FNode.prototype.onAddChild = function (child, index) { }; /** * @return {FNode} */ FNode.prototype.remove = function () { if (this.parent) this.parent.removeChild(this); }; /** * @param {FNode} child * @return {FNode} */ FNode.prototype.addChild = function (child) { child.remove(); this.children.push(child); child.parent = this; //data ready child.onAttach(); this.onAddChild(child, -1);//negative index for appending child child.onAttached(); }; /** * @param {FNode} child * @return {Boolean} */ FNode.prototype.removeChild = function (child) { var childIndex = this.children.indexOf(child); if (childIndex < 0) return false; this.children.splice(childIndex, 1); child.onDetach(this); this.onRemoveChild(child, childIndex); child.parent = undefined; child.onDetached(this); return true; }; /** * @param {FNode} child * @param {FNode} at * @return {FNode} */ FNode.prototype.addChildBefore = function (child, at) { child.remove(); var atIndex = this.children.indexOf(at); if (atIndex >= 0) { this.children.splice(atIndex, 0, child); child.parent = this; this.onAttach(); this.onAddChild(child, atIndex); child.onAttached(); return true; } return false; }; /** * @param {FNode} child * @param {FNode} at * @return {FNode} */ FNode.prototype.addChildAfter = function (child, at) { child.remove(); var atIndex = this.children.indexOf(at); if (atIndex >= 0) { this.children.splice(atIndex + 1, 0, child); child.parent = this; this.onAttach(); this.onAddChild(child, atIndex + 1); child.onAttached(); return true; } return false; }; /** * @param {FNode} child * @return {FNode} */ FNode.prototype.findChildBefore = function (child) { var index = this.children.indexOf(child); if (index > 0) return this.children[index - 1]; }; /** * @param {FNode} child * @return {FNode} */ FNode.prototype.findChildAfter = function (child) { var index = this.children.indexOf(child); if (index < this.children.length - 1) return this.children[index + 1]; }; /** * @param {FNode} child * @return {Number} */ FNode.prototype.indexOfChild = function (child) { return this.children.indexOf(child); }; export default FNode; /*** * * * @param {FNode} root * @param cb */ export function traversal(root, cb) { var ac = { path: [], node: null, isStopped: false, stop: function () { this.isStopped = true; }, isSkipChildren: false, skipChildren: function () { this.isSkipChildren = true; } }; function visit(node) { ac.path.push(node); ac.node = node; ac.isSkipChildren = false; ac.isStopped = false; cb(ac); if (!ac.isSkipChildren) { if (node.children) for (var i = 0; i < node.children.length && !ac.isStopped; ++i) { visit(node.children[i]); } } ac.node = ac.path.pop(); } visit(root); }