mirror of
https://github.com/onlyworlds/obsidian-plugin.git
synced 2026-07-22 11:00:31 +00:00
Save Element creates new elements (create-on-404); Upload World renamed with real error surfacing; Rename World pushes; Download World returns (prefixed-key clean) with self-healing Map/Pin/Marker templates; upload parser ships links as _id/_ids UUIDs; per-world key resolution ends the wrong-world write class; scoped keys primary in all copy. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { App, Modal, DropdownComponent, normalizePath, TFolder, TFile } from 'obsidian';
|
|
|
|
export class WorldKeySelectionModal extends Modal {
|
|
onChoose: (worldKey: string, worldFolder: string) => void;
|
|
activeWorldName: string;
|
|
|
|
constructor(app: App, onChoose: (worldKey: string, worldFolder: string) => void, activeWorldName: string) {
|
|
super(app);
|
|
this.onChoose = onChoose;
|
|
this.activeWorldName = activeWorldName;
|
|
}
|
|
|
|
async onOpen() {
|
|
let { contentEl } = this;
|
|
contentEl.createEl('h3', { text: 'Select World and Enter Key' });
|
|
contentEl.addClass('key-selection-modal');
|
|
|
|
const worldFolders = await this.getWorldFolders();
|
|
const dropdown = new DropdownComponent(contentEl);
|
|
dropdown.selectEl.addClass('key-selection-dropdown');
|
|
|
|
worldFolders.forEach(folder => {
|
|
dropdown.addOption(folder, folder);
|
|
});
|
|
if (worldFolders.length > 0) {
|
|
dropdown.setValue(this.activeWorldName || worldFolders[0]);
|
|
}
|
|
|
|
const input = contentEl.createEl('input', {
|
|
type: 'text',
|
|
placeholder: 'ow_ key or 10-digit key',
|
|
cls: 'key-selection-input'
|
|
});
|
|
|
|
const submitButton = contentEl.createEl('button', { text: 'Submit', cls: 'key-selection-submit-button' });
|
|
submitButton.onclick = () => {
|
|
this.close();
|
|
this.onChoose(input.value, dropdown.getValue());
|
|
};
|
|
|
|
input.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
if (e.key === 'Enter') {
|
|
submitButton.click();
|
|
}
|
|
});
|
|
|
|
input.focus();
|
|
}
|
|
|
|
async getWorldFolders(): Promise<string[]> {
|
|
const worldsPath = normalizePath('OnlyWorlds/Worlds/');
|
|
const worldsFolder = this.app.vault.getAbstractFileByPath(worldsPath);
|
|
|
|
if (!(worldsFolder instanceof TFolder)) {
|
|
console.error('Expected worlds folder not found.');
|
|
return [];
|
|
}
|
|
|
|
return worldsFolder.children
|
|
.filter(child => child instanceof TFolder && child.children.some(file => file instanceof TFile && file.name === "World.md"))
|
|
.map(folder => folder.name);
|
|
}
|
|
|
|
onClose() {
|
|
let { contentEl } = this;
|
|
contentEl.empty();
|
|
}
|
|
}
|