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

Explanation of how hovering over an element selects it in the example #171

Open
ddorstijn opened this issue Jul 31, 2024 · 1 comment
Open

Comments

@ddorstijn
Copy link

I know Reka is a state manager and this isn't fully related, but there seems to be enough overlap. In some way, hovering over an element on the site selects it. This is quite crucial behaviour in any visual editor. If I understand correctly, the code for this is handled in ComponentEditor.tsx

const mouseoverListener = (e: MouseEvent) => {
e.stopPropagation();
this.setTplEvent('hovered', tpl);
};
const mousedownListener = (e: MouseEvent) => {
e.stopPropagation();
this.setTplEvent('selected', tpl);
};
const mouseoutListener = (e: MouseEvent) => {
e.stopPropagation();
if (this.tplEvent.hovered?.id !== tpl.id) {
return;
}
this.setTplEvent('hovered', tpl);
};
if (addListeners) {
dom.addEventListener('mouseover', mouseoverListener);
dom.addEventListener('mousedown', mousedownListener);
dom.addEventListener('mouseout', mouseoutListener);
}

Trying to recreate this in another language is quite an endeavor as it isn't fully clear what the connectTplDom function actually does and how it interacts with the editor. This currently blocks my progress using Reka in my own editor. Could there be some documentation about how one can use these specialized functions to interface between the HTML and the frame tpl's?

@def-roth
Copy link
Contributor

def-roth commented Aug 1, 2024

There is quite more happening here.

  1. The dom elements get registered with connectTplDOM
  2. The functions in your excerpt are registered
  3. If the registered functions are called mobx triggers a state update
  4. The state update activates selection borders, template layers and template settings

Mobx is a reactive state management system. For a first understanding you can think of mobx having a global state storage and whenever a change is made everything depending on it is updated. Although this can be tricky as states might not be obvious.

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

2 participants