Update htmx to latest hyperscript, fix tests

This commit is contained in:
carson 2020-09-11 08:00:45 -06:00
parent 9c592d4e2f
commit 45f3909b9c
4 changed files with 1104 additions and 1012 deletions

View File

@ -457,7 +457,7 @@ return (function () {
processNode(child); processNode(child);
processScripts(child); processScripts(child);
processFocus(child) processFocus(child)
triggerEvent(child, 'htmx:load', {}); triggerEvent(child, 'htmx:load');
}; };
} }
@ -978,14 +978,10 @@ return (function () {
}); });
} }
function isHyperScriptAvailable() {
return typeof _hyperscript !== "undefined";
}
function findElementsToProcess(elt) { function findElementsToProcess(elt) {
if (elt.querySelectorAll) { if (elt.querySelectorAll) {
var results = elt.querySelectorAll(VERB_SELECTOR + ", a, form, [hx-sse], [data-hx-sse], [hx-ws]," + var results = elt.querySelectorAll(VERB_SELECTOR + ", a, form, [hx-sse], [data-hx-sse], [hx-ws]," +
" [data-hx-ws], [_], [script], [data-script]"); " [data-hx-ws]");
return results; return results;
} else { } else {
return []; return [];
@ -997,10 +993,6 @@ return (function () {
if (!nodeData.initialized) { if (!nodeData.initialized) {
nodeData.initialized = true; nodeData.initialized = true;
if (isHyperScriptAvailable()) {
_hyperscript.init(elt);
}
if (elt.value) { if (elt.value) {
nodeData.lastValue = elt.value; nodeData.lastValue = elt.value;
} }

View File

@ -11,6 +11,7 @@ describe("hyperscript integration", function() {
it('can trigger with a custom event', function () { it('can trigger with a custom event', function () {
this.server.respondWith("GET", "/test", "Custom Event Sent!"); this.server.respondWith("GET", "/test", "Custom Event Sent!");
var btn = make('<button _="on click send customEvent" hx-trigger="customEvent" hx-get="/test">Click Me!</button>') var btn = make('<button _="on click send customEvent" hx-trigger="customEvent" hx-get="/test">Click Me!</button>')
htmx.trigger(btn, "htmx:load"); // have to manually trigger the load event for non-AJAX dynamic content
btn.click(); btn.click();
this.server.respond(); this.server.respond();
btn.innerHTML.should.equal("Custom Event Sent!"); btn.innerHTML.should.equal("Custom Event Sent!");
@ -19,6 +20,7 @@ describe("hyperscript integration", function() {
it('can handle htmx driven events', function () { it('can handle htmx driven events', function () {
this.server.respondWith("GET", "/test", "Clicked!"); this.server.respondWith("GET", "/test", "Clicked!");
var btn = make('<button _="on htmx:afterSettle add .afterSettle" hx-get="/test">Click Me!</button>') var btn = make('<button _="on htmx:afterSettle add .afterSettle" hx-get="/test">Click Me!</button>')
htmx.trigger(btn, "htmx:load");
btn.classList.contains("afterSettle").should.equal(false); btn.classList.contains("afterSettle").should.equal(false);
btn.click(); btn.click();
this.server.respond(); this.server.respond();
@ -29,9 +31,20 @@ describe("hyperscript integration", function() {
this.server.respondWith("GET", "/test", [404, {}, "Bad request"]); this.server.respondWith("GET", "/test", [404, {}, "Bad request"]);
var div = make('<div id="d1"></div>') var div = make('<div id="d1"></div>')
var btn = make('<button _="on htmx:error(errorInfo) put errorInfo.error into #d1.innerHTML" hx-get="/test">Click Me!</button>') var btn = make('<button _="on htmx:error(errorInfo) put errorInfo.error into #d1.innerHTML" hx-get="/test">Click Me!</button>')
htmx.trigger(btn, "htmx:load");
btn.click(); btn.click();
this.server.respond(); this.server.respond();
div.innerHTML.should.equal("Response Status Error Code 404 from /test"); div.innerHTML.should.equal("Response Status Error Code 404 from /test");
}); });
it('hyperscript in non-htmx annotated nodes is evaluated', function () {
this.server.respondWith("GET", "/test", "<div><div><div id='d1' _='on click put \"Clicked...\" into my.innerHTML'></div></div></div>");
var btn = make('<button hx-get="/test">Click Me!</button>')
btn.click();
this.server.respond();
var newDiv = byId("d1");
newDiv.click();
newDiv.innerText.should.equal("Clicked...");
});
}); });

View File

@ -92,9 +92,6 @@
<!-- hyperscript integration --> <!-- hyperscript integration -->
<script src="lib/_hyperscript.js"></script> <script src="lib/_hyperscript.js"></script>
<script src="ext/hyperscript.js"></script> <script src="ext/hyperscript.js"></script>
<script>
_hyperscript.start();
</script>
<!-- extension tests --> <!-- extension tests -->
<script src="ext/extension-swap.js"></script> <script src="ext/extension-swap.js"></script>

File diff suppressed because it is too large Load Diff