Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the currently selected custom block? #112

Open
jaymo107 opened this issue Nov 7, 2024 · 0 comments
Open

Get the currently selected custom block? #112

jaymo107 opened this issue Nov 7, 2024 · 0 comments

Comments

@jaymo107
Copy link

jaymo107 commented Nov 7, 2024

I have a custom tool which places a custom element into the editor, when dropping it in we open a modal to customise the appearance. One thing I'd need it to be able to have a reference of the element in the custom property editor. I need to detect what the parent column size is where the element was placed, so we can dynamically update the image sizes in the block. We have something like this at the moment

Code shortened for brevity

unlayer.registerTool({
  name: 'tool',
  label: 'Tool',
  supportedDisplayModes: ['web', 'email'],
  options: {
    property: {
      title: 'Custom tool',
      position: 1,
    },
...
});

unlayer.registerPropertyEditor({
  name: 'custom_selector',
  layout: 'bottom',
  mount(node, value, updateValue, data) {
    if (!value || !value.property) {
      node.querySelector('#button').onclick = function () {
        // Can I get the reference to the element with context of the row/column
        // To figure out the column size of where the element was dropped?
        renderCustomModal(value);
      };
    }

The columns are exposed in the render method inside unlayer.createViewer() so I can grab where it was placed there, but I need to sort of be able to get it when I open the modal. Is there an event I can hook into when a new element gets selected or something? Or get the reference of the selected element in that button callback?

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant