@dotdrelle/wiki-manager 0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+ import { createEffect, createSignal, Show } from 'solid-js';
3
+
4
+ export type ActiveFileEditor = {
5
+ title: string;
6
+ filePath: string;
7
+ displayPath: string;
8
+ content: string;
9
+ language?: string;
10
+ };
11
+
12
+ export function FileEditorDialog(props: {
13
+ editor: ActiveFileEditor | null;
14
+ width: number;
15
+ height: number;
16
+ onSave: (content: string) => { ok: true } | { ok: false; error: string };
17
+ onCancel: () => void;
18
+ }) {
19
+ let textareaRef: any;
20
+ const [error, setError] = createSignal<string | null>(null);
21
+ const [draftContent, setDraftContent] = createSignal<string | null>(null);
22
+
23
+ createEffect(() => {
24
+ const editor = props.editor;
25
+ setError(null);
26
+ setDraftContent(editor?.content ?? null);
27
+ });
28
+
29
+ const dialogWidth = () => Math.max(52, Math.min(110, Math.floor(props.width * 0.74)));
30
+ const dialogHeight = () => Math.max(16, Math.min(34, Math.floor(props.height * 0.72)));
31
+ const left = () => Math.max(1, Math.floor((props.width - dialogWidth()) / 2));
32
+ const top = () => Math.max(1, Math.floor((props.height - dialogHeight()) / 2));
33
+ const editorHeight = () => Math.max(6, dialogHeight() - 8);
34
+
35
+ const save = () => {
36
+ const content = String(textareaRef?.plainText ?? draftContent() ?? props.editor?.content ?? '');
37
+ const result = props.onSave(content);
38
+ if (result.ok === false) setError(result.error);
39
+ };
40
+
41
+ return (
42
+ <Show when={props.editor}>
43
+ {(editor) => (
44
+ <box
45
+ position="absolute"
46
+ left={left()}
47
+ top={top()}
48
+ width={dialogWidth()}
49
+ height={dialogHeight()}
50
+ zIndex={30}
51
+ border
52
+ borderStyle="rounded"
53
+ borderColor="#5DADE2"
54
+ backgroundColor="#111318"
55
+ padding={1}
56
+ flexDirection="column"
57
+ overflow="hidden"
58
+ >
59
+ <text height={1} fg="#FBBF24">{editor().title}</text>
60
+ <text height={1} fg="#7F8C8D">{editor().displayPath}</text>
61
+ <box
62
+ height={editorHeight()}
63
+ flexDirection="column"
64
+ border
65
+ borderStyle="single"
66
+ borderColor="#4B5563"
67
+ backgroundColor="#0B0D12"
68
+ overflow="hidden"
69
+ >
70
+ <textarea
71
+ ref={textareaRef}
72
+ focused
73
+ height={editorHeight() - 2}
74
+ width={dialogWidth() - 6}
75
+ initialValue={editor().content}
76
+ wrapMode="word"
77
+ keyBindings={[{ name: 's', ctrl: true, action: 'submit' }]}
78
+ onSubmit={save}
79
+ onContentChange={setDraftContent}
80
+ />
81
+ </box>
82
+ <Show when={error()}>
83
+ {(message) => <text height={1} fg="#F87171">{message()}</text>}
84
+ </Show>
85
+ <box height={1} flexDirection="row">
86
+ <text fg="#111318" bg="#8BD5CA"> Save Ctrl+S </text>
87
+ <text fg="#7F8C8D"> </text>
88
+ <text fg="#D6DEE8" bg="#4B5563"> Cancel Esc </text>
89
+ </box>
90
+ </box>
91
+ )}
92
+ </Show>
93
+ );
94
+ }