-
-
Notifications
You must be signed in to change notification settings - Fork 0
Replace custom selector generation with @medv/finder #14
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
89dd2b2
Initial plan
Copilot 75ef081
Integrate @medv/finder for dynamic selector generation
Copilot 866bab5
Improve CSS.escape polyfill with full spec compliance
Copilot a1a2a6b
Remove redundant ID check, let finder handle all selectors
Copilot 49a5b3c
Replace custom CSS.escape polyfill with css.escape package
Copilot 136a717
Update dev dependencies and tooling
hirasso d394ced
Update unit tests workflow
hirasso a588cb5
Add changeset about the switch to @medv/finder
hirasso 93546af
Optimize usage of finder / formatting
hirasso 6dc78dd
Use happy-dom for support of `CSS.escape`
hirasso 5107e6f
add comment about tsc erroring if called via husky hook / lint-staged
hirasso 2aaa685
Optimize test for `@medv/finder`
hirasso 0e505ff
Optimize events tests
hirasso 4fd2dcf
Add changeset about updated dependencies
hirasso 5ba8514
Return a boolean from `restoreScroll()` indicating success / failure
hirasso df7cffe
Use `toggleAttribute` instead of `setAttribute` for marking target el…
hirasso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -69,5 +69,8 @@ | |
| "name": "pnpm", | ||
| "onFail": "warn" | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@medv/finder": "^4.0.2" | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,83 @@ | ||
| import { vi } from 'vitest'; | ||
| import { vi } from "vitest"; | ||
|
|
||
| // Stub browser functions for vitest | ||
| // console.log = vi.fn(); | ||
| // console.warn = vi.fn(); | ||
| // console.error = vi.fn(); | ||
|
|
||
| // Polyfill CSS.escape for jsdom | ||
| // Implementation based on: https://drafts.csswg.org/cssom/#the-css.escape()-method | ||
| declare global { | ||
| interface CSS { | ||
| escape(value: string): string; | ||
| } | ||
| } | ||
|
|
||
| if (!globalThis.CSS || !globalThis.CSS.escape) { | ||
| globalThis.CSS = globalThis.CSS || ({} as CSS); | ||
| globalThis.CSS.escape = (value: string): string => { | ||
| if (typeof value !== "string") { | ||
| throw new TypeError("CSS.escape requires a string argument"); | ||
| } | ||
|
|
||
| const length = value.length; | ||
| let result = ""; | ||
| let index = 0; | ||
|
|
||
| while (index < length) { | ||
| const character = value.charAt(index); | ||
| const charCode = character.charCodeAt(0); | ||
|
|
||
| // Handle null character | ||
| if (charCode === 0x0000) { | ||
| result += "\uFFFD"; | ||
| } | ||
| // If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F | ||
| else if ( | ||
| (charCode >= 0x0001 && charCode <= 0x001f) || | ||
| charCode === 0x007f | ||
| ) { | ||
| result += "\\" + charCode.toString(16) + " "; | ||
| } | ||
| // If the character is the first character and is a digit (U+0030 to U+0039) | ||
| else if (index === 0 && charCode >= 0x0030 && charCode <= 0x0039) { | ||
| result += "\\" + charCode.toString(16) + " "; | ||
| } | ||
| // If the character is the second character and is a digit (U+0030 to U+0039) | ||
| // and the first character is a `-` (U+002D) | ||
| else if ( | ||
| index === 1 && | ||
| charCode >= 0x0030 && | ||
| charCode <= 0x0039 && | ||
| value.charCodeAt(0) === 0x002d | ||
| ) { | ||
| result += "\\" + charCode.toString(16) + " "; | ||
| } | ||
| // If the character is the first character and is a `-` (U+002D), and there is no second character | ||
| else if (index === 0 && length === 1 && charCode === 0x002d) { | ||
| result += "\\" + character; | ||
| } | ||
| // If the character is not handled above and is greater than or equal to U+0080, | ||
| // is `-` (U+002D) or `_` (U+005F), or is in one of the ranges [0-9] (U+0030 to U+0039), | ||
| // [A-Z] (U+0041 to U+005A), or [a-z] (U+0061 to U+007A) | ||
| else if ( | ||
| charCode >= 0x0080 || | ||
| charCode === 0x002d || | ||
| charCode === 0x005f || | ||
| (charCode >= 0x0030 && charCode <= 0x0039) || | ||
| (charCode >= 0x0041 && charCode <= 0x005a) || | ||
| (charCode >= 0x0061 && charCode <= 0x007a) | ||
| ) { | ||
| result += character; | ||
| } | ||
| // Otherwise, the escaped character | ||
| else { | ||
| result += "\\" + character; | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.