@@ -137,6 +137,7 @@ class Blocks extends React.Component {
137
137
'handleEnableProcedureReturns'
138
138
] ) ;
139
139
this . ScratchBlocks . prompt = this . handlePromptStart ;
140
+ this . ScratchBlocks . customPrompt = this . handleCustomPrompt ;
140
141
this . ScratchBlocks . statusButtonCallback = this . handleConnectionModalStart ;
141
142
this . ScratchBlocks . recordSoundCallback = this . handleOpenSoundRecorder ;
142
143
@@ -609,6 +610,43 @@ class Blocks extends React.Component {
609
610
p . prompt . showCloudOption = ( optVarType === this . ScratchBlocks . SCALAR_VARIABLE_TYPE ) && this . props . canUseCloud ;
610
611
this . setState ( p ) ;
611
612
}
613
+ handleCustomPrompt ( title , scale , enterInfo , closeInfo ) {
614
+ const isObject = ( value ) => typeof value === 'object' && ! Array . isArray ( value ) ;
615
+ let needsExit = false ;
616
+ const exitFunc = ( message ) => {
617
+ needsExit = true ;
618
+ console . error ( message ) ;
619
+ } ;
620
+
621
+ /* validate arguments */
622
+ if ( isObject ( scale ) ) {
623
+ if ( ! scale . width || ! scale . height ) exitFunc ( "Custom Modal -- Missing width/height number property in Param 2" ) ;
624
+ } else {
625
+ exitFunc ( "Custom Modal -- Param 2 must be a object with 'width' and 'height' number properties" ) ;
626
+ }
627
+ if ( isObject ( enterInfo ) ) {
628
+ if ( ! scale . name || ! scale . callback ) exitFunc ( "Custom Modal -- Missing width/height number property in Param 3" ) ;
629
+ if ( scale . callback && typeof scale . callback !== 'function' ) exitFunc ( "Custom Modal -- callback property in Param 3 must be a function" ) ;
630
+ } else {
631
+ exitFunc ( "Custom Modal -- Param 3 must be a object with properties: 'name' (string) and 'callback' (function)" ) ;
632
+ }
633
+ if ( isObject ( closeInfo ) ) {
634
+ if ( ! scale . name || ! scale . callback ) exitFunc ( "Custom Modal -- Missing width/height number property in Param 4" ) ;
635
+ if ( scale . callback && typeof scale . callback !== 'function' ) exitFunc ( "Custom Modal -- callback property in Param 4 must be a function" ) ;
636
+ } else {
637
+ exitFunc ( "Custom Modal -- Param 4 must be a object with properties: 'name' (string) and 'callback' (function)" ) ;
638
+ }
639
+ if ( needsExit ) return ;
640
+
641
+ this . setState ( { prompt : {
642
+ isCustom : true ,
643
+ title,
644
+ width : Number ( scale . width ) , height : Number ( scale . height ) ,
645
+ enterInfo, closeInfo
646
+ } ) ;
647
+
648
+ return document . querySelector ( `div[class="ReactModalPortal"] div[class*="prompt_body_"]` ) ;
649
+ }
612
650
handleConnectionModalStart ( extensionId ) {
613
651
this . props . onOpenConnectionModal ( extensionId ) ;
614
652
}
@@ -625,13 +663,19 @@ class Blocks extends React.Component {
625
663
* to the variable validation prompt callback used in scratch-blocks.
626
664
*/
627
665
handlePromptCallback ( input , variableOptions ) {
666
+ if ( this . state . prompt . isCustom ) {
667
+ this . state . prompt . enterInfo . callback ( ) ;
668
+ this . setState ( { prompt : null } ) ;
669
+ return ;
670
+ }
628
671
this . state . prompt . callback (
629
672
input ,
630
673
this . props . vm . runtime . getAllVarNamesOfType ( this . state . prompt . varType ) ,
631
674
variableOptions ) ;
632
675
this . handlePromptClose ( ) ;
633
676
}
634
677
handlePromptClose ( ) {
678
+ if ( this . state . prompt . isCustom ) this . state . prompt . closeInfo . callback ( ) ;
635
679
this . setState ( { prompt : null } ) ;
636
680
}
637
681
handleCustomProceduresClose ( data ) {
@@ -687,7 +731,19 @@ class Blocks extends React.Component {
687
731
onDrop = { this . handleDrop }
688
732
{ ...props }
689
733
/>
690
- { this . state . prompt ? (
734
+ { this . state . prompt ? this . state . prompt . isCustom ? (
735
+ < Prompt
736
+ isCustom = { this . state . prompt . isCustom }
737
+ width = { this . state . prompt . width }
738
+ height = { this . state . prompt . height }
739
+ title = { this . state . prompt . title }
740
+ enterTitle = { this . state . prompt . enterInfo . name }
741
+ closeTitle = { this . state . prompt . closeInfo . name }
742
+ vm = { vm }
743
+ onCancel = { this . handlePromptClose }
744
+ onOk = { this . handlePromptCallback }
745
+ />
746
+ ) : (
691
747
< Prompt
692
748
defaultValue = { this . state . prompt . defaultValue }
693
749
isStage = { vm . runtime . getEditingTarget ( ) . isStage }
0 commit comments