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

Add support for extracting styles to tss #1177

Merged
merged 10 commits into from
Oct 29, 2023

Conversation

ewanharris
Copy link
Collaborator

@ewanharris ewanharris commented Oct 17, 2023

Implements a new refactoring action for views that allows extracting the properties from a tag and inserting them into the related TSS document. This can be triggered via the usual refactor shortcut, menu item, or lightbulb.

Some known todos (hence draft status) are:

  • Support nested properties (font only?)
  • Multiline properties
  • Better handling of class merging (currently only merging classes when performing whole line extraction)
  • Tests!

A demonstration is below, it first demonstrates extracting a select group of properties and then extract properties from the current line the cursor is on.

Screen.Recording.2023-10-17.at.22.11.17.mov

…o a tss file

Implements a code action that allows extract styles from an xml node into a tss document. It can
be triggered using the usual refactor shortcut, menu item, or lightbulb and supports running on
an entire line or just the selected properties.

Some known todos are:

* Support nested properties (font stuff)
* Multiline properties
* Better handling of class merging
* Tests!
@hansemannn
Copy link
Contributor

This is awesome! Regarding nested properties: All that we know are font and center (x and y). @m1ga Do you maybe have more? I wonder if they are somehow registered in Alloy already somewhere.

@m1ga
Copy link
Contributor

m1ga commented Oct 18, 2023

Nice feature 👍

@hansemannn sorry, don't know. Didn't even know that the font part was merged 😄 Not using that many inline styles at all. It looks like it is this PR tidev/alloy#765 and I would say that it supports all name.property=""

@hansemannn
Copy link
Contributor

Yep, handling them in general (detect a . inside an attribute) might be the best way to extract those. But handling those two manually for a PoC would also be more than sufficient.

@ewanharris ewanharris changed the title build: update node related build settings to use newer syntax Add support for extracting styles to tss Oct 18, 2023
@hansemannn
Copy link
Contributor

hansemannn commented Oct 19, 2023

Some more small improvements (can definitely be moved to a later stage as it's super low prio):

  • Use existing tab vs spacing settings of the file
  • Use existing single- vs double-quote settings of the file
  • Number properties, e.g. top="100" are added as strings, better would be top: 100
  • The following properties are not caught, yet:
    • backgroundColor="myColor"
    • contentWidth="100%"

@ewanharris
Copy link
Collaborator Author

@hansemannn I've ticked off everything in that list other than the spaces/tabs one, that'll need some digging into the vscode docs to see if I can get that information or if there's a way to have them handle it when applying the edits.

@ewanharris ewanharris marked this pull request as ready for review October 29, 2023 20:51
Copy link
Contributor

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, the changes work very well! Just to be sure: Is the version bumped automatically, or should it be adjusted in the package.json? EDIT: Okay, it seems like the CI does that, cool!

@hansemannn hansemannn merged commit 74c2a3f into tidev:master Oct 29, 2023
6 checks passed
@ewanharris ewanharris deleted the feat/extract-style-code-action branch October 29, 2023 22:05
ewanharris added a commit that referenced this pull request Oct 29, 2023
* build: update node related build settings to use newer syntax

* feat(providers/codeaction): allow extracting styles from an xml tag to a tss file

Implements a code action that allows extract styles from an xml node into a tss document. It can
be triggered using the usual refactor shortcut, menu item, or lightbulb and supports running on
an entire line or just the selected properties.

Some known todos are:

* Support nested properties (font stuff)
* Multiline properties
* Better handling of class merging
* Tests!

* feat: handle extracting object style properties

* fix: handle multi-line strings

* fix: allow percentages in values

* fix: handle not wrapping numbers, Alloy, Titanium APIs, wrap using correct quotes for file

* fix: handle “$.args” in attributes, show number-properties without quotes

* chore: add comma after new property

* fix: fix typo

* chore: remove last comma

---------

Co-authored-by: Hans Knöchel <h.knoechel@lambus.com>
github-actions bot pushed a commit that referenced this pull request Oct 29, 2023
# [1.3.0](v1.2.1...v1.3.0) (2023-10-29)

### Features

* add support for extracting styles to tss from views ([#1177](#1177)) ([67fa837](67fa837))
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

Successfully merging this pull request may close these issues.

3 participants