From 8d880eda17d6f339555b12f056374de4cd82b9de Mon Sep 17 00:00:00 2001 From: Alexandre Spaeth Date: Tue, 16 Jul 2024 16:35:15 -0700 Subject: [PATCH 1/2] Generate .d.ts file from the esm module (#2733) --- dist/{htmx.d.ts => htmx.esm.d.ts} | 171 ++++++++++++++++-------------- package.json | 4 +- 2 files changed, 92 insertions(+), 83 deletions(-) rename dist/{htmx.d.ts => htmx.esm.d.ts} (78%) diff --git a/dist/htmx.d.ts b/dist/htmx.esm.d.ts similarity index 78% rename from dist/htmx.d.ts rename to dist/htmx.esm.d.ts index 2176ff4b5..41252c4b5 100644 --- a/dist/htmx.d.ts +++ b/dist/htmx.esm.d.ts @@ -1,67 +1,6 @@ -declare namespace htmx { - const onLoad: (callback: (elt: Node) => void) => EventListener; - const process: (elt: string | Element) => void; - const on: (arg1: string | EventTarget, arg2: string | EventListener, arg3?: EventListener) => EventListener; - const off: (arg1: string | EventTarget, arg2: string | EventListener, arg3?: EventListener) => EventListener; - const trigger: (elt: string | EventTarget, eventName: string, detail?: any) => boolean; - const ajax: (verb: HttpVerb, path: string, context: string | Element | HtmxAjaxHelperContext) => Promise; - const find: (eltOrSelector: string | ParentNode, selector?: string) => Element; - const findAll: (eltOrSelector: string | ParentNode, selector?: string) => NodeListOf; - const closest: (elt: string | Element, selector: string) => Element; - function values(elt: Element, type: HttpVerb): any; - const remove: (elt: Node, delay?: number) => void; - const addClass: (elt: string | Element, clazz: string, delay?: number) => void; - const removeClass: (node: string | Node, clazz: string, delay?: number) => void; - 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 removeExtension: (name: string) => void; - const logAll: () => void; - const logNone: () => void; - const logger: any; - namespace config { - const historyEnabled: boolean; - const historyCacheSize: number; - const refreshOnHistoryMiss: boolean; - const defaultSwapStyle: HtmxSwapStyle; - const defaultSwapDelay: number; - const defaultSettleDelay: number; - const includeIndicatorStyles: boolean; - const indicatorClass: string; - const requestClass: string; - const addedClass: string; - const settlingClass: string; - const swappingClass: string; - const allowEval: boolean; - const allowScriptTags: boolean; - const inlineScriptNonce: string; - const inlineStyleNonce: string; - const attributesToSettle: string[]; - const withCredentials: boolean; - const timeout: number; - const wsReconnectDelay: "full-jitter" | ((retryCount: number) => number); - const wsBinaryType: BinaryType; - const disableSelector: string; - const scrollBehavior: 'auto' | 'instant' | 'smooth'; - const defaultFocusScroll: boolean; - const getCacheBusterParam: boolean; - const globalViewTransitions: boolean; - const methodsThatUseUrlParams: (HttpVerb)[]; - const selfRequestsOnly: boolean; - const ignoreTitle: boolean; - const scrollIntoViewOnBoost: boolean; - const triggerSpecsCache: any | null; - const disableInheritance: boolean; - const responseHandling: HtmxResponseHandlingConfig[]; - const allowNestedOobSwaps: boolean; - } - const parseInterval: (str: string) => number; - const _: (str: string) => any; - const version: string; -} -type HttpVerb = 'get' | 'head' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' | 'patch'; -type SwapOptions = { +export default htmx; +export type HttpVerb = 'get' | 'head' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' | 'patch'; +export type SwapOptions = { select?: string; selectOOB?: string; eventInfo?: any; @@ -70,9 +9,9 @@ type SwapOptions = { afterSwapCallback?: swapCallback; afterSettleCallback?: swapCallback; }; -type swapCallback = () => any; -type HtmxSwapStyle = 'innerHTML' | 'outerHTML' | 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'delete' | 'none' | string; -type HtmxSwapSpecification = { +export type swapCallback = () => any; +export type HtmxSwapStyle = 'innerHTML' | 'outerHTML' | 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'delete' | 'none' | string; +export type HtmxSwapSpecification = { swapStyle: HtmxSwapStyle; swapDelay: number; settleDelay: number; @@ -85,10 +24,10 @@ type HtmxSwapSpecification = { showTarget?: string; focusScroll?: boolean; }; -type ConditionalFunction = ((this: Node, evt: Event) => boolean) & { +export type ConditionalFunction = ((this: Node, evt: Event) => boolean) & { source: string; }; -type HtmxTriggerSpecification = { +export type HtmxTriggerSpecification = { trigger: string; pollInterval?: number; eventFilter?: ConditionalFunction; @@ -103,13 +42,13 @@ type HtmxTriggerSpecification = { root?: string; threshold?: string; }; -type HtmxElementValidationError = { +export type HtmxElementValidationError = { elt: Element; message: string; validity: ValidityState; }; -type HtmxHeaderSpecification = Record; -type HtmxAjaxHelperContext = { +export type HtmxHeaderSpecification = Record; +export type HtmxAjaxHelperContext = { source?: Element | string; event?: Event; handler?: HtmxAjaxHandler; @@ -119,7 +58,7 @@ type HtmxAjaxHelperContext = { headers?: Record; select?: string; }; -type HtmxRequestConfig = { +export type HtmxRequestConfig = { boosted: boolean; useUrlParams: boolean; formData: FormData; @@ -141,7 +80,7 @@ type HtmxRequestConfig = { path: string; triggeringEvent: Event; }; -type HtmxResponseInfo = { +export type HtmxResponseInfo = { xhr: XMLHttpRequest; target: Element; requestConfig: HtmxRequestConfig; @@ -157,7 +96,7 @@ type HtmxResponseInfo = { failed?: boolean; successful?: boolean; }; -type HtmxAjaxEtc = { +export type HtmxAjaxEtc = { returnPromise?: boolean; handler?: HtmxAjaxHandler; select?: string; @@ -168,7 +107,7 @@ type HtmxAjaxEtc = { credentials?: boolean; timeout?: number; }; -type HtmxResponseHandlingConfig = { +export type HtmxResponseHandlingConfig = { code?: string; swap: boolean; error?: boolean; @@ -178,18 +117,88 @@ type HtmxResponseHandlingConfig = { swapOverride?: string; event?: string; }; -type HtmxBeforeSwapDetails = HtmxResponseInfo & { +export type HtmxBeforeSwapDetails = HtmxResponseInfo & { shouldSwap: boolean; serverResponse: any; isError: boolean; ignoreTitle: boolean; selectOverride: string; }; -type HtmxAjaxHandler = (elt: Element, responseInfo: HtmxResponseInfo) => any; -type HtmxSettleTask = (() => void); -type HtmxSettleInfo = { +export type HtmxAjaxHandler = (elt: Element, responseInfo: HtmxResponseInfo) => any; +export type HtmxSettleTask = (() => void); +export type HtmxSettleInfo = { tasks: HtmxSettleTask[]; elts: Element[]; title?: string; }; -type HtmxExtension = any; +export 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; +}; +declare namespace htmx { + const onLoad: (callback: (elt: Node) => void) => EventListener; + const process: (elt: string | Element) => void; + const on: (arg1: string | EventTarget, arg2: string | EventListener, arg3?: EventListener) => EventListener; + const off: (arg1: string | EventTarget, arg2: string | EventListener, arg3?: EventListener) => EventListener; + const trigger: (elt: string | EventTarget, eventName: string, detail?: any) => boolean; + const ajax: (verb: HttpVerb, path: string, context: string | Element | HtmxAjaxHelperContext) => Promise; + const find: (eltOrSelector: string | ParentNode, selector?: string) => Element; + const findAll: (eltOrSelector: string | ParentNode, selector?: string) => NodeListOf; + const closest: (elt: string | Element, selector: string) => Element; + function values(elt: Element, type: HttpVerb): any; + const remove: (elt: Node, delay?: number) => void; + const addClass: (elt: string | Element, clazz: string, delay?: number) => void; + const removeClass: (node: string | Node, clazz: string, delay?: number) => void; + 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: HtmxExtension) => void; + const removeExtension: (name: string) => void; + const logAll: () => void; + const logNone: () => void; + const logger: any; + namespace config { + const historyEnabled: boolean; + const historyCacheSize: number; + const refreshOnHistoryMiss: boolean; + const defaultSwapStyle: HtmxSwapStyle; + const defaultSwapDelay: number; + const defaultSettleDelay: number; + const includeIndicatorStyles: boolean; + const indicatorClass: string; + const requestClass: string; + const addedClass: string; + const settlingClass: string; + const swappingClass: string; + const allowEval: boolean; + const allowScriptTags: boolean; + const inlineScriptNonce: string; + const inlineStyleNonce: string; + const attributesToSettle: string[]; + const withCredentials: boolean; + const timeout: number; + const wsReconnectDelay: "full-jitter" | ((retryCount: number) => number); + const wsBinaryType: BinaryType; + const disableSelector: string; + const scrollBehavior: 'auto' | 'instant' | 'smooth'; + const defaultFocusScroll: boolean; + const getCacheBusterParam: boolean; + const globalViewTransitions: boolean; + const methodsThatUseUrlParams: (HttpVerb)[]; + const selfRequestsOnly: boolean; + const ignoreTitle: boolean; + const scrollIntoViewOnBoost: boolean; + const triggerSpecsCache: any | null; + const disableInheritance: boolean; + const responseHandling: HtmxResponseHandlingConfig[]; + const allowNestedOobSwaps: boolean; + } + const parseInterval: (str: string) => number; + const _: (str: string) => any; + const version: string; +} diff --git a/package.json b/package.json index 60c2a9645..0998b3e08 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "editors/jetbrains/htmx.web-types.json" ], "main": "dist/htmx.esm.js", - "types": "dist/htmx.d.ts", + "types": "dist/htmx.esm.d.ts", "unpkg": "dist/htmx.min.js", "web-types": "editors/jetbrains/htmx.web-types.json", "scripts": { @@ -29,7 +29,7 @@ "lint": "eslint src/htmx.js test/attributes/ test/core/ test/util/", "format": "eslint --fix src/htmx.js test/attributes/ test/core/ test/util/", "types-check": "tsc src/htmx.js --noEmit --checkJs --target es6 --lib dom,dom.iterable", - "types-generate": "tsc src/htmx.js --declaration --emitDeclarationOnly --allowJs --outDir dist", + "types-generate": "tsc dist/htmx.esm.js --declaration --emitDeclarationOnly --allowJs --outDir dist", "test": "npm run lint && npm run types-check && mocha-chrome test/index.html", "type-declarations": "tsc --project ./jsconfig.json", "ws-tests": "cd ./test/ws-sse && node ./server.js", From 6910d7136ef013f728ad43d05239ddc32e434934 Mon Sep 17 00:00:00 2001 From: Alexandre Spaeth Date: Mon, 29 Jul 2024 09:02:39 -0700 Subject: [PATCH 2/2] Fix types annotation filename in package.json (#2734) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0998b3e08..0a18fbfb9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "files": [ "LICENSE", "README.md", - "dist/htmx.d.ts", + "dist/htmx.esm.d.ts", "dist/*.js", "dist/ext/*.js", "dist/*.js.gz",