Skip to content

Commit

Permalink
Add wire:target.except modifier functionality (#8065)
Browse files Browse the repository at this point in the history
Co-authored-by: Caleb Porzio <calebporzio@gmail.com>
  • Loading branch information
patriktoth67 and calebporzio committed Mar 12, 2024
1 parent 67c66a0 commit 54722b4
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 224 deletions.
33 changes: 22 additions & 11 deletions dist/livewire.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,17 +1485,27 @@ var require_module_cjs = __commonJS({
}) {
deferHandlingDirectives(() => {
walker(el, (el2, skip) => {
if (el2._x_inited) {
if (el2._x_ignore)
skip();
return;
}
intercept(el2, skip);
initInterceptors.forEach((i) => i(el2, skip));
directives(el2, el2.attributes).forEach((handle) => handle());
el2._x_ignore && skip();
if (el2._x_ignore) {
skip();
} else {
el2._x_inited = true;
}
});
});
}
function destroyTree(root, walker = walk) {
walker(root, (el) => {
cleanupAttributes(el);
cleanupElement(el);
delete el._x_inited;
});
}
var onAttributeAddeds = [];
Expand Down Expand Up @@ -1638,8 +1648,6 @@ var require_module_cjs = __commonJS({
node._x_ignore = true;
});
for (let node of addedNodes) {
if (removedNodes.has(node))
continue;
if (!node.isConnected)
continue;
delete node._x_ignoreSelf;
Expand Down Expand Up @@ -1687,15 +1695,15 @@ var require_module_cjs = __commonJS({
has({ objects }, name) {
if (name == Symbol.unscopables)
return false;
return objects.some((obj) => Object.prototype.hasOwnProperty.call(obj, name) || Reflect.has(obj, name));
return objects.some((obj) => Reflect.has(obj, name));
},
get({ objects }, name, thisProxy) {
if (name == "toJSON")
return collapseProxies;
return Reflect.get(objects.find((obj) => Reflect.has(obj, name)) || {}, name, thisProxy);
},
set({ objects }, name, value, thisProxy) {
const target = objects.find((obj) => Object.prototype.hasOwnProperty.call(obj, name)) || objects[objects.length - 1];
const target = objects.find((obj) => Reflect.has(obj, name)) || objects[objects.length - 1];
const descriptor = Object.getOwnPropertyDescriptor(target, name);
if ((descriptor == null ? void 0 : descriptor.set) && (descriptor == null ? void 0 : descriptor.get))
return Reflect.set(target, name, value, thisProxy);
Expand Down Expand Up @@ -2840,7 +2848,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
get raw() {
return raw;
},
version: "3.13.7",
version: "3.13.6",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand Down Expand Up @@ -10043,9 +10051,9 @@ directive("offline", ({ el, directive: directive2, cleanup: cleanup2 }) => {

// js/directives/wire-loading.js
directive("loading", ({ el, directive: directive2, component }) => {
let targets = getTargets(el);
let { targets, inverted } = getTargets(el);
let [delay, abortDelay] = applyDelay(directive2);
whenTargetsArePartOfRequest(component, targets, [
whenTargetsArePartOfRequest(component, targets, inverted, [
() => delay(() => toggleBooleanStateDirective(el, directive2, true)),
() => abortDelay(() => toggleBooleanStateDirective(el, directive2, false))
]);
Expand Down Expand Up @@ -10092,11 +10100,11 @@ function applyDelay(directive2) {
}
];
}
function whenTargetsArePartOfRequest(component, targets, [startLoading, endLoading]) {
function whenTargetsArePartOfRequest(component, targets, inverted, [startLoading, endLoading]) {
on("commit", ({ component: iComponent, commit: payload, respond }) => {
if (iComponent !== component)
return;
if (targets.length > 0 && !containsTargets(payload, targets))
if (targets.length > 0 && containsTargets(payload, targets) === inverted)
return;
startLoading();
respond(() => {
Expand Down Expand Up @@ -10154,9 +10162,12 @@ function containsTargets(payload, targets) {
function getTargets(el) {
let directives = getDirectives(el);
let targets = [];
let inverted = false;
if (directives.has("target")) {
let directive2 = directives.get("target");
let raw = directive2.expression;
if (directive2.modifiers.includes("except"))
inverted = true;
if (raw.includes("(") && raw.includes(")")) {
targets.push({ target: directive2.method, params: quickHash(JSON.stringify(directive2.params)) });
} else if (raw.includes(",")) {
Expand All @@ -10170,7 +10181,7 @@ function getTargets(el) {
let nonActionOrModelLivewireDirectives = ["init", "dirty", "offline", "target", "loading", "poll", "ignore", "key", "id"];
directives.all().filter((i) => !nonActionOrModelLivewireDirectives.includes(i.value)).map((i) => i.expression.split("(")[0]).forEach((target) => targets.push({ target }));
}
return targets;
return { targets, inverted };
}
function quickHash(subject) {
return btoa(encodeURIComponent(subject));
Expand Down
33 changes: 22 additions & 11 deletions dist/livewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,17 +867,27 @@
}) {
deferHandlingDirectives(() => {
walker(el, (el2, skip) => {
if (el2._x_inited) {
if (el2._x_ignore)
skip();
return;
}
intercept(el2, skip);
initInterceptors.forEach((i) => i(el2, skip));
directives(el2, el2.attributes).forEach((handle) => handle());
el2._x_ignore && skip();
if (el2._x_ignore) {
skip();
} else {
el2._x_inited = true;
}
});
});
}
function destroyTree(root, walker = walk) {
walker(root, (el) => {
cleanupAttributes(el);
cleanupElement(el);
delete el._x_inited;
});
}
var onAttributeAddeds = [];
Expand Down Expand Up @@ -1020,8 +1030,6 @@
node._x_ignore = true;
});
for (let node of addedNodes) {
if (removedNodes.has(node))
continue;
if (!node.isConnected)
continue;
delete node._x_ignoreSelf;
Expand Down Expand Up @@ -1069,15 +1077,15 @@
has({ objects }, name) {
if (name == Symbol.unscopables)
return false;
return objects.some((obj) => Object.prototype.hasOwnProperty.call(obj, name) || Reflect.has(obj, name));
return objects.some((obj) => Reflect.has(obj, name));
},
get({ objects }, name, thisProxy) {
if (name == "toJSON")
return collapseProxies;
return Reflect.get(objects.find((obj) => Reflect.has(obj, name)) || {}, name, thisProxy);
},
set({ objects }, name, value, thisProxy) {
const target = objects.find((obj) => Object.prototype.hasOwnProperty.call(obj, name)) || objects[objects.length - 1];
const target = objects.find((obj) => Reflect.has(obj, name)) || objects[objects.length - 1];
const descriptor = Object.getOwnPropertyDescriptor(target, name);
if (descriptor?.set && descriptor?.get)
return Reflect.set(target, name, value, thisProxy);
Expand Down Expand Up @@ -2222,7 +2230,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
get raw() {
return raw;
},
version: "3.13.7",
version: "3.13.6",
flushAndStopDeferringMutations,
dontAutoEvaluateFunctions,
disableEffectScheduling,
Expand Down Expand Up @@ -9172,9 +9180,9 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);

// js/directives/wire-loading.js
directive2("loading", ({ el, directive: directive3, component }) => {
let targets = getTargets(el);
let { targets, inverted } = getTargets(el);
let [delay3, abortDelay] = applyDelay(directive3);
whenTargetsArePartOfRequest(component, targets, [
whenTargetsArePartOfRequest(component, targets, inverted, [
() => delay3(() => toggleBooleanStateDirective(el, directive3, true)),
() => abortDelay(() => toggleBooleanStateDirective(el, directive3, false))
]);
Expand Down Expand Up @@ -9221,11 +9229,11 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
}
];
}
function whenTargetsArePartOfRequest(component, targets, [startLoading, endLoading]) {
function whenTargetsArePartOfRequest(component, targets, inverted, [startLoading, endLoading]) {
on2("commit", ({ component: iComponent, commit: payload, respond }) => {
if (iComponent !== component)
return;
if (targets.length > 0 && !containsTargets(payload, targets))
if (targets.length > 0 && containsTargets(payload, targets) === inverted)
return;
startLoading();
respond(() => {
Expand Down Expand Up @@ -9283,9 +9291,12 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
function getTargets(el) {
let directives2 = getDirectives(el);
let targets = [];
let inverted = false;
if (directives2.has("target")) {
let directive3 = directives2.get("target");
let raw2 = directive3.expression;
if (directive3.modifiers.includes("except"))
inverted = true;
if (raw2.includes("(") && raw2.includes(")")) {
targets.push({ target: directive3.method, params: quickHash(JSON.stringify(directive3.params)) });
} else if (raw2.includes(",")) {
Expand All @@ -9299,7 +9310,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
let nonActionOrModelLivewireDirectives = ["init", "dirty", "offline", "target", "loading", "poll", "ignore", "key", "id"];
directives2.all().filter((i) => !nonActionOrModelLivewireDirectives.includes(i.value)).map((i) => i.expression.split("(")[0]).forEach((target) => targets.push({ target }));
}
return targets;
return { targets, inverted };
}
function quickHash(subject) {
return btoa(encodeURIComponent(subject));
Expand Down
12 changes: 6 additions & 6 deletions dist/livewire.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/livewire.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

{"/livewire.js":"b43a9abd"}
{"/livewire.js":"d76a01eb"}
Loading

0 comments on commit 54722b4

Please sign in to comment.