mirror of
https://github.com/waiting0324/obsidian-code-note.git
synced 2026-07-22 07:30:24 +00:00
修改類名稱
This commit is contained in:
parent
a906afae11
commit
0cb31d67fa
7 changed files with 32 additions and 104 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { Graph } from '@antv/x6';
|
||||
import { utils } from './utils'
|
||||
import { Utils } from './Utils'
|
||||
|
||||
const myUtils = new utils()
|
||||
const myUtils = new Utils()
|
||||
|
||||
/**
|
||||
* 註冊 類聲明 中 方法名稱位置 計算函數
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import hljs from 'highlight.js';
|
||||
import { utils, CodeData } from './utils'
|
||||
import { Utils, CodeData } from './Utils'
|
||||
|
||||
const myUtils = new utils()
|
||||
const myUtils = new Utils()
|
||||
|
||||
class CodeBlockShape {
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Shape } from '@antv/x6';
|
||||
import { CodeData, utils } from './utils'
|
||||
import { CodeData, Utils } from './Utils'
|
||||
|
||||
const myUtils = new utils()
|
||||
const myUtils = new Utils()
|
||||
|
||||
class Edge {
|
||||
|
||||
|
|
@ -104,4 +104,4 @@ class Edge {
|
|||
|
||||
}
|
||||
|
||||
export { Edge }
|
||||
export { Edge }
|
||||
|
|
@ -1,92 +1,15 @@
|
|||
import {Cell, Graph, Shape} from '@antv/x6';
|
||||
import {CodeBlockShape} from './codeBlockShape';
|
||||
import {ClassShape} from './classShape';
|
||||
import {CLASS_SHAPE_ID_TAG, CODE_BLOCK_ID_TAG, CodeData, utils} from './utils';
|
||||
import {Edge} from './edge'
|
||||
import {CodeBlockShape} from './CodeBlockShape';
|
||||
import {ClassShape} from './ClassShape';
|
||||
import {CLASS_SHAPE_ID_TAG, CODE_BLOCK_ID_TAG, CodeData, Utils} from './Utils';
|
||||
import {Edge} from './Edge'
|
||||
|
||||
let codeBlocks = [`
|
||||
/**
|
||||
* listen plugin handler event and handle plugin.
|
||||
* @class ShenyuWebHandler
|
||||
* @function onApplicationEvent(final PluginHandlerEvent event)
|
||||
* @param event sort plugin event
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(final PluginHandlerEvent event) {
|
||||
PluginHandlerEventEnum stateEnums = event.getPluginStateEnums();
|
||||
PluginData pluginData = (PluginData) event.getSource();
|
||||
switch (stateEnums) {
|
||||
case ENABLED:
|
||||
onPluginEnabled(pluginData);
|
||||
break;
|
||||
case DELETE:
|
||||
case DISABLED:
|
||||
// disable or removed plugin.
|
||||
onPluginRemoved(pluginData);
|
||||
break;
|
||||
case SORTED:
|
||||
// copy a new one, or there will be concurrency problems
|
||||
onSortedPlugins();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + event.getPluginStateEnums());
|
||||
}
|
||||
onSortedPlugins();
|
||||
}
|
||||
`,
|
||||
`
|
||||
/**
|
||||
* handler error.
|
||||
*
|
||||
* @class ShenyuWebHandler
|
||||
* @function handle(@NonNull final ServerWebExchange exchange, @NonNull final Throwable throwable)
|
||||
* @call ShenyuPluginLoader @ getInstance()
|
||||
*
|
||||
* @param exchange the exchange
|
||||
* @param throwable the throwable
|
||||
* @return error result
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
public Mono<Void> handle(@NonNull final ServerWebExchange exchange, @NonNull final Throwable throwable) {
|
||||
LOG.error("handle error: {}{}", exchange.getLogPrefix(), formatError(throwable, exchange.getRequest()), throwable);
|
||||
HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
if (throwable instanceof ResponseStatusException) {
|
||||
httpStatus = ((ResponseStatusException) throwable).getStatus();
|
||||
}
|
||||
exchange.getResponse().setStatusCode(httpStatus);
|
||||
Object error = ShenyuResultWrap.error(exchange, httpStatus.value(), httpStatus.getReasonPhrase(), throwable);
|
||||
return WebFluxResultUtils.result(exchange, error);
|
||||
}
|
||||
`,
|
||||
`
|
||||
/**
|
||||
* Get plugin loader instance.
|
||||
*
|
||||
* @class ShenyuPluginLoader
|
||||
* @function getInstance()
|
||||
*
|
||||
* @return plugin loader instance
|
||||
*/
|
||||
public static ShenyuPluginLoader getInstance() {
|
||||
if (null == pluginLoader) {
|
||||
synchronized (ShenyuPluginLoader.class) {
|
||||
if (null == pluginLoader) {
|
||||
pluginLoader = new ShenyuPluginLoader();
|
||||
}
|
||||
}
|
||||
}
|
||||
return pluginLoader;
|
||||
}
|
||||
`]
|
||||
|
||||
const myUtils = new utils()
|
||||
const myUtils = new Utils()
|
||||
const codeBlockShape = new CodeBlockShape()
|
||||
const classShape = new ClassShape()
|
||||
const edge = new Edge()
|
||||
|
||||
// window.onload = function () {
|
||||
export let indexInit = function (codeBlocks: String[]) {
|
||||
export let initGraph = function (codeBlocks: String[]) {
|
||||
|
||||
// 創建畫布
|
||||
const graph = new Graph({
|
||||
|
|
@ -132,9 +55,6 @@ export let indexInit = function (codeBlocks: String[]) {
|
|||
// 綁定 開啟/關閉 代碼塊圖形 事件
|
||||
graph.on('toggle:codeBlock', ({e, node}) => {
|
||||
|
||||
console.dir(e)
|
||||
console.dir(node)
|
||||
|
||||
// 獲取 代碼塊圖形、開關文字 對象
|
||||
let codeBlock = graph.getCellById(e.currentTarget.getAttribute('target-code-block'))
|
||||
let toggleText = e.currentTarget.parentNode.childNodes[3].children[0]
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import {ItemView, View, WorkspaceLeaf} from "obsidian";
|
||||
import {indexInit} from "./index";
|
||||
import {initGraph} from "./Graph";
|
||||
import {SOURCE_CODE_VIEW_TYPE} from "./main";
|
||||
|
||||
export default class SourceCodeView extends ItemView {
|
||||
|
|
@ -26,7 +26,7 @@ export default class SourceCodeView extends ItemView {
|
|||
div.id = 'container';
|
||||
this.containerEl.children[1].appendChild(div);
|
||||
|
||||
indexInit(this.codeBlocks);
|
||||
initGraph(this.codeBlocks);
|
||||
}
|
||||
|
||||
async onClose() {
|
||||
|
|
@ -16,7 +16,7 @@ type CodeDataFuncCall = {
|
|||
|
||||
export const CLASS_SHAPE_ID_TAG: string = "class-";
|
||||
export const CODE_BLOCK_ID_TAG: string = 'code-block-';
|
||||
class utils {
|
||||
class Utils {
|
||||
|
||||
/**
|
||||
* 計算字串寬度
|
||||
|
|
@ -164,4 +164,4 @@ class utils {
|
|||
}
|
||||
|
||||
|
||||
export { utils, CodeData, CodeDataFunc }
|
||||
export { Utils, CodeData, CodeDataFunc }
|
||||
22
src/main.ts
22
src/main.ts
|
|
@ -1,26 +1,34 @@
|
|||
import {Plugin, Workspace, WorkspaceLeaf} from 'obsidian';
|
||||
import SourceCodeView from "./source-code";
|
||||
import SourceCodeView from "./SourceCodeView";
|
||||
|
||||
|
||||
export const SOURCE_CODE_VIEW_TYPE = 'source-code-view'
|
||||
export default class MyPlugin extends Plugin {
|
||||
export default class SourceCodeViewPlugin extends Plugin {
|
||||
|
||||
sourceCodeView: SourceCodeView
|
||||
// Obsidian 中 Markdown 的 代碼塊內容 集合
|
||||
codeBlocks: string[] = []
|
||||
|
||||
/**
|
||||
* 載入插件時,註冊相關組件
|
||||
*/
|
||||
async onload() {
|
||||
|
||||
// 註冊 Obsidian 的 View
|
||||
this.registerView(
|
||||
SOURCE_CODE_VIEW_TYPE,
|
||||
(leaf: WorkspaceLeaf) =>
|
||||
(this.sourceCodeView = new SourceCodeView(this.codeBlocks, leaf))
|
||||
(leaf: WorkspaceLeaf) => (new SourceCodeView(this.codeBlocks, leaf))
|
||||
);
|
||||
|
||||
// 註冊 Obsidian 左側的按鈕
|
||||
this.addRibbonIcon("dice", "Activate view", () => {
|
||||
this.initCanvas()
|
||||
this.initView()
|
||||
});
|
||||
}
|
||||
|
||||
initCanvas() {
|
||||
/**
|
||||
* 初始化 Obsidian 的 View 頁面
|
||||
*/
|
||||
initView() {
|
||||
|
||||
// 當 ResourceCodeView 頁面已開啟,則返回
|
||||
if (this.app.workspace.getLeavesOfType(SOURCE_CODE_VIEW_TYPE).length > 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue