kmerc / sketch-import-symbols

Import Sketch symbols from another Sketch file into your current doc
86 stars 8 forks source link

Rewrote plugin to allow for symbols to update themselves. #10

Closed drewloomer closed 7 years ago

drewloomer commented 7 years ago

Sorry for the huge delta, but I had to make some major changes to get this set up to work. I saw your discussion here (#9) yesterday when I ran into this problem myself.

In this PR, when symbols are imported they store the objectID of the original symbol. This lets us replace those symbols when the same file is imported again. Symbol overrides continue to work!

Also fixed a bug with the canvas size of the imported symbols being incorrect.

Totally understand if you're not comfortable with such a huge change in the code. I'm happy to keep this as a fork but thought I would offer it up as a solution.

Paging @florianpnn as well, since you had the original issue.

florianpeninon commented 7 years ago

@drewloomer that looks promising! I will have a look at it today.

timothyachumba commented 7 years ago

😍

mattymatty commented 7 years ago

@drewloomer is it possible to update and overwrite a symbol if the NAME already exists? I am getting duplicated symbols because the ID's don't match.

E.G. I already have two sketch files. A "sub" file and a "master" file. Both files contain "header" symbol and look identical. I update "header" on the master sketch file save and close. Then open sub sketch file and run plugin. Currently I will get duplicate "header" symbols and the page that contains the symbol does not update.

drewloomer commented 7 years ago

@mattymatty it would be easy to use names instead of IDs, I was just concerned about potential false positives when importing from multiple sources. We could probably have two menu items: import by ID or import by name. Or maybe everyone just wants to use name. I'm cool with either but will hold off changing anything until I get some more feedback from you, @florianpnn, @kmerc.

mattymatty commented 7 years ago

@drewloomer I like the idea of having two options. That way if you change a symbol name you can use import by ID (I wonder if that could that also rename the symbol to match the master). Great idea!

drewloomer commented 7 years ago

Awesome idea, @mattymatty! I'll try to put that together next week.

drewloomer commented 7 years ago

@mattymatty, I've added the options to import by name or ID. Let me know if this fits the bill for what you were looking for!

mattymatty commented 7 years ago

@drewloomer this is great! Though, I'm getting broken symbols when a symbol contains another symbol.

kmerc commented 7 years ago

Thanks @drewloomer and apologies for the late response - things have been busy! Would you be able to take a look at @mattymatty 's latest issue? If this can be resolved I would be more than happy to merge :)

drewloomer commented 7 years ago

@kmerc and @mattymatty, can you give the latest code a spin and see if it fixes the issues you were having?

mattymatty commented 7 years ago

@drewloomer I'm still getting "Symbol is Missing". Attaching a screenshot for reference. screen shot 2017-05-30 at 10 07 20 am

Is there anyway after the script updates symbols to go back through all the symbols and relink them?

UPDATE: On sketch version 44.1 the script works great - thank you drew! There are two small bugs 1) after the script runs I can't seem to change the page (unless I first click on an object in the layer list OR click on the blank space under the page list and 2) when a symbol is added it is placed on top of another symbol. On sketch version 43.2 I get the Symbol is missing.

drewloomer commented 7 years ago

@mattymatty Thanks for testing this! I'm not sure what to say about the first bug. Seems to be an issue with document.setCurrentPage or documentData().symbolsPageOrCreateIfNecessary(). Either way, I can't track it down and I'm guessing that bug actually exists with the current version of the plugin as well.

As for the second bug, I've updated the import logic to place imported symbols at the "visual" end of the symbols list. This will be after the bottom-most, right-most symbol. Does that makes sense? Please let me know if that works on your machine.

As for the symbols missing, I actually don't expect this plugin to work on 43.2. As you may know, v44 changed a bunch of the API and the file format, so I would assume something in changeInstanceToSymbol is broken. Unfortunately, I cannot downgrade to 43.2 to test this out :(. @kmerc, do you have strong feelings about supporting versions of Sketch <44?

Hoping we can get this wrapped up soon! Thanks again for all the feedback.

yourfavorite commented 7 years ago

Any word on when this will be merged into the main repo?

Also, is it stable enough to use now?

kmerc commented 7 years ago

@drewloomer Great work! Appreciate your time on this 👍 I have now merged @yourfavorite @florianpnn @timothyachumba @mattymatty Thanks all for your patience!