Skip to content

Commit 3df8521

Browse files
committed
fix: load default options in webview
since it is not serializable
1 parent 1b6082e commit 3df8521

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"husky": "^8.0.3",
128128
"lodash.debounce": "^4.0.8",
129129
"markmap-common": "0.18.0",
130-
"markmap-lib": "0.18.0",
130+
"markmap-lib": "0.18.1",
131131
"markmap-render": "0.18.0",
132132
"markmap-toolbar": "0.18.0",
133133
"markmap-view": "0.18.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { INode } from 'markmap-common';
22
import { Toolbar } from 'markmap-toolbar';
33
import {
4+
defaultOptions,
45
deriveOptions,
56
type IMarkmapJSONOptions,
67
type Markmap,
@@ -14,14 +15,17 @@ let root: INode | undefined;
1415
let style: HTMLStyleElement;
1516
let active:
1617
| {
17-
node: INode;
18-
el: Element;
19-
}
18+
node: INode;
19+
el: Element;
20+
}
2021
| undefined;
2122

2223
const handlers = {
2324
async setData(data: { root?: INode; jsonOptions?: IMarkmapJSONOptions }) {
24-
await mm.setData((root = data.root), deriveOptions(data.jsonOptions) || {});
25+
await mm.setData((root = data.root), {
26+
...defaultOptions,
27+
...deriveOptions(data.jsonOptions),
28+
});
2529
if (firstTime) {
2630
mm.fit();
2731
firstTime = false;

src/extension.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import debounce from 'lodash.debounce';
22
import { JSItem, type CSSItem } from 'markmap-common';
33
import { fillTemplate } from 'markmap-render';
4-
import { defaultOptions, type IMarkmapJSONOptions } from 'markmap-view';
4+
import { type IMarkmapJSONOptions } from 'markmap-view';
55
import {
66
ColorThemeKind,
77
CustomTextEditorProvider,
@@ -49,7 +49,7 @@ async function writeFile(targetUri: Uri, text: string) {
4949
class MarkmapEditor implements CustomTextEditorProvider {
5050
private webviewPanelMap = new Map<TextDocument, WebviewPanel>();
5151

52-
constructor(private context: ExtensionContext) { }
52+
constructor(private context: ExtensionContext) {}
5353

5454
private resolveAssetPath(relPath: string) {
5555
return Utils.joinPath(this.context.extensionUri, relPath);
@@ -165,7 +165,6 @@ class MarkmapEditor implements CustomTextEditorProvider {
165165
data: {
166166
root,
167167
jsonOptions: {
168-
...defaultOptions,
169168
...globalOptions,
170169
...(frontmatter as any)?.markmap,
171170
},
@@ -193,11 +192,11 @@ class MarkmapEditor implements CustomTextEditorProvider {
193192
styles: [
194193
...(customCSS
195194
? [
196-
{
197-
type: 'style',
198-
data: customCSS,
199-
} as CSSItem,
200-
]
195+
{
196+
type: 'style',
197+
data: customCSS,
198+
} as CSSItem,
199+
]
201200
: []),
202201
],
203202
scripts: [

0 commit comments

Comments
 (0)