forked from Uniswap/token-lists
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
discourse-local-dates-3d6e4bc02e4952710b91a53202bb79df0e357173e5c0d82ec38fe0b3db7373a3.br.js.download
129 lines (127 loc) Β· 32.7 KB
/
discourse-local-dates-3d6e4bc02e4952710b91a53202bb79df0e357173e5c0d82ec38fe0b3db7373a3.br.js.download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
define("discourse/plugins/discourse-local-dates/discourse/components/modal/local-dates-create",["exports","@ember/component","@ember/object","@ember/object/computed","@ember/runloop","discourse/lib/computed","discourse/lib/local-dates","discourse/lib/text","discourse-common/config/environment","discourse-common/utils/decorators","discourse-i18n","discourse/plugins/discourse-local-dates/lib/local-date-markup-generator","@ember/template-factory"],(function(e,t,o,a,n,i,r,s,l,d,c,m,u){"use strict"
var f,p,h,g,z,_,b,T,v,y,w,D,O,P,L,F,j
function C(e,t,o,a,n){var i={}
return Object.keys(a).forEach((function(e){i[e]=a[e]})),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=o.slice().reverse().reduce((function(o,a){return a(e,t,o)||o}),i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(e,t,i),i=null),i}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0
const S=(0,u.createTemplateFactory)({id:"BjnsQKXJ",block:'[[[8,[39,0],[[24,0,"discourse-local-dates-create-modal -large"]],[["@title","@closeModal"],[[28,[37,1],["discourse_local_dates.title"],null],[30,1]]],[["body","footer"],[[[[1,"\\n "],[10,0],[14,0,"form"],[12],[1,"\\n"],[41,[30,0,["isValid"]],[[[41,[30,0,["timezoneIsDifferentFromUserTimezone"]],[[[1," "],[10,0],[14,0,"preview alert alert-info"],[12],[1,"\\n "],[1,[28,[35,1],["discourse_local_dates.create.form.current_timezone"],null]],[1,"\\n "],[10,"b"],[12],[1,[30,0,["formattedCurrentUserTimezone"]]],[13],[1,[30,0,["currentPreview"]]],[1,"\\n "],[13],[1,"\\n"]],[]],null]],[]],[[[1," "],[10,0],[14,0,"validation-error alert alert-error"],[12],[1,"\\n "],[1,[28,[35,1],["discourse_local_dates.create.form.invalid_date"],null]],[1,"\\n "],[13],[1,"\\n"]],[]]],[1,"\\n "],[1,[30,0,["computeDate"]]],[1,"\\n\\n "],[10,0],[14,0,"date-time-configuration"],[12],[1,"\\n "],[10,0],[14,0,"inputs-panel"],[12],[1,"\\n "],[10,0],[15,0,[29,["date-time-control from\\n ",[52,[30,0,["fromSelected"]],"is-selected"],"\\n ",[52,[30,0,["fromFilled"]],"is-filled"]]]],[12],[1,"\\n "],[1,[28,[35,3],["calendar-alt"],null]],[1,"\\n "],[8,[39,4],[[24,1,"from-date-time"],[24,0,"date-time"],[24,"autofocus",""]],[["@action","@translatedLabel"],[[30,0,["focusFrom"]],[30,0,["formattedFrom"]]]],null],[1,"\\n "],[13],[1,"\\n\\n "],[10,0],[15,0,[29,["date-time-control to\\n ",[52,[30,0,["toSelected"]],"is-selected"],"\\n ",[52,[30,0,["toFilled"]],"is-filled"]]]],[12],[1,"\\n "],[1,[28,[35,3],["calendar-alt"],null]],[1,"\\n "],[8,[39,4],[[24,0,"date-time"]],[["@action","@translatedLabel"],[[30,0,["focusTo"]],[30,0,["formattedTo"]]]],null],[1,"\\n"],[41,[30,0,["toFilled"]],[[[1," "],[8,[39,4],[[24,0,"delete-to-date"]],[["@action","@icon"],[[30,0,["eraseToDateTime"]],"times"]],null],[1,"\\n"]],[]],null],[1," "],[13],[1,"\\n\\n"],[41,[30,0,["site","desktopView"]],[[[1," "],[8,[39,5],null,[["@options","@value","@onChange"],[[28,[37,6],null,[["icon"],["globe"]]],[30,0,["timezone"]],[28,[37,7],[[28,[37,8],[[30,0,["timezone"]]],null]],null]]],null],[1,"\\n"]],[]],null],[1," "],[13],[1,"\\n\\n "],[10,0],[14,0,"picker-panel"],[12],[1,"\\n "],[8,[39,9],null,[["@datePickerId","@date","@time","@minDate","@timeFormat","@dateFormat","@onChangeDate","@onChangeTime"],["local-date-create-form",[30,0,["selectedDate"]],[30,0,["selectedTime"]],[30,0,["minDate"]],[30,0,["timeFormat"]],[30,0,["dateFormat"]],[30,0,["changeSelectedDate"]],[30,0,["changeSelectedTime"]]]],null],[1,"\\n "],[13],[1,"\\n\\n"],[41,[30,0,["site","mobileView"]],[[[1," "],[8,[39,5],null,[["@value","@options","@onChange"],[[30,0,["timezone"]],[28,[37,6],null,[["icon"],["globe"]]],[28,[37,7],[[28,[37,8],[[30,0,["timezone"]]],null]],null]]],null],[1,"\\n"]],[]],null],[1," "],[13],[1,"\\n\\n"],[41,[30,0,["advancedMode"]],[[[1," "],[10,0],[14,0,"advanced-options"],[12],[1,"\\n"],[41,[51,[30,0,["isRange"]]],[[[1," "],[10,0],[14,0,"control-group recurrence"],[12],[1,"\\n "],[10,"label"],[14,0,"control-label"],[12],[1,"\\n "],[1,[28,[35,1],["discourse_local_dates.create.form.recurring_title"],null]],[1,"\\n "],[13],[1,"\\n "],[10,2],[12],[1,[28,[35,11],[[28,[37,1],["discourse_local_dates.create.form.recurring_description"],null]],null]],[13],[1,"\\n "],[10,0],[14,0,"controls"],[12],[1,"\\n "],[8,[39,12],[[24,0,"recurrence-input"]],[["@content","@value","@onChange","@options"],[[30,0,["recurringOptions"]],[30,0,["recurring"]],[28,[37,7],[[28,[37,8],[[30,0,["recurring"]]],null]],null],[28,[37,6],null,[["none"],["discourse_local_dates.create.form.recurring_none"]]]]],null],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n"]],[]],null],[1,"\\n "],[10,0],[14,0,"control-group timezones"],[12],[1,"\\n "],[10,"label"],[12],[1,[28,[35,1],["discourse_local_dates.create.form.timezones_title"],null]],[13],[1,"\\n "],[10,2],[12],[1,[28,[35,1],["discourse_local_dates.create.form.timezones_description"],null]],[13],[1,"\\n "],[10,0],[14,0,"controls"],[12],[1,"\\n "],[8,[39,13],[[24,0,"timezones-input"]],[["@valueProperty","@nameProperty","@content","@value","@options"],[null,null,[30,0,["allTimezones"]],[30,0,["timezones"]],[28,[37,6],null,[["allowAny","maximum"],[false,5]]]]],null],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n\\n "],[10,0],[14,0,"control-group format"],[12],[1,"\\n "],[10,"label"],[12],[1,[28,[35,1],["discourse_local_dates.create.form.format_title"],null]],[13],[1,"\\n "],[10,2],[12],[1,"\\n "],[1,[28,[35,1],["discourse_local_dates.create.form.format_description"],null]],[1,"\\n "],[10,3],[14,"target","_blank"],[14,6,"https://momentjs.com/docs/#/parsing/string-format/"],[14,"rel","noopener noreferrer"],[12],[1,"\\n "],[1,[28,[35,3],["question-circle"],null]],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n "],[10,0],[14,0,"controls"],[12],[1,"\\n "],[8,[39,14],[[24,0,"format-input"]],[["@value"],[[30,0,["format"]]]],null],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n "],[10,0],[14,0,"control-group"],[12],[1,"\\n "],[10,"ul"],[14,0,"formats"],[12],[1,"\\n"],[42,[28,[37,16],[[28,[37,16],[[30,0,["previewedFormats"]]],null]],null],null,[[[1," "],[10,"li"],[14,0,"format"],[12],[1,"\\n "],[11,3],[24,0,"moment-format"],[24,6,""],[4,[38,17],["click",[28,[37,7],[[30,0,["updateFormat"]],[30,2,["format"]]],null]],null],[12],[1,"\\n "],[1,[30,2,["format"]]],[1,"\\n "],[13],[1,"\\n "],[10,1],[14,0,"previewed-format"],[12],[1,"\\n "],[1,[30,2,["preview"]]],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n"]],[2]],null],[1," "],[13],[1,"\\n "],[13],[1,"\\n "],[13],[1,"\\n"]],[]],null],[1," "],[13],[1,"\\n "]],[]],[[[1,"\\n\\n"],[41,[30,0,["isValid"]],[[[1," "],[8,[39,4],[[24,0,"btn-primary"]],[["@action","@label"],[[30,0,["save"]],"discourse_local_dates.create.form.insert"]],null],[1,"\\n"]],[]],null],[1,"\\n "],[8,[39,4],[[24,0,"btn-flat"]],[["@action","@translatedLabel"],[[30,0,["cancel"]],[28,[37,1],["cancel"],null]]],null],[1,"\\n\\n "],[8,[39,4],[[24,0,"btn-default advanced-mode-btn"]],[["@action","@icon","@label"],[[30,0,["toggleAdvancedMode"]],"cog",[30,0,["toggleModeBtnLabel"]]]],null],[1,"\\n "]],[]]]]]],["@closeModal","previewedFormat"],false,["d-modal","i18n","if","d-icon","d-button","timezone-input","hash","fn","mut","calendar-date-time-input","unless","html-safe","combo-box","multi-select","text-field","each","-track-array","on"]]',moduleName:"discourse/plugins/discourse-local-dates/discourse/components/modal/local-dates-create.hbs",isStrictMode:!1})
e.default=(0,t.setComponentTemplate)(S,t.default.extend((f=(0,d.observes)("computedConfig.{from,to,options}","options","isValid","isRange"),p=(0,d.debounce)(l.INPUT_DELAY),h=(0,d.default)("date","toDate","toTime"),g=(0,d.default)("computedConfig","isRange"),z=(0,d.default)("date","time","isRange","options.{format,timezone}"),_=(0,d.default)("toDate","toTime","isRange","options.{timezone,format}"),b=(0,d.default)("recurring","timezones","timezone","format"),T=(0,d.default)("fromConfig.{date}","toConfig.{date}","options.{recurring,timezones,timezone,format}"),v=(0,d.default)("currentUserTimezone"),y=(0,d.default)("formats"),w=(0,d.default)("advancedMode"),D=(0,d.default)("computedConfig.{from,to,options}","options","isValid","isRange"),O=(0,d.default)("fromConfig.dateTime"),P=(0,d.default)("toConfig.dateTime","toSelected"),L=(0,d.default)("fromSelected","toSelected"),F=(0,d.default)("fromSelected","toSelected"),j={timeFormat:"HH:mm:ss",dateFormat:"YYYY-MM-DD",dateTimeFormat:"YYYY-MM-DD HH:mm:ss",date:null,toDate:null,time:null,toTime:null,format:null,formats:null,recurring:null,advancedMode:!1,timezone:null,fromSelected:null,fromFilled:(0,a.notEmpty)("date"),toSelected:null,toFilled:(0,a.notEmpty)("toDate"),init(){this._super(...arguments),this._picker=null,this.setProperties({timezones:[],formats:(this.siteSettings.discourse_local_dates_default_formats||"").split("|").filter((e=>e)),timezone:this.currentUserTimezone,date:moment().format(this.dateFormat)})},didInsertElement(){this._super(...arguments),this.send("focusFrom")},configChanged(){this._renderPreview()},async _renderPreview(){if(this.markup){const e=await(0,s.cook)(this.markup)
this.set("currentPreview",e),(0,n.schedule)("afterRender",(()=>{(0,r.applyLocalDates)(document.querySelectorAll(".preview .discourse-local-date"),this.siteSettings)}))}},isRange:(e,t,o)=>e&&(t||o),isValid(e,t){const o=e.from
if(!e.from.dateTime||!e.from.dateTime.isValid())return!1
if(t){const t=e.to
if(!t.dateTime||!t.dateTime.isValid()||t.dateTime.diff(o.dateTime)<0)return!1}return!0},fromConfig(e,t,a){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}
const i=!t
let r
r=i?moment.tz(e,n.timezone):moment.tz(`${e} ${t}`,n.timezone),i||(t=r.format(this.timeFormat))
let s=n.format
return i&&this.formats.includes(s)&&(s="LL"),o.default.create({date:r.format(this.dateFormat),time:t,dateTime:r,format:s,range:!!a&&"start"})},toConfig(e,t,a){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}
const i=!t
let r
t&&!e&&(e=moment().format(this.dateFormat)),r=i?moment.tz(e,n.timezone).endOf("day"):moment.tz(`${e} ${t}`,n.timezone),i||(t=r.format(this.timeFormat))
let s=n.format
return i&&this.formats.includes(s)&&(s="LL"),o.default.create({date:r.format(this.dateFormat),time:t,dateTime:r,format:s,range:!!a&&"end"})},options:(e,t,a,n)=>o.default.create({recurring:e,timezones:t,timezone:a,format:n}),computedConfig:(e,t,a)=>o.default.create({from:e,to:t,options:a}),currentUserTimezone(){return this.currentUser.user_option.timezone||moment.tz.guess()},allTimezones:()=>moment.tz.names(),timezoneIsDifferentFromUserTimezone:(0,i.propertyNotEqual)("currentUserTimezone","options.timezone"),formattedCurrentUserTimezone:e=>e.replace("_"," ").replace("Etc/","").replace("/",", "),previewedFormats:e=>e.map((e=>({format:e,preview:moment().format(e)}))),recurringOptions(){const e="discourse_local_dates.create.form.recurring"
return[{name:c.default.t(`${e}.every_day`),id:"1.days"},{name:c.default.t(`${e}.every_week`),id:"1.weeks"},{name:c.default.t(`${e}.every_two_weeks`),id:"2.weeks"},{name:c.default.t(`${e}.every_month`),id:"1.months"},{name:c.default.t(`${e}.every_two_months`),id:"2.months"},{name:c.default.t(`${e}.every_three_months`),id:"3.months"},{name:c.default.t(`${e}.every_six_months`),id:"6.months"},{name:c.default.t(`${e}.every_year`),id:"1.years"}]},_generateDateMarkup:(e,t,o,a)=>(0,m.default)(e,t,o,a),toggleModeBtnLabel:e=>e?"discourse_local_dates.create.form.simple_mode":"discourse_local_dates.create.form.advanced_mode",markup(e,t,o,a){let n
return o&&e.from&&(n=e.to&&e.to.range?this._generateDateMarkup(e.from,t,a,e.to):this._generateDateMarkup(e.from,t,a)),n},formattedFrom:e=>e.format("LLLL"),formattedTo(e,t){const o=t?" ":c.default.t("discourse_local_dates.create.form.until")
return e.isValid()?e.format("LLLL"):o},updateFormat(e,t){t?.preventDefault(),this.set("format",e)},selectedDate(e){return e?this.date:this.toDate},selectedTime(e){return e?this.time:this.toTime},changeSelectedDate(e){this.fromSelected?this.set("date",e):this.set("toDate",e)},changeSelectedTime(e){this.fromSelected?this.set("time",e):this.set("toTime",e)},eraseToDateTime(){this.setProperties({toDate:null,toTime:null}),this.focusFrom()},focusFrom(){this.setProperties({fromSelected:!0,toSelected:!1,minDate:null})},focusTo(){this.setProperties({toSelected:!0,fromSelected:!1,minDate:this.get("fromConfig.date")})},toggleAdvancedMode(){this.toggleProperty("advancedMode")},save(){const e=this.markup
e&&(this.closeModal(),this.model.insertDate(e))},cancel(){this.closeModal()}},C(j,"configChanged",[f],Object.getOwnPropertyDescriptor(j,"configChanged"),j),C(j,"_renderPreview",[p],Object.getOwnPropertyDescriptor(j,"_renderPreview"),j),C(j,"isRange",[h],Object.getOwnPropertyDescriptor(j,"isRange"),j),C(j,"isValid",[g],Object.getOwnPropertyDescriptor(j,"isValid"),j),C(j,"fromConfig",[z],Object.getOwnPropertyDescriptor(j,"fromConfig"),j),C(j,"toConfig",[_],Object.getOwnPropertyDescriptor(j,"toConfig"),j),C(j,"options",[b],Object.getOwnPropertyDescriptor(j,"options"),j),C(j,"computedConfig",[T],Object.getOwnPropertyDescriptor(j,"computedConfig"),j),C(j,"currentUserTimezone",[d.default],Object.getOwnPropertyDescriptor(j,"currentUserTimezone"),j),C(j,"allTimezones",[d.default],Object.getOwnPropertyDescriptor(j,"allTimezones"),j),C(j,"formattedCurrentUserTimezone",[v],Object.getOwnPropertyDescriptor(j,"formattedCurrentUserTimezone"),j),C(j,"previewedFormats",[y],Object.getOwnPropertyDescriptor(j,"previewedFormats"),j),C(j,"recurringOptions",[d.default],Object.getOwnPropertyDescriptor(j,"recurringOptions"),j),C(j,"toggleModeBtnLabel",[w],Object.getOwnPropertyDescriptor(j,"toggleModeBtnLabel"),j),C(j,"markup",[D],Object.getOwnPropertyDescriptor(j,"markup"),j),C(j,"formattedFrom",[O],Object.getOwnPropertyDescriptor(j,"formattedFrom"),j),C(j,"formattedTo",[P],Object.getOwnPropertyDescriptor(j,"formattedTo"),j),C(j,"updateFormat",[o.action],Object.getOwnPropertyDescriptor(j,"updateFormat"),j),C(j,"selectedDate",[L],Object.getOwnPropertyDescriptor(j,"selectedDate"),j),C(j,"selectedTime",[F],Object.getOwnPropertyDescriptor(j,"selectedTime"),j),C(j,"changeSelectedDate",[o.action],Object.getOwnPropertyDescriptor(j,"changeSelectedDate"),j),C(j,"changeSelectedTime",[o.action],Object.getOwnPropertyDescriptor(j,"changeSelectedTime"),j),C(j,"eraseToDateTime",[o.action],Object.getOwnPropertyDescriptor(j,"eraseToDateTime"),j),C(j,"focusFrom",[o.action],Object.getOwnPropertyDescriptor(j,"focusFrom"),j),C(j,"focusTo",[o.action],Object.getOwnPropertyDescriptor(j,"focusTo"),j),C(j,"toggleAdvancedMode",[o.action],Object.getOwnPropertyDescriptor(j,"toggleAdvancedMode"),j),C(j,"save",[o.action],Object.getOwnPropertyDescriptor(j,"save"),j),C(j,"cancel",[o.action],Object.getOwnPropertyDescriptor(j,"cancel"),j),j)))})),define("discourse/plugins/discourse-local-dates/initializers/discourse-local-dates",["exports","@ember/service","@ember/template","discourse/lib/download-calendar","discourse/lib/plugin-api","discourse/lib/to-markdown","discourse-common/lib/icon-library","discourse-common/utils/decorators","discourse-i18n","discourse/plugins/discourse-local-dates/lib/local-date-markup-generator","discourse/plugins/discourse-local-dates/discourse/components/modal/local-dates-create","discourse/plugins/discourse-local-dates/lib/local-date-builder"],(function(e,t,o,a,n,i,r,s,l,d,c,m){"use strict"
var u
function f(e,t){if(!t.discourse_local_dates_enabled)return
const o=moment.tz.guess()
e.forEach(((e,a,n)=>{const i=h(e,t)
if("to"===e.attributes["data-range"]?.value&&0!==a&&"from"===n[a-1].attributes["data-range"]?.value){(function(e,t){if(!e.attributes["data-time"]||!t.attributes["data-time"])return!1
const o=e.attributes["data-timezone"].value,a=moment(p(e)).tz(o),n=moment(p(t)).tz(o)
return a.isSame(n,"day")})(n[a-1],e)&&(i.sameLocalDayAsFrom=!0)}const r=new m.default(i,o).build()
e.innerText="",e.insertAdjacentHTML("beforeend",`\n <svg class="fa d-icon d-icon-globe-americas svg-icon" xmlns="http://www.w3.org/2000/svg">\n <use href="#globe-americas"></use>\n </svg>\n <span class="relative-time">${r.formatted}</span>\n `),e.setAttribute("aria-label",r.textPreview)
const s=["cooked-date"]
r.pastEvent&&s.push("past"),e.classList.add(...s)}))}function p(e){return`${e.attributes["data-date"].value}T${e.attributes["data-time"].value}`}function h(e,t){const o={},a=e.dataset
return 2===z(e).length&&(o.duration=function(e){const[t,o]=z(e).map((e=>e.dataset)),a=moment(`${t.date} ${t.time||""}`.trim()),n=moment(`${o.date} ${o.time||""}`.trim()).diff(a,"minutes")
return e.dataset===t?n:-n}(e)),o.time=a.time,o.date=a.date,o.recurring=a.recurring,o.timezones=(a.timezones||t.discourse_local_dates_default_timezones||"Etc/UTC").split("|").filter(Boolean),o.timezone=a.timezone,o.calendar="on"===(a.calendar||"on"),o.displayedTimezone=a.displayedTimezone,o.format=a.format||(o.time?"LLL":"LL"),o.countdown=a.countdown,o}function g(e){const t={}
return t.time=e.attributes["data-time"],t.date=e.attributes["data-date"],t.recurring=e.attributes["data-recurring"],t.timezones=e.attributes["data-timezones"],t.timezone=e.attributes["data-timezone"],t.calendar="on"===(e.attributes["data-calendar"]||"on"),t.displayedTimezone=e.attributes["data-displayed-timezone"],t.format=e.attributes["data-format"],t.countdown=e.attributes["data-countdown"],t.range=e.attributes["data-range"],t}function z(e){return e.parentElement?e.dataset.range?function(e){const t=[],o=Array.from(e.parentElement.children).filter((e=>e.dataset.range))
for(;o.length>0;)t.push(o.splice(0,2))
return t}(e).find((t=>t.includes(e))):[e]:[]}function _(e){const o=e.container.lookup("service:site-settings"),a=l.default.t("discourse_local_dates.default_title",{site_name:o.title})
e.decorateCookedElement(((e,t)=>{const n=e.querySelectorAll(".discourse-local-date")
f(n,o)
const i=t?.getModel()?.topic?.title
n.forEach((e=>{e.dataset.title=e.dataset.title||i||a}))})),e.onToolbarCreate((e=>{e.addButton({title:"discourse_local_dates.title",id:"local-dates",group:"extras",icon:"calendar-alt",sendAction:t=>e.context.send("insertDiscourseLocalDate",t)})})),e.modifyClass("component:d-editor",{modal:(0,t.service)(),pluginId:"discourse-local-dates",actions:{insertDiscourseLocalDate(e){this.modal.show(c.default,{model:{insertDate:t=>{e.addText(t)}}})}}}),(0,i.addTextDecorateCallback)((function(e,t,o,a){if(a.discourseLocalDateStartRangeOpts&&t?.attributes.class?.includes("discourse-local-date")&&"β"===e)return""})),(0,i.addTagDecorateCallback)((function(){if(this.element.attributes.class?.includes("discourse-local-date")){if(this.metadata.discourseLocalDateStartRangeOpts){const e=this.metadata.discourseLocalDateStartRangeOpts,t=g(this.element),o=(0,d.default)({date:e.date,time:e.time,format:e.format},t,!0,{date:t.date,time:t.time,format:t.format})
return this.prefix=o,this.metadata.discourseLocalDateStartRangeOpts=null,""}if("true"===this.element.attributes["data-range"]||"from"===this.element.attributes["data-range"]||"to"===this.element.attributes["data-range"])return this.metadata.discourseLocalDateStartRangeOpts=g(this.element),""
const e=g(this.element),t=(0,d.default)({date:e.date,time:e.time,format:e.format},e,!1)
return this.prefix=t,""}}))}function b(e,t){const o=h(e,t),a=new m.default(o,moment.tz.guess()).build().previews.map((e=>{const t=document.createElement("div")
t.classList.add("preview"),e.current&&t.classList.add("current")
const o=document.createElement("span")
o.classList.add("timezone"),o.innerText=e.timezone,t.appendChild(o)
const a=document.createElement("span")
return a.classList.add("date-time"),a.innerHTML=e.formatted,t.appendChild(a),t})),n=document.createElement("div")
n.classList.add("locale-dates-previews"),a.forEach((e=>n.appendChild(e)))
const i=function(e){const[t,o]=z(e).map((e=>e.dataset)),[a,n]=function(e,t){let o,a
o=moment.tz(`${e.date} ${e.time||""}`.trim(),e.timezone),t&&(a=moment.tz(`${t.date} ${t.time||""}`.trim(),t.timezone))
return[o,a]}(t,o)
if(a<moment().tz(t.timezone))return!1
const i=document.createElement("div")
i.classList.add("download-calendar"),i.innerHTML=`${(0,r.renderIcon)("string","file")} ${l.default.t("download_calendar.add_to_calendar")}`,i.setAttribute("data-starts-at",a.toISOString()),o&&i.setAttribute("data-ends-at",n.toISOString())
t.time||o||i.setAttribute("data-ends-at",a.add(24,"hours").toISOString())
return i.setAttribute("data-title",t.title),i}(e)
return i&&n.appendChild(i),n.outerHTML}Object.defineProperty(e,"__esModule",{value:!0}),e.applyLocalDates=f,e.default=void 0
var T,v,y,w,D,O
e.default=(T=u={name:"discourse-local-dates",showDatePopover(e){const t=this.container.lookup("service:tooltip")
if(e?.target?.classList?.contains("download-calendar")){const o=e.target.dataset
return(0,a.downloadCalendar)(o.title,[{startsAt:o.startsAt,endsAt:o.endsAt}]),t.close("local-date")}if(!e?.target?.classList?.contains("discourse-local-date"))return
const n=this.container.lookup("service:site-settings")
return t.show(e.target,{identifier:"local-date",content:(0,o.htmlSafe)(b(e.target,n))})},initialize(e){this.container=e,window.addEventListener("click",this.showDatePopover,{passive:!0})
e.lookup("service:site-settings").discourse_local_dates_enabled&&(0,n.withPluginApi)("0.8.8",_)},teardown(){window.removeEventListener("click",this.showDatePopover)}},v="showDatePopover",y=[s.bind],w=Object.getOwnPropertyDescriptor(u,"showDatePopover"),D=u,O={},Object.keys(w).forEach((function(e){O[e]=w[e]})),O.enumerable=!!O.enumerable,O.configurable=!!O.configurable,("value"in O||O.initializer)&&(O.writable=!0),O=y.slice().reverse().reduce((function(e,t){return t(T,v,e)||e}),O),D&&void 0!==O.initializer&&(O.value=O.initializer?O.initializer.call(D):void 0,O.initializer=void 0),void 0===O.initializer&&(Object.defineProperty(T,v,O),O=null),u)})),define("discourse/plugins/discourse-local-dates/lib/date-with-zone-helper",["exports","@ember/object"],(function(e,t){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0
class o{static fromDatetime(e,t,a){return new o({year:e.year(),month:e.month(),day:e.date(),hour:e.hour(),minute:e.minute(),second:e.second(),timezone:t,localTimezone:a})}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}
this.timezone=e.timezone||"UTC",this.localTimezone=e.localTimezone||moment.tz.guess(),this.datetime=moment.tz((0,t.getProperties)(e,["year","month","day","hour","minute","second"]),this.timezone)}isDST(){return this.datetime.tz(this.localTimezone).isDST()}unitRepetitionsBetweenDates(e,t){const[o,a]=e.split("."),n=Math.abs(this.datetime.diff(t,a,!0)),i=n/o%1
return Math.trunc(n/o)*parseInt(o,10)+(i>0?parseInt(o,10):0)}add(e,t){return this._fromDatetime(this.datetime.clone().add(e,t),this.timezone,this.localTimezone)}subtract(e,t){return this._fromDatetime(this.datetime.clone().subtract(e,t),this.timezone,this.localTimezone)}datetimeWithZone(e){return this.datetime.clone().tz(e)}format(e){return e?this.datetime.tz(this.localTimezone).format(e):this.datetime.tz(this.localTimezone).toISOString(!0)}_fromDatetime(e,t,a){return o.fromDatetime(e,t,a)}}e.default=o})),define("discourse/plugins/discourse-local-dates/lib/discourse-markdown/discourse-local-dates",["exports","pretty-text/engines/discourse-markdown/bbcode-block"],(function(e,t){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.setup=function(e){e.allowList(["span.discourse-local-date","span[aria-label]","span[data-date]","span[data-time]","span[data-format]","span[data-countdown]","span[data-calendar]","span[data-displayed-timezone]","span[data-timezone]","span[data-timezones]","span[data-recurring]","span[data-email-preview]"]),e.registerOptions(((e,t)=>{e.datesEmailFormat=t.discourse_local_dates_email_format,e.features["discourse-local-dates"]=!!t.discourse_local_dates_enabled})),e.registerPlugin((e=>{const t={matcher:/\[date(=.+?)\]/,onMatch:i}
e.core.textPostProcess.ruler.push("discourse-local-dates",t)})),e.registerPlugin((e=>{const t={matcher:/\[date-range(.+?)\]/,onMatch:r}
e.core.textPostProcess.ruler.push("discourse-local-dates",t)}))},moment.tz.link(["Asia/Kolkata|IST","Asia/Seoul|KST","Asia/Tokyo|JST"])
const o=moment.tz.names()
function a(e,t,a){let n=new t.Token("span_open","span",1)
if(n.attrs=[["data-date",t.md.utils.escapeHtml(a.date)]],!a.date.match(/\d{4}-\d{2}-\d{2}/))return void s(e,t,moment.invalid().format())
if(a.time&&!a.time.match(/\d{2}:\d{2}(?::\d{2})?/))return void s(e,t,moment.invalid().format())
let i=a.date
if(a.time&&(n.attrs.push(["data-time",t.md.utils.escapeHtml(a.time)]),i=`${i} ${a.time}`),!moment(i).isValid())return void s(e,t,moment.invalid().format())
if(n.attrs.push(["class","discourse-local-date"]),a.format&&n.attrs.push(["data-format",t.md.utils.escapeHtml(a.format)]),a.countdown&&n.attrs.push(["data-countdown",t.md.utils.escapeHtml(a.countdown)]),a.calendar&&n.attrs.push(["data-calendar",t.md.utils.escapeHtml(a.calendar)]),a.range&&n.attrs.push(["data-range",a.range]),a.displayedTimezone&&o.includes(a.displayedTimezone)&&n.attrs.push(["data-displayed-timezone",t.md.utils.escapeHtml(a.displayedTimezone)]),a.timezones){const e=a.timezones.split("|").filter((e=>o.includes(e)))
n.attrs.push(["data-timezones",t.md.utils.escapeHtml(e.join("|"))])}a.timezone&&o.includes(a.timezone)?(n.attrs.push(["data-timezone",t.md.utils.escapeHtml(a.timezone)]),i=moment.tz(i,a.timezone)):i=moment.utc(i),a.recurring&&n.attrs.push(["data-recurring",t.md.utils.escapeHtml(a.recurring)]),e.push(n)
const r=i.tz("Etc/UTC").format(t.md.options.discourse.datesEmailFormat||moment.defaultFormat)
n.attrs.push(["data-email-preview",`${r} UTC`]),s(e,t,i.utc().format(a.format))}function n(e){const o=e.replace(/[ββββ«»β]/g,'"')
return(0,t.parseBBCodeTag)("[date date"+o+"]",0,o.length+12)}function i(e,t,o){let i={date:null,time:null,timezone:null,format:null,timezones:null,displayedTimezone:null,countdown:null,range:!1}
const r=n(t[1])
i.date=r.attrs.date,i.format=r.attrs.format,i.calendar=r.attrs.calendar,i.time=r.attrs.time,i.timezone=(r.attrs.timezone||"").trim(),i.recurring=r.attrs.recurring,i.timezones=r.attrs.timezones,i.displayedTimezone=r.attrs.displayedTimezone,i.countdown=r.attrs.countdown,a(e,o,i)}function r(e,t,o){let i,r,s={date:null,time:null,timezone:null,format:null,timezones:null,displayedTimezone:null,countdown:null,range:!1}
const l=n(t[1])
if(s.format=l.attrs.format,s.calendar=l.attrs.calendar,s.timezone=(l.attrs.timezone||"").trim(),s.recurring=l.attrs.recurring,s.timezones=l.attrs.timezones,s.displayedTimezone=l.attrs.displayedTimezone,s.countdown=l.attrs.countdown,l.attrs.from&&([i,r]=l.attrs.from.split("T"),s.date=i,s.time=r,s.range="from",a(e,o,s)),s.range){const t=new o.Token("text","",0)
t.content="β",e.push(t)}l.attrs.to&&([i,r]=l.attrs.to.split("T"),s.date=i,s.time=r,s.range="to",a(e,o,s))}function s(e,t,o){let a
a=new t.Token("text","",0),a.content=o,e.push(a),a=new t.Token("span_close","span",-1),e.push(a)}})),define("discourse/plugins/discourse-local-dates/lib/local-date-builder",["exports","discourse-common/lib/icon-library","discourse-i18n","discourse/plugins/discourse-local-dates/lib/date-with-zone-helper"],(function(e,t,o,a){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0
const n="h:mm A"
e.default=class{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0
this.time=e.time,this.date=e.date,this.recurring=e.recurring,this.sameLocalDayAsFrom=e.sameLocalDayAsFrom,this.timezones=Array.from(new Set((e.timezones||[]).filter(Boolean))),this.timezone=e.timezone||"UTC",this.calendar=void 0===e.calendar||e.calendar,this.displayedTimezone=e.displayedTimezone,this.format=e.format||(this.time?"LLL":"LL"),this.countdown=e.countdown,this.duration=e.duration,this.localTimezone=t}build(){const[e,t,o]=this.date.split("-").map((e=>parseInt(e,10))),[n,i,r]=(this.time||"").split(":").map((e=>e?parseInt(e,10):void 0))
let s
s=this.time?this.displayedTimezone||this.localTimezone:this.displayedTimezone||this.timezone||this.localTimezone
let l=new a.default({year:e,month:t?t-1:null,day:o,hour:n,minute:i,second:r,timezone:this.timezone,localTimezone:this.localTimezone})
if(this.recurring&&moment().isAfter(l.datetime)){const e=this.recurring.split(".")[1],t=l.unitRepetitionsBetweenDates(this.recurring,moment.tz(this.localTimezone))
l=l.add(t,e)}const d=this._generatePreviews(l,s),c=void 0!==n
return{pastEvent:!this.recurring&&moment.tz(this.localTimezone).isAfter(l.datetime),formatted:this._applyFormatting(l,s,c),previews:d,textPreview:this._generateTextPreviews(d)}}_generateTextPreviews(e){return e.map((e=>`${this._zoneWithoutPrefix(e.timezone)} ${e.formatted}`)).join(", ")}_generatePreviews(e,t){const o=[],n=this.timezones.filter((e=>!this._isEqualZones(e,this.localTimezone)))
return o.push({timezone:this._zoneWithoutPrefix(this.localTimezone),current:!0,formatted:this._createDateTimeRange(a.default.fromDatetime(e.datetime,e.timezone,this.localTimezone),this.time,this.duration)}),!this.timezone||t!==this.localTimezone||this.timezone===t||this._isEqualZones(t,this.timezone)||this.timezones.any((e=>this._isEqualZones(e,this.timezone)))||n.unshift(this.timezone),n.forEach((n=>{this._isEqualZones(n,t)||(this._isEqualZones(n,this.localTimezone)&&(n=this.localTimezone),o.push({timezone:this._zoneWithoutPrefix(n),formatted:this._createDateTimeRange(a.default.fromDatetime(e.datetime,e.timezone,n),this.time,this.duration)}))})),o.uniqBy("timezone")}_isEqualZones(e,t){return!!(!e&&!t||e&&t)&&(!(!e.includes(t)&&!t.includes(e))||moment.tz(e).utcOffset()===moment.tz(t).utcOffset())}_createDateTimeRange(e,t,o){const[a,i]=this._calculateDatesForRange(e,t,o)
let r=[a.format("dddd, LL"),this._optionalTimeIcon(a,i),a.format(n)]
return i&&(r=r.concat(["β",i.format(this._endDateFormat(a,i))])),r.filter(Boolean).join(" ")}_shortFormat(e,t){return t.datetime.diff(e.datetime,"days")<1}_optionalTimeIcon(e,o){if(!o||this._shortFormat(e,o))return`<br />${(0,t.renderIcon)("string","clock")}`}_endDateFormat(e,t){return this._shortFormat(e,t)?n:"LLLL"}_calculateDatesForRange(e,t,o){if(t&&!o)return[e]
const a=[e,o?e.add(o,"minutes"):e.add(24,"hours")]
return o<0?a.reverse():a}_applyFormatting(e,t,a){if(this.countdown){const t=moment.tz(this.localTimezone).diff(e.datetime)
return t<0?moment.duration(t).humanize():o.default.t("discourse_local_dates.relative_dates.countdown.passed")}const n=this._isEqualZones(t,this.localTimezone)
if(this.calendar){const o=moment.tz(this.localTimezone).isBetween(e.subtract(2,"day").datetime,e.add(1,"day").datetime.endOf("day"))
if(this.sameLocalDayAsFrom)return this._timeOnlyFormat(e,t)
if(o&&n){const t=e.datetimeWithZone(this.localTimezone)
return a&&0===t.hours()&&0===t.minutes()?t.format("dddd"):t.calendar(moment.tz(e.timezone),this._calendarFormats(this.time?this.time:null))}}return n?e.format(this.format):this._formatWithZone(e,t,this.format)}_calendarFormats(e){return{sameDay:this._translateCalendarKey(e,"today"),nextDay:this._translateCalendarKey(e,"tomorrow"),lastDay:this._translateCalendarKey(e,"yesterday"),sameElse:"L"}}_translateCalendarKey(e,t){const a=o.default.t(`discourse_local_dates.relative_dates.${t}`,{time:"LT"})
return e?a.split("LT").map((e=>`[${e}]`)).join("LT"):`[${a.replace(" LT","")}]`}_formatTimezone(e){return e.replace("_"," ").replace("Etc/","").split("/")}_zoneWithoutPrefix(e){const[t,o]=this._formatTimezone(e)
return o||t}_formatWithZone(e,t,o){return`${e.datetimeWithZone(t).format(o)} (${this._zoneWithoutPrefix(t)})`}_timeOnlyFormat(e,t){return this._formatWithZone(e,t,"LT")}}})),define("discourse/plugins/discourse-local-dates/lib/local-date-markup-generator",["exports","@ember/utils"],(function(e,t){"use strict"
Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(e,o,a,n){let i=""
if(a){i+=`[date-range from=${[e.date,e.time].filter((e=>!(0,t.isEmpty)(e))).join("T")} to=${[n.date,n.time].filter((e=>!(0,t.isEmpty)(e))).join("T")}`}else i+=`[date=${e.date}`
e.time&&!a&&(i+=` time=${e.time}`)
e.format&&e.format.length&&(i+=` format="${e.format}"`)
o.timezone&&(i+=` timezone="${o.timezone}"`)
o.countdown&&(i+=` countdown="${o.countdown}"`)
o.displayedTimezone&&(i+=` displayedTimezone="${o.displayedTimezone}"`)
o.timezones&&o.timezones.length&&(Array.isArray(o.timezones)?i+=` timezones="${o.timezones.join("|")}"`:i+=` timezones="${o.timezones}"`)
o.recurring&&!a&&(i+=` recurring="${o.recurring}"`)
return i+="]",i}}))
//# sourceMappingURL=discourse-local-dates-a37f9c9bf7d990a764cb4a1763d881d8b8e2a32a0aeb9a2983ee09ca49773c2d.map
//!
;