Files
ai/charting_library/bundles/chart-text-editor-renderer.a3a661287608e2046b5b.js

2 lines
4.0 KiB
JavaScript

(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[269],{69947:(e,t,n)=>{"use strict";n.d(t,{useIsomorphicLayoutEffect:()=>a});var o=n(79474);function a(e,t){("undefined"==typeof window?o.useEffect:o.useLayoutEffect)(e,t)}},52607:(e,t,n)=>{"use strict";n.d(t,{useProperty:()=>a});var o=n(79474);const a=e=>{const[t,n]=(0,o.useState)(e.value());return(0,o.useEffect)((()=>{const t=e=>{n(e.value())};t(e);const o={};return e.subscribe(o,t),()=>e.unsubscribe(o,t)}),[e]),t}},57069:(e,t,n)=>{"use strict";n.d(t,{useWatchedValueReadonly:()=>u});var o=n(79474),a=n(69947);const u=(e,t=!1,n=[])=>{const u="watchedValue"in e?e.watchedValue:void 0,r="defaultValue"in e?e.defaultValue:e.watchedValue.value(),[i,c]=(0,o.useState)(u?u.value():r);return(t?a.useIsomorphicLayoutEffect:o.useEffect)((()=>{if(u){c(u.value());const e=e=>c(e);return u.subscribe(e),()=>u.unsubscribe(e)}return()=>{}}),[u,...n]),i}},88002:(e,t,n)=>{"use strict";n.d(t,{useWatchedValue:()=>a});var o=n(79474);const a=(e,t=[])=>{const[n,a]=(0,o.useState)(e.value());return(0,o.useEffect)((()=>{const t=e=>a(e);return e.subscribe(t),()=>e.unsubscribe(t)}),[e,...t]),[n,t=>e.setValue(t)]}},78889:e=>{e.exports={padding:"2",textArea:"textArea-pBDekXDd"}},5443:(e,t,n)=>{"use strict";n.d(t,{closeChartEditorText:()=>x,updateChartEditorText:()=>_});var o=n(79474),a=n(29365),u=n(85842),r=n(63484),i=n(57069),c=n(88002),s=n(52607),l=n(23351),d=n(22384),f=n(78889);const v=parseInt(f.padding);var h;!function(e){e[e.Hotkey=0]="Hotkey",e[e.Blur=1]="Blur"}(h||(h={}));const p=new Map([["10b_2",.15],["10bi_2",.15],["12_3",.8],["12b_2",.5],["12bi_2",.45],["14b_2",.65],["14bi_2",.65],["16_2.5",.8],["16b_2",.8],["16bi_2",.75],["16b_2.5",.8],["16bi_2.5",.75],["16bi_3",.65],["20_2",1],["20b_2",.8],["20bi_2",.75],["20bi_3",.55],["20_2.5",.25],["20_3",.8],["24_2.5",.95],["24_3",.95],["28_2",1.4],["28_2.5",1.38],["28_3",1.38],["32_2",1.6],["32_2.5",1.6],["32_3",1.6]]),b=new d.Property(!1);function m(e){const{text:t,wordWrap:n=b,textInfo:a,placeholder:d,forbidLineBreaks:h,maxLength:m,onClose:x,onSelectionChange:_,onContextMenu:g}=e,[E,w]=(0,c.useWatchedValue)(t),y=(0,s.useProperty)(n),S=(0,i.useWatchedValueReadonly)({watchedValue:a}),{font:C,fontSize:L,textLeft:V,textTop:M,textBottom:R,textRight:k,textAlign:P,centerRotation:A,lineSpacing:B}=(0,u.ensureNotNull)((0,u.ensureDefined)(S)),D=Math.ceil(k-V)+1,W=Math.ceil(R-M);let I,N,F=0;void 0===A||0===A.angle?(I=Math.round(M),N=Math.round(V)):(N=A.x-D/2,I=A.y-W/2,F=A.angle);const H=C.includes("bold")?"b":"",T=C.includes("italic")?"i":"",$=devicePixelRatio<=2||devicePixelRatio>=3?devicePixelRatio:devicePixelRatio<2.5?2:2.5,q=p.get(L+H+T+"_"+$),z=(0,o.useRef)(null),[K,U]=(0,o.useState)(!0),X=(0,o.useMemo)((()=>performance.now()),[]);return(0,o.useEffect)((()=>{const e=()=>{const e=z.current;e&&_({start:e.selectionStart,end:e.selectionEnd})};return document.addEventListener("mousemove",e),document.addEventListener("touchmove",e),e(),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("touchmove",e)}}),[]),
o.createElement("textarea",{ref:z,placeholder:d,style:{width:D+2*v,height:W+2*v,top:I-v,left:N-v,font:C,lineHeight:`${L+B}px`,textAlign:P,letterSpacing:y?q+"px":"normal",rotate:F?`${F}rad`:void 0},maxLength:m,className:f.textArea,"data-name":"text-editor","data-qa-id":"inplace-text-editor",value:E,onClick:e=>j(e),onMouseDown:e=>function(e){U(!1),j(e)}(e),onMouseUp:e=>function(e){if(K)return void U(!1);j(e)}(e),onChange:function(e){w(e.target.value),_({start:e.target.selectionStart,end:e.target.selectionEnd})},onFocus:e=>function(e){const t=E.length;e.setSelectionRange(t,t)}(e.target),onBlur:()=>x(1),onKeyDown:function(e){const t=(0,l.hashFromEvent)(e);(27===t||h&&13===t)&&x(0)},onSelect:function(e){const t=e.target;_({start:t.selectionStart,end:t.selectionEnd})},onContextMenu:async function(e){if(!g)return;(0,r.preventDefault)(e),g(e)},autoFocus:!0});function j(e){performance.now()-X>500&&e.stopPropagation()}}function x(e){a.unmountComponentAtNode(e)}function _(e,t){a.render(o.createElement(m,{...t}),e)}}}]);