Skip to content

Commit

Permalink
prep for 1.9.11 release
Browse files Browse the repository at this point in the history
  • Loading branch information
1cg committed Mar 14, 2024
1 parent ef791c5 commit 11799bc
Show file tree
Hide file tree
Showing 18 changed files with 21,190 additions and 31,417 deletions.
39 changes: 26 additions & 13 deletions dist/ext/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
// Try to create EventSources when elements are processed
case "htmx:afterProcessNode":
ensureEventSourceOnElement(evt.target);
registerSSE(evt.target);
}
}
});
Expand Down Expand Up @@ -112,19 +111,18 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
* @param {HTMLElement} elt
*/
function registerSSE(elt) {
// Find closest existing event source
var sourceElement = api.getClosestMatch(elt, hasEventSource);
if (sourceElement == null) {
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
return null; // no eventsource in parentage, orphaned element
}

// Set internalData and source
var internalData = api.getInternalData(sourceElement);
var source = internalData.sseEventSource;

// Add message handlers for every `sse-swap` attribute
queryAttributeOnThisOrChildren(elt, "sse-swap").forEach(function(child) {
queryAttributeOnThisOrChildren(elt, "sse-swap").forEach(function (child) {
// Find closest existing event source
var sourceElement = api.getClosestMatch(child, hasEventSource);
if (sourceElement == null) {
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
return null; // no eventsource in parentage, orphaned element
}

// Set internalData and source
var internalData = api.getInternalData(sourceElement);
var source = internalData.sseEventSource;

var sseSwapAttr = api.getAttributeValue(child, "sse-swap");
if (sseSwapAttr) {
Expand All @@ -145,9 +143,13 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
// If the body no longer contains the element, remove the listener
if (!api.bodyContains(child)) {
source.removeEventListener(sseEventName, listener);
return;
}

// swap the response into the DOM and trigger a notification
if(!api.triggerEvent(elt, "htmx:sseBeforeMessage", event)) {
return;
}
swap(child, event.data);
api.triggerEvent(elt, "htmx:sseMessage", event);
};
Expand All @@ -160,6 +162,16 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions

// Add message handlers for every `hx-trigger="sse:*"` attribute
queryAttributeOnThisOrChildren(elt, "hx-trigger").forEach(function(child) {
// Find closest existing event source
var sourceElement = api.getClosestMatch(child, hasEventSource);
if (sourceElement == null) {
// api.triggerErrorEvent(elt, "htmx:noSSESourceError")
return null; // no eventsource in parentage, orphaned element
}

// Set internalData and source
var internalData = api.getInternalData(sourceElement);
var source = internalData.sseEventSource;

var sseEventName = api.getAttributeValue(child, "hx-trigger");
if (sseEventName == null) {
Expand Down Expand Up @@ -220,6 +232,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions
ensureEventSource(child, sseURL, retryCount);
});

registerSSE(elt);
}

function ensureEventSource(elt, url, retryCount) {
Expand Down
55 changes: 46 additions & 9 deletions dist/htmx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function addClass(elt: Element, clazz: string, delay?: number): void;
* @param element the element to target (defaults to the **body**)
* @returns Promise that resolves immediately if no request is sent, or when the request is complete
*/
export function ajax(verb: string, path: string, element: Element): Promise<void>;
export function ajax(verb: string, path: string, element?: Element): Promise<void>;

/**
* Issues an htmx-style AJAX request
Expand Down Expand Up @@ -429,20 +429,57 @@ export interface HtmxConfig {
* If set to true htmx will not update the title of the document when a title tag is found in new content
* @default false
*/
ignoreTitle:? boolean;
/**
* The cache to store evaluated trigger specifications into.
* You may define a simple object to use a never-clearing cache, or implement your own system using a [proxy object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
* @default null
*/
triggerSpecsCache?: {[trigger: string]: HtmxTriggerSpecification[]};
ignoreTitle?: boolean;
}

export type HtmxEvent = "htmx:abort"
| "htmx:afterOnLoad"
| "htmx:afterProcessNode"
| "htmx:afterRequest"
| "htmx:afterSettle"
| "htmx:afterSwap"
| "htmx:beforeCleanupElement"
| "htmx:beforeOnLoad"
| "htmx:beforeProcessNode"
| "htmx:beforeRequest"
| "htmx:beforeSwap"
| "htmx:beforeSend"
| "htmx:configRequest"
| "htmx:confirm"
| "htmx:historyCacheError"
| "htmx:historyCacheMiss"
| "htmx:historyCacheMissError"
| "htmx:historyCacheMissLoad"
| "htmx:historyRestore"
| "htmx:load"
| "htmx:noSSESourceError"
| "htmx:onLoadError"
| "htmx:oobAfterSwap"
| "htmx:oobBeforeSwap"
| "htmx:oobErrorNoTarget"
| "htmx:prompt"
| "htmx:pushedIntoHistory"
| "htmx:responseError"
| "htmx:sendError"
| "htmx:sseError"
| "htmx:sseOpen"
| "htmx:swapError"
| "htmx:targetError"
| "htmx:timeout"
| "htmx:validation:validate"
| "htmx:validation:failed"
| "htmx:validation:halted"
| "htmx:xhr:abort"
| "htmx:xhr:loadend"
| "htmx:xhr:loadstart"
| "htmx:xhr:progress"
;

/**
* https://htmx.org/extensions/#defining
*/
export interface HtmxExtension {
onEvent?: (name: string, evt: CustomEvent) => any;
onEvent?: (name: HtmxEvent, evt: CustomEvent) => any;
transformResponse?: (text: any, xhr: XMLHttpRequest, elt: any) => any;
isInlineSwap?: (swapStyle: any) => any;
handleSwap?: (swapStyle: any, target: any, fragment: any, settleInfo: any) => any;
Expand Down
35 changes: 26 additions & 9 deletions dist/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ return (function () {
sock.binaryType = htmx.config.wsBinaryType;
return sock;
},
version: "1.9.10"
version: "1.9.11"
};

/** @type {import("./htmx").HtmxInternalApi} */
Expand Down Expand Up @@ -309,10 +309,24 @@ return (function () {
content = content.replace(HEAD_TAG_REGEX, '');
}
if (htmx.config.useTemplateFragments && partialResponse) {
var documentFragment = parseHTML("<body><template>" + content + "</template></body>", 0);
var fragment = parseHTML("<body><template>" + content + "</template></body>", 0);
// @ts-ignore type mismatch between DocumentFragment and Element.
// TODO: Are these close enough for htmx to use interchangeably?
return documentFragment.querySelector('template').content;
if (htmx.config.allowScriptTags) {
// if there is a nonce set up, set it on the new script tags
forEach(fragment.querySelectorAll("script"), function (script) {
if (htmx.config.inlineScriptNonce) {
script.nonce = htmx.config.inlineScriptNonce;
}
getInternalData(script).executed = true; // mark as executed due to template insertion semantics
})
} else {
forEach(fragment.querySelectorAll("script"), function (script) {
// remove all script tags if scripts are disabled
removeElement(script);
})
}
return fragment.querySelector('template').content;
}
switch (startTag) {
case "thead":
Expand Down Expand Up @@ -1892,7 +1906,8 @@ return (function () {
}

function evalScript(script) {
if (htmx.config.allowScriptTags && (script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
if (!getInternalData(script).executed && htmx.config.allowScriptTags &&
(script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
var newScript = getDocument().createElement("script");
forEach(script.attributes, function (attr) {
newScript.setAttribute(attr.name, attr.value);
Expand All @@ -1918,12 +1933,14 @@ return (function () {
}

function processScripts(elt) {
if (matches(elt, "script")) {
evalScript(elt);
if (!htmx.config.useTemplateFragments) {
if (matches(elt, "script")) {
evalScript(elt);
}
forEach(findAll(elt, "script"), function (script) {
evalScript(script);
});
}
forEach(findAll(elt, "script"), function (script) {
evalScript(script);
});
}

function shouldProcessHxOn(elt) {
Expand Down
2 changes: 1 addition & 1 deletion dist/htmx.min.js

Large diffs are not rendered by default.

Binary file modified dist/htmx.min.js.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions www/static/node_modules/chai-dom/chai-dom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11799bc

Please sign in to comment.