-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into davidramos-customize-delay-for-instant-click…
…-behavior
- Loading branch information
Showing
21 changed files
with
343 additions
and
217 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Idiomorph } from "idiomorph/dist/idiomorph.esm" | ||
import { dispatch } from "../../../util" | ||
|
||
export default function morph(streamElement) { | ||
const morphStyle = streamElement.hasAttribute("children-only") ? "innerHTML" : "outerHTML" | ||
streamElement.targetElements.forEach((element) => { | ||
Idiomorph.morph(element, streamElement.templateContent, { | ||
morphStyle: morphStyle, | ||
callbacks: { | ||
beforeNodeAdded, | ||
beforeNodeMorphed, | ||
beforeAttributeUpdated, | ||
beforeNodeRemoved, | ||
afterNodeMorphed | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function beforeNodeAdded(node) { | ||
return !(node.id && node.hasAttribute("data-turbo-permanent") && document.getElementById(node.id)) | ||
} | ||
|
||
function beforeNodeRemoved(node) { | ||
return beforeNodeAdded(node) | ||
} | ||
|
||
function beforeNodeMorphed(target, newElement) { | ||
if (target instanceof HTMLElement) { | ||
if (!target.hasAttribute("data-turbo-permanent")) { | ||
const event = dispatch("turbo:before-morph-element", { | ||
cancelable: true, | ||
target, | ||
detail: { | ||
newElement | ||
} | ||
}) | ||
return !event.defaultPrevented | ||
} | ||
return false | ||
} | ||
} | ||
|
||
function beforeAttributeUpdated(attributeName, target, mutationType) { | ||
const event = dispatch("turbo:before-morph-attribute", { | ||
cancelable: true, | ||
target, | ||
detail: { | ||
attributeName, | ||
mutationType | ||
} | ||
}) | ||
return !event.defaultPrevented | ||
} | ||
|
||
function afterNodeMorphed(target, newElement) { | ||
if (newElement instanceof HTMLElement) { | ||
dispatch("turbo:morph-element", { | ||
target, | ||
detail: { | ||
newElement | ||
} | ||
}) | ||
} | ||
} |
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,3 @@ | ||
<turbo-frame id="refresh-after-navigation"> | ||
<h2 id="refresh-after-navigation-content">Frame has been navigated</h2> | ||
</turbo-frame> |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html id="html"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Morph Stream Action</title> | ||
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script> | ||
<script src="/src/tests/fixtures/test.js"></script> | ||
<meta name="turbo-refresh-method" content="replace"> | ||
</head> | ||
|
||
<body> | ||
<div id="message_1"> | ||
<div>Morph me</div> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.