24 lines
858 B
JavaScript
24 lines
858 B
JavaScript
// Generated, do not edit. sha256:b5a4abd8ddb07f0a2874418e2afd4b67b87a2f07cb6b67fe7d38692911fdc843
|
|||
|
|
export function seedValues(columns, row, newDefaults) {
|
||
|
|
const v = {};
|
||
|
|
for (const c of columns) {
|
||
|
|
if (!c.edit) continue;
|
||
|
|
v[c.key] = c.edit.value ? c.edit.value(row) : (row ? row[c.key] : undefined);
|
||
|
|
}
|
||
|
|
if (!row && newDefaults) Object.assign(v, newDefaults);
|
||
|
|
return v;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function normalizeOptions(list) {
|
||
|
|
return (list || []).map(x => ((typeof x === 'object') ? x : { value: x, label: x }));
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function loadOptions(columns, vals, cache) {
|
||
|
|
cache.clear();
|
||
|
|
for (const col of columns) {
|
||
|
|
if (!col.edit || col.edit.options === undefined) continue;
|
||
|
|
const o = typeof col.edit.options === 'function' ? await col.edit.options(vals) : col.edit.options;
|
||
|
|
cache.set(col.key, normalizeOptions(o));
|
||
|
|
}
|
||
|
|
return cache;
|
||
|
|
}
|