@@ -83,18 +83,42 @@ function RemoteFunctions(config = {}) {
8383 } , time * 1000 ) ;
8484 }
8585
86+ // the following fucntions can be in the handler and live preview will call those functions when the below
87+ // events happen
88+ const allowedHandlerFns = [
89+ "dismiss" , // when handler gets this event, it should dismiss all ui it renders in the live preview
90+ // render an icon or html when the selected element toolbox appears in edit mode.
91+ "renderToolBoxItem" ,
92+ "redraw" ,
93+ "onElementSelected" , // an item is selected in live preview
94+ "onElementCleanup" ,
95+ "handleConfigChange" ,
96+ // below function gets called to render the dropdown when user clicks on the ... menu in the options box,
97+ // the handler should retrun html tor ender the dropdown item.
98+ "renderDropdownItems" ,
99+ // called when an item is selected from the more options dropdown
100+ "handleDropdownClick" ,
101+ "reRegisterEventHandlers" ,
102+ "handleClick" // handle click on an icon in the more options box.
103+ ] ;
104+
86105 const _moreOptionsHandlers = new Map ( ) ;
87106 function registerNodeMoreOptionsHandler ( handlerName , handler ) {
88107 if ( _moreOptionsHandlers [ handlerName ] ) {
89108 console . error ( `lp: More options handler '${ handlerName } ' already registered. Ignoring new registration` ) ;
90109 return ;
91110 }
92- if ( ! handler || ! handler . dismiss ) {
93- console . error ( `lp: More options handler Ignoring registration: '${
94- handlerName } ' missing required function: 'dismiss'`) ;
111+ if ( ! handler || typeof handler !== "object" ) {
112+ console . error ( `lp: More options handler '${ handlerName } ' value is invalid ${ JSON . stringify ( handler ) } .` ) ;
95113 return ;
96114 }
97115 handler . handlerName = handlerName ;
116+ for ( const key of Object . keys ( handler ) ) {
117+ if ( key !== "handlerName" && ! allowedHandlerFns . includes ( key ) ) {
118+ console . warn ( `lp: More options handler '${ handlerName } ' has unknown property '${ key } '` ,
119+ `should be one of ${ allowedHandlerFns . join ( "," ) } ` ) ;
120+ }
121+ }
98122 _moreOptionsHandlers . set ( handlerName , handler ) ;
99123 }
100124 function getNodeMoreOptionsHandler ( handlerName ) {
@@ -900,10 +924,10 @@ function RemoteFunctions(config = {}) {
900924 // Render handler options with ordering support
901925 const handlerOptions = LivePreviewView . getAllNodeMoreOptionsHandlers ( )
902926 . map ( ( handler , index ) => {
903- if ( ! handler . renderMoreOptionsDropdown ) {
927+ if ( ! handler . renderToolBoxItem ) {
904928 return null ;
905929 }
906- const result = handler . renderMoreOptionsDropdown ( this . element ) ;
930+ const result = handler . renderToolBoxItem ( this . element ) ;
907931 if ( ! result ) {
908932 return null ;
909933 }
@@ -3933,7 +3957,7 @@ function RemoteFunctions(config = {}) {
39333957 dismissNodeInfoBox ( ) ;
39343958 dismissImageRibbonGallery ( ) ;
39353959 dismissToastMessage ( ) ;
3936- getAllNodeMoreOptionsHandlers ( ) . forEach ( handler => handler . dismiss ( ) ) ;
3960+ getAllNodeMoreOptionsHandlers ( ) . forEach ( handler => ( handler . dismiss && handler . dismiss ( ) ) ) ;
39373961 }
39383962
39393963 let _toastTimeout = null ;
@@ -4339,11 +4363,5 @@ function RemoteFunctions(config = {}) {
43394363 // DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_SCRIPTS
43404364
43414365 registerHandlers ( ) ;
4342- // Notify handlers about config initialization
4343- getAllNodeMoreOptionsHandlers ( ) . forEach ( handler => {
4344- if ( handler . handleConfigChange ) {
4345- handler . handleConfigChange ( { } , config ) ;
4346- }
4347- } ) ;
43484366 return customReturns ;
43494367}
0 commit comments