2026-04-29 14:41:24 +00:00
|
|
|
import { TextComponent } from 'obsidian';
|
2025-12-04 23:43:35 +00:00
|
|
|
|
|
|
|
|
export function setupArrayTextSetting(
|
|
|
|
|
text: TextComponent,
|
|
|
|
|
initialArray: string[],
|
2026-04-29 14:41:24 +00:00
|
|
|
onChange: (array: string[]) => Promise<void>,
|
2025-12-04 23:43:35 +00:00
|
|
|
) {
|
2026-04-29 14:41:24 +00:00
|
|
|
text.setValue(initialArray.join(', ')).onChange(async (value) => {
|
|
|
|
|
const array = value
|
|
|
|
|
.split(',')
|
|
|
|
|
.map((field) => field.trim())
|
|
|
|
|
.filter((field) => field.length > 0);
|
2025-12-04 23:43:35 +00:00
|
|
|
|
2026-04-29 14:41:24 +00:00
|
|
|
await onChange(array);
|
|
|
|
|
});
|
2025-12-04 23:43:35 +00:00
|
|
|
|
2026-04-29 14:41:24 +00:00
|
|
|
text.inputEl.addEventListener('blur', () => {
|
2025-12-04 23:43:35 +00:00
|
|
|
const currentValue = text.inputEl.value;
|
|
|
|
|
const cleaned = currentValue
|
2026-04-29 14:41:24 +00:00
|
|
|
.split(',')
|
|
|
|
|
.map((field) => field.trim())
|
|
|
|
|
.filter((field) => field.length > 0)
|
|
|
|
|
.join(', ');
|
2025-12-04 23:43:35 +00:00
|
|
|
|
|
|
|
|
if (currentValue !== cleaned) {
|
|
|
|
|
text.setValue(cleaned);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|