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**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/json-tree-wrap@0.0.2/lib/treeWrapper.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","(function (root, factory) {\n    if (typeof define === 'function' && define.amd) {\n        define(['lodash', './polyfills.js'], factory);\n    } else if (typeof exports === 'object') {\n        module.exports = factory(require('lodash'), require('./polyfills.js'));\n    } else {\n        root.TreeWrapper = factory(root._, root.jsonTreeWrapPolyfills);\n    }\n}(this, function (_, polyfills) {\n\n    polyfills();\n\n    function TreeWrapper(options) {\n        options = options || {};\n\n        var noOp = function() {};\n        this.options = _.defaults(options, {\n            childrenProp: 'items',\n            onInit: noOp,\n            onAdd: noOp,\n            onRemove: noOp,\n            onMove: noOp\n        });\n\n        if (options.observer) {\n            if (options.observer.onInit) this.options.onInit = options.observer.onInit.bind(options.observer);\n            if (options.observer.onAdd) this.options.onAdd = options.observer.onAdd.bind(options.observer);\n            if (options.observer.onRemove) this.options.onRemove = options.observer.onRemove.bind(options.observer);\n            if (options.observer.onMove) this.options.onMove = options.observer.onMove.bind(options.observer);\n        }\n\n        this.childrenProp = this.options.childrenProp;\n    }\n\n    TreeWrapper.prototype = {\n        wrap: function(obj) {\n            if (!obj) {\n                throw new Error('Object to wrap was null');\n            }\n\n            var parent = null;\n\n            if (this.options.onInit) {\n                traverse(obj, parent, 0, 0, this.childrenProp, function(item, parent, index, depth) {\n                    this.options.onInit(parent, index, item, depth);\n                }.bind(this));\n            }\n\n            return createItemWrapper(obj, parent, this.options);\n        },\n        createItemWrapper: function(item, parent) {\n            return createItemWrapper(item, parent, this.options);\n        },\n        // TODO: this is a bit of a smell. Just here to reuse the childrenProp config\n        traverse: function(item, callback) {\n            traverseSimple(item, null, this.childrenProp, callback);\n        }\n    };\n\n    return TreeWrapper;\n\n    function createItemWrapper(obj, parent, options) {\n\n        function getItemIndexOrThrow(parentItems, item) {\n            var thisItemIndex = parentItems.indexOf(item);\n            if (thisItemIndex < 0) {\n                throw new Error('Could not find item in parent items');\n            }\n            return thisItemIndex;\n        }\n\n        return {\n            getChild: function(index) {\n                var items = getOrCreateChildItems(obj, options.childrenProp);\n                return createItemWrapper(items[index], obj, options);\n            },\n            addChild: function(index, newObj, stateObj) {\n                var items = getOrCreateChildItems(obj, options.childrenProp);\n                items.splice(index, null, newObj);\n                options.onAdd(obj, index, newObj, stateObj);\n            },\n            addChildAtEnd: function(newObj, stateObj) {\n                var items = getOrCreateChildItems(obj, options.childrenProp);\n                this.addChild(items.length, newObj, stateObj);\n            },\n            addAbove: function(newObj, stateObj) {\n                if (!parent) {\n                    throw new Error('Cannot add above the root item');\n                }\n                var parentItems = getOrCreateChildItems(parent, options.childrenProp);\n                var thisItemIndex = getItemIndexOrThrow(parentItems, obj);\n                parentItems.splice(thisItemIndex, 0, newObj);\n                options.onAdd(parent, thisItemIndex, newObj, stateObj);\n            },\n            addBelow: function(newObj, stateObj) {\n                if (!parent) {\n                    throw new Error('Cannot add below the root item');\n                }\n                var parentItems = getOrCreateChildItems(parent, options.childrenProp);\n                var thisItemIndex = getItemIndexOrThrow(parentItems, obj);\n                parentItems.splice(thisItemIndex + 1, 0, newObj);\n                options.onAdd(parent, thisItemIndex + 1, newObj, stateObj);\n            },\n            remove: function() {\n                var parentItems = getOrCreateChildItems(parent, options.childrenProp);\n                var thisItemIndex = getItemIndexOrThrow(parentItems, obj);\n                var removed = parentItems.splice(thisItemIndex, 1);\n                if (removed.length) {\n                    options.onRemove(parent, thisItemIndex, removed[0]);\n                }\n            },\n            removeChild: function(index) {\n                var items = getOrCreateChildItems(obj, options.childrenProp);\n                var removed = items.splice(index, 1);\n                if (removed.length) {\n                    options.onRemove(obj, index, removed[0]);\n                }\n                return removed[0];\n            },\n            moveChild: function(removeIndex, insertIndexOrNewParent, newParentInsertIndex) {\n                if (insertIndexOrNewParent == this) {\n                    throw new Error('Cannot move an item under itself');\n                }\n\n                var items = getOrCreateChildItems(obj, options.childrenProp);\n                var removed = items.splice(removeIndex, 1);\n                if (!removed.length) {\n                    return;\n                }\n\n                var removedItem = removed[0];\n\n                if (typeof insertIndexOrNewParent === 'number') {\n                    items.splice(insertIndexOrNewParent, null, removedItem);\n                    options.onMove(obj, removeIndex, obj, insertIndexOrNewParent, removedItem);\n                } else {\n                    var newParent = insertIndexOrNewParent.unwrap();\n\n                    var newParentItems = getOrCreateChildItems(newParent, options.childrenProp);\n                    newParentItems.splice(newParentInsertIndex, null, removedItem);\n\n                    options.onMove(obj, removeIndex, newParent, newParentInsertIndex, removedItem);\n                }\n            },\n            unwrap: function() {\n                return obj;\n            },\n            traverse: function(callback) {\n                traverse(obj, parent, 0, 0, options.childrenProp, callback);\n            }\n        };\n    }\n\n    function traverseSimple(item, parent, childrenProp, callback) {\n        callback(item, parent);\n\n        var children = item[childrenProp];\n        if (!children) {\n            return;\n        }\n\n        for (var i = 0; i < children.length; i++) {\n            var child = children[i];\n            traverseSimple(child, item, childrenProp, callback);\n        }\n    }\n\n    function traverse(item, parent, index, depth, childrenProp, callback) {\n        callback(item, parent, index++, depth);\n\n        var children = item[childrenProp];\n        if (!children) {\n            return index;\n        }\n\n        for (var i = 0; i < children.length; i++) {\n            var child = children[i];\n            index = traverse(child, item, index, depth + 1, childrenProp, callback);\n        }\n\n        return index;\n    }\n\n    function getOrCreateChildItems(obj, childrenProp) {\n        var arr = obj[childrenProp];\n        if (!arr) {\n            arr = [];\n            obj[childrenProp] = arr;\n        }\n        return arr;\n    }\n}));\n"]}