Use the shared color picker for editable site fields
DC CMS qualification / qualify (push) Successful in 1m43s

This commit is contained in:
DCCONSTRUCTIONS
2026-11-06 10:28:17 +03:00
parent f0949f5e75
commit cf204a73dd
3 changed files with 53 additions and 84 deletions
+9 -59
View File
@@ -4663,7 +4663,7 @@ function renderHeaderBooleanToggle({ block, editableField, head }) {
head.append(label);
}
function renderCollectionScalarField({ block, field, grid }) {
function renderScalarField({ block, field, grid }) {
if (field.kind === "link-mode") {
renderLinkModeField({ block, field, grid });
return;
@@ -4684,7 +4684,8 @@ function renderCollectionScalarField({ block, field, grid }) {
return;
}
const label = document.createElement("label");
const isColor = field.kind === "color";
const label = document.createElement(isColor ? "div" : "label");
const labelRow = document.createElement("span");
const labelText = document.createElement("span");
const kind = document.createElement("span");
@@ -4706,7 +4707,10 @@ function renderCollectionScalarField({ block, field, grid }) {
input.dataset.path = field.path;
input.value = value;
if (!isLong) {
if (isColor) {
input.type = "hidden";
input.dataset.colorField = labelText.textContent;
} else if (!isLong) {
input.type = "text";
input.autocomplete = "off";
}
@@ -4941,7 +4945,7 @@ function renderCollectionField({ block, editableField, grid }) {
if (nestedField.kind === "media") {
renderMediaField({ block, editableField: nestedField, grid: itemGrid });
} else {
renderCollectionScalarField({ block, field: nestedField, grid: itemGrid });
renderScalarField({ block, field: nestedField, grid: itemGrid });
}
}
@@ -4997,61 +5001,7 @@ function renderContentFields(block) {
continue;
}
if (editableField.kind === "link-mode") {
renderLinkModeField({ block, field: editableField, grid });
continue;
}
if (editableField.kind === "boolean") {
renderBooleanField({ block, editableField, grid });
continue;
}
if (editableField.kind === "range") {
renderRangeField({ block, editableField, grid });
continue;
}
if (editableField.kind === "number") {
renderNumberField({ block, editableField, grid });
continue;
}
const label = document.createElement("label");
const labelRow = document.createElement("span");
const labelText = document.createElement("span");
const kind = document.createElement("span");
const path = document.createElement("span");
const value = getByPath(block, editableField.path) ?? "";
const isLong = editableField.kind === "html" || editableField.kind === "textarea";
const input = isLong ? document.createElement("textarea") : document.createElement("input");
label.className = `field-control${isLong ? " wide" : ""}`;
labelRow.className = "field-label-row";
labelText.className = "field-label-text";
labelText.textContent = editableField.label || editableField.path;
kind.className = "field-kind";
kind.textContent = editableField.kind || "text";
path.className = "field-path";
path.textContent = editableField.path;
labelRow.append(labelText, kind);
input.dataset.path = editableField.path;
input.value = value;
if (!isLong) {
input.type = "text";
input.autocomplete = "off";
}
input.addEventListener("input", () => {
const active = activeBlock();
if (!active) return;
syncFieldValue(active, editableField.path, input);
});
label.append(labelRow, input, path);
grid.append(label);
renderScalarField({ block, field: editableField, grid });
}
group.append(head, grid);