7 lines
185 KiB
JavaScript
7 lines
185 KiB
JavaScript
|
|
(()=>{var e,o={6730:(e,o,n)=>{"use strict";const t=window.wp.i18n,i=window.wp.blocks,a=window.wp.blockEditor,r=window.kadence.icons;var l=n(6942),d=n.n(l);const c=window.lodash,s=window.wp.data,p=window.wp.components,g=window.wp.coreData,b=window.wp.element,u=window.wp.apiFetch;var v=n.n(u);function k(e,o="post"){const[n,t]=(0,b.useState)(!1),{receiveEntityRecords:i}=(0,s.useDispatch)(g.store);return[n,async()=>{t(!0);try{const n=await v()({method:"POST",path:`/wp/v2/${e}/auto-draft`,data:{post_type:o}});i("postType",n.type,[n]);const a=n.id;try{const o=await v()({method:"POST",path:`/wp/v2/${e}/${a}`,data:{status:"publish"}});return i("postType",o.type,[o]),o}finally{t(!1)}}finally{t(!1)}}]}const _=window.wp.primitives,h=window.ReactJSXRuntime,m=(0,h.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,h.jsx)(_.Path,{d:"M6 5V18.5911L12 13.8473L18 18.5911V5H6Z"})});function y({onSelect:e,isSelecting:o,onAdd:n,onAddOtherType:i,isAdding:a,postType:r="post",label:l=(0,t.__)("Post"),instructions:d=(0,t.__)("Select an existing navigation or create a new one.","kadence-blocks"),placeholder:c=(0,t.__)("Select Navigation","kadence-blocks")}){const[g,u]=(0,b.useState)(0),{posts:v,menus:k}=(0,s.useSelect)(e=>({posts:e("core").getEntityRecords("postType",r,{per_page:-1,orderby:"title",order:"asc"}),menus:e("core").getEntityRecords("taxonomy","nav_menu",{order:"asc",orderby:"name",per_page:50})}),[r]),_=[...(v||[]).map(e=>({label:f(e.title.raw),value:e.id,type:"kadence_navigation"}))],y=[...(k||[]).map(e=>({label:f(e.name),value:e.id,type:"nav_menu"}))],w=[..._,...y],T=[{label:(0,t.__)("Kadence Navigations","kadence-blocks"),options:_},{label:(0,t.__)("Import WordPress Menu","kadence-blocks"),options:y}].map((e,o)=>(0,h.jsx)(h.Fragment,{children:e.options?.length&&(0,h.jsx)("optgroup",{label:e.label,children:e.options.map(e=>(0,h.jsx)("option",{value:e.value,children:e.label}))})})),M=w.find(e=>e.value==g);return M&&(M.id=M.value),"undefined"==typeof pagenow||"widgets"!==pagenow&&"customize"!==pagenow?(0,h.jsx)(p.Placeholder,{className:"kb-select-or-create-placeholder",icon:m,label:l,instructions:d,children:(0,h.jsxs)("form",{className:"kb-select-or-create-placeholder__actions",children:[(0,h.jsxs)(p.SelectControl,{label:l,value:g,onChange:u,hideLabelFromVision:!0,children:[(0,h.jsx)("option",{value:"0",disabled:!0,children:(0,t.__)("Make selection…","kadence-blocks")}),T]}),(0,h.jsxs)(p.Button,{style:{marginTop:"20px",marginRight:"10px"},variant:"primary",type:"submit",disabled:!g||a,isBusy:o,onClick:()=>{"kadence_navigation"===M?.type?e(Number.parseInt(M?.id)):i(M)},children:["nav_menu"===M?.type?(0,t.__)("Import","kadence-blocks"):(0,t.__)("Select","kadence-blocks")," "]}),(0,h.jsx)(p.Button,{variant:"secondary",onClick:n,disabled:o,isBusy:a,children:(0,t.__)("Create New","kadence-blocks")})]})}):(_.unshift({label:c,value:""}),(0,h.jsx)(p.Placeholder,{className:"kb-select-or-create-placeholder",icon:m,label:l,instructions:d,children:(0,h.jsxs)("form",{className:"kb-select-or-create-placeholder__actions",children:[(0,h.jsx)(p.SelectControl,{label:l,hideLabelFromVision:!0,options:_,onChange:u,value:g}),(0,h.jsx)(p.Button,{variant:"primary",type:"submit",disabled:!g||a,isBusy:o,onClick:()=>e(Number.parseInt(g)),children:(0,t.__)("Select","kadence-blocks")})]})}))}function f(e){const o=(e=e||"").replace(/<!--[\s\S]*?(-->|$)/g,"").replace(/<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/gi,"").replace(/<\/?[a-z][\s\S]*?(>|$)/gi,"");return o!==e?f(o):o}const w=window.kadence.components,T=(0,h.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,h.jsx)(_.Path,{d:"M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"})}),M=["kadence/column","kadence/rowlayout"],C=(0,h.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,h.jsx)(_.Path,{d:"M11 13h2v-2h-2v2zm-6 0h2v-2H5v2zm12-2v2h2v-2h-2z"})}),S=(0,h.jsx)(_.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,h.jsx)(_.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})}),x=(0,h.jsx)(_
|
||
|
|
// translators: 'Home' as in a website's home page.
|
||
|
|
label:(0,t.__)("Home"),url:"https://make.wordpress.org/"}},{name:"core/navigation-link",attributes:{
|
||
|
|
// translators: 'About' as in a website's about page.
|
||
|
|
label:(0,t.__)("About"),url:"https://make.wordpress.org/"}},{name:"core/navigation-link",attributes:{
|
||
|
|
// translators: 'Contact' as in a website's contact page.
|
||
|
|
label:(0,t.__)("Contact"),url:"https://make.wordpress.org/"}}]},edit:function(e){const{attributes:o,setAttributes:n,isSelected:l,clientId:u}=e,{id:v,uniqueID:_,templateKey:m,makePost:y}=o,[f,T]=(0,b.useState)(!1),[M,C]=(0,b.useState)(!1),[S,x]=(0,b.useState)(m),{post:A,postExists:D,isLoading:H,currentPostType:B,postId:z}=(0,s.useSelect)(e=>({post:v&&e(g.store).getEditedEntityRecord("postType","kadence_navigation",v),postExists:v&&e(g.store).getEntityRecord("postType","kadence_navigation",v),isLoading:e(g.store).isResolving("getEntityRecord",["postType","kadence_navigation",v]),currentPostType:e("core/editor")?.getCurrentPostType()?e("core/editor")?.getCurrentPostType():"",postId:e("core/editor")?.getCurrentPostId()?e("core/editor")?.getCurrentPostId():""}),[v]),[R,I]=Wn("meta","kadence_navigation"===B?z:v),[P,j]=Wn("title","kadence_navigation"===B?z:v),[L,E]=k("kadence_navigation","kadence_navigation"),[N,F,O]=(0,g.useEntityBlockEditor)("postType","kadence_navigation",{id:v}),U={orientation:R?._kad_navigation_orientation,orientationTablet:R?._kad_navigation_orientationTablet,orientationMobile:R?._kad_navigation_orientationMobile,stretchFill:R?._kad_navigation_stretchFill,stretchFillTablet:R?._kad_navigation_stretchFillTablet,stretchFillMobile:R?._kad_navigation_stretchFillMobile,horizontalLayout:R?._kad_navigation_horizontalLayout,horizontalLayoutTablet:R?._kad_navigation_horizontalLayoutTablet,horizontalLayoutMobile:R?._kad_navigation_horizontalLayoutMobile,horizontalGrid:R?._kad_navigation_horizontalGrid,horizontalGridTablet:R?._kad_navigation_horizontalGridTablet,horizontalGridMobile:R?._kad_navigation_horizontalGridMobile},{orientation:V,orientationTablet:G,orientationMobile:W,stretchFill:q,stretchFillTablet:K,stretchFillMobile:$,horizontalLayout:X,horizontalLayoutTablet:Y,horizontalLayoutMobile:Z}=U,J=!v&&m,Q=J?m.includes("vertical")?"vertical":"horizontal":V,ee=J?m.includes("vertical")?"vertical":"horizontal":G,oe=J?m.includes("vertical")?"vertical":"horizontal":W,{previewDevice:ne,isPreviewMode:te,getStash:ie}=(0,s.useSelect)(e=>({isPreviewMode:e("core/block-editor").getSettings().__unstableIsPreviewMode,previewDevice:e("kadenceblocks/data").getPreviewDeviceType(),getStash:o=>e("kadenceblocks/data").getStash(o)}),[u]);(0,kn.uniqueIdHelper)(e),(0,b.useEffect)(()=>{"kadence_navigation"===B&&window.wp.data.dispatch("core/block-editor").setTemplateValidity(!0)},[]);const ae=(0,kn.getPreviewSize)(ne,X,Y,Z),re=(0,kn.getPreviewSize)(ne,q,K,$),le=(0,kn.getPreviewSize)(ne,Q||"horizontal",ee,oe),de=(0,kn.getPreviewSize)("tablet",Q||"horizontal",ee,oe),ce=(0,kn.getPreviewSize)("mobile",Q||"horizontal",ee,oe),se=d()({[`wp-block-kadence-navigation${_}`]:_,[`kb-navigation-horizontal-layout-${ae}`]:ae,[`kb-navigation-orientation-${le}`]:le,"kb-navigation-layout-stretch-fill":"fill"===re,[`navigation-desktop-orientation-${Q||"horizontal"}`]:!ne||"Desktop"==ne,[`navigation-tablet-orientation-${de||"horizontal"}`]:"Tablet"==ne,[`navigation-mobile-orientation-${ce||"horizontal"}`]:"Mobile"==ne}),pe=(0,a.useBlockProps)({className:se});return"kadence_navigation"!==B||v||m?((0,b.useEffect)(()=>{!v&&m&&y&&(async()=>{try{C(!0);const e=await E(),o=e?.id;o&&n({id:o})}catch(e){console.error(e)}})()},[]),(0,b.useEffect)(()=>{if(v&&m&&y){n({makePost:!1});const{templateInnerBlocks:e,templatePostMeta:o}=Un(m,ie);O(e||[(0,i.createBlock)("kadence/navigation",{},[])],u),j(m),o._kad_navigation_description="A placeholder navigation",I({...R,...o}),wp.data.dispatch("core").saveEditedEntityRecord("postType","kadence_navigation",v).then(()=>{C(!1)})}},[v]),(0,b.useEffect)(()=>{"kadence_navigation"===B||l||0!==v||""!==m||""===S||n({templateKey:S})},[l]),!f&&H&&T(!0),M?(0,h.jsx)(p.Spinner,{}):(0,h.jsxs)("div",{...pe,children:[(0===v&&!m||void 0===D&&f&&!H&&null!==A)&&(0,h.jsx)(Gn,{id:v,postExists:D,post:A,commit:e=>n({id:e})}),v>0&&(0,c.isEmpty)(A)&&void 0===D&&H&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(p.Spinner,{}),(0,h.jsx)(a.InspectorControls,{children:(0,h.jsxs)(w.KadencePanelBody,{panelName:"kb-navigation-selected-switch",title:(0,t.__)("Select
|