@mdzip/editor 2.4.2 → 2.5.0
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.
- package/AGENTS.md +8 -0
- package/README.md +266 -5
- package/dist/diff-rendered.d.ts +54 -0
- package/dist/diff-rendered.d.ts.map +1 -0
- package/dist/diff-rendered.js +462 -0
- package/dist/diff-rendered.js.map +1 -0
- package/dist/diff-view-css.d.ts +2 -0
- package/dist/diff-view-css.d.ts.map +1 -1
- package/dist/diff-view-css.js +106 -43
- package/dist/diff-view-css.js.map +1 -1
- package/dist/diff-view.d.ts +112 -9
- package/dist/diff-view.d.ts.map +1 -1
- package/dist/diff-view.js +419 -33
- package/dist/diff-view.js.map +1 -1
- package/dist/front-matter-extension.d.ts.map +1 -1
- package/dist/front-matter-extension.js +2 -8
- package/dist/front-matter-extension.js.map +1 -1
- package/dist/heading-outline.d.ts +66 -0
- package/dist/heading-outline.d.ts.map +1 -0
- package/dist/heading-outline.js +208 -0
- package/dist/heading-outline.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/json-validation.d.ts +97 -0
- package/dist/json-validation.d.ts.map +1 -0
- package/dist/json-validation.js +496 -0
- package/dist/json-validation.js.map +1 -0
- package/dist/library-info.d.ts +7 -2
- package/dist/library-info.d.ts.map +1 -1
- package/dist/library-info.js +8 -2
- package/dist/library-info.js.map +1 -1
- package/dist/manifest-form.d.ts +40 -0
- package/dist/manifest-form.d.ts.map +1 -0
- package/dist/manifest-form.js +318 -0
- package/dist/manifest-form.js.map +1 -0
- package/dist/merge-conflicts.d.ts +56 -0
- package/dist/merge-conflicts.d.ts.map +1 -0
- package/dist/merge-conflicts.js +130 -0
- package/dist/merge-conflicts.js.map +1 -0
- package/dist/merge-regions.d.ts +92 -0
- package/dist/merge-regions.d.ts.map +1 -0
- package/dist/merge-regions.js +416 -0
- package/dist/merge-regions.js.map +1 -0
- package/dist/merge-view.d.ts +267 -0
- package/dist/merge-view.d.ts.map +1 -0
- package/dist/merge-view.js +2039 -0
- package/dist/merge-view.js.map +1 -0
- package/dist/preview-find.d.ts +30 -0
- package/dist/preview-find.d.ts.map +1 -0
- package/dist/preview-find.js +172 -0
- package/dist/preview-find.js.map +1 -0
- package/dist/rendering.d.ts +17 -52
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +21 -324
- package/dist/rendering.js.map +1 -1
- package/dist/scroll-anchors.d.ts +33 -0
- package/dist/scroll-anchors.d.ts.map +1 -0
- package/dist/scroll-anchors.js +80 -0
- package/dist/scroll-anchors.js.map +1 -0
- package/dist/view-css.d.ts.map +1 -1
- package/dist/view-css.js +2859 -2306
- package/dist/view-css.js.map +1 -1
- package/dist/view.d.ts +314 -7
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +1975 -419
- package/dist/view.js.map +1 -1
- package/dist/workspace-view.d.ts +2 -0
- package/dist/workspace-view.d.ts.map +1 -1
- package/dist/workspace-view.js +25 -2
- package/dist/workspace-view.js.map +1 -1
- package/dist/workspace.d.ts +29 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +124 -9
- package/dist/workspace.js.map +1 -1
- package/package.json +93 -83
package/dist/view.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
|
|
1
2
|
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
|
3
|
+
import { json } from '@codemirror/lang-json';
|
|
2
4
|
import { markdown } from '@codemirror/lang-markdown';
|
|
3
|
-
import {
|
|
5
|
+
import { linter } from '@codemirror/lint';
|
|
6
|
+
import { HighlightStyle, bracketMatching, foldGutter, foldKeymap, syntaxHighlighting, syntaxTree } from '@codemirror/language';
|
|
4
7
|
import { closeSearchPanel, openSearchPanel, search, searchKeymap } from '@codemirror/search';
|
|
5
|
-
import { Compartment, EditorState, RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
|
|
6
|
-
import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType, dropCursor, keymap, lineNumbers } from '@codemirror/view';
|
|
8
|
+
import { Compartment, EditorState, Prec, RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
|
|
9
|
+
import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType, dropCursor, keymap, highlightWhitespace, lineNumbers } from '@codemirror/view';
|
|
7
10
|
import { tags } from '@lezer/highlight';
|
|
8
|
-
import { Bold, Check, ChevronDown, ChevronRight, ClipboardPaste, ClipboardType, Code, Columns2, Copy, Eraser, Eye, File, FileBraces, FileImage, Folder, FolderOpen, Hash, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Highlighter, ImagePlus, Info, Italic, Link2Off, Link, List, ListOrdered, CornerDownLeft, Monitor, Moon, PackagePlus, PanelLeft, Pilcrow, Quote, Save, Scissors, Search, SpellCheck, SquareCode, SquarePen, Strikethrough, Sun, TextSelect, ZoomIn } from 'lucide';
|
|
11
|
+
import { Bold, CaseSensitive, Check, ChevronDown, ChevronRight, ChevronUp, ClipboardPaste, ClipboardType, Code, Columns2, Copy, Eraser, Eye, File, FileBraces, FileImage, Folder, FolderOpen, Hash, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Highlighter, ImagePlus, Info, Italic, Link2Off, Link, List, ListOrdered, CornerDownLeft, Monitor, Moon, PackagePlus, PanelLeft, Pilcrow, Quote, Save, Scissors, Search, SpellCheck, SquareCode, SquarePen, Strikethrough, Braces, Text, TableOfContents, Sun, TextSelect, X, ZoomIn } from 'lucide';
|
|
9
12
|
import { samePath } from '@mdzip/core-js';
|
|
10
13
|
import { browserClipboardHasImage, readBrowserClipboardImage } from './browser.js';
|
|
11
14
|
import { buildPackedArchiveBytes, isMarkdownArchivePath, resolveMarkdownEntryPoint } from './archive-utils.js';
|
|
@@ -13,8 +16,16 @@ import { MdzipAssetSession, mdzipArchiveSourceId, sniffImageSize } from './asset
|
|
|
13
16
|
import { MD_MARKDOWN_ICON } from './icons/md-markdown.js';
|
|
14
17
|
import { PAGE_WIDTH_DEFAULT_ICON, PAGE_WIDTH_FULL_ICON, PAGE_WIDTH_NARROW_ICON, PAGE_WIDTH_WIDE_ICON } from './icons/page-width.js';
|
|
15
18
|
import { MDZIP_RUNTIME_LIBRARIES } from './library-info.js';
|
|
16
|
-
import { MdzipWorkspaceService, extensionForMime, normalizeArchivePath, relativeArchivePath } from './workspace.js';
|
|
19
|
+
import { MdzipManifestInvalidError, MdzipWorkspaceService, extensionForMime, normalizeArchivePath, relativeArchivePath } from './workspace.js';
|
|
17
20
|
import { buildMdzipNavTree, canEditMdzipPath, escapeHtml, isOrphanedMdzipAsset, mdzipEntryIconKind, isMdzipManifestPath, isMdzipDefaultPolicyExternalLink, isMdzipExternalLink, isMdzipWorkspaceRelativeLink, parseMdzipLink, renderMdzipPreviewHtml } from './workspace-view.js';
|
|
21
|
+
import { collectMdzipHeadings } from '@mdzip/renderer';
|
|
22
|
+
import { describeMdzipJsonValidity, formatMdzipJsonText, isMdzipJsonPath, isMdzipRootManifestPath, setMdzipJsonMember } from './json-validation.js';
|
|
23
|
+
import { MdzipManifestForm } from './manifest-form.js';
|
|
24
|
+
import { mapScrollPosition } from './scroll-anchors.js';
|
|
25
|
+
import { zipSync } from 'fflate';
|
|
26
|
+
import { collectFindText, findMatches, findPattern, findRange, setFindHighlights } from './preview-find.js';
|
|
27
|
+
import { MDZIP_BLOCK_ATTRIBUTE, stripMdzipBlockMarks } from '@mdzip/renderer';
|
|
28
|
+
import { createMdzipHeadingOutline } from './heading-outline.js';
|
|
18
29
|
import { escapeMarkdownImageAlt, findImageReferenceAtOffset, formatImageEditMarkdown } from './image-edit.js';
|
|
19
30
|
import { MdzipRenderingService, defaultSafeMarkdownRenderer, groupTokensIntoChunks, chunkSourceKey, collectMdzipHeadingIds, MDZIP_HEADING_ID_PREFIX, tokenEmbedsImage, tokenIsHeading } from './rendering.js';
|
|
20
31
|
import { mdzipFrontMatterExtension } from './front-matter-extension.js';
|
|
@@ -53,6 +64,14 @@ const PREVIEW_ICON_HTML = lucideIcon(Eye, TOOLBAR_ICON_CLASS);
|
|
|
53
64
|
const SPLIT_ICON_HTML = lucideIcon(Columns2, TOOLBAR_ICON_CLASS);
|
|
54
65
|
const SAVE_ICON_HTML = lucideIcon(Save, TOOLBAR_ICON_CLASS);
|
|
55
66
|
const SEARCH_ICON_HTML = lucideIcon(Search, TOOLBAR_ICON_CLASS);
|
|
67
|
+
const FIND_ICON_CLASS = 'preview-find-icon';
|
|
68
|
+
const FIND_PREVIOUS_ICON_HTML = lucideIcon(ChevronUp, FIND_ICON_CLASS);
|
|
69
|
+
const FIND_NEXT_ICON_HTML = lucideIcon(ChevronDown, FIND_ICON_CLASS);
|
|
70
|
+
const FIND_CASE_ICON_HTML = lucideIcon(CaseSensitive, FIND_ICON_CLASS);
|
|
71
|
+
const FIND_CLOSE_ICON_HTML = lucideIcon(X, FIND_ICON_CLASS);
|
|
72
|
+
const OUTLINE_ICON_HTML = lucideIcon(TableOfContents, TOOLBAR_ICON_CLASS);
|
|
73
|
+
const WHITESPACE_ICON_HTML = lucideIcon(Pilcrow, TOOLBAR_ICON_CLASS);
|
|
74
|
+
const FORMAT_JSON_ICON_HTML = lucideIcon(Braces, TOOLBAR_ICON_CLASS);
|
|
56
75
|
const ZOOM_ICON_HTML = lucideIcon(ZoomIn, TOOLBAR_ICON_CLASS);
|
|
57
76
|
const DARK_THEME_ICON_HTML = lucideIcon(Moon, TOOLBAR_ICON_CLASS);
|
|
58
77
|
const LIGHT_THEME_ICON_HTML = lucideIcon(Sun, TOOLBAR_ICON_CLASS);
|
|
@@ -107,7 +126,8 @@ const MENU_IMAGE_ICON_HTML = lucideIcon(ImagePlus, MENU_ICON_CLASS);
|
|
|
107
126
|
const MENU_LINK_ICON_HTML = lucideIcon(Link, MENU_ICON_CLASS);
|
|
108
127
|
const MENU_CLEAR_FORMAT_ICON_HTML = lucideIcon(Eraser, MENU_ICON_CLASS);
|
|
109
128
|
const MENU_HEADING_PARENT_ICON_HTML = lucideIcon(Heading1, MENU_ICON_CLASS);
|
|
110
|
-
|
|
129
|
+
// Lines of plain text: ¶ is the Show whitespace button's icon.
|
|
130
|
+
const MENU_PARAGRAPH_ICON_HTML = lucideIcon(Text, MENU_ICON_CLASS);
|
|
111
131
|
const MENU_CHEVRON_ICON_HTML = lucideIcon(ChevronRight, 'nav-menu-chevron');
|
|
112
132
|
const MENU_HEADING_ICON_HTML = {
|
|
113
133
|
1: lucideIcon(Heading1, MENU_ICON_CLASS),
|
|
@@ -266,6 +286,7 @@ const CONTROL_PRESETS = {
|
|
|
266
286
|
formatting: { ...NO_FORMATTING_CONTROLS },
|
|
267
287
|
contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
|
|
268
288
|
lineNumbers: false,
|
|
289
|
+
whitespace: false,
|
|
269
290
|
save: false,
|
|
270
291
|
zoom: false,
|
|
271
292
|
previewWidth: false,
|
|
@@ -273,6 +294,7 @@ const CONTROL_PRESETS = {
|
|
|
273
294
|
orphanActions: false,
|
|
274
295
|
fileActions: false,
|
|
275
296
|
search: false,
|
|
297
|
+
outline: false,
|
|
276
298
|
codeBlockTools: true
|
|
277
299
|
},
|
|
278
300
|
viewer: {
|
|
@@ -284,6 +306,7 @@ const CONTROL_PRESETS = {
|
|
|
284
306
|
formatting: { ...NO_FORMATTING_CONTROLS },
|
|
285
307
|
contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
|
|
286
308
|
lineNumbers: true,
|
|
309
|
+
whitespace: true,
|
|
287
310
|
save: false,
|
|
288
311
|
zoom: true,
|
|
289
312
|
previewWidth: true,
|
|
@@ -291,6 +314,7 @@ const CONTROL_PRESETS = {
|
|
|
291
314
|
orphanActions: false,
|
|
292
315
|
fileActions: false,
|
|
293
316
|
search: true,
|
|
317
|
+
outline: true,
|
|
294
318
|
codeBlockTools: true
|
|
295
319
|
},
|
|
296
320
|
'standalone-editor': {
|
|
@@ -302,6 +326,7 @@ const CONTROL_PRESETS = {
|
|
|
302
326
|
formatting: { ...ALL_FORMATTING_CONTROLS },
|
|
303
327
|
contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
|
|
304
328
|
lineNumbers: true,
|
|
329
|
+
whitespace: true,
|
|
305
330
|
save: true,
|
|
306
331
|
zoom: true,
|
|
307
332
|
previewWidth: true,
|
|
@@ -309,6 +334,7 @@ const CONTROL_PRESETS = {
|
|
|
309
334
|
orphanActions: true,
|
|
310
335
|
fileActions: true,
|
|
311
336
|
search: true,
|
|
337
|
+
outline: true,
|
|
312
338
|
codeBlockTools: true
|
|
313
339
|
},
|
|
314
340
|
'hosted-editor': {
|
|
@@ -320,6 +346,7 @@ const CONTROL_PRESETS = {
|
|
|
320
346
|
formatting: { ...ALL_FORMATTING_CONTROLS },
|
|
321
347
|
contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
|
|
322
348
|
lineNumbers: true,
|
|
349
|
+
whitespace: true,
|
|
323
350
|
save: false,
|
|
324
351
|
zoom: true,
|
|
325
352
|
previewWidth: true,
|
|
@@ -327,6 +354,7 @@ const CONTROL_PRESETS = {
|
|
|
327
354
|
orphanActions: true,
|
|
328
355
|
fileActions: true,
|
|
329
356
|
search: true,
|
|
357
|
+
outline: true,
|
|
330
358
|
codeBlockTools: true
|
|
331
359
|
}
|
|
332
360
|
};
|
|
@@ -442,6 +470,24 @@ function normalizeContentDensity(value) {
|
|
|
442
470
|
return value === 'compact' ? value : 'comfortable';
|
|
443
471
|
}
|
|
444
472
|
const mdzipEditorTheme = EditorView.theme({
|
|
473
|
+
// Shown whitespace (controls.whitespace): small dots and arrows in the
|
|
474
|
+
// muted text color, so they stay in the background in light and dark.
|
|
475
|
+
'.cm-highlightSpace': {
|
|
476
|
+
backgroundImage: 'radial-gradient(circle at 50% 55%, var(--mdzip-muted-foreground-color, #999) 11%, transparent 13%)',
|
|
477
|
+
opacity: '0.7'
|
|
478
|
+
},
|
|
479
|
+
'.cm-highlightTab': {
|
|
480
|
+
backgroundImage: 'none',
|
|
481
|
+
position: 'relative',
|
|
482
|
+
opacity: '0.7'
|
|
483
|
+
},
|
|
484
|
+
'.cm-highlightTab::before': {
|
|
485
|
+
content: '"→"',
|
|
486
|
+
position: 'absolute',
|
|
487
|
+
left: '0',
|
|
488
|
+
color: 'var(--mdzip-muted-foreground-color, #999)',
|
|
489
|
+
pointerEvents: 'none'
|
|
490
|
+
},
|
|
445
491
|
'&': {
|
|
446
492
|
height: '100%',
|
|
447
493
|
fontSize: 'calc(16px * var(--mdz-zoom, 1))',
|
|
@@ -603,6 +649,13 @@ const mdzipMarkdownHighlight = HighlightStyle.define([
|
|
|
603
649
|
{ tag: tags.contentSeparator, color: '#6a9955' },
|
|
604
650
|
{ tag: tags.atom, color: '#d100d1' },
|
|
605
651
|
]);
|
|
652
|
+
// JSON entries (#68), in the same palette as the Markdown style above.
|
|
653
|
+
const mdzipJsonHighlight = HighlightStyle.define([
|
|
654
|
+
{ tag: tags.propertyName, color: '#008b8b' },
|
|
655
|
+
{ tag: tags.string, color: '#c36f00' },
|
|
656
|
+
{ tag: tags.number, color: '#6a9955' },
|
|
657
|
+
{ tag: [tags.bool, tags.null], color: '#d100d1' },
|
|
658
|
+
]);
|
|
606
659
|
const hardBreakMarkerMatcher = new MatchDecorator({
|
|
607
660
|
regexp: /<br\s*\/?>/gi,
|
|
608
661
|
decoration: Decoration.mark({ class: 'mdzip-hard-break-marker' })
|
|
@@ -819,6 +872,22 @@ function attributesToHtml(attrs) {
|
|
|
819
872
|
.map(([key, value]) => ` ${key}="${escapeHtml(String(value))}"`)
|
|
820
873
|
.join('');
|
|
821
874
|
}
|
|
875
|
+
// The selection key of the tree row at or around `element`: `f:<path>` for
|
|
876
|
+
// a file, `d:<path>` for a folder's own row (its summary), else null.
|
|
877
|
+
function navRowKey(element) {
|
|
878
|
+
if (!element) {
|
|
879
|
+
return null;
|
|
880
|
+
}
|
|
881
|
+
const file = element.closest('[data-nav-path]');
|
|
882
|
+
if (file) {
|
|
883
|
+
return `f:${file.getAttribute('data-nav-path') ?? ''}`;
|
|
884
|
+
}
|
|
885
|
+
const summary = element.closest('details[data-nav-dir] > summary');
|
|
886
|
+
if (summary) {
|
|
887
|
+
return `d:${summary.parentElement?.getAttribute('data-nav-dir') ?? ''}`;
|
|
888
|
+
}
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
822
891
|
// Renders the per-row indent/guide cells: one fixed-width cell per ancestor
|
|
823
892
|
// depth. An ancestor column draws a continuous vertical rail when that folder
|
|
824
893
|
// still has siblings below it (so the spine keeps going), otherwise it is
|
|
@@ -855,6 +924,7 @@ depth = 0) {
|
|
|
855
924
|
: safePath;
|
|
856
925
|
const classes = [
|
|
857
926
|
'nav-file',
|
|
927
|
+
options.selected.has(`f:${node.entry.path}`) ? 'nav-selected' : '',
|
|
858
928
|
isCurrent ? 'current-entry' : '',
|
|
859
929
|
isOrphaned ? 'orphaned-asset' : '',
|
|
860
930
|
isEntryPoint ? 'entry-point' : ''
|
|
@@ -866,19 +936,19 @@ depth = 0) {
|
|
|
866
936
|
: isImageFile(node.entry.path)
|
|
867
937
|
? IMAGE_ICON_HTML
|
|
868
938
|
: FILE_ICON_HTML;
|
|
869
|
-
const orphanBtnHtml = isOrphaned && options.allowOrphanActions ? `
|
|
870
|
-
<span class="nav-orphan-button" role="button" tabindex="0"
|
|
871
|
-
title="Orphaned asset" aria-label="Orphaned asset actions"
|
|
872
|
-
data-orphan-path="${safePath}">
|
|
873
|
-
${ORPHAN_ICON_HTML}
|
|
939
|
+
const orphanBtnHtml = isOrphaned && options.allowOrphanActions ? `
|
|
940
|
+
<span class="nav-orphan-button" role="button" tabindex="0"
|
|
941
|
+
title="Orphaned asset" aria-label="Orphaned asset actions"
|
|
942
|
+
data-orphan-path="${safePath}">
|
|
943
|
+
${ORPHAN_ICON_HTML}
|
|
874
944
|
</span>` : '';
|
|
875
945
|
const draggable = options.allowDrag && !isManifest;
|
|
876
|
-
return `<button type="button" class="${classes}" title="${title}"
|
|
877
|
-
data-nav-path="${safePath}" data-orphan="${isOrphaned ? 'true' : ''}"${draggable ? ' draggable="true"' : ''}>
|
|
878
|
-
${guides}<span class="nav-caret"></span>
|
|
879
|
-
<span class="nav-file-icon ${iconKind}">${iconHtml}</span>
|
|
880
|
-
${orphanBtnHtml}
|
|
881
|
-
<span class="nav-label">${safeName}</span>
|
|
946
|
+
return `<button type="button" class="${classes}" title="${title}"
|
|
947
|
+
data-nav-path="${safePath}" data-orphan="${isOrphaned ? 'true' : ''}"${draggable ? ' draggable="true"' : ''}>
|
|
948
|
+
${guides}<span class="nav-caret"></span>
|
|
949
|
+
<span class="nav-file-icon ${iconKind}">${iconHtml}</span>
|
|
950
|
+
${orphanBtnHtml}
|
|
951
|
+
<span class="nav-label">${safeName}</span>
|
|
882
952
|
</button>`;
|
|
883
953
|
}
|
|
884
954
|
const childTrail = depth === 0 ? [] : [...trail, !isLast];
|
|
@@ -886,14 +956,16 @@ depth = 0) {
|
|
|
886
956
|
.map((child, index) => renderNavNode(child, state, options, childTrail, index === node.children.length - 1, depth + 1))
|
|
887
957
|
.join('');
|
|
888
958
|
const pending = options.pendingFolders.has(node.path);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
<span class="nav-
|
|
894
|
-
<span class="nav-
|
|
895
|
-
|
|
896
|
-
|
|
959
|
+
const open = options.collapsed.has(node.path) ? '' : ' open';
|
|
960
|
+
const selected = options.selected.has(`d:${node.path}`) ? ' class="nav-selected"' : '';
|
|
961
|
+
return `<details class="nav-directory${pending ? ' pending-folder' : ''}"${open} data-nav-dir="${escapeHtml(node.path)}">
|
|
962
|
+
<summary${selected}${pending ? ` title="${escapeHtml(node.path)} — not saved until it contains a file"` : ''}>
|
|
963
|
+
${guides}<span class="nav-caret" aria-hidden="true"></span>
|
|
964
|
+
<span class="nav-folder-icon closed">${FOLDER_CLOSED_ICON_HTML}</span>
|
|
965
|
+
<span class="nav-folder-icon open">${FOLDER_OPEN_ICON_HTML}</span>
|
|
966
|
+
<span class="nav-label">${escapeHtml(node.name)}</span>
|
|
967
|
+
</summary>
|
|
968
|
+
<div class="nav-directory-children">${children}</div>
|
|
897
969
|
</details>`;
|
|
898
970
|
}
|
|
899
971
|
// Inserts view-local pending (not yet saved) folders into the nav tree so they
|
|
@@ -1068,6 +1140,14 @@ export class MdzipWorkspaceView {
|
|
|
1068
1140
|
this.contextMenuState = null;
|
|
1069
1141
|
this.nameDialogState = null;
|
|
1070
1142
|
this.deleteDialogState = null;
|
|
1143
|
+
// Selected rows of the file tree (#69): `f:<path>` / `d:<path>`, in the
|
|
1144
|
+
// order picked, and the row a Shift+click range starts from.
|
|
1145
|
+
this.navSelection = [];
|
|
1146
|
+
this.navSelectionAnchor = null;
|
|
1147
|
+
// Folders the reader closed, kept across the tree's redraws.
|
|
1148
|
+
this.navCollapsed = new Set();
|
|
1149
|
+
// A yes/no question in the editor's own dialog (see askConfirm()).
|
|
1150
|
+
this.confirmDialogState = null;
|
|
1071
1151
|
this.pendingNewFolders = new Set();
|
|
1072
1152
|
this.pendingReplacePath = null;
|
|
1073
1153
|
this.conversionHookPending = false;
|
|
@@ -1091,7 +1171,12 @@ export class MdzipWorkspaceView {
|
|
|
1091
1171
|
this.cmEditor = null;
|
|
1092
1172
|
this.readOnlyCompartment = new Compartment();
|
|
1093
1173
|
this.lineNumbersCompartment = new Compartment();
|
|
1174
|
+
this.whitespaceCompartment = new Compartment();
|
|
1094
1175
|
this.searchCompartment = new Compartment();
|
|
1176
|
+
this.languageCompartment = new Compartment();
|
|
1177
|
+
this.cmLanguage = 'markdown';
|
|
1178
|
+
this.jsonValidity = null;
|
|
1179
|
+
this.jsonValidityPath = null;
|
|
1095
1180
|
this.updatingCm = false;
|
|
1096
1181
|
this.syncing = false;
|
|
1097
1182
|
// Last value this class itself wrote to each pane's scrollTop, used to
|
|
@@ -1099,6 +1184,8 @@ export class MdzipWorkspaceView {
|
|
|
1099
1184
|
// syncScrollFromPreview/syncScrollToPreview).
|
|
1100
1185
|
this.lastSyncedEditorScrollTop = null;
|
|
1101
1186
|
this.lastSyncedPreviewScrollTop = null;
|
|
1187
|
+
// See splitScrollBlocks().
|
|
1188
|
+
this.splitBlockCache = null;
|
|
1102
1189
|
// Timestamp of the most recent updatePreview() call (edit-driven or
|
|
1103
1190
|
// otherwise). A content change that alters a mounted element's rendered
|
|
1104
1191
|
// height (a chunk reconcile re-rendering a mermaid diagram, an image
|
|
@@ -1164,6 +1251,8 @@ export class MdzipWorkspaceView {
|
|
|
1164
1251
|
// (images loading or easing open, a diagram rendering) and push it out of
|
|
1165
1252
|
// view. This holds the target at the pane's top edge until the user
|
|
1166
1253
|
// scrolls either pane or the preview re-renders.
|
|
1254
|
+
// requestAnimationFrame handle of a smooth scroll to an anchor (see glidePreviewTo).
|
|
1255
|
+
this.previewGlide = null;
|
|
1167
1256
|
this.anchorPin = null;
|
|
1168
1257
|
// Each link's own target/rel from before the external-link policy touched
|
|
1169
1258
|
// it, so a policy change can restore them before re-applying.
|
|
@@ -1200,6 +1289,36 @@ export class MdzipWorkspaceView {
|
|
|
1200
1289
|
// matches() does not re-run on every snapshot render of the same entry.
|
|
1201
1290
|
this.entryMatchMissKey = null;
|
|
1202
1291
|
this.entryGeneration = 0;
|
|
1292
|
+
this.findOpen = false;
|
|
1293
|
+
this.findMatchCase = false;
|
|
1294
|
+
this.findState = null;
|
|
1295
|
+
// Each drawn chunk's text with its nodes, until something in it changes.
|
|
1296
|
+
this.findDomTexts = new WeakMap();
|
|
1297
|
+
// Every chunk's text by its source key, drawn or not, for counting.
|
|
1298
|
+
this.findTextCache = new Map();
|
|
1299
|
+
this.findObserver = null;
|
|
1300
|
+
this.findRefreshQueued = false;
|
|
1301
|
+
this.findIndexing = false;
|
|
1302
|
+
// Goes to the first match once typing pauses, when it isn't drawn yet.
|
|
1303
|
+
this.findRevealTimer = null;
|
|
1304
|
+
this.outlinePosition = 'right';
|
|
1305
|
+
// Null until set by the option or a drag: the style sheet's width applies.
|
|
1306
|
+
this.outlineWidth = null;
|
|
1307
|
+
this.outlineVisible = false;
|
|
1308
|
+
this.whitespaceVisible = false;
|
|
1309
|
+
// Which parts of the edit toolbar the last render showed (renderFormattingControls).
|
|
1310
|
+
this.formattingShown = false;
|
|
1311
|
+
// The manifest keeps its own layout (form by default); the other files'
|
|
1312
|
+
// layout waits in documentLayout while it's open.
|
|
1313
|
+
this.manifestLayout = 'preview';
|
|
1314
|
+
this.documentLayout = 'preview';
|
|
1315
|
+
this.layoutIsManifest = false;
|
|
1316
|
+
this.manifestForm = null;
|
|
1317
|
+
this.whitespaceControlShown = false;
|
|
1318
|
+
this.formatJsonShown = false;
|
|
1319
|
+
this.outlineOptions = {};
|
|
1320
|
+
this.outline = null;
|
|
1321
|
+
this.outlineGeneration = -1;
|
|
1203
1322
|
this.pendingAddFilesDir = null;
|
|
1204
1323
|
this.options = options;
|
|
1205
1324
|
this.controlPolicy = resolveMdzipControlPolicy(options.controls);
|
|
@@ -1216,6 +1335,14 @@ export class MdzipWorkspaceView {
|
|
|
1216
1335
|
this.colorSchemePreference = options.initialColorScheme ?? 'system';
|
|
1217
1336
|
this.colorScheme = this.resolveColorScheme(this.colorSchemePreference);
|
|
1218
1337
|
this.navVisible = options.navigationButtonActive ?? this.navVisible;
|
|
1338
|
+
this.outlineOptions = typeof options.outline === 'object' ? options.outline : {};
|
|
1339
|
+
this.outlineVisible = typeof options.outline === 'object' ? options.outline.visible ?? false : options.outline ?? false;
|
|
1340
|
+
this.outlinePosition = this.outlineOptions.position === 'left' ? 'left' : 'right';
|
|
1341
|
+
this.outlineWidth = typeof this.outlineOptions.width === 'number' && this.outlineOptions.width > 0
|
|
1342
|
+
? Math.round(this.outlineOptions.width)
|
|
1343
|
+
: null;
|
|
1344
|
+
this.whitespaceVisible = options.showWhitespace ?? false;
|
|
1345
|
+
this.manifestLayout = options.manifestView === 'json' ? 'source' : 'preview';
|
|
1219
1346
|
this.markdownRenderer = options.markdownRenderer;
|
|
1220
1347
|
this.markdownExtensions = options.markdownExtensions ?? [];
|
|
1221
1348
|
this.frontMatterOptions = options.frontMatter ?? {};
|
|
@@ -1241,6 +1368,18 @@ export class MdzipWorkspaceView {
|
|
|
1241
1368
|
this.elSourceIcon = q('[data-ref="source-icon"]');
|
|
1242
1369
|
this.elSaveBtn = q('[data-ref="save-btn"]');
|
|
1243
1370
|
this.elSearchBtn = q('[data-ref="search-btn"]');
|
|
1371
|
+
this.elFind = q('[data-ref="preview-find"]');
|
|
1372
|
+
this.elFindInput = q('[data-ref="preview-find-input"]');
|
|
1373
|
+
this.elFindCount = q('[data-ref="preview-find-count"]');
|
|
1374
|
+
this.elFindCase = q('[data-ref="preview-find-case"]');
|
|
1375
|
+
this.elFindPrevious = q('[data-ref="preview-find-previous"]');
|
|
1376
|
+
this.elFindNext = q('[data-ref="preview-find-next"]');
|
|
1377
|
+
this.elFindClose = q('[data-ref="preview-find-close"]');
|
|
1378
|
+
this.elOutlineBtn = q('[data-ref="outline-btn"]');
|
|
1379
|
+
this.elWhitespaceBtn = q('[data-ref="whitespace-btn"]');
|
|
1380
|
+
this.elFormatJsonBtn = q('[data-ref="format-json-btn"]');
|
|
1381
|
+
this.elOutlinePane = q('[data-ref="outline-pane"]');
|
|
1382
|
+
this.elOutlineResizer = q('[data-ref="outline-resizer"]');
|
|
1244
1383
|
this.elZoomBtn = q('[data-ref="zoom-btn"]');
|
|
1245
1384
|
this.elWidthControls = q('[data-ref="width-controls"]');
|
|
1246
1385
|
this.elWidthMenuBtn = q('[data-ref="width-menu-btn"]');
|
|
@@ -1264,6 +1403,7 @@ export class MdzipWorkspaceView {
|
|
|
1264
1403
|
this.elEditToolbar = q('[data-ref="edit-toolbar"]');
|
|
1265
1404
|
this.elImageInput = q('[data-ref="image-input"]');
|
|
1266
1405
|
this.elEditorHost = q('[data-ref="editor-host"]');
|
|
1406
|
+
this.elJsonStatus = q('[data-ref="json-status"]');
|
|
1267
1407
|
this.elSplitResizer = q('[data-ref="split-resizer"]');
|
|
1268
1408
|
this.elPreviewPane = q('[data-ref="preview-pane"]');
|
|
1269
1409
|
this.elPreviewContent = q('[data-ref="preview-content"]');
|
|
@@ -1309,6 +1449,10 @@ export class MdzipWorkspaceView {
|
|
|
1309
1449
|
this.elNameValidation = q('[data-ref="name-validation"]');
|
|
1310
1450
|
this.elNameConfirmBtn = q('[data-ref="name-confirm-btn"]');
|
|
1311
1451
|
this.elDeleteDialog = q('[data-ref="delete-dialog"]');
|
|
1452
|
+
this.elConfirmDialog = q('[data-ref="confirm-dialog"]');
|
|
1453
|
+
this.elConfirmDialogTitle = q('[data-ref="confirm-dialog-title"]');
|
|
1454
|
+
this.elConfirmDialogText = q('[data-ref="confirm-dialog-text"]');
|
|
1455
|
+
this.elConfirmDialogOk = q('[data-ref="confirm-dialog-ok"]');
|
|
1312
1456
|
this.elDeleteDialogText = q('[data-ref="delete-dialog-text"]');
|
|
1313
1457
|
this.elDeleteConfirmBtn = q('[data-ref="delete-confirm-btn"]');
|
|
1314
1458
|
this.elReplaceInput = q('[data-ref="replace-input"]');
|
|
@@ -1552,11 +1696,12 @@ export class MdzipWorkspaceView {
|
|
|
1552
1696
|
return true;
|
|
1553
1697
|
}
|
|
1554
1698
|
/**
|
|
1555
|
-
* Opens
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1559
|
-
* the
|
|
1699
|
+
* Opens find for the current document. In the View layout it's a find
|
|
1700
|
+
* bar over the preview that searches the rendered text, the whole
|
|
1701
|
+
* document including parts not drawn yet, and leaves the layout as it is.
|
|
1702
|
+
* In Edit and Split it's CodeMirror's find/replace panel. Works in
|
|
1703
|
+
* read-only (Viewer) hosts too. When the preview belongs to an entry
|
|
1704
|
+
* renderer, switches to split/source for the panel.
|
|
1560
1705
|
*/
|
|
1561
1706
|
async openSearch() {
|
|
1562
1707
|
if (!this.controlPolicy.search) {
|
|
@@ -1566,6 +1711,10 @@ export class MdzipWorkspaceView {
|
|
|
1566
1711
|
if (!snapshot || snapshot.currentPathType !== 'markdown') {
|
|
1567
1712
|
return false;
|
|
1568
1713
|
}
|
|
1714
|
+
if (this.findApplies(snapshot)) {
|
|
1715
|
+
this.openFind();
|
|
1716
|
+
return true;
|
|
1717
|
+
}
|
|
1569
1718
|
if (this.layout === 'preview') {
|
|
1570
1719
|
const nextLayout = this.controlPolicy.layout.split
|
|
1571
1720
|
? 'split'
|
|
@@ -1583,8 +1732,357 @@ export class MdzipWorkspaceView {
|
|
|
1583
1732
|
return openSearchPanel(editor);
|
|
1584
1733
|
}
|
|
1585
1734
|
closeSearch() {
|
|
1735
|
+
if (this.findOpen) {
|
|
1736
|
+
return this.closeFind();
|
|
1737
|
+
}
|
|
1586
1738
|
return this.cmEditor ? closeSearchPanel(this.cmEditor) : false;
|
|
1587
1739
|
}
|
|
1740
|
+
/** Whether the find bar is open over the preview. */
|
|
1741
|
+
get isFindOpen() {
|
|
1742
|
+
return this.findOpen;
|
|
1743
|
+
}
|
|
1744
|
+
// --- Find in the preview (#62) ---------------------------------------------------
|
|
1745
|
+
findApplies(snapshot = this.workspace?.snapshot()) {
|
|
1746
|
+
return !!snapshot && this.controlPolicy.search && this.layout === 'preview'
|
|
1747
|
+
&& snapshot.currentPathType === 'markdown' && !this.entryState;
|
|
1748
|
+
}
|
|
1749
|
+
openFind() {
|
|
1750
|
+
const doc = this.elRoot.ownerDocument;
|
|
1751
|
+
// Like a browser: a short selection in the document becomes the query.
|
|
1752
|
+
const selection = doc.getSelection?.();
|
|
1753
|
+
if (selection && selection.rangeCount && selection.anchorNode && this.elPreviewContent.contains(selection.anchorNode)) {
|
|
1754
|
+
const selected = selection.toString().trim();
|
|
1755
|
+
if (selected && selected.length <= 200 && !/\n/.test(selected)) {
|
|
1756
|
+
this.elFindInput.value = selected;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
this.findOpen = true;
|
|
1760
|
+
this.elFind.hidden = false;
|
|
1761
|
+
this.elSearchBtn.classList.add('active');
|
|
1762
|
+
this.elFindInput.focus();
|
|
1763
|
+
this.elFindInput.select();
|
|
1764
|
+
if (!this.findObserver && typeof MutationObserver !== 'undefined') {
|
|
1765
|
+
this.findObserver = new MutationObserver((records) => {
|
|
1766
|
+
for (const record of records) {
|
|
1767
|
+
const target = record.target.nodeType === 1 ? record.target : record.target.parentElement;
|
|
1768
|
+
const root = target?.closest('.mdzip-chunk') ?? this.elPreviewContent;
|
|
1769
|
+
this.findDomTexts.delete(root);
|
|
1770
|
+
}
|
|
1771
|
+
this.scheduleFindRefresh();
|
|
1772
|
+
});
|
|
1773
|
+
this.findObserver.observe(this.elPreviewContent, { childList: true, subtree: true, characterData: true });
|
|
1774
|
+
}
|
|
1775
|
+
this.refreshFind('viewport');
|
|
1776
|
+
this.revealFindMatchSoon();
|
|
1777
|
+
}
|
|
1778
|
+
// When the current match is in a chunk not drawn yet, draws it and goes
|
|
1779
|
+
// there once typing pauses (the next keystroke starts the wait again).
|
|
1780
|
+
revealFindMatchSoon() {
|
|
1781
|
+
if (this.findRevealTimer !== null) {
|
|
1782
|
+
clearTimeout(this.findRevealTimer);
|
|
1783
|
+
}
|
|
1784
|
+
this.findRevealTimer = setTimeout(() => {
|
|
1785
|
+
this.findRevealTimer = null;
|
|
1786
|
+
void this.moveFind(0);
|
|
1787
|
+
}, 300);
|
|
1788
|
+
}
|
|
1789
|
+
closeFind(restoreFocus = true) {
|
|
1790
|
+
if (!this.findOpen) {
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
const doc = this.elRoot.ownerDocument;
|
|
1794
|
+
const hadFocus = this.elFind.contains(doc.activeElement);
|
|
1795
|
+
this.findOpen = false;
|
|
1796
|
+
if (this.findRevealTimer !== null) {
|
|
1797
|
+
clearTimeout(this.findRevealTimer);
|
|
1798
|
+
this.findRevealTimer = null;
|
|
1799
|
+
}
|
|
1800
|
+
this.elFind.hidden = true;
|
|
1801
|
+
this.elSearchBtn.classList.remove('active');
|
|
1802
|
+
this.findState = null;
|
|
1803
|
+
this.findObserver?.disconnect();
|
|
1804
|
+
this.findObserver = null;
|
|
1805
|
+
this.findDomTexts = new WeakMap();
|
|
1806
|
+
setFindHighlights(doc, this, [], null);
|
|
1807
|
+
if (restoreFocus && hadFocus) {
|
|
1808
|
+
this.elPreviewPane.focus({ preventScroll: true });
|
|
1809
|
+
}
|
|
1810
|
+
return true;
|
|
1811
|
+
}
|
|
1812
|
+
scheduleFindRefresh() {
|
|
1813
|
+
if (this.findRefreshQueued) {
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
this.findRefreshQueued = true;
|
|
1817
|
+
requestAnimationFrame(() => {
|
|
1818
|
+
this.findRefreshQueued = false;
|
|
1819
|
+
this.refreshFind('keep');
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
// The chunks of the document, drawn or not. Without chunks (a custom
|
|
1823
|
+
// renderer), the whole preview is one.
|
|
1824
|
+
findChunks() {
|
|
1825
|
+
const state = this.chunkedRenderState;
|
|
1826
|
+
if (!state) {
|
|
1827
|
+
return [{ key: null, root: this.elPreviewContent, index: 0 }];
|
|
1828
|
+
}
|
|
1829
|
+
return state.records.map((record, index) => ({
|
|
1830
|
+
key: record.key,
|
|
1831
|
+
root: record.root && record.root.isConnected ? record.root : null,
|
|
1832
|
+
index
|
|
1833
|
+
}));
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Matches the query against every chunk's text and repaints. `viewport`
|
|
1837
|
+
* (a new query) makes the first match at or below the top of the pane
|
|
1838
|
+
* current and scrolls to it; `keep` (the document changed under the bar)
|
|
1839
|
+
* keeps the current match.
|
|
1840
|
+
*/
|
|
1841
|
+
refreshFind(mode, scroll = mode === 'viewport') {
|
|
1842
|
+
if (!this.findOpen || this.destroyed) {
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
const previous = this.findState;
|
|
1846
|
+
const pattern = findPattern(this.elFindInput.value, this.findMatchCase);
|
|
1847
|
+
const matches = [];
|
|
1848
|
+
const texts = [];
|
|
1849
|
+
let pending = false;
|
|
1850
|
+
const chunks = this.findChunks();
|
|
1851
|
+
if (pattern) {
|
|
1852
|
+
for (const chunk of chunks) {
|
|
1853
|
+
let dom = null;
|
|
1854
|
+
let text;
|
|
1855
|
+
if (chunk.root) {
|
|
1856
|
+
dom = this.findDomTexts.get(chunk.root) ?? null;
|
|
1857
|
+
if (!dom) {
|
|
1858
|
+
dom = collectFindText(chunk.root);
|
|
1859
|
+
this.findDomTexts.set(chunk.root, dom);
|
|
1860
|
+
}
|
|
1861
|
+
text = dom.text;
|
|
1862
|
+
if (chunk.key !== null) {
|
|
1863
|
+
this.findTextCache.set(chunk.key, text);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
else if (chunk.key !== null) {
|
|
1867
|
+
text = this.findTextCache.get(chunk.key);
|
|
1868
|
+
}
|
|
1869
|
+
texts.push(dom);
|
|
1870
|
+
if (text === undefined) {
|
|
1871
|
+
pending = true;
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
let ordinal = 0;
|
|
1875
|
+
for (const [start, end] of findMatches(text, pattern)) {
|
|
1876
|
+
matches.push({ chunk: chunk.index, ordinal: ordinal++, start, end });
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
let current = -1;
|
|
1881
|
+
if (matches.length) {
|
|
1882
|
+
const was = mode === 'keep' && previous && previous.current >= 0 ? previous.matches[previous.current] : null;
|
|
1883
|
+
if (was) {
|
|
1884
|
+
current = matches.findIndex((match) => match.chunk === was.chunk && match.ordinal === was.ordinal);
|
|
1885
|
+
if (current < 0) {
|
|
1886
|
+
current = Math.min(previous.current, matches.length - 1);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
else {
|
|
1890
|
+
current = this.firstFindMatchInView(matches, chunks, texts);
|
|
1891
|
+
// A first match (perhaps found by the background count): show it,
|
|
1892
|
+
// drawing its chunk first when it isn't yet.
|
|
1893
|
+
scroll = true;
|
|
1894
|
+
if (!texts[matches[current].chunk]) {
|
|
1895
|
+
this.revealFindMatchSoon();
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
this.findState = { matches, current, pending, texts };
|
|
1900
|
+
this.paintFind(scroll);
|
|
1901
|
+
if (pending) {
|
|
1902
|
+
this.indexFindChunks();
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
// The first match at or below the top of the preview pane, or the first.
|
|
1906
|
+
firstFindMatchInView(matches, chunks, texts) {
|
|
1907
|
+
const paneTop = this.elPreviewPane.getBoundingClientRect().top;
|
|
1908
|
+
let skipped = -1;
|
|
1909
|
+
for (let i = 0; i < matches.length; i += 1) {
|
|
1910
|
+
const match = matches[i];
|
|
1911
|
+
const root = chunks[match.chunk]?.root;
|
|
1912
|
+
const dom = texts[match.chunk];
|
|
1913
|
+
if (!root || !dom) {
|
|
1914
|
+
// Not drawn yet: below what is.
|
|
1915
|
+
return i;
|
|
1916
|
+
}
|
|
1917
|
+
if (match.chunk === skipped) {
|
|
1918
|
+
continue;
|
|
1919
|
+
}
|
|
1920
|
+
if (root.getBoundingClientRect().bottom < paneTop) {
|
|
1921
|
+
skipped = match.chunk;
|
|
1922
|
+
continue;
|
|
1923
|
+
}
|
|
1924
|
+
const range = findRange(dom, match.start, match.end);
|
|
1925
|
+
if (!range || typeof range.getBoundingClientRect !== 'function' || range.getBoundingClientRect().top >= paneTop - 1) {
|
|
1926
|
+
return i;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
return 0;
|
|
1930
|
+
}
|
|
1931
|
+
// Highlights the matches near the current one (all of them, up to a
|
|
1932
|
+
// thousand) and the current one, and updates the count.
|
|
1933
|
+
paintFind(scroll) {
|
|
1934
|
+
const state = this.findState;
|
|
1935
|
+
const all = [];
|
|
1936
|
+
let currentRange = null;
|
|
1937
|
+
if (state && state.current >= 0) {
|
|
1938
|
+
const from = Math.max(0, state.current - 500);
|
|
1939
|
+
const to = Math.min(state.matches.length, state.current + 500);
|
|
1940
|
+
for (let i = from; i < to; i += 1) {
|
|
1941
|
+
const match = state.matches[i];
|
|
1942
|
+
const dom = state.texts[match.chunk];
|
|
1943
|
+
const range = dom ? findRange(dom, match.start, match.end) : null;
|
|
1944
|
+
if (!range) {
|
|
1945
|
+
continue;
|
|
1946
|
+
}
|
|
1947
|
+
if (i === state.current) {
|
|
1948
|
+
currentRange = range;
|
|
1949
|
+
}
|
|
1950
|
+
else {
|
|
1951
|
+
all.push(range);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
setFindHighlights(this.elRoot.ownerDocument, this, all, currentRange);
|
|
1956
|
+
const query = this.elFindInput.value.trim();
|
|
1957
|
+
const total = state?.matches.length ?? 0;
|
|
1958
|
+
let label = '';
|
|
1959
|
+
if (query && state) {
|
|
1960
|
+
if (!total) {
|
|
1961
|
+
label = state.pending ? 'Searching…' : 'No results';
|
|
1962
|
+
}
|
|
1963
|
+
else {
|
|
1964
|
+
label = `${state.current + 1} of ${total}${state.pending ? '+' : ''}`;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
this.elFindCount.textContent = label;
|
|
1968
|
+
this.elFind.classList.toggle('no-results', !!query && !!state && !total && !state.pending);
|
|
1969
|
+
this.elFindPrevious.disabled = total === 0;
|
|
1970
|
+
this.elFindNext.disabled = total === 0;
|
|
1971
|
+
if (scroll && currentRange) {
|
|
1972
|
+
this.scrollFindRangeIntoView(currentRange);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
scrollFindRangeIntoView(range) {
|
|
1976
|
+
if (typeof range.getBoundingClientRect !== 'function') {
|
|
1977
|
+
return;
|
|
1978
|
+
}
|
|
1979
|
+
const pane = this.elPreviewPane;
|
|
1980
|
+
const rect = range.getBoundingClientRect();
|
|
1981
|
+
const paneRect = pane.getBoundingClientRect();
|
|
1982
|
+
// Below the find bar, above the bottom edge.
|
|
1983
|
+
if (rect.top >= paneRect.top + this.elFind.offsetHeight + 16 && rect.bottom <= paneRect.bottom - 16) {
|
|
1984
|
+
return;
|
|
1985
|
+
}
|
|
1986
|
+
this.releaseAnchorPin();
|
|
1987
|
+
pane.scrollTop += rect.top - paneRect.top - pane.clientHeight / 3;
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Goes to the next (1) or previous (-1) match, drawing its chunk first
|
|
1991
|
+
* when it isn't yet. A current match that hasn't been shown (its chunk
|
|
1992
|
+
* isn't drawn) is gone to first, not skipped; 0 only does that.
|
|
1993
|
+
*/
|
|
1994
|
+
async moveFind(delta) {
|
|
1995
|
+
const state = this.findState;
|
|
1996
|
+
if (!this.findOpen || !state || !state.matches.length) {
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
const total = state.matches.length;
|
|
2000
|
+
const unseen = state.current >= 0 && !state.texts[state.matches[state.current].chunk];
|
|
2001
|
+
if (!unseen) {
|
|
2002
|
+
if (delta === 0) {
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
const from = state.current < 0 ? (delta > 0 ? -1 : 0) : state.current;
|
|
2006
|
+
state.current = (from + delta + total) % total;
|
|
2007
|
+
}
|
|
2008
|
+
const match = state.matches[state.current];
|
|
2009
|
+
if (!state.texts[match.chunk]) {
|
|
2010
|
+
await this.mountChunksThrough(match.chunk);
|
|
2011
|
+
this.findDomTexts = new WeakMap();
|
|
2012
|
+
this.refreshFind('keep', true);
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
this.paintFind(true);
|
|
2016
|
+
}
|
|
2017
|
+
// Draws the chunks up to and including `index`, as scrollToAnchor() does.
|
|
2018
|
+
async mountChunksThrough(index) {
|
|
2019
|
+
const pending = this.chunkedRenderState;
|
|
2020
|
+
if (!pending || pending.cursor > index) {
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
await this.drainRemainingChunks(pending, () => { }, new AbortController().signal, index);
|
|
2024
|
+
const remaining = this.chunkedRenderState;
|
|
2025
|
+
if (remaining && remaining.generation === pending.generation && !remaining.sentinelHandle
|
|
2026
|
+
&& remaining.cursor < remaining.records.length) {
|
|
2027
|
+
this.armChunkSentinel(remaining.records, remaining.cursor, remaining.context, remaining.generation, remaining.animateImageHydration);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
/**
|
|
2031
|
+
* Finds the text of chunks not drawn yet, a few at a time between frames,
|
|
2032
|
+
* so the count covers the whole document: each chunk's HTML (cached, or
|
|
2033
|
+
* rendered) in a detached fragment, read the same way as the preview.
|
|
2034
|
+
*/
|
|
2035
|
+
indexFindChunks() {
|
|
2036
|
+
const state = this.chunkedRenderState;
|
|
2037
|
+
if (this.findIndexing || !state) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
this.findIndexing = true;
|
|
2041
|
+
const records = state.records;
|
|
2042
|
+
const generation = state.generation;
|
|
2043
|
+
const live = new Set(records.map((record) => record.key));
|
|
2044
|
+
for (const key of Array.from(this.findTextCache.keys())) {
|
|
2045
|
+
if (!live.has(key)) {
|
|
2046
|
+
this.findTextCache.delete(key);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
const run = async () => {
|
|
2050
|
+
let batchStart = performance.now();
|
|
2051
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
2052
|
+
if (!this.findOpen || this.destroyed || this.chunkedRenderState?.records !== records) {
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
const record = records[i];
|
|
2056
|
+
if ((record.root && record.root.isConnected) || this.findTextCache.has(record.key)) {
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
let html = record.html
|
|
2060
|
+
?? (this.chunkHtmlCache?.generation === generation ? this.chunkHtmlCache.html.get(i) : undefined);
|
|
2061
|
+
if (html === undefined) {
|
|
2062
|
+
const result = this.renderingService.renderChunk(record.tokens, state.context, { index: i, markBlocks: true });
|
|
2063
|
+
html = typeof result === 'string' ? result : await result;
|
|
2064
|
+
}
|
|
2065
|
+
this.findTextCache.set(record.key, collectFindText(this.inertPreviewFragment(html)).text);
|
|
2066
|
+
if (performance.now() - batchStart > 12) {
|
|
2067
|
+
this.refreshFind('keep', false);
|
|
2068
|
+
await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
2069
|
+
batchStart = performance.now();
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
void run()
|
|
2074
|
+
.catch((error) => {
|
|
2075
|
+
if (error?.name !== 'AbortError') {
|
|
2076
|
+
this.options.onFailed?.(error);
|
|
2077
|
+
}
|
|
2078
|
+
})
|
|
2079
|
+
.finally(() => {
|
|
2080
|
+
this.findIndexing = false;
|
|
2081
|
+
if (this.findOpen && !this.destroyed && this.chunkedRenderState?.records === records) {
|
|
2082
|
+
this.refreshFind('keep', false);
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
1588
2086
|
async convertToMdz() {
|
|
1589
2087
|
if (!this.workspace || this.workspace.mode === 'read-only') {
|
|
1590
2088
|
return false;
|
|
@@ -1603,6 +2101,7 @@ export class MdzipWorkspaceView {
|
|
|
1603
2101
|
this.cmEditor?.focus();
|
|
1604
2102
|
}
|
|
1605
2103
|
destroy() {
|
|
2104
|
+
this.closeFind(false);
|
|
1606
2105
|
this.systemColorSchemeQuery?.removeEventListener?.('change', this.onSystemColorSchemeChange);
|
|
1607
2106
|
this.conversionDocumentGeneration += 1;
|
|
1608
2107
|
this.resolveImageInsertDialog(null);
|
|
@@ -1616,6 +2115,8 @@ export class MdzipWorkspaceView {
|
|
|
1616
2115
|
this.resetPreviewState();
|
|
1617
2116
|
this.replaceAssetSession(null);
|
|
1618
2117
|
this.teardownEntryRenderer();
|
|
2118
|
+
this.outline?.destroy();
|
|
2119
|
+
this.outline = null;
|
|
1619
2120
|
// Release any whenRendered() waiters so their promises do not hang.
|
|
1620
2121
|
this.flushRenderedWaiters();
|
|
1621
2122
|
this.destroyed = true;
|
|
@@ -2039,7 +2540,13 @@ export class MdzipWorkspaceView {
|
|
|
2039
2540
|
this.fireAssetsHydrated(snapshot, generation);
|
|
2040
2541
|
}).catch((error) => this.options.onFailed?.(error));
|
|
2041
2542
|
}
|
|
2543
|
+
else if (this.isManifestFormPath(snapshot)) {
|
|
2544
|
+
this.mountManifestForm(snapshot);
|
|
2545
|
+
this.firePreviewRendered(snapshot, generation);
|
|
2546
|
+
this.fireAssetsHydrated(snapshot, generation);
|
|
2547
|
+
}
|
|
2042
2548
|
else {
|
|
2549
|
+
this.manifestForm = null;
|
|
2043
2550
|
this.elPreviewContent.innerHTML = renderMdzipPreviewHtml(snapshot);
|
|
2044
2551
|
this.firePreviewRendered(snapshot, generation);
|
|
2045
2552
|
this.fireAssetsHydrated(snapshot, generation);
|
|
@@ -2909,7 +3416,7 @@ export class MdzipWorkspaceView {
|
|
|
2909
3416
|
html = cacheHit;
|
|
2910
3417
|
}
|
|
2911
3418
|
else {
|
|
2912
|
-
const result = this.renderingService.renderChunk(chunkTokens, context, { index: chunkIndex });
|
|
3419
|
+
const result = this.renderingService.renderChunk(chunkTokens, context, { index: chunkIndex, markBlocks: true });
|
|
2913
3420
|
html = typeof result === 'string' ? result : await result;
|
|
2914
3421
|
}
|
|
2915
3422
|
}
|
|
@@ -3298,6 +3805,7 @@ export class MdzipWorkspaceView {
|
|
|
3298
3805
|
this.restorePendingPreviewScroll(generation);
|
|
3299
3806
|
this.flushPendingAnchorSoon();
|
|
3300
3807
|
this.markPreviewMounted();
|
|
3808
|
+
this.refreshOutline();
|
|
3301
3809
|
this.firingPreviewRendered = true;
|
|
3302
3810
|
try {
|
|
3303
3811
|
this.options.onPreviewRendered?.(snapshot);
|
|
@@ -3542,6 +4050,7 @@ export class MdzipWorkspaceView {
|
|
|
3542
4050
|
doc: initialText,
|
|
3543
4051
|
extensions: [
|
|
3544
4052
|
this.lineNumbersCompartment.of(this.controlPolicy.lineNumbers ? lineNumbers() : []),
|
|
4053
|
+
this.whitespaceCompartment.of(this.whitespaceVisible ? highlightWhitespace() : []),
|
|
3545
4054
|
this.searchCompartment.of(this.controlPolicy.search ? [search({ top: true }), keymap.of(searchKeymap)] : []),
|
|
3546
4055
|
history(),
|
|
3547
4056
|
keymap.of([
|
|
@@ -3550,7 +4059,7 @@ export class MdzipWorkspaceView {
|
|
|
3550
4059
|
{ key: 'Mod-k', run: () => self.runFormatShortcut('link') }
|
|
3551
4060
|
]),
|
|
3552
4061
|
keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
|
|
3553
|
-
markdown(),
|
|
4062
|
+
this.languageCompartment.of(markdown()),
|
|
3554
4063
|
syntaxHighlighting(mdzipMarkdownHighlight),
|
|
3555
4064
|
hardBreakMarkerHighlight,
|
|
3556
4065
|
htmlTagMarkerHighlight,
|
|
@@ -3666,7 +4175,10 @@ export class MdzipWorkspaceView {
|
|
|
3666
4175
|
|| !canShowSourceLayout(snapshot)) {
|
|
3667
4176
|
return this.cmEditor;
|
|
3668
4177
|
}
|
|
4178
|
+
this.cmLanguage = 'markdown';
|
|
4179
|
+
this.jsonValidityPath = null;
|
|
3669
4180
|
this.cmEditor = this.createCmEditor(this.elEditorHost, snapshot.currentText, snapshot.mode);
|
|
4181
|
+
this.syncEditorLanguage(snapshot);
|
|
3670
4182
|
return this.cmEditor;
|
|
3671
4183
|
}
|
|
3672
4184
|
render() {
|
|
@@ -3695,6 +4207,7 @@ export class MdzipWorkspaceView {
|
|
|
3695
4207
|
this.elToolbar.hidden = true;
|
|
3696
4208
|
return;
|
|
3697
4209
|
}
|
|
4210
|
+
this.swapManifestLayout(snapshot);
|
|
3698
4211
|
this.layout = this.validLayoutForSnapshot(this.layout, snapshot);
|
|
3699
4212
|
const entryClaimed = this.syncEntryRenderer(snapshot);
|
|
3700
4213
|
const canEdit = !entryClaimed
|
|
@@ -3713,29 +4226,49 @@ export class MdzipWorkspaceView {
|
|
|
3713
4226
|
if (!showWidthControl) {
|
|
3714
4227
|
this.widthMenuOpen = false;
|
|
3715
4228
|
}
|
|
3716
|
-
|
|
3717
|
-
|
|
4229
|
+
// Only where the source editor shows: Edit or Split, for a file it can edit.
|
|
4230
|
+
const showWhitespaceControl = this.controlPolicy.whitespace && !entryClaimed
|
|
4231
|
+
&& canShowSource && this.shownLayout(snapshot) !== 'preview';
|
|
4232
|
+
const showSearchControl = this.controlPolicy.search && snapshot.currentPathType === 'markdown'
|
|
4233
|
+
&& (canShowSource || this.findApplies(snapshot));
|
|
4234
|
+
if (this.findOpen && !this.findApplies(snapshot)) {
|
|
4235
|
+
this.closeFind(false);
|
|
4236
|
+
}
|
|
4237
|
+
const showOutlineControl = this.controlPolicy.outline && !entryClaimed
|
|
4238
|
+
&& snapshot.currentPathType === 'markdown' && this.layout !== 'source';
|
|
3718
4239
|
const showEditControls = canEdit
|
|
3719
4240
|
&& snapshot.currentPathType === 'markdown'
|
|
3720
4241
|
&& this.layout !== 'preview'
|
|
3721
4242
|
&& hasFormattingControls(this.controlPolicy.formatting);
|
|
3722
4243
|
const showToolbar = this.controlPolicy.toolbar
|
|
3723
4244
|
&& (showNavigationControl || showLayoutControls || showSaveControl
|
|
3724
|
-
|| showZoomControl || showWidthControl || showColorSchemeControl || showSearchControl
|
|
3725
|
-
|| showEditControls);
|
|
4245
|
+
|| showZoomControl || showWidthControl || showColorSchemeControl || showSearchControl || showWhitespaceControl
|
|
4246
|
+
|| showOutlineControl || showEditControls);
|
|
3726
4247
|
this.elDocumentStrip.hidden = !showTitleControl;
|
|
3727
4248
|
this.elToolbar.hidden = !showToolbar;
|
|
3728
4249
|
this.elToolbarLeft.hidden = !showNavigationControl;
|
|
3729
|
-
|
|
4250
|
+
const showFormatJsonControl = canEdit && isMdzipJsonPath(snapshot.currentPath)
|
|
4251
|
+
&& this.shownLayout(snapshot) !== 'preview';
|
|
4252
|
+
this.elEditToolbar.hidden = !showEditControls && !showWhitespaceControl && !showFormatJsonControl;
|
|
4253
|
+
this.formattingShown = showEditControls;
|
|
4254
|
+
this.whitespaceControlShown = showWhitespaceControl;
|
|
4255
|
+
this.formatJsonShown = showFormatJsonControl;
|
|
3730
4256
|
this.elLayoutControls.hidden = !showLayoutControls;
|
|
3731
4257
|
this.elToolbarControls.hidden = !showSaveControl && !showZoomControl
|
|
3732
|
-
&& !showWidthControl && !showColorSchemeControl && !showSearchControl;
|
|
4258
|
+
&& !showWidthControl && !showColorSchemeControl && !showSearchControl && !showOutlineControl;
|
|
3733
4259
|
this.elNavBtn.hidden = !showNavigationControl;
|
|
3734
4260
|
this.elPreviewBtn.hidden = !this.controlPolicy.layout.preview;
|
|
3735
4261
|
this.elSplitBtn.hidden = !this.controlPolicy.layout.split;
|
|
3736
4262
|
this.elSourceBtn.hidden = !this.controlPolicy.layout.source;
|
|
3737
4263
|
this.elSaveBtn.hidden = !showSaveControl;
|
|
3738
4264
|
this.elSearchBtn.hidden = !showSearchControl;
|
|
4265
|
+
const findLabel = this.findApplies(snapshot) ? 'Find' : 'Find/replace';
|
|
4266
|
+
this.elSearchBtn.title = `${findLabel} (Mod-F)`;
|
|
4267
|
+
this.elSearchBtn.setAttribute('aria-label', findLabel);
|
|
4268
|
+
this.elWhitespaceBtn.setAttribute('aria-pressed', String(this.whitespaceVisible));
|
|
4269
|
+
this.elOutlineBtn.hidden = !showOutlineControl;
|
|
4270
|
+
this.elOutlineBtn.classList.toggle('active', this.outlineVisible);
|
|
4271
|
+
this.elOutlineBtn.setAttribute('aria-pressed', String(this.outlineVisible));
|
|
3739
4272
|
this.elZoomBtn.hidden = !showZoomControl;
|
|
3740
4273
|
this.elWidthControls.hidden = !showWidthControl;
|
|
3741
4274
|
this.elThemeControls.hidden = !showColorSchemeControl;
|
|
@@ -3768,7 +4301,10 @@ export class MdzipWorkspaceView {
|
|
|
3768
4301
|
|| !this.controlPolicy.title.editable;
|
|
3769
4302
|
this.renderMetadata(snapshot);
|
|
3770
4303
|
this.elSaveBtn.disabled = snapshot.mode === 'read-only' || !snapshot.dirty;
|
|
3771
|
-
|
|
4304
|
+
// Split only means something for Markdown: for JSON and other text the
|
|
4305
|
+
// preview would repeat the editor's text (see shownLayout).
|
|
4306
|
+
this.elSplitBtn.disabled = !this.controlPolicy.layout.split || !canShowSource
|
|
4307
|
+
|| (snapshot.currentPathType !== 'markdown' && !this.isManifestFormPath(snapshot));
|
|
3772
4308
|
this.elSourceBtn.disabled = !this.controlPolicy.layout.source || !canShowSource;
|
|
3773
4309
|
this.renderFormattingControls();
|
|
3774
4310
|
// Update button labels based on mode
|
|
@@ -3783,11 +4319,12 @@ export class MdzipWorkspaceView {
|
|
|
3783
4319
|
this.elSourceIcon.innerHTML = SOURCE_EDIT_ICON_HTML;
|
|
3784
4320
|
}
|
|
3785
4321
|
this.elPreviewBtn.classList.toggle('active', this.layout === 'preview');
|
|
3786
|
-
this.
|
|
3787
|
-
this.
|
|
4322
|
+
const shownLayout = this.shownLayout(snapshot);
|
|
4323
|
+
this.elSplitBtn.classList.toggle('active', shownLayout === 'split');
|
|
4324
|
+
this.elSourceBtn.classList.toggle('active', shownLayout === 'source');
|
|
3788
4325
|
this.elPreviewBtn.setAttribute('aria-pressed', String(this.layout === 'preview'));
|
|
3789
|
-
this.elSplitBtn.setAttribute('aria-pressed', String(
|
|
3790
|
-
this.elSourceBtn.setAttribute('aria-pressed', String(
|
|
4326
|
+
this.elSplitBtn.setAttribute('aria-pressed', String(shownLayout === 'split'));
|
|
4327
|
+
this.elSourceBtn.setAttribute('aria-pressed', String(shownLayout === 'source'));
|
|
3791
4328
|
if (snapshot.sourceFormat === 'markdown') {
|
|
3792
4329
|
this.elNavBtn.innerHTML = CONVERT_TO_MDZ_ICON_HTML;
|
|
3793
4330
|
this.elNavBtn.classList.remove('active');
|
|
@@ -3873,11 +4410,14 @@ export class MdzipWorkspaceView {
|
|
|
3873
4410
|
allowOrphanActions,
|
|
3874
4411
|
allowFileActions,
|
|
3875
4412
|
allowDrag: snapshot.mode !== 'read-only' && snapshot.sourceFormat === 'mdz',
|
|
3876
|
-
pendingFolders: new Set(this.pendingNewFolders)
|
|
4413
|
+
pendingFolders: new Set(this.pendingNewFolders),
|
|
4414
|
+
selected: new Set(this.navSelection),
|
|
4415
|
+
collapsed: this.navCollapsed
|
|
3877
4416
|
};
|
|
3878
4417
|
this.elNavTree.innerHTML = navTree
|
|
3879
4418
|
.map((n, i) => renderNavNode(n, snapshot, navRenderOptions, [], i === navTree.length - 1, 0))
|
|
3880
4419
|
.join('');
|
|
4420
|
+
this.syncNavSelection();
|
|
3881
4421
|
this.prepareTooltips();
|
|
3882
4422
|
if (this.cmEditor) {
|
|
3883
4423
|
this.updatingCm = true;
|
|
@@ -3891,17 +4431,21 @@ export class MdzipWorkspaceView {
|
|
|
3891
4431
|
this.cmEditor.dispatch({
|
|
3892
4432
|
effects: this.readOnlyCompartment.reconfigure(EditorState.readOnly.of(snapshot.mode === 'read-only'))
|
|
3893
4433
|
});
|
|
4434
|
+
this.syncEditorLanguage(snapshot);
|
|
3894
4435
|
}
|
|
3895
4436
|
this.updatePreview(snapshot, entryClaimed);
|
|
3896
4437
|
const pt = snapshot.currentPathType;
|
|
3897
|
-
const
|
|
3898
|
-
const
|
|
3899
|
-
|
|
4438
|
+
const shown = this.shownLayout(snapshot);
|
|
4439
|
+
const showEdit = !entryClaimed && (pt === 'markdown' || pt === 'text') && shown !== 'preview';
|
|
4440
|
+
// A text file's preview is its text as-is: shown in View, not beside the editor.
|
|
4441
|
+
const showPreview = !entryClaimed && (pt === 'image' || pt === 'binary'
|
|
4442
|
+
|| ((pt === 'markdown' || pt === 'text') && shown !== 'source'));
|
|
3900
4443
|
this.elEditPane.classList.toggle('active', showEdit);
|
|
3901
4444
|
this.elPreviewPane.classList.toggle('active', showPreview);
|
|
3902
4445
|
this.elEntryPane.classList.toggle('active', entryClaimed);
|
|
3903
|
-
this.elPaneStack.classList.toggle('split-mode',
|
|
4446
|
+
this.elPaneStack.classList.toggle('split-mode', shown === 'split' && !entryClaimed);
|
|
3904
4447
|
this.elPaneStack.classList.toggle('entry-claimed', entryClaimed);
|
|
4448
|
+
this.syncOutlinePane(this.outlineVisible && !entryClaimed && pt === 'markdown' && this.layout !== 'source');
|
|
3905
4449
|
if (!showTitleControl) {
|
|
3906
4450
|
this.titleDialogOpen = false;
|
|
3907
4451
|
this.metadataDialogOpen = false;
|
|
@@ -3992,6 +4536,12 @@ export class MdzipWorkspaceView {
|
|
|
3992
4536
|
this.elNameValidation.textContent = this.nameDialogState.error;
|
|
3993
4537
|
this.elNameConfirmBtn.disabled = Boolean(this.nameDialogState.error);
|
|
3994
4538
|
}
|
|
4539
|
+
this.elConfirmDialog.hidden = this.confirmDialogState === null;
|
|
4540
|
+
if (this.confirmDialogState) {
|
|
4541
|
+
this.elConfirmDialogTitle.textContent = this.confirmDialogState.title;
|
|
4542
|
+
this.elConfirmDialogText.textContent = this.confirmDialogState.text;
|
|
4543
|
+
this.elConfirmDialogOk.textContent = this.confirmDialogState.confirm;
|
|
4544
|
+
}
|
|
3995
4545
|
this.elDeleteDialog.hidden = this.deleteDialogState === null;
|
|
3996
4546
|
if (this.deleteDialogState) {
|
|
3997
4547
|
this.elDeleteDialogText.textContent =
|
|
@@ -4039,6 +4589,9 @@ export class MdzipWorkspaceView {
|
|
|
4039
4589
|
if (this.widthMenuOpen) {
|
|
4040
4590
|
this.closeWidthMenu(true);
|
|
4041
4591
|
}
|
|
4592
|
+
if (this.confirmDialogState) {
|
|
4593
|
+
this.answerConfirm(false);
|
|
4594
|
+
}
|
|
4042
4595
|
if (this.contextMenuState || this.deleteDialogState || this.nameDialogState) {
|
|
4043
4596
|
this.contextMenuState = null;
|
|
4044
4597
|
this.deleteDialogState = null;
|
|
@@ -4121,7 +4674,74 @@ export class MdzipWorkspaceView {
|
|
|
4121
4674
|
}
|
|
4122
4675
|
});
|
|
4123
4676
|
this.elSearchBtn.addEventListener('click', () => {
|
|
4124
|
-
|
|
4677
|
+
if (this.findOpen) {
|
|
4678
|
+
this.closeFind();
|
|
4679
|
+
}
|
|
4680
|
+
else {
|
|
4681
|
+
void this.openSearch();
|
|
4682
|
+
}
|
|
4683
|
+
});
|
|
4684
|
+
this.elFindInput.addEventListener('input', () => {
|
|
4685
|
+
this.refreshFind('viewport');
|
|
4686
|
+
this.revealFindMatchSoon();
|
|
4687
|
+
});
|
|
4688
|
+
this.elFindInput.addEventListener('keydown', (event) => {
|
|
4689
|
+
if (event.key === 'Enter') {
|
|
4690
|
+
event.preventDefault();
|
|
4691
|
+
void this.moveFind(event.shiftKey ? -1 : 1);
|
|
4692
|
+
}
|
|
4693
|
+
else if (event.key === 'Escape') {
|
|
4694
|
+
event.preventDefault();
|
|
4695
|
+
event.stopPropagation();
|
|
4696
|
+
this.closeFind();
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4699
|
+
this.elFindCase.addEventListener('click', () => {
|
|
4700
|
+
this.findMatchCase = !this.findMatchCase;
|
|
4701
|
+
this.elFindCase.setAttribute('aria-pressed', String(this.findMatchCase));
|
|
4702
|
+
this.refreshFind('viewport');
|
|
4703
|
+
this.revealFindMatchSoon();
|
|
4704
|
+
this.elFindInput.focus();
|
|
4705
|
+
});
|
|
4706
|
+
this.elFindPrevious.addEventListener('click', () => { void this.moveFind(-1); });
|
|
4707
|
+
this.elFindNext.addEventListener('click', () => { void this.moveFind(1); });
|
|
4708
|
+
this.elFindClose.addEventListener('click', () => { this.closeFind(); });
|
|
4709
|
+
// Ctrl/Cmd+F in the View layout opens the find bar instead of the
|
|
4710
|
+
// browser's, which can't see chunks not drawn yet; F3 / Shift+F3 move
|
|
4711
|
+
// and Escape closes while it's open.
|
|
4712
|
+
doc.addEventListener('keydown', (e) => {
|
|
4713
|
+
if (this.destroyed) {
|
|
4714
|
+
return;
|
|
4715
|
+
}
|
|
4716
|
+
const focused = doc.activeElement;
|
|
4717
|
+
const inView = !!focused && this.elRoot.contains(focused);
|
|
4718
|
+
const key = e.key.toLowerCase();
|
|
4719
|
+
if (key === 'f' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
|
|
4720
|
+
if (inView && this.findApplies()) {
|
|
4721
|
+
e.preventDefault();
|
|
4722
|
+
this.openFind();
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
else if (e.key === 'F3' && this.findOpen && inView) {
|
|
4726
|
+
e.preventDefault();
|
|
4727
|
+
void this.moveFind(e.shiftKey ? -1 : 1);
|
|
4728
|
+
}
|
|
4729
|
+
else if (e.key === 'Escape' && this.findOpen && !!focused && this.elPreviewPane.contains(focused)) {
|
|
4730
|
+
e.preventDefault();
|
|
4731
|
+
this.closeFind();
|
|
4732
|
+
}
|
|
4733
|
+
});
|
|
4734
|
+
this.elOutlineBtn.addEventListener('click', () => {
|
|
4735
|
+
this.setOutlineVisible(!this.outlineVisible);
|
|
4736
|
+
this.options.onOutlineVisibilityChanged?.(this.outlineVisible);
|
|
4737
|
+
});
|
|
4738
|
+
this.elFormatJsonBtn.addEventListener('click', () => {
|
|
4739
|
+
this.formatJson();
|
|
4740
|
+
this.cmEditor?.focus();
|
|
4741
|
+
});
|
|
4742
|
+
this.elWhitespaceBtn.addEventListener('click', () => {
|
|
4743
|
+
this.setWhitespaceVisible(!this.whitespaceVisible);
|
|
4744
|
+
this.options.onWhitespaceVisibilityChanged?.(this.whitespaceVisible);
|
|
4125
4745
|
});
|
|
4126
4746
|
this.elZoomBtn.addEventListener('click', (e) => {
|
|
4127
4747
|
if (!this.controlPolicy.zoom) {
|
|
@@ -4247,21 +4867,85 @@ export class MdzipWorkspaceView {
|
|
|
4247
4867
|
this.showNavMenuForPath(orphanBtn.getAttribute('data-orphan-path'), e);
|
|
4248
4868
|
return;
|
|
4249
4869
|
}
|
|
4870
|
+
const key = navRowKey(target);
|
|
4871
|
+
if (key && (e.ctrlKey || e.metaKey || e.shiftKey)) {
|
|
4872
|
+
// Selecting, not opening (or, on a folder, not opening or closing it).
|
|
4873
|
+
e.preventDefault();
|
|
4874
|
+
if (e.shiftKey) {
|
|
4875
|
+
this.selectNavRange(key, e.ctrlKey || e.metaKey);
|
|
4876
|
+
}
|
|
4877
|
+
else {
|
|
4878
|
+
this.navSelection = this.navSelection.includes(key)
|
|
4879
|
+
? this.navSelection.filter((item) => item !== key)
|
|
4880
|
+
: [...this.navSelection, key];
|
|
4881
|
+
this.navSelectionAnchor = key;
|
|
4882
|
+
}
|
|
4883
|
+
this.syncNavSelection();
|
|
4884
|
+
return;
|
|
4885
|
+
}
|
|
4886
|
+
if (key) {
|
|
4887
|
+
this.navSelection = [key];
|
|
4888
|
+
this.navSelectionAnchor = key;
|
|
4889
|
+
this.syncNavSelection();
|
|
4890
|
+
}
|
|
4250
4891
|
const navFile = target.closest('[data-nav-path]');
|
|
4251
4892
|
if (navFile) {
|
|
4252
4893
|
void this.openPath(navFile.getAttribute('data-nav-path'));
|
|
4253
4894
|
}
|
|
4254
4895
|
});
|
|
4896
|
+
// Remember closed folders: the tree is redrawn on every change.
|
|
4897
|
+
this.elNavTree.addEventListener('toggle', (e) => {
|
|
4898
|
+
const details = e.target;
|
|
4899
|
+
if (!(details instanceof HTMLElement) || !details.matches('details[data-nav-dir]')) {
|
|
4900
|
+
return;
|
|
4901
|
+
}
|
|
4902
|
+
const path = details.getAttribute('data-nav-dir') ?? '';
|
|
4903
|
+
if (details.open) {
|
|
4904
|
+
this.navCollapsed.delete(path);
|
|
4905
|
+
}
|
|
4906
|
+
else {
|
|
4907
|
+
this.navCollapsed.add(path);
|
|
4908
|
+
}
|
|
4909
|
+
}, true);
|
|
4255
4910
|
this.elNavPane.addEventListener('contextmenu', (e) => {
|
|
4256
|
-
|
|
4911
|
+
let target = this.navMenuTargetFromElement(e.target);
|
|
4257
4912
|
if (!target) {
|
|
4258
4913
|
return;
|
|
4259
4914
|
}
|
|
4260
4915
|
e.preventDefault();
|
|
4261
4916
|
e.stopPropagation();
|
|
4917
|
+
// Right-clicking a row outside the selection selects just that row, as
|
|
4918
|
+
// file managers do; inside a selection of several, the menu is for all.
|
|
4919
|
+
const key = navRowKey(e.target);
|
|
4920
|
+
if (key && !this.navSelection.includes(key)) {
|
|
4921
|
+
this.navSelection = [key];
|
|
4922
|
+
this.navSelectionAnchor = key;
|
|
4923
|
+
this.syncNavSelection();
|
|
4924
|
+
}
|
|
4925
|
+
else if (key && this.navSelection.length > 1) {
|
|
4926
|
+
target = {
|
|
4927
|
+
kind: 'selection',
|
|
4928
|
+
files: this.navSelection.filter((item) => item.startsWith('f:')).map((item) => item.slice(2)),
|
|
4929
|
+
folders: this.navSelection.filter((item) => item.startsWith('d:')).map((item) => item.slice(2))
|
|
4930
|
+
};
|
|
4931
|
+
}
|
|
4262
4932
|
this.showNavMenu(target, e);
|
|
4263
4933
|
});
|
|
4264
4934
|
this.elNavTree.addEventListener('keydown', (e) => {
|
|
4935
|
+
if (e.key.toLowerCase() === 'a' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
|
|
4936
|
+
e.preventDefault();
|
|
4937
|
+
this.navSelection = this.navRowKeys();
|
|
4938
|
+
this.navSelectionAnchor = this.navSelection[0] ?? null;
|
|
4939
|
+
this.syncNavSelection();
|
|
4940
|
+
return;
|
|
4941
|
+
}
|
|
4942
|
+
if (e.key === 'Escape' && this.navSelection.length > 1) {
|
|
4943
|
+
e.preventDefault();
|
|
4944
|
+
this.navSelection = [];
|
|
4945
|
+
this.navSelectionAnchor = null;
|
|
4946
|
+
this.syncNavSelection();
|
|
4947
|
+
return;
|
|
4948
|
+
}
|
|
4265
4949
|
if (e.key === 'Enter') {
|
|
4266
4950
|
const orphanBtn = e.target.closest('[data-orphan-path]');
|
|
4267
4951
|
if (this.controlPolicy.orphanActions && orphanBtn) {
|
|
@@ -4292,6 +4976,35 @@ export class MdzipWorkspaceView {
|
|
|
4292
4976
|
window.addEventListener('pointermove', onMove);
|
|
4293
4977
|
window.addEventListener('pointerup', onUp, { once: true });
|
|
4294
4978
|
});
|
|
4979
|
+
// The outline's edge: it's on the document side of the panel, so dragging
|
|
4980
|
+
// toward the document widens it on either side.
|
|
4981
|
+
this.elOutlineResizer.addEventListener('pointerdown', (e) => {
|
|
4982
|
+
if (e.button !== 0) {
|
|
4983
|
+
return;
|
|
4984
|
+
}
|
|
4985
|
+
e.preventDefault();
|
|
4986
|
+
this.resizing = true;
|
|
4987
|
+
this.elRoot.classList.add('resizing');
|
|
4988
|
+
const start = this.outlineWidth;
|
|
4989
|
+
const onMove = (me) => {
|
|
4990
|
+
const shell = this.elWorkspaceShell.getBoundingClientRect();
|
|
4991
|
+
const pane = this.elOutlinePane.getBoundingClientRect();
|
|
4992
|
+
const raw = this.outlinePosition === 'left' ? me.clientX - pane.left : pane.right - me.clientX;
|
|
4993
|
+
const max = Math.max(200, Math.floor(shell.width * 0.5));
|
|
4994
|
+
this.outlineWidth = Math.max(160, Math.min(max, Math.round(raw)));
|
|
4995
|
+
this.syncOutlineGeometry();
|
|
4996
|
+
};
|
|
4997
|
+
const onUp = () => {
|
|
4998
|
+
this.resizing = false;
|
|
4999
|
+
this.elRoot.classList.remove('resizing');
|
|
5000
|
+
window.removeEventListener('pointermove', onMove);
|
|
5001
|
+
if (this.outlineWidth !== null && this.outlineWidth !== start) {
|
|
5002
|
+
this.options.onOutlineWidthChanged?.(this.outlineWidth);
|
|
5003
|
+
}
|
|
5004
|
+
};
|
|
5005
|
+
window.addEventListener('pointermove', onMove);
|
|
5006
|
+
window.addEventListener('pointerup', onUp, { once: true });
|
|
5007
|
+
});
|
|
4295
5008
|
this.elSplitResizer.addEventListener('pointerdown', (e) => {
|
|
4296
5009
|
if (e.button !== 0 || this.layout !== 'split') {
|
|
4297
5010
|
return;
|
|
@@ -4562,6 +5275,9 @@ export class MdzipWorkspaceView {
|
|
|
4562
5275
|
this.elNameConfirmBtn.addEventListener('click', () => {
|
|
4563
5276
|
void this.confirmNameDialog();
|
|
4564
5277
|
});
|
|
5278
|
+
this.elConfirmDialog.querySelector('[data-action="cancel-confirm"]')
|
|
5279
|
+
.addEventListener('click', () => this.answerConfirm(false));
|
|
5280
|
+
this.elConfirmDialogOk.addEventListener('click', () => this.answerConfirm(true));
|
|
4565
5281
|
this.elDeleteDialog.querySelector('[data-action="cancel-delete"]')
|
|
4566
5282
|
.addEventListener('click', () => {
|
|
4567
5283
|
this.deleteDialogState = null;
|
|
@@ -4732,8 +5448,11 @@ export class MdzipWorkspaceView {
|
|
|
4732
5448
|
* anchor (`''` and `'top'` scroll to the top and resolve `true`), and
|
|
4733
5449
|
* `false` when nothing matches, an entry renderer owns the pane, or the
|
|
4734
5450
|
* view is destroyed first.
|
|
5451
|
+
*
|
|
5452
|
+
* `{ smooth: true }` glides there instead of jumping, as an outline click
|
|
5453
|
+
* does; it jumps anyway when the user asked for reduced motion.
|
|
4735
5454
|
*/
|
|
4736
|
-
async scrollToAnchor(anchor) {
|
|
5455
|
+
async scrollToAnchor(anchor, options = {}) {
|
|
4737
5456
|
const fragment = anchor.startsWith('#') ? anchor.slice(1) : anchor;
|
|
4738
5457
|
// onPreviewRendered runs inside the first chunk batch's completion,
|
|
4739
5458
|
// before the lazy-continuation sentinel is armed — same race as
|
|
@@ -4754,15 +5473,142 @@ export class MdzipWorkspaceView {
|
|
|
4754
5473
|
return false;
|
|
4755
5474
|
}
|
|
4756
5475
|
if (generation !== this.previewGeneration) {
|
|
4757
|
-
return this.scrollToAnchor(anchor);
|
|
5476
|
+
return this.scrollToAnchor(anchor, options);
|
|
4758
5477
|
}
|
|
4759
5478
|
}
|
|
4760
5479
|
if (this.entryState) {
|
|
4761
5480
|
return false;
|
|
4762
5481
|
}
|
|
4763
|
-
const found = await this.scrollPreviewToAnchor(fragment);
|
|
5482
|
+
const found = await this.scrollPreviewToAnchor(fragment, options.smooth === true && !this.prefersReducedMotion());
|
|
4764
5483
|
return found || !fragment || fragment.toLowerCase() === 'top';
|
|
4765
5484
|
}
|
|
5485
|
+
/** Whether the outline panel is switched on (it shows while a Markdown preview is visible). */
|
|
5486
|
+
get isOutlineVisible() {
|
|
5487
|
+
return this.outlineVisible;
|
|
5488
|
+
}
|
|
5489
|
+
/** Whether spaces and tabs are shown in the source editor. */
|
|
5490
|
+
get isWhitespaceVisible() {
|
|
5491
|
+
return this.whitespaceVisible;
|
|
5492
|
+
}
|
|
5493
|
+
/** Shows or hides spaces and tabs in the source editor, as the ¶ toolbar button does (without calling `onWhitespaceVisibilityChanged`). */
|
|
5494
|
+
setWhitespaceVisible(visible) {
|
|
5495
|
+
if (this.whitespaceVisible === visible) {
|
|
5496
|
+
return;
|
|
5497
|
+
}
|
|
5498
|
+
this.whitespaceVisible = visible;
|
|
5499
|
+
this.cmEditor?.dispatch({
|
|
5500
|
+
effects: this.whitespaceCompartment.reconfigure(visible ? highlightWhitespace() : [])
|
|
5501
|
+
});
|
|
5502
|
+
this.render();
|
|
5503
|
+
}
|
|
5504
|
+
/** Shows or hides the outline panel, as its toolbar button does (without calling `onOutlineVisibilityChanged`). */
|
|
5505
|
+
setOutlineVisible(visible) {
|
|
5506
|
+
if (this.outlineVisible === visible) {
|
|
5507
|
+
return;
|
|
5508
|
+
}
|
|
5509
|
+
this.outlineVisible = visible;
|
|
5510
|
+
this.render();
|
|
5511
|
+
}
|
|
5512
|
+
/** Which side of the document the outline panel is on. */
|
|
5513
|
+
get outlineSide() {
|
|
5514
|
+
return this.outlinePosition;
|
|
5515
|
+
}
|
|
5516
|
+
/** Puts the outline panel on the left or the right of the document. */
|
|
5517
|
+
setOutlinePosition(position) {
|
|
5518
|
+
this.outlinePosition = position === 'left' ? 'left' : 'right';
|
|
5519
|
+
this.syncOutlineGeometry();
|
|
5520
|
+
}
|
|
5521
|
+
/** The outline panel's width in pixels, as last set or dragged; null while the style sheet's width applies. */
|
|
5522
|
+
get outlinePaneWidth() {
|
|
5523
|
+
return this.outlineWidth;
|
|
5524
|
+
}
|
|
5525
|
+
syncOutlineGeometry() {
|
|
5526
|
+
this.elRoot.classList.toggle('outline-left', this.outlinePosition === 'left');
|
|
5527
|
+
if (this.outlineWidth === null) {
|
|
5528
|
+
this.elRoot.style.removeProperty('--mdzip-outline-pane-width');
|
|
5529
|
+
}
|
|
5530
|
+
else {
|
|
5531
|
+
this.elRoot.style.setProperty('--mdzip-outline-pane-width', `${this.outlineWidth}px`);
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
syncOutlinePane(show) {
|
|
5535
|
+
this.elRoot.classList.toggle('outline-pane-visible', show);
|
|
5536
|
+
this.syncOutlineGeometry();
|
|
5537
|
+
if (!show) {
|
|
5538
|
+
this.elOutlinePane.hidden = true;
|
|
5539
|
+
this.outline?.destroy();
|
|
5540
|
+
this.outline = null;
|
|
5541
|
+
return;
|
|
5542
|
+
}
|
|
5543
|
+
if (!this.outline) {
|
|
5544
|
+
// The outline hides its container while the document has no headings.
|
|
5545
|
+
this.outline = createMdzipHeadingOutline({
|
|
5546
|
+
content: this.elPreviewContent,
|
|
5547
|
+
container: this.elOutlinePane,
|
|
5548
|
+
scrollContainer: this.elPreviewPane,
|
|
5549
|
+
label: this.outlineOptions.label ?? 'Outline',
|
|
5550
|
+
collapse: this.outlineOptions.collapse,
|
|
5551
|
+
offset: 64,
|
|
5552
|
+
headings: () => this.outlineHeadings(),
|
|
5553
|
+
findElement: (heading) => this.findOutlineElement(heading),
|
|
5554
|
+
onNavigate: (heading, event) => {
|
|
5555
|
+
event.preventDefault();
|
|
5556
|
+
void this.scrollToAnchor(heading.id, { smooth: true });
|
|
5557
|
+
}
|
|
5558
|
+
});
|
|
5559
|
+
this.outlineGeneration = this.previewMountedGeneration;
|
|
5560
|
+
}
|
|
5561
|
+
else if (this.outlineGeneration !== this.previewMountedGeneration) {
|
|
5562
|
+
this.refreshOutline();
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
/** Rebuilds the outline after the preview renders a new version of the document. */
|
|
5566
|
+
refreshOutline() {
|
|
5567
|
+
if (!this.outline) {
|
|
5568
|
+
return;
|
|
5569
|
+
}
|
|
5570
|
+
this.outlineGeneration = this.previewMountedGeneration;
|
|
5571
|
+
this.outline.refresh();
|
|
5572
|
+
}
|
|
5573
|
+
/**
|
|
5574
|
+
* The document's headings for the outline, ids without the
|
|
5575
|
+
* `user-content-` prefix. Under progressive rendering they come from the
|
|
5576
|
+
* chunks' tokens, so headings in chunks that aren't mounted yet are listed
|
|
5577
|
+
* too (without an element until they mount).
|
|
5578
|
+
*/
|
|
5579
|
+
outlineHeadings() {
|
|
5580
|
+
if (this.entryState) {
|
|
5581
|
+
return [];
|
|
5582
|
+
}
|
|
5583
|
+
const levels = new Set(this.outlineOptions.levels ?? [1, 2, 3]);
|
|
5584
|
+
const state = this.chunkedRenderState;
|
|
5585
|
+
if (state && state.generation === this.previewGeneration) {
|
|
5586
|
+
return state.records
|
|
5587
|
+
.flatMap((record) => collectMdzipHeadings(record.tokens))
|
|
5588
|
+
.filter((heading) => levels.has(heading.level))
|
|
5589
|
+
.map((heading) => ({ ...heading, element: null }));
|
|
5590
|
+
}
|
|
5591
|
+
const headings = [];
|
|
5592
|
+
for (const element of Array.from(this.elPreviewContent.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]'))) {
|
|
5593
|
+
const level = Number(element.tagName[1]);
|
|
5594
|
+
// Only the document's own headings: not the footnotes section's label, say.
|
|
5595
|
+
if (!levels.has(level) || !element.id.startsWith(MDZIP_HEADING_ID_PREFIX))
|
|
5596
|
+
continue;
|
|
5597
|
+
const text = (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
5598
|
+
if (text) {
|
|
5599
|
+
headings.push({ id: element.id.slice(MDZIP_HEADING_ID_PREFIX.length), text, level, element });
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
return headings;
|
|
5603
|
+
}
|
|
5604
|
+
findOutlineElement(heading) {
|
|
5605
|
+
const id = MDZIP_HEADING_ID_PREFIX + heading.id;
|
|
5606
|
+
for (const element of Array.from(this.elPreviewContent.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]'))) {
|
|
5607
|
+
if (element.id === id)
|
|
5608
|
+
return element;
|
|
5609
|
+
}
|
|
5610
|
+
return null;
|
|
5611
|
+
}
|
|
4766
5612
|
/**
|
|
4767
5613
|
* The anchors {@link scrollToAnchor} can reach in the current preview, in
|
|
4768
5614
|
* document order: every heading id (without the `user-content-` prefix),
|
|
@@ -4860,7 +5706,15 @@ export class MdzipWorkspaceView {
|
|
|
4860
5706
|
* a chunk that hasn't been mounted yet, so this mounts everything up to and
|
|
4861
5707
|
* including that chunk first. Returns whether an anchor was found.
|
|
4862
5708
|
*/
|
|
4863
|
-
|
|
5709
|
+
prefersReducedMotion() {
|
|
5710
|
+
try {
|
|
5711
|
+
return this.elRoot.ownerDocument.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
5712
|
+
}
|
|
5713
|
+
catch {
|
|
5714
|
+
return false;
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
async scrollPreviewToAnchor(rawFragment, smooth = false) {
|
|
4864
5718
|
let fragment = rawFragment;
|
|
4865
5719
|
try {
|
|
4866
5720
|
fragment = decodeURIComponent(rawFragment);
|
|
@@ -4886,17 +5740,76 @@ export class MdzipWorkspaceView {
|
|
|
4886
5740
|
if (!target) {
|
|
4887
5741
|
// `#` and `#top` mean the top of the document, as in a browser.
|
|
4888
5742
|
if (!fragment || fragment.toLowerCase() === 'top') {
|
|
4889
|
-
|
|
5743
|
+
this.releaseAnchorPin();
|
|
5744
|
+
if (smooth) {
|
|
5745
|
+
this.glidePreviewTo(() => 0);
|
|
5746
|
+
}
|
|
5747
|
+
else {
|
|
5748
|
+
pane.scrollTop = 0;
|
|
5749
|
+
}
|
|
4890
5750
|
}
|
|
4891
5751
|
return false;
|
|
4892
5752
|
}
|
|
4893
|
-
|
|
5753
|
+
// Pin first: pinning releases any earlier pin, and with it a glide.
|
|
4894
5754
|
this.pinPreviewAnchor(target);
|
|
5755
|
+
if (smooth) {
|
|
5756
|
+
this.glidePreviewTo(() => this.paneTopOf(target));
|
|
5757
|
+
}
|
|
5758
|
+
else {
|
|
5759
|
+
this.scrollPaneToElement(target);
|
|
5760
|
+
}
|
|
4895
5761
|
return true;
|
|
4896
5762
|
}
|
|
5763
|
+
paneTopOf(target) {
|
|
5764
|
+
const pane = this.elPreviewPane;
|
|
5765
|
+
return pane.scrollTop + target.getBoundingClientRect().top - pane.getBoundingClientRect().top;
|
|
5766
|
+
}
|
|
4897
5767
|
scrollPaneToElement(target) {
|
|
5768
|
+
this.elPreviewPane.scrollTop = this.paneTopOf(target);
|
|
5769
|
+
this.syncScrollFromPreview(true);
|
|
5770
|
+
}
|
|
5771
|
+
/**
|
|
5772
|
+
* Scrolls the preview to `targetTop()` over a few hundred milliseconds.
|
|
5773
|
+
* The target is measured again every frame, so images loading above it
|
|
5774
|
+
* while it moves bend the path instead of restarting it (the browser's
|
|
5775
|
+
* own smooth scroll restarts on every change and stutters). A wheel,
|
|
5776
|
+
* touch or click in the pane stops it, as it releases the anchor pin.
|
|
5777
|
+
*/
|
|
5778
|
+
glidePreviewTo(targetTop) {
|
|
5779
|
+
this.cancelPreviewGlide();
|
|
4898
5780
|
const pane = this.elPreviewPane;
|
|
4899
|
-
|
|
5781
|
+
const start = pane.scrollTop;
|
|
5782
|
+
const distance = Math.abs(targetTop() - start);
|
|
5783
|
+
if (distance < 2) {
|
|
5784
|
+
pane.scrollTop = targetTop();
|
|
5785
|
+
this.syncScrollFromPreview(true);
|
|
5786
|
+
return;
|
|
5787
|
+
}
|
|
5788
|
+
// Longer for longer trips, within limits that still feel quick.
|
|
5789
|
+
const duration = Math.min(700, 250 + distance * 0.12);
|
|
5790
|
+
const startTime = performance.now();
|
|
5791
|
+
// performance.now(), not the frame's timestamp: the two can count from
|
|
5792
|
+
// different origins (another window's requestAnimationFrame, jsdom).
|
|
5793
|
+
const step = () => {
|
|
5794
|
+
const now = performance.now();
|
|
5795
|
+
if (this.destroyed) {
|
|
5796
|
+
this.previewGlide = null;
|
|
5797
|
+
return;
|
|
5798
|
+
}
|
|
5799
|
+
const t = Math.min(1, Math.max(0, (now - startTime) / duration));
|
|
5800
|
+
const eased = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
5801
|
+
pane.scrollTop = start + (targetTop() - start) * eased;
|
|
5802
|
+
// In Split, the source follows along.
|
|
5803
|
+
this.syncScrollFromPreview(true);
|
|
5804
|
+
this.previewGlide = t < 1 ? requestAnimationFrame(step) : null;
|
|
5805
|
+
};
|
|
5806
|
+
this.previewGlide = requestAnimationFrame(step);
|
|
5807
|
+
}
|
|
5808
|
+
cancelPreviewGlide() {
|
|
5809
|
+
if (this.previewGlide !== null) {
|
|
5810
|
+
cancelAnimationFrame(this.previewGlide);
|
|
5811
|
+
this.previewGlide = null;
|
|
5812
|
+
}
|
|
4900
5813
|
}
|
|
4901
5814
|
/** See `anchorPin`. */
|
|
4902
5815
|
pinPreviewAnchor(target) {
|
|
@@ -4910,12 +5823,16 @@ export class MdzipWorkspaceView {
|
|
|
4910
5823
|
this.releaseAnchorPin();
|
|
4911
5824
|
return;
|
|
4912
5825
|
}
|
|
4913
|
-
this.
|
|
5826
|
+
if (this.previewGlide === null) {
|
|
5827
|
+
// While gliding, each frame measures the target again anyway.
|
|
5828
|
+
this.scrollPaneToElement(target);
|
|
5829
|
+
}
|
|
4914
5830
|
});
|
|
4915
5831
|
observer.observe(this.elPreviewContent);
|
|
4916
5832
|
this.anchorPin = observer;
|
|
4917
5833
|
}
|
|
4918
5834
|
releaseAnchorPin() {
|
|
5835
|
+
this.cancelPreviewGlide();
|
|
4919
5836
|
this.anchorPin?.disconnect();
|
|
4920
5837
|
this.anchorPin = null;
|
|
4921
5838
|
}
|
|
@@ -5099,9 +6016,160 @@ export class MdzipWorkspaceView {
|
|
|
5099
6016
|
this.render();
|
|
5100
6017
|
}
|
|
5101
6018
|
catch (error) {
|
|
6019
|
+
if (error instanceof MdzipManifestInvalidError) {
|
|
6020
|
+
await this.showManifestProblems(error.validity);
|
|
6021
|
+
}
|
|
5102
6022
|
this.options.onFailed?.(error);
|
|
5103
6023
|
}
|
|
5104
6024
|
}
|
|
6025
|
+
// Saving is blocked by an invalid manifest: show it, with its problems,
|
|
6026
|
+
// wherever the user is, so they can see what to fix.
|
|
6027
|
+
async showManifestProblems(validity) {
|
|
6028
|
+
const snapshot = this.workspace?.snapshot();
|
|
6029
|
+
if (snapshot && !isMdzipRootManifestPath(snapshot.currentPath)) {
|
|
6030
|
+
await this.openPath('manifest.json');
|
|
6031
|
+
}
|
|
6032
|
+
this.setJsonValidity(validity, 'manifest.json');
|
|
6033
|
+
if (this.layout !== 'source' && this.manifestForm) {
|
|
6034
|
+
// The form shows each problem under its field.
|
|
6035
|
+
this.manifestForm.flash();
|
|
6036
|
+
return;
|
|
6037
|
+
}
|
|
6038
|
+
this.elJsonStatus.classList.remove('flash');
|
|
6039
|
+
void this.elJsonStatus.offsetWidth;
|
|
6040
|
+
this.elJsonStatus.classList.add('flash');
|
|
6041
|
+
}
|
|
6042
|
+
/**
|
|
6043
|
+
* Re-indents the open JSON file (2 spaces), changing only whitespace, as
|
|
6044
|
+
* the toolbar's Format JSON button and Shift+Alt+F do. One undo step.
|
|
6045
|
+
* Returns `false` when no JSON file is open in an editable editor or its
|
|
6046
|
+
* text isn't valid JSON.
|
|
6047
|
+
*/
|
|
6048
|
+
formatJson() {
|
|
6049
|
+
const editor = this.cmEditor;
|
|
6050
|
+
const snapshot = this.workspace?.snapshot();
|
|
6051
|
+
if (!editor || !snapshot || snapshot.mode === 'read-only' || !isMdzipJsonPath(snapshot.currentPath)) {
|
|
6052
|
+
return false;
|
|
6053
|
+
}
|
|
6054
|
+
const text = editor.state.doc.toString();
|
|
6055
|
+
const formatted = formatMdzipJsonText(text);
|
|
6056
|
+
if (formatted === null) {
|
|
6057
|
+
return false;
|
|
6058
|
+
}
|
|
6059
|
+
if (formatted !== text) {
|
|
6060
|
+
// Replace only what differs, so the cursor keeps its place where it can.
|
|
6061
|
+
let start = 0;
|
|
6062
|
+
while (start < text.length && start < formatted.length && text[start] === formatted[start])
|
|
6063
|
+
start += 1;
|
|
6064
|
+
let end = 0;
|
|
6065
|
+
while (end < text.length - start && end < formatted.length - start
|
|
6066
|
+
&& text[text.length - 1 - end] === formatted[formatted.length - 1 - end])
|
|
6067
|
+
end += 1;
|
|
6068
|
+
editor.dispatch({
|
|
6069
|
+
changes: { from: start, to: text.length - end, insert: formatted.slice(start, formatted.length - end) },
|
|
6070
|
+
userEvent: 'input.format',
|
|
6071
|
+
scrollIntoView: true
|
|
6072
|
+
});
|
|
6073
|
+
}
|
|
6074
|
+
return true;
|
|
6075
|
+
}
|
|
6076
|
+
/**
|
|
6077
|
+
* The problems of the edited `manifest.json` that block saving, or `null`
|
|
6078
|
+
* when the archive can be saved.
|
|
6079
|
+
*/
|
|
6080
|
+
getManifestValidity() {
|
|
6081
|
+
return this.workspace?.manifestValidity() ?? null;
|
|
6082
|
+
}
|
|
6083
|
+
// JSON files get JSON highlighting and live validation; everything else
|
|
6084
|
+
// keeps the Markdown language, as before.
|
|
6085
|
+
syncEditorLanguage(snapshot) {
|
|
6086
|
+
const isJson = (snapshot.currentPathType === 'text' || snapshot.currentPathType === 'markdown')
|
|
6087
|
+
&& isMdzipJsonPath(snapshot.currentPath);
|
|
6088
|
+
const language = isJson ? 'json' : 'markdown';
|
|
6089
|
+
if (language !== this.cmLanguage && this.cmEditor) {
|
|
6090
|
+
this.cmLanguage = language;
|
|
6091
|
+
this.cmEditor.dispatch({
|
|
6092
|
+
effects: this.languageCompartment.reconfigure(isJson
|
|
6093
|
+
// No spellcheck in JSON: keys like "someNewProp" aren't words.
|
|
6094
|
+
? [
|
|
6095
|
+
json(),
|
|
6096
|
+
syntaxHighlighting(mdzipJsonHighlight),
|
|
6097
|
+
this.jsonLinter(),
|
|
6098
|
+
bracketMatching(),
|
|
6099
|
+
closeBrackets(),
|
|
6100
|
+
foldGutter(),
|
|
6101
|
+
Prec.high(keymap.of([
|
|
6102
|
+
...closeBracketsKeymap,
|
|
6103
|
+
...foldKeymap,
|
|
6104
|
+
{ key: 'Shift-Alt-f', run: () => this.formatJson() }
|
|
6105
|
+
])),
|
|
6106
|
+
Prec.highest(EditorView.contentAttributes.of({ spellcheck: 'false' }))
|
|
6107
|
+
]
|
|
6108
|
+
: markdown())
|
|
6109
|
+
});
|
|
6110
|
+
}
|
|
6111
|
+
if (!isJson) {
|
|
6112
|
+
this.setJsonValidity(null, null);
|
|
6113
|
+
}
|
|
6114
|
+
else if (this.jsonValidityPath !== snapshot.currentPath && this.workspace) {
|
|
6115
|
+
this.setJsonValidity(this.workspace.validateJsonText(snapshot.currentPath, snapshot.currentText), snapshot.currentPath);
|
|
6116
|
+
}
|
|
6117
|
+
}
|
|
6118
|
+
jsonLinter() {
|
|
6119
|
+
return linter((view) => {
|
|
6120
|
+
const workspace = this.workspace;
|
|
6121
|
+
if (!workspace) {
|
|
6122
|
+
return [];
|
|
6123
|
+
}
|
|
6124
|
+
const path = workspace.snapshot().currentPath;
|
|
6125
|
+
const validity = workspace.validateJsonText(path, view.state.doc.toString());
|
|
6126
|
+
this.setJsonValidity(validity, path);
|
|
6127
|
+
const length = view.state.doc.length;
|
|
6128
|
+
return validity.problems.map((problem) => {
|
|
6129
|
+
const from = Math.min(problem.from, length);
|
|
6130
|
+
return {
|
|
6131
|
+
from,
|
|
6132
|
+
to: Math.max(from, Math.min(problem.to, length)),
|
|
6133
|
+
severity: problem.severity,
|
|
6134
|
+
message: problem.message
|
|
6135
|
+
};
|
|
6136
|
+
});
|
|
6137
|
+
}, { delay: 300 });
|
|
6138
|
+
}
|
|
6139
|
+
setJsonValidity(validity, path) {
|
|
6140
|
+
const changed = this.jsonValidityPath !== path
|
|
6141
|
+
|| JSON.stringify(this.jsonValidity?.problems ?? null) !== JSON.stringify(validity?.problems ?? null);
|
|
6142
|
+
this.jsonValidity = validity;
|
|
6143
|
+
this.jsonValidityPath = path;
|
|
6144
|
+
const status = this.elJsonStatus;
|
|
6145
|
+
status.hidden = validity === null || this.options.jsonStatus === false;
|
|
6146
|
+
// Format needs valid JSON; a manifest error that isn't about syntax is fine.
|
|
6147
|
+
this.elFormatJsonBtn.disabled = validity !== null && validity.value === undefined;
|
|
6148
|
+
this.elFormatJsonBtn.title = this.elFormatJsonBtn.disabled
|
|
6149
|
+
? 'Format JSON: fix the syntax error first'
|
|
6150
|
+
: 'Format JSON (Shift+Alt+F)';
|
|
6151
|
+
if (validity) {
|
|
6152
|
+
status.dataset.status = validity.status;
|
|
6153
|
+
status.textContent = validity.canSave
|
|
6154
|
+
? describeMdzipJsonValidity(validity)
|
|
6155
|
+
: `${describeMdzipJsonValidity(validity)} Saving is blocked until it's fixed.`;
|
|
6156
|
+
const custom = validity.customFields.length
|
|
6157
|
+
? `Custom fields, kept as they are: ${validity.customFields.join(', ')}.`
|
|
6158
|
+
: '';
|
|
6159
|
+
status.title = [
|
|
6160
|
+
...validity.problems.map((problem) => `${problem.severity}: ${problem.message}`),
|
|
6161
|
+
custom
|
|
6162
|
+
].filter(Boolean).join('\n');
|
|
6163
|
+
}
|
|
6164
|
+
else {
|
|
6165
|
+
delete status.dataset.status;
|
|
6166
|
+
status.textContent = '';
|
|
6167
|
+
status.title = '';
|
|
6168
|
+
}
|
|
6169
|
+
if (changed) {
|
|
6170
|
+
this.options.onJsonValidityChanged?.(validity, path);
|
|
6171
|
+
}
|
|
6172
|
+
}
|
|
5105
6173
|
downloadSavedBlob(blob, fileName) {
|
|
5106
6174
|
const doc = this.elRoot.ownerDocument;
|
|
5107
6175
|
const urlApi = doc.defaultView?.URL;
|
|
@@ -6037,6 +7105,9 @@ export class MdzipWorkspaceView {
|
|
|
6037
7105
|
card.replaceWith(image);
|
|
6038
7106
|
}
|
|
6039
7107
|
const text = previewPlainText(container);
|
|
7108
|
+
for (const element of Array.from(container.querySelectorAll(`[${MDZIP_BLOCK_ATTRIBUTE}]`))) {
|
|
7109
|
+
element.removeAttribute(MDZIP_BLOCK_ATTRIBUTE);
|
|
7110
|
+
}
|
|
6040
7111
|
for (const element of Array.from(container.querySelectorAll(PREVIEW_CHROME_REMOVE_SELECTOR))) {
|
|
6041
7112
|
element.remove();
|
|
6042
7113
|
}
|
|
@@ -6351,7 +7422,8 @@ export class MdzipWorkspaceView {
|
|
|
6351
7422
|
chunkHtml = cacheHit;
|
|
6352
7423
|
}
|
|
6353
7424
|
else {
|
|
6354
|
-
|
|
7425
|
+
// Marked like the preview's chunks: the two share chunkHtmlCache.
|
|
7426
|
+
const result = this.renderingService.renderChunk(chunks[chunkIndex], context, { index: chunkIndex, markBlocks: true });
|
|
6355
7427
|
chunkHtml = typeof result === 'string' ? result : await result;
|
|
6356
7428
|
// Only populate the shared cache if this generation is *still*
|
|
6357
7429
|
// the live one at the moment this (possibly async) render
|
|
@@ -6387,7 +7459,8 @@ export class MdzipWorkspaceView {
|
|
|
6387
7459
|
setTimeout(resolve, 0);
|
|
6388
7460
|
});
|
|
6389
7461
|
}
|
|
6390
|
-
|
|
7462
|
+
// The split view's block marks are for this page only.
|
|
7463
|
+
return stripMdzipBlockMarks(html);
|
|
6391
7464
|
}
|
|
6392
7465
|
/**
|
|
6393
7466
|
* Like `copyAllPreviewContent`, but writes a rich `text/html` clipboard
|
|
@@ -6771,6 +7844,12 @@ export class MdzipWorkspaceView {
|
|
|
6771
7844
|
link: formatting.link,
|
|
6772
7845
|
image: formatting.image
|
|
6773
7846
|
};
|
|
7847
|
+
// Formatting only applies to Markdown; the whitespace toggle to any text the editor shows.
|
|
7848
|
+
for (const key of Object.keys(visibility)) {
|
|
7849
|
+
visibility[key] = visibility[key] && this.formattingShown;
|
|
7850
|
+
}
|
|
7851
|
+
visibility['whitespace'] = this.whitespaceControlShown;
|
|
7852
|
+
visibility['formatJson'] = this.formatJsonShown;
|
|
6774
7853
|
this.elEditToolbar.querySelectorAll('[data-format-control]').forEach((element) => {
|
|
6775
7854
|
element.hidden = !visibility[element.dataset['formatControl'] ?? ''];
|
|
6776
7855
|
});
|
|
@@ -7194,20 +8273,26 @@ export class MdzipWorkspaceView {
|
|
|
7194
8273
|
// Items for the nav context menu; null entries render as separators.
|
|
7195
8274
|
navMenuItems(target, snapshot) {
|
|
7196
8275
|
const canMutate = this.allowFileActions(snapshot);
|
|
8276
|
+
if (target.kind === 'selection') {
|
|
8277
|
+
return this.extractMenuItems('many', false);
|
|
8278
|
+
}
|
|
7197
8279
|
if (target.kind === 'directory') {
|
|
8280
|
+
const hasFiles = this.collectExtractPaths({ files: [], folders: [target.path] }, snapshot).length > 0;
|
|
8281
|
+
const extract = hasFiles ? this.extractMenuItems('many', target.path === '') : [];
|
|
7198
8282
|
if (!canMutate) {
|
|
7199
|
-
return
|
|
8283
|
+
return extract;
|
|
7200
8284
|
}
|
|
7201
8285
|
return [
|
|
7202
8286
|
{ action: 'new-file', label: 'New .md File' },
|
|
7203
8287
|
{ action: 'new-folder', label: 'New Folder' },
|
|
7204
8288
|
null,
|
|
7205
|
-
{ action: 'add-files', label: 'Add Files…' }
|
|
8289
|
+
{ action: 'add-files', label: 'Add Files…' },
|
|
8290
|
+
...(extract.length ? [null, ...extract] : [])
|
|
7206
8291
|
];
|
|
7207
8292
|
}
|
|
7208
8293
|
const hostItems = this.fileActionItems(target);
|
|
7209
8294
|
if (target.isManifest) {
|
|
7210
|
-
return [...hostItems, ...(hostItems.length ? [null] : []),
|
|
8295
|
+
return [...hostItems, ...(hostItems.length ? [null] : []), ...this.extractMenuItems('one', false)];
|
|
7211
8296
|
}
|
|
7212
8297
|
const groups = [];
|
|
7213
8298
|
if (canMutate) {
|
|
@@ -7242,7 +8327,7 @@ export class MdzipWorkspaceView {
|
|
|
7242
8327
|
if (hostItems.length > 0) {
|
|
7243
8328
|
groups.push(hostItems);
|
|
7244
8329
|
}
|
|
7245
|
-
groups.push(
|
|
8330
|
+
groups.push(this.extractMenuItems('one', false));
|
|
7246
8331
|
if (canMutate && !target.isEntryPoint) {
|
|
7247
8332
|
groups.push([{
|
|
7248
8333
|
action: 'delete',
|
|
@@ -7251,6 +8336,26 @@ export class MdzipWorkspaceView {
|
|
|
7251
8336
|
}
|
|
7252
8337
|
return groups.flatMap((group, index) => index === 0 ? group : [null, ...group]);
|
|
7253
8338
|
}
|
|
8339
|
+
/**
|
|
8340
|
+
* Taking files out of the archive: **Extract…** where the host writes
|
|
8341
|
+
* them (`onExtractFiles`), else **Download** for one file, and for several
|
|
8342
|
+
* **Download as ZIP** plus **Extract to Folder…** where the browser can
|
|
8343
|
+
* write to a folder.
|
|
8344
|
+
*/
|
|
8345
|
+
extractMenuItems(count, all) {
|
|
8346
|
+
if (this.options.onExtractFiles) {
|
|
8347
|
+
return [{ action: 'extract', label: all ? 'Extract All…' : 'Extract…' }];
|
|
8348
|
+
}
|
|
8349
|
+
if (count === 'one') {
|
|
8350
|
+
return [{ action: 'download', label: 'Download' }];
|
|
8351
|
+
}
|
|
8352
|
+
const items = [{ action: 'download-zip', label: all ? 'Download All as ZIP' : 'Download as ZIP' }];
|
|
8353
|
+
const win = this.elRoot.ownerDocument.defaultView;
|
|
8354
|
+
if (typeof win?.showDirectoryPicker === 'function') {
|
|
8355
|
+
items.push({ action: 'extract-folder', label: all ? 'Extract All to Folder…' : 'Extract to Folder…' });
|
|
8356
|
+
}
|
|
8357
|
+
return items;
|
|
8358
|
+
}
|
|
7254
8359
|
/** Menu items for the host's {@link MdzipFileAction}s that apply to this file. */
|
|
7255
8360
|
fileActionItems(target) {
|
|
7256
8361
|
const file = fileActionTarget(target);
|
|
@@ -7326,6 +8431,11 @@ export class MdzipWorkspaceView {
|
|
|
7326
8431
|
await this.downloadArchiveFile(target.path);
|
|
7327
8432
|
}
|
|
7328
8433
|
break;
|
|
8434
|
+
case 'extract':
|
|
8435
|
+
case 'download-zip':
|
|
8436
|
+
case 'extract-folder':
|
|
8437
|
+
await this.extractNavTarget(target, action);
|
|
8438
|
+
break;
|
|
7329
8439
|
case 'duplicate':
|
|
7330
8440
|
if (target.kind === 'file') {
|
|
7331
8441
|
await this.duplicateFile(target.path);
|
|
@@ -7534,6 +8644,189 @@ export class MdzipWorkspaceView {
|
|
|
7534
8644
|
const fileName = path.slice(path.lastIndexOf('/') + 1);
|
|
7535
8645
|
this.downloadSavedBlob(new Blob([buffer]), fileName);
|
|
7536
8646
|
}
|
|
8647
|
+
/**
|
|
8648
|
+
* The files of the archive as `{ path, bytes }`, for a host or a test to
|
|
8649
|
+
* write elsewhere (#69). Each path names a file, or a folder (with or
|
|
8650
|
+
* without a trailing `/`; `''` is the whole archive) whose files are all
|
|
8651
|
+
* included when `includeFolders` isn't false. `manifest.json` comes only
|
|
8652
|
+
* when named. In archive order, each file once; paths that match nothing
|
|
8653
|
+
* are skipped. Bytes are the file's current content, as Download gives.
|
|
8654
|
+
*/
|
|
8655
|
+
async extractFiles(paths, options = {}) {
|
|
8656
|
+
const snapshot = this.workspace?.snapshot();
|
|
8657
|
+
if (!snapshot) {
|
|
8658
|
+
return [];
|
|
8659
|
+
}
|
|
8660
|
+
const files = [];
|
|
8661
|
+
const folders = [];
|
|
8662
|
+
for (const path of paths) {
|
|
8663
|
+
if (snapshot.content.paths.some((entry) => samePath(entry.path, path))) {
|
|
8664
|
+
files.push(path);
|
|
8665
|
+
}
|
|
8666
|
+
else if (options.includeFolders !== false) {
|
|
8667
|
+
folders.push(path.replace(/\/+$/, ''));
|
|
8668
|
+
}
|
|
8669
|
+
}
|
|
8670
|
+
return this.readExtractFiles(this.collectExtractPaths({ files, folders }, snapshot));
|
|
8671
|
+
}
|
|
8672
|
+
// The archive paths a selection covers, in archive order.
|
|
8673
|
+
collectExtractPaths(selection, snapshot) {
|
|
8674
|
+
return snapshot.content.paths
|
|
8675
|
+
.map((entry) => entry.path)
|
|
8676
|
+
.filter((path) => selection.files.some((file) => samePath(file, path))
|
|
8677
|
+
|| (!isMdzipManifestPath(path) && selection.folders.some((folder) => folder === '' || path.startsWith(`${folder}/`))));
|
|
8678
|
+
}
|
|
8679
|
+
async readExtractFiles(paths) {
|
|
8680
|
+
const workspace = this.workspace;
|
|
8681
|
+
const files = [];
|
|
8682
|
+
for (const path of paths) {
|
|
8683
|
+
const bytes = await workspace?.readPathBytes(path);
|
|
8684
|
+
if (bytes) {
|
|
8685
|
+
files.push({ path, bytes });
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
return files;
|
|
8689
|
+
}
|
|
8690
|
+
async extractNavTarget(target, action) {
|
|
8691
|
+
const snapshot = this.workspace?.snapshot();
|
|
8692
|
+
if (!snapshot) {
|
|
8693
|
+
return;
|
|
8694
|
+
}
|
|
8695
|
+
const selection = target.kind === 'selection'
|
|
8696
|
+
? { files: target.files, folders: target.folders }
|
|
8697
|
+
: target.kind === 'directory'
|
|
8698
|
+
? { files: [], folders: [target.path] }
|
|
8699
|
+
: { files: [target.path], folders: [] };
|
|
8700
|
+
if (action === 'extract-folder') {
|
|
8701
|
+
// Ask for the folder first: the picker needs the click's user activation.
|
|
8702
|
+
await this.extractToPickedFolder(selection, snapshot);
|
|
8703
|
+
return;
|
|
8704
|
+
}
|
|
8705
|
+
const files = await this.readExtractFiles(this.collectExtractPaths(selection, snapshot));
|
|
8706
|
+
if (!files.length) {
|
|
8707
|
+
return;
|
|
8708
|
+
}
|
|
8709
|
+
if (action === 'extract') {
|
|
8710
|
+
await this.options.onExtractFiles?.({ files, selection });
|
|
8711
|
+
return;
|
|
8712
|
+
}
|
|
8713
|
+
const zippable = {};
|
|
8714
|
+
for (const file of files) {
|
|
8715
|
+
// Pictures are compressed already.
|
|
8716
|
+
zippable[file.path] = [file.bytes, { level: /\.(png|jpe?g|gif|webp|avif|mp4|webm|zip|mdz)$/i.test(file.path) ? 0 : 6 }];
|
|
8717
|
+
}
|
|
8718
|
+
const zipped = zipSync(zippable);
|
|
8719
|
+
const buffer = zipped.buffer.slice(zipped.byteOffset, zipped.byteOffset + zipped.byteLength);
|
|
8720
|
+
const base = snapshot.fileName.replace(/\.[^.]+$/, '') || 'archive';
|
|
8721
|
+
const onlyFolder = selection.files.length === 0 && selection.folders.length === 1 && selection.folders[0] !== ''
|
|
8722
|
+
? selection.folders[0].slice(selection.folders[0].lastIndexOf('/') + 1)
|
|
8723
|
+
: null;
|
|
8724
|
+
this.downloadSavedBlob(new Blob([buffer], { type: 'application/zip' }), `${onlyFolder ?? base}.zip`);
|
|
8725
|
+
}
|
|
8726
|
+
// Extract to Folder… in a browser that can write to one: keeps the archive
|
|
8727
|
+
// paths below the folder picked, and asks before replacing files.
|
|
8728
|
+
async extractToPickedFolder(selection, snapshot) {
|
|
8729
|
+
const win = this.elRoot.ownerDocument.defaultView;
|
|
8730
|
+
if (!win?.showDirectoryPicker) {
|
|
8731
|
+
return;
|
|
8732
|
+
}
|
|
8733
|
+
let root;
|
|
8734
|
+
try {
|
|
8735
|
+
root = await win.showDirectoryPicker({ mode: 'readwrite', id: 'mdzip-extract' });
|
|
8736
|
+
}
|
|
8737
|
+
catch (error) {
|
|
8738
|
+
if (error?.name === 'AbortError') {
|
|
8739
|
+
return;
|
|
8740
|
+
}
|
|
8741
|
+
throw error;
|
|
8742
|
+
}
|
|
8743
|
+
const files = await this.readExtractFiles(this.collectExtractPaths(selection, snapshot));
|
|
8744
|
+
const folderOf = async (path, create) => {
|
|
8745
|
+
let dir = root;
|
|
8746
|
+
for (const part of path.split('/').slice(0, -1)) {
|
|
8747
|
+
try {
|
|
8748
|
+
dir = await dir.getDirectoryHandle(part, { create });
|
|
8749
|
+
}
|
|
8750
|
+
catch {
|
|
8751
|
+
return null;
|
|
8752
|
+
}
|
|
8753
|
+
}
|
|
8754
|
+
return dir;
|
|
8755
|
+
};
|
|
8756
|
+
const nameOf = (path) => path.slice(path.lastIndexOf('/') + 1);
|
|
8757
|
+
let existing = 0;
|
|
8758
|
+
for (const file of files) {
|
|
8759
|
+
const dir = await folderOf(file.path, false);
|
|
8760
|
+
if (dir && await dir.getFileHandle(nameOf(file.path)).then(() => true, () => false)) {
|
|
8761
|
+
existing += 1;
|
|
8762
|
+
}
|
|
8763
|
+
}
|
|
8764
|
+
if (existing > 0) {
|
|
8765
|
+
const ok = await this.askConfirm('Replace Existing Files?', `${existing === 1 ? 'One file' : `${existing} files`} of the ${files.length} already ${existing === 1 ? 'exists' : 'exist'} in "${root.name}". Replace ${existing === 1 ? 'it' : 'them'}?`, 'Replace');
|
|
8766
|
+
if (!ok) {
|
|
8767
|
+
return;
|
|
8768
|
+
}
|
|
8769
|
+
}
|
|
8770
|
+
for (const file of files) {
|
|
8771
|
+
const dir = await folderOf(file.path, true);
|
|
8772
|
+
if (!dir) {
|
|
8773
|
+
throw new Error(`Could not create the folder for ${file.path}.`);
|
|
8774
|
+
}
|
|
8775
|
+
const writable = await (await dir.getFileHandle(nameOf(file.path), { create: true })).createWritable();
|
|
8776
|
+
await writable.write(file.bytes);
|
|
8777
|
+
await writable.close();
|
|
8778
|
+
}
|
|
8779
|
+
this.showCopyToast(`Extracted ${files.length === 1 ? 'one file' : `${files.length} files`} to "${root.name}"`);
|
|
8780
|
+
}
|
|
8781
|
+
/** Asks a yes/no question in the editor's own dialog (no browser confirm(), which some hosts block). */
|
|
8782
|
+
askConfirm(title, text, confirm) {
|
|
8783
|
+
this.confirmDialogState?.resolve(false);
|
|
8784
|
+
return new Promise((resolve) => {
|
|
8785
|
+
this.confirmDialogState = { title, text, confirm, resolve };
|
|
8786
|
+
this.render();
|
|
8787
|
+
this.elConfirmDialogOk.focus();
|
|
8788
|
+
});
|
|
8789
|
+
}
|
|
8790
|
+
answerConfirm(ok) {
|
|
8791
|
+
const state = this.confirmDialogState;
|
|
8792
|
+
this.confirmDialogState = null;
|
|
8793
|
+
this.render();
|
|
8794
|
+
state?.resolve(ok);
|
|
8795
|
+
}
|
|
8796
|
+
// The tree's rows in order, as selection keys.
|
|
8797
|
+
navRowKeys() {
|
|
8798
|
+
return Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))
|
|
8799
|
+
// Hidden in a closed folder? (A folder's own row shows while it's closed.)
|
|
8800
|
+
.filter((row) => !(row.matches('summary') ? row.parentElement?.parentElement : row)?.closest('details:not([open])'))
|
|
8801
|
+
.map((row) => navRowKey(row))
|
|
8802
|
+
.filter((key) => key !== null);
|
|
8803
|
+
}
|
|
8804
|
+
// Shift+click: the rows from the anchor to this one (added to the
|
|
8805
|
+
// selection with Ctrl/Cmd).
|
|
8806
|
+
selectNavRange(key, add) {
|
|
8807
|
+
const rows = this.navRowKeys();
|
|
8808
|
+
const anchor = this.navSelectionAnchor && rows.includes(this.navSelectionAnchor) ? this.navSelectionAnchor : key;
|
|
8809
|
+
const [from, to] = [rows.indexOf(anchor), rows.indexOf(key)].sort((a, b) => a - b);
|
|
8810
|
+
const range = rows.slice(from, to + 1);
|
|
8811
|
+
this.navSelection = add ? [...new Set([...this.navSelection, ...range])] : range;
|
|
8812
|
+
this.navSelectionAnchor = anchor;
|
|
8813
|
+
}
|
|
8814
|
+
// Marks the selected rows, dropping any no longer in the tree.
|
|
8815
|
+
syncNavSelection() {
|
|
8816
|
+
const present = new Set(this.navRowKeysAll());
|
|
8817
|
+
this.navSelection = this.navSelection.filter((key) => present.has(key));
|
|
8818
|
+
const selected = new Set(this.navSelection);
|
|
8819
|
+
for (const row of Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))) {
|
|
8820
|
+
const key = navRowKey(row);
|
|
8821
|
+
row.classList.toggle('nav-selected', !!key && selected.has(key));
|
|
8822
|
+
}
|
|
8823
|
+
this.elNavTree.classList.toggle('has-selection', this.navSelection.length > 1);
|
|
8824
|
+
}
|
|
8825
|
+
navRowKeysAll() {
|
|
8826
|
+
return Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))
|
|
8827
|
+
.map((row) => navRowKey(row))
|
|
8828
|
+
.filter((key) => key !== null);
|
|
8829
|
+
}
|
|
7537
8830
|
async duplicateFile(path) {
|
|
7538
8831
|
const workspace = this.workspace;
|
|
7539
8832
|
const snapshot = workspace?.snapshot();
|
|
@@ -7708,17 +9001,107 @@ export class MdzipWorkspaceView {
|
|
|
7708
9001
|
this.options.onFailed?.(error);
|
|
7709
9002
|
}
|
|
7710
9003
|
}
|
|
9004
|
+
// The layout as drawn for the open file. Split shows the editor alone for
|
|
9005
|
+
// non-Markdown text (JSON, CSS, …), whose preview would only repeat the
|
|
9006
|
+
// text; this.layout keeps the choice, so Markdown files open split again.
|
|
9007
|
+
shownLayout(snapshot) {
|
|
9008
|
+
return this.layout === 'split' && snapshot.currentPathType === 'text' && !this.isManifestFormPath(snapshot)
|
|
9009
|
+
? 'source'
|
|
9010
|
+
: this.layout;
|
|
9011
|
+
}
|
|
9012
|
+
// The archive's own manifest.json, which View shows as a form.
|
|
9013
|
+
isManifestFormPath(snapshot) {
|
|
9014
|
+
return snapshot.sourceFormat === 'mdz'
|
|
9015
|
+
&& snapshot.currentPathType === 'text'
|
|
9016
|
+
&& isMdzipRootManifestPath(snapshot.currentPath);
|
|
9017
|
+
}
|
|
9018
|
+
// Moving into or out of manifest.json swaps in that side's remembered
|
|
9019
|
+
// layout, so the form (View) and a document's Split don't override each other.
|
|
9020
|
+
swapManifestLayout(snapshot) {
|
|
9021
|
+
const isManifest = this.isManifestFormPath(snapshot);
|
|
9022
|
+
if (isManifest === this.layoutIsManifest) {
|
|
9023
|
+
return;
|
|
9024
|
+
}
|
|
9025
|
+
this.layoutIsManifest = isManifest;
|
|
9026
|
+
if (isManifest) {
|
|
9027
|
+
this.documentLayout = this.layout;
|
|
9028
|
+
this.layout = this.manifestLayout;
|
|
9029
|
+
}
|
|
9030
|
+
else {
|
|
9031
|
+
this.manifestLayout = this.layout;
|
|
9032
|
+
this.layout = this.documentLayout;
|
|
9033
|
+
}
|
|
9034
|
+
if (this.layout !== 'preview' && !this.cmEditor) {
|
|
9035
|
+
// The editor is created on demand; draw again once it exists.
|
|
9036
|
+
void this.ensureCmEditor().then(() => this.render());
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
mountManifestForm(snapshot) {
|
|
9040
|
+
const workspace = this.workspace;
|
|
9041
|
+
if (!workspace) {
|
|
9042
|
+
return;
|
|
9043
|
+
}
|
|
9044
|
+
if (!this.manifestForm || !this.elPreviewContent.contains(this.manifestForm.root)) {
|
|
9045
|
+
this.manifestForm = new MdzipManifestForm(this.elRoot.ownerDocument, {
|
|
9046
|
+
editable: snapshot.mode !== 'read-only',
|
|
9047
|
+
markdownPaths: snapshot.content.paths.filter((entry) => entry.isMarkdown).map((entry) => entry.path),
|
|
9048
|
+
onChange: (path, value) => this.setManifestValue(path, value),
|
|
9049
|
+
onEditJson: () => {
|
|
9050
|
+
// In Split the JSON is already beside the form: just go to it.
|
|
9051
|
+
const show = this.layout === 'split' ? Promise.resolve() : this.setLayout('source');
|
|
9052
|
+
void show.then(() => this.cmEditor?.focus());
|
|
9053
|
+
}
|
|
9054
|
+
});
|
|
9055
|
+
this.elPreviewContent.replaceChildren(this.manifestForm.root);
|
|
9056
|
+
}
|
|
9057
|
+
const validity = workspace.validateJsonText(snapshot.currentPath, snapshot.currentText);
|
|
9058
|
+
this.manifestForm.update(validity);
|
|
9059
|
+
this.setJsonValidity(validity, snapshot.currentPath);
|
|
9060
|
+
}
|
|
9061
|
+
// A change made in the form: one value set in the JSON text, through the
|
|
9062
|
+
// editor when there is one (so Ctrl+Z undoes it), else the workspace.
|
|
9063
|
+
setManifestValue(path, value) {
|
|
9064
|
+
const workspace = this.workspace;
|
|
9065
|
+
if (!workspace) {
|
|
9066
|
+
return;
|
|
9067
|
+
}
|
|
9068
|
+
const current = this.cmEditor && this.layout !== 'preview'
|
|
9069
|
+
? this.cmEditor.state.doc.toString()
|
|
9070
|
+
: workspace.snapshot().currentText;
|
|
9071
|
+
const next = setMdzipJsonMember(current, path, value);
|
|
9072
|
+
if (next === null || next === current) {
|
|
9073
|
+
return;
|
|
9074
|
+
}
|
|
9075
|
+
const editor = this.cmEditor;
|
|
9076
|
+
if (editor && editor.state.doc.toString() === current) {
|
|
9077
|
+
editor.dispatch({ changes: { from: 0, to: current.length, insert: next }, userEvent: 'input.form' });
|
|
9078
|
+
}
|
|
9079
|
+
else {
|
|
9080
|
+
try {
|
|
9081
|
+
workspace.editText(next);
|
|
9082
|
+
}
|
|
9083
|
+
catch (error) {
|
|
9084
|
+
this.options.onFailed?.(error);
|
|
9085
|
+
}
|
|
9086
|
+
}
|
|
9087
|
+
}
|
|
7711
9088
|
validLayoutForSnapshot(requested, snapshot) {
|
|
7712
9089
|
if (requested === 'source' || requested === 'split') {
|
|
7713
9090
|
return canShowSourceLayout(snapshot) ? requested : 'preview';
|
|
7714
9091
|
}
|
|
7715
9092
|
return requested;
|
|
7716
9093
|
}
|
|
7717
|
-
|
|
7718
|
-
|
|
9094
|
+
/**
|
|
9095
|
+
* In Split, scrolls the source to match the preview. Normally only after
|
|
9096
|
+
* the reader scrolled the preview themselves; `driven` is for the editor's
|
|
9097
|
+
* own moves (going to a heading from the outline or a link), which no
|
|
9098
|
+
* gesture precedes.
|
|
9099
|
+
*/
|
|
9100
|
+
syncScrollFromPreview(driven = false) {
|
|
9101
|
+
if (this.syncing || !this.cmEditor || this.layout !== 'split' || this.layoutIsManifest) {
|
|
7719
9102
|
return;
|
|
7720
9103
|
}
|
|
7721
|
-
if (performance.now() - this.lastPreviewGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
|
|
9104
|
+
if (!driven && performance.now() - this.lastPreviewGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
|
|
7722
9105
|
return;
|
|
7723
9106
|
}
|
|
7724
9107
|
if (performance.now() - this.lastContentChangeTime < MdzipWorkspaceView.SCROLL_SYNC_SETTLE_MS) {
|
|
@@ -7739,19 +9122,25 @@ export class MdzipWorkspaceView {
|
|
|
7739
9122
|
return;
|
|
7740
9123
|
}
|
|
7741
9124
|
this.syncing = true;
|
|
7742
|
-
const previewHeight = this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight;
|
|
7743
|
-
const scrollRatio = previewHeight > 0 ? currentTop / previewHeight : 0;
|
|
7744
9125
|
const cmScroller = this.cmEditor.dom.querySelector('.cm-scroller');
|
|
7745
9126
|
if (cmScroller) {
|
|
7746
|
-
const
|
|
7747
|
-
|
|
9127
|
+
const anchors = this.splitScrollAnchors('preview', currentTop);
|
|
9128
|
+
let target;
|
|
9129
|
+
if (anchors) {
|
|
9130
|
+
target = mapScrollPosition(currentTop, anchors.map(([editor, preview]) => [preview, editor]), this.elPreviewPane, cmScroller);
|
|
9131
|
+
}
|
|
9132
|
+
else {
|
|
9133
|
+
const previewHeight = this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight;
|
|
9134
|
+
const scrollRatio = previewHeight > 0 ? currentTop / previewHeight : 0;
|
|
9135
|
+
target = scrollRatio * (cmScroller.scrollHeight - cmScroller.clientHeight);
|
|
9136
|
+
}
|
|
7748
9137
|
this.lastSyncedEditorScrollTop = target;
|
|
7749
9138
|
cmScroller.scrollTop = target;
|
|
7750
9139
|
}
|
|
7751
9140
|
this.syncing = false;
|
|
7752
9141
|
}
|
|
7753
9142
|
syncScrollToPreview() {
|
|
7754
|
-
if (this.syncing || !this.cmEditor || this.layout !== 'split') {
|
|
9143
|
+
if (this.syncing || !this.cmEditor || this.layout !== 'split' || this.layoutIsManifest) {
|
|
7755
9144
|
return;
|
|
7756
9145
|
}
|
|
7757
9146
|
if (performance.now() - this.lastEditorGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
|
|
@@ -7807,13 +9196,141 @@ export class MdzipWorkspaceView {
|
|
|
7807
9196
|
return;
|
|
7808
9197
|
}
|
|
7809
9198
|
this.syncing = true;
|
|
7810
|
-
const
|
|
7811
|
-
|
|
7812
|
-
|
|
9199
|
+
const anchors = this.splitScrollAnchors('editor', currentTop);
|
|
9200
|
+
let target;
|
|
9201
|
+
if (anchors) {
|
|
9202
|
+
target = mapScrollPosition(currentTop, anchors, cmScroller, this.elPreviewPane);
|
|
9203
|
+
}
|
|
9204
|
+
else {
|
|
9205
|
+
const scrollRatio = editorHeight > 0 ? currentTop / editorHeight : 0;
|
|
9206
|
+
target = scrollRatio * (this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight);
|
|
9207
|
+
}
|
|
7813
9208
|
this.lastSyncedPreviewScrollTop = target;
|
|
7814
9209
|
this.elPreviewPane.scrollTop = target;
|
|
7815
9210
|
this.syncing = false;
|
|
7816
9211
|
}
|
|
9212
|
+
/**
|
|
9213
|
+
* The two pairs of [offset in the editor, offset in the preview] for the
|
|
9214
|
+
* same content around `scrollTop` of one pane (#13), for
|
|
9215
|
+
* `mapScrollPosition` to interpolate between: the mounted top-level
|
|
9216
|
+
* blocks the renderer marked (`data-mdzip-block`), each at its token's
|
|
9217
|
+
* first source line. The panes stay together past a tall image, table or
|
|
9218
|
+
* code block, where one ratio for the whole document drifts. Null when
|
|
9219
|
+
* nothing is marked (a custom renderer) or the preview isn't laid out:
|
|
9220
|
+
* the sync falls back to that ratio.
|
|
9221
|
+
*
|
|
9222
|
+
* Only the two blocks around the position are measured, found by binary
|
|
9223
|
+
* search (both panes keep blocks in document order), so a scroll costs
|
|
9224
|
+
* the same in a document of any length.
|
|
9225
|
+
*/
|
|
9226
|
+
splitScrollAnchors(from, scrollTop) {
|
|
9227
|
+
const editor = this.cmEditor;
|
|
9228
|
+
const blocks = this.splitScrollBlocks();
|
|
9229
|
+
if (!editor || !blocks || !this.elPreviewContent.offsetHeight) {
|
|
9230
|
+
return null;
|
|
9231
|
+
}
|
|
9232
|
+
const scroller = editor.scrollDOM;
|
|
9233
|
+
const pane = this.elPreviewPane;
|
|
9234
|
+
const previewOrigin = pane.scrollTop - pane.getBoundingClientRect().top;
|
|
9235
|
+
const editorOrigin = editor.documentTop - scroller.getBoundingClientRect().top + scroller.scrollTop;
|
|
9236
|
+
const editorTop = (i) => editor.lineBlockAt(Math.min(blocks.offsets[i], editor.state.doc.length)).top + editorOrigin;
|
|
9237
|
+
const previewTop = (i) => blocks.elements[i].getBoundingClientRect().top + previewOrigin;
|
|
9238
|
+
const top = from === 'editor' ? editorTop : previewTop;
|
|
9239
|
+
// The last block at or above scrollTop (-1: above the first).
|
|
9240
|
+
let low = 0;
|
|
9241
|
+
let high = blocks.offsets.length - 1;
|
|
9242
|
+
let at = -1;
|
|
9243
|
+
while (low <= high) {
|
|
9244
|
+
const mid = (low + high) >> 1;
|
|
9245
|
+
if (top(mid) <= scrollTop) {
|
|
9246
|
+
at = mid;
|
|
9247
|
+
low = mid + 1;
|
|
9248
|
+
}
|
|
9249
|
+
else {
|
|
9250
|
+
high = mid - 1;
|
|
9251
|
+
}
|
|
9252
|
+
}
|
|
9253
|
+
const anchors = [];
|
|
9254
|
+
for (const i of [at, at + 1]) {
|
|
9255
|
+
if (i >= 0 && i < blocks.offsets.length) {
|
|
9256
|
+
anchors.push([editorTop(i), previewTop(i)]);
|
|
9257
|
+
}
|
|
9258
|
+
}
|
|
9259
|
+
return anchors;
|
|
9260
|
+
}
|
|
9261
|
+
/**
|
|
9262
|
+
* The preview's mounted, marked blocks in order, each with its token's
|
|
9263
|
+
* offset in the editor's text. Offsets come from each token's `raw` text,
|
|
9264
|
+
* found in order in the editor's current text rather than counted from
|
|
9265
|
+
* the tokens: front matter is stripped before tokenizing, and the preview
|
|
9266
|
+
* can be a render behind the editor while typing (a block not found is
|
|
9267
|
+
* left out). Kept until the text or the mounted chunks change; no layout
|
|
9268
|
+
* is read here.
|
|
9269
|
+
*/
|
|
9270
|
+
splitScrollBlocks() {
|
|
9271
|
+
const editor = this.cmEditor;
|
|
9272
|
+
const state = this.chunkedRenderState;
|
|
9273
|
+
if (!editor || !state) {
|
|
9274
|
+
return null;
|
|
9275
|
+
}
|
|
9276
|
+
const cached = this.splitBlockCache;
|
|
9277
|
+
if (cached && cached.doc === editor.state.doc && cached.records === state.records && cached.cursor === state.cursor) {
|
|
9278
|
+
return cached.blocks;
|
|
9279
|
+
}
|
|
9280
|
+
const text = editor.state.doc.toString();
|
|
9281
|
+
const offsets = [];
|
|
9282
|
+
const elements = [];
|
|
9283
|
+
let cursor = 0;
|
|
9284
|
+
let located = false;
|
|
9285
|
+
for (const record of state.records) {
|
|
9286
|
+
const tokenOffsets = [];
|
|
9287
|
+
for (const token of record.tokens) {
|
|
9288
|
+
const raw = token.raw;
|
|
9289
|
+
let at = -1;
|
|
9290
|
+
if (raw) {
|
|
9291
|
+
if (text.startsWith(raw, cursor)) {
|
|
9292
|
+
at = cursor;
|
|
9293
|
+
}
|
|
9294
|
+
else if (!located) {
|
|
9295
|
+
// The first block can come after front matter of any length.
|
|
9296
|
+
at = text.indexOf(raw, cursor);
|
|
9297
|
+
}
|
|
9298
|
+
else {
|
|
9299
|
+
// Later, only look a little ahead: a block edited since the
|
|
9300
|
+
// preview rendered isn't in the text, and mustn't cost a scan
|
|
9301
|
+
// of the rest of the document.
|
|
9302
|
+
const found = text.slice(cursor, cursor + raw.length + 4096).indexOf(raw);
|
|
9303
|
+
at = found < 0 ? -1 : cursor + found;
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9306
|
+
tokenOffsets.push(at);
|
|
9307
|
+
if (at >= 0) {
|
|
9308
|
+
located = true;
|
|
9309
|
+
cursor = at + raw.length;
|
|
9310
|
+
}
|
|
9311
|
+
}
|
|
9312
|
+
if (!record.root) {
|
|
9313
|
+
continue;
|
|
9314
|
+
}
|
|
9315
|
+
// At any depth: the preview wraps some blocks after mounting (a code
|
|
9316
|
+
// block in its header box). Not inside another block, though: only
|
|
9317
|
+
// raw HTML written that way could put one there.
|
|
9318
|
+
for (const element of Array.from(record.root.querySelectorAll(`[${MDZIP_BLOCK_ATTRIBUTE}]`))) {
|
|
9319
|
+
if (element.parentElement?.closest(`[${MDZIP_BLOCK_ATTRIBUTE}]`)) {
|
|
9320
|
+
continue;
|
|
9321
|
+
}
|
|
9322
|
+
const index = Number(element.getAttribute(MDZIP_BLOCK_ATTRIBUTE) ?? NaN);
|
|
9323
|
+
const offset = Number.isInteger(index) ? tokenOffsets[index] ?? -1 : -1;
|
|
9324
|
+
if (offset >= 0) {
|
|
9325
|
+
offsets.push(offset);
|
|
9326
|
+
elements.push(element);
|
|
9327
|
+
}
|
|
9328
|
+
}
|
|
9329
|
+
}
|
|
9330
|
+
const blocks = offsets.length ? { offsets, elements } : null;
|
|
9331
|
+
this.splitBlockCache = { doc: editor.state.doc, records: state.records, cursor: state.cursor, blocks };
|
|
9332
|
+
return blocks;
|
|
9333
|
+
}
|
|
7817
9334
|
/**
|
|
7818
9335
|
* Handles syncScrollToPreview's bottom edge when the preview still has
|
|
7819
9336
|
* unmounted chunks: force-mounts the rest (same drain Copy All uses) so
|
|
@@ -8045,349 +9562,388 @@ function formatMetadataValue(value) {
|
|
|
8045
9562
|
}
|
|
8046
9563
|
return 'Not available';
|
|
8047
9564
|
}
|
|
8048
|
-
const SHELL_HTML = `
|
|
8049
|
-
<section class="mdzip-root">
|
|
8050
|
-
<div class="document-strip" data-ref="document-strip" hidden>
|
|
8051
|
-
<button type="button" class="title-button" data-ref="title-btn"></button>
|
|
8052
|
-
<button type="button" class="document-info-button" data-ref="document-info-btn"
|
|
8053
|
-
title="Document information" aria-label="Document information">
|
|
8054
|
-
${INFO_ICON_HTML}
|
|
8055
|
-
</button>
|
|
8056
|
-
</div>
|
|
8057
|
-
|
|
8058
|
-
<header class="toolbar" data-ref="toolbar" hidden>
|
|
8059
|
-
<div class="toolbar-start">
|
|
8060
|
-
<div class="toolbar-left">
|
|
8061
|
-
<button type="button" class="icon-toggle nav-toggle" data-ref="nav-btn" title="Toggle contents" aria-label="Toggle contents">
|
|
8062
|
-
${NAV_TOGGLE_ICON_HTML}
|
|
8063
|
-
</button>
|
|
8064
|
-
</div>
|
|
8065
|
-
|
|
8066
|
-
<div class="edit-toolbar" data-ref="edit-toolbar" role="toolbar" aria-label="
|
|
8067
|
-
<div class="edit-toolbar-group">
|
|
8068
|
-
<button type="button" data-format="bold" data-format-control="bold" title="Bold" aria-label="Bold">${BOLD_ICON_HTML}</button>
|
|
8069
|
-
<button type="button" data-format="italic" data-format-control="italic" title="Italic" aria-label="Italic">${ITALIC_ICON_HTML}</button>
|
|
8070
|
-
<button type="button" data-format="strike" data-format-control="strikethrough" title="Strikethrough" aria-label="Strikethrough">${STRIKE_ICON_HTML}</button>
|
|
8071
|
-
<div class="format-menu" data-format-control="headings">
|
|
8072
|
-
<button type="button" class="format-menu-toggle" data-format-menu-toggle
|
|
8073
|
-
aria-label="Heading" aria-haspopup="menu" aria-expanded="false">
|
|
8074
|
-
${HEADING_ICON_HTML}${CHEVRON_ICON_HTML}
|
|
8075
|
-
</button>
|
|
8076
|
-
<div class="format-menu-popover" data-format-menu role="menu" aria-label="Heading level" hidden>
|
|
8077
|
-
<button type="button" role="menuitem" data-format="paragraph">Paragraph</button>
|
|
8078
|
-
<button type="button" role="menuitem" data-format="heading-1" data-heading-level="1"><strong>H1</strong> Heading 1</button>
|
|
8079
|
-
<button type="button" role="menuitem" data-format="heading-2" data-heading-level="2"><strong>H2</strong> Heading 2</button>
|
|
8080
|
-
<button type="button" role="menuitem" data-format="heading-3" data-heading-level="3"><strong>H3</strong> Heading 3</button>
|
|
8081
|
-
<button type="button" role="menuitem" data-format="heading-4" data-heading-level="4"><strong>H4</strong> Heading 4</button>
|
|
8082
|
-
<button type="button" role="menuitem" data-format="heading-5" data-heading-level="5"><strong>H5</strong> Heading 5</button>
|
|
8083
|
-
<button type="button" role="menuitem" data-format="heading-6" data-heading-level="6"><strong>H6</strong> Heading 6</button>
|
|
8084
|
-
</div>
|
|
8085
|
-
</div>
|
|
8086
|
-
</div>
|
|
8087
|
-
<span class="edit-toolbar-divider" aria-hidden="true"></span>
|
|
8088
|
-
<div class="edit-toolbar-group">
|
|
8089
|
-
<button type="button" data-format="bullet-list" data-format-control="bulletList" title="Bulleted list" aria-label="Bulleted list">${BULLET_LIST_ICON_HTML}</button>
|
|
8090
|
-
<button type="button" data-format="ordered-list" data-format-control="orderedList" title="Numbered list" aria-label="Numbered list">${ORDERED_LIST_ICON_HTML}</button>
|
|
8091
|
-
<div class="format-menu" data-format-control="code">
|
|
8092
|
-
<button type="button" class="format-menu-toggle" data-format-menu-toggle
|
|
8093
|
-
aria-label="Code" aria-haspopup="menu" aria-expanded="false">
|
|
8094
|
-
${CODE_ICON_HTML}${CHEVRON_ICON_HTML}
|
|
8095
|
-
</button>
|
|
8096
|
-
<div class="format-menu-popover" data-format-menu role="menu" aria-label="Code format" hidden>
|
|
8097
|
-
<button type="button" role="menuitem" data-format="code" data-code-kind="inline">Inline code</button>
|
|
8098
|
-
<button type="button" role="menuitem" data-format="code-block" data-code-kind="block">Code block</button>
|
|
8099
|
-
</div>
|
|
8100
|
-
</div>
|
|
8101
|
-
<button type="button" data-format="quote" data-format-control="blockquote" title="Blockquote" aria-label="Blockquote">${QUOTE_ICON_HTML}</button>
|
|
8102
|
-
<button type="button" data-format="line-break" data-format-control="lineBreak" title="Line break" aria-label="Line break">${LINE_BREAK_ICON_HTML}</button>
|
|
8103
|
-
</div>
|
|
8104
|
-
<span class="edit-toolbar-divider" aria-hidden="true"></span>
|
|
8105
|
-
<div class="edit-toolbar-group">
|
|
8106
|
-
<button type="button" data-format="link" data-format-control="link" title="Link" aria-label="Link">${LINK_ICON_HTML}</button>
|
|
8107
|
-
<button type="button" data-format="image" data-format-control="image" title="Image" aria-label="Image">${IMAGE_FORMAT_ICON_HTML}</button>
|
|
8108
|
-
<input type="file" data-ref="image-input" accept="image/*" hidden />
|
|
8109
|
-
</div>
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
</
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
<button type="button"
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
<
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
<
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
<
|
|
8214
|
-
<button type="button" class="
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
<
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
<
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
<
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
<
|
|
8275
|
-
<
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
</
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
<
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
<
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
<
|
|
8323
|
-
|
|
8324
|
-
<
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
<
|
|
8337
|
-
<
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
<
|
|
8350
|
-
<div
|
|
8351
|
-
<
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
<
|
|
8361
|
-
<
|
|
8362
|
-
|
|
8363
|
-
<button type="button" data-action="cancel-
|
|
8364
|
-
<button type="button" class="save-title" data-ref="
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
<
|
|
8374
|
-
<
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8378
|
-
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
</
|
|
9565
|
+
const SHELL_HTML = `
|
|
9566
|
+
<section class="mdzip-root">
|
|
9567
|
+
<div class="document-strip" data-ref="document-strip" hidden>
|
|
9568
|
+
<button type="button" class="title-button" data-ref="title-btn"></button>
|
|
9569
|
+
<button type="button" class="document-info-button" data-ref="document-info-btn"
|
|
9570
|
+
title="Document information" aria-label="Document information">
|
|
9571
|
+
${INFO_ICON_HTML}
|
|
9572
|
+
</button>
|
|
9573
|
+
</div>
|
|
9574
|
+
|
|
9575
|
+
<header class="toolbar" data-ref="toolbar" hidden>
|
|
9576
|
+
<div class="toolbar-start">
|
|
9577
|
+
<div class="toolbar-left">
|
|
9578
|
+
<button type="button" class="icon-toggle nav-toggle" data-ref="nav-btn" title="Toggle contents" aria-label="Toggle contents">
|
|
9579
|
+
${NAV_TOGGLE_ICON_HTML}
|
|
9580
|
+
</button>
|
|
9581
|
+
</div>
|
|
9582
|
+
|
|
9583
|
+
<div class="edit-toolbar" data-ref="edit-toolbar" role="toolbar" aria-label="Editing">
|
|
9584
|
+
<div class="edit-toolbar-group">
|
|
9585
|
+
<button type="button" data-format="bold" data-format-control="bold" title="Bold" aria-label="Bold">${BOLD_ICON_HTML}</button>
|
|
9586
|
+
<button type="button" data-format="italic" data-format-control="italic" title="Italic" aria-label="Italic">${ITALIC_ICON_HTML}</button>
|
|
9587
|
+
<button type="button" data-format="strike" data-format-control="strikethrough" title="Strikethrough" aria-label="Strikethrough">${STRIKE_ICON_HTML}</button>
|
|
9588
|
+
<div class="format-menu" data-format-control="headings">
|
|
9589
|
+
<button type="button" class="format-menu-toggle" data-format-menu-toggle
|
|
9590
|
+
aria-label="Heading" aria-haspopup="menu" aria-expanded="false">
|
|
9591
|
+
${HEADING_ICON_HTML}${CHEVRON_ICON_HTML}
|
|
9592
|
+
</button>
|
|
9593
|
+
<div class="format-menu-popover" data-format-menu role="menu" aria-label="Heading level" hidden>
|
|
9594
|
+
<button type="button" role="menuitem" data-format="paragraph">Paragraph</button>
|
|
9595
|
+
<button type="button" role="menuitem" data-format="heading-1" data-heading-level="1"><strong>H1</strong> Heading 1</button>
|
|
9596
|
+
<button type="button" role="menuitem" data-format="heading-2" data-heading-level="2"><strong>H2</strong> Heading 2</button>
|
|
9597
|
+
<button type="button" role="menuitem" data-format="heading-3" data-heading-level="3"><strong>H3</strong> Heading 3</button>
|
|
9598
|
+
<button type="button" role="menuitem" data-format="heading-4" data-heading-level="4"><strong>H4</strong> Heading 4</button>
|
|
9599
|
+
<button type="button" role="menuitem" data-format="heading-5" data-heading-level="5"><strong>H5</strong> Heading 5</button>
|
|
9600
|
+
<button type="button" role="menuitem" data-format="heading-6" data-heading-level="6"><strong>H6</strong> Heading 6</button>
|
|
9601
|
+
</div>
|
|
9602
|
+
</div>
|
|
9603
|
+
</div>
|
|
9604
|
+
<span class="edit-toolbar-divider" aria-hidden="true"></span>
|
|
9605
|
+
<div class="edit-toolbar-group">
|
|
9606
|
+
<button type="button" data-format="bullet-list" data-format-control="bulletList" title="Bulleted list" aria-label="Bulleted list">${BULLET_LIST_ICON_HTML}</button>
|
|
9607
|
+
<button type="button" data-format="ordered-list" data-format-control="orderedList" title="Numbered list" aria-label="Numbered list">${ORDERED_LIST_ICON_HTML}</button>
|
|
9608
|
+
<div class="format-menu" data-format-control="code">
|
|
9609
|
+
<button type="button" class="format-menu-toggle" data-format-menu-toggle
|
|
9610
|
+
aria-label="Code" aria-haspopup="menu" aria-expanded="false">
|
|
9611
|
+
${CODE_ICON_HTML}${CHEVRON_ICON_HTML}
|
|
9612
|
+
</button>
|
|
9613
|
+
<div class="format-menu-popover" data-format-menu role="menu" aria-label="Code format" hidden>
|
|
9614
|
+
<button type="button" role="menuitem" data-format="code" data-code-kind="inline">Inline code</button>
|
|
9615
|
+
<button type="button" role="menuitem" data-format="code-block" data-code-kind="block">Code block</button>
|
|
9616
|
+
</div>
|
|
9617
|
+
</div>
|
|
9618
|
+
<button type="button" data-format="quote" data-format-control="blockquote" title="Blockquote" aria-label="Blockquote">${QUOTE_ICON_HTML}</button>
|
|
9619
|
+
<button type="button" data-format="line-break" data-format-control="lineBreak" title="Line break" aria-label="Line break">${LINE_BREAK_ICON_HTML}</button>
|
|
9620
|
+
</div>
|
|
9621
|
+
<span class="edit-toolbar-divider" aria-hidden="true"></span>
|
|
9622
|
+
<div class="edit-toolbar-group">
|
|
9623
|
+
<button type="button" data-format="link" data-format-control="link" title="Link" aria-label="Link">${LINK_ICON_HTML}</button>
|
|
9624
|
+
<button type="button" data-format="image" data-format-control="image" title="Image" aria-label="Image">${IMAGE_FORMAT_ICON_HTML}</button>
|
|
9625
|
+
<input type="file" data-ref="image-input" accept="image/*" hidden />
|
|
9626
|
+
</div>
|
|
9627
|
+
<span class="edit-toolbar-divider" aria-hidden="true"></span>
|
|
9628
|
+
<div class="edit-toolbar-group">
|
|
9629
|
+
<button type="button" data-ref="format-json-btn" data-format-control="formatJson"
|
|
9630
|
+
title="Format JSON (Shift+Alt+F)" aria-label="Format JSON">${FORMAT_JSON_ICON_HTML}</button>
|
|
9631
|
+
<button type="button" class="edit-toolbar-toggle" data-ref="whitespace-btn" data-format-control="whitespace"
|
|
9632
|
+
title="Show whitespace" aria-label="Show whitespace" aria-pressed="false">${WHITESPACE_ICON_HTML}</button>
|
|
9633
|
+
</div>
|
|
9634
|
+
</div>
|
|
9635
|
+
</div>
|
|
9636
|
+
|
|
9637
|
+
<div class="toolbar-buttons view-mode-toggle-group" data-ref="layout-controls" role="group" aria-label="Editor layout">
|
|
9638
|
+
<button type="button" class="icon-toggle view-mode-toggle" data-ref="source-btn" title="Edit" aria-label="Edit" aria-pressed="false">
|
|
9639
|
+
<span class="commandbar-flex-container" data-ref="source-icon">${SOURCE_EDIT_ICON_HTML}</span>
|
|
9640
|
+
</button>
|
|
9641
|
+
<button type="button" class="icon-toggle view-mode-toggle" data-ref="split-btn" title="Split" aria-label="Split" aria-pressed="false">
|
|
9642
|
+
<span class="commandbar-flex-container">
|
|
9643
|
+
${SPLIT_ICON_HTML}
|
|
9644
|
+
</span>
|
|
9645
|
+
</button>
|
|
9646
|
+
<button type="button" class="icon-toggle view-mode-toggle" data-ref="preview-btn" title="View" aria-label="View" aria-pressed="false">
|
|
9647
|
+
<span class="commandbar-flex-container">
|
|
9648
|
+
${PREVIEW_ICON_HTML}
|
|
9649
|
+
</span>
|
|
9650
|
+
</button>
|
|
9651
|
+
</div>
|
|
9652
|
+
|
|
9653
|
+
<div class="toolbar-controls" data-ref="toolbar-controls">
|
|
9654
|
+
<button type="button" class="icon-toggle outline-toggle" data-ref="outline-btn" title="Outline" aria-label="Outline" aria-pressed="false">
|
|
9655
|
+
${OUTLINE_ICON_HTML}
|
|
9656
|
+
</button>
|
|
9657
|
+
<button type="button" class="icon-toggle" data-ref="search-btn" title="Find/replace (Mod-F)" aria-label="Find/replace">
|
|
9658
|
+
${SEARCH_ICON_HTML}
|
|
9659
|
+
</button>
|
|
9660
|
+
<button type="button" class="icon-toggle" data-ref="save-btn" title="Save" aria-label="Save">
|
|
9661
|
+
${SAVE_ICON_HTML}
|
|
9662
|
+
</button>
|
|
9663
|
+
<button type="button" class="icon-toggle zoom-toggle" data-ref="zoom-btn" title="Zoom controls" aria-label="Zoom controls">
|
|
9664
|
+
${ZOOM_ICON_HTML}
|
|
9665
|
+
</button>
|
|
9666
|
+
<div class="toolbar-menu width-menu" data-ref="width-controls">
|
|
9667
|
+
<button type="button" class="icon-toggle toolbar-menu-toggle" data-ref="width-menu-btn"
|
|
9668
|
+
title="Page width" aria-label="Page width" aria-haspopup="menu" aria-expanded="false">
|
|
9669
|
+
<span class="toolbar-menu-icon" data-ref="width-menu-icon">${PAGE_WIDTH_DEFAULT_ICON_HTML}</span>
|
|
9670
|
+
</button>
|
|
9671
|
+
<div class="toolbar-popover" data-ref="width-popover" role="menu" aria-label="Page width" hidden>
|
|
9672
|
+
${['narrow', 'default', 'wide', 'full'].map((choice) => `
|
|
9673
|
+
<button type="button" role="menuitemradio" class="icon-toggle toolbar-menu-item" data-width="${choice}"
|
|
9674
|
+
title="${PREVIEW_WIDTH_LABELS[choice]}" aria-label="${PREVIEW_WIDTH_LABELS[choice]}" aria-checked="false">
|
|
9675
|
+
${PREVIEW_WIDTH_ICONS_HTML[choice]}
|
|
9676
|
+
</button>`).join('')}
|
|
9677
|
+
</div>
|
|
9678
|
+
</div>
|
|
9679
|
+
<div class="theme-menu" data-ref="theme-controls">
|
|
9680
|
+
<button type="button" class="icon-toggle theme-menu-toggle" data-ref="theme-menu-btn"
|
|
9681
|
+
title="Color scheme" aria-label="Color scheme" aria-haspopup="menu" aria-expanded="false">
|
|
9682
|
+
<span class="theme-menu-icon" data-ref="theme-menu-icon">${SYSTEM_THEME_ICON_HTML}</span>
|
|
9683
|
+
</button>
|
|
9684
|
+
<div class="theme-popover" data-ref="theme-popover" role="menu" aria-label="Color scheme" hidden>
|
|
9685
|
+
<button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="light-theme-btn"
|
|
9686
|
+
title="Light mode" aria-label="Light mode" aria-checked="false">
|
|
9687
|
+
${LIGHT_THEME_ICON_HTML}
|
|
9688
|
+
</button>
|
|
9689
|
+
<button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="dark-theme-btn"
|
|
9690
|
+
title="Dark mode" aria-label="Dark mode" aria-checked="false">
|
|
9691
|
+
${DARK_THEME_ICON_HTML}
|
|
9692
|
+
</button>
|
|
9693
|
+
<button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="system-theme-btn"
|
|
9694
|
+
title="System setting" aria-label="System setting" aria-checked="false">
|
|
9695
|
+
${SYSTEM_THEME_ICON_HTML}
|
|
9696
|
+
</button>
|
|
9697
|
+
</div>
|
|
9698
|
+
</div>
|
|
9699
|
+
<div class="zoom-popover" data-ref="zoom-popover" hidden role="group" aria-label="Zoom">
|
|
9700
|
+
<span class="zoom-level" data-ref="zoom-level">100%</span>
|
|
9701
|
+
<span class="zoom-stepper">
|
|
9702
|
+
<button type="button" data-action="zoom-out" title="Zoom out" aria-label="Zoom out">-</button>
|
|
9703
|
+
<button type="button" data-action="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
|
|
9704
|
+
</span>
|
|
9705
|
+
<button type="button" class="zoom-reset" data-action="zoom-reset" title="Reset zoom">Reset</button>
|
|
9706
|
+
</div>
|
|
9707
|
+
</div>
|
|
9708
|
+
</header>
|
|
9709
|
+
|
|
9710
|
+
<div class="workspace-shell" data-ref="workspace-shell" hidden>
|
|
9711
|
+
<aside class="nav-pane" data-ref="nav-pane" aria-label="Package contents">
|
|
9712
|
+
<div class="nav-tree" data-ref="nav-tree"></div>
|
|
9713
|
+
</aside>
|
|
9714
|
+
<div class="nav-resizer" data-ref="nav-resizer"
|
|
9715
|
+
role="separator" aria-orientation="vertical" aria-label="Resize contents pane"></div>
|
|
9716
|
+
|
|
9717
|
+
<div class="pane-stack" data-ref="pane-stack">
|
|
9718
|
+
<section class="pane edit-pane" data-ref="edit-pane">
|
|
9719
|
+
<div class="editor-host" data-ref="editor-host"></div>
|
|
9720
|
+
<div class="json-status" data-ref="json-status" role="status" aria-live="polite" hidden></div>
|
|
9721
|
+
</section>
|
|
9722
|
+
<div class="split-resizer" data-ref="split-resizer"
|
|
9723
|
+
role="separator" aria-orientation="vertical" aria-label="Resize split panes"></div>
|
|
9724
|
+
<section class="pane preview-pane" data-ref="preview-pane" tabindex="-1">
|
|
9725
|
+
<article class="preview-content" data-ref="preview-content"></article>
|
|
9726
|
+
</section>
|
|
9727
|
+
<div class="preview-find" data-ref="preview-find" role="search" aria-label="Find in document" hidden>
|
|
9728
|
+
<input type="text" class="preview-find-input" data-ref="preview-find-input"
|
|
9729
|
+
placeholder="Find" aria-label="Find in document" spellcheck="false" autocomplete="off" />
|
|
9730
|
+
<span class="preview-find-count" data-ref="preview-find-count" aria-live="polite"></span>
|
|
9731
|
+
<button type="button" class="preview-find-button" data-ref="preview-find-case"
|
|
9732
|
+
aria-pressed="false" title="Match case" aria-label="Match case">${FIND_CASE_ICON_HTML}</button>
|
|
9733
|
+
<button type="button" class="preview-find-button" data-ref="preview-find-previous"
|
|
9734
|
+
title="Previous match (Shift+Enter)" aria-label="Previous match">${FIND_PREVIOUS_ICON_HTML}</button>
|
|
9735
|
+
<button type="button" class="preview-find-button" data-ref="preview-find-next"
|
|
9736
|
+
title="Next match (Enter)" aria-label="Next match">${FIND_NEXT_ICON_HTML}</button>
|
|
9737
|
+
<button type="button" class="preview-find-button" data-ref="preview-find-close"
|
|
9738
|
+
title="Close (Escape)" aria-label="Close find">${FIND_CLOSE_ICON_HTML}</button>
|
|
9739
|
+
</div>
|
|
9740
|
+
<section class="pane entry-pane" data-ref="entry-pane"></section>
|
|
9741
|
+
</div>
|
|
9742
|
+
<aside class="outline-pane" data-ref="outline-pane" hidden></aside>
|
|
9743
|
+
<div class="outline-resizer" data-ref="outline-resizer"
|
|
9744
|
+
role="separator" aria-orientation="vertical" aria-label="Resize outline"></div>
|
|
9745
|
+
</div>
|
|
9746
|
+
|
|
9747
|
+
<div class="title-dialog-backdrop" data-ref="title-dialog" hidden
|
|
9748
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-title-dialog-heading">
|
|
9749
|
+
<div class="title-dialog">
|
|
9750
|
+
<h3 id="mdzip-title-dialog-heading">Set Document Title</h3>
|
|
9751
|
+
<p>This is the package-level title stored in manifest.json.</p>
|
|
9752
|
+
<input type="text" maxlength="120" data-ref="title-input" aria-label="Document title" />
|
|
9753
|
+
<p class="title-dialog-validation" data-ref="title-validation" hidden>Title cannot be empty.</p>
|
|
9754
|
+
<p>If unset, consumers may fall back to entry point, filename, or first heading.</p>
|
|
9755
|
+
<div class="title-dialog-actions">
|
|
9756
|
+
<button type="button" class="reset-title" data-ref="title-reset-btn">Reset</button>
|
|
9757
|
+
<button type="button" data-action="cancel-title">Cancel</button>
|
|
9758
|
+
<button type="button" class="save-title" data-ref="title-save-btn">Save</button>
|
|
9759
|
+
</div>
|
|
9760
|
+
</div>
|
|
9761
|
+
</div>
|
|
9762
|
+
|
|
9763
|
+
<div class="title-dialog-backdrop" data-ref="conversion-dialog" hidden
|
|
9764
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-conversion-dialog-heading">
|
|
9765
|
+
<div class="title-dialog">
|
|
9766
|
+
<h3 id="mdzip-conversion-dialog-heading">Convert to MDZ?</h3>
|
|
9767
|
+
<p>
|
|
9768
|
+
Regular Markdown files contain only text. Convert this document to an
|
|
9769
|
+
MDZ package to add images, package navigation, and document metadata.
|
|
9770
|
+
</p>
|
|
9771
|
+
<p>The next save will produce an .mdz file.</p>
|
|
9772
|
+
<div class="title-dialog-actions">
|
|
9773
|
+
<button type="button" data-action="cancel-conversion">Cancel</button>
|
|
9774
|
+
<button type="button" class="save-title" data-ref="conversion-confirm-btn">Convert</button>
|
|
9775
|
+
</div>
|
|
9776
|
+
</div>
|
|
9777
|
+
</div>
|
|
9778
|
+
|
|
9779
|
+
<div class="title-dialog-backdrop" data-ref="image-insert-dialog" hidden
|
|
9780
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-image-insert-dialog-heading">
|
|
9781
|
+
<div class="title-dialog image-insert-dialog">
|
|
9782
|
+
<h3 id="mdzip-image-insert-dialog-heading">Insert Image</h3>
|
|
9783
|
+
<p>Choose the Markdown inserted for this image.</p>
|
|
9784
|
+
<fieldset class="image-insert-options">
|
|
9785
|
+
<legend>Output</legend>
|
|
9786
|
+
<label>
|
|
9787
|
+
<input type="radio" name="mdzip-image-insert-mode" value="markdown"
|
|
9788
|
+
data-ref="image-insert-mode-markdown" checked />
|
|
9789
|
+
Markdown image
|
|
9790
|
+
</label>
|
|
9791
|
+
<label>
|
|
9792
|
+
<input type="radio" name="mdzip-image-insert-mode" value="html"
|
|
9793
|
+
data-ref="image-insert-mode-html" />
|
|
9794
|
+
HTML <img> with sizing
|
|
9795
|
+
</label>
|
|
9796
|
+
</fieldset>
|
|
9797
|
+
<label class="image-insert-field">
|
|
9798
|
+
<span>Alt text</span>
|
|
9799
|
+
<input type="text" data-ref="image-insert-alt" />
|
|
9800
|
+
</label>
|
|
9801
|
+
<div class="image-insert-grid">
|
|
9802
|
+
<label class="image-insert-field">
|
|
9803
|
+
<span>Size by</span>
|
|
9804
|
+
<select data-ref="image-insert-size-mode">
|
|
9805
|
+
<option value="original">Original size</option>
|
|
9806
|
+
<option value="width" selected>Width</option>
|
|
9807
|
+
<option value="height">Height</option>
|
|
9808
|
+
<option value="percent">Percent</option>
|
|
9809
|
+
</select>
|
|
9810
|
+
</label>
|
|
9811
|
+
<label class="image-insert-field">
|
|
9812
|
+
<span>Value</span>
|
|
9813
|
+
<input type="number" min="1" step="1" data-ref="image-insert-size-value" />
|
|
9814
|
+
</label>
|
|
9815
|
+
</div>
|
|
9816
|
+
<label class="image-insert-field">
|
|
9817
|
+
<span>Position</span>
|
|
9818
|
+
<select data-ref="image-insert-position">
|
|
9819
|
+
<option value="inline">Inline/default</option>
|
|
9820
|
+
<option value="left">Left</option>
|
|
9821
|
+
<option value="center">Center</option>
|
|
9822
|
+
<option value="right">Right</option>
|
|
9823
|
+
<option value="wrap-left">Wrap left</option>
|
|
9824
|
+
<option value="wrap-right">Wrap right</option>
|
|
9825
|
+
</select>
|
|
9826
|
+
</label>
|
|
9827
|
+
<div class="title-dialog-actions">
|
|
9828
|
+
<button type="button" data-action="cancel-image-insert">Cancel</button>
|
|
9829
|
+
<button type="button" class="save-title" data-ref="image-insert-confirm-btn">Insert</button>
|
|
9830
|
+
</div>
|
|
9831
|
+
</div>
|
|
9832
|
+
</div>
|
|
9833
|
+
|
|
9834
|
+
<div class="title-dialog-backdrop" data-ref="pack-files-dialog" hidden
|
|
9835
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-pack-files-dialog-heading">
|
|
9836
|
+
<div class="title-dialog pack-files-dialog">
|
|
9837
|
+
<h3 id="mdzip-pack-files-dialog-heading">Package Markdown Files</h3>
|
|
9838
|
+
<p>These files contain more than one Markdown document. Choose how to package them.</p>
|
|
9839
|
+
<fieldset class="pack-files-options">
|
|
9840
|
+
<legend>Mode</legend>
|
|
9841
|
+
<label>
|
|
9842
|
+
<input type="radio" name="mdzip-pack-files-mode" value="document"
|
|
9843
|
+
data-ref="pack-files-mode-document" checked />
|
|
9844
|
+
Document — one primary page; the rest are attached
|
|
9845
|
+
</label>
|
|
9846
|
+
<label>
|
|
9847
|
+
<input type="radio" name="mdzip-pack-files-mode" value="project"
|
|
9848
|
+
data-ref="pack-files-mode-project" />
|
|
9849
|
+
Project — a set of related documents
|
|
9850
|
+
</label>
|
|
9851
|
+
</fieldset>
|
|
9852
|
+
<label class="pack-files-field">
|
|
9853
|
+
<span>Entry point</span>
|
|
9854
|
+
<select data-ref="pack-files-entry"></select>
|
|
9855
|
+
</label>
|
|
9856
|
+
<div class="title-dialog-actions">
|
|
9857
|
+
<button type="button" data-action="cancel-pack-files">Cancel</button>
|
|
9858
|
+
<button type="button" class="save-title" data-ref="pack-files-confirm-btn">Package</button>
|
|
9859
|
+
</div>
|
|
9860
|
+
</div>
|
|
9861
|
+
</div>
|
|
9862
|
+
|
|
9863
|
+
<div class="title-dialog-backdrop" data-ref="copy-render-dialog" hidden
|
|
9864
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-copy-render-dialog-heading">
|
|
9865
|
+
<div class="title-dialog copy-render-dialog">
|
|
9866
|
+
<h3 id="mdzip-copy-render-dialog-heading" data-ref="copy-render-heading">Copying document...</h3>
|
|
9867
|
+
<div data-ref="copy-render-progress-section">
|
|
9868
|
+
<p data-ref="copy-render-progress-text">Rendering the full document...</p>
|
|
9869
|
+
<div class="copy-render-progress-track">
|
|
9870
|
+
<div class="copy-render-progress-bar" data-ref="copy-render-progress-bar"></div>
|
|
9871
|
+
</div>
|
|
9872
|
+
</div>
|
|
9873
|
+
<p data-ref="copy-render-ready-text" hidden>
|
|
9874
|
+
The document is ready. Browsers only allow a clipboard write right after a click, so this needs one more —
|
|
9875
|
+
click Copy to finish.
|
|
9876
|
+
</p>
|
|
9877
|
+
<p data-ref="copy-render-done-text" hidden></p>
|
|
9878
|
+
<div class="title-dialog-actions">
|
|
9879
|
+
<button type="button" data-action="cancel-copy-render" data-ref="copy-render-cancel-btn">Cancel</button>
|
|
9880
|
+
<button type="button" data-action="cancel-copy-ready" data-ref="copy-render-ready-cancel-btn" hidden>Cancel</button>
|
|
9881
|
+
<button type="button" class="save-title" data-action="confirm-copy-ready" data-ref="copy-render-confirm-btn" hidden>Copy</button>
|
|
9882
|
+
<button type="button" class="save-title" data-action="dismiss-copy-render" data-ref="copy-render-dismiss-btn" hidden>Dismiss</button>
|
|
9883
|
+
</div>
|
|
9884
|
+
</div>
|
|
9885
|
+
</div>
|
|
9886
|
+
|
|
9887
|
+
<div class="title-dialog-backdrop" data-ref="metadata-dialog" hidden
|
|
9888
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-metadata-dialog-heading">
|
|
9889
|
+
<div class="title-dialog metadata-dialog">
|
|
9890
|
+
<h3 id="mdzip-metadata-dialog-heading">Document Information</h3>
|
|
9891
|
+
<dl data-ref="metadata-list"></dl>
|
|
9892
|
+
<h4>Libraries</h4>
|
|
9893
|
+
<dl data-ref="library-list"></dl>
|
|
9894
|
+
<div class="title-dialog-actions">
|
|
9895
|
+
<button type="button" class="save-title" data-action="close-metadata">Close</button>
|
|
9896
|
+
</div>
|
|
9897
|
+
</div>
|
|
9898
|
+
</div>
|
|
9899
|
+
|
|
9900
|
+
<div class="title-dialog-backdrop" data-ref="name-dialog" hidden
|
|
9901
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-name-dialog-heading">
|
|
9902
|
+
<div class="title-dialog">
|
|
9903
|
+
<h3 id="mdzip-name-dialog-heading" data-ref="name-dialog-heading">New Markdown File</h3>
|
|
9904
|
+
<input type="text" maxlength="260" data-ref="name-input" aria-label="File name" />
|
|
9905
|
+
<p class="title-dialog-validation" data-ref="name-validation" hidden></p>
|
|
9906
|
+
<div class="title-dialog-actions">
|
|
9907
|
+
<button type="button" data-action="cancel-name">Cancel</button>
|
|
9908
|
+
<button type="button" class="save-title" data-ref="name-confirm-btn">Create</button>
|
|
9909
|
+
</div>
|
|
9910
|
+
</div>
|
|
9911
|
+
</div>
|
|
9912
|
+
|
|
9913
|
+
<div class="title-dialog-backdrop" data-ref="delete-dialog" hidden
|
|
9914
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-delete-dialog-heading">
|
|
9915
|
+
<div class="title-dialog">
|
|
9916
|
+
<h3 id="mdzip-delete-dialog-heading">Delete File?</h3>
|
|
9917
|
+
<p data-ref="delete-dialog-text"></p>
|
|
9918
|
+
<div class="title-dialog-actions">
|
|
9919
|
+
<button type="button" data-action="cancel-delete">Cancel</button>
|
|
9920
|
+
<button type="button" class="danger-action" data-ref="delete-confirm-btn">Delete</button>
|
|
9921
|
+
</div>
|
|
9922
|
+
</div>
|
|
9923
|
+
</div>
|
|
9924
|
+
|
|
9925
|
+
<div class="title-dialog-backdrop" data-ref="confirm-dialog" hidden
|
|
9926
|
+
role="dialog" aria-modal="true" aria-labelledby="mdzip-confirm-dialog-heading">
|
|
9927
|
+
<div class="title-dialog">
|
|
9928
|
+
<h3 id="mdzip-confirm-dialog-heading" data-ref="confirm-dialog-title"></h3>
|
|
9929
|
+
<p data-ref="confirm-dialog-text"></p>
|
|
9930
|
+
<div class="title-dialog-actions">
|
|
9931
|
+
<button type="button" data-action="cancel-confirm">Cancel</button>
|
|
9932
|
+
<button type="button" class="danger-action" data-ref="confirm-dialog-ok"></button>
|
|
9933
|
+
</div>
|
|
9934
|
+
</div>
|
|
9935
|
+
</div>
|
|
9936
|
+
|
|
9937
|
+
<input type="file" data-ref="replace-input" hidden />
|
|
9938
|
+
<input type="file" data-ref="add-files-input" multiple hidden />
|
|
9939
|
+
|
|
9940
|
+
<div class="nav-context-menu" data-ref="nav-menu" hidden role="menu"></div>
|
|
9941
|
+
|
|
9942
|
+
<div class="mdzip-tooltip" data-ref="tooltip" role="tooltip" hidden></div>
|
|
9943
|
+
|
|
9944
|
+
<div class="mdzip-copy-toast" data-ref="copy-toast" role="status" aria-live="polite" hidden></div>
|
|
9945
|
+
|
|
9946
|
+
<p class="mdzip-empty" data-ref="empty-state">No MDZip workspace loaded.</p>
|
|
9947
|
+
</section>
|
|
8392
9948
|
`;
|
|
8393
9949
|
//# sourceMappingURL=view.js.map
|