Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing for defineExtension should allow partials #3028

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions dist/htmx.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ var htmx = (function() {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
path = getRawAttribute(elt, 'action')
if (verb === 'get' && path.includes('?')) {
if (verb === 'get' && path && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
Expand Down Expand Up @@ -3906,9 +3906,9 @@ var htmx = (function() {
})
} else {
let resolvedTarget = resolveTarget(context.target)
// If target is supplied but can't resolve OR both target and source can't be resolved
// If target is supplied but can't resolve OR source is supplied but both target and source can't be resolved
// then use DUMMY_ELT to abort the request with htmx:targetError to avoid it replacing body by mistake
if ((context.target && !resolvedTarget) || (!resolvedTarget && !resolveTarget(context.source))) {
if ((context.target && !resolvedTarget) || (context.source && !resolvedTarget && !resolveTarget(context.source))) {
resolvedTarget = DUMMY_ELT
}
return issueAjaxRequest(verb, path, resolveTarget(context.source), context.event,
Expand Down Expand Up @@ -4040,7 +4040,15 @@ var htmx = (function() {
get: function(target, name) {
if (typeof name === 'symbol') {
// Forward symbol calls to the FormData itself directly
return Reflect.get(target, name)
const result = Reflect.get(target, name)
// Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error
if (typeof result === 'function') {
return function() {
return result.apply(formData, arguments)
}
} else {
return result
}
}
if (name === 'toJSON') {
// Support JSON.stringify call on proxy
Expand Down Expand Up @@ -4874,7 +4882,7 @@ var htmx = (function() {
* @see https://htmx.org/api/#defineExtension
*
* @param {string} name the extension name
* @param {HtmxExtension} extension the extension definition
* @param {Partial<HtmxExtension>} extension the extension definition
*/
function defineExtension(name, extension) {
if (extension.init) {
Expand Down
18 changes: 13 additions & 5 deletions dist/htmx.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ var htmx = (function() {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
path = getRawAttribute(elt, 'action')
if (verb === 'get' && path.includes('?')) {
if (verb === 'get' && path && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
Expand Down Expand Up @@ -3905,9 +3905,9 @@ var htmx = (function() {
})
} else {
let resolvedTarget = resolveTarget(context.target)
// If target is supplied but can't resolve OR both target and source can't be resolved
// If target is supplied but can't resolve OR source is supplied but both target and source can't be resolved
// then use DUMMY_ELT to abort the request with htmx:targetError to avoid it replacing body by mistake
if ((context.target && !resolvedTarget) || (!resolvedTarget && !resolveTarget(context.source))) {
if ((context.target && !resolvedTarget) || (context.source && !resolvedTarget && !resolveTarget(context.source))) {
resolvedTarget = DUMMY_ELT
}
return issueAjaxRequest(verb, path, resolveTarget(context.source), context.event,
Expand Down Expand Up @@ -4039,7 +4039,15 @@ var htmx = (function() {
get: function(target, name) {
if (typeof name === 'symbol') {
// Forward symbol calls to the FormData itself directly
return Reflect.get(target, name)
const result = Reflect.get(target, name)
// Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error
if (typeof result === 'function') {
return function() {
return result.apply(formData, arguments)
}
} else {
return result
}
}
if (name === 'toJSON') {
// Support JSON.stringify call on proxy
Expand Down Expand Up @@ -4873,7 +4881,7 @@ var htmx = (function() {
* @see https://htmx.org/api/#defineExtension
*
* @param {string} name the extension name
* @param {HtmxExtension} extension the extension definition
* @param {Partial<HtmxExtension>} extension the extension definition
*/
function defineExtension(name, extension) {
if (extension.init) {
Expand Down
2 changes: 1 addition & 1 deletion dist/htmx.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ declare namespace htmx {
let toggleClass: (elt: Element | string, clazz: string) => void;
let takeClass: (elt: Node | string, clazz: string) => void;
let swap: (target: string | Element, content: string, swapSpec: HtmxSwapSpecification, swapOptions?: SwapOptions) => void;
let defineExtension: (name: string, extension: HtmxExtension) => void;
let defineExtension: (name: string, extension: Partial<HtmxExtension>) => void;
let removeExtension: (name: string) => void;
let logAll: () => void;
let logNone: () => void;
Expand Down
18 changes: 13 additions & 5 deletions dist/htmx.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ var htmx = (function() {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
path = getRawAttribute(elt, 'action')
if (verb === 'get' && path.includes('?')) {
if (verb === 'get' && path && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
Expand Down Expand Up @@ -3905,9 +3905,9 @@ var htmx = (function() {
})
} else {
let resolvedTarget = resolveTarget(context.target)
// If target is supplied but can't resolve OR both target and source can't be resolved
// If target is supplied but can't resolve OR source is supplied but both target and source can't be resolved
// then use DUMMY_ELT to abort the request with htmx:targetError to avoid it replacing body by mistake
if ((context.target && !resolvedTarget) || (!resolvedTarget && !resolveTarget(context.source))) {
if ((context.target && !resolvedTarget) || (context.source && !resolvedTarget && !resolveTarget(context.source))) {
resolvedTarget = DUMMY_ELT
}
return issueAjaxRequest(verb, path, resolveTarget(context.source), context.event,
Expand Down Expand Up @@ -4039,7 +4039,15 @@ var htmx = (function() {
get: function(target, name) {
if (typeof name === 'symbol') {
// Forward symbol calls to the FormData itself directly
return Reflect.get(target, name)
const result = Reflect.get(target, name)
// Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error
if (typeof result === 'function') {
return function() {
return result.apply(formData, arguments)
}
} else {
return result
}
}
if (name === 'toJSON') {
// Support JSON.stringify call on proxy
Expand Down Expand Up @@ -4873,7 +4881,7 @@ var htmx = (function() {
* @see https://htmx.org/api/#defineExtension
*
* @param {string} name the extension name
* @param {HtmxExtension} extension the extension definition
* @param {Partial<HtmxExtension>} extension the extension definition
*/
function defineExtension(name, extension) {
if (extension.init) {
Expand Down
18 changes: 13 additions & 5 deletions dist/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ var htmx = (function() {
const rawAttribute = getRawAttribute(elt, 'method')
verb = (/** @type HttpVerb */(rawAttribute ? rawAttribute.toLowerCase() : 'get'))
path = getRawAttribute(elt, 'action')
if (verb === 'get' && path.includes('?')) {
if (verb === 'get' && path && path.includes('?')) {
path = path.replace(/\?[^#]+/, '')
}
}
Expand Down Expand Up @@ -3905,9 +3905,9 @@ var htmx = (function() {
})
} else {
let resolvedTarget = resolveTarget(context.target)
// If target is supplied but can't resolve OR both target and source can't be resolved
// If target is supplied but can't resolve OR source is supplied but both target and source can't be resolved
// then use DUMMY_ELT to abort the request with htmx:targetError to avoid it replacing body by mistake
if ((context.target && !resolvedTarget) || (!resolvedTarget && !resolveTarget(context.source))) {
if ((context.target && !resolvedTarget) || (context.source && !resolvedTarget && !resolveTarget(context.source))) {
resolvedTarget = DUMMY_ELT
}
return issueAjaxRequest(verb, path, resolveTarget(context.source), context.event,
Expand Down Expand Up @@ -4039,7 +4039,15 @@ var htmx = (function() {
get: function(target, name) {
if (typeof name === 'symbol') {
// Forward symbol calls to the FormData itself directly
return Reflect.get(target, name)
const result = Reflect.get(target, name)
// Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error
if (typeof result === 'function') {
return function() {
return result.apply(formData, arguments)
}
} else {
return result
}
}
if (name === 'toJSON') {
// Support JSON.stringify call on proxy
Expand Down Expand Up @@ -4873,7 +4881,7 @@ var htmx = (function() {
* @see https://htmx.org/api/#defineExtension
*
* @param {string} name the extension name
* @param {HtmxExtension} extension the extension definition
* @param {Partial<HtmxExtension>} extension the extension definition
*/
function defineExtension(name, extension) {
if (extension.init) {
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.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -4881,7 +4881,7 @@ var htmx = (function() {
* @see https://htmx.org/api/#defineExtension
*
* @param {string} name the extension name
* @param {HtmxExtension} extension the extension definition
* @param {Partial<HtmxExtension>} extension the extension definition
*/
function defineExtension(name, extension) {
if (extension.init) {
Expand Down