UNPKG

iobroker.javascript

Version:
81 lines (77 loc) 41.5 kB
import{r as e}from"./rolldown-runtime-C0FnF6B9.js";import{$t as t,Hn as n,Nt as r,Un as i,Xn as a,Xt as o,Yt as s,Zt as c,bt as l,f as u,jn as d,o as f,xt as p,yr as m,zt as h}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-CxICLr5Z.js";import{n as g,t as _}from"./Import-DpTg1Jow.js";import{t as v}from"./Error-DDfrxAt2.js";import{t as y}from"./blocklyDarkTheme-DEiAX5DT.js";m();var b=window.Blockly,x=class extends Error{constructor(){super(`The field has not yet been attached to its input. Call appendField to attach it.`)}},S=class e extends b.Field{constructor(e,t,n){super(e),d(this,`textGroup`,null),d(this,`borderRect_`,null),d(this,`maxLines_`,1/0),d(this,`isOverflowedY_`,!1),e!==Symbol(`SKIP_SETUP`)&&(n&&this.configure_(n),this.SERIALIZABLE=!0,this.setValue((e==null?void 0:e.toString())||``),t&&this.setValidator(t))}configure_(e){super.configure_(e),e.maxLines&&this.setMaxLines(e.maxLines)}toXml(e){return e.textContent=this.getValue().replace(/\n/g,`&#10;`),e}fromXml(e){this.setValue(e.textContent.replace(/&#10;/g,` `))}saveState(){let t=this.saveLegacyState(e);return t===null?this.getValue():t}loadState(e){this.loadLegacyState(b.Field,e)||this.setValue(e)}initView(){this.createBorderRect_(),this.textGroup=b.utils.dom.createSvgElement(b.utils.Svg.G,{class:`blocklyEditableText`},this.fieldGroup_)}onHtmlInputKeyDownSuper_(e){e.key===`Enter`?(b.WidgetDiv.hideIfOwner(this),b.dropDownDiv.hideWithoutAnimation()):e.key===`Escape`?(this.setValue(this.htmlInput_.getAttribute(`data-untyped-default-value`),!1),b.WidgetDiv.hideIfOwner(this),b.dropDownDiv.hideWithoutAnimation()):e.key===`Tab`&&(b.WidgetDiv.hideIfOwner(this),b.dropDownDiv.hideWithoutAnimation(),this.sourceBlock_.tab(this,!e.shiftKey),e.preventDefault())}onHtmlInputChange_(e){let t=this.value_;this.setValue(this.getValueFromEditorText_(this.htmlInput_.value),!1),this.sourceBlock_&&b.Events.isEnabled()&&this.value_!==t&&b.Events.fire(new(b.Events.get(`block_field_intermediate_change`))(this.sourceBlock_,this.name||null,t,this.value_))}onFinishEditing_(e){}getValueFromEditorText_(e){return e}bindInputEvents_(e){this.onKeyDownWrapper_=b.browserEvents.conditionalBind(e,`keydown`,this,this.onHtmlInputKeyDown_),this.onKeyInputWrapper_=b.browserEvents.conditionalBind(e,`input`,this,this.onHtmlInputChange_)}getDisplayText_(){let e=this.getSourceBlock();if(!e)throw Error(`The field has not yet been attached to its input. Call appendField to attach it.`);let t=this.getText();if(!t)return b.Field.NBSP;let n=t.split(` `);t=``;let r=this.isOverflowedY_?this.maxLines_:n.length;for(let e=0;e<r;e++){let i=n[e]||``;i.length>this.maxDisplayLength?i=`${i.substring(0,this.maxDisplayLength-4)}...`:this.isOverflowedY_&&e===r-1&&(i=`${i.substring(0,i.length-3)}...`),i=i.replace(/\s/g,b.Field.NBSP),t+=i,e!==r-1&&(t+=` `)}return e.RTL&&(t+=`‏`),t}doValueUpdate_(e){super.doValueUpdate_(e),this.value_!==null&&(this.isOverflowedY_=this.value_.split(` `).length>this.maxLines_)}render_(){let e=this.getSourceBlock();if(!e)throw Error(`The field has not yet been attached to its input. Call appendField to attach it.`);let t,n=this.textGroup;for(;t=n.firstChild;)n.removeChild(t);let r=this.getConstants();if(!r)throw Error(`Constants not found`);let i=this.getDisplayText_().split(` `),a=0;for(let e=0;e<i.length;e++){let t=r.FIELD_TEXT_HEIGHT+r.FIELD_BORDER_RECT_Y_PADDING;b.utils.dom.createSvgElement(b.utils.Svg.TEXT,{class:`blocklyText blocklyMultilineText`,x:r.FIELD_BORDER_RECT_X_PADDING,y:a+r.FIELD_BORDER_RECT_Y_PADDING,dy:r.FIELD_TEXT_BASELINE},n).appendChild(document.createTextNode(i[e])),a+=t}if(this.isBeingEdited_){let e=this.htmlInput_;this.isOverflowedY_?b.utils.dom.addClass(e,`blocklyHtmlTextAreaInputOverflowedY`):b.utils.dom.removeClass(e,`blocklyHtmlTextAreaInputOverflowedY`)}if(this.updateSize_(),this.isBeingEdited_){e.RTL?setTimeout(this.resizeEditor_.bind(this),0):this.resizeEditor_();let t=this.htmlInput_;this.isTextValid_?(b.utils.dom.removeClass(t,`blocklyInvalidInput`),b.utils.aria.setState(t,b.utils.aria.State.INVALID,!1)):(b.utils.dom.addClass(t,`blocklyInvalidInput`),b.utils.aria.setState(t,b.utils.aria.State.INVALID,!0))}}updateSize_(){let e=this.getConstants();if(!e)throw Error(`Constants not found`);let t=this.textGroup.childNodes,n=e.FIELD_TEXT_FONTSIZE,r=e.FIELD_TEXT_FONTWEIGHT,i=e.FIELD_TEXT_FONTFAMILY,a=0,o=0;for(let s=0;s<t.length;s++){let c=t[s],l=b.utils.dom.getFastTextWidth(c,n,r,i);l>a&&(a=l),o+=e.FIELD_TEXT_HEIGHT+(s>0?e.FIELD_BORDER_RECT_Y_PADDING:0)}if(this.isBeingEdited_){let e=String(this.value_).split(` `),t=b.utils.dom.createSvgElement(b.utils.Svg.TEXT,{class:`blocklyText blocklyMultilineText`});for(let o=0;o<e.length;o++){e[o].length>this.maxDisplayLength&&(e[o]=e[o].substring(0,this.maxDisplayLength)),t.textContent=e[o];let s=b.utils.dom.getFastTextWidth(t,n,r,i);s>a&&(a=s)}let o=this.htmlInput_,s=o.offsetWidth-o.clientWidth;a+=s}this.borderRect_&&(o+=e.FIELD_BORDER_RECT_Y_PADDING*2,a+=e.FIELD_BORDER_RECT_X_PADDING*2+1,this.borderRect_.setAttribute(`width`,`${a}`),this.borderRect_.setAttribute(`height`,`${o}`)),this.size_.width=a,this.size_.height=o,this.positionBorderRect_()}showInlineEditor_(e){let t=this.getSourceBlock();if(!t)throw new x;b.WidgetDiv.show(this,t.RTL,this.widgetDispose_.bind(this),this.workspace_),this.htmlInput_=this.widgetCreate_(),this.isBeingEdited_=!0,this.valueWhenEditorWasOpened_=this.value_,e||(this.htmlInput_.focus({preventScroll:!0}),this.htmlInput_.select())}getEditorText_(e){return`${e}`}getScaledBBox(){let e,t,n,r=this.getSourceBlock();if(!r)throw new x;if(this.isFullBlockField()){let i=this.sourceBlock_.getHeightWidth(),a=r.workspace.scale;n=this.getAbsoluteXY_(),e=(i.width+1)*a,t=(i.height+1)*a,b.utils.userAgent.GECKO?(n.x+=1.5*a,n.y+=1.5*a):(n.x-=.5*a,n.y-=.5*a)}else{let r=this.borderRect_.getBoundingClientRect();n=b.utils.style.getPageOffset(this.borderRect_),e=r.width,t=r.height}return new b.utils.Rect(n.y,n.y+t,n.x,n.x+e)}resizeEditor_(){b.renderManagement.finishQueuedRenders().then(()=>{let e=this.getSourceBlock();if(!e)throw new x;let t=b.WidgetDiv.getDiv(),n=this.getScaledBBox();t.style.width=`${n.right-n.left}px`,t.style.height=`${n.bottom-n.top}px`;let r=e.RTL?n.right-t.offsetWidth:n.left,i=n.top;t.style.left=`${r}px`,t.style.top=`${i}px`})}unbindInputEvents_(){this.onKeyDownWrapper_&&=(b.browserEvents.unbind(this.onKeyDownWrapper_),null),this.onKeyInputWrapper_&&=(b.browserEvents.unbind(this.onKeyInputWrapper_),null)}getClickTarget_(){return this.clickTarget_||this.getSvgRoot()}widgetDispose_(){this.isBeingEdited_=!1,this.isTextValid_=!0,this.forceRerender(),this.onFinishEditing_(this.value_),this.sourceBlock_&&b.Events.isEnabled()&&this.valueWhenEditorWasOpened_!==null&&this.valueWhenEditorWasOpened_!==this.value_&&(b.Events.fire(new(b.Events.get(`change`))(this.sourceBlock_,`field`,this.name||null,this.valueWhenEditorWasOpened_,this.value_)),this.valueWhenEditorWasOpened_=null),b.Events.setGroup(!1),this.unbindInputEvents_();let e=b.WidgetDiv.getDiv().style;e.width=`auto`,e.height=`auto`,e.fontSize=``,e.transition=``,e.boxShadow=``,this.htmlInput_=null;let t=this.getClickTarget_();if(!t)throw Error(`A click target has not been set.`);b.utils.dom.removeClass(t,`editing`)}showEditor_(e,t){this.workspace_=this.sourceBlock_.workspace,!t&&this.workspace_.options.modalInputs&&(b.utils.userAgent.MOBILE||b.utils.userAgent.ANDROID||b.utils.userAgent.IPAD)?this.showPromptEditor_():this.showInlineEditor_(!!t),this.forceRerender()}widgetCreate_(){let e=b.WidgetDiv.getDiv(),t=this.workspace_.getScale(),n=this.getConstants();if(!n)throw Error(`Constants not found`);let r=document.createElement(`textarea`);r.className=`blocklyHtmlInput blocklyHtmlTextAreaInput`,r.setAttribute(`spellcheck`,String(this.spellcheck_));let i=`${n.FIELD_TEXT_FONTSIZE*t}pt`;e.style.fontSize=i,r.style.fontSize=i;let a=`${b.FieldTextInput.BORDERRADIUS*t}px`;r.style.borderRadius=a;let o=n.FIELD_BORDER_RECT_X_PADDING*t,s=n.FIELD_BORDER_RECT_Y_PADDING*t/2;r.style.padding=`${s}px ${o}px ${s}px ${o}px`;let c=n.FIELD_TEXT_HEIGHT+n.FIELD_BORDER_RECT_Y_PADDING;return r.style.lineHeight=`${c*t}px`,e.appendChild(r),r.value=r.defaultValue=this.getEditorText_(this.value_),r.setAttribute(`data-untyped-default-value`,String(this.value_)),r.setAttribute(`data-old-value`,``),b.utils.userAgent.GECKO?setTimeout(this.resizeEditor_.bind(this),0):this.resizeEditor_(),this.bindInputEvents_(r),r}setMaxLines(e){typeof e==`number`&&e>0&&e!==this.maxLines_&&(this.maxLines_=e,this.forceRerender())}getMaxLines(){return this.maxLines_}onHtmlInputKeyDown_(e){e.key!==`Enter`&&this.onHtmlInputKeyDownSuper_(e)}static fromJson(e){let t=b.utils.parsing.replaceMessageReferences(e.text);return new this(t,void 0,e)}};b.Css.register(` .blocklyHtmlTextAreaInput { font-family: monospace; resize: none; overflow: hidden; height: 100%; text-align: left; } .blocklyHtmlTextAreaInputOverflowedY { overflow-y: scroll; } `);var C=`text_multiline`,w={type:C,message0:`%1 %2`,args0:[{type:`field_image`,src:`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAARCAYAAADpPU2iAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAdhgAAHYYBXaITgQAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS42/U4J6AAAAP1JREFUOE+Vks0KQUEYhjmRIja4ABtZ2dm5A3t3Ia6AUm7CylYuQRaUhZSlLZJiQbFAyRnPN33y01HOW08z8873zpwzM4F3GWOCruvGIE4/rLaV+Nq1hVGMBqzhqlxgCys4wJA65xnogMHsQ5lujnYHTejBBCK2mE4abjCgMGhNxHgDFWjDSG07kdfVa2pZMf4ZyMAdWmpZMfYOsLiDMYMjlMB+K613QISRhTnITnsYg5yUd0DETmEoMlkFOeIT/A58iyK5E18BuTBfgYXfwNJv4P9/oEBerLylOnRhygmGdPpTTBZAPkde61lbQe4moWUvYUZYLfUNftIY4zwA5X2Z9AYnQrEAAAAASUVORK5CYII=`,width:12,height:17,alt:`¶`},{type:`field_multilinetext`,name:`TEXT`,text:``}],output:`String`,style:`text_blocks`,helpUrl:`%{BKY_TEXT_TEXT_HELPURL}`,tooltip:`%{BKY_TEXT_TEXT_TOOLTIP}`,extensions:[`parent_tooltip_when_inline`]};function T(e,t){let n=t.multiline_quote_(e.getFieldValue(`TEXT`));return[n,n.indexOf(`+`)===-1?0:6.2]}window.Blockly.common.createBlockDefinitionsFromJsonArray([w])[C];var E=window.Blockly,D=class extends E.Field{constructor(e,t,n){super(e),d(this,`picker`,null),d(this,`highlightedIndex`,null),d(this,`boundEvents`,[]),d(this,`SERIALIZABLE`,!0),d(this,`CURSOR`,`default`),d(this,`isDirty_`,!1),d(this,`colours`,`#ffffff.#cccccc.#c0c0c0.#999999.#666666.#333333.#000000.#ffcccc.#ff6666.#ff0000.#cc0000.#990000.#660000.#330000.#ffcc99.#ff9966.#ff9900.#ff6600.#cc6600.#993300.#663300.#ffff99.#ffff66.#ffcc66.#ffcc33.#cc9933.#996633.#663333.#ffffcc.#ffff33.#ffff00.#ffcc00.#999900.#666600.#333300.#99ff99.#66ff99.#33ff33.#33cc00.#009900.#006600.#003300.#99ffff.#33ffff.#66cccc.#00cccc.#339999.#336666.#003333.#ccffff.#66ffff.#33ccff.#3366ff.#3333ff.#000099.#000066.#ccccff.#9999ff.#6666cc.#6633ff.#6600cc.#333399.#330099.#ffccff.#ff99ff.#cc66cc.#cc33cc.#993399.#663366.#330033`.split(`.`)),d(this,`titles`,[]),d(this,`columns`,7),e!==Symbol(`SKIP_SETUP`)&&(n&&this.configure_(n),this.setValue(e),t&&this.setValidator(t))}configure_(e){super.configure_(e),e.colourOptions&&(this.colours=e.colourOptions),e.colourTitles&&(this.titles=e.colourTitles),e.columns&&(this.columns=e.columns)}initView(){let e=this.getConstants();if(!e)throw Error(`Constants not found`);this.size_=new E.utils.Size(e.FIELD_COLOUR_DEFAULT_WIDTH,e.FIELD_COLOUR_DEFAULT_HEIGHT),this.createBorderRect_(),this.getBorderRect().style.fillOpacity=`1`,this.getBorderRect().setAttribute(`stroke`,`#fff`),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot())}isFullBlockField(){if(!this.getSourceBlock())throw new E.UnattachedFieldError;let e=this.getConstants();return this.blockIsSimpleReporter()&&!!(e!=null&&e.FIELD_COLOUR_FULL_BLOCK)}blockIsSimpleReporter(){let e=this.getSourceBlock();if(!e)throw new E.UnattachedFieldError;if(!e.outputConnection)return!1;for(let t of e.inputList)if(t.connection||t.fieldRow.length>1)return!1;return!0}applyColour(){let e=this.getSourceBlock();if(!e)throw new E.UnattachedFieldError;if(!this.fieldGroup_)return;let t=this.borderRect_;if(!t)throw Error(`The border rect has not been initialized`);this.isFullBlockField()?(t.style.display=`none`,e.pathObject.svgPath.setAttribute(`fill`,this.getValue()),e.pathObject.svgPath.setAttribute(`stroke`,`#fff`)):(t.style.display=`block`,t.style.fill=this.getValue())}getSize(){var e;return(e=this.getConstants())!=null&&e.FIELD_COLOUR_FULL_BLOCK&&(this.render_(),this.isDirty_=!1),super.getSize()}render_(){super.render_();let e=this.getSourceBlock();if(!e)throw new E.UnattachedFieldError;e.applyColour()}updateSize_(e){let t=this.getConstants();if(!t)return;let n,r;this.isFullBlockField()?(n=(e??0)*2,r=t.FIELD_TEXT_HEIGHT):(n=t.FIELD_COLOUR_DEFAULT_WIDTH,r=t.FIELD_COLOUR_DEFAULT_HEIGHT),this.size_.height=r,this.size_.width=n,this.positionBorderRect_()}doClassValidation_(e){return typeof e==`string`?E.utils.colour.parse(e):null}getText(){let e=this.value_;return/^#(.)\1(.)\2(.)\3$/.test(e)&&(e=`#${e[1]}${e[3]}${e[5]}`),e}setColours(e,t){return this.colours=e,t&&(this.titles=t),this}setColumns(e){return this.columns=e,this}showEditor_(){if(this.dropdownCreate(),!this.picker)throw Error(`Picker not found`);E.DropDownDiv.getContentDiv().appendChild(this.picker),E.DropDownDiv.showPositionedByField(this,this.dropdownDispose.bind(this)),this.picker.focus({preventScroll:!0})}onClick(e){let t=e.target,n=t==null?void 0:t.getAttribute(`data-colour`);n!==null&&(this.setValue(n),E.DropDownDiv.hideIfOwner(this))}onKeyDown(e){let t=!0,n;switch(e.key){case`ArrowUp`:this.moveHighlightBy(0,-1);break;case`ArrowDown`:this.moveHighlightBy(0,1);break;case`ArrowLeft`:this.moveHighlightBy(-1,0);break;case`ArrowRight`:this.moveHighlightBy(1,0);break;case`Enter`:if(n=this.getHighlighted(),n){let e=n.getAttribute(`data-colour`);e!==null&&this.setValue(e)}E.DropDownDiv.hideWithoutAnimation();break;default:t=!1}t&&e.stopPropagation()}moveHighlightBy(e,t){if(!this.highlightedIndex)return;let n=this.colours,r=this.columns,i=this.highlightedIndex%r,a=Math.floor(this.highlightedIndex/r);i+=e,a+=t,e<0?i<0&&a>0?(i=r-1,a--):i<0&&(i=0):e>0?i>r-1&&a<Math.floor(n.length/r)-1?(i=0,a++):i>r-1&&i--:t<0?a<0&&(a=0):t>0&&a>Math.floor(n.length/r)-1&&(a=Math.floor(n.length/r)-1);let o=this.picker.childNodes[a].childNodes[i],s=a*r+i;this.setHighlightedCell(o,s)}onMouseMove(e){let t=e.target,n=t&&Number(t.getAttribute(`data-index`));n!==null&&n!==this.highlightedIndex&&this.setHighlightedCell(t,n)}onMouseEnter(){var e;(e=this.picker)==null||e.focus({preventScroll:!0})}onMouseLeave(){var e;(e=this.picker)==null||e.blur();let t=this.getHighlighted();t&&E.utils.dom.removeClass(t,`blocklyColourHighlighted`)}getHighlighted(){var e;if(!this.highlightedIndex)return null;let t=this.highlightedIndex%this.columns,n=Math.floor(this.highlightedIndex/this.columns),r=(e=this.picker)==null?void 0:e.childNodes[n];return r?r.childNodes[t]:null}setHighlightedCell(e,t){let n=this.getHighlighted();n&&E.utils.dom.removeClass(n,`blocklyColourHighlighted`),E.utils.dom.addClass(e,`blocklyColourHighlighted`),this.highlightedIndex=t;let r=e.getAttribute(`id`);r&&this.picker&&E.utils.aria.setState(this.picker,E.utils.aria.State.ACTIVEDESCENDANT,r)}dropdownCreate(){let e=this.columns,t=this.colours,n=this.getValue(),r=document.createElement(`table`);r.className=`blocklyColourTable`,r.tabIndex=0,r.dir=`ltr`,E.utils.aria.setRole(r,E.utils.aria.Role.GRID),E.utils.aria.setState(r,E.utils.aria.State.EXPANDED,!0),E.utils.aria.setState(r,E.utils.aria.State.ROWCOUNT,Math.floor(t.length/e)),E.utils.aria.setState(r,E.utils.aria.State.COLCOUNT,e);let i=null;for(let a=0;a<t.length;a++){a%e===0&&(i=document.createElement(`tr`),E.utils.aria.setRole(i,E.utils.aria.Role.ROW),r.appendChild(i));let o=document.createElement(`td`);i.appendChild(o),o.setAttribute(`data-colour`,t[a]),o.title=this.titles[a]||t[a],o.id=E.utils.idGenerator.getNextUniqueId(),o.setAttribute(`data-index`,`${a}`),E.utils.aria.setRole(o,E.utils.aria.Role.GRIDCELL),E.utils.aria.setState(o,E.utils.aria.State.LABEL,t[a]),E.utils.aria.setState(o,E.utils.aria.State.SELECTED,t[a]===n),o.style.backgroundColor=t[a],t[a]===n&&(o.className=`blocklyColourSelected`,this.highlightedIndex=a)}this.boundEvents.push(E.browserEvents.conditionalBind(r,`pointerdown`,this,this.onClick,!0)),this.boundEvents.push(E.browserEvents.conditionalBind(r,`pointermove`,this,this.onMouseMove,!0)),this.boundEvents.push(E.browserEvents.conditionalBind(r,`pointerenter`,this,this.onMouseEnter,!0)),this.boundEvents.push(E.browserEvents.conditionalBind(r,`pointerleave`,this,this.onMouseLeave,!0)),this.boundEvents.push(E.browserEvents.conditionalBind(r,`keydown`,this,this.onKeyDown,!1)),this.picker=r}dropdownDispose(){for(let e of this.boundEvents)E.browserEvents.unbind(e);this.boundEvents.length=0,this.picker=null,this.highlightedIndex=null}static fromJson(e){return new this(e.colour,void 0,e)}};D.prototype.DEFAULT_VALUE=`#ffffff`,E.Css.register(` .blocklyColourTable { border-collapse: collapse; display: block; outline: none; padding: 1px; } .blocklyColourTable>tr>td { border: 0.5px solid #888; box-sizing: border-box; cursor: pointer; display: inline-block; height: 20px; padding: 0; width: 20px; } .blocklyColourTable>tr>td.blocklyColourHighlighted { border-color: #eee; box-shadow: 2px 2px 7px 2px rgba(0, 0, 0, 0.3); position: relative; } .blocklyColourSelected, .blocklyColourSelected:hover { border-color: #eee !important; outline: 1px solid #333; position: relative; } `);var O=`colour_picker`,k={type:O,message0:`%1`,args0:[{type:`field_colour`,name:`COLOUR`,colour:`#ff0000`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_PICKER_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_PICKER_TOOLTIP}`,extensions:[`parent_tooltip_when_inline`]};function A(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),0]}window.Blockly.common.createBlockDefinitionsFromJsonArray([k])[O];var j=`colour_random`,M={type:j,message0:`%{BKY_COLOUR_RANDOM_TITLE}`,output:`Colour`,helpUrl:`%{BKY_COLOUR_RANDOM_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RANDOM_TOOLTIP}`};function N(e,t){return[`${t.provideFunction_(`colourRandom`,` function ${t.FUNCTION_NAME_PLACEHOLDER_}() { var num = Math.floor(Math.random() * 0x1000000); return '#' + ('00000' + num.toString(16)).substr(-6); } `)}()`,2]}window.Blockly.common.createBlockDefinitionsFromJsonArray([M])[j];var P=`colour_rgb`,F={type:P,message0:`%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3`,args0:[{type:`input_value`,name:`RED`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`GREEN`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`BLUE`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_RGB_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RGB_TOOLTIP}`};function I(e,t){let n=t.valueToCode(e,`RED`,99)||0,r=t.valueToCode(e,`GREEN`,99)||0,i=t.valueToCode(e,`BLUE`,99)||0;return[`${t.provideFunction_(`colourRgb`,` function ${t.FUNCTION_NAME_PLACEHOLDER_}(r, g, b) { r = Math.max(Math.min(Number(r), 100), 0) * 2.55; g = Math.max(Math.min(Number(g), 100), 0) * 2.55; b = Math.max(Math.min(Number(b), 100), 0) * 2.55; r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2); g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2); b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2); return '#' + r + g + b; } `)}(${n}, ${r}, ${i})`,2]}window.Blockly.common.createBlockDefinitionsFromJsonArray([F])[P];var L=`colour_blend`,R={type:L,message0:`%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} %1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3`,args0:[{type:`input_value`,name:`COLOUR1`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`COLOUR2`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`RATIO`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_BLEND_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_BLEND_TOOLTIP}`};function z(e,t){let n=t.valueToCode(e,`COLOUR1`,99)||`'#000000'`,r=t.valueToCode(e,`COLOUR2`,99)||`'#000000'`,i=t.valueToCode(e,`RATIO`,99)||.5;return[`${t.provideFunction_(`colourBlend`,` function ${t.FUNCTION_NAME_PLACEHOLDER_}(c1, c2, ratio) { ratio = Math.max(Math.min(Number(ratio), 1), 0); var r1 = parseInt(c1.substring(1, 3), 16); var g1 = parseInt(c1.substring(3, 5), 16); var b1 = parseInt(c1.substring(5, 7), 16); var r2 = parseInt(c2.substring(1, 3), 16); var g2 = parseInt(c2.substring(3, 5), 16); var b2 = parseInt(c2.substring(5, 7), 16); var r = Math.round(r1 * (1 - ratio) + r2 * ratio); var g = Math.round(g1 * (1 - ratio) + g2 * ratio); var b = Math.round(b1 * (1 - ratio) + b2 * ratio); r = ('0' + (r || 0).toString(16)).slice(-2); g = ('0' + (g || 0).toString(16)).slice(-2); b = ('0' + (b || 0).toString(16)).slice(-2); return '#' + r + g + b; } `)}(${n}, ${r}, ${i})`,2]}window.Blockly.common.createBlockDefinitionsFromJsonArray([R])[L];function B(){window.Blockly.FieldMultilineInput||(window.Blockly.fieldRegistry.register(`field_multilinetext`,S),window.Blockly.JavaScript.forBlock.text_multiline=T,window.Blockly.FieldMultilineInput=S,Object.assign(window.Blockly.Blocks,window.Blockly.common.createBlockDefinitionsFromJsonArray([{type:`text_multiline`,message0:`%1 %2`,args0:[{type:`field_image`,src:`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAARCAYAAADpPU2iAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAdhgAAHYYBXaITgQAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS42/U4J6AAAAP1JREFUOE+Vks0KQUEYhjmRIja4ABtZ2dm5A3t3Ia6AUm7CylYuQRaUhZSlLZJiQbFAyRnPN33y01HOW08z8873zpwzM4F3GWOCruvGIE4/rLaV+Nq1hVGMBqzhqlxgCys4wJA65xnogMHsQ5lujnYHTejBBCK2mE4abjCgMGhNxHgDFWjDSG07kdfVa2pZMf4ZyMAdWmpZMfYOsLiDMYMjlMB+K613QISRhTnITnsYg5yUd0DETmEoMlkFOeIT/A58iyK5E18BuTBfgYXfwNJv4P9/oEBerLylOnRhygmGdPpTTBZAPkde61lbQe4moWUvYUZYLfUNftIY4zwA5X2Z9AYnQrEAAAAASUVORK5CYII=`,width:12,height:17,alt:`¶`},{type:`field_multilinetext`,name:`TEXT`,text:``}],output:`String`,style:`text_blocks`,helpUrl:`%{BKY_TEXT_TEXT_HELPURL}`,tooltip:`%{BKY_TEXT_TEXT_TOOLTIP}`,extensions:[`parent_tooltip_when_inline`]}]))),window.Blockly.FieldColour||(window.Blockly.fieldRegistry.register(`field_colour`,D),window.Blockly.JavaScript.forBlock.colour_picker=A,window.Blockly.JavaScript.forBlock.colour_blend=z,window.Blockly.JavaScript.forBlock.colour_random=N,window.Blockly.JavaScript.forBlock.colour_rgb=I,window.Blockly.FieldColour=D,Object.assign(window.Blockly.Blocks,window.Blockly.common.createBlockDefinitionsFromJsonArray([{type:`colour_picker`,message0:`%1`,args0:[{type:`field_colour`,name:`COLOUR`,colour:`#ff0000`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_PICKER_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_PICKER_TOOLTIP}`,extensions:[`parent_tooltip_when_inline`]}])),Object.assign(window.Blockly.Blocks,window.Blockly.common.createBlockDefinitionsFromJsonArray([{type:`colour_random`,message0:`%{BKY_COLOUR_RANDOM_TITLE}`,output:`Colour`,helpUrl:`%{BKY_COLOUR_RANDOM_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RANDOM_TOOLTIP}`}])),Object.assign(window.Blockly.Blocks,window.Blockly.common.createBlockDefinitionsFromJsonArray([{type:`colour_rgb`,message0:`%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3`,args0:[{type:`input_value`,name:`RED`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`GREEN`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`BLUE`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_RGB_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RGB_TOOLTIP}`}])),Object.assign(window.Blockly.Blocks,window.Blockly.common.createBlockDefinitionsFromJsonArray([{type:`colour_blend`,message0:`%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} %1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3`,args0:[{type:`input_value`,name:`COLOUR1`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`COLOUR2`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`RATIO`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_BLEND_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_BLEND_TOOLTIP}`}])));let e=window.Blockly.JavaScript;e.forBlock&&Object.keys(e).forEach(t=>{typeof e[t]==`function`&&(e.forBlock[t]||(console.log(`Migrating Blockly.JavaScript.${t} to Blockly.JavaScript.forBlock.${t}`),e.forBlock[t]=e[t],delete e[t]))})}var V=e({default:()=>J}),H=!1,U=!1,W=null,G=null,K=[];function q(e,t,n,r){if(r||=[],(e.tagName===`BLOCK`||e.tagName===`block`)&&(n=e.id),e.tagName===`FIELD`||e.tagName===`field`)for(let a=0;a<e.attributes.length;a++){let o=(e.attributes[a].value||``).toLowerCase();if(e.attributes[a].nodeName===`name`&&(o===`oid`||o===`text`||o===`var`)){var i;n&&(i=e.innerHTML)!=null&&i.toLowerCase().includes(t)&&r.push(n)}}return e.childNodes.forEach(e=>q(e,t,n,r)),r}var J=class e extends a.Component{constructor(t){super(t),d(this,`blockly`,null),d(this,`blocklyWorkspace`,null),d(this,`originalCode`,void 0),d(this,`someSelected`,null),d(this,`changeTimer`,null),d(this,`someSelectedTime`,0),d(this,`ignoreChanges`,!1),d(this,`blinkBlock`,void 0),d(this,`onResizeBind`,void 0),d(this,`resizeObserver`,null),d(this,`didUpdate`,null),d(this,`lastCommand`,``),d(this,`lastSearch`,void 0),d(this,`onShowNameDialog`,(e,t,n)=>{this.setState({showInputPrompt:{promptText:e,defaultText:t,callback:n,value:t}})}),this.state={languageOwnLoaded:U,languageBlocklyLoaded:H,changed:!1,message:``,error:``,themeType:this.props.themeType,exportText:``,importText:!1,searchText:this.props.searchText||``,showInputPrompt:null},this.originalCode=t.code||``,this.someSelected=null,this.onResizeBind=this.onResize.bind(this),this.lastSearch=this.props.searchText||``,this.blinkBlock=null,B(),e.Blockly.dialog.setPrompt(this.onShowNameDialog),this.loadLanguages()}static loadJS(e,t,n){let r=document.createElement(`script`);try{r.src=e,r.onload=t,r.onerror=t,(n||window.document.body).appendChild(r)}catch(n){console.error(`Cannot load ${e}: ${n}`),t&&t()}}static loadScripts(t,n){if(!(t!=null&&t.length)){n&&n();return}let r=t.pop();r&&!K.includes(r)?(K.push(r),e.loadJS(`../../adapter/${r}/blockly.js`,()=>setTimeout(()=>e.loadScripts(t,n),0))):setTimeout(()=>e.loadScripts(t,n),0)}static loadCustomBlockly(t,n){let r=[];for(let e in t){var i;!Object.prototype.hasOwnProperty.call(t,e)||!t[e]||!e.match(/^system\.adapter\./)||t[e].type!==`adapter`||(i=t[e].common)!=null&&i.blockly&&(console.log(`Detected custom blockly: ${t[e].common.name}`),r.push(t[e].common.name))}e.loadScripts(r,n)}static loadXMLDoc(e){let t;return t=window.DOMParser?e=>new window.DOMParser().parseFromString(e,`text/xml`):window.ActiveXObject!==void 0&&new window.ActiveXObject(`Microsoft.XMLDOM`)?e=>{let t=new window.ActiveXObject(`Microsoft.XMLDOM`);return t.async=`false`,t.loadXML(e),t}:()=>null,t(e)}searchBlocks(t){if(this.blocklyWorkspace){let n=q(e.Blockly.Xml.workspaceToDom(this.blocklyWorkspace),t.toLowerCase());return console.log(`Search "${t}" found blocks: ${n.length?JSON.stringify(n):`none`}`),n}return[]}searchId(){let e=this.lastSearch?this.searchBlocks(this.lastSearch):null;e!=null&&e.length?(this.someSelected=e,this.someSelected.forEach(e=>{var t;return(t=this.blocklyWorkspace)==null?void 0:t.highlightBlock(e,!0)}),this.someSelectedTime=Date.now()):this.someSelected&&=(this.someSelected.forEach(e=>{var t;return(t=this.blocklyWorkspace)==null?void 0:t.highlightBlock(e,!1)}),null)}UNSAFE_componentWillReceiveProps(t){t.command&&this.lastCommand!==t.command&&(this.lastCommand=t.command,setTimeout(()=>this.lastCommand=``,300),this.lastCommand===`check`?this.blocklyCheckBlocks((t,n)=>{t?(n&&e.blocklyBlinkBlock(n),this.setState({error:{text:u.t(t),title:u.t(`Error was found`)}}),this.blinkBlock=n):this.setState({message:u.t(`Ok`)})}):this.lastCommand===`export`?this.exportBlocks():this.lastCommand===`import`&&this.importBlocks()),t.searchText!==this.lastSearch&&(this.lastSearch=t.searchText,this.searchId()),this.state.themeType!==t.themeType&&this.setState({themeType:t.themeType},()=>this.updateBackground()),this.originalCode!==t.code&&(this.originalCode=t.code||``,this.loadCode(),this.searchId())}loadLanguages(){if(!H){let e=window.document.createElement(`script`);e.setAttribute(`type`,`text/javascript`),e.setAttribute(`src`,`google-blockly/msg/js/${u.getLanguage()}.js`),e.onload=()=>{H=!0,this.setState({languageBlocklyLoaded:H})},window.document.getElementsByTagName(`head`)[0].appendChild(e)}if(!U){let e=window.document.createElement(`script`);e.setAttribute(`type`,`text/javascript`),e.setAttribute(`src`,`google-blockly/own/msg/${u.getLanguage()}.js`),e.onload=()=>{U=!0,this.setState({languageOwnLoaded:U})},window.document.getElementsByTagName(`head`)[0].appendChild(e)}}onResize(){this.blocklyWorkspace&&e.Blockly.svgResize(this.blocklyWorkspace)}static jsCode2Blockly(e){e||=``;let t=e.split(/[\r\n]+|\r|\n/g),n=``;for(let e=t.length-1;e>=0;e--)if(t[e].substring(0,2)===`//`){n=t[e].substring(2);break}if(n.substring(0,4)===`<xml`)return n;let r;try{r=window.decodeURIComponent(window.atob(n))}catch(e){r=null,console.error(`cannot decode: ${n}`),console.error(e)}return r}static blocklyBlinkBlock(e){for(let t=300;t<3e3;t+=300)setTimeout(()=>e.select(),t),setTimeout(()=>e.unselect(),t+150)}blocklyRemoveOrphanedShadows(){if(this.blocklyWorkspace){let e=this.blocklyWorkspace.getAllBlocks(),t;for(let n=0;t=e[n];n++)if(t.isShadow()){let e=t.getConnections_(!0),n;for(let r=0;n=e[r];r++)if(!n.targetConnection){t.dispose();break}}}}blocklyCheckBlocks(t){let n;if(!this.blocklyWorkspace||this.blocklyWorkspace.getAllBlocks().length===0)return t&&t(`no blocks found`),!1;let r=this.blocklyGetUnconnectedBlock();return r?n=`not properly connected`:(r=this.blocklyGetBlockWithWarning(),r&&(n=`warning on this block`)),r?(t?t(n,r):e.blocklyBlinkBlock(r),!1):(t(),!0)}blocklyGetUnconnectedBlock(){var t;let n=(t=this.blocklyWorkspace)==null?void 0:t.getAllBlocks(),r;if(n)for(let t=0;r=n[t];t++){let t=r.getConnections_(!0),n;for(let i=0;n=t[i];i++)if(!n.sourceBlock_||(n.type===e.Blockly.INPUT_VALUE||n.type===e.Blockly.OUTPUT_VALUE)&&!n.targetConnection&&!n._optional)return r}return null}blocklyGetBlockWithWarning(){var e;let t=(e=this.blocklyWorkspace)==null?void 0:e.getAllBlocks(),n;if(t){for(let e=0;n=t[e];e++)if(n.warning)return n}return null}appendBlocksFromXml(e){this.onImportBlocks(e)}applyAiBlocks(t){if(this.blocklyWorkspace&&(t=(t||``).trim(),t))try{t.startsWith(`<xml`)||(t=`<xml xmlns="https://developers.google.com/blockly/xml">${t}</xml>`),t=t.replace(/[\n\r]/g,``).replace(/<variables>.*<\/variables>/g,``);let n=e.Blockly.utils.xml.textToDom(t),r=Array.from(n.querySelectorAll(`:scope > block`));if(r.length===0)return;let i=e=>{let t=e.getAttribute(`type`)||``,n=[];for(let t of Array.from(e.children))t.tagName===`field`&&n.push(`${t.getAttribute(`name`)}=${t.textContent}`),t.tagName===`mutation`&&n.push(`mut:${t.outerHTML}`);return`${t}|${n.join(`,`)}`},a=e=>{let t=e.type||``,n=[];for(let t of e.inputList||[])for(let e of t.fieldRow||[])e.name&&e.getValue&&n.push(`${e.name}=${e.getValue()}`);if(e.mutationToDom)try{let t=e.mutationToDom();t&&n.push(`mut:${t.outerHTML}`)}catch{}return`${t}|${n.join(`,`)}`},o=r.map(e=>i(e)),s=this.blocklyWorkspace.getTopBlocks(!1),c=s.map(e=>a(e)),l=Array(s.length).fill(!1),u=[];for(let e=0;e<o.length;e++){let t=!1;for(let n=0;n<c.length;n++)if(!l[n]&&o[e]===c[n]){l[n]=!0;let e=s[n].getRelativeToSurfaceXY();u.push({x:e.x,y:e.y}),t=!0;break}if(!t){let n=r[e].getAttribute(`type`)||``;for(let e=0;e<s.length;e++)if(!l[e]&&s[e].type===n){l[e]=!0;let n=s[e].getRelativeToSurfaceXY();u.push({x:n.x,y:n.y}),t=!0;break}}t||u.push(null)}let d=window.Blockly,f=d.utils.idGenerator.genUid();d.Events.setGroup(f),window.scripts.loading=!0;for(let e=0;e<s.length;e++)l[e]&&s[e].dispose(!1);if(r.length>1){let e=new Set;for(let t of r)e.add(`${t.getAttribute(`x`)||`0`},${t.getAttribute(`y`)||`0`}`);if(e.size===1){let e=10;for(let t of r)t.setAttribute(`x`,`10`),t.setAttribute(`y`,String(e)),e+=200}}e.Blockly.Xml.appendDomToWorkspace(n,this.blocklyWorkspace);let p=this.blocklyWorkspace.getTopBlocks(!1),m=p.slice(-r.length),h=10;for(let e of p.slice(0,-r.length)){let t=e.getRelativeToSurfaceXY(),n=e.getHeightWidth();h=Math.max(h,t.y+n.height+30)}for(let e=0;e<m.length;e++){let t=u[e];if(t){let n=m[e].getRelativeToSurfaceXY();m[e].moveBy(t.x-n.x,t.y-n.y)}else{let t=m[e].getRelativeToSurfaceXY();m[e].moveBy(10-t.x,h-t.y),h+=m[e].getHeightWidth().height+20}}window.scripts.loading=!1,d.Events.setGroup(!1),this.onBlocklyChanged()}catch(e){var n;window.scripts.loading=!1,(n=window.Blockly)==null||(n=n.Events)==null||n.setGroup(!1),console.error(`Error applying AI blocks:`,e)}}getWorkspaceXml(){if(!this.blocklyWorkspace)return``;let t=e.Blockly.Xml.workspaceToDom(this.blocklyWorkspace);return e.Blockly.Xml.domToPrettyText(t)}blocklyCode2JSCode(t){if(!this.blocklyWorkspace)return``;let n=e.Blockly.JavaScript.workspaceToCode(this.blocklyWorkspace);if(!t){n+=` `;let t=e.Blockly.Xml.workspaceToDom(this.blocklyWorkspace),r=e.Blockly.Xml.domToText(t);n+=`//${btoa(encodeURIComponent(r))}`}return n}exportBlocks(){if(!this.blocklyWorkspace)return;let t,n=e.Blockly.getSelected();if(n){let r=e.Blockly.Xml.blockToDom(n),i=n.getRelativeToSurfaceXY();r.setAttribute(`x`,(n.RTL?-i.x:i.x).toString()),r.setAttribute(`y`,i.y.toString()),t=e.Blockly.Xml.domToPrettyText(r)}else{let n=e.Blockly.Xml.workspaceToDom(this.blocklyWorkspace);t=e.Blockly.Xml.domToPrettyText(n)}this.setState({exportText:t})}importBlocks(){this.setState({importText:!0})}onImportBlocks(t){if(this.blocklyWorkspace&&(t=(t||``).trim(),t))try{t.startsWith(`<xml`)||(t=`<xml xmlns="https://developers.google.com/blockly/xml">${t}</xml>`),t=t.replace(/[\n\r]/g,``).replace(/<variables>.*<\/variables>/g,``),window.scripts.loading=!0;let n=e.Blockly.utils.xml.textToDom(t),r=Array.from(n.querySelectorAll(`:scope > block`));if(r.length>1){let e=new Set;for(let t of r)e.add(`${t.getAttribute(`x`)||`0`},${t.getAttribute(`y`)||`0`}`);if(e.size===1){let e=parseInt(r[0].getAttribute(`y`)||`0`,10);for(let t of r)t.setAttribute(`y`,String(e)),e+=200}}if(e.Blockly.Xml.appendDomToWorkspace(n,this.blocklyWorkspace),r.length>1){let e=this.blocklyWorkspace.getTopBlocks(!1).slice(-r.length);if(e.length>1){let t=e[0].getRelativeToSurfaceXY().y;for(let n of e){let e=n.getRelativeToSurfaceXY();n.moveBy(0,t-e.y),t+=n.getHeightWidth().height+20}}}window.scripts.loading=!1,this.onBlocklyChanged()}catch(e){this.setState({error:{text:e.toString(),title:u.t(`Import error`)}})}}loadCode(){if(this.blocklyWorkspace){this.ignoreChanges=!0,this.blocklyWorkspace.clear();try{let t=e.jsCode2Blockly(this.originalCode)||`<xml xmlns="https://developers.google.com/blockly/xml"></xml>`;window.scripts.loading=!0;let n=e.Blockly.utils.xml.textToDom(t);e.Blockly.Xml.domToWorkspace(n,this.blocklyWorkspace),window.scripts.loading=!1}catch(e){console.error(e),setTimeout(()=>this.setState({error:u.t(`Cannot extract Blockly code!`)}))}setTimeout(()=>this.ignoreChanges=!1,100)}}onBlocklyChanged(){this.blocklyRemoveOrphanedShadows(),this.setState({changed:!0}),this.onChange()}async componentDidUpdate(){var t;if(!this.blockly||(this.didUpdate&&=(clearTimeout(this.didUpdate),null),this.blocklyWorkspace))return;window.addEventListener(`resize`,this.onResizeBind,!1),!this.resizeObserver&&this.blockly&&(this.resizeObserver=new ResizeObserver(()=>this.onResize()),this.resizeObserver.observe(this.blockly)),W||=await this.getToolbox(),G||=e.Blockly.utils.xml.textToDom(W),this.blocklyWorkspace=e.Blockly.inject(this.blockly,{renderer:`thrasos`,theme:this.state.themeType===`dark`?y():`classic`,media:`google-blockly/media/`,toolbox:G,zoom:{controls:!0,wheel:!1,startScale:1,maxScale:3,minScale:.3,scaleSpeed:1.2,pinch:!0},move:{scrollbars:{horizontal:!0,vertical:!0},drag:!0,wheel:!0},trashcan:!0,grid:{spacing:25,length:1,snap:!0},sounds:!1}),window.scripts={blocklyWorkspace:this.blocklyWorkspace},this.blocklyWorkspace.registerToolboxCategoryCallback(`PROCEDURE`,window.Blockly.Procedures.flyoutCategoryNew),this.blocklyWorkspace.addChangeListener(t=>{if(this.someSelected&&Date.now()-this.someSelectedTime>500){var n;let e=(n=this.blocklyWorkspace)==null?void 0:n.getAllBlocks();this.someSelected=null,e==null||e.forEach(e=>e.removeSelect())}[e.Blockly.Events.UI,e.Blockly.Events.CREATE,e.Blockly.Events.VIEWPORT_CHANGE].includes(t.type)||this.ignoreChanges||(this.changeTimer&&clearTimeout(this.changeTimer),this.changeTimer=setTimeout(()=>{this.changeTimer=null,this.onBlocklyChanged()},200))}),this.loadCode(),this.onResize();let n=document.getElementsByClassName(`blocklyToolboxDiv`)[0];if(this.blockly.appendChild(n),(t=window.Blockly)!=null&&(t=t.FieldOID)!=null&&t.DISPLAY_MODE_KEYS){let t=this.blocklyWorkspace,n=t.configureContextMenu;t.configureContextMenu=(r,i)=>{n&&n.call(t,r,i);let a=window.Blockly.FieldOID,o=a.DISPLAY_MODE_KEYS;for(let n=0;n<o.length;n++){var s,c;let i=((s=e.Blockly.Words)==null||(s=s[o[n]])==null?void 0:s[u.getLanguage()])||((c=e.Blockly.Words)==null||(c=c[o[n]])==null?void 0:c.en)||o[n];r.push({text:`${a.displayMode===n?`✓ `:` `}${i}`,enabled:!0,callback:()=>a.setDisplayMode(n,t),scope:{workspace:t},weight:200+n})}}}this.updateBackground(),setTimeout(()=>this.searchId(),200)}updateBackground(){if(this.state.themeType===`dark`){var t;(t=this.blocklyWorkspace)==null||t.setTheme(y())}else this.blocklyWorkspace&&(this.blocklyWorkspace.getThemeManager(),this.blocklyWorkspace.setTheme(e.Blockly.Themes.Classic))}componentWillUnmount(){this.appendBlocksFromXml,this.applyAiBlocks,this.getWorkspaceXml,this.blocklyWorkspace&&(this.blocklyWorkspace.dispose(),this.blocklyWorkspace=null,this.changeTimer&&clearTimeout(this.changeTimer),this.changeTimer=null,window.removeEventListener(`resize`,this.onResizeBind),this.resizeObserver&&=(this.resizeObserver.disconnect(),null))}onChange(){this.originalCode=this.blocklyCode2JSCode(),this.props.onChange&&this.props.onChange(this.originalCode)}async getToolbox(e){let t=window.document.getElementById(`toolbox`),n=t==null?void 0:t.outerHTML;if(!n)return e?(console.error(`Cannot load blocks!`),``):new Promise(e=>{setTimeout(()=>e(this.getToolbox(!0)),500)});if(n=n.replace(/{(\w+)}/g,(e,t)=>window.MSG[t]),window.Blockly.CustomBlocks){let e=``,t=u.getLanguage();for(let n=0;n<window.Blockly.CustomBlocks.length;n++){let r=window.Blockly.CustomBlocks[n],i=window.Blockly[r];e+=`<category name="${window.Blockly.Words[r][t]}" colour="${i.HUE}">`;for(let t in i.blocks)Object.prototype.hasOwnProperty.call(i.blocks,t)&&(e+=i.blocks[t]);e+=`</category>`}n=n.replace(`<category><block>%%CUSTOM_BLOCKS%%</block></category>`,e)}return n}renderMessageDialog(){return this.state.message?n(f,{text:typeof this.state.message==`object`?this.state.message.text:this.state.message,title:typeof this.state.message==`object`?this.state.message.title:``,onClose:()=>this.setState({message:``})},`dialogMessage`):null}renderErrorDialog(){return this.state.error?n(v,{text:typeof this.state.error==`object`?this.state.error.text.toString():this.state.error,title:typeof this.state.error==`object`?this.state.error.title:``,onClose:()=>{this.blinkBlock&&=(e.blocklyBlinkBlock(this.blinkBlock),null),this.setState({error:``})}},`dialogError`):null}renderExportDialog(){return this.state.exportText?n(g,{themeType:this.state.themeType,onClose:()=>this.setState({exportText:``}),text:this.state.exportText,scriptId:this.props.scriptId},`dialogExport`):null}renderImportDialog(){return this.state.importText?n(_,{themeType:this.props.themeType,onClose:e=>{this.setState({importText:!1}),this.onImportBlocks(e)}},`dialogImport`):null}renderDialogPrompt(){return this.state.showInputPrompt?i(s,{onClose:()=>{var e;let t=(e=this.state.showInputPrompt)==null?void 0:e.callback;t&&t(null),this.setState({showInputPrompt:null})},maxWidth:`sm`,fullWidth:!0,open:!0,children:[n(t,{children:this.state.showInputPrompt.promptText}),n(c,{children:n(r,{variant:`standard`,fullWidth:!0,autoFocus:!0,value:this.state.showInputPrompt.value,onKeyUp:e=>{if(e.key===`Enter`){var t,n;let e=(t=this.state.showInputPrompt)==null?void 0:t.callback,r=(n=this.state.showInputPrompt)==null?void 0:n.value;e&&e(r===void 0?null:r),this.setState({showInputPrompt:null})}},onChange:e=>{var t;let n={...this.state.showInputPrompt};if((t=this.state.showInputPrompt)!=null&&t.callback){var r;n.callback=(r=this.state.showInputPrompt)==null?void 0:r.callback}n.value=e.target.value,this.setState({showInputPrompt:n})}})}),i(o,{children:[n(h,{variant:`contained`,disabled:!this.state.showInputPrompt.value,onClick:()=>{var e,t;let n=(e=this.state.showInputPrompt)==null?void 0:e.callback,r=(t=this.state.showInputPrompt)==null?void 0:t.value;n&&n(r===void 0?null:r),this.setState({showInputPrompt:null})},color:`primary`,startIcon:n(l,{}),children:u.t(`Apply`)}),n(h,{color:`grey`,variant:`contained`,onClick:()=>{var e;let t=(e=this.state.showInputPrompt)==null?void 0:e.callback;t&&t(null),this.setState({showInputPrompt:null})},startIcon:n(p,{}),children:u.t(`Close`)})]})]},`inputDialog`):null}render(){return this.state.languageBlocklyLoaded&&this.state.languageOwnLoaded?(this.didUpdate=setTimeout(()=>{this.didUpdate=null,this.componentDidUpdate()},100),[n(`div`,{ref:e=>{this.blockly=e},style:{width:`100%`,height:`100%`,position:`relative`}},`blocklyDOM`),this.renderDialogPrompt(),this.renderMessageDialog(),this.renderErrorDialog(),this.renderExportDialog(),this.renderImportDialog()]):null}};d(J,`Blockly`,window.Blockly);export{V as n,J as t};