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

Improve morph support for <template> elements #49

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Apr 12, 2024

Closes #15

When morphing <template> elements, treat the DocumentFragment
instances returned from the HTMLTemplateElement.content properties
as morphChildren methods' newParent and oldParent variables.

That way, descendant nodes can be iterated across the
connected-disconnected boundary.

@@ -110,7 +110,7 @@ var Idiomorph = (function () {
* @returns {boolean}
*/
function ignoreValueOfActiveElement(possibleActiveElement, ctx) {
return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement;
return ctx.ignoreActiveValue && possibleActiveElement === document.activeElement && possibleActiveElement !== document.body;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1cg this line (along with the rest of the generated portion of the diff) might be best merged as part of #47 (ahead of this PR).

@caleb
Copy link

caleb commented Aug 21, 2024

This would be very helpful to me. Right now I need to use a stimulus controller to copy the template contents on turbo:morph-element.

@seanpdoyle
Copy link
Contributor Author

@1cg are you able to review these changes? The crucial part of this diff is in the src/ and test/ directories. The rest of the diff includes changes in services of providing passing test coverage. They're proposed by individual related pull requests:

According to #25 (comment), I believe those changes would be covered by your process prior to cutting a new release:

Can you undo the changes to /dist? I'll generate those when we do the next release

If that's a requirement for this diff, I'm happy to exclude dist/ changes and only include src/ and test/.

@1cg
Copy link
Contributor

1cg commented Oct 12, 2024

hi @seanpdoyle this looks good to me, happy to merge

can I ask you to revert the changes to /dist for me and I'll pull it in? thank you!

Closes [bigskysoftware#15][]

When morphing `<template>` elements, treat the [DocumentFragment][]
instances returned from the [HTMLTemplateElement.content][] properties
as `morphChildren` methods' `newParent` and `oldParent` variables.

That way, descendant nodes can be iterated across the
connected-disconnected boundary.

[bigskysoftware#15]: bigskysoftware#15
[DocumentFragment]: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
[HTMLTemplateElement.content]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content
@seanpdoyle seanpdoyle force-pushed the morph-template-elements branch from dc8816e to a530659 Compare October 12, 2024 19:30
@seanpdoyle
Copy link
Contributor Author

@1cg thank you for the review. I've reverted the changes to dist/.

@1cg 1cg merged commit 831420e into bigskysoftware:main Oct 12, 2024
@seanpdoyle seanpdoyle deleted the morph-template-elements branch October 12, 2024 23:51
@scuml scuml mentioned this pull request Dec 5, 2024
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.

Template contents are not replaced on merge
3 participants