3 lines
27 KiB
JavaScript
3 lines
27 KiB
JavaScript
|
(self.webpackChunkwebpackWcBlocksJsonp=self.webpackChunkwebpackWcBlocksJsonp||[]).push([[9662],{8082:(e,t,n)=>{"use strict";n.d(t,{k:()=>Q});var o=n(9196),r=n(3554),s=n(711),i=n(9307),l=n(5736),a=n(2629),c=n(4184),d=n.n(c),u=n(4333),p=n(2819),f=n(9630),h=n(5158),m=n(444);const g=(0,i.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,i.createElement)(m.Path,{d:"M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"}));var v=n(7462);class b extends i.Component{constructor(){super(...arguments),this.onChange=this.onChange.bind(this),this.bindInput=this.bindInput.bind(this)}focus(){this.input.focus()}hasFocus(){return this.input===this.input.ownerDocument.activeElement}bindInput(e){this.input=e}onChange(e){this.props.onChange({value:e.target.value})}render(){const{value:e,isExpanded:t,instanceId:n,selectedSuggestionIndex:o,className:r,...s}=this.props,l=e?e.length+1:0;return(0,i.createElement)("input",(0,v.Z)({ref:this.bindInput,id:`components-form-token-input-${n}`,type:"text"},s,{value:e||"",onChange:this.onChange,size:l,className:d()(r,"components-form-token-field__input"),autoComplete:"off",role:"combobox","aria-expanded":t,"aria-autocomplete":"list","aria-owns":t?`components-form-token-suggestions-${n}`:void 0,"aria-activedescendant":-1!==o?`components-form-token-suggestions-${n}-${o}`:void 0,"aria-describedby":`components-form-token-suggestions-howto-${n}`}))}}const E=b;var w=n(4979),y=n.n(w);class _ extends i.Component{constructor(){super(...arguments),this.handleMouseDown=this.handleMouseDown.bind(this),this.bindList=this.bindList.bind(this)}componentDidUpdate(){this.props.selectedIndex>-1&&this.props.scrollIntoView&&this.list.children[this.props.selectedIndex]&&(this.scrollingIntoView=!0,y()(this.list.children[this.props.selectedIndex],this.list,{onlyScrollIfNeeded:!0}),this.props.setTimeout((()=>{this.scrollingIntoView=!1}),100))}bindList(e){this.list=e}handleHover(e){return()=>{this.scrollingIntoView||this.props.onHover(e)}}handleClick(e){return()=>{this.props.onSelect(e)}}handleMouseDown(e){e.preventDefault()}computeSuggestionMatch(e){const t=this.props.displayTransform(this.props.match||"").toLocaleLowerCase();if(0===t.length)return null;const n=(e=this.props.displayTransform(e)).toLocaleLowerCase().indexOf(t);return{suggestionBeforeMatch:e.substring(0,n),suggestionMatch:e.substring(n,n+t.length),suggestionAfterMatch:e.substring(n+t.length)}}render(){return(0,i.createElement)("ul",{ref:this.bindList,className:"components-form-token-field__suggestions-list",id:`components-form-token-suggestions-${this.props.instanceId}`,role:"listbox"},(0,p.map)(this.props.suggestions,((e,t)=>{const n=this.computeSuggestionMatch(e),o=d()("components-form-token-field__suggestion",{"is-selected":t===this.props.selectedIndex});return(0,i.createElement)("li",{id:`components-form-token-suggestions-${this.props.instanceId}-${t}`,role:"option",className:o,key:null!=e&&e.value?e.value:this.props.displayTransform(e),onMouseDown:this.handleMouseDown,onClick:this.handleClick(e),onMouseEnter:this.handleHover(e),"aria-selected":t===this.props.selectedIndex},n?(0,i.createElement)("span",{"aria-label":this.props.displayTransform(e)},n.suggestionBeforeMatch,(0,i.createElement)("strong",{className:"components-form-token-field__suggestion-match"},n.suggestionMatch),n.suggestionAfterMatch):this.props.displayTransform(e))})))}}_.defaultProps={match:"",onHover:()=>{},onSelect:()=>{},suggestions:Object.freeze([])};const C=(0,u.withSafeTimeout)(_);var k=n(4662),S=n(9685),A=n(2875),T=n(1092),I=n(9179),L=n(2506);const O=(0,T.L)({as:"div",useHook:function(e){const t=(0,I.y)(e,"FlexBlock");return(0,L.i)({isBlock:!0,...t})},name:"FlexBlock"});var F=n(1685);const N=(0,u.createHigherOrderComponent)((e=>t=>{const[n,o]=(0,i.useState)(),r=(0,i.useCallback)((e=>o((()=>null!=e&&e.handleFocusOutside?e.handleFocusOutside.bind(e):void 0))),[]);return(0,i.createElement)("div",(0,u.__experimentalUseFocusOutside)(n),(0,i.createElement)(e,(0,v.Z)({ref
|
||
|
/* translators: %d: number of results. */
|
||
|
(0,l._n)("%d result found, use up and down arrow keys to navigate.","%d results found, use up and down arrow keys to navigate.",W.length),W.length):(0,l.__)("No results.");(0,h.speak)(t,"polite")}}),[W,I]),(0,i.createElement)(N,{onFocusOutside:()=>{L(!1)}},(0,i.createElement)(k.Z,{className:d()(v,"components-combobox-control"),tabIndex:"-1",label:n,id:`components-form-token-input-${y}`,hideLabelFromVision:a,help:c},(0,i.createElement)("div",{className:"components-combobox-control__suggestions-container",tabIndex:"-1",onKeyDown:e=>{let t=!1;switch(e.keyCode){case f.ENTER:_&&(q(_),t=!0);break;case f.UP:K(-1),t=!0;break;case f.DOWN:K(1),t=!0;break;case f.ESCAPE:L(!1),T(null),t=!0,e.stopPropagation()}t&&e.preventDefault()}},(0,i.createElement)(A.Z,null,(0,i.createElement)(O,null,(0,i.createElement)(E,{className:"components-combobox-control__input",instanceId:y,ref:V,value:I?D:M,"aria-label":M?`${M}, ${n}`:null,onFocus:()=>{R(!0),L(!0),s(""),B("")},onBlur:()=>{R(!1)},isExpanded:I,selectedSuggestionIndex:W.indexOf(_),onChange:e=>{const t=e.value;B(t),s(t),x&&L(!0)}})),m&&(0,i.createElement)(F.Z,null,(0,i.createElement)(S.Z,{className:"components-combobox-control__reset",icon:g,disabled:!t,onClick:()=>{r(null),V.current.input.focus()},label:(0,l.__)("Reset")}))),I&&(0,i.createElement)(C,{instanceId:y,match:{label:D},displayTransform:e=>e.label,suggestions:W,selectedIndex:W.indexOf(_),onHover:T,onSelect:q,scrollIntoView:!0}))))};var R=n(7884),D=n(9818),B=n(4801);n(5821);const V=(0,u.withInstanceId)((({id:e,className:t,label:n,onChange:r,options:a,value:c,required:u=!1,errorMessage:p=(0,l.__)("Please select a value.","woocommerce"),errorId:f,instanceId:h="0",autoComplete:m="off"})=>{const g=(0,i.useRef)(null),v=e||"control-"+h,b=f||v,{setValidationErrors:E,clearValidationError:w}=(0,D.useDispatch)(B.VALIDATION_STORE_KEY),y=(0,D.useSelect)((e=>e(B.VALIDATION_STORE_KEY).getValidationError(b)));return(0,i.useEffect)((()=>(!u||c?w(b):E({[b]:{message:p,hidden:!0}}),()=>{w(b)})),[w,c,b,p,u,E]),(0,o.createElement)("div",{id:v,className:d()("wc-block-components-combobox",t,{"is-active":c,"has-error":(null==y?void 0:y.message)&&!(null!=y&&y.hidden)}),ref:g},(0,o.createElement)(x,{className:"wc-block-components-combobox-control",label:n,onChange:r,onFilterValueChange:e=>{if(e.length){const t=(0,R.Kn)(g.current)?g.current.ownerDocument.activeElement:void 0;if(t&&(0,R.Kn)(g.current)&&g.current.contains(t))return;const n=e.toLocaleUpperCase(),o=a.find((e=>e.value.toLocaleUpperCase()===n));if(o)return void r(o.value);const s=a.find((e=>e.label.toLocaleUpperCase().startsWith(n)));s&&r(s.value)}},options:a,value:c||"",allowReset:!1,autoComplete:m,"aria-invalid":(null==y?void 0:y.message)&&!(null!=y&&y.hidden)}),(0,o.createElement)(s.ValidationInputError,{propertyName:b}))}));n(7775);const P=({className:e,countries:t,id:n,label:r,onChange:s,value:c="",autoComplete:u="off",required:p=!1,errorId:f,errorMessage:h=(0,l.__)("Please select a country","woocommerce")})=>{const m=(0,i.useMemo)((()=>Object.entries(t).map((([e,t])=>({value:e,label:(0,a.decodeEntities)(t)})))),[t]);return(0,o.createElement)("div",{className:d()(e,"wc-block-components-country-input")},(0,o.createElement)(V,{id:n,label:r,onChange:s,options:m,value:c,errorId:f,errorMessage:h,required:p,autoComplete:u}))};var M=n(5271);const W=e=>(0,o.createElement)(P,{countries:M.DK,...e}),q=e=>(0,o.createElement)(P,{countries:M.mO,...e});n(8410);const K=(e,t)=>{const n=t.find((t=>t.label.toLocaleUpperCase()===e.toLocaleUpperCase()||t.value.toLocaleUpperCase()===e.toLocaleUpperCase()));return n?n.value:""},U=({className:e,id:t,states:n,country:r,label:c,onChange:u,autoComplete:p="off",value:f="",required:h=!1,errorId:m=""})=>{const g=n[r],v=(0,i.useMemo)((()=>g?Object.keys(g).map((e=>({value:e,label:(0,a.decodeEntities)(g[e])}))):[]),[g]),b=(0,i.useCallback)((e=>{const t=v.length>0?K(e,v):e;t!==f&&u(t)}),[u,v,f]),E=(0,i.useRef)(f);return(0,i.useEffect)((()=>{E.current!==f&&(E.current=f)}),[f]),(0,i.useEffect)((()=>{if(v.length>0&&E.current){const e=K(E.current,v);e!==E.current&&b(e)}}),[v,b]),
|