PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / trunk
bBlocks – Essential Gutenberg Blocks & Patterns Collection vtrunk
2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 106 releases
b-blocks / build / chart / view.js

view.js in bBlocks – Essential Gutenberg Blocks & Patterns Collection trunk, at build/chart/view.js

1 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (()=>{"use strict";const t=window.ReactDOM,e=window.React,n="linear-gradient(135deg, #0040E3, #18D4FD)",r=t=>{const e=(t=>{try{const e=new URL(t);return["http:","https:"].includes(e.protocol)?e.toString():null}catch(e){return"string"==typeof t&&t.startsWith("/")&&!t.startsWith("//")?t:null}})(t);return e?`url('${e.replace(/['"()]/g,"")}')`:"none"},o=(t,e)=>{return null==(n=e)||""===n||Array.isArray(n)&&0===n.length||"object"==typeof n&&0===Object.keys(n).length||"string"==typeof n&&""===n.trim()||"number"==typeof n&&0===n?"":`${t}: ${e};`;var n},i=(t,e=!0,i=!0,a=!0)=>{const{type:s="solid",color:l="",gradient:c=n,image:d={},position:u="center center",attachment:b="",repeat:g="no-repeat",size:p="",overlayColor:h=""}=t||{};return"gradient"===s&&i?o("background",c):"image"===s&&a?`background: ${r(d?.url)};\n\t\t\t\t${o("background-color",h)}\n\t\t\t\t${o("background-position",u)}\n\t\t\t\t${o("background-size",p)}\n\t\t\t\t${o("background-repeat",g)}\n\t\t\t\t${o("background-attachment",b)}\n\t\t\t\t${o("background-repeat",g)}\n\t\t\t\tbackground-blend-mode: overlay;`:e&&o("background",l)},a="bBlocksChart",s=window.ReactJSXRuntime,l=({attributes:t,id:e})=>{const{background:n,width:r,height:o,alignment:l}=t,c=`#${e}`,d=`${c} .${a}`;return(0,s.jsx)("style",{dangerouslySetInnerHTML:{__html:`\n\t\t${c}{\n\t\t\ttext-align: ${l};\n\t\t}\n\t\t${d}{\n\t\t\theight: ${o};\n\t\t}\n\t\t${d},\n\t\t${c} .downloadArea{\n\t\t\twidth: ${r};\n\t\t}\n\t\t${d} canvas{\n\t\t\t${i(n)};\n\t\t}\n\t\t`.replace(/\s+/g," ")}})},c=({attributes:t,id:n,isBackend:r=!1})=>{const{data:o,type:i,textColor:l,isXScale:c,isXGridLine:d,isYScale:u,isYGridLine:b,gridLineColor:g,isTitle:p,title:h,titleFontSize:y,titleColor:m,isSubtitle:$,subtitle:k,subtitleFontSize:w,subtitleColor:S,isDownload:f}=t,v=(0,e.useRef)(null),x=(0,e.useRef)(null),C=r?[o,i,l,c,d,u,b,g,p,h,y,m,$,k,w,S,f,v.current]:[];return(0,e.useEffect)((()=>{r&&(v.current.innerHTML="",v.current.innerHTML="<canvas>Your browser does not support the canvas element.</canvas>");const e=v.current.ownerDocument,o=e.querySelector(`#${n} .${a} canvas`),i=o&&new Chart(o,(t=>{const{data:e,type:n,textColor:r,isXScale:o,isXGridLine:i,isYScale:a,isYGridLine:s,gridLineColor:l,isTitle:c,title:d,titleFontSize:u,titleColor:b,isSubtitle:g,subtitle:p,subtitleFontSize:h,subtitleColor:y}=t;return{type:n,data:e,options:{maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{usePointStyle:!0,color:r}},title:{display:c,text:d,color:b,font:{size:u,family:"Roboto"},padding:{bottom:10}},subtitle:{display:g,text:p,color:y,font:{size:h,family:"Roboto"},padding:{bottom:15}},tooltip:{position:"nearest",usePointStyle:!0}},scales:{x:{display:o,ticks:{color:r},grid:{display:i,color:l}},y:{display:a,beginAtZero:!0,ticks:{color:r},grid:{display:s,color:l}}}}}})(t));f&&x?.current.addEventListener("click",(()=>{const t=e.createElement("a");t.href=i.toBase64Image(),t.download="b-chart.png",t.click()}))}),C),(0,s.jsxs)(s.Fragment,{children:[f&&(0,s.jsx)("div",{className:"downloadArea",children:(0,s.jsx)("div",{className:"downloadChart",ref:x,children:"Download Chart"})}),(0,s.jsx)("div",{className:a,ref:v,children:(0,s.jsx)("canvas",{children:"Your browser does not support the canvas element."})})]})};document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll(".wp-block-b-blocks-chart").forEach((e=>{const n=JSON.parse(e.dataset.attributes);(0,t.createRoot)(e).render((0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l,{attributes:n,id:e.id}),(0,s.jsx)(c,{attributes:n,id:e.id})]})),e?.removeAttribute("data-attributes")}))}))})();