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

Changing order of nodes #63

Open
lavrton opened this issue Apr 21, 2023 · 5 comments
Open

Changing order of nodes #63

lavrton opened this issue Apr 21, 2023 · 5 comments

Comments

@lavrton
Copy link
Member

lavrton commented Apr 21, 2023

I made this demo: https://codesandbox.io/s/festive-germain-1js7yj?file=/App.svelte

In the demo, I am rendering stars from an array. Also I am changing order of stars, to display dragged start on top:

let handleDragStart = e => {
	// save drag element:
	dragItemId = e.detail.target.id();
	// move current element to the top:
	const item = list.find(i => i.id === dragItemId);
	const index = list.indexOf(item);
	list.splice(index, 1);
	list.push(item);
};

But I don't see that on canvas. Does the library support that? Or I am doing something wrong?

@langscot
Copy link

Your code sandbox link is corrupted, it says "something went wrong". Can you share another one?

@lavrton
Copy link
Member Author

lavrton commented Apr 21, 2023

@TeyKey1
Copy link
Member

TeyKey1 commented Apr 21, 2023

Ordering within each is kind of a pain point in svelte-konva currently as it can be done in many ways but not all possibilities lead to the desired results. I currently opted to let the user do the layering using the Konva-native layering functionality without recalculating layering on changes manually within each blocks (like vue-konva does for example).

So the problem you face would be solved with the following code:

let handleDragStart = e => {
	// save drag element:
	dragItemId = e.detail.target.id();

	// move current element to the top:
	const item = list.find(i => i.id === dragItemId);

	item.handle.moveToTop(); // Use Konva native way of layering
};

And in the template section add bind:handle={item.handle} to the Star component to get access to the Konva node.

I'm not sure how straightforward it would be in svelte to add a similar functionality akin to vue-konva to order the components within an each block automatically. It would certainly make it more straightforward for end-users to grasp svelte-konva if they come from vue-konva for example. Certainly something I'll look into.

@lavrton
Copy link
Member Author

lavrton commented Apr 21, 2023

I think it must follow the order that I have in the template. It is predicable and allows writing in app in a "svelte" and declarative way. If possible, a user should use as less Konva API directly as possible.

@TeyKey1
Copy link
Member

TeyKey1 commented May 13, 2023

After some more tinkering, this is not possible to achieve in a sound way in Svelte right now. I have created an issue in Svelte about this (sveltejs/svelte#8547) so we might get the required functionality to make this work in the future. For now, we have to rely on the Konva-native way of ordering for such use cases. I'll keep this issue open to track any progress on Svelte side which might make such a functionality possible. I've also written an extensive doc page in the old svelte-konva docs about this, and will port the important bits to the Konva page to avoid too much confusion about this.

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

Successfully merging a pull request may close this issue.

3 participants