From 330dc719ad724c2bc6da6baaa88bfb304d07f3b5 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Tue, 27 Aug 2024 00:08:55 -0400 Subject: [PATCH 01/16] Started work on saving datetimes as meta; fixed bug that called datetime endpoint many times on save rather than just once. --- build/blocks/event-date/index.asset.php | 2 +- build/blocks/event-date/index.js | 4 +- build/panels.asset.php | 2 +- build/panels.js | 4 +- includes/core/classes/class-event-setup.php | 45 +++++++++++++++++++++ includes/core/classes/class-event.php | 23 +++++++++++ src/components/DateTimeRange.js | 2 +- 7 files changed, 75 insertions(+), 7 deletions(-) diff --git a/build/blocks/event-date/index.asset.php b/build/blocks/event-date/index.asset.php index 0c0d6956d..830100ab8 100644 --- a/build/blocks/event-date/index.asset.php +++ b/build/blocks/event-date/index.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '0f22ffb28fbe7d004c9f'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '00019915fe473a5617eb'); diff --git a/build/blocks/event-date/index.js b/build/blocks/event-date/index.js index 9f7598a87..018fc8d1b 100644 --- a/build/blocks/event-date/index.js +++ b/build/blocks/event-date/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={110:(e,t,n)=>{const r=window.wp.blocks,s=window.moment;var i=n.n(s);const a=window.wp.i18n,o=window.wp.blockEditor,d=window.wp.components,c=window.wp.element,l=(e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:r});dispatchEvent(s)}},m=window.wp.data,p=window.wp.apiFetch;var u=n.n(p);function h(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function g(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),r=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[r]=t}function v(){const e=i().tz(f("eventDetails.dateTime.datetime_end"),S());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&i().tz(S()).valueOf()>e.valueOf()}function T(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),v()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const x=window.wp.date,j=window.ReactJSXRuntime,D="YYYY-MM-DDTHH:mm:ss",_="YYYY-MM-DD HH:mm:ss",w=i().tz(S()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(D),z=i().tz(w,S()).add(2,"hours").format(D);function b(){return k(f("settings.dateFormat"))+" "+k(f("settings.timeFormat"))}function S(e=f("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function y(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,n=e.replace(t,"$1");return n!==e?"UTC"+n+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_end"),S()).valueOf(),n=i().tz(e,S()).valueOf();n>=t&&E(i().tz(n,S()).add(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),h()}function E(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_start"),S()).valueOf(),n=i().tz(e,S()).valueOf();n<=t&&O(i().tz(n,S()).subtract(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),h()}function P(){const e=(0,m.select)("core/editor").isSavingPost(),t=(0,m.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&e&&!t&&u()({path:f("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:f("eventDetails.postId"),datetime_start:i().tz(f("eventDetails.dateTime.datetime_start"),S()).format(_),datetime_end:i().tz(f("eventDetails.dateTime.datetime_end"),S()).format(_),timezone:f("eventDetails.dateTime.timezone"),_wpnonce:f("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,m.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,m.select)("core/editor").getEditedPostAttribute("status")||v()||t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{l({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})}()}))}function k(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,n,r)=>{const s=r[n-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const C=e=>{const{isSelected:t}=e,n=t?"none":"block";return(0,j.jsxs)("div",{style:{position:"relative"},children:[e.children,(0,j.jsx)("div",{style:{position:"absolute",top:"0",right:"0",bottom:"0",left:"0",display:n}})]})},M=e=>{const{dateTimeStart:t}=e;return i().tz(t,S()).format(b())},Y=e=>{const{dateTimeEnd:t}=e;return i().tz(t,S()).format(b())},F=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>O(e,n),is12Hour:s})},$=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>E(e,n),is12Hour:s})},I=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,S()).format(D):w,g("eventDetails.dateTime.datetime_start",e),e}(),S()).format(D)),l({setDateTimeStart:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,a.__)("Start","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-start",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(F,{dateTimeStart:t,setDateTimeStart:n})})})]})})},H=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,S()).format(D):z,g("eventDetails.dateTime.datetime_end",e),e}(),S()).format(D)),l({setDateTimeEnd:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,a.__)("End","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-end",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(Y,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)($,{dateTimeEnd:t,setDateTimeEnd:n})})})]})})},G=e=>{const{timezone:t,setTimezone:n}=e,r=f("misc.timezoneChoices");return(0,c.useEffect)((()=>{n(f("eventDetails.dateTime.timezone"))}),[n]),(0,c.useEffect)((()=>{l({setTimezone:f("eventDetails.dateTime.timezone")})})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsx)(d.SelectControl,{label:(0,a.__)("Time Zone","gatherpress"),value:y(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,n=e.replace(t,"$1");if(n!==e){const r=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),n+r+s}return e}(e),n(e),g("eventDetails.dateTime.timezone",e),h()},children:Object.keys(r).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,j.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},N=()=>{const[e,t]=(0,c.useState)(),[n,r]=(0,c.useState)(),[s,i]=(0,c.useState)();return(0,m.subscribe)(P),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,a.__)("Date & time","gatherpress")}),(0,j.jsx)(I,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(H,{dateTimeEnd:n,setDateTimeEnd:r}),(0,j.jsx)(G,{timezone:s,setTimezone:i})]})},B=(e,t,n)=>{const r=k(f("settings.dateFormat")),s=k(f("settings.timeFormat")),o=f("settings.showTimezone")?"z":"",d=r+" "+s,c=S(n);let l=r+" "+s+" "+o;return i().tz(e,c).format(r)===i().tz(t,c).format(r)&&(l=s+" "+o),(0,a.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ -(0,a.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,c).format(d),i().tz(t,c).format(l),(m=S(m=c),(0,a.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(f("eventDetails.dateTime.timezone"))));var m},L=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"gatherpress/event-date","version":"1.0.1","title":"Event Date","category":"gatherpress","icon":"clock","example":{},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"}},"supports":{"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,r.registerBlockType)(L,{edit:()=>{const e=(0,o.useBlockProps)(),[t,n]=(0,c.useState)(w),[r,s]=(0,c.useState)(z),[i,a]=(0,c.useState)(S());return((e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t)),addEventListener(e,(e=>{r(e.detail)}),!1)}})({setDateTimeEnd:s,setDateTimeStart:n,setTimezone:a}),(0,j.jsx)("div",{...e,children:(0,j.jsx)(C,{children:(0,j.jsxs)(d.Flex,{justify:"normal",align:"center",gap:"4",children:[(0,j.jsx)(d.FlexItem,{display:"flex",className:"gatherpress-event-date__icon",children:(0,j.jsx)(d.Icon,{icon:"clock"})}),(0,j.jsx)(d.FlexItem,{children:B(t,r,i)}),"string"==typeof(0,m.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(o.InspectorControls,{children:(0,j.jsx)(d.PanelBody,{children:(0,j.jsx)(N,{})})})]})})})},save:()=>null})}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var a=1/0;for(l=0;l=i)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(o=!1,i0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[n,s,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[a,o,d]=n,c=0;if(a.some((t=>0!==e[t]))){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);if(d)var l=d(r)}for(t&&t(n);cr(110)));s=r.O(s)})(); \ No newline at end of file +(()=>{"use strict";var e,t={110:(e,t,n)=>{const r=window.wp.blocks,s=window.moment;var i=n.n(s);const a=window.wp.i18n,o=window.wp.blockEditor,d=window.wp.components,c=window.wp.element,l=(e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:r});dispatchEvent(s)}},m=window.wp.data,p=window.wp.apiFetch;var u=n.n(p);function h(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function g(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),r=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[r]=t}function v(){const e=i().tz(f("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&i().tz(b()).valueOf()>e.valueOf()}function T(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),v()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const x=window.wp.date,j=window.ReactJSXRuntime,D="YYYY-MM-DDTHH:mm:ss",_="YYYY-MM-DD HH:mm:ss",w=i().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(D),z=i().tz(w,b()).add(2,"hours").format(D);function S(){return P(f("settings.dateFormat"))+" "+P(f("settings.timeFormat"))}function b(e=f("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function y(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,n=e.replace(t,"$1");return n!==e?"UTC"+n+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_end"),b()).valueOf(),n=i().tz(e,b()).valueOf();n>=t&&E(i().tz(n,b()).add(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),h()}function E(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_start"),b()).valueOf(),n=i().tz(e,b()).valueOf();n<=t&&O(i().tz(n,b()).subtract(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),h()}function P(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,n,r)=>{const s=r[n-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const k=e=>{const{isSelected:t}=e,n=t?"none":"block";return(0,j.jsxs)("div",{style:{position:"relative"},children:[e.children,(0,j.jsx)("div",{style:{position:"absolute",top:"0",right:"0",bottom:"0",left:"0",display:n}})]})},C=e=>{const{dateTimeStart:t}=e;return i().tz(t,b()).format(S())},M=e=>{const{dateTimeEnd:t}=e;return i().tz(t,b()).format(S())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>O(e,n),is12Hour:s})},F=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>E(e,n),is12Hour:s})},$=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,b()).format(D):w,g("eventDetails.dateTime.datetime_start",e),e}(),b()).format(D)),l({setDateTimeStart:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,a.__)("Start","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-start",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(C,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(Y,{dateTimeStart:t,setDateTimeStart:n})})})]})})},I=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,b()).format(D):z,g("eventDetails.dateTime.datetime_end",e),e}(),b()).format(D)),l({setDateTimeEnd:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,a.__)("End","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-end",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)(F,{dateTimeEnd:t,setDateTimeEnd:n})})})]})})},H=e=>{const{timezone:t,setTimezone:n}=e,r=f("misc.timezoneChoices");return(0,c.useEffect)((()=>{n(f("eventDetails.dateTime.timezone"))}),[n]),(0,c.useEffect)((()=>{l({setTimezone:f("eventDetails.dateTime.timezone")})})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsx)(d.SelectControl,{label:(0,a.__)("Time Zone","gatherpress"),value:y(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,n=e.replace(t,"$1");if(n!==e){const r=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),n+r+s}return e}(e),n(e),g("eventDetails.dateTime.timezone",e),h()},children:Object.keys(r).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,j.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},G=()=>{const[e,t]=(0,c.useState)(),[n,r]=(0,c.useState)(),[s,o]=(0,c.useState)();return function(){const e=(0,m.select)("core/editor").isSavingPost(),t=(0,m.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&e&&!t&&u()({path:f("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:f("eventDetails.postId"),datetime_start:i().tz(f("eventDetails.dateTime.datetime_start"),b()).format(_),datetime_end:i().tz(f("eventDetails.dateTime.datetime_end"),b()).format(_),timezone:f("eventDetails.dateTime.timezone"),_wpnonce:f("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,m.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,m.select)("core/editor").getEditedPostAttribute("status")||v()||t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{l({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})}()}))}(),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,a.__)("Date & time","gatherpress")}),(0,j.jsx)($,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(I,{dateTimeEnd:n,setDateTimeEnd:r}),(0,j.jsx)(H,{timezone:s,setTimezone:o})]})},N=(e,t,n)=>{const r=P(f("settings.dateFormat")),s=P(f("settings.timeFormat")),o=f("settings.showTimezone")?"z":"",d=r+" "+s,c=b(n);let l=r+" "+s+" "+o;return i().tz(e,c).format(r)===i().tz(t,c).format(r)&&(l=s+" "+o),(0,a.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ +(0,a.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,c).format(d),i().tz(t,c).format(l),(m=b(m=c),(0,a.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(f("eventDetails.dateTime.timezone"))));var m},B=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"gatherpress/event-date","version":"1.0.1","title":"Event Date","category":"gatherpress","icon":"clock","example":{},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"}},"supports":{"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,r.registerBlockType)(B,{edit:()=>{const e=(0,o.useBlockProps)(),[t,n]=(0,c.useState)(w),[r,s]=(0,c.useState)(z),[i,a]=(0,c.useState)(b());return((e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t)),addEventListener(e,(e=>{r(e.detail)}),!1)}})({setDateTimeEnd:s,setDateTimeStart:n,setTimezone:a}),(0,j.jsx)("div",{...e,children:(0,j.jsx)(k,{children:(0,j.jsxs)(d.Flex,{justify:"normal",align:"center",gap:"4",children:[(0,j.jsx)(d.FlexItem,{display:"flex",className:"gatherpress-event-date__icon",children:(0,j.jsx)(d.Icon,{icon:"clock"})}),(0,j.jsx)(d.FlexItem,{children:N(t,r,i)}),"string"==typeof(0,m.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(o.InspectorControls,{children:(0,j.jsx)(d.PanelBody,{children:(0,j.jsx)(G,{})})})]})})})},save:()=>null})}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var a=1/0;for(l=0;l=i)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(o=!1,i0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[n,s,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[a,o,d]=n,c=0;if(a.some((t=>0!==e[t]))){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);if(d)var l=d(r)}for(t&&t(n);cr(110)));s=r.O(s)})(); \ No newline at end of file diff --git a/build/panels.asset.php b/build/panels.asset.php index 7110f9cf5..6357ae25a 100644 --- a/build/panels.asset.php +++ b/build/panels.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '052bad33e07326687357'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'fd8759db317610523313'); diff --git a/build/panels.js b/build/panels.js index 00efa2d63..8ddc4c9b5 100644 --- a/build/panels.js +++ b/build/panels.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,i=window.wp.editPost,a=window.moment;var o=e.n(a);const l=window.wp.apiFetch;var c=e.n(l);const d=window.wp.element;function u(){(0,s.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function m(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[n]=t}const g=window.wp.date,h=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",x=o().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),f=o().tz(x,b()).add(2,"hours").format(_);function j(){return w(m("settings.dateFormat"))+" "+w(m("settings.timeFormat"))}function b(e=m("eventDetails.dateTime.timezone")){return o().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function S(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function T(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_end"),b()).valueOf(),s=o().tz(e,b()).valueOf();s>=t&&P(o().tz(s,b()).add(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),u()}function P(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_start"),b()).valueOf(),s=o().tz(e,b()).valueOf();s<=t&&T(o().tz(s,b()).subtract(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),u()}function D(){const e=(0,s.select)("core/editor").isSavingPost(),n=(0,s.select)("core/editor").isAutosavingPost();k()&&e&&!n&&c()({path:m("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:m("eventDetails.postId"),datetime_start:o().tz(m("eventDetails.dateTime.datetime_start"),b()).format(v),datetime_end:o().tz(m("eventDetails.dateTime.datetime_end"),b()).format(v),timezone:m("eventDetails.dateTime.timezone"),_wpnonce:m("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",n=(0,s.dispatch)("core/notices");n.removeNotice(e),"publish"!==(0,s.select)("core/editor").getEditedPostAttribute("status")||z()||n.createNotice("success",(0,t.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{C({setOpen:!0})},label:(0,t.__)("Compose Message","gatherpress")}]})}()}))}function w(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e})).join("")}const C=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},E=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}};function k(){return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()}function z(){const e=o().tz(m("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&o().tz(b()).valueOf()>e.valueOf()}function N(){const e="gatherpress_event_past",n=(0,s.dispatch)("core/notices");n.removeNotice(e),z()&&n.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const y=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);i&&(a=m("settings.enableAnonymousRsvp"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},O=()=>(0,h.jsx)("section",{children:(0,h.jsx)(y,{})}),A=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);i&&(a=m("settings.enableInitialDecline"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:o,onChange:e=>{c(e)}})},M=()=>(0,h.jsx)("section",{children:(0,h.jsx)(A,{})}),F=e=>{const{dateTimeStart:t}=e;return o().tz(t,b()).format(j())},Y=e=>{const{dateTimeEnd:t}=e;return o().tz(t,b()).format(j())},L=e=>{const{dateTimeStart:t,setDateTimeStart:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>T(e,s),is12Hour:i})},R=e=>{const{dateTimeEnd:t,setDateTimeEnd:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>P(e,s),is12Hour:i})},I=e=>{const{dateTimeStart:s,setDateTimeStart:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""!==e?o().tz(e,b()).format(_):x,p("eventDetails.dateTime.datetime_start",e),e}(),b()).format(_)),C({setDateTimeStart:s}),N()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Start","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-start",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(F,{dateTimeStart:s})}),renderContent:()=>(0,h.jsx)(L,{dateTimeStart:s,setDateTimeStart:r})})})]})})},H=e=>{const{dateTimeEnd:s,setDateTimeEnd:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_end");return e=""!==e?o().tz(e,b()).format(_):f,p("eventDetails.dateTime.datetime_end",e),e}(),b()).format(_)),C({setDateTimeEnd:s}),N()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("End","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-end",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(Y,{dateTimeEnd:s})}),renderContent:()=>(0,h.jsx)(R,{dateTimeEnd:s,setDateTimeEnd:r})})})]})})},$=e=>{const{timezone:s,setTimezone:r}=e,i=m("misc.timezoneChoices");return(0,d.useEffect)((()=>{r(m("eventDetails.dateTime.timezone"))}),[r]),(0,d.useEffect)((()=>{C({setTimezone:m("eventDetails.dateTime.timezone")})})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:S(s),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,s=e.replace(t,"$1");if(s!==e){const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}return e}(e),r(e),p("eventDetails.dateTime.timezone",e),u()},children:Object.keys(i).map((e=>(0,h.jsx)("optgroup",{label:e,children:Object.keys(i[e]).map((t=>(0,h.jsx)("option",{value:t,children:i[e][t]},t)))},e)))})})},G=()=>{const[e,n]=(0,d.useState)(),[r,i]=(0,d.useState)(),[a,o]=(0,d.useState)();return(0,s.subscribe)(D),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("h3",{children:(0,t.__)("Date & time","gatherpress")}),(0,h.jsx)(I,{dateTimeStart:e,setDateTimeStart:n}),(0,h.jsx)(H,{dateTimeEnd:r,setDateTimeEnd:i}),(0,h.jsx)($,{timezone:a,setTimezone:o})]})},W=()=>(0,h.jsx)("section",{children:(0,h.jsx)(G,{})}),B=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);i&&(a=m("settings.maxGuestLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}})},V=()=>(0,h.jsx)("section",{children:(0,h.jsx)(B,{})}),J=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);i&&(a=m("settings.maxAttendanceLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,h.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},U=()=>(0,h.jsx)("section",{children:(0,h.jsx)(J,{})}),X=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!z()&&(0,h.jsxs)("section",{children:[(0,h.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,h.jsx)(n.Button,{variant:"secondary",onClick:()=>C({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),Z=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[a,o]=(0,d.useState)(i);return E({setOnlineEventLink:o},m("eventDetails.postId")),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:a,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),C({setOnlineEventLink:t},m("eventDetails.postId")),r()})(t)}})},q=()=>(0,h.jsx)("section",{children:(0,h.jsx)(Z,{})}),K=()=>{const[e,r]=(0,d.useState)(""),[i,a]=(0,d.useState)(""),[o,l]=(0,d.useState)(""),[c,u]=(0,d.useState)(""),[m,p]=(0,d.useState)(!1),[g,_]=(0,d.useState)(""),[v,x]=(0,d.useState)(""),[f,j]=(0,d.useState)(""),b=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:S}=(0,s.useDispatch)("core/editor"),T=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),P=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",T))),D=P?.slug.replace(/^_/,""),[w,E]=(0,d.useState)(""),k=T+":"+w,z=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:w})));(0,d.useEffect)((()=>{var e,s,n,i,o,c;let d={};if(w&&Array.isArray(z)){var m;const e=null!==(m=z[0]?.meta?.gatherpress_venue_information)&&void 0!==m?m:"{}";var p;e&&(d=JSON.parse(e),d.name=null!==(p=z[0]?.title.rendered)&&void 0!==p?p:"")}const g=null!==(e=d?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),h=null!==(s=d?.fullAddress)&&void 0!==s?s:"",v=null!==(n=d?.phoneNumber)&&void 0!==n?n:"",f=null!==(i=d?.website)&&void 0!==i?i:"",b=null!==(o=d?.latitude)&&void 0!==o?o:"0",S=null!==(c=d?.longitude)&&void 0!==c?c:"0";D&&E(D),j(k?String(k):""),r(g),a(h),l(v),u(f),_(b),x(S),C({setName:g,setFullAddress:h,setPhoneNumber:v,setWebsite:f,setLatitude:b,setLongitude:S,setIsOnlineEventTerm:"online-event"===w})}),[w,z,D,k]);let N=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return N?(N=N.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),N.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):N=[],(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:f,onChange:e=>{(e=>{j(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];b({_gatherpress_venue:t}),E(e[1]),S()})(e)},options:N})})},Q=()=>(0,h.jsx)("section",{children:(0,h.jsx)(K,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>k()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,h.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,h.jsx)(W,{}),(0,h.jsx)(Q,{}),(0,h.jsx)(q,{}),(0,h.jsx)(V,{}),(0,h.jsx)(U,{}),(0,h.jsx)(O,{}),(0,h.jsx)(M,{}),(0,h.jsx)(X,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const ee=window.wp.compose,te=()=>{var e,r,i;const a=(0,s.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...l,...e});a({meta:{gatherpress_venue_information:t}})};let l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));l=l?JSON.parse(l):{};const[c,u]=(0,d.useState)(null!==(e=l.fullAddress)&&void 0!==e?e:""),[m,p]=(0,d.useState)(null!==(r=l.phoneNumber)&&void 0!==r?r:""),[g,_]=(0,d.useState)(null!==(i=l.website)&&void 0!==i?i:"");E({setFullAddress:u,setPhoneNumber:p,setWebsite:_});const v=(0,d.useRef)(o),x=(0,d.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${c}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ -(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[c]),f=(0,ee.useDebounce)(x,300);return(0,d.useEffect)((()=>{v.current=o}),[o]),(0,d.useEffect)((()=>{f()}),[c,f]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:c,onChange:e=>{C({setFullAddress:e}),o({fullAddress:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:m,onChange:e=>{C({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:g,type:"url",onChange:e=>{C({setWebsite:e}),o({website:e})}})]})},se=()=>(0,h.jsx)("section",{children:(0,h.jsx)(te,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,h.jsx)(n.__experimentalVStack,{spacing:6,children:(0,h.jsx)(se,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,i=window.wp.editPost,a=window.moment;var o=e.n(a);const l=window.wp.apiFetch;var c=e.n(l);const d=window.wp.element;function u(){(0,s.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function m(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[n]=t}const g=window.wp.date,h=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",x=o().tz(S()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),f=o().tz(x,S()).add(2,"hours").format(_);function j(){return D(m("settings.dateFormat"))+" "+D(m("settings.timeFormat"))}function S(e=m("eventDetails.dateTime.timezone")){return o().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function b(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function T(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_end"),S()).valueOf(),s=o().tz(e,S()).valueOf();s>=t&&P(o().tz(s,S()).add(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),u()}function P(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_start"),S()).valueOf(),s=o().tz(e,S()).valueOf();s<=t&&T(o().tz(s,S()).subtract(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),u()}function D(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e})).join("")}const w=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},C=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}};function E(){return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()}function k(){const e=o().tz(m("eventDetails.dateTime.datetime_end"),S());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&o().tz(S()).valueOf()>e.valueOf()}function z(){const e="gatherpress_event_past",n=(0,s.dispatch)("core/notices");n.removeNotice(e),k()&&n.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const N=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);i&&(a=m("settings.enableAnonymousRsvp"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},y=()=>(0,h.jsx)("section",{children:(0,h.jsx)(N,{})}),O=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);i&&(a=m("settings.enableInitialDecline"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:o,onChange:e=>{c(e)}})},A=()=>(0,h.jsx)("section",{children:(0,h.jsx)(O,{})}),M=e=>{const{dateTimeStart:t}=e;return o().tz(t,S()).format(j())},F=e=>{const{dateTimeEnd:t}=e;return o().tz(t,S()).format(j())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>T(e,s),is12Hour:i})},L=e=>{const{dateTimeEnd:t,setDateTimeEnd:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>P(e,s),is12Hour:i})},R=e=>{const{dateTimeStart:s,setDateTimeStart:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""!==e?o().tz(e,S()).format(_):x,p("eventDetails.dateTime.datetime_start",e),e}(),S()).format(_)),w({setDateTimeStart:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Start","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-start",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(M,{dateTimeStart:s})}),renderContent:()=>(0,h.jsx)(Y,{dateTimeStart:s,setDateTimeStart:r})})})]})})},I=e=>{const{dateTimeEnd:s,setDateTimeEnd:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_end");return e=""!==e?o().tz(e,S()).format(_):f,p("eventDetails.dateTime.datetime_end",e),e}(),S()).format(_)),w({setDateTimeEnd:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("End","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-end",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(F,{dateTimeEnd:s})}),renderContent:()=>(0,h.jsx)(L,{dateTimeEnd:s,setDateTimeEnd:r})})})]})})},H=e=>{const{timezone:s,setTimezone:r}=e,i=m("misc.timezoneChoices");return(0,d.useEffect)((()=>{r(m("eventDetails.dateTime.timezone"))}),[r]),(0,d.useEffect)((()=>{w({setTimezone:m("eventDetails.dateTime.timezone")})})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:b(s),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,s=e.replace(t,"$1");if(s!==e){const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}return e}(e),r(e),p("eventDetails.dateTime.timezone",e),u()},children:Object.keys(i).map((e=>(0,h.jsx)("optgroup",{label:e,children:Object.keys(i[e]).map((t=>(0,h.jsx)("option",{value:t,children:i[e][t]},t)))},e)))})})},$=()=>{const[e,n]=(0,d.useState)(),[r,i]=(0,d.useState)(),[a,l]=(0,d.useState)();return function(){const e=(0,s.select)("core/editor").isSavingPost(),n=(0,s.select)("core/editor").isAutosavingPost();E()&&e&&!n&&c()({path:m("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:m("eventDetails.postId"),datetime_start:o().tz(m("eventDetails.dateTime.datetime_start"),S()).format(v),datetime_end:o().tz(m("eventDetails.dateTime.datetime_end"),S()).format(v),timezone:m("eventDetails.dateTime.timezone"),_wpnonce:m("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",n=(0,s.dispatch)("core/notices");n.removeNotice(e),"publish"!==(0,s.select)("core/editor").getEditedPostAttribute("status")||k()||n.createNotice("success",(0,t.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{w({setOpen:!0})},label:(0,t.__)("Compose Message","gatherpress")}]})}()}))}(),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("h3",{children:(0,t.__)("Date & time","gatherpress")}),(0,h.jsx)(R,{dateTimeStart:e,setDateTimeStart:n}),(0,h.jsx)(I,{dateTimeEnd:r,setDateTimeEnd:i}),(0,h.jsx)(H,{timezone:a,setTimezone:l})]})},G=()=>(0,h.jsx)("section",{children:(0,h.jsx)($,{})}),W=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);i&&(a=m("settings.maxGuestLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}})},B=()=>(0,h.jsx)("section",{children:(0,h.jsx)(W,{})}),V=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);i&&(a=m("settings.maxAttendanceLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,h.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},J=()=>(0,h.jsx)("section",{children:(0,h.jsx)(V,{})}),U=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!k()&&(0,h.jsxs)("section",{children:[(0,h.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,h.jsx)(n.Button,{variant:"secondary",onClick:()=>w({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),X=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[a,o]=(0,d.useState)(i);return C({setOnlineEventLink:o},m("eventDetails.postId")),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:a,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),w({setOnlineEventLink:t},m("eventDetails.postId")),r()})(t)}})},Z=()=>(0,h.jsx)("section",{children:(0,h.jsx)(X,{})}),q=()=>{const[e,r]=(0,d.useState)(""),[i,a]=(0,d.useState)(""),[o,l]=(0,d.useState)(""),[c,u]=(0,d.useState)(""),[m,p]=(0,d.useState)(!1),[g,_]=(0,d.useState)(""),[v,x]=(0,d.useState)(""),[f,j]=(0,d.useState)(""),S=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:b}=(0,s.useDispatch)("core/editor"),T=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),P=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",T))),D=P?.slug.replace(/^_/,""),[C,E]=(0,d.useState)(""),k=T+":"+C,z=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:C})));(0,d.useEffect)((()=>{var e,s,n,i,o,c;let d={};if(C&&Array.isArray(z)){var m;const e=null!==(m=z[0]?.meta?.gatherpress_venue_information)&&void 0!==m?m:"{}";var p;e&&(d=JSON.parse(e),d.name=null!==(p=z[0]?.title.rendered)&&void 0!==p?p:"")}const g=null!==(e=d?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),h=null!==(s=d?.fullAddress)&&void 0!==s?s:"",v=null!==(n=d?.phoneNumber)&&void 0!==n?n:"",f=null!==(i=d?.website)&&void 0!==i?i:"",S=null!==(o=d?.latitude)&&void 0!==o?o:"0",b=null!==(c=d?.longitude)&&void 0!==c?c:"0";D&&E(D),j(k?String(k):""),r(g),a(h),l(v),u(f),_(S),x(b),w({setName:g,setFullAddress:h,setPhoneNumber:v,setWebsite:f,setLatitude:S,setLongitude:b,setIsOnlineEventTerm:"online-event"===C})}),[C,z,D,k]);let N=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return N?(N=N.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),N.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):N=[],(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:f,onChange:e=>{(e=>{j(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];S({_gatherpress_venue:t}),E(e[1]),b()})(e)},options:N})})},K=()=>(0,h.jsx)("section",{children:(0,h.jsx)(q,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>E()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,h.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,h.jsx)(G,{}),(0,h.jsx)(K,{}),(0,h.jsx)(Z,{}),(0,h.jsx)(B,{}),(0,h.jsx)(J,{}),(0,h.jsx)(y,{}),(0,h.jsx)(A,{}),(0,h.jsx)(U,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const Q=window.wp.compose,ee=()=>{var e,r,i;const a=(0,s.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...l,...e});a({meta:{gatherpress_venue_information:t}})};let l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));l=l?JSON.parse(l):{};const[c,u]=(0,d.useState)(null!==(e=l.fullAddress)&&void 0!==e?e:""),[m,p]=(0,d.useState)(null!==(r=l.phoneNumber)&&void 0!==r?r:""),[g,_]=(0,d.useState)(null!==(i=l.website)&&void 0!==i?i:"");C({setFullAddress:u,setPhoneNumber:p,setWebsite:_});const v=(0,d.useRef)(o),x=(0,d.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${c}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ +(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[c]),f=(0,Q.useDebounce)(x,300);return(0,d.useEffect)((()=>{v.current=o}),[o]),(0,d.useEffect)((()=>{f()}),[c,f]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:c,onChange:e=>{w({setFullAddress:e}),o({fullAddress:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:m,onChange:e=>{w({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:g,type:"url",onChange:e=>{w({setWebsite:e}),o({website:e})}})]})},te=()=>(0,h.jsx)("section",{children:(0,h.jsx)(ee,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,h.jsx)(n.__experimentalVStack,{spacing:6,children:(0,h.jsx)(te,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file diff --git a/includes/core/classes/class-event-setup.php b/includes/core/classes/class-event-setup.php index 7a314fbc1..a47d65e6a 100644 --- a/includes/core/classes/class-event-setup.php +++ b/includes/core/classes/class-event-setup.php @@ -157,6 +157,51 @@ public function register_post_type(): void { */ public function register_post_meta(): void { $post_meta = array( + 'gatherpress_datetime_start' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_start_gmt' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_end' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_datetime_end_gmt' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), + 'gatherpress_timezone' => array( + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ), 'gatherpress_max_guest_limit' => array( 'auth_callback' => function () { return current_user_can( 'edit_posts' ); diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index 0de4c76b2..a9345e1d3 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -685,11 +685,34 @@ function ( $key ) { $fields, array( 'post_id' => $fields['post_id'] ) ); + delete_transient( sprintf( self::DATETIME_CACHE_KEY, $fields['post_id'] ) ); } else { $value = $wpdb->insert( $table, $fields ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery } + foreach ( $fields as $key => $field ) { + if ( 'post_id' === $key ) { + continue; + } + + $meta_key = sprintf( 'gatherpress_%s', sanitize_key( $key ) ); + + if ( ! empty( $exists ) ) { + update_post_meta( + $fields['post_id'], + $meta_key, + sanitize_text_field( $field ) + ); + } else { + add_post_meta( + $fields['post_id'], + $meta_key, + sanitize_text_field( $field ) + ); + } + } + return (bool) $value; } diff --git a/src/components/DateTimeRange.js b/src/components/DateTimeRange.js index e4d67ea8d..be6c0ec12 100644 --- a/src/components/DateTimeRange.js +++ b/src/components/DateTimeRange.js @@ -31,7 +31,7 @@ const DateTimeRange = () => { const [dateTimeEnd, setDateTimeEnd] = useState(); const [timezone, setTimezone] = useState(); - subscribe(saveDateTime); + saveDateTime(); return ( <> From 64e68cd5ec706d517ba944faeced782b266008f6 Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Mon, 2 Sep 2024 19:34:54 -0400 Subject: [PATCH 02/16] Started work on event date block updates. --- build/blocks/event-date/block.json | 65 +++++++++++++++++++-- build/blocks/event-date/index.asset.php | 2 +- build/blocks/event-date/index.js | 4 +- build/blocks/event-date/render.php | 11 +--- build/blocks/event-date/style-index-rtl.css | 2 +- build/blocks/event-date/style-index.css | 2 +- package-lock.json | 1 + package.json | 1 + src/blocks/event-date/block.json | 65 +++++++++++++++++++-- src/blocks/event-date/edit.js | 50 ++++++++-------- src/blocks/event-date/render.php | 11 +--- src/blocks/event-date/style.scss | 20 +------ 12 files changed, 160 insertions(+), 74 deletions(-) diff --git a/build/blocks/event-date/block.json b/build/blocks/event-date/block.json index 4dc2ac045..65b480895 100644 --- a/build/blocks/event-date/block.json +++ b/build/blocks/event-date/block.json @@ -1,12 +1,14 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "gatherpress/event-date", - "version": "1.0.1", + "version": "2.0.0", "title": "Event Date", "category": "gatherpress", "icon": "clock", - "example": {}, + "example": { + "viewportWidth": 350 + }, "description": "Displays the date and time for an event.", "attributes": { "eventEnd": { @@ -14,10 +16,65 @@ }, "eventStart": { "type": "string" + }, + "textAlign": { + "type": "string" + }, + "format": { + "type": "string" + }, + "isLink": { + "type": "boolean", + "default": false + }, + "displayType": { + "type": "string", + "default": "date" } }, "supports": { - "html": false + "html": false, + "color": { + "gradients": true, + "link": true, + "__experimentalDefaultControls": { + "background": true, + "text": true, + "link": true + } + }, + "spacing": { + "margin": true, + "padding": true + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalFontWeight": true, + "__experimentalFontStyle": true, + "__experimentalTextTransform": true, + "__experimentalTextDecoration": true, + "__experimentalLetterSpacing": true, + "__experimentalDefaultControls": { + "fontSize": true + } + }, + "interactivity": { + "clientNavigation": true + }, + "__experimentalBorder": { + "radius": true, + "color": true, + "width": true, + "style": true, + "__experimentalDefaultControls": { + "radius": true, + "color": true, + "width": true, + "style": true + } + } }, "textdomain": "gatherpress", "editorScript": "file:./index.js", diff --git a/build/blocks/event-date/index.asset.php b/build/blocks/event-date/index.asset.php index 830100ab8..1ca7b9f87 100644 --- a/build/blocks/event-date/index.asset.php +++ b/build/blocks/event-date/index.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '00019915fe473a5617eb'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => '6c56669f0eae86a3fd6c'); diff --git a/build/blocks/event-date/index.js b/build/blocks/event-date/index.js index 018fc8d1b..b92453b3e 100644 --- a/build/blocks/event-date/index.js +++ b/build/blocks/event-date/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={110:(e,t,n)=>{const r=window.wp.blocks,s=window.moment;var i=n.n(s);const a=window.wp.i18n,o=window.wp.blockEditor,d=window.wp.components,c=window.wp.element,l=(e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:r});dispatchEvent(s)}},m=window.wp.data,p=window.wp.apiFetch;var u=n.n(p);function h(){(0,m.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function f(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function g(e,t){if("object"!=typeof GatherPress)return;const n=e.split("."),r=n.pop();n.reduce(((e,t)=>{var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={}}),GatherPress)[r]=t}function v(){const e=i().tz(f("eventDetails.dateTime.datetime_end"),b());return"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&i().tz(b()).valueOf()>e.valueOf()}function T(){const e="gatherpress_event_past",t=(0,m.dispatch)("core/notices");t.removeNotice(e),v()&&t.createNotice("warning",(0,a.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const x=window.wp.date,j=window.ReactJSXRuntime,D="YYYY-MM-DDTHH:mm:ss",_="YYYY-MM-DD HH:mm:ss",w=i().tz(b()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(D),z=i().tz(w,b()).add(2,"hours").format(D);function S(){return P(f("settings.dateFormat"))+" "+P(f("settings.timeFormat"))}function b(e=f("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,a.__)("GMT","gatherpress")}function y(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,n=e.replace(t,"$1");return n!==e?"UTC"+n+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_end"),b()).valueOf(),n=i().tz(e,b()).valueOf();n>=t&&E(i().tz(n,b()).add(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),h()}function E(e,t=null){!function(e){const t=i().tz(f("eventDetails.dateTime.datetime_start"),b()).valueOf(),n=i().tz(e,b()).valueOf();n<=t&&O(i().tz(n,b()).subtract(2,"hours").format(D))}(e),g("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),h()}function P(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,n,r)=>{const s=r[n-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const k=e=>{const{isSelected:t}=e,n=t?"none":"block";return(0,j.jsxs)("div",{style:{position:"relative"},children:[e.children,(0,j.jsx)("div",{style:{position:"absolute",top:"0",right:"0",bottom:"0",left:"0",display:n}})]})},C=e=>{const{dateTimeStart:t}=e;return i().tz(t,b()).format(S())},M=e=>{const{dateTimeEnd:t}=e;return i().tz(t,b()).format(S())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>O(e,n),is12Hour:s})},F=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e,r=(0,x.getSettings)(),s=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(d.DateTimePicker,{currentDate:t,onChange:e=>E(e,n),is12Hour:s})},$=e=>{const{dateTimeStart:t,setDateTimeStart:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,b()).format(D):w,g("eventDetails.dateTime.datetime_start",e),e}(),b()).format(D)),l({setDateTimeStart:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,a.__)("Start","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-start",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(C,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(Y,{dateTimeStart:t,setDateTimeStart:n})})})]})})},I=e=>{const{dateTimeEnd:t,setDateTimeEnd:n}=e;return(0,c.useEffect)((()=>{n(i().tz(function(){let e=f("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,b()).format(D):z,g("eventDetails.dateTime.datetime_end",e),e}(),b()).format(D)),l({setDateTimeEnd:t}),T()})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsxs)(d.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,a.__)("End","gatherpress")})}),(0,j.jsx)(d.FlexItem,{children:(0,j.jsx)(d.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:n})=>(0,j.jsx)(d.Button,{id:"gatherpress-datetime-end",onClick:n,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)(F,{dateTimeEnd:t,setDateTimeEnd:n})})})]})})},H=e=>{const{timezone:t,setTimezone:n}=e,r=f("misc.timezoneChoices");return(0,c.useEffect)((()=>{n(f("eventDetails.dateTime.timezone"))}),[n]),(0,c.useEffect)((()=>{l({setTimezone:f("eventDetails.dateTime.timezone")})})),(0,j.jsx)(d.PanelRow,{children:(0,j.jsx)(d.SelectControl,{label:(0,a.__)("Time Zone","gatherpress"),value:y(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,n=e.replace(t,"$1");if(n!==e){const r=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),n+r+s}return e}(e),n(e),g("eventDetails.dateTime.timezone",e),h()},children:Object.keys(r).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(r[e]).map((t=>(0,j.jsx)("option",{value:t,children:r[e][t]},t)))},e)))})})},G=()=>{const[e,t]=(0,c.useState)(),[n,r]=(0,c.useState)(),[s,o]=(0,c.useState)();return function(){const e=(0,m.select)("core/editor").isSavingPost(),t=(0,m.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,m.select)("core/editor")?.getCurrentPostType()&&e&&!t&&u()({path:f("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:f("eventDetails.postId"),datetime_start:i().tz(f("eventDetails.dateTime.datetime_start"),b()).format(_),datetime_end:i().tz(f("eventDetails.dateTime.datetime_end"),b()).format(_),timezone:f("eventDetails.dateTime.timezone"),_wpnonce:f("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,m.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,m.select)("core/editor").getEditedPostAttribute("status")||v()||t.createNotice("success",(0,a.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{l({setOpen:!0})},label:(0,a.__)("Compose Message","gatherpress")}]})}()}))}(),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,a.__)("Date & time","gatherpress")}),(0,j.jsx)($,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(I,{dateTimeEnd:n,setDateTimeEnd:r}),(0,j.jsx)(H,{timezone:s,setTimezone:o})]})},N=(e,t,n)=>{const r=P(f("settings.dateFormat")),s=P(f("settings.timeFormat")),o=f("settings.showTimezone")?"z":"",d=r+" "+s,c=b(n);let l=r+" "+s+" "+o;return i().tz(e,c).format(r)===i().tz(t,c).format(r)&&(l=s+" "+o),(0,a.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ -(0,a.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,c).format(d),i().tz(t,c).format(l),(m=b(m=c),(0,a.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(f("eventDetails.dateTime.timezone"))));var m},B=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"gatherpress/event-date","version":"1.0.1","title":"Event Date","category":"gatherpress","icon":"clock","example":{},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"}},"supports":{"html":false},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,r.registerBlockType)(B,{edit:()=>{const e=(0,o.useBlockProps)(),[t,n]=(0,c.useState)(w),[r,s]=(0,c.useState)(z),[i,a]=(0,c.useState)(b());return((e,t="")=>{for(const[n,r]of Object.entries(e)){let e=n;t&&(e+="_"+String(t)),addEventListener(e,(e=>{r(e.detail)}),!1)}})({setDateTimeEnd:s,setDateTimeStart:n,setTimezone:a}),(0,j.jsx)("div",{...e,children:(0,j.jsx)(k,{children:(0,j.jsxs)(d.Flex,{justify:"normal",align:"center",gap:"4",children:[(0,j.jsx)(d.FlexItem,{display:"flex",className:"gatherpress-event-date__icon",children:(0,j.jsx)(d.Icon,{icon:"clock"})}),(0,j.jsx)(d.FlexItem,{children:N(t,r,i)}),"string"==typeof(0,m.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(o.InspectorControls,{children:(0,j.jsx)(d.PanelBody,{children:(0,j.jsx)(G,{})})})]})})})},save:()=>null})}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,n,s,i)=>{if(!n){var a=1/0;for(l=0;l=i)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(o=!1,i0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[n,s,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[a,o,d]=n,c=0;if(a.some((t=>0!==e[t]))){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);if(d)var l=d(r)}for(t&&t(n);cr(110)));s=r.O(s)})(); \ No newline at end of file +(()=>{"use strict";var e,t={3358:(e,t,r)=>{const n=window.wp.blocks,s=window.moment;var i=r.n(s);function a(e){var t,r,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var s=e.length;for(t=0;t{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t));const s=new CustomEvent(e,{detail:n});dispatchEvent(s)}},u=window.wp.data,f=window.wp.apiFetch;var h=r.n(f);function g(){(0,u.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function v(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function T(e,t){if("object"!=typeof GatherPress)return;const r=e.split("."),n=r.pop();r.reduce(((e,t)=>{var r;return null!==(r=e[t])&&void 0!==r?r:e[t]={}}),GatherPress)[n]=t}function x(){const e=i().tz(v("eventDetails.dateTime.datetime_end"),k());return"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&i().tz(k()).valueOf()>e.valueOf()}function _(){const e="gatherpress_event_past",t=(0,u.dispatch)("core/notices");t.removeNotice(e),x()&&t.createNotice("warning",(0,l.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const D=window.wp.date,j=window.ReactJSXRuntime,w="YYYY-MM-DDTHH:mm:ss",y="YYYY-MM-DD HH:mm:ss",z=i().tz(k()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(w),S=i().tz(z,k()).add(2,"hours").format(w);function b(){return P(v("settings.dateFormat"))+" "+P(v("settings.timeFormat"))}function k(e=v("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,l.__)("GMT","gatherpress")}function C(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,r=e.replace(t,"$1");return r!==e?"UTC"+r+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=i().tz(v("eventDetails.dateTime.datetime_end"),k()).valueOf(),r=i().tz(e,k()).valueOf();r>=t&&E(i().tz(r,k()).add(2,"hours").format(w))}(e),T("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),g()}function E(e,t=null){!function(e){const t=i().tz(v("eventDetails.dateTime.datetime_start"),k()).valueOf(),r=i().tz(e,k()).valueOf();r<=t&&O(i().tz(r,k()).subtract(2,"hours").format(w))}(e),T("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),g()}function P(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,r,n)=>{const s=n[r-1];return e in t&&"\\"!==s?t[e]:e})).join("")}const F=e=>{const{dateTimeStart:t}=e;return i().tz(t,k()).format(b())},M=e=>{const{dateTimeEnd:t}=e;return i().tz(t,k()).format(b())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e,n=(0,D.getSettings)(),s=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(c.DateTimePicker,{currentDate:t,onChange:e=>O(e,r),is12Hour:s})},$=e=>{const{dateTimeEnd:t,setDateTimeEnd:r}=e,n=(0,D.getSettings)(),s=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(c.DateTimePicker,{currentDate:t,onChange:e=>E(e,r),is12Hour:s})},A=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e;return(0,m.useEffect)((()=>{r(i().tz(function(){let e=v("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,k()).format(w):z,T("eventDetails.dateTime.datetime_start",e),e}(),k()).format(w)),p({setDateTimeStart:t}),_()})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsxs)(c.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,l.__)("Start","gatherpress")})}),(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:r})=>(0,j.jsx)(c.Button,{id:"gatherpress-datetime-start",onClick:r,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(F,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(Y,{dateTimeStart:t,setDateTimeStart:r})})})]})})},H=e=>{const{dateTimeEnd:t,setDateTimeEnd:r}=e;return(0,m.useEffect)((()=>{r(i().tz(function(){let e=v("eventDetails.dateTime.datetime_end");return e=""!==e?i().tz(e,k()).format(w):S,T("eventDetails.dateTime.datetime_end",e),e}(),k()).format(w)),p({setDateTimeEnd:t}),_()})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsxs)(c.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,l.__)("End","gatherpress")})}),(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:r})=>(0,j.jsx)(c.Button,{id:"gatherpress-datetime-end",onClick:r,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)($,{dateTimeEnd:t,setDateTimeEnd:r})})})]})})},L=e=>{const{timezone:t,setTimezone:r}=e,n=v("misc.timezoneChoices");return(0,m.useEffect)((()=>{r(v("eventDetails.dateTime.timezone"))}),[r]),(0,m.useEffect)((()=>{p({setTimezone:v("eventDetails.dateTime.timezone")})})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsx)(c.SelectControl,{label:(0,l.__)("Time Zone","gatherpress"),value:C(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,r=e.replace(t,"$1");if(r!==e){const n=e.replace(t,"$2").padStart(2,"0");let s=e.replace(t,"$3");return""===s&&(s=":00"),s=s.replace(".25",":15").replace(".5",":30").replace(".75",":45"),r+n+s}return e}(e),r(e),T("eventDetails.dateTime.timezone",e),g()},children:Object.keys(n).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(n[e]).map((t=>(0,j.jsx)("option",{value:t,children:n[e][t]},t)))},e)))})})},B=()=>{const[e,t]=(0,m.useState)(),[r,n]=(0,m.useState)(),[s,a]=(0,m.useState)();return function(){const e=(0,u.select)("core/editor").isSavingPost(),t=(0,u.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&e&&!t&&h()({path:v("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:v("eventDetails.postId"),datetime_start:i().tz(v("eventDetails.dateTime.datetime_start"),k()).format(y),datetime_end:i().tz(v("eventDetails.dateTime.datetime_end"),k()).format(y),timezone:v("eventDetails.dateTime.timezone"),_wpnonce:v("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communcation",t=(0,u.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,u.select)("core/editor").getEditedPostAttribute("status")||x()||t.createNotice("success",(0,l.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{p({setOpen:!0})},label:(0,l.__)("Compose Message","gatherpress")}]})}()}))}(),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,l.__)("Date & time","gatherpress")}),(0,j.jsx)(A,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(H,{dateTimeEnd:r,setDateTimeEnd:n}),(0,j.jsx)(L,{timezone:s,setTimezone:a})]})},I=(e,t,r)=>{const n=P(v("settings.dateFormat")),s=P(v("settings.timeFormat")),a=v("settings.showTimezone")?"z":"",o=n+" "+s,d=k(r);let c=n+" "+s+" "+a;return i().tz(e,d).format(n)===i().tz(t,d).format(n)&&(c=s+" "+a),(0,l.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ +(0,l.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,d).format(o),i().tz(t,d).format(c),(m=k(m=d),(0,l.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(v("eventDetails.dateTime.timezone"))));var m},N=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/event-date","version":"2.0.0","title":"Event Date","category":"gatherpress","icon":"clock","example":{"viewportWidth":350},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"},"textAlign":{"type":"string"},"format":{"type":"string"},"isLink":{"type":"boolean","default":false},"displayType":{"type":"string","default":"date"}},"supports":{"html":false,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"interactivity":{"clientNavigation":true},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,n.registerBlockType)(N,{edit:({attributes:{textAlign:e,format:t,isLink:r,displayType:n},setAttributes:s})=>{const[i,a]=(0,m.useState)(z),[l,p]=(0,m.useState)(S),[f,h]=(0,m.useState)(k()),g=(0,d.useBlockProps)({className:o({[`has-text-align-${e}`]:e})});return((e,t="")=>{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}})({setDateTimeEnd:p,setDateTimeStart:a,setTimezone:h}),(0,j.jsxs)("div",{...g,children:[(0,j.jsx)(d.BlockControls,{children:(0,j.jsx)(d.AlignmentToolbar,{value:e,onChange:e=>s({textAlign:e})})}),I(i,l,f),"string"==typeof(0,u.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(d.InspectorControls,{children:(0,j.jsx)(c.PanelBody,{children:(0,j.jsx)(B,{})})})]})},save:()=>null})}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.m=t,e=[],n.O=(t,r,s,i)=>{if(!r){var a=1/0;for(c=0;c=i)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(o=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[r,s,i]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var s,i,[a,o,l]=r,d=0;if(a.some((t=>0!==e[t]))){for(s in o)n.o(o,s)&&(n.m[s]=o[s]);if(l)var c=l(n)}for(t&&t(r);dn(3358)));s=n.O(s)})(); \ No newline at end of file diff --git a/build/blocks/event-date/render.php b/build/blocks/event-date/render.php index 7a7fe3979..7b01ff8ca 100644 --- a/build/blocks/event-date/render.php +++ b/build/blocks/event-date/render.php @@ -15,14 +15,5 @@ $gatherpress_event = new Event( get_the_ID() ); ?>
> -
-
-
-
-
-
- get_display_datetime() ); ?> -
-
-
+ get_display_datetime() ); ?>
diff --git a/build/blocks/event-date/style-index-rtl.css b/build/blocks/event-date/style-index-rtl.css index 1c5b2f552..21b123c2d 100644 --- a/build/blocks/event-date/style-index-rtl.css +++ b/build/blocks/event-date/style-index-rtl.css @@ -1 +1 @@ -.gatherpress-event-date__icon{align-items:flex-start;display:flex}.gatherpress-event-date__item{align-items:center;display:flex;gap:.75rem}.gatherpress-event-date__row{display:flex} +.wp-block-gatherpress-event-date{box-sizing:border-box} diff --git a/build/blocks/event-date/style-index.css b/build/blocks/event-date/style-index.css index 1c5b2f552..21b123c2d 100644 --- a/build/blocks/event-date/style-index.css +++ b/build/blocks/event-date/style-index.css @@ -1 +1 @@ -.gatherpress-event-date__icon{align-items:flex-start;display:flex}.gatherpress-event-date__item{align-items:center;display:flex;gap:.75rem}.gatherpress-event-date__row{display:flex} +.wp-block-gatherpress-event-date{box-sizing:border-box} diff --git a/package-lock.json b/package-lock.json index 4dd7f1f4f..92bbfcd24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@wordpress/plugins": "^7.4.0", "@wordpress/scripts": "^28.4.0", "classnames": "^2.5.1", + "clsx": "^2.1.1", "dotenv": "^16.4.5", "eslint": "^8.57.0", "eslint-plugin-import": "^2.29.1", diff --git a/package.json b/package.json index 691fd4762..50ec1ab47 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@wordpress/plugins": "^7.4.0", "@wordpress/scripts": "^28.4.0", "classnames": "^2.5.1", + "clsx": "^2.1.1", "dotenv": "^16.4.5", "eslint": "^8.57.0", "eslint-plugin-import": "^2.29.1", diff --git a/src/blocks/event-date/block.json b/src/blocks/event-date/block.json index 9ae6f03ec..1dcfd2132 100644 --- a/src/blocks/event-date/block.json +++ b/src/blocks/event-date/block.json @@ -1,12 +1,14 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "gatherpress/event-date", - "version": "1.0.1", + "version": "2.0.0", "title": "Event Date", "category": "gatherpress", "icon": "clock", - "example": {}, + "example": { + "viewportWidth": 350 + }, "description": "Displays the date and time for an event.", "attributes": { "eventEnd": { @@ -14,10 +16,65 @@ }, "eventStart": { "type": "string" + }, + "textAlign": { + "type": "string" + }, + "format": { + "type": "string" + }, + "isLink": { + "type": "boolean", + "default": false + }, + "displayType": { + "type": "string", + "default": "date" } }, "supports": { - "html": false + "html": false, + "color": { + "gradients": true, + "link": true, + "__experimentalDefaultControls": { + "background": true, + "text": true, + "link": true + } + }, + "spacing": { + "margin": true, + "padding": true + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalFontWeight": true, + "__experimentalFontStyle": true, + "__experimentalTextTransform": true, + "__experimentalTextDecoration": true, + "__experimentalLetterSpacing": true, + "__experimentalDefaultControls": { + "fontSize": true + } + }, + "interactivity": { + "clientNavigation": true + }, + "__experimentalBorder": { + "radius": true, + "color": true, + "width": true, + "style": true, + "__experimentalDefaultControls": { + "radius": true, + "color": true, + "width": true, + "style": true + } + } }, "textdomain": "gatherpress", "editorScript": "file:./index.js", diff --git a/src/blocks/event-date/edit.js b/src/blocks/event-date/edit.js index f20ecf1b8..d3b10d285 100644 --- a/src/blocks/event-date/edit.js +++ b/src/blocks/event-date/edit.js @@ -2,12 +2,13 @@ * External dependencies. */ import moment from 'moment'; +import clsx from 'clsx'; /** * WordPress dependencies. */ import { __, sprintf } from '@wordpress/i18n'; -import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import {AlignmentToolbar, BlockControls, InspectorControls, useBlockProps} from '@wordpress/block-editor'; import { Flex, FlexItem, Icon, PanelBody } from '@wordpress/components'; import { useState } from '@wordpress/element'; @@ -81,36 +82,37 @@ const displayDateTime = (start, end, tz) => { * @see {@link displayDateTime} - Function for formatting and displaying date and time. * @see {@link Listener} - Function for adding event listeners. */ -const Edit = () => { - const blockProps = useBlockProps(); +const Edit = ( { + attributes: { textAlign, format, isLink, displayType }, + setAttributes, +} ) => { const [dateTimeStart, setDateTimeStart] = useState(defaultDateTimeStart); const [dateTimeEnd, setDateTimeEnd] = useState(defaultDateTimeEnd); const [timezone, setTimezone] = useState(getTimeZone()); + const blockProps = useBlockProps( { + className: clsx( { + [ `has-text-align-${ textAlign }` ]: textAlign + } ), + } ); Listener({ setDateTimeEnd, setDateTimeStart, setTimezone }); return ( -
- - - - - - - {displayDateTime(dateTimeStart, dateTimeEnd, timezone)} - - {isSinglePostInEditor() && ( - - - - - - )} - - +
+ + setAttributes({textAlign: newAlign})} + /> + + {displayDateTime(dateTimeStart, dateTimeEnd, timezone)} + {isSinglePostInEditor() && ( + + + + + + )}
); }; diff --git a/src/blocks/event-date/render.php b/src/blocks/event-date/render.php index 7a7fe3979..7b01ff8ca 100644 --- a/src/blocks/event-date/render.php +++ b/src/blocks/event-date/render.php @@ -15,14 +15,5 @@ $gatherpress_event = new Event( get_the_ID() ); ?>
> -
-
-
-
-
-
- get_display_datetime() ); ?> -
-
-
+ get_display_datetime() ); ?>
diff --git a/src/blocks/event-date/style.scss b/src/blocks/event-date/style.scss index 3b5158b16..b26778114 100644 --- a/src/blocks/event-date/style.scss +++ b/src/blocks/event-date/style.scss @@ -1,18 +1,4 @@ -@import "../mixins"; - -.gatherpress-event-date { - &__icon { - align-items: flex-start; - display: flex; - } - - &__item { - align-items: center; - display: flex; - gap: 0.75rem; - } - - &__row { - display: flex; - } +.wp-block-gatherpress-event-date { + // This block has customizable padding, border-box makes that more predictable. + box-sizing: border-box; } From 4538e871eac78593e904e516e97712d4353b997a Mon Sep 17 00:00:00 2001 From: Mike Auteri Date: Sat, 7 Sep 2024 22:36:01 -0400 Subject: [PATCH 03/16] Started work on basic store. --- build/blocks/event-date/index.asset.php | 2 +- build/blocks/event-date/index.js | 4 +- build/panels.asset.php | 2 +- build/panels.js | 4 +- src/components/DateTime.js | 39 ++++- src/components/DateTimeEnd.js | 2 +- src/components/DateTimeRange.js | 17 ++- src/components/DateTimeStart.js | 2 +- .../event-settings/datetime-range/index.js | 4 +- src/stores/datetime.js | 137 ++++++++++++++++++ 10 files changed, 187 insertions(+), 26 deletions(-) create mode 100644 src/stores/datetime.js diff --git a/build/blocks/event-date/index.asset.php b/build/blocks/event-date/index.asset.php index bf99a18d5..442960fed 100644 --- a/build/blocks/event-date/index.asset.php +++ b/build/blocks/event-date/index.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => 'c5d1dd7fa090f699a15e'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n'), 'version' => 'f0fb8a9926d430696d2e'); diff --git a/build/blocks/event-date/index.js b/build/blocks/event-date/index.js index d79640a3b..e59126bb3 100644 --- a/build/blocks/event-date/index.js +++ b/build/blocks/event-date/index.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e,t={3358:(e,t,r)=>{const n=window.wp.blocks,i=window.moment;var s=r.n(i);function a(e){var t,r,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var i=e.length;for(t=0;t{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t));const i=new CustomEvent(e,{detail:n});dispatchEvent(i)}},u=window.wp.data,f=window.wp.apiFetch;var h=r.n(f);function g(){(0,u.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function v(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function T(e,t){if("object"!=typeof GatherPress)return;const r=e.split("."),n=r.pop();r.reduce(((e,t)=>{var r;return null!==(r=e[t])&&void 0!==r?r:e[t]={}}),GatherPress)[n]=t}function x(){const e=s().tz(v("eventDetails.dateTime.datetime_end"),k());return"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&s().tz(k()).valueOf()>e.valueOf()}function _(){const e="gatherpress_event_past",t=(0,u.dispatch)("core/notices");t.removeNotice(e),x()&&t.createNotice("warning",(0,l.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const D=window.wp.date,j=window.ReactJSXRuntime,w="YYYY-MM-DDTHH:mm:ss",y="YYYY-MM-DD HH:mm:ss",z=s().tz(k()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(w),S=s().tz(z,k()).add(2,"hours").format(w);function b(){return P(v("settings.dateFormat"))+" "+P(v("settings.timeFormat"))}function k(e=v("eventDetails.dateTime.timezone")){return s().tz.zone(e)?e:(0,l.__)("GMT","gatherpress")}function C(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,r=e.replace(t,"$1");return r!==e?"UTC"+r+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function O(e,t=null){!function(e){const t=s().tz(v("eventDetails.dateTime.datetime_end"),k()).valueOf(),r=s().tz(e,k()).valueOf();r>=t&&E(s().tz(r,k()).add(2,"hours").format(w))}(e),T("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),g()}function E(e,t=null){!function(e){const t=s().tz(v("eventDetails.dateTime.datetime_start"),k()).valueOf(),r=s().tz(e,k()).valueOf();r<=t&&O(s().tz(r,k()).subtract(2,"hours").format(w))}(e),T("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),g()}function P(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,r,n)=>{const i=n[r-1];return e in t&&"\\"!==i?t[e]:e})).join("")}const F=e=>{const{dateTimeStart:t}=e;return s().tz(t,k()).format(b())},M=e=>{const{dateTimeEnd:t}=e;return s().tz(t,k()).format(b())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e,n=(0,D.getSettings)(),i=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(c.DateTimePicker,{currentDate:t,onChange:e=>O(e,r),is12Hour:i})},$=e=>{const{dateTimeEnd:t,setDateTimeEnd:r}=e,n=(0,D.getSettings)(),i=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,j.jsx)(c.DateTimePicker,{currentDate:t,onChange:e=>E(e,r),is12Hour:i})},A=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e;return(0,m.useEffect)((()=>{r(s().tz(function(){let e=v("eventDetails.dateTime.datetime_start");return e=""!==e?s().tz(e,k()).format(w):z,T("eventDetails.dateTime.datetime_start",e),e}(),k()).format(w)),p({setDateTimeStart:t}),_()})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsxs)(c.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,l.__)("Start","gatherpress")})}),(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:r})=>(0,j.jsx)(c.Button,{id:"gatherpress-datetime-start",onClick:r,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(F,{dateTimeStart:t})}),renderContent:()=>(0,j.jsx)(Y,{dateTimeStart:t,setDateTimeStart:r})})})]})})},H=e=>{const{dateTimeEnd:t,setDateTimeEnd:r}=e;return(0,m.useEffect)((()=>{r(s().tz(function(){let e=v("eventDetails.dateTime.datetime_end");return e=""!==e?s().tz(e,k()).format(w):S,T("eventDetails.dateTime.datetime_end",e),e}(),k()).format(w)),p({setDateTimeEnd:t}),_()})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsxs)(c.Flex,{direction:"column",gap:"0",children:[(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,l.__)("End","gatherpress")})}),(0,j.jsx)(c.FlexItem,{children:(0,j.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:r})=>(0,j.jsx)(c.Button,{id:"gatherpress-datetime-end",onClick:r,"aria-expanded":e,isLink:!0,children:(0,j.jsx)(M,{dateTimeEnd:t})}),renderContent:()=>(0,j.jsx)($,{dateTimeEnd:t,setDateTimeEnd:r})})})]})})},L=e=>{const{timezone:t,setTimezone:r}=e,n=v("misc.timezoneChoices");return(0,m.useEffect)((()=>{r(v("eventDetails.dateTime.timezone"))}),[r]),(0,m.useEffect)((()=>{p({setTimezone:v("eventDetails.dateTime.timezone")})})),(0,j.jsx)(c.PanelRow,{children:(0,j.jsx)(c.SelectControl,{label:(0,l.__)("Time Zone","gatherpress"),value:C(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,r=e.replace(t,"$1");if(r!==e){const n=e.replace(t,"$2").padStart(2,"0");let i=e.replace(t,"$3");return""===i&&(i=":00"),i=i.replace(".25",":15").replace(".5",":30").replace(".75",":45"),r+n+i}return e}(e),r(e),T("eventDetails.dateTime.timezone",e),g()},children:Object.keys(n).map((e=>(0,j.jsx)("optgroup",{label:e,children:Object.keys(n[e]).map((t=>(0,j.jsx)("option",{value:t,children:n[e][t]},t)))},e)))})})},B=()=>{const[e,t]=(0,m.useState)(),[r,n]=(0,m.useState)(),[i,a]=(0,m.useState)();return function(){const e=(0,u.select)("core/editor").isSavingPost(),t=(0,u.select)("core/editor").isAutosavingPost();"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&e&&!t&&h()({path:v("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:v("eventDetails.postId"),datetime_start:s().tz(v("eventDetails.dateTime.datetime_start"),k()).format(y),datetime_end:s().tz(v("eventDetails.dateTime.datetime_end"),k()).format(y),timezone:v("eventDetails.dateTime.timezone"),_wpnonce:v("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communication",t=(0,u.dispatch)("core/notices");t.removeNotice(e),"publish"!==(0,u.select)("core/editor").getEditedPostAttribute("status")||x()||t.createNotice("success",(0,l.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{p({setOpen:!0})},label:(0,l.__)("Compose Message","gatherpress")}]})}()}))}(),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("h3",{children:(0,l.__)("Date & time","gatherpress")}),(0,j.jsx)(A,{dateTimeStart:e,setDateTimeStart:t}),(0,j.jsx)(H,{dateTimeEnd:r,setDateTimeEnd:n}),(0,j.jsx)(L,{timezone:i,setTimezone:a})]})},I=(e,t,r)=>{const n=P(v("settings.dateFormat")),i=P(v("settings.timeFormat")),a=v("settings.showTimezone")?"z":"",o=n+" "+i,d=k(r);let c=n+" "+i+" "+a;return s().tz(e,d).format(n)===s().tz(t,d).format(n)&&(c=i+" "+a),(0,l.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ -(0,l.__)("%1$s to %2$s %3$s","gatherpress"),s().tz(e,d).format(o),s().tz(t,d).format(c),(m=k(m=d),(0,l.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(v("eventDetails.dateTime.timezone"))));var m},N=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/event-date","version":"2.0.0","title":"Event Date","category":"gatherpress","icon":"clock","example":{"viewportWidth":350},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"},"textAlign":{"type":"string"},"format":{"type":"string"},"isLink":{"type":"boolean","default":false},"displayType":{"type":"string","default":"date"}},"supports":{"html":false,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"interactivity":{"clientNavigation":true},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,n.registerBlockType)(N,{edit:({attributes:{textAlign:e,format:t,isLink:r,displayType:n},setAttributes:i})=>{const[s,a]=(0,m.useState)(z),[l,p]=(0,m.useState)(S),[f,h]=(0,m.useState)(k()),g=(0,d.useBlockProps)({className:o({[`has-text-align-${e}`]:e})});return((e,t="")=>{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}})({setDateTimeEnd:p,setDateTimeStart:a,setTimezone:h}),(0,j.jsxs)("div",{...g,children:[(0,j.jsx)(d.BlockControls,{children:(0,j.jsx)(d.AlignmentToolbar,{value:e,onChange:e=>i({textAlign:e})})}),I(s,l,f),"string"==typeof(0,u.select)("core/editor")?.getCurrentPostType()&&(0,j.jsx)(d.InspectorControls,{children:(0,j.jsx)(c.PanelBody,{children:(0,j.jsx)(B,{})})})]})},save:()=>null})}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,n),s.exports}n.m=t,e=[],n.O=(t,r,i,s)=>{if(!r){var a=1/0;for(c=0;c=s)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(o=!1,s0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,i,s]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var i,s,[a,o,l]=r,d=0;if(a.some((t=>0!==e[t]))){for(i in o)n.o(o,i)&&(n.m[i]=o[i]);if(l)var c=l(n)}for(t&&t(r);dn(3358)));i=n.O(i)})(); \ No newline at end of file +(()=>{"use strict";var e,t={7311:(e,t,r)=>{const n=window.wp.blocks,a=window.moment;var i=r.n(a);function s(e){var t,r,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var a=e.length;for(t=0;t{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t));const a=new CustomEvent(e,{detail:n});dispatchEvent(a)}},u=window.wp.data,h=window.wp.apiFetch;var g=r.n(h);function T(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function f(e,t){if("object"!=typeof GatherPress)return;const r=e.split("."),n=r.pop();r.reduce(((e,t)=>{var r;return null!==(r=e[t])&&void 0!==r?r:e[t]={}}),GatherPress)[n]=t}const S=window.wp.date,E=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",D=i().tz(y()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),x=i().tz(D,y()).add(2,"hours").format(_);function y(e=T("eventDetails.dateTime.timezone")){return i().tz.zone(e)?e:(0,l.__)("GMT","gatherpress")}function w(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,r=e.replace(t,"$1");return r!==e?"UTC"+r+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function z(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,r,n)=>{const a=n[r-1];return e in t&&"\\"!==a?t[e]:e})).join("")}const j={datetimeStart:null,datetimeEnd:null,timezone:"UTC",isFetching:!1},b={setDatetimeStart:e=>({type:"SET_DATETIME_START",datetimeStart:e}),setDatetimeEnd:e=>({type:"SET_DATETIME_END",datetimeEnd:e}),setTimezone:e=>({type:"SET_TIMEZONE",timezone:e}),fetchEventDetails:()=>async e=>{e({type:"FETCH_EVENT_DETAILS_REQUEST"});try{const t=await g()({path:"/wp/v2/event/details"});e({type:"FETCH_EVENT_DETAILS_SUCCESS",datetimeStart:t.datetimeStart,datetimeEnd:t.datetimeEnd,timezone:t.timezone})}catch(t){e({type:"FETCH_EVENT_DETAILS_FAILURE",error:t})}},saveEventDetails:({datetimeStart:e,datetimeEnd:t,timezone:r})=>async n=>{console.log("Starting saveEventDetails");try{console.log("Making API call..."),await g()({path:T("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:T("eventDetails.postId"),datetime_start:i().tz(e,y()).format(v),datetime_end:i().tz(t,y()).format(v),timezone:r,_wpnonce:T("misc.nonce")}})}catch(e){console.log(e)}}},F=(e=j,t)=>{switch(t.type){case"SET_DATETIME_START":return{...e,datetimeStart:t.datetimeStart};case"SET_DATETIME_END":return{...e,datetimeEnd:t.datetimeEnd};case"SET_TIMEZONE":return{...e,timezone:t.timezone};case"SAVE_EVENT_DETAILS_SUCCESS":return{...e,isFetching:!1};case"SAVE_EVENT_DETAILS_FAILURE":return{...e,isFetching:!1,error:t.error};case"SET_FETCHING":return{...e,isFetching:t.isFetching};default:return e}};if(!(0,u.hasStore)("gatherpress/datetime")){const e=(0,u.createReduxStore)("gatherpress/datetime",{reducer:F,actions:b,selectors:{getDatetimeStart:e=>e.datetimeStart,getDatetimeEnd:e=>e.datetimeEnd,getTimezone:e=>e.timezone,isFetching:e=>e.isFetching}});(0,u.register)(e)}const C=e=>{const{dateTimeStart:t}=e;return i().tz(t,y()).format(z(T("settings.dateFormat"))+" "+z(T("settings.timeFormat")))},A=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e,n=(0,S.getSettings)(),a=/a(?!\\)/i.test(n.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join("")),{datetimeStart:i,datetimeEnd:s,timezone:o,isFetching:l}=(0,u.useSelect)((e=>({datetimeStart:e("gatherpress/datetime").getDatetimeStart(),datetimeEnd:e("gatherpress/datetime").getDatetimeEnd(),timezone:e("gatherpress/datetime").getTimezone(),isFetching:e("gatherpress/datetime").isFetching()}))),{saveEventDetails:d}=(0,u.useDispatch)("gatherpress/datetime");return(0,E.jsx)(E.Fragment,{children:l?(0,E.jsx)(c.Spinner,{}):(0,E.jsx)(c.DateTimePicker,{currentDate:t,onChange:e=>{d(e)},is12Hour:a})})},M=e=>{const{dateTimeStart:t,setDateTimeStart:r}=e;return(0,m.useEffect)((()=>{r(i().tz(function(){let e=T("eventDetails.dateTime.datetime_start");return e=""!==e?i().tz(e,y()).format(_):D,f("eventDetails.dateTime.datetime_start",e),e}(),y()).format(_)),p({setDateTimeStart:t}),function(){const e="gatherpress_event_past",t=(0,u.dispatch)("core/notices");t.removeNotice(e),function(){const e=i().tz(T("eventDetails.dateTime.datetime_end"),y());return"gatherpress_event"===(0,u.select)("core/editor")?.getCurrentPostType()&&i().tz(y()).valueOf()>e.valueOf()}()&&t.createNotice("warning",(0,l.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}()})),(0,E.jsx)(c.PanelRow,{children:(0,E.jsxs)(c.Flex,{direction:"row",gap:"0",children:[(0,E.jsx)(c.FlexItem,{children:(0,E.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,l.__)("Start","gatherpress")})}),(0,E.jsx)(c.FlexItem,{children:(0,E.jsx)(c.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:r})=>(0,E.jsx)(c.Button,{id:"gatherpress-datetime-start",onClick:r,"aria-expanded":e,isLink:!0,children:(0,E.jsx)(C,{dateTimeStart:t})}),renderContent:()=>(0,E.jsx)(A,{dateTimeStart:t,setDateTimeStart:r})})})]})})},k=e=>{const{timezone:t,setTimezone:r}=e,n=T("misc.timezoneChoices");return(0,m.useEffect)((()=>{r(T("eventDetails.dateTime.timezone"))}),[r]),(0,m.useEffect)((()=>{p({setTimezone:T("eventDetails.dateTime.timezone")})})),(0,E.jsx)(c.PanelRow,{children:(0,E.jsx)(c.SelectControl,{label:(0,l.__)("Time Zone","gatherpress"),value:w(t),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,r=e.replace(t,"$1");if(r!==e){const n=e.replace(t,"$2").padStart(2,"0");let a=e.replace(t,"$3");return""===a&&(a=":00"),a=a.replace(".25",":15").replace(".5",":30").replace(".75",":45"),r+n+a}return e}(e),r(e),f("eventDetails.dateTime.timezone",e),(0,u.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})},children:Object.keys(n).map((e=>(0,E.jsx)("optgroup",{label:e,children:Object.keys(n[e]).map((t=>(0,E.jsx)("option",{value:t,children:n[e][t]},t)))},e)))})})},O=()=>{const[e,t]=(0,m.useState)(),[r,n]=(0,m.useState)(),[a,i]=(0,m.useState)();return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("h3",{children:(0,l.__)("Date & time","gatherpress")}),(0,E.jsx)(M,{dateTimeStart:e,setDateTimeStart:t}),(0,E.jsx)(k,{timezone:a,setTimezone:i})]})},I=(e,t,r)=>{const n=z(T("settings.dateFormat")),a=z(T("settings.timeFormat")),s=T("settings.showTimezone")?"z":"",o=n+" "+a,d=y(r);let c=n+" "+a+" "+s;return i().tz(e,d).format(n)===i().tz(t,d).format(n)&&(c=a+" "+s),(0,l.sprintf)(/* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ /* translators: %1$s: datetime start, %2$s: datetime end, %3$s timezone. */ +(0,l.__)("%1$s to %2$s %3$s","gatherpress"),i().tz(e,d).format(o),i().tz(t,d).format(c),(m=y(m=d),(0,l.__)("GMT","gatherpress")!==m?"":function(e=""){return e.replace(":","")}(T("eventDetails.dateTime.timezone"))));var m},Y=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"gatherpress/event-date","version":"2.0.0","title":"Event Date","category":"gatherpress","icon":"clock","example":{"viewportWidth":350},"description":"Displays the date and time for an event.","attributes":{"eventEnd":{"type":"string"},"eventStart":{"type":"string"},"textAlign":{"type":"string"},"format":{"type":"string"},"isLink":{"type":"boolean","default":false},"displayType":{"type":"string","default":"date"}},"supports":{"html":false,"color":{"gradients":true,"link":true,"__experimentalDefaultControls":{"background":true,"text":true,"link":true}},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true,"__experimentalFontFamily":true,"__experimentalFontWeight":true,"__experimentalFontStyle":true,"__experimentalTextTransform":true,"__experimentalTextDecoration":true,"__experimentalLetterSpacing":true,"__experimentalDefaultControls":{"fontSize":true}},"interactivity":{"clientNavigation":true},"__experimentalBorder":{"radius":true,"color":true,"width":true,"style":true,"__experimentalDefaultControls":{"radius":true,"color":true,"width":true,"style":true}}},"textdomain":"gatherpress","editorScript":"file:./index.js","style":"file:./style-index.css","render":"file:./render.php"}');(0,n.registerBlockType)(Y,{edit:({attributes:{textAlign:e,format:t,isLink:r,displayType:n},setAttributes:a})=>{const[i,s]=(0,m.useState)(D),[l,p]=(0,m.useState)(x),[h,g]=(0,m.useState)(y()),T=(0,d.useBlockProps)({className:o({[`has-text-align-${e}`]:e})});return((e,t="")=>{for(const[r,n]of Object.entries(e)){let e=r;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}})({setDateTimeEnd:p,setDateTimeStart:s,setTimezone:g}),(0,E.jsxs)("div",{...T,children:[(0,E.jsx)(d.BlockControls,{children:(0,E.jsx)(d.AlignmentToolbar,{value:e,onChange:e=>a({textAlign:e})})}),I(i,l,h),"string"==typeof(0,u.select)("core/editor")?.getCurrentPostType()&&(0,E.jsx)(d.InspectorControls,{children:(0,E.jsx)(c.PanelBody,{children:(0,E.jsx)(O,{})})})]})},save:()=>null})}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.m=t,e=[],n.O=(t,r,a,i)=>{if(!r){var s=1/0;for(c=0;c=i)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(o=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[r,a,i]},n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={532:0,4:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,i,[s,o,l]=r,d=0;if(s.some((t=>0!==e[t]))){for(a in o)n.o(o,a)&&(n.m[a]=o[a]);if(l)var c=l(n)}for(t&&t(r);dn(7311)));a=n.O(a)})(); \ No newline at end of file diff --git a/build/panels.asset.php b/build/panels.asset.php index 2f54afde1..ef8080df2 100644 --- a/build/panels.asset.php +++ b/build/panels.asset.php @@ -1 +1 @@ - array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '1ddf43062a2ffa28200c'); + array('moment', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'a14392be224ed2e39487'); diff --git a/build/panels.js b/build/panels.js index 3d6b9dc60..2afbfab63 100644 --- a/build/panels.js +++ b/build/panels.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,i=window.wp.editPost,a=window.moment;var o=e.n(a);const l=window.wp.apiFetch;var c=e.n(l);const d=window.wp.element;function u(){(0,s.dispatch)("core/editor")?.editPost({meta:{_non_existing_meta:!0}})}function m(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}function p(e,t){if("object"!=typeof GatherPress)return;const s=e.split("."),n=s.pop();s.reduce(((e,t)=>{var s;return null!==(s=e[t])&&void 0!==s?s:e[t]={}}),GatherPress)[n]=t}const g=window.wp.date,h=window.ReactJSXRuntime,_="YYYY-MM-DDTHH:mm:ss",v="YYYY-MM-DD HH:mm:ss",x=o().tz(S()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(_),f=o().tz(x,S()).add(2,"hours").format(_);function j(){return D(m("settings.dateFormat"))+" "+D(m("settings.timeFormat"))}function S(e=m("eventDetails.dateTime.timezone")){return o().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}function b(e=""){const t=/^([+-])(\d{2}):(00|15|30|45)$/,s=e.replace(t,"$1");return s!==e?"UTC"+s+parseInt(e.replace(t,"$2")).toString()+e.replace(t,"$3").replace("00","").replace("15",".25").replace("30",".5").replace("45",".75"):e}function T(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_end"),S()).valueOf(),s=o().tz(e,S()).valueOf();s>=t&&P(o().tz(s,S()).add(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_start",e),"function"==typeof t&&t(e),u()}function P(e,t=null){!function(e){const t=o().tz(m("eventDetails.dateTime.datetime_start"),S()).valueOf(),s=o().tz(e,S()).valueOf();s<=t&&T(o().tz(s,S()).subtract(2,"hours").format(_))}(e),p("eventDetails.dateTime.datetime_end",e),null!==t&&t(e),u()}function D(e){const t={d:"DD",D:"ddd",j:"D",l:"dddd",N:"E",S:"o",w:"e",z:"DDD",W:"W",F:"MMMM",m:"MM",M:"MMM",n:"M",t:"",L:"",o:"YYYY",Y:"YYYY",y:"YY",a:"a",A:"A",B:"",g:"h",G:"H",h:"hh",H:"HH",i:"mm",s:"ss",u:"SSS",e:"zz",I:"",O:"",P:"",T:"",Z:"",c:"",r:"",U:"X"};return String(e).split("").map(((e,s,n)=>{const r=n[s-1];return e in t&&"\\"!==r?t[e]:e})).join("")}const w=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},C=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}};function E(){return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()}function k(){const e=o().tz(m("eventDetails.dateTime.datetime_end"),S());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&o().tz(S()).valueOf()>e.valueOf()}function z(){const e="gatherpress_event_past",n=(0,s.dispatch)("core/notices");n.removeNotice(e),k()&&n.createNotice("warning",(0,t.__)("This event has already passed.","gatherpress"),{id:e,isDismissible:!1})}const N=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);i&&(a=m("settings.enableAnonymousRsvp"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:o,onChange:e=>{c(e)}})},y=()=>(0,h.jsx)("section",{children:(0,h.jsx)(N,{})}),O=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);i&&(a=m("settings.enableInitialDecline"));const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:o,onChange:e=>{c(e)}})},A=()=>(0,h.jsx)("section",{children:(0,h.jsx)(O,{})}),M=e=>{const{dateTimeStart:t}=e;return o().tz(t,S()).format(j())},F=e=>{const{dateTimeEnd:t}=e;return o().tz(t,S()).format(j())},Y=e=>{const{dateTimeStart:t,setDateTimeStart:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>T(e,s),is12Hour:i})},L=e=>{const{dateTimeEnd:t,setDateTimeEnd:s}=e,r=(0,g.getSettings)(),i=/a(?!\\)/i.test(r.formats.time.toLowerCase().replace(/\\\\/g,"").split("").reverse().join(""));return(0,h.jsx)(n.DateTimePicker,{currentDate:t,onChange:e=>P(e,s),is12Hour:i})},R=e=>{const{dateTimeStart:s,setDateTimeStart:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_start");return e=""!==e?o().tz(e,S()).format(_):x,p("eventDetails.dateTime.datetime_start",e),e}(),S()).format(_)),w({setDateTimeStart:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-start",children:(0,t.__)("Start","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-start",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(M,{dateTimeStart:s})}),renderContent:()=>(0,h.jsx)(Y,{dateTimeStart:s,setDateTimeStart:r})})})]})})},I=e=>{const{dateTimeEnd:s,setDateTimeEnd:r}=e;return(0,d.useEffect)((()=>{r(o().tz(function(){let e=m("eventDetails.dateTime.datetime_end");return e=""!==e?o().tz(e,S()).format(_):f,p("eventDetails.dateTime.datetime_end",e),e}(),S()).format(_)),w({setDateTimeEnd:s}),z()})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsxs)(n.Flex,{direction:"column",gap:"0",children:[(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)("label",{htmlFor:"gatherpress-datetime-end",children:(0,t.__)("End","gatherpress")})}),(0,h.jsx)(n.FlexItem,{children:(0,h.jsx)(n.Dropdown,{popoverProps:{placement:"bottom-end"},renderToggle:({isOpen:e,onToggle:t})=>(0,h.jsx)(n.Button,{id:"gatherpress-datetime-end",onClick:t,"aria-expanded":e,isLink:!0,children:(0,h.jsx)(F,{dateTimeEnd:s})}),renderContent:()=>(0,h.jsx)(L,{dateTimeEnd:s,setDateTimeEnd:r})})})]})})},H=e=>{const{timezone:s,setTimezone:r}=e,i=m("misc.timezoneChoices");return(0,d.useEffect)((()=>{r(m("eventDetails.dateTime.timezone"))}),[r]),(0,d.useEffect)((()=>{w({setTimezone:m("eventDetails.dateTime.timezone")})})),(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Time Zone","gatherpress"),value:b(s),onChange:e=>{e=function(e=""){const t=/^UTC([+-])(\d+)(.\d+)?$/,s=e.replace(t,"$1");if(s!==e){const n=e.replace(t,"$2").padStart(2,"0");let r=e.replace(t,"$3");return""===r&&(r=":00"),r=r.replace(".25",":15").replace(".5",":30").replace(".75",":45"),s+n+r}return e}(e),r(e),p("eventDetails.dateTime.timezone",e),u()},children:Object.keys(i).map((e=>(0,h.jsx)("optgroup",{label:e,children:Object.keys(i[e]).map((t=>(0,h.jsx)("option",{value:t,children:i[e][t]},t)))},e)))})})},$=()=>{const[e,n]=(0,d.useState)(),[r,i]=(0,d.useState)(),[a,l]=(0,d.useState)();return function(){const e=(0,s.select)("core/editor").isSavingPost(),n=(0,s.select)("core/editor").isAutosavingPost();E()&&e&&!n&&c()({path:m("urls.eventRestApi")+"/datetime",method:"POST",data:{post_id:m("eventDetails.postId"),datetime_start:o().tz(m("eventDetails.dateTime.datetime_start"),S()).format(v),datetime_end:o().tz(m("eventDetails.dateTime.datetime_end"),S()).format(v),timezone:m("eventDetails.dateTime.timezone"),_wpnonce:m("misc.nonce")}}).then((()=>{!function(){const e="gatherpress_event_communication",n=(0,s.dispatch)("core/notices");n.removeNotice(e),"publish"!==(0,s.select)("core/editor").getEditedPostAttribute("status")||k()||n.createNotice("success",(0,t.__)("Send an event update to members via email?","gatherpress"),{id:e,isDismissible:!0,actions:[{onClick:()=>{w({setOpen:!0})},label:(0,t.__)("Compose Message","gatherpress")}]})}()}))}(),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("h3",{children:(0,t.__)("Date & time","gatherpress")}),(0,h.jsx)(R,{dateTimeStart:e,setDateTimeStart:n}),(0,h.jsx)(I,{dateTimeEnd:r,setDateTimeEnd:i}),(0,h.jsx)(H,{timezone:a,setTimezone:l})]})},G=()=>(0,h.jsx)("section",{children:(0,h.jsx)($,{})}),W=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);i&&(a=m("settings.maxGuestLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:o,min:0,max:5,onChange:e=>{c(e)}})},B=()=>(0,h.jsx)("section",{children:(0,h.jsx)(W,{})}),V=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let a=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);i&&(a=m("settings.maxAttendanceLimit")),!1===a&&(a=0);const[o,l]=(0,d.useState)(a),c=(0,d.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};l(t),e({meta:s}),r()}),[e,r]);return(0,d.useEffect)((()=>{i&&0!==a&&c(a)}),[i,a,c]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:o,min:0,onChange:e=>{c(e)}}),(0,h.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},J=()=>(0,h.jsx)("section",{children:(0,h.jsx)(V,{})}),U=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!k()&&(0,h.jsxs)("section",{children:[(0,h.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,h.jsx)(n.Button,{variant:"secondary",onClick:()=>w({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),X=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[a,o]=(0,d.useState)(i);return C({setOnlineEventLink:o},m("eventDetails.postId")),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:a,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),o(t),w({setOnlineEventLink:t},m("eventDetails.postId")),r()})(t)}})},Z=()=>(0,h.jsx)("section",{children:(0,h.jsx)(X,{})}),q=()=>{const[e,r]=(0,d.useState)(""),[i,a]=(0,d.useState)(""),[o,l]=(0,d.useState)(""),[c,u]=(0,d.useState)(""),[m,p]=(0,d.useState)(!1),[g,_]=(0,d.useState)(""),[v,x]=(0,d.useState)(""),[f,j]=(0,d.useState)(""),S=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:b}=(0,s.useDispatch)("core/editor"),T=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),P=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",T))),D=P?.slug.replace(/^_/,""),[C,E]=(0,d.useState)(""),k=T+":"+C,z=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:C})));(0,d.useEffect)((()=>{var e,s,n,i,o,c;let d={};if(C&&Array.isArray(z)){var m;const e=null!==(m=z[0]?.meta?.gatherpress_venue_information)&&void 0!==m?m:"{}";var p;e&&(d=JSON.parse(e),d.name=null!==(p=z[0]?.title.rendered)&&void 0!==p?p:"")}const g=null!==(e=d?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),h=null!==(s=d?.fullAddress)&&void 0!==s?s:"",v=null!==(n=d?.phoneNumber)&&void 0!==n?n:"",f=null!==(i=d?.website)&&void 0!==i?i:"",S=null!==(o=d?.latitude)&&void 0!==o?o:"0",b=null!==(c=d?.longitude)&&void 0!==c?c:"0";D&&E(D),j(k?String(k):""),r(g),a(h),l(v),u(f),_(S),x(b),w({setName:g,setFullAddress:h,setPhoneNumber:v,setWebsite:f,setLatitude:S,setLongitude:b,setIsOnlineEventTerm:"online-event"===C})}),[C,z,D,k]);let N=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return N?(N=N.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),N.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):N=[],(0,h.jsx)(n.PanelRow,{children:(0,h.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:f,onChange:e=>{(e=>{j(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];S({_gatherpress_venue:t}),E(e[1]),b()})(e)},options:N})})},K=()=>(0,h.jsx)("section",{children:(0,h.jsx)(q,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>E()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,h.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,h.jsx)(G,{}),(0,h.jsx)(K,{}),(0,h.jsx)(Z,{}),(0,h.jsx)(B,{}),(0,h.jsx)(J,{}),(0,h.jsx)(y,{}),(0,h.jsx)(A,{}),(0,h.jsx)(U,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const Q=window.wp.compose,ee=()=>{var e,r,i;const a=(0,s.useDispatch)("core/editor").editPost,o=e=>{const t=JSON.stringify({...l,...e});a({meta:{gatherpress_venue_information:t}})};let l=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));l=l?JSON.parse(l):{};const[c,u]=(0,d.useState)(null!==(e=l.fullAddress)&&void 0!==e?e:""),[m,p]=(0,d.useState)(null!==(r=l.phoneNumber)&&void 0!==r?r:""),[g,_]=(0,d.useState)(null!==(i=l.website)&&void 0!==i?i:"");C({setFullAddress:u,setPhoneNumber:p,setWebsite:_});const v=(0,d.useRef)(o),x=(0,d.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${c}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ -(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[c]),f=(0,Q.useDebounce)(x,300);return(0,d.useEffect)((()=>{v.current=o}),[o]),(0,d.useEffect)((()=>{f()}),[c,f]),(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:c,onChange:e=>{w({setFullAddress:e}),o({fullAddress:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:m,onChange:e=>{w({setPhoneNumber:e}),o({phoneNumber:e})}}),(0,h.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:g,type:"url",onChange:e=>{w({setWebsite:e}),o({website:e})}})]})},te=()=>(0,h.jsx)("section",{children:(0,h.jsx)(ee,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,h.jsx)(i.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,h.jsx)(n.__experimentalVStack,{spacing:6,children:(0,h.jsx)(te,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,s=window.wp.data,n=window.wp.components,r=window.wp.plugins,o=window.wp.editPost,i=window.moment;var a=e.n(i);window.wp.apiFetch;const l=window.wp.element;function u(e){if("object"==typeof GatherPress)return e.split(".").reduce(((e,t)=>e&&e[t]),GatherPress)}window.wp.date;const c=window.ReactJSXRuntime,d="YYYY-MM-DDTHH:mm:ss",g=a().tz(p()).add(1,"day").set("hour",18).set("minute",0).set("second",0).format(d);function p(e=u("eventDetails.dateTime.timezone")){return a().tz.zone(e)?e:(0,t.__)("GMT","gatherpress")}a().tz(g,p()).add(2,"hours").format(d);const h=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),o=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_anonymous_rsvp),[]);o&&(i=u("settings.enableAnonymousRsvp"));const[a,d]=(0,l.useState)(i),g=(0,l.useCallback)((t=>{const s={gatherpress_enable_anonymous_rsvp:Number(t)};d(t),e({meta:s}),r()}),[e,r]);return(0,l.useEffect)((()=>{o&&0!==i&&g(i)}),[o,i,g]),(0,c.jsx)(n.CheckboxControl,{label:(0,t.__)("Enable Anonymous RSVP","gatherpress"),checked:a,onChange:e=>{g(e)}})},m=()=>(0,c.jsx)("section",{children:(0,c.jsx)(h,{})}),_=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),o=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_enable_initial_decline),[]);o&&(i=u("settings.enableInitialDecline"));const[a,d]=(0,l.useState)(i),g=(0,l.useCallback)((t=>{const s={gatherpress_enable_initial_decline:Number(t)};d(t),e({meta:s}),r()}),[e,r]);return(0,l.useEffect)((()=>{o&&0!==i&&g(i)}),[o,i,g]),(0,c.jsx)(n.CheckboxControl,{label:(0,t.__)('Enable Immediate "Not Attending" Option for Attendees',"gatherpress"),checked:a,onChange:e=>{g(e)}})},v=()=>(0,c.jsx)("section",{children:(0,c.jsx)(_,{})}),x=()=>(0,c.jsx)("section",{}),b=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),o=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_guest_limit),[]);o&&(i=u("settings.maxGuestLimit")),!1===i&&(i=0);const[a,d]=(0,l.useState)(i),g=(0,l.useCallback)((t=>{const s={gatherpress_max_guest_limit:Number(t)};d(t),e({meta:s}),r()}),[e,r]);return(0,l.useEffect)((()=>{o&&0!==i&&g(i)}),[o,i,g]),(0,c.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Number of Guests","gatherpress"),value:a,min:0,max:5,onChange:e=>{g(e)}})},S=()=>(0,c.jsx)("section",{children:(0,c.jsx)(b,{})}),j=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),o=(0,s.useSelect)((e=>e("core/editor").isCleanNewPost()),[]);let i=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_max_attendance_limit),[]);o&&(i=u("settings.maxAttendanceLimit")),!1===i&&(i=0);const[a,d]=(0,l.useState)(i),g=(0,l.useCallback)((t=>{const s={gatherpress_max_attendance_limit:Number(t)};d(t),e({meta:s}),r()}),[e,r]);return(0,l.useEffect)((()=>{o&&0!==i&&g(i)}),[o,i,g]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.__experimentalNumberControl,{label:(0,t.__)("Maximum Attendance Limit","gatherpress"),value:a,min:0,onChange:e=>{g(e)}}),(0,c.jsx)("p",{className:"description",children:(0,t.__)("A value of 0 indicates no limit.","gatherpress")})]})},f=()=>(0,c.jsx)("section",{children:(0,c.jsx)(j,{})}),P=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t));const r=new CustomEvent(e,{detail:n});dispatchEvent(r)}},w=(e,t="")=>{for(const[s,n]of Object.entries(e)){let e=s;t&&(e+="_"+String(t)),addEventListener(e,(e=>{n(e.detail)}),!1)}},C=()=>"publish"===(0,s.select)("core/editor").getEditedPostAttribute("status")&&!function(){const e=a().tz(u("eventDetails.dateTime.datetime_end"),p());return"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&a().tz(p()).valueOf()>e.valueOf()}()&&(0,c.jsxs)("section",{children:[(0,c.jsx)("h3",{style:{marginBottom:"0.5rem"},children:(0,t.__)("Send an event update","gatherpress")}),(0,c.jsx)(n.Button,{variant:"secondary",onClick:()=>P({setOpen:!0}),children:(0,t.__)("Compose Message","gatherpress")})]}),E=()=>{const{editPost:e,unlockPostSaving:r}=(0,s.useDispatch)("core/editor"),o=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_online_event_link)),[i,a]=(0,l.useState)(o);return w({setOnlineEventLink:a},u("eventDetails.postId")),(0,c.jsx)(n.TextControl,{label:(0,t.__)("Online event link","gatherpress"),value:i,placeholder:(0,t.__)("Add link to online event","gatherpress"),onChange:t=>{(t=>{e({meta:{gatherpress_online_event_link:t}}),a(t),P({setOnlineEventLink:t},u("eventDetails.postId")),r()})(t)}})},N=()=>(0,c.jsx)("section",{children:(0,c.jsx)(E,{})}),k=()=>{const[e,r]=(0,l.useState)(""),[o,i]=(0,l.useState)(""),[a,u]=(0,l.useState)(""),[d,g]=(0,l.useState)(""),[p,h]=(0,l.useState)(!1),[m,_]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[b,S]=(0,l.useState)(""),j=(0,s.useDispatch)("core/editor").editPost,{unlockPostSaving:f}=(0,s.useDispatch)("core/editor"),w=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("_gatherpress_venue"))),C=(0,s.useSelect)((e=>e("core").getEntityRecord("taxonomy","_gatherpress_venue",w))),E=C?.slug.replace(/^_/,""),[N,k]=(0,l.useState)(""),y=w+":"+N,A=(0,s.useSelect)((e=>e("core").getEntityRecords("postType","gatherpress_venue",{per_page:1,slug:N})));(0,l.useEffect)((()=>{var e,s,n,o,a,l;let c={};if(N&&Array.isArray(A)){var d;const e=null!==(d=A[0]?.meta?.gatherpress_venue_information)&&void 0!==d?d:"{}";var p;e&&(c=JSON.parse(e),c.name=null!==(p=A[0]?.title.rendered)&&void 0!==p?p:"")}const h=null!==(e=c?.name)&&void 0!==e?e:(0,t.__)("No venue selected.","gatherpress"),m=null!==(s=c?.fullAddress)&&void 0!==s?s:"",v=null!==(n=c?.phoneNumber)&&void 0!==n?n:"",b=null!==(o=c?.website)&&void 0!==o?o:"",j=null!==(a=c?.latitude)&&void 0!==a?a:"0",f=null!==(l=c?.longitude)&&void 0!==l?l:"0";E&&k(E),S(y?String(y):""),r(h),i(m),u(v),g(b),_(j),x(f),P({setName:h,setFullAddress:m,setPhoneNumber:v,setWebsite:b,setLatitude:j,setLongitude:f,setIsOnlineEventTerm:"online-event"===N})}),[N,A,E,y]);let O=(0,s.useSelect)((e=>e("core").getEntityRecords("taxonomy","_gatherpress_venue",{per_page:-1,context:"view"})),[]);return O?(O=O.map((e=>({label:e.name,value:e.id+":"+e.slug.replace(/^_/,"")}))),O.unshift({value:":",label:(0,t.__)("Choose a venue","gatherpress")})):O=[],(0,c.jsx)(n.PanelRow,{children:(0,c.jsx)(n.SelectControl,{label:(0,t.__)("Venue Selector","gatherpress"),value:b,onChange:e=>{(e=>{S(e);const t=""!==(e=e.split(":"))[0]?[e[0]]:[];j({_gatherpress_venue:t}),k(e[1]),f()})(e)},options:O})})},y=()=>(0,c.jsx)("section",{children:(0,c.jsx)(k,{})});(0,r.registerPlugin)("gatherpress-event-settings",{render:()=>"gatherpress_event"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,c.jsx)(o.PluginDocumentSettingPanel,{name:"gatherpress-event-settings",title:(0,t.__)("Event settings","gatherpress"),initialOpen:!0,className:"gatherpress-event-settings",children:(0,c.jsxs)(n.__experimentalVStack,{spacing:6,children:[(0,c.jsx)(x,{}),(0,c.jsx)(y,{}),(0,c.jsx)(N,{}),(0,c.jsx)(S,{}),(0,c.jsx)(f,{}),(0,c.jsx)(m,{}),(0,c.jsx)(v,{}),(0,c.jsx)(C,{})]})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-event-settings/gatherpress-event-settings");const A=window.wp.compose,O=()=>{var e,r,o;const i=(0,s.useDispatch)("core/editor").editPost,a=e=>{const t=JSON.stringify({...u,...e});i({meta:{gatherpress_venue_information:t}})};let u=(0,s.useSelect)((e=>e("core/editor").getEditedPostAttribute("meta").gatherpress_venue_information));u=u?JSON.parse(u):{};const[d,g]=(0,l.useState)(null!==(e=u.fullAddress)&&void 0!==e?e:""),[p,h]=(0,l.useState)(null!==(r=u.phoneNumber)&&void 0!==r?r:""),[m,_]=(0,l.useState)(null!==(o=u.website)&&void 0!==o?o:"");w({setFullAddress:g,setPhoneNumber:h,setWebsite:_});const v=(0,l.useRef)(a),x=(0,l.useCallback)((()=>{let e=null,s=null;fetch(`https://nominatim.openstreetmap.org/search?q=${d}&format=geojson`).then((e=>{if(!e.ok)throw new Error((0,t.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */ +(0,t.__)("Network response was not ok %s","gatherpress"),e.statusText));return e.json()})).then((t=>{t.features.length>0&&(e=t.features[0].geometry.coordinates[1],s=t.features[0].geometry.coordinates[0]),v.current({latitude:e,longitude:s})}))}),[d]),b=(0,A.useDebounce)(x,300);return(0,l.useEffect)((()=>{v.current=a}),[a]),(0,l.useEffect)((()=>{b()}),[d,b]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.TextControl,{label:(0,t.__)("Full Address","gatherpress"),value:d,onChange:e=>{P({setFullAddress:e}),a({fullAddress:e})}}),(0,c.jsx)(n.TextControl,{label:(0,t.__)("Phone Number","gatherpress"),value:p,onChange:e=>{P({setPhoneNumber:e}),a({phoneNumber:e})}}),(0,c.jsx)(n.TextControl,{label:(0,t.__)("Website","gatherpress"),value:m,type:"url",onChange:e=>{P({setWebsite:e}),a({website:e})}})]})},D=()=>(0,c.jsx)("section",{children:(0,c.jsx)(O,{})});(0,r.registerPlugin)("gatherpress-venue-settings",{render:()=>"gatherpress_venue"===(0,s.select)("core/editor")?.getCurrentPostType()&&(0,c.jsx)(o.PluginDocumentSettingPanel,{name:"gatherpress-venue-settings",title:(0,t.__)("Venue settings","gatherpress"),initialOpen:!0,className:"gatherpress-venue-settings",children:(0,c.jsx)(n.__experimentalVStack,{spacing:6,children:(0,c.jsx)(D,{})})})}),(0,s.dispatch)("core/edit-post").toggleEditorPanelOpened("gatherpress-venue-settings/gatherpress-venue-settings")})(); \ No newline at end of file diff --git a/src/components/DateTime.js b/src/components/DateTime.js index 8321d7d44..5a95ff2f7 100644 --- a/src/components/DateTime.js +++ b/src/components/DateTime.js @@ -2,8 +2,10 @@ * WordPress dependencies. */ import { getSettings } from '@wordpress/date'; -import { DateTimePicker } from '@wordpress/components'; +import {DateTimePicker, Spinner} from '@wordpress/components'; import moment from 'moment'; +// import { setDatetimeStart, setDatetimeEnd, setTimezone, saveEventDetails } from '../stores/datetime'; +import '../stores/datetime'; /** * Internal dependencies. @@ -14,6 +16,8 @@ import { dateTimeLabelFormat, getTimeZone, } from '../helpers/datetime'; +import {useDispatch, useSelect} from '@wordpress/data'; +import {useEffect} from '@wordpress/element'; /** * Formats the provided start date and time according to the specified label format @@ -78,13 +82,32 @@ export const DateTimeStartPicker = (props) => { .join('') ); - return ( - updateDateTimeStart(date, setDateTimeStart)} - is12Hour={is12HourTime} - /> - ); + const { datetimeStart, datetimeEnd, timezone, isFetching } = useSelect((select) => ({ + datetimeStart: select('gatherpress/datetime').getDatetimeStart(), + datetimeEnd: select('gatherpress/datetime').getDatetimeEnd(), + timezone: select('gatherpress/datetime').getTimezone(), + isFetching: select('gatherpress/datetime').isFetching(), + })); + + // Get dispatch function from the store + // const dispatch = useDispatch('gatherpress/datetime'); + const { saveEventDetails } = useDispatch('gatherpress/datetime'); + +return ( + <> + {isFetching ? ( + + ) : ( + { + saveEventDetails(value); // Dispatch the action to update datetimeStart + }} + is12Hour={is12HourTime} + /> + )} + +); }; /** diff --git a/src/components/DateTimeEnd.js b/src/components/DateTimeEnd.js index 03ee9fa0d..6d79dca46 100644 --- a/src/components/DateTimeEnd.js +++ b/src/components/DateTimeEnd.js @@ -64,7 +64,7 @@ const DateTimeEnd = (props) => { return ( - +