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

Ability to ungroup objects #489

Closed
KevinGutowski opened this issue May 7, 2019 · 5 comments
Closed

Ability to ungroup objects #489

KevinGutowski opened this issue May 7, 2019 · 5 comments

Comments

@KevinGutowski
Copy link
Contributor

It is pretty easy to drop down into the internal API to ungroup an object but it would be nice if the JS API properly supported it.

@mathieudutour
Copy link
Contributor

ungrouping is just moving the layers of the group to the parent of the group, right? I don't think you need a specific API for it

@KevinGutowski
Copy link
Contributor Author

KevinGutowski commented May 7, 2019

I guess its nice because of a few things

  1. Its one action on the group object
  2. It deletes the group

Right now I have to remove the parent for each layer in the group and then reattach the containing parent to the layers (bc of this bug #486). I then have to be careful that objects aren’t repositioned because the frames need to be different. Lastly, I then have to clean up the leftover group and remove the parent. (Which I assume delete’s the group object?)

@mathieudutour
Copy link
Contributor

The bug will be fixed soon so it will be easier :)

So it would look like this:

const parent = group.parent
group.layers.forEach(l => {
  l.frame = frame.changeBasis({ from: group, to: parent })
  l.parent = parent
})
group.remove()

I'm trying to keep the API surface to a minimum: if you can do it with the existing API, it's not likely that I'll add a helper function in the core API.

That's being said, we could start to create another module with those kind of helpers. There are much easier to contribute to because you don't need any knowledge about the internal API.

@KevinGutowski
Copy link
Contributor Author

Yeah its pretty verbose. Adding a new module with those helpers would be cool! Maybe another module for some UI stuff too? I'll note that this could be a good candidate for a different module.

Also, didn't know about the changeBasis on layer. That's pretty handy.

@mathieudutour
Copy link
Contributor

I wrote a bit about what should or shoudn't go in the API here: https://github.com/BohemianCoding/SketchAPI/blob/70ab0df427f3a3c277fd7810b0cae8075535b16d/docs/philosophy.md

I'll close this issue now but let's start to think about some helpers that could be included in a separate library (a bit like lodash)

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