@tripetto/block-checkboxes
Version:
Checkboxes block for Tripetto.
2 lines • 13 kB
JavaScript
/*! Tripetto Checkboxes Block 7.1.1 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("TripettoRunner")):"function"==typeof define&&define.amd?define("TripettoBlockCheckboxes",["TripettoRunner"],t):"object"==typeof exports?exports.TripettoBlockCheckboxes=t(require("TripettoRunner")):e.TripettoBlockCheckboxes=t(e.TripettoRunner)}(this,(function(e){return function(){"use strict";var t={250:function(e,t,o){var r,n=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(t,o,c):n(t,o))||c);return i>3&&c&&Object.defineProperty(t,o,c),c};Object.defineProperty(t,"__esModule",{value:!0}),t.Checkboxes=void 0;var c=o(294),u=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.counterSlot=t.valueOf("counter"),t.concatenationSlot=t.valueOf("concatenation","feature"),t.scoreSlot=t.valueOf("score","feature"),t}return n(t,e),Object.defineProperty(t.prototype,"required",{get:function(){return this.props.required||!1},enumerable:!1,configurable:!0}),t.prototype.transform=function(){var e=this,t=(0,c.filter)((0,c.map)(this.props.checkboxes,(function(t){return{id:t.id,label:t.value||t.name||"",exclusive:t.exclusive,valueRef:e.valueOf(t.id)}})),(function(e){var t;return!0===(null===(t=e.valueRef)||void 0===t?void 0:t.value)})).sort((function(e,t){var o,r;return((null===(o=t.valueRef)||void 0===o?void 0:o.time)||0)-((null===(r=e.valueRef)||void 0===r?void 0:r.time)||0)})),o=t.length&&t[0];if(o&&t.forEach((function(e){e.id!==o.id&&(o.exclusive||e.exclusive)&&(e.valueRef.value=!1)})),this.props.max){var r=this.props.max,n=0;t.forEach((function(e){var t;!0===(null===(t=e.valueRef)||void 0===t?void 0:t.value)&&++n>r&&(e.valueRef.value=!1)}))}if(this.counterSlot){var i=(0,c.filter)(t,(function(e){var t;return!0===(null===(t=e.valueRef)||void 0===t?void 0:t.value)})).length;this.counterSlot.set(i)}if(this.concatenationSlot){var u=[],a="",s=0;if((0,c.each)(this.props.checkboxes,(function(t){var o,r=t.value||t.name||"";if(r&&!0===(null===(o=e.valueOf(t.id))||void 0===o?void 0:o.value))switch(e.props.formatSeparator){case"space":a+=(""===a?"":" ")+r;break;case"list":a+=(""===a?"":"\n")+r;break;case"bullets":a+=(""===a?"":"\n")+"- "+r;break;case"numbers":a+=(""===a?"":"\n")+"".concat(++s,". ").concat(r);break;case"conjunction":case"disjunction":u.push(r);break;case"custom":a+=(""===a?"":e.props.formatSeparatorCustom||"")+r;break;default:a+=(""===a?"":", ")+r}})),"conjunction"===this.props.formatSeparator||"disjunction"===this.props.formatSeparator)try{var l=new Intl.ListFormat(this.context.l10n.current||"en",{type:this.props.formatSeparator});a=l.format(u)}catch(e){a=c.Str.iterateToString(u,", ")}this.concatenationSlot.set(a)}},t.prototype.score=function(e){var t=this;this.scoreSlot&&(0,c.isNumberFinite)(e.score)&&this.scoreSlot.set((0,c.reduce)(this.props.checkboxes,(function(e,o){var r;return e+(!0===(null===(r=t.valueOf(o.id))||void 0===r?void 0:r.value)&&o.score||0)}),0))},t.prototype.checkboxSlot=function(e){var t=this;return this.valueOf(e.id,"dynamic",{confirm:!0,onChange:function(){t.transform(),t.score(e)},onContext:function(o,r){var n;t.scoreSlot&&(null===(n=r.contextualValueOf(t.scoreSlot))||void 0===n||n.set(!0===o.value?e.score||0:void 0))}})},t.prototype.isChecked=function(e){var t=this.checkboxSlot(e);return(null==t?void 0:t.value)||!1},t.prototype.check=function(e,t){var o=this.checkboxSlot(e);return!!o&&(o.value=t,o.value)},t.prototype.toggle=function(e){var t=this.checkboxSlot(e);t&&(t.value=!t.value)},t.prototype.checkboxes=function(e){var t,o=this,r=0,n=this,i=(null===(t=this.props.checkboxes)||void 0===t?void 0:t.map((function(t){var i=o.checkboxSlot(t);return o.props.max&&!0===(null==i?void 0:i.value)&&r++,{id:t.id,score:t.score,exclusive:t.exclusive,label:e.markdownifyToJSX(t.name,!1),description:t.description&&e.markdownifyToJSX(t.description,!0)||void 0,value:i,tabIndex:e.tabIndex,get disabled(){return n.props.max&&r>=n.props.max&&!0!==(null==i?void 0:i.value)||!1}}})))||[];if(this.props.randomize&&i.length>1){if(!this.randomized||this.randomized.length!==i.length||(0,c.findFirst)(this.randomized,(function(e){var t;return(null===(t=i[e.index])||void 0===t?void 0:t.id)!==e.id}))){this.randomized=i.map((function(e,t){return{index:t,id:e.id}}));for(var u=this.randomized.length;--u;){var a=Math.floor(Math.random()*u),s=this.randomized[u];this.randomized[u]=this.randomized[a],this.randomized[a]=s}}return this.randomized.map((function(e){return i[e.index]}))}return this.randomized&&(this.randomized=void 0),i},t.prototype.validate=function(){var e=this;if(this.props.min||this.props.max){var t=(0,c.filter)(this.props.checkboxes,(function(t){var o;return!0===(null===(o=e.checkboxSlot(t))||void 0===o?void 0:o.value)})).length;if(this.props.min&&t<this.props.min||this.props.max&&t>this.props.max)return!1}return!this.props.required||!!(0,c.findFirst)(this.props.checkboxes,(function(t){var o;return!0===(null===(o=e.valueOf(t.id))||void 0===o?void 0:o.value)}))},i([c.validator],t.prototype,"validate",null),t}(c.NodeBlock);t.Checkboxes=u},126:function(e,t,o){var r,n=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(t,o,c):n(t,o))||c);return i>3&&c&&Object.defineProperty(t,o,c),c};Object.defineProperty(t,"__esModule",{value:!0}),t.CheckboxCondition=void 0;var c=o(294),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.isChecked=function(){var e=this.valueOf();return e&&e.value===this.props.checked||!1},i([c.condition],t.prototype,"isChecked",null),t=i([(0,c.tripetto)({type:"condition",legacyBlock:!0,identifier:"@tripetto/block-checkboxes"})],t)}(c.ConditionBlock);t.CheckboxCondition=u},924:function(e,t,o){var r,n=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(t,o,c):n(t,o))||c);return i>3&&c&&Object.defineProperty(t,o,c),c};Object.defineProperty(t,"__esModule",{value:!0}),t.CounterCondition=void 0;var c=o(294),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.getValue=function(e,t){if((0,c.isString)(t)&&e instanceof c.Slots.Number){var o=this.variableFor(t);return o&&o.hasValue?e.toValue(o.value):void 0}return(0,c.isNumberFinite)(t)?t:void 0},t.prototype.verify=function(){var e=this.valueOf();if(e){var t=this.getValue(e.slot,this.props.value);switch(this.props.mode){case"equal":return(e.hasValue?e.value:void 0)===t;case"not-equal":return(e.hasValue?e.value:void 0)!==t;case"below":return(0,c.isNumberFinite)(t)&&e.hasValue&&e.value<t;case"above":return(0,c.isNumberFinite)(t)&&e.hasValue&&e.value>t;case"between":case"not-between":var o=this.getValue(e.slot,this.props.to);return(0,c.isNumberFinite)(t)&&(0,c.isNumberFinite)(o)&&(e.hasValue&&e.value>=c.Num.min(t,o)&&e.value<=c.Num.max(t,o))===("between"===this.props.mode)}}return!1},i([c.condition],t.prototype,"verify",null),t=i([(0,c.tripetto)({type:"condition",legacyBlock:!0,identifier:"".concat("@tripetto/block-checkboxes",":counter")})],t)}(c.ConditionBlock);t.CounterCondition=u},502:function(e,t,o){var r,n=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(t,o,c):n(t,o))||c);return i>3&&c&&Object.defineProperty(t,o,c),c};Object.defineProperty(t,"__esModule",{value:!0}),t.ScoreCondition=void 0;var c=o(294),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.getValue=function(e,t){if((0,c.isString)(t)&&e instanceof c.Slots.Numeric){var o=this.variableFor(t);return o&&o.hasValue?e.toValue(o.value):void 0}return(0,c.isNumberFinite)(t)?t:void 0},t.prototype.verify=function(){var e=this.valueOf();if(e){var t=this.getValue(e.slot,this.props.value);switch(this.props.mode){case"equal":return(e.hasValue?e.value:void 0)===t;case"not-equal":return(e.hasValue?e.value:void 0)!==t;case"below":return(0,c.isNumberFinite)(t)&&e.hasValue&&e.value<t;case"above":return(0,c.isNumberFinite)(t)&&e.hasValue&&e.value>t;case"between":case"not-between":var o=this.getValue(e.slot,this.props.to);return(0,c.isNumberFinite)(t)&&(0,c.isNumberFinite)(o)&&(e.hasValue&&e.value>=c.Num.min(t,o)&&e.value<=c.Num.max(t,o))===("between"===this.props.mode);case"defined":return e.hasValue;case"undefined":return!e.hasValue}}return!1},i([c.condition],t.prototype,"verify",null),t=i([(0,c.tripetto)({type:"condition",legacyBlock:!0,identifier:"".concat("@tripetto/block-checkboxes",":score")})],t)}(c.ConditionBlock);t.ScoreCondition=u},87:function(e,t,o){var r,n=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(n=e[u])&&(c=(i<3?n(c):i>3?n(t,o,c):n(t,o))||c);return i>3&&c&&Object.defineProperty(t,o,c),c};Object.defineProperty(t,"__esModule",{value:!0}),t.UncheckedCondition=void 0;var c=o(294),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.prototype.allUnchecked=function(){var e=this,t=this.slots;return!t||!t.each((function(t){var o=e.valueOf(t);return o&&o.value||!1}))},i([c.condition],t.prototype,"allUnchecked",null),t=i([(0,c.tripetto)({type:"condition",legacyBlock:!0,identifier:"".concat("@tripetto/block-checkboxes",":unchecked")})],t)}(c.ConditionBlock);t.UncheckedCondition=u},294:function(t){t.exports=e}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var i=o[e]={exports:{}};return t[e].call(i.exports,i,i.exports,r),i.exports}var n={};return function(){var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.Checkboxes=void 0,r(126),r(87),r(924),r(502);var t=r(250);Object.defineProperty(e,"Checkboxes",{enumerable:!0,get:function(){return t.Checkboxes}})}(),n}()}));