@tripetto/block-multiple-choice
Version:
Multiple choice block for Tripetto.
3 lines (2 loc) • 35.2 kB
JavaScript
/*! Tripetto Multiple Choice Block 7.0.1 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */
import{Collection as e,isString as i,markdownifyToString as t,Markdown as o,Slots as l,pgettext as c,Forms as a,insertVariable as s,REGEX_IS_URL as n,isBoolean as u,definition as r,name as h,affects as d,alias as b,score as p,created as m,reordered as M,renamed as g,refreshed as v,deleted as N,editor as w,collection as A,detached as I,tripetto as L,ConditionBlock as S,isFilledString as k,arraySize as j,isNumberFinite as D,L10n as y,lookupVariable as x,populateVariables as f,supplies as C,NodeBlock as T,npgettext as z,isNumber as E,each as U,slots as Y,conditions as O}from"@tripetto/builder";function V(e,i,t,o){var l,c=arguments.length,a=c<3?i:null===o?o=Object.getOwnPropertyDescriptor(i,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,i,t,o);else for(var s=e.length-1;s>=0;s--)(l=e[s])&&(a=(c<3?l(a):c>3?l(i,t,a):l(i,t))||a);return c>3&&a&&Object.defineProperty(i,t,a),a}class F extends e.Item{constructor(){super(...arguments),this.name=""}defineSlot(){if(this.ref.multiple&&!i(this.url)){const e=this.name&&t(this.name,o.MarkdownFeatures.Formatting|o.MarkdownFeatures.Hyperlinks)||void 0,i=this.ref.slots.dynamic({type:l.Boolean,reference:this.id,label:c("block:multiple-choice","Choice"),sequence:this.index,name:e,alias:this.value,required:this.ref.required,exportable:"concatenate"!==this.ref.format&&this.ref.exportable,pipeable:{label:c("block:multiple-choice","Choice"),content:this.moniker?{string:e||"",markdown:this.moniker}:this.name!==e?{string:e||"",markdown:this.name}:"name",alias:this.ref.alias,legacy:"Choice"}});i.labelForTrue=this.labelForTrue||this.ref.labelForTrue||c("block:multiple-choice","Selected"),i.labelForFalse=this.labelForFalse||this.ref.labelForFalse||c("block:multiple-choice","Not selected")}else this.deleteSlot()}deleteSlot(){this.ref.slots.delete(this.id,"dynamic")}defineEditor(){this.editor.option({name:c("block:multiple-choice","Name"),form:{title:c("block:multiple-choice","Choice name"),controls:[new a.Text("singleline",a.Text.bind(this,"name","")).action("@",s(this)).autoFocus().autoSelect().enter(this.editor.close).escape(this.editor.close)]},locked:!0}),this.editor.option({name:c("block:multiple-choice","Description"),form:{title:c("block:multiple-choice","Choice description"),controls:[new a.Text("singleline",a.Text.bind(this,"description",void 0)).action("@",s(this))]},activated:i(this.description)}),this.editor.group(c("block:multiple-choice","Options"));const e=new a.Checkbox(c("block:multiple-choice","Open in new tab/window"),"self"!==this.target).on((e=>{this.target=e.isFeatureEnabled&&!e.isDisabled?e.isChecked?"blank":"self":void 0}));this.editor.option({name:c("block:multiple-choice","URL"),form:{title:c("block:multiple-choice","URL"),controls:[new a.Text("singleline",a.Text.bind(this,"url",void 0)).placeholder("https://").action("@",s(this)).autoValidate((e=>""===e.value?"unknown":n.test(e.value)||(0===e.value.indexOf("mailto:")||0===e.value.indexOf("tel:"))&&e.value.length>10?"pass":"fail")).on((i=>{e.isDisabled=0===i.value.indexOf("mailto:")||0===i.value.indexOf("tel:")})),e,new a.Static(c("block:multiple-choice","If a URL is set, clicking the choice will open it. The choice cannot be selected as answer."))]},activated:i(this.url),on:e=>{t.disabled(e.isActivated),d.disabled(e.isActivated),o.disabled(e.isActivated||!this.ref.multiple),h.disabled(e.isActivated||!this.ref.multiple)}});const t=this.editor.option({name:c("block:multiple-choice","Moniker"),form:{title:c("block:multiple-choice","Choice moniker"),controls:[new a.Text("singleline",a.Text.bind(this,"moniker",void 0)).action("@",s(this)),new a.Static(c("block:multiple-choice","If a moniker is set, this moniker will be used when referred to this choice."))]},activated:i(this.moniker),disabled:i(this.url)});this.editor.option({name:c("block:multiple-choice","Color"),form:{title:c("block:multiple-choice","Choice color"),controls:[new a.ColorPicker(a.ColorPicker.bind(this,"color",void 0)).placeholder(c("block:multiple-choice","Select an alternative color for this choice")).swatches(!1,!0),new a.Static(c("block:multiple-choice","Here you can specify an alternative color for the choice button."))]},activated:i(this.color)});const o=this.editor.option({name:c("block:multiple-choice","Exclusivity"),form:{title:c("block:multiple-choice","Choice exclusivity"),controls:[new a.Checkbox(c("block:multiple-choice","Unselect all other selected choices when selected"),a.Checkbox.bind(this,"exclusive",void 0,!0))]},activated:this.ref.multiple&&!i(this.url)&&u(this.exclusive)||!1,disabled:!this.ref.multiple||i(this.url)}),l=c("block:multiple-choice","Selected"),r=c("block:multiple-choice","Not selected"),h=this.editor.option({name:c("block:multiple-choice","Labels"),form:{title:c("block:multiple-choice","Labels"),controls:[new a.Text("singleline",a.Text.bind(this,"labelForTrue",void 0)).placeholder(l),new a.Text("singleline",a.Text.bind(this,"labelForFalse",void 0)).placeholder(r),new a.Static(c("block:multiple-choice","These labels will be used in the dataset and override the default values %1 and %2.",`**${l}**`,`**${r}**`)).markdown()]},activated:i(this.labelForTrue)||i(this.labelForFalse),disabled:!this.ref.multiple||i(this.url)}),d=this.editor.option({name:c("block:multiple-choice","Identifier"),form:{title:c("block:multiple-choice","Choice identifier"),controls:[new a.Text("singleline",a.Text.bind(this,"value",void 0)),new a.Static(c("block:multiple-choice","If a choice identifier is set, this identifier will be used instead of the label."))]},activated:i(this.value),disabled:i(this.url)}),b=this.ref.slots.select("score","feature");this.editor.option({name:c("block:multiple-choice","Score"),form:{title:c("block:multiple-choice","Score"),controls:[new a.Numeric(a.Numeric.bind(this,"score",void 0)).precision((null==b?void 0:b.precision)||0).digits((null==b?void 0:b.digits)||0).decimalSign((null==b?void 0:b.decimal)||"").thousands(!!(null==b?void 0:b.separator),(null==b?void 0:b.separator)||"").prefix((null==b?void 0:b.prefix)||"").prefixPlural((null==b?void 0:b.prefixPlural)||void 0).suffix((null==b?void 0:b.suffix)||"").suffixPlural((null==b?void 0:b.suffixPlural)||void 0)]},activated:!0,locked:!!b,disabled:!b})}}V([r("string"),h],F.prototype,"name",void 0),V([r("string","optional")],F.prototype,"description",void 0),V([r("string","optional"),d("#refresh")],F.prototype,"url",void 0),V([r("string","optional")],F.prototype,"target",void 0),V([r("string","optional"),d("#refresh")],F.prototype,"moniker",void 0),V([r("string","optional"),b],F.prototype,"value",void 0),V([r("string","optional"),d("#refresh")],F.prototype,"labelForTrue",void 0),V([r("string","optional"),d("#refresh")],F.prototype,"labelForFalse",void 0),V([r("number","optional"),p],F.prototype,"score",void 0),V([r("boolean","optional"),d("#name")],F.prototype,"exclusive",void 0),V([r("string","optional")],F.prototype,"color",void 0),V([m,M,g,v],F.prototype,"defineSlot",null),V([N],F.prototype,"deleteSlot",null),V([w],F.prototype,"defineEditor",null);var Z="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTEwIDIwYy0yLjY3MSAwLTUuMTgyLTEuMDQtNy4wNzEtMi45MjlTMCAxMi42NzEgMCAxMGMwLTIuNjcxIDEuMDQtNS4xODIgMi45MjktNy4wNzFTNy4zMjkgMCAxMCAwYzIuNjcxIDAgNS4xODIgMS4wNCA3LjA3MSAyLjkyOVMyMCA3LjMyOSAyMCAxMGMwIDIuNjcxLTEuMDQgNS4xODItMi45MjkgNy4wNzFTMTIuNjcxIDIwIDEwIDIwem0wLTE5Yy00Ljk2MyAwLTkgNC4wMzctOSA5czQuMDM3IDkgOSA5IDktNC4wMzcgOS05LTQuMDM3LTktOS05eiIgY2xhc3M9InRyaXBldHRvLWZpbGwiLz48cGF0aCBkPSJNMTAgMTZjLTMuMzA4IDAtNi0yLjY5Mi02LTZzMi42OTItNiA2LTYgNiAyLjY5MiA2IDYtMi42OTIgNi02IDZ6bTAtMTFjLTIuNzU3IDAtNSAyLjI0My01IDVzMi4yNDMgNSA1IDUgNS0yLjI0MyA1LTUtMi4yNDMtNS01LTV6IiBjbGFzcz0idHJpcGV0dG8tZmlsbCIvPjwvc3ZnPg==",P="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggY2xhc3M9InRyaXBldHRvLWZpbGwiIGQ9Ik0xOCAxOS41SDJjLS44MjcgMC0xLjUtLjY3My0xLjUtMS41VjJDLjUgMS4xNzMgMS4xNzMuNSAyIC41aDE2Yy44MjcgMCAxLjUuNjczIDEuNSAxLjV2MTZjMCAuODI3LS42NzMgMS41LTEuNSAxLjV6TTIgMS41YS41LjUgMCAwIDAtLjUuNXYxNmEuNS41IDAgMCAwIC41LjVoMTZhLjUuNSAwIDAgMCAuNS0uNVYyYS41LjUgMCAwIDAtLjUtLjV6Ii8+PHBhdGggY2xhc3M9InRyaXBldHRvLWZpbGwiIGQ9Ik04IDE0YS41MDIuNTAyIDAgMCAxLS4zNTQtLjE0NmwtMy0zYS41LjUgMCAwIDEgLjcwNy0uNzA3bDIuNjQ2IDIuNjQ2IDYuNjQ2LTYuNjQ2YS41LjUgMCAwIDEgLjcwNy43MDdsLTcgN2EuNDk4LjQ5OCAwIDAgMS0uMzU0LjE0NnoiLz48L3N2Zz4=";let R=class extends S{get icon(){var e,i;return(null===(e=this.node)||void 0===e?void 0:e.block)instanceof $&&(null===(i=this.node)||void 0===i?void 0:i.block.multiple)?P:Z}get name(){var e;return(null===(e=this.choice)||void 0===e?void 0:e.name)||this.type.label}get label(){var e;return(null===(e=this.node)||void 0===e?void 0:e.block)instanceof $&&(this.node.block.alias||this.node.label)||""}get choices(){return this.node&&this.node.block instanceof $&&this.node.block.choices||void 0}migrate(){var e;if(this.choice&&(null===(e=this.node)||void 0===e?void 0:e.block)instanceof $){const e=this.node.block.slots,i=this.node.block.multiple?this.choice.id:"choice";return()=>{var t;return(null===(t=this.node)||void 0===t?void 0:t.block)instanceof $&&(this.slot=e.select(i),!0)}}}defineEditor(){if(this.node&&this.choices){const e=[];this.choices.each((i=>{k(i.name)&&e.push({label:t(i.name),value:i})})),j(e)>0&&this.editor.form({title:this.node.label,controls:[new a.Dropdown(e,a.Dropdown.bind(this,"choice",void 0))]})}}};V([d("#condition"),A("#choices")],R.prototype,"choice",void 0),V([I("slot")],R.prototype,"migrate",null),V([w],R.prototype,"defineEditor",null),R=V([L({type:"condition",legacyBlock:!0,context:"@tripetto/block-multiple-choice",identifier:"@tripetto/block-multiple-choice",version:"7.0.1",alias:"multiple-choice",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE2LjIzIDMuMzA3Yy0uMzk2LS4yNjgtLjk0OS0uNTA0LTEuNjQzLS43MDJDMTMuMjIxIDIuMjE1IDExLjQxNSAyIDkuNSAycy0zLjcyMi4yMTUtNS4wODcuNjA1Yy0uNjk0LjE5OC0xLjI0Ni40MzQtMS42NDMuNzAyLS42MzcuNDMtLjc3Ljg4Ni0uNzcgMS4xOTNWNWMwIC40MjguMzIxIDEuMTMzLjYzOSAxLjYwOWw0Ljg5MSA3LjMzNmMuMjUxLjM3Ni40NzEgMS4xMDMuNDcxIDEuNTU1djNhLjUuNSAwIDAgMCAuNzI0LjQ0N2wyLTFhLjUuNSAwIDAgMCAuMjc2LS40NDd2LTJjMC0uNDUyLjIyLTEuMTc5LjQ3MS0xLjU1NWw0Ljg5MS03LjMzNmMuMzE3LS40NzYuNjM5LTEuMTgyLjYzOS0xLjYwOXYtLjVjMC0uMzA3LS4xMzQtLjc2My0uNzctMS4xOTN6bS0xMS41NDIuMjZDNS45NjcgMy4yMDIgNy42NzYgMyA5LjUgM3MzLjUzNC4yMDEgNC44MTIuNTY3QzE1LjY5IDMuOTYxIDE2IDQuMzgzIDE2IDQuNXMtLjMxLjU0LTEuNjg4LjkzM0MxMy4wMzMgNS43OTggMTEuMzI0IDYgOS41IDZzLTMuNTM0LS4yMDEtNC44MTItLjU2N0MzLjMxIDUuMDM5IDMgNC42MTcgMyA0LjVzLjMxLS41NCAxLjY4OC0uOTMzem01Ljk1MSA5LjgyNGMtLjM1OC41MzctLjYzOSAxLjQ2NC0uNjM5IDIuMTA5djEuNjkxbC0xIC41VjE1LjVjMC0uNjQ2LS4yODEtMS41NzItLjYzOS0yLjEwOWwtNC44OC03LjMyYy4yNzQuMTE3LjU4NS4yMjYuOTMyLjMyNEM1Ljc3OSA2Ljc4NSA3LjU4NSA3IDkuNSA3czMuNzIyLS4yMTUgNS4wODctLjYwNWMuMzQ2LS4wOTkuNjU4LS4yMDcuOTMyLS4zMjVsLTQuODggNy4zMnoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+",get label(){return c("block:multiple-choice","Choice")}})],R);let H=class extends S{};H=V([L({type:"condition",legacyBlock:!0,context:"@tripetto/block-multiple-choice",identifier:"@tripetto/block-multiple-choice:undefined",version:"7.0.1",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0ibTEwLjcwNyAxMC41IDUuNjQ2LTUuNjQ2YS41LjUgMCAwIDAtLjcwNy0uNzA3TDEwIDkuNzkzIDQuMzU0IDQuMTQ3YS41LjUgMCAwIDAtLjcwNy43MDdMOS4yOTMgMTAuNWwtNS42NDYgNS42NDZhLjUuNSAwIDAgMCAuNzA4LjcwN2w1LjY0Ni01LjY0NiA1LjY0NiA1LjY0NmEuNDk4LjQ5OCAwIDAgMCAuNzA4IDAgLjUuNSAwIDAgMCAwLS43MDdMMTAuNzA5IDEwLjV6IiBjbGFzcz0idHJpcGV0dG8tZmlsbCIvPjwvc3ZnPg==",get label(){return c("block:multiple-choice","No choice made")}})],H);var q="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE4LjUgOEgxM1YzLjVhLjUuNSAwIDAgMC0uNS0uNWgtNmEuNS41IDAgMCAwLS41LjVWNkguNWEuNS41IDAgMCAwLS41LjV2MTBhLjUuNSAwIDAgMCAuNS41aDE4YS41LjUgMCAwIDAgLjUtLjV2LThhLjUuNSAwIDAgMC0uNS0uNXpNNyA0aDV2MTJIN1Y0ek0xIDdoNXY5SDFWN3ptMTcgOWgtNVY5aDV2N3oiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PHBhdGggZD0iTTkuNSAxMGEuNS41IDAgMCAxLS41LS41di00YS41LjUgMCAwIDEgMSAwdjRhLjUuNSAwIDAgMS0uNS41em0tNSAzaC0yYS41LjUgMCAwIDEtLjUtLjV2LTJhLjUuNSAwIDAgMSAuNS0uNUg0VjlIMi41YS41LjUgMCAwIDEgMC0xaDJhLjUuNSAwIDAgMSAuNS41djJhLjUuNSAwIDAgMS0uNS41SDN2MWgxLjVhLjUuNSAwIDAgMSAwIDF6bTEyLTNoLTJhLjUuNSAwIDAgMCAwIDFIMTZ2MWgtMS41YS41LjUgMCAwIDAgMCAxSDE2djFoLTEuNWEuNS41IDAgMCAwIDAgMWgyYS41LjUgMCAwIDAgLjUtLjV2LTRhLjUuNSAwIDAgMC0uNS0uNXoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+";let Q=class extends S{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="equal"}get label(){return""}get name(){const e=this.slot;if(e instanceof l.Numeric){const i=this.parse(e,this.value);switch(this.mode){case"between":return`${i} ≤ @${e.id} ≤ ${this.parse(e,this.to)}`;case"not-between":return`@${e.id} < ${i} ${c("block:multiple-choice","or")} @${e.id} > ${this.parse(e,this.to)}`;case"defined":return`@${e.id} ${c("block:multiple-choice","calculated")}`;case"undefined":return`@${e.id} ${c("block:multiple-choice","not calculated")}`;case"not-equal":return`@${e.id} ≠ ${i}`;case"above":case"below":case"equal":return`@${e.id} ${"above"===this.mode?">":"below"===this.mode?"<":"="} ${i}`}}return this.type.label}get title(){var e,i;return(null===(e=this.slot)||void 0===e?void 0:e.label)||(null===(i=this.node)||void 0===i?void 0:i.label)}parse(e,t){var o;return D(t)?e.toString(t,((e,i)=>y.locale.number(e,i,!1))):i(t)&&t&&(null===(o=x(this,t))||void 0===o?void 0:o.label)?`@${t}`:"\\_\\_"}defineEditor(){this.editor.form({title:c("block:multiple-choice","Compare mode"),controls:[new a.Radiobutton([{label:c("block:multiple-choice","Score is equal to"),value:"equal"},{label:c("block:multiple-choice","Score is not equal to"),value:"not-equal"},{label:c("block:multiple-choice","Score is lower than"),value:"below"},{label:c("block:multiple-choice","Score is higher than"),value:"above"},{label:c("block:multiple-choice","Score is between"),value:"between"},{label:c("block:multiple-choice","Score is not between"),value:"not-between"},{label:c("block:multiple-choice","Score is calculated"),value:"defined"},{label:c("block:multiple-choice","Score is not calculated"),value:"undefined"}],a.Radiobutton.bind(this,"mode","equal")).on((e=>{switch(t.visible("defined"!==e.value&&"undefined"!==e.value),o.visible("between"===e.value||"not-between"===e.value),e.value){case"equal":t.title=c("block:multiple-choice","If score equals");break;case"not-equal":t.title=c("block:multiple-choice","If score not equals");break;case"below":t.title=c("block:multiple-choice","If score is lower than");break;case"above":t.title=c("block:multiple-choice","If score is higher than");break;case"between":t.title=c("block:multiple-choice","If score is between");break;case"not-between":t.title=c("block:multiple-choice","If score is not between")}}))]});const e=(e,t,o)=>{var s;const n=this[e],u=this.slot,r=new a.Numeric(D(n)?n:0).label(c("block:multiple-choice","Use fixed number")).precision((null==u?void 0:u.precision)||0).digits((null==u?void 0:u.digits)||0).decimalSign((null==u?void 0:u.decimal)||"").thousands(!!(null==u?void 0:u.separator),(null==u?void 0:u.separator)||"").prefix((null==u?void 0:u.prefix)||"").prefixPlural((null==u?void 0:u.prefixPlural)||void 0).suffix((null==u?void 0:u.suffix)||"").suffixPlural((null==u?void 0:u.suffixPlural)||void 0).autoFocus("value"===e).escape(this.editor.close).enter((()=>("between"!==this.mode&&"not-between"!==this.mode||"to"===e)&&this.editor.close())).on((i=>{i.isFormVisible&&i.isObservable&&(this[e]=i.value)})),h=f(this,(e=>e instanceof l.Number||e instanceof l.Numeric),i(n)?n:void 0,!0,null===(s=this.slot)||void 0===s?void 0:s.id),d=new a.Dropdown(h,i(n)?n:"").label(c("block:multiple-choice","Use value of")).width("full").on((i=>{i.isFormVisible&&i.isObservable&&(this[e]=i.value||"")}));return this.editor.form({title:t,controls:[new a.Radiobutton([{label:c("block:multiple-choice","Number"),value:"number"},{label:c("block:multiple-choice","Value"),value:"variable",disabled:0===h.length}],i(n)?"variable":"number").on((e=>{r.visible("number"===e.value),d.visible("variable"===e.value),r.isObservable&&r.focus()})),r,d]}).visible(o)},t=e("value",c("block:multiple-choice","If score equals"),"defined"!==this.mode&&"undefined"!==this.mode),o=e("to",c("block:multiple-choice","And"),"between"===this.mode||"not-between"===this.mode)}};V([r,d("#name")],Q.prototype,"mode",void 0),V([r,d("#name")],Q.prototype,"value",void 0),V([r,d("#name")],Q.prototype,"to",void 0),V([w],Q.prototype,"defineEditor",null),Q=V([L({type:"condition",legacyBlock:!0,context:"@tripetto/block-multiple-choice",identifier:"@tripetto/block-multiple-choice:score",version:"7.0.1",icon:q,get label(){return c("block:multiple-choice","Verify score")}})],Q);var G="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTIgNmEuNTAyLjUwMiAwIDAgMS0uMzU0LS4xNDZsLTEuNS0xLjVhLjUuNSAwIDAgMSAuNzA3LS43MDdsMS4xNDYgMS4xNDZMNi4xNDUuNjQ3YS41LjUgMCAwIDEgLjcwNy43MDdsLTQuNSA0LjVBLjQ5OC40OTggMCAwIDEgMS45OTggNnptMTcuNS0xaC0xMmEuNS41IDAgMCAxIDAtMWgxMmEuNS41IDAgMCAxIDAgMXpNMiAxM2EuNTAyLjUwMiAwIDAgMS0uMzU0LS4xNDZsLTEuNS0xLjVhLjUuNSAwIDAgMSAuNzA3LS43MDdsMS4xNDYgMS4xNDYgNC4xNDYtNC4xNDZhLjUuNSAwIDAgMSAuNzA3LjcwN2wtNC41IDQuNWEuNDk4LjQ5OCAwIDAgMS0uMzU0LjE0NnptMTcuNS0xaC0xMmEuNS41IDAgMCAxIDAtMWgxMmEuNS41IDAgMCAxIDAgMXpNMiAyMGEuNTAyLjUwMiAwIDAgMS0uMzU0LS4xNDZsLTEuNS0xLjVhLjUuNSAwIDAgMSAuNzA3LS43MDdsMS4xNDYgMS4xNDYgNC4xNDYtNC4xNDZhLjUuNSAwIDAgMSAuNzA3LjcwN2wtNC41IDQuNWEuNDk4LjQ5OCAwIDAgMS0uMzU0LjE0NnptMTcuNS0xaC0xMmEuNS41IDAgMCAxIDAtMWgxMmEuNS41IDAgMCAxIDAgMXoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+";let W=class extends S{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="equal"}get label(){return""}get name(){const e=this.slot;if(e instanceof l.Number){const i=this.parse(e,this.value);switch(this.mode){case"between":return`${i} ≤ @${e.id} ≤ ${this.parse(e,this.to)}`;case"not-between":return`@${e.id} < ${i} ${c("block:multiple-choice","or")} @${e.id} > ${this.parse(e,this.to)}`;case"not-equal":return`@${e.id} ≠ ${i}`;case"above":case"below":case"equal":return`@${e.id} ${"above"===this.mode?">":"below"===this.mode?"<":"="} ${i}`}}return this.type.label}get title(){var e,i;return(null===(e=this.slot)||void 0===e?void 0:e.label)||(null===(i=this.node)||void 0===i?void 0:i.label)}parse(e,t){var o;return D(t)?e.toString(t,(e=>y.locale.number(e,0,!1))):i(t)&&t&&(null===(o=x(this,t))||void 0===o?void 0:o.label)?`@${t}`:"\\_\\_"}defineEditor(){this.editor.form({title:c("block:multiple-choice","Compare mode"),controls:[new a.Radiobutton([{label:c("block:multiple-choice","Counter is equal to"),value:"equal"},{label:c("block:multiple-choice","Counter is not equal to"),value:"not-equal"},{label:c("block:multiple-choice","Counter is lower than"),value:"below"},{label:c("block:multiple-choice","Counter is higher than"),value:"above"},{label:c("block:multiple-choice","Counter is between"),value:"between"},{label:c("block:multiple-choice","Counter is not between"),value:"not-between"}],a.Radiobutton.bind(this,"mode","equal")).on((e=>{switch(o.visible("between"===e.value||"not-between"===e.value),e.value){case"equal":t.title=c("block:multiple-choice","If counter equals");break;case"not-equal":t.title=c("block:multiple-choice","If counter not equals");break;case"below":t.title=c("block:multiple-choice","If counter is lower than");break;case"above":t.title=c("block:multiple-choice","If counter is higher than");break;case"between":t.title=c("block:multiple-choice","If counter is between");break;case"not-between":t.title=c("block:multiple-choice","If counter is not between")}}))]});const e=(e,t)=>{var o;const s=this[e],n=new a.Numeric(D(s)?s:0).label(c("block:multiple-choice","Use fixed number")).autoFocus("value"===e).escape(this.editor.close).enter((()=>("between"!==this.mode&&"not-between"!==this.mode||"to"===e)&&this.editor.close())).on((i=>{i.isFormVisible&&i.isObservable&&(this[e]=i.value)})),u=f(this,(e=>e instanceof l.Number||e instanceof l.Numeric),i(s)?s:void 0,!0,null===(o=this.slot)||void 0===o?void 0:o.id),r=new a.Dropdown(u,i(s)?s:"").label(c("block:multiple-choice","Use value of")).width("full").on((i=>{i.isFormVisible&&i.isObservable&&(this[e]=i.value||"")}));return this.editor.form({title:t,controls:[new a.Radiobutton([{label:c("block:multiple-choice","Number"),value:"number"},{label:c("block:multiple-choice","Value"),value:"variable",disabled:0===u.length}],i(s)?"variable":"number").on((e=>{n.visible("number"===e.value),r.visible("variable"===e.value),n.isObservable&&n.focus()})),n,r]})},t=e("value",c("block:multiple-choice","If counter equals")),o=e("to",c("block:multiple-choice","And"))}};V([r,d("#name")],W.prototype,"mode",void 0),V([r,d("#name")],W.prototype,"value",void 0),V([r,d("#name")],W.prototype,"to",void 0),V([w],W.prototype,"defineEditor",null),W=V([L({type:"condition",legacyBlock:!0,context:"@tripetto/block-multiple-choice",identifier:"@tripetto/block-multiple-choice:counter",version:"7.0.1",icon:G,get label(){return c("block:multiple-choice","Verify counter")}})],W);let $=class extends T{constructor(){super(...arguments),this.choices=e.of(F,this)}get label(){return z("block:multiple-choice","%2 (%1 option)","%2 (%1 options)",this.choices.count,this.type.label)}defineSlot(){this.multiple?(this.slots.delete("choice","static"),this.slots.meta({type:l.Number,reference:"counter",label:c("block:multiple-choice","Counter"),exportable:!1,protected:!0}),"concatenate"===this.format||"both"===this.format?this.slots.feature({type:l.Text,reference:"concatenation",label:c("block:multiple-choice","Text value"),exportable:this.exportable,alias:this.alias,protected:!0}):this.slots.delete("concatenation","feature")):(this.slots.delete("counter","meta"),this.slots.delete("concatenation","feature"),this.slots.static({type:l.String,reference:"choice",label:c("block:multiple-choice","Choice"),alias:this.alias,required:this.required,exportable:this.exportable,exchange:["alias","required","exportable"]}))}defineEditor(){this.editor.name(!0,!0),this.editor.option({name:c("block:multiple-choice","Caption"),form:{title:c("block:multiple-choice","Caption"),controls:[new a.Text("multiline",a.Text.bind(this,"caption",void 0)).placeholder(c("block:multiple-choice","Type caption text here...")).action("@",s(this))]},activated:i(this.caption)}),this.editor.description(),this.editor.option({name:c("block:multiple-choice","Image"),form:{title:c("block:multiple-choice","Image"),controls:[new a.Text("singleline",a.Text.bind(this,"imageURL",void 0)).label(c("block:multiple-choice","Image source URL")).inputMode("url").placeholder("https://").action("@",s(this)).autoValidate((e=>""===e.value?"unknown":n.test(e.value)||e.value.length>23&&0===e.value.indexOf("data:image/jpeg;base64,")||e.value.length>22&&0===e.value.indexOf("data:image/png;base64,")||e.value.length>22&&0===e.value.indexOf("data:image/svg;base64,")||e.value.length>22&&0===e.value.indexOf("data:image/gif;base64,")||e.value.length>1&&"/"===e.value.charAt(0)?"pass":"fail")),new a.Text("singleline",a.Checkbox.bind(this,"imageWidth",void 0)).label(c("block:multiple-choice","Image width (optional)")).width(100).align("center"),new a.Checkbox(c("block:multiple-choice","Display image on top of the paragraph"),a.Checkbox.bind(this,"imageAboveText",void 0))]},activated:i(this.imageURL)}),this.editor.explanation();const e=this.editor.collection({collection:this.choices,title:c("block:multiple-choice","Choices"),placeholder:c("block:multiple-choice","Unnamed choice"),icon:this.multiple?P:Z,autoOpen:!0,allowVariables:!0,allowImport:!0,allowExport:!0,allowDedupe:!0,showAliases:!0,markdown:o.MarkdownFeatures.Formatting|o.MarkdownFeatures.Hyperlinks,sorting:"manual",indicator:e=>this.multiple&&e.exclusive&&c("block:multiple-choice","Exclusive").toUpperCase()||void 0,emptyMessage:c("block:multiple-choice","Click the + button to add a choice...")});this.editor.groups.settings(),this.editor.option({name:c("block:multiple-choice","Multiple select"),form:{title:c("block:multiple-choice","Multiple select"),controls:[new a.Checkbox(c("block:multiple-choice","Allow the selection of multiple choices"),a.Checkbox.bind(this,"multiple",void 0,!0)).on((()=>{r.disabled(!this.multiple),b.disabled(!this.multiple),g.disabled(!this.multiple),p.disabled(this.multiple&&"concatenate"!==this.format&&"both"!==this.format||!1),e.icon=this.multiple?P:Z,this.choices.each((e=>{!0===e.exclusive&&e.refresh("name")}))}))]},activated:u(this.multiple)});const t=new a.Numeric(a.Numeric.bind(this,"min",void 0)).min(1).max(this.max).visible(E(this.min)).indent(32).width(75).on((()=>{l.min(this.min||1)})),l=new a.Numeric(a.Numeric.bind(this,"max",void 0)).min(this.min||1).visible(E(this.max)).indent(32).width(75).on((()=>{t.max(this.max)})),r=this.editor.option({name:c("block:multiple-choice","Limits"),form:{title:c("block:multiple-choice","Limits"),controls:[new a.Checkbox(c("block:multiple-choice","Minimum number of selected choices"),E(this.min)).on((e=>{t.visible(e.isChecked)})),t,new a.Checkbox(c("block:multiple-choice","Maximum number of selected choices"),E(this.max)).on((e=>{l.visible(e.isChecked)})),l]},activated:E(this.max)||E(this.min),disabled:!this.multiple});this.editor.option({name:c("block:multiple-choice","Randomization"),form:{title:c("block:multiple-choice","Randomization"),controls:[new a.Checkbox(c("block:multiple-choice","Randomize the choices (using [Fisher-Yates shuffle](%1))","https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle"),a.Checkbox.bind(this,"randomize",void 0,!0)).markdown()]},activated:u(this.randomize)}),this.editor.option({name:c("block:multiple-choice","Alignment"),form:{title:c("block:multiple-choice","Alignment"),controls:[new a.Radiobutton([{label:c("block:multiple-choice","Vertical - Variable width"),description:c("block:multiple-choice","Display choices vertically (top-down). All choices have their own width."),value:!1},{label:c("block:multiple-choice","Vertical - Equal width"),description:c("block:multiple-choice","Display choices vertically (top-down). All choices have equal widths, determined by the widest choice."),value:"equal"},{label:c("block:multiple-choice","Vertical - Full width"),description:c("block:multiple-choice","Display choices vertically (top-down). All choices have 100% widths, with text centered."),value:"full"},{label:c("block:multiple-choice","Columns"),description:c("block:multiple-choice","Display choices in two columns. All choices have 100% widths inside their column. Both columns have 50% width."),value:"columns"},{label:c("block:multiple-choice","Horizontal"),description:c("block:multiple-choice","Display choices from left to right. All choices have their own width."),value:!0}],a.Radiobutton.bind(this,"alignment",void 0))]},activated:u(this.alignment)||"equal"===this.alignment||"full"===this.alignment||"columns"===this.alignment}),this.editor.groups.options(),this.editor.required(this),this.editor.visibility();const h=c("block:multiple-choice","Selected"),d=c("block:multiple-choice","Not selected"),b=this.editor.option({name:c("block:multiple-choice","Labels"),form:{title:c("block:multiple-choice","Labels"),controls:[new a.Text("singleline",a.Text.bind(this,"labelForTrue",void 0)).placeholder(h),new a.Text("singleline",a.Text.bind(this,"labelForFalse",void 0)).placeholder(d),new a.Static(c("block:multiple-choice","These labels will be used in the dataset and override the default values %1 and %2.",`**${h}**`,`**${d}**`)).markdown()]},activated:i(this.labelForTrue)||i(this.labelForFalse),disabled:!this.multiple});this.editor.scores({target:this,collection:e,description:c("block:multiple-choice","Generates a score based on the selected choices. Open the settings panel for each choice to set the individual score for that choice.")});const p=this.editor.alias(this).disabled(this.multiple&&"concatenate"!==this.format&&"both"!==this.format||!1),m=new a.Text("singleline",a.Text.bind(this,"formatSeparatorCustom",void 0)).visible("custom"===this.formatSeparator).sanitize(!1).width(200).label(c("block:multiple-choice","Use this separator:")),M=new a.Group([new a.Dropdown([{label:c("block:multiple-choice","Comma separated"),value:"comma"},{label:c("block:multiple-choice","Space separated"),value:"space"},{label:c("block:multiple-choice","List on multiple lines"),value:"list"},{label:c("block:multiple-choice","Bulleted list"),value:"bullets"},{label:c("block:multiple-choice","Numbered list"),value:"numbers"},{label:c("block:multiple-choice","Language sensitive conjunction (_, _, and _)"),value:"conjunction"},{label:c("block:multiple-choice","Language sensitive disjunction (_, _, or _)"),value:"disjunction"},{label:c("block:multiple-choice","Custom separator"),value:"custom"}],a.Radiobutton.bind(this,"formatSeparator",void 0,"comma")).label(c("block:multiple-choice","How to separate the selected choices:")).on((e=>{m.visible("custom"===e.value)})),m]).visible("concatenate"===this.format||"both"===this.format),g=this.editor.option({name:c("block:multiple-choice","Data format"),form:{title:c("block:multiple-choice","Data format"),controls:[new a.Radiobutton([{label:c("block:multiple-choice","Every choice as a separate field"),description:c("block:multiple-choice","Every choice is included in the dataset as a separate value."),value:"fields"},{label:c("block:multiple-choice","Text field with a list of all selected choices"),description:c("block:multiple-choice","All the selected choices are concatenated to a single string of text separated using a configurable separator."),value:"concatenate"},{label:c("block:multiple-choice","Both options above"),description:c("block:multiple-choice","Includes every choice in the dataset together with the concatenated text."),value:"both"}],a.Radiobutton.bind(this,"format",void 0,"fields")).label(c("block:multiple-choice","This setting determines how the data is stored in the dataset:")).on((e=>{M.visible("concatenate"===e.value||"both"===e.value),p.disabled(this.multiple&&"concatenate"!==this.format&&"both"!==this.format||!1)})),M]},activated:i(this.format),disabled:!this.multiple});this.editor.exportable(this)}defineConditions(){this.choices.each((e=>{e.name&&!i(e.url)&&this.conditions.template({condition:R,label:e.name,icon:this.multiple?P:Z,burst:"branch",props:{choice:e,slot:this.slots.select(this.multiple?e.id:"choice")}})})),this.choices.count>0&&this.conditions.template({condition:H,separator:!0});const e=this.slots.select("counter","meta");if(e&&e.label){const i=this.conditions.group(e.label,G);U([{mode:"equal",label:c("block:multiple-choice","Counter is equal to")},{mode:"not-equal",label:c("block:multiple-choice","Counter is not equal to")},{mode:"below",label:c("block:multiple-choice","Counter is lower than")},{mode:"above",label:c("block:multiple-choice","Counter is higher than")},{mode:"between",label:c("block:multiple-choice","Counter is between")},{mode:"not-between",label:c("block:multiple-choice","Counter is not between")}],(t=>{i.template({condition:W,label:t.label,autoOpen:!0,props:{slot:e,mode:t.mode,value:0,to:"between"===t.mode||"not-between"===t.mode?0:void 0}})}))}const t=this.slots.select("score","feature");if(t&&t.label){const e=this.conditions.group(t.label,q);U([{mode:"equal",label:c("block:multiple-choice","Score is equal to")},{mode:"not-equal",label:c("block:multiple-choice","Score is not equal to")},{mode:"below",label:c("block:multiple-choice","Score is lower than")},{mode:"above",label:c("block:multiple-choice","Score is higher than")},{mode:"between",label:c("block:multiple-choice","Score is between")},{mode:"not-between",label:c("block:multiple-choice","Score is not between")},{mode:"defined",label:c("block:multiple-choice","Score is calculated")},{mode:"undefined",label:c("block:multiple-choice","Score is not calculated")}],(i=>{e.template({condition:Q,label:i.label,autoOpen:"defined"!==i.mode&&"undefined"!==i.mode,props:{slot:t,mode:i.mode,value:0,to:"between"===i.mode||"not-between"===i.mode?0:void 0}})}))}}};V([r("string","optional")],$.prototype,"caption",void 0),V([r("string","optional")],$.prototype,"imageURL",void 0),V([r("string","optional")],$.prototype,"imageWidth",void 0),V([r("boolean","optional")],$.prototype,"imageAboveText",void 0),V([r("items"),d("#name"),C("#slot","choice")],$.prototype,"choices",void 0),V([r("boolean","optional"),d("#slots"),d("#collection","choices")],$.prototype,"multiple",void 0),V([r("number","optional")],$.prototype,"min",void 0),V([r("number","optional")],$.prototype,"max",void 0),V([r("alignment","optional")],$.prototype,"alignment",void 0),V([r("boolean","optional"),d("#required"),d("#slots"),d("#collection","choices")],$.prototype,"required",void 0),V([r("string","optional"),d("#slots"),d("#collection","choices"),d("#label")],$.prototype,"alias",void 0),V([r("boolean","optional"),d("#slots"),d("#collection","choices")],$.prototype,"exportable",void 0),V([r("string","optional"),d("#collection","choices")],$.prototype,"labelForTrue",void 0),V([r("string","optional"),d("#collection","choices")],$.prototype,"labelForFalse",void 0),V([r("boolean","optional")],$.prototype,"randomize",void 0),V([r("string","optional"),d("#slots"),d("#collection","choices")],$.prototype,"format",void 0),V([r("string","optional")],$.prototype,"formatSeparator",void 0),V([r("string","optional")],$.prototype,"formatSeparatorCustom",void 0),V([Y],$.prototype,"defineSlot",null),V([w],$.prototype,"defineEditor",null),V([O],$.prototype,"defineConditions",null),$=V([L({type:"node",legacyBlock:!0,identifier:"@tripetto/block-multiple-choice",version:"7.0.1",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE4LjUgN2gtMTJDNS42NzMgNyA1IDYuMzI3IDUgNS41UzUuNjczIDQgNi41IDRoMTJjLjgyNyAwIDEuNS42NzMgMS41IDEuNVMxOS4zMjcgNyAxOC41IDd6bS0xMi0yYS41LjUgMCAwIDAgMCAxaDEyYS41LjUgMCAwIDAgMC0xaC0xMnptMTIgN2gtMTJjLS44MjcgMC0xLjUtLjY3My0xLjUtMS41UzUuNjczIDkgNi41IDloMTJjLjgyNyAwIDEuNS42NzMgMS41IDEuNXMtLjY3MyAxLjUtMS41IDEuNXptLTEyLTJhLjUuNSAwIDAgMCAwIDFoMTJhLjUuNSAwIDAgMCAwLTFoLTEyem0xMiA3aC0xMmMtLjgyNyAwLTEuNS0uNjczLTEuNS0xLjVTNS42NzMgMTQgNi41IDE0aDEyYy44MjcgMCAxLjUuNjczIDEuNSAxLjVzLS42NzMgMS41LTEuNSAxLjV6bS0xMi0yYS41LjUgMCAwIDAgMCAxaDEyYS41LjUgMCAwIDAgMC0xaC0xMnptLTUtOEMuNjczIDcgMCA2LjMyNyAwIDUuNVMuNjczIDQgMS41IDQgMyA0LjY3MyAzIDUuNSAyLjMyNyA3IDEuNSA3em0wLTJhLjUuNSAwIDEgMCAwIDEgLjUuNSAwIDAgMCAwLTF6bTAgN0MuNjczIDEyIDAgMTEuMzI3IDAgMTAuNVMuNjczIDkgMS41IDkgMyA5LjY3MyAzIDEwLjUgMi4zMjcgMTIgMS41IDEyem0wLTJhLjUuNSAwIDEgMCAwIDEgLjUuNSAwIDAgMCAwLTF6bTAgN0MuNjczIDE3IDAgMTYuMzI3IDAgMTUuNVMuNjczIDE0IDEuNSAxNHMxLjUuNjczIDEuNSAxLjVTMi4zMjcgMTcgMS41IDE3em0wLTJhLjUuNSAwIDEgMCAwIDEgLjUuNSAwIDAgMCAwLTF6IiBjbGFzcz0idHJpcGV0dG8tZmlsbCIvPjwvc3ZnPg==",alias:"multiple-choice",get label(){return c("block:multiple-choice","Multiple choice")}})],$);export{$ as MultipleChoice};