htmx v4, alpha8 #18

Merged
danieljsummers merged 1 commits from v4alpha8 into htmx-v4 2026-03-22 22:21:23 +00:00
9 changed files with 17 additions and 19 deletions
Showing only changes of commit 0b4e52389d - Show all commits

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
module Giraffe.Htmx.Common
/// <summary>The version of htmx embedded in the package</summary>
let HtmxVersion = "4.0.0-alpha6"
let HtmxVersion = "4.0.0-alpha8"
/// <summary>The path for the provided htmx script</summary>
let internal htmxLocalScript = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
+1 -1
View File
@@ -2,6 +2,6 @@
This package contains common code shared between [`Giraffe.Htmx`](https://www.nuget.org/packages/Giraffe.Htmx) and [`Giraffe.ViewEngine.Htmx`](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx), and will be automatically installed when you install either one. It also contains htmx as a static web asset, allowing it to be loaded from your local (or published) project.
**htmx version: 4.0.0-alpha6**
**htmx version: 4.0.0-alpha8**
_**NOTE:** Pay special attention to breaking changes highlighted in the packages listed above._
+1 -1
View File
@@ -1 +1 @@
var htmx=(()=>{class e{#e=null;#t=[];issue(e,t){return e.queueStrategy=t,this.#e?"replace"===t||"abort"!==t&&"abort"===this.#e.queueStrategy?(this.#t.map(e=>e.status="dropped"),this.#t=[],this.#e.request.abort(),this.#e=e,!0):("queue all"===t?(this.#t.push(e),e.status="queued"):"drop"===t?e.status="dropped":"queue last"===t?(this.#t.map(e=>e.status="dropped"),this.#t=[e],e.status="queued"):0===this.#t.length&&"abort"!==t?(this.#t.push(e),e.status="queued"):e.status="dropped",!1):(this.#e=e,!0)}finish(){this.#e=null}next(){return this.#t.shift()}abort(){this.#e?.abort?.()}more(){return this.#t?.length}}return new class{#r=new Map;#i="";#s=new Set;#n;#a;#o="a,form";#l=["get","post","put","patch","delete"];#h;#c;#u;constructor(){this.#d(),this.#f(),this.#a=`[${this.#m("hx-action")}],[${this.#m("hx-get")}],[${this.#m("hx-post")}],[${this.#m("hx-put")}],[${this.#m("hx-patch")}],[${this.#m("hx-delete")}]`,this.#h=(new XPathEvaluator).createExpression(`.//*[@*[ starts-with(name(), "${this.#m("hx-on")}")]]`),this.#n={attributeValue:this.#p.bind(this),parseTriggerSpecs:this.#g.bind(this),determineMethodAndAction:this.#x.bind(this),createRequestContext:this.#b.bind(this),collectFormData:this.#y.bind(this),handleHxVals:this.#v.bind(this),insertContent:this.#S.bind(this),morph:this.#E.bind(this)},document.addEventListener("DOMContentLoaded",()=>{this.#w(),this.process(document.body)})}#d(){this.config={version:"4.0.0-alpha6",logAll:!1,prefix:"",transitions:!1,history:!0,mode:"same-origin",defaultSwap:"innerHTML",indicatorClass:"htmx-indicator",requestClass:"htmx-request",includeIndicatorCSS:!0,defaultTimeout:6e4,extensions:"",sse:{reconnect:!1,reconnectDelay:500,reconnectMaxDelay:6e4,reconnectMaxAttempts:10,reconnectJitter:.3,pauseInBackground:!1},morphIgnore:["data-htmx-powered"],morphScanLimit:10,noSwap:[204,304],implicitInheritance:!1};let e=document.querySelector('meta[name="htmx-config"]');e&&this.#C(e.content,this.config),this.#i=this.config.extensions}#f(){if(!1!==this.config.includeIndicatorCSS){let e="";this.config.inlineStyleNonce&&(e=` nonce="${this.config.inlineStyleNonce}"`);let t=this.config.indicatorClass,r=this.config.requestClass;document.head.insertAdjacentHTML("beforeend",`<style${e}>.${t}{opacity:0;visibility: hidden} .${r} .${t}, .${r}.${t}{opacity:1;visibility: visible;transition: opacity 200ms ease-in}</style>`)}}registerExtension(e,t){return!(this.#i&&!this.#i.split(/,\s*/).includes(e))&&(!this.#s.has(e)&&(this.#s.add(e),t.init&&t.init(this.#n),void Object.entries(t).forEach(([e,t])=>{this.#r.get(e)?.push(t)||this.#r.set(e,[t])})))}#q(e){return!e.closest||null!=e.closest(`[${this.#m("hx-ignore")}]`)}#m(e){return this.config.prefix?e.replace("hx-",this.config.prefix):e}#A(e,t){let r=[...e.querySelectorAll(t)];return e.matches?.(t)&&r.unshift(e),r}#T(e){return"before"===e?"beforebegin":"after"===e?"afterend":"prepend"===e?"afterbegin":"append"===e?"beforeend":e}#M(e,t){let r=[];return this.#p(e,t,void 0,(e,t)=>{e?.split(/\s*,\s*/).includes("this")&&r.push(t)}),r}#p(e,t,r,i){let s=(t=this.#m(t))+this.#N(":append"),n=t+(this.config.implicitInheritance?"":this.#N(":inherited")),a=t+this.#N(":inherited:append");if(e.hasAttribute(t)){let r=e.getAttribute(t);return i?i(r,e):r}if(e.hasAttribute(n)){let t=e.getAttribute(n);return i?i(t,e):t}if(e.hasAttribute(s)||e.hasAttribute(a)){let r=e.getAttribute(s)||e.getAttribute(a),o=e.parentNode?.closest?.(`[${CSS.escape(n)}],[${CSS.escape(a)}]`);if(i&&i(r,e),o){let e=this.#p(o,t,void 0,i);return e?(e+","+r).replace(/[{}]/g,""):r}return r}let o=e.parentNode?.closest?.(`[${CSS.escape(n)}],[${CSS.escape(a)}]`);if(o){let r=this.#p(o,t,void 0,i);return!i&&r&&this.config.implicitInheritance&&this.#I(e,"htmx:after:implicitInheritance",{elt:e,name:t,parent:o}),r}return r}#H(e){if("{"===e[0])return JSON.parse(e);return[...e.matchAll(/(?:"([^"]+)"|([^\s,:]+))(?:\s*:\s*(?:"([^"]*)"|'([^']*)'|<([^>]+)\/>|([^\s,]+)))?(?=\s|,|$)/g)].reduce((e,t)=>{let r=(t[1]??t[2]).split("."),i=(t[3]??t[4]??t[5]??t[6]??"true").trim();return"true"===i?i=!0:"false"===i?i=!1:/^\d+$/.test(i)&&(i=parseInt(i)),r.slice(0,-1).reduce((e,t)=>e[t]??={},e)[r.at(-1)]=i,e},{})}#C(e,t){let r=this.#H(e);for(let e in r){let i=r[e];i&&"object"==typeof i&&!Array.isArray(i)&&t[e]?Object.assign(t[e],i):t[e]=i}return t}#g(e){return e.split(",").map(e=>{let t=e.match(/^\s*(\S+\[[^\]]*\]|\S+)\s*(.*?)\s*$/);if(!t||!t[1])return null;if(t[1].includes("[")&&!t[1].includes("]"))throw"unterminated:"+t[1];let r=t[2]?this.#H(t[2]):{};return r.name=t[1],r}).filter(e=>e)}#x(e,t){if(this.#O(e))return this.#L(e,t);{let t=this.#p(e,"hx-method")||"GET",r=this.#p(e,"hx-action");if(!r)for(let i of this.#l){let s=this.#p(e,"hx-"+i);if(s){r=s,t=i;break}}return t=t.toUpperCase(),{action:r,method:t}}}#L(e,t){if(e.matches("a"))return{action:e.getAttribute("href"),method:"GET"};return{action:t.submitter?.getAttribute?.("formAction")||e.getAttribute("action"),method:t.submitter?.getAttribute?.("formMethod")||e.getAttribute("method")||"GLine truncated
var htmx=(()=>{class e{#e=null;#t=[];issue(e,t){return e.queueStrategy=t,this.#e?"replace"===t||"abort"!==t&&"abort"===this.#e.queueStrategy?(this.#t.forEach(e=>e.status="dropped"),this.#t=[],this.#e.request?.abort?.(),this.#e=e,!0):("queue all"===t?(this.#t.push(e),e.status="queued"):"drop"===t?e.status="dropped":"queue last"===t?(this.#t.forEach(e=>e.status="dropped"),this.#t=[e],e.status="queued"):0===this.#t.length&&"abort"!==t?(this.#t.push(e),e.status="queued"):e.status="dropped",!1):(this.#e=e,!0)}finish(){this.#e=null}next(){return this.#t.shift()}abort(){this.#e?.request?.abort?.()}more(){return this.#t?.length}}return new class{#r=new Map;#i="";#s=new Set;#n;#a;#o="a,form";#l=["get","post","put","patch","delete"];#h;#u;#c;#d;constructor(){this.#f(),this.#m(),this.#a=`[${this.#p("hx-action")}],[${this.#p("hx-get")}],[${this.#p("hx-post")}],[${this.#p("hx-put")}],[${this.#p("hx-patch")}],[${this.#p("hx-delete")}]`,this.#h=(new XPathEvaluator).createExpression(`.//*[@*[ starts-with(name(), "${this.#p("hx-on")}")]]`),this.#n={attributeValue:this.#g.bind(this),parseTriggerSpecs:this.#b.bind(this),determineMethodAndAction:this.#x.bind(this),createRequestContext:this.#y.bind(this),collectFormData:this.#v.bind(this),getAttributeObject:this.#S.bind(this),insertContent:this.#E.bind(this),morph:this.#w.bind(this),isSoftMatch:this.#C.bind(this),onTrigger:this.#A.bind(this),htmxProp:this.#q.bind(this),triggerHtmxEvent:this.#T.bind(this)};let e=()=>{this.#M(),this.process(document.body)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):setTimeout(e)}#f(){this.version="4.0.0-alpha8",this.config={logAll:!1,prefix:"",transitions:!1,history:!0,mode:"same-origin",defaultSwap:"innerHTML",defaultFocusScroll:!1,indicatorClass:"htmx-indicator",requestClass:"htmx-request",includeIndicatorCSS:!0,defaultTimeout:6e4,extensions:"",morphIgnore:["data-htmx-powered"],morphScanLimit:10,noSwap:[204,304],implicitInheritance:!1,defaultSettleDelay:1};let e=document.querySelector('meta[name="htmx-config"]');e&&this.#N(e.content,this.config),this.#i=this.config.extensions}#m(){if(!1!==this.config.includeIndicatorCSS){let e="";this.config.inlineStyleNonce&&(e=` nonce="${this.config.inlineStyleNonce}"`);let t=this.config.indicatorClass,r=this.config.requestClass;document.head.insertAdjacentHTML("beforeend",`<style${e}>.${t}{opacity:0;visibility: hidden} .${r} .${t}, .${r}.${t}{opacity:1;visibility: visible;transition: opacity 200ms ease-in}</style>`)}}registerExtension(e,t){return!(this.#i&&!this.#i.split(/,\s*/).includes(e))&&(!this.#s.has(e)&&(this.#s.add(e),t.init&&t.init(this.#n),void Object.entries(t).forEach(([e,t])=>{this.#r.get(e)?.push(t)||this.#r.set(e,[t])})))}#H(e){return!e.closest||null!=e.closest(`[${this.#p("hx-ignore")}]`)}#p(e){return this.config.prefix?e.replace("hx-",this.config.prefix):e}#I(e,t){let r=[...e.querySelectorAll?.(t)??[]];return e.matches?.(t)&&r.unshift(e),r}#O(e){return"before"===e?"beforebegin":"after"===e?"afterend":"prepend"===e?"afterbegin":"append"===e?"beforeend":e}#L(e,t){let r=[];return this.#g(e,t,void 0,(e,t)=>{e?.split(/\s*,\s*/).includes("this")&&r.push(t)}),r}#g(e,t,r,i){let s=t,n=(t=this.#k(this.#p(t)))+this.#k(":append"),a=t+(this.config.implicitInheritance?"":this.#k(":inherited")),o=t+this.#k(":inherited:append");if(e.hasAttribute(t)){let r=e.getAttribute(t);return i?i(r,e):r}if(e.hasAttribute(a)){let t=e.getAttribute(a);return i?i(t,e):t}if(e.hasAttribute(n)||e.hasAttribute(o)){let t=e.getAttribute(n)||e.getAttribute(o),r=e.parentNode?.closest?.(`[${CSS.escape(a)}],[${CSS.escape(o)}]`);if(i&&i(t,e),r){let e=this.#g(r,s,void 0,i);return e?(e+","+t).replace(/[{}]/g,""):t}return t}let l=e.parentNode?.closest?.(`[${CSS.escape(a)}],[${CSS.escape(o)}]`);if(l){let r=this.#g(l,s,void 0,i);return!i&&r&&this.config.implicitInheritance&&this.#R(e,"htmx:after:implicitInheritance",{elt:e,name:t,parent:l}),r}return r}#j(e){if(!e)return{};if("{"===e[0])return JSON.parse(e);return[...e.matchAll(/(?:"([^"]+)"|([^\s,:]+))(?:\s*:\s*(?:"([^"]*)"|'([^']*)'|<([^>]+)\/>|([^\s,]+)))?(?=\s|,|$)/g)].reduce((e,t)=>{let r=(t[1]??t[2]).split("."),i=(t[3]??t[4]??t[5]??t[6]??"true").trim();return"true"===i?i=!0:"false"===i?i=!1:/^\d+$/.test(i)&&(i=parseInt(i)),r.some(e=>this.#V(e))||(r.slice(0,-1).reduce((e,t)=>e[t]??={},e)[r.at(-1)]=i),e},{})}#V(e){return"#proto#"===e||"constructor"===e||"prototype"===e}#N(e,t){let r=this.#j(e);for(let e in r){if(this.#V(e))continue;let i=r[e];i&&"object"==typeof i&&!Array.isArray(i)&&t[e]?Object.assign(t[e],i):t[e]=i}return t}#b(e){return e.split(",").map(e=>{let t=e.match(/^\s*(\S+\[[^\]]*\]|\S+)\s*(.*?)\s*$/);if(!t||!t[1])return null;if(t[1].includes("[")&&!t[1].includes("]"))throw"unterminated:"+t[1];let r=t[2]?this.#j(t[2]):{};return r.name=t[1],r}).filter(e=>e)}#x(e,t){if(this.#P(e))return this.#B(e,t);{let t=this.#g(e,"hx-method")||"GET",r=this.#g(e,"hx-action");if(!r)for(let i of this.#l){let s=this.#g(e,"hx-"+i);if(null!=s){r=s,t=i;break}}reLine truncated
+5 -7
View File
@@ -3,15 +3,13 @@
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<VersionPrefix>4.0.0</VersionPrefix>
<VersionSuffix>alpha6a</VersionSuffix>
<VersionSuffix>alpha8</VersionSuffix>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReleaseNotes>First htmx 4 alpha release of these libraries
- [Server] Marked removed headers as obsolete; added new HX-Source header
- [View Engine] Marked removed attributes as obsolete
- [View Engine] Added new attributes, modifiers, and support for new hx-partial tag
- Updated script tags to pull htmx 4.0.0-alpha6
<PackageReleaseNotes>Update htmx 4 to alpha8
- [Common] Update provided htmx 4 to 4.0.0-alpha8
- [View Engine] Updated script tags to pull htmx 4.0.0-alpha8
See package READMEs; this is not an update-and-forget-it release
See package and prior alpha release READMEs; v2 to v4 is not an update-and-forget-it release
</PackageReleaseNotes>
<Authors>danieljsummers</Authors>
<Company>Bit Badger Solutions</Company>
+1 -1
View File
@@ -2,7 +2,7 @@
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
**htmx version: 4.0.0-alpha6**
**htmx version: 4.0.0-alpha8**
_Upgrading from v2.x: the [migration guide](https://four.htmx.org/migration-guide-htmx-4/) lists changes for v4. For this package, the `HX-Trigger` and `HX-Trigger-Name` headers are marked obsolete. They are replaced by `HX-Source`, which provides the triggering tag name and `id` attribute. The `HX-Prompt` header has also been marked as obsolete, as the `hx-prompt` attribute which generated its content has been removed._
+1 -1
View File
@@ -6,7 +6,7 @@ open Giraffe.Htmx
/// Test to ensure the version was updated
let version =
test "HtmxVersion is correct" {
Expect.equal HtmxVersion "4.0.0-alpha6" "htmx version incorrect"
Expect.equal HtmxVersion "4.0.0-alpha8" "htmx version incorrect"
}
/// Tests for the HxSwap module
+2 -2
View File
@@ -687,14 +687,14 @@ let script =
let html = RenderView.AsString.htmlNode Script.cdnMinified
Expect.equal
html
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-/5n21KGM472oBhvzUrvju8FRDq/4WNMS3TGw5RWFkZR/kq+sCevqNXFcakqRtaHu" crossorigin="anonymous"></script>"""
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-hUj4cz/Dd2p+Dq0r8A6TAMS1u7gu2bTyisk8xCQX3nodazPP+fRmcAWJrTh4Ycwb" crossorigin="anonymous"></script>"""
"CDN minified script tag is incorrect"
}
test "cdnUnminified succeeds" {
let html = RenderView.AsString.htmlNode Script.cdnUnminified
Expect.equal
html
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-I3uRy2RjSNcS8Oi2SNWZD9IrafyrrrBb4QaHNA9pWVWfJuKtL0p8qAwHSrEyXoKh" crossorigin="anonymous"></script>"""
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-CHKZYHwIgmpkwoWtoPaiFIiMxP1Up7yHcsZ2NeECzLxRTXCO0mqXlujZwdJgFsFC" crossorigin="anonymous"></script>"""
"CDN unminified script tag is incorrect"
}
]
+4 -4
View File
@@ -978,15 +978,15 @@ module Script =
/// <summary>Script tag to load the minified version from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMinified =
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha6/dist/htmx.min.js"
_integrity "sha384-/5n21KGM472oBhvzUrvju8FRDq/4WNMS3TGw5RWFkZR/kq+sCevqNXFcakqRtaHu"
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha8/dist/htmx.min.js"
_integrity "sha384-hUj4cz/Dd2p+Dq0r8A6TAMS1u7gu2bTyisk8xCQX3nodazPP+fRmcAWJrTh4Ycwb"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the unminified version from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnUnminified =
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha6/dist/htmx.js"
_integrity "sha384-I3uRy2RjSNcS8Oi2SNWZD9IrafyrrrBb4QaHNA9pWVWfJuKtL0p8qAwHSrEyXoKh"
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha8/dist/htmx.js"
_integrity "sha384-CHKZYHwIgmpkwoWtoPaiFIiMxP1Up7yHcsZ2NeECzLxRTXCO0mqXlujZwdJgFsFC"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the minified version from jsdelivr.net</summary>
+1 -1
View File
@@ -2,7 +2,7 @@
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
**htmx version: 4.0.0-alpha6**
**htmx version: 4.0.0-alpha8**
_Upgrading from v2.x: see [the migration guide](https://four.htmx.org/migration-guide-htmx-4/) for changes, which are plentiful. htmx switches from `XMLHTTPRequest` to `fetch`, and many changes are related to the new event cycle._