collabmd 0.1.47 → 0.1.48
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/README.md +9 -6
- package/dist/client/assets/JetBrainsMono-Regular-BQaDgvhP.woff2 +0 -0
- package/dist/client/assets/babel-CY5KOv-I.js +16 -0
- package/dist/client/assets/comment-ui-shared-DuoyznXW.js +7 -0
- package/dist/client/assets/dist-ChRoo3IB.js +9 -0
- package/dist/client/assets/document-formatter-Dxl_a8XO.js +2 -0
- package/dist/client/assets/{drawio-editor-BjrxTe3l.js → drawio-editor-BVaNNtYp.js} +2 -2
- package/dist/client/assets/{drawioEditor-DUVZjSSr.js → drawioEditor-BkIBlXx0.js} +2 -2
- package/dist/client/assets/editor-session-DMyVdHLj.js +54 -0
- package/dist/client/assets/embedded-editor-base-B3l6Xy65.css +1 -0
- package/dist/client/assets/estree-CuT_pB8K.js +44 -0
- package/dist/client/assets/{excalidraw-editor-BlcN6umJ.css → excalidraw-editor-BbSbI80a.css} +1 -1
- package/dist/client/assets/excalidraw-editor-BjYaNEMY.js +9 -0
- package/dist/client/assets/{excalidrawEditor-B0jOK3lv.js → excalidrawEditor-ChqF_d82.js} +2 -2
- package/dist/client/assets/export-page-Dyu0XCbu.js +57 -0
- package/dist/client/assets/exportDocument-CJBx4Xjx.css +1 -0
- package/dist/client/assets/{exportDocument-Dg9MjkIk.js → exportDocument-Dgvfa2Sd.js} +2 -2
- package/dist/client/assets/{file-icon-svg-CQAjlWjK.js → file-icon-svg-Y_kpF957.js} +1 -1
- package/dist/client/assets/file-kind-BwMIcZbi.js +1 -0
- package/dist/client/assets/file-search-DDLyyLDU.js +1 -0
- package/dist/client/assets/html-Cdnr2qzU.js +25 -0
- package/dist/client/assets/index-CSNIMyOP.css +1 -0
- package/dist/client/assets/index-DG3N2Ps-.js +2 -0
- package/dist/client/assets/main-D0wCxpVn.js +903 -0
- package/dist/client/assets/markdown-CByV-4CU.js +70 -0
- package/dist/client/assets/mermaid.core-BJRLUQZE.js +11 -0
- package/dist/client/assets/{preview-render-compiler-BApvlLLo.js → preview-render-compiler-CrJIooVD.js} +2 -2
- package/dist/client/assets/preview-render-compiler-O0JxBVNF.js +1 -0
- package/dist/client/assets/{preview-render-profile-CE-5rVTC.js → preview-render-profile-B4RWYWHt.js} +1 -1
- package/dist/client/assets/{preview-render-worker-BmN79bVc.js → preview-render-worker-_QTxqKvP.js} +22 -22
- package/dist/client/assets/quick-switcher-controller-CaEjEtq_.js +1 -0
- package/dist/client/assets/standalone-6z5x8CWe.js +29 -0
- package/dist/client/assets/{vault-api-client-_LpV1aIn.js → vault-api-client-BkwdFjx0.js} +2 -2
- package/dist/client/assets/{es-CAsWR6hG.js → vault-utils-DvoSftJT.js} +1 -1
- package/dist/client/assets/yaml-9ltHPDNO.js +154 -0
- package/dist/client/drawio-editor.html +1 -1
- package/dist/client/excalidraw-editor.html +1 -1
- package/dist/client/export-document.html +2 -2
- package/dist/client/index.html +41 -19
- package/package.json +4 -1
- package/src/client/app/index.html +39 -17
- package/src/client/application/app-shell/export-feature.js +17 -1
- package/src/client/application/app-shell/git-feature.js +28 -9
- package/src/client/application/app-shell/ui-feature-identity.js +13 -0
- package/src/client/application/app-shell/ui-feature-shell.js +164 -9
- package/src/client/application/app-shell-elements.js +4 -0
- package/src/client/application/workspace-coordinator.js +21 -4
- package/src/client/application/workspace-preview-controller.js +120 -2
- package/src/client/application/workspace-route-controller.js +4 -1
- package/src/client/assets/vendor/jetbrains-mono/JetBrainsMono-Regular.woff2 +0 -0
- package/src/client/assets/vendor/jetbrains-mono/OFL.txt +93 -0
- package/src/client/bootstrap/collabmd-app-shell.js +21 -5
- package/src/client/domain/document-formatter.js +193 -0
- package/src/client/domain/file-search.js +73 -0
- package/src/client/domain/git-labels.js +5 -0
- package/src/client/domain/vault-paths.js +6 -4
- package/src/client/domain/wiki-link-completions.js +20 -20
- package/src/client/drawio-editor.js +8 -3
- package/src/client/excalidraw-editor.js +152 -6
- package/src/client/export/export-host.js +56 -35
- package/src/client/export/export-page.js +14 -4
- package/src/client/export/export-pipeline.js +266 -25
- package/src/client/infrastructure/editor-session.js +4 -0
- package/src/client/infrastructure/editor-view-adapter.js +60 -14
- package/src/client/presentation/bases-preview-controller.js +35 -11
- package/src/client/presentation/file-action-controller.js +15 -2
- package/src/client/presentation/file-explorer-controller.js +3 -0
- package/src/client/presentation/file-explorer-view.js +2 -1
- package/src/client/presentation/file-history-view-controller.js +6 -1
- package/src/client/presentation/file-tree-state.js +1 -11
- package/src/client/presentation/git-diff-view-controller.js +36 -11
- package/src/client/presentation/git-panel-controller.js +10 -6
- package/src/client/presentation/quick-switcher-controller.js +54 -154
- package/src/client/styles/components/scrollbars.css +10 -0
- package/src/client/styles/export-document.css +44 -29
- package/src/client/styles/features/collaboration-presence.css +13 -1
- package/src/client/styles/features/preview-markdown.css +54 -0
- package/src/client/styles/foundation/tokens.css +8 -0
- package/src/client/styles/layout/shell.css +76 -24
- package/src/client/styles/layout/view-modes.css +2 -0
- package/src/client/styles/overrides/codemirror.css +31 -19
- package/src/client/styles/surfaces/excalidraw-editor.css +42 -0
- package/src/domain/file-kind.js +12 -1
- package/src/server/domain/ripgrep-search-service.js +110 -37
- package/src/server/infrastructure/persistence/path-utils.js +10 -4
- package/src/server/infrastructure/persistence/vault-file-store.js +2 -0
- package/dist/client/assets/comment-ui-shared-DWkk9Vh3.js +0 -7
- package/dist/client/assets/editor-session-DfZuRgB_.js +0 -54
- package/dist/client/assets/embedded-editor-base-DvMynhKu.css +0 -1
- package/dist/client/assets/excalidraw-editor-D7pnUCLH.js +0 -9
- package/dist/client/assets/export-page-Bs3xE1fg.js +0 -57
- package/dist/client/assets/exportDocument-PnYU3v1s.css +0 -1
- package/dist/client/assets/file-kind-BbqgGzpc.js +0 -1
- package/dist/client/assets/index-BIpgxyGZ.css +0 -1
- package/dist/client/assets/index-Z5sI0Bj-.js +0 -2
- package/dist/client/assets/main-Dwnj9Gaq.js +0 -903
- package/dist/client/assets/mermaid.core-CLZBlpIW.js +0 -11
- package/dist/client/assets/preview-render-compiler-BQ_3h9vD.js +0 -1
- package/dist/client/assets/quick-switcher-controller-ButWPmCI.js +0 -12
- package/dist/client/assets/vault-utils-wdQ0RNR9.js +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -168,6 +168,7 @@ export class CollabMdAppShell {
|
|
|
168
168
|
this.chatToastController = new ToastController(this.elements.chatToastContainer);
|
|
169
169
|
this.fileExplorer = new FileExplorerController({
|
|
170
170
|
mobileBreakpointQuery: this.mobileBreakpointQuery,
|
|
171
|
+
onDirectoryExport: (directoryPath, format) => this.handleDirectoryExportRequest(directoryPath, format),
|
|
171
172
|
onFileDelete: () => this.navigation.navigateToFile(null),
|
|
172
173
|
onFileSelect: (filePath) => this.workspaceRouteController.handleFileSelection(filePath, {
|
|
173
174
|
closeSidebarOnMobile: true,
|
|
@@ -208,7 +209,11 @@ export class CollabMdAppShell {
|
|
|
208
209
|
});
|
|
209
210
|
this.outlineController = new OutlineController({
|
|
210
211
|
mobileBreakpointQuery: this.mobileBreakpointQuery,
|
|
211
|
-
onNavigateToHeading: ({ sourceLine }) => {
|
|
212
|
+
onNavigateToHeading: ({ headingId, sourceLine }) => {
|
|
213
|
+
const heading = document.getElementById(headingId);
|
|
214
|
+
if (this.elements.previewContent?.contains(heading)) {
|
|
215
|
+
this.unfoldPreviewHeading(heading);
|
|
216
|
+
}
|
|
212
217
|
if (!Number.isFinite(sourceLine)) return;
|
|
213
218
|
this.scrollSyncController.suspendSync(250);
|
|
214
219
|
this.session?.scrollToLine(sourceLine, 0);
|
|
@@ -254,6 +259,7 @@ export class CollabMdAppShell {
|
|
|
254
259
|
this.excalidrawEmbed.reconcileEmbeds(this.elements.previewContent, { isLargeDocument: stats.isLargeDocument });
|
|
255
260
|
this.scrollSyncController.setLargeDocumentMode(stats.isLargeDocument);
|
|
256
261
|
this.syncPreviewCodeCopyButtons();
|
|
262
|
+
this.syncPreviewHeadingFoldButtons();
|
|
257
263
|
this.syncPreviewHeadingLinkButtons();
|
|
258
264
|
this.applyPendingPreviewRouteAnchor({ behavior: 'auto', clearMissing: true });
|
|
259
265
|
this.schedulePreviewLayoutSync({ delayMs: 0 });
|
|
@@ -500,8 +506,15 @@ export class CollabMdAppShell {
|
|
|
500
506
|
this.clearInitialFileBootstrap();
|
|
501
507
|
},
|
|
502
508
|
onConnectionChange: (state) => this.handleConnectionChange(state),
|
|
503
|
-
onContentChange: ({ isBase, isMermaid, isPlantUml, isStructurizrWorkspace }) => {
|
|
509
|
+
onContentChange: ({ isBase, isHtml, isMermaid, isPlantUml, isStructurizrWorkspace }) => {
|
|
504
510
|
this.handleCommentEditorContentChange();
|
|
511
|
+
if (isHtml) {
|
|
512
|
+
this.workspacePreviewController.renderHtmlFilePreview({
|
|
513
|
+
content: this.session?.getText?.() ?? '',
|
|
514
|
+
});
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
505
518
|
if (isBase) {
|
|
506
519
|
this.scheduleBaseFilePreview(this.currentFilePath, {
|
|
507
520
|
source: this.session?.getText?.() ?? '',
|
|
@@ -524,10 +537,11 @@ export class CollabMdAppShell {
|
|
|
524
537
|
},
|
|
525
538
|
onCommentsChange: (threads) => this.handleCommentThreadsChange(threads),
|
|
526
539
|
onFileAwarenessChange: (users) => this.updateFileAwareness(users),
|
|
527
|
-
onFileOpenError: () => {
|
|
528
|
-
|
|
540
|
+
onFileOpenError: ({ code } = {}) => {
|
|
541
|
+
const notFound = code === 'not-found';
|
|
542
|
+
this.showEditorLoadError(notFound ? 'File not found' : 'Failed to load file');
|
|
529
543
|
this.syncWrapToggle();
|
|
530
|
-
this.toastController.show('Failed to initialize editor');
|
|
544
|
+
this.toastController.show(notFound ? 'File not found' : 'Failed to initialize editor');
|
|
531
545
|
},
|
|
532
546
|
onFileOpenReady: () => {
|
|
533
547
|
this.hideEditorLoading();
|
|
@@ -545,6 +559,7 @@ export class CollabMdAppShell {
|
|
|
545
559
|
onRenderDrawioPreview: (filePath) => this.workspacePreviewController.renderDrawioFilePreview(filePath),
|
|
546
560
|
onRenderBasePreview: (filePath) => this.renderBaseFilePreview(filePath),
|
|
547
561
|
onRenderExcalidrawPreview: (filePath) => this.workspacePreviewController.renderExcalidrawFilePreview(filePath),
|
|
562
|
+
onRenderHtmlPreview: (options) => this.workspacePreviewController.renderHtmlFilePreview(options),
|
|
548
563
|
onRenderImagePreview: (filePath) => this.workspacePreviewController.renderImageFilePreview(filePath),
|
|
549
564
|
onRenderPdfPreview: (filePath) => this.workspacePreviewController.renderPdfFilePreview(filePath),
|
|
550
565
|
onRenderStructurizrPreview: (filePath, options) => this.workspacePreviewController.renderStructurizrFilePreview(filePath, options),
|
|
@@ -561,6 +576,7 @@ export class CollabMdAppShell {
|
|
|
561
576
|
});
|
|
562
577
|
this.syncCommentChrome(filePath);
|
|
563
578
|
this.syncFileHistoryButton({ filePath, mode: 'editor' });
|
|
579
|
+
this.syncReviewFileChangesButton({ filePath, mode: 'editor' });
|
|
564
580
|
if (this.elements.activeFileName) {
|
|
565
581
|
this.elements.activeFileName.textContent = displayName;
|
|
566
582
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getVaultFileKind } from '../../domain/file-kind.js';
|
|
2
|
+
|
|
3
|
+
const FORMATTABLE_FILE_KINDS = new Set(['base', 'html', 'markdown', 'mermaid', 'plantuml']);
|
|
4
|
+
const PLANTUML_BLOCK_OPENERS = [
|
|
5
|
+
[/^if\b.*\bthen\b/iu, 'endif'],
|
|
6
|
+
[/^while\b/iu, 'endwhile'],
|
|
7
|
+
[/^repeat\b(?!\s+while\b)/iu, 'repeat while'],
|
|
8
|
+
[/^switch\b/iu, 'endswitch'],
|
|
9
|
+
[/^fork\b(?!\s+again\b)/iu, 'end fork'],
|
|
10
|
+
[/^split\b(?!\s+again\b)/iu, 'end split'],
|
|
11
|
+
[/^(?:alt|opt|loop|par|critical|group|box|ref\s+over)\b/iu, 'end'],
|
|
12
|
+
[/^break\s+\S/iu, 'end'],
|
|
13
|
+
];
|
|
14
|
+
const PLANTUML_MIDDLE_PATTERN = /^(?:else(?:if)?|and|fork\s+again|split\s+again|case|option)\b/iu;
|
|
15
|
+
|
|
16
|
+
function getPlantUmlOpaqueBlock(trimmedLine) {
|
|
17
|
+
if (trimmedLine.startsWith("/'")) {
|
|
18
|
+
return trimmedLine.slice(2).includes("'/")
|
|
19
|
+
? { oneLine: true }
|
|
20
|
+
: { end: (line) => line.includes("'/") };
|
|
21
|
+
}
|
|
22
|
+
const tripleQuoteCount = trimmedLine.split('"""').length - 1;
|
|
23
|
+
if (tripleQuoteCount % 2 === 1) return { end: (line) => line.includes('"""') };
|
|
24
|
+
if (/^<style>.*<\/style>\s*$/iu.test(trimmedLine)) return { oneLine: true };
|
|
25
|
+
if (/^<style>\s*$/iu.test(trimmedLine)) return { end: (line) => /<\/style>/iu.test(line) };
|
|
26
|
+
if (/^!(?:if|ifdef|ifndef)\b/iu.test(trimmedLine)) {
|
|
27
|
+
let depth = 1;
|
|
28
|
+
return { end: (line) => {
|
|
29
|
+
if (/^!(?:if|ifdef|ifndef)\b/iu.test(line)) depth += 1;
|
|
30
|
+
if (/^!endif\b/iu.test(line)) depth -= 1;
|
|
31
|
+
return depth === 0;
|
|
32
|
+
} };
|
|
33
|
+
}
|
|
34
|
+
if (/^!(?:while|foreach)\b/iu.test(trimmedLine)) {
|
|
35
|
+
const endPattern = /^!while\b/iu.test(trimmedLine) ? /^!endwhile\b/iu : /^!endfor\b/iu;
|
|
36
|
+
return { end: (line) => endPattern.test(line) };
|
|
37
|
+
}
|
|
38
|
+
if (/^!(?:definelong|procedure|function)\b/iu.test(trimmedLine)) {
|
|
39
|
+
return { end: (line) => /^!end(?:definelong|procedure|function)\b/iu.test(line) };
|
|
40
|
+
}
|
|
41
|
+
if (/^!\w+/u.test(trimmedLine)) return { oneLine: true };
|
|
42
|
+
if (/^(?:[hr]?note|legend)\b(?!.*:\s*\S)/iu.test(trimmedLine)) {
|
|
43
|
+
return { end: (line) => /^(?:end\s+note|endlegend)\b/iu.test(line) };
|
|
44
|
+
}
|
|
45
|
+
if (/^(?:title|header|footer|caption)\s*$/iu.test(trimmedLine)) {
|
|
46
|
+
const blockName = trimmedLine.toLowerCase();
|
|
47
|
+
return { end: (line) => line.toLowerCase().replace(/\s/gu, '') === `end${blockName}` };
|
|
48
|
+
}
|
|
49
|
+
if (/^(?:json|yaml|salt|sprite)\b.*\{\s*$/iu.test(trimmedLine)) {
|
|
50
|
+
return { braceDepth: 1 };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function countPlantUmlBraces(line) {
|
|
56
|
+
let count = 0;
|
|
57
|
+
let escaped = false;
|
|
58
|
+
let quoted = false;
|
|
59
|
+
for (const character of line) {
|
|
60
|
+
if (escaped) {
|
|
61
|
+
escaped = false;
|
|
62
|
+
} else if (character === '\\') {
|
|
63
|
+
escaped = true;
|
|
64
|
+
} else if (character === '"') {
|
|
65
|
+
quoted = !quoted;
|
|
66
|
+
} else if (!quoted && character === '{') {
|
|
67
|
+
count += 1;
|
|
68
|
+
} else if (!quoted && character === '}') {
|
|
69
|
+
count -= 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return count;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getPlantUmlCloser(trimmedLine) {
|
|
76
|
+
if (/^\}\s*$/u.test(trimmedLine)) return '}';
|
|
77
|
+
if (/^endif\b/iu.test(trimmedLine)) return 'endif';
|
|
78
|
+
if (/^endwhile\b/iu.test(trimmedLine)) return 'endwhile';
|
|
79
|
+
if (/^repeat\s+while\b/iu.test(trimmedLine)) return 'repeat while';
|
|
80
|
+
if (/^endswitch\b/iu.test(trimmedLine)) return 'endswitch';
|
|
81
|
+
if (/^end\s+fork\b/iu.test(trimmedLine)) return 'end fork';
|
|
82
|
+
if (/^end\s+split\b/iu.test(trimmedLine)) return 'end split';
|
|
83
|
+
if (/^end(?:\s+\w+)?\s*$/iu.test(trimmedLine)) return 'end';
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getPlantUmlOpener(trimmedLine) {
|
|
88
|
+
if (/\{\s*$/u.test(trimmedLine)) return '}';
|
|
89
|
+
return PLANTUML_BLOCK_OPENERS.find(([pattern]) => pattern.test(trimmedLine))?.[1] ?? null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function indentPlantUml(source) {
|
|
93
|
+
const parts = String(source ?? '').split(/(\r\n|\n|\r)/u);
|
|
94
|
+
const stack = [];
|
|
95
|
+
let opaqueBlock = null;
|
|
96
|
+
|
|
97
|
+
for (let index = 0; index < parts.length; index += 2) {
|
|
98
|
+
const line = parts[index];
|
|
99
|
+
const content = line.replace(/^[\t ]*/u, '');
|
|
100
|
+
const trimmedLine = content.trimEnd();
|
|
101
|
+
|
|
102
|
+
if (opaqueBlock) {
|
|
103
|
+
if (opaqueBlock.braceDepth) {
|
|
104
|
+
opaqueBlock.braceDepth += countPlantUmlBraces(trimmedLine);
|
|
105
|
+
if (opaqueBlock.braceDepth <= 0) opaqueBlock = null;
|
|
106
|
+
} else if (opaqueBlock.end(trimmedLine)) {
|
|
107
|
+
opaqueBlock = null;
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const nextOpaqueBlock = getPlantUmlOpaqueBlock(trimmedLine);
|
|
113
|
+
if (nextOpaqueBlock) {
|
|
114
|
+
opaqueBlock = nextOpaqueBlock.oneLine ? null : nextOpaqueBlock;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!trimmedLine) continue;
|
|
118
|
+
|
|
119
|
+
const closer = getPlantUmlCloser(trimmedLine);
|
|
120
|
+
const closesCurrentBlock = closer && stack.at(-1) === closer;
|
|
121
|
+
const isMiddle = PLANTUML_MIDDLE_PATTERN.test(trimmedLine) && stack.length > 0;
|
|
122
|
+
const opener = getPlantUmlOpener(trimmedLine);
|
|
123
|
+
|
|
124
|
+
if (stack.length > 0 || closesCurrentBlock || isMiddle || opener) {
|
|
125
|
+
const depth = Math.max(0, stack.length - (closesCurrentBlock || isMiddle ? 1 : 0));
|
|
126
|
+
parts[index] = `${' '.repeat(depth)}${content}`;
|
|
127
|
+
}
|
|
128
|
+
if (closesCurrentBlock) stack.pop();
|
|
129
|
+
if (opener) stack.push(opener);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return parts.join('');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function canFormatDocument(filePath) {
|
|
136
|
+
return FORMATTABLE_FILE_KINDS.has(getVaultFileKind(filePath));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function formatWithPrettier(source, parser) {
|
|
140
|
+
let pluginImport = import('prettier/plugins/markdown');
|
|
141
|
+
if (parser === 'yaml') pluginImport = import('prettier/plugins/yaml');
|
|
142
|
+
if (parser === 'html') pluginImport = import('prettier/plugins/html');
|
|
143
|
+
|
|
144
|
+
const [{ format }, plugin] = await Promise.all([
|
|
145
|
+
import('prettier/standalone'),
|
|
146
|
+
pluginImport,
|
|
147
|
+
]);
|
|
148
|
+
const plugins = [plugin.default];
|
|
149
|
+
|
|
150
|
+
if (parser === 'mdx') {
|
|
151
|
+
const [babel, estree] = await Promise.all([
|
|
152
|
+
import('prettier/plugins/babel'),
|
|
153
|
+
import('prettier/plugins/estree'),
|
|
154
|
+
]);
|
|
155
|
+
plugins.push(babel.default, estree.default);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return format(source, {
|
|
159
|
+
parser,
|
|
160
|
+
plugins,
|
|
161
|
+
proseWrap: 'preserve',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function formatMermaid(source) {
|
|
166
|
+
const [{ default: mermaid }, { formatMermaid }] = await Promise.all([
|
|
167
|
+
import('mermaid'),
|
|
168
|
+
import('mermaid-formatter'),
|
|
169
|
+
]);
|
|
170
|
+
if (!await mermaid.parse(source, { suppressErrors: true })) {
|
|
171
|
+
throw new Error('Mermaid syntax is invalid');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const formatted = formatMermaid(source, { indentSize: 2 });
|
|
175
|
+
if (!await mermaid.parse(formatted, { suppressErrors: true })) {
|
|
176
|
+
throw new Error('The formatter produced invalid Mermaid syntax');
|
|
177
|
+
}
|
|
178
|
+
return formatted;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function formatDocumentText(filePath, source) {
|
|
182
|
+
const kind = getVaultFileKind(filePath);
|
|
183
|
+
|
|
184
|
+
if (kind === 'mermaid') return formatMermaid(source);
|
|
185
|
+
if (kind === 'plantuml') return indentPlantUml(source);
|
|
186
|
+
if (kind === 'base') return formatWithPrettier(source, 'yaml');
|
|
187
|
+
if (kind === 'html') return formatWithPrettier(source, 'html');
|
|
188
|
+
if (kind === 'markdown') {
|
|
189
|
+
const parser = String(filePath).toLowerCase().endsWith('.mdx') ? 'mdx' : 'markdown';
|
|
190
|
+
return formatWithPrettier(source, parser);
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { stripVaultFileExtension } from '../../domain/file-kind.js';
|
|
2
|
+
|
|
3
|
+
function createRangeIndices(start, length) {
|
|
4
|
+
return Array.from({ length }, (_, index) => start + index);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function findFuzzyMatch(text, query) {
|
|
8
|
+
const indices = [];
|
|
9
|
+
let queryIndex = 0;
|
|
10
|
+
let score = 0;
|
|
11
|
+
let consecutiveBonus = 0;
|
|
12
|
+
|
|
13
|
+
for (let index = 0; index < text.length && queryIndex < query.length; index += 1) {
|
|
14
|
+
if (/\s/u.test(query[queryIndex]) && /[\s/\\_-]/u.test(text[index])) {
|
|
15
|
+
queryIndex += 1;
|
|
16
|
+
consecutiveBonus = 0;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (text[index] !== query[queryIndex]) {
|
|
21
|
+
if (queryIndex > 0) score -= 0.25;
|
|
22
|
+
consecutiveBonus = 0;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
queryIndex += 1;
|
|
27
|
+
indices.push(index);
|
|
28
|
+
consecutiveBonus += 1;
|
|
29
|
+
score += consecutiveBonus;
|
|
30
|
+
|
|
31
|
+
if (index === 0 || /[/\-_ ]/u.test(text[index - 1])) score += 5;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return queryIndex === query.length && score > 0 ? { indices, score } : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createFileSearchEntry(filePath) {
|
|
38
|
+
const displayName = stripVaultFileExtension(filePath);
|
|
39
|
+
const fileName = displayName.split('/').pop() || displayName;
|
|
40
|
+
const rawFileName = String(filePath ?? '').split('/').pop() || String(filePath ?? '');
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
displayName,
|
|
44
|
+
fileName,
|
|
45
|
+
filePath,
|
|
46
|
+
lowerDisplayName: displayName.toLowerCase(),
|
|
47
|
+
lowerFileName: fileName.toLowerCase(),
|
|
48
|
+
lowerPath: String(filePath).toLowerCase(),
|
|
49
|
+
lowerRawFileName: rawFileName.toLowerCase(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function findFileSearchMatch(entry, query) {
|
|
54
|
+
const fileNameStart = entry.displayName.length - entry.fileName.length;
|
|
55
|
+
const searches = [
|
|
56
|
+
[entry.lowerFileName, fileNameStart, 100],
|
|
57
|
+
[entry.lowerDisplayName, 0, 50],
|
|
58
|
+
[entry.lowerRawFileName, fileNameStart, 40],
|
|
59
|
+
[entry.lowerPath, 0, 25],
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
for (const [text, offset, baseScore] of searches) {
|
|
63
|
+
const index = text.indexOf(query);
|
|
64
|
+
if (index >= 0) {
|
|
65
|
+
return {
|
|
66
|
+
indices: createRangeIndices(index + offset, query.length),
|
|
67
|
+
score: baseScore + (1 / text.length),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return findFuzzyMatch(entry.lowerDisplayName, query);
|
|
73
|
+
}
|
|
@@ -8,10 +8,12 @@ import {
|
|
|
8
8
|
} from '../../domain/file-kind.js';
|
|
9
9
|
|
|
10
10
|
export function normalizeVaultPathInput(value) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const normalized = String(value ?? '').trim().replace(/\\/g, '/');
|
|
12
|
+
if (!normalized || normalized.startsWith('/')) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const segments = normalized
|
|
15
17
|
.split('/')
|
|
16
18
|
.map((segment) => segment.trim())
|
|
17
19
|
.filter(Boolean);
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createFileSearchEntry, findFileSearchMatch } from './file-search.js';
|
|
2
|
+
|
|
3
|
+
const MAX_VISIBLE_RESULTS = 30;
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* CodeMirror autocomplete source for [[wiki-links]].
|
|
3
7
|
*
|
|
@@ -29,31 +33,28 @@ export function wikiLinkCompletions(getFileList) {
|
|
|
29
33
|
return null;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
const query = afterOpen.toLowerCase();
|
|
36
|
+
const query = afterOpen.trim().toLowerCase().replace(/\s+/gu, ' ');
|
|
33
37
|
const from = line.from + openIndex + 2;
|
|
34
|
-
const
|
|
38
|
+
const entries = getFileList().map((filePath) => createFileSearchEntry(filePath));
|
|
39
|
+
const matches = query
|
|
40
|
+
? entries
|
|
41
|
+
.map((entry) => ({ entry, match: findFileSearchMatch(entry, query) }))
|
|
42
|
+
.filter(({ match }) => match)
|
|
43
|
+
.sort((left, right) => right.match.score - left.match.score
|
|
44
|
+
|| left.entry.lowerPath.localeCompare(right.entry.lowerPath))
|
|
45
|
+
: entries.map((entry) => ({ entry, match: null }));
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.map((
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { filePath, label, fileName };
|
|
43
|
-
})
|
|
44
|
-
.filter(({ label, fileName }) =>
|
|
45
|
-
label.toLowerCase().includes(query) || fileName.toLowerCase().includes(query),
|
|
46
|
-
)
|
|
47
|
-
.map(({ label, fileName }) => ({
|
|
48
|
-
label,
|
|
49
|
-
// Show just the filename as detail when in a subdirectory
|
|
50
|
-
detail: label.includes('/') ? ` ${fileName}` : undefined,
|
|
47
|
+
const options = matches
|
|
48
|
+
.slice(0, MAX_VISIBLE_RESULTS)
|
|
49
|
+
.map(({ entry }) => ({
|
|
50
|
+
label: entry.filePath,
|
|
51
|
+
displayLabel: entry.filePath.split('/').pop(),
|
|
52
|
+
detail: entry.displayName.slice(0, -entry.fileName.length - 1) || undefined,
|
|
51
53
|
apply: (view, completion, from, to) => {
|
|
52
54
|
// Replace from the query start to cursor, and also consume any trailing `]]`
|
|
53
|
-
const docText = view.state.doc.toString();
|
|
54
55
|
let end = to;
|
|
55
56
|
// If there's already a `]]` right after cursor, consume it
|
|
56
|
-
if (
|
|
57
|
+
if (view.state.sliceDoc(to, to + 2) === ']]') {
|
|
57
58
|
end = to + 2;
|
|
58
59
|
}
|
|
59
60
|
view.dispatch({
|
|
@@ -62,7 +63,6 @@ export function wikiLinkCompletions(getFileList) {
|
|
|
62
63
|
});
|
|
63
64
|
},
|
|
64
65
|
type: 'text',
|
|
65
|
-
boost: label.toLowerCase().startsWith(query) ? 1 : 0,
|
|
66
66
|
}));
|
|
67
67
|
|
|
68
68
|
if (options.length === 0) {
|
|
@@ -155,8 +155,13 @@ function teardownDrawioFrame() {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
function buildDrawioFrameUrl() {
|
|
158
|
-
const
|
|
159
|
-
|
|
158
|
+
const fallbackUrl = 'https://embed.diagrams.net';
|
|
159
|
+
let url;
|
|
160
|
+
try {
|
|
161
|
+
url = new URL(runtimeConfig.drawioBaseUrl || fallbackUrl);
|
|
162
|
+
} catch {
|
|
163
|
+
url = new URL(fallbackUrl);
|
|
164
|
+
}
|
|
160
165
|
url.searchParams.set('embed', '1');
|
|
161
166
|
url.searchParams.set('proto', 'json');
|
|
162
167
|
url.searchParams.set('spin', '1');
|
|
@@ -396,7 +401,7 @@ function handleLeaseState(nextState) {
|
|
|
396
401
|
state.canClaim = Boolean(nextState?.canClaim);
|
|
397
402
|
|
|
398
403
|
if (state.isEditor) {
|
|
399
|
-
state.bannerText = '
|
|
404
|
+
state.bannerText = 'Changes save automatically.';
|
|
400
405
|
} else if (nextState?.hasHealthyHolder) {
|
|
401
406
|
const holderName = nextState.holderName || 'Another user';
|
|
402
407
|
state.bannerText = `${holderName} is editing this diagram. Read-only mode. Updates appear after they save.`;
|