diff --git a/blocks/bar-graph/build/index.asset.php b/blocks/bar-graph/build/index.asset.php index 61f16cf..1d2a55f 100644 --- a/blocks/bar-graph/build/index.asset.php +++ b/blocks/bar-graph/build/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '79dffd7b201fcf20bc7c'); + array('react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'c6994dab2419d48d7900'); diff --git a/blocks/bar-graph/build/index.js b/blocks/bar-graph/build/index.js index 198c680..4681ccf 100644 --- a/blocks/bar-graph/build/index.js +++ b/blocks/bar-graph/build/index.js @@ -1 +1 @@ -(()=>{"use strict";var t,n={126:()=>{const t=window.wp.blocks,n=window.wp.i18n,e=window.wp.blockEditor,r=window.wp.components,i=window.wp.element,o=window.ReactJSXRuntime,a=["#FF6384","#36A2EB","#FFCE56","#4BC0C0","#9966FF","#FF9F40","#FF6384","#C9CBCF","#4BC0C0","#FF9F40"],l=({value:t,onChange:l,dataSource:s,onDataSourceChange:u})=>{const[c,h]=(0,i.useState)(""),[f,d]=(0,i.useState)(""),[p,g]=(0,i.useState)("");(0,i.useEffect)((()=>{if(t&&Object.keys(t).length>0)if("manual_json"===s)d(JSON.stringify(t,null,2));else if("csv_url"===s){const n=t[Object.keys(t)[0]]?.[0]?.sourceUrl;n&&h(n)}}),[]);const m=[{label:(0,n.__)("Manual JSON","lcp"),value:"manual_json"},{label:(0,n.__)("CSV Upload","lcp"),value:"csv_upload"},{label:(0,n.__)("CSV URL","lcp"),value:"csv_url"}],v=(t,n="")=>{try{const e=t.split("\n");if(e.length<2)throw new Error("CSV must have at least a header row and one data row");const r=e[0].split(",").map((t=>t.trim()));if(!r.includes("label")||!r.includes("value"))throw new Error('CSV must have "label" and "value" columns');const i={"Dataset 1":e.slice(1).filter((t=>t.trim())).map(((t,e)=>{const i=t.split(",").map((t=>t.trim())),o={};return r.forEach(((t,n)=>{"color"!==t||i[n]?o[t]=i[n]:o[t]=a[e%a.length]})),n&&(o.sourceUrl=n),o}))};return g(""),i}catch(t){return g("Error parsing CSV: "+t.message),null}};return(0,o.jsxs)("div",{className:"lcp-data-selector",children:[(0,o.jsx)(r.SelectControl,{label:(0,n.__)("Data Source","lcp"),value:s,options:m,onChange:u}),"manual_json"===s&&(0,o.jsx)(r.TextareaControl,{label:(0,n.__)("JSON Data","lcp"),help:(0,n.__)("Enter datasets with arrays containing objects with label and value properties. Color is optional.","lcp"),value:f,onChange:t=>{d(t);const n=(t=>{try{const n=JSON.parse(t);if("object"!=typeof n||Array.isArray(n))throw new Error("Data must be an object with dataset names as keys");return Object.entries(n).forEach((([t,n])=>{if(!Array.isArray(n))throw new Error(`Dataset "${t}" must be an array`);n.forEach(((n,e)=>{if(!n.label||!n.value)throw new Error(`Item at index ${e} in dataset "${t}" is missing required fields (label or value)`);n.color||(n.color=a[e%a.length])}))})),g(""),n}catch(t){return g(t.message),null}})(t);n&&l(n)},placeholder:'{\n "Dataset 1": [\n {\n "label": "Label 1",\n "value": 100,\n "color": "red"\n },\n {\n "label": "Label 2",\n "value": 200\n }\n ],\n "Dataset 2": [\n {\n "label": "Label 3",\n "value": 300,\n "color": "green"\n }\n ]\n}'}),"csv_upload"===s&&(0,o.jsx)(e.MediaUploadCheck,{children:(0,o.jsx)(e.MediaUpload,{onSelect:t=>{const n=t.url;fetch(t.url).then((t=>t.text())).then((t=>{const e=v(t,n);e&&l(e)})).catch((t=>{g("Error reading CSV file: "+t.message)}))},allowedTypes:["text/csv"],render:({open:e})=>(0,o.jsxs)("div",{children:[(0,o.jsx)(r.Button,{onClick:e,isPrimary:!0,children:(0,n.__)("Upload CSV File","lcp")}),t&&Object.keys(t).length>0&&t[Object.keys(t)[0]]?.[0]?.sourceUrl&&(0,o.jsxs)("div",{className:"current-file",style:{marginTop:"10px"},children:[(0,n.__)("Current file:","lcp")," ",t[Object.keys(t)[0]][0].sourceUrl.split("/").pop()]})]})})}),"csv_url"===s&&(0,o.jsx)(r.TextControl,{label:(0,n.__)("CSV URL","lcp"),value:c,onChange:t=>{h(t),t&&fetch(t).then((t=>t.text())).then((n=>{const e=v(n,t);e&&l(e)})).catch((t=>{g("Error fetching CSV file: "+t.message)}))},help:(0,n.__)("Enter URL of a CSV file with label and value columns. Color column is optional.","lcp")}),p&&(0,o.jsx)("div",{className:"lcp-data-selector-error",style:{color:"red",marginTop:"10px"},children:p}),t&&Object.keys(t).length>0&&(0,o.jsxs)("div",{className:"data-preview",style:{marginTop:"15px"},children:[(0,o.jsx)("h4",{children:(0,n.__)("Current Data Preview:","lcp")}),(0,o.jsx)("div",{style:{fontSize:"12px",color:"#666"},children:Object.entries(t).map((([t,e])=>(0,o.jsxs)("div",{children:[t,": ",e.length," ",(0,n.__)("data points","lcp")]},t)))})]})]})};function s(t,n){let e;if(void 0===n)for(const n of t)null!=n&&(e=n)&&(e=n);else{let r=-1;for(let i of t)null!=(i=n(i,++r,t))&&(e=i)&&(e=i)}return e}function u(t){return t}var c=1e-6;function h(t){return"translate("+t+",0)"}function f(t){return"translate(0,"+t+")"}function d(t){return n=>+t(n)}function p(t,n){return n=Math.max(0,t.bandwidth()-2*n)/2,t.round()&&(n=Math.round(n)),e=>+t(e)+n}function g(){return!this.__axis}function m(t,n){var e=[],r=null,i=null,o=6,a=6,l=3,s="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,m=1===t||4===t?-1:1,v=4===t||2===t?"x":"y",y=1===t||3===t?h:f;function w(h){var f=null==r?n.ticks?n.ticks.apply(n,e):n.domain():r,w=null==i?n.tickFormat?n.tickFormat.apply(n,e):u:i,b=Math.max(o,0)+l,_=n.range(),x=+_[0]+s,C=+_[_.length-1]+s,k=(n.bandwidth?p:d)(n.copy(),s),j=h.selection?h.selection():h,M=j.selectAll(".domain").data([null]),A=j.selectAll(".tick").data(f,n).order(),S=A.exit(),N=A.enter().append("g").attr("class","tick"),E=A.select("line"),$=A.select("text");M=M.merge(M.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),A=A.merge(N),E=E.merge(N.append("line").attr("stroke","currentColor").attr(v+"2",m*o)),$=$.merge(N.append("text").attr("fill","currentColor").attr(v,m*b).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),h!==j&&(M=M.transition(h),A=A.transition(h),E=E.transition(h),$=$.transition(h),S=S.transition(h).attr("opacity",c).attr("transform",(function(t){return isFinite(t=k(t))?y(t+s):this.getAttribute("transform")})),N.attr("opacity",c).attr("transform",(function(t){var n=this.parentNode.__axis;return y((n&&isFinite(n=n(t))?n:k(t))+s)}))),S.remove(),M.attr("d",4===t||2===t?a?"M"+m*a+","+x+"H"+s+"V"+C+"H"+m*a:"M"+s+","+x+"V"+C:a?"M"+x+","+m*a+"V"+s+"H"+C+"V"+m*a:"M"+x+","+s+"H"+C),A.attr("opacity",1).attr("transform",(function(t){return y(k(t)+s)})),E.attr(v+"2",m*o),$.attr(v,m*b).text(w),j.filter(g).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),j.each((function(){this.__axis=k}))}return w.scale=function(t){return arguments.length?(n=t,w):n},w.ticks=function(){return e=Array.from(arguments),w},w.tickArguments=function(t){return arguments.length?(e=null==t?[]:Array.from(t),w):e.slice()},w.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),w):r&&r.slice()},w.tickFormat=function(t){return arguments.length?(i=t,w):i},w.tickSize=function(t){return arguments.length?(o=a=+t,w):o},w.tickSizeInner=function(t){return arguments.length?(o=+t,w):o},w.tickSizeOuter=function(t){return arguments.length?(a=+t,w):a},w.tickPadding=function(t){return arguments.length?(l=+t,w):l},w.offset=function(t){return arguments.length?(s=+t,w):s},w}function v(t){return m(3,t)}function y(t){return m(4,t)}function w(){}function b(t){return null==t?w:function(){return this.querySelector(t)}}function _(){return[]}function x(t){return null==t?_:function(){return this.querySelectorAll(t)}}function C(t){return function(){return this.matches(t)}}function k(t){return function(n){return n.matches(t)}}var j=Array.prototype.find;function M(){return this.firstElementChild}var A=Array.prototype.filter;function S(){return Array.from(this.children)}function N(t){return new Array(t.length)}function E(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function $(t,n,e,r,i,o){for(var a,l=0,s=n.length,u=o.length;ln?1:t>=n?0:NaN}E.prototype={constructor:E,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,n){return this._parent.insertBefore(t,n)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var R="http://www.w3.org/1999/xhtml";const D={svg:"http://www.w3.org/2000/svg",xhtml:R,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function L(t){var n=t+="",e=n.indexOf(":");return e>=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),D.hasOwnProperty(n)?{space:D[n],local:t}:t}function F(t){return function(){this.removeAttribute(t)}}function V(t){return function(){this.removeAttributeNS(t.space,t.local)}}function G(t,n){return function(){this.setAttribute(t,n)}}function I(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function X(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function U(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function H(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function q(t){return function(){this.style.removeProperty(t)}}function z(t,n,e){return function(){this.style.setProperty(t,n,e)}}function Y(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function W(t,n){return t.style.getPropertyValue(n)||H(t).getComputedStyle(t,null).getPropertyValue(n)}function J(t){return function(){delete this[t]}}function K(t,n){return function(){this[t]=n}}function Z(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function Q(t){return t.trim().split(/^|\s+/)}function tt(t){return t.classList||new nt(t)}function nt(t){this._node=t,this._names=Q(t.getAttribute("class")||"")}function et(t,n){for(var e=tt(t),r=-1,i=n.length;++r=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var At=[null];function St(t,n){this._groups=t,this._parents=n}function Nt(){return new St([[document.documentElement]],At)}St.prototype=Nt.prototype={constructor:St,select:function(t){"function"!=typeof t&&(t=b(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i=_&&(_=b+1);!(w=v[_])&&++_=0;)(r=i[o])&&(a&&4^r.compareDocumentPosition(a)&&a.parentNode.insertBefore(r,a),a=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=B);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o1?this.each((null==n?q:"function"==typeof n?Y:z)(t,n,null==e?"":e)):W(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?J:"function"==typeof n?Z:K)(t,n)):this.node()[t]},classed:function(t,n){var e=Q(t+"");if(arguments.length<2){for(var r=tt(this.node()),i=-1,o=e.length;++i=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}}))}(t+""),a=o.length;if(!(arguments.length<2)){for(l=n?Ct:xt,r=0;r{}};function Ot(){for(var t,n=0,e=arguments.length,r={};n=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))),a=-1,l=o.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++a0)for(var e,r,i=new Array(e),o=0;o=0&&n._call.call(void 0,t),n=n._next;--Ft}()}finally{Ft=0,function(){for(var t,n,e=Dt,r=1/0;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:Dt=n);Lt=t,Qt(r)}(),Xt=0}}function Zt(){var t=Ht.now(),n=t-It;n>1e3&&(Ut-=n,It=t)}function Qt(t){Ft||(Vt&&(Vt=clearTimeout(Vt)),t-Xt>24?(t<1/0&&(Vt=setTimeout(Kt,t-Ht.now()-Ut)),Gt&&(Gt=clearInterval(Gt))):(Gt||(It=Ht.now(),Gt=setInterval(Zt,1e3)),Ft=1,qt(Kt)))}function tn(t,n,e){var r=new Wt;return n=null==n?0:+n,r.restart((e=>{r.stop(),t(e+n)}),n,e),r}Wt.prototype=Jt.prototype={constructor:Wt,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?zt():+e)+(null==n?0:+n),this._next||Lt===this||(Lt?Lt._next=this:Dt=this,Lt=this),this._call=t,this._time=e,Qt()},stop:function(){this._call&&(this._call=null,this._time=1/0,Qt())}};var nn=Rt("start","end","cancel","interrupt"),en=[];function rn(t,n,e,r,i,o){var a=t.__transition;if(a){if(e in a)return}else t.__transition={};!function(t,n,e){var r,i=t.__transition;function o(s){var u,c,h,f;if(1!==e.state)return l();for(u in i)if((f=i[u]).name===e.name){if(3===f.state)return tn(o);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return e}function an(t,n){var e=ln(t,n);if(e.state>3)throw new Error("too late; already running");return e}function ln(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function sn(t,n){return t=+t,n=+n,function(e){return t*(1-e)+n*e}}var un,cn=180/Math.PI,hn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function fn(t,n,e,r,i,o){var a,l,s;return(a=Math.sqrt(t*t+n*n))&&(t/=a,n/=a),(s=t*e+n*r)&&(e-=t*s,r-=n*s),(l=Math.sqrt(e*e+r*r))&&(e/=l,r/=l,s/=l),t*r180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:sn(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,a.rotate,l,s),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:sn(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,a.skewX,l,s),function(t,n,e,r,o,a){if(t!==e||n!==r){var l=o.push(i(o)+"scale(",null,",",null,")");a.push({i:l-4,x:sn(t,e)},{i:l-2,x:sn(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,a.scaleX,a.scaleY,l,s),o=a=null,function(t){for(var n,e=-1,r=s.length;++e>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1):8===e?Vn(n>>24&255,n>>16&255,n>>8&255,(255&n)/255):4===e?Vn(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|240&n,((15&n)<<4|15&n)/255):null):(n=Nn.exec(t))?new In(n[1],n[2],n[3],1):(n=En.exec(t))?new In(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=$n.exec(t))?Vn(n[1],n[2],n[3],n[4]):(n=On.exec(t))?Vn(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=Pn.exec(t))?Yn(n[1],n[2]/100,n[3]/100,1):(n=Tn.exec(t))?Yn(n[1],n[2]/100,n[3]/100,n[4]):Bn.hasOwnProperty(t)?Fn(Bn[t]):"transparent"===t?new In(NaN,NaN,NaN,0):null}function Fn(t){return new In(t>>16&255,t>>8&255,255&t,1)}function Vn(t,n,e,r){return r<=0&&(t=n=e=NaN),new In(t,n,e,r)}function Gn(t,n,e,r){return 1===arguments.length?((i=t)instanceof xn||(i=Ln(i)),i?new In((i=i.rgb()).r,i.g,i.b,i.opacity):new In):new In(t,n,e,null==r?1:r);var i}function In(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Xn(){return`#${zn(this.r)}${zn(this.g)}${zn(this.b)}`}function Un(){const t=Hn(this.opacity);return`${1===t?"rgb(":"rgba("}${qn(this.r)}, ${qn(this.g)}, ${qn(this.b)}${1===t?")":`, ${t})`}`}function Hn(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function qn(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function zn(t){return((t=qn(t))<16?"0":"")+t.toString(16)}function Yn(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Jn(t,n,e,r)}function Wn(t){if(t instanceof Jn)return new Jn(t.h,t.s,t.l,t.opacity);if(t instanceof xn||(t=Ln(t)),!t)return new Jn;if(t instanceof Jn)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),a=NaN,l=o-i,s=(o+i)/2;return l?(a=n===o?(e-r)/l+6*(e0&&s<1?0:a,new Jn(a,l,s,t.opacity)}function Jn(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Kn(t){return(t=(t||0)%360)<0?t+360:t}function Zn(t){return Math.max(0,Math.min(1,t||0))}function Qn(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}function te(t,n,e,r,i){var o=t*t,a=o*t;return((1-3*t+3*o-a)*n+(4-6*o+3*a)*e+(1+3*t+3*o-3*a)*r+a*i)/6}wn(xn,Ln,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Rn,formatHex:Rn,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Wn(this).formatHsl()},formatRgb:Dn,toString:Dn}),wn(In,Gn,bn(xn,{brighter(t){return t=null==t?kn:Math.pow(kn,t),new In(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Cn:Math.pow(Cn,t),new In(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new In(qn(this.r),qn(this.g),qn(this.b),Hn(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Xn,formatHex:Xn,formatHex8:function(){return`#${zn(this.r)}${zn(this.g)}${zn(this.b)}${zn(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Un,toString:Un})),wn(Jn,(function(t,n,e,r){return 1===arguments.length?Wn(t):new Jn(t,n,e,null==r?1:r)}),bn(xn,{brighter(t){return t=null==t?kn:Math.pow(kn,t),new Jn(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Cn:Math.pow(Cn,t),new Jn(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new In(Qn(t>=240?t-240:t+120,i,r),Qn(t,i,r),Qn(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Jn(Kn(this.h),Zn(this.s),Zn(this.l),Hn(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Hn(this.opacity);return`${1===t?"hsl(":"hsla("}${Kn(this.h)}, ${100*Zn(this.s)}%, ${100*Zn(this.l)}%${1===t?")":`, ${t})`}`}}));const ne=t=>()=>t;function ee(t,n){var e=n-t;return e?function(t,n){return function(e){return t+e*n}}(t,e):ne(isNaN(t)?n:t)}const re=function t(n){var e=function(t){return 1==(t=+t)?ee:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):ne(isNaN(n)?e:n)}}(n);function r(t,n){var r=e((t=Gn(t)).r,(n=Gn(n)).r),i=e(t.g,n.g),o=e(t.b,n.b),a=ee(t.opacity,n.opacity);return function(n){return t.r=r(n),t.g=i(n),t.b=o(n),t.opacity=a(n),t+""}}return r.gamma=t,r}(1);function ie(t){return function(n){var e,r,i=n.length,o=new Array(i),a=new Array(i),l=new Array(i);for(e=0;e=1?(e=1,n-1):Math.floor(e*n),i=t[r],o=t[r+1],a=r>0?t[r-1]:2*i-o,l=ro&&(i=n.slice(o,i),l[a]?l[a]+=i:l[++a]=i),(e=e[0])===(r=r[0])?l[a]?l[a]+=r:l[++a]=r:(l[++a]=null,s.push({i:a,x:sn(e,r)})),o=ae.lastIndex;return o=0&&(t=t.slice(0,n)),!t||"start"===t}))}(n)?on:an;return function(){var a=o(this,t),l=a.on;l!==r&&(i=(r=l).copy()).on(n,e),a.on=i}}(e,t,n))},attr:function(t,n){var e=L(t),r="transform"===e?gn:se;return this.attrTween(t,"function"==typeof n?(e.local?pe:de)(e,r,yn(this,"attr."+t,n)):null==n?(e.local?ce:ue)(e):(e.local?fe:he)(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=L(t);return this.tween(e,(r.local?ge:me)(r,n))},style:function(t,n,e){var r="transform"==(t+="")?pn:se;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=W(this,t),a=(this.style.removeProperty(t),W(this,t));return o===a?null:o===e&&a===r?i:i=n(e=o,r=a)}}(t,r)).on("end.style."+t,xe(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,o;return function(){var a=W(this,t),l=e(this),s=l+"";return null==l&&(this.style.removeProperty(t),s=l=W(this,t)),a===s?null:a===r&&s===i?o:(i=s,o=n(r=a,l))}}(t,r,yn(this,"style."+t,n))).each(function(t,n){var e,r,i,o,a="style."+n,l="end."+a;return function(){var s=an(this,t),u=s.on,c=null==s.value[a]?o||(o=xe(n)):void 0;u===e&&i===c||(r=(e=u).copy()).on(l,i=c),s.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,o=e+"";return function(){var a=W(this,t);return a===o?null:a===r?i:i=n(r=a,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(yn(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!=typeof t)throw new Error;return this.tween(n,function(t){var n,e;function r(){var r=t.apply(this,arguments);return r!==e&&(n=(e=r)&&function(t){return function(n){this.textContent=t.call(this,n)}}(r)),n}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=ln(this.node(),e).tween,o=0,a=i.length;o2&&e.state<5,e.state=6,e.timer.stop(),e.on.call(r?"interrupt":"cancel",t,t.__data__,e.index,e.group),delete o[i]):a=!1;a&&delete t.__transition}}(this,t)}))},Et.prototype.transition=function(t){var n,e;t instanceof ke?(n=t._id,t=t._name):(n=je(),(e=Ae).time=zt(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o=Ve?10:o>=Ge?5:o>=Ie?2:1;let l,s,u;return i<0?(u=Math.pow(10,-i)/a,l=Math.round(t*u),s=Math.round(n*u),l/un&&--s,u=-u):(u=Math.pow(10,i)*a,l=Math.round(t/u),s=Math.round(n/u),l*un&&--s),sn?1:t>=n?0:NaN}function qe(t,n){return null==t||null==n?NaN:nt?1:n>=t?0:NaN}function ze(t){let n,e,r;function i(t,r,i=0,o=t.length){if(i>>1;e(t[n],r)<0?i=n+1:o=n}while(iHe(t(n),e),r=(n,e)=>t(n)-e):(n=t===He||t===qe?t:Ye,e=t,r=t),{left:i,center:function(t,n,e=0,o=t.length){const a=i(t,n,e,o-1);return a>e&&r(t[a-1],n)>-r(t[a],n)?a-1:a},right:function(t,r,i=0,o=t.length){if(i>>1;e(t[n],r)<=0?i=n+1:o=n}while(i=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function fr(t){if(!(n=hr.exec(t)))throw new Error("invalid format: "+t);var n;return new dr({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}function dr(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function pr(t,n){if((e=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var e,r=t.slice(0,e);return[r.length>1?r[0]+r.slice(2):r,+t.slice(e+1)]}function gr(t){return(t=pr(Math.abs(t)))?t[1]:NaN}function mr(t,n){var e=pr(t,n);if(!e)return t+"";var r=e[0],i=e[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}fr.prototype=dr.prototype,dr.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const vr={"%":(t,n)=>(100*t).toFixed(n),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,n)=>t.toExponential(n),f:(t,n)=>t.toFixed(n),g:(t,n)=>t.toPrecision(n),o:t=>Math.round(t).toString(8),p:(t,n)=>mr(100*t,n),r:mr,s:function(t,n){var e=pr(t,n);if(!e)return t+"";var r=e[0],i=e[1],o=i-(cr=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,a=r.length;return o===a?r:o>a?r+new Array(o-a+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+pr(t,Math.max(0,n+o-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function yr(t){return t}var wr,br,_r,xr=Array.prototype.map,Cr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function kr(t){var n=t.domain;return t.ticks=function(t){var e=n();return function(t,n,e){if(!((e=+e)>0))return[];if((t=+t)==(n=+n))return[t];const r=n=i))return[];const l=o-i+1,s=new Array(l);if(r)if(a<0)for(let t=0;t0;){if((i=Ue(s,u,e))===r)return o[a]=s,o[l]=u,n(o);if(i>0)s=Math.floor(s/i)*i,u=Math.ceil(u/i)*i;else{if(!(i<0))break;s=Math.ceil(s*i)/i,u=Math.floor(u*i)/i}r=i}return t},t}function jr(){var t=function(){var t,n,e,r,i,o,a=or,l=or,s=er,u=ar;function c(){var t,n,e,s=Math.min(a.length,l.length);return u!==ar&&(t=a[0],n=a[s-1],t>n&&(e=t,t=n,n=e),u=function(e){return Math.max(t,Math.min(n,e))}),r=s>2?ur:sr,i=o=null,h}function h(n){return null==n||isNaN(n=+n)?e:(i||(i=r(a.map(t),l,s)))(t(u(n)))}return h.invert=function(e){return u(n((o||(o=r(l,a.map(t),sn)))(e)))},h.domain=function(t){return arguments.length?(a=Array.from(t,ir),c()):a.slice()},h.range=function(t){return arguments.length?(l=Array.from(t),c()):l.slice()},h.rangeRound=function(t){return l=Array.from(t),s=rr,c()},h.clamp=function(t){return arguments.length?(u=!!t||ar,c()):u!==ar},h.interpolate=function(t){return arguments.length?(s=t,c()):s},h.unknown=function(t){return arguments.length?(e=t,h):e},function(e,r){return t=e,n=r,c()}}()(ar,ar);return t.copy=function(){return n=t,jr().domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown());var n},Pe.apply(t,arguments),kr(t)}function Mr(t){return"string"==typeof t?new St([[document.querySelector(t)]],[document.documentElement]):new St([[t]],At)}function Ar(t,n,e){this.k=t,this.x=n,this.y=e}wr=function(t){var n,e,r=void 0===t.grouping||void 0===t.thousands?yr:(n=xr.call(t.grouping,Number),e=t.thousands+"",function(t,r){for(var i=t.length,o=[],a=0,l=n[0],s=0;i>0&&l>0&&(s+l+1>r&&(l=Math.max(1,r-s)),o.push(t.substring(i-=l,i+l)),!((s+=l+1)>r));)l=n[a=(a+1)%n.length];return o.reverse().join(e)}),i=void 0===t.currency?"":t.currency[0]+"",o=void 0===t.currency?"":t.currency[1]+"",a=void 0===t.decimal?".":t.decimal+"",l=void 0===t.numerals?yr:function(t){return function(n){return n.replace(/[0-9]/g,(function(n){return t[+n]}))}}(xr.call(t.numerals,String)),s=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"−":t.minus+"",c=void 0===t.nan?"NaN":t.nan+"";function h(t){var n=(t=fr(t)).fill,e=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,g=t.comma,m=t.precision,v=t.trim,y=t.type;"n"===y?(g=!0,y="g"):vr[y]||(void 0===m&&(m=12),v=!0,y="g"),(d||"0"===n&&"="===e)&&(d=!0,n="0",e="=");var w="$"===f?i:"#"===f&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",b="$"===f?o:/[%p]/.test(y)?s:"",_=vr[y],x=/[defgprs%]/.test(y);function C(t){var i,o,s,f=w,C=b;if("c"===y)C=_(t)+C,t="";else{var k=(t=+t)<0||1/t<0;if(t=isNaN(t)?c:_(Math.abs(t),m),v&&(t=function(t){t:for(var n,e=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(n+1):t}(t)),k&&0==+t&&"+"!==h&&(k=!1),f=(k?"("===h?h:u:"-"===h||"("===h?"":h)+f,C=("s"===y?Cr[8+cr/3]:"")+C+(k&&"("===h?")":""),x)for(i=-1,o=t.length;++i(s=t.charCodeAt(i))||s>57){C=(46===s?a+t.slice(i+1):t.slice(i))+C,t=t.slice(0,i);break}}g&&!d&&(t=r(t,1/0));var j=f.length+t.length+C.length,M=j>1)+f+t+C+M.slice(j);break;default:t=M+f+t+C}return l(t)}return m=void 0===m?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),C.toString=function(){return t+""},C}return{format:h,formatPrefix:function(t,n){var e=h(((t=fr(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(gr(n)/3))),i=Math.pow(10,-r),o=Cr[8+r/3];return function(t){return e(i*t)+o}}}}({thousands:",",grouping:[3],currency:["$",""]}),br=wr.format,_r=wr.formatPrefix,Ar.prototype={constructor:Ar,scale:function(t){return 1===t?this:new Ar(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new Ar(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}},new Ar(1,0,0),Ar.prototype;const Sr=({data:t,width:n="100%",height:e="400px",backgroundColor:r,title:a,showGridX:l,showGridY:u,xGridColor:c,yGridColor:h,xGridWidth:f,yGridWidth:d,showBarValues:p,xAxisLabel:g,yAxisLabel:m,colorSource:w,defaultBarColor:b,customColors:_,barOpacity:x,enableHierarchicalView:C,enableStackedBars:k,selectedParentId:j,setAttributes:M})=>{const A=(0,i.useRef)(),S=(0,i.useRef)(),N=(t,n)=>{const e=Ln(t).rgb();return Gn(Math.max(0,e.r-n),Math.max(0,e.g-n),Math.max(0,e.b-n)).toString()};return(0,i.useEffect)((()=>{if(!t||!A.current||!S.current)return;Mr(A.current).selectAll("*").remove();let n=t;C&&!k&&(n={},Object.entries(t).forEach((([t,e])=>{const r=e.filter((t=>t.parent===j));r.length>0&&(n[t]=r)})));const i=[];Object.entries(n).forEach((([n,e])=>{e.forEach((e=>{if(!k||null===e.parent){const r=e.color||b,o=(n=>{const e=[];return Object.entries(t).forEach((([t,r])=>{r.forEach((r=>{r.parent===n&&e.push({...r,dataset:t,color:r.color||b})}))})),e})(e.id),a={id:e.id,dataset:n,label:e.label||"",value:parseFloat(e.value)||0,color:r,hasChildren:o.length>0,children:[]};if(k&&o.length>0){let t=new Set([r]);o.forEach(((n,e)=>{let i=n.color||r;for(;t.has(i);)i=N(i,30);t.add(i),a.children.push({id:n.id,label:n.label,value:parseFloat(n.value)||0,color:i})}))}i.push(a)}}))}));const o=S.current.clientWidth,E="number"==typeof e?e:400,$={top:a?40:20,right:20,bottom:g?50:30,left:m?60:40},O=Math.max(o-$.left-$.right,0),P=Math.max(E-$.top-$.bottom,0),T=Mr(A.current).attr("width",o).attr("height",E).style("background-color",r);a&&T.append("text").attr("x",o/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").text(a);const B=T.append("g").attr("transform",`translate(${$.left},${$.top})`),R=Fe().domain(i.map((t=>t.label))).range([0,O]).padding(.1),D=jr().domain([0,s(i,(t=>k?t.value+t.children.reduce(((t,n)=>t+n.value),0):t.value))||100]).range([P,0]);l&&B.append("g").attr("class","grid x-grid").attr("transform",`translate(0,${P})`).style("color",c).style("stroke-width",f).call(v(R).tickSize(-P).tickFormat("")),u&&B.append("g").attr("class","grid y-grid").style("color",h).style("stroke-width",d).call(y(D).tickSize(-O).tickFormat(""));const L=B.selectAll(".bar-group").data(i).enter().append("g").attr("class","bar-group").attr("transform",(t=>`translate(${R(t.label)},0)`));L.append("rect").attr("class","main-bar").attr("y",(t=>D(t.value))).attr("width",R.bandwidth()).attr("height",(t=>P-D(t.value))).attr("fill",(t=>(t=>{switch(w){case"singleColor":return b;case"customColors":const n=_?.find((n=>n.dataset===t.dataset&&n.label===t.label));return n?n.color:t.color;default:return t.color}})(t))).style("opacity",x).style("cursor",(t=>t.hasChildren&&!k?"pointer":"default")),k&&L.each((function(t){let n=t.value;t.children.forEach((t=>{Mr(this).append("rect").attr("class","child-bar").attr("y",(()=>D(n+t.value))).attr("width",R.bandwidth()).attr("height",(()=>P-D(t.value))).attr("fill",t.color).style("opacity",x),n+=t.value}))})),C&&!k&&(L.selectAll(".main-bar").on("click",(function(t,n){n.hasChildren&&M&&M({selectedParentId:n.id})})),null!==j&&T.append("text").attr("x",$.left).attr("y",$.top/2).attr("class","back-button").style("cursor","pointer").style("font-weight","bold").text("← Back").on("click",(function(){if(M){let n=null;Object.values(t).forEach((t=>{const e=t.find((t=>t.id===j));e&&(n=e.parent)})),M({selectedParentId:n})}}))),p&&L.each((function(t){if(Mr(this).append("text").attr("class","bar-value").attr("x",R.bandwidth()/2).attr("y",D(t.value)-5).attr("text-anchor","middle").text(t.value),k){let n=t.value;t.children.forEach((t=>{Mr(this).append("text").attr("class","bar-value").attr("x",R.bandwidth()/2).attr("y",D(n+t.value)-5).attr("text-anchor","middle").text(t.value),n+=t.value}))}})),B.append("g").attr("transform",`translate(0,${P})`).call(v(R)).selectAll("text").style("text-anchor","end").attr("dx","-.8em").attr("dy",".15em").attr("transform","rotate(-45)"),B.append("g").call(y(D)),g&&B.append("text").attr("class","x-axis-label").attr("x",O/2).attr("y",P+40).attr("text-anchor","middle").style("font-size","12px").text(g),m&&B.append("text").attr("class","y-axis-label").attr("transform","rotate(-90)").attr("x",-P/2).attr("y",-45).attr("text-anchor","middle").style("font-size","12px").text(m)}),[t,n,e,a,l,u,c,h,f,d,p,g,m,w,b,_,x,C,k,j]),(0,o.jsx)("div",{ref:S,className:"bar-graph",style:{width:n,height:e,backgroundColor:r,position:"relative"},children:(0,o.jsx)("svg",{ref:A})})},Nr=({label:t,value:n,onChange:e})=>{const{number:i,unit:a}=(t=>{const n=t?.match(/^(\d+)(.*)$/);return n?{number:parseInt(n[1],10),unit:n[2]||"px"}:{number:300,unit:"px"}})(n);return(0,o.jsxs)("div",{className:"lcp-dimension-control",children:[(0,o.jsx)("label",{className:"components-base-control__label",children:t}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start"},children:[(0,o.jsx)(r.TextControl,{type:"number",value:i,onChange:t=>{e(`${t}${a}`)},min:0,style:{width:"80px"}}),(0,o.jsx)(r.SelectControl,{value:a,options:[{label:"Pixels (px)",value:"px"},{label:"Percentage (%)",value:"%"},{label:"Viewport Width (vw)",value:"vw"},{label:"Viewport Height (vh)",value:"vh"}],onChange:t=>{e(`${i}${t}`)},style:{minWidth:"100px"}})]})]})},Er=({data:t,colorSource:e,singleColor:a,customColors:l,onColorSourceChange:s,onSingleColorChange:u,onCustomColorChange:c})=>{const[h,f]=(0,i.useState)(null),d=(t,n)=>{const e=l.find((e=>e.dataset===t&&e.label===n));return e?e.color:"#FF6384"};return(0,o.jsxs)("div",{className:"lcp-color-controls",children:[(0,o.jsx)(r.SelectControl,{label:(0,n.__)("Color Source","lcp"),value:e,options:[{label:(0,n.__)("Default Colors","lcp"),value:"default"},{label:(0,n.__)("Single Color","lcp"),value:"singleColor"},{label:(0,n.__)("Custom Colors","lcp"),value:"customColors"}],onChange:s}),"singleColor"===e&&(0,o.jsxs)("div",{className:"components-base-control",children:[(0,o.jsx)("label",{className:"components-base-control__label",children:(0,n.__)("Bar Color","lcp")}),(0,o.jsx)(r.ColorPicker,{color:a,onChangeComplete:t=>u(t.hex)})]}),"customColors"===e&&(0,o.jsx)("div",{className:"custom-colors-grid",style:{marginTop:"10px"},children:(()=>{const n=[];return Object.entries(t).forEach((([t,e])=>{e.forEach((e=>{n.push({dataset:t,label:e.label,value:e.value})}))})),n})().map(((t,n)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"8px",gap:"8px"},children:[(0,o.jsx)("span",{style:{flex:1},children:t.label}),(0,o.jsx)(r.Button,{onClick:()=>f(n),style:{backgroundColor:d(t.dataset,t.label),width:"24px",height:"24px",borderRadius:"50%",padding:0,border:"1px solid #ddd"}}),h===n&&(0,o.jsx)(r.Popover,{onClose:()=>f(null),children:(0,o.jsx)("div",{style:{padding:"12px"},children:(0,o.jsx)(r.ColorPicker,{color:d(t.dataset,t.label),onChangeComplete:n=>{c(t.dataset,t.label,n.hex)}})})})]},`${t.dataset}-${t.label}`)))})]})},$r=JSON.parse('{"UU":"lcp/bar-graph"}');(0,t.registerBlockType)($r.UU,{edit:function({attributes:t,setAttributes:a}){const{chartHeight:s,chartWidth:u,barColor:c,barOpacity:h,backgroundColor:f,showGridY:d,yGridColor:p,xGridColor:g,xGridWidth:m,yGridWidth:v,chartData:y,dataSource:w,displayChartTitle:b,chartTitle:_,allowDownload:x,downloadMaxWidth:C,showSorting:k,showFiltering:j,showBarValues:M,showGridX:A,xAxisLabel:S,yAxisLabel:N,chartColorSource:E,chartCustomColors:$,enableHierarchicalView:O,enableStackedBars:P,selectedParentId:T}=t,B=(0,e.useBlockProps)(),R=t=>{console.log("New data:",t),a({chartData:t})},D=t=>{a({dataSource:t,chartData:{}})},L=(t,n,e)=>{const r=[...$],i=r.findIndex((e=>e.dataset===t&&e.label===n));i>=0?r[i].color=e:r.push({dataset:t,label:n,color:e}),a({chartCustomColors:r})},[F,V]=(0,i.useState)(!1),[G,I]=(0,i.useState)(!1),X=()=>{V(!F)},U=()=>{I(!G)},[H,q]=(0,i.useState)(!1),z=()=>{q(!H)};return console.log("Chart data:",y),t.chartData&&"object"==typeof t.chartData||a({chartData:{}}),(0,o.jsxs)("div",{...B,children:[(0,o.jsx)(e.InspectorControls,{children:(0,o.jsx)(r.TabPanel,{className:"lcp-tab-panel",activeClass:"active-tab",tabs:[{name:"data",title:(0,n.__)("Data Settings","lcp"),className:"tab-data"},{name:"appearance",title:(0,n.__)("Appearance","lcp"),className:"tab-appearance"},{name:"tools",title:(0,n.__)("Tools Settings","lcp"),className:"tab-tools"}],children:t=>"data"===t.name?(0,o.jsxs)(r.Panel,{children:[(0,o.jsx)(r.PanelBody,{title:"Data Settings",children:(0,o.jsx)(l,{value:y,onChange:R,dataSource:w,onDataSourceChange:D})}),(0,o.jsxs)(r.PanelBody,{title:(0,n.__)("Chart Settings","lcp"),initialOpen:!0,children:[(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Enable Hierarchical View","lcp"),checked:O,onChange:t=>a({enableHierarchicalView:t})}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Enable Stacked Bars","lcp"),checked:P,onChange:t=>a({enableStackedBars:t})}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Display Chart Title","lcp"),checked:b,onChange:t=>a({displayChartTitle:t})}),b&&(0,o.jsx)(r.TextControl,{label:(0,n.__)("Chart Title","lcp"),value:_,onChange:t=>a({chartTitle:t})}),(0,o.jsx)(Nr,{label:(0,n.__)("Chart Width","lcp"),value:u,onChange:t=>a({chartWidth:t})}),(0,o.jsx)(Nr,{label:(0,n.__)("Chart Height","lcp"),value:s,onChange:t=>a({chartHeight:t})})]}),(0,o.jsxs)(r.PanelBody,{title:"Appearance",children:[(0,o.jsxs)("div",{className:"background-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"10px"},children:[(0,o.jsx)("span",{children:"Background Color"}),(0,o.jsx)(r.Button,{className:"background-color-button",onClick:z,style:{backgroundColor:f,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),H&&(0,o.jsx)(r.Popover,{position:"bottom center",onClose:z,children:(0,o.jsx)(r.ColorPicker,{color:f,onChangeComplete:t=>{return n=t.hex,void a({backgroundColor:n});var n}})})]}),(0,o.jsx)(Er,{data:y,colorSource:E,singleColor:c,customColors:$,onColorSourceChange:t=>a({chartColorSource:t}),onSingleColorChange:t=>a({barColor:t}),onCustomColorChange:L}),(0,o.jsx)(r.RangeControl,{label:(0,n.__)("Bar Opacity","lcp"),value:h,onChange:t=>a({barOpacity:t}),min:0,max:1,step:.1}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Show Bar Values","lcp"),checked:M,onChange:t=>a({showBarValues:t})})]}),(0,o.jsxs)(r.PanelBody,{title:"Grid Settings",children:[(0,o.jsx)(r.TextControl,{label:(0,n.__)("X-Axis Label","lcp"),value:S,onChange:t=>a({xAxisLabel:t})}),(0,o.jsx)(r.TextControl,{label:(0,n.__)("Y-Axis Label","lcp"),value:N,onChange:t=>a({yAxisLabel:t})}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Show X-Axis Grid","lcp"),checked:A,onChange:t=>a({showGridX:t})}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Show Y-Axis Grid","lcp"),checked:d,onChange:t=>a({showGridY:t})}),d&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"y-grid-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"8px"},children:[(0,o.jsx)("span",{children:"Y-Axis Grid Color"}),(0,o.jsx)(r.Button,{className:"grid-color-button",onClick:X,style:{backgroundColor:p,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),F&&(0,o.jsx)(r.Popover,{position:"bottom center",onClose:X,children:(0,o.jsx)(r.ColorPicker,{color:p,onChangeComplete:t=>{return n=t.hex,void a({yGridColor:n});var n}})})]}),(0,o.jsx)(r.RangeControl,{label:(0,n.__)("Y-Axis Grid Width","lcp"),value:v,onChange:t=>a({yGridWidth:t}),min:1,max:5,step:1})]}),A&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:"x-grid-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"8px"},children:[(0,o.jsx)("span",{children:"X-Axis Grid Color"}),(0,o.jsx)(r.Button,{className:"grid-color-button",onClick:U,style:{backgroundColor:g,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),G&&(0,o.jsx)(r.Popover,{position:"bottom center",onClose:U,children:(0,o.jsx)(r.ColorPicker,{color:g,onChangeComplete:t=>{return n=t.hex,void a({xGridColor:n});var n}})})]}),(0,o.jsx)(r.RangeControl,{label:(0,n.__)("X-Axis Grid Width","lcp"),value:m,onChange:t=>a({xGridWidth:t}),min:1,max:5,step:1})]})]})]}):"appearance"===t.name?(0,o.jsx)(r.PanelBody,{}):"tools"===t.name?(0,o.jsxs)(r.PanelBody,{children:[(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Allow Download","lcp"),checked:x,onChange:t=>a({allowDownload:t})}),x&&(0,o.jsx)(r.TextControl,{type:"number",label:(0,n.__)("Max Download Width (px)","lcp"),value:parseInt(C),onChange:t=>a({downloadMaxWidth:`${t}px`}),min:100,max:5e3}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Show Sorting Options","lcp"),checked:k,onChange:t=>a({showSorting:t})}),(0,o.jsx)(r.ToggleControl,{label:(0,n.__)("Show Filtering Options","lcp"),checked:j,onChange:t=>a({showFiltering:t})})]}):void 0})}),x&&(0,o.jsx)("div",{className:"lcp-bar-graph-toolbar",children:(0,o.jsx)(r.Button,{isPrimary:!0,onClick:()=>{const t=document.querySelector(".bar-graph svg");if(!t)return;const n=document.createElement("canvas"),e=(new XMLSerializer).serializeToString(t),r=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),i=window.URL||window.webkitURL||window,o=i.createObjectURL(r),a=new Image;a.onload=()=>{n.width=t.width.baseVal.value,n.height=t.height.baseVal.value;const e=n.getContext("2d");e.fillStyle=f,e.fillRect(0,0,n.width,n.height),e.drawImage(a,0,0),n.toBlob((t=>{const n=URL.createObjectURL(t),e=document.createElement("a");e.href=n,e.download="bar-graph.png",document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(n),i.revokeObjectURL(o)}),"image/png")},a.src=o},icon:"download",children:(0,n.__)("Download Graph","lcp")})}),y&&Object.keys(y).length>0?(0,o.jsx)(Sr,{data:y,height:s,width:u,backgroundColor:f,defaultBarColor:c,barOpacity:h,showGridX:A,showGridY:d,yGridColor:p,xGridColor:g,xGridWidth:m,yGridWidth:v,title:b?_:"",showBarValues:M,xAxisLabel:S,yAxisLabel:N,colorSource:E,customColors:$,enableHierarchicalView:O,enableStackedBars:P,selectedParentId:T,setAttributes:a}):(0,o.jsx)("div",{className:"lcp-bar-graph-placeholder",style:{height:s,width:u,backgroundColor:f,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed #ccc",borderRadius:"4px",color:"#666"},children:(0,n.__)("Please add data using the Data Settings panel","lcp")})]})},save:function({attributes:t}){const{chartHeight:n,backgroundColor:r}=t;return(0,o.jsx)("div",{...e.useBlockProps.save(),children:(0,o.jsx)("div",{className:"lcp-bar-graph",style:{height:n,backgroundColor:r}})})}})}},e={};function r(t){var i=e[t];if(void 0!==i)return i.exports;var o=e[t]={exports:{}};return n[t](o,o.exports,r),o.exports}r.m=n,t=[],r.O=(n,e,i,o)=>{if(!e){var a=1/0;for(c=0;c=o)&&Object.keys(r.O).every((t=>r.O[t](e[s])))?e.splice(s--,1):(l=!1,o0&&t[c-1][2]>o;c--)t[c]=t[c-1];t[c]=[e,i,o]},r.o=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),(()=>{var t={57:0,350:0};r.O.j=n=>0===t[n];var n=(n,e)=>{var i,o,[a,l,s]=e,u=0;if(a.some((n=>0!==t[n]))){for(i in l)r.o(l,i)&&(r.m[i]=l[i]);if(s)var c=s(r)}for(n&&n(e);ur(126)));i=r.O(i)})(); \ No newline at end of file +(()=>{"use strict";var t,e={301:(t,e,n)=>{var r={};n.r(r),n.d(r,{FILE:()=>Wt,HTML:()=>Jt,TEXT:()=>Kt,URL:()=>zt});const i=window.wp.blocks,o=window.wp.i18n,a=window.wp.blockEditor,s=window.wp.components,l=window.wp.element;function c(t,e,...n){if("undefined"!=typeof process&&void 0===e)throw new Error("invariant requires an error message argument");if(!t){let t;if(void 0===e)t=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{let r=0;t=new Error(e.replace(/%s/g,(function(){return n[r++]}))),t.name="Invariant Violation"}throw t.framesToPop=1,t}}var u=n(792);const h=window.React,d="undefined"!=typeof window?h.useLayoutEffect:h.useEffect;function f(t,e,n){return function(t,e,n){const[r,i]=function(t,e,n){const[r,i]=(0,h.useState)((()=>e(t))),o=(0,h.useCallback)((()=>{const o=e(t);u(r,o)||(i(o),n&&n())}),[r,t,n]);return d(o),[r,o]}(t,e,n);return d((function(){const e=t.getHandlerId();if(null!=e)return t.subscribeToStateChange(i,{handlerIds:[e]})}),[t,i]),r}(e,t||(()=>({})),(()=>n.reconnect()))}function g(t,e){const n=[...e||[]];return null==e&&"function"!=typeof t&&n.push(t),(0,h.useMemo)((()=>"function"==typeof t?t():t),n)}function p(t){return(0,h.useMemo)((()=>t.hooks.dragSource()),[t])}function v(t){return(0,h.useMemo)((()=>t.hooks.dragPreview()),[t])}function m(t,e,n,r){let i=n?n.call(r,t,e):void 0;if(void 0!==i)return!!i;if(t===e)return!0;if("object"!=typeof t||!t||"object"!=typeof e||!e)return!1;const o=Object.keys(t),a=Object.keys(e);if(o.length!==a.length)return!1;const s=Object.prototype.hasOwnProperty.bind(e);for(let a=0;a{const r=t[n];if(n.endsWith("Ref"))e[n]=t[n];else{const t=function(t){return(e=null,n=null)=>{if(!(0,h.isValidElement)(e)){const r=e;return t(r,n),r}const r=e;return function(t){if("string"==typeof t.type)return;const e=t.type.displayName||t.type.name||"the component";throw new Error(`Only native element nodes can now be passed to React DnD connectors.You can either wrap ${e} into a
, or turn it into a drag source or a drop target itself.`)}(r),function(t,e){const n=t.ref;return c("string"!=typeof n,"Cannot connect React DnD to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a or
. Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs"),n?(0,h.cloneElement)(t,{ref:t=>{w(n,t),w(e,t)}}):(0,h.cloneElement)(t,{ref:e})}(r,n?e=>t(e,n):t)}}(r);e[n]=()=>t}})),e}function w(t,e){"function"==typeof t?t(e):t.current=e}class x{receiveHandlerId(t){this.handlerId!==t&&(this.handlerId=t,this.reconnect())}get connectTarget(){return this.dragSource}get dragSourceOptions(){return this.dragSourceOptionsInternal}set dragSourceOptions(t){this.dragSourceOptionsInternal=t}get dragPreviewOptions(){return this.dragPreviewOptionsInternal}set dragPreviewOptions(t){this.dragPreviewOptionsInternal=t}reconnect(){const t=this.reconnectDragSource();this.reconnectDragPreview(t)}reconnectDragSource(){const t=this.dragSource,e=this.didHandlerIdChange()||this.didConnectedDragSourceChange()||this.didDragSourceOptionsChange();return e&&this.disconnectDragSource(),this.handlerId?t?(e&&(this.lastConnectedHandlerId=this.handlerId,this.lastConnectedDragSource=t,this.lastConnectedDragSourceOptions=this.dragSourceOptions,this.dragSourceUnsubscribe=this.backend.connectDragSource(this.handlerId,t,this.dragSourceOptions)),e):(this.lastConnectedDragSource=t,e):e}reconnectDragPreview(t=!1){const e=this.dragPreview,n=t||this.didHandlerIdChange()||this.didConnectedDragPreviewChange()||this.didDragPreviewOptionsChange();n&&this.disconnectDragPreview(),this.handlerId&&(e?n&&(this.lastConnectedHandlerId=this.handlerId,this.lastConnectedDragPreview=e,this.lastConnectedDragPreviewOptions=this.dragPreviewOptions,this.dragPreviewUnsubscribe=this.backend.connectDragPreview(this.handlerId,e,this.dragPreviewOptions)):this.lastConnectedDragPreview=e)}didHandlerIdChange(){return this.lastConnectedHandlerId!==this.handlerId}didConnectedDragSourceChange(){return this.lastConnectedDragSource!==this.dragSource}didConnectedDragPreviewChange(){return this.lastConnectedDragPreview!==this.dragPreview}didDragSourceOptionsChange(){return!m(this.lastConnectedDragSourceOptions,this.dragSourceOptions)}didDragPreviewOptionsChange(){return!m(this.lastConnectedDragPreviewOptions,this.dragPreviewOptions)}disconnectDragSource(){this.dragSourceUnsubscribe&&(this.dragSourceUnsubscribe(),this.dragSourceUnsubscribe=void 0)}disconnectDragPreview(){this.dragPreviewUnsubscribe&&(this.dragPreviewUnsubscribe(),this.dragPreviewUnsubscribe=void 0,this.dragPreviewNode=null,this.dragPreviewRef=null)}get dragSource(){return this.dragSourceNode||this.dragSourceRef&&this.dragSourceRef.current}get dragPreview(){return this.dragPreviewNode||this.dragPreviewRef&&this.dragPreviewRef.current}clearDragSource(){this.dragSourceNode=null,this.dragSourceRef=null}clearDragPreview(){this.dragPreviewNode=null,this.dragPreviewRef=null}constructor(t){this.hooks=b({dragSource:(t,e)=>{this.clearDragSource(),this.dragSourceOptions=e||null,y(t)?this.dragSourceRef=t:this.dragSourceNode=t,this.reconnectDragSource()},dragPreview:(t,e)=>{this.clearDragPreview(),this.dragPreviewOptions=e||null,y(t)?this.dragPreviewRef=t:this.dragPreviewNode=t,this.reconnectDragPreview()}}),this.handlerId=null,this.dragSourceRef=null,this.dragSourceOptionsInternal=null,this.dragPreviewRef=null,this.dragPreviewOptionsInternal=null,this.lastConnectedHandlerId=null,this.lastConnectedDragSource=null,this.lastConnectedDragSourceOptions=null,this.lastConnectedDragPreview=null,this.lastConnectedDragPreviewOptions=null,this.backend=t}}const _=(0,h.createContext)({dragDropManager:void 0});function C(){const{dragDropManager:t}=(0,h.useContext)(_);return c(null!=t,"Expected drag drop context"),t}let S=!1,O=!1;class D{receiveHandlerId(t){this.sourceId=t}getHandlerId(){return this.sourceId}canDrag(){c(!S,"You may not call monitor.canDrag() inside your canDrag() implementation. Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor");try{return S=!0,this.internalMonitor.canDragSource(this.sourceId)}finally{S=!1}}isDragging(){if(!this.sourceId)return!1;c(!O,"You may not call monitor.isDragging() inside your isDragging() implementation. Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor");try{return O=!0,this.internalMonitor.isDraggingSource(this.sourceId)}finally{O=!1}}subscribeToStateChange(t,e){return this.internalMonitor.subscribeToStateChange(t,e)}isDraggingSource(t){return this.internalMonitor.isDraggingSource(t)}isOverTarget(t,e){return this.internalMonitor.isOverTarget(t,e)}getTargetIds(){return this.internalMonitor.getTargetIds()}isSourcePublic(){return this.internalMonitor.isSourcePublic()}getSourceId(){return this.internalMonitor.getSourceId()}subscribeToOffsetChange(t){return this.internalMonitor.subscribeToOffsetChange(t)}canDragSource(t){return this.internalMonitor.canDragSource(t)}canDropOnTarget(t){return this.internalMonitor.canDropOnTarget(t)}getItemType(){return this.internalMonitor.getItemType()}getItem(){return this.internalMonitor.getItem()}getDropResult(){return this.internalMonitor.getDropResult()}didDrop(){return this.internalMonitor.didDrop()}getInitialClientOffset(){return this.internalMonitor.getInitialClientOffset()}getInitialSourceClientOffset(){return this.internalMonitor.getInitialSourceClientOffset()}getSourceClientOffset(){return this.internalMonitor.getSourceClientOffset()}getClientOffset(){return this.internalMonitor.getClientOffset()}getDifferenceFromInitialOffset(){return this.internalMonitor.getDifferenceFromInitialOffset()}constructor(t){this.sourceId=null,this.internalMonitor=t.getMonitor()}}class T{beginDrag(){const t=this.spec,e=this.monitor;let n=null;return n="object"==typeof t.item?t.item:"function"==typeof t.item?t.item(e):{},null!=n?n:null}canDrag(){const t=this.spec,e=this.monitor;return"boolean"==typeof t.canDrag?t.canDrag:"function"!=typeof t.canDrag||t.canDrag(e)}isDragging(t,e){const n=this.spec,r=this.monitor,{isDragging:i}=n;return i?i(r):e===t.getSourceId()}endDrag(){const t=this.spec,e=this.monitor,n=this.connector,{end:r}=t;r&&r(e.getItem(),e),n.reconnect()}constructor(t,e,n){this.spec=t,this.monitor=e,this.connector=n}}function I(t,e){const n=g(t,e);c(!n.begin,"useDrag::spec.begin was deprecated in v14. Replace spec.begin() with spec.item(). (see more here - https://react-dnd.github.io/react-dnd/docs/api/use-drag)");const r=function(){const t=C();return(0,h.useMemo)((()=>new D(t)),[t])}(),i=function(t,e){const n=C(),r=(0,h.useMemo)((()=>new x(n.getBackend())),[n]);return d((()=>(r.dragSourceOptions=t||null,r.reconnect(),()=>r.disconnectDragSource())),[r,t]),d((()=>(r.dragPreviewOptions=e||null,r.reconnect(),()=>r.disconnectDragPreview())),[r,e]),r}(n.options,n.previewOptions);return function(t,e,n){const r=C(),i=function(t,e,n){const r=(0,h.useMemo)((()=>new T(t,e,n)),[e,n]);return(0,h.useEffect)((()=>{r.spec=t}),[t]),r}(t,e,n),o=function(t){return(0,h.useMemo)((()=>{const e=t.type;return c(null!=e,"spec.type must be defined"),e}),[t])}(t);d((function(){if(null!=o){const[t,a]=function(t,e,n){const r=n.getRegistry(),i=r.addSource(t,e);return[i,()=>r.removeSource(i)]}(o,i,r);return e.receiveHandlerId(t),n.receiveHandlerId(t),a}}),[r,e,n,i,o])}(n,r,i),[f(n.collect,r,i),p(i),v(i)]}function E(t){return(0,h.useMemo)((()=>t.hooks.dropTarget()),[t])}class k{get connectTarget(){return this.dropTarget}reconnect(){const t=this.didHandlerIdChange()||this.didDropTargetChange()||this.didOptionsChange();t&&this.disconnectDropTarget();const e=this.dropTarget;this.handlerId&&(e?t&&(this.lastConnectedHandlerId=this.handlerId,this.lastConnectedDropTarget=e,this.lastConnectedDropTargetOptions=this.dropTargetOptions,this.unsubscribeDropTarget=this.backend.connectDropTarget(this.handlerId,e,this.dropTargetOptions)):this.lastConnectedDropTarget=e)}receiveHandlerId(t){t!==this.handlerId&&(this.handlerId=t,this.reconnect())}get dropTargetOptions(){return this.dropTargetOptionsInternal}set dropTargetOptions(t){this.dropTargetOptionsInternal=t}didHandlerIdChange(){return this.lastConnectedHandlerId!==this.handlerId}didDropTargetChange(){return this.lastConnectedDropTarget!==this.dropTarget}didOptionsChange(){return!m(this.lastConnectedDropTargetOptions,this.dropTargetOptions)}disconnectDropTarget(){this.unsubscribeDropTarget&&(this.unsubscribeDropTarget(),this.unsubscribeDropTarget=void 0)}get dropTarget(){return this.dropTargetNode||this.dropTargetRef&&this.dropTargetRef.current}clearDropTarget(){this.dropTargetRef=null,this.dropTargetNode=null}constructor(t){this.hooks=b({dropTarget:(t,e)=>{this.clearDropTarget(),this.dropTargetOptions=e,y(t)?this.dropTargetRef=t:this.dropTargetNode=t,this.reconnect()}}),this.handlerId=null,this.dropTargetRef=null,this.dropTargetOptionsInternal=null,this.lastConnectedHandlerId=null,this.lastConnectedDropTarget=null,this.lastConnectedDropTargetOptions=null,this.backend=t}}let N=!1;class j{receiveHandlerId(t){this.targetId=t}getHandlerId(){return this.targetId}subscribeToStateChange(t,e){return this.internalMonitor.subscribeToStateChange(t,e)}canDrop(){if(!this.targetId)return!1;c(!N,"You may not call monitor.canDrop() inside your canDrop() implementation. Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor");try{return N=!0,this.internalMonitor.canDropOnTarget(this.targetId)}finally{N=!1}}isOver(t){return!!this.targetId&&this.internalMonitor.isOverTarget(this.targetId,t)}getItemType(){return this.internalMonitor.getItemType()}getItem(){return this.internalMonitor.getItem()}getDropResult(){return this.internalMonitor.getDropResult()}didDrop(){return this.internalMonitor.didDrop()}getInitialClientOffset(){return this.internalMonitor.getInitialClientOffset()}getInitialSourceClientOffset(){return this.internalMonitor.getInitialSourceClientOffset()}getSourceClientOffset(){return this.internalMonitor.getSourceClientOffset()}getClientOffset(){return this.internalMonitor.getClientOffset()}getDifferenceFromInitialOffset(){return this.internalMonitor.getDifferenceFromInitialOffset()}constructor(t){this.targetId=null,this.internalMonitor=t.getMonitor()}}class M{canDrop(){const t=this.spec,e=this.monitor;return!t.canDrop||t.canDrop(e.getItem(),e)}hover(){const t=this.spec,e=this.monitor;t.hover&&t.hover(e.getItem(),e)}drop(){const t=this.spec,e=this.monitor;if(t.drop)return t.drop(e.getItem(),e)}constructor(t,e){this.spec=t,this.monitor=e}}function P(t,e){const n=g(t,e),r=function(){const t=C();return(0,h.useMemo)((()=>new j(t)),[t])}(),i=function(t){const e=C(),n=(0,h.useMemo)((()=>new k(e.getBackend())),[e]);return d((()=>(n.dropTargetOptions=t||null,n.reconnect(),()=>n.disconnectDropTarget())),[t]),n}(n.options);return function(t,e,n){const r=C(),i=function(t,e){const n=(0,h.useMemo)((()=>new M(t,e)),[e]);return(0,h.useEffect)((()=>{n.spec=t}),[t]),n}(t,e),o=function(t){const{accept:e}=t;return(0,h.useMemo)((()=>(c(null!=t.accept,"accept must be defined"),Array.isArray(e)?e:[e])),[e])}(t);d((function(){const[t,a]=function(t,e,n){const r=n.getRegistry(),i=r.addTarget(t,e);return[i,()=>r.removeTarget(i)]}(o,i,r);return e.receiveHandlerId(t),n.receiveHandlerId(t),a}),[r,e,i,n,o.map((t=>t.toString())).join("|")])}(n,r,i),[f(n.collect,r,i),E(i)]}const A=window.ReactJSXRuntime;function R(t){return"Minified Redux error #"+t+"; visit https://redux.js.org/Errors?code="+t+" for the full message or use the non-minified dev environment for full errors. "}var L="function"==typeof Symbol&&Symbol.observable||"@@observable",$=function(){return Math.random().toString(36).substring(7).split("").join(".")},H={INIT:"@@redux/INIT"+$(),REPLACE:"@@redux/REPLACE"+$(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+$()}};function B(t,e,n){var r;if("function"==typeof e&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(R(0));if("function"==typeof e&&void 0===n&&(n=e,e=void 0),void 0!==n){if("function"!=typeof n)throw new Error(R(1));return n(B)(t,e)}if("function"!=typeof t)throw new Error(R(2));var i=t,o=e,a=[],s=a,l=!1;function c(){s===a&&(s=a.slice())}function u(){if(l)throw new Error(R(3));return o}function h(t){if("function"!=typeof t)throw new Error(R(4));if(l)throw new Error(R(5));var e=!0;return c(),s.push(t),function(){if(e){if(l)throw new Error(R(6));e=!1,c();var n=s.indexOf(t);s.splice(n,1),a=null}}}function d(t){if(!function(t){if("object"!=typeof t||null===t)return!1;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}(t))throw new Error(R(7));if(void 0===t.type)throw new Error(R(8));if(l)throw new Error(R(9));try{l=!0,o=i(o,t)}finally{l=!1}for(var e=a=s,n=0;n=0;r--)if(e.canDragSource(t[r])){n=t[r];break}return n}(e,a);if(null==l)return void t.dispatch(z);let u=null;if(i){if(!o)throw new Error("getSourceClientOffset must be defined");!function(t){c("function"==typeof t,"When clientOffset is provided, getSourceClientOffset must be a function.")}(o),u=o(l)}t.dispatch(W(i,u));const h=s.getSource(l).beginDrag(a,l);if(null==h)return;!function(t){c(U(t),"Item must be an object.")}(h),s.pinSource(l);const d=s.getSourceType(l);return{type:V,payload:{itemType:d,item:h,sourceId:l,clientOffset:i||null,sourceClientOffset:u||null,isSourcePublic:!!r}}}}function J(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Z(t){for(var e=1;e{const a=function(t,e,n,r){const i=n.getTarget(t);let o=i?i.drop(r,t):void 0;return function(t){c(void 0===t||U(t),"Drop result must either be an object or undefined.")}(o),void 0===o&&(o=0===e?{}:r.getDropResult()),o}(i,o,r,n),s={type:q,payload:{dropResult:Z({},e,a)}};t.dispatch(s)}))}}function tt(t){return function(){const e=t.getMonitor(),n=t.getRegistry();!function(t){c(t.isDragging(),"Cannot call endDrag while not dragging.")}(e);const r=e.getSourceId();return null!=r&&(n.getSource(r,!0).endDrag(e,r),n.unpinSource()),{type:Y}}}function et(t,e){return null===e?null===t:Array.isArray(t)?t.some((t=>t===e)):t===e}function nt(t){return function(e,{clientOffset:n}={}){!function(t){c(Array.isArray(t),"Expected targetIds to be an array.")}(e);const r=e.slice(0),i=t.getMonitor(),o=t.getRegistry();return function(t,e,n){for(let r=t.length-1;r>=0;r--){const i=t[r];et(e.getTargetType(i),n)||t.splice(r,1)}}(r,o,i.getItemType()),function(t,e,n){c(e.isDragging(),"Cannot call hover while not dragging."),c(!e.didDrop(),"Cannot call hover after drop.");for(let e=0;e{const o=n[i];var a;return r[i]=(a=o,(...n)=>{const r=a.apply(t,n);void 0!==r&&e(r)}),r}),{})}dispatch(t){this.store.dispatch(t)}constructor(t,e){this.isSetUp=!1,this.handleRefCountChange=()=>{const t=this.store.getState().refCount>0;this.backend&&(t&&!this.isSetUp?(this.backend.setup(),this.isSetUp=!0):!t&&this.isSetUp&&(this.backend.teardown(),this.isSetUp=!1))},this.store=t,this.monitor=e,t.subscribe(this.handleRefCountChange)}}function ot(t,e){return{x:t.x-e.x,y:t.y-e.y}}const at=[],st=[];at.__IS_NONE__=!0,st.__IS_ALL__=!0;class lt{subscribeToStateChange(t,e={}){const{handlerIds:n}=e;c("function"==typeof t,"listener must be a function."),c(void 0===n||Array.isArray(n),"handlerIds, when specified, must be an array of strings.");let r=this.store.getState().stateId;return this.store.subscribe((()=>{const e=this.store.getState(),i=e.stateId;try{const o=i===r||i===r+1&&!function(t,e){return t!==at&&(t===st||void 0===e||(n=t,e.filter((t=>n.indexOf(t)>-1))).length>0);var n}(e.dirtyHandlerIds,n);o||t()}finally{r=i}}))}subscribeToOffsetChange(t){c("function"==typeof t,"listener must be a function.");let e=this.store.getState().dragOffset;return this.store.subscribe((()=>{const n=this.store.getState().dragOffset;n!==e&&(e=n,t())}))}canDragSource(t){if(!t)return!1;const e=this.registry.getSource(t);return c(e,`Expected to find a valid source. sourceId=${t}`),!this.isDragging()&&e.canDrag(this,t)}canDropOnTarget(t){if(!t)return!1;const e=this.registry.getTarget(t);return c(e,`Expected to find a valid target. targetId=${t}`),!(!this.isDragging()||this.didDrop())&&(et(this.registry.getTargetType(t),this.getItemType())&&e.canDrop(this,t))}isDragging(){return Boolean(this.getItemType())}isDraggingSource(t){if(!t)return!1;const e=this.registry.getSource(t,!0);return c(e,`Expected to find a valid source. sourceId=${t}`),!(!this.isDragging()||!this.isSourcePublic())&&(this.registry.getSourceType(t)===this.getItemType()&&e.isDragging(this,t))}isOverTarget(t,e={shallow:!1}){if(!t)return!1;const{shallow:n}=e;if(!this.isDragging())return!1;const r=this.registry.getTargetType(t),i=this.getItemType();if(i&&!et(r,i))return!1;const o=this.getTargetIds();if(!o.length)return!1;const a=o.indexOf(t);return n?a===o.length-1:a>-1}getItemType(){return this.store.getState().dragOperation.itemType}getItem(){return this.store.getState().dragOperation.item}getSourceId(){return this.store.getState().dragOperation.sourceId}getTargetIds(){return this.store.getState().dragOperation.targetIds}getDropResult(){return this.store.getState().dragOperation.dropResult}didDrop(){return this.store.getState().dragOperation.didDrop}isSourcePublic(){return Boolean(this.store.getState().dragOperation.isSourcePublic)}getInitialClientOffset(){return this.store.getState().dragOffset.initialClientOffset}getInitialSourceClientOffset(){return this.store.getState().dragOffset.initialSourceClientOffset}getClientOffset(){return this.store.getState().dragOffset.clientOffset}getSourceClientOffset(){return function(t){const{clientOffset:e,initialClientOffset:n,initialSourceClientOffset:r}=t;return e&&n&&r?ot((o=r,{x:(i=e).x+o.x,y:i.y+o.y}),n):null;var i,o}(this.store.getState().dragOffset)}getDifferenceFromInitialOffset(){return function(t){const{clientOffset:e,initialClientOffset:n}=t;return e&&n?ot(e,n):null}(this.store.getState().dragOffset)}constructor(t,e){this.store=t,this.registry=e}}const ct="undefined"!=typeof global?global:self,ut=ct.MutationObserver||ct.WebKitMutationObserver;function ht(t){return function(){const e=setTimeout(r,0),n=setInterval(r,50);function r(){clearTimeout(e),clearInterval(n),t()}}}const dt="function"==typeof ut?function(t){let e=1;const n=new ut(t),r=document.createTextNode("");return n.observe(r,{characterData:!0}),function(){e=-e,r.data=e}}:ht;class ft{call(){try{this.task&&this.task()}catch(t){this.onError(t)}finally{this.task=null,this.release(this)}}constructor(t,e){this.onError=t,this.release=e,this.task=null}}const gt=new class{enqueueTask(t){const{queue:e,requestFlush:n}=this;e.length||(n(),this.flushing=!0),e[e.length]=t}constructor(){this.queue=[],this.pendingErrors=[],this.flushing=!1,this.index=0,this.capacity=1024,this.flush=()=>{const{queue:t}=this;for(;this.indexthis.capacity){for(let e=0,n=t.length-this.index;e{this.pendingErrors.push(t),this.requestErrorThrow()},this.requestFlush=dt(this.flush),this.requestErrorThrow=ht((()=>{if(this.pendingErrors.length)throw this.pendingErrors.shift()}))}},pt=new class{create(t){const e=this.freeTasks,n=e.length?e.pop():new ft(this.onError,(t=>e[e.length]=t));return n.task=t,n}constructor(t){this.onError=t,this.freeTasks=[]}}(gt.registerPendingError),vt="dnd-core/ADD_SOURCE",mt="dnd-core/ADD_TARGET",yt="dnd-core/REMOVE_SOURCE",bt="dnd-core/REMOVE_TARGET";function wt(t,e){e&&Array.isArray(t)?t.forEach((t=>wt(t,!1))):c("string"==typeof t||"symbol"==typeof t,e?"Type can only be a string, a symbol, or an array of either.":"Type can only be a string or a symbol.")}var xt;!function(t){t.SOURCE="SOURCE",t.TARGET="TARGET"}(xt||(xt={}));let _t=0;function Ct(t){switch(t[0]){case"S":return xt.SOURCE;case"T":return xt.TARGET;default:throw new Error(`Cannot parse handler ID: ${t}`)}}function St(t,e){const n=t.entries();let r=!1;do{const{done:t,value:[,i]}=n.next();if(i===e)return!0;r=!!t}while(!r);return!1}class Ot{addSource(t,e){wt(t),function(t){c("function"==typeof t.canDrag,"Expected canDrag to be a function."),c("function"==typeof t.beginDrag,"Expected beginDrag to be a function."),c("function"==typeof t.endDrag,"Expected endDrag to be a function.")}(e);const n=this.addHandler(xt.SOURCE,t,e);return this.store.dispatch(function(t){return{type:vt,payload:{sourceId:t}}}(n)),n}addTarget(t,e){wt(t,!0),function(t){c("function"==typeof t.canDrop,"Expected canDrop to be a function."),c("function"==typeof t.hover,"Expected hover to be a function."),c("function"==typeof t.drop,"Expected beginDrag to be a function.")}(e);const n=this.addHandler(xt.TARGET,t,e);return this.store.dispatch(function(t){return{type:mt,payload:{targetId:t}}}(n)),n}containsHandler(t){return St(this.dragSources,t)||St(this.dropTargets,t)}getSource(t,e=!1){return c(this.isSourceId(t),"Expected a valid source ID."),e&&t===this.pinnedSourceId?this.pinnedSource:this.dragSources.get(t)}getTarget(t){return c(this.isTargetId(t),"Expected a valid target ID."),this.dropTargets.get(t)}getSourceType(t){return c(this.isSourceId(t),"Expected a valid source ID."),this.types.get(t)}getTargetType(t){return c(this.isTargetId(t),"Expected a valid target ID."),this.types.get(t)}isSourceId(t){return Ct(t)===xt.SOURCE}isTargetId(t){return Ct(t)===xt.TARGET}removeSource(t){var e;c(this.getSource(t),"Expected an existing source."),this.store.dispatch(function(t){return{type:yt,payload:{sourceId:t}}}(t)),e=()=>{this.dragSources.delete(t),this.types.delete(t)},gt.enqueueTask(pt.create(e))}removeTarget(t){c(this.getTarget(t),"Expected an existing target."),this.store.dispatch(function(t){return{type:bt,payload:{targetId:t}}}(t)),this.dropTargets.delete(t),this.types.delete(t)}pinSource(t){const e=this.getSource(t);c(e,"Expected an existing source."),this.pinnedSourceId=t,this.pinnedSource=e}unpinSource(){c(this.pinnedSource,"No source is pinned at the time."),this.pinnedSourceId=null,this.pinnedSource=null}addHandler(t,e,n){const r=function(t){const e=(_t++).toString();switch(t){case xt.SOURCE:return`S${e}`;case xt.TARGET:return`T${e}`;default:throw new Error(`Unknown Handler Role: ${t}`)}}(t);return this.types.set(r,e),t===xt.SOURCE?this.dragSources.set(r,n):t===xt.TARGET&&this.dropTargets.set(r,n),r}constructor(t){this.types=new Map,this.dragSources=new Map,this.dropTargets=new Map,this.pinnedSourceId=null,this.pinnedSource=null,this.store=t}}const Dt=(t,e)=>t===e;function Tt(t=at,e){switch(e.type){case X:break;case vt:case mt:case bt:case yt:return at;default:return st}const{targetIds:n=[],prevTargetIds:r=[]}=e.payload,i=function(t,e){const n=new Map,r=t=>{n.set(t,n.has(t)?n.get(t)+1:1)};t.forEach(r),e.forEach(r);const i=[];return n.forEach(((t,e)=>{1===t&&i.push(e)})),i}(n,r);if(!(i.length>0)&&function(t,e,n=Dt){if(t.length!==e.length)return!1;for(let r=0;rt!==i)))});case q:return jt({},t,{dropResult:n.dropResult,didDrop:!0,targetIds:[]});case Y:return jt({},t,{itemType:null,item:null,sourceId:null,dropResult:null,didDrop:!1,isSourcePublic:null,targetIds:[]});default:return t}var r,i}function At(t=0,e){switch(e.type){case vt:case mt:return t+1;case yt:case bt:return t-1;default:return t}}function Rt(t=0){return t+1}function Lt(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function $t(t){for(var e=1;et&&t[e]?t[e]:r||null),n))})}),dragOffset:kt(t.dragOffset,e),refCount:At(t.refCount,e),dragOperation:Pt(t.dragOperation,e),stateId:Rt(t.stateId)};var n,r}function Bt(t,e=void 0,n={},r=!1){const i=function(t){const e="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__;return B(Ht,t&&e&&e({name:"dnd-core",instanceId:"dnd-core"}))}(r),o=new lt(i,new Ot(i)),a=new it(i,o),s=t(a,e,n);return a.receiveBackend(s),a}let Ut=0;const Ft=Symbol.for("__REACT_DND_CONTEXT_INSTANCE__");var Vt=(0,h.memo)((function(t){var{children:e}=t,n=function(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}(t,["children"]);const[r,i]=function(t){if("manager"in t)return[{dragDropManager:t.manager},!1];return[function(t,e=Gt(),n,r){const i=e;return i[Ft]||(i[Ft]={dragDropManager:Bt(t,e,n,r)}),i[Ft]}(t.backend,t.context,t.options,t.debugMode),!t.context]}(n);return(0,h.useEffect)((()=>{if(i){const t=Gt();return++Ut,()=>{0==--Ut&&(t[Ft]=null)}}}),[]),(0,A.jsx)(_.Provider,{value:r,children:e})}));function Gt(){return"undefined"!=typeof global?global:window}function Xt(t){let e=null;return()=>(null==e&&(e=t()),e)}class qt{enter(t){const e=this.entered.length;return this.entered=function(t,e){const n=new Set,r=t=>n.add(t);t.forEach(r),e.forEach(r);const i=[];return n.forEach((t=>i.push(t))),i}(this.entered.filter((e=>this.isNodeInDocument(e)&&(!e.contains||e.contains(t)))),[t]),0===e&&this.entered.length>0}leave(t){const e=this.entered.length;var n,r;return this.entered=(n=this.entered.filter(this.isNodeInDocument),r=t,n.filter((t=>t!==r))),e>0&&0===this.entered.length}reset(){this.entered=[]}constructor(t){this.entered=[],this.isNodeInDocument=t}}class Yt{initializeExposedProperties(){Object.keys(this.config.exposeProperties).forEach((t=>{Object.defineProperty(this.item,t,{configurable:!0,enumerable:!0,get:()=>(console.warn(`Browser doesn't allow reading "${t}" until the drop event.`),null)})}))}loadDataTransfer(t){if(t){const e={};Object.keys(this.config.exposeProperties).forEach((n=>{const r=this.config.exposeProperties[n];null!=r&&(e[n]={value:r(t,this.config.matchesTypes),configurable:!0,enumerable:!0})})),Object.defineProperties(this.item,e)}}canDrag(){return!0}beginDrag(){return this.item}isDragging(t,e){return e===t.getSourceId()}endDrag(){}constructor(t){this.config=t,this.item={},this.initializeExposedProperties()}}const Wt="__NATIVE_FILE__",zt="__NATIVE_URL__",Kt="__NATIVE_TEXT__",Jt="__NATIVE_HTML__";function Zt(t,e,n){const r=e.reduce(((e,n)=>e||t.getData(n)),"");return null!=r?r:n}const Qt={[Wt]:{exposeProperties:{files:t=>Array.prototype.slice.call(t.files),items:t=>t.items,dataTransfer:t=>t},matchesTypes:["Files"]},[Jt]:{exposeProperties:{html:(t,e)=>Zt(t,e,""),dataTransfer:t=>t},matchesTypes:["Html","text/html"]},[zt]:{exposeProperties:{urls:(t,e)=>Zt(t,e,"").split("\n"),dataTransfer:t=>t},matchesTypes:["Url","text/uri-list"]},[Kt]:{exposeProperties:{text:(t,e)=>Zt(t,e,""),dataTransfer:t=>t},matchesTypes:["Text","text/plain"]}};function te(t){if(!t)return null;const e=Array.prototype.slice.call(t.types||[]);return Object.keys(Qt).filter((t=>{const n=Qt[t];return!!(null==n?void 0:n.matchesTypes)&&n.matchesTypes.some((t=>e.indexOf(t)>-1))}))[0]||null}const ee=Xt((()=>/firefox/i.test(navigator.userAgent))),ne=Xt((()=>Boolean(window.safari)));class re{interpolate(t){const{xs:e,ys:n,c1s:r,c2s:i,c3s:o}=this;let a=e.length-1;if(t===e[a])return n[a];let s,l=0,c=o.length-1;for(;l<=c;){s=Math.floor(.5*(l+c));const r=e[s];if(rt))return n[s];c=s-1}}a=Math.max(0,c);const u=t-e[a],h=u*u;return n[a]+r[a]*u+i[a]*h+o[a]*u*h}constructor(t,e){const{length:n}=t,r=[];for(let t=0;tt[e]{this.sourcePreviewNodes.delete(t),this.sourcePreviewNodeOptions.delete(t)}}connectDragSource(t,e,n){this.sourceNodes.set(t,e),this.sourceNodeOptions.set(t,n);const r=e=>this.handleDragStart(e,t),i=t=>this.handleSelectStart(t);return e.setAttribute("draggable","true"),e.addEventListener("dragstart",r),e.addEventListener("selectstart",i),()=>{this.sourceNodes.delete(t),this.sourceNodeOptions.delete(t),e.removeEventListener("dragstart",r),e.removeEventListener("selectstart",i),e.setAttribute("draggable","false")}}connectDropTarget(t,e){const n=e=>this.handleDragEnter(e,t),r=e=>this.handleDragOver(e,t),i=e=>this.handleDrop(e,t);return e.addEventListener("dragenter",n),e.addEventListener("dragover",r),e.addEventListener("drop",i),()=>{e.removeEventListener("dragenter",n),e.removeEventListener("dragover",r),e.removeEventListener("drop",i)}}addEventListeners(t){t.addEventListener&&(t.addEventListener("dragstart",this.handleTopDragStart),t.addEventListener("dragstart",this.handleTopDragStartCapture,!0),t.addEventListener("dragend",this.handleTopDragEndCapture,!0),t.addEventListener("dragenter",this.handleTopDragEnter),t.addEventListener("dragenter",this.handleTopDragEnterCapture,!0),t.addEventListener("dragleave",this.handleTopDragLeaveCapture,!0),t.addEventListener("dragover",this.handleTopDragOver),t.addEventListener("dragover",this.handleTopDragOverCapture,!0),t.addEventListener("drop",this.handleTopDrop),t.addEventListener("drop",this.handleTopDropCapture,!0))}removeEventListeners(t){t.removeEventListener&&(t.removeEventListener("dragstart",this.handleTopDragStart),t.removeEventListener("dragstart",this.handleTopDragStartCapture,!0),t.removeEventListener("dragend",this.handleTopDragEndCapture,!0),t.removeEventListener("dragenter",this.handleTopDragEnter),t.removeEventListener("dragenter",this.handleTopDragEnterCapture,!0),t.removeEventListener("dragleave",this.handleTopDragLeaveCapture,!0),t.removeEventListener("dragover",this.handleTopDragOver),t.removeEventListener("dragover",this.handleTopDragOverCapture,!0),t.removeEventListener("drop",this.handleTopDrop),t.removeEventListener("drop",this.handleTopDropCapture,!0))}getCurrentSourceNodeOptions(){const t=this.monitor.getSourceId(),e=this.sourceNodeOptions.get(t);return le({dropEffect:this.altKeyPressed?"copy":"move"},e||{})}getCurrentDropEffect(){return this.isDraggingNativeItem()?"copy":this.getCurrentSourceNodeOptions().dropEffect}getCurrentSourcePreviewNodeOptions(){const t=this.monitor.getSourceId();return le({anchorX:.5,anchorY:.5,captureDraggingState:!1},this.sourcePreviewNodeOptions.get(t)||{})}isDraggingNativeItem(){const t=this.monitor.getItemType();return Object.keys(r).some((e=>r[e]===t))}beginDragNativeItem(t,e){this.clearCurrentDragSourceNode(),this.currentNativeSource=function(t,e){const n=Qt[t];if(!n)throw new Error(`native type ${t} has no configuration`);const r=new Yt(n);return r.loadDataTransfer(e),r}(t,e),this.currentNativeHandle=this.registry.addSource(t,this.currentNativeSource),this.actions.beginDrag([this.currentNativeHandle])}setCurrentDragSourceNode(t){this.clearCurrentDragSourceNode(),this.currentDragSourceNode=t,this.mouseMoveTimeoutTimer=setTimeout((()=>{var t;return null===(t=this.rootElement)||void 0===t?void 0:t.addEventListener("mousemove",this.endDragIfSourceWasRemovedFromDOM,!0)}),1e3)}clearCurrentDragSourceNode(){var t;return!!this.currentDragSourceNode&&(this.currentDragSourceNode=null,this.rootElement&&(null===(t=this.window)||void 0===t||t.clearTimeout(this.mouseMoveTimeoutTimer||void 0),this.rootElement.removeEventListener("mousemove",this.endDragIfSourceWasRemovedFromDOM,!0)),this.mouseMoveTimeoutTimer=null,!0)}handleDragStart(t,e){t.defaultPrevented||(this.dragStartSourceIds||(this.dragStartSourceIds=[]),this.dragStartSourceIds.unshift(e))}handleDragEnter(t,e){this.dragEnterTargetIds.unshift(e)}handleDragOver(t,e){null===this.dragOverTargetIds&&(this.dragOverTargetIds=[]),this.dragOverTargetIds.unshift(e)}handleDrop(t,e){this.dropTargetIds.unshift(e)}constructor(t,e,n){this.sourcePreviewNodes=new Map,this.sourcePreviewNodeOptions=new Map,this.sourceNodes=new Map,this.sourceNodeOptions=new Map,this.dragStartSourceIds=null,this.dropTargetIds=[],this.dragEnterTargetIds=[],this.currentNativeSource=null,this.currentNativeHandle=null,this.currentDragSourceNode=null,this.altKeyPressed=!1,this.mouseMoveTimeoutTimer=null,this.asyncEndDragFrameId=null,this.dragOverTargetIds=null,this.lastClientOffset=null,this.hoverRafId=null,this.getSourceClientOffset=t=>{const e=this.sourceNodes.get(t);return e&&ie(e)||null},this.endDragNativeItem=()=>{this.isDraggingNativeItem()&&(this.actions.endDrag(),this.currentNativeHandle&&this.registry.removeSource(this.currentNativeHandle),this.currentNativeHandle=null,this.currentNativeSource=null)},this.isNodeInDocument=t=>Boolean(t&&this.document&&this.document.body&&this.document.body.contains(t)),this.endDragIfSourceWasRemovedFromDOM=()=>{const t=this.currentDragSourceNode;null==t||this.isNodeInDocument(t)||(this.clearCurrentDragSourceNode()&&this.monitor.isDragging()&&this.actions.endDrag(),this.cancelHover())},this.scheduleHover=t=>{null===this.hoverRafId&&"undefined"!=typeof requestAnimationFrame&&(this.hoverRafId=requestAnimationFrame((()=>{this.monitor.isDragging()&&this.actions.hover(t||[],{clientOffset:this.lastClientOffset}),this.hoverRafId=null})))},this.cancelHover=()=>{null!==this.hoverRafId&&"undefined"!=typeof cancelAnimationFrame&&(cancelAnimationFrame(this.hoverRafId),this.hoverRafId=null)},this.handleTopDragStartCapture=()=>{this.clearCurrentDragSourceNode(),this.dragStartSourceIds=[]},this.handleTopDragStart=t=>{if(t.defaultPrevented)return;const{dragStartSourceIds:e}=this;this.dragStartSourceIds=null;const n=oe(t);this.monitor.isDragging()&&(this.actions.endDrag(),this.cancelHover()),this.actions.beginDrag(e||[],{publishSource:!1,getSourceClientOffset:this.getSourceClientOffset,clientOffset:n});const{dataTransfer:r}=t,i=te(r);if(this.monitor.isDragging()){if(r&&"function"==typeof r.setDragImage){const t=this.monitor.getSourceId(),e=this.sourceNodes.get(t),i=this.sourcePreviewNodes.get(t)||e;if(i){const{anchorX:t,anchorY:o,offsetX:a,offsetY:s}=this.getCurrentSourcePreviewNodeOptions(),l=function(t,e,n,r,i){const o="IMG"===(m=e).nodeName&&(ee()||!(null===(y=document.documentElement)||void 0===y?void 0:y.contains(m))),a=ie(o?t:e),s={x:n.x-a.x,y:n.y-a.y},{offsetWidth:l,offsetHeight:c}=t,{anchorX:u,anchorY:h}=r,{dragPreviewWidth:d,dragPreviewHeight:f}=function(t,e,n,r){let i=t?e.width:n,o=t?e.height:r;return ne()&&t&&(o/=window.devicePixelRatio,i/=window.devicePixelRatio),{dragPreviewWidth:i,dragPreviewHeight:o}}(o,e,l,c),{offsetX:g,offsetY:p}=i,v=0===p||p;var m,y;return{x:0===g||g?g:new re([0,.5,1],[s.x,s.x/l*d,s.x+d-l]).interpolate(u),y:v?p:(()=>{let t=new re([0,.5,1],[s.y,s.y/c*f,s.y+f-c]).interpolate(h);return ne()&&o&&(t+=(window.devicePixelRatio-1)*f),t})()}}(e,i,n,{anchorX:t,anchorY:o},{offsetX:a,offsetY:s});r.setDragImage(i,l.x,l.y)}}try{null==r||r.setData("application/json",{})}catch(t){}this.setCurrentDragSourceNode(t.target);const{captureDraggingState:e}=this.getCurrentSourcePreviewNodeOptions();e?this.actions.publishDragSource():setTimeout((()=>this.actions.publishDragSource()),0)}else if(i)this.beginDragNativeItem(i);else{if(r&&!r.types&&(t.target&&!t.target.hasAttribute||!t.target.hasAttribute("draggable")))return;t.preventDefault()}},this.handleTopDragEndCapture=()=>{this.clearCurrentDragSourceNode()&&this.monitor.isDragging()&&this.actions.endDrag(),this.cancelHover()},this.handleTopDragEnterCapture=t=>{var e;if(this.dragEnterTargetIds=[],this.isDraggingNativeItem()&&(null===(e=this.currentNativeSource)||void 0===e||e.loadDataTransfer(t.dataTransfer)),!this.enterLeaveCounter.enter(t.target)||this.monitor.isDragging())return;const{dataTransfer:n}=t,r=te(n);r&&this.beginDragNativeItem(r,n)},this.handleTopDragEnter=t=>{const{dragEnterTargetIds:e}=this;this.dragEnterTargetIds=[],this.monitor.isDragging()&&(this.altKeyPressed=t.altKey,e.length>0&&this.actions.hover(e,{clientOffset:oe(t)}),e.some((t=>this.monitor.canDropOnTarget(t)))&&(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect=this.getCurrentDropEffect())))},this.handleTopDragOverCapture=t=>{var e;this.dragOverTargetIds=[],this.isDraggingNativeItem()&&(null===(e=this.currentNativeSource)||void 0===e||e.loadDataTransfer(t.dataTransfer))},this.handleTopDragOver=t=>{const{dragOverTargetIds:e}=this;if(this.dragOverTargetIds=[],!this.monitor.isDragging())return t.preventDefault(),void(t.dataTransfer&&(t.dataTransfer.dropEffect="none"));this.altKeyPressed=t.altKey,this.lastClientOffset=oe(t),this.scheduleHover(e),(e||[]).some((t=>this.monitor.canDropOnTarget(t)))?(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect=this.getCurrentDropEffect())):this.isDraggingNativeItem()?t.preventDefault():(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="none"))},this.handleTopDragLeaveCapture=t=>{this.isDraggingNativeItem()&&t.preventDefault(),this.enterLeaveCounter.leave(t.target)&&(this.isDraggingNativeItem()&&setTimeout((()=>this.endDragNativeItem()),0),this.cancelHover())},this.handleTopDropCapture=t=>{var e;this.dropTargetIds=[],this.isDraggingNativeItem()?(t.preventDefault(),null===(e=this.currentNativeSource)||void 0===e||e.loadDataTransfer(t.dataTransfer)):te(t.dataTransfer)&&t.preventDefault(),this.enterLeaveCounter.reset()},this.handleTopDrop=t=>{const{dropTargetIds:e}=this;this.dropTargetIds=[],this.actions.hover(e,{clientOffset:oe(t)}),this.actions.drop({dropEffect:this.getCurrentDropEffect()}),this.isDraggingNativeItem()?this.endDragNativeItem():this.monitor.isDragging()&&this.actions.endDrag(),this.cancelHover()},this.handleSelectStart=t=>{const e=t.target;"function"==typeof e.dragDrop&&("INPUT"===e.tagName||"SELECT"===e.tagName||"TEXTAREA"===e.tagName||e.isContentEditable||(t.preventDefault(),e.dragDrop()))},this.options=new ae(e,n),this.actions=t.getActions(),this.monitor=t.getMonitor(),this.registry=t.getRegistry(),this.enterLeaveCounter=new qt(this.isNodeInDocument)}}const ue=function(t,e,n){return new ce(t,e,n)},he="dataset_item",de=({item:t,datasetKey:e,moveItem:n,updateItem:r,items:i})=>{const[a,c]=(0,l.useState)(!1),u=(0,l.useRef)(null),[{isDragging:h},d]=I({type:he,item:{id:t.id,datasetKey:e},collect:t=>({isDragging:t.isDragging()})}),[{isOver:f},g]=P({accept:he,hover(e,r){if(!u.current)return;if(e.id===t.id)return;const i=u.current.getBoundingClientRect(),o=(i.bottom-i.top)/2,a=(i.right-i.left)/2,s=r.getClientOffset();if(!s)return;const l=s.y-i.top,c=s.x-i.left>a&&l>o;n(e.id,t.id,c)},collect:t=>({isOver:t.isOver()})});d(g(u));const p=i.filter((e=>e.parent===t.id)),v={marginLeft:t.parent?"20px":"0",opacity:h?.5:1,cursor:"move",background:f?"#f0f0f0":"white",border:f?"2px dashed #0073aa":"1px solid #e2e4e7",marginBottom:"8px",transition:"all 0.2s ease"};return(0,A.jsxs)("div",{children:[(0,A.jsx)("div",{ref:u,style:v,children:(0,A.jsx)(s.Card,{children:(0,A.jsx)(s.CardBody,{children:(0,A.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[(0,A.jsx)(s.TextControl,{placeholder:(0,o.__)("Label","lcp"),value:t.label,onChange:n=>r(e,t.id,"label",n),style:{flex:2}}),(0,A.jsx)(s.TextControl,{type:"number",placeholder:(0,o.__)("Value","lcp"),value:t.value,onChange:n=>r(e,t.id,"value",parseFloat(n)),style:{flex:1}}),(0,A.jsxs)("div",{style:{position:"relative"},children:[(0,A.jsx)(s.Button,{onClick:()=>c(!0),style:{backgroundColor:t.color,width:"30px",height:"30px",borderRadius:"50%",padding:0,border:"1px solid #ddd"}}),a&&(0,A.jsx)(s.Popover,{onClose:()=>c(!1),position:"bottom center",children:(0,A.jsx)("div",{style:{padding:"10px"},children:(0,A.jsx)(s.ColorPicker,{color:t.color,onChange:n=>r(e,t.id,"color",n),enableAlpha:!1})})})]})]})})})}),p.map((t=>(0,A.jsx)(de,{item:t,datasetKey:e,moveItem:n,updateItem:r,items:i},t.id)))]})},fe=({value:t,onChange:e})=>{const[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(t||{}),c=()=>{const t=`Dataset ${Object.keys(i).length+1}`,n={...i,[t]:[{id:`dataset-${Date.now()}`,label:t,parent:null,value:0,color:"#000000"}]};a(n),e(n)},u=(t,n,r,o)=>{const s={...i,[t]:i[t].map((t=>t.id===n?{...t,[r]:o}:t))};a(s),e(s)},h=(t,n,r)=>{const o=Object.keys(i).find((e=>i[e].some((e=>e.id===t))));if(!o)return;const s=[...i[o]],l=s.find((e=>e.id===t)),c=s.find((t=>t.id===n));if(!l||!c)return;let u=c;for(;u.parent;){if(u.parent===t)return;u=s.find((t=>t.id===u.parent))}l.parent=r?n:c.parent;const h={...i,[o]:s};a(h),e(h)};return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(s.Button,{variant:"primary",onClick:()=>{r(!0),0===Object.keys(i).length&&c()},children:(0,o.__)("Open Dataset Builder","lcp")}),n&&(0,A.jsx)(s.Modal,{title:(0,o.__)("Dataset Builder","lcp"),onRequestClose:()=>r(!1),style:{width:"90vw"},children:(0,A.jsx)(Vt,{backend:ue,children:(0,A.jsxs)("div",{style:{padding:"20px"},children:[Object.entries(i).map((([t,n])=>(0,A.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,A.jsx)("h3",{children:t}),(0,A.jsx)("div",{children:n.filter((t=>!t.parent)).map((e=>(0,A.jsx)(de,{item:e,datasetKey:t,moveItem:h,updateItem:u,items:n},e.id)))}),(0,A.jsx)(s.Button,{variant:"secondary",onClick:()=>(t=>{const n={id:`item-${Date.now()}`,label:"New Item",parent:null,value:0,color:"#000000"},r={...i,[t]:[...i[t],n]};a(r),e(r)})(t),style:{marginTop:"10px"},children:(0,o.__)("Add Item","lcp")})]},t))),(0,A.jsx)(s.Button,{variant:"primary",onClick:c,style:{marginTop:"20px"},children:(0,o.__)("Add New Dataset","lcp")})]})})})]})},ge=["#FF6384","#36A2EB","#FFCE56","#4BC0C0","#9966FF","#FF9F40","#FF6384","#C9CBCF","#4BC0C0","#FF9F40"],pe=({value:t,onChange:e,dataSource:n,onDataSourceChange:r})=>{const[i,c]=(0,l.useState)(""),[u,h]=(0,l.useState)(""),[d,f]=(0,l.useState)("");(0,l.useEffect)((()=>{if(t&&Object.keys(t).length>0)if("manual_json"===n)h(JSON.stringify(t,null,2));else if("csv_url"===n){const e=t[Object.keys(t)[0]]?.[0]?.sourceUrl;e&&c(e)}}),[]);const g=[{label:(0,o.__)("Manual JSON","lcp"),value:"manual_json"},{label:(0,o.__)("CSV Upload","lcp"),value:"csv_upload"},{label:(0,o.__)("CSV URL","lcp"),value:"csv_url"},{label:(0,o.__)("Dataset Builder","lcp"),value:"dataset_builder"}],p=(t,e="")=>{try{const n=t.split("\n");if(n.length<2)throw new Error("CSV must have at least a header row and one data row");const r=n[0].split(",").map((t=>t.trim()));if(!r.includes("label")||!r.includes("value"))throw new Error('CSV must have "label" and "value" columns');const i={"Dataset 1":n.slice(1).filter((t=>t.trim())).map(((t,n)=>{const i=t.split(",").map((t=>t.trim())),o={};return r.forEach(((t,e)=>{"color"!==t||i[e]?o[t]=i[e]:o[t]=ge[n%ge.length]})),e&&(o.sourceUrl=e),o}))};return f(""),i}catch(t){return f("Error parsing CSV: "+t.message),null}};return(0,A.jsxs)("div",{className:"lcp-data-selector",children:[(0,A.jsx)(s.SelectControl,{label:(0,o.__)("Data Source","lcp"),value:n,options:g,onChange:r}),"dataset_builder"===n&&(0,A.jsx)(fe,{value:t,onChange:t=>{e(t)}}),"manual_json"===n&&(0,A.jsx)(s.TextareaControl,{label:(0,o.__)("JSON Data","lcp"),help:(0,o.__)("Enter datasets with arrays containing objects with label and value properties. Color is optional.","lcp"),value:u,onChange:t=>{h(t);const n=(t=>{try{const e=JSON.parse(t);if("object"!=typeof e||Array.isArray(e))throw new Error("Data must be an object with dataset names as keys");return Object.entries(e).forEach((([t,e])=>{if(!Array.isArray(e))throw new Error(`Dataset "${t}" must be an array`);e.forEach(((e,n)=>{if(!e.label||!e.value)throw new Error(`Item at index ${n} in dataset "${t}" is missing required fields (label or value)`);e.color||(e.color=ge[n%ge.length])}))})),f(""),e}catch(t){return f(t.message),null}})(t);n&&e(n)},placeholder:'{\n "Dataset 1": [\n {\n "label": "Label 1",\n "value": 100,\n "color": "red"\n },\n {\n "label": "Label 2",\n "value": 200\n }\n ],\n "Dataset 2": [\n {\n "label": "Label 3",\n "value": 300,\n "color": "green"\n }\n ]\n}'}),"csv_upload"===n&&(0,A.jsx)(a.MediaUploadCheck,{children:(0,A.jsx)(a.MediaUpload,{onSelect:t=>{const n=t.url;fetch(t.url).then((t=>t.text())).then((t=>{const r=p(t,n);r&&e(r)})).catch((t=>{f("Error reading CSV file: "+t.message)}))},allowedTypes:["text/csv"],render:({open:e})=>(0,A.jsxs)("div",{children:[(0,A.jsx)(s.Button,{onClick:e,isPrimary:!0,children:(0,o.__)("Upload CSV File","lcp")}),t&&Object.keys(t).length>0&&t[Object.keys(t)[0]]?.[0]?.sourceUrl&&(0,A.jsxs)("div",{className:"current-file",style:{marginTop:"10px"},children:[(0,o.__)("Current file:","lcp")," ",t[Object.keys(t)[0]][0].sourceUrl.split("/").pop()]})]})})}),"csv_url"===n&&(0,A.jsx)(s.TextControl,{label:(0,o.__)("CSV URL","lcp"),value:i,onChange:t=>{c(t),t&&fetch(t).then((t=>t.text())).then((n=>{const r=p(n,t);r&&e(r)})).catch((t=>{f("Error fetching CSV file: "+t.message)}))},help:(0,o.__)("Enter URL of a CSV file with label and value columns. Color column is optional.","lcp")}),d&&(0,A.jsx)("div",{className:"lcp-data-selector-error",style:{color:"red",marginTop:"10px"},children:d}),t&&Object.keys(t).length>0&&(0,A.jsxs)("div",{className:"data-preview",style:{marginTop:"15px"},children:[(0,A.jsx)("h4",{children:(0,o.__)("Current Data Preview:","lcp")}),(0,A.jsx)("div",{style:{fontSize:"12px",color:"#666"},children:Object.entries(t).map((([t,e])=>(0,A.jsxs)("div",{children:[t,": ",e.length," ",(0,o.__)("data points","lcp")]},t)))})]})]})};function ve(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n=i)&&(n=i)}return n}function me(t){return t}var ye=1e-6;function be(t){return"translate("+t+",0)"}function we(t){return"translate(0,"+t+")"}function xe(t){return e=>+t(e)}function _e(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function Ce(){return!this.__axis}function Se(t,e){var n=[],r=null,i=null,o=6,a=6,s=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,c=1===t||4===t?-1:1,u=4===t||2===t?"x":"y",h=1===t||3===t?be:we;function d(d){var f=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,g=null==i?e.tickFormat?e.tickFormat.apply(e,n):me:i,p=Math.max(o,0)+s,v=e.range(),m=+v[0]+l,y=+v[v.length-1]+l,b=(e.bandwidth?_e:xe)(e.copy(),l),w=d.selection?d.selection():d,x=w.selectAll(".domain").data([null]),_=w.selectAll(".tick").data(f,e).order(),C=_.exit(),S=_.enter().append("g").attr("class","tick"),O=_.select("line"),D=_.select("text");x=x.merge(x.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),_=_.merge(S),O=O.merge(S.append("line").attr("stroke","currentColor").attr(u+"2",c*o)),D=D.merge(S.append("text").attr("fill","currentColor").attr(u,c*p).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),d!==w&&(x=x.transition(d),_=_.transition(d),O=O.transition(d),D=D.transition(d),C=C.transition(d).attr("opacity",ye).attr("transform",(function(t){return isFinite(t=b(t))?h(t+l):this.getAttribute("transform")})),S.attr("opacity",ye).attr("transform",(function(t){var e=this.parentNode.__axis;return h((e&&isFinite(e=e(t))?e:b(t))+l)}))),C.remove(),x.attr("d",4===t||2===t?a?"M"+c*a+","+m+"H"+l+"V"+y+"H"+c*a:"M"+l+","+m+"V"+y:a?"M"+m+","+c*a+"V"+l+"H"+y+"V"+c*a:"M"+m+","+l+"H"+y),_.attr("opacity",1).attr("transform",(function(t){return h(b(t)+l)})),O.attr(u+"2",c*o),D.attr(u,c*p).text(g),w.filter(Ce).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),w.each((function(){this.__axis=b}))}return d.scale=function(t){return arguments.length?(e=t,d):e},d.ticks=function(){return n=Array.from(arguments),d},d.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),d):n.slice()},d.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),d):r&&r.slice()},d.tickFormat=function(t){return arguments.length?(i=t,d):i},d.tickSize=function(t){return arguments.length?(o=a=+t,d):o},d.tickSizeInner=function(t){return arguments.length?(o=+t,d):o},d.tickSizeOuter=function(t){return arguments.length?(a=+t,d):a},d.tickPadding=function(t){return arguments.length?(s=+t,d):s},d.offset=function(t){return arguments.length?(l=+t,d):l},d}function Oe(t){return Se(3,t)}function De(t){return Se(4,t)}function Te(){}function Ie(t){return null==t?Te:function(){return this.querySelector(t)}}function Ee(){return[]}function ke(t){return null==t?Ee:function(){return this.querySelectorAll(t)}}function Ne(t){return function(){return this.matches(t)}}function je(t){return function(e){return e.matches(t)}}var Me=Array.prototype.find;function Pe(){return this.firstElementChild}var Ae=Array.prototype.filter;function Re(){return Array.from(this.children)}function Le(t){return new Array(t.length)}function $e(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function He(t,e,n,r,i,o){for(var a,s=0,l=e.length,c=o.length;se?1:t>=e?0:NaN}$e.prototype={constructor:$e,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Ge="http://www.w3.org/1999/xhtml";const Xe={svg:"http://www.w3.org/2000/svg",xhtml:Ge,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function qe(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),Xe.hasOwnProperty(e)?{space:Xe[e],local:t}:t}function Ye(t){return function(){this.removeAttribute(t)}}function We(t){return function(){this.removeAttributeNS(t.space,t.local)}}function ze(t,e){return function(){this.setAttribute(t,e)}}function Ke(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Je(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Ze(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Qe(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function tn(t){return function(){this.style.removeProperty(t)}}function en(t,e,n){return function(){this.style.setProperty(t,e,n)}}function nn(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function rn(t,e){return t.style.getPropertyValue(e)||Qe(t).getComputedStyle(t,null).getPropertyValue(e)}function on(t){return function(){delete this[t]}}function an(t,e){return function(){this[t]=e}}function sn(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function ln(t){return t.trim().split(/^|\s+/)}function cn(t){return t.classList||new un(t)}function un(t){this._node=t,this._names=ln(t.getAttribute("class")||"")}function hn(t,e){for(var n=cn(t),r=-1,i=e.length;++r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Ln=[null];function $n(t,e){this._groups=t,this._parents=e}function Hn(){return new $n([[document.documentElement]],Ln)}$n.prototype=Hn.prototype={constructor:$n,select:function(t){"function"!=typeof t&&(t=Ie(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=w+1);!(b=m[x])&&++x=0;)(r=i[o])&&(a&&4^r.compareDocumentPosition(a)&&a.parentNode.insertBefore(r,a),a=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Ve);for(var n=this._groups,r=n.length,i=new Array(r),o=0;o1?this.each((null==e?tn:"function"==typeof e?nn:en)(t,e,null==n?"":n)):rn(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?on:"function"==typeof e?sn:an)(t,e)):this.node()[t]},classed:function(t,e){var n=ln(t+"");if(arguments.length<2){for(var r=cn(this.node()),i=-1,o=n.length;++i=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}(t+""),a=o.length;if(!(arguments.length<2)){for(s=e?Mn:jn,r=0;r{}};function Fn(){for(var t,e=0,n=arguments.length,r={};e=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))),a=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++a0)for(var n,r,i=new Array(n),o=0;o=0&&e._call.call(void 0,t),e=e._next;--zn}()}finally{zn=0,function(){for(var t,e,n=Yn,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Yn=e);Wn=t,cr(r)}(),Qn=0}}function lr(){var t=er.now(),e=t-Zn;e>1e3&&(tr-=e,Zn=t)}function cr(t){zn||(Kn&&(Kn=clearTimeout(Kn)),t-Qn>24?(t<1/0&&(Kn=setTimeout(sr,t-er.now()-tr)),Jn&&(Jn=clearInterval(Jn))):(Jn||(Zn=er.now(),Jn=setInterval(lr,1e3)),zn=1,nr(sr)))}function ur(t,e,n){var r=new or;return e=null==e?0:+e,r.restart((n=>{r.stop(),t(n+e)}),e,n),r}or.prototype=ar.prototype={constructor:or,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?rr():+n)+(null==e?0:+e),this._next||Wn===this||(Wn?Wn._next=this:Yn=this,Wn=this),this._call=t,this._time=n,cr()},stop:function(){this._call&&(this._call=null,this._time=1/0,cr())}};var hr=qn("start","end","cancel","interrupt"),dr=[];function fr(t,e,n,r,i,o){var a=t.__transition;if(a){if(n in a)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function o(l){var c,u,h,d;if(1!==n.state)return s();for(c in i)if((d=i[c]).name===n.name){if(3===d.state)return ur(o);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete i[c]):+c0)throw new Error("too late; already scheduled");return n}function pr(t,e){var n=vr(t,e);if(n.state>3)throw new Error("too late; already running");return n}function vr(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function mr(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var yr,br=180/Math.PI,wr={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function xr(t,e,n,r,i,o){var a,s,l;return(a=Math.sqrt(t*t+e*e))&&(t/=a,e/=a),(l=t*n+e*r)&&(n-=t*l,r-=e*l),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,l/=s),t*r180?e+=360:e-t>180&&(t+=360),o.push({i:n.push(i(n)+"rotate(",null,r)-2,x:mr(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(o.rotate,a.rotate,s,l),function(t,e,n,o){t!==e?o.push({i:n.push(i(n)+"skewX(",null,r)-2,x:mr(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(o.skewX,a.skewX,s,l),function(t,e,n,r,o,a){if(t!==n||e!==r){var s=o.push(i(o)+"scale(",null,",",null,")");a.push({i:s-4,x:mr(t,n)},{i:s-2,x:mr(e,r)})}else 1===n&&1===r||o.push(i(o)+"scale("+n+","+r+")")}(o.scaleX,o.scaleY,a.scaleX,a.scaleY,s,l),o=a=null,function(t){for(var e,n=-1,r=l.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Wr(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Wr(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Lr.exec(t))?new Kr(e[1],e[2],e[3],1):(e=$r.exec(t))?new Kr(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Hr.exec(t))?Wr(e[1],e[2],e[3],e[4]):(e=Br.exec(t))?Wr(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ur.exec(t))?ni(e[1],e[2]/100,e[3]/100,1):(e=Fr.exec(t))?ni(e[1],e[2]/100,e[3]/100,e[4]):Vr.hasOwnProperty(t)?Yr(Vr[t]):"transparent"===t?new Kr(NaN,NaN,NaN,0):null}function Yr(t){return new Kr(t>>16&255,t>>8&255,255&t,1)}function Wr(t,e,n,r){return r<=0&&(t=e=n=NaN),new Kr(t,e,n,r)}function zr(t,e,n,r){return 1===arguments.length?((i=t)instanceof kr||(i=qr(i)),i?new Kr((i=i.rgb()).r,i.g,i.b,i.opacity):new Kr):new Kr(t,e,n,null==r?1:r);var i}function Kr(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function Jr(){return`#${ei(this.r)}${ei(this.g)}${ei(this.b)}`}function Zr(){const t=Qr(this.opacity);return`${1===t?"rgb(":"rgba("}${ti(this.r)}, ${ti(this.g)}, ${ti(this.b)}${1===t?")":`, ${t})`}`}function Qr(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ti(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function ei(t){return((t=ti(t))<16?"0":"")+t.toString(16)}function ni(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new ii(t,e,n,r)}function ri(t){if(t instanceof ii)return new ii(t.h,t.s,t.l,t.opacity);if(t instanceof kr||(t=qr(t)),!t)return new ii;if(t instanceof ii)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),o=Math.max(e,n,r),a=NaN,s=o-i,l=(o+i)/2;return s?(a=e===o?(n-r)/s+6*(n0&&l<1?0:a,new ii(a,s,l,t.opacity)}function ii(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function oi(t){return(t=(t||0)%360)<0?t+360:t}function ai(t){return Math.max(0,Math.min(1,t||0))}function si(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function li(t,e,n,r,i){var o=t*t,a=o*t;return((1-3*t+3*o-a)*e+(4-6*o+3*a)*n+(1+3*t+3*o-3*a)*r+a*i)/6}Ir(kr,qr,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Gr,formatHex:Gr,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ri(this).formatHsl()},formatRgb:Xr,toString:Xr}),Ir(Kr,zr,Er(kr,{brighter(t){return t=null==t?jr:Math.pow(jr,t),new Kr(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Nr:Math.pow(Nr,t),new Kr(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Kr(ti(this.r),ti(this.g),ti(this.b),Qr(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Jr,formatHex:Jr,formatHex8:function(){return`#${ei(this.r)}${ei(this.g)}${ei(this.b)}${ei(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Zr,toString:Zr})),Ir(ii,(function(t,e,n,r){return 1===arguments.length?ri(t):new ii(t,e,n,null==r?1:r)}),Er(kr,{brighter(t){return t=null==t?jr:Math.pow(jr,t),new ii(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Nr:Math.pow(Nr,t),new ii(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new Kr(si(t>=240?t-240:t+120,i,r),si(t,i,r),si(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new ii(oi(this.h),ai(this.s),ai(this.l),Qr(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Qr(this.opacity);return`${1===t?"hsl(":"hsla("}${oi(this.h)}, ${100*ai(this.s)}%, ${100*ai(this.l)}%${1===t?")":`, ${t})`}`}}));const ci=t=>()=>t;function ui(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):ci(isNaN(t)?e:t)}const hi=function t(e){var n=function(t){return 1==(t=+t)?ui:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):ci(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=zr(t)).r,(e=zr(e)).r),i=n(t.g,e.g),o=n(t.b,e.b),a=ui(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=o(e),t.opacity=a(e),t+""}}return r.gamma=t,r}(1);function di(t){return function(e){var n,r,i=e.length,o=new Array(i),a=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],o=t[r+1],a=r>0?t[r-1]:2*i-o,s=ro&&(i=e.slice(o,i),s[a]?s[a]+=i:s[++a]=i),(n=n[0])===(r=r[0])?s[a]?s[a]+=r:s[++a]=r:(s[++a]=null,l.push({i:a,x:mr(n,r)})),o=gi.lastIndex;return o=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?gr:pr;return function(){var a=o(this,t),s=a.on;s!==r&&(i=(r=s).copy()).on(e,n),a.on=i}}(n,t,e))},attr:function(t,e){var n=qe(t),r="transform"===n?Sr:vi;return this.attrTween(t,"function"==typeof e?(n.local?_i:xi)(n,r,Tr(this,"attr."+t,e)):null==e?(n.local?yi:mi)(n):(n.local?wi:bi)(n,r,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var r=qe(t);return this.tween(n,(r.local?Ci:Si)(r,e))},style:function(t,e,n){var r="transform"==(t+="")?Cr:vi;return null==e?this.styleTween(t,function(t,e){var n,r,i;return function(){var o=rn(this,t),a=(this.style.removeProperty(t),rn(this,t));return o===a?null:o===n&&a===r?i:i=e(n=o,r=a)}}(t,r)).on("end.style."+t,ki(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var r,i,o;return function(){var a=rn(this,t),s=n(this),l=s+"";return null==s&&(this.style.removeProperty(t),l=s=rn(this,t)),a===l?null:a===r&&l===i?o:(i=l,o=e(r=a,s))}}(t,r,Tr(this,"style."+t,e))).each(function(t,e){var n,r,i,o,a="style."+e,s="end."+a;return function(){var l=pr(this,t),c=l.on,u=null==l.value[a]?o||(o=ki(e)):void 0;c===n&&i===u||(r=(n=c).copy()).on(s,i=u),l.on=r}}(this._id,t)):this.styleTween(t,function(t,e,n){var r,i,o=n+"";return function(){var a=rn(this,t);return a===o?null:a===r?i:i=e(r=a,n)}}(t,r,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==e)return this.tween(r,null);if("function"!=typeof e)throw new Error;return this.tween(r,function(t,e,n){var r,i;function o(){var o=e.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}(t,o,n)),r}return o._value=e,o}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(Tr(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&function(t){return function(e){this.textContent=t.call(this,e)}}(r)),e}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var r,i=vr(this.node(),n).tween,o=0,a=i.length;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete o[i]):a=!1;a&&delete t.__transition}}(this,t)}))},Bn.prototype.transition=function(t){var e,n;t instanceof ji?(e=t._id,t=t._name):(e=Mi(),(n=Ai).time=rr(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,o=0;o=Wi?10:o>=zi?5:o>=Ki?2:1;let s,l,c;return i<0?(c=Math.pow(10,-i)/a,s=Math.round(t*c),l=Math.round(e*c),s/ce&&--l,c=-c):(c=Math.pow(10,i)*a,s=Math.round(t/c),l=Math.round(e/c),s*ce&&--l),le?1:t>=e?0:NaN}function to(t,e){return null==t||null==e?NaN:et?1:e>=t?0:NaN}function eo(t){let e,n,r;function i(t,r,i=0,o=t.length){if(i>>1;n(t[e],r)<0?i=e+1:o=e}while(iQi(t(e),n),r=(e,n)=>t(e)-n):(e=t===Qi||t===to?t:no,n=t,r=t),{left:i,center:function(t,e,n=0,o=t.length){const a=i(t,e,n,o-1);return a>n&&r(t[a-1],e)>-r(t[a],e)?a-1:a},right:function(t,r,i=0,o=t.length){if(i>>1;n(t[e],r)<=0?i=e+1:o=e}while(i=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function xo(t){if(!(e=wo.exec(t)))throw new Error("invalid format: "+t);var e;return new _o({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function _o(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Co(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function So(t){return(t=Co(Math.abs(t)))?t[1]:NaN}function Oo(t,e){var n=Co(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}xo.prototype=_o.prototype,_o.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const Do={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Oo(100*t,e),r:Oo,s:function(t,e){var n=Co(t,e);if(!n)return t+"";var r=n[0],i=n[1],o=i-(bo=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,a=r.length;return o===a?r:o>a?r+new Array(o-a+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+Co(t,Math.max(0,e+o-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function To(t){return t}var Io,Eo,ko,No=Array.prototype.map,jo=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Mo(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)==(e=+e))return[t];const r=e=i))return[];const s=o-i+1,l=new Array(s);if(r)if(a<0)for(let t=0;t0;){if((i=Zi(l,c,n))===r)return o[a]=l,o[s]=c,e(o);if(i>0)l=Math.floor(l/i)*i,c=Math.ceil(c/i)*i;else{if(!(i<0))break;l=Math.ceil(l*i)/i,c=Math.floor(c*i)/i}r=i}return t},t}function Po(){var t=function(){var t,e,n,r,i,o,a=go,s=go,l=uo,c=po;function u(){var t,e,n,l=Math.min(a.length,s.length);return c!==po&&(t=a[0],e=a[l-1],t>e&&(n=t,t=e,e=n),c=function(n){return Math.max(t,Math.min(e,n))}),r=l>2?yo:mo,i=o=null,h}function h(e){return null==e||isNaN(e=+e)?n:(i||(i=r(a.map(t),s,l)))(t(c(e)))}return h.invert=function(n){return c(e((o||(o=r(s,a.map(t),mr)))(n)))},h.domain=function(t){return arguments.length?(a=Array.from(t,fo),u()):a.slice()},h.range=function(t){return arguments.length?(s=Array.from(t),u()):s.slice()},h.rangeRound=function(t){return s=Array.from(t),l=ho,u()},h.clamp=function(t){return arguments.length?(c=!!t||po,u()):c!==po},h.interpolate=function(t){return arguments.length?(l=t,u()):l},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,r){return t=n,e=r,u()}}()(po,po);return t.copy=function(){return e=t,Po().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Ui.apply(t,arguments),Mo(t)}function Ao(t){return"string"==typeof t?new $n([[document.querySelector(t)]],[document.documentElement]):new $n([[t]],Ln)}function Ro(t,e,n){this.k=t,this.x=e,this.y=n}Io=function(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?To:(e=No.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,o=[],a=0,s=e[0],l=0;i>0&&s>0&&(l+s+1>r&&(s=Math.max(1,r-l)),o.push(t.substring(i-=s,i+s)),!((l+=s+1)>r));)s=e[a=(a+1)%e.length];return o.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",o=void 0===t.currency?"":t.currency[1]+"",a=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?To:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(No.call(t.numerals,String)),l=void 0===t.percent?"%":t.percent+"",c=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=xo(t)).fill,n=t.align,h=t.sign,d=t.symbol,f=t.zero,g=t.width,p=t.comma,v=t.precision,m=t.trim,y=t.type;"n"===y?(p=!0,y="g"):Do[y]||(void 0===v&&(v=12),m=!0,y="g"),(f||"0"===e&&"="===n)&&(f=!0,e="0",n="=");var b="$"===d?i:"#"===d&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",w="$"===d?o:/[%p]/.test(y)?l:"",x=Do[y],_=/[defgprs%]/.test(y);function C(t){var i,o,l,d=b,C=w;if("c"===y)C=x(t)+C,t="";else{var S=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:x(Math.abs(t),v),m&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),S&&0==+t&&"+"!==h&&(S=!1),d=(S?"("===h?h:c:"-"===h||"("===h?"":h)+d,C=("s"===y?jo[8+bo/3]:"")+C+(S&&"("===h?")":""),_)for(i=-1,o=t.length;++i(l=t.charCodeAt(i))||l>57){C=(46===l?a+t.slice(i+1):t.slice(i))+C,t=t.slice(0,i);break}}p&&!f&&(t=r(t,1/0));var O=d.length+t.length+C.length,D=O>1)+d+t+C+D.slice(O);break;default:t=D+d+t+C}return s(t)}return v=void 0===v?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,v)):Math.max(0,Math.min(20,v)),C.toString=function(){return t+""},C}return{format:h,formatPrefix:function(t,e){var n=h(((t=xo(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(So(e)/3))),i=Math.pow(10,-r),o=jo[8+r/3];return function(t){return n(i*t)+o}}}}({thousands:",",grouping:[3],currency:["$",""]}),Eo=Io.format,ko=Io.formatPrefix,Ro.prototype={constructor:Ro,scale:function(t){return 1===t?this:new Ro(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Ro(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}},new Ro(1,0,0),Ro.prototype;const Lo=({data:t,width:e="100%",height:n="400px",backgroundColor:r,title:i,showGridX:o,showGridY:a,xGridColor:s,yGridColor:c,xGridWidth:u,yGridWidth:h,showBarValues:d,xAxisLabel:f,yAxisLabel:g,colorSource:p,defaultBarColor:v,customColors:m,barOpacity:y,enableHierarchicalView:b,enableStackedBars:w,selectedParentId:x,setAttributes:_})=>{const C=(0,l.useRef)(),S=(0,l.useRef)(),O=(t,e)=>{const n=qr(t).rgb();return zr(Math.max(0,n.r-e),Math.max(0,n.g-e),Math.max(0,n.b-e)).toString()};return(0,l.useEffect)((()=>{if(!t||!C.current||!S.current)return;Ao(C.current).selectAll("*").remove();let e=t;b&&!w&&(e={},Object.entries(t).forEach((([t,n])=>{const r=n.filter((t=>t.parent===x));r.length>0&&(e[t]=r)})));const l=[];Object.entries(e).forEach((([e,n])=>{n.forEach((n=>{if(!w||null===n.parent){const r=n.color||v,i=(e=>{const n=[];return Object.entries(t).forEach((([t,r])=>{r.forEach((r=>{r.parent===e&&n.push({...r,dataset:t,color:r.color||v})}))})),n})(n.id),o={id:n.id,dataset:e,label:n.label||"",value:parseFloat(n.value)||0,color:r,hasChildren:i.length>0,children:[]};if(w&&i.length>0){let t=new Set([r]);i.forEach(((e,n)=>{let i=e.color||r;for(;t.has(i);)i=O(i,30);t.add(i),o.children.push({id:e.id,label:e.label,value:parseFloat(e.value)||0,color:i})}))}l.push(o)}}))}));const D=S.current.clientWidth,T="number"==typeof n?n:400,I={top:i?40:20,right:20,bottom:f?50:30,left:g?60:40},E=Math.max(D-I.left-I.right,0),k=Math.max(T-I.top-I.bottom,0),N=Ao(C.current).attr("width",D).attr("height",T).style("background-color",r);i&&N.append("text").attr("x",D/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").text(i);const j=N.append("g").attr("transform",`translate(${I.left},${I.top})`),M=Yi().domain(l.map((t=>t.label))).range([0,E]).padding(.1),P=Po().domain([0,ve(l,(t=>w?t.value+t.children.reduce(((t,e)=>t+e.value),0):t.value))||100]).range([k,0]);o&&j.append("g").attr("class","grid x-grid").attr("transform",`translate(0,${k})`).style("color",s).style("stroke-width",u).call(Oe(M).tickSize(-k).tickFormat("")),a&&j.append("g").attr("class","grid y-grid").style("color",c).style("stroke-width",h).call(De(P).tickSize(-E).tickFormat(""));const A=j.selectAll(".bar-group").data(l).enter().append("g").attr("class","bar-group").attr("transform",(t=>`translate(${M(t.label)},0)`));A.append("rect").attr("class","main-bar").attr("y",(t=>P(t.value))).attr("width",M.bandwidth()).attr("height",(t=>k-P(t.value))).attr("fill",(t=>(t=>{switch(p){case"singleColor":return v;case"customColors":const e=m?.find((e=>e.dataset===t.dataset&&e.label===t.label));return e?e.color:t.color;default:return t.color}})(t))).style("opacity",y).style("cursor",(t=>t.hasChildren&&!w?"pointer":"default")),w&&A.each((function(t){let e=t.value;t.children.forEach((t=>{Ao(this).append("rect").attr("class","child-bar").attr("y",(()=>P(e+t.value))).attr("width",M.bandwidth()).attr("height",(()=>k-P(t.value))).attr("fill",t.color).style("opacity",y),e+=t.value}))})),b&&!w&&(A.selectAll(".main-bar").on("click",(function(t,e){e.hasChildren&&_&&_({selectedParentId:e.id})})),null!==x&&N.append("text").attr("x",I.left).attr("y",I.top/2).attr("class","back-button").style("cursor","pointer").style("font-weight","bold").text("← Back").on("click",(function(){if(_){let e=null;Object.values(t).forEach((t=>{const n=t.find((t=>t.id===x));n&&(e=n.parent)})),_({selectedParentId:e})}}))),d&&A.each((function(t){if(Ao(this).append("text").attr("class","bar-value").attr("x",M.bandwidth()/2).attr("y",P(t.value)-5).attr("text-anchor","middle").text(t.value),w){let e=t.value;t.children.forEach((t=>{Ao(this).append("text").attr("class","bar-value").attr("x",M.bandwidth()/2).attr("y",P(e+t.value)-5).attr("text-anchor","middle").text(t.value),e+=t.value}))}})),j.append("g").attr("transform",`translate(0,${k})`).call(Oe(M)).selectAll("text").style("text-anchor","end").attr("dx","-.8em").attr("dy",".15em").attr("transform","rotate(-45)"),j.append("g").call(De(P)),f&&j.append("text").attr("class","x-axis-label").attr("x",E/2).attr("y",k+40).attr("text-anchor","middle").style("font-size","12px").text(f),g&&j.append("text").attr("class","y-axis-label").attr("transform","rotate(-90)").attr("x",-k/2).attr("y",-45).attr("text-anchor","middle").style("font-size","12px").text(g)}),[t,e,n,i,o,a,s,c,u,h,d,f,g,p,v,m,y,b,w,x]),(0,A.jsx)("div",{ref:S,className:"bar-graph",style:{width:e,height:n,backgroundColor:r,position:"relative"},children:(0,A.jsx)("svg",{ref:C})})},$o=({label:t,value:e,onChange:n})=>{const{number:r,unit:i}=(t=>{const e=t?.match(/^(\d+)(.*)$/);return e?{number:parseInt(e[1],10),unit:e[2]||"px"}:{number:300,unit:"px"}})(e);return(0,A.jsxs)("div",{className:"lcp-dimension-control",children:[(0,A.jsx)("label",{className:"components-base-control__label",children:t}),(0,A.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start"},children:[(0,A.jsx)(s.TextControl,{type:"number",value:r,onChange:t=>{n(`${t}${i}`)},min:0,style:{width:"80px"}}),(0,A.jsx)(s.SelectControl,{value:i,options:[{label:"Pixels (px)",value:"px"},{label:"Percentage (%)",value:"%"},{label:"Viewport Width (vw)",value:"vw"},{label:"Viewport Height (vh)",value:"vh"}],onChange:t=>{n(`${r}${t}`)},style:{minWidth:"100px"}})]})]})},Ho=({data:t,colorSource:e,singleColor:n,customColors:r,onColorSourceChange:i,onSingleColorChange:a,onCustomColorChange:c})=>{const[u,h]=(0,l.useState)(null),d=(t,e)=>{const n=r.find((n=>n.dataset===t&&n.label===e));return n?n.color:"#FF6384"};return(0,A.jsxs)("div",{className:"lcp-color-controls",children:[(0,A.jsx)(s.SelectControl,{label:(0,o.__)("Color Source","lcp"),value:e,options:[{label:(0,o.__)("Default Colors","lcp"),value:"default"},{label:(0,o.__)("Single Color","lcp"),value:"singleColor"},{label:(0,o.__)("Custom Colors","lcp"),value:"customColors"}],onChange:i}),"singleColor"===e&&(0,A.jsxs)("div",{className:"components-base-control",children:[(0,A.jsx)("label",{className:"components-base-control__label",children:(0,o.__)("Bar Color","lcp")}),(0,A.jsx)(s.ColorPicker,{color:n,onChangeComplete:t=>a(t.hex)})]}),"customColors"===e&&(0,A.jsx)("div",{className:"custom-colors-grid",style:{marginTop:"10px"},children:(()=>{const e=[];return Object.entries(t).forEach((([t,n])=>{n.forEach((n=>{e.push({dataset:t,label:n.label,value:n.value})}))})),e})().map(((t,e)=>(0,A.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"8px",gap:"8px"},children:[(0,A.jsx)("span",{style:{flex:1},children:t.label}),(0,A.jsx)(s.Button,{onClick:()=>h(e),style:{backgroundColor:d(t.dataset,t.label),width:"24px",height:"24px",borderRadius:"50%",padding:0,border:"1px solid #ddd"}}),u===e&&(0,A.jsx)(s.Popover,{onClose:()=>h(null),children:(0,A.jsx)("div",{style:{padding:"12px"},children:(0,A.jsx)(s.ColorPicker,{color:d(t.dataset,t.label),onChangeComplete:e=>{c(t.dataset,t.label,e.hex)}})})})]},`${t.dataset}-${t.label}`)))})]})},Bo=JSON.parse('{"UU":"lcp/bar-graph"}');(0,i.registerBlockType)(Bo.UU,{edit:function({attributes:t,setAttributes:e}){const{chartHeight:n,chartWidth:r,barColor:i,barOpacity:c,backgroundColor:u,showGridY:h,yGridColor:d,xGridColor:f,xGridWidth:g,yGridWidth:p,chartData:v,dataSource:m,displayChartTitle:y,chartTitle:b,allowDownload:w,downloadMaxWidth:x,showSorting:_,showFiltering:C,showBarValues:S,showGridX:O,xAxisLabel:D,yAxisLabel:T,chartColorSource:I,chartCustomColors:E,enableHierarchicalView:k,enableStackedBars:N,selectedParentId:j}=t,M=(0,a.useBlockProps)(),P=t=>{console.log("New data:",t),e({chartData:t})},R=t=>{e({dataSource:t,chartData:{}})},L=(t,n,r)=>{const i=[...E],o=i.findIndex((e=>e.dataset===t&&e.label===n));o>=0?i[o].color=r:i.push({dataset:t,label:n,color:r}),e({chartCustomColors:i})},[$,H]=(0,l.useState)(!1),[B,U]=(0,l.useState)(!1),F=()=>{H(!$)},V=()=>{U(!B)},[G,X]=(0,l.useState)(!1),q=()=>{X(!G)};return console.log("Chart data:",v),t.chartData&&"object"==typeof t.chartData||e({chartData:{}}),(0,A.jsxs)("div",{...M,children:[(0,A.jsx)(a.InspectorControls,{children:(0,A.jsx)(s.TabPanel,{className:"lcp-tab-panel",activeClass:"active-tab",tabs:[{name:"data",title:(0,o.__)("Data Settings","lcp"),className:"tab-data"},{name:"appearance",title:(0,o.__)("Appearance","lcp"),className:"tab-appearance"},{name:"tools",title:(0,o.__)("Tools Settings","lcp"),className:"tab-tools"}],children:t=>"data"===t.name?(0,A.jsxs)(s.Panel,{children:[(0,A.jsx)(s.PanelBody,{title:"Data Settings",children:(0,A.jsx)(pe,{value:v,onChange:P,dataSource:m,onDataSourceChange:R})}),(0,A.jsxs)(s.PanelBody,{title:(0,o.__)("Chart Settings","lcp"),initialOpen:!0,children:[(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Enable Hierarchical View","lcp"),checked:k,onChange:t=>e({enableHierarchicalView:t})}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Enable Stacked Bars","lcp"),checked:N,onChange:t=>e({enableStackedBars:t})}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Display Chart Title","lcp"),checked:y,onChange:t=>e({displayChartTitle:t})}),y&&(0,A.jsx)(s.TextControl,{label:(0,o.__)("Chart Title","lcp"),value:b,onChange:t=>e({chartTitle:t})}),(0,A.jsx)($o,{label:(0,o.__)("Chart Width","lcp"),value:r,onChange:t=>e({chartWidth:t})}),(0,A.jsx)($o,{label:(0,o.__)("Chart Height","lcp"),value:n,onChange:t=>e({chartHeight:t})})]}),(0,A.jsxs)(s.PanelBody,{title:"Appearance",children:[(0,A.jsxs)("div",{className:"background-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"10px"},children:[(0,A.jsx)("span",{children:"Background Color"}),(0,A.jsx)(s.Button,{className:"background-color-button",onClick:q,style:{backgroundColor:u,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),G&&(0,A.jsx)(s.Popover,{position:"bottom center",onClose:q,children:(0,A.jsx)(s.ColorPicker,{color:u,onChangeComplete:t=>{return n=t.hex,void e({backgroundColor:n});var n}})})]}),(0,A.jsx)(Ho,{data:v,colorSource:I,singleColor:i,customColors:E,onColorSourceChange:t=>e({chartColorSource:t}),onSingleColorChange:t=>e({barColor:t}),onCustomColorChange:L}),(0,A.jsx)(s.RangeControl,{label:(0,o.__)("Bar Opacity","lcp"),value:c,onChange:t=>e({barOpacity:t}),min:0,max:1,step:.1}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Show Bar Values","lcp"),checked:S,onChange:t=>e({showBarValues:t})})]}),(0,A.jsxs)(s.PanelBody,{title:"Grid Settings",children:[(0,A.jsx)(s.TextControl,{label:(0,o.__)("X-Axis Label","lcp"),value:D,onChange:t=>e({xAxisLabel:t})}),(0,A.jsx)(s.TextControl,{label:(0,o.__)("Y-Axis Label","lcp"),value:T,onChange:t=>e({yAxisLabel:t})}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Show X-Axis Grid","lcp"),checked:O,onChange:t=>e({showGridX:t})}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Show Y-Axis Grid","lcp"),checked:h,onChange:t=>e({showGridY:t})}),h&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("div",{className:"y-grid-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"8px"},children:[(0,A.jsx)("span",{children:"Y-Axis Grid Color"}),(0,A.jsx)(s.Button,{className:"grid-color-button",onClick:F,style:{backgroundColor:d,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),$&&(0,A.jsx)(s.Popover,{position:"bottom center",onClose:F,children:(0,A.jsx)(s.ColorPicker,{color:d,onChangeComplete:t=>{return n=t.hex,void e({yGridColor:n});var n}})})]}),(0,A.jsx)(s.RangeControl,{label:(0,o.__)("Y-Axis Grid Width","lcp"),value:p,onChange:t=>e({yGridWidth:t}),min:1,max:5,step:1})]}),O&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("div",{className:"x-grid-color-row",style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"8px"},children:[(0,A.jsx)("span",{children:"X-Axis Grid Color"}),(0,A.jsx)(s.Button,{className:"grid-color-button",onClick:V,style:{backgroundColor:f,width:"26px",height:"26px",borderRadius:"50%",border:"1px solid #ccc"}}),B&&(0,A.jsx)(s.Popover,{position:"bottom center",onClose:V,children:(0,A.jsx)(s.ColorPicker,{color:f,onChangeComplete:t=>{return n=t.hex,void e({xGridColor:n});var n}})})]}),(0,A.jsx)(s.RangeControl,{label:(0,o.__)("X-Axis Grid Width","lcp"),value:g,onChange:t=>e({xGridWidth:t}),min:1,max:5,step:1})]})]})]}):"appearance"===t.name?(0,A.jsx)(s.PanelBody,{}):"tools"===t.name?(0,A.jsxs)(s.PanelBody,{children:[(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Allow Download","lcp"),checked:w,onChange:t=>e({allowDownload:t})}),w&&(0,A.jsx)(s.TextControl,{type:"number",label:(0,o.__)("Max Download Width (px)","lcp"),value:parseInt(x),onChange:t=>e({downloadMaxWidth:`${t}px`}),min:100,max:5e3}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Show Sorting Options","lcp"),checked:_,onChange:t=>e({showSorting:t})}),(0,A.jsx)(s.ToggleControl,{label:(0,o.__)("Show Filtering Options","lcp"),checked:C,onChange:t=>e({showFiltering:t})})]}):void 0})}),w&&(0,A.jsx)("div",{className:"lcp-bar-graph-toolbar",children:(0,A.jsx)(s.Button,{isPrimary:!0,onClick:()=>{const t=document.querySelector(".bar-graph svg");if(!t)return;const e=document.createElement("canvas"),n=(new XMLSerializer).serializeToString(t),r=new Blob([n],{type:"image/svg+xml;charset=utf-8"}),i=window.URL||window.webkitURL||window,o=i.createObjectURL(r),a=new Image;a.onload=()=>{e.width=t.width.baseVal.value,e.height=t.height.baseVal.value;const n=e.getContext("2d");n.fillStyle=u,n.fillRect(0,0,e.width,e.height),n.drawImage(a,0,0),e.toBlob((t=>{const e=URL.createObjectURL(t),n=document.createElement("a");n.href=e,n.download="bar-graph.png",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(e),i.revokeObjectURL(o)}),"image/png")},a.src=o},icon:"download",children:(0,o.__)("Download Graph","lcp")})}),v&&Object.keys(v).length>0?(0,A.jsx)(Lo,{data:v,height:n,width:r,backgroundColor:u,defaultBarColor:i,barOpacity:c,showGridX:O,showGridY:h,yGridColor:d,xGridColor:f,xGridWidth:g,yGridWidth:p,title:y?b:"",showBarValues:S,xAxisLabel:D,yAxisLabel:T,colorSource:I,customColors:E,enableHierarchicalView:k,enableStackedBars:N,selectedParentId:j,setAttributes:e}):(0,A.jsx)("div",{className:"lcp-bar-graph-placeholder",style:{height:n,width:r,backgroundColor:u,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed #ccc",borderRadius:"4px",color:"#666"},children:(0,o.__)("Please add data using the Data Settings panel","lcp")})]})},save:function({attributes:t}){const{chartHeight:e,backgroundColor:n}=t;return(0,A.jsx)("div",{...a.useBlockProps.save(),children:(0,A.jsx)("div",{className:"lcp-bar-graph",style:{height:e,backgroundColor:n}})})}})},792:t=>{t.exports=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var r,i,o;if(Array.isArray(e)){if((r=e.length)!=n.length)return!1;for(i=r;0!=i--;)if(!t(e[i],n[i]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((r=(o=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(i=r;0!=i--;)if(!Object.prototype.hasOwnProperty.call(n,o[i]))return!1;for(i=r;0!=i--;){var a=o[i];if(!t(e[a],n[a]))return!1}return!0}return e!=e&&n!=n}}},n={};function r(t){var i=n[t];if(void 0!==i)return i.exports;var o=n[t]={exports:{}};return e[t](o,o.exports,r),o.exports}r.m=e,t=[],r.O=(e,n,i,o)=>{if(!n){var a=1/0;for(u=0;u=o)&&Object.keys(r.O).every((t=>r.O[t](n[l])))?n.splice(l--,1):(s=!1,o0&&t[u-1][2]>o;u--)t[u]=t[u-1];t[u]=[n,i,o]},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t={57:0,350:0};r.O.j=e=>0===t[e];var e=(e,n)=>{var i,o,[a,s,l]=n,c=0;if(a.some((e=>0!==t[e]))){for(i in s)r.o(s,i)&&(r.m[i]=s[i]);if(l)var u=l(r)}for(e&&e(n);cr(301)));i=r.O(i)})(); \ No newline at end of file diff --git a/components/LCPDataSelector.js b/components/LCPDataSelector.js index ae019eb..8f7aee4 100644 --- a/components/LCPDataSelector.js +++ b/components/LCPDataSelector.js @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n'; import { SelectControl, TextareaControl, Button, TextControl } from '@wordpress/components'; import { useState, useEffect } from '@wordpress/element'; import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; +import LCPDatasetBuilder from './LCPDatasetBuilder'; const DEFAULT_COLORS = [ '#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', @@ -43,6 +44,7 @@ const LCPDataSelector = ({ value, onChange, dataSource, onDataSourceChange }) => { label: __('Manual JSON', 'lcp'), value: 'manual_json' }, { label: __('CSV Upload', 'lcp'), value: 'csv_upload' }, { label: __('CSV URL', 'lcp'), value: 'csv_url' }, + { label: __('Dataset Builder', 'lcp'), value: 'dataset_builder' }, ]; const validateJsonData = (jsonString) => { @@ -170,6 +172,15 @@ const LCPDataSelector = ({ value, onChange, dataSource, onDataSourceChange }) => onChange={onDataSourceChange} /> + {dataSource === 'dataset_builder' && ( + { + onChange(newValue); + }} + /> + )} + {dataSource === 'manual_json' && ( { + const [showColorPicker, setShowColorPicker] = useState(false); + const ref = useRef(null); + + const [{ isDragging }, drag] = useDrag({ + type: ItemTypes.DATASET_ITEM, + item: { id: item.id, datasetKey }, + collect: (monitor) => ({ + isDragging: monitor.isDragging(), + }), + }); + + const [{ isOver }, drop] = useDrop({ + accept: ItemTypes.DATASET_ITEM, + hover(draggedItem, monitor) { + if (!ref.current) return; + if (draggedItem.id === item.id) return; + + const hoverBoundingRect = ref.current.getBoundingClientRect(); + const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2; + const hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2; + const clientOffset = monitor.getClientOffset(); + + if (!clientOffset) return; + + const hoverClientY = clientOffset.y - hoverBoundingRect.top; + const hoverClientX = clientOffset.x - hoverBoundingRect.left; + + // If hovering in the right half and below middle, make it a child + const shouldBeChild = hoverClientX > hoverMiddleX && hoverClientY > hoverMiddleY; + + moveItem(draggedItem.id, item.id, shouldBeChild); + }, + collect: (monitor) => ({ + isOver: monitor.isOver(), + }), + }); + + // Initialize drag and drop refs + drag(drop(ref)); + + // Get child items + const childItems = items.filter(i => i.parent === item.id); + + const style = { + marginLeft: item.parent ? '20px' : '0', + opacity: isDragging ? 0.5 : 1, + cursor: 'move', + background: isOver ? '#f0f0f0' : 'white', + border: isOver ? '2px dashed #0073aa' : '1px solid #e2e4e7', + marginBottom: '8px', + transition: 'all 0.2s ease', + }; + + return ( +
+
+ + +
+ updateItem(datasetKey, item.id, 'label', value)} + style={{ flex: 2 }} + /> + updateItem(datasetKey, item.id, 'value', parseFloat(value))} + style={{ flex: 1 }} + /> +
+
+
+
+
+
+ {/* Render child items */} + {childItems.map(childItem => ( + + ))} +
+ ); +}; + +const LCPDatasetBuilder = ({ value, onChange }) => { + const [isModalOpen, setIsModalOpen] = useState(false); + const [datasets, setDatasets] = useState(value || {}); + + const addNewDataset = () => { + const newDatasetName = `Dataset ${Object.keys(datasets).length + 1}`; + const updatedDatasets = { + ...datasets, + [newDatasetName]: [{ + id: `dataset-${Date.now()}`, + label: newDatasetName, + parent: null, + value: 0, + color: '#000000' + }] + }; + setDatasets(updatedDatasets); + onChange(updatedDatasets); + }; + + const addNewItem = (datasetKey) => { + const newItem = { + id: `item-${Date.now()}`, + label: 'New Item', + parent: null, + value: 0, + color: '#000000' + }; + + const updatedDatasets = { + ...datasets, + [datasetKey]: [...datasets[datasetKey], newItem] + }; + setDatasets(updatedDatasets); + onChange(updatedDatasets); + }; + + const updateItem = (datasetKey, itemId, field, value) => { + const updatedDatasets = { + ...datasets, + [datasetKey]: datasets[datasetKey].map(item => + item.id === itemId ? { ...item, [field]: value } : item + ) + }; + setDatasets(updatedDatasets); + onChange(updatedDatasets); + }; + + const moveItem = (draggedId, targetId, makeChild) => { + const datasetKey = Object.keys(datasets).find(key => + datasets[key].some(item => item.id === draggedId) + ); + + if (!datasetKey) return; + + const items = [...datasets[datasetKey]]; + const draggedItem = items.find(item => item.id === draggedId); + const targetItem = items.find(item => item.id === targetId); + + if (!draggedItem || !targetItem) return; + + // If target is a descendant of dragged item, prevent the move + let current = targetItem; + while (current.parent) { + if (current.parent === draggedId) return; + current = items.find(item => item.id === current.parent); + } + + // Update parent reference + draggedItem.parent = makeChild ? targetId : targetItem.parent; + + const updatedDatasets = { + ...datasets, + [datasetKey]: items + }; + + setDatasets(updatedDatasets); + onChange(updatedDatasets); + }; + + return ( + <> + + + {isModalOpen && ( + setIsModalOpen(false)} + style={{ width: '90vw' }} + > + +
+ {Object.entries(datasets).map(([datasetKey, items]) => ( +
+

{datasetKey}

+
+ {items + .filter(item => !item.parent) // Only render top-level items + .map(item => ( + + )) + } +
+ +
+ ))} + +
+
+
+ )} + + ); +}; + +export default LCPDatasetBuilder; diff --git a/package-lock.json b/package-lock.json index fab9fe2..cf38285 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,5 +2,138 @@ "name": "lcp-data-blocks", "lockfileVersion": 3, "requires": true, - "packages": {} + "packages": { + "": { + "dependencies": { + "react-dnd": "^16.0.1", + "react-dnd-html5-backend": "^16.0.1" + } + }, + "node_modules/@babel/runtime": { + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz", + "integrity": "sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==", + "license": "MIT", + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@react-dnd/asap": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@react-dnd/asap/-/asap-5.0.2.tgz", + "integrity": "sha512-WLyfoHvxhs0V9U+GTsGilGgf2QsPl6ZZ44fnv0/b8T3nQyvzxidxsg/ZltbWssbsRDlYW8UKSQMTGotuTotZ6A==", + "license": "MIT" + }, + "node_modules/@react-dnd/invariant": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@react-dnd/invariant/-/invariant-4.0.2.tgz", + "integrity": "sha512-xKCTqAK/FFauOM9Ta2pswIyT3D8AQlfrYdOi/toTPEhqCuAs1v5tcJ3Y08Izh1cJ5Jchwy9SeAXmMg6zrKs2iw==", + "license": "MIT" + }, + "node_modules/@react-dnd/shallowequal": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@react-dnd/shallowequal/-/shallowequal-4.0.2.tgz", + "integrity": "sha512-/RVXdLvJxLg4QKvMoM5WlwNR9ViO9z8B/qPcc+C0Sa/teJY7QG7kJ441DwzOjMYEY7GmU4dj5EcGHIkKZiQZCA==", + "license": "MIT" + }, + "node_modules/dnd-core": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/dnd-core/-/dnd-core-16.0.1.tgz", + "integrity": "sha512-HK294sl7tbw6F6IeuK16YSBUoorvHpY8RHO+9yFfaJyCDVb6n7PRcezrOEOa2SBCqiYpemh5Jx20ZcjKdFAVng==", + "license": "MIT", + "dependencies": { + "@react-dnd/asap": "^5.0.1", + "@react-dnd/invariant": "^4.0.1", + "redux": "^4.2.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/hoist-non-react-statics": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", + "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", + "license": "BSD-3-Clause", + "dependencies": { + "react-is": "^16.7.0" + } + }, + "node_modules/react": { + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.0.0.tgz", + "integrity": "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dnd": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/react-dnd/-/react-dnd-16.0.1.tgz", + "integrity": "sha512-QeoM/i73HHu2XF9aKksIUuamHPDvRglEwdHL4jsp784BgUuWcg6mzfxT0QDdQz8Wj0qyRKx2eMg8iZtWvU4E2Q==", + "license": "MIT", + "dependencies": { + "@react-dnd/invariant": "^4.0.1", + "@react-dnd/shallowequal": "^4.0.1", + "dnd-core": "^16.0.1", + "fast-deep-equal": "^3.1.3", + "hoist-non-react-statics": "^3.3.2" + }, + "peerDependencies": { + "@types/hoist-non-react-statics": ">= 3.3.1", + "@types/node": ">= 12", + "@types/react": ">= 16", + "react": ">= 16.14" + }, + "peerDependenciesMeta": { + "@types/hoist-non-react-statics": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, + "node_modules/react-dnd-html5-backend": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/react-dnd-html5-backend/-/react-dnd-html5-backend-16.0.1.tgz", + "integrity": "sha512-Wu3dw5aDJmOGw8WjH1I1/yTH+vlXEL4vmjk5p+MHxP8HuHJS1lAGeIdG/hze1AvNeXWo/JgULV87LyQOr+r5jw==", + "license": "MIT", + "dependencies": { + "dnd-core": "^16.0.1" + } + }, + "node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "license": "MIT" + }, + "node_modules/redux": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/redux/-/redux-4.2.1.tgz", + "integrity": "sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.9.2" + } + }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "license": "MIT" + } + } } diff --git a/package.json b/package.json new file mode 100644 index 0000000..dac2a5d --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "react-dnd": "^16.0.1", + "react-dnd-html5-backend": "^16.0.1" + } +}