@humanmade/block-editor-components
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,1 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@humanmade/block-editor-components"]=t():e["@humanmade/block-editor-components"]=t()}(self,(()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ConditionalComponent:()=>l,FetchAllTermSelectControl:()=>f,FileControls:()=>b,ImageControl:()=>_,LinkToolbar:()=>E,PlainTextWithLimit:()=>C,PostTitleControl:()=>B,PostTypeCheck:()=>x,RichTextWithLimit:()=>N,createOptionFromPost:()=>G,createOptionFromTerm:()=>Q,createOptionsFromPosts:()=>q,createOptionsFromPostsWithHierarchy:()=>J,createOptionsFromTerms:()=>K,createOptionsFromTermsWithHierarchy:()=>X,findBlockByName:()=>U,findInvalidBlock:()=>$,findInvalidBlocks:()=>W,findValidBlock:()=>z,findValidBlocks:()=>H,getImageDataForSize:()=>h,useActiveBlockStyle:()=>O,useBlockStyles:()=>F,useDisallowedBlocks:()=>A,useMeta:()=>L,useRenderAppenderWithBlockLimit:()=>R,useSelectBlock:()=>j,useSetAttribute:()=>D,withActiveVariation:()=>Z});const n=window.wp.element,o=window.React;function l(e){const{children:t=null,ComponentFalse:o=(()=>null),ComponentTrue:l=(()=>t),predicate:r,...i}=e,c=r(i)?l:o;return(0,n.createElement)(c,i)}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},r.apply(this,arguments)}const i=window.wp.apiFetch;var c=e.n(i);const a=window.wp.components,u=window.wp.data,s=window.wp.i18n,d=window.wp.url,m={label:"",value:""},p={disabled:!0,label:(0,s.__)("No items found!","block-editor-components"),value:""};const f=function(e){const{defaultOption:t=m,fallbackOption:l=p,taxonomy:i,...f}=e,[v,b]=(0,o.useState)(),[h,g]=(0,o.useState)(),k=(0,u.useSelect)((e=>{var t;return null===(t=e("core").getTaxonomy(i))||void 0===t?void 0:t.rest_base}),[i]);return(0,o.useEffect)((()=>{k&&(async()=>{try{const e=await c()({path:(0,d.addQueryArgs)(`/wp/v2/${k}`,{_fields:"id,name",context:"view",per_page:-1})});if(null==e||!e.length)return void g(l?[l]:[]);g([...t?[t]:[],...K(e)])}catch(t){var e;b(null!==(e=t.message)&&void 0!==e?e:(0,s.__)("Unknown error.","block-editor-components"))}})()}),[k,t,l]),v?(0,n.createElement)(a.Notice,{isDismissible:!1,status:"error"},(0,n.createElement)("p",null,v)):h?(0,n.createElement)(a.SelectControl,r({},f,{options:h})):(0,n.createElement)(a.Spinner,null)},v=window.wp.blockEditor;function b(e){const{value:t,onChange:o,...l}=e;return(0,n.createElement)(v.MediaUploadCheck,null,(0,n.createElement)(v.MediaUpload,r({title:(0,s.__)("Select or Upload File","block-editor-components")},l,{multiple:!1,render:e=>{let{open:l}=e;return(0,n.createElement)(a.ToolbarGroup,null,(0,n.createElement)(a.ToolbarButton,{icon:"admin-links",label:t?(0,s.__)("Edit file","block-editor-components"):(0,s.__)("Select file","block-editor-components"),onClick:l}),t&&(0,n.createElement)(a.ToolbarButton,{icon:"editor-unlink",label:(0,s.__)("Deselect file","block-editor-components"),onClick:()=>o(null)}))},value:t,onSelect:o})))}function h(e,t){var n,o;const l=null!==(n=null==e?void 0:e.sizes)&&void 0!==n?n:null==e||null===(o=e.media_details)||void 0===o?void 0:o.sizes,r=null==l?void 0:l[t];return r?{src:r.url||r.source_url,width:r.width,height:r.height}:null}const g=["image"],k=(0,s.__)("Select Image","block-editor-components"),w=(0,s.__)("Select Image","block-editor-components"),S=(0,s.__)("Remove image","block-editor-components"),y=(0,s.__)("Replace Image","block-editor-components");function _(e){const{buttonText:t=k,className:o,help:l,id:r,label:i,modalTitle:c=w,removeButtonText:s=S,replaceButtonText:d=y,size:m,value:p,onChange:f}=e,b=(0,u.useSelect)((e=>{const t=e("core").getMedia(p,{context:"view"});return t?t.alt_text:""}),[p]),_=(0,u.useSelect)((e=>{const t=e("core").getMedia(p,{context:"view"});if(t){if(m){const e=h(t,m);if(e)return e.src}return t.source_url}}),[m,p]);return(0,n.createElement)(a.BaseControl,{className:o,help:l,id:r,label:i},(0,n.createElement)(v.MediaUploadCheck,null,(0,n.createElement)(v.MediaUpload,{allowedTypes:g,render:e=>{let{open:o}=e;return(0,n.createElement)("div",null,p?_?(0,n.createElement)(a.Button,{isLink:!0,onClick:o},(0,n.createElement)("img",{alt:b,src:_})):(0,n.createElement)(a.Spinner,null):null,(0,n.createElement)(a.Button,{isSecondary:!0,onClick:o},p?d:t))},title:c,onSelect:f})),(0,n.createElement)("br",null),p?(0,n.createElement)(a.Button,{isDestructive:!0,isLink:!0,onClick:()=>f(null)},s):null)}function E(e){const{onChange:t,opensInNewTab:l,url:r}=e,[i,c]=(0,o.useState)(!1),u=(0,o.useMemo)((()=>[{icon:"admin-links",title:(0,s.__)("Link","block-editor-components"),isActive:(null==r?void 0:r.length)>0,onClick:()=>c(!i)}]),[c,i,r]),d=(0,o.useMemo)((()=>({url:r,opensInNewTab:l})),[l,r]);return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(a.Toolbar,{controls:u}),i&&(0,n.createElement)(a.Popover,null,(0,n.createElement)(v.__experimentalLinkControl,{forceIsEditingLink:i,opensInNewTab:l,value:d,onChange:t})))}function C(e){var t;const{className:l,limit:i=0,onChange:c,...a}=e,[u,s]=(0,o.useState)(i&&(null===(t=e.value)||void 0===t?void 0:t.length)>i);return(0,n.createElement)(v.PlainText,r({className:`${l} limit-text ${u?"invalid":""}`.trim(),onChange:e=>{i&&e.length>i?u||s(!0):(u&&s(!1),c(e))}},a))}const T=/[\r\n]+/g;function B(e){const{editPost:t}=(0,u.useDispatch)("core/editor"),l=(0,u.useSelect)((e=>e("core/editor").getEditedPostAttribute("title")),[]),i=(0,o.useCallback)((e=>t({title:e.replace(T," ")})),[t]);return(0,n.createElement)(v.RichText,r({},e,{allowedFormats:[],value:l,onChange:i}))}function x(e){var t;const{postType:n}=e;return(0,u.useSelect)((e=>e("core/editor").getCurrentPostType()),[])===n?e.children:null!==(t=e.fallback)&&void 0!==t?t:null}const M=window.wp.dom;function N(e){var t;const{className:l,limit:i=0,onChange:c,...a}=e,u=(0,o.useRef)(),[s,d]=(0,o.useState)(i&&(null===(t=e.value)||void 0===t?void 0:t.length)>i),[m,p]=(0,o.useState)(!1);return(0,n.createElement)(v.RichText,r({ref:u,className:`${l} limit-text ${s?"invalid":""}`.trim(),onChange:t=>{if(i&&(0,M.__unstableStripHTML)(t).length>i)return p(!1),u.current.innerHTML=e.value,(e=>{const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const n=window.getSelection();n.removeAllRanges(),n.addRange(t)})(u.current),void(s||d(!0));m&&s&&d(!1),p(!0),c(t)}},a))}const P=/^is-style-/;function O(e){const{blockName:t,className:n}=(0,u.useSelect)((t=>{var n,o,l;const r=t("core/editor").getBlock(e);return{blockName:null!==(n=null==r?void 0:r.name)&&void 0!==n?n:"",className:null!==(o=null==r||null===(l=r.attributes)||void 0===l?void 0:l.className)&&void 0!==o?o:""}}),[e]),{blockStyles:l,defaultStyle:r}=F(t),i=(0,o.useMemo)((()=>l.map((e=>{let{name:t}=e;return t}))),[l]),c=(0,o.useMemo)((()=>function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().replace(/\s+/," ").split(" ").map((e=>P.test(e)?e.replace(P,""):"")).filter(Boolean)}(n)),[n]);return(0,o.useMemo)((()=>{var e;return null!==(e=c.find((e=>i.includes(e))))&&void 0!==e?e:r}),[i,c,r])}function F(e){const t=(0,u.useSelect)((t=>t("core/blocks").getBlockStyles(e)),[e]);return(0,o.useMemo)((()=>{var e,n;return{blockStyles:t,defaultStyle:null!==(e=null===(n=t.find((e=>{let{isDefault:t}=e;return t})))||void 0===n?void 0:n.name)&&void 0!==e?e:""}}),[t])}const I=window.wp.blocks;function A(e){return(0,o.useMemo)((()=>{const t=(0,I.getBlockTypes)();return null!=t&&t.length?t.filter((t=>{let{name:n,parent:o}=t;return!o&&!e.includes(n)})).map((e=>{let{name:t}=e;return t})):[]}),[e])}function L(e,t){var n;const{editPost:l}=(0,u.useDispatch)("core/editor"),r=(0,u.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta"))),i=(0,o.useCallback)((t=>l({meta:{[e]:t}})),[l,e]);return[null!==(n=null==r?void 0:r[e])&&void 0!==n?n:t,i]}function R(e,t,n){return(0,u.useSelect)((o=>{const{innerBlocks:l}=o("core/block-editor").getBlock(e);return(null==l?void 0:l.length)<t&&n}),[])}function j(){const{selectBlock:e}=(0,u.useDispatch)("core/block-editor");return(0,o.useCallback)((t=>{const n=document.getElementById(`block-${t}`);n&&(e(t),setTimeout((()=>n.scrollIntoView({behavior:"smooth"})),200))}),[e])}function D(e,t,n){return(0,o.useCallback)((function(){let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n;return t({[e]:o})}),[e,n,t])}function U(e){const{getBlocks:t}=(0,u.select)("core/block-editor");return t().find((t=>{let{name:n}=t;return n===e}))}function $(e,t){return e.find((e=>!t(e)))}function W(e,t){return e.filter((e=>!t(e)))}function z(e,t){return e.find((e=>t(e)))}function H(e,t){return e.filter((e=>t(e)))}const V=window.wp.htmlEntities;function G(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const{id:n,title:o}=e;return{label:t+(0,V.decodeEntities)(o.rendered||(0,s.sprintf)((0,s.__)("#%d (no title)","block-editor-components"),n)),value:n}}function Q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const{id:n,name:o}=e;return{label:t+(0,V.decodeEntities)(o||(0,s.sprintf)((0,s.__)("#%d (no name)","block-editor-components"),n)),value:n}}function q(e){return e.map((e=>G(e)))}function J(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"\u2014 ",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return e.map((e=>{let{children:o=[],...l}=e;return[G(l,t.repeat(n)),...J(o,t,n+1)]})).flat()}function K(e){return e.map((e=>Q(e)))}function X(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"\u2014 ",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return e.map((e=>{let{children:o=[],...l}=e;return[Q(l,t.repeat(n)),...X(o,t,n+1)]})).flat()}function Y(e){return(t,n)=>e.every((e=>t[e]===n[e]))}function Z(e){var t;if(null!==(t=e.variations)&&void 0!==t&&t.length){for(var n=arguments.length,o=new Array(n>1?n-1:0),l=1;l<n;l++)o[l-1]=arguments[l];const t=Y(o);e.variations=e.variations.map((e=>(e.isActive=t,e)))}return e}return t})())); | ||
/*! For license information please see index.js.LICENSE.txt */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["@humanmade/block-editor-components"]=t():e["@humanmade/block-editor-components"]=t()}(self,(()=>(()=>{var e={184:(e,t)=>{var n;!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var n=arguments[t];if(n){var r=typeof n;if("string"===r||"number"===r)e.push(n);else if(Array.isArray(n)){if(n.length){var i=l.apply(null,n);i&&e.push(i)}}else if("object"===r){if(n.toString!==Object.prototype.toString&&!n.toString.toString().includes("[native code]")){e.push(n.toString());continue}for(var a in n)o.call(n,a)&&n[a]&&e.push(a)}}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(n=function(){return l}.apply(t,[]))||(e.exports=n)}()},703:(e,t,n)=>{"use strict";var o=n(414);function l(){}function r(){}r.resetWarningCache=l,e.exports=function(){function e(e,t,n,l,r,i){if(i!==o){var a=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:r,resetWarningCache:l};return n.PropTypes=n,n}},697:(e,t,n)=>{e.exports=n(703)()},414:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}},t={};function n(o){var l=t[o];if(void 0!==l)return l.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";n.r(o),n.d(o,{ConditionalComponent:()=>l,FetchAllTermSelectControl:()=>f,FileControls:()=>b,ImageControl:()=>E,InnerBlockSlider:()=>A,LinkToolbar:()=>M,PlainTextWithLimit:()=>L,PostTitleControl:()=>j,PostTypeCheck:()=>D,RichTextWithLimit:()=>$,createOptionFromPost:()=>ne,createOptionFromTerm:()=>oe,createOptionsFromPosts:()=>le,createOptionsFromPostsWithHierarchy:()=>re,createOptionsFromTerms:()=>ie,createOptionsFromTermsWithHierarchy:()=>ae,findBlockByName:()=>J,findInvalidBlock:()=>K,findInvalidBlocks:()=>X,findValidBlock:()=>Z,findValidBlocks:()=>ee,getImageDataForSize:()=>g,useActiveBlockStyle:()=>W,useBlockStyles:()=>H,useDisallowedBlocks:()=>z,useMeta:()=>V,useRenderAppenderWithBlockLimit:()=>G,useSelectBlock:()=>Q,useSetAttribute:()=>Y,withActiveVariation:()=>se});const e=window.wp.element,t=window.React;function l(t){const{children:n=null,ComponentFalse:o=(()=>null),ComponentTrue:l=(()=>n),predicate:r,...i}=t,a=r(i)?l:o;return(0,e.createElement)(a,i)}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},r.apply(this,arguments)}const i=window.wp.apiFetch;var a=n.n(i);const c=window.wp.components,s=window.wp.data,u=window.wp.i18n,d=window.wp.url,p={label:"",value:""},m={disabled:!0,label:(0,u.__)("No items found!","block-editor-components"),value:""};const f=function(n){const{defaultOption:o=p,fallbackOption:l=m,taxonomy:i,...f}=n,[v,b]=(0,t.useState)(),[g,k]=(0,t.useState)(),h=(0,s.useSelect)((e=>{var t;return null===(t=e("core").getTaxonomy(i))||void 0===t?void 0:t.rest_base}),[i]);return(0,t.useEffect)((()=>{h&&(async()=>{try{const e=await a()({path:(0,d.addQueryArgs)(`/wp/v2/${h}`,{_fields:"id,name",context:"view",per_page:-1})});if(null==e||!e.length)return void k(l?[l]:[]);k([...o?[o]:[],...ie(e)])}catch(t){var e;b(null!==(e=t.message)&&void 0!==e?e:(0,u.__)("Unknown error.","block-editor-components"))}})()}),[h,o,l]),v?(0,e.createElement)(c.Notice,{isDismissible:!1,status:"error"},(0,e.createElement)("p",null,v)):g?(0,e.createElement)(c.SelectControl,r({},f,{options:g})):(0,e.createElement)(c.Spinner,null)},v=window.wp.blockEditor;function b(t){const{value:n,onChange:o,...l}=t;return(0,e.createElement)(v.MediaUploadCheck,null,(0,e.createElement)(v.MediaUpload,r({title:(0,u.__)("Select or Upload File","block-editor-components")},l,{multiple:!1,render:t=>{let{open:l}=t;return(0,e.createElement)(c.ToolbarGroup,null,(0,e.createElement)(c.ToolbarButton,{icon:"admin-links",label:n?(0,u.__)("Edit file","block-editor-components"):(0,u.__)("Select file","block-editor-components"),onClick:l}),n&&(0,e.createElement)(c.ToolbarButton,{icon:"editor-unlink",label:(0,u.__)("Deselect file","block-editor-components"),onClick:()=>o(null)}))},value:n,onSelect:o})))}function g(e,t){var n,o;const l=null!==(n=null==e?void 0:e.sizes)&&void 0!==n?n:null==e||null===(o=e.media_details)||void 0===o?void 0:o.sizes,r=null==l?void 0:l[t];return r?{src:r.url||r.source_url,width:r.width,height:r.height}:null}const k=["image"],h=(0,u.__)("Select Image","block-editor-components"),y=(0,u.__)("Select Image","block-editor-components"),S=(0,u.__)("Remove image","block-editor-components"),w=(0,u.__)("Replace Image","block-editor-components");function E(t){const{buttonText:n=h,className:o,help:l,id:r,label:i,modalTitle:a=y,removeButtonText:u=S,replaceButtonText:d=w,size:p,value:m,onChange:f}=t,b=(0,s.useSelect)((e=>{const t=e("core").getMedia(m,{context:"view"});return t?t.alt_text:""}),[m]),E=(0,s.useSelect)((e=>{const t=e("core").getMedia(m,{context:"view"});if(t){if(p){const e=g(t,p);if(e)return e.src}return t.source_url}}),[p,m]);return(0,e.createElement)(c.BaseControl,{className:o,help:l,id:r,label:i},(0,e.createElement)(v.MediaUploadCheck,null,(0,e.createElement)(v.MediaUpload,{allowedTypes:k,render:t=>{let{open:o}=t;return(0,e.createElement)("div",null,m?E?(0,e.createElement)(c.Button,{isLink:!0,onClick:o},(0,e.createElement)("img",{alt:b,src:E})):(0,e.createElement)(c.Spinner,null):null,(0,e.createElement)(c.Button,{isSecondary:!0,onClick:o},m?d:n))},title:a,onSelect:f})),(0,e.createElement)("br",null),m?(0,e.createElement)(c.Button,{isDestructive:!0,isLink:!0,onClick:()=>f(null)},u):null)}var _=n(697),T=n.n(_);const B=window.wp.blocks;function C(n){let{className:o,allowedBlocks:l,template:r,currentItemIndex:i,parentBlockId:a,renderAppender:c,captureToolbars:s}=n;const u=(0,t.useRef)(),d=(0,v.useInnerBlocksProps)({id:`inner-block-display-single-${a}`,className:o},{__experimentalCaptureToolbars:s,allowedBlocks:l,orientation:"horizontal",renderAppender:c,template:r,templateLock:!1});return(0,t.useEffect)((()=>{u.current&&(u.current.innerHTML=`#inner-block-display-single-${a} > *:not(:nth-child(${i+1}) ) { display: none; }`)}),[i,u,a]),(0,e.createElement)(e.Fragment,null,(0,e.createElement)("style",{ref:u}),(0,e.createElement)("div",d))}C.defaultProps={currentItemIndex:0,renderAppender:!1,captureToolbars:!0},C.propTypes={parentBlockId:T().string.isRequired,allowedBlocks:T().arrayOf(T().string).isRequired,template:T().array,className:T().string,currentItemIndex:T().number,renderAppender:T().oneOfType([T().bool,T().element])};const x=C;var P=n(184),I=n.n(P);function O(t){let{totalPages:n,currentPage:o,setCurrentPage:l,prevEnabled:r,nextEnabled:i,addSlide:a=(()=>{}),addSlideEnabled:s=!1}=t;return(0,e.createElement)("div",{className:"inner-block-slider__navigation"},(0,e.createElement)(c.IconButton,{disabled:!r,icon:"arrow-left-alt2",isSecondary:!0,isSmall:!0,onClick:()=>{r&&l(o-1)}}),[...Array(n).keys()].map((t=>(0,e.createElement)(c.Button,{key:t+1,"aria-label":`Slide ${t+1}`,className:I()("components-button","is-not-small",{"is-primary":o===t+1,"is-secondary":o!==t+1}),type:"button",onClick:()=>{l(t+1)}},t+1))),(0,e.createElement)(c.IconButton,{disabled:!i,icon:"arrow-right-alt2",isSecondary:!0,isSmall:!0,onClick:()=>{i&&l(o+1)}}),(0,e.createElement)(c.IconButton,{disabled:!s,icon:"plus-alt2",isSecondary:!0,isSmall:!0,onClick:()=>a()}))}O.propTypes={totalPages:T().number.isRequired,currentPage:T().number.isRequired,setCurrentPage:T().func.isRequired,prevEnabled:T().bool.isRequired,nextEnabled:T().bool.isRequired,addSlide:T().func,addSlideEnabled:T().bool};const R=O,N=n=>{let{parentBlockId:o,allowedBlock:l,template:r,slideLimit:i}=n;const a=r||[[l]],c=(0,s.useSelect)((e=>e("core/block-editor").getBlock(o).innerBlocks)),[u,d]=(0,t.useState)(0),p=(0,t.useRef)(c.length),{insertBlock:m}=(0,s.useDispatch)("core/block-editor");return(0,t.useEffect)((()=>{(c.length>p.current||c.length<p.current&&u+1>c.length)&&d(c.length-1),p.current=c.length}),[c.length,u,p]),(0,e.createElement)("div",{className:"inner-block-slider"},(0,e.createElement)(x,{allowedBlocks:[l],className:"slides",currentItemIndex:u,parentBlockId:o,template:a}),(0,e.createElement)(R,{addSlide:()=>{const e=(0,B.createBlock)(l);m(e,void 0,o)},addSlideEnabled:c.length<i,currentPage:u+1,nextEnabled:u+1<c.length,prevEnabled:u+1>1,setCurrentPage:e=>d(e-1),totalPages:c.length}))};N.defaultProps={slideLimit:10,template:null},N.propTypes={parentBlockId:T().string.isRequired,allowedBlock:T().string.isRequired,template:T().array};const A=N;function M(n){const{onChange:o,opensInNewTab:l,url:r}=n,[i,a]=(0,t.useState)(!1),s=(0,t.useMemo)((()=>[{icon:"admin-links",title:(0,u.__)("Link","block-editor-components"),isActive:(null==r?void 0:r.length)>0,onClick:()=>a(!i)}]),[a,i,r]),d=(0,t.useMemo)((()=>({url:r,opensInNewTab:l})),[l,r]);return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(c.ToolbarGroup,{controls:s}),i&&(0,e.createElement)(c.Popover,null,(0,e.createElement)(v.__experimentalLinkControl,{forceIsEditingLink:i,opensInNewTab:l,value:d,onChange:o})))}function L(n){var o;const{className:l,limit:i=0,onChange:a,...c}=n,[s,u]=(0,t.useState)(i&&(null===(o=n.value)||void 0===o?void 0:o.length)>i);return(0,e.createElement)(v.PlainText,r({className:`${l} limit-text ${s?"invalid":""}`.trim(),onChange:e=>{i&&e.length>i?s||u(!0):(s&&u(!1),a(e))}},c))}const F=/[\r\n]+/g;function j(n){const{editPost:o}=(0,s.useDispatch)("core/editor"),l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("title")),[]),i=(0,t.useCallback)((e=>o({title:e.replace(F," ")})),[o]);return(0,e.createElement)(v.RichText,r({},n,{allowedFormats:[],value:l,onChange:i}))}function D(e){var t;const{postType:n}=e;return(0,s.useSelect)((e=>e("core/editor").getCurrentPostType()),[])===n?e.children:null!==(t=e.fallback)&&void 0!==t?t:null}const q=window.wp.dom;function $(n){var o;const{className:l,limit:i=0,onChange:a,...c}=n,s=(0,t.useRef)(),[u,d]=(0,t.useState)(i&&(null===(o=n.value)||void 0===o?void 0:o.length)>i),[p,m]=(0,t.useState)(!1);return(0,e.createElement)(v.RichText,r({ref:s,className:`${l} limit-text ${u?"invalid":""}`.trim(),onChange:e=>{if(i&&(0,q.__unstableStripHTML)(e).length>i)return m(!1),s.current.innerHTML=n.value,(e=>{const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const n=window.getSelection();n.removeAllRanges(),n.addRange(t)})(s.current),void(u||d(!0));p&&u&&d(!1),m(!0),a(e)}},c))}const U=/^is-style-/;function W(e){const{blockName:n,className:o}=(0,s.useSelect)((t=>{var n,o,l;const r=t("core/block-editor").getBlock(e);return{blockName:null!==(n=null==r?void 0:r.name)&&void 0!==n?n:"",className:null!==(o=null==r||null===(l=r.attributes)||void 0===l?void 0:l.className)&&void 0!==o?o:""}}),[e]),{blockStyles:l,defaultStyle:r}=H(n),i=(0,t.useMemo)((()=>l.map((e=>{let{name:t}=e;return t}))),[l]),a=(0,t.useMemo)((()=>function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().replace(/\s+/," ").split(" ").map((e=>U.test(e)?e.replace(U,""):"")).filter(Boolean)}(o)),[o]);return(0,t.useMemo)((()=>{var e;return null!==(e=a.find((e=>i.includes(e))))&&void 0!==e?e:r}),[i,a,r])}function H(e){const n=(0,s.useSelect)((t=>t("core/blocks").getBlockStyles(e)),[e]);return(0,t.useMemo)((()=>{var e,t;return{blockStyles:n,defaultStyle:null!==(e=null===(t=n.find((e=>{let{isDefault:t}=e;return t})))||void 0===t?void 0:t.name)&&void 0!==e?e:""}}),[n])}function z(e){return(0,t.useMemo)((()=>{const t=(0,B.getBlockTypes)();return null!=t&&t.length?t.filter((t=>{let{name:n,parent:o}=t;return!o&&!e.includes(n)})).map((e=>{let{name:t}=e;return t})):[]}),[e])}function V(e,n){var o;const{editPost:l}=(0,s.useDispatch)("core/editor"),r=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta"))),i=(0,t.useCallback)((t=>l({meta:{[e]:t}})),[l,e]);return[null!==(o=null==r?void 0:r[e])&&void 0!==o?o:n,i]}function G(e,t,n){return(0,s.useSelect)((o=>{const{innerBlocks:l}=o("core/block-editor").getBlock(e);return(null==l?void 0:l.length)<t&&n}),[])}function Q(){const{selectBlock:e}=(0,s.useDispatch)("core/block-editor");return(0,t.useCallback)((t=>{const n=document.getElementById(`block-${t}`);n&&(e(t),setTimeout((()=>n.scrollIntoView({behavior:"smooth"})),200))}),[e])}function Y(e,n,o){return(0,t.useCallback)((function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o;return n({[e]:t})}),[e,o,n])}function J(e){const{getBlocks:t}=(0,s.select)("core/block-editor");return t().find((t=>{let{name:n}=t;return n===e}))}function K(e,t){return e.find((e=>!t(e)))}function X(e,t){return e.filter((e=>!t(e)))}function Z(e,t){return e.find((e=>t(e)))}function ee(e,t){return e.filter((e=>t(e)))}const te=window.wp.htmlEntities;function ne(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const{id:n,title:o}=e;return{label:t+(0,te.decodeEntities)(o.rendered||(0,u.sprintf)((0,u.__)("#%d (no title)","block-editor-components"),n)),value:n}}function oe(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const{id:n,name:o}=e;return{label:t+(0,te.decodeEntities)(o||(0,u.sprintf)((0,u.__)("#%d (no name)","block-editor-components"),n)),value:n}}function le(e){return e.map((e=>ne(e)))}function re(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"\u2014 ",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return e.map((e=>{let{children:o=[],...l}=e;return[ne(l,t.repeat(n)),...re(o,t,n+1)]})).flat()}function ie(e){return e.map((e=>oe(e)))}function ae(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"\u2014 ",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return e.map((e=>{let{children:o=[],...l}=e;return[oe(l,t.repeat(n)),...ae(o,t,n+1)]})).flat()}function ce(e){return(t,n)=>e.every((e=>t[e]===n[e]))}function se(e){var t;if(null!==(t=e.variations)&&void 0!==t&&t.length){for(var n=arguments.length,o=new Array(n>1?n-1:0),l=1;l<n;l++)o[l-1]=arguments[l];const t=ce(o);e.variations=e.variations.map((e=>(e.isActive=t,e)))}return e}})(),o})())); |
{ | ||
"name": "@humanmade/block-editor-components", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Reusable components, hooks and helper functions for the WordPress block editor(s).", | ||
@@ -21,2 +21,3 @@ "keywords": [ | ||
"build": "webpack", | ||
"start": "webpack watch --mode development", | ||
"lint": "eslint .", | ||
@@ -28,24 +29,24 @@ "test": "jest" | ||
"@humanmade/eslint-config": "^1.1.3", | ||
"@wordpress/babel-preset-default": "^7.5.0", | ||
"@wordpress/babel-preset-default": "^7.14.0", | ||
"@wordpress/data": "^7.4.0", | ||
"@wordpress/dependency-extraction-webpack-plugin": "^4.4.0", | ||
"@wordpress/dependency-extraction-webpack-plugin": "^4.13.0", | ||
"@wordpress/html-entities": "^3.20.0", | ||
"@wordpress/i18n": "^4.20.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^29.2.1", | ||
"babel-jest": "^29.5.0", | ||
"babel-loader": "^8.3.0", | ||
"eslint": "^8.27.0", | ||
"eslint": "^8.37.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"eslint-plugin-flowtype": "^8.0.3", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsdoc": "^39.3.23", | ||
"eslint-plugin-jsonc": "^2.4.0", | ||
"eslint-plugin-jsx-a11y": "^6.6.1", | ||
"eslint-plugin-react": "^7.31.10", | ||
"eslint-plugin-jsonc": "^2.7.0", | ||
"eslint-plugin-jsx-a11y": "^6.7.1", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-sort-destructure-keys": "^1.4.0", | ||
"jest": "^29.2.1", | ||
"jest": "^29.5.0", | ||
"react": "^17.0.2", | ||
"terser-webpack-plugin": "^5.3.6", | ||
"webpack": "^5.74.0", | ||
"webpack": "^5.77.0", | ||
"webpack-cli": "^4.10.0" | ||
@@ -58,3 +59,6 @@ }, | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"classnames": "^2.3.2" | ||
} | ||
} |
@@ -14,2 +14,3 @@ # Block Editor Components | ||
- [Utils](#utils) | ||
- [Contributing](#contributing) | ||
@@ -48,2 +49,3 @@ --- | ||
- [`ImageControl`](src/components/ImageControl) | ||
- [`InnerBlockSlider`](src/components/InnerBlockSlider) | ||
- [`LinkToolbar`](src/components/LinkToolbar) | ||
@@ -71,1 +73,6 @@ - [`PlainTextWithLimit`](src/components/PlainTextWithLimit) | ||
- [Variation Utils](src/utils/variations) | ||
## Contributing | ||
This project relies on contributions from those using it! | ||
See the [contribution guidelines](CONTRIBUTING.md) for more information. |
import React, { ReactNode, useMemo, useState } from 'react'; | ||
import { __experimentalLinkControl as LinkControl } from '@wordpress/block-editor'; | ||
import { Popover, Toolbar } from '@wordpress/components'; | ||
import { Popover, ToolbarGroup } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
@@ -44,3 +44,3 @@ | ||
<> | ||
<Toolbar controls={ controls } /> | ||
<ToolbarGroup controls={ controls } /> | ||
{ showLinkControl && ( | ||
@@ -47,0 +47,0 @@ <Popover> |
@@ -33,3 +33,3 @@ import { useMemo } from 'react'; | ||
( select ) => { | ||
const block = select( 'core/editor' ).getBlock( clientId ); | ||
const block = select( 'core/block-editor' ).getBlock( clientId ); | ||
@@ -36,0 +36,0 @@ return { |
@@ -5,2 +5,3 @@ export { default as ConditionalComponent } from './components/ConditionalComponent'; | ||
export { default as ImageControl } from './components/ImageControl'; | ||
export { default as InnerBlockSlider } from './components/InnerBlockSlider'; | ||
export { default as LinkToolbar } from './components/LinkToolbar'; | ||
@@ -7,0 +8,0 @@ export { default as PlainTextWithLimit } from './components/PlainTextWithLimit'; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156818
52
1063
76
1
4
1
+ Addedclassnames@^2.3.2
+ Addedclassnames@2.5.1(transitive)