-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPATCH.html
More file actions
281 lines (244 loc) · 11.8 KB
/
Copy pathPATCH.html
File metadata and controls
281 lines (244 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!--
╔══════════════════════════════════════════════════════════════════════╗
║ Markdown Studio — index.html PATCH GUIDE ║
║ Apply these changes to your existing index.html ║
╚══════════════════════════════════════════════════════════════════════╝
CHANGE 1 ── In <head>, REPLACE the existing <script src="…/vue…"> tag
and the marked/hljs/mermaid/katex <script> tags with:
─────────────────────────────────────────────────────────────────────
-->
<!-- ① Vue 3 (keep as-is) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.4.21/vue.global.prod.min.js"></script>
<!-- ② marked (keep as-is) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.0/marked.min.js"></script>
<!-- ③ highlight.js (keep as-is) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" id="hljs-theme"/>
<!-- ④ mermaid (keep as-is) -->
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<!-- ⑤ KaTeX (keep as-is) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
<!-- ⑥ NEW: DOMPurify for safe HTML rendering -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.1.6/purify.min.js"></script>
<!-- ⑦ NEW: CodeMirror 6 bundle — YOU provide this file.
Place your built bundle at: scripts/vendor/codemirror-bundle.js
It must expose window.CM = { EditorView, EditorState, Compartment,
keymap, lineNumbers, history, historyKeymap, defaultKeymap,
indentOnInput, bracketMatching, closeBrackets, closeBracketsKeymap,
syntaxHighlighting, defaultHighlightStyle, markdown, oneDark,
undo, redo }
Until the bundle exists the editor falls back to a plain textarea.
-->
<script src="scripts/vendor/codemirror-bundle.js" onerror="console.warn('[editor] CM bundle not found, using textarea fallback')"></script>
<!--
CHANGE 2 ── REPLACE the old inline <script> at the bottom that mounted Vue
with the new module-type tag:
OLD (remove this):
<script src="scripts/script.js"></script>
NEW (replace with):
-->
<script type="module" src="scripts/script.js"></script>
<!--
CHANGE 3 ── In #editor-wrap, REMOVE the <textarea id="editor-textarea" …>
The CM6 adapter / fallback will inject itself into #editor-wrap.
OLD (inside #editor-wrap div):
<textarea
id="editor-textarea"
ref="editorRef"
v-model="currentContent"
:style="{whiteSpace:wordWrap?'pre-wrap':'pre',fontSize:editorFontSize+'px',lineHeight:editorLineHeight}"
@keydown="onEditorKeydown"
@input="onInput"
spellcheck="false"
placeholder="# Start writing…"
></textarea>
NEW (replace with — editor.js will append CM6/textarea inside this div):
(leave #editor-wrap div empty, or add a loading indicator)
-->
<div
id="editor-wrap"
v-show="activePanel==='editor'"
@contextmenu.prevent="openEditorCtx"
ref="editorWrap"
></div>
<!--
CHANGE 4 ── ADD the Settings button to the topbar (after the shortcuts button).
In the .tb-right div, after the <button class="tb-icon" @click="showShortcuts=true"> button, ADD:
-->
<button class="tb-icon" @click="openSettings" title="Settings">
<i class="ti ti-settings"></i>
</button>
<!--
CHANGE 5 ── ADD the Snapshot/History button to the topbar .tb-right div.
Add after the Settings button:
-->
<button class="tb-icon" @click="openHistory" title="Version History (Ctrl+Shift+H)">
<i class="ti ti-history"></i>
</button>
<!--
CHANGE 6 ── ADD the autosave indicator to #statusbar (before the word count span).
Replace the existing first <span> (Saved/Unsaved) with:
-->
<span>
<span
class="status-dot"
:style="{background: autosaveStatus==='saved' ? 'var(--suc)' : autosaveStatus==='saving' ? 'var(--warn)' : 'var(--err)'}"
></span>
{{ autosaveStatus === 'saved' ? 'Autosaved' : autosaveStatus === 'saving' ? 'Saving…' : 'Unsaved' }}
</span>
<!--
CHANGE 7 ── ADD the "Save Snapshot" button in the pane-toolbar (editor side).
Inside the <template v-if="activePanel==='editor'"> block,
add after the last tool button group:
-->
<button class="tool-btn" @click="manualSnapshot" title="Save snapshot (version)">
<i class="ti ti-camera"></i>
</button>
<!--
════════════════════════════════════════════════════════════════════════
NEW MODALS — add these before the closing </div> of #vue-root
════════════════════════════════════════════════════════════════════════
-->
<!-- ══════ SETTINGS MODAL ══════ -->
<div class="modal-overlay" v-if="showSettings" @click.self="showSettings=false">
<div class="modal-box" style="max-width:520px;">
<div class="modal-header">
<div class="modal-title"><i class="ti ti-settings"></i> Settings</div>
<button class="modal-close" @click="showSettings=false"><i class="ti ti-x"></i></button>
</div>
<div style="padding:16px 20px; display:flex; flex-direction:column; gap:18px;">
<!-- Autosave -->
<div class="sp-section">
<div class="sp-title">Autosave</div>
<div class="slider-row">
<label>Delay</label>
<input type="range" min="500" max="10000" step="500" v-model.number="settingsAutosaveDelay"/>
<span class="val">{{ (settingsAutosaveDelay/1000).toFixed(1) }}s</span>
</div>
</div>
<!-- Snapshots -->
<div class="sp-section">
<div class="sp-title">Version Snapshots</div>
<div class="slider-row">
<label>Auto-snapshot every</label>
<input type="range" min="1" max="60" step="1" v-model.number="settingsSnapshotFreq"/>
<span class="val">{{ settingsSnapshotFreq }} min</span>
</div>
</div>
<!-- Editor -->
<div class="sp-section">
<div class="sp-title">Editor</div>
<div class="slider-row">
<label>Font size</label>
<input type="range" min="11" max="24" v-model.number="settingsEditorFontSize"/>
<span class="val">{{ settingsEditorFontSize }}px</span>
</div>
<div class="slider-row" style="margin-top:6px">
<label>Line height</label>
<input type="range" min="1.2" max="2.4" step="0.05" v-model.number="settingsLineHeight"/>
<span class="val">{{ settingsLineHeight.toFixed(2) }}</span>
</div>
<div style="display:flex; gap:10px; margin-top:8px; align-items:center;">
<label style="font-size:12px; color:var(--fg2)">Word wrap</label>
<input type="checkbox" v-model="settingsWordWrap"/>
<label style="font-size:12px; color:var(--fg2); margin-left:12px">Spellcheck</label>
<input type="checkbox" v-model="settingsSpellcheck"/>
</div>
</div>
</div>
<div style="display:flex; justify-content:flex-end; gap:8px; padding:12px 20px; border-top:1px solid var(--border);">
<button class="btn btn-sm" @click="showSettings=false">Cancel</button>
<button class="btn btn-sm btn-primary" @click="applySettings">
<i class="ti ti-check"></i> Apply
</button>
</div>
</div>
</div>
<!-- ══════ VERSION HISTORY MODAL ══════ -->
<div class="modal-overlay" v-if="showHistory" @click.self="showHistory=false">
<div class="modal-box" style="max-width:600px; max-height:80vh; display:flex; flex-direction:column;">
<div class="modal-header">
<div class="modal-title"><i class="ti ti-history"></i> Version History</div>
<button class="modal-close" @click="showHistory=false"><i class="ti ti-x"></i></button>
</div>
<div style="padding:10px 16px; border-bottom:1px solid var(--border); display:flex; gap:8px; flex-shrink:0;">
<button class="btn btn-sm btn-primary" @click="manualSnapshot">
<i class="ti ti-camera"></i> Save snapshot now
</button>
<span style="font-size:11px; color:var(--fg3); margin:auto 0;">
{{ snapshots.length }} snapshot(s) · auto every {{ snapshotFreq }} min
</span>
</div>
<div style="flex:1; overflow-y:auto; padding:8px 16px;">
<div v-if="!snapshots.length" style="text-align:center; color:var(--fg3); padding:32px 0; font-size:13px;">
No snapshots yet. Start editing and they will appear here automatically.
</div>
<div
v-for="snap in snapshots"
:key="snap.id"
style="display:flex; align-items:center; gap:10px; padding:10px 0; border-bottom:1px solid var(--border);"
>
<i class="ti ti-camera" style="color:var(--acc); font-size:14px; flex-shrink:0;"></i>
<div style="flex:1; min-width:0;">
<div style="font-size:13px; font-weight:500; color:var(--fg1);">{{ snap.label }}</div>
<div style="font-size:11px; color:var(--fg3);">
{{ formatSnapDate(snap.savedAt) }} · {{ snap.content.length }} chars
</div>
</div>
<button
class="btn btn-sm"
@click="restoreSnapshot(snap)"
title="Restore this version"
style="flex-shrink:0;"
>
<i class="ti ti-restore"></i> Restore
</button>
<button
class="btn btn-sm"
@click="removeSnapshot(snap)"
title="Delete snapshot"
style="flex-shrink:0; color:var(--err);"
>
<i class="ti ti-trash"></i>
</button>
</div>
</div>
<div style="padding:10px 16px; border-top:1px solid var(--border); font-size:11px; color:var(--fg3); flex-shrink:0;">
Snapshots are stored locally in IndexedDB. Up to 50 snapshots per file.
</div>
</div>
</div>
<!--
════════════════════════════════════════════════════════════════════════
CSS ADDITIONS — add to assets/style.css
════════════════════════════════════════════════════════════════════════
/* CodeMirror 6 host — fills #editor-wrap */
#editor-wrap .cm-editor {
height: 100%;
background: transparent;
}
#editor-wrap .cm-editor.cm-focused {
outline: none;
}
/* fallback textarea (when CM bundle is missing) */
#editor-wrap textarea {
width: 100%;
height: 100%;
resize: none;
border: none;
outline: none;
background: transparent;
color: inherit;
padding: 12px 18px;
box-sizing: border-box;
}
/* snapshot / history modal snapshot row */
.snapshot-row { transition: background 0.15s; }
.snapshot-row:hover { background: var(--bg2); }
/* settings modal */
.settings-section { border-bottom: 1px solid var(--border); padding-bottom: 14px; }
/* status bar autosave indicator */
.status-dot-saving { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
-->