Skip to content

Commit

Permalink
fix: load default options in webview
Browse files Browse the repository at this point in the history
since it is not serializable
  • Loading branch information
gera2ld committed Dec 20, 2024
1 parent 1b6082e commit 3df8521
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"husky": "^8.0.3",
"lodash.debounce": "^4.0.8",
"markmap-common": "0.18.0",
"markmap-lib": "0.18.0",
"markmap-lib": "0.18.1",
"markmap-render": "0.18.0",
"markmap-toolbar": "0.18.0",
"markmap-view": "0.18.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { INode } from 'markmap-common';
import { Toolbar } from 'markmap-toolbar';
import {
defaultOptions,
deriveOptions,
type IMarkmapJSONOptions,
type Markmap,
Expand All @@ -14,14 +15,17 @@ let root: INode | undefined;
let style: HTMLStyleElement;
let active:
| {
node: INode;
el: Element;
}
node: INode;
el: Element;
}
| undefined;

const handlers = {
async setData(data: { root?: INode; jsonOptions?: IMarkmapJSONOptions }) {
await mm.setData((root = data.root), deriveOptions(data.jsonOptions) || {});
await mm.setData((root = data.root), {
...defaultOptions,
...deriveOptions(data.jsonOptions),
});
if (firstTime) {
mm.fit();
firstTime = false;
Expand Down
15 changes: 7 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import debounce from 'lodash.debounce';
import { JSItem, type CSSItem } from 'markmap-common';
import { fillTemplate } from 'markmap-render';
import { defaultOptions, type IMarkmapJSONOptions } from 'markmap-view';
import { type IMarkmapJSONOptions } from 'markmap-view';
import {
ColorThemeKind,
CustomTextEditorProvider,
Expand Down Expand Up @@ -49,7 +49,7 @@ async function writeFile(targetUri: Uri, text: string) {
class MarkmapEditor implements CustomTextEditorProvider {
private webviewPanelMap = new Map<TextDocument, WebviewPanel>();

constructor(private context: ExtensionContext) { }
constructor(private context: ExtensionContext) {}

private resolveAssetPath(relPath: string) {
return Utils.joinPath(this.context.extensionUri, relPath);
Expand Down Expand Up @@ -165,7 +165,6 @@ class MarkmapEditor implements CustomTextEditorProvider {
data: {
root,
jsonOptions: {
...defaultOptions,
...globalOptions,
...(frontmatter as any)?.markmap,
},
Expand Down Expand Up @@ -193,11 +192,11 @@ class MarkmapEditor implements CustomTextEditorProvider {
styles: [
...(customCSS
? [
{
type: 'style',
data: customCSS,
} as CSSItem,
]
{
type: 'style',
data: customCSS,
} as CSSItem,
]
: []),
],
scripts: [
Expand Down

0 comments on commit 3df8521

Please sign in to comment.