Skip to content

Commit

Permalink
prep beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
1cg committed May 16, 2024
1 parent a216e1b commit 12675fd
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ By removing these arbitrary constraints htmx completes HTML as a
## quick start

```html
<script src="https://unpkg.com/htmx.org@2.0.0-beta3"></script>
<script src="https://unpkg.com/htmx.org@2.0.0-beta4"></script>
<!-- have a button POST a click via AJAX -->
<button hx-post="/clicked" hx-swap="outerHTML">
Click Me
Expand Down
41 changes: 36 additions & 5 deletions dist/htmx.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ var htmx = (function() {
* @default ''
*/
inlineScriptNonce: '',
/**
* If set, the nonce will be added to inline styles.
* @type string
* @default ''
*/
inlineStyleNonce: '',
/**
* The attributes to settle during the settling phase.
* @type string[]
Expand Down Expand Up @@ -272,7 +278,7 @@ var htmx = (function() {
parseInterval: null,
/** @type {typeof internalEval} */
_: null,
version: '2.0.0-beta3'
version: '2.0.0-beta4'
}
// Tsc madness part 2
htmx.onLoad = onLoadHelper
Expand Down Expand Up @@ -2252,6 +2258,13 @@ var htmx = (function() {
getRawAttribute(elt, 'href').indexOf('#') !== 0
}

/**
* @param {Element} elt
*/
function eltIsDisabled(elt) {
return closest(elt, htmx.config.disableSelector)
}

/**
* @param {Element} elt
* @param {HtmxNodeInternalData} nodeData
Expand All @@ -2274,7 +2287,7 @@ var htmx = (function() {
triggerSpecs.forEach(function(triggerSpec) {
addEventListener(elt, function(node, evt) {
const elt = asElement(node)
if (closest(elt, htmx.config.disableSelector)) {
if (eltIsDisabled(elt)) {
cleanUpElement(elt)
return
}
Expand Down Expand Up @@ -2636,8 +2649,21 @@ var htmx = (function() {
function findElementsToProcess(elt) {
if (elt.querySelectorAll) {
const boostedSelector = ', [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]'

const extensionSelectors = []
for (const e in extensions) {
const extension = extensions[e]
if (extension.getSelectors) {
var selectors = extension.getSelectors()
if (selectors) {
extensionSelectors.push(selectors)
}
}
}

const results = elt.querySelectorAll(VERB_SELECTOR + boostedSelector + ", form, [type='submit']," +
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]')
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]' + extensionSelectors.flat().map(s => ', ' + s).join(''))

return results
} else {
return []
Expand Down Expand Up @@ -2696,7 +2722,7 @@ var htmx = (function() {
}

/**
* @param {EventTarget} elt
* @param {Element} elt
* @param {string} eventName
* @param {string} code
*/
Expand All @@ -2709,6 +2735,9 @@ var htmx = (function() {
/** @type EventListener */
const listener = function(e) {
maybeEval(elt, function() {
if (eltIsDisabled(elt)) {
return
}
if (!func) {
func = new Function('event', code)
}
Expand Down Expand Up @@ -4755,6 +4784,7 @@ var htmx = (function() {
function extensionBase() {
return {
init: function(api) { return null },
getSelectors: function() { return null },
onEvent: function(name, evt) { return true },
transformResponse: function(text, xhr, elt) { return text },
isInlineSwap: function(swapStyle) { return false },
Expand Down Expand Up @@ -4853,8 +4883,9 @@ var htmx = (function() {

function insertIndicatorStyles() {
if (htmx.config.includeIndicatorStyles !== false) {
const nonceAttribute = htmx.config.inlineStyleNonce ? ` nonce="${htmx.config.inlineStyleNonce}"` : ''
getDocument().head.insertAdjacentHTML('beforeend',
'<style>\
'<style' + nonceAttribute + '>\
.' + htmx.config.indicatorClass + '{opacity:0}\
.' + htmx.config.requestClass + ' .' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
.' + htmx.config.requestClass + '.' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
Expand Down
41 changes: 36 additions & 5 deletions dist/htmx.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ var htmx = (function() {
* @default ''
*/
inlineScriptNonce: '',
/**
* If set, the nonce will be added to inline styles.
* @type string
* @default ''
*/
inlineStyleNonce: '',
/**
* The attributes to settle during the settling phase.
* @type string[]
Expand Down Expand Up @@ -271,7 +277,7 @@ var htmx = (function() {
parseInterval: null,
/** @type {typeof internalEval} */
_: null,
version: '2.0.0-beta3'
version: '2.0.0-beta4'
}
// Tsc madness part 2
htmx.onLoad = onLoadHelper
Expand Down Expand Up @@ -2251,6 +2257,13 @@ var htmx = (function() {
getRawAttribute(elt, 'href').indexOf('#') !== 0
}

/**
* @param {Element} elt
*/
function eltIsDisabled(elt) {
return closest(elt, htmx.config.disableSelector)
}

/**
* @param {Element} elt
* @param {HtmxNodeInternalData} nodeData
Expand All @@ -2273,7 +2286,7 @@ var htmx = (function() {
triggerSpecs.forEach(function(triggerSpec) {
addEventListener(elt, function(node, evt) {
const elt = asElement(node)
if (closest(elt, htmx.config.disableSelector)) {
if (eltIsDisabled(elt)) {
cleanUpElement(elt)
return
}
Expand Down Expand Up @@ -2635,8 +2648,21 @@ var htmx = (function() {
function findElementsToProcess(elt) {
if (elt.querySelectorAll) {
const boostedSelector = ', [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]'

const extensionSelectors = []
for (const e in extensions) {
const extension = extensions[e]
if (extension.getSelectors) {
var selectors = extension.getSelectors()
if (selectors) {
extensionSelectors.push(selectors)
}
}
}

const results = elt.querySelectorAll(VERB_SELECTOR + boostedSelector + ", form, [type='submit']," +
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]')
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]' + extensionSelectors.flat().map(s => ', ' + s).join(''))

return results
} else {
return []
Expand Down Expand Up @@ -2695,7 +2721,7 @@ var htmx = (function() {
}

/**
* @param {EventTarget} elt
* @param {Element} elt
* @param {string} eventName
* @param {string} code
*/
Expand All @@ -2708,6 +2734,9 @@ var htmx = (function() {
/** @type EventListener */
const listener = function(e) {
maybeEval(elt, function() {
if (eltIsDisabled(elt)) {
return
}
if (!func) {
func = new Function('event', code)
}
Expand Down Expand Up @@ -4754,6 +4783,7 @@ var htmx = (function() {
function extensionBase() {
return {
init: function(api) { return null },
getSelectors: function() { return null },
onEvent: function(name, evt) { return true },
transformResponse: function(text, xhr, elt) { return text },
isInlineSwap: function(swapStyle) { return false },
Expand Down Expand Up @@ -4852,8 +4882,9 @@ var htmx = (function() {

function insertIndicatorStyles() {
if (htmx.config.includeIndicatorStyles !== false) {
const nonceAttribute = htmx.config.inlineStyleNonce ? ` nonce="${htmx.config.inlineStyleNonce}"` : ''
getDocument().head.insertAdjacentHTML('beforeend',
'<style>\
'<style' + nonceAttribute + '>\
.' + htmx.config.indicatorClass + '{opacity:0}\
.' + htmx.config.requestClass + ' .' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
.' + htmx.config.requestClass + '.' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
Expand Down
41 changes: 36 additions & 5 deletions dist/htmx.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ var htmx = (function() {
* @default ''
*/
inlineScriptNonce: '',
/**
* If set, the nonce will be added to inline styles.
* @type string
* @default ''
*/
inlineStyleNonce: '',
/**
* The attributes to settle during the settling phase.
* @type string[]
Expand Down Expand Up @@ -271,7 +277,7 @@ var htmx = (function() {
parseInterval: null,
/** @type {typeof internalEval} */
_: null,
version: '2.0.0-beta3'
version: '2.0.0-beta4'
}
// Tsc madness part 2
htmx.onLoad = onLoadHelper
Expand Down Expand Up @@ -2251,6 +2257,13 @@ var htmx = (function() {
getRawAttribute(elt, 'href').indexOf('#') !== 0
}

/**
* @param {Element} elt
*/
function eltIsDisabled(elt) {
return closest(elt, htmx.config.disableSelector)
}

/**
* @param {Element} elt
* @param {HtmxNodeInternalData} nodeData
Expand All @@ -2273,7 +2286,7 @@ var htmx = (function() {
triggerSpecs.forEach(function(triggerSpec) {
addEventListener(elt, function(node, evt) {
const elt = asElement(node)
if (closest(elt, htmx.config.disableSelector)) {
if (eltIsDisabled(elt)) {
cleanUpElement(elt)
return
}
Expand Down Expand Up @@ -2635,8 +2648,21 @@ var htmx = (function() {
function findElementsToProcess(elt) {
if (elt.querySelectorAll) {
const boostedSelector = ', [hx-boost] a, [data-hx-boost] a, a[hx-boost], a[data-hx-boost]'

const extensionSelectors = []
for (const e in extensions) {
const extension = extensions[e]
if (extension.getSelectors) {
var selectors = extension.getSelectors()
if (selectors) {
extensionSelectors.push(selectors)
}
}
}

const results = elt.querySelectorAll(VERB_SELECTOR + boostedSelector + ", form, [type='submit']," +
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]')
' [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger]' + extensionSelectors.flat().map(s => ', ' + s).join(''))

return results
} else {
return []
Expand Down Expand Up @@ -2695,7 +2721,7 @@ var htmx = (function() {
}

/**
* @param {EventTarget} elt
* @param {Element} elt
* @param {string} eventName
* @param {string} code
*/
Expand All @@ -2708,6 +2734,9 @@ var htmx = (function() {
/** @type EventListener */
const listener = function(e) {
maybeEval(elt, function() {
if (eltIsDisabled(elt)) {
return
}
if (!func) {
func = new Function('event', code)
}
Expand Down Expand Up @@ -4754,6 +4783,7 @@ var htmx = (function() {
function extensionBase() {
return {
init: function(api) { return null },
getSelectors: function() { return null },
onEvent: function(name, evt) { return true },
transformResponse: function(text, xhr, elt) { return text },
isInlineSwap: function(swapStyle) { return false },
Expand Down Expand Up @@ -4852,8 +4882,9 @@ var htmx = (function() {

function insertIndicatorStyles() {
if (htmx.config.includeIndicatorStyles !== false) {
const nonceAttribute = htmx.config.inlineStyleNonce ? ` nonce="${htmx.config.inlineStyleNonce}"` : ''
getDocument().head.insertAdjacentHTML('beforeend',
'<style>\
'<style' + nonceAttribute + '>\
.' + htmx.config.indicatorClass + '{opacity:0}\
.' + htmx.config.requestClass + ' .' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
.' + htmx.config.requestClass + '.' + htmx.config.indicatorClass + '{opacity:1; transition: opacity 200ms ease-in;}\
Expand Down

0 comments on commit 12675fd

Please sign in to comment.