Skip to content

Commit

Permalink
add typings
Browse files Browse the repository at this point in the history
removed undesired comments. we are only documenting public API

testing

bump

optional

optionals

done

removed two junk files

moved dependency to dev dependency
  • Loading branch information
paxperscientiam committed Jul 6, 2021
1 parent 9837c96 commit cdd5c9e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
14 changes: 14 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"noEmit": true,
"checkJs": true,
"jsx": "react",
"strict": false,
"lib": [ "dom" ]
},
"include": [
"./src/htmx.js"
],
"verbose": true
}
6 changes: 6 additions & 0 deletions package-lock.json

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

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 changes: 26 additions & 0 deletions src/htmx.d.ts
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions src/htmx.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions tsconfig.json

This file was deleted.

0 comments on commit cdd5c9e

Please sign in to comment.