feat(hx-trigger): add support for rootMargin on intersect
Description
Add support for rootMargin in intersect triggers. This allows us to extend the size of the intersect area. I've selected to separate multiple values using underscores, similar to how Tailwind solves it.
Corresponding issue: #1349
Testing
I've tested it locally using one of my own projects. I didn't find any tests for the intersect modifiers, so I couldn't find anything to base new tests on.
Checklist
- [x] I have read the contribution guidelines
- [x] I have targeted this PR against the correct branch (
masterfor website changes,devfor source changes) - [x] This is either a bugfix, a documentation update, or a new feature that has been explicitly approved via an issue
- [x] I ran the test suite locally (
npm run test) and verified that it succeeded
i like everything about this except the underscores. What if we consumed until EOF or the next token followed by a colon? (this may be a horrible idea idk)
I wasn't too excited about the underscores either, but I didn't have a better idea at the time. Two other options could be:
/,|(root)|(threshold)/to match comma or one of the other two intersect options/[,rt]/for comma and the starting character of the options
I think the first option is easier to understand though
@1cg any thoughts on the updated parsing proposal above?
I came to need this again, so I updated the API without the need for underscores. Now it works with all these variations:
intersect rootMargin:10%intersect rootMargin:10px 20px 30px 40pxintersect rootMargin:10px 10px threshold:0.1intersect rootMargin:10px 10px threshold:0.1 root:#test
Hi! Given there might be many elements with the need for lazy loading scroll with the same margin value, it would be nice to support setting a default value for all elements instead of specifying it for each element (not sure exactly how though).
@1cg What do you think about the updated API? I found a need for this again and remembered I had this PR 😅