Files
ai/charting_library/bundles/global-toasts.4e2377e6bac59b8285e6.js
2023-02-02 13:31:14 +00:00

3 lines
8.5 KiB
JavaScript

(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[4291],{7881:t=>{t.exports={"toast-wrapper":"toast-wrapper-LaQcqQbu",compact:"compact-LaQcqQbu"}},99062:t=>{t.exports={"toast-positioning-wrapper":"toast-positioning-wrapper-uEa3054V",compact:"compact-uEa3054V","location-bottom-left":"location-bottom-left-uEa3054V","location-bottom-right":"location-bottom-right-uEa3054V",hidden:"hidden-uEa3054V",added:"added-uEa3054V"}},56139:(t,e,o)=>{"use strict";o.r(e),o.d(e,{globalToasts:()=>M,showToast:()=>E});var s=o(59496),a=o(97754),i=o(87995),n=o(9423),r=o(65718),h=o(50655),d=o(88216),u=o(36947),g=o(65355);class c{constructor(t){this._animationStage=g.ToastAnimationStage.Add,this._keys=new Map,this._element=null,this.render=t=>this._render(t),this.remove=()=>this._currentToastsLayer.removeToast(this);const{priority:e,origin:o,currentLayer:s,onLayerChange:a,render:i,onMouseOver:n,onMouseOut:r}=t;this._staticData=Object.freeze({priority:e,origin:o,onLayerChange:a,onMouseOver:n,onMouseOut:r}),this._currentToastsLayer=s||o,this._render=i}getStaticData(){return this._staticData}migrate(t){this._currentToastsLayer=t,this._animationStage=g.ToastAnimationStage.Add}getCurrentLayer(){return this._currentToastsLayer}isForeign(){return this._staticData.origin!==this._currentToastsLayer}getAnimationStage(){return this._animationStage}setAnimationStage(t){this._animationStage=t}setKey(t,e){this._keys.set(t,e)}getKey(t=this._currentToastsLayer){return this._keys.get(t)}getElement(){return this._element}setElement(t){this._element=t}}var l=o(99062);const m={position:"fixed",left:"0",bottom:"0",right:"0",zIndex:145};class _{constructor(t,e,o=m,s){this._toasts={[g.ToastPriority.Low]:[],[g.ToastPriority.Medium]:[],[g.ToastPriority.High]:[]},this._container=void 0!==e?e:document.body,this._suggestedLayout=void 0!==t?t:"loose",this._location=null!=s?s:"bottom-left",this._manager=new d.OverlapManager(document),this._overlapManagerContainer=function(t,e={}){const o=t.createElement("div");return o.dataset.role="toast-container",p(o,{...m,...e}),o}(document,o),this._manager.setContainer(this._overlapManagerContainer),this._container.appendChild(this._overlapManagerContainer),this._detachedContainer=document.createElement("div")}showToast(t){const{render:e,priority:o=g.ToastPriority.Medium,index:s,origin:a=this,onLayerChange:i,onMouseOver:n,onMouseOut:r}=t,h=new c({priority:o,origin:a,currentLayer:this,render:e,onLayerChange:i,onMouseOver:n,onMouseOut:r}),d=this._getNextKey();return h.setKey(this,d),"compact"===this._suggestedLayout&&o===g.ToastPriority.Low?Promise.all(this._toasts[g.ToastPriority.Low].map(t=>this.removeToast(t))).then(()=>{this._add(h,s),this._render()}):(this._add(h,s),this._render()),h}showExistingToast(t){const e=this._getNextKey();return t.setKey(this,e),this._add(t),this._render(),t}removeToast(t){return new Promise(e=>{t.setAnimationStage(g.ToastAnimationStage.Remove),this._render(),setTimeout(()=>{this._remove(t),this._render(),e()},250)})}update(t){
const{suggestedLayout:e,location:o,container:s,rootContainerOptions:a}=t;let i=!1,n=!1;void 0!==e&&e!==this._suggestedLayout&&(this._setSuggestedLayout(e),i=!0),void 0!==o&&(this._setLocation(o),n=!0),void 0!==s&&(this._setContainer(s),n=!0),void 0!==a&&(this._updateRootContainer(a),n=!0),i?"compact"===this._suggestedLayout&&this._toasts[g.ToastPriority.Low].slice(0,-1).forEach(t=>this.removeToast(t)):n&&this._render()}getToasts(){return this._toasts}forceRender(){this._render()}merge(t){y(t.getToasts()).forEach(async e=>{const o=e.getStaticData();await e.remove(),e.migrate(this),this.showExistingToast(e),void 0!==o.onLayerChange&&o.onLayerChange(t,this)})}split(t){y(this._toasts).filter(t=>t.isForeign()).forEach(async e=>{const o=e.getStaticData();await e.remove(),e.migrate(t),t.showExistingToast(e),void 0!==o.onLayerChange&&o.onLayerChange(this,t)})}reset(){this._toasts={[g.ToastPriority.Low]:[],[g.ToastPriority.Medium]:[],[g.ToastPriority.High]:[]},this._render()}destroy(){this._removeRootContainer()}_removeRootContainer(){i.unmountComponentAtNode(this._detachedContainer),this._detachedContainer.remove(),this._overlapManagerContainer.remove()}_getToastsList(t){const e=t.getStaticData().priority;return this._toasts[e]}_normalizeIndex(t,e){return t<0?0:t>e.length?e.length:t}_add(t,e){const o=this._getToastsList(t);if(void 0!==e){const s=this._normalizeIndex(e,o);o.splice(s,0,t)}else o.push(t)}_remove(t){const e=this._getToastsList(t),o=e.indexOf(t);o>=0&&e.splice(o,1)}_render(){const t=y(this._toasts);i.render(s.createElement(T,{toasts:t,suggestedLayout:this._suggestedLayout,location:this._location,manager:this._manager,layer:this}),this._detachedContainer)}_setSuggestedLayout(t){t!==this._suggestedLayout&&(this._suggestedLayout=t)}_setLocation(t){t!==this._location&&(this._location=t)}_setContainer(t){t!==this._container&&(this._container=t,this._container.appendChild(this._overlapManagerContainer))}_updateRootContainer(t){p(this._overlapManagerContainer,t)}_getNextKey(){return(0,n.randomHashN)(5)}}function y(t){return[...t[g.ToastPriority.Low],...t[g.ToastPriority.Medium],...t[g.ToastPriority.High]]}function p(t,e){const{top:o,right:s,bottom:a,left:i,position:n,zIndex:r}=e;void 0!==n&&(t.style.position=n),void 0!==r&&(t.style.zIndex=String(r)),void 0!==o&&(t.style.top=o),void 0!==s&&(t.style.right=s),void 0!==a&&(t.style.bottom=a),void 0!==i&&(t.style.left=i)}function L(t,e,o){return t.getKey(o)||e.toString(10)}function v(t){const{toast:e,toasts:o,layer:i,suggestedLayout:n,location:h,forceRender:d}=t,u=(0,s.useRef)(null),c=e.getAnimationStage(),m=c!==g.ToastAnimationStage.None,_=c===g.ToastAnimationStage.Add,y=function(t,e,o){var s;const a=e.indexOf(t),i=L(t,a,o);let n=0;for(const t of e){const r=e.indexOf(t),h=L(t,r,o),d=(null===(s=t.getElement())||void 0===s?void 0:s.offsetHeight)||0,u=t.getAnimationStage()!==g.ToastAnimationStage.None;let c=0;u&&h===i?c=1:!u&&a<r&&(c=-1),n+=c*d}return n}(e,o,i),p=a(l["toast-positioning-wrapper"],m&&l.hidden,_&&l.added,"compact"===n&&l.compact,h&&l["location-"+h]);return(0,
s.useEffect)(()=>{if(e.getCurrentLayer()!==i||e.getAnimationStage()!==g.ToastAnimationStage.Add||null===u.current)return;const t=e.getElement();null===t||t!==u.current?(e.setElement(u.current),d()):(e.setAnimationStage(g.ToastAnimationStage.None),d())}),s.createElement(r.Portal,{layerOptions:{position:"absolute"},left:"0",right:"0"},s.createElement("div",{onMouseOver:e.getStaticData().onMouseOver,onMouseOut:e.getStaticData().onMouseOut,className:p,style:{transform:`translateY(${y}px)`},ref:u},e.render({onRemove:e.remove,suggestedLayout:n})))}function T(t){const{toasts:e,suggestedLayout:o,location:a,manager:i,layer:n}=t,r=(0,u.useForceUpdate)();return s.createElement(h.SlotContext.Provider,{value:i},e.map((t,i)=>s.createElement(v,{key:L(t,i,n),toast:t,toasts:e,layer:n,suggestedLayout:o,location:a,forceRender:r})))}var f=o(86240),C=o(7881);const w=f["media-mf-phone-landscape"];function S(t){const{suggestedLayout:e,children:o}=t;return s.createElement("div",{className:a(C["toast-wrapper"],"compact"===e&&C.compact)},o)}const M=new class{constructor(){var t;this._mediaQuery=window.matchMedia(w),this._handleMediaQueryChange=()=>{this._toastsLayer.update({suggestedLayout:this._getSuggestedLayout()})},this._handleLoginStateChange=()=>{this._toastsLayer.update({location:this._getLocation()})},this._toastsLayer=new _(this._getSuggestedLayout(),void 0,void 0,this._getLocation()),this._mediaQuery.addListener(this._handleMediaQueryChange),null===(t=window.loginStateChange)||void 0===t||t.subscribe(this,this._handleLoginStateChange)}destroy(){var t;this._toastsLayer.destroy(),this._mediaQuery.removeListener(this._handleMediaQueryChange),null===(t=window.loginStateChange)||void 0===t||t.unsubscribe(this,this._handleLoginStateChange)}showCustomToast(t){const{render:e,...o}=t;var a;return this._toastsLayer.showToast({render:(a=e,t=>s.createElement(S,{suggestedLayout:t.suggestedLayout,children:a(t)})),...o}).remove}reset(){this._toastsLayer.reset()}forceRender(){this._toastsLayer.forceRender()}merge(t){this._toastsLayer.merge(t)}split(t){this._toastsLayer.split(t)}_getSuggestedLayout(){return this._mediaQuery.matches?"loose":"compact"}_getLocation(){return"bottom-left"}};function E(t){return M.showCustomToast(t)}},36947:(t,e,o)=>{"use strict";o.d(e,{useForceUpdate:()=>a});var s=o(59496);const a=()=>{const[,t]=(0,s.useReducer)((t,e)=>t+1,0);return t}},65355:(t,e,o)=>{"use strict";var s,a;o.d(e,{ToastAnimationStage:()=>s,ToastPriority:()=>a}),function(t){t[t.Add=0]="Add",t[t.Remove=1]="Remove",t[t.None=2]="None"}(s||(s={})),function(t){t[t.Low=0]="Low",t[t.Medium=1]="Medium",t[t.High=2]="High"}(a||(a={}))}}]);