text: /**
   * @license
   * Copyright (c) 2014, 2018, Oracle and/or its affiliates.
   * The Universal Permissive License (UPL), Version 1.0
   */
  "use strict";define(["ojs/ojcore","jquery","ojs/ojcomponentcore","ojs/ojanimation","ojs/ojkeyset","ojdnd"],function(e,t){var n={properties:{currentItem:{type:"any",writeback:!0,readOnly:!0},data:{type:"oj.TreeDataSource"},dnd:{type:"object",properties:{drag:{type:"object",properties:{items:{type:"object",properties:{dataTypes:{type:"string|Array<string>"},dragStart:{type:"function"},drag:{type:"function"},dragEnd:{type:"function"}}}}},drop:{type:"object",properties:{items:{type:"object",properties:{dataTypes:{type:"string|Array<string>"},dragEnter:{type:"function"},dragOver:{type:"function"},dragLeave:{type:"function"},drop:{type:"function"}}}}}}},expanded:{type:"KeySet",writeback:!0,value:"new ExpandedKeySet()"},item:{type:"object",properties:{focusable:{type:"function",properties:{componentElement:{type:"Element"},data:{type:"D"},depth:{type:"number"},index:{type:"number"},key:{type:"K"},leaf:{type:"boolean"},parentElement:{type:"Element"},parentKey:{type:"K"}}},renderer:{type:"function",properties:{componentElement:{type:"Element"},data:{type:"D"},depth:{type:"number"},index:{type:"number"},key:{type:"K"},leaf:{type:"boolean"},parentElement:{type:"Element"},parentKey:{type:"K"}}},selectable:{type:"function",properties:{componentElement:{type:"Element"},data:{type:"D"},depth:{type:"number"},index:{type:"number"},key:{type:"K"},leaf:{type:"boolean"},parentElement:{type:"Element"},parentKey:{type:"K"}}}}},selection:{type:"Array<any>",writeback:!0,value:[]},selectionMode:{type:"string",enumValues:["multiple","none","single"],value:"none"},translations:{type:"object",value:{}}},methods:{getContextByNode:{},refresh:{},setProperty:{},getProperty:{},setProperties:{},getNodeBySubId:{},getSubIdByNode:{}},events:{ojAnimateEnd:{},ojAnimateStart:{},ojBeforeCollapse:{},ojBeforeCurrentItem:{},ojBeforeExpand:{},ojCollapse:{},ojExpand:{}},extension:{}};e.__registerWidget("oj.ojTreeView",t.oj.baseComponent,{version:"1.0.0",defaultElement:"<div>",widgetEventPrefix:"oj",options:{currentItem:null,data:null,dnd:{drag:null,drop:null},expanded:new e.ExpandedKeySet,item:{focusable:null,renderer:null,selectable:null},selection:[],selectionMode:"none",animateEnd:null,animateStart:null,beforeCollapse:null,beforeCurrentItem:null,beforeExpand:null,collapse:null,expand:null},_ComponentCreate:function(){this._super()},_AfterCreate:function(){this._super(),this._initRender(),this._render()},_initRender:function(){var e=this;this._on(this.element,{click:function(t){e._handleClick(t)},mouseover:function(t){e._handleMouseOver(t)},mouseout:function(t){e._handleMouseOut(t)},mousedown:function(t){e._handleMouseDown(t)},mouseup:function(t){e._handleMouseUp(t)},keydown:function(t){e._handleKeyDown(t)},dragstart:function(t){e._handleDragStart(t)},drag:function(t){e._handleDragSourceEvent(t,"drag")},dragend:function(t){e._handleDragSourceEvent(t,"dragEnd")},dragenter:function(t){e._handleDropTargetEvent(t,"dragEnter")},dragover:function(t){e._handleDropTargetEvent(t,"dragOver")},dragleave:function(t){e._handleDropTargetEvent(t,"dragLeave")},drop:function(t){e._handleDropTargetEvent(t,"drop")}});var n=t(document.createElement("span")).addClass("oj-treeview-drop-marker-icon oj-component-icon");this._dropMarker=t(document.createElement("div")).addClass("oj-treeview-drop-marker").append(n).appendTo(this.element),this._dropMarkerRect=this._dropMarker[0].getBoundingClientRect(),this._dropMarker.hide(),this._dropLine=t(document.createElement("div")).addClass("oj-treeview-drop-line").appendTo(this.element),this._dropLineRect=this._dropLine[0].getBoundingClientRect(),this._dropLine.hide()},_render:function(){var e=this;this.element.removeClass("oj-complete"),this._keyList=new Set,this.options.data?(this.element.find("ul").remove(),this._fetchChildren(null,function(t){e._renderItems(t,e.element),e._resetFocus(),e.element.addClass("oj-complete")})):(this.element.find("ul").addClass("oj-treeview-list").attr("role","group"),this.element.find("li").each(function(){var n=t(this);e._decorateItem(n)}),this._resetFocus(),this.element.addClass("oj-complete")),this._decorateTree(),this._lastSelectedItem=null},_fetchChildren:function(t,n){var i=this.options.data,s={start:0,count:i.getChildCount(t)},r=this._addBusyState("fetching data");i.fetchChildren(t,s,{success:function(e){n(e),r()},error:function(t){e.Logger.error(t),r()}})},_renderItems:function(e,n){for(var i=t(document.createElement("ul")).addClass("oj-treeview-list").attr("role","group").appendTo(n),s=0;s<e.getCount();s++)this._renderItem(i,e,s)},_renderItem:function(n,i,s){s+=i.getStart();var r=i.getData(s),o=i.getMetadata(s),a=o.key;if(this._keyList.has(a))throw new Error("JET TreeView nodes should not have duplicated keys: "+a);this._keyList.add(a);var l=this.options.item.renderer;l=this._WrapCustomElementRenderer(l);var d=t(document.createElement("li")).attr("id",a).appendTo(n);if(l){var h={};for(var c in h.parentElement=d,h.index=s,h.data=r,h.datasource=this.options.data,h.parentKey=this._getKey(this._getParentItem(d)),h.component=e.Components.__GetWidgetConstructor(this.element),this._FixRendererContext&&(h=this._FixRendererContext(h)),o)o.hasOwnProperty(c)&&(h[c]=o[c]);var u=l.call(this,h);if(null!=u)if(null===u.parentNode||u.parentNode instanceof DocumentFragment)d.append(u);else if(null!=u.parentNode);else if(u.toString){var p=document.createElement("span");p.appendChild(document.createTextNode(u.toString())),d.append(p)}d=n.children().eq(s),h.parentElement=d,null==d.attr("id")&&d.attr("id",a)}d.data("data",r).data("metadata",o),this._decorateItem(d)},_decorateTree:function(){var e=this,t=this._getRoot();this._focusable({element:t,applyHighlight:!0,setupHandlers:function(t,n){e._focusInHandler=t,e._focusOutHandler=n}}),t.attr("tabIndex",0).on("focus",function(t){e._focusInHandler(e._getItemContent(e._currentItem))}).on("blur",function(t){e._focusOutHandler(e._getItemContent(e._currentItem))}).attr("role","tree").attr("aria-labelledby",this.element.attr("id"));var n=this.options.selectionMode;"none"!=n?t.attr("aria-multiselectable","multiple"==n?"true":"false"):t.removeAttr("aria-multiselectable")},_decorateItem:function(e){e.addClass("oj-treeview-item").attr("role","treeitem");var n=this._getItemContent(e);0==n.length&&((n=t(document.createElement("div")).addClass("oj-treeview-item-content").append(e.contents()).appendTo(e)).children("ul").appendTo(e),n.find(".oj-treeview-item-icon").addClass("oj-treeview-icon")),this._select(e);var i=this._getDragOptions();n.attr("draggable",Object.keys(i).length>0?"true":"false");var s=e.children(".oj-treeview-spacer");0==s.length&&(s=t(document.createElement("ins")).addClass("oj-treeview-icon oj-treeview-spacer").prependTo(e)),this._isLeaf(e)?e.addClass("oj-treeview-leaf"):(this._isInitExpanded(e)?this._expand(e,!1):this._collapse(e,!1),s.addClass("oj-treeview-disclosure-icon oj-component-icon oj-clickable-icon-nocontext oj-default"))},_getItems:function(){return this.element.find(".oj-treeview-item")},_getKey:function(e){var t=e.data("metadata");return t?t.key:e.attr("id")},_getItemByKey:function(e){return this.element.find("li#"+e)},_getItemContent:function(e){return e.children(".oj-treeview-item-content")},_getChildItems:function(e){return e.children(".oj-treeview-list").children(".oj-treeview-item")},_getParentItem:function(e){return e.parent(".oj-treeview-list").parent(".oj-treeview-item")},_getSubtree:function(e){return e.children(".oj-treeview-list")},_getRoot:function(){return this.element.children(".oj-treeview-list")},_isLeaf:function(e){var t=e.data("metadata");return!(t?!t.leaf:this._getSubtree(e).length>0)},_isInitExpanded:function(e){var t=this._getKey(e),n=this.options.expanded;return!(!n||!n.has)&&n.has(t)},_isExpanded:function(e){return e.hasClass("oj-expanded")},_expand:function(e,t,n,i){var s=this;if(!this._isExpanded(e)&&!this._isLeaf(e)){if(t&&!this._trigger("beforeExpand",n,this._getEventPayload(e))&&!1!==i)return;if(this._lastSelectedItem=null,0==this._getSubtree(e).length)return s._fetchChildren(s._getKey(e),function(i){s._renderItems(i,e),s._expandAfterFetch(e,t,n)});s._expandAfterFetch(e,t,n)}},_expandAfterFetch:function(e,t,n){var i=this;e.removeClass("oj-collapsed").addClass("oj-expanded").attr("aria-expanded","true");var s=this._getSubtree(e);if(s.css("max-height","none"),t){var r=this._addBusyState("animating expand");e.addClass("oj-treeview-animated"),this._startAnimation(s,"expand").then(function(){e.removeClass("oj-treeview-animated"),i._trigger("expand",n,i._getEventPayload(e));var t=i.options.expanded.add([i._getKey(e)]);i._userOptionChange("expanded",t,n),r()})}},_collapse:function(e,t,n,i){var s=this;if(!e.hasClass("oj-collapsed")&&!this._isLeaf(e)){if(t&&!this._trigger("beforeCollapse",n,this._getEventPayload(e))&&!1!==i)return;e.removeClass("oj-expanded").addClass("oj-collapsed").attr("aria-expanded","false"),this._lastSelectedItem=null;var r=this._getSubtree(e);if(t){var o=this._addBusyState("animating collapse");e.addClass("oj-treeview-animated"),this._startAnimation(r,"collapse").then(function(){r.css("max-height",0),e.removeClass("oj-treeview-animated"),s._trigger("collapse",n,s._getEventPayload(e));var t=s.options.expanded.delete([s._getKey(e)]);s._userOptionChange("expanded",t,n),o()})}else r.css("max-height",0)}},_startAnimation:function(t,n){this.defaultOptions||(this.defaultOptions=e.ThemeUtils.parseJSONFromFontFamily("oj-treeview-option-defaults"));var i=(this.defaultOptions.animation||{})[n];return e.AnimationUtils.startAnimation(t[0],n,i,this)},_getEventPayload:function(e){return{key:this._getKey(e),item:e[0]}},_isActionable:function(e,t){var n=this.options.item[t+"able"];return!1!==n&&("function"!=typeof n||n(this.getContextByNode(e[0])))},_isSelected:function(e){var t=this.options.selectionMode,n=this.options.selection;if("none"===t)return!1;"single"===t&&n.length>1&&(n=[n[0]]);var i=this._getKey(e);return-1!=n.indexOf(i)},_select:function(t,n){var i=this.options.selectionMode;if("none"!==i&&this._isActionable(t,"select")){var s=this._isSelected(t);if(n){var r=e.DomUtils.isTouchSupported(),o=e.DomUtils.isMetaKeyPressed(n),a="multiple"===i,l=40==n.keyCode||38==n.keyCode,d=this._getKey(t),h=[];if(a&&n.shiftKey&&!l){o?h=this.options.selection.slice(0):this._clearSelection();for(var c=this._lastSelectedItem,u=c&&c.offset().top<t.offset().top?this._getNextActionableItem.bind(this):this._getPreviousActionableItem.bind(this);c&&c[0]!=t[0];){var p=this._getKey(c);-1==h.indexOf(p)&&(h.push(p),this._setSelected(c)),c=u(c,"select")}s=!0,h.push(d)}else a&&(o||r||l)?(s=!s,h=this.options.selection.slice(0),s?h.push(d):h.splice(h.indexOf(d),1)):(this._clearSelection(),(r||32==n.keyCode)&&s?(s=!1,h=[]):(s=!0,h=[d]));this._userOptionChange("selection",h,n),this._lastSelectedItem=t}s?this._setSelected(t):this._setUnselected(t)}},_setSelected:function(e){this._getItemContent(e).addClass("oj-selected"),e.attr("aria-selected","true")},_setUnselected:function(e){this._getItemContent(e).removeClass("oj-selected"),e.attr("aria-selected","false")},_clearSelection:function(){this._setUnselected(this._getItems())},_focus:function(e,t){if(this._isActionable(e,"focus")){if(t){var n=this._getEventPayload(e);if(this._currentItem&&(n.previousKey=this._getKey(this._currentItem),n.previousItem=this._currentItem[0]),!this._trigger("beforeCurrentItem",t,n))return;this._userOptionChange("currentItem",this._getKey(e),t)}this._focusOutHandler(this._getItemContent(this._currentItem)),this._focusInHandler(this._getItemContent(e)),this._setCurrentItem(e)}},_resetFocus:function(){if(this.options.currentItem){var e=this._getItemByKey(this.options.currentItem);if(e.length>0)return void this._setCurrentItem(e)}var t=this._getItems().first();this._setCurrentItem(t),this._userOptionChange("currentItem",this._getKey(this._currentItem),null)},_setCurrentItem:function(e){this._currentItem=e,this._getRoot().attr("aria-activedescendant",this._getKey(e))},_addBusyState:function(t){var n=e.Context.getContext(this.element[0]).getBusyContext(),i=this.element.attr("id");return n.addBusyState({description:"The component identified by '"+i+"', "+t})},_userOptionChange:function(e,t,n){this.option(e,t,{_context:{originalEvent:n,writeback:!0,internalSet:!0}})},_getDragOptions:function(){return((this.options.dnd||{}).drag||{}).items||{}},_getDropOptions:function(){return((this.options.dnd||{}).drop||{}).items||{}},_getClosestItem:function(e){return e.closest(".oj-treeview-item")},_getClosestItemContent:function(e){return e.closest(".oj-treeview-item-content")},_getClosestDisclosureIcon:function(e){return e.closest(".oj-treeview-disclosure-icon")},_handleClick:function(e){var n=this._getClosestDisclosureIcon(t(e.target));if(n.length>0){var i=n.closest(".oj-treeview-item");this._isExpanded(i)?this._collapse(i,!0,e):this._expand(i,!0,e)}else{var s=this._getClosestItemContent(t(e.target));if(s.length>0)return i=s.parent(),this._select(i,e),void this._focus(i,e);"none"!=this.options.selectionMode&&(this._clearSelection(),this._lastSelectedItem=null,this._userOptionChange("selection",[],e))}},_handleMouseOver:function(n){if(!e.DomUtils.isTouchSupported()){var i=this._getClosestDisclosureIcon(t(n.target));0==i.length&&(i=this._getClosestItemContent(t(n.target))),i.removeClass("oj-default"),i.addClass("oj-hover")}},_handleMouseOut:function(n){if(!e.DomUtils.isTouchSupported()){var i=this._getClosestDisclosureIcon(t(n.target));i.removeClass("oj-selected"),0==i.length&&(i=this._getClosestItemContent(t(n.target))),i.addClass("oj-default"),i.removeClass("oj-hover")}},_handleMouseDown:function(e){this._getClosestDisclosureIcon(t(e.target)).addClass("oj-selected")},_handleMouseUp:function(e){this._getClosestDisclosureIcon(t(e.target)).removeClass("oj-selected")},_handleKeyDown:function(e){var t,n=e.keyCode,i=this._currentItem;if(38==n||40==n)(t=40==n?this._getNextActionableItem(i,"focus"):this._getPreviousActionableItem(i,"focus"))&&(e.preventDefault(),this._isSelected(i)&&e.shiftKey&&this._select(this._isSelected(t)?i:t,e),this._focus(t,e));else if(37==n||39==n){var s="rtl"==this._GetReadingDirection(),r=!s&&39==n||s&&37==n;!r||this._isLeaf(i)||this._isExpanded(i)?r||this._isLeaf(i)||!this._isExpanded(i)?(t=r?this._getNextActionableItem(i,"focus"):this._getPreviousActionableItem(i,"focus"))&&(e.preventDefault(),this._focus(t,e)):(e.preventDefault(),this._collapse(i,!0,e)):(e.preventDefault(),this._expand(i,!0,e))}else 13!=n&&32!=n||(e.preventDefault(),this._select(i,e))},_getNextItem:function(e){if(!this._isLeaf(e)&&this._isExpanded(e)){var t=this._getChildItems(e).first();if(t.length>0)return t}for(var n=e;n.length>0;){var i=n.next(".oj-treeview-item");if(i.length>0)return i;n=this._getParentItem(n)}return null},_getNextActionableItem:function(e,t){for(;null!=e;)if(null!=(e=this._getNextItem(e))&&this._isActionable(e,t))return e;return null},_getPreviousItem:function(e){for(var t=e.prev(".oj-treeview-item");t.length>0;){if(this._isLeaf(t)||!this._isExpanded(t))return t;var n=this._getChildItems(t).last();if(!(n.length>0))return t;t=n}var i=this._getParentItem(e);return i.length>0?i:null},_getPreviousActionableItem:function(e,t){for(;null!=e;)if(null!=(e=this._getPreviousItem(e))&&this._isActionable(e,t))return e;return null},_handleDragStart:function(n){var i=this,s="rtl"==this._GetReadingDirection(),r=this._getClosestItem(t(n.target));if(0!=r.length){var o=t();if(this._isSelected(r))for(var a=this.options.selection,l=0;l<a.length;l++)o=o.add(this._getItemByKey(a[l]));else this._select(r,n),o=o.add(r);var d=this._getDragOptions(),h=n.originalEvent.dataTransfer,c=t(document.createElement("ul")).addClass("oj-treeview-drag-image oj-treeview-list");e.AgentUtils.getAgentInfo().browser===e.AgentUtils.BROWSER.SAFARI&&c.css("position","absolute");var u=[],p=1/0,_=1/0;o.each(function(e){var n=t(this);u.push(n.data("data"));var r=n.offset();s&&(r.left=i._getItemContent(n).offset().left);var o=n.clone().css({top:r.top,left:r.left});i._getSubtree(o).remove(),r.top<p&&(p=r.top),r.left<_&&(_=r.left),c.append(o)}),c.children().each(function(){t(this).css({top:parseFloat(t(this).css("top"))-p,left:parseFloat(t(this).css("left"))-_})});var f=d.dataTypes,m="string"==typeof f?[f]:f||[];for(l=0;l<m.length;l++)h.setData(m[l],JSON.stringify(u));t("body").append(c),h.setDragImage(c[0],n.pageX-_,n.pageY-p),setTimeout(function(){c.remove()},0);var g=d.dragStart;g&&g(n.originalEvent,{items:u})}},_handleDragSourceEvent:function(e,t){var n=this._getDragOptions()[t];n&&n(e.originalEvent)},_handleDropTargetEvent:function(e,n){var i=this._getDropOptions(),s=i.dataTypes,r="string"==typeof s?[s]:s||[],o=i[n],a=t(e.target).closest(".oj-treeview-item"),l=a.children(".oj-treeview-spacer")[0],d=l.getBoundingClientRect(),h=l.offsetTop,c=l.offsetLeft,u=h+d.height/2,p="inside",_=e.pageY-d.top;_<.25*d.height?p="before":_>.75*d.height&&(p=this._isExpanded(a)?"first":"after"),o&&o(e.originalEvent,{item:a[0],position:p});for(var f=0;f<r.length;f++){var m=e.originalEvent.dataTransfer.types;if(m&&m.indexOf(r[f])>=0){e.preventDefault();break}}if("dragEnter"!=n&&"dragOver"!=n||!e.originalEvent.defaultPrevented)this._dropMarker.hide(),this._dropLine.hide();else{var g="rtl"==this._GetReadingDirection(),v=u,y=g?c-this._dropLineRect.width:c+d.width,C=u-this._dropMarkerRect.height/2,I=c+d.width/2-this._dropMarkerRect.width/2;if("before"==p)C-=d.height/2,v-=d.height/2;else if(("after"==p||"first"==p)&&(C+=d.height/2,v+=d.height/2,"first"==p)){var j=(g?-1:1)*d.width;I+=j,y+=j}this._dropMarker.css("top",C+"px").css("left",I+"px").show(),"inside"!=p?this._dropLine.css("top",v+"px").css("left",y+"px").show():this._dropLine.hide()}},_NotifyContextMenuGesture:function(e,t,n){if("keyboard"===n){var i=this._currentItem?this._getItemContent(this._currentItem):this.element,s={launcher:i,initialFocus:"menu",position:{my:"start top",at:"start bottom",of:i}};this._OpenContextMenu(t,n,s)}else this._superApply(arguments)},refresh:function(){this._super(),this._render()},getNodeBySubId:function(e){if(null==e)return this.element?this.element[0]:null;var t,n=e.key,i=e.subId,s=this._getItemByKey(n);return"oj-treeview-disclosure"===i?t=s.children(".oj-treeview-disclosure-icon")[0]:"oj-treeview-item"===i&&(t=s.children(".oj-treeview-item-content")[0]),t||null},getSubIdByNode:function(e){if(!t.contains(this.element[0],e))return null;var n,i=this._getClosestDisclosureIcon(t(e)),s=this._getClosestItem(t(e));if(i.length>0)n="oj-treeview-disclosure";else{if(!(s.length>0))return null;n="oj-treeview-item"}return{subId:n,key:this._getKey(s)}},getContextByNode:function(n){if(!t.contains(this.element[0],n))return null;var i=this._getClosestItem(t(n));if(i.length<1)return null;var s={subId:"oj-treeview-item"};s.index=i.parent().children(".oj-treeview-item").index(i),s.parentKey=this._getKey(this._getParentItem(i)),s.component=e.Components.__GetWidgetConstructor(this.element),this._FixRendererContext&&(s=this._FixRendererContext(s));var r=i.data("metadata");if(r)for(var o in s.data=i.data("data"),s.datasource=this.options.data,r)r.hasOwnProperty(o)&&(s[o]=r[o]);else s.key=this._getKey(i),s.leaf=this._isLeaf(i),s.depth=i.parents(".oj-treeview-list").length;return s},_setOption:function(e,n,i){var s=this;if(this._superApply(arguments),"expanded"==e)this._getItems().each(function(){var e=t(this);s._isInitExpanded(e)?s._expand(e,!0):s._collapse(e,!0)});else if("selection"==e)this._getItems().each(function(){var e=t(this);s._select(e)});else{if("currentItem"!=e)return void this.refresh();this._resetFocus()}},_destroy:function(){this._super()}}),n.extension._WIDGET_NAME="ojTreeView",e.CustomElementBridge.registerMetadata("oj-tree-view","baseComponent",n),e.CustomElementBridge.register("oj-tree-view",{metadata:e.CustomElementBridge.getMetadata("oj-tree-view")})});