mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-01 23:11:12 +00:00
fix: type definitions for HtmxExtension (#2721)
This commit is contained in:
parent
c8418332de
commit
cbb2b46de2
12
src/htmx.d.ts
vendored
12
src/htmx.d.ts
vendored
@ -15,7 +15,7 @@ declare namespace htmx {
|
||||
const toggleClass: (elt: string | Element, clazz: string) => void;
|
||||
const takeClass: (elt: string | Node, clazz: string) => void;
|
||||
const swap: (target: string | Element, content: string, swapSpec: HtmxSwapSpecification, swapOptions?: SwapOptions) => void;
|
||||
const defineExtension: (name: string, extension: any) => void;
|
||||
const defineExtension: (name: string, extension: HtmxExtension) => void;
|
||||
const removeExtension: (name: string) => void;
|
||||
const logAll: () => void;
|
||||
const logNone: () => void;
|
||||
@ -192,4 +192,12 @@ type HtmxSettleInfo = {
|
||||
elts: Element[];
|
||||
title?: string;
|
||||
};
|
||||
type HtmxExtension = any;
|
||||
type HtmxExtension = {
|
||||
init: (api: any) => void;
|
||||
onEvent: (name: string, event: Event | CustomEvent) => boolean;
|
||||
transformResponse: (text: string, xhr: XMLHttpRequest, elt: Element) => string;
|
||||
isInlineSwap: (swapStyle: HtmxSwapStyle) => boolean;
|
||||
handleSwap: (swapStyle: HtmxSwapStyle, target: Node, fragment: Node, settleInfo: HtmxSettleInfo) => boolean | Node[];
|
||||
encodeParameters: (xhr: XMLHttpRequest, parameters: FormData, elt: Node) => any | string | null;
|
||||
getSelectors: () => string[] | null;
|
||||
};
|
||||
|
@ -1753,7 +1753,7 @@ var htmx = (function() {
|
||||
try {
|
||||
const newElements = ext.handleSwap(swapStyle, target, fragment, settleInfo)
|
||||
if (newElements) {
|
||||
if (typeof newElements.length !== 'undefined') {
|
||||
if (Array.isArray(newElements)) {
|
||||
// if handleSwap returns an array (like) of elements, we handle them
|
||||
for (let j = 0; j < newElements.length; j++) {
|
||||
const child = newElements[j]
|
||||
@ -5121,12 +5121,13 @@ var htmx = (function() {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see https://github.com/bigskysoftware/htmx-extensions/blob/main/README.md
|
||||
* @typedef {Object} HtmxExtension
|
||||
* @see https://htmx.org/extensions/#defining
|
||||
* @property {(api: any) => void} init
|
||||
* @property {(name: string, event: Event|CustomEvent) => boolean} onEvent
|
||||
* @property {(text: string, xhr: XMLHttpRequest, elt: Element) => string} transformResponse
|
||||
* @property {(swapStyle: HtmxSwapStyle) => boolean} isInlineSwap
|
||||
* @property {(swapStyle: HtmxSwapStyle, target: Element, fragment: Node, settleInfo: HtmxSettleInfo) => boolean} handleSwap
|
||||
* @property {(xhr: XMLHttpRequest, parameters: FormData, elt: Element) => *|string|null} encodeParameters
|
||||
* @property {(swapStyle: HtmxSwapStyle, target: Node, fragment: Node, settleInfo: HtmxSettleInfo) => boolean|Node[]} handleSwap
|
||||
* @property {(xhr: XMLHttpRequest, parameters: FormData, elt: Node) => *|string|null} encodeParameters
|
||||
* @property {() => string[]|null} getSelectors
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user