Merge pull request #545 from paxperscientiam/add-typings

Add typings
This commit is contained in:
1cg 2021-07-06 16:03:18 -06:00 committed by GitHub
commit 3ba3e87709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 2 deletions

14
jsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"noEmit": true,
"checkJs": true,
"jsx": "react",
"strict": false,
"lib": [ "dom" ]
},
"include": [
"./src/htmx.js"
],
"verbose": true
}

6
package-lock.json generated
View File

@ -7239,6 +7239,12 @@
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"dev": true
},
"typescript": {
"version": "4.3.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz",
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==",
"dev": true
},
"ua-parser-js": {
"version": "0.7.28",
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.28.tgz",

View File

@ -19,9 +19,11 @@
"dist/*.js.gz"
],
"main": "dist/htmx.min.js",
"types": "src/htmx.d.ts",
"unpkg": "dist/htmx.min.js",
"scripts": {
"test": "mocha-chrome test/index.html",
"test-types": "tsc --project ./jsconfig.json",
"dist": "cp -r src/* dist/ && npm run-script uglify && gzip -k -f dist/htmx.min.js > dist/htmx.min.js.gz && exit",
"www": "node scripts/www.js",
"uglify": "uglifyjs -m eval -o dist/htmx.min.js dist/htmx.js"
@ -38,8 +40,9 @@
"fs-extra": "^9.1.0",
"mocha": "^7.2.0",
"mocha-chrome": "^2.2.0",
"sass": "^1.34.0",
"sinon": "^9.2.4",
"uglify-js": "^3.13.7",
"sass": "^1.34.0"
"typescript": "^4.3.5",
"uglify-js": "^3.13.7"
}
}

26
src/htmx.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
export interface HtmxApi {
config?: HtmxConfig
logger?: (a: HTMLElement, b: Event, c: any) => void | null
}
export interface HtmxConfig {
historyEnabled?: boolean;
historyCacheSize?: number;
refreshOnHistoryMiss?: boolean;
defaultSwapStyle?: 'innerHTML' | string;
defaultSwapDelay?: number;
defaultSettleDelay?: number;
includeIndicatorStyles?: boolean;
indicatorClass?: 'htmx-indicator' | string;
requestClass?: 'htmx-request' | string;
settlingClass?: 'htmx-settling' | string;
swappingClass?: 'htmx-swapping' | string;
allowEval?: boolean;
attributesToSettle?: ["class", "style", "width", "height"] | string[];
withCredentials?: boolean;
wsReconnectDelay?: 'full-jitter' | string;
disableSelector?: "[hx-disable], [data-hx-disable]" | string;
useTemplateFragments?: boolean;
}
export declare var htmx: HtmxApi

View File

@ -1,7 +1,9 @@
//AMD insanity
(function (root, factory) {
//@ts-ignore
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
//@ts-ignore
define([], factory);
} else {
// Browser globals
@ -150,9 +152,11 @@ return (function () {
var responseNode = responseDoc.body;
while (depth > 0) {
depth--;
// @ts-ignore
responseNode = responseNode.firstChild;
}
if (responseNode == null) {
// @ts-ignore
responseNode = getDocument().createDocumentFragment();
}
return responseNode;
@ -1205,6 +1209,7 @@ return (function () {
function getWebSocketReconnectDelay(retryCount) {
var delay = htmx.config.wsReconnectDelay;
if (typeof delay === 'function') {
// @ts-ignore
return delay(retryCount);
}
if (delay === 'full-jitter') {
@ -1598,9 +1603,11 @@ return (function () {
if (this.status >= 200 && this.status < 400) {
triggerEvent(getDocument().body, "htmx:historyCacheMissLoad", details);
var fragment = makeFragment(this.response);
// @ts-ignore
fragment = fragment.querySelector('[hx-history-elt],[data-hx-history-elt]') || fragment;
var historyElement = getHistoryElement();
var settleInfo = makeSettleInfo(historyElement);
// @ts-ignore
swapInnerHTML(historyElement, fragment, settleInfo)
settleImmediately(settleInfo.tasks);
currentPathForHistory = path;
@ -2369,7 +2376,9 @@ return (function () {
try {
selectionInfo = {
elt: activeElt,
// @ts-ignore
start: activeElt ? activeElt.selectionStart : null,
// @ts-ignore
end: activeElt ? activeElt.selectionEnd : null
};
} catch (e) {
@ -2384,7 +2393,9 @@ return (function () {
selectionInfo.elt.id) {
var newActiveElt = document.getElementById(selectionInfo.elt.id);
if (newActiveElt) {
// @ts-ignore
if (selectionInfo.start && newActiveElt.setSelectionRange) {
// @ts-ignore
newActiveElt.setSelectionRange(selectionInfo.start, selectionInfo.end);
}
newActiveElt.focus();
@ -2536,6 +2547,7 @@ return (function () {
function getMetaConfig() {
var element = getDocument().querySelector('meta[name="htmx-config"]');
if (element) {
// @ts-ignore
return parseJSON(element.content);
} else {
return null;