From ddb75976293134bfa6c43cfaf5ebf9639bb8c5b1 Mon Sep 17 00:00:00 2001 From: Carson Gross Date: Thu, 21 Mar 2024 15:41:17 -0600 Subject: [PATCH] add warning if people aren't using the correct version of extensions --- dist/ext/ajax-header.js | 6 ++++- dist/ext/alpine-morph.js | 6 ++++- dist/ext/class-tools.js | 7 +++++- dist/ext/client-side-templates.js | 4 ++++ dist/ext/debug.js | 4 ++++ dist/ext/disable-element.js | 8 ++++--- dist/ext/event-header.js | 4 ++++ dist/ext/head-support.js | 7 +++++- dist/ext/include-vals.js | 4 ++++ dist/ext/json-enc.js | 8 +++++-- dist/ext/loading-states.js | 6 +++++ dist/ext/method-override.js | 4 ++++ dist/ext/morphdom-swap.js | 4 ++++ dist/ext/multi-swap.js | 7 +++++- dist/ext/path-deps.js | 17 ++++++++------ dist/ext/path-params.js | 6 ++++- dist/ext/preload.js | 24 +++++++++++-------- dist/ext/rails-method.js | 4 ++++ dist/ext/remove-me.js | 4 ++++ dist/ext/response-targets.js | 7 +++++- dist/ext/restored.js | 6 ++++- dist/ext/sse.js | 39 +++++++++++++++++-------------- dist/ext/ws.js | 5 ++++ 23 files changed, 144 insertions(+), 47 deletions(-) diff --git a/dist/ext/ajax-header.js b/dist/ext/ajax-header.js index 5c6221bf..be4758d5 100644 --- a/dist/ext/ajax-header.js +++ b/dist/ext/ajax-header.js @@ -1,7 +1,11 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('ajax-header', { onEvent: function (name, evt) { if (name === "htmx:configRequest") { evt.detail.headers['X-Requested-With'] = 'XMLHttpRequest'; } } -}); \ No newline at end of file +}); diff --git a/dist/ext/alpine-morph.js b/dist/ext/alpine-morph.js index 1872daec..fcf4b2b4 100644 --- a/dist/ext/alpine-morph.js +++ b/dist/ext/alpine-morph.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('alpine-morph', { isInlineSwap: function (swapStyle) { return swapStyle === 'morph'; @@ -13,4 +17,4 @@ htmx.defineExtension('alpine-morph', { } } } -}); \ No newline at end of file +}); diff --git a/dist/ext/class-tools.js b/dist/ext/class-tools.js index 1cf4b426..7d4bfa87 100644 --- a/dist/ext/class-tools.js +++ b/dist/ext/class-tools.js @@ -1,5 +1,10 @@ (function () { + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + function splitOnWhitespace(trigger) { return trigger.split(/\s+/); } @@ -89,4 +94,4 @@ } } }); -})(); \ No newline at end of file +})(); diff --git a/dist/ext/client-side-templates.js b/dist/ext/client-side-templates.js index 2bace419..a8e24ddf 100644 --- a/dist/ext/client-side-templates.js +++ b/dist/ext/client-side-templates.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('client-side-templates', { transformResponse : function(text, xhr, elt) { diff --git a/dist/ext/debug.js b/dist/ext/debug.js index 861ee743..b8a59a17 100644 --- a/dist/ext/debug.js +++ b/dist/ext/debug.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('debug', { onEvent: function (name, evt) { if (console.debug) { diff --git a/dist/ext/disable-element.js b/dist/ext/disable-element.js index 07bef62d..b9e25935 100644 --- a/dist/ext/disable-element.js +++ b/dist/ext/disable-element.js @@ -1,5 +1,7 @@ -"use strict"; - +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} // Disable Submit Button htmx.defineExtension('disable-element', { onEvent: function (name, evt) { @@ -15,4 +17,4 @@ htmx.defineExtension('disable-element', { } } } -}); \ No newline at end of file +}); diff --git a/dist/ext/event-header.js b/dist/ext/event-header.js index c7d29334..bcc5567c 100644 --- a/dist/ext/event-header.js +++ b/dist/ext/event-header.js @@ -1,4 +1,8 @@ (function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } function stringifyEvent(event) { var obj = {}; for (var key in event) { diff --git a/dist/ext/head-support.js b/dist/ext/head-support.js index 67cfc692..906ca233 100644 --- a/dist/ext/head-support.js +++ b/dist/ext/head-support.js @@ -5,6 +5,11 @@ //========================================================== (function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + var api = null; function log() { @@ -138,4 +143,4 @@ } }); -})() \ No newline at end of file +})() diff --git a/dist/ext/include-vals.js b/dist/ext/include-vals.js index d8f5ce4f..52ec67fb 100644 --- a/dist/ext/include-vals.js +++ b/dist/ext/include-vals.js @@ -1,4 +1,8 @@ (function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } function mergeObjects(obj1, obj2) { for (var key in obj2) { diff --git a/dist/ext/json-enc.js b/dist/ext/json-enc.js index db0aa36f..02b1792f 100644 --- a/dist/ext/json-enc.js +++ b/dist/ext/json-enc.js @@ -1,12 +1,16 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('json-enc', { onEvent: function (name, evt) { if (name === "htmx:configRequest") { evt.detail.headers['Content-Type'] = "application/json"; } }, - + encodeParameters : function(xhr, parameters, elt) { xhr.overrideMimeType('text/json'); return (JSON.stringify(parameters)); } -}); \ No newline at end of file +}); diff --git a/dist/ext/loading-states.js b/dist/ext/loading-states.js index c8ab51da..b5dfcf0e 100644 --- a/dist/ext/loading-states.js +++ b/dist/ext/loading-states.js @@ -1,4 +1,10 @@ ;(function () { + + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + let loadingStatesUndoQueue = [] function loadingStateContainer(target) { diff --git a/dist/ext/method-override.js b/dist/ext/method-override.js index 2e3504cb..cd84d6e5 100644 --- a/dist/ext/method-override.js +++ b/dist/ext/method-override.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('method-override', { onEvent: function (name, evt) { if (name === "htmx:configRequest") { diff --git a/dist/ext/morphdom-swap.js b/dist/ext/morphdom-swap.js index a1e53ce9..13d58adf 100644 --- a/dist/ext/morphdom-swap.js +++ b/dist/ext/morphdom-swap.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('morphdom-swap', { isInlineSwap: function(swapStyle) { return swapStyle === 'morphdom'; diff --git a/dist/ext/multi-swap.js b/dist/ext/multi-swap.js index f38f5b06..a9435323 100644 --- a/dist/ext/multi-swap.js +++ b/dist/ext/multi-swap.js @@ -1,5 +1,10 @@ (function () { + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + /** @type {import("../htmx").HtmxInternalApi} */ var api; @@ -42,4 +47,4 @@ } } }); -})(); \ No newline at end of file +})(); diff --git a/dist/ext/path-deps.js b/dist/ext/path-deps.js index 4987e50e..19e8541c 100644 --- a/dist/ext/path-deps.js +++ b/dist/ext/path-deps.js @@ -1,9 +1,12 @@ (function(undefined){ 'use strict'; - + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } // Save a reference to the global object (window in the browser) var _root = this; - + function dependsOn(pathSpec, url) { if (pathSpec === "ignore") { return false; @@ -30,8 +33,8 @@ if (dependsOn(elt.getAttribute('path-deps'), path)) { htmx.trigger(elt, "path-deps"); } - } - } + } + } htmx.defineExtension('path-deps', { onEvent: function (name, evt) { @@ -41,7 +44,7 @@ if (config.verb !== "get" && evt.target.getAttribute('path-deps') !== 'ignore') { refreshPath(config.path); } - } + } } }); @@ -49,12 +52,12 @@ * ******************** * Expose functionality * ******************** - */ + */ _root.PathDeps = { refresh: function(path) { refreshPath(path); } }; - + }).call(this); diff --git a/dist/ext/path-params.js b/dist/ext/path-params.js index e251b892..173696e0 100644 --- a/dist/ext/path-params.js +++ b/dist/ext/path-params.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('path-params', { onEvent: function(name, evt) { if (name === "htmx:configRequest") { @@ -8,4 +12,4 @@ htmx.defineExtension('path-params', { }) } } -}); \ No newline at end of file +}); diff --git a/dist/ext/preload.js b/dist/ext/preload.js index a7493703..74c5a3f7 100644 --- a/dist/ext/preload.js +++ b/dist/ext/preload.js @@ -1,5 +1,9 @@ -// This adds the "preload" extension to htmx. By default, this will -// preload the targets of any tags with `href` or `hx-get` attributes +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} +// This adds the "preload" extension to htmx. By default, this will +// preload the targets of any tags with `href` or `hx-get` attributes // if they also have a `preload` attribute as well. See documentation // for more details htmx.defineExtension("preload", { @@ -18,8 +22,8 @@ htmx.defineExtension("preload", { if (node == undefined) {return undefined;} return node.getAttribute(property) || node.getAttribute("data-" + property) || attr(node.parentElement, property) } - - // load handles the actual HTTP fetch, and uses htmx.ajax in cases where we're + + // load handles the actual HTTP fetch, and uses htmx.ajax in cases where we're // preloading an htmx resource (this sends the same HTTP headers as a regular htmx request) var load = function(node) { @@ -43,7 +47,7 @@ htmx.defineExtension("preload", { } // Special handling for HX-GET - use built-in htmx.ajax function - // so that headers match other htmx requests, then set + // so that headers match other htmx requests, then set // node.preloadState = TRUE so that requests are not duplicated // in the future var hxGet = node.getAttribute("hx-get") || node.getAttribute("data-hx-get") @@ -57,8 +61,8 @@ htmx.defineExtension("preload", { return; } - // Otherwise, perform a standard xhr request, then set - // node.preloadState = TRUE so that requests are not duplicated + // Otherwise, perform a standard xhr request, then set + // node.preloadState = TRUE so that requests are not duplicated // in the future. if (node.getAttribute("href")) { var r = new XMLHttpRequest(); @@ -83,16 +87,16 @@ htmx.defineExtension("preload", { if (node.preloadState !== undefined) { return; } - + // Get event name from config. var on = attr(node, "preload") || "mousedown" const always = on.indexOf("always") !== -1 if (always) { on = on.replace('always', '').trim() } - + // FALL THROUGH to here means we need to add an EventListener - + // Apply the listener to the node node.addEventListener(on, function(evt) { if (node.preloadState === "PAUSE") { // Only add one event listener diff --git a/dist/ext/rails-method.js b/dist/ext/rails-method.js index 5d48eccc..4843a346 100644 --- a/dist/ext/rails-method.js +++ b/dist/ext/rails-method.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('rails-method', { onEvent: function (name, evt) { if (name === "configRequest.htmx") { diff --git a/dist/ext/remove-me.js b/dist/ext/remove-me.js index 42be9932..47faf736 100644 --- a/dist/ext/remove-me.js +++ b/dist/ext/remove-me.js @@ -1,4 +1,8 @@ (function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } function maybeRemoveMe(elt) { var timing = elt.getAttribute("remove-me") || elt.getAttribute("data-remove-me"); if (timing) { diff --git a/dist/ext/response-targets.js b/dist/ext/response-targets.js index dd6fd418..a23c1aed 100644 --- a/dist/ext/response-targets.js +++ b/dist/ext/response-targets.js @@ -1,5 +1,10 @@ (function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + /** @type {import("../htmx").HtmxInternalApi} */ var api; @@ -58,7 +63,7 @@ } } } - + return null; } diff --git a/dist/ext/restored.js b/dist/ext/restored.js index 6f65267c..13daa343 100644 --- a/dist/ext/restored.js +++ b/dist/ext/restored.js @@ -1,3 +1,7 @@ +if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") +} htmx.defineExtension('restored', { onEvent : function(name, evt) { if (name === 'htmx:restored'){ @@ -12,4 +16,4 @@ htmx.defineExtension('restored', { } return; } -}) \ No newline at end of file +}) diff --git a/dist/ext/sse.js b/dist/ext/sse.js index 28c4dd32..5fecef65 100644 --- a/dist/ext/sse.js +++ b/dist/ext/sse.js @@ -7,6 +7,11 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions (function() { + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + /** @type {import("../htmx").HtmxInternalApi} */ var api; @@ -14,8 +19,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * Init saves the provided reference to the internal HTMX API. - * - * @param {import("../htmx").HtmxInternalApi} api + * + * @param {import("../htmx").HtmxInternalApi} api * @returns void */ init: function(apiRef) { @@ -30,9 +35,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * onEvent handles all events passed to this extension. - * - * @param {string} name - * @param {Event} evt + * + * @param {string} name + * @param {Event} evt * @returns void */ onEvent: function(name, evt) { @@ -64,8 +69,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * createEventSource is the default method for creating new EventSource objects. * it is hoisted into htmx.config.createEventSource to be overridden by the user, if needed. - * - * @param {string} url + * + * @param {string} url * @returns EventSource */ function createEventSource(url) { @@ -105,7 +110,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions } /** - * registerSSE looks for attributes that can contain sse events, right + * registerSSE looks for attributes that can contain sse events, right * now hx-trigger and sse-swap and adds listeners based on these attributes too * the closest event source * @@ -183,7 +188,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions if (sseEventName.slice(0, 4) != "sse:") { return; } - + // remove the sse: prefix from here on out sseEventName = sseEventName.substr(4); @@ -269,8 +274,8 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * maybeCloseSSESource confirms that the parent element still exists. * If not, then any associated SSE source is closed and the function returns true. - * - * @param {HTMLElement} elt + * + * @param {HTMLElement} elt * @returns boolean */ function maybeCloseSSESource(elt) { @@ -287,9 +292,9 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT. - * - * @param {HTMLElement} elt - * @param {string} attributeName + * + * @param {HTMLElement} elt + * @param {string} attributeName */ function queryAttributeOnThisOrChildren(elt, attributeName) { @@ -310,7 +315,7 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions /** * @param {HTMLElement} elt - * @param {string} content + * @param {string} content */ function swap(elt, content) { @@ -340,10 +345,10 @@ This extension adds support for Server Sent Events to htmx. See /www/extensions } /** - * doSettle mirrors much of the functionality in htmx that + * doSettle mirrors much of the functionality in htmx that * settles elements after their content has been swapped. * TODO: this should be published by htmx, and not duplicated here - * @param {import("../htmx").HtmxSettleInfo} settleInfo + * @param {import("../htmx").HtmxSettleInfo} settleInfo * @returns () => void */ function doSettle(settleInfo) { diff --git a/dist/ext/ws.js b/dist/ext/ws.js index c1e29620..8488b18b 100644 --- a/dist/ext/ws.js +++ b/dist/ext/ws.js @@ -6,6 +6,11 @@ This extension adds support for WebSockets to htmx. See /www/extensions/ws.md f (function () { + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://extensions.htmx.org") + } + /** @type {import("../htmx").HtmxInternalApi} */ var api;