PluginProbe
M Chart / 2.2.2
M Chart v2.2.2
2.3.2 2.3.1 2.3 2.2.2 2.2.1 2.2 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.10 1.10.1 1.11 1.11.1 1.11.2 1.12 1.2 1.2.1 1.3 1.3.1 1.3.2 All 53 releases
m-chart / components / block / index.js

index.js in M Chart 2.2.2, at components/block/index.js

4 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (()=>{var t={873(t,e,r){var s=r(325).Symbol;t.exports=s},552(t,e,r){var s=r(873),a=r(659),i=r(350),n=s?s.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":n&&n in Object(t)?a(t):i(t)}},128(t,e,r){var s=r(800),a=/^\s+/;t.exports=function(t){return t?t.slice(0,s(t)+1).replace(a,""):t}},840(t){var e="object"==typeof globalThis&&globalThis&&globalThis.Object===Object&&globalThis;t.exports=e},659(t,e,r){var s=r(873),a=Object.prototype,i=a.hasOwnProperty,n=a.toString,c=s?s.toStringTag:void 0;t.exports=function(t){var e=i.call(t,c),r=t[c];try{t[c]=void 0;var s=!0}catch(t){}var a=n.call(t);return s&&(e?t[c]=r:delete t[c]),a}},350(t){var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},325(t,e,r){var s=r(840),a="object"==typeof self&&self&&self.Object===Object&&self,i=s||a||Function("return this")();t.exports=i},800(t){var e=/\s/;t.exports=function(t){for(var r=t.length;r--&&e.test(t.charAt(r)););return r}},221(t,e,r){var s=r(805),a=r(124),i=r(374),n=Math.max,c=Math.min;t.exports=function(t,e,r){var o,l,h,d,u,p,m=0,x=!1,f=!1,v=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function j(e){var r=o,s=l;return o=l=void 0,m=e,d=t.apply(s,r)}function b(t){var r=t-p;return void 0===p||r>=e||r<0||f&&t-m>=h}function g(){var t=a();if(b(t))return w(t);u=setTimeout(g,function(t){var r=e-(t-p);return f?c(r,h-(t-m)):r}(t))}function w(t){return u=void 0,v&&o?j(t):(o=l=void 0,d)}function y(){var t=a(),r=b(t);if(o=arguments,l=this,p=t,r){if(void 0===u)return function(t){return m=t,u=setTimeout(g,e),x?j(t):d}(p);if(f)return clearTimeout(u),u=setTimeout(g,e),j(p)}return void 0===u&&(u=setTimeout(g,e)),d}return e=i(e)||0,s(r)&&(x=!!r.leading,h=(f="maxWait"in r)?n(i(r.maxWait)||0,e):h,v="trailing"in r?!!r.trailing:v),y.cancel=function(){void 0!==u&&clearTimeout(u),m=0,o=p=l=u=void 0},y.flush=function(){return void 0===u?d:w(a())},y}},805(t){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},346(t){t.exports=function(t){return null!=t&&"object"==typeof t}},394(t,e,r){var s=r(552),a=r(346);t.exports=function(t){return"symbol"==typeof t||a(t)&&"[object Symbol]"==s(t)}},124(t,e,r){var s=r(325);t.exports=function(){return s.Date.now()}},374(t,e,r){var s=r(128),a=r(805),i=r(394),n=/^[-+]0x[0-9a-f]+$/i,c=/^0b[01]+$/i,o=/^0o[0-7]+$/i,l=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(i(t))return NaN;if(a(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=a(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=s(t);var r=c.test(t);return r||o.test(t)?l(t.slice(2),r?2:8):n.test(t)?NaN:+t}}},e={};function r(s){var a=e[s];if(void 0!==a)return a.exports;var i=e[s]={exports:{}};return t[s](i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var s in e)r.o(e,s)&&!r.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";const t=window.wp.blocks,e=window.wp.components,s=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"m-chart/chart","title":"M Chart","category":"layout","description":"Embed a chart made with M Chart into your posts and pages","textdomain":"m-chart","attributes":{"chartId":{"type":"integer","default":0},"show":{"type":"string","default":"chart"}},"supports":{"html":false},"editorScript":"m-chart-editor","editorStyle":"m-chart-editor-style","render":"file:./render.php"}'),a=window.wp.element,i=window.wp.blockEditor,n=window.wp.i18n,c=window.wp.htmlEntities,o=window.wp.apiFetch;var l=r.n(o),h=r(221),d=r.n(h);const u=window.ReactJSXRuntime,p=(0,u.jsx)(e.SVG,{viewBox:"0 0 437 370.056",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",focusable:"false",children:(0,u.jsxs)(e.G,{transform:"matrix(1, 0, 0, 1, 38.403999, 55.937004)",children:[(0,u.jsx)(e.Rect,{x:"281.401",y:"148.511",width:"88.71",height:"141.45"}),(0,u.jsx)(e.Rect,{x:"-9.919",y:"264.821",width:"88.71",height:"25.13"}),(0,u.jsx)(e.Rect,{x:"-9.919",y:"-31.779",width:"88.71",height:"284.21"}),(0,u.jsx)(e.Rect,{x:"281.401",y:"-31.779",width:"88.71",height:"167.87"}),(0,u.jsx)(e.Rect,{x:"186.281",y:"194.551",width:"82.79",height:"95.4"}),(0,u.jsx)(e.Rect,{x:"91.081",y:"235.411",width:"82.94",height:"54.55"}),(0,u.jsx)(e.Polygon,{points:"281.401 -31.779 180.101 65.111 180.101 176.701 281.401 79.711 281.401 -31.779"}),(0,u.jsx)(e.Polygon,{points:"78.801 79.711 180.101 176.701 180.101 65.111 78.801 -31.779 78.801 79.711"})]})});(0,t.registerBlockType)(s,{edit:function({attributes:r,setAttributes:s}){const[o,h]=(0,a.useState)([]),[p,m]=(0,a.useState)(""),[x,f]=(0,a.useState)(!1),[v,j]=(0,a.useState)(0),[b,g]=(0,a.useState)(!1),[w,y]=(0,a.useState)(null),[_,N]=(0,a.useState)(null),[S,k]=(0,a.useState)(!1),[T,I]=(0,a.useState)(!1),[C,E]=(0,a.useState)(1),[O,R]=(0,a.useState)(!1),B=(0,a.useRef)(null),P=`${_}/wp-admin/post-new.php?post_type=m-chart`,$=`${_}/wp-admin/post.php?post=${r.chartId}&action=edit`,M=(0,i.useBlockProps)({className:"m-chart-block-chart-selector"}),L=`?cache=${performance.now()}`,F=(0,a.useCallback)((t,e=1)=>{I(!1),e>1&&R(!0);const r=new URLSearchParams;t&&r.set("s",t),e>1&&r.set("page",e);const s=r.toString();l()({path:"/m-chart/v1/charts"+(s?"?"+s:"")}).then(t=>{const r=t.posts.map(t=>({id:t.id,title:(0,c.decodeEntities)(t.title||"-"),subtitle:(0,c.decodeEntities)(t.subtitle||""),width:t.width,height:t.height,type:t.type||"",src:t.url||""}));j(t.found_posts),h(1===e?r:t=>[...t,...r]),g(!0),R(!1)}).catch(t=>{"rest_no_route"===t.code&&I(!0),R(!1)})},[]),G=(0,a.useMemo)(()=>d()(t=>{m(t),E(1),F(t)},500),[F]);(0,a.useEffect)(()=>{l()({path:"/m-chart/v1/options"}).then(t=>{k(t.image_support),N(t.siteurl),f(t.posts_avilable)}),F(p)},[]),(0,a.useEffect)(()=>{var t;y(null),r.chartId&&(t=parseInt(r.chartId,10),l()({path:`/m-chart/v1/chart/${t}`}).then(t=>{y({id:t.id,title:(0,c.decodeEntities)(t.title||"-"),subtitle:(0,c.decodeEntities)(t.subtitle||""),width:t.width,height:t.height,type:t.type||"",src:t.url||""})}).catch(()=>{}))},[r.chartId]),(0,a.useEffect)(()=>{const t=B.current;if(!t)return;const e=()=>{if(!O&&!(o.length>=v)&&t.scrollTop+t.clientHeight>=t.scrollHeight-100){const t=C+1;E(t),F(p,t)}};return t.addEventListener("scroll",e),()=>t.removeEventListener("scroll",e)},[o,v,O,C,p,F,r.chartId]);const A=o.map(t=>{
2 /* translators: %s: the chart's title */
3 const e=(0,n.sprintf)((0,n.__)("Select chart: %s","m-chart"),t.title);return S&&t.src?(0,u.jsx)("li",{className:"item image",children:(0,u.jsxs)("button",{type:"button",className:"select",onClick:()=>D(t.id),"aria-label":e,children:[(0,u.jsx)("h6",{className:"title",children:t.title}),(0,u.jsx)("img",{src:t.src+L,alt:""})]})},t.id):(0,u.jsx)("li",{className:"item no-image",children:(0,u.jsx)("button",{type:"button",className:"select",onClick:()=>D(t.id),"aria-label":e,children:(0,u.jsxs)("div",{className:"type",children:[(0,u.jsx)("span",{className:"icon "+t.type,"aria-hidden":"true"}),(0,u.jsx)("h6",{className:"title",children:t.title})]})})},t.id)}),D=t=>{s({chartId:t}),y(null)};return(0,u.jsxs)("div",{...M,children:[!!r.chartId&&(0,u.jsx)(i.InspectorControls,{children:(0,u.jsx)(e.PanelBody,{title:(0,n.__)("Display settings","m-chart"),children:(0,u.jsx)(e.SelectControl,{label:(0,n.__)("Show","m-chart"),value:r.show,options:[{label:(0,n.__)("Chart","m-chart"),value:"chart"},{label:(0,n.__)("Image","m-chart"),value:"image"},{label:(0,n.__)("Table","m-chart"),value:"table"}],onChange:t=>s({show:t})})})}),(0,u.jsx)(i.BlockControls,{children:(0,u.jsxs)(e.ToolbarGroup,{className:"m-chart-block",children:[!r.chartId&&(0,u.jsx)(e.ToolbarButton,{onClick:()=>window.open(P,"_blank"),icon:"external",children:(0,n.__)("New chart","m-chart")}),!!r.chartId&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(e.ToolbarButton,{onClick:()=>window.open($,"_blank"),icon:"external",children:(0,n.__)("Edit chart","m-chart")}),(0,u.jsx)(e.ToolbarButton,{onClick:()=>D(0),children:(0,n.__)("Replace","m-chart")})]})]})}),r.chartId?(0,u.jsx)("div",{className:"wp-block m-chart-selector",children:w?(0,u.jsx)("div",{className:"chart-selected",children:S&&w.src?(0,u.jsx)("div",{className:"image",children:(0,u.jsx)("img",{className:"preview",src:w.src+L,alt:w.title||""})}):(0,u.jsx)("div",{className:"no-image",style:{aspectRatio:w.width/w.height},children:(0,u.jsxs)("div",{className:"type",children:[(0,u.jsx)("span",{className:"icon "+w.type,"aria-hidden":"true"}),(0,u.jsx)("h5",{className:"title",children:w.title}),w.subtitle&&(0,u.jsx)("h6",{className:"subtitle",children:w.subtitle})]})})}):(0,u.jsx)("p",{className:"center",children:(0,u.jsx)(e.Spinner,{})})}):(0,u.jsx)("div",{className:"wp-block m-chart-selector",children:(0,u.jsx)(e.Placeholder,{className:"block-editor-m-chart-placeholder",icon:(0,t.getBlockType)("m-chart/chart").icon.src,label:(0,n.__)("M Chart","m-chart"),children:(0,u.jsx)("div",{className:"viewbox",children:T?(0,u.jsx)("p",{children:(0,n.__)("There was a problem loading charts","m-chart")}):(0,u.jsxs)(u.Fragment,{children:[!b&&(0,u.jsx)("p",{className:"center",children:(0,u.jsx)(e.Spinner,{})}),b&&!1===x&&(0,u.jsxs)("div",{children:[(0,u.jsxs)("p",{children:[(0,n.__)("No charts found","m-chart"),(0,u.jsx)("br",{})]}),(0,u.jsx)("p",{children:(0,u.jsx)(e.ExternalLink,{href:P,children:(0,n.__)("Create a new chart","m-chart")})})]}),b&&!1!==x&&(0,u.jsxs)("div",{className:"no-chart-selected",children:[(0,u.jsxs)("div",{className:"search-box",children:[(0,u.jsx)(e.SearchControl,{value:p,placeholder:(0,n.__)("Search by title","m-chart"),onChange:t=>(t=>{G(t)})(t)}),(0,u.jsx)("p",{className:"count",role:"status","aria-live":"polite",children:/* translators: %d: number of charts found */ /* translators: %d: number of charts found */
4 (0,n.sprintf)((0,n._n)("%d chart found","%d charts found",v,"m-chart"),v)})]}),0===A.length&&p.length>1?(0,u.jsx)("p",{children:(0,n.__)("No charts found","m-chart")}):(0,u.jsxs)("ul",{ref:B,className:S?"results image-support":"results no-image-support",children:[A,O&&(0,u.jsx)("li",{className:"loading-more",children:(0,u.jsx)(e.Spinner,{})}),!O&&o.length<v&&(0,u.jsx)("li",{className:"load-more",children:(0,u.jsx)(e.Button,{variant:"secondary",size:"compact",onClick:()=>{const t=C+1;E(t),F(p,t)},children:(0,n.__)("Load more results","m-chart")})})]})]})]})})})})]})},save:()=>null,icon:p,deprecated:[{attributes:{chartId:{type:"string",default:""},show:{type:"string",default:"chart"}},save:()=>null,isEligible:t=>"string"==typeof t.chartId,migrate:t=>({...t,chartId:parseInt(t.chartId,10)||0})}]})})()})();