WordPress/wp-includes/js/dist/widgets.min.js

7 lines
18 KiB
JavaScript

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.widgets=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="4g8P")}({"1ZqX":function(e,t){e.exports=window.wp.data},"4g8P":function(e,t,n){"use strict";n.r(t),n.d(t,"MoveToWidgetArea",(function(){return Q})),n.d(t,"getWidgetIdFromBlock",(function(){return R})),n.d(t,"addWidgetIdToBlock",(function(){return G})),n.d(t,"registerLegacyWidgetBlock",(function(){return q})),n.d(t,"registerLegacyWidgetVariations",(function(){return U}));var i={};n.r(i),n.d(i,"metadata",(function(){return N})),n.d(i,"name",(function(){return V})),n.d(i,"settings",(function(){return A}));var r=n("HSyU"),a=n("GRId"),o=n("Tqx9");var s=Object(a.createElement)(o.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)(o.Path,{d:"M7 11h2v2H7v-2zm14-5v14l-2 2H5l-2-2V6l2-2h1V2h2v2h8V2h2v2h1l2 2zM5 8h14V6H5v2zm14 12V10H5v10h14zm-4-7h2v-2h-2v2zm-4 0h2v-2h-2v2z"})),c=n("TSYQ"),l=n.n(c),d=n("axFQ"),u=n("tI+e");var h=Object(a.createElement)(o.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(a.createElement)(o.Path,{d:"M4 20h8v-1.5H4V20zM18.9 3.5c-.6-.6-1.5-.6-2.1 0l-7.2 7.2c-.4-.1-.7 0-1.1.1-.5.2-1.5.7-1.9 2.2-.4 1.7-.8 2.2-1.1 2.7-.1.1-.2.3-.3.4l-.6 1.1H6c2 0 3.4-.4 4.7-1.4.8-.6 1.2-1.4 1.3-2.3 0-.3 0-.5-.1-.7L19 5.7c.5-.6.5-1.6-.1-2.2zM9.7 14.7c-.7.5-1.5.8-2.4 1 .2-.5.5-1.2.8-2.3.2-.6.4-1 .8-1.1.5-.1 1 .1 1.3.3.2.2.3.5.2.8 0 .3-.1.9-.7 1.3z"})),m=n("l3Sj"),w=n("1ZqX"),g=n("jZUy");function b({selectedId:e,onSelect:t}){const n=Object(w.useSelect)(e=>{var t,n,i;const r=null!==(t=null===(n=e(d.store).getSettings())||void 0===n?void 0:n.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==t?t:[];return null===(i=e(g.store).getWidgetTypes({per_page:-1}))||void 0===i?void 0:i.filter(e=>!r.includes(e.id))},[]);return n?0===n.length?Object(m.__)("There are no widgets available."):Object(a.createElement)(u.SelectControl,{label:Object(m.__)("Select a legacy widget to display:"),value:null!=e?e:"",options:[{value:"",label:Object(m.__)("Select widget")},...n.map(e=>({value:e.id,label:e.name}))],onChange:e=>{if(e){const i=n.find(t=>t.id===e);t({selectedId:i.id,isMulti:i.is_multi})}else t({selectedId:null})}}):Object(a.createElement)(u.Spinner,null)}function p({name:e,description:t}){return Object(a.createElement)("div",{className:"wp-block-legacy-widget-inspector-card"},Object(a.createElement)("h3",{className:"wp-block-legacy-widget-inspector-card__name"},e),Object(a.createElement)("span",null,t))}var f=n("onLe"),v=n("K9lf"),y=n("YLtl"),j=n("ywyh"),O=n.n(j);class _{constructor({id:e,idBase:t,instance:n,onChangeInstance:i,onChangeHasPreview:r,onError:a}){this.id=e,this.idBase=t,this._instance=n,this._hasPreview=null,this.onChangeInstance=i,this.onChangeHasPreview=r,this.onError=a,this.number=++E,this.handleFormChange=Object(y.debounce)(this.handleFormChange.bind(this),200),this.handleFormSubmit=this.handleFormSubmit.bind(this),this.initDOM(),this.bindEvents(),this.loadContent()}destroy(){this.unbindEvents(),this.element.remove()}initDOM(){var e,t;this.element=k("div",{class:"widget open"},[k("div",{class:"widget-inside"},[this.form=k("form",{class:"form",method:"post"},[k("input",{class:"widget-id",type:"hidden",name:"widget-id",value:null!==(e=this.id)&&void 0!==e?e:`${this.idBase}-${this.number}`}),k("input",{class:"id_base",type:"hidden",name:"id_base",value:null!==(t=this.idBase)&&void 0!==t?t:this.id}),k("input",{class:"widget-width",type:"hidden",name:"widget-width",value:"250"}),k("input",{class:"widget-height",type:"hidden",name:"widget-height",value:"200"}),k("input",{class:"widget_number",type:"hidden",name:"widget_number",value:this.idBase?this.number.toString():""}),this.content=k("div",{class:"widget-content"}),this.id&&k("button",{class:"button is-primary",type:"submit"},Object(m.__)("Save"))])])])}bindEvents(){if(window.jQuery){const{jQuery:e}=window;e(this.form).on("change",null,this.handleFormChange),e(this.form).on("input",null,this.handleFormChange),e(this.form).on("submit",this.handleFormSubmit)}else this.form.addEventListener("change",this.handleFormChange),this.form.addEventListener("input",this.handleFormChange),this.form.addEventListener("submit",this.handleFormSubmit)}unbindEvents(){if(window.jQuery){const{jQuery:e}=window;e(this.form).off("change",null,this.handleFormChange),e(this.form).off("input",null,this.handleFormChange),e(this.form).off("submit",this.handleFormSubmit)}else this.form.removeEventListener("change",this.handleFormChange),this.form.removeEventListener("input",this.handleFormChange),this.form.removeEventListener("submit",this.handleFormSubmit)}async loadContent(){try{if(this.id){const{form:e}=await S(this.id);this.content.innerHTML=e}else if(this.idBase){const{form:e,preview:t}=await B({idBase:this.idBase,instance:this.instance,number:this.number});if(this.content.innerHTML=e,this.hasPreview=!T(t),!this.instance.hash){const{instance:e}=await B({idBase:this.idBase,instance:this.instance,number:this.number,formData:x(this.form)});this.instance=e}}if(window.jQuery){const{jQuery:e}=window;e(document).trigger("widget-added",[e(this.element)])}}catch(e){this.onError(e)}}handleFormChange(){this.idBase&&this.saveForm()}handleFormSubmit(e){e.preventDefault(),this.saveForm()}async saveForm(){const e=x(this.form);try{if(this.id){const{form:t}=await S(this.id,e);if(this.content.innerHTML=t,window.jQuery){const{jQuery:e}=window;e(document).trigger("widget-updated",[e(this.element)])}}else if(this.idBase){const{instance:t,preview:n}=await B({idBase:this.idBase,instance:this.instance,number:this.number,formData:e});this.instance=t,this.hasPreview=!T(n)}}catch(e){this.onError(e)}}get instance(){return this._instance}set instance(e){this._instance!==e&&(this._instance=e,this.onChangeInstance(e))}get hasPreview(){return this._hasPreview}set hasPreview(e){this._hasPreview!==e&&(this._hasPreview=e,this.onChangeHasPreview(e))}}let E=0;function k(e,t={},n=null){const i=document.createElement(e);for(const[e,n]of Object.entries(t))i.setAttribute(e,n);if(Array.isArray(n))for(const e of n)e&&i.appendChild(e);else"string"==typeof n&&(i.innerText=n);return i}async function S(e,t=null){let n;return n=t?await O()({path:`/wp/v2/widgets/${e}?context=edit`,method:"PUT",data:{form_data:t}}):await O()({path:`/wp/v2/widgets/${e}?context=edit`,method:"GET"}),{form:n.rendered_form}}async function B({idBase:e,instance:t,number:n,formData:i=null}){const r=await O()({path:`/wp/v2/widget-types/${e}/encode`,method:"POST",data:{instance:t,number:n,form_data:i}});return{instance:r.instance,form:r.form,preview:r.preview}}function T(e){const t=document.createElement("div");return t.innerHTML=e,C(t)}function C(e){switch(e.nodeType){case e.TEXT_NODE:return""===e.nodeValue.trim();case e.ELEMENT_NODE:return!["AUDIO","CANVAS","EMBED","IFRAME","IMG","MATH","OBJECT","SVG","VIDEO"].includes(e.tagName)&&(!e.hasChildNodes()||Array.from(e.childNodes).every(C));default:return!0}}function x(e){return new window.URLSearchParams(Array.from(new window.FormData(e))).toString()}function P({title:e,isVisible:t,id:n,idBase:i,instance:r,isWide:o,onChangeInstance:s,onChangeHasPreview:c}){const d=Object(a.useRef)(),h=Object(v.useViewportMatch)("small"),g=Object(a.useRef)(new Set),b=Object(a.useRef)(new Set),{createNotice:p}=Object(w.useDispatch)(f.store);return Object(a.useEffect)(()=>{if(b.current.has(r))return void b.current.delete(r);const e=new _({id:n,idBase:i,instance:r,onChangeInstance(e){g.current.add(r),b.current.add(e),s(e)},onChangeHasPreview:c,onError(e){var t;p("error",null!==(t=null==e?void 0:e.message)&&void 0!==t?t:Object(m.__)("An error occured while fetching or updating the widget."))}});return d.current.appendChild(e.element),()=>{g.current.has(r)?g.current.delete(r):e.destroy()}},[n,i,r,s,c,h]),o&&h?Object(a.createElement)("div",{className:l()({"wp-block-legacy-widget__container":t})},t&&Object(a.createElement)("h3",{className:"wp-block-legacy-widget__edit-form-title"},e),Object(a.createElement)(u.Popover,{focusOnMount:!1,position:"middle right",__unstableForceXAlignment:!0},Object(a.createElement)("div",{ref:d,className:"wp-block-legacy-widget__edit-form",hidden:!t}))):Object(a.createElement)("div",{ref:d,className:"wp-block-legacy-widget__edit-form",hidden:!t},Object(a.createElement)("h3",{className:"wp-block-legacy-widget__edit-form-title"},e))}var M=n("Mmq9");function I({idBase:e,instance:t,isVisible:n}){const[i,r]=Object(a.useState)(),o=Object(v.useRefEffect)(e=>{function t(){var t,n;const i=null==e||null===(t=e.contentDocument)||void 0===t||null===(n=t.body)||void 0===n?void 0:n.getBoundingClientRect();i&&r(i.top+i.height)}const{IntersectionObserver:n}=e.ownerDocument.defaultView;return new n(t,{threshold:1}).observe(e),e.addEventListener("load",t),()=>{e.removeEventListener("load",t)}},[]);return Object(a.createElement)(a.Fragment,null,n&&null===i&&Object(a.createElement)(u.Placeholder,null,Object(a.createElement)(u.Spinner,null)),Object(a.createElement)("div",{className:l()("wp-block-legacy-widget__edit-preview",{"is-offscreen":!n||null===i})},Object(a.createElement)(u.Disabled,null,Object(a.createElement)("iframe",{ref:o,className:"wp-block-legacy-widget__edit-preview-iframe",title:Object(m.__)("Legacy Widget Preview"),src:Object(M.addQueryArgs)("widgets.php",{"legacy-widget-preview":{idBase:e,instance:t}}),height:i||100}))))}function F({name:e}){return Object(a.createElement)("div",{className:"wp-block-legacy-widget__edit-no-preview"},e&&Object(a.createElement)("h3",null,e),Object(a.createElement)("p",null,Object(m.__)("No preview available.")))}function L({clientId:e,rawInstance:t}){const{replaceBlocks:n}=Object(w.useDispatch)(d.store);return Object(a.createElement)(u.ToolbarButton,{onClick:()=>{t.title?n(e,[Object(r.createBlock)("core/heading",{content:t.title}),...Object(r.rawHandler)({HTML:t.text})]):n(e,Object(r.rawHandler)({HTML:t.text}))}},Object(m.__)("Convert to blocks"))}function H({attributes:{id:e,idBase:t},setAttributes:n}){return Object(a.createElement)(u.Placeholder,{icon:Object(a.createElement)(d.BlockIcon,{icon:h}),label:Object(m.__)("Legacy Widget")},Object(a.createElement)(b,{selectedId:null!=e?e:t,onSelect:({selectedId:e,isMulti:t})=>{n(e?t?{id:null,idBase:e,instance:{}}:{id:e,idBase:null,instance:null}:{id:null,idBase:null,instance:null})}}))}function D({attributes:{id:e,idBase:t,instance:n},setAttributes:i,clientId:r,isSelected:o,isWide:s=!1}){const[c,l]=Object(a.useState)(null),{widgetType:b,hasResolvedWidgetType:f,isNavigationMode:v}=Object(w.useSelect)(n=>{const i=null!=e?e:t;return{widgetType:n(g.store).getWidgetType(i),hasResolvedWidgetType:n(g.store).hasFinishedResolution("getWidgetType",[i]),isNavigationMode:n(d.store).isNavigationMode()}},[e,t]),y=Object(a.useCallback)(e=>{i({instance:e})},[]);if(!b&&f)return Object(a.createElement)(u.Placeholder,{icon:Object(a.createElement)(d.BlockIcon,{icon:h}),label:Object(m.__)("Legacy Widget")},Object(m.__)("Widget is missing."));if(!f)return Object(a.createElement)(u.Placeholder,null,Object(a.createElement)(u.Spinner,null));const j=!t||!v&&o?"edit":"preview";return Object(a.createElement)(a.Fragment,null,"text"===t&&Object(a.createElement)(d.BlockControls,{group:"other"},Object(a.createElement)(L,{clientId:r,rawInstance:n.raw})),Object(a.createElement)(d.InspectorControls,null,Object(a.createElement)(p,{name:b.name,description:b.description})),Object(a.createElement)(P,{title:b.name,isVisible:"edit"===j,id:e,idBase:t,instance:n,isWide:s,onChangeInstance:y,onChangeHasPreview:l}),t&&Object(a.createElement)(a.Fragment,null,null===c&&"preview"===j&&Object(a.createElement)(u.Placeholder,null,Object(a.createElement)(u.Spinner,null)),!0===c&&Object(a.createElement)(I,{idBase:t,instance:n,isVisible:"preview"===j}),!1===c&&"preview"===j&&Object(a.createElement)(F,{name:b.name})))}var W={to:[{block:"core/calendar",widget:"calendar"},{block:"core/search",widget:"search"},{block:"core/html",widget:"custom_html",transform:({content:e})=>({content:e})},{block:"core/archives",widget:"archives",transform:({count:e,dropdown:t})=>({displayAsDropdown:!!t,showPostCounts:!!e})},{block:"core/latest-posts",widget:"recent-posts",transform:({show_date:e,number:t})=>({displayPostDate:!!e,postsToShow:t})},{block:"core/latest-comments",widget:"recent-comments",transform:({number:e})=>({commentsToShow:e})},{block:"core/tag-cloud",widget:"tag_cloud",transform:({taxonomy:e,count:t})=>({showTagCounts:!!t,taxonomy:e})},{block:"core/categories",widget:"categories",transform:({count:e,dropdown:t,hierarchical:n})=>({displayAsDropdown:!!t,showPostCounts:!!e,showHierarchy:!!n})},{block:"core/audio",widget:"media_audio",transform:({url:e,preload:t,loop:n,attachment_id:i})=>({src:e,id:i,preload:t,loop:n})},{block:"core/video",widget:"media_video",transform:({url:e,preload:t,loop:n,attachment_id:i})=>({src:e,id:i,preload:t,loop:n})},{block:"core/image",widget:"media_image",transform:({alt:e,attachment_id:t,caption:n,height:i,link_classes:r,link_rel:a,link_target_blank:o,link_type:s,link_url:c,size:l,url:d,width:u})=>({alt:e,caption:n,height:i,id:t,link:c,linkClass:r,linkDestination:s,linkTarget:o?"_blank":void 0,rel:a,sizeSlug:l,url:d,width:u})},{block:"core/gallery",widget:"media_gallery",transform:({ids:e,link_type:t,size:n,number:i})=>({ids:e,columns:i,linkTo:t,sizeSlug:n,images:e.map(e=>({id:e}))})},{block:"core/rss",widget:"rss",transform:({url:e,show_author:t,show_date:n,show_summary:i,items:r})=>({feedURL:e,displayAuthor:!!t,displayDate:!!n,displayExcerpt:!!i,itemsToShow:r})}].map(({block:e,widget:t,transform:n})=>({type:"block",blocks:[e],isMatch:({idBase:e,instance:n})=>e===t&&!(null==n||!n.raw),transform:({instance:t})=>{var i;const a=Object(r.createBlock)(e,n?n(t.raw):void 0);return null!==(i=t.raw)&&void 0!==i&&i.title?[Object(r.createBlock)("core/heading",{content:t.raw.title}),a]:a}}))};const N={apiVersion:2,name:"core/legacy-widget",title:"Legacy Widget",category:"widgets",description:"Display a legacy widget.",textdomain:"default",attributes:{id:{type:"string",default:null},idBase:{type:"string",default:null},instance:{type:"object",default:null}},supports:{html:!1,customClassName:!1,reusable:!1},editorStyle:"wp-block-legacy-widget-editor"},{name:V}=N,A={icon:s,edit:function(e){const{id:t,idBase:n}=e.attributes,{isWide:i=!1}=e,r=Object(d.useBlockProps)({className:l()({"is-wide-widget":i})});return Object(a.createElement)("div",r,t||n?Object(a.createElement)(D,e):Object(a.createElement)(H,e))},transforms:W};var z=Object(a.createElement)(o.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(a.createElement)(o.Path,{d:"M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z"}));function Q({currentWidgetAreaId:e,widgetAreas:t,onSelect:n}){return Object(a.createElement)(u.ToolbarGroup,null,Object(a.createElement)(u.ToolbarItem,null,i=>Object(a.createElement)(u.DropdownMenu,{icon:z,label:Object(m.__)("Move to widget area"),toggleProps:i},({onClose:i})=>Object(a.createElement)(u.MenuGroup,{label:Object(m.__)("Move to")},Object(a.createElement)(u.MenuItemsChoice,{choices:t.map(e=>({value:e.id,label:e.name,info:e.description})),value:e,onSelect:e=>{n(e),i()}})))))}function R(e){return e.attributes.__internalWidgetId}function G(e,t){return{...e,attributes:{...e.attributes||{},__internalWidgetId:t}}}function U(e){const t=Object(w.subscribe)(()=>{var n,i;const a=null!==(n=null==e?void 0:e.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==n?n:[],o=null===(i=Object(w.select)(g.store).getWidgetTypes({per_page:-1}))||void 0===i?void 0:i.filter(e=>!a.includes(e.id));o&&(t(),Object(w.dispatch)(r.store).addBlockVariations("core/legacy-widget",o.map(e=>({name:e.id,title:e.name,description:e.description,attributes:e.is_multi?{idBase:e.id,instance:{}}:{id:e.id}}))))})}function q(){const{metadata:e,settings:t,name:n}=i;Object(r.registerBlockType)({name:n,...e},t)}},GRId:function(e,t){e.exports=window.wp.element},HSyU:function(e,t){e.exports=window.wp.blocks},K9lf:function(e,t){e.exports=window.wp.compose},Mmq9:function(e,t){e.exports=window.wp.url},TSYQ:function(e,t,n){var i;
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t<arguments.length;t++){var i=arguments[t];if(i){var a=typeof i;if("string"===a||"number"===a)e.push(i);else if(Array.isArray(i)){if(i.length){var o=r.apply(null,i);o&&e.push(o)}}else if("object"===a)if(i.toString===Object.prototype.toString)for(var s in i)n.call(i,s)&&i[s]&&e.push(s);else e.push(i.toString())}}return e.join(" ")}e.exports?(r.default=r,e.exports=r):void 0===(i=function(){return r}.apply(t,[]))||(e.exports=i)}()},Tqx9:function(e,t){e.exports=window.wp.primitives},YLtl:function(e,t){e.exports=window.lodash},axFQ:function(e,t){e.exports=window.wp.blockEditor},jZUy:function(e,t){e.exports=window.wp.coreData},l3Sj:function(e,t){e.exports=window.wp.i18n},onLe:function(e,t){e.exports=window.wp.notices},"tI+e":function(e,t){e.exports=window.wp.components},ywyh:function(e,t){e.exports=window.wp.apiFetch}});