Skip to content

Commit

Permalink
feat: update cash
Browse files Browse the repository at this point in the history
  • Loading branch information
nlemoine committed Jul 25, 2023
1 parent 61e3b8f commit 1b8914c
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 34 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on:
push:
branches:
- main

name: CI

jobs:
release-js-package:
uses: Humanoidfr/humanoid-github-workflows/.github/workflows/release-js-package.yml@main
secrets:
READ_PACKAGES_TOKEN: ${{ secrets.READ_PACKAGES_TOKEN }}
WRITE_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}
@humanoidfr:registry=https://npm.pkg.github.com
33 changes: 26 additions & 7 deletions dist/cash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ const classRe = /^\.(?:[\w-]|\\.|[^\x00-\xa0])*$/;
const htmlRe = /<.+>/;
const tagRe = /^\w+$/;
// @require ./variables.ts
const input = {
':input': 'input, textarea, select, button',
':button': 'button',
};
function find(selector, context) {
const isFragment = isDocumentFragment(context);
return !selector || (!isFragment && !isDocument(context) && !isElement(context))
// const isFragment = isDocumentFragment ( context );
return !selector || (!isDocument(context) && !isElement(context))
? []
: !isFragment && classRe.test(selector)
? context.getElementsByClassName(selector.slice(1).replace(/\\/g, ''))
: !isFragment && tagRe.test(selector)
: classRe.test(selector)
? context.getElementsByClassName(selector.slice(1))
: tagRe.test(selector)
? context.getElementsByTagName(selector)
: context.querySelectorAll(selector);
: input[selector]
? context.querySelectorAll(input[selector])
: context.querySelectorAll(selector.replace(/(\[[^=]+=)([^"\]]+)(])/, '$1"$2"$3')); // add quote around attr value
}
// @require ./find.ts
// @require ./variables.ts
Expand Down Expand Up @@ -305,6 +311,12 @@ function isHidden(ele) {
// @require ./cash.ts
function matches(ele, selector) {
const matches = ele && (ele['matches'] || ele['webkitMatchesSelector'] || ele['msMatchesSelector']);
if (selector === ':visible') {
return !!(ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length);
}
else if (selector === ':hidden') {
return !(ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length);
}
return !!matches && !!selector && matches.call(ele, selector);
}
// @require ./matches.ts
Expand Down Expand Up @@ -927,6 +939,7 @@ fn.trigger = function (event, data) {
event.___ot = nameOriginal;
}
event.___td = data;
event.___array = Array.isArray(data);
const isEventFocus = (event.___ot in eventsFocus);
return this.each((i, ele) => {
if (isEventFocus && isFunction(ele[event.___ot])) {
Expand Down Expand Up @@ -1085,7 +1098,13 @@ function on(eventFullName, selector, data, callback, _one) {
return data;
}
});
const returnValue = callback.call(thisArg, event, event.___td);
let returnValue = null;
if (Array.isArray(event.___td) && event.___array) {
returnValue = callback.call(thisArg, event, ...event.___td);
}
else {
returnValue = callback.call(thisArg, event, event.___td);
}
if (_one) {
removeEvent(ele, name, namespaces, selector, finalCallback);
}
Expand Down
42 changes: 35 additions & 7 deletions dist/cash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
(function(){
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var doc = document;
var win = window;
var docEle = doc.documentElement;
Expand All @@ -15,15 +24,21 @@ var classRe = /^\.(?:[\w-]|\\.|[^\x00-\xa0])*$/;
var htmlRe = /<.+>/;
var tagRe = /^\w+$/;
// @require ./variables.ts
var input = {
':input': 'input, textarea, select, button',
':button': 'button',
};
function find(selector, context) {
var isFragment = isDocumentFragment(context);
return !selector || (!isFragment && !isDocument(context) && !isElement(context))
// const isFragment = isDocumentFragment ( context );
return !selector || (!isDocument(context) && !isElement(context))
? []
: !isFragment && classRe.test(selector)
? context.getElementsByClassName(selector.slice(1).replace(/\\/g, ''))
: !isFragment && tagRe.test(selector)
: classRe.test(selector)
? context.getElementsByClassName(selector.slice(1))
: tagRe.test(selector)
? context.getElementsByTagName(selector)
: context.querySelectorAll(selector);
: input[selector]
? context.querySelectorAll(input[selector])
: context.querySelectorAll(selector.replace(/(\[[^=]+=)([^"\]]+)(])/, '$1"$2"$3')); // add quote around attr value
}
// @require ./find.ts
// @require ./variables.ts
Expand Down Expand Up @@ -312,6 +327,12 @@ function isHidden(ele) {
// @require ./cash.ts
function matches(ele, selector) {
var matches = ele && (ele['matches'] || ele['webkitMatchesSelector'] || ele['msMatchesSelector']);
if (selector === ':visible') {
return !!(ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length);
}
else if (selector === ':hidden') {
return !(ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length);
}
return !!matches && !!selector && matches.call(ele, selector);
}
// @require ./matches.ts
Expand Down Expand Up @@ -936,6 +957,7 @@ fn.trigger = function (event, data) {
event.___ot = nameOriginal;
}
event.___td = data;
event.___array = Array.isArray(data);
var isEventFocus = (event.___ot in eventsFocus);
return this.each(function (i, ele) {
if (isEventFocus && isFunction(ele[event.___ot])) {
Expand Down Expand Up @@ -1097,7 +1119,13 @@ function on(eventFullName, selector, data, callback, _one) {
return data;
}
});
var returnValue = callback.call(thisArg, event, event.___td);
var returnValue = null;
if (Array.isArray(event.___td) && event.___array) {
returnValue = callback.call.apply(callback, __spreadArray([thisArg, event], event.___td, false));
}
else {
returnValue = callback.call(thisArg, event, event.___td);
}
if (_one) {
removeEvent(ele, name, namespaces, selector, finalCallback);
}
Expand Down
4 changes: 2 additions & 2 deletions dist/cash.min.js

Large diffs are not rendered by default.

34 changes: 27 additions & 7 deletions dist/cash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,24 @@ const tagRe = /^\w+$/;

// @require ./variables.ts

const input = {
':input': 'input, textarea, select, button',
':button': 'button',
};

function find ( selector: string, context: Ele ): ArrayLike<Element> {

const isFragment = isDocumentFragment ( context );
// const isFragment = isDocumentFragment ( context );

return !selector || ( !isFragment && !isDocument ( context ) && !isElement ( context ) )
return !selector || ( !isDocument ( context ) && !isElement ( context ) )
? []
: !isFragment && classRe.test ( selector )
? context.getElementsByClassName ( selector.slice ( 1 ).replace ( /\\/g, '' ) )
: !isFragment && tagRe.test ( selector )
: classRe.test ( selector )
? context.getElementsByClassName ( selector.slice ( 1 ) )
: tagRe.test ( selector )
? context.getElementsByTagName ( selector )
: context.querySelectorAll ( selector );
: input[selector]
? context.querySelectorAll(input[selector])
: context.querySelectorAll ( selector.replace(/(\[[^=]+=)([^"\]]+)(])/, '$1"$2"$3') ); // add quote around attr value

}

Expand Down Expand Up @@ -733,6 +740,12 @@ function matches ( ele: any, selector: string ): boolean {

const matches = ele && ( ele['matches'] || ele['webkitMatchesSelector'] || ele['msMatchesSelector'] );

if (selector === ':visible') {
return !!( ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length );
} else if (selector === ':hidden') {
return !( ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length );
}

return !!matches && !!selector && matches.call ( ele, selector );

}
Expand Down Expand Up @@ -2375,6 +2388,7 @@ fn.trigger = function ( this: Cash, event: Event | string, data?: any ) {
}

event.___td = data;
event.___array = Array.isArray(data);

const isEventFocus = ( event.___ot in eventsFocus );

Expand Down Expand Up @@ -2713,7 +2727,13 @@ function on ( this: Cash, eventFullName: Record<string, EventCallback> | string,
}
});

const returnValue = callback.call ( thisArg, event, event.___td );
let returnValue = null;

if (Array.isArray(event.___td) && event.___array) {
returnValue = callback.call ( thisArg, event, ...event.___td );
} else {
returnValue = callback.call ( thisArg, event, event.___td );
}

if ( _one ) {

Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "cash-dom",
"repository": "github:fabiospampinato/cash",
"name": "@humanoidfr/cash-dom",
"description": "An absurdly small jQuery alternative for modern browsers.",
"version": "8.1.5",
"license": "MIT",
Expand All @@ -12,6 +11,14 @@
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Humanoidfr/cash.git"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/",
"scope": "@humanoidfr"
},
"scripts": {
"build": "bash ./tasks/build.sh",
"watch": "monex --watch src --exec npm:build",
Expand All @@ -25,8 +32,7 @@
"test:jquery:reverse:build": "cat ./node_modules/jquery/dist/jquery.js ./dist/cash.min.js ./test/jquery_reverse_patch.js > ./dist/cash.js",
"test:jquery:reverse:build:watch": "while sleep 1; do npm run test:jquery:reverse:build; done",
"test:playwright": "node ./test/playwright.mjs",
"graph": "minipacco graph src/export_esm.ts",
"prepublishOnly": "npm run build && npm run test:playwright"
"graph": "minipacco graph src/export_esm.ts"
},
"devDependencies": {
"esbuild": "^0.17.10",
Expand Down
19 changes: 13 additions & 6 deletions src/core/find.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@

// @require ./variables.ts

const input = {
':input': 'input, textarea, select, button',
':button': 'button',
};

function find ( selector: string, context: Ele ): ArrayLike<Element> {

const isFragment = isDocumentFragment ( context );
// const isFragment = isDocumentFragment ( context );

return !selector || ( !isFragment && !isDocument ( context ) && !isElement ( context ) )
return !selector || ( !isDocument ( context ) && !isElement ( context ) )
? []
: !isFragment && classRe.test ( selector )
? context.getElementsByClassName ( selector.slice ( 1 ).replace ( /\\/g, '' ) )
: !isFragment && tagRe.test ( selector )
: classRe.test ( selector )
? context.getElementsByClassName ( selector.slice ( 1 ) )
: tagRe.test ( selector )
? context.getElementsByTagName ( selector )
: context.querySelectorAll ( selector );
: input[selector]
? context.querySelectorAll(input[selector])
: context.querySelectorAll ( selector.replace(/(\[[^=]+=)([^"\]]+)(])/, '$1"$2"$3') ); // add quote around attr value

}
6 changes: 6 additions & 0 deletions src/core/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ function matches ( ele: any, selector: string ): boolean {

const matches = ele && ( ele['matches'] || ele['webkitMatchesSelector'] || ele['msMatchesSelector'] );

if (selector === ':visible') {
return !!( ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length );
} else if (selector === ':hidden') {
return !( ele.offsetWidth || ele.offsetHeight || ele.getClientRects().length );
}

return !!matches && !!selector && matches.call ( ele, selector );

}
8 changes: 7 additions & 1 deletion src/events/on.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ function on ( this: Cash, eventFullName: Record<string, EventCallback> | string,
}
});

const returnValue = callback.call ( thisArg, event, event.___td );
let returnValue = null;

if (Array.isArray(event.___td) && event.___array) {
returnValue = callback.call ( thisArg, event, ...event.___td );
} else {
returnValue = callback.call ( thisArg, event, event.___td );
}

if ( _one ) {

Expand Down
1 change: 1 addition & 0 deletions src/events/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn.trigger = function ( this: Cash, event: Event | string, data?: any ) {
}

event.___td = data;
event.___array = Array.isArray(data);

const isEventFocus = ( event.___ot in eventsFocus );

Expand Down

0 comments on commit 1b8914c

Please sign in to comment.