/*! For license information please see index.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],t);else{var n="object"==typeof exports?t(require("blockly/core")):t(e.Blockly);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(e=>(()=>{"use strict";var t={573:t=>{t.exports=e}},n={};function o(e){var i=n[e];if(void 0!==i)return i.exports;var s=n[e]={exports:{}};return t[e](s,s.exports,o),s.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{o.r(i),o.d(i,{FieldDependentDropdown:()=>s});var e=o(573);function t(e,n){return e.length===n.length&&e.every(((e,o)=>{const i=n[o];return Array.isArray(e)&&Array.isArray(i)?t(e,i):e===i}))}class n extends e.Events.BlockBase{constructor(e,t,o,i,s,r){super(e),this.type=n.EVENT_TYPE,e&&t&&o&&i&&s&&r&&(this.name=t,this.oldValue=o,this.newValue=i,this.oldOptions=s,this.newOptions=r)}toJson(){const e=super.toJson();if(!(this.name&&this.oldValue&&this.newValue&&this.oldOptions&&this.newOptions))throw new Error("The changed element is undefined. Either pass all needed parameters to the constructor, or call fromJson.");return e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,e.oldOptions=this.oldOptions,e.newOptions=this.newOptions,e}static fromJson(e,t,n){const o=super.fromJson(e,t,n);return o.name=e.name,o.oldValue=e.oldValue,o.newValue=e.newValue,o.oldOptions=e.oldOptions,o.newOptions=e.newOptions,o}isNull(){const e=this.oldValue===this.newValue,n=this.oldOptions===this.newOptions||Array.isArray(this.oldOptions)&&Array.isArray(this.newOptions)&&t(this.oldOptions,this.newOptions);return e&&n}run(e){if(!(this.blockId&&this.name&&this.oldValue&&this.newValue&&this.oldOptions&&this.newOptions))return void console.warn("Can't run uninitialized event.");const t=this.getEventWorkspace_().getBlockById(this.blockId);if(!t)return void console.warn("Can't change non-existent block: "+this.blockId);const n=t.getField(this.name);if(!n)return void console.warn("Can't change non-existent dropdown field: "+this.name);const o=e?this.newValue:this.oldValue,i=e?this.newOptions:this.oldOptions;n.dependencyData.derivedOptions=i,n.getOptions(!1),n.setValue(o)}}n.EVENT_TYPE="dropdown_options_change",e.registry.register(e.registry.Type.EVENT,n.EVENT_TYPE,n);class s extends e.FieldDropdown{constructor(e,t,n,o,i){const s={};super((()=>{if(s.derivedOptions)return s.derivedOptions;if(s.parentField){const e=s.parentField.getValue();if(e){const n=t[e];if(n)return n}}return n||[["",""]]}),o,i),this.parentName=e,this.optionMapping=t,this.defaultOptions=n,this.dependencyData=s}static fromJson(e){return new s(e.parentName,e.optionMapping,e.defaultOptions,void 0,e)}setSourceBlock(e){var t;super.setSourceBlock(e);const n=e.getField(this.parentName);if(!n)throw new Error("Could not find a parent field with the name "+this.parentName+" for the dependent dropdown.");this.dependencyData.parentField=n;const o=n.getValidator();n.setValidator((e=>{if(o){const t=o(e);if(null===t)return null;void 0!==t&&(e=t)}return this.updateOptionsBasedOnNewValue(e),e})),this.updateOptionsBasedOnNewValue(null!==(t=n.getValue())&&void 0!==t?t:void 0)}updateOptionsBasedOnNewValue(t){if(null==t)return;const o=this.getSourceBlock();if(!o)throw new Error("Could not validate a field that is not attached to a block: "+this.name);const i=this.getValue(),s=this.getOptions(!1);let r=this.optionMapping[t];if(!r){if(!this.defaultOptions)return void console.warn("Could not find child options for the parent value: "+t);r=this.defaultOptions}const l=null!=r.find((e=>e[1]==i))?i:r[0][1];this.dependencyData.derivedOptions=r,this.getOptions(!1),e.Events.disable(),this.setValue(l),e.Events.enable(),e.Events.getRecordUndo()&&(e.Events.getGroup()||(e.Events.setGroup(!0),setTimeout((()=>e.Events.setGroup(!1)))),e.Events.fire(new n(o,this.name,null!=i?i:void 0,null!=l?l:void 0,s,r)))}}Object.defineProperty(e,"FieldDependentDropdown",{value:s,writable:!0,enumerable:!0,configurable:!0}),e.fieldRegistry.register("field_dependent_dropdown",s)})(),i})()));