feat: allow configuration of window
global for event subscriptions
#1400
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
In multi-window applications, both on the web and in web embedders like Electron or CEF, it is not unusual to open child windows as "dumb" windows that serve as a render target only and allow their parent to retain control of all scripting responsibilities. In order for event listeners to work correctly, though, rendering code has to take into account the fact that input subscriptions need to be setup for the render target (child) window, rather than the control window.
Proposed change
As far as I can tell, only the drag and drop module and the Transformer class access the window object for event subscription.
Transformer
This change adds an optional configuration property to
Stage
which sets thewindow
global that the Konva should be using to make event subscriptions within this stage. It also adds a public getter for this value.Drag and drop
The drag and drop code is a little tricky because the event subscription happens at the top level of the module. To delay that in order to subscribe to the window global we actually care about, we defer that event subscription until Stage construction.
Miscellaneous
I had to reorder the Transformer destructor to remove events before detaching — I don't know the code well enough to know the implications of that, so please advise if that is undesirable.