image icon indicating copy to clipboard operation
image copied to clipboard

access corresponding block from custom action

Open develowper opened this issue 4 years ago • 2 comments

hi dear developers.

i want to create a custom action. in your first example i see somethings like this:

  image: {
                                class: ImageTool,
                        
                                config: {
                                    actions: [
                                        {
                                            name: 'new_button',
                                            icon: '<i class="fa fa-align-center"></i>',
                                            title: 'title',
                                            action: (name) => {
                                                alert(`${name}   `);
                                                //access `corresponding` block  ???
                                                return false;
                                            }
                                        }
                                    ],
}

in this action you just used name and alert the name , i want to access block elements from this section and modify an image inside this block (and set width for image). how can i access block from this section? thanks

develowper avatar Jan 21 '22 08:01 develowper

I found some solution by wrapping Image tool into my own class

export default class MyImageTool extends ImageTool {
  constructor(props) {
    super(props);
    this.tunes.actions = this.tunes.actions.map((a) => {
      return {
        ...a,
        action: a.action.bind(this)
      };
    });
  }
}

This helps to get this inside actions funcs

mvodyanov avatar Apr 11 '22 20:04 mvodyanov