Skip to content

Commit

Permalink
Update AlpineJS version and enhance event handling
Browse files Browse the repository at this point in the history
Updated the AlpineJS library version from 3.13.10 to 3.14.0. Enhanced the event handling in the `cdn.js` file to include click events, and added a new function `isClickEvent(event)` to check if an event is a click event. Updated the `isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)` function to include additional modifiers in the exclusion list and to return `false` if the event type is a click event. Also, updated the promise resolution in the `hideAfterChildren` function to use optional chaining.
  • Loading branch information
marcominerva committed May 22, 2024
1 parent 0ad565d commit 564e71d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion samples/DatabaseGpt.Web/libman.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"destination": "wwwroot/lib/jquery"
},
{
"library": "alpinejs@3.13.10",
"library": "alpinejs@3.14.0",
"destination": "wwwroot/lib/alpinejs"
},
{
Expand Down
21 changes: 13 additions & 8 deletions samples/DatabaseGpt.Web/wwwroot/lib/alpinejs/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
let carry = Promise.all([
el2._x_hidePromise,
...(el2._x_hideChildren || []).map(hideAfterChildren)
]).then(([i]) => i());
]).then(([i]) => i?.());
delete el2._x_hidePromise;
delete el2._x_hideChildren;
return carry;
Expand Down Expand Up @@ -1642,7 +1642,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
get raw() {
return raw;
},
version: "3.13.10",
version: "3.14.0",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand Down Expand Up @@ -2684,14 +2684,14 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
handler4 = wrapHandler(handler4, (next, e) => {
e.target === el && next(e);
});
handler4 = wrapHandler(handler4, (next, e) => {
if (isKeyEvent(event)) {
if (isKeyEvent(event) || isClickEvent(event)) {
handler4 = wrapHandler(handler4, (next, e) => {
if (isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)) {
return;
}
}
next(e);
});
next(e);
});
}
listenerTarget.addEventListener(event, handler4, options);
return () => {
listenerTarget.removeEventListener(event, handler4, options);
Expand All @@ -2716,9 +2716,12 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
function isKeyEvent(event) {
return ["keydown", "keyup"].includes(event);
}
function isClickEvent(event) {
return ["contextmenu", "click", "mouse"].some((i) => event.includes(i));
}
function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
let keyModifiers = modifiers.filter((i) => {
return !["window", "document", "prevent", "stop", "once", "capture"].includes(i);
return !["window", "document", "prevent", "stop", "once", "capture", "self", "away", "outside", "passive"].includes(i);
});
if (keyModifiers.includes("debounce")) {
let debounceIndex = keyModifiers.indexOf("debounce");
Expand All @@ -2742,6 +2745,8 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return e[`${modifier}Key`];
});
if (activelyPressedKeyModifiers.length === selectedSystemKeyModifiers.length) {
if (isClickEvent(e.type))
return false;
if (keyToModifiers(e.key).includes(keyModifiers[0]))
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions samples/DatabaseGpt.Web/wwwroot/lib/alpinejs/cdn.min.js

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions samples/DatabaseGpt.Web/wwwroot/lib/alpinejs/module.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ window.Element.prototype._x_toggleAndCascadeWithTransitions = function(el, value
let carry = Promise.all([
el2._x_hidePromise,
...(el2._x_hideChildren || []).map(hideAfterChildren)
]).then(([i]) => i());
]).then(([i]) => i == null ? void 0 : i());
delete el2._x_hidePromise;
delete el2._x_hideChildren;
return carry;
Expand Down Expand Up @@ -3055,7 +3055,7 @@ var Alpine = {
get raw() {
return raw;
},
version: "3.13.10",
version: "3.14.0",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand Down Expand Up @@ -3392,14 +3392,14 @@ function on(el, event, modifiers, callback) {
handler4 = wrapHandler(handler4, (next, e) => {
e.target === el && next(e);
});
handler4 = wrapHandler(handler4, (next, e) => {
if (isKeyEvent(event)) {
if (isKeyEvent(event) || isClickEvent(event)) {
handler4 = wrapHandler(handler4, (next, e) => {
if (isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)) {
return;
}
}
next(e);
});
next(e);
});
}
listenerTarget.addEventListener(event, handler4, options);
return () => {
listenerTarget.removeEventListener(event, handler4, options);
Expand All @@ -3424,9 +3424,12 @@ function kebabCase2(subject) {
function isKeyEvent(event) {
return ["keydown", "keyup"].includes(event);
}
function isClickEvent(event) {
return ["contextmenu", "click", "mouse"].some((i) => event.includes(i));
}
function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
let keyModifiers = modifiers.filter((i) => {
return !["window", "document", "prevent", "stop", "once", "capture"].includes(i);
return !["window", "document", "prevent", "stop", "once", "capture", "self", "away", "outside", "passive"].includes(i);
});
if (keyModifiers.includes("debounce")) {
let debounceIndex = keyModifiers.indexOf("debounce");
Expand All @@ -3450,6 +3453,8 @@ function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
return e[`${modifier}Key`];
});
if (activelyPressedKeyModifiers.length === selectedSystemKeyModifiers.length) {
if (isClickEvent(e.type))
return false;
if (keyToModifiers(e.key).includes(keyModifiers[0]))
return false;
}
Expand Down

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions samples/DatabaseGpt.Web/wwwroot/lib/alpinejs/module.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ window.Element.prototype._x_toggleAndCascadeWithTransitions = function(el, value
let carry = Promise.all([
el2._x_hidePromise,
...(el2._x_hideChildren || []).map(hideAfterChildren)
]).then(([i]) => i());
]).then(([i]) => i?.());
delete el2._x_hidePromise;
delete el2._x_hideChildren;
return carry;
Expand Down Expand Up @@ -1641,7 +1641,7 @@ var Alpine = {
get raw() {
return raw;
},
version: "3.13.10",
version: "3.14.0",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand Down Expand Up @@ -2683,14 +2683,14 @@ function on(el, event, modifiers, callback) {
handler4 = wrapHandler(handler4, (next, e) => {
e.target === el && next(e);
});
handler4 = wrapHandler(handler4, (next, e) => {
if (isKeyEvent(event)) {
if (isKeyEvent(event) || isClickEvent(event)) {
handler4 = wrapHandler(handler4, (next, e) => {
if (isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)) {
return;
}
}
next(e);
});
next(e);
});
}
listenerTarget.addEventListener(event, handler4, options);
return () => {
listenerTarget.removeEventListener(event, handler4, options);
Expand All @@ -2715,9 +2715,12 @@ function kebabCase2(subject) {
function isKeyEvent(event) {
return ["keydown", "keyup"].includes(event);
}
function isClickEvent(event) {
return ["contextmenu", "click", "mouse"].some((i) => event.includes(i));
}
function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
let keyModifiers = modifiers.filter((i) => {
return !["window", "document", "prevent", "stop", "once", "capture"].includes(i);
return !["window", "document", "prevent", "stop", "once", "capture", "self", "away", "outside", "passive"].includes(i);
});
if (keyModifiers.includes("debounce")) {
let debounceIndex = keyModifiers.indexOf("debounce");
Expand All @@ -2741,6 +2744,8 @@ function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
return e[`${modifier}Key`];
});
if (activelyPressedKeyModifiers.length === selectedSystemKeyModifiers.length) {
if (isClickEvent(e.type))
return false;
if (keyToModifiers(e.key).includes(keyModifiers[0]))
return false;
}
Expand Down

Large diffs are not rendered by default.

0 comments on commit 564e71d

Please sign in to comment.