Use the shared color picker for editable site fields
DC CMS qualification / qualify (push) Successful in 1m43s
DC CMS qualification / qualify (push) Successful in 1m43s
This commit is contained in:
+24
-24
File diff suppressed because one or more lines are too long
+9
-59
@@ -4663,7 +4663,7 @@ function renderHeaderBooleanToggle({ block, editableField, head }) {
|
|||||||
head.append(label);
|
head.append(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderCollectionScalarField({ block, field, grid }) {
|
function renderScalarField({ block, field, grid }) {
|
||||||
if (field.kind === "link-mode") {
|
if (field.kind === "link-mode") {
|
||||||
renderLinkModeField({ block, field, grid });
|
renderLinkModeField({ block, field, grid });
|
||||||
return;
|
return;
|
||||||
@@ -4684,7 +4684,8 @@ function renderCollectionScalarField({ block, field, grid }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = document.createElement("label");
|
const isColor = field.kind === "color";
|
||||||
|
const label = document.createElement(isColor ? "div" : "label");
|
||||||
const labelRow = document.createElement("span");
|
const labelRow = document.createElement("span");
|
||||||
const labelText = document.createElement("span");
|
const labelText = document.createElement("span");
|
||||||
const kind = document.createElement("span");
|
const kind = document.createElement("span");
|
||||||
@@ -4706,7 +4707,10 @@ function renderCollectionScalarField({ block, field, grid }) {
|
|||||||
input.dataset.path = field.path;
|
input.dataset.path = field.path;
|
||||||
input.value = value;
|
input.value = value;
|
||||||
|
|
||||||
if (!isLong) {
|
if (isColor) {
|
||||||
|
input.type = "hidden";
|
||||||
|
input.dataset.colorField = labelText.textContent;
|
||||||
|
} else if (!isLong) {
|
||||||
input.type = "text";
|
input.type = "text";
|
||||||
input.autocomplete = "off";
|
input.autocomplete = "off";
|
||||||
}
|
}
|
||||||
@@ -4941,7 +4945,7 @@ function renderCollectionField({ block, editableField, grid }) {
|
|||||||
if (nestedField.kind === "media") {
|
if (nestedField.kind === "media") {
|
||||||
renderMediaField({ block, editableField: nestedField, grid: itemGrid });
|
renderMediaField({ block, editableField: nestedField, grid: itemGrid });
|
||||||
} else {
|
} else {
|
||||||
renderCollectionScalarField({ block, field: nestedField, grid: itemGrid });
|
renderScalarField({ block, field: nestedField, grid: itemGrid });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4997,61 +5001,7 @@ function renderContentFields(block) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editableField.kind === "link-mode") {
|
renderScalarField({ block, field: editableField, grid });
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group.append(head, grid);
|
group.append(head, grid);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { flushSync } from "react-dom";
|
import { flushSync } from "react-dom";
|
||||||
import { Select, Switch, RangeControl, ProgressBar, Dropdown, IconButton, Icon, StatusBadge } from "@nodedc/ui-react";
|
import { Select, Switch, ColorField, RangeControl, ProgressBar, Dropdown, IconButton, Icon, StatusBadge } from "@nodedc/ui-react";
|
||||||
import { installPreferences } from "./preferences.mjs";
|
import { installPreferences } from "./preferences.mjs";
|
||||||
import { createApplicationWorkspaceController, createModalController } from "@nodedc/ui-dom";
|
import { createApplicationWorkspaceController, createModalController } from "@nodedc/ui-dom";
|
||||||
const h = React.createElement, $ = (s, r = document) => r.querySelector(s), all = (s, r = document) => [...r.querySelectorAll(s)];
|
const h = React.createElement, $ = (s, r = document) => r.querySelector(s), all = (s, r = document) => [...r.querySelectorAll(s)];
|
||||||
@@ -100,6 +100,24 @@ function ranges() {
|
|||||||
} })));
|
} })));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function colors() {
|
||||||
|
for (const input of all("input[data-color-field]")) {
|
||||||
|
const item = island(input);
|
||||||
|
const label = input.dataset.colorField;
|
||||||
|
const signature = JSON.stringify([label, input.value]);
|
||||||
|
if (item.signature === signature) continue;
|
||||||
|
item.signature = signature;
|
||||||
|
flushSync(() => item.root.render(h(ColorField, {
|
||||||
|
label,
|
||||||
|
value: input.value,
|
||||||
|
onChange: value => {
|
||||||
|
input.value = value;
|
||||||
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||||
|
schedule();
|
||||||
|
},
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
||||||
function progress() {
|
function progress() {
|
||||||
for (const track of all(".publish-progress-track")) {
|
for (const track of all(".publish-progress-track")) {
|
||||||
const item = island(track), value = Number(track.getAttribute("aria-valuenow") || 0);
|
const item = island(track), value = Number(track.getAttribute("aria-valuenow") || 0);
|
||||||
@@ -368,6 +386,7 @@ function refresh() {
|
|||||||
switches();
|
switches();
|
||||||
selects();
|
selects();
|
||||||
ranges();
|
ranges();
|
||||||
|
colors();
|
||||||
progress();
|
progress();
|
||||||
buttons();
|
buttons();
|
||||||
navItems();
|
navItems();
|
||||||
|
|||||||
Reference in New Issue
Block a user