generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove almost all of the TypeScript errors.
Signed-off-by: Ryan McQuen <rpcm@linux.com>
- Loading branch information
1 parent
ca295fd
commit 67ca3c1
Showing
10 changed files
with
1,977 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
## Obsidian Org Mode | ||
|
||
Add Org Mode support to Obsidian. | ||
|
||
<img width="502" alt="Screen Shot 2021-05-14 at 10 08 41 AM" src="https://user-images.githubusercontent.com/772937/118305097-65c15900-b49c-11eb-8437-b9f5da3dad75.png"> | ||
|
||
### Manually installing the plugin | ||
|
||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/obsidian-org-mode/`. | ||
## Obsidian Org Mode | ||
|
||
Add Org Mode support to Obsidian. | ||
|
||
<img width="502" alt="Screen Shot 2021-05-14 at 10 08 41 AM" src="https://user-images.githubusercontent.com/772937/118305097-65c15900-b49c-11eb-8437-b9f5da3dad75.png"> | ||
|
||
### Manually installing the plugin | ||
|
||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/obsidian-org-mode/`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import { nodeResolve } from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
|
||
const isProd = process.env.BUILD === 'production'; | ||
|
||
const banner = `/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP | ||
if you want to view the source visit the plugins github repository | ||
*/ | ||
`; | ||
|
||
export default { | ||
input: 'src/main.ts', | ||
output: { | ||
dir: '.', | ||
sourcemap: 'inline', | ||
sourcemapExcludeSources: isProd, | ||
format: 'cjs', | ||
exports: 'default', | ||
banner, | ||
}, | ||
external: ['obsidian'], | ||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()], | ||
}; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import { nodeResolve } from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
|
||
const isProd = process.env.BUILD === "production"; | ||
|
||
const banner = `/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP | ||
if you want to view the source visit the plugins github repository | ||
*/ | ||
`; | ||
|
||
export default { | ||
input: "src/main.ts", | ||
output: { | ||
dir: ".", | ||
sourcemap: "inline", | ||
sourcemapExcludeSources: isProd, | ||
format: "cjs", | ||
exports: "default", | ||
banner, | ||
}, | ||
external: ["obsidian"], | ||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()], | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = CodeMirror; | ||
export default CodeMirror; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,108 @@ | ||
import "./lib/codemirror.js"; | ||
import "./mode/simple/simple.js"; | ||
import "./mode/orgmode/orgmode-fold.js"; | ||
import "./mode/orgmode/orgmode-mode.js"; | ||
import { Plugin, TextFileView, WorkspaceLeaf } from "obsidian"; | ||
|
||
export default class OrgMode extends Plugin { | ||
async onload() { | ||
super.onload(); | ||
console.log("Loading Org Mode plugin ..."); | ||
|
||
this.registerView("orgmode", this.orgViewCreator); | ||
this.registerExtensions(["org"], "orgmode"); | ||
} | ||
|
||
orgViewCreator = (leaf: WorkspaceLeaf) => { | ||
return new OrgView(leaf); | ||
}; | ||
|
||
onunload() { | ||
console.log("Unloading Org Mode plugin ..."); | ||
} | ||
} | ||
|
||
// This is the custom view: | ||
class OrgView extends TextFileView { | ||
// Internal code mirror instance: | ||
codeMirror: CodeMirror.Editor; | ||
|
||
// this.contentEl is not exposed, so cheat a bit. | ||
public get extContentEl(): HTMLElement { | ||
// @ts-ignore | ||
return this.contentEl; | ||
} | ||
|
||
constructor(leaf: WorkspaceLeaf) { | ||
super(leaf); | ||
// @ts-ignore | ||
this.codeMirror = CodeMirror(this.extContentEl, { | ||
theme: "obsidian", | ||
|
||
// I am not sure autofocus is necessary ... | ||
autofocus: true, | ||
foldGutter: { | ||
minFoldSize: 1, | ||
}, | ||
foldOptions: { | ||
widget: " ...", | ||
}, | ||
gutters: ["CodeMirror-foldgutter"], | ||
}); | ||
|
||
this.codeMirror.on("changes", this.changed); | ||
} | ||
|
||
// When the view is resized, refresh CodeMirror (thanks Licat!). | ||
onResize() { | ||
this.codeMirror.refresh(); | ||
} | ||
|
||
changed = async ( | ||
_instance: CodeMirror.Editor, | ||
_changes: CodeMirror.EditorChangeLinkedList[] | ||
) => { | ||
this.requestSave(); | ||
}; | ||
|
||
getViewData = () => { | ||
return this.codeMirror.getValue(); | ||
}; | ||
|
||
setViewData = (data: string, clear: boolean) => { | ||
if (clear) { | ||
// @ts-ignore | ||
this.codeMirror.swapDoc(CodeMirror.Doc(data, "orgmode")); | ||
} else { | ||
this.codeMirror.setValue(data); | ||
} | ||
|
||
// HACK: | ||
// Ideally this would actually be able to find the user defined | ||
// keyMap, and not just check the 'vimMode' boolean. | ||
// @ts-ignore | ||
if (this.app?.vault?.config?.vimMode) { | ||
this.codeMirror.setOption("keyMap", "vim"); | ||
} | ||
|
||
// This seems to fix some odd visual bugs: | ||
this.codeMirror.refresh(); | ||
|
||
// This focuses the editor, which is analogous to the | ||
// default Markdown behavior in Obsidian: | ||
this.codeMirror.focus(); | ||
}; | ||
|
||
clear = () => { | ||
this.codeMirror.setValue(""); | ||
this.codeMirror.clearHistory(); | ||
}; | ||
|
||
getDisplayText() { | ||
if (this.file) { | ||
return this.file.basename; | ||
} else { | ||
return "org (No File)"; | ||
} | ||
} | ||
|
||
canAcceptExtension(extension: string) { | ||
return extension === "org"; | ||
} | ||
|
||
getViewType() { | ||
return "orgmode"; | ||
} | ||
} | ||
import { Plugin, TextFileView, WorkspaceLeaf } from "obsidian"; | ||
import "./mode/simple/simple.js"; | ||
import "./mode/orgmode/orgmode-fold.js"; | ||
import "./mode/orgmode/orgmode-mode.js"; | ||
import CodeMirror from "./lib/codemirror"; | ||
|
||
export default class OrgMode extends Plugin { | ||
async onload() { | ||
super.onload(); | ||
console.log("Loading Org Mode plugin ..."); | ||
|
||
this.registerView("orgmode", this.orgViewCreator); | ||
this.registerExtensions(["org"], "orgmode"); | ||
} | ||
|
||
orgViewCreator = (leaf: WorkspaceLeaf) => { | ||
return new OrgView(leaf); | ||
}; | ||
|
||
onunload() { | ||
console.log("Unloading Org Mode plugin ..."); | ||
} | ||
} | ||
|
||
// This is the custom view: | ||
class OrgView extends TextFileView { | ||
// Internal code mirror instance: | ||
codeMirror: CodeMirror.Editor; | ||
|
||
// this.contentEl is not exposed, so cheat a bit. | ||
public get extContentEl(): HTMLElement { | ||
return this.contentEl; | ||
} | ||
|
||
constructor(leaf: WorkspaceLeaf) { | ||
super(leaf); | ||
|
||
this.codeMirror = CodeMirror(this.extContentEl, { | ||
theme: "obsidian", | ||
|
||
// I am not sure autofocus is necessary ... | ||
autofocus: true, | ||
foldGutter: { | ||
minFoldSize: 1, | ||
}, | ||
foldOptions: { | ||
widget: " ...", | ||
}, | ||
gutters: ["CodeMirror-foldgutter"], | ||
} as CodeMirror.EditorConfiguration); | ||
|
||
this.codeMirror.on("changes", this.changed); | ||
} | ||
|
||
// When the view is resized, refresh CodeMirror (thanks Licat!). | ||
onResize() { | ||
this.codeMirror.refresh(); | ||
} | ||
|
||
changed = async () => { | ||
this.requestSave(); | ||
}; | ||
|
||
getViewData = () => { | ||
return this.codeMirror.getValue(); | ||
}; | ||
|
||
setViewData = (data: string, clear: boolean) => { | ||
if (clear) { | ||
this.codeMirror.swapDoc(CodeMirror.Doc(data, "orgmode")); | ||
} else { | ||
this.codeMirror.setValue(data); | ||
} | ||
|
||
// @ts-ignore | ||
if (this.app?.vault?.config?.vimMode) { | ||
this.codeMirror.setOption("keyMap", "vim"); | ||
} | ||
|
||
// This seems to fix some odd visual bugs: | ||
this.codeMirror.refresh(); | ||
|
||
// This focuses the editor, which is analogous to the | ||
// default Markdown behavior in Obsidian: | ||
this.codeMirror.focus(); | ||
}; | ||
|
||
clear = () => { | ||
this.codeMirror.setValue(""); | ||
this.codeMirror.clearHistory(); | ||
}; | ||
|
||
getDisplayText() { | ||
if (this.file) { | ||
return this.file.basename; | ||
} else { | ||
return "org (No File)"; | ||
} | ||
} | ||
|
||
canAcceptExtension(extension: string) { | ||
return extension === "org"; | ||
} | ||
|
||
getViewType() { | ||
return "orgmode"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"module": "ESNext", | ||
"target": "es6", | ||
"allowJs": false, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"importHelpers": true, | ||
"lib": ["dom", "es5", "scripthost", "es2015"] | ||
}, | ||
"include": ["**/*.ts"] | ||
} | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"module": "ESNext", | ||
"target": "es6", | ||
"allowJs": false, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"importHelpers": true, | ||
"lib": ["dom", "es5", "scripthost", "es2015"], | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
curl https://cdn.jsdelivr.net/npm/codemirror@5/addon/mode/simple.js -o src/mode/simple/simple.js | ||
curl https://cdn.jsdelivr.net/gh/mickael-kerjean/codemirror-orgmode/orgmode-fold.js -o src/mode/orgmode/orgmode-fold.js | ||
curl https://cdn.jsdelivr.net/gh/mickael-kerjean/codemirror-orgmode/orgmode-mode.js -o src/mode/orgmode/orgmode-mode.js | ||
|
||
curl https://cdn.jsdelivr.net/npm/@types/codemirror@5/index.d.ts -o src/lib/codemirror.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"1.3.1": "0.10.12", | ||
"1.3.0": "0.10.12", | ||
"1.2.1": "0.10.12", | ||
"1.2.0": "0.10.12", | ||
|