Skip to content

Commit

Permalink
alpinejs: Update to v3.13.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Nov 30, 2023
1 parent af8d4a5 commit 9718a23
Show file tree
Hide file tree
Showing 55 changed files with 4,814 additions and 282 deletions.
89 changes: 66 additions & 23 deletions alpinejs/packages/alpinejs/dist/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
directives(el, attrs).forEach((handle) => handle());
});
let outNestedComponents = (el) => !closestRoot(el.parentElement, true);
Array.from(document.querySelectorAll(allSelectors())).filter(outNestedComponents).forEach((el) => {
Array.from(document.querySelectorAll(allSelectors().join(","))).filter(outNestedComponents).forEach((el) => {
initTree(el);
});
dispatch(document, "alpine:initialized");
Expand Down Expand Up @@ -789,6 +789,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
"ref",
"data",
"id",
"anchor",
"bind",
"init",
"for",
Expand Down Expand Up @@ -1061,7 +1062,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
el._x_hidePromise = el._x_transition ? new Promise((resolve, reject) => {
el._x_transition.out(() => {
}, () => resolve(hide));
el._x_transitioning.beforeCancel(() => reject({ isFromCancelledTransition: true }));
el._x_transitioning && el._x_transitioning.beforeCancel(() => reject({ isFromCancelledTransition: true }));
}) : Promise.resolve(hide);
queueMicrotask(() => {
let closest = closestHide(el);
Expand Down Expand Up @@ -1215,11 +1216,12 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
function onlyDuringClone(callback) {
return (...args) => isCloning && callback(...args);
}
var interceptors = [];
function interceptClone(callback) {
interceptors.push(callback);
}
function cloneNode(from, to) {
if (from._x_dataStack) {
to._x_dataStack = from._x_dataStack;
to.setAttribute("data-has-alpine-state", true);
}
interceptors.forEach((i) => i(from, to));
isCloning = true;
dontRegisterReactiveSideEffects(() => {
initTree(to, (el, callback) => {
Expand Down Expand Up @@ -1264,13 +1266,6 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
callback();
overrideEffect(cache);
}
function shouldSkipRegisteringDataDuringClone(el) {
if (!isCloning)
return false;
if (isCloningLegacy)
return true;
return el.hasAttribute("data-has-alpine-state");
}

// packages/alpinejs/src/utils/bind.js
function bind(el, name, value, modifiers = []) {
Expand Down Expand Up @@ -1303,7 +1298,11 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
el.value = value;
}
if (window.fromModel) {
el.checked = checkedAttrLooseCompare(el.value, value);
if (typeof value === "boolean") {
el.checked = safeParseBoolean(el.value) === value;
} else {
el.checked = checkedAttrLooseCompare(el.value, value);
}
}
} else if (el.type === "checkbox") {
if (Number.isInteger(value)) {
Expand Down Expand Up @@ -1372,6 +1371,15 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
function checkedAttrLooseCompare(valueA, valueB) {
return valueA == valueB;
}
function safeParseBoolean(rawValue) {
if ([1, "1", "true", "on", "yes", true].includes(rawValue)) {
return true;
}
if ([0, "0", "false", "off", "no", false].includes(rawValue)) {
return false;
}
return rawValue ? Boolean(rawValue) : null;
}
function isBooleanAttr(attrName) {
const booleanAttributes = [
"disabled",
Expand Down Expand Up @@ -1602,7 +1610,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
get raw() {
return raw;
},
version: "3.13.1",
version: "3.13.3",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand All @@ -1616,6 +1624,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
onlyDuringClone,
addRootSelector,
addInitSelector,
interceptClone,
addScopeToNode,
deferMutations,
mapAttributes,
Expand Down Expand Up @@ -2564,7 +2573,9 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
directive("ignore", handler);

// packages/alpinejs/src/directives/x-effect.js
directive("effect", (el, { expression }, { effect: effect3 }) => effect3(evaluateLater(el, expression)));
directive("effect", skipDuringClone((el, { expression }, { effect: effect3 }) => {
effect3(evaluateLater(el, expression));
}));

// packages/alpinejs/src/utils/on.js
function on(el, event, modifiers, callback) {
Expand Down Expand Up @@ -2806,21 +2817,40 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
return event.detail !== null && event.detail !== void 0 ? event.detail : event.target.value;
else if (el.type === "checkbox") {
if (Array.isArray(currentValue)) {
let newValue = modifiers.includes("number") ? safeParseNumber(event.target.value) : event.target.value;
let newValue = null;
if (modifiers.includes("number")) {
newValue = safeParseNumber(event.target.value);
} else if (modifiers.includes("boolean")) {
newValue = safeParseBoolean(event.target.value);
} else {
newValue = event.target.value;
}
return event.target.checked ? currentValue.concat([newValue]) : currentValue.filter((el2) => !checkedAttrLooseCompare2(el2, newValue));
} else {
return event.target.checked;
}
} else if (el.tagName.toLowerCase() === "select" && el.multiple) {
return modifiers.includes("number") ? Array.from(event.target.selectedOptions).map((option) => {
let rawValue = option.value || option.text;
return safeParseNumber(rawValue);
}) : Array.from(event.target.selectedOptions).map((option) => {
if (modifiers.includes("number")) {
return Array.from(event.target.selectedOptions).map((option) => {
let rawValue = option.value || option.text;
return safeParseNumber(rawValue);
});
} else if (modifiers.includes("boolean")) {
return Array.from(event.target.selectedOptions).map((option) => {
let rawValue = option.value || option.text;
return safeParseBoolean(rawValue);
});
}
return Array.from(event.target.selectedOptions).map((option) => {
return option.value || option.text;
});
} else {
let rawValue = event.target.value;
return modifiers.includes("number") ? safeParseNumber(rawValue) : modifiers.includes("trim") ? rawValue.trim() : rawValue;
if (modifiers.includes("number")) {
return safeParseNumber(event.target.value);
} else if (modifiers.includes("boolean")) {
return safeParseBoolean(event.target.value);
}
return modifiers.includes("trim") ? event.target.value.trim() : event.target.value;
}
});
}
Expand Down Expand Up @@ -2939,6 +2969,19 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
cleanup22();
});
});
interceptClone((from, to) => {
if (from._x_dataStack) {
to._x_dataStack = from._x_dataStack;
to.setAttribute("data-has-alpine-state", true);
}
});
function shouldSkipRegisteringDataDuringClone(el) {
if (!isCloning)
return false;
if (isCloningLegacy)
return true;
return el.hasAttribute("data-has-alpine-state");
}

// packages/alpinejs/src/directives/x-show.js
directive("show", (el, { modifiers, expression }, { effect: effect3 }) => {
Expand Down
Loading

0 comments on commit 9718a23

Please sign in to comment.