Skip to content

开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.

feat(web): add debug console (#83)

pubuzhixing8477ddfb24dc5
diff --git a/apps/web/src/app/app.tsx b/apps/web/src/app/app.tsx
index 7d925e5..f9a891a 100644
--- a/apps/web/src/app/app.tsx
+++ b/apps/web/src/app/app.tsx
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { initializeData } from './initialize-data';
import { Drawnix } from '@drawnix/core';
-import { PlaitElement, PlaitTheme, Viewport } from '@plait/core';
+import { PlaitBoard, PlaitElement, PlaitTheme, Viewport } from '@plait/core';
const DRAWNIX_LOCAL_DATA_KEY = 'drawnix-local-data';
@@ -18,18 +18,41 @@ export function App() {
return { children: initializeData };
});
return (
- <Drawnix
- value={value.children}
- viewport={value.viewport}
- theme={value.theme}
- onChange={(value) => {
- localStorage.setItem(DRAWNIX_LOCAL_DATA_KEY, JSON.stringify(value));
- }}
- afterInit={(board) => {
- console.log('board initialized');
- }}
- ></Drawnix>
+ <>
+ <Drawnix
+ value={value.children}
+ viewport={value.viewport}
+ theme={value.theme}
+ onChange={(value) => {
+ localStorage.setItem(DRAWNIX_LOCAL_DATA_KEY, JSON.stringify(value));
+ }}
+ afterInit={(board) => {
+ console.log('board initialized');
+ console.log(
+ `add __drawnix__web__debug_log to window, so you can call add log anywhere, like: window.__drawnix__web__console('some thing')`
+ );
+ (window as any)['__drawnix__web__console'] = (value: string) => {
+ addDebugLog(board, value);
+ };
+ }}
+ ></Drawnix>
+ </>
);
}
+const addDebugLog = (board: PlaitBoard, value: string) => {
+ const container = PlaitBoard.getBoardContainer(board).closest(
+ '.drawnix'
+ ) as HTMLElement;
+ let consoleContainer = container.querySelector('.drawnix-console');
+ if (!consoleContainer) {
+ consoleContainer = document.createElement('div');
+ consoleContainer.classList.add('drawnix-console');
+ container.append(consoleContainer);
+ }
+ const div = document.createElement('div');
+ div.innerHTML = value;
+ consoleContainer.append(div);
+};
+
export default App;
diff --git a/apps/web/src/styles.scss b/apps/web/src/styles.scss
index a04f56f..0a77b10 100644
--- a/apps/web/src/styles.scss
+++ b/apps/web/src/styles.scss
@@ -13,4 +13,17 @@ body {
height: 100%;
width: 100%;
overflow: hidden;
+}
+.drawnix-console {
+ position: absolute;
+ top: 50%;
+ transform: translateY(-50%);
+ left: 0;
+ height: 200px;
+ width: 200px;
+ overflow: auto;
+ background-color: black;
+ color: white;
+ padding: 8px;
+ opacity: 0.5;
}
\ No newline at end of file