-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: match selected node and style rules in client side (#8)
* chore: add style matcher module in view * fix: match selected node and style rules in client side so that we immediately react the style changes in editor for updating preview appearance
- Loading branch information
Showing
11 changed files
with
185 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Style, Rule } from '@/parser/style/types' | ||
import { Template } from '@/parser/template/types' | ||
import { createStyleMatcher } from '@/parser/style/match' | ||
|
||
type Matcher = (template: Template, path: number[]) => Rule[] | ||
|
||
export class StyleMatcher { | ||
private matchers = new Map<string, Matcher>() | ||
|
||
match(uri: string, template: Template, path: number[]): Rule[] { | ||
const matcher = this.matchers.get(uri) | ||
if (!matcher) { | ||
return [] | ||
} | ||
return matcher(template, path) | ||
} | ||
|
||
register(uri: string, styles: Style[]): void { | ||
const matcher = createStyleMatcher(styles) | ||
this.matchers.set(uri, matcher) | ||
} | ||
|
||
unregister(uri: string): void { | ||
this.matchers.delete(uri) | ||
} | ||
|
||
clear(): void { | ||
this.matchers.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.