UNPKG

@tripetto/block-date

Version:

Date block for Tripetto.

2 lines 17.1 kB
/*! Tripetto Date Block 4.0.3 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */ !function(){"use strict";var e={583:function(e,t,o){var i,a=this&&this.__extends||(i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},i(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),n=this&&this.__decorate||function(e,t,o,i){var a,n=arguments.length,l=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,i);else for(var r=e.length-1;r>=0;r--)(a=e[r])&&(l=(n<3?a(l):n>3?a(t,o,l):a(t,o))||l);return n>3&&l&&Object.defineProperty(t,o,l),l};Object.defineProperty(t,"__esModule",{value:!0}),t.DateTimeCondition=void 0;var l=o(954),r=o(110),s=o(537),d=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.allowMarkdown=!0,t.mode="equal",t}return a(t,e),Object.defineProperty(t.prototype,"label",{get:function(){return""},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){var e=this.slot;if(e instanceof l.Slots.Date){var t=this.parse(e,this.value);switch(this.mode){case"between":return"".concat(t," ≤ @").concat(e.id," ≤ ").concat(this.parse(e,this.to));case"not-between":return"@".concat(e.id," < ").concat(t," ").concat((0,l.pgettext)("block:date","or")," @").concat(e.id," > ").concat(this.parse(e,this.to));case"defined":return"@".concat(e.id," ").concat((0,l.pgettext)("block:date","not empty"));case"undefined":return"@".concat(e.id," ").concat((0,l.pgettext)("block:date","empty"));case"before":case"after":case"equal":case"not-equal":return"@".concat(e.id," ").concat("after"===this.mode?">":"before"===this.mode?"<":"not-equal"===this.mode?"≠":"="," ").concat(t)}}return this.type.label},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"title",{get:function(){var e,t=this.node;return(null==t?void 0:t.block)instanceof r.DateTime&&t.label+(t.block.range?" / "+(null===(e=this.slot)||void 0===e?void 0:e.label):"")||void 0},enumerable:!1,configurable:!0}),t.prototype.parse=function(e,t){var o;return(0,l.isNumberFinite)(t)?e.supportsTime?l.L10n.locale.dateTimeShort(e.toValue(t),!0):l.L10n.locale.dateShort(e.toValue(t),!0):(0,l.isString)(t)?t&&(null===(o=(0,l.lookupVariable)(this,t))||void 0===o?void 0:o.label)?"@".concat(t):"\\_\\_":"`"+(0,l.pgettext)("block:date","Now").toUpperCase()+"`"},t.prototype.defineEditor=function(){var e=this,t=this.slot instanceof l.Slots.Date&&this.slot.supportsTime;this.editor.form({title:(0,l.pgettext)("block:date","Compare mode"),controls:[new l.Forms.Radiobutton([{label:(0,l.pgettext)("block:date","Date is equal to"),value:"equal"},{label:(0,l.pgettext)("block:date","Date is not equal to"),value:"not-equal"},{label:(0,l.pgettext)("block:date","Date is before"),value:"before"},{label:(0,l.pgettext)("block:date","Date is after"),value:"after"},{label:(0,l.pgettext)("block:date","Date is between"),value:"between"},{label:(0,l.pgettext)("block:date","Date is not between"),value:"not-between"},{label:(0,l.pgettext)("block:date","Date is not empty"),value:"defined"},{label:(0,l.pgettext)("block:date","Date is empty"),value:"undefined"}],l.Forms.Radiobutton.bind(this,"mode","equal")).on((function(e){switch(i.visible("defined"!==e.value&&"undefined"!==e.value),a.visible("between"===e.value||"not-between"===e.value),e.value){case"equal":i.title=(0,l.pgettext)("block:date","If date equals");break;case"not-equal":i.title=(0,l.pgettext)("block:date","If date not equals");break;case"before":i.title=(0,l.pgettext)("block:date","If date is before");break;case"after":i.title=(0,l.pgettext)("block:date","If date is after");break;case"between":i.title=(0,l.pgettext)("block:date","If date is between");break;case"not-between":i.title=(0,l.pgettext)("block:date","If date is not between")}}))]});var o=function(o,i,a){var n,s=e[o],d=(0,l.populateVariables)(e,(function(e){return e instanceof l.Slots.Date}),(0,l.isString)(s)?s:void 0,!0,null===(n=e.slot)||void 0===n?void 0:n.id),u=new l.Forms.DateTime((0,l.isNumberFinite)(s)?s:r.DateTime.getToday("to"===o?"end":"begin")).label(t?(0,l.pgettext)("block:date","Use fixed date/time"):(0,l.pgettext)("block:date","Use fixed date")).features(1|(t?8:32)).years((new Date).getFullYear()-150,(new Date).getFullYear()+50).zone("UTC").width("full").required().on((function(t){t.isFormVisible&&t.isObservable&&(e[o]=t.value)})),c=new l.Forms.Dropdown(d,(0,l.isString)(s)?s:"").label((0,l.pgettext)("block:date","Use value of")).width("full").on((function(t){t.isFormVisible&&t.isObservable&&(e[o]=t.value||"")}));return e.editor.form({title:i,controls:[new l.Forms.Radiobutton([{label:t?(0,l.pgettext)("block:date","Current date/time"):(0,l.pgettext)("block:date","Current date"),value:"current"},{label:t?(0,l.pgettext)("block:date","Fixed date/time"):(0,l.pgettext)("block:date","Fixed date"),value:"date"},{label:(0,l.pgettext)("block:date","Value"),value:"variable",disabled:0===d.length}],(0,l.isString)(s)?"variable":(0,l.isNumberFinite)(s)?"date":"current").on((function(t){u.visible("date"===t.value),c.visible("variable"===t.value),"current"===t.value&&(e[o]=void 0)})),u,c]}).visible(a)},i=o("value",(0,l.pgettext)("block:date","If date equals"),"defined"!==this.mode&&"undefined"!==this.mode),a=o("to",(0,l.pgettext)("block:date","And"),"between"===this.mode||"not-between"===this.mode)},n([l.definition,(0,l.affects)("#name")],t.prototype,"mode",void 0),n([l.definition,(0,l.affects)("#name")],t.prototype,"value",void 0),n([l.definition,(0,l.affects)("#name")],t.prototype,"to",void 0),n([l.editor],t.prototype,"defineEditor",null),t=n([(0,l.tripetto)({type:"condition",legacyBlock:!0,context:"@tripetto/block-date",identifier:"@tripetto/block-date",version:"4.0.3",icon:s.default,get label(){return(0,l.pgettext)("block:date","Verify date")}})],t)}(l.ConditionBlock);t.DateTimeCondition=d},110:function(e,t,o){var i,a=this&&this.__extends||(i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},i(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),n=this&&this.__decorate||function(e,t,o,i){var a,n=arguments.length,l=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,o,i);else for(var r=e.length-1;r>=0;r--)(a=e[r])&&(l=(n<3?a(l):n>3?a(t,o,l):a(t,o))||l);return n>3&&l&&Object.defineProperty(t,o,l),l};Object.defineProperty(t,"__esModule",{value:!0}),t.DateTime=void 0;var l=o(954),r=o(583),s=o(617),d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}var o;return a(t,e),o=t,Object.defineProperty(t.prototype,"label",{get:function(){return this.range?(0,l.pgettext)("block:date","Date range"):this.time?(0,l.pgettext)("block:date","Date with time"):this.type.label},enumerable:!1,configurable:!0}),t.getToday=function(e){return l.DateTime.UTCToday+("end"===e?86399999:0)},t.prototype.defineSlot=function(){if(this.dateSlot=this.slots.static({type:l.Slots.Date,reference:"date",label:this.range?(0,l.pgettext)("block:date","Date from"):this.time?(0,l.pgettext)("block:date","Date with time"):o.label,required:this.required,alias:this.alias,exportable:this.exportable,exchange:["required","alias","exportable","precision","minimum","maximum"]}),this.dateSlot.precision=this.time?"minutes":"days",this.dateSlot.minimum=this.minimum,this.dateSlot.maximum=this.maximum,this.range){var e=this.slots.static({type:l.Slots.Date,reference:"to",label:(0,l.pgettext)("block:date","Date to"),required:this.required,alias:this.alias,exportable:this.exportable,exchange:["required","alias","exportable","precision","minimum","maximum"],pipe:"to"});e.precision=this.dateSlot.precision,e.minimum=this.dateSlot.minimum,e.maximum=this.dateSlot.maximum}else this.slots.delete("to","static")},t.prototype.defineEditor=function(){var e=this,t=function(e){return 1|(e?8:32)},o=new l.Forms.Text("singleline",l.Forms.Text.bind(this,"placeholder",void 0,"")).placeholder((0,l.pgettext)("block:date","Type placeholder for the range to date field...")).action("@",(0,l.insertVariable)(this)).visible(this.range||!1);this.editor.name(),this.editor.description(),this.editor.placeholder(o),this.editor.explanation(),this.editor.groups.settings(),this.editor.option({name:(0,l.pgettext)("block:date","Time"),form:{title:(0,l.pgettext)("block:date","Time"),controls:[new l.Forms.Checkbox((0,l.pgettext)("block:date","Allow a time to be set"),l.Forms.Checkbox.bind(this,"time",void 0,!0)).on((function(e){i.features(t(e.isFeatureEnabled&&e.isChecked)),a.features(t(e.isFeatureEnabled&&e.isChecked))})),new l.Forms.Static((0,l.pgettext)("block:date","When enabled this will allow the user to set a specific time along with the date."))]},activated:(0,l.isBoolean)(this.time)}),this.editor.option({name:(0,l.pgettext)("block:date","Range"),form:{title:(0,l.pgettext)("block:date","Range"),controls:[new l.Forms.Checkbox((0,l.pgettext)("block:date","Enable date range"),l.Forms.Checkbox.bind(this,"range",void 0,!0)).on((function(){o.visible(e.range||!1)})),new l.Forms.Static((0,l.pgettext)("block:date","When enabled this will display two date input fields. One for the *from* date and another one for the *to* date.")).markdown()]},activated:(0,l.isBoolean)(this.range)});var i=new l.Forms.DateTime((0,l.isNumber)(this.minimum)?this.minimum:void 0).zone("UTC").features(t(this.time)).disabled(!0===this.minimum).years((new Date).getFullYear()-150,(new Date).getFullYear()+50).width("full").label((0,l.pgettext)("block:date","Minimum")).placeholder((0,l.pgettext)("block:date","Not set")).on((function(){i.isFeatureEnabled?!0!==e.minimum&&(e.minimum=i.value):e.minimum=void 0})),a=new l.Forms.DateTime((0,l.isNumber)(this.maximum)?this.maximum:void 0).zone("UTC").features(t(this.time)).disabled(!0===this.maximum).years((new Date).getFullYear()-150,(new Date).getFullYear()+50).width("full").label((0,l.pgettext)("block:date","Maximum")).placeholder((0,l.pgettext)("block:date","Not set")).on((function(){a.isFeatureEnabled?!0!==e.maximum&&(e.maximum=a.value):e.maximum=void 0}));this.editor.option({name:(0,l.pgettext)("block:date","Limits"),form:{title:(0,l.pgettext)("block:date","Limits"),controls:[i,a,new l.Forms.Static((0,l.pgettext)("block:date","Options")),new l.Forms.Checkbox((0,l.pgettext)("block:date","Date must be in the future"),!0===this.minimum).on((function(t){t.isFeatureEnabled&&t.isChecked?e.minimum=!0:!0===e.minimum&&(e.minimum=void 0,i.refresh()),i.disabled(!0===e.minimum)})),new l.Forms.Checkbox((0,l.pgettext)("block:date","Date must be in the past"),!0===this.maximum).on((function(t){t.isFeatureEnabled&&t.isChecked?e.maximum=!0:!0===e.maximum&&(e.maximum=void 0,a.refresh()),a.disabled(!0===e.maximum)}))]},activated:(0,l.isNumber)(this.minimum)||!0===this.minimum||(0,l.isNumber)(this.maximum)||!0===this.maximum}),this.editor.groups.options(),this.editor.required(this),this.editor.visibility(),this.editor.alias(this),this.editor.exportable(this)},t.prototype.defineCondition=function(){var e=this,t=this.slots.select("date"),o=this.slots.select("to"),i=[{mode:"equal",label:(0,l.pgettext)("block:date","Is equal to")},{mode:"not-equal",label:(0,l.pgettext)("block:date","Is not equal to")},{mode:"before",label:(0,l.pgettext)("block:date","Is before")},{mode:"after",label:(0,l.pgettext)("block:date","Is after")},{mode:"between",label:(0,l.pgettext)("block:date","Is between")},{mode:"not-between",label:(0,l.pgettext)("block:date","Is not between")},{mode:"defined",label:(0,l.pgettext)("block:date","Is not empty")},{mode:"undefined",label:(0,l.pgettext)("block:date","Is empty")}];if(t){var a=o?this.conditions.group(t.label||(0,l.pgettext)("block:date","Date from")):this.conditions;(0,l.each)(i,(function(o){a.template({condition:r.DateTimeCondition,label:o.label,autoOpen:"defined"!==o.mode&&"undefined"!==o.mode,props:{slot:t,mode:o.mode,value:e.time?l.DateTime.UTC:l.DateTime.UTCToday,to:"between"===o.mode||"not-between"===o.mode?e.time?l.DateTime.UTC:l.DateTime.UTCToday:void 0}})}))}if(o){var n=this.conditions.group(o.label||(0,l.pgettext)("block:date","Date to"));(0,l.each)(i,(function(e){n.template({condition:r.DateTimeCondition,label:e.label,autoOpen:"defined"!==e.mode&&"undefined"!==e.mode,props:{slot:o,mode:e.mode,value:l.DateTime.UTC,to:"between"===e.mode||"not-between"===e.mode?l.DateTime.UTC:void 0}})}))}},n([(0,l.definition)("boolean","optional"),(0,l.affects)("#label"),(0,l.affects)("#slots")],t.prototype,"time",void 0),n([(0,l.definition)("boolean","optional"),(0,l.affects)("#label"),(0,l.affects)("#slots")],t.prototype,"range",void 0),n([(0,l.definition)("number","optional"),(0,l.affects)("#slots")],t.prototype,"minimum",void 0),n([(0,l.definition)("number","optional"),(0,l.affects)("#slots")],t.prototype,"maximum",void 0),n([(0,l.definition)("boolean","optional"),(0,l.affects)("#slots")],t.prototype,"required",void 0),n([(0,l.definition)("string","optional"),(0,l.affects)("#slots")],t.prototype,"alias",void 0),n([(0,l.definition)("boolean","optional"),(0,l.affects)("#slots")],t.prototype,"exportable",void 0),n([(0,l.definition)("string","optional")],t.prototype,"placeholder",void 0),n([l.slots],t.prototype,"defineSlot",null),n([l.editor],t.prototype,"defineEditor",null),n([l.conditions],t.prototype,"defineCondition",null),t=o=n([(0,l.tripetto)({type:"node",legacyBlock:!0,identifier:"@tripetto/block-date",version:"4.0.3",icon:s.default,get label(){return(0,l.pgettext)("block:date","Date")}})],t)}(l.NodeBlock);t.DateTime=d},537:function(e,t,o){o.r(t),t.default="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE4LjUgMkgxNnYtLjVhLjUuNSAwIDAgMC0xIDBWMkg1di0uNWEuNS41IDAgMCAwLTEgMFYySDEuNUMuNjczIDIgMCAyLjY3MyAwIDMuNXYxNGMwIC44M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wIDF6bTMgMGgtMWEuNS41IDAgMCAxIDAtMWgxYS41LjUgMCAwIDEgMCAxeiIgY2xhc3M9InRyaXBldHRvLWZpbGwiLz48L3N2Zz4="},954:function(e){e.exports=require("@tripetto/builder")}},t={};function o(i){var a=t[i];if(void 0!==a)return a.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,o),n.exports}o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i=o(110);module.exports=i}();