-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add data-lvt-target for cross-element targeting #53
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,6 +110,25 @@ export function parseReactiveAttribute( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Resolve the target element for an lvt-el: action. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * If the element has data-lvt-target, resolves to the specified element: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - "#id" → document.getElementById(id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - "closest:sel" → element.closest(sel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Falls back to the element itself if no target or target not found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function resolveTarget(element: Element): Element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const selector = element.getAttribute("data-lvt-target"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!selector) return element; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (selector.startsWith("#")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return document.getElementById(selector.slice(1)) || element; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (selector.startsWith("closest:")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return element.closest(selector.slice(8)) || element; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+116
to
+128
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * - "#id" → document.getElementById(id) | |
| * - "closest:sel" → element.closest(sel) | |
| * Falls back to the element itself if no target or target not found. | |
| */ | |
| export function resolveTarget(element: Element): Element { | |
| const selector = element.getAttribute("data-lvt-target"); | |
| if (!selector) return element; | |
| if (selector.startsWith("#")) { | |
| return document.getElementById(selector.slice(1)) || element; | |
| } | |
| if (selector.startsWith("closest:")) { | |
| return element.closest(selector.slice(8)) || element; | |
| } | |
| * - "#id" → element.ownerDocument.getElementById(id) | |
| * - "closest:sel" → element.closest(sel) | |
| * Falls back to the element itself if no target or target not found. | |
| */ | |
| export function resolveTarget(element: Element): Element { | |
| const target = element.getAttribute("data-lvt-target")?.trim(); | |
| if (!target) return element; | |
| if (target.startsWith("#")) { | |
| const id = target.slice(1).trim(); | |
| if (!id) return element; | |
| return element.ownerDocument.getElementById(id) || element; | |
| } | |
| if (target.startsWith("closest:")) { | |
| const closestSelector = target.slice(8).trim(); | |
| if (!closestSelector) return element; | |
| try { | |
| return element.closest(closestSelector) || element; | |
| } catch { | |
| return element; | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces a second
## [Unreleased]section at the top of the file while an existing## [Unreleased]section already exists further down. Please merge these into a single Unreleased section to avoid duplicated headings and keep changelog tooling/readers consistent.