Skip to content

Commit f87796d

Browse files
committed
Rebuild dist/
1 parent 56caf14 commit f87796d

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ function combineSpacedArray(parts) {
898898
return finalParts;
899899
}
900900

901-
function getDeepData(data, propertyPath) {
901+
function parseDeepData(data, propertyPath) {
902902
const finalData = JSON.parse(JSON.stringify(data));
903903
let currentLevelData = finalData;
904904
const parts = propertyPath.split('.');
@@ -914,7 +914,7 @@ function getDeepData(data, propertyPath) {
914914
};
915915
}
916916
function setDeepData(data, propertyPath, value) {
917-
const { currentLevelData, finalData, finalKey, parts } = getDeepData(data, propertyPath);
917+
const { currentLevelData, finalData, finalKey, parts } = parseDeepData(data, propertyPath);
918918
if (typeof currentLevelData !== 'object') {
919919
const lastPart = parts.pop();
920920
throw new Error(`Cannot set data-model="${propertyPath}". The parent "${parts.join('.')}" data does not appear to be an object (it's "${currentLevelData}"). Did you forget to add exposed={"${lastPart}"} to its LiveProp?`);
@@ -990,6 +990,29 @@ function cloneHTMLElement(element) {
990990
return newElement;
991991
}
992992

993+
function getArrayValue(element, value, currentValue) {
994+
if (!(currentValue instanceof Array)) {
995+
currentValue = [];
996+
}
997+
if (element instanceof HTMLInputElement && element.type === 'checkbox') {
998+
const index = currentValue.indexOf(value);
999+
if (element.checked) {
1000+
if (index === -1) {
1001+
currentValue.push(value);
1002+
}
1003+
}
1004+
else {
1005+
if (index > -1) {
1006+
currentValue.splice(index, 1);
1007+
}
1008+
}
1009+
}
1010+
else if (element instanceof HTMLSelectElement) {
1011+
currentValue = Array.from(element.selectedOptions).map(el => el.value);
1012+
}
1013+
return currentValue.length ? currentValue : null;
1014+
}
1015+
9931016
const DEFAULT_DEBOUNCE = 150;
9941017
class default_1 extends Controller {
9951018
constructor() {
@@ -1094,24 +1117,15 @@ class default_1 extends Controller {
10941117
const clonedElement = cloneHTMLElement(element);
10951118
throw new Error(`The update() method could not be called for "${clonedElement.outerHTML}": the element must either have a "data-model" or "name" attribute set to the model name.`);
10961119
}
1097-
if (element instanceof HTMLInputElement && element.type === 'checkbox' && !element.checked) {
1098-
value = null;
1099-
}
11001120
if (/\[]$/.test(model)) {
1101-
const { currentLevelData, finalKey } = getDeepData(this.dataValue, normalizeModelName(model));
1121+
const { currentLevelData, finalKey } = parseDeepData(this.dataValue, normalizeModelName(model));
11021122
const currentValue = currentLevelData[finalKey];
1103-
if (currentValue instanceof Array) {
1104-
if (null === value) {
1105-
const index = currentValue.indexOf(this._getValueFromElement(element));
1106-
if (index > -1) {
1107-
currentValue.splice(index, 1);
1108-
}
1109-
}
1110-
else {
1111-
currentValue.push(value);
1112-
}
1113-
}
1114-
value = currentValue;
1123+
value = getArrayValue(element, value, currentValue);
1124+
}
1125+
else if (element instanceof HTMLInputElement
1126+
&& element.type === 'checkbox'
1127+
&& !element.checked) {
1128+
value = null;
11151129
}
11161130
this.$updateModel(model, value, shouldRender, element.hasAttribute('name') ? element.getAttribute('name') : null, {});
11171131
}

0 commit comments

Comments
 (0)