Skip to content

Commit

Permalink
Fix wire:model bug
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed May 23, 2023
1 parent b349098 commit f92126a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 48 deletions.
81 changes: 39 additions & 42 deletions dist/livewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
return this.get(key).forEach(callback);
}
};
function monkeyPatchDomSetAttributeToAllowAtSymbols() {
let original = Element.prototype.setAttribute;
let hostDiv = document.createElement("div");
Element.prototype.setAttribute = function newSetAttribute(name, value) {
if (!name.includes("@")) {
return original.call(this, name, value);
}
hostDiv.innerHTML = `<span ${name}="${value}"></span>`;
let attr = hostDiv.firstElementChild.getAttributeNode(name);
hostDiv.firstElementChild.removeAttributeNode(attr);
this.setAttributeNode(attr);
};
}
function isObjecty(subject) {
return typeof subject === "object" && subject !== null;
}
Expand Down Expand Up @@ -117,8 +104,9 @@
}
var specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
var isBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
var EMPTY_OBJ = false ? Object.freeze({}) : {};
var EMPTY_ARR = false ? Object.freeze([]) : [];
var EMPTY_OBJ = true ? Object.freeze({}) : {};
var EMPTY_ARR = true ? Object.freeze([]) : [];
var extend = Object.assign;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
var isArray2 = Array.isArray;
Expand Down Expand Up @@ -154,6 +142,9 @@
};

// node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
function warn(msg, ...args) {
console.warn(`[Vue warn] ${msg}`, ...args);
}
var createDep = (effects) => {
const dep = new Set(effects);
dep.w = 0;
Expand All @@ -167,8 +158,8 @@
var trackOpBit = 1;
var maxMarkerBits = 30;
var activeEffect;
var ITERATE_KEY = Symbol(false ? "iterate" : "");
var MAP_KEY_ITERATE_KEY = Symbol(false ? "Map key iterate" : "");
var ITERATE_KEY = Symbol(true ? "iterate" : "");
var MAP_KEY_ITERATE_KEY = Symbol(true ? "Map key iterate" : "");
var shouldTrack = true;
var trackStack = [];
function pauseTracking2() {
Expand All @@ -189,7 +180,7 @@
if (!dep) {
depsMap.set(key, dep = createDep());
}
const eventInfo = false ? { effect: activeEffect, target, type, key } : void 0;
const eventInfo = true ? { effect: activeEffect, target, type, key } : void 0;
trackEffects(dep, eventInfo);
}
}
Expand All @@ -206,7 +197,7 @@
if (shouldTrack3) {
dep.add(activeEffect);
activeEffect.deps.push(dep);
if (false) {
if (activeEffect.onTrack) {
activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
}
}
Expand Down Expand Up @@ -256,10 +247,10 @@
break;
}
}
const eventInfo = false ? { target, type, key, newValue, oldValue, oldTarget } : void 0;
const eventInfo = true ? { target, type, key, newValue, oldValue, oldTarget } : void 0;
if (deps.length === 1) {
if (deps[0]) {
if (false) {
if (true) {
triggerEffects(deps[0], eventInfo);
} else {
triggerEffects(deps[0]);
Expand All @@ -272,7 +263,7 @@
effects.push(...dep);
}
}
if (false) {
if (true) {
triggerEffects(createDep(effects), eventInfo);
} else {
triggerEffects(createDep(effects));
Expand All @@ -294,7 +285,7 @@
}
function triggerEffect(effect3, debuggerEventExtraInfo) {
if (effect3 !== activeEffect || effect3.allowRecurse) {
if (false) {
if (effect3.onTrigger) {
effect3.onTrigger(extend({ effect: effect3 }, debuggerEventExtraInfo));
}
if (effect3.scheduler) {
Expand Down Expand Up @@ -428,13 +419,13 @@
var readonlyHandlers = {
get: readonlyGet,
set(target, key) {
if (false) {
if (true) {
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
}
return true;
},
deleteProperty(target, key) {
if (false) {
if (true) {
warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
}
return true;
Expand Down Expand Up @@ -498,7 +489,7 @@
if (!hadKey) {
key = toRaw(key);
hadKey = has3.call(target, key);
} else if (false) {
} else if (true) {
checkIdentityKeys(target, has3, key);
}
const oldValue = get3.call(target, key);
Expand All @@ -517,7 +508,7 @@
if (!hadKey) {
key = toRaw(key);
hadKey = has3.call(target, key);
} else if (false) {
} else if (true) {
checkIdentityKeys(target, has3, key);
}
const oldValue = get3 ? get3.call(target, key) : void 0;
Expand All @@ -530,7 +521,7 @@
function clear2() {
const target = toRaw(this);
const hadItems = target.size !== 0;
const oldTarget = false ? isMap(target) ? new Map(target) : new Set(target) : void 0;
const oldTarget = true ? isMap(target) ? new Map(target) : new Set(target) : void 0;
const result = target.clear();
if (hadItems) {
trigger(target, "clear", void 0, void 0, oldTarget);
Expand Down Expand Up @@ -575,7 +566,7 @@
}
function createReadonlyMethod(type) {
return function(...args) {
if (false) {
if (true) {
const key = args[0] ? `on key "${args[0]}" ` : ``;
console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
}
Expand Down Expand Up @@ -677,6 +668,13 @@
var readonlyCollectionHandlers = {
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
};
function checkIdentityKeys(target, has3, key) {
const rawKey = toRaw(key);
if (rawKey !== key && has3.call(target, rawKey)) {
const type = toRawType(target);
console.warn(`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
}
}
var reactiveMap = /* @__PURE__ */ new WeakMap();
var shallowReactiveMap = /* @__PURE__ */ new WeakMap();
var readonlyMap = /* @__PURE__ */ new WeakMap();
Expand Down Expand Up @@ -709,7 +707,7 @@
}
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
if (!isObject2(target)) {
if (false) {
if (true) {
console.warn(`value cannot be made reactive: ${String(target)}`);
}
return target;
Expand Down Expand Up @@ -1510,12 +1508,12 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
node = node.nextElementSibling;
}
}
function warn(message2, ...args) {
function warn2(message2, ...args) {
console.warn(`Alpine Warning: ${message2}`, ...args);
}
function start() {
if (!document.body)
warn("Unable to initialize. Trying to load Alpine before `<body>` is available. Did you forget to add `defer` in Alpine's `<script>` tag?");
warn2("Unable to initialize. Trying to load Alpine before `<body>` is available. Did you forget to add `defer` in Alpine's `<script>` tag?");
dispatch(document, "alpine:init");
dispatch(document, "alpine:initializing");
startObservingMutations();
Expand Down Expand Up @@ -2752,7 +2750,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
key = toRaw2(key);
hadKey = has22.call(target, key);
} else if (true) {
checkIdentityKeys(target, has22, key);
checkIdentityKeys2(target, has22, key);
}
const oldValue = get3.call(target, key);
target.set(key, value);
Expand All @@ -2771,7 +2769,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
key = toRaw2(key);
hadKey = has22.call(target, key);
} else if (true) {
checkIdentityKeys(target, has22, key);
checkIdentityKeys2(target, has22, key);
}
const oldValue = get3 ? get3.call(target, key) : void 0;
const result = target.delete(key);
Expand Down Expand Up @@ -2927,7 +2925,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
var shallowReadonlyCollectionHandlers = {
get: createInstrumentationGetter2(true, true)
};
function checkIdentityKeys(target, has22, key) {
function checkIdentityKeys2(target, has22, key) {
const rawKey = toRaw2(key);
if (rawKey !== key && has22.call(target, rawKey)) {
const type = toRawType2(target);
Expand Down Expand Up @@ -3058,7 +3056,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
warnMissingPluginMagic("Focus", "focus", "focus");
warnMissingPluginMagic("Persist", "persist", "persist");
function warnMissingPluginMagic(name, magicName, slug) {
magic(magicName, (el) => warn(`You can't use [$${directiveName}] without first installing the "${name}" plugin here: https://alpinejs.dev/plugins/${slug}`, el));
magic(magicName, (el) => warn2(`You can't use [$${directiveName}] without first installing the "${name}" plugin here: https://alpinejs.dev/plugins/${slug}`, el));
}
directive("modelable", (el, { expression }, { effect: effect3, evaluateLater: evaluateLater2, cleanup: cleanup22 }) => {
let func = evaluateLater2(expression);
Expand Down Expand Up @@ -3099,14 +3097,14 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
var teleportContainerDuringClone = document.createElement("div");
directive("teleport", (el, { modifiers, expression }, { cleanup: cleanup22 }) => {
if (el.tagName.toLowerCase() !== "template")
warn("x-teleport can only be used on a <template> tag", el);
warn2("x-teleport can only be used on a <template> tag", el);
let target = skipDuringClone(() => {
return document.querySelector(expression);
}, () => {
return teleportContainerDuringClone;
})();
if (!target)
warn(`Cannot find x-teleport element for selector: "${expression}"`);
warn2(`Cannot find x-teleport element for selector: "${expression}"`);
let clone2 = el.content.cloneNode(true).firstElementChild;
el._x_teleport = clone2;
clone2._x_teleportBack = el;
Expand Down Expand Up @@ -3628,7 +3626,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
initTree(clone2);
});
if (typeof key === "object") {
warn("x-for key cannot be an object, it must be a string or an integer", templateEl);
warn2("x-for key cannot be an object, it must be a string or an integer", templateEl);
}
lookup[key] = clone2;
}
Expand Down Expand Up @@ -3753,7 +3751,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
warnMissingPluginDirective("Focus", "trap", "focus");
warnMissingPluginDirective("Mask", "mask", "mask");
function warnMissingPluginDirective(name, directiveName2, slug) {
directive(directiveName2, (el) => warn(`You can't use [x-${directiveName2}] without first installing the "${name}" plugin here: https://alpinejs.dev/plugins/${slug}`, el));
directive(directiveName2, (el) => warn2(`You can't use [x-${directiveName2}] without first installing the "${name}" plugin here: https://alpinejs.dev/plugins/${slug}`, el));
}
alpine_default.setEvaluator(normalEvaluator);
alpine_default.setReactivityEngine({ reactive: reactive22, effect: effect22, release: stop, raw: toRaw2 });
Expand Down Expand Up @@ -4827,7 +4825,6 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);

// js/lifecycle.js
function start2() {
monkeyPatchDomSetAttributeToAllowAtSymbols();
module_default.plugin(module_default4);
module_default.plugin(module_default3);
module_default.plugin(module_default2);
Expand Down Expand Up @@ -5638,7 +5635,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el);
if (!expression) {
return console.warn("Livewire: [wire:model] is missing a value.", el);
}
if (el.type.toLowerCase() === "file") {
if (el.type && el.type.toLowerCase() === "file") {
return handleFileUpload(el, expression, component, cleanup3);
}
forceUpdateOnDirty(component, el, expression, cleanup3);
Expand Down
Loading

0 comments on commit f92126a

Please sign in to comment.