import { PanelControl } from "addons/ohmymn" ; import checkInputCorrect from "inputChecker" ; import lang from "lang" ; import { actions } from "synthesizer" ; import { cellViewType , IRowButton } from "types/Addon" ; import { MbBookNote } from "types/MarginNote" ; import { UIAlertViewStyle } from "types/UIKit" ; import { popup , showHUD , HUDController } from "utils/common" ; import { getSelectNodes , getSelectNodesAll , undoGroupingWithRefresh } from "utils/note" ; import { manageProfileAction } from "utils/profile" ; import { closePanel } from "./switchPanel" ; export default async ( row , option ? ) => { if ( option !== undefined ) await handleMagicAction ( row . key , option ) ; else switch ( row . type ) { case cellViewType . buttonWithInput : for ( ; ; ) { const { option , content } = await popup ( row . label , row . help ?? "" , UIAlertViewStyle . PlainTextInput , row . option ? row . option : [ lang . handle_user_action . sure ] , ( alert , buttonIndex ) => { return { content : alert . textFieldAtIndex ( 0 ) . text , option : buttonIndex } ; } ) ; if ( ! content || checkInputCorrect ( content , row . key ) ) { await handleMagicAction ( row . key , option ! , content ) ; return ; } else showHUD ( lang . handle_user_action . input_error ) ; } case cellViewType . button : const { option } = await popup ( row . label , row . help ?? "" , UIAlertViewStyle . Default , row . option ?? [ lang . handle_user_action . sure ] , ( _ , buttonIndex ) => ( { option : buttonIndex } ) ) ; await handleMagicAction ( row . key , option ! ) ; } } ; let customSelectedNodes = [ ] ; const handleMagicAction = async ( key , option , content = "" ) => { if ( key != "filterCards" && self . profile . ohmymn . panelControl . includes ( PanelControl . CompleteClose ) ) closePanel ( ) ; let nodes = [ ] ; if ( customSelectedNodes . length ) { nodes = customSelectedNodes ; customSelectedNodes = [ ] ; HUDController . hidden ( ) ; } else { nodes = getSelectNodes ( ) ; if ( ! nodes . length ) { showHUD ( lang . magic_action_handler . not_selected ) ; return ; } const isHavingChildren = nodes . every ( node => nodes [ 0 ] . parentNote == node . parentNote && node ?. childNotes . length ) ; const { smart_select } = lang . magic_action_handler ; if ( isHavingChildren ) { const { option } = await popup ( "OhMyMN" , nodes . length > 1 ? smart_select . cards_with_children : smart_select . card_with_children , UIAlertViewStyle . Default , smart_select . option , ( alert , buttonIndex ) => ( { option : buttonIndex } ) ) ; nodes = [ nodes , getSelectNodesAll ( true ) , getSelectNodesAll ( ) ] [ option ! ] ; } } if ( content ) content = content . trim ( ) ; switch ( key ) { case "filterCards" : customSelectedNodes = actions [ key ] ( { content , nodes , option } ) ; break ; case "completeSelected" : actions [ key ] ( { content , nodes , option } ) ; break ; case "manageProfile" : undoGroupingWithRefresh ( ( ) => void manageProfileAction ( { nodes , option } ) ) ; break ; default : undoGroupingWithRefresh ( ( ) => void actions [ key ] ( { content , nodes , option } ) ) ; } } ;