UNPKG

@tripetto/block-dropdown

Version:

Dropdown block for Tripetto.

2 lines 7.56 kB
/*! Tripetto Dropdown Block 7.0.0 - 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("TripettoBlockDropdown",["TripettoRunner"],t):"object"==typeof exports?exports.TripettoBlockDropdown=t(require("TripettoRunner")):e.TripettoBlockDropdown=t(e.TripettoRunner)}(this,(function(e){return function(){"use strict";var t={566:function(e,t,o){var n,r=this&&this.__extends||(n=function(e,t){return n=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])},n(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}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,n){var r,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,o,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(u=(i<3?r(u):i>3?r(t,o,u):r(t,o))||u);return i>3&&u&&Object.defineProperty(t,o,u),u};Object.defineProperty(t,"__esModule",{value:!0}),t.DropdownCondition=void 0;var u=o(294),s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.isSelected=function(){var e=this.valueOf();return e&&(e.reference===this.props.option||!this.props.option&&!e.reference)||!1},i([u.condition],t.prototype,"isSelected",null),t=i([(0,u.tripetto)({type:"condition",legacyBlock:!0,identifier:"@tripetto/block-dropdown"})],t)}(u.ConditionBlock);t.DropdownCondition=s},502:function(e,t,o){var n,r=this&&this.__extends||(n=function(e,t){return n=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])},n(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}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__decorate||function(e,t,o,n){var r,i=arguments.length,u=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,o,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(u=(i<3?r(u):i>3?r(t,o,u):r(t,o))||u);return i>3&&u&&Object.defineProperty(t,o,u),u};Object.defineProperty(t,"__esModule",{value:!0}),t.ScoreCondition=void 0;var u=o(294),s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.getValue=function(e,t){if((0,u.isString)(t)&&e instanceof u.Slots.Numeric){var o=this.variableFor(t);return o&&o.hasValue?e.toValue(o.value):void 0}return(0,u.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,u.isNumberFinite)(t)&&e.hasValue&&e.value<t;case"above":return(0,u.isNumberFinite)(t)&&e.hasValue&&e.value>t;case"between":case"not-between":var o=this.getValue(e.slot,this.props.to);return(0,u.isNumberFinite)(t)&&(0,u.isNumberFinite)(o)&&(e.hasValue&&e.value>=u.Num.min(t,o)&&e.value<=u.Num.max(t,o))===("between"===this.props.mode);case"defined":return e.hasValue;case"undefined":return!e.hasValue}}return!1},i([u.condition],t.prototype,"verify",null),t=i([(0,u.tripetto)({type:"condition",legacyBlock:!0,identifier:"".concat("@tripetto/block-dropdown",":score")})],t)}(u.ConditionBlock);t.ScoreCondition=s},58:function(e,t,o){var n,r=this&&this.__extends||(n=function(e,t){return n=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])},n(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}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},i.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.Dropdown=void 0;var u=o(294),s=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.scoreSlot=t.valueOf("score","feature"),t.dropdownSlot=(0,u.assert)(t.valueOf("option","static",{confirm:!0,modifier:function(e){if(e.value){if(!e.reference){var o=(0,u.findFirst)(t.props.options,(function(t){return t.value===e.value}))||(0,u.findFirst)(t.props.options,(function(t){return t.id===e.value}))||(0,u.findFirst)(t.props.options,(function(t){return t.name===e.value}))||(0,u.findFirst)(t.props.options,(function(t){return t.name.toLowerCase()===e.value.toLowerCase()}));return{value:o&&(o.value||o.name),reference:o&&o.id,display:null==o?void 0:o.name}}if(!(0,u.findFirst)(t.props.options,(function(t){return t.id===e.reference})))return{value:void 0,reference:void 0,display:void 0}}},onChange:function(e){if(t.scoreSlot){var o=(0,u.findFirst)(t.props.options,(function(t){return t.id===e.reference}));t.scoreSlot.set(o&&((null==o?void 0:o.score)||0))}}})),t.required=t.dropdownSlot.slot.required||!1,t}return r(t,e),Object.defineProperty(t.prototype,"options",{get:function(){var e,t=this,o=(null===(e=this.props.options)||void 0===e?void 0:e.map((function(e){return i(i({},e),{name:(0,u.markdownifyToString)(e.name,t.context)})})))||[];if(this.props.randomize&&o.length>1){if(!this.randomized||this.randomized.length!==o.length||(0,u.findFirst)(this.randomized,(function(e){var t;return(null===(t=o[e.index])||void 0===t?void 0:t.id)!==e.id}))){this.randomized=o.map((function(e,t){return{index:t,id:e.id}}));for(var n=this.randomized.length;--n;){var r=Math.floor(Math.random()*n),s=this.randomized[n];this.randomized[n]=this.randomized[r],this.randomized[r]=s}}return this.randomized.map((function(e){return o[e.index]}))}return this.randomized&&(this.randomized=void 0),o},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){var e=this,t=(0,u.findFirst)(this.props.options,(function(t){return t.id===e.dropdownSlot.reference}));if(!t&&!this.node.placeholder){var o=(0,u.findFirst)(this.props.options,(function(e){return!!e.name}));return this.dropdownSlot.default(o&&(o.value||o.name),o&&o.id),o&&o.id||""}return t&&t.id||""},set:function(e){this.select((0,u.findFirst)(this.props.options,(function(t){return t.id===e})))},enumerable:!1,configurable:!0}),t.prototype.select=function(e){return this.dropdownSlot.set(e&&(e.value||e.name),e&&e.id,null==e?void 0:e.name),e&&e.id||""},t}(u.NodeBlock);t.Dropdown=s},294:function(t){t.exports=e}},o={};function n(e){var r=o[e];if(void 0!==r)return r.exports;var i=o[e]={exports:{}};return t[e].call(i.exports,i,i.exports,n),i.exports}var r={};return function(){var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.Dropdown=void 0,n(566),n(502);var t=n(58);Object.defineProperty(e,"Dropdown",{enumerable:!0,get:function(){return t.Dropdown}})}(),r}()}));