Add first iteration of the Image DB editor

This commit is contained in:
Oliver 2026-01-18 23:34:24 -07:00
parent 773c506570
commit c7c02702d7
13 changed files with 425 additions and 7 deletions

View file

@ -0,0 +1,6 @@
import { options } from "./options.mjs";
export default {
// MARK: Complex
"tb-options": options,
};

View file

@ -0,0 +1,43 @@
/**
* @typedef {object} Option
* @property {string} [label]
* @property {string|number} value
* @property {boolean} [disabled]
*/
/**
* @param {string | number | Array<string | number>} selected
* @param {Array<Option | string>} opts
* @param {any} meta
*/
export function options(selected, opts, meta) {
const chosen = new Set();
if (!Array.isArray(selected)) {
selected = new Set([selected]);
chosen.add(selected);
} else {
selected.forEach(opt => chosen.add(opt));
};
const { localize = false } = meta.hash;
selected = Handlebars.escapeExpression(selected);
const htmlOptions = [];
for (let opt of opts) {
if (typeof opt === `string`) {
opt = { label: opt, value: opt };
};
opt.value = Handlebars.escapeExpression(opt.value);
htmlOptions.push(
`<option
value="${opt.value}"
${chosen.has(opt.value) ? `selected` : ``}
${opt.disabled ? `disabled` : ``}
>
${localize ? _loc(opt.label) : opt.label}
</option>`,
);
};
return new Handlebars.SafeString(htmlOptions.join(`\n`));
};