Compare commits
No commits in common. "c36e5654ed20c43764a25340de1e727028d7068f" and "0595c98991efe328bc967d1cead376e22dda0154" have entirely different histories.
c36e5654ed
...
0595c98991
|
|
@ -67,16 +67,6 @@
|
||||||
padding-left: 1.5em;
|
padding-left: 1.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.blockquote {
|
|
||||||
display: block;
|
|
||||||
opacity: .5;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-wrap: break-word;
|
|
||||||
border-left: 2px solid currentColor;
|
|
||||||
margin-bottom: .5em;
|
|
||||||
padding-left: .5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hr {
|
.hr {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--hrColor, #555);
|
border-top: 1px solid var(--hrColor, #555);
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,12 @@ export const parseTable = (table: string): string => {
|
||||||
|
|
||||||
export const highlight = (message: string, keepMarkup = true): string => {
|
export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
let resultHTML = '';
|
let resultHTML = '';
|
||||||
const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)/g;
|
const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |\n)/g;
|
||||||
const headerRegex = /#{1,3} $/;
|
const headerRegex = /#{1,3} $/;
|
||||||
const blockquoteRegex = /> $/;
|
|
||||||
const stack: string[] = [];
|
const stack: string[] = [];
|
||||||
let inCodeBlock = false;
|
let inCodeBlock = false;
|
||||||
let inMonospaced = false;
|
let inMonospaced = false;
|
||||||
let inHeader = false;
|
let inHeader = false;
|
||||||
let inBlockquote = false;
|
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match: RegExpExecArray | null;
|
let match: RegExpExecArray | null;
|
||||||
|
|
||||||
|
|
@ -85,7 +83,6 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
const headerMatch = token.match(headerRegex);
|
const headerMatch = token.match(headerRegex);
|
||||||
if (headerMatch) {
|
if (headerMatch) {
|
||||||
if (inHeader) resultHTML += '</span>';
|
if (inHeader) resultHTML += '</span>';
|
||||||
if (inBlockquote) { resultHTML += '</span>'; inBlockquote = false; }
|
|
||||||
const markup = keepMarkup ? headerMatch[0] : '';
|
const markup = keepMarkup ? headerMatch[0] : '';
|
||||||
const len = headerMatch[0].length;
|
const len = headerMatch[0].length;
|
||||||
inHeader = true;
|
inHeader = true;
|
||||||
|
|
@ -93,23 +90,10 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockquoteMatch = token.match(blockquoteRegex);
|
|
||||||
if (blockquoteMatch) {
|
|
||||||
if (inHeader) { resultHTML += '</span>'; inHeader = false; }
|
|
||||||
if (inBlockquote) resultHTML += '</span>';
|
|
||||||
const markup = keepMarkup ? '> ' : '';
|
|
||||||
inBlockquote = true;
|
|
||||||
resultHTML += `${token.slice(0, -2)}<span class="${styles.blockquote}">${markup}`;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token === '\n') {
|
if (token === '\n') {
|
||||||
if (inHeader) {
|
if (inHeader) {
|
||||||
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
||||||
inHeader = false;
|
inHeader = false;
|
||||||
} else if (inBlockquote) {
|
|
||||||
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
|
||||||
inBlockquote = false;
|
|
||||||
} else {
|
} else {
|
||||||
resultHTML += '\n';
|
resultHTML += '\n';
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +126,6 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
resultHTML += message.slice(lastIndex);
|
resultHTML += message.slice(lastIndex);
|
||||||
|
|
||||||
if (inHeader) resultHTML += '</span>';
|
if (inHeader) resultHTML += '</span>';
|
||||||
if (inBlockquote) resultHTML += '</span>';
|
|
||||||
resultHTML += '</span>'.repeat(stack.length);
|
resultHTML += '</span>'.repeat(stack.length);
|
||||||
|
|
||||||
if (!keepMarkup) {
|
if (!keepMarkup) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import Prompt from "../utils/prompt";
|
||||||
import { Tools } from "../utils/tools";
|
import { Tools } from "../utils/tools";
|
||||||
import { Sparkles } from "lucide-preact";
|
import { Sparkles } from "lucide-preact";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { ContentEditable } from "@common/components/ContentEditable";
|
|
||||||
|
|
||||||
// ─── Role Header ──────────────────────────────────────────────────────────────
|
// ─── Role Header ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
@ -351,18 +350,13 @@ export const ChatSidebar = () => {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ContentEditable
|
<textarea
|
||||||
autoLines
|
|
||||||
class={styles.input}
|
class={styles.input}
|
||||||
value={input}
|
value={input}
|
||||||
onInput={setInput}
|
onInput={setInput}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
placeholder={
|
placeholder={isDisabled ? 'Connect to an LLM server to chat' : 'Type a message...'}
|
||||||
isLoading
|
rows={3}
|
||||||
? 'Generating...'
|
|
||||||
: isDisabled
|
|
||||||
? 'Connect to an LLM server to chat'
|
|
||||||
: 'Type a message...'}
|
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { ContentEditable } from "@common/components/ContentEditable";
|
||||||
import { highlight } from "@common/highlight";
|
import { highlight } from "@common/highlight";
|
||||||
import { useAppState, type Tab } from "../contexts/state";
|
import { useAppState, type Tab } from "../contexts/state";
|
||||||
import styles from '../assets/editor.module.css';
|
import styles from '../assets/editor.module.css';
|
||||||
import { useMemo, useRef, useEffect } from "preact/hooks";
|
import { useMemo } from "preact/hooks";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { CharacterEditor } from "./character-editor";
|
import { CharacterEditor } from "./character-editor";
|
||||||
import { LocationEditor } from "./location-editor";
|
import { LocationEditor } from "./location-editor";
|
||||||
|
|
@ -17,8 +17,7 @@ const TABS: { id: Tab; label: string; right?: boolean }[] = [
|
||||||
{ id: "lore", label: "Lore" },
|
{ id: "lore", label: "Lore" },
|
||||||
{ id: "characters", label: "Characters" },
|
{ id: "characters", label: "Characters" },
|
||||||
{ id: "locations", label: "Locations" },
|
{ id: "locations", label: "Locations" },
|
||||||
{ id: "scratchpad", label: "Scratchpad", right: true },
|
{ id: "prompt", label: "Prompt", right: true },
|
||||||
{ id: "prompt", label: "Prompt" },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export const Editor = () => {
|
export const Editor = () => {
|
||||||
|
|
@ -27,12 +26,11 @@ export const Editor = () => {
|
||||||
|
|
||||||
const handleInput = useInputCallback((text: string) => {
|
const handleInput = useInputCallback((text: string) => {
|
||||||
if (!currentStory) return;
|
if (!currentStory) return;
|
||||||
dispatch({ type: 'EDIT_STORY', id: currentStory.id, text });
|
dispatch({
|
||||||
}, [currentStory?.id]);
|
type: 'EDIT_STORY',
|
||||||
|
id: currentStory.id,
|
||||||
const handleScratchpadInput = useInputCallback((text: string) => {
|
text,
|
||||||
if (!currentStory) return;
|
});
|
||||||
dispatch({ type: 'EDIT_STORY', id: currentStory.id, text });
|
|
||||||
}, [currentStory?.id]);
|
}, [currentStory?.id]);
|
||||||
|
|
||||||
const handleTabChange = (tab: Tab) => {
|
const handleTabChange = (tab: Tab) => {
|
||||||
|
|
@ -44,14 +42,6 @@ export const Editor = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const contentRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (contentRef.current) {
|
|
||||||
contentRef.current.scrollTop = contentRef.current.scrollHeight;
|
|
||||||
}
|
|
||||||
}, [currentStory?.currentTab]);
|
|
||||||
|
|
||||||
const storyValue = useMemo(() => currentStory ? highlight(currentStory.text) : '', [currentStory?.text]);
|
const storyValue = useMemo(() => currentStory ? highlight(currentStory.text) : '', [currentStory?.text]);
|
||||||
const promptPreview = useMemo(() => {
|
const promptPreview = useMemo(() => {
|
||||||
if (currentStory?.currentTab !== 'prompt') return '';
|
if (currentStory?.currentTab !== 'prompt') return '';
|
||||||
|
|
@ -68,7 +58,7 @@ export const Editor = () => {
|
||||||
<div class={styles.title}>
|
<div class={styles.title}>
|
||||||
{currentStory.title}
|
{currentStory.title}
|
||||||
</div>
|
</div>
|
||||||
<div class={styles.content} ref={contentRef}>
|
<div class={styles.content}>
|
||||||
{currentStory.currentTab === "story" && (
|
{currentStory.currentTab === "story" && (
|
||||||
<ContentEditable
|
<ContentEditable
|
||||||
class={styles.editable}
|
class={styles.editable}
|
||||||
|
|
@ -89,14 +79,6 @@ export const Editor = () => {
|
||||||
{currentStory.currentTab === "chapters" && (
|
{currentStory.currentTab === "chapters" && (
|
||||||
<ChaptersEditor />
|
<ChaptersEditor />
|
||||||
)}
|
)}
|
||||||
{currentStory.currentTab === "scratchpad" && (
|
|
||||||
<ContentEditable
|
|
||||||
class={styles.editable}
|
|
||||||
value={currentStory.scratchpad ?? ''}
|
|
||||||
onInput={handleScratchpadInput}
|
|
||||||
placeholder="Notes, ideas, outlines — anything you don't want in the story..."
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{currentStory.currentTab === "prompt" && (
|
{currentStory.currentTab === "prompt" && (
|
||||||
<div class={styles.promptPreview} dangerouslySetInnerHTML={{ __html: promptPreview }} />
|
<div class={styles.promptPreview} dangerouslySetInnerHTML={{ __html: promptPreview }} />
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export type ChatMessage = LLM.ChatMessage & {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Tab = "story" | "lore" | "characters" | "locations" | "chapters" | "scratchpad" | "prompt";
|
export type Tab = "story" | "lore" | "characters" | "locations" | "chapters" | "prompt";
|
||||||
|
|
||||||
export enum CharacterRole {
|
export enum CharacterRole {
|
||||||
Protagonist = 'protagonist',
|
Protagonist = 'protagonist',
|
||||||
|
|
@ -67,7 +67,6 @@ export interface Story {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
text: string;
|
text: string;
|
||||||
scratchpad: string;
|
|
||||||
lore: LoreEntry[];
|
lore: LoreEntry[];
|
||||||
characters: Character[];
|
characters: Character[];
|
||||||
locations: Location[];
|
locations: Location[];
|
||||||
|
|
@ -94,7 +93,6 @@ type Action =
|
||||||
| { type: 'CREATE_STORY'; title: string }
|
| { type: 'CREATE_STORY'; title: string }
|
||||||
| { type: 'RENAME_STORY'; id: string; title: string }
|
| { type: 'RENAME_STORY'; id: string; title: string }
|
||||||
| { type: 'EDIT_STORY'; id: string; text: string }
|
| { type: 'EDIT_STORY'; id: string; text: string }
|
||||||
| { type: 'EDIT_SCRATCHPAD'; id: string; text: string }
|
|
||||||
| { type: 'ADD_LORE_ENTRY'; storyId: string; entry: LoreEntry }
|
| { type: 'ADD_LORE_ENTRY'; storyId: string; entry: LoreEntry }
|
||||||
| { type: 'EDIT_LORE_ENTRY'; storyId: string; entryId: string; updates: Partial<LoreEntry> }
|
| { type: 'EDIT_LORE_ENTRY'; storyId: string; entryId: string; updates: Partial<LoreEntry> }
|
||||||
| { type: 'DELETE_LORE_ENTRY'; storyId: string; entryId: string }
|
| { type: 'DELETE_LORE_ENTRY'; storyId: string; entryId: string }
|
||||||
|
|
@ -143,7 +141,6 @@ function reducer(state: IState, action: Action): IState {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
title: action.title,
|
title: action.title,
|
||||||
text: '',
|
text: '',
|
||||||
scratchpad: '',
|
|
||||||
lore: [],
|
lore: [],
|
||||||
characters: [],
|
characters: [],
|
||||||
locations: [],
|
locations: [],
|
||||||
|
|
@ -259,7 +256,6 @@ function reducer(state: IState, action: Action): IState {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
title: `${original.title} (Copy)`,
|
title: `${original.title} (Copy)`,
|
||||||
text: '',
|
text: '',
|
||||||
scratchpad: '',
|
|
||||||
lore: [...original.lore],
|
lore: [...original.lore],
|
||||||
characters: original.characters,
|
characters: original.characters,
|
||||||
locations: original.locations,
|
locations: original.locations,
|
||||||
|
|
@ -487,14 +483,6 @@ function reducer(state: IState, action: Action): IState {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'EDIT_SCRATCHPAD': {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
stories: state.stories.map(s =>
|
|
||||||
s.id === action.id ? { ...s, scratchpad: action.text } : s
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case 'STORE_CHAPTER_SUMMARY': {
|
case 'STORE_CHAPTER_SUMMARY': {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
||||||
|
|
@ -299,10 +299,6 @@ namespace Prompt {
|
||||||
parts.push(locationsSection);
|
parts.push(locationsSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentStory.scratchpad) {
|
|
||||||
parts.push(`## Scratchpad`, currentStory.scratchpad);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentStory.text && storyTokenBudget > 0) {
|
if (currentStory.text && storyTokenBudget > 0) {
|
||||||
const storyText = formatStoryChunks(currentStory.text, currentStory.chapters ?? [], storyTokenBudget);
|
const storyText = formatStoryChunks(currentStory.text, currentStory.chapters ?? [], storyTokenBudget);
|
||||||
if (storyText) {
|
if (storyText) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue