Compare commits
15 Commits
d9ee24e7cb
...
ff5c3073dc
| Author | SHA1 | Date | |
|---|---|---|---|
| ff5c3073dc | |||
| c4ad259362 | |||
| 9b634ccc05 | |||
| cb66d08027 | |||
| 98b01098a1 | |||
| 63efadd3fb | |||
| af01951d9a | |||
| 2b4b86816c | |||
| 9232054331 | |||
| c9edc1e266 | |||
| a16a4ef0f9 | |||
| 621c7a3681 | |||
| 4266708e8b | |||
| 57cff46ccd | |||
| 1215ab8fae |
@@ -1,12 +1,13 @@
|
||||
# TextDB
|
||||
|
||||
TextDB is a **non-destructive**, completely offline, local-first text editor with built-in Markdown preview functionality. Its core promise is simple: your edits never overwrite your history. Every manual save is immutable and append-only, and autosaves are kept as a separate draft layer. No accounts, no telemetry, no remote fonts, and no network calls.
|
||||
TextDB is a **non-destructive**, completely offline, local-first text editor with built-in Markdown preview **and local AI conversion**. Its core promise is simple: your edits never overwrite your history. Every manual save is immutable and append-only, and autosaves are kept as a separate draft layer. It can also convert plain text to Markdown using a local Ollama model (recommended: `ministral:3b`). No accounts, no telemetry, no remote fonts, and no outside network calls.
|
||||
|
||||
## Features
|
||||
|
||||
- Non-destructive editing: immutable manual saves + safe autosaved drafts.
|
||||
- Version history panel with quick restore.
|
||||
- Markdown preview mode.
|
||||
- Markdown preview mode with split view.
|
||||
- Convert plain text to Markdown manually or via local Ollama (recommended model: `ministral:3b`).
|
||||
- Sort your texts in nested folders with expandable tree; move items around via right-click.
|
||||
- Open/import `.txt` and `.md` files; export to `.txt` or print / `.pdf`.
|
||||
- Settings for theme, text size, and optional display of line numbers in the textarea.
|
||||
@@ -39,6 +40,8 @@ npm install
|
||||
npm run tauri dev
|
||||
```
|
||||
|
||||
For AI based text-to-markdown conversion, install Ollama: `https://ollama.com`
|
||||
|
||||
## Autosave + versioning behavior
|
||||
|
||||
- Typing triggers a debounced autosave (~600ms) that writes to the draft record.
|
||||
|
||||
210
src/App.tsx
210
src/App.tsx
@@ -94,6 +94,12 @@ type SidebarEntry =
|
||||
|
||||
const DEFAULT_TITLE = "Untitled Text";
|
||||
const DEFAULT_FOLDER_NAME = "New Folder";
|
||||
const DEFAULT_OLLAMA_URL = "http://localhost:11434";
|
||||
const DEFAULT_OLLAMA_PROMPT = `Convert the following plain text into well-formatted Markdown.
|
||||
Do not change or omit any content.
|
||||
Only add Markdown structure (such as headings, lists, code blocks, tables, quotes, links, bold, italics, etc.) where appropriate, based on the meaning and structure of the original text.
|
||||
Keep the content itself unaltered and do not translate, summarize or rephrase. Only use your Markdown-formatting skills.
|
||||
Text:`;
|
||||
|
||||
export default function App() {
|
||||
const [texts, setTexts] = useState<Text[]>([]);
|
||||
@@ -158,6 +164,19 @@ export default function App() {
|
||||
const stored = localStorage.getItem("textdb.splitView");
|
||||
return stored === null ? true : stored === "true";
|
||||
});
|
||||
const [ollamaUrl, setOllamaUrl] = useState(() => {
|
||||
return localStorage.getItem("textdb.ollamaUrl") || DEFAULT_OLLAMA_URL;
|
||||
});
|
||||
const [ollamaModel, setOllamaModel] = useState(() => {
|
||||
return localStorage.getItem("textdb.ollamaModel") || "";
|
||||
});
|
||||
const [ollamaPrompt, setOllamaPrompt] = useState(() => {
|
||||
return localStorage.getItem("textdb.ollamaPrompt") || DEFAULT_OLLAMA_PROMPT;
|
||||
});
|
||||
const [ollamaModels, setOllamaModels] = useState<string[]>([]);
|
||||
const [ollamaLoading, setOllamaLoading] = useState(false);
|
||||
const [ollamaError, setOllamaError] = useState<string | null>(null);
|
||||
const [isConverting, setIsConverting] = useState(false);
|
||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(() => {
|
||||
return localStorage.getItem("textdb.sidebarCollapsed") === "true";
|
||||
});
|
||||
@@ -199,6 +218,18 @@ export default function App() {
|
||||
localStorage.setItem("textdb.splitView", String(splitView));
|
||||
}, [splitView]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem("textdb.ollamaUrl", ollamaUrl);
|
||||
}, [ollamaUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem("textdb.ollamaModel", ollamaModel);
|
||||
}, [ollamaModel]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem("textdb.ollamaPrompt", ollamaPrompt);
|
||||
}, [ollamaPrompt]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(
|
||||
"textdb.expandedFolders",
|
||||
@@ -256,6 +287,10 @@ export default function App() {
|
||||
() => (markdownPreview ? markdownToHTML(body) : ""),
|
||||
[body, markdownPreview]
|
||||
);
|
||||
const normalizedOllamaUrl = useMemo(() => {
|
||||
const trimmed = ollamaUrl.trim();
|
||||
return (trimmed || DEFAULT_OLLAMA_URL).replace(/\/+$/, "");
|
||||
}, [ollamaUrl]);
|
||||
|
||||
const folderById = useMemo(() => {
|
||||
const map = new Map<string, Folder>();
|
||||
@@ -352,6 +387,41 @@ export default function App() {
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!settingsOpen) return;
|
||||
const controller = new AbortController();
|
||||
const loadModels = async () => {
|
||||
setOllamaLoading(true);
|
||||
setOllamaError(null);
|
||||
try {
|
||||
const response = await fetch(`${normalizedOllamaUrl}/api/tags`, {
|
||||
signal: controller.signal
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ollama responded with ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
const models = Array.isArray(data?.models)
|
||||
? data.models.map((model: { name?: string }) => model.name).filter(Boolean)
|
||||
: [];
|
||||
setOllamaModels(models);
|
||||
if (!ollamaModel && models.length > 0) {
|
||||
setOllamaModel(models[0]);
|
||||
}
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) return;
|
||||
setOllamaModels([]);
|
||||
setOllamaError("Unable to reach Ollama.");
|
||||
} finally {
|
||||
if (!controller.signal.aborted) {
|
||||
setOllamaLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
loadModels();
|
||||
return () => controller.abort();
|
||||
}, [normalizedOllamaUrl, settingsOpen]);
|
||||
|
||||
const handlePrintMarkdown = useCallback(() => {
|
||||
if (!markdownPreview) return;
|
||||
document.body.classList.add("print-markdown");
|
||||
@@ -511,6 +581,82 @@ export default function App() {
|
||||
setHistoryItems(combined);
|
||||
}, [historyOpen, selectedTextId]);
|
||||
|
||||
const handleConvertToMarkdown = useCallback(async () => {
|
||||
if (!selectedTextId || !hasText || isViewingHistory || isConverting) return;
|
||||
if (!ollamaModel) {
|
||||
setConfirmState({
|
||||
title: "Ollama",
|
||||
message: "Select an Ollama model first.",
|
||||
actionLabel: "OK",
|
||||
onConfirm: () => {}
|
||||
});
|
||||
return;
|
||||
}
|
||||
const prompt = (ollamaPrompt || DEFAULT_OLLAMA_PROMPT).trim();
|
||||
const fullPrompt = `${prompt}\n${body}`;
|
||||
setIsConverting(true);
|
||||
try {
|
||||
const response = await fetch(`${normalizedOllamaUrl}/api/generate`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
model: ollamaModel,
|
||||
prompt: fullPrompt,
|
||||
stream: false
|
||||
})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ollama responded with ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
const resultText = typeof data?.response === "string" ? data.response : "";
|
||||
if (!resultText) {
|
||||
throw new Error("Ollama returned an empty response.");
|
||||
}
|
||||
const normalizedTitle = title.trim() || DEFAULT_TITLE;
|
||||
const result = await saveManualVersion(
|
||||
selectedTextId,
|
||||
normalizedTitle,
|
||||
resultText
|
||||
);
|
||||
setBody(resultText);
|
||||
setLastPersistedBody(resultText);
|
||||
setLastPersistedTitle(normalizedTitle);
|
||||
setHasDraft(false);
|
||||
setRestoredDraft(false);
|
||||
setLatestManualVersionId(result.versionId);
|
||||
setDraftBaseVersionId(result.versionId);
|
||||
setSelectedHistoryId(result.versionId);
|
||||
setViewingVersion(null);
|
||||
historySnapshotRef.current = null;
|
||||
setMarkdownPreview(true);
|
||||
await refreshTexts();
|
||||
await refreshVersions();
|
||||
} catch (error) {
|
||||
console.error("Failed to convert with Ollama", error);
|
||||
setConfirmState({
|
||||
title: "Ollama error",
|
||||
message: error instanceof Error ? error.message : "Conversion failed.",
|
||||
actionLabel: "OK",
|
||||
onConfirm: () => {}
|
||||
});
|
||||
} finally {
|
||||
setIsConverting(false);
|
||||
}
|
||||
}, [
|
||||
body,
|
||||
hasText,
|
||||
isConverting,
|
||||
isViewingHistory,
|
||||
normalizedOllamaUrl,
|
||||
ollamaModel,
|
||||
ollamaPrompt,
|
||||
refreshTexts,
|
||||
refreshVersions,
|
||||
selectedTextId,
|
||||
title
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshTexts().catch((error) => {
|
||||
console.error("Failed to load texts", error);
|
||||
@@ -1639,6 +1785,14 @@ export default function App() {
|
||||
: "Edit"
|
||||
: "Preview Markdown"}
|
||||
</button>
|
||||
<button
|
||||
className="button"
|
||||
type="button"
|
||||
onClick={handleConvertToMarkdown}
|
||||
disabled={!ollamaModel || isConverting || isViewingHistory}
|
||||
>
|
||||
{isConverting ? "Converting…" : "Convert to Markdown"}
|
||||
</button>
|
||||
<button className="button" onClick={handleExportText}>
|
||||
Export Text
|
||||
</button>
|
||||
@@ -1787,6 +1941,7 @@ export default function App() {
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div className="settings-panel__section-title">Interface</div>
|
||||
<div className="settings-panel__section">
|
||||
<label className="settings-panel__label" htmlFor="theme-select">
|
||||
Theme
|
||||
@@ -1843,6 +1998,61 @@ export default function App() {
|
||||
<div className="settings-panel__value">{textSize}px</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="settings-panel__section-title">Ollama</div>
|
||||
<div className="settings-panel__section">
|
||||
<label className="settings-panel__label" htmlFor="ollama-url">
|
||||
URL
|
||||
</label>
|
||||
<input
|
||||
id="ollama-url"
|
||||
className="settings-panel__input"
|
||||
type="text"
|
||||
value={ollamaUrl}
|
||||
onChange={(event) => setOllamaUrl(event.target.value)}
|
||||
placeholder={DEFAULT_OLLAMA_URL}
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-panel__section">
|
||||
<label className="settings-panel__label" htmlFor="ollama-model">
|
||||
Model
|
||||
</label>
|
||||
<select
|
||||
id="ollama-model"
|
||||
className="settings-panel__select"
|
||||
value={ollamaModel}
|
||||
onChange={(event) => setOllamaModel(event.target.value)}
|
||||
disabled={ollamaLoading}
|
||||
>
|
||||
{ollamaModels.length > 0 ? (
|
||||
ollamaModels.map((model) => (
|
||||
<option key={model} value={model}>
|
||||
{model}
|
||||
</option>
|
||||
))
|
||||
) : ollamaModel ? (
|
||||
<option value={ollamaModel}>{ollamaModel}</option>
|
||||
) : (
|
||||
<option value="">
|
||||
{ollamaLoading ? "Loading models…" : "No models found"}
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
{ollamaError ? (
|
||||
<div className="settings-panel__hint">{ollamaError}</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="settings-panel__section">
|
||||
<label className="settings-panel__label" htmlFor="ollama-prompt">
|
||||
Prompt
|
||||
</label>
|
||||
<textarea
|
||||
id="ollama-prompt"
|
||||
className="settings-panel__textarea"
|
||||
value={ollamaPrompt}
|
||||
onChange={(event) => setOllamaPrompt(event.target.value)}
|
||||
rows={6}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -966,11 +966,34 @@ body:not([data-theme="light"]) .folder-item {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.settings-panel__section-title {
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.settings-panel__label {
|
||||
font-size: 0.9rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.settings-panel__input,
|
||||
.settings-panel__textarea {
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-input);
|
||||
color: var(--ink);
|
||||
padding: 8px 10px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.settings-panel__textarea {
|
||||
resize: vertical;
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.settings-panel__select {
|
||||
border-radius: 10px;
|
||||
border: 1px solid var(--border);
|
||||
@@ -997,6 +1020,11 @@ body:not([data-theme="light"]) .folder-item {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.settings-panel__hint {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
body[data-theme="light"] .editor__textarea-wrap:focus-within {
|
||||
border-color: var(--accent-strong);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user